zhunk пре 1 година
родитељ
комит
e8a0144bc0

+ 7 - 9
Application_cbd_apm32f1/applications/beep.c

@@ -150,8 +150,8 @@ static int init_tim2(void)
     }
 
     /* 设置定时器超时值为5s并启动定时器 */
-    timeout_s.sec = 1;      /* 秒 */
-    timeout_s.usec = 1000000;     /* 微秒 */ //1000ms
+    timeout_s.sec = 0;      /* 秒 */
+    timeout_s.usec = 500000;     /* 微秒 */ //100ms
     if (rt_device_write(hw_dev, 0, &timeout_s, sizeof(timeout_s)) != sizeof(timeout_s))
     {
         rt_kprintf("set timeout value failed\n");
@@ -164,18 +164,16 @@ int hwtimer2_pwm3_output(rt_uint32_t time,rt_uint32_t freq,uint8_t EN,uint8_t DI
 {
     ctr_Motor_Driver_Power(ON);
     rt_thread_delay(100);
-    init_pwm3();
-
-    rt_pwm_set(pwm_device, BEEP_PWM_CH, freq, freq);//channel,period,pulse
-    rt_pwm_enable(pwm_device, BEEP_PWM_CH); //使能蜂鸣器对应的 PWM 通道
-    rt_thread_delay(10);
     rt_pin_mode(Motor_EN, PIN_MODE_OUTPUT);
     rt_pin_mode(Motor_DIR, PIN_MODE_OUTPUT);
     rt_pin_write(Motor_EN, EN);
-    rt_pin_write(Motor_DIR, OFF);
+    rt_thread_delay(1);
+    rt_pin_write(Motor_DIR, DIR);
+    init_pwm3();
 
+    rt_pwm_set(pwm_device, BEEP_PWM_CH, freq, freq/2);//channel,period,pulse
     if(init_tim2()==0)
-        rt_pwm_set(pwm_device, BEEP_PWM_CH, freq, freq/2);//channel,period,pulse
+        rt_pwm_enable(pwm_device, BEEP_PWM_CH); //使能蜂鸣器对应的 PWM 通道
     return 0;
 }
 

+ 170 - 28
Application_cbd_apm32f1/applications/control.c

@@ -1591,10 +1591,160 @@ void HardWare_Check(uint8_t boot)
     }
 
 }
