zhunk před 1 rokem
rodič
revize
0962f6d3e6

+ 20 - 55
Application_cbd_apm32f1/applications/control.c

@@ -152,42 +152,7 @@ uint8_t ctr_Motor_xifu(uint8_t status_ws)
     }
     return 0;
 }
-//清扫-卷带电机
-void ctr_JD_Clear(uint8_t shake_sw)
-{
-    rt_uint16_t turn_timeout = 0;
-    rt_pin_mode(MOTOR_C_LIMIT,PIN_MODE_INPUT);
-    ctr_cangmen_up(OFF);        //清扫传送带的电机
-    if(shake_sw==ON)
-    {
-        ctr_Heat(ON);   //清洁风机
-        Motor_shake(ON, 0);
-        ctr_cangmen_up(OPEN);   //打开清扫
-    }
-    else {
-        Motor_shake(OFF, 0);
-        ctr_cangmen_up(OPEN);   //打开清扫
-    }
-    while(rt_pin_read(MOTOR_C_LIMIT)==0)
-    {
-       Motor_Juandai(ON);
-       rt_thread_delay(50);
-       turn_timeout++;
-       if(turn_timeout==1000) break;
-    }
-    turn_timeout = 0;
-    while(rt_pin_read(MOTOR_C_LIMIT)==1)
-    {
-       Motor_Juandai(ON);
-       turn_timeout++;
-       rt_thread_delay(50);
-       if(turn_timeout==1000) break;
-    }
-    Motor_shake(OFF, 1);
-    Motor_Juandai(OFF);
-    ctr_cangmen_up(OFF);    //关闭清扫
-    ctr_Heat(OFF);
-}
+
 //工作任务流程
 void WorkTask_XCT(void)
 {
@@ -666,28 +631,28 @@ void ctr_Motor_Driver(uint8_t EN,uint8_t DIR,rt_uint32_t pwm,rt_uint32_t time_ou
 
     rt_pin_write(Motor_DIR, DIR);
     beep_set(pwm, pwm/2);      //200kzh - 50%
-    while(DIR==1&&rt_pin_read(LIMIT_DOWN)==1)
-    {
-        if(time_out==0)
-        {
-            break;
-        }
-        rt_thread_delay(50);
-        time_out --;
-    }
-    while(DIR==0&&rt_pin_read(LIMIT_UP)==1)
-    {
-        if(time_out==0)
-        {
-            break;
-        }
-        rt_thread_delay(50);
-        time_out --;
-    }
+//    while(DIR==1&&rt_pin_read(LIMIT_DOWN)==1)
+//    {
+//        if(time_out==0)
+//        {
+//            break;
+//        }
+//        rt_thread_delay(50);
+//        time_out --;
+//    }
+//    while(DIR==0&&rt_pin_read(LIMIT_UP)==1)
+//    {
+//        if(time_out==0)
+//        {
+//            break;
+//        }
+//        rt_thread_delay(50);
+//        time_out --;
+//    }
     //rt_pin_write(Motor_EN, OFF);
     //if(device_status.autotakepic==0)
     //ctr_lamp(OFF, 1);
-    beep_set(0, 0);      //200kzh - 50%
+//    beep_set(0, 0);      //200kzh - 50%
     rt_thread_delay(50);
 }
 /*************************************************

+ 21 - 1
Application_cbd_apm32f1/applications/control.h

@@ -191,6 +191,12 @@ typedef struct
     char OP_MOTOR_2[8];
     char OP_MOTOR_3[8];
 
+    float VOLTAGE_5V;
+    float VOLTAGE_12V;
+    float VOLTAGE_3_3V;
+
+    float MCU_T;
+
     uint16_t ADC_1;                 //ADC通道1数值
     uint16_t ADC_2;                 //ADC通道2数值
     uint16_t ADC_3;                 //ADC通道3数值
@@ -225,6 +231,17 @@ typedef struct
     uint8_t  FLASH_WRITE_STA;
     uint8_t  FLASH_READ_STA;
 
+    uint8_t  IN_1_STA;
+    uint8_t  IN_2_STA;
+    uint8_t  IN_3_STA;
+    uint8_t  IN_4_STA;
+
+    uint8_t  VOLTAGE_5V_STA;
+    uint8_t  VOLTAGE_12V_STA;
+    uint8_t  VOLTAGE_3V3_STA;
+
+    uint8_t  MCU_TEMPTURE_STA;
+
     uint8_t  RESULT;                //自检结果,0-通过,1-失败
     uint8_t list_all;               //检测总数
     uint8_t checked;                //已检测
@@ -308,7 +325,10 @@ typedef struct
 #define MOTOR_CR_PIN GET_PIN(C,7)
 #define MOTOR_CL_PIN GET_PIN(C,8)
 
-#define MOTOR_C_LIMIT GET_PIN(C,13)       //卷带限位
+#define IO_IN1 GET_PIN(C,13)      //限位1
+#define IO_IN2 GET_PIN(B,9)       //限位2
+#define IO_IN3 GET_PIN(B,8)       //限位3
+#define IO_IN4 GET_PIN(B,5)       //限位4
 
 void ctr_JD_Clear(uint8_t shake_sw);
 uint8_t ctr_Motor_xichong(uint8_t status_ws);

+ 1 - 0
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -1071,6 +1071,7 @@ int parseDtu(char *json_string)
             check_results.UATR_2_TX_STA = 1;
             check_results.UATR_4_RX_STA = 1;
         }
+
         cJSON_Delete(root);
     }
     return 0;

+ 179 - 17
Application_cbd_apm32f1/applications/hmi.c

@@ -32,6 +32,7 @@
 #define DBG_TAG "hmi"
 #define DBG_LEVEL         DBG_LOG
 #include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
+#include <cJSON.h>
 
 #define HMI_THREAD_PRIORITY         5          //线程优先级
 #define HMI_THREAD_STACK_SIZE       2048        //线程栈空间大小
@@ -149,6 +150,41 @@ static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
     return result;
 }
 
+//JSON数据解析
+int parsehmi(char *json_string)
+{
+    cJSON *root = cJSON_Parse(json_string);
+    if(!root)
+    {
+        cJSON_Delete(root);
+        LOG_E("parse json err:%s",json_string);
+        return -1;
+    }
+    else
+    {
+        LOG_I("解析JSON:%s",json_string);
+        cJSON *item2 = cJSON_GetObjectItem(root,"write");
+        cJSON *item3 = cJSON_GetObjectItem(root,"message");
+        cJSON *item4 = cJSON_GetObjectItem(root,"status");
+        cJSON *item5 = cJSON_GetObjectItem(root,"UART2");
+
+        if(item5!=RT_NULL&&
+                item2!=RT_NULL&&
+                item3!=RT_NULL&&
+                item4!=RT_NULL)
+        {
+            check_results.UATR_2_TX_STA = 0;
+            check_results.UATR_4_RX_STA = 0;
+        }else {
+            check_results.UATR_2_TX_STA = 1;
+            check_results.UATR_4_RX_STA = 1;
+        }
+
+        cJSON_Delete(root);
+    }
+    return 0;
+}
+
 
 /*入口函数*/
 static void Hmi_thread_entry(void *parameter)
@@ -181,7 +217,7 @@ static void Hmi_thread_entry(void *parameter)
             rt_sprintf(str_check_end, "%c",rx_buffer[rx_length-1]);
             if(str_check_end[0]==str_check[1]&&str_check_head[0]==str_check[0])
             {
-                  parseDtu(rx_buffer);
+                    parsehmi(rx_buffer);
                   rt_memset(rx_buffer,0,sizeof(rx_buffer));
                   rt_memset(rx_buffer_tmp,0,sizeof(rx_buffer_tmp));
                   rt_memset(rx_buffer_tmp2,0,sizeof(rx_buffer_tmp2));
@@ -194,7 +230,7 @@ static void Hmi_thread_entry(void *parameter)
                    else {
                        rt_sprintf(rx_buffer_tmp2,"%s",rx_buffer);
                        rt_sprintf(rx_buffer, "%s%s",rx_buffer_tmp,rx_buffer_tmp2);
-                       parseDtu(rx_buffer);
+                       parsehmi(rx_buffer);
                        rt_memset(rx_buffer,0,sizeof(rx_buffer));
                        rt_memset(rx_buffer_tmp,0,sizeof(rx_buffer_tmp));
                        rt_memset(rx_buffer_tmp2,0,sizeof(rx_buffer_tmp2));
@@ -260,9 +296,64 @@ int Hmi_Fresh(void)
 }
 
 
+void callback_IN1(void *args)
+{
+    LOG_W("callback_IN1!");
+    check_results.IN_1_STA = 0;
+}
+
+void callback_IN2(void *args)
+{
+    LOG_W("callback_IN2!");
+    check_results.IN_2_STA = 0;
+}
+
+void callback_IN3(void *args)
+{
+    LOG_W("callback_IN3!");
+    check_results.IN_3_STA = 0;
+}
+
+void callback_IN4(void *args)
+{
+    LOG_W("callback_IN4!");
+    check_results.IN_4_STA = 0;
+}
 
 void Check_ParamConfig(void)
 {
+    rt_tick_t start, end;
+    start = rt_tick_get(); // 获取当前tick值
+    check_results.IN_1_STA = 1;
+    check_results.IN_2_STA = 1;
+    check_results.IN_3_STA = 1;
+    check_results.IN_4_STA = 1;
+    /* PC14引脚为输入模式 */
+    rt_pin_mode(IO_IN1, PIN_MODE_INPUT);
+    /* 绑定中断,下降沿模式,回调函数名为guanshan_on */
+    rt_pin_attach_irq(IO_IN1, PIN_IRQ_MODE_RISING, callback_IN1, RT_NULL);
+    /* 使能中断 */
+    rt_pin_irq_enable(IO_IN1, PIN_IRQ_ENABLE);
+
+
+    rt_pin_mode(IO_IN2, PIN_MODE_INPUT);
+    /* 绑定中断,下降沿模式,回调函数名为guanshan_on */
+    rt_pin_attach_irq(IO_IN2, PIN_IRQ_MODE_RISING, callback_IN2, RT_NULL);
+    /* 使能中断 */
+    rt_pin_irq_enable(IO_IN2, PIN_IRQ_ENABLE);
+
+    rt_pin_mode(IO_IN3, PIN_MODE_INPUT);
+    /* 绑定中断,下降沿模式,回调函数名为guanshan_on */
+    rt_pin_attach_irq(IO_IN3, PIN_IRQ_MODE_RISING, callback_IN3, RT_NULL);
+    /* 使能中断 */
+    rt_pin_irq_enable(IO_IN3, PIN_IRQ_ENABLE);
+
+    rt_pin_mode(IO_IN4, PIN_MODE_INPUT);
+    /* 绑定中断,下降沿模式,回调函数名为guanshan_on */
+    rt_pin_attach_irq(IO_IN4, PIN_IRQ_MODE_RISING, callback_IN4, RT_NULL);
+    /* 使能中断 */
+    rt_pin_irq_enable(IO_IN4, PIN_IRQ_ENABLE);
+
     EfErrCode ec_ef= 0;
     uint16_t current_1 = 0;
     ctr_photo(OFF);
@@ -319,6 +410,7 @@ void Check_ParamConfig(void)
         Beep_Tip(2000);
         return;
     }
+    LOG_I("负载电流:%d",current);
     if(voltage_<=23)
     {
         check_results.VOLTAGE_24V_STA = 1;
@@ -368,7 +460,7 @@ void Check_ParamConfig(void)
         LOG_W("24V输出通道2正常!");
         check_results.OP_24V_2_STA = 0;
     }else {
-        LOG_W("24V输出通道2负载电流异常!");
+        LOG_E("24V输出通道2负载电流异常!");
         check_results.OP_24V_2_STA = 1;
     }
 
@@ -386,7 +478,7 @@ void Check_ParamConfig(void)
         LOG_W("24V输出通道3正常!");
         check_results.OP_24V_3_STA = 0;
     }else {
-        LOG_W("24V输出通道3负载电流异常!");
+        LOG_E("24V输出通道3负载电流异常!");
         check_results.OP_24V_3_STA = 1;
     }
 
@@ -476,7 +568,7 @@ void Check_ParamConfig(void)
         LOG_W("12V输出通道1正常!");
         check_results.OP_12V_1_STA = 0;
     }else {
-        LOG_W("12V输出通道1负载电流异常!");
+        LOG_E("12V输出通道1负载电流异常!");
         check_results.OP_12V_1_STA = 1;
     }
 
