Commit 490a67cf authored by chen.weican's avatar chen.weican

【修改内容】添加APP端主动删除子设备的消息处理

【提交人】陈伟灿
parent 4edd1128
...@@ -22,9 +22,11 @@ ...@@ -22,9 +22,11 @@
#define KK_FILTER_STATUS_ONLINE_REPLY "/thing/status/online_reply" #define KK_FILTER_STATUS_ONLINE_REPLY "/thing/status/online_reply"
#define KK_FILTER_STATUS_OFFLINE "/thing/status/offline" #define KK_FILTER_STATUS_OFFLINE "/thing/status/offline"
#define KK_FILTER_STATUS_OFFLINE_REPLY "/thing/status/offline_reply" #define KK_FILTER_STATUS_OFFLINE_REPLY "/thing/status/offline_reply"
#define KK_FILTER_TOPO_CHANEG_REPLY "/thing/topo/change_reply"
#define KK_CLOUDSTATE_MSG "/thing/ccu/cloudstate" #define KK_CLOUDSTATE_MSG "/thing/ccu/cloudstate"
#define KK_CLOUDSTATE_MSG_REPLY "/thing/ccu/cloudstate_reply" #define KK_CLOUDSTATE_MSG_REPLY "/thing/ccu/cloudstate_reply"
#define KK_TOPO_CHANGE_MSG_STR "/thing/topo/change"
const char DM_MSG_TO_MIDDWARE[] = "{\"msgtype\":\"%s\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"}"; const char DM_MSG_TO_MIDDWARE[] = "{\"msgtype\":\"%s\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"}";
#define KK_TOPIC_SERVICE_DELIMITER '/' #define KK_TOPIC_SERVICE_DELIMITER '/'
...@@ -202,6 +204,9 @@ static int _check_invalid_topic(const char* topic) ...@@ -202,6 +204,9 @@ static int _check_invalid_topic(const char* topic)
else if(strstr(topic, KK_FILTER_SET_TOPIC_REPLY) != NULL){ else if(strstr(topic, KK_FILTER_SET_TOPIC_REPLY) != NULL){
return 1; return 1;
} }
else if(strstr(topic,KK_FILTER_TOPO_CHANEG_REPLY) != NULL){
return 1;
}
else if(strstr(topic, KK_FILTER_EVENT_POST_TOPIC) != NULL && \ else if(strstr(topic, KK_FILTER_EVENT_POST_TOPIC) != NULL && \
strstr(topic,KK_FILTER_LOGIN_TOPIC_REPLY) == NULL){ strstr(topic,KK_FILTER_LOGIN_TOPIC_REPLY) == NULL){
return 1; return 1;
...@@ -273,7 +278,31 @@ static int _kk_topic_parse_pkdn(_IN_ char *topic, _IN_ int start_deli, ...@@ -273,7 +278,31 @@ static int _kk_topic_parse_pkdn(_IN_ char *topic, _IN_ int start_deli,
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
static int _kk_topo_change_handle(cJSON *payload)
{
cJSON *paramStr = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
if(paramStr == NULL){
ERROR_PRINT("[%s][%d]\n",__FUNCTION__,__LINE__);
return RETURN_FAIL;
}
cJSON *state = cJSON_GetObjectItem(paramStr, MSG_TOPO_CHANGE_TYPE_STR);
if(state != NULL && state->valueint == 1){
cJSON *deviceArray = cJSON_GetObjectItem(paramStr, MSG_TOPO_CHANGE_DEVICES_STR);
if(deviceArray == NULL){
ERROR_PRINT("[%s][%d]\n",__FUNCTION__,__LINE__);
return RETURN_FAIL;
}
cJSON * item = deviceArray->child;
while(item != NULL){
char *deviceCode = cJSON_GetObjectItem(item,MSG_DEVICE_CODE_STR)->valuestring;
char *productCode = cJSON_GetObjectItem(item,MSG_PRODUCT_CODE_STR)->valuestring;
KK_Subdev_UnSubscribe_By_DeviceCode(deviceCode,productCode);
item = item->next;
}
}
return RETURN_SUCCESS;
}
static char * _kk_data_create(const char *topic,const char *data) static char * _kk_data_create(const char *topic,const char *data)
{ {
cJSON *root; cJSON *root;
...@@ -302,16 +331,19 @@ static char * _kk_data_create(const char *topic,const char *data) ...@@ -302,16 +331,19 @@ static char * _kk_data_create(const char *topic,const char *data)
cJSON* payloadObj = cJSON_Parse(data); cJSON* payloadObj = cJSON_Parse(data);
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);
if(strstr(topic,KK_TOPO_CHANGE_MSG_STR)){
_kk_topo_change_handle(payloadObj);
}
out=cJSON_Print(root); out=cJSON_Print(root);
cJSON_Delete(root); cJSON_Delete(root);
free(msgStr); free(msgStr);
free(infoStr); free(infoStr);
INFO_PRINT("[%s][%d]%s\n",__FUNCTION__,__LINE__,out); INFO_PRINT("[%s][%d]%s\n",__FUNCTION__,__LINE__,out);
return out; return out;
//free(out); /* Print to text, Delete the cJSON, print it, release the string. */ //free(out); /* Print to text, Delete the cJSON, print it, release the string. */
} }
const char DM_MSG_CLOUDSTATE[] = "{\"msgId\":\"1\",\"version\":\"1.0\",\"params\":{\"IOTCloudState\":\"%d\"},\"method\":\"thing.ccu.cloudstate_reply\"}"; const char DM_MSG_CLOUDSTATE[] = "{\"msgId\":\"1\",\"version\":\"1.0\",\"params\":{\"IOTCloudState\":\"%d\"},\"method\":\"thing.ccu.cloudstate_reply\"}";
int KK_Send_CloudState(int state) int KK_Send_CloudState(int state)
{ {
char *infoStr = NULL; char *infoStr = NULL;
......
...@@ -66,8 +66,6 @@ int main(int argc, char* argv[]) ...@@ -66,8 +66,6 @@ int main(int argc, char* argv[])
kk_zlog_init("kcloud"); kk_zlog_init("kcloud");
/*set the callback to get the device date to cloud*/ /*set the callback to get the device date to cloud*/
HAL_SetProduct_Type(PRODUCT_TPYE);
HAL_SetProduct_Code(PRODUCT_CODE);
kk_ipc_init(IPC_APP2MID,KK_Data_FromDev,NULL,NULL); kk_ipc_init(IPC_APP2MID,KK_Data_FromDev,NULL,NULL);
rc = mqtt_start(); rc = mqtt_start();
......
...@@ -135,12 +135,29 @@ static int _kk_utils_topic(_IN_ const char *name, _IN_ char *product_code, ...@@ -135,12 +135,29 @@ static int _kk_utils_topic(_IN_ const char *name, _IN_ char *product_code,
return 0; return 0;
} }
int KK_Subdev_UnSubscribe(cJSON *payload)
int KK_Subdev_UnSubscribe_By_DeviceCode(const char *deviceCode,const char *productCode )
{ {
cJSON *params,*productCode,*deviceCode;
char *topic = NULL; char *topic = NULL;
int topic_len = 0; int topic_len = 0;
topic_len = strlen(KK_URI_SYS_PREFIX) + strlen(productCode)+strlen(deviceCode) + 1;
topic = malloc(topic_len);
if (topic == NULL) {
return -1;
}
memset(topic,0,topic_len);
snprintf(topic, topic_len, KK_URI_SYS_PREFIX, productCode,deviceCode);
INFO_PRINT("[%s][%d] TOPIC:%s\n",__FUNCTION__,__LINE__,topic);
KK_MQTT_UnsubTopic(topic);
free(topic);
return 0;
}
int KK_Subdev_UnSubscribe(cJSON *payload)
{
cJSON *params,*productCode,*deviceCode;
if(payload == NULL){ if(payload == NULL){
goto errorreturn; goto errorreturn;
} }
...@@ -156,17 +173,8 @@ int KK_Subdev_UnSubscribe(cJSON *payload) ...@@ -156,17 +173,8 @@ int KK_Subdev_UnSubscribe(cJSON *payload)
if(deviceCode == NULL){ if(deviceCode == NULL){
goto errorreturn; goto errorreturn;
} }
KK_Subdev_UnSubscribe_By_DeviceCode(deviceCode->valuestring,productCode->valuestring);
topic_len = strlen(KK_URI_SYS_PREFIX) + strlen(productCode->valuestring)+strlen(deviceCode->valuestring) + 1;
topic = malloc(topic_len);
if (topic == NULL) {
goto errorreturn;
}
memset(topic,0,topic_len);
snprintf(topic, topic_len, KK_URI_SYS_PREFIX, productCode->valuestring,deviceCode->valuestring);
INFO_PRINT("[%s][%d] TOPIC:%s\n",__FUNCTION__,__LINE__,topic);
KK_MQTT_UnsubTopic(topic);
free(topic);
return 0; return 0;
errorreturn: errorreturn:
return -1; return -1;
......
...@@ -37,6 +37,8 @@ typedef enum { ...@@ -37,6 +37,8 @@ typedef enum {
#define MSG_INDENTIFIER_STR "identifier" #define MSG_INDENTIFIER_STR "identifier"
#define MSG_PARAMS_STR "params" #define MSG_PARAMS_STR "params"
#define MSG_IOTClOUDSTATE_STR "IOTCloudState" #define MSG_IOTClOUDSTATE_STR "IOTCloudState"
#define MSG_TOPO_CHANGE_TYPE_STR "changeType"
#define MSG_TOPO_CHANGE_DEVICES_STR "devices"
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);
......
...@@ -51,6 +51,7 @@ const char DM_MSG_INFO[] DM_READ_ONLY; ...@@ -51,6 +51,7 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_THING_TOPO_ADD_MSG "/thing/topo/add" #define KK_THING_TOPO_ADD_MSG "/thing/topo/add"
#define KK_THING_PROPERTY_POST "property/post" #define KK_THING_PROPERTY_POST "property/post"
#define KK_THING_TOPO_DELETE_MSG "/thing/topo/delete" #define KK_THING_TOPO_DELETE_MSG "/thing/topo/delete"
#define KK_THING_TOPO_CHANGE_MSG "/thing/topo/change"
//const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/"; //const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/";
......
...@@ -234,6 +234,31 @@ int kk_get_cloud_recv_status(void){ ...@@ -234,6 +234,31 @@ int kk_get_cloud_recv_status(void){
return s_CloudStatusRecv; return s_CloudStatusRecv;
} }
static int _iotx_linkkit_delete_handle(cJSON *payload)
{
if(payload == NULL){
return FAIL_RETURN;
}
cJSON *paramStr = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
cJSON *state = cJSON_GetObjectItem(paramStr, MSG_TOPO_CHANGE_TYPE_STR);
if(state != NULL && state->valueint == 1){
cJSON *deviceArray = cJSON_GetObjectItem(paramStr, MSG_TOPO_CHANGE_DEVICES_STR);
if(deviceArray == NULL){
return FAIL_RETURN;
}
cJSON * item = deviceArray->child;
while(item != NULL){
char *deviceCode = cJSON_GetObjectItem(item,MSG_DEVICE_CODE_STR)->valuestring;
dm_mgr_subdev_delete(deviceCode);
item = item->next;
}
}
return SUCCESS_RETURN;
}
static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
{ {
INFO_PRINT("_iotx_linkkit_event_callback ================== [%s]\n",data); INFO_PRINT("_iotx_linkkit_event_callback ================== [%s]\n",data);
...@@ -331,7 +356,12 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -331,7 +356,12 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
INFO_PRINT("ota upgrade... \n"); INFO_PRINT("ota upgrade... \n");
kk_dm_ota_send(data, strlen(data)+1); kk_dm_ota_send(data, strlen(data)+1);
}else{ }else if(strstr(typeJson->valuestring,KK_THING_TOPO_CHANGE_MSG)){
INFO_PRINT(" topo change \n");
_iotx_linkkit_delete_handle(payload);
}
else{
INFO_PRINT("Error 222222222222222 \n"); INFO_PRINT("Error 222222222222222 \n");
} }
......
...@@ -618,14 +618,6 @@ void *ccu_property_monitor(void *args) ...@@ -618,14 +618,6 @@ void *ccu_property_monitor(void *args)
} }
static int kk_set_product_info(void)
{
HAL_SetProduct_Type(PRODUCT_TPYE);
HAL_SetProduct_Code(PRODUCT_CODE);
return 0;
}
int main(const int argc, const char **argv) int main(const int argc, const char **argv)
{ {
...@@ -638,7 +630,6 @@ int main(const int argc, const char **argv) ...@@ -638,7 +630,6 @@ int main(const int argc, const char **argv)
kk_zlog_init("midware"); kk_zlog_init("midware");
memset(mid_ctx, 0, sizeof(mid_ctx_t)); memset(mid_ctx, 0, sizeof(mid_ctx_t));
kk_set_product_info();
kk_tsl_api_init(); kk_tsl_api_init();
kk_ipc_init(IPC_MID2APP, mid_cb, NULL, NULL); kk_ipc_init(IPC_MID2APP, mid_cb, NULL, NULL);
kk_ipc_init(IPC_MID2PLAT, mid2p_cb, NULL, "*"); kk_ipc_init(IPC_MID2PLAT, mid2p_cb, NULL, "*");
......
...@@ -4,6 +4,39 @@ ...@@ -4,6 +4,39 @@
//emberAfAppPrintln("[tsl report:Gloabl] OnOff~~~~~~~~~"); //emberAfAppPrintln("[tsl report:Gloabl] OnOff~~~~~~~~~");
//cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac) //cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac)
cJSON *kk_topo_change_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac)
{
int res = 0;
cJSON *changeTypeStr = NULL;
UTIL_LOG_INFO("\n********************kk_topo_change_operation********************\n");
if(params == NULL){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}else{
changeTypeStr = rpc_cJSON_GetObjectItem(params, MSG_TOPO_CHANGE_TYPE_STR);
if(changeTypeStr != NULL && changeTypeStr->valueint == 1){
cJSON *deviceArray = rpc_cJSON_GetObjectItem(params, MSG_TOPO_CHANGE_DEVICES_STR);
if(deviceArray == NULL){
goto error_return;
}
cJSON * item = deviceArray->child;
while(item != NULL){
char *deviceCode = rpc_cJSON_GetObjectItem(item,MSG_DEVICE_CODE_STR)->valuestring;
item = item->next;
}
}
}
return rpc_cJSON_CreateNumber(res);
error_return:
return rpc_cJSON_CreateNull();
}
cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac) cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac)
{ {
sub_dev_node_t *node = NULL; sub_dev_node_t *node = NULL;
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#define __KK_TSL_PROPERTY_SET_H #define __KK_TSL_PROPERTY_SET_H
#include "kk_test.h" #include "kk_test.h"
cJSON *kk_topo_change_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac);
cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON * params, cJSON *id,cJSON *mac); cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON * params, cJSON *id,cJSON *mac);
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#define KK_REPORT_DEVICE_JOINED_TYPE "/thing/topo/add" #define KK_REPORT_DEVICE_JOINED_TYPE "/thing/topo/add"
#define KK_REPORT_DEVICE_LEFT_TYPE "/thing/topo/delete" #define KK_REPORT_DEVICE_LEFT_TYPE "/thing/topo/delete"
#define KK_REPORT_ATTRIBUTE_TYPE "/thing/event/property/post" #define KK_REPORT_ATTRIBUTE_TYPE "/thing/event/property/post"
#define KK_DEVICE_TOPO_CHANGE_TYPE "/thing/topo/change"
#define KK_IPC_VERSION "1.0" #define KK_IPC_VERSION "1.0"
#define KK_REPORT_DEVICE_JOINED_METHOD "thing.topo.add" #define KK_REPORT_DEVICE_JOINED_METHOD "thing.topo.add"
...@@ -26,6 +27,8 @@ ...@@ -26,6 +27,8 @@
#define TEST_PRODUCT_CODE "24" #define TEST_PRODUCT_CODE "24"
#define GW2CCU_PROTOCOL "tcp" #define GW2CCU_PROTOCOL "tcp"
#define MSG_TOPO_CHANGE_TYPE_STR "changeType"
#define MSG_TOPO_CHANGE_DEVICES_STR "devices"
...@@ -44,7 +47,8 @@ int kk_sendData2CCU(char* data, int len); ...@@ -44,7 +47,8 @@ int kk_sendData2CCU(char* data, int len);
#define RPC_KK_TEST_FUNCTION_TABLE \ #define RPC_KK_TEST_FUNCTION_TABLE \
{(rpc_function*)kk_tsl_property_operation,"/thing/service/property/set"},\ {(rpc_function*)kk_tsl_property_operation,"/thing/service/property/set"},\
{(rpc_function*)kk_tsl_property_operation,KK_READ_ATTRIBUTE_METHOD} {(rpc_function*)kk_tsl_property_operation,KK_READ_ATTRIBUTE_METHOD},\
{(rpc_function*)kk_topo_change_operation,KK_DEVICE_TOPO_CHANGE_TYPE}
......
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