/*
  裁判系统抽象。
*/

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ----------------------------------------------------------------- */
#include <cmsis_os2.h>
#include <stdbool.h>

#include "component\cmd.h"
#include "component\ui.h"
#include "component\user_math.h"
#include "device\can.h"
#include "device\device.h"

/* Exported constants ------------------------------------------------------- */
/* Exported macro ----------------------------------------------------------- */
#define REF_SWITCH_STATUS(ref, stat) ((ref).ref_status = (stat)) 
#define CHASSIS_POWER_MAX_WITHOUT_REF 2000.0f /* 裁判系统离线底盘最大功率 */

#define REF_UI_MAX_GRAPIC_NUM (7) /* 最大图形数量 */
#define REF_UI_MAX_STRING_NUM (7) /* 最大字符串数量 */
#define REF_UI_MAX_DEL_NUM (3) /* 最大删除数量 */

/* Exported types ----------------------------------------------------------- */
typedef struct __packed {
  uint8_t sof;
  uint16_t data_length;
  uint8_t seq;
  uint8_t crc8;
} Referee_Header_t;

typedef enum { REF_STATUS_OFFLINE = 0, REF_STATUS_RUNNING } Referee_Status_t;

typedef enum {
  REF_CMD_ID_GAME_STATUS             = 0x0001,           //比赛状态数据，固定以1Hz频率发送
  REF_CMD_ID_GAME_RESULT             = 0x0002,           //比赛结果数据，比赛结束触发发送
  REF_CMD_ID_GAME_ROBOT_HP           = 0x0003,           //机器人血量数据，固定以3Hz频率发送
  //REF_CMD_ID_DART_STATUS           = 0x0004,           
  // REF_CMD_ID_ICRA_ZONE_STATUS     = 0x0005,           
  REF_CMD_ID_FIELD_EVENTS            = 0x0101,           //场地事件数据，固定以1Hz频率发送
  //REF_CMD_ID_SUPPLY_ACTION         = 0x0102,
  //REF_CMD_ID_REQUEST_SUPPLY        = 0x0103,
  REF_CMD_ID_WARNING                 = 0x0104,           //裁判警告数据
  REF_CMD_ID_DART_COUNTDOWN          = 0x0105,           //飞镖发射相关数据
  REF_CMD_ID_ROBOT_STATUS            = 0x0201,           //机器人性能体系数据
  REF_CMD_ID_POWER_HEAT_DATA         = 0x0202,           //实时底盘缓冲能量和射击热量数据
  REF_CMD_ID_ROBOT_POS               = 0x0203,           //机器人位置数据
  REF_CMD_ID_ROBOT_BUFF              = 0x0204,           //机器人增益和底盘能量数据
  //REF_CMD_ID_DRONE_ENERGY          = 0x0205,
  REF_CMD_ID_ROBOT_DMG               = 0x0206,           //伤害状态数据
  REF_CMD_ID_SHOOT_DATA              = 0x0207,           //实时射击数据
  REF_CMD_ID_BULLET_REMAINING        = 0x0208,           //允许发弹量
  REF_CMD_ID_RFID                    = 0x0209,           //机器人RFID模块状态
  REF_CMD_ID_DART_CLIENT             = 0x020A,           //飞镖选手端指令数据
  REF_CMD_ID_ROBOT_POS_TO_SENTRY     = 0X020B,           //地面机器人位置数据
  REF_CMD_ID_RADAR_MARK              = 0X020C,           //雷达标记进度数据
  REF_CMD_ID_SENTRY_DECISION         = 0x020D,           //哨兵自主决策相关信息同步
  REF_CMD_ID_RADAR_DECISION          = 0x020E,           //雷达自主决策相关信息同步
  REF_CMD_ID_INTER_STUDENT           = 0x0301,           //机器人交互数据
  REF_CMD_ID_INTER_STUDENT_CUSTOM    = 0x0302,           //自定义控制器与机器人交互数据
  REF_CMD_ID_CLIENT_MAP              = 0x0303,           //选手端小地图交互数据
  REF_CMD_ID_KEYBOARD_MOUSE          = 0x0304,           //键鼠遥控数据
  REF_CMD_ID_MAP_ROBOT_DATA          = 0x0305,           //选手端小地图接收雷达数据
  REF_CMD_ID_CUSTOM_KEYBOARD_MOUSE   = 0X0306,           //自定义控制器与选手端交互数据
  REF_CMD_ID_SENTRY_POS_DATA         = 0x0307,           //选手端小地图接收哨兵数据
  REF_CMD_ID_ROBOT_POS_DATA          = 0x0308,           //选手端小地图接受机器人消息 
  REF_CMD_ID_DATA                    = 0x0309,            //自定义控制器接收机器人数据 
} Referee_CMDID_t;

