瀏覽代碼

增加自检

zhunk 1 年之前
父節點
當前提交
c06f923231

+ 43 - 75
Application_CBD/applications/control.c

@@ -16,6 +16,7 @@
 #include "sound.h"
 #include "dtu_uart2.h"
 #include "sht30_collect.h"
+#include "string.h"
 #define DBG_ENABLE
 #define DBG_COLOR
 #define DBG_TAG "control"
@@ -38,6 +39,24 @@ rt_thread_t tid_workloop = RT_NULL;
 rt_thread_t tid_wkstc = RT_NULL;
 rt_thread_t tid_ctr = RT_NULL;
 rt_thread_t tid_heat = RT_NULL;
+
+int thread_delete_workloop(void)
+{
+    rt_err_t result;
+    if(tid_workloop!=RT_NULL)
+    {
+        result = rt_thread_delete(tid_workloop);
+    }
+    return result;
+}
+
+int thread_restart_workloop(void)
+{
+    rt_err_t result;
+    result = Work_Loop_Task();
+    return result;
+}
+
 /**************************1.0定制2000W*************************************/
 uint8_t ctr_Fan_PUT(uint8_t status_ws)
 {
@@ -2282,6 +2301,10 @@ void WorkTask(void)
         }
         #else
             ctr_lamp(ON,1);
+            if(device_status.version_type==12)
+            {
+                ctr_Heat(ON);
+            }
         #endif
         LOG_I("打开灯管!!!");
         #if 0
@@ -2391,7 +2414,7 @@ void WorkTask(void)
                 LOG_I("等待上仓门关闭!!!");
             }
             //5.加热
-            if(device_status.heat_sw==0)
+            if(device_status.heat_sw==0||device_status.version_type==12)
             {
                 calorstat(device_status.heattime*60);
             }
@@ -2433,7 +2456,7 @@ void WorkTask(void)
              LOG_I("打开上仓门!!!");
              HMI_WRITE("workSta.g0.txt=\"打开上仓门!\"");
              device_status.ctr_up_motor = 1;