+
+
+void WorkCheck(void)
+{
+    static rt_uint32_t light_timeout = 3600;
+    while(device_status.ds == 1 &&
+          device_status.rain_status == 0 &&
+          device_status.temp_status == 0 &&
+          device_status.bat_status == 0)
+    {
+        if(device_status.timeSwitch == 1) // 时控模式
+        {
+            LOG_I("***********时控*****************");
+            if(device_status.startBar == device_status.stopBar &&
+               device_status.startBar == 0)
+            {
+                // 24小时模式处理
+                #if LAMP_EN == 1
+                device_status.lamp_status = (device_status.sun_status == 0) ? 1 : 0;
+                device_status.lamp1_status = 0;
+                device_status.lamp2_status = 0;
+                #endif
+                device_status.work_status = 1;
+                rt_thread_delay(1000);
+                continue;
+            }
+
+            time_t now;
+            time(&now);
+            struct tm now_tm = *localtime(&now);
+            struct tm start_tm = *localtime(&now);
+            struct tm end_tm = *localtime(&now);
+
+            // 设置开始时间
+            now_tm.tm_hour = now_tm.tm_hour-8;
+            time_t now_time = mktime(&now_tm);
+
+            // 设置开始时间
+            start_tm.tm_hour = device_status.startBar-8;
+            start_tm.tm_min = 0;
+            start_tm.tm_sec = 0;
+            time_t start_time = mktime(&start_tm);
+
+            // 设置结束时间(自动处理跨天)
+            end_tm.tm_hour = device_status.stopBar-8;
+            end_tm.tm_min = 0;
+            end_tm.tm_sec = 0;
+            if(device_status.startBar >= device_status.stopBar) {
+                end_tm.tm_mday += 1; // 结束时间+1天
+            }
+            time_t end_time = mktime(&end_tm);
+
+            // 工作时间判断
+            if(now_time >= start_time && now_time < end_time)
+            {
+                device_status.work_status = 1;
+                LOG_I("时控工作模式:现在:%d- 开始:%d-结束:%d",now_time,start_time,end_time);
+                rt_thread_delay(10000);
+                #if LAMP_EN == 1
+                // 统一灯控制逻辑
+                int hours = now_tm.tm_hour;
+                if (hours >= 20 && hours < 21) {
+                    device_status.lamp_status = 1;
+                    device_status.lamp1_status = 0;
+                    device_status.lamp2_status = 0;
+                } else if (hours >= 21 && hours < 22) {
+                    device_status.lamp_status = 0;
+                    device_status.lamp1_status = 1;
+                    device_status.lamp2_status = 0;
+                } else if (hours >= 22 && hours < 23) {
+                    device_status.lamp_status = 0;
+                    device_status.lamp1_status = 0;
+                    device_status.lamp2_status = 1;
+                } else {
+                    // 非20-23点默认状态
+                    device_status.lamp_status = 1;
+                    device_status.lamp1_status = 0;
+                    device_status.lamp2_status = 0;
+                }
+                #endif
+            }
+            else
+            {
+                device_status.work_status = 0;
+                LOG_I("时控待机模式:现在:%d- 开始:%d-结束:%d",now_time,start_time,end_time);
+                rt_thread_delay(10000);
+                #if LAMP_EN == 1
+                // 非工作时间关灯
+                device_status.lamp_status = 0;
+                device_status.lamp1_status = 0;
+                device_status.lamp2_status = 0;
+                #endif
+            }
+        }
+        else // 光控模式
+        {
+            LOG_I("光控定时模式!");
+            if(device_status.sun_status == 0 && device_status.light_over_tim != 0)
+            {
+                device_status.light_over_tim--;
+                light_timeout = 3600;  // 重置超时计数器
+                #if LAMP_EN == 1
+                Led_Check(device_status.sunBar);
+                #else
+                device_status.work_status = 1;
+                LOG_I("光控定时,计时中>>>>>>>>>:%d",device_status.light_over_tim);
+                #endif
+            }
+            else
+            {
+                // 仅在白天递减超时计数器
+                if(device_status.sun_status == 1 && light_timeout > 0) {
+                    light_timeout--;
+                }
+
+                device_status.work_status = 0;
+
+                //没有在测试并且没有在自检
+                if(device_status.test_flag==0&&device_status.selfcheck_ws==0)
+                {
+                    ctr_lamp(OFF,1);
+                    #if LAMP_EN == 1
+                    ctr_lamp(OFF,2);
+                    ctr_lamp(OFF,3);
+                    #endif
+                }
+
+                // 连续1小时白天后重置
+                if(light_timeout == 0) {
+                    device_status.light_over_tim = 0;
+                    light_timeout = 3600;  // 重置防止负数
+                }
+
+                // 白天且倒计时结束:重置夜晚时长
+                if(device_status.light_over_tim == 0 &&
+                   device_status.sun_status == 1)
+                {
+                    device_status.light_over_tim = device_status.sunBar * 3600;
+                }
+            }
+        }
+        rt_thread_delay(1000);
+    }
+
+    // 异常状态处理
+    device_status.work_status = 0;
+    rt_thread_delay(1000);
+}
+#if 0
 //工作状态检测
 void WorkCheck(void)
 {
     static rt_uint32_t light_timeout = 3600;
+    static int check_stamp_cnt = 0;
     //雨控检测,温控检测,电池电压检测
     while(device_status.ds==1&&device_status.rain_status==0&&device_status.temp_status==0&&device_status.bat_status==0)
     {
@@ -1644,18 +1794,25 @@ void WorkCheck(void)
                 if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&endtime))<0))
                 {
                     LOG_I("当前时间大于开始时间,小于结束时间,工作中!!!");
-                    device_status.work_status = 1;
+                    check_stamp_cnt++;
+                    if(check_stamp_cnt>20)
+                    {
+                        device_status.work_status = 1;
+                    }
+
                 }
                 //如果当前时间小于开始时间
                 else if(difftime(mktime(&nowtime),mktime(&starttime))<0)
                 {
                     LOG_I("当前时间小于开始时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
                     device_status.work_status = 0;
+                    check_stamp_cnt = 0;
                 }
                 //当前时间大于结束时间
                 else {
                     LOG_I("当前时间大于结束时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
                     device_status.work_status = 0;
+                    check_stamp_cnt = 0;
                 }
                 #if LAMP_EN == 1
                 //如果当前时间超过20点,未到21点
@@ -1736,16 +1893,7 @@ void WorkCheck(void)
         }
         else {
                 LOG_I("光控定时模式!");
-                /*
-                time_t now;
-                time(&now);
-                static struct tm nowstamp;
-                nowstamp =*localtime(&now);
-                nowstamp.tm_hour = nowstamp.tm_hour - 8;
-                static rt_uint32_t nowstamp_num = 0;
-                nowstamp_num = mktime(&nowstamp);
-                rt_kprintf("now stamp:%d\n",nowstamp_num);
-                */
+
                 if(device_status.sun_status==0&&device_status.light_over_tim!=0)
                 {
 
@@ -1782,7 +1930,7 @@ void WorkCheck(void)
     device_status.work_status = 0;
     rt_thread_delay(1000);
 }
-
+#endif
 //工作任务流程s
 void WorkTask(void)
 {
@@ -1808,6 +1956,16 @@ void WorkTask(void)
             ctr_Fan_PUT(ON);
             #endif
             DTU_Write("workstart.mp3");
+            if(device_status.debug_ws==1)
+            {
+                time_t stamp=time(RT_NULL);
+                static struct tm tm;
+                gmtime_r(&stamp, &tm);
+                rt_sprintf(device_status.stamp,"%04d%02d%02d%02d%02d%02d",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
+                char* debug_str = makeJson_Warn("Work start!", device_status.stamp);
+                DTU_Write(debug_str);
+                rt_free(debug_str);
+            }
         }
         //1.打开灯管
         #if LAMP_EN == 1
@@ -1985,22 +2143,6 @@ void WorkTask(void)
                 //ctr_shake(ON, 100);
             }
         }
-        else {
-                    //打开高压
-                    ctr_Heat(ON);
-                    //打开补光
-                    ctr_led(ON);
-                    LOG_I("打开补光!!");
-                    rt_pin_mode(CLEAR_L_LIMIT,PIN_MODE_INPUT);
-                    //2.翻转清虫
-                    while(rt_pin_read(CLEAR_L_LIMIT)==1)  rt_thread_delay(20);
-                    rt_thread_delay(500);
-                    Hk_Take_io();  //触发海康相机拍照
-                    rt_thread_delay(500);
-                    ctr_turnv5();  //摆动清虫
-                    LOG_I("摆动清虫!");
-
-        }
    }
     if(device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status==1 || device_status.ds==0)
     {

+ 3 - 2
Application_cbd_apm32f1/applications/control.h

@@ -18,7 +18,7 @@
 
 
 #define LAMP_EN          0             //李新3灯管:0关闭,1打开
-#define PCB_V1           0             //1-旧PCB,0-新PCB(模块化)
+#define PCB_V1           1             //1-旧PCB,0-新PCB(模块化)
 #define MATCH_DEVICE     0             //比赛设备
 #define SENSOR_EN        1             //温湿度:0关闭,1打开
 
@@ -33,7 +33,7 @@
     #define VERSION_HK_2000W    "1.3led.40(2000W)"       //水稻
 #else
     #define VERSION_HK          "2.5.41(HK)"            //4.0海康-1200W
-    #define VERSION_HK_2000W    "2.16.4(2000W)"         //4.0水稻
+    #define VERSION_HK_2000W    "2.17.4(2000W)"         //4.0水稻
 #endif
 
 #define VERSION_ZP          "1.45.1(ZP)"            //1.0转盘
@@ -124,6 +124,7 @@ typedef struct  _packed
     uint8_t selfcheck_ws;    //自检开关1-北大荒,2-标配
     uint8_t gps_inuse;
     uint8_t gps_view;
+    uint8_t debug_ws;        //调试开关,把调试信息上报到MQTT
     uint16_t dattim;         //数据上传间隔
     uint16_t shake_sec;      //震动时间
     uint16_t thsp;           //息屏时间

+ 29 - 11
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -1623,6 +1623,24 @@ int parseDtu(char *json_string)
                       if(device_status.vol==0)
                           device_status.vol = 111;
                   }
