优化数据发送方式,整包发送

This commit is contained in:
kidneygood 2023-01-13 21:45:04 +08:00
parent 9b16407b57
commit e0abbf95ca
5 changed files with 197 additions and 190 deletions

View File

@ -36,6 +36,7 @@
//////////////////////////////////////////////////syhtodo //////////////////////////////////////////////////syhtodo
#include "referee_UI.h" #include "referee_UI.h"
#include "referee.h" #include "referee.h"
#include "referee_def.h"
////////////////////////////////////////////////// //////////////////////////////////////////////////
/* USER CODE END Includes */ /* USER CODE END Includes */
@ -119,10 +120,12 @@ int main(void)
//////////////////////////////////////////////////syhtodo //////////////////////////////////////////////////syhtodo
Graph_Data graph[5]; Graph_Data_t graph[5];
Graph_Data num[2]; Graph_Data_t num[2];
String_Data sdata[1]; String_Data_t sdata[1];
memset(sdata[0].show_Data, 0, 30); //使用memset方法 syhtodo 数据存在初始化未默认为0的情况 memset(sdata[0].show_Data, 0, 30); //使用memset方法 syhtodo 数据存在初始化未默认为0的情况
memset(&graph[0], 0, 15);
UI_Delete(UI_Data_Del_ALL,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); 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); 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]); 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_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]); Char_ReFresh(sdata[0]);
////////////////////////////////////////////////// //////////////////////////////////////////////////

View File

