node-red-zelecproto 0.0.2 → 0.0.3
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.
- package/698.js +28 -18
- package/package.json +1 -1
- package/test.js +12 -0
package/698.js
CHANGED
|
@@ -13,6 +13,13 @@
|
|
|
13
13
|
|
|
14
14
|
/** ===================== 工具/常量 ===================== */
|
|
15
15
|
|
|
16
|
+
|
|
17
|
+
let mlog={
|
|
18
|
+
debug: function(...args){ console.log("[DEBUG]", ...args); },
|
|
19
|
+
status: function(...args){ console.log("[STATUS]", ...args); },
|
|
20
|
+
error: function(...args){ console.error("[ERROR]", ...args); }
|
|
21
|
+
}
|
|
22
|
+
|
|
16
23
|
// CRC-16/X-25
|
|
17
24
|
function crc16X25(buffer) {
|
|
18
25
|
const CRC_TABLE = Uint16Array.from([
|
|
@@ -1258,15 +1265,15 @@ function parsePowerAbnormalCount(dataBuffer) {
|
|
|
1258
1265
|
const { result: generic } = enhancedParseData(dataBuffer, '302C', '07');
|
|
1259
1266
|
|
|
1260
1267
|
const nums = [];
|
|
1261
|
-
function collect(
|
|
1262
|
-
if (!
|
|
1263
|
-
if (typeof
|
|
1264
|
-
if (Array.isArray(
|
|
1265
|
-
if (typeof
|
|
1266
|
-
if (typeof
|
|
1267
|
-
collect(
|
|
1268
|
-
if (
|
|
1269
|
-
if (
|
|
1268
|
+
function collect(nitem, depth = 0) {
|
|
1269
|
+
if (!nitem || depth > 8) return;
|
|
1270
|
+
if (typeof nitem === 'number') { nums.push(nitem); return; }
|
|
1271
|
+
if (Array.isArray(nitem)) { for (const it of nitem) collect(it, depth + 1); return; }
|
|
1272
|
+
if (typeof nitem === 'object') {
|
|
1273
|
+
if (typeof nitem.parsedValue === 'number') nums.push(nitem.parsedValue);
|
|
1274
|
+
collect(nitem.parsedValue, depth + 1);
|
|
1275
|
+
if (nitem.value && nitem.value !== nitem.parsedValue) collect(nitem.value, depth + 1);
|
|
1276
|
+
if (nitem.data && nitem.data !== nitem.parsedValue && nitem.data !== nitem.value) collect(nitem.data, depth + 1);
|
|
1270
1277
|
}
|
|
1271
1278
|
}
|
|
1272
1279
|
collect(generic);
|
|
@@ -2877,7 +2884,8 @@ function batchMsg(_msg, mode) {
|
|
|
2877
2884
|
frameLen: finalFrame.length,
|
|
2878
2885
|
time: new Date().toISOString()
|
|
2879
2886
|
};
|
|
2880
|
-
if (typeof node !== 'undefined' && node) node.status({ fill: 'green', shape: 'dot', text: `编码成功: ${finalFrame.length}B` });
|
|
2887
|
+
// if (typeof node !== 'undefined' && node) node.status({ fill: 'green', shape: 'dot', text: `编码成功: ${finalFrame.length}B` });
|
|
2888
|
+
mlog.status({ fill: 'green', shape: 'dot', text: `编码成功: ${finalFrame.length}B` });
|
|
2881
2889
|
_msg = Object.assign({}, _pdata, _msg);
|
|
2882
2890
|
return _msg;
|
|
2883
2891
|
|
|
@@ -2924,14 +2932,17 @@ function batchMsg(_msg, mode) {
|
|
|
2924
2932
|
: `解码成功: ${result.unifiedFormat.objectInfo?.desc || result.unifiedFormat.type}`;
|
|
2925
2933
|
const statusFill = (_msg.payload && _msg.payload.error) ? "red" : "green";
|
|
2926
2934
|
|
|
2927
|
-
node.status({ fill: statusFill, shape: "dot", text: statusText });
|
|
2928
|
-
|
|
2935
|
+
// node.status({ fill: statusFill, shape: "dot", text: statusText });
|
|
2936
|
+
mlog.status({ fill: statusFill, shape: "dot", text: statusText });
|
|
2929
2937
|
return _msg;
|
|
2930
2938
|
}
|
|
2931
2939
|
|
|
2932
2940
|
} catch (err) {
|
|
2933
|
-
node.status({ fill: 'red', shape: 'ring', text: `${mode === 'encode' ? '编码' : '解码'}异常` });
|
|
2934
|
-
node.error(`[DLT698-Codec] ${err.message}`, _msg);
|
|
2941
|
+
// node.status({ fill: 'red', shape: 'ring', text: `${mode === 'encode' ? '编码' : '解码'}异常` });
|
|
2942
|
+
// node.error(`[DLT698-Codec] ${err.message}`, _msg);
|
|
2943
|
+
mlog.status({ fill: 'red', shape: 'ring', text: `${mode === 'encode' ? '编码' : '解码'}异常` });
|
|
2944
|
+
mlog.error(`[DLT698-Codec] ${err.message}`, _msg);
|
|
2945
|
+
|
|
2935
2946
|
_msg.error = err.message;
|
|
2936
2947
|
_msg._mode = mode;
|
|
2937
2948
|
_msg.payload = null;
|
|
@@ -2943,6 +2954,7 @@ function batchMsg(_msg, mode) {
|
|
|
2943
2954
|
|
|
2944
2955
|
|
|
2945
2956
|
|
|
2957
|
+
|
|
2946
2958
|
function bufferSummary(buf, maxFullSize = 1024) {
|
|
2947
2959
|
if (!Buffer.isBuffer(buf)) {
|
|
2948
2960
|
return String(buf);
|
|
@@ -2986,10 +2998,8 @@ function batchMsg698(msg) {
|
|
|
2986
2998
|
}
|
|
2987
2999
|
|
|
2988
3000
|
} catch (error) {
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
node.error("msg.payload 传入协议解析只支持String和Array", msg);
|
|
2992
|
-
}
|
|
3001
|
+
throw new Error(`msg.payload 传入协议解析只支持String和Array,${error}`);
|
|
3002
|
+
|
|
2993
3003
|
}
|
|
2994
3004
|
}
|
|
2995
3005
|
}
|
package/package.json
CHANGED
package/test.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
var proto645 = require("./645");
|
|
3
|
+
var proto698 = require("./698");
|
|
4
|
+
|
|
5
|
+
let msg = {};
|
|
6
|
+
msg.payload = '68 39 00 C3 05 94 18 05 08 37 00 11 97 E1 90 01 20 A0 85 A9 10 C3 33 0D 19 30 D4 EA 61 05 39 C8 41 7F A8 07 63 5C D4 56 A4 D9 C6 F2 2F 98 2A D9 F0 01 00 04 05 78 AC 43 73 01 16 '
|
|
7
|
+
msg.proto = 698
|
|
8
|
+
msg.mode = 'decode'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
console.log(proto698(msg));
|