Fawkes API
Fawkes Development Version
|
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();
const char * worldinfo_gamestate_team_tostring(worldinfo_gamestate_team_t team)
Convert gamestate team to a string.
bool msgq_first_is()
Check if first message has desired type.
bool is_kickoff() const
Get kickoff value.
void msgq_pop()
Erase first message from queue.
bool msgq_empty()
Check if queue is empty.
if_gamestate_team_t our_team() const
Get our_team value.
virtual void set_gamestate(int game_state, fawkes::worldinfo_gamestate_team_t state_team)
virtual void set_handler(RefBoxStateHandler *rsh)
Set handler.
virtual bool check_connection()=0
virtual bool get_bool(const char *path)=0
void set_our_team(const if_gamestate_team_t new_our_team)
Set our_team value.
virtual void loop()
Code to execute in the thread.
if_gamestate_team_t state_team() const
Get state_team value.
void set_penalty(const uint16_t new_penalty)
Set penalty value.
void set_our_goal_color(const if_gamestate_goalcolor_t new_our_goal_color)
Set our_goal_color value.
virtual void add_penalty(unsigned int penalty, unsigned int seconds_remaining)
No team, not team-specific.
RefBoxCommThread()
Constructor.
void set_score_magenta(const uint32_t new_score_magenta)
Set score_magenta value.
virtual void close(Interface *interface)=0
const char * worldinfo_gamestate_half_tostring(worldinfo_gamestate_half_t half)
Convert half time to a string.
const char * worldinfo_gamestate_goalcolor_tostring(worldinfo_gamestate_goalcolor_t goal_color)
Convert goal color to a string.
virtual void finalize()
Finalize the thread.
worldinfo_gamestate_goalcolor_t
Goal color.
virtual void set_team_goal(fawkes::worldinfo_gamestate_team_t our_team, fawkes::worldinfo_gamestate_goalcolor_t goal_color)
worldinfo_gamestate_team_t
Team.
void set_state_team(const if_gamestate_team_t new_state_team)
Set state_team value.
virtual void set_score(unsigned int score_cyan, unsigned int score_magenta)
bool has_writer() const
Check if there is a writer for the interface.
virtual void refbox_process()=0
void set_kickoff(const bool new_kickoff)
Set kickoff value.
virtual void init()
Initialize the thread.
void set_game_state(const uint32_t new_game_state)
Set game_state value.
void set_half(const if_gamestate_half_t new_half)
Set half value.
virtual float get_float(const char *path)=0
worldinfo_gamestate_half_t
Game time half.
virtual unsigned int get_uint(const char *path)=0
virtual std::string get_string(const char *path)=0
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
unsigned int msgq_enqueue(Message *message)
Enqueue message at end of queue.
virtual void set_half(fawkes::worldinfo_gamestate_half_t half, bool kickoff)
void set_score_cyan(const uint32_t new_score_cyan)
Set score_cyan value.
Message * msgq_first()
Get the first message from the message queue.
virtual void log_debug(const char *component, const char *format,...)=0
void write()
Write from local copy into BlackBoard memory.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
uint16_t penalty() const
Get penalty value.
virtual void handle_refbox_state()