diff --git a/hk_as923_decoder.js b/hk_as923_decoder.js index e72dc78..50c4ced 100644 --- a/hk_as923_decoder.js +++ b/hk_as923_decoder.js @@ -4,7 +4,7 @@ // - 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 R20250519R01 +// Yunhorn SmarToilets Sensor R20250521R02 // function Decode(fPort, data, variables) { @@ -18,6 +18,7 @@ function Decode(fPort, data, variables) { 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" }; + var l8code2cmd = { "0": "L8R", "1": "Head Height Threshold", "2": "Potential fall duration threshold", "3": "Confirmed fall duration threshold", "4": "Motionless short threshold", "5": "Motionless long threshold", "6": "Overstay Occupy", "7": "Gesture mask off height", "8": "Fall body Min height", "9": "Upload bitmap gesture" }; switch (fPort) { // RESPOND PORT --- bottom of swith fport @@ -256,14 +257,14 @@ function Decode(fPort, data, variables) { 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]); + data.fhmos_gesture_map1 = bytes2matrix(9, bytes); + data.fhmos_gesture_map2 = bytes2matrix(10, bytes); + data.fhmos_gesture_map3 = bytes2matrix(11, bytes); + data.fhmos_gesture_map4 = bytes2matrix(12, bytes); + data.fhmos_gesture_map5 = bytes2matrix(13, bytes); + data.fhmos_gesture_map6 = bytes2matrix(14, bytes); + data.fhmos_gesture_map7 = bytes2matrix(15, bytes); + data.fhmos_gesture_map8 = bytes2matrix(16, bytes); 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; @@ -273,14 +274,14 @@ function Decode(fPort, data, variables) { 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]); + data.fhmos_gesture_map1 = bytes2matrix(7, bytes);; + data.fhmos_gesture_map2 = bytes2matrix(8, bytes); + data.fhmos_gesture_map3 = bytes2matrix(9, bytes); + data.fhmos_gesture_map4 = bytes2matrix(10, bytes); + data.fhmos_gesture_map5 = bytes2matrix(11, bytes); + data.fhmos_gesture_map6 = bytes2matrix(12, bytes); + data.fhmos_gesture_map7 = bytes2matrix(13, bytes); + data.fhmos_gesture_map8 = bytes2matrix(14, bytes); break; } return { "Yunhorn_SmarToilets_data": data }; @@ -964,11 +965,34 @@ function Decode(fPort, data, variables) { } break; + case 8: + if ((bytes[0] == 'P') && (bytes[1] == '1') && (bytes[2] == '1')) + { + data.L8_CMD = l8code2cmd[bytes[3]]; + if ((bytes[3] == '9')) { + if (bytes[7] == 2) { + data.L8_CMD_Value = "Gesture bitmap "; + } else { + data.L8_CMD_Value = "Backgrond bitmap "; + } + } + else if ((bytes[3] == 1) || (bytes[3] == 7) || (bytes[3] == 8)) { + data.L8_CMD_Unit = " cm"; + } + else { + data.L8_CMD_Unit = " seconds"; + } + data.L8_CMD_Value = (bytes[4] * 100 + bytes[5] * 10 + bytes[6]) * 15; + } + break; + + // YUNHORN PRD MARK case 10: - if ((bytes[0] == 0x59) && (bytes[9] == 0x38)) + if ((bytes[0] == 0x59) && (bytes[9] == 0x38)) { data.Yunhorn_PRD = "True"; - data.PRD_String = String.fromCharCode(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6]); + data.PRD_String = String.fromCharCode(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6]); + } break; // YUNHORN NVM CONFIG LENGTH