forked from Animency/SPR2023-Engineer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
referee.c
201 lines (168 loc) · 5.67 KB
/
referee.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include "referee.h"
#include "string.h"
#include "stdio.h"
#include "CRC8_CRC16.h"
#include "protocol.h"
frame_header_struct_t referee_receive_header;
frame_header_struct_t referee_send_header;
ext_game_state_t game_state;
ext_game_result_t game_result;
ext_game_robot_HP_t game_robot_HP_t;
ext_event_data_t field_event;
ext_supply_projectile_action_t supply_projectile_action_t;
ext_supply_projectile_booking_t supply_projectile_booking_t;
ext_referee_warning_t referee_warning_t;
ext_game_robot_state_t robot_state;
ext_power_heat_data_t power_heat_data_t;
ext_game_robot_pos_t game_robot_pos_t;
ext_buff_musk_t buff_musk_t;
aerial_robot_energy_t robot_energy_t;
ext_robot_hurt_t robot_hurt_t;
ext_shoot_data_t shoot_data_t;
ext_bullet_remaining_t bullet_remaining_t;
ext_student_interactive_data_t student_interactive_data_t;
custom_robot_data_t custom_controller_data_t;
int test_id;
void init_referee_struct_data(void)
{
memset(&referee_receive_header, 0, sizeof(frame_header_struct_t));
memset(&referee_send_header, 0, sizeof(frame_header_struct_t));
memset(&game_state, 0, sizeof(ext_game_state_t));
memset(&game_result, 0, sizeof(ext_game_result_t));
memset(&game_robot_HP_t, 0, sizeof(ext_game_robot_HP_t));
memset(&field_event, 0, sizeof(ext_event_data_t));
memset(&supply_projectile_action_t, 0, sizeof(ext_supply_projectile_action_t));
memset(&supply_projectile_booking_t, 0, sizeof(ext_supply_projectile_booking_t));
memset(&referee_warning_t, 0, sizeof(ext_referee_warning_t));
memset(&robot_state, 0, sizeof(ext_game_robot_state_t));
memset(&power_heat_data_t, 0, sizeof(ext_power_heat_data_t));
memset(&game_robot_pos_t, 0, sizeof(ext_game_robot_pos_t));
memset(&buff_musk_t, 0, sizeof(ext_buff_musk_t));
memset(&robot_energy_t, 0, sizeof(aerial_robot_energy_t));
memset(&robot_hurt_t, 0, sizeof(ext_robot_hurt_t));
memset(&shoot_data_t, 0, sizeof(ext_shoot_data_t));
memset(&bullet_remaining_t, 0, sizeof(ext_bullet_remaining_t));
memset(&student_interactive_data_t, 0, sizeof(ext_student_interactive_data_t));
memset(&custom_controller_data_t, 0, sizeof(custom_controller_data_t));
}
void referee_data_solve(uint8_t *frame)
{
uint16_t cmd_id = 0;
uint8_t index = 0;
memcpy(&referee_receive_header, frame, sizeof(frame_header_struct_t));
index += sizeof(frame_header_struct_t);
memcpy(&cmd_id, frame + index, sizeof(uint16_t));
index += sizeof(uint16_t);
test_id = cmd_id;
switch (cmd_id)
{
case GAME_STATE_CMD_ID:
{
memcpy(&game_state, frame + index, sizeof(ext_game_state_t));
}
break;
case GAME_RESULT_CMD_ID:
{
memcpy(&game_result, frame + index, sizeof(game_result));
}
break;
case GAME_ROBOT_HP_CMD_ID:
{
memcpy(&game_robot_HP_t, frame + index, sizeof(ext_game_robot_HP_t));
}
break;
case FIELD_EVENTS_CMD_ID:
{
memcpy(&field_event, frame + index, sizeof(field_event));
}
break;
case SUPPLY_PROJECTILE_ACTION_CMD_ID:
{
memcpy(&supply_projectile_action_t, frame + index, sizeof(supply_projectile_action_t));
}
break;
case SUPPLY_PROJECTILE_BOOKING_CMD_ID:
{
memcpy(&supply_projectile_booking_t, frame + index, sizeof(supply_projectile_booking_t));
}
break;
case REFEREE_WARNING_CMD_ID:
{
memcpy(&referee_warning_t, frame + index, sizeof(ext_referee_warning_t));
}
break;
case ROBOT_STATE_CMD_ID:
{
memcpy(&robot_state, frame + index, sizeof(robot_state));
}
break;
case POWER_HEAT_DATA_CMD_ID:
{
memcpy(&power_heat_data_t, frame + index, sizeof(power_heat_data_t));
}
break;
case ROBOT_POS_CMD_ID:
{
memcpy(&game_robot_pos_t, frame + index, sizeof(game_robot_pos_t));
}
break;
case BUFF_MUSK_CMD_ID:
{
memcpy(&buff_musk_t, frame + index, sizeof(buff_musk_t));
}
break;
case AERIAL_ROBOT_ENERGY_CMD_ID:
{
memcpy(&robot_energy_t, frame + index, sizeof(robot_energy_t));
}
break;
case ROBOT_HURT_CMD_ID:
{
memcpy(&robot_hurt_t, frame + index, sizeof(robot_hurt_t));
}
break;
case SHOOT_DATA_CMD_ID:
{
memcpy(&shoot_data_t, frame + index, sizeof(shoot_data_t));
}
break;
case BULLET_REMAINING_CMD_ID:
{
memcpy(&bullet_remaining_t, frame + index, sizeof(ext_bullet_remaining_t));
}
break;
case STUDENT_INTERACTIVE_DATA_CMD_ID:
{
memcpy(&student_interactive_data_t, frame + index, sizeof(student_interactive_data_t));
}
break;
case CUSTOM_ROBOT_DATA_CMD_ID:
{
memcpy(&custom_controller_data_t, frame + index, sizeof(custom_robot_data_t));
}
break;
default:
{
break;
}
}
}
void get_chassis_power_and_buffer(float *power, float *buffer)
{
*power = power_heat_data_t.chassis_power;
*buffer = power_heat_data_t.chassis_power_buffer;
}
uint8_t get_robot_id(void)
{
return robot_state.robot_id;
}
void get_shoot_heat0_limit_and_heat0(uint16_t *heat0_limit, uint16_t *heat0)
{
*heat0_limit = robot_state.shooter_heat0_cooling_limit;
*heat0 = power_heat_data_t.shooter_heat0;
}
void get_shoot_heat1_limit_and_heat1(uint16_t *heat1_limit, uint16_t *heat1)
{
*heat1_limit = robot_state.shooter_heat1_cooling_limit;
*heat1 = power_heat_data_t.shooter_heat1;
}