typedef struct __packed {
  uint8_t game_type : 4;
  uint8_t game_progress : 4;
  uint16_t stage_remain_time;
  uint64_t sync_time_stamp;
} Referee_GameStatus_t;/* 0x0001 */

typedef struct __packed {
  uint8_t winner;
} Referee_GameResult_t;/* 0x0002 */

typedef struct __packed {
  uint16_t red_1;
  uint16_t red_2;
  uint16_t red_3;
  uint16_t red_4;
  uint16_t reserved; 
  uint16_t red_7;
  uint16_t red_outpose;
  uint16_t red_base;
  uint16_t blue_1;
  uint16_t blue_2;
  uint16_t blue_3;
  uint16_t blue_4;
  uint16_t reserved1;
  uint16_t blue_7;
  uint16_t blue_outpose;
  uint16_t blue_base;
} Referee_GameRobotHP_t;/* 0x0003 */

typedef struct __packed {
  uint8_t dart_belong;
  uint16_t stage_remain_time;
} Referee_DartStatus_t;

typedef struct __packed {
  uint8_t f1_status : 1;
  uint8_t f1_buff_status : 3;
  uint8_t f2_status : 1;
  uint8_t f2_buff_status : 3;
  uint8_t f3_status : 1;
  uint8_t f3_buff_status : 3;
  uint8_t f4_status : 1;
  uint8_t f4_buff_status : 3;
  uint8_t f5_status : 1;
  uint8_t f5_buff_status : 3;
  uint8_t f6_status : 1;
  uint8_t f6_buff_status : 3;
  uint16_t red1_bullet_remain;
  uint16_t red2_bullet_remain;
  uint16_t blue1_bullet_remain;
  uint16_t blue2_bullet_remain;
} Referee_ICRAZoneStatus_t;

typedef struct __packed {
  uint32_t exchange_nooverlap_status : 1;
  uint32_t exchange_overlap_status : 1;
  uint32_t supply_status : 1;
  uint32_t energy_mech_small_status : 1;
  uint32_t energy_mech_big_status : 1;
  uint32_t highland_annular : 2;
  uint32_t highland_trapezium_1 : 2;
  uint32_t last_hit_time : 9;
  uint32_t last_hit_target : 3;
  uint32_t activation_status : 2;
  uint32_t res : 9;
} Referee_FieldEvents_t;/* 0x0101 */

typedef struct __packed {
  uint8_t supply_id;
  uint8_t robot_id;
  uint8_t supply_step;
  uint8_t supply_sum;
} Referee_SupplyAction_t;/* 0x0102 */

typedef struct __packed {
  uint8_t place_holder; /* TODO */
} Referee_RequestSupply_t;/* 0x0103 */

typedef struct __packed {
  uint8_t level;
  uint8_t robot_id;
  uint8_t count;
} Referee_Warning_t;/* 0x0104 */

typedef struct __packed {
  uint8_t countdown;
  uint16_t dart_last_target : 3;
  uint16_t attack_count : 2;
  uint16_t dart_target : 2;
  uint16_t res : 8;
} Referee_DartCountdown_t;/* 0x0105 */


typedef struct __packed {
  uint8_t robot_id;
  uint8_t robot_level;
  uint16_t remain_hp;
  uint16_t max_hp;
  uint16_t shooter_cooling_value;
  uint16_t shooter_heat_limit;
  uint16_t chassis_power_limit;
  uint8_t power_gimbal_output : 1;
  uint8_t power_chassis_output : 1;
  uint8_t power_shoot_output : 1;
} Referee_RobotStatus_t; /* 0x0201 */

