RM2_1 #2

Merged
sundp merged 208 commits from RM2_1 into master 2024-09-13 09:16:14 +08:00
5 changed files with 85 additions and 84 deletions
Showing only changes of commit c0b1bb73dc - Show all commits

View File

@ -44,9 +44,10 @@ enum sts_lamp_color {
STS_PINK, //紫5 1 0 1
STS_CYAN, //青6 0 1 1
STS_WHITE, //白7 1 1 1
STS_RED_BLUE, //红蓝闪烁8
STS_RED_DARK, //RD: 9 1 0 0 RED Flash
STS_COLOR_MAX // MAX NUM OF COLORS
STS_COLOR_MAX,
STS_RED_BLUE=0x23, //红蓝闪烁8
STS_RED_DARK=0x20 //RD: 9 1 0 0 RED Flash
// MAX NUM OF COLORS
};
enum sts_oo_work_mode {

View File

@ -173,12 +173,12 @@ typedef struct STS_OO_SensorStatusDataTypeDef
uint16_t rss_presence_score; // in 1000*score
uint8_t unconcious_state;
uint16_t unconcious_threshold;
uint16_t unconcious_duration;
uint32_t unconcious_duration;
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; // 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
uint32_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)% */

View File

@ -191,7 +191,7 @@ void STS_Lamp_Bar_Set_STS_RGB_Color(uint8_t sts_lamp_color, uint8_t lum)
{
//static bool r_b = false;
//STS_Lamp_Bar_Set_RGB_Color(0x0, 0x0, 0x0);
switch (sts_lamp_color)
switch (sts_lamp_color&0x0f)
{
case STS_DARK:
STS_Lamp_Bar_Set_RGB_Color(0x0, 0x0, 0x0);
@ -233,33 +233,6 @@ void STS_Reed_Hall_Working(void)
}
void STS_Combined_Status_Processing(void)
{
mems_event_time = SysTimeGetMcuTime();
if ((sts_rss_result == STS_RESULT_MOTION) || (sts_reed_hall_1_result == STS_Status_Door_Close)|| (sts_reed_hall_2_result == STS_Status_SOS_Pushdown) || (sts_tof_result == STS_RESULT_PRESENCE))
{
if (event_start_time == 0) {
event_start_time = mems_event_time.Seconds;
event_door_lock_start_time = event_start_time;
event_stop_time = 0;
APP_LOG(TS_OFF, VLEVEL_H, "\r\n Event Started at %6u Seconds \r\n", event_start_time);
}
} else if ((sts_rss_result != STS_RESULT_MOTION) || (sts_reed_hall_1_result != STS_Status_Door_Close)|| (sts_reed_hall_2_result != STS_Status_SOS_Pushdown) || (sts_tof_result != STS_RESULT_PRESENCE))
{
if (event_stop_time ==0)
{
event_stop_time = mems_event_time.Seconds;
event_door_lock_stop_time = event_stop_time;
event_start_time = 0;
APP_LOG(TS_OFF, VLEVEL_H, "\r\n Event Stop at %6u Seconds, Duration = %6u Seconds\r\n", event_stop_time, (event_stop_time-event_start_time));
}
}
switch (sts_work_mode)
{
case STS_NETWORK_MODE:
@ -286,12 +259,6 @@ void STS_Combined_Status_Processing(void)
}
break;
case STS_DUAL_MODE:
uint8_t flapping_flag=0;
if ((event_stop_time - event_start_time)<=4) {
flapping_flag=1;
}
if (!flapping_flag) {
if ((sts_rss_result == STS_RESULT_NO_MOTION) && (sts_reed_hall_1_result == STS_Status_Door_Open )&& (sts_reed_hall_2_result == STS_Status_SOS_Release ))
{
sts_status_color = STS_GREEN;
@ -299,23 +266,25 @@ void STS_Combined_Status_Processing(void)
} else if ((sts_rss_result == STS_RESULT_MOTION) || (sts_reed_hall_1_result == STS_Status_Door_Close )||(sts_reed_hall_2_result == STS_Status_SOS_Pushdown ))
{
sts_status_color = STS_RED;
if (sts_fall_rising_detected_result == STS_PRESENCE_LAYDOWN) {
switch(sts_fall_rising_detected_result) {
case STS_PRESENCE_LAYDOWN:
sts_lamp_bar_color = STS_YELLOW;
sts_status_color = STS_YELLOW;
} else if (sts_fall_rising_detected_result == STS_PRESENCE_FALL){ //RED_BLUE FLASH
break;
case STS_PRESENCE_FALL: //RED_BLUE FLASH
sts_lamp_bar_color = STS_RED_BLUE;
sts_status_color = STS_RED_BLUE;
} else if (sts_fall_rising_detected_result == STS_PRESENCE_RISING) { //NORMAL OCCUPANCY STATUS
break;
case STS_PRESENCE_RISING: //NORMAL OCCUPANCY STATUS
sts_lamp_bar_color = STS_RED;
sts_status_color = STS_RED;
break;
}
if (sts_reed_hall_2_result == STS_Status_SOS_Pushdown )
{
sts_status_color = STS_RED_BLUE;
}
}
}
break;
case STS_REMOTE_REED_RSS_MODE:
if ((sts_rss_result == STS_RESULT_NO_MOTION) && (sts_reed_hall_result == STS_Status_Door_Open ))

View File

@ -554,6 +554,8 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *senso
sensor_data->rss_presence_score = 0x0;
}
sensor_data->unconcious_state=(sts_fall_rising_detected_result == STS_PRESENCE_UNCONCIOUS)? 1:0;
sensor_data->over_stay_state = sts_o7_sensorData.over_stay_state;
sensor_data->over_stay_duration = sts_o7_sensorData.over_stay_duration;
sensor_data->fall_state = sts_fall_rising_detected_result;
if (sts_fall_rising_detected_result == STS_PRESENCE_FALL)
@ -579,31 +581,6 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *senso
}
#if 0
void STS_PRESENCE_SENSOR_Read(STS_OO_SensorStatusDataTypeDef *oo_data)
{
oo_data->lamp_bar_color = (uint8_t)sts_o7_sensorData.lamp_bar_color;
oo_data->workmode = (uint8_t)sts_o7_sensorData.workmode;
oo_data->state_sensor1_on_off = (uint8_t)sts_o7_sensorData.state_sensor1_on_off;
oo_data->state_sensor2_on_off = (uint8_t)sts_o7_sensorData.state_sensor2_on_off;
oo_data->state_sensor3_on_off = (uint8_t)sts_o7_sensorData.state_sensor3_on_off;
oo_data->state_sensor4_on_off = (uint8_t)sts_o7_sensorData.state_sensor4_on_off;
oo_data->rss_presence_distance = (uint16_t)sts_o7_sensorData.rss_presence_distance;
oo_data->rss_presence_score = (uint16_t)sts_o7_sensorData.rss_presence_score;
oo_data->fall_state = (uint8_t)sts_o7_sensorData.fall_state;
oo_data->event_start_time = (uint32_t)sts_o7_sensorData.event_start_time;
oo_data->event_stop_time = (uint32_t)sts_o7_sensorData.event_stop_time;
oo_data->over_stay_state = (uint8_t)sts_o7_sensorData.over_stay_state;
oo_data->over_stay_duration = (uint16_t)sts_o7_sensorData.over_stay_duration;
oo_data->battery_Pct = (uint8_t)sts_o7_sensorData.battery_Pct;
oo_data->dutycycletimelevel = (uint8_t)sts_o7_sensorData.dutycycletimelevel;
}
#endif
/**
* @brief Initializes the motion sensors
* @param Instance Motion sensor instance
@ -865,27 +842,30 @@ void OnSensor1StateChanged(void)
{
SysTime_t sensor_event_time = SysTimeGetMcuTime();
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_duration = sensor_event_time.Seconds- sts_o7_sensorData.event_sensor1_start_time;
}
}
void OnSensor2StateChanged(void)
{
SysTime_t sensor_event_time = SysTimeGetMcuTime();
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_duration = sensor_event_time.Seconds- sts_o7_sensorData.event_sensor2_start_time;
}
}
void OnSensor3StateChanged(void)
{
SysTime_t sensor_event_time = SysTimeGetMcuTime();
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_duration = sensor_event_time.Seconds- sts_o7_sensorData.event_sensor3_start_time;
}
}
void OnSensor4StateChanged(void)

View File

@ -36,6 +36,7 @@
#include "sys_sensors.h"
#include "flash_if.h"
#include "LmhpClockSync.h"
/* USER CODE BEGIN Includes */
#include "tim.h"
#include "sts_lamp_bar.h"
@ -496,6 +497,7 @@ static UTIL_TIMER_Object_t RxLedTimer;
*/
static UTIL_TIMER_Object_t JoinLedTimer;
static volatile bool IsClockSynched = false;
/**
* @brief Timer to handle the Yunhorn STS Lamp Bar Color Led to toggle
*/
@ -602,6 +604,11 @@ void LoRaWAN_Init(void)
/* USER CODE BEGIN LoRaWAN_Init_2 */
UTIL_TIMER_Start(&JoinLedTimer);
// TODO XXX 2024-06-04
LmHandlerPackageRegister( PACKAGE_ID_CLOCK_SYNC, NULL );
IsClockSynched = false;
/* USER CODE END LoRaWAN_Init_2 */
LmHandlerJoin(ActivationType, ForceRejoin);
@ -858,7 +865,7 @@ static void SendTxData(void)
} else if ((sensor_data_ready!= 0U)) //sensor_data_ready for manual push button-1 trigger)
{
sensor_data_ready =0;
AppData.Buffer[i++] = AppLedStateOn|0x80; // ************ MUST KEEP IT HERE, NON-ZERO ******
AppData.Buffer[i++] = AppLedStateOn|0x80; //00 ************ MUST KEEP IT HERE, NON-ZERO ******
AppData.Buffer[i++] = (uint8_t)(sensorData.lamp_bar_color)&0xff; //01
AppData.Buffer[i++] = (uint8_t)(sensorData.workmode)&0xff; //02 WORK MODE
@ -891,6 +898,10 @@ static void SendTxData(void)
AppData.BufferSize = (sts_service_mask > STS_SERVICE_MASK_L1? 0:i);
//AppData.BufferSize = (sts_service_mask > STS_SERVICE_MASK_L1? 0:i);
if( IsClockSynched == false )
{
status = LmhpClockSyncAppTimeReq( );
}
if ((JoinLedTimer.IsRunning) && (LmHandlerJoinStatus() == LORAMAC_HANDLER_SET))
{
@ -986,8 +997,23 @@ static void OnYunhornSTSLampBarColorTimerEvent(void *context)
//uint8_t lum=DEFAULT_LUMINANCE_LEVEL;
//HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin); /* STS GREEN */
//if ((sts_work_mode != STS_WIRED_MODE))
uint8_t high4=(sts_lamp_bar_color>>4)&0x0f, low4=sts_lamp_bar_color&0x0f;
if (high4==0) {
if (last_sts_lamp_bar_color != sts_lamp_bar_color)
{
STS_Lamp_Bar_Set_STS_RGB_Color(sts_lamp_bar_color, DEFAULT_LUMINANCE_LEVEL);
last_sts_lamp_bar_color = sts_lamp_bar_color;
}
} else {
if (r_b)
STS_Lamp_Bar_Set_STS_RGB_Color(high4, DEFAULT_LUMINANCE_LEVEL);
else
STS_Lamp_Bar_Set_STS_RGB_Color(low4, DEFAULT_LUMINANCE_LEVEL);
r_b = !r_b;
}
#if 0
if (sts_lamp_bar_color == STS_RED_BLUE) {
if (r_b)
STS_Lamp_Bar_Set_STS_RGB_Color(STS_RED, DEFAULT_LUMINANCE_LEVEL);
@ -1012,7 +1038,7 @@ static void OnYunhornSTSLampBarColorTimerEvent(void *context)
}
}
#endif
}
static void OnYunhornSTSDurationCheckTimerEvent(void *context)
@ -1183,7 +1209,7 @@ static void OnBeaconStatusChange(LmHandlerBeaconParams_t *params)
static void OnSysTimeUpdate(void)
{
/* USER CODE BEGIN OnSysTimeUpdate_1 */
IsClockSynched = true;
/* USER CODE END OnSysTimeUpdate_1 */
}
@ -1697,7 +1723,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
APP_LOG(TS_OFF, VLEVEL_L, ">>>>>>>>>>>>>>>>>>>>> Mask = [ %02x ] \r\n", sts_service_mask);
OnStoreSTSCFGContextRequest();
if (sts_service_mask != STS_SERVICE_MASK_L0) STS_Lamp_Bar_Set_Dark();
STS_Combined_Status_Processing();
//STS_Combined_Status_Processing();
}
break;
@ -1713,11 +1739,35 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
outbuf[i++] = (uint8_t) MajorVer;
outbuf[i++] = (uint8_t) MinorVer;
outbuf[i++] = (uint8_t) SubMinorVer;
struct tm localtime;
SysTime_t UnixEpoch = SysTimeGet();
UnixEpoch.Seconds -= 18; /*removing leap seconds*/
UnixEpoch.Seconds += 3600 * 2; /*adding 2 hours*/
SysTimeLocalTime(UnixEpoch.Seconds, & localtime);
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
LmhPackage_t LmhpClockSyncPackageFactory;
LmhpClockSyncPackageFactory.Init;
if (LmhpClockSyncPackageFactory.IsInitialized)
LmhpClockSyncPackageFactory.Process;
if (LORAMAC_HANDLER_SUCCESS == LmhpClockSyncAppTimeReq()) {
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Clock Sync Success \r\n");
}
SysTime_t mytime=SysTimeGet();
struct tm mylocal;
SysTimeLocalTime((uint32_t)mytime.Seconds, &mylocal);
APP_LOG(TS_OFF, VLEVEL_M, "\r\nTime YYYYMMDD=%4d:%2d:%2d HHMMSS=%2d:%2d:%2d \r\n",
mylocal.tm_year, mylocal.tm_mon, mylocal.tm_mday, mylocal.tm_hour, mylocal.tm_min, mylocal.tm_sec);
outbuf[i++] = (uint8_t) mylocal.tm_year>>8&0xff;
outbuf[i++] = (uint8_t) mylocal.tm_year&0xff;
outbuf[i++] = (uint8_t) mylocal.tm_mon;
@ -1725,6 +1775,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
outbuf[i++] = (uint8_t) mylocal.tm_hour;
outbuf[i++] = (uint8_t) mylocal.tm_min;
outbuf[i++] = (uint8_t) mylocal.tm_sec;
#endif
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
APP_LOG(TS_OFF, VLEVEL_M, "###### YUNHORN Report Version [ %10x ] \r\n", (uint8_t *)outbuf);
}