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