-            if(device_status.version_type==4||device_status.version_type==41)
+            if(device_status.version_type==4||device_status.version_type==41||strstr(device_status.project,"A7_RTU_V3")!=RT_NULL)
             {
                 //震动
                 ctr_shake(ON, device_status.shake_sec);
@@ -2610,65 +2633,8 @@ static void Control_Clear_thread_entry(void *parameter)
 /*入口函数加热*/
 static void Control_Heat_thread_entry(void *parameter)
 {
-
-    uint16_t var_clear = 0;
-    #if ROBOT_EN == 1
-    static uint8_t key_on = 0;
-    #else
-    #if Color_EN == 0
-    while(device_status.work_status==0)
-    {
-        rt_thread_delay(1000);
-    }
-    #endif
-    #endif
     while(1)
     {
-        #if ROBOT_EN == 1
-        //磁悬浮供电
-        //监测磁悬浮限位位置`
-        LOG_D("Read 磁悬浮:%d",device_status.heattem);
-        //等待10S
-        if(device_status.heattem<30&&Read_Real_Voltage()/100>12)   //磁悬浮处于关闭状态
-        {
-            key_on = 0;
-            //发送触摸按钮信号
-            rt_pin_mode(EMS_Dir, PIN_MODE_OUTPUT);
-            rt_pin_write(EMS_Dir, 0);
-            rt_thread_delay(50);
-            rt_pin_write(EMS_Dir, 1);
-        }
-        else if (device_status.heattem<30&&Read_Real_Voltage()/100<12) {
-            ctr_router(OFF);
-        }
-        if(device_status.heattem>40)
-        {
-            key_on = 1;
-            rt_thread_delay(1000);
-            LOG_D("Read 磁悬浮已打开:%d",device_status.heattem);
-        }
-
-        //磁悬浮供电
-        //监测磁悬浮限位位置
-        //根据位置确定是否 按下按钮+
-        if(Read_Real_Voltage()/100<12&&key_on==1)
-        {
-            key_on = 0;
-            rt_pin_mode(EMS_Dir, PIN_MODE_OUTPUT);
-            rt_pin_write(EMS_Dir, 0);
-            rt_thread_delay(50);
-            rt_pin_write(EMS_Dir, 1);
-        }
-        #else
-        #if Color_EN == 1
-        /*黄板归位*/
-        if(Read_Color_Key(KEY_BACK)==1)
-        {
-            LOG_W("黄板归位!");
-            ctr_Color_board(CLOSE, 300);
-            rt_thread_delay(5000);
-        }
-        #else
         if(device_status.work_status==1&&device_status.heat_sw==1)
         {
             ctr_lamp(ON, 1);
@@ -2677,26 +2643,28 @@ static void Control_Heat_thread_entry(void *parameter)
         }
         else
         {
-            LOG_I("Not calorstat!");
-        }
-        if(device_status.work_status==1&&device_status.version_type==5)
-        {
-            var_clear++;
-            if(var_clear==300)
+            LOG_I("Not calorstat!%d",device_status.selfcheck_ws);
+            if(device_status.selfcheck_ws==2)
             {
-                var_clear = 0;
-                ctr_cangmen_down(ON);
-                rt_thread_mdelay(5000);
-                ctr_cangmen_down(OFF);
-                rt_thread_mdelay(500);
-                ctr_cangmen_down(ON);
-                rt_thread_mdelay(5000);
-                ctr_cangmen_down(OFF);
+                static int total_seconds = 200;
+                static int current_second = 0;
+                while(current_second <= total_seconds)
+                {
+                    int process = (current_second * 100) / total_seconds;
+                    device_status.process = process / 100.0;
+                    LOG_I("process:%d",process);
+                    HMI_WRITE("selfcheck.s106.val=%d",process);
+                    rt_thread_delay(1000);
+                    current_second++;
+                    if(device_status.selfcheck_ws==0)
+                    {
+                        HMI_WRITE("selfcheck.s106.val=1");
+                        break;
+                    }
+                }
             }
         }
         rt_thread_delay(1000);
-        #endif
-        #endif
     }
 }
 /*清扫线程*/

+ 14 - 5
Application_CBD/applications/control.h

@@ -25,12 +25,12 @@
     #define VERSION_HK          "1.(3ledV9).41(HK)"      //4.0海康-三色光源
     #define VERSION_HK_2000W    "1.3led.40(2000W)"       //水稻
 #else
-    #define VERSION_HK          "1.54.41(HK)"            //4.0海康-1200W
-    #define VERSION_HK_2000W    "1.53.40(2000W)"         //4.0水稻
+    #define VERSION_HK          "1.55.41(HK)"            //4.0海康-1200W
+    #define VERSION_HK_2000W    "1.54.40(2000W)"         //4.0水稻
 #endif
 
-#define VERSION_ZP          "1.45.1(ZP)"            //1.0转盘
-#define VERSION_GK          "1.41.1(GK)"            //1.0高空
+#define VERSION_ZP          "1.46.1(ZP)"            //1.0转盘
+#define VERSION_GK          "1.42.1(GK)"            //1.0高空
 
 #define VERSION_XCT         "1.13.6(HK)"            //吸虫塔-海康
 #define VERSION_V5          "1.2.5(HK)"             //5.0
@@ -107,7 +107,7 @@ typedef struct  _packed
     uint8_t hmi_fresh;       //是否启动屏幕
     uint8_t update_flag;     //是否启动升级
     uint8_t photo_type;      //相机类型,0-USB,1-海康,2-大华
-    uint8_t version_type;    //版本类型,1-转盘,4-海康,41-水稻,11-高空,48-4800
+    uint8_t version_type;    //版本类型,1-转盘,41-海康,4-水稻,11-高空,48-4800,42-低端款
     uint8_t stop_in_bootloader;     //进入bootloader模式 1
     uint8_t account_status;         //卡状态
     uint8_t test_flag;              //测试标志
@@ -126,12 +126,14 @@ typedef struct  _packed
     uint16_t dattim;         //数据上传间隔
     uint16_t shake_sec;      //震动时间
     uint16_t thsp;           //息屏时间
+    uint16_t C01;            //故障码
     rt_uint32_t num_updata;         //
     rt_uint32_t rebootcnt;          //启动次数
     rt_uint32_t light_over_tim;     //光控定时差秒数,镇流器的结束时间
     rt_uint32_t data_plan;          //流量套餐
     rt_uint32_t expiry_date;        //到期时间
     int passWord;              //初始密码
+    double process;
     long photo_stamp;           //采集时间戳
     const char *coll_time[10];
     char mqttcfg1[64];         //
@@ -143,6 +145,8 @@ typedef struct  _packed
     char gps_state[8];         //定位类型
     char tempture[12];         //温度
     char humidity[12];         //湿度
+    char lux[12];              //照度Lux
+    char ap[12];               //大气压hpa
     char driver[64];           //版本
     char driver_4g[64];        //4g版本
     char driver_bl[64];        //BL版本
@@ -326,4 +330,9 @@ int Control_clear(void);
 int Workstatus_check(void);
 int Work_Loop_Task(void);
 int Control_heat(void);
+
+int thread_delete_workloop(void);
+int thread_restart_workloop(void);
+
+
 #endif /* APPLICATIONS_INC_CONTROL_H_ */

+ 164 - 4
Application_CBD/applications/dtu_uart2.c

@@ -12,7 +12,7 @@
 #include <board.h>
 #include <rtdevice.h>
 #include  "stdarg.h"
-#include  "string.h"
+#include  "string.h"version_type
 #include "stdio.h"
 #include "dtu_uart2.h"
 #include <cJSON.h>
@@ -22,6 +22,7 @@
 #include "sound.h"
 #include <ymodem.h>
 #include "beep.h"
+#include "selfcheck.h"
 #define DBG_ENABLE
 #define DBG_COLOR
 #define DBG_TAG "dtu"
@@ -537,6 +538,37 @@ char *makeJson_selfCheck_(uint8_t sta)  //sta==0 应答,sta==1结果
     return t;
 }
 