typedef struct __packed {
  uint16_t chassis_volt;
  uint16_t chassis_amp;
  float chassis_watt;
  uint16_t chassis_pwr_buff;
  uint16_t shoot_id1_17_heat;
  uint16_t shoot_id2_17_heat;
  uint16_t shoot_42_heat;
} Referee_PowerHeat_t;   /* 0x0202 */

typedef struct __packed {
  float x;
  float y;
  float z;
  float yaw;
} Referee_RobotPos_t;    /* 0x0203 */


typedef struct __packed {
  uint8_t healing_buff;
  uint8_t cooling_acc;
  uint8_t defense_buff;
  uint8_t vulnerability_buff;
  uint16_t attack_buff;
  uint8_t remaining_energy;
} Referee_RobotBuff_t;    /* 0x0204 */

typedef struct __packed {
  uint8_t attack_countdown;
} Referee_DroneEnergy_t;  /* 0x0205 *///删

typedef struct __packed {
  uint8_t armor_id : 4;
  uint8_t damage_type : 4;
} Referee_RobotDamage_t;  /* 0x0206 */

typedef struct __packed {
  uint8_t bullet_type;
  uint8_t shooter_id;
  uint8_t bullet_freq;
  float bullet_speed;
} Referee_ShootData_t;/* 0x0207 */

typedef struct __packed {
  uint16_t bullet_17_remain;
  uint16_t bullet_42_remain;
  uint16_t coin_remain;
} Referee_BulletRemain_t;/* 0x0208 */

typedef struct __packed {
  uint32_t own_base : 1;                  //0
  uint32_t own_highland_annular : 1;      //1
  uint32_t enemy_highland_annular : 1;    //2
  uint32_t own_trapezium_R3B3 : 1;        //3
  uint32_t enemy_trapezium_R3B3 : 1;      //4
  uint32_t own_slope_before : 1;          //坡道前5
  uint32_t own_slope_after : 1;           //坡道后6
  uint32_t enemy_slope_before : 1;        //坡道前7
  uint32_t enemy_slope_after : 1;         //坡道后8
  uint32_t own_crosses_above : 1;         //增益点 上方9
  uint32_t own_crosses_below : 1;         //增益点 下方10
  uint32_t enemy_crosses_above : 1;       //增益点 上方11
  uint32_t enemy_crosses_below : 1;       //增益点 下方12
  uint32_t own_highway_above : 1;         //公路 上方13
  uint32_t own_highway_below : 1;         //公路 下方14
  uint32_t enemy_highway_above : 1;       //公路 上方15
  uint32_t enemy_highway_below : 1;       //公路 下方16
  uint32_t own_fortress : 1;              //己方堡垒增益点17
  uint32_t own_outpost : 1;               //己方前哨站增益点18
  uint32_t own_RMUL : 1;                  //己方RMUL增益点19
  uint32_t enemy_RMDL : 1;                //敌方RMDL增益点20
  uint32_t own_island : 1;                //己方资源岛 21
  uint32_t enemy_island : 1;              //敌方资源岛 22
  uint32_t centre : 1;                    //中心 23
  uint32_t res : 8;
} Referee_RFID_t;/* 0x0209 */

typedef struct __packed {
  uint8_t opening_status;
  uint8_t target;
  uint16_t target_changable_countdown;
  uint16_t operator_cmd_launch_time;
} Referee_DartClient_t;/* 0x020A */

typedef struct __packed {
  float hero_x;  
  float hero_y;  
  float engineer_x;  
  float engineer_y;  
  float standard_3_x;  
  float standard_3_y;  
  float standard_4_x;  
  float standard_4_y;  
  float reserved;  
  float reserved1; 
} Referee_Robot_Position_t;/* 0x020B */

typedef struct __packed
{ 
  uint8_t mark_hero_progress;  
  uint8_t mark_engineer_progress;  
  uint8_t mark_standard_3_progress;  
  uint8_t mark_standard_4_progress;  
  uint8_t mark_sentry_progress;   
}Referee_Radar_mark_data_t; /* 0x020C */

