diff --git a/AS923_HK_DECODER.js b/AS923_HK_DECODER.js index b194fbf..ced6d05 100644 --- a/AS923_HK_DECODER.js +++ b/AS923_HK_DECODER.js @@ -90,12 +90,19 @@ function Decode(fPort, data, variables) { data.Sensor2_Motion_Detected = bytes[4] === 0 ? "No Motion" : "Motion Detected"; data.Sensor3_Emergency_Button = bytes[5] === 0 ? "Alarm Push Down" : "No Alarm, Released"; - if (bytes.length > 6) { - data.Sensor4 = bytes[6] === 0 ? "No" : "Yes"; + data.length = bytes.length + if (data.length === 9) { + data.Over_stay_state = (bytes[6] === 0) ? "False" : "True"; + data.Over_Stay_duration_in_Seconds = (bytes[7] << 8 | bytes[8]); + + return { "Yunhorn_SmarToilets_data": data }; + } + else if (data.length > 9) { + data.Sensor4 = (bytes[6] === 0) ? "No" : "Yes"; data.Distance_in_mm = (bytes[7] << 8 | bytes[8]); data.MotionLevel = (bytes[9] << 8 | bytes[10]); - data.Unconcious_State = bytes[11]; + data.Unconcious_State = (bytes[11] == 0) ? "False" : "True"; switch (bytes[12]) { case 0x0: data.Fall_Down_Detected_State = "Presence_Normal"; @@ -116,7 +123,7 @@ function Decode(fPort, data, variables) { data.Fall_Down_Detected_State = "Presence_Stay_Still"; break; } - data.OverStay_Detected_State = (bytes[13] == 0x0) ? "No" : "Yes"; + data.OverStay_Detected_State = (bytes[13] == 0x0) ? "False" : "True"; data.OverStay_Duration_in_Seconds = (bytes[14] << 8 | bytes[15]); data.No_Movement_Duration_in_Seconds = (bytes[16] << 8 | bytes[17]); data.Unconcious_Duration_in_Seconds = (bytes[16] << 8 | bytes[17]); diff --git a/Core/Src/yunhorn_sts_process.c b/Core/Src/yunhorn_sts_process.c index 0c618b6..39a1eba 100644 --- a/Core/Src/yunhorn_sts_process.c +++ b/Core/Src/yunhorn_sts_process.c @@ -561,7 +561,11 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *senso { APP_LOG(TS_OFF, VLEVEL_M, "\r\n......FALL RISING DETECTION RESULT: %25s \r\n",(char*)sts_presence_fall_detection_message[sts_fall_rising_detected_result] ); sensor_data->fall_speed = (uint8_t)sts_fall_rising_pattern_factor1; - sensor_data->fall_gravity = (uint8_t)sts_roc_acc_standard_variance; + sensor_data->fall_gravity = (uint8_t)sts_roc_acc_standard_variance; + } else { + sensor_data->fall_speed = 0; + sensor_data->fall_gravity = 0; + } // For occupancy over time process diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index adc09a9..6e93568 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -939,6 +939,12 @@ static void SendTxData(void) AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor2_on_off)&0xff; //04 Sensor head #2 status AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor3_on_off)&0xff; //05 Sensor head #3 status + AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_state)&0xff; //06 occupancy over time or not + AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_duration>>8)&0xff; //07 occupancy over stay duration MSB + AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_duration)&0xff; //08 occupancy over stay duration LSB + + + } else if (sts_work_mode == STS_UNI_MODE) { AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor1_on_off)&0xff; //03 Sensor head #1 status @@ -959,6 +965,10 @@ static void SendTxData(void) AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_duration)&0xff; //15 occupancy over stay duration LSB AppData.Buffer[i++] = (uint8_t)(sensorData.no_movement_duration>>8)&0xff; //16 occupancy over stay duration LSB AppData.Buffer[i++] = (uint8_t)(sensorData.no_movement_duration)&0xff; //17 occupancy over stay duration LSB + + AppData.Buffer[i++] = (uint8_t)(sensorData.fall_speed)&0xff; //18 fall detected speed + AppData.Buffer[i++] = (uint8_t)(sensorData.fall_gravity)&0xff; //19 fall detected gravity + } uint8_t ich= (sts_lamp_bar_color>>4 & 0x0f); uint8_t icl= (sts_lamp_bar_color & 0x0f); @@ -1145,6 +1155,7 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) sts_o7_sensorData.event_sensor1_duration = current_time.Seconds - sts_o7_sensorData.event_sensor1_start_time; } else { sts_o7_sensorData.event_sensor1_duration = 0; + sts_o7_sensorData.over_stay_state = 0; } //if (sts_o7_sensorData.event_sensor1_duration > sts_occupancy_overtime_threshold_in_10min*600) if (sts_o7_sensorData.event_sensor1_duration > sts_occupancy_overtime_threshold_in_10min*60) //for debug @@ -1162,6 +1173,8 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) sts_o7_sensorData.event_sensor2_duration = current_time.Seconds - sts_o7_sensorData.event_sensor2_start_time; } else { sts_o7_sensorData.event_sensor2_duration =0; + sts_o7_sensorData.over_stay_state = 0; + } //if (sts_o7_sensorData.event_sensor2_duration > sts_occupancy_overtime_threshold_in_10min*600) if (sts_o7_sensorData.event_sensor2_duration > sts_occupancy_overtime_threshold_in_10min*60) //for debug @@ -1179,6 +1192,7 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) sts_o7_sensorData.event_sensor3_motion_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_motion_start_time; } else { sts_o7_sensorData.event_sensor3_motion_duration =0; + sts_o7_sensorData.occupancy_over_stay_state = 0; } //if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold_in_10min*600) if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold_in_10min) //for debug @@ -1208,7 +1222,7 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) if (sts_o7_sensorData.event_sensor3_fall_duration > 10*sts_cfg_nvm.fall_confirm_threshold_in_10sec) { //sts_o7_sensorData.occupancy_over_stay_state = 1; - sts_o7_sensorData.fall_state = 1; + sts_o7_sensorData.fall_state = sts_fall_rising_detected_result; sts_o7_sensorData.fall_laydown_duration =sts_o7_sensorData.event_sensor3_fall_duration; } @@ -1221,6 +1235,7 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) case STS_PRESENCE_UNCONSCIOUS: case STS_PRESENCE_STAYSTILL: case STS_PRESENCE_NO_MOVEMENT: + sts_o7_sensorData.fall_state = sts_fall_rising_detected_result; sts_o7_sensorData.event_sensor3_no_movement_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_no_movement_start_time; sts_o7_sensorData.event_sensor3_unconcious_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_unconcious_start_time; break;