wip good so far 2025 04 14

This commit is contained in:
Yunhorn 2025-04-14 23:53:37 +08:00
parent cebc42f735
commit fbc9138720
8 changed files with 306 additions and 101 deletions

View File

@ -79,7 +79,7 @@ enum sts_oo_work_mode {
STS_TOF_PRESENCE_MODE, // A TOF PRESENCE OCCUPANCY
STS_TOF_IN_OUT_MODE, // B TOF IN OUT COUNT
STS_RSS_BACKGROUND_MODE, // C RSS_BACKGROUND EVALUATION MODE
STS_OTHER_MODE // ? OTHER MODE
};
#if defined(STS_O7)||defined(STS_O6)

View File

@ -246,8 +246,8 @@
#define STS_IOC_MODE_5_MASK STS_IOC_IN_ALL|STS_IOC_OUT_ALL //UNI_MODE
#define MajorVer 25U
#define MinorVer 3U
#define SubMinorVer 25U
#define MinorVer 4U
#define SubMinorVer 15U
#define FirmwareVersion 3U
#define YUNHORN_STS_MAX_NVM_CFG_SIZE 64U

View File

@ -85,7 +85,7 @@ enum RSS_CFG_order{
RSS_CFG_DOWNSAMPLING_FACTOR, // 15
RSS_CFG_POWER_MODE, // 16
RSS_CFG_UPDATE_FLAG, // 17 ADD AT 2025-04-11
RSS_CFG_RESERVE1, // 18
RSS_CFG_BG_MOTION_NOISE, // 18
RSS_CFG_RESERVE2, // 19
};
@ -726,7 +726,7 @@ void STS_PRESENCE_SENSOR_Read(STS_OO_SensorStatusDataTypeDef *o6_data);
void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *sensor_data);
void STS_PRESENCE_SENSOR_Init(void);
void STS_PRESENCE_SENSOR_RSS_Init(void);
//void STS_PRESENCE_SENSOR_RSS_Init(void);
void STS_PRESENCE_SENSOR_REEDSWITCH_HALL_Init(void);
void STS_PRESENCE_SENSOR_TOF_Init(void);
@ -770,7 +770,8 @@ void STS_SENSOR_Function_Test_Process(void);
void STS_SENSOR_Distance_Test_Process(void);
void STS_PRESENCE_SENSOR_Function_Test_Process(uint8_t *self_test_result, uint8_t count);
void STS_PRESENCE_SENSOR_Distance_Measure_Process(void);
void STS_PRESENCE_SENSOR_Background_Measure_Process(uint16_t *bg_distance, uint16_t *bg_motion_noise);
void sts_presence_rss_background_evaluation_process(uint16_t *evaluated_distance, uint16_t *evaluated_score);
void STS_Sensor_Init(void);
void STS_Sensor_Prepare(void);

View File

