zhunk 1 年間 前
親
コミット
f2915bd935

+ 28 - 111
Application_cbd_apm32f1/applications/control.c

@@ -939,106 +939,30 @@ u_int8_t alarmCheck(u_int8_t starthour,u_int8_t endhour)
 {
     u_int8_t workflag = 0;
     if(starthour == endhour) return workflag;
-    //雨控检测,温控检测,电池电压检测
-//    while(1)
-//    {
-//        rt_thread_delay(1000);
-         if(starthour < endhour)
-         {
-                LOG_D("开始和结束是同一天");
-                time_t now;
-                time(&now);
-                static struct tm nowtime;   //现在
-                static struct tm starttime; //开始
-                static struct tm endtime;   //结束
-                //获取当前时间戳
-                nowtime =*localtime(&now);
-                nowtime.tm_hour = nowtime.tm_hour-8;
-                //获取定时开始的时间戳
-                starttime = *localtime(&now);
-                starttime.tm_hour = starthour-8;
-                starttime.tm_min = 0;
-                starttime.tm_sec = 0;
-                //获取定时结束的时间戳
-                endtime = *localtime(&now);
-                endtime.tm_hour = endhour - 8;
-                endtime.tm_min = 0;
-                endtime.tm_sec = 0;
-                LOG_D("***工作结束在当天:现在时间:%d-开始时间:%d-结束时间:%d***",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
-                //如果当前时间大于开始时间且小于结束时间,且没有开始工作
-                if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&endtime))<0))
-                {
-                    LOG_D("当前时间大于开始时间,小于结束时间,工作中!!!");
-                    workflag = ON;
-                }
-                //如果当前时间小于开始时间
-                else if(difftime(mktime(&nowtime),mktime(&starttime))<0)
-                {
-                    LOG_D("当前时间小于开始时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
-                    workflag = OFF;
-                }
-                //当前时间大于结束时间
-                else {
-                    LOG_D("当前时间大于结束时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
-                    workflag = OFF;
-                }
-         }
-            //如果结束时间是第二天
-            else if (starthour>endhour)
-            {
-                time_t now;
-                time(&now);
-                static struct tm nowtime;   //现在
-                static struct tm starttime; //开始
-                static struct tm endtime;   //结束
-                //获取当前时间戳
-                nowtime =*localtime(&now);
-                nowtime.tm_hour = nowtime.tm_hour-8;
-                //获取定时开始的时间戳
-                starttime = *localtime(&now);
-                starttime.tm_hour = starthour - 8;
-                starttime.tm_min = 0;
-                starttime.tm_sec = 0;
-                //获取定时结束的时间戳
-                endtime = *localtime(&now);
-                endtime.tm_hour = endhour-8;
-                endtime.tm_min = 0;
-                endtime.tm_sec = 0;
-             //   LOG_I("工作结束在第二天:现在时间:%d-开始时间:%d-结束时间:%d!!!",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
-                //如果当前时间大于开始时间,且没有开始工作 ,注意时间戳日期加1
-                if((difftime(mktime(&nowtime), mktime(&starttime)) > 0 ))
-                {
-                    //获取定时结束的时间戳
-                    endtime = *localtime(&now);  //将获取到的时间转换为时间戳
-                    endtime.tm_hour = endhour - 8;  //这里需减8用于时区转换
-                    endtime.tm_min = 0;
-                    endtime.tm_sec = 0;
-                    workflag = ON;
-               //     LOG_I("当前前时间大于开始时间,且没有开始工作");
-                }
-                //当前时间小于开始时间
-                else if ((difftime(mktime(&nowtime), mktime(&starttime)) < 0))
-                {
-                    //获取定时结束的时间戳
-                    endtime = *localtime(&now);  //将获取到的时间转换为时间戳
-                    endtime.tm_hour = endhour - 8;  //这里需减8用于时区转换
-                    endtime.tm_min = 0;
-                    endtime.tm_sec = 0;
-                    //如果当前时间戳小于结束时间戳
-                    if(difftime(mktime(&nowtime),mktime(&endtime)) < 0)
-                    {
-                //        LOG_I("当前时间大于开始时间,且没有开始工作,当前时间小于结束时间的情况:计算工作时间:从当前时间工作第二天的结束时间");
-                        workflag = ON;
-                    }
-                    else
-                    {
-                //        LOG_I("当前时间小于开始时间,且没有开始工作,不是重启引起的,即还没到开始时间");
-                        workflag = OFF; //不在工作时间,待机
-                    }
-                }
-            }
-         return workflag;
-        //}
+    time_t now;
+    time(&now);
+    struct tm now_tm = *localtime(&now);
+    rt_uint32_t curr_sec = now_tm.tm_hour*3600 + now_tm.tm_min*60 + now_tm.tm_sec;
+    rt_uint32_t start_sec = starthour * 3600;
+    rt_uint32_t end_sec = endhour * 3600;
+
+    // 修复跨天判断逻辑
+    if (start_sec < end_sec)
+    {
+        // 不跨天模式
+        workflag = (curr_sec >= start_sec && curr_sec < end_sec) ? 1 : 0;
+    }
+    else
+    {
+        // 跨天模式
+        workflag = (curr_sec >= start_sec || curr_sec < end_sec) ? 1 : 0;
+    }
+    LOG_I("时控模式:状态[%s] 当前时间:%02d:%02d:%02d 设置:%02d:00-%02d:00",
+          workflag ? "工作" : "待机",
+          now_tm.tm_hour, now_tm.tm_min, now_tm.tm_sec,
+          starthour, endhour);
+    rt_thread_delay(10000);
+    return workflag;
 }
 
 void WorkTask_BZYV2(void)