+char *makeJson_C01_Warn(uint16_t code,double process)
+{
+    cJSON * pJsonRoot = NULL;
+    pJsonRoot = cJSON_CreateObject();
+    if(NULL==pJsonRoot)
+    {
+        LOG_E("cJSON pJsonRoot NULL!!!");
+        return NULL;
+    }
+    cJSON_AddStringToObject(pJsonRoot, "cmd", "selfcheck");
+    cJSON * pubstring = NULL;
+    pubstring = cJSON_CreateObject();
+    if(NULL==pubstring)
+    {
+        rt_kprintf("cJSON pubstring NULL!!!\n");
+        return NULL;
+    }
+    cJSON_AddItemToObject(pJsonRoot, "ext", pubstring);
+    cJSON_AddNumberToObject(pubstring, "C01", code);//
+    cJSON_AddNumberToObject(pubstring, "process", process);//
+    char * w = cJSON_PrintUnformatted(pJsonRoot);
+    if(NULL == w)
+    {
+        cJSON_Delete(pJsonRoot);
+        LOG_E("wJsonRoot cJSON_Delete NULL!!!\n");
+        return NULL;
+    }
+    cJSON_Delete(pJsonRoot);
+    return w;
+}
+
 
 char * makeJson_Rtutakephoto()
 {
@@ -689,6 +721,11 @@ char * makeJson()
     else if (device_status.version_type==11) {
         rt_sprintf(device_status.driver,"%s-%s",VERSION_GK,device_status.driver_4g);
     }
+    else if (device_status.version_type==12) {
+        rt_sprintf(device_status.driver,"%s-%s",VERSION_GK,device_status.driver_4g);
+        cJSON_AddStringToObject(pSubJson,"lux",device_status.lux);
+        cJSON_AddStringToObject(pSubJson,"ap",device_status.ap);
+    }
     else if (device_status.version_type==5) {
         rt_sprintf(device_status.driver,"%s-%s",VERSION_V5,device_status.driver_4g);
     }
@@ -698,6 +735,9 @@ char * makeJson()
     else if (device_status.version_type==7) {
         rt_sprintf(device_status.driver,"%s-%s",VERSION_BZY,device_status.driver_4g);
     }
+    else if (device_status.version_type==42) {
+        rt_sprintf(device_status.driver,"%s-%s",VERSION_HK_2000W,device_status.driver_4g);
+    }
     if(device_status.sensor_485_sta!=0)
     {
         if(strstr(device_status.driver,"485")==RT_NULL)
@@ -722,6 +762,7 @@ char * makeJson()
     else if (device_status.version_type==11) {  //高空
         rt_sprintf(utos,"11");
         cJSON_AddStringToObject(pSubJson,"vtype",utos);
+
     }
     else if (device_status.version_type==5) {   //5.0
         rt_sprintf(utos,"5");
@@ -731,6 +772,10 @@ char * makeJson()
         rt_sprintf(utos,"6");
         cJSON_AddStringToObject(pSubJson,"vtype",utos);
     }
+    else if (device_status.version_type==42) {   //测报灯低端款
+            rt_sprintf(utos,"42");
+            cJSON_AddStringToObject(pSubJson,"vtype",utos);
+    }
     if(device_status.version_type!=6&&device_status.dtype!=7)
     {
         //光控定时
@@ -1019,7 +1064,6 @@ int parseDtu(char *json_string)
           if(cam_cmd!=NULL){
               //先检查定时器状态,否则会崩溃
               rt_timer_stop(timer_uart2);
-
               LOG_I("cam_code");
               if(cam_cmd->valueint==0){
                   ctr_led(ON);
@@ -1033,11 +1077,23 @@ int parseDtu(char *json_string)
 
           if(ledsta!=NULL)
           {
+              rt_timer_stop(timer_takephoto);
+              HMI_WRITE("selfcheck.t3.bco=2024");
+              device_status.C01 &= ~(1<<2);
+              if(ledsta->valueint==0)
+              {
+                  HMI_WRITE("selfcheck.t4.bco=2024");
+                  device_status.C01 &= ~(1<<3);
+              }
+              else
+              {
+                  HMI_WRITE("selfcheck.t4.bco=63488");
+                  device_status.C01 |= (1<<3);
+              }
               device_status.led_sta = ledsta->valueint;
               LOG_I("补光灯报警状态:%d",device_status.led_sta);
           }
           if(photolink!=NULL){
-              device_status.selfcheck_ws = 0;
               device_status.camsta = 0; //拍照正常
               device_status.ctr_up_motor = 0;   //关闭
               device_status.ctr_down_motor = 0; //关闭
@@ -1155,15 +1211,119 @@ int parseDtu(char *json_string)
                       if(device_status.vol==0)
                           device_status.vol = 111;
                   }
-                  else if (strstr(type->valuestring,"led_on")!=RT_NULL)
+                  else if (strstr(type->valuestring,"led_on")!=RT_NULL)             //打开补光灯
                   {
+                      LOG_I("远程打开补光灯!");
                       ctr_led(ON);
+                      char *ctr_c = makeJson_Warn("打开补光灯","control");
+                      DTU_Write("%s",ctr_c);
+                      rt_free(ctr_c);
+                      rt_thread_delay(2000);
                   }
                   else if (strstr(type->valuestring,"led_off")!=RT_NULL)
                   {
+                      LOG_I("远程关闭补光灯!");
                       ctr_led(OFF);
                       device_status.photo_ws = 0;
                   }
+                  else if (strstr(type->valuestring,"lamp_on")!=RT_NULL)
+                  {
+                      LOG_I("远程打开镇流器!");
+                      ctr_lamp(ON,1);
+                      char *ctr_c = makeJson_Warn("打开镇流器","control");
+                      DTU_Write("%s",ctr_c);
+                      rt_free(ctr_c);
+                      rt_thread_delay(2000);
+                  }
+                  else if (strstr(type->valuestring,"lamp_off")!=RT_NULL)
+                  {
+                      LOG_I("远程关闭镇流器!");
+                      ctr_lamp(OFF,1);
+                      char *ctr_c = makeJson_Warn("关闭镇流器","control");
+                      DTU_Write("%s",ctr_c);
+                      rt_free(ctr_c);
+                      rt_thread_delay(2000);
+                  }
+                  else if (strstr(type->valuestring,"up_m_open")!=RT_NULL)
+                  {
+                      LOG_I("远程打开上仓门!");
+                      device_status.ctr_up_motor = 1;
+                      char *ctr_c = makeJson_Warn("打开上仓门","control");
+                      DTU_Write("%s",ctr_c);
+                      rt_free(ctr_c);
+                      rt_thread_delay(2000);
+                  }
+                  else if (strstr(type->valuestring,"up_m_close")!=RT_NULL)
+                  {
+                      LOG_I("远程关闭上仓门!");
+                      device_status.ctr_up_motor = 2;
+                      char *ctr_c = makeJson_Warn("关闭上仓门","control");
+                      DTU_Write("%s",ctr_c);
+                      rt_free(ctr_c);
+                      rt_thread_delay(2000);
+                  }
+                  else if (strstr(type->valuestring,"down_m_open")!=RT_NULL)
+                  {
+                      LOG_I("远程打开下仓门!");
+                      device_status.ctr_down_motor = 1;
+                      char *ctr_c = makeJson_Warn("打开下仓门","control");
+                      DTU_Write("%s",ctr_c);
+                      rt_free(ctr_c);
+                      rt_thread_delay(2000);
+                  }
+                  else if (strstr(type->valuestring,"down_m_close")!=RT_NULL)
+                  {
+                      LOG_I("远程关闭下仓门!");
+                      device_status.ctr_down_motor = 2;
+                      char *ctr_c = makeJson_Warn("关闭下仓门","control");
+                      DTU_Write("%s",ctr_c);
+                      rt_free(ctr_c);
+                      rt_thread_delay(2000);
+                  }
+                  else if (strstr(type->valuestring,"heat_on")!=RT_NULL)
+                  {
+                      LOG_I("远程打开加热!");
+                      ctr_Heat(ON);
+                      char *ctr_c = makeJson_Warn("打开加热","control");
+                      DTU_Write("%s",ctr_c);
+                      rt_free(ctr_c);
+                      rt_thread_delay(2000);
+                  }
+                  else if (strstr(type->valuestring,"heat_off")!=RT_NULL)
+                  {
+                      LOG_I("远程关闭加热!");
+                      ctr_Heat(ON);
+                      char *ctr_c = makeJson_Warn("关闭加热","control");
+                      DTU_Write("%s",ctr_c);
+                      rt_free(ctr_c);
+                      rt_thread_delay(2000);
+                  }
+                  else if (strstr(type->valuestring,"clear_on")!=RT_NULL)
+                  {
+                      LOG_I("远程打开清扫!");
+                      device_status.clear_status = 1;
+                      char *ctr_c = makeJson_Warn("打开清扫","control");
+                      DTU_Write("%s",ctr_c);
+                      rt_free(ctr_c);
+                      rt_thread_delay(2000);
+                  }
+
+                  else if(strstr(type->valuestring,"selfcheck")!=RT_NULL)
+                  {
+                      if(device_status.selfcheck_ws == 2)
+                      {
+                          char *js = makeJson_C01_Warn(device_status.C01,device_status.process);
+                          DTU_Write("%s",js);
+                          free(js);
+                      }
+                      else
+                      {
+
+                          device_status.selfcheck_ws = 2;
+                      }
+                      LOG_I("收到自检指令:%d",device_status.selfcheck_ws);
+
+                  }
               }
               //切换平台
               else if (strstr(item_cmd->valuestring,"platform")!=RT_NULL)

+ 1 - 0
Application_CBD/applications/dtu_uart2.h

@@ -38,4 +38,5 @@ char *makeJson_Config_Reset(void);
 char *makeJson_Config_BDH(char * deviceId);
 char *makeJson_selfCheck_(uint8_t sta);
 char *makeJson_Cam(char * s,char *t);
+char *makeJson_C01_Warn(uint16_t code,double process);
 #endif /* APPLICATIONS_INC_DTU_UART2_H_ */

+ 55 - 2
Application_CBD/applications/hmi.c

@@ -310,8 +310,17 @@ static void HMI_Decode(void)
         }else if(atoi(device_status.gps)==2){
             HMI_WRITE("menu.gps_state.txt=\"定位成功:(基站)\"");
         }
+        if(device_status.sensor_485_sta==1)
+        {
+            HMI_WRITE("menu.sensor_state.txt=\"传感器已连接:(%s-%s)lux\"",device_status.lux,device_status.ap);
+        }
+        else
+        {
+            HMI_WRITE("menu.sensor_state.txt=\"传感器未连接\"");
+        }
         #endif
 
+
         //更新联网状态
         if(atoi(device_status.net)==1)
         {
@@ -1198,6 +1207,22 @@ static void HMI_Decode(void)
     else if (strstr(rx_buffer,"DebugDisable")!=NULL) {
         Debug_log_OFF();
     }
+    //高空-带拍照
+    else if (strstr(rx_buffer,"SwversionV12")!=NULL)
+    {
+        device_status.dtype = 3;
+        if(device_status.version_type != 12)
+        {
+            device_status.version_type = 12;
+            sprintf(device_status.driver, "%s",VERSION_GK);
+            ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type));        //版本类型
+            ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype));        //版本类型
+            MA_save();
+        }
+        else {
+
+        }
+    }
     //高空
     else if (strstr(rx_buffer,"SwversionV11")!=NULL)
     {
@@ -1230,6 +1255,19 @@ static void HMI_Decode(void)
 
         }
     }