typedef struct __packed 
{  
  uint32_t exchanged_bullet_num : 11;
  uint32_t exchanged_bullet_times : 4;
  uint32_t exchanged_blood_times : 4;
  uint32_t Confirmation_resurrection : 1;
  uint32_t now_resurrection : 1;
  uint32_t money : 10;
  uint32_t res : 1; 
  uint16_t state : 1;
  uint16_t quantity : 11;
  uint16_t res1 : 4;
} Referee_Sentry_Info_t; /* 0x020D */

typedef struct __packed 
{  
  uint8_t qualification : 2;
  uint8_t enemy_status : 1;
  uint8_t res : 5;
} Referee_Radar_Info_t; /* 0x020E */

typedef struct __packed 
{  
  uint16_t data_cmd_id; /* 子内容ID */
  uint16_t sender_id;
  uint16_t receiver_id;
  uint8_t user_data[112]; 
} Referee_Interaction_Data_t; /* 0x0301 */

typedef struct __packed 
{  
  uint8_t data[30];  
} Referee_custom_robot_data_t; /* 0x0302 */

typedef struct __packed {
  float position_x;
  float position_y;
  uint8_t commd_keyboard;
  uint8_t robot_id;
  uint8_t cmd_source;
} Referee_ClientMap_t;/* 0x0303 */

typedef struct __packed {
  int16_t mouse_x;
  int16_t mouse_y;
  int16_t mouse_wheel;
  int8_t button_l;
  int8_t button_r;
  uint16_t keyboard_value;
  uint16_t res;
} Referee_KeyboardMouse_t;/* 0x0304 */

typedef struct __packed {
  uint16_t hero_position_x; 
  uint16_t hero_position_y; 
  uint16_t engineer_position_x; 
  uint16_t engineer_position_y; 
  uint16_t infantry_3_position_x; 
  uint16_t infantry_3_position_y; 
  uint16_t infantry_4_position_x; 
  uint16_t infantry_4_position_y; 
  uint16_t infantry_5_position_x; 
  uint16_t infantry_5_position_y; 
  uint16_t sentry_position_x; 
  uint16_t sentry_position_y; 
  } Referee_map_robot_data_t;/* 0x0305 */

  typedef struct __packed {
    uint16_t key_value;
    uint16_t x_position : 12;
    uint16_t mouse_left : 4;
    uint16_t y_position : 12;
    uint16_t mouse_right : 4;
    uint16_t res;
  } Referee_custom_client_data_t; /* 0x0306 */

  typedef struct __packed {
    uint8_t intention; 
    uint16_t start_position_x; 
    uint16_t start_position_y; 
    int8_t delta_x[49]; 
    int8_t delta_y[49]; 
    uint16_t sender_id; 
  } Referee_map_data_t;/* 0x0307 */

  typedef struct __packed 
  {  
  uint16_t sender_id; 
  uint16_t receiver_id; 
  uint8_t user_data[30]; 
  }Referee_custom_info_t; /* 0x0308 */

  typedef struct __packed 
{ 
uint8_t data[30]; 
}Referee_robot_custom_data_t; /* 0x0309*/

typedef uint16_t Referee_Tail_t;

// typedef enum {
//   REF_BOT_RED_HERO = 1,
//   REF_BOT_RED_ENGINEER = 2,
//   REF_BOT_RED_INFANTRY_1 = 3,
//   REF_BOT_RED_INFANTRY_2 = 4,
//   REF_BOT_RED_INFANTRY_3 = 5,
//   REF_BOT_RED_DRONE = 6,
//   REF_BOT_RED_SENTRY = 7,
//   REF_BOT_RED_RADER = 9,
//   REF_BOT_BLU_HERO = 101,
//   REF_BOT_BLU_ENGINEER = 102,
//   REF_BOT_BLU_INFANTRY_1 = 103,
//   REF_BOT_BLU_INFANTRY_2 = 104,
//   REF_BOT_BLU_INFANTRY_3 = 105,
//   REF_BOT_BLU_DRONE = 106,
//   REF_BOT_BLU_SENTRY = 107,
//   REF_BOT_BLU_RADER = 109,
// } Referee_RobotID_t;//

