Commit e31335ef authored by chen.weican's avatar chen.weican

【修改内容】调整topic的处理,所有topic在app层处理,以应对不同topic规则。

【提交人】陈伟灿
parent be59c2bf
...@@ -104,8 +104,8 @@ void onConnect(void* context, MQTTAsync_successData* response) ...@@ -104,8 +104,8 @@ void onConnect(void* context, MQTTAsync_successData* response)
int messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message) int messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
{ {
/* not expecting any messages */ /* not expecting any messages */
INFO_PRINT("onMessageArrived topic:%s,message length:%d.\n",topicName,message->payloadlen); //INFO_PRINT("onMessageArrived topic:%s,message length:%d.\n",topicName,message->payloadlen);
INFO_PRINT("payload:%s,\n",message->payload); //INFO_PRINT("payload:%s,\n",message->payload);
KK_MQTT_RecvMsg(topicName,message->payload); KK_MQTT_RecvMsg(topicName,message->payload);
MQTTAsync_freeMessage(&message); MQTTAsync_freeMessage(&message);
MQTTAsync_free(topicName); MQTTAsync_free(topicName);
......
...@@ -27,6 +27,21 @@ typedef enum { ...@@ -27,6 +27,21 @@ typedef enum {
IPC_UNDEF IPC_UNDEF
} ipc_type; } ipc_type;
typedef enum{
MSG_REGISTER = 0,
MSG_UNREGISTER,
MSG_TOPOADD,
MSG_TOPODELETE,
MSG_TOPOGET,
MSG_LISTFOUND,
MSG_LOGIN,
MSG_LOGOUT,
MSG_PROPERTYPOST,
MSG_EVENTPOST,
MSG_SERVICERESPONSE,
MSG_SETREPLY,
}kk_msg_type_t;
typedef void ipc_cb(void* data, int len); typedef void ipc_cb(void* data, int len);
int kk_ipc_init(ipc_type type, ipc_cb cb); int kk_ipc_init(ipc_type type, ipc_cb cb);
int kk_ipc_dinit(); int kk_ipc_dinit();
......
...@@ -17,37 +17,6 @@ const char DM_URI_REPLY_SUFFIX[] DM_READ_ONLY = "_reply"; ...@@ -17,37 +17,6 @@ const char DM_URI_REPLY_SUFFIX[] DM_READ_ONLY = "_reply";
const char DM_URI_OTA_DEVICE_INFORM[] DM_READ_ONLY = "/ota/device/inform/%s/%s"; const char DM_URI_OTA_DEVICE_INFORM[] DM_READ_ONLY = "/ota/device/inform/%s/%s";
/* From Cloud To Local Request And Response*/
const char DM_URI_THING_TOPO_ADD_NOTIFY[] DM_READ_ONLY = "thing/topo/add/notify";
const char DM_URI_THING_TOPO_ADD_NOTIFY_REPLY[] DM_READ_ONLY = "thing/topo/add/notify_reply";
const char DM_URI_THING_DELETE[] DM_READ_ONLY = "thing/delete";
const char DM_URI_THING_DELETE_REPLY[] DM_READ_ONLY = "thing/delete_reply";
const char DM_URI_THING_DISABLE[] DM_READ_ONLY = "thing/disable";
const char DM_URI_THING_DISABLE_REPLY[] DM_READ_ONLY = "thing/disable_reply";
const char DM_URI_THING_ENABLE[] DM_READ_ONLY = "thing/enable";
const char DM_URI_THING_ENABLE_REPLY[] DM_READ_ONLY = "thing/enable_reply";
const char DM_URI_THING_GATEWAY_PERMIT[] DM_READ_ONLY = "thing/gateway/permit";
const char DM_URI_THING_GATEWAY_PERMIT_REPLY[] DM_READ_ONLY = "thing/gateway/permit_reply";
/* From Local To Cloud Request And Response*/
const char DM_URI_THING_SUB_REGISTER[] DM_READ_ONLY = "thing/sub/register";
const char DM_URI_THING_SUB_REGISTER_REPLY[] DM_READ_ONLY = "thing/sub/register_reply";
const char DM_URI_THING_SUB_UNREGISTER[] DM_READ_ONLY = "thing/sub/unregister";
const char DM_URI_THING_SUB_UNREGISTER_REPLY[] DM_READ_ONLY = "thing/sub/unregister_reply";
const char DM_URI_THING_TOPO_ADD[] DM_READ_ONLY = "thing/topo/add";
const char DM_URI_THING_TOPO_ADD_REPLY[] DM_READ_ONLY = "thing/topo/add_reply";
const char DM_URI_THING_TOPO_DELETE[] DM_READ_ONLY = "thing/topo/delete";
const char DM_URI_THING_TOPO_DELETE_REPLY[] DM_READ_ONLY = "thing/topo/delete_reply";
const char DM_URI_THING_TOPO_GET[] DM_READ_ONLY = "thing/topo/get";
const char DM_URI_THING_TOPO_GET_REPLY[] DM_READ_ONLY = "thing/topo/get_reply";
const char DM_URI_THING_LIST_FOUND[] DM_READ_ONLY = "thing/list/found";
const char DM_URI_THING_LIST_FOUND_REPLY[] DM_READ_ONLY = "thing/list/found_reply";
const char DM_URI_COMBINE_LOGIN[] DM_READ_ONLY = "combine/login";
const char DM_URI_COMBINE_LOGIN_REPLY[] DM_READ_ONLY = "combine/login_reply";
const char DM_URI_COMBINE_LOGOUT[] DM_READ_ONLY = "combine/logout";
const char DM_URI_COMBINE_LOGOUT_REPLY[] DM_READ_ONLY = "combine/logout_reply";
static dm_mgr_ctx g_dm_mgr = {0}; static dm_mgr_ctx g_dm_mgr = {0};
static dm_mgr_ctx *_dm_mgr_get_ctx(void) static dm_mgr_ctx *_dm_mgr_get_ctx(void)
{ {
...@@ -432,8 +401,8 @@ int dm_mgr_deinit(void) ...@@ -432,8 +401,8 @@ int dm_mgr_deinit(void)
const char DM_MSG_THING_UPSTREAM_REQUEST_PARAMS[] DM_READ_ONLY = const char DM_MSG_THING_UPSTREAM_REQUEST_PARAMS[] DM_READ_ONLY =
"{\"value\":%s,\"timestamp\":\"%s\"}"; "{\"value\":%s,\"timestamp\":\"%s\"}";
static int _dm_mgr_upstream_request_assemble(_IN_ int msgid, _IN_ int devid, _IN_ const char *service_prefix, static int _dm_mgr_upstream_request_assemble(_IN_ int msgid, _IN_ int devid,
_IN_ const char *service_name, _IN_ int msgtype, _IN_ char *identify,
_IN_ char *params, _IN_ int params_len, _IN_ char *method, _OU_ dm_msg_request_t *request) _IN_ char *params, _IN_ int params_len, _IN_ char *method, _OU_ dm_msg_request_t *request)
{ {
int res = 0; int res = 0;
...@@ -461,8 +430,12 @@ static int _dm_mgr_upstream_request_assemble(_IN_ int msgid, _IN_ int devid, _IN ...@@ -461,8 +430,12 @@ static int _dm_mgr_upstream_request_assemble(_IN_ int msgid, _IN_ int devid, _IN
request->msgid = msgid; request->msgid = msgid;
request->devid = devid; request->devid = devid;
request->service_prefix = service_prefix; request->msgtype = msgtype;
request->service_name = service_name; memset(request->identity,0x0,sizeof(request->identity));
if(strlen(identify) < IDENTIFY_MAXLEN)
{
memcpy(request->identity,identify,strlen(identify));
}
memcpy(request->product_key, node->product_key, strlen(node->product_key)); memcpy(request->product_key, node->product_key, strlen(node->product_key));
memcpy(request->device_name, node->device_name, strlen(node->device_name)); memcpy(request->device_name, node->device_name, strlen(node->device_name));
request->params = payload_param; request->params = payload_param;
...@@ -488,7 +461,7 @@ int dm_mgr_upstream_thing_property_post(_IN_ int devid, _IN_ char *payload, _IN_ ...@@ -488,7 +461,7 @@ int dm_mgr_upstream_thing_property_post(_IN_ int devid, _IN_ char *payload, _IN_
} }
memset(&request, 0, sizeof(dm_msg_request_t)); memset(&request, 0, sizeof(dm_msg_request_t));
res = _dm_mgr_upstream_request_assemble(iotx_report_id(), devid, DM_URI_SYS_PREFIX, DM_URI_THING_EVENT_PROPERTY_POST, res = _dm_mgr_upstream_request_assemble(iotx_report_id(), devid, MSG_PROPERTYPOST, "",
payload, payload_len, DM_URI_THING_EVENT_PROPERTY_POST_METHOD, &request); payload, payload_len, DM_URI_THING_EVENT_PROPERTY_POST_METHOD, &request);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
return FAIL_RETURN; return FAIL_RETURN;
...@@ -505,25 +478,16 @@ int dm_mgr_upstream_thing_property_post(_IN_ int devid, _IN_ char *payload, _IN_ ...@@ -505,25 +478,16 @@ int dm_mgr_upstream_thing_property_post(_IN_ int devid, _IN_ char *payload, _IN_
int dm_mgr_upstream_thing_event_post(_IN_ int devid, _IN_ char *identifier, _IN_ int identifier_len, _IN_ char *method, int dm_mgr_upstream_thing_event_post(_IN_ int devid, _IN_ char *identifier, _IN_ int identifier_len, _IN_ char *method,
_IN_ char *payload, _IN_ int payload_len) _IN_ char *payload, _IN_ int payload_len)
{ {
int res = 0, service_name_len = 0; int res = 0;
char *service_name = NULL;
dm_msg_request_t request; dm_msg_request_t request;
if (devid < 0 || identifier == NULL || identifier_len <= 0 || if (devid < 0 || identifier == NULL || identifier_len <= 0 ||
method == NULL || payload == NULL || payload_len <= 0) { method == NULL || payload == NULL || payload_len <= 0) {
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
service_name_len = strlen(DM_URI_THING_EVENT_POST) + identifier_len + 1;
service_name = malloc(service_name_len);
if (service_name == NULL) {
return MEMORY_NOT_ENOUGH;
}
memset(service_name, 0, service_name_len);
snprintf(service_name, service_name_len, DM_URI_THING_EVENT_POST, identifier_len, identifier);
memset(&request, 0, sizeof(dm_msg_request_t)); memset(&request, 0, sizeof(dm_msg_request_t));
res = _dm_mgr_upstream_request_assemble(iotx_report_id(), devid, DM_URI_SYS_PREFIX, service_name, res = _dm_mgr_upstream_request_assemble(iotx_report_id(), devid,MSG_EVENTPOST,identifier,
payload, payload_len, method, &request); payload, payload_len, method, &request);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
return FAIL_RETURN; return FAIL_RETURN;
...@@ -534,14 +498,13 @@ int dm_mgr_upstream_thing_event_post(_IN_ int devid, _IN_ char *identifier, _IN_ ...@@ -534,14 +498,13 @@ int dm_mgr_upstream_thing_event_post(_IN_ int devid, _IN_ char *identifier, _IN_
/* Send Message To Cloud */ /* Send Message To Cloud */
res = dm_msg_request(&request); res = dm_msg_request(&request);
free(service_name);
return res; return res;
} }
static int _kk_mgr_upstream_response_assemble(_IN_ int devid, _IN_ char *msgid, _IN_ int msgid_len, static int _kk_mgr_upstream_response_assemble(_IN_ int devid, _IN_ char *msgid, _IN_ int msgid_len,
_IN_ const char *prefix, _IN_ int msgtype,
_IN_ const char *service_name, _IN_ int code, _OU_ kk_msg_request_payload_t *request, _OU_ kk_msg_response_t *response) _IN_ const char *identfy, _IN_ int code, _OU_ kk_msg_request_payload_t *request, _OU_ kk_msg_response_t *response)
{ {
int res = 0; int res = 0;
dm_mgr_dev_node_t *node = NULL; dm_mgr_dev_node_t *node = NULL;
...@@ -554,8 +517,11 @@ static int _kk_mgr_upstream_response_assemble(_IN_ int devid, _IN_ char *msgid, ...@@ -554,8 +517,11 @@ static int _kk_mgr_upstream_response_assemble(_IN_ int devid, _IN_ char *msgid,
request->id.value = msgid; request->id.value = msgid;
request->id.value_length = msgid_len; request->id.value_length = msgid_len;
response->service_prefix = DM_URI_SYS_PREFIX; response->msgtype = msgtype;
response->service_name = service_name; if(strlen(identfy) < IDENTIFY_MAXLEN)
{
memcpy(response->identity,identfy,strlen(identfy));
}
memcpy(response->product_key, node->product_key, strlen(node->product_key)); memcpy(response->product_key, node->product_key, strlen(node->product_key));
memcpy(response->device_name, node->device_name, strlen(node->device_name)); memcpy(response->device_name, node->device_name, strlen(node->device_name));
response->code = code; response->code = code;
...@@ -567,7 +533,7 @@ int dm_mgr_deprecated_upstream_thing_service_response(_IN_ int devid, _IN_ int m ...@@ -567,7 +533,7 @@ int dm_mgr_deprecated_upstream_thing_service_response(_IN_ int devid, _IN_ int m
_IN_ char *identifier, _IN_ int identifier_len, _IN_ char *payload, _IN_ int payload_len) _IN_ char *identifier, _IN_ int identifier_len, _IN_ char *payload, _IN_ int payload_len)
{ {
int res = 0, service_name_len = 0; int res = 0, service_name_len = 0;
char *msgid_str = NULL, *service_name = NULL; char *msgid_str = NULL;
kk_msg_request_payload_t request; kk_msg_request_payload_t request;
kk_msg_response_t response; kk_msg_response_t response;
...@@ -588,27 +554,18 @@ int dm_mgr_deprecated_upstream_thing_service_response(_IN_ int devid, _IN_ int m ...@@ -588,27 +554,18 @@ int dm_mgr_deprecated_upstream_thing_service_response(_IN_ int devid, _IN_ int m
request.id.value_length = strlen(msgid_str); request.id.value_length = strlen(msgid_str);
/* Service Name */ /* Service Name */
service_name_len = strlen(DM_URI_THING_SERVICE_RESPONSE) + identifier_len + 1;
service_name = malloc(service_name_len);
if (service_name == NULL) {
free(msgid_str);
return MEMORY_NOT_ENOUGH;
}
memset(service_name, 0, service_name_len);
snprintf(service_name, service_name_len, DM_URI_THING_SERVICE_RESPONSE, identifier_len, identifier);
res = _kk_mgr_upstream_response_assemble(devid, msgid_str, strlen(msgid_str), DM_URI_SYS_PREFIX, service_name, code, res = _kk_mgr_upstream_response_assemble(devid, msgid_str, strlen(msgid_str), MSG_SERVICERESPONSE, identifier, code,
&request, &request,
&response); &response);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
return FAIL_RETURN; return FAIL_RETURN;
} }
printf("Current Service Name: %s", service_name);
dm_msg_response(&request, &response, payload, payload_len, NULL); dm_msg_response(&request, &response, payload, payload_len, NULL);
free(msgid_str); free(msgid_str);
free(service_name);
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
...@@ -628,8 +585,10 @@ int dm_mgr_upstream_thing_sub_register(_IN_ int devid) ...@@ -628,8 +585,10 @@ int dm_mgr_upstream_thing_sub_register(_IN_ int devid)
} }
memset(&request, 0, sizeof(dm_msg_request_t)); memset(&request, 0, sizeof(dm_msg_request_t));
request.service_prefix = DM_URI_SYS_PREFIX; //request.service_prefix = DM_URI_SYS_PREFIX;
request.service_name = DM_URI_THING_SUB_REGISTER; //request.service_name = DM_URI_THING_SUB_REGISTER;
request.msgtype = MSG_REGISTER;
memcpy(request.identity,"",strlen(""));
HAL_GetProduct_Type(request.product_key); HAL_GetProduct_Type(request.product_key);
HAL_GetProduct_Code(request.device_name); HAL_GetProduct_Code(request.device_name);
...@@ -674,8 +633,8 @@ int dm_mgr_upstream_thing_sub_unregister(_IN_ int devid) ...@@ -674,8 +633,8 @@ int dm_mgr_upstream_thing_sub_unregister(_IN_ int devid)
} }
memset(&request, 0, sizeof(dm_msg_request_t)); memset(&request, 0, sizeof(dm_msg_request_t));
request.service_prefix = DM_URI_SYS_PREFIX; request.msgtype = MSG_UNREGISTER;
request.service_name = DM_URI_THING_SUB_UNREGISTER; memset(request.identity,"",strlen(""));
HAL_GetProduct_Type(request.product_key); HAL_GetProduct_Type(request.product_key);
HAL_GetProduct_Code(request.device_name); HAL_GetProduct_Code(request.device_name);
...@@ -722,8 +681,8 @@ int dm_mgr_upstream_thing_topo_add(_IN_ int devid) ...@@ -722,8 +681,8 @@ int dm_mgr_upstream_thing_topo_add(_IN_ int devid)
} }
memset(&request, 0, sizeof(dm_msg_request_t)); memset(&request, 0, sizeof(dm_msg_request_t));
request.service_prefix = DM_URI_SYS_PREFIX; request.msgtype = MSG_TOPOADD;
request.service_name = DM_URI_THING_TOPO_ADD; memcpy(request.identity,"",strlen(""));
HAL_GetProduct_Type(request.product_key); HAL_GetProduct_Type(request.product_key);
HAL_GetProduct_Code(request.device_name); HAL_GetProduct_Code(request.device_name);
...@@ -770,8 +729,8 @@ int dm_mgr_upstream_thing_topo_delete(_IN_ int devid) ...@@ -770,8 +729,8 @@ int dm_mgr_upstream_thing_topo_delete(_IN_ int devid)
} }
memset(&request, 0, sizeof(dm_msg_request_t)); memset(&request, 0, sizeof(dm_msg_request_t));
request.service_prefix = DM_URI_SYS_PREFIX; request.msgtype = MSG_TOPODELETE;
request.service_name = DM_URI_THING_TOPO_DELETE; memcpy(request.identity,"",strlen(""));
HAL_GetProduct_Type(request.product_key); HAL_GetProduct_Type(request.product_key);
HAL_GetProduct_Code(request.device_name); HAL_GetProduct_Code(request.device_name);
...@@ -809,8 +768,8 @@ int dm_mgr_upstream_thing_topo_get(void) ...@@ -809,8 +768,8 @@ int dm_mgr_upstream_thing_topo_get(void)
dm_msg_request_t request; dm_msg_request_t request;
memset(&request, 0, sizeof(dm_msg_request_t)); memset(&request, 0, sizeof(dm_msg_request_t));
request.service_prefix = DM_URI_SYS_PREFIX; request.msgtype = MSG_TOPOGET;
request.service_name = DM_URI_THING_TOPO_GET; memcpy(request.identity,"",strlen(""));
HAL_GetProduct_Type(request.product_key); HAL_GetProduct_Type(request.product_key);
HAL_GetProduct_Code(request.device_name); HAL_GetProduct_Code(request.device_name);
...@@ -860,8 +819,8 @@ int dm_mgr_upstream_thing_list_found(_IN_ int devid) ...@@ -860,8 +819,8 @@ int dm_mgr_upstream_thing_list_found(_IN_ int devid)
} }
memset(&request, 0, sizeof(dm_msg_request_t)); memset(&request, 0, sizeof(dm_msg_request_t));
request.service_prefix = DM_URI_SYS_PREFIX; request.msgtype = MSG_LISTFOUND;
request.service_name = DM_URI_THING_LIST_FOUND; memcpy(request.identity,"",strlen(""));
HAL_GetProduct_Type(request.product_key); HAL_GetProduct_Type(request.product_key);
HAL_GetProduct_Code(request.device_name); HAL_GetProduct_Code(request.device_name);
...@@ -907,8 +866,8 @@ int dm_mgr_upstream_combine_login(_IN_ int devid) ...@@ -907,8 +866,8 @@ int dm_mgr_upstream_combine_login(_IN_ int devid)
} }
memset(&request, 0, sizeof(dm_msg_request_t)); memset(&request, 0, sizeof(dm_msg_request_t));
request.service_prefix = DM_URI_EXT_SESSION_PREFIX; request.msgtype = MSG_LOGIN;
request.service_name = DM_URI_COMBINE_LOGIN; memcpy(request.identity,"",strlen(""));
HAL_GetProduct_Type(request.product_key); HAL_GetProduct_Type(request.product_key);
HAL_GetProduct_Code(request.device_name); HAL_GetProduct_Code(request.device_name);
...@@ -955,8 +914,8 @@ int dm_mgr_upstream_combine_logout(_IN_ int devid) ...@@ -955,8 +914,8 @@ int dm_mgr_upstream_combine_logout(_IN_ int devid)
} }
memset(&request, 0, sizeof(dm_msg_request_t)); memset(&request, 0, sizeof(dm_msg_request_t));
request.service_prefix = DM_URI_EXT_SESSION_PREFIX; request.msgtype = MSG_LOGOUT;
request.service_name = DM_URI_COMBINE_LOGOUT; memcpy(request.identity,"",strlen(""));
HAL_GetProduct_Type(request.product_key); HAL_GetProduct_Type(request.product_key);
HAL_GetProduct_Code(request.device_name); HAL_GetProduct_Code(request.device_name);
......
#ifndef __KK_DM_MNG__ #ifndef __KK_DM_MNG__
#define __KK_DM_MNG__ #define __KK_DM_MNG__
#include "com_api.h"
#include "kk_tsl_common.h" #include "kk_tsl_common.h"
#include "klist.h" #include "klist.h"
...@@ -9,6 +10,7 @@ ...@@ -9,6 +10,7 @@
#define KK_DM_DEVICE_SUBDEV (0x02) #define KK_DM_DEVICE_SUBDEV (0x02)
#define KK_DM_DEVICE_GATEWAY (0x04) #define KK_DM_DEVICE_GATEWAY (0x04)
#define KK_MID_SYNC_DEFAULT_TIMEOUT_MS (200) #define KK_MID_SYNC_DEFAULT_TIMEOUT_MS (200)
#define IDENTIFY_MAXLEN (64 + 1)
typedef struct { typedef struct {
int devid; int devid;
...@@ -30,8 +32,10 @@ typedef struct { ...@@ -30,8 +32,10 @@ typedef struct {
typedef struct { typedef struct {
int msgid; int msgid;
int devid; int devid;
const char *service_prefix; //const char *service_prefix;
const char *service_name; //const char *service_name;
kk_msg_type_t msgtype;
char identity[IDENTIFY_MAXLEN];
char product_key[PRODUCT_KEY_MAXLEN]; char product_key[PRODUCT_KEY_MAXLEN];
char device_name[DEVICE_NAME_MAXLEN]; char device_name[DEVICE_NAME_MAXLEN];
char *params; char *params;
...@@ -39,5 +43,12 @@ typedef struct { ...@@ -39,5 +43,12 @@ typedef struct {
char *method; char *method;
//iotx_cm_data_handle_cb callback; //iotx_cm_data_handle_cb callback;
} dm_msg_request_t; } dm_msg_request_t;
typedef struct {
kk_msg_type_t msgtype;
char identity[IDENTIFY_MAXLEN];
char product_key[PRODUCT_KEY_MAXLEN];
char device_name[DEVICE_NAME_MAXLEN];
iotx_dm_error_code_t code;
} kk_msg_response_t;
#endif #endif
...@@ -16,10 +16,11 @@ const char DM_URI_THING_EVENT_PROPERTY_POST_METHOD[] DM_READ_ONLY = "thing.even ...@@ -16,10 +16,11 @@ const char DM_URI_THING_EVENT_PROPERTY_POST_METHOD[] DM_READ_ONLY = "thing.even
const char DM_MSG_REQUEST[] DM_READ_ONLY = "{\"msgId\":\"%d\",\"version\":\"%s\",\"params\":%.*s,\"method\":\"%s\"}"; const char DM_MSG_REQUEST[] DM_READ_ONLY = "{\"msgId\":\"%d\",\"version\":\"%s\",\"params\":%.*s,\"method\":\"%s\"}";
const char DM_MSG_INFO[] DM_READ_ONLY = "{\"msgtype\":\"%d\",\"product_type\":\"%s\",\"device_name\":\"%s\",\"identifier\":\"%s\"}";
void kk_sendData2app(void *uri, void *payload){ void kk_sendData2app(void *info, void *payload){
cJSON *root=cJSON_CreateObject(); cJSON *root=cJSON_CreateObject();
cJSON_AddStringToObject(root, "topic", uri); cJSON_AddStringToObject(root, "info", info);
cJSON_AddStringToObject(root, "payload", payload); cJSON_AddStringToObject(root, "payload", payload);
void *buf = cJSON_Print(root); void *buf = cJSON_Print(root);
kk_ipc_send(IPC_MID2APP, buf, strlen(buf) + 1); kk_ipc_send(IPC_MID2APP, buf, strlen(buf) + 1);
...@@ -395,48 +396,56 @@ int dm_msg_combine_logout(_IN_ char product_key[PRODUCT_KEY_MAXLEN], ...@@ -395,48 +396,56 @@ int dm_msg_combine_logout(_IN_ char product_key[PRODUCT_KEY_MAXLEN],
int dm_msg_request (_IN_ dm_msg_request_t *request) int dm_msg_request (_IN_ dm_msg_request_t *request)
{ {
int res = 0, payload_len = 0; int res = 0, payload_len = 0,req_info_len = 0;
char *payload = NULL, *uri = NULL; char *payload = NULL;
lite_cjson_t lite; lite_cjson_t lite;
char *req_info = NULL;
if (request == NULL || request->params == NULL || request->method == NULL) { if (request == NULL || request->params == NULL || request->method == NULL) {
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
/* Request URI */
res = kk_utils_service_name(request->service_prefix, request->service_name,
request->product_key, request->device_name, &uri);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
payload_len = strlen(DM_MSG_REQUEST) + 10 + strlen(DM_MSG_VERSION) + request->params_len + strlen( payload_len = strlen(DM_MSG_REQUEST) + 10 + strlen(DM_MSG_VERSION) + request->params_len + strlen(
request->method) + 1; request->method) + 1;
payload = malloc(payload_len); payload = malloc(payload_len);
if (payload == NULL) { if (payload == NULL) {
free(uri);
return MEMORY_NOT_ENOUGH; return MEMORY_NOT_ENOUGH;
} }
memset(payload, 0, payload_len); memset(payload, 0, payload_len);
snprintf(payload, payload_len, DM_MSG_REQUEST, request->msgid, snprintf(payload, payload_len, DM_MSG_REQUEST, request->msgid,
DM_MSG_VERSION, request->params_len, request->params, request->method); DM_MSG_VERSION, request->params_len, request->params, request->method);
req_info_len = strlen(DM_MSG_INFO)+10+strlen(request->product_key)+strlen(request->device_name)+strlen(request->identity)+1;
req_info = malloc(req_info_len);
if (req_info == NULL) {
free(payload);
return MEMORY_NOT_ENOUGH;
}
memset(req_info, 0, req_info_len);
snprintf(req_info, req_info_len, DM_MSG_INFO, request->msgtype,
request->product_key, request->device_name,request->identity);
memset(&lite, 0, sizeof(lite_cjson_t)); memset(&lite, 0, sizeof(lite_cjson_t));
res = lite_cjson_parse(payload, payload_len, &lite); res = lite_cjson_parse(payload, payload_len, &lite);
if (res < SUCCESS_RETURN) { if (res < SUCCESS_RETURN) {
printf("Wrong JSON Format, URI: %s, Payload: %s", uri, payload); printf("Wrong JSON Format, Payload: %s", payload);
free(uri); free(req_info);
free(payload);
return FAIL_RETURN;
}
memset(&lite, 0, sizeof(lite_cjson_t));
res = lite_cjson_parse(req_info, req_info_len, &lite);
if (res < SUCCESS_RETURN) {
printf("Wrong JSON Format, Payload: %s", req_info_len);
free(req_info);
free(payload); free(payload);
return FAIL_RETURN; return FAIL_RETURN;
} }
printf("DM Send Message, URI: %s, Payload: %s \n", uri, payload);
//if (type & DM_MSG_DEST_CLOUD) { //if (type & DM_MSG_DEST_CLOUD) {
// dm_client_publish(uri, (unsigned char *)payload, strlen(payload), request->callback); // dm_client_publish(uri, (unsigned char *)payload, strlen(payload), request->callback);
kk_sendData2app(uri, payload); kk_sendData2app(req_info, payload);
//} //}
free(uri); free(req_info);
free(payload); free(payload);
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
...@@ -446,20 +455,15 @@ const char DM_MSG_RESPONSE_WITH_DATA[] DM_READ_ONLY = "{\"msgId\":\"%.*s\",\"cod ...@@ -446,20 +455,15 @@ const char DM_MSG_RESPONSE_WITH_DATA[] DM_READ_ONLY = "{\"msgId\":\"%.*s\",\"cod
int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response_t *response, int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response_t *response,
_IN_ char *data, _IN_ int data_len, _IN_ void *user_data) _IN_ char *data, _IN_ int data_len, _IN_ void *user_data)
{ {
int res = 0, payload_len = 0; int res = 0, payload_len = 0,res_info_len = 0;
char *uri = NULL, *payload = NULL; char *uri = NULL, *payload = NULL;
lite_cjson_t lite; lite_cjson_t lite;
char *res_info = NULL;
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if (request == NULL || response == NULL || data == NULL || data_len <= 0) { if (request == NULL || response == NULL || data == NULL || data_len <= 0) {
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
/* Response URI */
res = kk_utils_service_name(response->service_prefix, response->service_name,
response->product_key, response->device_name, &uri);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
/* Response Payload */ /* Response Payload */
payload_len = strlen(DM_MSG_RESPONSE_WITH_DATA) + request->id.value_length + DM_UTILS_UINT32_STRLEN + data_len + 1; payload_len = strlen(DM_MSG_RESPONSE_WITH_DATA) + request->id.value_length + DM_UTILS_UINT32_STRLEN + data_len + 1;
...@@ -468,10 +472,23 @@ int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response ...@@ -468,10 +472,23 @@ int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response
free(uri); free(uri);
return MEMORY_NOT_ENOUGH; return MEMORY_NOT_ENOUGH;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
memset(payload, 0, payload_len); memset(payload, 0, payload_len);
snprintf(payload, payload_len, DM_MSG_RESPONSE_WITH_DATA, snprintf(payload, payload_len, DM_MSG_RESPONSE_WITH_DATA,
request->id.value_length, request->id.value, response->code, data_len, data); request->id.value_length, request->id.value, response->code, data_len, data);
res_info_len = strlen(DM_MSG_INFO)+10+strlen(response->product_key)+strlen(response->device_name)+strlen(response->identity)+1;
res_info = malloc(res_info_len);
if (res_info == NULL) {
free(payload);
return MEMORY_NOT_ENOUGH;
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
memset(res_info, 0, res_info_len);
snprintf(res_info, res_info_len, DM_MSG_INFO, response->msgtype,
response->product_key, response->device_name,response->identity);
memset(&lite, 0, sizeof(lite_cjson_t)); memset(&lite, 0, sizeof(lite_cjson_t));
res = lite_cjson_parse(payload, payload_len, &lite); res = lite_cjson_parse(payload, payload_len, &lite);
if (res < SUCCESS_RETURN) { if (res < SUCCESS_RETURN) {
...@@ -480,13 +497,22 @@ int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response ...@@ -480,13 +497,22 @@ int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response
free(payload); free(payload);
return FAIL_RETURN; return FAIL_RETURN;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
printf("Send URI: %s, Payload: %s", uri, payload); memset(&lite, 0, sizeof(lite_cjson_t));
res = lite_cjson_parse(res_info, res_info_len, &lite);
if (res < SUCCESS_RETURN) {
printf("Wrong JSON Format, Payload: %s", res_info_len);
free(res_info);
free(payload);
return FAIL_RETURN;
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
//dm_client_publish(uri, (unsigned char *)payload, strlen(payload), NULL); //dm_client_publish(uri, (unsigned char *)payload, strlen(payload), NULL);
kk_sendData2app(uri, payload); kk_sendData2app(res_info, payload);
free(uri); free(res_info);
free(payload); free(payload);
return SUCCESS_RETURN; return SUCCESS_RETURN;
...@@ -564,6 +590,7 @@ int dm_msg_thing_property_set_reply(const char *topic, const char *payload, unsi ...@@ -564,6 +590,7 @@ int dm_msg_thing_property_set_reply(const char *topic, const char *payload, unsi
memset(&request, 0, sizeof(kk_msg_request_payload_t)); memset(&request, 0, sizeof(kk_msg_request_payload_t));
memset(&response, 0, sizeof(kk_msg_response_t)); memset(&response, 0, sizeof(kk_msg_response_t));
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
/**************to do*******************/ /**************to do*******************/
...@@ -574,19 +601,23 @@ int dm_msg_thing_property_set_reply(const char *topic, const char *payload, unsi ...@@ -574,19 +601,23 @@ int dm_msg_thing_property_set_reply(const char *topic, const char *payload, unsi
res =kk_msg_uri_parse_pkdn((char *)topic, strlen(topic), 2 + KK_URI_OFFSET, 4 + KK_URI_OFFSET, product_key, res =kk_msg_uri_parse_pkdn((char *)topic, strlen(topic), 2 + KK_URI_OFFSET, 4 + KK_URI_OFFSET, product_key,
device_name); device_name);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
res = dm_mgr_search_device_by_pkdn(product_key, device_name, &devid); res = dm_mgr_search_device_by_pkdn(product_key, device_name, &devid);
if (res < SUCCESS_RETURN) { if (res < SUCCESS_RETURN) {
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return res; return res;
} }
res = dm_msg_request_parse((char *)payload, payload_len, &request); res = dm_msg_request_parse((char *)payload, payload_len, &request);
if (res < SUCCESS_RETURN) { if (res < SUCCESS_RETURN) {
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return res ; return res ;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
/* Response */ /* Response */
response.service_prefix = DM_URI_SYS_PREFIX; response.msgtype = MSG_SETREPLY;
response.service_name = DM_URI_THING_SERVICE_PROPERTY_SET_REPLY; memset(response.identity,"",strlen(""));
memcpy(response.product_key, product_key, strlen(product_key)); memcpy(response.product_key, product_key, strlen(product_key));
memcpy(response.device_name, device_name, strlen(device_name)); memcpy(response.device_name, device_name, strlen(device_name));
response.code = (res == SUCCESS_RETURN) ? (IOTX_DM_ERR_CODE_SUCCESS) : (IOTX_DM_ERR_CODE_REQUEST_ERROR); response.code = (res == SUCCESS_RETURN) ? (IOTX_DM_ERR_CODE_SUCCESS) : (IOTX_DM_ERR_CODE_REQUEST_ERROR);
......
...@@ -1234,31 +1234,6 @@ int kk_msg_uri_parse_pkdn(_IN_ char *uri, _IN_ int uri_len, _IN_ int start_deli, ...@@ -1234,31 +1234,6 @@ int kk_msg_uri_parse_pkdn(_IN_ char *uri, _IN_ int uri_len, _IN_ int start_deli,
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
int kk_tsl_response_ok(const char *topic, const char *payload, unsigned int payload_len)
{
int res = 0;
char product_key[PRODUCT_KEY_MAXLEN] = {0};
char device_name[DEVICE_NAME_MAXLEN] = {0};
kk_msg_response_t response;
kk_msg_request_payload_t request;
memset(&request, 0, sizeof(kk_msg_request_payload_t));
memset(&response, 0, sizeof(kk_msg_response_t));
res =kk_msg_uri_parse_pkdn((char *)topic, strlen(topic), 2 + KK_URI_OFFSET, 4 + KK_URI_OFFSET, product_key,
device_name);
res = _kk_msg_request_parse((char *)payload, payload_len, &request);
if (res < SUCCESS_RETURN) {
return res ;
}
response.service_prefix = DM_URI_SYS_PREFIX;
response.service_name = DM_URI_THING_SERVICE_PROPERTY_SET_REPLY;
memcpy(response.product_key, product_key, strlen(product_key));
memcpy(response.device_name, device_name, strlen(device_name));
response.code = (res == SUCCESS_RETURN) ? (IOTX_DM_ERR_CODE_SUCCESS) : (IOTX_DM_ERR_CODE_REQUEST_ERROR);
dm_msg_response(&request, &response, "{}", strlen("{}"), NULL);
return SUCCESS_RETURN;
}
int kk_tsl_property_set_byMac(const char mac[DEVICE_MAC_MAXLEN], const char *payload, unsigned int payload_len) int kk_tsl_property_set_byMac(const char mac[DEVICE_MAC_MAXLEN], const char *payload, unsigned int payload_len)
{ {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define KK_MSG_KEY_ID "id" #define KK_MSG_KEY_ID "msgId"
#define KK_MSG_KEY_VERSION "version" #define KK_MSG_KEY_VERSION "version"
#define KK_MSG_KEY_METHOD "method" #define KK_MSG_KEY_METHOD "method"
#define KK_MSG_KEY_PARAMS "params" #define KK_MSG_KEY_PARAMS "params"
...@@ -49,25 +49,7 @@ typedef struct { ...@@ -49,25 +49,7 @@ typedef struct {
lite_cjson_t message; lite_cjson_t message;
} kk_msg_response_payload_t; } kk_msg_response_payload_t;
typedef struct {
int msgid;
int devid;
const char *service_prefix;
const char *service_name;
char product_key[PRODUCT_KEY_MAXLEN];
char device_name[DEVICE_NAME_MAXLEN];
char *params;
int params_len;
char *method;
//iotx_cm_data_handle_cb callback;
} kk_msg_request_t;
typedef struct {
const char *service_prefix;
const char *service_name;
char product_key[PRODUCT_KEY_MAXLEN];
char device_name[DEVICE_NAME_MAXLEN];
iotx_dm_error_code_t code;
} kk_msg_response_t;
typedef enum { typedef enum {
kk_tsl_set_property_value = 0, kk_tsl_set_property_value = 0,
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#define DEVICE_MAC_MAXLEN (16 + 1) #define DEVICE_MAC_MAXLEN (16 + 1)
#define DEVICE_SN_MAXLEN (32 + 1) #define DEVICE_SN_MAXLEN (32 + 1)
#define TSL_PATH_MAXLEN (64 + 1) #define TSL_PATH_MAXLEN (64 + 1)
#define DM_UTILS_UINT16_STRLEN (5) #define DM_UTILS_UINT16_STRLEN (5)
......
...@@ -500,7 +500,7 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS) ...@@ -500,7 +500,7 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS)
kk_print("*******************123****************\r\n"); kk_print("*******************123****************\r\n");
kk_print_info("\r\n-----hello world![%s:%s]-----\r\n",__DATE__,__TIME__); kk_print_info("\r\n-----hello world![%s:%s]-----\r\n",__DATE__,__TIME__);
kk_print_version(); kk_print_version();
kk_tsl_init();
emberSerialInit(APP_SERIAL, BAUD_RATE, PARITY_NONE, 1); //fock child process emberSerialInit(APP_SERIAL, BAUD_RATE, PARITY_NONE, 1); //fock child process
emberAfAppPrintln("Reset info: %d (%p)", emberAfAppPrintln("Reset info: %d (%p)",
......
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