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 *
76 Position2DTrackInterface::track_x_positions() const
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
104 Position2DTrackInterface::maxlenof_track_x_positions() const
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  data_changed |= change_field(data->track_x_positions, new_track_x_positions);
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  data_changed |= change_field(data->track_x_positions, index, new_track_x_positions);
134 }
135 /** Get track_y_positions value.
136  *
137  Y-Positions of the track. The first array-element is the oldest position of the track,
138  the last is the newest.
139 
140  * @return track_y_positions value
141  */
142 float *
143 Position2DTrackInterface::track_y_positions() const
144 {
145  return data->track_y_positions;
146 }
147 
148 /** Get track_y_positions value at given index.
149  *
150  Y-Positions of the track. The first array-element is the oldest position of the track,
151  the last is the newest.
152 
153  * @param index index of value
154  * @return track_y_positions value
155  * @exception Exception thrown if index is out of bounds
156  */
157 float
158 Position2DTrackInterface::track_y_positions(unsigned int index) const
159 {
160  if (index > 29) {
161  throw Exception("Index value %u out of bounds (0..29)", index);
162  }
163  return data->track_y_positions[index];
164 }
165 
166 /** Get maximum length of track_y_positions value.
167  * @return length of track_y_positions value, can be length of the array or number of
168  * maximum number of characters for a string
169  */
170 size_t
171 Position2DTrackInterface::maxlenof_track_y_positions() const
172 {
173  return 30;
174 }
175 
176 /** Set track_y_positions value.
177  *
178  Y-Positions of the track. The first array-element is the oldest position of the track,
179  the last is the newest.
180 
181  * @param new_track_y_positions new track_y_positions value
182  */
183 void
184 Position2DTrackInterface::set_track_y_positions(const float * new_track_y_positions)
185 {
186  data_changed |= change_field(data->track_y_positions, new_track_y_positions);
187 }
188 
189 /** Set track_y_positions value at given index.
190  *
191  Y-Positions of the track. The first array-element is the oldest position of the track,
192  the last is the newest.
193 
194  * @param new_track_y_positions new track_y_positions value
195  * @param index index for of the value
196  */
197 void
198 Position2DTrackInterface::set_track_y_positions(unsigned int index, const float new_track_y_positions)
199 {
200  data_changed |= change_field(data->track_y_positions, index, new_track_y_positions);
201 }
202 /** Get track_timestamps value.
203  *
204  Timestamps of the track. The first array-element is the oldest position of the track,
205  the last is the newest.
206 
207  * @return track_timestamps value
208  */
209 int32_t *
210 Position2DTrackInterface::track_timestamps() const
211 {
212  return data->track_timestamps;
213 }
214 
215 /** Get track_timestamps value at given index.
216  *
217  Timestamps of the track. The first array-element is the oldest position of the track,
218  the last is the newest.
219 
220  * @param index index of value
221  * @return track_timestamps value
222  * @exception Exception thrown if index is out of bounds
223  */
224 int32_t
225 Position2DTrackInterface::track_timestamps(unsigned int index) const
226 {
227  if (index > 29) {
228  throw Exception("Index value %u out of bounds (0..29)", index);
229  }
230  return data->track_timestamps[index];
231 }
232 
233 /** Get maximum length of track_timestamps value.
234  * @return length of track_timestamps value, can be length of the array or number of
235  * maximum number of characters for a string
236  */
237 size_t
238 Position2DTrackInterface::maxlenof_track_timestamps() const
239 {
240  return 30;
241 }
242 
243 /** Set track_timestamps value.
244  *
245  Timestamps of the track. The first array-element is the oldest position of the track,
246  the last is the newest.
247 
248  * @param new_track_timestamps new track_timestamps value
249  */
250 void
251 Position2DTrackInterface::set_track_timestamps(const int32_t * new_track_timestamps)
252 {
253  data_changed |= change_field(data->track_timestamps, new_track_timestamps);
254 }
255 
256 /** Set track_timestamps value at given index.
257  *
258  Timestamps of the track. The first array-element is the oldest position of the track,
259  the last is the newest.
260 
261  * @param new_track_timestamps new track_timestamps value
262  * @param index index for of the value
263  */
264 void
265 Position2DTrackInterface::set_track_timestamps(unsigned int index, const int32_t new_track_timestamps)
266 {
267  data_changed |= change_field(data->track_timestamps, index, new_track_timestamps);
268 }
269 /** Get length value.
270  * Length of the Tracks (i.e. up to which index there are valid positions).
271  * @return length value
272  */
273 uint32_t
274 Position2DTrackInterface::length() const
275 {
276  return data->length;
277 }
278 
279 /** Get maximum length of length value.
280  * @return length of length value, can be length of the array or number of
281  * maximum number of characters for a string
282  */
283 size_t
284 Position2DTrackInterface::maxlenof_length() const
285 {
286  return 1;
287 }
288 
289 /** Set length value.
290  * Length of the Tracks (i.e. up to which index there are valid positions).
291  * @param new_length new length value
292  */
293 void
294 Position2DTrackInterface::set_length(const uint32_t new_length)
295 {
296  data_changed |= change_field(data->length, new_length);
297 }
298 
299 /** Get track_id value.
300  * The ID of the Track.
301  * @return track_id value
302  */
303 uint32_t
304 Position2DTrackInterface::track_id() const
305 {
306  return data->track_id;
307 }
308 
309 /** Get maximum length of track_id value.
310  * @return length of track_id value, can be length of the array or number of
311  * maximum number of characters for a string
312  */
313 size_t
314 Position2DTrackInterface::maxlenof_track_id() const
315 {
316  return 1;
317 }
318 
319 /** Set track_id value.
320  * The ID of the Track.
321  * @param new_track_id new track_id value
322  */
323 void
324 Position2DTrackInterface::set_track_id(const uint32_t new_track_id)
325 {
326  data_changed |= change_field(data->track_id, new_track_id);
327 }
328 
329 /* =========== message create =========== */
330 Message *
331 Position2DTrackInterface::create_message(const char *type) const
332 {
333  throw UnknownTypeException("The given type '%s' does not match any known "
334  "message type for this interface type.", type);
335 }
336 
337 
338 /** Copy values from other interface.
339  * @param other other interface to copy values from
340  */
341 void
342 Position2DTrackInterface::copy_values(const Interface *other)
343 {
344  const Position2DTrackInterface *oi = dynamic_cast<const Position2DTrackInterface *>(other);
345  if (oi == NULL) {
346  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
347  type(), other->type());
348  }
349  memcpy(data, oi->data, sizeof(Position2DTrackInterface_data_t));
350 }
351 
352 const char *
353 Position2DTrackInterface::enum_tostring(const char *enumtype, int val) const
354 {
355  throw UnknownTypeException("Unknown enum type %s", enumtype);
356 }
357 
358 /* =========== messages =========== */
359 /** Check if message is valid and can be enqueued.
360  * @param message Message to check
361  * @return true if the message is valid, false otherwise.
362  */
363 bool
364 Position2DTrackInterface::message_valid(const Message *message) const
365 {
366  return false;
367 }
368 
369 /// @cond INTERNALS
370 EXPORT_INTERFACE(Position2DTrackInterface)
371 /// @endcond
372 
373 
374 } // end namespace fawkes
Base class for exceptions in Fawkes.
Definition: exception.h:36
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
const char * type() const
Get type of interface.
Definition: interface.cpp:643
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:45
Position2DTrackInterface Fawkes BlackBoard Interface.
Fawkes library namespace.
bool change_field(FieldT &field, const DataT &value)
Set a field and return whether it changed.
Definition: message.h:167