Commit e54d33e1 authored by 黄振令's avatar 黄振令

【修改内容】优化程序

【提交人】huang.zhenling
parent af90a653
...@@ -40,7 +40,7 @@ typedef enum { ...@@ -40,7 +40,7 @@ typedef enum {
typedef void ipc_cb(void* data, int len, char* chalMark); typedef void ipc_cb(void* data, int len, char* chalMark);
int kk_ipc_init(ipc_type type, ipc_cb cb, char* chalMark, char* ip); int kk_ipc_init(ipc_type type, ipc_cb cb, char* chalMark, char* ip);
int kk_ipc_deinit(); int kk_ipc_deinit(ipc_type type);
int kk_ipc_send(ipc_type type, void* data, int len); int kk_ipc_send(ipc_type type, void* data, int len);
int kk_ipc_send_ex(ipc_type type, void* data, int len, char* chalMark); int kk_ipc_send_ex(ipc_type type, void* data, int len, char* chalMark);
......
...@@ -338,7 +338,7 @@ static void read_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) ...@@ -338,7 +338,7 @@ static void read_cb(struct ev_loop *loop, struct ev_io *watcher, int revents)
free(watcher); free(watcher);
} else { } else {
//intf("READ:\r\n %s\r\n", buffer); //intf("READ:\r\n %s\r\n", buffer);
printf("read_cb deviceCode ip sock [%s][%s][%d]",tcp_ctrl->deviceCode,tcp_ctrl->ip, tcp_ctrl->sock); //printf("read_cb deviceCode ip sock [%s][%s][%d] \n",tcp_ctrl->deviceCode,tcp_ctrl->ip, tcp_ctrl->sock);
if (g_cb != NULL){ if (g_cb != NULL){
g_cb(buffer,bytes,tcp_ctrl->deviceCode); g_cb(buffer,bytes,tcp_ctrl->deviceCode);
} }
......
...@@ -459,17 +459,25 @@ int search_ccu(char devcode[33], char ip[16], int* port){ ...@@ -459,17 +459,25 @@ int search_ccu(char devcode[33], char ip[16], int* port){
void* _msg_topo_add(){ void* _msg_topo_add(){
char msgFmt[] = "{\"info\":{\"msgtype\":\"/thing/topo/add\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"},\ char msgFmt[] = "{\"info\":{\"msgtype\":\"/thing/topo/add\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"},\
\"payload\":{\"msgId\":\"%d\",\"version\":\"1.0\",\"params\":{\"deviceCode\":\"%s\",\"productCode\":\"%s\",\"mac\":\"%s\"}}}"; \"payload\":{\"msgId\":\"%d\",\"version\":\"1.0\",\"params\":{\"deviceCode\":\"%s\",\"productCode\":\"%s\",\"mac\":\"%s\"}}}";
char msg[520] = {0}; //char msg[520] = {0};
char* msg = NULL;
char* macString = kk_get_gw_mac(); char* macString = kk_get_gw_mac();
if (macString == NULL){ if (macString == NULL){
printf("[%s] get mac fail\n",__FUNCTION__); printf("[%s] get mac fail\n",__FUNCTION__);
return NULL; return NULL;
} }
msg = malloc(520);
if (msg == NULL){
printf("[%s] msg malloc fail\n",__FUNCTION__);
return NULL;
}
sprintf(msg, msgFmt, GW_PRODUCT_CODE, macString, 1, macString, GW_PRODUCT_CODE,macString); sprintf(msg, msgFmt, GW_PRODUCT_CODE, macString, 1, macString, GW_PRODUCT_CODE,macString);
cJSON* msgObj = cJSON_Parse(msg); //cJSON* msgObj = cJSON_Parse(msg);
char* outbuf = cJSON_Print(msgObj); //char* outbuf = cJSON_Print(msgObj);
cJSON_Delete(msgObj); //cJSON_Delete(msgObj);
return outbuf; //return outbuf;
return msg;
} }
...@@ -480,18 +488,27 @@ void* _msg_event_property_post(char ip[16], int port){ ...@@ -480,18 +488,27 @@ void* _msg_event_property_post(char ip[16], int port){
\"OnlineDetectionState\":%d,\"SN\":\"%s\",\"IPAddress\":\"%s\",\"MACAddress\":\"%s\",\"Port\":%d},\ \"OnlineDetectionState\":%d,\"SN\":\"%s\",\"IPAddress\":\"%s\",\"MACAddress\":\"%s\",\"Port\":%d},\
\"time\":1524448722000,\"method\":\"thing.event.property.post\"}\ \"time\":1524448722000,\"method\":\"thing.event.property.post\"}\
}"; }";
char msg[620] = {0}; //char msg[620] = {0};
char* msg = NULL;
char* macString = kk_get_gw_mac(); char* macString = kk_get_gw_mac();
if (macString == NULL){ if (macString == NULL){
printf("[%s] get mac fail\n",__FUNCTION__); printf("[%s] get mac fail\n",__FUNCTION__);
return NULL; return NULL;
} }
msg = malloc(620);
if (msg == NULL){
printf("[%s] msg malloc fail\n",__FUNCTION__);
return NULL;
}
sprintf(msg, msgFmt, GW_PRODUCT_CODE, macString, sprintf(msg, msgFmt, GW_PRODUCT_CODE, macString,
1, 0, 0, 0, "12345", ip,macString,port); 1, 0, 0, 0, "12345", ip,macString,port);
cJSON* msgObj = cJSON_Parse(msg); //cJSON* msgObj = cJSON_Parse(msg);
char* outbuf = cJSON_Print(msgObj); //char* outbuf = cJSON_Print(msgObj);
cJSON_Delete(msgObj); //cJSON_Delete(msgObj);
return outbuf; //return outbuf;
return msg;
} }
......
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