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_UINT32, "length", 1, &data->length);
57  add_fieldinfo(IFT_UINT32, "track_id", 1, &data->track_id);
58  unsigned char tmp_hash[] = {0x48, 0xe9, 0x35, 0x74, 0x18, 0x14, 0x46, 0x31, 0x6e, 0x5c, 0x76, 0x2e, 0x39, 0x1, 0x5, 0x30};
59  set_hash(tmp_hash);
60 }
61 
62 /** Destructor */
63 Position2DTrackInterface::~Position2DTrackInterface()
64 {
65  free(data_ptr);
66 }
67 /* Methods */
68 /** Get track_x_positions value.
69  *
70  X-Positions of the track. The first array-element is the oldest position of the track,
71  the last is the newest.
72 
73  * @return track_x_positions value
74  */
75 float *
77 {
78  return data->track_x_positions;
79 }
80 
81 /** Get track_x_positions value at given index.
82  *
83  X-Positions of the track. The first array-element is the oldest position of the track,
84  the last is the newest.
85 
86  * @param index index of value
87  * @return track_x_positions value
88  * @exception Exception thrown if index is out of bounds
89  */
90 float
91 Position2DTrackInterface::track_x_positions(unsigned int index) const
92 {
93  if (index > 29) {
94  throw Exception("Index value %u out of bounds (0..29)", index);
95  }
96  return data->track_x_positions[index];
97 }
98 
99 /** Get maximum length of track_x_positions value.
100  * @return length of track_x_positions value, can be length of the array or number of
101  * maximum number of characters for a string
102  */
103 size_t
105 {
106  return 30;
107 }
108 
109 /** Set track_x_positions value.
110  *
111  X-Positions of the track. The first array-element is the oldest position of the track,
112  the last is the newest.
113 
114  * @param new_track_x_positions new track_x_positions value
115  */
116 void
117 Position2DTrackInterface::set_track_x_positions(const float * new_track_x_positions)
118 {
119  memcpy(data->track_x_positions, new_track_x_positions, sizeof(float) * 30);
120  data_changed = true;
121 }
122 
123 /** Set track_x_positions value at given index.
124  *
125  X-Positions of the track. The first array-element is the oldest position of the track,
126  the last is the newest.
127 
128  * @param new_track_x_positions new track_x_positions value
129  * @param index index for of the value
130  */
131 void
132 Position2DTrackInterface::set_track_x_positions(unsigned int index, const float new_track_x_positions)
133 {
134  if (index > 29) {
135  throw Exception("Index value %u out of bounds (0..29)", index);
136  }
137  data->track_x_positions[index] = new_track_x_positions;
138  data_changed = true;
139 }
140 /** Get track_y_positions value.
141  *
142  Y-Positions of the track. The first array-element is the oldest position of the track,
143  the last is the newest.
144 
145  * @return track_y_positions value
146  */
147 float *
149 {
150  return data->track_y_positions;
151 }
152 
153 /** Get track_y_positions value at given index.
154  *
155  Y-Positions of the track. The first array-element is the oldest position of the track,
156  the last is the newest.
157 
158  * @param index index of value
159  * @return track_y_positions value
160  * @exception Exception thrown if index is out of bounds
161  */
162 float
163 Position2DTrackInterface::track_y_positions(unsigned int index) const
164 {
165  if (index > 29) {
166  throw Exception("Index value %u out of bounds (0..29)", index);
167  }
168  return data->track_y_positions[index];
169 }
170 
171 /** Get maximum length of track_y_positions value.
172  * @return length of track_y_positions value, can be length of the array or number of
173  * maximum number of characters for a string
174  */
175 size_t
177 {
178  return 30;
179 }
180 
181 /** Set track_y_positions value.
182  *
183  Y-Positions of the track. The first array-element is the oldest position of the track,
184  the last is the newest.
185 
186  * @param new_track_y_positions new track_y_positions value
187  */
188 void
189 Position2DTrackInterface::set_track_y_positions(const float * new_track_y_positions)
190 {
191  memcpy(data->track_y_positions, new_track_y_positions, sizeof(float) * 30);
192  data_changed = true;
193 }
194 
195 /** Set track_y_positions value at given index.
196  *
197  Y-Positions of the track. The first array-element is the oldest position of the track,
198  the last is the newest.
199 
200  * @param new_track_y_positions new track_y_positions value
201  * @param index index for of the value
202  */
203 void
204 Position2DTrackInterface::set_track_y_positions(unsigned int index, const float new_track_y_positions)
205 {
206  if (index > 29) {
207  throw Exception("Index value %u out of bounds (0..29)", index);
208  }
209  data->track_y_positions[index] = new_track_y_positions;
210  data_changed = true;
211 }
212 /** Get track_timestamps value.
213  *
214  Timestamps of the track. The first array-element is the oldest position of the track,
215  the last is the newest.
216 
217  * @return track_timestamps value
218  */
219 int32_t *
221 {
222  return data->track_timestamps;
223 }
224 
225 /** Get track_timestamps value at given index.
226  *
227  Timestamps of the track. The first array-element is the oldest position of the track,
228  the last is the newest.
229 
230  * @param index index of value
231  * @return track_timestamps value
232  * @exception Exception thrown if index is out of bounds
233  */
234 int32_t
235 Position2DTrackInterface::track_timestamps(unsigned int index) const
236 {
237  if (index > 29) {
238  throw Exception("Index value %u out of bounds (0..29)", index);
239  }
240  return data->track_timestamps[index];
241 }
242 
243 /** Get maximum length of track_timestamps value.
244  * @return length of track_timestamps value, can be length of the array or number of
245  * maximum number of characters for a string
246  */
247 size_t
249 {
250  return 30;
251 }
252 
253 /** Set track_timestamps value.
254  *
255  Timestamps of the track. The first array-element is the oldest position of the track,
256  the last is the newest.
257 
258  * @param new_track_timestamps new track_timestamps value
259  */
260 void
261 Position2DTrackInterface::set_track_timestamps(const int32_t * new_track_timestamps)
262 {
263  memcpy(data->track_timestamps, new_track_timestamps, sizeof(int32_t) * 30);
264  data_changed = true;
265 }
266 
267 /** Set track_timestamps value at given index.
268  *
269  Timestamps of the track. The first array-element is the oldest position of the track,
270  the last is the newest.
271 
272  * @param new_track_timestamps new track_timestamps value
273  * @param index index for of the value
274  */
275 void
276 Position2DTrackInterface::set_track_timestamps(unsigned int index, const int32_t new_track_timestamps)
277 {
278  if (index > 29) {
279  throw Exception("Index value %u out of bounds (0..29)", index);
280  }
281  data->track_timestamps[index] = new_track_timestamps;
282  data_changed = true;
283 }
284 /** Get length value.
285  * Length of the Tracks (i.e. up to which index there are valid positions).
286  * @return length value
287  */
288 uint32_t
290 {
291  return data->length;
292 }
293 
294 /** Get maximum length of length value.
295  * @return length of length value, can be length of the array or number of
296  * maximum number of characters for a string
297  */
298 size_t
300 {
301  return 1;
302 }
303 
304 /** Set length value.
305  * Length of the Tracks (i.e. up to which index there are valid positions).
306  * @param new_length new length value
307  */
308 void
309 Position2DTrackInterface::set_length(const uint32_t new_length)
310 {
311  data->length = new_length;
312  data_changed = true;
313 }
314 
315 /** Get track_id value.
316  * The ID of the Track.
317  * @return track_id value
318  */
319 uint32_t
321 {
322  return data->track_id;
323 }
324 
325 /** Get maximum length of track_id value.
326  * @return length of track_id value, can be length of the array or number of
327  * maximum number of characters for a string
328  */
329 size_t
331 {
332  return 1;
333 }
334 
335 /** Set track_id value.
336  * The ID of the Track.
337  * @param new_track_id new track_id value
338  */
339 void
340 Position2DTrackInterface::set_track_id(const uint32_t new_track_id)
341 {
342  data->track_id = new_track_id;
343  data_changed = true;
344 }
345 
346 /* =========== message create =========== */
347 Message *
349 {
350  throw UnknownTypeException("The given type '%s' does not match any known "
351  "message type for this interface type.", type);
352 }
353 
354 
355 /** Copy values from other interface.
356  * @param other other interface to copy values from
357  */
358 void
360 {
361  const Position2DTrackInterface *oi = dynamic_cast<const Position2DTrackInterface *>(other);
362  if (oi == NULL) {
363  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
364  type(), other->type());
365  }
366  memcpy(data, oi->data, sizeof(Position2DTrackInterface_data_t));
367 }
368 
369 const char *
370 Position2DTrackInterface::enum_tostring(const char *enumtype, int val) const
371 {
372  throw UnknownTypeException("Unknown enum type %s", enumtype);
373 }
374 
375 /* =========== messages =========== */
376 /** Check if message is valid and can be enqueued.
377  * @param message Message to check
378  * @return true if the message is valid, false otherwise.
379  */
380 bool
382 {
383  return false;
384 }
385 
386 /// @cond INTERNALS
387 EXPORT_INTERFACE(Position2DTrackInterface)
388 /// @endcond
389 
390 
391 } // end namespace fawkes
fawkes::Position2DTrackInterface::maxlenof_track_x_positions
size_t maxlenof_track_x_positions() const
Get maximum length of track_x_positions value.
Definition: Position2DTrackInterface.cpp:110
fawkes::Interface::data_ptr
void * data_ptr
Definition: interface.h:224
fawkes::Position2DTrackInterface::copy_values
virtual void copy_values(const Interface *other)
Copy values from other interface.
Definition: Position2DTrackInterface.cpp:365
fawkes::Position2DTrackInterface::maxlenof_track_timestamps
size_t maxlenof_track_timestamps() const
Get maximum length of track_timestamps value.
Definition: Position2DTrackInterface.cpp:254
fawkes::Position2DTrackInterface::maxlenof_length
size_t maxlenof_length() const
Get maximum length of length value.
Definition: Position2DTrackInterface.cpp:305
fawkes::Message
Definition: message.h:41
fawkes::Position2DTrackInterface::set_length
void set_length(const uint32_t new_length)
Set length value.
Definition: Position2DTrackInterface.cpp:315
fawkes::Message::data_ptr
void * data_ptr
Definition: message.h:125
fawkes::Position2DTrackInterface::maxlenof_track_id
size_t maxlenof_track_id() const
Get maximum length of track_id value.
Definition: Position2DTrackInterface.cpp:336
fawkes::IFT_FLOAT
@ IFT_FLOAT
float field
Definition: types.h:60
fawkes::Message::data_ts
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:135
fawkes::IFT_UINT32
@ IFT_UINT32
32 bit unsigned integer field
Definition: types.h:57
fawkes::Interface::type
const char * type() const
Get type of interface.
Definition: interface.cpp:645
fawkes::Position2DTrackInterface::track_timestamps
int32_t * track_timestamps() const
Get track_timestamps value.
Definition: Position2DTrackInterface.cpp:226
fawkes::TypeMismatchException
Definition: software.h:49
fawkes::Interface::data_changed
bool data_changed
Definition: interface.h:226
fawkes::IFT_INT32
@ IFT_INT32
32 bit integer field
Definition: types.h:56
fawkes::UnknownTypeException
Definition: software.h:55
fawkes
fawkes::Interface::set_hash
void set_hash(unsigned char *ihash)
Set hash.
Definition: interface.cpp:321
fawkes::Message::data_size
unsigned int data_size
Definition: message.h:126
fawkes::Interface
Definition: interface.h:78
fawkes::Position2DTrackInterface::track_x_positions
float * track_x_positions() const
Get track_x_positions value.
Definition: Position2DTrackInterface.cpp:82
fawkes::Position2DTrackInterface::set_track_x_positions
void set_track_x_positions(unsigned int index, const float new_track_x_positions)
Set track_x_positions value at given index.
Definition: Position2DTrackInterface.cpp:138
fawkes::Position2DTrackInterface::set_track_id
void set_track_id(const uint32_t new_track_id)
Set track_id value.
Definition: Position2DTrackInterface.cpp:346
fawkes::Position2DTrackInterface::create_message
virtual Message * create_message(const char *type) const
Definition: Position2DTrackInterface.cpp:354
fawkes::Message::add_fieldinfo
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:406
fawkes::Position2DTrackInterface::maxlenof_track_y_positions
size_t maxlenof_track_y_positions() const
Get maximum length of track_y_positions value.
Definition: Position2DTrackInterface.cpp:182
fawkes::Position2DTrackInterface::length
uint32_t length() const
Get length value.
Definition: Position2DTrackInterface.cpp:295
fawkes::Position2DTrackInterface::track_id
uint32_t track_id() const
Get track_id value.
Definition: Position2DTrackInterface.cpp:326
fawkes::Position2DTrackInterface::enum_tostring
virtual const char * enum_tostring(const char *enumtype, int val) const
Definition: Position2DTrackInterface.cpp:376
fawkes::Position2DTrackInterface::message_valid
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
Definition: Position2DTrackInterface.cpp:387
fawkes::Position2DTrackInterface
Definition: Position2DTrackInterface.h:39
fawkes::Position2DTrackInterface::track_y_positions
float * track_y_positions() const
Get track_y_positions value.
Definition: Position2DTrackInterface.cpp:154
fawkes::Position2DTrackInterface::set_track_y_positions
void set_track_y_positions(unsigned int index, const float new_track_y_positions)
Set track_y_positions value at given index.
Definition: Position2DTrackInterface.cpp:210
fawkes::Position2DTrackInterface::set_track_timestamps
void set_track_timestamps(unsigned int index, const int32_t new_track_timestamps)
Set track_timestamps value at given index.
Definition: Position2DTrackInterface.cpp:282
fawkes::Exception
Definition: exception.h:41