zhunk hai 8 meses
pai
achega
2c8673cc45

+ 36 - 4
Application_cbd_apm32f1/applications/control.c

@@ -108,14 +108,16 @@ void ctr_router(uint8_t status_router)
 void ctr_hmi_5v(uint8_t sw)
 {
     rt_pin_mode(POWER_5V, PIN_MODE_OUTPUT);
-
+    rt_pin_mode(SIGNAL_OUTPUT_LED, PIN_MODE_OUTPUT);
     if(sw==ON)
     {
         rt_pin_write(POWER_5V,ON);
+        rt_pin_write(SIGNAL_OUTPUT_LED,OFF);
         LOG_W("打开5V电源!");
     }
     else {
         rt_pin_write(POWER_5V,OFF);
+        rt_pin_write(SIGNAL_OUTPUT_LED,ON);
         LOG_W("关闭5V电源!");
     }
 }
@@ -179,7 +181,7 @@ void ResetInit(void)
     //1.打开路由器供电
     ctr_router(ON);
     //2. 打开RTU供电
-    ctr_RTU_12V(ON);
+    //ctr_RTU_12V(ON);
     //3.打开光栅供电
     ctr_led(OFF);
     ctr_gaoya_12v(OFF);
@@ -286,6 +288,25 @@ void guanshan_on(void *args)
     //rt_event_send(event_485_play, 0x01);
 }
 
+void button_on(void *args)
+{
+    LOG_W("button_on!");
+    if(device_status.sleep_mode==1) ctr_RTU_12V(ON);
+    ctr_hmi_5v(ON);
+    //rt_event_send(event_485_play, 0x01);
+}
+
+void pin_button_bind(void)
+{
+   LOG_W("pin_button_bind");
+    /* PA11引脚为输入模式 */
+   rt_pin_mode(SIGNAL_INPUT_KEY, PIN_MODE_INPUT);
+   /* 绑定中断,上升沿沿模式,回调函数名为guanshan_on */
+   rt_pin_attach_irq(SIGNAL_INPUT_KEY, PIN_IRQ_MODE_FALLING, button_on, RT_NULL);
+   /* 使能中断 */
+   rt_pin_irq_enable(SIGNAL_INPUT_KEY, PIN_IRQ_ENABLE);
+}
+
 
 void pin_guangshan_bind(void)
 {
@@ -336,11 +357,21 @@ void WorkTask_XYV3(void)
             }
             if(cal_n%2==0)    //每隔2S钟高压通电5S
             {
-                ctr_router(ON);
-                ctr_RTU_12V(ON);
+//                ctr_router(ON);
+//                ctr_RTU_12V(ON);
                 ctr_gaoya_12v(ON);
                 gaoya_on = 1;
             }
