zhunk 1 tahun lalu
induk
melakukan
805ddf14cf

+ 155 - 113
Application_cbd_apm32f1/applications/control.c

@@ -1074,11 +1074,12 @@ void ctr_RTU_DTU(uint8_t status_rtu)
     rt_pin_mode(RTU_DTU, PIN_MODE_OUTPUT);
     if(status_rtu==ON)
     {
+        LOG_W("RTU电源启动!!!");
         rt_pin_write(RTU_DTU,ON);
     }
     else
     {
-        LOG_W("RTU电源复位!!!");
+        LOG_W("RTU电源关闭!!!");
         rt_pin_write(RTU_DTU,OFF);
     }
 }
@@ -1279,10 +1280,14 @@ void SunTest(void)
 /*上电初始化*/
 void ResetInit(void)
 {
-    //1.打开路由器供电
-    ctr_router(ON);
-    //2. 打开RTU供电
-    ctr_RTU_DTU(ON);
+    LOG_I("ResetInit...");
+    if(device_status.sleep_mode==0)
+    {
+        //1.打开路由器供电
+        ctr_router(ON);
+        //2. 打开RTU供电
+        ctr_RTU_DTU(ON);
+    }
     //3.打开光栅供电
     ctr_photo(ON);
     //5.关闭加热
@@ -1582,29 +1587,8 @@ void WorkCheck(void)
 }
 
 
-void guanshan_on(void *args)
-{
-    LOG_W("guanshan_on!");
-    rt_event_send(event_485_play, 0x01);
-}
-
-static void pin_guangshan_bind(void)
-{
-    /* PC14引脚为输入模式 */
-    rt_pin_mode(GUANG_SHAN, PIN_MODE_INPUT);
-    /* 绑定中断,下降沿模式,回调函数名为guanshan_on */
-    rt_pin_attach_irq(GUANG_SHAN, PIN_IRQ_MODE_RISING, guanshan_on, RT_NULL);
-    /* 使能中断 */
-    rt_pin_irq_enable(GUANG_SHAN, PIN_IRQ_ENABLE);
-}
-
-static void pin_guangshan_unbind(void)
-{
-    rt_pin_detach_irq(GUANG_SHAN);
-}
-
-
 
+static uint8_t sleep_cnt = 0;
 //拍照性诱工作任务流程
 void WorkTask_XYV3(void)
 {
@@ -1629,18 +1613,23 @@ void WorkTask_XYV3(void)
                 cal_n = device_status.cul_time * 60;
             }
             if(device_status.sleep_mode>0){
-                if(cal_n==120){
+                device_status.cul_time = 120;
+                if(cal_n==60){
                     ctr_router(ON);
                     ctr_RTU_DTU(ON);
                 }
             }
-
             if(device_status.sleep_mode==10)
             {
-                rt_thread_delay(5000);
-                ctr_router(OFF);
-                ctr_RTU_DTU(OFF);
-                device_status.sleep_mode = 1;
+                LOG_I("倒计时关闭联网模块电源:%d",sleep_cnt);
+                sleep_cnt++;
+                if(sleep_cnt>=60)
+                {
+                    sleep_cnt = 0;
+                    ctr_router(OFF);
+                    ctr_RTU_DTU(OFF);
+                    device_status.sleep_mode = 1;
+                }
             }
 
             if(device_status.temp_status==1 || device_status.bat_status==1 ||device_status.work_status==0) break;
@@ -1716,87 +1705,157 @@ static void Control_Clear_thread_entry(void *parameter)
 }
 
 /*入口函数加热*/
