JSON协议是什么,物联网中的RTU中如何使用JSON协议和服务器交互
JSON之所以受欢迎,主要是因为它仍然使用 JavaScript 语法来描述数据对象,并没有改变开发人员的使用习惯,这更容易被开发人员接受。由于这种相似性,JavaScript 程序就无需解析器,便可以直接用 JSON 数据来生成原生的 JavaScript 对象。
01
概述
1.1 什么是 JSON
JSON是JavaScript Object Notation的简称,中文含义为“JavaScript 对象表示法”,它是一种数据交换的文本格式,而不是一种编程语言。
JSON 是一种轻量级的数据交换格式,它基于 ECMAScript (w3c制定的js规范)的一个子集,采用完全独立于编程语言的文本格式来存储和表示数据。简洁和清晰的层次结构使得 JSON 成为理想的数据交换语言。
JSON之所以受欢迎,主要是因为它仍然使用 JavaScript 语法来描述数据对象,并没有改变开发人员的使用习惯,这更容易被开发人员接受。由于这种相似性,JavaScript 程序就无需解析器,便可以直接用 JSON 数据来生成原生的 JavaScript 对象。
1.2 JSON 的特点
JSON 主要具有以下特性,这些特性使它成为理想的数据交换语言:
-
JSON 是轻量级的文本数据交换格式
-
JSON 具有自我描述性,更易理解
-
JSON 采用完全独立于语言的文本格式:JSON 使用 JavaScript 语法来描述数据对象,但是 JSON 仍然独立于语言和平台。JSON 解析器和 JSON 库支持许多不同的编程语言。 目前常见的动态编程语言(PHP,JSP,.NET)都支持JSON。
-
JSON 是存储和交换文本信息的一种语法,它与XML具有相同的特性,是一种数据存储格式,却比 XML 更小、更快、 更易于人编写和阅读、更易于生成和解析。
类似于 XML 的特性:
-
JSON 是纯文本
-
JSON 具有“自我描述性”(人类可读)
-
JSON 具有层级结构(值中存在值)
-
JSON 可通过 JavaScript 进行解析
-
JSON 数据可使用 AJAX 进行传输
相比 XML 的不同之处:
-
没有结束标签
-
更短
-
读写的速度更快
-
能够使用内建的 JavaScript eval() 方法进行解析
-
使用数组
-
不使用保留字
02
JSON语法
在 JavaScript 语言中,一切皆对象。任何支持的类型,如字符串、数值、对象、数组等,都可以通过 JSON 来表示。
JSON 语法是 JavaScript 对象表示法的子集:
-
数据在键/值对中,键/值对可以嵌套
-
数据由逗号分隔
-
花括号保存对象,对象可以包含多个键/值对
-
方括号保存数组,数组可以包含多个对象
-
JSON不是JavaScript语句,对象的末尾没有分号,对象和数组的最后一个成员后面,也不能加逗号。
2.1 JSON 键/值对
JSON键/值对由键和值组成,键必须是字符串,值可以是字符串(string)、数值(number) 、对象(object)、数组(array)、true、false、 null。如图所示:
在定义JSON键/值时,先是键名,后面写一个冒号,然后是值。如:
"github": "https://github.com/leiqikui"
这就等价于这条 JavaScript 语句:
github = "https://github.com/leiqikui"
2.2 JSON 字符串
JSON 的字符串(string)跟C或者Java的字符串非常相似,是由双引号包围的任意数量Unicode字符的集合,使用反斜线转义。如图所示:
由于JSON 字符串不能使用单引号,因此一个字符(character)就是一个单独的字符串(character string)。
2.3 JSON 数值
JSON 数值(number)与C或者Java的数值非常相似,支持整型、浮点型,浮点型也可以用指数表示。如图所示:
JSON不支持八进制和十六进制, 数值必须以十进制表示,且不能使用NaN和Infinity。以下是合法的JSON数值:
{ "age": 30 }
2.4 JSON 对象
JSON 对象是一个无序的key/value对的集合。一个对象以 '{' 开始,以 '}' 结束;每个key 和 value 中使用冒号分隔;每个 key/value 对之间使用逗号分隔。如图 14所示:
JSON 对象语法:
-
对象在大括号({})中书写。
-
对象可以包含多个 key/value(键/值)对。
-
key是字符串,必须放在双引号里面。value 可以是合法的 JSON 数据类型(字符串, 数值, 对象, 数组, 布尔值或 null)。
-
一个 key/value 对内部,key 和 value使用冒号(:)分隔。
-
key/value 对之间,使用逗号(,)分隔。
-
对象可以嵌套
2.5 JSON 数组
数组是值(value)的有序集合。一个数组以“[”(左中括号)开始,“]”(右中括号)结束。值之间使用“,”(逗号)分隔。如图 15所示:
JSON 数组:
-
数组在中括号中书写。
-
数组的值必须是合法的 JSON 数据类型(字符串, 数值, 对象, 数组, 布尔值或 null),也可以是 JavaScript 的表达式,包括函数、日期、undefined。
2.6 JSON 布尔值
JSON 布尔值可以是 true 或者 false。如:
{ "flag":true }
2.7 JSON null
JSON 可以设置 null 值。如:
{ "zhihu":null }
2.8 JSON 文件
JSON 文件的文件类型是 ".json"
JSON 文本的 MIME 类型是 "application/json"
03
JSON协议组件的使用
1 Gitee链接地址
组件位于amaziot_bloom_os_sdk\libraries\am\xtu\am_json.c
Gitee源码地址:https://gitee.com/ning./hongdou
Github源码地址:https://github.com/ayumid/hongdou
2 应用层组件功能介绍
提供JSON协议和服务器通信连接实例。
使用该组件,必须同时使用AT组件,文件组件,TCP组件,掉线组件,掉线重连组件,DI组件,DO组件,AI组件,JSON组件,CLK组件。
3 代码讲解
1 dtu_json_task_send_msgq
发送消息给模块主任务,错误后串口输出信息
/**
* Function : dtu_json_task_send_msgq
* Description : 发送消息给模块主任务,错误后串口输出信息
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
int dtu_json_task_send_msgq(DTU_JSON_MSG_T * msg)
{
int ret = 0;
//发送消息给json主任务
OSA_STATUS status = OSAMsgQSend(dtu_json_msgq, DTU_JSON_TASK_MSGQ_MSG_SIZE, (void*)msg, OSA_NO_SUSPEND);
if (status != OS_SUCCESS)
{
printf("%s, OSAMsgQSend lose, msg->id=%d, status=%d", __FUNCTION__, msg->msgId, status);
ret = -1;
}
return ret;
}
2 dtu_sys_json_get_sys_config
发送消息给主任务,按照协议回复相应内容
/**
* Function : dtu_sys_json_get_sys_config
* Description : 发送消息给主任务,按照协议回复相应内容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_sys_json_get_sys_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID为获取配置回复
p_smsg.msgId = DTU_SYS_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d \n", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}
3 dtu_sys_json_get_sys_config_res
回复服务器获取sys配置
/**
* Function : dtu_sys_json_get_sys_config_res
* Description : 回复服务器获取sys配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_sys_json_get_sys_config_res(void)
{
cJSON *gdocr = NULL;
cJSON *data = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//创建json对象
gdocr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(data, "enHb", cJSON_CreateNumber(dtu_file_ctx->hb.heartflag));
cJSON_AddItemToObject(data, "cycHb", cJSON_CreateNumber(dtu_file_ctx->hb.hearttime));
cJSON_AddItemToObject(data, "hbPkg", cJSON_CreateString(dtu_file_ctx->hb.heart));
cJSON_AddItemToObject(data, "enReg", cJSON_CreateNumber(dtu_file_ctx->reg.linkflag));
cJSON_AddItemToObject(data, "regpkg", cJSON_CreateString(dtu_file_ctx->reg.link));
cJSON_AddItemToObject(gdocr, "msgType", cJSON_CreateString("getSysConfigRes"));
cJSON_AddItemToObject(gdocr, "data", data);
//申请内存
send = malloc(strlen(cJSON_Print(gdocr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdocr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gdocr);
}
4 dtu_sys_json_set_sys_config
设置sys配置
/**
* Function : dtu_sys_json_set_sys_config
* Description : 设置sys配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_sys_json_set_sys_config(int len , char *rcvdata)
{
UINT8 res = 0;
DTU_JSON_MSG_T p_smsg = {0};
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
DTU_TIME_PARAM_T* dtu_timer_ctx = NULL;
cJSON * gdocg = NULL;
cJSON * data = NULL;
cJSON * item = NULL;
//获取对应模块的上下文指针
dtu_file_ctx = dtu_get_file_ctx();
dtu_timer_ctx = dtu_get_timer_ctx();
//消息ID设置为对应ID
p_smsg.msgId = DTU_SYS_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s\n", __FUNCTION__, rcvdata);
//解析数据
gdocg = cJSON_Parse(rcvdata);
if(NULL != gdocg)
{
data = cJSON_GetObjectItem(gdocg, "data");
if(NULL != data)
{
printf("data:%s",cJSON_Print(data));
item = cJSON_GetObjectItem(data, "enHb");
dtu_file_ctx->hb.heartflag = item->valueint;
item = cJSON_GetObjectItem(data, "cycHb");
dtu_file_ctx->hb.hearttime = item->valueint;
item = cJSON_GetObjectItem(data, "hbPkg");
memset(dtu_file_ctx->hb.heart, 0, sizeof(dtu_file_ctx->hb.heart));
memcpy(dtu_file_ctx->hb.heart, item->valuestring, strlen(item->valuestring));
item = cJSON_GetObjectItem(data, "enReg");
dtu_file_ctx->reg.linkflag = item->valueint;
item = cJSON_GetObjectItem(data, "regpkg");
memset(dtu_file_ctx->reg.link, 0, sizeof(dtu_file_ctx->reg.link));
memcpy(dtu_file_ctx->reg.link, item->valuestring, strlen(item->valuestring));
if(1 == dtu_file_ctx->hb.heartflag)
{
//开始心跳定时器
OSATimerStart(dtu_timer_ctx->dtu_timer_ref, dtu_file_ctx->hb.hearttime * 200, dtu_file_ctx->hb.hearttime * 200 , dtu_hb_timer_callback, 0);
}
else if(0 == dtu_file_ctx->hb.heartflag)
{
//关闭心跳定时器
OSATimerStop(dtu_timer_ctx->dtu_timer_ref);
}
//写入文件
dtu_trans_conf_file_write(dtu_file_ctx);
printf("enHb: %d, cycHb: %d, hbPkg: %s, enReg: %d, regpkg: %s\r\n",
dtu_file_ctx->hb.heartflag,
dtu_file_ctx->hb.hearttime,
dtu_file_ctx->hb.heart,
dtu_file_ctx->reg.linkflag,
dtu_file_ctx->reg.link);
}
else
{
res = 1;
}
}
else
{
res = 1;
}
p_smsg.status = res;
dtu_json_task_send_msgq(&p_smsg);
}
5 dtu_sys_json_set_sys_config_res
回复服务器设置sys
/**
* Function : dtu_sys_json_set_sys_config_res
* Description : 回复服务器设置sys
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_sys_json_set_sys_config_res(UINT8 res)
{
cJSON *gdocr = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
gdocr = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(gdocr, "msgType", cJSON_CreateString("setSysConfigRes"));
cJSON_AddItemToObject(gdocr, "data", cJSON_CreateNumber(res));
//申请内存
send = malloc(strlen(cJSON_Print(gdocr)));
if(NULL != gdocr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdocr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gdocr);
}
6 dtu_net_json_get_net_config
发送消息给主任务,按照协议回复相应内容
/**
* Function : dtu_net_json_get_net_config
* Description : 发送消息给主任务,按照协议回复相应内容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_net_json_get_net_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID设置为对应ID
p_smsg.msgId = DTU_NET_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d \n", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}
7 dtu_net_json_get_net_config_res
回复服务器获net配置
/**
* Function : dtu_net_json_get_net_config_res
* Description : 回复服务器获net配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_net_json_get_net_config_res(void)
{
cJSON *gdocr = NULL;
cJSON *data = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//创建json对象
gdocr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(data, "IP", cJSON_CreateString(dtu_file_ctx->socket.ip));
cJSON_AddItemToObject(data, "port", cJSON_CreateNumber(dtu_file_ctx->socket.port));
cJSON_AddItemToObject(data, "type", cJSON_CreateNumber(dtu_file_ctx->socket.type));
cJSON_AddItemToObject(gdocr, "msgType", cJSON_CreateString("getNetConfigRes"));
cJSON_AddItemToObject(gdocr, "data", data);
//申请内存
send = malloc(strlen(cJSON_Print(gdocr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdocr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gdocr);
}
8 dtu_net_json_set_net_config
设置网络配置
/**
* Function : dtu_net_json_set_net_config
* Description : 设置网络配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_net_json_set_net_config(int len , char *rcvdata)
{
UINT8 res = 0;
DTU_JSON_MSG_T p_smsg = {0};
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
cJSON * gdocg = NULL;
cJSON * data = NULL;
cJSON * item = NULL;
//获取对应模块的上下文指针
dtu_file_ctx = dtu_get_file_ctx();
//消息ID设置为对应ID
p_smsg.msgId = DTU_NET_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s\n", __FUNCTION__, rcvdata);
//解析数据
gdocg = cJSON_Parse(rcvdata);
if(NULL != gdocg)
{
data = cJSON_GetObjectItem(gdocg, "data");
if(NULL != data)
{
printf("data:%s",cJSON_Print(data));
item = cJSON_GetObjectItem(data, "IP");
memset(dtu_file_ctx->socket.ip, 0, sizeof(dtu_file_ctx->socket.ip));
memcpy(dtu_file_ctx->socket.ip, item->valuestring, strlen(item->valuestring));
item = cJSON_GetObjectItem(data, "port");
dtu_file_ctx->socket.port = item->valueint;
item = cJSON_GetObjectItem(data, "type");
dtu_file_ctx->socket.type = item->valueint;
//写入文件
dtu_trans_conf_file_write(dtu_file_ctx);
printf("IP %s, port %d, type %d",
dtu_file_ctx->socket.ip,
dtu_file_ctx->socket.port,
dtu_file_ctx->socket.type);
}
else
{
res = 1;
}
}
else
{
res = 1;
}
p_smsg.status = res;
dtu_json_task_send_msgq(&p_smsg);
}
9 dtu_net_json_set_net_config
设置网络配置
/**
* Function : dtu_net_json_set_net_config
* Description : 设置网络配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_net_json_set_net_config(int len , char *rcvdata)
{
UINT8 res = 0;
DTU_JSON_MSG_T p_smsg = {0};
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
cJSON * gdocg = NULL;
cJSON * data = NULL;
cJSON * item = NULL;
//获取对应模块的上下文指针
dtu_file_ctx = dtu_get_file_ctx();
//消息ID设置为对应ID
p_smsg.msgId = DTU_NET_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s\n", __FUNCTION__, rcvdata);
//解析数据
gdocg = cJSON_Parse(rcvdata);
if(NULL != gdocg)
{
data = cJSON_GetObjectItem(gdocg, "data");
if(NULL != data)
{
printf("data:%s",cJSON_Print(data));
item = cJSON_GetObjectItem(data, "IP");
memset(dtu_file_ctx->socket.ip, 0, sizeof(dtu_file_ctx->socket.ip));
memcpy(dtu_file_ctx->socket.ip, item->valuestring, strlen(item->valuestring));
item = cJSON_GetObjectItem(data, "port");
dtu_file_ctx->socket.port = item->valueint;
item = cJSON_GetObjectItem(data, "type");
dtu_file_ctx->socket.type = item->valueint;
//写入文件
dtu_trans_conf_file_write(dtu_file_ctx);
printf("IP %s, port %d, type %d",
dtu_file_ctx->socket.ip,
dtu_file_ctx->socket.port,
dtu_file_ctx->socket.type);
}
else
{
res = 1;
}
}
else
{
res = 1;
}
p_smsg.status = res;
dtu_json_task_send_msgq(&p_smsg);
}
10 dtu_net_json_set_net_config_res
回复服务器设置net
/**
* Function : dtu_net_json_set_net_config_res
* Description : 回复服务器设置net
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_net_json_set_net_config_res(UINT8 res)
{
cJSON *gdocr = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
gdocr = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(gdocr, "msgType", cJSON_CreateString("setNetConfigRes"));
cJSON_AddItemToObject(gdocr, "data", cJSON_CreateNumber(res));
//申请内存
send = malloc(strlen(cJSON_Print(gdocr)));
if(NULL != gdocr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdocr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gdocr);
}
11 dtu_di_json_get_di_value
发送消息给主任务,按照协议回复相应内容
/**
* Function : dtu_di_json_get_di_value
* Description : 发送消息给主任务,按照协议回复相应内容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_di_json_get_di_value(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID设置为对应ID
p_smsg.msgId = DTU_DI_MSG_ID_GET_VALUE_REPORT;
// printf("%s PIN4 status: %d \n", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}
12 dtu_di_json_get_di_value_res
回复服务器获取di值
/**
* Function : dtu_di_json_get_di_value_res
* Description : 回复服务器获取di值
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_di_json_get_di_value_res(void)
{
cJSON *gdivr = NULL;
cJSON *data = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
gdivr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(data, "DI1", cJSON_CreateNumber(dtu_di_read_pin_1()));
cJSON_AddItemToObject(data, "DI2", cJSON_CreateNumber(dtu_di_read_pin_2()));
cJSON_AddItemToObject(data, "DI3", cJSON_CreateNumber(dtu_di_read_pin_3()));
cJSON_AddItemToObject(data, "DI4", cJSON_CreateNumber(dtu_di_read_pin_4()));
cJSON_AddItemToObject(data, "DI5", cJSON_CreateNumber(dtu_di_read_pin_5()));
cJSON_AddItemToObject(gdivr, "msgType", cJSON_CreateString("getDiValueRes"));
cJSON_AddItemToObject(gdivr, "data", data);
//申请内存
send = malloc(strlen(cJSON_Print(gdivr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdivr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gdivr);
}
13 dtu_di_json_get_di_config
发送消息给主任务,按照协议回复相应内容
/**
* Function : dtu_di_json_get_di_config
* Description : 发送消息给主任务,按照协议回复相应内容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_di_json_get_di_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID设置为对应ID
p_smsg.msgId = DTU_DI_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d \n", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}
14 dtu_di_json_get_di_config_res
回复服务器获取di配置
/**
* Function : dtu_di_json_get_di_config_res
* Description : 回复服务器获取di配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_di_json_get_di_config_res(void)
{
cJSON *gdicr = NULL;
cJSON *data = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//创建json对象
gdicr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(data, "enRpt1", cJSON_CreateNumber(dtu_file_ctx->di.di1.di_type));
cJSON_AddItemToObject(data, "cyc1", cJSON_CreateNumber(dtu_file_ctx->di.di1.di_interval));
cJSON_AddItemToObject(data, "edge1", cJSON_CreateNumber(dtu_file_ctx->di.di1.di_edge));
cJSON_AddItemToObject(data, "enRpt2", cJSON_CreateNumber(dtu_file_ctx->di.di2.di_type));
cJSON_AddItemToObject(data, "cyc2", cJSON_CreateNumber(dtu_file_ctx->di.di2.di_interval));
cJSON_AddItemToObject(data, "edge2", cJSON_CreateNumber(dtu_file_ctx->di.di2.di_edge));
cJSON_AddItemToObject(data, "enRpt3", cJSON_CreateNumber(dtu_file_ctx->di.di3.di_type));
cJSON_AddItemToObject(data, "cyc3", cJSON_CreateNumber(dtu_file_ctx->di.di3.di_interval));
cJSON_AddItemToObject(data, "edge3", cJSON_CreateNumber(dtu_file_ctx->di.di3.di_edge));
cJSON_AddItemToObject(data, "enRpt4", cJSON_CreateNumber(dtu_file_ctx->di.di4.di_type));
cJSON_AddItemToObject(data, "cyc4", cJSON_CreateNumber(dtu_file_ctx->di.di4.di_interval));
cJSON_AddItemToObject(data, "edge4", cJSON_CreateNumber(dtu_file_ctx->di.di4.di_edge));
cJSON_AddItemToObject(data, "enRpt5", cJSON_CreateNumber(dtu_file_ctx->di.di5.di_type));
cJSON_AddItemToObject(data, "cyc5", cJSON_CreateNumber(dtu_file_ctx->di.di5.di_interval));
cJSON_AddItemToObject(data, "edge5", cJSON_CreateNumber(dtu_file_ctx->di.di5.di_edge));
cJSON_AddItemToObject(gdicr, "msgType", cJSON_CreateString("getDiConfigRes"));
cJSON_AddItemToObject(gdicr, "data", data);
//申请内存
send = malloc(strlen(cJSON_Print(gdicr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdicr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gdicr);
}
15 dtu_di_json_set_di_config
设置di配置
/**
* Function : dtu_di_json_set_di_config
* Description : 设置di配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_di_json_set_di_config(int len , char *rcvdata)
{
UINT8 res = 0;
DTU_JSON_MSG_T p_smsg = {0};
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
cJSON * gdicg = NULL;
cJSON * data = NULL;
cJSON * item = NULL;
//获取对应模块的上下文指针
dtu_file_ctx = dtu_get_file_ctx();
//消息ID设置为对应ID
p_smsg.msgId = DTU_DI_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s\n", __FUNCTION__, rcvdata);
//解析数据
gdicg = cJSON_Parse(rcvdata);
if(NULL != gdicg)
{
data = cJSON_GetObjectItem(gdicg, "data");
if(NULL != data)
{
printf("data:%s",cJSON_Print(data));
item = cJSON_GetObjectItem(data, "enRpt1");
dtu_file_ctx->di.di1.di_type = item->valueint;
item = cJSON_GetObjectItem(data, "cyc1");
dtu_file_ctx->di.di1.di_interval = item->valueint;
item = cJSON_GetObjectItem(data, "defaultLv1");
dtu_file_ctx->di.di1.di_edge = item->valueint;
item = cJSON_GetObjectItem(data, "enRpt2");
dtu_file_ctx->di.di2.di_type = item->valueint;
item = cJSON_GetObjectItem(data, "cyc2");
dtu_file_ctx->di.di2.di_interval = item->valueint;
item = cJSON_GetObjectItem(data, "defaultLv2");
dtu_file_ctx->di.di2.di_edge = item->valueint;
item = cJSON_GetObjectItem(data, "enRpt3");
dtu_file_ctx->di.di3.di_type = item->valueint;
item = cJSON_GetObjectItem(data, "cyc3");
dtu_file_ctx->di.di3.di_interval = item->valueint;
item = cJSON_GetObjectItem(data, "defaultLv3");
dtu_file_ctx->di.di3.di_edge = item->valueint;
item = cJSON_GetObjectItem(data, "enRpt4");
dtu_file_ctx->di.di4.di_type = item->valueint;
item = cJSON_GetObjectItem(data, "cyc4");
dtu_file_ctx->di.di4.di_interval = item->valueint;
item = cJSON_GetObjectItem(data, "defaultLv4");
dtu_file_ctx->di.di4.di_edge = item->valueint;
item = cJSON_GetObjectItem(data, "enRpt5");
dtu_file_ctx->di.di5.di_type = item->valueint;
item = cJSON_GetObjectItem(data, "cyc5");
dtu_file_ctx->di.di5.di_interval = item->valueint;
item = cJSON_GetObjectItem(data, "defaultLv5");
dtu_file_ctx->di.di5.di_edge = item->valueint;
if(DTU_DI_REPORT_INITIATIVE == dtu_file_ctx->di.di1.di_type)
{
//开定时器
dtu_di1_report_timer_start(dtu_file_ctx->di.di1.di_interval);
}
else if(DTU_DI_REPORT_NONE == dtu_file_ctx->di.di1.di_type)
{
dtu_di1_report_timer_stop();
}
if(DTU_DI_REPORT_INITIATIVE == dtu_file_ctx->di.di2.di_type)
{
//开定时器
dtu_di2_report_timer_start(dtu_file_ctx->di.di2.di_interval);
}
else if(DTU_DI_REPORT_NONE == dtu_file_ctx->di.di2.di_type)
{
dtu_di2_report_timer_stop();
}
if(DTU_DI_REPORT_INITIATIVE == dtu_file_ctx->di.di3.di_type)
{
//开定时器
dtu_di3_report_timer_start(dtu_file_ctx->di.di3.di_interval);
}
else if(DTU_DI_REPORT_NONE == dtu_file_ctx->di.di3.di_type)
{
dtu_di3_report_timer_stop();
}
if(DTU_DI_REPORT_INITIATIVE == dtu_file_ctx->di.di4.di_type)
{
//开定时器
dtu_di4_report_timer_start(dtu_file_ctx->di.di4.di_interval);
}
else if(DTU_DI_REPORT_NONE == dtu_file_ctx->di.di4.di_type)
{
dtu_di4_report_timer_stop();
}
if(DTU_DI_REPORT_INITIATIVE == dtu_file_ctx->di.di5.di_type)
{
//开定时器
dtu_di5_report_timer_start(dtu_file_ctx->di.di5.di_interval);
}
else if(DTU_DI_REPORT_NONE == dtu_file_ctx->di.di5.di_type)
{
dtu_di5_report_timer_stop();
}
//写入文件
dtu_trans_conf_file_write(dtu_file_ctx);
printf("DI1:type %d, interval %d, pull %d\r\n" \
"DI2:type %d, interval %d, pull %d\r\n" \
"DI3:type %d, interval %d, pull %d\r\n" \
"DI4:type %d, interval %d, pull %d\r\n" \
"DI5:type %d, interval %d, pull %d\r\n",
dtu_file_ctx->di.di1.di_type,
dtu_file_ctx->di.di1.di_interval,
dtu_file_ctx->di.di1.di_edge,
dtu_file_ctx->di.di2.di_type,
dtu_file_ctx->di.di2.di_interval,
dtu_file_ctx->di.di2.di_edge,
dtu_file_ctx->di.di3.di_type,
dtu_file_ctx->di.di3.di_interval,
dtu_file_ctx->di.di3.di_edge,
dtu_file_ctx->di.di4.di_type,
dtu_file_ctx->di.di4.di_interval,
dtu_file_ctx->di.di4.di_edge,
dtu_file_ctx->di.di5.di_type,
dtu_file_ctx->di.di5.di_interval,
dtu_file_ctx->di.di5.di_edge);
}
else
{
res = 1;
}
}
else
{
res = 1;
}
p_smsg.status = res;
dtu_json_task_send_msgq(&p_smsg);
}
16 dtu_di_set_di_value_res
回复服务器设置di值
/**
* Function : dtu_di_set_di_value_res
* Description : 回复服务器设置di值
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_di_json_set_di_config_res(UINT8 res)
{
cJSON *gdivr = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
gdivr = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(gdivr, "msgType", cJSON_CreateString("setDiConfigRes"));
cJSON_AddItemToObject(gdivr, "data", cJSON_CreateNumber(res));
//申请内存
send = malloc(strlen(cJSON_Print(gdivr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdivr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gdivr);
}
17 dtu_di_json_res
DI主动上报
/**
* Function : dtu_di_json_res
* Description : DI主动上报
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_di_json_res(UINT8 type, UINT8 channel, UINT8 level)
{
cJSON *gdivr = NULL;
cJSON *data = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
gdivr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照协议,对象内加入成员
if(DTU_GPIO_CHNNEL_1 == channel)
{
cJSON_AddItemToObject(data, "DI1", cJSON_CreateNumber(level));
}
else if(DTU_GPIO_CHNNEL_2 == channel)
{
cJSON_AddItemToObject(data, "DI2", cJSON_CreateNumber(level));
}
else if(DTU_GPIO_CHNNEL_3 == channel)
{
cJSON_AddItemToObject(data, "DI3", cJSON_CreateNumber(level));
}
else if(DTU_GPIO_CHNNEL_4 == channel)
{
cJSON_AddItemToObject(data, "DI4", cJSON_CreateNumber(level));
}
else if(DTU_GPIO_CHNNEL_5 == channel)
{
cJSON_AddItemToObject(data, "DI5", cJSON_CreateNumber(level));
}
if(DTU_DI_REPORT_INTER == type)
{
cJSON_AddItemToObject(gdivr, "msgType", cJSON_CreateString("diValueRpt"));
}
else if(DTU_DI_REPORT_TRIG == type)
{
cJSON_AddItemToObject(gdivr, "msgType", cJSON_CreateString("diValueRptTrig"));
}
cJSON_AddItemToObject(gdivr, "data", data);
//申请内存
send = malloc(strlen(cJSON_Print(gdivr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdivr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gdivr);
}
18 dtu_do_json_get_do_value
发送消息给主任务,按照协议回复相应内容
/**
* Function : dtu_do_json_get_do_value
* Description : 发送消息给主任务,按照协议回复相应内容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_do_json_get_do_value(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID设置为对应ID
p_smsg.msgId = DTU_DO_MSG_ID_GET_VALUE_REPORT;
// printf("%s PIN4 status: %d \n", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}
19 dtu_do_json_get_do_value_res
回复服务器获取di值
/**
* Function : dtu_do_json_get_do_value_res
* Description : 回复服务器获取di值
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_do_json_get_do_value_res(void)
{
cJSON *gdovr = NULL;
cJSON *data = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
gdovr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(data, "DO1", cJSON_CreateNumber(dtu_do_read_pin(DTU_GPIO_DO_PIN1)));
cJSON_AddItemToObject(data, "DO2", cJSON_CreateNumber(dtu_do_read_pin(DTU_GPIO_DO_PIN2)));
cJSON_AddItemToObject(data, "DO3", cJSON_CreateNumber(dtu_do_read_pin(DTU_GPIO_DO_PIN3)));
cJSON_AddItemToObject(data, "DO4", cJSON_CreateNumber(dtu_do_read_pin(DTU_GPIO_DO_PIN4)));
cJSON_AddItemToObject(data, "DO5", cJSON_CreateNumber(dtu_do_read_pin(DTU_GPIO_DO_PIN5)));
cJSON_AddItemToObject(gdovr, "msgType", cJSON_CreateString("getDoValueRes"));
cJSON_AddItemToObject(gdovr, "data", data);
//申请内存
send = malloc(strlen(cJSON_Print(gdovr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdovr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gdovr);
}
20 dtu_do_json_set_do_value
设置di配置
/**
* Function : dtu_do_json_set_do_value
* Description : 设置di配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_do_json_set_do_value(int len , char *rcvdata)
{
UINT8 res = 0;
UINT8 do1 = 0;
UINT8 do2 = 0;
UINT8 do3 = 0;
UINT8 do4 = 0;
UINT8 do5 = 0;
DTU_JSON_MSG_T p_smsg = {0};
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
cJSON * gdov = NULL;
cJSON * data = NULL;
cJSON * item = NULL;
//获取对应模块的上下文指针
dtu_file_ctx = dtu_get_file_ctx();
//消息ID设置为对应ID
p_smsg.msgId = DTU_DO_MSG_ID_SET_VALUE_REPORT;
// printf("%s %s\n", __FUNCTION__, rcvdata);
//解析数据
gdov = cJSON_Parse(rcvdata);
if(NULL != gdov)
{
data = cJSON_GetObjectItem(gdov, "data");
if(NULL != data)
{
printf("data:%s",cJSON_Print(data));
item = cJSON_GetObjectItem(data, "DO1");
dtu_do_write_pin("DO1", item->valueint);
item = cJSON_GetObjectItem(data, "DO2");
dtu_do_write_pin("DO2", item->valueint);
item = cJSON_GetObjectItem(data, "DO3");
dtu_do_write_pin("DO3", item->valueint);
item = cJSON_GetObjectItem(data, "DO4");
dtu_do_write_pin("DO4", item->valueint);
do1 = GpioGetLevel(DTU_GPIO_DO_PIN1);
do2 = GpioGetLevel(DTU_GPIO_DO_PIN2);
do3 = GpioGetLevel(DTU_GPIO_DO_PIN3);
do4 = GpioGetLevel(DTU_GPIO_DO_PIN4);
do5 = GpioGetLevel(DTU_GPIO_DO_PIN5);
//写入文件
dtu_trans_conf_file_write(dtu_file_ctx);
printf("DO1:%d, DO2:%d, DO3:%d, DO4:%d, DO5:%d", do1, do2, do3, do4, do5);
}
else
{
res = 1;
}
}
else
{
res = 1;
}
p_smsg.status = res;
dtu_json_task_send_msgq(&p_smsg);
}
21 dtu_do_json_set_do_value_res
回复服务器设置di值
/**
* Function : dtu_do_json_set_do_value_res
* Description : 回复服务器设置di值
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_do_json_set_do_value_res(UINT8 res)
{
cJSON *gdovr = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
gdovr = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(gdovr, "msgType", cJSON_CreateString("setDoValueRes"));
cJSON_AddItemToObject(gdovr, "data", cJSON_CreateNumber(res));
//申请内存
send = malloc(strlen(cJSON_Print(gdovr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdovr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gdovr);
}
22 dtu_do_json_get_do_config
发送消息给主任务,按照协议回复相应内容
/**
* Function : dtu_do_json_get_do_config
* Description : 发送消息给主任务,按照协议回复相应内容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_do_json_get_do_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID设置为对应ID
p_smsg.msgId = DTU_DO_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d \n", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}
23 dtu_do_json_get_do_config_res
回复服务器获取di配置
/**
* Function : dtu_do_json_get_do_config_res
* Description : 回复服务器获取di配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_do_json_get_do_config_res(void)
{
cJSON *gdocr = NULL;
cJSON *data = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//创建json对象
gdocr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(data, "enRpt1", cJSON_CreateNumber(dtu_file_ctx->doo.do1.do_type));
cJSON_AddItemToObject(data, "enRpt2", cJSON_CreateNumber(dtu_file_ctx->doo.do2.do_type));
cJSON_AddItemToObject(data, "enRpt3", cJSON_CreateNumber(dtu_file_ctx->doo.do3.do_type));
cJSON_AddItemToObject(data, "enRpt4", cJSON_CreateNumber(dtu_file_ctx->doo.do4.do_type));
cJSON_AddItemToObject(data, "enRpt5", cJSON_CreateNumber(dtu_file_ctx->doo.do5.do_type));
cJSON_AddItemToObject(data, "rptInterval1", cJSON_CreateNumber(dtu_file_ctx->doo.do1.do_interval));
cJSON_AddItemToObject(data, "rptInterval2", cJSON_CreateNumber(dtu_file_ctx->doo.do2.do_interval));
cJSON_AddItemToObject(data, "rptInterval3", cJSON_CreateNumber(dtu_file_ctx->doo.do3.do_interval));
cJSON_AddItemToObject(data, "rptInterval4", cJSON_CreateNumber(dtu_file_ctx->doo.do4.do_interval));
cJSON_AddItemToObject(data, "rptInterval5", cJSON_CreateNumber(dtu_file_ctx->doo.do5.do_interval));
cJSON_AddItemToObject(data, "rstStatus1", cJSON_CreateNumber(dtu_file_ctx->doo.do1.do_status));
cJSON_AddItemToObject(data, "rstStatus2", cJSON_CreateNumber(dtu_file_ctx->doo.do2.do_status));
cJSON_AddItemToObject(data, "rstStatus3", cJSON_CreateNumber(dtu_file_ctx->doo.do3.do_status));
cJSON_AddItemToObject(data, "rstStatus4", cJSON_CreateNumber(dtu_file_ctx->doo.do4.do_status));
cJSON_AddItemToObject(data, "rstStatus5", cJSON_CreateNumber(dtu_file_ctx->doo.do5.do_status));
// cJSON_AddItemToObject(data, "holdTime1", cJSON_CreateNumber(dtu_file_ctx->doo.do1.do_time));
// cJSON_AddItemToObject(data, "holdTime2", cJSON_CreateNumber(dtu_file_ctx->doo.do2.do_time));
// cJSON_AddItemToObject(data, "holdTime3", cJSON_CreateNumber(dtu_file_ctx->doo.do3.do_time));
// cJSON_AddItemToObject(data, "holdTime4", cJSON_CreateNumber(dtu_file_ctx->doo.do4.do_time));
// cJSON_AddItemToObject(data, "holdTime5", cJSON_CreateNumber(dtu_file_ctx->doo.do5.do_time));
// cJSON_AddItemToObject(data, "turnTime1", cJSON_CreateNumber(dtu_file_ctx->doo.do1.do_flip));
// cJSON_AddItemToObject(data, "turnTime2", cJSON_CreateNumber(dtu_file_ctx->doo.do2.do_flip));
// cJSON_AddItemToObject(data, "turnTime3", cJSON_CreateNumber(dtu_file_ctx->doo.do3.do_flip));
// cJSON_AddItemToObject(data, "turnTime4", cJSON_CreateNumber(dtu_file_ctx->doo.do4.do_flip));
// cJSON_AddItemToObject(data, "turnTime5", cJSON_CreateNumber(dtu_file_ctx->doo.do5.do_flip));
cJSON_AddItemToObject(gdocr, "msgType", cJSON_CreateString("getDoConfigRes"));
cJSON_AddItemToObject(gdocr, "data", data);
//申请内存
send = malloc(strlen(cJSON_Print(gdocr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdocr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gdocr);
}
24 dtu_do_json_set_do_config
设置do配置
/**
* Function : dtu_do_json_set_do_config
* Description : 设置do配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_do_json_set_do_config(int len , char *rcvdata)
{
UINT8 res = 0;
DTU_JSON_MSG_T p_smsg = {0};
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
cJSON * gdocg = NULL;
cJSON * data = NULL;
cJSON * item = NULL;
//获取对应模块的上下文指针
dtu_file_ctx = dtu_get_file_ctx();
//消息ID设置为对应ID
p_smsg.msgId = DTU_DO_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s\n", __FUNCTION__, rcvdata);
//解析数据
gdocg = cJSON_Parse(rcvdata);
if(NULL != gdocg)
{
data = cJSON_GetObjectItem(gdocg, "data");
if(NULL != data)
{
printf("data:%s",cJSON_Print(data));
item = cJSON_GetObjectItem(data, "enRpt1");
dtu_file_ctx->doo.do1.do_type = item->valueint;
item = cJSON_GetObjectItem(data, "rptInterval1");
dtu_file_ctx->doo.do1.do_interval = item->valueint;
item = cJSON_GetObjectItem(data, "rstStatus1");
dtu_file_ctx->doo.do1.do_status = item->valueint;
// item = cJSON_GetObjectItem(data, "holdTime1");
// dtu_file_ctx->doo.do1.do_time = item->valueint;
// item = cJSON_GetObjectItem(data, "turnTime1");
// dtu_file_ctx->doo.do1.do_flip = item->valueint;
item = cJSON_GetObjectItem(data, "enRpt2");
dtu_file_ctx->doo.do2.do_type = item->valueint;
item = cJSON_GetObjectItem(data, "rptInterval2");
dtu_file_ctx->doo.do2.do_interval = item->valueint;
item = cJSON_GetObjectItem(data, "rstStatus2");
dtu_file_ctx->doo.do2.do_status = item->valueint;
// item = cJSON_GetObjectItem(data, "holdTime2");
// dtu_file_ctx->doo.do2.do_time = item->valueint;
// item = cJSON_GetObjectItem(data, "turnTime2");
// dtu_file_ctx->doo.do2.do_flip = item->valueint;
item = cJSON_GetObjectItem(data, "enRpt3");
dtu_file_ctx->doo.do3.do_type = item->valueint;
item = cJSON_GetObjectItem(data, "rptInterval3");
dtu_file_ctx->doo.do3.do_interval = item->valueint;
item = cJSON_GetObjectItem(data, "rstStatus3");
dtu_file_ctx->doo.do3.do_status = item->valueint;
// item = cJSON_GetObjectItem(data, "holdTime3");
// dtu_file_ctx->doo.do3.do_time = item->valueint;
// item = cJSON_GetObjectItem(data, "turnTime3");
// dtu_file_ctx->doo.do3.do_flip = item->valueint;
item = cJSON_GetObjectItem(data, "enRpt4");
dtu_file_ctx->doo.do4.do_type = item->valueint;
item = cJSON_GetObjectItem(data, "rptInterval4");
dtu_file_ctx->doo.do4.do_interval = item->valueint;
item = cJSON_GetObjectItem(data, "rstStatus4");
dtu_file_ctx->doo.do4.do_status = item->valueint;
// item = cJSON_GetObjectItem(data, "holdTime4");
// dtu_file_ctx->doo.do4.do_time = item->valueint;
// item = cJSON_GetObjectItem(data, "turnTime4");
// dtu_file_ctx->doo.do4.do_flip = item->valueint;
item = cJSON_GetObjectItem(data, "enRpt5");
dtu_file_ctx->doo.do5.do_type = item->valueint;
item = cJSON_GetObjectItem(data, "rptInterval5");
dtu_file_ctx->doo.do5.do_interval = item->valueint;
item = cJSON_GetObjectItem(data, "rstStatus5");
dtu_file_ctx->doo.do5.do_status = item->valueint;
// item = cJSON_GetObjectItem(data, "holdTime5");
// dtu_file_ctx->doo.do5.do_time = item->valueint;
// item = cJSON_GetObjectItem(data, "turnTime5");
// dtu_file_ctx->doo.do5.do_flip = item->valueint;
if(DTU_DO_REPORT_INITIATIVE == dtu_file_ctx->doo.do1.do_type)
{
//开定时器
dtu_do1_report_timer_start(dtu_file_ctx->doo.do1.do_interval);
}
else if(DTU_DO_REPORT_NONE == dtu_file_ctx->doo.do1.do_type)
{
//关闭定时器
dtu_do1_report_timer_stop();
}
if(DTU_DO_REPORT_INITIATIVE == dtu_file_ctx->doo.do2.do_type)
{
//开定时器
dtu_do2_report_timer_start(dtu_file_ctx->doo.do2.do_interval);
}
else if(DTU_DO_REPORT_NONE == dtu_file_ctx->doo.do2.do_type)
{
//关闭定时器
dtu_do2_report_timer_stop();
}
if(DTU_DO_REPORT_INITIATIVE == dtu_file_ctx->doo.do3.do_type)
{
//开定时器
dtu_do3_report_timer_start(dtu_file_ctx->doo.do3.do_interval);
}
else if(DTU_DO_REPORT_NONE == dtu_file_ctx->doo.do3.do_type)
{
//关闭定时器
dtu_do3_report_timer_stop();
}
if(DTU_DO_REPORT_INITIATIVE == dtu_file_ctx->doo.do4.do_type)
{
//开定时器
dtu_do4_report_timer_start(dtu_file_ctx->doo.do4.do_interval);
}
else if(DTU_DO_REPORT_NONE == dtu_file_ctx->doo.do4.do_type)
{
//关闭定时器
dtu_do4_report_timer_stop();
}
if(DTU_DO_REPORT_INITIATIVE == dtu_file_ctx->doo.do5.do_type)
{
//开定时器
dtu_do5_report_timer_start(dtu_file_ctx->doo.do5.do_interval);
}
else if(DTU_DO_REPORT_NONE == dtu_file_ctx->doo.do5.do_type)
{
//关闭定时器
dtu_do5_report_timer_stop();
}
//写入文件
dtu_trans_conf_file_write(dtu_file_ctx);
printf("DO1:type %d, interval %d, status %d\r\n" \
"DO2:type %d, interval %d, status %d\r\n" \
"DO3:type %d, interval %d, status %d\r\n" \
"DO4:type %d, interval %d, status %d\r\n" \
"DO5:type %d, interval %d, status %d\r\n",
dtu_file_ctx->doo.do1.do_type,
dtu_file_ctx->doo.do1.do_interval,
dtu_file_ctx->doo.do1.do_status,
// dtu_file_ctx->doo.do1.do_time,
// dtu_file_ctx->doo.do1.do_flip,
dtu_file_ctx->doo.do2.do_type,
dtu_file_ctx->doo.do2.do_interval,
dtu_file_ctx->doo.do2.do_status,
// dtu_file_ctx->doo.do2.do_time,
// dtu_file_ctx->doo.do2.do_flip,
dtu_file_ctx->doo.do3.do_type,
dtu_file_ctx->doo.do3.do_interval,
dtu_file_ctx->doo.do3.do_status,
// dtu_file_ctx->doo.do3.do_time,
// dtu_file_ctx->doo.do3.do_flip,
dtu_file_ctx->doo.do4.do_type,
dtu_file_ctx->doo.do4.do_interval,
dtu_file_ctx->doo.do4.do_status,
// dtu_file_ctx->doo.do4.do_time,
// dtu_file_ctx->doo.do4.do_flip,
dtu_file_ctx->doo.do5.do_type,
dtu_file_ctx->doo.do5.do_interval,
dtu_file_ctx->doo.do5.do_status);
// dtu_file_ctx->doo.do5.do_time,
// dtu_file_ctx->doo.do5.do_flip);
}
else
{
res = 1;
}
}
else
{
res = 1;
}
p_smsg.status = res;
dtu_json_task_send_msgq(&p_smsg);
}
25 dtu_do_json_set_do_config_res
回复服务器设置do
/**
* Function : dtu_do_json_set_do_config_res
* Description : 回复服务器设置do
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_do_json_set_do_config_res(UINT8 res)
{
cJSON *gdocr = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
gdocr = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(gdocr, "msgType", cJSON_CreateString("setDoConfigRes"));
cJSON_AddItemToObject(gdocr, "data", cJSON_CreateNumber(res));
//申请内存
send = malloc(strlen(cJSON_Print(gdocr)));
if(NULL != gdocr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdocr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gdocr);
}
26 dtu_do_json_res
DO主动上报
/**
* Function : dtu_ai_json_get_ai_value
* Description : 发送消息给主任务,按照协议回复相应内容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_ai_json_get_ai_value(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID设置为对应ID
p_smsg.msgId = DTU_AI_MSG_ID_GET_VALUE_REPORT;
// printf("%s PIN4 status: %d \n", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}
27 dtu_ai_json_get_ai_value_res
回复服务器获取di值
/**
* Function : dtu_ai_json_get_ai_value_res
* Description : 回复服务器获取di值
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_ai_json_get_ai_value_res(void)
{
cJSON *gaivr = NULL;
cJSON *data = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
gaivr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(data, "AI1", cJSON_CreateNumber(SDK_READ_ADC_VALUE_NEW(0,1)));
cJSON_AddItemToObject(gaivr, "msgType", cJSON_CreateString("getAiValueRes"));
cJSON_AddItemToObject(gaivr, "data", data);
//申请内存
send = malloc(strlen(cJSON_Print(gaivr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gaivr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gaivr);
}
28 dtu_ai_json_get_ai_config
发送消息给主任务,按照协议回复相应内容
/**
* Function : dtu_ai_json_get_ai_config
* Description : 发送消息给主任务,按照协议回复相应内容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_ai_json_get_ai_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID设置为对应ID
p_smsg.msgId = DTU_AI_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d \n", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}
29 dtu_ai_json_get_ai_config_res
回复服务器获取di配置
/**
* Function : dtu_ai_json_get_ai_config_res
* Description : 回复服务器获取di配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_ai_json_get_ai_config_res(void)
{
cJSON *gaicr = NULL;
cJSON *data = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//创建json对象
gaicr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(data, "enRpt1", cJSON_CreateNumber(dtu_file_ctx->ai.ai_type));
cJSON_AddItemToObject(data, "cyc1", cJSON_CreateNumber(dtu_file_ctx->ai.ai_interval));
cJSON_AddItemToObject(data, "rptRule1", cJSON_CreateNumber(dtu_file_ctx->ai.ai_res_rule));
cJSON_AddItemToObject(data, "rptMin1", cJSON_CreateNumber(dtu_file_ctx->ai.ai_alarm_low));
cJSON_AddItemToObject(data, "rptMax1", cJSON_CreateNumber(dtu_file_ctx->ai.ai_alarm_high));
cJSON_AddItemToObject(gaicr, "msgType", cJSON_CreateString("getAiConfigRes"));
cJSON_AddItemToObject(gaicr, "data", data);
//申请内存
send = malloc(strlen(cJSON_Print(gaicr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gaicr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gaicr);
}
30 dtu_ai_json_set_ai_config
设置ai配置
/**
* Function : dtu_ai_json_set_ai_config
* Description : 设置ai配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_ai_json_set_ai_config(int len , char *rcvdata)
{
UINT8 res = 0;
DTU_JSON_MSG_T p_smsg = {0};
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
cJSON * gaicg = NULL;
cJSON * data = NULL;
cJSON * item = NULL;
//获取对应模块的上下文指针
dtu_file_ctx = dtu_get_file_ctx();
//消息ID设置为对应ID
p_smsg.msgId = DTU_AI_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s\n", __FUNCTION__, rcvdata);
//解析数据
gaicg = cJSON_Parse(rcvdata);
if(NULL != gaicg)
{
data = cJSON_GetObjectItem(gaicg, "data");
if(NULL != data)
{
printf("data:%s",cJSON_Print(data));
item = cJSON_GetObjectItem(data, "enRpt1");
dtu_file_ctx->ai.ai_type = item->valueint;
item = cJSON_GetObjectItem(data, "cyc1");
dtu_file_ctx->ai.ai_interval = item->valueint;
item = cJSON_GetObjectItem(data, "rptRule1");
dtu_file_ctx->ai.ai_res_rule = item->valueint;
item = cJSON_GetObjectItem(data, "rptMin1");
dtu_file_ctx->ai.ai_alarm_low = item->valueint;
item = cJSON_GetObjectItem(data, "rptMax1");
dtu_file_ctx->ai.ai_alarm_high = item->valueint;
// if(DTU_AI_REPORT_INITIATIVE == dtu_file_ctx->ai.ai_type)
// {
// //开定时器
// dtu_ai1_report_timer_start(dtu_file_ctx->di.di1.di_interval);
// }
// else if(DTU_AI_REPORT_NONE == dtu_file_ctx->ai.ai_type)
// {
// dtu_ai1_report_timer_stop();
// }
//写入文件
dtu_trans_conf_file_write(dtu_file_ctx);
printf("AI1:type %d, interval %d, rull %d, min %d, max %d\r\n",
dtu_file_ctx->ai.ai_type,
dtu_file_ctx->ai.ai_interval,
dtu_file_ctx->ai.ai_res_rule,
dtu_file_ctx->ai.ai_alarm_low,
dtu_file_ctx->ai.ai_alarm_high);
}
else
{
res = 1;
}
}
else
{
res = 1;
}
p_smsg.status = res;
dtu_json_task_send_msgq(&p_smsg);
}
31 dtu_ai_json_set_ai_config_res
回复服务器设置di值
/**
* Function : dtu_ai_json_set_ai_config_res
* Description : 回复服务器设置di值
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_ai_json_set_ai_config_res(UINT8 res)
{
cJSON *gaivr = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
gaivr = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(gaivr, "msgType", cJSON_CreateString("setAiConfigRes"));
cJSON_AddItemToObject(gaivr, "data", cJSON_CreateNumber(res));
//申请内存
send = malloc(strlen(cJSON_Print(gaivr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gaivr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gaivr);
}
32 dtu_ai_json_res
DI主动上报
/**
* Function : dtu_ai_json_res
* Description : DI主动上报
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_ai_json_res(void)
{
cJSON *gaivr = NULL;
cJSON *data = NULL;
char* send = NULL;
INT16 ul_adc_value = 0;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
gaivr = cJSON_CreateObject();
data = cJSON_CreateObject();
//获取adc值
ul_adc_value = SDK_READ_ADC_VALUE_NEW(0,1);
//按照协议,对象内加入成员
cJSON_AddItemToObject(data, "AI1", cJSON_CreateNumber(ul_adc_value));
cJSON_AddItemToObject(gaivr, "msgType", cJSON_CreateString("aiValueRpt"));
cJSON_AddItemToObject(gaivr, "data", data);
//申请内存
send = malloc(strlen(cJSON_Print(gaivr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gaivr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gaivr);
}
33 dtu_flow_json_get_flow_config
发送消息给主任务,按照协议回复相应内容
/**
* Function : dtu_flow_json_get_flow_config
* Description : 发送消息给主任务,按照协议回复相应内容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_flow_json_get_flow_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID设置为对应ID
p_smsg.msgId = DTU_FLOW_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d \n", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}
34 dtu_flow_json_get_flow_config_res
回复服务器获取flow配置
/**
* Function : dtu_flow_json_get_flow_config_res
* Description : 回复服务器获取flow配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_flow_json_get_flow_config_res(void)
{
cJSON *gfcr = NULL;
cJSON *data = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//创建json对象
gfcr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(data, "enHb", cJSON_CreateNumber(dtu_file_ctx->hb.heartflag));
cJSON_AddItemToObject(data, "cycHb", cJSON_CreateNumber(dtu_file_ctx->hb.hearttime));
cJSON_AddItemToObject(data, "hbPkg", cJSON_CreateString(dtu_file_ctx->hb.heart));
cJSON_AddItemToObject(data, "enReg", cJSON_CreateNumber(dtu_file_ctx->reg.linkflag));
cJSON_AddItemToObject(data, "regpkg", cJSON_CreateString(dtu_file_ctx->reg.link));
cJSON_AddItemToObject(gfcr, "msgType", cJSON_CreateString("getSysConfigRes"));
cJSON_AddItemToObject(gfcr, "data", data);
//申请内存
send = malloc(strlen(cJSON_Print(gfcr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gfcr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gfcr);
}
35 dtu_flow_json_set_flow_config
设置flow配置
/**
* Function : dtu_flow_json_set_flow_config
* Description : 设置flow配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_flow_json_set_flow_config(int len , char *rcvdata)
{
UINT8 res = 0;
DTU_JSON_MSG_T p_smsg = {0};
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
cJSON * gfcg = NULL;
cJSON * data = NULL;
cJSON * item = NULL;
//获取对应模块的上下文指针
dtu_file_ctx = dtu_get_file_ctx();
//消息ID设置为对应ID
p_smsg.msgId = DTU_FLOW_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s\n", __FUNCTION__, rcvdata);
//解析数据
gfcg = cJSON_Parse(rcvdata);
if(NULL != gfcg)
{
data = cJSON_GetObjectItem(gfcg, "data");
if(NULL != data)
{
printf("data:%s",cJSON_Print(data));
item = cJSON_GetObjectItem(data, "enHb");
dtu_file_ctx->hb.heartflag = item->valueint;
item = cJSON_GetObjectItem(data, "cycHb");
dtu_file_ctx->hb.hearttime = item->valueint;
item = cJSON_GetObjectItem(data, "hbPkg");
memset(dtu_file_ctx->hb.heart, 0, sizeof(dtu_file_ctx->hb.heart));
memcpy(dtu_file_ctx->hb.heart, item->valuestring, strlen(item->valuestring));
item = cJSON_GetObjectItem(data, "enReg");
dtu_file_ctx->reg.linkflag = item->valueint;
item = cJSON_GetObjectItem(data, "regpkg");
memset(dtu_file_ctx->reg.link, 0, sizeof(dtu_file_ctx->reg.link));
memcpy(dtu_file_ctx->reg.link, item->valuestring, strlen(item->valuestring));
if(1 == dtu_file_ctx->hb.heartflag)
{
//开始心跳定时器
}
else if(0 == dtu_file_ctx->hb.heartflag)
{
//关闭心跳定时器
}
//写入文件
dtu_trans_conf_file_write(dtu_file_ctx);
printf("enHb: %d, cycHb: %d, hbPkg: %s, enReg: %d, regpkg: %s\r\n",
dtu_file_ctx->hb.heartflag,
dtu_file_ctx->hb.hearttime,
dtu_file_ctx->hb.heart,
dtu_file_ctx->reg.linkflag,
dtu_file_ctx->reg.link);
}
else
{
res = 1;
}
}
else
{
res = 1;
}
p_smsg.status = res;
dtu_json_task_send_msgq(&p_smsg);
}
36 dtu_flow_json_set_flow_config_res
回复服务器设置flow
/**
* Function : dtu_flow_json_set_flow_config_res
* Description : 回复服务器设置flow
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_flow_json_set_flow_config_res(UINT8 res)
{
cJSON *gfcr = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
gfcr = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(gfcr, "msgType", cJSON_CreateString("setSysConfigRes"));
cJSON_AddItemToObject(gfcr, "data", cJSON_CreateNumber(res));
//申请内存
send = malloc(strlen(cJSON_Print(gfcr)));
if(NULL != gfcr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gfcr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gfcr);
}
37 dtu_clk_json_get_clk_config
发送消息给主任务,按照协议回复相应内容
/**
* Function : dtu_clk_json_clk_net_config
* Description : 发送消息给主任务,按照协议回复相应内容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_clk_json_get_clk_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID设置为对应ID
p_smsg.msgId = DTU_CLK_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d \n", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}
38 dtu_clk_json_get_clk_config_res
回复服务器获clk配置
/**
* Function : dtu_clk_json_get_clk_config_res
* Description : 回复服务器获clk配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_clk_json_get_clk_config_res(void)
{
cJSON *gclkcr = NULL;
cJSON *data = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//创建json对象
gclkcr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(data, "IP", cJSON_CreateString(dtu_file_ctx->socket.ip));
cJSON_AddItemToObject(data, "port", cJSON_CreateNumber(dtu_file_ctx->socket.port));
cJSON_AddItemToObject(data, "type", cJSON_CreateNumber(dtu_file_ctx->socket.type));
cJSON_AddItemToObject(gclkcr, "msgType", cJSON_CreateString("getClockConfigRes"));
cJSON_AddItemToObject(gclkcr, "data", data);
//申请内存
send = malloc(strlen(cJSON_Print(gclkcr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gclkcr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gclkcr);
}
39 dtu_clk_json_set_clk_config
设置网络配置
/**
* Function : dtu_clk_json_set_clk_config
* Description : 设置网络配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_clk_json_set_clk_config(int len , char *rcvdata)
{
UINT8 res = 0;
DTU_JSON_MSG_T p_smsg = {0};
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
cJSON * gclkcg = NULL;
cJSON * data = NULL;
cJSON * item = NULL;
//获取对应模块的上下文指针
dtu_file_ctx = dtu_get_file_ctx();
//消息ID设置为对应ID
p_smsg.msgId = DTU_CLK_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s\n", __FUNCTION__, rcvdata);
//解析数据
gclkcg = cJSON_Parse(rcvdata);
if(NULL != gclkcg)
{
data = cJSON_GetObjectItem(gclkcg, "data");
if(NULL != data)
{
printf("data:%s",cJSON_Print(data));
item = cJSON_GetObjectItem(data, "IP");
memset(dtu_file_ctx->socket.ip, 0, sizeof(dtu_file_ctx->socket.ip));
memcpy(dtu_file_ctx->socket.ip, item->valuestring, strlen(item->valuestring));
item = cJSON_GetObjectItem(data, "port");
dtu_file_ctx->socket.port = item->valueint;
item = cJSON_GetObjectItem(data, "type");
dtu_file_ctx->socket.type = item->valueint;
//写入文件
dtu_trans_conf_file_write(dtu_file_ctx);
printf("IP %s, port %d, type %d",
dtu_file_ctx->socket.ip,
dtu_file_ctx->socket.port,
dtu_file_ctx->socket.type);
}
else
{
res = 1;
}
}
else
{
res = 1;
}
p_smsg.status = res;
dtu_json_task_send_msgq(&p_smsg);
}
40 dtu_clk_json_set_clk_config_res
回复服务器设置clk
/**
* Function : dtu_clk_json_set_clk_config_res
* Description : 回复服务器设置clk
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_clk_json_set_clk_config_res(UINT8 res)
{
cJSON *gclkcr = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
gclkcr = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(gclkcr, "msgType", cJSON_CreateString("setClockConfigRes"));
cJSON_AddItemToObject(gclkcr, "data", cJSON_CreateNumber(res));
//申请内存
send = malloc(strlen(cJSON_Print(gclkcr)));
if(NULL != gclkcr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gclkcr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gclkcr);
}
41 dtu_fota_result_json_cbk
json ota 回调函数
/**
* Function : dtu_fota_result_json_cbk
* Description : json ota 回调函数
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_fota_result_json_cbk(UINT32 result)
{
// printf("%s: result = %ld",__FUNCTION__, result);
int res = 0;
cJSON *gota = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
if(result != FOTA_SUCCESS)
{
res = 1;
printf("Fota Error,Please try again!");
}
//创建json对象
gota = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(gota, "msgType", cJSON_CreateString("setOTAConfigRes"));
cJSON_AddItemToObject(gota, "data", cJSON_CreateNumber(res));
//申请内存
send = malloc(strlen(cJSON_Print(gota)));
if(NULL != gota)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gota); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//删除json对象
cJSON_Delete(gota);
if(result == FOTA_SUCCESS)
{
printf("Down Bin Ok! Moudle Rebooting For Update...");
sleep(1);
PM812_SW_RESET();// restart will update
}
}
42 dtu_ota_json_set_ota_config
设置ota参数
/**
* Function : dtu_ota_json_set_ota_config
* Description : 设置ota参数
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_ota_json_set_ota_config(int len , char *rcvdata)
{
UINT8 res = 0;
DTU_JSON_MSG_T p_smsg = {0};
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
cJSON * gclkcg = NULL;
cJSON * data = NULL;
cJSON * item = NULL;
//获取对应模块的上下文指针
dtu_file_ctx = dtu_get_file_ctx();
//消息ID设置为对应ID
p_smsg.msgId = DTU_OTA_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s\n", __FUNCTION__, rcvdata);
//解析数据
gclkcg = cJSON_Parse(rcvdata);
if(NULL != gclkcg)
{
data = cJSON_GetObjectItem(gclkcg, "data");
if(NULL != data)
{
printf("data:%s",cJSON_Print(data));
item = cJSON_GetObjectItem(data, "url");
printf("url:%s",item->valuestring);
SDK_MYFOTA_UPDATE(item->valuestring, "", "", dtu_fota_result_json_cbk, 20);
}
else
{
res = 1;
}
}
else
{
res = 1;
}
p_smsg.status = res;
dtu_json_task_send_msgq(&p_smsg);
}
43 dtu_modbus_json_get_modbus_config
服务器下发获取modbus配置
/**
* Function : dtu_modbus_json_get_modbus_config
* Description : 服务器下发获取modbus配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_modbus_json_get_modbus_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID设置为对应ID
p_smsg.msgId = DTU_MODBUS_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d \n", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}
44 dtu_modbus_json_get_modbus_config_res
回复服务器获取modbus配置
/**
* Function : dtu_modbus_json_get_modbus_config_res
* Description : 回复服务器获取modbus配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_modbus_json_get_modbus_config_res(void)
{
cJSON *gmdcr = NULL;
cJSON *data = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//创建json对象
gmdcr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(data, "enMb", cJSON_CreateNumber(dtu_file_ctx->modbus.config.type));
cJSON_AddItemToObject(data, "wait", cJSON_CreateNumber(dtu_file_ctx->modbus.config.wait));
cJSON_AddItemToObject(data, "interval", cJSON_CreateNumber(dtu_file_ctx->modbus.config.interval));
cJSON_AddItemToObject(data, "delay", cJSON_CreateNumber(dtu_file_ctx->modbus.config.delay));
cJSON_AddItemToObject(gmdcr, "msgType", cJSON_CreateString("getMbConfig"));
cJSON_AddItemToObject(gmdcr, "data", data);
//申请内存
send = malloc(strlen(cJSON_Print(gmdcr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gmdcr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
//释放内存
free(send);
}
//删除json对象
cJSON_Delete(gmdcr);
}
45 dtu_modbus_json_set_modbus_config
服务器下发设置modbus配置
/**
* Function : dtu_modbus_json_set_modbus_config
* Description : 服务器下发设置modbus配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_modbus_json_set_modbus_config(int len , char *rcvdata)
{
UINT8 res = 0;
DTU_JSON_MSG_T p_smsg = {0};
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
cJSON * smdcr = NULL;
cJSON * data = NULL;
cJSON * item = NULL;
//获取对应模块的上下文指针
dtu_file_ctx = dtu_get_file_ctx();
//消息ID设置为对应ID
p_smsg.msgId = DTU_MODBUS_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s\n", __FUNCTION__, rcvdata);
//解析数据
smdcr = cJSON_Parse(rcvdata);
if(NULL != smdcr)
{
data = cJSON_GetObjectItem(smdcr, "data");
if(NULL != data)
{
printf("data:%s",cJSON_Print(data));
item = cJSON_GetObjectItem(data, "enMb");
dtu_file_ctx->modbus.config.type = item->valueint;
item = cJSON_GetObjectItem(data, "wait");
dtu_file_ctx->modbus.config.wait = item->valueint;
item = cJSON_GetObjectItem(data, "interval");
dtu_file_ctx->modbus.config.interval = item->valueint;
item = cJSON_GetObjectItem(data, "delay");
dtu_file_ctx->modbus.config.delay = item->valueint;
if(0 == dtu_file_ctx->modbus.config.type)
{
//打开心跳
dtu_file_ctx->hb.heartflag = 1;
}
else
{
//关闭心跳
dtu_file_ctx->hb.heartflag = 0;
#ifdef DTU_TYPE_HTTP_INCLUDE
//关闭http
dtu_file_ctx->http.config.type = 0;
#endif /* ifdef DTU_TYPE_HTTP_INCLUDE.2023-10-12 10:38:15 by: zhaoning */
}
//写入文件
dtu_trans_conf_file_write(dtu_file_ctx);
printf("enMb %d, wait %d, interval %d, delay %d",
dtu_file_ctx->modbus.config.type,
dtu_file_ctx->modbus.config.wait,
dtu_file_ctx->modbus.config.interval,
dtu_file_ctx->modbus.config.delay);
}
else
{
res = 1;
}
}
else
{
res = 1;
}
p_smsg.status = res;
dtu_json_task_send_msgq(&p_smsg);
}
46 dtu_modbus_json_set_modbus_config_res
回复服务器设置modbus配置
/**
* Function : dtu_modbus_json_set_modbus_config_res
* Description : 回复服务器设置modbus配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_modbus_json_set_modbus_config_res(UINT8 res)
{
cJSON *smdcr = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
smdcr = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(smdcr, "msgType", cJSON_CreateString("setMbConfigRes"));
cJSON_AddItemToObject(smdcr, "data", cJSON_CreateNumber(res));
//申请内存
send = malloc(strlen(cJSON_Print(smdcr)));
if(NULL != smdcr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(smdcr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
//释放内存
free(send);
}
//删除json对象
cJSON_Delete(smdcr);
}
47 dtu_modbus_json_get_modbus_cmd
服务器获取modubs指令
/**
* Function : dtu_modbus_json_get_modbus_cmd
* Description : 服务器获取modubs指令
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_modbus_json_get_modbus_cmd(int len , char *rcvdata)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID设置为对应ID
p_smsg.msgId = DTU_MODBUS_MSG_ID_GET_CMD_REPORT;
// printf("%s PIN4 status: %d \n", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}
48 dtu_modbus_json_get_modbus_cmd_res
回复服务器获取modubs指令
/**
* Function : dtu_modbus_json_get_modbus_cmd_res
* Description : 回复服务器获取modubs指令
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_modbus_json_get_modbus_cmd_res(UINT8 id)
{
cJSON *gmdcr = NULL;
cJSON *data = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//创建json对象
gmdcr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(data, "active", cJSON_CreateNumber(dtu_file_ctx->modbus.cmd[id].active));
cJSON_AddItemToObject(data, "sAddr", cJSON_CreateNumber(dtu_file_ctx->modbus.cmd[id].slave_addr));
cJSON_AddItemToObject(data, "cmdType", cJSON_CreateNumber(dtu_file_ctx->modbus.cmd[id].fn));
cJSON_AddItemToObject(data, "regSaddr", cJSON_CreateNumber(dtu_file_ctx->modbus.cmd[id].reg_addr));
cJSON_AddItemToObject(data, "regNorD", cJSON_CreateNumber(dtu_file_ctx->modbus.cmd[id].reg_n_d));
cJSON_AddItemToObject(gmdcr, "msgType", cJSON_CreateString("gerMdCfgRes"));
cJSON_AddItemToObject(gmdcr, "data", data);
//申请内存
send = malloc(strlen(cJSON_Print(gmdcr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gmdcr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
//释放内存
free(send);
}
//删除json对象
cJSON_Delete(gmdcr);
}
49 dtu_modbus_json_get_modbus_cmdwn
服务器获取modubs指令
/**
* Function : dtu_modbus_json_get_modbus_cmdwn
* Description : 服务器获取modubs指令
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_modbus_json_get_modbus_cmdwn(int len , char *rcvdata)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID设置为对应ID
p_smsg.msgId = DTU_MODBUS_MSG_ID_GET_CMD_REPORT;
// printf("%s PIN4 status: %d \n", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}
50 dtu_modbus_json_get_modbus_cmdwn_res
回复服务器获取modubs指令
/**
* Function : dtu_modbus_json_get_modbus_cmdwn_res
* Description : 回复服务器获取modubs指令
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_modbus_json_get_modbus_cmdwn_res(UINT8 id)
{
cJSON *gmdcr = NULL;
cJSON *data = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//创建json对象
gmdcr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(data, "active", cJSON_CreateNumber(dtu_file_ctx->modbus.cmd_wn[id].active));
cJSON_AddItemToObject(data, "sAddr", cJSON_CreateNumber(dtu_file_ctx->modbus.cmd_wn[id].slave_addr));
cJSON_AddItemToObject(data, "cmdType", cJSON_CreateNumber(dtu_file_ctx->modbus.cmd_wn[id].fn));
cJSON_AddItemToObject(data, "regSaddr", cJSON_CreateNumber(dtu_file_ctx->modbus.cmd_wn[id].reg_addr));
cJSON_AddItemToObject(data, "regN", cJSON_CreateNumber(dtu_file_ctx->modbus.cmd_wn[id].reg_n));
// cJSON_AddItemToObject(data, "regData", cJSON_CreateString(dtu_file_ctx->modbus.cmd[id].reg_data));
cJSON_AddItemToObject(gmdcr, "msgType", cJSON_CreateString("getMdCmdWnRes"));
cJSON_AddItemToObject(gmdcr, "data", data);
//申请内存
send = malloc(strlen(cJSON_Print(gmdcr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gmdcr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
//释放内存
free(send);
}
//删除json对象
cJSON_Delete(gmdcr);
}
51 dtu_modbus_json_set_modbus_cmd
服务器下发设置modbus指令
/**
* Function : dtu_modbus_json_set_modbus_cmd
* Description : 服务器下发设置modbus指令
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_modbus_json_set_modbus_cmd(int len , char *rcvdata)
{
UINT8 res = 0;
DTU_JSON_MSG_T p_smsg = {0};
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
cJSON * smdc = NULL;
cJSON * data = NULL;
cJSON * item = NULL;
UINT8 id = 0;
//获取对应模块的上下文指针
dtu_file_ctx = dtu_get_file_ctx();
//消息ID设置为对应ID
p_smsg.msgId = DTU_MODBUS_MSG_ID_SET_CMD_REPORT;
// printf("%s %s\n", __FUNCTION__, rcvdata);
//解析数据
smdc = cJSON_Parse(rcvdata);
if(NULL != smdc)
{
data = cJSON_GetObjectItem(smdc, "data");
if(NULL != data)
{
printf("data:%s",cJSON_Print(data));
item = cJSON_GetObjectItem(data, "active");
dtu_file_ctx->modbus.cmd[id].active = item->valueint;
item = cJSON_GetObjectItem(data, "sAddr");
dtu_file_ctx->modbus.cmd[id].slave_addr = item->valueint;
item = cJSON_GetObjectItem(data, "cmdType");
dtu_file_ctx->modbus.cmd[id].fn = item->valueint;
item = cJSON_GetObjectItem(data, "regSaddr");
dtu_file_ctx->modbus.cmd[id].reg_addr = item->valueint;
item = cJSON_GetObjectItem(data, "regNorD");
dtu_file_ctx->modbus.cmd[id].reg_n_d = item->valueint;
item = cJSON_GetObjectItem(data, "regData");
//写入文件
dtu_trans_conf_file_write(dtu_file_ctx);
printf("IP %s, port %d, type %d",
dtu_file_ctx->socket.ip,
dtu_file_ctx->socket.port,
dtu_file_ctx->socket.type);
}
else
{
res = 1;
}
}
else
{
res = 1;
}
p_smsg.status = res;
dtu_json_task_send_msgq(&p_smsg);
}
52 dtu_modbus_json_set_modbus_cmd_res
回复服务器设置modbus指令
/**
* Function : dtu_modbus_json_set_modbus_cmd_res
* Description : 回复服务器设置modbus指令
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_modbus_json_set_modbus_cmd_res(UINT8 res)
{
cJSON *smdcr = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
smdcr = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(smdcr, "msgType", cJSON_CreateString("setMbCmdRes"));
cJSON_AddItemToObject(smdcr, "data", cJSON_CreateNumber(res));
//申请内存
send = malloc(strlen(cJSON_Print(smdcr)));
if(NULL != smdcr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(smdcr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
//释放内存
free(send);
}
//删除json对象
cJSON_Delete(smdcr);
}
53 dtu_modbus_json_set_modbus_cmdwn
服务器下发设置modbus指令
/**
* Function : dtu_modbus_json_set_modbus_cmdwn
* Description : 服务器下发设置modbus指令
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_modbus_json_set_modbus_cmdwn(int len , char *rcvdata)
{
UINT8 res = 0;
DTU_JSON_MSG_T p_smsg = {0};
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
cJSON * smdc = NULL;
cJSON * data = NULL;
cJSON * item = NULL;
UINT8 id = 0;
//获取对应模块的上下文指针
dtu_file_ctx = dtu_get_file_ctx();
//消息ID设置为对应ID
p_smsg.msgId = DTU_MODBUS_MSG_ID_SET_CMD_REPORT;
// printf("%s %s\n", __FUNCTION__, rcvdata);
//解析数据
smdc = cJSON_Parse(rcvdata);
if(NULL != smdc)
{
data = cJSON_GetObjectItem(smdc, "data");
if(NULL != data)
{
printf("data:%s",cJSON_Print(data));
item = cJSON_GetObjectItem(data, "active");
dtu_file_ctx->modbus.cmd_wn[id].active = item->valueint;
item = cJSON_GetObjectItem(data, "sAddr");
dtu_file_ctx->modbus.cmd_wn[id].slave_addr = item->valueint;
item = cJSON_GetObjectItem(data, "cmdType");
dtu_file_ctx->modbus.cmd_wn[id].fn = item->valueint;
item = cJSON_GetObjectItem(data, "regSaddr");
dtu_file_ctx->modbus.cmd_wn[id].reg_addr = item->valueint;
item = cJSON_GetObjectItem(data, "regN");
dtu_file_ctx->modbus.cmd_wn[id].reg_n = item->valueint;
item = cJSON_GetObjectItem(data, "regData");
memset(dtu_file_ctx->modbus.cmd_wn[id].reg_data, 0, sizeof(dtu_file_ctx->modbus.cmd_wn[id].reg_data));
memcpy(dtu_file_ctx->modbus.cmd_wn[id].reg_data, item->valuestring, strlen(item->valuestring));
//写入文件
dtu_trans_conf_file_write(dtu_file_ctx);
printf("IP %s, port %d, type %d",
dtu_file_ctx->socket.ip,
dtu_file_ctx->socket.port,
dtu_file_ctx->socket.type);
}
else
{
res = 1;
}
}
else
{
res = 1;
}
p_smsg.status = res;
dtu_json_task_send_msgq(&p_smsg);
}
54 dtu_modbus_json_set_modbus_cmdwn_res
回复服务器设置modbus指令
/**
* Function : dtu_modbus_json_set_modbus_cmdwn_res
* Description : 回复服务器设置modbus指令
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_modbus_json_set_modbus_cmdwn_res(UINT8 res)
{
cJSON *gclkcr = NULL;
char* send = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
//创建json对象
gclkcr = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(gclkcr, "msgType", cJSON_CreateString("setMbCmdWnRes"));
cJSON_AddItemToObject(gclkcr, "data", cJSON_CreateNumber(res));
//申请内存
send = malloc(strlen(cJSON_Print(gclkcr)));
if(NULL != gclkcr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gclkcr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
//释放内存
free(send);
}
//删除json对象
cJSON_Delete(gclkcr);
}
55 dtu_modbus_json_modbus_res
modbus模式下,配置为modbus上报后,调用此函数把hex转json
/**
* Function : dtu_modbus_json_modbus_res
* Description : modbus模式下,配置为modbus上报后,调用此函数把hex转json
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_modbus_json_modbus_res(UINT8* hex, UINT32 len)
{
cJSON *s01hr = NULL;
cJSON *data = NULL;
char* send = NULL;
char* asciistr = NULL;
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
//获取对应模块的上下文指针
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//创建json对象
s01hr = cJSON_CreateObject();
//按照协议,对象内加入成员
cJSON_AddItemToObject(s01hr, "msgType", cJSON_CreateString("rs485Rpt"));
if(len > DTU_MODBUS_RES_LEN / 2)
{
len = DTU_MODBUS_RES_LEN / 2;
}
//申请内存
asciistr = malloc(len * 2 + 1);
if(NULL != asciistr)
{
memset(asciistr, 0, len * 2 + 1);
utils_hex2ascii_str(asciistr, hex, len);
cJSON_AddItemToObject(s01hr, "data", cJSON_CreateString(asciistr));
//申请内存
send = malloc(strlen(cJSON_Print(s01hr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(s01hr); // 生成不带空格的JSON字符串
printf("send:%s",send);
//发送数据到服务器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
//释放内存
free(send);
}
}
//删除json对象
cJSON_Delete(s01hr);
}
56 dtu_json_task
json主任务
/**
* Function : dtu_json_task
* Description : json主任务
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_json_task(void *param)
{
OS_STATUS status;
DTU_JSON_MSG_T json_rcv_msg = {0};
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
dtu_file_ctx = dtu_get_file_ctx();
//获取对应模块的上下文指针
dtu_di_times_init();
dtu_di_int_init_all();
dtu_do_times_init();
dtu_do_init();
dtu_ai_times_init();
// dtu_ai1_report_timer_start(dtu_file_ctx->ai.ai_interval);
while(1)
{
status = OSAMsgQRecv(dtu_json_msgq, (void *)&json_rcv_msg, DTU_JSON_TASK_MSGQ_MSG_SIZE, OSA_SUSPEND);
if (status == OS_SUCCESS)
{
printf("%s: json_rcv_msg id: %d\n", __FUNCTION__, json_rcv_msg.msgId);
printf("%s: json_rcv_msg status: %d\n", __FUNCTION__, json_rcv_msg.status);
printf("%s: json_rcv_msg channel: %d\n", __FUNCTION__, json_rcv_msg.channel);
printf("%s: json_rcv_msg result: %d\n", __FUNCTION__, json_rcv_msg.result);
printf("%s: json_rcv_msg current: %d\n", __FUNCTION__, json_rcv_msg.current);
// printf("%s: json_rcv_msg value: %d\n", __FUNCTION__, json_rcv_msg.us_value);
switch(json_rcv_msg.msgId)
{
case DTU_SYS_MSG_ID_GET_CONFIG_REPORT:
dtu_sys_json_get_sys_config_res();
break;
case DTU_SYS_MSG_ID_SET_CONFIG_REPORT:
dtu_sys_json_set_sys_config_res(json_rcv_msg.status);
break;
case DTU_NET_MSG_ID_GET_CONFIG_REPORT:
dtu_net_json_get_net_config_res();
break;
case DTU_NET_MSG_ID_SET_CONFIG_REPORT:
dtu_net_json_set_net_config_res(json_rcv_msg.status);
break;
case DTU_DI_MSG_ID_DI_PROACTIVE_REPORT:
dtu_di_json_res(DTU_DI_REPORT_INTER, json_rcv_msg.channel, json_rcv_msg.status);
break;
case DTU_DI_MSG_ID_DI_TRIGGER_REPORT:
dtu_di_json_res(DTU_DI_REPORT_TRIG, json_rcv_msg.channel, json_rcv_msg.status);
break;
case DTU_DI_MSG_ID_GET_VALUE_REPORT:
dtu_di_json_get_di_value_res();
break;
case DTU_DI_MSG_ID_GET_CONFIG_REPORT:
dtu_di_json_get_di_config_res();
break;
case DTU_DI_MSG_ID_SET_CONFIG_REPORT:
dtu_di_json_set_di_config_res(json_rcv_msg.status);
break;
case DTU_DO_MSG_ID_DO_PROACTIVE_REPORT:
dtu_do_json_res( json_rcv_msg.channel, json_rcv_msg.status);
break;
case DTU_DO_MSG_ID_GET_VALUE_REPORT:
dtu_do_json_get_do_value_res();
break;
case DTU_DO_MSG_ID_GET_CONFIG_REPORT:
dtu_do_json_get_do_config_res();
break;
case DTU_DO_MSG_ID_SET_CONFIG_REPORT:
dtu_do_json_set_do_config_res(json_rcv_msg.status);
break;
case DTU_AI_MSG_ID_AI_PROACTIVE_REPORT:
dtu_ai_json_res();
break;
case DTU_AI_MSG_ID_GET_VALUE_REPORT:
dtu_ai_json_get_ai_value_res();
break;
case DTU_AI_MSG_ID_GET_CONFIG_REPORT:
dtu_ai_json_get_ai_config_res();
break;
case DTU_AI_MSG_ID_SET_CONFIG_REPORT:
dtu_ai_json_set_ai_config_res(json_rcv_msg.result);
break;
case DTU_FLOW_MSG_ID_GET_CONFIG_REPORT:
dtu_flow_json_get_flow_config_res();
break;
case DTU_FLOW_MSG_ID_SET_CONFIG_REPORT:
dtu_flow_json_set_flow_config_res(json_rcv_msg.status);
break;
case DTU_CLK_MSG_ID_GET_CONFIG_REPORT:
dtu_clk_json_get_clk_config_res();
break;
case DTU_CLK_MSG_ID_SET_CONFIG_REPORT:
dtu_clk_json_set_clk_config_res(json_rcv_msg.status);
break;
#ifdef DTU_TYPE_MODBUS_INCLUDE
case DTU_MODBUS_MSG_ID_GET_CONFIG_REPORT:
dtu_modbus_json_get_modbus_config_res();
break;
case DTU_MODBUS_MSG_ID_SET_CONFIG_REPORT:
dtu_modbus_json_set_modbus_config_res(json_rcv_msg.status);
break;
case DTU_MODBUS_MSG_ID_GET_CMD_REPORT:
dtu_modbus_json_get_modbus_cmd_res(json_rcv_msg.channel);
break;
case DTU_MODBUS_MSG_ID_SET_CMD_REPORT:
dtu_modbus_json_set_modbus_cmd_res(json_rcv_msg.status);
break;
#endif /* ifdef DTU_TYPE_MODBUS_INCLUDE.2023-10-10 11:08:46 by: zhaoning */
#ifdef DTU_TYPE_HTTP_INCLUDE
case DTU_HTTP_MSG_ID_GET_CONFIG_REPORT:
dtu_http_json_get_http_config_res();
break;
case DTU_HTTP_MSG_ID_SET_CONFIG_REPORT:
dtu_http_json_set_http_config_res(json_rcv_msg.status);
break;
case DTU_HTTP_MSG_ID_GET_CMD_REPORT:
dtu_http_json_get_http_cmd_res();
break;
case DTU_HTTP_MSG_ID_SET_CMD_REPORT:
dtu_http_json_set_http_cmd_res(json_rcv_msg.status);
break;
#endif /* ifdef DTU_TYPE_HTTP_INCLUDE.2023-10-10 11:09:21 by: zhaoning */
default:
break;
}
}
// if (json_rcv_msg.data)
// {
// free(json_rcv_msg.data);
// json_rcv_msg.data = NULL;
// }
}
}
57 dtu_di_task_init
di主任务和消息队列创建
/**
* Function : dtu_di_task_init
* Description : di主任务和消息队列创建
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_json_task_init(void)
{
OSA_STATUS status = 0;
/*creat message*/
status = OSAMsgQCreate(&dtu_json_msgq, "dtu_json_msgq", DTU_JSON_TASK_MSGQ_MSG_SIZE, DTU_JSON_TASK_MSGQ_QUEUE_SIZE, OS_FIFO);
ASSERT(status == OS_SUCCESS);
//创建DI任务
status = OSATaskCreate(&dtu_json_task_ref, dtu_json_task_stack, DTU_JSON_TASK_STACK_SIZE, 161, "json_task", dtu_json_task, NULL);
ASSERT(status == OS_SUCCESS);
}
4 Demo实战
4.1 创建一个Demo
复制20.9_di_xtu示例工程,到同一个文件夹下,修改文件名为20.12_json_xtu,如图:
4.2 修改makefile
增加文件组件所在目录头文件路径,和源文件路径,以及一些宏定义,如图:
-D是makefile中定义宏定义必要的前缀,可以搜索相关makefile学习文章学习相关知识。
DTU_BASED_ON_TCP 表示当前是TCP模式,当前组件使用需要am.h中包含一些对应。
DTU_TYPE_5X6 表示使用SOM板贴片5x6卡,可以使用其它卡,修改为对应宏定义就可以。
DTU_UART_115200_BAUD 表示使用115200波特率
DTU_TYPE_JSON_INCLUDE 表示把JSON功能包含进来
4.3 增加头文件
使用代码编辑器,将新建的工程文件加入代码编辑器中,打开main.c,修改main.c,加入am.h头文件,如图:
4.4 修改代码
示例使用的是板载5x6卡,用户的硬件可能是使用外置卡,或者是三合一全网通卡,因为硬件上三种卡使用的模组SIM卡接口不一样(外置卡SIM1,5x6卡和三合一卡SIM2),所以,需要通过一个全局变量来制定SIM卡硬件接口。
extern外部变量SDK_INIT_SIM_SELECT_VALUE,这里判断了是否使用外置卡,这个宏定义在Makefile里面定义。
在Phase1Inits_enter中,宏定义判断是否要包含对SDK_INIT_SIM_SELECT_VALUE变量的修改。
在Phase2Inits_exit 调用文件组件提供的对外API,如图:
4.5 编译
在SDK根目录打开命令行,输入命令.\build.bat -l .\amaziot_bloom_os_sdk\sample\libraries\20.12_json_xtu\
PS F:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08
λ .\build.bat -l .\amaziot_bloom_os_sdk\sample\libraries\20.12_json_xtu\
子目录或文件 out\bin 已经存在。
子目录或文件 build\cJSON 已经存在。
子目录或文件 build\obj 已经存在。
gnumake: Entering directory `F:/3.asr-b/cat.1-asr1606/1.software/BLOOM_OS_1606_OPENCPU_1191_A08/amaziot_bloom_os_sdk/sample/libraries/20.12_json_xtu'
armcc.exe -c --cpu Cortex-R4 --no_unaligned_access -g -O2 --apcs /inter --diag_suppress 2084,1,2,177,188,223,550,1296,2795,6319,9931,9933 --diag_error=warning --gnu --thumb --loose_implicit_cast -DDATA_COLLECTOR_IMPL -DISPT_OVER_SSP -DDIAG_SSP_DOUBLE_BUFFER_USE_DYNAMIC_ALLOCATION -DENV_XSCALE -DL1_DCXO_ENABLED -DLTE_HIGH_MOBILITY_OPTIMIZATION -DRUN_XIP_MODE -DCRANE_Z2 -DCA_LONG_IPC_MSG -DNEZHA3 -DNEZHA3_1826 -DUPGRADE_PLMS -DUPGRADE_PLMS_SR -DLTE_GSMMULTIBCCH -DGPLC_LTE_RSSI_SCAN -DL1V_NEW_RSSI -DUPGRADE_PLMS_3G -DUPGRADE_PLMS_L1 -DUPGRADE_FG_PLMS -DFG_PLMS_URR -DUPGRADE_L1A_FG_PLMS -DUPGRADE_PLMS_STAGE_2 -DUPGRADE_MBCCH -DMULTI_BCCH_READY_IND -DURR_MRAT_ICS_SEARCH -DUPGRADE_ICS -DMRAT_NAS -DUPGRADE_PLMS_SEARCH_API -DICS_MBCCH -DICS_MBCCH_2G_RSSI -DDIAG_NEWPP -DPHS_SW_DEMO -DPHS_SW_DEMO_TTC -DPHS_SW_DEMO_TTC_PM -DFULL_SYSTEM -D_DDR_INIT_ -D_TAVOR_HARBELL_ -DUPGRADE_ARBEL_PLATFORM -D_TAVOR_B0_SILICON_ -DTDL1C_SPY_ENABLE -DDLM_TAVOR -DTAVOR -DFLAVOR_DUALCORE -DDEBUG_D2_MOR_REG_RESEREVED_ENABLE -D_DIAG_USE_COMMSTACK_ -D_TAVOR_DIAG_ -DPM_DEBUG_MODE_ENABLED -DPM_D2FULL_MODE -DPM_EXT_DBG_INT_ARR -DFEATURE_WB_AMR_PS -DMACRO_FOR_LWG -DHL_LWG -DOPTIMIZE_FOR_2G_BCCH -DPLAT_TEST -D_FDI_USE_OSA_ -DPLAT_USE_THREADX -DLWIP_IPNETBUF_SUPPORT -DCRANE_MCU_DONGLE -DAT_OVER_UART -DPHS_SW_DEMO_TTC_PM -DUPGRADE_LTE_ONLY -DEXT_AT_MODEM_SUPPORT -DLTEONLY_THIN_SINGLE_SIM -DLFS_FILE_SYS -DLFS_FILE_SYS_V2 -DPSM_ENABLE -DNO_PAHO_MQTT -DNO_XML -DNO_LWM2M -DREMOVE_MBEDTLS -DNO_AT_NET -DCRANE_SD_NOT_SUPPORT -DNTP -DYMODEM_EEH_DUMP -DENABLE_DM_LTEONLY -DLTEONLY_THIN -DNO_EXTEND_MY_Q_AT -DNOT_SUPPORT_HTTPS -DNOT_SUPPORT_PM813 -DCRANEL_4MRAM -DREMOVE_PB -DUART_NEW_VERSION -DREMOVE_MEP -DREMOVE_SMS -DREMOVE_ENVSIM -DAPN_INCODE -DLTEONLY_THIN_SINGLE_SIM_2MFLASH -DASR160X_OPENCPU_FEATURE -DENABLE_UART3_FEATRUE -DENABLE_UART4_FEATRUE -DYUGE_MBEDTLS_3_2_1 -DENABLE_MAC_TX_DATA_LOGGING -DDISABLE_NVRAM_ACCESS -DINTEL_UPGRADE_EE_HANDLER_SUPPORT -DLTE_W_PS -DL1_DUAL_MODE -DUPGRADE_HERMON_DUAL -DINTEL_UPGRADE_DUAL_RAT -DINTEL_UPGRADE_GPRS_CIPHER_FLUSH -DUPGRADE_ENHANCED_QUAD_BAND -DINTEL_2CHIP_PLAT -DI_2CHIP_PLAT -DUPGRDE_TAVOR_COMMUNICATION -DRUN_WIRELESS_MODEM -DFLAVOR_DDR12MB_GB1MB5 -DFEATURE_SHMEM -DACIPC_ENABLE_NEW_CALLBACK_MECHANISM -DRELIABLE_DATA -DMAP_NSS -DTV_FNAME="\"SW_PLATFORM=PMD2NONE PHS_SW_DEMO PHS_SW_DEMO_PM SRCNUCLEUS FULL_SYSTEM NOACRTC PDFLT PLAT_TEST PV2 DIAGOSHMEM NVM WITHL1V\"" -DTV_FDESC="\"SW_DESCRIPTION=\"" -DENABLE_ACIPC -D_DATAOMSL_ENABLED_ -DUSB_CABLE_DETECTION_VIA_PMIC -DMIPS_TEST -DMIPS_TEST_RAM -DFLAVOR_DIET_RAM -DNVM_INCLUDE -DMSL_INCLUDE -DMSL_POOL_MEM -DNO_AUDIO -DOSA_QUEUE_NAMES -D_DIAG_DISABLE_USB_ -DOSA_NUCLEUS -DOSA_USED -DPM_D2NONE_MODE -DCRANE_SOC_TEMPERATURE_SENSOR -DL1_SW_UPDATE_FOR_DIGRF -DPHS_L1_SW_UPDATE_R7 -DUPGRADE_LTE -DFRBD_CALIB_NVM -DFRBD_AGC_CALIB -DFRBD_FDT_CALIB -DHSPA_MPR -DCAPT_PARAMS_OPTIMIZE -DL1_WB_R99_ONLY -DL1V_WB_R99_ONLY -DINTERGRATED_RF_SUPPORT -DL1_RX_DIV_SUPPORT -DENABLE_OOS_HANDLING -DTAVOR_D2_WB_L1_SUPPORT -DL1_DDR_HIGH_FREQ -DUPGRADE_DIGRF3G_SUPPORT -DW_PS_PLUS_G_PAGING -D"NO_APLP=0" -DINTEL_UPGRADE_UNIFIED_VOICE_TASK -DINTEL_UPGRADE_R99 -DAPLP_SPY_ENABLE -D__TARGET_FEATURE_DOUBLEWORD -DWHOLE_UMTS_STACK -DUSE_TTPCOM_CSR_BLUETOOTH_AUDIO_GAIN_CONTROL -DL1_UPGRADE_R5 -DUPGRADE_EDGE -DUPGRADE_R4_FS1 -DINTEL_UPGRADE_GSM_CRL_IF -DUPGRADE_EGPRS_M -DINTEL_UPGRADE_EGPRS_M -DINTEL_UPGRADE_RF_PARAMS_IN_CF_TDS -DINTEL_UPGRADE_2SAMPLES_PER_SYMBOL -D"GPRS_MULTISLOT_CLASS=12" -D"EGPRS_MULTISLOT_CLASS=12" -DMARVELL_UPGRADE_BSIC_REDESIGN -DMSL_INCLUDE -DINTEL_HERMON_SAC -DCRANE_CUST_BUILD -DL1_SW_UPDATE_FOR_DIGRF -DFLAVOR_COM -DSILICON_PV2 -DSILICON_SEAGULL -DSILICON_TTC_CORE_SEAGULL -DPCAC_INCLUDE -Otime -DBUILD_DATE="\"11 22 2023\"" -DBUILD_TIME="\"10:48:29\"" -Iatcmds\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\telephony\yuge\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hal\UART\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hal\core\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hal\PMU\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hal\GPIO\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\os\posix\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\diag\diag_logic\src -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\csw\SysCfg\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\csw\platform\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\env\win32\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\csw\BSP\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\csw\platform\dev_plat\build -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\os\osa\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\os\threadx\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\os\nu_xscale\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\psm\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\httpclient\src -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\diag\diag_logic\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\timer\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\intc\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\csw\PM\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\pm\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\softutil\TickManager\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\BSP\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\telephony\atcmdsrv\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\telephony\atparser\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\telephony\sdk\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\httpclient\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\ci\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\lwipv4v6\src\include -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\lwipv4v6\src\include\arch -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\lwipv4v6\src\include\ipv4 -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\lwipv4v6\src\include\ipv6 -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\lwipv4v6\src\include\lwip -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\lwipv4v6\src\include\netif -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\mmi_mat\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\tavor\Arbel\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\tavor\env\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\telephony\modem\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\duster\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\fota\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hal\I2C\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hal\ACIPC\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\softutil\fatsys\flash -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\softutil\FDI\src\INCLUDE -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hal\MMU\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\softutil\FDI\src\FDI_ADD -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\softutil\FDI\src\FM_INC -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\softutil\fatsys\fs\hdr -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\softutil\littlefs\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\tts\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\dial\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\softutil\csw_memory\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\utilities\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\commpm\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\softutil\nvm\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\softutil\EEhandler\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\softutil\EEhandler\src -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\RTC\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\telephony\ci_client\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hal\BT_device\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hal\UART\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\mrd\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\dma\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\softutil\softutil\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hal\SPI\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\websocket\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\atnet_srv\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\softutil\fotacomm\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\aud_sw\Audio\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\aud_sw\ACM_COMM\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\aud_sw\audio_stub\src -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop\aam\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\aud_sw\AudioHAL\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hal\dbgshell\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\pcac\opencpu\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\amaziot_bloom_os_sdk\utils -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\CSDK_CODE\cJSON\inc -IF:/3.asr-b/cat.1-asr1606/1.software/BLOOM_OS_1606_OPENCPU_1191_A08/amaziot_bloom_os_sdk/sample/libraries/20.12_json_xtu\am\inc -IF:/3.asr-b/cat.1-asr1606/1.software/BLOOM_OS_1606_OPENCPU_1191_A08/amaziot_bloom_os_sdk/sample/libraries/20.12_json_xtu\atcmds\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08/amaziot_bloom_os_sdk/libraries\am\xtu -DDTU_BASED_ON_TCP -DDTU_TYPE_5X6 -DDTU_UART_115200_BAUD -DDTU_TYPE_DODIAI_INCLUDE -DDTU_TYPE_JSON_INCLUDE -o build\obj/ext_at_cmds.o F:/3.asr-b/cat.1-asr1606/1.software/BLOOM_OS_1606_OPENCPU_1191_A08/amaziot_bloom_os_sdk/sample/libraries/20.12_json_xtu/atcmds/src/ext_at_cmds.c
armlink.exe build\obj/main.o build\obj/ext_at_cmds.o build\obj/ext_at_controller.o build\obj/am_file.o build\obj/am_at.o build\obj/am_trans.o build\obj/am_hb.o build\obj/am_di.o build\obj/am_do.o build\obj/am_ai.o build\obj/am_clock.o build\obj/am_json.o build\obj/am_socket.o build\CSDK_CODE.lib \
-o F:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\out\bin\Arbel_PMD2NONE_40M.axf \
--via F:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\prebuilt_1606l\Arbel_PMD2NONE_targ_objliblist.txt \
--elf \
--scatter F:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\prebuilt_1606l\Crane_DS_4M_Ram_2M_Flash_XIP_CIPSRAM_Common_SingleSIM.sct \
--predefine="-DLTEONLY_THIN_SINGLE_SIM" --map --symbols --info sizes,totals \
--list F:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\out\bin\Arbel_PMD2NONE_40M.map \
--keep init.o(Header) --keep init.o(Vectors) --diag_suppress 6312,6314,6319,6329 \
--feedback F:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\out\feedbackLinkOptLteonlyThin_SingleSim_NoSMS.txt
F:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\tools\buildimage_1606l.bat
SDK_PROD_TYPE : [DM]
SDK_CUST_SKU : [THIN_SINGLE_SIM_NO_SMS]
SDK_PS_MODE : [LTEONLY]
SDK_CHIP_VER : [Z2A0]
SDK_OS_TYPE : [TX]
Platform Convertion Tools v4.01 with PS option extension
Convertion done!
|INPUT |out\bin\cp_1606L.bin
|MARK |NAME |EXEADDR .LOADADDR.LENGTH .CPZLADDR|COMPRESS STASTIC |
|--------|--------|--------.--------.--------.--------|------------------------------|
|This Is LteOnly 4M|
|RW_CPZ_1|DDR_RW_ |7e11c000.8006cd70.0000d40c.8006d000|0000d40c->00003000
|This Is LteOnly 4M|
|RW_CPZ_2|PS_NCAH |7e388000.8007a17c.00001300.80070000|00001300->00001000
|This Is LteOnly 4M|
|RW_CPZ_3|ITCM |7e3dac00.8007b47c.0000f51c.80071000|0000f51c->0000a000
|This Is LteOnly 4M|
|RW_CPZ_4|CODE_PS |7e1ad000.8008a998.0002fcdc.8007b000|0002fcdc->0001e000
|This Is LteOnly 4M|
|RW_CPZ_5|CODEPSB |7e1df000.800ba674.000339c0.80099000|000339c0->0001b000
|This Is LteOnly 4M|
|RW_CPZ_6|CODEPSC |7e216000.800ee034.000323ec.800b4000|000323ec->0001b000
|This Is LteOnly 4M|
|RW_CPZ_7|CODEPSD |7e24c000.80120420.00028d88.800cf000|00028d88->0001a000
|This Is LteOnly 4M|
|RW_CPZ_8|CODEPSE |7e27a000.801491a8.0002e310.800e9000|0002e310->0001a000
|This Is LteOnly 4M|
|RW_CPZ_9|CODEPSF |7e2ac000.801774b8.0001c948.80103000|0001c948->00011000
|This Is LteOnly 4M|
|RW_CPZ_A|CODE_PL |7e2cd000.80193e00.0002f914.80114000|0002f914->0001e000
|This Is LteOnly 4M|
|RW_CPZ_B|CODEPLB |7e2fd000.801c3714.00038d38.80132000|00038d38->00021000
|This Is LteOnly 4M|
|RW_CPZ_C|CODEPLC |7e337000.801fc44c.000268d4.80153000|000268d4->00012000
|--------|--------|--------.--------.--------.--------|------------------------------|
| | 0x0020bd20 -> 0x0014e000|
| | 2.046(MB) -> 1.305(MB)|
|------------------------------------------------------------------------------------|
cp_1606L.axf
cp_1606L.bin
cp_1606L.map
gnumake: Leaving directory `F:/3.asr-b/cat.1-asr1606/1.software/BLOOM_OS_1606_OPENCPU_1191_A08/amaziot_bloom_os_sdk/sample/libraries/20.12_json_xtu'
"copy NEZHAC_CP_CNR_MIFI_TX.bin to ./ "
已复制 1 个文件。
4.6 生成固件
参考入门中开发工具,生成工具。
4.7 查看现象
固件下载到模组后,配置服务器地址,之后按照Json协议下发数据测试,
5 总结
根据实验现象,用户需要实现自己的AT指令,只需要参考组件中的例子,按照自己需求修改,
04
获取更多知识
本文章源自奇迹物联开源的物联网应用知识库Cellular IoT Wiki,更多技术干货欢迎关注收藏Wiki。
欢迎同学们走进AmazIOT知识库的世界!
这里是为物联网人构建的技术应用百科,以便帮助你更快更简单的开发物联网产品。
Cellular IoT Wiki初心:
在我们长期投身于蜂窝物联网 ODM/OEM 解决方案的实践过程中,一直被物联网技术碎片化与产业资源碎片化的问题所困扰。从产品定义、芯片选型,到软硬件研发和测试,物联网技术的碎片化以及产业资源的碎片化,始终对团队的产品开发交付质量和效率形成制约。为了减少因物联网碎片化而带来的重复开发工作,我们着手对物联网开发中高频应用的技术知识进行沉淀管理,并基于 Bloom OS 搭建了不同平台的 RTOS 应用生态。后来我们发现,很多物联网产品开发团队都面临着相似的困扰,于是,我们决定向全体物联网行业开发者开放奇迹物联内部沉淀的应用技术知识库 Wiki,期望能为更多物联网产品开发者减轻一些重复造轮子的负担。
Cellular IoT Wiki沉淀的技术内容方向如下:
奇迹物联的业务服务范围:基于自研的NB-IoT、Cat1、Cat4等物联网模组,为客户物联网ODM/OEM解决方案服务。我们的研发技术中心在石家庄,PCBA生产基地分布在深圳、石家庄、北京三个工厂,满足不同区域&不同量产规模&不同产品开发阶段的生产制造任务。跟传统PCBA工厂最大的区别是我们只服务物联网行业客户。
连接我们,和10000+物联网开发者一起 降低技术和成本门槛
让蜂窝物联网应用更简单~~
注:本文部分内容来源于网络,如有侵权,请及时联系我们。
更多推荐
所有评论(0)