zhunk il y a 9 mois
Parent
commit
af7b74ab85

+ 6 - 6
Application_cbd_apm32f1/applications/control.c

@@ -1097,7 +1097,7 @@ void calorstat(uint16_t heat_time)
     uint16_t delay_heat = 60;
     FlagStatus heat_flg = RESET;
     device_status.heat_time_min = 0;
-    device_status.run_sta = device_status.heattem;      //初始化加热实时温度
+    device_status.heat_tem_max = device_status.heattem;      //初始化加热实时温度
     ctr_Heat(ON);
 //    UpLoad_Data();      //开始加热时的第一条数据
     //恒温模式
@@ -1114,8 +1114,8 @@ void calorstat(uint16_t heat_time)
                 rt_kprintf("正在恒温加热!!!:%d",delay_heat);
                 HMI_WRITE("workSta.g0.txt=\"正在恒温加热!!!:%d\"",delay_heat);
                 rt_thread_delay(1000);
-                if(device_status.heattem>device_status.run_sta + 1){
-                    device_status.run_sta = device_status.heattem;
+                if(device_status.heattem>device_status.heat_tem_max + 1){
+                    device_status.heat_tem_max = device_status.heattem;
                 }
             }
             delay_heat = 60;
@@ -1124,11 +1124,11 @@ void calorstat(uint16_t heat_time)
         }
 
         if(device_status.heattem>device_status.run_sta + 1){
-            device_status.run_sta = device_status.heattem;
+            device_status.heat_tem_max = device_status.heattem;
         }
         if(device_status.heattem < (device_status.heatvalue - 5)&&heat_flg == SET)
         {
-            //device_status.run_sta = device_status.heattem;
+            device_status.heat_tem_max = device_status.heattem;
             ctr_Heat(ON);
         }
         else if (device_status.heattem>=device_status.heatvalue&&heat_flg==SET)
@@ -1138,7 +1138,7 @@ void calorstat(uint16_t heat_time)
 //                UpLoad_Data();      //加热到设定温度的数据
 //                heat_up_cnt = 1;
 //            }
-            //device_status.run_sta = device_status.heattem;
+            device_status.heat_tem_max = device_status.heattem;
             ctr_Heat(OFF);
         }
         if((n % 60)==0)

+ 3 - 1
Application_cbd_apm32f1/applications/control.h

@@ -38,7 +38,7 @@
 #else
     #define VERSION_HK          "2.6.41(HK)"            //4.0海康-1200W
     #if TG_MODULE == 0
-    #define VERSION_HK_2000W    "2.33.4(2000W)"         //4.0水稻
+    #define VERSION_HK_2000W    "2.34.4(2000W)"         //4.0水稻
     #else
     #define VERSION_HK_2000W    "2.6.4(TG)"             //推杆结构
     #endif
