Laser720Interface.cpp

00001
00002 /***************************************************************************
00003  *  Laser720Interface.cpp - Fawkes BlackBoard Interface - Laser720Interface
00004  *
00005  *  Templated created:   Thu Oct 12 10:49:19 2006
00006  *  Copyright  2008  Tim Niemueller
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/Laser720Interface.h>
00025
00026 #include <core/exceptions/software.h>
00027
00028 #include <cstring>
00029 #include <cstdlib>
00030
00031 namespace fawkes {
00032 
00033 /** @class Laser720Interface <interfaces/Laser720Interface.h>
00034  * Laser720Interface Fawkes BlackBoard Interface.
00035  * 
00036       This interface provides access to data of a laser scanner that produces
00037       720 beams per scan.
00038     
00039  * @ingroup FawkesInterfaces
00040  */
00041
00042
00043 
00044 /** Constructor */
00045 Laser720Interface::Laser720Interface() : Interface()
00046 {
00047   data_size = sizeof(Laser720Interface_data_t);
00048   data_ptr  = malloc(data_size);
00049   data      = (Laser720Interface_data_t *)data_ptr;
00050   memset(data_ptr, 0, data_size);
00051   add_fieldinfo(IFT_FLOAT, "distances", 720, &data->distances);
00052   unsigned char tmp_hash[] = {0xc6, 0x5c, 0xe2, 0xcd, 0x6, 0x6c, 0xdb, 0x3f, 0x8c, 0x81, 0x78, 0xe1, 0xba, 0xf4, 0xc5, 0x17};
00053   set_hash(tmp_hash);
00054 }
00055 
00056 /** Destructor */
00057 Laser720Interface::~Laser720Interface()
00058 {
00059   free(data_ptr);
00060 }
00061 /* Methods */
00062 /** Get distances value.
00063  * 
00064       The distances in meter of the beams.
00065     
00066  * @return distances value
00067  */
00068 float *
00069 Laser720Interface::distances() const
00070 {
00071   return data->distances;
00072 }
00073 
00074 /** Get distances value at given index.
00075  * 
00076       The distances in meter of the beams.
00077     
00078  * @param index index of value
00079  * @return distances value
00080  * @exception Exception thrown if index is out of bounds
00081  */
00082 float
00083 Laser720Interface::distances(unsigned int index) const
00084 {
00085   if (index > 720) {
00086     throw Exception("Index value %u out of bounds (0..720)", index);
00087   }
00088   return data->distances[index];
00089 }
00090 
00091 /** Get maximum length of distances value.
00092  * @return length of distances value, can be length of the array or number of 
00093  * maximum number of characters for a string
00094  */
00095 size_t
00096 Laser720Interface::maxlenof_distances() const
00097 {
00098   return 720;
00099 }
00100 
00101 /** Set distances value.
00102  * 
00103       The distances in meter of the beams.
00104     
00105  * @param new_distances new distances value
00106  */
00107 void
00108 Laser720Interface::set_distances(const float * new_distances)
00109 {
00110   memcpy(data->distances, new_distances, sizeof(float) * 720);
00111 }
00112 
00113 /** Set distances value at given index.
00114  * 
00115       The distances in meter of the beams.
00116     
00117  * @param new_distances new distances value
00118  * @param index index for of the value
00119  */
00120 void
00121 Laser720Interface::set_distances(unsigned int index, const float new_distances)
00122 {
00123   if (index > 720) {
00124     throw Exception("Index value %u out of bounds (0..720)", index);
00125   }
00126   data->distances[index] = new_distances;
00127 }
00128 /* =========== message create =========== */
00129 Message *
00130 Laser720Interface::create_message(const char *type) const
00131 {
00132   throw UnknownTypeException("The given type '%s' does not match any known "
00133                              "message type for this interface type.", type);
00134 }
00135
00136 
00137 /** Copy values from other interface.
00138  * @param other other interface to copy values from
00139  */
00140 void
00141 Laser720Interface::copy_values(const Interface *other)
00142 {
00143   const Laser720Interface *oi = dynamic_cast<const Laser720Interface *>(other);
00144   if (oi == NULL) {
00145     throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00146                                 type(), other->type());
00147   }
00148   memcpy(data, oi->data, sizeof(Laser720Interface_data_t));
00149 }
00150
00151 /* =========== messages =========== */
00152 /** Check if message is valid and can be enqueued.
00153  * @param message Message to check
00154  */
00155 bool
00156 Laser720Interface::message_valid(const Message *message) const
00157 {
00158   return false;
00159 }
00160 
00161 /// @cond INTERNALS
00162 EXPORT_INTERFACE(Laser720Interface)
00163 /// @endcond
00164 
00165
00166 } // end namespace fawkes