Commit 1cb9ada1 authored by chen.weican's avatar chen.weican

【修改内容】1,去掉productType相关设置;2,增加mac的数据保存

parent 19e63444
......@@ -23,7 +23,7 @@
#define KK_CLOUDSTATE_MSG "/thing/ccu/cloudstate"
const char DM_MSG_TO_MIDDWARE[] = "{\"msgtype\":\"%s\",\"productType\":\"%s\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"}";
const char DM_MSG_TO_MIDDWARE[] = "{\"msgtype\":\"%s\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"}";
#define KK_TOPIC_SERVICE_DELIMITER '/'
int _kk_sendto_cloud(cJSON *root)
......@@ -136,11 +136,11 @@ static int _kk_topic_parse_msgType(_IN_ char *topic, _IN_ int start_deli,_OU_ ch
}
static int _kk_topic_parse_pkdn(_IN_ char *topic, _IN_ int start_deli,
_OU_ char productType[PRODUCT_TYPE_LEN], _OU_ char productCode[PRODUCT_CODE_LEN],_OU_ char deviceCode[DEVICE_CODE_LEN])
_OU_ char productCode[PRODUCT_CODE_LEN],_OU_ char deviceCode[DEVICE_CODE_LEN])
{
int res = 0, start = 0, end = 0, slice = 0,slice1 = 0;
int res = 0, start = 0, end = 0, slice = 0;
if (topic == NULL || productType == NULL || deviceCode == NULL) {
if (topic == NULL || deviceCode == NULL) {
return -1;
}
res = kk_utils_memtok(topic, strlen(topic), KK_TOPIC_SERVICE_DELIMITER, start_deli, &start);
......@@ -151,18 +151,14 @@ static int _kk_topic_parse_pkdn(_IN_ char *topic, _IN_ int start_deli,
if (res != 0) {
return -1;
}
res = kk_utils_memtok(topic, strlen(topic), KK_TOPIC_SERVICE_DELIMITER, start_deli + 2, &slice1);
if (res != 0) {
return -1;
}
res = kk_utils_memtok(topic, strlen(topic), KK_TOPIC_SERVICE_DELIMITER, start_deli + 3, &end);
res = kk_utils_memtok(topic, strlen(topic), KK_TOPIC_SERVICE_DELIMITER, start_deli + 2, &end);
if (res != 0) {
return -1;
}
memcpy(productType, topic + start + 1, slice - start - 1);
memcpy(productCode, topic + slice + 1, slice1 - slice - 1);
memcpy(deviceCode, topic + slice1 + 1, end - slice1 - 1);
memcpy(productCode, topic + start + 1, slice - start - 1);
memcpy(deviceCode, topic + slice + 1, end - slice - 1);
return 0;
}
......@@ -174,14 +170,13 @@ static char * _kk_data_create(const char *topic,const char *data)
char *infoStr = NULL;
int infoStr_len = 0;
int res = 0;
char productType[PRODUCT_TYPE_LEN] = {0};
char productCode[PRODUCT_CODE_LEN] = {0};
char deviceCode[DEVICE_CODE_LEN] = {0};
char * msgStr = NULL;
res =_kk_topic_parse_pkdn((char *)topic,2, productType,productCode,deviceCode);
res =_kk_topic_parse_pkdn((char *)topic,3,productCode,deviceCode);
res|=_kk_topic_parse_msgType((char *)topic,5,&msgStr);
infoStr_len = strlen(DM_MSG_TO_MIDDWARE)+strlen(productType)+strlen(productCode)+strlen(deviceCode)+strlen(msgStr)+10;
infoStr_len = strlen(DM_MSG_TO_MIDDWARE)+strlen(productCode)+strlen(deviceCode)+strlen(msgStr)+10;
infoStr = malloc(infoStr_len);
if(infoStr == NULL){
ERROR_PRINT("[%s][%d]\n",__FUNCTION__,__LINE__);
......@@ -189,7 +184,7 @@ static char * _kk_data_create(const char *topic,const char *data)
return NULL;
}
memset(infoStr,0x0,infoStr_len);
snprintf(infoStr,infoStr_len,DM_MSG_TO_MIDDWARE,msgStr,productType,productCode,deviceCode);
snprintf(infoStr,infoStr_len,DM_MSG_TO_MIDDWARE,msgStr,productCode,deviceCode);
root=cJSON_CreateObject();
cJSON* infoObj = cJSON_Parse(infoStr);
......@@ -222,7 +217,7 @@ int KK_Send_CloudState(int state)
return -1;
}
memset(infoStr,0x0,infoStr_len);
snprintf(infoStr,infoStr_len,DM_MSG_TO_MIDDWARE,KK_CLOUDSTATE_MSG,"","","");
snprintf(infoStr,infoStr_len,DM_MSG_TO_MIDDWARE,KK_CLOUDSTATE_MSG,"","");
payloadStr_len = strlen(DM_MSG_CLOUDSTATE) + 10;
payloadStr = malloc(payloadStr_len);
......
......@@ -10,18 +10,6 @@
const char KK_URI_SYS_PREFIX[] = "/sys/kk/%s/%s/#";
const char KK_URI_SYS_PREFIX_EX[] = "/sys/kk/%s/%s";
const char DM_URI_THING_SUB_REGISTER[] = "thing/sub/register";
const char DM_URI_THING_SUB_UNREGISTER[] = "thing/sub/unregister";
const char DM_URI_THING_TOPO_ADD[] = "thing/topo/add";
const char DM_URI_THING_TOPO_DELETE[] = "thing/topo/delete";
const char DM_URI_THING_TOPO_GET[] = "thing/topo/get";
const char DM_URI_THING_LIST_FOUND[] = "thing/list/found";
const char DM_URI_COMBINE_LOGIN[] = "combine/login";
const char DM_URI_COMBINE_LOGOUT[] = "combine/logout";
const char DM_URI_THING_EVENT_PROPERTY_POST[] = "thing/event/property/post";
const char DM_URI_THING_EVENT_POST[] = "thing/event/%.*s/post";
const char DM_URI_THING_SERVICE_RESPONSE[] = "thing/service/%.*s_reply";
const char DM_URI_THING_SERVICE_PROPERTY_SET_REPLY[] = "thing/service/property/set_reply";
const char KK_URI_OTA_PREFIX[] = "/ota/device/upgrade/kk/%s/%s/#";
const char KK_URI_OTA_PROCESS[] = "/ota/device/progress/%s/%s";
const char KK_URI_OTA_INFORM[] = "/ota/device/inform/%s/%s";
......
......@@ -537,7 +537,7 @@ int HAL_Get_mac(char* mac)
int HAL_Get_SN(char sn[SN_ADDR_LEN])
{
strncpy(sn,"11111111111111111111111111111111",SN_ADDR_LEN);
strncpy(sn,"15",SN_ADDR_LEN);
return 0;//just for test
}
......
......@@ -302,12 +302,12 @@ int iotx_dm_subscribe(_IN_ int devid)
//send app to subscribe mqtt
const char subscribe_cmd[] =
"{\"cmd\":\"subscribe\",\"data\":{\"productType\":\"%s\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"}}";
int len = strlen(subscribe_cmd) + strlen(node->productType) +strlen(node->productCode)+ strlen(node->deviceCode) + 1;
"{\"cmd\":\"subscribe\",\"data\":{\"productCode\":\"%s\",\"deviceCode\":\"%s\"}}";
int len = strlen(subscribe_cmd) +strlen(node->productCode)+ strlen(node->deviceCode) + 1;
void* buf = malloc(len);
if (buf){
HAL_Snprintf(buf, len, subscribe_cmd, node->productType, node->productCode,node->deviceCode);
HAL_Snprintf(buf, len, subscribe_cmd, node->productCode,node->deviceCode);
kk_ipc_send(IPC_MID2APP, buf, len);
free(buf);
}else{
......
......@@ -60,16 +60,13 @@ int dm_mgr_search_dev_by_devid(_IN_ int devid, _OU_ dm_mgr_dev_node_t **node)
ERROR_PRINT("Device Not Found, devid: %d", devid);
return FAIL_RETURN;
}
static int _dm_mgr_search_dev_by_pkdn(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_mgr_dev_node_t **node)
static int _dm_mgr_search_dev_by_pkdn(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_mgr_dev_node_t **node)
{
dm_mgr_ctx *ctx = _dm_mgr_get_ctx();
dm_mgr_dev_node_t *search_node = NULL;
list_for_each_entry(search_node, &ctx->dev_list, linked_list, dm_mgr_dev_node_t) {
if ((strlen(search_node->productType) == strlen(productType)) &&
(memcmp(search_node->productType, productType, strlen(productType)) == 0) &&
(strlen(search_node->deviceCode) == strlen(deviceCode)) &&
if ( (strlen(search_node->deviceCode) == strlen(deviceCode)) &&
(memcmp(search_node->deviceCode, deviceCode, strlen(deviceCode)) == 0)) {
/* dm_log_debug("Device Found, Product Key: %s, Device Name: %s", product_key, device_name); */
if (node) {
......@@ -79,7 +76,7 @@ static int _dm_mgr_search_dev_by_pkdn(_IN_ char productType[PRODUCT_TYPE_MAXLEN]
}
}
ERROR_PRINT("Device Not Found, Product Type: %s, Device Code: %s", productType, deviceCode);
ERROR_PRINT("Device Not Found, Device Code: %s", deviceCode);
return FAIL_RETURN;
}
static int _dm_mgr_next_devid(void)
......@@ -91,10 +88,10 @@ static int _dm_mgr_next_devid(void)
static int _dm_init_tsl_params(int devId)
{
int res = 0;
char version[VERSION_MAXLEN];
char s_IP[NETWORK_ADDR_LEN];
char s_mac[MAC_ADDR_LEN];
char s_SN[SN_ADDR_LEN];
char version[VERSION_MAXLEN] = {0};
char s_IP[NETWORK_ADDR_LEN] = {0};
char s_mac[MAC_ADDR_LEN] = {0};
char s_SN[SN_ADDR_LEN] = {0};
int port = 0;
/*******set version***********/
......@@ -148,8 +145,8 @@ static int _dm_init_tsl_params(int devId)
}
return res;
}
int dm_mgr_device_create(_IN_ int dev_type, _IN_ char productType[PRODUCT_TYPE_MAXLEN],
_IN_ char productCode[PRODUCT_CODE_MAXLEN], _IN_ char deviceCode[DEVICE_CODE_MAXLEN],_IN_ char fatherMac[DEVICE_MAC_MAXLEN], _OU_ int *devid)
int dm_mgr_device_create(_IN_ int dev_type,_IN_ char productCode[PRODUCT_CODE_MAXLEN], _IN_ char deviceCode[DEVICE_CODE_MAXLEN],
_IN_ char mac[DEVICE_MAC_MAXLEN],_IN_ char fatherDeviceCode[DEVICE_CODE_MAXLEN], _OU_ int *devid)
{
int res = 0;
dm_mgr_ctx *ctx = _dm_mgr_get_ctx();
......@@ -158,14 +155,11 @@ int dm_mgr_device_create(_IN_ int dev_type, _IN_ char productType[PRODUCT_TYPE_M
int idx = 0;
if (productType != NULL && strlen(productType) >= PRODUCT_TYPE_MAXLEN) {
return INVALID_PARAMETER;
}
if (deviceCode != NULL && strlen(deviceCode) >= DEVICE_CODE_MAXLEN) {
return INVALID_PARAMETER;
}
res = _dm_mgr_search_dev_by_pkdn(productType, deviceCode, &node);
res = _dm_mgr_search_dev_by_pkdn(deviceCode, &node);
if (res == SUCCESS_RETURN) {
if (devid) {
*devid = node->devid;
......@@ -185,17 +179,17 @@ int dm_mgr_device_create(_IN_ int dev_type, _IN_ char productType[PRODUCT_TYPE_M
node->devid = _dm_mgr_next_devid();
node->dev_type = dev_type;
node->dev_shadow = NULL;
if (productType != NULL) {
memcpy(node->productType, productType, strlen(productType));
}
if (productCode != NULL) {
memcpy(node->productCode, productCode, strlen(productCode));
}
if (deviceCode != NULL) {
memcpy(node->deviceCode, deviceCode, strlen(deviceCode));
}
if (dev_type != KK_DM_DEVICE_CCU && fatherMac != NULL) {
memcpy(node->fatherMac, fatherMac, strlen(fatherMac));
if (mac != NULL) {
memcpy(node->mac, mac, strlen(mac));
}
if (dev_type != KK_DM_DEVICE_CCU && fatherDeviceCode != NULL) {
memcpy(node->fatherDeviceCode, fatherDeviceCode, strlen(fatherDeviceCode));
}
//node->dev_status = IOTX_DM_DEV_STATUS_AUTHORIZED;
......@@ -221,17 +215,16 @@ int dm_mgr_device_create(_IN_ int dev_type, _IN_ char productType[PRODUCT_TYPE_M
return SUCCESS_RETURN;
}
int dm_mgr_search_device_by_pkdn(_IN_ char productType[PRODUCT_TYPE_MAXLEN], _IN_ char deviceCode[DEVICE_CODE_MAXLEN],
_OU_ int *devid)
int dm_mgr_search_device_by_pkdn( _IN_ char deviceCode[DEVICE_CODE_MAXLEN],_OU_ int *devid)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (productType == NULL || deviceCode == NULL) {
if (deviceCode == NULL) {
return INVALID_PARAMETER;
}
res = _dm_mgr_search_dev_by_pkdn(productType, deviceCode, &node);
res = _dm_mgr_search_dev_by_pkdn(deviceCode, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -243,55 +236,9 @@ int dm_mgr_search_device_by_pkdn(_IN_ char productType[PRODUCT_TYPE_MAXLEN], _IN
return SUCCESS_RETURN;
}
int dm_mgr_search_mac_by_topic(_IN_ char* topic, _OU_ char mac[DEVICE_MAC_MAXLEN])
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
char productType[PRODUCT_TYPE_MAXLEN] = {0};
char deviceCode[DEVICE_CODE_MAXLEN] = {0};
if (topic == NULL) {
return INVALID_PARAMETER;
}
res =kk_msg_uri_parse_pkdn((char *)topic, strlen(topic), 2 + KK_URI_OFFSET, 4 + KK_URI_OFFSET, productType,
deviceCode);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = _dm_mgr_search_dev_by_pkdn(productType, deviceCode, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
memcpy(mac, node->deviceCode, DEVICE_MAC_MAXLEN);
return SUCCESS_RETURN;
}
int dm_mgr_search_mac_by_pkdn(_IN_ char productType[PRODUCT_TYPE_MAXLEN], _IN_ char deviceCode[DEVICE_CODE_MAXLEN],
_OU_ char mac[DEVICE_MAC_MAXLEN])
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (productType == NULL || deviceCode == NULL) {
return INVALID_PARAMETER;
}
res = _dm_mgr_search_dev_by_pkdn(productType, deviceCode, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
memcpy(mac, node->deviceCode, DEVICE_MAC_MAXLEN);
return SUCCESS_RETURN;
}
int dm_mgr_get_deviceType_by_mac(_IN_ char deviceCode[DEVICE_MAC_MAXLEN], _OU_ int* deviceType)
int dm_mgr_get_devicetype_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ int* deviceType)
{
dm_mgr_ctx *ctx = _dm_mgr_get_ctx();
dm_mgr_dev_node_t *node = NULL;
......@@ -312,7 +259,7 @@ int dm_mgr_get_deviceType_by_mac(_IN_ char deviceCode[DEVICE_MAC_MAXLEN], _OU_ i
}
int dm_mgr_get_device_by_mac(_IN_ char deviceCode[DEVICE_MAC_MAXLEN], _OU_ dm_mgr_dev_node_t **node)
int dm_mgr_get_device_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_mgr_dev_node_t **node)
{
dm_mgr_ctx *ctx = _dm_mgr_get_ctx();
dm_mgr_dev_node_t *search_node = NULL;
......@@ -332,7 +279,7 @@ int dm_mgr_get_device_by_mac(_IN_ char deviceCode[DEVICE_MAC_MAXLEN], _OU_ dm_mg
return FAIL_RETURN;
}
int dm_mgr_get_devId_by_mac(_IN_ char deviceCode[DEVICE_MAC_MAXLEN],_OU_ int *devid)
int dm_mgr_get_devId_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN],_OU_ int *devid)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
......@@ -341,7 +288,7 @@ int dm_mgr_get_devId_by_mac(_IN_ char deviceCode[DEVICE_MAC_MAXLEN],_OU_ int *de
return INVALID_PARAMETER;
}
res = dm_mgr_get_device_by_mac(deviceCode, &node);
res = dm_mgr_get_device_by_devicecode(deviceCode, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -372,9 +319,9 @@ int dm_mgr_init(void)
{
int res = 0;
dm_mgr_ctx *ctx = _dm_mgr_get_ctx();
char productType[PRODUCT_TYPE_MAXLEN] = {0};
char productCode[PRODUCT_CODE_MAXLEN] = {0};
char deviceCode[DEVICE_CODE_MAXLEN]= {0};
char mac[DEVICE_MAC_MAXLEN]= {0};
int devId = 0;
memset(ctx, 0, sizeof(dm_mgr_ctx));
......@@ -391,9 +338,8 @@ int dm_mgr_init(void)
//HAL_GetProduct_Type(product_key);
//HAL_GetProduct_Code(device_name);
memset(deviceCode,0x0,sizeof(deviceCode));
HAL_Get_mac(deviceCode);
res = dm_mgr_device_create(KK_DM_DEVICE_CCU,KK_DM_CCU_DEVICE_PRODUCT_TYPE,KK_DM_CCU_DEVICE_PRODUCT_CODE,"CCU_66666","",&devId);
HAL_Get_mac(mac);
res = dm_mgr_device_create(KK_DM_DEVICE_CCU,KK_DM_CCU_DEVICE_PRODUCT_CODE,"CCU_66666",mac,"",&devId);
if (res != SUCCESS_RETURN) {
goto ERROR;
}
......@@ -401,13 +347,6 @@ int dm_mgr_init(void)
_dm_init_tsl_params(devId);
}
//res = dm_mgr_device_create(KK_DM_DEVICE_GATEWAY,KK_DM_GW_DEVICE_PRODUCT_TYPE,KK_DM_GW_DEVICE_PRODUCT_CODE,"1122334455667788",deviceCode,&devId);
//if (res != SUCCESS_RETURN) {
// goto ERROR;
//}
//sleep(3);
//kk_dm_subdev_topo_add(devId);
return SUCCESS_RETURN;
ERROR:
......@@ -473,7 +412,6 @@ static int _dm_mgr_upstream_request_assemble(_IN_ int msgid, _IN_ int devid,
}
memset(request->msgTypeStr,0x0,msgTypeLen);
snprintf(request->msgTypeStr,msgTypeLen,DM_URI_THING_EVENT_POST,identify);
memcpy(request->productType, node->productType, strlen(node->productType));
memcpy(request->productCode, node->productCode, strlen(node->productCode));
memcpy(request->deviceCode, node->deviceCode, strlen(node->deviceCode));
request->params = payload_param;
......@@ -566,7 +504,6 @@ static int _kk_mgr_upstream_response_assemble(_IN_ int devid, _IN_ char *msgid,
}
memset(response->msgTypeStr,0x0,msgTypeLen);
snprintf(response->msgTypeStr,msgTypeLen,DM_URI_THING_SERVICE_RESPONSE,identfy);
memcpy(response->productType, node->productType, strlen(node->productType));
memcpy(response->productCode, node->productCode, strlen(node->productCode));
memcpy(response->deviceCode, node->deviceCode, strlen(node->deviceCode));
response->code = code;
......@@ -632,18 +569,17 @@ int dm_mgr_upstream_thing_sub_register(_IN_ int devid)
return FAIL_RETURN;
}
res = dm_mgr_get_device_by_mac(node->fatherMac,&gw_node);
res = dm_mgr_get_device_by_devicecode(node->fatherDeviceCode,&gw_node);
if (res != SUCCESS_RETURN) {
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return FAIL_RETURN;
}
memset(&request, 0, sizeof(dm_msg_request_t));
request.msgTypeStr = DM_URI_THING_SUB_REGISTER;
memcpy(request.productType,gw_node->productType,strlen(gw_node->productType));
memcpy(request.productCode,gw_node->productCode,strlen(gw_node->productCode));
memcpy(request.deviceCode,gw_node->deviceCode,strlen(gw_node->deviceCode));
/* Get Params And Method */
res = dm_msg_thing_sub_register(node->productType, node->productCode,node->deviceCode, &request);
res = dm_msg_thing_sub_register( node->productCode,node->deviceCode, &request);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -683,7 +619,7 @@ int dm_mgr_upstream_thing_sub_unregister(_IN_ int devid)
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = dm_mgr_get_device_by_mac(node->fatherMac,&gw_node);
res = dm_mgr_get_device_by_devicecode(node->fatherDeviceCode,&gw_node);
if (res != SUCCESS_RETURN) {
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return FAIL_RETURN;
......@@ -691,13 +627,12 @@ int dm_mgr_upstream_thing_sub_unregister(_IN_ int devid)
memset(&request, 0, sizeof(dm_msg_request_t));
request.msgTypeStr = DM_URI_THING_SUB_UNREGISTER;
memcpy(request.productType,gw_node->productType,strlen(gw_node->productType));
memcpy(request.productCode,gw_node->productCode,strlen(gw_node->productCode));
memcpy(request.deviceCode,gw_node->deviceCode,strlen(gw_node->deviceCode));
/* Get Params And Method */
res = dm_msg_thing_sub_unregister(node->productType, node->deviceCode, &request);
res = dm_msg_thing_sub_unregister(node->deviceCode, &request);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -728,7 +663,7 @@ int dm_mgr_upstream_thing_topo_add(_IN_ int devid)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
dm_mgr_dev_node_t *father_node = NULL;
dm_mgr_dev_node_t *gw_node = NULL;
dm_msg_request_t request;
if (devid < 0) {
......@@ -741,7 +676,7 @@ int dm_mgr_upstream_thing_topo_add(_IN_ int devid)
ERROR_PRINT("ERROR res:%d\n",res);
return FAIL_RETURN;
}
res = dm_mgr_get_device_by_mac(node->fatherMac,&father_node);
res = dm_mgr_get_device_by_devicecode(node->fatherDeviceCode,&gw_node);
if (res != SUCCESS_RETURN) {
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
......@@ -750,13 +685,12 @@ int dm_mgr_upstream_thing_topo_add(_IN_ int devid)
memset(&request, 0, sizeof(dm_msg_request_t));
request.msgTypeStr = DM_URI_THING_TOPO_ADD;
memcpy(request.productType,father_node->productType,strlen(father_node->productType));
memcpy(request.productCode,father_node->productCode,strlen(father_node->productCode));
memcpy(request.deviceCode,father_node->deviceCode,strlen(father_node->deviceCode));
memcpy(request.productCode,gw_node->productCode,strlen(gw_node->productCode));
memcpy(request.deviceCode,gw_node->deviceCode,strlen(gw_node->deviceCode));
/* Get Params And Method */
res = dm_msg_thing_topo_add(node->productType, node->productCode, node->deviceCode,node->deviceCode, &request);
res = dm_msg_thing_topo_add( node->productCode, node->deviceCode, &request);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -799,7 +733,7 @@ int dm_mgr_upstream_thing_topo_delete(_IN_ int devid)
return FAIL_RETURN;
}
res = dm_mgr_get_device_by_mac(node->fatherMac,&gw_node);
res = dm_mgr_get_device_by_devicecode(node->fatherDeviceCode,&gw_node);
if (res != SUCCESS_RETURN) {
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return FAIL_RETURN;
......@@ -807,15 +741,13 @@ int dm_mgr_upstream_thing_topo_delete(_IN_ int devid)
memset(&request, 0, sizeof(dm_msg_request_t));
request.msgTypeStr = DM_URI_THING_TOPO_DELETE;
memcpy(request.identity,"",strlen(""));
memcpy(request.productType,gw_node->productType,strlen(gw_node->productType));
memcpy(request.productCode,gw_node->productCode,strlen(gw_node->productCode));
memcpy(request.deviceCode,gw_node->deviceCode,strlen(gw_node->deviceCode));
/* Get Params And Method */
res = dm_msg_thing_topo_delete(node->productType, node->deviceCode, &request);
res = dm_msg_thing_topo_delete( node->deviceCode, &request);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -851,11 +783,10 @@ int dm_mgr_upstream_thing_topo_get(void)
memset(&request, 0, sizeof(dm_msg_request_t));
request.msgTypeStr = DM_URI_THING_TOPO_GET;
HAL_GetProduct_Type(request.productType);
HAL_GetProduct_Code(request.deviceCode);
res = _dm_mgr_search_dev_by_pkdn(request.productType, request.deviceCode, &node);
res = _dm_mgr_search_dev_by_pkdn(request.deviceCode, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -901,7 +832,7 @@ int dm_mgr_upstream_thing_list_found(_IN_ int devid)
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = dm_mgr_get_device_by_mac(node->fatherMac,&gw_node);
res = dm_mgr_get_device_by_devicecode(node->fatherDeviceCode,&gw_node);
if (res != SUCCESS_RETURN) {
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return FAIL_RETURN;
......@@ -909,13 +840,12 @@ int dm_mgr_upstream_thing_list_found(_IN_ int devid)
memset(&request, 0, sizeof(dm_msg_request_t));
request.msgTypeStr = DM_URI_THING_LIST_FOUND;
memcpy(request.productType,gw_node->productType,strlen(gw_node->productType));
memcpy(request.productCode,gw_node->productCode,strlen(gw_node->productCode));
memcpy(request.deviceCode,gw_node->deviceCode,strlen(gw_node->deviceCode));
/* Get Params And Method */
res = dm_msg_thing_list_found(node->productType, node->deviceCode, &request);
res = dm_msg_thing_list_found( node->deviceCode, &request);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -955,18 +885,16 @@ int dm_mgr_upstream_status_online(_IN_ int devid)
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
if(devid != 0){
res = dm_mgr_get_device_by_mac(node->fatherMac,&gw_node);
if(strlen(node->fatherDeviceCode) > 0){
res = dm_mgr_get_device_by_devicecode(node->fatherDeviceCode,&gw_node);
if (res != SUCCESS_RETURN) {
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return FAIL_RETURN;
}
memcpy(request.productType,gw_node->productType,strlen(gw_node->productType));
memcpy(request.productCode,gw_node->productCode,strlen(gw_node->productCode));
memcpy(request.deviceCode,gw_node->deviceCode,strlen(gw_node->deviceCode));
}else{
memcpy(request.productType,node->productType,strlen(node->productType));
memcpy(request.productCode,node->productCode,strlen(node->productCode));
memcpy(request.deviceCode,node->deviceCode,strlen(node->deviceCode));
}
......@@ -977,7 +905,7 @@ int dm_mgr_upstream_status_online(_IN_ int devid)
/* Get Params And Method */
res = dm_msg_status_online(node->productType, node->productCode, node->deviceCode, &request);
res = dm_msg_status_online( node->productCode, node->deviceCode, &request);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -1019,7 +947,7 @@ int dm_mgr_upstream_combine_login(_IN_ int devid)
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = dm_mgr_get_device_by_mac(node->fatherMac,&gw_node);
res = dm_mgr_get_device_by_devicecode(node->fatherDeviceCode,&gw_node);
if (res != SUCCESS_RETURN) {
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return FAIL_RETURN;
......@@ -1027,13 +955,12 @@ int dm_mgr_upstream_combine_login(_IN_ int devid)
memset(&request, 0, sizeof(dm_msg_request_t));
request.msgTypeStr = DM_URI_COMBINE_LOGIN;
memcpy(request.productType,gw_node->productType,strlen(gw_node->productType));
memcpy(request.productCode,gw_node->productCode,strlen(gw_node->productCode));
memcpy(request.deviceCode,gw_node->deviceCode,strlen(gw_node->deviceCode));
/* Get Params And Method */
res = dm_msg_combine_login(node->productType, node->productCode, node->deviceCode, &request);
res = dm_msg_combine_login( node->productCode, node->deviceCode, &request);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -1074,7 +1001,7 @@ int dm_mgr_upstream_combine_logout(_IN_ int devid)
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = dm_mgr_get_device_by_mac(node->fatherMac,&gw_node);
res = dm_mgr_get_device_by_devicecode(node->fatherDeviceCode,&gw_node);
if (res != SUCCESS_RETURN) {
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return FAIL_RETURN;
......@@ -1082,13 +1009,12 @@ int dm_mgr_upstream_combine_logout(_IN_ int devid)
memset(&request, 0, sizeof(dm_msg_request_t));
request.msgTypeStr = DM_URI_COMBINE_LOGOUT;
memcpy(request.productType,gw_node->productType,strlen(gw_node->productType));
memcpy(request.productCode,gw_node->productCode,strlen(gw_node->productCode));
memcpy(request.deviceCode,gw_node->deviceCode,strlen(gw_node->deviceCode));
/* Get Params And Method */
res = dm_msg_combine_logout(node->productType, node->deviceCode, &request);
res = dm_msg_combine_logout( node->deviceCode, &request);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -1137,7 +1063,6 @@ int dm_mgr_ota_report_version(_IN_ int devid, char *version)
return MEMORY_NOT_ENOUGH;
}
sprintf(request.msgTypeStr,KK_URI_OTA_INFORM,node->productCode,node->deviceCode);
memcpy(request.productType, node->productType, PRODUCT_TYPE_MAXLEN);
memcpy(request.productCode, node->productCode, PRODUCT_CODE_MAXLEN);
memcpy(request.deviceCode, node->deviceCode, DEVICE_CODE_MAXLEN);
......@@ -1172,11 +1097,11 @@ int dm_mgr_ota_report_version(_IN_ int devid, char *version)
int dm_mgr_subdev_create(int devtype, _IN_ char productType[PRODUCT_TYPE_MAXLEN],
_IN_ char productCode[PRODUCT_CODE_MAXLEN], _IN_ char deviceCode[DEVICE_CODE_MAXLEN],_IN_ char fatherMac[DEVICE_MAC_MAXLEN], _OU_ int *devid){
int dm_mgr_subdev_create(int devtype,_IN_ char productCode[PRODUCT_CODE_MAXLEN], _IN_ char deviceCode[DEVICE_CODE_MAXLEN],
_IN_ char mac[DEVICE_MAC_MAXLEN],_IN_ char fatherDeviceCode[DEVICE_CODE_MAXLEN], _OU_ int *devid){
int res = 0;
res = dm_mgr_device_create(devtype,productType,productCode,deviceCode,fatherMac, devid);
res = dm_mgr_device_create(devtype,productCode,deviceCode,fatherDeviceCode,mac, devid);
if(TSL_ALREADY_EXIST == res)
{
ERROR_PRINT("SUBDEV ALREADY EXIST!!!\n");
......
......@@ -20,10 +20,10 @@ typedef struct {
int devid;
int dev_type;
kk_tsl_t *dev_shadow;
char productType[PRODUCT_TYPE_MAXLEN];
char mac[DEVICE_MAC_MAXLEN];
char productCode[PRODUCT_CODE_MAXLEN];
char deviceCode[DEVICE_CODE_MAXLEN];
char fatherMac[DEVICE_MAC_MAXLEN];
char fatherDeviceCode[DEVICE_CODE_MAXLEN];
struct list_head linked_list;
} dm_mgr_dev_node_t;
......@@ -40,7 +40,6 @@ typedef struct {
//const char *service_name;
char *msgTypeStr;
char identity[IDENTIFY_MAXLEN];
char productType[PRODUCT_TYPE_MAXLEN];
char productCode[PRODUCT_CODE_MAXLEN];
char deviceCode[DEVICE_CODE_MAXLEN];
char *params;
......@@ -50,7 +49,6 @@ typedef struct {
} dm_msg_request_t;
typedef struct {
char *msgTypeStr;
char productType[PRODUCT_TYPE_MAXLEN];
char productCode[PRODUCT_CODE_MAXLEN];
char deviceCode[DEVICE_CODE_MAXLEN];
......
......@@ -9,7 +9,7 @@
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\":\"%s\",\"productType\":\"%s\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"}";
const char DM_MSG_INFO[] DM_READ_ONLY = "{\"msgtype\":\"%s\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"}";
void kk_sendData2app(void *info, void *payload){
cJSON *root=cJSON_CreateObject();
......@@ -24,31 +24,28 @@ void kk_sendData2app(void *info, void *payload){
}
const char DM_MSG_THING_SUB_REGISTER_METHOD[] = "thing.sub.register";
const char DM_MSG_THING_SUB_REGISTER_PARAMS[] = "[{\"productType\":\"%s\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"}]";
const char DM_MSG_THING_SUB_REGISTER_PARAMS[] = "[{\"productCode\":\"%s\",\"deviceCode\":\"%s\"}]";
int dm_msg_thing_sub_register(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
_IN_ char productCode[DEVICE_CODE_MAXLEN], _IN_ char deviceCode[DEVICE_CODE_MAXLEN],
int dm_msg_thing_sub_register(_IN_ char productCode[DEVICE_CODE_MAXLEN], _IN_ char deviceCode[DEVICE_CODE_MAXLEN],
_OU_ dm_msg_request_t *request)
{
int params_len = 0;
char *params = NULL;
if (request == NULL || productType == NULL || deviceCode == NULL ||
(strlen(productType) >= PRODUCT_TYPE_MAXLEN) ||
if (request == NULL || deviceCode == NULL ||
(strlen(deviceCode) >= DEVICE_CODE_MAXLEN) ||
(strlen(request->productType) >= PRODUCT_TYPE_MAXLEN) ||
(strlen(request->deviceCode) >= DEVICE_CODE_MAXLEN)) {
return INVALID_PARAMETER;
}
params_len = strlen(DM_MSG_THING_SUB_REGISTER_PARAMS) + strlen(productType)+strlen(productCode) + strlen(deviceCode) + 1;
params_len = strlen(DM_MSG_THING_SUB_REGISTER_PARAMS) +strlen(productCode) + strlen(deviceCode) + 1;
params = malloc(params_len);
if (params == NULL) {
return MEMORY_NOT_ENOUGH;
}
memset(params, 0, params_len);
snprintf(params, params_len, DM_MSG_THING_SUB_REGISTER_PARAMS, productType,productCode, deviceCode);
snprintf(params, params_len, DM_MSG_THING_SUB_REGISTER_PARAMS,productCode, deviceCode);
/* Get Params */
request->params = params;
......@@ -61,29 +58,25 @@ int dm_msg_thing_sub_register(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
}
const char DM_MSG_THING_SUB_UNREGISTER_METHOD[] DM_READ_ONLY = "thing.sub.unregister";
const char DM_MSG_THING_SUB_UNREGISTER_PARAMS[] DM_READ_ONLY = "[{\"productKey\":\"%s\",\"deviceName\":\"%s\"}]";
int dm_msg_thing_sub_unregister(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
_IN_ char deviceCode[DEVICE_CODE_MAXLEN],
_OU_ dm_msg_request_t *request)
const char DM_MSG_THING_SUB_UNREGISTER_PARAMS[] DM_READ_ONLY = "[{\"deviceCode\":\"%s\"}]";
int dm_msg_thing_sub_unregister(_IN_ char deviceCode[DEVICE_CODE_MAXLEN],_OU_ dm_msg_request_t *request)
{
int params_len = 0;
char *params = NULL;
if (request == NULL || productType == NULL || deviceCode == NULL ||
(strlen(productType) >= PRODUCT_TYPE_MAXLEN) ||
if (request == NULL || deviceCode == NULL ||
(strlen(deviceCode) >= DEVICE_CODE_MAXLEN) ||
(strlen(request->productType) >= PRODUCT_TYPE_MAXLEN) ||
(strlen(request->deviceCode) >= DEVICE_CODE_MAXLEN)) {
return INVALID_PARAMETER;
}
params_len = strlen(DM_MSG_THING_SUB_UNREGISTER_PARAMS) + strlen(productType) + strlen(deviceCode) + 1;
params_len = strlen(DM_MSG_THING_SUB_UNREGISTER_PARAMS) + strlen(deviceCode) + 1;
params = malloc(params_len);
if (params == NULL) {
return MEMORY_NOT_ENOUGH;
}
memset(params, 0, params_len);
snprintf(params, params_len, DM_MSG_THING_SUB_UNREGISTER_PARAMS, productType, deviceCode);
snprintf(params, params_len, DM_MSG_THING_SUB_UNREGISTER_PARAMS, deviceCode);
/* Get Params */
request->params = params;
......@@ -95,14 +88,13 @@ int dm_msg_thing_sub_unregister(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
return SUCCESS_RETURN;
}
const char DM_MSG_THING_TOPO_ADD_SIGN_SOURCE[] DM_READ_ONLY = "clientId%sdeviceName%sproductKey%stimestamp%s";
const char DM_MSG_THING_TOPO_ADD_SIGN_SOURCE[] DM_READ_ONLY = "clientId%sdeviceCode%stimestamp%s";
const char DM_MSG_THING_TOPO_ADD_METHOD[] DM_READ_ONLY = "thing.topo.add";
const char DM_MSG_THING_TOPO_ADD_PARAMS[] DM_READ_ONLY =
//"[{\"productKey\":\"%s\",\"deviceName\":\"%s\",\"signmethod\":\"%s\",\"sign\":\"%s\",\"timestamp\":\"%s\",\"clientId\":\"%s\"}]";
"[{\"productCode\":\"%s\",\"deviceCode\":\"%s\",\"mac\":\"%s\"}]";
int dm_msg_thing_topo_add(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
_IN_ char productCode[PRODUCT_CODE_MAXLEN],
int dm_msg_thing_topo_add(_IN_ char productCode[PRODUCT_CODE_MAXLEN],
_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _IN_ char mac[DEVICE_MAC_MAXLEN],
_OU_ dm_msg_request_t *request)
{
......@@ -116,12 +108,10 @@ int dm_msg_thing_topo_add(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
char sign[65] = {0};
if (request == NULL || productType == NULL ||
productCode == NULL || deviceCode == NULL ||
(strlen(productType) >= PRODUCT_TYPE_MAXLEN) ||
if (request == NULL ||
deviceCode == NULL ||
(strlen(productCode) >= PRODUCT_CODE_MAXLEN) ||
(strlen(deviceCode) >= DEVICE_CODE_MAXLEN) ||
(strlen(request->productType) >= PRODUCT_TYPE_MAXLEN) ||
(strlen(request->deviceCode) >= DEVICE_CODE_MAXLEN)) {
return INVALID_PARAMETER;
}
......@@ -131,18 +121,18 @@ int dm_msg_thing_topo_add(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
/* dm_log_debug("Time Stamp: %s", timestamp); */
/* Client ID */
HAL_Snprintf(client_id, PRODUCT_TYPE_MAXLEN + DEVICE_CODE_MAXLEN + 1, "%s.%s", productType, deviceCode);
HAL_Snprintf(client_id, DEVICE_CODE_MAXLEN + 1, "%s", deviceCode);
/* Sign */
sign_source_len = strlen(DM_MSG_THING_TOPO_ADD_SIGN_SOURCE) + strlen(client_id) +
strlen(deviceCode) + strlen(productType) + strlen(timestamp) + 1;
strlen(deviceCode) + strlen(timestamp) + 1;
sign_source = malloc(sign_source_len);
if (sign_source == NULL) {
return MEMORY_NOT_ENOUGH;
}
memset(sign_source, 0, sign_source_len);
HAL_Snprintf(sign_source, sign_source_len, DM_MSG_THING_TOPO_ADD_SIGN_SOURCE, client_id,
deviceCode, productType, timestamp);
deviceCode, timestamp);
/* dm_log_debug("Sign Srouce: %s", sign_source); */
#if 0
......@@ -164,7 +154,7 @@ int dm_msg_thing_topo_add(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
/* Params */
request->method = (char *)DM_MSG_THING_TOPO_ADD_METHOD;
params_len = strlen(DM_MSG_THING_TOPO_ADD_PARAMS) + strlen(productType) + strlen(deviceCode) +
params_len = strlen(DM_MSG_THING_TOPO_ADD_PARAMS) + strlen(deviceCode) +
strlen(sign_method) + strlen(sign) + strlen(timestamp) + strlen(client_id) + 1;
params = malloc(params_len);
......@@ -183,32 +173,28 @@ int dm_msg_thing_topo_add(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
}
const char DM_MSG_THING_TOPO_DELETE_METHOD[] DM_READ_ONLY = "thing.topo.delete";
const char DM_MSG_THING_TOPO_DELETE_PARAMS[] DM_READ_ONLY = "[{\"productKey\":\"%s\",\"deviceName\":\"%s\"}]";
int dm_msg_thing_topo_delete(_IN_ char productType[PRODUCT_CODE_MAXLEN],
_IN_ char deviceCode[DEVICE_CODE_MAXLEN],
_OU_ dm_msg_request_t *request)
const char DM_MSG_THING_TOPO_DELETE_PARAMS[] DM_READ_ONLY = "[{\"deviceCode\":\"%s\"}]";
int dm_msg_thing_topo_delete(_IN_ char deviceCode[DEVICE_CODE_MAXLEN],_OU_ dm_msg_request_t *request)
{
char *params = NULL;
int params_len = 0;
if (request == NULL || productType == NULL ||
if (request == NULL ||
deviceCode == NULL ||
(strlen(productType) >= PRODUCT_CODE_MAXLEN) ||
(strlen(deviceCode) >= DEVICE_CODE_MAXLEN) ||
(strlen(request->productType) >= PRODUCT_CODE_MAXLEN) ||
(strlen(request->deviceCode) >= DEVICE_CODE_MAXLEN)) {
return INVALID_PARAMETER;
}
/* Params */
request->method = (char *)DM_MSG_THING_TOPO_DELETE_METHOD;
params_len = strlen(DM_MSG_THING_TOPO_DELETE_PARAMS) + strlen(productType) + strlen(deviceCode) + 1;
params_len = strlen(DM_MSG_THING_TOPO_DELETE_PARAMS) + strlen(deviceCode) + 1;
params = malloc(params_len);
if (params == NULL) {
return MEMORY_NOT_ENOUGH;
}
memset(params, 0, params_len);
HAL_Snprintf(params, params_len, DM_MSG_THING_TOPO_DELETE_PARAMS, deviceCode, deviceCode);
HAL_Snprintf(params, params_len, DM_MSG_THING_TOPO_DELETE_PARAMS, deviceCode);
request->params = params;
request->params_len = strlen(request->params);
......@@ -240,16 +226,14 @@ int dm_msg_thing_topo_delete(_IN_ char productType[PRODUCT_CODE_MAXLEN],
}
const char DM_MSG_THING_LIST_FOUND_METHOD[] DM_READ_ONLY = "thing.list.found";
const char DM_MSG_THING_LIST_FOUND_PARAMS[] DM_READ_ONLY = "[{\"productKey\":\"%s\",\"deviceName\":\"%s\"}]";
int dm_msg_thing_list_found(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
_IN_ char deviceCode[DEVICE_CODE_MAXLEN],
const char DM_MSG_THING_LIST_FOUND_PARAMS[] DM_READ_ONLY = "[{\"deviceCode\":\"%s\"}]";
int dm_msg_thing_list_found(_IN_ char deviceCode[DEVICE_CODE_MAXLEN],
_OU_ dm_msg_request_t *request)
{
char *params = NULL;
int params_len = 0;
if (productType == NULL || deviceCode == NULL ||
(strlen(productType) >= PRODUCT_TYPE_MAXLEN) ||
if ( deviceCode == NULL ||
(strlen(deviceCode) >= DEVICE_CODE_MAXLEN) ||
request == NULL) {
return INVALID_PARAMETER;
......@@ -257,13 +241,13 @@ int dm_msg_thing_topo_delete(_IN_ char productType[PRODUCT_CODE_MAXLEN],
/* Params */
request->method = (char *)DM_MSG_THING_LIST_FOUND_METHOD;
params_len = strlen(DM_MSG_THING_LIST_FOUND_PARAMS) + strlen(productType) + strlen(deviceCode) + 1;
params_len = strlen(DM_MSG_THING_LIST_FOUND_PARAMS) + strlen(deviceCode) + 1;
params = malloc(params_len);
if (params == NULL) {
return MEMORY_NOT_ENOUGH;
}
memset(params, 0, params_len);
HAL_Snprintf(params, params_len, DM_MSG_THING_LIST_FOUND_PARAMS, productType, deviceCode);
HAL_Snprintf(params, params_len, DM_MSG_THING_LIST_FOUND_PARAMS, deviceCode);
request->params = params;
request->params_len = strlen(request->params);
......@@ -273,8 +257,7 @@ int dm_msg_thing_topo_delete(_IN_ char productType[PRODUCT_CODE_MAXLEN],
const char DM_MSG_COMBINE_STATUS_ONLINE_METHOD[] DM_READ_ONLY = "thing.status.online";
const char DM_MSG_COMBINE_STATUS_ONLINE[] DM_READ_ONLY =
"{\"deviceCode\":\"%s\"}";
int dm_msg_status_online(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
_IN_ char productCode[PRODUCT_CODE_MAXLEN],
int dm_msg_status_online(_IN_ char productCode[PRODUCT_CODE_MAXLEN],
_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_msg_request_t *request)
{
char *params = NULL;
......@@ -285,12 +268,10 @@ const char DM_MSG_COMBINE_STATUS_ONLINE[] DM_READ_ONLY =
char sign[64] = {0};
if (request == NULL || productType == NULL ||
if (request == NULL ||
deviceCode == NULL || productCode == NULL ||
(strlen(productType) >= PRODUCT_TYPE_MAXLEN) ||
(strlen(deviceCode) >= DEVICE_CODE_MAXLEN) ||
(strlen(productCode) >= PRODUCT_CODE_MAXLEN) ||
(strlen(request->productType) >= PRODUCT_TYPE_MAXLEN) ||
(strlen(request->deviceCode) >= DEVICE_CODE_MAXLEN)) {
return INVALID_PARAMETER;
}
......@@ -318,12 +299,11 @@ const char DM_MSG_COMBINE_STATUS_ONLINE[] DM_READ_ONLY =
}
const char DM_MSG_COMBINE_LOGIN_SIGN_SOURCE[] DM_READ_ONLY = "clientId%sdeviceName%sproductKey%stimestamp%s";
const char DM_MSG_COMBINE_LOGIN_SIGN_SOURCE[] DM_READ_ONLY = "clientId%sdeviceCode%stimestamp%s";
const char DM_MSG_COMBINE_LOGIN_METHOD[] DM_READ_ONLY = "combine.login";
const char DM_MSG_COMBINE_LOGIN_PARAMS[] DM_READ_ONLY =
"{\"productKey\":\"%s\",\"deviceName\":\"%s\",\"clientId\":\"%s\",\"timestamp\":\"%s\",\"signMethod\":\"%s\",\"sign\":\"%s\",\"cleanSession\":\"%s\"}";
int dm_msg_combine_login(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
_IN_ char productCode[PRODUCT_CODE_MAXLEN],
"{\"deviceCode\":\"%s\",\"clientId\":\"%s\",\"timestamp\":\"%s\",\"signMethod\":\"%s\",\"sign\":\"%s\",\"cleanSession\":\"%s\"}";
int dm_msg_combine_login(_IN_ char productCode[PRODUCT_CODE_MAXLEN],
_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_msg_request_t *request)
{
char *params = NULL;
......@@ -335,13 +315,10 @@ int dm_msg_combine_login(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
char *sign_method = DM_MSG_SIGN_METHOD_HMACSHA1;
char sign[64] = {0};
if (request == NULL || productType == NULL ||
if (request == NULL ||
deviceCode == NULL || productCode == NULL ||
(strlen(productType) >= PRODUCT_TYPE_MAXLEN) ||
(strlen(deviceCode) >= DEVICE_CODE_MAXLEN) ||
(strlen(productCode) >= PRODUCT_CODE_MAXLEN) ||
(strlen(request->productType) >= PRODUCT_TYPE_MAXLEN) ||
(strlen(request->deviceCode) >= DEVICE_CODE_MAXLEN)) {
return INVALID_PARAMETER;
}
......@@ -351,18 +328,18 @@ int dm_msg_combine_login(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
/* dm_log_debug("Time Stamp: %s", timestamp); */
/* Client ID */
HAL_Snprintf(client_id, PRODUCT_TYPE_MAXLEN + DEVICE_CODE_MAXLEN + 20, "%s.%s|_v=sdk-c-3.0.1|", productType, deviceCode);
HAL_Snprintf(client_id, PRODUCT_TYPE_MAXLEN + DEVICE_CODE_MAXLEN + 20, "%s|_v=sdk-c-3.0.1|", deviceCode);
/* Sign */
sign_source_len = strlen(DM_MSG_COMBINE_LOGIN_SIGN_SOURCE) + strlen(client_id) +
strlen(deviceCode) + strlen(productType) + strlen(timestamp) + 1;
strlen(deviceCode) + strlen(timestamp) + 1;
sign_source = malloc(sign_source_len);
if (sign_source == NULL) {
return DM_MEMORY_NOT_ENOUGH;
}
memset(sign_source, 0, sign_source_len);
HAL_Snprintf(sign_source, sign_source_len, DM_MSG_COMBINE_LOGIN_SIGN_SOURCE, client_id,
deviceCode, productType, timestamp);
deviceCode, timestamp);
/* dm_log_debug("Sign Srouce: %s", sign_source); */
#if 0
......@@ -384,7 +361,7 @@ int dm_msg_combine_login(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
/* Params */
request->method = (char *)DM_MSG_COMBINE_LOGIN_METHOD;
params_len = strlen(DM_MSG_COMBINE_LOGIN_PARAMS) + strlen(productType) + strlen(deviceCode) +
params_len = strlen(DM_MSG_COMBINE_LOGIN_PARAMS) + strlen(deviceCode) +
strlen(sign_method) + strlen(sign) + strlen(timestamp) + strlen(client_id) + 1;
params = malloc(params_len);
......@@ -392,7 +369,7 @@ int dm_msg_combine_login(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
return DM_MEMORY_NOT_ENOUGH;
}
memset(params, 0, params_len);
HAL_Snprintf(params, params_len, DM_MSG_COMBINE_LOGIN_PARAMS, productType, deviceCode,
HAL_Snprintf(params, params_len, DM_MSG_COMBINE_LOGIN_PARAMS, deviceCode,
client_id, timestamp, sign_method, sign, "true");
request->params = params;
......@@ -403,32 +380,29 @@ int dm_msg_combine_login(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
const char DM_MSG_COMBINE_LOGOUT_METHOD[] DM_READ_ONLY = "combine.logout";
const char DM_MSG_COMBINE_LOGOUT_PARAMS[] DM_READ_ONLY = "{\"productKey\":\"%s\",\"deviceName\":\"%s\"}";
int dm_msg_combine_logout(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
_IN_ char deviceCode[DEVICE_CODE_MAXLEN],
_OU_ dm_msg_request_t *request)
const char DM_MSG_COMBINE_LOGOUT_PARAMS[] DM_READ_ONLY = "{\"deviceCode\":\"%s\"}";
int dm_msg_combine_logout(_IN_ char deviceCode[DEVICE_CODE_MAXLEN],_OU_ dm_msg_request_t *request)
{
char *params = NULL;
int params_len = 0;
if (productType == NULL || deviceCode == NULL ||
(strlen(productType) >= PRODUCT_TYPE_MAXLEN ||
if ( deviceCode == NULL ||
(strlen(deviceCode) >= DEVICE_CODE_MAXLEN) ||
request == NULL) ){
request == NULL){
return INVALID_PARAMETER;
}
/* Params */
request->method = (char *)DM_MSG_COMBINE_LOGOUT_METHOD;
params_len = strlen(DM_MSG_COMBINE_LOGOUT_PARAMS) + strlen(productType) + strlen(deviceCode) + 1;
params_len = strlen(DM_MSG_COMBINE_LOGOUT_PARAMS) + strlen(deviceCode) + 1;
params = malloc(params_len);
if (params == NULL) {
return MEMORY_NOT_ENOUGH;
}
memset(params, 0, params_len);
HAL_Snprintf(params, params_len, DM_MSG_COMBINE_LOGOUT_PARAMS, productType, deviceCode);
HAL_Snprintf(params, params_len, DM_MSG_COMBINE_LOGOUT_PARAMS, deviceCode);
request->params = params;
request->params_len = strlen(request->params);
......@@ -489,15 +463,14 @@ int dm_msg_request (_IN_ dm_msg_request_t *request)
snprintf(payload, payload_len, DM_MSG_REQUEST, request->msgid,
DM_MSG_VERSION, request->params_len, request->params, request->method);
req_info_len = strlen(DM_MSG_INFO)+10+strlen(request->productType)+strlen(request->productCode)+strlen(request->deviceCode)+strlen(request->msgTypeStr)+1;
req_info_len = strlen(DM_MSG_INFO)+10+strlen(request->productCode)+strlen(request->deviceCode)+strlen(request->msgTypeStr)+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->msgTypeStr,
request->productType, request->productCode, request->deviceCode);
snprintf(req_info, req_info_len, DM_MSG_INFO, request->msgTypeStr, request->productCode, request->deviceCode);
memset(&lite, 0, sizeof(lite_cjson_t));
res = lite_cjson_parse(payload, payload_len, &lite);
......@@ -551,7 +524,7 @@ int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response
snprintf(payload, payload_len, DM_MSG_RESPONSE_WITH_DATA,
request->id.value_length, request->id.value, response->code, data_len, data);
res_info_len = strlen(DM_MSG_INFO)+10+strlen(response->productType)+strlen(response->productCode)+strlen(response->deviceCode)+strlen(response->msgTypeStr)+1;
res_info_len = strlen(DM_MSG_INFO)+10+strlen(response->productCode)+strlen(response->deviceCode)+strlen(response->msgTypeStr)+1;
res_info = malloc(res_info_len);
if (res_info == NULL) {
free(payload);
......@@ -559,8 +532,7 @@ int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response
}
memset(res_info, 0, res_info_len);
snprintf(res_info, res_info_len, DM_MSG_INFO, response->msgTypeStr,
response->productType,response->productCode, response->deviceCode);
snprintf(res_info, res_info_len, DM_MSG_INFO, response->msgTypeStr,response->productCode, response->deviceCode);
memset(&lite, 0, sizeof(lite_cjson_t));
......@@ -662,7 +634,7 @@ int dm_msg_thing_property_set_reply(char deviceCode[DEVICE_CODE_MAXLEN],char *pa
memset(&request, 0, sizeof(kk_msg_request_payload_t));
memset(&response, 0, sizeof(kk_msg_response_t));
res = dm_mgr_get_device_by_mac(deviceCode, &node);
res = dm_mgr_get_device_by_devicecode(deviceCode, &node);
if (res < SUCCESS_RETURN) {
ERROR_PRINT("dm_mgr_search_device_by_pkdn failed");
return res;
......@@ -674,7 +646,6 @@ int dm_msg_thing_property_set_reply(char deviceCode[DEVICE_CODE_MAXLEN],char *pa
}
response.msgTypeStr = DM_URI_THING_SERVICE_PROPERTY_SET_REPLY;
memcpy(response.productType, node->productType, strlen( node->productType));
memcpy(response.productCode, node->productCode, strlen( node->productCode));
memcpy(response.deviceCode, node->deviceCode, strlen(node->deviceCode));
response.code = (res == SUCCESS_RETURN) ? (IOTX_DM_ERR_CODE_SUCCESS) : (IOTX_DM_ERR_CODE_REQUEST_ERROR);
......
......@@ -249,7 +249,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
//get devicececret and save it
INFO_PRINT(" topic:register_reply \n");
dm_msg_response_payload_t response;
res = dm_msg_response_parse((char *)payload_Str, strlen(payload_Str)+1, &response);
res = dm_msg_response_parse((char *)payload_Str, strlen(payload->valuestring)+1, &response);
if (res != SUCCESS_RETURN) {
goto directReturn;
}
......@@ -263,7 +263,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
//
INFO_PRINT(" topic:add_reply \n");
dm_msg_response_payload_t response;
res = dm_msg_response_parse((char *)payload_Str, strlen(payload_Str)+1, &response);
res = dm_msg_response_parse((char *)payload_Str, strlen(payload->valuestring)+1, &response);
if (res != SUCCESS_RETURN) {
goto directReturn;
}
......@@ -272,12 +272,12 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
_iotx_linkkit_upstream_callback_remove(atoi(response.id.value), response.code.value_int);
_iotx_linkkit_upstream_mutex_unlock();
}else if (strstr(typeJson->valuestring,KK_LOGIN_TOPIC_REPLY) || strstr(typeJson->valuestring,KK_ONLINE_TOPIC_REPLY)){
}else if (strstr(typeJson->valuestring,KK_LOGIN_TOPIC_REPLY)){
//====todo======
//
INFO_PRINT(" topic:login_reply \n");
dm_msg_response_payload_t response;
res = dm_msg_response_parse((char *)payload_Str, strlen(payload_Str)+1, &response);
res = dm_msg_response_parse((char *)payload_Str, strlen(payload->valuestring)+1, &response);
if (res != SUCCESS_RETURN) {
goto directReturn;
}
......@@ -305,6 +305,9 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
{
ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
}
iotx_dm_dev_online(0);//first online,report the online status
usleep(200000);
kk_tsl_post_property(0,NULL);
}else if (strstr(typeJson->valuestring,KK_THING_OTA_DEVICE_UPGRADE)){
INFO_PRINT("ota upgrade... \n");
kk_dm_ota_send(data, strlen(data)+1);
......@@ -1035,7 +1038,6 @@ int _iotx_linkkit_slave_connect(int devid)
return FAIL_RETURN;
}
#if 0
/* Subdev Register */
res = kk_dm_subdev_register(devid);
if (res < SUCCESS_RETURN) {
......@@ -1076,9 +1078,7 @@ int _iotx_linkkit_slave_connect(int devid)
_iotx_linkkit_upstream_mutex_unlock();
}
#endif
/* Subdev Add Topo */
res = kk_dm_subdev_topo_add(devid);
if (res < SUCCESS_RETURN) {
......@@ -1339,7 +1339,7 @@ static int _iotx_linkkit_subdev_login(int devid)
void *semaphore = NULL;
void *callback = NULL;
res = iotx_dm_dev_online(devid);//iotx_dm_subdev_login(devid);
res = iotx_dm_subdev_login(devid);
if (res < SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -1672,18 +1672,18 @@ int iot_linkkit_subdev_query_id(char product_key[IOTX_PRODUCT_KEY_LEN + 1], char
#endif /* #ifdef DEVICE_MODEL_GATEWAY */
int kk_mid_subdev_add(int devType, char productType[PRODUCT_TYPE_MAXLEN], char productCode[PRODUCT_CODE_MAXLEN], char deviceCode[DEVICE_CODE_MAXLEN],char fatherMac[DEVICE_MAC_MAXLEN]){
int kk_mid_subdev_add(int devType, char productCode[PRODUCT_CODE_MAXLEN], char deviceCode[DEVICE_CODE_MAXLEN],char mac[DEVICE_MAC_MAXLEN],char fatherDeviceCode[DEVICE_CODE_MAXLEN]){
int res = 0;
int devid = 0;
res = dm_mgr_subdev_create(devType, productType,productCode,deviceCode,fatherMac,&devid);
res = dm_mgr_subdev_create(devType,productCode,deviceCode,mac,fatherDeviceCode,&devid);
if (res != SUCCESS_RETURN) {
ERROR_PRINT("subdev create Failed\n");
return FAIL_RETURN;
}
INFO_PRINT("subdev open susseed, devid = %d\n", devid);
res = kk_subDev_insert_db(devType,productCode,deviceCode,fatherMac,"1.1.0");
res = kk_subDev_insert_db(KK_DM_DEVICE_SUBDEV,productCode,deviceCode,fatherDeviceCode,mac,"1.1.0");
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -1703,3 +1703,4 @@ int kk_mid_subdev_add(int devType, char productType[PRODUCT_TYPE_MAXLEN], char p
return SUCCESS_RETURN;
}
......@@ -12,6 +12,18 @@ typedef struct {
int subDevNum;
sqlite3 *pDb;
} kk_subDb_ctx_t;
typedef enum{
DB_IDX = 0,
DB_ONLINE,
DB_PRODUCTCODE,
DB_DEVICECODE,
DB_MAC,
DB_FATHERDEVICECODE,
DB_VERSION,
DB_AUTH,
DB_DEVTYPE,
};
static kk_subDb_ctx_t s_kk_subDb_ctx = {NULL,0,NULL};
static kk_subDb_ctx_t *_kk_subDb_get_ctx(void)
......@@ -54,7 +66,8 @@ static int kk_subDev_db_Init(void)
isOnline INTEGER, \
productCode varchar(33), \
deviceCode varchar(33), \
fatherMac varchar(17), \
mac varchar(17), \
fatherDeviceCode varchar(33), \
version varchar(33), \
isAuth INTEGER, \
devType INTEGER)";
......@@ -90,8 +103,9 @@ static int _kk_load_subDevice(void)
INFO_PRINT("_kk_load_subDevice total_column = %d\n", sqlite3_column_count(stmt));
while(sqlite3_step(stmt) == SQLITE_ROW){
res = dm_mgr_subdev_create(sqlite3_column_int(stmt, 7), "",sqlite3_column_text(stmt, 2),sqlite3_column_text(stmt, 3),
sqlite3_column_text(stmt, 4),&devId);
res = dm_mgr_subdev_create(sqlite3_column_int(stmt, DB_DEVTYPE),sqlite3_column_text(stmt, DB_PRODUCTCODE),
sqlite3_column_text(stmt, DB_DEVICECODE),
sqlite3_column_text(stmt, DB_MAC),sqlite3_column_text(stmt, DB_FATHERDEVICECODE),&devId);
if(res != SUCCESS_RETURN){
ERROR_PRINT("[%s][%d]dm_mgr_subdev_create FAIL!!!\n",__FUNCTION__,__LINE__);
......@@ -104,7 +118,7 @@ static int _kk_load_subDevice(void)
//再上线
iotx_dm_subscribe(devId);
kk_dm_ota_report_version(devId,sqlite3_column_text(stmt, 5));//version
kk_dm_ota_report_version(devId,sqlite3_column_text(stmt, DB_VERSION));//version
//usleep(100000);
}
sqlite3_finalize(stmt);
......@@ -142,7 +156,7 @@ static int _kk_check_subDev_exist(const char* deviceCode)
sqlite3_prepare_v2(ctx->pDb, searchCmd, strlen(searchCmd), &stmt, NULL);
INFO_PRINT("total_column = %d\n", sqlite3_column_count(stmt));
while(sqlite3_step(stmt) == SQLITE_ROW){
pmac = sqlite3_column_text(stmt, 3);
pmac = sqlite3_column_text(stmt, DB_DEVICECODE);
if(!strcmp(deviceCode,pmac))
{
isExist = 1;
......@@ -159,10 +173,10 @@ static int _kk_check_subDev_exist(const char* deviceCode)
}
int kk_subDev_insert_db(int devType,char productCode[PRODUCT_CODE_MAXLEN], \
char deviceCode[DEVICE_CODE_MAXLEN],char fatherMac[DEVICE_MAC_MAXLEN],char version[DEVICE_VERSION_MAXLEN])
char deviceCode[DEVICE_CODE_MAXLEN],char fatherDeviceCode[DEVICE_CODE_MAXLEN],char version[DEVICE_VERSION_MAXLEN])
{
const char *insertCmd = "insert into SubDeviceInfo (idx,isOnline,productCode,deviceCode,fatherMac,version,isAuth,devType) \
values ('%d','%d', '%s','%s','%s','%s','%d','%d');";
const char *insertCmd = "insert into SubDeviceInfo (idx,isOnline,productCode,deviceCode,mac,fatherMac,version,isAuth,devType) \
values ('%d','%d', '%s','%s','%s','%s','%s','%d','%d');";
char *sqlCmd = NULL;
int rc = 0;
char *zErrMsg = 0;
......@@ -175,7 +189,7 @@ int kk_subDev_insert_db(int devType,char productCode[PRODUCT_CODE_MAXLEN], \
return SUCCESS_RETURN;
}
_kk_subDb_lock();
sqlCmd = sqlite3_mprintf(insertCmd,ctx->subDevNum,0,productCode,deviceCode,fatherMac,version,0,devType);
sqlCmd = sqlite3_mprintf(insertCmd,ctx->subDevNum,0,productCode,deviceCode,fatherDeviceCode,version,0,devType);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){
......@@ -189,7 +203,7 @@ int kk_subDev_insert_db(int devType,char productCode[PRODUCT_CODE_MAXLEN], \
_kk_subDb_unlock();
return SUCCESS_RETURN;
}
int kk_subDev_delete_byMac(char deviceCode[DEVICE_CODE_MAXLEN])
int kk_subDev_delete_by_dcode(char deviceCode[DEVICE_CODE_MAXLEN])
{
const char *deleteCmd = "delete from SubDeviceInfo where deviceCode = %s;";
char *sqlCmd = NULL;
......@@ -213,7 +227,7 @@ int kk_subDev_delete_byMac(char deviceCode[DEVICE_CODE_MAXLEN])
return SUCCESS_RETURN;
}
int kk_subDev_update_online(int isOnline,const char *device_mac)
int kk_subDev_update_online(int isOnline,const char *deviceCode)
{
char *sqlCmd = NULL;
int len =0;
......@@ -222,7 +236,7 @@ int kk_subDev_update_online(int isOnline,const char *device_mac)
kk_subDb_ctx_t *ctx = _kk_subDb_get_ctx();
_kk_subDb_lock();
sqlCmd = sqlite3_mprintf("UPDATE SubDeviceInfo SET isOnline=%d WHERE deviceCode=%s",isOnline,device_mac);
sqlCmd = sqlite3_mprintf("UPDATE SubDeviceInfo SET isOnline=%d WHERE deviceCode=%s",isOnline,deviceCode);
INFO_PRINT("kk_subDev_update_online sqlCmd:%s\n",sqlCmd);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){
......
......@@ -27,8 +27,7 @@ char * g_filerToPlatTable[] =
{KK_ADD_TOPIC_REPLY},
{KK_LOGIN_TOPIC_REPLY},
{KK_THING_OTA_DEVICE_UPGRADE},
{KK_THING_CLOUDSTATE_MSG},
{KK_ONLINE_TOPIC_REPLY},
{KK_THING_CLOUDSTATE_MSG},
};
static int _kk_filter_to_plat(const char* msgtype)
......@@ -77,19 +76,19 @@ void mid_cb(void* data, int len){
}
int devType = 0;
dm_mgr_get_deviceType_by_mac(deviceCode->valuestring,&devType);
dm_mgr_get_devicetype_by_devicecode(deviceCode->valuestring,&devType);
if(devType == KK_DM_DEVICE_GATEWAY){
kk_ipc_send_ex(IPC_MID2PLAT, data, strlen(data), deviceCode->valuestring);//send to gw itself
}else if(devType == KK_DM_DEVICE_SUBDEV){
dm_mgr_dev_node_t *gw_node = NULL;
res = dm_mgr_get_device_by_mac(deviceCode->valuestring,&gw_node);
res = dm_mgr_get_device_by_devicecode(deviceCode->valuestring,&gw_node);
if (res != SUCCESS_RETURN) {
ERROR_PRINT("res:%d\n",res);
cJSON_Delete(json);
cJSON_Delete(info);
return;
}
kk_ipc_send_ex(IPC_MID2PLAT, data, strlen(data), gw_node->fatherMac);//send to sub device
kk_ipc_send_ex(IPC_MID2PLAT, data, strlen(data), gw_node->fatherDeviceCode);//send to sub device
}
else{
ERROR_PRINT("wrong type\n");
......@@ -140,33 +139,40 @@ void kk_platMsg_handle(void* data, char* chalMark){
char *out;
int res = 0;
cJSON *json;
cJSON *method;
cJSON *info;
cJSON *info_dcode;
cJSON *params;
cJSON *jsonPay;
cJSON *proType;
cJSON *msgType;
cJSON *proCode;
cJSON *devCode;
cJSON *mac;
cJSON *payload;
json=cJSON_Parse(data);
if (!json) {
WARNING_PRINT("Error before: [%s]\n","cJSON_Parse");
}
else{
method = cJSON_GetObjectItem(json, "method");
mac = cJSON_GetObjectItem(json, "mac");
if (method != NULL && strcmp(method->valuestring, "thing.topo.add")==0){
jsonPay = cJSON_GetObjectItem(json, "params");
proType = cJSON_GetObjectItem(jsonPay, "productType");
info = cJSON_GetObjectItem(json, "info");
payload = cJSON_GetObjectItem(json, "payload");
if(info != NULL){
msgType = cJSON_GetObjectItem(info, "msgType");
info_dcode = cJSON_GetObjectItem(info, "deviceCode");
}
if(payload != NULL){
jsonPay = cJSON_GetObjectItem(payload, "params");
}
if (info_dcode != NULL && msgType != NULL && strcmp(msgType->valuestring, "/thing/topo/add")==0){
proCode = cJSON_GetObjectItem(jsonPay, "productCode");
devCode = cJSON_GetObjectItem(jsonPay, "deviceCode");
INFO_PRINT("productType productCode mac: [%s][%s] [%s] \n",proType->valuestring, proCode->valuestring, mac->valuestring);
kk_mid_subdev_add(KK_DM_DEVICE_SUBDEV, proType->valuestring,proCode->valuestring,devCode->valuestring, mac->valuestring);
mac = cJSON_GetObjectItem(jsonPay, "mac");
INFO_PRINT("deviceCode productCode mac: [%s][%s] [%s] \n",devCode->valuestring, proCode->valuestring, mac->valuestring);
kk_mid_subdev_add(KK_DM_DEVICE_SUBDEV,proCode->valuestring,devCode->valuestring, mac->valuestring,info_dcode->valuestring);
}else if (method != NULL && mac != NULL){
}else if (info_dcode != NULL && strcmp(msgType->valuestring, "/thing/event/property/post")==0){
INFO_PRINT("save property and send to cloud \n");
kk_tsl_property_set_byMac(mac->valuestring, data, strlen(data)+1);
kk_tsl_property_set_by_devicecode(info_dcode->valuestring, payload, strlen(payload)+1);
}else{
INFO_PRINT("kk_platMsg_handle data: don't handle it [%s]\n",data);
......@@ -311,7 +317,6 @@ void *udp_dispatch_yield(void *args){
cJSON* infoObj = NULL;
cJSON* payloadObj = NULL;
cJSON* msgtype = NULL;
cJSON* proType = NULL;
cJSON* proCode = NULL;
cJSON* devCode = NULL;
cJSON* params = NULL;
......@@ -357,11 +362,10 @@ void *udp_dispatch_yield(void *args){
continue;
}
proType = cJSON_GetObjectItem(infoObj, "productType");
proCode = cJSON_GetObjectItem(infoObj, "productCode");
devCode = cJSON_GetObjectItem(infoObj, "deviceCode");
params = cJSON_GetObjectItem(payloadObj, "params");
if (proType == NULL || proCode == NULL || devCode == NULL || params == NULL){
if (proCode == NULL || devCode == NULL || params == NULL){
ERROR_PRINT("productType productCode deviceCode params parameters are error \n");
cJSON_Delete(json);
continue;
......@@ -375,16 +379,16 @@ void *udp_dispatch_yield(void *args){
continue;
}
INFO_PRINT("productType productCode deviceCode mac: [%s][%s][%s][%s] \n",proType->valuestring, proCode->valuestring,
INFO_PRINT(" productCode deviceCode mac: [%s][%s][%s][%s] \n", proCode->valuestring,
devCode->valuestring, macstr->valuestring);
char device_code[DEVICE_CODE_LEN] = {0};
HAL_GetDevice_Code(device_code);
int res = kk_mid_subdev_add(KK_DM_DEVICE_GATEWAY,proType->valuestring, proCode->valuestring, devCode->valuestring, device_code);
int res = kk_mid_subdev_add(KK_DM_DEVICE_GATEWAY, proCode->valuestring, devCode->valuestring,macstr->valuestring, device_code);
if (res != SUCCESS_RETURN) {
WARNING_PRINT("kk_mid_gw_add error");
WARNING_PRINT("dm_mgr_gw_create error");
}
//kk_ipc_send(IPC_MID2APP, szDec, size);
kk_ipc_send(IPC_MID2APP, szDec, size);
memset(host_ip, 0, sizeof(host_ip));
memset(mac, 0, sizeof(mac));
......@@ -436,7 +440,7 @@ void *ccu_property_monitor(void *args)
int needReport = 0;
static int s_cloudStatus = 0;
int cloudState = 0;
int time_second = 10;
int time_second = 60;
static int alreadyRepord = 0;
while (mid_ctx->g_ccuProChg_dispatch_thread_running) {
//dm_ota_yield(MID_YIELD_TIMEOUT_MS);
......@@ -467,23 +471,10 @@ void *ccu_property_monitor(void *args)
needReport = 1;
}
}
if(alreadyRepord){
time_second = 60;
}
else{
time_second = 10;
}
if(needReport&&(cloudState == 1)){
//kk_tsl_post_property(0,NULL);
needReport = 0;
if(alreadyRepord == 0){
iotx_dm_dev_online(0);//first online,report the online status
time_second = 60;
}
else{
kk_tsl_post_property(0,NULL);
}
alreadyRepord = 1;
kk_tsl_post_property(0,NULL);
}
INFO_PRINT("time_second:%d,s_cloudStatus:%d\n",time_second,s_cloudStatus);
sleep(time_second);
......@@ -503,8 +494,11 @@ static int kk_set_product_info(void)
int main(const int argc, const char **argv)
{
int res = 0;
char *tsl_str;
int i;
kk_tsl_t *dev_shadow[30] = {NULL};
mid_ctx_t *mid_ctx = kk_mid_get_ctx();
kk_zlog_init("midware");
......@@ -513,6 +507,255 @@ int main(const int argc, const char **argv)
kk_set_product_info();
kk_tsl_api_init();
#if 0
tsl_str = kk_load_json("15", KK_DM_DEVICE_CCU);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("2", KK_DM_DEVICE_GATEWAY);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("11", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("24", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("83", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("84", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("85", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("89", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("90", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("91", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("96", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("97", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("98", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("102", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("103", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("104", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("105", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("106", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("1002", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("1003", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("1004", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("1007", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("1022", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
tsl_str = kk_load_json("2102", KK_DM_DEVICE_SUBDEV);
if(tsl_str != NULL)
{
res = kk_tsl_create(tsl_str,strlen(tsl_str),&dev_shadow[i]);
free(tsl_str);
if(res != 0){
return FAIL_RETURN;
}
}
i++;
#endif
#if 1
kk_ipc_init(IPC_MID2APP, mid_cb, NULL, NULL);
kk_ipc_init(IPC_MID2PLAT, mid2p_cb, NULL, "*");
......@@ -561,6 +804,7 @@ int main(const int argc, const char **argv)
}
int ct = 0;
#endif
for (;;) {
usleep(200000);
kk_platMsg_dispatch();
......
......@@ -1240,14 +1240,14 @@ int kk_msg_uri_parse_pkdn(_IN_ char *uri, _IN_ int uri_len, _IN_ int start_deli,
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_by_devicecode(const char deviceCode[DEVICE_CODE_MAXLEN], const char *payload, unsigned int payload_len)
{
kk_msg_request_payload_t request;
int res = 0, devid = 0;
memset(&request, 0, sizeof(kk_msg_request_payload_t));
res = dm_mgr_get_devId_by_mac(mac, &devid);
res = dm_mgr_get_devId_by_devicecode(deviceCode, &devid);
if(res != SUCCESS_RETURN){
return FAIL_RETURN;
}
......
......@@ -356,7 +356,7 @@ $(TARGET_FILE): $(APPLICATION_OBJECTS) $(LIBRARIES)
@echo -e '\n$@ build success'
else
$(TARGET_FILE): $(APPLICATION_OBJECTS) $(LIBRARIES)
$(LD) $^ $(LINKER_FLAGS) -lm -L. -static -lapi_com -static -lnanomsg -lanl -pthread -static -lev -ltinfo -o $(TARGET_FILE)
$(LD) $^ $(LINKER_FLAGS) -lm -L. -lapi_com -lnanomsg -lanl -pthread -lev -ltinfo -o $(TARGET_FILE)
@echo -e '\n$@ build success'
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