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
33namespace 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 */
46LaserBoxFilterInterface::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 */
60LaserBoxFilterInterface::~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 */
69uint32_t
70LaserBoxFilterInterface::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 */
79size_t
80LaserBoxFilterInterface::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 */
89void
90LaserBoxFilterInterface::set_num_boxes(const uint32_t new_num_boxes)
91{
92 set_field(data->num_boxes, new_num_boxes);
93}
94
95/* =========== message create =========== */
96Message *
97LaserBoxFilterInterface::create_message(const char *type) const
98{
99 if ( strncmp("CreateNewBoxFilterMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
100 return new CreateNewBoxFilterMessage();
101 } else {
102 throw UnknownTypeException("The given type '%s' does not match any known "
103 "message type for this interface type.", type);
104 }
105}
106
107
108/** Copy values from other interface.
109 * @param other other interface to copy values from
110 */
111void
112LaserBoxFilterInterface::copy_values(const Interface *other)
113{
114 const LaserBoxFilterInterface *oi = dynamic_cast<const LaserBoxFilterInterface *>(other);
115 if (oi == NULL) {
116 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
117 type(), other->type());
118 }
119 memcpy(data, oi->data, sizeof(LaserBoxFilterInterface_data_t));
120}
121
122const char *
123LaserBoxFilterInterface::enum_tostring(const char *enumtype, int val) const
124{
125 throw UnknownTypeException("Unknown enum type %s", enumtype);
126}
127
128/* =========== messages =========== */
129/** @class LaserBoxFilterInterface::CreateNewBoxFilterMessage <interfaces/LaserBoxFilterInterface.h>
130 * CreateNewBoxFilterMessage Fawkes BlackBoard Interface Message.
131 *
132
133 */
134
135
136/** Constructor with initial values.
137 * @param ini_p1 initial value for p1
138 * @param ini_p2 initial value for p2
139 * @param ini_p3 initial value for p3
140 * @param ini_p4 initial value for p4
141 */
142LaserBoxFilterInterface::CreateNewBoxFilterMessage::CreateNewBoxFilterMessage(const double * ini_p1, const double * ini_p2, const double * ini_p3, const double * ini_p4) : Message("CreateNewBoxFilterMessage")
143{
144 data_size = sizeof(CreateNewBoxFilterMessage_data_t);
145 data_ptr = malloc(data_size);
146 memset(data_ptr, 0, data_size);
147 data = (CreateNewBoxFilterMessage_data_t *)data_ptr;
149 memcpy(data->p1, ini_p1, sizeof(double) * 2);
150 memcpy(data->p2, ini_p2, sizeof(double) * 2);
151 memcpy(data->p3, ini_p3, sizeof(double) * 2);
152 memcpy(data->p4, ini_p4, sizeof(double) * 2);
153 add_fieldinfo(IFT_DOUBLE, "p1", 2, &data->p1);
154 add_fieldinfo(IFT_DOUBLE, "p2", 2, &data->p2);
155 add_fieldinfo(IFT_DOUBLE, "p3", 2, &data->p3);
156 add_fieldinfo(IFT_DOUBLE, "p4", 2, &data->p4);
157}
158/** Constructor */
160{
161 data_size = sizeof(CreateNewBoxFilterMessage_data_t);
162 data_ptr = malloc(data_size);
163 memset(data_ptr, 0, data_size);
164 data = (CreateNewBoxFilterMessage_data_t *)data_ptr;
166 add_fieldinfo(IFT_DOUBLE, "p1", 2, &data->p1);
167 add_fieldinfo(IFT_DOUBLE, "p2", 2, &data->p2);
168 add_fieldinfo(IFT_DOUBLE, "p3", 2, &data->p3);
169 add_fieldinfo(IFT_DOUBLE, "p4", 2, &data->p4);
170}
171
172/** Destructor */
174{
175 free(data_ptr);
176}
177
178/** Copy constructor.
179 * @param m message to copy from
180 */
182{
183 data_size = m->data_size;
184 data_ptr = malloc(data_size);
185 memcpy(data_ptr, m->data_ptr, data_size);
186 data = (CreateNewBoxFilterMessage_data_t *)data_ptr;
188}
189
190/* Methods */
191/** Get p1 value.
192 * x,y coordinates of first vector
193 * @return p1 value
194 */
195double *
197{
198 return data->p1;
199}
200
201/** Get p1 value at given index.
202 * x,y coordinates of first vector
203 * @param index index of value
204 * @return p1 value
205 * @exception Exception thrown if index is out of bounds
206 */
207double
209{
210 if (index > 1) {
211 throw Exception("Index value %u out of bounds (0..1)", index);
212 }
213 return data->p1[index];
214}
215
216/** Get maximum length of p1 value.
217 * @return length of p1 value, can be length of the array or number of
218 * maximum number of characters for a string
219 */
220size_t
222{
223 return 2;
224}
225
226/** Set p1 value.
227 * x,y coordinates of first vector
228 * @param new_p1 new p1 value
229 */
230void
232{
233 set_field(data->p1, new_p1);
234}
235
236/** Set p1 value at given index.
237 * x,y coordinates of first vector
238 * @param new_p1 new p1 value
239 * @param index index for of the value
240 */
241void
243{
244 set_field(data->p1, index, new_p1);
245}
246/** Get p2 value.
247 * x,y coordinates of second vector
248 * @return p2 value
249 */
250double *
252{
253 return data->p2;
254}
255
256/** Get p2 value at given index.
257 * x,y coordinates of second vector
258 * @param index index of value
259 * @return p2 value
260 * @exception Exception thrown if index is out of bounds
261 */
262double
264{
265 if (index > 1) {
266 throw Exception("Index value %u out of bounds (0..1)", index);
267 }
268 return data->p2[index];
269}
270
271/** Get maximum length of p2 value.
272 * @return length of p2 value, can be length of the array or number of
273 * maximum number of characters for a string
274 */
275size_t
277{
278 return 2;
279}
280
281/** Set p2 value.
282 * x,y coordinates of second vector
283 * @param new_p2 new p2 value
284 */
285void
287{
288 set_field(data->p2, new_p2);
289}
290
291/** Set p2 value at given index.
292 * x,y coordinates of second vector
293 * @param new_p2 new p2 value
294 * @param index index for of the value
295 */
296void
298{
299 set_field(data->p2, index, new_p2);
300}
301/** Get p3 value.
302 * x,y coordinates of third vector
303 * @return p3 value
304 */
305double *
307{
308 return data->p3;
309}
310
311/** Get p3 value at given index.
312 * x,y coordinates of third vector
313 * @param index index of value
314 * @return p3 value
315 * @exception Exception thrown if index is out of bounds
316 */
317double
319{
320 if (index > 1) {
321 throw Exception("Index value %u out of bounds (0..1)", index);
322 }
323 return data->p3[index];
324}
325
326/** Get maximum length of p3 value.
327 * @return length of p3 value, can be length of the array or number of
328 * maximum number of characters for a string
329 */
330size_t
332{
333 return 2;
334}
335
336/** Set p3 value.
337 * x,y coordinates of third vector
338 * @param new_p3 new p3 value
339 */
340void
342{
343 set_field(data->p3, new_p3);
344}
345
346/** Set p3 value at given index.
347 * x,y coordinates of third vector
348 * @param new_p3 new p3 value
349 * @param index index for of the value
350 */
351void
353{
354 set_field(data->p3, index, new_p3);
355}
356/** Get p4 value.
357 * x,y coordinates of fourth vector
358 * @return p4 value
359 */
360double *
362{
363 return data->p4;
364}
365
366/** Get p4 value at given index.
367 * x,y coordinates of fourth vector
368 * @param index index of value
369 * @return p4 value
370 * @exception Exception thrown if index is out of bounds
371 */
372double
374{
375 if (index > 1) {
376 throw Exception("Index value %u out of bounds (0..1)", index);
377 }
378 return data->p4[index];
379}
380
381/** Get maximum length of p4 value.
382 * @return length of p4 value, can be length of the array or number of
383 * maximum number of characters for a string
384 */
385size_t
387{
388 return 2;
389}
390
391/** Set p4 value.
392 * x,y coordinates of fourth vector
393 * @param new_p4 new p4 value
394 */
395void
397{
398 set_field(data->p4, new_p4);
399}
400
401/** Set p4 value at given index.
402 * x,y coordinates of fourth vector
403 * @param new_p4 new p4 value
404 * @param index index for of the value
405 */
406void
408{
409 set_field(data->p4, index, new_p4);
410}
411/** Clone this message.
412 * Produces a message of the same type as this message and copies the
413 * data to the new message.
414 * @return clone of this message
415 */
416Message *
418{
420}
421/** Check if message is valid and can be enqueued.
422 * @param message Message to check
423 * @return true if the message is valid, false otherwise.
424 */
425bool
427{
428 const CreateNewBoxFilterMessage *m0 = dynamic_cast<const CreateNewBoxFilterMessage *>(message);
429 if ( m0 != NULL ) {
430 return true;
431 }
432 return false;
433}
434
435/// @cond INTERNALS
436EXPORT_INTERFACE(LaserBoxFilterInterface)
437/// @endcond
438
439
440} // end namespace fawkes
Base class for exceptions in Fawkes.
Definition: exception.h:36
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
CreateNewBoxFilterMessage Fawkes BlackBoard Interface Message.
size_t maxlenof_p3() const
Get maximum length of p3 value.
void set_p4(unsigned int index, const double new_p4)
Set p4 value at given index.
size_t maxlenof_p2() const
Get maximum length of p2 value.
void set_p1(unsigned int index, const double new_p1)
Set p1 value at given index.
void set_p2(unsigned int index, const double new_p2)
Set p2 value at given index.
size_t maxlenof_p1() const
Get maximum length of p1 value.
void set_p3(unsigned int index, const double new_p3)
Set p3 value at given index.
size_t maxlenof_p4() const
Get maximum length of p4 value.
LaserBoxFilterInterface Fawkes BlackBoard Interface.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
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.
@ IFT_DOUBLE
double field
Definition: types.h:47
Timestamp data, must be present and first entries for each interface data structs!...
Definition: message.h:152