refbox_state_sender.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __TOOLS_REFBOXREP_REFBOX_STATE_SENDER_H_
00024 #define __TOOLS_REFBOXREP_REFBOX_STATE_SENDER_H_
00025
00026 #include <core/threading/thread.h>
00027 #include <netcomm/worldinfo/enums.h>
00028 #include <map>
00029
00030 namespace fawkes {
00031 class WorldInfoTransceiver;
00032 }
00033
00034 class RefBoxStateSender
00035 {
00036 public:
00037 RefBoxStateSender(const char *addr, unsigned short port,
00038 const char *key, const char *iv,
00039 bool debug = false);
00040 virtual ~RefBoxStateSender();
00041
00042 virtual void send();
00043 virtual void set_gamestate(int game_state,
00044 fawkes::worldinfo_gamestate_team_t state_team);
00045 virtual void set_score(unsigned int score_cyan, unsigned int score_magenta);
00046 virtual void set_team_goal(fawkes::worldinfo_gamestate_team_t our_team,
00047 fawkes::worldinfo_gamestate_goalcolor_t goal_color);
00048 virtual void set_half(fawkes::worldinfo_gamestate_half_t half);
00049 virtual void add_penalty(unsigned int player, unsigned int penalty,
00050 unsigned int seconds_remaining);
00051
00052 class TimeoutThread : public fawkes::Thread
00053 {
00054 public:
00055 TimeoutThread(RefBoxStateSender *rss);
00056 virtual ~TimeoutThread();
00057 virtual void loop();
00058 private:
00059 unsigned int __timeout_usec;
00060 RefBoxStateSender *__rss;
00061 };
00062
00063 protected:
00064 RefBoxStateSender();
00065
00066 private:
00067 void execute_send();
00068
00069 private:
00070 bool __debug;
00071 fawkes::WorldInfoTransceiver *__transceiver;
00072 TimeoutThread *__timeout_thread;
00073
00074 int __game_state;
00075 fawkes::worldinfo_gamestate_team_t __state_team;
00076 unsigned int __score_cyan;
00077 unsigned int __score_magenta;
00078 fawkes::worldinfo_gamestate_team_t __our_team;
00079 fawkes::worldinfo_gamestate_goalcolor_t __our_goal_color;
00080 fawkes::worldinfo_gamestate_half_t __half;
00081
00082 typedef struct {
00083 unsigned int player;
00084 unsigned int penalty;
00085 unsigned int seconds_remaining;
00086 } rss_penalty_t;
00087 std::map<unsigned int, rss_penalty_t> __penalties;
00088 std::map<unsigned int, rss_penalty_t>::iterator __pit;
00089
00090 };
00091
00092 #endif