23 #include "refbox_state_writer.h"
25 #include <netcomm/worldinfo/transceiver.h>
26 #include <utils/time/time.h>
27 #include <utils/time/clock.h>
32 #define log(...) if (__debug) {\
33 printf("%3u %s ", __counter, get_time().c_str());\
39 using namespace fawkes;
42 std::string get_time() throw()
44 Clock* c = Clock::instance();
46 char* buf =
new char[Time::TIMESTR_SIZE];
48 std::string str = buf;
50 std::string::size_type from =
51 1+str.find_first_of(
' ',
52 1+str.find_first_of(
' ',
53 1+str.find_first_of(
' ')));
54 std::string::size_type to = str.find_last_of(
' ');
55 return str.substr(from, to - from + 1);
83 for (vector<string>::const_iterator it = hosts.begin(); it != hosts.end();
93 for (map<RemoteBlackBoard*, GameStateInterface*>::iterator it = __giss.begin();
94 it != __giss.end(); it++) {
104 void RefBoxStateBBWriter::connect(
const string& host)
111 log(
"Successfully connected to %s\n", host.c_str());
112 set_gamestate(__game_state, __state_team);
113 set_score(__score_cyan, __score_magenta);
114 set_team_goal(__our_team, __our_goal_color);
118 log(
"Connecting to %s failed\n", host.c_str());
133 log(
"Setting gamestate to '%d' for team '%s'\n",
136 __game_state = game_state;
137 __state_team = state_team;
139 for (map<RemoteBlackBoard*,GameStateInterface*>::iterator it = __giss.begin(); it != __giss.end(); it++) {
213 log(
"Setting score to %u:%u (cyan:magenta)\n", score_cyan, score_magenta);
215 __score_cyan = score_cyan;
216 __score_magenta = score_magenta;
218 for (map<RemoteBlackBoard*,GameStateInterface*>::iterator it = __giss.begin(); it != __giss.end(); it++) {
234 log(
"Setting team color to '%s' and goal color to '%s'\n",
238 __our_team = our_team;
239 __our_goal_color = goal_color;
241 for (map<RemoteBlackBoard*,GameStateInterface*>::iterator it = __giss.begin(); it != __giss.end(); it++) {
264 log(
"Setting half to '%s'\n",
269 for (map<RemoteBlackBoard*,GameStateInterface*>::iterator it = __giss.begin(); it != __giss.end(); it++) {
273 gis->
set_half(GameStateInterface::HALF_FIRST);
276 gis->
set_half(GameStateInterface::HALF_SECOND);
288 log(
"Sending worldinfo\n");
290 set<RemoteBlackBoard*> erase_rbbs;
291 set<string> reconnect_hosts;
294 for (map<RemoteBlackBoard*,GameStateInterface*>::iterator it = __giss.begin(); it != __giss.end(); it++) {
297 const string host = __rbbs[rbb].c_str();
301 log(
"%u. Successfully wrote game state on %s\n", ++i, __rbbs[rbb].c_str());
303 log(
"%u. Writing game state on %s failed, reason:\n", ++i, __rbbs[rbb].c_str());
305 log(
"I will reconnect after this loop\n");
306 erase_rbbs.insert(rbb);
307 reconnect_hosts.insert(host);
310 for (set<RemoteBlackBoard*>::iterator it = erase_rbbs.begin(); it != erase_rbbs.end(); it++) {
315 for (set<std::string>::iterator it = reconnect_hosts.begin(); it != reconnect_hosts.end(); it++) {
316 std::string host = *it;
317 log(
"Reconnecting to %s\n", host.c_str());
321 log(
"Sending worldinfo done\n");
virtual void set_team_goal(fawkes::worldinfo_gamestate_team_t our_team, fawkes::worldinfo_gamestate_goalcolor_t goal_color)
Set team and goal info.
virtual void set_gamestate(int game_state, fawkes::worldinfo_gamestate_team_t state_team)
Set current game state.
void set_game_state(const uint32_t new_game_state)
Set game_state value.
void set_score_cyan(const uint32_t new_score_cyan)
Set score_cyan value.
Referee drops ball, both teams can wrestle for the ball.
void set_our_goal_color(const if_gamestate_goalcolor_t new_our_goal_color)
Set our_goal_color value.
No team, not team-specific.
void set_state_team(const if_gamestate_team_t new_state_team)
Set state_team value.
This is supposed to be the central clock in Fawkes.
virtual void set_half(fawkes::worldinfo_gamestate_half_t half)
Set current half of the game time.
A class for handling time.
void write()
Write from local copy into BlackBoard memory.
void str_r(char *s, bool utc=false)
Output function.
virtual void send()
Send worldinfo.
worldinfo_gamestate_half_t
Game time half.
const char * worldinfo_gamestate_team_tostring(worldinfo_gamestate_team_t team)
Convert gamestate team to a string.
virtual void close(Interface *interface)
Close interface.
Base class for exceptions in Fawkes.
virtual ~RefBoxStateBBWriter()
Destructor.
const char * worldinfo_gamestate_goalcolor_tostring(worldinfo_gamestate_goalcolor_t goal_color)
Convert goal color to a string.
void print_trace()
Prints trace to stderr.
virtual void set_score(unsigned int score_cyan, unsigned int score_magenta)
Set score.
RefBoxStateBBWriter(std::vector< std::string > hosts, bool debug=false)
Constructor.
worldinfo_gamestate_team_t
Team.
GameStateInterface Fawkes BlackBoard Interface.
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.
Time now() const
Get the current time.
uint32_t score_cyan() const
Get score_cyan value.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier)
Open interface for writing.
worldinfo_gamestate_goalcolor_t
Goal color.
void set_half(const if_gamestate_half_t new_half)
Set half value.
void set_our_team(const if_gamestate_team_t new_our_team)
Set our_team value.