26 #include "state_handler.h"
28 #include <core/exception.h>
29 #include <logging/logger.h>
30 #include <netcomm/socket/datagram.h>
33 # include <interfaces/SoccerPenaltyInterface.h>
47 static const uint32_t SPL_STRUCT_VERSION = 6;
49 static const uint32_t SPL_STRUCT_VERSION = 7;
52 static const uint8_t SPL_STATE_INITIAL = 0;
53 static const uint8_t SPL_STATE_READY = 1;
54 static const uint8_t SPL_STATE_SET = 2;
55 static const uint8_t SPL_STATE_PLAYING = 3;
56 static const uint8_t SPL_STATE_FINISHED = 4;
63 static const uint8_t SPL_PENALTY_NONE = 0;
65 static const uint8_t SPL_PENALTY_BALL_HOLDING = 1;
66 static const uint8_t SPL_PENALTY_GOALIE_PUSHING = 2;
67 static const uint8_t SPL_PENALTY_PLAYER_PUSHING = 3;
68 static const uint8_t SPL_PENALTY_ILLEGAL_DEFENDER = 4;
69 static const uint8_t SPL_PENALTY_ILLEGAL_DEFENSE = 5;
70 static const uint8_t SPL_PENALTY_OBSTRUCTION = 6;
71 static const uint8_t SPL_PENALTY_REQ_FOR_PICKUP = 7;
72 static const uint8_t SPL_PENALTY_LEAVING = 8;
73 static const uint8_t SPL_PENALTY_DAMAGE = 9;
74 static const uint8_t SPL_PENALTY_MANUAL = 10;
90 static const uint8_t SPL_TEAM_BLUE = 0;
91 static const uint8_t SPL_TEAM_RED = 1;
98 static const char SPL_GAMECONTROL_HEADER[SPL_HEADER_SIZE] = {
'R',
'G',
'm',
'e'};
114 unsigned short int broadcast_port,
115 unsigned int team_number,
116 unsigned int player_number)
118 player_number_ = player_number;
119 team_number_ = team_number;
123 s_->bind(broadcast_port);
125 penalty_ = SPL_PENALTY_NONE;
151 case SPL_TEAM_BLUE: our_team =
TEAM_CYAN;
break;
153 default: printf(
"Ignoring faulty packet\n");
return;
157 _rsh->set_team_goal(our_team,
161 for (
unsigned int pl_num = 0; pl_num < SPL_MAX_NUM_PLAYERS; ++pl_num) {
162 if ((pl_num + 1) == player_number_) {
170 case SPL_PENALTY_BALL_HOLDING:
173 case SPL_PENALTY_GOALIE_PUSHING:
174 case SPL_PENALTY_PLAYER_PUSHING:
177 case SPL_PENALTY_ILLEGAL_DEFENDER:
178 case SPL_PENALTY_ILLEGAL_DEFENSE:
181 case SPL_PENALTY_OBSTRUCTION:
184 case SPL_PENALTY_REQ_FOR_PICKUP:
187 case SPL_PENALTY_LEAVING:
190 case SPL_PENALTY_DAMAGE:
202 switch (msg->
state) {
220 size_t bytes_read = s_->recv((
void *)&ctrlmsg,
sizeof(ctrlmsg));
221 if (bytes_read ==
sizeof(ctrlmsg)) {
222 if ((strncmp(ctrlmsg.
header, SPL_GAMECONTROL_HEADER, SPL_HEADER_SIZE) == 0)
223 && (ctrlmsg.
version == SPL_STRUCT_VERSION)) {
224 process_struct(&ctrlmsg);
229 logger_->log_warn(
"SplRefBoxProcessor",
"Receiving failed, exception follows");
230 logger_->log_warn(
"SplRefBoxProcessor", e);
249 size_t bytes_read = s_->recv((
void *)&ctrlmsg,
sizeof(ctrlmsg));
250 if (bytes_read ==
sizeof(ctrlmsg)) {
251 if ((strncmp(ctrlmsg.header, SPL_GAMECONTROL_HEADER, SPL_HEADER_SIZE) == 0)
252 && (ctrlmsg.version == SPL_STRUCT_VERSION)) {
253 process_struct(&ctrlmsg);
254 _rsh->handle_refbox_state();
256 printf(
"Received illegal package\n");
~SplRefBoxProcessor()
Destructor.
bool check_connection()
Check if the connection is alive and reconnect.
void refbox_process()
Process incoming refbox communication.
SplRefBoxProcessor(fawkes::Logger *logger, unsigned short int broadcast_port, unsigned int team_number, unsigned int player_number)
Constructor.
Base class for exceptions in Fawkes.
int get_errno()
Get errno.
static const uint16_t SPL_PENALTY_BALL_HOLDING
SPL_PENALTY_BALL_HOLDING constant.
static const uint16_t SPL_PENALTY_NONE
SPL_PENALTY_NONE constant.
static const uint16_t SPL_PENALTY_PLAYER_PUSHING
SPL_PENALTY_PLAYER_PUSHING constant.
static const uint16_t SPL_PENALTY_MANUAL
SPL_PENALTY_MANUAL constant.
static const uint16_t SPL_PENALTY_LEAVING_THE_FIELD
SPL_PENALTY_LEAVING_THE_FIELD constant.
static const uint16_t SPL_PENALTY_ILLEGAL_DEFENDER
SPL_PENALTY_ILLEGAL_DEFENDER constant.
static const uint16_t SPL_PENALTY_REQ_FOR_PICKUP
SPL_PENALTY_REQ_FOR_PICKUP constant.
static const uint16_t SPL_PENALTY_OBSTRUCTION
SPL_PENALTY_OBSTRUCTION constant.
Fawkes library namespace.
@ GOAL_YELLOW
Yellow goal.
@ HALF_SECOND
Second half.
worldinfo_gamestate_team_t
Team.
@ TEAM_MAGENTA
Magenta team.
@ PENALTY_NONE
No penalty.
@ GS_SPL_SET
Wait for kick-off.
@ GS_SPL_FINISHED
Corner kick.
@ GS_SPL_INITIAL
Initial setup phase.
@ GS_SPL_READY
Move to kick-off positions.
SPL RefBox protocol game control struct.
uint8_t first_half
1 = game in first half, 0 otherwise
uint32_t version
version of the data structure
spl_teaminfo_t teams[2]
Info about the teams.
char header[SPL_HEADER_SIZE]
header to identify the structure
uint8_t state
state of the game (STATE_READY, STATE_PLAYING, etc.)
uint8_t kick_off_team
the next team to kick off
uint16_t secs_till_unpenalized
estimate of time till unpenalised
uint16_t penalty
penalty state of the player
uint8_t team_color
colour of the team
uint8_t score
team's score
spl_robotinfo_t players[SPL_MAX_NUM_PLAYERS]
the team's players
uint8_t team_number
unique team number