@@ -489,12 +581,12 @@ void Check_ParamConfig(void)
     LOG_I("12V输出通道2负载电流:[%d]mA",current_);
     LOG_I("关闭12V输出通道2...");
     ctr_photo(OFF);
-    if(current_-current>700)
+    if(current_-current>500)
     {
         LOG_W("12V输出通道2正常!");
         check_results.OP_12V_2_STA = 0;
     }else {
-        LOG_W("12V输出通道2负载电流异常!");
+        LOG_E("12V输出通道2负载电流异常!");
         check_results.OP_12V_2_STA = 1;
     }
 
@@ -507,7 +599,7 @@ void Check_ParamConfig(void)
     LOG_I("5V输出通道1负载电流:[%d]mA",current_);
     LOG_I("关闭5V输出通道1...");
     ctr_led(OFF);
-    if(current_-current>200)
+    if(current_-current>100)
     {
         LOG_W("5V输出通道1正常!");
         check_results.OP_5V_1_STA = 0;
@@ -543,19 +635,18 @@ void Check_ParamConfig(void)
           check_results.ADC3_STA ? "异常" : "正常");
 
 
-    LOG_W("********UART2RX:%s %s",
-          device_status.power,
+    LOG_W("********UART2RX:%s",
           check_results.UATR_2_RX_STA ? "异常" : "正常");
-    LOG_W("********UART2TX:%s %s",
-          device_status.power,
+    LOG_W("********UART2TX:%s",
           check_results.UATR_2_TX_STA ? "异常" : "正常");
-    LOG_W("********UART4RX:%s %s",
-          device_status.power,
+    LOG_W("********UART4RX:%s",
           check_results.UATR_4_RX_STA ? "异常" : "正常");
-
-    LOG_W("********UART4TX:%s %s",
-          device_status.power,
+    LOG_W("********UART4TX:%s",
           check_results.UATR_4_TX_STA ? "异常" : "正常");
+
+    LOG_W("********UART 485:%s",
+          check_results.UART_485_STA ? "异常" : "正常");
+
     LOG_W("********24V通道1负载电流:%s %s",
           check_results.OP_24V_1,
           check_results.OP_24V_1_STA ? "异常" : "正常");
@@ -596,6 +687,77 @@ void Check_ParamConfig(void)
           check_results.OP_MOTOR_3,
           check_results.OP_MOTOR_3_STA ? "异常" : "正常");
 
+    LOG_W("********IO输入检测通道1:%s",
+          check_results.IN_1_STA ? "异常" : "正常");
+
+    LOG_W("********IO输入检测通道2:%s",
+          check_results.IN_2_STA ? "异常" : "正常");
+
+    LOG_W("********IO输入检测通道3:%s",
+          check_results.IN_3_STA ? "异常" : "正常");
+
+    LOG_W("********IO输入检测通道4:%s",
+          check_results.IN_4_STA ? "异常" : "正常");
+
+    LOG_W("********12V电压检测:%f %s",
+            check_results.VOLTAGE_12V,
+            check_results.VOLTAGE_12V_STA ? "异常" : "正常");
+    LOG_W("********5V电压检测:%f %s",
+            check_results.VOLTAGE_5V,
+            check_results.VOLTAGE_3V3_STA ? "异常" : "正常");
+
+    LOG_W("********3.3V电压检测:%f %s",
+            check_results.VOLTAGE_3_3V,
+            check_results.VOLTAGE_3V3_STA ? "异常" : "正常");
+
+
+
+    if(check_results.ADC1_STA ||
+            check_results.ADC2_STA ||
+            check_results.ADC3_STA ||
+            check_results.CURRENT_24V_STA ||
+            check_results.FLASH_READ_STA ||
+            check_results.FLASH_WRITE_STA ||
+            check_results.IN_1_STA ||
+            check_results.IN_2_STA ||
+            check_results.IN_3_STA ||
+            check_results.IN_4_STA ||
+            check_results.MCU_TEMPTURE_STA ||
+            check_results.OP_12V_1_STA ||
+            check_results.OP_12V_2_STA ||
+            check_results.OP_24V_1_STA ||
+            check_results.OP_24V_2_STA ||
+            check_results.OP_24V_3_STA ||
+            check_results.OP_24V_4_STA ||
+            check_results.OP_5V_1_STA ||
+            check_results.OP_MOTOR_1_STA ||
+            check_results.OP_MOTOR_2_STA ||
+            check_results.OP_MOTOR_3_STA ||
+            check_results.UART_485_STA ||
+            check_results.UATR_2_RX_STA ||
+            check_results.UATR_2_TX_STA ||
+            check_results.UATR_4_RX_STA ||
+            check_results.UATR_4_TX_STA ||
+            check_results.VOLTAGE_12V_STA ||
+            check_results.VOLTAGE_24V_STA ||
+            check_results.VOLTAGE_3V3_STA ||
+            check_results.VOLTAGE_5V_STA)
+    {
+        check_results.RESULT = 1;
+        LOG_E("********检测结果:%s",
+                check_results.RESULT ? "不通过" : "通过");
+        ef_set_and_save_env("RESULT", "不通过");
+    }else {
+        check_results.RESULT = 0;
+        LOG_I("********检测结果:%s",
+                check_results.RESULT ? "不通过" : "通过");
+        ef_set_and_save_env("RESULT", "通过");
+    }
+    ctr_Motor_Driver(1,1,0,0);
+    end = rt_tick_get();
+    rt_uint32_t  elapsed = end - start; // 计算消耗的tick数
+    LOG_W("耗时  %d ms %d s.\n", elapsed * (1000 / RT_TICK_PER_SECOND),elapsed * (1000 / RT_TICK_PER_SECOND)/1000);
+
 }
 
 

+ 2 - 0
Application_cbd_apm32f1/applications/main.c

@@ -33,6 +33,8 @@ int main(void)
     clock_information();
     Beep_Tip(100);
     //初始化
+    ctr_Motor_Driver(1,1,500000,0);
+    mb_master_samlpe();
     Check_ParamConfig();
     //打印内存占用
     //memtrace(0, NULL);

+ 85 - 36
Application_cbd_apm32f1/applications/sample_mb_master.c

@@ -12,6 +12,14 @@
 #include <user_mb_app.h>
 #include "control.h"
 #include "hmi.h"
+#include "math.h"
+
+#define DBG_ENABLE
+#define DBG_COLOR
+#define DBG_TAG "mb"
+#define DBG_LEVEL         DBG_LOG
+#include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
+
 #ifdef PKG_MODBUS_MASTER_SAMPLE
 #define SLAVE_ADDR      MB_SAMPLE_TEST_SLAVE_ADDR
 #define PORT_NUM        MB_MASTER_USING_PORT_NUM
@@ -34,6 +42,7 @@
 #define MB_POLL_CYCLE_MS   500
 
 Device_Status_typedef device_status;
+CheckResult check_results;
 
 extern USHORT   usMRegInBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_REG_INPUT_NREGS];
 extern SHORT usMRegHoldBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_REG_HOLDING_NREGS];
