From fd0b503e1a507e2e0151454d31182b8afe57c7d8 Mon Sep 17 00:00:00 2001 From: Yunhorn Date: Tue, 19 Dec 2023 19:19:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'decoder.js'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- decoder.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 decoder.js diff --git a/decoder.js b/decoder.js new file mode 100644 index 0000000..fe4cb01 --- /dev/null +++ b/decoder.js @@ -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]+"%", + } + ]; + } + }; \ No newline at end of file