Laser360Interface.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/Laser360Interface.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
00046
00047
00048 Laser360Interface::Laser360Interface() : Interface()
00049 {
00050 data_size = sizeof(Laser360Interface_data_t);
00051 data_ptr = malloc(data_size);
00052 data = (Laser360Interface_data_t *)data_ptr;
00053 data_ts = (interface_data_ts_t *)data_ptr;
00054 memset(data_ptr, 0, data_size);
00055 add_fieldinfo(IFT_FLOAT, "distances", 360, &data->distances);
00056 add_fieldinfo(IFT_BOOL, "clockwise_angle", 1, &data->clockwise_angle);
00057 unsigned char tmp_hash[] = {0xf6, 0x3a, 0x26, 0x7b, 0x46, 0x96, 0x74, 0xad, 0x48, 0x1c, 0x32, 0x66, 0x2b, 0xfe, 0x41, 0x43};
00058 set_hash(tmp_hash);
00059 }
00060
00061
00062 Laser360Interface::~Laser360Interface()
00063 {
00064 free(data_ptr);
00065 }
00066
00067
00068
00069
00070
00071
00072
00073 float *
00074 Laser360Interface::distances() const
00075 {
00076 return data->distances;
00077 }
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 float
00088 Laser360Interface::distances(unsigned int index) const
00089 {
00090 if (index > 360) {
00091 throw Exception("Index value %u out of bounds (0..360)", index);
00092 }
00093 return data->distances[index];
00094 }
00095
00096
00097
00098
00099
00100 size_t
00101 Laser360Interface::maxlenof_distances() const
00102 {
00103 return 360;
00104 }
00105
00106
00107
00108
00109
00110
00111
00112 void
00113 Laser360Interface::set_distances(const float * new_distances)
00114 {
00115 memcpy(data->distances, new_distances, sizeof(float) * 360);
00116 data_changed = true;
00117 }
00118
00119
00120
00121
00122
00123
00124
00125
00126 void
00127 Laser360Interface::set_distances(unsigned int index, const float new_distances)
00128 {
00129 if (index > 360) {
00130 throw Exception("Index value %u out of bounds (0..360)", index);
00131 }
00132 data->distances[index] = new_distances;
00133 }
00134
00135
00136
00137
00138
00139
00140 bool
00141 Laser360Interface::is_clockwise_angle() const
00142 {
00143 return data->clockwise_angle;
00144 }
00145
00146
00147
00148
00149
00150 size_t
00151 Laser360Interface::maxlenof_clockwise_angle() const
00152 {
00153 return 1;
00154 }
00155
00156
00157
00158
00159
00160
00161
00162 void
00163 Laser360Interface::set_clockwise_angle(const bool new_clockwise_angle)
00164 {
00165 data->clockwise_angle = new_clockwise_angle;
00166 data_changed = true;
00167 }
00168
00169
00170 Message *
00171 Laser360Interface::create_message(const char *type) const
00172 {
00173 throw UnknownTypeException("The given type '%s' does not match any known "
00174 "message type for this interface type.", type);
00175 }
00176
00177
00178
00179
00180
00181 void
00182 Laser360Interface::copy_values(const Interface *other)
00183 {
00184 const Laser360Interface *oi = dynamic_cast<const Laser360Interface *>(other);
00185 if (oi == NULL) {
00186 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00187 type(), other->type());
00188 }
00189 memcpy(data, oi->data, sizeof(Laser360Interface_data_t));
00190 }
00191
00192 const char *
00193 Laser360Interface::enum_tostring(const char *enumtype, int val) const
00194 {
00195 throw UnknownTypeException("Unknown enum type %s", enumtype);
00196 }
00197
00198
00199
00200
00201
00202
00203 bool
00204 Laser360Interface::message_valid(const Message *message) const
00205 {
00206 return false;
00207 }
00208
00209
00210 EXPORT_INTERFACE(Laser360Interface)
00211
00212
00213
00214 }