Explorar el Código

添加间隔时间,和发送个数

xuxinyi hace 1 mes
padre
commit
34161aeb2c
Se han modificado 4 ficheros con 37 adiciones y 26 borrados
  1. 7 3
      Core/Inc/E52.h
  2. 10 3
      Core/Src/E52.c
  3. 18 18
      Core/Src/main.c
  4. 2 2
      README.md

+ 7 - 3
Core/Inc/E52.h

@@ -119,9 +119,13 @@ typedef struct {
     uint8_t loraSendSuccessFlag;
 
     //定时器相关
-    uint8_t  timerEnable;           //定时器使能
-    uint16_t timeCount;             //定时器计数
-    uint16_t forwardBLAndLoraDataDuration;   //转发蓝牙数据持续时间高位ms
+    // uint8_t  timerEnable;           //定时器使能
+    // uint16_t timeCount;             //定时器计数
+
+    uint16_t forwardBLAndLoraDataDuration;   //发送蓝牙间隔时间
+    uint8_t forwardBLAndLoraDataCount;   //发送蓝牙数量
+    uint8_t forwardBLAndLoraDataCountMax;  //发送蓝牙数量最大值
+
     RingBuffer queueBLData;                 //蓝牙数据队列
     RingBuffer queueLoraCommandData;        //命令数据队列
     // RingBuffer queueSenderData;

+ 10 - 3
Core/Src/E52.c

@@ -123,9 +123,16 @@ void E52_Send_SOS_Fun( uint8_t *sendData,uint8_t finishData) {
  */
 void E52_Request_Command_Fun() {
     printf("这是请求蓝牙数据的命令\r\n");
+    deviceInfo.forwardBLAndLoraDataCount = 1;
+    if (rx_buf_uart2[5] == 0x00) {
+        //发送一条
+        deviceInfo.forwardBLAndLoraDataCountMax = 1;
+    }else {
+        deviceInfo.forwardBLAndLoraDataCountMax = rx_buf_uart2[5];
+    }
 
     // 修复运算符优先级警告,添加括号明确先执行位运算再比较
-    if ((((uint16_t)rx_buf_uart2[5] << 8) | rx_buf_uart2[6]) != 0) {
+    if ((((uint16_t)rx_buf_uart2[6] << 8) | rx_buf_uart2[7]) != 0) {
         // 组合两个字节为16位的持续时间值
         deviceInfo.forwardBLAndLoraDataDuration = ((uint16_t)rx_buf_uart2[5] << 8) | rx_buf_uart2[6];
     } else {
@@ -204,11 +211,11 @@ void E52_Analyze_Data() {
             // E52_Send_Sleep_Fun();
             deviceInfo.commandFromCloud = COMBINE_CMD_STEP(IDLE, STEP_INIT);
             break;
-        case E52_HEARTBEAT:
+        case E52_HEARTBEAT:// 完成
             E52_Heartbeat_Fun1();
             deviceInfo.commandFromCloud = COMBINE_CMD_STEP(E52_HEARTBEAT, HEARTBEAT_SEND);
             break;
-        case IS_ONLINE:
+        case IS_ONLINE: //完成
             deviceInfo.isOnline = TRUE;
             deviceInfo.commandFromCloud = COMBINE_CMD_STEP(IDLE, STEP_INIT);
             break;

+ 18 - 18
Core/Src/main.c

@@ -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);

+ 2 - 2
README.md

@@ -50,8 +50,8 @@
         55 BB       : 帧头
         03          : 命令(请求蓝牙数据)
         FC A5       : 设备地址
-        0A          : 发送蓝牙条数
-        00 00       : 间隔发送时间
+        0A          : 发送蓝牙条数(10条)
+        07 D0       : 间隔发送时间(07 DO = 2000 ms)(默认500ms,)  注意:success检测时间,实际时间可能会大于500ms,由硬件性能决定。
         34 60       : 目标地址(暂未启用)
         FF EE       : 帧尾
     }