| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969 |
- /*
- * 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 <rtthread.h>
- #include "hmi.h"
- #include <board.h>
- #include <rtdevice.h>
- #include "stdarg.h"
- #include "string.h"
- #include "stdio.h"
- #include "dtu_uart2.h"
- #include <cJSON.h>
- #include "control.h"
- #include "sht30_collect.h"
- #include <easyflash.h>
- #include "sound.h"
- #include <ymodem.h>
- #include "beep.h"
- #define DBG_ENABLE
- #define DBG_COLOR
- #define DBG_TAG "dtu"
- #define DBG_LEVEL DBG_LOG
- #include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
- #define DTU_THREAD_PRIORITY 6 // 线程优先级
- #define DTU_THREAD_STACK_SIZE 2048 // 线程栈空间大小
- #define DTU_THREAD_TIMESLICE 5 // 时间片
- Device_Status_typedef device_status;
- DataTemp data_arry;
- void list_mem(void);
- /* 串口接收消息结构*/
- 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 uint8_t makejson_sta = 0;
- /**
- * @brief 初始化用于与上层dtu通信的串口 - 串口2
- *
- * @return int 成功返回RT_EOK
- */
- static 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; // 数据位8c
- dtuconfig.stop_bits = STOP_BITS_1; // 停止位1
- dtuconfig.bufsz = 1024; // 缓冲区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 RT_EOK;
- }
- /*数据发送*/
- /**
- * @brief 将组包完成后的json字符串发送到dtu
- *
- * @param fmt 字符串模型
- * @param ... 可变参数
- */
- void DTU_Write(char *fmt, ...)
- {
- const char dtu_conf[4] = {device_status.vol, 0x00, 0x00, 0x00};
- 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);
- if (strstr(dtu_str, "volume") != RT_NULL)
- {
- rt_device_write(dtuserial, 0, dtu_conf, 4);
- }
- else if (strstr(dtu_str, "reset") != RT_NULL)
- {
- const char dtu_conf[4] = {7, 0x00, 0x00, 0x00};
- rt_device_write(dtuserial, 0, dtu_conf, 4);
- }
- 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;
- }
- /* 入口函数-指令接收*/
- /**
- * @brief dtu数据的接收线程
- *
- * @param parameter NULL
- */
- 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];
- 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_err = 0;
- 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';
- LOG_D("recv data:%s", rx_buffer);
- if (strstr(rx_buffer, "{") == RT_NULL || strstr(rx_buffer, "}") == RT_NULL)
- {
- HMI_WRITE("sysTest.result.txt=\"%s\"", 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));
- }
- // rt_kprintf("%s",rx_buffer);
- }
- }
- 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);
- }
- }
- /*入口函数-指令发送*/
- /**
- * @brief dtu数据的发送线程
- *
- * @param parameter NULL
- */
- static void dtu_thread_entry_send(void *parameter)
- {
- device_status.power_status = 1;
- device_status.num_updata = 0;
- rt_thread_delay(10000);
- static rt_uint16_t wait_i = 0;
- static rt_uint8_t check_i = 0;
- static rt_uint8_t power_i = 0;
- uint8_t log_en_inr = 30; // 打印log的速度 数值越小 打印越频繁
- static int8_t log_en_cnt = -1;
- while (1)
- {
- if (atoi(device_status.net) == 0)
- {
- if (device_status.rain_status == 1 || device_status.temp_status == 1)
- {
- if (check_i == 0)
- {
- check_i = 1;
- device_status.num_updata = 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 (atoi(device_status.voltage) == 0 && device_status.power_status == 1)
- {
- power_i++;
- // 确定网络状态
- if (power_i == 10)
- {
- 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;
- }
- }
- else
- {
- power_i = 0;
- ctr_router(ON);
- ctr_RTU_DTU(ON);
- }
- }
- 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++;
- if (chk_log_time)
- {
- LOG_I("wait connect internet......%d", wait_i);
- }
- // 检测到电源掉电
- if (atoi(device_status.voltage) == 0 && device_status.power_status == 1 && wait_i > 200)
- {
- check_i++;
- LOG_W("断网状态下检测到设备断电!%d", atoi(device_status.voltage));
- if (check_i == 10)
- {
- device_status.power_status = 0;
- rt_thread_delay(5000);
- ctr_router(OFF);
- ctr_RTU_DTU(OFF);
- check_i = 0;
- }
- }
- if (Read_Real_Voltage() / 100 > 10 && device_status.power_status == 0)
- {
- check_i = 0;
- LOG_I("电源恢复正常,打开路由器和RTU供电!");
- device_status.power_status = 1;
- // 打开路由器和RTU供电
- ctr_router(ON);
- ctr_RTU_DTU(ON);
- }
- }
- rt_thread_mdelay(1000);
- }
- }
- /* 创建线程 */
- /**
- * @brief 用于创建dtu通信相关的线程
- *
- * 该线程在主线程中-读取完保存的设备参数之后调用
- *
- * @return int 完成后返回RT_EOK
- */
- 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,
- 3, // 优先级高是为了保证数据上传的频率的精确度
- 20 // 时间片
- );
- /* 创建线程-指令接收解析*/
- 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 RT_EOK;
- }
- /**
- * @brief 组包读取设备信息的json
- *
- * @return char* 组包完成后的字符串指针
- */
- char *makeJson_ReadInfo()
- {
- cJSON *rJsonRoot = NULL;
- rJsonRoot = cJSON_CreateObject();
- if (NULL == rJsonRoot)
- {
- return NULL;
- }
- cJSON_AddStringToObject(rJsonRoot, "uart", "getinfo");
- char *r = cJSON_PrintUnformatted(rJsonRoot);
- if (NULL == r)
- {
- cJSON_Delete(rJsonRoot);
- return NULL;
- }
- cJSON_Delete(rJsonRoot);
- return r;
- }
- //{"cmd": "platform", "ext": {"type": "120.27.222.26"}}
- /**
- * @brief 组包平台参数的json
- *
- * @param plt 平台参数的内容
- * @return char* 组包完成后的字符串指针
- */
- char *makeJson_platform(char *plt)
- {
- cJSON *platform = NULL;
- platform = cJSON_CreateObject();
- if (NULL == platform)
- {
- return NULL;
- }
- cJSON_AddStringToObject(platform, "cmd", "platform");
- cJSON *extstr = NULL;
- extstr = cJSON_CreateObject();
- if (NULL == extstr)
- {
- return NULL;
- }
- cJSON_AddItemToObject(platform, "ext", extstr);
- cJSON_AddStringToObject(extstr, "type", plt);
- char *p_str = cJSON_PrintUnformatted(platform);
- if (NULL == p_str)
- {
- cJSON_Delete(platform);
- return NULL;
- }
- cJSON_Delete(platform);
- return p_str;
- }
- /**
- * @brief 组包拍照指令的json
- *
- * @return char* 完成后的指针
- */
- char *makeJson_takephoto()
- {
- cJSON *takephoto = NULL;
- takephoto = cJSON_CreateObject();
- if (NULL == takephoto)
- {
- return NULL;
- }
- cJSON_AddStringToObject(takephoto, "cmd", "takephoto");
- char *takephoto_str = cJSON_PrintUnformatted(takephoto);
- if (NULL == takephoto_str)
- {
- cJSON_Delete(takephoto);
- return NULL;
- }
- cJSON_Delete(takephoto);
- return takephoto_str;
- }
- /**
- * @brief 组包RTU拍照的json
- *
- * @return char* 完成后的指针
- */
- char *makeJson_Rtutakephoto()
- {
- cJSON *tJsonRoot = NULL;
- tJsonRoot = cJSON_CreateObject();
- if (NULL == tJsonRoot)
- {
- return NULL;
- }
- cJSON_AddStringToObject(tJsonRoot, "cmd", "ctrl");
- cJSON *tpubstring = NULL;
- tpubstring = cJSON_CreateObject();
- if (NULL == tpubstring)
- {
- LOG_E("cJSON tpubstring NULL!!!\n");
- return NULL;
- }
- cJSON_AddItemToObject(tJsonRoot, "ext", tpubstring);
- cJSON_AddStringToObject(tpubstring, "takephoto", "2");
- char *t = cJSON_PrintUnformatted(tJsonRoot);
- if (NULL == t)
- {
- cJSON_Delete(tJsonRoot);
- return NULL;
- }
- cJSON_Delete(tJsonRoot);
- return t;
- }
- // 预警消息
- /**
- * @brief 组包预警信息的json
- *
- * @param s status
- * @param t type
- * @return char* 完成后的指针
- */
- 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数据*/
- /**
- * @brief 组包设备状态信息的json
- *
- * @return char* 完成后的指针
- */
- 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
- {
- device_status.lamp_status = 0;
- }
- if (atoi(device_status.power) > 5000)
- rt_sprintf(device_status.power, "0.01");
- makejson_sta = 1;
- 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);
- cJSON *pJsonRoot = NULL;
- pJsonRoot = cJSON_CreateObject();
- if (NULL == pJsonRoot)
- {
- rt_kprintf("cJSON pJsonRoot NULL!!!\n");
- return NULL;
- }
- if (strstr(device_status.project, "A7_DTU_V3") != RT_NULL)
- {
- cJSON_AddStringToObject(pJsonRoot, "cmd", "read_data");
- }
- else
- {
- cJSON_AddStringToObject(pJsonRoot, "cmd", "data");
- }
- cJSON *pSubJson = NULL;
- pSubJson = cJSON_CreateObject();
- if (NULL == pSubJson)
- {
- rt_kprintf("cJSON pSubJson NULL!!!\n");
- return NULL;
- }
- memset(device_status.driver, 0, sizeof(device_status.driver));
- if (device_status.version_type == 1)
- {
- rt_sprintf(device_status.driver, "%s-%s", VERSION_ZP, device_status.driver_4g);
- }
- else if (device_status.version_type == 4)
- {
- rt_sprintf(device_status.driver, "%s-%s", VERSION_HK_2000W, device_status.driver_4g);
- }
- else if (device_status.version_type == 41)
- {
- rt_sprintf(device_status.driver, "%s-%s", VERSION_HK, device_status.driver_4g);
- }
- else if (device_status.version_type == 11)
- {
- rt_sprintf(device_status.driver, "%s-%s", VERSION_GK, device_status.driver_4g);
- }
- else if (device_status.version_type == 5)
- {
- rt_sprintf(device_status.driver, "%s-%s", VERSION_V5, device_status.driver_4g);
- }
- else if (device_status.version_type == 6)
- {
- rt_sprintf(device_status.driver, "%s-%s", VERSION_XCT, device_status.driver_4g);
- }
- else if (device_status.version_type == vt_BZY || device_status.version_type == vt_BZY_JD)
- {
- rt_sprintf(device_status.driver, "%s-%s", VERSION_BZY, device_status.driver_4g);
- }
- if (device_status.sensor_485_sta != 0)
- {
- if (strstr(device_status.driver, "485") == RT_NULL)
- strcat(device_status.driver, ".485");
- }
- cJSON_AddItemToObject(pJsonRoot, "ext", pSubJson);
- cJSON_AddStringToObject(pSubJson, "dver", device_status.driver); // 版本号,字符型
- cJSON_AddStringToObject(pSubJson, "proj", device_status.project); // 项目类型
- // 设备类型
- rt_sprintf(utos, "%d", device_status.dtype);
- cJSON_AddStringToObject(pSubJson, "dtype", utos);
- // 类型细分
- if (device_status.version_type == 4) // 水稻
- {
- rt_sprintf(utos, "4");
- cJSON_AddStringToObject(pSubJson, "vtype", utos);
- }
- else if (device_status.version_type == 1)
- { // 1.0
- rt_sprintf(utos, "1");
- cJSON_AddStringToObject(pSubJson, "vtype", utos);
- }
- else if (device_status.version_type == 11)
- { // 高空
- rt_sprintf(utos, "11");
- cJSON_AddStringToObject(pSubJson, "vtype", utos);
- }
- else if (device_status.version_type == 5)
- { // 5.0
- rt_sprintf(utos, "5");
- cJSON_AddStringToObject(pSubJson, "vtype", utos);
- }
- else if (device_status.version_type == 6)
- { // 吸虫塔
- rt_sprintf(utos, "6");
- cJSON_AddStringToObject(pSubJson, "vtype", utos);
- }
- else if (device_status.version_type == 6)
- { // 孢子仪
- rt_sprintf(utos, "A");
- cJSON_AddStringToObject(pSubJson, "vtype", utos);
- }
- if (device_status.version_type != 6 && device_status.dtype != 7)
- {
- // 光控定时
- rt_sprintf(utos, "%d", device_status.sunBar);
- cJSON_AddStringToObject(pSubJson, "tt", utos);
- // 定时模式
- rt_sprintf(utos, "%d", device_status.timeSwitch);
- cJSON_AddStringToObject(pSubJson, "ts", utos);
- // 温控
- rt_sprintf(utos, "%d", device_status.temp_status);
- cJSON_AddStringToObject(pSubJson, "tps", utos);
- // 光控状态
- rt_sprintf(utos, "%d", device_status.sun_status);
- cJSON_AddStringToObject(pSubJson, "lps", utos);
- // 雨控状态
- rt_sprintf(utos, "%d", device_status.rain_status);
- cJSON_AddStringToObject(pSubJson, "rps", utos);
- // 电池状态
- rt_sprintf(utos, "%d", device_status.bat_status);
- cJSON_AddStringToObject(pSubJson, "batStatus", utos);
- // 灯管状态
- rt_sprintf(utos, "%d", device_status.lamp_status);
- cJSON_AddStringToObject(pSubJson, "lamp", utos);
- // 上仓门状态 1-打开,0-关闭-(通道) 打开为落虫,关闭为排水
- rt_sprintf(utos, "%d", device_status.up_status);
- cJSON_AddStringToObject(pSubJson, "upds", utos);
- // 下仓门状态 1-打开,0-关闭
- rt_sprintf(utos, "%d", device_status.down_status);
- cJSON_AddStringToObject(pSubJson, "dnds", utos);
- // 加热仓温度
- if (device_status.run_sta > device_status.heattem)
- {
- rt_sprintf(utos, "%d", device_status.run_sta);
- device_status.run_sta = 0;
- }
- else
- {
- rt_sprintf(utos, "%d", device_status.heattem);
- }
- cJSON_AddStringToObject(pSubJson, "hrt", utos);
- // 加热状态
- rt_sprintf(utos, "%d", device_status.heat_status);
- cJSON_AddStringToObject(pSubJson, "hs", utos);
- // 收集时间(参数)
- rt_sprintf(utos, "%d", device_status.clt_time);
- cJSON_AddStringToObject(pSubJson, "collt", utos);
- // 加热时间(参数)
- rt_sprintf(utos, "%d", device_status.heattime);
- cJSON_AddStringToObject(pSubJson, "htim", utos);
- // 加热温度(参数)
- rt_sprintf(utos, "%d", device_status.heatvalue);
- cJSON_AddStringToObject(pSubJson, "hst", utos);
- // 高温保护
- rt_sprintf(utos, "%d", device_status.tph);
- cJSON_AddStringToObject(pSubJson, "tph", utos);
- // 低温保护
- rt_sprintf(utos, "%d", device_status.tpl);
- cJSON_AddStringToObject(pSubJson, "tpl", utos);
- }
- if (device_status.dtype == 3)
- {
- // 工作状态
- rt_sprintf(utos, "%d", device_status.work_status);
- cJSON_AddStringToObject(pSubJson, "ws", utos);
- // 保险丝电压
- cJSON_AddStringToObject(pSubJson, "fuse_voltage", device_status.fuse_voltage);
- // 开始时间
- rt_sprintf(utos, "%d", device_status.startBar);
- cJSON_AddStringToObject(pSubJson, "st", utos);
- // 结束时间
- rt_sprintf(utos, "%d", device_status.stopBar);
- cJSON_AddStringToObject(pSubJson, "et", utos);
- }
- else if (device_status.dtype == 7)
- {
- char ct1[10], ct2[10];
- rt_sprintf(ct1, "%d-%d", device_status.collecting_sh1, device_status.collecting_eh1);
- rt_sprintf(ct2, "%d-%d", device_status.collecting_sh2, device_status.collecting_eh2);
- rt_kprintf("ct1-ct2:%s\n", ct1);
- device_status.coll_time[0] = ct1;
- device_status.coll_time[1] = ct2;
- cJSON *data_clt = NULL;
- data_clt = cJSON_CreateStringArray(device_status.coll_time, 2);
- // 工作状态
- rt_sprintf(utos, "%d", device_status.work_status);
- cJSON_AddStringToObject(pSubJson, "work_sta", utos);
- // 运行状态
- rt_sprintf(utos, "%d", device_status.run_sta);
- cJSON_AddStringToObject(pSubJson, "run_sta", utos);
- // 箱体温度-box_tem
- rt_sprintf(utos, "%d", device_status.box_temp);
- cJSON_AddStringToObject(pSubJson, "box_tem", utos);
- // 培养时间-cul_time
- rt_sprintf(utos, "%d", device_status.cul_time);
- cJSON_AddStringToObject(pSubJson, "cul_time", utos);
- // 制冷状态
- rt_sprintf(utos, "%d", device_status.cold_sw);
- cJSON_AddStringToObject(pSubJson, "cold_sw", utos);
- // 电压状态-batStatus
- rt_sprintf(utos, "%d", device_status.bat_status);
- cJSON_AddStringToObject(pSubJson, "batStatus", utos);
- // 已培养时间-staytime
- rt_sprintf(utos, "%d", device_status.stay_time);
- cJSON_AddStringToObject(pSubJson, "stay_time", utos);
- // 风机开关
- rt_sprintf(utos, "%d", device_status.wind_sw);
- cJSON_AddStringToObject(pSubJson, "wind_sw", utos);
- // 培养仓温度
- rt_sprintf(utos, "%d", device_status.pre_temp);
- cJSON_AddStringToObject(pSubJson, "pre_temp", utos);
- // 分辨率
- cJSON_AddStringToObject(pSubJson, "imgres", "0");
- // usb
- cJSON_AddStringToObject(pSubJson, "usb_sta", "0");
- // 雨控状态-rps
- rt_sprintf(utos, "%d", device_status.rain_status);
- cJSON_AddStringToObject(pSubJson, "rps", utos);
- // 收集时间
- cJSON_AddItemToObject(pSubJson, "coll_time", data_clt);
- // 设定温度
- rt_sprintf(utos, "%d", device_status.heatvalue);
- cJSON_AddStringToObject(pSubJson, "set_temp", utos);
- }
- if (device_status.dtype != 7)
- {
- // 震动开关
- rt_sprintf(utos, "%d", device_status.shake_ws);
- cJSON_AddStringToObject(pSubJson, "shake", utos);
- }
- // 震动时间
- rt_sprintf(utos, "%d", device_status.shake_sec);
- cJSON_AddStringToObject(pSubJson, "shake_sec", utos);
- cJSON_AddStringToObject(pSubJson, "gps", device_status.gps); // 定位状态
- // 开关状态
- rt_sprintf(utos, "%d", device_status.ds);
- cJSON_AddStringToObject(pSubJson, "ds", utos);
- // 湿度
- cJSON_AddStringToObject(pSubJson, "ah", device_status.humidity);
- // 温度
- cJSON_AddStringToObject(pSubJson, "at", device_status.tempture);
- cJSON_AddStringToObject(pSubJson, "imei", device_status.imei); // IMEI
- cJSON_AddStringToObject(pSubJson, "iccid", device_status.iccid); // ICCID
- cJSON_AddStringToObject(pSubJson, "stamp", device_status.stamp); // 时间
- // 经度
- cJSON_AddStringToObject(pSubJson, "lng", device_status.lng);
- // 纬度
- cJSON_AddStringToObject(pSubJson, "lat", device_status.lat);
- // 是否为上电开机
- cJSON_AddNumberToObject(pSubJson, "rcnt", device_status.rebootcnt);
- // 电流(当前)
- cJSON_AddStringToObject(pSubJson, "current", device_status.power);
- // 电压
- cJSON_AddStringToObject(pSubJson, "vbat", device_status.voltage);
- // 数据上传间隔
- rt_sprintf(utos, "%d", device_status.dattim);
- cJSON_AddStringToObject(pSubJson, "dat_f", utos);
- // 信号强度
- cJSON_AddStringToObject(pSubJson, "csq", device_status.csq);
- 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数据解析
- /**
- * @brief 解析dtu发来的指令
- *
- * @param json_string 收到的json字符串
- * @return int 0 完成
- */
- int parseDtu(char *json_string)
- {
- extern int rt_hw_rtc_init(void);
- char *json_s = NULL;
- cJSON *item_cmd = NULL; // 嵌套ext
- cJSON *item_ext = NULL; // 嵌套ext
- cJSON *hst = NULL; // 加热温度
- cJSON *collt = NULL; // 收集时间
- cJSON *et = NULL; // 结束时间
- cJSON *datt = NULL; // 数据上传间隔
- cJSON *shake_sec = NULL; // 震动时间
- cJSON *tpl = NULL; // 低温保护阈值
- cJSON *shake = NULL; // 震动开关
- cJSON *tph = NULL; // 高温保护阈值
- cJSON *ts = NULL; // 工作模式
- cJSON *st = NULL; // 开始时间
- cJSON *tt = NULL; // 光控定时时长
- cJSON *htim = 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 *volume = NULL;
- cJSON *driver_4g = NULL; // 版本号
- 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 *value_commn = NULL;
- rt_kprintf("%s\n", json_string);
- cJSON *root = cJSON_Parse(json_string);
- if (!root)
- {
- cJSON_Delete(root);
- rt_kprintf("parse json err:%s", json_string);
- return -1;
- }
- 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, "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);
- }
- else if (strstr(item_cmd->valuestring, "json_w_clock") != RT_NULL)
- {
- rt_kprintf("查询时间配置!\n");
- json_s = makeJson_Warn(device_status.json_w_clock, "主动查询");
- DTU_Write("%s", json_s);
- rt_free(json_s);
- rt_thread_delay(1000);
- }
- else if (strstr(item_cmd->valuestring, "json_w_reset") != RT_NULL)
- {
- rt_kprintf("查询重置配置!\n");
- json_s = makeJson_Warn(device_status.json_w_reset, "主动查询");
- DTU_Write("%s", json_s);
- rt_free(json_s);
- rt_thread_delay(1000);
- }
- else if (strstr(item_cmd->valuestring, "json_w_platform") != RT_NULL)
- {
- rt_kprintf("查询平台配置!\n");
- json_s = makeJson_Warn(device_status.json_w_platform, "主动查询");
- DTU_Write("%s", json_s);
- rt_free(json_s);
- rt_thread_delay(1000);
- }
- else if (strstr(item_cmd->valuestring, "shake") != RT_NULL)
- {
- ctr_shake(ON, 30);
- char *shake = makeJson_Warn("shake", "control");
- DTU_Write("%s", shake);
- rt_free(shake);
- rt_thread_delay(2000);
- }
- // 远程给rtu重新上电
- else if (strstr(item_cmd->valuestring, "ctrl") != RT_NULL)
- {
- type = cJSON_GetObjectItem(item_ext, "type");
- if (strstr(type->valuestring, "rtu_off_on") != RT_NULL)
- {
- LOG_W("DTU 12V Power down");
- ctr_RTU_DTU(OFF);
- rt_thread_delay(5000);
- ctr_RTU_DTU(ON);
- }
- // 对焦拍照
- else if (strstr(type->valuestring, "auto_takephoto") != RT_NULL)
- {
- device_status.autotakepic = 1;
- rt_thread_delay(2000);
- char *auto_takephoto = makeJson_Warn("send cmd success:auto_takephoto", "control");
- DTU_Write("%s", auto_takephoto);
- rt_free(auto_takephoto);
- }
- else if (strstr(type->valuestring, "takephoto") != RT_NULL)
- {
- HK_TakePhoto();
- char *photo = makeJson_Warn("takephoto", "control");
- DTU_Write("%s", photo);
- rt_free(photo);
- rt_thread_delay(2000);
- }
- //{"ext": {"type": "turn"}, "cmd": "ctrl"} 转仓
- else if (strstr(type->valuestring, "turn") != RT_NULL)
- {
- #if Color_EN == 0
- char *turn_zp = makeJson_Warn("send cmd success:turn_zp", "control");
- DTU_Write("%s", turn_zp);
- rt_free(turn_zp);
- ctr_turn(90, 0);
- #else
- DTU_Write("黄板复位:%d", ctr_Color_board(RESET, 800));
- #endif
- }
- }
- // 切换平台
- else if (strstr(item_cmd->valuestring, "platform") != RT_NULL)
- {
- type = cJSON_GetObjectItem(item_ext, "type");
- if (strstr(type->valuestring, "8.136.98.49") != RT_NULL)
- {
- rt_sprintf(device_status.mqttcfg1, "8.136.98.49");
- ef_set_env_blob("platform", &device_status.mqttcfg1, sizeof(device_status.mqttcfg1));
- // 给RTU发送切换指令
- DTU_Write("%s", makeJson_platform("8.136.98.49"));
- rt_free(makeJson_platform("8.136.98.49"));
- rt_thread_delay(1000);
- rt_sprintf(device_status.json_w_platform, "平台操作:切换平台>大数据,操作时间:%s", device_status.stamp);
- json_s = makeJson_Warn(device_status.json_w_platform, "切换平台");
- ef_set_env_blob("json_w_platform", &device_status.json_w_platform, sizeof(device_status.json_w_platform)); // 将修改屏幕参数操作记录保存到Flash中
- if (atoi(device_status.net) == 0)
- DTU_Write("%s", json_s);
- rt_free(json_s);
- rt_thread_delay(1000);
- MA_save();
- }
- else if (strstr(type->valuestring, "120.27.222.26") != RT_NULL)
- {
- rt_sprintf(device_status.mqttcfg1, "120.27.222.26");
- ef_set_env_blob("platform", &device_status.mqttcfg1, sizeof(device_status.mqttcfg1));
- // 给RTU发送切换指令
- DTU_Write("%s", makeJson_platform("120.27.222.26"));
- rt_free(makeJson_platform("120.27.222.26"));
- rt_thread_delay(1000);
- rt_sprintf(device_status.json_w_platform, "平台操作:切换平台>四情,操作时间:%s", device_status.stamp);
- json_s = makeJson_Warn(device_status.json_w_platform, "切换平台");
- ef_set_env_blob("json_w_platform", &device_status.json_w_platform, sizeof(device_status.json_w_platform)); // 将修改屏幕参数操作记录保存到Flash中
- if (atoi(device_status.net) == 0)
- DTU_Write("%s", json_s);
- rt_free(json_s);
- rt_thread_delay(1000);
- MA_save();
- }
- }
- // 水稻2000万像素的串口拍照指令
- else if (strstr(item_cmd->valuestring, "mvs_photo") != RT_NULL)
- {
- HK_TakePhoto();
- char *photo = makeJson_Warn("mvs_takephoto", "control");
- DTU_Write("%s", photo);
- rt_free(photo);
- rt_thread_delay(2000);
- }
- 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, "reset") != RT_NULL)
- {
- ResetParamDefault();
- char *restart = makeJson_Warn("sysrem will reset", "control");
- DTU_Write("%s", restart);
- rt_free(restart);
- rt_thread_delay(2000);
- }
- 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, "poweron") != RT_NULL)
- {
- device_status.ds = 1;
- ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds)); //
- UpLoad_Data();
- }
- else if (strstr(item_cmd->valuestring, "poweroff") != RT_NULL)
- {
- device_status.ds = 0;
- ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds)); //
- UpLoad_Data();
- }
- // else if (strstr(item_cmd->valuestring,"log")!=RT_NULL) {
- // rt_thread_mdelay(2000);
- // //read_all_flash_log();
- // }
- // 设置温湿度
- else if (strstr(item_cmd->valuestring, "sensor") != RT_NULL)
- {
- // 2022-04-12add:485传感器正常,不再解析服务器下发的温湿度数据
- // if(device_status.sensor_485_sta!=0) return 0;
- hum = cJSON_GetObjectItem(item_ext, "new_hum");
- tmp = cJSON_GetObjectItem(item_ext, "new_tem");
- if (hum != NULL && tmp != NULL)
- {
- // 先判断是否是空字符再判断数值是否合理
- if (strcmp(hum->valuestring, "") != 0 && atoi(hum->valuestring) >= 0 && atoi(hum->valuestring) <= 100 && atoi(hum->valuestring) != 30 && device_status.sensor_485_sta == 0)
- {
- if (atoi(hum->valuestring) != atoi(device_status.humidity))
- {
- rt_sprintf(device_status.humidity, "%s", hum->valuestring);
- ef_set_env_blob("env_h", &device_status.humidity, sizeof(device_status.humidity)); // 湿度
- rt_kprintf("保存湿度成功:%d\n", atoi(device_status.humidity));
- }
- rt_kprintf("设置湿度成功:%d\n", atoi(device_status.humidity));
- }
- else
- {
- rt_kprintf("设置湿度失败:%s!!!\n", hum->valuestring);
- }
- // 先判断是否是空字符再判断数值是否合理
- if (strcmp(tmp->valuestring, "") != 0 && atoi(tmp->valuestring) > -50 && atoi(tmp->valuestring) <= 100 && device_status.sensor_485_sta == 0)
- {
- if (atoi(tmp->valuestring) != atoi(device_status.tempture))
- {
- rt_sprintf(device_status.tempture, "%s", tmp->valuestring);
- ef_set_env_blob("env_t", &device_status.tempture, sizeof(device_status.tempture)); // 湿度
- rt_kprintf("保存温度成功:%d\n", atoi(device_status.tempture));
- }
- rt_kprintf("设置温度成功:%d\n", atoi(device_status.tempture));
- }
- else
- {
- rt_kprintf("设置温度失败:%s!!!\n", tmp->valuestring);
- }
- }
- }
- else if (strstr(item_cmd->valuestring, "color") != RT_NULL)
- {
- if (item_ext != RT_NULL && strstr(item_ext->valuestring, "turn") != RT_NULL)
- {
- device_status.run_sta = 5;
- }
- else
- {
- LOG_W("Unknow cmd value!");
- }
- }
- else if (strstr(item_cmd->valuestring, "synchronization") != RT_NULL)
- {
- #if Color_EN == 0
- if (device_status.dtype == 7)
- {
- DTU_Write("%s", "SwversionV7");
- }
- else if (device_status.dtype == 3)
- {
- DTU_Write("%s", "SwversionV4");
- }
- #endif
- device_status.refresh_timeout = 0;
- // 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");
- sim = cJSON_GetObjectItem(item_ext, "sim");
- iccid = cJSON_GetObjectItem(item_ext, "iccid");
- imei = cJSON_GetObjectItem(item_ext, "imei");
- gps = cJSON_GetObjectItem(item_ext, "gps");
- volume = cJSON_GetObjectItem(item_ext, "volume");
- mqttcfg1 = cJSON_GetObjectItem(item_ext, "mqttcfg1");
- mqttcfg2 = cJSON_GetObjectItem(item_ext, "mqttcfg2");
- link_sta = cJSON_GetObjectItem(item_ext, "link_sta");
- cJSON *gps_inuse = cJSON_GetObjectItem(item_ext, "gps_inuse");
- cJSON *gps_view = cJSON_GetObjectItem(item_ext, "gps_view");
- // 如果DTU的IMEI和FLash中的不一样,保存到FLASH
- value_commn = cJSON_GetObjectItem(item_ext, "photo_sta");
- if (value_commn != RT_NULL)
- {
- HMI_WRITE("menu.eth1_sta.val=%d", atoi(value_commn->valuestring));
- }
- value_commn = cJSON_GetObjectItem(item_ext, "cpu_tmp");
- if (value_commn != RT_NULL)
- {
- HMI_WRITE("menu.cpu_temp.txt=\"%d.%d℃\"", atoi(value_commn->valuestring) / 1000, atoi(value_commn->valuestring) % 1000);
- }
- if (strstr(device_status.imei, imei->valuestring) == RT_NULL)
- {
- rt_kprintf("Change IMEI:new:%s-old:%s", imei->valuestring, device_status.imei);
- rt_sprintf(device_status.imei, "%s", imei->valuestring);
- ef_set_env_blob("imei", &device_status.imei, sizeof(device_status.imei)); // IMEI
- }
- else
- {
- rt_sprintf(device_status.imei, "%s", imei->valuestring);
- rt_kprintf("IMEI not change:%s-%s", imei->valuestring, device_status.imei);
- }
- // 如果DTU的ICCID和FLash中的不一样,保存到FLASH
- if (strstr(device_status.iccid, iccid->valuestring) == RT_NULL)
- {
- rt_kprintf("Change ICCID:new:%s-old:%s", iccid->valuestring, device_status.iccid);
- rt_sprintf(device_status.iccid, "%s", iccid->valuestring);
- ef_set_env_blob("iccid", &device_status.iccid, sizeof(device_status.iccid)); // Iccid
- }
- else
- {
- rt_sprintf(device_status.iccid, "%s", iccid->valuestring);
- rt_kprintf("ICCID not change:%s-%s", iccid->valuestring, device_status.iccid);
- }
- LOG_I("DTU时间:%s", datetime->valuestring);
- static 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) >= 2022 && atoi(year_s) < 3000 && atoi(month_s) > 0 && atoi(month_s) < 13 && atoi(day_s) > 0 && atoi(day_s) < 32)
- {
- if (atoi(net->valuestring) == 0 && atoi(year_s) >= 2022)
- {
- if (set_date(atoi(year_s), atoi(month_s), atoi(day_s)) == RT_EOK)
- {
- LOG_I("设置日期:%d年%d月%d日", 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)
- {
- LOG_I("设置时间:%d时%d分%d秒", atoi(hour_s), atoi(min_s), atoi(sec_s));
- set_time(atoi(hour_s), atoi(min_s), atoi(sec_s));
- }
- }
- else
- {
- LOG_E("set_date failed!");
- rt_hw_rtc_init();
- }
- }
- else
- {
- LOG_E("网络连接失败,同步时间失败!");
- }
- }
- LOG_I("参数同步:lat:%s lng:%s", lat->valuestring, lng->valuestring);
- // CSQ
- if (csq != NULL && atoi(csq->valuestring) >= 0 && atoi(csq->valuestring) <= 31)
- {
- rt_sprintf(device_status.csq, "%s", csq->valuestring);
- }
- else
- {
- rt_sprintf(device_status.csq, "0");
- }
- // 更新网线接入状态
- if (link_sta != NULL && atoi(link_sta->valuestring) >= 0 && atoi(link_sta->valuestring) <= 1)
- {
- device_status.link_sta = atoi(link_sta->valuestring);
- LOG_I(">>>>>>>>>>>>>有线接入状态>>>>>>>>>>>>>>:%d", device_status.link_sta);
- }
- // Volume
- if (volume != NULL && atoi(volume->valuestring) >= 0 && atoi(volume->valuestring) <= 31)
- {
- device_status.vol = atoi(volume->valuestring);
- LOG_I("设置音量:%d", device_status.vol);
- }
- else
- {
- device_status.vol = 7;
- }
- // NET
- if (net != NULL && atoi(net->valuestring) >= 0 && atoi(net->valuestring) <= 1)
- {
- LOG_I("网络状态:%s", net->valuestring);
- rt_sprintf(device_status.net, "%s", net->valuestring);
- }
- else
- {
- rt_sprintf(device_status.net, "1");
- }
- // SIM
- if (sim != NULL && atoi(sim->valuestring) >= 0 && atoi(sim->valuestring) <= 1)
- {
- rt_sprintf(device_status.sim, "%s", sim->valuestring);
- }
- else
- {
- rt_sprintf(device_status.sim, "1");
- }
- // GPS
- if (gps != NULL && atoi(gps->valuestring) >= 0 && atoi(gps->valuestring) <= 3)
- {
- 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");
- if (gps_inuse != NULL)
- {
- device_status.gps_inuse = atoi(gps_inuse->valuestring);
- }
- 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));
- memset(device_status.lng, 0, sizeof(device_status.lng));
- rt_sprintf(device_status.lat, "%s", lat->valuestring);
- rt_sprintf(device_status.lng, "%s", lng->valuestring);
- ef_set_env_blob("lat", &device_status.lat, sizeof(device_status.lat)); // Iccid
- ef_set_env_blob("lng", &device_status.lng, sizeof(device_status.lng)); // Iccid
- }
- else
- {
- LOG_I("经纬度信息同步:lat-%s,lng-%s", lat->valuestring, lng->valuestring);
- }
- }
- else if (atoi(gps->valuestring) == 0)
- {
- memset(device_status.lat, 0, sizeof(device_status.lat));
- memset(device_status.lng, 0, sizeof(device_status.lng));
- rt_sprintf(device_status.lat, "%s", lat->valuestring);
- rt_sprintf(device_status.lng, "%s", lng->valuestring);
- }
- }
- else
- {
- rt_sprintf(device_status.gps, "0");
- memset(device_status.lat, 0, sizeof(device_status.lat));
- memset(device_status.lng, 0, sizeof(device_status.lng));
- if (sizeof(device_status.lat) < 3)
- {
- sprintf(device_status.lat, "%s", "0");
- sprintf(device_status.lng, "%s", "0");
- }
- else
- {
- sprintf(device_status.lat, "%s", lat->valuestring);
- sprintf(device_status.lng, "%s", lng->valuestring);
- }
- }
- if (driver_4g != RT_NULL)
- sprintf(device_status.driver_4g, "%s", driver_4g->valuestring);
- if (project != RT_NULL)
- sprintf(device_status.project, "%s", project->valuestring);
- if (mqttcfg1 != NULL)
- {
- if (strstr("8.136.98.49", mqttcfg1->valuestring) != RT_NULL)
- {
- rt_sprintf(device_status.mqttcfg1, "8.136.98.49");
- }
- else if (strstr("120.27.222.26", mqttcfg1->valuestring) != RT_NULL)
- {
- rt_sprintf(device_status.mqttcfg1, "120.27.222.26");
- }
- else
- {
- rt_sprintf(device_status.mqttcfg1, "8.136.98.49");
- }
- LOG_I("当前平台1:%s", mqttcfg1->valuestring);
- }
- if (mqttcfg2 != NULL)
- {
- sprintf(device_status.mqttcfg2, "%s", mqttcfg2->valuestring);
- LOG_I("当前平台2:%s", mqttcfg2->valuestring);
- }
- if (device_status.num_updata == 0)
- {
- Beep_Tip(100);
- }
- else if (device_status.num_updata != 0 && device_status.hmi_fresh == 2)
- {
- if (strstr(device_status.project, "A7_DTU_V3") != RT_NULL)
- {
- UpLoad_Data();
- }
- else
- {
- rt_thread_delay(2000);
- UpLoad_Data();
- }
- }
- device_status.hmi_fresh = 0;
- }
- if (item_ext != RT_NULL && strstr(item_cmd->valuestring, "paramconf") != RT_NULL)
- {
- if (device_status.dtype == 3)
- hst = cJSON_GetObjectItem(item_ext, "hst");
- if (device_status.dtype == 7)
- hst = cJSON_GetObjectItem(item_ext, "set_temp");
- et = cJSON_GetObjectItem(item_ext, "et");
- datt = cJSON_GetObjectItem(item_ext, "datt");
- shake_sec = cJSON_GetObjectItem(item_ext, "shake_sec");
- tpl = cJSON_GetObjectItem(item_ext, "tpl");
- shake = cJSON_GetObjectItem(item_ext, "shake");
- tph = cJSON_GetObjectItem(item_ext, "tph");
- ts = cJSON_GetObjectItem(item_ext, "ts");
- st = cJSON_GetObjectItem(item_ext, "st");
- tt = cJSON_GetObjectItem(item_ext, "tt");
- htim = cJSON_GetObjectItem(item_ext, "htim");
- if (device_status.dtype == 3)
- ds = cJSON_GetObjectItem(item_ext, "ds");
- vt = cJSON_GetObjectItem(item_ext, "vt");
- if (device_status.dtype == 3)
- collt = cJSON_GetObjectItem(item_ext, "collt");
- if (device_status.dtype == 7)
- ds = cJSON_GetObjectItem(item_ext, "on_off");
- if (device_status.dtype == 7)
- collt = cJSON_GetObjectItem(item_ext, "coll_time"); // 收集(数组格式)
- cJSON *cul_time = cJSON_GetObjectItem(item_ext, "cul_time"); // 培养时间1~24
- cJSON *drop_sec = cJSON_GetObjectItem(item_ext, "drop_time");
- if (drop_sec != NULL)
- {
- if (drop_sec->valueint >= 1 && drop_sec->valueint <= 300)
- {
- device_status.shake_sec = drop_sec->valueint;
- ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); // 培养时间
- LOG_I("下发设置滴液时间:%d", drop_sec->valueint);
- }
- }
- if (cul_time != NULL)
- {
- if (cul_time->valueint >= 1 && cul_time->valueint <= 24)
- {
- device_status.cul_time = cul_time->valueint;
- ef_set_env_blob("cul_time", &device_status.cul_time, sizeof(device_status.cul_time)); // 培养时间
- LOG_I("下发设置培养时间:%d", cul_time->valueint);
- }
- }
- /*加热温度*/
- if (hst != NULL)
- {
- if (hst->type == cJSON_Number)
- {
- if (hst->valueint >= 10 && hst->valueint <= 150)
- {
- device_status.heatvalue = hst->valueint;
- ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue)); // 开始时间
- LOG_I("加热温度hst:%d", hst->valueint);
- }
- else
- {
- LOG_E("加热温度hst设置失败参数错误!!!");
- }
- }
- else
- {
- if (atoi(hst->valuestring) > 10 && atoi(hst->valuestring) < 150)
- {
- device_status.heatvalue = atoi(hst->valuestring);
- ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue)); // 加热温度
- LOG_I("加热温度hst:%d", atoi(hst->valuestring));
- }
- else
- {
- LOG_E("加热温度hst设置失败参数错误!!!");
- }
- }
- }
- #if LAMP_EN == 0 // 三色光源无法修改开始和结束时间
- if (st != NULL)
- {
- if (st->type == cJSON_Number)
- {
- if (st->valueint >= 0 && st->valueint <= 23)
- {
- device_status.startBar = st->valueint;
- ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar)); // 开始时间
- LOG_I("开始时间st:%d", st->valueint);
- }
- else
- {
- LOG_E("开始时间st设置失败参数错误!!!");
- }
- }
- else
- {
- if (atoi(st->valuestring) >= 0 && atoi(st->valuestring) <= 23)
- {
- device_status.startBar = atoi(st->valuestring);
- ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar)); // 开始时间
- LOG_I("开始时间st:%d", atoi(st->valuestring));
- }
- else
- {
- LOG_E("开始时间st设置失败参数错误!!!");
- }
- }
- }
- if (et != NULL)
- {
- if (et->type == cJSON_Number)
- {
- if (et->valueint >= 0 && et->valueint <= 23)
- {
- device_status.stopBar = et->valueint;
- ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar)); // 结束时间
- LOG_I("结束时间et:%d", et->valueint);
- }
- else
- {
- LOG_E("结束时间et设置失败参数错误!!!");
- }
- }
- else if (et->type == cJSON_String)
- {
- if (atoi(et->valuestring) >= 0 && atoi(et->valuestring) <= 23)
- {
- device_status.stopBar = atoi(et->valuestring);
- ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar)); // 结束时间
- LOG_I("结束时间et:%d", atoi(et->valuestring));
- }
- else
- {
- LOG_E("结束时间et设置失败参数错误!!!");
- }
- }
- }
- #endif
- if (collt != NULL)
- {
- if (collt->type == cJSON_Number)
- {
- if (collt->valueint >= 1 && collt->valueint <= 60)
- {
- device_status.clt_time = collt->valueint;
- ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time)); // 收集时间
- LOG_I("收集时间collt:%d", collt->valueint);
- }
- else
- {
- LOG_E("收集时间collt设置失败参数错误!!!");
- }
- }
- else if (collt->type == cJSON_String)
- {
- if (atoi(collt->valuestring) >= 1 && atoi(collt->valuestring) <= 60)
- {
- device_status.clt_time = atoi(collt->valuestring);
- ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time)); // 收集时间
- LOG_I("收集时间collt:%d", atoi(collt->valuestring));
- }
- else
- {
- LOG_E("收集时间collt设置失败参数错误!!!");
- }
- }
- else if (collt->type == cJSON_Array)
- {
- int icnt = 0;
- for (icnt = 0; icnt < cJSON_GetArraySize(collt); icnt++)
- {
- cJSON *pSub = cJSON_GetArrayItem(collt, icnt);
- if (NULL == pSub)
- break;
- char ivalue[10];
- rt_sprintf(ivalue, "%s", pSub->valuestring);
- if (icnt == 0)
- {
- if (ivalue[1] == '-')
- {
- device_status.collecting_sh1 = atoi(&ivalue[0]);
- if (strlen(ivalue) == 3)
- device_status.collecting_eh1 = atoi(&ivalue[2]);
- if (strlen(ivalue) == 4)
- device_status.collecting_eh1 = atoi(&ivalue[3]) << 8 | atoi(&ivalue[2]);
- ef_set_env_blob("collecting_sh1", &device_status.collecting_sh1, sizeof(device_status.collecting_sh1));
- ef_set_env_blob("collecting_eh1", &device_status.collecting_eh1, sizeof(device_status.collecting_eh1));
- }
- if (ivalue[2] == '-')
- {
- device_status.collecting_sh1 = atoi(&ivalue[1]) << 8 | atoi(&ivalue[0]);
- if (strlen(ivalue) == 3)
- device_status.collecting_eh1 = atoi(&ivalue[3]);
- if (strlen(ivalue) == 5)
- device_status.collecting_eh1 = atoi(&ivalue[4]) << 8 | atoi(&ivalue[3]);
- ef_set_env_blob("collecting_sh1", &device_status.collecting_sh1, sizeof(device_status.collecting_sh1));
- ef_set_env_blob("collecting_eh1", &device_status.collecting_eh1, sizeof(device_status.collecting_eh1));
- }
- LOG_I("开始结束时间1:%d-%d", device_status.collecting_sh1, device_status.collecting_eh1);
- }
- else if (icnt == 1)
- {
- if ((ivalue[1] == '-'))
- {
- device_status.collecting_sh2 = atoi(&ivalue[0]);
- if (strlen(ivalue) == 3)
- device_status.collecting_eh2 = atoi(&ivalue[2]);
- if (strlen(ivalue) == 4)
- device_status.collecting_eh2 = atoi(&ivalue[3]) << 8 | atoi(&ivalue[2]);
- ef_set_env_blob("collecting_sh2", &device_status.collecting_sh2, sizeof(device_status.collecting_sh2));
- ef_set_env_blob("collecting_eh2", &device_status.collecting_eh2, sizeof(device_status.collecting_eh2));
- }
- if ((ivalue[2] == '-'))
- {
- device_status.collecting_sh2 = atoi(&ivalue[1]) << 8 | atoi(&ivalue[0]);
- if (strlen(ivalue) == 3)
- device_status.collecting_eh2 = atoi(&ivalue[2]);
- if (strlen(ivalue) == 5)
- device_status.collecting_eh2 = atoi(&ivalue[4]) << 8 | atoi(&ivalue[3]);
- ef_set_env_blob("collecting_sh2", &device_status.collecting_sh2, sizeof(device_status.collecting_sh2));
- ef_set_env_blob("collecting_eh2", &device_status.collecting_eh2, sizeof(device_status.collecting_eh2));
- }
- LOG_I("开始结束时间2:%d-%d", device_status.collecting_sh2, device_status.collecting_eh2);
- }
- LOG_I("下发设置收集:%d-%s", icnt, ivalue);
- }
- }
- }
- if (datt != NULL)
- {
- if (datt->type == cJSON_Number)
- {
- if (datt->valueint >= 1 && datt->valueint <= 120)
- {
- device_status.dattim = datt->valueint;
- ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim)); // 数据上传间隔
- LOG_I("数据上传间隔datt:%d", datt->valueint);
- }
- else
- {
- LOG_E("数据上传间隔datt设置失败参数错误!!!");
- }
- }
- else if (datt->type == cJSON_String)
- {
- if (atoi(datt->valuestring) >= 1 && atoi(datt->valuestring) <= 120)
- {
- device_status.dattim = atoi(datt->valuestring);
- ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim)); // 数据上传间隔
- LOG_I("数据上传间隔datt:%d", atoi(datt->valuestring));
- }
- else
- {
- LOG_E("数据上传间隔datt设置失败参数错误!!!");
- }
- }
- }
- if (shake_sec != NULL)
- {
- if (shake_sec->type == cJSON_Number)
- {
- if (shake_sec->valueint >= 1 && shake_sec->valueint <= 1000)
- {
- device_status.shake_sec = shake_sec->valueint;
- ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); // 震动时间
- LOG_I("震动时间shake_sec:%d", shake_sec->valueint);
- }
- else
- {
- LOG_E("震动时间shake_sec设置失败参数错误!!!");
- }
- }
- else if (shake_sec->type == cJSON_String)
- {
- if (atoi(shake_sec->valuestring) >= 1 && atoi(shake_sec->valuestring) <= 1000)
- {
- device_status.shake_sec = atoi(shake_sec->valuestring);
- ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); // 震动时间
- LOG_I("震动时间shake_sec:%d", atoi(shake_sec->valuestring));
- }
- else
- {
- LOG_E("震动时间shake_sec设置失败参数错误!!!");
- }
- }
- }
- if (shake != NULL)
- {
- if (shake->type == cJSON_Number)
- {
- if (shake->valueint == 0 || shake->valueint == 1)
- {
- device_status.shake_ws = shake->valueint;
- ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); // 震动开关
- LOG_I("震动开关shake:%d", shake->valueint);
- }
- else
- {
- LOG_E("震动开关shake设置失败参数错误!!!");
- }
- }
- else if (shake->type == cJSON_String)
- {
- if (atoi(shake->valuestring) == 0 || atoi(shake->valuestring) == 1)
- {
- device_status.shake_ws = atoi(shake->valuestring);
- ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); // 震动开关
- LOG_I("震动开关shake:%d", atoi(shake->valuestring));
- }
- else
- {
- LOG_E("震动开关shake设置失败参数错误!!!");
- }
- }
- }
- if (tt != NULL)
- {
- if (tt->type == cJSON_Number)
- {
- if (tt->valueint >= 1 && tt->valueint <= 10)
- {
- #if LAMP_EN == 0
- device_status.sunBar = tt->valueint;
- ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar)); // 光控定时
- rt_kprintf("光控定时tt:%d\n", tt->valueint);
- #else
- if (tt->valueint == 3 || tt->valueint == 6 || tt->valueint == 9)
- {
- device_status.sunBar = tt->valueint;
- ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar)); // 光控定时
- rt_kprintf("光控定时tt:%d\n", tt->valueint);
- }
- else
- {
- device_status.sunBar = 3;
- rt_kprintf("三光源模式,禁止设置定时时长!!!\n");
- }
- #endif
- }
- else
- {
- rt_kprintf("光控定时tt设置失败参数错误!!!\n");
- }
- }
- else if (tt->type == cJSON_String)
- {
- if (atoi(tt->valuestring) >= 1 && atoi(tt->valuestring) <= 10)
- {
- #if LAMP_EN == 0
- device_status.sunBar = atoi(tt->valuestring);
- ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar)); // 光控定时
- rt_kprintf("光控定时tt:%d\n", atoi(tt->valuestring));
- #else
- if (atoi(tt->valuestring) % 3 == 0)
- {
- device_status.sunBar = atoi(tt->valuestring);
- ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar)); // 光控定时
- LOG_I("光控定时tt:%d", atoi(tt->valuestring));
- }
- else
- {
- device_status.sunBar = 3;
- LOG_W("三光源模式,禁止设置定时时长!!!");
- }
- #endif
- }
- else
- {
- LOG_E("光控定时tt设置失败参数错误!!!");
- }
- }
- }
- if (htim != NULL)
- {
- if (htim->type == cJSON_Number)
- {
- if (htim->valueint >= 1 && htim->valueint <= 30)
- {
- device_status.heattime = htim->valueint;
- ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime)); // 加热时间
- LOG_I("加热时长htim:%d", htim->valueint);
- }
- else
- {
- LOG_E("加热时长htim设置失败参数错误!!!");
- }
- }
- else if (htim->type == cJSON_String)
- {
- if (atoi(htim->valuestring) >= 1 && atoi(htim->valuestring) <= 30)
- {
- device_status.heattime = atoi(htim->valuestring);
- ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime)); // 加热时间
- LOG_I("加热时长htim:%d", atoi(htim->valuestring));
- }
- else
- {
- LOG_E("加热时长htim设置失败参数错误!!!");
- }
- }
- }
- if (ts != NULL)
- {
- if (ts->type == cJSON_Number)
- {
- if (ts->valueint == 0 || ts->valueint == 1)
- {
- device_status.timeSwitch = ts->valueint;
- ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch)); // 工作模式
- // time_t now;
- // time(&now);
- // static struct tm nowstamp;
- // nowstamp =*localtime(&now);
- // nowstamp.tm_hour = nowstamp.tm_hour - 8;
- // static rt_uint32_t nowstamp_num = 0;
- // nowstamp_num = mktime(&nowstamp);
- // device_status.light_over_tim = device_status.sunBar * 3600 + nowstamp_num;
- LOG_I("定时模式ts:%d", ts->valueint);
- }
- else
- {
- LOG_E("定时模式ts设置失败参数错误!!!");
- }
- }
- else if (ts->type == cJSON_String)
- {
- if (atoi(ts->valuestring) == 0 || atoi(ts->valuestring) == 1)
- {
- device_status.timeSwitch = atoi(ts->valuestring);
- ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch)); // 工作模式
- // time_t now;
- // time(&now);
- // static struct tm nowstamp;
- // nowstamp =*localtime(&now);
- // nowstamp.tm_hour = nowstamp.tm_hour - 8;
- // static rt_uint32_t nowstamp_num = 0;
- // nowstamp_num = mktime(&nowstamp);
- // device_status.light_over_tim = device_status.sunBar * 3600 + nowstamp_num;
- LOG_I("定时模式ts:%d", atoi(ts->valuestring));
- }
- else
- {
- LOG_I("定时模式ts设置失败参数错误!!!");
- }
- }
- }
- if (tpl != NULL)
- {
- if (tpl->type == cJSON_Number)
- {
- if (tpl->valueint >= -50 && tpl->valueint <= 50)
- {
- device_status.tpl = tpl->valueint;
- ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl)); // 低温保护
- rt_kprintf("低温保护tpl:%d\n", tpl->valueint);
- }
- else
- {
- rt_kprintf("低温保护tpl设置失败参数错误!!!\n");
- }
- }
- else if (tpl->type == cJSON_String)
- {
- if (atoi(tpl->valuestring) >= -50 && atoi(tpl->valuestring) <= 50)
- {
- device_status.tpl = atoi(tpl->valuestring);
- ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl)); // 低温保护
- rt_kprintf("低温保护tpl:%d\n", atoi(tpl->valuestring));
- }
- else
- {
- rt_kprintf("低温保护tpl设置失败参数错误!!!\n");
- }
- }
- }
- if (tph != NULL)
- {
- if (tph->type == cJSON_Number)
- {
- if (tph->valueint >= 50 && tph->valueint <= 80)
- {
- device_status.tph = tph->valueint;
- ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph)); // 高温保护
- rt_kprintf("高温保护tph:%d\n", tph->valueint);
- }
- else
- {
- rt_kprintf("高温保护tph设置失败参数错误!!!\n");
- }
- }
- else if (tph->type == cJSON_String)
- {
- if (atoi(tph->valuestring) >= 50 && atoi(tph->valuestring) <= 80)
- {
- device_status.tph = atoi(tph->valuestring);
- ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph)); // 高温保护
- rt_kprintf("高温保护tph:%d\n", atoi(tph->valuestring));
- }
- else
- {
- rt_kprintf("高温保护tph设置失败参数错误!!!\n");
- }
- }
- }
- if (ds != NULL)
- {
- if (ds->type == cJSON_Number)
- {
- if (ds->valueint >= 0 && ds->valueint <= 1)
- {
- device_status.ds = ds->valueint;
- ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
- LOG_I("开关机状态:%d", ds->valueint);
- }
- else
- {
- LOG_E("开关机状态设置失败参数错误!!!");
- }
- }
- else if (ds->type == cJSON_String)
- {
- if (atoi(ds->valuestring) >= 0 && atoi(ds->valuestring) <= 1)
- {
- device_status.ds = atoi(ds->valuestring);
- ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
- LOG_I("开关机状态:%d\n", atoi(ds->valuestring));
- }
- else
- {
- LOG_E("开关机状态设置失败参数错误!!!");
- }
- }
- }
- if (vt != NULL)
- {
- if (atoi(vt->valuestring) >= 0 && atoi(vt->valuestring) <= 100)
- {
- device_status.version_type = atoi(vt->valuestring);
- ef_set_env_blob("version_type", &device_status.version_type, sizeof(device_status.version_type));
- if (device_status.version_type == 7)
- {
- device_status.dtype = 7;
- ef_set_env_blob("dtype", &device_status.dtype, sizeof(device_status.dtype));
- }
- rt_kprintf("版本类型vt:%d\n", atoi(vt->valuestring));
- }
- else
- {
- rt_kprintf("版本类型设置失败参数错误!!!\n");
- }
- }
- UpLoad_Data();
- rt_thread_delay(2000);
- // 2022/06/23,add:
- if (device_status.dtype == 3)
- {
- rt_sprintf(device_status.json_w_clock, "平台操作:修改工作时间:开始-%d,结束-%d,模式-%d(0-光控,1-时控)-%s", device_status.startBar, device_status.stopBar, device_status.timeSwitch, device_status.stamp);
- json_s = makeJson_Warn(device_status.json_w_clock, "修改时间");
- ef_set_env_blob("json_w_clock", &device_status.json_w_clock, sizeof(device_status.json_w_clock)); // 将修改屏幕参数操作记录保存到Flash中
- if (atoi(device_status.net) == 0)
- DTU_Write("%s", json_s);
- rt_free(json_s);
- }
- rt_thread_delay(1000);
- MA_save();
- rt_thread_delay(1000);
- }
- }
- cJSON_Delete(root);
- }
- return 0;
- }
- /**
- * @brief 执行上报状态信息json的动作
- *
- */
- void UpLoad_Data(void)
- {
- char *updata = makeJson();
- LOG_I("upload data:%d%s", rt_strlen(updata), updata);
- rt_free(updata);
- #if Color_EN == 0
- DTU_Write("%s", updata);
- #endif
- list_mem();
- // 播放数据上传中语音
- }
|