/* * Copyright (c) 2006-2020, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2020-05-28 Administrator the first version */ #include #include "hmi.h" #include #include #include "stdarg.h" #include "string.h" #include "stdio.h" #include "dtu_uart2.h" #include #include "control.h" #include "sht30_collect.h" #include #include "sound.h" #include #define DBG_TAG "dtu_uart2.c" #define DBG_LVL LOG_LVL_INFO #include #include #include "beep.h" #define DTU_THREAD_PRIORITY 6 //线程优先级 #define DTU_THREAD_STACK_SIZE 2048 //线程栈空间大小 #define DTU_THREAD_TIMESLICE 5 //时间片 Device_Status_typedef device_status; DataTemp data_arry; /* 串口接收消息结构*/ struct rx_msg { rt_device_t dev; rt_size_t size; }; /* 消息队列句柄 */ static struct rt_messagequeue rx_mq_dtu; rt_thread_t dtu_recv_data = RT_NULL; rt_thread_t dtu_send_data = RT_NULL; rt_device_t dtuserial; /*串口设备句柄*/ struct serial_configure dtuconfig = RT_SERIAL_CONFIG_DEFAULT; /*初始化配置参数*/ static int num_updata = 0; /*****************************************************/ void list_mem(void); //声明 /*****************************************************/ int DTU_uart2_init(void) { dtuserial = rt_device_find(DTU_UART_NAME); /*修改串口配置参数*/ dtuconfig.baud_rate = BAUD_RATE_115200; //修改波特率9600 dtuconfig.data_bits = DATA_BITS_8; //数据位8 dtuconfig.stop_bits = STOP_BITS_1; //停止位1 dtuconfig.bufsz = 512; //缓冲区1k dtuconfig.parity = PARITY_NONE; //奇校验 /* step3:控制串口设备。通过控制接口传入命令控制字,与控制参数 */ rt_device_control(dtuserial, RT_DEVICE_CTRL_CONFIG, &dtuconfig); /* step4:打开串口设备。以DMA接收及轮询发送模式打开串口设备 */ rt_device_open(dtuserial, RT_DEVICE_FLAG_DMA_RX); return 0; } /*数据发送*/ void DTU_Write(char *fmt, ...) { va_list arg; static char dtu_str[800]; rt_size_t str_length; va_start(arg,fmt); str_length = rt_vsnprintf(dtu_str, sizeof(dtu_str) - 1, fmt, arg); if (str_length > 800 - 1) str_length = 800 - 1; rt_device_write(dtuserial, 0, dtu_str, str_length); va_end(arg); memset(dtu_str,'\0',sizeof(dtu_str)); } /* 接收数据回调函数 */ static rt_err_t dtu_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_dtu,&msg, sizeof(struct rx_msg)); if ( result == -RT_EFULL) { /* 消息队列满 */ rt_kprintf("message queue full!\n"); } return result; } /* 入口函数-指令接收*/ static void dtu_thread_entry_recv(void *parameter) { struct rx_msg msg; rt_err_t result; rt_uint32_t rx_length; static char str_check[2]={'{','}'}; static char rx_buffer[512]; static char rx_buffer_tmp[512]; static char rx_buffer_tmp2[512]; while(1) { rt_memset(&msg, 0, sizeof(msg)); // 从消息队列中获取被回调函数放入消息队列中的内容 result = rt_mq_recv(&rx_mq_dtu, &msg, sizeof(struct rx_msg), 100); if(result == RT_EOK) { rx_length =(sizeof(rx_buffer) - 1) > msg.size ? msg.size : sizeof(rx_buffer) - 1; rx_length = rt_device_read(msg.dev, 0, &rx_buffer[0], rx_length); rx_buffer[rx_length] = '\0'; rt_kprintf("recv data:%s\n",rx_buffer); //过滤异常数据 char str_check_head[2]; char str_check_end[2]; rt_sprintf(str_check_head, "%c",rx_buffer[0]); 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); 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)); } else { if(rx_buffer[rx_length-1]!='}') { rt_sprintf(rx_buffer_tmp, "%s",rx_buffer); } 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)); } //LOG_W("%s",rx_buffer); } } //rt_kprintf("%s\n",rx_json_buffer); // 将内容写回到串口1 //rt_device_write(dtuserial, 0, &rx_json_buffer[0], rx_length); } } /*入口函数-指令发送*/ static void dtu_thread_entry_send(void *parameter) { static uint8_t dev_sta = 1;//开机置1 rt_thread_delay(10000); //20S等待联网 while(1) { if(num_updata!=0) { num_updata --; // //屏幕休眠 if(num_updata==(device_status.dattim * 60-10)) { HMI_WRITE("sleep=%d",1); } } else { char *readinfo = makeJson_ReadInfo(); LOG_I("upload data:%s\n",readinfo); if(dev_sta==1) { DTU_Write("%s",makeJson_Warn("turnon", "dev_sta")); dev_sta = 0; rt_thread_delay(500); } DTU_Write("%s",readinfo); rt_thread_delay(2000); UpLoad_Data(); rt_free(readinfo); 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); } if(Read_Real_Voltage()/100<10) { rt_thread_delay(500); static char warn_power[20]; sprintf(warn_power,"Power up"); char * res_power_warn = makeJson_Warn(warn_power,"power"); DTU_Write("%s",res_power_warn); rt_free(res_power_warn); } num_updata = device_status.dattim * 60; } rt_thread_mdelay(1000); } } /* 创建线程 */ int dtu_data_play(void) { rt_err_t rm_dtu_result; DTU_uart2_init(); //初始化消息队列 rm_dtu_result = rt_mq_init(&rx_mq_dtu, "dtu", &data_arry.msg_pool[0], 128 - sizeof(void*), sizeof(data_arry.msg_pool), RT_IPC_FLAG_FIFO); if(rm_dtu_result==RT_EOK) { rt_kprintf("消息队列创建成功!!"); } else { rt_kprintf("消息队列创建失败!!"); } /* 设置接收回调函数 */ rt_device_set_rx_indicate(dtuserial, dtu_input); /*创建线程-指令发送*/ dtu_send_data = rt_thread_create("DTU_Uart_thread_send", dtu_thread_entry_send,RT_NULL, DTU_THREAD_STACK_SIZE, 19, DTU_THREAD_TIMESLICE ); /* 创建线程-指令接收解析*/ dtu_recv_data = rt_thread_create("DTU_Uart_thread_recv", dtu_thread_entry_recv, RT_NULL, DTU_THREAD_STACK_SIZE, DTU_THREAD_PRIORITY, DTU_THREAD_TIMESLICE); /* 如果获得线程控制块,启动这个线程 */ if(dtu_send_data!=RT_NULL) rt_thread_startup(dtu_send_data); /* 如果获得线程控制块,启动这个线程 */ if (dtu_recv_data != RT_NULL) rt_thread_startup(dtu_recv_data); return 0; } char * makeJson_ReadInfo() { cJSON * rJsonRoot = NULL; rJsonRoot = cJSON_CreateObject(); if(NULL==rJsonRoot) { return NULL; } cJSON_AddStringToObject(rJsonRoot, "cmd", "GetInfo"); char * r = cJSON_PrintUnformatted(rJsonRoot); if(NULL == r) { cJSON_Delete(rJsonRoot); return NULL; } cJSON_Delete(rJsonRoot); return r; } //预警消息 char *makeJson_Warn(char * s,char *t) { cJSON * wJsonRoot = NULL; wJsonRoot = cJSON_CreateObject(); if(NULL==wJsonRoot) { return NULL; } cJSON_AddStringToObject(wJsonRoot, "cmd", "warn"); cJSON * pubstring = NULL; pubstring = cJSON_CreateObject(); if(NULL==pubstring) { rt_kprintf("cJSON pubstring NULL!!!\n"); return NULL; } cJSON_AddItemToObject(wJsonRoot, "ext", pubstring); cJSON_AddStringToObject(pubstring,"status",s);// cJSON_AddStringToObject(pubstring,"type",t); char * w = cJSON_PrintUnformatted(wJsonRoot); if(NULL == w) { cJSON_Delete(wJsonRoot); rt_kprintf("wJsonRoot cJSON_Delete NULL!!!\n"); return NULL; } cJSON_Delete(wJsonRoot); return w; } /*生成JSON数据*/ char * makeJson() { device_status.dtype = 7; time_t stamp=time(RT_NULL); static struct tm tm; gmtime_r(&stamp, &tm); rt_sprintf(device_status.stamp,"%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); char ct1[10],ct2[10]; rt_sprintf(ct1,"%d-%d",device_status.culture_sh1,device_status.culture_eh1); rt_sprintf(ct2,"%d-%d",device_status.culture_sh2,device_status.culture_eh2); rt_kprintf("ct1-ct2:%s\n",ct1); device_status.coll_time[0] = ct1; device_status.coll_time[1] = ct2; cJSON * pJsonRoot = NULL; cJSON *data_clt = NULL; data_clt = cJSON_CreateStringArray(device_status.coll_time,2); pJsonRoot = cJSON_CreateObject(); if(NULL==pJsonRoot) { rt_kprintf("cJSON pJsonRoot NULL!!!\n"); return NULL; } cJSON_AddStringToObject(pJsonRoot, "cmd", "data"); cJSON * pSubJson = NULL; pSubJson = cJSON_CreateObject(); if(NULL==pSubJson) { rt_kprintf("cJSON pSubJson NULL!!!\n"); return NULL; } rt_sprintf(device_status.driver,"%s-%s",VERSION,device_status.driver_4g); cJSON_AddItemToObject(pJsonRoot, "ext", pSubJson); cJSON_AddStringToObject(pSubJson, "dver", device_status.driver); //版本号,字符型 cJSON_AddStringToObject(pSubJson,"proj",device_status.project); //项目类型 cJSON_AddNumberToObject(pSubJson,"dtype",device_status.dtype); //设备类型 cJSON_AddNumberToObject(pSubJson,"shake_sec",device_status.drop_sec); //震动时间 cJSON_AddNumberToObject(pSubJson,"gps",device_status.gps); //定位状态 cJSON_AddNumberToObject(pSubJson,"ws",device_status.work_status); //工作状态 cJSON_AddNumberToObject(pSubJson,"ds",device_status.ds); //开关状态 cJSON_AddStringToObject(pSubJson,"ah",device_status.humidity); //湿度 cJSON_AddStringToObject(pSubJson,"at",device_status.tempture); //温度 cJSON_AddNumberToObject(pSubJson,"batStatus",device_status.bat_status); //电池状态 cJSON_AddStringToObject(pSubJson,"stamp",device_status.stamp); //时间 cJSON_AddStringToObject(pSubJson,"imei",device_status.imei); //IMEI cJSON_AddStringToObject(pSubJson,"iccid",device_status.iccid); //ICCID //经度 cJSON_AddStringToObject(pSubJson,"lng",device_status.lng); //纬度 cJSON_AddStringToObject(pSubJson,"lat",device_status.lat); //箱体温度 cJSON_AddStringToObject(pSubJson,"box_tem",device_status.tempture); //开机次数 cJSON_AddNumberToObject(pSubJson,"rcnt",device_status.rebootcnt); //电流(当前) cJSON_AddStringToObject(pSubJson,"current",device_status.power); //电压 cJSON_AddStringToObject(pSubJson,"vbat",device_status.voltage); //保险丝电压 cJSON_AddStringToObject(pSubJson,"fuse_voltage",device_status.fuse_voltage); //数据上传间隔 cJSON_AddNumberToObject(pSubJson,"dat_f",device_status.dattim); //培养时间(参数) cJSON_AddNumberToObject(pSubJson,"cul_time",device_status.culture_time); //收集时间 cJSON_AddItemToObject(pSubJson,"coll_time",data_clt); //培养仓当前温度 cJSON_AddNumberToObject(pSubJson,"pre_temp",device_status.culture_tempture); //培养仓设定温度 cJSON_AddNumberToObject(pSubJson,"set_temp",device_status.set_tempture); //制冷开关 cJSON_AddNumberToObject(pSubJson,"cold_sw",device_status.cold_sw); //风机开关 cJSON_AddNumberToObject(pSubJson,"wind_sw",device_status.collect_fan_status); //已培养时间 cJSON_AddNumberToObject(pSubJson,"staytime",device_status.staytime); //信号强度 cJSON_AddNumberToObject(pSubJson,"csq",device_status.csq); //分辨率 cJSON_AddNumberToObject(pSubJson,"imgres",device_status.imgres); //相机状态 cJSON_AddNumberToObject(pSubJson,"usb_sta",device_status.usb_sta); // cJSON_AddNumberToObject(pSubJson,"rps",device_status.rps); char * p = cJSON_PrintUnformatted(pJsonRoot); if(NULL == p) { cJSON_Delete(pJsonRoot); rt_kprintf("cJSON_Delete NULL!!!\n"); return NULL; } cJSON_Delete(pJsonRoot); return p; } //JSON数据解析 void parseDtu(char *json_string) { cJSON* item_cmd = NULL; //嵌套ext cJSON* item_ext = NULL; //嵌套ext cJSON* item_data = NULL; cJSON* cul_time = NULL; //培养时间 cJSON* collt = NULL; //收集时间 cJSON* datt = NULL; //数据上传间隔 cJSON* drop_sec = NULL; //滴液时间 cJSON* cold_sw = NULL; //制冷开关 cJSON* wind_sw = NULL; //风机开关 cJSON* imgres = NULL; //分辨率 cJSON* set_temp = NULL; //设定培养温度 cJSON* gps = NULL; //定位状态 cJSON* datetime = NULL; //同步时间 cJSON* lat = NULL; cJSON* lng = NULL; cJSON* csq = NULL; cJSON* net = NULL; cJSON* iccid = NULL; cJSON* imei = NULL; cJSON* sim = NULL; cJSON* driver_4g = NULL; //版本号 cJSON* project = NULL; //Project cJSON* on_off = NULL; //开关机状态 cJSON* account_status = NULL; //卡状态 cJSON* data_plan = NULL; //套餐 cJSON* data_usage = NULL; //已使用 cJSON* expiry_date = NULL; //到期时间 rt_kprintf("%s\n",json_string); cJSON *root = cJSON_Parse(json_string); if(!root) { cJSON_Delete(root); LOG_E("parse json err:%s",json_string); return; } else { item_cmd = cJSON_GetObjectItem(root,"cmd"); item_ext=cJSON_GetObjectItem(root,"ext"); item_data = cJSON_GetObjectItem(root,"data"); if(item_cmd!=RT_NULL) { //对焦拍照 if (strstr(item_cmd->valuestring,"autotakephoto")!=RT_NULL) { device_status.autotakepic = 1; rt_thread_delay(2000); char *photo = makeJson_Warn("autotakephoto","control"); DTU_Write("%s",photo); rt_free(photo); } else if(strstr(item_cmd->valuestring,"takephoto")!=RT_NULL) { ctr_led(ON); //开灯 HK_TakePhoto(); ctr_led(OFF); //关灯 rt_thread_delay(2000); char *photo = makeJson_Warn("takephoto","control"); DTU_Write("%s",photo); rt_free(photo); } else if(strstr(item_cmd->valuestring,"turn")!=RT_NULL) { ctr_turn(90); rt_thread_delay(2000); char *photo = makeJson_Warn("turn","control"); DTU_Write("%s",photo); rt_free(photo); } //向上 else if (strstr(item_cmd->valuestring,"mv_up")!=RT_NULL) { ctr_Motor_Driver(1, 1, 500000,20); } //向下 else if (strstr(item_cmd->valuestring,"mv_down")!=RT_NULL) { ctr_Motor_Driver(1, 0, 500000,20); } //向左 else if (strstr(item_cmd->valuestring,"mv_left")!=RT_NULL) { ctr_Motor_Driver(2, 1, 500000,20); } //向右 else if (strstr(item_cmd->valuestring,"mv_right")!=RT_NULL) { ctr_Motor_Driver(2, 0, 500000,20); } else if (strstr(item_cmd->valuestring,"reboot")!=RT_NULL) { char *restart = makeJson_Warn("sysrem will restart","control"); rt_kprintf("%s\n",restart); rt_thread_delay(2000); DTU_Write("%s",restart); rt_hw_cpu_reset(); } else if (strstr(item_cmd->valuestring,"update")!=RT_NULL) { rt_kprintf("准备升级!!!"); device_status.update_flag = 1; ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag)); rt_kprintf("%s\n",makeJson_Warn("system will update","control")); rt_thread_delay(2000); DTU_Write("%s",makeJson_Warn("system will update","control")); rt_thread_delay(20); rt_hw_cpu_reset(); } else if (strstr(item_cmd->valuestring,"read")!=RT_NULL) { char * readinfo = makeJson_ReadInfo(); DTU_Write("%s",readinfo); rt_kprintf("%s\n",readinfo); rt_free(readinfo); device_status.hmi_fresh = 2; device_status.refresh_num = 15; } else if (strstr(item_cmd->valuestring,"log")!=RT_NULL) { rt_thread_mdelay(2000); read_all_flash_log(); } else if (strstr(item_cmd->valuestring,"synchronization")!=RT_NULL) { //driver_4g = cJSON_GetObjectItem(item_ext,"version"); driver_4g = cJSON_GetObjectItem(item_ext,"dver"); //project = cJSON_GetObjectItem(item_ext,"project"); project = cJSON_GetObjectItem(item_ext,"proj"); datetime = cJSON_GetObjectItem(item_ext,"datetime"); lat = cJSON_GetObjectItem(item_ext,"lat"); lng = cJSON_GetObjectItem(item_ext,"lng"); csq = cJSON_GetObjectItem(item_ext,"csq"); net = cJSON_GetObjectItem(item_ext,"net"); iccid = cJSON_GetObjectItem(item_ext,"iccid"); imei = cJSON_GetObjectItem(item_ext,"imei"); gps = cJSON_GetObjectItem(item_ext,"gps"); //如果DTU的IMEI和FLash中的不一样,保存到FLASH if(strstr(imei->valuestring,device_status.imei)==RT_NULL) { LOG_W("Change IMEI:%s-%s",imei->valuestring,device_status.imei); ef_set_env_blob("imei", imei->valuestring, sizeof(device_status.imei)); //IMEI } //如果DTU的ICCID和FLash中的不一样,保存到FLASH if(strstr(iccid->valuestring,device_status.iccid)==RT_NULL) { LOG_W("Change ICCID:%s-%s",iccid->valuestring,device_status.iccid); ef_set_env_blob("iccid", iccid->valuestring, sizeof(device_status.iccid)); //IMEI } sim = cJSON_GetObjectItem(item_ext,"sim"); rt_kprintf("DTU时间:%s",datetime->valuestring); char year_s[5],month_s[3],day_s[3],hour_s[3],min_s[3],sec_s[3]; strncpy(year_s, datetime->valuestring, 4); strncpy(month_s,datetime->valuestring+4,2); strncpy(day_s,datetime->valuestring+6,2); strncpy(hour_s,datetime->valuestring+8,2); strncpy(min_s,datetime->valuestring+10,2); strncpy(sec_s,datetime->valuestring+12,2); if(atoi(year_s)>2000&&atoi(year_s)<3000&&atoi(month_s)>0&&atoi(month_s)<13&&atoi(day_s)>0&&atoi(day_s)<32) { rt_kprintf("设置时间:%d年%d月%d日\n",atoi(year_s),atoi(month_s),atoi(day_s)); set_date(atoi(year_s),atoi(month_s),atoi(day_s)); } if(atoi(hour_s)>0&&atoi(hour_s)<=24&&atoi(min_s)>=0&&atoi(min_s)<=60&&atoi(sec_s)>=0&&atoi(sec_s)<=60) { rt_kprintf("设置时间:%d时%d分%d秒\n",atoi(hour_s),atoi(min_s),atoi(sec_s)); set_time(atoi(hour_s),atoi(min_s),atoi(sec_s)); } rt_kprintf("参数同步:\nlat:%s\nlng:%s\n",lat->valuestring,lng->valuestring); if(sim->valueint==0) { device_status.sim = 0; } else { device_status.sim = 1; } device_status.csq = atoi(csq->valuestring); device_status.net = net->valueint; device_status.gps = gps->valueint; if(gps->valueint!=0&&sizeof(lat->valuestring)>2) { sprintf(device_status.lat,"%s",lat->valuestring); sprintf(device_status.lng,"%s",lng->valuestring); } else if(gps->valueint==0||sizeof(lat->valuestring)<2) { sprintf(device_status.lat,"%s","34.8088073"); sprintf(device_status.lng,"%s","113.6624298"); } sprintf(device_status.iccid,"%s",iccid->valuestring); sprintf(device_status.imei,"%s",imei->valuestring); sprintf(device_status.driver_4g,"%s",driver_4g->valuestring); sprintf(device_status.project,"%s",project->valuestring); if(num_updata==0) { Beep_Tip(100); } else if(num_updata!=0&&device_status.hmi_fresh==2) { rt_thread_delay(2000); UpLoad_Data(); } device_status.hmi_fresh = 0; } if(item_ext!=RT_NULL&&strstr(item_cmd->valuestring,"paramconf")!=RT_NULL) { collt = cJSON_GetObjectItem(item_ext,"coll_time"); //收集(数组格式) datt = cJSON_GetObjectItem(item_ext,"datt"); cul_time = cJSON_GetObjectItem(item_ext,"cul_time"); drop_sec = cJSON_GetObjectItem(item_ext,"drop_time"); set_temp = cJSON_GetObjectItem(item_ext,"set_temp"); cold_sw = cJSON_GetObjectItem(item_ext,"cold_sw"); wind_sw = cJSON_GetObjectItem(item_ext,"wind_sw"); on_off = cJSON_GetObjectItem(item_ext,"on_off"); //开关机 imgres = cJSON_GetObjectItem(item_ext,"imgres"); if(collt!=NULL) { int array_size = cJSON_GetArraySize(collt); int icnt = 0; for(icnt=0;icnt < array_size;icnt++) { cJSON *pSub = cJSON_GetArrayItem(collt, icnt); uint8_t itmp = 0; if(NULL==pSub) {continue;} char * ivalue = pSub->valuestring; if(icnt==0) { for(itmp = 0;itmp<10;itmp++) { if(strstr(&ivalue[itmp],"-")!=NULL&&itmp==1) { device_status.culture_sh1 = atoi(&ivalue[0]); device_status.culture_eh1 = atoi(&ivalue[3])<<8|atoi(&ivalue[2]); 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)); } else if (strstr(&ivalue[itmp],"-")!=NULL&&itmp==2) { device_status.culture_sh1 = atoi(&ivalue[1])<<8|atoi(&ivalue[0]); device_status.culture_eh1 = atoi(&ivalue[4])<<8|atoi(&ivalue[3]); 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)); } } rt_kprintf("开始结束时间1:%d-%d",device_status.culture_sh1,device_status.culture_eh1); } else if (icnt==1) { for(itmp = 0;itmp<10;itmp++) { if(strstr(&ivalue[itmp],"-")!=NULL&&itmp==1) { device_status.culture_sh2 = atoi(&ivalue[0]); device_status.culture_eh2 = atoi(&ivalue[3])<<8|atoi(&ivalue[2]); 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)); } else if (strstr(&ivalue[itmp],"-")!=NULL&&itmp==2) { device_status.culture_sh2 = (atoi(&ivalue[1])<<8)|atoi(&ivalue[0]); device_status.culture_eh2 = (atoi(&ivalue[4])<<8)|atoi(&ivalue[3]); 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)); } } rt_kprintf("开始结束时间2:%d-%d",device_status.culture_sh2,device_status.culture_eh2); } rt_kprintf("下发设置收集:%d-%s\n",icnt,ivalue); } } if(cul_time->valueint>=1&&cul_time->valueint<=24) { device_status.culture_time = cul_time->valueint; ef_set_env_blob("culture_time", &device_status.culture_time, sizeof(device_status.culture_time)); //培养时间 rt_kprintf("下发设置培养时间:%d\n",cul_time->valueint); } if(drop_sec->valueint>=1&&drop_sec->valueint<=30) { device_status.drop_sec = drop_sec->valueint; ef_set_env_blob("drop_sec", &device_status.drop_sec, sizeof(device_status.drop_sec)); //培养时间 rt_kprintf("下发设置滴液时间:%d\n",drop_sec->valueint); } if(set_temp->valueint>=1&&set_temp->valueint<=50) { device_status.set_tempture = set_temp->valueint; ef_set_env_blob("set_tempture", &device_status.set_tempture, sizeof(device_status.set_tempture)); //培养温度 rt_kprintf("下发设置培养温度:%d\n",set_temp->valueint); } if(cold_sw->valueint>=0&&cold_sw->valueint<=1) { device_status.cold_sw = cold_sw->valueint; ef_set_env_blob("cold_sw", &device_status.cold_sw, sizeof(device_status.cold_sw)); //制冷开关 rt_kprintf("下发设置制冷开关:%d\n",cold_sw->valueint); } if(wind_sw->valueint>=0&&wind_sw->valueint<=1) { device_status.wind_sw = wind_sw->valueint; ef_set_env_blob("wind_sw", &device_status.wind_sw, sizeof(device_status.wind_sw)); //风机开关 rt_kprintf("下发设置风机开关:%d\n",wind_sw->valueint); } if(on_off->valueint>=0&&on_off->valueint<=1) { device_status.ds = on_off->valueint; ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds)); //设备开关 rt_kprintf("下发设置设备开关:%d\n",on_off->valueint); } if(imgres->valueint>=0&&imgres->valueint<=10) { device_status.imgres = imgres->valueint; ef_set_env_blob("imgres", &device_status.imgres, sizeof(device_status.imgres)); //设备开关 rt_kprintf("下发设置分辨率:%d\n",imgres->valueint); } if(datt->valueint>=1&&datt->valueint<=60&&datt!=NULL) { device_status.dattim = datt->valueint; ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim)); //数据上传间隔 rt_kprintf("数据上传间隔datt:%d\n",datt->valueint); } MA_save(); rt_thread_delay(2000); UpLoad_Data(); } } //解析SIM卡接口返回信息 if(item_data!=NULL) { account_status = cJSON_GetObjectItem(item_data,"account_status"); data_plan = cJSON_GetObjectItem(item_data,"data_plan"); data_usage = cJSON_GetObjectItem(item_data,"data_usage"); expiry_date = cJSON_GetObjectItem(item_data,"expiry_date"); iccid = cJSON_GetObjectItem(item_data,"iccid"); device_status.account_status = account_status->valueint; device_status.data_plan = data_plan->valueint; char data_usage_f[6]; struct tm t; time_t expiry_date_time = expiry_date->valueint; t= *localtime(&expiry_date_time); rt_kprintf("expiry_date:%04d-%02d-%02d %02d:%02d:%02d\r\n",t.tm_year+1900,t.tm_mon+1,t.tm_mday,t.tm_hour+8,t.tm_min,t.tm_sec); rt_kprintf("account_status:%d\n",account_status->valueint); rt_kprintf("expiry_date:%d\n",expiry_date->valueint); rt_kprintf("data_plan:%d\n",data_plan->valueint); HMI_WRITE("sim.iccid.txt=\"%s\"",iccid->valuestring); HMI_WRITE("sim.account_status.txt=\"%d\"",device_status.account_status); HMI_WRITE("sim.data_plan.txt=\"%d\"",device_status.data_plan); sprintf(data_usage_f,"%.5f",data_usage->valuedouble); rt_kprintf("data_usage_f:%s\n",data_usage_f); HMI_WRITE("sim.data_usage.txt=\"%s\"",data_usage_f); HMI_WRITE("sim.expiry_date.txt=\"%04d-%02d-%02d %02d:%02d:%02d\"",t.tm_year+1900,t.tm_mon+1,t.tm_mday,t.tm_hour+8,t.tm_min,t.tm_sec); } cJSON_Delete(root); } return; } void UpLoad_Data(void) { char *updata = makeJson(); rt_kprintf("upload data:%d\n%s\n",rt_strlen(updata),updata); DTU_Write("%s",updata); rt_free(updata); list_mem(); //播放数据上传中语音 }