@@ -1048,7 +972,7 @@ void WorkTask_BZYV2(void)
         ctr_swz(OFF);
         ctr_Collect_Fan(OFF);
         while(device_status.work_status ==0){
-            rt_thread_delay(1000);
+            rt_thread_delay(10000);
             LOG_W("等待设备进入工作");
         }
         while(device_status.work_status ==1){
@@ -1087,12 +1011,8 @@ static void Work_status_thread_entry(void *parameter)
      {
          while(alarmCheck(device_status.collecting_sh1,device_status.collecting_eh1) == ON)
          {
-             if(device_status.collecting_sh2==device_status.collecting_eh2){
-                 device_status.work_done = 1;
-             }else{
-                 device_status.work_done = 0;
-             }
              device_status.work_status = 1;
+             device_status.work_done = 1;
              LOG_I("the alarm1 workflag was ON");
              rt_thread_delay(1000);
          }
@@ -1100,12 +1020,8 @@ static void Work_status_thread_entry(void *parameter)
 
          while(alarmCheck(device_status.collecting_sh2,device_status.collecting_eh2) == ON)
          {
-           if(device_status.collecting_sh3==device_status.collecting_eh3){
-               device_status.work_done = 1;
-           }else{
-               device_status.work_done = 0;
-           }
            device_status.work_status = 1;
+           device_status.work_done = 1;
            LOG_I("the alarm2 workflag was ON");
            rt_thread_delay(1000);
          }
@@ -1119,6 +1035,7 @@ static void Work_status_thread_entry(void *parameter)
          }
          //当前时间大于3段定时结束时间
          device_status.work_status = 0;
+         device_status.work_done = 0;
          rt_thread_delay(1000);
      }
 }

+ 65 - 347
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -66,7 +66,7 @@ static int DTU_uart2_init(void)
         dtuconfig.stop_bits = STOP_BITS_1;     //停止位1
         #ifdef RT_USING_SERIAL_V2
         dtuconfig.rx_bufsz = 1024;
-        dtuconfig.tx_bufsz = 1024;
+        dtuconfig.tx_bufsz = 2048;
         #else
         dtuconfig.bufsz = 1024;                 //缓冲区1k
         #endif
@@ -75,7 +75,7 @@ static int DTU_uart2_init(void)
         rt_device_control(dtuserial, RT_DEVICE_CTRL_CONFIG, &dtuconfig);
         /* step4:打开串口设备。以DMA接收及轮询发送模式打开串口设备 */
         #ifdef RT_USING_SERIAL_V2
-        rt_err_t uart_res = rt_device_open(dtuserial, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING); // 串口设备使用模式为 (发送阻塞 接收非阻塞) 模式
+        rt_err_t uart_res = rt_device_open(dtuserial, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_RX_NON_BLOCKING); // 串口设备使用模式为 (发送阻塞 接收非阻塞) 模式
         #else
         rt_err_t uart_res = rt_device_open(dtuserial, RT_DEVICE_FLAG_DMA_RX);  //RT_DEVICE_FLAG_DMA_RX
         #endif