@ -57,7 +57,7 @@ static void JudgeReadData(uint8_t *ReadFromUsart)
memcpy(&referee_info.FrameHeader, ReadFromUsart, LEN_HEADER); memcpy(&referee_info.FrameHeader, ReadFromUsart, LEN_HEADER);
// 判断帧头数据(0)是否为0xA5 // 判断帧头数据(0)是否为0xA5
if (ReadFromUsart[SOF] == JUDGE_FRAME_HEADER) if (ReadFromUsart[SOF] == REFEREE_SOF)
{ {
// 帧头CRC8校验 // 帧头CRC8校验
if (Verify_CRC8_Check_Sum(ReadFromUsart, LEN_HEADER) == TRUE) if (Verify_CRC8_Check_Sum(ReadFromUsart, LEN_HEADER) == TRUE)

View File

@ -5,7 +5,10 @@
#include "dma.h" #include "dma.h"
#include "stdio.h" #include "stdio.h"
#include "referee.h" #include "referee.h"
/* syhtodo 根据自身id判断客户端id */ /* syhtodo 根据自身id判断客户端id
*/
uint16_t Robot_ID = UI_Data_RobotID_BHero; uint16_t Robot_ID = UI_Data_RobotID_BHero;
uint16_t Cilent_ID = UI_Data_CilentID_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) void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer)
{ {
/* syhtodo可化简去掉读写指针 */ UI_delete_t UI_delete_data;
unsigned char *framepoint; //读写指针
uint16_t frametail=0xFFFF; //CRC16校验值 UI_delete_data.FrameHeader.SOF = REFEREE_SOF;
UI_delete_data.FrameHeader.DataLength = UI_Data_LEN_Del;
UI_Packhead framehead; //帧头 UI_delete_data.FrameHeader.Seq = UI_Seq;
UI_Data_Operate datahead; //数据交互帧 UI_delete_data.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&UI_delete_data,4,0xFF);
UI_Data_Delete del; //删除图层帧
UI_delete_data.CmdID = ID_student_interactive;
framepoint=(unsigned char *)&framehead;
UI_delete_data.datahead.data_cmd_id = UI_Data_ID_Del;
framehead.SOF=UI_SOF; UI_delete_data.datahead.receiver_ID = Cilent_ID;
framehead.Data_Length=8; UI_delete_data.datahead.sender_ID = Robot_ID;
framehead.Seq=UI_Seq;
framehead.CRC8=Get_CRC8_Check_Sum(framepoint,4,0xFF); UI_delete_data.Delete_Operate = Del_Operate; //删除操作
framehead.CMD_ID=UI_CMD_Robo_Exchange; //填充包头数据 UI_delete_data.Layer = Del_Layer;
datahead.Data_ID=UI_Data_ID_Del; UI_delete_data.frametail = Get_CRC16_Check_Sum((uint8_t *)&UI_delete_data,LEN_HEADER+LEN_CMDID+UI_Data_LEN_Del,0xFFFF);
datahead.Sender_ID=Robot_ID; /* syhtodo为什么填入0xFFFF */
datahead.Receiver_ID=Cilent_ID; //填充操作数据
RefereeSend((uint8_t *)&UI_delete_data,LEN_HEADER+LEN_CMDID+UI_Data_LEN_Del+LEN_TAIL); //发送
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_Seq++; //包序号+1 UI_Seq++; //包序号+1
} }
/************************************************绘制直线************************************************* /************************************************绘制直线*************************************************
@ -64,11 +54,11 @@ void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer)
End_xEnd_y xy坐标 End_xEnd_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) uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y)
{ {
int i; int i;
//?????? //??????syhtodo
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];
@ -96,7 +86,7 @@ void Line_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint32
Start_xStart_y xy坐标 Start_xStart_y xy坐标
End_xEnd_y xy坐标 End_xEnd_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) uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t End_x,uint32_t End_y)
{ {
int i; int i;
@ -128,7 +118,7 @@ void Rectangle_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,u
Graph_Radius 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) uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t Graph_Radius)
{ {
int i; int i;
@ -157,7 +147,7 @@ void Circle_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint
Start_xStart_y xy坐标 Start_xStart_y xy坐标
End_xEnd_y xy半轴长度 End_xEnd_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) uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,uint32_t end_x,uint32_t end_y)
{ {
int i; int i;
@ -191,7 +181,7 @@ void Elliptical_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,
x_Length,y_Length 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, 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 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 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; 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) 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;
@ -267,7 +257,7 @@ void Float_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uint3
end_x=(a>>10)&0x7FF; end_x=(a>>10)&0x7FF;
end_y=(a>>21)&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) uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y,int32_t Graph_Integer)
{ {
int i; int i;
@ -301,10 +291,10 @@ void Integer_Draw(Graph_Data *graph,char graphname[3],uint32_t Graph_Operate,uin
Graph_Width 线 Graph_Width 线
Start_xStart_y Start_xStart_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) 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; int i;
for(i=0;i<3&&graphname[i]!='\0';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需要显示的字符串 fmt需要显示的字符串
syhtodo syhtodo
**********************************************************************************************************/ **********************************************************************************************************/
void Char_Write(String_Data *graph,char* fmt, ...) void Char_Write(String_Data_t *graph,char* fmt, ...)
{ {
uint16_t i = 0; uint16_t i = 0;
va_list ap; va_list ap;
@ -343,6 +333,7 @@ void Char_Write(String_Data *graph,char* fmt, ...)
graph->Graph_Control.end_angle = i; graph->Graph_Control.end_angle = i;
} }
/* UI推送函数使更改生效 /* UI推送函数使更改生效
cnt cnt
... ...
@ -351,107 +342,88 @@ void Char_Write(String_Data *graph,char* fmt, ...)
int UI_ReFresh(int cnt,...) int UI_ReFresh(int cnt,...)
{ {
int i; int i;
UI_Packhead framehead; UI_GraphReFresh_t UI_GraphReFresh_data;
UI_Data_Operate datahead; Graph_Data_t graphData;
Graph_Data graphData;
unsigned char *framepoint; //读写指针
uint16_t frametail=0xFFFF; //CRC16校验值
va_list ap;//创建一个 va_list 类型变量 va_list ap;//创建一个 va_list 类型变量
va_start(ap,cnt);//初始化 va_list 变量为一个参数列表 va_start(ap,cnt);//初始化 va_list 变量为一个参数列表
framepoint=(unsigned char *)&framehead; UI_GraphReFresh_data.FrameHeader.SOF = REFEREE_SOF;
framehead.SOF=UI_SOF; UI_GraphReFresh_data.FrameHeader.DataLength = 6+cnt*15;//syhtodo 换成枚举
framehead.Data_Length=6+cnt*15; UI_GraphReFresh_data.FrameHeader.Seq = UI_Seq;
framehead.Seq=UI_Seq; UI_GraphReFresh_data.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&UI_GraphReFresh_data,4,0xFF);
framehead.CRC8=Get_CRC8_Check_Sum(framepoint,4,0xFF);
framehead.CMD_ID=UI_CMD_Robo_Exchange; //填充包头数据 UI_GraphReFresh_data.CmdID = ID_student_interactive;
switch(cnt) //syhtodo可以直接计算式解决 switch(cnt) //syhtodo可以直接计算式解决
{ {
case 1: case 1:
datahead.Data_ID=UI_Data_ID_Draw1; UI_GraphReFresh_data.datahead.data_cmd_id=UI_Data_ID_Draw1;
break; break;
case 2: case 2:
datahead.Data_ID=UI_Data_ID_Draw2; UI_GraphReFresh_data.datahead.data_cmd_id=UI_Data_ID_Draw2;
break; break;
case 5: case 5:
datahead.Data_ID=UI_Data_ID_Draw5; UI_GraphReFresh_data.datahead.data_cmd_id=UI_Data_ID_Draw5;
break; break;
case 7: case 7:
datahead.Data_ID=UI_Data_ID_Draw7; UI_GraphReFresh_data.datahead.data_cmd_id=UI_Data_ID_Draw7;
break; break;
default: default:
return (-1); return (-1);
} }
datahead.Sender_ID=Robot_ID; UI_GraphReFresh_data.datahead.receiver_ID = Cilent_ID;
datahead.Receiver_ID=Cilent_ID; //填充操作数据 UI_GraphReFresh_data.datahead.sender_ID = Robot_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校验值计算部分
RefereeSend((uint8_t *)&framehead,sizeof(framehead)); UI_GraphReFresh_data.frametail=Get_CRC16_Check_Sum((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+6,0xFFFF);
RefereeSend((uint8_t *)&datahead,sizeof(datahead)); RefereeSend((uint8_t *)&UI_GraphReFresh_data,LEN_HEADER+LEN_CMDID+6);
unsigned char *framepoint; //读写指针
for(i=0;i<cnt;i++) //发送图片帧 for(i=0;i<cnt;i++) //发送图片帧
{ {
graphData=va_arg(ap,Graph_Data);//访问参数列表中的每个项 graphData=va_arg(ap,Graph_Data_t);//访问参数列表中的每个项,第二个参数是你要返回的参数的类型,在取值时需要将其强制转化为指定类型的变量
RefereeSend((uint8_t *)&graphData,sizeof(graphData)); RefereeSend((uint8_t *)&graphData,15);//syhtod 15可否计算
framepoint=(unsigned char *)&graphData; framepoint=(uint8_t *)&graphData;
frametail=Get_CRC16_Check_Sum(framepoint,sizeof(graphData),frametail); UI_GraphReFresh_data.frametail=Get_CRC16_Check_Sum(framepoint,15,UI_GraphReFresh_data.frametail);
} }
RefereeSend((uint8_t *)&frametail,sizeof(frametail)); //发送CRC16校验值 RefereeSend((uint8_t *)&UI_GraphReFresh_data.frametail,LEN_TAIL); //发送CRC16校验值
va_end(ap);//结束可变参数的获取 va_end(ap);//结束可变参数的获取
UI_Seq++; //包序号+1 UI_Seq++; //包序号+1
return 0; return 0;
} }
/************************************************UI推送字符使更改生效*********************************/ /************************************************UI推送字符使更改生效*********************************/
int Char_ReFresh(String_Data string_Data) int Char_ReFresh(String_Data_t string_Data)
{ {
String_Data graphData; UI_CharReFresh_t UI_CharReFresh_data;
unsigned char *framepoint; //读写指针
uint16_t frametail=0xFFFF; //CRC16校验值 UI_CharReFresh_data.FrameHeader.SOF = REFEREE_SOF;
UI_CharReFresh_data.FrameHeader.DataLength = UI_Data_LEN_DrawChar;
UI_Packhead framehead; UI_CharReFresh_data.FrameHeader.Seq = UI_Seq;
UI_Data_Operate datahead; UI_CharReFresh_data.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&UI_CharReFresh_data,4,0xFF);
graphData=string_Data;
UI_CharReFresh_data.CmdID = ID_student_interactive;
framepoint=(unsigned char *)&framehead; UI_CharReFresh_data.datahead.data_cmd_id = UI_Data_ID_DrawChar;
framehead.SOF=UI_SOF; UI_CharReFresh_data.datahead.receiver_ID = Cilent_ID;
framehead.Data_Length=6+45; UI_CharReFresh_data.datahead.sender_ID = Robot_ID;
framehead.Seq=UI_Seq;
framehead.CRC8=Get_CRC8_Check_Sum(framepoint,4,0xFF); UI_CharReFresh_data.String_Data = string_Data;
framehead.CMD_ID=UI_CMD_Robo_Exchange; //填充包头数据
UI_CharReFresh_data.frametail = Get_CRC16_Check_Sum((uint8_t *)&UI_CharReFresh_data,LEN_HEADER+LEN_CMDID+UI_Data_LEN_DrawChar,0xFFFF);
datahead.Data_ID=UI_Data_ID_DrawChar;
datahead.Sender_ID=Robot_ID; RefereeSend((uint8_t *)&UI_CharReFresh_data,LEN_HEADER+LEN_CMDID+UI_Data_LEN_DrawChar+LEN_TAIL); //发送
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);
framepoint=(unsigned char *)&graphData;
frametail=Get_CRC16_Check_Sum(framepoint,sizeof(graphData),frametail); //CRC16校验 //CRC16校验值计算部分
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校验值
UI_Seq++; //包序号+1 UI_Seq++; //包序号+1
return 0; return 0;
} }
// #define send_max_len 200 // #define send_max_len 200
// unsigned char CliendTxBuffer[send_max_len]; // unsigned char CliendTxBuffer[send_max_len];
// void JUDGE_Show_Data(void) // void JUDGE_Show_Data(void)

