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" 52 :
Thread(
"RefBoxCommThread",
Thread::OPMODE_WAITFORWAKEUP),
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();
virtual void init()
Initialize the thread.
void set_game_state(const uint32_t new_game_state)
Set game_state value.
bool msgq_empty()
Check if queue is empty.
void set_score_cyan(const uint32_t new_score_cyan)
Set score_cyan value.
void set_our_goal_color(const if_gamestate_goalcolor_t new_our_goal_color)
Set our_goal_color value.
No team, not team-specific.
Fawkes library namespace.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
uint16_t penalty() const
Get penalty value.
void set_state_team(const if_gamestate_team_t new_state_team)
Set state_team value.
void set_penalty(const uint16_t new_penalty)
Set penalty value.
virtual void set_gamestate(int game_state, fawkes::worldinfo_gamestate_team_t state_team)
Set current game state.
virtual void handle_refbox_state()
Process the information set up to now.
if_gamestate_team_t our_team() const
Get our_team value.
Thread class encapsulation of pthreads.
Mid-size league refbox repeater.
virtual void set_team_goal(fawkes::worldinfo_gamestate_team_t our_team, fawkes::worldinfo_gamestate_goalcolor_t goal_color)
Set team and goal info.
void write()
Write from local copy into BlackBoard memory.
virtual void set_handler(RefBoxStateHandler *rsh)
Set handler.
virtual bool check_connection()=0
Check if the connection is alive and reconnect.
Logger * logger
This is the Logger member used to access the logger.
virtual void loop()
Code to execute in the thread.
bool is_kickoff() const
Get kickoff value.
SoccerPenaltyInterface Fawkes BlackBoard Interface.
worldinfo_gamestate_half_t
Game time half.
SetPenaltyMessage Fawkes BlackBoard Interface Message.
virtual void add_penalty(unsigned int penalty, unsigned int seconds_remaining)
Add penalty.
Thread aspect to use blocked timing.
void msgq_pop()
Erase first message from queue.
RefBoxCommThread()
Constructor.
SwitchInterface Fawkes BlackBoard Interface.
const char * worldinfo_gamestate_team_tostring(worldinfo_gamestate_team_t team)
Convert gamestate team to a string.
Base class for exceptions in Fawkes.
virtual void refbox_process()=0
Process incoming refbox communication.
Message * msgq_first()
Get the first message from the message queue.
SetTeamColorMessage Fawkes BlackBoard Interface Message.
virtual void set_score(unsigned int score_cyan, unsigned int score_magenta)
Set score.
bool has_writer() const
Check if there is a writer for the interface.
bool msgq_first_is()
Check if first message has desired type.
SetKickoffMessage Fawkes BlackBoard Interface Message.
if_gamestate_team_t state_team() const
Get state_team value.
const char * worldinfo_gamestate_goalcolor_tostring(worldinfo_gamestate_goalcolor_t goal_color)
Convert goal color to a string.
unsigned int msgq_enqueue(Message *message)
Enqueue message at end of queue.
SetStateTeamMessage Fawkes BlackBoard Interface Message.
Remote BlackBoard refbox repeater.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
worldinfo_gamestate_team_t
Team.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
virtual void finalize()
Finalize the thread.
GameStateInterface Fawkes BlackBoard Interface.
EnableDurationMessage Fawkes BlackBoard Interface Message.
virtual unsigned int get_uint(const char *path)=0
Get value from configuration which is of type unsigned int.
void set_score_magenta(const uint32_t new_score_magenta)
Set score_magenta value.
const char * worldinfo_gamestate_half_tostring(worldinfo_gamestate_half_t half)
Convert half time to a string.
virtual void set_half(fawkes::worldinfo_gamestate_half_t half, bool kickoff)
Set current half of the game time.
Configuration * config
This is the Configuration member used to access the configuration.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
virtual float get_float(const char *path)=0
Get value from configuration which is of type float.
worldinfo_gamestate_goalcolor_t
Goal color.
void set_kickoff(const bool new_kickoff)
Set kickoff value.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
void set_half(const if_gamestate_half_t new_half)
Set half value.
SPL league refbox repeater.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
void set_our_team(const if_gamestate_team_t new_our_team)
Set our_team value.
virtual void close(Interface *interface)=0
Close interface.