@@ -90,26 +90,16 @@ static int DTU_uart2_init(void)
 /*数据发送*/
 void DTU_Write(char *fmt, ...)
 {
-    //static const char dtu_conf[4] = {device_status.vol,0x00,0x00,0x00};
     va_list ap;
-    static char dtu_str[1024];
+    static char dtu_str[2048];
     rt_size_t str_length;
     va_start(ap,fmt);
-    //str_length = rt_vsnprintf(dtu_str, sizeof(dtu_str) - 1, fmt, arg);
     str_length = rt_vsnprintf(dtu_str, sizeof(dtu_str) - 1, fmt, ap);
     va_end(ap);
-    if (str_length > 1024 - 1)
-        str_length = 1024 - 1;
+    if (str_length > 2048 - 1)
+        str_length = 2048 - 1;
     rt_device_write(dtuserial, 0, dtu_str, str_length);
-    rt_thread_mdelay(10);
-//    if(strstr(dtu_str,"volume")!=RT_NULL)
-//    {
-//        rt_device_write(dtuserial,0,dtu_conf,4);
-//    }
-//    else if (strstr(dtu_str,"reset")!=RT_NULL) {
-//        const char dtu_conf[4] = {7,0x00,0x00,0x00};
-//        rt_device_write(dtuserial,0,dtu_conf,4);
-//    }
+    LOG_D("DTU_Write:%s",dtu_str);
 }
 /* 接收数据回调函数 */
 static rt_err_t dtu_input(rt_device_t dev, rt_size_t size)
@@ -122,163 +112,30 @@ static rt_err_t dtu_input(rt_device_t dev, rt_size_t size)
     if ( result == -RT_EFULL)
     {
         /* 消息队列满 */
-        LOG_E("message queue full!");
+        LOG_E("rx_mq_dtu message queue full!");
         rt_mq_control(&rx_mq_dtu, RT_IPC_CMD_RESET, RT_NULL); // 清空队列
     }
     return result;
 }
