diff --git a/Core/Inc/yunhorn_sts_prd_conf.h b/Core/Inc/yunhorn_sts_prd_conf.h index 170dc5b..a123a82 100644 --- a/Core/Inc/yunhorn_sts_prd_conf.h +++ b/Core/Inc/yunhorn_sts_prd_conf.h @@ -219,6 +219,12 @@ #define YUNHORN_STS_MAX_NVM_CFG_SIZE 64U #define YUNHORN_STS_AC_CODE_SIZE 20U +#define STS_NVM_CFG_SIZE 32U +#define STS_CFG_PCFG_SIZE 28U +#define STS_CFG_CMD_SIZE 30U +#define STS_CFG_CMD_SHORT_LEN 8U +#define STS_MODE_COLOR_CMD_LEN 5U + #define STS_R0_NVM_CFG_SIZE 16U #define STS_R0_CFG_CMD_SIZE 12U #define CFG_CMD_TOF_SIMPLE_SIZE (STS_R0_CFG_CMD_SIZE) diff --git a/Core/Inc/yunhorn_sts_sensors.h b/Core/Inc/yunhorn_sts_sensors.h index d8b3332..eb7d9e5 100644 --- a/Core/Inc/yunhorn_sts_sensors.h +++ b/Core/Inc/yunhorn_sts_sensors.h @@ -532,23 +532,32 @@ typedef struct /* USER CODE END EM */ /* Exported functions prototypes ---------------------------------------------*/ - +// 0 --- 10 11 12 -- 39 40 41 42 43 44-63 +// LEN P RSS FALL_DETECTION AC_CODE enum nvm_order { NVM_MTM1=0, NVM_MTM2, NVM_VER, NVM_HWV, - NVM_PERIODICITY_H, - NVM_PERIODICITY_L, + NVM_PERIODICITY, NVM_UNIT, - NVM_SAMPLING_H, - NVM_SAMPLING_L, + NVM_SAMPLING, NVM_S_UNIT, NVM_WORK_MODE, NVM_SERVICE_MASK, - NVM_LEN, - NVM_CFG_START, - NVM_AC_CODE_START + NVM_RESERVE01, //10 + NVM_LEN, //11, 32=0x20 + NVM_CFG_START, //12, p[0] bytes for configs, + //13, p[1] + //14, p[2] + // ... + //39, P[27] + NVM_FALL_DETECTION_ACC_THRESHOLD=40, //40 + NVM_FALL_DETECTION_DEPTH_THRESHOLD, //41 + NVM_FALL_DETECTION_RESERVE, //42 + NVM_OCCUPANCY_OVERTIME_THRESHOLD, //43 + NVM_AC_CODE_START=44 //STORED, NO UPLOAD + //63, 20 bytes for AC code }; typedef struct sts_cfg_nvm { @@ -556,16 +565,19 @@ typedef struct sts_cfg_nvm { uint8_t mtmcode2; uint8_t version; uint8_t hardware_ver; - uint8_t periodicity_h; //count of uplink duty cycle duration high {0,9} - uint8_t periodicity_l; //count of uplink duty cycle duration low {0,9} - uint8_t unit; // uplink time unit of duty cycle duration, in 'S', 'M','H' seconds, minutes, hours - uint8_t heartbeat_h; //count of heart-beat duty cycle duration high {0,9} - uint8_t heartbeat_l; //count of heart-beat duty cycle duration low {0,9} - uint8_t s_unit; // sampling time unit of duty cycle duration, in 'S', 'M','H' seconds, minutes, hours + uint8_t periodicity; //count of uplink duty cycle duration high {99} + uint8_t unit; // uplink time unit of duty cycle duration, in 'S', 'M','H' seconds, minutes, hours + uint8_t sampling; //count of sampling duty cycle duration high {99} + uint8_t s_unit; // sampling time unit of duty cycle duration, in 'S', 'M','H' seconds, minutes, hours uint8_t work_mode; uint8_t sts_service_mask; - uint8_t length; - uint8_t p[YUNHORN_STS_MAX_NVM_CFG_SIZE]; //max 64 bytes + uint8_t reseve01; + uint8_t length; // length of following parameters except AC CODE(20bytes) + uint8_t p[STS_CFG_PCFG_SIZE]; + uint8_t fall_detection_acc_threshold; // 0 - 9: 0:disable: 1-9 accelaration mg/s2 + uint8_t fall_detection_depth_threshold; // 0 - 9: 0:disable: 1-9 fall down depth * 10 cm + uint8_t fall_detection_reserve; + uint8_t occupancy_overtime_threshold; // 0 - 9: 0:disable, 1-9 occupy over time threshold * 10 min uint8_t ac[YUNHORN_STS_AC_CODE_SIZE]; // authorization code, 20 bytes MCU UUID coded } sts_cfg_nvm_t; diff --git a/Core/Src/yunhorn_sts_process.c b/Core/Src/yunhorn_sts_process.c index 4d3a689..c5174d8 100644 --- a/Core/Src/yunhorn_sts_process.c +++ b/Core/Src/yunhorn_sts_process.c @@ -39,7 +39,8 @@ extern volatile sts_cfg_nvm_t sts_cfg_nvm; extern volatile uint8_t sts_ac_code[20]; volatile uint8_t sts_service_mask; volatile uint32_t rfac_timer; - +extern volatile uint8_t sensor_data_ready; +volatile uint32_t event_start_time, event_stop_time; #if (defined(YUNHORN_STS_O6_ENABLED) && defined(USE_ACCONEER_A111)) extern volatile STS_OO_RSS_SensorTuneDataTypeDef sts_presence_rss_config; @@ -118,7 +119,10 @@ void STS_YunhornAuthenticationCode_Process(void) } sts_service_mask = (sts_hmac_verify()!= 0)? STS_SERVICE_MASK_L2:STS_SERVICE_MASK_L0; - APP_LOG(TS_OFF, VLEVEL_M, "STS_SERVICE_MASK:%d \r\n",sts_service_mask); + if (sts_service_mask == STS_SERVICE_MASK_L2) { + sts_ac_code[0] = 0x0; + } + APP_LOG(TS_OFF, VLEVEL_H, "STS_SERVICE_MASK:%d \r\n",sts_service_mask); } void STS_YunhornSTSEventRFAC_Process(void) @@ -134,6 +138,9 @@ void STS_YunhornSTSEventRFAC_Process(void) { APP_LOG(TS_OFF, VLEVEL_M, "\r\n -------------------Verify RFAC Success or Not\r\n"); sts_service_mask = (sts_hmac_verify()!= 0)? STS_SERVICE_MASK_L2:STS_SERVICE_MASK_L0; + if (sts_service_mask == STS_SERVICE_MASK_L2) { + sts_ac_code[0] = 0x0; + } } } diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 5583b75..2270344 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -51,30 +51,67 @@ extern volatile uint32_t rfac_timer; volatile uint8_t sts_ac_code[YUNHORN_STS_AC_CODE_SIZE]={0x0}; extern hmac_result_t hmac_result; volatile uint8_t sts_work_mode =0; -//volatile uint32_t SamplingPeriodicity = 15000; //unit ms -//volatile uint32_t HeartBeatPeriodicity = 25000; //unit ms -//volatile uint32_t UploadingMessagePeriodicity = 30000; //unit ms +volatile uint8_t sensor_data_ready=0; +extern volatile uint8_t ToF_EventDetected; +extern volatile int sts_tof_distance_data; +volatile uint32_t SamplingPeriodicity = 1000; //unit ms +volatile uint32_t HeartBeatPeriodicity = 120000; //unit ms volatile uint8_t STS_LoRa_WAN_Joined = 0; volatile uint8_t mems_int1_detected = 0; volatile uint8_t periodicity_level=0; volatile uint8_t heart_beat_timer =0; +char outbuf[128]=""; volatile uint8_t upload_message_timer =0; volatile sts_cfg_nvm_t sts_cfg_nvm = { - sts_mtmcode1,sts_mtmcode2, sts_version, sts_hardware_ver, - 0x02,0x00,'S', //Upload message interval - 0x01,0x00,'S', //Sampling sensor interval + sts_mtmcode1, + sts_mtmcode2, + sts_version, + sts_hardware_ver, + 0x02, + 'S', //Upload message interval + 0x0A, + 'S', //Sampling sensor interval 0x04, // dual mode 0x00, // service mask - 0x1E, //30 bytes, below start of p[0] - { - 0x00,0x00, //lenght_m [2 0]=2.0f - 0x01,0x03, //threshold [1 3]=1.3f + 0x00, // reserve01 + 0x20, //32 bytes, below start of p[0] + { // below 28 bytes + 0x08, //start_m [8]*0.1 meter =0.8 + 0x19, //lenght_m 0x19=[25]*0.1=2.5f meter + 0x0F, //threshold 0X0F=[15]*0.1=1.5f + 0x28, //receiver gain 0x28 =[40]*0.01=0.40f max 99=0x63 0x04, //profile [4]=4 - 0x00,0x05, //output time const [0 5]=0.5 + 0x0A, //rate tracking 0x0A=10= 10U + 0x41, //rate presence 0x41=65= 65U + 0x3F, //hwaas 0x3F=63 =63U + 0x00, //nbr removed pc [0]=0 + 0x05, //inter frame deviation time const 0x05=[5]*0.1=0.5f + 0x0A, //inter frame fast cutoff 0x0A=[10] = 10U + 0x01, //inter frame slow cutoff,0x01=1[1]*0.01=0.01f + 0x00, //intra frame time const [0]=0 + 0x00, //intra frame weight, 0x00=[0]*0.1=0.0F + 0x05, //output time const 0x05=[5]*0.1=0.5 0x02, //downsampling factor [2]=2 - 0x03 //power saving mode [3] = 3U - }, - {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0} + 0x03, //power saving mode ACTIVE [3] = 3U + 0x00, //reserve + 0x00, //reserve + 0x00, //reserve + 0x00, //reserve + 0x00, //reserve + 0x00, //reserve + 0x00, //reserve + 0x00, //reserve + 0x00, //reserve + 0x00, //reserve + 0x00, //reserve + }, // above 28 bytes + // below 4 bytes + 0x01, //fall_detection_acc_threshold = *10 acceleration measure + 0x03, //fall detection_depth_threshold *10cm + 0x00, //reserve + 0x02, //occupancy over time threshold *10 minutes + // below 20 bytes + {0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0} }; @@ -103,7 +140,8 @@ typedef enum TxEventType_e //#define YUNHORN_STS_SAMPLING_CHECK_TIME SamplingPeriodicity //#define YUNHORN_STS_UPLOADING_MESSAGE_TIME UploadingMessagePeriodicity //#define YUNHORN_STS_HEART_BEAT_CHECK_TIME HeartBeatPeriodicity - +#define YUNHORN_STS_RSS_WAKEUP_CHECK_TIME SamplingPeriodicity //3000 ms +#define YUNHORN_STS_SAMPLING_CHECK_TIME SamplingPeriodicity /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ @@ -273,36 +311,18 @@ static void OnRxTimerLedEvent(void *context); */ static void OnJoinTimerLedEvent(void *context); - -/** REF - * @brief TX timer callback function - * @param context ptr of timer context +/** + * @brief Yunhorn STS Occupancy RSS WakeUP timer callback function + * @param context ptr of STS RSS WakeUp context */ -//REF: static void OnTxTimerEvent(void *context); - -//static void OnYunhornSTSSamplingPeriodicityChanged(uint32_t periodicity); - -//static void OnYunhornSTSUploadingMessagePeriodicityChanged(uint32_t periodicity); +static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context); +/** + * @brief Yunhorn STS Heart Beat Periodicity Chagne function + * @param duration of periodicty in ms (1/1000 sec) + */ static void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity); -/** - * @brief Yunhorn STS Sampling Check timer callback function - * @param context ptr of STS Sampling Check context - */ - -/* - * - * static void OnYunhornSTSSamplingCheckTimerEvent(void *context); - * - */ - -/** - * @brief Yunhorn STS Uploading Message callback function - * @param context ptr of STS Sampling Check context - */ -//static void OnYunhornSTSUploadingMessageEvent(void *context); - /** * @brief Yunhorn STS Heart Beat callback function * @param context ptr of STS Sampling Check context @@ -416,6 +436,11 @@ static UTIL_TIMER_Object_t RxLedTimer; */ static UTIL_TIMER_Object_t JoinLedTimer; +/** + * @brief Timer to handle the YunHorn STS RSS WakeUP Checking + */ +static UTIL_TIMER_Object_t YunhornSTSRSSWakeUpTimer; + /** * @brief Timer to handle the YunHorn STS Sensor Sampling Process */ @@ -433,17 +458,13 @@ static UTIL_TIMER_Object_t YunhornSTSHeartBeatTimer; /** * @brief Heart-Beat Timer period */ -static UTIL_TIMER_Time_t HeartBeatPeriodicity = 30*APP_TX_DUTYCYCLE; // 5 MIN initial - +//static UTIL_TIMER_Time_t HeartBeatPeriodicity = 30*APP_TX_DUTYCYCLE; // 5 MIN initial /* USER CODE END PV */ /* Exported functions ---------------------------------------------------------*/ /* USER CODE BEGIN EF */ -extern volatile uint8_t ToF_EventDetected; -extern volatile int sts_tof_distance_data; -extern volatile uint8_t TIME_TO_SEND; -extern volatile uint8_t sensor_data_ready; + /* USER CODE END EF */ void LoRaWAN_Init(void) @@ -538,8 +559,6 @@ void LoRaWAN_Init(void) /* USER CODE BEGIN LoRaWAN_Init_Last */ - APP_LOG(TS_OFF,VLEVEL_L,"REBOOT CONFIG \r\n"); - STS_REBOOT_CONFIG_Init(); @@ -1143,6 +1162,22 @@ static void OnRestoreContextRequest(void *nvm, uint32_t nvm_size) /* USER CODE END OnRestoreContextRequest_Last */ } + +/** + * @brief Yunhorn STS Occupancy RSS WakeUP timer callback function, act as sampling process + * @param context ptr of STS RSS WakeUp context + */ +static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context) +{ + UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP2), CFG_SEQ_Prio_0); + + if (STS_LoRa_WAN_Joined != 0) + { + UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); + + } +} + /** * @brief Yunhorn STS Sensor Live Heart Beat Periodicity/interval Change callback function * @param context ptr of STS Live Heart Beat context @@ -1211,30 +1246,38 @@ static void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity) * @param context ptr of STS RSS WakeUp context */ -//static void OnYunhornSTSSamplingPeriodicityChanged(uint32_t periodicity) -//{ +static void OnYunhornSTSSamplingPeriodicityChanged(uint32_t periodicity) +{ /* USER CODE BEGIN OnTxPeriodicityChanged_1 */ /* USER CODE END OnTxPeriodicityChanged_1 */ - //SamplingPeriodicity = periodicity; + SamplingPeriodicity = periodicity; - //if (SamplingPeriodicity == 0) - //{ + if (SamplingPeriodicity == 0) + { /* Revert to application default periodicity */ - // SamplingPeriodicity = APP_TX_DUTYCYCLE; - //} + SamplingPeriodicity = APP_TX_DUTYCYCLE; + } /* Update timer periodicity */ +#if (defined(YUNHORN_STS_O6_ENABLED) || defined(YUNHORN_STS_R0_ENABLED)) + UTIL_TIMER_Stop(&YunhornSTSRSSWakeUpTimer); + UTIL_TIMER_SetPeriod(&YunhornSTSRSSWakeUpTimer, SamplingPeriodicity); + UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer); + APP_LOG(TS_OFF, VLEVEL_L,"**************** Sampling Timer Periodicity = %u (sec)\r\n", (SamplingPeriodicity/1000) ); - // UTIL_TIMER_Stop(&YunhornSTSSamplingCheckTimer); -// UTIL_TIMER_SetPeriod(&YunhornSTSSamplingCheckTimer, SamplingPeriodicity); -// UTIL_TIMER_Start(&YunhornSTSSamplingCheckTimer); +#else + UTIL_TIMER_Stop(&YunhornSTSSamplingCheckTimer); + UTIL_TIMER_SetPeriod(&YunhornSTSSamplingCheckTimer, SamplingPeriodicity); + UTIL_TIMER_Start(&YunhornSTSSamplingCheckTimer); + APP_LOG(TS_OFF, VLEVEL_L,"**************** SamplingPeriodicity = %u (sec)\r\n", (SamplingPeriodicity/1000) ); +#endif /* USER CODE BEGIN OnTxPeriodicityChanged_2 */ -// APP_LOG(TS_OFF, VLEVEL_M,"**************** SamplingPeriodicity = %u (ms)\r\n", SamplingPeriodicity ); + /* USER CODE END OnTxPeriodicityChanged_2 */ -//} +} /* @@ -1324,7 +1367,7 @@ static void OnYunhornSTSHeartBeatTimerEvent(void *context) void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) { uint8_t i=0, mems_ver, invalid_flag=1; - char outbuf[128]=""; + /* * YUNHORN STS PRODUCT BOARD LEVEL CONTROL OR REPORT @@ -1352,18 +1395,15 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) * --M SERVICE LEVEL MASK * --# 'YM0', 'YM1','YM2', 'YM3' [YM0] WU0w [YM1]WU0x [YM2]WU0y [YM3]WU0z * - * --D UPLINK DURATION OR PERIODICITY + * --D UPLINK DURATION OR PERIODICITY Periodicity of Tx interval or Heart-Beat interval for real-time occupancy status update 2023-04-28 * --# * --# * --U UNIT (S, M, H) SECONDS, MINUTES, HOURS - * --S SAMPLING INTERVAL OR PERIODICITY - * --# - * --# - * --U UNIT (S, M, H) SECONDS, MINUTES, HOURS - * --L LIVE HEART BEAT DURATION OR PERIODICITY + * --S SAMPLING INTERVAL OR PERIODICITY periodicity for real-time sensing * --# * --# * --U UNIT (S, M, H) SECONDS, MINUTES, HOURS + * * --P ***** WORKMODE AND NETWORK COLOR * --# MTM-VER 1 @@ -1394,12 +1434,11 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) * --# MTM-VER 1 * --# STS-VER 1 * --30{#} FULL CONFIG PARAMETER + * --A ***** AC CODE (22 BYTES) + * --C + * --# + * --20{#} AC CODE 20 BYTES * - * - * - * --A - * --C - * --AC_CODE */ if (((char)tlv_buf[CFG_CMD1] == 'Y') && (tlv_buf_size <=5)) // BEGIN OF *** BOARD LEVEL CONTROL OR REPORT @@ -1411,19 +1450,21 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) //BOARD REVIVE STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, 20, "!YunHorn STS Revive!"); HAL_Delay(5000); + APP_LOG(TS_OFF, VLEVEL_H, "\r\n Yunhorn STS Node Revive ... \r\n"); + HAL_Delay(3000); OnSystemReset(); } else if ((char)tlv_buf[CFG_CMD3] == 'S') { // Self Function Testing "YZS" - i=0; - outbuf[i++] = (uint8_t) 'Y'; - outbuf[i++] = (uint8_t) 'Z'; - outbuf[i++] = (uint8_t) 'S'; - //STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf); i=0; memset(outbuf,sizeof(outbuf),0x30); + STS_SENSOR_Function_Test_Process(); + HAL_Delay(5000); + i=21; + STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf); + } else if ((char)tlv_buf[CFG_CMD3] == 'C') { // Lora-WAN Class "YZC" LORAWAN CLASS A/B/C DeviceClass_t deviceClass = CLASS_A; @@ -1441,10 +1482,8 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) outbuf[i++] = (uint8_t) 'Z'; outbuf[i++] = (uint8_t) 'D'; //STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf); -#ifdef YUNHORN_STS_O6_ENABLED - STS_SENSOR_Distance_Test_Process(); - APP_LOG(TS_OFF, VLEVEL_H, "\r\nRSS Measured Distance=[%u] mm \r\n", (int)sts_distance_rss_distance); + STS_SENSOR_Distance_Test_Process(); i=0; memset(outbuf,sizeof(outbuf),0x30); @@ -1454,11 +1493,16 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) outbuf[i++] = (uint8_t)sts_version; outbuf[i++] = (uint8_t)sts_hardware_ver; outbuf[i++] = (uint8_t)(99*((GetBatteryLevel()/254)&0xff)); +#ifdef STS_O6_ENABLED outbuf[i++] = (uint8_t)0x04; //length of following data outbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/1000)%10+0x30)&0xff; outbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/100)%10+0x30)&0xff; outbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/10)%10+0x30)&0xff; outbuf[i++] = (uint8_t) (((uint16_t)sts_distance_rss_distance)%10+0x30)&0xff; +#endif +#ifdef YUNHORN_STS_R0_ENABLED + outbuf[i++] = (uint8_t) (((uint16_t)sts_tof_distance_data)/100)&0xff; + outbuf[i++] = (uint8_t) (((uint16_t)sts_tof_distance_data)%100)&0xff; #endif STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf); @@ -1475,7 +1519,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) outbuf[i++] = (uint8_t) 'M'; outbuf[i++] = (uint8_t) (sts_service_mask+0x30); STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf); - //APP_LOG(TS_OFF, VLEVEL_L, ">>>>>>>>>>>>>>>>>>>>> Mask = [ %02x ] \r\n", sts_service_mask); + APP_LOG(TS_OFF, VLEVEL_L, ">>>>>>>>>>>>>>>>>>>>> Mask = [ %02x ] \r\n", sts_service_mask); OnStoreSTSCFGContextRequest(); #ifdef YUNHORN_STS_O6_ENABLED if (sts_service_mask != STS_SERVICE_MASK_L0) STS_Lamp_Bar_Set_Dark(); @@ -1503,26 +1547,29 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) uint8_t cfg_in_nvm[YUNHORN_STS_MAX_NVM_CFG_SIZE]=""; OnRestoreSTSCFGContextRequest((uint8_t *)cfg_in_nvm); + i=0; + memset(outbuf,sizeof(outbuf),0x30); outbuf[i++] = (uint8_t) 'C'; outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_MTM1]; //MTM Code outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_MTM2]; //MTM Code outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_VER]; //STS Version - outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_PERIODICITY_H]; //UPLINK Periodicity count high - outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_PERIODICITY_L]; //UPLINK Periodicity count low + outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_HWV]; //STS Version + outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_PERIODICITY]/10); //UPLINK Periodicity count high + outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_PERIODICITY]%10); //UPLINK Periodicity count low outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_UNIT]; //UPLINK Periodicity unit - outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_SAMPLING_H]; //SAMPLING Periodicity count high - outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_SAMPLING_L]; //SAMPLING Periodicity count low + outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_SAMPLING]/10); //SAMPLING Periodicity count high + outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_SAMPLING]%10); //SAMPLING Periodicity count low outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_S_UNIT]; //SAMPLING Periodicity unit outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_WORK_MODE]; // STS WORK MODE - outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_SERVICE_MASK]; //service mask - outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_LEN]; //length of following cfg value + outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_SERVICE_MASK]; //service mask + outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_RESERVE01]; //service mask + outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_LEN]; //length of following cfg value - for (uint8_t j=1; j <= cfg_in_nvm[NVM_LEN]; j++) { - outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_LEN+j]); + for (uint8_t j=0; j < cfg_in_nvm[NVM_LEN]; j++) { + outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_CFG_START+j]); } STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf); - //APP_LOG(TS_OFF, VLEVEL_L, "###### YUNHORN Report Config in NVM [ %30X ] \r\n", outbuf); } break; @@ -1575,18 +1622,16 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) (((char)tlv_buf[CFG_CMD5] == 'M' || ((char)tlv_buf[CFG_CMD5] =='H') ||((char)tlv_buf[CFG_CMD5] =='S')))) { uint32_t periodicity_length = (tlv_buf[CFG_CMD3]-0x30)*10+ (tlv_buf[CFG_CMD4]-0x30); - uint8_t periodicity_unit = (char)tlv_buf[CFG_CMD5]; - if ((char)tlv_buf[CFG_CMD5] == 'M') { periodicity_length *= 60; } else if ((char)tlv_buf[CFG_CMD5] == 'H') { periodicity_length *= 3600; } + TxPeriodicity = periodicity_length*1000; //translate to 1000ms=1s + HeartBeatPeriodicity = TxPeriodicity; - - OnTxPeriodicityChanged(periodicity_length*1000); //translate to 1000ms=1s - + OnTxPeriodicityChanged(TxPeriodicity); i = 0; outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD1]; outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD2]; @@ -1600,35 +1645,32 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) sts_cfg_nvm.mtmcode2 = (uint8_t)sts_mtmcode2; sts_cfg_nvm.version = (uint8_t)sts_version; sts_cfg_nvm.hardware_ver = (uint8_t)sts_hardware_ver; - sts_cfg_nvm.periodicity_h = (uint8_t)(tlv_buf[CFG_CMD3]-0x30); - sts_cfg_nvm.periodicity_l = (uint8_t)(tlv_buf[CFG_CMD4]-0x30); - sts_cfg_nvm.unit = (uint8_t)periodicity_unit; + sts_cfg_nvm.periodicity = (uint8_t)((tlv_buf[CFG_CMD3]-0x30)*10+(tlv_buf[CFG_CMD4]-0x30)); + sts_cfg_nvm.unit = (uint8_t)tlv_buf[CFG_CMD5]; sts_cfg_nvm.work_mode = (uint8_t)sts_work_mode; sts_cfg_nvm.sts_service_mask = (uint8_t)sts_service_mask; OnStoreSTSCFGContextRequest(); - //APP_LOG(TS_OFF, VLEVEL_M, "###### YUNHORN Upload Message Periodicity Changed to [ %d ] Seconds\r\n", periodicity_length); + APP_LOG(TS_OFF, VLEVEL_M, "###### YUNHORN Periodicity Changed to [ %d ] Seconds\r\n", periodicity_length); } else { STS_SENSOR_Upload_Config_Invalid_Message(); } break; - case 'L': // LIVE HEART BEAT INTERVAL OR DURATION + case 'S': // SAMPLING INTERVAL OR DURATION if ((((char)tlv_buf[CFG_CMD3] >= '0') && ((char)tlv_buf[CFG_CMD3] <='9') && ((char)tlv_buf[CFG_CMD4] >='0') && ((char)tlv_buf[CFG_CMD4] <='9')) && (((char)tlv_buf[CFG_CMD5] == 'M' || ((char)tlv_buf[CFG_CMD5] =='H') ||((char)tlv_buf[CFG_CMD5] =='S')))) { - uint32_t periodicity_length = (tlv_buf[CFG_CMD3]-0x30)*10+ (tlv_buf[CFG_CMD4]-0x30); - uint8_t periodicity_unit = (char)tlv_buf[CFG_CMD5]; - + uint32_t sampling_periodicity_length = (tlv_buf[CFG_CMD3]-0x30)*10+ (tlv_buf[CFG_CMD4]-0x30); if ((char)tlv_buf[CFG_CMD5] == 'M') { - periodicity_length *= 60; + sampling_periodicity_length *= 60; } else if ((char)tlv_buf[CFG_CMD5] == 'H') { - periodicity_length *= 3600; + sampling_periodicity_length *= 3600; } - - OnYunhornSTSHeartBeatPeriodicityChanged(periodicity_length*1000); //translate to 1000ms=1s + SamplingPeriodicity = sampling_periodicity_length*1000; //translate to 1000ms=1s + OnYunhornSTSSamplingPeriodicityChanged(SamplingPeriodicity); i = 0; outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD1]; @@ -1643,14 +1685,13 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) sts_cfg_nvm.mtmcode2 = (uint8_t)sts_mtmcode2; sts_cfg_nvm.version = (uint8_t)sts_version; sts_cfg_nvm.hardware_ver = (uint8_t)sts_hardware_ver; - sts_cfg_nvm.heartbeat_h = (uint8_t)(tlv_buf[CFG_CMD3]-0x30); - sts_cfg_nvm.heartbeat_l = (uint8_t)(tlv_buf[CFG_CMD4]-0x30); - sts_cfg_nvm.s_unit = (uint8_t)periodicity_unit; + sts_cfg_nvm.sampling = (uint8_t)((tlv_buf[CFG_CMD3]-0x30)*10+(tlv_buf[CFG_CMD4]-0x30)); + sts_cfg_nvm.s_unit = (uint8_t)tlv_buf[CFG_CMD5]; sts_cfg_nvm.work_mode = (uint8_t)sts_work_mode; sts_cfg_nvm.sts_service_mask = (uint8_t)sts_service_mask; OnStoreSTSCFGContextRequest(); - //APP_LOG(TS_OFF, VLEVEL_M, "###### YUNHORN Heart Beat Interval Changed to [ %d ] Seconds\r\n", periodicity_length); + APP_LOG(TS_OFF, VLEVEL_M, "###### YUNHORN Sampling Interval Changed to [ %d ] Seconds\r\n", sampling_periodicity_length); } else { STS_SENSOR_Upload_Config_Invalid_Message(); @@ -1753,41 +1794,42 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) } //END OF SWITCH TVL_BUF_P_MEMS_NO } //END OF PARAMETER CONFIG - else if (((char)tlv_buf[CFG_CMD1] == 'A') && ((char)tlv_buf[CFG_CMD2] == 'C') && (tlv_buf_size =22)) // BEGIN OF *** BOARD LEVEL AUTHORIZATION CODE - { - // 'AC'+ AC_CODE(20bytes) - - for (uint8_t j=0; j< 20; j++) + else if (((char)tlv_buf[CFG_CMD1] == 'A') && ((char)tlv_buf[CFG_CMD2] == 'C') && (tlv_buf_size == (YUNHORN_STS_AC_CODE_SIZE+2))) // BEGIN OF *** BOARD LEVEL AUTHORIZATION CODE { - sts_ac_code[j] = (uint8_t) tlv_buf[2+j]; - APP_LOG(TS_OFF, VLEVEL_L," %02x ", sts_ac_code[j]) - } + // 'AC'+ AC_CODE(20bytes) - STS_YUNHORN_RFAC_HANDLE_PROCESS(); - - if ((hmac_result.ac_pass == 1)) - { - for (uint8_t j=0; j < YUNHORN_STS_AC_CODE_SIZE; j++) + for (uint8_t j=0; j< YUNHORN_STS_AC_CODE_SIZE; j++) { - sts_cfg_nvm.ac[j] = sts_ac_code[j]; + sts_ac_code[j] = (uint8_t) tlv_buf[2+j]; } - sts_service_mask = STS_SERVICE_MASK_L0; + STS_YUNHORN_RFAC_HANDLE_PROCESS(); - } else { - sts_service_mask = STS_SERVICE_MASK_L2; + if ((hmac_result.ac_pass == 1U)) + { + for (uint8_t j=0; j < YUNHORN_STS_AC_CODE_SIZE; j++) + { + sts_cfg_nvm.ac[j] = sts_ac_code[j]; + } + + sts_service_mask = STS_SERVICE_MASK_L0; + + sts_cfg_nvm.sts_service_mask = sts_service_mask; + OnStoreSTSCFGContextRequest(); + + + } else { + sts_service_mask = STS_SERVICE_MASK_L2; + + } + + i=0; + for (uint8_t j=0; j <(tlv_buf_size) ; j++) { + outbuf[i++] = (uint8_t) tlv_buf[j]; + } + STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char*)outbuf); } - sts_cfg_nvm.sts_service_mask = sts_service_mask; - OnStoreSTSCFGContextRequest(); - - i=0; - for (uint8_t j=0; j <(tlv_buf_size) ; j++) { - outbuf[i++] = (uint8_t) tlv_buf[j]; - } - STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char*)outbuf); - - } } // END OF USER_APP_AUTO_RESPONDER_Parse @@ -1817,7 +1859,7 @@ void STS_SENSOR_Upload_Message(uint8_t appDataPort, uint8_t appBufferSize, char } AppData.Port = appDataPort; - AppData.BufferSize = (sts_service_mask >2?0:appBufferSize); + AppData.BufferSize = (sts_service_mask >1?0:appBufferSize); if ((JoinLedTimer.IsRunning) && (LmHandlerJoinStatus() == LORAMAC_HANDLER_SET)) { @@ -1909,42 +1951,42 @@ void STS_SENSOR_Auto_Responder_Process(uint8_t tlv_ver,uint8_t tlv_type, uint8_t void OnStoreSTSCFGContextRequest(void) { /* USER CODE BEGIN OnStoreContextRequest_1 */ - uint8_t nvm_store_value[YUNHORN_STS_MAX_NVM_CFG_SIZE]=""; - uint8_t nvm_store_size=YUNHORN_STS_MAX_NVM_CFG_SIZE; - uint8_t i=0, j=0; + uint8_t i=0, j=0, nvm_store_value[YUNHORN_STS_MAX_NVM_CFG_SIZE]=""; -//#ifdef YUNHORN_STS_O6_ENABLED - sts_cfg_nvm.length = NVM_CFG_PARAMETER_SIZE; +#if (defined(YUNHORN_STS_O6_ENABLED) || defined(YUNHORN_STS_R0_ENABLED)) + sts_cfg_nvm.length = STS_NVM_CFG_SIZE; nvm_store_value[i++] = sts_cfg_nvm.mtmcode1; nvm_store_value[i++] = sts_cfg_nvm.mtmcode2; nvm_store_value[i++] = sts_cfg_nvm.version; nvm_store_value[i++] = sts_cfg_nvm.hardware_ver; - nvm_store_value[i++] = sts_cfg_nvm.periodicity_h; - nvm_store_value[i++] = sts_cfg_nvm.periodicity_l; + nvm_store_value[i++] = sts_cfg_nvm.periodicity; nvm_store_value[i++] = sts_cfg_nvm.unit; - nvm_store_value[i++] = sts_cfg_nvm.heartbeat_h; - nvm_store_value[i++] = sts_cfg_nvm.heartbeat_l; + nvm_store_value[i++] = sts_cfg_nvm.sampling; nvm_store_value[i++] = sts_cfg_nvm.s_unit; nvm_store_value[i++] = sts_cfg_nvm.work_mode; nvm_store_value[i++] = sts_cfg_nvm.sts_service_mask; - nvm_store_value[i++] = sts_cfg_nvm.length; + nvm_store_value[i++] = sts_cfg_nvm.reseve01; + nvm_store_value[i++] = (uint8_t) STS_NVM_CFG_SIZE; //sts_cfg_nvm.length; - for (j = 0; j < NVM_CFG_PARAMETER_SIZE; j++) { + for (j = 0; j < STS_CFG_PCFG_SIZE; j++) { nvm_store_value[i++] = (sts_cfg_nvm.p[j]); } + nvm_store_value[i++] = sts_cfg_nvm.fall_detection_acc_threshold; + nvm_store_value[i++] = sts_cfg_nvm.fall_detection_depth_threshold; + nvm_store_value[i++] = sts_cfg_nvm.fall_detection_reserve; + nvm_store_value[i++] = sts_cfg_nvm.occupancy_overtime_threshold; + for (j = 0; j < YUNHORN_STS_AC_CODE_SIZE; j++) { nvm_store_value[i++] = (sts_cfg_nvm.ac[j]); } - -//#endif - +#endif /* USER CODE END OnStoreContextRequest_1 */ /* store nvm in flash */ if (FLASH_IF_Erase(STS_CONFIG_NVM_BASE_ADDRESS, FLASH_PAGE_SIZE) == FLASH_IF_OK) { - FLASH_IF_Write(STS_CONFIG_NVM_BASE_ADDRESS, (const void *)nvm_store_value, nvm_store_size); + FLASH_IF_Write(STS_CONFIG_NVM_BASE_ADDRESS, (const void *)nvm_store_value, YUNHORN_STS_MAX_NVM_CFG_SIZE); } @@ -1969,13 +2011,13 @@ void OnRestoreSTSCFGContextRequest(uint8_t *cfg_in_nvm) void STS_REBOOT_CONFIG_Init(void) { /* USER CODE BEGIN OnRestoreContextRequest_1 */ - uint8_t nvm_stored_value[YUNHORN_STS_MAX_NVM_CFG_SIZE]="", nvm_store_size=YUNHORN_STS_MAX_NVM_CFG_SIZE; + uint8_t nvm_stored_value[YUNHORN_STS_MAX_NVM_CFG_SIZE]={0x0}; /* USER CODE END OnRestoreContextRequest_1 */ - UTIL_MEM_cpy_8(nvm_stored_value, (void *)STS_CONFIG_NVM_BASE_ADDRESS, nvm_store_size); + UTIL_MEM_cpy_8(nvm_stored_value, (void *)STS_CONFIG_NVM_BASE_ADDRESS, YUNHORN_STS_MAX_NVM_CFG_SIZE); /* USER CODE BEGIN OnRestoreContextRequest_Last */ - //if ((nvm_stored_value[0] == 0xFF) || (nvm_stored_value[1] == 0xFF) ||(nvm_stored_value[2] == 0xFF)) +#if (defined(YUNHORN_STS_O6_ENABLED) || defined(YUNHORN_STS_R0_ENABLED)) if ((nvm_stored_value[NVM_MTM1] != sts_mtmcode1) || (nvm_stored_value[NVM_MTM2] != sts_mtmcode2) || (nvm_stored_value[NVM_VER] != sts_version)) { APP_LOG(TS_OFF, VLEVEL_L, "\r\nInitial Boot with Empty Config, Flash with default config....\r\n"); @@ -1984,28 +2026,33 @@ void STS_REBOOT_CONFIG_Init(void) HAL_Delay(1000); } else { - sts_cfg_nvm.mtmcode1 = (uint8_t)nvm_stored_value[NVM_MTM1]; - sts_cfg_nvm.mtmcode2 = (uint8_t)nvm_stored_value[NVM_MTM2]; - sts_cfg_nvm.version = (uint8_t)nvm_stored_value[NVM_VER]; - sts_cfg_nvm.hardware_ver = (uint8_t)nvm_stored_value[NVM_HWV]; - sts_cfg_nvm.periodicity_h = (uint8_t)(nvm_stored_value[NVM_PERIODICITY_H]); - sts_cfg_nvm.periodicity_l = (uint8_t)(nvm_stored_value[NVM_PERIODICITY_L]); - sts_cfg_nvm.unit = (uint8_t)(nvm_stored_value[NVM_UNIT]); - sts_cfg_nvm.heartbeat_h = (uint8_t)(nvm_stored_value[NVM_SAMPLING_H]); - sts_cfg_nvm.heartbeat_l = (uint8_t)(nvm_stored_value[NVM_SAMPLING_L]); - sts_cfg_nvm.s_unit = (uint8_t)(nvm_stored_value[NVM_S_UNIT]); - sts_cfg_nvm.work_mode = (uint8_t)(nvm_stored_value[NVM_WORK_MODE]); - sts_cfg_nvm.sts_service_mask = (uint8_t)(nvm_stored_value[NVM_SERVICE_MASK]); - sts_cfg_nvm.length = (uint8_t)(nvm_stored_value[NVM_LEN]&0x3F); //MAX 32 bytes - for (uint8_t j=0; j< sts_cfg_nvm.length; j++) { - sts_cfg_nvm.p[j] = (uint8_t)nvm_stored_value[NVM_CFG_START+j]; - } - for (uint8_t j=0; j< YUNHORN_STS_AC_CODE_SIZE; j++) { - sts_cfg_nvm.ac[j] = (uint8_t)nvm_stored_value[NVM_CFG_START+sts_cfg_nvm.length + j]; - } + sts_cfg_nvm.mtmcode1 = (uint8_t)nvm_stored_value[NVM_MTM1]; + sts_cfg_nvm.mtmcode2 = (uint8_t)nvm_stored_value[NVM_MTM2]; + sts_cfg_nvm.version = (uint8_t)nvm_stored_value[NVM_VER]; + sts_cfg_nvm.hardware_ver = (uint8_t)nvm_stored_value[NVM_HWV]; + sts_cfg_nvm.periodicity = (uint8_t)(nvm_stored_value[NVM_PERIODICITY]); + sts_cfg_nvm.unit = (uint8_t)(nvm_stored_value[NVM_UNIT]); + sts_cfg_nvm.sampling = (uint8_t)(nvm_stored_value[NVM_SAMPLING]); + sts_cfg_nvm.s_unit = (uint8_t)(nvm_stored_value[NVM_S_UNIT]); + sts_cfg_nvm.work_mode = (uint8_t)(nvm_stored_value[NVM_WORK_MODE]); + sts_cfg_nvm.sts_service_mask = (uint8_t)(nvm_stored_value[NVM_SERVICE_MASK]); + sts_cfg_nvm.reseve01 = (uint8_t)(nvm_stored_value[NVM_RESERVE01]); + sts_cfg_nvm.length = (uint8_t)(nvm_stored_value[NVM_LEN]&0x3F); //MAX 32 bytes + for (uint8_t j=0; j< sts_cfg_nvm.length; j++) { + sts_cfg_nvm.p[j] = (uint8_t)nvm_stored_value[NVM_CFG_START+j]; + } + + sts_cfg_nvm.fall_detection_acc_threshold = (uint8_t)nvm_stored_value[NVM_FALL_DETECTION_ACC_THRESHOLD]; + sts_cfg_nvm.fall_detection_depth_threshold = (uint8_t)nvm_stored_value[NVM_FALL_DETECTION_DEPTH_THRESHOLD]; + sts_cfg_nvm.fall_detection_reserve = (uint8_t)nvm_stored_value[NVM_FALL_DETECTION_RESERVE]; + sts_cfg_nvm.occupancy_overtime_threshold = (uint8_t)nvm_stored_value[NVM_OCCUPANCY_OVERTIME_THRESHOLD]; + + for (uint8_t j=0; j< YUNHORN_STS_AC_CODE_SIZE; j++) { + sts_cfg_nvm.ac[j] = (uint8_t)nvm_stored_value[NVM_AC_CODE_START +j]; + } } - +#endif OnRestoreSTSCFGContextProcess(); @@ -2014,7 +2061,7 @@ void STS_REBOOT_CONFIG_Init(void) void OnRestoreSTSCFGContextProcess(void) { - uint32_t periodicity = (sts_cfg_nvm.periodicity_h)*10+(sts_cfg_nvm.periodicity_l); + uint32_t periodicity = (sts_cfg_nvm.periodicity); if ((char)sts_cfg_nvm.unit =='M') { periodicity *= 60; } else if ((char) sts_cfg_nvm.unit =='H') { @@ -2022,11 +2069,11 @@ void OnRestoreSTSCFGContextProcess(void) } else if ((char) sts_cfg_nvm.unit =='S') { periodicity *= 1; } - periodicity = (periodicity > 10)? periodicity : 10; - TxPeriodicity= periodicity*1000; // to ms - OnTxPeriodicityChanged(TxPeriodicity); -/* - uint32_t samplingperiodicity = (sts_cfg_nvm.sampling_h)*10+(sts_cfg_nvm.sampling_l); + periodicity = (periodicity > 10)? periodicity : 10; // in seconds unit + TxPeriodicity= periodicity*1000; // to ms + OnTxPeriodicityChanged(TxPeriodicity); // in msec unit + + uint32_t samplingperiodicity = (sts_cfg_nvm.sampling); if ((char)sts_cfg_nvm.s_unit =='M') { samplingperiodicity *= 60; } else if ((char) sts_cfg_nvm.s_unit =='H') { @@ -2034,49 +2081,35 @@ void OnRestoreSTSCFGContextProcess(void) } else if ((char) sts_cfg_nvm.s_unit =='S') { samplingperiodicity *= 1; } - samplingperiodicity = (samplingperiodicity > 30)? samplingperiodicity : 30; - //Global - SamplingPeriodicity =samplingperiodicity*1000; // to ms - OnYunhornSTSSamplingPeriodicityChanged(SamplingPeriodicity); -*/ - uint32_t heartbeatperiodicity = (sts_cfg_nvm.heartbeat_h)*10+(sts_cfg_nvm.heartbeat_l); - if ((char)sts_cfg_nvm.s_unit =='M') { - heartbeatperiodicity *= 60; - } else if ((char) sts_cfg_nvm.s_unit =='H') { - heartbeatperiodicity *= 3600; - } else if ((char) sts_cfg_nvm.s_unit =='S') { - heartbeatperiodicity *= 1; - } - - heartbeatperiodicity = (heartbeatperiodicity > 30)? heartbeatperiodicity : 30; - HeartBeatPeriodicity = heartbeatperiodicity*1000; - - - OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity); + samplingperiodicity = (samplingperiodicity > 0)? samplingperiodicity : 1; // in seconds unit + OnYunhornSTSSamplingPeriodicityChanged(samplingperiodicity*1000); // in m-sec unit sts_work_mode = sts_cfg_nvm.work_mode; - - + sts_service_mask = sts_cfg_nvm.sts_service_mask; #ifdef YUNHORN_STS_O6_ENABLED - sts_lamp_bar_color = STS_GREEN; - - if ((sts_version == sts_cfg_nvm.version)&& (NVM_CFG_PARAMETER_SIZE == sts_cfg_nvm.length)) - { - STS_PRESENCE_SENSOR_Init(); - - } + sts_fall_detection_acc_threshold = (uint8_t)sts_cfg_nvm.fall_detection_acc_threshold*10; + sts_fall_detection_depth_threshold = (uint8_t)sts_cfg_nvm.fall_detection_depth_threshold*10; //in cm + // **** = sts_cfg_nvm.fall_detection_reserve; + sts_occupancy_overtime_threshold = (uint8_t)sts_cfg_nvm.occupancy_overtime_threshold*10; // minutes #endif - sts_service_mask = sts_cfg_nvm.sts_service_mask; for (uint8_t j=0; j< YUNHORN_STS_AC_CODE_SIZE; j++) { sts_ac_code[j] = sts_cfg_nvm.ac[j]; } +#ifdef YUNHORN_STS_O6_ENABLED + if ((sts_version == sts_cfg_nvm.version)&& (NVM_CFG_PARAMETER_SIZE == sts_cfg_nvm.length)) + { + STS_PRESENCE_SENSOR_Init(); + STS_PRESENCE_SENSOR_RSS_Init(); + } +#endif + } void STS_SENSOR_Distance_Test_Process(void) @@ -2094,49 +2127,51 @@ void STS_SENSOR_Distance_Test_Process(void) void STS_SENSOR_Function_Test_Process(void) { - char outbuf[128] =""; uint8_t i=0; + char tstbuf[128] =""; uint8_t i=0; //uint8_t count = 1; uint8_t mems_Dev_ID[2] = ""; - outbuf[i++] = (uint8_t) 'S'; - outbuf[i++] = (uint8_t) sts_mtmcode1; - outbuf[i++] = (uint8_t) sts_mtmcode2; - outbuf[i++] = (uint8_t) sts_version; - outbuf[i++] = (uint8_t) sts_hardware_ver; - outbuf[i++] = (uint8_t) (99*((GetBatteryLevel()/254)&0xff)); + tstbuf[i++] = (uint8_t) 'S'; + tstbuf[i++] = (uint8_t) sts_mtmcode1; + tstbuf[i++] = (uint8_t) sts_mtmcode2; + tstbuf[i++] = (uint8_t) sts_version; + tstbuf[i++] = (uint8_t) sts_hardware_ver; + tstbuf[i++] = (uint8_t) (99*((GetBatteryLevel()/254)&0xff)); STS_SENSOR_MEMS_Get_ID(mems_Dev_ID); if ((mems_Dev_ID[0]==0X0) && (mems_Dev_ID[1]==0x0)) { - outbuf[i++] = (uint8_t) 'X'; // Slave MEMS Not Avaliable + tstbuf[i++] = (uint8_t) 'X'; // Slave MEMS Not Avaliable } else { - #ifdef YUNHORN_STS_O6_ENABLED - outbuf[i++] = (uint8_t)20; //length of following data +#ifdef YUNHORN_STS_O6_ENABLED + tstbuf[i++] = (uint8_t)20; //length of following data uint8_t self_test_result[10]={0,0,0,0,0, 0,0,0,0,0}; STS_PRESENCE_SENSOR_Function_Test_Process(&self_test_result[0], count); for (uint8_t j=0; j < 10; j++) - outbuf[i++] = (uint8_t) (self_test_result[j])&0xff; + tstbuf[i++] = (uint8_t) (self_test_result[j])&0xff; STS_PRESENCE_SENSOR_Distance_Measure_Process(); - outbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/1000)%10+0x30)&0xff; - outbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/100)%10+0x30)&0xff; - outbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/10)%10+0x30)&0xff; - outbuf[i++] = (uint8_t) (((uint16_t)sts_distance_rss_distance)%10+0x30)&0xff; + tstbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/1000)%10+0x30)&0xff; + tstbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/100)%10+0x30)&0xff; + tstbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/10)%10+0x30)&0xff; + tstbuf[i++] = (uint8_t) (((uint16_t)sts_distance_rss_distance)%10+0x30)&0xff; #endif #ifdef YUNHORN_STS_R0_ENABLED - outbuf[i++] = (uint8_t)2; //length of following data + tstbuf[i++] = (uint8_t)2; //length of following data MX_TOF_Process(); - outbuf[i++] = (uint8_t) ((sts_tof_distance_data >>8 ) &0xff); - outbuf[i++] = (uint8_t) (sts_tof_distance_data &0xff); + tstbuf[i++] = (uint8_t) ((sts_tof_distance_data >>8 ) &0xff); + tstbuf[i++] = (uint8_t) (sts_tof_distance_data &0xff); #endif } + memset((void*)outbuf,sizeof(outbuf),0x30); + memcpy((void*)outbuf, tstbuf, i); - STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf); + //STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf); } diff --git a/STM32CubeIDE/.settings/language.settings.xml b/STM32CubeIDE/.settings/language.settings.xml index 6d8b782..4686da5 100644 --- a/STM32CubeIDE/.settings/language.settings.xml +++ b/STM32CubeIDE/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/TOF/App/app_tof_vl53l0x_range.c b/TOF/App/app_tof_vl53l0x_range.c index d662921..8d231df 100644 --- a/TOF/App/app_tof_vl53l0x_range.c +++ b/TOF/App/app_tof_vl53l0x_range.c @@ -80,7 +80,7 @@ int LeakyFactorFix8 = (int)( 0.6 *256); int nDevPresent=0; volatile int sts_tof_distance_data; -volatile uint8_t sensor_data_ready=0; +extern volatile uint8_t sensor_data_ready; VL53L0X_Dev_t VL53L0XDevs={ .I2cHandle=&X_WL55_WLE5_53L0X_hi2c,