-static void Control_Heat_thread_entry(void *parameter)
-{
+//static void Control_Heat_thread_entry(void *parameter)
+//{
+//    rt_pin_mode(SIGNAL_GaoYa, PIN_MODE_INPUT);
+//    rt_pin_mode(SIGNAL_GuangShan, PIN_MODE_INPUT);
+//    static int GaoyYa_cnt,GuangShan_cnt = 500; //10s
+//    bool GaoYa = false;
+//    bool GuangShan = false;
+//    while(1)
+//    {
+//
+//        if(rt_pin_read(SIGNAL_GaoYa)==0)
+//        {
+//            LOG_I("检测到高压计数!");
+//            GaoYa = true;
+//        }
+//
+//        if(rt_pin_read(SIGNAL_GuangShan)==0)
+//        {
+//            LOG_I("检测到光栅计数!");
+//            GuangShan = true;
+//        }
+//
+//        if(GaoYa)
+//        {
+//            GaoyYa_cnt --;
+//            if(GaoyYa_cnt==0)
+//            {
+//                GaoyYa_cnt = 500;
+//                GaoYa = false;
+//            }
+//        }
+//
+//        if(GuangShan)
+//        {
+//            GuangShan_cnt--;
+//            if(GuangShan_cnt==0)
+//            {
+//                GuangShan_cnt = 500;
+//                GuangShan = false;
+//            }
+//        }
+//
+//        if(GaoYa&&GuangShan)
+//        {
+//            device_status.all_ycct += 1;   //计数值增加
+//            //拍照
+//            if(device_status.all_ycct>=1){
+//                //device_status.photo_ws = 1;
+//            }
+//            GaoYa = false;
+//            GuangShan = false;
+//            GaoyYa_cnt = 500;
+//            GuangShan_cnt = 500;
+//            rt_thread_delay(1000);
+//        }
+//        rt_thread_delay(20);
+//    }
+//}
+
+static void Control_Heat_thread_entry(void *parameter) {
     rt_pin_mode(SIGNAL_GaoYa, PIN_MODE_INPUT);
     rt_pin_mode(SIGNAL_GuangShan, PIN_MODE_INPUT);
-    static int GaoyYa_cnt,GuangShan_cnt = 500; //10s
-    bool GaoYa = false;
-    bool GuangShan = false;
-    while(1)
-    {
 
-        if(rt_pin_read(SIGNAL_GaoYa)==0)
-        {
-            LOG_I("检测到高压计数!");
-            GaoYa = true;
-        }
-
-        if(rt_pin_read(SIGNAL_GuangShan)==0)
-        {
-            LOG_I("检测到光栅计数!");
-            GuangShan = true;
+    // 修正变量名和初始化
+    static int GaoYa_cnt = 500, GuangShan_cnt = 500;
+    static bool GaoYa = false, GuangShan = false;
+    static int gaoYaDebounce = 0, guangShanDebounce = 0;
+    static enum { PHOTO_IDLE, PHOTO_TRIGGERED, PHOTO_DELAY } photoState = PHOTO_IDLE;
+    static int photoDelayTicks = 0;
+
+    // 去抖动阈值 (100ms)
+    #define DEBOUNCE_TICKS 5
+
+    // 新增高压持续时间监测
+    static uint32_t highPressureDuration = 0;        // 持续时间计数器
+    const uint32_t pressureTimeout = 250;            // 5秒阈值(250 * 20ms=5000ms)
+    bool pressureAlarmTriggered = false;             // 报警触发标志
+
+    while (1) {
+        // 高压信号去抖动
+        if (rt_pin_read(SIGNAL_GaoYa) == 0) {
+            if (gaoYaDebounce < DEBOUNCE_TICKS) {
+                gaoYaDebounce++;
+                if (gaoYaDebounce == DEBOUNCE_TICKS && !GaoYa) {
+                    LOG_I("高压信号稳定触发");
+                    GaoYa = true;
+                }
+            }
+        } else {
+            gaoYaDebounce = 0;
         }
 
+        // 光栅信号去抖动(类似逻辑)
+        // ...
+        /* 高压持续时间监测 */
         if(GaoYa)
         {
-            GaoyYa_cnt --;
-            if(GaoyYa_cnt==0)
+            // 持续时间累计(每次循环+1,20ms/次)
+            if(++highPressureDuration >= pressureTimeout)
             {
-                GaoyYa_cnt = 500;
+                if(!pressureAlarmTriggered)
+                {
+                    LOG_E("高压持续超过5秒!");
+                    // 执行关闭高压操作(示例函数)
+                    ctr_lamp(OFF, 1);
+                    pressureAlarmTriggered = true;
+                    // 可选:自动复位保护
+                    rt_thread_mdelay(10000);    // 等待2秒
+                    ctr_lamp(ON, 1);
+                }
+            }
+        }
+        // 计数器逻辑
+        if (GaoYa) {
+            if (--GaoYa_cnt <= 0) {
                 GaoYa = false;
+                GaoYa_cnt = 500;
             }
         }
 
-        if(GuangShan)
-        {
-            GuangShan_cnt--;
-            if(GuangShan_cnt==0)
-            {
-                GuangShan_cnt = 500;
+        if (GuangShan) {
+            if (--GuangShan_cnt <= 0) {
                 GuangShan = false;
+                GuangShan_cnt = 500;
             }
         }
 
-        if(GaoYa&&GuangShan)
-        {
-            device_status.all_ycct += 1;   //计数值增加
-            //拍照
-            if(device_status.all_ycct>=1){
-                //device_status.photo_ws = 1;
-            }
-            GaoYa = false;
-            GuangShan = false;
-            GaoyYa_cnt = 500;
-            GuangShan_cnt = 500;
-            rt_thread_delay(1000);
+        // 触发拍照逻辑
+        if (GaoYa && GuangShan) {
+            device_status.all_ycct++;
+            photoState = PHOTO_TRIGGERED;
+            GaoYa = GuangShan = false;
+            GaoYa_cnt = GuangShan_cnt = 500;
         }
-        rt_thread_delay(20);
-    }
-}
-
-static void thread_485_play_entry(void *param)
-{
-    static USHORT sound105[] = {0x736F,0x756E,0x6431,0x3037};
-    rt_uint32_t e;
-    // 创建事件控制块
-    event_485_play = rt_event_create("event", RT_IPC_FLAG_FIFO);
-    if (event_485_play == RT_NULL)
-    {
-        LOG_E("Event create failed!");
-        return;
-    }
-    while(1)
-    {
-        if(device_status.update_flag==1) break;
-        //等待事件
-        if(rt_event_recv(event_485_play, 0x01, RT_EVENT_FLAG_OR|RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e)==RT_EOK)
-        {
-            LOG_I("Interrupt occurred and processed.");
-            _485_play(sound105, 4);
-            //发送串口消息,通知JETSON计算卡进行拍照
-            DTU_Write("{\"guangshan\":\"on\"}");
+#if 0
+        // 处理拍照状态机
+        switch (photoState) {
+        case PHOTO_TRIGGERED:
+            device_status.photo_ws = 1;
+            photoState = PHOTO_DELAY;
+            photoDelayTicks = 50; // 1s
+            break;
+        case PHOTO_DELAY:
+            if (--photoDelayTicks <= 0) {
+                device_status.photo_ws = 0;
+                photoState = PHOTO_IDLE;
+            }
+            break;
         }
+#endif
+        rt_thread_delay(20); // 保持20ms周期
     }
 }
 
@@ -1831,23 +1890,6 @@ int Control_heat(void)
     return 0;
 }
 
-int thread_485_play(void)
-{
-    tid_485_play = rt_thread_create("thread_485play",
-                                    thread_485_play_entry, RT_NULL,
-                                    1024,       //1024
-                                    26,         //23
-                                    5);       //5
-    if(tid_485_play!=RT_NULL)
-    {
-        rt_thread_startup(tid_485_play);
-    }
-    else {
-        LOG_E("thread_485_play start failed!");
-    }
-    return 0;
-}
-
 /* 创建线程 -工作状态检测*/
 int Workstatus_check(void)
 {

+ 28 - 82
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -314,13 +314,13 @@ static void dtu_thread_entry_recv(void *parameter)
         rx_buffer[rx_length] = '\0';
         // 处理数据(新增调试接口)
         LOG_I("Raw Data:%s-%d",rx_buffer, rx_length);
-
-        if(device_status.dtype==3)
+        if(strstr(rx_buffer,"{")==RT_NULL||strstr(rx_buffer,"}")==RT_NULL)
         {
             HMI_WRITE("sysSet.va0.txt=\"%s\"",rx_buffer);
-            rt_timer_stop(timer_uart2);
+        }else{
+            process_uart_data(rx_buffer, rx_length);
         }
-        process_uart_data(rx_buffer, rx_length);
+
         rt_free(rx_buffer);
         #if 0
         if(result == RT_EOK)
@@ -444,9 +444,7 @@ static void dtu_thread_entry_send(void *parameter)
 {
 
     device_status.power_status = 1;
-    device_status.num_updata = 0;
-    static uint16_t current_arry[10];
-    static uint8_t record_current = 0;
+    device_status.num_updata = 200;
     rt_thread_delay(10000);
     static rt_uint16_t wait_i = 0;
     static rt_uint8_t check_i = 0;
@@ -458,7 +456,7 @@ static void dtu_thread_entry_send(void *parameter)
         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(atoi(device_status.net)==0||(now_tm.tm_year+1900 >=2024))    //当前时间大于2024
         {
             if(device_status.rain_status==1||device_status.temp_status==1)
             {
@@ -480,13 +478,14 @@ static void dtu_thread_entry_send(void *parameter)
                     HMI_WRITE("sleep=%d",1);
                 }
                 if(device_status.sleep_mode == 1) {
-                    if(device_status.num_updata==120)
+                    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);
                     }
                 }
-
             }
             else {
                 char *readinfo =  makeJson_ReadInfo();
@@ -506,12 +505,6 @@ static void dtu_thread_entry_send(void *parameter)
                 }
                 device_status.num_updata = device_status.dattim * 60;
                 if(device_status.dattim==0) device_status.dattim=30;   //数据上传时间间隔设置为0?
-
-                if(device_status.sleep_mode == 1) {
-                    rt_thread_delay(5000);
-                    ctr_router(OFF);
-                    ctr_RTU_DTU(OFF);
-                }
             }
         }
     else {
@@ -1307,6 +1300,7 @@ int parseDtu(char *json_string)
                   free(json_temp);
               }
               if(device_status.work_status==0) ctr_lamp(OFF, 1);  //关闭高压
+              device_status.sleep_mode = 10;
           }
           if(item_checkself!=NULL){//自检签名
               memset(device_status.qianming,0,sizeof(device_status.qianming));
@@ -1370,6 +1364,12 @@ int parseDtu(char *json_string)
                   rt_free(shake);
                   rt_thread_delay(2000);
               }
+              //{"cmd":"photoinfo","ext":{"photo_ct":2}}
+              else if (strstr(item_cmd->valuestring,"photoinfo")!=RT_NULL)
+              {
+                  device_status.sleep_mode = 10;
+                  LOG_I("拍照成功,准备关闭联网模块电源!");
+              }
               //远程给rtu重新上电
               else if (strstr(item_cmd->valuestring,"ctrl")!=RT_NULL)
               {
@@ -1417,6 +1417,7 @@ int parseDtu(char *json_string)
                   {
                       ctr_led(OFF);
                   }
+                  //{"ext": {"type": "sleep_mode"}, "cmd": "ctrl"}
                   else if(strstr(type->valuestring,"sleep_mode")!=RT_NULL)
                   {
                       device_status.sleep_mode = 1;
@@ -1424,45 +1425,7 @@ int parseDtu(char *json_string)
                       LOG_I("收到设置休眠指令:%d",device_status.sleep_mode);
                   }
               }
-              //切换平台
-              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)
               {
@@ -1487,7 +1450,7 @@ int parseDtu(char *json_string)
                   rt_free(restart);
                   rt_thread_delay(2000);
 
-            }
+             }
               else if (strstr(item_cmd->valuestring,"update")!=RT_NULL)
               {
                   rt_kprintf("准备升级!!!");
@@ -1631,18 +1594,14 @@ int parseDtu(char *json_string)
                   mqttcfg2 = cJSON_GetObjectItem(item_ext,"mqttcfg2");
                   link_sta = cJSON_GetObjectItem(item_ext,"link_sta");
                   link_ip = cJSON_GetObjectItem(item_ext,"link_ip");
-                  photo_sta = cJSON_GetObjectItem(item_ext,"photo_sta");
                   cJSON *gps_inuse = cJSON_GetObjectItem(item_ext,"gps_inuse");
                   cJSON *gps_view = cJSON_GetObjectItem(item_ext,"gps_view");
                   //如果DTU的IMEI和FLash中的不一样,保存到FLASH
                   value_commn = cJSON_GetObjectItem(item_ext,"photo_sta");
-                  if(photo_sta!=NULL){
-                      device_status.camsta = photo_sta->valueint;
-                      LOG_I("相机状态:%d",device_status.camsta);
-                  }
+
                   if(value_commn!=RT_NULL)
                   {
-                      HMI_WRITE("menu.eth1_sta.val=%d",atoi(value_commn->valuestring));
+                      device_status.camsta = value_commn->valueint;
                   }
                   value_commn = cJSON_GetObjectItem(item_ext,"cpu_tmp");
                   sprintf(device_status.cpu_temp,"%s",value_commn->valuestring);
@@ -1817,16 +1776,8 @@ int parseDtu(char *json_string)
                   sprintf(device_status.project,"%s",project->valuestring);
                   if(mqttcfg1!=NULL)
                   {
-                      if(strstr("8.136.98.49",mqttcfg1->valuestring)!=RT_NULL)
-                      {
-                        rt_sprintf(device_status.mqttcfg1, "8.136.98.49");
-                      }
-                      else if (strstr("120.27.222.26",mqttcfg1->valuestring)!=RT_NULL) {
-                        rt_sprintf(device_status.mqttcfg1, "120.27.222.26");
-                      }
-                      else {
-                        rt_sprintf(device_status.mqttcfg1, "8.136.98.49");
-                      }
+                      rt_sprintf(device_status.mqttcfg1, mqttcfg1->valuestring);
+
                       LOG_I("当前平台1:%s",mqttcfg1->valuestring);
                   }
                   if(mqttcfg2!=NULL)
@@ -2378,16 +2329,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);
@@ -2406,6 +2347,11 @@ void UpLoad_Data(void)
     #if Color_EN ==0
     DTU_Write("%s",updata);
     #endif
+    if(device_status.sleep_mode == 1&&device_status.work_status==0&&atoi(device_status.net)==0) {
+        rt_thread_delay(5000);
+        ctr_router(OFF);
+        ctr_RTU_DTU(OFF);
+    }
     //list_mem();
     //播放数据上传中语音
 }

