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