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], ...@@ -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; return FAIL_RETURN;
} }
static int _dm_mgr_next_devid(void) static int _dm_mgr_next_devid(void)
...@@ -92,7 +92,7 @@ static int _dm_mgr_next_devid(void) ...@@ -92,7 +92,7 @@ static int _dm_mgr_next_devid(void)
return ctx->global_devid++; 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; int res = 0;
char version[VERSION_MAXLEN] = {0}; char version[VERSION_MAXLEN] = {0};
...@@ -150,6 +150,21 @@ static int _dm_init_tsl_params(kk_tsl_t * dev_shadow) ...@@ -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); 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; return res;
} }
...@@ -282,7 +297,7 @@ int dm_mgr_device_create(_IN_ int dev_type,_IN_ char productCode[PRODUCT_CODE_MA ...@@ -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); list_add_tail(&node->linked_list, &ctx->dev_list);
if(dev_type == KK_DM_DEVICE_CCU){ 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) { if (devid) {
......
...@@ -41,6 +41,23 @@ typedef struct { ...@@ -41,6 +41,23 @@ typedef struct {
struct list_head dev_list; struct list_head dev_list;
} dm_mgr_ctx; } 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 { typedef struct {
char msgid[MSG_MAX_LEN]; char msgid[MSG_MAX_LEN];
int devid; int devid;
......
...@@ -911,16 +911,40 @@ int dm_msg_ccu_property_post(dm_mgr_dev_node_t *node) ...@@ -911,16 +911,40 @@ int dm_msg_ccu_property_post(dm_mgr_dev_node_t *node)
} }
return SUCCESS_RETURN; 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 dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
{ {
int res = 0; int res = 0;
int nums = 0; int nums = 0;
int idx = 0; int idx = 0;
int i = 0;
dm_mgr_dev_node_t *node = NULL; dm_mgr_dev_node_t *node = NULL;
kk_tsl_data_t *property = NULL; kk_tsl_data_t *property = NULL;
cJSON *propertyItem = NULL; cJSON *propertyItem = NULL;
char tmpValue[20] = {0}; 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){ if(params == NULL || deviceCode == NULL){
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
...@@ -930,13 +954,37 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params) ...@@ -930,13 +954,37 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
return FAIL_RETURN; return FAIL_RETURN;
} }
//printf("dm_msg_thing_property_post_by_identify:%s\n",params->valuestring); //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; nums = node->dev_shadow->property_number;
for(idx = 0; idx < nums; idx++){ for(idx = 0; idx < nums; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx); property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL){ if(property == NULL){
continue; 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); propertyItem = cJSON_GetObjectItem(params, property->identifier);
if(propertyItem != NULL){ if(propertyItem != NULL){
...@@ -946,19 +994,43 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params) ...@@ -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){ property->data_value.type == KK_TSL_DATA_TYPE_BOOL){
sprintf(tmpValue,"%d",property->data_value.value_int); sprintf(tmpValue,"%d",property->data_value.value_int);
kk_property_db_update_value(deviceCode,property->identifier,tmpValue); 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){ else if(property->data_value.type == KK_TSL_DATA_TYPE_FLOAT){
sprintf(tmpValue,"%f",property->data_value.value_float); sprintf(tmpValue,"%f",property->data_value.value_float);
kk_property_db_update_value(deviceCode,property->identifier,tmpValue); 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){ else if(property->data_value.type == KK_TSL_DATA_TYPE_DOUBLE){
sprintf(tmpValue,"%f",property->data_value.value_double); sprintf(tmpValue,"%f",property->data_value.value_double);
kk_property_db_update_value(deviceCode,property->identifier,tmpValue); 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|| else if(property->data_value.type == KK_TSL_DATA_TYPE_TEXT||
property->data_value.type == KK_TSL_DATA_TYPE_DATE){ property->data_value.type == KK_TSL_DATA_TYPE_DATE){
kk_property_db_update_value(deviceCode,property->identifier,property->data_value.value); 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){ else if(property->data_value.type == KK_TSL_DATA_TYPE_STRUCT){
kk_tsl_data_value_complex_t *complex_struct = NULL; 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) ...@@ -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){ current_data->data_value.type == KK_TSL_DATA_TYPE_DATE){
kk_property_db_update_value(deviceCode,tmp_identifiers,current_data->data_value.value); 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){ else if(current_data->data_value.type == KK_TSL_DATA_TYPE_STRUCT){
kk_tsl_data_value_complex_t *complex_struct_1 = NULL; kk_tsl_data_value_complex_t *complex_struct_1 = NULL;
complex_struct_1 = current_data->data_value.value; complex_struct_1 = current_data->data_value.value;
...@@ -1029,6 +1102,7 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params) ...@@ -1029,6 +1102,7 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
} }
} }
#endif
else{ else{
ERROR_PRINT("Unsupport Type\n"); ERROR_PRINT("Unsupport Type\n");
} }
...@@ -1039,11 +1113,33 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params) ...@@ -1039,11 +1113,33 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
else{ else{
ERROR_PRINT("Unkonwn Number Type"); ERROR_PRINT("Unkonwn Number Type");
} }
//cJSON_DeleteItemFromObject(params,property->identifier);
} }
} }
char* outstr = cJSON_Print(params); int epIdx[4] = {0};
dm_mgr_upstream_thing_property_post(node->devid,outstr,strlen(outstr),0); for(idx = 0; idx < epNumInt; idx++){
free(outstr); 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; return SUCCESS_RETURN;
} }
......
...@@ -929,7 +929,20 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -929,7 +929,20 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
_iotx_linkkit_upstream_mutex_unlock(); _iotx_linkkit_upstream_mutex_unlock();
}else if (strstr(typeJson->valuestring,KK_THING_SERVICE_PROPERTY_SET)){ }else if (strstr(typeJson->valuestring,KK_THING_SERVICE_PROPERTY_SET)){
INFO_PRINT("property set \n"); 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)){ }else if (strstr(typeJson->valuestring,KK_THING_CLOUDSTATE_MSG)){
INFO_PRINT("cloud state notify \n"); INFO_PRINT("cloud state notify \n");
s_CloudStatusRecv = 1; s_CloudStatusRecv = 1;
......
...@@ -113,12 +113,12 @@ int kk_history_db_init(void) ...@@ -113,12 +113,12 @@ int kk_history_db_init(void)
/************************************************************ /************************************************************
*功能描述:删除历史数据 *功能描述:删除历史数据
*输入参数:time:记录时间 *输入参数:itime:记录时间
*输出参数:无 *输出参数:无
*返 回 值:0:成功;其他:失败 *返 回 值: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';"; const char *deleteCmd = "delete from '%s' where recordtime = '%d';";
char *sqlCmd = NULL; char *sqlCmd = NULL;
...@@ -126,7 +126,7 @@ int kk_history_delete_by_recordtime(const char *table,time_t time) ...@@ -126,7 +126,7 @@ int kk_history_delete_by_recordtime(const char *table,time_t time)
char *zErrMsg = 0; char *zErrMsg = 0;
kk_history_ctx_t *ctx = _kk_history_get_ctx(); 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); INFO_PRINT("Table delete data sqlCmd:%s\n",sqlCmd);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg); rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){ if( rc != SQLITE_OK ){
...@@ -179,7 +179,7 @@ err1: ...@@ -179,7 +179,7 @@ err1:
*返 回 值: 0:成功;其他:失败 *返 回 值: 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; int res = 0;
kk_history_ctx_t *ctx = _kk_history_get_ctx(); 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, ...@@ -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); INFO_PRINT("kk_history_insert_sensor_info,deviceCode:%s,identifier:%s,value:%s\n",deviceCode,identifier,valueStr);
_kk_history_lock(); _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); res = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( res != SQLITE_OK ){ if( res != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg); ERROR_PRINT("SQL error: %s\n", zErrMsg);
...@@ -235,7 +235,7 @@ int kk_history_insert_sensor_info(const char* deviceCode,const char* identifier, ...@@ -235,7 +235,7 @@ int kk_history_insert_sensor_info(const char* deviceCode,const char* identifier,
*返 回 值: 0:成功;其他:失败 *返 回 值: 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; int res = 0;
kk_history_ctx_t *ctx = _kk_history_get_ctx(); 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 ...@@ -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); INFO_PRINT("kk_history_insert_Outlet_info,deviceCode:%s,power:%s,metering:%s\n",deviceCode,power,metering);
_kk_history_lock(); _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); res = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( res != SQLITE_OK ){ if( res != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg); ERROR_PRINT("SQL error: %s\n", zErrMsg);
......
...@@ -15,8 +15,8 @@ enum{ ...@@ -15,8 +15,8 @@ enum{
DB_OUTLET_RECORDTIME, DB_OUTLET_RECORDTIME,
}; };
int kk_history_db_init(void); int kk_history_db_init(void);
int kk_history_delete_by_recordtime(const char *table,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 time); 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 time); int kk_history_insert_Outlet_info(const char* deviceCode,const char* power,const char* metering,time_t itime);
#endif #endif
...@@ -138,7 +138,21 @@ void kk_sendData2gw(void* data, int len, char* chalMark){ ...@@ -138,7 +138,21 @@ void kk_sendData2gw(void* data, int len, char* chalMark){
kk_print_long_data(data,newLen); kk_print_long_data(data,newLen);
INFO_PRINT("start to send data to gw end\n"); INFO_PRINT("start to send data to gw end\n");
} }
static void 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;
}
/************************************************************ /************************************************************
*功能描述:属性参数校验 *功能描述:属性参数校验
*输入参数:payload:消息内容 *输入参数:payload:消息内容
...@@ -152,104 +166,142 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){ ...@@ -152,104 +166,142 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){
dm_mgr_dev_node_t *node = NULL; dm_mgr_dev_node_t *node = NULL;
kk_tsl_data_t *property = NULL; kk_tsl_data_t *property = NULL;
cJSON *propertyItem = NULL; cJSON *propertyItem = NULL;
cJSON *epNum = NULL;
int epNumInt = 1;
int num = 0;
int res = 0; int res = 0;
int idx = 0; int idx = 0;
int value = 0; int value = 0;
char *propertiesbuf[64] = {0};
char propertiesTmp[64] = {0};
res = dm_mgr_get_device_by_devicecode((char*)deviceCode,&node); res = dm_mgr_get_device_by_devicecode((char*)deviceCode,&node);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res); ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return FAIL_RETURN; return FAIL_RETURN;
} }
params = cJSON_GetObjectItem(payload, MSG_PARAMS_STR); params = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
if(params != NULL){ if(params != NULL){
epNum = cJSON_GetObjectItem(params, "epNum");
if(epNum != NULL){
epNumInt = atoi(epNum->valuestring);
}else{
epNumInt = 1;
}
//printf("----------------->epNumInt:%d\n",epNumInt);
for(idx = 0; idx < node->dev_shadow->property_number; idx++){ for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx); property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL){ if(property == NULL){
continue; continue;
} }
//printf("----------------->property->identifier:%s\n",property->identifier);
memcpy(propertiesTmp,property->identifier,strlen(property->identifier));
split(propertiesTmp,"_",propertiesbuf,&num);
if(num == 2){
if(atoi(propertiesbuf[1]) == epNumInt){
//printf("----------------->propertiesbuf[0]:%s\n",propertiesbuf[0]);
propertyItem = cJSON_GetObjectItem(params, propertiesbuf[0]);
if(propertyItem != NULL){
//cJSON_AddNumberToObject(params,tmpPS,PowerSwitch->valueint);
//cJSON_DeleteItemFromObject(params, "PowerSwitch");
//printf("----------------->property->data_value.type:%d\n",property->data_value.type);
if(property->data_value.type == KK_TSL_DATA_TYPE_STRUCT){
kk_tsl_data_value_complex_t *complex_struct = NULL;
kk_tsl_data_t *current_data = NULL;
int index;
complex_struct = property->data_value.value;
for (index = 0; index < complex_struct->size; index++) {
current_data = (kk_tsl_data_t *)complex_struct->value + index;
cJSON *propertyItem_1 = NULL;
propertyItem_1 = cJSON_GetObjectItem(propertyItem, current_data->identifier);
if(propertyItem_1 == NULL){
continue;
}
if(current_data->data_value.type != KK_TSL_DATA_TYPE_STRUCT){
if(current_data->data_value.type == KK_TSL_DATA_TYPE_INT){
value = propertyItem_1->valueint;
if(value < current_data->data_value.mix ||value > current_data->data_value.max ){
ERROR_PRINT("ERROR !!!value:%d,mix:%d,max:%d\n",value,current_data->data_value.mix,current_data->data_value.max);
return INVALID_PARAMETER;
}
}
else if(current_data->data_value.type == KK_TSL_DATA_TYPE_TEXT){
if(strlen(propertyItem_1->valuestring) > current_data->data_value.length ){
ERROR_PRINT("ERROR !!!strlen(propertyItem_1->valuestring):%d,current_data->data_value.length:%d\n",strlen(propertyItem_1->valuestring),current_data->data_value.length);
return INVALID_PARAMETER;
}
}
}
else{
kk_tsl_data_value_complex_t *complex_struct_1 = NULL;
kk_tsl_data_t *current_data_1 = NULL;
int index_1;
complex_struct_1 = current_data->data_value.value;
for(index_1 = 0; index_1 < complex_struct_1->size; index_1++){
current_data_1 = (kk_tsl_data_t *)complex_struct_1->value + index_1;
cJSON *propertyItem_2 = NULL;
propertyItem_2 = cJSON_GetObjectItem(propertyItem_1, current_data_1->identifier);
if(propertyItem_2 == NULL){
continue;
}
if(current_data_1->data_value.type == KK_TSL_DATA_TYPE_INT){
value = propertyItem_2->valueint;
if(value < current_data_1->data_value.mix ||value > current_data_1->data_value.max ){
ERROR_PRINT("ERROR !!!value:%d,mix:%d,max:%d\n",value,current_data_1->data_value.mix,current_data_1->data_value.max);
return INVALID_PARAMETER;
}
}
else if(current_data_1->data_value.type == KK_TSL_DATA_TYPE_TEXT){
if(strlen(propertyItem_2->valuestring) > current_data_1->data_value.length ){
ERROR_PRINT("ERROR !!!strlen(propertyItem_2->valuestring):%d,propertyItem_2->data_value.length:%d\n",strlen(propertyItem_2->valuestring),current_data_1->data_value.length);
return INVALID_PARAMETER;
}
}
}
propertyItem = cJSON_GetObjectItem(params, property->identifier); }
if(propertyItem != NULL){
//if(strcmp(property->accessMode,"rw") != 0){
//ERROR_PRINT("ERROR !!!property->accessMode:%s\n",property->accessMode);
//return INVALID_PARAMETER;
//}
if(property->data_value.type == KK_TSL_DATA_TYPE_STRUCT){
kk_tsl_data_value_complex_t *complex_struct = NULL;
kk_tsl_data_t *current_data = NULL;
int index;
complex_struct = property->data_value.value;
for (index = 0; index < complex_struct->size; index++) {
current_data = (kk_tsl_data_t *)complex_struct->value + index;
cJSON *propertyItem_1 = NULL;
propertyItem_1 = cJSON_GetObjectItem(propertyItem, current_data->identifier);
if(propertyItem_1 == NULL){
continue;
}
if(current_data->data_value.type != KK_TSL_DATA_TYPE_STRUCT){
if(current_data->data_value.type == KK_TSL_DATA_TYPE_INT){
value = propertyItem_1->valueint;
if(value < current_data->data_value.mix ||value > current_data->data_value.max ){
ERROR_PRINT("ERROR !!!value:%d,mix:%d,max:%d\n",value,current_data->data_value.mix,current_data->data_value.max);
return INVALID_PARAMETER;
} }
cJSON_AddItemToObject(params,property->identifier,propertyItem);
cJSON_DeleteItemFromObject(params, propertiesbuf[0]);
} }
else if(current_data->data_value.type == KK_TSL_DATA_TYPE_TEXT){ else if(property->data_value.type == KK_TSL_DATA_TYPE_INT ||property->data_value.type == KK_TSL_DATA_TYPE_FLOAT \
if(strlen(propertyItem_1->valuestring) > current_data->data_value.length ){ || property->data_value.type == KK_TSL_DATA_TYPE_DOUBLE){
value = propertyItem->valueint;
ERROR_PRINT("ERROR !!!strlen(propertyItem_1->valuestring):%d,current_data->data_value.length:%d\n",strlen(propertyItem_1->valuestring),current_data->data_value.length); if(value < property->data_value.mix ||value > property->data_value.max ){
ERROR_PRINT("ERROR !!!value:%d,mix:%d,max:%d\n",value,property->data_value.mix,property->data_value.max);
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
INFO_PRINT("-----------------KK_TSL_DATA_TYPE_INT-------------------\n");
cJSON_AddNumberToObject(params,property->identifier,propertyItem->valueint);
cJSON_DeleteItemFromObject(params, propertiesbuf[0]);
} }
} else if(property->data_value.type == KK_TSL_DATA_TYPE_TEXT){
else{ if(strlen(propertyItem->valuestring) > property->data_value.length ){
kk_tsl_data_value_complex_t *complex_struct_1 = NULL; ERROR_PRINT("ERROR !!!strlen(propertyItem->valuestring):%d,property->data_value.length:%d\n",strlen(propertyItem->valuestring),property->data_value.length );
kk_tsl_data_t *current_data_1 = NULL; return INVALID_PARAMETER;
int index_1;
complex_struct_1 = current_data->data_value.value;
for(index_1 = 0; index_1 < complex_struct_1->size; index_1++){
current_data_1 = (kk_tsl_data_t *)complex_struct_1->value + index_1;
cJSON *propertyItem_2 = NULL;
propertyItem_2 = cJSON_GetObjectItem(propertyItem_1, current_data_1->identifier);
if(propertyItem_2 == NULL){
continue;
}
if(current_data_1->data_value.type == KK_TSL_DATA_TYPE_INT){
value = propertyItem_2->valueint;
if(value < current_data_1->data_value.mix ||value > current_data_1->data_value.max ){
ERROR_PRINT("ERROR !!!value:%d,mix:%d,max:%d\n",value,current_data_1->data_value.mix,current_data_1->data_value.max);
return INVALID_PARAMETER;
}
}
else if(current_data_1->data_value.type == KK_TSL_DATA_TYPE_TEXT){
if(strlen(propertyItem_2->valuestring) > current_data_1->data_value.length ){
ERROR_PRINT("ERROR !!!strlen(propertyItem_2->valuestring):%d,propertyItem_2->data_value.length:%d\n",strlen(propertyItem_2->valuestring),current_data_1->data_value.length);
return INVALID_PARAMETER;
}
} }
} INFO_PRINT("-----------------KK_TSL_DATA_TYPE_TEXT-------------------\n");
cJSON_AddStringToObject(params,property->identifier,propertyItem->valuestring);
} cJSON_DeleteItemFromObject(params, propertiesbuf[0]);
} }
else if(property->data_value.type == KK_TSL_DATA_TYPE_ENUM || property->data_value.type == KK_TSL_DATA_TYPE_BOOL){
} INFO_PRINT("-----------------KK_TSL_DATA_TYPE_ENUM-------------------\n");
else if(property->data_value.type == KK_TSL_DATA_TYPE_INT){ cJSON_AddNumberToObject(params,property->identifier,propertyItem->valueint);
value = propertyItem->valueint; cJSON_DeleteItemFromObject(params, propertiesbuf[0]);
if(value < property->data_value.mix ||value > property->data_value.max ){ }
ERROR_PRINT("ERROR !!!value:%d,mix:%d,max:%d\n",value,property->data_value.mix,property->data_value.max);
return INVALID_PARAMETER;
}
}
else if(property->data_value.type == KK_TSL_DATA_TYPE_TEXT){
if(strlen(propertyItem->valuestring) > property->data_value.length ){
ERROR_PRINT("ERROR !!!strlen(propertyItem->valuestring):%d,property->data_value.length:%d\n",strlen(propertyItem->valuestring),property->data_value.length );
return INVALID_PARAMETER;
} }
} }
} }
//propertyItem = cJSON_GetObjectItem(params, property->identifier);
//if(propertyItem != NULL){
//if(strcmp(property->accessMode,"rw") != 0){
//ERROR_PRINT("ERROR !!!property->accessMode:%s\n",property->accessMode);
//return INVALID_PARAMETER;
//}
//}
} }
} }
...@@ -305,6 +357,7 @@ void mid_cb(void* data, int len){ ...@@ -305,6 +357,7 @@ void mid_cb(void* data, int len){
cJSON_Delete(json); cJSON_Delete(json);
return; return;
} }
} }
int devType = 0; int devType = 0;
...@@ -331,7 +384,17 @@ void mid_cb(void* data, int len){ ...@@ -331,7 +384,17 @@ void mid_cb(void* data, int len){
cJSON_Delete(json); cJSON_Delete(json);
return; return;
} }
kk_sendData2gw(data, strlen(data), gw_node->fatherDeviceCode);//send to sub device cJSON * rootData=cJSON_CreateObject();
char *info_rootS=cJSON_Print(info_root);
char *payloadS = cJSON_Print(payload);
cJSON_AddItemToObject(rootData,MSG_INFO_STR, cJSON_Parse(info_rootS));
cJSON_AddItemToObject(rootData,MSG_PAYLOAD_STR, cJSON_Parse(payloadS));
char *pnewout=cJSON_Print(rootData);
kk_sendData2gw(pnewout, strlen(pnewout), gw_node->fatherDeviceCode);//send to sub device
free(info_rootS);
free(payloadS);
free(pnewout);
cJSON_Delete(rootData);
} }
else{ else{
ERROR_PRINT("wrong type\n"); ERROR_PRINT("wrong type\n");
...@@ -553,6 +616,7 @@ void kk_platMsg_handle(void* data, char* chalMark){ ...@@ -553,6 +616,7 @@ void kk_platMsg_handle(void* data, char* chalMark){
itemStr = cJSON_GetObjectItem(jsonPay, eventItem->identifier); itemStr = cJSON_GetObjectItem(jsonPay, eventItem->identifier);
itemData = eventItem->output_datas + index; itemData = eventItem->output_datas + index;
#if 0 #if 0
if(itemStr != NULL){ if(itemStr != NULL){
memset(tmpStr,0x0,sizeof(tmpStr)); memset(tmpStr,0x0,sizeof(tmpStr));
...@@ -900,6 +964,11 @@ void *udp_dispatch_yield(void *args){ ...@@ -900,6 +964,11 @@ void *udp_dispatch_yield(void *args){
memset(szOut, 0, sizeof(szOut)); memset(szOut, 0, sizeof(szOut));
HAL_Get_IP(host_ip,NULL); HAL_Get_IP(host_ip,NULL);
HAL_GetDevice_Code(device_code); HAL_GetDevice_Code(device_code);
// printf("[%s][%d]inet_ntoa(from.sin_addr):%s\n",__FUNCTION__,__LINE__,inet_ntoa(from.sin_addr));
// printf("[%s][%d]host_ip:%s\n",__FUNCTION__,__LINE__,host_ip);
// if(strcmp(inet_ntoa(from.sin_addr),host_ip) == 0){
sprintf(szOut,"search_kk_ccu_ack|deviceCode=%s;ip=%s;port=%d",device_code,host_ip,16565); sprintf(szOut,"search_kk_ccu_ack|deviceCode=%s;ip=%s;port=%d",device_code,host_ip,16565);
DEBUG_PRINT("szOut:%s\n",szOut); DEBUG_PRINT("szOut:%s\n",szOut);
...@@ -921,6 +990,7 @@ void *udp_dispatch_yield(void *args){ ...@@ -921,6 +990,7 @@ void *udp_dispatch_yield(void *args){
//{ //{
// DEBUG_PRINT("udp client is not local ip , refused send ack to it\n"); // DEBUG_PRINT("udp client is not local ip , refused send ack to it\n");
//} //}
// }
} }
} }
usleep(100000); usleep(100000);
......
...@@ -619,7 +619,7 @@ int kk_scene_parse_scene_trigger(const cJSON* str,const char *sceneId) ...@@ -619,7 +619,7 @@ int kk_scene_parse_scene_trigger(const cJSON* str,const char *sceneId)
cJSON *items, *item; cJSON *items, *item;
cJSON *type; cJSON *type;
cJSON *week; cJSON *week;
cJSON *time; cJSON *timestr;
int res = 0; int res = 0;
int weekflag = 0; int weekflag = 0;
if(str == NULL || sceneId == NULL){ if(str == NULL || sceneId == NULL){
...@@ -645,10 +645,10 @@ int kk_scene_parse_scene_trigger(const cJSON* str,const char *sceneId) ...@@ -645,10 +645,10 @@ int kk_scene_parse_scene_trigger(const cJSON* str,const char *sceneId)
week = cJSON_GetObjectItem(item,MSG_SCENE_WEEK); week = cJSON_GetObjectItem(item,MSG_SCENE_WEEK);
if(week == NULL) return FAIL_RETURN; if(week == NULL) return FAIL_RETURN;
weekflag = kk_scene_parse_repeatday(week); weekflag = kk_scene_parse_repeatday(week);
time = cJSON_GetObjectItem(item,MSG_SCENE_TIME); timestr = cJSON_GetObjectItem(item,MSG_SCENE_TIME);
if(time == NULL) return FAIL_RETURN; if(timestr == NULL) return FAIL_RETURN;
time_t current = HAL_GetTime(); 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_insert_scene_timer(newStart,weekflag,sceneId);
kk_scene_push_timer_info(newStart,weekflag,(char*)sceneId); kk_scene_push_timer_info(newStart,weekflag,(char*)sceneId);
} }
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#define DM_UTILS_UINT64_STRLEN (20) #define DM_UTILS_UINT64_STRLEN (20)
#define DEVICE_PROPERTY_NAME_MAX (64+1) #define DEVICE_PROPERTY_NAME_MAX (64+1)
#define DEVICE_PROPERTY_VALUE_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_SCHEMA "schema"
#define KK_TSL_KEY_LINK "link" #define KK_TSL_KEY_LINK "link"
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
#define KK_TSL_CCU_WANIP_IDENTIFIER "WanIPAddress" #define KK_TSL_CCU_WANIP_IDENTIFIER "WanIPAddress"
#define KK_TSL_CCU_WANSTATE_IDENTIFIER "WanState" #define KK_TSL_CCU_WANSTATE_IDENTIFIER "WanState"
#define KK_TSL_CCU_IOTCLOUD_IDENTIFIER "IOTCloudState" #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_VERSION_IDENTIFIER "Version"
#define KK_TSL_GATAWAY_IP_IDENTIFIER "IPAddress" #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