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

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

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