View File

@ -4,22 +4,12 @@
#include "stdarg.h" #include "stdarg.h"
#include "usart.h" #include "usart.h"
#include "stdint.h" #include "stdint.h"
#include "referee_def.h"
#pragma pack(1) //按1字节对齐 #pragma pack(1) //按1字节对齐
// #define NULL 0 // #define NULL 0
#define __FALSE 100 #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********************/ /****************************红方机器人ID********************/
#define UI_Data_RobotID_RHero 1 #define UI_Data_RobotID_RHero 1
#define UI_Data_RobotID_REngineer 2 #define UI_Data_RobotID_REngineer 2
@ -82,67 +72,49 @@
typedef struct typedef struct
{ {
uint8_t SOF; //起始字节,固定0xA5 xFrameHeader FrameHeader;
uint16_t Data_Length; //帧数据长度 uint16_t CmdID;
uint8_t Seq; //包序号 ext_student_interactive_header_data_t datahead;
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 Delete_Operate; //删除操作
uint8_t Layer; //删除图层 uint8_t Layer;
} UI_Data_Delete; //删除图层帧 uint16_t frametail;
} UI_delete_t;
/* 图形数据 */
typedef struct typedef struct
{ {
uint8_t graphic_name[3]; xFrameHeader FrameHeader;
uint32_t operate_tpye:3; uint16_t CmdID;
uint32_t graphic_tpye:3; ext_student_interactive_header_data_t datahead;
uint32_t layer:4; uint16_t frametail;
uint32_t color:4; } UI_GraphReFresh_t;
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 typedef struct
{ {
Graph_Data Graph_Control; xFrameHeader FrameHeader;
uint8_t show_Data[30]; uint16_t CmdID;
} String_Data; //打印字符串数据 ext_student_interactive_header_data_t datahead;
String_Data_t String_Data;
uint16_t frametail;
} UI_CharReFresh_t; //打印字符串数据
#pragma pack() #pragma pack()
void UI_Delete(uint8_t Del_Operate,uint8_t Del_Layer); 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 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 *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);
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 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 *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 *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);
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 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 *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);
int UI_ReFresh(int cnt,...); int UI_ReFresh(int cnt,...);
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_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 *graph,char* fmt, ...); void Char_Write(String_Data_t *graph,char* fmt, ...);
int Char_ReFresh(String_Data string_Data); int Char_ReFresh(String_Data_t string_Data);
#endif #endif