+            if(device_status.sleep_mode==1){
+                if(cal_n==100){
+                    ctr_RTU_12V(ON);
+                    ctr_hmi_5v(ON);
+                }
+                else if (cal_n==3400) {
+                    ctr_RTU_12V(OFF);
+                    ctr_hmi_5v(OFF);
+                }
+            }
             if(gaoya_on){
                 gaoya_on_sec++;
                 if(gaoya_on_sec>5){
@@ -373,6 +404,7 @@ static void Work_Loop_thread_entry(void *parameter)
 {
     rt_thread_delay(1000);
     ResetInit();
+    pin_button_bind();
     while(1)
     {
         WorkTask_XYV3();

+ 4 - 2
Application_cbd_apm32f1/applications/control.h

@@ -20,7 +20,7 @@
 
 ////////////////////////////////////////////////////////////////
 
-#define VERSION  "3.1.3"
+#define VERSION  "3.3.3"
 
 extern rt_event_t event_485_play;
 
@@ -171,7 +171,7 @@ typedef struct  _packed
 //高压12V
 #define GAOYA_12V GET_PIN(B,11)
 //路由器12V
-#define FourFaith_12V GET_PIN(A,8)
+#define FourFaith_12V GET_PIN(B,10)
 //RTU12V
 #define RTU_12V GET_PIN(A,8)
 
@@ -179,6 +179,8 @@ typedef struct  _packed
 #define DC_M2 GET_PIN(C,7)
 
 #define SIGNAL_GuangShan GET_PIN(B,5)
+#define SIGNAL_INPUT_KEY GET_PIN(A,11)
+#define SIGNAL_OUTPUT_LED GET_PIN(A,12)
 #define RAIN_POWER GET_PIN(B,8)
 #define LIMIT_FB GET_PIN(B,9)
 /***************************************************************/

+ 64 - 32
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -63,6 +63,29 @@ static uint8_t makejson_sta = 0;
 
 extern eMBMasterReqErrCode _485_play(USHORT *Buffer,USHORT NREGS);
 
+// 昆虫名称查找表
+const char* insect_names[] = {
+    "玉米黏虫",      // CORN_ARMYWORM       0
+    "草地贪夜蛾",          // FALL_WARM      1
+    "棉铃虫",    // COTTON_BOLLWORM            2
+    "玉米螟",         // CORN_BORER            3
+    "桃蛀螟",        // PEACH_BORER            4
+    "小地老虎",      // BLACK_CUTWORM           5
+    "黄地老虎",     // YELLOW_CUTWORM           6
+    "燕青地老虎",            // CUTWORM          7
+    "点蜂缘蝽",         // COREID_BUG           8
+    "豆荚螟",          // POD_BORER            9
+    "大豆食心虫",  // SOYBEAN_POD_BORER          10
+    "棉铃虫",           // BOLLWORM            11
+    "斜纹夜蛾",           // LEAFWORM           12
+    "甜菜夜蛾",      // BEET_ARMYWORM           13
+    "二化螟",    // RICE_STEM_BORER            14
+    "稻纵卷叶螟",   // RICE_LEAF_ROLLER         15
+    "大螟",    // PINK_RICE_BORER             16
+    "三化螟"   // YELLOW_RICE_BORER            17
+};
+
+
 static int DTU_uart2_init(void)
 {
     dtuserial  = rt_device_find(DTU_UART_NAME);
@@ -246,15 +269,19 @@ static void dtu_thread_entry_send(void *parameter)
                 {
                     HMI_WRITE("sleep=%d",1);
                 }
-//                if(device_status.sleep_mode == 1) {
-//                    LOG_I("启动联网模块剩余:%d -120",device_status.num_updata);
-//                    if(device_status.num_updata==120&&device_status.work_status==0)
-//                    {
-//                        device_status.dattim = 120;     //省电,设置上传间隔为2H
-//                        ctr_router(ON);
-//                        ctr_RTU_DTU(ON);
-//                    }
-//                }
+                if(device_status.sleep_mode == 1) {
+                    LOG_I("启动联网模块剩余:%d -120",device_status.num_updata);
+                    if(device_status.num_updata==120&&device_status.work_status==0)
+                    {
+                        device_status.dattim = 60;     //省电,设置上传间隔为1H
+                        ctr_RTU_12V(ON);
+                        ctr_hmi_5v(ON);
+                    }
+                    if(device_status.num_updata==3420&&device_status.work_status==0){
+                        ctr_RTU_12V(OFF);
+                        ctr_hmi_5v(OFF);
+                    }
+                }
             }
             else {
                 char *readinfo =  makeJson_ReadInfo();
@@ -268,12 +295,12 @@ static void dtu_thread_entry_send(void *parameter)
         }
     else {
             wait_i ++;
-//            if(device_status.sleep_mode == 1){
-//                if(wait_i==3500){
-//                    ctr_router(ON);
-//                    ctr_RTU_DTU(ON);
-//                }
-//            }
+            if(device_status.sleep_mode == 1){
+                if(wait_i==3500){
+                    ctr_RTU_12V(ON);
+                    ctr_hmi_5v(ON);
+                }
+            }
             LOG_I("wait connect internet......%d",wait_i);
         }
         rt_thread_mdelay(1000);
@@ -767,7 +794,8 @@ char * makeJson()
     cJSON_AddStringToObject(pSubJson,"lat",device_status.lat);
     //是否为上电开机
     cJSON_AddNumberToObject(pSubJson,"rcnt",device_status.rebootcnt);
-
+    //诱芯名称/昆虫种类
+    cJSON_AddStringToObject(pSubJson,"lurecore",insect_names[device_status.InsectSpecies]);
     //数据上传间隔
     rt_sprintf(utos, "%d",device_status.dattim);
     cJSON_AddStringToObject(pSubJson,"dat_f",utos);
@@ -1017,24 +1045,18 @@ int parseDtu(char *json_string)
                   {
                       ctr_hmi_5v(OFF);
                   }
-                  //{"ext": {"type": "sleep_mode"}, "cmd": "ctrl"}
+                  //{"ext": {"type": "sleep_mode","value": 0}, "cmd": "ctrl"}
                   else if(strstr(type->valuestring,"sleep_mode")!=RT_NULL)
                   {
-                      device_status.sleep_mode = 1;
-                      ef_set_env_blob("sleep_mode", &device_status.sleep_mode, sizeof(device_status.sleep_mode));      //
-                      LOG_I("收到设置休眠指令:%d",device_status.sleep_mode);
-                      char *sleep = makeJson_Warn("set sleep mode enable","control");
-                      DTU_Write("%s",sleep);
-                      rt_free(sleep);
-                  }
-                  else if(strstr(type->valuestring,"sleep_off")!=RT_NULL)
-                  {
-                      device_status.sleep_mode = 0;
-                      ef_set_env_blob("sleep_mode", &device_status.sleep_mode, sizeof(device_status.sleep_mode));      //
-                      LOG_I("收到设置休眠指令:%d",device_status.sleep_mode);
-                      char *sleep = makeJson_Warn("set sleep mode disable","control");
-                      DTU_Write("%s",sleep);
-                      rt_free(sleep);
+                      cJSON* value_commn = cJSON_GetObjectItem(item_ext,"value");
+                      if(value_commn!=RT_NULL){
+                          device_status.sleep_mode = value_commn->valueint;
+                          ef_set_env_blob("sleep_mode", &device_status.sleep_mode, sizeof(device_status.sleep_mode));      //
+                          LOG_I("收到设置休眠指令:%d",device_status.sleep_mode);
+                          char *sleep = makeJson_Warn("set sleep mode enable","control");
+                          DTU_Write("%s",sleep);
+                          rt_free(sleep);
+                      }
                   }
                   //{"ext": {"type": "clear"}, "cmd": "ctrl"}
                   else if(strstr(type->valuestring,"clear")!=RT_NULL)
@@ -1409,6 +1431,7 @@ int parseDtu(char *json_string)
                   cJSON *data_tim = cJSON_GetObjectItem(item_ext,"data_tim");
                   cJSON *power = cJSON_GetObjectItem(item_ext,"power");
                   cJSON *clt_tim = cJSON_GetObjectItem(item_ext,"clt_tim");
+                  cJSON *lurecore = cJSON_GetObjectItem(item_ext,"lurecore");
 
                   if(device_status.dtype==3)
                   hst = cJSON_GetObjectItem(item_ext,"hst");
@@ -1440,6 +1463,15 @@ int parseDtu(char *json_string)
 
                   cJSON* cul_time = cJSON_GetObjectItem(item_ext,"cul_time");   //培养时间1~24
                   cJSON* drop_sec = cJSON_GetObjectItem(item_ext,"drop_time");
+
+                  if(lurecore!=RT_NULL){
+                      if(lurecore->type==cJSON_Number){
+                          device_status.InsectSpecies = lurecore->valueint;
+                          ef_set_env_blob("InsectSpecies", &device_status.InsectSpecies, sizeof(device_status.InsectSpecies)); //诱芯序号
+                          LOG_I("下发设置诱芯序号:%d",device_status.InsectSpecies);
+                      }
+                  }
+
                   if(work_tim!=RT_NULL){
                       device_status.timeSwitch = 1;
                       st = cJSON_GetObjectItem(work_tim,"st");

+ 0 - 1
Application_cbd_apm32f1/applications/dtu_uart2.h

@@ -27,7 +27,6 @@ typedef struct{
 
 
 
-
 void dtu_send_data_start(void);
 //查询数据---{"cmd": "read"}
 //重启-------{"cmd": "reboot"}

+ 40 - 19
Application_cbd_apm32f1/applications/hmi.c

@@ -158,6 +158,7 @@ static void Hmi_thread_entry(void *parameter)
         device_status.run_sta = 0;
     }
     device_status.camsta = 1;
+    rt_uint32_t recv_t = 0;
     while(1)
     {
 
@@ -172,6 +173,14 @@ static void Hmi_thread_entry(void *parameter)
                 //LOG_I("%s",rx_buffer);
                 //\r 对应的hex为0x0d,0x0a,占两个字节,屏幕发送的数据都以\r结尾
                 HMI_Decode();
+                recv_t = 0;
+        }else{
+            recv_t++;
+            if(recv_t==20*60*3)    //持续3分钟无数据,关闭屏幕电源
+            {
+                recv_t = 0;
+                //ctr_hmi_5v(OFF);
+            }
         }
         /*********************************************************************************************************************/
         //rt_kprintf("%04d-%02d-%02d %02d:%02d:%02d\n",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
@@ -298,6 +307,7 @@ static void HMI_Decode(void)
             //更新加热时间
             HMI_WRITE("workSta.heatTime.val=%d",device_status.heattime);
             HMI_WRITE("sysSet.jtime.val=%d",device_status.heattime);
+            HMI_WRITE("sysSet.cb0.val=%d",device_status.sleep_mode);
             //
             HMI_WRITE("sysSet.vol.val=%d",device_status.vol);
             //更新加热时间和温度
@@ -697,22 +707,37 @@ static void HMI_Decode(void)
         rt_kprintf("数据上传设置:%d\n",device_status.dattim);
     }
     else if(strstr(rx_buffer,"saveXYtype=")!=NULL)
-        {
-            static char xy_str[3];
-            LOG_I("修改诱芯!");
-            var = strstr(rx_buffer,"=");
-            var ++;
-            strncpy(xy_str,var,2);
-            if(atoi(xy_str)>=0&&atoi(xy_str)<=100){
-                LOG_I("修改诱芯:%d",atoi(xy_str));
-                device_status.InsectSpecies =atoi(xy_str); //昆虫种类
-                ef_set_env_blob("InsectSpecies", &device_status.InsectSpecies, sizeof(device_status.InsectSpecies));
-                MA_save();
-            }else{
-                LOG_E("诱芯设置失败!");
-            }
+    {
+        static char xy_str[3];
+        LOG_I("修改诱芯!");
+        var = strstr(rx_buffer,"=");
+        var ++;
+        strncpy(xy_str,var,2);
+        if(atoi(xy_str)>=0&&atoi(xy_str)<=100){
+            LOG_I("修改诱芯:%d",atoi(xy_str));
+            device_status.InsectSpecies =atoi(xy_str); //昆虫种类
+            ef_set_env_blob("InsectSpecies", &device_status.InsectSpecies, sizeof(device_status.InsectSpecies));
+            MA_save();
+        }else{
+            LOG_E("诱芯设置失败!");
         }
-
+    }
+    else if(strstr(rx_buffer,"sleepmode=")!=NULL)
+    {
+        static char ss1[3];
+        LOG_I("修改休眠模式!");
+        var = strstr(rx_buffer,"=");
+        var ++;
+        strncpy(ss1,var,2);
+        if(atoi(ss1)>=0&&atoi(ss1)<=2){
+            LOG_I("修改休眠模式:%d",atoi(ss1));
+            device_status.sleep_mode =atoi(ss1); //昆虫种类
+            ef_set_env_blob("sleep_mode", &device_status.sleep_mode, sizeof(device_status.sleep_mode));
+            MA_save();
+        }else{
+            LOG_E("诱芯设置失败!");
+        }
+    }
     //恢复出厂设置电池
     else if (strstr(rx_buffer,"resetdcDefault")!=NULL)
     {
@@ -1094,8 +1119,6 @@ void Check_ParamConfig(void)
         rt_sprintf(device_status.net,"1");
         rt_sprintf(device_status.csq,"0");
         rt_sprintf(device_status.sim,"1");
-        ctr_RTU_12V(ON);    //RTU供电
-        ctr_router(ON);     //路由器供电
         Hmi_Fresh();
         Check_Self();
         dtu_data_play();
@@ -1214,10 +1237,8 @@ void ResetParamDefault_DC(void)
     ef_set_env_blob("cul_time", &device_status.cul_time, sizeof(device_status.cul_time));
     device_status.dattim = 30;      //数据上传间隔
     ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim)); //数据上传间隔
-
     device_status.startBar = 9;    //定时开始时间
     device_status.stopBar = 18;      //定时结束时间
-
     device_status.heattime = 10;    //加热时间
     device_status.shake_ws = 1;     //针对开关
     device_status.shake_sec = 1;    //震动时间1-100ms

+ 24 - 21
Application_cbd_apm32f1/packages/syswatch-latest/src/syswatch.c

@@ -401,35 +401,38 @@ static void syswatch_thread_entry(void *parameter)
             #endif
         }
 
+        if(device_status.sleep_mode==0){
+            if((alarm_new.tm_hour==01) ||
+                    (alarm_new.tm_hour==02) ||
+                    (alarm_new.tm_hour==03) ||
+                    (alarm_new.tm_hour==04) ||
+                    (alarm_new.tm_hour==23))
+            {
+                if((alarm_new.tm_min==05)&&(alarm_new.tm_sec>30))
+                {
+                    if(alarm_new.tm_year+1900>=2025)
+                    {
+                        ctr_router(OFF);
+                        ctr_RTU_12V(OFF);
+                    }
+                }
 
-        if((alarm_new.tm_hour==01) ||
-                (alarm_new.tm_hour==02) ||
-                (alarm_new.tm_hour==03) ||
-                (alarm_new.tm_hour==04) ||
-                (alarm_new.tm_hour==23))
-        {
-            if((alarm_new.tm_min==05)&&(alarm_new.tm_sec>30))
+            }
+            //
+            if((alarm_new.tm_hour==6) || (alarm_new.tm_hour==7))
             {
-                if(alarm_new.tm_year+1900>=2025)
+                if((alarm_new.tm_min==0) && (alarm_new.tm_sec>30))
                 {
-                    ctr_router(OFF);
-                    ctr_RTU_12V(OFF);
-                    ctr_hmi_5v(OFF);         //屏幕供电
+                    ctr_router(ON);
+                    ctr_RTU_12V(ON);
+                    //ctr_hmi_5v(ON);         //屏幕供电
                 }
             }
+        }else if(device_status.sleep_mode==1){
+            if(device_status.work_status==0){
 
-        }
-        //
-        if((alarm_new.tm_hour==6) || (alarm_new.tm_hour==7))
-        {
-            if((alarm_new.tm_min==0) && (alarm_new.tm_sec>30))
-            {
-                ctr_router(ON);
-                ctr_RTU_12V(ON);
-                ctr_hmi_5v(ON);         //屏幕供电
             }
         }
-
         #endif
         rt_thread_delay(RT_TICK_PER_SECOND);
         syswatch_wdt_feed();

+ 13 - 0
Application_cbd_apm32f1/readme.md

@@ -1,3 +1,16 @@
+# 2026-03-11 更新说明
+	版本:3.3.3
+	1. 关闭屏幕供电会导致rtu12V供电同时关闭,故增加休眠模式:只在上传/拍照时提前通电,结束后延迟掉电
+	2. 增加屏幕及mqtt设置休眠模式;
+# 2026-03-10 更新说明
+	版本:3.2.3
+	1. 2种工作模式:
+		正常模式,常供电
+		夜间休眠
+	2. 增加诱芯名称上报,lurecore
+	   增加诱芯序号设置,上报时根据序号自动匹配名称:
+	   {"cmd": "paramconf", "ext": {"lurecore": 0}}
+	   
 # 2026-03-01 更新说明
 	版本:3.1.3
 	1. 修复屏幕触发拍照测试无效;