24 #include "comm_thread.h"
25 #include "processor/remotebb.h"
27 # include "processor/msl2010.h"
30 # include "processor/spl.h"
33 #include <interfaces/GameStateInterface.h>
34 #include <interfaces/SwitchInterface.h>
36 # include <interfaces/SoccerPenaltyInterface.h>
39 #define CONFPREFIX "/plugins/refboxcomm"
41 using namespace fawkes;
64 __gamestate_if = NULL;
70 __last_score_cyan = 0xFFFFFFFF;
71 __last_score_magenta = 0xFFFFFFFF;
72 __last_gamestate = -1;
76 __gamestate_modified =
false;
78 std::string processor =
"";
84 if (league ==
"MSL" || league ==
"SPL") {
88 if (processor ==
"") {
89 throw Exception(
"No valid processor defined");
92 __cfg_beep_on_change =
true;
93 __cfg_beep_frequency = 1000.;
94 __cfg_beep_duration = 0.5;
96 __cfg_beep_on_change =
config->
get_bool(CONFPREFIX
"/beep_on_change");
104 if (__cfg_beep_on_change) {
108 if ( processor ==
"MSL" ) {
111 unsigned int refbox_port =
config->
get_uint(CONFPREFIX
"/MSL/port");
113 refbox_host.c_str(), refbox_port);
115 throw Exception(
"MSL2010 support not available at compile time");
117 }
else if ( processor ==
"SPL" ) {
119 unsigned int refbox_port =
config->
get_uint(CONFPREFIX
"/SPL/port");
123 __team_number, __player_number);
125 throw Exception(
"SPL support not available at compile time");
127 }
else if ( processor ==
"RemoteBB" ) {
129 unsigned int bb_port =
config->
get_uint(CONFPREFIX
"/RemoteBB/port");
130 std::string iface_id =
config->
get_string(CONFPREFIX
"/RemoteBB/interface_id");
132 bb_host.c_str(), bb_port,
135 throw Exception(
"Processor %s is not supported by refboxcomm plugin",
169 __gamestate_modified =
true;
174 __gamestate_modified =
true;
179 __gamestate_modified =
true;
184 while (!__penalty_if->msgq_empty()) {
189 __gamestate_modified =
true;
191 __penalty_if->msgq_pop();
197 if (__gamestate_modified) {
198 if (__cfg_beep_on_change && __beep_if->
has_writer()) {
202 __cfg_beep_frequency));
206 __gamestate_if->
write();
208 __penalty_if->write();
210 __gamestate_modified =
false;
219 if (game_state != __last_gamestate) {
220 __last_gamestate = game_state;
221 __gamestate_modified =
true;
226 switch (state_team) {
228 __gamestate_if->
set_state_team(GameStateInterface::TEAM_NONE);
break;
230 __gamestate_if->
set_state_team(GameStateInterface::TEAM_CYAN);
break;
232 __gamestate_if->
set_state_team(GameStateInterface::TEAM_MAGENTA);
break;
234 __gamestate_if->
set_state_team(GameStateInterface::TEAM_BOTH);
break;
242 if ( (score_cyan != __last_score_cyan) || (score_magenta != __last_score_magenta) ) {
243 __last_score_cyan = score_cyan;
244 __last_score_magenta = score_magenta;
245 __gamestate_modified =
true;
248 score_cyan, score_magenta);
259 if (our_team != __our_team)
264 __our_team = our_team;
267 __gamestate_if->
set_our_team(GameStateInterface::TEAM_CYAN);
270 __gamestate_if->
set_our_team(GameStateInterface::TEAM_MAGENTA);
275 __gamestate_modified =
true;
278 if (goal_color != __our_goal_color)
282 __our_goal_color = goal_color;
292 __gamestate_modified =
true;
301 if (half != __last_half) {
303 __gamestate_modified =
true;
307 kickoff ?
"yes" :
"no");
311 __gamestate_if->
set_half(GameStateInterface::HALF_FIRST);
break;
313 __gamestate_if->
set_half(GameStateInterface::HALF_SECOND);
break;
317 if (kickoff != __kickoff)
320 __gamestate_modified =
true;
328 unsigned int seconds_remaining)
331 if ((penalty != __penalty_if->penalty()) ||
332 (seconds_remaining != __penalty_if->remaining()))
334 __gamestate_modified =
true;
336 penalty, seconds_remaining);
337 __penalty_if->set_penalty(penalty);
338 __penalty_if->set_remaining(seconds_remaining);
348 __gamestate_if->
write();