Fawkes API  Fawkes Development Version
GameStateInterface.cpp
1 
2 /***************************************************************************
3  * GameStateInterface.cpp - Fawkes BlackBoard Interface - GameStateInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2008 Tim Niemueller
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <interfaces/GameStateInterface.h>
25 
26 #include <core/exceptions/software.h>
27 
28 #include <map>
29 #include <string>
30 #include <cstring>
31 #include <cstdlib>
32 
33 namespace fawkes {
34 
35 /** @class GameStateInterface <interfaces/GameStateInterface.h>
36  * GameStateInterface Fawkes BlackBoard Interface.
37  *
38  This interface provides access to the current game state. It is closely related to
39  the WorldInfo network protocol.
40  @see WorldInfoTransceiver
41 
42  * @ingroup FawkesInterfaces
43  */
44 
45 
46 /** GS_FROZEN constant */
47 const uint32_t GameStateInterface::GS_FROZEN = 0u;
48 /** GS_PLAY constant */
49 const uint32_t GameStateInterface::GS_PLAY = 1u;
50 /** GS_KICK_OFF constant */
51 const uint32_t GameStateInterface::GS_KICK_OFF = 2u;
52 /** GS_DROP_BALL constant */
53 const uint32_t GameStateInterface::GS_DROP_BALL = 3u;
54 /** GS_PENALTY constant */
55 const uint32_t GameStateInterface::GS_PENALTY = 4u;
56 /** GS_CORNER_KICK constant */
57 const uint32_t GameStateInterface::GS_CORNER_KICK = 5u;
58 /** GS_THROW_IN constant */
59 const uint32_t GameStateInterface::GS_THROW_IN = 6u;
60 /** GS_FREE_KICK constant */
61 const uint32_t GameStateInterface::GS_FREE_KICK = 7u;
62 /** GS_GOAL_KICK constant */
63 const uint32_t GameStateInterface::GS_GOAL_KICK = 8u;
64 /** GS_HALF_TIME constant */
65 const uint32_t GameStateInterface::GS_HALF_TIME = 9u;
66 /** GS_SPL_INITIAL constant */
67 const uint32_t GameStateInterface::GS_SPL_INITIAL = 0u;
68 /** GS_SPL_READY constant */
69 const uint32_t GameStateInterface::GS_SPL_READY = 1u;
70 /** GS_SPL_SET constant */
71 const uint32_t GameStateInterface::GS_SPL_SET = 2u;
72 /** GS_SPL_PLAY constant */
73 const uint32_t GameStateInterface::GS_SPL_PLAY = 3u;
74 /** GS_SPL_FINISHED constant */
75 const uint32_t GameStateInterface::GS_SPL_FINISHED = 4u;
76 
77 /** Constructor */
78 GameStateInterface::GameStateInterface() : Interface()
79 {
80  data_size = sizeof(GameStateInterface_data_t);
81  data_ptr = malloc(data_size);
82  data = (GameStateInterface_data_t *)data_ptr;
83  data_ts = (interface_data_ts_t *)data_ptr;
84  memset(data_ptr, 0, data_size);
85  enum_map_if_gamestate_team_t[(int)TEAM_NONE] = "TEAM_NONE";
86  enum_map_if_gamestate_team_t[(int)TEAM_CYAN] = "TEAM_CYAN";
87  enum_map_if_gamestate_team_t[(int)TEAM_MAGENTA] = "TEAM_MAGENTA";
88  enum_map_if_gamestate_team_t[(int)TEAM_BOTH] = "TEAM_BOTH";
89  enum_map_if_gamestate_goalcolor_t[(int)GOAL_BLUE] = "GOAL_BLUE";
90  enum_map_if_gamestate_goalcolor_t[(int)GOAL_YELLOW] = "GOAL_YELLOW";
91  enum_map_if_gamestate_half_t[(int)HALF_FIRST] = "HALF_FIRST";
92  enum_map_if_gamestate_half_t[(int)HALF_SECOND] = "HALF_SECOND";
93  enum_map_if_gamestate_role_t[(int)ROLE_GOALIE] = "ROLE_GOALIE";
94  enum_map_if_gamestate_role_t[(int)ROLE_DEFENDER] = "ROLE_DEFENDER";
95  enum_map_if_gamestate_role_t[(int)ROLE_MID_LEFT] = "ROLE_MID_LEFT";
96  enum_map_if_gamestate_role_t[(int)ROLE_MID_RIGHT] = "ROLE_MID_RIGHT";
97  enum_map_if_gamestate_role_t[(int)ROLE_ATTACKER] = "ROLE_ATTACKER";
98  add_fieldinfo(IFT_UINT32, "game_state", 1, &data->game_state);
99  add_fieldinfo(IFT_ENUM, "state_team", 1, &data->state_team, "if_gamestate_team_t", &enum_map_if_gamestate_team_t);
100  add_fieldinfo(IFT_ENUM, "our_team", 1, &data->our_team, "if_gamestate_team_t", &enum_map_if_gamestate_team_t);
101  add_fieldinfo(IFT_ENUM, "our_goal_color", 1, &data->our_goal_color, "if_gamestate_goalcolor_t", &enum_map_if_gamestate_goalcolor_t);
102  add_fieldinfo(IFT_ENUM, "half", 1, &data->half, "if_gamestate_half_t", &enum_map_if_gamestate_half_t);
103  add_fieldinfo(IFT_BOOL, "kickoff", 1, &data->kickoff);
104  add_fieldinfo(IFT_ENUM, "role", 1, &data->role, "if_gamestate_role_t", &enum_map_if_gamestate_role_t);
105  add_fieldinfo(IFT_UINT32, "score_cyan", 1, &data->score_cyan);
106  add_fieldinfo(IFT_UINT32, "score_magenta", 1, &data->score_magenta);
107  add_messageinfo("SetTeamColorMessage");
108  add_messageinfo("SetKickoffMessage");
109  add_messageinfo("SetStateTeamMessage");
110  unsigned char tmp_hash[] = {0xf5, 0x19, 0x26, 0x77, 0x6, 0x54, 0x44, 0xb4, 0xe1, 0x61, 0x40, 0x2a, 0x65, 0xfc, 0xaf, 0xa1};
111  set_hash(tmp_hash);
112 }
113 
114 /** Destructor */
115 GameStateInterface::~GameStateInterface()
116 {
117  free(data_ptr);
118 }
119 /** Convert if_gamestate_team_t constant to string.
120  * @param value value to convert to string
121  * @return constant value as string.
122  */
123 const char *
125 {
126  switch (value) {
127  case TEAM_NONE: return "TEAM_NONE";
128  case TEAM_CYAN: return "TEAM_CYAN";
129  case TEAM_MAGENTA: return "TEAM_MAGENTA";
130  case TEAM_BOTH: return "TEAM_BOTH";
131  default: return "UNKNOWN";
132  }
133 }
134 /** Convert if_gamestate_goalcolor_t constant to string.
135  * @param value value to convert to string
136  * @return constant value as string.
137  */
138 const char *
140 {
141  switch (value) {
142  case GOAL_BLUE: return "GOAL_BLUE";
143  case GOAL_YELLOW: return "GOAL_YELLOW";
144  default: return "UNKNOWN";
145  }
146 }
147 /** Convert if_gamestate_half_t constant to string.
148  * @param value value to convert to string
149  * @return constant value as string.
150  */
151 const char *
153 {
154  switch (value) {
155  case HALF_FIRST: return "HALF_FIRST";
156  case HALF_SECOND: return "HALF_SECOND";
157  default: return "UNKNOWN";
158  }
159 }
160 /** Convert if_gamestate_role_t constant to string.
161  * @param value value to convert to string
162  * @return constant value as string.
163  */
164 const char *
166 {
167  switch (value) {
168  case ROLE_GOALIE: return "ROLE_GOALIE";
169  case ROLE_DEFENDER: return "ROLE_DEFENDER";
170  case ROLE_MID_LEFT: return "ROLE_MID_LEFT";
171  case ROLE_MID_RIGHT: return "ROLE_MID_RIGHT";
172  case ROLE_ATTACKER: return "ROLE_ATTACKER";
173  default: return "UNKNOWN";
174  }
175 }
176 /* Methods */
177 /** Get game_state value.
178  * Current game state
179  * @return game_state value
180  */
181 uint32_t
183 {
184  return data->game_state;
185 }
186 
187 /** Get maximum length of game_state value.
188  * @return length of game_state value, can be length of the array or number of
189  * maximum number of characters for a string
190  */
191 size_t
193 {
194  return 1;
195 }
196 
197 /** Set game_state value.
198  * Current game state
199  * @param new_game_state new game_state value
200  */
201 void
202 GameStateInterface::set_game_state(const uint32_t new_game_state)
203 {
204  data->game_state = new_game_state;
205  data_changed = true;
206 }
207 
208 /** Get state_team value.
209  * Team referred to by game state
210  * @return state_team value
211  */
214 {
215  return (GameStateInterface::if_gamestate_team_t)data->state_team;
216 }
217 
218 /** Get maximum length of state_team value.
219  * @return length of state_team value, can be length of the array or number of
220  * maximum number of characters for a string
221  */
222 size_t
224 {
225  return 1;
226 }
227 
228 /** Set state_team value.
229  * Team referred to by game state
230  * @param new_state_team new state_team value
231  */
232 void
234 {
235  data->state_team = new_state_team;
236  data_changed = true;
237 }
238 
239 /** Get our_team value.
240  * Our team color
241  * @return our_team value
242  */
245 {
246  return (GameStateInterface::if_gamestate_team_t)data->our_team;
247 }
248 
249 /** Get maximum length of our_team value.
250  * @return length of our_team value, can be length of the array or number of
251  * maximum number of characters for a string
252  */
253 size_t
255 {
256  return 1;
257 }
258 
259 /** Set our_team value.
260  * Our team color
261  * @param new_our_team new our_team value
262  */
263 void
265 {
266  data->our_team = new_our_team;
267  data_changed = true;
268 }
269 
270 /** Get our_goal_color value.
271  * Our own goal color
272  * @return our_goal_color value
273  */
276 {
277  return (GameStateInterface::if_gamestate_goalcolor_t)data->our_goal_color;
278 }
279 
280 /** Get maximum length of our_goal_color value.
281  * @return length of our_goal_color value, can be length of the array or number of
282  * maximum number of characters for a string
283  */
284 size_t
286 {
287  return 1;
288 }
289 
290 /** Set our_goal_color value.
291  * Our own goal color
292  * @param new_our_goal_color new our_goal_color value
293  */
294 void
296 {
297  data->our_goal_color = new_our_goal_color;
298  data_changed = true;
299 }
300 
301 /** Get half value.
302  * Current game half
303  * @return half value
304  */
307 {
308  return (GameStateInterface::if_gamestate_half_t)data->half;
309 }
310 
311 /** Get maximum length of half value.
312  * @return length of half value, can be length of the array or number of
313  * maximum number of characters for a string
314  */
315 size_t
317 {
318  return 1;
319 }
320 
321 /** Set half value.
322  * Current game half
323  * @param new_half new half value
324  */
325 void
327 {
328  data->half = new_half;
329  data_changed = true;
330 }
331 
332 /** Get kickoff value.
333  * Whether we have kickoff
334  * @return kickoff value
335  */
336 bool
338 {
339  return data->kickoff;
340 }
341 
342 /** Get maximum length of kickoff value.
343  * @return length of kickoff value, can be length of the array or number of
344  * maximum number of characters for a string
345  */
346 size_t
348 {
349  return 1;
350 }
351 
352 /** Set kickoff value.
353  * Whether we have kickoff
354  * @param new_kickoff new kickoff value
355  */
356 void
357 GameStateInterface::set_kickoff(const bool new_kickoff)
358 {
359  data->kickoff = new_kickoff;
360  data_changed = true;
361 }
362 
363 /** Get role value.
364  * Current role of this robot
365  * @return role value
366  */
369 {
370  return (GameStateInterface::if_gamestate_role_t)data->role;
371 }
372 
373 /** Get maximum length of role value.
374  * @return length of role value, can be length of the array or number of
375  * maximum number of characters for a string
376  */
377 size_t
379 {
380  return 1;
381 }
382 
383 /** Set role value.
384  * Current role of this robot
385  * @param new_role new role value
386  */
387 void
389 {
390  data->role = new_role;
391  data_changed = true;
392 }
393 
394 /** Get score_cyan value.
395  * Score of team cyan
396  * @return score_cyan value
397  */
398 uint32_t
400 {
401  return data->score_cyan;
402 }
403 
404 /** Get maximum length of score_cyan value.
405  * @return length of score_cyan value, can be length of the array or number of
406  * maximum number of characters for a string
407  */
408 size_t
410 {
411  return 1;
412 }
413 
414 /** Set score_cyan value.
415  * Score of team cyan
416  * @param new_score_cyan new score_cyan value
417  */
418 void
419 GameStateInterface::set_score_cyan(const uint32_t new_score_cyan)
420 {
421  data->score_cyan = new_score_cyan;
422  data_changed = true;
423 }
424 
425 /** Get score_magenta value.
426  * Score of team magenta
427  * @return score_magenta value
428  */
429 uint32_t
431 {
432  return data->score_magenta;
433 }
434 
435 /** Get maximum length of score_magenta value.
436  * @return length of score_magenta value, can be length of the array or number of
437  * maximum number of characters for a string
438  */
439 size_t
441 {
442  return 1;
443 }
444 
445 /** Set score_magenta value.
446  * Score of team magenta
447  * @param new_score_magenta new score_magenta value
448  */
449 void
450 GameStateInterface::set_score_magenta(const uint32_t new_score_magenta)
451 {
452  data->score_magenta = new_score_magenta;
453  data_changed = true;
454 }
455 
456 /* =========== message create =========== */
457 Message *
459 {
460  if ( strncmp("SetTeamColorMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
461  return new SetTeamColorMessage();
462  } else if ( strncmp("SetKickoffMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
463  return new SetKickoffMessage();
464  } else if ( strncmp("SetStateTeamMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
465  return new SetStateTeamMessage();
466  } else {
467  throw UnknownTypeException("The given type '%s' does not match any known "
468  "message type for this interface type.", type);
469  }
470 }
471 
472 
473 /** Copy values from other interface.
474  * @param other other interface to copy values from
475  */
476 void
478 {
479  const GameStateInterface *oi = dynamic_cast<const GameStateInterface *>(other);
480  if (oi == NULL) {
481  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
482  type(), other->type());
483  }
484  memcpy(data, oi->data, sizeof(GameStateInterface_data_t));
485 }
486 
487 const char *
488 GameStateInterface::enum_tostring(const char *enumtype, int val) const
489 {
490  if (strcmp(enumtype, "if_gamestate_team_t") == 0) {
491  return tostring_if_gamestate_team_t((if_gamestate_team_t)val);
492  }
493  if (strcmp(enumtype, "if_gamestate_goalcolor_t") == 0) {
494  return tostring_if_gamestate_goalcolor_t((if_gamestate_goalcolor_t)val);
495  }
496  if (strcmp(enumtype, "if_gamestate_half_t") == 0) {
497  return tostring_if_gamestate_half_t((if_gamestate_half_t)val);
498  }
499  if (strcmp(enumtype, "if_gamestate_role_t") == 0) {
500  return tostring_if_gamestate_role_t((if_gamestate_role_t)val);
501  }
502  throw UnknownTypeException("Unknown enum type %s", enumtype);
503 }
504 
505 /* =========== messages =========== */
506 /** @class GameStateInterface::SetTeamColorMessage <interfaces/GameStateInterface.h>
507  * SetTeamColorMessage Fawkes BlackBoard Interface Message.
508  *
509 
510  */
511 
512 
513 /** Constructor with initial values.
514  * @param ini_our_team initial value for our_team
515  */
517 {
518  data_size = sizeof(SetTeamColorMessage_data_t);
519  data_ptr = malloc(data_size);
520  memset(data_ptr, 0, data_size);
521  data = (SetTeamColorMessage_data_t *)data_ptr;
523  data->our_team = ini_our_team;
524  enum_map_if_gamestate_team_t[(int)TEAM_NONE] = "TEAM_NONE";
525  enum_map_if_gamestate_team_t[(int)TEAM_CYAN] = "TEAM_CYAN";
526  enum_map_if_gamestate_team_t[(int)TEAM_MAGENTA] = "TEAM_MAGENTA";
527  enum_map_if_gamestate_team_t[(int)TEAM_BOTH] = "TEAM_BOTH";
528  enum_map_if_gamestate_goalcolor_t[(int)GOAL_BLUE] = "GOAL_BLUE";
529  enum_map_if_gamestate_goalcolor_t[(int)GOAL_YELLOW] = "GOAL_YELLOW";
530  enum_map_if_gamestate_half_t[(int)HALF_FIRST] = "HALF_FIRST";
531  enum_map_if_gamestate_half_t[(int)HALF_SECOND] = "HALF_SECOND";
532  enum_map_if_gamestate_role_t[(int)ROLE_GOALIE] = "ROLE_GOALIE";
533  enum_map_if_gamestate_role_t[(int)ROLE_DEFENDER] = "ROLE_DEFENDER";
534  enum_map_if_gamestate_role_t[(int)ROLE_MID_LEFT] = "ROLE_MID_LEFT";
535  enum_map_if_gamestate_role_t[(int)ROLE_MID_RIGHT] = "ROLE_MID_RIGHT";
536  enum_map_if_gamestate_role_t[(int)ROLE_ATTACKER] = "ROLE_ATTACKER";
537  add_fieldinfo(IFT_ENUM, "our_team", 1, &data->our_team, "if_gamestate_team_t", &enum_map_if_gamestate_team_t);
538 }
539 /** Constructor */
541 {
542  data_size = sizeof(SetTeamColorMessage_data_t);
543  data_ptr = malloc(data_size);
544  memset(data_ptr, 0, data_size);
545  data = (SetTeamColorMessage_data_t *)data_ptr;
547  enum_map_if_gamestate_team_t[(int)TEAM_NONE] = "TEAM_NONE";
548  enum_map_if_gamestate_team_t[(int)TEAM_CYAN] = "TEAM_CYAN";
549  enum_map_if_gamestate_team_t[(int)TEAM_MAGENTA] = "TEAM_MAGENTA";
550  enum_map_if_gamestate_team_t[(int)TEAM_BOTH] = "TEAM_BOTH";
551  enum_map_if_gamestate_goalcolor_t[(int)GOAL_BLUE] = "GOAL_BLUE";
552  enum_map_if_gamestate_goalcolor_t[(int)GOAL_YELLOW] = "GOAL_YELLOW";
553  enum_map_if_gamestate_half_t[(int)HALF_FIRST] = "HALF_FIRST";
554  enum_map_if_gamestate_half_t[(int)HALF_SECOND] = "HALF_SECOND";
555  enum_map_if_gamestate_role_t[(int)ROLE_GOALIE] = "ROLE_GOALIE";
556  enum_map_if_gamestate_role_t[(int)ROLE_DEFENDER] = "ROLE_DEFENDER";
557  enum_map_if_gamestate_role_t[(int)ROLE_MID_LEFT] = "ROLE_MID_LEFT";
558  enum_map_if_gamestate_role_t[(int)ROLE_MID_RIGHT] = "ROLE_MID_RIGHT";
559  enum_map_if_gamestate_role_t[(int)ROLE_ATTACKER] = "ROLE_ATTACKER";
560  add_fieldinfo(IFT_ENUM, "our_team", 1, &data->our_team, "if_gamestate_team_t", &enum_map_if_gamestate_team_t);
561 }
562 
563 /** Destructor */
565 {
566  free(data_ptr);
567 }
568 
569 /** Copy constructor.
570  * @param m message to copy from
571  */
573 {
574  data_size = m->data_size;
575  data_ptr = malloc(data_size);
576  memcpy(data_ptr, m->data_ptr, data_size);
577  data = (SetTeamColorMessage_data_t *)data_ptr;
579 }
580 
581 /* Methods */
582 /** Get our_team value.
583  * Our team color
584  * @return our_team value
585  */
588 {
589  return (GameStateInterface::if_gamestate_team_t)data->our_team;
590 }
591 
592 /** Get maximum length of our_team value.
593  * @return length of our_team value, can be length of the array or number of
594  * maximum number of characters for a string
595  */
596 size_t
598 {
599  return 1;
600 }
601 
602 /** Set our_team value.
603  * Our team color
604  * @param new_our_team new our_team value
605  */
606 void
608 {
609  data->our_team = new_our_team;
610 }
611 
612 /** Clone this message.
613  * Produces a message of the same type as this message and copies the
614  * data to the new message.
615  * @return clone of this message
616  */
617 Message *
619 {
621 }
622 /** @class GameStateInterface::SetKickoffMessage <interfaces/GameStateInterface.h>
623  * SetKickoffMessage Fawkes BlackBoard Interface Message.
624  *
625 
626  */
627 
628 
629 /** Constructor with initial values.
630  * @param ini_kickoff initial value for kickoff
631  */
632 GameStateInterface::SetKickoffMessage::SetKickoffMessage(const bool ini_kickoff) : Message("SetKickoffMessage")
633 {
634  data_size = sizeof(SetKickoffMessage_data_t);
635  data_ptr = malloc(data_size);
636  memset(data_ptr, 0, data_size);
637  data = (SetKickoffMessage_data_t *)data_ptr;
639  data->kickoff = ini_kickoff;
640  enum_map_if_gamestate_team_t[(int)TEAM_NONE] = "TEAM_NONE";
641  enum_map_if_gamestate_team_t[(int)TEAM_CYAN] = "TEAM_CYAN";
642  enum_map_if_gamestate_team_t[(int)TEAM_MAGENTA] = "TEAM_MAGENTA";
643  enum_map_if_gamestate_team_t[(int)TEAM_BOTH] = "TEAM_BOTH";
644  enum_map_if_gamestate_goalcolor_t[(int)GOAL_BLUE] = "GOAL_BLUE";
645  enum_map_if_gamestate_goalcolor_t[(int)GOAL_YELLOW] = "GOAL_YELLOW";
646  enum_map_if_gamestate_half_t[(int)HALF_FIRST] = "HALF_FIRST";
647  enum_map_if_gamestate_half_t[(int)HALF_SECOND] = "HALF_SECOND";
648  enum_map_if_gamestate_role_t[(int)ROLE_GOALIE] = "ROLE_GOALIE";
649  enum_map_if_gamestate_role_t[(int)ROLE_DEFENDER] = "ROLE_DEFENDER";
650  enum_map_if_gamestate_role_t[(int)ROLE_MID_LEFT] = "ROLE_MID_LEFT";
651  enum_map_if_gamestate_role_t[(int)ROLE_MID_RIGHT] = "ROLE_MID_RIGHT";
652  enum_map_if_gamestate_role_t[(int)ROLE_ATTACKER] = "ROLE_ATTACKER";
653  add_fieldinfo(IFT_BOOL, "kickoff", 1, &data->kickoff);
654 }
655 /** Constructor */
657 {
658  data_size = sizeof(SetKickoffMessage_data_t);
659  data_ptr = malloc(data_size);
660  memset(data_ptr, 0, data_size);
661  data = (SetKickoffMessage_data_t *)data_ptr;
663  enum_map_if_gamestate_team_t[(int)TEAM_NONE] = "TEAM_NONE";
664  enum_map_if_gamestate_team_t[(int)TEAM_CYAN] = "TEAM_CYAN";
665  enum_map_if_gamestate_team_t[(int)TEAM_MAGENTA] = "TEAM_MAGENTA";
666  enum_map_if_gamestate_team_t[(int)TEAM_BOTH] = "TEAM_BOTH";
667  enum_map_if_gamestate_goalcolor_t[(int)GOAL_BLUE] = "GOAL_BLUE";
668  enum_map_if_gamestate_goalcolor_t[(int)GOAL_YELLOW] = "GOAL_YELLOW";
669  enum_map_if_gamestate_half_t[(int)HALF_FIRST] = "HALF_FIRST";
670  enum_map_if_gamestate_half_t[(int)HALF_SECOND] = "HALF_SECOND";
671  enum_map_if_gamestate_role_t[(int)ROLE_GOALIE] = "ROLE_GOALIE";
672  enum_map_if_gamestate_role_t[(int)ROLE_DEFENDER] = "ROLE_DEFENDER";
673  enum_map_if_gamestate_role_t[(int)ROLE_MID_LEFT] = "ROLE_MID_LEFT";
674  enum_map_if_gamestate_role_t[(int)ROLE_MID_RIGHT] = "ROLE_MID_RIGHT";
675  enum_map_if_gamestate_role_t[(int)ROLE_ATTACKER] = "ROLE_ATTACKER";
676  add_fieldinfo(IFT_BOOL, "kickoff", 1, &data->kickoff);
677 }
678 
679 /** Destructor */
681 {
682  free(data_ptr);
683 }
684 
685 /** Copy constructor.
686  * @param m message to copy from
687  */
689 {
690  data_size = m->data_size;
691  data_ptr = malloc(data_size);
692  memcpy(data_ptr, m->data_ptr, data_size);
693  data = (SetKickoffMessage_data_t *)data_ptr;
695 }
696 
697 /* Methods */
698 /** Get kickoff value.
699  * Whether we have kickoff
700  * @return kickoff value
701  */
702 bool
704 {
705  return data->kickoff;
706 }
707 
708 /** Get maximum length of kickoff value.
709  * @return length of kickoff value, can be length of the array or number of
710  * maximum number of characters for a string
711  */
712 size_t
714 {
715  return 1;
716 }
717 
718 /** Set kickoff value.
719  * Whether we have kickoff
720  * @param new_kickoff new kickoff value
721  */
722 void
724 {
725  data->kickoff = new_kickoff;
726 }
727 
728 /** Clone this message.
729  * Produces a message of the same type as this message and copies the
730  * data to the new message.
731  * @return clone of this message
732  */
733 Message *
735 {
736  return new GameStateInterface::SetKickoffMessage(this);
737 }
738 /** @class GameStateInterface::SetStateTeamMessage <interfaces/GameStateInterface.h>
739  * SetStateTeamMessage Fawkes BlackBoard Interface Message.
740  *
741 
742  */
743 
744 
745 /** Constructor with initial values.
746  * @param ini_state_team initial value for state_team
747  */
749 {
750  data_size = sizeof(SetStateTeamMessage_data_t);
751  data_ptr = malloc(data_size);
752  memset(data_ptr, 0, data_size);
753  data = (SetStateTeamMessage_data_t *)data_ptr;
755  data->state_team = ini_state_team;
756  enum_map_if_gamestate_team_t[(int)TEAM_NONE] = "TEAM_NONE";
757  enum_map_if_gamestate_team_t[(int)TEAM_CYAN] = "TEAM_CYAN";
758  enum_map_if_gamestate_team_t[(int)TEAM_MAGENTA] = "TEAM_MAGENTA";
759  enum_map_if_gamestate_team_t[(int)TEAM_BOTH] = "TEAM_BOTH";
760  enum_map_if_gamestate_goalcolor_t[(int)GOAL_BLUE] = "GOAL_BLUE";
761  enum_map_if_gamestate_goalcolor_t[(int)GOAL_YELLOW] = "GOAL_YELLOW";
762  enum_map_if_gamestate_half_t[(int)HALF_FIRST] = "HALF_FIRST";
763  enum_map_if_gamestate_half_t[(int)HALF_SECOND] = "HALF_SECOND";
764  enum_map_if_gamestate_role_t[(int)ROLE_GOALIE] = "ROLE_GOALIE";
765  enum_map_if_gamestate_role_t[(int)ROLE_DEFENDER] = "ROLE_DEFENDER";
766  enum_map_if_gamestate_role_t[(int)ROLE_MID_LEFT] = "ROLE_MID_LEFT";
767  enum_map_if_gamestate_role_t[(int)ROLE_MID_RIGHT] = "ROLE_MID_RIGHT";
768  enum_map_if_gamestate_role_t[(int)ROLE_ATTACKER] = "ROLE_ATTACKER";
769  add_fieldinfo(IFT_ENUM, "state_team", 1, &data->state_team, "if_gamestate_team_t", &enum_map_if_gamestate_team_t);
770 }
771 /** Constructor */
773 {
774  data_size = sizeof(SetStateTeamMessage_data_t);
775  data_ptr = malloc(data_size);
776  memset(data_ptr, 0, data_size);
777  data = (SetStateTeamMessage_data_t *)data_ptr;
779  enum_map_if_gamestate_team_t[(int)TEAM_NONE] = "TEAM_NONE";
780  enum_map_if_gamestate_team_t[(int)TEAM_CYAN] = "TEAM_CYAN";
781  enum_map_if_gamestate_team_t[(int)TEAM_MAGENTA] = "TEAM_MAGENTA";
782  enum_map_if_gamestate_team_t[(int)TEAM_BOTH] = "TEAM_BOTH";
783  enum_map_if_gamestate_goalcolor_t[(int)GOAL_BLUE] = "GOAL_BLUE";
784  enum_map_if_gamestate_goalcolor_t[(int)GOAL_YELLOW] = "GOAL_YELLOW";
785  enum_map_if_gamestate_half_t[(int)HALF_FIRST] = "HALF_FIRST";
786  enum_map_if_gamestate_half_t[(int)HALF_SECOND] = "HALF_SECOND";
787  enum_map_if_gamestate_role_t[(int)ROLE_GOALIE] = "ROLE_GOALIE";
788  enum_map_if_gamestate_role_t[(int)ROLE_DEFENDER] = "ROLE_DEFENDER";
789  enum_map_if_gamestate_role_t[(int)ROLE_MID_LEFT] = "ROLE_MID_LEFT";
790  enum_map_if_gamestate_role_t[(int)ROLE_MID_RIGHT] = "ROLE_MID_RIGHT";
791  enum_map_if_gamestate_role_t[(int)ROLE_ATTACKER] = "ROLE_ATTACKER";
792  add_fieldinfo(IFT_ENUM, "state_team", 1, &data->state_team, "if_gamestate_team_t", &enum_map_if_gamestate_team_t);
793 }
794 
795 /** Destructor */
797 {
798  free(data_ptr);
799 }
800 
801 /** Copy constructor.
802  * @param m message to copy from
803  */
805 {
806  data_size = m->data_size;
807  data_ptr = malloc(data_size);
808  memcpy(data_ptr, m->data_ptr, data_size);
809  data = (SetStateTeamMessage_data_t *)data_ptr;
811 }
812 
813 /* Methods */
814 /** Get state_team value.
815  * Team referred to by game state
816  * @return state_team value
817  */
820 {
821  return (GameStateInterface::if_gamestate_team_t)data->state_team;
822 }
823 
824 /** Get maximum length of state_team value.
825  * @return length of state_team value, can be length of the array or number of
826  * maximum number of characters for a string
827  */
828 size_t
830 {
831  return 1;
832 }
833 
834 /** Set state_team value.
835  * Team referred to by game state
836  * @param new_state_team new state_team value
837  */
838 void
840 {
841  data->state_team = new_state_team;
842 }
843 
844 /** Clone this message.
845  * Produces a message of the same type as this message and copies the
846  * data to the new message.
847  * @return clone of this message
848  */
849 Message *
851 {
853 }
854 /** Check if message is valid and can be enqueued.
855  * @param message Message to check
856  * @return true if the message is valid, false otherwise.
857  */
858 bool
860 {
861  const SetTeamColorMessage *m0 = dynamic_cast<const SetTeamColorMessage *>(message);
862  if ( m0 != NULL ) {
863  return true;
864  }
865  const SetKickoffMessage *m1 = dynamic_cast<const SetKickoffMessage *>(message);
866  if ( m1 != NULL ) {
867  return true;
868  }
869  const SetStateTeamMessage *m2 = dynamic_cast<const SetStateTeamMessage *>(message);
870  if ( m2 != NULL ) {
871  return true;
872  }
873  return false;
874 }
875 
876 /// @cond INTERNALS
877 EXPORT_INTERFACE(GameStateInterface)
878 /// @endcond
879 
880 
881 } // end namespace fawkes
bool is_kickoff() const
Get kickoff value.
void set_state_team(const if_gamestate_team_t new_state_team)
Set state_team value.
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:124
Blue goal.
Definition: enums.h:64
static const uint32_t GS_FROZEN
GS_FROZEN constant.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
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.
if_gamestate_role_t role() const
Get role value.
static const uint32_t GS_DROP_BALL
GS_DROP_BALL constant.
size_t maxlenof_role() const
Get maximum length of role value.
void set_hash(unsigned char *ihash)
Set hash.
Definition: interface.cpp:314
void set_our_goal_color(const if_gamestate_goalcolor_t new_our_goal_color)
Set our_goal_color value.
size_t maxlenof_kickoff() const
Get maximum length of kickoff value.
if_gamestate_team_t our_team() const
Get our_team value.
virtual Message * clone() const
Clone this message.
No team, not team-specific.
Definition: enums.h:55
static const uint32_t GS_THROW_IN
GS_THROW_IN constant.
Fawkes library namespace.
void set_state_team(const if_gamestate_team_t new_state_team)
Set state_team value.
size_t maxlenof_score_cyan() const
Get maximum length of score_cyan value.
Timestamp data, must be present and first entries for each interface data structs! This leans on time...
Definition: message.h:129
void set_our_team(const if_gamestate_team_t new_our_team)
Set our_team value.
virtual Message * create_message(const char *type) const
Create message based on type name.
Yellow goal.
Definition: enums.h:65
if_gamestate_team_t our_team() const
Get our_team value.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
void set_role(const if_gamestate_role_t new_role)
Set role value.
virtual Message * clone() const
Clone this message.
Magenta team.
Definition: enums.h:57
void set_kickoff(const bool new_kickoff)
Set kickoff value.
const char * tostring_if_gamestate_half_t(if_gamestate_half_t value) const
Convert if_gamestate_half_t constant to string.
const char * tostring_if_gamestate_team_t(if_gamestate_team_t value) const
Convert if_gamestate_team_t constant to string.
if_gamestate_role_t
Enumeration defining the different robot roles.
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:133
First half.
Definition: enums.h:71
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:125
static const uint32_t GS_SPL_READY
GS_SPL_READY constant.
const char * tostring_if_gamestate_role_t(if_gamestate_role_t value) const
Convert if_gamestate_role_t constant to string.
void add_messageinfo(const char *name)
Add an entry to the message info list.
Definition: interface.cpp:373
bool data_changed
Indicator if data has changed.
Definition: interface.h:222
size_t maxlenof_our_goal_color() const
Get maximum length of our_goal_color value.
const char * type() const
Get type of interface.
Definition: interface.cpp:651
uint32_t score_cyan() const
Get score_cyan value.
static const uint32_t GS_SPL_PLAY
GS_SPL_PLAY constant.
SetTeamColorMessage Fawkes BlackBoard Interface Message.
static const uint32_t GS_FREE_KICK
GS_FREE_KICK constant.
Both teams.
Definition: enums.h:58
if_gamestate_half_t
Enumeration defining the different teams.
size_t maxlenof_our_team() const
Get maximum length of our_team value.
virtual Message * clone() const
Clone this message.
const char * tostring_if_gamestate_goalcolor_t(if_gamestate_goalcolor_t value) const
Convert if_gamestate_goalcolor_t constant to string.
static const uint32_t GS_SPL_FINISHED
GS_SPL_FINISHED constant.
if_gamestate_goalcolor_t our_goal_color() const
Get our_goal_color value.
size_t maxlenof_state_team() const
Get maximum length of state_team value.
if_gamestate_goalcolor_t
Enumeration defining the different teams.
static const uint32_t GS_KICK_OFF
GS_KICK_OFF constant.
Second half.
Definition: enums.h:72
size_t maxlenof_our_team() const
Get maximum length of our_team value.
SetKickoffMessage Fawkes BlackBoard Interface Message.
static const uint32_t GS_PLAY
GS_PLAY constant.
if_gamestate_team_t state_team() const
Get state_team value.
if_gamestate_half_t half() const
Get half value.
static const uint32_t GS_HALF_TIME
GS_HALF_TIME constant.
SetStateTeamMessage Fawkes BlackBoard Interface Message.
virtual void copy_values(const Interface *other)
Copy values from other interface.
Cyan team.
Definition: enums.h:56
size_t maxlenof_state_team() const
Get maximum length of state_team value.
if_gamestate_team_t state_team() const
Get state_team value.
uint32_t game_state() const
Get game_state value.
static const uint32_t GS_CORNER_KICK
GS_CORNER_KICK constant.
size_t maxlenof_game_state() const
Get maximum length of game_state value.
GameStateInterface Fawkes BlackBoard Interface.
static const uint32_t GS_GOAL_KICK
GS_GOAL_KICK constant.
size_t maxlenof_score_magenta() const
Get maximum length of score_magenta value.
size_t maxlenof_half() const
Get maximum length of half value.
void set_score_magenta(const uint32_t new_score_magenta)
Set score_magenta value.
size_t maxlenof_kickoff() const
Get maximum length of kickoff value.
if_gamestate_team_t
Enumeration defining the different teams.
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0, const interface_enum_map_t *enum_map=0)
Add an entry to the info list.
Definition: message.cpp:436
boolean field
Definition: types.h:36
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.
const char * type() const
Get message type.
Definition: message.cpp:378
static const uint32_t GS_SPL_SET
GS_SPL_SET constant.
static const uint32_t GS_SPL_INITIAL
GS_SPL_INITIAL constant.
32 bit unsigned integer field
Definition: types.h:42
field with interface specific enum type
Definition: types.h:49
No team, not team-specific.
void set_kickoff(const bool new_kickoff)
Set kickoff value.
static const uint32_t GS_PENALTY
GS_PENALTY constant.
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.
uint32_t score_magenta() const
Get score_magenta value.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.