From 2671b759f8aba465fdd82fc01e3177a44af82536 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Tue, 24 Sep 2024 14:42:11 +0800 Subject: [PATCH] --revised for accurate format --- LoRaWAN/App/lora_app.c | 51 +++++++++++++++++++++-------- STS/TOF/App/app_tof_vl53l0x_range.c | 10 ++++-- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index f0ac053..22c19fa 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -735,10 +735,20 @@ static void SendTxData(void) STS_RR_Sensor_Read(&sts_rr_sensor_data); AppData.Port = YUNHORN_STS_R1_LORA_APP_DATA_PORT; /* STS-R1 Data Port */ #endif + + AppData.Buffer[i++] = AppLedStateOn; + AppData.Buffer[i++] = (uint8_t) sts_mtmcode1; + AppData.Buffer[i++] = (uint8_t) sts_mtmcode2; + AppData.Buffer[i++] = (uint8_t) sts_hardware_ver; + AppData.Buffer[i++] = (uint8_t) 99*batteryLevel/254; + +#if 0 APP_LOG(TS_ON, VLEVEL_M, "VDDA: %d\r\n", batteryLevel); APP_LOG(TS_ON, VLEVEL_M, "temp: %d\r\n", (int16_t)(sensor_data.temperature)); - //AppData.Port = LORAWAN_USER_APP_PORT; + AppData.Port = LORAWAN_USER_APP_PORT; +#endif + #ifdef STS_P2 AppData.Port = 106; /* STS-P2 Data Port */ #endif @@ -758,6 +768,8 @@ static void SendTxData(void) CayenneLppCopy(AppData.Buffer); AppData.BufferSize = CayenneLppGetSize(); #else /* not CAYENNE_LPP */ + +#if 0 humidity = (uint16_t)(sensor_data.humidity * 10); /* in %*10 */ temperature = (int16_t)(sensor_data.temperature); pressure = (uint16_t)(sensor_data.pressure * 100 / 10); /* in hPa / 10 */ @@ -792,30 +804,41 @@ static void SendTxData(void) AppData.Buffer[i++] = (uint8_t)((altitudeGps >> 8) & 0xFF); AppData.Buffer[i++] = (uint8_t)(altitudeGps & 0xFF); } -#ifdef VL53L0 -#if defined(STS_R1)||defined(STS_R1D)||defined(STS_R5) +#endif + +#ifdef VL53L0 //VL53L0 +#if defined(STS_R1)||defined(STS_R5) + AppData.Buffer[i++] = 2; AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_1_distance_mm >>8 & 0xFF); AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_1_distance_mm & 0xFF); +#endif - +#ifdef STS_R1D + AppData.Buffer[i++] = 4; + AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_1_distance_mm >>8 & 0xFF); + AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_1_distance_mm & 0xFF); AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_2_distance_mm >>8 & 0xFF); AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_2_distance_mm & 0xFF); +#endif +#ifdef STS_R5_EXT AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_3_distance_mm >>8 & 0xFF); AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_3_distance_mm & 0xFF); - - #endif + #if defined(STS_R1D) AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_2_distance_mm >>8 & 0xFF); AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_2_distance_mm & 0xFF); #endif + #if defined(STS_R5_EXT) AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_3_distance_mm >>8 & 0xFF); AppData.Buffer[i++] = (uint8_t)(sts_rr_sensor_data.tof_3_distance_mm & 0xFF); #endif -#endif -#ifdef VL53LX + +#endif //VL53L0 + +#ifdef VL53LX // VL53L1X AppData.Buffer[i++] = (uint8_t)((sts_p2_sensor_data.Walk_In_People_Count>>8) & 0xFF); AppData.Buffer[i++] = (uint8_t)(sts_p2_sensor_data.Walk_In_People_Count & 0xFF); @@ -824,8 +847,8 @@ static void SendTxData(void) AppData.Buffer[i++] = (uint8_t)((sts_p2_sensor_data.Walk_Around_People_Count>>8) & 0xFF); AppData.Buffer[i++] = (uint8_t)(sts_p2_sensor_data.Walk_Around_People_Count & 0xFF); -#endif -#ifdef VL53LX +#endif // VL53L1X +#ifdef VL53LX // VL53L1X AppData.Buffer[i++] = (uint8_t)((sts_p2_sensor_data.Count_Period) & 0xFF); AppData.Buffer[i++] = (uint8_t)((sts_p2_sensor_data.Count_Period_Unit) & 0xFF); @@ -839,8 +862,10 @@ static void SendTxData(void) AppData.Buffer[i++] = (uint8_t)(sts_p2_sensor_data.Sum_Day_Walk_Around_People_Count & 0xFF); AppData.Buffer[i++] = (uint8_t)(sts_p2_sensor_data.Count_Valid & 0xFF); -#endif +#endif // VL53L1X + AppData.BufferSize = i; + #endif /* CAYENNE_LPP */ if ((JoinLedTimer.IsRunning) && (LmHandlerJoinStatus() == LORAMAC_HANDLER_SET)) @@ -1267,8 +1292,8 @@ static void OnYunhornSTSHeartBeatTimerEvent(void *context) appHeartBeatDataPort = YUNHORN_STS_R1_LORA_APP_HTBT_PORT; #endif appHeartBeatBufferSize = 2; - appHeartBeatDataBuffer[0]=0x80; - appHeartBeatDataBuffer[1]=0x63; //TODO XXX change to battery level % + appHeartBeatDataBuffer[0]=(uint8_t)(0x80|AppLedStateOn); + appHeartBeatDataBuffer[1]=(uint8_t)(SYS_GetBatteryLevel()/100); //TODO XXX change to battery level in mV STS_SENSOR_Upload_Message(appHeartBeatDataPort, appHeartBeatBufferSize, (uint8_t*)appHeartBeatDataBuffer); #endif diff --git a/STS/TOF/App/app_tof_vl53l0x_range.c b/STS/TOF/App/app_tof_vl53l0x_range.c index e9cb339..ca6b197 100644 --- a/STS/TOF/App/app_tof_vl53l0x_range.c +++ b/STS/TOF/App/app_tof_vl53l0x_range.c @@ -370,7 +370,8 @@ void STS_TOF_VL53L0X_Range_Process(void) sts_tof_vl53l0x_SetupSingleShot(RangingConfig); sensor_data_ready = 0 ; - for (i=0; i< MAX_TOF_COUNT; i++) + //for (i=0; i< MAX_TOF_COUNT; i++) + for (i=0; i< nSensorPresent; i++) { APP_LOG(TS_OFF, VLEVEL_M, "\n\n i=%u Present=%u DevAdd=%02x \n", i, VL53L0XDevs[i].Present, VL53L0XDevs[i].I2cDevAddr); if (VL53L0XDevs[i].Present ==1) @@ -386,7 +387,7 @@ void STS_TOF_VL53L0X_Range_Process(void) { sts_tof_distance_data[i] = (int)VL53L0XDevs[i].LeakyRange; nDevMask |= (1 << i); - sensor_data_ready |= 1; + sensor_data_ready |= 1<tof_3_distance_mm = sts_tof_distance_data[2]; } +void STS_Prepare_Packet_Data(void) +{ + //AppData.Buffer = 0x0; + //AppData.BufferSize = 0x0; +} /* USER CODE BEGIN 4 */