zhunk 1 год назад
Родитель
Сommit
a011ba3e73

BIN
Application_CBD/.settings/.rtmenus


+ 4 - 4
Application_CBD/Kconfig

@@ -15,10 +15,10 @@ config PKGS_DIR
     option env="PKGS_ROOT"
     default "packages"
 
-config PLATFORM_DIR
-    string
-    option env="PLATFORM_DIR"
-    default  "D:/RT-ThreadStudio/workspace/IOT_CBD_BZY_CTRL/Application_CBD/platform"
+config PLATFORM_DIR
+    string
+    option env="PLATFORM_DIR"
+    default "D:/RT-ThreadStudio/workspace/IOT_CBD_BZY_CTRL/Application_CBD/platform"
 
 source "$RTT_DIR/Kconfig"
 source "$PKGS_DIR/Kconfig"

+ 14 - 1
Application_CBD/applications/control.c

@@ -42,12 +42,25 @@ rt_thread_t tid_heat = RT_NULL;
 
 int thread_delete_workloop(void)
 {
+    LOG_W("thread_delete_workloop.");
     rt_err_t result;
     if(tid_workloop!=RT_NULL)
     {
         result = rt_thread_delete(tid_workloop);
     }
-    return result;
+    if(tid_wkstc!=RT_NULL)
+    {
+        result = rt_thread_delete(tid_wkstc);
+    }
+    if(tid_heat!=RT_NULL)
+    {
+        result = rt_thread_delete(tid_heat);
+    }
+    if(tid_ctr!=RT_NULL)
+    {
+        result = rt_thread_delete(tid_ctr);
+    }
+    return 0;
 }
 
 int thread_restart_workloop(void)

+ 20 - 9
Application_CBD/applications/dtu_uart2.c

@@ -56,6 +56,17 @@ struct  serial_configure dtuconfig = RT_SERIAL_CONFIG_DEFAULT;  /*初始化配
 
 static uint8_t makejson_sta = 0;
 
+
+int deltet_dtu_thread(void)
+{
+    if(dtu_send_data!=NULL)
+    {
+        rt_thread_delete(dtu_send_data);
+    }
+
+    return 0;
+}
+
 static int DTU_uart2_init(void)
 {
         dtuserial  = rt_device_find(DTU_UART_NAME);
@@ -69,6 +80,7 @@ static int DTU_uart2_init(void)
         rt_device_control(dtuserial, RT_DEVICE_CTRL_CONFIG, &dtuconfig);
         /* step4:打开串口设备。以DMA接收及轮询发送模式打开串口设备 */
         rt_device_open(dtuserial, RT_DEVICE_FLAG_DMA_RX);
+
         return RT_EOK;
 }
 
@@ -118,6 +130,8 @@ static void dtu_thread_entry_recv(void *parameter)
     static char rx_buffer_tmp2[512];
     while(1)
     {
+        if(device_status.update_flag==1) break;
+        led_tog(1);
         rt_memset(&msg, 0, sizeof(msg));
         // 从消息队列中获取被回调函数放入消息队列中的内容
         result = rt_mq_recv(&rx_mq_dtu, &msg, sizeof(struct rx_msg), 50);
@@ -211,6 +225,7 @@ static void dtu_thread_entry_send(void *parameter)
     static rt_uint8_t power_i = 0;
     while(1)
     {
+        if(device_status.update_flag==1) break;
         time_t now_t;
         time(&now_t);
         static struct tm now_tm;   //现在
@@ -1430,7 +1445,6 @@ int parseDtu(char *json_string)
               else if (strstr(item_cmd->valuestring,"reboot")!=RT_NULL)
               {
                   char *restart = makeJson_Warn("sysrem will restart","control");
-                  rt_kprintf("%s\n",restart);
                   rt_thread_delay(2000);
                   DTU_Write("%s",restart);
                   rt_hw_cpu_reset();
@@ -1445,13 +1459,12 @@ int parseDtu(char *json_string)
             }
               else if (strstr(item_cmd->valuestring,"update")!=RT_NULL)
               {
-                  rt_kprintf("准备升级!!!");
-                  device_status.update_flag = 1;
-                  ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));
-                  rt_kprintf("%s\n",makeJson_Warn("system will update","control"));
-                  rt_thread_delay(2000);
+                  LOG_W("启动升级!!!");
                   DTU_Write("%s",makeJson_Warn("system will update","control"));
-                  rt_thread_delay(20);
+                  rt_thread_delay(2000);
+                  device_status.update_flag = 1;
+                  ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));;
+                  rt_thread_delay(1000);
                   rt_hw_cpu_reset();
               }
               else if (strstr(item_cmd->valuestring,"read")!=RT_NULL)