+ 5 - 98
Application_cbd_apm32f1/applications/hmi.c

@@ -269,6 +269,8 @@ static void HMI_Decode(void)
             HMI_WRITE("workSta.upStatus.val=%d",device_status.up_status);
             //更新下仓门状态
             HMI_WRITE("workSta.downStatus.val=%d",device_status.down_status);
+
+            HMI_WRITE("menu.eth1_sta.val=%d",!device_status.camera_sta);
             //更新工作状态
             HMI_WRITE("menu.workStatus.val=%d",device_status.work_status);
             //更新温控状态
@@ -731,23 +733,6 @@ static void HMI_Decode(void)
                 LOG_E("诱芯设置失败!");
             }
         }
-    else if (strstr(rx_buffer,"setshake_sec=")!=NULL)
-    {
-        static char shakesec_str[4];
-        LOG_I("震动时间设置!");
-        var = strstr(rx_buffer,"=");
-        var ++;
-        strncpy(shakesec_str,var,2);
-        if(atoi(shakesec_str)>=0&&atoi(shakesec_str)<=10)
-        {
-            device_status.shake_sec =atoi(shakesec_str); //
-        }
-        else {
-            LOG_E("设置失败!!!");
-        }
-
-        LOG_D("震动时间设置:%d",device_status.shake_sec);
-    }
 
     //恢复出厂设置电池
     else if (strstr(rx_buffer,"resetdcDefault")!=NULL)