@@ -55,6 +55,7 @@ typedef struct  _packed
 {
     uint8_t iSave;           //存储标志位
     uint8_t dtype;           //设备类型?7-孢子仪,3-测报灯
+    uint8_t iFlag;           //参数标志位: 1异常,0正常
     /*孢子仪*/
     uint8_t run_sta;              //转盘的位置:0原始;1收集;2培养;3拍照;4凡士林,其他-测试
     uint8_t cul_time;             //培养时间
@@ -77,6 +78,7 @@ typedef struct  _packed
     uint8_t collecting_sh3;       //采集开启3
     uint8_t collecting_eh3;       //采集关闭3
     /*测报灯*/
+    uint8_t heat_tem_max;         //恒温加热达到的最大温度;
     uint8_t heat_sw;         //加热开关
     uint8_t photo_ws;        //拍照
     uint8_t power_status;    //电源

+ 261 - 4
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -253,7 +253,11 @@ int hasElementGreater_lessThan400(uint16_t arr[], int size) {
 /*入口函数-指令发送*/
 static void dtu_thread_entry_send(void *parameter)
 {
-
+    if(device_status.iFlag==0){
+        backup_param_to_rtu();
+    }else{
+        recover_param_from_rtu();
+    }
     device_status.power_status = 1;
     device_status.num_updata = 0;
     static uint16_t current_arry[10];
@@ -881,6 +885,251 @@ char* makeJsonRpc2_0(const char* method, cJSON* params, int id)
     return json_str;
 }
 
+void parse_param_to_mcu(cJSON* Params)
+{
+    if(Params!=NULL)
+    {
+        cJSON* value = NULL;
+        value = cJSON_GetObjectItem(Params,"reboot_time");
+        if(value!=NULL){
+            device_status.rebootcnt = value->valueint;
+            ef_set_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt));
+        }
+
+        value = cJSON_GetObjectItem(Params,"ds");
+        if(value!=NULL){
+            device_status.ds = value->valueint;
+            ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
+        }
+
+        value = cJSON_GetObjectItem(Params,"tt");
+        if(value!=NULL){
+            device_status.sunBar = value->valueint;
+            ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
+        }
+
+        value = cJSON_GetObjectItem(Params,"st");
+        if(value!=NULL){
+            device_status.startBar = value->valueint;
+            ef_set_env_blob("sunBar", &device_status.startBar, sizeof(device_status.startBar));
+        }
+
+        value = cJSON_GetObjectItem(Params,"et");
+        if(value!=NULL){
+            device_status.stopBar = value->valueint;
+            ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
+        }
+
+        value = cJSON_GetObjectItem(Params,"ts");
+        if(value!=NULL){
+            device_status.timeSwitch = value->valueint;
+            ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
+        }
+
+        value = cJSON_GetObjectItem(Params,"tpl");
+        if(value!=NULL){
+            device_status.tpl = value->valueint;
+            ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
+        }
+
+        value = cJSON_GetObjectItem(Params,"tph");
+        if(value!=NULL){
+            device_status.tph = value->valueint;
+            ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
+        }
+
+        value = cJSON_GetObjectItem(Params,"stime");
+        if(value!=NULL){
+            device_status.clt_time = value->valueint;
+            ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
+        }
+
+        value = cJSON_GetObjectItem(Params,"jtime");
+        if(value!=NULL){
+            device_status.heattime = value->valueint;
+            ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
+        }
+
+        value = cJSON_GetObjectItem(Params,"hrt");
+        if(value!=NULL){
+            device_status.heatvalue = value->valueint;
+            ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
+        }
+
+        value = cJSON_GetObjectItem(Params,"shake_sec");
+        if(value!=NULL){
+            device_status.shake_sec = value->valueint;
+            ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec));
+        }
+
+        value = cJSON_GetObjectItem(Params,"shake_ws");
+        if(value!=NULL){
+            device_status.shake_ws = value->valueint;
+            ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws));
+        }
+
+        value = cJSON_GetObjectItem(Params,"version_type");
+        if(value!=NULL){
+            device_status.version_type = value->valueint;
+            ef_set_env_blob("version_type", &device_status.version_type, sizeof(device_status.version_type));
+        }
+
+        value = cJSON_GetObjectItem(Params,"heat_sw");
+        if(value!=NULL){
+            device_status.heat_sw = value->valueint;
+            ef_set_env_blob("heat_sw", &device_status.heat_sw, sizeof(device_status.heat_sw));
+        }
+
+        value = cJSON_GetObjectItem(Params,"dattim");
+        if(value!=NULL){
+            device_status.dattim = value->valueint;
+            ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim));
+        }
+
+        value = cJSON_GetObjectItem(Params,"deviceId");
+        if(value!=NULL){
+            rt_snprintf(device_status.deviceId, sizeof(device_status.deviceId),"%s",value->string);
+            ef_set_env_blob("deviceId", &device_status.deviceId, sizeof(device_status.deviceId));
+        }
+
+        value = cJSON_GetObjectItem(Params,"handle_bugger");
+        if(value!=NULL){
+            device_status.handle_bugger = value->valueint;
+            ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
+        }
+
+    }else{
+        LOG_E("Params is NULL!");
+    }
+}
+
+//备份MCU参数到RTU
+void backup_param_to_rtu(void)
+{
+    cJSON* proot = cJSON_CreateObject();
+    if (proot == NULL) {
+        LOG_E("Error: Failed to create JSON object\n");
+        return;
+    }
+
+    // 添加开关机
+    if (!cJSON_AddNumberToObject(proot, "reboot_time", device_status.rebootcnt)) {
+        cJSON_Delete(proot);
+        return;
+    }
+
+    // 添加开关机
+    if (!cJSON_AddNumberToObject(proot, "ds", device_status.ds)) {
+        cJSON_Delete(proot);
+        return;
+    }
+    //光控定时时长
+    if (!cJSON_AddNumberToObject(proot, "tt", device_status.sunBar)) {
+        cJSON_Delete(proot);
+        return;
+    }
+    //时控开始时间
+    if (!cJSON_AddNumberToObject(proot, "st", device_status.startBar)) {
+        cJSON_Delete(proot);
+        return;
+    }
+    //时控结束时间
+    if (!cJSON_AddNumberToObject(proot, "et", device_status.stopBar)) {
+        cJSON_Delete(proot);
+        return;
+    }
+    //时控模式
+    if (!cJSON_AddNumberToObject(proot, "ts", device_status.timeSwitch)) {
+        cJSON_Delete(proot);
+        return;
+    }
+    //低温保护值
+    if (!cJSON_AddNumberToObject(proot, "tpl", device_status.tpl)) {
+        cJSON_Delete(proot);
+        return;
+    }
+    //高温保护值
+    if (!cJSON_AddNumberToObject(proot, "tph", device_status.tph)) {
+        cJSON_Delete(proot);
+        return;
+    }
+
+    //收集时间
+    if (!cJSON_AddNumberToObject(proot, "stime", device_status.clt_time)) {
+        cJSON_Delete(proot);
+        return;
+    }
+
+    //加热时间
+    if (!cJSON_AddNumberToObject(proot, "jtime", device_status.heattime)) {
+        cJSON_Delete(proot);
+        return;
+    }
+    //加热设定温度
+    if (!cJSON_AddNumberToObject(proot, "hrt", device_status.heatvalue)) {
+        cJSON_Delete(proot);
+        return;
+    }
+
+    //震动时间
+    if (!cJSON_AddNumberToObject(proot, "shake_sec", device_status.shake_sec)) {
+        cJSON_Delete(proot);
+        return;
+    }
+
+    //震动开关
+    if (!cJSON_AddNumberToObject(proot, "shake_ws", device_status.shake_ws)) {
+        cJSON_Delete(proot);
+        return;
+    }
+
+    //版本类型
+    if (!cJSON_AddNumberToObject(proot, "version_type", device_status.version_type)) {
+        cJSON_Delete(proot);
+        return;
+    }
+    //常加热开关
+    if (!cJSON_AddNumberToObject(proot, "heat_sw", device_status.heat_sw)) {
+        cJSON_Delete(proot);
+        return;
+    }
+    //上传间隔
+    if (!cJSON_AddNumberToObject(proot, "dattim", device_status.dattim)) {
+        cJSON_Delete(proot);
+        return;
+    }
+
+    //北大荒设备ID
+    if (!cJSON_AddStringToObject(proot, "deviceId", device_status.deviceId)) {
+        cJSON_Delete(proot);
+        return;
+    }
+
+    //handle_bugger
+    if (!cJSON_AddNumberToObject(proot, "handle_bugger", device_status.handle_bugger)) {
+        cJSON_Delete(proot);
+        return;
+    }
+
+
+    char* temp = makeJsonRpc2_0("sync_param", proot, 1);
+    if(temp){
+        DTU_Write(temp);
+        free(temp);
+    }
+    //cJSON_Delete(proot);
+}
+
+void recover_param_from_rtu(void)
+{
+    char* temp1 = makeJsonRpc2_0("recover_param", NULL, 1);
+    if(temp1){
+        DTU_Write(temp1);
+        rt_free(temp1);
+    }
+}
+
+
 /*生成JSON数据*/
 char * makeJson()
 {
@@ -1011,10 +1260,10 @@ char * makeJson()
         rt_sprintf(utos, "%d",device_status.down_status);
         cJSON_AddStringToObject(pSubJson,"dnds",utos);
         //加热仓温度
-        if(device_status.run_sta>device_status.heattem)
+        if(device_status.heat_tem_max>device_status.heattem)
         {
-            rt_sprintf(utos, "%d",device_status.run_sta);
-            device_status.run_sta = 0;
+            rt_sprintf(utos, "%d",device_status.heat_tem_max);
+            device_status.heat_tem_max = 0;
         }
         else {
             rt_sprintf(utos, "%d",device_status.heattem);
@@ -1285,6 +1534,14 @@ int parseDtu(char *json_string)
           cJSON* mqtt_data_record_TF_Max = cJSON_GetObjectItem(root,"mqtt_data_record_TF_Max");
           cJSON* picture_record_TF_Max = cJSON_GetObjectItem(root,"picture_record_TF_Max");
           if(JSONRPC!=NULL){
+              if(METHOD!=NULL){
+                  if(strcmp(METHOD->valuestring,"sync_param")==0){
+                      if(PARAMS!=NULL&&PARAMS->type==cJSON_Object){
+                          parse_param_to_mcu(PARAMS);
+                      }
+                  }
+
+              }
               if(RESULT!=NULL&&RESULT->type==cJSON_String)
               {
                   if(strcmp(RESULT->valuestring,"success")==0){

+ 3 - 0
Application_cbd_apm32f1/applications/dtu_uart2.h

@@ -79,4 +79,7 @@ char *makeJson_C01_Warn(uint16_t code,double process);
 char *makeJson_record_read(char *type);
 char *makeJson_record_write(char *mqtt_num,char *photo_num);
 char* makeJsonRpc2_0(const char* method, cJSON* params, int id);
+
+void backup_param_to_rtu(void);
+void recover_param_from_rtu(void);
 #endif /* APPLICATIONS_INC_DTU_UART2_H_ */

+ 2 - 0
Application_cbd_apm32f1/applications/hmi.c

@@ -1563,6 +1563,7 @@ void Check_ParamConfig(void)
     if(device_status.iSave!=FLASH_FLAG)
     {
         device_status.iSave=FLASH_FLAG;
+        device_status.iFlag = 1;
         /*设备类型,7孢子仪,3测报灯,默认设置测报灯*/
         device_status.dtype = 3;
         device_status.version_type = 4; //4.0
@@ -1650,6 +1651,7 @@ void Check_ParamConfig(void)
 
     }//从easyflash读取参数配置
     else if (device_status.iSave==FLASH_FLAG) {
+        device_status.iFlag = 0;
         ef_get_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype),NULL);                             //设备类型
         ef_get_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim),NULL);                          //数据上传间隔
         ef_get_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time), NULL);                    //收集时间

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

