From 6dd59ad9427fb5beb7a6e55bab05095607e1712f Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Fri, 26 Jul 2024 19:08:54 +0800 Subject: [PATCH] --- revised for time stamp --- Core/Inc/yunhorn_sts_sensors.h | 25 +++++++++--------- Core/Src/yunhorn_sts_process.c | 47 +++++++++++++++++++--------------- LoRaWAN/App/lora_app.c | 37 ++++++++++++++------------ 3 files changed, 60 insertions(+), 49 deletions(-) diff --git a/Core/Inc/yunhorn_sts_sensors.h b/Core/Inc/yunhorn_sts_sensors.h index af338b6..727e1b1 100644 --- a/Core/Inc/yunhorn_sts_sensors.h +++ b/Core/Inc/yunhorn_sts_sensors.h @@ -161,13 +161,13 @@ typedef struct //#if (defined(YUNHORN_STS_O0_ENABLED) || defined(YUNHORN_STS_O1_ENABLED) || defined(YUNHORN_STS_O2_ENABLED) || defined(YUNHORN_STS_O3_ENABLED) || defined(YUNHORN_STS_O4_ENABLED) || defined(YUNHORN_STS_O5_ENABLED)|| defined(YUNHORN_STS_O6_ENABLED)) typedef struct STS_OO_SensorStatusDataTypeDef { - uint8_t lamp_bar_color; /*measured color ID, 0,1,2,3,4,5,6,7,8,9 */ - uint8_t workmode; /*work mode, 0,1,2,3,4*/ - uint8_t state_sensor1_on_off; /* reedswitch or hall element 0: open, 1: closed */ - uint8_t state_sensor2_on_off; /* pcr_sensor_on_off; 1: occupancy, 0: no occupancy */ - uint8_t state_sensor3_on_off; /* urinal_sensor_on_off urinal sensor state */ - uint8_t state_sensor4_on_off; /* reserved_sensor_on_off sensor state */ - uint16_t rss_presence_distance; // in mm + uint8_t lamp_bar_color; /* measured color ID, 0,1,2,3,4,5,6,7,8,9 */ + uint8_t workmode; /* work mode, 0,1,2,3,4 */ + uint8_t state_sensor1_on_off; /* reedswitch or hall element 0: open, 1: closed */ + uint8_t state_sensor2_on_off; /* reedswitch or hall element 0: open, 1: closed */ + uint8_t state_sensor3_on_off; /* motion RSS, pcr_sensor_on_off; 1: occupancy, 0: no occupancy */ + uint8_t state_sensor4_on_off; /* reserved_sensor_on_off sensor state */ + uint16_t rss_presence_distance; // in mm uint8_t rss_presence_zone[10]; uint8_t rss_presence_zone_count[10]; uint16_t rss_presence_score; // in 1000*score @@ -185,20 +185,21 @@ typedef struct STS_OO_SensorStatusDataTypeDef uint32_t no_movement_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 */ + 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_start_time; /* reedswitch or hale element */ uint32_t event_sensor2_start_timestamp; uint32_t event_sensor2_stop_time; uint32_t event_sensor2_stop_timestamp; uint32_t event_sensor2_duration; - uint32_t event_sensor3_motion_start_time; + uint32_t event_sensor3_motion_start_time; /* RSS motion sensor */ uint32_t event_sensor3_motion_stop_time; + uint32_t event_sensor3_start_timestamp; uint32_t event_sensor3_motion_duration; uint32_t event_sensor3_fall_start_time; @@ -215,7 +216,7 @@ typedef struct STS_OO_SensorStatusDataTypeDef uint32_t event_sensor3_unconcious_stop_time; uint32_t event_sensor3_unconcious_duration; - uint32_t event_sensor4_start_time; + uint32_t event_sensor4_start_time; /* reserved */ uint32_t event_sensor4_stop_time; uint32_t event_sensor4_duration; uint8_t alarm_indictor_mute_state; diff --git a/Core/Src/yunhorn_sts_process.c b/Core/Src/yunhorn_sts_process.c index a9c14df..9f8abd1 100644 --- a/Core/Src/yunhorn_sts_process.c +++ b/Core/Src/yunhorn_sts_process.c @@ -222,19 +222,12 @@ void STS_YunhornSTSEventRFAC_Process(void) void STS_YunhornSTSEventP1_Process(void) { - - - { sts_reed_hall_1_result = HALL1_STATE; //sts_hall1_read; - last_sts_reed_hall_1_result = sts_reed_hall_1_result; - } - { sts_reed_hall_2_result = HALL2_STATE;// sts_hall2_read; - last_sts_reed_hall_2_result = sts_reed_hall_2_result; - } + STS_Combined_Status_Processing(); } @@ -620,7 +613,7 @@ void STS_Combined_Status_Processing(void) //STS_Lamp_Bar_Refresh(); - if ((sts_rss_result_changed_flag)|| (sts_reed_hall_changed_flag)|| (sts_reed_hall_changed_flag)) + if ((sts_rss_result_changed_flag)|| (sts_reed_hall_changed_flag)) { //sts_rss_result_changed_flag =0; //sts_reed_hall_changed_flag =0; @@ -721,12 +714,21 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *senso sensor_data->lamp_bar_color = sts_lamp_bar_color; sensor_data->workmode = sts_work_mode; sensor_data->state_sensor1_on_off = HALL1_STATE;//sts_hall1_read; //sts_hsts_reed_hall_result; // sts_hall1_read - sensor_data->state_sensor2_on_off = sts_rss_result; - sensor_data->state_sensor3_on_off = HALL2_STATE;//sts_hall2_read; //sts_emergency_button_pushed; //sts_hall2_read + sensor_data->state_sensor2_on_off = HALL2_STATE;//sts_hall2_read; //sts_emergency_button_pushed; //sts_hall2_read + sensor_data->state_sensor3_on_off = sts_rss_result; sensor_data->state_sensor4_on_off = sts_rss_2nd_result; - sensor_data->event_sensor2_start_timestamp = sts_o7_sensorData.event_sensor2_start_timestamp; - sensor_data->event_sensor2_stop_timestamp = sts_o7_sensorData.event_sensor2_stop_timestamp; + if (sensor_data->state_sensor2_on_off==STS_Status_SOS_Pushdown) + { + sensor_data->event_sensor2_start_timestamp = sts_o7_sensorData.event_sensor2_start_timestamp; + sensor_data->event_sensor2_stop_timestamp = sts_o7_sensorData.event_sensor2_stop_timestamp; + sts_o7_sensorData.event_sensor2_start_timestamp = 0; + } else { + sensor_data->event_sensor2_start_timestamp = 0; + sensor_data->event_sensor2_stop_timestamp = 0; + sensor_data->event_sensor2_stop_timestamp = sts_o7_sensorData.event_sensor2_stop_timestamp; + sts_o7_sensorData.event_sensor2_stop_timestamp = 0; + } if (sts_rss_result == STS_RESULT_MOTION) { @@ -780,7 +782,8 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *senso } else { sensor_data->fall_speed = 0; sensor_data->fall_gravity = 0; - + sensor_data->event_sensor3_fall_start_time_stamp = 0; + sensor_data->event_sensor3_fall_stop_time_stamp =0; } // For occupancy over time process @@ -1118,16 +1121,18 @@ void OnSensor2StateChanged(void) if (sts_hall2_read==STS_Status_SOS_Pushdown) { - sts_o7_sensorData.event_sensor2_start_time = sensor_event_time.Seconds; + sts_o7_sensorData.event_sensor2_start_time = sensor_event_time.Seconds; sts_o7_sensorData.event_sensor2_start_timestamp = time_stamp; - sts_o7_sensorData.event_sensor2_duration = 0; + sts_o7_sensorData.event_sensor2_stop_time = 0; + sts_o7_sensorData.event_sensor2_duration = 0; APP_LOG(TS_OFF, VLEVEL_L, "SOS PushDown ---Timer start: %u\r\n",sts_o7_sensorData.event_sensor2_start_time ); }else if (sts_hall2_read==STS_Status_SOS_Release) { - sts_o7_sensorData.event_sensor2_start_time =0; - sts_o7_sensorData.event_sensor2_stop_time = sensor_event_time.Seconds; - sts_o7_sensorData.event_sensor2_stop_timestamp = time_stamp; - sts_o7_sensorData.over_stay_state = 0; + sts_o7_sensorData.event_sensor2_start_time = 0; + sts_o7_sensorData.event_sensor2_start_timestamp = 0; + sts_o7_sensorData.event_sensor2_stop_time = sensor_event_time.Seconds; + sts_o7_sensorData.event_sensor2_stop_timestamp = time_stamp; + //sts_o7_sensorData.over_stay_state = 0; //sts_o7_sensorData.event_sensor2_duration = 0; } } @@ -1149,6 +1154,7 @@ void OnSensor3StateChanged(void) } else if (sts_rss_result == STS_RESULT_NO_MOTION) { sts_o7_sensorData.event_sensor3_motion_stop_time = sensor_event_time.Seconds; + sts_o7_sensorData.event_sensor3_start_timestamp = 0; //sts_o7_sensorData.event_sensor3_motion_duration = 0; } @@ -1175,6 +1181,7 @@ void OnSensor3AStateChanged(void) } else if (sts_rss_result == STS_RESULT_NO_MOTION) { sts_o7_sensorData.event_sensor3_motion_stop_time = sensor_event_time.Seconds; + sts_o7_sensorData.event_sensor3_start_timestamp = 0; //sts_o7_sensorData.event_sensor3_motion_duration = 0; } diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 1686261..01a7be2 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -960,27 +960,25 @@ static void SendTxData(void) AppData.Buffer[i++] = (uint8_t)(sensorData.workmode)&0xff; //02 WORK MODE if (sts_work_mode == STS_RSS_MODE) { - AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor1_on_off)&0xff; //03 Sensor head #1 status - AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor2_on_off)&0xff; //04 Sensor head #3 status + AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor1_on_off)&0xff; //03 Sensor head #1 status reed switch + AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor3_on_off)&0xff; //04 Sensor head #3 status RSS motion } else if (sts_work_mode == STS_DUAL_MODE) { - AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor1_on_off)&0xff; //03 Sensor head #1 status - AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor2_on_off)&0xff; //04 Sensor head #2 status - AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor3_on_off)&0xff; //05 Sensor head #3 status + AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor1_on_off)&0xff; //03 Sensor head #1 status reed switch + AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor2_on_off)&0xff; //04 Sensor head #2 status SOS button + AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor3_on_off)&0xff; //05 Sensor head #3 status RSS motion AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_state)&0xff; //06 occupancy over time or not AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_duration>>8)&0xff; //07 occupancy over stay duration MSB AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_duration)&0xff; //08 occupancy over stay duration LSB - - } else if (sts_work_mode == STS_UNI_MODE) { - AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor1_on_off)&0xff; //03 Sensor head #1 status - AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor2_on_off)&0xff; //04 Sensor head #2 status - AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor3_on_off)&0xff; //05 Sensor head #3 status - AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor4_on_off)&0xff; //06 Sensor head #4 status + AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor1_on_off)&0xff; //03 Sensor head #1 status reedswitch + AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor2_on_off)&0xff; //04 Sensor head #2 status SOS button + AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor3_on_off)&0xff; //05 Sensor head #3 status RSS motion + AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor4_on_off)&0xff; //06 Sensor head #4 status reserved AppData.Buffer[i++] = (uint8_t)(sensorData.rss_presence_distance>>8)&0xff; //07 MSB distance @@ -1031,17 +1029,22 @@ static void SendTxData(void) if (sts_work_mode == STS_UNI_MODE) { APP_LOG(TS_OFF, VLEVEL_L, - "\r\n######| S1-Door | S2-Motion | S3-SOS | S4 |Distance(mm) | MotionScore| Unconscious | Over_Stay_(min) | Fall Detected|" - "\r\n######| %s | %1d | %s | %1d | %04d | %04d | %1d | %4d | %s |\r\n", - 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, + "\r\n######| S1-Door | S2-SOS | S3-Motion | S4 |Distance(mm) | MotionScore| Unconscious | Over_Stay_(min) | Fall Detected|" + "\r\n######| %s | %s | %d | %1d | %04d | %04d | %1d | %4d | %s |\r\n", + sts_door_status_code[sensorData.state_sensor1_on_off], + sts_sos_status_code[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, sensorData.unconscious_state, sensorData.over_stay_duration, sts_fall_mode_code[sensorData.fall_state]); } else if (sts_work_mode == STS_DUAL_MODE) { APP_LOG(TS_OFF, VLEVEL_L, - "\r\n######| S1-Door | S2-Motion | S3-SOS |\r\n" - "\r\n######| %s | %1d | %s |\r\n", - sts_door_status_code[sensorData.state_sensor1_on_off], sensorData.state_sensor2_on_off,sts_sos_status_code[sensorData.state_sensor3_on_off]); + "\r\n######| S1-Door | S2-SOS | S3-Motion |\r\n" + "\r\n######| %s | %s | %d |\r\n", + sts_door_status_code[sensorData.state_sensor1_on_off], + sts_sos_status_code[sensorData.state_sensor2_on_off], + sensorData.state_sensor3_on_off); } }