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/KickerInterface.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 KickerInterface::KickerInterface() : Interface()
00046 {
00047 data_size = sizeof(KickerInterface_data_t);
00048 data_ptr = malloc(data_size);
00049 data = (KickerInterface_data_t *)data_ptr;
00050 data_ts = (interface_data_ts_t *)data_ptr;
00051 memset(data_ptr, 0, data_size);
00052 add_fieldinfo(IFT_INT32, "num_kicks_left", 1, &data->num_kicks_left);
00053 add_fieldinfo(IFT_INT32, "num_kicks_center", 1, &data->num_kicks_center);
00054 add_fieldinfo(IFT_INT32, "num_kicks_right", 1, &data->num_kicks_right);
00055 add_fieldinfo(IFT_ENUM, "guide_ball_side", 1, &data->guide_ball_side, "GuideBallSideEnum");
00056 add_fieldinfo(IFT_UINT32, "current_intensity", 1, &data->current_intensity);
00057 add_messageinfo("KickMessage");
00058 add_messageinfo("ResetCounterMessage");
00059 add_messageinfo("GuideBallMessage");
00060 unsigned char tmp_hash[] = {0x96, 0x3d, 0x55, 0x60, 0xfd, 0x65, 0xf2, 0xfa, 0xa8, 0xfa, 0xfc, 0xaa, 0xb6, 0xfc, 0xc2, 0x81};
00061 set_hash(tmp_hash);
00062 }
00063
00064
00065 KickerInterface::~KickerInterface()
00066 {
00067 free(data_ptr);
00068 }
00069
00070
00071
00072
00073 const char *
00074 KickerInterface::tostring_GuideBallSideEnum(GuideBallSideEnum value) const
00075 {
00076 switch (value) {
00077 case GUIDE_BALL_LEFT: return "GUIDE_BALL_LEFT";
00078 case GUIDE_BALL_RIGHT: return "GUIDE_BALL_RIGHT";
00079 default: return "UNKNOWN";
00080 }
00081 }
00082
00083
00084
00085
00086
00087
00088
00089 int32_t
00090 KickerInterface::num_kicks_left() const
00091 {
00092 return data->num_kicks_left;
00093 }
00094
00095
00096
00097
00098
00099 size_t
00100 KickerInterface::maxlenof_num_kicks_left() const
00101 {
00102 return 1;
00103 }
00104
00105
00106
00107
00108
00109
00110
00111 void
00112 KickerInterface::set_num_kicks_left(const int32_t new_num_kicks_left)
00113 {
00114 data->num_kicks_left = new_num_kicks_left;
00115 data_changed = true;
00116 }
00117
00118
00119
00120
00121
00122
00123
00124 int32_t
00125 KickerInterface::num_kicks_center() const
00126 {
00127 return data->num_kicks_center;
00128 }
00129
00130
00131
00132
00133
00134 size_t
00135 KickerInterface::maxlenof_num_kicks_center() const
00136 {
00137 return 1;
00138 }
00139
00140
00141
00142
00143
00144
00145
00146 void
00147 KickerInterface::set_num_kicks_center(const int32_t new_num_kicks_center)
00148 {
00149 data->num_kicks_center = new_num_kicks_center;
00150 data_changed = true;
00151 }
00152
00153
00154
00155
00156
00157
00158
00159 int32_t
00160 KickerInterface::num_kicks_right() const
00161 {
00162 return data->num_kicks_right;
00163 }
00164
00165
00166
00167
00168
00169 size_t
00170 KickerInterface::maxlenof_num_kicks_right() const
00171 {
00172 return 1;
00173 }
00174
00175
00176
00177
00178
00179
00180
00181 void
00182 KickerInterface::set_num_kicks_right(const int32_t new_num_kicks_right)
00183 {
00184 data->num_kicks_right = new_num_kicks_right;
00185 data_changed = true;
00186 }
00187
00188
00189
00190
00191
00192
00193 KickerInterface::GuideBallSideEnum
00194 KickerInterface::guide_ball_side() const
00195 {
00196 return data->guide_ball_side;
00197 }
00198
00199
00200
00201
00202
00203 size_t
00204 KickerInterface::maxlenof_guide_ball_side() const
00205 {
00206 return 1;
00207 }
00208
00209
00210
00211
00212
00213
00214 void
00215 KickerInterface::set_guide_ball_side(const GuideBallSideEnum new_guide_ball_side)
00216 {
00217 data->guide_ball_side = new_guide_ball_side;
00218 data_changed = true;
00219 }
00220
00221
00222
00223
00224
00225
00226
00227 uint32_t
00228 KickerInterface::current_intensity() const
00229 {
00230 return data->current_intensity;
00231 }
00232
00233
00234
00235
00236
00237 size_t
00238 KickerInterface::maxlenof_current_intensity() const
00239 {
00240 return 1;
00241 }
00242
00243
00244
00245
00246
00247
00248
00249 void
00250 KickerInterface::set_current_intensity(const uint32_t new_current_intensity)
00251 {
00252 data->current_intensity = new_current_intensity;
00253 data_changed = true;
00254 }
00255
00256
00257 Message *
00258 KickerInterface::create_message(const char *type) const
00259 {
00260 if ( strncmp("KickMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00261 return new KickMessage();
00262 } else if ( strncmp("ResetCounterMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00263 return new ResetCounterMessage();
00264 } else if ( strncmp("GuideBallMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00265 return new GuideBallMessage();
00266 } else {
00267 throw UnknownTypeException("The given type '%s' does not match any known "
00268 "message type for this interface type.", type);
00269 }
00270 }
00271
00272
00273
00274
00275
00276 void
00277 KickerInterface::copy_values(const Interface *other)
00278 {
00279 const KickerInterface *oi = dynamic_cast<const KickerInterface *>(other);
00280 if (oi == NULL) {
00281 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00282 type(), other->type());
00283 }
00284 memcpy(data, oi->data, sizeof(KickerInterface_data_t));
00285 }
00286
00287 const char *
00288 KickerInterface::enum_tostring(const char *enumtype, int val) const
00289 {
00290 if (strcmp(enumtype, "GuideBallSideEnum") == 0) {
00291 return tostring_GuideBallSideEnum((GuideBallSideEnum)val);
00292 }
00293 throw UnknownTypeException("Unknown enum type %s", enumtype);
00294 }
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 KickerInterface::KickMessage::KickMessage(const bool ini_left, const bool ini_center, const bool ini_right, const uint32_t ini_intensity) : Message("KickMessage")
00311 {
00312 data_size = sizeof(KickMessage_data_t);
00313 data_ptr = malloc(data_size);
00314 memset(data_ptr, 0, data_size);
00315 data = (KickMessage_data_t *)data_ptr;
00316 data_ts = (message_data_ts_t *)data_ptr;
00317 data->left = ini_left;
00318 data->center = ini_center;
00319 data->right = ini_right;
00320 data->intensity = ini_intensity;
00321 add_fieldinfo(IFT_BOOL, "left", 1, &data->left);
00322 add_fieldinfo(IFT_BOOL, "center", 1, &data->center);
00323 add_fieldinfo(IFT_BOOL, "right", 1, &data->right);
00324 add_fieldinfo(IFT_UINT32, "intensity", 1, &data->intensity);
00325 }
00326
00327 KickerInterface::KickMessage::KickMessage() : Message("KickMessage")
00328 {
00329 data_size = sizeof(KickMessage_data_t);
00330 data_ptr = malloc(data_size);
00331 memset(data_ptr, 0, data_size);
00332 data = (KickMessage_data_t *)data_ptr;
00333 data_ts = (message_data_ts_t *)data_ptr;
00334 add_fieldinfo(IFT_BOOL, "left", 1, &data->left);
00335 add_fieldinfo(IFT_BOOL, "center", 1, &data->center);
00336 add_fieldinfo(IFT_BOOL, "right", 1, &data->right);
00337 add_fieldinfo(IFT_UINT32, "intensity", 1, &data->intensity);
00338 }
00339
00340
00341 KickerInterface::KickMessage::~KickMessage()
00342 {
00343 free(data_ptr);
00344 }
00345
00346
00347
00348
00349 KickerInterface::KickMessage::KickMessage(const KickMessage *m) : Message("KickMessage")
00350 {
00351 data_size = m->data_size;
00352 data_ptr = malloc(data_size);
00353 memcpy(data_ptr, m->data_ptr, data_size);
00354 data = (KickMessage_data_t *)data_ptr;
00355 data_ts = (message_data_ts_t *)data_ptr;
00356 }
00357
00358
00359
00360
00361
00362
00363 bool
00364 KickerInterface::KickMessage::is_left() const
00365 {
00366 return data->left;
00367 }
00368
00369
00370
00371
00372
00373 size_t
00374 KickerInterface::KickMessage::maxlenof_left() const
00375 {
00376 return 1;
00377 }
00378
00379
00380
00381
00382
00383 void
00384 KickerInterface::KickMessage::set_left(const bool new_left)
00385 {
00386 data->left = new_left;
00387 }
00388
00389
00390
00391
00392
00393 bool
00394 KickerInterface::KickMessage::is_center() const
00395 {
00396 return data->center;
00397 }
00398
00399
00400
00401
00402
00403 size_t
00404 KickerInterface::KickMessage::maxlenof_center() const
00405 {
00406 return 1;
00407 }
00408
00409
00410
00411
00412
00413 void
00414 KickerInterface::KickMessage::set_center(const bool new_center)
00415 {
00416 data->center = new_center;
00417 }
00418
00419
00420
00421
00422
00423 bool
00424 KickerInterface::KickMessage::is_right() const
00425 {
00426 return data->right;
00427 }
00428
00429
00430
00431
00432
00433 size_t
00434 KickerInterface::KickMessage::maxlenof_right() const
00435 {
00436 return 1;
00437 }
00438
00439
00440
00441
00442
00443 void
00444 KickerInterface::KickMessage::set_right(const bool new_right)
00445 {
00446 data->right = new_right;
00447 }
00448
00449
00450
00451
00452
00453 uint32_t
00454 KickerInterface::KickMessage::intensity() const
00455 {
00456 return data->intensity;
00457 }
00458
00459
00460
00461
00462
00463 size_t
00464 KickerInterface::KickMessage::maxlenof_intensity() const
00465 {
00466 return 1;
00467 }
00468
00469
00470
00471
00472
00473 void
00474 KickerInterface::KickMessage::set_intensity(const uint32_t new_intensity)
00475 {
00476 data->intensity = new_intensity;
00477 }
00478
00479
00480
00481
00482
00483
00484 Message *
00485 KickerInterface::KickMessage::clone() const
00486 {
00487 return new KickerInterface::KickMessage(this);
00488 }
00489
00490
00491
00492
00493
00494
00495
00496
00497 KickerInterface::ResetCounterMessage::ResetCounterMessage() : Message("ResetCounterMessage")
00498 {
00499 data_size = sizeof(ResetCounterMessage_data_t);
00500 data_ptr = malloc(data_size);
00501 memset(data_ptr, 0, data_size);
00502 data = (ResetCounterMessage_data_t *)data_ptr;
00503 data_ts = (message_data_ts_t *)data_ptr;
00504 }
00505
00506
00507 KickerInterface::ResetCounterMessage::~ResetCounterMessage()
00508 {
00509 free(data_ptr);
00510 }
00511
00512
00513
00514
00515 KickerInterface::ResetCounterMessage::ResetCounterMessage(const ResetCounterMessage *m) : Message("ResetCounterMessage")
00516 {
00517 data_size = m->data_size;
00518 data_ptr = malloc(data_size);
00519 memcpy(data_ptr, m->data_ptr, data_size);
00520 data = (ResetCounterMessage_data_t *)data_ptr;
00521 data_ts = (message_data_ts_t *)data_ptr;
00522 }
00523
00524
00525
00526
00527
00528
00529
00530 Message *
00531 KickerInterface::ResetCounterMessage::clone() const
00532 {
00533 return new KickerInterface::ResetCounterMessage(this);
00534 }
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545 KickerInterface::GuideBallMessage::GuideBallMessage(const GuideBallSideEnum ini_guide_ball_side) : Message("GuideBallMessage")
00546 {
00547 data_size = sizeof(GuideBallMessage_data_t);
00548 data_ptr = malloc(data_size);
00549 memset(data_ptr, 0, data_size);
00550 data = (GuideBallMessage_data_t *)data_ptr;
00551 data_ts = (message_data_ts_t *)data_ptr;
00552 data->guide_ball_side = ini_guide_ball_side;
00553 add_fieldinfo(IFT_ENUM, "guide_ball_side", 1, &data->guide_ball_side, "GuideBallSideEnum");
00554 }
00555
00556 KickerInterface::GuideBallMessage::GuideBallMessage() : Message("GuideBallMessage")
00557 {
00558 data_size = sizeof(GuideBallMessage_data_t);
00559 data_ptr = malloc(data_size);
00560 memset(data_ptr, 0, data_size);
00561 data = (GuideBallMessage_data_t *)data_ptr;
00562 data_ts = (message_data_ts_t *)data_ptr;
00563 add_fieldinfo(IFT_ENUM, "guide_ball_side", 1, &data->guide_ball_side, "GuideBallSideEnum");
00564 }
00565
00566
00567 KickerInterface::GuideBallMessage::~GuideBallMessage()
00568 {
00569 free(data_ptr);
00570 }
00571
00572
00573
00574
00575 KickerInterface::GuideBallMessage::GuideBallMessage(const GuideBallMessage *m) : Message("GuideBallMessage")
00576 {
00577 data_size = m->data_size;
00578 data_ptr = malloc(data_size);
00579 memcpy(data_ptr, m->data_ptr, data_size);
00580 data = (GuideBallMessage_data_t *)data_ptr;
00581 data_ts = (message_data_ts_t *)data_ptr;
00582 }
00583
00584
00585
00586
00587
00588
00589 KickerInterface::GuideBallSideEnum
00590 KickerInterface::GuideBallMessage::guide_ball_side() const
00591 {
00592 return data->guide_ball_side;
00593 }
00594
00595
00596
00597
00598
00599 size_t
00600 KickerInterface::GuideBallMessage::maxlenof_guide_ball_side() const
00601 {
00602 return 1;
00603 }
00604
00605
00606
00607
00608
00609 void
00610 KickerInterface::GuideBallMessage::set_guide_ball_side(const GuideBallSideEnum new_guide_ball_side)
00611 {
00612 data->guide_ball_side = new_guide_ball_side;
00613 }
00614
00615
00616
00617
00618
00619
00620 Message *
00621 KickerInterface::GuideBallMessage::clone() const
00622 {
00623 return new KickerInterface::GuideBallMessage(this);
00624 }
00625
00626
00627
00628
00629 bool
00630 KickerInterface::message_valid(const Message *message) const
00631 {
00632 const KickMessage *m0 = dynamic_cast<const KickMessage *>(message);
00633 if ( m0 != NULL ) {
00634 return true;
00635 }
00636 const ResetCounterMessage *m1 = dynamic_cast<const ResetCounterMessage *>(message);
00637 if ( m1 != NULL ) {
00638 return true;
00639 }
00640 const GuideBallMessage *m2 = dynamic_cast<const GuideBallMessage *>(message);
00641 if ( m2 != NULL ) {
00642 return true;
00643 }
00644 return false;
00645 }
00646
00647
00648 EXPORT_INTERFACE(KickerInterface)
00649
00650
00651
00652 }