-// 最大JSON缓冲区长度(建议根据设备内存调整)
-#define MAX_JSON_BUFFER 1024
-// 全局缓冲区结构体
-static struct {
-    char buffer[MAX_JSON_BUFFER]; // 数据存储区
-    int index;                   // 当前写入位置
-    rt_tick_t last_received;     // 最后接收时间戳
-    int nested_level;            // 当前嵌套层数
-} json_ctx = {.index = 0, .last_received = 0, .nested_level = 0};
-
-
-// 自定义异常类型
-typedef enum {
-    JSON_OK,
-    JSON_INCOMPLETE,
-    JSON_INVALID_CHAR,
-    JSON_TOO_DEEP,
-    JSON_TOO_LONG
-} json_status_t;
-
-
-// 查找完整JSON边界(支持嵌套)
-static json_status_t find_json_boundary(int *start, int *end)
-{
-    *start = -1;
-    *end = -1;
-    int level = 0;
-
-    for (int i = 0; i < json_ctx.index; i++) {
-        if (json_ctx.buffer[i] == '{') {
-            if (level == 0) *start = i;
-            level++;
-            if (level > 32) return JSON_TOO_DEEP;
-        } else if (json_ctx.buffer[i] == '}') {
-            level--;
-            if (level < 0) return JSON_INVALID_CHAR;
-            if (level == 0 && *start != -1) {
-                *end = i;
-                return JSON_OK;
-            }
-        }
-    }
-
-    if (*start != -1) return JSON_INCOMPLETE;
-    return JSON_OK;
-}
-
-#define RT_MIN(a, b) ((a) < (b) ? (a) : (b))
-// 核心处理函数
-void process_uart_data(const char *data, int length)
-{
-    // 有效性检查
-    if (data == NULL || length <= 0) return;
-    json_ctx.last_received = rt_tick_get();
-
-    // 缓冲区溢出保护
-    int remain_space = MAX_JSON_BUFFER - json_ctx.index - 1;
-    if (remain_space < length) {
-        rt_kprintf("[JSON] Buffer overflow (%d/%d)\n",
-                  json_ctx.index + length, MAX_JSON_BUFFER);
-        json_ctx.index = 0; // 清空缓冲区重新开始
-        return;
-    }
-
-    // 追加新数据
-    rt_memcpy(json_ctx.buffer + json_ctx.index, data, length);
-    json_ctx.index += length;
-    json_ctx.buffer[json_ctx.index] = '\0';
-
-    // 循环处理所有完整报文
-    while (1) {
-        int start_pos, end_pos;
-        json_status_t status = find_json_boundary(&start_pos, &end_pos);
-
-        switch (status) {
-        case JSON_OK:
-            if (start_pos != -1 && end_pos != -1) {
-                // 提取有效JSON内容
-                char json_str[512] = {0};
-                int json_len = end_pos - start_pos + 1;
-                rt_strncpy(json_str, json_ctx.buffer + start_pos,
-                          RT_MIN(sizeof(json_str)-1, json_len));
-
-                // 调用解析函数
-                if (parseDtu(json_str) == RT_EOK) {
-                    rt_kprintf("[JSON] Parsed: %.*s\n", json_len, json_str);
-                }
-
-                // 移动缓冲区剩余内容
-                int remain_data = json_ctx.index - (end_pos + 1);
-                if (remain_data > 0) {
-                    rt_memmove(json_ctx.buffer,
-                              json_ctx.buffer + end_pos + 1,
-                              remain_data);
-                }
-                json_ctx.index = remain_data;
-                json_ctx.buffer[json_ctx.index] = '\0';
-            } else {
-                return; // 无更多完整报文
-            }
-            break;
 
-        case JSON_INCOMPLETE:
-            return; // 等待更多数据
 
-        default:
-            rt_kprintf("[JSON] Error %d at pos %d\n", status, start_pos);
-            // 错误恢复:跳过错误数据
-            json_ctx.index = 0;
-            return;
-        }
-    }
-}
 
 static void dtu_thread_entry_recv(void *parameter)
 {
     struct rx_msg msg;
     rt_memset(&msg, 0, sizeof(msg));
-    static int recv_cnt = 0;
+
+    rt_err_t result;
+    rt_uint32_t rx_length;
+    rt_uint32_t rx_err = 0;
+    static char str_check[2]={'{','}'};
+    static char rx_buffer[512];
+    static char rx_buffer_tmp[512];
+    static char rx_buffer_tmp2[512];
     while(1)
     {
-        //
-        // 从消息队列中获取被回调函数放入消息队列中的内容
-        int result = rt_mq_recv(&rx_mq_dtu, &msg, sizeof(struct rx_msg), 100);
-        if (result != RT_EOK){
-            recv_cnt++;
-            if(recv_cnt==15)
-            {
-                json_ctx.index = 0;
-            }
-            continue;
-        }
-        // 动态分配接收缓冲区
-        char *rx_buffer = rt_malloc(msg.size + 1);
-        if (!rx_buffer) {
-            LOG_E("Memory allocation failed");
-            continue;
-        }
-        // 安全读取数据
-        int rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
-        if (rx_length <= 0) {
-            rt_free(rx_buffer);
-            continue;
-        }
-        recv_cnt = 0;
-        rx_buffer[rx_length] = '\0';
-        // 处理数据(新增调试接口)
-        LOG_I("Raw Data:%s-%d",rx_buffer, rx_length);
-
-        process_uart_data(rx_buffer, rx_length);
-        rt_free(rx_buffer);
-        #if 0
+        result = rt_mq_recv(&rx_mq_dtu, &msg, sizeof(struct rx_msg), 50);
+        #if 1
         if(result == RT_EOK)
         {
 
@@ -290,19 +147,13 @@ static void dtu_thread_entry_recv(void *parameter)
             LOG_D("recv data:%s",rx_buffer);
             if(strstr(rx_buffer,"{")==RT_NULL||strstr(rx_buffer,"}")==RT_NULL)
             {
-                if(device_status.dtype==7)
-                {
-                    HMI_WRITE("sysTest.result.txt=\"%s\"",rx_buffer);
-                }
-
                 if(device_status.dtype==3)
                 {
                     HMI_WRITE("sysSet.va0.txt=\"%s\"",rx_buffer);
                     rt_timer_stop(timer_uart2);
                 }
-
             }
-
+            device_status.C01 &= ~(1<<13);   //通信 正常
             //过滤异常数据
             char str_check_head[2];
             char str_check_end[2];
@@ -328,130 +179,28 @@ static void dtu_thread_entry_recv(void *parameter)
                        rt_memset(rx_buffer_tmp,0,sizeof(rx_buffer_tmp));
                        rt_memset(rx_buffer_tmp2,0,sizeof(rx_buffer_tmp2));
                    }
-
                  }
-            #endif
-         }
-}
-#if 0
-/*入口函数-指令发送*/
-static void dtu_thread_entry_send(void *parameter)
-{
 
-    device_status.power_status = 1;
-    device_status.num_updata = 0;
-    rt_thread_delay(10000);
-    static rt_uint16_t wait_i = 0;
-    static rt_uint8_t check_i = 0;
-    static rt_uint8_t power_i = 0;
-    while(1)
-    {
-        time_t now_t;
-        time(&now_t);
-        static struct tm now_tm;   //现在
-        //获取当前时间戳
-        now_tm =*localtime(&now_t);
-        if(atoi(device_status.net)==0||atoi(device_status.gps)==1||(now_tm.tm_year+1900 >=2024))    //当前时间大于2024
-        {
-                if(device_status.rain_status==1||device_status.temp_status==1)
-                {
-                    if(check_i==0)
-                    {
-                        check_i = 1;
-                        device_status.num_updata = 0;
-                    }
-                }
-                else {
-                    check_i = 0;
-                }
-                if(device_status.num_updata!=0)
-                {
-                    device_status.num_updata--;
-                    //屏幕休眠
-                    if(device_status.num_updata==(device_status.dattim * 60-10))
-                    {
-                        HMI_WRITE("sleep=%d",1);
-                    }
-                    LOG_I("掉电检测:%d-%d",atoi(device_status.voltage),device_status.power_status);
-                    //检测到电源掉电
-                    if(atoi(device_status.voltage)<5&&device_status.power_status==1)
-                    {
-                        power_i++;
-                        //确定网络状态
-                        if(power_i==10)
-                        {
-                            device_status.bat_status = 1;
-                            rt_sprintf(device_status.net, "1");
-                            HMI_WRITE("sleep=%d",1);    //屏幕休眠
-                            DTU_Write("%s",makeJson_Warn("power down","power"));
-                            device_status.power_status = 0;
-                            rt_thread_delay(5000);
-                            ctr_router(OFF);
-                            ctr_RTU_DTU(OFF);
-                            power_i = 0;
-                        }
-                    }
-                    if(atoi(device_status.voltage)>12&&device_status.power_status==0)      //电压正常
-                    {
-                        device_status.power_status = 1;
-                        ctr_router(ON);
-                        ctr_RTU_DTU(ON);
-                        power_i = 0;
-                    }
-                }
-                else {
-                    char *readinfo =  makeJson_ReadInfo();
-                    rt_kprintf("upload data:%s\n",readinfo);
-                    DTU_Write("%s",readinfo);
-                    rt_free(readinfo);
-                    rt_thread_delay(1000);
-                    UpLoad_Data();
-                    if(atoi(device_status.fuse_voltage)<1)
-                    {
-                        rt_thread_delay(500);
-                        static char res[30];
-                        sprintf(res, "Fuse is fusing:%s",device_status.fuse_voltage);
-                        char * res_fuse_warn = makeJson_Warn(res,"device");
-                        DTU_Write("%s",res_fuse_warn);
-                        rt_free(res_fuse_warn);
-                    }
-                    device_status.num_updata = device_status.dattim * 60;
-                    if(device_status.dattim==0) device_status.dattim=20;   //数据上传时间间隔设置为0?
-                    if(device_status.bat_status==0) device_status.power_status = 1;     //解除欠压,清除标志位
-                }
-        }
-    else {
-            wait_i ++;
-            LOG_I("wait connect internet......%d",wait_i);
-            //检测到电源掉电
-            if(atoi(device_status.voltage)<5&&device_status.power_status==1&&wait_i>200)
-            {
-                check_i++;
-                LOG_W("断网状态下检测到设备断电!%d",atoi(device_status.voltage));
-                if(check_i==10)
-                {
-                    device_status.bat_status = 1;
-                    device_status.power_status = 0;
-                    rt_thread_delay(5000);
-                    ctr_router(OFF);
+         }
+        else {
+               rx_err ++;
+               if(rx_err==54000)//90分钟未接收到数据
+               {
                     ctr_RTU_DTU(OFF);
-                    check_i = 0;
-                }
-            }
-            if(Read_Real_Voltage()/100>10&&device_status.power_status==0)
-            {
-                check_i = 0;
-                LOG_I("电源恢复正常,打开路由器和RTU供电!");
-                device_status.power_status = 1;
-                //打开路由器和RTU供电
-                ctr_router(ON);
-                ctr_RTU_DTU(ON);
-            }
-        }
-    rt_thread_mdelay(1000);
-    }
+                    device_status.C01 |= (1<<13);    //灯管 故障
+               }
+               else if (rx_err>54100&&device_status.bat_status==0)
+               {
+                   LOG_W("通信中断,RTU重新上电");
+                   rx_err = 0;
+                   ctr_RTU_DTU(ON);
+                   ctr_photo(ON);
+               }
+         }
+   }
+        #endif
 }
