/** * @file referee.C * @author kidneygood (you@domain.com) * @brief * @version 0.1 * @date 2022-11-18 * * @copyright Copyright (c) 2022 * */ #include "referee_task.h" #include "robot_def.h" #include "rm_referee.h" #include "referee_UI.h" #include "string.h" #include "cmsis_os.h" #include "crc_ref.h" static Referee_Interactive_info_t *Interactive_data; // UI绘制需要的机器人状态数据 static referee_info_t *referee_recv_info; // 接收到的裁判系统数据 uint8_t UI_Seq; // 包序号,供整个referee文件使用 // @todo 不应该使用全局变量 /** * @brief 判断各种ID,选择客户端ID * @param referee_info_t *referee_recv_info * @retval none * @attention */ static void DeterminRobotID() { // id小于7是红色,大于7是蓝色,0为红色,1为蓝色 #define Robot_Red 0 #define Robot_Blue 1 referee_recv_info->referee_id.Robot_Color = referee_recv_info->GameRobotState.robot_id > 7 ? Robot_Blue : Robot_Red; referee_recv_info->referee_id.Robot_ID = referee_recv_info->GameRobotState.robot_id; referee_recv_info->referee_id.Cilent_ID = 0x0100 + referee_recv_info->referee_id.Robot_ID; // 计算客户端ID referee_recv_info->referee_id.Receiver_Robot_ID = 0; } Sentry_Decision_Data_t SentryDecision; static void Sentry_CMD_send(referee_id_t *_id,Sentry_Decision_Data_t Sentry_Decision); referee_info_t *UITaskInit(UART_HandleTypeDef *referee_usart_handle, Referee_Interactive_info_t *UI_data) { referee_recv_info = RefereeInit(referee_usart_handle); // 初始化裁判系统的串口,并返回裁判系统反馈数据指针 Interactive_data = UI_data; // 获取UI绘制需要的机器人状态数据 referee_recv_info->init_flag = 1; return referee_recv_info; } void UITask() { SentryDecision.reserve = 1; // 确认复活 SentryDecision.buy_bullet = 100; //买100发弹丸 Sentry_CMD_send(&referee_recv_info->referee_id,SentryDecision); } void MyUIInit() { // if (!referee_recv_info->init_flag) //vTaskDelete(NULL); // 如果没有初始化裁判系统则直接删除ui任务 while (referee_recv_info->GameRobotState.robot_id == 0) { osDelay(100); // 若还未收到裁判系统数据,等待一段时间后再检查 } DeterminRobotID(); // 确定ui要发送到的目标客户端 } void Sentry_CMD_send(referee_id_t *_id,Sentry_Decision_Data_t Sentry_Decision) { static Sentry_CMD_t sentryCmd; uint8_t temp_datalength = Interactive_Data_LEN_Head + Sentry_Decision_LEN; // 计算交互数据长度 sentryCmd.FrameHeader.SOF = REFEREE_SOF; sentryCmd.FrameHeader.DataLength = temp_datalength; sentryCmd.FrameHeader.Seq = UI_Seq; sentryCmd.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&sentryCmd, LEN_CRC8, 0xFF); sentryCmd.CmdID = ID_student_interactive; sentryCmd.datahead.data_cmd_id = Sentry_Decision_ID; sentryCmd.datahead.receiver_ID = RobotID_Referee; sentryCmd.datahead.sender_ID = _id->Robot_ID; sentryCmd.SentryDecision = Sentry_Decision; sentryCmd.frametail = Get_CRC16_Check_Sum((uint8_t *)&sentryCmd, LEN_HEADER + LEN_CMDID + temp_datalength, 0xFFFF); RefereeSend((uint8_t *)&sentryCmd, LEN_HEADER + LEN_CMDID + temp_datalength + LEN_TAIL); // 发送 UI_Seq++; // 包序号+1 }