Commit e1d805f0 authored by 黄振令's avatar 黄振令

【内容修改】数据库更新,接口参数更改

【提交人】huang.zhenling
parent 1699fe75
......@@ -269,7 +269,7 @@ void loop_thread(void *arg){
/*=================================
* for gateway, the "id" and "ip" is necessary
* chlMark: is unique, and suggest use gateway mac
* chlMark: is unique, and suggest use gateway deviceCode
* ip: ccu ip
* for the ccu, id and ip are null
*
......
......@@ -690,7 +690,7 @@ int dm_mgr_upstream_thing_topo_add(_IN_ int devid)
/* Get Params And Method */
res = dm_msg_thing_topo_add( node->productCode, node->deviceCode, &request);
res = dm_msg_thing_topo_add( node->productCode, node->deviceCode, node->mac,&request);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -1101,7 +1101,7 @@ int dm_mgr_subdev_create(int devtype,_IN_ char productCode[PRODUCT_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,productCode,deviceCode,fatherDeviceCode,mac, devid);
res = dm_mgr_device_create(devtype,productCode,deviceCode,mac,fatherDeviceCode, devid);
if(TSL_ALREADY_EXIST == res)
{
ERROR_PRINT("SUBDEV ALREADY EXIST!!!\n");
......
......@@ -92,7 +92,7 @@ const char DM_MSG_THING_TOPO_ADD_SIGN_SOURCE[] DM_READ_ONLY = "clientId%sdeviceC
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\"}]";
"{\"productCode\":\"%s\",\"deviceCode\":\"%s\",\"mac\":\"%s\"}";
int dm_msg_thing_topo_add(_IN_ char productCode[PRODUCT_CODE_MAXLEN],
_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _IN_ char mac[DEVICE_MAC_MAXLEN],
......@@ -116,6 +116,7 @@ int dm_msg_thing_topo_add(_IN_ char productCode[PRODUCT_CODE_MAXLEN],
return INVALID_PARAMETER;
}
#if 0
/* TimeStamp */
HAL_Snprintf(timestamp, DM_UTILS_UINT64_STRLEN, "%llu", (unsigned long long)HAL_UptimeMs());
/* dm_log_debug("Time Stamp: %s", timestamp); */
......@@ -133,6 +134,7 @@ int dm_msg_thing_topo_add(_IN_ char productCode[PRODUCT_CODE_MAXLEN],
memset(sign_source, 0, sign_source_len);
HAL_Snprintf(sign_source, sign_source_len, DM_MSG_THING_TOPO_ADD_SIGN_SOURCE, client_id,
deviceCode, timestamp);
/* dm_log_debug("Sign Srouce: %s", sign_source); */
#if 0
......@@ -151,11 +153,14 @@ int dm_msg_thing_topo_add(_IN_ char productCode[PRODUCT_CODE_MAXLEN],
#endif
free(sign_source);
/* dm_log_debug("Sign : %s", sign); */
#endif
/* Params */
request->method = (char *)DM_MSG_THING_TOPO_ADD_METHOD;
//params_len = strlen(DM_MSG_THING_TOPO_ADD_PARAMS) + strlen(deviceCode) +
// strlen(sign_method) + strlen(sign) + strlen(timestamp) + strlen(client_id) + 1;
params_len = strlen(DM_MSG_THING_TOPO_ADD_PARAMS) + strlen(deviceCode) +
strlen(sign_method) + strlen(sign) + strlen(timestamp) + strlen(client_id) + 1;
strlen(productCode) + strlen(mac) + strlen(client_id) + 1;
params = malloc(params_len);
if (params == NULL) {
......
......@@ -1038,12 +1038,14 @@ int _iotx_linkkit_slave_connect(int devid)
return FAIL_RETURN;
}
/* Subdev Register */
res = kk_dm_subdev_register(devid);
/*res = kk_dm_subdev_register(devid);
if (res < SUCCESS_RETURN) {
return FAIL_RETURN;
}
}*/
#if 0
if (res > SUCCESS_RETURN) {
semaphore = HAL_SemaphoreCreate();
if (semaphore == NULL) {
......@@ -1078,6 +1080,7 @@ int _iotx_linkkit_slave_connect(int devid)
_iotx_linkkit_upstream_mutex_unlock();
}
#endif
/* Subdev Add Topo */
res = kk_dm_subdev_topo_add(devid);
......@@ -1085,6 +1088,8 @@ int _iotx_linkkit_slave_connect(int devid)
_iotx_linkkit_mutex_unlock();
return FAIL_RETURN;
}
#if 0
semaphore = HAL_SemaphoreCreate();
if (semaphore == NULL) {
_iotx_linkkit_mutex_unlock();
......@@ -1117,6 +1122,7 @@ int _iotx_linkkit_slave_connect(int devid)
return FAIL_RETURN;
}
_iotx_linkkit_upstream_mutex_unlock();
#endif
return SUCCESS_RETURN;
}
......@@ -1339,11 +1345,12 @@ 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;
}
#ifdef MSG_NEED_RESP
msgid = res;
semaphore = HAL_SemaphoreCreate();
if (semaphore == NULL) {
......@@ -1375,7 +1382,7 @@ static int _iotx_linkkit_subdev_login(int devid)
return FAIL_RETURN;
}
_iotx_linkkit_upstream_mutex_unlock();
#endif
res = iotx_dm_subscribe(devid);
if (res != SUCCESS_RETURN) {
......@@ -1677,16 +1684,21 @@ int kk_mid_subdev_add(int devType, char productCode[PRODUCT_CODE_MAXLEN], char d
int devid = 0;
res = dm_mgr_subdev_create(devType,productCode,deviceCode,mac,fatherDeviceCode,&devid);
if (res != SUCCESS_RETURN) {
if (res != SUCCESS_RETURN && TSL_ALREADY_EXIST != res) {
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,fatherDeviceCode,mac,"1.1.0");
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
if (TSL_ALREADY_EXIST == res){
//todo
}else{
res = kk_subDev_insert_db(devType,productCode,deviceCode,fatherDeviceCode,mac,"1.1.0");
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
}
_iotx_linkkit_mutex_lock();
res = _iotx_linkkit_slave_connect(devid);
if (res != SUCCESS_RETURN) {
......
......@@ -173,9 +173,9 @@ 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 fatherDeviceCode[DEVICE_CODE_MAXLEN],char version[DEVICE_VERSION_MAXLEN])
char deviceCode[DEVICE_CODE_MAXLEN],char fatherDeviceCode[DEVICE_CODE_MAXLEN],char mac[DEVICE_MAC_MAXLEN],char version[DEVICE_VERSION_MAXLEN])
{
const char *insertCmd = "insert into SubDeviceInfo (idx,isOnline,productCode,deviceCode,mac,fatherMac,version,isAuth,devType) \
const char *insertCmd = "insert into SubDeviceInfo (idx,isOnline,productCode,deviceCode,mac,fatherDeviceCode,version,isAuth,devType) \
values ('%d','%d', '%s','%s','%s','%s','%s','%d','%d');";
char *sqlCmd = NULL;
int rc = 0;
......@@ -189,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,fatherDeviceCode,version,0,devType);
sqlCmd = sqlite3_mprintf(insertCmd,ctx->subDevNum,0,productCode,deviceCode,mac,fatherDeviceCode,version,0,devType);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){
......
......@@ -4,7 +4,7 @@
int kk_subDb_init(void);
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 fatherMac[DEVICE_MAC_MAXLEN],char mac[DEVICE_MAC_MAXLEN], char version[DEVICE_VERSION_MAXLEN]);
int kk_subDev_delete_byMac(char device_mac[DEVICE_MAC_MAXLEN]);
......
......@@ -170,9 +170,11 @@ void kk_platMsg_handle(void* data, char* chalMark){
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 (info_dcode != NULL && strcmp(msgType->valuestring, "/thing/event/property/post")==0){
}else if (info_dcode != NULL && strstr(msgType->valuestring, "property/post") != NULL){
INFO_PRINT("save property and send to cloud \n");
kk_tsl_property_set_by_devicecode(info_dcode->valuestring, payload, strlen(payload)+1);
char* outstr = cJSON_Print(payload);
kk_tsl_property_set_by_devicecode(info_dcode->valuestring, outstr, strlen(outstr)+1);
free(outstr);
}else{
INFO_PRINT("kk_platMsg_handle data: don't handle it [%s]\n",data);
......@@ -379,7 +381,7 @@ void *udp_dispatch_yield(void *args){
continue;
}
INFO_PRINT(" productCode deviceCode mac: [%s][%s][%s][%s] \n", proCode->valuestring,
INFO_PRINT(" productCode deviceCode mac: [%s][%s][%s] \n", proCode->valuestring,
devCode->valuestring, macstr->valuestring);
char device_code[DEVICE_CODE_LEN] = {0};
HAL_GetDevice_Code(device_code);
......@@ -388,7 +390,7 @@ void *udp_dispatch_yield(void *args){
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));
......@@ -803,14 +805,32 @@ int main(const int argc, const char **argv)
return -1;
}
#endif
int ct = 0;
#endif
for (;;) {
usleep(200000);
kk_platMsg_dispatch();
/*if (ct == 0){
ct =1;
void* buf = "{ \"msgId\": \"7\", \"version\": \"1.0\", \"mac\": \"588E81FFFED3834A\", \"method\": \"thing.topo.add\", \"params\": { \"AppVersion\": \"10\", \"deviceCode\": \"588E81FFFED3834A\", \"productType\": \"curtain\", \"productCode\": \"24\" }}";
void* buf = "{\
\"info\": {\
\"msgtype\": \"/thing/topo/add\",\
\"productType\": \"gw\",\
\"productCode\": \"2\",\
\"deviceCode\": \"1122334455667788\"\
},\
\"payload\": {\
\"msgId\": \"1\",\
\"version\": \"1.0\",\
\"params\": {\
\"deviceCode\": \"588E81FFFED3834A\",\
\"productCode\": \"24\",\
\"mac\": \"588E81FFFED3834A\"\
}\
}\
}";
kk_platMsg_handle(buf, "1122334455667788");
//kk_set_tsl_by_productKey("a1OYuSallan","model.json");
//kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq","","aabbccddeeff1122");
......
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