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