@ -148,6 +148,7 @@ 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;
extern uint8_t sts_lamp_bar_color;
/* USER CODE END Includes */
/* External variables ---------------------------------------------------------*/
@ -192,20 +193,11 @@ static uint8_t sts_rss_init_ok=0;
*
* @param[in] presence_configuration The presence configuration to set default values in
*/
static void set_default_configuration(acc_detector_presence_configuration_t presence_configuration)
static void set_default_configuration_common(acc_detector_presence_configuration_t presence_configuration)
{
acc_detector_presence_configuration_service_profile_set(presence_configuration, 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);
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_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);
acc_detector_presence_configuration_update_rate_set(presence_configuration, sts_presence_rss_config.default_update_rate_presence);
acc_detector_presence_configuration_downsampling_factor_set(presence_configuration, sts_presence_rss_config.default_downsampling_factor);
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;
@ -225,6 +217,47 @@ static void set_default_configuration(acc_detector_presence_configuration_t pres
acc_detector_presence_configuration_filter_parameters_set(presence_configuration, &filter);
acc_detector_presence_configuration_nbr_removed_pc_set(presence_configuration, DEFAULT_NBR_REMOVED_PC);
acc_detector_presence_configuration_power_save_mode_set(presence_configuration, ACC_POWER_SAVE_MODE_ACTIVE);
}
static void set_default_configuration(acc_detector_presence_configuration_t presence_configuration)
{
acc_detector_presence_configuration_sensor_set(presence_configuration, DEFAULT_SENSOR_ID);
acc_detector_presence_configuration_service_profile_set(presence_configuration, DEFAULT_PROFILE); // *** optional
acc_detector_presence_configuration_update_rate_set(presence_configuration, DEFAULT_UPDATE_RATE_PRESENCE);
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_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);
// by set_default_configuration_common
#if 0
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;
// 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.
// set the intra_frame_weight to 0.0
filter.intra_frame_weight = DEFAULT_INTRA_FRAME_WEIGHT;
// if detection toggles too often, increase the following, if too sluggish, decrease it instead
filter.output_time_const = DEFAULT_OUTPUT_TIME_CONST; //0.0f;
acc_detector_presence_configuration_filter_parameters_set(presence_configuration, &filter);
acc_detector_presence_configuration_nbr_removed_pc_set(presence_configuration, DEFAULT_NBR_REMOVED_PC);
acc_detector_presence_configuration_power_save_mode_set(presence_configuration, ACC_POWER_SAVE_MODE_ACTIVE);
#endif
// by set_default_configuration_common
}
/**
@ -235,14 +268,12 @@ static void set_default_configuration(acc_detector_presence_configuration_t pres
static void set_default_fall_rise_configuration(acc_detector_presence_configuration_t presence_configuration)
{
acc_detector_presence_configuration_sensor_set(presence_configuration, DEFAULT_SENSOR_ID);
acc_detector_presence_configuration_service_profile_set(presence_configuration, DEFAULT_PROFILE);
acc_detector_presence_configuration_update_rate_set(presence_configuration, DEFAULT_UPDATE_RATE_PRESENCE);
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, 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);
@ -303,7 +334,7 @@ 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)
static void sts_rss_set_configuration_background_evalution(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),
@ -314,15 +345,36 @@ static void sts_rss_set_current_configuration_simple(acc_detector_presence_confi
(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
acc_detector_presence_configuration_service_profile_set(presence_configuration, sts_presence_rss_config.default_profile);
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*2/3 - 300)/1000.0));
acc_detector_presence_configuration_detection_threshold_set(presence_configuration, (float)300/1000.0);
acc_detector_presence_configuration_receiver_gain_set(presence_configuration, (float)80/100.0);
set_default_configuration_common(presence_configuration);
}
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",
(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_service_profile_set(presence_configuration, sts_presence_rss_config.default_profile);
acc_detector_presence_configuration_update_rate_set(presence_configuration, sts_presence_rss_config.default_update_rate_presence);
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_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);
set_default_configuration_common(presence_configuration);
}
static void print_current_configuration(acc_detector_presence_configuration_t presence_configuration)
@ -344,7 +396,7 @@ 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_H, "\r\nWork_mode:%2d Start: %4d (mm) Length: %4d (mm) Threshold: %4d (*) Gain= %2d (%) UpdateRate=%4d Profile= %d \r\n",
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);
@ -376,6 +428,105 @@ static void print_result(acc_detector_presence_result_t result)
* OUTPUT: sts_rss_result = STS_PRESENCE_MOTION, STS_PRESENCE_NO_MOTION
* sts_rss_result
*/
void sts_presence_rss_background_evaluation_process(uint16_t *evaluated_distance, uint16_t *evaluated_score)
{
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");
return EXIT_FAILURE;
}
acc_rss_override_sensor_id_check_at_creation(true);
acc_detector_presence_configuration_t presence_configuration = acc_detector_presence_configuration_create();
if (presence_configuration == NULL)
{
APP_LOG(TS_OFF, VLEVEL_H,"Failed to create configuration\n");
acc_rss_deactivate();
return EXIT_FAILURE;
}
sts_rss_set_configuration_background_evalution(presence_configuration);
acc_detector_presence_handle_t handle = acc_detector_presence_create(presence_configuration);
if (handle == NULL)
{
APP_LOG(TS_OFF, VLEVEL_H,"Failed to create detector\n");
acc_detector_presence_configuration_destroy(&presence_configuration);
acc_detector_presence_destroy(&handle);
acc_rss_deactivate();
return EXIT_FAILURE;
}
print_current_configuration(presence_configuration);
acc_detector_presence_configuration_destroy(&presence_configuration);
if (!acc_detector_presence_activate(handle))
{
APP_LOG(TS_OFF, VLEVEL_H, "Failed to activate detector \n");
return false;
}
bool deactivated = false;
bool success = true;
const int iterations = 1000;
acc_detector_presence_result_t result;
uint16_t motioncount = 0;
float average_distance =0.0f;
float average_score =0.0f;
for (int i = 0; i < (iterations); i++)
{
success = acc_detector_presence_get_next(handle, &result);
if (!success)
{
APP_LOG(TS_OFF, VLEVEL_H,"acc_detector_presence_get_next() failed\n");
break;
}
//print_result(result);
if (!result.data_saturated)
{
if (result.presence_detected)
{
//print_result(result);
motioncount++;
average_distance += result.presence_distance;
average_score += result.presence_score;
}
}
acc_integration_sleep_ms(60); //--- around 1000ms in total
if (motioncount%10 ==0)
{
LED1_TOGGLE;
}
}
deactivated = acc_detector_presence_deactivate(handle);
acc_detector_presence_destroy(&handle);
acc_rss_deactivate();
average_distance = (1000.0f*average_distance)/motioncount; // in meters
average_score = (1000.0f*average_score)/motioncount;
APP_LOG(TS_OFF, VLEVEL_M, "\r\nBackground Scan: MotionCount: %d , Distance Center Around: %d (mm) , Score: %d \r\n", (int) motioncount, (int)average_distance, (int)average_score);
*evaluated_distance = (uint16_t)average_distance;
*evaluated_score = (uint16_t)average_score;
LED1_ON;
}
int sts_presence_rss_fall_rise_detection(void)
{
const acc_hal_t *hal = acc_hal_integration_get_implementation();
@ -404,11 +555,18 @@ int sts_presence_rss_fall_rise_detection(void)
if (sts_rss_init_ok==0)
{
if (sts_work_mode ==STS_UNI_MODE) sts_rss_config_updated_flag |= STS_RSS_CONFIG_FALL_DETECTION;
else if ((sts_work_mode == STS_RSS_MODE) || (sts_work_mode == STS_DUAL_MODE)) sts_rss_config_updated_flag |= STS_RSS_CONFIG_DEFAULT;
set_default_configuration(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M, "\r\n First Time RSS init, update flag=%02x\r\n", sts_rss_config_updated_flag);
print_current_configuration(presence_configuration);
if (sts_work_mode ==STS_UNI_MODE)
{
sts_rss_config_updated_flag = STS_RSS_CONFIG_FALL_DETECTION;
}
else if ((sts_work_mode == STS_RSS_MODE) || (sts_work_mode == STS_DUAL_MODE))
{
if (sts_rss_config_updated_flag == STS_RSS_CONFIG_NON)
sts_rss_config_updated_flag = STS_RSS_CONFIG_DEFAULT;
}
//set_default_configuration(presence_configuration);
//APP_LOG(TS_OFF, VLEVEL_M, "\r\n First Time RSS init, update flag=%02x\r\n", sts_rss_config_updated_flag);
//print_current_configuration(presence_configuration);
sts_rss_init_ok = 1;
}
@ -437,33 +595,6 @@ 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");
sts_rss_set_current_configuration_full(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_H,"\r\n######### YUNHORN STS *** FULL *** cfg applied\n");
break;
case STS_RSS_CONFIG_FULL|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");
sts_rss_set_current_configuration_full(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_H,"\r\n######### YUNHORN STS *** FULL *** cfg applied\n");
break;
case STS_RSS_CONFIG_SIMPLE|STS_RSS_CONFIG_FALL_DETECTION:
set_default_fall_rise_configuration(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n##### YUNHORN STS *** Default *** cfg applied\n");
sts_rss_set_current_configuration_simple(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n##### YUNHORN STS *** Simple *** cfg applied\n");
break;
default:
break;
}
@ -675,7 +806,7 @@ int sts_presence_rss_fall_rise_detection(void)
average_distance = (1000.0f*average_distance)/average_result; // in meters
average_score = (1000.0f*average_score)/average_result;
APP_LOG(TS_OFF, VLEVEL_M, "\r\nAverage Distance: %d (mm) Score: %d \r\n",(int)average_distance, (int)average_score);
sts_presence_rss_distance = average_distance;
sts_presence_rss_score = average_score;
// uint8_t pre_sts_rss_result = (average_result > (DEFAULT_UPDATE_RATE_PRESENCE/5))? 1: 0;

View File

@ -45,7 +45,7 @@ int sts_presence_rss_bring_up_test(uint8_t *rss_self_test_result)
uint8_t t=0;
uint8_t test_result[20]={0x0};
APP_LOG(TS_OFF, VLEVEL_L,"-- 0 -- Acconeer software version %s\n", acc_version_get());
// APP_LOG(TS_OFF, VLEVEL_L,"-- 0 -- Acconeer software version %s\n", acc_version_get());
const acc_hal_t *hal = acc_hal_integration_get_implementation();
@ -89,7 +89,7 @@ int sts_presence_rss_bring_up_test(uint8_t *rss_self_test_result)
acc_rss_assembly_test_configuration_communication_write_read_test_disable(configuration);
// Enable and run: Interrupt Test
APP_LOG(TS_OFF, VLEVEL_L,"-- Interrupt Test --- Start ********************\r\n");
// APP_LOG(TS_OFF, VLEVEL_L,"-- Interrupt Test --- Start ********************\r\n");
acc_rss_assembly_test_configuration_communication_interrupt_test_enable(configuration);
if (!run_test(configuration))
@ -104,10 +104,10 @@ int sts_presence_rss_bring_up_test(uint8_t *rss_self_test_result)
}
acc_rss_assembly_test_configuration_communication_interrupt_test_disable(configuration);
APP_LOG(TS_OFF, VLEVEL_L,"-- Interrupt Test --- End ********************\r\n");
// APP_LOG(TS_OFF, VLEVEL_L,"-- Interrupt Test --- End ********************\r\n");
// Enable and run: Clock Test
APP_LOG(TS_OFF, VLEVEL_L,"-- Clock Test --- Start ********************\r\n");
// APP_LOG(TS_OFF, VLEVEL_L,"-- Clock Test --- Start ********************\r\n");
acc_rss_assembly_test_configuration_clock_test_enable(configuration);
if (!run_test(configuration))
{
@ -121,11 +121,11 @@ int sts_presence_rss_bring_up_test(uint8_t *rss_self_test_result)
}
acc_rss_assembly_test_configuration_clock_test_disable(configuration);
APP_LOG(TS_OFF, VLEVEL_L,"-- Clock Test --- end ********************\r\n");
// APP_LOG(TS_OFF, VLEVEL_L,"-- Clock Test --- end ********************\r\n");
// Enable and run: Power cycle test
APP_LOG(TS_OFF, VLEVEL_L,"-- Power cycle test --- Start ********************\r\n");
// APP_LOG(TS_OFF, VLEVEL_L,"-- Power cycle test --- Start ********************\r\n");
acc_rss_assembly_test_configuration_power_cycle_test_enable(configuration);
if (!run_test(configuration))
{
@ -139,11 +139,11 @@ int sts_presence_rss_bring_up_test(uint8_t *rss_self_test_result)
}
acc_rss_assembly_test_configuration_power_cycle_test_disable(configuration);
APP_LOG(TS_OFF, VLEVEL_L,"-- Power cycle test --- end ********************\r\n");
// APP_LOG(TS_OFF, VLEVEL_L,"-- Power cycle test --- end ********************\r\n");
// Enable and run: Hibernate Test
APP_LOG(TS_OFF, VLEVEL_L,"-- Hibernate Test --- Start ********************\r\n");
// APP_LOG(TS_OFF, VLEVEL_L,"-- Hibernate Test --- Start ********************\r\n");
acc_rss_assembly_test_configuration_communication_hibernate_test_enable(configuration);
if (!run_test(configuration))
{
@ -157,10 +157,10 @@ int sts_presence_rss_bring_up_test(uint8_t *rss_self_test_result)
}
acc_rss_assembly_test_configuration_communication_hibernate_test_disable(configuration);
APP_LOG(TS_OFF, VLEVEL_L,"-- Hibernate Test --- End ********************\r\n");
// APP_LOG(TS_OFF, VLEVEL_L,"-- Hibernate Test --- End ********************\r\n");
// Enable and run: Supply Test
APP_LOG(TS_OFF, VLEVEL_L,"-- Supply Test --- Start ********************\r\n");
// APP_LOG(TS_OFF, VLEVEL_L,"-- Supply Test --- Start ********************\r\n");
acc_rss_assembly_test_configuration_supply_test_enable(configuration);
if (!run_test(configuration))
{
@ -174,10 +174,10 @@ int sts_presence_rss_bring_up_test(uint8_t *rss_self_test_result)
}
acc_rss_assembly_test_configuration_supply_test_disable(configuration);
APP_LOG(TS_OFF, VLEVEL_L,"-- Supply Test --- End ********************\r\n");
// APP_LOG(TS_OFF, VLEVEL_L,"-- Supply Test --- End ********************\r\n");
// Enable and run: Clock Test
APP_LOG(TS_OFF, VLEVEL_L,"-- Clock Test --- Start ********************\r\n");
// APP_LOG(TS_OFF, VLEVEL_L,"-- Clock Test --- Start ********************\r\n");
acc_rss_assembly_test_configuration_clock_test_enable(configuration);
if (!run_test(configuration))
{
@ -191,10 +191,10 @@ int sts_presence_rss_bring_up_test(uint8_t *rss_self_test_result)
}
acc_rss_assembly_test_configuration_clock_test_disable(configuration);
APP_LOG(TS_OFF, VLEVEL_L,"-- Clock Test --- end ********************\r\n");
// APP_LOG(TS_OFF, VLEVEL_L,"-- Clock Test --- end ********************\r\n");
// Enable and run: Power cycle test
APP_LOG(TS_OFF, VLEVEL_L,"-- Power cycle test --- Start ********************\r\n");
// APP_LOG(TS_OFF, VLEVEL_L,"-- Power cycle test --- Start ********************\r\n");
acc_rss_assembly_test_configuration_power_cycle_test_enable(configuration);
if (!run_test(configuration))
{
@ -208,14 +208,14 @@ int sts_presence_rss_bring_up_test(uint8_t *rss_self_test_result)
}
acc_rss_assembly_test_configuration_power_cycle_test_disable(configuration);
APP_LOG(TS_OFF, VLEVEL_L,"-- Power cycle test --- end ********************\r\n");
// APP_LOG(TS_OFF, VLEVEL_L,"-- Power cycle test --- end ********************\r\n");
APP_LOG(TS_OFF, VLEVEL_L,"-- 10 -- Bring up test: All tests passed\n");
// APP_LOG(TS_OFF, VLEVEL_L,"-- 10 -- Bring up test: All tests passed\n");
test_result[t++] = 1; //(10)
memcpy(rss_self_test_result, test_result, 12);
APP_LOG(TS_OFF, VLEVEL_L,"--Bring up test result #=%d \r\n", t);
// APP_LOG(TS_OFF, VLEVEL_L,"--Bring up test result #=%d \r\n", t);
acc_rss_assembly_test_configuration_destroy(&configuration);
acc_rss_deactivate();
@ -234,7 +234,7 @@ static bool run_test(acc_rss_assembly_test_configuration_t configuration)
APP_LOG(TS_OFF, VLEVEL_L,"Bring up test: Failed to complete\n");
return false;
} else {
APP_LOG(TS_OFF, VLEVEL_L,"Bring up test: SUCCESS to complete\n");
APP_LOG(TS_OFF, VLEVEL_H,"Bring up test: SUCCESS to complete\n");
}