+    //低端款
+    else if (strstr(rx_buffer,"SwversionV42")!=NULL) {
+        device_status.dtype = 3;
+        if(device_status.version_type != 42)
+        {
+            device_status.dtype = 3;
+            device_status.version_type = 42;
+            sprintf(device_status.driver, "%s",VERSION_HK_2000W);
+            ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type));        //版本类型
+            ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype));        //版本类型+
+            MA_save();
+        }
+    }
     //4.0
     else if (strstr(rx_buffer,"SwversionV41")!=NULL) {
         device_status.dtype = 3;
@@ -1398,7 +1436,18 @@ static void HMI_Decode(void)
         //开启超时定时器
         Start_timer_Uart2();
     }
-
+    else if(strstr(rx_buffer,"SelfCheck")!=NULL)
+    {
+        //校准屏幕的RTC
+        HMI_WRITE("rtc0=%d",tm.tm_year+1900);
+        HMI_WRITE("rtc1=%d",tm.tm_mon+1);
+        HMI_WRITE("rtc2=%d",tm.tm_mday);
+        HMI_WRITE("rtc3=%d",tm.tm_hour);
+        HMI_WRITE("rtc4=%d",tm.tm_min);
+        HMI_WRITE("rtc5=%d",tm.tm_sec);
+        device_status.selfcheck_ws = 2;
+        LOG_W("开始自检:%d",device_status.selfcheck_ws);
+    }
 }
 
 
