yf_zjb 2 лет назад
Родитель
Сommit
8ca3cde2a4

BIN
Application_CBD/Debug/Application_CBD.bin


BIN
Application_CBD/Debug/Application_CBD.elf


Разница между файлами не показана из-за своего большого размера
+ 1093 - 1086
Application_CBD/Debug/Application_CBD.map


BIN
Application_CBD/Debug/applications/beep.o


BIN
Application_CBD/Debug/applications/control.o


BIN
Application_CBD/Debug/applications/dtu_uart2.o


BIN
Application_CBD/Debug/applications/hmi.o


BIN
Application_CBD/Debug/applications/main.o


BIN
Application_CBD/Debug/applications/sample_mb_master.o


BIN
Application_CBD/Debug/applications/sht30_collect.o


BIN
Application_CBD/Debug/packages/EasyFlash-latest/src/ef_env.o


BIN
Application_CBD/Debug/packages/EasyFlash-latest/src/ef_fal_port.o


BIN
Application_CBD/Debug/packages/EasyFlash-latest/src/ef_log.o


BIN
Application_CBD/Debug/rt-thread/src/kservice.o


+ 6 - 1
Application_CBD/applications/control.c

@@ -1691,7 +1691,12 @@ void ResetInit(void)
                rt_thread_delay(1000);
            }
            //排虫
-           device_status.vol = 111;
+           if(device_status.handle_bugger==0){
+               device_status.run_sta = 111;
+           }else{
+               device_status.run_sta = 112;
+           }
+
     }
     else {
         if(device_status.power_status==1)

+ 8 - 5
Application_CBD/applications/control.h

@@ -26,7 +26,7 @@
 #else
     #define VERSION_HK          "1.51.41(HK)"       //4.0海康-1200W
 #endif
-#define VERSION_HK_2000W    "1.49.40(2000W)"         //4.0水稻
+#define VERSION_HK_2000W    "1.50.40(2000W)"         //4.0水稻
 #define VERSION_ZP          "1.44.1(ZP)"            //1.0转盘
 #define VERSION_GK          "1.40.1(GK)"            //1.0高空
 #define VERSION_XCT         "1.13.6(HK)"            //吸虫塔-海康
@@ -109,7 +109,9 @@ typedef struct  _packed
     uint8_t account_status;         //卡状态
     uint8_t test_flag;              //测试标志
     uint8_t sensor_485_sta;         //485传感器
-    uint8_t Power_Type;     //供电类型
+    uint8_t Power_Type;      //供电类型
+    uint8_t handle_bugger;   //排虫模式,0推杆收回来是排虫,1推出去是收虫
+    uint8_t collt_box_sta;   //收虫仓状态
     #if BOOT_ERR == 1
     uint8_t gps_inuse;
     uint8_t gps_view;
@@ -147,9 +149,10 @@ typedef struct  _packed
     char json_w_clock[128];    //修改时间
     char json_w_reset[128];    //
     char json_w_platform[128]; //
-    char power[8];               //功率
-    char voltage[8];             //电池电压
-    char deviceId[32];          //bdh-设备编码
+    char power[8];             //功率
+    char voltage[8];           //电池电压
+    char deviceId[32];         //bdh-设备编码
+    char voltage_sun[8];       //太阳能板电压
 }Device_Status_typedef;
 
 /************************************************/

+ 23 - 2
Application_CBD/applications/dtu_uart2.c

@@ -410,8 +410,29 @@ char * makeJson_takephoto()
     cJSON_Delete(takephoto);
     return takephoto_str;
 }
