diff --git a/Core/Src/yunhorn_sts_distance_rss.c b/Core/Src/yunhorn_sts_distance_rss.c index 14cec96..db72398 100644 --- a/Core/Src/yunhorn_sts_distance_rss.c +++ b/Core/Src/yunhorn_sts_distance_rss.c @@ -57,8 +57,8 @@ // GOOD --- volatile distance_measure_cfg_t distance_cfg={0.4, 3.5, 4, 63, 0, 10, 0.5, 1.3, 0.2}; // 2024-08-15 volatile distance_measure_cfg_t distance_cfg={0.8, 3.5, 2, 63, 2, 10, 0.5, 1.3, 0.2}; //volatile distance_measure_cfg_t distance_cfg={0.8, 3.5, 4, 63, 2, 10, 0.5, 1.3, 0.2}; -volatile distance_measure_cfg_t distance_cfg ={0.8, 3.5, 4, 63, 2, 10, 0.4, 1.2, 0.2}; -volatile distance_measure_cfg_t presence_distance_cfg ={0.8, 3.5, 4, 63, 2, 10, 0.4, 1.2, 0.2}; +volatile distance_measure_cfg_t distance_cfg = {0.8, 3.5, 2, 63, 2, 10.0, 0.4, 1.2, 0.2}; +volatile distance_measure_cfg_t presence_distance_cfg = {0.8, 3.5, 4, 63, 2, 10.0, 0.4, 1.2, 0.2}; //volatile distance_measure_cfg_t distance_cfg={1.5, 3.3, 2, 63, 4, 10, 0.8182f, 0.4, 0.2}; extern volatile uint16_t sts_distance_rss_distance, sts_sensor_install_height; extern volatile uint8_t sts_presence_distance_flag; diff --git a/Core/Src/yunhorn_sts_presence_rss.c b/Core/Src/yunhorn_sts_presence_rss.c index a50cb19..6e033ce 100644 --- a/Core/Src/yunhorn_sts_presence_rss.c +++ b/Core/Src/yunhorn_sts_presence_rss.c @@ -541,35 +541,7 @@ int sts_presence_rss_background_evaluation_process(uint16_t *evaluated_distance, int sts_presence_rss_fall_rise_detection(void) { -#if 0 - uint8_t exit_status = EXIT_SUCCESS, i=0; - //do - //{ - sts_presence_distance_flag = 1; - presence_distance_cfg.start_m = sts_presence_rss_config.default_start_m; - presence_distance_cfg.length_m = sts_presence_rss_config.default_length_m; - LED1_TOGGLE; - exit_status = sts_distance_rss_detector_distance(); - sts_presence_distance_flag = 0; - // HAL_Delay(10); - // i++; - //} while ((exit_status == EXIT_FAILURE) && (i < 1)); - if (exit_status == EXIT_FAILURE) - { - APP_LOG(TS_OFF, VLEVEL_M,"\r\nFailed to Get Distance \n"); - } - else - { - if ((sts_distance_rss_distance < 1000.0*(presence_distance_cfg.start_m + presence_distance_cfg.length_m)) && (sts_distance_rss_distance > 1000.0*presence_distance_cfg.length_m )) - { - sts_distance_presence_in_window = 1; - } else { - sts_distance_presence_in_window = 0; - } - } - LED1_TOGGLE; -#endif const acc_hal_t *hal = acc_hal_integration_get_implementation(); if (!acc_rss_activate(hal)) @@ -581,7 +553,7 @@ int sts_presence_rss_fall_rise_detection(void) acc_rss_override_sensor_id_check_at_creation(true); //+++++++++++++++++++++++++++++++++++ -#if 0 +//#if 0 acc_detector_distance_configuration_t distance_configuration = acc_detector_distance_configuration_create(); if (distance_configuration == NULL) @@ -593,7 +565,8 @@ int sts_presence_rss_fall_rise_detection(void) //if (sts_presence_distance_flag == 1) { - APP_LOG(TS_OFF, VLEVEL_M, "\r\n RSS CFG start: %4d Length:%4d \r\n", (int)(1000.0*sts_presence_rss_config.default_start_m), (int)(1000.0*sts_presence_rss_config.default_length_m)); + APP_LOG(TS_OFF, VLEVEL_M, + "|RSS start: %4d Length:%4d |", (int)(1000.0*sts_presence_rss_config.default_start_m), (int)(1000.0*sts_presence_rss_config.default_length_m)); presence_distance_cfg.start_m = sts_presence_rss_config.default_start_m; presence_distance_cfg.length_m = sts_presence_rss_config.default_length_m; @@ -622,7 +595,7 @@ int sts_presence_rss_fall_rise_detection(void) return EXIT_FAILURE; } #endif -#endif +//#endif //+++++++++++++++++++++++++++++++++++ acc_detector_presence_configuration_t presence_configuration = acc_detector_presence_configuration_create(); @@ -697,14 +670,78 @@ int sts_presence_rss_fall_rise_detection(void) acc_rss_deactivate(); return EXIT_FAILURE; } - - APP_LOG(TS_OFF, VLEVEL_H,"\r\n============= Start Scan\n"); - print_current_configuration(presence_configuration); - acc_detector_presence_configuration_destroy(&presence_configuration); + // ++++++++++++++++++++++++++++++++++++++ +#if 1 + + if (!acc_detector_distance_activate(distance_handle)) + { + APP_LOG(TS_OFF, VLEVEL_L, "acc_detector_distance_activate() failed\n"); + acc_detector_distance_destroy(&distance_handle); + acc_rss_deactivate(); + return EXIT_FAILURE; + } + + + bool success_d = true; + const int iterations_d = 1; //5; + uint16_t number_of_peaks_d = 5; // FSB first significant Bin + acc_detector_distance_result_t dresult[number_of_peaks_d]; + acc_detector_distance_result_info_t dresult_info; + float tmp_distance = 0.0f; + uint16_t tmp_num_of_peaks = 0; + + for (int i = 0; i < iterations_d; i++) + { + success_d = acc_detector_distance_get_next(distance_handle, dresult, number_of_peaks_d, &dresult_info); + + if (!success_d) + { + APP_LOG(TS_OFF, VLEVEL_L, "acc_detector_distance_get_next() failed\n"); + break; + } + for(uint8_t j=0; j< dresult_info.number_of_peaks; j++) + { + tmp_distance = tmp_distance + (dresult[j].distance_m); //KalmanFilter(result[j].distance_m); + } + tmp_num_of_peaks += dresult_info.number_of_peaks; + //print_distances(result, result_info.number_of_peaks); + } + + + // ensure it's a valid installation height + //sts_sensor_install_height = (uint16_t)MAX(sts_distance_rss_distance,2000); + //sts_distance_rss_distance = (uint16_t)(1000*tmp_distance)/(number_of_peaks*iterations); + sts_distance_rss_distance = (uint16_t)(1000*tmp_distance)/(tmp_num_of_peaks); + //sts_distance_rss_distance_peak = result_info.number_of_peaks; + sts_distance_rss_distance_peak = tmp_num_of_peaks/iterations_d; + + if (sts_presence_distance_flag == 1) + { + APP_LOG(TS_OFF, VLEVEL_M, "|AveDist=%u mm Peak: %d |", (uint16_t)sts_distance_rss_distance, sts_distance_rss_distance_peak); + + } else + { + sts_sensor_install_height = (uint16_t)sts_distance_rss_distance; + APP_LOG(TS_OFF, VLEVEL_H, "\r\nAssume Sensor Install Height = %u mm\r\n", (uint16_t)sts_sensor_install_height); + } + + bool ddeactivated = acc_detector_distance_deactivate(distance_handle); + + acc_detector_distance_destroy(&distance_handle); + presence_distance_cfg.start_m = sts_presence_rss_config.default_start_m; + presence_distance_cfg.length_m = sts_presence_rss_config.default_length_m; + + if ((sts_distance_rss_distance) < (sts_presence_rss_config.default_start_m + sts_presence_rss_config.default_length_m - 0.5)*1000.0f) + sts_distance_presence_in_window = 1; + else + sts_distance_presence_in_window = 0; +#endif + // ++++++++++++++++++++++++++++++++++++++ + // BEFORE MERGE FIRST AND SECOND HALF FALL RISE DETECTION if (!acc_detector_presence_activate(handle)) @@ -714,7 +751,7 @@ int sts_presence_rss_fall_rise_detection(void) } bool deactivated = false; bool success = true; - const int iterations = (DEFAULT_UPDATE_RATE_PRESENCE+1); + const int iterations = 20; //(DEFAULT_UPDATE_RATE_PRESENCE); acc_detector_presence_result_t result; uint8_t average_result = 0; float average_distance =0.0f; @@ -779,73 +816,13 @@ 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(10); //--- around 1000ms in total } deactivated = acc_detector_presence_deactivate(handle); acc_detector_presence_destroy(&handle); - // ++++++++++++++++++++++++++++++++++++++ -#if 0 - if (!acc_detector_distance_activate(distance_handle)) - { - APP_LOG(TS_OFF, VLEVEL_L, "acc_detector_distance_activate() failed\n"); - acc_detector_distance_destroy(&distance_handle); - acc_rss_deactivate(); - return EXIT_FAILURE; - } - - - bool success = true; - const int iterations = 1; //5; - uint16_t number_of_peaks = 5; // FSB first significant Bin - acc_detector_distance_result_t result[number_of_peaks]; - acc_detector_distance_result_info_t result_info; - float tmp_distance = 0.0f; - uint16_t tmp_num_of_peaks = 0; - - for (int i = 0; i < iterations; i++) - { - success = acc_detector_distance_get_next(distance_handle, result, number_of_peaks, &result_info); - - if (!success) - { - APP_LOG(TS_OFF, VLEVEL_L, "acc_detector_distance_get_next() failed\n"); - break; - } - for(uint8_t j=0; j< result_info.number_of_peaks; j++) - { - tmp_distance = tmp_distance + (result[j].distance_m); //KalmanFilter(result[j].distance_m); - } - tmp_num_of_peaks += result_info.number_of_peaks; - //print_distances(result, result_info.number_of_peaks); - } - - - // ensure it's a valid installation height - //sts_sensor_install_height = (uint16_t)MAX(sts_distance_rss_distance,2000); - //sts_distance_rss_distance = (uint16_t)(1000*tmp_distance)/(number_of_peaks*iterations); - sts_distance_rss_distance = (uint16_t)(1000*tmp_distance)/(tmp_num_of_peaks); - //sts_distance_rss_distance_peak = result_info.number_of_peaks; - sts_distance_rss_distance_peak = tmp_num_of_peaks/iterations; - - if (sts_presence_distance_flag == 1) - { - APP_LOG(TS_OFF, VLEVEL_M, "\r\nAverage Distance =%u mm Peak:%d\r\n", (uint16_t)sts_distance_rss_distance, sts_distance_rss_distance_peak); - - } else - { - sts_sensor_install_height = (uint16_t)sts_distance_rss_distance; - APP_LOG(TS_OFF, VLEVEL_H, "\r\nAssume Sensor Install Height = %u mm\r\n", (uint16_t)sts_sensor_install_height); - } - - bool deactivated = acc_detector_distance_deactivate(distance_handle); - - acc_detector_distance_destroy(&distance_handle); - -#endif - // ++++++++++++++++++++++++++++++++++++++ @@ -1281,20 +1258,8 @@ static void sts_distance_rss_update_presence_config(acc_detector_distance_config #define DEFAULT_FAR_RANGE_MUR ACC_SERVICE_MUR_6 #define DEFAULT_FAR_RANGE_SERVICE_PROFILE ACC_SERVICE_PROFILE_2 #define DEFAULT_FAR_MAXIMIZE_SIGNAL_ATTENUATION false -#define STS_DISTANCE_START_M (0.8f) -#define STS_DISTANCE_LENGTH_M (1.4f) -#define STS_DISTANCE_PROFILE ACC_SERVICE_PROFILE_2 -#define STS_DISTANCE_HWAAS (63) #define DEFAULT_FAR_RANGE_CFAR_THRESHOLD_GUARD 0.12f #define DEFAULT_FAR_RANGE_CFAR_THRESHOLD_WINDOW 0.03f -#ifndef MIN -#define MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) ) -#endif - -#ifndef MAX -#define MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) ) -#endif - acc_detector_distance_configuration_mur_set(distance_configuration, DEFAULT_FAR_RANGE_MUR); // NEW ADD acc_detector_distance_configuration_requested_start_set(distance_configuration, presence_distance_cfg.start_m); diff --git a/LoRaWAN/App/app_lorawan.c b/LoRaWAN/App/app_lorawan.c index 0317ebe..1bc3e68 100644 --- a/LoRaWAN/App/app_lorawan.c +++ b/LoRaWAN/App/app_lorawan.c @@ -69,10 +69,11 @@ void MX_LoRaWAN_Init(void) /* USER CODE END MX_LoRaWAN_Init_1 */ SystemApp_Init(); /* USER CODE BEGIN MX_LoRaWAN_Init_2 */ - //STS_Lamp_Bar_Self_Test_Simple(); - STS_Lamp_Bar_Self_Test(); + STS_Lamp_Bar_Self_Test_Simple(); + //STS_Lamp_Bar_Self_Test(); /* USER CODE END MX_LoRaWAN_Init_2 */ LoRaWAN_Init(); + /* USER CODE BEGIN MX_LoRaWAN_Init_3 */ /* USER CODE END MX_LoRaWAN_Init_3 */ diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index a02a283..542dcb1 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -75,7 +75,7 @@ extern volatile uint32_t event_start_time, event_stop_time; extern volatile uint16_t sts_unconscious_threshold; volatile uint8_t sts_occupancy_overtime_state = 0; volatile uint8_t sts_presence_fall_detection=FALSE; -volatile uint32_t SamplingPeriodicity = 1000; //unit ms +volatile uint32_t SamplingPeriodicity = 3000; //unit ms volatile uint32_t HeartBeatPeriodicity = 120000; //unit ms volatile uint8_t STS_LoRa_WAN_Joined = 0; @@ -1179,8 +1179,8 @@ static void SendTxData(void) static void OnTxTimerEvent(void *context) { /* USER CODE BEGIN OnTxTimerEvent_1 */ - - if (sts_warm_up_count < 5) + UTIL_TIMER_Stop(&TxTimer); + if (sts_warm_up_count < 10) { /* USER CODE END OnTxTimerEvent_1 */ //if ((sensor_data_ready ==1)) //|| (sts_reed_hall_changed_flag)) //||(sts_rss_result_changed_flag)||(sts_fall_rising_detected_result_changed_flag)) diff --git a/STM32CubeIDE/Release/STS_O7.bin b/STM32CubeIDE/Release/STS_O7.bin index 0cca4c4..d85e630 100644 Binary files a/STM32CubeIDE/Release/STS_O7.bin and b/STM32CubeIDE/Release/STS_O7.bin differ