Compare commits
2 Commits
740dda620f
...
d46bfa797d
Author | SHA1 | Date | |
---|---|---|---|
d46bfa797d | |||
5c6fe7b311 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
/.vscode/
|
/.vscode/
|
||||||
|
.idea
|
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# 基于编辑器的 HTTP 客户端请求
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
8
.idea/IRIS_Communication_Protocol.iml
generated
Normal file
8
.idea/IRIS_Communication_Protocol.iml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="CPP_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
105
.idea/deployment.xml
generated
Normal file
105
.idea/deployment.xml
generated
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="PublishConfigData" remoteFilesAllowedToDisappearOnAutoupload="false">
|
||||||
|
<serverData>
|
||||||
|
<paths name="ASDRadStation (0340c8fe-13af-4239-8cd7-9e5c44db25b0)">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="FSA (64660c1e-3077-4ca8-9d3c-230a28ead929)">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="FSAANDIS2 (fb91b536-9577-4b25-b407-58ea13389c0c)">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="M300CO2 (6fad263c-26b3-46ec-b752-eb124f26db19)">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="NanopiM4_air">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="TowerIS2 (db954183-53fc-4ada-9339-7bcf07f6e961)">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="forlinux (3f835093-ccb8-4ad3-9031-a7fd02ff9517)">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="is2 (92fcd400-343f-4bff-8ff2-c89556823e34)">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="nanopiM4 (c7faf773-a5c9-4127-92c5-fbf9ece802a0)">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="nanopiserver (6ad11e01-52ec-4934-8eb0-fefc1e30d593)">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="rockme (cd04aadc-c7bb-46a5-979e-b86bac017707)">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="testgui (2e6cddd8-02ba-48d6-ba20-19b504f11653)">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="topirr (8e108d97-9abd-4587-8f26-0eff66629188)">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="远程主机 (d789e20a-7887-454e-a5b8-dbb0c4612a02)">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
</serverData>
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/IRIS_Communication_Protocol.iml" filepath="$PROJECT_DIR$/.idea/IRIS_Communication_Protocol.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
32
Readme.md
32
Readme.md
@ -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
|
// -1: Error
|
||||||
// 成功返回打包后的数据长度
|
// 成功返回打包后的数据长度
|
||||||
int32_t IRIS_Protocol_Pack(uint8_t Command,uint16_t LenthofIn, uint8_t *BufferIn, uint8_t *PackData);
|
int32_t IRIS_Protocol_Pack(uint8_t Command,uint16_t LenthofIn, uint8_t *BufferIn, uint8_t *PackData);
|
||||||
|
|
||||||
|
// 解包函数 PackData 是接收到的数据 LenthofIn 是数据长度 Command 是命令 BufferOut 是输出
|
||||||
|
// 下位机使用的打包函数 Command 是输出
|
||||||
// 成功返回解包后的数据长度
|
// 成功返回解包后的数据长度
|
||||||
// 0: 该命令返回无参数
|
// 0: 该命令返回无参数
|
||||||
// -1: checksum error
|
// 错误返回ERRor
|
||||||
// -100: parameter error
|
// 成功返回解包后的数据长度
|
||||||
// -200: header error
|
int32_t IRIS_STM32_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t *Command, uint8_t *BufferOut);
|
||||||
// -300: command error
|
|
||||||
// -400: length error
|
// 解包函数 PackData 是接收到的数据 LenthofIn 是数据长度 Command 是命令输入 BufferOut 是输出 上位机使用
|
||||||
|
// 成功返回解包后的数据长度
|
||||||
|
// 0: 该命令返回无参数
|
||||||
|
// 错误返回ERRor
|
||||||
// 成功返回解包后的数据长度
|
// 成功返回解包后的数据长度
|
||||||
int32_t IRIS_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t Command, uint8_t *BufferOut);
|
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
|
// -1: Error
|
||||||
int32_t IRIS_Cut_Befor_Header(uint8_t *PackData, uint16_t LenthofIn );
|
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校验值
|
// 返回CRC校验值
|
||||||
uint16_t IRIS_calcCRC(const void *pBuffer, uint16_t bufferSize);
|
uint16_t IRIS_calcCRC(const void *pBuffer, uint16_t bufferSize);
|
||||||
#endif
|
#endif
|
||||||
|
@ -27,29 +27,62 @@ int32_t IRIS_Protocol_Pack(uint8_t Command,uint16_t LenthofIn, uint8_t *BufferIn
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t IRIS_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t Command, uint8_t *BufferOut)
|
int32_t IRIS_STM32_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t *Command, uint8_t *BufferOut)
|
||||||
{
|
{
|
||||||
|
|
||||||
if( PackData == NULL || BufferOut == NULL)
|
if( PackData == NULL || BufferOut == NULL)
|
||||||
{
|
{
|
||||||
return -100;
|
return ERROR_INPUT;
|
||||||
}
|
}
|
||||||
if(PackData[0] != 0x55 || PackData[1] != 0xAA)
|
if(PackData[0] != 0x55 || PackData[1] != 0xAA)
|
||||||
{
|
{
|
||||||
return -200;
|
return ERROR_HEADER;
|
||||||
}
|
|
||||||
if(PackData[2] != Command)
|
|
||||||
{
|
|
||||||
return -300;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t LenthofOut = PackData[3] + (PackData[4] << 8);
|
uint16_t LenthofOut = PackData[3] + (PackData[4] << 8);
|
||||||
if(LenthofOut > LenthofIn - 7)
|
if(LenthofOut > LenthofIn - 7)
|
||||||
{
|
{
|
||||||
return -400;
|
return ERROR_NOT_ENOUGH_DATA;
|
||||||
}
|
}
|
||||||
uint16_t CRC = IRIS_calcCRC(PackData, LenthofOut+5);
|
uint16_t CRC = IRIS_calcCRC(PackData, LenthofOut+5);
|
||||||
if(CRC != (PackData[LenthofOut+5] + (PackData[LenthofOut+6] << 8)))
|
if(CRC != (PackData[LenthofOut+5] + (PackData[LenthofOut+6] << 8)))
|
||||||
{
|
{
|
||||||
return -1;
|
return ERROR_CRC;
|
||||||
|
}
|
||||||
|
if(LenthofOut == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*Command=PackData[2] ;
|
||||||
|
|
||||||
|
memcpy(BufferOut,&PackData[5],LenthofOut);
|
||||||
|
return LenthofOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32_t IRIS_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t Command, uint8_t *BufferOut)
|
||||||
|
{
|
||||||
|
if( PackData == NULL || BufferOut == NULL)
|
||||||
|
{
|
||||||
|
return ERROR_INPUT;
|
||||||
|
}
|
||||||
|
if(PackData[0] != 0x55 || PackData[1] != 0xAA)
|
||||||
|
{
|
||||||
|
return ERROR_HEADER
|
||||||
|
}
|
||||||
|
if(PackData[2] != Command)
|
||||||
|
{
|
||||||
|
return ERROR_COMMAND;
|
||||||
|
}
|
||||||
|
uint16_t LenthofOut = PackData[3] + (PackData[4] << 8);
|
||||||
|
if(LenthofOut > LenthofIn - 7)
|
||||||
|
{
|
||||||
|
return ERROR_NOT_ENOUGH_DATA;
|
||||||
|
}
|
||||||
|
uint16_t CRC = IRIS_calcCRC(PackData, LenthofOut+5);
|
||||||
|
if(CRC != (PackData[LenthofOut+5] + (PackData[LenthofOut+6] << 8)))
|
||||||
|
{
|
||||||
|
return ERROR_CRC;
|
||||||
}
|
}
|
||||||
if(LenthofOut == 0)
|
if(LenthofOut == 0)
|
||||||
{
|
{
|
||||||
@ -65,7 +98,7 @@ int32_t IRIS_Cut_Befor_Header(uint8_t *PackData, uint16_t LenthofIn )
|
|||||||
{
|
{
|
||||||
if( PackData == NULL )
|
if( PackData == NULL )
|
||||||
{
|
{
|
||||||
return -1;
|
return ERROR_INPUT
|
||||||
}
|
}
|
||||||
uint16_t i = 0;
|
uint16_t i = 0;
|
||||||
for(i = 0; i < LenthofIn; i++)
|
for(i = 0; i < LenthofIn; i++)
|
||||||
@ -87,6 +120,36 @@ int32_t IRIS_Cut_Befor_Header(uint8_t *PackData, uint16_t LenthofIn )
|
|||||||
return LenthofOut;
|
return LenthofOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t IRIS_Check_Data_Valid(uint8_t *PackData, uint16_t LenthofIn)
|
||||||
|
{
|
||||||
|
if( PackData == NULL)
|
||||||
|
{
|
||||||
|
return ERROR_INPUT;
|
||||||
|
}
|
||||||
|
if (LenthofIn < 7)
|
||||||
|
{
|
||||||
|
return ERROR_NOT_ENOUGH_DATA;
|
||||||
|
/* code */
|
||||||
|
}
|
||||||
|
|
||||||
|
if(PackData[0] != 0x55 || PackData[1] != 0xAA)
|
||||||
|
{
|
||||||
|
return ERROR_HEADER;
|
||||||
|
}
|
||||||
|
uint16_t LenthofOut = PackData[3] + (PackData[4] << 8);
|
||||||
|
if(LenthofOut > LenthofIn - 7)
|
||||||
|
{
|
||||||
|
return ERROR_NOT_ENOUGH_DATA;
|
||||||
|
}
|
||||||
|
uint16_t CRC = IRIS_calcCRC(PackData, LenthofOut+5);
|
||||||
|
if(CRC != (PackData[LenthofOut+5] + (PackData[LenthofOut+6] << 8)))
|
||||||
|
{
|
||||||
|
return ERROR_CRC;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,19 +24,35 @@
|
|||||||
/*-------------------------------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------------------------------*/
|
||||||
/*
|
/*
|
||||||
在此之下开始定义一些函数
|
在此之下开始定义一些函数
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
#define ERROR_NOT_ENOUGH_DATA -200
|
||||||
|
#define ERROR_HEADER -300
|
||||||
|
#define ERROR_COMMAND -400
|
||||||
|
#define ERROR_INPUT -500
|
||||||
|
#define ERROR_CRC -600
|
||||||
|
|
||||||
|
|
||||||
// 成功返回打包后的数据长度
|
// 成功返回打包后的数据长度
|
||||||
// -1: Error
|
// -1: Error
|
||||||
// 成功返回打包后的数据长度
|
// 成功返回打包后的数据长度
|
||||||
int32_t IRIS_Protocol_Pack(uint8_t Command,uint16_t LenthofIn, uint8_t *BufferIn, uint8_t *PackData);
|
int32_t IRIS_Protocol_Pack(uint8_t Command,uint16_t LenthofIn, uint8_t *BufferIn, uint8_t *PackData);
|
||||||
|
|
||||||
|
// 解包函数 PackData 是接收到的数据 LenthofIn 是数据长度 Command 是命令 BufferOut 是输出
|
||||||
|
// 下位机使用的打包函数 Command 是输出
|
||||||
// 成功返回解包后的数据长度
|
// 成功返回解包后的数据长度
|
||||||
// 0: 该命令返回无参数
|
// 0: 该命令返回无参数
|
||||||
// -1: checksum error
|
// 错误返回ERRor
|
||||||
// -100: parameter error
|
// 成功返回解包后的数据长度
|
||||||
// -200: header error
|
int32_t IRIS_STM32_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t *Command, uint8_t *BufferOut);
|
||||||
// -300: command error
|
|
||||||
// -400: length error
|
// 解包函数 PackData 是接收到的数据 LenthofIn 是数据长度 Command 是命令输入 BufferOut 是输出 上位机使用
|
||||||
|
// 成功返回解包后的数据长度
|
||||||
|
// 0: 该命令返回无参数
|
||||||
|
// 错误返回ERRor
|
||||||
// 成功返回解包后的数据长度
|
// 成功返回解包后的数据长度
|
||||||
int32_t IRIS_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t Command, uint8_t *BufferOut);
|
int32_t IRIS_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t Command, uint8_t *BufferOut);
|
||||||
|
|
||||||
@ -45,6 +61,12 @@ int32_t IRIS_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t Comm
|
|||||||
// -1: Error
|
// -1: Error
|
||||||
int32_t IRIS_Cut_Befor_Header(uint8_t *PackData, uint16_t LenthofIn );
|
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校验值
|
// 返回CRC校验值
|
||||||
uint16_t IRIS_calcCRC(const void *pBuffer, uint16_t bufferSize);
|
uint16_t IRIS_calcCRC(const void *pBuffer, uint16_t bufferSize);
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user