Fawkes API
Fawkes Development Version
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
SoccerPenaltyInterface.cpp
1
2
/***************************************************************************
3
* SoccerPenaltyInterface.cpp - Fawkes BlackBoard Interface - SoccerPenaltyInterface
4
*
5
* Templated created: Thu Oct 12 10:49:19 2006
6
* Copyright 2008-2010 Tim Niemueller
7
*
8
****************************************************************************/
9
10
/* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version. A runtime exception applies to
14
* this software (see LICENSE.GPL_WRE file mentioned below for details).
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Library General Public License for more details.
20
*
21
* Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22
*/
23
24
#include <interfaces/SoccerPenaltyInterface.h>
25
26
#include <core/exceptions/software.h>
27
28
#include <cstring>
29
#include <cstdlib>
30
31
namespace
fawkes {
32
33
/** @class SoccerPenaltyInterface <interfaces/SoccerPenaltyInterface.h>
34
* SoccerPenaltyInterface Fawkes BlackBoard Interface.
35
*
36
This interface stores penalization information for soccer robots.
37
Currently it contains constants used in the RoboCup Standard Platform
38
League (SPL).
39
40
* @ingroup FawkesInterfaces
41
*/
42
43
44
/** SPL_PENALTY_NONE constant */
45
const
uint16_t
SoccerPenaltyInterface::SPL_PENALTY_NONE
= 0;
46
/** SPL_PENALTY_BALL_HOLDING constant */
47
const
uint16_t
SoccerPenaltyInterface::SPL_PENALTY_BALL_HOLDING
= 1;
48
/** SPL_PENALTY_PLAYER_PUSHING constant */
49
const
uint16_t
SoccerPenaltyInterface::SPL_PENALTY_PLAYER_PUSHING
= 2;
50
/** SPL_PENALTY_OBSTRUCTION constant */
51
const
uint16_t
SoccerPenaltyInterface::SPL_PENALTY_OBSTRUCTION
= 3;
52
/** SPL_PENALTY_INACTIVE_PLAYER constant */
53
const
uint16_t
SoccerPenaltyInterface::SPL_PENALTY_INACTIVE_PLAYER
= 4;
54
/** SPL_PENALTY_ILLEGAL_DEFENDER constant */
55
const
uint16_t
SoccerPenaltyInterface::SPL_PENALTY_ILLEGAL_DEFENDER
= 5;
56
/** SPL_PENALTY_LEAVING_THE_FIELD constant */
57
const
uint16_t
SoccerPenaltyInterface::SPL_PENALTY_LEAVING_THE_FIELD
= 6;
58
/** SPL_PENALTY_PLAYING_WITH_HANDS constant */
59
const
uint16_t
SoccerPenaltyInterface::SPL_PENALTY_PLAYING_WITH_HANDS
= 7;
60
/** SPL_PENALTY_REQ_FOR_PICKUP constant */
61
const
uint16_t
SoccerPenaltyInterface::SPL_PENALTY_REQ_FOR_PICKUP
= 8;
62
/** SPL_PENALTY_MANUAL constant */
63
const
uint16_t
SoccerPenaltyInterface::SPL_PENALTY_MANUAL
= 15;
64
65
/** Constructor */
66
SoccerPenaltyInterface::SoccerPenaltyInterface() : Interface()
67
{
68
data_size
=
sizeof
(SoccerPenaltyInterface_data_t);
69
data_ptr
= malloc(
data_size
);
70
data = (SoccerPenaltyInterface_data_t *)
data_ptr
;
71
data_ts
= (interface_data_ts_t *)
data_ptr
;
72
memset(
data_ptr
, 0,
data_size
);
73
add_fieldinfo
(
IFT_UINT16
,
"penalty"
, 1, &data->penalty);
74
add_fieldinfo
(
IFT_UINT16
,
"remaining"
, 1, &data->remaining);
75
add_messageinfo
(
"SetPenaltyMessage"
);
76
unsigned
char
tmp_hash[] = {0xa0, 0xa1, 0xf0, 0xc2, 0x4e, 0x8c, 0xd1, 0xe1, 0xaf, 0x46, 0x11, 0xe9, 0xa0, 0xc8, 0xaf, 0x5d};
77
set_hash
(tmp_hash);
78
}
79
80
/** Destructor */
81
SoccerPenaltyInterface::~SoccerPenaltyInterface()
82
{
83
free(
data_ptr
);
84
}
85
/* Methods */
86
/** Get penalty value.
87
* Current penalty code.
88
* @return penalty value
89
*/
90
uint16_t
91
SoccerPenaltyInterface::penalty
()
const
92
{
93
return
data->penalty;
94
}
95
96
/** Get maximum length of penalty value.
97
* @return length of penalty value, can be length of the array or number of
98
* maximum number of characters for a string
99
*/
100
size_t
101
SoccerPenaltyInterface::maxlenof_penalty
()
const
102
{
103
return
1;
104
}
105
106
/** Set penalty value.
107
* Current penalty code.
108
* @param new_penalty new penalty value
109
*/
110
void
111
SoccerPenaltyInterface::set_penalty
(
const
uint16_t new_penalty)
112
{
113
data->penalty = new_penalty;
114
data_changed
=
true
;
115
}
116
117
/** Get remaining value.
118
* Estimated time in seconds until the robot is unpenalized.
119
* @return remaining value
120
*/
121
uint16_t
122
SoccerPenaltyInterface::remaining
()
const
123
{
124
return
data->remaining;
125
}
126
127
/** Get maximum length of remaining value.
128
* @return length of remaining value, can be length of the array or number of
129
* maximum number of characters for a string
130
*/
131
size_t
132
SoccerPenaltyInterface::maxlenof_remaining
()
const
133
{
134
return
1;
135
}
136
137
/** Set remaining value.
138
* Estimated time in seconds until the robot is unpenalized.
139
* @param new_remaining new remaining value
140
*/
141
void
142
SoccerPenaltyInterface::set_remaining
(
const
uint16_t new_remaining)
143
{
144
data->remaining = new_remaining;
145
data_changed
=
true
;
146
}
147
148
/* =========== message create =========== */
149
Message
*
150
SoccerPenaltyInterface::create_message
(
const
char
*
type
)
const
151
{
152
if
( strncmp(
"SetPenaltyMessage"
, type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
153
return
new
SetPenaltyMessage
();
154
}
else
{
155
throw
UnknownTypeException
(
"The given type '%s' does not match any known "
156
"message type for this interface type."
, type);
157
}
158
}
159
160
161
/** Copy values from other interface.
162
* @param other other interface to copy values from
163
*/
164
void
165
SoccerPenaltyInterface::copy_values
(
const
Interface
*other)
166
{
167
const
SoccerPenaltyInterface
*oi =
dynamic_cast<
const
SoccerPenaltyInterface
*
>
(other);
168
if
(oi == NULL) {
169
throw
TypeMismatchException
(
"Can only copy values from interface of same type (%s vs. %s)"
,
170
type
(), other->
type
());
171
}
172
memcpy(data, oi->data,
sizeof
(SoccerPenaltyInterface_data_t));
173
}
174
175
const
char
*
176
SoccerPenaltyInterface::enum_tostring
(
const
char
*enumtype,
int
val)
const
177
{
178
throw
UnknownTypeException
(
"Unknown enum type %s"
, enumtype);
179
}
180
181
/* =========== messages =========== */
182
/** @class SoccerPenaltyInterface::SetPenaltyMessage <interfaces/SoccerPenaltyInterface.h>
183
* SetPenaltyMessage Fawkes BlackBoard Interface Message.
184
*
185
186
*/
187
188
189
/** Constructor with initial values.
190
* @param ini_penalty initial value for penalty
191
*/
192
SoccerPenaltyInterface::SetPenaltyMessage::SetPenaltyMessage
(
const
uint16_t ini_penalty) :
Message
(
"SetPenaltyMessage"
)
193
{
194
data_size
=
sizeof
(SetPenaltyMessage_data_t);
195
data_ptr
= malloc(
data_size
);
196
memset(
data_ptr
, 0,
data_size
);
197
data = (SetPenaltyMessage_data_t *)
data_ptr
;
198
data_ts
= (
message_data_ts_t
*)
data_ptr
;
199
data->penalty = ini_penalty;
200
add_fieldinfo
(
IFT_UINT16
,
"penalty"
, 1, &data->penalty);
201
}
202
/** Constructor */
203
SoccerPenaltyInterface::SetPenaltyMessage::SetPenaltyMessage
() :
Message
(
"SetPenaltyMessage"
)
204
{
205
data_size
=
sizeof
(SetPenaltyMessage_data_t);
206
data_ptr
= malloc(
data_size
);
207
memset(
data_ptr
, 0,
data_size
);
208
data = (SetPenaltyMessage_data_t *)
data_ptr
;
209
data_ts
= (
message_data_ts_t
*)
data_ptr
;
210
add_fieldinfo
(
IFT_UINT16
,
"penalty"
, 1, &data->penalty);
211
}
212
213
/** Destructor */
214
SoccerPenaltyInterface::SetPenaltyMessage::~SetPenaltyMessage
()
215
{
216
free(
data_ptr
);
217
}
218
219
/** Copy constructor.
220
* @param m message to copy from
221
*/
222
SoccerPenaltyInterface::SetPenaltyMessage::SetPenaltyMessage
(
const
SetPenaltyMessage
*m) :
Message
(
"SetPenaltyMessage"
)
223
{
224
data_size
= m->
data_size
;
225
data_ptr
= malloc(
data_size
);
226
memcpy(
data_ptr
, m->
data_ptr
,
data_size
);
227
data = (SetPenaltyMessage_data_t *)
data_ptr
;
228
data_ts
= (
message_data_ts_t
*)
data_ptr
;
229
}
230
231
/* Methods */
232
/** Get penalty value.
233
* Current penalty code.
234
* @return penalty value
235
*/
236
uint16_t
237
SoccerPenaltyInterface::SetPenaltyMessage::penalty
()
const
238
{
239
return
data->penalty;
240
}
241
242
/** Get maximum length of penalty value.
243
* @return length of penalty value, can be length of the array or number of
244
* maximum number of characters for a string
245
*/
246
size_t
247
SoccerPenaltyInterface::SetPenaltyMessage::maxlenof_penalty
()
const
248
{
249
return
1;
250
}
251
252
/** Set penalty value.
253
* Current penalty code.
254
* @param new_penalty new penalty value
255
*/
256
void
257
SoccerPenaltyInterface::SetPenaltyMessage::set_penalty
(
const
uint16_t new_penalty)
258
{
259
data->penalty = new_penalty;
260
}
261
262
/** Clone this message.
263
* Produces a message of the same type as this message and copies the
264
* data to the new message.
265
* @return clone of this message
266
*/
267
Message
*
268
SoccerPenaltyInterface::SetPenaltyMessage::clone
()
const
269
{
270
return
new
SoccerPenaltyInterface::SetPenaltyMessage
(
this
);
271
}
272
/** Check if message is valid and can be enqueued.
273
* @param message Message to check
274
* @return true if the message is valid, false otherwise.
275
*/
276
bool
277
SoccerPenaltyInterface::message_valid
(
const
Message
*message)
const
278
{
279
const
SetPenaltyMessage
*m0 =
dynamic_cast<
const
SetPenaltyMessage
*
>
(message);
280
if
( m0 != NULL ) {
281
return
true
;
282
}
283
return
false
;
284
}
285
286
/// @cond INTERNALS
287
EXPORT_INTERFACE(
SoccerPenaltyInterface
)
288
/// @endcond
289
290
291
}
// end namespace fawkes
src
libs
interfaces
SoccerPenaltyInterface.cpp
Generated by
1.8.1.1