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

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

【提交人】陈伟灿
parent 4edd1128
......@@ -22,9 +22,11 @@
#define KK_FILTER_STATUS_ONLINE_REPLY "/thing/status/online_reply"
#define KK_FILTER_STATUS_OFFLINE "/thing/status/offline"
#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_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\"}";
#define KK_TOPIC_SERVICE_DELIMITER '/'
......@@ -202,6 +204,9 @@ static int _check_invalid_topic(const char* topic)
else if(strstr(topic, KK_FILTER_SET_TOPIC_REPLY) != NULL){
return 1;
}
else if(strstr(topic,KK_FILTER_TOPO_CHANEG_REPLY) != NULL){
return 1;
}
else if(strstr(topic, KK_FILTER_EVENT_POST_TOPIC) != NULL && \
strstr(topic,KK_FILTER_LOGIN_TOPIC_REPLY) == NULL){
return 1;
......@@ -273,7 +278,31 @@ static int _kk_topic_parse_pkdn(_IN_ char *topic, _IN_ int start_deli,
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)
{
cJSON *root;
......@@ -301,17 +330,20 @@ static char * _kk_data_create(const char *topic,const char *data)
cJSON* infoObj = cJSON_Parse(infoStr);
cJSON* payloadObj = cJSON_Parse(data);
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);
cJSON_Delete(root);
free(msgStr);
free(infoStr);
INFO_PRINT("[%s][%d]%s\n",__FUNCTION__,__LINE__,out);
return out;
//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\"}";
int KK_Send_CloudState(int state)
{
char *infoStr = NULL;
......
/*******************************************************************************
* Copyright (c) 2012, 2020 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* https://www.eclipse.org/legal/epl-2.0/
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Ian Craggs - initial contribution
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "MQTTAsync.h"
#include "mqtt_api.h"
#include "com_api.h"
#include "kk_product.h"
static int mqtt_start(void)
{
int count = 0;
MQTTAsync mqttClient;
int rc = 0;
mqttClient = KK_MQTT_Connect();
if(mqttClient == NULL)
{
WARNING_PRINT("KK_MQTT_Connect FAIL!!!\n");
}
else
{
INFO_PRINT("Waiting for publication of %s\n"
"on topic %s for client with ClientID: %s\n",
PAYLOAD, TOPIC, CLIENTID);
}
while(1)
{
usleep(100000L);
count++;
if(count>50)
{
count = 0;
//INFO_PRINT("i am send now\n");
//KK_MQTT_SendMsg(TOPIC,"hello my world",2);
}
}
INFO_PRINT("MQTTAsync_destroy\n");
MQTTAsync_destroy(&mqttClient);
return rc;
}
int main(int argc, char* argv[])
{
int rc = 0;
//KK_Data_Hdl_Init();
kk_zlog_init("kcloud");
/*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);
rc = mqtt_start();
return rc;
}
/*******************************************************************************
* Copyright (c) 2012, 2020 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* https://www.eclipse.org/legal/epl-2.0/
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Ian Craggs - initial contribution
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "MQTTAsync.h"
#include "mqtt_api.h"
#include "com_api.h"
#include "kk_product.h"
static int mqtt_start(void)
{
int count = 0;
MQTTAsync mqttClient;
int rc = 0;
mqttClient = KK_MQTT_Connect();
if(mqttClient == NULL)
{
WARNING_PRINT("KK_MQTT_Connect FAIL!!!\n");
}
else
{
INFO_PRINT("Waiting for publication of %s\n"
"on topic %s for client with ClientID: %s\n",
PAYLOAD, TOPIC, CLIENTID);
}
while(1)
{
usleep(100000L);
count++;
if(count>50)
{
count = 0;
//INFO_PRINT("i am send now\n");
//KK_MQTT_SendMsg(TOPIC,"hello my world",2);
}
}
INFO_PRINT("MQTTAsync_destroy\n");
MQTTAsync_destroy(&mqttClient);
return rc;
}
int main(int argc, char* argv[])
{
int rc = 0;
//KK_Data_Hdl_Init();
kk_zlog_init("kcloud");
/*set the callback to get the device date to cloud*/
kk_ipc_init(IPC_APP2MID,KK_Data_FromDev,NULL,NULL);
rc = mqtt_start();
return rc;
}
This diff is collapsed.
/*
* Copyright (C) 2020-2020 ikonke
*/
#ifndef _KK_COM_API_H_
#define _KK_COM_API_H_
#if defined(__cplusplus)
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "ev.h"
#include "nn.h"
#include "pair.h"
#include "pubsub.h"
#include "pipeline.h"
//=====kk======================
typedef enum {
IPC_APP2MID = 0,
IPC_MID2APP,
IPC_MID2PLAT,
IPC_PLAT2MID,
IPC_UNDEF
} ipc_type;
#define MSG_TYPE_STR "msgtype"
#define MSG_PRODUCT_TYPE_STR "productType"
#define MSG_PRODUCT_CODE_STR "productCode"
#define MSG_DEVICE_CODE_STR "deviceCode"
#define MSG_PAYLOAD_STR "payload"
#define MSG_INFO_STR "info"
#define MSG_INDENTIFIER_STR "identifier"
#define MSG_PARAMS_STR "params"
#define MSG_IOTClOUDSTATE_STR "IOTCloudState"
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_deinit(ipc_type type);
int kk_ipc_send(ipc_type type, void* data, int len);
int kk_ipc_send_ex(ipc_type type, void* data, int len, char* chalMark);
#if defined(__cplusplus)
}
#endif
#endif
/*
* Copyright (C) 2020-2020 ikonke
*/
#ifndef _KK_COM_API_H_
#define _KK_COM_API_H_
#if defined(__cplusplus)
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "ev.h"
#include "nn.h"
#include "pair.h"
#include "pubsub.h"
#include "pipeline.h"
//=====kk======================
typedef enum {
IPC_APP2MID = 0,
IPC_MID2APP,
IPC_MID2PLAT,
IPC_PLAT2MID,
IPC_UNDEF
} ipc_type;
#define MSG_TYPE_STR "msgtype"
#define MSG_PRODUCT_TYPE_STR "productType"
#define MSG_PRODUCT_CODE_STR "productCode"
#define MSG_DEVICE_CODE_STR "deviceCode"
#define MSG_PAYLOAD_STR "payload"
#define MSG_INFO_STR "info"
#define MSG_INDENTIFIER_STR "identifier"
#define MSG_PARAMS_STR "params"
#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);
int kk_ipc_init(ipc_type type, ipc_cb cb, char* chalMark, char* ip);
int kk_ipc_deinit(ipc_type type);
int kk_ipc_send(ipc_type type, void* data, int len);
int kk_ipc_send_ex(ipc_type type, void* data, int len, char* chalMark);
#if defined(__cplusplus)
}
#endif
#endif
#ifndef __KK_DM_MSG__
#define __KK_DM_MSG__
#include "kk_tsl_common.h"
#include "../tsl_handle/lite-cjson.h"
#define DM_MSG_KEY_ID "id"
#define DM_MSG_KEY_VERSION "version"
#define DM_MSG_KEY_METHOD "method"
#define DM_MSG_KEY_PARAMS "params"
#define DM_MSG_KEY_CODE "code"
#define DM_MSG_KEY_DATA "data"
#define DM_MSG_KEY_MESSAGE "message"
#define DM_MSG_VERSION "1.0"
#define DM_MSG_KEY_PRODUCT_KEY "productKey"
#define DM_MSG_KEY_DEVICE_NAME "deviceName"
#define DM_MSG_KEY_DEVICE_SECRET "deviceSecret"
#define DM_MSG_KEY_TIME "time"
#define DM_MSG_SIGN_METHOD_SHA256 "Sha256"
#define DM_MSG_SIGN_METHOD_HMACMD5 "hmacMd5"
#define DM_MSG_SIGN_METHOD_HMACSHA1 "hmacSha1"
#define DM_MSG_SIGN_METHOD_HMACSHA256 "hmacSha256"
typedef struct {
lite_cjson_t id;
lite_cjson_t code;
lite_cjson_t data;
lite_cjson_t message;
} dm_msg_response_payload_t;
#ifndef DM_READ_ONLY
#define DM_READ_ONLY
#endif
#define DM_MSG_VERSION "1.0"
const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_REGISTER_TOPIC_REPLY "/thing/sub/register_reply"
#define KK_ADD_TOPIC_REPLY "/thing/topo/add_reply"
#define KK_LOGIN_TOPIC_REPLY "/thing/combine/login_reply"
#define KK_ONLINE_TOPIC_REPLY "/thing/status/online_reply"
#define KK_THING_SERVICE_PROPERTY_SET "/thing/service/property/set"
#define KK_THING_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
#define KK_THING_CLOUDSTATE_MSG "/thing/ccu/cloudstate_reply"
#define KK_THING_TOPO_ADD_MSG "/thing/topo/add"
#define KK_THING_PROPERTY_POST "property/post"
#define KK_THING_TOPO_DELETE_MSG "/thing/topo/delete"
//const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/";
#endif
#ifndef __KK_DM_MSG__
#define __KK_DM_MSG__
#include "kk_tsl_common.h"
#include "../tsl_handle/lite-cjson.h"
#define DM_MSG_KEY_ID "id"
#define DM_MSG_KEY_VERSION "version"
#define DM_MSG_KEY_METHOD "method"
#define DM_MSG_KEY_PARAMS "params"
#define DM_MSG_KEY_CODE "code"
#define DM_MSG_KEY_DATA "data"
#define DM_MSG_KEY_MESSAGE "message"
#define DM_MSG_VERSION "1.0"
#define DM_MSG_KEY_PRODUCT_KEY "productKey"
#define DM_MSG_KEY_DEVICE_NAME "deviceName"
#define DM_MSG_KEY_DEVICE_SECRET "deviceSecret"
#define DM_MSG_KEY_TIME "time"
#define DM_MSG_SIGN_METHOD_SHA256 "Sha256"
#define DM_MSG_SIGN_METHOD_HMACMD5 "hmacMd5"
#define DM_MSG_SIGN_METHOD_HMACSHA1 "hmacSha1"
#define DM_MSG_SIGN_METHOD_HMACSHA256 "hmacSha256"
typedef struct {
lite_cjson_t id;
lite_cjson_t code;
lite_cjson_t data;
lite_cjson_t message;
} dm_msg_response_payload_t;
#ifndef DM_READ_ONLY
#define DM_READ_ONLY
#endif
#define DM_MSG_VERSION "1.0"
const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_REGISTER_TOPIC_REPLY "/thing/sub/register_reply"
#define KK_ADD_TOPIC_REPLY "/thing/topo/add_reply"
#define KK_LOGIN_TOPIC_REPLY "/thing/combine/login_reply"
#define KK_ONLINE_TOPIC_REPLY "/thing/status/online_reply"
#define KK_THING_SERVICE_PROPERTY_SET "/thing/service/property/set"
#define KK_THING_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
#define KK_THING_CLOUDSTATE_MSG "/thing/ccu/cloudstate_reply"
#define KK_THING_TOPO_ADD_MSG "/thing/topo/add"
#define KK_THING_PROPERTY_POST "property/post"
#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/";
#endif
......@@ -234,6 +234,31 @@ int kk_get_cloud_recv_status(void){
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)
{
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)
INFO_PRINT("ota upgrade... \n");
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");
}
......
......@@ -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)
{
......@@ -638,7 +630,6 @@ int main(const int argc, const char **argv)
kk_zlog_init("midware");
memset(mid_ctx, 0, sizeof(mid_ctx_t));
kk_set_product_info();
kk_tsl_api_init();
kk_ipc_init(IPC_MID2APP, mid_cb, NULL, NULL);
kk_ipc_init(IPC_MID2PLAT, mid2p_cb, NULL, "*");
......
#ifndef __KK_TSL_PROPERTY_SET_H
#define __KK_TSL_PROPERTY_SET_H
#include "kk_test.h"
cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON * params, cJSON *id,cJSON *mac);
int kk_tsl_set_gloabl_OnOff(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_windowCovering_OperationMode(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_windowCovering_mode(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_windowCovering_position(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
#endif
#ifndef __KK_TSL_PROPERTY_SET_H
#define __KK_TSL_PROPERTY_SET_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);
int kk_tsl_set_gloabl_OnOff(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_windowCovering_OperationMode(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_windowCovering_mode(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_windowCovering_position(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
#endif
#ifndef _KK_TEST_H
#define _KK_TEST_H
#include "rpc_network_operate.h"
#include "network-creator.h"
#include "network-creator-security.h"
#include "RPC_API.h"
#include "com_api.h"
#include "zb_device_id.h"
#include "kk_device_manager.h"
#include "kk_zigbee_api.h"
#include "kk_tsl_property_report.h"
#include "kk_tsl_property_set.h"
#define KK_REPORT_DEVICE_JOINED_TYPE "/thing/topo/add"
#define KK_REPORT_DEVICE_LEFT_TYPE "/thing/topo/delete"
#define KK_REPORT_ATTRIBUTE_TYPE "/thing/event/property/post"
#define KK_IPC_VERSION "1.0"
#define KK_REPORT_DEVICE_JOINED_METHOD "thing.topo.add"
#define KK_REPORT_DEVICE_LEAVE_METHOD "thing.topo.delete"
#define KK_REPORT_ATTRIBUTE_METHOD "thing.event.property.post"
#define KK_READ_ATTRIBUTE_METHOD "thing.service.property.get"
#define ZIGBEE_COO_PRODUCT_CODE "2"
#define TEST_PRODUCT_CODE "24"
#define GW2CCU_PROTOCOL "tcp"
int kk_zcl_onoff_set(jrpc_context * ctx,const char *mac,unsigned char ep,void* data);
int kk_sendData2CCU(char* data, int len);
#define RPC_KK_TEST_FUNCTION_TABLE \
{(rpc_function*)kk_tsl_property_operation,"/thing/service/property/set"},\
{(rpc_function*)kk_tsl_property_operation,KK_READ_ATTRIBUTE_METHOD}
enum {
WC_normal_dir = 0,//"正转"
WC_reversed_dir = 1,//"反转"
WC_calibration_mode = 2,//"校验"
}windowCoveringMode;
#endif
#ifndef _KK_TEST_H
#define _KK_TEST_H
#include "rpc_network_operate.h"
#include "network-creator.h"
#include "network-creator-security.h"
#include "RPC_API.h"
#include "com_api.h"
#include "zb_device_id.h"
#include "kk_device_manager.h"
#include "kk_zigbee_api.h"
#include "kk_tsl_property_report.h"
#include "kk_tsl_property_set.h"
#define KK_REPORT_DEVICE_JOINED_TYPE "/thing/topo/add"
#define KK_REPORT_DEVICE_LEFT_TYPE "/thing/topo/delete"
#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_REPORT_DEVICE_JOINED_METHOD "thing.topo.add"
#define KK_REPORT_DEVICE_LEAVE_METHOD "thing.topo.delete"
#define KK_REPORT_ATTRIBUTE_METHOD "thing.event.property.post"
#define KK_READ_ATTRIBUTE_METHOD "thing.service.property.get"
#define ZIGBEE_COO_PRODUCT_CODE "2"
#define TEST_PRODUCT_CODE "24"
#define GW2CCU_PROTOCOL "tcp"
#define MSG_TOPO_CHANGE_TYPE_STR "changeType"
#define MSG_TOPO_CHANGE_DEVICES_STR "devices"
int kk_zcl_onoff_set(jrpc_context * ctx,const char *mac,unsigned char ep,void* data);
int kk_sendData2CCU(char* data, int len);
#define RPC_KK_TEST_FUNCTION_TABLE \
{(rpc_function*)kk_tsl_property_operation,"/thing/service/property/set"},\
{(rpc_function*)kk_tsl_property_operation,KK_READ_ATTRIBUTE_METHOD},\
{(rpc_function*)kk_topo_change_operation,KK_DEVICE_TOPO_CHANGE_TYPE}
enum {
WC_normal_dir = 0,//"正转"
WC_reversed_dir = 1,//"反转"
WC_calibration_mode = 2,//"校验"
}windowCoveringMode;
#endif
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