+                  //{"ext": {"type": "debug_on"}, "cmd": "ctrl"}
+                  else if (strstr(type->valuestring,"debug_on")!=RT_NULL)
+                  {
+                       device_status.debug_ws = 1;
+                       LOG_W("开启调试信息上报!");
+                       char *debug_sta = makeJson_Warn("debug on","debug");
+                       DTU_Write("%s",debug_sta);
+                       rt_free(debug_sta);
+                  }
+                  //{"ext": {"type": "debug_off"}, "cmd": "ctrl"}
+                  else if (strstr(type->valuestring,"debug_off")!=RT_NULL)
+                  {
+                      device_status.debug_ws = 0;
+                      LOG_W("关闭调试信息上报!");
+                      char *debug_sta = makeJson_Warn("debug off","debug");
+                      DTU_Write("%s",debug_sta);
+                      rt_free(debug_sta);
+                  }
                   else if (strstr(type->valuestring,"led_on")!=RT_NULL)
                   {
                       ctr_led(ON);
@@ -1776,17 +1794,17 @@ int parseDtu(char *json_string)
                           struct timeval tv;
                           gettimeofday(&tv,NULL);
                           LOG_I("系统当前时间戳:%d",tv.tv_sec);
-                          time_t timestamp_diff;
-                          if(timestamp>tv.tv_sec)
-                          {
-                             timestamp_diff = timestamp - tv.tv_sec;
-                          }else
-                          {
-                             timestamp_diff = tv.tv_sec - timestamp;
-                          }
-                          if (timestamp_diff>60) {
-                             setSystemTime(tm_time);
-                          }
+//                          time_t timestamp_diff;
+//                          if(timestamp>tv.tv_sec)
+//                          {
+//                             timestamp_diff = timestamp - tv.tv_sec;
+//                          }else
+//                          {
+//                             timestamp_diff = tv.tv_sec - timestamp;
+//                          }
+//                          if (timestamp_diff>60) {
+//                             setSystemTime(tm_time);
+//                          }
                       }
                       free(tm_time); // Free the allocated memory
                   }

