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