Laser720Interface.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
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 data_ts = (interface_data_ts_t *)data_ptr;
00051 memset(data_ptr, 0, data_size);
00052 add_fieldinfo(IFT_FLOAT, "distances", 720, &data->distances);
00053 add_fieldinfo(IFT_BOOL, "clockwise_angle", 1, &data->clockwise_angle);
00054 unsigned char tmp_hash[] = {0x8a, 0x9, 0x94, 0x1a, 0xe4, 0x3c, 0xa5, 0xde, 0x5, 0xe7, 0x8c, 0x6e, 0x3b, 0x7f, 0x34, 0x5};
00055 set_hash(tmp_hash);
00056 }
00057
00058
00059 Laser720Interface::~Laser720Interface()
00060 {
00061 free(data_ptr);
00062 }
00063
00064
00065
00066
00067
00068
00069
00070 float *
00071 Laser720Interface::distances() const
00072 {
00073 return data->distances;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 float
00085 Laser720Interface::distances(unsigned int index) const
00086 {
00087 if (index > 720) {
00088 throw Exception("Index value %u out of bounds (0..720)", index);
00089 }
00090 return data->distances[index];
00091 }
00092
00093
00094
00095
00096
00097 size_t
00098 Laser720Interface::maxlenof_distances() const
00099 {
00100 return 720;
00101 }
00102
00103
00104
00105
00106
00107
00108
00109 void
00110 Laser720Interface::set_distances(const float * new_distances)
00111 {
00112 memcpy(data->distances, new_distances, sizeof(float) * 720);
00113 data_changed = true;
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123 void
00124 Laser720Interface::set_distances(unsigned int index, const float new_distances)
00125 {
00126 if (index > 720) {
00127 throw Exception("Index value %u out of bounds (0..720)", index);
00128 }
00129 data->distances[index] = new_distances;
00130 }
00131
00132
00133
00134
00135
00136
00137 bool
00138 Laser720Interface::is_clockwise_angle() const
00139 {
00140 return data->clockwise_angle;
00141 }
00142
00143
00144
00145
00146
00147 size_t
00148 Laser720Interface::maxlenof_clockwise_angle() const
00149 {
00150 return 1;
00151 }
00152
00153
00154
00155
00156
00157
00158
00159 void
00160 Laser720Interface::set_clockwise_angle(const bool new_clockwise_angle)
00161 {
00162 data->clockwise_angle = new_clockwise_angle;
00163 data_changed = true;
00164 }
00165
00166
00167 Message *
00168 Laser720Interface::create_message(const char *type) const
00169 {
00170 throw UnknownTypeException("The given type '%s' does not match any known "
00171 "message type for this interface type.", type);
00172 }
00173
00174
00175
00176
00177
00178 void
00179 Laser720Interface::copy_values(const Interface *other)
00180 {
00181 const Laser720Interface *oi = dynamic_cast<const Laser720Interface *>(other);
00182 if (oi == NULL) {
00183 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00184 type(), other->type());
00185 }
00186 memcpy(data, oi->data, sizeof(Laser720Interface_data_t));
00187 }
00188
00189 const char *
00190 Laser720Interface::enum_tostring(const char *enumtype, int val) const
00191 {
00192 throw UnknownTypeException("Unknown enum type %s", enumtype);
00193 }
00194
00195
00196
00197
00198
00199
00200 bool
00201 Laser720Interface::message_valid(const Message *message) const
00202 {
00203 return false;
00204 }
00205
00206
00207 EXPORT_INTERFACE(Laser720Interface)
00208
00209
00210
00211 }