View File

@ -30,15 +30,15 @@ typedef enum
typedef enum typedef enum
{ {
LEN_HEADER = 5, // 帧头长 LEN_HEADER = 5, // 帧头长
LEN_CMDID = 2, // 命令码长度 LEN_CMDID = 2, // 命令码长度
LEN_TAIL = 2, // 帧尾CRC16 LEN_TAIL = 2, // 帧尾CRC16
} JudgeFrameLength; } JudgeFrameLength;
/****************************帧头****************************/ /****************************帧头****************************/
/****************************帧头****************************/ /****************************帧头****************************/
#define JUDGE_FRAME_HEADER (0xA5) // 起始字节,协议固定为0xA5
#define REFEREE_SOF 0xA5 // 起始字节,协议固定为0xA5
/* 帧头偏移 */ /* 帧头偏移 */
typedef enum typedef enum
{ {
@ -57,7 +57,6 @@ typedef struct
uint8_t CRC8; uint8_t CRC8;
} xFrameHeader; } xFrameHeader;
/****************************cmd_id命令码说明****************************/ /****************************cmd_id命令码说明****************************/
/****************************cmd_id命令码说明****************************/ /****************************cmd_id命令码说明****************************/
@ -77,7 +76,7 @@ typedef enum
ID_aerial_robot_energy = 0x0205, // 空中机器人能量状态数据 ID_aerial_robot_energy = 0x0205, // 空中机器人能量状态数据
ID_robot_hurt = 0x0206, // 伤害状态数据 ID_robot_hurt = 0x0206, // 伤害状态数据
ID_shoot_data = 0x0207, // 实时射击数据 ID_shoot_data = 0x0207, // 实时射击数据
ID_student_interactive = 0x0301, // 机器人间交互数据 ID_student_interactive = 0x0301, // 机器人间交互数据
} CmdID; } CmdID;
/* 命令码数据段长,根据官方协议来定义长度 */ /* 命令码数据段长,根据官方协议来定义长度 */
@ -88,13 +87,13 @@ typedef enum
LEN_game_robot_HP = 2, // 0x0003 LEN_game_robot_HP = 2, // 0x0003
LEN_event_data = 4, // 0x0101 LEN_event_data = 4, // 0x0101
LEN_supply_projectile_action = 4, // 0x0102 LEN_supply_projectile_action = 4, // 0x0102
LEN_game_robot_state = 27, // 0x0201 LEN_game_robot_state = 27, // 0x0201
LEN_power_heat_data = 14, // 0x0202 LEN_power_heat_data = 14, // 0x0202
LEN_game_robot_pos = 16, // 0x0203 LEN_game_robot_pos = 16, // 0x0203
LEN_buff_musk = 1, // 0x0204 LEN_buff_musk = 1, // 0x0204
LEN_aerial_robot_energy = 1, // 0x0205 LEN_aerial_robot_energy = 1, // 0x0205
LEN_robot_hurt = 1, // 0x0206 LEN_robot_hurt = 1, // 0x0206
LEN_shoot_data = 7, // 0x0207 LEN_shoot_data = 7, // 0x0207
} JudgeDataLength; } JudgeDataLength;
/****************************接收数据的详细说明****************************/ /****************************接收数据的详细说明****************************/
@ -220,8 +219,68 @@ typedef struct
float bullet_speed; float bullet_speed;
} ext_shoot_data_t; } ext_shoot_data_t;
/****************************机器人间交互数据****************************/
/****************************机器人间交互数据****************************/
/* 发送的内容数据段最大为 113 检测是否超出大小限制
30
syhtodo */
/* 交互数据头结构 */
typedef struct
{
uint16_t data_cmd_id;
uint16_t sender_ID;
uint16_t receiver_ID;
} ext_student_interactive_header_data_t;
/* 内容ID数据 */
//己方机器人通信未写实际上删除几个图形的id可以直接计算得出
typedef enum
{
UI_Data_ID_Del = 0x100,
UI_Data_ID_Draw1 = 0x101,
UI_Data_ID_Draw2 = 0x102,
UI_Data_ID_Draw5 = 0x103,
UI_Data_ID_Draw7 = 0x104,
UI_Data_ID_DrawChar = 0x110,
} UI_Data_ID;
typedef enum
{
UI_Data_LEN_Del = 6+2,
UI_Data_LEN_Draw1 = 6+15,
UI_Data_LEN_Draw2 = 6+30,
UI_Data_LEN_Draw5 = 6+75,
UI_Data_LEN_Draw7 = 6+105,
UI_Data_LEN_DrawChar = 6+15+30,//syhtodo 其实没啥用,换成各部分,可以直接带入计算
} UI_Data_Length;
/* 图形数据 */
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_t;//syhtodo 定义要有-t
typedef struct
{
Graph_Data_t Graph_Control;
uint8_t show_Data[30];
} String_Data_t; //打印字符串数据
#pragma pack() #pragma pack()
#endif #endif