Position2DTrackInterface.cpp

00001 
00002 /***************************************************************************
00003  *  Position2DTrackInterface.cpp - Fawkes BlackBoard Interface - Position2DTrackInterface
00004  *
00005  *  Templated created:   Thu Oct 12 10:49:19 2006
00006  *  Copyright  2009  Masrur Doostdar
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #include <interfaces/Position2DTrackInterface.h>
00025 
00026 #include <core/exceptions/software.h>
00027 
00028 #include <cstring>
00029 #include <cstdlib>
00030 
00031 namespace fawkes {
00032 
00033 /** @class Position2DTrackInterface <interfaces/Position2DTrackInterface.h>
00034  * Position2DTrackInterface Fawkes BlackBoard Interface.
00035  * 
00036       This interface provides access to a track of 2D positions.
00037     
00038  * @ingroup FawkesInterfaces
00039  */
00040 
00041 
00042 
00043 /** Constructor */
00044 Position2DTrackInterface::Position2DTrackInterface() : Interface()
00045 {
00046   data_size = sizeof(Position2DTrackInterface_data_t);
00047   data_ptr  = malloc(data_size);
00048   data      = (Position2DTrackInterface_data_t *)data_ptr;
00049   data_ts   = (interface_data_ts_t *)data_ptr;
00050   memset(data_ptr, 0, data_size);
00051   add_fieldinfo(IFT_FLOAT, "track_x_positions", 30, &data->track_x_positions);
00052   add_fieldinfo(IFT_FLOAT, "track_y_positions", 30, &data->track_y_positions);
00053   add_fieldinfo(IFT_INT32, "track_timestamps", 30, &data->track_timestamps);
00054   add_fieldinfo(IFT_BOOL, "valid", 1, &data->valid);
00055   add_fieldinfo(IFT_UINT32, "length", 1, &data->length);
00056   add_fieldinfo(IFT_UINT32, "track_id", 1, &data->track_id);
00057   unsigned char tmp_hash[] = {0xcd, 0xb8, 0x68, 0x14, 0xff, 0x3, 0xe4, 0xc4, 0x20, 0x43, 0x44, 0xb8, 0x86, 0x87, 0xa3, 0x4c};
00058   set_hash(tmp_hash);
00059 }
00060 
00061 /** Destructor */
00062 Position2DTrackInterface::~Position2DTrackInterface()
00063 {
00064   free(data_ptr);
00065 }
00066 /* Methods */
00067 /** Get track_x_positions value.
00068  * 
00069       X-Positions of the track. The first array-element is the oldest position of the track, 
00070       the last is the newest.
00071     
00072  * @return track_x_positions value
00073  */
00074 float *
00075 Position2DTrackInterface::track_x_positions() const
00076 {
00077   return data->track_x_positions;
00078 }
00079 
00080 /** Get track_x_positions value at given index.
00081  * 
00082       X-Positions of the track. The first array-element is the oldest position of the track, 
00083       the last is the newest.
00084     
00085  * @param index index of value
00086  * @return track_x_positions value
00087  * @exception Exception thrown if index is out of bounds
00088  */
00089 float
00090 Position2DTrackInterface::track_x_positions(unsigned int index) const
00091 {
00092   if (index > 30) {
00093     throw Exception("Index value %u out of bounds (0..30)", index);
00094   }
00095   return data->track_x_positions[index];
00096 }
00097 
00098 /** Get maximum length of track_x_positions value.
00099  * @return length of track_x_positions value, can be length of the array or number of 
00100  * maximum number of characters for a string
00101  */
00102 size_t
00103 Position2DTrackInterface::maxlenof_track_x_positions() const
00104 {
00105   return 30;
00106 }
00107 
00108 /** Set track_x_positions value.
00109  * 
00110       X-Positions of the track. The first array-element is the oldest position of the track, 
00111       the last is the newest.
00112     
00113  * @param new_track_x_positions new track_x_positions value
00114  */
00115 void
00116 Position2DTrackInterface::set_track_x_positions(const float * new_track_x_positions)
00117 {
00118   memcpy(data->track_x_positions, new_track_x_positions, sizeof(float) * 30);
00119   data_changed = true;
00120 }
00121 
00122 /** Set track_x_positions value at given index.
00123  * 
00124       X-Positions of the track. The first array-element is the oldest position of the track, 
00125       the last is the newest.
00126     
00127  * @param new_track_x_positions new track_x_positions value
00128  * @param index index for of the value
00129  */
00130 void
00131 Position2DTrackInterface::set_track_x_positions(unsigned int index, const float new_track_x_positions)
00132 {
00133   if (index > 30) {
00134     throw Exception("Index value %u out of bounds (0..30)", index);
00135   }
00136   data->track_x_positions[index] = new_track_x_positions;
00137 }
00138 /** Get track_y_positions value.
00139  * 
00140       Y-Positions of the track. The first array-element is the oldest position of the track, 
00141       the last is the newest.
00142     
00143  * @return track_y_positions value
00144  */
00145 float *
00146 Position2DTrackInterface::track_y_positions() const
00147 {
00148   return data->track_y_positions;
00149 }
00150 
00151 /** Get track_y_positions value at given index.
00152  * 
00153       Y-Positions of the track. The first array-element is the oldest position of the track, 
00154       the last is the newest.
00155     
00156  * @param index index of value
00157  * @return track_y_positions value
00158  * @exception Exception thrown if index is out of bounds
00159  */
00160 float
00161 Position2DTrackInterface::track_y_positions(unsigned int index) const
00162 {
00163   if (index > 30) {
00164     throw Exception("Index value %u out of bounds (0..30)", index);
00165   }
00166   return data->track_y_positions[index];
00167 }
00168 
00169 /** Get maximum length of track_y_positions value.
00170  * @return length of track_y_positions value, can be length of the array or number of 
00171  * maximum number of characters for a string
00172  */
00173 size_t
00174 Position2DTrackInterface::maxlenof_track_y_positions() const
00175 {
00176   return 30;
00177 }
00178 
00179 /** Set track_y_positions value.
00180  * 
00181       Y-Positions of the track. The first array-element is the oldest position of the track, 
00182       the last is the newest.
00183     
00184  * @param new_track_y_positions new track_y_positions value
00185  */
00186 void
00187 Position2DTrackInterface::set_track_y_positions(const float * new_track_y_positions)
00188 {
00189   memcpy(data->track_y_positions, new_track_y_positions, sizeof(float) * 30);
00190   data_changed = true;
00191 }
00192 
00193 /** Set track_y_positions value at given index.
00194  * 
00195       Y-Positions of the track. The first array-element is the oldest position of the track, 
00196       the last is the newest.
00197     
00198  * @param new_track_y_positions new track_y_positions value
00199  * @param index index for of the value
00200  */
00201 void
00202 Position2DTrackInterface::set_track_y_positions(unsigned int index, const float new_track_y_positions)
00203 {
00204   if (index > 30) {
00205     throw Exception("Index value %u out of bounds (0..30)", index);
00206   }
00207   data->track_y_positions[index] = new_track_y_positions;
00208 }
00209 /** Get track_timestamps value.
00210  * 
00211       Timestamps of the track. The first array-element is the oldest position of the track, 
00212       the last is the newest.
00213     
00214  * @return track_timestamps value
00215  */
00216 int32_t *
00217 Position2DTrackInterface::track_timestamps() const
00218 {
00219   return data->track_timestamps;
00220 }
00221 
00222 /** Get track_timestamps value at given index.
00223  * 
00224       Timestamps of the track. The first array-element is the oldest position of the track, 
00225       the last is the newest.
00226     
00227  * @param index index of value
00228  * @return track_timestamps value
00229  * @exception Exception thrown if index is out of bounds
00230  */
00231 int32_t
00232 Position2DTrackInterface::track_timestamps(unsigned int index) const
00233 {
00234   if (index > 30) {
00235     throw Exception("Index value %u out of bounds (0..30)", index);
00236   }
00237   return data->track_timestamps[index];
00238 }
00239 
00240 /** Get maximum length of track_timestamps value.
00241  * @return length of track_timestamps value, can be length of the array or number of 
00242  * maximum number of characters for a string
00243  */
00244 size_t
00245 Position2DTrackInterface::maxlenof_track_timestamps() const
00246 {
00247   return 30;
00248 }
00249 
00250 /** Set track_timestamps value.
00251  * 
00252       Timestamps of the track. The first array-element is the oldest position of the track, 
00253       the last is the newest.
00254     
00255  * @param new_track_timestamps new track_timestamps value
00256  */
00257 void
00258 Position2DTrackInterface::set_track_timestamps(const int32_t * new_track_timestamps)
00259 {
00260   memcpy(data->track_timestamps, new_track_timestamps, sizeof(int32_t) * 30);
00261   data_changed = true;
00262 }
00263 
00264 /** Set track_timestamps value at given index.
00265  * 
00266       Timestamps of the track. The first array-element is the oldest position of the track, 
00267       the last is the newest.
00268     
00269  * @param new_track_timestamps new track_timestamps value
00270  * @param index index for of the value
00271  */
00272 void
00273 Position2DTrackInterface::set_track_timestamps(unsigned int index, const int32_t new_track_timestamps)
00274 {
00275   if (index > 30) {
00276     throw Exception("Index value %u out of bounds (0..30)", index);
00277   }
00278   data->track_timestamps[index] = new_track_timestamps;
00279 }
00280 /** Get valid value.
00281  * True, if this track is valid.
00282  * @return valid value
00283  */
00284 bool
00285 Position2DTrackInterface::is_valid() const
00286 {
00287   return data->valid;
00288 }
00289 
00290 /** Get maximum length of valid value.
00291  * @return length of valid value, can be length of the array or number of 
00292  * maximum number of characters for a string
00293  */
00294 size_t
00295 Position2DTrackInterface::maxlenof_valid() const
00296 {
00297   return 1;
00298 }
00299 
00300 /** Set valid value.
00301  * True, if this track is valid.
00302  * @param new_valid new valid value
00303  */
00304 void
00305 Position2DTrackInterface::set_valid(const bool new_valid)
00306 {
00307   data->valid = new_valid;
00308   data_changed = true;
00309 }
00310 
00311 /** Get length value.
00312  * Length of the Tracks (i.e. up to which index there are valid positions).
00313  * @return length value
00314  */
00315 uint32_t
00316 Position2DTrackInterface::length() const
00317 {
00318   return data->length;
00319 }
00320 
00321 /** Get maximum length of length value.
00322  * @return length of length value, can be length of the array or number of 
00323  * maximum number of characters for a string
00324  */
00325 size_t
00326 Position2DTrackInterface::maxlenof_length() const
00327 {
00328   return 1;
00329 }
00330 
00331 /** Set length value.
00332  * Length of the Tracks (i.e. up to which index there are valid positions).
00333  * @param new_length new length value
00334  */
00335 void
00336 Position2DTrackInterface::set_length(const uint32_t new_length)
00337 {
00338   data->length = new_length;
00339   data_changed = true;
00340 }
00341 
00342 /** Get track_id value.
00343  * The ID of the Track.
00344  * @return track_id value
00345  */
00346 uint32_t
00347 Position2DTrackInterface::track_id() const
00348 {
00349   return data->track_id;
00350 }
00351 
00352 /** Get maximum length of track_id value.
00353  * @return length of track_id value, can be length of the array or number of 
00354  * maximum number of characters for a string
00355  */
00356 size_t
00357 Position2DTrackInterface::maxlenof_track_id() const
00358 {
00359   return 1;
00360 }
00361 
00362 /** Set track_id value.
00363  * The ID of the Track.
00364  * @param new_track_id new track_id value
00365  */
00366 void
00367 Position2DTrackInterface::set_track_id(const uint32_t new_track_id)
00368 {
00369   data->track_id = new_track_id;
00370   data_changed = true;
00371 }
00372 
00373 /* =========== message create =========== */
00374 Message *
00375 Position2DTrackInterface::create_message(const char *type) const
00376 {
00377   throw UnknownTypeException("The given type '%s' does not match any known "
00378                              "message type for this interface type.", type);
00379 }
00380 
00381 
00382 /** Copy values from other interface.
00383  * @param other other interface to copy values from
00384  */
00385 void
00386 Position2DTrackInterface::copy_values(const Interface *other)
00387 {
00388   const Position2DTrackInterface *oi = dynamic_cast<const Position2DTrackInterface *>(other);
00389   if (oi == NULL) {
00390     throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00391                                 type(), other->type());
00392   }
00393   memcpy(data, oi->data, sizeof(Position2DTrackInterface_data_t));
00394 }
00395 
00396 const char *
00397 Position2DTrackInterface::enum_tostring(const char *enumtype, int val) const
00398 {
00399   throw UnknownTypeException("Unknown enum type %s", enumtype);
00400 }
00401 
00402 /* =========== messages =========== */
00403 /** Check if message is valid and can be enqueued.
00404  * @param message Message to check
00405  * @return true if the message is valid, false otherwise.
00406  */
00407 bool
00408 Position2DTrackInterface::message_valid(const Message *message) const
00409 {
00410   return false;
00411 }
00412 
00413 /// @cond INTERNALS
00414 EXPORT_INTERFACE(Position2DTrackInterface)
00415 /// @endcond
00416 
00417 
00418 } // end namespace fawkes

Generated on Tue Feb 22 13:32:25 2011 for Fawkes API by  doxygen 1.4.7