|
|
@@ -0,0 +1,281 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2006-2021, RT-Thread Development Team
|
|
|
+ *
|
|
|
+ * SPDX-License-Identifier: Apache-2.0
|
|
|
+ *
|
|
|
+ * Change Logs:
|
|
|
+ * Date Author Notes
|
|
|
+ * 2024-09-29 Administrator the first version
|
|
|
+ */
|
|
|
+#include <rtthread.h>
|
|
|
+#include <cJSON.h>
|
|
|
+#include <control.h>
|
|
|
+#include "selfcheck.h"
|
|
|
+#include <hmi.h>
|
|
|
+#include <dtu_uart2.h>
|
|
|
+#define DBG_ENABLE
|
|
|
+#define DBG_COLOR
|
|
|
+#define DBG_TAG "selfcheck"
|
|
|
+#define DBG_LEVEL DBG_LOG
|
|
|
+#include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
|
|
|
+
|
|
|
+
|
|
|
+rt_timer_t timer_takephoto = RT_NULL;
|
|
|
+Device_Status_typedef device_status;
|
|
|
+
|
|
|
+static int calculate_average(int arr[], int n) {
|
|
|
+ int sum = 0; // 用于存储数组元素的总和
|
|
|
+ for (int i = 0; i < n; i++) {
|
|
|
+ sum += arr[i]; // 累加每个元素
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算平均值
|
|
|
+ int average = sum / n; // 强制类型转换确保得到浮点数结果
|
|
|
+ return average;
|
|
|
+}
|
|
|
+
|
|
|
+static void t_takephoto_callback(void *parameter)
|
|
|
+{
|
|
|
+ device_status.C01 |= (1<<2);
|
|
|
+ device_status.C01 |= (1<<3);
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"拍照超时\"");
|
|
|
+ LOG_E("t_takephoto_callback");
|
|
|
+}
|
|
|
+
|
|
|
+int selfcheck(uint8_t type)
|
|
|
+{
|
|
|
+ uint16_t C01 = 0;
|
|
|
+ int current_i[6];
|
|
|
+ int current_,current_open = 0;
|
|
|
+ //删除workloop线程 防止自动运行干扰
|
|
|
+ LOG_I("删除线程workloop:%d",thread_delete_workloop());
|
|
|
+ //初始化硬件
|
|
|
+ HardWare_Init(0);
|
|
|
+ /********************************************************/
|
|
|
+ //读取5次电流值,取平均值
|
|
|
+ for(int i = 0;i<5;i++)
|
|
|
+ {
|
|
|
+ current_i[i] = atoi(device_status.power);
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ }
|
|
|
+ current_ = calculate_average(current_i,5);
|
|
|
+ if(current_<50||current_>3000)
|
|
|
+ {
|
|
|
+ device_status.C01 |= (1<<12);
|
|
|
+ HMI_WRITE("selfcheck.t13.bco=63488");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ HMI_WRITE("selfcheck.t13.bco=2024");
|
|
|
+ device_status.C01 &= ~(1<<12);
|
|
|
+ }
|
|
|
+ if(atoi(device_status.gps_state)==0)
|
|
|
+ {
|
|
|
+ HMI_WRITE("selfcheck.t12.bco=63488");
|
|
|
+ device_status.C01 |= (1<<11);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ HMI_WRITE("selfcheck.t12.bco=2024");
|
|
|
+ device_status.C01 &= ~(1<<11);
|
|
|
+ }
|
|
|
+ if(device_status.bat_status==0)
|
|
|
+ {
|
|
|
+ HMI_WRITE("selfcheck.t5.bco=2024");
|
|
|
+ device_status.C01 &= ~(1<<4);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ HMI_WRITE("selfcheck.t5.bco=63488");
|
|
|
+ device_status.C01 |= (1<<4);
|
|
|
+ }
|
|
|
+ if(device_status.rain_status)
|
|
|
+ {
|
|
|
+ HMI_WRITE("selfcheck.t6.bco=63488");
|
|
|
+ device_status.C01 |= (1<<5);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ device_status.C01 &= ~(1<<5);
|
|
|
+ HMI_WRITE("selfcheck.t6.bco=2024");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(device_status.temp_status)
|
|
|
+ {
|
|
|
+ HMI_WRITE("selfcheck.t8.bco=63488");
|
|
|
+ device_status.C01 |= (1<<7);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ device_status.C01 &= ~(1<<7);
|
|
|
+ HMI_WRITE("selfcheck.t8.bco=2024");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(device_status.sun_status)
|
|
|
+ {
|
|
|
+ HMI_WRITE("selfcheck.t7.bco=63488");
|
|
|
+ device_status.C01 |= (1<<6);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ device_status.C01 &= ~(1<<6);
|
|
|
+ HMI_WRITE("selfcheck.t7.bco=2024");
|
|
|
+ }
|
|
|
+
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ /********************************************************/
|
|
|
+ ctr_lamp(ON, 0); //打开镇流器
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ for(int i = 0;i<5;i++)
|
|
|
+ {
|
|
|
+ current_i[i] = atoi(device_status.power);
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ }
|
|
|
+ ctr_lamp(OFF, 0); //关闭镇流器
|
|
|
+ current_open = calculate_average(current_i,5);
|
|
|
+ LOG_I("待机电流:%d",current_);
|
|
|
+ LOG_I("镇流器开启电流:%d",current_open);
|
|
|
+ if(current_open-current_>100)
|
|
|
+ {
|
|
|
+ HMI_WRITE("selfcheck.t1.bco=2024");
|
|
|
+ device_status.C01 &= ~(1<<0);
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"灯管正常\"");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ HMI_WRITE("selfcheck.t1.bco=63488");
|
|
|
+ device_status.C01 |= (1<<0);
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"灯管异常\"");
|
|
|
+ }
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ /********************************************************/
|
|
|
+ //打开上仓门
|
|
|
+ ctr_cangmen_up(OPEN);
|
|
|
+ for(int i = 0;i<5;i++)
|
|
|
+ {
|
|
|
+ current_i[i] = atoi(device_status.power);
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ }
|
|
|
+ ctr_cangmen_up(OFF);
|
|
|
+ current_open = calculate_average(current_i,5);
|
|
|
+ if(current_open-current_>100)
|
|
|
+ {
|
|
|
+ HMI_WRITE("selfcheck.t9.bco=2024");
|
|
|
+ device_status.C01 &= ~(1<<8);
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"上仓门正常\"");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ HMI_WRITE("selfcheck.t9.bco=63488");
|
|
|
+ device_status.C01 |= (1<<8);
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"上仓门故障\"");
|
|
|
+ }
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ /********************************************************/
|
|
|
+ //打开下仓门
|
|
|
+ ctr_cangmen_down(OPEN);
|
|
|
+ for(int i = 0;i<5;i++)
|
|
|
+ {
|
|
|
+ current_i[i] = atoi(device_status.power);
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ }
|
|
|
+ ctr_cangmen_down(OFF);
|
|
|
+ current_open = calculate_average(current_i,5);
|
|
|
+ if(current_open-current_>100)
|
|
|
+ {
|
|
|
+ HMI_WRITE("selfcheck.t10.bco=2024");
|
|
|
+ device_status.C01 &= ~(1<<9);
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"下仓门正常\"");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ HMI_WRITE("selfcheck.t10.bco=63488");
|
|
|
+ device_status.C01 |= (1<<9);
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"下仓门故障\"");
|
|
|
+ }
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ /********************************************************/
|
|
|
+ //记录当前电压、温度探头温度
|
|
|
+ float voltage_off = atof(device_status.voltage);
|
|
|
+ uint8_t heat_temp_off = device_status.heattem;
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"当前电压:%s-温度:%d\"",device_status.voltage,heat_temp_off);
|
|
|
+ //开启加热
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ ctr_Heat(ON);
|
|
|
+ //持续1分钟
|
|
|
+ for(int i = 60;i>0;i--)
|
|
|
+ {
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"加热测试中...%d\"",i);
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ }
|
|
|
+ LOG_I("当前温度:%d电压:%s",device_status.heatvalue,device_status.voltage);
|
|
|
+ //比较当前电压、温度探头温度和开启前
|
|
|
+ if((device_status.heattem - heat_temp_off)>=2 || (atof(device_status.voltage) - voltage_off)>=1.5)
|
|
|
+ {
|
|
|
+ HMI_WRITE("selfcheck.t2.bco=2024");
|
|
|
+ device_status.C01 &= ~(1<<1);
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"加热正常\"");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ HMI_WRITE("selfcheck.t2.bco=63488");
|
|
|
+ device_status.C01 |= (1<<1);
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"加热故障\"");
|
|
|
+ }
|
|
|
+ ctr_Heat(OFF);
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ /*********************************************************/
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"开始拍照\"");
|
|
|
+ rt_timer_start(timer_takephoto);
|
|
|
+ HK_TakePhoto();
|
|
|
+ for(int i = 20;i>0;i--)
|
|
|
+ {
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"拍照中...%d\"",i);
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ }
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ /*******************************************************/
|
|
|
+ //清扫
|
|
|
+ device_status.clear_status = 1;
|
|
|
+ rt_thread_delay(2000);
|
|
|
+ for(int i = 0;i<5;i++)
|
|
|
+ {
|
|
|
+ current_i[i] = atoi(device_status.power);
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ }
|
|
|
+ current_open = calculate_average(current_i,5);
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ if(atoi(device_status.power)-current_open>150)
|
|
|
+ {
|
|
|
+ HMI_WRITE("selfcheck.t11.bco=2024");
|
|
|
+ device_status.C01 &= ~(1<<10);
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"清扫正常\"");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ HMI_WRITE("selfcheck.t11.bco=63488");
|
|
|
+ device_status.C01 |= (1<<10);
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"清扫故障\"");
|
|
|
+ }
|
|
|
+ /*******************************************************/
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"故障码:%d\"",device_status.C01);
|
|
|
+ char *js = makeJson_C01_Warn(device_status.C01,1.0);
|
|
|
+ DTU_Write("%s",js);
|
|
|
+ free(js);
|
|
|
+ LOG_I("重启线程workloop:%d",thread_restart_workloop());
|
|
|
+}
|
|
|
+
|
|
|
+int rt_software_timer_init(void)
|
|
|
+{
|
|
|
+ //启动拍照超时定时器
|
|
|
+ timer_takephoto = rt_timer_create("t_takephoto",t_takephoto_callback,RT_NULL, 100000, RT_TIMER_FLAG_ONE_SHOT);
|
|
|
+ if(timer_takephoto==RT_NULL)
|
|
|
+ {
|
|
|
+ LOG_E("rt_timer_create t_takephoto failed!");
|
|
|
+ return RT_ERROR;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return RT_EOK;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+INIT_APP_EXPORT(rt_software_timer_init);
|
|
|
+
|