23 #include "refbox_state_sender.h"
25 #include <netcomm/worldinfo/transceiver.h>
26 #include <core/macros.h>
31 using namespace fawkes;
48 const char *key,
const char *iv,
54 __transceiver->set_loop(
true );
63 __timeout_thread = NULL;
80 __timeout_thread = NULL;
87 if ( __timeout_thread ) {
88 __timeout_thread->cancel();
89 __timeout_thread->join();
90 delete __timeout_thread;
105 printf(
"Setting gamestate to '%d' for team '%s'\n",
109 __game_state = game_state;
110 __state_team = state_team;
122 printf(
"Setting score to %u:%u (cyan:magenta)\n", score_cyan, score_magenta);
124 __score_cyan = score_cyan;
125 __score_magenta = score_magenta;
138 printf(
"Setting team color to '%s' and goal color to '%s'\n",
142 __our_team = our_team;
143 __our_goal_color = goal_color;
154 printf(
"Setting half to '%s'\n",
168 unsigned int seconds_remaining)
173 p.seconds_remaining = seconds_remaining;
174 __penalties[player] = p;
183 printf(
"Sending worldinfo\n");
186 if ( __timeout_thread ) {
187 __timeout_thread->cancel();
188 __timeout_thread->join();
189 delete __timeout_thread;
192 __timeout_thread->start();
200 RefBoxStateSender::execute_send()
202 if (unlikely(! __transceiver)) {
205 __transceiver->set_gamestate(__game_state, __state_team);
206 __transceiver->set_score(__score_cyan, __score_magenta);
207 __transceiver->set_team_goal(__our_team, __our_goal_color);
208 __transceiver->set_half(__half);
209 for (__pit = __penalties.begin(); __pit != __penalties.end(); ++__pit) {
210 __transceiver->add_penalty(__pit->second.player, __pit->second.penalty,
211 __pit->second.seconds_remaining);
214 __transceiver->send();
229 :
Thread(
"RefBoxStateSender::TimeoutThread",
Thread::OPMODE_CONTINUOUS)
245 __rss->execute_send();
247 switch (__timeout_usec) {
248 case 0: __timeout_usec = 1;
break;
249 case 1: __timeout_usec = 2;
break;
250 case 2: __timeout_usec = 50000;
break;
256 usleep(__timeout_usec);
Class to send and receive world information.
RefBox repeater state sender.
virtual ~TimeoutThread()
Destructor.
RefBoxStateSender()
Constructor.
virtual ~RefBoxStateSender()
Destructor.
Thread class encapsulation of pthreads.
virtual void set_gamestate(int game_state, fawkes::worldinfo_gamestate_team_t state_team)
Set current game state.
TimeoutThread(RefBoxStateSender *rss)
Constructor.
worldinfo_gamestate_half_t
Game time half.
const char * worldinfo_gamestate_team_tostring(worldinfo_gamestate_team_t team)
Convert gamestate team to a string.
virtual void add_penalty(unsigned int player, unsigned int penalty, unsigned int seconds_remaining)
Add penalty.
Use multicast socket for communication.
virtual void loop()
Code to execute in the thread.
virtual void set_team_goal(fawkes::worldinfo_gamestate_team_t our_team, fawkes::worldinfo_gamestate_goalcolor_t goal_color)
Set team and goal info.
const char * worldinfo_gamestate_goalcolor_tostring(worldinfo_gamestate_goalcolor_t goal_color)
Convert goal color to a string.
worldinfo_gamestate_team_t
Team.
virtual void send()
Send worldinfo.
virtual void set_half(fawkes::worldinfo_gamestate_half_t half)
Set current half of the game time.
const char * worldinfo_gamestate_half_tostring(worldinfo_gamestate_half_t half)
Convert half time to a string.
virtual void set_score(unsigned int score_cyan, unsigned int score_magenta)
Set score.
worldinfo_gamestate_goalcolor_t
Goal color.