From 162044889fe9f821ed83df5e30bb414578b1cff8 Mon Sep 17 00:00:00 2001 From: kidneygood <2979564623@qq.com> Date: Fri, 6 Jan 2023 22:54:01 +0800 Subject: [PATCH 01/15] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/referee/referee.c | 8 +- modules/referee/referee.h | 175 +----------------------- modules/referee/referee_UI.c | 95 +++++++++++++ modules/referee/referee_UI.h | 0 modules/referee/referee_communication.h | 92 +++++++++++++ modules/referee/referee_def.h | 83 +++++++++++ 6 files changed, 276 insertions(+), 177 deletions(-) create mode 100644 modules/referee/referee_UI.h create mode 100644 modules/referee/referee_communication.h create mode 100644 modules/referee/referee_def.h diff --git a/modules/referee/referee.c b/modules/referee/referee.c index f59c2bb..8cb685e 100644 --- a/modules/referee/referee.c +++ b/modules/referee/referee.c @@ -11,8 +11,8 @@ static USARTInstance *referee_usart_instance; /**************裁判系统数据******************/ static referee_info_t referee_info; -static uint8_t Judge_Self_ID; // 当前机器人的ID -static uint16_t Judge_SelfClient_ID; // 发送者机器人对应的客户端ID +// static uint8_t Judge_Self_ID; // 当前机器人的ID +// static uint16_t Judge_SelfClient_ID; // 发送者机器人对应的客户端ID /** * @brief 读取裁判数据,中断中读取保证速度 @@ -23,9 +23,7 @@ static uint16_t Judge_SelfClient_ID; // 发送者机器人对应的客户端ID static void JudgeReadData(uint8_t *ReadFromUsart) { uint16_t judge_length; // 统计一帧数据长度 - // referee_info.CmdID = 0; //数据命令码解析 - // 空数据包,则不作任何处理 - if (ReadFromUsart == NULL) + if (ReadFromUsart == NULL) // 空数据包,则不作任何处理 return; // 写入帧头数据(5-byte),用于判断是否开始存储裁判数据 diff --git a/modules/referee/referee.h b/modules/referee/referee.h index b2238c9..810db85 100644 --- a/modules/referee/referee.h +++ b/modules/referee/referee.h @@ -14,6 +14,7 @@ #include "bsp_usart.h" #include "usart.h" +#include "referee_def.h" #define FALSE 0 #define TRUE 1 @@ -30,72 +31,6 @@ #pragma pack(1) -/***************裁判系统数据接收********************/ - -typedef enum -{ - FRAME_HEADER = 0, - CMD_ID = 5, - DATA = 7, -} JudgeFrameOffset; - -// 5字节帧头,偏移位置 -typedef enum -{ - SOF = 0, // 起始位 - DATA_LENGTH = 1, // 帧内数据长度,根据这个来获取数据长度 - SEQ = 3, // 包序号 - CRC8 = 4 // CRC8 - -} FrameHeaderOffset; - -// 命令码ID,用来判断接收的是什么数据 -typedef enum -{ - ID_game_state = 0x0001, // 比赛状态数据 - ID_game_result = 0x0002, // 比赛结果数据 - ID_game_robot_survivors = 0x0003, // 比赛机器人血量数据 - ID_event_data = 0x0101, // 场地事件数据 - ID_supply_projectile_action = 0x0102, // 场地补给站动作标识数据 - ID_supply_projectile_booking = 0x0103, // 场地补给站预约子弹数据 - ID_game_robot_state = 0x0201, // 机器人状态数据 - ID_power_heat_data = 0x0202, // 实时功率热量数据 - ID_game_robot_pos = 0x0203, // 机器人位置数据 - ID_buff_musk = 0x0204, // 机器人增益数据 - ID_aerial_robot_energy = 0x0205, // 空中机器人能量状态数据 - ID_robot_hurt = 0x0206, // 伤害状态数据 - ID_shoot_data = 0x0207, // 实时射击数据 - -} CmdID; - -// 命令码数据段长,根据官方协议来定义长度 -typedef enum -{ - LEN_game_state = 3, // 0x0001 - LEN_game_result = 1, // 0x0002 - LEN_game_robot_HP = 2, // 0x0003 - LEN_event_data = 4, // 0x0101 - LEN_supply_projectile_action = 4, // 0x0102 - // LEN_game_robot_state = 15, // 0x0201 - LEN_game_robot_state = 27, // 0x0201 - LEN_power_heat_data = 14, // 0x0202 - LEN_game_robot_pos = 16, // 0x0203 - LEN_buff_musk = 1, // 0x0204 - LEN_aerial_robot_energy = 1, // 0x0205 - LEN_robot_hurt = 1, // 0x0206 - LEN_shoot_data = 7, // 0x0207 -} JudgeDataLength; - -/* 自定义帧头 */ -typedef struct -{ - uint8_t SOF; - uint16_t DataLength; - uint8_t Seq; - uint8_t CRC8; - -} xFrameHeader; - /* ID: 0x0001 Byte: 3 比赛状态数据 */ typedef struct { @@ -216,108 +151,6 @@ typedef struct float bullet_speed; } ext_shoot_data_t; -/***************裁判系统数据********************/ -/* - - 交互数据,包括一个统一的数据段头结构, - 包含了内容 ID,发送者以及接受者的 ID 和内容数据段, - 整个交互数据的包总共长最大为 128 个字节, - 减去 frame_header,cmd_id,frame_tail 以及数据段头结构的 6 个字节, - 故而发送的内容数据段最大为 113。 - 整个交互数据 0x0301 的包上行频率为 10Hz。 - - 机器人 ID: - 1,英雄(红); - 2,工程(红); - 3/4/5,步兵(红); - 6,空中(红); - 7,哨兵(红); - 11,英雄(蓝); - 12,工程(蓝); - 13/14/15,步兵(蓝); - 16,空中(蓝); - 17,哨兵(蓝)。 - 客户端 ID: - 0x0101 为英雄操作手客户端( 红) ; - 0x0102 ,工程操作手客户端 ((红 ); - 0x0103/0x0104/0x0105,步兵操作手客户端(红); - 0x0106,空中操作手客户端((红); - 0x0111,英雄操作手客户端(蓝); - 0x0112,工程操作手客户端(蓝); - 0x0113/0x0114/0x0115,操作手客户端步兵(蓝); - 0x0116,空中操作手客户端(蓝)。 -*/ -/* 交互数据接收信息:0x0301 */ -typedef struct -{ - uint16_t data_cmd_id; - uint16_t send_ID; - uint16_t receiver_ID; -} ext_student_interactive_header_data_t; - -/* - 客户端 客户端自定义数据:cmd_id:0x0301。内容 ID:0xD180 - 发送频率:上限 10Hz - 1. 客户端 客户端自定义数据:cmd_id:0x0301。内容 ID:0xD180。发送频率:上限 10Hz - 字节偏移量 大小 说明 备注 - 0 2 数据的内容 ID 0xD180 - 2 2 送者的 ID 需要校验发送者机器人的 ID 正确性 - 4 2 客户端的 ID 只能为发送者机器人对应的客户端 - 6 4 自定义浮点数据 1 - 10 4 自定义浮点数据 2 - 14 4 自定义浮点数据 3 - 18 1 自定义 8 位数据 4 - -*/ -typedef struct -{ - float data1; - float data2; - float data3; - uint8_t masks; -} client_custom_data_t; - -/* - 学生机器人间通信 cmd_id 0x0301,内容 ID:0x0200~0x02FF - 交互数据 机器人间通信:0x0301。 - 发送频率:上限 10Hz - - 字节偏移量 大小 说明 备注 - 0 2 数据的内容 ID 0x0200~0x02FF - 可以在以上 ID 段选取,具体 ID 含义由参赛队自定义 - - 2 2 发送者的 ID 需要校验发送者的 ID 正确性, - 4 2 接收者的 ID 需要校验接收者的 ID 正确性, - 例如不能发送到敌对机器人的ID - 6 n 数据段 n 需要小于 113 - -*/ -typedef struct -{ - uint8_t data[10]; // 数据段,n需要小于113 -} robot_interactive_data_t; - -// 发送给客户端的信息 -// 帧头 命令码 数据段头结构 数据段 帧尾 -typedef struct -{ - xFrameHeader txFrameHeader; // 帧头 - uint16_t CmdID; // 命令码 - ext_student_interactive_header_data_t dataFrameHeader; // 数据段头结构 - client_custom_data_t clientData; // 数据段 - uint16_t FrameTail; // 帧尾 -} ext_SendClientData_t; - -// 机器人交互信息 -typedef struct -{ - xFrameHeader txFrameHeader; // 帧头 - uint16_t CmdID; // 命令码 - ext_student_interactive_header_data_t dataFrameHeader; // 数据段头结构 - robot_interactive_data_t interactData; // 数据段 - uint16_t FrameTail; // 帧尾 -} ext_CommunatianData_t; - // 裁判系统接收数据整合进一个结构体 typedef struct { @@ -336,8 +169,8 @@ typedef struct ext_robot_hurt_t RobotHurt; // 0x0206 ext_shoot_data_t ShootData; // 0x0207 - ext_SendClientData_t ShowData; // 客户端信息 - ext_CommunatianData_t CommuData; // 队友通信信息 + // ext_SendClientData_t ShowData; // 客户端信息 + // ext_CommunatianData_t CommuData; // 队友通信信息 } referee_info_t; @@ -352,6 +185,4 @@ typedef struct referee_info_t* RefereeInit(UART_HandleTypeDef *referee_usart_handle); - - #endif // !REFEREE_H diff --git a/modules/referee/referee_UI.c b/modules/referee/referee_UI.c index e69de29..2b4d68f 100644 --- a/modules/referee/referee_UI.c +++ b/modules/referee/referee_UI.c @@ -0,0 +1,95 @@ +// /** +// * @brief 上传自定义数据 +// * @param void +// * @retval void +// * @attention 数据打包,打包完成后通过串口发送到裁判系统 +// */ +// #define send_max_len 200 +// unsigned char CliendTxBuffer[send_max_len]; +// void JUDGE_Show_Data(void) +// { +// static u8 datalength,i; +// uint8_t judge_led = 0xff;//初始化led为全绿 +// static uint8_t auto_led_time = 0; +// static uint8_t buff_led_time = 0; + +// determine_ID();//判断发送者ID和其对应的客户端ID + +// ShowData.txFrameHeader.SOF = 0xA5; +// ShowData.txFrameHeader.DataLength = sizeof(ext_student_interactive_header_data_t) + sizeof(client_custom_data_t); +// ShowData.txFrameHeader.Seq = 0; +// memcpy(CliendTxBuffer, &ShowData.txFrameHeader, sizeof(xFrameHeader));//写入帧头数据 +// Append_CRC8_Check_Sum(CliendTxBuffer, sizeof(xFrameHeader));//写入帧头CRC8校验码 + +// ShowData.CmdID = 0x0301; + +// ShowData.dataFrameHeader.data_cmd_id = 0xD180;//发给客户端的cmd,官方固定 +// //ID已经是自动读取的了 +// ShowData.dataFrameHeader.send_ID = Judge_Self_ID;//发送者的ID +// ShowData.dataFrameHeader.receiver_ID = Judge_SelfClient_ID;//客户端的ID,只能为发送者机器人对应的客户端 + +// /*- 自定义内容 -*/ +// ShowData.clientData.data1 = (float)Capvoltage_Percent();//电容剩余电量 +// ShowData.clientData.data2 = (float)Base_Angle_Measure();//吊射角度测 +// ShowData.clientData.data3 = GIMBAL_PITCH_Judge_Angle();//云台抬头角度 +// ShowData.clientData.masks = judge_led;//0~5位0红灯,1绿灯 + +// //打包写入数据段 +// memcpy( +// CliendTxBuffer + 5, +// (uint8_t*)&ShowData.CmdID, +// (sizeof(ShowData.CmdID)+ sizeof(ShowData.dataFrameHeader)+ sizeof(ShowData.clientData)) +// ); + +// Append_CRC16_Check_Sum(CliendTxBuffer,sizeof(ShowData));//写入数据段CRC16校验码 + +// datalength = sizeof(ShowData); +// for(i = 0;i < datalength;i++) +// { +// USART_SendData(UART5,(uint16_t)CliendTxBuffer[i]); +// while(USART_GetFlagStatus(UART5,USART_FLAG_TC)==RESET); +// } +// } + + + + +// /** +// * @brief 判断自己红蓝方 +// * @param void +// * @retval RED BLUE +// * @attention 数据打包,打包完成后通过串口发送到裁判系统 +// */ +// bool Color; +// bool is_red_or_blue(void) +// { +// Judge_Self_ID = GameRobotStat.robot_id;//读取当前机器人ID + +// if(GameRobotStat.robot_id > 10) +// { +// return BLUE; +// } +// else +// { +// return RED; +// } +// } + +// /** +// * @brief 判断自身ID,选择客户端ID +// * @param void +// * @retval RED BLUE +// * @attention 数据打包,打包完成后通过串口发送到裁判系统 +// */ +// void determine_ID(void) +// { +// Color = is_red_or_blue(); +// if(Color == BLUE) +// { +// Judge_SelfClient_ID = 0x0110 + (Judge_Self_ID-10);//计算客户端ID +// } +// else if(Color == RED) +// { +// Judge_SelfClient_ID = 0x0100 + Judge_Self_ID;//计算客户端ID +// } +// } \ No newline at end of file diff --git a/modules/referee/referee_UI.h b/modules/referee/referee_UI.h new file mode 100644 index 0000000..e69de29 diff --git a/modules/referee/referee_communication.h b/modules/referee/referee_communication.h new file mode 100644 index 0000000..b3b4f5a --- /dev/null +++ b/modules/referee/referee_communication.h @@ -0,0 +1,92 @@ +/** + * @file referee_communication.h + * @author kidneygood (you@domain.com) + * @version 0.1 + * @date 2022-12-02 + * + * @copyright Copyright (c) HNU YueLu EC 2022 all rights reserved + * + */ + +#ifndef REFEREE_COMMUNICATION_H +#define REFEREE_COMMUNICATION_H + +#include "stdint.h" +#include "referee_def.h" +#pragma pack(1) + + +//暂时放在这里 +/***************交互数据********************/ +/* + 0x0301 机器人间交互数据,发送方触发发送,上限 10Hz + 己方机器人间通信与UI绘制共用同一个cmd_id + 根据数据段内容ID的不同区分 +*/ +/* 交互数据接收信息:0x0301 */ +typedef struct +{ + uint16_t data_cmd_id; + uint16_t send_ID; + uint16_t receiver_ID; +} ext_student_interactive_header_data_t; + +/* + 客户端 客户端自定义数据:cmd_id:0x0301。内容 ID:0xD180 + 发送频率:上限 10Hz + 1. 客户端 客户端自定义数据:cmd_id:0x0301。内容 ID:0xD180。发送频率:上限 10Hz + 字节偏移量 大小 说明 备注 + 0 2 数据的内容 ID 0xD180 + 2 2 送者的 ID 需要校验发送者机器人的 ID 正确性 + 4 2 客户端的 ID 只能为发送者机器人对应的客户端 + 6 4 自定义浮点数据 1 + 10 4 自定义浮点数据 2 + 14 4 自定义浮点数据 3 + 18 1 自定义 8 位数据 4 + +*/ +typedef struct +{ + float data1; + float data2; + float data3; + uint8_t masks; +} client_custom_data_t; + +/* + 学生机器人间通信 cmd_id 0x0301,内容 ID:0x0200~0x02FF + 交互数据 机器人间通信:0x0301。 + 发送频率:上限 10Hz +*/ +typedef struct +{ + uint8_t data[10]; // 数据段,n需要小于113 +} robot_interactive_data_t; + +// 发送给客户端的信息 +//交互数据包括一个统一的数据段头结构。数据段包含了内容 ID,发送者以及接收者的 ID 和内容数据段, +// 整个交互数据的包总共长最大为 128 个字节,减去 frame_header,cmd_id 和 frame_tail 共 9 个字节以及 +// 数据段头结构的 6 个字节,故而发送的内容数据段最大为 113。 +// 帧头 命令码 数据段头结构 数据段 帧尾 +typedef struct +{ + xFrameHeader txFrameHeader; // 帧头 + uint16_t CmdID; // 命令码 + ext_student_interactive_header_data_t dataFrameHeader; // 数据段头结构 + client_custom_data_t clientData; // 数据段 + uint16_t FrameTail; // 帧尾 +} ext_SendClientData_t; + +// 机器人交互信息 +typedef struct +{ + xFrameHeader txFrameHeader; // 帧头 + uint16_t CmdID; // 命令码 + ext_student_interactive_header_data_t dataFrameHeader; // 数据段头结构 + robot_interactive_data_t interactData; // 数据段 + uint16_t FrameTail; // 帧尾 +} ext_CommunatianData_t; + +#pragma pack() + +#endif \ No newline at end of file diff --git a/modules/referee/referee_def.h b/modules/referee/referee_def.h new file mode 100644 index 0000000..24c3e30 --- /dev/null +++ b/modules/referee/referee_def.h @@ -0,0 +1,83 @@ +/** + * @file referee_def.h + * @author kidneygood (you@domain.com) + * @version 0.1 + * @date 2022-12-02 + * + * @copyright Copyright (c) HNU YueLu EC 2022 all rights reserved + * + */ + +#ifndef REFEREE_DEF_H +#define REFEREE_DEF_H + +#include "stdint.h" + +#pragma pack(1) + +// 枚举类型,代替#define声明 +typedef enum +{ + FRAME_HEADER = 0, + CMD_ID = 5, + DATA = 7, +} JudgeFrameOffset; + +// 帧头偏移,枚举 +typedef enum +{ + SOF = 0, // 起始位 + DATA_LENGTH = 1, // 帧内数据长度,根据这个来获取数据长度 + SEQ = 3, // 包序号 + CRC8 = 4 // CRC8 +} FrameHeaderOffset; + +/* 自定义帧头 */ +typedef struct +{ + uint8_t SOF; + uint16_t DataLength; + uint8_t Seq; + uint8_t CRC8; +} xFrameHeader; + +// 命令码ID,用来判断接收的是什么数据 +typedef enum +{ + ID_game_state = 0x0001, // 比赛状态数据 + ID_game_result = 0x0002, // 比赛结果数据 + ID_game_robot_survivors = 0x0003, // 比赛机器人血量数据 + ID_event_data = 0x0101, // 场地事件数据 + ID_supply_projectile_action = 0x0102, // 场地补给站动作标识数据 + ID_supply_projectile_booking = 0x0103, // 场地补给站预约子弹数据 + ID_game_robot_state = 0x0201, // 机器人状态数据 + ID_power_heat_data = 0x0202, // 实时功率热量数据 + ID_game_robot_pos = 0x0203, // 机器人位置数据 + ID_buff_musk = 0x0204, // 机器人增益数据 + ID_aerial_robot_energy = 0x0205, // 空中机器人能量状态数据 + ID_robot_hurt = 0x0206, // 伤害状态数据 + ID_shoot_data = 0x0207, // 实时射击数据 + +} CmdID; + +// 命令码数据段长,根据官方协议来定义长度 +typedef enum +{ + LEN_game_state = 3, // 0x0001 + LEN_game_result = 1, // 0x0002 + LEN_game_robot_HP = 2, // 0x0003 + LEN_event_data = 4, // 0x0101 + LEN_supply_projectile_action = 4, // 0x0102 + LEN_game_robot_state = 27, // 0x0201 + LEN_power_heat_data = 14, // 0x0202 + LEN_game_robot_pos = 16, // 0x0203 + LEN_buff_musk = 1, // 0x0204 + LEN_aerial_robot_energy = 1, // 0x0205 + LEN_robot_hurt = 1, // 0x0206 + LEN_shoot_data = 7, // 0x0207 +} JudgeDataLength; + +#pragma pack() + +#endif + From 86e30f7893a9c25e4c0373dae24f7cc97815b23c Mon Sep 17 00:00:00 2001 From: kidneygood <2979564623@qq.com> Date: Mon, 9 Jan 2023 16:17:03 +0800 Subject: [PATCH 02/15] =?UTF-8?q?=E4=B8=B2=E5=8F=A36DMA=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HAL_N_Middlewares/Src/main.c | 13 + application/chassis/chassis.c | 2 +- modules/referee/referee.c | 55 ++-- modules/referee/referee.h | 11 +- modules/referee/referee_UI.c | 512 +++++++++++++++++++++++++++++++++- modules/referee/referee_UI.h | 172 ++++++++++++ modules/referee/referee_def.h | 10 +- 7 files changed, 744 insertions(+), 31 deletions(-) diff --git a/HAL_N_Middlewares/Src/main.c b/HAL_N_Middlewares/Src/main.c index b89d655..13aa79d 100644 --- a/HAL_N_Middlewares/Src/main.c +++ b/HAL_N_Middlewares/Src/main.c @@ -33,6 +33,10 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "robot.h" +////////////////////////////////////////////////// +#include "referee_UI.h" +#include "referee.h" +////////////////////////////////////////////////// /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -113,6 +117,15 @@ int main(void) RobotInit(); + +////////////////////////////////////////////////// + // Graph_Data shoot_line; + UI_Delete(UI_Data_Del_ALL,0); + // //绘制发射基准线 + // Line_Draw(&shoot_line,"s1",UI_Graph_ADD,7,UI_Color_White,3,710,540,1210,540); + // UI_ReFresh(1,shoot_line); +////////////////////////////////////////////////// + /* USER CODE END 2 */ /* Call init function for freertos objects (in freertos.c) */ diff --git a/application/chassis/chassis.c b/application/chassis/chassis.c index e30a9fe..55625a1 100644 --- a/application/chassis/chassis.c +++ b/application/chassis/chassis.c @@ -49,7 +49,7 @@ static DJIMotorInstance *motor_lb; static DJIMotorInstance *motor_rb; /* 用于自旋变速策略的时间变量,后续考虑查表加速 */ -static float t; +// static float t; /* 私有函数计算的中介变量,设为静态避免参数传递的开销 */ static float chassis_vx, chassis_vy; // 将云台系的速度投影到底盘 diff --git a/modules/referee/referee.c b/modules/referee/referee.c index 8cb685e..7cc9679 100644 --- a/modules/referee/referee.c +++ b/modules/referee/referee.c @@ -2,18 +2,46 @@ #include "string.h" #include "crc.h" #include "bsp_usart.h" -#include "dma.h" -// 参考深圳大学 Infantry_X-master #define RE_RX_BUFFER_SIZE 200 -static USARTInstance *referee_usart_instance; +USARTInstance *referee_usart_instance; //暂时改为非静态变量 -/**************裁判系统数据******************/ static referee_info_t referee_info; +static void JudgeReadData(uint8_t *ReadFromUsart); +static void RefereeRxCallback(); + // static uint8_t Judge_Self_ID; // 当前机器人的ID // static uint16_t Judge_SelfClient_ID; // 发送者机器人对应的客户端ID +/* 裁判系统通信初始化 */ +referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle) +{ + USART_Init_Config_s conf; + conf.module_callback = RefereeRxCallback; + conf.usart_handle = referee_usart_handle; + conf.recv_buff_size = RE_RX_BUFFER_SIZE; + referee_usart_instance = USARTRegister(&conf); + return &referee_info; +} + + +/** + * @brief 发送函数 + * @param send 待发送数据 + */ +void RefereeSend(uint8_t *send,uint16_t tx_len) +{ + USARTSend(referee_usart_instance,send,tx_len); +} + + +/*裁判系统串口接收回调函数,解析数据 */ +static void RefereeRxCallback() +{ + JudgeReadData(referee_usart_instance->recv_buff); +} + /** * @brief 读取裁判数据,中断中读取保证速度 * @param ReadFromUsart: 读取到的裁判系统原始数据 @@ -103,23 +131,4 @@ static void JudgeReadData(uint8_t *ReadFromUsart) JudgeReadData(ReadFromUsart + sizeof(xFrameHeader) + LEN_CMDID + referee_info.FrameHeader.DataLength + LEN_TAIL); } } -} - -/** - * @brief 裁判系统串口接收回调函数,解析数据 - * - */ -static void RefereeRxCallback() -{ - JudgeReadData(referee_usart_instance->recv_buff); -} - -referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle) -{ - USART_Init_Config_s conf; - conf.module_callback = RefereeRxCallback; - conf.usart_handle = referee_usart_handle; - conf.recv_buff_size = RE_RX_BUFFER_SIZE; - referee_usart_instance = USARTRegister(&conf); - return &referee_info; } \ No newline at end of file diff --git a/modules/referee/referee.h b/modules/referee/referee.h index 810db85..3ed201f 100644 --- a/modules/referee/referee.h +++ b/modules/referee/referee.h @@ -12,9 +12,10 @@ #ifndef REFEREE_H #define REFEREE_H -#include "bsp_usart.h" #include "usart.h" #include "referee_def.h" +#include "bsp_usart.h" + #define FALSE 0 #define TRUE 1 @@ -184,5 +185,13 @@ typedef struct */ referee_info_t* RefereeInit(UART_HandleTypeDef *referee_usart_handle); +/** + * @brief 发送函数 + * @todo + * @param send 待发送数据 + */ +void RefereeSend(uint8_t *send,uint16_t tx_len); + +extern USARTInstance *referee_usart_instance; #endif // !REFEREE_H diff --git a/modules/referee/referee_UI.c b/modules/referee/referee_UI.c index 2b4d68f..6fbf7c1 100644 --- a/modules/referee/referee_UI.c +++ b/modules/referee/referee_UI.c @@ -1,3 +1,513 @@ +#include "referee_UI.h" +#include "string.h" +#include "crc.h" +#include "bsp_usart.h" +#include "dma.h" +#include "stdio.h" +#include "referee.h" + +uint16_t Robot_ID = UI_Data_RobotID_BHero; +uint16_t Cilent_ID = UI_Data_CilentID_BHero; + +unsigned char UI_Seq; //包序号 +/****************************************串口驱动映射************************************/ +void UI_SendByte(unsigned char ch) +{ + HAL_UART_Transmit_DMA(&huart6,&ch,1); +} + +/********************************************删除操作************************************* +**参数:Del_Operate 对应头文件删除操作 + Del_Layer 要删除的层 取值0-9 +*****************************************************************************************/ +void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer) +{ + + unsigned char *framepoint; //读写指针 + uint16_t frametail=0xFFFF; //CRC16校验值 + + UI_Packhead framehead; //帧头 + UI_Data_Operate datahead; //数据交互帧 + UI_Data_Delete del; //删除图层帧 + + framepoint=(unsigned char *)&framehead; + + framehead.SOF=UI_SOF; + framehead.Data_Length=8; + framehead.Seq=UI_Seq; + framehead.CRC8=Get_CRC8_Check_Sum_UI(framepoint,4,0xFF); + framehead.CMD_ID=UI_CMD_Robo_Exchange; //填充包头数据 + + datahead.Data_ID=UI_Data_ID_Del; + datahead.Sender_ID=Robot_ID; + datahead.Receiver_ID=Cilent_ID; //填充操作数据 + + del.Delete_Operate=Del_Operate; + del.Layer=Del_Layer; //控制信息 + + frametail=Get_CRC16_Check_Sum_UI(framepoint,sizeof(framehead),frametail); + framepoint=(unsigned char *)&datahead; + frametail=Get_CRC16_Check_Sum_UI(framepoint,sizeof(datahead),frametail); + framepoint=(unsigned char *)&del; + frametail=Get_CRC16_Check_Sum_UI(framepoint,sizeof(del),frametail); //CRC16校验值计算 + + RefereeSend((uint8_t *)&framehead,sizeof(framehead)); + RefereeSend((uint8_t *)&datahead,sizeof(datahead)); + RefereeSend((uint8_t *)&del,sizeof(del)); //发送所有帧 + RefereeSend((uint8_t *)&frametail,sizeof(frametail)); //发送CRC16校验值 + + UI_Seq++; //包序号+1 +} +/************************************************绘制直线************************************************* +**参数:*image Graph_Data类型变量指针,用于存放图形数据 + imagename[3] 图片名称,用于标识更改 + Graph_Operate 图片操作,见头文件 + Graph_Layer 图层0-9 + Graph_Color 图形颜色 + Graph_Width 图形线宽 + Start_x、Start_y 开始坐标 + End_x、End_y 结束坐标 +**********************************************************************************************************/ + +void Line_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y) +{ + int i; + for(i=0;i<3&&imagename[i]!='\0';i++) + image->graphic_name[2-i]=imagename[i]; + image->operate_tpye = Graph_Operate; + image->layer = Graph_Layer; + image->color = Graph_Color; + image->width = Graph_Width; + image->start_x = Start_x; + image->start_y = Start_y; + image->end_x = End_x; + image->end_y = End_y; +} + +/************************************************绘制矩形************************************************* +**参数:*image Graph_Data类型变量指针,用于存放图形数据 + imagename[3] 图片名称,用于标识更改 + Graph_Operate 图片操作,见头文件 + Graph_Layer 图层0-9 + Graph_Color 图形颜色 + Graph_Width 图形线宽 + Start_x、Start_y 开始坐标 + End_x、End_y 结束坐标(对顶角坐标) +**********************************************************************************************************/ + +void Rectangle_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y) +{ + int i; + for(i=0;i<3&&imagename[i]!='\0';i++) + image->graphic_name[2-i]=imagename[i]; + image->graphic_tpye = UI_Graph_Rectangle; + image->operate_tpye = Graph_Operate; + image->layer = Graph_Layer; + image->color = Graph_Color; + image->width = Graph_Width; + image->start_x = Start_x; + image->start_y = Start_y; + image->end_x = End_x; + image->end_y = End_y; +} + +/************************************************绘制整圆************************************************* +**参数:*image Graph_Data类型变量指针,用于存放图形数据 + imagename[3] 图片名称,用于标识更改 + Graph_Operate 图片操作,见头文件 + Graph_Layer 图层0-9 + Graph_Color 图形颜色 + Graph_Width 图形线宽 + Start_x、Start_y 圆心坐标 + Graph_Radius 图形半径 +**********************************************************************************************************/ + +void Circle_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius) +{ + int i; + for(i=0;i<3&&imagename[i]!='\0';i++) + image->graphic_name[2-i]=imagename[i]; + image->graphic_tpye = UI_Graph_Circle; + image->operate_tpye = Graph_Operate; + image->layer = Graph_Layer; + image->color = Graph_Color; + image->width = Graph_Width; + image->start_x = Start_x; + image->start_y = Start_y; + image->radius = Graph_Radius; +} + +/************************************************绘制圆弧************************************************* +**参数:*image Graph_Data类型变量指针,用于存放图形数据 + imagename[3] 图片名称,用于标识更改 + Graph_Operate 图片操作,见头文件 + Graph_Layer 图层0-9 + Graph_Color 图形颜色 + Graph_StartAngle,Graph_EndAngle 开始,终止角度 + Graph_Width 图形线宽 + Start_y,Start_y 圆心坐标 + x_Length,y_Length x,y方向上轴长,参考椭圆 +**********************************************************************************************************/ + +void Arc_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t x_Length,uint32_t y_Length) +{ + int i; + + for(i=0;i<3&&imagename[i]!='\0';i++) + image->graphic_name[2-i]=imagename[i]; + image->graphic_tpye = UI_Graph_Arc; + image->operate_tpye = Graph_Operate; + image->layer = Graph_Layer; + image->color = Graph_Color; + image->width = Graph_Width; + image->start_x = Start_x; + image->start_y = Start_y; + image->start_angle = Graph_StartAngle; + image->end_angle = Graph_EndAngle; + image->end_x = x_Length; + image->end_y = y_Length; +} + + + +/************************************************绘制浮点型数据************************************************* +**参数:*image Graph_Data类型变量指针,用于存放图形数据 + imagename[3] 图片名称,用于标识更改 + Graph_Operate 图片操作,见头文件 + Graph_Layer 图层0-9 + Graph_Color 图形颜色 + Graph_Size 字号 + Graph_Digit 小数位数 + Graph_Width 图形线宽 + Start_x、Start_y 开始坐标 + Graph_Float 要显示的浮点数数值*1000 +**********************************************************************************************************/ + +void Float_Draw(Float_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float) +{ + int i; + for(i=0;i<3&&imagename[i]!='\0';i++) + image->graphic_name[2-i]=imagename[i]; + image->graphic_tpye = UI_Graph_Float; + image->operate_tpye = Graph_Operate; + image->layer = Graph_Layer; + image->color = Graph_Color; + image->width = Graph_Width; + image->start_x = Start_x; + image->start_y = Start_y; + image->start_angle = Graph_Size; + image->end_angle = Graph_Digit; + image->graph_Float = Graph_Float; +} + +/************************************************绘制字符型数据************************************************* +**参数:*image Graph_Data类型变量指针,用于存放图形数据 + imagename[3] 图片名称,用于标识更改 + Graph_Operate 图片操作,见头文件 + Graph_Layer 图层0-9 + Graph_Color 图形颜色 + Graph_Size 字号 + Graph_Width 图形线宽 + Start_x、Start_y 开始坐标 +**********************************************************************************************************/ + +void Char_Draw(String_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y) +{ + int i; + for(i=0;i<3&&imagename[i]!='\0';i++) + image->Graph_Control.graphic_name[2-i]=imagename[i]; + image->Graph_Control.graphic_tpye = UI_Graph_Char; + image->Graph_Control.operate_tpye = Graph_Operate; + image->Graph_Control.layer = Graph_Layer; + image->Graph_Control.color = Graph_Color; + image->Graph_Control.width = Graph_Width; + image->Graph_Control.start_x = Start_x; + image->Graph_Control.start_y = Start_y; + image->Graph_Control.start_angle = Graph_Size; +} + +void Char_Write(String_Data *image,char* fmt, ...) +{ + uint16_t i = 0; + va_list ap; + va_start(ap, fmt); + vsprintf((char*)image->show_Data, fmt, ap); + va_end(ap); + i = strlen((const char*)image->show_Data); + image->Graph_Control.end_angle = i; +} + +/************************************************UI推送函数(使更改生效)********************************* +**参数: cnt 图形个数 + ... 图形变量参数 + + +Tips::该函数只能推送1,2,5,7个图形,其他数目协议未涉及 +**********************************************************************************************************/ +int UI_ReFresh(int cnt,...) +{ + int i,n; + Graph_Data imageData; + unsigned char *framepoint; //读写指针 + uint16_t frametail=0xFFFF; //CRC16校验值 + + UI_Packhead framehead; + UI_Data_Operate datahead; + + va_list ap; + va_start(ap,cnt); + + framepoint=(unsigned char *)&framehead; + framehead.SOF=UI_SOF; + framehead.Data_Length=6+cnt*15; + framehead.Seq=UI_Seq; + framehead.CRC8=Get_CRC8_Check_Sum_UI(framepoint,4,0xFF); + framehead.CMD_ID=UI_CMD_Robo_Exchange; //填充包头数据 + + switch(cnt) + { + case 1: + datahead.Data_ID=UI_Data_ID_Draw1; + break; + case 2: + datahead.Data_ID=UI_Data_ID_Draw2; + break; + case 5: + datahead.Data_ID=UI_Data_ID_Draw5; + break; + case 7: + datahead.Data_ID=UI_Data_ID_Draw7; + break; + default: + return (-1); + } + datahead.Sender_ID=Robot_ID; + datahead.Receiver_ID=Cilent_ID; //填充操作数据 + + framepoint=(unsigned char *)&framehead; + frametail=Get_CRC16_Check_Sum_UI(framepoint,sizeof(framehead),frametail); + framepoint=(unsigned char *)&datahead; + frametail=Get_CRC16_Check_Sum_UI(framepoint,sizeof(datahead),frametail); //CRC16校验值计算(部分) + + framepoint=(unsigned char *)&framehead; + for(i=0;i> 8) ^ wCRC_Table_UI[((uint16_t)(wCRC) ^ (uint16_t)(chData)) & + 0x00ff]; + } + return wCRC; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + // /** // * @brief 上传自定义数据 // * @param void @@ -8,7 +518,7 @@ // unsigned char CliendTxBuffer[send_max_len]; // void JUDGE_Show_Data(void) // { -// static u8 datalength,i; +// static uint8_t datalength,i; // uint8_t judge_led = 0xff;//初始化led为全绿 // static uint8_t auto_led_time = 0; // static uint8_t buff_led_time = 0; diff --git a/modules/referee/referee_UI.h b/modules/referee/referee_UI.h index e69de29..0efa2e2 100644 --- a/modules/referee/referee_UI.h +++ b/modules/referee/referee_UI.h @@ -0,0 +1,172 @@ +#ifndef REFEREE_UI_H +#define REFEREE_UI_H + +#include "stdarg.h" +#include "usart.h" +#include "stdint.h" +#pragma pack(1) //按1字节对齐 + +// #define NULL 0 +#define __FALSE 100 + +/****************************开始标志*********************/ +#define UI_SOF 0xA5 +/****************************CMD_ID数据********************/ +#define UI_CMD_Robo_Exchange 0x0301 +/****************************内容ID数据********************/ +#define UI_Data_ID_Del 0x100 +#define UI_Data_ID_Draw1 0x101 +#define UI_Data_ID_Draw2 0x102 +#define UI_Data_ID_Draw5 0x103 +#define UI_Data_ID_Draw7 0x104 +#define UI_Data_ID_DrawChar 0x110 +/****************************红方机器人ID********************/ +#define UI_Data_RobotID_RHero 1 +#define UI_Data_RobotID_REngineer 2 +#define UI_Data_RobotID_RStandard1 3 +#define UI_Data_RobotID_RStandard2 4 +#define UI_Data_RobotID_RStandard3 5 +#define UI_Data_RobotID_RAerial 6 +#define UI_Data_RobotID_RSentry 7 +#define UI_Data_RobotID_RRadar 9 +/****************************蓝方机器人ID********************/ +#define UI_Data_RobotID_BHero 101 +#define UI_Data_RobotID_BEngineer 102 +#define UI_Data_RobotID_BStandard1 103 +#define UI_Data_RobotID_BStandard2 104 +#define UI_Data_RobotID_BStandard3 105 +#define UI_Data_RobotID_BAerial 106 +#define UI_Data_RobotID_BSentry 107 +#define UI_Data_RobotID_BRadar 109 +/**************************红方操作手ID************************/ +#define UI_Data_CilentID_RHero 0x0101 +#define UI_Data_CilentID_REngineer 0x0102 +#define UI_Data_CilentID_RStandard1 0x0103 +#define UI_Data_CilentID_RStandard2 0x0104 +#define UI_Data_CilentID_RStandard3 0x0105 +#define UI_Data_CilentID_RAerial 0x0106 +/***************************蓝方操作手ID***********************/ +#define UI_Data_CilentID_BHero 0x0165 +#define UI_Data_CilentID_BEngineer 0x0166 +#define UI_Data_CilentID_BStandard1 0x0167 +#define UI_Data_CilentID_BStandard2 0x0168 +#define UI_Data_CilentID_BStandard3 0x0169 +#define UI_Data_CilentID_BAerial 0x016A +/***************************删除操作***************************/ +#define UI_Data_Del_NoOperate 0 +#define UI_Data_Del_Layer 1 +#define UI_Data_Del_ALL 2 +/***************************图形配置参数__图形操作********************/ +#define UI_Graph_ADD 1 +#define UI_Graph_Change 2 +#define UI_Graph_Del 3 +/***************************图形配置参数__图形类型********************/ +#define UI_Graph_Line 0 //直线 +#define UI_Graph_Rectangle 1 //矩形 +#define UI_Graph_Circle 2 //整圆 +#define UI_Graph_Ellipse 3 //椭圆 +#define UI_Graph_Arc 4 //圆弧 +#define UI_Graph_Float 5 //浮点型 +#define UI_Graph_Int 6 //整形 +#define UI_Graph_Char 7 //字符型 +/***************************图形配置参数__图形颜色********************/ +#define UI_Color_Main 0 //红蓝主色 +#define UI_Color_Yellow 1 +#define UI_Color_Green 2 +#define UI_Color_Orange 3 +#define UI_Color_Purplish_red 4 //紫红色 +#define UI_Color_Pink 5 +#define UI_Color_Cyan 6 //青色 +#define UI_Color_Black 7 +#define UI_Color_White 8 + + + +typedef unsigned char Uint8_t; +typedef unsigned char uint8_t; + +extern uint16_t Robot_ID; +extern uint16_t Cilent_ID; + + + +typedef struct +{ + uint8_t SOF; //起始字节,固定0xA5 + uint16_t Data_Length; //帧数据长度 + uint8_t Seq; //包序号 + uint8_t CRC8; //CRC8校验值 + uint16_t CMD_ID; //命令ID +} UI_Packhead; //帧头 + +typedef struct +{ + uint16_t Data_ID; //内容ID + uint16_t Sender_ID; //发送者ID + uint16_t Receiver_ID; //接收者ID +} UI_Data_Operate; //操作定义帧 + +typedef struct +{ + uint8_t Delete_Operate; //删除操作 + uint8_t Layer; //删除图层 +} UI_Data_Delete; //删除图层帧 + + +typedef struct +{ + uint8_t graphic_name[3]; + uint32_t operate_tpye:3; + uint32_t graphic_tpye:3; + uint32_t layer:4; + uint32_t color:4; + uint32_t start_angle:9; + uint32_t end_angle:9; + uint32_t width:10; + uint32_t start_x:11; + uint32_t start_y:11; + int32_t graph_Float; //浮点数据 +} Float_Data; + + +typedef struct +{ +uint8_t graphic_name[3]; +uint32_t operate_tpye:3; +uint32_t graphic_tpye:3; +uint32_t layer:4; +uint32_t color:4; +uint32_t start_angle:9; +uint32_t end_angle:9; +uint32_t width:10; +uint32_t start_x:11; +uint32_t start_y:11; +uint32_t radius:10; +uint32_t end_x:11; +uint32_t end_y:11; //图形数据 +} Graph_Data; + + +typedef struct +{ + Graph_Data Graph_Control; + uint8_t show_Data[30]; +} String_Data; //打印字符串数据 + +#pragma pack() + +void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer); +void Line_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); +int UI_ReFresh(int cnt,...); +unsigned char Get_CRC8_Check_Sum_UI(unsigned char *pchMessage,unsigned int dwLength,unsigned char ucCRC8); +uint16_t Get_CRC16_Check_Sum_UI(uint8_t *pchMessage,uint32_t dwLength,uint16_t wCRC); +void Circle_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius); +void Rectangle_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); +void Float_Draw(Float_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float); +void Char_Draw(String_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y); +int Char_ReFresh(String_Data string_Data); +void Char_Write(String_Data *image,char* fmt, ...); +void Arc_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t x_Length,uint32_t y_Length); + + +#endif diff --git a/modules/referee/referee_def.h b/modules/referee/referee_def.h index 24c3e30..b632260 100644 --- a/modules/referee/referee_def.h +++ b/modules/referee/referee_def.h @@ -15,7 +15,7 @@ #pragma pack(1) -// 枚举类型,代替#define声明 +/* 通信协议格式偏移,枚举类型,代替#define声明 */ typedef enum { FRAME_HEADER = 0, @@ -23,7 +23,7 @@ typedef enum DATA = 7, } JudgeFrameOffset; -// 帧头偏移,枚举 +/* 帧头偏移 */ typedef enum { SOF = 0, // 起始位 @@ -32,7 +32,7 @@ typedef enum CRC8 = 4 // CRC8 } FrameHeaderOffset; -/* 自定义帧头 */ +/* 帧头定义 */ typedef struct { uint8_t SOF; @@ -41,7 +41,7 @@ typedef struct uint8_t CRC8; } xFrameHeader; -// 命令码ID,用来判断接收的是什么数据 +/* 命令码ID,用来判断接收的是什么数据 */ typedef enum { ID_game_state = 0x0001, // 比赛状态数据 @@ -60,7 +60,7 @@ typedef enum } CmdID; -// 命令码数据段长,根据官方协议来定义长度 +/* 命令码数据段长,根据官方协议来定义长度 */ typedef enum { LEN_game_state = 3, // 0x0001 From 8df0014a79c51af93a65c3b5b128c8baf3571a23 Mon Sep 17 00:00:00 2001 From: kidneygood <2979564623@qq.com> Date: Mon, 9 Jan 2023 21:50:17 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E5=BB=BA=E7=AB=8B=E9=80=9A=E4=BF=A1?= =?UTF-8?q?=EF=BC=8C=E9=AA=8C=E8=AF=81=E5=9B=BE=E5=BD=A2=E7=BB=98=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HAL_N_Middlewares/Src/main.c | 12 +- modules/referee/crc.c | 26 +- modules/referee/referee.c | 2 + modules/referee/referee_UI.c | 514 ++++++++++++++--------------------- modules/referee/referee_UI.h | 36 ++- 5 files changed, 246 insertions(+), 344 deletions(-) diff --git a/HAL_N_Middlewares/Src/main.c b/HAL_N_Middlewares/Src/main.c index 13aa79d..4c31f58 100644 --- a/HAL_N_Middlewares/Src/main.c +++ b/HAL_N_Middlewares/Src/main.c @@ -119,11 +119,15 @@ int main(void) ////////////////////////////////////////////////// - // Graph_Data shoot_line; + Graph_Data graph[5]; UI_Delete(UI_Data_Del_ALL,0); - // //绘制发射基准线 - // Line_Draw(&shoot_line,"s1",UI_Graph_ADD,7,UI_Color_White,3,710,540,1210,540); - // UI_ReFresh(1,shoot_line); + Line_Draw(&graph[0],"s0",UI_Graph_ADD,0,UI_Color_White,3,710,540,1210,540); + Rectangle_Draw(&graph[1],"s1",UI_Graph_ADD,1,UI_Color_Yellow,4,600,200,800,500); + Circle_Draw(&graph[2],"s2",UI_Graph_ADD,2,UI_Color_Green,5,960,540,100); + Elliptical_Draw(&graph[3],"s3",UI_Graph_ADD,3,UI_Color_Orange,3,960,540,100,20); + Arc_Draw(&graph[4],"s4",UI_Graph_ADD,4,UI_Color_Purplish_red,30,160,3,1200,550,50,100); + UI_ReFresh(5,graph[0],graph[1],graph[2],graph[3],graph[4]); + ////////////////////////////////////////////////// /* USER CODE END 2 */ diff --git a/modules/referee/crc.c b/modules/referee/crc.c index a0cd359..c16b938 100644 --- a/modules/referee/crc.c +++ b/modules/referee/crc.c @@ -136,20 +136,18 @@ void Append_CRC8_Check_Sum( uint8_t *pchMessage, uint16_t dwLength) */ uint16_t Get_CRC16_Check_Sum(uint8_t *pchMessage,uint32_t dwLength,uint16_t wCRC) { - uint8_t chData; - - if (pchMessage == NULL) - { - return 0xFFFF; - } - while(dwLength--) - { - chData = *pchMessage++; - (wCRC) = ((uint16_t)(wCRC) >> 8) ^ - wCRC_Table[((uint16_t)(wCRC) ^ (uint16_t)(chData)) & 0x00ff]; - } - - return wCRC; + uint8_t chData; + if (pchMessage == NULL) + { + return 0xFFFF; + } + while(dwLength--) + { + chData = *pchMessage++; + (wCRC) = ((uint16_t)(wCRC) >> 8) ^ + wCRC_Table[((uint16_t)(wCRC) ^ (uint16_t)(chData)) & 0x00ff]; + } + return wCRC; } diff --git a/modules/referee/referee.c b/modules/referee/referee.c index 7cc9679..96df982 100644 --- a/modules/referee/referee.c +++ b/modules/referee/referee.c @@ -33,6 +33,8 @@ referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle) void RefereeSend(uint8_t *send,uint16_t tx_len) { USARTSend(referee_usart_instance,send,tx_len); + /* syhtodo DMA请求过快会导致数据发送丢失,考虑数据尽可能打成一阵个包 */ + HAL_Delay(1); } diff --git a/modules/referee/referee_UI.c b/modules/referee/referee_UI.c index 6fbf7c1..994d5d3 100644 --- a/modules/referee/referee_UI.c +++ b/modules/referee/referee_UI.c @@ -10,11 +10,6 @@ uint16_t Robot_ID = UI_Data_RobotID_BHero; uint16_t Cilent_ID = UI_Data_CilentID_BHero; unsigned char UI_Seq; //包序号 -/****************************************串口驱动映射************************************/ -void UI_SendByte(unsigned char ch) -{ - HAL_UART_Transmit_DMA(&huart6,&ch,1); -} /********************************************删除操作************************************* **参数:Del_Operate 对应头文件删除操作 @@ -22,7 +17,7 @@ void UI_SendByte(unsigned char ch) *****************************************************************************************/ void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer) { - +/* syhtodo可化简,去掉读写指针 */ unsigned char *framepoint; //读写指针 uint16_t frametail=0xFFFF; //CRC16校验值 @@ -35,7 +30,7 @@ void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer) framehead.SOF=UI_SOF; framehead.Data_Length=8; framehead.Seq=UI_Seq; - framehead.CRC8=Get_CRC8_Check_Sum_UI(framepoint,4,0xFF); + framehead.CRC8=Get_CRC8_Check_Sum(framepoint,4,0xFF); framehead.CMD_ID=UI_CMD_Robo_Exchange; //填充包头数据 datahead.Data_ID=UI_Data_ID_Del; @@ -45,11 +40,11 @@ void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer) del.Delete_Operate=Del_Operate; del.Layer=Del_Layer; //控制信息 - frametail=Get_CRC16_Check_Sum_UI(framepoint,sizeof(framehead),frametail); + frametail=Get_CRC16_Check_Sum(framepoint,sizeof(framehead),frametail); framepoint=(unsigned char *)&datahead; - frametail=Get_CRC16_Check_Sum_UI(framepoint,sizeof(datahead),frametail); + frametail=Get_CRC16_Check_Sum(framepoint,sizeof(datahead),frametail); framepoint=(unsigned char *)&del; - frametail=Get_CRC16_Check_Sum_UI(framepoint,sizeof(del),frametail); //CRC16校验值计算 + frametail=Get_CRC16_Check_Sum(framepoint,sizeof(del),frametail); //CRC16校验值计算 RefereeSend((uint8_t *)&framehead,sizeof(framehead)); RefereeSend((uint8_t *)&datahead,sizeof(datahead)); @@ -59,150 +54,202 @@ void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer) UI_Seq++; //包序号+1 } /************************************************绘制直线************************************************* -**参数:*image Graph_Data类型变量指针,用于存放图形数据 - imagename[3] 图片名称,用于标识更改 +**参数:*graph Graph_Data类型变量指针,用于存放图形数据 + graphname[3] 图片名称,用于标识更改 Graph_Operate 图片操作,见头文件 Graph_Layer 图层0-9 Graph_Color 图形颜色 Graph_Width 图形线宽 - Start_x、Start_y 开始坐标 - End_x、End_y 结束坐标 + Start_x、Start_y 起点xy坐标 + End_x、End_y 终点xy坐标 **********************************************************************************************************/ -void Line_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y) +void Line_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y) { int i; - for(i=0;i<3&&imagename[i]!='\0';i++) - image->graphic_name[2-i]=imagename[i]; - image->operate_tpye = Graph_Operate; - image->layer = Graph_Layer; - image->color = Graph_Color; - image->width = Graph_Width; - image->start_x = Start_x; - image->start_y = Start_y; - image->end_x = End_x; - image->end_y = End_y; + //?????? + for(i=0;i<3&&graphname[i]!='\0';i++) + { + graph->graphic_name[2-i]=graphname[i]; + } + + graph->operate_tpye = Graph_Operate; + graph->graphic_tpye = UI_Graph_Line; + graph->layer = Graph_Layer; + graph->color = Graph_Color; + + graph->width = Graph_Width; + graph->start_x = Start_x; + graph->start_y = Start_y; + graph->end_x = End_x; + graph->end_y = End_y; } /************************************************绘制矩形************************************************* -**参数:*image Graph_Data类型变量指针,用于存放图形数据 - imagename[3] 图片名称,用于标识更改 +**参数:*graph Graph_Data类型变量指针,用于存放图形数据 + graphname[3] 图片名称,用于标识更改 Graph_Operate 图片操作,见头文件 Graph_Layer 图层0-9 Graph_Color 图形颜色 Graph_Width 图形线宽 - Start_x、Start_y 开始坐标 - End_x、End_y 结束坐标(对顶角坐标) -**********************************************************************************************************/ - -void Rectangle_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y) + Start_x、Start_y 起点xy坐标 + End_x、End_y 对角顶点xy坐标 +**********************************************************************************************************/ +void Rectangle_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y) { int i; - for(i=0;i<3&&imagename[i]!='\0';i++) - image->graphic_name[2-i]=imagename[i]; - image->graphic_tpye = UI_Graph_Rectangle; - image->operate_tpye = Graph_Operate; - image->layer = Graph_Layer; - image->color = Graph_Color; - image->width = Graph_Width; - image->start_x = Start_x; - image->start_y = Start_y; - image->end_x = End_x; - image->end_y = End_y; + for(i=0;i<3&&graphname[i]!='\0';i++) + { + graph->graphic_name[2-i]=graphname[i]; + } + + graph->graphic_tpye = UI_Graph_Rectangle; + graph->operate_tpye = Graph_Operate; + graph->layer = Graph_Layer; + graph->color = Graph_Color; + + graph->width = Graph_Width; + graph->start_x = Start_x; + graph->start_y = Start_y; + graph->end_x = End_x; + graph->end_y = End_y; } /************************************************绘制整圆************************************************* -**参数:*image Graph_Data类型变量指针,用于存放图形数据 - imagename[3] 图片名称,用于标识更改 +**参数:*graph Graph_Data类型变量指针,用于存放图形数据 + graphname[3] 图片名称,用于标识更改 Graph_Operate 图片操作,见头文件 Graph_Layer 图层0-9 Graph_Color 图形颜色 Graph_Width 图形线宽 - Start_x、Start_y 圆心坐标 - Graph_Radius 图形半径 + Start_x、Start_y 圆心xy坐标 + Graph_Radius 圆形半径 **********************************************************************************************************/ -void Circle_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius) +void Circle_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius) { int i; - for(i=0;i<3&&imagename[i]!='\0';i++) - image->graphic_name[2-i]=imagename[i]; - image->graphic_tpye = UI_Graph_Circle; - image->operate_tpye = Graph_Operate; - image->layer = Graph_Layer; - image->color = Graph_Color; - image->width = Graph_Width; - image->start_x = Start_x; - image->start_y = Start_y; - image->radius = Graph_Radius; -} + for(i=0;i<3&&graphname[i]!='\0';i++) + { + graph->graphic_name[2-i]=graphname[i]; + } -/************************************************绘制圆弧************************************************* -**参数:*image Graph_Data类型变量指针,用于存放图形数据 - imagename[3] 图片名称,用于标识更改 + graph->graphic_tpye = UI_Graph_Circle; + graph->operate_tpye = Graph_Operate; + graph->layer = Graph_Layer; + graph->color = Graph_Color; + + graph->width = Graph_Width; + graph->start_x = Start_x; + graph->start_y = Start_y; + graph->radius = Graph_Radius; +} +/************************************************绘制椭圆************************************************* +**参数:*graph Graph_Data类型变量指针,用于存放图形数据 + graphname[3] 图片名称,用于标识更改 Graph_Operate 图片操作,见头文件 Graph_Layer 图层0-9 Graph_Color 图形颜色 - Graph_StartAngle,Graph_EndAngle 开始,终止角度 - Graph_Width 图形线宽 - Start_y,Start_y 圆心坐标 - x_Length,y_Length x,y方向上轴长,参考椭圆 + Graph_Width 图形线宽 + Start_x、Start_y 圆心xy坐标 + End_x、End_y xy半轴长度 **********************************************************************************************************/ - -void Arc_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t x_Length,uint32_t y_Length) +void Elliptical_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y) { int i; - - for(i=0;i<3&&imagename[i]!='\0';i++) - image->graphic_name[2-i]=imagename[i]; - image->graphic_tpye = UI_Graph_Arc; - image->operate_tpye = Graph_Operate; - image->layer = Graph_Layer; - image->color = Graph_Color; - image->width = Graph_Width; - image->start_x = Start_x; - image->start_y = Start_y; - image->start_angle = Graph_StartAngle; - image->end_angle = Graph_EndAngle; - image->end_x = x_Length; - image->end_y = y_Length; + for(i=0;i<3&&graphname[i]!='\0';i++) + { + graph->graphic_name[2-i]=graphname[i]; + } + + graph->graphic_tpye = UI_Graph_Ellipse; + graph->operate_tpye = Graph_Operate; + graph->layer = Graph_Layer; + graph->color = Graph_Color; + graph->width = Graph_Width; + + graph->start_x = Start_x; + graph->start_y = Start_y; + graph->end_x = end_x; + graph->end_y = end_y; +} + + +/************************************************绘制圆弧************************************************* +**参数:*graph Graph_Data类型变量指针,用于存放图形数据 + graphname[3] 图片名称,用于标识更改 + Graph_Operate 图片操作,见头文件 + Graph_Layer 图层0-9 + Graph_Color 图形颜色 + Graph_StartAngle,Graph_EndAngle 起始终止角度 + Graph_Width 图形线宽 + Start_y,Start_y 圆心xy坐标 + x_Length,y_Length xy半轴长度 +**********************************************************************************************************/ + +void Arc_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y) +{ + int i; + for(i=0;i<3&&graphname[i]!='\0';i++) + { + graph->graphic_name[2-i]=graphname[i]; + } + + graph->graphic_tpye = UI_Graph_Arc; + graph->operate_tpye = Graph_Operate; + graph->layer = Graph_Layer; + graph->color = Graph_Color; + + graph->start_angle = Graph_StartAngle; + graph->end_angle = Graph_EndAngle; + graph->width = Graph_Width; + graph->start_x = Start_x; + graph->start_y = Start_y; + graph->end_x = end_x; + graph->end_y = end_y; } /************************************************绘制浮点型数据************************************************* -**参数:*image Graph_Data类型变量指针,用于存放图形数据 - imagename[3] 图片名称,用于标识更改 +**参数:*graph Graph_Data类型变量指针,用于存放图形数据 + graphname[3] 图片名称,用于标识更改 Graph_Operate 图片操作,见头文件 Graph_Layer 图层0-9 Graph_Color 图形颜色 Graph_Size 字号 Graph_Digit 小数位数 - Graph_Width 图形线宽 + Graph_Width 图形线宽 Start_x、Start_y 开始坐标 Graph_Float 要显示的浮点数数值*1000 **********************************************************************************************************/ - -void Float_Draw(Float_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float) +/* syhtodo浮点,整形,字符待编写或检查 */ +/* syhtodo需要解决位分配问腿,更换结构体 */ +void Float_Draw(Float_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float) { int i; - for(i=0;i<3&&imagename[i]!='\0';i++) - image->graphic_name[2-i]=imagename[i]; - image->graphic_tpye = UI_Graph_Float; - image->operate_tpye = Graph_Operate; - image->layer = Graph_Layer; - image->color = Graph_Color; - image->width = Graph_Width; - image->start_x = Start_x; - image->start_y = Start_y; - image->start_angle = Graph_Size; - image->end_angle = Graph_Digit; - image->graph_Float = Graph_Float; + for(i=0;i<3&&graphname[i]!='\0';i++) + graph->graphic_name[2-i]=graphname[i]; + graph->graphic_tpye = UI_Graph_Float; + graph->operate_tpye = Graph_Operate; + graph->layer = Graph_Layer; + graph->color = Graph_Color; + graph->width = Graph_Width; + graph->start_x = Start_x; + graph->start_y = Start_y; + graph->start_angle = Graph_Size; + graph->end_angle = Graph_Digit; + graph->graph_Float = Graph_Float; } /************************************************绘制字符型数据************************************************* -**参数:*image Graph_Data类型变量指针,用于存放图形数据 - imagename[3] 图片名称,用于标识更改 +**参数:*graph Graph_Data类型变量指针,用于存放图形数据 + graphname[3] 图片名称,用于标识更改 Graph_Operate 图片操作,见头文件 Graph_Layer 图层0-9 Graph_Color 图形颜色 @@ -210,61 +257,59 @@ void Float_Draw(Float_Data *image,char imagename[3],uint32_t Graph_Operate,uint3 Graph_Width 图形线宽 Start_x、Start_y 开始坐标 **********************************************************************************************************/ - -void Char_Draw(String_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y) + +void Char_Draw(String_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y) { int i; - for(i=0;i<3&&imagename[i]!='\0';i++) - image->Graph_Control.graphic_name[2-i]=imagename[i]; - image->Graph_Control.graphic_tpye = UI_Graph_Char; - image->Graph_Control.operate_tpye = Graph_Operate; - image->Graph_Control.layer = Graph_Layer; - image->Graph_Control.color = Graph_Color; - image->Graph_Control.width = Graph_Width; - image->Graph_Control.start_x = Start_x; - image->Graph_Control.start_y = Start_y; - image->Graph_Control.start_angle = Graph_Size; + for(i=0;i<3&&graphname[i]!='\0';i++) + graph->Graph_Control.graphic_name[2-i]=graphname[i]; + graph->Graph_Control.graphic_tpye = UI_Graph_Char; + graph->Graph_Control.operate_tpye = Graph_Operate; + graph->Graph_Control.layer = Graph_Layer; + graph->Graph_Control.color = Graph_Color; + graph->Graph_Control.width = Graph_Width; + graph->Graph_Control.start_x = Start_x; + graph->Graph_Control.start_y = Start_y; + graph->Graph_Control.start_angle = Graph_Size; } -void Char_Write(String_Data *image,char* fmt, ...) +void Char_Write(String_Data *graph,char* fmt, ...) { uint16_t i = 0; va_list ap; va_start(ap, fmt); - vsprintf((char*)image->show_Data, fmt, ap); + vsprintf((char*)graph->show_Data, fmt, ap); va_end(ap); - i = strlen((const char*)image->show_Data); - image->Graph_Control.end_angle = i; + i = strlen((const char*)graph->show_Data); + graph->Graph_Control.end_angle = i; } /************************************************UI推送函数(使更改生效)********************************* **参数: cnt 图形个数 ... 图形变量参数 - - Tips::该函数只能推送1,2,5,7个图形,其他数目协议未涉及 **********************************************************************************************************/ int UI_ReFresh(int cnt,...) { - int i,n; - Graph_Data imageData; + int i; + UI_Packhead framehead; + UI_Data_Operate datahead; + Graph_Data graphData; + unsigned char *framepoint; //读写指针 uint16_t frametail=0xFFFF; //CRC16校验值 - UI_Packhead framehead; - UI_Data_Operate datahead; - - va_list ap; - va_start(ap,cnt); + va_list ap;//创建一个 va_list 类型变量 + va_start(ap,cnt);//初始化 va_list 变量为一个参数列表 framepoint=(unsigned char *)&framehead; framehead.SOF=UI_SOF; framehead.Data_Length=6+cnt*15; framehead.Seq=UI_Seq; - framehead.CRC8=Get_CRC8_Check_Sum_UI(framepoint,4,0xFF); + framehead.CRC8=Get_CRC8_Check_Sum(framepoint,4,0xFF); framehead.CMD_ID=UI_CMD_Robo_Exchange; //填充包头数据 - switch(cnt) + switch(cnt) //syhtodo可以直接计算式解决 { case 1: datahead.Data_ID=UI_Data_ID_Draw1; @@ -285,226 +330,69 @@ int UI_ReFresh(int cnt,...) datahead.Receiver_ID=Cilent_ID; //填充操作数据 framepoint=(unsigned char *)&framehead; - frametail=Get_CRC16_Check_Sum_UI(framepoint,sizeof(framehead),frametail); + frametail=Get_CRC16_Check_Sum(framepoint,sizeof(framehead),frametail); framepoint=(unsigned char *)&datahead; - frametail=Get_CRC16_Check_Sum_UI(framepoint,sizeof(datahead),frametail); //CRC16校验值计算(部分) + frametail=Get_CRC16_Check_Sum(framepoint,sizeof(datahead),frametail); //CRC16校验值计算(部分) - framepoint=(unsigned char *)&framehead; - for(i=0;i> 8) ^ wCRC_Table_UI[((uint16_t)(wCRC) ^ (uint16_t)(chData)) & - 0x00ff]; - } - return wCRC; -} - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/modules/referee/referee_UI.h b/modules/referee/referee_UI.h index 0efa2e2..e6b1712 100644 --- a/modules/referee/referee_UI.h +++ b/modules/referee/referee_UI.h @@ -112,7 +112,7 @@ typedef struct uint8_t Layer; //删除图层 } UI_Data_Delete; //删除图层帧 - +/* 是否有必要专门为浮点数定义?? */ typedef struct { uint8_t graphic_name[3]; @@ -125,10 +125,15 @@ typedef struct uint32_t width:10; uint32_t start_x:11; uint32_t start_y:11; - int32_t graph_Float; //浮点数据 + int32_t graph_Float; + /* syhtodo + uint32_t 正好对应 + radius:10; uint32_t end_x:11; uint32_t end_y:11; + 三个变量,考虑位操作赋值,则不需要专门定义结构体 + */ } Float_Data; - +/* 图形数据 */ typedef struct { uint8_t graphic_name[3]; @@ -143,7 +148,7 @@ uint32_t start_x:11; uint32_t start_y:11; uint32_t radius:10; uint32_t end_x:11; -uint32_t end_y:11; //图形数据 +uint32_t end_y:11; } Graph_Data; @@ -156,17 +161,22 @@ typedef struct #pragma pack() void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer); -void Line_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); +void Line_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); + + +void Circle_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius); +void Elliptical_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y); +void Rectangle_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); +void Float_Draw(Float_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float); +void Char_Draw(String_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y); + +void Char_Write(String_Data *graph,char* fmt, ...); +void Arc_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y); +int Char_ReFresh(String_Data string_Data); int UI_ReFresh(int cnt,...); + + unsigned char Get_CRC8_Check_Sum_UI(unsigned char *pchMessage,unsigned int dwLength,unsigned char ucCRC8); uint16_t Get_CRC16_Check_Sum_UI(uint8_t *pchMessage,uint32_t dwLength,uint16_t wCRC); -void Circle_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius); -void Rectangle_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); -void Float_Draw(Float_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float); -void Char_Draw(String_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y); -int Char_ReFresh(String_Data string_Data); -void Char_Write(String_Data *image,char* fmt, ...); -void Arc_Draw(Graph_Data *image,char imagename[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t x_Length,uint32_t y_Length); - #endif From 85a97abb9d43390e497ee98f47b2498383c4fdf5 Mon Sep 17 00:00:00 2001 From: kidneygood <2979564623@qq.com> Date: Thu, 12 Jan 2023 15:24:56 +0800 Subject: [PATCH 04/15] =?UTF-8?q?=E5=AD=97=E7=AC=A6=E7=BB=98=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HAL_N_Middlewares/Src/main.c | 21 +++++-- application/gimbal/gimbal.c | 4 +- modules/referee/referee.c | 2 +- modules/referee/referee_UI.c | 118 +++++++++++++++++++++++++---------- modules/referee/referee_UI.h | 56 ++++------------- 5 files changed, 115 insertions(+), 86 deletions(-) diff --git a/HAL_N_Middlewares/Src/main.c b/HAL_N_Middlewares/Src/main.c index 4c31f58..662fda8 100644 --- a/HAL_N_Middlewares/Src/main.c +++ b/HAL_N_Middlewares/Src/main.c @@ -120,13 +120,24 @@ int main(void) ////////////////////////////////////////////////// Graph_Data graph[5]; + Graph_Data num[2]; + String_Data sdata[1]; + memset(sdata[0].show_Data, 0, 30); //使用memset方法 UI_Delete(UI_Data_Del_ALL,0); + Line_Draw(&graph[0],"s0",UI_Graph_ADD,0,UI_Color_White,3,710,540,1210,540); - Rectangle_Draw(&graph[1],"s1",UI_Graph_ADD,1,UI_Color_Yellow,4,600,200,800,500); - Circle_Draw(&graph[2],"s2",UI_Graph_ADD,2,UI_Color_Green,5,960,540,100); - Elliptical_Draw(&graph[3],"s3",UI_Graph_ADD,3,UI_Color_Orange,3,960,540,100,20); - Arc_Draw(&graph[4],"s4",UI_Graph_ADD,4,UI_Color_Purplish_red,30,160,3,1200,550,50,100); - UI_ReFresh(5,graph[0],graph[1],graph[2],graph[3],graph[4]); + Rectangle_Draw(&graph[1],"s1",UI_Graph_ADD,0,UI_Color_Yellow,4,600,200,800,500); + Circle_Draw(&graph[2],"s2",UI_Graph_ADD,0,UI_Color_Green,5,960,540,100); + Elliptical_Draw(&graph[3],"s3",UI_Graph_ADD,0,UI_Color_Orange,3,960,540,100,20); + Arc_Draw(&graph[4],"s4",UI_Graph_ADD,0,UI_Color_Purplish_red,30,160,3,1200,550,50,100); + + Float_Draw(&num[0],"s5",UI_Graph_ADD,0,UI_Color_Pink,50,3,5,1050,660,111111111); + Integer_Draw(&num[1],"s6",UI_Graph_ADD,0,UI_Color_Cyan,50,5,1050,460,12345); + UI_ReFresh(7,graph[0],graph[1],graph[2],graph[3],graph[4],num[0],num[1]); + + Char_Draw(&sdata[0],"s7",UI_Graph_ADD,0,UI_Color_Green,20,2,620,710); + Char_Write(&sdata[0],"number:%d",1234); + Char_ReFresh(sdata[0]); ////////////////////////////////////////////////// diff --git a/application/gimbal/gimbal.c b/application/gimbal/gimbal.c index 6081847..c193e87 100644 --- a/application/gimbal/gimbal.c +++ b/application/gimbal/gimbal.c @@ -16,7 +16,9 @@ static Gimbal_Ctrl_Cmd_s gimbal_cmd_recv; // 来自cmd的控制信息 void GimbalInit() { - gimba_IMU_data = INS_Init(); // IMU先初始化,获取姿态数据指针赋给yaw电机的其他数据来源 + /* syh referee不需要imu + 暂时关闭以加快初始化速度 */ + // gimba_IMU_data = INS_Init(); // IMU先初始化,获取姿态数据指针赋给yaw电机的其他数据来源 // YAW Motor_Init_Config_s yaw_config = { diff --git a/modules/referee/referee.c b/modules/referee/referee.c index 96df982..c486ddc 100644 --- a/modules/referee/referee.c +++ b/modules/referee/referee.c @@ -34,7 +34,7 @@ void RefereeSend(uint8_t *send,uint16_t tx_len) { USARTSend(referee_usart_instance,send,tx_len); /* syhtodo DMA请求过快会导致数据发送丢失,考虑数据尽可能打成一阵个包 */ - HAL_Delay(1); + HAL_Delay(5); } diff --git a/modules/referee/referee_UI.c b/modules/referee/referee_UI.c index 994d5d3..5f1b5dc 100644 --- a/modules/referee/referee_UI.c +++ b/modules/referee/referee_UI.c @@ -5,11 +5,11 @@ #include "dma.h" #include "stdio.h" #include "referee.h" - +/* syhtodo 根据自身id判断客户端id */ uint16_t Robot_ID = UI_Data_RobotID_BHero; uint16_t Cilent_ID = UI_Data_CilentID_BHero; -unsigned char UI_Seq; //包序号 +uint8_t UI_Seq; //包序号 /********************************************删除操作************************************* **参数:Del_Operate 对应头文件删除操作 @@ -192,7 +192,8 @@ void Elliptical_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate, **********************************************************************************************************/ void Arc_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y) + uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y, + uint32_t end_x,uint32_t end_y) { int i; for(i=0;i<3&&graphname[i]!='\0';i++) @@ -214,8 +215,6 @@ void Arc_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_ graph->end_y = end_y; } - - /************************************************绘制浮点型数据************************************************* **参数:*graph Graph_Data类型变量指针,用于存放图形数据 graphname[3] 图片名称,用于标识更改 @@ -226,69 +225,129 @@ void Arc_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_ Graph_Digit 小数位数 Graph_Width 图形线宽 Start_x、Start_y 开始坐标 - Graph_Float 要显示的浮点数数值*1000 + radius=a&0x3FF; a为浮点数乘以1000后的32位整型数 + end_x=(a>>10)&0x7FF; + end_y=(a>>21)&0x7FF; **********************************************************************************************************/ -/* syhtodo浮点,整形,字符待编写或检查 */ -/* syhtodo需要解决位分配问腿,更换结构体 */ -void Float_Draw(Float_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float) + +void Float_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float) { - int i; + int i; for(i=0;i<3&&graphname[i]!='\0';i++) + { graph->graphic_name[2-i]=graphname[i]; + } graph->graphic_tpye = UI_Graph_Float; graph->operate_tpye = Graph_Operate; graph->layer = Graph_Layer; graph->color = Graph_Color; + graph->width = Graph_Width; graph->start_x = Start_x; graph->start_y = Start_y; graph->start_angle = Graph_Size; graph->end_angle = Graph_Digit; - graph->graph_Float = Graph_Float; + + graph->radius=Graph_Float&0x3FF; + graph->end_x=(Graph_Float>>10)&0x7FF; + graph->end_y=(Graph_Float>>21)&0x7FF; } +/************************************************绘制整型数据************************************************* +**参数:*graph Graph_Data类型变量指针,用于存放图形数据 + graphname[3] 图片名称,用于标识更改 + Graph_Operate 图片操作,见头文件 + Graph_Layer 图层0-9 + Graph_Color 图形颜色 + Graph_Size 字号 + Graph_Width 图形线宽 + Start_x、Start_y 开始坐标 + radius=a&0x3FF; a为32位整型数 + end_x=(a>>10)&0x7FF; + end_y=(a>>21)&0x7FF; +**********************************************************************************************************/ +void Integer_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Integer) +{ + int i; + for(i=0;i<3&&graphname[i]!='\0';i++) + { + graph->graphic_name[2-i]=graphname[i]; + } + graph->graphic_tpye = UI_Graph_Int; + graph->operate_tpye = Graph_Operate; + graph->layer = Graph_Layer; + graph->color = Graph_Color; + + graph->start_angle = Graph_Size; + graph->width = Graph_Width; + graph->start_x = Start_x; + graph->start_y = Start_y; + + graph->radius=Graph_Integer&0x3FF; + graph->end_x=(Graph_Integer>>10)&0x7FF; + graph->end_y=(Graph_Integer>>21)&0x7FF; +} + + /************************************************绘制字符型数据************************************************* **参数:*graph Graph_Data类型变量指针,用于存放图形数据 graphname[3] 图片名称,用于标识更改 Graph_Operate 图片操作,见头文件 Graph_Layer 图层0-9 Graph_Color 图形颜色 - Graph_Size 字号 + Graph_Size 字号 Graph_Width 图形线宽 Start_x、Start_y 开始坐标 -**********************************************************************************************************/ - -void Char_Draw(String_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y) -{ - int i; +**********************************************************************************************************/ +void Char_Draw(String_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y) +{ + memset(graph->Graph_Control.graphic_name, 0, 3); + int i; for(i=0;i<3&&graphname[i]!='\0';i++) - graph->Graph_Control.graphic_name[2-i]=graphname[i]; + { + graph->Graph_Control.graphic_name[2-i]=graphname[i]; + } + graph->Graph_Control.graphic_tpye = UI_Graph_Char; graph->Graph_Control.operate_tpye = Graph_Operate; graph->Graph_Control.layer = Graph_Layer; graph->Graph_Control.color = Graph_Color; + graph->Graph_Control.width = Graph_Width; graph->Graph_Control.start_x = Start_x; graph->Graph_Control.start_y = Start_y; graph->Graph_Control.start_angle = Graph_Size; + + //syhtodo无关的赋值为0 + graph->Graph_Control.radius=0; + graph->Graph_Control.end_x=0; + graph->Graph_Control.end_y=0; } +/************************************************绘制字符型数据************************************************* +**参数:*graph Graph_Data类型变量指针,用于存放图形数据 + fmt需要显示的字符串 +syhtodo 尚未理解该函数的写法 +**********************************************************************************************************/ void Char_Write(String_Data *graph,char* fmt, ...) { uint16_t i = 0; va_list ap; - va_start(ap, fmt); + va_start(ap,fmt); vsprintf((char*)graph->show_Data, fmt, ap); va_end(ap); i = strlen((const char*)graph->show_Data); graph->Graph_Control.end_angle = i; } -/************************************************UI推送函数(使更改生效)********************************* -**参数: cnt 图形个数 - ... 图形变量参数 -Tips::该函数只能推送1,2,5,7个图形,其他数目协议未涉及 -**********************************************************************************************************/ +/* UI推送函数(使更改生效) + 参数: cnt 图形个数 + ... 图形变量参数 + Tips::该函数只能推送1,2,5,7个图形,其他数目协议未涉及 + */ int UI_ReFresh(int cnt,...) { int i; @@ -386,7 +445,6 @@ int Char_ReFresh(String_Data string_Data) RefereeSend((uint8_t *)&framehead,sizeof(framehead)); RefereeSend((uint8_t *)&datahead,sizeof(datahead)); - RefereeSend((uint8_t *)&graphData,sizeof(graphData)); //发送操作数据 RefereeSend((uint8_t *)&frametail,sizeof(frametail)); //发送CRC16校验值 @@ -394,14 +452,6 @@ int Char_ReFresh(String_Data string_Data) return 0; } - - -// /** -// * @brief 上传自定义数据 -// * @param void -// * @retval void -// * @attention 数据打包,打包完成后通过串口发送到裁判系统 -// */ // #define send_max_len 200 // unsigned char CliendTxBuffer[send_max_len]; // void JUDGE_Show_Data(void) @@ -417,7 +467,7 @@ int Char_ReFresh(String_Data string_Data) // ShowData.txFrameHeader.DataLength = sizeof(ext_student_interactive_header_data_t) + sizeof(client_custom_data_t); // ShowData.txFrameHeader.Seq = 0; // memcpy(CliendTxBuffer, &ShowData.txFrameHeader, sizeof(xFrameHeader));//写入帧头数据 -// Append_CRC8_Check_Sum(CliendTxBuffer, sizeof(xFrameHeader));//写入帧头CRC8校验码 +// Append_CRC8_Check_Sum(CliendTxBuffer, sizeof(xFrameHeader));//写入帧头CRC8校验码 // ShowData.CmdID = 0x0301; diff --git a/modules/referee/referee_UI.h b/modules/referee/referee_UI.h index e6b1712..1b72fb9 100644 --- a/modules/referee/referee_UI.h +++ b/modules/referee/referee_UI.h @@ -55,7 +55,7 @@ /***************************删除操作***************************/ #define UI_Data_Del_NoOperate 0 #define UI_Data_Del_Layer 1 -#define UI_Data_Del_ALL 2 +#define UI_Data_Del_ALL 2 //删除全部图层,后面的参数已经不重要了。 /***************************图形配置参数__图形操作********************/ #define UI_Graph_ADD 1 #define UI_Graph_Change 2 @@ -80,16 +80,6 @@ #define UI_Color_Black 7 #define UI_Color_White 8 - - -typedef unsigned char Uint8_t; -typedef unsigned char uint8_t; - -extern uint16_t Robot_ID; -extern uint16_t Cilent_ID; - - - typedef struct { uint8_t SOF; //起始字节,固定0xA5 @@ -112,7 +102,7 @@ typedef struct uint8_t Layer; //删除图层 } UI_Data_Delete; //删除图层帧 -/* 是否有必要专门为浮点数定义?? */ +/* 图形数据 */ typedef struct { uint8_t graphic_name[3]; @@ -125,30 +115,9 @@ typedef struct uint32_t width:10; uint32_t start_x:11; uint32_t start_y:11; - int32_t graph_Float; - /* syhtodo - uint32_t 正好对应 - radius:10; uint32_t end_x:11; uint32_t end_y:11; - 三个变量,考虑位操作赋值,则不需要专门定义结构体 - */ -} Float_Data; - -/* 图形数据 */ -typedef struct -{ -uint8_t graphic_name[3]; -uint32_t operate_tpye:3; -uint32_t graphic_tpye:3; -uint32_t layer:4; -uint32_t color:4; -uint32_t start_angle:9; -uint32_t end_angle:9; -uint32_t width:10; -uint32_t start_x:11; -uint32_t start_y:11; -uint32_t radius:10; -uint32_t end_x:11; -uint32_t end_y:11; + uint32_t radius:10; + uint32_t end_x:11; + uint32_t end_y:11; } Graph_Data; @@ -161,22 +130,19 @@ typedef struct #pragma pack() void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer); + void Line_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); - - void Circle_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius); void Elliptical_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y); void Rectangle_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); -void Float_Draw(Float_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float); -void Char_Draw(String_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y); - -void Char_Write(String_Data *graph,char* fmt, ...); void Arc_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y); -int Char_ReFresh(String_Data string_Data); +void Float_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float); +void Integer_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Integer); int UI_ReFresh(int cnt,...); -unsigned char Get_CRC8_Check_Sum_UI(unsigned char *pchMessage,unsigned int dwLength,unsigned char ucCRC8); -uint16_t Get_CRC16_Check_Sum_UI(uint8_t *pchMessage,uint32_t dwLength,uint16_t wCRC); +void Char_Draw(String_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y); +void Char_Write(String_Data *graph,char* fmt, ...); +int Char_ReFresh(String_Data string_Data); #endif From 9b16407b5733f92df0bf1ea2f7d3591be359830f Mon Sep 17 00:00:00 2001 From: kidneygood <2979564623@qq.com> Date: Thu, 12 Jan 2023 16:11:40 +0800 Subject: [PATCH 05/15] =?UTF-8?q?referee.h=E6=96=87=E4=BB=B6=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E6=9E=9A=E4=B8=BE=E6=95=B4=E5=90=88=E8=87=B3=5Fdef.h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HAL_N_Middlewares/Src/main.c | 8 +- application/chassis/chassis.c | 4 +- modules/referee/referee.c | 27 +++--- modules/referee/referee.h | 129 +---------------------------- modules/referee/referee_def.h | 152 +++++++++++++++++++++++++++++++++- 5 files changed, 167 insertions(+), 153 deletions(-) diff --git a/HAL_N_Middlewares/Src/main.c b/HAL_N_Middlewares/Src/main.c index 662fda8..1f0cc0c 100644 --- a/HAL_N_Middlewares/Src/main.c +++ b/HAL_N_Middlewares/Src/main.c @@ -33,7 +33,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "robot.h" -////////////////////////////////////////////////// +//////////////////////////////////////////////////syhtodo #include "referee_UI.h" #include "referee.h" ////////////////////////////////////////////////// @@ -118,11 +118,11 @@ int main(void) RobotInit(); -////////////////////////////////////////////////// +//////////////////////////////////////////////////syhtodo Graph_Data graph[5]; Graph_Data num[2]; String_Data sdata[1]; - memset(sdata[0].show_Data, 0, 30); //使用memset方法 + memset(sdata[0].show_Data, 0, 30); //使用memset方法 syhtodo 数据存在初始化未默认为0的情况 UI_Delete(UI_Data_Del_ALL,0); Line_Draw(&graph[0],"s0",UI_Graph_ADD,0,UI_Color_White,3,710,540,1210,540); @@ -136,7 +136,7 @@ int main(void) UI_ReFresh(7,graph[0],graph[1],graph[2],graph[3],graph[4],num[0],num[1]); Char_Draw(&sdata[0],"s7",UI_Graph_ADD,0,UI_Color_Green,20,2,620,710); - Char_Write(&sdata[0],"number:%d",1234); + Char_Write(&sdata[0],"number:%d",12345); Char_ReFresh(sdata[0]); ////////////////////////////////////////////////// diff --git a/application/chassis/chassis.c b/application/chassis/chassis.c index 55625a1..75ede1f 100644 --- a/application/chassis/chassis.c +++ b/application/chassis/chassis.c @@ -238,9 +238,9 @@ void ChassisTask() // 获取裁判系统数据 // 我方颜色id小于7是红色,大于7是蓝色,注意这里发送的是对方的颜色, 0:blue , 1:red - chassis_feedback_data.enemy_color = referee_data->GameRobotStat.robot_id > 7 ? 1 : 0; + chassis_feedback_data.enemy_color = referee_data->GameRobotState.robot_id > 7 ? 1 : 0; // 当前只做了17mm热量的数据获取,后续根据robot_def中的宏切换双枪管和英雄42mm的情况 - chassis_feedback_data.bullet_speed = referee_data->GameRobotStat.shooter_id1_17mm_speed_limit; + chassis_feedback_data.bullet_speed = referee_data->GameRobotState.shooter_id1_17mm_speed_limit; chassis_feedback_data.rest_heat = referee_data->PowerHeatData.shooter_heat0; // 推送反馈消息 diff --git a/modules/referee/referee.c b/modules/referee/referee.c index c486ddc..0caeaaa 100644 --- a/modules/referee/referee.c +++ b/modules/referee/referee.c @@ -11,9 +11,6 @@ static referee_info_t referee_info; static void JudgeReadData(uint8_t *ReadFromUsart); static void RefereeRxCallback(); -// static uint8_t Judge_Self_ID; // 当前机器人的ID -// static uint16_t Judge_SelfClient_ID; // 发送者机器人对应的客户端ID - /* 裁判系统通信初始化 */ referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle) { @@ -77,50 +74,50 @@ static void JudgeReadData(uint8_t *ReadFromUsart) switch (referee_info.CmdID) { case ID_game_state: // 0x0001 - memcpy(&referee_info.GameState, (ReadFromUsart + DATA), LEN_game_state); + memcpy(&referee_info.GameState, (ReadFromUsart + DATA_Offset), LEN_game_state); break; case ID_game_result: // 0x0002 - memcpy(&referee_info.GameResult, (ReadFromUsart + DATA), LEN_game_result); + memcpy(&referee_info.GameResult, (ReadFromUsart + DATA_Offset), LEN_game_result); break; case ID_game_robot_survivors: // 0x0003 - memcpy(&referee_info.GameRobotHP, (ReadFromUsart + DATA), LEN_game_robot_HP); + memcpy(&referee_info.GameRobotHP, (ReadFromUsart + DATA_Offset), LEN_game_robot_HP); break; case ID_event_data: // 0x0101 - memcpy(&referee_info.EventData, (ReadFromUsart + DATA), LEN_event_data); + memcpy(&referee_info.EventData, (ReadFromUsart + DATA_Offset), LEN_event_data); break; case ID_supply_projectile_action: // 0x0102 - memcpy(&referee_info.SupplyProjectileAction, (ReadFromUsart + DATA), LEN_supply_projectile_action); + memcpy(&referee_info.SupplyProjectileAction, (ReadFromUsart + DATA_Offset), LEN_supply_projectile_action); break; case ID_game_robot_state: // 0x0201 - memcpy(&referee_info.GameRobotStat, (ReadFromUsart + DATA), LEN_game_robot_state); + memcpy(&referee_info.GameRobotState, (ReadFromUsart + DATA_Offset), LEN_game_robot_state); break; case ID_power_heat_data: // 0x0202 - memcpy(&referee_info.PowerHeatData, (ReadFromUsart + DATA), LEN_power_heat_data); + memcpy(&referee_info.PowerHeatData, (ReadFromUsart + DATA_Offset), LEN_power_heat_data); break; case ID_game_robot_pos: // 0x0203 - memcpy(&referee_info.GameRobotPos, (ReadFromUsart + DATA), LEN_game_robot_pos); + memcpy(&referee_info.GameRobotPos, (ReadFromUsart + DATA_Offset), LEN_game_robot_pos); break; case ID_buff_musk: // 0x0204 - memcpy(&referee_info.BuffMusk, (ReadFromUsart + DATA), LEN_buff_musk); + memcpy(&referee_info.BuffMusk, (ReadFromUsart + DATA_Offset), LEN_buff_musk); break; case ID_aerial_robot_energy: // 0x0205 - memcpy(&referee_info.AerialRobotEnergy, (ReadFromUsart + DATA), LEN_aerial_robot_energy); + memcpy(&referee_info.AerialRobotEnergy, (ReadFromUsart + DATA_Offset), LEN_aerial_robot_energy); break; case ID_robot_hurt: // 0x0206 - memcpy(&referee_info.RobotHurt, (ReadFromUsart + DATA), LEN_robot_hurt); + memcpy(&referee_info.RobotHurt, (ReadFromUsart + DATA_Offset), LEN_robot_hurt); break; case ID_shoot_data: // 0x0207 - memcpy(&referee_info.ShootData, (ReadFromUsart + DATA), LEN_shoot_data); + memcpy(&referee_info.ShootData, (ReadFromUsart + DATA_Offset), LEN_shoot_data); // JUDGE_ShootNumCount();//发弹量统计 break; } diff --git a/modules/referee/referee.h b/modules/referee/referee.h index 3ed201f..377129b 100644 --- a/modules/referee/referee.h +++ b/modules/referee/referee.h @@ -23,135 +23,8 @@ #define JUDGE_DATA_ERROR 0 #define JUDGE_DATA_CORRECT 1 -#define LEN_HEADER 5 // 帧头长 -#define LEN_CMDID 2 // 命令码长度 -#define LEN_TAIL 2 // 帧尾CRC16 - -// 起始字节,协议固定为0xA5 -#define JUDGE_FRAME_HEADER (0xA5) - #pragma pack(1) -/* ID: 0x0001 Byte: 3 比赛状态数据 */ -typedef struct -{ - uint8_t game_type : 4; - uint8_t game_progress : 4; - uint16_t stage_remain_time; -} ext_game_state_t; - -/* ID: 0x0002 Byte: 1 比赛结果数据 */ -typedef struct -{ - uint8_t winner; -} ext_game_result_t; - -/* ID: 0x0003 Byte: 32 比赛机器人血量数据 */ -typedef struct -{ - uint16_t red_1_robot_HP; - uint16_t red_2_robot_HP; - uint16_t red_3_robot_HP; - uint16_t red_4_robot_HP; - uint16_t red_5_robot_HP; - uint16_t red_7_robot_HP; - uint16_t red_outpost_HP; - uint16_t red_base_HP; - uint16_t blue_1_robot_HP; - uint16_t blue_2_robot_HP; - uint16_t blue_3_robot_HP; - uint16_t blue_4_robot_HP; - uint16_t blue_5_robot_HP; - uint16_t blue_7_robot_HP; - uint16_t blue_outpost_HP; - uint16_t blue_base_HP; -} ext_game_robot_HP_t; - -/* ID: 0x0101 Byte: 4 场地事件数据 */ -typedef struct -{ - uint32_t event_type; -} ext_event_data_t; - -/* ID: 0x0102 Byte: 3 场地补给站动作标识数据 */ -typedef struct -{ - uint8_t supply_projectile_id; - uint8_t supply_robot_id; - uint8_t supply_projectile_step; - uint8_t supply_projectile_num; -} ext_supply_projectile_action_t; - -/* ID: 0X0201 Byte: 27 机器人状态数据 */ -typedef struct -{ - uint8_t robot_id; - uint8_t robot_level; - uint16_t remain_HP; - uint16_t max_HP; - uint16_t shooter_id1_17mm_cooling_rate; - uint16_t shooter_id1_17mm_cooling_limit; - uint16_t shooter_id1_17mm_speed_limit; - uint16_t shooter_id2_17mm_cooling_rate; - uint16_t shooter_id2_17mm_cooling_limit; - uint16_t shooter_id2_17mm_speed_limit; - uint16_t shooter_id1_42mm_cooling_rate; - uint16_t shooter_id1_42mm_cooling_limit; - uint16_t shooter_id1_42mm_speed_limit; - uint16_t chassis_power_limit; - uint8_t mains_power_gimbal_output : 1; - uint8_t mains_power_chassis_output : 1; - uint8_t mains_power_shooter_output : 1; -} ext_game_robot_state_t; - -/* ID: 0X0202 Byte: 14 实时功率热量数据 */ -typedef struct -{ - uint16_t chassis_volt; - uint16_t chassis_current; - float chassis_power; // 瞬时功率 - uint16_t chassis_power_buffer; // 60焦耳缓冲能量 - uint16_t shooter_heat0; // 17mm - uint16_t shooter_heat1; -} ext_power_heat_data_t; - -/* ID: 0x0203 Byte: 16 机器人位置数据 */ -typedef struct -{ - float x; - float y; - float z; - float yaw; -} ext_game_robot_pos_t; - -/* ID: 0x0204 Byte: 1 机器人增益数据 */ -typedef struct -{ - uint8_t power_rune_buff; -} ext_buff_musk_t; - -/* ID: 0x0205 Byte: 1 空中机器人能量状态数据 */ -typedef struct -{ - uint8_t attack_time; -} aerial_robot_energy_t; - -/* ID: 0x0206 Byte: 1 伤害状态数据 */ -typedef struct -{ - uint8_t armor_id : 4; - uint8_t hurt_type : 4; -} ext_robot_hurt_t; - -/* ID: 0x0207 Byte: 7 实时射击数据 */ -typedef struct -{ - uint8_t bullet_type; - uint8_t shooter_id; - uint8_t bullet_freq; - float bullet_speed; -} ext_shoot_data_t; - // 裁判系统接收数据整合进一个结构体 typedef struct { @@ -162,7 +35,7 @@ typedef struct ext_game_robot_HP_t GameRobotHP; // 0x0003 ext_event_data_t EventData; // 0x0101 ext_supply_projectile_action_t SupplyProjectileAction; // 0x0102 - ext_game_robot_state_t GameRobotStat; // 0x0201 + ext_game_robot_state_t GameRobotState; // 0x0201 ext_power_heat_data_t PowerHeatData; // 0x0202 ext_game_robot_pos_t GameRobotPos; // 0x0203 ext_buff_musk_t BuffMusk; // 0x0204 diff --git a/modules/referee/referee_def.h b/modules/referee/referee_def.h index b632260..096cbb9 100644 --- a/modules/referee/referee_def.h +++ b/modules/referee/referee_def.h @@ -15,14 +15,30 @@ #pragma pack(1) +/****************************通信协议格式****************************/ +/****************************通信协议格式****************************/ + /* 通信协议格式偏移,枚举类型,代替#define声明 */ typedef enum { - FRAME_HEADER = 0, - CMD_ID = 5, - DATA = 7, + FRAME_HEADER_Offset = 0, + CMD_ID_Offset = 5, + DATA_Offset = 7, } JudgeFrameOffset; +/* 通信协议长度 */ +typedef enum +{ + LEN_HEADER = 5, // 帧头长 + LEN_CMDID = 2, // 命令码长度 + LEN_TAIL = 2, // 帧尾CRC16 +} JudgeFrameLength; + +/****************************帧头****************************/ +/****************************帧头****************************/ + +#define JUDGE_FRAME_HEADER (0xA5) // 起始字节,协议固定为0xA5 + /* 帧头偏移 */ typedef enum { @@ -41,6 +57,10 @@ typedef struct uint8_t CRC8; } xFrameHeader; + +/****************************cmd_id命令码说明****************************/ +/****************************cmd_id命令码说明****************************/ + /* 命令码ID,用来判断接收的是什么数据 */ typedef enum { @@ -57,7 +77,7 @@ typedef enum ID_aerial_robot_energy = 0x0205, // 空中机器人能量状态数据 ID_robot_hurt = 0x0206, // 伤害状态数据 ID_shoot_data = 0x0207, // 实时射击数据 - + ID_student_interactive = 0x0301, // 机器人间交互数据 } CmdID; /* 命令码数据段长,根据官方协议来定义长度 */ @@ -77,6 +97,130 @@ typedef enum LEN_shoot_data = 7, // 0x0207 } JudgeDataLength; +/****************************接收数据的详细说明****************************/ +/****************************接收数据的详细说明****************************/ + +/* ID: 0x0001 Byte: 3 比赛状态数据 */ +typedef struct +{ + uint8_t game_type : 4; + uint8_t game_progress : 4; + uint16_t stage_remain_time; +} ext_game_state_t; + +/* ID: 0x0002 Byte: 1 比赛结果数据 */ +typedef struct +{ + uint8_t winner; +} ext_game_result_t; + +/* ID: 0x0003 Byte: 32 比赛机器人血量数据 */ +typedef struct +{ + uint16_t red_1_robot_HP; + uint16_t red_2_robot_HP; + uint16_t red_3_robot_HP; + uint16_t red_4_robot_HP; + uint16_t red_5_robot_HP; + uint16_t red_7_robot_HP; + uint16_t red_outpost_HP; + uint16_t red_base_HP; + uint16_t blue_1_robot_HP; + uint16_t blue_2_robot_HP; + uint16_t blue_3_robot_HP; + uint16_t blue_4_robot_HP; + uint16_t blue_5_robot_HP; + uint16_t blue_7_robot_HP; + uint16_t blue_outpost_HP; + uint16_t blue_base_HP; +} ext_game_robot_HP_t; + +/* ID: 0x0101 Byte: 4 场地事件数据 */ +typedef struct +{ + uint32_t event_type; +} ext_event_data_t; + +/* ID: 0x0102 Byte: 3 场地补给站动作标识数据 */ +typedef struct +{ + uint8_t supply_projectile_id; + uint8_t supply_robot_id; + uint8_t supply_projectile_step; + uint8_t supply_projectile_num; +} ext_supply_projectile_action_t; + +/* ID: 0X0201 Byte: 27 机器人状态数据 */ +typedef struct +{ + uint8_t robot_id; + uint8_t robot_level; + uint16_t remain_HP; + uint16_t max_HP; + uint16_t shooter_id1_17mm_cooling_rate; + uint16_t shooter_id1_17mm_cooling_limit; + uint16_t shooter_id1_17mm_speed_limit; + uint16_t shooter_id2_17mm_cooling_rate; + uint16_t shooter_id2_17mm_cooling_limit; + uint16_t shooter_id2_17mm_speed_limit; + uint16_t shooter_id1_42mm_cooling_rate; + uint16_t shooter_id1_42mm_cooling_limit; + uint16_t shooter_id1_42mm_speed_limit; + uint16_t chassis_power_limit; + uint8_t mains_power_gimbal_output : 1; + uint8_t mains_power_chassis_output : 1; + uint8_t mains_power_shooter_output : 1; +} ext_game_robot_state_t; + +/* ID: 0X0202 Byte: 14 实时功率热量数据 */ +typedef struct +{ + uint16_t chassis_volt; + uint16_t chassis_current; + float chassis_power; // 瞬时功率 + uint16_t chassis_power_buffer; // 60焦耳缓冲能量 + uint16_t shooter_heat0; // 17mm + uint16_t shooter_heat1; +} ext_power_heat_data_t; + +/* ID: 0x0203 Byte: 16 机器人位置数据 */ +typedef struct +{ + float x; + float y; + float z; + float yaw; +} ext_game_robot_pos_t; + +/* ID: 0x0204 Byte: 1 机器人增益数据 */ +typedef struct +{ + uint8_t power_rune_buff; +} ext_buff_musk_t; + +/* ID: 0x0205 Byte: 1 空中机器人能量状态数据 */ +typedef struct +{ + uint8_t attack_time; +} aerial_robot_energy_t; + +/* ID: 0x0206 Byte: 1 伤害状态数据 */ +typedef struct +{ + uint8_t armor_id : 4; + uint8_t hurt_type : 4; +} ext_robot_hurt_t; + +/* ID: 0x0207 Byte: 7 实时射击数据 */ +typedef struct +{ + uint8_t bullet_type; + uint8_t shooter_id; + uint8_t bullet_freq; + float bullet_speed; +} ext_shoot_data_t; + + #pragma pack() #endif From e0abbf95ca5fe0561ed593169d82abf71d6f9de8 Mon Sep 17 00:00:00 2001 From: kidneygood <2979564623@qq.com> Date: Fri, 13 Jan 2023 21:45:04 +0800 Subject: [PATCH 06/15] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=8F=91=E9=80=81=E6=96=B9=E5=BC=8F=EF=BC=8C=E6=95=B4=E5=8C=85?= =?UTF-8?q?=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HAL_N_Middlewares/Src/main.c | 12 ++- modules/referee/referee.c | 2 +- modules/referee/referee_UI.c | 198 +++++++++++++++------------------- modules/referee/referee_UI.h | 88 ++++++--------- modules/referee/referee_def.h | 87 ++++++++++++--- 5 files changed, 197 insertions(+), 190 deletions(-) diff --git a/HAL_N_Middlewares/Src/main.c b/HAL_N_Middlewares/Src/main.c index 1f0cc0c..101809e 100644 --- a/HAL_N_Middlewares/Src/main.c +++ b/HAL_N_Middlewares/Src/main.c @@ -36,6 +36,7 @@ //////////////////////////////////////////////////syhtodo #include "referee_UI.h" #include "referee.h" +#include "referee_def.h" ////////////////////////////////////////////////// /* USER CODE END Includes */ @@ -119,10 +120,12 @@ int main(void) //////////////////////////////////////////////////syhtodo - Graph_Data graph[5]; - Graph_Data num[2]; - String_Data sdata[1]; + Graph_Data_t graph[5]; + Graph_Data_t num[2]; + String_Data_t sdata[1]; memset(sdata[0].show_Data, 0, 30); //使用memset方法 syhtodo 数据存在初始化未默认为0的情况 + memset(&graph[0], 0, 15); + UI_Delete(UI_Data_Del_ALL,0); Line_Draw(&graph[0],"s0",UI_Graph_ADD,0,UI_Color_White,3,710,540,1210,540); @@ -135,8 +138,9 @@ int main(void) Integer_Draw(&num[1],"s6",UI_Graph_ADD,0,UI_Color_Cyan,50,5,1050,460,12345); UI_ReFresh(7,graph[0],graph[1],graph[2],graph[3],graph[4],num[0],num[1]); + Char_Draw(&sdata[0],"s7",UI_Graph_ADD,0,UI_Color_Green,20,2,620,710); - Char_Write(&sdata[0],"number:%d",12345); + Char_Write(&sdata[0],"number:%d",12345678); Char_ReFresh(sdata[0]); ////////////////////////////////////////////////// diff --git a/modules/referee/referee.c b/modules/referee/referee.c index 0caeaaa..3e9256f 100644 --- a/modules/referee/referee.c +++ b/modules/referee/referee.c @@ -57,7 +57,7 @@ static void JudgeReadData(uint8_t *ReadFromUsart) memcpy(&referee_info.FrameHeader, ReadFromUsart, LEN_HEADER); // 判断帧头数据(0)是否为0xA5 - if (ReadFromUsart[SOF] == JUDGE_FRAME_HEADER) + if (ReadFromUsart[SOF] == REFEREE_SOF) { // 帧头CRC8校验 if (Verify_CRC8_Check_Sum(ReadFromUsart, LEN_HEADER) == TRUE) diff --git a/modules/referee/referee_UI.c b/modules/referee/referee_UI.c index 5f1b5dc..e2b3068 100644 --- a/modules/referee/referee_UI.c +++ b/modules/referee/referee_UI.c @@ -5,7 +5,10 @@ #include "dma.h" #include "stdio.h" #include "referee.h" -/* syhtodo 根据自身id判断客户端id */ +/* syhtodo 根据自身id判断客户端id +涉及到的数字是否可以枚举定义??? +*/ + uint16_t Robot_ID = UI_Data_RobotID_BHero; uint16_t Cilent_ID = UI_Data_CilentID_BHero; @@ -17,40 +20,27 @@ uint8_t UI_Seq; //包序号 *****************************************************************************************/ void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer) { -/* syhtodo可化简,去掉读写指针 */ - unsigned char *framepoint; //读写指针 - uint16_t frametail=0xFFFF; //CRC16校验值 - - UI_Packhead framehead; //帧头 - UI_Data_Operate datahead; //数据交互帧 - UI_Data_Delete del; //删除图层帧 - - framepoint=(unsigned char *)&framehead; - - framehead.SOF=UI_SOF; - framehead.Data_Length=8; - framehead.Seq=UI_Seq; - framehead.CRC8=Get_CRC8_Check_Sum(framepoint,4,0xFF); - framehead.CMD_ID=UI_CMD_Robo_Exchange; //填充包头数据 - - datahead.Data_ID=UI_Data_ID_Del; - datahead.Sender_ID=Robot_ID; - datahead.Receiver_ID=Cilent_ID; //填充操作数据 - - del.Delete_Operate=Del_Operate; - del.Layer=Del_Layer; //控制信息 - - frametail=Get_CRC16_Check_Sum(framepoint,sizeof(framehead),frametail); - framepoint=(unsigned char *)&datahead; - frametail=Get_CRC16_Check_Sum(framepoint,sizeof(datahead),frametail); - framepoint=(unsigned char *)&del; - frametail=Get_CRC16_Check_Sum(framepoint,sizeof(del),frametail); //CRC16校验值计算 - - RefereeSend((uint8_t *)&framehead,sizeof(framehead)); - RefereeSend((uint8_t *)&datahead,sizeof(datahead)); - RefereeSend((uint8_t *)&del,sizeof(del)); //发送所有帧 - RefereeSend((uint8_t *)&frametail,sizeof(frametail)); //发送CRC16校验值 - + UI_delete_t UI_delete_data; + + UI_delete_data.FrameHeader.SOF = REFEREE_SOF; + UI_delete_data.FrameHeader.DataLength = UI_Data_LEN_Del; + UI_delete_data.FrameHeader.Seq = UI_Seq; + UI_delete_data.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&UI_delete_data,4,0xFF); + + UI_delete_data.CmdID = ID_student_interactive; + + UI_delete_data.datahead.data_cmd_id = UI_Data_ID_Del; + UI_delete_data.datahead.receiver_ID = Cilent_ID; + UI_delete_data.datahead.sender_ID = Robot_ID; + + UI_delete_data.Delete_Operate = Del_Operate; //删除操作 + UI_delete_data.Layer = Del_Layer; + + UI_delete_data.frametail = Get_CRC16_Check_Sum((uint8_t *)&UI_delete_data,LEN_HEADER+LEN_CMDID+UI_Data_LEN_Del,0xFFFF); + /* syhtodo为什么填入0xFFFF */ + + RefereeSend((uint8_t *)&UI_delete_data,LEN_HEADER+LEN_CMDID+UI_Data_LEN_Del+LEN_TAIL); //发送 + UI_Seq++; //包序号+1 } /************************************************绘制直线************************************************* @@ -64,11 +54,11 @@ void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer) End_x、End_y 终点xy坐标 **********************************************************************************************************/ -void Line_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Line_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y) { int i; - //?????? + //??????syhtodo for(i=0;i<3&&graphname[i]!='\0';i++) { graph->graphic_name[2-i]=graphname[i]; @@ -96,7 +86,7 @@ void Line_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32 Start_x、Start_y 起点xy坐标 End_x、End_y 对角顶点xy坐标 **********************************************************************************************************/ -void Rectangle_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Rectangle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y) { int i; @@ -128,7 +118,7 @@ void Rectangle_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,u Graph_Radius 圆形半径 **********************************************************************************************************/ -void Circle_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Circle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius) { int i; @@ -157,7 +147,7 @@ void Circle_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint Start_x、Start_y 圆心xy坐标 End_x、End_y xy半轴长度 **********************************************************************************************************/ -void Elliptical_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Elliptical_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y) { int i; @@ -191,7 +181,7 @@ void Elliptical_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate, x_Length,y_Length xy半轴长度 **********************************************************************************************************/ -void Arc_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Arc_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y, uint32_t end_x,uint32_t end_y) { @@ -230,7 +220,7 @@ void Arc_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_ end_y=(a>>21)&0x7FF; **********************************************************************************************************/ -void Float_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Float_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float) { int i; @@ -267,7 +257,7 @@ void Float_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint3 end_x=(a>>10)&0x7FF; end_y=(a>>21)&0x7FF; **********************************************************************************************************/ -void Integer_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Integer_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Integer) { int i; @@ -301,10 +291,10 @@ void Integer_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uin Graph_Width 图形线宽 Start_x、Start_y 开始坐标 **********************************************************************************************************/ -void Char_Draw(String_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Char_Draw(String_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y) { - memset(graph->Graph_Control.graphic_name, 0, 3); + memset(graph->Graph_Control.graphic_name, 0, 3);//syhtodo 是否需要手动清零 int i; for(i=0;i<3&&graphname[i]!='\0';i++) { @@ -332,7 +322,7 @@ void Char_Draw(String_Data *graph,char graphname[3],uint32_t Graph_Operate,uint3 fmt需要显示的字符串 syhtodo 尚未理解该函数的写法 **********************************************************************************************************/ -void Char_Write(String_Data *graph,char* fmt, ...) +void Char_Write(String_Data_t *graph,char* fmt, ...) { uint16_t i = 0; va_list ap; @@ -343,6 +333,7 @@ void Char_Write(String_Data *graph,char* fmt, ...) graph->Graph_Control.end_angle = i; } + /* UI推送函数(使更改生效) 参数: cnt 图形个数 ... 图形变量参数 @@ -351,107 +342,88 @@ void Char_Write(String_Data *graph,char* fmt, ...) int UI_ReFresh(int cnt,...) { int i; - UI_Packhead framehead; - UI_Data_Operate datahead; - Graph_Data graphData; + UI_GraphReFresh_t UI_GraphReFresh_data; + Graph_Data_t graphData; - unsigned char *framepoint; //读写指针 - uint16_t frametail=0xFFFF; //CRC16校验值 - va_list ap;//创建一个 va_list 类型变量 va_start(ap,cnt);//初始化 va_list 变量为一个参数列表 - - framepoint=(unsigned char *)&framehead; - framehead.SOF=UI_SOF; - framehead.Data_Length=6+cnt*15; - framehead.Seq=UI_Seq; - framehead.CRC8=Get_CRC8_Check_Sum(framepoint,4,0xFF); - framehead.CMD_ID=UI_CMD_Robo_Exchange; //填充包头数据 - + + UI_GraphReFresh_data.FrameHeader.SOF = REFEREE_SOF; + UI_GraphReFresh_data.FrameHeader.DataLength = 6+cnt*15;//syhtodo 换成枚举 + UI_GraphReFresh_data.FrameHeader.Seq = UI_Seq; + UI_GraphReFresh_data.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&UI_GraphReFresh_data,4,0xFF); + + UI_GraphReFresh_data.CmdID = ID_student_interactive; + switch(cnt) //syhtodo可以直接计算式解决 { case 1: - datahead.Data_ID=UI_Data_ID_Draw1; + UI_GraphReFresh_data.datahead.data_cmd_id=UI_Data_ID_Draw1; break; case 2: - datahead.Data_ID=UI_Data_ID_Draw2; + UI_GraphReFresh_data.datahead.data_cmd_id=UI_Data_ID_Draw2; break; case 5: - datahead.Data_ID=UI_Data_ID_Draw5; + UI_GraphReFresh_data.datahead.data_cmd_id=UI_Data_ID_Draw5; break; case 7: - datahead.Data_ID=UI_Data_ID_Draw7; + UI_GraphReFresh_data.datahead.data_cmd_id=UI_Data_ID_Draw7; break; default: return (-1); } - datahead.Sender_ID=Robot_ID; - datahead.Receiver_ID=Cilent_ID; //填充操作数据 - - framepoint=(unsigned char *)&framehead; - frametail=Get_CRC16_Check_Sum(framepoint,sizeof(framehead),frametail); - framepoint=(unsigned char *)&datahead; - frametail=Get_CRC16_Check_Sum(framepoint,sizeof(datahead),frametail); //CRC16校验值计算(部分) - + UI_GraphReFresh_data.datahead.receiver_ID = Cilent_ID; + UI_GraphReFresh_data.datahead.sender_ID = Robot_ID; - RefereeSend((uint8_t *)&framehead,sizeof(framehead)); - RefereeSend((uint8_t *)&datahead,sizeof(datahead)); + UI_GraphReFresh_data.frametail=Get_CRC16_Check_Sum((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+6,0xFFFF); + RefereeSend((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+6); + + unsigned char *framepoint; //读写指针 for(i=0;i Date: Sat, 14 Jan 2023 21:50:58 +0800 Subject: [PATCH 07/15] =?UTF-8?q?=E6=9B=B4=E6=94=B9UI=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=86=85=E5=85=A8=E9=83=A8=E6=95=B0=E5=AD=97?= =?UTF-8?q?=E4=B8=BA=E6=9E=9A=E4=B8=BE=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HAL_N_Middlewares/Src/main.c | 4 ++-- modules/referee/referee_UI.c | 45 +++++++++++++++++++++-------------- modules/referee/referee_def.h | 15 +++++++----- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/HAL_N_Middlewares/Src/main.c b/HAL_N_Middlewares/Src/main.c index 101809e..d1be4f8 100644 --- a/HAL_N_Middlewares/Src/main.c +++ b/HAL_N_Middlewares/Src/main.c @@ -134,13 +134,13 @@ int main(void) Elliptical_Draw(&graph[3],"s3",UI_Graph_ADD,0,UI_Color_Orange,3,960,540,100,20); Arc_Draw(&graph[4],"s4",UI_Graph_ADD,0,UI_Color_Purplish_red,30,160,3,1200,550,50,100); - Float_Draw(&num[0],"s5",UI_Graph_ADD,0,UI_Color_Pink,50,3,5,1050,660,111111111); + Float_Draw(&num[0],"s5",UI_Graph_ADD,0,UI_Color_Pink,50,3,5,1050,660,1245545); Integer_Draw(&num[1],"s6",UI_Graph_ADD,0,UI_Color_Cyan,50,5,1050,460,12345); UI_ReFresh(7,graph[0],graph[1],graph[2],graph[3],graph[4],num[0],num[1]); Char_Draw(&sdata[0],"s7",UI_Graph_ADD,0,UI_Color_Green,20,2,620,710); - Char_Write(&sdata[0],"number:%d",12345678); + Char_Write(&sdata[0],"number:%d",123); Char_ReFresh(sdata[0]); ////////////////////////////////////////////////// diff --git a/modules/referee/referee_UI.c b/modules/referee/referee_UI.c index e2b3068..e474e30 100644 --- a/modules/referee/referee_UI.c +++ b/modules/referee/referee_UI.c @@ -21,11 +21,12 @@ uint8_t UI_Seq; //包序号 void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer) { UI_delete_t UI_delete_data; + uint8_t temp_datalength = UI_Data_LEN_Head + UI_Operate_LEN_Del; //计算交互数据长度 UI_delete_data.FrameHeader.SOF = REFEREE_SOF; - UI_delete_data.FrameHeader.DataLength = UI_Data_LEN_Del; + UI_delete_data.FrameHeader.DataLength = temp_datalength; UI_delete_data.FrameHeader.Seq = UI_Seq; - UI_delete_data.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&UI_delete_data,4,0xFF); + UI_delete_data.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&UI_delete_data,LEN_CRC8,0xFF); UI_delete_data.CmdID = ID_student_interactive; @@ -36,10 +37,10 @@ void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer) UI_delete_data.Delete_Operate = Del_Operate; //删除操作 UI_delete_data.Layer = Del_Layer; - UI_delete_data.frametail = Get_CRC16_Check_Sum((uint8_t *)&UI_delete_data,LEN_HEADER+LEN_CMDID+UI_Data_LEN_Del,0xFFFF); + UI_delete_data.frametail = Get_CRC16_Check_Sum((uint8_t *)&UI_delete_data,LEN_HEADER+LEN_CMDID+temp_datalength,0xFFFF); /* syhtodo为什么填入0xFFFF */ - RefereeSend((uint8_t *)&UI_delete_data,LEN_HEADER+LEN_CMDID+UI_Data_LEN_Del+LEN_TAIL); //发送 + RefereeSend((uint8_t *)&UI_delete_data,LEN_HEADER+LEN_CMDID+temp_datalength+LEN_TAIL); //发送 UI_Seq++; //包序号+1 } @@ -327,7 +328,7 @@ void Char_Write(String_Data_t *graph,char* fmt, ...) uint16_t i = 0; va_list ap; va_start(ap,fmt); - vsprintf((char*)graph->show_Data, fmt, ap); + vsprintf((char*)graph->show_Data, fmt, ap);//使用参数列表发送格式化输出到字符串 va_end(ap); i = strlen((const char*)graph->show_Data); graph->Graph_Control.end_angle = i; @@ -344,18 +345,19 @@ int UI_ReFresh(int cnt,...) int i; UI_GraphReFresh_t UI_GraphReFresh_data; Graph_Data_t graphData; + // uint8_t temp_datalength = UI_Data_LEN_Head + UI_Operate_LEN_Del; //计算交互数据长度 va_list ap;//创建一个 va_list 类型变量 va_start(ap,cnt);//初始化 va_list 变量为一个参数列表 UI_GraphReFresh_data.FrameHeader.SOF = REFEREE_SOF; - UI_GraphReFresh_data.FrameHeader.DataLength = 6+cnt*15;//syhtodo 换成枚举 + UI_GraphReFresh_data.FrameHeader.DataLength = UI_Data_LEN_Head+cnt*UI_Operate_LEN_PerDraw; UI_GraphReFresh_data.FrameHeader.Seq = UI_Seq; - UI_GraphReFresh_data.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&UI_GraphReFresh_data,4,0xFF); + UI_GraphReFresh_data.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&UI_GraphReFresh_data,LEN_CRC8,0xFF); UI_GraphReFresh_data.CmdID = ID_student_interactive; - switch(cnt) //syhtodo可以直接计算式解决 + switch(cnt) { case 1: UI_GraphReFresh_data.datahead.data_cmd_id=UI_Data_ID_Draw1; @@ -372,26 +374,30 @@ int UI_ReFresh(int cnt,...) default: return (-1); } + UI_GraphReFresh_data.datahead.receiver_ID = Cilent_ID; UI_GraphReFresh_data.datahead.sender_ID = Robot_ID; - UI_GraphReFresh_data.frametail=Get_CRC16_Check_Sum((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+6,0xFFFF); - RefereeSend((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+6); + //先发送帧头、命令码、交互数据帧头三部分,并计算CRC16校验值 + UI_GraphReFresh_data.frametail=Get_CRC16_Check_Sum((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+UI_Data_LEN_Head,0xFFFF); + RefereeSend((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+UI_Data_LEN_Head); - unsigned char *framepoint; //读写指针 + unsigned char *framepoint; //读写指针 syhtodo是否可以去掉 - for(i=0;i Date: Sat, 14 Jan 2023 22:39:26 +0800 Subject: [PATCH 08/15] =?UTF-8?q?=E6=93=8D=E4=BD=9C=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=AE=8F=E5=AE=9A=E4=B9=89=E6=8D=A2=E6=9E=9A=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/referee/referee_UI.c | 59 +------------- modules/referee/referee_UI.h | 27 ------ modules/referee/referee_communication.c | 51 ++++++++++++ modules/referee/referee_communication.h | 15 +--- modules/referee/referee_def.h | 104 +++++++++++++++++------- 5 files changed, 129 insertions(+), 127 deletions(-) diff --git a/modules/referee/referee_UI.c b/modules/referee/referee_UI.c index e474e30..ec436cd 100644 --- a/modules/referee/referee_UI.c +++ b/modules/referee/referee_UI.c @@ -345,7 +345,6 @@ int UI_ReFresh(int cnt,...) int i; UI_GraphReFresh_t UI_GraphReFresh_data; Graph_Data_t graphData; - // uint8_t temp_datalength = UI_Data_LEN_Head + UI_Operate_LEN_Del; //计算交互数据长度 va_list ap;//创建一个 va_list 类型变量 va_start(ap,cnt);//初始化 va_list 变量为一个参数列表 @@ -381,16 +380,13 @@ int UI_ReFresh(int cnt,...) //先发送帧头、命令码、交互数据帧头三部分,并计算CRC16校验值 UI_GraphReFresh_data.frametail=Get_CRC16_Check_Sum((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+UI_Data_LEN_Head,0xFFFF); RefereeSend((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+UI_Data_LEN_Head); - - unsigned char *framepoint; //读写指针 syhtodo是否可以去掉 - + for(i=0;i Date: Sun, 15 Jan 2023 21:11:15 +0800 Subject: [PATCH 09/15] =?UTF-8?q?=E4=B8=80=E8=87=B4UI=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E8=87=B3chassis=EF=BC=8C=E6=B7=BB=E5=8A=A0id=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HAL_N_Middlewares/Src/main.c | 32 ------- application/chassis/chassis.c | 8 +- modules/referee/referee.c | 17 +--- modules/referee/referee.h | 36 ++++---- modules/referee/referee_UI.c | 166 +++++++++++++++++++--------------- modules/referee/referee_UI.h | 57 +----------- modules/referee/referee_def.h | 31 ++++--- 7 files changed, 143 insertions(+), 204 deletions(-) diff --git a/HAL_N_Middlewares/Src/main.c b/HAL_N_Middlewares/Src/main.c index d1be4f8..b89d655 100644 --- a/HAL_N_Middlewares/Src/main.c +++ b/HAL_N_Middlewares/Src/main.c @@ -33,11 +33,6 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "robot.h" -//////////////////////////////////////////////////syhtodo -#include "referee_UI.h" -#include "referee.h" -#include "referee_def.h" -////////////////////////////////////////////////// /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -118,33 +113,6 @@ int main(void) RobotInit(); - -//////////////////////////////////////////////////syhtodo - Graph_Data_t graph[5]; - Graph_Data_t num[2]; - String_Data_t sdata[1]; - memset(sdata[0].show_Data, 0, 30); //使用memset方法 syhtodo 数据存在初始化未默认为0的情况 - memset(&graph[0], 0, 15); - - UI_Delete(UI_Data_Del_ALL,0); - - Line_Draw(&graph[0],"s0",UI_Graph_ADD,0,UI_Color_White,3,710,540,1210,540); - Rectangle_Draw(&graph[1],"s1",UI_Graph_ADD,0,UI_Color_Yellow,4,600,200,800,500); - Circle_Draw(&graph[2],"s2",UI_Graph_ADD,0,UI_Color_Green,5,960,540,100); - Elliptical_Draw(&graph[3],"s3",UI_Graph_ADD,0,UI_Color_Orange,3,960,540,100,20); - Arc_Draw(&graph[4],"s4",UI_Graph_ADD,0,UI_Color_Purplish_red,30,160,3,1200,550,50,100); - - Float_Draw(&num[0],"s5",UI_Graph_ADD,0,UI_Color_Pink,50,3,5,1050,660,1245545); - Integer_Draw(&num[1],"s6",UI_Graph_ADD,0,UI_Color_Cyan,50,5,1050,460,12345); - UI_ReFresh(7,graph[0],graph[1],graph[2],graph[3],graph[4],num[0],num[1]); - - - Char_Draw(&sdata[0],"s7",UI_Graph_ADD,0,UI_Color_Green,20,2,620,710); - Char_Write(&sdata[0],"number:%d",123); - Char_ReFresh(sdata[0]); - -////////////////////////////////////////////////// - /* USER CODE END 2 */ /* Call init function for freertos objects (in freertos.c) */ diff --git a/application/chassis/chassis.c b/application/chassis/chassis.c index 75ede1f..184045a 100644 --- a/application/chassis/chassis.c +++ b/application/chassis/chassis.c @@ -19,7 +19,7 @@ #include "referee.h" #include "general_def.h" #include "bsp_dwt.h" - +#include "referee_UI.h" #include "arm_math.h" /* 根据robot_def.h中的macro自动计算的参数 */ @@ -41,7 +41,7 @@ static Subscriber_t *chassis_sub; // 用于订阅底盘的控 static Chassis_Ctrl_Cmd_s chassis_cmd_recv; // 底盘接收到的控制命令 static Chassis_Upload_Data_s chassis_feedback_data; // 底盘回传的反馈数据 -static referee_info_t *referee_data; // 裁判系统的数据 +static referee_info_t *referee_data; // 裁判系统相关数据 static SuperCapInstance *cap; // 超级电容 static DJIMotorInstance *motor_lf; // left right forward back static DJIMotorInstance *motor_rf; @@ -101,6 +101,10 @@ void ChassisInit() referee_data = RefereeInit(&huart6); // 裁判系统初始化 + while (referee_data->GameRobotState.robot_id ==0); + Interactive_init(referee_data); + + SuperCap_Init_Config_s cap_conf = { .can_config = { .can_handle = &hcan2, diff --git a/modules/referee/referee.c b/modules/referee/referee.c index 3e9256f..7500ccf 100644 --- a/modules/referee/referee.c +++ b/modules/referee/referee.c @@ -22,7 +22,6 @@ referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle) return &referee_info; } - /** * @brief 发送函数 * @param send 待发送数据 @@ -30,11 +29,10 @@ referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle) void RefereeSend(uint8_t *send,uint16_t tx_len) { USARTSend(referee_usart_instance,send,tx_len); - /* syhtodo DMA请求过快会导致数据发送丢失,考虑数据尽可能打成一阵个包 */ + /* syhtodo DMA请求过快会导致数据发送丢失,考虑数据尽可能打成一个整包以及队列发送 */ HAL_Delay(5); } - /*裁判系统串口接收回调函数,解析数据 */ static void RefereeRxCallback() { @@ -76,49 +74,38 @@ static void JudgeReadData(uint8_t *ReadFromUsart) case ID_game_state: // 0x0001 memcpy(&referee_info.GameState, (ReadFromUsart + DATA_Offset), LEN_game_state); break; - case ID_game_result: // 0x0002 memcpy(&referee_info.GameResult, (ReadFromUsart + DATA_Offset), LEN_game_result); break; - case ID_game_robot_survivors: // 0x0003 memcpy(&referee_info.GameRobotHP, (ReadFromUsart + DATA_Offset), LEN_game_robot_HP); break; - case ID_event_data: // 0x0101 memcpy(&referee_info.EventData, (ReadFromUsart + DATA_Offset), LEN_event_data); break; - case ID_supply_projectile_action: // 0x0102 memcpy(&referee_info.SupplyProjectileAction, (ReadFromUsart + DATA_Offset), LEN_supply_projectile_action); break; - case ID_game_robot_state: // 0x0201 memcpy(&referee_info.GameRobotState, (ReadFromUsart + DATA_Offset), LEN_game_robot_state); break; case ID_power_heat_data: // 0x0202 memcpy(&referee_info.PowerHeatData, (ReadFromUsart + DATA_Offset), LEN_power_heat_data); break; - case ID_game_robot_pos: // 0x0203 memcpy(&referee_info.GameRobotPos, (ReadFromUsart + DATA_Offset), LEN_game_robot_pos); break; - case ID_buff_musk: // 0x0204 memcpy(&referee_info.BuffMusk, (ReadFromUsart + DATA_Offset), LEN_buff_musk); break; - case ID_aerial_robot_energy: // 0x0205 memcpy(&referee_info.AerialRobotEnergy, (ReadFromUsart + DATA_Offset), LEN_aerial_robot_energy); break; - case ID_robot_hurt: // 0x0206 memcpy(&referee_info.RobotHurt, (ReadFromUsart + DATA_Offset), LEN_robot_hurt); break; - case ID_shoot_data: // 0x0207 memcpy(&referee_info.ShootData, (ReadFromUsart + DATA_Offset), LEN_shoot_data); - // JUDGE_ShootNumCount();//发弹量统计 break; } } @@ -130,4 +117,4 @@ static void JudgeReadData(uint8_t *ReadFromUsart) JudgeReadData(ReadFromUsart + sizeof(xFrameHeader) + LEN_CMDID + referee_info.FrameHeader.DataLength + LEN_TAIL); } } -} \ No newline at end of file +} diff --git a/modules/referee/referee.h b/modules/referee/referee.h index 377129b..798f24b 100644 --- a/modules/referee/referee.h +++ b/modules/referee/referee.h @@ -16,18 +16,21 @@ #include "referee_def.h" #include "bsp_usart.h" - -#define FALSE 0 -#define TRUE 1 - -#define JUDGE_DATA_ERROR 0 -#define JUDGE_DATA_CORRECT 1 - #pragma pack(1) -// 裁判系统接收数据整合进一个结构体 typedef struct { + uint8_t Robot_Color; //机器人颜色 + uint16_t Robot_ID; //本机器人ID + uint16_t Cilent_ID; //本机器人对应的客户端ID + uint16_t Receiver_Robot_ID; //机器人车间通信时接收者的ID +} referee_id_t; + +// 次结构体包含裁判系统接收数据以及UI绘制与机器人车间通信的相关信息 +typedef struct +{ + referee_id_t referee_id; + xFrameHeader FrameHeader; // 接收到的帧头信息 uint16_t CmdID; ext_game_state_t GameState; // 0x0001 @@ -43,8 +46,7 @@ typedef struct ext_robot_hurt_t RobotHurt; // 0x0206 ext_shoot_data_t ShootData; // 0x0207 - // ext_SendClientData_t ShowData; // 客户端信息 - // ext_CommunatianData_t CommuData; // 队友通信信息 + // syhtodo 机器人间通信如何获取数据 } referee_info_t; @@ -52,19 +54,19 @@ typedef struct /** * @brief 初始化裁判系统,返回接收数据指针 - * - * @param referee_usart_handle - * @return referee_info_t* + * + * @param referee_usart_handle + * @return referee_info_t* */ -referee_info_t* RefereeInit(UART_HandleTypeDef *referee_usart_handle); +referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle); /** * @brief 发送函数 - * @todo + * @todo * @param send 待发送数据 */ -void RefereeSend(uint8_t *send,uint16_t tx_len); +void RefereeSend(uint8_t *send, uint16_t tx_len); -extern USARTInstance *referee_usart_instance; +extern USARTInstance *referee_usart_instance; #endif // !REFEREE_H diff --git a/modules/referee/referee_UI.c b/modules/referee/referee_UI.c index ec436cd..852a399 100644 --- a/modules/referee/referee_UI.c +++ b/modules/referee/referee_UI.c @@ -2,23 +2,90 @@ #include "string.h" #include "crc.h" #include "bsp_usart.h" -#include "dma.h" #include "stdio.h" #include "referee.h" -/* syhtodo 根据自身id判断客户端id -涉及到的数字是否可以枚举定义??? -*/ -uint16_t Robot_ID = UI_Data_RobotID_BHero; -uint16_t Cilent_ID = UI_Data_CilentID_BHero; +static void UI_Delete(referee_id_t *_id,uint8_t Del_Operate,uint8_t Del_Layer); +static void Line_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); +static void Rectangle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); +static void Circle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius); +static void Elliptical_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y); +static void Arc_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y, + uint32_t end_x,uint32_t end_y); +static void Float_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float); +static void Integer_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Integer); +static void Char_Draw(String_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y); +static void Char_Write(String_Data_t *graph,char* fmt, ...); +static int UI_ReFresh(referee_id_t *_id,int cnt,...); +static int Char_ReFresh(referee_id_t *_id,String_Data_t string_Data); + +static void determine_ID(referee_info_t *_referee_info); + +static uint8_t UI_Seq; //包序号 + +void Interactive_init(referee_info_t *_referee_info) +{ + determine_ID(_referee_info); + + + Graph_Data_t graph[5]; + Graph_Data_t num[2]; + String_Data_t sdata[1]; + memset(sdata[0].show_Data, 0, 30); //使用memset方法 syhtodo 数据存在初始化未默认为0的情况 + memset(&graph[0], 0, 15); + + UI_Delete(&_referee_info->referee_id,UI_Data_Del_ALL,0); + + Line_Draw(&graph[0],"s0",UI_Graph_ADD,0,UI_Color_White,3,710,540,1210,540); + Rectangle_Draw(&graph[1],"s1",UI_Graph_ADD,0,UI_Color_Yellow,4,600,200,800,500); + Circle_Draw(&graph[2],"s2",UI_Graph_ADD,0,UI_Color_Green,5,960,540,100); + Elliptical_Draw(&graph[3],"s3",UI_Graph_ADD,0,UI_Color_Orange,3,960,540,100,20); + Arc_Draw(&graph[4],"s4",UI_Graph_ADD,0,UI_Color_Purplish_red,30,160,3,1200,550,50,100); + + Float_Draw(&num[0],"s5",UI_Graph_ADD,0,UI_Color_Pink,50,3,5,1050,660,1245545); + Integer_Draw(&num[1],"s6",UI_Graph_ADD,0,UI_Color_Cyan,50,5,1050,460,12345); + UI_ReFresh(&_referee_info->referee_id,7,graph[0],graph[1],graph[2],graph[3],graph[4],num[0],num[1]); + + + Char_Draw(&sdata[0],"s7",UI_Graph_ADD,0,UI_Color_Green,20,2,620,710); + Char_Write(&sdata[0],"number:%d",123); + Char_ReFresh(&_referee_info->referee_id,sdata[0]); + +} + +/** + * @brief 判断各种ID,选择客户端ID + * @param void + * @retval referee_info + * @attention + */ +static void determine_ID(referee_info_t *_referee_info) +{ + //id小于7是红色,大于7是蓝色,0为红色,1为蓝色 #define Robot_Red 0 #define Robot_Blue 1 + _referee_info->referee_id.Robot_Color = _referee_info->GameRobotState.robot_id >7 ? Robot_Blue : Robot_Red; + _referee_info->referee_id.Robot_ID=_referee_info->GameRobotState.robot_id; + _referee_info->referee_id.Cilent_ID = 0x0100 + _referee_info->referee_id.Robot_ID;//计算客户端ID + _referee_info->referee_id.Receiver_Robot_ID = 0x00; //机器人车间通信时接收者的ID暂时为0 +} + + + + -uint8_t UI_Seq; //包序号 /********************************************删除操作************************************* **参数:Del_Operate 对应头文件删除操作 Del_Layer 要删除的层 取值0-9 *****************************************************************************************/ -void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer) +static void UI_Delete(referee_id_t *_id,uint8_t Del_Operate,uint8_t Del_Layer) { UI_delete_t UI_delete_data; uint8_t temp_datalength = UI_Data_LEN_Head + UI_Operate_LEN_Del; //计算交互数据长度 @@ -31,8 +98,8 @@ void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer) UI_delete_data.CmdID = ID_student_interactive; UI_delete_data.datahead.data_cmd_id = UI_Data_ID_Del; - UI_delete_data.datahead.receiver_ID = Cilent_ID; - UI_delete_data.datahead.sender_ID = Robot_ID; + UI_delete_data.datahead.receiver_ID = _id->Cilent_ID; + UI_delete_data.datahead.sender_ID = _id->Robot_ID; UI_delete_data.Delete_Operate = Del_Operate; //删除操作 UI_delete_data.Layer = Del_Layer; @@ -55,7 +122,7 @@ void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer) End_x、End_y 终点xy坐标 **********************************************************************************************************/ -void Line_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +static void Line_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y) { int i; @@ -87,7 +154,7 @@ void Line_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint Start_x、Start_y 起点xy坐标 End_x、End_y 对角顶点xy坐标 **********************************************************************************************************/ -void Rectangle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +static void Rectangle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y) { int i; @@ -119,7 +186,7 @@ void Rectangle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate Graph_Radius 圆形半径 **********************************************************************************************************/ -void Circle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +static void Circle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius) { int i; @@ -148,7 +215,7 @@ void Circle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,ui Start_x、Start_y 圆心xy坐标 End_x、End_y xy半轴长度 **********************************************************************************************************/ -void Elliptical_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +static void Elliptical_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y) { int i; @@ -182,7 +249,7 @@ void Elliptical_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operat x_Length,y_Length xy半轴长度 **********************************************************************************************************/ -void Arc_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +static void Arc_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y, uint32_t end_x,uint32_t end_y) { @@ -221,7 +288,7 @@ void Arc_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint3 end_y=(a>>21)&0x7FF; **********************************************************************************************************/ -void Float_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +static void Float_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float) { int i; @@ -258,7 +325,7 @@ void Float_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uin end_x=(a>>10)&0x7FF; end_y=(a>>21)&0x7FF; **********************************************************************************************************/ -void Integer_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +static void Integer_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Integer) { int i; @@ -292,7 +359,7 @@ void Integer_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,u Graph_Width 图形线宽 Start_x、Start_y 开始坐标 **********************************************************************************************************/ -void Char_Draw(String_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +static void Char_Draw(String_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y) { memset(graph->Graph_Control.graphic_name, 0, 3);//syhtodo 是否需要手动清零 @@ -323,7 +390,7 @@ void Char_Draw(String_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uin fmt需要显示的字符串 syhtodo 尚未理解该函数的写法 **********************************************************************************************************/ -void Char_Write(String_Data_t *graph,char* fmt, ...) +static void Char_Write(String_Data_t *graph,char* fmt, ...) { uint16_t i = 0; va_list ap; @@ -340,7 +407,7 @@ void Char_Write(String_Data_t *graph,char* fmt, ...) ... 图形变量参数 Tips::该函数只能推送1,2,5,7个图形,其他数目协议未涉及 */ -int UI_ReFresh(int cnt,...) +static int UI_ReFresh(referee_id_t *_id,int cnt,...) { int i; UI_GraphReFresh_t UI_GraphReFresh_data; @@ -374,8 +441,8 @@ int UI_ReFresh(int cnt,...) return (-1); } - UI_GraphReFresh_data.datahead.receiver_ID = Cilent_ID; - UI_GraphReFresh_data.datahead.sender_ID = Robot_ID; + UI_GraphReFresh_data.datahead.receiver_ID = _id->Cilent_ID; + UI_GraphReFresh_data.datahead.sender_ID = _id->Robot_ID; //先发送帧头、命令码、交互数据帧头三部分,并计算CRC16校验值 UI_GraphReFresh_data.frametail=Get_CRC16_Check_Sum((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+UI_Data_LEN_Head,0xFFFF); @@ -398,7 +465,7 @@ int UI_ReFresh(int cnt,...) } /************************************************UI推送字符(使更改生效)*********************************/ -int Char_ReFresh(String_Data_t string_Data) +static int Char_ReFresh(referee_id_t *_id,String_Data_t string_Data) { UI_CharReFresh_t UI_CharReFresh_data; @@ -412,8 +479,9 @@ int Char_ReFresh(String_Data_t string_Data) UI_CharReFresh_data.CmdID = ID_student_interactive; UI_CharReFresh_data.datahead.data_cmd_id = UI_Data_ID_DrawChar; - UI_CharReFresh_data.datahead.receiver_ID = Cilent_ID; - UI_CharReFresh_data.datahead.sender_ID = Robot_ID; + + UI_CharReFresh_data.datahead.receiver_ID = _id->Cilent_ID; + UI_CharReFresh_data.datahead.sender_ID = _id->Robot_ID; UI_CharReFresh_data.String_Data = string_Data; @@ -424,50 +492,4 @@ int Char_ReFresh(String_Data_t string_Data) UI_Seq++; //包序号+1 return 0; } - - - - - - - -// /** -// * @brief 判断自己红蓝方 -// * @param void -// * @retval RED BLUE -// * @attention 数据打包,打包完成后通过串口发送到裁判系统 -// */ - -// bool is_red_or_blue(void) -// { -// Judge_Self_ID = GameRobotStat.robot_id;//读取当前机器人ID - -// if(GameRobotStat.robot_id > 10) -// { -// return BLUE; -// } -// else -// { -// return RED; -// } -// } - -// /** -// * @brief 判断自身ID,选择客户端ID -// * @param void -// * @retval RED BLUE -// * @attention 数据打包,打包完成后通过串口发送到裁判系统 -// */ -// void determine_ID(void) -// { -// Color = is_red_or_blue(); -// if(Color == BLUE) -// { - -// Judge_SelfClient_ID = 0x0110 + (Judge_Self_ID-10);//计算客户端ID -// } -// else if(Color == RED) -// { -// Judge_SelfClient_ID = 0x0100 + Judge_Self_ID;//计算客户端ID -// } -// } \ No newline at end of file + \ No newline at end of file diff --git a/modules/referee/referee_UI.h b/modules/referee/referee_UI.h index eff18ce..85752e2 100644 --- a/modules/referee/referee_UI.h +++ b/modules/referee/referee_UI.h @@ -5,44 +5,11 @@ #include "usart.h" #include "stdint.h" #include "referee_def.h" -#pragma pack(1) //按1字节对齐 +#include "referee.h" -// #define NULL 0 -#define __FALSE 100 - -/****************************红方机器人ID********************/ -#define UI_Data_RobotID_RHero 1 -#define UI_Data_RobotID_REngineer 2 -#define UI_Data_RobotID_RStandard1 3 -#define UI_Data_RobotID_RStandard2 4 -#define UI_Data_RobotID_RStandard3 5 -#define UI_Data_RobotID_RAerial 6 -#define UI_Data_RobotID_RSentry 7 -#define UI_Data_RobotID_RRadar 9 -/****************************蓝方机器人ID********************/ -#define UI_Data_RobotID_BHero 101 -#define UI_Data_RobotID_BEngineer 102 -#define UI_Data_RobotID_BStandard1 103 -#define UI_Data_RobotID_BStandard2 104 -#define UI_Data_RobotID_BStandard3 105 -#define UI_Data_RobotID_BAerial 106 -#define UI_Data_RobotID_BSentry 107 -#define UI_Data_RobotID_BRadar 109 -/**************************红方操作手ID************************/ -#define UI_Data_CilentID_RHero 0x0101 -#define UI_Data_CilentID_REngineer 0x0102 -#define UI_Data_CilentID_RStandard1 0x0103 -#define UI_Data_CilentID_RStandard2 0x0104 -#define UI_Data_CilentID_RStandard3 0x0105 -#define UI_Data_CilentID_RAerial 0x0106 -/***************************蓝方操作手ID***********************/ -#define UI_Data_CilentID_BHero 0x0165 -#define UI_Data_CilentID_BEngineer 0x0166 -#define UI_Data_CilentID_BStandard1 0x0167 -#define UI_Data_CilentID_BStandard2 0x0168 -#define UI_Data_CilentID_BStandard3 0x0169 -#define UI_Data_CilentID_BAerial 0x016A +#pragma pack(1) //按1字节对齐 +/* 此处的定义只与UI绘制有关 */ typedef struct { xFrameHeader FrameHeader; @@ -61,7 +28,6 @@ typedef struct uint16_t frametail; } UI_GraphReFresh_t; - typedef struct { xFrameHeader FrameHeader; @@ -71,23 +37,8 @@ typedef struct uint16_t frametail; } UI_CharReFresh_t; //打印字符串数据 - #pragma pack() -void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer); - -void Line_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); -void Circle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius); -void Elliptical_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y); -void Rectangle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); -void Arc_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y); -void Float_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float); -void Integer_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Integer); -int UI_ReFresh(int cnt,...); - - -void Char_Draw(String_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color,uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y); -void Char_Write(String_Data_t *graph,char* fmt, ...); -int Char_ReFresh(String_Data_t string_Data); +void Interactive_init(referee_info_t *_referee_info); #endif diff --git a/modules/referee/referee_def.h b/modules/referee/referee_def.h index 24a7b07..e598af3 100644 --- a/modules/referee/referee_def.h +++ b/modules/referee/referee_def.h @@ -13,6 +13,13 @@ #include "stdint.h" +/****************************宏定义部分****************************/ +/****************************宏定义部分****************************/ + +#define REFEREE_SOF 0xA5 // 起始字节,协议固定为0xA5 +#define Robot_Red 0 +#define Robot_Blue 1 + #pragma pack(1) /****************************通信协议格式****************************/ @@ -24,7 +31,7 @@ typedef enum FRAME_HEADER_Offset = 0, CMD_ID_Offset = 5, DATA_Offset = 7, -} JudgeFrameOffset; +} JudgeFrameOffset_e; /* 通信协议长度 */ typedef enum @@ -34,12 +41,11 @@ typedef enum LEN_TAIL = 2, // 帧尾CRC16 LEN_CRC8 = 4, // 帧头CRC8校验长度=帧头+数据长+包序号 -} JudgeFrameLength; +} JudgeFrameLength_e; /****************************帧头****************************/ /****************************帧头****************************/ -#define REFEREE_SOF 0xA5 // 起始字节,协议固定为0xA5 /* 帧头偏移 */ typedef enum { @@ -47,7 +53,7 @@ typedef enum DATA_LENGTH = 1, // 帧内数据长度,根据这个来获取数据长度 SEQ = 3, // 包序号 CRC8 = 4 // CRC8 -} FrameHeaderOffset; +} FrameHeaderOffset_e; /* 帧头定义 */ typedef struct @@ -78,7 +84,7 @@ typedef enum ID_robot_hurt = 0x0206, // 伤害状态数据 ID_shoot_data = 0x0207, // 实时射击数据 ID_student_interactive = 0x0301, // 机器人间交互数据 -} CmdID; +} CmdID_e; /* 命令码数据段长,根据官方协议来定义长度 */ typedef enum @@ -95,7 +101,7 @@ typedef enum LEN_aerial_robot_energy = 1, // 0x0205 LEN_robot_hurt = 1, // 0x0206 LEN_shoot_data = 7, // 0x0207 -} JudgeDataLength; +} JudgeDataLength_e; /****************************接收数据的详细说明****************************/ /****************************接收数据的详细说明****************************/ @@ -242,7 +248,7 @@ typedef enum UI_Data_ID_Draw5 = 0x103, UI_Data_ID_Draw7 = 0x104, UI_Data_ID_DrawChar = 0x110, -} Interactive_Data_ID; +} Interactive_Data_ID_e; /* 交互数据长度 */ typedef enum { @@ -250,7 +256,7 @@ typedef enum UI_Operate_LEN_Del = 2, UI_Operate_LEN_PerDraw = 15, UI_Operate_LEN_DrawChar = 15 + 30, -} UI_Data_Length; +} UI_Data_Length_e; /****************************UI交互数据****************************/ @@ -286,7 +292,7 @@ typedef enum UI_Data_Del_NoOperate = 0, UI_Data_Del_Layer = 1, UI_Data_Del_ALL = 2, // 删除全部图层,后面的参数已经不重要了。 -} UI_Delete_Operate; +} UI_Delete_Operate_e; /* 图形配置参数__图形操作 */ typedef enum @@ -294,7 +300,7 @@ typedef enum UI_Graph_ADD = 1, UI_Graph_Change = 2, UI_Graph_Del = 3, -} UI_Graph_Operate; +} UI_Graph_Operate_e; /* 图形配置参数__图形类型 */ typedef enum @@ -308,7 +314,7 @@ typedef enum UI_Graph_Int = 6, // 整形 UI_Graph_Char = 7, // 字符型 -} UI_Graph_Type; +} UI_Graph_Type_e; /* 图形配置参数__图形颜色 */ typedef enum @@ -323,8 +329,7 @@ typedef enum UI_Color_Black = 7, UI_Color_White = 8, -} UI_Graph_Color; - +} UI_Graph_Color_e; #pragma pack() From 68f7e64c2a6c646e09561a0c353df95810da6be6 Mon Sep 17 00:00:00 2001 From: kidneygood <2979564623@qq.com> Date: Tue, 24 Jan 2023 22:37:53 +0800 Subject: [PATCH 10/15] =?UTF-8?q?application=E4=B8=AD=E5=88=86=E7=A6=BBref?= =?UTF-8?q?eree=E9=83=A8=E5=88=86=EF=BC=8C=E7=9B=B8=E5=85=B3=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=87=8D=E6=9E=84=EF=BC=8C=E5=AE=8C=E6=88=90=E6=AD=A5?= =?UTF-8?q?=E5=85=B5UI=E7=9A=84init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HAL_N_Middlewares/Src/freertos.c | 2 +- Makefile | 4 +- README.md | 4 +- application/chassis/chassis.c | 25 ++- application/referee/referee.c | 235 ++++++++++++++++++++ application/referee/referee.h | 45 ++++ application/robot.c | 3 + modules/referee/referee_UI.c | 130 +++-------- modules/referee/referee_UI.h | 39 +++- modules/referee/{referee.c => rm_referee.c} | 13 +- modules/referee/{referee.h => rm_referee.h} | 18 +- 11 files changed, 385 insertions(+), 133 deletions(-) create mode 100644 application/referee/referee.c create mode 100644 application/referee/referee.h rename modules/referee/{referee.c => rm_referee.c} (96%) rename modules/referee/{referee.h => rm_referee.h} (86%) diff --git a/HAL_N_Middlewares/Src/freertos.c b/HAL_N_Middlewares/Src/freertos.c index 391e140..dabedf9 100644 --- a/HAL_N_Middlewares/Src/freertos.c +++ b/HAL_N_Middlewares/Src/freertos.c @@ -198,7 +198,7 @@ void StartROBOTTASK(void const * argument) { // 200Hz RobotTask(); - osDelay(5); + osDelay(10);//syh此处暂时将时间改为10ms,原因在于未使用缓冲区发送,发送时延时5ms } } diff --git a/Makefile b/Makefile index a0a818a..e03012f 100644 --- a/Makefile +++ b/Makefile @@ -131,7 +131,7 @@ modules/motor/step_motor/step_motor.c \ modules/motor/servo_motor/servo_motor.c \ modules/motor/motor_task.c \ modules/referee/crc.c \ -modules/referee/referee.c \ +modules/referee/rm_referee.c \ modules/referee/referee_UI.c \ modules/referee/referee_communication.c \ modules/remote/remote_control.c \ @@ -143,6 +143,7 @@ modules/vofa/vofa.c \ application/gimbal/gimbal.c \ application/chassis/chassis.c \ application/shoot/shoot.c \ +application/referee/referee.c \ application/cmd/robot_cmd.c \ application/robot.c @@ -224,6 +225,7 @@ C_INCLUDES = \ -Iapplication/shoot \ -Iapplication/gimbal \ -Iapplication/cmd \ +-Iapplication/referee \ -Iapplication \ -Ibsp/dwt \ -Ibsp/can \ diff --git a/README.md b/README.md index 978928a..dc42adb 100644 --- a/README.md +++ b/README.md @@ -384,8 +384,8 @@ ROOT:. ├─referee │ crc.c │ crc.h - │ referee.c - │ referee.h + │ rm_referee.c + │ rm_referee.h │ referee.md │ referee_communication.c │ referee_UI.c diff --git a/application/chassis/chassis.c b/application/chassis/chassis.c index 184045a..9ce196e 100644 --- a/application/chassis/chassis.c +++ b/application/chassis/chassis.c @@ -16,7 +16,12 @@ #include "dji_motor.h" #include "super_cap.h" #include "message_center.h" + +///////////////////////// #include "referee.h" +#include "rm_referee.h" +///////////////////////// + #include "general_def.h" #include "bsp_dwt.h" #include "referee_UI.h" @@ -41,7 +46,7 @@ static Subscriber_t *chassis_sub; // 用于订阅底盘的控 static Chassis_Ctrl_Cmd_s chassis_cmd_recv; // 底盘接收到的控制命令 static Chassis_Upload_Data_s chassis_feedback_data; // 底盘回传的反馈数据 -static referee_info_t *referee_data; // 裁判系统相关数据 +// static referee_info_t *referee_data; // 裁判系统相关数据 static SuperCapInstance *cap; // 超级电容 static DJIMotorInstance *motor_lf; // left right forward back static DJIMotorInstance *motor_rf; @@ -99,10 +104,10 @@ void ChassisInit() chassis_motor_config.controller_setting_init_config.reverse_flag = MOTOR_DIRECTION_NORMAL; motor_rb = DJIMotorInit(&chassis_motor_config); - referee_data = RefereeInit(&huart6); // 裁判系统初始化 + // referee_data = RefereeInit(&huart6); // 裁判系统初始化 - while (referee_data->GameRobotState.robot_id ==0); - Interactive_init(referee_data); + // while (referee_data->GameRobotState.robot_id ==0); + // Referee_Interactive_init(referee_data); SuperCap_Init_Config_s cap_conf = { @@ -240,12 +245,12 @@ void ChassisTask() // 根据电机的反馈速度和IMU(如果有)计算真实速度 EstimateSpeed(); - // 获取裁判系统数据 - // 我方颜色id小于7是红色,大于7是蓝色,注意这里发送的是对方的颜色, 0:blue , 1:red - chassis_feedback_data.enemy_color = referee_data->GameRobotState.robot_id > 7 ? 1 : 0; - // 当前只做了17mm热量的数据获取,后续根据robot_def中的宏切换双枪管和英雄42mm的情况 - chassis_feedback_data.bullet_speed = referee_data->GameRobotState.shooter_id1_17mm_speed_limit; - chassis_feedback_data.rest_heat = referee_data->PowerHeatData.shooter_heat0; + // // 获取裁判系统数据 建议将裁判系统与底盘分离,所以此处数据应使用消息中心发送 + // // 我方颜色id小于7是红色,大于7是蓝色,注意这里发送的是对方的颜色, 0:blue , 1:red + // chassis_feedback_data.enemy_color = referee_data->GameRobotState.robot_id > 7 ? 1 : 0; + // // 当前只做了17mm热量的数据获取,后续根据robot_def中的宏切换双枪管和英雄42mm的情况 + // chassis_feedback_data.bullet_speed = referee_data->GameRobotState.shooter_id1_17mm_speed_limit; + // chassis_feedback_data.rest_heat = referee_data->PowerHeatData.shooter_heat0; // 推送反馈消息 #ifdef ONE_BOARD diff --git a/application/referee/referee.c b/application/referee/referee.c new file mode 100644 index 0000000..933c768 --- /dev/null +++ b/application/referee/referee.c @@ -0,0 +1,235 @@ +/** + * @file referee.C + * @author kidneygood (you@domain.com) + * @brief + * @version 0.1 + * @date 2022-11-18 + * + * @copyright Copyright (c) 2022 + * + */ +#include "referee.h" +#include "robot_def.h" +#include "rm_referee.h" +#include "referee_UI.h" + +static Referee_Interactive_info_t *Interactive_data;// 非裁判系统数据 +static referee_info_t *referee_data; // 裁判系统相关数据 +static void determine_ID(referee_info_t *_referee_info); +static void My_UI_init(referee_info_t *_referee_info); +static void My_UI_Refresh(referee_info_t *_referee_info,Referee_Interactive_info_t *_Interactive_data); + +void Referee_Interactive_init() +{ + referee_data = RefereeInit(&huart6); // 裁判系统初始化 + while (referee_data->GameRobotState.robot_id ==0); + + determine_ID(referee_data); + My_UI_init(referee_data); +} + +void Referee_Interactive_task() +{ + My_UI_Refresh(referee_data,Interactive_data); + +} + +static Graph_Data_t UI_shoot_line[10];//射击准线 +static String_Data_t UI_State_sta[5];//机器人状态,静态只需画一次 +static String_Data_t UI_State_dyn[5];//机器人状态,动态先add才能change +static uint32_t shoot_line_location[10]={540,960,490,515,565}; + +static void My_UI_init(referee_info_t *_referee_info) +{ + UI_Delete(&_referee_info->referee_id,UI_Data_Del_ALL,0); + + //绘制发射基准线 + Line_Draw(&UI_shoot_line[0],"sl0",UI_Graph_ADD,7,UI_Color_White,3,710,shoot_line_location[0],1210,shoot_line_location[0]); + Line_Draw(&UI_shoot_line[1],"sl1",UI_Graph_ADD,7,UI_Color_White,3,shoot_line_location[1],340,shoot_line_location[1],740); + Line_Draw(&UI_shoot_line[2],"sl2",UI_Graph_ADD,7,UI_Color_Yellow,2,810,shoot_line_location[2],1110,shoot_line_location[2]); + Line_Draw(&UI_shoot_line[3],"sl3",UI_Graph_ADD,7,UI_Color_Yellow,2,810,shoot_line_location[3],1110,shoot_line_location[3]); + Line_Draw(&UI_shoot_line[4],"sl4",UI_Graph_ADD,7,UI_Color_Yellow,2,810,shoot_line_location[4],1110,shoot_line_location[4]); + + UI_ReFresh(&_referee_info->referee_id,5,UI_shoot_line[0],UI_shoot_line[1],UI_shoot_line[2],UI_shoot_line[3],UI_shoot_line[4]); + + //绘制车辆状态标志,静态 + Char_Draw(&UI_State_sta[0],"ss0",UI_Graph_ADD,8,UI_Color_Main,15,2,150,750); + Char_Write(&UI_State_sta[0],"chassis:"); + Char_ReFresh(&_referee_info->referee_id,UI_State_sta[0]); + + Char_Draw(&UI_State_sta[1],"ss1",UI_Graph_ADD,8,UI_Color_Yellow,15,2,150,700); + Char_Write(&UI_State_sta[1],"gimbal:"); + Char_ReFresh(&_referee_info->referee_id,UI_State_sta[1]); + + Char_Draw(&UI_State_sta[2],"ss2",UI_Graph_ADD,8,UI_Color_Orange,15,2,150,650); + Char_Write(&UI_State_sta[2],"cover:"); + Char_ReFresh(&_referee_info->referee_id,UI_State_sta[2]); + + Char_Draw(&UI_State_sta[3],"ss3",UI_Graph_ADD,8,UI_Color_Pink,15,2,150,600); + Char_Write(&UI_State_sta[3],"frict:"); + Char_ReFresh(&_referee_info->referee_id,UI_State_sta[3]); + + //底盘功率显示,静态 + Char_Draw(&UI_State_sta[4],"ss4",UI_Graph_ADD,8,UI_Color_Green,18,2,720,210); + Char_Write(&UI_State_sta[4],"Power:"); + Char_ReFresh(&_referee_info->referee_id,UI_State_sta[4]); + + //绘制车辆状态标志,动态 + Char_Draw(&UI_State_dyn[0],"sd0",UI_Graph_ADD,8,UI_Color_Main,15,2,270,750); + Char_Write(&UI_State_dyn[0],"0000"); + Char_ReFresh(&_referee_info->referee_id,UI_State_dyn[0]); + + Char_Draw(&UI_State_dyn[1],"sd1",UI_Graph_ADD,8,UI_Color_Yellow,15,2,270,700); + Char_Write(&UI_State_dyn[1],"0000"); + Char_ReFresh(&_referee_info->referee_id,UI_State_dyn[1]); + + Char_Draw(&UI_State_dyn[2],"sd2",UI_Graph_ADD,8,UI_Color_Orange,15,2,270,650); + Char_Write(&UI_State_dyn[2],"0000"); + Char_ReFresh(&_referee_info->referee_id,UI_State_dyn[2]); + + Char_Draw(&UI_State_dyn[3],"sd3",UI_Graph_ADD,8,UI_Color_Pink,15,2,270,600); + Char_Write(&UI_State_dyn[3],"0000"); + Char_ReFresh(&_referee_info->referee_id,UI_State_dyn[3]); + + //底盘功率显示,动态 + Char_Draw(&UI_State_dyn[4],"sd4",UI_Graph_ADD,8,UI_Color_Green,18,2,840,210); + Char_Write(&UI_State_dyn[4],"0000"); + Char_ReFresh(&_referee_info->referee_id,UI_State_dyn[4]); +} + + + + +static void My_UI_Refresh(referee_info_t *_referee_info,Referee_Interactive_info_t *_Interactive_data) +{ + // syhtodo 按键刷新 + // syhtodo与上次不一样才要进入刷新,避免重复发送 + + +// switch(dbus_infomation.chassis_mode) +// { +// case rotate_mode: +// { +// Char_Draw(&UI_State[0],"s1",UI_Graph_Change,8,UI_Color_Main,15,2,150,750); +// Char_Write(&UI_State[0],"chassis:rotate"); +// break; +// } +// case back_middle_mode: +// { +// if (dbus_infomation.back_middle_mode_XL == X) +// { +// Char_Draw(&UI_State[0],"s1",UI_Graph_Change,8,UI_Color_Main,15,2,150,750); +// Char_Write(&UI_State[0],"chassis:follow_x"); +// } +// else if (dbus_infomation.back_middle_mode_XL == L) +// { +// Char_Draw(&UI_State[0],"s1",UI_Graph_Change,8,UI_Color_Main,15,2,150,750); +// Char_Write(&UI_State[0],"chassis:follow_l"); +// } +// break; +// } +// case free_mode: +// { +// Char_Draw(&UI_State[0],"s1",UI_Graph_Change,8,UI_Color_Main,15,2,150,750); +// Char_Write(&UI_State[0],"chassis:free "); +// break; +// } +// } +// Char_ReFresh(UI_State[0]); + +// switch(dbus_infomation.gimbal_mode) +// { +// case mechanical_mode: +// { +// Char_Draw(&UI_State[1],"s2",UI_Graph_Change,8,UI_Color_Yellow,15,2,150,700); +// Char_Write(&UI_State[1],"gimbal:mech "); +// break; +// } +// case visual_mode: +// { +// Char_Draw(&UI_State[1],"s2",UI_Graph_Change,8,UI_Color_Yellow,15,2,150,700); +// Char_Write(&UI_State[1],"gimbal:visual"); +// break; +// } +// case gyro_mode: +// { +// Char_Draw(&UI_State[1],"s2",UI_Graph_Change,8,UI_Color_Yellow,15,2,150,700); +// Char_Write(&UI_State[1],"gimbal:gyro "); +// break; +// } +// } +// Char_ReFresh(UI_State[1]); + +// switch(dbus_infomation.cover_state) +// { +// case cover_close_sign: +// { +// Char_Draw(&UI_State[2],"s3",UI_Graph_Change,8,UI_Color_Orange,15,2,150,650); +// Char_Write(&UI_State[2],"cover:OFF"); +// break; +// } +// case cover_open_sign: +// { +// Char_Draw(&UI_State[2],"s3",UI_Graph_Change,8,UI_Color_Orange,15,2,150,650); +// Char_Write(&UI_State[2],"cover:ON "); +// break; +// } +// } +// Char_ReFresh(UI_State[2]); + +// switch(dbus_infomation.friction_state) +// { +// case friction_stop_sign: +// { +// Char_Draw(&UI_State[3],"s4",UI_Graph_Change,8,UI_Color_Pink,15,2,150,600); +// Char_Write(&UI_State[3],"friction:OFF"); +// break; +// } +// case friction_start_sign: +// { +// Char_Draw(&UI_State[3],"s4",UI_Graph_Change,8,UI_Color_Pink,15,2,150,600); +// Char_Write(&UI_State[3],"friction:ON "); +// break; +// } +// } +// Char_ReFresh(UI_State[3]); + +// } +// else if(timer_count == PEFEREE_PERIOD_TX_C/2) +// { +// //功率值变化 +// Char_Draw(&UI_State[4],"s5",UI_Graph_Change,8,UI_Color_Green,18,2,720,240); +// Char_Write(&UI_State[4],"Voltage:%dV",super_cap_info.cap_voltage_cap); +// Char_ReFresh(UI_State[4]); +// } + +// } + + +} + + + + + +/** + * @brief 判断各种ID,选择客户端ID + * @param void + * @retval referee_info + * @attention + */ +static void determine_ID(referee_info_t *_referee_info) +{ + //id小于7是红色,大于7是蓝色,0为红色,1为蓝色 #define Robot_Red 0 #define Robot_Blue 1 + _referee_info->referee_id.Robot_Color = _referee_info->GameRobotState.robot_id >7 ? Robot_Blue : Robot_Red; + _referee_info->referee_id.Robot_ID=_referee_info->GameRobotState.robot_id; + _referee_info->referee_id.Cilent_ID = 0x0100 + _referee_info->referee_id.Robot_ID;//计算客户端ID + _referee_info->referee_id.Receiver_Robot_ID = 0x00; //机器人车间通信时接收者的ID暂时为0 +} + + + + + + + diff --git a/application/referee/referee.h b/application/referee/referee.h new file mode 100644 index 0000000..3446fbb --- /dev/null +++ b/application/referee/referee.h @@ -0,0 +1,45 @@ +#ifndef REFEREE_H +#define REFEREE_H + +#include "rm_referee.h" +#include "robot_def.h" +#pragma pack(1) + +typedef struct +{ + uint32_t chassis_flag : 1; + uint32_t gimbal_flag : 1; + uint32_t cover_flag : 1; + uint32_t friction_flag : 1; + uint32_t Power_flag : 1; + uint32_t end_angle_flag : 1; + +} Referee_Interactive_Flag_t; + + +// 此结构体包含UI绘制与机器人车间通信的需要的其他非裁判系统数据 +typedef struct +{ + Referee_Interactive_Flag_t Referee_Interactive_Flag; + //为UI绘制以及交互数据所用 + Robot_Status_e Robot_Status;// 机器人状态 + App_Status_e App_Status;// 应用状态 + chassis_mode_e chassis_mode;//底盘模式 + gimbal_mode_e gimbal_mode;//云台模式 + shoot_mode_e shoot_mode;//发射模式设置 + friction_mode_e friction_mode;//摩擦轮关闭 + lid_mode_e lid_mode;//弹舱盖打开 + loader_mode_e loader_mode;//单发...连发 + Chassis_Power_Data_s Chassis_Power_Data;// 功率控制 + +} Referee_Interactive_info_t; + +#pragma pack() + + +void Referee_Interactive_init(void); +void Referee_Interactive_task(void); +#endif // REFEREE_H + + + diff --git a/application/robot.c b/application/robot.c index 9020d70..d830aad 100644 --- a/application/robot.c +++ b/application/robot.c @@ -4,6 +4,7 @@ #if defined(ONE_BOARD) || defined(CHASSIS_BOARD) #include "chassis.h" +#include "referee.h" #endif #if defined(ONE_BOARD) || defined(GIMBAL_BOARD) @@ -23,6 +24,7 @@ void RobotInit() #endif #if defined(ONE_BOARD) || defined(CHASSIS_BOARD) + Referee_Interactive_init();//syh ChassisInit(); #endif } @@ -37,5 +39,6 @@ void RobotTask() #if defined(ONE_BOARD) || defined(CHASSIS_BOARD) ChassisTask(); + Referee_Interactive_task(); #endif } diff --git a/modules/referee/referee_UI.c b/modules/referee/referee_UI.c index 852a399..0ae93c7 100644 --- a/modules/referee/referee_UI.c +++ b/modules/referee/referee_UI.c @@ -1,91 +1,16 @@ #include "referee_UI.h" #include "string.h" #include "crc.h" -#include "bsp_usart.h" #include "stdio.h" -#include "referee.h" - -static void UI_Delete(referee_id_t *_id,uint8_t Del_Operate,uint8_t Del_Layer); -static void Line_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); -static void Rectangle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); -static void Circle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius); -static void Elliptical_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y); -static void Arc_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y, - uint32_t end_x,uint32_t end_y); -static void Float_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float); -static void Integer_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Integer); -static void Char_Draw(String_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y); -static void Char_Write(String_Data_t *graph,char* fmt, ...); -static int UI_ReFresh(referee_id_t *_id,int cnt,...); -static int Char_ReFresh(referee_id_t *_id,String_Data_t string_Data); - -static void determine_ID(referee_info_t *_referee_info); +#include "rm_referee.h" static uint8_t UI_Seq; //包序号 - -void Interactive_init(referee_info_t *_referee_info) -{ - determine_ID(_referee_info); - - - Graph_Data_t graph[5]; - Graph_Data_t num[2]; - String_Data_t sdata[1]; - memset(sdata[0].show_Data, 0, 30); //使用memset方法 syhtodo 数据存在初始化未默认为0的情况 - memset(&graph[0], 0, 15); - - UI_Delete(&_referee_info->referee_id,UI_Data_Del_ALL,0); - - Line_Draw(&graph[0],"s0",UI_Graph_ADD,0,UI_Color_White,3,710,540,1210,540); - Rectangle_Draw(&graph[1],"s1",UI_Graph_ADD,0,UI_Color_Yellow,4,600,200,800,500); - Circle_Draw(&graph[2],"s2",UI_Graph_ADD,0,UI_Color_Green,5,960,540,100); - Elliptical_Draw(&graph[3],"s3",UI_Graph_ADD,0,UI_Color_Orange,3,960,540,100,20); - Arc_Draw(&graph[4],"s4",UI_Graph_ADD,0,UI_Color_Purplish_red,30,160,3,1200,550,50,100); - - Float_Draw(&num[0],"s5",UI_Graph_ADD,0,UI_Color_Pink,50,3,5,1050,660,1245545); - Integer_Draw(&num[1],"s6",UI_Graph_ADD,0,UI_Color_Cyan,50,5,1050,460,12345); - UI_ReFresh(&_referee_info->referee_id,7,graph[0],graph[1],graph[2],graph[3],graph[4],num[0],num[1]); - - - Char_Draw(&sdata[0],"s7",UI_Graph_ADD,0,UI_Color_Green,20,2,620,710); - Char_Write(&sdata[0],"number:%d",123); - Char_ReFresh(&_referee_info->referee_id,sdata[0]); - -} - -/** - * @brief 判断各种ID,选择客户端ID - * @param void - * @retval referee_info - * @attention - */ -static void determine_ID(referee_info_t *_referee_info) -{ - //id小于7是红色,大于7是蓝色,0为红色,1为蓝色 #define Robot_Red 0 #define Robot_Blue 1 - _referee_info->referee_id.Robot_Color = _referee_info->GameRobotState.robot_id >7 ? Robot_Blue : Robot_Red; - _referee_info->referee_id.Robot_ID=_referee_info->GameRobotState.robot_id; - _referee_info->referee_id.Cilent_ID = 0x0100 + _referee_info->referee_id.Robot_ID;//计算客户端ID - _referee_info->referee_id.Receiver_Robot_ID = 0x00; //机器人车间通信时接收者的ID暂时为0 -} - - - - - - /********************************************删除操作************************************* -**参数:Del_Operate 对应头文件删除操作 +**参数:_id 对应的id结构体 + Del_Operate 对应头文件删除操作 Del_Layer 要删除的层 取值0-9 *****************************************************************************************/ -static void UI_Delete(referee_id_t *_id,uint8_t Del_Operate,uint8_t Del_Layer) +void UI_Delete(referee_id_t *_id,uint8_t Del_Operate,uint8_t Del_Layer) { UI_delete_t UI_delete_data; uint8_t temp_datalength = UI_Data_LEN_Head + UI_Operate_LEN_Del; //计算交互数据长度 @@ -122,16 +47,16 @@ static void UI_Delete(referee_id_t *_id,uint8_t Del_Operate,uint8_t Del_Layer) End_x、End_y 终点xy坐标 **********************************************************************************************************/ -static void Line_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Line_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y) { + // memset(graph,0,UI_Operate_LEN_PerDraw); //如果定义的是非静态变量,数据存在初始化未默认为0的情况,使用memset方法,以下类似 syhtodo int i; - //??????syhtodo - for(i=0;i<3&&graphname[i]!='\0';i++) + for(i=0;i<3&&graphname[i]!='\0';i++) //填充至‘0’为止 { - graph->graphic_name[2-i]=graphname[i]; + graph->graphic_name[2-i]=graphname[i]; //按内存地址增大方向填充,所以会有i与2-i } - + graph->operate_tpye = Graph_Operate; graph->graphic_tpye = UI_Graph_Line; graph->layer = Graph_Layer; @@ -154,9 +79,10 @@ static void Line_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Opera Start_x、Start_y 起点xy坐标 End_x、End_y 对角顶点xy坐标 **********************************************************************************************************/ -static void Rectangle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Rectangle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y) { + // memset(&graph,0,UI_Operate_LEN_PerDraw); int i; for(i=0;i<3&&graphname[i]!='\0';i++) { @@ -186,9 +112,10 @@ static void Rectangle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_ Graph_Radius 圆形半径 **********************************************************************************************************/ -static void Circle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Circle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius) { + // memset(&graph,0,UI_Operate_LEN_PerDraw); int i; for(i=0;i<3&&graphname[i]!='\0';i++) { @@ -215,9 +142,10 @@ static void Circle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Ope Start_x、Start_y 圆心xy坐标 End_x、End_y xy半轴长度 **********************************************************************************************************/ -static void Elliptical_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Elliptical_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y) { + // memset(&graph,0,UI_Operate_LEN_PerDraw); int i; for(i=0;i<3&&graphname[i]!='\0';i++) { @@ -249,10 +177,11 @@ static void Elliptical_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph x_Length,y_Length xy半轴长度 **********************************************************************************************************/ -static void Arc_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Arc_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y, uint32_t end_x,uint32_t end_y) { + //memset(&graph,0,UI_Operate_LEN_PerDraw); int i; for(i=0;i<3&&graphname[i]!='\0';i++) { @@ -288,9 +217,10 @@ static void Arc_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operat end_y=(a>>21)&0x7FF; **********************************************************************************************************/ -static void Float_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Float_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float) { + //memset(&graph,0,UI_Operate_LEN_PerDraw); int i; for(i=0;i<3&&graphname[i]!='\0';i++) { @@ -325,9 +255,10 @@ static void Float_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Oper end_x=(a>>10)&0x7FF; end_y=(a>>21)&0x7FF; **********************************************************************************************************/ -static void Integer_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Integer_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Integer) { + //memset(&graph,0,UI_Operate_LEN_PerDraw); int i; for(i=0;i<3&&graphname[i]!='\0';i++) { @@ -359,10 +290,11 @@ static void Integer_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Op Graph_Width 图形线宽 Start_x、Start_y 开始坐标 **********************************************************************************************************/ -static void Char_Draw(String_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, +void Char_Draw(String_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y) { - memset(graph->Graph_Control.graphic_name, 0, 3);//syhtodo 是否需要手动清零 + // //memset(graph->Graph_Control.graphic_name, 0, 3);//syhtodo 是否需要手动清零 + //memset(&graph,0,UI_Operate_LEN_DrawChar); int i; for(i=0;i<3&&graphname[i]!='\0';i++) { @@ -388,14 +320,15 @@ static void Char_Draw(String_Data_t *graph,char graphname[3],uint32_t Graph_Oper /************************************************绘制字符型数据************************************************* **参数:*graph Graph_Data类型变量指针,用于存放图形数据 fmt需要显示的字符串 + 此函数的实现和具体使用类似于printf函数 syhtodo 尚未理解该函数的写法 **********************************************************************************************************/ -static void Char_Write(String_Data_t *graph,char* fmt, ...) +void Char_Write(String_Data_t *graph,char* fmt, ...) { uint16_t i = 0; va_list ap; va_start(ap,fmt); - vsprintf((char*)graph->show_Data, fmt, ap);//使用参数列表发送格式化输出到字符串 + vsprintf((char*)graph->show_Data,fmt,ap);//使用参数列表进行格式化并输出到字符串 va_end(ap); i = strlen((const char*)graph->show_Data); graph->Graph_Control.end_angle = i; @@ -407,7 +340,7 @@ static void Char_Write(String_Data_t *graph,char* fmt, ...) ... 图形变量参数 Tips::该函数只能推送1,2,5,7个图形,其他数目协议未涉及 */ -static int UI_ReFresh(referee_id_t *_id,int cnt,...) +void UI_ReFresh(referee_id_t *_id,int cnt,...) { int i; UI_GraphReFresh_t UI_GraphReFresh_data; @@ -437,8 +370,6 @@ static int UI_ReFresh(referee_id_t *_id,int cnt,...) case 7: UI_GraphReFresh_data.datahead.data_cmd_id=UI_Data_ID_Draw7; break; - default: - return (-1); } UI_GraphReFresh_data.datahead.receiver_ID = _id->Cilent_ID; @@ -460,12 +391,10 @@ static int UI_ReFresh(referee_id_t *_id,int cnt,...) va_end(ap);//结束可变参数的获取 UI_Seq++; //包序号+1 - - return 0; } /************************************************UI推送字符(使更改生效)*********************************/ -static int Char_ReFresh(referee_id_t *_id,String_Data_t string_Data) +void Char_ReFresh(referee_id_t *_id,String_Data_t string_Data) { UI_CharReFresh_t UI_CharReFresh_data; @@ -490,6 +419,5 @@ static int Char_ReFresh(referee_id_t *_id,String_Data_t string_Data) RefereeSend((uint8_t *)&UI_CharReFresh_data,LEN_HEADER+LEN_CMDID+temp_datalength+LEN_TAIL); //发送 UI_Seq++; //包序号+1 - return 0; } \ No newline at end of file diff --git a/modules/referee/referee_UI.h b/modules/referee/referee_UI.h index 85752e2..474b966 100644 --- a/modules/referee/referee_UI.h +++ b/modules/referee/referee_UI.h @@ -2,10 +2,9 @@ #define REFEREE_UI_H #include "stdarg.h" -#include "usart.h" #include "stdint.h" #include "referee_def.h" -#include "referee.h" +#include "rm_referee.h" #pragma pack(1) //按1字节对齐 @@ -39,6 +38,40 @@ typedef struct #pragma pack() -void Interactive_init(referee_info_t *_referee_info); + + +void UI_Delete(referee_id_t *_id,uint8_t Del_Operate,uint8_t Del_Layer); + +void Line_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); + +void Rectangle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y); + +void Circle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius); + +void Elliptical_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y); + +void Arc_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y, + uint32_t end_x,uint32_t end_y); + +void Float_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float); + +void Integer_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Integer); + +void Char_Draw(String_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, + uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y); + +void Char_Write(String_Data_t *graph,char* fmt, ...); + +void UI_ReFresh(referee_id_t *_id,int cnt,...); + +void Char_ReFresh(referee_id_t *_id,String_Data_t string_Data); + #endif diff --git a/modules/referee/referee.c b/modules/referee/rm_referee.c similarity index 96% rename from modules/referee/referee.c rename to modules/referee/rm_referee.c index 7500ccf..e951374 100644 --- a/modules/referee/referee.c +++ b/modules/referee/rm_referee.c @@ -1,4 +1,15 @@ -#include "referee.h" +/** + * @file rm_referee.C + * @author kidneygood (you@domain.com) + * @brief + * @version 0.1 + * @date 2022-11-18 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "rm_referee.h" #include "string.h" #include "crc.h" #include "bsp_usart.h" diff --git a/modules/referee/referee.h b/modules/referee/rm_referee.h similarity index 86% rename from modules/referee/referee.h rename to modules/referee/rm_referee.h index 798f24b..0c22a1f 100644 --- a/modules/referee/referee.h +++ b/modules/referee/rm_referee.h @@ -1,20 +1,10 @@ -/** - * @file referee.h - * @author kidneygood (you@domain.com) - * @brief - * @version 0.1 - * @date 2022-11-18 - * - * @copyright Copyright (c) 2022 - * - */ - -#ifndef REFEREE_H -#define REFEREE_H +#ifndef RM_REFEREE_H +#define RM_REFEREE_H #include "usart.h" #include "referee_def.h" #include "bsp_usart.h" +#include "robot_def.h" #pragma pack(1) @@ -26,7 +16,7 @@ typedef struct uint16_t Receiver_Robot_ID; //机器人车间通信时接收者的ID } referee_id_t; -// 次结构体包含裁判系统接收数据以及UI绘制与机器人车间通信的相关信息 +// 此结构体包含裁判系统接收数据以及UI绘制与机器人车间通信的相关信息 typedef struct { referee_id_t referee_id; From 846a8b1cafa3dc6d9744e88271ba253f30e28d39 Mon Sep 17 00:00:00 2001 From: kidneygood <2979564623@qq.com> Date: Wed, 25 Jan 2023 22:32:13 +0800 Subject: [PATCH 11/15] =?UTF-8?q?chassis=5Fmode=E5=8A=A8=E6=80=81=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E5=AE=8C=E6=88=90=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/referee/referee.c | 409 +++++++++++++++++++--------------- application/referee/referee.h | 9 +- application/robot_def.h | 1 - 3 files changed, 238 insertions(+), 181 deletions(-) diff --git a/application/referee/referee.c b/application/referee/referee.c index 933c768..98d50f9 100644 --- a/application/referee/referee.c +++ b/application/referee/referee.c @@ -13,223 +13,276 @@ #include "rm_referee.h" #include "referee_UI.h" -static Referee_Interactive_info_t *Interactive_data;// 非裁判系统数据 -static referee_info_t *referee_data; // 裁判系统相关数据 +static Referee_Interactive_info_t Interactive_data; // 非裁判系统数据 +static referee_info_t *referee_data; // 裁判系统相关数据 static void determine_ID(referee_info_t *_referee_info); static void My_UI_init(referee_info_t *_referee_info); -static void My_UI_Refresh(referee_info_t *_referee_info,Referee_Interactive_info_t *_Interactive_data); +static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_info_t *_Interactive_data); +static void robot_mode_change(Referee_Interactive_info_t *_Interactive_data); // 测试用函数,实现模式自动变化 void Referee_Interactive_init() { referee_data = RefereeInit(&huart6); // 裁判系统初始化 - while (referee_data->GameRobotState.robot_id ==0); - + while (referee_data->GameRobotState.robot_id == 0); determine_ID(referee_data); My_UI_init(referee_data); -} +} void Referee_Interactive_task() { - My_UI_Refresh(referee_data,Interactive_data); - + robot_mode_change(&Interactive_data); // 测试用函数,实现模式自动变化 + My_UI_Refresh(referee_data, &Interactive_data); } -static Graph_Data_t UI_shoot_line[10];//射击准线 -static String_Data_t UI_State_sta[5];//机器人状态,静态只需画一次 -static String_Data_t UI_State_dyn[5];//机器人状态,动态先add才能change -static uint32_t shoot_line_location[10]={540,960,490,515,565}; +static Graph_Data_t UI_shoot_line[10]; // 射击准线 +static String_Data_t UI_State_sta[5]; // 机器人状态,静态只需画一次 +static String_Data_t UI_State_dyn[5]; // 机器人状态,动态先add才能change +static uint32_t shoot_line_location[10] = {540, 960, 490, 515, 565}; static void My_UI_init(referee_info_t *_referee_info) { - UI_Delete(&_referee_info->referee_id,UI_Data_Del_ALL,0); + UI_Delete(&_referee_info->referee_id, UI_Data_Del_ALL, 0); - //绘制发射基准线 - Line_Draw(&UI_shoot_line[0],"sl0",UI_Graph_ADD,7,UI_Color_White,3,710,shoot_line_location[0],1210,shoot_line_location[0]); - Line_Draw(&UI_shoot_line[1],"sl1",UI_Graph_ADD,7,UI_Color_White,3,shoot_line_location[1],340,shoot_line_location[1],740); - Line_Draw(&UI_shoot_line[2],"sl2",UI_Graph_ADD,7,UI_Color_Yellow,2,810,shoot_line_location[2],1110,shoot_line_location[2]); - Line_Draw(&UI_shoot_line[3],"sl3",UI_Graph_ADD,7,UI_Color_Yellow,2,810,shoot_line_location[3],1110,shoot_line_location[3]); - Line_Draw(&UI_shoot_line[4],"sl4",UI_Graph_ADD,7,UI_Color_Yellow,2,810,shoot_line_location[4],1110,shoot_line_location[4]); + // 绘制发射基准线 + Line_Draw(&UI_shoot_line[0], "sl0", UI_Graph_ADD, 7, UI_Color_White, 3, 710, shoot_line_location[0], 1210, shoot_line_location[0]); + Line_Draw(&UI_shoot_line[1], "sl1", UI_Graph_ADD, 7, UI_Color_White, 3, shoot_line_location[1], 340, shoot_line_location[1], 740); + Line_Draw(&UI_shoot_line[2], "sl2", UI_Graph_ADD, 7, UI_Color_Yellow, 2, 810, shoot_line_location[2], 1110, shoot_line_location[2]); + Line_Draw(&UI_shoot_line[3], "sl3", UI_Graph_ADD, 7, UI_Color_Yellow, 2, 810, shoot_line_location[3], 1110, shoot_line_location[3]); + Line_Draw(&UI_shoot_line[4], "sl4", UI_Graph_ADD, 7, UI_Color_Yellow, 2, 810, shoot_line_location[4], 1110, shoot_line_location[4]); - UI_ReFresh(&_referee_info->referee_id,5,UI_shoot_line[0],UI_shoot_line[1],UI_shoot_line[2],UI_shoot_line[3],UI_shoot_line[4]); + UI_ReFresh(&_referee_info->referee_id, 5, UI_shoot_line[0], UI_shoot_line[1], UI_shoot_line[2], UI_shoot_line[3], UI_shoot_line[4]); - //绘制车辆状态标志,静态 - Char_Draw(&UI_State_sta[0],"ss0",UI_Graph_ADD,8,UI_Color_Main,15,2,150,750); - Char_Write(&UI_State_sta[0],"chassis:"); - Char_ReFresh(&_referee_info->referee_id,UI_State_sta[0]); + // 绘制车辆状态标志,静态 + Char_Draw(&UI_State_sta[0], "ss0", UI_Graph_ADD, 8, UI_Color_Main, 15, 2, 150, 750); + Char_Write(&UI_State_sta[0], "chassis:"); + Char_ReFresh(&_referee_info->referee_id, UI_State_sta[0]); - Char_Draw(&UI_State_sta[1],"ss1",UI_Graph_ADD,8,UI_Color_Yellow,15,2,150,700); - Char_Write(&UI_State_sta[1],"gimbal:"); - Char_ReFresh(&_referee_info->referee_id,UI_State_sta[1]); + Char_Draw(&UI_State_sta[1], "ss1", UI_Graph_ADD, 8, UI_Color_Yellow, 15, 2, 150, 700); + Char_Write(&UI_State_sta[1], "gimbal:"); + Char_ReFresh(&_referee_info->referee_id, UI_State_sta[1]); - Char_Draw(&UI_State_sta[2],"ss2",UI_Graph_ADD,8,UI_Color_Orange,15,2,150,650); - Char_Write(&UI_State_sta[2],"cover:"); - Char_ReFresh(&_referee_info->referee_id,UI_State_sta[2]); - - Char_Draw(&UI_State_sta[3],"ss3",UI_Graph_ADD,8,UI_Color_Pink,15,2,150,600); - Char_Write(&UI_State_sta[3],"frict:"); - Char_ReFresh(&_referee_info->referee_id,UI_State_sta[3]); + Char_Draw(&UI_State_sta[2], "ss2", UI_Graph_ADD, 8, UI_Color_Orange, 15, 2, 150, 650); + Char_Write(&UI_State_sta[2], "cover:"); + Char_ReFresh(&_referee_info->referee_id, UI_State_sta[2]); - //底盘功率显示,静态 - Char_Draw(&UI_State_sta[4],"ss4",UI_Graph_ADD,8,UI_Color_Green,18,2,720,210); - Char_Write(&UI_State_sta[4],"Power:"); - Char_ReFresh(&_referee_info->referee_id,UI_State_sta[4]); + Char_Draw(&UI_State_sta[3], "ss3", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 150, 600); + Char_Write(&UI_State_sta[3], "frict:"); + Char_ReFresh(&_referee_info->referee_id, UI_State_sta[3]); - //绘制车辆状态标志,动态 - Char_Draw(&UI_State_dyn[0],"sd0",UI_Graph_ADD,8,UI_Color_Main,15,2,270,750); - Char_Write(&UI_State_dyn[0],"0000"); - Char_ReFresh(&_referee_info->referee_id,UI_State_dyn[0]); + // 底盘功率显示,静态 + Char_Draw(&UI_State_sta[4], "ss4", UI_Graph_ADD, 8, UI_Color_Green, 18, 2, 720, 210); + Char_Write(&UI_State_sta[4], "Power:"); + Char_ReFresh(&_referee_info->referee_id, UI_State_sta[4]); - Char_Draw(&UI_State_dyn[1],"sd1",UI_Graph_ADD,8,UI_Color_Yellow,15,2,270,700); - Char_Write(&UI_State_dyn[1],"0000"); - Char_ReFresh(&_referee_info->referee_id,UI_State_dyn[1]); + // 绘制车辆状态标志,动态 + //syhtodo 由于初始化时xxx_last_mode默认为0,所以此处对应UI也应该设为0时对应的UI,防止模式不变的情况下无法置位flag,导致UI无法刷新 + Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_ADD, 8, UI_Color_Main, 15, 2, 270, 750); + Char_Write(&UI_State_dyn[0], "0000"); + Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[0]); - Char_Draw(&UI_State_dyn[2],"sd2",UI_Graph_ADD,8,UI_Color_Orange,15,2,270,650); - Char_Write(&UI_State_dyn[2],"0000"); - Char_ReFresh(&_referee_info->referee_id,UI_State_dyn[2]); - - Char_Draw(&UI_State_dyn[3],"sd3",UI_Graph_ADD,8,UI_Color_Pink,15,2,270,600); - Char_Write(&UI_State_dyn[3],"0000"); - Char_ReFresh(&_referee_info->referee_id,UI_State_dyn[3]); + Char_Draw(&UI_State_dyn[1], "sd1", UI_Graph_ADD, 8, UI_Color_Yellow, 15, 2, 270, 700); + Char_Write(&UI_State_dyn[1], "0000"); + Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[1]); - //底盘功率显示,动态 - Char_Draw(&UI_State_dyn[4],"sd4",UI_Graph_ADD,8,UI_Color_Green,18,2,840,210); - Char_Write(&UI_State_dyn[4],"0000"); - Char_ReFresh(&_referee_info->referee_id,UI_State_dyn[4]); + Char_Draw(&UI_State_dyn[2], "sd2", UI_Graph_ADD, 8, UI_Color_Orange, 15, 2, 270, 650); + Char_Write(&UI_State_dyn[2], "0000"); + Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[2]); + + Char_Draw(&UI_State_dyn[3], "sd3", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 270, 600); + Char_Write(&UI_State_dyn[3], "0000"); + Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[3]); + + // 底盘功率显示,动态 + Char_Draw(&UI_State_dyn[4], "sd4", UI_Graph_ADD, 8, UI_Color_Green, 18, 2, 840, 210); + Char_Write(&UI_State_dyn[4], "0000"); + Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[4]); } +static uint8_t count = 0; +static uint16_t count1 = 0; +static void robot_mode_change(Referee_Interactive_info_t *_Interactive_data) // 测试用函数,实现模式自动变化 +{ + count++; + if (count >= 50) + { + count = 0; + count1++; + } + switch (count1%4) + { + case 0: + { + _Interactive_data->chassis_mode =CHASSIS_ZERO_FORCE; + _Interactive_data->gimbal_mode =GIMBAL_ZERO_FORCE; + _Interactive_data->shoot_mode = SHOOT_ON; + _Interactive_data->friction_mode = FRICTION_ON; + _Interactive_data->lid_mode = LID_OPEN; + break; + } + case 1: + {; + _Interactive_data->chassis_mode =CHASSIS_ROTATE; + _Interactive_data->gimbal_mode =GIMBAL_FREE_MODE; + _Interactive_data->shoot_mode = SHOOT_OFF; + _Interactive_data->friction_mode = FRICTION_OFF; + _Interactive_data->lid_mode = LID_CLOSE; + break; + } + case 2: + { + _Interactive_data->chassis_mode =CHASSIS_NO_FOLLOW; + _Interactive_data->gimbal_mode =GIMBAL_GYRO_MODE; + _Interactive_data->shoot_mode = SHOOT_ON; + _Interactive_data->friction_mode = FRICTION_ON; + _Interactive_data->lid_mode = LID_OPEN; + break; + } + case 3: + { + _Interactive_data->chassis_mode =CHASSIS_FOLLOW_GIMBAL_YAW; + _Interactive_data->gimbal_mode =GIMBAL_ZERO_FORCE; + _Interactive_data->shoot_mode = SHOOT_OFF; + _Interactive_data->friction_mode = FRICTION_OFF; + _Interactive_data->lid_mode = LID_CLOSE; + break; + } + default : break; + } +} - -static void My_UI_Refresh(referee_info_t *_referee_info,Referee_Interactive_info_t *_Interactive_data) +static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_info_t *_Interactive_data) { // syhtodo 按键刷新 - // syhtodo与上次不一样才要进入刷新,避免重复发送 + // syhtodo与上次不一样才要进入刷新,避免重复发送,使用新结构体flag + if (_Interactive_data->chassis_mode !=_Interactive_data->chassis_last_mode) + { + _Interactive_data->Referee_Interactive_Flag.chassis_flag=1; + _Interactive_data->chassis_last_mode = _Interactive_data->chassis_mode; + } + + if (_Interactive_data->Referee_Interactive_Flag.chassis_flag==1) + { + switch(_Interactive_data->chassis_mode) + { + case CHASSIS_ZERO_FORCE: + { + Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750); + Char_Write(&UI_State_dyn[0], "zeroforce"); + break; + } + case CHASSIS_ROTATE: + { + Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750); + Char_Write(&UI_State_dyn[0], "rotate "); //此处注意字数对齐问题,字数相同才能覆盖掉 + break; + } + case CHASSIS_NO_FOLLOW: + { + Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750); + Char_Write(&UI_State_dyn[0], "nofollow "); + break; + } + case CHASSIS_FOLLOW_GIMBAL_YAW: + { + Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750); + Char_Write(&UI_State_dyn[0], "follow "); + break; + } + } + + Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[0]); + _Interactive_data->Referee_Interactive_Flag.chassis_flag=0; + } -// switch(dbus_infomation.chassis_mode) -// { -// case rotate_mode: -// { -// Char_Draw(&UI_State[0],"s1",UI_Graph_Change,8,UI_Color_Main,15,2,150,750); -// Char_Write(&UI_State[0],"chassis:rotate"); -// break; -// } -// case back_middle_mode: -// { -// if (dbus_infomation.back_middle_mode_XL == X) -// { -// Char_Draw(&UI_State[0],"s1",UI_Graph_Change,8,UI_Color_Main,15,2,150,750); -// Char_Write(&UI_State[0],"chassis:follow_x"); -// } -// else if (dbus_infomation.back_middle_mode_XL == L) -// { -// Char_Draw(&UI_State[0],"s1",UI_Graph_Change,8,UI_Color_Main,15,2,150,750); -// Char_Write(&UI_State[0],"chassis:follow_l"); -// } -// break; -// } -// case free_mode: -// { -// Char_Draw(&UI_State[0],"s1",UI_Graph_Change,8,UI_Color_Main,15,2,150,750); -// Char_Write(&UI_State[0],"chassis:free "); -// break; -// } -// } -// Char_ReFresh(UI_State[0]); - -// switch(dbus_infomation.gimbal_mode) -// { -// case mechanical_mode: -// { -// Char_Draw(&UI_State[1],"s2",UI_Graph_Change,8,UI_Color_Yellow,15,2,150,700); -// Char_Write(&UI_State[1],"gimbal:mech "); -// break; -// } -// case visual_mode: -// { -// Char_Draw(&UI_State[1],"s2",UI_Graph_Change,8,UI_Color_Yellow,15,2,150,700); -// Char_Write(&UI_State[1],"gimbal:visual"); -// break; -// } -// case gyro_mode: -// { -// Char_Draw(&UI_State[1],"s2",UI_Graph_Change,8,UI_Color_Yellow,15,2,150,700); -// Char_Write(&UI_State[1],"gimbal:gyro "); -// break; -// } -// } -// Char_ReFresh(UI_State[1]); - -// switch(dbus_infomation.cover_state) -// { -// case cover_close_sign: -// { -// Char_Draw(&UI_State[2],"s3",UI_Graph_Change,8,UI_Color_Orange,15,2,150,650); -// Char_Write(&UI_State[2],"cover:OFF"); -// break; -// } -// case cover_open_sign: -// { -// Char_Draw(&UI_State[2],"s3",UI_Graph_Change,8,UI_Color_Orange,15,2,150,650); -// Char_Write(&UI_State[2],"cover:ON "); -// break; -// } -// } -// Char_ReFresh(UI_State[2]); - -// switch(dbus_infomation.friction_state) -// { -// case friction_stop_sign: -// { -// Char_Draw(&UI_State[3],"s4",UI_Graph_Change,8,UI_Color_Pink,15,2,150,600); -// Char_Write(&UI_State[3],"friction:OFF"); -// break; -// } -// case friction_start_sign: -// { -// Char_Draw(&UI_State[3],"s4",UI_Graph_Change,8,UI_Color_Pink,15,2,150,600); -// Char_Write(&UI_State[3],"friction:ON "); -// break; -// } -// } -// Char_ReFresh(UI_State[3]); - -// } -// else if(timer_count == PEFEREE_PERIOD_TX_C/2) -// { -// //功率值变化 -// Char_Draw(&UI_State[4],"s5",UI_Graph_Change,8,UI_Color_Green,18,2,720,240); -// Char_Write(&UI_State[4],"Voltage:%dV",super_cap_info.cap_voltage_cap); -// Char_ReFresh(UI_State[4]); -// } - -// } + + + + + + // switch(dbus_infomation.gimbal_mode) + // { + // case mechanical_mode: + // { + // Char_Draw(&UI_State[1],"s2",UI_Graph_Change,8,UI_Color_Yellow,15,2,150,700); + // Char_Write(&UI_State[1],"gimbal:mech "); + // break; + // } + // case visual_mode: + // { + // Char_Draw(&UI_State[1],"s2",UI_Graph_Change,8,UI_Color_Yellow,15,2,150,700); + // Char_Write(&UI_State[1],"gimbal:visual"); + // break; + // } + // case gyro_mode: + // { + // Char_Draw(&UI_State[1],"s2",UI_Graph_Change,8,UI_Color_Yellow,15,2,150,700); + // Char_Write(&UI_State[1],"gimbal:gyro "); + // break; + // } + // } + // Char_ReFresh(UI_State[1]); + + // switch(dbus_infomation.cover_state) + // { + // case cover_close_sign: + // { + // Char_Draw(&UI_State[2],"s3",UI_Graph_Change,8,UI_Color_Orange,15,2,150,650); + // Char_Write(&UI_State[2],"cover:OFF"); + // break; + // } + // case cover_open_sign: + // { + // Char_Draw(&UI_State[2],"s3",UI_Graph_Change,8,UI_Color_Orange,15,2,150,650); + // Char_Write(&UI_State[2],"cover:ON "); + // break; + // } + // } + // Char_ReFresh(UI_State[2]); + + // switch(dbus_infomation.friction_state) + // { + // case friction_stop_sign: + // { + // Char_Draw(&UI_State[3],"s4",UI_Graph_Change,8,UI_Color_Pink,15,2,150,600); + // Char_Write(&UI_State[3],"friction:OFF"); + // break; + // } + // case friction_start_sign: + // { + // Char_Draw(&UI_State[3],"s4",UI_Graph_Change,8,UI_Color_Pink,15,2,150,600); + // Char_Write(&UI_State[3],"friction:ON "); + // break; + // } + // } + // Char_ReFresh(UI_State[3]); + + // } + // else if(timer_count == PEFEREE_PERIOD_TX_C/2) + // { + // //功率值变化 + // Char_Draw(&UI_State[4],"s5",UI_Graph_Change,8,UI_Color_Green,18,2,720,240); + // Char_Write(&UI_State[4],"Voltage:%dV",super_cap_info.cap_voltage_cap); + // Char_ReFresh(UI_State[4]); + // } + + // } } - - - - /** - * @brief 判断各种ID,选择客户端ID - * @param void - * @retval referee_info - * @attention - */ + * @brief 判断各种ID,选择客户端ID + * @param void + * @retval referee_info + * @attention + */ static void determine_ID(referee_info_t *_referee_info) { - //id小于7是红色,大于7是蓝色,0为红色,1为蓝色 #define Robot_Red 0 #define Robot_Blue 1 - _referee_info->referee_id.Robot_Color = _referee_info->GameRobotState.robot_id >7 ? Robot_Blue : Robot_Red; - _referee_info->referee_id.Robot_ID=_referee_info->GameRobotState.robot_id; - _referee_info->referee_id.Cilent_ID = 0x0100 + _referee_info->referee_id.Robot_ID;//计算客户端ID - _referee_info->referee_id.Receiver_Robot_ID = 0x00; //机器人车间通信时接收者的ID暂时为0 + // id小于7是红色,大于7是蓝色,0为红色,1为蓝色 #define Robot_Red 0 #define Robot_Blue 1 + _referee_info->referee_id.Robot_Color = _referee_info->GameRobotState.robot_id > 7 ? Robot_Blue : Robot_Red; + _referee_info->referee_id.Robot_ID = _referee_info->GameRobotState.robot_id; + _referee_info->referee_id.Cilent_ID = 0x0100 + _referee_info->referee_id.Robot_ID; // 计算客户端ID + _referee_info->referee_id.Receiver_Robot_ID = 0x00; // 机器人车间通信时接收者的ID暂时为0 } - - - - - - - diff --git a/application/referee/referee.h b/application/referee/referee.h index 3446fbb..8f6bf54 100644 --- a/application/referee/referee.h +++ b/application/referee/referee.h @@ -5,6 +5,7 @@ #include "robot_def.h" #pragma pack(1) +//模式是否切换标志位,0为未切换,1为切换,static定义默认为0 typedef struct { uint32_t chassis_flag : 1; @@ -13,7 +14,6 @@ typedef struct uint32_t friction_flag : 1; uint32_t Power_flag : 1; uint32_t end_angle_flag : 1; - } Referee_Interactive_Flag_t; @@ -32,11 +32,16 @@ typedef struct loader_mode_e loader_mode;//单发...连发 Chassis_Power_Data_s Chassis_Power_Data;// 功率控制 + chassis_mode_e chassis_last_mode;//底盘模式 + gimbal_mode_e gimbal_last_mode;//云台模式 + shoot_mode_e shoot_last_mode;//发射模式设置 + friction_mode_e friction_last_mode;//摩擦轮关闭 + lid_mode_e lid_last_mode;//弹舱盖打开 + } Referee_Interactive_info_t; #pragma pack() - void Referee_Interactive_init(void); void Referee_Interactive_task(void); #endif // REFEREE_H diff --git a/application/robot_def.h b/application/robot_def.h index a4fe70d..c877e60 100644 --- a/application/robot_def.h +++ b/application/robot_def.h @@ -127,7 +127,6 @@ typedef enum // 功率限制,从裁判系统获取 typedef struct { // 功率控制 - } Chassis_Power_Data_s; /* ----------------CMD应用发布的控制数据,应当由gimbal/chassis/shoot订阅---------------- */ From 67940a4e388afc53dabf77601565c86b09e4a83a Mon Sep 17 00:00:00 2001 From: kidneygood <2979564623@qq.com> Date: Thu, 26 Jan 2023 15:07:00 +0800 Subject: [PATCH 12/15] =?UTF-8?q?=E5=8A=A8=E6=80=81UI=E6=A0=B7=E4=BE=8B?= =?UTF-8?q?=E7=BB=98=E5=88=B6=E3=80=81=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/gimbal/gimbal.c | 3 +- application/referee/referee.c | 393 ++++++++++++++++++++-------------- application/referee/referee.h | 4 +- modules/referee/referee_UI.c | 3 +- modules/referee/referee_def.h | 4 +- modules/referee/rm_referee.c | 2 +- 6 files changed, 233 insertions(+), 176 deletions(-) diff --git a/application/gimbal/gimbal.c b/application/gimbal/gimbal.c index c193e87..e7ef766 100644 --- a/application/gimbal/gimbal.c +++ b/application/gimbal/gimbal.c @@ -16,8 +16,7 @@ static Gimbal_Ctrl_Cmd_s gimbal_cmd_recv; // 来自cmd的控制信息 void GimbalInit() { - /* syh referee不需要imu - 暂时关闭以加快初始化速度 */ + /* syh referee不需要imu暂时关闭以加快初始化速度 */ // gimba_IMU_data = INS_Init(); // IMU先初始化,获取姿态数据指针赋给yaw电机的其他数据来源 // YAW diff --git a/application/referee/referee.c b/application/referee/referee.c index 98d50f9..7915f2a 100644 --- a/application/referee/referee.c +++ b/application/referee/referee.c @@ -14,16 +14,18 @@ #include "referee_UI.h" static Referee_Interactive_info_t Interactive_data; // 非裁判系统数据 -static referee_info_t *referee_data; // 裁判系统相关数据 +static referee_info_t *referee_data; // 裁判系统相关数据 static void determine_ID(referee_info_t *_referee_info); static void My_UI_init(referee_info_t *_referee_info); static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_info_t *_Interactive_data); static void robot_mode_change(Referee_Interactive_info_t *_Interactive_data); // 测试用函数,实现模式自动变化 +static void Mode_Change_Check(Referee_Interactive_info_t *_Interactive_data); // 模式切换检测 void Referee_Interactive_init() { referee_data = RefereeInit(&huart6); // 裁判系统初始化 - while (referee_data->GameRobotState.robot_id == 0); + while (referee_data->GameRobotState.robot_id == 0) + ; determine_ID(referee_data); My_UI_init(referee_data); } @@ -35,8 +37,8 @@ void Referee_Interactive_task() } static Graph_Data_t UI_shoot_line[10]; // 射击准线 -static String_Data_t UI_State_sta[5]; // 机器人状态,静态只需画一次 -static String_Data_t UI_State_dyn[5]; // 机器人状态,动态先add才能change +static String_Data_t UI_State_sta[6]; // 机器人状态,静态只需画一次 +static String_Data_t UI_State_dyn[6]; // 机器人状态,动态先add才能change static uint32_t shoot_line_location[10] = {540, 960, 490, 515, 565}; static void My_UI_init(referee_info_t *_referee_info) @@ -62,40 +64,48 @@ static void My_UI_init(referee_info_t *_referee_info) Char_ReFresh(&_referee_info->referee_id, UI_State_sta[1]); Char_Draw(&UI_State_sta[2], "ss2", UI_Graph_ADD, 8, UI_Color_Orange, 15, 2, 150, 650); - Char_Write(&UI_State_sta[2], "cover:"); + Char_Write(&UI_State_sta[2], "shoot:"); Char_ReFresh(&_referee_info->referee_id, UI_State_sta[2]); Char_Draw(&UI_State_sta[3], "ss3", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 150, 600); Char_Write(&UI_State_sta[3], "frict:"); Char_ReFresh(&_referee_info->referee_id, UI_State_sta[3]); - // 底盘功率显示,静态 - Char_Draw(&UI_State_sta[4], "ss4", UI_Graph_ADD, 8, UI_Color_Green, 18, 2, 720, 210); - Char_Write(&UI_State_sta[4], "Power:"); + Char_Draw(&UI_State_sta[4], "ss4", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 150, 550); + Char_Write(&UI_State_sta[4], "lid:"); Char_ReFresh(&_referee_info->referee_id, UI_State_sta[4]); - // 绘制车辆状态标志,动态 - //syhtodo 由于初始化时xxx_last_mode默认为0,所以此处对应UI也应该设为0时对应的UI,防止模式不变的情况下无法置位flag,导致UI无法刷新 + // 底盘功率显示,静态 + Char_Draw(&UI_State_sta[5], "ss5", UI_Graph_ADD, 8, UI_Color_Green, 18, 2, 720, 210); + Char_Write(&UI_State_sta[5], "Power:"); + Char_ReFresh(&_referee_info->referee_id, UI_State_sta[5]); + + // 绘制车辆状态标志,动态 + // 由于初始化时xxx_last_mode默认为0,所以此处对应UI也应该设为0时对应的UI,防止模式不变的情况下无法置位flag,导致UI无法刷新 Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_ADD, 8, UI_Color_Main, 15, 2, 270, 750); - Char_Write(&UI_State_dyn[0], "0000"); + Char_Write(&UI_State_dyn[0], "zeroforce"); Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[0]); Char_Draw(&UI_State_dyn[1], "sd1", UI_Graph_ADD, 8, UI_Color_Yellow, 15, 2, 270, 700); - Char_Write(&UI_State_dyn[1], "0000"); + Char_Write(&UI_State_dyn[1], "zeroforce"); Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[1]); Char_Draw(&UI_State_dyn[2], "sd2", UI_Graph_ADD, 8, UI_Color_Orange, 15, 2, 270, 650); - Char_Write(&UI_State_dyn[2], "0000"); + Char_Write(&UI_State_dyn[2], "off"); Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[2]); Char_Draw(&UI_State_dyn[3], "sd3", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 270, 600); - Char_Write(&UI_State_dyn[3], "0000"); + Char_Write(&UI_State_dyn[3], "off"); Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[3]); - // 底盘功率显示,动态 - Char_Draw(&UI_State_dyn[4], "sd4", UI_Graph_ADD, 8, UI_Color_Green, 18, 2, 840, 210); - Char_Write(&UI_State_dyn[4], "0000"); + Char_Draw(&UI_State_dyn[4], "sd4", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 270, 550); + Char_Write(&UI_State_dyn[4], "open "); Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[4]); + + // 底盘功率显示,动态 + Char_Draw(&UI_State_dyn[5], "sd5", UI_Graph_ADD, 8, UI_Color_Green, 18, 2, 840, 210); + Char_Write(&UI_State_dyn[5], "0000"); + Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[5]); } static uint8_t count = 0; @@ -108,174 +118,225 @@ static void robot_mode_change(Referee_Interactive_info_t *_Interactive_data) // count = 0; count1++; } - switch (count1%4) + switch (count1 % 4) { - case 0: - { - _Interactive_data->chassis_mode =CHASSIS_ZERO_FORCE; - _Interactive_data->gimbal_mode =GIMBAL_ZERO_FORCE; - _Interactive_data->shoot_mode = SHOOT_ON; - _Interactive_data->friction_mode = FRICTION_ON; - _Interactive_data->lid_mode = LID_OPEN; - break; - - } - case 1: - {; - _Interactive_data->chassis_mode =CHASSIS_ROTATE; - _Interactive_data->gimbal_mode =GIMBAL_FREE_MODE; - _Interactive_data->shoot_mode = SHOOT_OFF; - _Interactive_data->friction_mode = FRICTION_OFF; - _Interactive_data->lid_mode = LID_CLOSE; - break; - } - case 2: - { - _Interactive_data->chassis_mode =CHASSIS_NO_FOLLOW; - _Interactive_data->gimbal_mode =GIMBAL_GYRO_MODE; - _Interactive_data->shoot_mode = SHOOT_ON; - _Interactive_data->friction_mode = FRICTION_ON; - _Interactive_data->lid_mode = LID_OPEN; - break; - } - case 3: - { - _Interactive_data->chassis_mode =CHASSIS_FOLLOW_GIMBAL_YAW; - _Interactive_data->gimbal_mode =GIMBAL_ZERO_FORCE; - _Interactive_data->shoot_mode = SHOOT_OFF; - _Interactive_data->friction_mode = FRICTION_OFF; - _Interactive_data->lid_mode = LID_CLOSE; - break; - } - default : break; - } + case 0: + { + _Interactive_data->chassis_mode = CHASSIS_ZERO_FORCE; + _Interactive_data->gimbal_mode = GIMBAL_ZERO_FORCE; + _Interactive_data->shoot_mode = SHOOT_ON; + _Interactive_data->friction_mode = FRICTION_ON; + _Interactive_data->lid_mode = LID_OPEN; + break; + } + case 1: + { + ; + _Interactive_data->chassis_mode = CHASSIS_ROTATE; + _Interactive_data->gimbal_mode = GIMBAL_FREE_MODE; + _Interactive_data->shoot_mode = SHOOT_OFF; + _Interactive_data->friction_mode = FRICTION_OFF; + _Interactive_data->lid_mode = LID_CLOSE; + break; + } + case 2: + { + _Interactive_data->chassis_mode = CHASSIS_NO_FOLLOW; + _Interactive_data->gimbal_mode = GIMBAL_GYRO_MODE; + _Interactive_data->shoot_mode = SHOOT_ON; + _Interactive_data->friction_mode = FRICTION_ON; + _Interactive_data->lid_mode = LID_OPEN; + break; + } + case 3: + { + _Interactive_data->chassis_mode = CHASSIS_FOLLOW_GIMBAL_YAW; + _Interactive_data->gimbal_mode = GIMBAL_ZERO_FORCE; + _Interactive_data->shoot_mode = SHOOT_OFF; + _Interactive_data->friction_mode = FRICTION_OFF; + _Interactive_data->lid_mode = LID_CLOSE; + break; + } + default: + break; + } } static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_info_t *_Interactive_data) { // syhtodo 按键刷新 - // syhtodo与上次不一样才要进入刷新,避免重复发送,使用新结构体flag - if (_Interactive_data->chassis_mode !=_Interactive_data->chassis_last_mode) + + Mode_Change_Check(_Interactive_data); + // chassis + if (_Interactive_data->Referee_Interactive_Flag.chassis_flag == 1) { - _Interactive_data->Referee_Interactive_Flag.chassis_flag=1; + switch (_Interactive_data->chassis_mode) + { + case CHASSIS_ZERO_FORCE: + { + Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750); + Char_Write(&UI_State_dyn[0], "zeroforce"); + break; + } + case CHASSIS_ROTATE: + { + Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750); + Char_Write(&UI_State_dyn[0], "rotate "); // 此处注意字数对齐问题,字数相同才能覆盖掉 + break; + } + case CHASSIS_NO_FOLLOW: + { + Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750); + Char_Write(&UI_State_dyn[0], "nofollow "); + break; + } + case CHASSIS_FOLLOW_GIMBAL_YAW: + { + Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750); + Char_Write(&UI_State_dyn[0], "follow "); + break; + } + } + Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[0]); + _Interactive_data->Referee_Interactive_Flag.chassis_flag = 0; + } + // gimbal + if (_Interactive_data->Referee_Interactive_Flag.gimbal_flag == 1) + { + switch (_Interactive_data->gimbal_mode) + { + case GIMBAL_ZERO_FORCE: + { + Char_Draw(&UI_State_dyn[1], "sd1", UI_Graph_Change, 8, UI_Color_Yellow, 15, 2, 270, 700); + Char_Write(&UI_State_dyn[1], "zeroforce"); + break; + } + case GIMBAL_FREE_MODE: + { + Char_Draw(&UI_State_dyn[1], "sd1", UI_Graph_Change, 8, UI_Color_Yellow, 15, 2, 270, 700); + Char_Write(&UI_State_dyn[1], "free "); + break; + } + case GIMBAL_GYRO_MODE: + { + Char_Draw(&UI_State_dyn[1], "sd1", UI_Graph_Change, 8, UI_Color_Yellow, 15, 2, 270, 700); + Char_Write(&UI_State_dyn[1], "gyro "); + break; + } + } + Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[1]); + _Interactive_data->Referee_Interactive_Flag.gimbal_flag = 0; + } + // shoot + if (_Interactive_data->Referee_Interactive_Flag.shoot_flag == 1) + { + switch (_Interactive_data->shoot_mode) + { + case SHOOT_OFF: + { + Char_Draw(&UI_State_dyn[2], "sd2", UI_Graph_Change, 8, UI_Color_Orange, 15, 2, 270, 650); + Char_Write(&UI_State_dyn[2], "off"); + break; + } + case SHOOT_ON: + { + Char_Draw(&UI_State_dyn[2], "sd2", UI_Graph_Change, 8, UI_Color_Orange, 15, 2, 270, 650); + Char_Write(&UI_State_dyn[2], "on "); + break; + } + } + Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[2]); + _Interactive_data->Referee_Interactive_Flag.shoot_flag = 0; + } + + // friction + if (_Interactive_data->Referee_Interactive_Flag.friction_flag == 1) + { + switch (_Interactive_data->friction_mode) + { + case FRICTION_OFF: + { + Char_Draw(&UI_State_dyn[3], "sd3", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 600); + Char_Write(&UI_State_dyn[3], "off"); + break; + } + case FRICTION_ON: + { + Char_Draw(&UI_State_dyn[3], "sd3", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 600); + Char_Write(&UI_State_dyn[3], "on "); + break; + } + } + Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[3]); + _Interactive_data->Referee_Interactive_Flag.friction_flag = 0; + } + // lid + if (_Interactive_data->Referee_Interactive_Flag.lid_flag == 1) + { + switch (_Interactive_data->lid_mode) + { + case LID_CLOSE: + { + Char_Draw(&UI_State_dyn[4], "sd4", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 550); + Char_Write(&UI_State_dyn[4], "close"); + break; + } + case LID_OPEN: + { + Char_Draw(&UI_State_dyn[4], "sd4", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 550); + Char_Write(&UI_State_dyn[4], "open "); + break; + } + } + Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[4]); + _Interactive_data->Referee_Interactive_Flag.lid_flag = 0; + } +} + + +/** + * @brief 模式切换检测,模式发生切换时,对flag置位 + * @param Referee_Interactive_info_t *_Interactive_data + * @retval none + * @attention + */ +static void Mode_Change_Check(Referee_Interactive_info_t *_Interactive_data) +{ + if (_Interactive_data->chassis_mode != _Interactive_data->chassis_last_mode) + { + _Interactive_data->Referee_Interactive_Flag.chassis_flag = 1; _Interactive_data->chassis_last_mode = _Interactive_data->chassis_mode; } - if (_Interactive_data->Referee_Interactive_Flag.chassis_flag==1) + if (_Interactive_data->gimbal_mode != _Interactive_data->gimbal_last_mode) { - switch(_Interactive_data->chassis_mode) - { - case CHASSIS_ZERO_FORCE: - { - Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750); - Char_Write(&UI_State_dyn[0], "zeroforce"); - break; - } - case CHASSIS_ROTATE: - { - Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750); - Char_Write(&UI_State_dyn[0], "rotate "); //此处注意字数对齐问题,字数相同才能覆盖掉 - break; - } - case CHASSIS_NO_FOLLOW: - { - Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750); - Char_Write(&UI_State_dyn[0], "nofollow "); - break; - } - case CHASSIS_FOLLOW_GIMBAL_YAW: - { - Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750); - Char_Write(&UI_State_dyn[0], "follow "); - break; - } - } - - Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[0]); - _Interactive_data->Referee_Interactive_Flag.chassis_flag=0; + _Interactive_data->Referee_Interactive_Flag.gimbal_flag = 1; + _Interactive_data->gimbal_last_mode = _Interactive_data->gimbal_mode; } + if (_Interactive_data->shoot_mode != _Interactive_data->shoot_last_mode) + { + _Interactive_data->Referee_Interactive_Flag.shoot_flag = 1; + _Interactive_data->shoot_last_mode = _Interactive_data->shoot_mode; + } + if (_Interactive_data->friction_mode != _Interactive_data->friction_last_mode) + { + _Interactive_data->Referee_Interactive_Flag.friction_flag = 1; + _Interactive_data->friction_last_mode = _Interactive_data->friction_mode; + } - - - - - - - // switch(dbus_infomation.gimbal_mode) - // { - // case mechanical_mode: - // { - // Char_Draw(&UI_State[1],"s2",UI_Graph_Change,8,UI_Color_Yellow,15,2,150,700); - // Char_Write(&UI_State[1],"gimbal:mech "); - // break; - // } - // case visual_mode: - // { - // Char_Draw(&UI_State[1],"s2",UI_Graph_Change,8,UI_Color_Yellow,15,2,150,700); - // Char_Write(&UI_State[1],"gimbal:visual"); - // break; - // } - // case gyro_mode: - // { - // Char_Draw(&UI_State[1],"s2",UI_Graph_Change,8,UI_Color_Yellow,15,2,150,700); - // Char_Write(&UI_State[1],"gimbal:gyro "); - // break; - // } - // } - // Char_ReFresh(UI_State[1]); - - // switch(dbus_infomation.cover_state) - // { - // case cover_close_sign: - // { - // Char_Draw(&UI_State[2],"s3",UI_Graph_Change,8,UI_Color_Orange,15,2,150,650); - // Char_Write(&UI_State[2],"cover:OFF"); - // break; - // } - // case cover_open_sign: - // { - // Char_Draw(&UI_State[2],"s3",UI_Graph_Change,8,UI_Color_Orange,15,2,150,650); - // Char_Write(&UI_State[2],"cover:ON "); - // break; - // } - // } - // Char_ReFresh(UI_State[2]); - - // switch(dbus_infomation.friction_state) - // { - // case friction_stop_sign: - // { - // Char_Draw(&UI_State[3],"s4",UI_Graph_Change,8,UI_Color_Pink,15,2,150,600); - // Char_Write(&UI_State[3],"friction:OFF"); - // break; - // } - // case friction_start_sign: - // { - // Char_Draw(&UI_State[3],"s4",UI_Graph_Change,8,UI_Color_Pink,15,2,150,600); - // Char_Write(&UI_State[3],"friction:ON "); - // break; - // } - // } - // Char_ReFresh(UI_State[3]); - - // } - // else if(timer_count == PEFEREE_PERIOD_TX_C/2) - // { - // //功率值变化 - // Char_Draw(&UI_State[4],"s5",UI_Graph_Change,8,UI_Color_Green,18,2,720,240); - // Char_Write(&UI_State[4],"Voltage:%dV",super_cap_info.cap_voltage_cap); - // Char_ReFresh(UI_State[4]); - // } - - // } + if (_Interactive_data->lid_mode != _Interactive_data->lid_last_mode) + { + _Interactive_data->Referee_Interactive_Flag.lid_flag = 1; + _Interactive_data->lid_last_mode = _Interactive_data->lid_mode; + } } /** * @brief 判断各种ID,选择客户端ID - * @param void - * @retval referee_info + * @param referee_info_t *_referee_info + * @retval none * @attention */ static void determine_ID(referee_info_t *_referee_info) diff --git a/application/referee/referee.h b/application/referee/referee.h index 8f6bf54..d531d5a 100644 --- a/application/referee/referee.h +++ b/application/referee/referee.h @@ -10,10 +10,10 @@ typedef struct { uint32_t chassis_flag : 1; uint32_t gimbal_flag : 1; - uint32_t cover_flag : 1; + uint32_t shoot_flag : 1; + uint32_t lid_flag : 1; uint32_t friction_flag : 1; uint32_t Power_flag : 1; - uint32_t end_angle_flag : 1; } Referee_Interactive_Flag_t; diff --git a/modules/referee/referee_UI.c b/modules/referee/referee_UI.c index 0ae93c7..074e323 100644 --- a/modules/referee/referee_UI.c +++ b/modules/referee/referee_UI.c @@ -30,7 +30,7 @@ void UI_Delete(referee_id_t *_id,uint8_t Del_Operate,uint8_t Del_Layer) UI_delete_data.Layer = Del_Layer; UI_delete_data.frametail = Get_CRC16_Check_Sum((uint8_t *)&UI_delete_data,LEN_HEADER+LEN_CMDID+temp_datalength,0xFFFF); - /* syhtodo为什么填入0xFFFF */ + /* syhtodo为什么填入0xFFFF,关于crc校验 */ RefereeSend((uint8_t *)&UI_delete_data,LEN_HEADER+LEN_CMDID+temp_datalength+LEN_TAIL); //发送 @@ -321,7 +321,6 @@ void Char_Draw(String_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uin **参数:*graph Graph_Data类型变量指针,用于存放图形数据 fmt需要显示的字符串 此函数的实现和具体使用类似于printf函数 -syhtodo 尚未理解该函数的写法 **********************************************************************************************************/ void Char_Write(String_Data_t *graph,char* fmt, ...) { diff --git a/modules/referee/referee_def.h b/modules/referee/referee_def.h index e598af3..ac82dfb 100644 --- a/modules/referee/referee_def.h +++ b/modules/referee/referee_def.h @@ -228,9 +228,7 @@ typedef struct /****************************机器人间交互数据****************************/ /****************************机器人间交互数据****************************/ -/* 发送的内容数据段最大为 113 检测是否超出大小限制 -实际上图形段不会超,数据段最多30个,也不会超,检查验证一下 - syhtodo */ +/* 发送的内容数据段最大为 113 检测是否超出大小限制?实际上图形段不会超,数据段最多30个,也不会超下*/ /* 交互数据头结构 */ typedef struct { diff --git a/modules/referee/rm_referee.c b/modules/referee/rm_referee.c index e951374..b73b32c 100644 --- a/modules/referee/rm_referee.c +++ b/modules/referee/rm_referee.c @@ -40,7 +40,7 @@ referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle) void RefereeSend(uint8_t *send,uint16_t tx_len) { USARTSend(referee_usart_instance,send,tx_len); - /* syhtodo DMA请求过快会导致数据发送丢失,考虑数据尽可能打成一个整包以及队列发送 */ + /* syhtodo DMA请求过快会导致数据发送丢失,考虑数据尽可能打成一个整包以及队列发送,并且发送函数添加缓冲区 */ HAL_Delay(5); } From dc68657c16868daf5b7016831fbabe13b2f1067b Mon Sep 17 00:00:00 2001 From: kidneygood <2979564623@qq.com> Date: Thu, 26 Jan 2023 19:52:07 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=E6=95=B0=E6=8D=AE=E3=80=81=E6=9C=BA=E5=99=A8=E4=BA=BA?= =?UTF-8?q?=E8=BD=A6=E9=97=B4=E9=80=9A=E4=BF=A1=E7=9A=84=E5=8F=91=E9=80=81?= =?UTF-8?q?=E5=92=8C=E6=8E=A5=E6=94=B6=EF=BC=8C=E4=BB=85=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/referee/referee.c | 14 ++++- modules/referee/referee_UI.c | 22 +++++-- modules/referee/referee_communication.c | 84 ++++++++++++------------- modules/referee/referee_communication.h | 75 +--------------------- modules/referee/referee_def.h | 79 ++++++++++++++++++++--- modules/referee/rm_referee.c | 13 ++-- modules/referee/rm_referee.h | 12 ++-- 7 files changed, 154 insertions(+), 145 deletions(-) diff --git a/application/referee/referee.c b/application/referee/referee.c index 7915f2a..c21122d 100644 --- a/application/referee/referee.c +++ b/application/referee/referee.c @@ -12,15 +12,21 @@ #include "robot_def.h" #include "rm_referee.h" #include "referee_UI.h" +#include "referee_communication.h" static Referee_Interactive_info_t Interactive_data; // 非裁判系统数据 -static referee_info_t *referee_data; // 裁判系统相关数据 +static referee_info_t *referee_data; // 裁判系统相关数据 +static robot_interactive_data_t *SendData={1,2,3,4,5}; + static void determine_ID(referee_info_t *_referee_info); static void My_UI_init(referee_info_t *_referee_info); static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_info_t *_Interactive_data); -static void robot_mode_change(Referee_Interactive_info_t *_Interactive_data); // 测试用函数,实现模式自动变化 static void Mode_Change_Check(Referee_Interactive_info_t *_Interactive_data); // 模式切换检测 +//syhtod 正式上车后需删除 +static void robot_mode_change(Referee_Interactive_info_t *_Interactive_data); // 测试用函数,实现模式自动变化 + + void Referee_Interactive_init() { referee_data = RefereeInit(&huart6); // 裁判系统初始化 @@ -28,6 +34,8 @@ void Referee_Interactive_init() ; determine_ID(referee_data); My_UI_init(referee_data); + referee_data->referee_id.Receiver_Robot_ID = RobotID_BEngineer; // 机器人车间通信时接收者的ID暂时发给蓝色2 + Communicate_SendData(&referee_data->referee_id,SendData); } void Referee_Interactive_task() @@ -345,5 +353,5 @@ static void determine_ID(referee_info_t *_referee_info) _referee_info->referee_id.Robot_Color = _referee_info->GameRobotState.robot_id > 7 ? Robot_Blue : Robot_Red; _referee_info->referee_id.Robot_ID = _referee_info->GameRobotState.robot_id; _referee_info->referee_id.Cilent_ID = 0x0100 + _referee_info->referee_id.Robot_ID; // 计算客户端ID - _referee_info->referee_id.Receiver_Robot_ID = 0x00; // 机器人车间通信时接收者的ID暂时为0 + _referee_info->referee_id.Receiver_Robot_ID = 0; } diff --git a/modules/referee/referee_UI.c b/modules/referee/referee_UI.c index 074e323..3e20cc1 100644 --- a/modules/referee/referee_UI.c +++ b/modules/referee/referee_UI.c @@ -1,10 +1,20 @@ +/** + * @file referee_UI.C + * @author kidneygood (you@domain.com) + * @brief + * @version 0.1 + * @date 2023-1-18 + * + * @copyright Copyright (c) 2022 + * + */ #include "referee_UI.h" #include "string.h" #include "crc.h" #include "stdio.h" #include "rm_referee.h" -static uint8_t UI_Seq; //包序号 + //包序号 /********************************************删除操作************************************* **参数:_id 对应的id结构体 Del_Operate 对应头文件删除操作 @@ -13,7 +23,7 @@ static uint8_t UI_Seq; //包序号 void UI_Delete(referee_id_t *_id,uint8_t Del_Operate,uint8_t Del_Layer) { UI_delete_t UI_delete_data; - uint8_t temp_datalength = UI_Data_LEN_Head + UI_Operate_LEN_Del; //计算交互数据长度 + uint8_t temp_datalength = Interactive_Data_LEN_Head + UI_Operate_LEN_Del; //计算交互数据长度 UI_delete_data.FrameHeader.SOF = REFEREE_SOF; UI_delete_data.FrameHeader.DataLength = temp_datalength; @@ -349,7 +359,7 @@ void UI_ReFresh(referee_id_t *_id,int cnt,...) va_start(ap,cnt);//初始化 va_list 变量为一个参数列表 UI_GraphReFresh_data.FrameHeader.SOF = REFEREE_SOF; - UI_GraphReFresh_data.FrameHeader.DataLength = UI_Data_LEN_Head+cnt*UI_Operate_LEN_PerDraw; + UI_GraphReFresh_data.FrameHeader.DataLength = Interactive_Data_LEN_Head+cnt*UI_Operate_LEN_PerDraw; UI_GraphReFresh_data.FrameHeader.Seq = UI_Seq; UI_GraphReFresh_data.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&UI_GraphReFresh_data,LEN_CRC8,0xFF); @@ -375,8 +385,8 @@ void UI_ReFresh(referee_id_t *_id,int cnt,...) UI_GraphReFresh_data.datahead.sender_ID = _id->Robot_ID; //先发送帧头、命令码、交互数据帧头三部分,并计算CRC16校验值 - UI_GraphReFresh_data.frametail=Get_CRC16_Check_Sum((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+UI_Data_LEN_Head,0xFFFF); - RefereeSend((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+UI_Data_LEN_Head); + UI_GraphReFresh_data.frametail=Get_CRC16_Check_Sum((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+Interactive_Data_LEN_Head,0xFFFF); + RefereeSend((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+Interactive_Data_LEN_Head); for(i=0;iRobot_ID; + SendData.datahead.receiver_ID = _id->Receiver_Robot_ID; + SendData.Data = *_data; + + SendData.frametail = Get_CRC16_Check_Sum((uint8_t *)&SendData,LEN_HEADER+LEN_CMDID+temp_datalength,0xFFFF); + + RefereeSend((uint8_t *)&SendData,LEN_HEADER+LEN_CMDID+temp_datalength+LEN_TAIL); //发送 + UI_Seq++; // 包序号+1 +} diff --git a/modules/referee/referee_communication.h b/modules/referee/referee_communication.h index 4acc879..cba2324 100644 --- a/modules/referee/referee_communication.h +++ b/modules/referee/referee_communication.h @@ -1,79 +1,10 @@ -/** - * @file referee_communication.h - * @author kidneygood (you@domain.com) - * @version 0.1 - * @date 2022-12-02 - * - * @copyright Copyright (c) HNU YueLu EC 2022 all rights reserved - * - */ - #ifndef REFEREE_COMMUNICATION_H #define REFEREE_COMMUNICATION_H #include "stdint.h" #include "referee_def.h" -#pragma pack(1) +#include "rm_referee.h" +void Communicate_SendData(referee_id_t *_id,robot_interactive_data_t *_data); - - -/* - 客户端 客户端自定义数据:cmd_id:0x0301。内容 ID:0xD180 - 发送频率:上限 10Hz - 1. 客户端 客户端自定义数据:cmd_id:0x0301。内容 ID:0xD180。发送频率:上限 10Hz - 字节偏移量 大小 说明 备注 - 0 2 数据的内容 ID 0xD180 - 2 2 送者的 ID 需要校验发送者机器人的 ID 正确性 - 4 2 客户端的 ID 只能为发送者机器人对应的客户端 - 6 4 自定义浮点数据 1 - 10 4 自定义浮点数据 2 - 14 4 自定义浮点数据 3 - 18 1 自定义 8 位数据 4 - -*/ -typedef struct -{ - float data1; - float data2; - float data3; - uint8_t masks; -} client_custom_data_t; - -/* - 学生机器人间通信 cmd_id 0x0301,内容 ID:0x0200~0x02FF - 交互数据 机器人间通信:0x0301。 - 发送频率:上限 10Hz -*/ -typedef struct -{ - uint8_t data[10]; // 数据段,n需要小于113 -} robot_interactive_data_t; - -// 发送给客户端的信息 -//交互数据包括一个统一的数据段头结构。数据段包含了内容 ID,发送者以及接收者的 ID 和内容数据段, -// 整个交互数据的包总共长最大为 128 个字节,减去 frame_header,cmd_id 和 frame_tail 共 9 个字节以及 -// 数据段头结构的 6 个字节,故而发送的内容数据段最大为 113。 -// 帧头 命令码 数据段头结构 数据段 帧尾 -typedef struct -{ - xFrameHeader txFrameHeader; // 帧头 - uint16_t CmdID; // 命令码 - ext_student_interactive_header_data_t dataFrameHeader; // 数据段头结构 - client_custom_data_t clientData; // 数据段 - uint16_t FrameTail; // 帧尾 -} ext_SendClientData_t; - -// 机器人交互信息 -typedef struct -{ - xFrameHeader txFrameHeader; // 帧头 - uint16_t CmdID; // 命令码 - ext_student_interactive_header_data_t dataFrameHeader; // 数据段头结构 - robot_interactive_data_t interactData; // 数据段 - uint16_t FrameTail; // 帧尾 -} ext_CommunatianData_t; - -#pragma pack() - -#endif \ No newline at end of file +#endif \ No newline at end of file diff --git a/modules/referee/referee_def.h b/modules/referee/referee_def.h index ac82dfb..11d44ee 100644 --- a/modules/referee/referee_def.h +++ b/modules/referee/referee_def.h @@ -19,8 +19,9 @@ #define REFEREE_SOF 0xA5 // 起始字节,协议固定为0xA5 #define Robot_Red 0 #define Robot_Blue 1 +#define Communicate_Data_LEN 5 //自定义交互数据长度,该长度决定了我方发送和他方接收,自定义交互数据协议更改时只需要更改此宏定义即可 -#pragma pack(1) +#pragma pack(1) /****************************通信协议格式****************************/ /****************************通信协议格式****************************/ @@ -86,7 +87,7 @@ typedef enum ID_student_interactive = 0x0301, // 机器人间交互数据 } CmdID_e; -/* 命令码数据段长,根据官方协议来定义长度 */ +/* 命令码数据段长,根据官方协议来定义长度,还有自定义数据长度 */ typedef enum { LEN_game_state = 3, // 0x0001 @@ -101,6 +102,8 @@ typedef enum LEN_aerial_robot_energy = 1, // 0x0205 LEN_robot_hurt = 1, // 0x0206 LEN_shoot_data = 7, // 0x0207 + LEN_receive_data = 6+Communicate_Data_LEN, //0x0301 + } JudgeDataLength_e; /****************************接收数据的详细说明****************************/ @@ -226,17 +229,40 @@ typedef struct float bullet_speed; } ext_shoot_data_t; -/****************************机器人间交互数据****************************/ -/****************************机器人间交互数据****************************/ -/* 发送的内容数据段最大为 113 检测是否超出大小限制?实际上图形段不会超,数据段最多30个,也不会超下*/ +/****************************机器人交互数据****************************/ +/****************************机器人交互数据****************************/ +/* 发送的内容数据段最大为 113 检测是否超出大小限制?实际上图形段不会超,数据段最多30个,也不会超*/ /* 交互数据头结构 */ typedef struct { - uint16_t data_cmd_id; + uint16_t data_cmd_id; //由于存在多个内容 ID,但整个cmd_id 上行频率最大为 10Hz,请合理安排带宽。syhtodo 注意交互部分的上行频率 uint16_t sender_ID; uint16_t receiver_ID; } ext_student_interactive_header_data_t; +/* 机器人id */ +typedef enum +{ + // 红方机器人ID + RobotID_RHero = 1, + RobotID_REngineer = 2, + RobotID_RStandard1 = 3, + RobotID_RStandard2 = 4, + RobotID_RStandard3 = 5, + RobotID_RAerial = 6, + RobotID_RSentry = 7, + RobotID_RRadar = 9, + // 蓝方机器人ID + RobotID_BHero = 101, + RobotID_BEngineer = 102, + RobotID_BStandard1 = 103, + RobotID_BStandard2 = 104, + RobotID_BStandard3 = 105, + RobotID_BAerial = 106, + RobotID_BSentry = 107, + RobotID_BRadar = 109, +} Robot_ID_e; + /* 交互数据ID */ typedef enum { @@ -246,15 +272,52 @@ typedef enum UI_Data_ID_Draw5 = 0x103, UI_Data_ID_Draw7 = 0x104, UI_Data_ID_DrawChar = 0x110, + + /* 自定义交互数据部分 */ + Communicate_Data_ID = 0x0200, + } Interactive_Data_ID_e; /* 交互数据长度 */ typedef enum { - UI_Data_LEN_Head = 6, + Interactive_Data_LEN_Head = 6, UI_Operate_LEN_Del = 2, UI_Operate_LEN_PerDraw = 15, UI_Operate_LEN_DrawChar = 15 + 30, -} UI_Data_Length_e; + + /* 自定义交互数据部分 */ + // Communicate_Data_LEN = 5, + +} Interactive_Data_Length_e; + +/****************************自定义交互数据****************************/ +/****************************自定义交互数据****************************/ +/* + 学生机器人间通信 cmd_id 0x0301,内容 ID:0x0200~0x02FF + 自定义交互数据 机器人间通信:0x0301。 + 发送频率:上限 10Hz +*/ +//自定义交互数据协议,可更改,更改后需要修改最上方宏定义数据长度的值 +typedef struct +{ + uint8_t data[Communicate_Data_LEN]; // 数据段,n需要小于113 +} robot_interactive_data_t; + +// 机器人交互信息_发送 +typedef struct +{ + xFrameHeader FrameHeader; + uint16_t CmdID; + ext_student_interactive_header_data_t datahead; + robot_interactive_data_t Data; // 数据段 + uint16_t frametail; +} Communicate_SendData_t; +// 机器人交互信息_接收 +typedef struct +{ + ext_student_interactive_header_data_t datahead; + robot_interactive_data_t Data; // 数据段 +} Communicate_ReceiveData_t; /****************************UI交互数据****************************/ diff --git a/modules/referee/rm_referee.c b/modules/referee/rm_referee.c index b73b32c..3a3cbb1 100644 --- a/modules/referee/rm_referee.c +++ b/modules/referee/rm_referee.c @@ -16,12 +16,14 @@ #define RE_RX_BUFFER_SIZE 200 -USARTInstance *referee_usart_instance; //暂时改为非静态变量 +static USARTInstance *referee_usart_instance; // 暂时改为非静态变量 static referee_info_t referee_info; static void JudgeReadData(uint8_t *ReadFromUsart); static void RefereeRxCallback(); +uint8_t UI_Seq = 0; // 包序号,供整个referee文件使用 + /* 裁判系统通信初始化 */ referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle) { @@ -37,9 +39,9 @@ referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle) * @brief 发送函数 * @param send 待发送数据 */ -void RefereeSend(uint8_t *send,uint16_t tx_len) +void RefereeSend(uint8_t *send, uint16_t tx_len) { - USARTSend(referee_usart_instance,send,tx_len); + USARTSend(referee_usart_instance, send, tx_len); /* syhtodo DMA请求过快会导致数据发送丢失,考虑数据尽可能打成一个整包以及队列发送,并且发送函数添加缓冲区 */ HAL_Delay(5); } @@ -58,7 +60,7 @@ static void RefereeRxCallback() */ static void JudgeReadData(uint8_t *ReadFromUsart) { - uint16_t judge_length; // 统计一帧数据长度 + uint16_t judge_length; // 统计一帧数据长度 if (ReadFromUsart == NULL) // 空数据包,则不作任何处理 return; @@ -118,6 +120,9 @@ static void JudgeReadData(uint8_t *ReadFromUsart) case ID_shoot_data: // 0x0207 memcpy(&referee_info.ShootData, (ReadFromUsart + DATA_Offset), LEN_shoot_data); break; + case ID_student_interactive: // 0x0301 syhtodo接收代码未测试 + memcpy(&referee_info.ReceiveData, (ReadFromUsart + DATA_Offset), LEN_receive_data); + break; } } } diff --git a/modules/referee/rm_referee.h b/modules/referee/rm_referee.h index 0c22a1f..16fb381 100644 --- a/modules/referee/rm_referee.h +++ b/modules/referee/rm_referee.h @@ -4,23 +4,22 @@ #include "usart.h" #include "referee_def.h" #include "bsp_usart.h" -#include "robot_def.h" +extern uint8_t UI_Seq; #pragma pack(1) - typedef struct { uint8_t Robot_Color; //机器人颜色 uint16_t Robot_ID; //本机器人ID uint16_t Cilent_ID; //本机器人对应的客户端ID - uint16_t Receiver_Robot_ID; //机器人车间通信时接收者的ID + uint16_t Receiver_Robot_ID; //机器人车间通信时接收者的ID,必须和本机器人同颜色 } referee_id_t; // 此结构体包含裁判系统接收数据以及UI绘制与机器人车间通信的相关信息 typedef struct { referee_id_t referee_id; - + xFrameHeader FrameHeader; // 接收到的帧头信息 uint16_t CmdID; ext_game_state_t GameState; // 0x0001 @@ -36,7 +35,8 @@ typedef struct ext_robot_hurt_t RobotHurt; // 0x0206 ext_shoot_data_t ShootData; // 0x0207 - // syhtodo 机器人间通信如何获取数据 + //自定义交互数据的接收 + Communicate_ReceiveData_t ReceiveData; } referee_info_t; @@ -57,6 +57,4 @@ referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle); */ void RefereeSend(uint8_t *send, uint16_t tx_len); -extern USARTInstance *referee_usart_instance; - #endif // !REFEREE_H From 996839367217caed8712e441921621c0dd7729fa Mon Sep 17 00:00:00 2001 From: kidneygood <2979564623@qq.com> Date: Thu, 26 Jan 2023 20:41:52 +0800 Subject: [PATCH 14/15] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/referee/referee.c | 34 ++++- modules/referee/referee_UI.c | 251 +++++++++++++++++----------------- modules/referee/referee_def.h | 2 +- 3 files changed, 159 insertions(+), 128 deletions(-) diff --git a/application/referee/referee.c b/application/referee/referee.c index c21122d..67cfaed 100644 --- a/application/referee/referee.c +++ b/application/referee/referee.c @@ -16,7 +16,7 @@ static Referee_Interactive_info_t Interactive_data; // 非裁判系统数据 static referee_info_t *referee_data; // 裁判系统相关数据 -static robot_interactive_data_t *SendData={1,2,3,4,5}; +static robot_interactive_data_t *SendData; static void determine_ID(referee_info_t *_referee_info); static void My_UI_init(referee_info_t *_referee_info); @@ -25,7 +25,7 @@ static void Mode_Change_Check(Referee_Interactive_info_t *_Interactive_data); // //syhtod 正式上车后需删除 static void robot_mode_change(Referee_Interactive_info_t *_Interactive_data); // 测试用函数,实现模式自动变化 - +static void UI_test_init(referee_info_t *_referee_info);//UI测试函数 void Referee_Interactive_init() { @@ -34,6 +34,12 @@ void Referee_Interactive_init() ; determine_ID(referee_data); My_UI_init(referee_data); + //UI_test_init(referee_data); + + for (int i=0;idata[i]=i+1; + } referee_data->referee_id.Receiver_Robot_ID = RobotID_BEngineer; // 机器人车间通信时接收者的ID暂时发给蓝色2 Communicate_SendData(&referee_data->referee_id,SendData); } @@ -355,3 +361,27 @@ static void determine_ID(referee_info_t *_referee_info) _referee_info->referee_id.Cilent_ID = 0x0100 + _referee_info->referee_id.Robot_ID; // 计算客户端ID _referee_info->referee_id.Receiver_Robot_ID = 0; } + +/* 测试用函数 */ +static void UI_test_init(referee_info_t *_referee_info) +{ + Graph_Data_t graph[5]; + Graph_Data_t num[2]; + String_Data_t sdata[1]; + UI_Delete(&_referee_info->referee_id, UI_Data_Del_ALL, 0); + + Line_Draw(&graph[0],"s0",UI_Graph_ADD,0,UI_Color_White,3,710,540,1210,540); + Rectangle_Draw(&graph[1],"s1",UI_Graph_ADD,0,UI_Color_Yellow,4,600,200,800,500); + Circle_Draw(&graph[2],"s2",UI_Graph_ADD,0,UI_Color_Green,5,960,540,100); + Elliptical_Draw(&graph[3],"s3",UI_Graph_ADD,0,UI_Color_Orange,3,960,540,100,20); + Arc_Draw(&graph[4],"s4",UI_Graph_ADD,0,UI_Color_Purplish_red,30,160,3,1200,550,50,100); + + Float_Draw(&num[0],"s5",UI_Graph_ADD,0,UI_Color_Pink,50,3,5,1050,660,1245545); + Integer_Draw(&num[1],"s6",UI_Graph_ADD,0,UI_Color_Cyan,50,5,1050,460,12345); + UI_ReFresh(&_referee_info->referee_id,7,graph[0],graph[1],graph[2],graph[3],graph[4],num[0],num[1]); + + + Char_Draw(&sdata[0],"s7",UI_Graph_ADD,0,UI_Color_Green,20,2,620,710); + Char_Write(&sdata[0],"number:%d",123); + Char_ReFresh(&_referee_info->referee_id,sdata[0]); +} diff --git a/modules/referee/referee_UI.c b/modules/referee/referee_UI.c index 3e20cc1..ed1c235 100644 --- a/modules/referee/referee_UI.c +++ b/modules/referee/referee_UI.c @@ -14,21 +14,21 @@ #include "stdio.h" #include "rm_referee.h" - //包序号 +// 包序号 /********************************************删除操作************************************* **参数:_id 对应的id结构体 Del_Operate 对应头文件删除操作 Del_Layer 要删除的层 取值0-9 *****************************************************************************************/ -void UI_Delete(referee_id_t *_id,uint8_t Del_Operate,uint8_t Del_Layer) +void UI_Delete(referee_id_t *_id, uint8_t Del_Operate, uint8_t Del_Layer) { UI_delete_t UI_delete_data; - uint8_t temp_datalength = Interactive_Data_LEN_Head + UI_Operate_LEN_Del; //计算交互数据长度 + uint8_t temp_datalength = Interactive_Data_LEN_Head + UI_Operate_LEN_Del; // 计算交互数据长度 UI_delete_data.FrameHeader.SOF = REFEREE_SOF; UI_delete_data.FrameHeader.DataLength = temp_datalength; UI_delete_data.FrameHeader.Seq = UI_Seq; - UI_delete_data.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&UI_delete_data,LEN_CRC8,0xFF); + UI_delete_data.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&UI_delete_data, LEN_CRC8, 0xFF); UI_delete_data.CmdID = ID_student_interactive; @@ -36,15 +36,15 @@ void UI_Delete(referee_id_t *_id,uint8_t Del_Operate,uint8_t Del_Layer) UI_delete_data.datahead.receiver_ID = _id->Cilent_ID; UI_delete_data.datahead.sender_ID = _id->Robot_ID; - UI_delete_data.Delete_Operate = Del_Operate; //删除操作 - UI_delete_data.Layer = Del_Layer; + UI_delete_data.Delete_Operate = Del_Operate; // 删除操作 + UI_delete_data.Layer = Del_Layer; - UI_delete_data.frametail = Get_CRC16_Check_Sum((uint8_t *)&UI_delete_data,LEN_HEADER+LEN_CMDID+temp_datalength,0xFFFF); + UI_delete_data.frametail = Get_CRC16_Check_Sum((uint8_t *)&UI_delete_data, LEN_HEADER + LEN_CMDID + temp_datalength, 0xFFFF); /* syhtodo为什么填入0xFFFF,关于crc校验 */ - RefereeSend((uint8_t *)&UI_delete_data,LEN_HEADER+LEN_CMDID+temp_datalength+LEN_TAIL); //发送 - - UI_Seq++; //包序号+1 + RefereeSend((uint8_t *)&UI_delete_data, LEN_HEADER + LEN_CMDID + temp_datalength + LEN_TAIL); // 发送 + + UI_Seq++; // 包序号+1 } /************************************************绘制直线************************************************* **参数:*graph Graph_Data类型变量指针,用于存放图形数据 @@ -56,25 +56,27 @@ void UI_Delete(referee_id_t *_id,uint8_t Del_Operate,uint8_t Del_Layer) Start_x、Start_y 起点xy坐标 End_x、End_y 终点xy坐标 **********************************************************************************************************/ - -void Line_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y) + +void Line_Draw(Graph_Data_t *graph, char graphname[3], uint32_t Graph_Operate, uint32_t Graph_Layer, uint32_t Graph_Color, + uint32_t Graph_Width, uint32_t Start_x, uint32_t Start_y, uint32_t End_x, uint32_t End_y) { - // memset(graph,0,UI_Operate_LEN_PerDraw); //如果定义的是非静态变量,数据存在初始化未默认为0的情况,使用memset方法,以下类似 syhtodo int i; - for(i=0;i<3&&graphname[i]!='\0';i++) //填充至‘0’为止 + for (i = 0; i < 3 && graphname[i] != '\0'; i++) // 填充至‘0’为止 { - graph->graphic_name[2-i]=graphname[i]; //按内存地址增大方向填充,所以会有i与2-i + graph->graphic_name[2 - i] = graphname[i]; // 按内存地址增大方向填充,所以会有i与2-i } - + graph->operate_tpye = Graph_Operate; graph->graphic_tpye = UI_Graph_Line; graph->layer = Graph_Layer; graph->color = Graph_Color; + graph->start_angle = 0; + graph->end_angle = 0; graph->width = Graph_Width; graph->start_x = Start_x; graph->start_y = Start_y; + graph->radius = 0; graph->end_x = End_x; graph->end_y = End_y; } @@ -88,15 +90,14 @@ void Line_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint Graph_Width 图形线宽 Start_x、Start_y 起点xy坐标 End_x、End_y 对角顶点xy坐标 -**********************************************************************************************************/ -void Rectangle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y) +**********************************************************************************************************/ +void Rectangle_Draw(Graph_Data_t *graph, char graphname[3], uint32_t Graph_Operate, uint32_t Graph_Layer, uint32_t Graph_Color, + uint32_t Graph_Width, uint32_t Start_x, uint32_t Start_y, uint32_t End_x, uint32_t End_y) { - // memset(&graph,0,UI_Operate_LEN_PerDraw); int i; - for(i=0;i<3&&graphname[i]!='\0';i++) + for (i = 0; i < 3 && graphname[i] != '\0'; i++) { - graph->graphic_name[2-i]=graphname[i]; + graph->graphic_name[2 - i] = graphname[i]; } graph->graphic_tpye = UI_Graph_Rectangle; @@ -104,9 +105,12 @@ void Rectangle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate graph->layer = Graph_Layer; graph->color = Graph_Color; + graph->start_angle = 0; + graph->end_angle = 0; graph->width = Graph_Width; graph->start_x = Start_x; graph->start_y = Start_y; + graph->radius = 0; graph->end_x = End_x; graph->end_y = End_y; } @@ -121,15 +125,14 @@ void Rectangle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate Start_x、Start_y 圆心xy坐标 Graph_Radius 圆形半径 **********************************************************************************************************/ - -void Circle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius) + +void Circle_Draw(Graph_Data_t *graph, char graphname[3], uint32_t Graph_Operate, uint32_t Graph_Layer, uint32_t Graph_Color, + uint32_t Graph_Width, uint32_t Start_x, uint32_t Start_y, uint32_t Graph_Radius) { - // memset(&graph,0,UI_Operate_LEN_PerDraw); int i; - for(i=0;i<3&&graphname[i]!='\0';i++) + for (i = 0; i < 3 && graphname[i] != '\0'; i++) { - graph->graphic_name[2-i]=graphname[i]; + graph->graphic_name[2 - i] = graphname[i]; } graph->graphic_tpye = UI_Graph_Circle; @@ -137,10 +140,14 @@ void Circle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,ui graph->layer = Graph_Layer; graph->color = Graph_Color; + graph->start_angle = 0; + graph->end_angle = 0; graph->width = Graph_Width; graph->start_x = Start_x; graph->start_y = Start_y; graph->radius = Graph_Radius; + graph->end_x = 0; + graph->end_y = 0; } /************************************************绘制椭圆************************************************* **参数:*graph Graph_Data类型变量指针,用于存放图形数据 @@ -152,14 +159,13 @@ void Circle_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,ui Start_x、Start_y 圆心xy坐标 End_x、End_y xy半轴长度 **********************************************************************************************************/ -void Elliptical_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y) +void Elliptical_Draw(Graph_Data_t *graph, char graphname[3], uint32_t Graph_Operate, uint32_t Graph_Layer, uint32_t Graph_Color, + uint32_t Graph_Width, uint32_t Start_x, uint32_t Start_y, uint32_t end_x, uint32_t end_y) { - // memset(&graph,0,UI_Operate_LEN_PerDraw); int i; - for(i=0;i<3&&graphname[i]!='\0';i++) + for (i = 0; i < 3 && graphname[i] != '\0'; i++) { - graph->graphic_name[2-i]=graphname[i]; + graph->graphic_name[2 - i] = graphname[i]; } graph->graphic_tpye = UI_Graph_Ellipse; @@ -168,13 +174,16 @@ void Elliptical_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operat graph->color = Graph_Color; graph->width = Graph_Width; + graph->start_angle = 0; + graph->end_angle = 0; + graph->width = Graph_Width; graph->start_x = Start_x; graph->start_y = Start_y; + graph->radius = 0; graph->end_x = end_x; graph->end_y = end_y; } - /************************************************绘制圆弧************************************************* **参数:*graph Graph_Data类型变量指针,用于存放图形数据 graphname[3] 图片名称,用于标识更改 @@ -182,20 +191,19 @@ void Elliptical_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operat Graph_Layer 图层0-9 Graph_Color 图形颜色 Graph_StartAngle,Graph_EndAngle 起始终止角度 - Graph_Width 图形线宽 + Graph_Width 图形线宽 Start_y,Start_y 圆心xy坐标 x_Length,y_Length xy半轴长度 **********************************************************************************************************/ - -void Arc_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_StartAngle,uint32_t Graph_EndAngle,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y, - uint32_t end_x,uint32_t end_y) + +void Arc_Draw(Graph_Data_t *graph, char graphname[3], uint32_t Graph_Operate, uint32_t Graph_Layer, uint32_t Graph_Color, + uint32_t Graph_StartAngle, uint32_t Graph_EndAngle, uint32_t Graph_Width, uint32_t Start_x, uint32_t Start_y, + uint32_t end_x, uint32_t end_y) { - //memset(&graph,0,UI_Operate_LEN_PerDraw); int i; - for(i=0;i<3&&graphname[i]!='\0';i++) + for (i = 0; i < 3 && graphname[i] != '\0'; i++) { - graph->graphic_name[2-i]=graphname[i]; + graph->graphic_name[2 - i] = graphname[i]; } graph->graphic_tpye = UI_Graph_Arc; @@ -208,6 +216,7 @@ void Arc_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint3 graph->width = Graph_Width; graph->start_x = Start_x; graph->start_y = Start_y; + graph->radius = 0; graph->end_x = end_x; graph->end_y = end_y; } @@ -220,21 +229,21 @@ void Arc_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint3 Graph_Color 图形颜色 Graph_Size 字号 Graph_Digit 小数位数 - Graph_Width 图形线宽 + Graph_Width 图形线宽 Start_x、Start_y 开始坐标 radius=a&0x3FF; a为浮点数乘以1000后的32位整型数 end_x=(a>>10)&0x7FF; end_y=(a>>21)&0x7FF; **********************************************************************************************************/ - -void Float_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_Size,uint32_t Graph_Digit,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Float) + +void Float_Draw(Graph_Data_t *graph, char graphname[3], uint32_t Graph_Operate, uint32_t Graph_Layer, uint32_t Graph_Color, + uint32_t Graph_Size, uint32_t Graph_Digit, uint32_t Graph_Width, uint32_t Start_x, uint32_t Start_y, int32_t Graph_Float) { - //memset(&graph,0,UI_Operate_LEN_PerDraw); + int i; - for(i=0;i<3&&graphname[i]!='\0';i++) + for (i = 0; i < 3 && graphname[i] != '\0'; i++) { - graph->graphic_name[2-i]=graphname[i]; + graph->graphic_name[2 - i] = graphname[i]; } graph->graphic_tpye = UI_Graph_Float; graph->operate_tpye = Graph_Operate; @@ -247,9 +256,9 @@ void Float_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uin graph->start_angle = Graph_Size; graph->end_angle = Graph_Digit; - graph->radius=Graph_Float&0x3FF; - graph->end_x=(Graph_Float>>10)&0x7FF; - graph->end_y=(Graph_Float>>21)&0x7FF; + graph->radius = Graph_Float & 0x3FF; + graph->end_x = (Graph_Float >> 10) & 0x7FF; + graph->end_y = (Graph_Float >> 21) & 0x7FF; } /************************************************绘制整型数据************************************************* @@ -259,20 +268,19 @@ void Float_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uin Graph_Layer 图层0-9 Graph_Color 图形颜色 Graph_Size 字号 - Graph_Width 图形线宽 + Graph_Width 图形线宽 Start_x、Start_y 开始坐标 radius=a&0x3FF; a为32位整型数 end_x=(a>>10)&0x7FF; end_y=(a>>21)&0x7FF; **********************************************************************************************************/ -void Integer_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Integer) +void Integer_Draw(Graph_Data_t *graph, char graphname[3], uint32_t Graph_Operate, uint32_t Graph_Layer, uint32_t Graph_Color, + uint32_t Graph_Size, uint32_t Graph_Width, uint32_t Start_x, uint32_t Start_y, int32_t Graph_Integer) { - //memset(&graph,0,UI_Operate_LEN_PerDraw); int i; - for(i=0;i<3&&graphname[i]!='\0';i++) + for (i = 0; i < 3 && graphname[i] != '\0'; i++) { - graph->graphic_name[2-i]=graphname[i]; + graph->graphic_name[2 - i] = graphname[i]; } graph->graphic_tpye = UI_Graph_Int; graph->operate_tpye = Graph_Operate; @@ -280,16 +288,15 @@ void Integer_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,u graph->color = Graph_Color; graph->start_angle = Graph_Size; + graph->end_angle = 0; graph->width = Graph_Width; graph->start_x = Start_x; graph->start_y = Start_y; - - graph->radius=Graph_Integer&0x3FF; - graph->end_x=(Graph_Integer>>10)&0x7FF; - graph->end_y=(Graph_Integer>>21)&0x7FF; + graph->radius = Graph_Integer & 0x3FF; + graph->end_x = (Graph_Integer >> 10) & 0x7FF; + graph->end_y = (Graph_Integer >> 21) & 0x7FF; } - /************************************************绘制字符型数据************************************************* **参数:*graph Graph_Data类型变量指针,用于存放图形数据 graphname[3] 图片名称,用于标识更改 @@ -299,18 +306,16 @@ void Integer_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,u Graph_Size 字号 Graph_Width 图形线宽 Start_x、Start_y 开始坐标 -**********************************************************************************************************/ -void Char_Draw(String_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uint32_t Graph_Layer,uint32_t Graph_Color, - uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y) -{ - // //memset(graph->Graph_Control.graphic_name, 0, 3);//syhtodo 是否需要手动清零 - //memset(&graph,0,UI_Operate_LEN_DrawChar); +**********************************************************************************************************/ +void Char_Draw(String_Data_t *graph, char graphname[3], uint32_t Graph_Operate, uint32_t Graph_Layer, uint32_t Graph_Color, + uint32_t Graph_Size, uint32_t Graph_Width, uint32_t Start_x, uint32_t Start_y) +{ int i; - for(i=0;i<3&&graphname[i]!='\0';i++) + for (i = 0; i < 3 && graphname[i] != '\0'; i++) { - graph->Graph_Control.graphic_name[2-i]=graphname[i]; + graph->Graph_Control.graphic_name[2 - i] = graphname[i]; } - + graph->Graph_Control.graphic_tpye = UI_Graph_Char; graph->Graph_Control.operate_tpye = Graph_Operate; graph->Graph_Control.layer = Graph_Layer; @@ -320,11 +325,9 @@ void Char_Draw(String_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uin graph->Graph_Control.start_x = Start_x; graph->Graph_Control.start_y = Start_y; graph->Graph_Control.start_angle = Graph_Size; - - //syhtodo无关的赋值为0 - graph->Graph_Control.radius=0; - graph->Graph_Control.end_x=0; - graph->Graph_Control.end_y=0; + graph->Graph_Control.radius = 0; + graph->Graph_Control.end_x = 0; + graph->Graph_Control.end_y = 0; } /************************************************绘制字符型数据************************************************* @@ -332,87 +335,86 @@ void Char_Draw(String_Data_t *graph,char graphname[3],uint32_t Graph_Operate,uin fmt需要显示的字符串 此函数的实现和具体使用类似于printf函数 **********************************************************************************************************/ -void Char_Write(String_Data_t *graph,char* fmt, ...) +void Char_Write(String_Data_t *graph, char *fmt, ...) { - uint16_t i = 0; - va_list ap; - va_start(ap,fmt); - vsprintf((char*)graph->show_Data,fmt,ap);//使用参数列表进行格式化并输出到字符串 - va_end(ap); - i = strlen((const char*)graph->show_Data); - graph->Graph_Control.end_angle = i; + uint16_t i = 0; + va_list ap; + va_start(ap, fmt); + vsprintf((char *)graph->show_Data, fmt, ap); // 使用参数列表进行格式化并输出到字符串 + va_end(ap); + i = strlen((const char *)graph->show_Data); + graph->Graph_Control.end_angle = i; } - /* UI推送函数(使更改生效) 参数: cnt 图形个数 ... 图形变量参数 Tips::该函数只能推送1,2,5,7个图形,其他数目协议未涉及 */ -void UI_ReFresh(referee_id_t *_id,int cnt,...) +void UI_ReFresh(referee_id_t *_id, int cnt, ...) { int i; UI_GraphReFresh_t UI_GraphReFresh_data; Graph_Data_t graphData; - va_list ap;//创建一个 va_list 类型变量 - va_start(ap,cnt);//初始化 va_list 变量为一个参数列表 + va_list ap; // 创建一个 va_list 类型变量 + va_start(ap, cnt); // 初始化 va_list 变量为一个参数列表 UI_GraphReFresh_data.FrameHeader.SOF = REFEREE_SOF; - UI_GraphReFresh_data.FrameHeader.DataLength = Interactive_Data_LEN_Head+cnt*UI_Operate_LEN_PerDraw; + UI_GraphReFresh_data.FrameHeader.DataLength = Interactive_Data_LEN_Head + cnt * UI_Operate_LEN_PerDraw; UI_GraphReFresh_data.FrameHeader.Seq = UI_Seq; - UI_GraphReFresh_data.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&UI_GraphReFresh_data,LEN_CRC8,0xFF); + UI_GraphReFresh_data.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&UI_GraphReFresh_data, LEN_CRC8, 0xFF); UI_GraphReFresh_data.CmdID = ID_student_interactive; - switch(cnt) + switch (cnt) { - case 1: - UI_GraphReFresh_data.datahead.data_cmd_id=UI_Data_ID_Draw1; - break; - case 2: - UI_GraphReFresh_data.datahead.data_cmd_id=UI_Data_ID_Draw2; - break; - case 5: - UI_GraphReFresh_data.datahead.data_cmd_id=UI_Data_ID_Draw5; - break; - case 7: - UI_GraphReFresh_data.datahead.data_cmd_id=UI_Data_ID_Draw7; - break; + case 1: + UI_GraphReFresh_data.datahead.data_cmd_id = UI_Data_ID_Draw1; + break; + case 2: + UI_GraphReFresh_data.datahead.data_cmd_id = UI_Data_ID_Draw2; + break; + case 5: + UI_GraphReFresh_data.datahead.data_cmd_id = UI_Data_ID_Draw5; + break; + case 7: + UI_GraphReFresh_data.datahead.data_cmd_id = UI_Data_ID_Draw7; + break; } UI_GraphReFresh_data.datahead.receiver_ID = _id->Cilent_ID; UI_GraphReFresh_data.datahead.sender_ID = _id->Robot_ID; - //先发送帧头、命令码、交互数据帧头三部分,并计算CRC16校验值 - UI_GraphReFresh_data.frametail=Get_CRC16_Check_Sum((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+Interactive_Data_LEN_Head,0xFFFF); - RefereeSend((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+Interactive_Data_LEN_Head); - - for(i=0;i Date: Sun, 5 Mar 2023 22:28:31 +0800 Subject: [PATCH 15/15] =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=89=8D=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/gimbal/gimbal.c | 1 - application/referee/referee.c | 2 -- application/robot.c | 2 +- modules/referee/referee_UI.c | 2 +- modules/referee/referee_def.h | 2 +- 5 files changed, 3 insertions(+), 6 deletions(-) diff --git a/application/gimbal/gimbal.c b/application/gimbal/gimbal.c index e7ef766..34d9721 100644 --- a/application/gimbal/gimbal.c +++ b/application/gimbal/gimbal.c @@ -16,7 +16,6 @@ static Gimbal_Ctrl_Cmd_s gimbal_cmd_recv; // 来自cmd的控制信息 void GimbalInit() { - /* syh referee不需要imu暂时关闭以加快初始化速度 */ // gimba_IMU_data = INS_Init(); // IMU先初始化,获取姿态数据指针赋给yaw电机的其他数据来源 // YAW diff --git a/application/referee/referee.c b/application/referee/referee.c index 67cfaed..57ab4c6 100644 --- a/application/referee/referee.c +++ b/application/referee/referee.c @@ -178,8 +178,6 @@ static void robot_mode_change(Referee_Interactive_info_t *_Interactive_data) // static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_info_t *_Interactive_data) { - // syhtodo 按键刷新 - Mode_Change_Check(_Interactive_data); // chassis if (_Interactive_data->Referee_Interactive_Flag.chassis_flag == 1) diff --git a/application/robot.c b/application/robot.c index d830aad..bc5c929 100644 --- a/application/robot.c +++ b/application/robot.c @@ -24,7 +24,7 @@ void RobotInit() #endif #if defined(ONE_BOARD) || defined(CHASSIS_BOARD) - Referee_Interactive_init();//syh + Referee_Interactive_init(); ChassisInit(); #endif } diff --git a/modules/referee/referee_UI.c b/modules/referee/referee_UI.c index ed1c235..2dc3e36 100644 --- a/modules/referee/referee_UI.c +++ b/modules/referee/referee_UI.c @@ -40,7 +40,7 @@ void UI_Delete(referee_id_t *_id, uint8_t Del_Operate, uint8_t Del_Layer) UI_delete_data.Layer = Del_Layer; UI_delete_data.frametail = Get_CRC16_Check_Sum((uint8_t *)&UI_delete_data, LEN_HEADER + LEN_CMDID + temp_datalength, 0xFFFF); - /* syhtodo为什么填入0xFFFF,关于crc校验 */ + /* 填入0xFFFF,关于crc校验 */ RefereeSend((uint8_t *)&UI_delete_data, LEN_HEADER + LEN_CMDID + temp_datalength + LEN_TAIL); // 发送 diff --git a/modules/referee/referee_def.h b/modules/referee/referee_def.h index 19f6102..4c2312f 100644 --- a/modules/referee/referee_def.h +++ b/modules/referee/referee_def.h @@ -235,7 +235,7 @@ typedef struct /* 交互数据头结构 */ typedef struct { - uint16_t data_cmd_id; //由于存在多个内容 ID,但整个cmd_id 上行频率最大为 10Hz,请合理安排带宽。syhtodo 注意交互部分的上行频率 + uint16_t data_cmd_id; //由于存在多个内容 ID,但整个cmd_id 上行频率最大为 10Hz,请合理安排带宽。注意交互部分的上行频率 uint16_t sender_ID; uint16_t receiver_ID; } ext_student_interactive_header_data_t;