Fawkes API  Fawkes Development Version
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   data_changed = true;
00138 }
00139 /** Get track_y_positions value.
00140  * 
00141       Y-Positions of the track. The first array-element is the oldest position of the track, 
00142       the last is the newest.
00143     
00144  * @return track_y_positions value
00145  */
00146 float *
00147 Position2DTrackInterface::track_y_positions() const
00148 {
00149   return data->track_y_positions;
00150 }
00151 
00152 /** Get track_y_positions value at given index.
00153  * 
00154       Y-Positions of the track. The first array-element is the oldest position of the track, 
00155       the last is the newest.
00156     
00157  * @param index index of value
00158  * @return track_y_positions value
00159  * @exception Exception thrown if index is out of bounds
00160  */
00161 float
00162 Position2DTrackInterface::track_y_positions(unsigned int index) const
00163 {
00164   if (index > 30) {
00165     throw Exception("Index value %u out of bounds (0..30)", index);
00166   }
00167   return data->track_y_positions[index];
00168 }
00169 
00170 /** Get maximum length of track_y_positions value.
00171  * @return length of track_y_positions value, can be length of the array or number of 
00172  * maximum number of characters for a string
00173  */
00174 size_t
00175 Position2DTrackInterface::maxlenof_track_y_positions() const
00176 {
00177   return 30;
00178 }
00179 
00180 /** Set track_y_positions value.
00181  * 
00182       Y-Positions of the track. The first array-element is the oldest position of the track, 
00183       the last is the newest.
00184     
00185  * @param new_track_y_positions new track_y_positions value
00186  */
00187 void
00188 Position2DTrackInterface::set_track_y_positions(const float * new_track_y_positions)
00189 {
00190   memcpy(data->track_y_positions, new_track_y_positions, sizeof(float) * 30);
00191   data_changed = true;
00192 }
00193 
00194 /** Set track_y_positions value at given index.
00195  * 
00196       Y-Positions of the track. The first array-element is the oldest position of the track, 
00197       the last is the newest.
00198     
00199  * @param new_track_y_positions new track_y_positions value
00200  * @param index index for of the value
00201  */
00202 void
00203 Position2DTrackInterface::set_track_y_positions(unsigned int index, const float new_track_y_positions)
00204 {
00205   if (index > 30) {
00206     throw Exception("Index value %u out of bounds (0..30)", index);
00207   }
00208   data->track_y_positions[index] = new_track_y_positions;
00209   data_changed = true;
00210 }
00211 /** Get track_timestamps value.
00212  * 
00213       Timestamps of the track. The first array-element is the oldest position of the track, 
00214       the last is the newest.
00215     
00216  * @return track_timestamps value
00217  */
00218 int32_t *
00219 Position2DTrackInterface::track_timestamps() const
00220 {
00221   return data->track_timestamps;
00222 }
00223 
00224 /** Get track_timestamps value at given index.
00225  * 
00226       Timestamps of the track. The first array-element is the oldest position of the track, 
00227       the last is the newest.
00228     
00229  * @param index index of value
00230  * @return track_timestamps value
00231  * @exception Exception thrown if index is out of bounds
00232  */
00233 int32_t
00234 Position2DTrackInterface::track_timestamps(unsigned int index) const
00235 {
00236   if (index > 30) {
00237     throw Exception("Index value %u out of bounds (0..30)", index);
00238   }
00239   return data->track_timestamps[index];
00240 }
00241 
00242 /** Get maximum length of track_timestamps value.
00243  * @return length of track_timestamps value, can be length of the array or number of 
00244  * maximum number of characters for a string
00245  */
00246 size_t
00247 Position2DTrackInterface::maxlenof_track_timestamps() const
00248 {
00249   return 30;
00250 }
00251 
00252 /** Set track_timestamps value.
00253  * 
00254       Timestamps of the track. The first array-element is the oldest position of the track, 
00255       the last is the newest.
00256     
00257  * @param new_track_timestamps new track_timestamps value
00258  */
00259 void
00260 Position2DTrackInterface::set_track_timestamps(const int32_t * new_track_timestamps)
00261 {
00262   memcpy(data->track_timestamps, new_track_timestamps, sizeof(int32_t) * 30);
00263   data_changed = true;
00264 }
00265 
00266 /** Set track_timestamps value at given index.
00267  * 
00268       Timestamps of the track. The first array-element is the oldest position of the track, 
00269       the last is the newest.
00270     
00271  * @param new_track_timestamps new track_timestamps value
00272  * @param index index for of the value
00273  */
00274 void
00275 Position2DTrackInterface::set_track_timestamps(unsigned int index, const int32_t new_track_timestamps)
00276 {
00277   if (index > 30) {
00278     throw Exception("Index value %u out of bounds (0..30)", index);
00279   }
00280   data->track_timestamps[index] = new_track_timestamps;
00281   data_changed = true;
00282 }
00283 /** Get valid value.
00284  * True, if this track is valid.
00285  * @return valid value
00286  */
00287 bool
00288 Position2DTrackInterface::is_valid() const
00289 {
00290   return data->valid;
00291 }
00292 
00293 /** Get maximum length of valid value.
00294  * @return length of valid value, can be length of the array or number of 
00295  * maximum number of characters for a string
00296  */
00297 size_t
00298 Position2DTrackInterface::maxlenof_valid() const
00299 {
00300   return 1;
00301 }
00302 
00303 /** Set valid value.
00304  * True, if this track is valid.
00305  * @param new_valid new valid value
00306  */
00307 void
00308 Position2DTrackInterface::set_valid(const bool new_valid)
00309 {
00310   data->valid = new_valid;
00311   data_changed = true;
00312 }
00313 
00314 /** Get length value.
00315  * Length of the Tracks (i.e. up to which index there are valid positions).
00316  * @return length value
00317  */
00318 uint32_t
00319 Position2DTrackInterface::length() const
00320 {
00321   return data->length;
00322 }
00323 
00324 /** Get maximum length of length value.
00325  * @return length of length value, can be length of the array or number of 
00326  * maximum number of characters for a string
00327  */
00328 size_t
00329 Position2DTrackInterface::maxlenof_length() const
00330 {
00331   return 1;
00332 }
00333 
00334 /** Set length value.
00335  * Length of the Tracks (i.e. up to which index there are valid positions).
00336  * @param new_length new length value
00337  */
00338 void
00339 Position2DTrackInterface::set_length(const uint32_t new_length)
00340 {
00341   data->length = new_length;
00342   data_changed = true;
00343 }
00344 
00345 /** Get track_id value.
00346  * The ID of the Track.
00347  * @return track_id value
00348  */
00349 uint32_t
00350 Position2DTrackInterface::track_id() const
00351 {
00352   return data->track_id;
00353 }
00354 
00355 /** Get maximum length of track_id value.
00356  * @return length of track_id value, can be length of the array or number of 
00357  * maximum number of characters for a string
00358  */
00359 size_t
00360 Position2DTrackInterface::maxlenof_track_id() const
00361 {
00362   return 1;
00363 }
00364 
00365 /** Set track_id value.
00366  * The ID of the Track.
00367  * @param new_track_id new track_id value
00368  */
00369 void
00370 Position2DTrackInterface::set_track_id(const uint32_t new_track_id)
00371 {
00372   data->track_id = new_track_id;
00373   data_changed = true;
00374 }
00375 
00376 /* =========== message create =========== */
00377 Message *
00378 Position2DTrackInterface::create_message(const char *type) const
00379 {
00380   throw UnknownTypeException("The given type '%s' does not match any known "
00381                              "message type for this interface type.", type);
00382 }
00383 
00384 
00385 /** Copy values from other interface.
00386  * @param other other interface to copy values from
00387  */
00388 void
00389 Position2DTrackInterface::copy_values(const Interface *other)
00390 {
00391   const Position2DTrackInterface *oi = dynamic_cast<const Position2DTrackInterface *>(other);
00392   if (oi == NULL) {
00393     throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00394                                 type(), other->type());
00395   }
00396   memcpy(data, oi->data, sizeof(Position2DTrackInterface_data_t));
00397 }
00398 
00399 const char *
00400 Position2DTrackInterface::enum_tostring(const char *enumtype, int val) const
00401 {
00402   throw UnknownTypeException("Unknown enum type %s", enumtype);
00403 }
00404 
00405 /* =========== messages =========== */
00406 /** Check if message is valid and can be enqueued.
00407  * @param message Message to check
00408  * @return true if the message is valid, false otherwise.
00409  */
00410 bool
00411 Position2DTrackInterface::message_valid(const Message *message) const
00412 {
00413   return false;
00414 }
00415 
00416 /// @cond INTERNALS
00417 EXPORT_INTERFACE(Position2DTrackInterface)
00418 /// @endcond
00419 
00420 
00421 } // end namespace fawkes