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;
56 static const uint8_t SPL_STATE2_NORMAL = 0;
57 static const uint8_t SPL_STATE2_PENALTYSHOOT = 1;
59 static const uint8_t SPL_PENALTY_NONE = 0;
61 static const uint8_t SPL_PENALTY_BALL_HOLDING = 1;
62 static const uint8_t SPL_PENALTY_GOALIE_PUSHING = 2;
63 static const uint8_t SPL_PENALTY_PLAYER_PUSHING = 3;
64 static const uint8_t SPL_PENALTY_ILLEGAL_DEFENDER = 4;
65 static const uint8_t SPL_PENALTY_ILLEGAL_DEFENSE = 5;
66 static const uint8_t SPL_PENALTY_OBSTRUCTION = 6;
67 static const uint8_t SPL_PENALTY_REQ_FOR_PICKUP = 7;
68 static const uint8_t SPL_PENALTY_LEAVING = 8;
69 static const uint8_t SPL_PENALTY_DAMAGE = 9;
70 static const uint8_t SPL_PENALTY_MANUAL = 10;
72 static const uint8_t SPL_PENALTY_BALL_HOLDING = 1;
73 static const uint8_t SPL_PENALTY_PLAYER_PUSHING = 2;
74 static const uint8_t SPL_PENALTY_OBSTRUCTION = 3;
75 static const uint8_t SPL_PENALTY_INACTIVE_PLAYER = 4;
76 static const uint8_t SPL_PENALTY_ILLEGAL_DEFENDER = 5;
77 static const uint8_t SPL_PENALTY_LEAVING_THE_FIELD = 6;
78 static const uint8_t SPL_PENALTY_PLAYING_WITH_HANDS = 7;
79 static const uint8_t SPL_PENALTY_REQ_FOR_PICKUP = 8;
80 static const uint8_t SPL_PENALTY_MANUAL = 15;
84 static const uint8_t SPL_TEAM_BLUE = 0;
85 static const uint8_t SPL_TEAM_RED = 1;
87 static const uint8_t SPL_GOAL_BLUE = 0;
88 static const uint8_t SPL_GOAL_YELLOW = 1;
90 static const char SPL_GAMECONTROL_HEADER[SPL_HEADER_SIZE] = {
'R',
'G',
'm',
'e'};
107 unsigned short int broadcast_port,
108 unsigned int team_number,
109 unsigned int player_number)
111 __player_number = player_number;
112 __team_number = team_number;
116 __s->bind(broadcast_port);
118 __penalty = SPL_PENALTY_NONE;
150 printf(
"Ignoring faulty packet\n");
157 for (
unsigned int pl_num = 0; pl_num < SPL_MAX_NUM_PLAYERS; ++pl_num)
159 if ((pl_num + 1) == __player_number)
169 case SPL_PENALTY_BALL_HOLDING:
171 case SPL_PENALTY_GOALIE_PUSHING:
172 case SPL_PENALTY_PLAYER_PUSHING:
174 case SPL_PENALTY_ILLEGAL_DEFENDER:
175 case SPL_PENALTY_ILLEGAL_DEFENSE:
177 case SPL_PENALTY_OBSTRUCTION:
179 case SPL_PENALTY_REQ_FOR_PICKUP:
181 case SPL_PENALTY_LEAVING:
183 case SPL_PENALTY_DAMAGE:
184 case SPL_PENALTY_MANUAL:
191 _rsh->add_penalty(__penalty,
198 switch (msg->
state) {
199 case SPL_STATE_INITIAL:
202 case SPL_STATE_READY:
208 case SPL_STATE_PLAYING:
211 case SPL_STATE_FINISHED:
229 size_t bytes_read = __s->recv((
void *)&ctrlmsg,
sizeof(ctrlmsg));
230 if ( bytes_read ==
sizeof(ctrlmsg) ) {
231 if ((strncmp(ctrlmsg.
header, SPL_GAMECONTROL_HEADER, SPL_HEADER_SIZE) == 0) &&
232 (ctrlmsg.
version == SPL_STRUCT_VERSION) ) {
233 process_struct(&ctrlmsg);
238 __logger->log_warn(
"SplRefBoxProcessor",
"Receiving failed, exception follows");
239 __logger->log_warn(
"SplRefBoxProcessor", e);
259 size_t bytes_read = __s->recv((
void *)&ctrlmsg,
sizeof(ctrlmsg));
260 if ( bytes_read ==
sizeof(ctrlmsg) ) {
261 if ( (strncmp(ctrlmsg.
header, SPL_GAMECONTROL_HEADER, SPL_HEADER_SIZE) == 0) &&
262 (ctrlmsg.
version == SPL_STRUCT_VERSION) ) {
263 process_struct(&ctrlmsg);
264 _rsh->handle_refbox_state();
266 printf(
"Received illegal package\n");
char header[SPL_HEADER_SIZE]
header to identify the structure
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.
spl_teaminfo_t teams[2]
Info about the teams.
Fawkes library namespace.
uint32_t version
version of the data structure
static const uint16_t SPL_PENALTY_NONE
SPL_PENALTY_NONE constant.
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.
spl_robotinfo_t players[SPL_MAX_NUM_PLAYERS]
the team's players
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