-
-char *makeJson_Config_BDH(char * deviceId){
+/*重置RTU配置参数*/
+char *makeJson_Config_Reset(void)
+{
+    cJSON * tJsonRoot = NULL;
+    tJsonRoot = cJSON_CreateObject();
+    if(NULL==tJsonRoot)
+    {
+        cJSON_Delete(tJsonRoot);
+        return NULL;
+    }
+    cJSON_AddStringToObject(tJsonRoot, "cmd", "config_reset");
+    char * t = cJSON_PrintUnformatted(tJsonRoot);
+    if(NULL == t)
+    {
+        cJSON_Delete(tJsonRoot);
+        return NULL;
+    }
+    cJSON_Delete(tJsonRoot);
+    return t;
+}
+/*设置北大荒设备编码到RTU*/
+char *makeJson_Config_BDH(char * deviceId)
+{
     cJSON * tJsonRoot = NULL;
     tJsonRoot = cJSON_CreateObject();
     if(NULL==tJsonRoot)

+ 3 - 1
Application_CBD/applications/dtu_uart2.h

@@ -33,5 +33,7 @@ char *makeJson_ReadInfo();
 char *makeJson_takephoto();
 char *makeJson_Warn(char * s,char *t);
 void UpLoad_Data(void);
-char * uint8tostring(uint8_t dat);
+char *uint8tostring(uint8_t dat);
+char *makeJson_Config_Reset(void);
+char *makeJson_Config_BDH(char * deviceId);
 #endif /* APPLICATIONS_INC_DTU_UART2_H_ */

+ 88 - 19
Application_CBD/applications/hmi.c

@@ -128,6 +128,10 @@ static void Hmi_thread_entry(void *parameter)
     struct rx_msg msg;
     rt_err_t result;
     rt_uint32_t rx_length;
+    if(device_status.dtype==3){
+        device_status.collt_box_sta = 0;
+        device_status.run_sta = 0;
+    }
     while(1)
     {
 
@@ -648,13 +652,40 @@ static void HMI_Decode(void)
         }
 
     }
+    else if(strstr(rx_buffer,"putTest.Testpaichong")!=NULL){
+        if(device_status.collt_box_sta==0){
+            device_status.collt_box_sta = 111;
+        }else{
+            HMI_WRITE("sysTest.result.txt=\"请等待当前执行完成再进行操作\"");
+        }
+        LOG_I("排虫测试!");
+    }
     //排虫
     else if(strstr(rx_buffer,"putTest.paichong")!=NULL){
-        device_status.vol = 111;
+        if(device_status.run_sta == 0){
+            device_status.run_sta = 111;
+        }else{
+            HMI_WRITE("sysTest.result.txt=\"请等待当前执行完成再进行操作\"");
+        }
+
         LOG_I("开始排虫!");
+        device_status.handle_bugger = 0;
+        ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
+    }
+    else if(strstr(rx_buffer,"putTest.shouchong")!=NULL){
+        if(device_status.run_sta == 0){
+            device_status.run_sta = 112;
+        }else{
+            HMI_WRITE("sysTest.result.txt=\"请等待当前执行完成再进行操作\"");
+        }
+
+        LOG_I("开始收虫!");
+        device_status.handle_bugger = 1;
+        ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
     }
     //设备编码设置
-    else if (strstr(rx_buffer,"deviceId=")!=NULL) {
+    else if (strstr(rx_buffer,"deviceId=")!=NULL)
+    {
         char value_str[20];
         memset(value_str,0,sizeof(value_str));
         LOG_I("设备编码 长度:%d",strlen(rx_buffer));
@@ -665,13 +696,21 @@ static void HMI_Decode(void)
         var = strstr(rx_buffer,"=");
         var ++;
         strncpy(value_str,var,16);  //设备编码为16位
-        rt_sprintf(device_status.deviceId,"%s",value_str);
-        ef_set_env_blob("deviceId", &device_status.deviceId, sizeof(device_status.deviceId));
-        LOG_I("解析到设备编码:%s",device_status.deviceId);
-        char *device_id = makeJson_Config_BDH(device_status.deviceId);
-        //发送json到RTU
-        DTU_Write("%s",device_id);
-        rt_free(device_id);
+        if(strstr(value_str,"0000000000000000")!=RT_NULL){
+            char *config_reset = makeJson_Config_Reset();
+            //发送json到RTU
+            DTU_Write("%s",config_reset);
+            rt_free(config_reset);
+            //恢复RTU的默认配置参数
+        }else{
+            rt_sprintf(device_status.deviceId,"%s",value_str);
+            ef_set_env_blob("deviceId", &device_status.deviceId, sizeof(device_status.deviceId));
+            LOG_I("解析到设备编码:%s",device_status.deviceId);
+            char *device_id = makeJson_Config_BDH(device_status.deviceId);
+            //发送json到RTU
+            DTU_Write("%s",device_id);
+            rt_free(device_id);
+        }
     }
     //定时设置
     else if (strstr(rx_buffer,"saveClockSet=")!=NULL) {
@@ -1527,7 +1566,8 @@ static void Ctr_Mortor_entry(void* parameter)
         {
             ctr_Petroleum_jelly(10);
         }
-        if(device_status.vol==111){
+
+        if(device_status.collt_box_sta==111){
             ctr_Fan_IN(ON);   //推杆电机收缩(供电打开,复位)
             num_tg_init--;
             if(num_tg_init%10==0)
@@ -1536,28 +1576,51 @@ static void Ctr_Mortor_entry(void* parameter)
                 HMI_WRITE("sysTest.result.txt=\"排虫复位完成\"");
                 ctr_Fan_PUT(ON);
                 num_tg_init = 200;
-                device_status.vol=112;
+                device_status.collt_box_sta=112;
             }
-        }else if(device_status.vol==112){
+        }else if(device_status.collt_box_sta==112){
             num_tg_open--;
             if(num_tg_open%10==0)
-                            HMI_WRITE("sysTest.result.txt=\"开始执行排虫:%d\"",num_tg_open/10);
+                HMI_WRITE("sysTest.result.txt=\"开始执行排虫:%d\"",num_tg_open/10);
             if(num_tg_open==0){
                 HMI_WRITE("sysTest.result.txt=\"排虫复位中\"");
                 ctr_Fan_PUT(OFF);
                 num_tg_open = 200;
-                device_status.vol=113;
+                device_status.collt_box_sta=113;
             }
-        }else if(device_status.vol==113){
+        }else if(device_status.collt_box_sta==113){
             num_tg_init--;
             if(num_tg_init%10==0)
-                            HMI_WRITE("sysTest.result.txt=\"排虫复位中:%d\"",num_tg_init/10);
+                HMI_WRITE("sysTest.result.txt=\"排虫复位中:%d\"",num_tg_init/10);
             if(num_tg_init==0){
                 HMI_WRITE("sysTest.result.txt=\"排虫机执行已完成!\"");
                 ctr_Fan_PUT(OFF);
                 ctr_Fan_IN(OFF);
                 num_tg_init = 200;
-                device_status.vol=0;
+                device_status.collt_box_sta=0;
+            }
+        }
+
+        if(device_status.run_sta==111){//收虫
+            ctr_Fan_IN(ON);   //推杆电机收缩(供电打开,复位)
+            num_tg_init--;
+            if(num_tg_init%10==0)
+                HMI_WRITE("sysTest.result.txt=\"排虫复位中:%d\"",num_tg_init/10);
+            if(num_tg_init==0){
+                HMI_WRITE("sysTest.result.txt=\"排虫复位完成\"");
+                ctr_Fan_IN(OFF);
+                num_tg_init = 200;
+            }
+        }else if(device_status.run_sta==112){
+            ctr_Fan_PUT(ON);
+            num_tg_open--;
+            if(num_tg_open%10==0)
+                            HMI_WRITE("sysTest.result.txt=\"开始执行排虫:%d\"",num_tg_open/10);
+            if(num_tg_open==0){
+                HMI_WRITE("sysTest.result.txt=\"排虫中...\"");
+                ctr_Fan_PUT(OFF);
+                num_tg_open = 200;
+                device_status.run_sta=0;
             }
         }
 
@@ -1746,7 +1809,7 @@ void Check_ParamConfig(void)
         device_status.heat_sw =0;
         device_status.cul_time = 1;
         device_status.run_sta = 0;
-
+        device_status.handle_bugger = 0;    //默认排虫
         sprintf(device_status.driver, "%s",VERSION_HK);
         sprintf(device_status.deviceId,"0");
         rt_sprintf(device_status.tempture, "-15");
@@ -1782,6 +1845,7 @@ void Check_ParamConfig(void)
         ef_set_env_blob("collecting_eh2",&device_status.collecting_eh2,sizeof(device_status.collecting_eh2));        //采集时间
         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));
 
         LOG_I("SOFTWARE VERSION:%s",device_status.driver);
         LOG_I("Default paramconf is:");
@@ -1838,6 +1902,7 @@ void Check_ParamConfig(void)
         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);                    //设备编码
