|
|
@@ -23,7 +23,8 @@
|
|
|
#include <ymodem.h>
|
|
|
#include "beep.h"
|
|
|
#include <selfcheck.h>
|
|
|
-#include <s2j.h>
|
|
|
+#include <user_mb_app.h>
|
|
|
+
|
|
|
#define DBG_ENABLE
|
|
|
#define DBG_COLOR
|
|
|
#define DBG_TAG "dtu"
|
|
|
@@ -32,7 +33,7 @@
|
|
|
|
|
|
|
|
|
#define DTU_THREAD_PRIORITY 6 //线程优先级
|
|
|
-#define DTU_THREAD_STACK_SIZE 2048 //线程栈空间大小
|
|
|
+#define DTU_THREAD_STACK_SIZE 4096 //线程栈空间大小
|
|
|
#define DTU_THREAD_TIMESLICE 5 //时间片
|
|
|
|
|
|
|
|
|
@@ -57,6 +58,8 @@ struct serial_configure dtuconfig = RT_SERIAL_CONFIG_DEFAULT; /*初始化配
|
|
|
|
|
|
static uint8_t makejson_sta = 0;
|
|
|
|
|
|
+extern eMBMasterReqErrCode _485_play(USHORT *Buffer,USHORT NREGS);
|
|
|
+
|
|
|
static int DTU_uart2_init(void)
|
|
|
{
|
|
|
dtuserial = rt_device_find(DTU_UART_NAME);
|
|
|
@@ -99,12 +102,12 @@ void DTU_Write(char *fmt, ...)
|
|
|
rt_size_t str_length;
|
|
|
va_start(ap,fmt);
|
|
|
//str_length = rt_vsnprintf(dtu_str, sizeof(dtu_str) - 1, fmt, arg);
|
|
|
- str_length = rt_vsnprintf(dtu_str, sizeof(dtu_str) - 4, fmt, ap);
|
|
|
+ str_length = rt_vsnprintf(dtu_str, sizeof(dtu_str)-1, fmt, ap);
|
|
|
va_end(ap);
|
|
|
- if (str_length > 1024 - 4)
|
|
|
- str_length = 1024 - 4;
|
|
|
+ if (str_length > 1024 - 1)
|
|
|
+ str_length = 1024 - 1;
|
|
|
rt_device_write(dtuserial, 0, dtu_str, str_length);
|
|
|
- rt_thread_mdelay(10);
|
|
|
+ rt_thread_mdelay(20);
|
|
|
// if(strstr(dtu_str,"volume")!=RT_NULL)
|
|
|
// {
|
|
|
// rt_device_write(dtuserial,0,dtu_conf,4);
|
|
|
@@ -126,27 +129,199 @@ static rt_err_t dtu_input(rt_device_t dev, rt_size_t size)
|
|
|
{
|
|
|
/* 消息队列满 */
|
|
|
rt_kprintf("message queue full!\n");
|
|
|
+ rt_mq_control(&rx_mq_dtu, RT_IPC_CMD_RESET, RT_NULL); // 清空队列
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+// 最大JSON缓冲区长度(建议根据设备内存调整)
|
|
|
+#define MAX_JSON_BUFFER 1024
|
|
|
+// 最大超时时间(单位:RT_TICK_PER_SECOND)
|
|
|
+#define JSON_PARSE_TIMEOUT 2
|
|
|
+
|
|
|
+// 全局缓冲区结构体
|
|
|
+static struct {
|
|
|
+ char buffer[MAX_JSON_BUFFER]; // 数据存储区
|
|
|
+ int index; // 当前写入位置
|
|
|
+ rt_tick_t last_received; // 最后接收时间戳
|
|
|
+ int nested_level; // 当前嵌套层数
|
|
|
+} json_ctx = {.index = 0, .last_received = 0, .nested_level = 0};
|
|
|
+
|
|
|
+
|
|
|
+// 自定义异常类型
|
|
|
+typedef enum {
|
|
|
+ JSON_OK,
|
|
|
+ JSON_INCOMPLETE,
|
|
|
+ JSON_INVALID_CHAR,
|
|
|
+ JSON_TOO_DEEP,
|
|
|
+ JSON_TOO_LONG
|
|
|
+} json_status_t;
|
|
|
+
|
|
|
+// 查找完整JSON边界(支持嵌套)
|
|
|
+static json_status_t find_json_boundary(int *start, int *end)
|
|
|
+{
|
|
|
+ *start = -1;
|
|
|
+ *end = -1;
|
|
|
+ int level = 0;
|
|
|
+
|
|
|
+ for (int i = 0; i < json_ctx.index; i++) {
|
|
|
+ if (json_ctx.buffer[i] == '{') {
|
|
|
+ if (level == 0) *start = i;
|
|
|
+ level++;
|
|
|
+ if (level > 32) return JSON_TOO_DEEP;
|
|
|
+ } else if (json_ctx.buffer[i] == '}') {
|
|
|
+ level--;
|
|
|
+ if (level < 0) return JSON_INVALID_CHAR;
|
|
|
+ if (level == 0 && *start != -1) {
|
|
|
+ *end = i;
|
|
|
+ return JSON_OK;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (*start != -1) return JSON_INCOMPLETE;
|
|
|
+ return JSON_OK;
|
|
|
+}
|
|
|
+// 处理缓冲区超时
|
|
|
+static void check_timeout_reset(void)
|
|
|
+{
|
|
|
+ if (rt_tick_get() - json_ctx.last_received > JSON_PARSE_TIMEOUT * RT_TICK_PER_SECOND) {
|
|
|
+ rt_memset(json_ctx.buffer, 0, MAX_JSON_BUFFER);
|
|
|
+ json_ctx.index = 0;
|
|
|
+ json_ctx.nested_level = 0;
|
|
|
+ rt_kprintf("[JSON] Timeout reset\n");
|
|
|
+ }
|
|
|
+}
|
|
|
+#define RT_MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
|
+// 核心处理函数
|
|
|
+void process_uart_data(const char *data, int length)
|
|
|
+{
|
|
|
+ // 有效性检查
|
|
|
+ if (data == NULL || length <= 0) return;
|
|
|
+ json_ctx.last_received = rt_tick_get();
|
|
|
+
|
|
|
+ // 缓冲区溢出保护
|
|
|
+ int remain_space = MAX_JSON_BUFFER - json_ctx.index - 1;
|
|
|
+ if (remain_space < length) {
|
|
|
+ rt_kprintf("[JSON] Buffer overflow (%d/%d)\n",
|
|
|
+ json_ctx.index + length, MAX_JSON_BUFFER);
|
|
|
+ json_ctx.index = 0; // 清空缓冲区重新开始
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 追加新数据
|
|
|
+ rt_memcpy(json_ctx.buffer + json_ctx.index, data, length);
|
|
|
+ json_ctx.index += length;
|
|
|
+ json_ctx.buffer[json_ctx.index] = '\0';
|
|
|
+
|
|
|
+ // 循环处理所有完整报文
|
|
|
+ while (1) {
|
|
|
+ int start_pos, end_pos;
|
|
|
+ json_status_t status = find_json_boundary(&start_pos, &end_pos);
|
|
|
+
|
|
|
+ switch (status) {
|
|
|
+ case JSON_OK:
|
|
|
+ if (start_pos != -1 && end_pos != -1) {
|
|
|
+ // 提取有效JSON内容
|
|
|
+ char json_str[512] = {0};
|
|
|
+ int json_len = end_pos - start_pos + 1;
|
|
|
+ rt_strncpy(json_str, json_ctx.buffer + start_pos,
|
|
|
+ RT_MIN(sizeof(json_str)-1, json_len));
|
|
|
+
|
|
|
+ // 调用解析函数
|
|
|
+ if (parseDtu(json_str) == RT_EOK) {
|
|
|
+ rt_kprintf("[JSON] Parsed: %.*s\n", json_len, json_str);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 移动缓冲区剩余内容
|
|
|
+ int remain_data = json_ctx.index - (end_pos + 1);
|
|
|
+ if (remain_data > 0) {
|
|
|
+ rt_memmove(json_ctx.buffer,
|
|
|
+ json_ctx.buffer + end_pos + 1,
|
|
|
+ remain_data);
|
|
|
+ }
|
|
|
+ json_ctx.index = remain_data;
|
|
|
+ json_ctx.buffer[json_ctx.index] = '\0';
|
|
|
+ } else {
|
|
|
+ return; // 无更多完整报文
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case JSON_INCOMPLETE:
|
|
|
+ return; // 等待更多数据
|
|
|
+
|
|
|
+ default:
|
|
|
+ rt_kprintf("[JSON] Error %d at pos %d\n", status, start_pos);
|
|
|
+ // 错误恢复:跳过错误数据
|
|
|
+ json_ctx.index = 0;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/* 入口函数-指令接收*/
|
|
|
static void dtu_thread_entry_recv(void *parameter)
|
|
|
{
|
|
|
struct rx_msg msg;
|
|
|
- rt_err_t result;
|
|
|
- rt_uint32_t rx_length;
|
|
|
- rt_uint32_t rx_err = 0;
|
|
|
- static char str_check[2]={'{','}'};
|
|
|
- static char rx_buffer[512];
|
|
|
- static char rx_buffer_tmp[512];
|
|
|
- static char rx_buffer_tmp2[512];
|
|
|
+ rt_memset(&msg, 0, sizeof(msg));
|
|
|
+ static int rx_err = 0;
|
|
|
while(1)
|
|
|
{
|
|
|
- rt_memset(&msg, 0, sizeof(msg));
|
|
|
+ //
|
|
|
// 从消息队列中获取被回调函数放入消息队列中的内容
|
|
|
- result = rt_mq_recv(&rx_mq_dtu, &msg, sizeof(struct rx_msg), 50);
|
|
|
+ int result = rt_mq_recv(&rx_mq_dtu, &msg, sizeof(struct rx_msg), 50);
|
|
|
+ if (result != RT_EOK){
|
|
|
+ rx_err ++;
|
|
|
+ if(rx_err==54000)//90分钟未接收到数据
|
|
|
+ {
|
|
|
+ if(device_status.version_type==6)
|
|
|
+ {
|
|
|
+ LOG_E("RK3399 transter Error!");
|
|
|
+ ctr_photo(OFF);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ ctr_RTU_DTU(OFF);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rx_err==54100&&device_status.bat_status==0)
|
|
|
+ {
|
|
|
+ LOG_W("通信中断,RTU重新上电");
|
|
|
+ rx_err = 0;
|
|
|
+ ctr_RTU_DTU(ON);
|
|
|
+ ctr_photo(ON);
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 动态分配接收缓冲区
|
|
|
+ char *rx_buffer = rt_malloc(msg.size + 1);
|
|
|
+ if (!rx_buffer) {
|
|
|
+ LOG_E("Memory allocation failed");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 安全读取数据
|
|
|
+ int rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
|
|
|
+ if (rx_length <= 0) {
|
|
|
+ rt_free(rx_buffer);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ rx_buffer[rx_length] = '\0';
|
|
|
+ // 处理数据(新增调试接口)
|
|
|
+ LOG_I("Raw Data:%s-%d",rx_buffer, rx_length);
|
|
|
+
|
|
|
+ if(device_status.dtype==3)
|
|
|
+ {
|
|
|
+ HMI_WRITE("sysSet.va0.txt=\"%s\"",rx_buffer);
|
|
|
+ rt_timer_stop(timer_uart2);
|
|
|
+ }
|
|
|
+ process_uart_data(rx_buffer, rx_length);
|
|
|
+ rt_free(rx_buffer);
|
|
|
+ #if 0
|
|
|
if(result == RT_EOK)
|
|
|
{
|
|
|
+
|
|
|
rx_err = 0;
|
|
|
rx_length =(sizeof(rx_buffer) - 1) > msg.size ?
|
|
|
msg.size : sizeof(rx_buffer) - 1;
|
|
|
@@ -167,6 +342,7 @@ static void dtu_thread_entry_recv(void *parameter)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
//过滤异常数据
|
|
|
char str_check_head[2];
|
|
|
char str_check_end[2];
|
|
|
@@ -187,48 +363,49 @@ static void dtu_thread_entry_recv(void *parameter)
|
|
|
else {
|
|
|
rt_sprintf(rx_buffer_tmp2,"%s",rx_buffer);
|
|
|
rt_sprintf(rx_buffer, "%s%s",rx_buffer_tmp,rx_buffer_tmp2);
|
|
|
- //rt_kprintf("rxbuffer:%s",rx_buffer);
|
|
|
parseDtu(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));
|
|
|
}
|
|
|
- //rt_kprintf("%s",rx_buffer);
|
|
|
+
|
|
|
}
|
|
|
+ #endif
|
|
|
}
|
|
|
- else {
|
|
|
- rx_err ++;
|
|
|
- if(rx_err==54000)//90分钟未接收到数据
|
|
|
- {
|
|
|
- if(device_status.version_type==6)
|
|
|
- {
|
|
|
- LOG_E("RK3399 transter Error!");
|
|
|
- ctr_photo(OFF);
|
|
|
- }
|
|
|
- else {
|
|
|
- ctr_RTU_DTU(OFF);
|
|
|
- }
|
|
|
- }
|
|
|
- else if (rx_err==54100&&device_status.bat_status==0)
|
|
|
- {
|
|
|
- LOG_W("通信中断,RTU重新上电");
|
|
|
- rx_err = 0;
|
|
|
- ctr_RTU_DTU(ON);
|
|
|
- ctr_photo(ON);
|
|
|
- }
|
|
|
- }
|
|
|
- //rt_kprintf("%s\n",rx_json_buffer);
|
|
|
- // 将内容写回到串口1
|
|
|
- //rt_device_write(dtuserial, 0, &rx_json_buffer[0], rx_length);
|
|
|
+// else {
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// 函数定义:判断数组中是否有大于 100 的元素
|
|
|
+int hasElementGreaterThan400(uint16_t arr[], int size) {
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
+ if (arr[i] < 400) {
|
|
|
+ return 1; // 找到大于 100 的元素,返回 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 0; // 遍历完数组,没有找到大于 100 的元素,返回 0
|
|
|
+}
|
|
|
|
|
|
+int hasElementGreater_lessThan400(uint16_t arr[], int size) {
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
+ if (arr[i] > 400) {
|
|
|
+ return 1; // 找到大于 100 的元素,返回 1
|
|
|
+ }
|
|
|
}
|
|
|
+ return 0; // 遍历完数组,没有找到大于 100 的元素,返回 0
|
|
|
}
|
|
|
+
|
|
|
/*入口函数-指令发送*/
|
|
|
static void dtu_thread_entry_send(void *parameter)
|
|
|
{
|
|
|
|
|
|
device_status.power_status = 1;
|
|
|
device_status.num_updata = 0;
|
|
|
+ static uint16_t current_arry[10];
|
|
|
+ static uint8_t record_current = 0;
|
|
|
rt_thread_delay(10000);
|
|
|
static rt_uint16_t wait_i = 0;
|
|
|
static rt_uint8_t check_i = 0;
|
|
|
@@ -242,72 +419,90 @@ static void dtu_thread_entry_send(void *parameter)
|
|
|
now_tm =*localtime(&now_t);
|
|
|
if(atoi(device_status.net)==0||atoi(device_status.gps)==1||(now_tm.tm_year+1900 >=2024)) //当前时间大于2024
|
|
|
{
|
|
|
- if(device_status.rain_status==1||device_status.temp_status==1)
|
|
|
+ if(device_status.rain_status==1||device_status.temp_status==1)
|
|
|
+ {
|
|
|
+ if(check_i==0)
|
|
|
{
|
|
|
- if(check_i==0)
|
|
|
- {
|
|
|
- check_i = 1;
|
|
|
- device_status.num_updata = 0;
|
|
|
- }
|
|
|
+ check_i = 1;
|
|
|
+ device_status.num_updata = 0;
|
|
|
}
|
|
|
- else {
|
|
|
- check_i = 0;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ check_i = 0;
|
|
|
+ }
|
|
|
+ if(device_status.num_updata!=0)
|
|
|
+ {
|
|
|
+ device_status.num_updata--;
|
|
|
+ //屏幕休眠
|
|
|
+ if(device_status.num_updata==(device_status.dattim * 60-10))
|
|
|
+ {
|
|
|
+ HMI_WRITE("sleep=%d",1);
|
|
|
}
|
|
|
- if(device_status.num_updata!=0)
|
|
|
+ LOG_I("掉电检测:%d-%d",atoi(device_status.voltage),device_status.power_status);
|
|
|
+ //检测到电源掉电
|
|
|
+ if(atoi(device_status.voltage)<5&&device_status.power_status==1)
|
|
|
{
|
|
|
- device_status.num_updata--;
|
|
|
- //屏幕休眠
|
|
|
- if(device_status.num_updata==(device_status.dattim * 60-10))
|
|
|
+ power_i++;
|
|
|
+ //确定网络状态
|
|
|
+ if(power_i==10)
|
|
|
{
|
|
|
- HMI_WRITE("sleep=%d",1);
|
|
|
+ device_status.bat_status = 1;
|
|
|
+ rt_sprintf(device_status.net, "1");
|
|
|
+ HMI_WRITE("sleep=%d",1); //屏幕休眠
|
|
|
+ DTU_Write("%s",makeJson_Warn("power down","power"));
|
|
|
+ device_status.power_status = 0;
|
|
|
+ rt_thread_delay(5000);
|
|
|
+ ctr_router(OFF);
|
|
|
+ ctr_RTU_DTU(OFF);
|
|
|
+ power_i = 0;
|
|
|
}
|
|
|
- LOG_I("掉电检测:%d-%d",atoi(device_status.voltage),device_status.power_status);
|
|
|
- //检测到电源掉电
|
|
|
- if(atoi(device_status.voltage)<5&&device_status.power_status==1)
|
|
|
+ }
|
|
|
+ if(atoi(device_status.voltage)>12&&device_status.power_status==0) //电压正常
|
|
|
+ {
|
|
|
+ device_status.power_status = 1;
|
|
|
+ ctr_router(ON);
|
|
|
+ ctr_RTU_DTU(ON);
|
|
|
+ power_i = 0;
|
|
|
+ }
|
|
|
+ if(device_status.work_status==1&&device_status.num_updata%5==0&&atoi(device_status.power)>20) //每过5S把电流值存入数组,连续10条数据的电流值大于400mA判断为正常
|
|
|
+ {
|
|
|
+ current_arry[record_current] = atoi(device_status.power);
|
|
|
+ record_current++;
|
|
|
+ if(record_current==10)
|
|
|
{
|
|
|
- power_i++;
|
|
|
- //确定网络状态
|
|
|
- if(power_i==10)
|
|
|
+ record_current = 0;
|
|
|
+ if(hasElementGreaterThan400(current_arry, 10)==0) //连续10条电流值大于400,灯管状态正常
|
|
|
{
|
|
|
- device_status.bat_status = 1;
|
|
|
- rt_sprintf(device_status.net, "1");
|
|
|
- HMI_WRITE("sleep=%d",1); //屏幕休眠
|
|
|
- DTU_Write("%s",makeJson_Warn("power down","power"));
|
|
|
- device_status.power_status = 0;
|
|
|
- rt_thread_delay(5000);
|
|
|
- ctr_router(OFF);
|
|
|
- ctr_RTU_DTU(OFF);
|
|
|
- power_i = 0;
|
|
|
+ device_status.lamp_status = 0;
|
|
|
}
|
|
|
- }
|
|
|
- if(atoi(device_status.voltage)>12&&device_status.power_status==0) //电压正常
|
|
|
- {
|
|
|
- device_status.power_status = 1;
|
|
|
- ctr_router(ON);
|
|
|
- ctr_RTU_DTU(ON);
|
|
|
- power_i = 0;
|
|
|
+ if(hasElementGreater_lessThan400(current_arry,10)==0) //连续10条电流值小于400,灯管状态异常
|
|
|
+ {
|
|
|
+ device_status.lamp_status = 1;
|
|
|
+ }
|
|
|
+ memset(current_arry,0,sizeof(current_arry));
|
|
|
}
|
|
|
}
|
|
|
- else {
|
|
|
- char *readinfo = makeJson_ReadInfo();
|
|
|
- rt_kprintf("upload data:%s\n",readinfo);
|
|
|
- DTU_Write("%s",readinfo);
|
|
|
- rt_free(readinfo);
|
|
|
- rt_thread_delay(1000);
|
|
|
- UpLoad_Data();
|
|
|
- if(atoi(device_status.fuse_voltage)<1)
|
|
|
- {
|
|
|
- rt_thread_delay(500);
|
|
|
- static char res[30];
|
|
|
- sprintf(res, "Fuse is fusing:%s",device_status.fuse_voltage);
|
|
|
- char * res_fuse_warn = makeJson_Warn(res,"device");
|
|
|
- DTU_Write("%s",res_fuse_warn);
|
|
|
- rt_free(res_fuse_warn);
|
|
|
- }
|
|
|
- device_status.num_updata = device_status.dattim * 60;
|
|
|
- if(device_status.dattim==0) device_status.dattim=20; //数据上传时间间隔设置为0?
|
|
|
- if(device_status.bat_status==0) device_status.power_status = 1; //解除欠压,清除标志位
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ char *readinfo = makeJson_ReadInfo();
|
|
|
+ rt_kprintf("upload data:%s\n",readinfo);
|
|
|
+ DTU_Write("%s",readinfo);
|
|
|
+ rt_free(readinfo);
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ UpLoad_Data();
|
|
|
+ if(atoi(device_status.fuse_voltage)<1)
|
|
|
+ {
|
|
|
+ rt_thread_delay(500);
|
|
|
+ static char res[30];
|
|
|
+ sprintf(res, "Fuse is fusing:%s",device_status.fuse_voltage);
|
|
|
+ char * res_fuse_warn = makeJson_Warn(res,"device");
|
|
|
+ DTU_Write("%s",res_fuse_warn);
|
|
|
+ rt_free(res_fuse_warn);
|
|
|
}
|
|
|
+ device_status.num_updata = device_status.dattim * 60;
|
|
|
+ if(device_status.dattim==0) device_status.dattim=20; //数据上传时间间隔设置为0?
|
|
|
+ if(device_status.bat_status==0) device_status.power_status = 1; //解除欠压,清除标志位
|
|
|
+ }
|
|
|
}
|
|
|
else {
|
|
|
wait_i ++;
|
|
|
@@ -729,16 +924,8 @@ char * makeJson()
|
|
|
char utos[5];
|
|
|
if(device_status.gps==NULL)
|
|
|
rt_sprintf(device_status.gps, "0");
|
|
|
- //如果设备工作并且电流小于500,并且不是上电启动灯管异常
|
|
|
- if(atoi(device_status.power)<400&&atoi(device_status.power)!=0&&device_status.work_status==1&&makejson_sta!=0)
|
|
|
- {
|
|
|
- #if LAMP_EN == 0
|
|
|
- LOG_I("Current is:%d",atoi(device_status.power));
|
|
|
- if(atoi(device_status.power)>10) //过滤电流检测芯片损坏导致电流直为0 的异常
|
|
|
- device_status.lamp_status = 1;
|
|
|
- #endif
|
|
|
- }
|
|
|
- else {
|
|
|
+
|
|
|
+ if(device_status.work_status==0) {
|
|
|
device_status.lamp_status = 0;
|
|
|
}
|
|
|
if(atoi(device_status.power)>5000)
|
|
|
@@ -1010,6 +1197,10 @@ char * makeJson()
|
|
|
cJSON_AddNumberToObject(pSubJson,"rcnt",device_status.rebootcnt);
|
|
|
//电流(当前)
|
|
|
cJSON_AddStringToObject(pSubJson,"current",device_status.power);
|
|
|
+ #if PCB_V1 == 0
|
|
|
+ //加热电流(当前)
|
|
|
+ cJSON_AddStringToObject(pSubJson,"current_heat",device_status.heat_power);
|
|
|
+ #endif
|
|
|
//电压
|
|
|
cJSON_AddStringToObject(pSubJson,"vbat",device_status.voltage);
|
|
|
//数据上传间隔
|
|
|
@@ -1118,16 +1309,13 @@ int parseDtu(char *json_string)
|
|
|
cJSON* project = NULL; //Project
|
|
|
cJSON* ds = NULL; //设备状态
|
|
|
cJSON* vt = NULL; //版本类型
|
|
|
-// cJSON* account_status = NULL; //卡状态
|
|
|
-// cJSON* data_plan = NULL; //套餐
|
|
|
-// cJSON* data_usage = NULL; //已使用
|
|
|
-// cJSON* expiry_date = NULL; //到期时间
|
|
|
cJSON* mqttcfg1 = NULL;
|
|
|
cJSON* mqttcfg2 = NULL;
|
|
|
cJSON* type =NULL;
|
|
|
cJSON* hum = NULL;
|
|
|
cJSON* tmp = NULL;
|
|
|
cJSON* link_sta = NULL;
|
|
|
+ cJSON* link_ip = NULL;
|
|
|
cJSON* value_commn= NULL;
|
|
|
rt_kprintf("%s\n",json_string);
|
|
|
cJSON *root = cJSON_Parse(json_string);
|
|
|
@@ -1139,12 +1327,100 @@ int parseDtu(char *json_string)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+
|
|
|
item_cmd = cJSON_GetObjectItem(root,"cmd");
|
|
|
+ cJSON* item_aplay = cJSON_GetObjectItem(root,"aplay");
|
|
|
item_checkself = cJSON_GetObjectItem(root,"selfcheck");
|
|
|
photolink = cJSON_GetObjectItem(root,"photolink");
|
|
|
cJSON* ledsta = cJSON_GetObjectItem(root,"ledsta");
|
|
|
cJSON* cam_cmd= cJSON_GetObjectItem(root,"cam_code");
|
|
|
+ cJSON* yolo_start = cJSON_GetObjectItem(root,"yolo");
|
|
|
item_ext=cJSON_GetObjectItem(root,"ext");
|
|
|
+ if(yolo_start!=NULL)
|
|
|
+ {
|
|
|
+ if(strcmp(yolo_start->valuestring,"start")==0) //”识别进程已启动“
|
|
|
+ {
|
|
|
+ //CAB6 B1F0 BDF8 B3CC D2D1 C6F4 B6AF
|
|
|
+ static USHORT sound_7[] = {0xCAB6,0xB1F0,0xBDF8,0xB3CC,0xD2D1,0xC6F4,0xB6AF};
|
|
|
+ _485_play(sound_7,7);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(item_aplay!=NULL)
|
|
|
+ {
|
|
|
+ if(strcmp(item_aplay->valuestring,"data_upload")==0) //数据上传中
|
|
|
+ {
|
|
|
+ //CAFD BEDD C9CF B4AB D6D0
|
|
|
+ static USHORT sound_0[] = {0xcafd,0xbedd,0xc9cf,0xb4ab,0xd6d0};
|
|
|
+ _485_play(sound_0,5);
|
|
|
+ }else if(strcmp(item_aplay->valuestring,"kuaimen")==0) //数据上传中
|
|
|
+ {
|
|
|
+ //736F 756E 6431 3031
|
|
|
+ static USHORT sound_1[] = {0x736f,0x756e,0x6431,0x3031};
|
|
|
+ _485_play(sound_1,4);
|
|
|
+ }else if(strcmp(item_aplay->valuestring,"photouploadsuccess")==0) //图片上传成功
|
|
|
+ {
|
|
|
+ //C9CF B4AB B3C9 B9A6
|
|
|
+ static USHORT sound_2[] = {0xc9cf,0xb4ab,0xb3c9,0xb9a6};
|
|
|
+ _485_play(sound_2,4);
|
|
|
+ }else if(strcmp(item_aplay->valuestring,"photouploadfailed")==0) //图片上传失败
|
|
|
+ {
|
|
|
+ //C9CF B4AB CAA7 B0DC
|
|
|
+ static USHORT sound_3[] = {0xc9cf,0xb4ab,0xcaa7,0xb0dc};
|
|
|
+ _485_play(sound_3,4);
|
|
|
+ }else if(strcmp(item_aplay->valuestring,"welcom")==0) //JETSON启动
|
|
|
+ {
|
|
|
+ //4A45 5453 4F4E C6F4 B6AF
|
|
|
+ static USHORT sound_4[] = {0x4A45,0x5453,0x4F4E,0xC6F4,0xB6AF};
|
|
|
+ _485_play(sound_4,5);
|
|
|
+ }else if(strcmp(item_aplay->valuestring,"fdsucess")==0) //升级文件下载成功
|
|
|
+ {
|
|
|
+ //C9FD BCB6 CEC4 BCFE CFC2 D4D8 B3C9 B9A6
|
|
|
+ static USHORT sound_5[] = {0xC9FD,0xBCB6,0xCEC4,0xBCFE,0xCFC2,0xD4D8,0xB3C9,0xB9A6};
|
|
|
+ _485_play(sound_5,8);
|
|
|
+ }else if(strcmp(item_aplay->valuestring,"fdfailed")==0) //”升级文件下载失败“
|
|
|
+ {
|
|
|
+ //C9FD BCB6 CEC4 BCFE CFC2 D4D8 CAA7 B0DC
|
|
|
+ static USHORT sound_6[] = {0xC9FD,0xBCB6,0xCEC4,0xBCFE,0xCFC2,0xD4D8,0xCAA7,0xB0DC};
|
|
|
+ _485_play(sound_6,8);
|
|
|
+ }else if(strcmp(item_aplay->valuestring,"yolodone")==0) //”识别进程已结束“
|
|
|
+ {
|
|
|
+ //CAB6 B1F0 BDF8 B3CC D2D1 BDE1 CAF8
|
|
|
+ static USHORT sound_8[] = {0xCAB6,0xB1F0,0xBDF8,0xB3CC,0xD2D1,0xBDE1,0xCAF8};
|
|
|
+ _485_play(sound_8,8);
|
|
|
+ }else if(strcmp(item_aplay->valuestring,"onmessage")==0) //”提示音“
|
|
|
+ {
|
|
|
+ //sound10?
|
|
|
+ static USHORT sound_9[] = {0xCAB6,0xB1F0,0xBDF8,0xB3CC,0xD2D1,0xBDE1,0xCAF8};
|
|
|
+ _485_play(sound_9,8);
|
|
|
+ }else if(strcmp(item_aplay->valuestring,"startupdate")==0) //”开始升级“
|
|
|
+ {
|
|
|
+ //BFAA CABC C9FD BCB6
|
|
|
+ static USHORT sound_10[] = {0xBFAA,0xCABC,0xC9FD,0xBCB6};
|
|
|
+ _485_play(sound_10,4);
|
|
|
+ }else if(strcmp(item_aplay->valuestring,"updatesuccess")==0) //”升级成功“
|
|
|
+ {
|
|
|
+ //C9FD BCB6 B3C9 B9A6
|
|
|
+ static USHORT sound_11[] = {0xC9FD,0xBCB6,0xB3C9,0xB9A6};
|
|
|
+ _485_play(sound_11,4);
|
|
|
+ }else if(strcmp(item_aplay->valuestring,"updatefailed")==0) //”升级失败“
|
|
|
+ {
|
|
|
+ //C9FD BCB6 CAA7 B0DC
|
|
|
+ static USHORT sound_12[] = {0xC9FD,0xBCB6,0xCAA7,0xB0DC};
|
|
|
+ _485_play(sound_12,4);
|
|
|
+ }else if(strcmp(item_aplay->valuestring,"sound113")==0) //”mqtt消息提示音“
|
|
|
+ {
|
|
|
+ //736F 756E 6431 3133
|
|
|
+ static USHORT sound_13[] = {0x736F,0x756E,0x6431,0x3133};
|
|
|
+ _485_play(sound_13,4);
|
|
|
+ }else if(strcmp(item_aplay->valuestring,"net_connect")==0) //"网络连接成功“
|
|
|
+ {
|
|
|
+ //CDF8 C2E7 C1AC BDD3 B3C9 B9A6
|
|
|
+ static USHORT sound_14[] = {0xCDF8,0xC2E7,0xC1AC,0xBDD3,0xB3C9,0xB9A6};
|
|
|
+ _485_play(sound_14,6);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
if(cam_cmd!=NULL){
|
|
|
//先检查定时器状态,否则会崩溃
|
|
|
rt_timer_stop(timer_uart2);
|
|
|
@@ -1211,12 +1487,19 @@ int parseDtu(char *json_string)
|
|
|
{
|
|
|
if(strstr(item_cmd->valuestring,"takephoto")!=RT_NULL)
|
|
|
{
|
|
|
- //HK_TakePhoto();
|
|
|
- device_status.photo_ws=1;
|
|
|
- char *photo = makeJson_Warn("takephoto","control");
|
|
|
- DTU_Write("%s",photo);
|
|
|
- rt_free(photo);
|
|
|
- rt_thread_delay(2000);
|
|
|
+ #if 0
|
|
|
+ ctr_led(ON);
|
|
|
+ //发送拍照指令
|
|
|
+ char *takephotojson = makeJson_takephoto();
|
|
|
+ DTU_Write("%s",takephotojson);
|
|
|
+ rt_free(takephotojson);
|
|
|
+ #else
|
|
|
+ device_status.photo_ws=1;
|
|
|
+ char *photo = makeJson_Warn("takephoto","control");
|
|
|
+ DTU_Write("%s",photo);
|
|
|
+ rt_free(photo);
|
|
|
+ rt_thread_delay(2000);
|
|
|
+ #endif
|
|
|
}
|
|
|
else if (strstr(item_cmd->valuestring,"json_w_clock")!=RT_NULL) {
|
|
|
rt_kprintf("查询时间配置!\n");
|
|
|
@@ -1320,6 +1603,16 @@ int parseDtu(char *json_string)
|
|
|
}
|
|
|
LOG_I("收到自检指令:%d",device_status.selfcheck_ws);
|
|
|
}
|
|
|
+ else if(strstr(type->valuestring,"insect_kill")!=RT_NULL)
|
|
|
+ {
|
|
|
+ device_status.autotakepic = 10;
|
|
|
+ LOG_W("收到害虫信号!");
|
|
|
+ }
|
|
|
+ else if(strstr(type->valuestring,"insect_save")!=RT_NULL)
|
|
|
+ {
|
|
|
+ device_status.autotakepic = 11;
|
|
|
+ LOG_W("收到益虫信号!");
|
|
|
+ }
|
|
|
}
|
|
|
//切换平台
|
|
|
else if (strstr(item_cmd->valuestring,"platform")!=RT_NULL)
|
|
|
@@ -1500,6 +1793,7 @@ int parseDtu(char *json_string)
|
|
|
mqttcfg1 = cJSON_GetObjectItem(item_ext,"mqttcfg1");
|
|
|
mqttcfg2 = cJSON_GetObjectItem(item_ext,"mqttcfg2");
|
|
|
link_sta = cJSON_GetObjectItem(item_ext,"link_sta");
|
|
|
+ link_ip = cJSON_GetObjectItem(item_ext,"link_ip");
|
|
|
photo_sta = cJSON_GetObjectItem(item_ext,"photo_sta");
|
|
|
cJSON *gps_inuse = cJSON_GetObjectItem(item_ext,"gps_inuse");
|
|
|
cJSON *gps_view = cJSON_GetObjectItem(item_ext,"gps_view");
|
|
|
@@ -1519,6 +1813,13 @@ int parseDtu(char *json_string)
|
|
|
HMI_WRITE("menu.cpu_temp.txt=\"%d.%d℃\"",atoi(value_commn->valuestring)/1000,atoi(value_commn->valuestring)%1000);
|
|
|
|
|
|
}
|
|
|
+ if(link_ip!=NULL)
|
|
|
+ {
|
|
|
+ //sprintf(device_status.)
|
|
|
+ sprintf(device_status.link_ip,"%s",link_ip->valuestring);
|
|
|
+ //HMI_WRITE("menu.t0.txt=\"%s\"",link_ip->valuestring);
|
|
|
+ }
|
|
|
+
|
|
|
if(strstr(device_status.imei,imei->valuestring)==RT_NULL)
|
|
|
{
|
|
|
rt_kprintf("Change IMEI:new:%s-old:%s",imei->valuestring,device_status.imei);
|
|
|
@@ -1628,7 +1929,6 @@ int parseDtu(char *json_string)
|
|
|
rt_sprintf(device_status.gps,"%s",gps->valuestring);
|
|
|
if(atoi(gps->valuestring)!=0)
|
|
|
{
|
|
|
- #if BOOT_ERR == 1
|
|
|
if(atoi(gps->valuestring)==1)
|
|
|
rt_sprintf(device_status.gps_state, "%s","GPS+BD");
|
|
|
|
|
|
@@ -1638,7 +1938,7 @@ int parseDtu(char *json_string)
|
|
|
if(gps_view!=NULL){
|
|
|
device_status.gps_view = atoi(gps_view->valuestring);
|
|
|
}
|
|
|
- #endif
|
|
|
+
|
|
|
if(strstr(device_status.lat,lat->valuestring)==NULL)
|
|
|
{
|
|
|
memset(device_status.lat,0,sizeof(device_status.lat));
|
|
|
@@ -2273,3 +2573,4 @@ void UpLoad_Data(void)
|
|
|
//播放数据上传中语音
|
|
|
}
|
|
|
|
|
|
+MSH_CMD_EXPORT(UpLoad_Data,UpLoad_Data);
|