typedef enum {
  REF_BOT_RED_HERO = 1,
  REF_BOT_RED_ENGINEER = 2,
  REF_BOT_RED_INFANTRY_1 = 3,
  REF_BOT_RED_INFANTRY_2 = 4,
  REF_BOT_RED_INFANTRY_3 = 5,
  REF_BOT_RED_DRONE = 6,
  REF_BOT_RED_SENTRY = 7,
  REF_BOT_RED_DART = 8,
  REF_BOT_RED_RADER = 9,
  REF_BOT_RED_OUTPOST = 10,
  REF_BOT_RED_BASE = 11,
  REF_BOT_BLU_HERO = 101,
  REF_BOT_BLU_ENGINEER = 102,
  REF_BOT_BLU_INFANTRY_1 = 103,
  REF_BOT_BLU_INFANTRY_2 = 104,
  REF_BOT_BLU_INFANTRY_3 = 105,
  REF_BOT_BLU_DRONE = 106,
  REF_BOT_BLU_SENTRY = 107,
  REF_BOT_BLU_DART = 108,
  REF_BOT_BLU_RADER = 109,
  REF_BOT_BLU_OUTPOST = 110,
  REF_BOT_BLU_BASE = 111,
} Referee_RobotID_t;//


// typedef enum {
//   REF_CL_RED_HERO = 0x0101,
//   REF_CL_RED_ENGINEER = 0x0102,
//   REF_CL_RED_INFANTRY_1 = 0x0103,
//   REF_CL_RED_INFANTRY_2 = 0x0104,
//   REF_CL_RED_INFANTRY_3 = 0x0105,
//   REF_CL_RED_DRONE = 0x0106,
//   REF_CL_BLU_HERO = 0x0165,
//   REF_CL_BLU_ENGINEER = 0x0166,
//   REF_CL_BLU_INFANTRY_1 = 0x0167,
//   REF_CL_BLU_INFANTRY_2 = 0x0168,
//   REF_CL_BLU_INFANTRY_3 = 0x0169,
//   REF_CL_BLU_DRONE = 0x016A,
// } Referee_ClientID_t;//选手端ID
typedef enum {
  REF_CL_RED_HERO = 0x0101,
  REF_CL_RED_ENGINEER = 0x0102,
  REF_CL_RED_INFANTRY_1 = 0x0103,
  REF_CL_RED_INFANTRY_2 = 0x0104,
  REF_CL_RED_INFANTRY_3 = 0x0105,
  REF_CL_RED_DRONE = 0x0106,
  REF_CL_BLU_HERO = 0x0165,
  REF_CL_BLU_ENGINEER = 0x0166,
  REF_CL_BLU_INFANTRY_1 = 0x0167,
  REF_CL_BLU_INFANTRY_2 = 0x0168,
  REF_CL_BLU_INFANTRY_3 = 0x0169,
  REF_CL_BLU_DRONE = 0x016A,
  REF_CL_REFEREE_SERVER = 0x8080, /* 裁判系统服务器，用于哨兵和雷达自主决策 */
} Referee_ClientID_t;//选手端ID


// typedef enum {
//   REF_STDNT_CMD_ID_UI_DEL = 0x0100,
//   REF_STDNT_CMD_ID_UI_DRAW1 = 0x0101,
//   REF_STDNT_CMD_ID_UI_DRAW2 = 0x0102,
//   REF_STDNT_CMD_ID_UI_DRAW5 = 0x0103,
//   REF_STDNT_CMD_ID_UI_DRAW7 = 0x0104,
//   REF_STDNT_CMD_ID_UI_STR = 0x0110,

//   REF_STDNT_CMD_ID_CUSTOM = 0x0200,
// } Referee_StudentCMDID_t;
typedef enum {
  REF_STDNT_CMD_ID_UI_DEL = 0x0100,
  REF_STDNT_CMD_ID_UI_DRAW1 = 0x0101,
  REF_STDNT_CMD_ID_UI_DRAW2 = 0x0102,
  REF_STDNT_CMD_ID_UI_DRAW5 = 0x0103,
  REF_STDNT_CMD_ID_UI_DRAW7 = 0x0104,
  REF_STDNT_CMD_ID_UI_STR = 0x0110,
  REF_STDNT_CMD_ID_CUSTOM = 0x0200,
  REF_STDNT_CMD_ID_SENTRY_CMD = 0X0120,
  REF_STDNT_CMD_ID_RADAR_CMD = 0X0121,
} Referee_StudentCMDID_t;

