Fawkes API  Fawkes Development Version
Position2DTrackInterface.cpp
1 
2 /***************************************************************************
3  * Position2DTrackInterface.cpp - Fawkes BlackBoard Interface - Position2DTrackInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2009 Masrur Doostdar
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/Position2DTrackInterface.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 Position2DTrackInterface <interfaces/Position2DTrackInterface.h>
36  * Position2DTrackInterface Fawkes BlackBoard Interface.
37  *
38  This interface provides access to a track of 2D positions.
39 
40  * @ingroup FawkesInterfaces
41  */
42 
43 
44 
45 /** Constructor */
46 Position2DTrackInterface::Position2DTrackInterface() : Interface()
47 {
48  data_size = sizeof(Position2DTrackInterface_data_t);
49  data_ptr = malloc(data_size);
50  data = (Position2DTrackInterface_data_t *)data_ptr;
51  data_ts = (interface_data_ts_t *)data_ptr;
52  memset(data_ptr, 0, data_size);
53  add_fieldinfo(IFT_FLOAT, "track_x_positions", 30, &data->track_x_positions);
54  add_fieldinfo(IFT_FLOAT, "track_y_positions", 30, &data->track_y_positions);
55  add_fieldinfo(IFT_INT32, "track_timestamps", 30, &data->track_timestamps);
56  add_fieldinfo(IFT_BOOL, "valid", 1, &data->valid);
57  add_fieldinfo(IFT_UINT32, "length", 1, &data->length);
58  add_fieldinfo(IFT_UINT32, "track_id", 1, &data->track_id);
59  unsigned char tmp_hash[] = {0xcd, 0xb8, 0x68, 0x14, 0xff, 0x3, 0xe4, 0xc4, 0x20, 0x43, 0x44, 0xb8, 0x86, 0x87, 0xa3, 0x4c};
60  set_hash(tmp_hash);
61 }
62 
63 /** Destructor */
64 Position2DTrackInterface::~Position2DTrackInterface()
65 {
66  free(data_ptr);
67 }
68 /* Methods */
69 /** Get track_x_positions value.
70  *
71  X-Positions of the track. The first array-element is the oldest position of the track,
72  the last is the newest.
73 
74  * @return track_x_positions value
75  */
76 float *
78 {
79  return data->track_x_positions;
80 }
81 
82 /** Get track_x_positions value at given index.
83  *
84  X-Positions of the track. The first array-element is the oldest position of the track,
85  the last is the newest.
86 
87  * @param index index of value
88  * @return track_x_positions value
89  * @exception Exception thrown if index is out of bounds
90  */
91 float
93 {
94  if (index > 30) {
95  throw Exception("Index value %u out of bounds (0..30)", index);
96  }
97  return data->track_x_positions[index];
98 }
99 
100 /** Get maximum length of track_x_positions value.
101  * @return length of track_x_positions value, can be length of the array or number of
102  * maximum number of characters for a string
103  */
104 size_t
106 {
107  return 30;
108 }
109 
110 /** Set track_x_positions value.
111  *
112  X-Positions of the track. The first array-element is the oldest position of the track,
113  the last is the newest.
114 
115  * @param new_track_x_positions new track_x_positions value
116  */
117 void
118 Position2DTrackInterface::set_track_x_positions(const float * new_track_x_positions)
119 {
120  memcpy(data->track_x_positions, new_track_x_positions, sizeof(float) * 30);
121  data_changed = true;
122 }
123 
124 /** Set track_x_positions value at given index.
125  *
126  X-Positions of the track. The first array-element is the oldest position of the track,
127  the last is the newest.
128 
129  * @param new_track_x_positions new track_x_positions value
130  * @param index index for of the value
131  */
132 void
133 Position2DTrackInterface::set_track_x_positions(unsigned int index, const float new_track_x_positions)
134 {
135  if (index > 30) {
136  throw Exception("Index value %u out of bounds (0..30)", index);
137  }
138  data->track_x_positions[index] = new_track_x_positions;
139  data_changed = true;
140 }
141 /** Get track_y_positions value.
142  *
143  Y-Positions of the track. The first array-element is the oldest position of the track,
144  the last is the newest.
145 
146  * @return track_y_positions value
147  */
148 float *
150 {
151  return data->track_y_positions;
152 }
153 
154 /** Get track_y_positions value at given index.
155  *
156  Y-Positions of the track. The first array-element is the oldest position of the track,
157  the last is the newest.
158 
159  * @param index index of value
160  * @return track_y_positions value
161  * @exception Exception thrown if index is out of bounds
162  */
163 float
165 {
166  if (index > 30) {
167  throw Exception("Index value %u out of bounds (0..30)", index);
168  }
169  return data->track_y_positions[index];
170 }
171 
172 /** Get maximum length of track_y_positions value.
173  * @return length of track_y_positions value, can be length of the array or number of
174  * maximum number of characters for a string
175  */
176 size_t
178 {
179  return 30;
180 }
181 
182 /** Set track_y_positions value.
183  *
184  Y-Positions of the track. The first array-element is the oldest position of the track,
185  the last is the newest.
186 
187  * @param new_track_y_positions new track_y_positions value
188  */
189 void
190 Position2DTrackInterface::set_track_y_positions(const float * new_track_y_positions)
191 {
192  memcpy(data->track_y_positions, new_track_y_positions, sizeof(float) * 30);
193  data_changed = true;
194 }
195 
196 /** Set track_y_positions value at given index.
197  *
198  Y-Positions of the track. The first array-element is the oldest position of the track,
199  the last is the newest.
200 
201  * @param new_track_y_positions new track_y_positions value
202  * @param index index for of the value
203  */
204 void
205 Position2DTrackInterface::set_track_y_positions(unsigned int index, const float new_track_y_positions)
206 {
207  if (index > 30) {
208  throw Exception("Index value %u out of bounds (0..30)", index);
209  }
210  data->track_y_positions[index] = new_track_y_positions;
211  data_changed = true;
212 }
213 /** Get track_timestamps value.
214  *
215  Timestamps of the track. The first array-element is the oldest position of the track,
216  the last is the newest.
217 
218  * @return track_timestamps value
219  */
220 int32_t *
222 {
223  return data->track_timestamps;
224 }
225 
226 /** Get track_timestamps value at given index.
227  *
228  Timestamps of the track. The first array-element is the oldest position of the track,
229  the last is the newest.
230 
231  * @param index index of value
232  * @return track_timestamps value
233  * @exception Exception thrown if index is out of bounds
234  */
235 int32_t
237 {
238  if (index > 30) {
239  throw Exception("Index value %u out of bounds (0..30)", index);
240  }
241  return data->track_timestamps[index];
242 }
243 
244 /** Get maximum length of track_timestamps value.
245  * @return length of track_timestamps value, can be length of the array or number of
246  * maximum number of characters for a string
247  */
248 size_t
250 {
251  return 30;
252 }
253 
254 /** Set track_timestamps value.
255  *
256  Timestamps of the track. The first array-element is the oldest position of the track,
257  the last is the newest.
258 
259  * @param new_track_timestamps new track_timestamps value
260  */
261 void
262 Position2DTrackInterface::set_track_timestamps(const int32_t * new_track_timestamps)
263 {
264  memcpy(data->track_timestamps, new_track_timestamps, sizeof(int32_t) * 30);
265  data_changed = true;
266 }
267 
268 /** Set track_timestamps value at given index.
269  *
270  Timestamps of the track. The first array-element is the oldest position of the track,
271  the last is the newest.
272 
273  * @param new_track_timestamps new track_timestamps value
274  * @param index index for of the value
275  */
276 void
277 Position2DTrackInterface::set_track_timestamps(unsigned int index, const int32_t new_track_timestamps)
278 {
279  if (index > 30) {
280  throw Exception("Index value %u out of bounds (0..30)", index);
281  }
282  data->track_timestamps[index] = new_track_timestamps;
283  data_changed = true;
284 }
285 /** Get valid value.
286  * True, if this track is valid.
287  * @return valid value
288  */
289 bool
291 {
292  return data->valid;
293 }
294 
295 /** Get maximum length of valid value.
296  * @return length of valid value, can be length of the array or number of
297  * maximum number of characters for a string
298  */
299 size_t
301 {
302  return 1;
303 }
304 
305 /** Set valid value.
306  * True, if this track is valid.
307  * @param new_valid new valid value
308  */
309 void
311 {
312  data->valid = new_valid;
313  data_changed = true;
314 }
315 
316 /** Get length value.
317  * Length of the Tracks (i.e. up to which index there are valid positions).
318  * @return length value
319  */
320 uint32_t
322 {
323  return data->length;
324 }
325 
326 /** Get maximum length of length value.
327  * @return length of length value, can be length of the array or number of
328  * maximum number of characters for a string
329  */
330 size_t
332 {
333  return 1;
334 }
335 
336 /** Set length value.
337  * Length of the Tracks (i.e. up to which index there are valid positions).
338  * @param new_length new length value
339  */
340 void
341 Position2DTrackInterface::set_length(const uint32_t new_length)
342 {
343  data->length = new_length;
344  data_changed = true;
345 }
346 
347 /** Get track_id value.
348  * The ID of the Track.
349  * @return track_id value
350  */
351 uint32_t
353 {
354  return data->track_id;
355 }
356 
357 /** Get maximum length of track_id value.
358  * @return length of track_id value, can be length of the array or number of
359  * maximum number of characters for a string
360  */
361 size_t
363 {
364  return 1;
365 }
366 
367 /** Set track_id value.
368  * The ID of the Track.
369  * @param new_track_id new track_id value
370  */
371 void
372 Position2DTrackInterface::set_track_id(const uint32_t new_track_id)
373 {
374  data->track_id = new_track_id;
375  data_changed = true;
376 }
377 
378 /* =========== message create =========== */
379 Message *
381 {
382  throw UnknownTypeException("The given type '%s' does not match any known "
383  "message type for this interface type.", type);
384 }
385 
386 
387 /** Copy values from other interface.
388  * @param other other interface to copy values from
389  */
390 void
392 {
393  const Position2DTrackInterface *oi = dynamic_cast<const Position2DTrackInterface *>(other);
394  if (oi == NULL) {
395  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
396  type(), other->type());
397  }
398  memcpy(data, oi->data, sizeof(Position2DTrackInterface_data_t));
399 }
400 
401 const char *
402 Position2DTrackInterface::enum_tostring(const char *enumtype, int val) const
403 {
404  throw UnknownTypeException("Unknown enum type %s", enumtype);
405 }
406 
407 /* =========== messages =========== */
408 /** Check if message is valid and can be enqueued.
409  * @param message Message to check
410  * @return true if the message is valid, false otherwise.
411  */
412 bool
414 {
415  return false;
416 }
417 
418 /// @cond INTERNALS
419 EXPORT_INTERFACE(Position2DTrackInterface)
420 /// @endcond
421 
422 
423 } // end namespace fawkes
void set_valid(const bool new_valid)
Set valid value.
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:124
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
float * track_x_positions() const
Get track_x_positions value.
void set_track_x_positions(unsigned int index, const float new_track_x_positions)
Set track_x_positions value at given index.
void set_hash(unsigned char *ihash)
Set hash.
Definition: interface.cpp:314
Fawkes library namespace.
size_t maxlenof_track_y_positions() const
Get maximum length of track_y_positions value.
size_t maxlenof_valid() const
Get maximum length of valid value.
void set_track_id(const uint32_t new_track_id)
Set track_id value.
uint32_t length() const
Get length value.
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.
virtual Message * create_message(const char *type) const
Create message based on type name.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
uint32_t track_id() const
Get track_id value.
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:133
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:125
void set_track_y_positions(unsigned int index, const float new_track_y_positions)
Set track_y_positions value at given index.
void set_track_timestamps(unsigned int index, const int32_t new_track_timestamps)
Set track_timestamps value at given index.
bool data_changed
Indicator if data has changed.
Definition: interface.h:222
bool is_valid() const
Get valid value.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
float * track_y_positions() const
Get track_y_positions value.
const char * type() const
Get type of interface.
Definition: interface.cpp:651
Base class for exceptions in Fawkes.
Definition: exception.h:36
size_t maxlenof_track_x_positions() const
Get maximum length of track_x_positions value.
size_t maxlenof_track_timestamps() const
Get maximum length of track_timestamps value.
virtual void copy_values(const Interface *other)
Copy values from other interface.
float field
Definition: types.h:45
size_t maxlenof_length() const
Get maximum length of length value.
32 bit integer field
Definition: types.h:41
void set_length(const uint32_t new_length)
Set length value.
size_t maxlenof_track_id() const
Get maximum length of track_id value.
int32_t * track_timestamps() const
Get track_timestamps 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:436
boolean field
Definition: types.h:36
const char * type() const
Get message type.
Definition: message.cpp:378
32 bit unsigned integer field
Definition: types.h:42
Position2DTrackInterface Fawkes BlackBoard Interface.