+        ef_get_env_blob("handle_bugger",&device_status.handle_bugger,sizeof(device_status.handle_bugger),NULL);     //排虫
         device_status.light_over_tim = device_status.sunBar * 3600;                                                 //光控计数
         device_status.work_done = 0;
         //工作完成标志位
@@ -1928,6 +1993,7 @@ void Check_ParamConfig(void)
         LOG_I("孢子仪采集时间:[%d-%d,%d-%d]",device_status.collecting_sh1,device_status.collecting_eh1,device_status.collecting_sh2,device_status.collecting_eh2);
         LOG_I("PowerType:%d",device_status.Power_Type);
         LOG_I("deviceId:%s",device_status.deviceId);
+        LOG_I("handle_bugger:%d",device_status.handle_bugger);
     }
     //RTC时间判断,如果当前年份小于2020,提示需要设置时间,切换为光控
     if(device_status.update_flag==1)
@@ -2047,7 +2113,8 @@ void ResetParamDefault(void)
         ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
         ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws));       //震动开关
         ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec));    //震动时间
-
+        device_status.handle_bugger = 0;
+        ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
     }
     else if(device_status.dtype==7)
     {
@@ -2094,6 +2161,8 @@ void ResetParamDefault_DC(void)
     device_status.passWord = 8888;
     device_status.timeSwitch = 0;
     device_status.Power_Type = 0;
+    device_status.handle_bugger = 0;
+    ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
     ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
     ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
     ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));

