Fawkes API  Fawkes Development Version
spl.h
1 
2 /***************************************************************************
3  * spl.h - Fawkes SPL refbox repeater
4  *
5  * Created: Tue Jul 08 13:46:19 2008
6  * Copyright 2008-2010 Tim Niemueller [www.niemueller.de]
7  * 2009 Tobias Kellner
8  *
9  ****************************************************************************/
10 
11 /* This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
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 file in the doc directory.
22  */
23 
24 #ifndef _TOOLS_REFBOXREP_SPL_H_
25 #define _TOOLS_REFBOXREP_SPL_H_
26 
27 #include "enums.h"
28 #include "processor.h"
29 
30 #include <cstdlib>
31 #include <map>
32 #include <memory>
33 #include <stdint.h>
34 
35 namespace fawkes {
36 class Logger;
37 class DatagramSocket;
38 } // namespace fawkes
39 
40 #define SPL_HEADER_SIZE 4
41 #define SPL_MAX_NUM_PLAYERS 11
42 
43 #pragma pack(push, 4)
44 /** SPL RefBox protocol robot info struct. */
45 typedef struct
46 {
47  uint16_t penalty; /**< penalty state of the player */
48  uint16_t secs_till_unpenalized; /**< estimate of time till unpenalised */
50 
51 /** SPL RefBox protocol team info struct. */
52 typedef struct
53 {
54  uint8_t team_number; /**< unique team number */
55  uint8_t team_color; /**< colour of the team */
56 #ifdef USE_SPL_GC6
57  uint16_t score; /**< team's score */
58 #else
59  uint8_t goal_color; /**< colour of the goal */
60  uint8_t score; /**< team's score */
61 #endif
62  spl_robotinfo_t players[SPL_MAX_NUM_PLAYERS]; /**< the team's players */
64 
65 /** SPL RefBox protocol game control struct. */
66 typedef struct
67 {
68  char header[SPL_HEADER_SIZE]; /**< header to identify the structure */
69  uint32_t version; /**< version of the data structure */
70  uint8_t players_per_team; /**< The number of players on a team */
71  uint8_t state; /**< state of the game (STATE_READY, STATE_PLAYING, etc.) */
72  uint8_t first_half; /**< 1 = game in first half, 0 otherwise */
73  uint8_t kick_off_team; /**< the next team to kick off */
74  uint8_t
75  secondary_state; /**< Extra state information - (STATE2_NORMAL, STATE2_PENALTYSHOOT, etc) */
76  uint8_t drop_in_team; /**< team that caused last drop in */
77  uint16_t
78  drop_in_time; /**< number of seconds passed since the last drop in. -1 before first dropin */
79  uint32_t secs_remaining; /**< estimate of number of seconds remaining in the half */
80  spl_teaminfo_t teams[2]; /**< Info about the teams */
82 #pragma pack(pop)
83 
85 {
86 public:
88  unsigned short int broadcast_port,
89  unsigned int team_number,
90  unsigned int player_number);
92 
93  void run();
94 
95  bool check_connection();
96  void refbox_process();
97 
98 private:
99  void process_struct(spl_gamecontrol_t *msg);
100 
101 private:
102  std::shared_ptr<fawkes::DatagramSocket> s_;
103  fawkes::Logger * logger_;
104 
105  bool quit_;
106 
107  uint16_t penalty_;
108  uint8_t team_number_;
109  uint8_t player_number_;
110 };
111 
112 #endif
spl_teaminfo_t
SPL RefBox protocol team info struct.
Definition: spl.h:53
spl_teaminfo_t::goal_color
uint8_t goal_color
colour of the goal
Definition: spl.h:59
spl_gamecontrol_t::secs_remaining
uint32_t secs_remaining
estimate of number of seconds remaining in the half
Definition: spl.h:79
SplRefBoxProcessor::refbox_process
void refbox_process()
Process incoming refbox communication.
Definition: spl.cpp:216
spl_gamecontrol_t::version
uint32_t version
version of the data structure
Definition: spl.h:69
SplRefBoxProcessor
SPL league refbox repeater.
Definition: spl.h:85
spl_gamecontrol_t::secondary_state
uint8_t secondary_state
Extra state information - (STATE2_NORMAL, STATE2_PENALTYSHOOT, etc)
Definition: spl.h:75
SplRefBoxProcessor::SplRefBoxProcessor
SplRefBoxProcessor(fawkes::Logger *logger, unsigned short int broadcast_port, unsigned int team_number, unsigned int player_number)
Constructor.
Definition: spl.cpp:113
spl_gamecontrol_t::drop_in_time
uint16_t drop_in_time
number of seconds passed since the last drop in.
Definition: spl.h:78
spl_teaminfo_t::score
uint8_t score
team's score
Definition: spl.h:60
SplRefBoxProcessor::check_connection
bool check_connection()
Check if the connection is alive and reconnect.
Definition: spl.cpp:236
spl_gamecontrol_t::players_per_team
uint8_t players_per_team
The number of players on a team.
Definition: spl.h:70
fawkes::Logger
Interface for logging.
Definition: logger.h:42
fawkes
Fawkes library namespace.
RefBoxProcessor
Referee Box Communication Processor.
Definition: processor.h:29
spl_gamecontrol_t::state
uint8_t state
state of the game (STATE_READY, STATE_PLAYING, etc.)
Definition: spl.h:71
SplRefBoxProcessor::~SplRefBoxProcessor
~SplRefBoxProcessor()
Destructor.
Definition: spl.cpp:129
spl_gamecontrol_t::first_half
uint8_t first_half
1 = game in first half, 0 otherwise
Definition: spl.h:72
spl_gamecontrol_t
SPL RefBox protocol game control struct.
Definition: spl.h:67
spl_teaminfo_t::team_number
uint8_t team_number
unique team number
Definition: spl.h:54
spl_robotinfo_t
SPL RefBox protocol robot info struct.
Definition: spl.h:46
SplRefBoxProcessor::run
void run()
Run.
Definition: spl.cpp:245
spl_robotinfo_t::secs_till_unpenalized
uint16_t secs_till_unpenalized
estimate of time till unpenalised
Definition: spl.h:48
spl_robotinfo_t::penalty
uint16_t penalty
penalty state of the player
Definition: spl.h:47
spl_gamecontrol_t::drop_in_team
uint8_t drop_in_team
team that caused last drop in
Definition: spl.h:76
spl_gamecontrol_t::kick_off_team
uint8_t kick_off_team
the next team to kick off
Definition: spl.h:73
spl_teaminfo_t::team_color
uint8_t team_color
colour of the team
Definition: spl.h:55