Compare commits
4 Commits
2c03d0ecf5
...
main
Author | SHA1 | Date | |
---|---|---|---|
ede12920c7 | |||
164ba745a3 | |||
a3ac3b3ec1 | |||
74b80c24b8 |
10
Readme.md
10
Readme.md
@ -21,21 +21,21 @@
|
||||
|
||||
json定义比较灵活 但是根对象必须提供如下:
|
||||
|
||||
- CN: 命令名称
|
||||
- command: 命令名称
|
||||
|
||||
|
||||
|
||||
- PA:命令参数 //发送时必须 返回可选
|
||||
- PA:命令参数 //可选
|
||||
|
||||
返回时应提供相应状态
|
||||
|
||||
- ST:OK
|
||||
- ST:OK //可选
|
||||
|
||||
发送示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"CN":"SetCamerTime",
|
||||
"command":"SetCamerTime",
|
||||
"PA":{
|
||||
"time1":1000,
|
||||
"time2":1000
|
||||
@ -49,7 +49,7 @@ json定义比较灵活 但是根对象必须提供如下:
|
||||
|
||||
```json
|
||||
{
|
||||
"CN":"SetCamerTime",
|
||||
"command":"SetCamerTime",
|
||||
"Other":"自己定义",
|
||||
"ST":"OK"
|
||||
}
|
||||
|
@ -11,6 +11,22 @@
|
||||
// #define MYCOMAN 0x02 //命令全大写
|
||||
// todo : define your protocol here
|
||||
/*-------------------------------------------------------------------------------------------------------------*/
|
||||
#define GET_BASIC_INFO 0x50
|
||||
#define SET_INTEGRAL_TIME 0x51
|
||||
#define SET_AUTO_EXPOSURE 0x52
|
||||
#define GET_INTEGRAL_TIME_AND_DATA_PROCESS 0x53
|
||||
#define GET_TEMPRETURE 0x54
|
||||
#define SET_SHUTTER_OPEN 0x56
|
||||
#define SET_SHUTTER_CLOSE 0x55
|
||||
#define GET_BANDNUMBER 0x57
|
||||
#define SET_WEAVE_COEFF 0x58
|
||||
#define GET_WEAVE_COEFF 0x59
|
||||
#define SET_DATA_PROCESS_METHOD 0x60
|
||||
#define GET_DATA_FROM_SENSOR 0x61
|
||||
|
||||
|
||||
|
||||
#define NONE_DATA 0x00
|
||||
|
||||
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
// Created by xin on 2024/2/1.
|
||||
//
|
||||
#include "IRIS_Method.h"
|
||||
|
||||
#include <string.h>
|
||||
int32_t IRIS_Protocol_Pack(uint8_t Command, uint16_t LenthofIn, uint8_t *BufferIn, uint8_t *PackData) {
|
||||
if (PackData == NULL || (LenthofIn != 0 && BufferIn == NULL)) {
|
||||
return -1;
|
||||
@ -29,12 +29,10 @@ int32_t IRIS_Protocol_Pack(uint8_t Command, uint16_t LenthofIn, uint8_t *BufferI
|
||||
memcpy(&PackData[5], BufferIn, LenthofIn);
|
||||
}
|
||||
uint16_t crcbytelenth = LenthofIn;
|
||||
uint16_t CRC = IRIS_calcCRC(PackData + 5, crcbytelenth);
|
||||
PackData[LenthofIn + 5] = (CRC >> 8) & 0xFF;
|
||||
PackData[LenthofIn + 6] = CRC & 0xFF;
|
||||
uint16_t CRC_CRC = IRIS_calcCRC(PackData + 5, crcbytelenth);
|
||||
PackData[LenthofIn + 5] = (CRC_CRC >> 8) & 0xFF;
|
||||
PackData[LenthofIn + 6] = CRC_CRC & 0xFF;
|
||||
return LenthofIn + 7;
|
||||
|
||||
|
||||
}
|
||||
|
||||
int32_t IRIS_STM32_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t *Command, uint8_t *BufferOut) {
|
||||
@ -54,8 +52,8 @@ int32_t IRIS_STM32_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_
|
||||
if (PackData[LenthofOut + 6] == 0xEE && PackData[LenthofOut + 5] == 0xEE) {
|
||||
|
||||
} else {
|
||||
uint16_t CRC = IRIS_calcCRC(PackData + 5, LenthofOut);
|
||||
if (CRC != (PackData[LenthofOut + 6] + (PackData[LenthofOut + 5] << 8))) {
|
||||
uint16_t CRC_CRC = IRIS_calcCRC(PackData + 5, LenthofOut);
|
||||
if (CRC_CRC != (PackData[LenthofOut + 6] + (PackData[LenthofOut + 5] << 8))) {
|
||||
return ERROR_CRC;
|
||||
}
|
||||
}
|
||||
@ -88,8 +86,8 @@ int32_t IRIS_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t Comm
|
||||
if (PackData[LenthofOut + 6] == 0xEE && PackData[LenthofOut + 5] == 0xEE) {
|
||||
|
||||
} else {
|
||||
uint16_t CRC = IRIS_calcCRC(PackData + 5, LenthofOut);
|
||||
if (CRC != (PackData[LenthofOut + 6] + (PackData[LenthofOut + 5] << 8))) {
|
||||
uint16_t CRC_CRC = IRIS_calcCRC(PackData + 5, LenthofOut);
|
||||
if (CRC_CRC != (PackData[LenthofOut + 6] + (PackData[LenthofOut + 5] << 8))) {
|
||||
return ERROR_CRC;
|
||||
}
|
||||
}
|
||||
@ -106,6 +104,9 @@ int32_t IRIS_Cut_Befor_Header(uint8_t *PackData, uint16_t LenthofIn) {
|
||||
if (PackData == NULL) {
|
||||
return ERROR_INPUT;
|
||||
}
|
||||
if (LenthofIn <2) {
|
||||
return LenthofIn;
|
||||
}
|
||||
uint16_t i = 0;
|
||||
for (i = 0; i < LenthofIn; i++) {
|
||||
if (PackData[i] == 0x55 && PackData[i + 1] == 0xAA) {
|
||||
@ -142,8 +143,8 @@ int32_t IRIS_Check_Data_Valid(uint8_t *PackData, uint16_t LenthofIn) {
|
||||
if (PackData[LenthofOut + 6] == 0xEE && PackData[LenthofOut + 5] == 0xEE) {
|
||||
|
||||
} else {
|
||||
uint16_t CRC = IRIS_calcCRC(PackData + 5, LenthofOut);
|
||||
if (CRC != (PackData[LenthofOut + 6] + (PackData[LenthofOut + 5] << 8))) {
|
||||
uint16_t CRC_CRC = IRIS_calcCRC(PackData + 5, LenthofOut);
|
||||
if (CRC_CRC != (PackData[LenthofOut + 6] + (PackData[LenthofOut + 5] << 8))) {
|
||||
return ERROR_CRC;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
******************************************************************************
|
||||
* @file : IRIS_Method.h
|
||||
* @author : xin
|
||||
* @brief : None
|
||||
@ -20,7 +20,8 @@
|
||||
#define ERROR_COMMAND -400
|
||||
#define ERROR_INPUT -500
|
||||
#define ERROR_CRC -600
|
||||
|
||||
#include <stdint.h>
|
||||
//#include<Arduino.h>
|
||||
|
||||
// 成功返回打包后的数据长度
|
||||
// -1: Error
|
||||
|
Reference in New Issue
Block a user