@@ -45,24 +45,24 @@ static const ef_env default_env_set[] = {
         {"stop_in_bootloader", "0"},
         {"reboot_time","0"},
         {"iSave","0xAA"},
-        {"dtype","3"},          //设备类型
-        {"startBar","20"},      //
-        {"stopBar","0"},        //
-        {"timeSwitch","1"}, //
-        {"sunBar","8"},     //
-        {"jtime","20"},     //加热时间
-        {"stime","20"},     //收集时间
-        {"jheat","110"},    //加热温度
-        {"thsp","300"},     //熄屏时间
-        {"tph","70"},       //高温保护
-        {"tpl","5"},        //低温保护
+        {"dtype","3"},       //设备类型
+        {"startBar","20"},   //
+        {"stopBar","0"},     //
+        {"timeSwitch","1"},  //
+        {"sunBar","8"},      //
+        {"jtime","20"},      //加热时间
+        {"stime","20"},      //收集时间
+        {"jheat","110"},     //加热温度
+        {"thsp","300"},      //熄屏时间
+        {"tph","70"},        //高温保护
+        {"tpl","5"},         //低温保护
         {"vol","30"},        //音量
         {"passWord","0"},    //屏幕密码
-        {"shake_sw","0"},   //震动开关
-        {"shake_sec","1"},  //震动时间
-        {"dattim","20"},    //数据上传间隔
+        {"shake_sw","0"},    //震动开关
+        {"shake_sec","1"},   //震动时间
+        {"dattim","20"},     //数据上传间隔
         {"update_flag","0"}, //升级
-        {"imei","0"},       //imei
+        {"imei","0"},        //imei
         {"lat","0"},
         {"lng","0"},
         {"iccid","012345678910"},   //iccid
@@ -70,7 +70,7 @@ static const ef_env default_env_set[] = {
         {"env_t","26"},       //温度
         {"env_h","50"},       //湿度
         {"version_type","0"}, //版本类型,1对应1.0,4对应HK
-        {"driver_bl","0"},//BL版本
+        {"driver_bl","0"},    //BL版本
         {"platform","8.136.98.49"},//平台
         {"driver_compile","0"},//BL编译时间
         {"json_w_clock","0"},
@@ -78,16 +78,16 @@ static const ef_env default_env_set[] = {
         {"json_w_platform","0"},
         {"run_sta","0"},    //孢子仪,运行状态
         {"cul_time","1"},   //孢子仪,培养时间
-        {"cold_sw","0"},    //
-        {"wind_sw","0"},    //
-        {"run_sta","0"},    //
+        {"cold_sw","0"},           //
+        {"wind_sw","0"},           //
+        {"run_sta","0"},           //
         {"collecting_sh1","0"},    //
         {"collecting_eh1","0"},    //
         {"collecting_sh2","0"},    //
         {"collecting_eh2","0"},    //
         {"Power_Type","0"},        //供电类型
         {"deviceId","0"},          //BDH设备编码
-        {"handle_bugger","0"},      //虫子处理,收虫,排虫
+        {"handle_bugger","0"},     //虫子处理,收虫,排虫
         {"heat_sw","0"}
 };
 static char log_buf[RT_CONSOLEBUF_SIZE];

+ 3 - 0
Application_cbd_apm32f1/readme.md

@@ -1,3 +1,6 @@
+# 2026-02-02 更新说明
+	"2.34.4(2000W)"
+	增加MCU参数备份到RTU中
 #define VERSION_HK_2000W    "2.33.4(2000W)"         //4.0水稻 
 	20260122
 	1. 修改定时重启RTU的方式,修改为软重启,发送重启指令超时20S没有收到恢复后执行硬重启,硬断电时间由10S修改为30S;