|
|
@@ -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);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|