-#endif
+
 /* 创建线程 */
 int dtu_data_play(void)
 {
@@ -470,7 +219,7 @@ int dtu_data_play(void)
     rt_device_set_rx_indicate(dtuserial, dtu_input);
     #if 0
     /*创建线程-指令发送*/
-    dtu_send_data = rt_thread_create("DTU_Uart_thread_send",
+    dtu_send_data = rt_thread_create("DTU_thread",
                                     dtu_thread_entry_send,RT_NULL,
                                     DTU_THREAD_STACK_SIZE,
                                     3,                              //优先级高是为了保证数据上传的频率的精确度
@@ -478,7 +227,7 @@ int dtu_data_play(void)
             );
     #endif
     /* 创建线程-指令接收解析*/
-    dtu_recv_data = rt_thread_create("DTU_Uart_thread_recv",
+    dtu_recv_data = rt_thread_create("thread_uart2",
             dtu_thread_entry_recv, RT_NULL,
             DTU_THREAD_STACK_SIZE,
             DTU_THREAD_PRIORITY,
@@ -1225,45 +974,7 @@ int parseDtu(char *json_string)
                       LOG_I("收到自检指令:%d",device_status.selfcheck_ws);
                   }
               }
-              //切换平台
-              else if (strstr(item_cmd->valuestring,"platform")!=RT_NULL)
-              {
-                  type = cJSON_GetObjectItem(item_ext,"type");
-                  if(strstr(type->valuestring,"8.136.98.49")!=RT_NULL)
-                  {
-                      rt_sprintf(device_status.mqttcfg1, "8.136.98.49");
-                      ef_set_env_blob("platform", &device_status.mqttcfg1, sizeof(device_status.mqttcfg1));
-                      //给RTU发送切换指令
-                      DTU_Write("%s",makeJson_platform("8.136.98.49"));
-                      rt_free(makeJson_platform("8.136.98.49"));
-                      rt_thread_delay(1000);
-                      rt_sprintf(device_status.json_w_platform,"平台操作:切换平台>大数据,操作时间:%s",device_status.stamp);
-                                            json_s = makeJson_Warn(device_status.json_w_platform, "切换平台");
-                                            ef_set_env_blob("json_w_platform", &device_status.json_w_platform, sizeof(device_status.json_w_platform));   //将修改屏幕参数操作记录保存到Flash中
-                                            if(atoi(device_status.net)==0)
-                                                DTU_Write("%s",json_s);
-                                            rt_free(json_s);
-                                            rt_thread_delay(1000);
-                      MA_save();
-                  }
-                  else if (strstr(type->valuestring,"120.27.222.26")!=RT_NULL)
-                  {
-                      rt_sprintf(device_status.mqttcfg1, "120.27.222.26");
-                      ef_set_env_blob("platform", &device_status.mqttcfg1, sizeof(device_status.mqttcfg1));
-                      //给RTU发送切换指令
-                      DTU_Write("%s",makeJson_platform("120.27.222.26"));
-                      rt_free(makeJson_platform("120.27.222.26"));
-                      rt_thread_delay(1000);
-                      rt_sprintf(device_status.json_w_platform,"平台操作:切换平台>四情,操作时间:%s",device_status.stamp);
-                      json_s = makeJson_Warn(device_status.json_w_platform, "切换平台");
-                      ef_set_env_blob("json_w_platform", &device_status.json_w_platform, sizeof(device_status.json_w_platform));   //将修改屏幕参数操作记录保存到Flash中
-                      if(atoi(device_status.net)==0)
-                          DTU_Write("%s",json_s);
-                      rt_free(json_s);
-                      rt_thread_delay(1000);
-                      MA_save();
-                  }
-              }
+
               //水稻2000万像素的串口拍照指令
               else if (strstr(item_cmd->valuestring,"mvs_photo")!=RT_NULL)
               {
@@ -1304,7 +1015,6 @@ int parseDtu(char *json_string)
               {
                   char * readinfo = makeJson_ReadInfo();
                   DTU_Write("%s",readinfo);
-                  rt_kprintf("%s\n",readinfo);
                   rt_free(readinfo);
                   device_status.hmi_fresh = 2;
                   device_status.refresh_num = 15;
@@ -1796,6 +1506,31 @@ int parseDtu(char *json_string)
                                          }
                                          LOG_I("开始结束时间2:%d-%d",device_status.collecting_sh2,device_status.collecting_eh2);
                                      }
+                                     else if (icnt==2)
+                                     {
+                                         if((ivalue[1]=='-'))
+                                         {
+                                             device_status.collecting_sh3 = atoi(&ivalue[0]);
+                                             if(strlen(ivalue)==3)
+                                                 device_status.collecting_eh3 = atoi(&ivalue[2]);
+                                             if(strlen(ivalue)==4)
+                                                 device_status.collecting_eh3 = atoi(&ivalue[3])<<8|atoi(&ivalue[2]);
+                                             ef_set_env_blob("collecting_sh3", &device_status.collecting_sh3, sizeof(device_status.collecting_sh3));
+                                             ef_set_env_blob("collecting_eh3", &device_status.collecting_eh3, sizeof(device_status.collecting_eh3));
+                                         }
+                                         if((ivalue[2]=='-'))
+                                         {
+                                             device_status.collecting_sh3 = atoi(&ivalue[1])<<8|atoi(&ivalue[0]);
+                                             if(strlen(ivalue)==3)
+                                                 device_status.collecting_eh3 = atoi(&ivalue[2]);
+                                             if(strlen(ivalue)==5)
+                                                 device_status.collecting_eh3 = atoi(&ivalue[4])<<8|atoi(&ivalue[3]);
+                                             ef_set_env_blob("collecting_sh3", &device_status.collecting_sh3, sizeof(device_status.collecting_sh3));
+                                             ef_set_env_blob("collecting_eh3", &device_status.collecting_eh3, sizeof(device_status.collecting_eh3));
+                                         }
+                                         LOG_I("开始结束时间3:%d-%d",device_status.collecting_sh3,device_status.collecting_eh3);
+                                     }
+
                                      LOG_I("下发设置收集:%d-%s",icnt,ivalue);
                                  }
                               }
