Commit 07ca1ed8 authored by 黄振令's avatar 黄振令

【修改内容】1. 整理网关添加topo代码;2. 增加网关连接成功后,发送网关状态

【提交人】huang.zhenling
parent 88f4925a
......@@ -217,7 +217,7 @@ static int eval_request(struct jrpc_server *server, cJSON *root) {
void _cb(void* data){
if (data != NULL){
printf("plat2mid_cb: %s RECEIVED \r\n", data);
//printf("plat2mid_cb: %s RECEIVED \r\n", data);
cJSON *root;
char *end_ptr = NULL;
......@@ -424,6 +424,39 @@ int search_ccu(char devcode[33], char ip[16], int* port){
}
#define GW_PRODUCT_CODE "2"
#define GW_MAC GW_DEVICE_CODE
void* _msg_topo_add(){
char msgFmt[] = "{\"info\":{\"msgtype\":\"/thing/topo/add\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"},\
\"payload\":{\"msgId\":\"%d\",\"version\":\"1.0\",\"params\":{\"deviceCode\":\"%s\",\"productCode\":\"%s\",\"mac\":\"%s\"}}}";
char msg[520] = {0};
sprintf(msg, msgFmt, GW_PRODUCT_CODE, GW_DEVICE_CODE, 1, GW_DEVICE_CODE, GW_PRODUCT_CODE,GW_MAC);
cJSON* msgObj = cJSON_Parse(msg);
char* outbuf = cJSON_Print(msgObj);
cJSON_Delete(msgObj);
return outbuf;
}
void* _msg_event_property_post(char ip[16], int port){
char msgFmt[] = "{\"info\":{\"msgtype\":\"/thing/event/property/post\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"},\
\"payload\":{\"msgId\":\"%d\",\"version\":\"1.0\",\"params\":{\"NetChannelState\":%d,\"WhiteListState\":%d,\
\"OnlineDetectionState\":%d,\"SN\":\"%s\",\"IPAddress\":\"%s\",\"MACAddress\":\"%s\",\"Port\":%d},\
\"time\":1524448722000,\"method\":\"thing.event.property.post\"}\
}";
char msg[620] = {0};
sprintf(msg, msgFmt, GW_PRODUCT_CODE, GW_DEVICE_CODE,
1, 0, 0, 0, "12345", ip,GW_MAC,port);
cJSON* msgObj = cJSON_Parse(msg);
char* outbuf = cJSON_Print(msgObj);
cJSON_Delete(msgObj);
return outbuf;
}
void ipcHandle(void)
{
char deviceCode[33] = {0};
......@@ -445,23 +478,23 @@ void ipcHandle(void)
}
//send add gw to ccu
char info[] = "{\"msgtype\":\"/thing/topo/add\",\"productType\":\"gw\",\"productCode\":\"2\",\"deviceCode\":\"1122334455667788\"}";
char payload[] = "{\"msgId\":\"1\",\"version\":\"1.0\",\"params\":{\"deviceCode\":\"1122334455667788\",\"productCode\":\"2\",\"mac\":\"1122334455667788\"}}";
cJSON* root = cJSON_CreateObject();
cJSON* infoObj = cJSON_Parse(info);
cJSON* payloadObj = cJSON_Parse(payload);
cJSON_AddItemToObject(root, "info", infoObj);
cJSON_AddItemToObject(root, "payload",payloadObj);
char* outbuf = cJSON_Print(root);
cJSON_Delete(root);
char* outbuf = _msg_topo_add();
kk_sendData2CCU(outbuf, strlen(outbuf));
//kk_sendData2CCU("allan test", strlen("allan test"));
free(outbuf);
int cnt = 0;
//handle procidure
while(1){
//
usleep(20000);
cnt++;
if (cnt == 2){
sleep(1);
char* postmsg = _msg_event_property_post(ip,port);
kk_sendData2CCU(postmsg, strlen(postmsg));
free(postmsg);
}
}
//jrpc_server_run(&my_server);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment