node-zserial 1.0.32 → 1.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/zserial.js +9 -0
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "node-zserial",
3
- "version": "1.0.32",
3
+ "version": "1.0.33",
4
4
  "description": "Node-RED nodes to talk to serial ports",
5
5
  "dependencies": {
6
6
  "serialport": "^12.0.0"
7
7
  },
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/bensonzhow/node-red-zserialport.git"
10
+ "url": "git+https://github.com/bensonzhow/node-red-zserialport.git"
11
11
  },
12
12
  "keywords": [
13
13
  "node-red",
package/zserial.js CHANGED
@@ -1082,6 +1082,15 @@ module.exports = function (RED) {
1082
1082
  if (b.length >= 4 && b[3] === 0x16) {
1083
1083
  return { ok: false };
1084
1084
  }
1085
+ // 约束 3:控制域 C 必须看起来像 698 的控制域(功能码通常为 1=链路管理 或 3=用户数据)
1086
+ // 目的:避免 645 的地址字节被当成 698 控制域,从而把 645 整帧误判为 698-LEN 候选帧并被消费掉。
1087
+ // 698 控制域:bit0..bit3 为功能码(1 或 3 最常见);其他位为 DIR/PRM/分帧/扰码标志。
1088
+ const C = b[3] >>> 0;
1089
+ const func = C & 0x0F;
1090
+ if (!(func === 0x01 || func === 0x03)) {
1091
+ // 不消费任何字节,让 645 解析器继续尝试
1092
+ return { ok: false };
1093
+ }
1085
1094
  // ------------------------------------------------------------------------
1086
1095
 
1087
1096
  // 期望 0x16 的位置(相对 b 起点):1 + L