@@ -1569,7 +1618,7 @@ static void Ctr_Mortor_entry(void* parameter)
             if(photo_led_sec==900)
                 ctr_led(ON);
             //打开补光灯
-            if(device_status.version_type==4&&photo_led_sec==800)
+            if((device_status.version_type==4||device_status.version_type==42)&&photo_led_sec==800)
             {
                 LOG_I("测试拍照!");
                 #if 1
@@ -1827,6 +1876,10 @@ static void Ctr_Mortor_entry(void* parameter)
             device_status.auto_test_sw=0;
             HMI_WRITE("sysTest.auto_flag.txt=\"\"");
         }
+        if(device_status.selfcheck_ws==2)
+        {
+            selfcheck(1);
+        }
         rt_thread_delay(100);
     }
 }

+ 18 - 4
Application_CBD/applications/sample_mb_master.c

@@ -80,7 +80,7 @@ static void send_thread_entry(void *parameter)
         }
         #endif
         if(device_status.sensor_485_sta!=200){
-            error_code = eMBMasterReqReadHoldingRegister(SLAVE_ADDR, MB_SEND_REG_START,2,1000);//读多个保持寄存器
+            error_code = eMBMasterReqReadHoldingRegister(SLAVE_ADDR, MB_SEND_REG_START,10,1000);//读多个保持寄存器
             rt_kprintf("eMBMasterReqReadHoldingRegister: %d \n",error_code);//一直出错,我便把错误返回值打印出来
             if(error_code==0)
             {
@@ -89,15 +89,28 @@ static void send_thread_entry(void *parameter)
                 //温度=25并且湿度=30不更新,否则会导致屏幕上显示空
     //            if((int)usMRegHoldBuf[0][0]/10!=25&&(int)usMRegHoldBuf[0][1]/10!=30)
     //            {
-                    rt_sprintf(device_status.tempture,"%d.%d",(int)usMRegHoldBuf[0][0]/100, (uint)usMRegHoldBuf[0][0] % 100);
-                    rt_sprintf(device_status.humidity,"%d.%d",(int)usMRegHoldBuf[0][1]/100, (uint)usMRegHoldBuf[0][1] % 100);
+//                    rt_sprintf(device_status.tempture,"%d.%d",(int)usMRegHoldBuf[0][0]/10, (uint)usMRegHoldBuf[0][0] % 10);
+//                    rt_sprintf(device_status.humidity,"%d.%d",(int)usMRegHoldBuf[0][1]/10, (uint)usMRegHoldBuf[0][1] % 10);
+//                    rt_sprintf(device_status.lux,"%d",((int)usMRegHoldBuf[0][2]*10+(int)usMRegHoldBuf[0][3]));
+//                    rt_kprintf("照度:%s Lux\n",device_status.lux);
+                    rt_kprintf("usMRegHoldBuf[0]:%d\n",(int)usMRegHoldBuf[0][0]);
+                    rt_kprintf("usMRegHoldBuf[1]:%d\n",(int)usMRegHoldBuf[0][1]);
+                    rt_kprintf("usMRegHoldBuf[2]:%d\n",(int)usMRegHoldBuf[0][2]);
+                    rt_kprintf("usMRegHoldBuf[3]:%d\n",(int)usMRegHoldBuf[0][3]);
+                    rt_kprintf("usMRegHoldBuf[4]:%d\n",(int)usMRegHoldBuf[0][4]);
+                    rt_kprintf("usMRegHoldBuf[5]:%d\n",(int)usMRegHoldBuf[0][5]);
+                    rt_kprintf("usMRegHoldBuf[6]:%d\n",(int)usMRegHoldBuf[0][6]);
+                    rt_sprintf(device_status.tempture,"%d.%d",(int)usMRegHoldBuf[0][2]/10, (uint)usMRegHoldBuf[0][2] % 10);
+                    rt_sprintf(device_status.humidity,"%d.%d",(int)usMRegHoldBuf[0][3]/10, (uint)usMRegHoldBuf[0][3] % 10);
+                    rt_sprintf(device_status.ap,"%d.%d",(int)usMRegHoldBuf[0][4]/10, (uint)usMRegHoldBuf[0][4] % 10); //    大气压
+                    rt_sprintf(device_status.lux,"%d",(int)usMRegHoldBuf[0][5]*10+(int)usMRegHoldBuf[0][6]); //    照度
+                    rt_kprintf("大气压:%s 照度:%s\n",device_status.ap,device_status.lux);//0代表从机ID=1
     //                sprintf(device_status.tempture,"%0.01f",(float)usMRegHoldBuf[0][0]/100);
     //                sprintf(device_status.humidity,"%0.01f",(float)usMRegHoldBuf[0][1]/100);
     //            }
                     //rt_thread_delay(1000);
             }
         }
-        rt_kprintf("slave data-tem:%d,hum:%d\n",usMRegHoldBuf[0][0],usMRegHoldBuf[0][1]);//0代表从机ID=1
         rt_kprintf("slave data-tem:%s,hum:%s\n",device_status.tempture,device_status.humidity);//0代表从机ID=1
         rt_thread_delay(5000);
         /* Record the number of errors */
@@ -108,6 +121,7 @@ static void send_thread_entry(void *parameter)
             {
                 error_count = 0;
                 device_status.sensor_485_sta = 0;
+                rt_sprintf(device_status.lux,"NA");
             }
         }
     }

+ 301 - 0
Application_CBD/applications/selfcheck.c

@@ -0,0 +1,301 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2024-12-04     Administrator       the first version
+ */
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2024-09-29     Administrator       the first version
+ */
+#include <rtthread.h>
+#include <cJSON.h>
+#include <control.h>
+#include "selfcheck.h"
+#include <hmi.h>
+#include <dtu_uart2.h>
+#define DBG_ENABLE
+#define DBG_COLOR
+#define DBG_TAG "selfcheck"
+#define DBG_LEVEL         DBG_LOG
+#include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
+
+
+rt_timer_t timer_takephoto = RT_NULL;
+Device_Status_typedef device_status;
+
+static int calculate_average(int arr[], int n) {
+    int sum = 0;  // 用于存储数组元素的总和
+    for (int i = 0; i < n; i++) {
+        sum += arr[i];  // 累加每个元素
+    }
+
+    // 计算平均值
+    int average = sum / n;  // 强制类型转换确保得到浮点数结果
+    return average;
+}
+
+static void t_takephoto_callback(void *parameter)
+{
+    device_status.C01 |= (1<<2);
+    device_status.C01 |= (1<<3);
+    HMI_WRITE("sysSet.va0.txt=\"拍照超时\"");
+    LOG_E("t_takephoto_callback");
+}
+
+int selfcheck(uint8_t type)
+{
+    uint16_t C01 = 0;
+    int current_i[6];
+    int current_,current_open = 0;
+    //删除workloop线程 防止自动运行干扰
+    LOG_I("删除线程workloop:%d",thread_delete_workloop());
+    //初始化硬件
+    HardWare_Init(0);
+    /********************************************************/
+    //读取5次电流值,取平均值
+    for(int i = 0;i<5;i++)
+    {
+        current_i[i] = atoi(device_status.power);
+        rt_thread_delay(1000);
+    }
+    current_ = calculate_average(current_i,5);
+    if(current_<50||current_>3000)
+    {
+        device_status.C01 |= (1<<12);
+        HMI_WRITE("selfcheck.t13.bco=63488");
+    }
+    else
+    {
+        HMI_WRITE("selfcheck.t13.bco=2024");
+        device_status.C01 &= ~(1<<12);
+    }
+    if(atoi(device_status.gps_state)==0)
+    {
+        HMI_WRITE("selfcheck.t12.bco=63488");
+        device_status.C01 |= (1<<11);
+    }
+    else {
+        HMI_WRITE("selfcheck.t12.bco=2024");
+        device_status.C01 &= ~(1<<11);
+    }
+    if(device_status.bat_status==0)
+    {
+        HMI_WRITE("selfcheck.t5.bco=2024");
+        device_status.C01 &= ~(1<<4);
+    }
+    else
+    {
+        HMI_WRITE("selfcheck.t5.bco=63488");
+        device_status.C01 |= (1<<4);
+    }
+    if(device_status.rain_status)
+    {
+        HMI_WRITE("selfcheck.t6.bco=63488");
+        device_status.C01 |= (1<<5);
+    }
+    else
+    {
+        device_status.C01 &= ~(1<<5);
+        HMI_WRITE("selfcheck.t6.bco=2024");
+    }
+
+    if(device_status.temp_status)
+    {
+        HMI_WRITE("selfcheck.t8.bco=63488");
+        device_status.C01 |= (1<<7);
+    }
+    else
+    {
+        device_status.C01 &= ~(1<<7);
+        HMI_WRITE("selfcheck.t8.bco=2024");
+    }
+
+    if(device_status.sun_status)
+    {
+        HMI_WRITE("selfcheck.t7.bco=63488");
+        device_status.C01 |= (1<<6);
+    }
+    else
+    {
+        device_status.C01 &= ~(1<<6);
+        HMI_WRITE("selfcheck.t7.bco=2024");
+    }
+
+    rt_thread_delay(1000);
+    /********************************************************/
+    ctr_lamp(ON, 1);        //打开镇流器
+    rt_thread_delay(1000);
+    for(int i = 0;i<5;i++)
+    {
+        current_i[i] = atoi(device_status.power);
+        rt_thread_delay(1000);
+    }
+    ctr_lamp(OFF, 1);       //关闭镇流器
+    current_open = calculate_average(current_i,5);
+    LOG_I("待机电流:%d",current_);
+    LOG_I("镇流器开启电流:%d",current_open);
+    if(current_open-current_>100)
+    {
+        HMI_WRITE("selfcheck.t1.bco=2024");
+        device_status.C01 &= ~(1<<0);
+        HMI_WRITE("sysSet.va0.txt=\"灯管正常\"");
+    }
+    else
+    {
+        HMI_WRITE("selfcheck.t1.bco=63488");
+        device_status.C01 |= (1<<0);
+        HMI_WRITE("sysSet.va0.txt=\"灯管异常\"");
+    }
+    rt_thread_delay(1000);
+    /********************************************************/
+    //打开上仓门
+    ctr_cangmen_up(OPEN);
+    for(int i = 0;i<5;i++)
+    {
+        current_i[i] = atoi(device_status.power);
+        rt_thread_delay(1000);
+    }
+    ctr_cangmen_up(OFF);
+    current_open = calculate_average(current_i,5);
+    if(current_open-current_>100)
+    {
+        HMI_WRITE("selfcheck.t9.bco=2024");
+        device_status.C01 &= ~(1<<8);
+        HMI_WRITE("sysSet.va0.txt=\"上仓门正常\"");
+    }
+    else{
+        HMI_WRITE("selfcheck.t9.bco=63488");
+        device_status.C01 |= (1<<8);
+        HMI_WRITE("sysSet.va0.txt=\"上仓门故障\"");
+    }
+    rt_thread_delay(1000);
+    /********************************************************/
+    //打开下仓门
+    ctr_cangmen_down(OPEN);
+    for(int i = 0;i<5;i++)
+    {
+        current_i[i] = atoi(device_status.power);
+        rt_thread_delay(1000);
+    }
+    ctr_cangmen_down(OFF);
+    current_open = calculate_average(current_i,5);
+    if(current_open-current_>100)
+    {
+        HMI_WRITE("selfcheck.t10.bco=2024");
+        device_status.C01 &= ~(1<<9);
+        HMI_WRITE("sysSet.va0.txt=\"下仓门正常\"");
+    }
+    else{
+        HMI_WRITE("selfcheck.t10.bco=63488");
+        device_status.C01 |= (1<<9);
+        HMI_WRITE("sysSet.va0.txt=\"下仓门故障\"");
+    }
+    rt_thread_delay(1000);
+    /********************************************************/
+    //记录当前电压、温度探头温度
+    float voltage_off = atof(device_status.voltage);
+    uint8_t heat_temp_off = device_status.heattem;
+    HMI_WRITE("sysSet.va0.txt=\"当前电压:%s-温度:%d\"",device_status.voltage,heat_temp_off);
+    //开启加热
+    rt_thread_delay(1000);
+    //温度大于50摄氏度小于150摄氏度证明加热已经工作了
+    if(voltage_off>50.0&&voltage_off<150.0)
+    {
+        HMI_WRITE("selfcheck.t2.bco=2024");
+        device_status.C01 &= ~(1<<1);
+        HMI_WRITE("sysSet.va0.txt=\"加热正常\"");
+    }
+    else {
+        ctr_Heat(ON);
+        //持续1分钟
+        for(int i = 60;i>0;i--)
+        {
+            HMI_WRITE("sysSet.va0.txt=\"加热测试中...%d\"",i);
+            rt_thread_delay(1000);
+        }
+        LOG_I("当前温度:%d电压:%s",device_status.heatvalue,device_status.voltage);
+        //比较当前电压、温度探头温度和开启前
+        if((device_status.heattem - heat_temp_off)>=2 || (atof(device_status.voltage) - voltage_off)>=1.5)
+        {
+            HMI_WRITE("selfcheck.t2.bco=2024");
+            device_status.C01 &= ~(1<<1);
+            HMI_WRITE("sysSet.va0.txt=\"加热正常\"");
+        }
+        else
+        {
+            HMI_WRITE("selfcheck.t2.bco=63488");
+            device_status.C01 |= (1<<1);
+            HMI_WRITE("sysSet.va0.txt=\"加热故障\"");
+        }
+    }
+    ctr_Heat(OFF);
+    rt_thread_delay(1000);
+    /*********************************************************/
+    HMI_WRITE("sysSet.va0.txt=\"开始拍照\"");
+    rt_timer_start(timer_takephoto);
+    HK_TakePhoto();
+    for(int i = 20;i>0;i--)
+    {
+        HMI_WRITE("sysSet.va0.txt=\"拍照中...%d\"",i);
+        rt_thread_delay(1000);
+    }
+    rt_thread_delay(1000);
+    /*******************************************************/
+    //清扫
+    device_status.clear_status = 1;
+    rt_thread_delay(2000);
+    for(int i = 0;i<5;i++)
+    {
+        current_i[i] = atoi(device_status.power);
+        rt_thread_delay(1000);
+    }
+    current_open = calculate_average(current_i,5);
+    rt_thread_delay(1000);
+    if(atoi(device_status.power)-current_open>150)
+    {
+        HMI_WRITE("selfcheck.t11.bco=2024");
+        device_status.C01 &= ~(1<<10);
+        HMI_WRITE("sysSet.va0.txt=\"清扫正常\"");
+    }
+    else
+    {
+        HMI_WRITE("selfcheck.t11.bco=63488");
+        device_status.C01 |= (1<<10);
+        HMI_WRITE("sysSet.va0.txt=\"清扫故障\"");
+    }
+    /*******************************************************/
+    HMI_WRITE("sysSet.va0.txt=\"故障码:%d\"",device_status.C01);
+    char *js = makeJson_C01_Warn(device_status.C01,1.0);
+    DTU_Write("%s",js);
+    free(js);
+    LOG_I("重启线程workloop:%d",thread_restart_workloop());
+    device_status.selfcheck_ws = 0;
+    device_status.process = 0.0;
+}
+
+int rt_software_timer_init(void)
+{
+    //启动拍照超时定时器
+    timer_takephoto = rt_timer_create("t_takephoto",t_takephoto_callback,RT_NULL, 100000, RT_TIMER_FLAG_ONE_SHOT);
+    if(timer_takephoto==RT_NULL)
+    {
+        LOG_E("rt_timer_create t_takephoto failed!");
+        return RT_ERROR;
+    }
+    else
+    {
+        return RT_EOK;
+    }
+}
+
+INIT_APP_EXPORT(rt_software_timer_init);
+

