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  *             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 GCHS 4
00040 #define MAX_NUM_PLAYERS 11
00041 #pragma pack(push,4)
00042 /** SPL RefBox protocol robot info struct. */
00043 typedef struct {
00044   uint16_t penalty;               /**< penalty state of the player */
00045   uint16_t secs_till_unpenalized; /**< estimate of time till unpenalised */
00046 } spl_robotinfo_t;
00047 
00048 /** SPL RefBox protocol team info struct. */
00049 typedef struct {
00050   uint8_t  team_number;           /**< unique team number */
00051   uint8_t  team_color;            /**< colour of the team */
00052   uint16_t score;                 /**< team's score */
00053   spl_robotinfo_t players[MAX_NUM_PLAYERS];       /**< the team's players */
00054 } spl_teaminfo_t;
00055 
00056 /** SPL RefBox protocol game control struct. */
00057 typedef struct {
00058   char      header[GCHS];        /**< header to identify the structure */
00059   uint32_t  version;             /**< version of the data structure */
00060   uint8_t   players_per_team;    /**< The number of players on a team */
00061   uint8_t   state;               /**< state of the game (STATE_READY, STATE_PLAYING, etc) */
00062   uint8_t   first_half;          /**< 1 = game in first half, 0 otherwise */
00063   uint8_t   kick_off_team;       /**< the next team to kick off */
00064   uint8_t   secondary_state;     /**< Extra state information - (STATE2_NORMAL, STATE2_PENALTYSHOOT, etc) */
00065   uint8_t   drop_in_team;        /**< team that caused last drop in */
00066   uint16_t  drop_in_time;        /**< number of seconds passed since the last drop in.  -1 before first dropin */
00067   uint32_t  secs_remaining;      /**< estimate of number of seconds remaining in the half */
00068   spl_teaminfo_t teams[2];       /**< Info about the teams */
00069 } spl_gamecontrol_t;
00070 #pragma pack(pop)
00071 
00072 class SplRefBoxProcessor : public RefBoxProcessor
00073 {
00074  public:
00075   SplRefBoxProcessor(fawkes::Logger *logger, unsigned short int broadcast_port,
00076                      unsigned int team_number, unsigned int player_number);
00077   ~SplRefBoxProcessor();
00078
00079   void run();
00080
00081   bool check_connection();
00082   void refbox_process();
00083
00084  private:
00085   void process_struct(spl_gamecontrol_t *msg);
00086
00087  private:
00088   fawkes::DatagramSocket *__s;
00089   fawkes::Logger         *__logger;
00090
00091   bool __quit;
00092
00093   uint16_t __penalty;
00094   uint8_t  __team_number;
00095   uint8_t  __player_number;
00096 };
00097
00098 #endif