wip 2025-03-21

This commit is contained in:
Yunhorn 2025-03-21 17:18:06 +08:00
parent 2e44e814dc
commit 76dc939083
15 changed files with 362 additions and 66 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -42,7 +42,7 @@
//#define USE_TOF_VL53LXX
//#define USE_MEMS_ADXL345
#if defined(STS_O2)||defined(STS_O6)||defined(STS_O7)
#define USE_ACCONEER_A111
#define USE_ACCONEER_A111 1U
#endif
/* ########################## Product Selection ############################## */
/**

View File

@ -734,7 +734,9 @@ 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_detector_rss_start(void);
int sts_presence_detector_rss_close(void);
int sts_presence_rss_fall_rise_detection_process(void);
int sts_presence_rss_presence_detection(void);
int sts_presence_rss_fall_rise_detection(void);
int sts_distance_rss_detector_distance(void);

View File

@ -211,6 +211,9 @@ bool hal_test_spi_read_chipid(uint8_t chipid[2])
hal->sensor_device.power_on(sensor);
hal->sensor_device.transfer(sensor,buffer,sizeof(buffer));
hal->sensor_device.power_off(sensor);
//APP_LOG(TS_OFF, VLEVEL_M, "\r\n A111 SPI read_chipid=%02x %02x %02x %02x %02x %02x\r\n", buffer[0],buffer[1],buffer[2],buffer[3],buffer[4],buffer[5]);
if (buffer[4] == 0x11 && buffer[5] == 0x12) {
chipid[0] = buffer[4];
chipid[1] = buffer[5];

View File

@ -20,7 +20,8 @@
/* Includes ------------------------------------------------------------------*/
#include "gpio.h"
#include "main.h"
#include "yunhorn_sts_prd_conf.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */

View File

@ -20,6 +20,7 @@
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32wlxx_it.h"
#include "yunhorn_sts_prd_conf.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
@ -277,8 +278,9 @@ void EXTI3_IRQHandler(void)
/* USER CODE END EXTI3_IRQn 0 */
#if defined(RM2_1) && defined(USE_ACCONEER_A111)
//HAL_GPIO_EXTI_IRQHandler(A111_SENSOR_INTERRUPT_Pin);
HAL_GPIO_EXTI_IRQHandler(A111_SENSOR_INTERRUPT_Pin);
#endif
#ifdef STS_P2
// TODO XXX
HAL_GPIO_EXTI_IRQHandler(TOF_C_INT_Pin);

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

@ -57,7 +57,7 @@
// 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 distance_cfg={0.8, 3.5, 4, 63, 4, 10, 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;
@ -80,13 +80,13 @@ int sts_distance_rss_detector_distance(void)
return EXIT_FAILURE;
}
//acc_rss_override_sensor_id_check_at_creation(true);
acc_rss_override_sensor_id_check_at_creation(true);
acc_detector_distance_configuration_t distance_configuration = acc_detector_distance_configuration_create();
if (distance_configuration == NULL)
{
APP_LOG(TS_OFF, VLEVEL_L, "acc_detector_distance_configuration_create() failed\n");
APP_LOG(TS_OFF, VLEVEL_M, "acc_detector_distance_configuration_create() failed\n");
acc_rss_deactivate();
return EXIT_FAILURE;
}
@ -152,7 +152,7 @@ int sts_distance_rss_detector_distance(void)
if (deactivated && success)
{
APP_LOG(TS_OFF, VLEVEL_H, "Application finished OK\n");
APP_LOG(TS_OFF, VLEVEL_M, "Application finished OK\n");
return EXIT_SUCCESS;
}

View File

