diff --git a/.project b/.project deleted file mode 100644 index 0be5481..0000000 --- a/.project +++ /dev/null @@ -1,11 +0,0 @@ - - - STS_O7 - - - - - - - - diff --git a/Core/Inc/yunhorn_sts_prd_conf.h b/Core/Inc/yunhorn_sts_prd_conf.h index 868044e..feaa12e 100644 --- a/Core/Inc/yunhorn_sts_prd_conf.h +++ b/Core/Inc/yunhorn_sts_prd_conf.h @@ -245,9 +245,9 @@ #define STS_IOC_MODE_4_MASK STS_IOC_IN_0|STS_IOC_IN_1|STS_IOC_IN_2|STS_IOC_OUT_0|STS_IOC_OUT_1 //DUAL MODE #define STS_IOC_MODE_5_MASK STS_IOC_IN_ALL|STS_IOC_OUT_ALL //UNI_MODE -#define MajorVer 24U -#define MinorVer 8U -#define SubMinorVer 15U +#define MajorVer 25U +#define MinorVer 3U +#define SubMinorVer 25U #define FirmwareVersion 3U #define YUNHORN_STS_MAX_NVM_CFG_SIZE 64U diff --git a/Core/Inc/yunhorn_sts_sensors.h b/Core/Inc/yunhorn_sts_sensors.h index e5fc084..9fc374a 100644 --- a/Core/Inc/yunhorn_sts_sensors.h +++ b/Core/Inc/yunhorn_sts_sensors.h @@ -64,12 +64,12 @@ enum p_cmd_order{ }; enum RSS_CFG_order{ - // FOR SIMPLE CONFIG .... 8 BYTES + // FOR SIMPLE CONFIG .... 4 BYTES RSS_CFG_START_M=0, RSS_CFG_LENGTH_M, RSS_CFG_THRESHOLD, RSS_CFG_RECEIVER_GAIN, - // FOR SIMPLE CONFIG .... 8 BYTES + // FOR SIMPLE CONFIG .... 4 BYTES RSS_CFG_PROFILE, RSS_CFG_RATE_TRACKING, RSS_CFG_RATE_PRESENCE, diff --git a/Core/Src/yunhorn_sts_presence_rss.c b/Core/Src/yunhorn_sts_presence_rss.c index 8a1d8e9..f87ca46 100644 --- a/Core/Src/yunhorn_sts_presence_rss.c +++ b/Core/Src/yunhorn_sts_presence_rss.c @@ -52,7 +52,7 @@ #define DEFAULT_DETECTION_THRESHOLD (2.0f) #define DEFAULT_NBR_REMOVED_PC_2 (0) -#define DEFAULT_PROFILE ACC_SERVICE_PROFILE_2 //ACC_SERVICE_PROFILE_4 +#define DEFAULT_PROFILE ACC_SERVICE_PROFILE_4 //ACC_SERVICE_PROFILE_4 #define DEFAULT_UPDATE_RATE (10) #define DEFAULT_POWER_SAVE_MODE ACC_POWER_SAVE_MODE_ACTIVE #define DEFAULT_SENSOR_ID (1) @@ -302,6 +302,14 @@ static void sts_rss_set_current_configuration_full(acc_detector_presence_configu static void sts_rss_set_current_configuration_simple(acc_detector_presence_configuration_t presence_configuration) { + APP_LOG(TS_OFF, VLEVEL_M, "\r\nsts_rss_cfg-start: %4d ,length: %4d ,threshold: %4d ,gain: %2d ,rate: %2d ,profile: %1d \r\n", + (int)(sts_presence_rss_config.default_start_m*1000), + (int)(sts_presence_rss_config.default_length_m*1000), + (int)(sts_presence_rss_config.default_threshold*1000), + (int)(sts_presence_rss_config.default_receiver_gain*100), + (int)(sts_presence_rss_config.default_update_rate_presence), + (int)(sts_presence_rss_config.default_profile)); + acc_detector_presence_configuration_sensor_set(presence_configuration, DEFAULT_SENSOR_ID); //acc_detector_presence_configuration_update_rate_set(presence_configuration, DEFAULT_UPDATE_RATE_PRESENCE); 2024-08-21 update @@ -310,10 +318,38 @@ static void sts_rss_set_current_configuration_simple(acc_detector_presence_confi acc_detector_presence_configuration_length_set(presence_configuration, sts_presence_rss_config.default_length_m); //DEFAULT_LENGTH_M_2); acc_detector_presence_configuration_detection_threshold_set(presence_configuration, sts_presence_rss_config.default_threshold);//DEFAULT_DETECTION_THRESHOLD_2); acc_detector_presence_configuration_receiver_gain_set(presence_configuration, sts_presence_rss_config.default_receiver_gain); + acc_detector_presence_configuration_service_profile_set(presence_configuration, sts_presence_rss_config.default_profile); } +static void print_current_configuration(acc_detector_presence_configuration_t presence_configuration) +{ + float sts_run_start = acc_detector_presence_configuration_start_get(presence_configuration); + float sts_run_length = acc_detector_presence_configuration_length_get(presence_configuration); + float sts_run_threshold = acc_detector_presence_configuration_detection_threshold_get(presence_configuration); + float sts_run_gain = acc_detector_presence_configuration_receiver_gain_get(presence_configuration); + float sts_run_update_rate = acc_detector_presence_configuration_update_rate_get(presence_configuration); + float sts_run_profile = acc_detector_presence_configuration_service_profile_get(presence_configuration); + acc_detector_presence_configuration_filter_parameters_t sts_run_filter = acc_detector_presence_configuration_filter_parameters_get(presence_configuration); + + float sts_run_f_inter_fast_cutoff = sts_run_filter.inter_frame_fast_cutoff; + float sts_run_f_inter_slow_cutoff = sts_run_filter.inter_frame_slow_cutoff; + float sts_run_f_inter_frame_dev_time_const = sts_run_filter.inter_frame_deviation_time_const; + + float sts_run_f_intra_frame_time_const = sts_run_filter.intra_frame_time_const; + float sts_run_f_intra_frame_weight = sts_run_filter.intra_frame_weight; + float sts_run_f_output_time_const = sts_run_filter.output_time_const; + + APP_LOG(TS_OFF, VLEVEL_M, "\r\nStart: %4d (mm) Length: %4d (mm) Threshold: %4d (*) Gain= %2d (%) UpdateRate=%2d Profile= %1d \r\n", + (int)(1000.0*sts_run_start), (int)(1000.0*sts_run_length), (int)(1000.0*sts_run_threshold), (int)(100.0*sts_run_gain),(int)sts_run_update_rate, (int)sts_run_profile); + + APP_LOG(TS_OFF, VLEVEL_H, "\rn\n(1)FastCut:%4u (2)SlowCut:%4u (3)InterFrameDevTime:%4u " + "(4)IntraFrameTimeConst:%4d (5)IntraWeight:%4u (5)OutputTime:%4u \r\n", + (int)(1000.0*sts_run_f_inter_fast_cutoff), (int)(1000*sts_run_f_inter_slow_cutoff), (int)(1000*sts_run_f_inter_frame_dev_time_const), + (int)(1000*sts_run_f_intra_frame_time_const),(int)(1000*sts_run_f_intra_frame_weight),(int)(1000*sts_run_f_output_time_const)); + +} static void print_result(acc_detector_presence_result_t result) { if (result.presence_detected) @@ -378,12 +414,15 @@ int sts_presence_rss_fall_rise_detection(void) set_default_fall_rise_configuration(presence_configuration); APP_LOG(TS_OFF, VLEVEL_H,"\r\n######### YUNHORN STS *** FALL DETECTION *** cfg applied\n"); break; +#if 1 case STS_RSS_CONFIG_DEFAULT|STS_RSS_CONFIG_SIMPLE: set_default_configuration(presence_configuration); APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Default *** cfg applied\n"); sts_rss_set_current_configuration_simple(presence_configuration); APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Simple *** cfg applied\n"); break; +#endif + case STS_RSS_CONFIG_DEFAULT|STS_RSS_CONFIG_FULL: set_default_configuration(presence_configuration); APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Default *** cfg applied\n"); @@ -416,6 +455,12 @@ int sts_presence_rss_fall_rise_detection(void) acc_rss_deactivate(); return EXIT_FAILURE; } + + + print_current_configuration(presence_configuration); + + acc_detector_presence_configuration_destroy(&presence_configuration); + // BEFORE MERGE FIRST AND SECOND HALF FALL RISE DETECTION if (!acc_detector_presence_activate(handle)) @@ -490,7 +535,7 @@ int sts_presence_rss_fall_rise_detection(void) //acc_integration_sleep_ms(1000 / DEFAULT_UPDATE_RATE_PRESENCE); // 15ms, DEFAULT_UPDATE_RATE); //acc_integration_sleep_ms(10); // --- around 1500 ms in total - acc_integration_sleep_ms(2); //--- around 1000ms in total + acc_integration_sleep_ms(5); //--- around 1000ms in total } deactivated = acc_detector_presence_deactivate(handle); @@ -578,7 +623,7 @@ int sts_presence_rss_fall_rise_detection(void) // ~12 ms per RSS scan // acc_integration_sleep_ms(1000 / DEFAULT_UPDATE_RATE_PRESENCE); // 15 ms, DEFAULT_UPDATE_RATE); //acc_integration_sleep_ms(10); //--- around 1500 ms in total - acc_integration_sleep_ms(2); //--- around 1000ms in total + acc_integration_sleep_ms(5); //--- around 1000ms in total } deactivated = acc_detector_presence_deactivate(handle); acc_detector_presence_destroy(&handle); @@ -606,8 +651,10 @@ int sts_presence_rss_fall_rise_detection(void) sts_presence_rss_distance = average_distance; sts_presence_rss_score = average_score; - uint8_t pre_sts_rss_result = (average_result > (DEFAULT_UPDATE_RATE_PRESENCE/20))? 1: 0; - sts_rss_result=STS_RSS_Filter(pre_sts_rss_result); + // uint8_t pre_sts_rss_result = (average_result > (DEFAULT_UPDATE_RATE_PRESENCE/5))? 1: 0; + // sts_rss_result=STS_RSS_Filter(pre_sts_rss_result); + + sts_rss_result = (average_result > (DEFAULT_UPDATE_RATE_PRESENCE/5))? 1: 0; if (sts_rss_result) //if (average_score !=0) //if (sts_rss_result) { @@ -681,7 +728,7 @@ int sts_presence_rss_fall_rise_detection(void) if (deactivated && success) { - //APP_LOG(TS_OFF, VLEVEL_M,"Application finished OK\n"); + APP_LOG(TS_OFF, VLEVEL_H,"Application finished OK\n"); return EXIT_SUCCESS; } diff --git a/Core/Src/yunhorn_sts_process.c b/Core/Src/yunhorn_sts_process.c index 34cda68..f2f2987 100644 --- a/Core/Src/yunhorn_sts_process.c +++ b/Core/Src/yunhorn_sts_process.c @@ -287,25 +287,28 @@ void STS_YunhornSTSEventP2_Process(void) break; } - sts_presence_rss_fall_rise_detection(); + int res = sts_presence_rss_fall_rise_detection(); + if (res == 0) + { - sts_rss_result_changed_flag = (sts_rss_result == last_sts_rss_result)? 0:1; + sts_rss_result_changed_flag = (sts_rss_result == last_sts_rss_result)? 0:1; - last_sts_rss_result = sts_rss_result; + last_sts_rss_result = sts_rss_result; - //sts_fall_rising_detected_result_changed_flag = (sts_fall_rising_detected_result == last_sts_fall_rising_detected_result)?0:1; - //sts_fall_rising_detected_result_changed_flag = (sts_fall_rising_detected_result != last_sts_fall_rising_detected_result)?1:0; + //sts_fall_rising_detected_result_changed_flag = (sts_fall_rising_detected_result == last_sts_fall_rising_detected_result)?0:1; + //sts_fall_rising_detected_result_changed_flag = (sts_fall_rising_detected_result != last_sts_fall_rising_detected_result)?1:0; - last_sts_fall_rising_detected_result = sts_fall_rising_detected_result; + last_sts_fall_rising_detected_result = sts_fall_rising_detected_result; - if (sts_service_mask > 0 ) { - sts_rss_result_changed_flag =0; - sts_reed_hall_changed_flag = 0; - sts_fall_rising_detected_result_changed_flag =0; - } + if (sts_service_mask > 0 ) { + sts_rss_result_changed_flag =0; + sts_reed_hall_changed_flag = 0; + sts_fall_rising_detected_result_changed_flag =0; + } - STS_Combined_Status_Processing(); + STS_Combined_Status_Processing(); + } else APP_LOG(TS_OFF, VLEVEL_H, "\r\n RSS detection error =%d \r\n", res); } } @@ -721,6 +724,14 @@ void STS_PRESENCE_SENSOR_NVM_CFG_SIMPLE(void) sts_presence_rss_config.default_threshold = (float)(sts_cfg_nvm.p[RSS_CFG_THRESHOLD]*0.1f); sts_presence_rss_config.default_receiver_gain = (float)(sts_cfg_nvm.p[RSS_CFG_RECEIVER_GAIN]*0.01f); + sts_presence_rss_config.default_zone_length_m = DEFAULT_ZONE_LENGTH; + sts_presence_rss_config.default_profile = (float)(sts_cfg_nvm.p[RSS_CFG_PROFILE]); + sts_presence_rss_config.default_update_rate_tracking = (float)(sts_cfg_nvm.p[RSS_CFG_RATE_TRACKING]); + sts_presence_rss_config.default_update_rate_presence = (float)(sts_cfg_nvm.p[RSS_CFG_RATE_PRESENCE]); + sts_presence_rss_config.default_hwaas = (float)(sts_cfg_nvm.p[RSS_CFG_HWAAS]); + + sts_presence_rss_config.default_nbr_removed_pc = (float)(sts_cfg_nvm.p[RSS_CFG_NBR_REMOVED_PC]); + sts_rss_config_updated_flag = (sts_rss_config_updated_flag|STS_RSS_CONFIG_SIMPLE); //set to 1 for simple config effect in next detection } diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 2c1a76f..847854d 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -2567,7 +2567,8 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, uint8_t tlv_buf_size) sts_cfg_nvm.p[RSS_CFG_THRESHOLD] = (uint8_t)((tlv_buf[CFG_CMD8] - 0x30)*10+(tlv_buf[CFG_CMD9] - 0x30)); sts_cfg_nvm.p[RSS_CFG_RECEIVER_GAIN] = (uint8_t)((tlv_buf[CFG_CMD10]- 0x30)*10+(tlv_buf[CFG_CMD11]- 0x30)); - + APP_LOG(TS_OFF, VLEVEL_H,"\r\nStart,Lenght,threshold,gain=%02x %02x %02x %02x \r\n", + sts_cfg_nvm.p[RSS_CFG_START_M],sts_cfg_nvm.p[RSS_CFG_LENGTH_M],sts_cfg_nvm.p[RSS_CFG_THRESHOLD],sts_cfg_nvm.p[RSS_CFG_RECEIVER_GAIN]); STS_PRESENCE_SENSOR_NVM_CFG_SIMPLE(); i=0; // Step 1: Prepare status update message diff --git a/STM32CubeIDE/.cproject b/STM32CubeIDE/.cproject index 93edae5..aac35da 100644 --- a/STM32CubeIDE/.cproject +++ b/STM32CubeIDE/.cproject @@ -135,7 +135,7 @@