From 6cf3d200129f6595417c099eaac1842a4dbf3a31 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Thu, 13 Jun 2024 22:46:54 +0800 Subject: [PATCH] refined motionless, unconscious, overstay, fall detection cfg --- Core/Inc/yunhorn_sts_sensors.h | 55 +++++----- Core/Src/yunhorn_sts_presence_rss.c | 8 +- Core/Src/yunhorn_sts_process.c | 24 ++--- LoRaWAN/App/lora_app.c | 155 +++++++++++++++++----------- 4 files changed, 143 insertions(+), 99 deletions(-) diff --git a/Core/Inc/yunhorn_sts_sensors.h b/Core/Inc/yunhorn_sts_sensors.h index 2bd07cf..1e92e82 100644 --- a/Core/Inc/yunhorn_sts_sensors.h +++ b/Core/Inc/yunhorn_sts_sensors.h @@ -41,7 +41,7 @@ extern "C" { #if defined(STS_O7)||defined(STS_O6) enum cfg_cmd_order{ - CFG_CMD1=0, //'Y' + CFG_CMD1=0, //'Y' ’P‘ CFG_CMD2, //'D' 'Z' 'V' 'O' 'F' 'H' 'M' CFG_CMD3, // # Z {H, S, C} M {0,1,2,3,4] CFG_CMD4, // # @@ -171,9 +171,9 @@ typedef struct STS_OO_SensorStatusDataTypeDef uint8_t rss_presence_zone[10]; uint8_t rss_presence_zone_count[10]; uint16_t rss_presence_score; // in 1000*score - uint8_t unconcious_state; - uint16_t unconcious_threshold; - uint32_t unconcious_duration; + uint8_t unconscious_state; + uint16_t unconscious_threshold; + uint32_t unconscious_duration; uint8_t fall_state; // FALL DETECION NONE, FALL DOWN, RISE UP, LAYDOWN_STILL uint8_t fall_speed; // speed of fall down measure uint8_t fall_gravity; // gravity of fall down measure @@ -207,7 +207,7 @@ enum sts_presence_fall_detection_type { STS_PRESENCE_FALL, STS_PRESENCE_RISING, STS_PRESENCE_LAYDOWN, - STS_PRESENCE_UNCONCIOUS, + STS_PRESENCE_UNCONSCIOUS, STS_PRESENCE_STAYSTILL }; @@ -566,17 +566,20 @@ enum nvm_order { NVM_RESERVE02, //32 NVM_RESERVE03, //33 NVM_RESERVE04, //34 - NVM_RESERVE05, //35 + NVM_ALARM_PARAMETER05, //35 NVM_ALARM_MUTE_RESET_TIMER, //36 - NVM_FALL_CONFIRM_THRESHOLD, //37 - NVM_MOTIONLESS_THRESHOLD, //38 - NVM_LAMP_BAR_FLASHING_COLOR, //39 - NVM_FALL_DETECTION_ACC_THRESHOLD, //40 - NVM_FALL_DETECTION_DEPTH_THRESHOLD, //41 - NVM_UNCONCIOUS_THRESHOLD, //42 - NVM_OCCUPANCY_OVERTIME_THRESHOLD, //43 - NVM_AC_CODE_START=44 //STORED, NO UPLOAD - //63, 20 bytes for AC code + NVM_ALARM_LAMP_BAR_FLASHING_COLOR, //37 + NVM_OCCUPANCY_OVERTIME_THRESHOLD, //38 + + NVM_MOTIONLESS_DURATION_THRESHOLD, //39 + NVM_UNCONSCIOUS_LEVEL_THRESHOLD, //40 + + NVM_FALL_DETECTION_ACC_THRESHOLD, //41 + NVM_FALL_DETECTION_DEPTH_THRESHOLD, //42 + NVM_FALL_CONFIRM_THRESHOLD, //43 + + NVM_AC_CODE_START=44 //STORED, NO UPLOAD + //63, 20 bytes for AC code }; typedef struct sts_cfg_nvm { @@ -597,17 +600,19 @@ typedef struct sts_cfg_nvm { uint8_t reserve02; uint8_t reserve03; uint8_t reserve04; - uint8_t reserve05; - uint8_t alarm_mute_or_reset_expire_timer_in_Sec;//60(0x3C) sec alarm_mute_or_reset_expire_timer_in_sec - uint8_t falldown_confirm_threshold_in_Sec; //0-60(0x3C) Sec, or 30(0x1E) sec default falldown_confirm_threshold_in_sec - uint8_t motionless_duration_threshold_in_Sec; //120(0x78) Sec (2 min.) motionless_duration_threshold_in_Sec + uint8_t alarm_parameter05; + uint8_t alarm_mute_reset_timer_in_10sec; //60(0x3C) sec alarm_mute_or_reset_expire_timer_in_sec + uint8_t alarm_lamp_bar_flashing_color; //Lamp Bar Flashing color define, 0x20, 2==STS_RED, 0 = STS_DARK, 0x23, 2=STS_RED, 3=STS_BLUE + uint8_t occupancy_overtime_threshold_in_10min; // 0 - 9: 0:disable, 1-9 occupy over time threshold * 10 min - uint8_t lamp_bar_flashing_color; //Lamp Bar Flashing color define, 0x20, 2==STS_RED, 0 = STS_DARK, 0x23, 2=STS_RED, 3=STS_BLUE - uint8_t fall_detection_acc_threshold; // 0 - 9: 0:disable: 1-9 accelaration mg/s2 - uint8_t fall_detection_depth_threshold; // 0 - 9: 0:disable: 1-9 fall down depth * 10 cm - uint8_t unconcious_threshold; // 0 - 9 motion level *10 - uint8_t occupancy_overtime_threshold; // 0 - 9: 0:disable, 1-9 occupy over time threshold * 10 min - uint8_t ac[YUNHORN_STS_AC_CODE_SIZE]; // authorization code, 20 bytes MCU UUID coded + uint8_t motionless_duration_threshold_in_min; // 10(0x0A) min (2 min.) motionless_duration_threshold_in_min + uint8_t unconscious_or_motionless_level_threshold; // 0 - 9 motion level *128 + + uint8_t fall_detection_acc_threshold; // 0 - 9: 0:disable: 1-9 accelaration mg/s2 + uint8_t fall_detection_depth_threshold; // 0 - 9: 0:disable: 1-9 fall down depth * 10 cm + uint8_t fall_confirm_threshold_in_10sec; // 0-60(0x3C) Sec, or 3*10(0x03) sec default falldown_confirm_threshold_in_10sec + + uint8_t ac[YUNHORN_STS_AC_CODE_SIZE]; // authorization code, 20 bytes MCU UUID coded } sts_cfg_nvm_t; /** diff --git a/Core/Src/yunhorn_sts_presence_rss.c b/Core/Src/yunhorn_sts_presence_rss.c index 034bad2..02dd631 100644 --- a/Core/Src/yunhorn_sts_presence_rss.c +++ b/Core/Src/yunhorn_sts_presence_rss.c @@ -79,15 +79,15 @@ #define DEFAULT_MOTION_DATASET_LEN (128) //MOTION DATASET/PATTERN COLLECTION #define DEFAULT_MOTION_FEATURE_LEN (10) //MOTION FEATURE IDENDIFIED -#define DEFAULT_UNCONCIOUS_THRESHOLD (250) +#define DEFAULT_UNCONSCIOUS_THRESHOLD (250) #ifndef MIN # define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif extern volatile uint8_t sts_fall_detection_acc_threshold, sts_fall_detection_depth_threshold, sts_occupancy_overtime_threshold; -volatile uint8_t sts_unconcious_state=0; -volatile uint16_t sts_unconcious_threshold=1280, sts_unconcious_duration=0; +volatile uint8_t sts_unconscious_state=0; +volatile uint16_t sts_unconscious_threshold=1280, sts_unconscious_duration=0; extern volatile uint8_t sts_rss_result, sts_rss_config_updated_flag, last_sts_rss_result; extern volatile float sts_distance_rss_distance; volatile float sts_presence_rss_distance, sts_presence_rss_score; @@ -649,7 +649,7 @@ void STS_YunhornCheckStandardDeviation(void) #endif // *********** detection suggestion - if (standard_variance_presence_score <= MIN(DEFAULT_UNCONCIOUS_THRESHOLD, sts_unconcious_threshold)) { + if (standard_variance_presence_score <= MIN(DEFAULT_UNCONSCIOUS_THRESHOLD, sts_unconscious_threshold)) { sts_fall_rising_detected_result = STS_PRESENCE_STAYSTILL; } diff --git a/Core/Src/yunhorn_sts_process.c b/Core/Src/yunhorn_sts_process.c index 6186e72..fd0f106 100644 --- a/Core/Src/yunhorn_sts_process.c +++ b/Core/Src/yunhorn_sts_process.c @@ -60,11 +60,11 @@ volatile uint32_t event_door_lock_start_time=0,event_door_lock_stop_time=0; extern volatile uint8_t sts_occupancy_overtime_state; extern volatile STS_OO_RSS_SensorTuneDataTypeDef sts_presence_rss_config; extern volatile sts_cfg_nvm_t sts_cfg_nvm; -extern volatile uint8_t sts_fall_detection_acc_threshold, sts_fall_detection_depth_threshold, sts_occupancy_overtime_threshold; +extern volatile uint8_t sts_fall_detection_acc_threshold, sts_fall_detection_depth_threshold, sts_occupancy_overtime_threshold_in_10min; extern volatile uint8_t sts_fall_rising_detected_result_changed_flag; extern volatile uint8_t last_sts_fall_rising_detected_result; -extern volatile uint8_t sts_unconcious_state; -extern volatile uint16_t sts_unconcious_threshold, sts_unconcious_duration; +extern volatile uint8_t sts_unconscious_state; +extern volatile uint16_t sts_unconscious_threshold, sts_unconscious_duration; extern volatile uint8_t sts_emergency_button_pushed, sts_rss_2nd_result,sts_tof_result, sts_status_color, sts_lamp_bar_color, sts_service_mask; extern volatile distance_measure_cfg_t distance_cfg; extern uint8_t sts_fall_rising_detected_result; @@ -114,7 +114,7 @@ char sts_presence_fall_detection_message[10][20]={ "State_Fall_Down", "State_Rising_Up", "State_Laydown", - "State_Unconcious", + "State_Unconscious", "State_StayStill" }; @@ -502,8 +502,8 @@ void STS_PRESENCE_SENSOR_Init_Send_Data(void) sts_o7_sensorData.fall_gravity = 0x0; sts_o7_sensorData.over_stay_state = 0x0; sts_o7_sensorData.over_stay_duration = 0x0; - sts_o7_sensorData.unconcious_state = 0x0; - sts_o7_sensorData.unconcious_duration = 0x0; + sts_o7_sensorData.unconscious_state = 0x0; + sts_o7_sensorData.unconscious_duration = 0x0; sts_o7_sensorData.event_sensor1_start_time = 0x0; sts_o7_sensorData.event_sensor1_duration = 0x0; @@ -534,14 +534,14 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *senso { sensor_data->rss_presence_distance = (uint16_t)(sts_presence_rss_distance)&0xFFFF; sensor_data->rss_presence_score = (uint16_t)(sts_presence_rss_score)&0xFFFF; - // uint8_t sts_unconcious_state; - // uint16_t sts_unconcious_threshold, sts_unconcious_threshold_duration; + // uint8_t sts_unconscious_state; + // uint16_t sts_unconscious_threshold, sts_unconscious_threshold_duration; } else { sensor_data->rss_presence_distance = 0x0; sensor_data->rss_presence_score = 0x0; } - sensor_data->unconcious_state=(sts_fall_rising_detected_result == STS_PRESENCE_UNCONCIOUS)? 1:0; + sensor_data->unconscious_state=(sts_fall_rising_detected_result == STS_PRESENCE_UNCONSCIOUS)? 1:0; sensor_data->over_stay_state = sts_o7_sensorData.over_stay_state; sensor_data->over_stay_duration = sts_o7_sensorData.over_stay_duration; @@ -555,7 +555,7 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *senso // For occupancy over time process //SysTime_t occupy_check_time = SysTimeGetMcuTime(); - if ((sts_occupancy_overtime_threshold != 0) && (event_start_time !=0)) + if ((sts_occupancy_overtime_threshold_in_10min != 0) && (event_start_time !=0)) { if (sts_occupancy_overtime_state == 1U) { sts_status_color = STS_RED_BLUE; @@ -597,8 +597,8 @@ void STS_PRESENCE_SENSOR_Init(void) sts_o7_sensorData.over_stay_state = 0; sts_o7_sensorData.over_stay_duration = 0; - sts_o7_sensorData.unconcious_duration = 0; - sts_o7_sensorData.unconcious_state = 0; + sts_o7_sensorData.unconscious_duration = 0; + sts_o7_sensorData.unconscious_state = 0; STS_SENSOR_Power_ON(0); STS_PRESENCE_SENSOR_REEDSWITCH_HALL_Init(); diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index e2ed847..6dc2f40 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -60,10 +60,14 @@ extern volatile uint8_t sts_lamp_bar_flashing_color; volatile uint8_t last_sts_lamp_bar_color=STS_DARK; extern volatile uint8_t sts_rss_result; extern volatile uint8_t sts_rss_result_changed_flag, sts_hall1_changed_flag, sts_hall2_changed_flag, sts_reed_hall_changed_flag; -volatile uint8_t sts_fall_detection_acc_threshold = 10, sts_fall_detection_depth_threshold=20, sts_occupancy_overtime_threshold=2; +volatile uint8_t sts_fall_detection_acc_threshold = 10, sts_fall_detection_depth_threshold=20, sts_fall_confirm_threshold_in_10sec=1, sts_occupancy_overtime_threshold_in_10min=2; +volatile uint8_t sts_unconscious_or_motionless_level_threshold=6; //6*128 +volatile uint8_t sts_motionless_duration_threshold_in_min=1; // test mode, 1 min, normal 10 min. long occupation 30 min +volatile uint16_t sts_unconscious_level_threshold=600; +volatile uint8_t sts_alarm_mute_reset_timer_in_10sec=6; extern volatile uint8_t sts_fall_rising_detected_result; extern volatile uint32_t event_start_time, event_stop_time; -extern volatile uint16_t sts_unconcious_threshold; +extern volatile uint16_t sts_unconscious_threshold; volatile uint8_t sts_occupancy_overtime_state = 0; volatile uint8_t sts_presence_fall_detection=1; volatile uint32_t SamplingPeriodicity = 1000; //unit ms @@ -114,17 +118,19 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = { 0x00, //reserve2 0x00, //reserve3 0x00, //reserve4 - 0x00, //reserve5 - 0x3C, //reserve6 60(0x3C) sec alarm_mute_or_reset_expire_timer_in_sec - 0x1E, //reserve7 0-60(0x3C) Sec, or 30(0x1E) sec default falldown_confirm_threshold_in_sec - 0x78, //reserve8 120(0x78) Sec (2 min.) motionless_duration_threshold_in_Sec - // below 5 bytes - 0x23, //Lamp Bar Flashing color define, 0x20, 2==STS_RED, 0 = STS_DARK, 0x23, 2=STS_RED, 3=STS_BLUE + + 0x00, //reserve5 alarm_parameter05 + 0x06, //reserve6 alarm_mute_or_reset_expire_timer_in_10sec, 60 seconds + 0x23, //reserve7 alarm Lamp Bar Flashing color define, 0x20, 2==STS_RED, 0 = STS_DARK, 0x23, 2=STS_RED, 3=STS_BLUE + 0x03, //reserve8 occupancy over time threshold 3*10 = 30 minutes + + 0x09, //reserve8 motionless_duration_threshold_in_min+1, normal: 10 min(0x0A) Minutes (2 min.) 1-9== 2-10min + 0x09, //unconscious threshold * 128, 0-9, 9*128=1280 motion level + 0x01, //fall_detection_acc_threshold = *10 acceleration measure 0x03, //fall detection_depth_threshold *10cm - 0x08, //unconcious threshold * 128, 0-9, 9*128=1280 motion level - 0x02, //occupancy over time threshold *10 minutes - // below 20 bytes + 0x03, //falldown_confirm_threshold_in_10sec, 0x3=30 sec default + // below 20 bytes for RFAC code {0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0} }; @@ -908,7 +914,7 @@ static void SendTxData(void) AppData.Buffer[i++] = (uint8_t)(sensorData.rss_presence_score>>8)&0xff; //09 MSB score AppData.Buffer[i++] = (uint8_t)(sensorData.rss_presence_score)&0xff; //10 LSB score - AppData.Buffer[i++] = (uint8_t)(sensorData.unconcious_state)&0xff; //11 unconcious state detected or not + AppData.Buffer[i++] = (uint8_t)(sensorData.unconscious_state)&0xff; //11 unconscious state detected or not AppData.Buffer[i++] = (uint8_t)(sensorData.fall_state)&0xff; //12 fall detected or not AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_state)&0xff; //13 occupancy over time or not AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_duration>>8)&0xff; //14 occupancy over stay duration MSB @@ -924,11 +930,11 @@ static void SendTxData(void) if (sts_work_mode == STS_UNI_MODE) { APP_LOG(TS_OFF, VLEVEL_H, - "\r\n######| S1-DoorOpen | S2-Motion | S3-SOS | S4 |Distance(mm) | MotionScore| Unconcious | Over_Stay | Fall Detected|" + "\r\n######| S1-DoorOpen | S2-Motion | S3-SOS | S4 |Distance(mm) | MotionScore| Unconscious | Over_Stay | Fall Detected|" "\r\n######| %1d | %1d | %1d | %1d | %04d | %04d | %1d | %1d | %1d |\r\n", sensorData.state_sensor1_on_off, sensorData.state_sensor2_on_off,sensorData.state_sensor3_on_off, sensorData.state_sensor4_on_off, (uint16_t)sensorData.rss_presence_distance,(uint16_t)sensorData.rss_presence_score, - sensorData.unconcious_state, sensorData.unconcious_duration, sensorData.fall_state ); + sensorData.unconscious_state, sensorData.unconscious_duration, sensorData.fall_state ); } else if (sts_work_mode == STS_DUAL_MODE) { APP_LOG(TS_OFF, VLEVEL_L, @@ -1096,7 +1102,7 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) if (sts_hall1_read==STS_Status_Door_Close) sts_o7_sensorData.event_sensor1_duration = current_time.Seconds - sts_o7_sensorData.event_sensor1_start_time; - if (sts_o7_sensorData.event_sensor1_duration > sts_occupancy_overtime_threshold) + if (sts_o7_sensorData.event_sensor1_duration > sts_occupancy_overtime_threshold_in_10min*600) { sts_o7_sensorData.over_stay_state = 1; sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor1_duration; @@ -1105,7 +1111,7 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) // to be defiend later for SOS threshold TODO XXXX if (sts_hall2_read==STS_Status_SOS_Pushdown) sts_o7_sensorData.event_sensor2_duration = current_time.Seconds - sts_o7_sensorData.event_sensor2_start_time; - if (sts_o7_sensorData.event_sensor2_duration > sts_occupancy_overtime_threshold) + if (sts_o7_sensorData.event_sensor2_duration > sts_occupancy_overtime_threshold_in_10min*600) { sts_o7_sensorData.over_stay_state = 1; sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor2_duration; @@ -1115,7 +1121,7 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) if (sts_rss_result==STS_RESULT_MOTION) sts_o7_sensorData.event_sensor3_motion_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_motion_start_time; - if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold) + if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold_in_10min*600) { sts_o7_sensorData.occupancy_over_stay_state = 1; sts_o7_sensorData.occupancy_duration =sts_o7_sensorData.event_sensor3_motion_duration; @@ -1126,19 +1132,19 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) STS_PRESENCE_FALL, STS_PRESENCE_RISING, STS_PRESENCE_LAYDOWN, - STS_PRESENCE_UNCONCIOUS, + STS_PRESENCE_UNCONSCIOUS, STS_PRESENCE_STAYSTILL */ switch (sts_fall_rising_detected_result){ case STS_PRESENCE_NONE: sts_o7_sensorData.fall_state = 0; sts_o7_sensorData.fall_laydown_duration=0; - sts_o7_sensorData.unconcious_state =0; - sts_o7_sensorData.unconcious_duration =0; + sts_o7_sensorData.unconscious_state =0; + sts_o7_sensorData.unconscious_duration =0; break; case STS_PRESENCE_FALL: sts_o7_sensorData.event_sensor3_fall_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_fall_start_time; - if (sts_o7_sensorData.event_sensor3_fall_duration > sts_cfg_nvm.falldown_confirm_threshold_in_Sec) + 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; @@ -1150,7 +1156,7 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) break; case STS_PRESENCE_LAYDOWN: break; - case STS_PRESENCE_UNCONCIOUS: + case STS_PRESENCE_UNCONSCIOUS: break; case STS_PRESENCE_STAYSTILL: break; @@ -2085,20 +2091,23 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD5]; STS_Combined_Status_Processing(); - } else if (tlv_buf_size == 8 && tlv_buf[CFG_CMD4]=='F') // Change fall detection, occupancy overtime threshold + } else if (tlv_buf_size == 8 && tlv_buf[CFG_CMD4]=='F') // Change fall detection { invalid_flag = 0; // P 1 1 F A B C D if (((tlv_buf[CFG_CMD5] >='0') && (tlv_buf[CFG_CMD5]<='9')) && ((tlv_buf[CFG_CMD6]<='9') && (tlv_buf[CFG_CMD6]>='0')) && ((tlv_buf[CFG_CMD7]<='9') && (tlv_buf[CFG_CMD7]>='0'))&& ((tlv_buf[CFG_CMD8]<='9') && (tlv_buf[CFG_CMD8]>='0'))) { - sts_fall_detection_acc_threshold = (uint8_t)(tlv_buf[CFG_CMD5] - 0x30)*10; //acc *10 mg/s2 - sts_fall_detection_depth_threshold = (uint8_t)(tlv_buf[CFG_CMD6] - 0x30)*10; //depth *10 in cm - sts_unconcious_threshold = (uint8_t)(tlv_buf[CFG_CMD7] - 0x30+1)*128; //motion level less than 1280 - sts_occupancy_overtime_threshold = (uint8_t)(tlv_buf[CFG_CMD8] - 0x30)*10; // overtime *10 min + sts_fall_detection_acc_threshold = (uint8_t)(tlv_buf[CFG_CMD5] - 0x30)*10; //acc *10 mg/s2 + sts_fall_detection_depth_threshold = (uint8_t)(tlv_buf[CFG_CMD6] - 0x30)*10; //depth *10 in cm + sts_fall_confirm_threshold_in_10sec = (uint8_t)(tlv_buf[CFG_CMD7] - 0x30+1)*128; //fall_confirm_threshold_in_10sec + + sts_occupancy_overtime_threshold_in_10min = (uint8_t)(tlv_buf[CFG_CMD8] - 0x30)*10; // overtime *10 min + sts_cfg_nvm.fall_detection_acc_threshold = (uint8_t)(tlv_buf[CFG_CMD5] - 0x30); sts_cfg_nvm.fall_detection_depth_threshold = (uint8_t)(tlv_buf[CFG_CMD6] - 0x30); - sts_cfg_nvm.unconcious_threshold = (uint8_t)(tlv_buf[CFG_CMD7] - 0x30+1); - sts_cfg_nvm.occupancy_overtime_threshold = (uint8_t)(tlv_buf[CFG_CMD8] - 0x30); + sts_cfg_nvm.fall_confirm_threshold_in_10sec = (uint8_t)(tlv_buf[CFG_CMD7] - 0x30+1); + + sts_cfg_nvm.occupancy_overtime_threshold_in_10min = (uint8_t)(tlv_buf[CFG_CMD8] - 0x30); if (sts_work_mode == STS_UNI_MODE) // fall detection threshold only effective in Uni_mode { @@ -2124,7 +2133,37 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) - } else if (tlv_buf_size == 4 ) // P WORK mode switch + }else if (tlv_buf_size == 8 && tlv_buf[CFG_CMD4]=='O') // Change occupancy/motionless/ unconscious overtime threshold + { + invalid_flag = 0; // P 1 1 O A B C D + if (((tlv_buf[CFG_CMD5] >='0') && (tlv_buf[CFG_CMD5]<='9')) && ((tlv_buf[CFG_CMD6]<='9') && (tlv_buf[CFG_CMD6]>='0')) + && ((tlv_buf[CFG_CMD7]<='9') && (tlv_buf[CFG_CMD7]>='0'))&& ((tlv_buf[CFG_CMD8]<='9') && (tlv_buf[CFG_CMD8]>='0'))) + { + sts_motionless_duration_threshold_in_min = (uint8_t)(tlv_buf[CFG_CMD5] - 0x30); //Motionless duration in min + sts_occupancy_overtime_threshold_in_10min = (uint8_t)(tlv_buf[CFG_CMD6] - 0x30)*10; //Long occupation in min + sts_unconscious_level_threshold = (uint8_t)(tlv_buf[CFG_CMD7] - 0x30+1)*128; //motion level threshold less than 1280 + sts_alarm_mute_reset_timer_in_10sec = (uint8_t)(tlv_buf[CFG_CMD8] - 0x30)*10; //alarm mute reset timer in 10 sec + + sts_cfg_nvm.motionless_duration_threshold_in_min = (uint8_t)(tlv_buf[CFG_CMD5] - 0x30); + sts_cfg_nvm.occupancy_overtime_threshold_in_10min = (uint8_t)(tlv_buf[CFG_CMD6] - 0x30); + sts_cfg_nvm.unconscious_or_motionless_level_threshold = (uint8_t)(tlv_buf[CFG_CMD7] - 0x30+1); + sts_cfg_nvm.alarm_mute_reset_timer_in_10sec = (uint8_t)(tlv_buf[CFG_CMD8] - 0x30)*10; + + OnStoreSTSCFGContextRequest(); + + i=0; // Step 1: Prepare status update message + outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD1]; + outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD2]; + outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD3]; + outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD4]; + outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD5]; + outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD6]; + outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD7]; + outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD8]; + STS_Combined_Status_Processing(); + } + } + else if (tlv_buf_size == 4 ) // P WORK mode switch { invalid_flag = 0; @@ -2417,20 +2456,16 @@ void OnStoreSTSCFGContextRequest(void) nvm_store_value[i++] = sts_cfg_nvm.reserve02; nvm_store_value[i++] = sts_cfg_nvm.reserve03; nvm_store_value[i++] = sts_cfg_nvm.reserve04; - nvm_store_value[i++] = sts_cfg_nvm.reserve05; - nvm_store_value[i++] = sts_cfg_nvm.alarm_mute_or_reset_expire_timer_in_Sec; - nvm_store_value[i++] = sts_cfg_nvm.falldown_confirm_threshold_in_Sec; - nvm_store_value[i++] = sts_cfg_nvm.motionless_duration_threshold_in_Sec; - nvm_store_value[i++] = sts_cfg_nvm.lamp_bar_flashing_color; + nvm_store_value[i++] = sts_cfg_nvm.alarm_parameter05; + nvm_store_value[i++] = sts_cfg_nvm.alarm_mute_reset_timer_in_10sec; + nvm_store_value[i++] = sts_cfg_nvm.alarm_lamp_bar_flashing_color; + nvm_store_value[i++] = sts_cfg_nvm.occupancy_overtime_threshold_in_10min; + nvm_store_value[i++] = sts_cfg_nvm.motionless_duration_threshold_in_min; + nvm_store_value[i++] = sts_cfg_nvm.unconscious_or_motionless_level_threshold; nvm_store_value[i++] = sts_cfg_nvm.fall_detection_acc_threshold; nvm_store_value[i++] = sts_cfg_nvm.fall_detection_depth_threshold; - nvm_store_value[i++] = sts_cfg_nvm.unconcious_threshold; - nvm_store_value[i++] = sts_cfg_nvm.occupancy_overtime_threshold; - if ((sts_cfg_nvm.fall_detection_acc_threshold ==0)&&(sts_cfg_nvm.fall_detection_depth_threshold==0)) { - sts_presence_fall_detection =0; - } else { - sts_presence_fall_detection =1; - } + nvm_store_value[i++] = sts_cfg_nvm.fall_confirm_threshold_in_10sec; + if ((sts_cfg_nvm.ac[0]!=0x0) && (sts_cfg_nvm.ac[19]!=0x0)) { for (j = 0; j < YUNHORN_STS_AC_CODE_SIZE; j++) { nvm_store_value[i++] = (sts_cfg_nvm.ac[j]); @@ -2508,16 +2543,17 @@ void STS_REBOOT_CONFIG_Init(void) sts_cfg_nvm.reserve02 =(uint8_t)nvm_stored_value[NVM_RESERVE02]; sts_cfg_nvm.reserve03 =(uint8_t)nvm_stored_value[NVM_RESERVE03]; sts_cfg_nvm.reserve04 =(uint8_t)nvm_stored_value[NVM_RESERVE04]; - sts_cfg_nvm.reserve05 =(uint8_t)nvm_stored_value[NVM_RESERVE05]; - sts_cfg_nvm.alarm_mute_or_reset_expire_timer_in_Sec = (uint8_t)nvm_stored_value[NVM_ALARM_MUTE_RESET_TIMER]; - sts_cfg_nvm.falldown_confirm_threshold_in_Sec = (uint8_t)nvm_stored_value[NVM_FALL_CONFIRM_THRESHOLD]; - sts_cfg_nvm.motionless_duration_threshold_in_Sec = (uint8_t)nvm_stored_value[NVM_MOTIONLESS_THRESHOLD]; - sts_cfg_nvm.motionless_duration_threshold_in_Sec= (uint8_t)nvm_stored_value[NVM_LAMP_BAR_FLASHING_COLOR]; - sts_cfg_nvm.lamp_bar_flashing_color = (uint8_t)nvm_stored_value[NVM_LAMP_BAR_FLASHING_COLOR]; + sts_cfg_nvm.alarm_parameter05 =(uint8_t)nvm_stored_value[NVM_ALARM_PARAMETER05]; + sts_cfg_nvm.alarm_mute_reset_timer_in_10sec = (uint8_t)nvm_stored_value[NVM_ALARM_MUTE_RESET_TIMER]; + sts_cfg_nvm.alarm_lamp_bar_flashing_color = (uint8_t)nvm_stored_value[NVM_ALARM_LAMP_BAR_FLASHING_COLOR]; + sts_cfg_nvm.occupancy_overtime_threshold_in_10min = (uint8_t)nvm_stored_value[NVM_OCCUPANCY_OVERTIME_THRESHOLD]; + sts_cfg_nvm.motionless_duration_threshold_in_min= (uint8_t)nvm_stored_value[NVM_MOTIONLESS_DURATION_THRESHOLD]; + sts_cfg_nvm.unconscious_or_motionless_level_threshold = (uint8_t)nvm_stored_value[NVM_UNCONSCIOUS_LEVEL_THRESHOLD]; sts_cfg_nvm.fall_detection_acc_threshold = (uint8_t)nvm_stored_value[NVM_FALL_DETECTION_ACC_THRESHOLD]; sts_cfg_nvm.fall_detection_depth_threshold = (uint8_t)nvm_stored_value[NVM_FALL_DETECTION_DEPTH_THRESHOLD]; - sts_cfg_nvm.unconcious_threshold = (uint8_t)nvm_stored_value[NVM_UNCONCIOUS_THRESHOLD]; - sts_cfg_nvm.occupancy_overtime_threshold = (uint8_t)nvm_stored_value[NVM_OCCUPANCY_OVERTIME_THRESHOLD]; + sts_cfg_nvm.fall_confirm_threshold_in_10sec = (uint8_t)nvm_stored_value[NVM_FALL_CONFIRM_THRESHOLD]; + + //sts_cfg_nvm.occupancy_overtime_threshold = (uint8_t)nvm_stored_value[NVM_OCCUPANCY_OVERTIME_THRESHOLD]; for (uint8_t j=0; j< YUNHORN_STS_AC_CODE_SIZE; j++) { sts_cfg_nvm.ac[j] = (uint8_t)nvm_stored_value[NVM_AC_CODE_START +j]; @@ -2578,20 +2614,23 @@ void OnRestoreSTSCFGContextProcess(void) #endif } - sts_work_mode = sts_cfg_nvm.work_mode; - sts_lamp_bar_color = STS_GREEN; - sts_service_mask = sts_cfg_nvm.sts_service_mask; - sts_lamp_bar_flashing_color = sts_cfg_nvm.lamp_bar_flashing_color; + sts_work_mode = sts_cfg_nvm.work_mode; + sts_lamp_bar_color = STS_GREEN; + sts_service_mask = sts_cfg_nvm.sts_service_mask; + sts_lamp_bar_flashing_color = sts_cfg_nvm.alarm_lamp_bar_flashing_color; if (sts_work_mode == STS_UNI_MODE){ sts_presence_fall_detection =1; } else { sts_presence_fall_detection =0; } - sts_fall_detection_acc_threshold = (uint8_t)sts_cfg_nvm.fall_detection_acc_threshold*10; - sts_fall_detection_depth_threshold = (uint8_t)sts_cfg_nvm.fall_detection_depth_threshold*10; //in cm - sts_unconcious_threshold = (uint8_t)(sts_cfg_nvm.unconcious_threshold+1)*128; // unconcious threshold - sts_occupancy_overtime_threshold = (uint8_t)sts_cfg_nvm.occupancy_overtime_threshold*10; // minutes + sts_fall_detection_acc_threshold = (uint8_t)sts_cfg_nvm.fall_detection_acc_threshold*10; + sts_fall_detection_depth_threshold = (uint8_t)sts_cfg_nvm.fall_detection_depth_threshold*10; //in cm + sts_fall_confirm_threshold_in_10sec = (uint8_t)sts_cfg_nvm.fall_confirm_threshold_in_10sec*10; + + sts_unconscious_or_motionless_level_threshold = (uint8_t)(sts_cfg_nvm.unconscious_or_motionless_level_threshold+1)*128; // unconscious threshold + sts_motionless_duration_threshold_in_min = (uint8_t)sts_cfg_nvm.motionless_duration_threshold_in_min; + sts_occupancy_overtime_threshold_in_10min = (uint8_t)sts_cfg_nvm.occupancy_overtime_threshold_in_10min; // minutes for (uint8_t j=0; j< YUNHORN_STS_AC_CODE_SIZE; j++)