Commit 8bb38811 authored by chen.weican's avatar chen.weican

【修改内容】1,调整属性上报方式;2,相关代码优化

【提交人】陈伟灿
parent f4929f7d
......@@ -196,7 +196,7 @@ int dm_mgr_device_create(_IN_ int dev_type,_IN_ char productCode[PRODUCT_CODE_MA
memset(node, 0, sizeof(dm_mgr_dev_node_t));
if(dev_type == KK_DM_DEVICE_CCU)
node->devid = 0;
node->devid = KK_DM_DEVICE_CCU_DEVICEID;
else
node->devid = _dm_mgr_next_devid();
node->dev_type = dev_type;
......@@ -1302,7 +1302,10 @@ int dm_mgr_subdev_delete(_IN_ char deviceCode[DEVICE_CODE_MAXLEN])
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if(deviceCode == NULL || strlen(deviceCode) <=0){
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return FAIL_RETURN;
}
INFO_PRINT("dm_mgr_subdev_delete deviceCode:%s\n",deviceCode);
res = kk_subDev_delete_by_dcode(deviceCode);//delete sub db data
if (res != SUCCESS_RETURN) {
......
......@@ -16,6 +16,8 @@
#define KK_DM_GW_DEVICE_PRODUCT_TYPE "gw"
#define KK_DM_GW_DEVICE_PRODUCT_CODE "2"
#define KK_DM_DEVICE_CCU_DEVICEID (0x00)
typedef struct {
int devid;
int dev_type;
......
......@@ -765,6 +765,7 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
dm_mgr_dev_node_t *node = NULL;
kk_tsl_data_t *property = NULL;
cJSON *propertyItem = NULL;
char tmpValue[20] = {0};
if(params == NULL || deviceCode == NULL){
return FAIL_RETURN;
}
......@@ -773,6 +774,8 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
//printf("dm_msg_thing_property_post_by_identify:%s\n",params->valuestring);
nums = node->dev_shadow->property_number;
for(idx = 0; idx < nums; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
......@@ -781,9 +784,36 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
}
propertyItem = cJSON_GetObjectItem(params, property->identifier);
if(propertyItem != NULL){
kk_tsl_post_property(node->devid,property->identifier,0);
//kk_tsl_post_property(node->devid,property->identifier,0);
/*update the db data */
if(property->data_value.type == KK_TSL_DATA_TYPE_INT ||
property->data_value.type == KK_TSL_DATA_TYPE_ENUM||
property->data_value.type == KK_TSL_DATA_TYPE_BOOL){
sprintf(tmpValue,"%d",property->data_value.value_int);
kk_property_db_update_value(deviceCode,property->identifier,tmpValue);
}
else if(property->data_value.type == KK_TSL_DATA_TYPE_FLOAT){
sprintf(tmpValue,"%d",property->data_value.value_float);
kk_property_db_update_value(deviceCode,property->identifier,tmpValue);
}
else if(property->data_value.type == KK_TSL_DATA_TYPE_DOUBLE){
sprintf(tmpValue,"%d",property->data_value.value_double);
kk_property_db_update_value(deviceCode,property->identifier,tmpValue);
}
else if(property->data_value.type == KK_TSL_DATA_TYPE_TEXT||
property->data_value.type == KK_TSL_DATA_TYPE_DATE){
kk_property_db_update_value(deviceCode,property->identifier,property->data_value.value);
}
else{
ERROR_PRINT("Unkonwn Number Type");
}
}
}
char* outstr = cJSON_Print(params);
dm_mgr_upstream_thing_property_post(node->devid,outstr,strlen(outstr),0);
free(outstr);
return SUCCESS_RETURN;
}
......
......@@ -48,6 +48,9 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_THING_SERVICE_PROPERTY_SET "/thing/service/property/set"
#define KK_THING_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
#define KK_THING_CLOUDSTATE_MSG "/thing/ccu/cloudstate_reply"
#define KK_THING_TOPO_ADD_MSG "/thing/topo/add"
#define KK_THING_PROPERTY_POST "property/post"
#define KK_THING_TOPO_DELETE_MSG "/thing/topo/delete"
//const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/";
......
......@@ -317,9 +317,9 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
}
kk_property_db_update("CCU_66666");
if(s_CloudStatus){
iotx_dm_dev_online(0);//first online,report the online status
iotx_dm_dev_online(KK_DM_DEVICE_CCU_DEVICEID);//first online,report the online status
usleep(200000);
kk_tsl_post_property(0,NULL,0);
kk_tsl_post_property(KK_DM_DEVICE_CCU_DEVICEID,NULL,0);
}
}else if (strstr(typeJson->valuestring,KK_THING_OTA_DEVICE_UPGRADE)){
INFO_PRINT("ota upgrade... \n");
......
......@@ -272,7 +272,6 @@ int kk_property_db_get_rawdata(const char *identifier,const int dev_type, kk_pro
return SUCCESS_RETURN;
}
int kk_property_db_update(const char *deviceCode)
{
int res = 0;
......
......@@ -177,17 +177,17 @@ void kk_platMsg_handle(void* data, char* chalMark){
WARNING_PRINT("Error before: [%s]\n","cJSON_Parse");
}
else{
info = cJSON_GetObjectItem(json, "info");
payload = cJSON_GetObjectItem(json, "payload");
info = cJSON_GetObjectItem(json, MSG_INFO_STR);
payload = cJSON_GetObjectItem(json, MSG_PAYLOAD_STR);
if (info == NULL || payload == NULL){
ERROR_PRINT("info or payload params error\n");
goto error;
}
msgType = cJSON_GetObjectItem(info, "msgType");
info_dcode = cJSON_GetObjectItem(info, "deviceCode");
msgType = cJSON_GetObjectItem(info, MSG_TYPE_STR);
info_dcode = cJSON_GetObjectItem(info, MSG_DEVICE_CODE_STR);
jsonPay = cJSON_GetObjectItem(payload, "params");
jsonPay = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
if (msgType == NULL || info_dcode == NULL || jsonPay == NULL){
ERROR_PRINT("msgType info_dcode or jsonPay params are error\n");
......@@ -200,9 +200,9 @@ void kk_platMsg_handle(void* data, char* chalMark){
dm_mgr_update_timestamp_by_devicecode(info_dcode->valuestring,HAL_UptimeMs());
if (strcmp(msgType->valuestring, "/thing/topo/add")==0){
proCode = cJSON_GetObjectItem(jsonPay, "productCode");
devCode = cJSON_GetObjectItem(jsonPay, "deviceCode");
if (strcmp(msgType->valuestring, KK_THING_TOPO_ADD_MSG)==0){
proCode = cJSON_GetObjectItem(jsonPay, MSG_PRODUCT_CODE_STR);
devCode = cJSON_GetObjectItem(jsonPay, MSG_DEVICE_CODE_STR);
mac = cJSON_GetObjectItem(jsonPay, "mac");
if (proCode == NULL || devCode == NULL || mac == NULL){
ERROR_PRINT("productCode, deviceCode mac params are error\n");
......@@ -218,21 +218,19 @@ void kk_platMsg_handle(void* data, char* chalMark){
kk_mid_subdev_add(KK_DM_DEVICE_SUBDEV,proCode->valuestring,devCode->valuestring, mac->valuestring,info_dcode->valuestring);
}
}else if (strstr(msgType->valuestring, "property/post") != NULL){
}else if (strstr(msgType->valuestring, KK_THING_PROPERTY_POST) != NULL){
INFO_PRINT("save property and send to cloud \n");
char* outstr = cJSON_Print(payload);
kk_tsl_property_set_by_devicecode(info_dcode->valuestring, outstr, strlen(outstr)+1);
dm_msg_thing_property_post_by_identify(info_dcode->valuestring,jsonPay);
kk_property_db_update(info_dcode->valuestring);
free(outstr);
}else if(strstr(msgType->valuestring, "/thing/topo/delete") != NULL){
}else if(strstr(msgType->valuestring, KK_THING_TOPO_DELETE_MSG) != NULL){
INFO_PRINT("kk_platMsg_handle data: handle delete\n");
devCode = cJSON_GetObjectItem(jsonPay, "deviceCode");
devCode = cJSON_GetObjectItem(jsonPay, MSG_DEVICE_CODE_STR);
kk_ipc_send(IPC_MID2APP,data,strlen(data));
dm_mgr_subdev_delete(devCode->valuestring);
}else{
INFO_PRINT("kk_platMsg_handle data: don't handle it [%s]\n",data);
......@@ -603,7 +601,7 @@ void *ccu_property_monitor(void *args)
}
if(needReport&&(kk_get_cloudstatus() == 1)){
needReport = 0;
kk_tsl_post_property(0,NULL,0);
kk_tsl_post_property(KK_DM_DEVICE_CCU_DEVICEID,NULL,0);
}
sleep(time_second);
}
......
......@@ -1259,6 +1259,7 @@ int kk_tsl_property_set_by_devicecode(const char deviceCode[DEVICE_CODE_MAXLEN],
/* Operation */
res = _kk_msg_property_set(devid, &request);
/* Response */
//kk_tsl_post_property(devid,NULL);
......
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