@@ -62,16 +71,21 @@ extern eMBMasterReqErrCode write_single_holding_register(UCHAR ucSndAddr, USHORT
     return _code_ret;
 }
 
+int float_equal(float a, float b, float epsilon) {
+    return fabsf(a - b) <= epsilon;
+}
+
 
 static void send_thread_entry(void *parameter)
 {
     BOOL IN_3A = 0;           //数据解析方式设置
     eMBMasterReqErrCode error_code = MB_MRE_NO_ERR;
     rt_uint16_t error_count = 0;
+    check_results.UART_485_STA = 1;
     while (1)
     {
 
-        #if 0
+        #if 1
         error_code = eMBMasterReqReadInputRegister(SLAVE_ADDR, MB_SEND_REG_START,3,1000);
         rt_kprintf("eMBMasterReqReadInputRegister: %d \n",error_code);//一直出错,把错误返回值打印出来
         if(error_code==0)
@@ -86,47 +100,82 @@ static void send_thread_entry(void *parameter)
             for(int i=0;i<3;i++){
                 rt_kprintf("usMRegInBuf:%d-%u\n",i,usMRegInBuf[0][i]);
             }
-            rt_sprintf(device_status.voltage_sun,"%d.%d",usMRegInBuf[0][0]/100,usMRegInBuf[0][0]%100/10);
-            //太阳能板电压
-            HMI_WRITE("menu.g0.txt=\"太阳能板电压:%sV\"",device_status.voltage_sun);
-        }else{
-            rt_sprintf(device_status.voltage_sun,"%s","0.0");
-        }
-        #endif
-        if(device_status.sensor_485_sta!=200){
+            check_results.VOLTAGE_5V = (float)usMRegInBuf[0][0]/100;
+            check_results.VOLTAGE_12V = (float)usMRegInBuf[0][1]/100;
+            check_results.VOLTAGE_3_3V = (float)usMRegInBuf[0][2]/100;
+            if(float_equal(check_results.VOLTAGE_5V,5.0f,0.5f))
+            {
+                LOG_I("5V测量值在误差范围内");
+                check_results.VOLTAGE_5V_STA = 0;
+            }else {
+                check_results.VOLTAGE_5V_STA = 1;
+                LOG_E("超过允许误差:期望%.2f,实际%.2f", 5.00f, check_results.VOLTAGE_5V);
+            }
 
-            error_code = eMBMasterReqReadHoldingRegister(SLAVE_ADDR, MB_SEND_REG_START,2,1000);//读多个保持寄存器
-            // 发送写多个保持寄存器请求
-            //error_code = eMBMasterReqWriteMultipleHoldingRegister(SLAVE_ADDRESS,REGISTER_ADDRESS,REGISTER_COUNT,usDataBuffer,1000);
-            rt_kprintf("eMBMasterReqReadHoldingRegister: %d \n",error_code);//一直出错,我便把错误返回值打印出来
-            if(error_code==0)
+            if(float_equal(check_results.VOLTAGE_12V,12.60,0.50))
             {
-                device_status.sensor_485_sta = 100;
-                error_count = 0;
-                //温度=25并且湿度=30不更新,否则会导致屏幕上显示空
-    //            if((int)usMRegHoldBuf[0][0]/10!=25&&(int)usMRegHoldBuf[0][1]/10!=30)
-    //            {
-                    rt_sprintf(device_status.tempture,"%d.%d",(int)usMRegHoldBuf[0][0]/100, (unsigned int)usMRegHoldBuf[0][0] % 100);
-                    rt_sprintf(device_status.humidity,"%d.%d",(int)usMRegHoldBuf[0][1]/100, (unsigned int)usMRegHoldBuf[0][1] % 100);
-    //                sprintf(device_status.tempture,"%0.01f",(float)usMRegHoldBuf[0][0]/100);
-    //                sprintf(device_status.humidity,"%0.01f",(float)usMRegHoldBuf[0][1]/100);
-    //            }
-                    //rt_thread_delay(1000);
+                check_results.VOLTAGE_12V_STA = 0;
+                LOG_I("12V测量值在误差范围内");
+            }else {
+                check_results.VOLTAGE_12V_STA = 1;
+                LOG_E("超过允许误差:期望%.2f,实际%.2f", 12.60f, check_results.VOLTAGE_12V);
             }
-        }
-        rt_kprintf("slave data-tem:%d,hum:%d\n",usMRegHoldBuf[0][0],usMRegHoldBuf[0][1]);//0代表从机ID=1
-        rt_kprintf("slave data-tem:%s,hum:%s\n",device_status.tempture,device_status.humidity);//0代表从机ID=1
-        rt_thread_delay(5000);
-        /* Record the number of errors */
-        if (error_code != 0)
-        {
-            error_count++;
-            if(error_count == 10)
+
+            if(float_equal(check_results.VOLTAGE_3_3V,3.30,0.20))
             {
-                error_count = 0;
-                device_status.sensor_485_sta = 0;
+                check_results.VOLTAGE_3V3_STA = 0;
+                LOG_I("3.3V测量值在误差范围内");
+            }else {
+                check_results.VOLTAGE_3V3_STA = 1;
+                LOG_E("超过允许误差:期望%.2f,实际%.2f", 3.30f, check_results.VOLTAGE_3_3V);
             }
+
+            //太阳能板电压
+            LOG_I("采集电压5V:%0.01f V\"",check_results.VOLTAGE_5V);
+            LOG_I("采集电压12V:%0.01f V\"",check_results.VOLTAGE_12V);
+            LOG_I("采集电压3.3V:%0.01f V\"",check_results.VOLTAGE_3_3V);
+            check_results.UART_485_STA = 0;
+        }else{
+            check_results.VOLTAGE_12V_STA = 1;
+            check_results.VOLTAGE_3V3_STA = 1;
+            check_results.VOLTAGE_5V_STA = 1;
+            check_results.UART_485_STA = 1;
         }
+        #endif
+//        if(device_status.sensor_485_sta!=200){
+//
+//            error_code = eMBMasterReqReadHoldingRegister(SLAVE_ADDR, MB_SEND_REG_START,2,1000);//读多个保持寄存器
+//            // 发送写多个保持寄存器请求
+//            //error_code = eMBMasterReqWriteMultipleHoldingRegister(SLAVE_ADDRESS,REGISTER_ADDRESS,REGISTER_COUNT,usDataBuffer,1000);
+//            rt_kprintf("eMBMasterReqReadHoldingRegister: %d \n",error_code);//一直出错,我便把错误返回值打印出来
+//            if(error_code==0)
+//            {
+//                device_status.sensor_485_sta = 100;
+//                error_count = 0;
+//                //温度=25并且湿度=30不更新,否则会导致屏幕上显示空
+//    //            if((int)usMRegHoldBuf[0][0]/10!=25&&(int)usMRegHoldBuf[0][1]/10!=30)
+//    //            {
+//                    rt_sprintf(device_status.tempture,"%d.%d",(int)usMRegHoldBuf[0][0]/100, (unsigned int)usMRegHoldBuf[0][0] % 100);
+//                    rt_sprintf(device_status.humidity,"%d.%d",(int)usMRegHoldBuf[0][1]/100, (unsigned int)usMRegHoldBuf[0][1] % 100);
+//    //                sprintf(device_status.tempture,"%0.01f",(float)usMRegHoldBuf[0][0]/100);
+//    //                sprintf(device_status.humidity,"%0.01f",(float)usMRegHoldBuf[0][1]/100);
+//    //            }
+//                    //rt_thread_delay(1000);
+//            }
+//        }
+//        rt_kprintf("slave data-tem:%d,hum:%d\n",usMRegHoldBuf[0][0],usMRegHoldBuf[0][1]);//0代表从机ID=1
+//        rt_kprintf("slave data-tem:%s,hum:%s\n",device_status.tempture,device_status.humidity);//0代表从机ID=1
+//        rt_thread_delay(5000);
+//        /* Record the number of errors */
+//        if (error_code != 0)
+//        {
+//            error_count++;
+//            if(error_count == 10)
+//            {
+//                error_count = 0;
+//                device_status.sensor_485_sta = 0;
+//            }
+//        }
     }
 }
 

