Commit 19e63444 authored by 黄振令's avatar 黄振令

【修改内容】设备加入后,发送/topo/add和/status/online 服务器交互命令

【修改人】huang.zhenling
parent 17c5ff55
......@@ -728,7 +728,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 *gw_node = NULL;
dm_mgr_dev_node_t *father_node = NULL;
dm_msg_request_t request;
if (devid < 0) {
......@@ -741,7 +741,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,&gw_node);
res = dm_mgr_get_device_by_mac(node->fatherMac,&father_node);
if (res != SUCCESS_RETURN) {
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
......@@ -750,13 +750,13 @@ 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,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));
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));
/* Get Params And Method */
res = dm_msg_thing_topo_add(node->productType, node->productCode, node->deviceCode, &request);
res = dm_msg_thing_topo_add(node->productType, node->productCode, node->deviceCode,node->deviceCode, &request);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -1172,11 +1172,11 @@ int dm_mgr_ota_report_version(_IN_ int devid, char *version)
int dm_mgr_subdev_create(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
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 res = 0;
res = dm_mgr_device_create(KK_DM_DEVICE_SUBDEV,productType,productCode,deviceCode,fatherMac, devid);
res = dm_mgr_device_create(devtype,productType,productCode,deviceCode,fatherMac, devid);
if(TSL_ALREADY_EXIST == res)
{
ERROR_PRINT("SUBDEV ALREADY EXIST!!!\n");
......@@ -1184,15 +1184,3 @@ int dm_mgr_subdev_create(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
return res;
}
int dm_mgr_gw_create(_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 res = 0;
res = dm_mgr_device_create(KK_DM_DEVICE_GATEWAY,productType,productCode,deviceCode,fatherMac, devid);
if(TSL_ALREADY_EXIST == res)
{
ERROR_PRINT("GATEWAY ALREADY EXIST!!!\n");
}
return res;
}
......@@ -98,10 +98,13 @@ int dm_msg_thing_sub_unregister(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
const char DM_MSG_THING_TOPO_ADD_SIGN_SOURCE[] DM_READ_ONLY = "clientId%sdeviceName%sproductKey%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\"}]";
//"[{\"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],
_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_msg_request_t *request)
_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _IN_ char mac[DEVICE_MAC_MAXLEN],
_OU_ dm_msg_request_t *request)
{
char *params = NULL;
int params_len = 0;
......@@ -169,8 +172,9 @@ int dm_msg_thing_topo_add(_IN_ char productType[PRODUCT_TYPE_MAXLEN],
return MEMORY_NOT_ENOUGH;
}
memset(params, 0, params_len);
HAL_Snprintf(params, params_len, DM_MSG_THING_TOPO_ADD_PARAMS, productType, deviceCode,
sign_method, sign, timestamp, client_id);
//HAL_Snprintf(params, params_len, DM_MSG_THING_TOPO_ADD_PARAMS, productType, deviceCode,
// sign_method, sign, timestamp, client_id);
HAL_Snprintf(params, params_len, DM_MSG_THING_TOPO_ADD_PARAMS, productCode, deviceCode,mac);
request->params = params;
request->params_len = strlen(request->params);
......
......@@ -44,6 +44,7 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_REGISTER_TOPIC_REPLY "/thing/sub/register_reply"
#define KK_ADD_TOPIC_REPLY "/thing/topo/add_reply"
#define KK_LOGIN_TOPIC_REPLY "/thing/combine/login_reply"
#define KK_ONLINE_TOPIC_REPLY "/thing/status/online_reply"
#define KK_THING_SERVICE_PROPERTY_SET "/thing/service/property/set"
#define KK_THING_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
#define KK_THING_CLOUDSTATE_MSG "/thing/ccu/cloudstate"
......
......@@ -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->valuestring)+1, &response);
res = dm_msg_response_parse((char *)payload_Str, strlen(payload_Str)+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->valuestring)+1, &response);
res = dm_msg_response_parse((char *)payload_Str, strlen(payload_Str)+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)){
}else if (strstr(typeJson->valuestring,KK_LOGIN_TOPIC_REPLY) || strstr(typeJson->valuestring,KK_ONLINE_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->valuestring)+1, &response);
res = dm_msg_response_parse((char *)payload_Str, strlen(payload_Str)+1, &response);
if (res != SUCCESS_RETURN) {
goto directReturn;
}
......@@ -1035,6 +1035,7 @@ int _iotx_linkkit_slave_connect(int devid)
return FAIL_RETURN;
}
#if 0
/* Subdev Register */
res = kk_dm_subdev_register(devid);
if (res < SUCCESS_RETURN) {
......@@ -1075,6 +1076,8 @@ int _iotx_linkkit_slave_connect(int devid)
_iotx_linkkit_upstream_mutex_unlock();
}
#endif
/* Subdev Add Topo */
res = kk_dm_subdev_topo_add(devid);
......@@ -1336,7 +1339,7 @@ static int _iotx_linkkit_subdev_login(int devid)
void *semaphore = NULL;
void *callback = NULL;
res = iotx_dm_subdev_login(devid);
res = iotx_dm_dev_online(devid);//iotx_dm_subdev_login(devid);
if (res < SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -1669,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(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 productType[PRODUCT_TYPE_MAXLEN], char productCode[PRODUCT_CODE_MAXLEN], char deviceCode[DEVICE_CODE_MAXLEN],char fatherMac[DEVICE_MAC_MAXLEN]){
int res = 0;
int devid = 0;
res = dm_mgr_subdev_create(productType,productCode,deviceCode,fatherMac,&devid);
res = dm_mgr_subdev_create(devType, productType,productCode,deviceCode,fatherMac,&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(KK_DM_DEVICE_SUBDEV,productCode,deviceCode,fatherMac,"1.1.0");
res = kk_subDev_insert_db(devType,productCode,deviceCode,fatherMac,"1.1.0");
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -1700,4 +1703,3 @@ int kk_mid_subdev_add(char productType[PRODUCT_TYPE_MAXLEN], char productCode[PR
return SUCCESS_RETURN;
}
......@@ -90,7 +90,7 @@ 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_text(stmt, 2),sqlite3_column_text(stmt, 3),
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);
if(res != SUCCESS_RETURN){
......@@ -100,6 +100,9 @@ static int _kk_load_subDevice(void)
ctx->subDevNum++;
}
usleep(100000);
//如果为认证,需要认证
//再上线
iotx_dm_subscribe(devId);
kk_dm_ota_report_version(devId,sqlite3_column_text(stmt, 5));//version
//usleep(100000);
......
......@@ -28,6 +28,7 @@ char * g_filerToPlatTable[] =
{KK_LOGIN_TOPIC_REPLY},
{KK_THING_OTA_DEVICE_UPGRADE},
{KK_THING_CLOUDSTATE_MSG},
{KK_ONLINE_TOPIC_REPLY},
};
static int _kk_filter_to_plat(const char* msgtype)
......@@ -161,7 +162,7 @@ void kk_platMsg_handle(void* data, char* chalMark){
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(proType->valuestring,proCode->valuestring,devCode->valuestring, mac->valuestring);
kk_mid_subdev_add(KK_DM_DEVICE_SUBDEV, proType->valuestring,proCode->valuestring,devCode->valuestring, mac->valuestring);
}else if (method != NULL && mac != NULL){
INFO_PRINT("save property and send to cloud \n");
......@@ -376,12 +377,14 @@ void *udp_dispatch_yield(void *args){
INFO_PRINT("productType productCode deviceCode mac: [%s][%s][%s][%s] \n",proType->valuestring, proCode->valuestring,
devCode->valuestring, macstr->valuestring);
int res = dm_mgr_gw_create(proType->valuestring,proCode->valuestring,devCode->valuestring,macstr->valuestring,&devId);
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);
if (res != SUCCESS_RETURN) {
WARNING_PRINT("dm_mgr_gw_create error");
WARNING_PRINT("kk_mid_gw_add 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));
......
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