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/SwitchInterface.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 SwitchInterface::SwitchInterface() : Interface()
00048 {
00049 data_size = sizeof(SwitchInterface_data_t);
00050 data_ptr = malloc(data_size);
00051 data = (SwitchInterface_data_t *)data_ptr;
00052 data_ts = (interface_data_ts_t *)data_ptr;
00053 memset(data_ptr, 0, data_size);
00054 add_fieldinfo(IFT_BOOL, "enabled", 1, &data->enabled);
00055 add_fieldinfo(IFT_FLOAT, "value", 1, &data->value);
00056 add_fieldinfo(IFT_FLOAT, "history", 1, &data->history);
00057 add_fieldinfo(IFT_UINT32, "short_activations", 1, &data->short_activations);
00058 add_fieldinfo(IFT_UINT32, "long_activations", 1, &data->long_activations);
00059 add_fieldinfo(IFT_UINT32, "activation_count", 1, &data->activation_count);
00060 add_messageinfo("SetMessage");
00061 add_messageinfo("EnableSwitchMessage");
00062 add_messageinfo("DisableSwitchMessage");
00063 add_messageinfo("EnableDurationMessage");
00064 unsigned char tmp_hash[] = {0xa7, 0xa4, 0xc, 0x19, 0x66, 0xa4, 0x87, 0x6b, 0xa9, 0x32, 0x95, 0x40, 0xc7, 0x82, 0x75, 0x6d};
00065 set_hash(tmp_hash);
00066 }
00067
00068
00069 SwitchInterface::~SwitchInterface()
00070 {
00071 free(data_ptr);
00072 }
00073
00074
00075
00076
00077
00078
00079
00080 bool
00081 SwitchInterface::is_enabled() const
00082 {
00083 return data->enabled;
00084 }
00085
00086
00087
00088
00089
00090 size_t
00091 SwitchInterface::maxlenof_enabled() const
00092 {
00093 return 1;
00094 }
00095
00096
00097
00098
00099
00100
00101
00102 void
00103 SwitchInterface::set_enabled(const bool new_enabled)
00104 {
00105 data->enabled = new_enabled;
00106 data_changed = true;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 float
00118 SwitchInterface::value() const
00119 {
00120 return data->value;
00121 }
00122
00123
00124
00125
00126
00127 size_t
00128 SwitchInterface::maxlenof_value() const
00129 {
00130 return 1;
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 void
00142 SwitchInterface::set_value(const float new_value)
00143 {
00144 data->value = new_value;
00145 data_changed = true;
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 float
00160 SwitchInterface::history() const
00161 {
00162 return data->history;
00163 }
00164
00165
00166
00167
00168
00169 size_t
00170 SwitchInterface::maxlenof_history() const
00171 {
00172 return 1;
00173 }
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 void
00187 SwitchInterface::set_history(const float new_history)
00188 {
00189 data->history = new_history;
00190 data_changed = true;
00191 }
00192
00193
00194
00195
00196
00197
00198
00199
00200 uint32_t
00201 SwitchInterface::short_activations() const
00202 {
00203 return data->short_activations;
00204 }
00205
00206
00207
00208
00209
00210 size_t
00211 SwitchInterface::maxlenof_short_activations() const
00212 {
00213 return 1;
00214 }
00215
00216
00217
00218
00219
00220
00221
00222
00223 void
00224 SwitchInterface::set_short_activations(const uint32_t new_short_activations)
00225 {
00226 data->short_activations = new_short_activations;
00227 data_changed = true;
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237 uint32_t
00238 SwitchInterface::long_activations() const
00239 {
00240 return data->long_activations;
00241 }
00242
00243
00244
00245
00246
00247 size_t
00248 SwitchInterface::maxlenof_long_activations() const
00249 {
00250 return 1;
00251 }
00252
00253
00254
00255
00256
00257
00258
00259
00260 void
00261 SwitchInterface::set_long_activations(const uint32_t new_long_activations)
00262 {
00263 data->long_activations = new_long_activations;
00264 data_changed = true;
00265 }
00266
00267
00268
00269
00270
00271
00272
00273
00274 uint32_t
00275 SwitchInterface::activation_count() const
00276 {
00277 return data->activation_count;
00278 }
00279
00280
00281
00282
00283
00284 size_t
00285 SwitchInterface::maxlenof_activation_count() const
00286 {
00287 return 1;
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297 void
00298 SwitchInterface::set_activation_count(const uint32_t new_activation_count)
00299 {
00300 data->activation_count = new_activation_count;
00301 data_changed = true;
00302 }
00303
00304
00305 Message *
00306 SwitchInterface::create_message(const char *type) const
00307 {
00308 if ( strncmp("SetMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00309 return new SetMessage();
00310 } else if ( strncmp("EnableSwitchMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00311 return new EnableSwitchMessage();
00312 } else if ( strncmp("DisableSwitchMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00313 return new DisableSwitchMessage();
00314 } else if ( strncmp("EnableDurationMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00315 return new EnableDurationMessage();
00316 } else {
00317 throw UnknownTypeException("The given type '%s' does not match any known "
00318 "message type for this interface type.", type);
00319 }
00320 }
00321
00322
00323
00324
00325
00326 void
00327 SwitchInterface::copy_values(const Interface *other)
00328 {
00329 const SwitchInterface *oi = dynamic_cast<const SwitchInterface *>(other);
00330 if (oi == NULL) {
00331 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00332 type(), other->type());
00333 }
00334 memcpy(data, oi->data, sizeof(SwitchInterface_data_t));
00335 }
00336
00337 const char *
00338 SwitchInterface::enum_tostring(const char *enumtype, int val) const
00339 {
00340 throw UnknownTypeException("Unknown enum type %s", enumtype);
00341 }
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355 SwitchInterface::SetMessage::SetMessage(const bool ini_enabled, const float ini_value) : Message("SetMessage")
00356 {
00357 data_size = sizeof(SetMessage_data_t);
00358 data_ptr = malloc(data_size);
00359 memset(data_ptr, 0, data_size);
00360 data = (SetMessage_data_t *)data_ptr;
00361 data_ts = (message_data_ts_t *)data_ptr;
00362 data->enabled = ini_enabled;
00363 data->value = ini_value;
00364 add_fieldinfo(IFT_BOOL, "enabled", 1, &data->enabled);
00365 add_fieldinfo(IFT_FLOAT, "value", 1, &data->value);
00366 }
00367
00368 SwitchInterface::SetMessage::SetMessage() : Message("SetMessage")
00369 {
00370 data_size = sizeof(SetMessage_data_t);
00371 data_ptr = malloc(data_size);
00372 memset(data_ptr, 0, data_size);
00373 data = (SetMessage_data_t *)data_ptr;
00374 data_ts = (message_data_ts_t *)data_ptr;
00375 add_fieldinfo(IFT_BOOL, "enabled", 1, &data->enabled);
00376 add_fieldinfo(IFT_FLOAT, "value", 1, &data->value);
00377 }
00378
00379
00380 SwitchInterface::SetMessage::~SetMessage()
00381 {
00382 free(data_ptr);
00383 }
00384
00385
00386
00387
00388 SwitchInterface::SetMessage::SetMessage(const SetMessage *m) : Message("SetMessage")
00389 {
00390 data_size = m->data_size;
00391 data_ptr = malloc(data_size);
00392 memcpy(data_ptr, m->data_ptr, data_size);
00393 data = (SetMessage_data_t *)data_ptr;
00394 data_ts = (message_data_ts_t *)data_ptr;
00395 }
00396
00397
00398
00399
00400
00401
00402
00403
00404 bool
00405 SwitchInterface::SetMessage::is_enabled() const
00406 {
00407 return data->enabled;
00408 }
00409
00410
00411
00412
00413
00414 size_t
00415 SwitchInterface::SetMessage::maxlenof_enabled() const
00416 {
00417 return 1;
00418 }
00419
00420
00421
00422
00423
00424
00425
00426 void
00427 SwitchInterface::SetMessage::set_enabled(const bool new_enabled)
00428 {
00429 data->enabled = new_enabled;
00430 }
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440 float
00441 SwitchInterface::SetMessage::value() const
00442 {
00443 return data->value;
00444 }
00445
00446
00447
00448
00449
00450 size_t
00451 SwitchInterface::SetMessage::maxlenof_value() const
00452 {
00453 return 1;
00454 }
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464 void
00465 SwitchInterface::SetMessage::set_value(const float new_value)
00466 {
00467 data->value = new_value;
00468 }
00469
00470
00471
00472
00473
00474
00475 Message *
00476 SwitchInterface::SetMessage::clone() const
00477 {
00478 return new SwitchInterface::SetMessage(this);
00479 }
00480
00481
00482
00483
00484
00485
00486
00487
00488 SwitchInterface::EnableSwitchMessage::EnableSwitchMessage() : Message("EnableSwitchMessage")
00489 {
00490 data_size = sizeof(EnableSwitchMessage_data_t);
00491 data_ptr = malloc(data_size);
00492 memset(data_ptr, 0, data_size);
00493 data = (EnableSwitchMessage_data_t *)data_ptr;
00494 data_ts = (message_data_ts_t *)data_ptr;
00495 }
00496
00497
00498 SwitchInterface::EnableSwitchMessage::~EnableSwitchMessage()
00499 {
00500 free(data_ptr);
00501 }
00502
00503
00504
00505
00506 SwitchInterface::EnableSwitchMessage::EnableSwitchMessage(const EnableSwitchMessage *m) : Message("EnableSwitchMessage")
00507 {
00508 data_size = m->data_size;
00509 data_ptr = malloc(data_size);
00510 memcpy(data_ptr, m->data_ptr, data_size);
00511 data = (EnableSwitchMessage_data_t *)data_ptr;
00512 data_ts = (message_data_ts_t *)data_ptr;
00513 }
00514
00515
00516
00517
00518
00519
00520
00521 Message *
00522 SwitchInterface::EnableSwitchMessage::clone() const
00523 {
00524 return new SwitchInterface::EnableSwitchMessage(this);
00525 }
00526
00527
00528
00529
00530
00531
00532
00533
00534 SwitchInterface::DisableSwitchMessage::DisableSwitchMessage() : Message("DisableSwitchMessage")
00535 {
00536 data_size = sizeof(DisableSwitchMessage_data_t);
00537 data_ptr = malloc(data_size);
00538 memset(data_ptr, 0, data_size);
00539 data = (DisableSwitchMessage_data_t *)data_ptr;
00540 data_ts = (message_data_ts_t *)data_ptr;
00541 }
00542
00543
00544 SwitchInterface::DisableSwitchMessage::~DisableSwitchMessage()
00545 {
00546 free(data_ptr);
00547 }
00548
00549
00550
00551
00552 SwitchInterface::DisableSwitchMessage::DisableSwitchMessage(const DisableSwitchMessage *m) : Message("DisableSwitchMessage")
00553 {
00554 data_size = m->data_size;
00555 data_ptr = malloc(data_size);
00556 memcpy(data_ptr, m->data_ptr, data_size);
00557 data = (DisableSwitchMessage_data_t *)data_ptr;
00558 data_ts = (message_data_ts_t *)data_ptr;
00559 }
00560
00561
00562
00563
00564
00565
00566
00567 Message *
00568 SwitchInterface::DisableSwitchMessage::clone() const
00569 {
00570 return new SwitchInterface::DisableSwitchMessage(this);
00571 }
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583 SwitchInterface::EnableDurationMessage::EnableDurationMessage(const float ini_duration, const float ini_value) : Message("EnableDurationMessage")
00584 {
00585 data_size = sizeof(EnableDurationMessage_data_t);
00586 data_ptr = malloc(data_size);
00587 memset(data_ptr, 0, data_size);
00588 data = (EnableDurationMessage_data_t *)data_ptr;
00589 data_ts = (message_data_ts_t *)data_ptr;
00590 data->duration = ini_duration;
00591 data->value = ini_value;
00592 add_fieldinfo(IFT_FLOAT, "duration", 1, &data->duration);
00593 add_fieldinfo(IFT_FLOAT, "value", 1, &data->value);
00594 }
00595
00596 SwitchInterface::EnableDurationMessage::EnableDurationMessage() : Message("EnableDurationMessage")
00597 {
00598 data_size = sizeof(EnableDurationMessage_data_t);
00599 data_ptr = malloc(data_size);
00600 memset(data_ptr, 0, data_size);
00601 data = (EnableDurationMessage_data_t *)data_ptr;
00602 data_ts = (message_data_ts_t *)data_ptr;
00603 add_fieldinfo(IFT_FLOAT, "duration", 1, &data->duration);
00604 add_fieldinfo(IFT_FLOAT, "value", 1, &data->value);
00605 }
00606
00607
00608 SwitchInterface::EnableDurationMessage::~EnableDurationMessage()
00609 {
00610 free(data_ptr);
00611 }
00612
00613
00614
00615
00616 SwitchInterface::EnableDurationMessage::EnableDurationMessage(const EnableDurationMessage *m) : Message("EnableDurationMessage")
00617 {
00618 data_size = m->data_size;
00619 data_ptr = malloc(data_size);
00620 memcpy(data_ptr, m->data_ptr, data_size);
00621 data = (EnableDurationMessage_data_t *)data_ptr;
00622 data_ts = (message_data_ts_t *)data_ptr;
00623 }
00624
00625
00626
00627
00628
00629
00630
00631 float
00632 SwitchInterface::EnableDurationMessage::duration() const
00633 {
00634 return data->duration;
00635 }
00636
00637
00638
00639
00640
00641 size_t
00642 SwitchInterface::EnableDurationMessage::maxlenof_duration() const
00643 {
00644 return 1;
00645 }
00646
00647
00648
00649
00650
00651
00652 void
00653 SwitchInterface::EnableDurationMessage::set_duration(const float new_duration)
00654 {
00655 data->duration = new_duration;
00656 }
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666 float
00667 SwitchInterface::EnableDurationMessage::value() const
00668 {
00669 return data->value;
00670 }
00671
00672
00673
00674
00675
00676 size_t
00677 SwitchInterface::EnableDurationMessage::maxlenof_value() const
00678 {
00679 return 1;
00680 }
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690 void
00691 SwitchInterface::EnableDurationMessage::set_value(const float new_value)
00692 {
00693 data->value = new_value;
00694 }
00695
00696
00697
00698
00699
00700
00701 Message *
00702 SwitchInterface::EnableDurationMessage::clone() const
00703 {
00704 return new SwitchInterface::EnableDurationMessage(this);
00705 }
00706
00707
00708
00709
00710 bool
00711 SwitchInterface::message_valid(const Message *message) const
00712 {
00713 const SetMessage *m0 = dynamic_cast<const SetMessage *>(message);
00714 if ( m0 != NULL ) {
00715 return true;
00716 }
00717 const EnableSwitchMessage *m1 = dynamic_cast<const EnableSwitchMessage *>(message);
00718 if ( m1 != NULL ) {
00719 return true;
00720 }
00721 const DisableSwitchMessage *m2 = dynamic_cast<const DisableSwitchMessage *>(message);
00722 if ( m2 != NULL ) {
00723 return true;
00724 }
00725 const EnableDurationMessage *m3 = dynamic_cast<const EnableDurationMessage *>(message);
00726 if ( m3 != NULL ) {
00727 return true;
00728 }
00729 return false;
00730 }
00731
00732
00733 EXPORT_INTERFACE(SwitchInterface)
00734
00735
00736
00737 }