|
|
@ -140,6 +140,17 @@ extern volatile uint8_t sensor_data_ready;
|
|
|
|
extern volatile STS_OO_SensorStatusDataTypeDef sts_o7_sensorData;
|
|
|
|
extern volatile STS_OO_SensorStatusDataTypeDef sts_o7_sensorData;
|
|
|
|
extern volatile float sts_distance_rss_distance, sts_sensor_install_height;
|
|
|
|
extern volatile float sts_distance_rss_distance, sts_sensor_install_height;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//#define STS_Status_Door_Close (1) //Normal Close NC:Open **2024-07-15 changed
|
|
|
|
|
|
|
|
//#define STS_Status_Door_Open (0) //Normal Close NC:Close **2024-07-15 changed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char sts_door_status_code[2][10]={
|
|
|
|
|
|
|
|
"Close",
|
|
|
|
|
|
|
|
"Open "
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
char sts_sos_status_code[2][10]={
|
|
|
|
|
|
|
|
"PushDown",
|
|
|
|
|
|
|
|
"No_Push"
|
|
|
|
|
|
|
|
};
|
|
|
|
char sts_lamp_color_code[15][15]={
|
|
|
|
char sts_lamp_color_code[15][15]={
|
|
|
|
"Dark",
|
|
|
|
"Dark",
|
|
|
|
"Green",
|
|
|
|
"Green",
|
|
|
@ -670,6 +681,7 @@ void LoRaWAN_Init(void)
|
|
|
|
UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL);
|
|
|
|
UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL);
|
|
|
|
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
|
|
|
|
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UTIL_TIMER_Start(&STSDurationCheckTimer);
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
UTIL_TIMER_Create(&YunhornSTSSamplingCheckTimer,
|
|
|
|
UTIL_TIMER_Create(&YunhornSTSSamplingCheckTimer,
|
|
|
@ -690,17 +702,19 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
|
|
|
case HALL1_Pin:
|
|
|
|
case HALL1_Pin:
|
|
|
|
if (sts_reed_hall_1_changed)
|
|
|
|
if (sts_reed_hall_1_changed)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HAL_Delay(30); //de-bouncing
|
|
|
|
|
|
|
|
sts_hall1_read = HALL1_STATE;
|
|
|
|
sts_hall1_read = HALL1_STATE;
|
|
|
|
|
|
|
|
HAL_Delay(30); //de-bouncing
|
|
|
|
|
|
|
|
|
|
|
|
if (sts_hall1_read == HALL1_STATE)
|
|
|
|
if (sts_hall1_read == HALL1_STATE)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SysTime_t current_event_time = SysTimeGetMcuTime();
|
|
|
|
SysTime_t current_event_time = SysTimeGetMcuTime();
|
|
|
|
if ((last_sts_hall1_read !=sts_hall1_read) && ((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_start_time)>5)&&((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_stop_time)>5))
|
|
|
|
if ((last_sts_hall1_read !=sts_hall1_read) && ((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_start_time)>5)
|
|
|
|
|
|
|
|
&&((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_stop_time)>5))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_start_time) > 5) || ((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_stop_time) > 5))
|
|
|
|
//if (((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_start_time) > 5) || ((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_stop_time) > 5))
|
|
|
|
// if (last_sts_hall1_read !=sts_hall1_read)
|
|
|
|
// if (last_sts_hall1_read !=sts_hall1_read)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
APP_LOG(TS_OFF, VLEVEL_L, "\n\n Door Contact Read = %02x --%20s\r\n", HALL1_STATE, (HALL1_STATE==STS_Status_Door_Close)?"Door Closed":"Door Opened");
|
|
|
|
APP_LOG(TS_OFF, VLEVEL_L, "\n\n Door Contact Read = %02x --%s\r\n", sts_hall1_read, sts_door_status_code[sts_hall1_read]);
|
|
|
|
OnSensor1StateChanged();
|
|
|
|
OnSensor1StateChanged();
|
|
|
|
/* Note: when "EventType == TX_ON_TIMER" this GPIO is not initialized */
|
|
|
|
/* Note: when "EventType == TX_ON_TIMER" this GPIO is not initialized */
|
|
|
|
// if (EventType == TX_ON_EVENT)
|
|
|
|
// if (EventType == TX_ON_EVENT)
|
|
|
@ -724,12 +738,12 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
|
|
|
HAL_Delay(30); //de-bouncing
|
|
|
|
HAL_Delay(30); //de-bouncing
|
|
|
|
if (sts_hall2_read == HALL2_STATE)
|
|
|
|
if (sts_hall2_read == HALL2_STATE)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SysTime_t current_event_time = SysTimeGetMcuTime();
|
|
|
|
//SysTime_t current_event_time = SysTimeGetMcuTime();
|
|
|
|
if (last_sts_hall2_read != sts_hall2_read)
|
|
|
|
if (last_sts_hall2_read != sts_hall2_read)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (((current_event_time.Seconds - sts_o7_sensorData.event_sensor2_start_time) > 2) || ((current_event_time.Seconds - sts_o7_sensorData.event_sensor2_stop_time) > 2))
|
|
|
|
//if (((current_event_time.Seconds - sts_o7_sensorData.event_sensor2_start_time) > 2) || ((current_event_time.Seconds - sts_o7_sensorData.event_sensor2_stop_time) > 2))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
APP_LOG(TS_OFF, VLEVEL_L, "\n\n SOS Button Read = %02x --%20s\r\n", HALL2_STATE, (HALL2_STATE==STS_Status_SOS_Pushdown)?"SOS Pushdown":"SOS Released");
|
|
|
|
APP_LOG(TS_OFF, VLEVEL_L, "\n\n SOS Button Read = %02x --%s\r\n", sts_hall2_read, sts_sos_status_code[sts_hall2_read]);
|
|
|
|
OnSensor2StateChanged();
|
|
|
|
OnSensor2StateChanged();
|
|
|
|
//sensor_data_ready =1;
|
|
|
|
//sensor_data_ready =1;
|
|
|
|
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP1), CFG_SEQ_Prio_0);
|
|
|
|
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP1), CFG_SEQ_Prio_0);
|
|
|
@ -949,22 +963,22 @@ static void SendTxData(void)
|
|
|
|
char colorshow[30]="";
|
|
|
|
char colorshow[30]="";
|
|
|
|
strcpy(colorshow, (ich==0)?"":sts_lamp_color_code[ich]);
|
|
|
|
strcpy(colorshow, (ich==0)?"":sts_lamp_color_code[ich]);
|
|
|
|
|
|
|
|
|
|
|
|
APP_LOG(TS_OFF, VLEVEL_M,
|
|
|
|
APP_LOG(TS_OFF, VLEVEL_L,
|
|
|
|
"\r\n######| Color = %s%s | Mode = %5s |\r\n",(char *)colorshow, sts_lamp_color_code[icl], (char*)sts_work_mode_code[sensorData.workmode]);
|
|
|
|
"\r\n######| Color = %s%s | Mode = %5s |\r\n",(char *)colorshow, sts_lamp_color_code[icl], (char*)sts_work_mode_code[sensorData.workmode]);
|
|
|
|
if (sts_work_mode == STS_UNI_MODE)
|
|
|
|
if (sts_work_mode == STS_UNI_MODE)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
APP_LOG(TS_OFF, VLEVEL_M,
|
|
|
|
APP_LOG(TS_OFF, VLEVEL_L,
|
|
|
|
"\r\n######| S1-DoorOpen | S2-Motion | S3-SOS | S4 |Distance(mm) | MotionScore| Unconscious | Over_Stay_(min) | Fall Detected|"
|
|
|
|
"\r\n######| S1-Door | S2-Motion | S3-SOS | S4 |Distance(mm) | MotionScore| Unconscious | Over_Stay_(min) | Fall Detected|"
|
|
|
|
"\r\n######| %1d | %1d | %1d | %1d | %04d | %04d | %1d | %4d | %1d |\r\n",
|
|
|
|
"\r\n######| %s | %1d | %s | %1d | %04d | %04d | %1d | %4d | %1d |\r\n",
|
|
|
|
sensorData.state_sensor1_on_off, sensorData.state_sensor2_on_off,sensorData.state_sensor3_on_off, sensorData.state_sensor4_on_off,
|
|
|
|
sts_door_status_code[sensorData.state_sensor1_on_off], sensorData.state_sensor2_on_off,sts_sos_status_code[sensorData.state_sensor3_on_off], sensorData.state_sensor4_on_off,
|
|
|
|
(uint16_t)sensorData.rss_presence_distance,(uint16_t)sensorData.rss_presence_score,
|
|
|
|
(uint16_t)sensorData.rss_presence_distance,(uint16_t)sensorData.rss_presence_score,
|
|
|
|
sensorData.unconscious_state, sensorData.over_stay_duration/60, sensorData.fall_state );
|
|
|
|
sensorData.unconscious_state, sensorData.over_stay_duration, sensorData.fall_state );
|
|
|
|
} else if (sts_work_mode == STS_DUAL_MODE) {
|
|
|
|
} else if (sts_work_mode == STS_DUAL_MODE) {
|
|
|
|
|
|
|
|
|
|
|
|
APP_LOG(TS_OFF, VLEVEL_M,
|
|
|
|
APP_LOG(TS_OFF, VLEVEL_L,
|
|
|
|
"\r\n######| S1-DoorOpen | S2-Motion | S3-SOS |\r\n"
|
|
|
|
"\r\n######| S1-Door | S2-Motion | S3-SOS |\r\n"
|
|
|
|
"\r\n######| %1d | %1d | %1d |\r\n",
|
|
|
|
"\r\n######| %s | %1d | %s |\r\n",
|
|
|
|
sensorData.state_sensor1_on_off, sensorData.state_sensor2_on_off,sensorData.state_sensor3_on_off);
|
|
|
|
sts_door_status_code[sensorData.state_sensor1_on_off], sensorData.state_sensor2_on_off,sts_sos_status_code[sensorData.state_sensor3_on_off]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1125,27 +1139,47 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (STS_Status_Door_Close==sts_hall1_read)
|
|
|
|
if (STS_Status_Door_Close==sts_hall1_read)
|
|
|
|
|
|
|
|
{
|
|
|
|
sts_o7_sensorData.event_sensor1_duration = current_time.Seconds - sts_o7_sensorData.event_sensor1_start_time;
|
|
|
|
sts_o7_sensorData.event_sensor1_duration = current_time.Seconds - sts_o7_sensorData.event_sensor1_start_time;
|
|
|
|
if (sts_o7_sensorData.event_sensor1_duration > sts_occupancy_overtime_threshold_in_10min*600)
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sts_o7_sensorData.event_sensor1_duration = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//if (sts_o7_sensorData.event_sensor1_duration > sts_occupancy_overtime_threshold_in_10min*600)
|
|
|
|
|
|
|
|
if (sts_o7_sensorData.event_sensor1_duration > sts_occupancy_overtime_threshold_in_10min*60) //for debug
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sts_o7_sensorData.over_stay_state = 1;
|
|
|
|
sts_o7_sensorData.over_stay_state = 1;
|
|
|
|
sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor1_duration;
|
|
|
|
sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor1_duration;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
APP_LOG(TS_OFF, VLEVEL_L, "\r\nSensor 1 Over Stay = %d Sec \r\n", (sts_o7_sensorData.over_stay_duration));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// to be defiend later for SOS threshold TODO XXXX
|
|
|
|
// to be defiend later for SOS threshold TODO XXXX
|
|
|
|
if (STS_Status_SOS_Pushdown==sts_hall2_read)
|
|
|
|
if (STS_Status_SOS_Pushdown==sts_hall2_read)
|
|
|
|
|
|
|
|
{
|
|
|
|
sts_o7_sensorData.event_sensor2_duration = current_time.Seconds - sts_o7_sensorData.event_sensor2_start_time;
|
|
|
|
sts_o7_sensorData.event_sensor2_duration = current_time.Seconds - sts_o7_sensorData.event_sensor2_start_time;
|
|
|
|
if (sts_o7_sensorData.event_sensor2_duration > sts_occupancy_overtime_threshold_in_10min*600)
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sts_o7_sensorData.event_sensor2_duration =0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//if (sts_o7_sensorData.event_sensor2_duration > sts_occupancy_overtime_threshold_in_10min*600)
|
|
|
|
|
|
|
|
if (sts_o7_sensorData.event_sensor2_duration > sts_occupancy_overtime_threshold_in_10min*60) //for debug
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sts_o7_sensorData.over_stay_state = 1;
|
|
|
|
sts_o7_sensorData.over_stay_state = 1;
|
|
|
|
sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor2_duration;
|
|
|
|
// 2024-07-15 update, no overwrite sensor1 duration value
|
|
|
|
|
|
|
|
//sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor2_duration;
|
|
|
|
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// to be defiend later for SOS threshold TODO XXXX
|
|
|
|
// to be defiend later for SOS threshold TODO XXXX
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sts_rss_result==STS_RESULT_MOTION)
|
|
|
|
if (sts_rss_result==STS_RESULT_MOTION)
|
|
|
|
|
|
|
|
{
|
|
|
|
sts_o7_sensorData.event_sensor3_motion_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_motion_start_time;
|
|
|
|
sts_o7_sensorData.event_sensor3_motion_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_motion_start_time;
|
|
|
|
if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold_in_10min*600)
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sts_o7_sensorData.event_sensor3_motion_duration =0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold_in_10min*600)
|
|
|
|
|
|
|
|
if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold_in_10min) //for debug
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sts_o7_sensorData.occupancy_over_stay_state = 1;
|
|
|
|
sts_o7_sensorData.occupancy_over_stay_state = 1;
|
|
|
|
sts_o7_sensorData.occupancy_duration =sts_o7_sensorData.event_sensor3_motion_duration;
|
|
|
|
sts_o7_sensorData.occupancy_duration =sts_o7_sensorData.event_sensor3_motion_duration;
|
|
|
|