@@ -797,18 +782,7 @@ static void HMI_Decode(void)
                 MA_save();
             }
     }
-    else if (strstr(rx_buffer,"putTest.switchFAN_PU=1")!=NULL) {
-        ctr_Fan_PUT(ON);
-    }
-    else if (strstr(rx_buffer,"putTest.switchFAN_PU=0")!=NULL) {
-        ctr_Fan_PUT(OFF);
-    }
-    else if (strstr(rx_buffer,"putTest.switchFAN_IN=1")!=NULL) {
-        ctr_Fan_IN(ON);
-    }
-    else if (strstr(rx_buffer,"putTest.switchFAN_IN=0")!=NULL) {
-        ctr_Fan_IN(OFF);
-    }
+
     else if(strstr(rx_buffer,"DisplayPower")!=RT_NULL)
     {
         HMI_WRITE("sysTest.sysTest_power.txt=\"%s\"",device_status.power);
@@ -1179,7 +1153,6 @@ void Check_ParamConfig(void)
         LOG_I("SOFTWARE VERSION:%s-imei:%s--iccid:%s",device_status.driver,device_status.imei,device_status.iccid);
         LOG_I("read flash paramconfis:%d-%s-%s",device_status.version_type,device_status.driver_bl,device_status.driver_compile);
         LOG_I("开机次数:%d",device_status.rebootcnt);
-        LOG_I("收集时间:%d",device_status.clt_time);
         LOG_I("定时开始时间:%d",device_status.startBar);
         LOG_I("定时结束时间:%d",device_status.stopBar);
         LOG_I("timeSwitch:%d",device_status.timeSwitch);
@@ -1263,12 +1236,13 @@ void Check_ParamConfig(void)
             connect_num++;
             if(connect_num>5) break;
         }