@@ -1867,7 +1880,6 @@ int parseDtu(char *json_string)
                                       LOG_E("加热温度hst设置失败参数错误!!!");
                                 }
                             }
-
                           }
 #if 1  //三色光源无法修改开始和结束时间
                           if (st!=NULL)
@@ -1895,7 +1907,6 @@ int parseDtu(char *json_string)
                                       LOG_E("开始时间st设置失败参数错误!!!");
                                   }
                               }
-
                           }
                           if(et!=NULL)
                           {

+ 74 - 52
Application_CBD/applications/hmi.c

@@ -1557,9 +1557,12 @@ static void Ctr_Mortor_entry(void* parameter)
             {
                 LOG_I("测试拍照!");
                 #if 1
-                char *takephotojson = makeJson_takephoto();
-                DTU_Write("%s",takephotojson);
-                rt_free(takephotojson);
+                if(device_status.version_type!=41){
+                    char *takephotojson = makeJson_takephoto();
+                    DTU_Write("%s",takephotojson);
+                    rt_free(takephotojson);
+                }
+
                 #endif
                 rt_thread_delay(5000);  //延时
             }
@@ -1571,9 +1574,11 @@ static void Ctr_Mortor_entry(void* parameter)
                 rt_thread_delay(1000);
                 LOG_I("测试拍照!");
                 Hk_Take_io();
-//                char *takephotojson = makeJson_takephoto();
-//                DTU_Write("%s",takephotojson);
-//                rt_free(takephotojson);
+                if(device_status.version_type==41){
+                    char *takephotojson = makeJson_takephoto();
+                    DTU_Write("%s",takephotojson);
+                    rt_free(takephotojson);
+                }
             }
             photo_led_sec--;
             if(photo_led_sec==300)    //
@@ -2099,7 +2104,8 @@ void Check_ParamConfig(void)
         ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));
         ymodem_ota(1,0);
     }
-    else {
+    else
+    {
         device_status.update_flag = 0;
         //初始化联网状态
         rt_sprintf(device_status.net,"1");
@@ -2163,7 +2169,8 @@ void Check_ParamConfig(void)
             if(connect_num>5) break;
         }
         if(device_status.version_type==6) device_status.timeSwitch = 1;
-        DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
+        if(device_status.update_flag==0)
+            DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
         rt_thread_delay(1000);
         dtu_send_data_start();
 #endif
@@ -2307,54 +2314,69 @@ void app_partion_backup(void)
             }
             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)
+                    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)
                             {
-                                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);
+                                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);
+                    }
             }
 }
+
+int delete_hmi_thread(void)
+{
+    LOG_W("delete_hmi_thread.");
+    if(ctr_motor!=RT_NULL)
+    {
+        rt_thread_delete(ctr_motor);
+    }
+    if(hmi1!=RT_NULL)
+    {
+        rt_thread_delete(hmi1);
+    }
+    return 0;
+}
+
 void Debug_log_ON(void)
 {
     rt_console_set_device("uart4");

+ 2 - 0
Application_CBD/applications/hmi.h

@@ -33,4 +33,6 @@ void app_partion_backup(void);
 void Debug_log_OFF(void);
 void Debug_log_ON(void);
 void bubblesort(int a[], int n);
+
+int delete_hmi_thread(void);
 #endif /* APPLICATIONS_INC_HMI_H_ */

+ 3 - 2
Application_CBD/applications/main.c

@@ -75,7 +75,8 @@ int main(void)
     //看门狗初始化
      wdt_init();
      //打印内存占用
-     memtrace();
+     if(device_status.update_flag==0)
+         memtrace();
 }
 /*初始化看门狗*/
 static int wdt_init(void)
@@ -132,7 +133,7 @@ static void idle_hook(void)
 //    }
     /* 在空闲线程的回调函数里喂狗 */
     rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_KEEPALIVE, NULL);