+ 34 - 0
Application_CBD/applications/selfcheck.h

@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2024-09-29     Administrator       the first version
+ */
+#ifndef APPLICATIONS_SELFCHECK_H_
+#define APPLICATIONS_SELFCHECK_H_
+
+extern rt_timer_t timer_takephoto;
+
+typedef struct _C_DEVICE_ERROR_INFO_
+{
+    uint8_t sta_lamp;
+    uint8_t sta_heat;
+    uint8_t sta_camera;
+    uint8_t sta_led;
+    uint8_t sta_bat;
+    uint8_t sta_rain;
+    uint8_t sta_light;
+    uint8_t sta_tempture;
+    uint8_t sta_motor_upper;
+    uint8_t sta_motor_lower;
+    uint8_t sta_motor_clear;
+    uint8_t sta_location;
+    uint8_t sta_rtu_communication;
+};
+
+int selfcheck(uint8_t type);
+
+#endif /* APPLICATIONS_SELFCHECK_H_ */

+ 62 - 6
Application_CBD/applications/sht30_collect.c

@@ -57,6 +57,56 @@ static rt_thread_t tid1 = RT_NULL;
 static rt_thread_t tid2 = RT_NULL;
 
 ADC_HandleTypeDef hadc1;
+
+
+// 定义滑动平均滤波器结构体
+typedef struct {
+    float* buffer;
+    int bufferSize;
+    int currentIndex;
+    float sum;
+} MovingAverageFilter;
+
+// 初始化滑动平均滤波器
+MovingAverageFilter* moving_average_filter_init(int size) {
+    MovingAverageFilter* filter = (MovingAverageFilter*)malloc(sizeof(MovingAverageFilter));
+    if (filter == NULL) {
+        return NULL;
+    }
+
+    filter->buffer = (float*)calloc(size, sizeof(float));
+    if (filter->buffer == NULL) {
+        free(filter);
+        return NULL;
+    }
+
+    filter->bufferSize = size;
+    filter->currentIndex = 0;
+    filter->sum = 0.0;
+
+    return filter;
+}
+
+
+// 更新滑动平均滤波器
+float moving_average_filter_update(MovingAverageFilter* filter, float newValue) {
+    filter->sum -= filter->buffer[filter->currentIndex];
+    filter->buffer[filter->currentIndex] = newValue;
+    filter->sum += newValue;
+    filter->currentIndex = (filter->currentIndex + 1) % filter->bufferSize;
+    return filter->sum / filter->bufferSize;
+}
+
+// 释放滑动平均滤波器资源
+void moving_average_filter_free(MovingAverageFilter* filter) {
+    if (filter != NULL) {
+        free(filter->buffer);
+        free(filter);
+    }
+}
+
+
+
 /*串口初始化*/
 int UART_485_INIT(void)
 {
@@ -151,9 +201,13 @@ static void Power_ReadCheck(void *parameter)
     int rain_cnt = 0;
     int bat_cnt = 0;
     int RV;
+    MovingAverageFilter* filter = moving_average_filter_init(10);
+    MovingAverageFilter* filter_v = moving_average_filter_init(10);
+    rt_thread_mdelay(1000);
     while(1)
     {
-        sprintf(device_status.power,"%.2f",(float)Read_Real_Current()/100*2.5);
+        //sprintf(device_status.power,"%.2f",(float)Read_Real_Current()/100*2.5);
+        sprintf(device_status.power,"%.2f",(float)(moving_average_filter_update(filter, (float)Read_Real_Current()/100*2.5))+20.0);
         if (Read_Real_Voltage()/100<12) {
                     //关闭外设
                     ctr_photo(OFF); //关闭相机供电
@@ -243,24 +297,26 @@ static void Power_ReadCheck(void *parameter)
                 rain_cnt++;
                 //雨控消抖,1分钟
                 LOG_D("rain_cnt:%d-value:%d",rain_cnt,Read_Rain_Voltage());
-                if(rain_cnt==60&&Read_Rain_Voltage()<1500)
+                if(rain_cnt==600&&Read_Rain_Voltage()<1500)
                 {
                     rain_cnt = 0;
                     device_status.rain_status = 0;
                 }
             }
         }
-        if(bat_cnt>=5){  //持续10s
+        if(bat_cnt>=15){  //持续10s
             bat_cnt = 0;
             device_status.bat_status = 1; //欠压
         }
         #if ROBOT_EN == 0
-        rt_sprintf(device_status.voltage,"%d.%02d",filter_voltage()/100,filter_voltage()%100);
+        sprintf(device_status.voltage,"%.2f",(float)(moving_average_filter_update(filter_v, (float)Read_Real_Voltage()/100)));
+        //rt_sprintf(device_status.voltage,"%d.%02d",filter_voltage()/100,filter_voltage()%100);
         //LOG_D("voltage is:%sV",device_status.voltage);
         sprintf(device_status.fuse_voltage, "%d.%02d",Read_Fuse_Voltage()/100,Read_Fuse_Voltage()%100);
         #endif
         rt_thread_mdelay(10);
     }
+    moving_average_filter_free(filter);
 }
 /*读取电流值*/
 int Read_Real_Current(void)
