适配下位机STM32 unpack

This commit is contained in:
xin
2024-01-25 13:10:47 +08:00
parent 740dda620f
commit 5c6fe7b311
8 changed files with 262 additions and 20 deletions

View File

@ -69,7 +69,7 @@ json定义比较灵活 但是根对象必须提供如下:
#include <stdint.h>
#include <Communication_struct.h>
// DEFINE The protocol Here
//Forexample
//Forexample
// #define MYCOMAN 0x02 //命令全大写
// todo : define your protocol here
/*-------------------------------------------------------------------------------------------------------------*/
@ -87,19 +87,35 @@ json定义比较灵活 但是根对象必须提供如下:
/*-------------------------------------------------------------------------------------------------------------*/
/*
在此之下开始定义一些函数
*/
#define ERROR_NOT_ENOUGH_DATA -200
#define ERROR_HEADER -300
#define ERROR_COMMAND -400
#define ERROR_INPUT -500
#define ERROR_CRC -600
// 成功返回打包后的数据长度
// -1: Error
// 成功返回打包后的数据长度
int32_t IRIS_Protocol_Pack(uint8_t Command,uint16_t LenthofIn, uint8_t *BufferIn, uint8_t *PackData);
// 解包函数 PackData 是接收到的数据 LenthofIn 是数据长度 Command 是命令 BufferOut 是输出
// 下位机使用的打包函数 Command 是输出
// 成功返回解包后的数据长度
// 0: 该命令返回无参数
// 错误返回ERRor
// 成功返回解包后的数据长度
int32_t IRIS_STM32_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t *Command, uint8_t *BufferOut);
// 解包函数 PackData 是接收到的数据 LenthofIn 是数据长度 Command 是命令输入 BufferOut 是输出 上位机使用
// 成功返回解包后的数据长度
// 0: 该命令返回无参数
// -1: checksum error
// -100: parameter error
// -200: header error
// -300: command error
// -400: length error
// 错误返回ERRor
// 成功返回解包后的数据长度
int32_t IRIS_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t Command, uint8_t *BufferOut);
@ -108,6 +124,12 @@ int32_t IRIS_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t Comm
// -1: Error
int32_t IRIS_Cut_Befor_Header(uint8_t *PackData, uint16_t LenthofIn );
// 检查数据是否有效
// 有效返回值1
// 错误返回ERRor
int32_t IRIS_Check_Data_Valid(uint8_t *PackData, uint16_t LenthofIn );
// 返回CRC校验值
uint16_t IRIS_calcCRC(const void *pBuffer, uint16_t bufferSize);
#endif