@@ -2051,20 +1786,6 @@ int parseDtu(char *json_string)
                             }
                           }
                           UpLoad_Data();
-                          rt_thread_delay(2000);
-                          //2022/06/23,add:
-                          if(device_status.dtype==3)
-                          {
-                              rt_sprintf(device_status.json_w_clock,"平台操作:修改工作时间:开始-%d,结束-%d,模式-%d(0-光控,1-时控)-%s",device_status.startBar,device_status.stopBar,device_status.timeSwitch,device_status.stamp);
-                              json_s = makeJson_Warn(device_status.json_w_clock, "修改时间");
-                              ef_set_env_blob("json_w_clock", &device_status.json_w_clock, sizeof(device_status.json_w_clock));   //将修改屏幕参数操作记录保存到Flash中
-                              if(atoi(device_status.net)==0)
-                                  DTU_Write("%s",json_s);
-                              rt_free(json_s);
-                          }
-
-                          rt_thread_delay(1000);
-                          MA_save();
                           rt_thread_delay(1000);
                }
           }
@@ -2076,11 +1797,8 @@ int parseDtu(char *json_string)
 void UpLoad_Data(void)
 {
     char *updata = makeJson();
-    LOG_I("upload data:%d %s",rt_strlen(updata),updata);
+    DTU_Write(updata);
     rt_free(updata);
-    #if Color_EN ==0
-    DTU_Write("%s",updata);
-    #endif
     //list_mem();
     //播放数据上传中语音
 }

