Fawkes API  Fawkes Development Version
KickerInterface.cpp
1 
2 /***************************************************************************
3  * KickerInterface.cpp - Fawkes BlackBoard Interface - KickerInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2007 Daniel Beck
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/KickerInterface.h>
25 
26 #include <core/exceptions/software.h>
27 
28 #include <cstring>
29 #include <cstdlib>
30 
31 namespace fawkes {
32 
33 /** @class KickerInterface <interfaces/KickerInterface.h>
34  * KickerInterface Fawkes BlackBoard Interface.
35  *
36  In these variables it is stored how often the right, center or
37  left kick have been triggered.
38 
39  * @ingroup FawkesInterfaces
40  */
41 
42 
43 
44 /** Constructor */
45 KickerInterface::KickerInterface() : Interface()
46 {
47  data_size = sizeof(KickerInterface_data_t);
48  data_ptr = malloc(data_size);
49  data = (KickerInterface_data_t *)data_ptr;
50  data_ts = (interface_data_ts_t *)data_ptr;
51  memset(data_ptr, 0, data_size);
52  add_fieldinfo(IFT_INT32, "num_kicks_left", 1, &data->num_kicks_left);
53  add_fieldinfo(IFT_INT32, "num_kicks_center", 1, &data->num_kicks_center);
54  add_fieldinfo(IFT_INT32, "num_kicks_right", 1, &data->num_kicks_right);
55  add_fieldinfo(IFT_ENUM, "guide_ball_side", 1, &data->guide_ball_side, "è›eBallSideEnum");
56  add_fieldinfo(IFT_UINT32, "current_intensity", 1, &data->current_intensity);
57  add_messageinfo("KickMessage");
58  add_messageinfo("ResetCounterMessage");
59  add_messageinfo("GuideBallMessage");
60  unsigned char tmp_hash[] = {0x96, 0x3d, 0x55, 0x60, 0xfd, 0x65, 0xf2, 0xfa, 0xa8, 0xfa, 0xfc, 0xaa, 0xb6, 0xfc, 0xc2, 0x81};
61  set_hash(tmp_hash);
62 }
63 
64 /** Destructor */
65 KickerInterface::~KickerInterface()
66 {
67  free(data_ptr);
68 }
69 /** Convert GuideBallSideEnum constant to string.
70  * @param value value to convert to string
71  * @return constant value as string.
72  */
73 const char *
75 {
76  switch (value) {
77  case GUIDE_BALL_LEFT: return "GUIDE_BALL_LEFT";
78  case GUIDE_BALL_RIGHT: return "GUIDE_BALL_RIGHT";
79  default: return "UNKNOWN";
80  }
81 }
82 /* Methods */
83 /** Get num_kicks_left value.
84  *
85  Number of Left-Kicks
86 
87  * @return num_kicks_left value
88  */
89 int32_t
91 {
92  return data->num_kicks_left;
93 }
94 
95 /** Get maximum length of num_kicks_left value.
96  * @return length of num_kicks_left value, can be length of the array or number of
97  * maximum number of characters for a string
98  */
99 size_t
101 {
102  return 1;
103 }
104 
105 /** Set num_kicks_left value.
106  *
107  Number of Left-Kicks
108 
109  * @param new_num_kicks_left new num_kicks_left value
110  */
111 void
112 KickerInterface::set_num_kicks_left(const int32_t new_num_kicks_left)
113 {
114  data->num_kicks_left = new_num_kicks_left;
115  data_changed = true;
116 }
117 
118 /** Get num_kicks_center value.
119  *
120  Number of Center-Kicks
121 
122  * @return num_kicks_center value
123  */
124 int32_t
126 {
127  return data->num_kicks_center;
128 }
129 
130 /** Get maximum length of num_kicks_center value.
131  * @return length of num_kicks_center value, can be length of the array or number of
132  * maximum number of characters for a string
133  */
134 size_t
136 {
137  return 1;
138 }
139 
140 /** Set num_kicks_center value.
141  *
142  Number of Center-Kicks
143 
144  * @param new_num_kicks_center new num_kicks_center value
145  */
146 void
147 KickerInterface::set_num_kicks_center(const int32_t new_num_kicks_center)
148 {
149  data->num_kicks_center = new_num_kicks_center;
150  data_changed = true;
151 }
152 
153 /** Get num_kicks_right value.
154  *
155  Number of Right-Kicks
156 
157  * @return num_kicks_right value
158  */
159 int32_t
161 {
162  return data->num_kicks_right;
163 }
164 
165 /** Get maximum length of num_kicks_right value.
166  * @return length of num_kicks_right value, can be length of the array or number of
167  * maximum number of characters for a string
168  */
169 size_t
171 {
172  return 1;
173 }
174 
175 /** Set num_kicks_right value.
176  *
177  Number of Right-Kicks
178 
179  * @param new_num_kicks_right new num_kicks_right value
180  */
181 void
182 KickerInterface::set_num_kicks_right(const int32_t new_num_kicks_right)
183 {
184  data->num_kicks_right = new_num_kicks_right;
185  data_changed = true;
186 }
187 
188 /** Get guide_ball_side value.
189  * Side where the ball
190  guidance arm is currently erected.
191  * @return guide_ball_side value
192  */
195 {
196  return (KickerInterface::GuideBallSideEnum)data->guide_ball_side;
197 }
198 
199 /** Get maximum length of guide_ball_side value.
200  * @return length of guide_ball_side value, can be length of the array or number of
201  * maximum number of characters for a string
202  */
203 size_t
205 {
206  return 1;
207 }
208 
209 /** Set guide_ball_side value.
210  * Side where the ball
211  guidance arm is currently erected.
212  * @param new_guide_ball_side new guide_ball_side value
213  */
214 void
216 {
217  data->guide_ball_side = new_guide_ball_side;
218  data_changed = true;
219 }
220 
221 /** Get current_intensity value.
222  *
223  The currently set intensity.
224 
225  * @return current_intensity value
226  */
227 uint32_t
229 {
230  return data->current_intensity;
231 }
232 
233 /** Get maximum length of current_intensity value.
234  * @return length of current_intensity value, can be length of the array or number of
235  * maximum number of characters for a string
236  */
237 size_t
239 {
240  return 1;
241 }
242 
243 /** Set current_intensity value.
244  *
245  The currently set intensity.
246 
247  * @param new_current_intensity new current_intensity value
248  */
249 void
250 KickerInterface::set_current_intensity(const uint32_t new_current_intensity)
251 {
252  data->current_intensity = new_current_intensity;
253  data_changed = true;
254 }
255 
256 /* =========== message create =========== */
257 Message *
259 {
260  if ( strncmp("KickMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
261  return new KickMessage();
262  } else if ( strncmp("ResetCounterMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
263  return new ResetCounterMessage();
264  } else if ( strncmp("GuideBallMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
265  return new GuideBallMessage();
266  } else {
267  throw UnknownTypeException("The given type '%s' does not match any known "
268  "message type for this interface type.", type);
269  }
270 }
271 
272 
273 /** Copy values from other interface.
274  * @param other other interface to copy values from
275  */
276 void
278 {
279  const KickerInterface *oi = dynamic_cast<const KickerInterface *>(other);
280  if (oi == NULL) {
281  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
282  type(), other->type());
283  }
284  memcpy(data, oi->data, sizeof(KickerInterface_data_t));
285 }
286 
287 const char *
288 KickerInterface::enum_tostring(const char *enumtype, int val) const
289 {
290  if (strcmp(enumtype, "GuideBallSideEnum") == 0) {
291  return tostring_GuideBallSideEnum((GuideBallSideEnum)val);
292  }
293  throw UnknownTypeException("Unknown enum type %s", enumtype);
294 }
295 
296 /* =========== messages =========== */
297 /** @class KickerInterface::KickMessage <interfaces/KickerInterface.h>
298  * KickMessage Fawkes BlackBoard Interface Message.
299  *
300 
301  */
302 
303 
304 /** Constructor with initial values.
305  * @param ini_left initial value for left
306  * @param ini_center initial value for center
307  * @param ini_right initial value for right
308  * @param ini_intensity initial value for intensity
309  */
310 KickerInterface::KickMessage::KickMessage(const bool ini_left, const bool ini_center, const bool ini_right, const uint32_t ini_intensity) : Message("KickMessage")
311 {
312  data_size = sizeof(KickMessage_data_t);
313  data_ptr = malloc(data_size);
314  memset(data_ptr, 0, data_size);
315  data = (KickMessage_data_t *)data_ptr;
317  data->left = ini_left;
318  data->center = ini_center;
319  data->right = ini_right;
320  data->intensity = ini_intensity;
321  add_fieldinfo(IFT_BOOL, "left", 1, &data->left);
322  add_fieldinfo(IFT_BOOL, "center", 1, &data->center);
323  add_fieldinfo(IFT_BOOL, "right", 1, &data->right);
324  add_fieldinfo(IFT_UINT32, "intensity", 1, &data->intensity);
325 }
326 /** Constructor */
328 {
329  data_size = sizeof(KickMessage_data_t);
330  data_ptr = malloc(data_size);
331  memset(data_ptr, 0, data_size);
332  data = (KickMessage_data_t *)data_ptr;
334  add_fieldinfo(IFT_BOOL, "left", 1, &data->left);
335  add_fieldinfo(IFT_BOOL, "center", 1, &data->center);
336  add_fieldinfo(IFT_BOOL, "right", 1, &data->right);
337  add_fieldinfo(IFT_UINT32, "intensity", 1, &data->intensity);
338 }
339 
340 /** Destructor */
342 {
343  free(data_ptr);
344 }
345 
346 /** Copy constructor.
347  * @param m message to copy from
348  */
350 {
351  data_size = m->data_size;
352  data_ptr = malloc(data_size);
353  memcpy(data_ptr, m->data_ptr, data_size);
354  data = (KickMessage_data_t *)data_ptr;
356 }
357 
358 /* Methods */
359 /** Get left value.
360  * True to kick with left kicker.
361  * @return left value
362  */
363 bool
365 {
366  return data->left;
367 }
368 
369 /** Get maximum length of left value.
370  * @return length of left value, can be length of the array or number of
371  * maximum number of characters for a string
372  */
373 size_t
375 {
376  return 1;
377 }
378 
379 /** Set left value.
380  * True to kick with left kicker.
381  * @param new_left new left value
382  */
383 void
385 {
386  data->left = new_left;
387 }
388 
389 /** Get center value.
390  * True to kick with central kicker.
391  * @return center value
392  */
393 bool
395 {
396  return data->center;
397 }
398 
399 /** Get maximum length of center value.
400  * @return length of center value, can be length of the array or number of
401  * maximum number of characters for a string
402  */
403 size_t
405 {
406  return 1;
407 }
408 
409 /** Set center value.
410  * True to kick with central kicker.
411  * @param new_center new center value
412  */
413 void
415 {
416  data->center = new_center;
417 }
418 
419 /** Get right value.
420  * True to kick with right kicker.
421  * @return right value
422  */
423 bool
425 {
426  return data->right;
427 }
428 
429 /** Get maximum length of right value.
430  * @return length of right value, can be length of the array or number of
431  * maximum number of characters for a string
432  */
433 size_t
435 {
436  return 1;
437 }
438 
439 /** Set right value.
440  * True to kick with right kicker.
441  * @param new_right new right value
442  */
443 void
445 {
446  data->right = new_right;
447 }
448 
449 /** Get intensity value.
450  * Intensity in the range [0..255].
451  * @return intensity value
452  */
453 uint32_t
455 {
456  return data->intensity;
457 }
458 
459 /** Get maximum length of intensity value.
460  * @return length of intensity value, can be length of the array or number of
461  * maximum number of characters for a string
462  */
463 size_t
465 {
466  return 1;
467 }
468 
469 /** Set intensity value.
470  * Intensity in the range [0..255].
471  * @param new_intensity new intensity value
472  */
473 void
474 KickerInterface::KickMessage::set_intensity(const uint32_t new_intensity)
475 {
476  data->intensity = new_intensity;
477 }
478 
479 /** Clone this message.
480  * Produces a message of the same type as this message and copies the
481  * data to the new message.
482  * @return clone of this message
483  */
484 Message *
486 {
487  return new KickerInterface::KickMessage(this);
488 }
489 /** @class KickerInterface::ResetCounterMessage <interfaces/KickerInterface.h>
490  * ResetCounterMessage Fawkes BlackBoard Interface Message.
491  *
492 
493  */
494 
495 
496 /** Constructor */
498 {
499  data_size = sizeof(ResetCounterMessage_data_t);
500  data_ptr = malloc(data_size);
501  memset(data_ptr, 0, data_size);
502  data = (ResetCounterMessage_data_t *)data_ptr;
504 }
505 
506 /** Destructor */
508 {
509  free(data_ptr);
510 }
511 
512 /** Copy constructor.
513  * @param m message to copy from
514  */
516 {
517  data_size = m->data_size;
518  data_ptr = malloc(data_size);
519  memcpy(data_ptr, m->data_ptr, data_size);
520  data = (ResetCounterMessage_data_t *)data_ptr;
522 }
523 
524 /* Methods */
525 /** Clone this message.
526  * Produces a message of the same type as this message and copies the
527  * data to the new message.
528  * @return clone of this message
529  */
530 Message *
532 {
533  return new KickerInterface::ResetCounterMessage(this);
534 }
535 /** @class KickerInterface::GuideBallMessage <interfaces/KickerInterface.h>
536  * GuideBallMessage Fawkes BlackBoard Interface Message.
537  *
538 
539  */
540 
541 
542 /** Constructor with initial values.
543  * @param ini_guide_ball_side initial value for guide_ball_side
544  */
545 KickerInterface::GuideBallMessage::GuideBallMessage(const GuideBallSideEnum ini_guide_ball_side) : Message("GuideBallMessage")
546 {
547  data_size = sizeof(GuideBallMessage_data_t);
548  data_ptr = malloc(data_size);
549  memset(data_ptr, 0, data_size);
550  data = (GuideBallMessage_data_t *)data_ptr;
552  data->guide_ball_side = ini_guide_ball_side;
553  add_fieldinfo(IFT_ENUM, "guide_ball_side", 1, &data->guide_ball_side, "");
554 }
555 /** Constructor */
557 {
558  data_size = sizeof(GuideBallMessage_data_t);
559  data_ptr = malloc(data_size);
560  memset(data_ptr, 0, data_size);
561  data = (GuideBallMessage_data_t *)data_ptr;
563  add_fieldinfo(IFT_ENUM, "guide_ball_side", 1, &data->guide_ball_side, "");
564 }
565 
566 /** Destructor */
568 {
569  free(data_ptr);
570 }
571 
572 /** Copy constructor.
573  * @param m message to copy from
574  */
576 {
577  data_size = m->data_size;
578  data_ptr = malloc(data_size);
579  memcpy(data_ptr, m->data_ptr, data_size);
580  data = (GuideBallMessage_data_t *)data_ptr;
582 }
583 
584 /* Methods */
585 /** Get guide_ball_side value.
586  * Side where to guide the ball and erect the arm.
587  * @return guide_ball_side value
588  */
591 {
592  return (KickerInterface::GuideBallSideEnum)data->guide_ball_side;
593 }
594 
595 /** Get maximum length of guide_ball_side value.
596  * @return length of guide_ball_side value, can be length of the array or number of
597  * maximum number of characters for a string
598  */
599 size_t
601 {
602  return 1;
603 }
604 
605 /** Set guide_ball_side value.
606  * Side where to guide the ball and erect the arm.
607  * @param new_guide_ball_side new guide_ball_side value
608  */
609 void
611 {
612  data->guide_ball_side = new_guide_ball_side;
613 }
614 
615 /** Clone this message.
616  * Produces a message of the same type as this message and copies the
617  * data to the new message.
618  * @return clone of this message
619  */
620 Message *
622 {
623  return new KickerInterface::GuideBallMessage(this);
624 }
625 /** Check if message is valid and can be enqueued.
626  * @param message Message to check
627  * @return true if the message is valid, false otherwise.
628  */
629 bool
631 {
632  const KickMessage *m0 = dynamic_cast<const KickMessage *>(message);
633  if ( m0 != NULL ) {
634  return true;
635  }
636  const ResetCounterMessage *m1 = dynamic_cast<const ResetCounterMessage *>(message);
637  if ( m1 != NULL ) {
638  return true;
639  }
640  const GuideBallMessage *m2 = dynamic_cast<const GuideBallMessage *>(message);
641  if ( m2 != NULL ) {
642  return true;
643  }
644  return false;
645 }
646 
647 /// @cond INTERNALS
648 EXPORT_INTERFACE(KickerInterface)
649 /// @endcond
650 
651 
652 } // end namespace fawkes
size_t maxlenof_center() const
Get maximum length of center value.
virtual Message * clone() const
Clone this message.
bool is_center() const
Get center value.
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:114
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:43
size_t maxlenof_num_kicks_center() const
Get maximum length of num_kicks_center value.
GuideBallSideEnum guide_ball_side() const
Get guide_ball_side value.
size_t maxlenof_guide_ball_side() const
Get maximum length of guide_ball_side value.
void set_hash(unsigned char *ihash)
Set hash.
Definition: interface.cpp:312
virtual Message * clone() const
Clone this message.
Fawkes library namespace.
void set_num_kicks_left(const int32_t new_num_kicks_left)
Set num_kicks_left value.
Timestamp data, must be present and first entries for each interface data structs! This leans on time...
Definition: message.h:119
size_t maxlenof_guide_ball_side() const
Get maximum length of guide_ball_side value.
bool is_left() const
Get left value.
void set_intensity(const uint32_t new_intensity)
Set intensity value.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
void set_center(const bool new_center)
Set center value.
void set_guide_ball_side(const GuideBallSideEnum new_guide_ball_side)
Set guide_ball_side value.
GuideBallMessage Fawkes BlackBoard Interface Message.
void set_right(const bool new_right)
Set right value.
virtual Message * create_message(const char *type) const
Create message based on type name.
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:123
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:115
void set_current_intensity(const uint32_t new_current_intensity)
Set current_intensity value.
void add_messageinfo(const char *name)
Add an entry to the message info list.
Definition: interface.cpp:368
virtual Message * clone() const
Clone this message.
void set_num_kicks_right(const int32_t new_num_kicks_right)
Set num_kicks_right value.
void set_num_kicks_center(const int32_t new_num_kicks_center)
Set num_kicks_center value.
bool data_changed
Indicator if data has changed.
Definition: interface.h:208
size_t maxlenof_current_intensity() const
Get maximum length of current_intensity value.
void * data_ptr
Pointer to local memory storage.
Definition: interface.h:206
KickMessage Fawkes BlackBoard Interface Message.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
int32_t num_kicks_center() const
Get num_kicks_center value.
int32_t num_kicks_left() const
Get num_kicks_left value.
size_t maxlenof_num_kicks_left() const
Get maximum length of num_kicks_left value.
void set_left(const bool new_left)
Set left value.
size_t maxlenof_intensity() const
Get maximum length of intensity value.
ResetCounterMessage Fawkes BlackBoard Interface Message.
uint32_t intensity() const
Get intensity value.
bool is_right() const
Get right value.
GuideBallSideEnum guide_ball_side() const
Get guide_ball_side value.
KickerInterface Fawkes BlackBoard Interface.
32 bit integer field
Definition: types.h:39
uint32_t current_intensity() const
Get current_intensity value.
GuideBallSideEnum
Enumeration defining on which side of the robot the ball shall be guided (and thus on which side the ...
const char * tostring_GuideBallSideEnum(GuideBallSideEnum value) const
Convert GuideBallSideEnum constant to string.
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0)
Add an entry to the info list.
Definition: message.cpp:435
virtual void copy_values(const Interface *other)
Copy values from other interface.
int32_t num_kicks_right() const
Get num_kicks_right value.
void set_guide_ball_side(const GuideBallSideEnum new_guide_ball_side)
Set guide_ball_side value.
size_t maxlenof_left() const
Get maximum length of left value.
boolean field
Definition: types.h:34
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.
const char * type() const
Get type of interface.
Definition: interface.cpp:635
32 bit unsigned integer field
Definition: types.h:40
field with interface specific enum type
Definition: types.h:47
size_t maxlenof_num_kicks_right() const
Get maximum length of num_kicks_right value.
size_t maxlenof_right() const
Get maximum length of right value.