spl.h

00001 
00002 /***************************************************************************
00003  *  spl.h - Fawkes SPL refbox repeater
00004  *
00005  *  Created: Tue Jul 08 13:46:19 2008
00006  *  Copyright  2008-2010  Tim Niemueller [www.niemueller.de]
00007  *             2009       Tobias Kellner
00008  *
00009  ****************************************************************************/
00010 
00011 /*  This program is free software; you can redistribute it and/or modify
00012  *  it under the terms of the GNU General Public License as published by
00013  *  the Free Software Foundation; either version 2 of the License, or
00014  *  (at your option) any later version.
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL file in the doc directory.
00022  */
00023 
00024 #ifndef __TOOLS_REFBOXREP_SPL_H_
00025 #define __TOOLS_REFBOXREP_SPL_H_
00026 
00027 #include "processor.h"
00028 #include <netcomm/worldinfo/enums.h>
00029 
00030 #include <cstdlib>
00031 #include <stdint.h>
00032 #include <map>
00033 
00034 namespace fawkes {
00035   class Logger;
00036   class DatagramSocket;
00037 }
00038 
00039 #define SPL_HEADER_SIZE 4
00040 #define SPL_MAX_NUM_PLAYERS 11
00041 
00042 #pragma pack(push,4)
00043 /** SPL RefBox protocol robot info struct. */
00044 typedef struct {
00045   uint16_t penalty;               /**< penalty state of the player */
00046   uint16_t secs_till_unpenalized; /**< estimate of time till unpenalised */
00047 } spl_robotinfo_t;
00048 
00049 /** SPL RefBox protocol team info struct. */
00050 typedef struct {
00051   uint8_t  team_number;           /**< unique team number */
00052   uint8_t  team_color;            /**< colour of the team */
00053 #ifdef USE_SPL_GC6
00054   uint16_t score;                 /**< team's score */
00055 #else
00056   uint8_t  goal_color;            /**< colour of the goal */
00057   uint8_t  score;                 /**< team's score */
00058 #endif
00059   spl_robotinfo_t players[SPL_MAX_NUM_PLAYERS];       /**< the team's players */
00060 } spl_teaminfo_t;
00061 
00062 /** SPL RefBox protocol game control struct. */
00063 typedef struct {
00064   char      header[SPL_HEADER_SIZE];  /**< header to identify the structure */
00065   uint32_t  version;             /**< version of the data structure */
00066   uint8_t   players_per_team;    /**< The number of players on a team */
00067   uint8_t   state;               /**< state of the game (STATE_READY, STATE_PLAYING, etc.) */
00068   uint8_t   first_half;          /**< 1 = game in first half, 0 otherwise */
00069   uint8_t   kick_off_team;       /**< the next team to kick off */
00070   uint8_t   secondary_state;     /**< Extra state information - (STATE2_NORMAL, STATE2_PENALTYSHOOT, etc) */
00071   uint8_t   drop_in_team;        /**< team that caused last drop in */
00072   uint16_t  drop_in_time;        /**< number of seconds passed since the last drop in.  -1 before first dropin */
00073   uint32_t  secs_remaining;      /**< estimate of number of seconds remaining in the half */
00074   spl_teaminfo_t teams[2];       /**< Info about the teams */
00075 } spl_gamecontrol_t;
00076 #pragma pack(pop)
00077 
00078 class SplRefBoxProcessor : public RefBoxProcessor
00079 {
00080  public:
00081   SplRefBoxProcessor(fawkes::Logger *logger, unsigned short int broadcast_port,
00082                      unsigned int team_number, unsigned int player_number);
00083   ~SplRefBoxProcessor();
00084 
00085   void run();
00086 
00087   bool check_connection();
00088   void refbox_process();
00089 
00090  private:
00091   void process_struct(spl_gamecontrol_t *msg);
00092 
00093  private:
00094   fawkes::DatagramSocket *__s;
00095   fawkes::Logger         *__logger;
00096 
00097   bool __quit;
00098 
00099   uint16_t __penalty;
00100   uint8_t  __team_number;
00101   uint8_t  __player_number;
00102 };
00103 
00104 #endif

Generated on 1 Mar 2011 for Fawkes API by  doxygen 1.6.1