+ 1 - 1
Application_cbd_apm32f1/applications/dtu_uart2.h

@@ -11,7 +11,7 @@
 #define APPLICATIONS_INC_DTU_UART2_H_
 
 #define DTU_UART_NAME "uart2"  /*串口设备名称*/
-#define MAX_DTU_SIZE 512
+#define MAX_DTU_SIZE 1024
 typedef struct{
     char msg_pool[MAX_DTU_SIZE];
 }DataTemp;

+ 5 - 1
Application_cbd_apm32f1/applications/hmi.c

@@ -1652,6 +1652,8 @@ void Check_ParamConfig(void)
         ef_set_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1));        //采集时间
         ef_set_env_blob("collecting_sh2",&device_status.collecting_sh2,sizeof(device_status.collecting_sh2));        //采集时间
         ef_set_env_blob("collecting_eh2",&device_status.collecting_eh2,sizeof(device_status.collecting_eh2));        //采集时间
+        ef_set_env_blob("collecting_sh3",&device_status.collecting_sh3,sizeof(device_status.collecting_sh3));        //采集时间
+        ef_set_env_blob("collecting_eh3",&device_status.collecting_eh3,sizeof(device_status.collecting_eh3));        //采集时间
         ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));      //
         ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
         ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
@@ -1708,6 +1710,8 @@ void Check_ParamConfig(void)
         ef_get_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1),NULL);  //采集结束1
         ef_get_env_blob("collecting_sh2",&device_status.collecting_sh2,sizeof(device_status.collecting_sh2),NULL);  //采集开始2
         ef_get_env_blob("collecting_eh2",&device_status.collecting_eh2,sizeof(device_status.collecting_eh2),NULL);  //采集结束2
