引入mqtt 引入cjson

This commit is contained in:
2584532475@qq.com committed 2023-11-30 08:10:01 +08:00
1 parent a69c1a58d6
commit f8591b8b99
86 files changed
+12141 -2157

No files matched your search

+106
View File
@@ -0,0 +1,106 @@
#include "jsonunpack.h"
#include "cjson.h"
#include <string.h>
#include <rtthread.h>
#include "data.h"
#include <easyflash.h>
#include <stdlib.h>
#include "data.h"
#include "os-app.h"
char config_list[16][32] = {NULL};
int config_list_size = 0;
void JsonUnPacket (int index, char *buff)
{
// 读取Json 数据类型
char * packMsg = (char *) buff;
cJSON *root = NULL, *list = NULL;
root = cJSON_Parse (packMsg);
DownDataType_t type = (DownDataType_t) 0;
char * p, *key, *value;
int list_size;
TypeIndexMail_t mail;
p = cJSON_GetStringValue (cJSON_GetObjectItem (root, "type"));
type = (DownDataType_t) cDownType2Index (p);
rt_kprintf("down :%s<%d>\r\n",p,type);
switch (type)
{
case DownRun : // 开度提闸
// rt_kprintf ("open:%u mm/10\r\n", datak);
// //SluiceData[gMqttDrv.rx_index].opt = 1; // 执行操作闸门
// SluiceData[gMqttDrv.rx_index - 1].sopen = datak / 10;
// mail.Type = MAIL_SLUICE_OPT;
// mail.index = gMqttDrv.rx_index - 1;
// rt_mb_send (gSluiceMail, * ( (uint32_t*) &mail));
// // 回复应答
// mail.Type = MAIL_COMM_SLACK;
// mail.index = gMqttDrv.rx_index;
// rt_mb_send (gTCommMail, * ( (uint32_t*) &mail));
break;
case DownStop :
break;
case DownOpen :
break;
case DownClose :
break;
case DownRegistAns :
break;
case DownHeartAns :
break;
case DownUpdate :
rt_memset (SysData.fileName, 0, 32);
p = cJSON_GetStringValue (cJSON_GetObjectItem (root, "file"));
rt_sprintf (SysData.fileName, "%s", p) ;
// 启动升级线程
// 回复应答
mail.Type = MAIL_COMM_UPACK;
mail.index = index + 1; // 0通道用来升级的通道
rt_mb_send (gTCommMail, * ( (uint32_t*) &mail));
rt_thread_mdelay (2000); // 等待2s 进入升级线程
UpgradeThreadStart();
break;
case DownReboot :
break;
case DownConfig: // 设置参数
// 读取参数列表
list = cJSON_GetObjectItem (root, "list");
list_size = cJSON_GetArraySize (list);
for (int i = 0; i < list_size; i++)
{
key = cJSON_GetStringValue (cJSON_GetArrayItem (list, i));
value = cJSON_GetStringValue (cJSON_GetObjectItem (root, key));
if ( (ef_get_env (key) != NULL) && (value != NULL))
{
ef_set_env (key, value);
}
}
break;
case DownRead: // 读取参数
list = cJSON_GetObjectItem (root, "list");
config_list_size = cJSON_GetArraySize (list);
for (int i = 0; i < config_list_size; i++)
{
key = cJSON_GetStringValue (cJSON_GetArrayItem (list, i));
rt_sprintf(config_list[i],"%s",key);
}
mail.Type = MAIL_COMM_READPARA;
mail.index = index + 1; // 0通道用来升级的通道
rt_mb_send (gTCommMail, * ( (uint32_t*) &mail));
// 读取参数列表
break;
default:
break;
}
cJSON_Delete (root);
}