Commit 3de8f63f authored by 陈伟灿's avatar 陈伟灿

Merge branch 'hzl' into 'master'

【修改内容】1. tcp连接粘包问题:1)使用json格式找'{'找到完成的json;2). 收到数据有'\0',用'\0'来区分粘包;2....

See merge request chenweican/k-sdk!15
parents a279a29f e1a27285
...@@ -382,7 +382,7 @@ int KK_Send_CloudState(int state) ...@@ -382,7 +382,7 @@ int KK_Send_CloudState(int state)
cJSON_AddItemToObject(root, MSG_INFO_STR, infoObj); cJSON_AddItemToObject(root, MSG_INFO_STR, infoObj);
cJSON_AddItemToObject(root, MSG_PAYLOAD_STR,payloadObj); cJSON_AddItemToObject(root, MSG_PAYLOAD_STR,payloadObj);
out=cJSON_Print(root); out=cJSON_Print(root);
kk_ipc_send(IPC_APP2MID, out, strlen(out)+1); kk_ipc_send(IPC_APP2MID, out, strlen(out));
cJSON_Delete(root); cJSON_Delete(root);
free(payloadStr); free(payloadStr);
free(infoStr); free(infoStr);
...@@ -401,6 +401,6 @@ void KK_Sendto_DevData(const char *topic,const char *data) ...@@ -401,6 +401,6 @@ void KK_Sendto_DevData(const char *topic,const char *data)
if(send_data == NULL){ if(send_data == NULL){
return; return;
} }
kk_ipc_send(IPC_APP2MID, send_data, strlen(send_data)+1); kk_ipc_send(IPC_APP2MID, send_data, strlen(send_data));
free(send_data); free(send_data);
} }
...@@ -100,7 +100,7 @@ static void watcher_cb (struct ev_loop *loop ,struct ev_io *w, int revents) ...@@ -100,7 +100,7 @@ static void watcher_cb (struct ev_loop *loop ,struct ev_io *w, int revents)
if (strncmp(validDat,MAGIC_ACK, strlen(MAGIC_ACK)) == 0){ if (strncmp(validDat,MAGIC_ACK, strlen(MAGIC_ACK)) == 0){
}else{ }else{
kk_ipc_send_ex(loop_ctrl->type, MAGIC_ACK, strlen(MAGIC_ACK)+1, chlMark); kk_ipc_send_ex(loop_ctrl->type, MAGIC_ACK, strlen(MAGIC_ACK), chlMark);
} }
loop_ctrl->isconnect =1; loop_ctrl->isconnect =1;
...@@ -453,7 +453,7 @@ int kk_ipc_isconnect(ipc_type type){ ...@@ -453,7 +453,7 @@ int kk_ipc_isconnect(ipc_type type){
{ {
for(int i =0; i<20;i++){ for(int i =0; i<20;i++){
kk_ipc_send(type, MAGIC, strlen(MAGIC)+1); kk_ipc_send(type, MAGIC, strlen(MAGIC));
usleep(500000); usleep(500000);
if (loop_ctrl->isconnect == 1){ if (loop_ctrl->isconnect == 1){
break; break;
......
This diff is collapsed.
...@@ -22,7 +22,7 @@ void kk_sendData2app(void *info, void *payload,int isAsync){ ...@@ -22,7 +22,7 @@ void kk_sendData2app(void *info, void *payload,int isAsync){
dm_queue_msg_insert4(buf); dm_queue_msg_insert4(buf);
}else{ }else{
kk_ipc_send(IPC_MID2APP, buf, strlen(buf) + 1); kk_ipc_send(IPC_MID2APP, buf, strlen(buf) );
free(buf); free(buf);
} }
cJSON_Delete(root); cJSON_Delete(root);
......
...@@ -153,7 +153,7 @@ void mid2p_cb(void* data, int len, char* chalMark){ ...@@ -153,7 +153,7 @@ void mid2p_cb(void* data, int len, char* chalMark){
void gw2mid_cb(void* data, int len, char* chalMark){ void gw2mid_cb(void* data, int len, char* chalMark){
if (data != NULL){ if (data != NULL){
printf("gw2mid_cb chalMark=%s, data: %s RECEIVED \r\n", chalMark, data); printf("gw2mid_cb chalMark=%s, data: %s [%d]RECEIVED \r\n", chalMark, data,len);
mid2p_cb(data,len,chalMark); mid2p_cb(data,len,chalMark);
} }
} }
......
...@@ -549,7 +549,7 @@ int OTA_publishProgress(void *handle, char* payload){ ...@@ -549,7 +549,7 @@ int OTA_publishProgress(void *handle, char* payload){
cJSON_AddStringToObject(root, "info", topicBuf); cJSON_AddStringToObject(root, "info", topicBuf);
cJSON_AddStringToObject(root, "payload", payload); cJSON_AddStringToObject(root, "payload", payload);
void *buf = cJSON_Print(root); void *buf = cJSON_Print(root);
kk_ipc_send(IPC_MID2APP, buf, strlen(buf) + 1); kk_ipc_send(IPC_MID2APP, buf, strlen(buf));
free(msgTypeStr); free(msgTypeStr);
free(topicBuf); free(topicBuf);
free(buf); free(buf);
......
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
...@@ -112,7 +113,7 @@ static int send_result_resp(cJSON * result, ...@@ -112,7 +113,7 @@ static int send_result_resp(cJSON * result,
char * str_result = rpc_cJSON_Print(result_root); char * str_result = rpc_cJSON_Print(result_root);
printf("send json:\n%s\n",str_result); printf("send json:\n%s\n",str_result);
return_value = kk_sendData2CCU(str_result, strlen(str_result)+1); return_value = kk_sendData2CCU(str_result, strlen(str_result));
free(str_result); free(str_result);
rpc_cJSON_Delete(result_root); rpc_cJSON_Delete(result_root);
return return_value; return return_value;
...@@ -154,7 +155,7 @@ static int send_error_resp(int code, char* message, ...@@ -154,7 +155,7 @@ static int send_error_resp(int code, char* message,
} }
char * str_result = rpc_cJSON_Print(result_root); char * str_result = rpc_cJSON_Print(result_root);
//printf("alla=========== :%d\n", strlen(str_result)+1); //printf("alla=========== :%d\n", strlen(str_result)+1);
return_value = kk_sendData2CCU(str_result, strlen(str_result)+1); return_value = kk_sendData2CCU(str_result, strlen(str_result));
printf("send_error_resp:\n%s\n", str_result); printf("send_error_resp:\n%s\n", str_result);
free(str_result); free(str_result);
rpc_cJSON_Delete(result_root); rpc_cJSON_Delete(result_root);
...@@ -227,7 +228,7 @@ static int eval_request(struct jrpc_server *server, cJSON *root) { ...@@ -227,7 +228,7 @@ static int eval_request(struct jrpc_server *server, cJSON *root) {
void _cb(void* data, int len, char* chlmark){ void _cb(void* data, int len, char* chlmark){
if (data != NULL){ if (data != NULL){
printf("plat_cb: %s RECEIVED \r\n", data); printf("plat_cb: %s [%d]RECEIVED \r\n", data,len);
cJSON *root; cJSON *root;
char *end_ptr = NULL; char *end_ptr = NULL;
...@@ -625,7 +626,7 @@ int jrpc_send_msg(cJSON * msgJson) { ...@@ -625,7 +626,7 @@ int jrpc_send_msg(cJSON * msgJson) {
return_value = kk_sendData2CCU(str_result, strlen(str_result)+1); return_value = kk_sendData2CCU(str_result, strlen(str_result));
free(str_result); free(str_result);
return return_value; return return_value;
} }
...@@ -1013,4 +1014,3 @@ void rpc_reportDevices(void) ...@@ -1013,4 +1014,3 @@ void rpc_reportDevices(void)
} }
rpc_report_devices(devicesJson); rpc_report_devices(devicesJson);
} }
\ No newline at end of file
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