Commit 983bc9ac authored by 陈伟灿's avatar 陈伟灿

Merge branch 'cwc' into 'master'

【修改内容】增加属性设置时参数根据物模型所定义的mix,max以及length进行有效性判断

See merge request chenweican/k-sdk!24
parents 5c98ce43 fc3801f2
......@@ -57,6 +57,112 @@ void kk_sendData2gw(void* data, int len, char* chalMark){
kk_ipc_send_ex(IPC_MID2PLAT, data, len + 1, chalMark);
}
}
static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){
cJSON *params = NULL;
dm_mgr_dev_node_t *node = NULL;
kk_tsl_data_t *property = NULL;
cJSON *propertyItem = NULL;
int res = 0;
int idx = 0;
int value = 0;
res = dm_mgr_get_device_by_devicecode(deviceCode,&node);
if (res != SUCCESS_RETURN) {
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return FAIL_RETURN;
}
params = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
if(params != NULL){
for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL){
continue;
}
propertyItem = cJSON_GetObjectItem(params, property->identifier);
if(propertyItem != NULL){
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;
}
}
}
}
}
}else if(property->data_value.type == KK_TSL_DATA_TYPE_INT){
value = propertyItem->valueint;
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;
}
}
}
}
}
return SUCCESS_RETURN;
}
void mid_cb(void* data, int len){
if (data != NULL){
......@@ -85,6 +191,16 @@ void mid_cb(void* data, int len){
cJSON_Delete(json);
return;
}
/*****属性设置需要先检测设置参数是否超出物模型给定范围*******/
if (strcmp(type->valuestring, KK_THING_SERVICE_PROPERTY_SET)==0){
cJSON* payload = cJSON_GetObjectItem(json, MSG_PAYLOAD_STR);
if(payload != NULL){
res = kk_property_set_data_check(payload,deviceCode->valuestring);
if(res != SUCCESS_RETURN){
return;
}
}
}
int devType = 0;
dm_mgr_get_devicetype_by_devicecode(deviceCode->valuestring,&devType);
......
......@@ -409,12 +409,6 @@ static int _kk_msg_request_parse(_IN_ char *payload, _IN_ int payload_len, _OU_
&request->params) != SUCCESS_RETURN) {
return FAIL_RETURN;
}
INFO_PRINT("Current Request Message ID: %.*s", request->id.value_length, request->id.value);
INFO_PRINT("Current Request Message Version: %.*s", request->version.value_length, request->version.value);
INFO_PRINT("Current Request Message Method: %.*s", request->method.value_length, request->method.value);
INFO_PRINT("Current Request Message Params: %.*s", request->params.value_length, request->params.value);
return SUCCESS_RETURN;
}
......
......@@ -122,6 +122,9 @@ typedef struct {
typedef struct {
kk_tsl_data_type_e type;
int mix;
int max;
int length;
union {
int value_int;
float value_float;
......
......@@ -351,8 +351,39 @@ static int _kk_tsl_array_struct_parse(_IN_ kk_tsl_data_value_t *data_value, _IN_
return SUCCESS_RETURN;
}
static int _kk_tsl_opt_parse(_IN_ kk_tsl_data_value_t *data_value, _IN_ lite_cjson_t *root)
{
int res = 0;
lite_cjson_t lite_item;
if(data_value->type == KK_TSL_DATA_TYPE_TEXT){
res = lite_cjson_object_item(root, KK_TSL_KEY_LENGTH, strlen(KK_TSL_KEY_LENGTH), &lite_item);
if(res == SUCCESS_RETURN){
data_value->length = atoi(lite_item.value);
}
}
else if(data_value->type == KK_TSL_DATA_TYPE_INT){
res = lite_cjson_object_item(root, KK_TSL_KEY_MIN, strlen(KK_TSL_KEY_MIN), &lite_item);
if(res == SUCCESS_RETURN){
data_value->mix = atoi(lite_item.value);
printf("------------>[%s][%d]data_value->mix:%d\n",__FUNCTION__,__LINE__,data_value->mix);
}
res = lite_cjson_object_item(root, KK_TSL_KEY_MAX, strlen(KK_TSL_KEY_MAX), &lite_item);
if(res == SUCCESS_RETURN){
data_value->max = atoi(lite_item.value);
printf("------------>[%s][%d]data_value->max:%d\n",__FUNCTION__,__LINE__,data_value->max);
}
}
return SUCCESS_RETURN;
}
static int _kk_tsl_data_parse(_IN_ kk_tsl_data_value_t *data_value, _IN_ lite_cjson_t *root)
{
int res = 0;
......@@ -376,7 +407,8 @@ static int _kk_tsl_data_parse(_IN_ kk_tsl_data_value_t *data_value, _IN_ lite_cj
memset(&lite_item, 0, sizeof(lite_cjson_t));
res = lite_cjson_object_item(root, KK_TSL_KEY_SPECS, strlen(KK_TSL_KEY_SPECS), &lite_item);
if (res == SUCCESS_RETURN) {
/* dm_log_debug("TSL Data Specs: %.*s",lite_item.value_length,lite_item.value); */
_kk_tsl_opt_parse(data_value,&lite_item);
}
//Parse Type And Value
......@@ -407,7 +439,6 @@ static int _kk_tsl_property_parse(_IN_ kk_tsl_data_t *property, _IN_ lite_cjson_
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
//printf("Identifier: %s\n", property->identifier);
//Parse DataType
memset(&lite_item, 0, sizeof(lite_cjson_t));
......@@ -432,12 +463,10 @@ static int _kk_tsl_properties_parse(_IN_ kk_tsl_t *shadow, _IN_ lite_cjson_t *ro
memset(&lite_properties, 0, sizeof(lite_cjson_t));
res = lite_cjson_object_item(root, KK_TSL_KEY_PROPERTIES, strlen(KK_TSL_KEY_PROPERTIES), &lite_properties);
if (res == SUCCESS_RETURN) {
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if (!lite_cjson_is_array(&lite_properties)) {
return JSON_PARSE_FAILED;
}
} else {
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return SUCCESS_RETURN;
}
......
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