+        ef_get_env_blob("collecting_sh3",&device_status.collecting_sh2,sizeof(device_status.collecting_sh3),NULL);  //采集开始3
+        ef_get_env_blob("collecting_eh3",&device_status.collecting_eh2,sizeof(device_status.collecting_eh3),NULL);  //采集结束3
         ef_get_env_blob("run_sta",&device_status.run_sta,sizeof(device_status.run_sta),NULL);                       //运行状态
         ef_get_env_blob("Power_Type",&device_status.Power_Type,sizeof(device_status.Power_Type),NULL);              //供电类型
         ef_get_env_blob("deviceId",&device_status.deviceId,sizeof(device_status.deviceId),NULL);                    //设备编码
@@ -1751,7 +1755,7 @@ void Check_ParamConfig(void)
         LOG_I("温湿度数据:%d-%d",atoi(device_status.tempture),atoi(device_status.humidity));
         LOG_I("上传平台:%s",device_status.mqttcfg1);
         LOG_I("孢子仪运行状态:%d",device_status.run_sta);
-        LOG_I("孢子仪采集时间:[%d-%d,%d-%d]",device_status.collecting_sh1,device_status.collecting_eh1,device_status.collecting_sh2,device_status.collecting_eh2);
+        LOG_I("孢子仪采集时间:[%d-%d,%d-%d,%d-%d]",device_status.collecting_sh1,device_status.collecting_eh1,device_status.collecting_sh2,device_status.collecting_eh2,device_status.collecting_sh3,device_status.collecting_eh3);
         LOG_I("PowerType:%d",device_status.Power_Type);
         LOG_I("deviceId:%s",device_status.deviceId);
         LOG_I("handle_bugger:%d",device_status.handle_bugger);

+ 2 - 0
Application_cbd_apm32f1/packages/EasyFlash-v4.1.0/src/ef_fal_port.c

@@ -85,6 +85,8 @@ static const ef_env default_env_set[] = {
         {"collecting_eh1","0"},    //
         {"collecting_sh2","0"},    //
         {"collecting_eh2","0"},    //
+        {"collecting_sh3","0"},    //
+        {"collecting_eh3","0"},    //
         {"Power_Type","0"},        //供电类型
         {"deviceId","0"},          //BDH设备编码
         {"handle_bugger","0"}      //虫子处理,收虫,排虫