Browse Source

spoolend 【修改文档】差异点梳理

dma_temp
Lizongdi 1 week ago
parent
commit
5e95fb8c7e
  1. 12
      project/Spoolend/README.md
  2. 14
      project/Spoolend/modbus.c

12
project/Spoolend/README.md

@ -221,7 +221,7 @@ set(SRC_LIST
| 项目 | 内容 | | 项目 | 内容 |
|------|------| |------|------|
| 操作 | 发送: `34 03 000B 0002 CRC` (从地址11开始读2个) | | 操作 | 发送: `34 03 000B 0002 CRC` (从地址11开始读2个) |
| 预期响应 | `34 83 02 CRC` (异常码 0x02: 非法数据地址) | | 预期响应 | `34 80 02 CRC` (异常码 0x02: 非法数据地址) |
### TC-MODBUS-04: FC06 写单个寄存器 — 写 K1 控制 ### TC-MODBUS-04: FC06 写单个寄存器 — 写 K1 控制
@ -236,7 +236,7 @@ set(SRC_LIST
| 项目 | 内容 | | 项目 | 内容 |
|------|------| |------|------|
| 操作 | 发送: `34 06 000C 0000 CRC` (地址 12 超出范围) | | 操作 | 发送: `34 06 000C 0000 CRC` (地址 12 超出范围) |
| 预期响应 | `34 86 02 CRC` (异常码 0x02) | | 预期响应 | `34 80 02 CRC` (异常码 0x02) |
### TC-MODBUS-06: FC10 写多个寄存器 — 批量写入 K1-K4 ### TC-MODBUS-06: FC10 写多个寄存器 — 批量写入 K1-K4
@ -251,7 +251,7 @@ set(SRC_LIST
| 项目 | 内容 | | 项目 | 内容 |
|------|------| |------|------|
| 操作 | 发送: `34 10 0000 0004 04 0001 0000 CRC` (byteCount=4 但 registerCount=4 需要 8 字节) | | 操作 | 发送: `34 10 0000 0004 04 0001 0000 CRC` (byteCount=4 但 registerCount=4 需要 8 字节) |
| 预期响应 | `34 90 03 CRC` (异常码 0x03) | | 预期响应 | `34 80 03 CRC` (异常码 0x03) |
### TC-MODBUS-08: FC10 写多个寄存器 — 只读寄存器保护 ### TC-MODBUS-08: FC10 写多个寄存器 — 只读寄存器保护
@ -273,7 +273,7 @@ set(SRC_LIST
| 项目 | 内容 | | 项目 | 内容 |
|------|------| |------|------|
| 操作 | 发送: `34 01 0000 0001 CRC` (FC01 不支持) | | 操作 | 发送: `34 01 0000 0001 CRC` (FC01 不支持) |
| 预期响应 | `34 81 01 CRC` (异常码 0x01) | | 预期响应 | 无响应(静默丢弃) |
--- ---
@ -310,7 +310,7 @@ set(SRC_LIST
| 项目 | 内容 | | 项目 | 内容 |
|------|------| |------|------|
| 前置条件 | holdingRegisters[5]=0 (自动), [4]=0 (正极性), [7]=5000 (5秒超时) | | 前置条件 | holdingRegisters[5]=0 (自动), [4]=0 (正极性), [7]=0x1388 (5秒超时) |
| 操作 | 持续发送 Modbus 命令(间隔 < 5秒 | | 操作 | 持续发送 Modbus 命令(间隔 < 5秒 |
| 预期 | K5 引脚保持低电平(电源开启,正极性时 RESET=开) | | 预期 | K5 引脚保持低电平(电源开启,正极性时 RESET=开) |
@ -424,7 +424,7 @@ set(SRC_LIST
| 项目 | 内容 | | 项目 | 内容 |
|------|------| |------|------|
| 操作 | 修改 K1-K4 为自定义值,FC06 写 holdingRegisters[10]=55 | | 操作 | 修改 K1-K4 为自定义值,FC06 写 holdingRegisters[10]=0x37 |
| 预期 | 参数写入 Flash 最后一页;holdingRegisters[10] 自动变为 1 | | 预期 | 参数写入 Flash 最后一页;holdingRegisters[10] 自动变为 1 |
| 验证 | 发送 FC03 读取确认 [10]=1 | | 验证 | 发送 FC03 读取确认 [10]=1 |

14
project/Spoolend/modbus.c

@ -91,7 +91,7 @@ int Modbus_Slave_Check(char *_pBuffer, uint32_t _iSize)
} }
break; break;
default: default:
return -1; return -1; // 由于这一行导致当前的不支持功能码的行为也是静默不响应
} }
if (_iSize < expected_len) return 0; if (_iSize < expected_len) return 0;
@ -150,13 +150,13 @@ void Modbus_Slave_Decode(const char *_pBuffer, uint32_t _iSize)
} }
else else
{ {
Modbus_SendExceptionResponse(0x03); Modbus_SendExceptionResponse(0x03);// 数据长度错误
} }
} }
break; break;
default: default:
Modbus_SendExceptionResponse(0x01); //Modbus_SendExceptionResponse(0x01); // 不支持的功能码
break; break;
} }
} }
@ -170,7 +170,7 @@ static void Modbus_HandleFunction03(uint16_t startAddress, uint16_t registerCoun
|| startAddress + registerCount > REGISTER_START_ADDRESS + REGISTER_COUNT || startAddress + registerCount > REGISTER_START_ADDRESS + REGISTER_COUNT
|| registerCount > 0x7D) || registerCount > 0x7D)
{ {
Modbus_SendExceptionResponse(0x02); Modbus_SendExceptionResponse(0x02);// 地址错误
return; return;
} }
@ -208,7 +208,7 @@ static void Modbus_HandleFunction06(uint16_t registerAddress, uint16_t value)
if (registerAddress < REGISTER_START_ADDRESS if (registerAddress < REGISTER_START_ADDRESS
|| registerAddress >= REGISTER_START_ADDRESS + REGISTER_COUNT) || registerAddress >= REGISTER_START_ADDRESS + REGISTER_COUNT)
{ {
Modbus_SendExceptionResponse(0x02); Modbus_SendExceptionResponse(0x02);// 地址错误
return; return;
} }
@ -239,7 +239,7 @@ static void Modbus_HandleFunction10(uint16_t startAddress, uint16_t registerCoun
|| startAddress + registerCount > REGISTER_START_ADDRESS + REGISTER_COUNT || startAddress + registerCount > REGISTER_START_ADDRESS + REGISTER_COUNT
|| registerCount == 0 || registerCount > 0x7B) || registerCount == 0 || registerCount > 0x7B)
{ {
Modbus_SendExceptionResponse(0x02); Modbus_SendExceptionResponse(0x02);// 地址错误
return; return;
} }
@ -278,7 +278,7 @@ static void Modbus_SendExceptionResponse(uint8_t exceptionCode)
extern TComCtrl *g_ptRS485_1; extern TComCtrl *g_ptRS485_1;
response[0] = MODBUS_SLAVE_ADDRESS; response[0] = MODBUS_SLAVE_ADDRESS;
response[1] = 0x80; response[1] = 0x80; //这里与原版差异为直接回复0x80而不是与一个功能码
response[2] = exceptionCode; response[2] = exceptionCode;
uint16_t crc = CalculateCRC(response, 3); uint16_t crc = CalculateCRC(response, 3);

Loading…
Cancel
Save