24 #include <netcomm/socket/datagram.h>
32 static const uint32_t SPL_STRUCT_VERSION = 6;
34 static const uint8_t SPL_STATE_INITIAL = 0;
35 static const uint8_t SPL_STATE_READY = 1;
36 static const uint8_t SPL_STATE_SET = 2;
37 static const uint8_t SPL_STATE_PLAYING = 3;
38 static const uint8_t SPL_STATE_FINISHED = 4;
40 static const uint8_t SPL_STATE2_NORMAL = 0;
41 static const uint8_t SPL_STATE2_PENALTYSHOOT = 1;
43 static const uint8_t SPL_PENALTY_NONE = 0;
44 static const uint8_t SPL_PENALTY_BALL_HOLDING = 1;
45 static const uint8_t SPL_PENALTY_GOALIE_PUSHING = 2;
46 static const uint8_t SPL_PENALTY_PLAYER_PUSHING = 3;
47 static const uint8_t SPL_PENALTY_ILLEGAL_DEFENDER = 4;
48 static const uint8_t SPL_PENALTY_ILLEGAL_DEFENSE = 5;
49 static const uint8_t SPL_PENALTY_OBSTRUCTION = 6;
50 static const uint8_t SPL_PENALTY_REQ_FOR_PICKUP = 7;
51 static const uint8_t SPL_PENALTY_LEAVING = 8;
52 static const uint8_t SPL_PENALTY_DAMAGE = 9;
53 static const uint8_t SPL_PENALTY_MANUAL = 10;
56 static const uint8_t SPL_TEAM_BLUE = 0;
57 static const uint8_t SPL_TEAM_RED = 1;
59 static const char SPL_GAMECONTROL_HEADER[GCHS] = {
'R',
'G',
'm',
'e'};
77 const char *broadcast_ip,
78 unsigned short int broadcast_port,
84 __our_team = our_team;
85 __our_goal = our_goal;
87 __s->
bind(broadcast_port);
89 for (
unsigned int i = 0; i < MAX_NUM_PLAYERS; ++i) {
90 __penalties[i] = SPL_PENALTY_NONE;
107 switch (msg->
state) {
108 case SPL_STATE_INITIAL:
111 case SPL_STATE_READY:
113 (msg->
kick_off_team == SPL_TEAM_BLUE) ? TEAM_CYAN : TEAM_MAGENTA);
117 (msg->
kick_off_team == SPL_TEAM_BLUE) ? TEAM_CYAN : TEAM_MAGENTA);
119 case SPL_STATE_PLAYING:
121 (msg->
kick_off_team == SPL_TEAM_BLUE) ? TEAM_CYAN : TEAM_MAGENTA);
123 case SPL_STATE_FINISHED:
139 for (
unsigned int i = 0; i < MAX_NUM_PLAYERS; ++i) {
159 size_t bytes_read = __s->
recv((
void *)&ctrlmsg,
sizeof(ctrlmsg));
160 if ( bytes_read ==
sizeof(ctrlmsg) ) {
161 if ( (strncmp(ctrlmsg.
header, SPL_GAMECONTROL_HEADER, GCHS) == 0) &&
162 (ctrlmsg.
version == SPL_STRUCT_VERSION) ) {
163 process_struct(&ctrlmsg);
165 printf(
"Received illegal package\n");
char header[SPL_HEADER_SIZE]
header to identify the structure
virtual void close()
Close socket.
uint8_t first_half
1 = game in first half, 0 otherwise
spl_teaminfo_t teams[2]
Info about the teams.
RefBox repeater state sender.
Fawkes library namespace.
virtual size_t recv(void *buf, size_t buf_len)
Read from socket.
uint32_t version
version of the data structure
virtual void set_gamestate(int game_state, fawkes::worldinfo_gamestate_team_t state_team)
Set current game state.
SplRefBoxRepeater(RefBoxStateSender &rss, const char *broadcast_ip, unsigned short int broadcast_port, fawkes::worldinfo_gamestate_team_t our_team, fawkes::worldinfo_gamestate_goalcolor_t our_goal)
Constructor.
~SplRefBoxRepeater()
Destructor.
virtual void add_penalty(unsigned int player, unsigned int penalty, unsigned int seconds_remaining)
Add penalty.
uint8_t score
team's score
SPL RefBox protocol game control struct.
virtual void bind(const unsigned short int port)
Bind socket.
uint8_t state
state of the game (STATE_READY, STATE_PLAYING, etc.)
uint16_t penalty
penalty state of the player
worldinfo_gamestate_team_t
Team.
virtual void send()
Send worldinfo.
virtual void set_half(fawkes::worldinfo_gamestate_half_t half)
Set current half of the game time.
uint8_t kick_off_team
the next team to kick off
spl_robotinfo_t players[SPL_MAX_NUM_PLAYERS]
the team's players
virtual void set_score(unsigned int score_cyan, unsigned int score_magenta)
Set score.
worldinfo_gamestate_goalcolor_t
Goal color.
uint16_t secs_till_unpenalized
estimate of time till unpenalised
uint8_t team_color
colour of the team