+
         device_status.timeSwitch = 1;
         DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
         rt_thread_delay(1000);
         Workstatus_check();
         Work_Loop_Task();
-
+        device_status.num_updata = 2;
     }
 }
 
@@ -1323,7 +1297,6 @@ 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));    //震动时间
-
     }
 
     ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
@@ -1391,73 +1364,7 @@ void ResetParamDefault_DC(void)
     DTU_Write("reset.mp3");
     rt_thread_delay(1000);
 }
-//固件备份
-void app_partion_backup(void)
-{
-        rt_kprintf("固件恢复!!!\n");
-        const char *dst_part_name = "df_area";
-        const char *src_part_name = "app";
-        const struct fal_partition *dst_part;
-        const struct fal_partition *src_part;
-        dst_part = fal_partition_find(dst_part_name);
-        src_part = fal_partition_find(src_part_name);
-        if (dst_part == RT_NULL || src_part == RT_NULL)
-        {
-            if (dst_part == RT_NULL)
-            rt_kprintf("%s partition is not exist!\n", dst_part_name);
-            if (src_part == RT_NULL)
-            rt_kprintf("%s partition is not exist!\n", src_part_name);
-        }
-        else
-        {
-            rt_kprintf("Clone %s partition to %s partition:\n", src_part_name, dst_part_name);
-            if (fal_partition_erase(dst_part, 0, dst_part->len) >= 0)
-            {
-                int clone_pos = 0;
-                int clone_len = 0, clone_tol_len;
-                rt_uint8_t *buf = rt_malloc(4096);
-
-                if (dst_part->len < src_part->len)
-                    clone_tol_len = dst_part->len;
-                else
-                    clone_tol_len = src_part->len;
-
-                while ((clone_pos < clone_tol_len) && (buf != RT_NULL))
-                {
-                    clone_len = fal_partition_read(src_part, clone_pos, buf, 4096);
-                    if (clone_len < 0)
-                    {
-                        rt_kprintf("\nread %s partition failed, clone stop!\n", src_part_name);
-                        break;
-                    }
-
-                    if (fal_partition_write(dst_part, clone_pos, buf, clone_len) < 0)
-                    {
-                        rt_kprintf("\nwrite %s partition failed, clone stop!\n", dst_part_name);
-                        break;
-                    }
-
-                    HMI_WRITE("#");
-                    rt_kprintf("#");
-                    clone_pos += clone_len;
-                }
-
-                if (clone_pos >= clone_tol_len)
-                {
-
-                    rt_kprintf("\nClone partition success, total %d bytes!\n", clone_tol_len);
-
-                }
-                else
-                {
-                    rt_kprintf("Clone partition failed!");
 
-                }
-                if (buf)
-                    rt_free(buf);
-            }
-        }
-}
 void Debug_log_ON(void)
 {
     rt_console_set_device("uart4");

+ 0 - 7
Application_cbd_apm32f1/drivers/drv_clk.c

@@ -57,13 +57,6 @@ static void system_clock_config(void)
     }
     //Enables the Clock Security System
 
