Commit 00917ffc authored by 黄振令's avatar 黄振令

【修改内容】整理代码,解决platform消息处理错误

【提交人】黄振令
parent 6e247767
...@@ -30,9 +30,9 @@ ...@@ -30,9 +30,9 @@
#include "kk_product.h" #include "kk_product.h"
//#include "iot_import.h" //#include "iot_import.h"
char g_product_type[PRODUCT_TYPE_LEN]; char g_product_type[PRODUCT_TYPE_LEN]={0};
char g_product_code[PRODUCT_CODE_LEN]; char g_product_code[PRODUCT_CODE_LEN]={0};
char g_device_code[DEVICE_CODE_LEN]; char g_device_code[DEVICE_CODE_LEN] = {0};
#define PLATFORM_WAIT_INFINITE (~0) #define PLATFORM_WAIT_INFINITE (~0)
......
...@@ -267,8 +267,8 @@ int dm_mgr_search_mac_by_topic(_IN_ char* topic, _OU_ char mac[DEVI ...@@ -267,8 +267,8 @@ int dm_mgr_search_mac_by_topic(_IN_ char* topic, _OU_ char mac[DEVI
int res = 0; int res = 0;
dm_mgr_dev_node_t *node = NULL; dm_mgr_dev_node_t *node = NULL;
char product_key[PRODUCT_KEY_MAXLEN]; char product_key[PRODUCT_KEY_MAXLEN] = {0};
char device_name[DEVICE_NAME_MAXLEN]; char device_name[DEVICE_NAME_MAXLEN] = {0};
if (topic == NULL) { if (topic == NULL) {
return INVALID_PARAMETER; return INVALID_PARAMETER;
......
...@@ -144,7 +144,7 @@ int dm_queue_msg_insert(void *data) ...@@ -144,7 +144,7 @@ int dm_queue_msg_insert(void *data)
node = malloc(sizeof(dm_queue_msg_node_t)); node = malloc(sizeof(dm_queue_msg_node_t));
if (node == NULL) { if (node == NULL) {
_dm_queue_unlock(); _dm_queue_unlock();
return DM_MEMORY_NOT_ENOUGH; return MEMORY_NOT_ENOUGH;
} }
memset(node, 0, sizeof(dm_queue_msg_node_t)); memset(node, 0, sizeof(dm_queue_msg_node_t));
......
...@@ -20,10 +20,23 @@ ...@@ -20,10 +20,23 @@
void mid_cb(void* data, int len){ void mid_cb(void* data, int len){
if (data != NULL){ if (data != NULL){
printf("app2mid_cb: %s RECEIVED \r\n", data);
char *out;cJSON *json, *topic, *payload; char *out;
cJSON *json;
cJSON *topic;
cJSON*payload;
int res; int res;
void* buf = malloc(len);
memcpy(buf, data, len);
res = dm_queue_msg_insert((void *)buf);
if (res != SUCCESS_RETURN) {
free(buf);
//return FAIL_RETURN;
}
json=cJSON_Parse(data); json=cJSON_Parse(data);
if (!json) { if (!json) {
printf("Error before: [%s]\n","cJSON_Parse"); printf("Error before: [%s]\n","cJSON_Parse");
...@@ -31,31 +44,28 @@ void mid_cb(void* data, int len){ ...@@ -31,31 +44,28 @@ void mid_cb(void* data, int len){
else else
{ {
topic = cJSON_GetObjectItem(json, "topic"); topic = cJSON_GetObjectItem(json, "topic");
payload = cJSON_GetObjectItem(json, "payload"); if (topic != NULL && (strstr(topic->valuestring, "register_reply") != NULL ||
printf("mid_cb topic: [%s] ,payload= %s \n",topic->valuestring,payload->valuestring ); strstr(topic->valuestring, "add_reply") != NULL ||
if (strcmp(payload->valuestring, "addsub")==0){ strstr(topic->valuestring, "login_reply") != NULL ||
//kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq",""); strstr(topic->valuestring, "offline_reply") != NULL))
}else{ {
void* buf = malloc(len); printf("This topic don't send to platform: %s \r\n", topic->valuestring);
memcpy(buf, data, len); return;
int res = dm_queue_msg_insert((void *)buf);
if (res != SUCCESS_RETURN) {
free(buf);
//return FAIL_RETURN;
}
//kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
} }
char mac[DEVICE_MAC_MAXLEN];
payload = cJSON_GetObjectItem(json, "payload");
char mac[DEVICE_MAC_MAXLEN] = {0};
res =dm_mgr_search_mac_by_topic(topic->valuestring, mac); res =dm_mgr_search_mac_by_topic(topic->valuestring, mac);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
return; return;
} }
printf("dm_mgr_search_mac_by_topic mac: %s \r\n", mac);
cJSON * jsonplay=cJSON_Parse(payload->valuestring); cJSON * jsonplay=cJSON_Parse(payload->valuestring);
cJSON_AddStringToObject(jsonplay, "mac", mac); cJSON_AddStringToObject(jsonplay, "mac", mac);
void* out = cJSON_Print(jsonplay); void* out = cJSON_Print(jsonplay);
printf("dm_mgr_search_mac_by_topic out: %s \r\n", out);
kk_ipc_send(IPC_MID2PLAT, out, strlen(out)); kk_ipc_send(IPC_MID2PLAT, out, strlen(out));
free(out); free(out);
cJSON_Delete(jsonplay); cJSON_Delete(jsonplay);
...@@ -69,7 +79,7 @@ void mid_cb(void* data, int len){ ...@@ -69,7 +79,7 @@ void mid_cb(void* data, int len){
void mid2p_cb(void* data, int len){ void mid2p_cb(void* data, int len){
if (data != NULL){ if (data != NULL){
printf("mid2plat_cb: %s RECEIVED \r\n", data); //printf("mid2plat_cb: %s RECEIVED \r\n", data);
void* buf = malloc(len); void* buf = malloc(len);
memcpy(buf, data, len); memcpy(buf, data, len);
int res = dm_queue_msg_insert2((void *)buf); int res = dm_queue_msg_insert2((void *)buf);
...@@ -86,7 +96,13 @@ void kk_platMsg_handle(void* data){ ...@@ -86,7 +96,13 @@ void kk_platMsg_handle(void* data){
char *out; char *out;
int res = 0; int res = 0;
cJSON *json, *method, *params; cJSON *json;
cJSON *method;
cJSON *params;
cJSON *jsonPay;
cJSON *proType;
cJSON *proCode;
cJSON *mac;
json=cJSON_Parse(data); json=cJSON_Parse(data);
if (!json) { if (!json) {
...@@ -94,32 +110,23 @@ void kk_platMsg_handle(void* data){ ...@@ -94,32 +110,23 @@ void kk_platMsg_handle(void* data){
} }
else{ else{
method = cJSON_GetObjectItem(json, "method"); method = cJSON_GetObjectItem(json, "method");
mac = cJSON_GetObjectItem(json, "mac");
if (method != NULL && strcmp(method->valuestring, "thing.topo.add")==0){ if (method != NULL && strcmp(method->valuestring, "thing.topo.add")==0){
cJSON *jsonPay, *proType, *proCode, *mac;
params = cJSON_GetObjectItem(json, "params"); jsonPay = cJSON_GetObjectItem(json, "params");
jsonPay =cJSON_Parse(params->valuestring); proType = cJSON_GetObjectItem(jsonPay, "productType");
proCode = cJSON_GetObjectItem(jsonPay, "productCode");
if (!jsonPay) { printf("productType productCode mac: [%s][%s] [%s] \n",proType->valuestring, proCode->valuestring, mac->valuestring);
printf("Error before: [%s]\n","cJSON_Parse"); kk_set_tsl_by_productKey(proType->valuestring,"model.json");
}else{ kk_mid_subdev_add(proType->valuestring,proCode->valuestring,"", mac->valuestring);
proType = cJSON_GetObjectItem(jsonPay, "productType");
proCode = cJSON_GetObjectItem(jsonPay, "productCode");
mac = cJSON_GetObjectItem(jsonPay, "mac");
printf("productType productCode : [%s][%s]\n",proType, proCode);
kk_set_tsl_by_productKey(proCode->valuestring,"model.json");
kk_mid_subdev_add(proType->valuestring,proCode->valuestring,"", mac->valuestring);
cJSON_Delete(jsonPay);
}
}else if (method != NULL && strcmp(method->valuestring, "thing.event.property.post")==0){ }else if (method != NULL && mac != NULL){
cJSON *mac; printf("save property and send to cloud \n");
mac = cJSON_GetObjectItem(json, "mac"); kk_tsl_property_set_byMac(mac->valuestring, data, strlen(data)+1);
//kk_tsl_service_property_set(topic->valuestring, data, strlen(data), NULL);
}else{ }else{
printf("kk_platMsg_handle data: [%s]\n",data); printf("kk_platMsg_handle data: don't handle it [%s]\n",data);
//kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL); //kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
} }
...@@ -275,25 +282,19 @@ int main(const int argc, const char **argv) ...@@ -275,25 +282,19 @@ int main(const int argc, const char **argv)
IOT_Linkkit_Close(mid_ctx->master_devid); IOT_Linkkit_Close(mid_ctx->master_devid);
return -1; return -1;
} }
char buf[100] = {0};
int ct = 0; int ct = 0;
for (;;) { for (;;) {
usleep(4000000); usleep(200000);
kk_platMsg_dispatch();
if (ct == 0){ if (ct == 0){
ct =1; ct =1;
void* buf = "{ \"msgId\": \"7\", \"version\": \"1.0\", \"mac\": \"588E81FFFED3834A\", \"method\": \"thing.topo.add\", \"params\": { \"AppVersion\": \"10\", \"deviceType\": \"1\", \"deviceCode\": \"2\", \"productType\": \"3\", \"productCode\": \"4\" }}";
kk_set_tsl_by_productKey("a1OYuSallan","model.json"); kk_platMsg_handle(buf);
kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq","","aabbccddeeff1122"); //kk_set_tsl_by_productKey("a1OYuSallan","model.json");
//kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq","","aabbccddeeff1122");
} }
/*memset(buf, 0, 100);
sprintf(buf , "send data app time = %d\n", getSysTime());
printf("M2A: %s", buf);
kk_ipc_send(IPC_MID2APP, buf, strlen(buf)+1);
memset(buf, 0, 100);
sprintf(buf, "send data to plat time = %d\n", getSysTime());
printf("M2P: %s", buf);
kk_ipc_send(IPC_MID2PLAT, buf, strlen(buf) + 1);*/
} }
} }
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