typedef struct __packed {
  Referee_StudentCMDID_t data_cmd_id;
  uint16_t id_sender;
  uint16_t id_receiver;
  uint8_t *data;
} Referee_InterStudent_t;

typedef struct __packed {
  uint8_t place_holder;
} Referee_InterStudent_Custom_t;

typedef struct {
  Referee_Status_t ref_status;
  Referee_GameStatus_t game_status;                       /* 0x0001 */
  Referee_GameResult_t game_result;                       /* 0x0002 */
  Referee_GameRobotHP_t game_robot_hp;                    /* 0x0003 */
  // Referee_DartStatus_t dart_status;
  // Referee_ICRAZoneStatus_t icra_zone;
  Referee_FieldEvents_t field_event;                      /* 0x0101 */
  //Referee_SupplyAction_t supply_action;                 /* 0x0102 */
  Referee_RequestSupply_t request_supply;                 /* 0x0103 */
  Referee_Warning_t warning;                              /* 0x0104 */
  Referee_DartCountdown_t dart_countdown;                 /* 0x0105 */
  Referee_RobotStatus_t robot_status;                     /* 0x0201 */
  Referee_PowerHeat_t power_heat;                         /* 0x0202 */
  Referee_RobotPos_t robot_pos;                           /* 0x0203 */
  Referee_RobotBuff_t robot_buff;                         /* 0x0204 */
  //Referee_DroneEnergy_t drone_energy;                   /* 0x0205 */
  Referee_RobotDamage_t robot_danage;                     /* 0x0206 */
  Referee_ShootData_t shoot_data;                         /* 0x0207 */
  Referee_BulletRemain_t bullet_remain;                   /* 0x0208 */
  Referee_RFID_t rfid;                                    /* 0x0209 */
  Referee_DartClient_t dart_client;                       /* 0x020A */
  Referee_Robot_Position_t pos_sentry;                    /* 0x020B */
  Referee_Radar_mark_data_t radar_mark;                   /* 0x020C */
  Referee_Sentry_Info_t sentry_decision;                  /* 0x020D */
  Referee_Radar_Info_t radar_decision;                    /* 0x020E */
  // Referee_InterStudent_Custom_t custom;
  Referee_Interaction_Data_t interactive_data;            /* 0x0301 */
  Referee_custom_robot_data_t custom_robot_data;          /* 0x0302 */
  Referee_ClientMap_t client_map;                         /* 0x0303 */
  Referee_KeyboardMouse_t keyboard_mouse;                 /* 0x0304 */
  Referee_map_robot_data_t map_robot_data;                /* 0x0305 */
  Referee_custom_client_data_t custom_keyboard_mouse;     /* 0x0306 */
  Referee_map_data_t sentry_pos_data;                     /* 0x0307 */
  Referee_custom_info_t  custom_info;                     /* 0x0308 */
  Referee_robot_custom_data_t  custom_data;               /* 0x0309*/

  osTimerId_t ui_fast_timer_id;
  osTimerId_t ui_slow_timer_id;
} Referee_t;

typedef struct {
  CMD_ChassisMode_t mode;
  float angle;
} Referee_ChassisUI_t;

typedef struct {
  float percentage;
  CAN_CapStatus_t status;
} Referee_CapUI_t;

typedef struct {
  CMD_GimbalMode_t mode;
} Referee_GimbalUI_t;

typedef struct {
  CMD_ShootMode_t mode;
  CMD_FireMode_t fire;
} Referee_ShootUI_t;

typedef struct __packed {
  /* UI缓冲数据 */
  UI_Ele_t grapic[REF_UI_MAX_GRAPIC_NUM];
  UI_Drawcharacter_t character_data[REF_UI_MAX_STRING_NUM];
  UI_Del_t del[REF_UI_MAX_DEL_NUM];
  /* 待发送数量 */
  uint8_t grapic_counter;
  uint8_t character_counter;
  uint8_t del_counter;
  /* UI所需信息 */
  Referee_CapUI_t cap_ui;
  Referee_ChassisUI_t chassis_ui;
  Referee_ShootUI_t shoot_ui;
  Referee_GimbalUI_t gimbal_ui;
  bool cmd_pc;
  /* 屏幕分辨率 */
  const CMD_Screen_t *screen;
} Referee_UI_t;

