diff --git a/Core/Inc/sts_lamp_bar.h b/Core/Inc/sts_lamp_bar.h index 89edc9b..e57dae5 100644 --- a/Core/Inc/sts_lamp_bar.h +++ b/Core/Inc/sts_lamp_bar.h @@ -64,6 +64,13 @@ enum sts_lamp_color { STS_REDGREEN=0x45, // RED/GREEN FLASH 'E' STS_BLUEGREEN=0x46 // BLUE/GREEN FLASH 'F' }; + +#define STS_VACANT_COLOR STS_BLUE +#define STS_OCCUPY_COLOR STS_GREEN +#define STS_FALL_SUSPICIOUS_COLOR STS_YELLOW +#define STS_FALL_CONFIRMED_COLOR STS_RED +#define STS_HUMAN_MOVEMENT_MOTIONLESS_COLOR STS_YELLOW +#define STS_OCCUPANCY_OVERSTAY_COLOR STS_RED /* enum sts_oo_work_mode { STS_NETWORK_MODE = 0, // 0 NETWORK MODE diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 695c363..19f9056 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -67,9 +67,9 @@ volatile uint8_t sts_data_buf[LORAWAN_APP_DATA_BUFFER_MAX_SIZE]={0x0}; extern volatile uint8_t fhmos_fall, fhmos_human_movement, fhmos_occupancy, fhmos_sos_alarm; extern volatile uint32_t fhmos_fall_counter; // extern volatile uint32_t sts_low_threshold, sts_high_threshold, sts_occupancy_threshold; -extern volatile sts_fhmos_sensor_data_t sts_fhmos_data; -extern volatile sts_fhmos_sensor_config_t sts_fhmos_cfg; -extern volatile sts_fhmos_sensor_ambient_height_t sts_fhmos_bg; +extern volatile sts_fhmos_sensor_data_t fhmos_data; +extern volatile sts_fhmos_sensor_config_t fhmos_cfg; +extern volatile sts_fhmos_sensor_ambient_height_t fhmos_bg; // volatile LmHandlerAppData_t sts_app_data={ 0, 0, sts_data_buf }; extern volatile uint8_t sts_hall1_read, sts_hall2_read; // Above hall1_read == reed_hall_result, hall2_read == emergency_button extern volatile uint8_t sts_hall3_read, sts_hall4_read; @@ -867,7 +867,7 @@ static void SendTxData(void) #elif defined(STS_M1) sts_r_sensor_data_t sts_m1_sensor_data={0}; #elif defined(STS_L8) - sts_fhmos_sensor_data_t sts_fhmos_data={0}; + sts_fhmos_sensor_data_t fhmos_data={0}; #elif defined(STS_XX) #endif @@ -901,7 +901,7 @@ static void SendTxData(void) #endif #ifdef STS_L8 - STS_FHMOS_sensor_read(&sts_fhmos_data); + STS_FHMOS_sensor_read(&fhmos_data); #endif #ifdef VL53LX @@ -1072,10 +1072,10 @@ static void SendTxData(void) #if defined(L8) AppData.Buffer[i++] = 4; - AppData.Buffer[i++] = sts_fhmos_data.fall_state; - AppData.Buffer[i++] = sts_fhmos_data.human_movement_state; - AppData.Buffer[i++] = sts_fhmos_data.occupancy_state; - AppData.Buffer[i++] = sts_fhmos_data.sos_alarm_state; + AppData.Buffer[i++] = fhmos_data.state_fall; + AppData.Buffer[i++] = fhmos_data.state_human_movement; + AppData.Buffer[i++] = fhmos_data.state_occupancy; + AppData.Buffer[i++] = fhmos_data.state_sos_alarm; //(uint8_t)((sts_l8_sensor_data.tof_range_presence_state & 0xFF)); diff --git a/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf b/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf index 1aa0431..9c0b852 100644 Binary files a/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf and b/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf differ diff --git a/STM32CubeIDE/Release/makefile b/STM32CubeIDE/Release/makefile index 90d8aef..931125d 100644 --- a/STM32CubeIDE/Release/makefile +++ b/STM32CubeIDE/Release/makefile @@ -20,6 +20,7 @@ RM := rm -rf -include Application/User/Startup/subdir.mk -include Application/User/STS/TOF/Target/subdir.mk -include Application/User/STS/TOF/App/subdir.mk +-include Application/User/STS/RSS/subdir.mk -include Application/User/STS/Core/Src/subdir.mk -include Application/User/LoRaWAN/Target/subdir.mk -include Application/User/LoRaWAN/App/subdir.mk diff --git a/STM32CubeIDE/Release/sources.mk b/STM32CubeIDE/Release/sources.mk index c6e8d88..d63a2a8 100644 --- a/STM32CubeIDE/Release/sources.mk +++ b/STM32CubeIDE/Release/sources.mk @@ -26,6 +26,7 @@ Application/User/Core \ Application/User/LoRaWAN/App \ Application/User/LoRaWAN/Target \ Application/User/STS/Core/Src \ +Application/User/STS/RSS \ Application/User/STS/TOF/App \ Application/User/STS/TOF/Target \ Application/User/Startup \ diff --git a/STS/Core/Inc/yunhorn_sts_sensors.h b/STS/Core/Inc/yunhorn_sts_sensors.h index 8c4209b..cc97e2c 100644 --- a/STS/Core/Inc/yunhorn_sts_sensors.h +++ b/STS/Core/Inc/yunhorn_sts_sensors.h @@ -252,27 +252,69 @@ typedef struct sts_r_sensor_data } sts_r_sensor_data_t; +enum { + STS_FHMOS_FALL_STATE_NO_OCCUPY=0, + STS_FHMOS_FALL_STATE_NORMAL, + STS_FHMOS_FALL_STATE_POTENTIAL, + STS_FHMOS_FALL_STATE_CONFIRMED +}; + +enum { + STS_FHMOS_HUMAN_MOVEMENT_NO_OCCUPY=0, + STS_FHMOS_HUMAN_MOVEMENT_NORMAL, + STS_FHMOS_HUMAN_MOVEMENT_MOTIONLESS_SHORT, + STS_FHMOS_HUMAN_MOVEMENT_MOTIONLESS_LONG, +}; + +enum { + STS_FHMOS_OCCUPANCY_NO_OCCUPY=0, + STS_FHMOS_OCCUPANCY_NORMAL, + STS_FHMOS_OCCUPANCY_OVERSTAY, +}; + + +enum { + STS_FHMOS_SOS_ALARM_BUTTON_NORMAL=0, + STS_FHMOS_SOS_ALARM_BUTTON_PUSHED, + STS_FHMOS_SOS_ALARM_BUTTON_RESET +}; + typedef struct sts_fhmos_sensor_data { uint16_t install_height_mm; /*Default distance sensor measured distance */ uint16_t battery_mV; /*mV, 1000mv-5000mv, regular 3300mV - 3600mV --4200mV */ - uint8_t fall_state; /* 0/blue: no occupy, 1/green:occupy yet normal, 2/yellow: suspicious state, 3/red: fall confirmed */ - uint8_t human_movement_state; /* 0/blue: no occupy, 1/green:occupy yet normal, 2/yellow: suspicious state, 3/red: fall confirmed */ - uint8_t occupancy_state; /* 0/blue: no occupy, 1/green:occupy yet normal, 3/red: over stay */ - uint8_t sos_alarm_state; /* 1/green, sos on-duty, 2/yellow, sos button pressed 3/red, alarm */ + uint8_t state_fall; /* 0/blue: no occupy, 1/green:occupy yet normal, 2/yellow: suspicious state, 3/red: fall confirmed */ + uint8_t state_human_movement; /* 0/blue: no occupy, 1/green:occupy yet normal, 2/yellow: suspicious state, 3/red: fall confirmed */ + uint8_t state_occupancy; /* 0/blue: no occupy, 1/green:occupy yet normal, 3/red: over stay */ + uint8_t state_sos_alarm; /* 1/green, sos on-duty, 2/yellow, sos button pressed 3/red, alarm */ uint8_t on_off_event; /* 1: liquid sensed, 0: no liquid sensed */ - - + uint8_t state_changed_fall; + uint8_t state_changed_human_movemen; + uint8_t state_changed_occupancy; + uint8_t state_changed_sos; + uint8_t prev_fall; + uint8_t prev_human_movement; + uint8_t prev_occupancy; + uint8_t prev_sos; } sts_fhmos_sensor_data_t; +typedef struct sts_fhmos_threshold_type +{ + uint16_t th_low_mm; + uint16_t th_high_mm; + uint16_t th_occupancy__low_mm; + uint16_t th_occupancy_high_mm; + uint16_t th_fall_head_level_mm; +} sts_fhmos_threshold_t; + typedef struct sts_fhmos_sensor_config { - uint8_t sts_head_level_height_threshold_cm; - uint8_t sts_fall_duration_threshold_potential_15sec; - uint8_t sts_fall_duration_threshold_confirm_15sec; - uint8_t sts_motionless_threshold_short_15sec; - uint8_t sts_motionless_threshold_long_15sec; - uint8_t sts_occupancy_threshold_overstay_15sec; + uint8_t th_head_level_height_cm; + uint8_t th_fall_duration_potential_15sec; + uint8_t th_fall_duration_confirm_15sec; + uint8_t th_motionless_short_15sec; + uint8_t th_motionless_long_15sec; + uint8_t th_occupancy_overstay_15sec; } sts_fhmos_sensor_config_t; diff --git a/STS/Core/Src/yunhorn_sts_process.c b/STS/Core/Src/yunhorn_sts_process.c index 0b85d66..dd51a43 100644 --- a/STS/Core/Src/yunhorn_sts_process.c +++ b/STS/Core/Src/yunhorn_sts_process.c @@ -66,11 +66,11 @@ extern volatile uint8_t sts_lamp_bar_color; //puColor extern volatile uint8_t sts_lamp_bar_flashing_color; //0x23; RED_BLUE; volatile uint8_t sts_cloud_netcolor = STS_BLUE; //netColor extern volatile uint8_t sts_occupancy_status; - +extern volatile sts_fhmos_sensor_config_t fhmos_cfg; extern volatile uint8_t sts_status_color, sts_lamp_bar_color;//puColor extern uint8_t luminance_level; - -extern volatile sts_fhmos_sensor_config_t sts_fhmos_cfg; +volatile uint8_t sts_fhmos_state_changed=0; +volatile sts_fhmos_sensor_config_t sts_fhmos_cfg; extern volatile uint8_t sts_mask_bitmap[8]; #endif volatile sts_cfg_nvm_t sts_cfg_nvm = { @@ -474,7 +474,17 @@ void STS_YunhornSTSEventP5_Process(void) #elif defined(L8) //STS_TOF_VL53L8X_Process(); //printf("\r\n P5 process \r\n"); + STS_TOF_L8_Process(); + + if (sts_fhmos_state_changed) + { + sts_fhmos_state_changed = 0; + UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); + + } + + //MX_TOF_Process(); //MX_TOF_Ranging_Process(); #endif @@ -667,40 +677,40 @@ void USER_APP_Parse_CMD_P(uint8_t *parse_buffer, uint8_t parse_buffer_size) { uint8_t sts_fhmos_cfg_index = (uint8_t)(parse_buffer[CFG_CMD5]-0x30); uint8_t sts_fhmos_cfg_value = (parse_buffer[CFG_CMD6]-0x30)*100+(parse_buffer[CFG_CMD7]-0x30)*10+(parse_buffer[CFG_CMD8]-0x30); - //APP_LOG(TS_OFF, VLEVEL_M, "\r\nCFG_CMD VALUE =0X%02X =%d \r\n", sts_fhmos_cfg_value,sts_fhmos_cfg_value); + APP_LOG(TS_OFF, VLEVEL_M, "\r\nCFG_CMD Index=%d, VALUE =0X%02X =%d \r\n", sts_fhmos_cfg_index, sts_fhmos_cfg_value,sts_fhmos_cfg_value); switch (sts_fhmos_cfg_index) { case 1: // head level height threshold - sts_fhmos_cfg.sts_head_level_height_threshold_cm = sts_fhmos_cfg_value; + sts_fhmos_cfg.th_head_level_height_cm = sts_fhmos_cfg_value; break; case 2: - sts_fhmos_cfg.sts_fall_duration_threshold_potential_15sec = sts_fhmos_cfg_value; + sts_fhmos_cfg.th_fall_duration_potential_15sec = sts_fhmos_cfg_value; break; case 3: - sts_fhmos_cfg.sts_fall_duration_threshold_confirm_15sec = sts_fhmos_cfg_value; + sts_fhmos_cfg.th_fall_duration_confirm_15sec = sts_fhmos_cfg_value; break; case 4: - sts_fhmos_cfg.sts_motionless_threshold_short_15sec = sts_fhmos_cfg_value; + sts_fhmos_cfg.th_motionless_short_15sec = sts_fhmos_cfg_value; break; case 5: - sts_fhmos_cfg.sts_motionless_threshold_long_15sec = sts_fhmos_cfg_value; + sts_fhmos_cfg.th_motionless_long_15sec = sts_fhmos_cfg_value; break; case 6: - sts_fhmos_cfg.sts_occupancy_threshold_overstay_15sec = sts_fhmos_cfg_value; + sts_fhmos_cfg.th_occupancy_overstay_15sec = sts_fhmos_cfg_value; break; } - sts_cfg_nvm.fhmos_cfg_1 = sts_fhmos_cfg.sts_head_level_height_threshold_cm; - sts_cfg_nvm.fhmos_cfg_2 = sts_fhmos_cfg.sts_fall_duration_threshold_potential_15sec; - sts_cfg_nvm.fhmos_cfg_3 = sts_fhmos_cfg.sts_fall_duration_threshold_confirm_15sec; - sts_cfg_nvm.fhmos_cfg_4 = sts_fhmos_cfg.sts_motionless_threshold_short_15sec; - sts_cfg_nvm.fhmos_cfg_5 = sts_fhmos_cfg.sts_motionless_threshold_long_15sec; - sts_cfg_nvm.fhmos_cfg_6 = sts_fhmos_cfg.sts_occupancy_threshold_overstay_15sec; + sts_cfg_nvm.fhmos_cfg_1 = fhmos_cfg.th_head_level_height_cm; + sts_cfg_nvm.fhmos_cfg_2 = fhmos_cfg.th_fall_duration_potential_15sec; + sts_cfg_nvm.fhmos_cfg_3 = fhmos_cfg.th_fall_duration_confirm_15sec; + sts_cfg_nvm.fhmos_cfg_4 = fhmos_cfg.th_motionless_short_15sec; + sts_cfg_nvm.fhmos_cfg_5 = fhmos_cfg.th_motionless_long_15sec; + sts_cfg_nvm.fhmos_cfg_6 = fhmos_cfg.th_occupancy_overstay_15sec; OnStoreSTSCFGContextRequest(); @@ -1795,24 +1805,24 @@ void OnRestoreSTSCFGContextProcess(void) void STS_FHMOS_sensor_config_init(void) { //uint8_t fhmos_fall=0, fhmos_human_movement=0, fhmos_occupancy=0, fhmos_sos_alarm=0; - sts_fhmos_cfg.sts_head_level_height_threshold_cm = 70; // default 700mm - sts_fhmos_cfg.sts_fall_duration_threshold_potential_15sec = 4; // 4*15=60 sec, 1 min. - sts_fhmos_cfg.sts_fall_duration_threshold_confirm_15sec = 8; // 8*15 = 120 sec, 2 min. - sts_fhmos_cfg.sts_motionless_threshold_short_15sec = 4; // 4*15 = 60 sec , 1 min. - sts_fhmos_cfg.sts_motionless_threshold_long_15sec = 16; // 20*15 = 300 sec, 5 min. - sts_fhmos_cfg.sts_occupancy_threshold_overstay_15sec = 100; // 80*15 = 1200 sec, 20 min. + sts_fhmos_cfg.th_head_level_height_cm = 70; // default 700mm + sts_fhmos_cfg.th_fall_duration_potential_15sec = 4; // 4*15=60 sec, 1 min. + sts_fhmos_cfg.th_fall_duration_confirm_15sec = 8; // 8*15 = 120 sec, 2 min. + sts_fhmos_cfg.th_motionless_short_15sec = 4; // 4*15 = 60 sec , 1 min. + sts_fhmos_cfg.th_motionless_long_15sec = 16; // 20*15 = 300 sec, 5 min. + sts_fhmos_cfg.th_occupancy_overstay_15sec = 100; // 80*15 = 1200 sec, 20 min. } void STS_FHMOS_sensor_config_update() { - sts_fhmos_cfg.sts_head_level_height_threshold_cm = sts_cfg_nvm.fhmos_cfg_1; // default 700mm - sts_fhmos_cfg.sts_fall_duration_threshold_potential_15sec = sts_cfg_nvm.fhmos_cfg_2; // 4*15=60 sec, 1 min. - sts_fhmos_cfg.sts_fall_duration_threshold_confirm_15sec = sts_cfg_nvm.fhmos_cfg_3; // 8*15 = 120 sec, 2 min. - sts_fhmos_cfg.sts_motionless_threshold_short_15sec = sts_cfg_nvm.fhmos_cfg_4; // 4*15 = 60 sec , 1 min. - sts_fhmos_cfg.sts_motionless_threshold_long_15sec = sts_cfg_nvm.fhmos_cfg_5; // 20*15 = 300 sec, 5 min. - sts_fhmos_cfg.sts_occupancy_threshold_overstay_15sec = sts_cfg_nvm.fhmos_cfg_6; // 80*15 = 1200 sec, 20 min. + sts_fhmos_cfg.th_head_level_height_cm = sts_cfg_nvm.fhmos_cfg_1; // default 700mm + sts_fhmos_cfg.th_fall_duration_potential_15sec = sts_cfg_nvm.fhmos_cfg_2; // 4*15=60 sec, 1 min. + sts_fhmos_cfg.th_fall_duration_confirm_15sec = sts_cfg_nvm.fhmos_cfg_3; // 8*15 = 120 sec, 2 min. + sts_fhmos_cfg.th_motionless_short_15sec = sts_cfg_nvm.fhmos_cfg_4; // 4*15 = 60 sec , 1 min. + sts_fhmos_cfg.th_motionless_long_15sec = sts_cfg_nvm.fhmos_cfg_5; // 20*15 = 300 sec, 5 min. + sts_fhmos_cfg.th_occupancy_overstay_15sec = sts_cfg_nvm.fhmos_cfg_6; // 80*15 = 1200 sec, 20 min. } diff --git a/STS/TOF/App/app_tof.c b/STS/TOF/App/app_tof.c index 18fd0f4..3cd13f4 100644 --- a/STS/TOF/App/app_tof.c +++ b/STS/TOF/App/app_tof.c @@ -39,9 +39,12 @@ extern "C" { volatile uint8_t fhmos_fall=0, fhmos_human_movement=0, fhmos_occupancy=0, fhmos_sos_alarm=0; volatile uint32_t fhmos_fall_counter=0; volatile uint32_t sts_low_threshold=1500, sts_high_threshold=2800, sts_occupancy_threshold=2300; -volatile sts_fhmos_sensor_data_t sts_fhmos_data; -volatile sts_fhmos_sensor_config_t sts_fhmos_cfg; -volatile sts_fhmos_sensor_ambient_height_t sts_fhmos_bg={0x0}; + +volatile sts_fhmos_sensor_data_t fhmos={0x0}; +volatile sts_fhmos_sensor_config_t fhmos_cfg; +volatile sts_fhmos_sensor_ambient_height_t fhmos_bg={0x0}; +volatile sts_fhmos_sensor_data_t fhmos_data; + volatile uint8_t sts_mask_bitmap[8]={0x0}; extern volatile uint16_t sts_sensor_install_height; //in mm extern volatile uint8_t sts_lamp_bar_color; @@ -88,12 +91,12 @@ extern volatile uint8_t sts_lamp_bar_color; /* ceiling -------------------- zero - 00 ref. 3000 mm high * * - * people high --------------- 2100 mm western people + * people high --------------- 2100 mm high people * * * * - * people how ------------------- 900 mm child normal + * people low ------------------- 900 mm child normal * * * @@ -171,9 +174,12 @@ void STS_LMZ_Ambient_Height_Scan_Process(void) for (i=0; i<64; i++) { - sts_fhmos_bg.h2cm[i] = 0; - sts_fhmos_bg.maskoff[i] = 0; + fhmos_bg.h2cm[i] = 0; + fhmos_bg.maskoff[i] = 0; } + for (i=0;i<8;i++) + sts_mask_bitmap[i]=0; + // printf("sts sensor install height = %4d \r\n", (int)sts_sensor_install_height); @@ -192,20 +198,20 @@ void STS_LMZ_Ambient_Height_Scan_Process(void) range_distance = (uint32_t)Result.ZoneResult[i].Distance[0]; //if (sts_sensor_install_height > range_distance) - sts_fhmos_bg.h2cm[i] += ((uint32_t)sts_sensor_install_height - range_distance); - if (abs(sts_fhmos_bg.h2cm[i])<100){ - sts_fhmos_bg.maskoff[i] = 0; + fhmos_bg.h2cm[i] += ((uint32_t)sts_sensor_install_height - range_distance); + if (abs(fhmos_bg.h2cm[i])<100){ + fhmos_bg.maskoff[i] = 0; } else { - sts_fhmos_bg.maskoff[i] = 1; - sts_mask_bitmap[i/8] |= 1<<(7-i%8); - } + fhmos_bg.maskoff[i] = 1; + } + sts_mask_bitmap[(uint8_t)(i/8)] |= (fhmos_bg.maskoff[i])<<(7-i%8); if (i%8==0) printf("\r\n"); - printf("|%4d %4d ", range_distance, sts_fhmos_bg.h2cm[i]); + printf("|%4d %4d ", range_distance, fhmos_bg.h2cm[i]); } else { - sts_fhmos_bg.h2cm[i] += 0; + fhmos_bg.h2cm[i] += 0; //printf(" .%d. ", i); } @@ -215,7 +221,7 @@ void STS_LMZ_Ambient_Height_Scan_Process(void) for (i=0; i<64; i++) { if (i%8==0) printf("\r\n"); - printf("|%d ", (uint8_t)sts_fhmos_bg.maskoff[i]); + printf("|%d ", (uint8_t)fhmos_bg.maskoff[i]); } for (i=0; i<8; i++) printf("%02X\r\n",sts_mask_bitmap[i]); @@ -462,43 +468,57 @@ static void print_result(RANGING_SENSOR_Result_t *Result) //int32_t roi_distance =(uint32_t)(Result->ZoneResult[j + k].Distance[l]); int32_t roi_distance =(uint32_t)center_range_distance/4; + /* state tree */ - if ((roi_distance < sts_high_threshold) && (roi_distance > (sts_high_threshold - sts_fhmos_cfg.sts_head_level_height_threshold_cm*10))) // TODO XXX + if ((roi_distance < sts_high_threshold) && (roi_distance > (sts_high_threshold - fhmos_cfg.th_head_level_height_cm*10))) // TODO XXX { - printf("\r\n roi_distance =%d -----[high=%4d Head Level =%d \r\n", roi_distance, sts_high_threshold, (sts_high_threshold- sts_fhmos_cfg.sts_head_level_height_threshold_cm*10)); + printf("\r\n Suspicious Fall state: roi_distance =%d -----[high=%4d mm Head Level =%d mm\r\n", roi_distance, sts_high_threshold, 10*fhmos_cfg.th_head_level_height_cm); - sts_fhmos_data.fall_state = 1; - sts_fhmos_data.human_movement_state = 1; + fhmos_data.state_fall = 1; + fhmos_data.state_human_movement = 1; - fhmos_fall = 1; - fhmos_human_movement = 1; fhmos_fall_counter ++; // TODO XXX Timer for confirmation if ((fhmos_fall_counter >60)&& (fhmos_fall_counter < 200)) { printf("\r\n Fall state --- Yellow \r\n"); fhmos_fall =2; - sts_lamp_bar_color = STS_YELLOW; + sts_lamp_bar_color = STS_FALL_SUSPICIOUS_COLOR; + fhmos_data.state_changed_fall = STS_FHMOS_FALL_STATE_POTENTIAL; } else if (fhmos_fall_counter >= 200) { printf("\r\n Fall state --- Red \r\n"); fhmos_fall =3; - sts_lamp_bar_color = STS_RED; + sts_lamp_bar_color = STS_FALL_CONFIRMED_COLOR; + fhmos_data.state_changed_fall = STS_FHMOS_FALL_STATE_CONFIRMED; } } else if ((roi_distance > sts_low_threshold)&&(roi_distance < sts_occupancy_threshold)) { - printf("\r\n rio distance =%d, low =%d occupy=%d \r\n", roi_distance, sts_low_threshold, sts_occupancy_threshold); - //fhmos_occupancy = 1; - sts_fhmos_data.occupancy_state = 1; - if (prev_occupy_state != sts_fhmos_data.occupancy_state) - sts_lamp_bar_color = STS_GREEN; - } else { - sts_fhmos_data.occupancy_state = 0; - if (prev_occupy_state != sts_fhmos_data.occupancy_state) - sts_lamp_bar_color = STS_BLUE; + fhmos_fall_counter = 0; + fhmos_fall = 0; + fhmos_human_movement = 1; + + printf("\r\nNormal Occupy state: rio distance =%d, low =%d occupy=%d \r\n", roi_distance, sts_low_threshold, sts_occupancy_threshold); + //fhmos_occupancy = STS_FHMOS_OCCUPANCY_NORMAL; + fhmos_data.state_occupancy = STS_FHMOS_OCCUPANCY_NORMAL; + if (fhmos_data.prev_occupancy != fhmos_data.state_occupancy) + { + sts_lamp_bar_color = STS_OCCUPY_COLOR; + } + + }else + { + fhmos_data.state_occupancy = STS_FHMOS_OCCUPANCY_NO_OCCUPY; + fhmos_fall_counter =0; + fhmos_data.state_human_movement =STS_FHMOS_HUMAN_MOVEMENT_NO_OCCUPY; + fhmos_data.state_fall = STS_FHMOS_FALL_STATE_NO_OCCUPY; + + if (fhmos_data.prev_occupancy != fhmos_data.state_occupancy) + sts_lamp_bar_color = STS_VACANT_COLOR; } - prev_occupy_state = sts_fhmos_data.occupancy_state; + + fhmos_data.prev_occupancy = fhmos_data.state_occupancy; @@ -682,10 +702,10 @@ static void print_result(RANGING_SENSOR_Result_t *Result) void STS_FHMOS_sensor_read(sts_fhmos_sensor_data_t *sts_data) { //uint8_t fhmos_fall=0, fhmos_human_movement=0, fhmos_occupancy=0, fhmos_sos_alarm=0; - sts_data->occupancy_state = sts_fhmos_data.occupancy_state|fhmos_occupancy; - sts_data->fall_state = sts_fhmos_data.fall_state|fhmos_fall; - sts_data->human_movement_state =sts_fhmos_data.human_movement_state|fhmos_human_movement; - sts_data->sos_alarm_state = sts_fhmos_data.sos_alarm_state|fhmos_sos_alarm; + sts_data->state_occupancy = fhmos_data.state_occupancy; + sts_data->state_fall = fhmos_data.state_fall; + sts_data->state_human_movement = fhmos_data.state_human_movement; + sts_data->state_sos_alarm = fhmos_data.state_sos_alarm; } diff --git a/hk_as923_decoder.js b/hk_as923_decoder.js index e463e1f..27fd380 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 R20241119A01 +// Yunhorn SmarToilets Sensor R20241126A01 // function Decode(fPort, data, variables) { @@ -848,7 +848,7 @@ function Decode(fPort, data, variables) { data.sts_verion = bytes[3]; data.sts_hw_ver = bytes[4]; data.battery_level = bytes[5]; - if ((bytes[6] === 0x04)) { // report sensor install height + 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"; @@ -862,7 +862,88 @@ function Decode(fPort, data, variables) { 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; + } + 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