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/SoccerPenaltyInterface.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 uint16_t SoccerPenaltyInterface::SPL_PENALTY_NONE = 0;
00046
00047 const uint16_t SoccerPenaltyInterface::SPL_PENALTY_BALL_HOLDING = 1;
00048
00049 const uint16_t SoccerPenaltyInterface::SPL_PENALTY_PLAYER_PUSHING = 2;
00050
00051 const uint16_t SoccerPenaltyInterface::SPL_PENALTY_OBSTRUCTION = 3;
00052
00053 const uint16_t SoccerPenaltyInterface::SPL_PENALTY_INACTIVE_PLAYER = 4;
00054
00055 const uint16_t SoccerPenaltyInterface::SPL_PENALTY_ILLEGAL_DEFENDER = 5;
00056
00057 const uint16_t SoccerPenaltyInterface::SPL_PENALTY_LEAVING_THE_FIELD = 6;
00058
00059 const uint16_t SoccerPenaltyInterface::SPL_PENALTY_PLAYING_WITH_HANDS = 7;
00060
00061 const uint16_t SoccerPenaltyInterface::SPL_PENALTY_REQ_FOR_PICKUP = 8;
00062
00063 const uint16_t SoccerPenaltyInterface::SPL_PENALTY_MANUAL = 15;
00064
00065
00066 SoccerPenaltyInterface::SoccerPenaltyInterface() : Interface()
00067 {
00068 data_size = sizeof(SoccerPenaltyInterface_data_t);
00069 data_ptr = malloc(data_size);
00070 data = (SoccerPenaltyInterface_data_t *)data_ptr;
00071 data_ts = (interface_data_ts_t *)data_ptr;
00072 memset(data_ptr, 0, data_size);
00073 add_fieldinfo(IFT_UINT16, "penalty", 1, &data->penalty);
00074 add_fieldinfo(IFT_UINT16, "remaining", 1, &data->remaining);
00075 add_messageinfo("SetPenaltyMessage");
00076 unsigned char tmp_hash[] = {0xa0, 0xa1, 0xf0, 0xc2, 0x4e, 0x8c, 0xd1, 0xe1, 0xaf, 0x46, 0x11, 0xe9, 0xa0, 0xc8, 0xaf, 0x5d};
00077 set_hash(tmp_hash);
00078 }
00079
00080
00081 SoccerPenaltyInterface::~SoccerPenaltyInterface()
00082 {
00083 free(data_ptr);
00084 }
00085
00086
00087
00088
00089
00090 uint16_t
00091 SoccerPenaltyInterface::penalty() const
00092 {
00093 return data->penalty;
00094 }
00095
00096
00097
00098
00099
00100 size_t
00101 SoccerPenaltyInterface::maxlenof_penalty() const
00102 {
00103 return 1;
00104 }
00105
00106
00107
00108
00109
00110 void
00111 SoccerPenaltyInterface::set_penalty(const uint16_t new_penalty)
00112 {
00113 data->penalty = new_penalty;
00114 data_changed = true;
00115 }
00116
00117
00118
00119
00120
00121 uint16_t
00122 SoccerPenaltyInterface::remaining() const
00123 {
00124 return data->remaining;
00125 }
00126
00127
00128
00129
00130
00131 size_t
00132 SoccerPenaltyInterface::maxlenof_remaining() const
00133 {
00134 return 1;
00135 }
00136
00137
00138
00139
00140
00141 void
00142 SoccerPenaltyInterface::set_remaining(const uint16_t new_remaining)
00143 {
00144 data->remaining = new_remaining;
00145 data_changed = true;
00146 }
00147
00148
00149 Message *
00150 SoccerPenaltyInterface::create_message(const char *type) const
00151 {
00152 if ( strncmp("SetPenaltyMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00153 return new SetPenaltyMessage();
00154 } else {
00155 throw UnknownTypeException("The given type '%s' does not match any known "
00156 "message type for this interface type.", type);
00157 }
00158 }
00159
00160
00161
00162
00163
00164 void
00165 SoccerPenaltyInterface::copy_values(const Interface *other)
00166 {
00167 const SoccerPenaltyInterface *oi = dynamic_cast<const SoccerPenaltyInterface *>(other);
00168 if (oi == NULL) {
00169 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00170 type(), other->type());
00171 }
00172 memcpy(data, oi->data, sizeof(SoccerPenaltyInterface_data_t));
00173 }
00174
00175 const char *
00176 SoccerPenaltyInterface::enum_tostring(const char *enumtype, int val) const
00177 {
00178 throw UnknownTypeException("Unknown enum type %s", enumtype);
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 SoccerPenaltyInterface::SetPenaltyMessage::SetPenaltyMessage(const uint16_t ini_penalty) : Message("SetPenaltyMessage")
00193 {
00194 data_size = sizeof(SetPenaltyMessage_data_t);
00195 data_ptr = malloc(data_size);
00196 memset(data_ptr, 0, data_size);
00197 data = (SetPenaltyMessage_data_t *)data_ptr;
00198 data_ts = (message_data_ts_t *)data_ptr;
00199 data->penalty = ini_penalty;
00200 add_fieldinfo(IFT_UINT16, "penalty", 1, &data->penalty);
00201 }
00202
00203 SoccerPenaltyInterface::SetPenaltyMessage::SetPenaltyMessage() : Message("SetPenaltyMessage")
00204 {
00205 data_size = sizeof(SetPenaltyMessage_data_t);
00206 data_ptr = malloc(data_size);
00207 memset(data_ptr, 0, data_size);
00208 data = (SetPenaltyMessage_data_t *)data_ptr;
00209 data_ts = (message_data_ts_t *)data_ptr;
00210 add_fieldinfo(IFT_UINT16, "penalty", 1, &data->penalty);
00211 }
00212
00213
00214 SoccerPenaltyInterface::SetPenaltyMessage::~SetPenaltyMessage()
00215 {
00216 free(data_ptr);
00217 }
00218
00219
00220
00221
00222 SoccerPenaltyInterface::SetPenaltyMessage::SetPenaltyMessage(const SetPenaltyMessage *m) : Message("SetPenaltyMessage")
00223 {
00224 data_size = m->data_size;
00225 data_ptr = malloc(data_size);
00226 memcpy(data_ptr, m->data_ptr, data_size);
00227 data = (SetPenaltyMessage_data_t *)data_ptr;
00228 data_ts = (message_data_ts_t *)data_ptr;
00229 }
00230
00231
00232
00233
00234
00235
00236 uint16_t
00237 SoccerPenaltyInterface::SetPenaltyMessage::penalty() const
00238 {
00239 return data->penalty;
00240 }
00241
00242
00243
00244
00245
00246 size_t
00247 SoccerPenaltyInterface::SetPenaltyMessage::maxlenof_penalty() const
00248 {
00249 return 1;
00250 }
00251
00252
00253
00254
00255
00256 void
00257 SoccerPenaltyInterface::SetPenaltyMessage::set_penalty(const uint16_t new_penalty)
00258 {
00259 data->penalty = new_penalty;
00260 }
00261
00262
00263
00264
00265
00266
00267 Message *
00268 SoccerPenaltyInterface::SetPenaltyMessage::clone() const
00269 {
00270 return new SoccerPenaltyInterface::SetPenaltyMessage(this);
00271 }
00272
00273
00274
00275
00276 bool
00277 SoccerPenaltyInterface::message_valid(const Message *message) const
00278 {
00279 const SetPenaltyMessage *m0 = dynamic_cast<const SetPenaltyMessage *>(message);
00280 if ( m0 != NULL ) {
00281 return true;
00282 }
00283 return false;
00284 }
00285
00286
00287 EXPORT_INTERFACE(SoccerPenaltyInterface)
00288
00289
00290
00291 }