--- revised for shorter interval to 1 sec

This commit is contained in:
Yunhorn 2024-08-22 20:28:28 +08:00
parent 4c68db4475
commit 6b286bfa21
4 changed files with 133 additions and 23 deletions

View File

@ -764,7 +764,7 @@ void STS_PRESENCE_SENSOR_Function_Test_Process(uint8_t *self_test_result, uint8_
void STS_PRESENCE_SENSOR_Distance_Measure_Process(void); void STS_PRESENCE_SENSOR_Distance_Measure_Process(void);
float KalmanFilter(float inData); float KalmanFilter(float inData);
uint8_t STS_RSS_Filter(uint8_t pre_sts_rss_result);
/* USER CODE BEGIN Private defines */ /* USER CODE BEGIN Private defines */
/* /*
In this example TIM2 input clock (TIM2CLK) is set to APB1 clock (PCLK1), In this example TIM2 input clock (TIM2CLK) is set to APB1 clock (PCLK1),

View File

@ -359,48 +359,48 @@ int sts_presence_rss_fall_rise_detection(void)
switch (sts_rss_config_updated_flag) switch (sts_rss_config_updated_flag)
{ {
case STS_RSS_CONFIG_NON: case STS_RSS_CONFIG_NON:
APP_LOG(TS_OFF, VLEVEL_M,"\r\n##### YUNHORN STS *** Non *** cfg \n"); APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Non *** cfg \n");
return EXIT_SUCCESS; return EXIT_SUCCESS;
break; break;
case STS_RSS_CONFIG_DEFAULT: case STS_RSS_CONFIG_DEFAULT:
set_default_configuration(presence_configuration); set_default_configuration(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n##### YUNHORN STS *** Default *** cfg applied\n"); APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Default *** cfg applied\n");
break; break;
case STS_RSS_CONFIG_SIMPLE: case STS_RSS_CONFIG_SIMPLE:
sts_rss_set_current_configuration_simple(presence_configuration); sts_rss_set_current_configuration_simple(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n##### YUNHORN STS *** Simple *** cfg applied\n"); APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Simple *** cfg applied\n");
break; break;
case STS_RSS_CONFIG_FULL: case STS_RSS_CONFIG_FULL:
sts_rss_set_current_configuration_full(presence_configuration); sts_rss_set_current_configuration_full(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n######### YUNHORN STS *** FULL *** cfg applied\n"); APP_LOG(TS_OFF, VLEVEL_H,"\r\n######### YUNHORN STS *** FULL *** cfg applied\n");
break; break;
case STS_RSS_CONFIG_FALL_DETECTION: case STS_RSS_CONFIG_FALL_DETECTION:
set_default_fall_rise_configuration(presence_configuration); set_default_fall_rise_configuration(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n######### YUNHORN STS *** FALL DETECTION *** cfg applied\n"); APP_LOG(TS_OFF, VLEVEL_H,"\r\n######### YUNHORN STS *** FALL DETECTION *** cfg applied\n");
break; break;
case STS_RSS_CONFIG_DEFAULT|STS_RSS_CONFIG_SIMPLE: case STS_RSS_CONFIG_DEFAULT|STS_RSS_CONFIG_SIMPLE:
set_default_configuration(presence_configuration); set_default_configuration(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n##### YUNHORN STS *** Default *** cfg applied\n"); APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Default *** cfg applied\n");
sts_rss_set_current_configuration_simple(presence_configuration); sts_rss_set_current_configuration_simple(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n##### YUNHORN STS *** Simple *** cfg applied\n"); APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Simple *** cfg applied\n");
break; break;
case STS_RSS_CONFIG_DEFAULT|STS_RSS_CONFIG_FULL: case STS_RSS_CONFIG_DEFAULT|STS_RSS_CONFIG_FULL:
set_default_configuration(presence_configuration); set_default_configuration(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n##### YUNHORN STS *** Default *** cfg applied\n"); APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Default *** cfg applied\n");
sts_rss_set_current_configuration_full(presence_configuration); sts_rss_set_current_configuration_full(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n######### YUNHORN STS *** FULL *** cfg applied\n"); APP_LOG(TS_OFF, VLEVEL_H,"\r\n######### YUNHORN STS *** FULL *** cfg applied\n");
break; break;
case STS_RSS_CONFIG_FULL|STS_RSS_CONFIG_FALL_DETECTION: case STS_RSS_CONFIG_FULL|STS_RSS_CONFIG_FALL_DETECTION:
set_default_fall_rise_configuration(presence_configuration); set_default_fall_rise_configuration(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n######### YUNHORN STS *** FALL DETECTION *** cfg applied\n"); APP_LOG(TS_OFF, VLEVEL_H,"\r\n######### YUNHORN STS *** FALL DETECTION *** cfg applied\n");
sts_rss_set_current_configuration_full(presence_configuration); sts_rss_set_current_configuration_full(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n######### YUNHORN STS *** FULL *** cfg applied\n"); APP_LOG(TS_OFF, VLEVEL_H,"\r\n######### YUNHORN STS *** FULL *** cfg applied\n");
break; break;
case STS_RSS_CONFIG_SIMPLE|STS_RSS_CONFIG_FALL_DETECTION: case STS_RSS_CONFIG_SIMPLE|STS_RSS_CONFIG_FALL_DETECTION:
set_default_fall_rise_configuration(presence_configuration); set_default_fall_rise_configuration(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n##### YUNHORN STS *** Default *** cfg applied\n"); APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Default *** cfg applied\n");
sts_rss_set_current_configuration_simple(presence_configuration); sts_rss_set_current_configuration_simple(presence_configuration);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n##### YUNHORN STS *** Simple *** cfg applied\n"); APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Simple *** cfg applied\n");
break; break;
default: default:
break; break;
@ -489,8 +489,8 @@ 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(1000 / DEFAULT_UPDATE_RATE_PRESENCE); // 15ms, DEFAULT_UPDATE_RATE);
acc_integration_sleep_ms(10); // --- around 1500 ms in total //acc_integration_sleep_ms(10); // --- around 1500 ms in total
//acc_integration_sleep_ms(2); acc_integration_sleep_ms(2); //--- around 1000ms in total
} }
deactivated = acc_detector_presence_deactivate(handle); deactivated = acc_detector_presence_deactivate(handle);
@ -577,15 +577,15 @@ int sts_presence_rss_fall_rise_detection(void)
} }
// ~12 ms per RSS scan // ~12 ms per RSS scan
// acc_integration_sleep_ms(1000 / DEFAULT_UPDATE_RATE_PRESENCE); // 15 ms, DEFAULT_UPDATE_RATE); // 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(10); //--- around 1500 ms in total
//acc_integration_sleep_ms(2); //--- around 1000ms in total acc_integration_sleep_ms(2); //--- around 1000ms in total
} }
deactivated = acc_detector_presence_deactivate(handle); deactivated = acc_detector_presence_deactivate(handle);
acc_detector_presence_destroy(&handle); acc_detector_presence_destroy(&handle);
acc_rss_deactivate(); acc_rss_deactivate();
APP_LOG(TS_OFF, VLEVEL_H, "\r\n Second Half --- Motion Count Sum to = %u \r\n", motion_count); 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,"Second Half, Fall Rise Detection, Motion Count = %u \r\n", (int)motion_count); //APP_LOG(TS_OFF, VLEVEL_L,"Second Half, Fall Rise Detection, Motion Count = %u \r\n", (int)motion_count);
@ -606,7 +606,8 @@ int sts_presence_rss_fall_rise_detection(void)
sts_presence_rss_distance = average_distance; sts_presence_rss_distance = average_distance;
sts_presence_rss_score = average_score; sts_presence_rss_score = average_score;
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;
sts_rss_result=STS_RSS_Filter(pre_sts_rss_result);
if (sts_rss_result) //if (average_score !=0) //if (sts_rss_result) if (sts_rss_result) //if (average_score !=0) //if (sts_rss_result)
{ {

View File

@ -1368,6 +1368,114 @@ float KalmanFilter(float inData)
} }
#if 0
uint8_t Radar_Data_Analysis(void)
{
uint8_t xReturn = 0;
const char* person = "Motion ";
const char* noperson = "No motion";
if(Radar_Data_Flag == 1)
{
if(strncmp((char *)USART3_RX_Buffer,person,strlen(person)) == 0){
xReturn = 1;
}
else if( strncmp((char *)USART3_RX_Buffer,noperson,strlen(noperson)) == 0){
xReturn = 0;
}
}
return xReturn;
}
void Radar_Filtering_clutter(volatile uint8_t *color)
{
_Bool pNew_Motion_Flag = 0;
static uint8_t Motion_Changed_Flag = 0;
static uint8_t numerator = 0;
static uint8_t denominator = 0;
pNew_Motion_Flag = Radar_Data_Analysis();
if(pNew_Motion_Flag != Motion_Flag){
Motion_Changed_Flag = 1;
}
if(Motion_Changed_Flag == 1)
{
denominator++;
if(pNew_Motion_Flag != Motion_Flag){
numerator++;
}
if(denominator >= Preset_denominator)
{
if(numerator >= Preset_numerator) //的确改变
{
Motion_Flag = !Motion_Flag;
if(Motion_Flag)
{
//M100C_Send_Data(10,0,ZhanYong);
*color = 2;
}
else
{
//M100C_Send_Data(10,0,KeYong);
*color = 1;
}
}
denominator = 0;
numerator = 0;
Motion_Changed_Flag = 0;
}
}
}
#endif
#define PRESET_DENOMINATOR 8
#define PRESET_NUMERATOR 5
uint8_t STS_RSS_Filter(uint8_t pre_sts_rss_result)
{
_Bool pNew_Motion_Flag = 0;
static uint8_t Motion_Changed_Flag = 0;
static uint8_t numerator = 0;
static uint8_t denominator = 0;
uint8_t Motion_Flag = sts_rss_result, xReturn=0;
pNew_Motion_Flag = pre_sts_rss_result;
if(pNew_Motion_Flag != Motion_Flag){
Motion_Changed_Flag = 1;
}
if(Motion_Changed_Flag == 1)
{
denominator++;
if(pNew_Motion_Flag != Motion_Flag){
numerator++;
}
if(denominator >= PRESET_DENOMINATOR)
{
if(numerator >= PRESET_NUMERATOR) //SURE CHANGED
{
Motion_Flag = !Motion_Flag;
if(Motion_Flag)
{
//M100C_Send_Data(10,0,ZhanYong);
xReturn = 1;
}
else
{
//M100C_Send_Data(10,0,KeYong);
xReturn = 0;
}
}
denominator = 0;
numerator = 0;
Motion_Changed_Flag = 0;
}
}
return xReturn;
}
/* USER CODE BEGIN EF */ /* USER CODE BEGIN EF */

View File

@ -75,7 +75,7 @@ extern volatile uint32_t event_start_time, event_stop_time;
extern volatile uint16_t sts_unconscious_threshold; extern volatile uint16_t sts_unconscious_threshold;
volatile uint8_t sts_occupancy_overtime_state = 0; volatile uint8_t sts_occupancy_overtime_state = 0;
volatile uint8_t sts_presence_fall_detection=FALSE; volatile uint8_t sts_presence_fall_detection=FALSE;
volatile uint32_t SamplingPeriodicity = 3000; //unit ms volatile uint32_t SamplingPeriodicity = 1000; //unit ms
volatile uint32_t HeartBeatPeriodicity = 120000; //unit ms volatile uint32_t HeartBeatPeriodicity = 120000; //unit ms
volatile uint8_t STS_LoRa_WAN_Joined = 0; volatile uint8_t STS_LoRa_WAN_Joined = 0;
@ -93,7 +93,7 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = {
sts_hardware_ver, sts_hardware_ver,
0x05, 0x05,
'M', //Uplink data interval for heart-beat uplink 'M', //Uplink data interval for heart-beat uplink
0x03, 0x01,
'S', //Sampling sensor interval for real-time sensing of MEMS 'S', //Sampling sensor interval for real-time sensing of MEMS
0x04, // dual mode=4, uni_mode =5 0x04, // dual mode=4, uni_mode =5
0x00, // sts service mask 0x00, // sts service mask
@ -1110,7 +1110,8 @@ static void SendTxData(void)
} }
} }
//else { APP_LOG(TS_OFF, VLEVEL_M, "\r\n ######## LmHandlerIsBusy ************** \r\n"); } //else { APP_LOG(TS_OFF, VLEVEL_M, "\r\n ######## LmHandlerIsBusy ************** \r\n"); }
heart_beat_timer = 0;
sensor_data_ready = 0;
if ((EventType == TX_ON_TIMER)) //||((EventType == TX_ON_EVENT)&&(nextTxIn >0))) if ((EventType == TX_ON_TIMER)) //||((EventType == TX_ON_EVENT)&&(nextTxIn >0)))
{ {
UTIL_TIMER_Stop(&TxTimer); UTIL_TIMER_Stop(&TxTimer);