1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| key-data-change-rule-5601808030001129
{ "str": { "processorFn": "const arr = data.split(':'); return[{attr: arr[0],val:arr[1]}];" }, "hex": { "framework": { // hex 偏移量规则 本例基于 modbus 协议制定 "address": 2, "command": 2, "length": 2, "data": "*", "crc": 4 }, "data": "data", // 数据属性名 "dataChangeFn": [ // 数据转换格式,位置参数 "data = data + 'ms'; return{attr:'SSLL',val:data};", "data = data + 'ms'; return{attr:'LJLL',val:data};" ], "checkTag": "crc", "checkFn": {
}, // 解码规则 (基于 modbus 协议) "processorFn": "const count = data.length / 8;const dataItemList = [];let offset = 0;for (let i = 1; i <= count; i++){let subData = data.slice(offset, offset + 8);const h = subData.slice(0, 4);const l = subData.slice(4, 8);const data_bit = parseInt(l + h, 16).toString(2);const data_E = parseInt(data_bit.slice(0, 8), 2);const data_M = data_bit.slice(8, 64);let data_M_10 = 0.0;for (var j = 0; j < data_M.length; j++){data_M_10 = data_M_10 + data_M[j]* Math.pow(2, -1 * (j + 1));}const readData = Math.pow(2, data_E - 127) * (1 + data_M_10);dataItemList.push(readData);offset += 8;}return dataItemList;" }, "json": { "processorFn": "const jsonStr = JSON.parse(data);const datas = jsonStr.data;return [{attr:'YL',val:datas[0].ch1}];" } }
|