Commit 0d796981 authored by 黄振令's avatar 黄振令

【修改内容】1. 通过info里的deviceCode与payload里的deviceCode来区分添加网关还是子设备

【提交人】huang.zhenling
parent e1d805f0
...@@ -156,21 +156,40 @@ void kk_platMsg_handle(void* data, char* chalMark){ ...@@ -156,21 +156,40 @@ void kk_platMsg_handle(void* data, char* chalMark){
else{ else{
info = cJSON_GetObjectItem(json, "info"); info = cJSON_GetObjectItem(json, "info");
payload = cJSON_GetObjectItem(json, "payload"); payload = cJSON_GetObjectItem(json, "payload");
if(info != NULL){ if (info == NULL || payload == NULL){
msgType = cJSON_GetObjectItem(info, "msgType"); ERROR_PRINT("info or payload params is error\n");
info_dcode = cJSON_GetObjectItem(info, "deviceCode"); goto error;
} }
if(payload != NULL){
jsonPay = cJSON_GetObjectItem(payload, "params"); msgType = cJSON_GetObjectItem(info, "msgType");
info_dcode = cJSON_GetObjectItem(info, "deviceCode");
jsonPay = cJSON_GetObjectItem(payload, "params");
if (msgType == NULL || info_dcode == NULL || jsonPay == NULL){
ERROR_PRINT("msgType info_dcode or jsonPay params are error\n");
goto error;
} }
if (info_dcode != NULL && msgType != NULL && strcmp(msgType->valuestring, "/thing/topo/add")==0){
proCode = cJSON_GetObjectItem(jsonPay, "productCode"); if (strcmp(msgType->valuestring, "/thing/topo/add")==0){
devCode = cJSON_GetObjectItem(jsonPay, "deviceCode"); proCode = cJSON_GetObjectItem(jsonPay, "productCode");
mac = cJSON_GetObjectItem(jsonPay, "mac"); devCode = cJSON_GetObjectItem(jsonPay, "deviceCode");
INFO_PRINT("deviceCode productCode mac: [%s][%s] [%s] \n",devCode->valuestring, proCode->valuestring, mac->valuestring); mac = cJSON_GetObjectItem(jsonPay, "mac");
if (proCode == NULL || devCode == NULL || mac == NULL){
ERROR_PRINT("productCode, deviceCode mac params are error\n");
goto error;
}
INFO_PRINT("deviceCode productCode mac: [%s][%s] [%s] \n",devCode->valuestring, proCode->valuestring, mac->valuestring);
//判断网关还是子设备
if (strcmp(info_dcode->valuestring, devCode->valuestring) == 0){
char ccu_deviceCode[DEVICE_CODE_MAXLEN] = {0};
HAL_GetDevice_Code(ccu_deviceCode);
kk_mid_subdev_add(KK_DM_DEVICE_GATEWAY,proCode->valuestring,devCode->valuestring, mac->valuestring,ccu_deviceCode);
}else{
kk_mid_subdev_add(KK_DM_DEVICE_SUBDEV,proCode->valuestring,devCode->valuestring, mac->valuestring,info_dcode->valuestring); kk_mid_subdev_add(KK_DM_DEVICE_SUBDEV,proCode->valuestring,devCode->valuestring, mac->valuestring,info_dcode->valuestring);
}
}else if (info_dcode != NULL && strstr(msgType->valuestring, "property/post") != NULL){ }else if (strstr(msgType->valuestring, "property/post") != NULL){
INFO_PRINT("save property and send to cloud \n"); INFO_PRINT("save property and send to cloud \n");
char* outstr = cJSON_Print(payload); char* outstr = cJSON_Print(payload);
kk_tsl_property_set_by_devicecode(info_dcode->valuestring, outstr, strlen(outstr)+1); kk_tsl_property_set_by_devicecode(info_dcode->valuestring, outstr, strlen(outstr)+1);
...@@ -181,6 +200,7 @@ void kk_platMsg_handle(void* data, char* chalMark){ ...@@ -181,6 +200,7 @@ void kk_platMsg_handle(void* data, char* chalMark){
//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);
} }
error:
cJSON_Delete(json); cJSON_Delete(json);
} }
} }
......
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