@@ -275,8 +331,8 @@ int Read_Real_Current(void)
     HAL_ADCEx_Calibration_Start(adc_dev->parent.user_data);
     rt_adc_enable(adc_dev, ADC_DEV_CHANNLE_1);
     //rt_adc_enable(adc_dev, 17);
-    adc1_value = filter_Mid(rt_adc_read(adc_dev, ADC_DEV_CHANNLE_1));
-    in_adc_17 = filter_Mid(rt_adc_read(adc_dev, 17));
+    adc1_value = rt_adc_read(adc_dev, ADC_DEV_CHANNLE_1);
+    in_adc_17 = rt_adc_read(adc_dev, 17);
     /* 关闭通道 */
     rt_adc_disable(adc_dev, ADC_DEV_CHANNLE_1);
     //rt_adc_disable(adc_dev, 17);

+ 10 - 1
Application_CBD/readme.md

@@ -1,4 +1,13 @@
-
+# 2024-12-04 更新说明
+#define VERSION_HK          "1.55.41(HK)"            //4.0海康-1200W
+#define VERSION_HK_2000W    "1.54.40(2000W)"         //4.0水稻/低端款
+#define VERSION_ZP          "1.46.1(ZP)"             //1.0转盘
+#define VERSION_GK          "1.42.1(GK)"             //1.0高空
+1. 定时重启RTU开启;
+2. 新增vtype:42为低端款测报灯;
+3. 默认低温保护-5改为5;
+4. 高考测报等增加温度湿度光照传感器,增加lux照度字段;
+5. 电流电压采集滤波算法更新为滑动滤波算法,原中位值平均滤波算法;
 
 # 2024-10-10 更新说明
 #define VERSION_HK          "1.54.41(HK)"       //4.0海康-1200W