From c77bfc506710e0a380ba1ffccc304f242bebeca4 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Mon, 19 May 2025 12:42:18 +0800 Subject: [PATCH] revised decoder for matrix 0 map --- hk_as923_decoder.js | 583 ++++++++++++++++++-------------------------- 1 file changed, 238 insertions(+), 345 deletions(-) diff --git a/hk_as923_decoder.js b/hk_as923_decoder.js index 27fd380..e72dc78 100644 --- a/hk_as923_decoder.js +++ b/hk_as923_decoder.js @@ -4,12 +4,21 @@ // - variables contains the device variables e.g. {"calibration": "3.5"} (both the key / value are of type string) // The function must return an object, e.g. {"temperature": 22.5} // -// Yunhorn SmarToilets Sensor R20241126A01 +// Yunhorn SmarToilets Sensor R20250519R01 // function Decode(fPort, data, variables) { var data = {}; data.length = bytes.length; + var code2color = { "0": "Dark", "1": "Green", "2": "Red", "3": "Blue", "4": "Yellow", "5": "Pink", "6": "Cyan", "7": "White" }; + var code2workmode = { "0": "Network_mode", "1": "Wired_mode", "2": "Hall_element_mode", "3": "Motion_detect_mode", "4": "Dual_mode", "5": "Uni_mode" }; + var code2state = { "0": "Not Occupied", "1": "Normal:Green", "2": "Warning:Yellow", "3": "Emegency:Red" }; + var code2fallstate = { "0": "Presence_Normal", "1": " Presence_Fall_Down", "2": " Presence_Rising_Up", "3": " Presence_LayDown", "4": " Presence_Unconcious", "5": " Presence_Stay_Still" }; + var movecode2state = { "0": " :Not Occupied", "1": " :Normal:Green", "2": " :Warning:Yellow", "3": " :Emegency:Red" }; + var fallcode2state = { "0": " Not Occupied", "1": " Normal:Green", "2": " Warning:Yellow", "3": " :Emegency:Red" }; + var occupancycode2state = { "0": " :Not Occupied", "1": " :Normal Occupancy:Green", "2": " :Over Time Warning:Yellow", "3": " :Over Time Emegency:Red" }; + var soscode2state = { "0": " :Normal: Released ", "1": " :Emegency:SOS Pushdown" }; + switch (fPort) { // RESPOND PORT --- bottom of swith fport // case 1: @@ -105,79 +114,20 @@ function Decode(fPort, data, variables) { // STS_O2_O6 V3 version 2023,pixel-network version case 10: - switch (bytes[0]) { - case 0x00: - data.LEDcolor = "Dark"; - break; - case 0x01: - data.LEDcolor = "Green"; - data.cubicleOccupyStatus = "Vacant"; - break; - case 0x02: - data.LEDcolor = "Red"; - data.cubicleOccupyStatus = "Occupied"; - break; - case 0x03: - data.LEDcolor = "Blue"; - data.cubicleOccupyStatus = "Maintenance"; - break; - case 0x04: - data.LEDcolor = "Yellow"; - data.cubicleOccupyStatus = "TBD"; - break; - case 0x05: - data.LEDcolor = "Pink"; - data.cubicleOccupyStatus = "TBD"; - break; - case 0x06: - data.LEDcolor = "Cyan"; - data.cubicleOccupyStatus = "TBD"; - break; - case 0x07: - data.LEDcolor = "White"; - data.cubicleOccupyStatus = "TBD"; - break; - case 0x08: - data.LEDcolor = "Red_Blue"; - data.cubicleOccupyStatus = "EMERGENCY"; - break; - case 0x23: - data.LEDcolor = "Red_Blue"; - data.cubicleOccupyStatus = "EMERGENCY"; - break; - case 0x20: - data.LEDcolor = "Red_Flash"; - data.cubicleOccupyStatus = "EMERGENCY"; - break; - default: - data.LEDcolor = "TBD_COLOR"; - data.cubicleOccupyStatus = "TBD_status"; - break; + data.LEDcolor = code2color[bytes[0]]; + data.workmode = code2workmode[bytes[1]]; + data.Sensor1_Door_Contact_Open = bytes[2] === 0 ? "Door Closed" : "Door Open"; + if (bytes[1] == 0x03) { + data.Sensor3_RSS_Motion = (bytes[3] === 1) ? "1:Motion Detected" : "0: Motion less"; } - switch (bytes[1]) { - case 0x0: - data.workmode = "Network_mode"; - break; - case 0x01: - data.workmode = "Wired_Mode"; - break; - case 0x02: - data.workmode = "Hall_element_mode"; - break; - case 0x03: - data.workmode = "MotionDetect_mode"; - break; - case 0x04: - data.workmode = "Dual_mode"; - break; - case 0x05: - data.workmode = "Uni_Mode"; - break; - default: - data.workmode = "Unknown Mode"; - break; - } + return { "Yunhorn_SmarToilets_data": data }; + + break; + case 17: + data.LEDcolor = code2color[bytes[0]]; + data.cubicleOccupyStatus = code2state[bytes[3]]; + data.workmode = code2workmode[bytes[1]]; // select only one below // For NC (Normal Closed states) @@ -187,9 +137,13 @@ function Decode(fPort, data, variables) { // data.Sensor1_Door_Contact_Open = bytes[3]===1?"Door Closed":"Door Open"; if (bytes[1] == 0x02) //Hall_element_mode { - data.Sensor2_SOS_Pushed = bytes[3] === 0 ? "PushDown" : "RelaseUP"; + data.Sensor2_SOS_Pushed = bytes[2] === 0 ? "PushDown" : "RelaseUP"; } else if (bytes[1] > 0x02) { - data.Sensor2_Motion_Detected = bytes[3] === 0 ? "No Motion" : "Motion Detected"; + data.Sensor1_Door_Contact = (bytes[2] === 1) ? "1:Door Open" : "0:Door Closed"; + data.Sensor2_SOS_Button = (bytes[3] === 1) ? "1:SOS Released" : "0: SOS Push Down"; + data.Sensor3_RSS_Motion = (bytes[4] === 1) ? "1:Motion Detected" : "0: Motion less"; + data.OverStay_state = bytes[5]; + data.OverStay_duration = (bytes[6] << 8 | bytes[7]) / 60 + " Min"; } return { "Yunhorn_SmarToilets_data": data }; @@ -238,6 +192,9 @@ function Decode(fPort, data, variables) { data.Battery_Level = bytes[4] + " %"; data.Payload_Size = bytes[5]; data.Presence_State = (bytes[6] == 1) ? "Occupied" : "Vacant"; + data.Motion_state_PIR = (bytes[7] == 1) ? "Motion" : "Motionless"; v + data.Lamp_bar_color_code = bytes[8]; + data.Presence_Distance_cm = bytes[9] * 10 + " cm"; return { "Yunhorn_SmarToilets_data": data }; break; @@ -275,86 +232,72 @@ function Decode(fPort, data, variables) { break; - // Heart-beat for STS-O6 occupancy sensor - case 17: - // STS-O7 Fall detection sensor case 19: + data.header_board_led = bytes[0] & 0x7f; + data.header_mtm1 = bytes[1]; + data.header_mtm2 = bytes[2]; + data.header_fw = bytes[3]; + data.header_battery_level = bytes[4] + " %"; + data.payload_size = bytes[5]; + data.payload_type = bytes[6]; + switch (bytes[6]) // fall/movement/occupancy/sos status + { + case 0x01: + data.fhmos_state_fall = bytes[7] + fallcode2state[bytes[7]]; + data.fhmos_state_human_movement = bytes[8] + movecode2state[bytes[8]]; + data.fhmos_state_occupancy = bytes[9] + occupancycode2state[bytes[9]]; + data.fhmos_state_sosbutton = bytes[10] + soscode2state[bytes[10]]; + + data.lamp_bar_color = bytes[11] + " - LampBar Color: " + code2color[bytes[11]]; + data.sensor1_state = bytes[12] + " - Door: " + ((bytes[12] == 1) ? "Open" : "Closed"); + data.sensor2_state = bytes[13] + " - TOF: " + code2state[bytes[13]];; + data.sensor3_PIR_state = bytes[14] + " - PIR: " + ((bytes[14] == 1) ? "Motion" : "No Motion"); + break; + case 0x02: // fall gesture map + data.fhmos_gesture_head_height_cm = bytes[7]; + data.fhmos_gesture_head_x_y = bytes[8]; + data.fhmos_gesture_map1 = String.fromCharCode(bytes[9]); + data.fhmos_gesture_map2 = String.fromCharCode(bytes[10]); + data.fhmos_gesture_map3 = String.fromCharCode(bytes[11]); + data.fhmos_gesture_map4 = String.fromCharCode(bytes[12]); + data.fhmos_gesture_map5 = String.fromCharCode(bytes[13]); + data.fhmos_gesture_map6 = String.fromCharCode(bytes[14]); + data.fhmos_gesture_map7 = String.fromCharCode(bytes[15]); + data.fhmos_gesture_map8 = String.fromCharCode(bytes[16]); + var my_time_zone = 8 * 60 * 60; // (8*60*60) + data.fhmos_fall_event_utc_time = bytes[17] << 24 | bytes[18] << 16 | bytes[19] << 8 | bytes[20]; + data.fhmos_fall_event_time = data.fhmos_fall_event_utc_time + my_time_zone; + var dev_date = new Date(data.fhmos_fall_event_time * 1000); + data.fhmos_fall_event_time_stamp = dev_date.getHours() + ":" + dev_date.getMinutes(); + data.fhmos_fall_event_date_stamp = dev_date.getDate() + "." + (dev_date.getMonth() + 1) + "." + dev_date.getFullYear(); + + break; + case 0x03: // Background mask off map + data.fhmos_gesture_map1 = String.fromCharCode(bytes[7]); + data.fhmos_gesture_map2 = String.fromCharCode(bytes[8]); + data.fhmos_gesture_map3 = String.fromCharCode(bytes[9]); + data.fhmos_gesture_map4 = String.fromCharCode(bytes[10]); + data.fhmos_gesture_map5 = String.fromCharCode(bytes[11]); + data.fhmos_gesture_map6 = String.fromCharCode(bytes[12]); + data.fhmos_gesture_map7 = String.fromCharCode(bytes[13]); + data.fhmos_gesture_map8 = String.fromCharCode(bytes[14]); + break; + } + return { "Yunhorn_SmarToilets_data": data }; + + break; + + // Heart-beat for STS-O6 occupancy sensor + // case 17: + // STS-O7 Fall detection sensor + case 21: { data.BoardLED = ((bytes[0] & 0x7F) === 0x01) ? "ON" : "OFF"; - switch (bytes[1]) { - case 0x00: - data.LEDcolor = "Dark"; - break; - case 0x01: - data.LEDcolor = "Green"; - data.cubicleOccupyStatus = "Vacant"; - break; - case 0x02: - data.LEDcolor = "Red"; - data.cubicleOccupyStatus = "Occupied"; - break; - case 0x03: - data.LEDcolor = "Blue"; - data.cubicleOccupyStatus = "Maintenance"; - break; - case 0x04: - data.LEDcolor = "Yellow"; - data.cubicleOccupyStatus = "TBD"; - break; - case 0x05: - data.LEDcolor = "Pink"; - data.cubicleOccupyStatus = "TBD"; - break; - case 0x06: - data.LEDcolor = "Cyan"; - data.cubicleOccupyStatus = "TBD"; - break; - case 0x07: - data.LEDcolor = "White"; - data.cubicleOccupyStatus = "TBD"; - break; - case 0x08: - data.LEDcolor = "Red_Blue"; - data.cubicleOccupyStatus = "EMERGENCY"; - break; - case 0x23: - data.LEDcolor = "Red_Blue"; - data.cubicleOccupyStatus = "EMERGENCY"; - break; - case 0x20: - data.LEDcolor = "Red_Flash"; - data.cubicleOccupyStatus = "EMERGENCY"; - break; - default: - data.LEDcolor = "TBD_COLOR"; - data.cubicleOccupyStatus = "TBD_status"; - break; - } + data.LEDcolor = code2color[bytes[1]]; + data.cubicleOccupyStatus = code2state[bytes[1]]; + data.workmode = code2state[bytes[2]]; - switch (bytes[2]) { - case 0x0: - data.workmode = "Network_mode"; - break; - case 0x01: - data.workmode = "Wired_Mode"; - break; - case 0x02: - data.workmode = "Hall_element_mode"; - break; - case 0x03: - data.workmode = "MotionDetect_mode"; - break; - case 0x04: - data.workmode = "Dual_mode"; - break; - case 0x05: - data.workmode = "Uni_Mode"; - break; - default: - data.workmode = "Unknown Mode"; - break; - } // select only one below // For NC(Normal Closed states data.Sensor1_Door_Contact_Open = bytes[3] === 0 ? "Door Closed" : "Door Open"; @@ -376,32 +319,8 @@ function Decode(fPort, data, variables) { data.Sensor5_ALARM_RESET = (bytes[7] === 0) ? "Down RESET" : "NO Reset"; data.Distance_in_mm = (bytes[8] << 8 | bytes[9]); data.MotionLevel = (bytes[10] << 8 | bytes[11]); - data.Unconcious_State = (bytes[12] == 0) ? "False" : "True"; - - switch (bytes[13]) { - case 0x0: - data.Fall_Down_Detected_State = "Presence_Normal"; - break; - case 0x01: - data.Fall_Down_Detected_State = "Presence_Fall_Down"; - break; - case 0x02: - data.Fall_Down_Detected_State = "Presence_Rising_Up"; - break; - case 0x03: - data.Fall_Down_Detected_State = "Presence_LayDown"; - break; - case 0x04: - data.Fall_Down_Detected_State = "Presence_Unconcious"; - break; - case 0x05: - data.Fall_Down_Detected_State = "Presence_Stay_Still"; - break; - default: - data.Fall_Down_Detected_State = "Presence_Normal"; - break; - } + data.Fall_Down_Detected_State = code2fallstate[bytes[13]]; data.OverStay_Detected_State = (bytes[14] == 0x0) ? "False" : "True"; data.OverStay_Duration_in_Seconds = (bytes[15] << 8 | bytes[16]); data.No_Movement_Duration_in_Seconds = (bytes[17] << 8 | bytes[18]); @@ -466,8 +385,8 @@ function Decode(fPort, data, variables) { data.HW_Code = bytes[3]; data.Battery_Level = bytes[4] + " %"; data.Payload_Size = bytes[5]; - data.Weight_g = (bytes[6] << 8 | bytes[7]); - data.Tare_g = (bytes[8] << 8 | bytes[9]); + data.Weight_g = (bytes[6] << 24 | bytes[7]) << 16 | bytes[8] << 8 + bytes[9] + bytes[10]; + data.Weight_g = (bytes[6] << 24 | bytes[7]) << bytes[8] + bytes[9]; return { "Yunhorn_SmarToilets_data": data }; break; @@ -567,8 +486,19 @@ function Decode(fPort, data, variables) { break; - // STS-E2 PTAQ, ODOR LEVEL Sensor + // STS-E2 PTAQ, ODOR LEVEL Sensor 9-in-1 case 101: + data.Temperature = ((bytes[0] & 0x01) ? "+" : "-") + (bytes[1] + (bytes[2] / 100)) + " C"; + data.Humidity = (bytes[3] + (bytes[4] / 100)) + " %RH"; + data.NH3 = (bytes[5] + (bytes[6] / 100)) + " ppm"; + data.H2S = (bytes[7] + bytes[8] / 100) + " ppm"; + data.CH2O = (bytes[9] + (bytes[10] / 100)) + " ug/m3"; + data.CO2 = (bytes[11] << 8 | bytes[12]) + " ppm"; + data.TVOC = (bytes[13] << 8 | bytes[14]) + " ppm"; + data.PM2_5 = ((bytes[15] << 8) | bytes[16]) + " ug/m3"; + data.PM10 = ((bytes[17] << 8) | bytes[18]) + " ug/m3"; + data.O3 = ((bytes[19] << 8) | bytes[20]) + " ppb"; + return { "Yunhorn_SmarToilets_data": data }; break; @@ -630,10 +560,30 @@ function Decode(fPort, data, variables) { return { "Yunhorn_SmarToilets_data": data }; break; + // TIME SYNC PORT + case 202: + data.TimeSyncReq = "True"; + return { "Yunhorn_SmarToilets_data": data }; + break; // respond port case 1: switch (bytes[0]) { + //AC CODE RESPONSE + case 0x41: + if ((bytes[1] == 0x43) && (data.length == 22)) + data.RFAC_RESULT = "SUCCESS"; + break; + + // RSS background center distance and motion noise 'B' + case 0x42: + if ((bytes[6] == 0x04)) { + data.background_result = "Motion Noise Measured"; + data.background_distance_center = (bytes[7] << 8 | bytes[8]) + " mm"; + data.background_motion_noise = (bytes[9] << 8 | bytes[10]) + " score"; + + } + break; // NVM config 'C' case 0x43: // report current nvm config @@ -666,8 +616,8 @@ function Decode(fPort, data, variables) { data.rss_output_time_const = bytes[27] * 0.1; data.rss_downsampling_factor = bytes[28]; data.rss_power_saving_mode_active = bytes[29]; - data.rss_reserve02 = bytes[30]; - data.rss_reserve03 = bytes[31]; + data.rss_cfg_update_flag = bytes[30]; + data.rss_bg_noise_score = bytes[31] * 10; data.rss_reserve04 = bytes[32]; data.reserve2 = bytes[33]; data.reserve3 = bytes[34]; @@ -702,7 +652,21 @@ function Decode(fPort, data, variables) { data.Distance_unit = "mm"; break; + // G Fall down Gesture bitmap REPORT + case 0x47: + data.head_level_cm = bytes[7]; + data.head_coordination = "X: " + bytes[8] / 8 + " Y:" + bytes[8] % 8; + data.matrix0 = bytes2matrix(11, bytes); + data.matrix1 = bytes2matrix(12, bytes); + data.matrix2 = bytes2matrix(13, bytes); + data.matrix3 = bytes2matrix(14, bytes); + data.matrix4 = bytes2matrix(15, bytes); + data.matrix5 = bytes2matrix(16, bytes); + data.matrix6 = bytes2matrix(17, bytes); + data.matrix7 = bytes2matrix(18, bytes); + return + break; // LoRa Class 'L' case 0x4c: // LoRaWAN Class A/B/C @@ -742,31 +706,15 @@ function Decode(fPort, data, variables) { case 4: if ((data.length === 4) && (bytes[1] === 0x31) && (bytes[2] === 0x31)) { data.Work_Mode_Switch = "OK"; - switch (bytes[3] - 0x30) { - case 0x0: - data.workmode = "Network_mode"; - break; - case 0x01: - data.workmode = "Wired_Mode"; - break; - case 0x02: - data.workmode = "Hall_element_mode"; - break; - case 0x03: - data.workmode = "MotionDetect_mode"; - break; - case 0x04: - data.workmode = "Dual_mode"; - break; - case 0x05: - data.workmode = "Uni_Mode"; - break; - default: - data.workmode = "Unknown Mode"; - break; - } + data.workmode = code2workmode[bytes[3] - 0x30]; } + break; + case 6: + data.P_cmd = "Change Lamp Bar color config"; + data.workmode = code2workmode[bytes[3] - 0x30]; + data.color_occupy = code2color[bytes[4] - 0x30]; + data.color_vacant = code2color[bytes[5] - 0x30]; break; case 7: if (bytes[3] === 0x46) { @@ -842,125 +790,69 @@ function Decode(fPort, data, variables) { // Self-Test function 'S' case 0x53: - // SELF TEST FUNCTION - data.mtm_code1 = bytes[1]; - data.mtm_code2 = bytes[2]; - data.sts_verion = bytes[3]; - data.sts_hw_ver = bytes[4]; - data.battery_level = bytes[5]; - if ((bytes[6] === 0x0C)) { // report sensor install height and bitmap - data.sts_sensor_chip_model_type_ID = (bytes[7] << 8 | bytes[8]); - if ((bytes[7] === 0xF0) && (bytes[8] === 0x0C)) { - data.sts_sensor_chip_model_type = "VL53L8X"; - } - else if ((bytes[7] === 0xEA) & (bytes[8] === 0xCC)) { - data.sts_sensor_chip_model_type = "VL53L1X"; - } - else if ((bytes[7] === 0xEE) & (bytes[8] === 0xAA)) { - data.sts_sensor_chip_model_type = "VL53L0X"; + if ((bytes[1] == 0x54) && (bytes[2] == 0x53)) { + data.Yunhorn_PRD = "True"; + data.PRD_String = String.fromCharCode(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6]); + } else { + + // SELF TEST FUNCTION + data.mtm_code1 = bytes[1]; + data.mtm_code2 = bytes[2]; + data.sts_verion = bytes[3]; + data.sts_hw_ver = bytes[4]; + data.battery_level = bytes[5]; + if ((bytes[6] === 0x0C) || (bytes[6] === 0x04)) { // report sensor install height and bitmap + data.sts_sensor_chip_model_type_ID = (bytes[7] << 8 | bytes[8]); + if ((bytes[7] === 0xF0) && (bytes[8] === 0x0C)) { + data.sts_sensor_chip_model_type = "VL53L8X"; + } + else if ((bytes[7] === 0xEA) & (bytes[8] === 0xCC)) { + data.sts_sensor_chip_model_type = "VL53L1X"; + } + else if ((bytes[7] === 0xEE) & (bytes[8] === 0xAA)) { + data.sts_sensor_chip_model_type = "VL53L0X"; + } + + data.sts_sensor_install_height = (bytes[9] << 8 | bytes[10]); + data.sts_sensor_install_height_unit = "mm"; + //data.maskoff_bitmap= String.fromCharCode(bytes[11])+String.fromCharCode(bytes[12])+String.fromCharCode(bytes[13])+String.fromCharCode(bytes[14])+String.fromCharCode(bytes[15])+String.fromCharCode(bytes[16])+String.fromCharCode(bytes[17])+String.fromCharCode(bytes[18]); + if (bytes[6] === 0x0c) { + data.matrix0 = bytes2matrix(11, bytes); + data.matrix1 = bytes2matrix(12, bytes); + data.matrix2 = bytes2matrix(13, bytes); + data.matrix3 = bytes2matrix(14, bytes); + data.matrix4 = bytes2matrix(15, bytes); + data.matrix5 = bytes2matrix(16, bytes); + data.matrix6 = bytes2matrix(17, bytes); + data.matrix7 = bytes2matrix(18, bytes); + } + } - data.sts_sensor_install_height = (bytes[9] << 8 | bytes[10]); - data.sts_sensor_install_height_unit = "mm"; - //data.maskoff_bitmap= String.fromCharCode(bytes[11])+String.fromCharCode(bytes[12])+String.fromCharCode(bytes[13])+String.fromCharCode(bytes[14])+String.fromCharCode(bytes[15])+String.fromCharCode(bytes[16])+String.fromCharCode(bytes[17])+String.fromCharCode(bytes[18]); - - var mmm = bytes[11]; - var con = 0x30; - var matrix0 = " [ "; - for (i = 0; i < 8; i++) { - con += ((mmm >> i) & 0x01); - matrix0 += (String.fromCharCode(con) + "__"); - con = 0x30; + else if ((bytes[6] === 0x58)) { + data.sts_Test_Result = "### Motion Sensor Not Detected ###"; + } else if ((bytes[6] === 0x78)) { + data.sts_Test_Result = "### Motion Sensor Detected, Yet Not Stable ###"; + } else if ((bytes[6] === 0x12)) //result length=18, 12 rss bytes, 2 distance bytes, 2 range bytes, 2 motion noise + { + data.sts_Test_Result = "Motion Sensor Test Result:"; + data.sts_test_result_length = bytes[6]; + data.sts_rss_sub_code1 = bytes[7]; + data.sts_rss_sub_code2 = bytes[8]; + data.sts_rss_sub_code3 = bytes[9]; + data.sts_rss_sub_code4 = bytes[10]; + data.sts_rss_sub_code5 = bytes[11]; + data.sts_rss_sub_code6 = bytes[12]; + data.sts_rss_sub_code7 = bytes[13]; + data.sts_rss_sub_code8 = bytes[14]; + data.sts_rss_sub_code9 = bytes[15]; + data.sts_rss_sub_code10 = bytes[16]; + data.sts_rss_sub_code11 = bytes[17]; + data.sts_rss_sub_code12 = bytes[18]; + data.sts_sensor_install_height = (bytes[19] << 8 | bytes[20]) + " mm"; + data.sts_rss_background_range_center = (bytes[21] << 8 | bytes[22]) + " mm"; + data.sts_rss_background_motion_noise = (bytes[23] << 8 | bytes[24]) + " score"; } - data.matrix01 = matrix0; - mmm = bytes[12]; - var con = 0x30; - var matrix0 = " [ "; - for (i = 0; i < 8; i++) { - con += ((mmm >> i) & 0x01); - matrix0 += (String.fromCharCode(con) + "__"); - con = 0x30; - } - data.matrix02 = matrix0; - - mmm = bytes[13]; - var con = 0x30; - var matrix0 = " [ "; - for (i = 0; i < 8; i++) { - con += ((mmm >> i) & 0x01); - matrix0 += (String.fromCharCode(con) + "__"); - con = 0x30; - } - data.matrix03 = matrix0; - mmm = bytes[14]; - var con = 0x30; - var matrix0 = " [ "; - for (i = 0; i < 8; i++) { - con += ((mmm >> i) & 0x01); - matrix0 += (String.fromCharCode(con) + "__"); - con = 0x30; - } - data.matrix04 = matrix0; - - mmm = bytes[15]; - var con = 0x30; - var matrix0 = " [ "; - for (i = 0; i < 8; i++) { - con += ((mmm >> i) & 0x01); - matrix0 += (String.fromCharCode(con) + "__"); - con = 0x30; - } - data.matrix05 = matrix0; - - mmm = bytes[16]; - var con = 0x30; - var matrix0 = " [ "; - for (i = 0; i < 8; i++) { - con += ((mmm >> i) & 0x01); - matrix0 += (String.fromCharCode(con) + "__"); - con = 0x30; - } - data.matrix06 = matrix0; - - mmm = bytes[17]; - var con = 0x30; - var matrix0 = " [ "; - for (i = 0; i < 8; i++) { - con += ((mmm >> i) & 0x01); - matrix0 += (String.fromCharCode(con) + "__"); - con = 0x30; - } - data.matrix07 = matrix0; - - mmm = bytes[18]; - var con = 0x30; - var matrix0 = " [ "; - for (i = 0; i < 8; i++) { - con += ((mmm >> i) & 0x01); - matrix0 += (String.fromCharCode(con) + "__"); - con = 0x30; - } - data.matrix08 = matrix0; - - } - - else if ((bytes[6] === 0x58)) { - data.sts_Test_Result = "### Motion Sensor Not Detected ###"; - } else if ((bytes[6] === 0x0E)) //result length, 10 rss bytes, 4 distance bytes - { - data.sts_Test_Result = "Motion Sensor Test Result:"; - data.sts_test_result_length = bytes[6]; - data.sts_rss_sub_code1 = bytes[7]; - data.sts_rss_sub_code2 = bytes[8]; - data.sts_rss_sub_code3 = bytes[9]; - data.sts_rss_sub_code4 = bytes[10]; - data.sts_rss_sub_code5 = bytes[11]; - data.sts_rss_sub_code6 = bytes[12]; - data.sts_rss_sub_code7 = bytes[13]; - data.sts_rss_sub_code8 = bytes[14]; - data.sts_rss_sub_code9 = bytes[15]; - data.sts_rss_sub_code10 = bytes[16]; - data.sts_sensor_install_height = String.fromCharCode(bytes[17]) + String.fromCharCode(bytes[18]) + String.fromCharCode(bytes[19]) + String.fromCharCode(bytes[20]) + " mm"; } break; @@ -1018,8 +910,17 @@ function Decode(fPort, data, variables) { data.Heart_Beat_interval = (bytes[2] - 0x30) * 10 + (bytes[3] - 0x30); data.Heart_Beat_interval_unit = String.fromCharCode(bytes[4]); // if sts_mtm1 == O6/O7 ....TODO XXXX - // data.Wakeup_sampling_interval = (bytes[2]-0x30)*10 + (bytes[3]-0x30); - // data.Unit = String.fromCharCode(bytes[4]); + if (bytes[4] == 0x4C) { + data.Wakeup_sampling_interval = 100 * ((bytes[2] - 0x30) * 10 + (bytes[3] - 0x30)); + data.Unit = "ms"; + } + break; + // YWABB + case 0x57: // W + data.RSS_Sliding_Win_CFG = "true"; + data.RSS_Slid_Win_Threshold = (bytes[2] - 0x30); + data.RSS_Slid_Win_Length = (bytes[3] - 0x30) * 10 + (bytes[4] - 0x30); + break; } @@ -1045,29 +946,8 @@ function Decode(fPort, data, variables) { } else { if ((bytes[0] === 0x50) && (bytes[1] === 0x31) && (bytes[2] === 0x31)) { data.Work_Mode_Switch = "OK"; - switch (bytes[3] - 0x30) { - case 0x0: - data.workmode = "Network_mode"; - break; - case 0x01: - data.workmode = "Wired_Mode"; - break; - case 0x02: - data.workmode = "Hall_element_mode"; - break; - case 0x03: - data.workmode = "MotionDetect_mode"; - break; - case 0x04: - data.workmode = "Dual_mode"; - break; - case 0x05: - data.workmode = "Uni_Mode"; - break; - default: - data.workmode = "Unknown Mode"; - break; - } + data.workmode = code2workmode[bytes[3] - 0x30]; + } else if ((bytes[0] === 0x59) && (bytes[1] === 0x44)) //Duration interval { data.Uplink_interval = (bytes[2] - 0x30) * 10 + (bytes[3] - 0x30); @@ -1123,8 +1003,8 @@ function Decode(fPort, data, variables) { data.rss_output_time_const = bytes[27] * 0.1; data.rss_downsampling_factor = bytes[28]; data.rss_power_saving_mode_active = bytes[29]; - data.rss_reserve02 = bytes[30]; - data.rss_reserve03 = bytes[31]; + data.rss_cfg_update_flag = bytes[30]; + data.rss_bg_motion_noise = bytes[31] * 10; data.rss_reserve04 = bytes[32]; data.reserve2 = bytes[33]; data.reserve3 = bytes[34]; @@ -1154,6 +1034,19 @@ function Decode(fPort, data, variables) { } +function bytes2matrix(i, bytes) { + var mmm = bytes[i]; + var con = 0x30; + var matrix0 = " [ "; + for (cc = 0; cc < 8; cc++) { + con += ((mmm >> cc) & 0x01); + matrix0 += (String.fromCharCode(con) + "__"); + con = 0x30; + } + return matrix0; +} + + // // Yunhorn SmarToilets Sensor Decoder //