添加 'decoder.js'

This commit is contained in:
Yunhorn 2023-12-19 19:19:54 +08:00
parent a1ea2a9ee7
commit fd0b503e1a
1 changed files with 32 additions and 0 deletions

32
decoder.js Normal file
View File

@ -0,0 +1,32 @@
function Decode(fPort, data, variables) {
if (fPort === 13) {
return [
{
led_state: bytes[0]===0?"Off":"On",
mtm_code_1: bytes[1],
mtm_code_2: bytes[2],
hw_code: bytes[3],
battery_level: bytes[4]+"%",
size_value: bytes[5],
spot_cnt: bytes[6]+" blocks",
spillage_level: bytes[7]+"%",
top1_position:"X= "+bytes[8]%10+" Y= "+ parseFloat(bytes[8]/10).toFixed(0),
top2_position:"X= "+bytes[9]%10+" Y= "+ parseFloat(bytes[9]/10).toFixed(0),
top3_position:"X= "+bytes[10]%10+" Y= "+ parseFloat(bytes[10]/10).toFixed(0),
top4_position:"X= "+bytes[11]%10+" Y= "+ parseFloat(bytes[11]/10).toFixed(0),
min_temp: (bytes[12] | bytes[13] / 100)+"C",
average_temp: (bytes[14] + bytes[15] / 100)+"C",
max_temp: (bytes[16] + bytes[17] / 100)+"C",
center_temp: (bytes[18] + bytes[19] / 100)+"C",
}
]
}
else if (fPort === 14) {
return [
{
led_state: (bytes[0]&0x7f)===0?"Off":"On",
battery_level: bytes[1]+"%",
}
];
}
};