24 #include "comm_thread.h" 26 #include "processor/remotebb.h" 28 # include "processor/msl2010.h" 31 # include "processor/spl.h" 34 #include <interfaces/GameStateInterface.h> 35 #include <interfaces/SwitchInterface.h> 37 # include <interfaces/SoccerPenaltyInterface.h> 40 #define CONFPREFIX "/plugins/refboxcomm" 52 :
Thread(
"RefBoxCommThread",
Thread::OPMODE_WAITFORWAKEUP),
69 last_score_cyan_ = 0xFFFFFFFF;
70 last_score_magenta_ = 0xFFFFFFFF;
75 gamestate_modified_ =
false;
77 std::string processor =
"";
83 if (league ==
"MSL" || league ==
"SPL") {
87 if (processor ==
"") {
88 throw Exception(
"No valid processor defined");
91 cfg_beep_on_change_ =
true;
92 cfg_beep_frequency_ = 1000.;
93 cfg_beep_duration_ = 0.5;
95 cfg_beep_on_change_ =
config->
get_bool(CONFPREFIX
"/beep_on_change");
106 if (cfg_beep_on_change_) {
110 if (processor ==
"MSL") {
113 unsigned int refbox_port =
config->
get_uint(CONFPREFIX
"/MSL/port");
116 throw Exception(
"MSL2010 support not available at compile time");
118 }
else if (processor ==
"SPL") {
120 unsigned int refbox_port =
config->
get_uint(CONFPREFIX
"/SPL/port");
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");
134 throw Exception(
"Processor %s is not supported by refboxcomm plugin", processor.c_str());
166 gamestate_modified_ =
true;
171 gamestate_modified_ =
true;
176 gamestate_modified_ =
true;
181 while (!penalty_if_->msgq_empty()) {
186 gamestate_modified_ =
true;
188 penalty_if_->msgq_pop();
194 if (gamestate_modified_) {
195 if (cfg_beep_on_change_ && beep_if_->
has_writer()) {
203 gamestate_if_->
write();
205 penalty_if_->write();
207 gamestate_modified_ =
false;
214 if (game_state != last_gamestate_) {
215 last_gamestate_ = game_state;
216 gamestate_modified_ =
true;
219 "Gamestate: %d State team: %s",
223 switch (state_team) {
235 if ((score_cyan != last_score_cyan_) || (score_magenta != last_score_magenta_)) {
236 last_score_cyan_ = score_cyan;
237 last_score_magenta_ = score_magenta;
238 gamestate_modified_ =
true;
240 logger->
log_debug(
"RefBoxCommThread",
"Score (cyan:magenta): %u:%u", score_cyan, score_magenta);
250 if (our_team != our_team_) {
253 our_team_ = our_team;
259 gamestate_modified_ =
true;
262 if (goal_color != our_goal_color_) {
266 our_goal_color_ = goal_color;
267 switch (goal_color) {
271 gamestate_modified_ =
true;
278 if (half != last_half_) {
280 gamestate_modified_ =
true;
283 "Half time: %s (Kickoff? %s)",
285 kickoff ?
"yes" :
"no");
293 if (kickoff != kickoff_) {
295 gamestate_modified_ =
true;
304 if ((penalty != penalty_if_->penalty()) || (seconds_remaining != penalty_if_->remaining())) {
305 gamestate_modified_ =
true;
307 "Penalty %u (%u sec remaining)",
310 penalty_if_->set_penalty(penalty);
311 penalty_if_->set_remaining(seconds_remaining);
319 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.