|
|
@@ -1,889 +0,0 @@
|
|
|
-/*
|
|
|
- * Copyright (c) 2006-2020, RT-Thread Development Team
|
|
|
- *
|
|
|
- * SPDX-License-Identifier: Apache-2.0
|
|
|
- *
|
|
|
- * Change Logs:
|
|
|
- * Date Author Notes
|
|
|
- * 2020-05-26 Administrator the first version
|
|
|
- */
|
|
|
-#include <rtthread.h>
|
|
|
-#include "hmi.h"
|
|
|
-#include <board.h>
|
|
|
-#include <control.h>
|
|
|
-#include <rtdevice.h>
|
|
|
-#include <stdio.h>
|
|
|
-#include <stdlib.h>
|
|
|
-#include <string.h>
|
|
|
-#include "stdarg.h"
|
|
|
-#include "string.h"
|
|
|
-#include "sht30_collect.h"
|
|
|
-#include "beep.h"
|
|
|
-#include "easyflash.h"
|
|
|
-#include "sound.h"
|
|
|
-#include "ymodem.h"
|
|
|
-#define DBG_TAG "hmi.c"
|
|
|
-#define DBG_LVL LOG_LVL_INFO
|
|
|
-#include <ulog.h>
|
|
|
-#include <shell.h>
|
|
|
-#include "dtu_uart2.h"
|
|
|
-#include <fal.h>
|
|
|
-#include <syswatch.h>
|
|
|
-#define HMI_THREAD_PRIORITY 21 //线程优先级
|
|
|
-#define HMI_THREAD_STACK_SIZE 1024 //线程栈空间大小
|
|
|
-#define HMI_THREAD_TIMESLICE 5 //时间片
|
|
|
-
|
|
|
-#define CONTROL_MOTOR_PRIORITY 18
|
|
|
-#define CONTROL_MOTOR_STACK_SIZE 2048
|
|
|
-#define CONTROL_MOTOR_TIMESLICE 5
|
|
|
-
|
|
|
-
|
|
|
-static char msg_pool[256];
|
|
|
-
|
|
|
-static char rx_buffer[HMI_UART_RXBUFFER_SIZE + 1];
|
|
|
-/**/
|
|
|
-Device_Status_typedef device_status;
|
|
|
-
|
|
|
-time_t time(time_t *t);
|
|
|
-void list_mem(void);
|
|
|
-/* 串口接收消息结构*/
|
|
|
-struct rx_msg
|
|
|
-{
|
|
|
- rt_device_t dev;
|
|
|
- rt_size_t size;
|
|
|
-};
|
|
|
-
|
|
|
-struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; /*初始化配置参数*/
|
|
|
-
|
|
|
-static rt_thread_t hmi1 = RT_NULL;
|
|
|
-static rt_thread_t ctr_motor = RT_NULL;
|
|
|
-rt_device_t serial; /*串口设备句柄*/
|
|
|
-/* 消息队列控制块 */
|
|
|
-static struct rt_messagequeue rx_mq;//接收数据消息队列
|
|
|
-static void HMI_Decode(char *cmd,uint8_t cmd_len);
|
|
|
-static rt_err_t uart_input(rt_device_t dev, rt_size_t size);
|
|
|
-void HMI_uart4_init(void)
|
|
|
-{
|
|
|
- serial = rt_device_find(UART_NAME);
|
|
|
- /*修改串口配置参数*/
|
|
|
- config.baud_rate = BAUD_RATE_9600; //修改波特率9600
|
|
|
- config.data_bits = DATA_BITS_8; //数据位8
|
|
|
- config.stop_bits = STOP_BITS_1; //停止位1
|
|
|
- config.bufsz = 512; //缓冲区128字节
|
|
|
- config.parity = PARITY_NONE; //无奇偶校验
|
|
|
- /* step3:控制串口设备。通过控制接口传入命令控制字,与控制参数 */
|
|
|
- rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config);
|
|
|
-// /* step4:打开串口设备。以中断接收及轮询发送模式打开串口设备 */
|
|
|
- //rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
|
|
|
- /* 以 DMA 接收及轮询发送模式打开串口设备 */
|
|
|
- rt_device_open(serial, RT_DEVICE_FLAG_DMA_RX);
|
|
|
-
|
|
|
-}
|
|
|
-/*串口屏写数据*/
|
|
|
-void HMI_WRITE(char *fmt, ...)
|
|
|
-{
|
|
|
- va_list ap;
|
|
|
- //末尾需要拼接的3个ff
|
|
|
- const char hmi_hex[3]={0xff,0xff,0xff};
|
|
|
- static char str[MAX_SIZE];
|
|
|
- //memset(str,'\0',sizeof(str));
|
|
|
- rt_size_t str_length;
|
|
|
- va_start(ap,fmt);
|
|
|
- str_length = rt_vsnprintf(str, sizeof(str) - 1, fmt, ap);
|
|
|
- if (str_length > MAX_SIZE - 1)
|
|
|
- str_length = MAX_SIZE - 1;
|
|
|
-
|
|
|
- rt_device_write(serial, 0, str, str_length);
|
|
|
- va_end(ap);
|
|
|
- rt_device_write(serial, 0,hmi_hex,3);
|
|
|
-}
|
|
|
-/* 接收数据回调函数 */
|
|
|
-static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
|
|
|
-{
|
|
|
- struct rx_msg msg;
|
|
|
- rt_err_t result;
|
|
|
- msg.dev = dev;
|
|
|
- msg.size = size;
|
|
|
-
|
|
|
- result = rt_mq_send(&rx_mq, &msg, sizeof(msg));
|
|
|
- if ( result == -RT_EFULL)
|
|
|
- {
|
|
|
- /* 消息队列满 */
|
|
|
- rt_kprintf("message queue full!\n");
|
|
|
- }
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-/*入口函数*/
|
|
|
-static void Hmi_thread_entry(void *parameter)
|
|
|
-{
|
|
|
- struct rx_msg msg;
|
|
|
- rt_err_t result;
|
|
|
- rt_uint32_t rx_length;
|
|
|
- while(1)
|
|
|
- {
|
|
|
- rt_memset(&msg, 0, sizeof(msg));
|
|
|
- /* 从消息队列中读取消息*/
|
|
|
- result = rt_mq_recv(&rx_mq, &msg, sizeof(msg), 10);
|
|
|
- if (result == RT_EOK)
|
|
|
- {
|
|
|
- rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
|
|
|
- rx_buffer[rx_length] = '\0';
|
|
|
- LOG_I("%s\n",rx_buffer);
|
|
|
- HMI_Decode(rx_buffer,rx_length);
|
|
|
- }
|
|
|
- /*********************************************************************************************************************/
|
|
|
- //rt_kprintf("%04d-%02d-%02d %02d:%02d:%02d\n",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
|
|
|
- //rt_kprintf("workSta.vbat.txt=%c%d.%02d%c\n",hmi_str,voltage/100,voltage%100,hmi_str);
|
|
|
- }
|
|
|
-}
|
|
|
-/*******************************************************************************************/
|
|
|
-
|
|
|
-/***************************** 解析从屏幕收到的数据 begin **********************************/
|
|
|
-static void HMI_Decode(char *cmd,uint8_t cmd_len)
|
|
|
-{
|
|
|
- char *var;
|
|
|
- if(device_status.refresh_num==0) device_status.refresh_num = 10;
|
|
|
- if(strstr(rx_buffer,"getFullData") != NULL){
|
|
|
- time_t now = time(RT_NULL);
|
|
|
- static struct tm tm;
|
|
|
- gmtime_r(&now, &tm);
|
|
|
- if(device_status.refresh_num==5)
|
|
|
- {
|
|
|
- char *readinfo = makeJson_ReadInfo();
|
|
|
- device_status.net = 1;
|
|
|
- device_status.sim = 1;
|
|
|
- device_status.csq = 1;
|
|
|
- device_status.refresh_num = 15;
|
|
|
- DTU_Write("%s",readinfo);
|
|
|
- list_mem();
|
|
|
- rt_free(readinfo);
|
|
|
- device_status.hmi_fresh = 1;
|
|
|
- HMI_WRITE("temHum.env_hum.val=%d",atoi(device_status.humidity));
|
|
|
- HMI_WRITE("temHum.env_tem.val=%d",atoi(device_status.tempture));
|
|
|
- HMI_WRITE("workSta.env_hum.val=%d",atoi(device_status.humidity));
|
|
|
- HMI_WRITE("workSta.env_tem.val=%d",atoi(device_status.tempture));
|
|
|
- }
|
|
|
- device_status.refresh_num--;
|
|
|
- //更新时间
|
|
|
- HMI_WRITE("workSta.rtc.txt=\"%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);
|
|
|
- //更新电压
|
|
|
- HMI_WRITE("workSta.vbat.txt=\"%s\"",device_status.voltage);
|
|
|
- //更新电流
|
|
|
- HMI_WRITE("workSta.power.txt=\"%s\"",device_status.power);
|
|
|
-
|
|
|
-
|
|
|
- //更新电池状态
|
|
|
- HMI_WRITE("workSta.bat_sta.val=%d",device_status.bat_status);
|
|
|
- //更新散热风机状态
|
|
|
- HMI_WRITE("workSta.cool_fan.val=%d",device_status.cool_fan_status);
|
|
|
- //更新开关状态
|
|
|
- HMI_WRITE("workSta.on_off.val=%d",device_status.ds);
|
|
|
- //更新工作状态
|
|
|
- HMI_WRITE("workSta.work_sta.val=%d",device_status.work_status);
|
|
|
- //箱内温度-外壳
|
|
|
- HMI_WRITE("workSta.box_tmp.txt=\"%s\"",device_status.tempture);
|
|
|
- HMI_WRITE("temHum.box_tmp.txt=\"%s\"",device_status.tempture);
|
|
|
- //制冷开关
|
|
|
- HMI_WRITE("workSta.cold_sw.val=%d",device_status.cold_sw);
|
|
|
- HMI_WRITE("sysSet.cold_sw.val=%d",device_status.cold_sw);
|
|
|
- //制冷状态
|
|
|
- HMI_WRITE("workSta.cold_sta.val=%d",device_status.cold_status);
|
|
|
- //培养温度
|
|
|
- HMI_WRITE("workSta.set_temp.val=%d",device_status.set_tempture);
|
|
|
- HMI_WRITE("sysSet.keep.val=%d",device_status.set_tempture);
|
|
|
- //当前温度-培养仓
|
|
|
- HMI_WRITE("workSta.pre_temp.val=%d",device_status.culture_tempture);
|
|
|
- //设定培养时间
|
|
|
- HMI_WRITE("workSta.cul_time.val=%d",device_status.culture_time);
|
|
|
- HMI_WRITE("clockSet.stay.val=%d",device_status.culture_time);
|
|
|
- //已培养时间
|
|
|
-
|
|
|
- //滴液时间
|
|
|
- HMI_WRITE("clockSet.drop.val=%d",device_status.drop_sec);
|
|
|
- //采集开始时间1
|
|
|
- HMI_WRITE("clockSet.start1.val=%d",device_status.culture_sh1);
|
|
|
- //采集开始时间2
|
|
|
- HMI_WRITE("clockSet.start2.val=%d",device_status.culture_sh2);
|
|
|
- //采集结束时间1
|
|
|
- HMI_WRITE("clockSet.end1.val=%d",device_status.culture_eh1);
|
|
|
- //采集结束时间2
|
|
|
- HMI_WRITE("clockSet.end2.val=%d",device_status.culture_eh2);
|
|
|
- //更新联网状态
|
|
|
- if(device_status.net==1)
|
|
|
- {
|
|
|
- HMI_WRITE("workSta.net.val=1");
|
|
|
- }
|
|
|
- else {
|
|
|
- HMI_WRITE("workSta.net.val=0");
|
|
|
- }
|
|
|
- if(device_status.csq==1)
|
|
|
- {
|
|
|
- HMI_WRITE("workSta.net.val=2");
|
|
|
- }
|
|
|
- //更新CSQ
|
|
|
- static char csq_str[10];
|
|
|
- itoa(device_status.csq,csq_str,10);
|
|
|
- HMI_WRITE("workSta.csq.txt=\"%s\"",csq_str);
|
|
|
- //更新加热状态
|
|
|
- HMI_WRITE("workSta.heatStatus.val=%d",device_status.heat_status);
|
|
|
- //更新熄屏时间
|
|
|
- HMI_WRITE("sysSet.lcd_time.thsp=%d",device_status.thsp/60);
|
|
|
- HMI_WRITE("thsp=%d",device_status.thsp);
|
|
|
- //更新密码
|
|
|
- static char pwd_char[10];
|
|
|
- //整型转字符串
|
|
|
- itoa(device_status.passWord,pwd_char,10);
|
|
|
- HMI_WRITE("inputPasswd.pwdData.txt=\"%s\"",pwd_char);
|
|
|
- //SIM卡状态
|
|
|
- HMI_WRITE("workSta.bt0.val=%d",device_status.sim);
|
|
|
- //ID
|
|
|
- HMI_WRITE("workSta.equipid.txt=\"%s\"",device_status.imei);
|
|
|
- //数据上传间隔
|
|
|
- HMI_WRITE("sysSet.datt.val=%d",device_status.dattim);
|
|
|
- //语音音量
|
|
|
- HMI_WRITE("sysSet.vol.val=%d",device_status.vol);
|
|
|
- //固件版本
|
|
|
- HMI_WRITE("debug.t3.txt=\"%s\"",VERSION);
|
|
|
- //编译时间
|
|
|
- HMI_WRITE("debug.t4.txt=\"%s\"",COMPILE);
|
|
|
- }
|
|
|
- else if (strstr(rx_buffer,"button")!=NULL) {
|
|
|
- rt_kprintf("按键!\n");
|
|
|
- DTU_Write("button");
|
|
|
- }
|
|
|
- //拍照
|
|
|
- else if(strstr(rx_buffer,"putTest.switchPic=1")!=NULL) {
|
|
|
- rt_kprintf("\n测试拍照!\n");
|
|
|
- HK_TakePhoto();
|
|
|
- }
|
|
|
- //转盘复位
|
|
|
- else if (strstr(rx_buffer,"turn_init")!=NULL) {
|
|
|
- rt_kprintf("转仓复位!\n");
|
|
|
- ctr_turn(0);
|
|
|
- }
|
|
|
- //转盘
|
|
|
- else if (strstr(rx_buffer,"turn")!=NULL) {
|
|
|
- rt_kprintf("转仓!\n");
|
|
|
- ctr_turn(90);
|
|
|
- }
|
|
|
- //打开电磁阀
|
|
|
- else if (strstr(rx_buffer,"putTest.switchDrop=1")!=NULL) {
|
|
|
- LOG_I("开始滴液!\n");
|
|
|
- ctr_DiYe(device_status.drop_sec);
|
|
|
- }
|
|
|
- //关闭电磁阀
|
|
|
- else if (strstr(rx_buffer,"putTest.switchDrop=0")!=NULL) {
|
|
|
- LOG_I("停止滴液!\n");
|
|
|
- ctr_DiYe(OFF);
|
|
|
- }
|
|
|
- //打开补光
|
|
|
- else if (strstr(rx_buffer,"putTest.switchLed=1")!=NULL) {
|
|
|
- rt_kprintf("\n打开补光!!!\n");
|
|
|
- ctr_led(ON);
|
|
|
- }
|
|
|
- //关闭补光
|
|
|
- else if (strstr(rx_buffer,"putTest.switchLed=0")!=NULL) {
|
|
|
- rt_kprintf("\n关闭补光!!!\n");
|
|
|
- ctr_led(OFF);
|
|
|
- }
|
|
|
- //关闭加热
|
|
|
- else if(strstr(rx_buffer,"putTest.switchHeat=0")!=NULL) {
|
|
|
- device_status.heat_status = 0;
|
|
|
- ctr_Heat(OFF);
|
|
|
- rt_kprintf("Close Heat!\n");
|
|
|
- }
|
|
|
- //打开加热
|
|
|
- else if(strstr(rx_buffer,"putTest.switchHeat=1")!=NULL) {
|
|
|
- device_status.heat_status = 1;
|
|
|
- ctr_Heat(ON);
|
|
|
- rt_kprintf("Open Heat!\n");
|
|
|
- }
|
|
|
- //打开制冷
|
|
|
- else if(strstr(rx_buffer,"putTest.switchCold=1")!=NULL) {
|
|
|
- ctr_Cold(ON);
|
|
|
- rt_kprintf("Open Cold!\n");
|
|
|
- }
|
|
|
- //关闭制冷
|
|
|
- else if(strstr(rx_buffer,"putTest.switchCold=0")!=NULL) {
|
|
|
- ctr_Cold(OFF);
|
|
|
- rt_kprintf("Close Cold!\n");
|
|
|
- }
|
|
|
- //打开采集
|
|
|
- else if(strstr(rx_buffer,"putTest.switchCollect=1")!=NULL){
|
|
|
- ctr_Collect_Fan(ON);
|
|
|
- rt_kprintf("采集风机已打开!\n");
|
|
|
- }
|
|
|
- //关闭采集
|
|
|
- else if(strstr(rx_buffer,"putTest.switchCollect=0")!=NULL){
|
|
|
- ctr_Collect_Fan(OFF);
|
|
|
- rt_kprintf("采集风机已关闭!\n");
|
|
|
- }
|
|
|
- //打开散热
|
|
|
- else if(strstr(rx_buffer,"putTest.switchCool=1")!=NULL){
|
|
|
- ctr_Cool_Fan(ON);
|
|
|
- rt_kprintf("散热风机已打开!\n");
|
|
|
- }
|
|
|
- //关闭散热
|
|
|
- else if(strstr(rx_buffer,"putTest.switchCool=0")!=NULL){
|
|
|
- ctr_Cool_Fan(OFF);
|
|
|
- rt_kprintf("散热风机已关闭!\n");
|
|
|
- }
|
|
|
- //步进上行开始
|
|
|
- else if(strstr(rx_buffer,"putTest.switchUp=1")!=NULL){
|
|
|
- ctr_Motor_Driver(1, 0,500000,200);
|
|
|
- rt_kprintf("开始步进上行!\n");
|
|
|
- }
|
|
|
- //步进上行停止
|
|
|
- else if(strstr(rx_buffer,"putTest.switchUp=0")!=NULL){
|
|
|
- ctr_Motor_Driver(0, 0,0,0);
|
|
|
- rt_kprintf("停止步进上行!\n");
|
|
|
- }
|
|
|
- //步进下行
|
|
|
- else if(strstr(rx_buffer,"putTest.switchDown=1")!=NULL){
|
|
|
- ctr_Motor_Driver(1, 1,500000,200);
|
|
|
- rt_kprintf("开始步进下行!\n");
|
|
|
- }
|
|
|
- //步进下行停止
|
|
|
- else if(strstr(rx_buffer,"putTest.switchDown=0")!=NULL){
|
|
|
- ctr_Motor_Driver(0, 0,0,0);
|
|
|
- rt_kprintf("停止步进下行!\n");
|
|
|
- }
|
|
|
- //开始对焦拍照
|
|
|
- else if(strstr(rx_buffer,"putTest.switchAutopic=1")!=NULL){
|
|
|
- device_status.autotakepic=1;
|
|
|
- rt_kprintf("开始对焦拍照!\n");
|
|
|
- }
|
|
|
- //停止对焦拍照
|
|
|
- else if(strstr(rx_buffer,"putTest.switchAutopic=0")!=NULL){
|
|
|
- device_status.autotakepic=0;
|
|
|
- }
|
|
|
- //粘附测试-开
|
|
|
- else if(strstr(rx_buffer,"putTest.switchFsl=1")!=NULL){
|
|
|
- rt_kprintf("粘附测试开!\n");
|
|
|
- device_status.fsl_sw = 1;
|
|
|
- }
|
|
|
- //粘附测试-关
|
|
|
- else if(strstr(rx_buffer,"putTest.switchFsl=0")!=NULL){
|
|
|
- rt_kprintf("粘附测试关!\n");
|
|
|
- pwm_off(2, 0);
|
|
|
- pwm_off(3,0);
|
|
|
- }
|
|
|
- //定时设置
|
|
|
- else if (strstr(rx_buffer,"saveClockSet")!=NULL) {
|
|
|
- rt_kprintf("时间设置!\n");
|
|
|
- var = strstr(rx_buffer,"=");
|
|
|
- var ++;
|
|
|
- device_status.culture_sh1 = *((int *)var); //采集1开始
|
|
|
- ef_set_env_blob("culture_sh1", &device_status.culture_sh1, sizeof(device_status.culture_sh1));
|
|
|
- var+=4;
|
|
|
- device_status.culture_eh1 = *((int *)var); //采集1结束
|
|
|
- ef_set_env_blob("culture_eh1", &device_status.culture_eh1, sizeof(device_status.culture_eh1));
|
|
|
- var+=4;
|
|
|
- device_status.culture_sh2 = *((int *)var); //采集2开始
|
|
|
- ef_set_env_blob("culture_sh2", &device_status.culture_sh2, sizeof(device_status.culture_sh2));
|
|
|
- var+=4;
|
|
|
- device_status.culture_eh2 = *((int *)var); //采集2结束
|
|
|
- ef_set_env_blob("culture_eh2", &device_status.culture_eh2, sizeof(device_status.culture_eh2));
|
|
|
- var+=4;
|
|
|
- device_status.drop_sec = *((int *)var); //滴液时间
|
|
|
- ef_set_env_blob("drop_sec", &device_status.drop_sec, sizeof(device_status.drop_sec));
|
|
|
- var+=4;
|
|
|
- device_status.culture_time = *((int *)var); //培养时间
|
|
|
- ef_set_env_blob("culture_time", &device_status.culture_time, sizeof(device_status.culture_time));
|
|
|
- MA_save();
|
|
|
- rt_kprintf("参数已保存:%d-%d-%d-%d-%d-%d",device_status.culture_sh1,device_status.culture_eh1,device_status.culture_sh2,device_status.culture_eh2,device_status.drop_sec,device_status.culture_time);
|
|
|
- }
|
|
|
- else if (strstr(rx_buffer,"saveSystemSet")!=NULL) {
|
|
|
- rt_kprintf("系统设置!\n");
|
|
|
- var = strstr(rx_buffer,"=");
|
|
|
- var ++;
|
|
|
- device_status.cold_sw = *((int *)var); //制冷开关
|
|
|
- ef_set_env_blob("cold_sw", &device_status.cold_sw, sizeof(device_status.cold_sw));
|
|
|
- var+=4;
|
|
|
- device_status.vol = *((int *)var); //音量
|
|
|
- var+=4;
|
|
|
- device_status.set_tempture = *((int *)var); //培养温度
|
|
|
- ef_set_env_blob("set_tempture", &device_status.set_tempture, sizeof(device_status.set_tempture));
|
|
|
- var+=4;
|
|
|
- device_status.dattim = *((int *)var); //数据上传间隔
|
|
|
- ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim));
|
|
|
- var+=4;
|
|
|
- device_status.thsp = *((int *)var); //自动熄屏
|
|
|
- ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
|
|
|
- MA_save();
|
|
|
- rt_kprintf("制冷开关:%d\n",device_status.cold_sw);
|
|
|
- rt_kprintf("系统设置已保存:自动熄屏-%d,音量-%d,培养温度-%d,数据上传间隔-%d\n",device_status.thsp,device_status.vol,device_status.culture_tempture,device_status.dattim);
|
|
|
- }
|
|
|
- //恢复出厂设置
|
|
|
- else if (strstr(rx_buffer,"resetDefault")!=NULL)
|
|
|
- {
|
|
|
- ResetParamDefault();
|
|
|
- MA_save();
|
|
|
- rt_kprintf("恢复出厂设置!!!");
|
|
|
- }
|
|
|
- //获取SIM卡信息
|
|
|
- else if(strstr(rx_buffer,"getSim")!=NULL)
|
|
|
- {
|
|
|
- //http://sim.openluat.com/api/wechat/openapidoc
|
|
|
- DTU_Write("getsiminfo");
|
|
|
- }
|
|
|
- else if (strstr(rx_buffer,"DebugEnable")!=NULL) {
|
|
|
- Debug_log_ON();
|
|
|
- }
|
|
|
- else if (strstr(rx_buffer,"DebugDisable")!=NULL) {
|
|
|
- Debug_log_OFF();
|
|
|
- }
|
|
|
- else if (strstr(rx_buffer,"putTest.switchAutotest=1")!=NULL)
|
|
|
- {
|
|
|
- rt_kprintf("开始一键测试!!!\n");
|
|
|
- device_status.auto_test_sw=1;
|
|
|
- }
|
|
|
- else if (strstr(rx_buffer,"putTest.switchAutotest=1")!=NULL)
|
|
|
- {
|
|
|
- rt_kprintf("停止一键测试!!!\n");
|
|
|
- device_status.auto_test_sw=0;
|
|
|
- }
|
|
|
- else if(strstr(rx_buffer,"DisplayPower")!=RT_NULL)
|
|
|
- {
|
|
|
- HMI_WRITE("sysTest.sysTest_power.txt=\"%s\"",device_status.power);
|
|
|
- }
|
|
|
- //进入bootloader模式
|
|
|
- else if (strstr(rx_buffer,"bootloader")!=NULL) {
|
|
|
- device_status.stop_in_bootloader = 1;
|
|
|
- ef_set_env_blob("stop_in_bootloader", &device_status.stop_in_bootloader, sizeof(device_status.stop_in_bootloader));
|
|
|
- rt_hw_cpu_reset();
|
|
|
- }
|
|
|
- //软件重启
|
|
|
- else if (strstr(rx_buffer,"reboot")!=NULL) {
|
|
|
- rt_hw_cpu_reset();
|
|
|
- }
|
|
|
-}
|
|
|
-//入口函数-对焦拍照
|
|
|
-static void Ctr_Mortor_entry(void* parameter)
|
|
|
-{
|
|
|
- rt_uint8_t photo_setup = 0;
|
|
|
- while(1)
|
|
|
- {
|
|
|
- if(device_status.autotakepic==1)
|
|
|
- {
|
|
|
- //打开补光灯
|
|
|
- ctr_led(ON);
|
|
|
- //电机向下运动
|
|
|
- ctr_Motor_Driver(1, 1, 500000,200);
|
|
|
- rt_thread_delay(1000);
|
|
|
- LOG_I("电机到达下方!!!");
|
|
|
- HK_TakePhoto();
|
|
|
- rt_thread_delay(1000);
|
|
|
- LOG_I("电机开始向上!!!");
|
|
|
- rt_pin_write(Motor_EN, 1);
|
|
|
- rt_pin_write(Motor_DIR, 0);
|
|
|
- beep_set(500000, 500000/5); //2kzh - 50%
|
|
|
- while(rt_pin_read(LIMIT_UP)==1)
|
|
|
- {
|
|
|
- rt_thread_delay(10);
|
|
|
- photo_setup++;
|
|
|
- rt_pin_write(Motor_EN, 0); //驱动器失能
|
|
|
- HK_TakePhoto();
|
|
|
- rt_thread_delay(1000);
|
|
|
- rt_pin_write(Motor_EN, 1); //驱动器使能
|
|
|
- if(photo_setup==100)
|
|
|
- {
|
|
|
- ctr_led(OFF);
|
|
|
- device_status.autotakepic=0;
|
|
|
- rt_pin_write(Motor_EN, 0); //驱动器失能
|
|
|
- beep_set(500000, 0); //2kzh - 50%
|
|
|
- HMI_WRITE("sysTest.switchAutopic.val=%d",0);
|
|
|
- break;
|
|
|
- }
|
|
|
- rt_kprintf("对焦拍照:%d\n",photo_setup);
|
|
|
- }
|
|
|
- ctr_led(OFF);
|
|
|
- rt_pin_write(Motor_EN, 0); //驱动器失能
|
|
|
- beep_set(500000, 0); //2kzh - 50%
|
|
|
- HMI_WRITE("sysTest.switchAutopic.val=%d",0);
|
|
|
- char w_temp[20];
|
|
|
- rt_sprintf(w_temp,"%s%d","autoTakePhoto success!!!",photo_setup);
|
|
|
- char *autotake_warn = makeJson_Warn(w_temp, "Motor");
|
|
|
- DTU_Write("%s",autotake_warn);
|
|
|
- rt_free(autotake_warn);
|
|
|
- device_status.autotakepic=0;
|
|
|
- photo_setup = 0;
|
|
|
- HMI_WRITE("sysTest.switchAutopic.val=%d",0);
|
|
|
- }
|
|
|
- if(device_status.fsl_sw==1)
|
|
|
- {
|
|
|
- ctr_Petroleum_jelly(10);
|
|
|
- }
|
|
|
- //一键测试
|
|
|
- if(device_status.auto_test_sw==1)
|
|
|
- {
|
|
|
- //转盘复位
|
|
|
- rt_kprintf("转盘复位!!!\n");
|
|
|
- rt_thread_delay(2000);
|
|
|
- ctr_turn(0);
|
|
|
- //转90
|
|
|
- rt_kprintf("第一次转盘!!!\n");
|
|
|
- ctr_turn(90);
|
|
|
- rt_thread_delay(2000);
|
|
|
- //推杆电机:测试粘附:
|
|
|
- rt_kprintf("涂凡士林!!!\n");
|
|
|
- ctr_Petroleum_jelly(10);
|
|
|
- rt_thread_delay(2000);
|
|
|
- //转90
|
|
|
- rt_kprintf("第二次转盘!!!\n");
|
|
|
- ctr_turn(90);
|
|
|
- rt_thread_delay(2000);
|
|
|
- //采集,打开风机
|
|
|
- rt_kprintf("采集,打开风机!!!\n");
|
|
|
- ctr_Collect_Fan(ON);
|
|
|
- rt_thread_delay(5000);
|
|
|
- rt_kprintf("采集结束,关闭风机!!!\n");
|
|
|
- rt_thread_delay(2000);
|
|
|
- ctr_Collect_Fan(OFF);
|
|
|
- //散热
|
|
|
- rt_kprintf("打开散热!!!\n");
|
|
|
- rt_thread_delay(2000);
|
|
|
- ctr_Cool_Fan(ON);
|
|
|
- rt_thread_delay(5000);
|
|
|
- rt_kprintf("关闭散热!!!\n");
|
|
|
- rt_thread_delay(2000);
|
|
|
- ctr_Cool_Fan(OFF);
|
|
|
- //转90
|
|
|
- rt_kprintf("第三次转盘!!!\n");
|
|
|
- ctr_turn(90);
|
|
|
- rt_thread_delay(5000);
|
|
|
- //滴液
|
|
|
- rt_kprintf("开始滴液!!!\n");
|
|
|
- rt_thread_delay(2000);
|
|
|
- ctr_DiYe(device_status.drop_sec);
|
|
|
- rt_thread_delay(5000);
|
|
|
- rt_kprintf("停止滴液!!!\n");
|
|
|
- rt_thread_delay(2000);
|
|
|
- //加热
|
|
|
- rt_kprintf("开始加热!!!\n");
|
|
|
- rt_thread_delay(2000);
|
|
|
- ctr_Heat(ON);
|
|
|
- rt_thread_delay(5000);
|
|
|
- rt_kprintf("停止加热!!!\n");
|
|
|
- rt_thread_delay(2000);
|
|
|
- ctr_Heat(OFF);
|
|
|
- //制冷
|
|
|
- rt_kprintf("开始制冷!!!\n");
|
|
|
- rt_thread_delay(2000);
|
|
|
- ctr_Cold(ON);
|
|
|
- rt_thread_delay(5000);
|
|
|
- rt_kprintf("停止制冷!!!\n");
|
|
|
- rt_thread_delay(2000);
|
|
|
- ctr_Cold(OFF);
|
|
|
- //转90
|
|
|
- rt_kprintf("第四次转盘!!!\n");
|
|
|
- ctr_turn(90);
|
|
|
- rt_kprintf("打开补光灯!!!\n");
|
|
|
- rt_thread_delay(2000);
|
|
|
- ctr_led(ON);
|
|
|
- device_status.autotakepic=1;
|
|
|
- device_status.auto_test_sw=0;
|
|
|
- }
|
|
|
- rt_thread_delay(100);
|
|
|
- }
|
|
|
-}
|
|
|
-/*屏幕写数据*/
|
|
|
-int Hmi_Fresh(void)
|
|
|
-{
|
|
|
- //初始化串口4
|
|
|
- rt_err_t ret = RT_EOK;
|
|
|
- /* 初始化消息队列 */
|
|
|
- rt_mq_init(&rx_mq, "rx_mq",
|
|
|
- msg_pool, /* 存放消息的缓冲区 */
|
|
|
- sizeof(struct rx_msg), /* 一条消息的最大长度 */
|
|
|
- sizeof(msg_pool), /* 存放消息的缓冲区大小 */
|
|
|
- RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
|
|
|
- /* 设置接收回调函数 */
|
|
|
- rt_device_set_rx_indicate(serial, uart_input);
|
|
|
- /* 创建线程*/
|
|
|
- hmi1 = rt_thread_create("Hmi_Fresh_thread",
|
|
|
- Hmi_thread_entry,
|
|
|
- RT_NULL,
|
|
|
- HMI_THREAD_STACK_SIZE,
|
|
|
- HMI_THREAD_PRIORITY,
|
|
|
- HMI_THREAD_TIMESLICE);
|
|
|
- /*打开上仓门的线程*/
|
|
|
- ctr_motor = rt_thread_create("Ctr motor",
|
|
|
- Ctr_Mortor_entry,
|
|
|
- RT_NULL,
|
|
|
- CONTROL_MOTOR_STACK_SIZE,
|
|
|
- CONTROL_MOTOR_PRIORITY,
|
|
|
- CONTROL_MOTOR_TIMESLICE);
|
|
|
- if(ctr_motor != RT_NULL)
|
|
|
- {
|
|
|
- rt_thread_startup(ctr_motor);
|
|
|
- }
|
|
|
- /* 如果获得线程控制块,启动这个线程 */
|
|
|
- if (hmi1 != RT_NULL)
|
|
|
- {
|
|
|
- rt_thread_startup(hmi1);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ret = RT_ERROR;
|
|
|
- }
|
|
|
- return ret;
|
|
|
-}
|
|
|
-void Check_ParamConfig(void)
|
|
|
-{
|
|
|
- Hmi_Fresh();
|
|
|
- time_t now = time(RT_NULL);
|
|
|
- static struct tm tm;
|
|
|
- gmtime_r(&now, &tm);
|
|
|
- if(easyflash_init()==EF_NO_ERR) //初始化成功
|
|
|
- {
|
|
|
- ef_get_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt), NULL); //读出reboot_time的值
|
|
|
- ef_get_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag), NULL); //读出updateflag的值
|
|
|
- ef_get_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave), NULL); //判断是否用户配置了程序
|
|
|
- device_status.rebootcnt++;
|
|
|
- ef_set_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt));
|
|
|
- rt_kprintf("REBOOT_TIME:%d-%d-%d\n",device_status.rebootcnt,device_status.iSave,device_status.update_flag);
|
|
|
- HMI_WRITE("hardcheck.flash.txt=\"READ FLASH OK\"");
|
|
|
- HMI_WRITE("hardcheck.p8.pic=%d",70);
|
|
|
- }
|
|
|
- else {
|
|
|
- LOG_W("easyflash init failed!!!");
|
|
|
- HMI_WRITE("hardcheck.flash.txt=\"ERR\"");
|
|
|
- HMI_WRITE("hardcheck.p8.pic=%d",72);
|
|
|
- }
|
|
|
- //保存默认屏幕配置
|
|
|
- if(device_status.iSave!=FLASH_FLAG)
|
|
|
- {
|
|
|
- app_partion_backup();
|
|
|
- device_status.iSave=FLASH_FLAG;
|
|
|
- device_status.culture_time = 1; //设定培养时间-1小时
|
|
|
- device_status.culture_tempture = 25; //设定培养仓温度
|
|
|
- device_status.thsp = 300; //默认熄屏时间5分钟
|
|
|
- device_status.drop_sec = 1; //滴液时间,s
|
|
|
- device_status.cold_sw = 0; //制冷开关,默认关
|
|
|
- device_status.culture_sh1 = 10;
|
|
|
- device_status.culture_eh1 = 12;
|
|
|
- device_status.culture_sh2 = 13;
|
|
|
- device_status.culture_eh2 = 17;
|
|
|
- device_status.culture_sh3 = 17;
|
|
|
- device_status.culture_eh3 = 17;
|
|
|
- device_status.culture_time = 1;
|
|
|
- device_status.vol = 7; //音量
|
|
|
- device_status.passWord = 8888; //屏幕密码
|
|
|
- device_status.work_done = 0; //工作完成标志位
|
|
|
- device_status.dattim = 20; //数据上传间隔
|
|
|
- device_status.ds = 1; //设备状态
|
|
|
- device_status.dtype = 7; //版本类型
|
|
|
- ef_set_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave)); //
|
|
|
- ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
|
|
|
- ef_set_env_blob("cold_sw", &device_status.cold_sw, sizeof(device_status.cold_sw));
|
|
|
- ef_set_env_blob("culture_sh1", &device_status.culture_sh1, sizeof(device_status.culture_sh1));
|
|
|
- ef_set_env_blob("culture_sh2", &device_status.culture_sh2, sizeof(device_status.culture_sh2));
|
|
|
- ef_set_env_blob("culture_sh3", &device_status.culture_sh3, sizeof(device_status.culture_sh3));
|
|
|
- ef_set_env_blob("culture_eh1", &device_status.culture_eh1, sizeof(device_status.culture_eh1));
|
|
|
- ef_set_env_blob("culture_eh2", &device_status.culture_eh2, sizeof(device_status.culture_eh2));
|
|
|
- ef_set_env_blob("culture_eh3", &device_status.culture_eh3, sizeof(device_status.culture_eh3));
|
|
|
- ef_set_env_blob("culture_time", &device_status.culture_time, sizeof(device_status.culture_time));
|
|
|
- ef_set_env_blob("culture_tempture", &device_status.culture_tempture, sizeof(device_status.culture_tempture));
|
|
|
- ef_set_env_blob("drop_sec", &device_status.drop_sec, sizeof(device_status.drop_sec)); //震动时间
|
|
|
- ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
|
|
|
- ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
|
|
|
- ef_set_env_blob("lat",&device_status.lat,sizeof(device_status.lat)); //纬度
|
|
|
- ef_set_env_blob("lng",&device_status.lng,sizeof(device_status.lng)); //经度
|
|
|
- ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
|
|
|
- sprintf(device_status.driver, "%s",VERSION);
|
|
|
- LOG_I("SOFTWARE VERSION:%s\n",device_status.driver);
|
|
|
- rt_kprintf("set flash paramconfis:\n");
|
|
|
- rt_kprintf("iSave:%d\n",device_status.iSave);
|
|
|
- rt_kprintf("culture_time:%d\n",device_status.culture_time);
|
|
|
- rt_kprintf("jheat:%d\n",device_status.culture_tempture);
|
|
|
- rt_kprintf("thsp:%d\n", device_status.thsp);
|
|
|
- rt_kprintf("密码:%d\n",device_status.passWord);
|
|
|
-
|
|
|
- }//从easyflash读取参数配置
|
|
|
- else if (device_status.iSave==FLASH_FLAG) {
|
|
|
- ef_get_env_blob("culture_sh1",&device_status.culture_sh1,sizeof(device_status.culture_sh1),NULL); //采集开始时间1
|
|
|
- ef_get_env_blob("culture_sh2",&device_status.culture_sh2,sizeof(device_status.culture_sh2),NULL); //采集开始时间2
|
|
|
- ef_get_env_blob("culture_sh3",&device_status.culture_sh3,sizeof(device_status.culture_sh3),NULL); //采集开始时间2
|
|
|
- ef_get_env_blob("culture_eh1",&device_status.culture_eh1,sizeof(device_status.culture_eh1),NULL); //采集结束时间1
|
|
|
- ef_get_env_blob("culture_eh2",&device_status.culture_eh2,sizeof(device_status.culture_eh2),NULL); //采集结束时间2
|
|
|
- ef_get_env_blob("culture_eh3",&device_status.culture_eh3,sizeof(device_status.culture_eh3),NULL); //采集结束时间3
|
|
|
- ef_get_env_blob("cold_sw",&device_status.cold_sw,sizeof(device_status.cold_sw),NULL); //数据上传间隔
|
|
|
- ef_get_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim),NULL); //数据上传间隔
|
|
|
- ef_get_env_blob("culture_time", &device_status.culture_time, sizeof(device_status.culture_time), NULL); //培养时间
|
|
|
- ef_get_env_blob("culture_tempture", &device_status.culture_tempture, sizeof(device_status.culture_tempture), NULL); //设定培养温度
|
|
|
- ef_get_env_blob("drop_sec", &device_status.drop_sec, sizeof(device_status.drop_sec), NULL); //滴液时间
|
|
|
- ef_get_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim), NULL); //数据上传间隔
|
|
|
- ef_get_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp), NULL); //熄屏时间
|
|
|
- ef_get_env_blob("passWord",&device_status.passWord,sizeof(device_status.passWord),NULL); //密码
|
|
|
- ef_get_env_blob("imei",&device_status.imei,sizeof(device_status.imei),NULL); //IMEI
|
|
|
- ef_get_env_blob("iccid",&device_status.iccid,sizeof(device_status.iccid),NULL); //ICCID
|
|
|
- ef_get_env_blob("ds",&device_status.ds,sizeof(device_status.ds),NULL); //开关机状态
|
|
|
- ef_get_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type),NULL); //版本类型
|
|
|
- device_status.work_done = 0;
|
|
|
- //工作完成标志位
|
|
|
- if(device_status.dattim==0)
|
|
|
- {
|
|
|
- device_status.dattim = 20;
|
|
|
- }
|
|
|
- if(device_status.version_type==1)
|
|
|
- {
|
|
|
- app_partion_backup(); //固件备份至df_area
|
|
|
- ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type));
|
|
|
- }
|
|
|
- rt_sprintf(device_status.driver, "%s",VERSION);
|
|
|
-
|
|
|
- LOG_I("SOFTWARE VERSION:%s\n",device_status.driver);
|
|
|
- rt_kprintf("read flash paramconfis:%d\r\n",device_status.version_type);
|
|
|
- rt_kprintf("开机次数:%d\n",device_status.rebootcnt);
|
|
|
- rt_kprintf("收集时间:%d\n",device_status.culture_time);
|
|
|
- rt_kprintf("加热温度:%d\n",device_status.culture_tempture);
|
|
|
- rt_kprintf("震动时间:%d\n",device_status.drop_sec);
|
|
|
- rt_kprintf("thsp:%d\n", device_status.thsp);
|
|
|
- rt_kprintf("密码:%d\n",device_status.passWord);
|
|
|
-
|
|
|
- rt_kprintf("数据上传间隔:%d\n",device_status.dattim);
|
|
|
- }
|
|
|
- rt_kprintf("当前时间:%04d-%02d-%02d %02d:%02d:%02d\n",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
|
|
|
- HMI_WRITE("hardcheck.tip_rtc.txt=%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);
|
|
|
- HMI_WRITE("hardcheck.p0.pic=%d",70);
|
|
|
- //RTC时间判断,如果当前年份小于2020,提示需要设置时间,切换为光控
|
|
|
- if(tm.tm_year+1900<2020)
|
|
|
- {
|
|
|
- LOG_E("Time not set:%04d-%02d-%02d %02d:%02d:%02d\n",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
|
|
|
- HMI_WRITE("hardcheck.tip_rtc.txt=%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);
|
|
|
- HMI_WRITE("hardcheck.p0.pic=%d",71);
|
|
|
- set_date(2020, 1, 1);
|
|
|
- set_time(0, 0, 0);
|
|
|
- }
|
|
|
- if(device_status.update_flag==1)
|
|
|
- {
|
|
|
- device_status.update_flag = 0;
|
|
|
- ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));
|
|
|
- ymodem_ota(1,0);
|
|
|
- }
|
|
|
-}
|
|
|
-void ResetParamDefault(void)
|
|
|
-{
|
|
|
- device_status.culture_time = 1; //培养时间
|
|
|
- device_status.dattim = 20; //数据上传间隔
|
|
|
- device_status.drop_sec = 1; //滴液时间1-100ms
|
|
|
- device_status.culture_tempture = 25; //培养温度
|
|
|
- device_status.ds = 1; //设备状态开机
|
|
|
- device_status.thsp = 300;
|
|
|
- device_status.passWord = 8888;
|
|
|
- device_status.culture_sh1 = 10;
|
|
|
- device_status.culture_eh1 = 12;
|
|
|
- device_status.culture_sh2 = 12;
|
|
|
- device_status.culture_eh2 = 17;
|
|
|
- ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
|
|
|
- ef_set_env_blob("culture_sh1", &device_status.culture_sh1, sizeof(device_status.culture_sh1));
|
|
|
- ef_set_env_blob("culture_eh1", &device_status.culture_eh1, sizeof(device_status.culture_eh1));
|
|
|
- ef_set_env_blob("culture_sh2", &device_status.culture_sh2, sizeof(device_status.culture_sh2));
|
|
|
- ef_set_env_blob("culture_eh2", &device_status.culture_eh2, sizeof(device_status.culture_eh2));
|
|
|
- ef_set_env_blob("culture_time", &device_status.culture_time, sizeof(device_status.culture_time));
|
|
|
- ef_set_env_blob("culture_tempture", &device_status.culture_tempture, sizeof(device_status.culture_tempture));
|
|
|
-
|
|
|
- ef_set_env_blob("drop_sec", &device_status.drop_sec, sizeof(device_status.drop_sec)); //震动时间
|
|
|
- ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
|
|
|
- ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
|
|
|
-}
|
|
|
-//固件备份
|
|
|
-void app_partion_backup(void)
|
|
|
-{
|
|
|
- rt_kprintf("固件备份!!!\n");
|
|
|
- const char *dst_part_name = "df_area";
|
|
|
- const char *src_part_name = "app";
|
|
|
- const struct fal_partition *dst_part;
|
|
|
- const struct fal_partition *src_part;
|
|
|
- dst_part = fal_partition_find(dst_part_name);
|
|
|
- src_part = fal_partition_find(src_part_name);
|
|
|
- if (dst_part == RT_NULL || src_part == RT_NULL)
|
|
|
- {
|
|
|
- if (dst_part == RT_NULL)
|
|
|
- rt_kprintf("%s partition is not exist!\n", dst_part_name);
|
|
|
- if (src_part == RT_NULL)
|
|
|
- rt_kprintf("%s partition is not exist!\n", src_part_name);
|
|
|
- }
|
|
|
- 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)
|
|
|
- {
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-void Debug_log_ON(void)
|
|
|
-{
|
|
|
- rt_console_set_device("uart4");
|
|
|
- finsh_set_device("uart4");
|
|
|
-}
|
|
|
-void Debug_log_OFF(void)
|
|
|
-{
|
|
|
-
|
|
|
- rt_console_set_device("uart1");
|
|
|
- finsh_set_device("uart1");
|
|
|
- rt_mq_init(&rx_mq, "rx_mq",
|
|
|
- msg_pool, /* 存放消息的缓冲区 */
|
|
|
- sizeof(struct rx_msg), /* 一条消息的最大长度 */
|
|
|
- sizeof(msg_pool), /* 存放消息的缓冲区大小 */
|
|
|
- RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
|
|
|
- rt_device_set_rx_indicate(serial, uart_input);
|
|
|
- hmi1 = rt_thread_create("Hmi_Fresh_thread",
|
|
|
- Hmi_thread_entry,
|
|
|
- RT_NULL,
|
|
|
- HMI_THREAD_STACK_SIZE,
|
|
|
- HMI_THREAD_PRIORITY,
|
|
|
- HMI_THREAD_TIMESLICE);
|
|
|
- if (hmi1 != RT_NULL)
|
|
|
- {
|
|
|
- rt_thread_startup(hmi1);
|
|
|
- }
|
|
|
-}
|
|
|
-MSH_CMD_EXPORT(Debug_log_ON,Debug_log_ON);
|
|
|
-MSH_CMD_EXPORT(Debug_log_OFF,Debug_log_OFF);
|
|
|
-
|
|
|
-INIT_BOARD_EXPORT(HMI_uart4_init);
|