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/LedInterface.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 const float LedInterface::ON = 1.0;
00046
00047 const float LedInterface::OFF = 0.0;
00048
00049
00050 LedInterface::LedInterface() : Interface()
00051 {
00052 data_size = sizeof(LedInterface_data_t);
00053 data_ptr = malloc(data_size);
00054 data = (LedInterface_data_t *)data_ptr;
00055 memset(data_ptr, 0, data_size);
00056 add_fieldinfo(IFT_FLOAT, "intensity", 1, &data->intensity);
00057 add_messageinfo("SetIntensityMessage");
00058 add_messageinfo("TurnOnMessage");
00059 add_messageinfo("TurnOffMessage");
00060 unsigned char tmp_hash[] = {0xd, 0x86, 0x60, 0xcd, 0xae, 0x41, 0xa5, 0xa1, 0xbc, 0xb7, 0xf, 0x9, 0x90, 00, 0x4d, 0x40};
00061 set_hash(tmp_hash);
00062 }
00063
00064
00065 LedInterface::~LedInterface()
00066 {
00067 free(data_ptr);
00068 }
00069
00070
00071
00072
00073
00074 float
00075 LedInterface::intensity() const
00076 {
00077 return data->intensity;
00078 }
00079
00080
00081
00082
00083
00084 size_t
00085 LedInterface::maxlenof_intensity() const
00086 {
00087 return 1;
00088 }
00089
00090
00091
00092
00093
00094 void
00095 LedInterface::set_intensity(const float new_intensity)
00096 {
00097 data->intensity = new_intensity;
00098 }
00099
00100
00101 Message *
00102 LedInterface::create_message(const char *type) const
00103 {
00104 if ( strncmp("SetIntensityMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00105 return new SetIntensityMessage();
00106 } else if ( strncmp("TurnOnMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00107 return new TurnOnMessage();
00108 } else if ( strncmp("TurnOffMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00109 return new TurnOffMessage();
00110 } else {
00111 throw UnknownTypeException("The given type '%s' does not match any known "
00112 "message type for this interface type.", type);
00113 }
00114 }
00115
00116
00117
00118
00119
00120 void
00121 LedInterface::copy_values(const Interface *other)
00122 {
00123 const LedInterface *oi = dynamic_cast<const LedInterface *>(other);
00124 if (oi == NULL) {
00125 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00126 type(), other->type());
00127 }
00128 memcpy(data, oi->data, sizeof(LedInterface_data_t));
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 LedInterface::SetIntensityMessage::SetIntensityMessage(const float ini_time_sec, const float ini_intensity) : Message("SetIntensityMessage")
00144 {
00145 data_size = sizeof(SetIntensityMessage_data_t);
00146 data_ptr = malloc(data_size);
00147 memset(data_ptr, 0, data_size);
00148 data = (SetIntensityMessage_data_t *)data_ptr;
00149 data->time_sec = ini_time_sec;
00150 data->intensity = ini_intensity;
00151 add_fieldinfo(IFT_FLOAT, "time_sec", 1, &data->time_sec);
00152 add_fieldinfo(IFT_FLOAT, "intensity", 1, &data->intensity);
00153 }
00154
00155 LedInterface::SetIntensityMessage::SetIntensityMessage() : Message("SetIntensityMessage")
00156 {
00157 data_size = sizeof(SetIntensityMessage_data_t);
00158 data_ptr = malloc(data_size);
00159 memset(data_ptr, 0, data_size);
00160 data = (SetIntensityMessage_data_t *)data_ptr;
00161 add_fieldinfo(IFT_FLOAT, "time_sec", 1, &data->time_sec);
00162 add_fieldinfo(IFT_FLOAT, "intensity", 1, &data->intensity);
00163 }
00164
00165
00166 LedInterface::SetIntensityMessage::~SetIntensityMessage()
00167 {
00168 free(data_ptr);
00169 }
00170
00171
00172
00173
00174 LedInterface::SetIntensityMessage::SetIntensityMessage(const SetIntensityMessage *m) : Message("SetIntensityMessage")
00175 {
00176 data_size = m->data_size;
00177 data_ptr = malloc(data_size);
00178 memcpy(data_ptr, m->data_ptr, data_size);
00179 data = (SetIntensityMessage_data_t *)data_ptr;
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189 float
00190 LedInterface::SetIntensityMessage::time_sec() const
00191 {
00192 return data->time_sec;
00193 }
00194
00195
00196
00197
00198
00199 size_t
00200 LedInterface::SetIntensityMessage::maxlenof_time_sec() const
00201 {
00202 return 1;
00203 }
00204
00205
00206
00207
00208
00209
00210
00211 void
00212 LedInterface::SetIntensityMessage::set_time_sec(const float new_time_sec)
00213 {
00214 data->time_sec = new_time_sec;
00215 }
00216
00217
00218
00219
00220
00221 float
00222 LedInterface::SetIntensityMessage::intensity() const
00223 {
00224 return data->intensity;
00225 }
00226
00227
00228
00229
00230
00231 size_t
00232 LedInterface::SetIntensityMessage::maxlenof_intensity() const
00233 {
00234 return 1;
00235 }
00236
00237
00238
00239
00240
00241 void
00242 LedInterface::SetIntensityMessage::set_intensity(const float new_intensity)
00243 {
00244 data->intensity = new_intensity;
00245 }
00246
00247
00248
00249
00250
00251
00252 Message *
00253 LedInterface::SetIntensityMessage::clone() const
00254 {
00255 return new LedInterface::SetIntensityMessage(this);
00256 }
00257
00258
00259
00260
00261
00262
00263
00264
00265 LedInterface::TurnOnMessage::TurnOnMessage() : Message("TurnOnMessage")
00266 {
00267 data_size = 0;
00268 data_ptr = NULL;
00269 }
00270
00271
00272 LedInterface::TurnOnMessage::~TurnOnMessage()
00273 {
00274 }
00275
00276
00277
00278
00279 LedInterface::TurnOnMessage::TurnOnMessage(const TurnOnMessage *m) : Message("TurnOnMessage")
00280 {
00281 data_size = 0;
00282 data_ptr = NULL;
00283 }
00284
00285
00286
00287
00288
00289
00290
00291 Message *
00292 LedInterface::TurnOnMessage::clone() const
00293 {
00294 return new LedInterface::TurnOnMessage(this);
00295 }
00296
00297
00298
00299
00300
00301
00302
00303
00304 LedInterface::TurnOffMessage::TurnOffMessage() : Message("TurnOffMessage")
00305 {
00306 data_size = 0;
00307 data_ptr = NULL;
00308 }
00309
00310
00311 LedInterface::TurnOffMessage::~TurnOffMessage()
00312 {
00313 }
00314
00315
00316
00317
00318 LedInterface::TurnOffMessage::TurnOffMessage(const TurnOffMessage *m) : Message("TurnOffMessage")
00319 {
00320 data_size = 0;
00321 data_ptr = NULL;
00322 }
00323
00324
00325
00326
00327
00328
00329
00330 Message *
00331 LedInterface::TurnOffMessage::clone() const
00332 {
00333 return new LedInterface::TurnOffMessage(this);
00334 }
00335
00336
00337
00338 bool
00339 LedInterface::message_valid(const Message *message) const
00340 {
00341 const SetIntensityMessage *m0 = dynamic_cast<const SetIntensityMessage *>(message);
00342 if ( m0 != NULL ) {
00343 return true;
00344 }
00345 const TurnOnMessage *m1 = dynamic_cast<const TurnOnMessage *>(message);
00346 if ( m1 != NULL ) {
00347 return true;
00348 }
00349 const TurnOffMessage *m2 = dynamic_cast<const TurnOffMessage *>(message);
00350 if ( m2 != NULL ) {
00351 return true;
00352 }
00353 return false;
00354 }
00355
00356
00357 EXPORT_INTERFACE(LedInterface)
00358
00359
00360
00361 }