Compare commits
2 Commits
74b80c24b8
...
164ba745a3
Author | SHA1 | Date | |
---|---|---|---|
164ba745a3 | |||
a3ac3b3ec1 |
@ -11,6 +11,22 @@
|
|||||||
// #define MYCOMAN 0x02 //命令全大写
|
// #define MYCOMAN 0x02 //命令全大写
|
||||||
// todo : define your protocol here
|
// 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 0x55
|
||||||
|
#define SET_SHUTTER_CLOSE 0x56
|
||||||
|
#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.
|
// Created by xin on 2024/2/1.
|
||||||
//
|
//
|
||||||
#include "IRIS_Method.h"
|
#include "IRIS_Method.h"
|
||||||
|
#include <string.h>
|
||||||
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) {
|
||||||
if (PackData == NULL || (LenthofIn != 0 && BufferIn == NULL)) {
|
if (PackData == NULL || (LenthofIn != 0 && BufferIn == NULL)) {
|
||||||
return -1;
|
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);
|
memcpy(&PackData[5], BufferIn, LenthofIn);
|
||||||
}
|
}
|
||||||
uint16_t crcbytelenth = LenthofIn;
|
uint16_t crcbytelenth = LenthofIn;
|
||||||
uint16_t CRC = IRIS_calcCRC(PackData + 5, crcbytelenth);
|
uint16_t CRC_CRC = IRIS_calcCRC(PackData + 5, crcbytelenth);
|
||||||
PackData[LenthofIn + 5] = (CRC >> 8) & 0xFF;
|
PackData[LenthofIn + 5] = (CRC_CRC >> 8) & 0xFF;
|
||||||
PackData[LenthofIn + 6] = CRC & 0xFF;
|
PackData[LenthofIn + 6] = CRC_CRC & 0xFF;
|
||||||
return LenthofIn + 7;
|
return LenthofIn + 7;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t IRIS_STM32_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) {
|
||||||
@ -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) {
|
if (PackData[LenthofOut + 6] == 0xEE && PackData[LenthofOut + 5] == 0xEE) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
uint16_t CRC = IRIS_calcCRC(PackData + 5, LenthofOut);
|
uint16_t CRC_CRC = IRIS_calcCRC(PackData + 5, LenthofOut);
|
||||||
if (CRC != (PackData[LenthofOut + 6] + (PackData[LenthofOut + 5] << 8))) {
|
if (CRC_CRC != (PackData[LenthofOut + 6] + (PackData[LenthofOut + 5] << 8))) {
|
||||||
return ERROR_CRC;
|
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) {
|
if (PackData[LenthofOut + 6] == 0xEE && PackData[LenthofOut + 5] == 0xEE) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
uint16_t CRC = IRIS_calcCRC(PackData + 5, LenthofOut);
|
uint16_t CRC_CRC = IRIS_calcCRC(PackData + 5, LenthofOut);
|
||||||
if (CRC != (PackData[LenthofOut + 6] + (PackData[LenthofOut + 5] << 8))) {
|
if (CRC_CRC != (PackData[LenthofOut + 6] + (PackData[LenthofOut + 5] << 8))) {
|
||||||
return ERROR_CRC;
|
return ERROR_CRC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,6 +104,9 @@ int32_t IRIS_Cut_Befor_Header(uint8_t *PackData, uint16_t LenthofIn) {
|
|||||||
if (PackData == NULL) {
|
if (PackData == NULL) {
|
||||||
return ERROR_INPUT;
|
return ERROR_INPUT;
|
||||||
}
|
}
|
||||||
|
if (LenthofIn <2) {
|
||||||
|
return LenthofIn;
|
||||||
|
}
|
||||||
uint16_t i = 0;
|
uint16_t i = 0;
|
||||||
for (i = 0; i < LenthofIn; i++) {
|
for (i = 0; i < LenthofIn; i++) {
|
||||||
if (PackData[i] == 0x55 && PackData[i + 1] == 0xAA) {
|
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) {
|
if (PackData[LenthofOut + 6] == 0xEE && PackData[LenthofOut + 5] == 0xEE) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
uint16_t CRC = IRIS_calcCRC(PackData + 5, LenthofOut);
|
uint16_t CRC_CRC = IRIS_calcCRC(PackData + 5, LenthofOut);
|
||||||
if (CRC != (PackData[LenthofOut + 6] + (PackData[LenthofOut + 5] << 8))) {
|
if (CRC_CRC != (PackData[LenthofOut + 6] + (PackData[LenthofOut + 5] << 8))) {
|
||||||
return ERROR_CRC;
|
return ERROR_CRC;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @file : IRIS_Method.h
|
* @file : IRIS_Method.h
|
||||||
* @author : xin
|
* @author : xin
|
||||||
* @brief : None
|
* @brief : None
|
||||||
@ -20,7 +20,8 @@
|
|||||||
#define ERROR_COMMAND -400
|
#define ERROR_COMMAND -400
|
||||||
#define ERROR_INPUT -500
|
#define ERROR_INPUT -500
|
||||||
#define ERROR_CRC -600
|
#define ERROR_CRC -600
|
||||||
|
#include <stdint.h>
|
||||||
|
//#include<Arduino.h>
|
||||||
|
|
||||||
// 成功返回打包后的数据长度
|
// 成功返回打包后的数据长度
|
||||||
// -1: Error
|
// -1: Error
|
||||||
|
Reference in New Issue
Block a user