+ 10 - 8
Application_cbd_apm32f1/applications/sht30_collect.c

@@ -174,10 +174,13 @@ static void sht30_collect_thread_entry(void *parameter)
         }else {
             check_results.ADC3_STA = 1;
         }
-
-        LOG_I("电压:%s,电流:%s,电流2:%s",device_status.voltage,device_status.power,device_status.heat_power);
-        LOG_I("ADC_LIGHT:%d,ADC_RAIN:%d,ADC_TEMPTURE:%d",check_results.ADC_1,check_results.ADC_2,check_results.ADC_3);
-        LOG_I("MCU温度:%d.%d℃",Get_Temprate()/100,Get_Temprate()%100);
+        check_results.MCU_T = (float)Get_Temprate()/100;
+        if(check_results.MCU_T>50.0f)
+        {
+            check_results.MCU_TEMPTURE_STA = 1;
+        }else {
+            check_results.MCU_TEMPTURE_STA = 0;
+        }
         rt_thread_mdelay(5000);
     }
 }
@@ -488,10 +491,9 @@ int sht30_collect(void)
 //控制台打印传感器信息
 void Msh_DisplaySensor(void)
 {
-    rt_kprintf("温度:%d\n",tem_value);
-    rt_kprintf("湿度:%d\n",hum_value);
-    rt_kprintf("电压:%s\n",device_status.voltage);
-    rt_kprintf("电流:%s\n",device_status.power);
+    LOG_I("电压:%s,电流:%s,电流2:%s",device_status.voltage,device_status.power,device_status.heat_power);
+    LOG_I("ADC_LIGHT:%d,ADC_RAIN:%d,ADC_TEMPTURE:%d",check_results.ADC_1,check_results.ADC_2,check_results.ADC_3);
+    LOG_I("MCU温度:%f ℃",check_results.MCU_T);
 }
 MSH_CMD_EXPORT(Msh_DisplaySensor,Msh_DisplaySensor);
 MSH_CMD_EXPORT(Read_Rain_Voltage,Read_Rain_Voltage);

+ 1 - 1
Application_cbd_apm32f1/rt-thread/src/kservice.c

@@ -1315,7 +1315,7 @@ RT_WEAK int rt_kprintf(const char *fmt, ...)
      * large excluding the terminating null byte. If the output string
      * would be larger than the rt_log_buf, we have to adjust the output
      * length. */
-    length = rt_vsnprintf(rt_log_buf, sizeof(rt_log_buf) - 1, fmt, args);
+    length = vsnprintf(rt_log_buf, sizeof(rt_log_buf) - 1, fmt, args);
     if (length > RT_CONSOLEBUF_SIZE - 1)
         length = RT_CONSOLEBUF_SIZE - 1;
 #ifdef RT_USING_DEVICE