+ 25 - 1
Application_CBD/applications/sample_mb_master.c

@@ -40,6 +40,7 @@ extern SHORT usMRegHoldBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_REG_HOLDING_NREGS];
 
 static void send_thread_entry(void *parameter)
 {
+    BOOL IN_3A = 0;           //数据解析方式设置
     eMBMasterReqErrCode error_code = MB_MRE_NO_ERR;
     rt_uint16_t error_count = 0;
     //USHORT data[3] = {0};
@@ -54,8 +55,9 @@ static void send_thread_entry(void *parameter)
 //                                                              MB_SEND_REG_NUM,     /* register total number */
 //                                                              data,                /* data to be written */
 //                                                              RT_WAITING_FOREVER); /* timeout */
+        #if 1
         error_code = eMBMasterReqReadHoldingRegister(SLAVE_ADDR, MB_SEND_REG_START,2,1000);//读多个保持寄存器
-        rt_kprintf("error_code: %d \n",error_code);//一直出错,我便把错误返回值打印出来
+        rt_kprintf("eMBMasterReqReadHoldingRegister: %d \n",error_code);//一直出错,我便把错误返回值打印出来
         if(error_code==0)
         {
             device_status.sensor_485_sta = 100;
@@ -69,6 +71,27 @@ static void send_thread_entry(void *parameter)
 //                sprintf(device_status.humidity,"%0.01f",(float)usMRegHoldBuf[0][1]/100);
 //            }
         }
+        rt_thread_delay(1000);
+        #endif
+
+        #if 0
+        error_code = eMBMasterReqReadInputRegister(SLAVE_ADDR, MB_SEND_REG_START,3,1000);
+        rt_kprintf("eMBMasterReqReadInputRegister: %d \n",error_code);//一直出错,把错误返回值打印出来
+        if(error_code==0)
+        {
+            if(IN_3A==0){
+                error_code = eMBMasterReqWriteHoldingRegister(0,0x3A,1,1000);
+                IN_3A = 1;
+                rt_kprintf("数据解析方式设置:%d\n",error_code);
+            }
+            device_status.sensor_485_sta = 200;
+            error_count = 0;
+            for(int i=0;i<3;i++){
+                rt_kprintf("usMRegInBuf:%d-%u\n",i,usMRegInBuf[0][i]);
+            }
+            rt_sprintf(device_status.voltage_sun,"%d.%1d",usMRegInBuf[0][0]/100,usMRegInBuf[0][0]%100);
+        }
+        #endif
         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);
@@ -80,6 +103,7 @@ static void send_thread_entry(void *parameter)
             {
                 error_count = 0;
                 device_status.sensor_485_sta = 0;
+
             }
         }
     }

