bad wip... park here

This commit is contained in:
Yunhorn 2025-04-28 11:58:15 +08:00
parent 7dd5e395ec
commit 96c0075a51
8 changed files with 349 additions and 73 deletions

View File

@ -742,9 +742,11 @@ void STS_SENSOR_Upload_Message(uint8_t appDataPort, uint8_t appBufferSize, uint8
void STS_SENSOR_Auto_Responder_Process(uint8_t tlv_ver,uint8_t tlv_type, uint8_t tlv_length, uint8_t *tlv_content);
uint8_t STS_SENSOR_MEMS_Get_ID(uint8_t *devID);
int sts_presence_rss_presence_detection(void);
int sts_presence_rss_fall_rise_detection(void);
int sts_presence_rss_fall_rise_detection_start(void);
int sts_presence_rss_fall_rise_detection_loop(void);
int sts_presence_rss_fall_rise_detection_end(void);
int sts_distance_rss_detector_distance(void);
int acc_example_detector_distance(int argc, char *argv[]);
int acc_example_service_sparse(int argc, char *argv[]);

View File

@ -40,7 +40,7 @@ extern SPI_HandleTypeDef A111_SPI_HANDLE;
* @brief Size of SPI transfer buffer
*/
#ifndef A111_SPI_MAX_TRANSFER_SIZE
#define A111_SPI_MAX_TRANSFER_SIZE 65535 //4096 //65535
#define A111_SPI_MAX_TRANSFER_SIZE 4096//65535 //4096 //65535
#endif
/**

View File

@ -96,10 +96,32 @@ int main(void)
MX_LoRaWAN_Init();
/* USER CODE BEGIN 2 */
STS_Sensor_Init();
int ret=0;
while(1)
{
sts_presence_rss_fall_rise_detection_start();
do
{
ret = sts_presence_rss_fall_rise_detection_loop();
} while(!ret);
sts_presence_rss_fall_rise_detection_end();
LED1_TOGGLE;
HAL_Delay(1000);
}
/* USER CODE BEGIN 2 */
//STS_Sensor_Init();
/* USER CODE END 2 */
STS_Sensor_Prepare();
//STS_Sensor_Prepare();
STS_SENSOR_Function_Test_Process();
/* Infinite loop */
/* USER CODE BEGIN WHILE */

View File

@ -41,7 +41,7 @@ void MX_USART2_UART_Init(void)
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.BaudRate = 460800;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;

View File

@ -65,25 +65,25 @@
#define DEFAULT_UPDATE_RATE_PRESENCE (65.0F) //(65.0f) //default 80 unit(hz)
//#define DEFAULT_UPDATE_RATE_PRESENCE (80.0F) //(65.0f) //default 80 unit(hz)
#define DEFAULT_SWEEPS_PER_FRAME (16.0F) // sweeps_per_frame
#define DEFAULT_HWAAS (63) //default 10 unit(hz)
#define DEFAULT_THRESHOLD (1.2f) //default 1.5 level float [3]
//acc_detector_presence_configuration_filter_parameters_t
#define DEFAULT_INTER_FRAME_DEVIATION_TIME_CONST (0.5f) //default 0.5 unit(seconds) [6]
#define DEFAULT_INTER_FRAME_FAST_CUTOFF (10.0f) //default 20.0 unit(hz) [8]
#define DEFAULT_INTER_FRAME_SLOW_CUTOFF (0.01f) //(0.01f) 0.2 hz unit(hz) [9]
#define DEFAULT_INTER_FRAME_FAST_CUTOFF (18.0f) // (10.0f) //default 20.0 unit(hz) [8]
#define DEFAULT_INTER_FRAME_SLOW_CUTOFF (0.17f) // (0.01f) //(0.01f) 0.2 hz unit(hz) [9]
#define DEFAULT_INTRA_FRAME_TIME_CONST (0) //default 0.0 unit(seconds)
#define DEFAULT_INTRA_FRAME_WEIGHT (0) //default 0.6 for normal slow tracking 1.0 for fast tracking
// 2025 03 26 *** if detection toggles too often, increase the following, if too sluggish, decrease it instead
//#define DEFAULT_OUTPUT_TIME_CONST (0.8f) //default 0.5 unit(seconds) [5]
#define DEFAULT_OUTPUT_TIME_CONST (0.5f) //default 0.5 unit(seconds) [5]
#define DEFAULT_OUTPUT_TIME_CONST (0.2f) // (0.5f) //default 0.5 unit(seconds) [5]
//#define DEFAULT_OUTPUT_TIME_CONST (0.4f) //default 0.5 unit(seconds) [5]
#define DEFAULT_NBR_REMOVED_PC (0) //default 0 int [10]
#define DEFAULT_DOWNSAMPLING_FACTOR (2) //default 1
#define DEFAULT_DOWNSAMPLING_FACTOR (1) // (2) 20250427 //default 1
//#define DEFAULT_RECEIVER_GAIN (0.65f) //default 0.9 gain mdB [4]
#define DEFAULT_RECEIVER_GAIN (0.65f) //default 0.9 gain mdB [4]
@ -149,8 +149,14 @@ volatile uint16_t sts_fall_rising_pattern_factor1=0, sts_fall_rising_pattern_fac
volatile uint16_t sts_roc_acc_standard_variance=0;
extern volatile uint8_t sts_presence_fall_detection;
static uint8_t sts_rss_init_ok=0;
volatile uint8_t sts_presence_singularity=1;
volatile uint8_t sts_presence_singularity=0;
volatile uint16_t sts_rss_threshold;
extern uint8_t sts_lamp_bar_color;
volatile acc_detector_presence_handle_t handle;
volatile acc_detector_presence_result_t result;
volatile acc_detector_presence_configuration_t presence_configuration;
bool success;
uint16_t sweeps_per_frame=16;
/* USER CODE END Includes */
/* External variables ---------------------------------------------------------*/
@ -198,8 +204,14 @@ extern uint8_t sts_lamp_bar_color;
static void set_default_configuration_common(acc_detector_presence_configuration_t presence_configuration)
{
acc_detector_presence_configuration_update_rate_set(presence_configuration, sts_presence_rss_config.default_update_rate_presence);
//acc_detector_presence_configuration_update_rate_set(presence_configuration, sts_presence_rss_config.default_update_rate_presence);
acc_detector_presence_configuration_update_rate_set(presence_configuration, 5);
acc_detector_presence_configuration_downsampling_factor_set(presence_configuration, sts_presence_rss_config.default_downsampling_factor);
acc_detector_presence_configuration_hw_accelerated_average_samples_set(presence_configuration, DEFAULT_HWAAS);
uint16_t sweeps_per_frame=16;
sweeps_per_frame = acc_detector_presence_configuration_sweeps_per_frame_get(presence_configuration);
acc_detector_presence_configuration_sweeps_per_frame_set(presence_configuration, sweeps_per_frame);
acc_detector_presence_configuration_filter_parameters_t filter = acc_detector_presence_configuration_filter_parameters_get(presence_configuration);
filter.inter_frame_deviation_time_const = DEFAULT_INTER_FRAME_DEVIATION_TIME_CONST;
@ -207,7 +219,7 @@ static void set_default_configuration_common(acc_detector_presence_configuration
// will be disabled if this value > 1/2 of update rate, default update rate 65, so must < 30
filter.inter_frame_fast_cutoff = DEFAULT_INTER_FRAME_FAST_CUTOFF;
filter.inter_frame_slow_cutoff = DEFAULT_INTER_FRAME_SLOW_CUTOFF;
#if 0
// no effect if intra-frame-weight set to 0
filter.intra_frame_time_const = DEFAULT_INTRA_FRAME_TIME_CONST;
// for slow movement, people sit still, rest in sofa, seat, closestool, etc.
@ -216,8 +228,14 @@ static void set_default_configuration_common(acc_detector_presence_configuration
// if detection toggles too often, increase the following, if too sluggish, decrease it instead
filter.output_time_const = DEFAULT_OUTPUT_TIME_CONST; //0.0f;
#endif
acc_detector_presence_configuration_filter_parameters_set(presence_configuration, &filter);
#if 0
acc_detector_presence_configuration_nbr_removed_pc_set(presence_configuration, DEFAULT_NBR_REMOVED_PC);
#endif
acc_detector_presence_configuration_power_save_mode_set(presence_configuration, ACC_POWER_SAVE_MODE_ACTIVE);
@ -230,13 +248,14 @@ static void set_default_configuration(acc_detector_presence_configuration_t pres
acc_detector_presence_configuration_detection_threshold_set(presence_configuration, DEFAULT_THRESHOLD);
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//acc_service_sparse_configuration_sweeps_per_frame_set(sparse_configuration, sweeps_per_frame);
//acc_service_sparse_configuration_sweeps_per_frame_set(sparse_configuration, DEFAULT_SWEEPS_PER_FRAME);
acc_detector_presence_configuration_start_set(presence_configuration, DEFAULT_START_M);
acc_detector_presence_configuration_length_set(presence_configuration, DEFAULT_LENGTH_M);
acc_detector_presence_configuration_downsampling_factor_set(presence_configuration, DEFAULT_DOWNSAMPLING_FACTOR);
acc_detector_presence_configuration_receiver_gain_set(presence_configuration, DEFAULT_RECEIVER_GAIN);
set_default_configuration_common(presence_configuration);
//set_default_configuration_common(presence_configuration);
// by set_default_configuration_common
#if 0
@ -276,6 +295,8 @@ static void set_default_fall_rise_configuration(acc_detector_presence_configurat
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//acc_service_sparse_configuration_sweeps_per_frame_set(sparse_configuration, sweeps_per_frame);
acc_detector_presence_configuration_sweeps_per_frame_set(presence_configuration, DEFAULT_SWEEPS_PER_FRAME);
acc_detector_presence_configuration_start_set(presence_configuration, DEFAULT_START_M);
acc_detector_presence_configuration_length_set(presence_configuration, DEFAULT_LENGTH_M);
acc_detector_presence_configuration_downsampling_factor_set(presence_configuration, DEFAULT_DOWNSAMPLING_FACTOR);
@ -315,6 +336,8 @@ static void sts_rss_set_current_configuration_full(acc_detector_presence_configu
acc_detector_presence_configuration_update_rate_set(presence_configuration, sts_presence_rss_config.default_update_rate_presence); //DEFAULT_UPDATE_RATE_2);
acc_detector_presence_configuration_detection_threshold_set(presence_configuration, sts_presence_rss_config.default_threshold);//DEFAULT_DETECTION_THRESHOLD_2);
acc_detector_presence_configuration_sweeps_per_frame_set(presence_configuration, DEFAULT_SWEEPS_PER_FRAME);
acc_detector_presence_configuration_start_set(presence_configuration, sts_presence_rss_config.default_start_m);
acc_detector_presence_configuration_length_set(presence_configuration, sts_presence_rss_config.default_length_m); //DEFAULT_LENGTH_M_2);
@ -349,6 +372,8 @@ static void sts_rss_set_configuration_background_evalution(acc_detector_presence
acc_detector_presence_configuration_sensor_set(presence_configuration, DEFAULT_SENSOR_ID);
acc_detector_presence_configuration_service_profile_set(presence_configuration, sts_presence_rss_config.default_profile);
acc_detector_presence_configuration_sweeps_per_frame_set(presence_configuration, DEFAULT_SWEEPS_PER_FRAME);
acc_detector_presence_configuration_start_set(presence_configuration, ((float)sts_sensor_install_height/2000.0));
acc_detector_presence_configuration_length_set(presence_configuration, ((float)(sts_sensor_install_height)/1000.0));
acc_detector_presence_configuration_detection_threshold_set(presence_configuration, (float)300.0/1000.0);
@ -360,7 +385,7 @@ static void sts_rss_set_configuration_background_evalution(acc_detector_presence
static void sts_rss_set_current_configuration_simple(acc_detector_presence_configuration_t presence_configuration)
{
APP_LOG(TS_OFF, VLEVEL_H, "\r\nsts_rss_cfg-start: %4d ,length: %4d ,threshold: %4d ,gain: %2d ,rate: %2d ,profile: %1d \r\n",
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),
@ -371,22 +396,48 @@ static void sts_rss_set_current_configuration_simple(acc_detector_presence_confi
acc_detector_presence_configuration_sensor_set(presence_configuration, DEFAULT_SENSOR_ID);
acc_detector_presence_configuration_service_profile_set(presence_configuration, sts_presence_rss_config.default_profile);
sweeps_per_frame = acc_detector_presence_configuration_sweeps_per_frame_get(presence_configuration);
acc_detector_presence_configuration_sweeps_per_frame_set(presence_configuration, sweeps_per_frame);
acc_detector_presence_configuration_downsampling_factor_set(presence_configuration, sts_presence_rss_config.default_downsampling_factor);
acc_detector_presence_configuration_hw_accelerated_average_samples_set(presence_configuration, DEFAULT_HWAAS);
acc_detector_presence_configuration_update_rate_set(presence_configuration, 5);
acc_detector_presence_configuration_detection_threshold_set(presence_configuration, sts_presence_rss_config.default_threshold);//DEFAULT_DETECTION_THRESHOLD_2);
acc_detector_presence_configuration_start_set(presence_configuration, sts_presence_rss_config.default_start_m);
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_power_save_mode_set(presence_configuration, DEFAULT_POWER_SAVE_MODE);
acc_detector_presence_configuration_receiver_gain_set(presence_configuration, sts_presence_rss_config.default_receiver_gain);
set_default_configuration_common(presence_configuration);
acc_detector_presence_configuration_filter_parameters_t filter = acc_detector_presence_configuration_filter_parameters_get(presence_configuration);
filter.inter_frame_deviation_time_const = DEFAULT_INTER_FRAME_DEVIATION_TIME_CONST;
// will be disabled if this value > 1/2 of update rate, default update rate 65, so must < 30
filter.inter_frame_fast_cutoff = DEFAULT_INTER_FRAME_FAST_CUTOFF;
filter.inter_frame_slow_cutoff = DEFAULT_INTER_FRAME_SLOW_CUTOFF;
acc_detector_presence_configuration_filter_parameters_set(presence_configuration,&filter);
// set_default_configuration_common(presence_configuration);
}
static void print_current_configuration(acc_detector_presence_configuration_t presence_configuration)
{
static uint32_t print_cnt=0;
if (print_cnt++%200 != 0) return;
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);
float sts_run_sweeps_rate = acc_detector_presence_configuration_sweeps_per_frame_get(presence_configuration);
float sts_run_downsampling = acc_detector_presence_configuration_downsampling_factor_get(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M, "\r\nWork_mode:%2d Start: %4d (mm) Length: %4d (mm) Threshold: %4d (*) Gain= %2d (%) UpdateRate=%4d Profile= %d Sweeps Rate=%d Downsampling=%d\r\n",
sts_work_mode, (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, (int)sts_run_sweeps_rate, (int)sts_run_downsampling);
acc_detector_presence_configuration_filter_parameters_t sts_run_filter = acc_detector_presence_configuration_filter_parameters_get(presence_configuration);
@ -398,31 +449,119 @@ static void print_current_configuration(acc_detector_presence_configuration_t pr
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\nWork_mode:%2d Start: %4d (mm) Length: %4d (mm) Threshold: %4d (*) Gain= %2d (%) UpdateRate=%4d Profile= %d \r\n",
sts_work_mode, (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 "
APP_LOG(TS_OFF, VLEVEL_M, "\r\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 uint8_t yes_count =0;
static uint8_t no_count = 0;
#define TIME_C 4
static void print_result(acc_detector_presence_result_t result)
{
// 2025-04 27 update according to BYD V1.4 2021-02-21
#if 0
if (result.presence_detected)
{
uint32_t detected_zone = (uint32_t)((float)(result.presence_distance - DEFAULT_START_M) / (float)DEFAULT_ZONE_LENGTH);
// 2024-08-05
//uint32_t detected_zone = (uint32_t)((float)(result.presence_distance) / (float)DEFAULT_ZONE_LENGTH);
APP_LOG(TS_OFF, VLEVEL_M,"Motion in zone: %u, distance: %d, score: %d\n", (unsigned int)detected_zone,
APP_LOG(TS_OFF, VLEVEL_H,"Motion in zone: %u, distance: %d, score: %d\n", (unsigned int)detected_zone,
(int)(result.presence_distance * 1000.0f),
(int)(result.presence_score * 1000.0f));
}
else
{
APP_LOG(TS_OFF, VLEVEL_M,"No motion, score: %u\n", (int)(result.presence_score * 1000.0f));
APP_LOG(TS_OFF, VLEVEL_H,"No motion, score: %u\n", (int)(result.presence_score * 1000.0f));
}
#endif
// 2025-04 27 update according to BYD V1.4 2021-02-21
uint16_t signal = 0;
uint16_t dist = 0;
uint8_t i = 0;
signal = (int)(result.presence_score * 1000.0f);
dist = (int)(result.presence_distance * 1000.0f);
uint8_t flag=0;
if (signal> sts_rss_threshold)
{
if(dist<500)
{
if(signal>(sts_rss_threshold+1000))
{
LED1_ON;
if(yes_count<TIME_C)
{
yes_count++;
}
else
{
no_count=0;
}
}
else
{
LED1_ON;
if(no_count<TIME_C)
{
no_count++;
}
else
{
yes_count=0;
}
}
}
else
{
LED1_ON;
if(yes_count<TIME_C)
{
yes_count++;
}
else
{
no_count=0;
}
}
}
else
{
LED1_OFF;
if(no_count<TIME_C)
{
no_count++;
}
else
{
yes_count=0;
}
//printf("No motion");
}
// else
// {
// printf("Wait.....");
// }
if(yes_count>(TIME_C-1))
{
//Out1_ON
//Out2_OFF
//printf("Motion (%5d), Distance: %4dmm\r\n", signal,dist);
APP_LOG(TS_OFF, VLEVEL_M, "\r\nMotion (%5d), Distance: %4dmm", signal, dist);
}
else if(no_count>(TIME_C-1))
{
//Out1_OFF
//Out2_ON
// printf("No motion(%5d), Distance: %4dmm\r\n", signal,dist);
APP_LOG(TS_OFF, VLEVEL_M, "\r\nNo motion(%5d), Distance: %4dmm", signal, dist);
}
}
/*
@ -484,7 +623,8 @@ int sts_presence_rss_background_evaluation_process(uint16_t *evaluated_distance,
float average_distance =0.0f;
float average_score =0.0f;
for (int i = 0; i < (iterations); i++)
//for (int i = 0; i < (iterations); i++)
while(1)
{
success = acc_detector_presence_get_next(handle, &result);
if (!success)
@ -493,7 +633,7 @@ int sts_presence_rss_background_evaluation_process(uint16_t *evaluated_distance,
break;
}
//print_result(result);
print_result(result);
if (!result.data_saturated)
{
if (result.presence_detected)
@ -506,7 +646,7 @@ int sts_presence_rss_background_evaluation_process(uint16_t *evaluated_distance,
}
}
acc_integration_sleep_ms(60); //--- around 1000ms in total
acc_integration_sleep_ms(200); //--- around 1000ms in total
if (motioncount%10 ==0)
{
@ -531,22 +671,114 @@ int sts_presence_rss_background_evaluation_process(uint16_t *evaluated_distance,
return EXIT_SUCCESS;
}
int sts_presence_rss_fall_rise_detection(void)
int sts_presence_rss_fall_rise_detection_loop(void)
{
success = acc_detector_presence_get_next(handle, &result);
if (!success)
{
APP_LOG(TS_OFF, VLEVEL_M,"acc_detector_presence_get_next() failed\n");
return EXIT_FAILURE;
}
print_result(result);
return EXIT_SUCCESS;
}
int sts_presence_rss_fall_rise_detection_end(void)
{
bool deactivated = acc_detector_presence_deactivate(handle);
acc_detector_presence_destroy(&handle);
acc_rss_deactivate();
if (deactivated && success)
{
APP_LOG(TS_OFF, VLEVEL_H,"Application finished OK\n");
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
int sts_presence_rss_fall_rise_detection_start(void)
{
const acc_hal_t *hal = acc_hal_integration_get_implementation();
if (!acc_rss_activate(hal))
{
APP_LOG(TS_OFF, VLEVEL_H,"Failed to activate RSS\n");
APP_LOG(TS_OFF, VLEVEL_M,"Failed to activate RSS\n");
return EXIT_FAILURE;
}
acc_rss_override_sensor_id_check_at_creation(true);
acc_detector_presence_configuration_t presence_configuration = acc_detector_presence_configuration_create();
//acc_detector_presence_configuration_t presence_configuration = acc_detector_presence_configuration_create();
presence_configuration = acc_detector_presence_configuration_create();
if (presence_configuration == NULL)
{
APP_LOG(TS_OFF, VLEVEL_H,"Failed to create configuration\n");
APP_LOG(TS_OFF, VLEVEL_M,"Failed to create configuration\n");
acc_rss_deactivate();
return EXIT_FAILURE;
}
// sts_rss_set_current_configuration_simple(presence_configuration);
set_default_configuration(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n##### YUNHORN STS *** Simple *** cfg applied\n");
print_current_configuration(presence_configuration);
sts_rss_threshold = sts_presence_rss_config.default_threshold*1000.0F;
//print_current_configuration(presence_configuration);
// acc_detector_presence_handle_t handle = acc_detector_presence_create(presence_configuration);
handle = acc_detector_presence_create(presence_configuration);
if (handle == NULL)
{
APP_LOG(TS_OFF, VLEVEL_M,"Failed to create detector\n");
acc_detector_presence_configuration_destroy(&presence_configuration);
//acc_detector_presence_destroy(&handle);
acc_rss_deactivate();
return EXIT_FAILURE;
}
sts_rss_threshold = sts_presence_rss_config.default_threshold*1000.0F;
APP_LOG(TS_OFF, VLEVEL_M,"\r\n============= Start Scan\n");
if (!acc_detector_presence_activate(handle))
{
APP_LOG(TS_OFF, VLEVEL_M, "Failed to activate detector \n");
acc_detector_presence_destroy(&handle);
acc_rss_deactivate();
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int sts_presence_rss_fall_rise_detection_startx(void)
{
const acc_hal_t *hal = acc_hal_integration_get_implementation();
if (!acc_rss_activate(hal))
{
APP_LOG(TS_OFF, VLEVEL_M,"Failed to activate RSS\n");
return EXIT_FAILURE;
}
acc_rss_override_sensor_id_check_at_creation(true);
//acc_detector_presence_configuration_t presence_configuration = acc_detector_presence_configuration_create();
presence_configuration = acc_detector_presence_configuration_create();
if (presence_configuration == NULL)
{
APP_LOG(TS_OFF, VLEVEL_M,"Failed to create configuration\n");
acc_rss_deactivate();
return EXIT_FAILURE;
}
@ -554,7 +786,7 @@ int sts_presence_rss_fall_rise_detection(void)
if ((sts_rss_config_updated_flag != STS_RSS_CONFIG_NON) || (sts_rss_init_ok != 1))
{
APP_LOG(TS_OFF, VLEVEL_H, "\r\n ------ ---------- rss cfg update flag=%02x \r\n", sts_rss_config_updated_flag);
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ------ ---------- rss cfg update flag=%02x \r\n", sts_rss_config_updated_flag);
if (sts_rss_init_ok==0)
@ -574,7 +806,7 @@ int sts_presence_rss_fall_rise_detection(void)
sts_rss_init_ok = 1;
}
APP_LOG(TS_OFF, VLEVEL_H, "\r\n Update flag=%02x, workmode=%2d \r\n", sts_rss_config_updated_flag, sts_work_mode);
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Update flag=%02x, workmode=%2d \r\n", sts_rss_config_updated_flag, sts_work_mode);
switch (sts_rss_config_updated_flag)
{
#if 0
@ -585,19 +817,20 @@ int sts_presence_rss_fall_rise_detection(void)
#endif
case STS_RSS_CONFIG_DEFAULT:
set_default_configuration(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Default *** cfg applied\n");
APP_LOG(TS_OFF, VLEVEL_M,"\r\n##### YUNHORN STS *** Default *** cfg applied\n");
break;
case STS_RSS_CONFIG_SIMPLE:
sts_rss_set_current_configuration_simple(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Simple *** cfg applied\n");
APP_LOG(TS_OFF, VLEVEL_M,"\r\n##### YUNHORN STS *** Simple *** cfg applied\n");
print_current_configuration(presence_configuration);
break;
case STS_RSS_CONFIG_FULL:
sts_rss_set_current_configuration_full(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_H,"\r\n######### YUNHORN STS *** FULL *** cfg applied\n");
APP_LOG(TS_OFF, VLEVEL_M,"\r\n######### YUNHORN STS *** FULL *** cfg applied\n");
break;
case STS_RSS_CONFIG_FALL_DETECTION:
set_default_fall_rise_configuration(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_H,"\r\n######### YUNHORN STS *** FALL DETECTION *** cfg applied\n");
APP_LOG(TS_OFF, VLEVEL_M,"\r\n######### YUNHORN STS *** FALL DETECTION *** cfg applied\n");
break;
default:
break;
@ -605,35 +838,45 @@ int sts_presence_rss_fall_rise_detection(void)
// sts_rss_config_updated_flag = STS_RSS_CONFIG_NON; //update finished, set to 0
}
sts_rss_threshold = sts_presence_rss_config.default_threshold*1000.0F;
acc_detector_presence_handle_t handle = acc_detector_presence_create(presence_configuration);
//print_current_configuration(presence_configuration);
// acc_detector_presence_handle_t handle = acc_detector_presence_create(presence_configuration);
handle = acc_detector_presence_create(presence_configuration);
if (handle == NULL)
{
APP_LOG(TS_OFF, VLEVEL_H,"Failed to create detector\n");
APP_LOG(TS_OFF, VLEVEL_M,"Failed to create detector\n");
acc_detector_presence_configuration_destroy(&presence_configuration);
acc_detector_presence_destroy(&handle);
//acc_detector_presence_destroy(&handle);
acc_rss_deactivate();
return EXIT_FAILURE;
}
sts_rss_threshold = sts_presence_rss_config.default_threshold*1000.0F;
APP_LOG(TS_OFF, VLEVEL_H,"\r\n============= Start Scan\n");
APP_LOG(TS_OFF, VLEVEL_M,"\r\n============= Start Scan\n");
print_current_configuration(presence_configuration);
//print_current_configuration(presence_configuration);
acc_detector_presence_configuration_destroy(&presence_configuration);
//acc_detector_presence_configuration_destroy(&presence_configuration);
// BEFORE MERGE FIRST AND SECOND HALF FALL RISE DETECTION
if (!acc_detector_presence_activate(handle))
{
APP_LOG(TS_OFF, VLEVEL_H, "Failed to activate detector \n");
APP_LOG(TS_OFF, VLEVEL_M, "Failed to activate detector \n");
acc_detector_presence_destroy(&handle);
acc_rss_deactivate();
return false;
}
#if 0
bool deactivated = false;
bool success = true;
const int iterations = (DEFAULT_UPDATE_RATE_PRESENCE);
acc_detector_presence_result_t result;
const int iterations = 1; //(DEFAULT_UPDATE_RATE_PRESENCE);
//acc_detector_presence_result_t result;
uint8_t average_result = 0;
float average_distance =0.0f;
float average_score =0.0f;
@ -655,6 +898,7 @@ int sts_presence_rss_fall_rise_detection(void)
{
for (int i = 0; i < (iterations); i++)
{
success = acc_detector_presence_get_next(handle, &result);
if (!success)
{
@ -663,10 +907,10 @@ int sts_presence_rss_fall_rise_detection(void)
}
//print_result(result);
if (!result.data_saturated)
//if (!result.data_saturated)
{
//APP_LOG(TS_OFF, VLEVEL_H,"\n%u ", i);
//print_result(result);
print_result(result);
if (result.presence_detected)
{
//print_result(result);
@ -697,15 +941,15 @@ 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(2); //--- around 1000ms in total
}
#if 0
deactivated = acc_detector_presence_deactivate(handle);
acc_detector_presence_destroy(&handle);
acc_rss_deactivate();
APP_LOG(TS_OFF, VLEVEL_H, "\r\n First Half --- Motion Count = %u \r\n", motion_count);
#endif
//acc_detector_presence_deactivate(handle);
}
else if ((sts_work_mode == STS_UNI_MODE))
@ -739,7 +983,7 @@ int sts_presence_rss_fall_rise_detection(void)
acc_detector_presence_configuration_destroy(&presence_configuration);
// set to full length of iteration
for (int i = 0; i < (iterations); i++)
for (int i = 0; i <= (iterations); i++)
{
success = acc_detector_presence_get_next(handle, &result);
if (!success)
@ -787,13 +1031,14 @@ int sts_presence_rss_fall_rise_detection(void)
//acc_integration_sleep_ms(10); //--- around 1500 ms in total
acc_integration_sleep_ms(2); //--- around 1000ms in total
}
#if 0
deactivated = acc_detector_presence_deactivate(handle);
acc_detector_presence_destroy(&handle);
acc_rss_deactivate();
APP_LOG(TS_OFF, VLEVEL_H, "\r\n Second Half --- Motion Count Sum to = %u \r\n", motion_count);
#endif
//APP_LOG(TS_OFF, VLEVEL_L,"Second Half, Fall Rise Detection, Motion Count = %u \r\n", (int)motion_count);
motion_count = motion_count%DEFAULT_MOTION_DATASET_LEN; // get all required number of motion data
@ -807,14 +1052,13 @@ int sts_presence_rss_fall_rise_detection(void)
}
}
average_distance = (float)(1000.0f*average_distance)/(float)average_result; // in meters
average_score = (float)(1000.0f*average_score)/(float)average_result;
sts_presence_rss_distance = average_distance;
sts_presence_rss_score = average_score;
STS_Yunhorn_DistanceStandardDeviation();
//STS_Yunhorn_DistanceStandardDeviation();
// APP_LOG(TS_OFF, VLEVEL_H, "\r\nAverage Distance: %d (mm) Score: %d Singularity: %d \r\n",(int)average_distance, (int)average_score, sts_presence_singularity);
// uint8_t pre_sts_rss_result = (average_result > (DEFAULT_UPDATE_RATE_PRESENCE/5))? 1: 0;
@ -830,10 +1074,10 @@ int sts_presence_rss_fall_rise_detection(void)
uint8_t pre_sts_rss_result=0;
if (sts_work_mode == STS_UNI_MODE) {
pre_sts_rss_result = (average_result > 0)? 1: 0;
pre_sts_rss_result = (average_result > (uint8_t)(0.7*iterations))? 1: 0;
} else {
pre_sts_rss_result = ((average_result > 0)&&(sts_presence_singularity ==0))? 1: 0;
pre_sts_rss_result = ((average_result > (uint8_t)(0.7*iterations))&&(sts_presence_singularity ==0))? 1: 0;
}
//Write_RingBuff(pre_sts_rss_result);
@ -847,7 +1091,7 @@ int sts_presence_rss_fall_rise_detection(void)
// APP_LOG(TS_OFF, VLEVEL_M, "\r\nMotionCount=%4d Overall Motion=%d \r\n", (int)motion_count, (int)sts_rss_result);
//APP_LOG(TS_OFF, VLEVEL_M, "\r\nAverage Result=%d Distance=%d, Score=%d MotionCount=%d ---Overall Result=%d \r\n",
// (int)average_result, (int)average_distance, (int)average_score, (int)motion_count, (int)sts_rss_result);
APP_LOG(TS_OFF, VLEVEL_M, "\r\nMotion Status: %d %d (mm) %d singularity: %d Rated-> %d \r\n",(int)average_result, (int)average_distance, (int)average_score, (int)sts_presence_singularity, (int)sts_rss_result);
APP_LOG(TS_OFF, VLEVEL_H, "\r\nMotion Status: %d %d (mm) %d singularity: %d Rated-> %d \r\n",(int)average_result, (int)average_distance, (int)average_score, (int)sts_presence_singularity, (int)sts_rss_result);
#if 0
if (sts_rss_result) //if (average_score !=0) //if (sts_rss_result)
{
@ -923,7 +1167,7 @@ int sts_presence_rss_fall_rise_detection(void)
APP_LOG(TS_OFF, VLEVEL_H,"Application finished OK\n");
return EXIT_SUCCESS;
}
#endif
return EXIT_FAILURE;
}
@ -948,7 +1192,8 @@ void STS_Yunhorn_DistanceStandardDeviation(void)
sum_presence_distance += (uint32_t)(sts_motion_dataset[j].presence_distance - average_presence_distance);
}
sts_presence_singularity = (sum_presence_distance > 0)? 0:1;
// sts_presence_singularity = (sum_presence_distance > 0)? 0:1;
sts_presence_singularity = 0;
// APP_LOG(TS_OFF, VLEVEL_M, "\r\n*** STS_Singularity=%u ***\r\n", sts_presence_singularity);
}

View File

@ -39,8 +39,8 @@
extern volatile sts_cfg_nvm_t sts_cfg_nvm;
extern volatile uint8_t sts_ac_code[20];
volatile uint8_t sts_work_mode = STS_UNI_MODE;
#if 0
//volatile uint8_t sts_work_mode = STS_UNI_MODE;
#if 1
#if defined(STS_O7)
volatile uint8_t sts_work_mode = STS_UNI_MODE;
#elif defined(STS_O6)
@ -332,7 +332,11 @@ void STS_YunhornSTSEventP2_Process(void)
break;
}
#endif
int res = sts_presence_rss_fall_rise_detection();
// int res = sts_presence_rss_fall_rise_detection();
APP_LOG(TS_OFF, VLEVEL_M, "\r\n RSS detection LOOP \r\n");
int res = sts_presence_rss_fall_rise_detection_loop();
if (res == 0)
{
@ -353,7 +357,7 @@ void STS_YunhornSTSEventP2_Process(void)
}
STS_Combined_Status_Processing();
} else APP_LOG(TS_OFF, VLEVEL_H, "\r\n RSS detection error =%d \r\n", res);
} else APP_LOG(TS_OFF, VLEVEL_M, "\r\n RSS detection error =%d \r\n", res);
}
}
@ -1146,11 +1150,12 @@ uint8_t STS_SENSOR_MEMS_Get_ID(uint8_t *devID)
{
devID[0] = scanned_id[0];
devID[1] = scanned_id[1];
APP_LOG(TS_OFF, VLEVEL_H,"\r\n--------------devID = %02x %02x \r\n",devID[0], devID[1]);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n--------------devID = %02x %02x \r\n",devID[0], devID[1]);
return true;
}
else
{
APP_LOG(TS_OFF, VLEVEL_M,"\r\n--------------devID = %02x %02x \r\n",devID[0], devID[1]);
return false;
}
#endif
@ -1582,12 +1587,12 @@ void STS_RSS_Filter(uint8_t pre_sts_rss_result)
{
//sts_rss_result= ((sum_filter >= SLIDING_THRESHOLD))? 1:0;
// sts_rss_result= ((sum_filter > (SLIDING_WIN_LEN - SLIDING_THRESHOLD)))? 1:0;
sts_rss_result= ((sum_filter > (sts_rss_cfg_slid_win_size - sts_rss_cfg_slid_win_threshold)))? 1:0;
sts_rss_result= ((sum_filter >= (15 - 13)))? 1:0;
} else {
sts_rss_result= ((sum_filter > sts_rss_cfg_slid_win_threshold))? 1:0;
sts_rss_result= ((sum_filter > 6 ))? 1:0;
}
#if 0

View File

@ -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 = 100; //unit ms
volatile uint32_t HeartBeatPeriodicity = 120000; //unit ms
volatile uint8_t STS_LoRa_WAN_Joined = 0;
@ -121,7 +121,7 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = {
0x00, //intra frame time const [0]=0 Lower to reduce sensitivity, higher to increase sensitivity
0x0A, //intra frame weight, 0x00=[0]*0.1=0.0F 0x0A=10, 10*0.1=1 FOR FAST MOVEMENT TRACKING FALL DETECTION
0x09, //output time const 0x05=[5]*0.1=0.5 0.5--> 0.9 2025-03-26 TODO XXXXXX
0x02, //downsampling factor [2]=2
0x01, //downsampling factor [2]=2 ---> 1 20250427 per acconeer BYD module cfg print result
0x03, //power saving mode ACTIVE [3] = 3U
0x02, //P[17] RSS CFG UPDATE FLAG 2025-04-14
0x6E, //P[18] RSS_CFG_BG_MOTION_NOISE 2025-04-14
@ -735,10 +735,11 @@ void STS_Sensor_Init(void)
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP7), UTIL_SEQ_RFU, STS_YunhornSTSEventP7_Process);
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP8), UTIL_SEQ_RFU, STS_YunhornSTSEventP8_Process);
#endif
//sts_presence_rss_fall_rise_detection_start();
#if defined(STS_O7)||defined(STS_O6)
UTIL_TIMER_Create(&YunhornSTSRSSWakeUpTimer, YUNHORN_STS_RSS_WAKEUP_CHECK_TIME, UTIL_TIMER_ONESHOT, OnYunhornSTSOORSSWakeUpTimerEvent, NULL);
// UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer);
//UTIL_TIMER_Create(&YunhornSTSRSSWakeUpTimer, YUNHORN_STS_RSS_WAKEUP_CHECK_TIME, UTIL_TIMER_ONESHOT, OnYunhornSTSOORSSWakeUpTimerEvent, NULL);
UTIL_TIMER_Create(&YunhornSTSRSSWakeUpTimer, 200, UTIL_TIMER_ONESHOT, OnYunhornSTSOORSSWakeUpTimerEvent, NULL);
UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer);
// HeartBeatPeriodicity HAS BEEN CHANGED IN REBOOT SESSION UPDATE 2025-04-23
// UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, YUNHORN_STS_HEART_BEAT_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL);
@ -763,7 +764,8 @@ void STS_Sensor_Init(void)
void STS_Sensor_Prepare(void)
{
int res = sts_presence_rss_fall_rise_detection_start();
//if (res != EXIT_FAILURE)
UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer);
}
@ -3138,7 +3140,7 @@ void STS_SENSOR_Function_Test_Process(void)
tstbuf[i++] = (uint8_t) sts_hardware_ver;
tstbuf[i++] = (uint8_t) (99*((GetBatteryLevel()/254)&0xff));
APP_LOG(TS_OFF, VLEVEL_H, "\r\nStart Function Test \r\n");
APP_LOG(TS_OFF, VLEVEL_M, "\r\nStart Function Test \r\n");
STS_SENSOR_MEMS_Get_ID(mems_Dev_ID);
if ((mems_Dev_ID[0]==0X0) && (mems_Dev_ID[1]==0x0)) {

Binary file not shown.