-    // 使能电源接口时钟和备份区域时钟
-    __HAL_RCC_PWR_CLK_ENABLE();
-    __HAL_RCC_BKP_CLK_ENABLE();
-
-    // 取消备份区域写保护
-    HAL_PWR_EnableBkUpAccess();
-
     HAL_RCC_EnableCSS();
 
     #define NVIC_VTOR_MASK   0x3FFFFF80

+ 55 - 49
Application_cbd_apm32f1/drivers/drv_rtc.c

@@ -14,13 +14,14 @@
 
 #ifdef BSP_USING_ONCHIP_RTC
 
-
+/*
 #ifndef HAL_RTCEx_BKUPRead
 #define HAL_RTCEx_BKUPRead(x1, x2) (~BKUP_REG_DATA)
 #endif
 #ifndef HAL_RTCEx_BKUPWrite
 #define HAL_RTCEx_BKUPWrite(x1, x2, x3)
 #endif
+*/
 #ifndef RTC_BKP_DR1
 #define RTC_BKP_DR1 RT_NULL
 #endif
@@ -29,63 +30,68 @@
 #define LOG_TAG             "drv.rtc"
 #include <drv_log.h>
 
-#define BKUP_REG_DATA 0xA5A5
+#define BKUP_REG_DATA 0xA0A0
 
 static struct rt_device rtc;
 
 static RTC_HandleTypeDef RTC_Handler;
