|
點(diǎn)擊左上方藍(lán)色“一口Linux”,選擇“設(shè)為星標(biāo)”
第一時(shí)間看干貨文章
?【干貨】嵌入式驅(qū)動(dòng)工程師學(xué)習(xí)路線?【干貨】Linux嵌入式知識(shí)點(diǎn)-思維導(dǎo)圖-免費(fèi)獲取?【就業(yè)】一個(gè)可以寫到簡歷的基于Linux物聯(lián)網(wǎng)綜合項(xiàng)目?【就業(yè)】找工作簡歷模版
bpdlyoqjbf16405962205.gif (555.24 KB, 下載次數(shù): 7)
下載附件
保存到相冊
bpdlyoqjbf16405962205.gif
2024-9-26 06:49 上傳
作者:AmazIOT一 概述1.1 什么是 JSONJSON是JavaScript Object Notation的簡稱,中文含義為“JavaScript 對象表示法”,它是一種數(shù)據(jù)交換的文本格式,而不是一種編程語言。
JSON 是一種輕量級(jí)的數(shù)據(jù)交換格式,它基于 ECMAScript (w3c制定的js規(guī)范)的一個(gè)子集,采用完全獨(dú)立于編程語言的文本格式來存儲(chǔ)和表示數(shù)據(jù)。簡潔和清晰的層次結(jié)構(gòu)使得 JSON 成為理想的數(shù)據(jù)交換語言。
JSON之所以受歡迎,主要是因?yàn)樗匀皇褂?JavaScript 語法來描述數(shù)據(jù)對象,并沒有改變開發(fā)人員的使用習(xí)慣,這更容易被開發(fā)人員接受。由于這種相似性,JavaScript 程序就無需解析器,便可以直接用 JSON 數(shù)據(jù)來生成原生的 JavaScript 對象。
1.2 JSON 的特點(diǎn)JSON 主要具有以下特性,這些特性使它成為理想的數(shù)據(jù)交換語言:
JSON 是輕量級(jí)的文本數(shù)據(jù)交換格式
JSON 具有自我描述性,更易理解
JSON 采用完全獨(dú)立于語言的文本格式:JSON 使用 JavaScript 語法來描述數(shù)據(jù)對象,但是 JSON 仍然獨(dú)立于語言和平臺(tái)。JSON 解析器和 JSON 庫支持許多不同的編程語言。目前常見的動(dòng)態(tài)編程語言(PHP,JSP,.NET)都支持JSON。
JSON 是存儲(chǔ)和交換文本信息的一種語法,它與XML具有相同的特性,是一種數(shù)據(jù)存儲(chǔ)格式,卻比 XML 更小、更快、 更易于人編寫和閱讀、更易于生成和解析。
類似于 XML 的特性:
JSON 是純文本
JSON 具有“自我描述性”(人類可讀)
JSON 具有層級(jí)結(jié)構(gòu)(值中存在值)
JSON 可通過 JavaScript 進(jìn)行解析
JSON 數(shù)據(jù)可使用 AJAX 進(jìn)行傳輸
相比 XML 的不同之處:
沒有結(jié)束標(biāo)簽
更短
讀寫的速度更快
能夠使用內(nèi)建的 JavaScript eval() 方法進(jìn)行解析
使用數(shù)組
不使用保留字
二 JSON語法在 JavaScript 語言中,一切皆對象。任何支持的類型,如字符串、數(shù)值、對象、數(shù)組等,都可以通過 JSON 來表示。
JSON 語法是 JavaScript 對象表示法的子集:
數(shù)據(jù)在鍵/值對中,鍵/值對可以嵌套
數(shù)據(jù)由逗號(hào)分隔
花括號(hào)保存對象,對象可以包含多個(gè)鍵/值對
方括號(hào)保存數(shù)組,數(shù)組可以包含多個(gè)對象
JSON不是JavaScript語句,對象的末尾沒有分號(hào),對象和數(shù)組的最后一個(gè)成員后面,也不能加逗號(hào)。
2.1 JSON 鍵/值對JSON鍵/值對由鍵和值組成,鍵必須是字符串,值可以是字符串(string)、數(shù)值(number) 、對象(object)、數(shù)組(array)、true、false、 null。如圖所示:
c2rowuem0h56405962305.png (6.2 KB, 下載次數(shù): 9)
下載附件
保存到相冊
c2rowuem0h56405962305.png
2024-9-26 06:49 上傳
在定義JSON鍵/值時(shí),先是鍵名,后面寫一個(gè)冒號(hào),然后是值。如:
"github": "https://github.com/leiqikui"
這就等價(jià)于這條 JavaScript 語句:
github = "https://github.com/leiqikui"
2.2 JSON 字符串JSON 的字符串(string)跟C或者Java的字符串非常相似,是由雙引號(hào)包圍的任意數(shù)量Unicode字符的集合,使用反斜線轉(zhuǎn)義。如圖所示:
allobexjdid6405962406.png (15.2 KB, 下載次數(shù): 7)
下載附件
保存到相冊
allobexjdid6405962406.png
2024-9-26 06:49 上傳
由于JSON 字符串不能使用單引號(hào),因此一個(gè)字符(character)就是一個(gè)單獨(dú)的字符串(character string)。
2.3 JSON 數(shù)值JSON 數(shù)值(number)與C或者Java的數(shù)值非常相似,支持整型、浮點(diǎn)型,浮點(diǎn)型也可以用指數(shù)表示。如圖所示:
ybhsqjcxpbh6405962506.png (9.27 KB, 下載次數(shù): 8)
下載附件
保存到相冊
ybhsqjcxpbh6405962506.png
2024-9-26 06:49 上傳
JSON不支持八進(jìn)制和十六進(jìn)制, 數(shù)值必須以十進(jìn)制表示,且不能使用NaN和Infinity。以下是合法的JSON數(shù)值:
{ "age": 30 }
2.4 JSON 對象JSON 對象是一個(gè)無序的key/value對的集合。一個(gè)對象以 '{' 開始,以 '}' 結(jié)束;每個(gè)key 和 value 中使用冒號(hào)分隔;每個(gè) key/value 對之間使用逗號(hào)分隔。如圖 14所示:
p0i3chztwi56405962606.png (4.9 KB, 下載次數(shù): 8)
下載附件
保存到相冊
p0i3chztwi56405962606.png
2024-9-26 06:49 上傳
JSON 對象語法:
對象在大括號(hào)({})中書寫。
對象可以包含多個(gè) key/value(鍵/值)對。
key是字符串,必須放在雙引號(hào)里面。value 可以是合法的 JSON 數(shù)據(jù)類型(字符串, 數(shù)值, 對象, 數(shù)組, 布爾值或 null)。
一個(gè) key/value 對內(nèi)部,key 和 value使用冒號(hào)(:)分隔。
key/value 對之間,使用逗號(hào)(,)分隔。
對象可以嵌套
2.5 JSON 數(shù)組數(shù)組是值(value)的有序集合。一個(gè)數(shù)組以“[”(左中括號(hào))開始,“]”(右中括號(hào))結(jié)束。值之間使用“,”(逗號(hào))分隔。如圖 15所示:
woqlfzfxp1h6405962706.png (4.12 KB, 下載次數(shù): 7)
下載附件
保存到相冊
woqlfzfxp1h6405962706.png
2024-9-26 06:49 上傳
JSON 數(shù)組:
數(shù)組在中括號(hào)中書寫。
數(shù)組的值必須是合法的 JSON 數(shù)據(jù)類型(字符串, 數(shù)值, 對象, 數(shù)組, 布爾值或 null),也可以是 JavaScript 的表達(dá)式,包括函數(shù)、日期、undefined。
2.6 JSON 布爾值JSON 布爾值可以是 true 或者 false。如:
{ "flag":true }
2.7 JSON nullJSON 可以設(shè)置 null 值。如:
{ "zhihu":null }
2.8 JSON 文件JSON 文件的文件類型是 ".json"
JSON 文本的 MIME 類型是 "application/json"
三 JSON協(xié)議組件的使用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 應(yīng)用層組件功能介紹提供JSON協(xié)議和服務(wù)器通信連接實(shí)例。
使用該組件,必須同時(shí)使用AT組件,文件組件,TCP組件,掉線組件,掉線重連組件,DI組件,DO組件,AI組件,JSON組件,CLK組件。
3 代碼講解1 dtu_json_task_send_msgq
發(fā)送消息給模塊主任務(wù),錯(cuò)誤后串口輸出信息
/**
* Function : dtu_json_task_send_msgq
* Description : 發(fā)送消息給模塊主任務(wù),錯(cuò)誤后串口輸出信息
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
int dtu_json_task_send_msgq(DTU_JSON_MSG_T * msg)
{
int ret = 0;
//發(fā)送消息給json主任務(wù)
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
發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
/**
* Function : dtu_sys_json_get_sys_config
* Description : 發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_sys_json_get_sys_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID為獲取配置回復(fù)
p_smsg.msgId = DTU_SYS_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d
", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}3 dtu_sys_json_get_sys_config_res
回復(fù)服務(wù)器獲取sys配置
/**
* Function : dtu_sys_json_get_sys_config_res
* Description : 回復(fù)服務(wù)器獲取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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//創(chuàng)建json對象
gdocr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
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);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gdocr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdocr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gdocr);
}4 dtu_sys_json_set_sys_config
設(shè)置sys配置
/**
* Function : dtu_sys_json_set_sys_config
* Description : 設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
dtu_file_ctx = dtu_get_file_ctx();
dtu_timer_ctx = dtu_get_timer_ctx();
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_SYS_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s
", __FUNCTION__, rcvdata);
//解析數(shù)據(jù)
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)
{
//開始心跳定時(shí)器
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)
{
//關(guān)閉心跳定時(shí)器
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
",
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
回復(fù)服務(wù)器設(shè)置sys
/**
* Function : dtu_sys_json_set_sys_config_res
* Description : 回復(fù)服務(wù)器設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
gdocr = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
cJSON_AddItemToObject(gdocr, "msgType", cJSON_CreateString("setSysConfigRes"));
cJSON_AddItemToObject(gdocr, "data", cJSON_CreateNumber(res));
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gdocr)));
if(NULL != gdocr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdocr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gdocr);
}6 dtu_net_json_get_net_config
發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
/**
* Function : dtu_net_json_get_net_config
* Description : 發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_net_json_get_net_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_NET_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d
", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}7 dtu_net_json_get_net_config_res
回復(fù)服務(wù)器獲net配置
/**
* Function : dtu_net_json_get_net_config_res
* Description : 回復(fù)服務(wù)器獲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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//創(chuàng)建json對象
gdocr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
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);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gdocr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdocr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gdocr);
}8 dtu_net_json_set_net_config
設(shè)置網(wǎng)絡(luò)配置
/**
* Function : dtu_net_json_set_net_config
* Description : 設(shè)置網(wǎng)絡(luò)配置
* 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;
//獲取對應(yīng)模塊的上下文指針
dtu_file_ctx = dtu_get_file_ctx();
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_NET_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s
", __FUNCTION__, rcvdata);
//解析數(shù)據(jù)
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
設(shè)置網(wǎng)絡(luò)配置
/**
* Function : dtu_net_json_set_net_config
* Description : 設(shè)置網(wǎng)絡(luò)配置
* 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;
//獲取對應(yīng)模塊的上下文指針
dtu_file_ctx = dtu_get_file_ctx();
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_NET_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s
", __FUNCTION__, rcvdata);
//解析數(shù)據(jù)
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
回復(fù)服務(wù)器設(shè)置net
/**
* Function : dtu_net_json_set_net_config_res
* Description : 回復(fù)服務(wù)器設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
gdocr = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
cJSON_AddItemToObject(gdocr, "msgType", cJSON_CreateString("setNetConfigRes"));
cJSON_AddItemToObject(gdocr, "data", cJSON_CreateNumber(res));
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gdocr)));
if(NULL != gdocr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdocr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gdocr);
}11 dtu_di_json_get_di_value
發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
/**
* Function : dtu_di_json_get_di_value
* Description : 發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_di_json_get_di_value(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_DI_MSG_ID_GET_VALUE_REPORT;
// printf("%s PIN4 status: %d
", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}12 dtu_di_json_get_di_value_res
回復(fù)服務(wù)器獲取di值
/**
* Function : dtu_di_json_get_di_value_res
* Description : 回復(fù)服務(wù)器獲取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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
gdivr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
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);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gdivr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdivr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gdivr);
}13 dtu_di_json_get_di_config
發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
/**
* Function : dtu_di_json_get_di_config
* Description : 發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_di_json_get_di_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_DI_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d
", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}14 dtu_di_json_get_di_config_res
回復(fù)服務(wù)器獲取di配置
/**
* Function : dtu_di_json_get_di_config_res
* Description : 回復(fù)服務(wù)器獲取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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//創(chuàng)建json對象
gdicr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
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);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gdicr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdicr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gdicr);
}15 dtu_di_json_set_di_config
設(shè)置di配置
/**
* Function : dtu_di_json_set_di_config
* Description : 設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
dtu_file_ctx = dtu_get_file_ctx();
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_DI_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s
", __FUNCTION__, rcvdata);
//解析數(shù)據(jù)
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)
{
//開定時(shí)器
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)
{
//開定時(shí)器
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)
{
//開定時(shí)器
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)
{
//開定時(shí)器
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)
{
//開定時(shí)器
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
" \
"DI2:type %d, interval %d, pull %d\r
" \
"DI3:type %d, interval %d, pull %d\r
" \
"DI4:type %d, interval %d, pull %d\r
" \
"DI5:type %d, interval %d, pull %d\r
",
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
回復(fù)服務(wù)器設(shè)置di值
/**
* Function : dtu_di_set_di_value_res
* Description : 回復(fù)服務(wù)器設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
gdivr = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
cJSON_AddItemToObject(gdivr, "msgType", cJSON_CreateString("setDiConfigRes"));
cJSON_AddItemToObject(gdivr, "data", cJSON_CreateNumber(res));
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gdivr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdivr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gdivr);
}17 dtu_di_json_res
DI主動(dòng)上報(bào)
/**
* Function : dtu_di_json_res
* Description : DI主動(dòng)上報(bào)
* 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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
gdivr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
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);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gdivr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdivr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gdivr);
}18 dtu_do_json_get_do_value
發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
/**
* Function : dtu_do_json_get_do_value
* Description : 發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_do_json_get_do_value(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_DO_MSG_ID_GET_VALUE_REPORT;
// printf("%s PIN4 status: %d
", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}19 dtu_do_json_get_do_value_res
回復(fù)服務(wù)器獲取di值
/**
* Function : dtu_do_json_get_do_value_res
* Description : 回復(fù)服務(wù)器獲取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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
gdovr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
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);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gdovr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdovr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gdovr);
}20 dtu_do_json_set_do_value
設(shè)置di配置
/**
* Function : dtu_do_json_set_do_value
* Description : 設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
dtu_file_ctx = dtu_get_file_ctx();
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_DO_MSG_ID_SET_VALUE_REPORT;
// printf("%s %s
", __FUNCTION__, rcvdata);
//解析數(shù)據(jù)
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
回復(fù)服務(wù)器設(shè)置di值
/**
* Function : dtu_do_json_set_do_value_res
* Description : 回復(fù)服務(wù)器設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
gdovr = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
cJSON_AddItemToObject(gdovr, "msgType", cJSON_CreateString("setDoValueRes"));
cJSON_AddItemToObject(gdovr, "data", cJSON_CreateNumber(res));
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gdovr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdovr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gdovr);
}22 dtu_do_json_get_do_config
發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
/**
* Function : dtu_do_json_get_do_config
* Description : 發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_do_json_get_do_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_DO_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d
", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}23 dtu_do_json_get_do_config_res
回復(fù)服務(wù)器獲取di配置
/**
* Function : dtu_do_json_get_do_config_res
* Description : 回復(fù)服務(wù)器獲取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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//創(chuàng)建json對象
gdocr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
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);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gdocr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdocr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gdocr);
}24 dtu_do_json_set_do_config
設(shè)置do配置
/**
* Function : dtu_do_json_set_do_config
* Description : 設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
dtu_file_ctx = dtu_get_file_ctx();
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_DO_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s
", __FUNCTION__, rcvdata);
//解析數(shù)據(jù)
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)
{
//開定時(shí)器
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)
{
//關(guān)閉定時(shí)器
dtu_do1_report_timer_stop();
}
if(DTU_DO_REPORT_INITIATIVE == dtu_file_ctx->doo.do2.do_type)
{
//開定時(shí)器
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)
{
//關(guān)閉定時(shí)器
dtu_do2_report_timer_stop();
}
if(DTU_DO_REPORT_INITIATIVE == dtu_file_ctx->doo.do3.do_type)
{
//開定時(shí)器
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)
{
//關(guān)閉定時(shí)器
dtu_do3_report_timer_stop();
}
if(DTU_DO_REPORT_INITIATIVE == dtu_file_ctx->doo.do4.do_type)
{
//開定時(shí)器
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)
{
//關(guān)閉定時(shí)器
dtu_do4_report_timer_stop();
}
if(DTU_DO_REPORT_INITIATIVE == dtu_file_ctx->doo.do5.do_type)
{
//開定時(shí)器
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)
{
//關(guān)閉定時(shí)器
dtu_do5_report_timer_stop();
}
//寫入文件
dtu_trans_conf_file_write(dtu_file_ctx);
printf("DO1:type %d, interval %d, status %d\r
" \
"DO2:type %d, interval %d, status %d\r
" \
"DO3:type %d, interval %d, status %d\r
" \
"DO4:type %d, interval %d, status %d\r
" \
"DO5:type %d, interval %d, status %d\r
",
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
回復(fù)服務(wù)器設(shè)置do
/**
* Function : dtu_do_json_set_do_config_res
* Description : 回復(fù)服務(wù)器設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
gdocr = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
cJSON_AddItemToObject(gdocr, "msgType", cJSON_CreateString("setDoConfigRes"));
cJSON_AddItemToObject(gdocr, "data", cJSON_CreateNumber(res));
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gdocr)));
if(NULL != gdocr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gdocr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gdocr);
}
26 dtu_do_json_res
DO主動(dòng)上報(bào)
/**
* Function : dtu_do_json_res
* Description : DO主動(dòng)上報(bào)
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
static void dtu_ai_json_res(void)
{
cJSON *gaivr = NULL;
cJSON *data = NULL;
char* send = NULL;
UINT16 ai_v = 0;
float ai_i = 0.0;
char ai_str[10] = {0};
DTU_SOCKET_PARAM_T* socket_ctx = NULL;
DTU_FILE_PARAM_T* dtu_file_ctx = NULL;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//創(chuàng)建json對象
gaivr = cJSON_CreateObject();
data = cJSON_CreateObject();
//獲取adc值
ai_v = dtu_ai_read();
ai_i = (float)ai_v / DTU_AI_RES_VAL;
sprintf(ai_str, "%.02f", ai_i);
//根據(jù)模式?jīng)Q定是否上報(bào)
do
{
//排除不用上報(bào)的情況
if(DTU_AI_REPORT_TRIGGER == dtu_file_ctx->ai.ai_type)
{
// printf("AI Trigger rpt");
//在閾值外上報(bào),當(dāng)電流位于閾值內(nèi),跳出
if(DTU_AI_REPORT_OUT == dtu_file_ctx->ai.ai_res_rule)
{
// printf("AI rpt out");
if(ai_i ai.ai_alarm_high && ai_i >= dtu_file_ctx->ai.ai_alarm_low)
{
// printf("AI rpt out break");
break;
}
}
//在閾值內(nèi)上報(bào),當(dāng)電流位于閾值外,跳出
else if(DTU_AI_REPORT_IN == dtu_file_ctx->ai.ai_res_rule)
{
// printf("AI rpt in");
if(ai_i > dtu_file_ctx->ai.ai_alarm_high || ai_i ai.ai_alarm_low)
{
// printf("AI rpt in break");
break;
}
}
}
//按照協(xié)議,對象內(nèi)加入成員
cJSON_AddItemToObject(data, "AI1", cJSON_CreateString(ai_str));
cJSON_AddItemToObject(gaivr, "msgType", cJSON_CreateString("aiValueRpt"));
cJSON_AddItemToObject(gaivr, "data", data);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gaivr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gaivr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
}while(0);
//刪除json對象
cJSON_Delete(gaivr);
}dtu_ai_json_get_ai_value
發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
/**
* Function : dtu_ai_json_get_ai_value
* Description : 發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_ai_json_get_ai_value(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_AI_MSG_ID_GET_VALUE_REPORT;
// printf("%s PIN4 status: %d
", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}27 dtu_ai_json_get_ai_value_res
回復(fù)服務(wù)器獲取di值
/**
* Function : dtu_ai_json_get_ai_value_res
* Description : 回復(fù)服務(wù)器獲取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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
gaivr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
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);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gaivr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gaivr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gaivr);
}28 dtu_ai_json_get_ai_config
發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
/**
* Function : dtu_ai_json_get_ai_config
* Description : 發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_ai_json_get_ai_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_AI_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d
", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}29 dtu_ai_json_get_ai_config_res
回復(fù)服務(wù)器獲取di配置
/**
* Function : dtu_ai_json_get_ai_config_res
* Description : 回復(fù)服務(wù)器獲取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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//創(chuàng)建json對象
gaicr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
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);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gaicr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gaicr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gaicr);
}30 dtu_ai_json_set_ai_config
設(shè)置ai配置
/**
* Function : dtu_ai_json_set_ai_config
* Description : 設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
dtu_file_ctx = dtu_get_file_ctx();
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_AI_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s
", __FUNCTION__, rcvdata);
//解析數(shù)據(jù)
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)
// {
// //開定時(shí)器
// 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
",
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
回復(fù)服務(wù)器設(shè)置di值
/**
* Function : dtu_ai_json_set_ai_config_res
* Description : 回復(fù)服務(wù)器設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
gaivr = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
cJSON_AddItemToObject(gaivr, "msgType", cJSON_CreateString("setAiConfigRes"));
cJSON_AddItemToObject(gaivr, "data", cJSON_CreateNumber(res));
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gaivr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gaivr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gaivr);
}32 dtu_ai_json_res
DI主動(dòng)上報(bào)
/**
* Function : dtu_ai_json_res
* Description : DI主動(dòng)上報(bào)
* 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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
gaivr = cJSON_CreateObject();
data = cJSON_CreateObject();
//獲取adc值
ul_adc_value = SDK_READ_ADC_VALUE_NEW(0,1);
//按照協(xié)議,對象內(nèi)加入成員
cJSON_AddItemToObject(data, "AI1", cJSON_CreateNumber(ul_adc_value));
cJSON_AddItemToObject(gaivr, "msgType", cJSON_CreateString("aiValueRpt"));
cJSON_AddItemToObject(gaivr, "data", data);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gaivr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gaivr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gaivr);
}33 dtu_flow_json_get_flow_config
發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
/**
* Function : dtu_flow_json_get_flow_config
* Description : 發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_flow_json_get_flow_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_FLOW_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d
", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}34 dtu_flow_json_get_flow_config_res
回復(fù)服務(wù)器獲取flow配置
/**
* Function : dtu_flow_json_get_flow_config_res
* Description : 回復(fù)服務(wù)器獲取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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//創(chuàng)建json對象
gfcr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
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);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gfcr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gfcr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gfcr);
}35 dtu_flow_json_set_flow_config
設(shè)置flow配置
/**
* Function : dtu_flow_json_set_flow_config
* Description : 設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
dtu_file_ctx = dtu_get_file_ctx();
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_FLOW_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s
", __FUNCTION__, rcvdata);
//解析數(shù)據(jù)
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)
{
//開始心跳定時(shí)器
}
else if(0 == dtu_file_ctx->hb.heartflag)
{
//關(guān)閉心跳定時(shí)器
}
//寫入文件
dtu_trans_conf_file_write(dtu_file_ctx);
printf("enHb: %d, cycHb: %d, hbPkg: %s, enReg: %d, regpkg: %s\r
",
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
回復(fù)服務(wù)器設(shè)置flow
/**
* Function : dtu_flow_json_set_flow_config_res
* Description : 回復(fù)服務(wù)器設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
gfcr = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
cJSON_AddItemToObject(gfcr, "msgType", cJSON_CreateString("setSysConfigRes"));
cJSON_AddItemToObject(gfcr, "data", cJSON_CreateNumber(res));
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gfcr)));
if(NULL != gfcr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gfcr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gfcr);
}37 dtu_clk_json_get_clk_config
發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
/**
* Function : dtu_clk_json_clk_net_config
* Description : 發(fā)送消息給主任務(wù),按照協(xié)議回復(fù)相應(yīng)內(nèi)容
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_clk_json_get_clk_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_CLK_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d
", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}38 dtu_clk_json_get_clk_config_res
回復(fù)服務(wù)器獲clk配置
/**
* Function : dtu_clk_json_get_clk_config_res
* Description : 回復(fù)服務(wù)器獲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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//創(chuàng)建json對象
gclkcr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
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);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gclkcr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gclkcr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gclkcr);
}39 dtu_clk_json_set_clk_config
設(shè)置網(wǎng)絡(luò)配置
/**
* Function : dtu_clk_json_set_clk_config
* Description : 設(shè)置網(wǎng)絡(luò)配置
* 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;
//獲取對應(yīng)模塊的上下文指針
dtu_file_ctx = dtu_get_file_ctx();
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_CLK_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s
", __FUNCTION__, rcvdata);
//解析數(shù)據(jù)
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
回復(fù)服務(wù)器設(shè)置clk
/**
* Function : dtu_clk_json_set_clk_config_res
* Description : 回復(fù)服務(wù)器設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
gclkcr = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
cJSON_AddItemToObject(gclkcr, "msgType", cJSON_CreateString("setClockConfigRes"));
cJSON_AddItemToObject(gclkcr, "data", cJSON_CreateNumber(res));
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gclkcr)));
if(NULL != gclkcr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gclkcr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
free(send);
}
//刪除json對象
cJSON_Delete(gclkcr);
}41 dtu_fota_result_json_cbk
json ota 回調(diào)函數(shù)
/**
* Function : dtu_fota_result_json_cbk
* Description : json ota 回調(diào)函數(shù)
* 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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
if(result != FOTA_SUCCESS)
{
res = 1;
printf("Fota Error,Please try again!");
}
//創(chuàng)建json對象
gota = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
cJSON_AddItemToObject(gota, "msgType", cJSON_CreateString("setOTAConfigRes"));
cJSON_AddItemToObject(gota, "data", cJSON_CreateNumber(res));
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gota)));
if(NULL != gota)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gota); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
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
設(shè)置ota參數(shù)
/**
* Function : dtu_ota_json_set_ota_config
* Description : 設(shè)置ota參數(shù)
* 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;
//獲取對應(yīng)模塊的上下文指針
dtu_file_ctx = dtu_get_file_ctx();
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_OTA_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s
", __FUNCTION__, rcvdata);
//解析數(shù)據(jù)
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
服務(wù)器下發(fā)獲取modbus配置
/**
* Function : dtu_modbus_json_get_modbus_config
* Description : 服務(wù)器下發(fā)獲取modbus配置
* Input :
*
* Output :
* Return :
* Auther : zhaoning
* Others :
**/
void dtu_modbus_json_get_modbus_config(void)
{
DTU_JSON_MSG_T p_smsg = {0};
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_MODBUS_MSG_ID_GET_CONFIG_REPORT;
// printf("%s PIN4 status: %d
", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}44 dtu_modbus_json_get_modbus_config_res
回復(fù)服務(wù)器獲取modbus配置
/**
* Function : dtu_modbus_json_get_modbus_config_res
* Description : 回復(fù)服務(wù)器獲取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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//創(chuàng)建json對象
gmdcr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
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);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gmdcr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gmdcr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
//釋放內(nèi)存
free(send);
}
//刪除json對象
cJSON_Delete(gmdcr);
}45 dtu_modbus_json_set_modbus_config
服務(wù)器下發(fā)設(shè)置modbus配置
/**
* Function : dtu_modbus_json_set_modbus_config
* Description : 服務(wù)器下發(fā)設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
dtu_file_ctx = dtu_get_file_ctx();
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_MODBUS_MSG_ID_SET_CONFIG_REPORT;
// printf("%s %s
", __FUNCTION__, rcvdata);
//解析數(shù)據(jù)
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
{
//關(guān)閉心跳
dtu_file_ctx->hb.heartflag = 0;
#ifdef DTU_TYPE_HTTP_INCLUDE
//關(guān)閉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
回復(fù)服務(wù)器設(shè)置modbus配置
/**
* Function : dtu_modbus_json_set_modbus_config_res
* Description : 回復(fù)服務(wù)器設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
smdcr = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
cJSON_AddItemToObject(smdcr, "msgType", cJSON_CreateString("setMbConfigRes"));
cJSON_AddItemToObject(smdcr, "data", cJSON_CreateNumber(res));
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(smdcr)));
if(NULL != smdcr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(smdcr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
//釋放內(nèi)存
free(send);
}
//刪除json對象
cJSON_Delete(smdcr);
}47 dtu_modbus_json_get_modbus_cmd
服務(wù)器獲取modubs指令
/**
* Function : dtu_modbus_json_get_modbus_cmd
* Description : 服務(wù)器獲取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設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_MODBUS_MSG_ID_GET_CMD_REPORT;
// printf("%s PIN4 status: %d
", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}48 dtu_modbus_json_get_modbus_cmd_res
回復(fù)服務(wù)器獲取modubs指令
/**
* Function : dtu_modbus_json_get_modbus_cmd_res
* Description : 回復(fù)服務(wù)器獲取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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//創(chuàng)建json對象
gmdcr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
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);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gmdcr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gmdcr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
//釋放內(nèi)存
free(send);
}
//刪除json對象
cJSON_Delete(gmdcr);
}49 dtu_modbus_json_get_modbus_cmdwn
服務(wù)器獲取modubs指令
/**
* Function : dtu_modbus_json_get_modbus_cmdwn
* Description : 服務(wù)器獲取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設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_MODBUS_MSG_ID_GET_CMD_REPORT;
// printf("%s PIN4 status: %d
", __FUNCTION__, p_smsg.status);
dtu_json_task_send_msgq(&p_smsg);
}
50 dtu_modbus_json_get_modbus_cmdwn_res
回復(fù)服務(wù)器獲取modubs指令
/**
* Function : dtu_modbus_json_get_modbus_cmdwn_res
* Description : 回復(fù)服務(wù)器獲取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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//創(chuàng)建json對象
gmdcr = cJSON_CreateObject();
data = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
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);
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gmdcr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gmdcr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
//釋放內(nèi)存
free(send);
}
//刪除json對象
cJSON_Delete(gmdcr);
}51 dtu_modbus_json_set_modbus_cmd
服務(wù)器下發(fā)設(shè)置modbus指令
/**
* Function : dtu_modbus_json_set_modbus_cmd
* Description : 服務(wù)器下發(fā)設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
dtu_file_ctx = dtu_get_file_ctx();
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_MODBUS_MSG_ID_SET_CMD_REPORT;
// printf("%s %s
", __FUNCTION__, rcvdata);
//解析數(shù)據(jù)
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
回復(fù)服務(wù)器設(shè)置modbus指令
/**
* Function : dtu_modbus_json_set_modbus_cmd_res
* Description : 回復(fù)服務(wù)器設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
smdcr = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
cJSON_AddItemToObject(smdcr, "msgType", cJSON_CreateString("setMbCmdRes"));
cJSON_AddItemToObject(smdcr, "data", cJSON_CreateNumber(res));
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(smdcr)));
if(NULL != smdcr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(smdcr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
//釋放內(nèi)存
free(send);
}
//刪除json對象
cJSON_Delete(smdcr);
}
53 dtu_modbus_json_set_modbus_cmdwn
服務(wù)器下發(fā)設(shè)置modbus指令
/**
* Function : dtu_modbus_json_set_modbus_cmdwn
* Description : 服務(wù)器下發(fā)設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
dtu_file_ctx = dtu_get_file_ctx();
//消息ID設(shè)置為對應(yīng)ID
p_smsg.msgId = DTU_MODBUS_MSG_ID_SET_CMD_REPORT;
// printf("%s %s
", __FUNCTION__, rcvdata);
//解析數(shù)據(jù)
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
回復(fù)服務(wù)器設(shè)置modbus指令
/**
* Function : dtu_modbus_json_set_modbus_cmdwn_res
* Description : 回復(fù)服務(wù)器設(shè)置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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
//創(chuàng)建json對象
gclkcr = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
cJSON_AddItemToObject(gclkcr, "msgType", cJSON_CreateString("setMbCmdWnRes"));
cJSON_AddItemToObject(gclkcr, "data", cJSON_CreateNumber(res));
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(gclkcr)));
if(NULL != gclkcr)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(gclkcr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
//釋放內(nèi)存
free(send);
}
//刪除json對象
cJSON_Delete(gclkcr);
}55 dtu_modbus_json_modbus_res
modbus模式下,配置為modbus上報(bào)后,調(diào)用此函數(shù)把hex轉(zhuǎn)json
/**
* Function : dtu_modbus_json_modbus_res
* Description : modbus模式下,配置為modbus上報(bào)后,調(diào)用此函數(shù)把hex轉(zhuǎn)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;
//獲取對應(yīng)模塊的上下文指針
socket_ctx = dtu_get_socket_ctx();
dtu_file_ctx = dtu_get_file_ctx();
//創(chuàng)建json對象
s01hr = cJSON_CreateObject();
//按照協(xié)議,對象內(nèi)加入成員
cJSON_AddItemToObject(s01hr, "msgType", cJSON_CreateString("rs485Rpt"));
if(len > DTU_MODBUS_RES_LEN / 2)
{
len = DTU_MODBUS_RES_LEN / 2;
}
//申請內(nèi)存
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));
//申請內(nèi)存
send = malloc(strlen(cJSON_Print(s01hr)));
if(NULL != send)
{
memset(send, 0, sizeof(send));
send = cJSON_PrintUnformatted(s01hr); // 生成不帶空格的JSON字符串
printf("send:%s",send);
//發(fā)送數(shù)據(jù)到服務(wù)器
dtu_socket_write(socket_ctx->fd, send, strlen(send));
//釋放內(nèi)存
free(send);
}
}
//刪除json對象
cJSON_Delete(s01hr);
}56 dtu_json_task
json主任務(wù)
/**
* Function : dtu_json_task
* Description : json主任務(wù)
* 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();
//獲取對應(yīng)模塊的上下文指針
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
", __FUNCTION__, json_rcv_msg.msgId);
printf("%s: json_rcv_msg status: %d
", __FUNCTION__, json_rcv_msg.status);
printf("%s: json_rcv_msg channel: %d
", __FUNCTION__, json_rcv_msg.channel);
printf("%s: json_rcv_msg result: %d
", __FUNCTION__, json_rcv_msg.result);
printf("%s: json_rcv_msg current: %d
", __FUNCTION__, json_rcv_msg.current);
// printf("%s: json_rcv_msg value: %d
", __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主任務(wù)和消息隊(duì)列創(chuàng)建
/**
* Function : dtu_di_task_init
* Description : di主任務(wù)和消息隊(duì)列創(chuàng)建
* 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);
//創(chuàng)建DI任務(wù)
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實(shí)戰(zhàn)4.1 創(chuàng)建一個(gè)Demo復(fù)制20.9_di_xtu示例工程,到同一個(gè)文件夾下,修改文件名為20.12_json_xtu,如圖:
knu13v1aurb6405962806.png (52.51 KB, 下載次數(shù): 6)
下載附件
保存到相冊
knu13v1aurb6405962806.png
2024-9-26 06:49 上傳
4.2 修改makefile增加文件組件所在目錄頭文件路徑,和源文件路徑,以及一些宏定義,如圖:
-D是makefile中定義宏定義必要的前綴,可以搜索相關(guān)makefile學(xué)習(xí)文章學(xué)習(xí)相關(guān)知識(shí)。
DTU_BASED_ON_TCP 表示當(dāng)前是TCP模式,當(dāng)前組件使用需要am.h中包含一些對應(yīng)。
DTU_TYPE_5X6 表示使用SOM板貼片5x6卡,可以使用其它卡,修改為對應(yīng)宏定義就可以。
DTU_UART_115200_BAUD 表示使用115200波特率
DTU_TYPE_JSON_INCLUDE 表示把JSON功能包含進(jìn)來
p0jmacrm5k36405962906.png (55.97 KB, 下載次數(shù): 6)
下載附件
保存到相冊
p0jmacrm5k36405962906.png
2024-9-26 06:49 上傳
4.3 增加頭文件使用代碼編輯器,將新建的工程文件加入代碼編輯器中,打開main.c,修改main.c,加入am.h頭文件,如圖:
w43jxekiejo6405963006.png (14.72 KB, 下載次數(shù): 6)
下載附件
保存到相冊
w43jxekiejo6405963006.png
2024-9-26 06:49 上傳
4.4 修改代碼示例使用的是板載5x6卡,用戶的硬件可能是使用外置卡,或者是三合一全網(wǎng)通卡,因?yàn)橛布先N卡使用的模組SIM卡接口不一樣(外置卡SIM1,5x6卡和三合一卡SIM2),所以,需要通過一個(gè)全局變量來制定SIM卡硬件接口。
extern外部變量SDK_INIT_SIM_SELECT_VALUE,這里判斷了是否使用外置卡,這個(gè)宏定義在Makefile里面定義。
5v1a53qityb6405963106.png (11.33 KB, 下載次數(shù): 8)
下載附件
保存到相冊
5v1a53qityb6405963106.png
2024-9-26 06:49 上傳
在Phase1Inits_enter中,宏定義判斷是否要包含對SDK_INIT_SIM_SELECT_VALUE變量的修改。
xeauusaohwt6405963206.png (13.85 KB, 下載次數(shù): 7)
下載附件
保存到相冊
xeauusaohwt6405963206.png
2024-9-26 06:49 上傳
在Phase2Inits_exit 調(diào)用文件組件提供的對外API,如圖:
zoeqabdsifh6405963306.jpg (134.99 KB, 下載次數(shù): 6)
下載附件
保存到相冊
zoeqabdsifh6405963306.jpg
2024-9-26 06:49 上傳
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 已經(jīng)存在。
子目錄或文件 build\cJSON 已經(jīng)存在。
子目錄或文件 build\obj 已經(jīng)存在。
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 elephony\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 hreadx\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\os
u_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 imer\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 elephony\atcmdsrv\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop elephony\atparser\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop elephony\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
etif -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 avor\Arbel\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x avor\env\inc -IF:\3.asr-b\cat.1-asr1606\1.software\BLOOM_OS_1606_OPENCPU_1191_A08\include\asr160x\hop elephony\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 ts\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
vm\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 elephony\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 ools\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 ./ "
已復(fù)制 1 個(gè)文件。4.6 生成固件參考入門中開發(fā)工具,生成工具。
4.7 查看現(xiàn)象固件下載到模組后,配置服務(wù)器地址,之后按照J(rèn)son協(xié)議下發(fā)數(shù)據(jù)測試,
5 總結(jié)根據(jù)實(shí)驗(yàn)現(xiàn)象,用戶需要實(shí)現(xiàn)自己的AT指令,只需要參考組件中的例子,按照自己需求修改,
注:本文部分內(nèi)容來源于網(wǎng)絡(luò),如有侵權(quán),請及時(shí)聯(lián)系我們。
本文章源自奇跡物聯(lián)開源的物聯(lián)網(wǎng)應(yīng)用知識(shí)庫Cellular IoT Wiki,更多技術(shù)干貨歡迎關(guān)注收藏Wiki:Cellular IoT Wiki 知識(shí)庫
end
一口Linux
關(guān)注,回復(fù)【1024】海量Linux資料贈(zèng)送
精彩文章合集
文章推薦
?【專輯】ARM?【專輯】粉絲問答?【專輯】所有原創(chuàng)?【專輯】linux入門?【專輯】計(jì)算機(jī)網(wǎng)絡(luò)?【專輯】Linux驅(qū)動(dòng)?【干貨】嵌入式驅(qū)動(dòng)工程師學(xué)習(xí)路線?【干貨】Linux嵌入式所有知識(shí)點(diǎn)-思維導(dǎo)圖 |
|