-    led_tog(1);
+    //led_tog(1);
     //rt_kprintf("feed the dog!\n ");
 }
 /*

+ 16 - 1
Application_CBD/applications/sample_mb_master.c

@@ -32,12 +32,28 @@
 #define MB_SEND_REG_NUM    10
 
 #define MB_POLL_CYCLE_MS   500
+rt_thread_t tid1 = RT_NULL, tid2 = RT_NULL;
 
 Device_Status_typedef device_status;
 
 extern USHORT   usMRegInBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_REG_INPUT_NREGS];
 extern SHORT usMRegHoldBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_REG_HOLDING_NREGS];
 
+int delete_mb_thread(void)
+{
+    if(tid1!=NULL)
+    {
+        rt_thread_delete(tid1);
+    }
+    if(tid2!=NULL)
+    {
+        rt_thread_delete(tid2);
+    }
+    return 0;
+}
+
+
+
 
 static void send_thread_entry(void *parameter)
 {
@@ -142,7 +158,6 @@ static void mb_master_poll(void *parameter)
 int mb_master_samlpe(void)
 {
     static rt_uint8_t is_init = 0;
-    rt_thread_t tid1 = RT_NULL, tid2 = RT_NULL;
 
     if (is_init > 0)
     {

+ 16 - 0
Application_CBD/applications/sht30_collect.c

@@ -563,6 +563,22 @@ int sht30_collect(void)
         rt_thread_startup(tid2);
     return 0;
 }
+
+
+int thread_delete_adc(void)
+{
+    LOG_W("退出ADC采集线程...");
+    if(tid1!=RT_NULL)
+    {
+        rt_thread_delete(tid1);
+    }
+    if(tid2!=RT_NULL)
+    {
+        rt_thread_delete(tid2);
+    }
+    return 0;
+}
+
 //控制台打印传感器信息
 void Msh_DisplaySensor(void)
 {

+ 3 - 0
Application_CBD/applications/sht30_collect.h

@@ -28,6 +28,9 @@ int TempCalculate(float Rv,int B,int BasicRx);
 short Get_Temprate(void);
 unsigned int filter_Mid(int adc_return);
 unsigned int filter_voltage(void);
+
+
+int thread_delete_adc(void);
 #endif /* APPLICATIONS_INC_SHT30_COLLECT_H_ */
 
 //STM32之ADC(内部基准电压,参考电压)

+ 6 - 7
Application_CBD/packages/ota_downloader-latest/src/ymodem_ota.c

@@ -26,8 +26,6 @@
 #include <rtdbg.h>
 
 
-
-
 #ifdef PKG_USING_YMODEM_OTA
 
 #define DEFAULT_DOWNLOAD_PART  RT_FOTA_FM_PART_NAME
@@ -44,7 +42,7 @@ static enum rym_code ymodem_on_begin(struct rym_ctx *ctx, rt_uint8_t *buf, rt_si
     file_name = (char *)&buf[0];
     file_size = (char *)&buf[rt_strlen(file_name) + 1];
     update_file_total_size = atol(file_size);
-    rt_kprintf("Ymodem file_size:%d\n", update_file_total_size);
+    //rt_kprintf("Ymodem file_size:%d\n", update_file_total_size);
 
     update_file_cur_size = 0;
 
@@ -61,7 +59,7 @@ static enum rym_code ymodem_on_begin(struct rym_ctx *ctx, rt_uint8_t *buf, rt_si
         return RYM_CODE_CAN;
     }
 
-    LOG_I("Start erase. Size (%d)", update_file_total_size);
+    //LOG_I("Start erase. Size (%d)", update_file_total_size);
 
     /* erase DL section */
     if (fal_partition_erase(dl_part, 0, update_file_total_size) < 0)
@@ -81,7 +79,7 @@ static enum rym_code ymodem_on_data(struct rym_ctx *ctx, rt_uint8_t *buf, rt_siz
         LOG_E("Firmware download failed! Partition (%s) write data error!", dl_part->name);
         return RYM_CODE_CAN;
     }
-
+    led_tog(1);
     update_file_cur_size += len;
 
     return RYM_CODE_ACK;
@@ -113,8 +111,9 @@ void ymodem_ota(uint8_t argc, char **argv)
         }
     }
     rt_console_set_device("uart2");
-    rt_kprintf("Warning: Ymodem has started! This operator will not recovery.\n");
-    rt_kprintf("Please select the ota firmware file and use Ymodem to send.\n");
+    finsh_set_device("uart2");
+    //rt_kprintf("Warning: Ymodem has started! This operator will not recovery.\n");
+    //rt_kprintf("Please select the ota firmware file and use Ymodem to send.\n");
 
     if (!rym_recv_on_device(&rctx, rt_console_get_device(), RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
                             ymodem_on_begin, ymodem_on_data, NULL, RT_TICK_PER_SECOND))