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 *
124 GameStateInterface::tostring_if_gamestate_team_t(if_gamestate_team_t value) const
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 *
139 GameStateInterface::tostring_if_gamestate_goalcolor_t(if_gamestate_goalcolor_t value) const
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 *
152 GameStateInterface::tostring_if_gamestate_half_t(if_gamestate_half_t value) const
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 *
165 GameStateInterface::tostring_if_gamestate_role_t(if_gamestate_role_t value) const
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
182 GameStateInterface::game_state() const
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
192 GameStateInterface::maxlenof_game_state() const
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  set_field(data->game_state, new_game_state);
205 }
206 
207 /** Get state_team value.
208  * Team referred to by game state
209  * @return state_team value
210  */
212 GameStateInterface::state_team() const
213 {
214  return (GameStateInterface::if_gamestate_team_t)data->state_team;
215 }
216 
217 /** Get maximum length of state_team value.
218  * @return length of state_team value, can be length of the array or number of
219  * maximum number of characters for a string
220  */
221 size_t
222 GameStateInterface::maxlenof_state_team() const
223 {
224  return 1;
225 }
226 
227 /** Set state_team value.
228  * Team referred to by game state
229  * @param new_state_team new state_team value
230  */
231 void
232 GameStateInterface::set_state_team(const if_gamestate_team_t new_state_team)
233 {
234  set_field(data->state_team, new_state_team);
235 }
236 
237 /** Get our_team value.
238  * Our team color
239  * @return our_team value
240  */
242 GameStateInterface::our_team() const
243 {
244  return (GameStateInterface::if_gamestate_team_t)data->our_team;
245 }
246 
247 /** Get maximum length of our_team value.
248  * @return length of our_team value, can be length of the array or number of
249  * maximum number of characters for a string
250  */
251 size_t
252 GameStateInterface::maxlenof_our_team() const
253 {
254  return 1;
255 }
256 
257 /** Set our_team value.
258  * Our team color
259  * @param new_our_team new our_team value
260  */
261 void
262 GameStateInterface::set_our_team(const if_gamestate_team_t new_our_team)
263 {
264  set_field(data->our_team, new_our_team);
265 }
266 
267 /** Get our_goal_color value.
268  * Our own goal color
269  * @return our_goal_color value
270  */
272 GameStateInterface::our_goal_color() const
273 {
274  return (GameStateInterface::if_gamestate_goalcolor_t)data->our_goal_color;
275 }
276 
277 /** Get maximum length of our_goal_color value.
278  * @return length of our_goal_color value, can be length of the array or number of
279  * maximum number of characters for a string
280  */
281 size_t
282 GameStateInterface::maxlenof_our_goal_color() const
283 {
284  return 1;
285 }
286 
287 /** Set our_goal_color value.
288  * Our own goal color
289  * @param new_our_goal_color new our_goal_color value
290  */
291 void
292 GameStateInterface::set_our_goal_color(const if_gamestate_goalcolor_t new_our_goal_color)
293 {
294  set_field(data->our_goal_color, new_our_goal_color);
295 }
296 
297 /** Get half value.
298  * Current game half
299  * @return half value
300  */
302 GameStateInterface::half() const
303 {
304  return (GameStateInterface::if_gamestate_half_t)data->half;
305 }
306 
307 /** Get maximum length of half value.
308  * @return length of half value, can be length of the array or number of
309  * maximum number of characters for a string
310  */
311 size_t
312 GameStateInterface::maxlenof_half() const
313 {
314  return 1;
315 }
316 
317 /** Set half value.
318  * Current game half
319  * @param new_half new half value
320  */
321 void
322 GameStateInterface::set_half(const if_gamestate_half_t new_half)
323 {
324  set_field(data->half, new_half);
325 }
326 
327 /** Get kickoff value.
328  * Whether we have kickoff
329  * @return kickoff value
330  */
331 bool
332 GameStateInterface::is_kickoff() const
333 {
334  return data->kickoff;
335 }
336 
337 /** Get maximum length of kickoff value.
338  * @return length of kickoff value, can be length of the array or number of
339  * maximum number of characters for a string
340  */
341 size_t
342 GameStateInterface::maxlenof_kickoff() const
343 {
344  return 1;
345 }
346 
347 /** Set kickoff value.
348  * Whether we have kickoff
349  * @param new_kickoff new kickoff value
350  */
351 void
352 GameStateInterface::set_kickoff(const bool new_kickoff)
353 {
354  set_field(data->kickoff, new_kickoff);
355 }
356 
357 /** Get role value.
358  * Current role of this robot
359  * @return role value
360  */
362 GameStateInterface::role() const
363 {
364  return (GameStateInterface::if_gamestate_role_t)data->role;
365 }
366 
367 /** Get maximum length of role value.
368  * @return length of role value, can be length of the array or number of
369  * maximum number of characters for a string
370  */
371 size_t
372 GameStateInterface::maxlenof_role() const
373 {
374  return 1;
375 }
376 
377 /** Set role value.
378  * Current role of this robot
379  * @param new_role new role value
380  */
381 void
382 GameStateInterface::set_role(const if_gamestate_role_t new_role)
383 {
384  set_field(data->role, new_role);
385 }
386 
387 /** Get score_cyan value.
388  * Score of team cyan
389  * @return score_cyan value
390  */
391 uint32_t
392 GameStateInterface::score_cyan() const
393 {
394  return data->score_cyan;
395 }
396 
397 /** Get maximum length of score_cyan value.
398  * @return length of score_cyan value, can be length of the array or number of
399  * maximum number of characters for a string
400  */
401 size_t
402 GameStateInterface::maxlenof_score_cyan() const
403 {
404  return 1;
405 }
406 
407 /** Set score_cyan value.
408  * Score of team cyan
409  * @param new_score_cyan new score_cyan value
410  */
411 void
412 GameStateInterface::set_score_cyan(const uint32_t new_score_cyan)
413 {
414  set_field(data->score_cyan, new_score_cyan);
415 }
416 
417 /** Get score_magenta value.
418  * Score of team magenta
419  * @return score_magenta value
420  */
421 uint32_t
422 GameStateInterface::score_magenta() const
423 {
424  return data->score_magenta;
425 }
426 
427 /** Get maximum length of score_magenta value.
428  * @return length of score_magenta value, can be length of the array or number of
429  * maximum number of characters for a string
430  */
431 size_t
432 GameStateInterface::maxlenof_score_magenta() const
433 {
434  return 1;
435 }
436 
437 /** Set score_magenta value.
438  * Score of team magenta
439  * @param new_score_magenta new score_magenta value
440  */
441 void
442 GameStateInterface::set_score_magenta(const uint32_t new_score_magenta)
443 {
444  set_field(data->score_magenta, new_score_magenta);
445 }
446 
447 /* =========== message create =========== */
448 Message *
449 GameStateInterface::create_message(const char *type) const
450 {
451  if ( strncmp("SetTeamColorMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
452  return new SetTeamColorMessage();
453  } else if ( strncmp("SetKickoffMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
454  return new SetKickoffMessage();
455  } else if ( strncmp("SetStateTeamMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
456  return new SetStateTeamMessage();
457  } else {
458  throw UnknownTypeException("The given type '%s' does not match any known "
459  "message type for this interface type.", type);
460  }
461 }
462 
463 
464 /** Copy values from other interface.
465  * @param other other interface to copy values from
466  */
467 void
468 GameStateInterface::copy_values(const Interface *other)
469 {
470  const GameStateInterface *oi = dynamic_cast<const GameStateInterface *>(other);
471  if (oi == NULL) {
472  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
473  type(), other->type());
474  }
475  memcpy(data, oi->data, sizeof(GameStateInterface_data_t));
476 }
477 
478 const char *
479 GameStateInterface::enum_tostring(const char *enumtype, int val) const
480 {
481  if (strcmp(enumtype, "if_gamestate_team_t") == 0) {
482  return tostring_if_gamestate_team_t((if_gamestate_team_t)val);
483  }
484  if (strcmp(enumtype, "if_gamestate_goalcolor_t") == 0) {
485  return tostring_if_gamestate_goalcolor_t((if_gamestate_goalcolor_t)val);
486  }
487  if (strcmp(enumtype, "if_gamestate_half_t") == 0) {
488  return tostring_if_gamestate_half_t((if_gamestate_half_t)val);
489  }
490  if (strcmp(enumtype, "if_gamestate_role_t") == 0) {
491  return tostring_if_gamestate_role_t((if_gamestate_role_t)val);
492  }
493  throw UnknownTypeException("Unknown enum type %s", enumtype);
494 }
495 
496 /* =========== messages =========== */
497 /** @class GameStateInterface::SetTeamColorMessage <interfaces/GameStateInterface.h>
498  * SetTeamColorMessage Fawkes BlackBoard Interface Message.
499  *
500 
501  */
502 
503 
504 /** Constructor with initial values.
505  * @param ini_our_team initial value for our_team
506  */
507 GameStateInterface::SetTeamColorMessage::SetTeamColorMessage(const if_gamestate_team_t ini_our_team) : Message("SetTeamColorMessage")
508 {
509  data_size = sizeof(SetTeamColorMessage_data_t);
510  data_ptr = malloc(data_size);
511  memset(data_ptr, 0, data_size);
512  data = (SetTeamColorMessage_data_t *)data_ptr;
514  data->our_team = ini_our_team;
515  enum_map_if_gamestate_team_t[(int)TEAM_NONE] = "TEAM_NONE";
516  enum_map_if_gamestate_team_t[(int)TEAM_CYAN] = "TEAM_CYAN";
517  enum_map_if_gamestate_team_t[(int)TEAM_MAGENTA] = "TEAM_MAGENTA";
518  enum_map_if_gamestate_team_t[(int)TEAM_BOTH] = "TEAM_BOTH";
519  enum_map_if_gamestate_goalcolor_t[(int)GOAL_BLUE] = "GOAL_BLUE";
520  enum_map_if_gamestate_goalcolor_t[(int)GOAL_YELLOW] = "GOAL_YELLOW";
521  enum_map_if_gamestate_half_t[(int)HALF_FIRST] = "HALF_FIRST";
522  enum_map_if_gamestate_half_t[(int)HALF_SECOND] = "HALF_SECOND";
523  enum_map_if_gamestate_role_t[(int)ROLE_GOALIE] = "ROLE_GOALIE";
524  enum_map_if_gamestate_role_t[(int)ROLE_DEFENDER] = "ROLE_DEFENDER";
525  enum_map_if_gamestate_role_t[(int)ROLE_MID_LEFT] = "ROLE_MID_LEFT";
526  enum_map_if_gamestate_role_t[(int)ROLE_MID_RIGHT] = "ROLE_MID_RIGHT";
527  enum_map_if_gamestate_role_t[(int)ROLE_ATTACKER] = "ROLE_ATTACKER";
528  add_fieldinfo(IFT_ENUM, "our_team", 1, &data->our_team, "if_gamestate_team_t", &enum_map_if_gamestate_team_t);
529 }
530 /** Constructor */
532 {
533  data_size = sizeof(SetTeamColorMessage_data_t);
534  data_ptr = malloc(data_size);
535  memset(data_ptr, 0, data_size);
536  data = (SetTeamColorMessage_data_t *)data_ptr;
538  enum_map_if_gamestate_team_t[(int)TEAM_NONE] = "TEAM_NONE";
539  enum_map_if_gamestate_team_t[(int)TEAM_CYAN] = "TEAM_CYAN";
540  enum_map_if_gamestate_team_t[(int)TEAM_MAGENTA] = "TEAM_MAGENTA";
541  enum_map_if_gamestate_team_t[(int)TEAM_BOTH] = "TEAM_BOTH";
542  enum_map_if_gamestate_goalcolor_t[(int)GOAL_BLUE] = "GOAL_BLUE";
543  enum_map_if_gamestate_goalcolor_t[(int)GOAL_YELLOW] = "GOAL_YELLOW";
544  enum_map_if_gamestate_half_t[(int)HALF_FIRST] = "HALF_FIRST";
545  enum_map_if_gamestate_half_t[(int)HALF_SECOND] = "HALF_SECOND";
546  enum_map_if_gamestate_role_t[(int)ROLE_GOALIE] = "ROLE_GOALIE";
547  enum_map_if_gamestate_role_t[(int)ROLE_DEFENDER] = "ROLE_DEFENDER";
548  enum_map_if_gamestate_role_t[(int)ROLE_MID_LEFT] = "ROLE_MID_LEFT";
549  enum_map_if_gamestate_role_t[(int)ROLE_MID_RIGHT] = "ROLE_MID_RIGHT";
550  enum_map_if_gamestate_role_t[(int)ROLE_ATTACKER] = "ROLE_ATTACKER";
551  add_fieldinfo(IFT_ENUM, "our_team", 1, &data->our_team, "if_gamestate_team_t", &enum_map_if_gamestate_team_t);
552 }
553 
554 /** Destructor */
556 {
557  free(data_ptr);
558 }
559 
560 /** Copy constructor.
561  * @param m message to copy from
562  */
564 {
565  data_size = m->data_size;
566  data_ptr = malloc(data_size);
567  memcpy(data_ptr, m->data_ptr, data_size);
568  data = (SetTeamColorMessage_data_t *)data_ptr;
570 }
571 
572 /* Methods */
573 /** Get our_team value.
574  * Our team color
575  * @return our_team value
576  */
579 {
580  return (GameStateInterface::if_gamestate_team_t)data->our_team;
581 }
582 
583 /** Get maximum length of our_team value.
584  * @return length of our_team value, can be length of the array or number of
585  * maximum number of characters for a string
586  */
587 size_t
589 {
590  return 1;
591 }
592 
593 /** Set our_team value.
594  * Our team color
595  * @param new_our_team new our_team value
596  */
597 void
599 {
600  set_field(data->our_team, new_our_team);
601 }
602 
603 /** Clone this message.
604  * Produces a message of the same type as this message and copies the
605  * data to the new message.
606  * @return clone of this message
607  */
608 Message *
610 {
612 }
613 /** @class GameStateInterface::SetKickoffMessage <interfaces/GameStateInterface.h>
614  * SetKickoffMessage Fawkes BlackBoard Interface Message.
615  *
616 
617  */
618 
619 
620 /** Constructor with initial values.
621  * @param ini_kickoff initial value for kickoff
622  */
623 GameStateInterface::SetKickoffMessage::SetKickoffMessage(const bool ini_kickoff) : Message("SetKickoffMessage")
624 {
625  data_size = sizeof(SetKickoffMessage_data_t);
626  data_ptr = malloc(data_size);
627  memset(data_ptr, 0, data_size);
628  data = (SetKickoffMessage_data_t *)data_ptr;
630  data->kickoff = ini_kickoff;
631  enum_map_if_gamestate_team_t[(int)TEAM_NONE] = "TEAM_NONE";
632  enum_map_if_gamestate_team_t[(int)TEAM_CYAN] = "TEAM_CYAN";
633  enum_map_if_gamestate_team_t[(int)TEAM_MAGENTA] = "TEAM_MAGENTA";
634  enum_map_if_gamestate_team_t[(int)TEAM_BOTH] = "TEAM_BOTH";
635  enum_map_if_gamestate_goalcolor_t[(int)GOAL_BLUE] = "GOAL_BLUE";
636  enum_map_if_gamestate_goalcolor_t[(int)GOAL_YELLOW] = "GOAL_YELLOW";
637  enum_map_if_gamestate_half_t[(int)HALF_FIRST] = "HALF_FIRST";
638  enum_map_if_gamestate_half_t[(int)HALF_SECOND] = "HALF_SECOND";
639  enum_map_if_gamestate_role_t[(int)ROLE_GOALIE] = "ROLE_GOALIE";
640  enum_map_if_gamestate_role_t[(int)ROLE_DEFENDER] = "ROLE_DEFENDER";
641  enum_map_if_gamestate_role_t[(int)ROLE_MID_LEFT] = "ROLE_MID_LEFT";
642  enum_map_if_gamestate_role_t[(int)ROLE_MID_RIGHT] = "ROLE_MID_RIGHT";
643  enum_map_if_gamestate_role_t[(int)ROLE_ATTACKER] = "ROLE_ATTACKER";
644  add_fieldinfo(IFT_BOOL, "kickoff", 1, &data->kickoff);
645 }
646 /** Constructor */
648 {
649  data_size = sizeof(SetKickoffMessage_data_t);
650  data_ptr = malloc(data_size);
651  memset(data_ptr, 0, data_size);
652  data = (SetKickoffMessage_data_t *)data_ptr;
654  enum_map_if_gamestate_team_t[(int)TEAM_NONE] = "TEAM_NONE";
655  enum_map_if_gamestate_team_t[(int)TEAM_CYAN] = "TEAM_CYAN";
656  enum_map_if_gamestate_team_t[(int)TEAM_MAGENTA] = "TEAM_MAGENTA";
657  enum_map_if_gamestate_team_t[(int)TEAM_BOTH] = "TEAM_BOTH";
658  enum_map_if_gamestate_goalcolor_t[(int)GOAL_BLUE] = "GOAL_BLUE";
659  enum_map_if_gamestate_goalcolor_t[(int)GOAL_YELLOW] = "GOAL_YELLOW";
660  enum_map_if_gamestate_half_t[(int)HALF_FIRST] = "HALF_FIRST";
661  enum_map_if_gamestate_half_t[(int)HALF_SECOND] = "HALF_SECOND";
662  enum_map_if_gamestate_role_t[(int)ROLE_GOALIE] = "ROLE_GOALIE";
663  enum_map_if_gamestate_role_t[(int)ROLE_DEFENDER] = "ROLE_DEFENDER";
664  enum_map_if_gamestate_role_t[(int)ROLE_MID_LEFT] = "ROLE_MID_LEFT";
665  enum_map_if_gamestate_role_t[(int)ROLE_MID_RIGHT] = "ROLE_MID_RIGHT";
666  enum_map_if_gamestate_role_t[(int)ROLE_ATTACKER] = "ROLE_ATTACKER";
667  add_fieldinfo(IFT_BOOL, "kickoff", 1, &data->kickoff);
668 }
669 
670 /** Destructor */
672 {
673  free(data_ptr);
674 }
675 
676 /** Copy constructor.
677  * @param m message to copy from
678  */
680 {
681  data_size = m->data_size;
682  data_ptr = malloc(data_size);
683  memcpy(data_ptr, m->data_ptr, data_size);
684  data = (SetKickoffMessage_data_t *)data_ptr;
686 }
687 
688 /* Methods */
689 /** Get kickoff value.
690  * Whether we have kickoff
691  * @return kickoff value
692  */
693 bool
695 {
696  return data->kickoff;
697 }
698 
699 /** Get maximum length of kickoff value.
700  * @return length of kickoff value, can be length of the array or number of
701  * maximum number of characters for a string
702  */
703 size_t
705 {
706  return 1;
707 }
708 
709 /** Set kickoff value.
710  * Whether we have kickoff
711  * @param new_kickoff new kickoff value
712  */
713 void
715 {
716  set_field(data->kickoff, new_kickoff);
717 }
718 
719 /** Clone this message.
720  * Produces a message of the same type as this message and copies the
721  * data to the new message.
722  * @return clone of this message
723  */
724 Message *
726 {
727  return new GameStateInterface::SetKickoffMessage(this);
728 }
729 /** @class GameStateInterface::SetStateTeamMessage <interfaces/GameStateInterface.h>
730  * SetStateTeamMessage Fawkes BlackBoard Interface Message.
731  *
732 
733  */
734 
735 
736 /** Constructor with initial values.
737  * @param ini_state_team initial value for state_team
738  */
740 {
741  data_size = sizeof(SetStateTeamMessage_data_t);
742  data_ptr = malloc(data_size);
743  memset(data_ptr, 0, data_size);
744  data = (SetStateTeamMessage_data_t *)data_ptr;
746  data->state_team = ini_state_team;
747  enum_map_if_gamestate_team_t[(int)TEAM_NONE] = "TEAM_NONE";
748  enum_map_if_gamestate_team_t[(int)TEAM_CYAN] = "TEAM_CYAN";
749  enum_map_if_gamestate_team_t[(int)TEAM_MAGENTA] = "TEAM_MAGENTA";
750  enum_map_if_gamestate_team_t[(int)TEAM_BOTH] = "TEAM_BOTH";
751  enum_map_if_gamestate_goalcolor_t[(int)GOAL_BLUE] = "GOAL_BLUE";
752  enum_map_if_gamestate_goalcolor_t[(int)GOAL_YELLOW] = "GOAL_YELLOW";
753  enum_map_if_gamestate_half_t[(int)HALF_FIRST] = "HALF_FIRST";
754  enum_map_if_gamestate_half_t[(int)HALF_SECOND] = "HALF_SECOND";
755  enum_map_if_gamestate_role_t[(int)ROLE_GOALIE] = "ROLE_GOALIE";
756  enum_map_if_gamestate_role_t[(int)ROLE_DEFENDER] = "ROLE_DEFENDER";
757  enum_map_if_gamestate_role_t[(int)ROLE_MID_LEFT] = "ROLE_MID_LEFT";
758  enum_map_if_gamestate_role_t[(int)ROLE_MID_RIGHT] = "ROLE_MID_RIGHT";
759  enum_map_if_gamestate_role_t[(int)ROLE_ATTACKER] = "ROLE_ATTACKER";
760  add_fieldinfo(IFT_ENUM, "state_team", 1, &data->state_team, "if_gamestate_team_t", &enum_map_if_gamestate_team_t);
761 }
762 /** Constructor */
764 {
765  data_size = sizeof(SetStateTeamMessage_data_t);
766  data_ptr = malloc(data_size);
767  memset(data_ptr, 0, data_size);
768  data = (SetStateTeamMessage_data_t *)data_ptr;
770  enum_map_if_gamestate_team_t[(int)TEAM_NONE] = "TEAM_NONE";
771  enum_map_if_gamestate_team_t[(int)TEAM_CYAN] = "TEAM_CYAN";
772  enum_map_if_gamestate_team_t[(int)TEAM_MAGENTA] = "TEAM_MAGENTA";
773  enum_map_if_gamestate_team_t[(int)TEAM_BOTH] = "TEAM_BOTH";
774  enum_map_if_gamestate_goalcolor_t[(int)GOAL_BLUE] = "GOAL_BLUE";
775  enum_map_if_gamestate_goalcolor_t[(int)GOAL_YELLOW] = "GOAL_YELLOW";
776  enum_map_if_gamestate_half_t[(int)HALF_FIRST] = "HALF_FIRST";
777  enum_map_if_gamestate_half_t[(int)HALF_SECOND] = "HALF_SECOND";
778  enum_map_if_gamestate_role_t[(int)ROLE_GOALIE] = "ROLE_GOALIE";
779  enum_map_if_gamestate_role_t[(int)ROLE_DEFENDER] = "ROLE_DEFENDER";
780  enum_map_if_gamestate_role_t[(int)ROLE_MID_LEFT] = "ROLE_MID_LEFT";
781  enum_map_if_gamestate_role_t[(int)ROLE_MID_RIGHT] = "ROLE_MID_RIGHT";
782  enum_map_if_gamestate_role_t[(int)ROLE_ATTACKER] = "ROLE_ATTACKER";
783  add_fieldinfo(IFT_ENUM, "state_team", 1, &data->state_team, "if_gamestate_team_t", &enum_map_if_gamestate_team_t);
784 }
785 
786 /** Destructor */
788 {
789  free(data_ptr);
790 }
791 
792 /** Copy constructor.
793  * @param m message to copy from
794  */
796 {
797  data_size = m->data_size;
798  data_ptr = malloc(data_size);
799  memcpy(data_ptr, m->data_ptr, data_size);
800  data = (SetStateTeamMessage_data_t *)data_ptr;
802 }
803 
804 /* Methods */
805 /** Get state_team value.
806  * Team referred to by game state
807  * @return state_team value
808  */
811 {
812  return (GameStateInterface::if_gamestate_team_t)data->state_team;
813 }
814 
815 /** Get maximum length of state_team value.
816  * @return length of state_team value, can be length of the array or number of
817  * maximum number of characters for a string
818  */
819 size_t
821 {
822  return 1;
823 }
824 
825 /** Set state_team value.
826  * Team referred to by game state
827  * @param new_state_team new state_team value
828  */
829 void
831 {
832  set_field(data->state_team, new_state_team);
833 }
834 
835 /** Clone this message.
836  * Produces a message of the same type as this message and copies the
837  * data to the new message.
838  * @return clone of this message
839  */
840 Message *
842 {
844 }
845 /** Check if message is valid and can be enqueued.
846  * @param message Message to check
847  * @return true if the message is valid, false otherwise.
848  */
849 bool
851 {
852  const SetTeamColorMessage *m0 = dynamic_cast<const SetTeamColorMessage *>(message);
853  if ( m0 != NULL ) {
854  return true;
855  }
856  const SetKickoffMessage *m1 = dynamic_cast<const SetKickoffMessage *>(message);
857  if ( m1 != NULL ) {
858  return true;
859  }
860  const SetStateTeamMessage *m2 = dynamic_cast<const SetStateTeamMessage *>(message);
861  if ( m2 != NULL ) {
862  return true;
863  }
864  return false;
865 }
866 
867 /// @cond INTERNALS
868 EXPORT_INTERFACE(GameStateInterface)
869 /// @endcond
870 
871 
872 } // end namespace fawkes
SetKickoffMessage Fawkes BlackBoard Interface Message.
virtual Message * clone() const
Clone this message.
size_t maxlenof_kickoff() const
Get maximum length of kickoff value.
void set_kickoff(const bool new_kickoff)
Set kickoff value.
SetStateTeamMessage Fawkes BlackBoard Interface Message.
void set_state_team(const if_gamestate_team_t new_state_team)
Set state_team value.
size_t maxlenof_state_team() const
Get maximum length of state_team value.
if_gamestate_team_t state_team() const
Get state_team value.
virtual Message * clone() const
Clone this message.
SetTeamColorMessage Fawkes BlackBoard Interface Message.
if_gamestate_team_t our_team() const
Get our_team value.
virtual Message * clone() const
Clone this message.
size_t maxlenof_our_team() const
Get maximum length of our_team value.
void set_our_team(const if_gamestate_team_t new_our_team)
Set our_team value.
GameStateInterface Fawkes BlackBoard Interface.
if_gamestate_team_t
Enumeration defining the different teams.
@ TEAM_NONE
No team, not team-specific.
static const uint32_t GS_SPL_FINISHED
GS_SPL_FINISHED constant.
static const uint32_t GS_FREE_KICK
GS_FREE_KICK constant.
static const uint32_t GS_SPL_READY
GS_SPL_READY constant.
if_gamestate_goalcolor_t
Enumeration defining the different teams.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
static const uint32_t GS_CORNER_KICK
GS_CORNER_KICK constant.
if_gamestate_half_t
Enumeration defining the different teams.
static const uint32_t GS_THROW_IN
GS_THROW_IN constant.
static const uint32_t GS_HALF_TIME
GS_HALF_TIME constant.
static const uint32_t GS_FROZEN
GS_FROZEN constant.
static const uint32_t GS_KICK_OFF
GS_KICK_OFF constant.
static const uint32_t GS_DROP_BALL
GS_DROP_BALL constant.
static const uint32_t GS_SPL_INITIAL
GS_SPL_INITIAL constant.
static const uint32_t GS_SPL_SET
GS_SPL_SET constant.
static const uint32_t GS_GOAL_KICK
GS_GOAL_KICK constant.
static const uint32_t GS_SPL_PLAY
GS_SPL_PLAY constant.
if_gamestate_role_t
Enumeration defining the different robot roles.
static const uint32_t GS_PLAY
GS_PLAY constant.
static const uint32_t GS_PENALTY
GS_PENALTY constant.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
const char * type() const
Get type of interface.
Definition: interface.cpp:652
void * data_ptr
Pointer to local memory storage.
Definition: interface.h:244
void set_field(FieldT &field, DataT &data)
Set a field, set data_changed to true and update data_changed accordingly.
Definition: interface.h:304
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
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:435
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:146
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:156
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:147
Fawkes library namespace.
@ GOAL_BLUE
Blue goal.
Definition: enums.h:62
@ GOAL_YELLOW
Yellow goal.
Definition: enums.h:63
@ IFT_BOOL
boolean field
Definition: types.h:37
@ IFT_ENUM
field with interface specific enum type
Definition: types.h:50
@ HALF_SECOND
Second half.
Definition: enums.h:69
@ HALF_FIRST
First half.
Definition: enums.h:68
@ TEAM_MAGENTA
Magenta team.
Definition: enums.h:56
@ TEAM_NONE
No team, not team-specific.
Definition: enums.h:54
@ TEAM_CYAN
Cyan team.
Definition: enums.h:55
@ TEAM_BOTH
Both teams.
Definition: enums.h:57
Timestamp data, must be present and first entries for each interface data structs!...
Definition: message.h:152