+ 1 - 1
Application_CBD/packages/EasyFlash-latest/inc/ef_cfg.h

@@ -92,7 +92,7 @@
 #define EF_START_ADDR             PKG_EASYFLASH_START_ADDR
 
 /* ENV area size. It's at least one empty sector for GC. So it's definition must more then or equal 2 flash sector size. */
-#define ENV_AREA_SIZE             (EF_ERASE_MIN_SIZE * 2) /* default is the double erase min size */
+#define ENV_AREA_SIZE             (EF_ERASE_MIN_SIZE * 16) /* default is the double erase min size */
 
 /* print debug information of flash */
 #ifdef PKG_EASYFLASH_DEBUG

+ 4 - 4
Application_CBD/packages/EasyFlash-latest/src/ef_env.c

@@ -61,7 +61,7 @@
 
 /* the total remain empty sector threshold before GC */
 #ifndef EF_GC_EMPTY_SEC_THRESHOLD
-#define EF_GC_EMPTY_SEC_THRESHOLD                1
+#define EF_GC_EMPTY_SEC_THRESHOLD                2
 #endif
 
 /* the ENV cache table size, it will improve ENV search speed when using cache */
@@ -507,7 +507,7 @@ static uint32_t get_next_env_addr(sector_meta_data_t sector, env_node_obj_t pre_
             addr = find_next_env_addr(addr, sector->addr + SECTOR_SIZE - SECTOR_HDR_DATA_SIZE);
 
             if (addr > sector->addr + SECTOR_SIZE || pre_env->len == 0) {
-                //TODO 扇区连续模式
+                //TODO 锟斤拷锟斤拷锟斤拷锟斤拷模式
                 return FAILED_ADDR;
             }
         } else {
@@ -542,7 +542,7 @@ static EfErrCode read_env(env_node_obj_t env)
         env->crc_is_ok = false;
         return EF_READ_ERR;
     } else if (env->len > SECTOR_SIZE - SECTOR_HDR_DATA_SIZE && env->len < ENV_AREA_SIZE) {
-        //TODO 扇区连续模式,或者写入长度没有写入完整
+        //TODO 锟斤拷锟斤拷锟斤拷锟斤拷模式锟斤拷锟斤拷锟斤拷写锟诫长锟斤拷没锟斤拷写锟斤拷锟斤拷锟斤拷
         EF_ASSERT(0);
     }
 
@@ -1726,7 +1726,7 @@ static bool check_and_recovery_env_cb(env_node_obj_t env, void *arg1, void *arg2
     } else if (env->status == ENV_PRE_WRITE) {
         uint8_t status_table[ENV_STATUS_TABLE_SIZE];
         /* the ENV has not write finish, change the status to error */
-        //TODO 绘制异常处理的状态装换图
+        //TODO �����쳣�����״̬װ��ͼ
         write_status(env->addr.start, status_table, ENV_STATUS_NUM, ENV_ERR_HDR);
         return true;
     }

+ 3 - 2
Application_CBD/packages/EasyFlash-latest/src/ef_fal_port.c

@@ -85,8 +85,9 @@ static const ef_env default_env_set[] = {
         {"collecting_eh1","0"},    //
         {"collecting_sh2","0"},    //
         {"collecting_eh2","0"},    //
-        {"Power_Type","0"},
-        {"deviceId","0"}
+        {"Power_Type","0"},        //供电类型
+        {"deviceId","0"},          //BDH设备编码
+        {"handle_bugger","0"}      //虫子处理,收虫,排虫
 };
 static char log_buf[RT_CONSOLEBUF_SIZE];
 static struct rt_semaphore env_cache_lock;

+ 6 - 1
Application_CBD/readme.md

@@ -1,4 +1,9 @@
-# 2021-06-13  更新说明
+# 2024-06-19 更新说明	版本变更为:1.50.40(2000W)
+1. 增加485采集太阳能板电压;
+2. 增加重置RTU参数;
+3. 接虫模式实现方式调整,0-排虫,1收虫,
+	初始化过程执行
+# 2024-06-13  更新说明
 1. 增加北大荒设备编码录入功能,版本变更为:1.49.40(2000W)
 # 2024-05-20 更新说明
 1. 欠压检测消抖,10s