update crc16
This commit is contained in:
parent
d391743361
commit
b67eee24e7
27
protocol.c
27
protocol.c
@ -131,6 +131,12 @@ void InitDeviceStatus() {
|
||||
void writeCMD(uint8_t *txBuf, uint16_t *txLen) {
|
||||
}
|
||||
|
||||
uint8_t SendToHost(uint8_t *txBuf, uint16_t txLen) {
|
||||
// 发送数据到主机
|
||||
// 具体实现
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -177,8 +183,9 @@ uint16_t ReadPump1Reg(uint8_t index, uint16_t reg) {
|
||||
FillBigEndian16(&data[4], 2);
|
||||
|
||||
uint16_t crc = CalculateCRC16(data, 6);
|
||||
// 大端序填充
|
||||
FillBigEndian16(&data[6], crc);
|
||||
// 小端序填充
|
||||
memcpy(&data[6], &crc, 2);
|
||||
|
||||
|
||||
writeCMD(data, 8);
|
||||
}
|
||||
@ -191,8 +198,8 @@ uint8_t WritePump1Reg(uint8_t index, uint16_t reg, uint16_t value) {
|
||||
FillBigEndian16(&data[2], reg);
|
||||
FillBigEndian16(&data[4], value);
|
||||
uint16_t crc = CalculateCRC16(data, 6);
|
||||
// 大端序填充
|
||||
FillBigEndian16(&data[6], crc);
|
||||
// 小端序填充
|
||||
memcpy(&data[6], &crc, 2);
|
||||
|
||||
writeCMD(data, 8);
|
||||
}
|
||||
@ -207,8 +214,8 @@ uint8_t WritePump2Reg(uint8_t index, uint16_t reg, uint32_t value) {
|
||||
data[6] = 8;
|
||||
FillBigEndian32(&data[7], value);
|
||||
uint16_t crc = CalculateCRC16(data, 11);
|
||||
// 大端序填充
|
||||
FillBigEndian16(&data[11], crc);
|
||||
// 小端序填充
|
||||
memcpy(&data[11], &crc, 2);
|
||||
|
||||
writeCMD(data, 13);
|
||||
}
|
||||
@ -384,10 +391,12 @@ static uint8_t HandleInit(uint8_t *rxBuf, uint8_t *txBuf, uint16_t *txLen) {
|
||||
|
||||
|
||||
// 状态查询处理
|
||||
static uint8_t HandleStatusQuery(uint8_t *txBuf) {
|
||||
static uint8_t HandleStatusQuery(void) {
|
||||
// 填充并返回数据
|
||||
uint8_t txBuf[sizeof(DeviceStatus)] = {0};
|
||||
memcpy(txBuf, &deviceStatus, sizeof(DeviceStatus));
|
||||
return sizeof(DeviceStatus);
|
||||
SendToHost(txBuf, sizeof(txBuf));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 三通阀控制处理
|
||||
@ -524,7 +533,7 @@ CmdFrameError_t ProcessHostCommand(uint8_t *rxBuf, uint16_t rxLen) {
|
||||
|
||||
switch(cmdCode) {
|
||||
case CMD_STATUS_QUERY:
|
||||
error = HandleStatusQuery(data, dataLen);
|
||||
error = HandleStatusQuery();
|
||||
break;
|
||||
case CMD_VALVE_CTRL:
|
||||
error = HandleValveControl(data, dataLen);
|
||||
|
Loading…
Reference in New Issue
Block a user