-
+uint32_t           RTC_ReadTimeCounter(RTC_HandleTypeDef *hrtc);
+HAL_StatusTypeDef RTC_WriteTimeCounter(RTC_HandleTypeDef *hrtc, uint32_t TimeCounter);
 static time_t get_rtc_timestamp(void)
 {
-    RTC_TimeTypeDef RTC_TimeStruct = {0};
-    RTC_DateTypeDef RTC_DateStruct = {0};
-    struct tm tm_new;
-
-    HAL_RTC_GetTime(&RTC_Handler, &RTC_TimeStruct, RTC_FORMAT_BIN);
-    HAL_RTC_GetDate(&RTC_Handler, &RTC_DateStruct, RTC_FORMAT_BIN);
-
-    tm_new.tm_sec  = RTC_TimeStruct.Seconds;
-    tm_new.tm_min  = RTC_TimeStruct.Minutes;
-    tm_new.tm_hour = RTC_TimeStruct.Hours;
-    tm_new.tm_mday = RTC_DateStruct.Date;
-    tm_new.tm_mon  = RTC_DateStruct.Month - 1;
-    tm_new.tm_year = RTC_DateStruct.Year + 100;
-
-    LOG_D("get rtc time.");
-    return mktime(&tm_new);
+//    RTC_TimeTypeDef RTC_TimeStruct = {0};
+//    RTC_DateTypeDef RTC_DateStruct = {0};
+//    struct tm tm_new;
+//
+//    HAL_RTC_GetTime(&RTC_Handler, &RTC_TimeStruct, RTC_FORMAT_BIN);
+//    HAL_RTC_GetDate(&RTC_Handler, &RTC_DateStruct, RTC_FORMAT_BIN);
+//
+//    tm_new.tm_sec  = RTC_TimeStruct.Seconds;
+//    tm_new.tm_min  = RTC_TimeStruct.Minutes;
+//    tm_new.tm_hour = RTC_TimeStruct.Hours;
+//    tm_new.tm_mday = RTC_DateStruct.Date;
+//    tm_new.tm_mon  = RTC_DateStruct.Month - 1;
+//    tm_new.tm_year = RTC_DateStruct.Year + 100;
+//
+//    LOG_D("get rtc time.");
+//    RTC_ReadTimeCounter(&RTC_Handler);
+    //return mktime(&tm_new);
+    return RTC_ReadTimeCounter(&RTC_Handler);
 }
 
 static rt_err_t set_rtc_time_stamp(time_t time_stamp)
 {
-    RTC_TimeTypeDef RTC_TimeStruct = {0};
-    RTC_DateTypeDef RTC_DateStruct = {0};
-    struct tm *p_tm;
-
-    p_tm = localtime(&time_stamp);
-    if (p_tm->tm_year < 100)
-    {
-        return -RT_ERROR;
-    }
-
-    RTC_TimeStruct.Seconds = p_tm->tm_sec ;
-    RTC_TimeStruct.Minutes = p_tm->tm_min ;
-    RTC_TimeStruct.Hours   = p_tm->tm_hour;
-    RTC_DateStruct.Date    = p_tm->tm_mday;
-    RTC_DateStruct.Month   = p_tm->tm_mon + 1 ;
-    RTC_DateStruct.Year    = p_tm->tm_year - 100;
-    RTC_DateStruct.WeekDay = p_tm->tm_wday + 1;
-
-    if (HAL_RTC_SetTime(&RTC_Handler, &RTC_TimeStruct, RTC_FORMAT_BIN) != HAL_OK)
-    {
-        return -RT_ERROR;
-    }
-    if (HAL_RTC_SetDate(&RTC_Handler, &RTC_DateStruct, RTC_FORMAT_BIN) != HAL_OK)
-    {
-        return -RT_ERROR;
-    }
-
-    LOG_D("set rtc time.");
-    HAL_RTCEx_BKUPWrite(&RTC_Handler, RTC_BKP_DR1, BKUP_REG_DATA);
+//    RTC_TimeTypeDef RTC_TimeStruct = {0};
+//    RTC_DateTypeDef RTC_DateStruct = {0};
+//    struct tm *p_tm;
+//
+//    p_tm = localtime(&time_stamp);
+//    if (p_tm->tm_year < 100)
+//    {
+//        return -RT_ERROR;
+//    }
+//
+//    RTC_TimeStruct.Seconds = p_tm->tm_sec ;
+//    RTC_TimeStruct.Minutes = p_tm->tm_min ;
+//    RTC_TimeStruct.Hours   = p_tm->tm_hour;
+//    RTC_DateStruct.Date    = p_tm->tm_mday;
+//    RTC_DateStruct.Month   = p_tm->tm_mon + 1 ;
+//    RTC_DateStruct.Year    = p_tm->tm_year - 100;
+//    RTC_DateStruct.WeekDay = p_tm->tm_wday + 1;
+//
+//    if (HAL_RTC_SetTime(&RTC_Handler, &RTC_TimeStruct, RTC_FORMAT_BIN) != HAL_OK)
+//    {
+//        return -RT_ERROR;
+//    }
+//    if (HAL_RTC_SetDate(&RTC_Handler, &RTC_DateStruct, RTC_FORMAT_BIN) != HAL_OK)
+//    {
+//        return -RT_ERROR;
+//    }
+//
+//    LOG_D("set rtc time.");
+     HAL_RTCEx_BKUPWrite(&RTC_Handler, RTC_BKP_DR1, BKUP_REG_DATA);
+//    return RT_EOK;
+    RTC_WriteTimeCounter(&RTC_Handler,time_stamp);
     return RT_EOK;
 }
 
@@ -247,6 +253,6 @@ int rt_hw_rtc_init(void)
     LOG_D("rtc init success");
     return RT_EOK;
 }
-INIT_DEVICE_EXPORT(rt_hw_rtc_init);  //INIT_DEVICE_EXPORT
+INIT_DEVICE_EXPORT(rt_hw_rtc_init);
 
 #endif /* BSP_USING_ONCHIP_RTC */

+ 4 - 4
Application_cbd_apm32f1/libraries/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc.c

@@ -221,8 +221,8 @@
 /** @defgroup RTC_Private_Functions RTC Private Functions
   * @{
   */
-static uint32_t           RTC_ReadTimeCounter(RTC_HandleTypeDef *hrtc);
-static HAL_StatusTypeDef  RTC_WriteTimeCounter(RTC_HandleTypeDef *hrtc, uint32_t TimeCounter);
+ uint32_t           RTC_ReadTimeCounter(RTC_HandleTypeDef *hrtc);
+ HAL_StatusTypeDef  RTC_WriteTimeCounter(RTC_HandleTypeDef *hrtc, uint32_t TimeCounter);
 static uint32_t           RTC_ReadAlarmCounter(RTC_HandleTypeDef *hrtc);
 static HAL_StatusTypeDef  RTC_WriteAlarmCounter(RTC_HandleTypeDef *hrtc, uint32_t AlarmCounter);
 static HAL_StatusTypeDef  RTC_EnterInitMode(RTC_HandleTypeDef *hrtc);
@@ -1584,7 +1584,7 @@ HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc)
   *                the configuration information for RTC.
   * @retval Time counter
   */
-static uint32_t RTC_ReadTimeCounter(RTC_HandleTypeDef *hrtc)
+uint32_t RTC_ReadTimeCounter(RTC_HandleTypeDef *hrtc)
 {
   uint16_t high1 = 0U, high2 = 0U, low = 0U;
   uint32_t timecounter = 0U;
@@ -1616,7 +1616,7 @@ static uint32_t RTC_ReadTimeCounter(RTC_HandleTypeDef *hrtc)
   * @param  TimeCounter: Counter to write in RTC_CNT registers
   * @retval HAL status
   */
-static HAL_StatusTypeDef RTC_WriteTimeCounter(RTC_HandleTypeDef *hrtc, uint32_t TimeCounter)
+ HAL_StatusTypeDef RTC_WriteTimeCounter(RTC_HandleTypeDef *hrtc, uint32_t TimeCounter)
 {
   HAL_StatusTypeDef status = HAL_OK;