typedef struct __packed {
  uint16_t data_cmd_id;
  uint16_t sender_ID;
  uint16_t receiver_ID;
} Referee_Interactive_Header_t;

typedef struct __packed {
  Referee_Header_t header;
  uint16_t cmd_id;
  Referee_Interactive_Header_t IA_header;
  UI_Drawgrapic_1_t data;
  uint16_t crc16;
} Referee_UI_Drawgrapic_1_t;

typedef struct __packed {
  Referee_Header_t header;
  uint16_t cmd_id;
  Referee_Interactive_Header_t IA_header;
  UI_Drawgrapic_2_t data;
  uint16_t crc16;
} Referee_UI_Drawgrapic_2_t;

typedef struct __packed {
  Referee_Header_t header;
  uint16_t cmd_id;
  Referee_Interactive_Header_t IA_header;
  UI_Drawgrapic_5_t data;
  uint16_t crc16;
} Referee_UI_Drawgrapic_5_t;

typedef struct __packed {
  Referee_Header_t header;
  uint16_t cmd_id;
  Referee_Interactive_Header_t IA_header;
  UI_Drawgrapic_7_t data;
  uint16_t crc16;
} Referee_UI_Drawgrapic_7_t;

typedef struct __packed {
  Referee_Header_t header;
  uint16_t cmd_id;
  Referee_Interactive_Header_t IA_header;
  UI_Drawcharacter_t data;
  uint16_t crc16;
} Referee_UI_Drawcharacter_t;

typedef struct __packed {
  Referee_Header_t header;
  uint16_t cmd_id;
  Referee_Interactive_Header_t IA_header;
  UI_Del_t data;
  uint16_t crc16;
} Referee_UI_Del_t;

typedef struct {
  Referee_Status_t ref_status;
  float chassis_watt;
  float chassis_power_limit;
  float chassis_pwr_buff;
} Referee_ForCap_t;

typedef struct {
  Referee_Status_t ref_status;
} Referee_ForAI_t;

typedef struct {
  Referee_Status_t ref_status;
  float chassis_power_limit;
  float chassis_pwr_buff;
} Referee_ForChassis_t;

typedef struct {
  Referee_Status_t ref_status;
  Referee_PowerHeat_t power_heat;
  Referee_RobotStatus_t robot_status;
  Referee_ShootData_t shoot_data;
} Referee_ForShoot_t;

/* Exported functions prototypes -------------------------------------------- */
int8_t Referee_Init(Referee_t *ref, Referee_UI_t *ui,
                    const CMD_Screen_t *screen);
int8_t Referee_Restart(void);

int8_t Referee_StartReceiving(Referee_t *ref);
int8_t Referee_Parse(Referee_t *ref);
void Referee_HandleOffline(Referee_t *referee);
int8_t Referee_SetHeader(Referee_Interactive_Header_t *header,
                         Referee_StudentCMDID_t cmd_id, uint8_t sender_id);
int8_t Referee_StartSend(uint8_t *data, uint32_t len);
int8_t Referee_MoveData(void *data, void *tmp, uint32_t len);
int8_t Referee_PackUI(Referee_UI_t *ui, Referee_t *ref);
UI_Ele_t *Referee_GetGrapicAdd(Referee_UI_t *ref_ui);
UI_Drawcharacter_t *Referee_GetCharacterAdd(Referee_UI_t *ref_ui);
uint8_t Referee_PraseCmd(Referee_UI_t *ref_ui, CMD_UI_t cmd);
uint8_t Referee_PackCap(Referee_ForCap_t *cap, const Referee_t *ref);
uint8_t Referee_PackShoot(Referee_ForShoot_t *ai, Referee_t *ref);
uint8_t Referee_PackChassis(Referee_ForChassis_t *chassis,
                            const Referee_t *ref);
uint8_t Referee_PackAI(Referee_ForAI_t *shoot, const Referee_t *ref);
uint8_t Referee_UIRefresh(Referee_UI_t *ui);
#ifdef __cplusplus
}
#endif