+ 2 - 0
Application_cbd_apm32f1/applications/hmi.c

@@ -1559,11 +1559,13 @@ static void Ctr_Mortor_entry(void* parameter)
          }
         else if (device_status.autotakepic==10) {
             hwtimer2_pwm3_output(1,500000,1,0);
+            //ctr_xmove(400,200);
             device_status.autotakepic = 0;
         }
 
         else if (device_status.autotakepic==11) {
             hwtimer2_pwm3_output(1,500000,1,1);
+            //ctr_xmove(400,200);
             device_status.autotakepic = 0;
         }
 

+ 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;
 

+ 7 - 1
Application_cbd_apm32f1/readme.md

@@ -1,4 +1,10 @@
-修复RTC问题
+# 2025-05-30 更新说明
+#define VERSION_HK_2000W    "2.17.4(2000W)"         //4.0水稻
+1. 增加调试上报功能
+2. 修改时控定时逻辑
+# 2025-05-28 更新说明
+#define VERSION_HK_2000W    "2.16.4(2000W)"         //4.0水稻
+1. 修复RTC问题,取消设置时间
 # 2025-05-22 更新说明
 #define VERSION_HK_2000W    "2.15.4(2000W)"         //4.0水稻
 1. 修复偶发灯管状态显示异常问题,原因是和开关灯管状态的变量lamp_status冲突导致,解决:灯管状态使用单独的变量:lamp;