----- STS-O6/O7 General OK 2024-06-04
This commit is contained in:
parent
c6bcf2424f
commit
f0a1f3a510
|
@ -177,19 +177,21 @@ typedef struct STS_OO_SensorStatusDataTypeDef
|
|||
uint8_t fall_state; // FALL DETECION NONE, FALL DOWN, RISE UP, LAYDOWN_STILL
|
||||
uint8_t fall_speed; // speed of fall down measure
|
||||
uint8_t fall_gravity; // gravity of fall down measure
|
||||
uint8_t over_stay_state; // occupancy over time or not 0:1
|
||||
uint16_t over_stay_duration; // time lenght of overstay in seconds
|
||||
uint8_t over_stay_state; // sensor 1, door lock or door contact occupancy over time or not 0:1
|
||||
uint16_t over_stay_duration; // sensor 1, door lock or door contact, time lenght of overstay in seconds
|
||||
uint16_t occupancy_duration; // sensor 3, motion detection duration
|
||||
uint8_t occupancy_over_stay_state; //
|
||||
uint8_t battery_Pct; /* % of battery two digits, 88% (00-99)% */
|
||||
uint8_t dutycycletimelevel; /* level=0,255 */
|
||||
uint8_t sts_service_mask; /* sts service mask */
|
||||
uint32_t event_sensor1_start_time;
|
||||
uint32_t event_sensor1_stop_time;
|
||||
uint32_t event_sensor1_duration;
|
||||
uint32_t event_sensor2_start_time;
|
||||
uint32_t event_sensor2_stop_time;
|
||||
uint32_t event_sensor2_duration;
|
||||
uint32_t event_sensor3_start_time;
|
||||
uint32_t event_sensor3_stop_time;
|
||||
uint32_t event_sensor3_duration;
|
||||
uint32_t event_sensor4_start_time;
|
||||
uint32_t event_sensor4_stop_time;
|
||||
uint32_t event_sensor4_duration;
|
||||
|
||||
} STS_OO_SensorStatusDataTypeDef;
|
||||
//#endif
|
||||
|
|
|
@ -520,13 +520,13 @@ void STS_PRESENCE_SENSOR_Init_Send_Data(void)
|
|||
sts_o7_sensorData.unconcious_duration = 0x0;
|
||||
|
||||
sts_o7_sensorData.event_sensor1_start_time = 0x0;
|
||||
sts_o7_sensorData.event_sensor1_stop_time = 0x0;
|
||||
sts_o7_sensorData.event_sensor1_duration = 0x0;
|
||||
sts_o7_sensorData.event_sensor2_start_time = 0x0;
|
||||
sts_o7_sensorData.event_sensor2_stop_time = 0x0;
|
||||
sts_o7_sensorData.event_sensor2_duration = 0x0;
|
||||
sts_o7_sensorData.event_sensor3_start_time = 0x0;
|
||||
sts_o7_sensorData.event_sensor3_stop_time = 0x0;
|
||||
sts_o7_sensorData.event_sensor3_duration = 0x0;
|
||||
sts_o7_sensorData.event_sensor4_start_time = 0x0;
|
||||
sts_o7_sensorData.event_sensor4_stop_time = 0x0;
|
||||
sts_o7_sensorData.event_sensor4_duration = 0x0;
|
||||
|
||||
sts_o7_sensorData.battery_Pct = 99; // 99% as init value
|
||||
sts_o7_sensorData.dutycycletimelevel = 1;
|
||||
|
@ -556,7 +556,7 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *senso
|
|||
sensor_data->unconcious_state=(sts_fall_rising_detected_result == STS_PRESENCE_UNCONCIOUS)? 1:0;
|
||||
|
||||
sensor_data->fall_state = sts_fall_rising_detected_result;
|
||||
if (sts_fall_rising_detected_result != STS_PRESENCE_NONE)
|
||||
if (sts_fall_rising_detected_result == STS_PRESENCE_FALL)
|
||||
{
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n......FALL RISING DETECTION RESULT: %25s \r\n",(char*)sts_presence_fall_detection_message[sts_fall_rising_detected_result] );
|
||||
sensor_data->fall_speed = (uint8_t)sts_fall_rising_pattern_factor1;
|
||||
|
@ -567,35 +567,14 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *senso
|
|||
//SysTime_t occupy_check_time = SysTimeGetMcuTime();
|
||||
if ((sts_occupancy_overtime_threshold != 0) && (event_start_time !=0))
|
||||
{
|
||||
#if 0
|
||||
uint32_t check_time_tmp = occupy_check_time.Seconds - event_start_time;
|
||||
check_time_tmp = event_door_lock_start_time -event_door_lock_stop_time;
|
||||
#endif
|
||||
uint32_t check_time_tmp = (sts_o7_sensorData.event_sensor1_stop_time - sts_o7_sensorData.event_sensor1_start_time);
|
||||
//check_time_tmp = event_door_lock_start_time -event_door_lock_stop_time;
|
||||
//APP_LOG(TS_OFF, VLEVEL_L, "\r\n Check time at %6u Seconds, time lag =%6u, Started at %6u \r\n", occupy_check_time.Seconds, check_time_tmp, event_start_time);
|
||||
if (check_time_tmp <0) {
|
||||
check_time_tmp = 0xffff + sts_o7_sensorData.event_sensor1_stop_time - sts_o7_sensorData.event_sensor1_start_time;
|
||||
}
|
||||
|
||||
|
||||
if (check_time_tmp > sts_occupancy_overtime_threshold*60)
|
||||
{
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n......OVER STAY............\r\n");
|
||||
sts_occupancy_overtime_state = 1U;
|
||||
sensor_data->over_stay_state = sts_occupancy_overtime_state;
|
||||
sensor_data->over_stay_duration = check_time_tmp;
|
||||
|
||||
if (sts_occupancy_overtime_state == 1U) {
|
||||
sts_status_color = STS_RED_BLUE;
|
||||
sts_lamp_bar_color = STS_RED_BLUE;
|
||||
|
||||
}
|
||||
//STS_Lamp_Bar_Refresh();
|
||||
}
|
||||
|
||||
}// else
|
||||
//{
|
||||
// sts_occupancy_overtime_state = 0U;
|
||||
// }
|
||||
|
||||
sensor_data_ready = 1;
|
||||
}
|
||||
|
||||
|
@ -641,13 +620,13 @@ void STS_PRESENCE_SENSOR_Init(void)
|
|||
sts_o7_sensorData.battery_Pct = 99;
|
||||
sts_o7_sensorData.dutycycletimelevel = 1;
|
||||
sts_o7_sensorData.event_sensor1_start_time = 0;
|
||||
sts_o7_sensorData.event_sensor1_stop_time = 0;
|
||||
sts_o7_sensorData.event_sensor1_duration = 0;
|
||||
sts_o7_sensorData.event_sensor2_start_time = 0;
|
||||
sts_o7_sensorData.event_sensor2_stop_time = 0;
|
||||
sts_o7_sensorData.event_sensor2_duration = 0;
|
||||
sts_o7_sensorData.event_sensor3_start_time = 0;
|
||||
sts_o7_sensorData.event_sensor3_stop_time = 0;
|
||||
sts_o7_sensorData.event_sensor3_duration = 0;
|
||||
sts_o7_sensorData.event_sensor4_start_time = 0;
|
||||
sts_o7_sensorData.event_sensor4_stop_time = 0;
|
||||
sts_o7_sensorData.event_sensor4_duration = 0;
|
||||
|
||||
sts_o7_sensorData.over_stay_state = 0;
|
||||
sts_o7_sensorData.over_stay_duration = 0;
|
||||
|
@ -888,7 +867,7 @@ void OnSensor1StateChanged(void)
|
|||
if (sts_hall1_read==STS_Status_Door_Close)
|
||||
sts_o7_sensorData.event_sensor1_start_time = sensor_event_time.Seconds;
|
||||
else
|
||||
sts_o7_sensorData.event_sensor1_stop_time = sensor_event_time.Seconds;
|
||||
sts_o7_sensorData.event_sensor1_duration = sensor_event_time.Seconds- sts_o7_sensorData.event_sensor1_start_time;
|
||||
}
|
||||
|
||||
void OnSensor2StateChanged(void)
|
||||
|
@ -897,7 +876,7 @@ void OnSensor2StateChanged(void)
|
|||
if (sts_hall2_read==STS_Status_SOS_Pushdown)
|
||||
sts_o7_sensorData.event_sensor2_start_time = sensor_event_time.Seconds;
|
||||
else
|
||||
sts_o7_sensorData.event_sensor2_stop_time = sensor_event_time.Seconds;
|
||||
sts_o7_sensorData.event_sensor2_duration = sensor_event_time.Seconds- sts_o7_sensorData.event_sensor2_start_time;
|
||||
}
|
||||
|
||||
void OnSensor3StateChanged(void)
|
||||
|
@ -906,7 +885,7 @@ void OnSensor3StateChanged(void)
|
|||
if (sts_rss_result == STS_RESULT_MOTION)
|
||||
sts_o7_sensorData.event_sensor3_start_time = sensor_event_time.Seconds;
|
||||
else if (sts_rss_result == STS_RESULT_NO_MOTION)
|
||||
sts_o7_sensorData.event_sensor3_stop_time = sensor_event_time.Seconds;
|
||||
sts_o7_sensorData.event_sensor3_duration = sensor_event_time.Seconds- sts_o7_sensorData.event_sensor3_start_time;
|
||||
}
|
||||
|
||||
void OnSensor4StateChanged(void)
|
||||
|
|
|
@ -56,8 +56,10 @@ volatile uint8_t sts_reed_hall_result =0, sts_emergency_button_pushed=0; // init
|
|||
extern volatile uint8_t sts_work_mode, sts_cloud_netcolor, sts_lamp_bar_color, sts_status_color;
|
||||
extern volatile uint8_t sts_lamp_bar_flashing_color;
|
||||
volatile uint8_t last_sts_lamp_bar_color=STS_DARK;
|
||||
extern volatile uint8_t sts_rss_result;
|
||||
extern volatile uint8_t sts_rss_result_changed_flag, sts_hall1_changed_flag, sts_hall2_changed_flag, sts_reed_hall_changed_flag;
|
||||
volatile uint8_t sts_fall_detection_acc_threshold = 10, sts_fall_detection_depth_threshold=20, sts_occupancy_overtime_threshold=2;
|
||||
extern volatile uint8_t sts_fall_rising_detected_result;
|
||||
extern volatile uint32_t event_start_time, event_stop_time;
|
||||
extern volatile uint16_t sts_unconcious_threshold;
|
||||
volatile uint8_t sts_occupancy_overtime_state = 0;
|
||||
|
@ -357,6 +359,12 @@ static void OnJoinTimerLedEvent(void *context);
|
|||
*/
|
||||
static void OnYunhornSTSLampBarColorTimerEvent(void *context);
|
||||
|
||||
/**
|
||||
* @brief SYS occupancy, door lock, motion duration check timer callback function
|
||||
* @param context ptr of duration check context
|
||||
*/
|
||||
static void OnYunhornSTSDurationCheckTimerEvent(void *context);
|
||||
|
||||
/**
|
||||
* @brief Yunhorn STS Occupancy RSS WakeUP timer callback function
|
||||
* @param context ptr of STS RSS WakeUp context
|
||||
|
@ -493,6 +501,10 @@ static UTIL_TIMER_Object_t JoinLedTimer;
|
|||
*/
|
||||
static UTIL_TIMER_Object_t STSLampBarColorTimer;
|
||||
|
||||
/**
|
||||
* @brief Timer to handle the Yunhorn STS Lamp Bar Color Led to toggle
|
||||
*/
|
||||
static UTIL_TIMER_Object_t STSDurationCheckTimer;
|
||||
|
||||
/**
|
||||
* @brief Timer to handle the YunHorn STS RSS WakeUP Checking
|
||||
|
@ -562,6 +574,7 @@ void LoRaWAN_Init(void)
|
|||
UTIL_TIMER_Create(&RxLedTimer, LED_PERIOD_TIME, UTIL_TIMER_ONESHOT, OnRxTimerLedEvent, NULL);
|
||||
UTIL_TIMER_Create(&JoinLedTimer, LED_PERIOD_TIME, UTIL_TIMER_PERIODIC, OnJoinTimerLedEvent, NULL);
|
||||
UTIL_TIMER_Create(&STSLampBarColorTimer, LED_PERIOD_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSLampBarColorTimerEvent, NULL);
|
||||
UTIL_TIMER_Create(&STSDurationCheckTimer, 20*LED_PERIOD_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSDurationCheckTimerEvent, NULL);
|
||||
|
||||
if (FLASH_IF_Init(NULL) != FLASH_IF_OK)
|
||||
{
|
||||
|
@ -867,9 +880,9 @@ static void SendTxData(void)
|
|||
AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_duration)&0xff; //15 occupancy over stay duration LSB
|
||||
|
||||
APP_LOG(TS_OFF, VLEVEL_L,
|
||||
"\r\n######| Color =| %4s || Mode =| %5s |\r\n",(char *)sts_lamp_color_code[sensorData.lamp_bar_color], (char*)sts_work_mode_code[sensorData.workmode]);
|
||||
"\r\n######| Color = %4s | Mode = %5s |\r\n",(char *)sts_lamp_color_code[sensorData.lamp_bar_color], (char*)sts_work_mode_code[sensorData.workmode]);
|
||||
APP_LOG(TS_OFF, VLEVEL_L,
|
||||
"\r\n######| S1-DoorOpen | S2-Motion | S3-No_Emergency | S4 |Distance(mm) | MotionScore| Unconcious | Over_Stay | Fall Detected|"
|
||||
"\r\n######| S1-DoorOpen | S2-Motion | S3-SOS | S4 |Distance(mm) | MotionScore| Unconcious | Over_Stay | Fall Detected|"
|
||||
"\r\n######| %1d | %1d | %1d | %1d | %04d | %04d | %1d | %1d | %1d |\r\n",
|
||||
sensorData.state_sensor1_on_off, sensorData.state_sensor2_on_off,sensorData.state_sensor3_on_off, sensorData.state_sensor4_on_off,
|
||||
(uint16_t)sensorData.rss_presence_distance,(uint16_t)sensorData.rss_presence_score,
|
||||
|
@ -1002,6 +1015,60 @@ static void OnYunhornSTSLampBarColorTimerEvent(void *context)
|
|||
|
||||
}
|
||||
|
||||
static void OnYunhornSTSDurationCheckTimerEvent(void *context)
|
||||
{
|
||||
SysTime_t sensor_event_time = SysTimeGetMcuTime();
|
||||
|
||||
|
||||
if (sts_hall1_read==STS_Status_Door_Close)
|
||||
sts_o7_sensorData.event_sensor1_duration = sensor_event_time.Seconds - sts_o7_sensorData.event_sensor1_start_time;
|
||||
if (sts_o7_sensorData.event_sensor1_duration > sts_occupancy_overtime_threshold)
|
||||
{
|
||||
sts_o7_sensorData.over_stay_state = 1;
|
||||
sts_o7_sensorData.over_stay_duration =sts_o7_sensorData.event_sensor1_duration;
|
||||
}
|
||||
|
||||
if (sts_hall2_read==STS_Status_SOS_Pushdown)
|
||||
sts_o7_sensorData.event_sensor2_duration = sensor_event_time.Seconds - sts_o7_sensorData.event_sensor2_start_time;
|
||||
|
||||
if (sts_rss_result==STS_RESULT_MOTION)
|
||||
sts_o7_sensorData.event_sensor3_duration = sensor_event_time.Seconds - sts_o7_sensorData.event_sensor3_start_time;
|
||||
if (sts_o7_sensorData.event_sensor3_duration > sts_occupancy_overtime_threshold)
|
||||
{
|
||||
sts_o7_sensorData.occupancy_over_stay_state = 1;
|
||||
sts_o7_sensorData.occupancy_duration =sts_o7_sensorData.event_sensor3_duration;
|
||||
}
|
||||
/*
|
||||
STS_PRESENCE_NONE=0,
|
||||
STS_PRESENCE_FALL,
|
||||
STS_PRESENCE_RISING,
|
||||
STS_PRESENCE_LAYDOWN,
|
||||
STS_PRESENCE_UNCONCIOUS,
|
||||
STS_PRESENCE_STAYSTILL
|
||||
*/
|
||||
switch (sts_fall_rising_detected_result){
|
||||
case STS_PRESENCE_NONE:
|
||||
break;
|
||||
case STS_PRESENCE_FALL:
|
||||
break;
|
||||
case STS_PRESENCE_RISING:
|
||||
break;
|
||||
case STS_PRESENCE_LAYDOWN:
|
||||
break;
|
||||
case STS_PRESENCE_UNCONCIOUS:
|
||||
break;
|
||||
case STS_PRESENCE_STAYSTILL:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
if (sts_xxx_result == xxx)
|
||||
sts_o7_sensorData.event_sensor3_event_duration = sensor_event_time.Seconds - sts_o7_sensorData.event_sensor4_start_time;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void OnTxData(LmHandlerTxParams_t *params)
|
||||
{
|
||||
|
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue