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

【修改内容】1,epNum适配处理

【提交人】陈伟灿
parent f6d14e16
......@@ -83,7 +83,7 @@ static int _dm_mgr_search_dev_by_pkdn(_IN_ char deviceCode[DEVICE_CODE_MAXLEN],
}
}
ERROR_PRINT("Device Not Found, Device Code: %s", deviceCode);
ERROR_PRINT("Device Not Found, Device Code: %s\n", deviceCode);
return FAIL_RETURN;
}
static int _dm_mgr_next_devid(void)
......@@ -92,7 +92,7 @@ static int _dm_mgr_next_devid(void)
return ctx->global_devid++;
}
static int _dm_init_tsl_params(kk_tsl_t * dev_shadow)
static int _dm_init_tsl_params(kk_tsl_t * dev_shadow,char *deviceCode)
{
int res = 0;
char version[VERSION_MAXLEN] = {0};
......@@ -150,6 +150,21 @@ static int _dm_init_tsl_params(kk_tsl_t * dev_shadow)
{
ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
}
char currentValue[16] = {0};
kk_property_db_get_value(deviceCode,KK_TSL_CCU_ARMINGSTATE_IDENTIFIER,currentValue);
if(strlen(currentValue) == 0){
res = kk_tsl_set_value(kk_tsl_set_property_value,dev_shadow,KK_TSL_CCU_ARMINGSTATE_IDENTIFIER,NULL,"1");//默认撤防设置
if(res != SUCCESS_RETURN)
{
ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
}
}else{
res = kk_tsl_set_value(kk_tsl_set_property_value,dev_shadow,KK_TSL_CCU_ARMINGSTATE_IDENTIFIER,NULL,currentValue);//默认撤防设置
if(res != SUCCESS_RETURN)
{
ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
}
}
return res;
}
......@@ -282,7 +297,7 @@ int dm_mgr_device_create(_IN_ int dev_type,_IN_ char productCode[PRODUCT_CODE_MA
list_add_tail(&node->linked_list, &ctx->dev_list);
if(dev_type == KK_DM_DEVICE_CCU){
_dm_init_tsl_params(node->dev_shadow);
_dm_init_tsl_params(node->dev_shadow,node->deviceCode);
}
if (devid) {
......
......@@ -41,6 +41,23 @@ typedef struct {
struct list_head dev_list;
} dm_mgr_ctx;
typedef struct kk_dm_property_handle
{
char property[DEVICE_PROPERTY_NAME_MAX];
union{
char *valueStr;
double value;
};
int type;
}kk_dm_property_handle_t;
typedef struct kk_dm_property_e
{
kk_dm_property_handle_t info[DEVICE_PROPERTY_NUM_MAX];
int num;
}kk_dm_property_e_t;
typedef struct {
char msgid[MSG_MAX_LEN];
int devid;
......
......@@ -911,16 +911,40 @@ int dm_msg_ccu_property_post(dm_mgr_dev_node_t *node)
}
return SUCCESS_RETURN;
}
static void kk_split(char *src,const char *separator,char **dest,int *num) {
char *pNext;
int count = 0;
if (src == NULL || strlen(src) == 0)
return;
if (separator == NULL || strlen(separator) == 0)
return;
pNext = strtok(src,separator);
while(pNext != NULL) {
*dest++ = pNext;
++count;
pNext = strtok(NULL,separator);
}
*num = count;
}
int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
{
int res = 0;
int nums = 0;
int idx = 0;
int i = 0;
dm_mgr_dev_node_t *node = NULL;
kk_tsl_data_t *property = NULL;
cJSON *propertyItem = NULL;
char tmpValue[20] = {0};
kk_dm_property_e_t propertyInfoBuf[DEVICE_PROPERTY_NUM_MAX];
char propertiesTmp[DEVICE_PROPERTY_NAME_MAX] = {0};
char pFinal[DEVICE_PROPERTY_NAME_MAX] = {0};
int num = 0;
int countPro = 0;
int epNumInt = 1;
int maxEpNum = 1;
if(params == NULL || deviceCode == NULL){
return INVALID_PARAMETER;
}
......@@ -930,13 +954,37 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
return FAIL_RETURN;
}
//printf("dm_msg_thing_property_post_by_identify:%s\n",params->valuestring);
memset(propertyInfoBuf,0x0,sizeof(kk_dm_property_e_t)*16);
nums = node->dev_shadow->property_number;
for(idx = 0; idx < nums; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL){
continue;
}
memset(propertiesTmp,0x0,sizeof(propertiesTmp));
memset(pFinal,0x0,sizeof(pFinal));
memcpy(propertiesTmp,property->identifier,strlen(property->identifier));
//printf("---------------------------------->propertiesTmp:%s\n",propertiesTmp);
if(strstr(propertiesTmp,"_") != NULL){
char *propertiesbuf[DEVICE_PROPERTY_NAME_MAX] = {0};
kk_split(propertiesTmp,"_",propertiesbuf,&num);
if(num == 2){
epNumInt = atoi(propertiesbuf[1]);
}
if(epNumInt < 1 || epNumInt >= 16){
epNumInt = 1;
}
memcpy(pFinal,propertiesbuf[0],strlen(propertiesbuf[0]));
//printf("---------------------------------------->pFinal:%s,num:%d\n",pFinal,epNumInt);
}else{
//printf("---------------------------------->property->identifier:%s\n",property->identifier);
memcpy(pFinal,property->identifier,strlen(property->identifier));
//memset(propertiesbuf[0],0x0,sizeof(propertiesbuf[0]));
//memcpy(propertiesbuf[0],property->identifier,strlen(property->identifier));
//printf("propertiesbuf[0]:%s,num:%d\n",propertiesbuf[0],num);
epNumInt = 1;
}
propertyItem = cJSON_GetObjectItem(params, property->identifier);
if(propertyItem != NULL){
......@@ -946,19 +994,43 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
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);
propertyInfoBuf[epNumInt-1].num++;
countPro = propertyInfoBuf[epNumInt-1].num;
propertyInfoBuf[epNumInt-1].info[countPro-1].type = property->data_value.type;
memset(propertyInfoBuf[epNumInt-1].info[countPro-1].property,0x0,sizeof(propertyInfoBuf[epNumInt-1].info[countPro-1].property));
memcpy(propertyInfoBuf[epNumInt-1].info[countPro-1].property,pFinal,strlen(pFinal));
propertyInfoBuf[epNumInt-1].info[countPro-1].value = property->data_value.value_int;
}
else if(property->data_value.type == KK_TSL_DATA_TYPE_FLOAT){
sprintf(tmpValue,"%f",property->data_value.value_float);
kk_property_db_update_value(deviceCode,property->identifier,tmpValue);
propertyInfoBuf[epNumInt-1].num++;
countPro = propertyInfoBuf[epNumInt-1].num;
propertyInfoBuf[epNumInt-1].info[countPro-1].type = property->data_value.type;
memset(propertyInfoBuf[epNumInt-1].info[countPro-1].property,0x0,sizeof(propertyInfoBuf[epNumInt-1].info[countPro-1].property));
memcpy(propertyInfoBuf[epNumInt-1].info[countPro-1].property,pFinal,strlen(pFinal));
propertyInfoBuf[epNumInt-1].info[countPro-1].value = property->data_value.value_float;
}
else if(property->data_value.type == KK_TSL_DATA_TYPE_DOUBLE){
sprintf(tmpValue,"%f",property->data_value.value_double);
kk_property_db_update_value(deviceCode,property->identifier,tmpValue);
propertyInfoBuf[epNumInt-1].num++;
countPro = propertyInfoBuf[epNumInt-1].num;
propertyInfoBuf[epNumInt-1].info[countPro-1].type = property->data_value.type;
memset(propertyInfoBuf[epNumInt-1].info[countPro-1].property,0x0,sizeof(propertyInfoBuf[epNumInt-1].info[countPro-1].property));
memcpy(propertyInfoBuf[epNumInt-1].info[countPro-1].property,pFinal,strlen(pFinal));
propertyInfoBuf[epNumInt-1].info[countPro-1].value = property->data_value.value_double;
}
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);
propertyInfoBuf[epNumInt-1].num++;
countPro = propertyInfoBuf[epNumInt-1].num;
propertyInfoBuf[epNumInt-1].info[countPro-1].type = property->data_value.type;
memset(propertyInfoBuf[epNumInt-1].info[countPro-1].property,0x0,sizeof(propertyInfoBuf[epNumInt-1].info[countPro-1].property));
memcpy(propertyInfoBuf[epNumInt-1].info[countPro-1].property,pFinal,strlen(pFinal));
propertyInfoBuf[epNumInt-1].info[countPro-1].valueStr = property->data_value.value;
}
else if(property->data_value.type == KK_TSL_DATA_TYPE_STRUCT){
kk_tsl_data_value_complex_t *complex_struct = NULL;
......@@ -991,6 +1063,7 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
current_data->data_value.type == KK_TSL_DATA_TYPE_DATE){
kk_property_db_update_value(deviceCode,tmp_identifiers,current_data->data_value.value);
}
#if 0
else if(current_data->data_value.type == KK_TSL_DATA_TYPE_STRUCT){
kk_tsl_data_value_complex_t *complex_struct_1 = NULL;
complex_struct_1 = current_data->data_value.value;
......@@ -1029,6 +1102,7 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
}
}
#endif
else{
ERROR_PRINT("Unsupport Type\n");
}
......@@ -1039,11 +1113,33 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
else{
ERROR_PRINT("Unkonwn Number Type");
}
//cJSON_DeleteItemFromObject(params,property->identifier);
}
}
char* outstr = cJSON_Print(params);
dm_mgr_upstream_thing_property_post(node->devid,outstr,strlen(outstr),0);
free(outstr);
int epIdx[4] = {0};
for(idx = 0; idx < epNumInt; idx++){
countPro = propertyInfoBuf[idx].num;
memset(epIdx,0x0,sizeof(epIdx));
sprintf(epIdx,"%d",idx+1);
cJSON * rootData=cJSON_CreateObject();
cJSON_AddStringToObject(rootData,"epNum", epIdx);
for(i = 0; i < countPro; i++){
int vtype = propertyInfoBuf[idx].info[i].type;
if(vtype == KK_TSL_DATA_TYPE_INT || vtype == KK_TSL_DATA_TYPE_ENUM \
||vtype == KK_TSL_DATA_TYPE_BOOL || vtype == KK_TSL_DATA_TYPE_FLOAT \
||vtype == KK_TSL_DATA_TYPE_DOUBLE)
{
cJSON_AddNumberToObject(rootData,propertyInfoBuf[idx].info[i].property, propertyInfoBuf[idx].info[i].value);
}else if(vtype == KK_TSL_DATA_TYPE_TEXT || vtype == KK_TSL_DATA_TYPE_DATE){
cJSON_AddStringToObject(rootData,propertyInfoBuf[idx].info[i].property, propertyInfoBuf[idx].info[i].valueStr);
}
}
char* outstr = cJSON_Print(rootData);
dm_mgr_upstream_thing_property_post(node->devid,outstr,strlen(outstr),0);
free(outstr);
cJSON_Delete(rootData);
}
return SUCCESS_RETURN;
}
......
......@@ -929,7 +929,20 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
_iotx_linkkit_upstream_mutex_unlock();
}else if (strstr(typeJson->valuestring,KK_THING_SERVICE_PROPERTY_SET)){
INFO_PRINT("property set \n");
dm_msg_thing_property_set_reply(deviceCode->valuestring,payload_Str, strlen(payload_Str), NULL);
dm_mgr_dev_node_t *node = NULL;
cJSON *paramStr = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
cJSON *state = cJSON_GetObjectItem(paramStr, KK_TSL_CCU_ARMINGSTATE_IDENTIFIER);
if(state != NULL){
dm_mgr_search_dev_by_devid(KK_DM_DEVICE_CCU_DEVICEID,&node);
res = kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,KK_TSL_CCU_ARMINGSTATE_IDENTIFIER,NULL,state->valuestring);
if(res != SUCCESS_RETURN)
{
ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
}
kk_property_db_update(KK_CCU_ID);
//dm_msg_thing_property_set_reply(deviceCode->valuestring,payload_Str, strlen(payload_Str), NULL);
dm_msg_ccu_property_post(node);
}
}else if (strstr(typeJson->valuestring,KK_THING_CLOUDSTATE_MSG)){
INFO_PRINT("cloud state notify \n");
s_CloudStatusRecv = 1;
......
......@@ -113,12 +113,12 @@ int kk_history_db_init(void)
/************************************************************
*功能描述:删除历史数据
*输入参数:time:记录时间
*输入参数:itime:记录时间
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
int kk_history_delete_by_recordtime(const char *table,time_t time)
int kk_history_delete_by_recordtime(const char *table,time_t itime)
{
const char *deleteCmd = "delete from '%s' where recordtime = '%d';";
char *sqlCmd = NULL;
......@@ -126,7 +126,7 @@ int kk_history_delete_by_recordtime(const char *table,time_t time)
char *zErrMsg = 0;
kk_history_ctx_t *ctx = _kk_history_get_ctx();
sqlCmd = sqlite3_mprintf(deleteCmd,table,time);
sqlCmd = sqlite3_mprintf(deleteCmd,table,itime);
INFO_PRINT("Table delete data sqlCmd:%s\n",sqlCmd);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){
......@@ -179,7 +179,7 @@ err1:
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int kk_history_insert_sensor_info(const char* deviceCode,const char* identifier,const char* valueStr,time_t time)
int kk_history_insert_sensor_info(const char* deviceCode,const char* identifier,const char* valueStr,time_t itime)
{
int res = 0;
kk_history_ctx_t *ctx = _kk_history_get_ctx();
......@@ -194,7 +194,7 @@ int kk_history_insert_sensor_info(const char* deviceCode,const char* identifier,
INFO_PRINT("kk_history_insert_sensor_info,deviceCode:%s,identifier:%s,value:%s\n",deviceCode,identifier,valueStr);
_kk_history_lock();
sqlCmd = sqlite3_mprintf(insertCmd,deviceCode,identifier,valueStr,time);
sqlCmd = sqlite3_mprintf(insertCmd,deviceCode,identifier,valueStr,itime);
res = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( res != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
......@@ -235,7 +235,7 @@ int kk_history_insert_sensor_info(const char* deviceCode,const char* identifier,
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int kk_history_insert_Outlet_info(const char* deviceCode,const char* power,const char* metering,time_t time)
int kk_history_insert_Outlet_info(const char* deviceCode,const char* power,const char* metering,time_t itime)
{
int res = 0;
kk_history_ctx_t *ctx = _kk_history_get_ctx();
......@@ -250,7 +250,7 @@ int kk_history_insert_Outlet_info(const char* deviceCode,const char* power,const
INFO_PRINT("kk_history_insert_Outlet_info,deviceCode:%s,power:%s,metering:%s\n",deviceCode,power,metering);
_kk_history_lock();
sqlCmd = sqlite3_mprintf(insertCmd,deviceCode,power,metering,time);
sqlCmd = sqlite3_mprintf(insertCmd,deviceCode,power,metering,itime);
res = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( res != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
......
......@@ -15,8 +15,8 @@ enum{
DB_OUTLET_RECORDTIME,
};
int kk_history_db_init(void);
int kk_history_delete_by_recordtime(const char *table,time_t time);
int kk_history_insert_sensor_info(const char* deviceCode,const char* identifier,const char* valueStr,time_t time);
int kk_history_insert_Outlet_info(const char* deviceCode,const char* power,const char* metering,time_t time);
int kk_history_delete_by_recordtime(const char *table,time_t itime);
int kk_history_insert_sensor_info(const char* deviceCode,const char* identifier,const char* valueStr,time_t itime);
int kk_history_insert_Outlet_info(const char* deviceCode,const char* power,const char* metering,time_t itime);
#endif
This diff is collapsed.
......@@ -619,7 +619,7 @@ int kk_scene_parse_scene_trigger(const cJSON* str,const char *sceneId)
cJSON *items, *item;
cJSON *type;
cJSON *week;
cJSON *time;
cJSON *timestr;
int res = 0;
int weekflag = 0;
if(str == NULL || sceneId == NULL){
......@@ -645,10 +645,10 @@ int kk_scene_parse_scene_trigger(const cJSON* str,const char *sceneId)
week = cJSON_GetObjectItem(item,MSG_SCENE_WEEK);
if(week == NULL) return FAIL_RETURN;
weekflag = kk_scene_parse_repeatday(week);
time = cJSON_GetObjectItem(item,MSG_SCENE_TIME);
if(time == NULL) return FAIL_RETURN;
timestr = cJSON_GetObjectItem(item,MSG_SCENE_TIME);
if(timestr == NULL) return FAIL_RETURN;
time_t current = HAL_GetTime();
time_t newStart = kk_scene_creat_timer_starttime(weekflag,atoi(time->valuestring),current);
time_t newStart = kk_scene_creat_timer_starttime(weekflag,atoi(timestr->valuestring),current);
kk_scene_insert_scene_timer(newStart,weekflag,sceneId);
kk_scene_push_timer_info(newStart,weekflag,(char*)sceneId);
}
......
......@@ -27,7 +27,7 @@
#define DM_UTILS_UINT64_STRLEN (20)
#define DEVICE_PROPERTY_NAME_MAX (64+1)
#define DEVICE_PROPERTY_VALUE_MAX (64+1)
#define DEVICE_PROPERTY_NUM_MAX (16)
#define KK_TSL_KEY_SCHEMA "schema"
#define KK_TSL_KEY_LINK "link"
......@@ -77,6 +77,7 @@
#define KK_TSL_CCU_WANIP_IDENTIFIER "WanIPAddress"
#define KK_TSL_CCU_WANSTATE_IDENTIFIER "WanState"
#define KK_TSL_CCU_IOTCLOUD_IDENTIFIER "IOTCloudState"
#define KK_TSL_CCU_ARMINGSTATE_IDENTIFIER "ArmingState"
#define KK_TSL_GATAWAY_VERSION_IDENTIFIER "Version"
#define KK_TSL_GATAWAY_IP_IDENTIFIER "IPAddress"
......
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