View File

@ -762,9 +762,11 @@ void STS_PRESENCE_SENSOR_NVM_CFG(void)
sts_presence_rss_config.default_power_save_mode = (float)(sts_cfg_nvm.p[RSS_CFG_POWER_MODE]);
// sts_rss_config_updated_flag = (sts_rss_config_updated_flag|STS_RSS_CONFIG_FULL); //set to 2 for FULL config effect in next detection
sts_rss_config_updated_flag = (STS_RSS_CONFIG_FULL); //set to 2 for FULL config effect in next detection
//sts_rss_config_updated_flag = (STS_RSS_CONFIG_FULL); //set to 2 for FULL config effect in next detection
//sts_presence_rss_config.default_config_update_flag = (uint8_t) sts_rss_config_updated_flag;
sts_rss_config_updated_flag = (uint8_t)(sts_cfg_nvm.p[RSS_CFG_UPDATE_FLAG]);
APP_LOG(TS_ON, VLEVEL_M, "\r\n##### Reboot --- with NVM CFG'ED RSS flag =%02x \r\n", sts_rss_config_updated_flag);
}
void STS_PRESENCE_SENSOR_NVM_CFG_SIMPLE(void)
@ -1002,6 +1004,8 @@ void STS_PRESENCE_SENSOR_REEDSWITCH_HALL_Init(void)
APP_LOG(TS_ON, VLEVEL_H, "##### YunHorn SmarToilets(r) REED SWITCH HALL ELEMENT Initializing \r\n");
}
#if 0
void STS_PRESENCE_SENSOR_RSS_Init(void)
{
APP_LOG(TS_ON, VLEVEL_H, "##### YunHorn SmarToilets(r) MEMS RSS Initializing \r\n");
@ -1045,7 +1049,7 @@ void STS_PRESENCE_SENSOR_RSS_Init(void)
#endif
APP_LOG(TS_ON, VLEVEL_M, "\r\n##### Reboot --- with NVM CFG'ED RSS flag =%02x \r\n", sts_rss_config_updated_flag);
}
#endif
void STS_PRESENCE_SENSOR_Distance_Measure_Process(void)
{
@ -1056,18 +1060,42 @@ void STS_PRESENCE_SENSOR_Distance_Measure_Process(void)
(unsigned int)(distance_cfg.acc_profile),(unsigned int)(distance_cfg.hwaas));
do
{
LED1_TOGGLE;
exit_status = sts_distance_rss_detector_distance();
HAL_Delay(10);
i++;
} while ((exit_status == EXIT_FAILURE) && (i < 1));
LED1_ON;
}
void STS_PRESENCE_SENSOR_Background_Measure_Process(uint16_t *bg_distance, uint16_t *bg_motion_noise)
{
uint8_t previous_sts_work_mode = sts_work_mode, previous_sts_lamp_bar_color = sts_lamp_bar_color;
uint16_t distance_center=0, motion_noise=0;
sts_work_mode = STS_RSS_BACKGROUND_MODE;
sts_lamp_bar_color = STS_BLUE;
sts_presence_rss_background_evaluation_process(&distance_center, &motion_noise);
APP_LOG(TS_OFF, VLEVEL_H, "\r\n Background Distance center at %d mm, and Motion Noise =%d \r\n", distance_center, motion_noise);
*bg_distance = distance_center;
*bg_motion_noise = motion_noise;
sts_work_mode = previous_sts_work_mode;
sts_lamp_bar_color = previous_sts_lamp_bar_color;
}
void STS_PRESENCE_SENSOR_Function_Test_Process(uint8_t *self_test_result, uint8_t count)
{
uint8_t bring_up_result[20];
uint8_t bring_up_result[16];
uint8_t previous_lamp_bar_color=sts_lamp_bar_color;
uint16_t bg_range=0, bg_noise=0;
PME_ON;
HAL_Init();
MX_GPIO_Init();
@ -1076,19 +1104,32 @@ void STS_PRESENCE_SENSOR_Function_Test_Process(uint8_t *self_test_result, uint8_
for (uint8_t i=0;i < count; i++) //while(1)
{
STS_Lamp_Bar_Self_Test_Simple();
sts_lamp_bar_color = STS_PINK;
STS_Lamp_Bar_Refresh();
HAL_Delay(200);
sts_lamp_bar_color = STS_PINK;
sts_presence_rss_bring_up_test(bring_up_result);
HAL_Delay(200);
sts_lamp_bar_color = STS_CYAN;
STS_PRESENCE_SENSOR_Distance_Measure_Process();
bring_up_result[10]=sts_sensor_install_height>>8&0xff;
bring_up_result[11]=sts_sensor_install_height&0xff;
HAL_Delay(200);
STS_PRESENCE_SENSOR_Background_Measure_Process(&bg_range, &bg_noise);
bring_up_result[12]=bg_range>>8&0xff;
bring_up_result[13]=bg_range&0xff;
bring_up_result[14]=bg_noise>>8&0xff;
bring_up_result[15]=bg_noise&0xff;
}
HAL_Delay(200);
sts_lamp_bar_color = previous_lamp_bar_color;
UTIL_MEM_cpy_8(self_test_result, bring_up_result, 10);
UTIL_MEM_cpy_8(self_test_result, bring_up_result, sizeof(bring_up_result));
}

View File

@ -121,8 +121,8 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = {
0x09, //output time const 0x05=[5]*0.1=0.5 0.5--> 0.9 2025-03-26 TODO XXXXXX
0x02, //downsampling factor [2]=2
0x03, //power saving mode ACTIVE [3] = 3U
0x01, //reserve --P[17] RSS CFG UPDATE FLAG 2025-04-14
0x00, //reserve --P[18] RESERVE1
0x02, //P[17] RSS CFG UPDATE FLAG 2025-04-14
0x6E, //P[18] RSS_CFG_BG_MOTION_NOISE 2025-04-14
0x00, //reserve --P[19] RESERVE2
}, // above 20 bytes
0x00, //reserve2
@ -1180,7 +1180,7 @@ static void OnTxTimerEvent(void *context)
{
/* USER CODE BEGIN OnTxTimerEvent_1 */
if (sts_warm_up_count < 10)
if (sts_warm_up_count < 5)
{
/* 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))
@ -2066,11 +2066,10 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, uint8_t tlv_buf_size)
outbuf[i++] = (uint8_t)(99*((GetBatteryLevel()/254)&0xff));
#if defined(STS_O7)||defined(STS_O6)
outbuf[i++] = (uint8_t)0x04; //length of following data
outbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/1000)%10+0x30)&0xff;
outbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/100)%10+0x30)&0xff;
outbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/10)%10+0x30)&0xff;
outbuf[i++] = (uint8_t) (((uint16_t)sts_distance_rss_distance)%10+0x30)&0xff;
outbuf[i++] = (uint8_t)0x02; //length of following data, 2025 04 14 UPDATE
outbuf[i++] = (uint8_t) (((uint16_t)sts_distance_rss_distance>>8)&0xff);
outbuf[i++] = (uint8_t) ((uint16_t)sts_distance_rss_distance&0xff);
#endif
#if (defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED)||defined(YUNHORN_STS_R1_ENABLED))
#ifdef TOF_1
@ -2090,9 +2089,36 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, uint8_t tlv_buf_size)
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
} else if ((char)tlv_buf[CFG_CMD3] == 'B')
{ // Background Noise Measure "YZB"
#if defined(STS_O7)||defined(STS_O6)
uint16_t bg_distance=0, bg_motion_noise=0;
STS_PRESENCE_SENSOR_Background_Measure_Process(&bg_distance, &bg_motion_noise);
APP_LOG(TS_OFF, VLEVEL_M, "\r\nRSS Measured Background Center Distance=[%u] mm Motion Noise Level = [%d] \r\n",
(uint16_t)bg_distance, (uint16_t)bg_motion_noise);
sts_cfg_nvm.p[RSS_CFG_BG_MOTION_NOISE] = (uint8_t)(bg_motion_noise/10)&0xff;
OnStoreSTSCFGContextRequest();
i=0;
outbuf[i++] = (uint8_t)'B';
outbuf[i++] = (uint8_t)sts_mtmcode1;
outbuf[i++] = (uint8_t)sts_mtmcode2;
outbuf[i++] = (uint8_t)sts_version;
outbuf[i++] = (uint8_t)sts_hardware_ver;
outbuf[i++] = (uint8_t)(99*((GetBatteryLevel()/254)&0xff));
outbuf[i++] = (uint8_t) 0x04; //length of following data
outbuf[i++] = (uint8_t) (bg_distance>>8)&0xff;
outbuf[i++] = (uint8_t) (bg_distance)&0xff;
outbuf[i++] = (uint8_t) (bg_motion_noise>>8)&0xff;
outbuf[i++] = (uint8_t) (bg_motion_noise)&0xff;
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
#endif
}
break;
break; // "YZ_"
case 'M': //"YM"
if ((char)tlv_buf[CFG_CMD3] >= '0' && (char)tlv_buf[CFG_CMD3]<='9') // Service Mask "YZM"
@ -2605,6 +2631,8 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, uint8_t tlv_buf_size)
if (invalid_flag == 0)
{
sts_cfg_nvm.p[RSS_CFG_UPDATE_FLAG] = STS_RSS_CONFIG_FULL;
STS_PRESENCE_SENSOR_NVM_CFG();
i=0; // Step 1: Prepare status update message
@ -2647,6 +2675,8 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, uint8_t tlv_buf_size)
APP_LOG(TS_OFF, VLEVEL_M,"\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_cfg_nvm.p[RSS_CFG_UPDATE_FLAG] = STS_RSS_CONFIG_SIMPLE;
STS_PRESENCE_SENSOR_NVM_CFG_SIMPLE();
i=0; // Step 1: Prepare status update message
@ -3136,7 +3166,8 @@ void OnRestoreSTSCFGContextProcess(void)
// if ((sts_version == sts_cfg_nvm.version)&& (NVM_CFG_PARAMETER_SIZE == sts_cfg_nvm.length))
{
STS_PRESENCE_SENSOR_Init();
STS_PRESENCE_SENSOR_RSS_Init();
STS_PRESENCE_SENSOR_NVM_CFG();
//STS_PRESENCE_SENSOR_RSS_Init();
}
#endif
//STS_SENSOR_Distance_Test_Process();
@ -3157,7 +3188,7 @@ void STS_SENSOR_Distance_Test_Process(void)
void STS_SENSOR_Function_Test_Process(void)
{
char tstbuf[128] =""; uint8_t i=0, count = 1;
uint8_t tstbuf[128] ={0x0}; uint8_t i=0, count = 1;
uint8_t mems_Dev_ID[2] = {0x0};
tstbuf[i++] = (uint8_t) 'S';
@ -3175,22 +3206,23 @@ void STS_SENSOR_Function_Test_Process(void)
}
else
{
tstbuf[i++] = (uint8_t)14; //length of following data
tstbuf[i++] = (uint8_t)16; //length of following data 16 bytes
#if defined(STS_O7)||defined(STS_O6)
uint8_t self_test_result[10]={0x0};
uint8_t self_test_result[16]={0x0};
STS_PRESENCE_SENSOR_Function_Test_Process(self_test_result, count);
for (uint8_t j=0; j < 10; j++)
for (uint8_t j=0; j < 16; j++)
tstbuf[i++] = (uint8_t) (self_test_result[j])&0xff;
//STS_PRESENCE_SENSOR_Distance_Measure_Process();
#if 0
tstbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/1000)%10+0x30)&0xff;
tstbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/100)%10+0x30)&0xff;
tstbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/10)%10+0x30)&0xff;
tstbuf[i++] = (uint8_t) (((uint16_t)sts_distance_rss_distance)%10+0x30)&0xff;
#endif
#endif
#if (defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED)||defined(YUNHORN_STS_R1_ENABLED))
tstbuf[i++] = (uint8_t) (count)&0xff;
//MX_TOF_Process();
@ -3213,7 +3245,7 @@ void STS_SENSOR_Function_Test_Process(void)
}
//memset((void*)outbuf,0x0, sizeof(outbuf));
UTIL_MEM_cpy_8((void*)outbuf, (void*)tstbuf, i);
UTIL_MEM_cpy_8((void*)outbuf, (void*)tstbuf, sizeof(tstbuf));
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t*)outbuf);
}

Binary file not shown.