25 #include "state_handler.h" 26 #include <core/exception.h> 27 #include <netcomm/socket/datagram.h> 28 #include <logging/logger.h> 31 # include <interfaces/SoccerPenaltyInterface.h> 45 static const uint32_t SPL_STRUCT_VERSION = 6;
47 static const uint32_t SPL_STRUCT_VERSION = 7;
50 static const uint8_t SPL_STATE_INITIAL = 0;
51 static const uint8_t SPL_STATE_READY = 1;
52 static const uint8_t SPL_STATE_SET = 2;
53 static const uint8_t SPL_STATE_PLAYING = 3;
54 static const uint8_t SPL_STATE_FINISHED = 4;
61 static const uint8_t SPL_PENALTY_NONE = 0;
63 static const uint8_t SPL_PENALTY_BALL_HOLDING = 1;
64 static const uint8_t SPL_PENALTY_GOALIE_PUSHING = 2;
65 static const uint8_t SPL_PENALTY_PLAYER_PUSHING = 3;
66 static const uint8_t SPL_PENALTY_ILLEGAL_DEFENDER = 4;
67 static const uint8_t SPL_PENALTY_ILLEGAL_DEFENSE = 5;
68 static const uint8_t SPL_PENALTY_OBSTRUCTION = 6;
69 static const uint8_t SPL_PENALTY_REQ_FOR_PICKUP = 7;
70 static const uint8_t SPL_PENALTY_LEAVING = 8;
71 static const uint8_t SPL_PENALTY_DAMAGE = 9;
72 static const uint8_t SPL_PENALTY_MANUAL = 10;
88 static const uint8_t SPL_TEAM_BLUE = 0;
89 static const uint8_t SPL_TEAM_RED = 1;
96 static const char SPL_GAMECONTROL_HEADER[SPL_HEADER_SIZE] = {
'R',
'G',
'm',
'e'};
113 unsigned short int broadcast_port,
114 unsigned int team_number,
115 unsigned int player_number)
117 __player_number = player_number;
118 __team_number = team_number;
122 __s->bind(broadcast_port);
124 __penalty = SPL_PENALTY_NONE;
156 printf(
"Ignoring faulty packet\n");
163 for (
unsigned int pl_num = 0; pl_num < SPL_MAX_NUM_PLAYERS; ++pl_num)
165 if ((pl_num + 1) == __player_number)
175 case SPL_PENALTY_BALL_HOLDING:
177 case SPL_PENALTY_GOALIE_PUSHING:
178 case SPL_PENALTY_PLAYER_PUSHING:
180 case SPL_PENALTY_ILLEGAL_DEFENDER:
181 case SPL_PENALTY_ILLEGAL_DEFENSE:
183 case SPL_PENALTY_OBSTRUCTION:
185 case SPL_PENALTY_REQ_FOR_PICKUP:
187 case SPL_PENALTY_LEAVING:
189 case SPL_PENALTY_DAMAGE:
190 case SPL_PENALTY_MANUAL:
197 _rsh->add_penalty(__penalty,
204 switch (msg->
state) {
205 case SPL_STATE_INITIAL:
208 case SPL_STATE_READY:
214 case SPL_STATE_PLAYING:
217 case SPL_STATE_FINISHED:
235 size_t bytes_read = __s->recv((
void *)&ctrlmsg,
sizeof(ctrlmsg));
236 if ( bytes_read ==
sizeof(ctrlmsg) ) {
237 if ((strncmp(ctrlmsg.header, SPL_GAMECONTROL_HEADER, SPL_HEADER_SIZE) == 0) &&
238 (ctrlmsg.version == SPL_STRUCT_VERSION) ) {
239 process_struct(&ctrlmsg);
244 __logger->log_warn(
"SplRefBoxProcessor",
"Receiving failed, exception follows");
245 __logger->log_warn(
"SplRefBoxProcessor", e);
265 size_t bytes_read = __s->recv((
void *)&ctrlmsg,
sizeof(ctrlmsg));
266 if ( bytes_read ==
sizeof(ctrlmsg) ) {
267 if ( (strncmp(ctrlmsg.header, SPL_GAMECONTROL_HEADER, SPL_HEADER_SIZE) == 0) &&
268 (ctrlmsg.version == SPL_STRUCT_VERSION) ) {
269 process_struct(&ctrlmsg);
270 _rsh->handle_refbox_state();
272 printf(
"Received illegal package\n");
static const uint16_t SPL_PENALTY_ILLEGAL_DEFENDER
SPL_PENALTY_ILLEGAL_DEFENDER constant.
uint8_t first_half
1 = game in first half, 0 otherwise
int get_errno()
Get errno.
Fawkes library namespace.
static const uint16_t SPL_PENALTY_NONE
SPL_PENALTY_NONE constant.
spl_robotinfo_t players[SPL_MAX_NUM_PLAYERS]
the team's players
static const uint16_t SPL_PENALTY_LEAVING_THE_FIELD
SPL_PENALTY_LEAVING_THE_FIELD constant.
Base class for exceptions in Fawkes.
static const uint16_t SPL_PENALTY_REQ_FOR_PICKUP
SPL_PENALTY_REQ_FOR_PICKUP constant.
SplRefBoxProcessor(fawkes::Logger *logger, unsigned short int broadcast_port, unsigned int team_number, unsigned int player_number)
Constructor.
uint8_t score
team's score
static const uint16_t SPL_PENALTY_MANUAL
SPL_PENALTY_MANUAL constant.
SPL RefBox protocol game control struct.
uint8_t state
state of the game (STATE_READY, STATE_PLAYING, etc.)
static const uint16_t SPL_PENALTY_PLAYER_PUSHING
SPL_PENALTY_PLAYER_PUSHING constant.
uint8_t team_number
unique team number
uint16_t penalty
penalty state of the player
worldinfo_gamestate_team_t
Team.
~SplRefBoxProcessor()
Destructor.
uint8_t kick_off_team
the next team to kick off
static const uint16_t SPL_PENALTY_BALL_HOLDING
SPL_PENALTY_BALL_HOLDING constant.
Move to kick-off positions.
bool check_connection()
Check if the connection is alive and reconnect.
static const uint16_t SPL_PENALTY_OBSTRUCTION
SPL_PENALTY_OBSTRUCTION constant.
void refbox_process()
Process incoming refbox communication.
uint16_t secs_till_unpenalized
estimate of time till unpenalised
uint8_t team_color
colour of the team
spl_teaminfo_t teams[2]
Info about the teams.