Fawkes API  Fawkes Development Version
LaserBoxFilterInterface.cpp
1 
2 /***************************************************************************
3  * LaserBoxFilterInterface.cpp - Fawkes BlackBoard Interface - LaserBoxFilterInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2018 Nicolas Limpert
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/LaserBoxFilterInterface.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 LaserBoxFilterInterface <interfaces/LaserBoxFilterInterface.h>
36  * LaserBoxFilterInterface Fawkes BlackBoard Interface.
37  *
38  Interface to create new laser filters at runtime.
39 
40  * @ingroup FawkesInterfaces
41  */
42 
43 
44 
45 /** Constructor */
46 LaserBoxFilterInterface::LaserBoxFilterInterface() : Interface()
47 {
48  data_size = sizeof(LaserBoxFilterInterface_data_t);
49  data_ptr = malloc(data_size);
50  data = (LaserBoxFilterInterface_data_t *)data_ptr;
51  data_ts = (interface_data_ts_t *)data_ptr;
52  memset(data_ptr, 0, data_size);
53  add_fieldinfo(IFT_UINT32, "num_boxes", 1, &data->num_boxes);
54  add_messageinfo("CreateNewBoxFilterMessage");
55  unsigned char tmp_hash[] = {0xd5, 0xd3, 0x35, 0xa5, 0xf5, 0xeb, 0xfe, 0xe0, 0x2e, 0x9e, 0xda, 0xa8, 0x77, 0x6f, 0x3, 0x74};
56  set_hash(tmp_hash);
57 }
58 
59 /** Destructor */
60 LaserBoxFilterInterface::~LaserBoxFilterInterface()
61 {
62  free(data_ptr);
63 }
64 /* Methods */
65 /** Get num_boxes value.
66  * The number of currently applied boxes
67  * @return num_boxes value
68  */
69 uint32_t
70 LaserBoxFilterInterface::num_boxes() const
71 {
72  return data->num_boxes;
73 }
74 
75 /** Get maximum length of num_boxes value.
76  * @return length of num_boxes value, can be length of the array or number of
77  * maximum number of characters for a string
78  */
79 size_t
80 LaserBoxFilterInterface::maxlenof_num_boxes() const
81 {
82  return 1;
83 }
84 
85 /** Set num_boxes value.
86  * The number of currently applied boxes
87  * @param new_num_boxes new num_boxes value
88  */
89 void
90 LaserBoxFilterInterface::set_num_boxes(const uint32_t new_num_boxes)
91 {
92  data->num_boxes = new_num_boxes;
93  data_changed = true;
94 }
95 
96 /* =========== message create =========== */
97 Message *
98 LaserBoxFilterInterface::create_message(const char *type) const
99 {
100  if ( strncmp("CreateNewBoxFilterMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_) == 0 ) {
101  return new CreateNewBoxFilterMessage();
102  } else {
103  throw UnknownTypeException("The given type '%s' does not match any known "
104  "message type for this interface type.", type);
105  }
106 }
107 
108 
109 /** Copy values from other interface.
110  * @param other other interface to copy values from
111  */
112 void
113 LaserBoxFilterInterface::copy_values(const Interface *other)
114 {
115  const LaserBoxFilterInterface *oi = dynamic_cast<const LaserBoxFilterInterface *>(other);
116  if (oi == NULL) {
117  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
118  type(), other->type());
119  }
120  memcpy(data, oi->data, sizeof(LaserBoxFilterInterface_data_t));
121 }
122 
123 const char *
124 LaserBoxFilterInterface::enum_tostring(const char *enumtype, int val) const
125 {
126  throw UnknownTypeException("Unknown enum type %s", enumtype);
127 }
128 
129 /* =========== messages =========== */
130 /** @class LaserBoxFilterInterface::CreateNewBoxFilterMessage <interfaces/LaserBoxFilterInterface.h>
131  * CreateNewBoxFilterMessage Fawkes BlackBoard Interface Message.
132  *
133 
134  */
135 
136 
137 /** Constructor with initial values.
138  * @param ini_p1 initial value for p1
139  * @param ini_p2 initial value for p2
140  * @param ini_p3 initial value for p3
141  * @param ini_p4 initial value for p4
142  */
143 LaserBoxFilterInterface::CreateNewBoxFilterMessage::CreateNewBoxFilterMessage(const double * ini_p1, const double * ini_p2, const double * ini_p3, const double * ini_p4) : Message("CreateNewBoxFilterMessage")
144 {
145  data_size = sizeof(CreateNewBoxFilterMessage_data_t);
146  data_ptr = malloc(data_size);
147  memset(data_ptr, 0, data_size);
148  data = (CreateNewBoxFilterMessage_data_t *)data_ptr;
150  memcpy(data->p1, ini_p1, sizeof(double) * 2);
151  memcpy(data->p2, ini_p2, sizeof(double) * 2);
152  memcpy(data->p3, ini_p3, sizeof(double) * 2);
153  memcpy(data->p4, ini_p4, sizeof(double) * 2);
154  add_fieldinfo(IFT_DOUBLE, "p1", 2, &data->p1);
155  add_fieldinfo(IFT_DOUBLE, "p2", 2, &data->p2);
156  add_fieldinfo(IFT_DOUBLE, "p3", 2, &data->p3);
157  add_fieldinfo(IFT_DOUBLE, "p4", 2, &data->p4);
158 }
159 /** Constructor */
161 {
162  data_size = sizeof(CreateNewBoxFilterMessage_data_t);
163  data_ptr = malloc(data_size);
164  memset(data_ptr, 0, data_size);
165  data = (CreateNewBoxFilterMessage_data_t *)data_ptr;
167  add_fieldinfo(IFT_DOUBLE, "p1", 2, &data->p1);
168  add_fieldinfo(IFT_DOUBLE, "p2", 2, &data->p2);
169  add_fieldinfo(IFT_DOUBLE, "p3", 2, &data->p3);
170  add_fieldinfo(IFT_DOUBLE, "p4", 2, &data->p4);
171 }
172 
173 /** Destructor */
175 {
176  free(data_ptr);
177 }
178 
179 /** Copy constructor.
180  * @param m message to copy from
181  */
183 {
184  data_size = m->data_size;
185  data_ptr = malloc(data_size);
186  memcpy(data_ptr, m->data_ptr, data_size);
187  data = (CreateNewBoxFilterMessage_data_t *)data_ptr;
189 }
190 
191 /* Methods */
192 /** Get p1 value.
193  * x,y coordinates of first vector
194  * @return p1 value
195  */
196 double *
198 {
199  return data->p1;
200 }
201 
202 /** Get p1 value at given index.
203  * x,y coordinates of first vector
204  * @param index index of value
205  * @return p1 value
206  * @exception Exception thrown if index is out of bounds
207  */
208 double
210 {
211  if (index > 2) {
212  throw Exception("Index value %u out of bounds (0..2)", index);
213  }
214  return data->p1[index];
215 }
216 
217 /** Get maximum length of p1 value.
218  * @return length of p1 value, can be length of the array or number of
219  * maximum number of characters for a string
220  */
221 size_t
223 {
224  return 2;
225 }
226 
227 /** Set p1 value.
228  * x,y coordinates of first vector
229  * @param new_p1 new p1 value
230  */
231 void
233 {
234  memcpy(data->p1, new_p1, sizeof(double) * 2);
235 }
236 
237 /** Set p1 value at given index.
238  * x,y coordinates of first vector
239  * @param new_p1 new p1 value
240  * @param index index for of the value
241  */
242 void
243 LaserBoxFilterInterface::CreateNewBoxFilterMessage::set_p1(unsigned int index, const double new_p1)
244 {
245  if (index > 2) {
246  throw Exception("Index value %u out of bounds (0..2)", index);
247  }
248  data->p1[index] = new_p1;
249 }
250 /** Get p2 value.
251  * x,y coordinates of second vector
252  * @return p2 value
253  */
254 double *
256 {
257  return data->p2;
258 }
259 
260 /** Get p2 value at given index.
261  * x,y coordinates of second vector
262  * @param index index of value
263  * @return p2 value
264  * @exception Exception thrown if index is out of bounds
265  */
266 double
268 {
269  if (index > 2) {
270  throw Exception("Index value %u out of bounds (0..2)", index);
271  }
272  return data->p2[index];
273 }
274 
275 /** Get maximum length of p2 value.
276  * @return length of p2 value, can be length of the array or number of
277  * maximum number of characters for a string
278  */
279 size_t
281 {
282  return 2;
283 }
284 
285 /** Set p2 value.
286  * x,y coordinates of second vector
287  * @param new_p2 new p2 value
288  */
289 void
291 {
292  memcpy(data->p2, new_p2, sizeof(double) * 2);
293 }
294 
295 /** Set p2 value at given index.
296  * x,y coordinates of second vector
297  * @param new_p2 new p2 value
298  * @param index index for of the value
299  */
300 void
301 LaserBoxFilterInterface::CreateNewBoxFilterMessage::set_p2(unsigned int index, const double new_p2)
302 {
303  if (index > 2) {
304  throw Exception("Index value %u out of bounds (0..2)", index);
305  }
306  data->p2[index] = new_p2;
307 }
308 /** Get p3 value.
309  * x,y coordinates of third vector
310  * @return p3 value
311  */
312 double *
314 {
315  return data->p3;
316 }
317 
318 /** Get p3 value at given index.
319  * x,y coordinates of third vector
320  * @param index index of value
321  * @return p3 value
322  * @exception Exception thrown if index is out of bounds
323  */
324 double
326 {
327  if (index > 2) {
328  throw Exception("Index value %u out of bounds (0..2)", index);
329  }
330  return data->p3[index];
331 }
332 
333 /** Get maximum length of p3 value.
334  * @return length of p3 value, can be length of the array or number of
335  * maximum number of characters for a string
336  */
337 size_t
339 {
340  return 2;
341 }
342 
343 /** Set p3 value.
344  * x,y coordinates of third vector
345  * @param new_p3 new p3 value
346  */
347 void
349 {
350  memcpy(data->p3, new_p3, sizeof(double) * 2);
351 }
352 
353 /** Set p3 value at given index.
354  * x,y coordinates of third vector
355  * @param new_p3 new p3 value
356  * @param index index for of the value
357  */
358 void
359 LaserBoxFilterInterface::CreateNewBoxFilterMessage::set_p3(unsigned int index, const double new_p3)
360 {
361  if (index > 2) {
362  throw Exception("Index value %u out of bounds (0..2)", index);
363  }
364  data->p3[index] = new_p3;
365 }
366 /** Get p4 value.
367  * x,y coordinates of fourth vector
368  * @return p4 value
369  */
370 double *
372 {
373  return data->p4;
374 }
375 
376 /** Get p4 value at given index.
377  * x,y coordinates of fourth vector
378  * @param index index of value
379  * @return p4 value
380  * @exception Exception thrown if index is out of bounds
381  */
382 double
384 {
385  if (index > 2) {
386  throw Exception("Index value %u out of bounds (0..2)", index);
387  }
388  return data->p4[index];
389 }
390 
391 /** Get maximum length of p4 value.
392  * @return length of p4 value, can be length of the array or number of
393  * maximum number of characters for a string
394  */
395 size_t
397 {
398  return 2;
399 }
400 
401 /** Set p4 value.
402  * x,y coordinates of fourth vector
403  * @param new_p4 new p4 value
404  */
405 void
407 {
408  memcpy(data->p4, new_p4, sizeof(double) * 2);
409 }
410 
411 /** Set p4 value at given index.
412  * x,y coordinates of fourth vector
413  * @param new_p4 new p4 value
414  * @param index index for of the value
415  */
416 void
417 LaserBoxFilterInterface::CreateNewBoxFilterMessage::set_p4(unsigned int index, const double new_p4)
418 {
419  if (index > 2) {
420  throw Exception("Index value %u out of bounds (0..2)", index);
421  }
422  data->p4[index] = new_p4;
423 }
424 /** Clone this message.
425  * Produces a message of the same type as this message and copies the
426  * data to the new message.
427  * @return clone of this message
428  */
429 Message *
431 {
433 }
434 /** Check if message is valid and can be enqueued.
435  * @param message Message to check
436  * @return true if the message is valid, false otherwise.
437  */
438 bool
440 {
441  const CreateNewBoxFilterMessage *m0 = dynamic_cast<const CreateNewBoxFilterMessage *>(message);
442  if ( m0 != NULL ) {
443  return true;
444  }
445  return false;
446 }
447 
448 /// @cond INTERNALS
449 EXPORT_INTERFACE(LaserBoxFilterInterface)
450 /// @endcond
451 
452 
453 } // end namespace fawkes
size_t maxlenof_p3() const
Get maximum length of p3 value.
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:125
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:41
void set_p3(unsigned int index, const double new_p3)
Set p3 value at given index.
Fawkes library namespace.
Timestamp data, must be present and first entries for each interface data structs!...
Definition: message.h:130
size_t maxlenof_p1() const
Get maximum length of p1 value.
void set_p1(unsigned int index, const double new_p1)
Set p1 value at given index.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:78
LaserBoxFilterInterface Fawkes BlackBoard Interface.
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:135
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:126
const char * type() const
Get type of interface.
Definition: interface.cpp:640
void * data_ptr
Pointer to local memory storage.
Definition: interface.h:224
Base class for exceptions in Fawkes.
Definition: exception.h:35
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
size_t maxlenof_p2() const
Get maximum length of p2 value.
CreateNewBoxFilterMessage Fawkes BlackBoard Interface Message.
size_t maxlenof_p4() const
Get maximum length of p4 value.
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:410
void set_p4(unsigned int index, const double new_p4)
Set p4 value at given index.
double field
Definition: types.h:47
void set_p2(unsigned int index, const double new_p2)
Set p2 value at given index.