|
|
@@ -327,7 +327,6 @@ int main(void)
|
|
|
/* Infinite loop */
|
|
|
/* USER CODE BEGIN WHILE */
|
|
|
|
|
|
- printf("Device is ready\r\n");
|
|
|
printf("设备地址:0x%02X%02X\n", deviceInfo.loraDeviceAddress_H, deviceInfo.loraDeviceAddress_L);
|
|
|
uint8_t i = 0;
|
|
|
while (1)
|
|
|
@@ -338,7 +337,7 @@ int main(void)
|
|
|
|
|
|
// 检查是否接收到"心跳"命令,且设备在线
|
|
|
printf("设备状态:0x%02X\n", deviceInfo.commandFromCloud);
|
|
|
-
|
|
|
+ printf("Device is ready: %d\r\n", deviceInfo.isOnline);
|
|
|
// schedule_Fun();
|
|
|
// 心跳:不在线时,每 10 秒发一次
|
|
|
if (!deviceInfo.isOnline) {
|
|
|
@@ -351,7 +350,7 @@ int main(void)
|
|
|
if (GET_CMD(deviceInfo.commandFromCloud) == IDLE || GET_STEP(deviceInfo.commandFromCloud) == STEP_INIT) {
|
|
|
HAL_RTC_GetTime(&hrtc, &IDLE_struct, RTC_FORMAT_BIN); // 直接更新
|
|
|
} else {
|
|
|
- if (IsTimeElapsed(&hrtc, &IDLE_struct, 20)) {
|
|
|
+ if (IsTimeElapsed(&hrtc, &IDLE_struct, 20*60)) {
|
|
|
deviceInfo.commandFromCloud = COMBINE_CMD_STEP(IDLE, STEP_INIT);
|
|
|
}
|
|
|
}
|
|
|
@@ -373,17 +372,21 @@ int main(void)
|
|
|
|
|
|
case REQUEST_BLUETOOTH_DATA_SEND:
|
|
|
uint8_t sentData_Temp[25] = {0};
|
|
|
- if (RingBuffer_Dequeue(&deviceInfo.queueBLData, sentData_Temp) == 0) {
|
|
|
- //不为空的情况下
|
|
|
- E52_Send_Bl_Data_Fun(sentData_Temp,0x00);
|
|
|
- } else {
|
|
|
- //为空的情况下
|
|
|
- // printf("发送最后一位,开始发送蓝牙数据给Lora\r\n");
|
|
|
- HAL_Delay(1000);
|
|
|
- E52_Send_Bl_Data_Fun(sentData_Temp,0x01);
|
|
|
- deviceInfo.BlDataFlag = BL_START;
|
|
|
- deviceInfo.commandFromCloud = COMBINE_CMD_STEP(REQUEST_BLUETOOTH_DATA, STEP_COMPLETE);
|
|
|
- printf("发送完成\r\n");
|
|
|
+ if (deviceInfo.loraSendSuccessFlag == 0) { // 5 5
|
|
|
+ if (RingBuffer_Dequeue(&deviceInfo.queueBLData, sentData_Temp) == 0 && deviceInfo.forwardBLAndLoraDataCount < deviceInfo.forwardBLAndLoraDataCountMax) {
|
|
|
+ //不为空的情况下
|
|
|
+ E52_Send_Bl_Data_Fun(sentData_Temp,0x00);
|
|
|
+ deviceInfo.forwardBLAndLoraDataCount++;
|
|
|
+ } else {
|
|
|
+ //为空的情况下
|
|
|
+ // printf("发送最后一位,开始发送蓝牙数据给Lora\r\n");
|
|
|
+ uint8_t endFrame[25] = {0};
|
|
|
+ E52_Send_Bl_Data_Fun(endFrame,0x01);
|
|
|
+ deviceInfo.BlDataFlag = BL_START;
|
|
|
+ deviceInfo.commandFromCloud = COMBINE_CMD_STEP(REQUEST_BLUETOOTH_DATA, STEP_COMPLETE);
|
|
|
+ printf("发送完成\r\n");
|
|
|
+ }
|
|
|
+ HAL_Delay(deviceInfo.forwardBLAndLoraDataDuration);//后台配置间隔时间
|
|
|
}
|
|
|
break; //发送数据阶段
|
|
|
case STEP_COMPLETE:
|
|
|
@@ -395,7 +398,6 @@ int main(void)
|
|
|
default:
|
|
|
// 处理未知步骤
|
|
|
receiveBlDataCount = 0;
|
|
|
- deviceInfo.timeCount = 0;
|
|
|
deviceInfo.forwardBLAndLoraDataDuration = 0;
|
|
|
i = 0;
|
|
|
deviceInfo.commandFromCloud = COMBINE_CMD_STEP(IDLE, STEP_INIT);
|
|
|
@@ -409,10 +411,8 @@ int main(void)
|
|
|
case HEARTBEAT_SEND:
|
|
|
if (deviceInfo.loraSendSuccessFlag == 0) {
|
|
|
E52_Heartbeat_Fun();
|
|
|
- }else {
|
|
|
- continue;
|
|
|
+ deviceInfo.commandFromCloud = COMBINE_CMD_STEP(REQUEST_BLUETOOTH_DATA, STEP_COMPLETE);
|
|
|
}
|
|
|
- deviceInfo.commandFromCloud = COMBINE_CMD_STEP(REQUEST_BLUETOOTH_DATA, STEP_COMPLETE);
|
|
|
break;
|
|
|
case STEP_COMPLETE:
|
|
|
deviceInfo.commandFromCloud = COMBINE_CMD_STEP(IDLE, STEP_INIT);
|