diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 18d3b98..4c1be42 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -63,7 +63,7 @@ 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 upload_message_timer=0; volatile uint8_t heart_beat_timer =0; char outbuf[128]=""; volatile sts_cfg_nvm_t sts_cfg_nvm = { @@ -903,6 +903,9 @@ static void SendTxData(void) { /* USER CODE BEGIN SendTxData_1 */ LmHandlerErrorStatus_t status = LORAMAC_HANDLER_ERROR; + uint8_t batteryLevel = GetBatteryLevel(); + //uint16_t batteryLevelmV = SYS_GetBatteryLevel(); + //sensor_t sensor_data; UTIL_TIMER_Time_t nextTxIn = 0; uint8_t i = 0; @@ -914,19 +917,22 @@ static void SendTxData(void) if (heart_beat_timer != 0L) { - AppData.Port = LORAWAN_USER_APP_HTBT_PORT; - heart_beat_timer = 0; - i = PrepareSendTxData(); + heart_beat_timer = 0U; + AppData.Port = sts_sendhtbtport; //LORAWAN_USER_APP_PORT+1; + AppData.Buffer[i++]= AppLedStateOn|0x80; + AppData.Buffer[i++] = (uint8_t)(0xFF & (99*batteryLevel/254)); //#05 - } else if (sensor_data_ready != 0L) - { - sensor_data_ready =0; - i = PrepareSendTxData(); + } else if ((upload_message_timer != 0U)||(sensor_data_ready!= 0U)) //sensor_data_ready for manual push button-1 trigger) + { + sensor_data_ready =0; + upload_message_timer =0; + //AppData.Buffer[i++] = AppLedStateOn; + i = PrepareSendTxData(); } if (i!=0) { - AppData.BufferSize = (sts_service_mask >= STS_SERVICE_MASK_L2? 0:i); + AppData.BufferSize = (sts_service_mask > STS_SERVICE_MASK_L1? 0:i); if ((JoinLedTimer.IsRunning) && (LmHandlerJoinStatus() == LORAMAC_HANDLER_SET)) { @@ -1333,18 +1339,22 @@ static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context) } /** - * @brief Yunhorn STS Heart beat timer callback function - * @param context ptr of context + * @brief Yunhorn STS Sensor Heart Beat Timer callback function + * @param context ptr of STS Sampling Check context */ - static void OnYunhornSTSHeartBeatTimerEvent(void *context) { heart_beat_timer = 1; + UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); + UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); - if (STS_LoRa_WAN_Joined != 0) + if ((STS_LoRa_WAN_Joined ) && (sts_ac_code[0]==0x0) && (sts_ac_code[19]==0x0)) { - UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); - + /* RFAC Challenge */ + if (rfac_timer < (STS_BURN_IN_RFAC+3)) { + rfac_timer ++; + } + UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventRFAC), CFG_SEQ_Prio_0); } } @@ -1441,83 +1451,83 @@ static void OnYunhornSTSSamplingCheckTimerEvent(void *context) } */ + +/* + * YUNHORN STS PRODUCT BOARD LEVEL CONTROL OR REPORT + * --Y + * --Z BOARD LEVEL + * --H 'YZH' Hardware REBOOT [YZH] WVpI + * --C 'YZC' LoRa-WAN CLASS A/B/C [YZC] WVpD + * --S 'YZS' SELF-TEST FUNCTION TEST [YZS] WVpT + * --D 'YZD' DISTANCE MEASURE [YZD] WVpE + * + * + * --V VERSION + * --H 'YVH' HARDWARE/FIRMWARE VERSION [YVH] WVZI + * --C 'YVC' NVM CONFIG VERSION [YVC] WVZD + * + * --O POWER-ON + * --# 'YO1', 'YO2','YO3' [YO0] WU8w, [YO1] WU8x, [YO2] WU8y + * + * --F POWER-OFF + * --# 'YF1', 'YF2','YF3' [YF0] WUYw, [YF1] WUYx, [YF2] WUYy + * + * --H MEMS RESET + * --# 'YH0','YH1','YH2' [YH0] WUgw, [YH1] WUgx, [YH2] WUgy + * + * --M SERVICE LEVEL MASK + * --# 'YM0', 'YM1','YM2', 'YM3' [YM0] WU0w [YM1]WU0x [YM2]WU0y [YM3]WU0z + * + * --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 periodicity for real-time sensing + * --# + * --# + * --U UNIT (S, M, H) SECONDS, MINUTES, HOURS + + * + * --P ***** WORKMODE AND NETWORK COLOR + * --# MTM-VER 1 + * --# STS-VER 1 + * --M WORK MODE + * + * --N NETWORK WORK MODE {0,1,2,3,4,5,6} + * --C NETWORK COLOR, {0,1,2,3,4,5,6,7,8,9} + * + * --P ***** SIMPLE CONFIG PARAMETER FOR RSS (8 DIGITS) + * --# MTM-VER 1 + * --# STS-VER 1 + * + * --## START #.# meter + * --## LENGTH #.# meter + * --## THRESHOLD #.#*1000 + * --## GAIN 0.## + * + * --P ***** DISTANCE MEASURE CONFIG PARAMETER FOR RSS (7 DIGITS) + * --# MTM-VER 1 + * --# STS-VER 1 + * --## START #.# meter + * --## LENGTH #.# meter + * --# PROFILE # + * --## HWAAS ## + * + ** --P ***** FULL CONFIG PARAMETER FOR RSS (30 DIGITS) + * --# MTM-VER 1 + * --# STS-VER 1 + * --30{#} FULL CONFIG PARAMETER + * --A ***** AC CODE (22 BYTES) + * --C + * --# + * --20{#} AC CODE 20 BYTES + * + */ + void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) { uint8_t i=0, mems_ver, invalid_flag=1; - - /* - * YUNHORN STS PRODUCT BOARD LEVEL CONTROL OR REPORT - * --Y - * --Z BOARD LEVEL - * --H 'YZH' Hardware REBOOT [YZH] WVpI - * --C 'YZC' LoRa-WAN CLASS A/B/C [YZC] WVpD - * --S 'YZS' SELF-TEST FUNCTION TEST [YZS] WVpT - * --D 'YZD' DISTANCE MEASURE [YZD] WVpE - * - * - * --V VERSION - * --H 'YVH' HARDWARE/FIRMWARE VERSION [YVH] WVZI - * --C 'YVC' NVM CONFIG VERSION [YVC] WVZD - * - * --O POWER-ON - * --# 'YO1', 'YO2','YO3' [YO0] WU8w, [YO1] WU8x, [YO2] WU8y - * - * --F POWER-OFF - * --# 'YF1', 'YF2','YF3' [YF0] WUYw, [YF1] WUYx, [YF2] WUYy - * - * --H MEMS RESET - * --# 'YH0','YH1','YH2' [YH0] WUgw, [YH1] WUgx, [YH2] WUgy - * - * --M SERVICE LEVEL MASK - * --# 'YM0', 'YM1','YM2', 'YM3' [YM0] WU0w [YM1]WU0x [YM2]WU0y [YM3]WU0z - * - * --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 periodicity for real-time sensing - * --# - * --# - * --U UNIT (S, M, H) SECONDS, MINUTES, HOURS - - * - * --P ***** WORKMODE AND NETWORK COLOR - * --# MTM-VER 1 - * --# STS-VER 1 - * --M WORK MODE - * - * --N NETWORK WORK MODE {0,1,2,3,4,5,6} - * --C NETWORK COLOR, {0,1,2,3,4,5,6,7,8,9} - * - * --P ***** SIMPLE CONFIG PARAMETER FOR RSS (8 DIGITS) - * --# MTM-VER 1 - * --# STS-VER 1 - * - * --## START #.# meter - * --## LENGTH #.# meter - * --## THRESHOLD #.#*1000 - * --## GAIN 0.## - * - * --P ***** DISTANCE MEASURE CONFIG PARAMETER FOR RSS (7 DIGITS) - * --# MTM-VER 1 - * --# STS-VER 1 - * --## START #.# meter - * --## LENGTH #.# meter - * --# PROFILE # - * --## HWAAS ## - * - ** --P ***** FULL CONFIG PARAMETER FOR RSS (30 DIGITS) - * --# MTM-VER 1 - * --# STS-VER 1 - * --30{#} FULL CONFIG PARAMETER - * --A ***** AC CODE (22 BYTES) - * --C - * --# - * --20{#} AC CODE 20 BYTES - * - */ - if (((char)tlv_buf[CFG_CMD1] == 'Y') && (tlv_buf_size <=5)) // BEGIN OF *** BOARD LEVEL CONTROL OR REPORT { switch ((char)tlv_buf[CFG_CMD2]) @@ -1541,7 +1551,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) //STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf); i=0; - memset(outbuf,sizeof(outbuf),0x30); + memset(outbuf,0x0, sizeof(outbuf)); STS_SENSOR_Function_Test_Process(); @@ -1572,18 +1582,36 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) APP_LOG(TS_OFF, VLEVEL_H, "\r\nRSS Measured Distance=[%u] mm \r\n", (int)sts_distance_rss_distance); i=0; - memset(outbuf,sizeof(outbuf),0x30); + memset(outbuf,0x0, sizeof(outbuf)); outbuf[i++] = (uint8_t)'D'; 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)); +#if defined(STS_O7)||defined(STS_O6) 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 +#if (defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED)||defined(YUNHORN_STS_R1_ENABLED)) +#ifdef TOF_1 + outbuf[i++] = (uint8_t) (((uint16_t)sts_tof_distance_data[0])/100)&0xff; + outbuf[i++] = (uint8_t) (((uint16_t)sts_tof_distance_data[0])%100)&0xff; +#endif +#ifdef TOF_2 + outbuf[i++] = (uint8_t) (((uint16_t)sts_tof_distance_data[1])/100)&0xff; + outbuf[i++] = (uint8_t) (((uint16_t)sts_tof_distance_data[1])%100)&0xff; +#endif + +#ifdef TOF_3 + outbuf[i++] = (uint8_t) (((uint16_t)sts_tof_distance_data[2])/100)&0xff; + outbuf[i++] = (uint8_t) (((uint16_t)sts_tof_distance_data[2])%100)&0xff; +#endif +#endif + STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf); } @@ -1628,19 +1656,17 @@ 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); + memset(outbuf,0x0, sizeof(outbuf)); 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_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_PERIODICITY]); //UPLINK Periodicity outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_UNIT]; //UPLINK Periodicity unit - 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_SAMPLING]); //Heart-beat or SAMPLING Periodicity + outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_S_UNIT]; //Heart-beat or 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_RESERVE01]; //service mask @@ -1742,16 +1768,22 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) && ((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 sampling_periodicity_length = (tlv_buf[CFG_CMD3]-0x30)*10+ (tlv_buf[CFG_CMD4]-0x30); + uint32_t heart_beat_or_sampling_periodicity_length = (tlv_buf[CFG_CMD3]-0x30)*10+ (tlv_buf[CFG_CMD4]-0x30); - if ((char)tlv_buf[CFG_CMD5] == 'M') { - sampling_periodicity_length *= 60; - } else if ((char)tlv_buf[CFG_CMD5] == 'H') { - sampling_periodicity_length *= 3600; - } - SamplingPeriodicity = sampling_periodicity_length*1000; //translate to 1000ms=1s - OnYunhornSTSSamplingPeriodicityChanged(SamplingPeriodicity); + if ((char)tlv_buf[CFG_CMD5] == 'M') { + heart_beat_or_sampling_periodicity_length *= 60; + } else if ((char)tlv_buf[CFG_CMD5] == 'H') { + heart_beat_or_sampling_periodicity_length *= 3600; + } +#ifdef YUNHORN_STS_E0_ENABLED + SamplingPeriodicity = heart_beat_or_sampling_periodicity_length*1000; //translate to 1000ms=1s + OnYunhornSTSSamplingPeriodicityChanged(SamplingPeriodicity); +#endif +//#if defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED) + HeartBeatPeriodicity = heart_beat_or_sampling_periodicity_length*1000; //translate to 1000ms=1s + OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity); +//#endif i = 0; outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD1]; outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD2]; @@ -1771,7 +1803,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) sts_cfg_nvm.sts_service_mask = (uint8_t)sts_service_mask; OnStoreSTSCFGContextRequest(); - APP_LOG(TS_OFF, VLEVEL_M, "###### YUNHORN Sampling Interval Changed to [ %d ] Seconds\r\n", sampling_periodicity_length); + APP_LOG(TS_OFF, VLEVEL_M, "###### YUNHORN HeartBeat or Sampling Interval Changed to [ %d ] Seconds\r\n", (heart_beat_or_sampling_periodicity_length/1000)); } else { STS_SENSOR_Upload_Config_Invalid_Message(); @@ -2117,9 +2149,9 @@ void STS_SENSOR_Upload_Message(uint8_t appDataPort, uint8_t appBufferSize, char void OnStoreSTSCFGContextRequest(void) { /* USER CODE BEGIN OnStoreContextRequest_1 */ - uint8_t i=0, j=0, nvm_store_value[YUNHORN_STS_MAX_NVM_CFG_SIZE]=""; + uint8_t i=0,j=0,nvm_store_value[YUNHORN_STS_MAX_NVM_CFG_SIZE]={0x0}; -#ifdef YUNHORN_STS_O7_ENABLED +#if (defined(STS_O7)||defined(STS_O5) || defined(STS_O6) || defined(STS_R0) || defined(STS_R5)|| defined(STS_R4)|| defined(STS_R1D)) sts_cfg_nvm.length = STS_O7_NVM_CFG_SIZE; nvm_store_value[i++] = sts_cfg_nvm.mtmcode1; nvm_store_value[i++] = sts_cfg_nvm.mtmcode2; @@ -2143,8 +2175,10 @@ void OnStoreSTSCFGContextRequest(void) nvm_store_value[i++] = sts_cfg_nvm.fall_unconcious_threshold; 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]); + if ((sts_cfg_nvm.ac[0]!=0x0) && (sts_cfg_nvm.ac[19]!=0x0)) { + for (j = 0; j < YUNHORN_STS_AC_CODE_SIZE; j++) { + nvm_store_value[i++] = (sts_cfg_nvm.ac[j]); + } } #endif @@ -2190,12 +2224,12 @@ void STS_REBOOT_CONFIG_Init(void) UTIL_MEM_cpy_8(nvm_stored_value, (void *)STS_CONFIG_NVM_BASE_ADDRESS, YUNHORN_STS_MAX_NVM_CFG_SIZE); /* USER CODE BEGIN OnRestoreContextRequest_Last */ -#ifdef YUNHORN_STS_O7_ENABLED +#if (defined(STS_O7)||defined(STS_O5) || defined(STS_O6) || defined(STS_R0) || defined(STS_R5)|| defined(STS_R4)|| defined(STS_R1D)) 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_M, "Initial Boot with Empty Config, Flash with default config....\r\n"); OnStoreSTSCFGContextRequest(); - UTIL_MEM_set_8((void *)sts_ac_code, 0x00, YUNHORN_STS_AC_CODE_SIZE); + //UTIL_MEM_set_8((void *)sts_ac_code, 0x00, YUNHORN_STS_AC_CODE_SIZE); HAL_Delay(1000); } else { @@ -2246,20 +2280,28 @@ void OnRestoreSTSCFGContextProcess(void) } periodicity = (periodicity > 10)? periodicity : 10; // in seconds unit TxPeriodicity= periodicity*1000; // to ms - OnTxPeriodicityChanged(TxPeriodicity); // in msec unit + //OnTxPeriodicityChanged(TxPeriodicity); // in msec unit + if ((sts_cfg_nvm.ac[0] ==0x0 )&& (sts_cfg_nvm.ac[19]==0x0)) + { // ensure it's not in production yet + OnTxPeriodicityChanged(APP_TX_DUTYCYCLE); // in msec unit + OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity); + } else + { + OnTxPeriodicityChanged(TxPeriodicity); // in msec unit + //Heart-beat or Sampling interval +#ifdef STS_E0 + samplingperiodicity = (samplingperiodicity > 0)? samplingperiodicity : 1; // in seconds unit + HeartBeatPeriodicity = samplingperiodicity*1000; +#endif +#if defined(STS_O7)|| defined(STS_O6) ||defined(STS_O5) + OnYunhornSTSSamplingPeriodicityChanged(HeartBeatPeriodicity); // in m-sec unit +#endif - 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') { - samplingperiodicity *= 3600; - } else if ((char) sts_cfg_nvm.s_unit =='S') { - samplingperiodicity *= 1; +#if defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED)||defined(YUNHORN_STS_R4_ENABLED) + OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity); +#endif } - samplingperiodicity = (samplingperiodicity > 0)? samplingperiodicity : 1; // in seconds unit - OnYunhornSTSSamplingPeriodicityChanged(samplingperiodicity*1000); // in m-sec unit - sts_work_mode = sts_cfg_nvm.work_mode; sts_lamp_bar_color = STS_GREEN; sts_service_mask = sts_cfg_nvm.sts_service_mask; @@ -2288,20 +2330,25 @@ void OnRestoreSTSCFGContextProcess(void) void STS_SENSOR_Distance_Test_Process(void) { +#if defined(STS_O6)||defined(STS_O7) sts_distance_rss_distance =0; do { STS_PRESENCE_SENSOR_Distance_Measure_Process(); HAL_Delay(200); } while(sts_distance_rss_distance == 0); - APP_LOG(TS_OFF, VLEVEL_H, "\r\nSensor Function Test: Distance Measured =%u mm\r\n", (int)sts_distance_rss_distance); + APP_LOG(TS_OFF, VLEVEL_L, "\r\nSensor Function Test: Distance Measured =%u mm\r\n", (int)sts_distance_rss_distance); +#endif +#if defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED) + MX_TOF_Process(); +#endif } void STS_SENSOR_Function_Test_Process(void) { char tstbuf[128] =""; uint8_t i=0, count = 1; - uint8_t mems_Dev_ID[2] = ""; + uint8_t mems_Dev_ID[2] = {0x0}; tstbuf[i++] = (uint8_t) 'S'; tstbuf[i++] = (uint8_t) sts_mtmcode1; @@ -2319,8 +2366,8 @@ void STS_SENSOR_Function_Test_Process(void) else { tstbuf[i++] = (uint8_t)14; //length of following data -#ifdef YUNHORN_STS_O7_ENABLED - uint8_t self_test_result[10]={0,0,0,0,0, 0,0,0,0,0}; +#if defined(STS_O7)||defined(STS_O6) + uint8_t self_test_result[10]={0x0}; STS_PRESENCE_SENSOR_Function_Test_Process(self_test_result, count); @@ -2333,93 +2380,32 @@ void STS_SENSOR_Function_Test_Process(void) 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 +#if (defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED)||defined(YUNHORN_STS_R1_ENABLED)) + tstbuf[i++] = (uint8_t) (count)&0xff; + //MX_TOF_Process(); + STS_TOF_VL53L0X_Range_Process(); + +#ifdef TOF_1 + tstbuf[i++] = (uint8_t) ((sts_tof_distance_data[0] >>8 ) &0xff); + tstbuf[i++] = (uint8_t) (sts_tof_distance_data[0] &0xff); +#endif +#ifdef TOF_2 + tstbuf[i++] = (uint8_t) ((sts_tof_distance_data[1] >>8 ) &0xff); + tstbuf[i++] = (uint8_t) (sts_tof_distance_data[1] &0xff); +#endif +#ifdef TOF_3 + tstbuf[i++] = (uint8_t) ((sts_tof_distance_data[2] >>8 ) &0xff); + tstbuf[i++] = (uint8_t) (sts_tof_distance_data[2] &0xff); +#endif + #endif } - memset((void*)outbuf,sizeof(outbuf),0x30); + memset((void*)outbuf,0x0, sizeof(outbuf)); 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); } -/* - - if (sts_work_mode == STS_WIRED_MODE) - { - AppData.Buffer[i++] = sts_mtmcode1; - AppData.Buffer[i++] = sts_mtmcode2; - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.state_sensor1_on_off); //01 Sensor head #1 status - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.battery_Pct); //02 Battery Level % - AppData.Buffer[i++] = (uint8_t)(0xFF & batteryLevelmV >>8); //03 Battery mV MSB - AppData.Buffer[i++] = (uint8_t)(0xFF & batteryLevelmV ); //04 Battery mV LSB - APP_LOG(TS_OFF, VLEVEL_L,"\r\n######| Mode S1 BAT % BAT mV |" - "\r\n######| %1d %1d %2d% %4d mV|\r\n", - sts_work_mode, AppData.Buffer[2], AppData.Buffer[3], batteryLevelmV); - - } else - { - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.lamp_bar_color); //01 - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.workmode); //02 WORK MODE - - if (sts_work_mode == STS_NETWORK_MODE) - { - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.state_sensor1_on_off); //03 Sensor head #1 status - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.state_sensor2_on_off); //04 Sensor head #2 status - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.state_sensor3_on_off); //05 Sensor head #3 status - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.state_sensor4_on_off); //06 Sensor head #4 status - APP_LOG(TS_OFF, VLEVEL_L, - "\r\n######| Color Mode S1 S2 S3 S4 |" - "\r\n######| %1d %1d %1d %1d %1d %1d |\r\n", - AppData.Buffer[0], AppData.Buffer[1], AppData.Buffer[2],AppData.Buffer[3], AppData.Buffer[4],AppData.Buffer[5]); - } else if (sts_work_mode == STS_REEDSWITCH_MODE) - { - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.state_sensor1_on_off); //03 Sensor head #1 status - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.battery_Pct); //02 Battery Level % - AppData.Buffer[i++] = (uint8_t)(0xFF & batteryLevelmV >>8); //03 Battery mV MSB - AppData.Buffer[i++] = (uint8_t)(0xFF & batteryLevelmV ); //04 Battery mV LSB - APP_LOG(TS_OFF, VLEVEL_L, - "\r\n######| Color Mode S1 VBAT in mV|" - "\r\n######| %1d %1d %1d %2d% %4d mV|\r\n", - AppData.Buffer[0], AppData.Buffer[1], AppData.Buffer[2],AppData.Buffer[3], batteryLevelmV); - - } else if (sts_work_mode == STS_RSS_MODE) { - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.state_sensor2_on_off); //03 Sensor head #2 status - //AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.state_sensor3_on_off); // Sensor head #3 status - //AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.state_sensor4_on_off); // Sensor head #4 status - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.rss_presence_distance>>8); //04 MSB distance - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.rss_presence_distance); //05 LSB distance - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.rss_presence_score >>8); //06 MSB score - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.rss_presence_score); //07 LSB score - AppData.Buffer[i++] = (uint8_t)(0xFF & sts_occupancy_overtime_state); //11 occupancy over time or not - APP_LOG(TS_OFF, VLEVEL_L, - "\r\n######| Color Mode S2 |Distance(mm) MotionScore|" - "\r\n######| %1d %1d %1d |%04d %04d |\r\n", - AppData.Buffer[0], AppData.Buffer[1], AppData.Buffer[2], (uint16_t)o7_data.rss_presence_distance,(uint16_t)o7_data.rss_presence_score); - } else { - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.state_sensor1_on_off); //03 Sensor head #1 status - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.state_sensor2_on_off); //04 Sensor head #2 status - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.state_sensor3_on_off); //05 Sensor head #3 status - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.state_sensor4_on_off); //06 Sensor head #4 status - if (o7_data.state_sensor2_on_off !=0) - { - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.rss_presence_distance>>8); //07 MSB distance - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.rss_presence_distance); //08 LSB distance - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.rss_presence_score >>8); //09 MSB score - AppData.Buffer[i++] = (uint8_t)(0xFF & o7_data.rss_presence_score); //10 LSB score - } - // overtime dismissed while state not back to zero - if ((o7_data.state_sensor1_on_off == 0)&& (o7_data.state_sensor2_on_off == 0)) - sts_occupancy_overtime_state = 0; - AppData.Buffer[i++] = (uint8_t)(0xFF & sts_occupancy_overtime_state); //11 occupancy over time or not - APP_LOG(TS_OFF, VLEVEL_L, - "\r\n######| Color Mode S1 S2 S3 S4 |Distance(mm) MotionScore|" - "\r\n######| %1d %1d %1d %1d %1d %1d |%04d %04d |\r\n", - AppData.Buffer[0], AppData.Buffer[1],AppData.Buffer[2], AppData.Buffer[3],AppData.Buffer[4], AppData.Buffer[5], (uint16_t)o7_data.rss_presence_distance,(uint16_t)o7_data.rss_presence_score); - } - - } - - - - */ diff --git a/STM32CubeIDE/Release/STS_O7.bin b/STM32CubeIDE/Release/STS_O7.bin index 0a5b710..2c32cc5 100644 Binary files a/STM32CubeIDE/Release/STS_O7.bin and b/STM32CubeIDE/Release/STS_O7.bin differ