@ -145,6 +145,12 @@ volatile uint16_t last_average_presence_distance=0;
volatile uint16_t sts_fall_rising_pattern_factor1=0, sts_fall_rising_pattern_factor2=0, sts_fall_rising_pattern_factor3=0;
volatile uint16_t sts_roc_acc_standard_variance=0;
extern volatile uint8_t sts_presence_fall_detection;
static acc_detector_presence_handle_t sts_rss_handle;
acc_detector_presence_configuration_t presence_configuration;
volatile bool sts_rss_deactivated = false;
acc_detector_presence_result_t result;
bool success= true;
/* USER CODE END Includes */
/* External variables ---------------------------------------------------------*/
@ -331,6 +337,255 @@ static void print_result(acc_detector_presence_result_t result)
}
}
int sts_presence_detector_rss_start(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;
}
switch (sts_rss_config_updated_flag)
{
case STS_RSS_CONFIG_NON:
//return EXIT_SUCCESS;
break;
case STS_RSS_CONFIG_DEFAULT:
set_default_configuration(presence_configuration);
break;
case STS_RSS_CONFIG_SIMPLE:
sts_rss_set_current_configuration_simple(presence_configuration);
break;
case STS_RSS_CONFIG_FULL:
sts_rss_set_current_configuration_full(presence_configuration);
break;
case STS_RSS_CONFIG_FALL_DETECTION:
set_default_fall_rise_configuration(presence_configuration);
break;
case STS_RSS_CONFIG_DEFAULT|STS_RSS_CONFIG_SIMPLE:
set_default_configuration(presence_configuration);
sts_rss_set_current_configuration_simple(presence_configuration);
break;
case STS_RSS_CONFIG_DEFAULT|STS_RSS_CONFIG_FULL:
set_default_configuration(presence_configuration);
sts_rss_set_current_configuration_full(presence_configuration);
break;
case STS_RSS_CONFIG_FULL|STS_RSS_CONFIG_FALL_DETECTION:
set_default_fall_rise_configuration(presence_configuration);
sts_rss_set_current_configuration_full(presence_configuration);
break;
case STS_RSS_CONFIG_SIMPLE|STS_RSS_CONFIG_FALL_DETECTION:
set_default_fall_rise_configuration(presence_configuration);
sts_rss_set_current_configuration_simple(presence_configuration);
break;
default:
break;
}
// acc_detector_presence_handle_t sts_rss_handle = acc_detector_presence_create(presence_configuration);
sts_rss_handle = acc_detector_presence_create(presence_configuration);
if (sts_rss_handle == NULL)
{
APP_LOG(TS_OFF, VLEVEL_M,"Failed to create detector\n");
acc_detector_presence_configuration_destroy(&presence_configuration);
acc_detector_presence_destroy(&sts_rss_handle);
acc_rss_deactivate();
return EXIT_FAILURE;
}
if (!acc_detector_presence_activate(sts_rss_handle))
{
APP_LOG(TS_OFF, VLEVEL_M, "Failed to activate detector \n");
return false;
}
success = acc_detector_presence_get_next(sts_rss_handle, &result);
if (!success)
{
APP_LOG(TS_OFF, VLEVEL_M,"acc_detector_presence_get_next() failed\n");
}
if (!result.data_saturated)
{
if (result.presence_detected)
{
print_result(result);
sts_distance_rss_distance= result.presence_distance*1000;
}
}
return EXIT_SUCCESS;
}
int sts_presence_detector_rss_close(void)
{
sts_rss_deactivated = acc_detector_presence_deactivate(sts_rss_handle);
acc_detector_presence_destroy(&sts_rss_handle);
acc_rss_deactivate();
APP_LOG(TS_OFF, VLEVEL_M, "\r\n First Half --- Normal Motion Presence Count = %u \r\n", motion_count);
}
int sts_presence_rss_fall_rise_detection_process(void)
{
//bool success = true;
const int iterations = (DEFAULT_UPDATE_RATE_PRESENCE+1);
// acc_detector_presence_result_t result;
uint8_t average_result = 0;
float average_distance =0.0f;
float average_score =0.0f;
//uint8_t k=0;
uint16_t motion_in_zone[10]={0x0};
uint16_t detected_zone=0;
for (uint8_t k=0;k<12;k++)
motion_in_hs_zone[k][motion_detected_count]=0;
UTIL_MEM_set_8(sts_motion_dataset, 0x0, sizeof(sts_motion_dataset));
motion_count =0;
//memset((void*)motion_in_hs_zone, 0x0, 12*10);
//past 10 times of detection with 5 zones from ground to ceiling
//for (k=0; k<5; k++) {motion_in_zone[k]=0;}
if ((sts_work_mode == STS_DUAL_MODE)||(sts_work_mode == STS_RSS_MODE))
{
for (int i = 0; i < (iterations); i++)
{
success = acc_detector_presence_get_next(sts_rss_handle, &result);
if (!success)
{
APP_LOG(TS_OFF, VLEVEL_M,"acc_detector_presence_get_next() failed\n");
break;
}
//print_result(result);
if (!result.data_saturated)
{
//APP_LOG(TS_OFF, VLEVEL_H,"\n%u ", i);
//print_result(result);
if (result.presence_detected)
{
//print_result(result);
average_result++;
average_distance += result.presence_distance;
average_score += result.presence_score;
//detected_zone = (uint16_t)((float)(result.presence_distance - DEFAULT_START_M) / (float)DEFAULT_ZONE_LENGTH);
//2024-08-05
detected_zone = (uint16_t)((float)(result.presence_distance) / (float)DEFAULT_ZONE_LENGTH);
motion_in_zone[detected_zone]++;
// new add 2024-06-18
//detected_hs_zone = (uint16_t)((float)(sts_sensor_install_height/1000.0f - (result.presence_distance))/(float)DEFAULT_ZONE_LENGTH);
//if (detected_hs_zone == 0)
//APP_LOG(TS_OFF, VLEVEL_L, "\r\nPresence_Distance=%u \r\n", (int)result.presence_distance*1000.0);
//APP_LOG(TS_OFF, VLEVEL_L, "\r\nHS_ZONE=%u", (int)detected_hs_zone);
//detected_hs_zone = 12 - detected_zone;
detected_hs_zone = (sts_sensor_install_height/1000)/(DEFAULT_ZONE_LENGTH) - detected_zone;
//motion_in_hs_zone[detected_hs_zone][(motion_detected_count)]++;
motion_in_hs_zone[detected_hs_zone][motion_detected_count]++;
sts_motion_dataset[motion_count].presence_distance = 1000*result.presence_distance;
sts_motion_dataset[motion_count].presence_score = 1000*result.presence_score;
motion_count++;
}
}
//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
}
}
else if ((sts_work_mode == STS_UNI_MODE))
{
// set to full length of iteration
for (int i = 0; i < (iterations); i++)
{
success = acc_detector_presence_get_next(sts_rss_handle, &result);
if (!success)
{
APP_LOG(TS_OFF, VLEVEL_M,"acc_detector_presence_get_next() failed\n");
break;
}
if (!result.data_saturated)
{
//APP_LOG(TS_OFF, VLEVEL_L,"\n%u ", i);
//print_result(result);
if ((result.presence_detected) && (result.presence_score > DEFAULT_THRESHOLD))
{
//print_result(result);
average_result++;
average_distance += result.presence_distance;
average_score += result.presence_score;
//detected_zone = (uint16_t)((float)(result.presence_distance - DEFAULT_START_M) / (float)DEFAULT_ZONE_LENGTH);
// 2024-08-05
detected_zone = (uint16_t)((float)(result.presence_distance) / (float)DEFAULT_ZONE_LENGTH);
motion_in_zone[detected_zone]++;
// new add 2024-06-18
//detected_hs_zone = (uint16_t)((float)(sts_sensor_install_height/1000.0f - (result.presence_distance))/(float)DEFAULT_ZONE_LENGTH);
//if (detected_hs_zone == 0)
//APP_LOG(TS_OFF, VLEVEL_L, "\r\nPresence_Distance=%u \r\n", (int)result.presence_distance*1000.0);
//APP_LOG(TS_OFF, VLEVEL_L, "\r\nHS_ZONE=%u", detected_hs_zone);
//(sts_sensor_install_height/1000)/(DEFAULT_ZONE_LENGTH)
detected_hs_zone = (sts_sensor_install_height/1000)/(DEFAULT_ZONE_LENGTH) - detected_zone;
//motion_in_hs_zone[detected_hs_zone][(motion_detected_count)]++;
motion_in_hs_zone[detected_hs_zone][motion_detected_count]++;
sts_motion_dataset[motion_count].presence_distance = 1000*result.presence_distance;
sts_motion_dataset[motion_count].presence_score = 1000*result.presence_score;
motion_count++;
}
}
// ~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
}
}
}
/*
*
* OUTPUT: sts_rss_result = STS_PRESENCE_MOTION, STS_PRESENCE_NO_MOTION
@ -343,7 +598,7 @@ int sts_presence_rss_fall_rise_detection(void)
if (!acc_rss_activate(hal))
{
APP_LOG(TS_OFF, VLEVEL_H,"Failed to activate RSS\n");
APP_LOG(TS_OFF, VLEVEL_L,"Failed to activate RSS\n");
return EXIT_FAILURE;
}
@ -352,7 +607,7 @@ int sts_presence_rss_fall_rise_detection(void)
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");
APP_LOG(TS_OFF, VLEVEL_L,"Failed to create configuration\n");
acc_rss_deactivate();
return EXIT_FAILURE;
}
@ -360,48 +615,48 @@ int sts_presence_rss_fall_rise_detection(void)
switch (sts_rss_config_updated_flag)
{
case STS_RSS_CONFIG_NON:
APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Non *** cfg \n");
return EXIT_SUCCESS;
break;
case STS_RSS_CONFIG_DEFAULT:
set_default_configuration(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_H,"\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");
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");
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");
break;
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;
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_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;
default:
break;
@ -411,7 +666,7 @@ int sts_presence_rss_fall_rise_detection(void)
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");
APP_LOG(TS_OFF, VLEVEL_L,"Failed to create detector\n");
acc_detector_presence_configuration_destroy(&presence_configuration);
acc_detector_presence_destroy(&handle);
acc_rss_deactivate();
@ -421,7 +676,7 @@ int sts_presence_rss_fall_rise_detection(void)
if (!acc_detector_presence_activate(handle))
{
APP_LOG(TS_OFF, VLEVEL_H, "Failed to activate detector \n");
APP_LOG(TS_OFF, VLEVEL_L, "Failed to activate detector \n");
return false;
}
bool deactivated = false;
@ -452,7 +707,7 @@ int sts_presence_rss_fall_rise_detection(void)
success = acc_detector_presence_get_next(handle, &result);
if (!success)
{
APP_LOG(TS_OFF, VLEVEL_H,"acc_detector_presence_get_next() failed\n");
APP_LOG(TS_OFF, VLEVEL_L,"acc_detector_presence_get_next() failed\n");
break;
}
@ -498,7 +753,7 @@ int sts_presence_rss_fall_rise_detection(void)
acc_detector_presence_destroy(&handle);
acc_rss_deactivate();
APP_LOG(TS_OFF, VLEVEL_M, "\r\n First Half --- Motion Count = %u \r\n", motion_count);
APP_LOG(TS_OFF, VLEVEL_L, "\r\n First Half --- Normal Motion Presence Count = %u \r\n", motion_count);
//acc_detector_presence_deactivate(handle);
}
@ -538,7 +793,7 @@ int sts_presence_rss_fall_rise_detection(void)
success = acc_detector_presence_get_next(handle, &result);
if (!success)
{
APP_LOG(TS_OFF, VLEVEL_H,"acc_detector_presence_get_next() failed\n");
APP_LOG(TS_OFF, VLEVEL_L,"acc_detector_presence_get_next() failed\n");
break;
}
@ -586,7 +841,7 @@ int sts_presence_rss_fall_rise_detection(void)
acc_rss_deactivate();
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Second Half --- Motion Count Sum to = %u \r\n", motion_count);
APP_LOG(TS_OFF, VLEVEL_L, "\r\n Second Half --- Free Fall Down Detection Count Sum to = %u \r\n", motion_count);
//APP_LOG(TS_OFF, VLEVEL_L,"Second Half, Fall Rise Detection, Motion Count = %u \r\n", (int)motion_count);
@ -607,7 +862,9 @@ 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;
// uint8_t pre_sts_rss_result = (average_result > (DEFAULT_UPDATE_RATE_PRESENCE/20))? 1: 0; // 2025-03-20 update
uint8_t pre_sts_rss_result = (average_result > 15) ? 1: 0; // 2025-03-20 update
sts_rss_result=STS_RSS_Filter(pre_sts_rss_result);
if (sts_rss_result) //if (average_score !=0) //if (sts_rss_result)
@ -703,7 +960,7 @@ void STS_YunhornCheckStandardDeviation(void)
uint32_t roc_acc[DEFAULT_MOTION_DATASET_LEN]={0}, sum_roc_acc=0, average_roc_acc=0, variance_roc_acc=0, standard_variance_roc_acc=0;
//act as speed of change at given time slot acc_integration_sleep_ms(1000 / DEFAULT_UPDATE_RATE_PRESENCE);
uint8_t SAMPLE_DATASET_NUM = MIN(motion_count,DEFAULT_MOTION_DATASET_LEN );
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Sample dataset for deviation process =%u \r\n",SAMPLE_DATASET_NUM);
APP_LOG(TS_OFF, VLEVEL_L, "\r\n Sample dataset for deviation process =%u \r\n",SAMPLE_DATASET_NUM);
// initial state
sts_fall_rising_detected_result = STS_PRESENCE_NORMAL;
@ -730,7 +987,7 @@ void STS_YunhornCheckStandardDeviation(void)
//STANDARD VARIANCE sigma
standard_variance_presence_distance = (uint32_t)sqrt(sum_presence_distance/SAMPLE_DATASET_NUM);
standard_variance_presence_score = (uint32_t)sqrt(sum_presence_score/SAMPLE_DATASET_NUM);
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Standard Variance_Presence_Distance=%u \r\n Standard Variance Presence Score=%u\r\n",
APP_LOG(TS_OFF, VLEVEL_L, "\r\n Standard Variance_Presence_Distance=%u \r\n Standard Variance Presence Score=%u\r\n",
standard_variance_presence_distance, standard_variance_presence_score);
// ROC distance
@ -785,11 +1042,11 @@ void STS_YunhornCheckStandardDeviation(void)
#endif
// print result
//#ifdef LOG_RSS
APP_LOG(TS_OFF, VLEVEL_M, "\r\n---Sensor Install Height=%4u (mm)-----\r\n-------------Distance Average =%6u (mm); Standard_Variance =%04u (mm)\r\n",
APP_LOG(TS_OFF, VLEVEL_L, "\r\n---Sensor Install Height=%4u (mm)-----\r\n-------------Distance Average =%6u (mm); Standard_Variance =%04u (mm)\r\n",
(int)sts_sensor_install_height, (int)(average_presence_distance), (int)(standard_variance_presence_distance));
//#endif
//#ifdef LOG_RSS
APP_LOG(TS_OFF, VLEVEL_M, "\r\n\n-------------Motion Average (score)=%04u; Standard_Variance (score)=%04u \r\n",
APP_LOG(TS_OFF, VLEVEL_L, "\r\n\n-------------Motion Average (score)=%04u; Standard_Variance (score)=%04u \r\n",
(int)(average_presence_score), (int)(standard_variance_presence_score));
sts_o7_sensorData.event_sensor3_fall_distance =(uint16_t)average_presence_distance;
@ -797,10 +1054,10 @@ void STS_YunhornCheckStandardDeviation(void)
//#endif
//#ifdef LOG_RSS
APP_LOG(TS_OFF, VLEVEL_M, "\r\n-------------ROC Dist Average (mm/s) =%6u; Standard_Variance =%6u (mm/s)\r\n",
APP_LOG(TS_OFF, VLEVEL_L, "\r\n-------------ROC Dist Average (mm/s) =%6u; Standard_Variance =%6u (mm/s)\r\n",
(int)(average_roc_distance), (int)(standard_variance_roc_distance));
APP_LOG(TS_OFF, VLEVEL_M, "\r\n-------------ROC ACC Average =%6u (mm/s2); Standard_Variance =%6u (mm/s2)\r\n",
APP_LOG(TS_OFF, VLEVEL_L, "\r\n-------------ROC ACC Average =%6u (mm/s2); Standard_Variance =%6u (mm/s2)\r\n",
(int)(average_roc_acc), (int)(standard_variance_roc_acc));
//sts_fall_rising_pattern_factor1 = (int)(standard_variance_roc_distance);
@ -814,13 +1071,13 @@ void STS_YunhornCheckStandardDeviation(void)
APP_LOG(TS_OFF, VLEVEL_L,"\r\nAvg-Dist =%6u (mm), Last_AVG-Dist =%6u (mm)\r\n", (int)(average_presence_distance), (int)(last_average_presence_distance));
APP_LOG(TS_OFF, VLEVEL_L,"\r\nStandard Variance Presence_score =%u (score)\r\n", (int)(standard_variance_presence_score));
APP_LOG(TS_OFF, VLEVEL_M, "\r\nThreshold 1: Acc = %6u (mm/s) ---- Measure 1 = %6u (mm/s)---- \r\n",
APP_LOG(TS_OFF, VLEVEL_L, "\r\nThreshold 1: Acc = %6u (mm/s) ---- Measure 1 = %6u (mm/s)---- \r\n",
(int)(sts_fall_detection_acc_threshold), (int)(sts_fall_rising_pattern_factor1));
APP_LOG(TS_OFF, VLEVEL_M, "\r\nThreshold 2: Dis = %6u (cm) --- Measure 2 = %6u (cm) ---- \r\n",
APP_LOG(TS_OFF, VLEVEL_L, "\r\nThreshold 2: Dis = %6u (cm) --- Measure 2 = %6u (cm) ---- \r\n",
(int)(sts_fall_detection_depth_threshold), (int)(sts_fall_rising_pattern_factor2/10));
APP_LOG(TS_OFF, VLEVEL_M, "\r\nMeasure 3 = %6u (score) ---- \r\n", (int)(sts_fall_rising_pattern_factor3));
APP_LOG(TS_OFF, VLEVEL_L, "\r\nMeasure 3 = %6u (score) ---- \r\n", (int)(sts_fall_rising_pattern_factor3));
//#endif
// *******************************************

View File

@ -69,7 +69,7 @@ volatile uint16_t sts_sensor_install_height=0;//in mm
volatile uint16_t sts_distance_rss_distance=0;//in mm
extern volatile float sts_presence_rss_distance, sts_presence_rss_score;
volatile uint8_t sts_rss_config_updated_flag = STS_RSS_CONFIG_NON;
volatile uint8_t sts_rss_config_updated_flag = STS_RSS_CONFIG_SIMPLE;
extern volatile uint8_t sts_occupancy_overtime_state;
extern volatile distance_measure_cfg_t distance_cfg;
extern volatile uint16_t sts_fall_rising_pattern_factor1;
@ -290,7 +290,8 @@ void STS_YunhornSTSEventP2_Process(void)
break;
}
sts_presence_rss_fall_rise_detection();
// sts_presence_rss_fall_rise_detection();
sts_presence_rss_fall_rise_detection_process();
sts_rss_result_changed_flag = (sts_rss_result == last_sts_rss_result)? 0:1;
@ -939,8 +940,7 @@ void STS_PRESENCE_SENSOR_Init(void)
//STS_PRESENCE_SENSOR_REEDSWITCH_HALL_Init();
//STS_PRESENCE_SENSOR_TOF_Init();
//HAL_Delay(2000);
//STS_PRESENCE_SENSOR_Distance_Measure_Process();
STS_PRESENCE_SENSOR_Distance_Measure_Process();
}
@ -960,8 +960,17 @@ void STS_PRESENCE_SENSOR_RSS_Init(void)
#ifdef USE_ACCONEER_A111
APP_LOG(TS_ON, VLEVEL_H, "##### YunHorn SmarToilets(r) MEMS RSS Initializing \r\n");
// PME_ON;
PME_ON;
uint8_t exit_status =0;
//exit_status=sts_distance_rss_detector_distance();
//sts_rss_config_updated_flag |= STS_RSS_CONFIG_FALL_DETECTION;
//sts_presence_detector_rss_start();
#if 0
//if ((sts_distance_rss_distance==0)&&(sts_sensor_install_height==0))
{
uint8_t exit_status =0;
@ -978,6 +987,9 @@ void STS_PRESENCE_SENSOR_RSS_Init(void)
sts_sensor_install_height = (uint16_t)sts_distance_rss_distance;
}
#endif
sts_sensor_install_height = (uint16_t)sts_distance_rss_distance;
STS_PRESENCE_SENSOR_NVM_CFG();
@ -1010,7 +1022,7 @@ void STS_PRESENCE_SENSOR_Distance_Measure_Process(void)
do
{
exit_status = sts_distance_rss_detector_distance();
HAL_Delay(100);
// HAL_Delay(100);
i++;
} while ((exit_status == EXIT_FAILURE) && (i < 2));
#endif
@ -1042,15 +1054,18 @@ void STS_PRESENCE_SENSOR_Function_Test_Process(uint8_t *self_test_result, uint8_
STS_Lamp_Bar_Self_Test_Simple();
sts_lamp_bar_color = STS_PINK;
STS_Lamp_Bar_Refresh();
HAL_Delay(1000);
HAL_Delay(200);
sts_presence_rss_bring_up_test(bring_up_result);
HAL_Delay(1000);
HAL_Delay(200);
STS_PRESENCE_SENSOR_Distance_Measure_Process();
sts_lamp_bar_color = STS_GREEN;
STS_Lamp_Bar_Refresh();
}
HAL_Delay(1000);
HAL_Delay(200);
UTIL_MEM_cpy_8(self_test_result, bring_up_result, 10);
@ -1065,7 +1080,7 @@ 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

View File

@ -37,6 +37,7 @@
#include "flash_if.h"
#include "main.h"
#include <stdio.h>
#include "timer_if.h"
#ifdef CLOCK_SYNC
#include "LmhpClockSync.h"
#endif
@ -77,7 +78,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;
@ -585,8 +586,9 @@ void LoRaWAN_Init(void)
/* USER CODE END LoRaWAN_Init_LV */
/* USER CODE BEGIN LoRaWAN_Init_1 */
APP_LOG(TS_OFF, VLEVEL_M, "\r\n\n\n##### YUNHORN_STS_SWV%d HWV:%d MTM:%d.%d R:%d.%d.%d####\r\n\n\n",
sts_version, sts_hardware_ver, sts_mtmcode1,sts_mtmcode2, MajorVer, MinorVer, SubMinorVer);
APP_LOG(TS_OFF, VLEVEL_M, "\n\r# YUNHORN SMARTOILETS: (%s) MTM:%d.%d HWFW:%d.%d V:%d.%d.%d #\n\r",(char*)YUNHORN_STS_PRD_STRING,
(uint8_t)sts_mtmcode1, (uint8_t)sts_mtmcode2,(uint8_t)sts_hardware_ver,(uint8_t)FirmwareVersion,
(uint8_t)MajorVer,(uint8_t)MinorVer,(uint8_t)SubMinorVer);
/* Get LoRaWAN APP version*/
APP_LOG(TS_OFF, VLEVEL_M, "APPLICATION_VERSION: V%X.%X.%X\r\n",
@ -662,6 +664,10 @@ void LoRaWAN_Init(void)
LmHandlerJoin(ActivationType, ForceRejoin);
UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, YUNHORN_STS_HEART_BEAT_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL);
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
if (EventType == TX_ON_TIMER)
{
/* send every time timer elapses */
@ -693,15 +699,14 @@ void LoRaWAN_Init(void)
#endif
#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_Start(&YunhornSTSRSSWakeUpTimer);
UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, YUNHORN_STS_HEART_BEAT_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL);
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
//UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, YUNHORN_STS_HEART_BEAT_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL);
//UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
UTIL_TIMER_Start(&STSLampBarColorTimer);
//UTIL_TIMER_Start(&STSDurationCheckTimer);
UTIL_TIMER_Start(&STSDurationCheckTimer);
#else
#if 0
@ -1443,11 +1448,13 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
AppData.Port = 1;
AppData.BufferSize = 16;
UTIL_MEM_cpy_8((uint8_t*)AppData.Buffer, (uint8_t *)YUNHORN_STS_PRD_STRING, sizeof(YUNHORN_STS_PRD_STRING));
AppData.BufferSize = sizeof(YUNHORN_STS_PRD_STRING);
AppData.BufferSize = sizeof(YUNHORN_STS_PRD_STRING) -1;
LmHandlerParams.IsTxConfirmed = true;
LmHandlerErrorStatus_t status = LmHandlerSend(&AppData, LmHandlerParams.IsTxConfirmed, false);
if (status ==LORAMAC_HANDLER_SUCCESS ) LmHandlerParams.IsTxConfirmed = false;
STS_SENSOR_Distance_Test_Process();
}
else
{
@ -1457,11 +1464,11 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
APP_LOG(TS_OFF, VLEVEL_H, "###### U/L FRAME:JOIN | DR:%d | PWR:%d\r\n", joinParams->Datarate, joinParams->TxPower);
}
#if 0
if (STS_LoRa_WAN_Joined)
{
heart_beat_timer = 1;
//SendTxData();
//UTIL_TIMER_Start(&TxTimer);
UTIL_TIMER_Start(&STSDurationCheckTimer);
OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity);
@ -1469,6 +1476,7 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
//UTIL_TIMER_Create(&YunhornSTSRSSWakeUpTimer, YUNHORN_STS_RSS_WAKEUP_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSOORSSWakeUpTimerEvent, NULL);
STS_SENSOR_Distance_Test_Process();
//STS_SENSOR_Function_Test_Process();
#ifdef USE_ACCONEER_A111
APP_LOG(TS_OFF, VLEVEL_H, "\r\nRSS Measured Distance=[%u] mm \r\n", (uint16_t)sts_distance_rss_distance);
#elif defined(STS_P2)
@ -1479,6 +1487,8 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
}
#endif
/* USER CODE END OnJoinRequest_1 */
}
@ -2102,7 +2112,7 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
APP_LOG(TS_OFF, VLEVEL_M, "LTIME:%02dh%02dm%02ds on %02d/%02d/%04d\r\n",
localtime.tm_hour, localtime.tm_min, localtime.tm_sec,
localtime.tm_mday, localtime.tm_mon + 1, localtime.tm_year + 1900);
#if 0
#if 1
LmhPackage_t LmhpClockSyncPackageFactory;
LmhpClockSyncPackageFactory.Init;
@ -2602,7 +2612,7 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
#if 1
for (j =0; j < CFG_CMD_RSS_SIMPLE_SIZE-3; j++)
{
if ((tlv_buf[CFG_CMD4+j] < '0') || (tlv_buf[CFG_CMD4+j] >'9'))
if ((tlv_buf[CFG_CMD4+j] >= '0') || (tlv_buf[CFG_CMD4+j] <= '9'))
{
//sts_cfg_nvm.p[j] = (uint8_t)((tlv_buf[CFG_CMD4+j] - 0x30)&0xff);
@ -3036,7 +3046,7 @@ 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_RSS_Init();
}
#endif
//STS_SENSOR_Distance_Test_Process();
@ -3082,9 +3092,15 @@ 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");
PME_ON;
HAL_Delay(400);
STS_SENSOR_MEMS_Get_ID(mems_Dev_ID);
APP_LOG(TS_OFF, VLEVEL_M, "\r\n MEMS Dev ID=%02x %02X", mems_Dev_ID[0], mems_Dev_ID[1]);
if ((mems_Dev_ID[0]==0X0) && (mems_Dev_ID[1]==0x0)) {
tstbuf[i++] = (uint8_t) 'X'; // Slave MEMS Not Avaliable
}

View File

@ -155,7 +155,7 @@
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols.2024044405" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
<listOptionValue builtIn="false" value="CORE_CM4"/>
<listOptionValue builtIn="false" value="CLOCK_SYNC"/>
<listOptionValue builtIn="false" value="RM2"/>
<listOptionValue builtIn="false" value="RM2_1"/>
<listOptionValue builtIn="false" value="STS_O7"/>
<listOptionValue builtIn="false" value="YUNHORN_STS_RANDOM"/>
<listOptionValue builtIn="false" value="STM32WLE5xx"/>

Binary file not shown.