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] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE=E5=8F=91?= =?UTF-8?q?=E9=80=81=E6=96=B9=E5=BC=8F=EF=BC=8C=E6=95=B4=E5=8C=85=E5=8F=91?= =?UTF-8?q?=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