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

【修改内容】增加RGB彩灯灯带的控制,目前还处于debug阶段,相关对应的clusterID还需要细调

【提交人】陈伟灿
parent c676193f
......@@ -148,9 +148,10 @@ static int _dm_init_tsl_params(kk_tsl_t * dev_shadow)
}
return res;
}
/*目前支持到三级结构体的属性解析保存到数据库*/
int dm_mgr_properities_db_create(kk_tsl_t* dev_shadow,char *deviceCode,int devType )
{
int num = 0,idx = 0,index = 0;
int num = 0,idx = 0,index = 0,index1 = 0;
kk_tsl_data_t *pProperty = NULL;
kk_tsl_data_t *current_data = NULL;
char tmp_identifiers[256] = {0};
......@@ -170,10 +171,28 @@ int dm_mgr_properities_db_create(kk_tsl_t* dev_shadow,char *deviceCode,int devTy
complex_struct = pProperty->data_value.value;
for (index = 0; index < complex_struct->size; index++) {
current_data = (kk_tsl_data_t *)complex_struct->value + index;
memset(tmp_identifiers,0x0,sizeof(tmp_identifiers));
sprintf(tmp_identifiers,"%s.%s",pProperty->identifier,current_data->identifier);
INFO_PRINT("dm_mgr_properities_db_create tmp_identifiers:%s!!\n",tmp_identifiers);
kk_property_db_insert(deviceCode,tmp_identifiers,current_data->data_value.type,devType);
if(current_data->data_value.type != KK_TSL_DATA_TYPE_STRUCT ){
memset(tmp_identifiers,0x0,sizeof(tmp_identifiers));
sprintf(tmp_identifiers,"%s.%s",pProperty->identifier,current_data->identifier);
INFO_PRINT("dm_mgr_properities_db_create tmp_identifiers:%s!!\n",tmp_identifiers);
kk_property_db_insert(deviceCode,tmp_identifiers,current_data->data_value.type,devType);
}
else{
kk_tsl_data_value_complex_t *complex_struct_1 = NULL;
complex_struct_1 = current_data->data_value.value;
for(index1 = 0; index1 < complex_struct_1->size; index1++){
kk_tsl_data_t *current_data_1 = NULL;
current_data_1 = (kk_tsl_data_t *)complex_struct_1->value + index1;
if(current_data_1->data_value.type != KK_TSL_DATA_TYPE_STRUCT ){
memset(tmp_identifiers,0x0,sizeof(tmp_identifiers));
sprintf(tmp_identifiers,"%s.%s.%s",pProperty->identifier,current_data->identifier,current_data_1->identifier);
INFO_PRINT("dm_mgr_properities_db_create tmp_identifiers:%s!!\n",tmp_identifiers);
kk_property_db_insert(deviceCode,tmp_identifiers,current_data_1->data_value.type,devType);
}
}
}
}
}else
{
......@@ -452,9 +471,8 @@ int dm_mgr_init(void)
/* Init Device List */
INIT_LIST_HEAD(&ctx->dev_list);
//HAL_GetProduct_Type(product_key);
//HAL_GetProduct_Code(device_name);
HAL_Get_mac(mac);
res = dm_mgr_device_create(KK_DM_DEVICE_CCU,KK_DM_CCU_DEVICE_PRODUCT_CODE,"CCU_66666",mac,"",&devId);
if (res != SUCCESS_RETURN) {
goto ERROR;
......
......@@ -908,6 +908,44 @@ 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);
}
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;
int index1 = 0;
kk_tsl_data_t *current_data_1 = NULL;
cJSON *propertyItem_2 = NULL;
for(index1 = 0; index1 < complex_struct_1->size; index1++){
current_data_1 = (kk_tsl_data_t *)complex_struct_1->value + index1;
propertyItem_2 = cJSON_GetObjectItem(propertyItem_1, current_data_1->identifier);
if(propertyItem_2 != NULL){
memset(tmp_identifiers,0x0,sizeof(tmp_identifiers));
sprintf(tmp_identifiers,"%s.%s.%s",property->identifier,current_data->identifier,current_data_1->identifier);
if(current_data_1->data_value.type == KK_TSL_DATA_TYPE_INT ||
current_data_1->data_value.type == KK_TSL_DATA_TYPE_ENUM||
current_data_1->data_value.type == KK_TSL_DATA_TYPE_BOOL){
sprintf(tmpValue,"%d",current_data_1->data_value.value_int);
kk_property_db_update_value(deviceCode,tmp_identifiers,tmpValue);
}
else if(current_data_1->data_value.type == KK_TSL_DATA_TYPE_FLOAT){
sprintf(tmpValue,"%d",current_data_1->data_value.value_float);
kk_property_db_update_value(deviceCode,tmp_identifiers,tmpValue);
}
else if(current_data_1->data_value.type == KK_TSL_DATA_TYPE_DOUBLE){
sprintf(tmpValue,"%d",current_data_1->data_value.value_double);
kk_property_db_update_value(deviceCode,tmp_identifiers,tmpValue);
}
else if(current_data_1->data_value.type == KK_TSL_DATA_TYPE_TEXT||
current_data_1->data_value.type == KK_TSL_DATA_TYPE_DATE){
kk_property_db_update_value(deviceCode,tmp_identifiers,current_data_1->data_value.value);
}
else{
ERROR_PRINT("Unsupport Type ~~\n");
}
}
}
}
else{
ERROR_PRINT("Unsupport Type\n");
}
......
......@@ -403,5 +403,28 @@ int kk_property_delete_by_dcode(char deviceCode[DEVICE_CODE_MAXLEN])
return SUCCESS_RETURN;
}
int kk_property_delete_by_identify(char *identify)
{
const char *deleteCmd = "delete from PropertiesInfo where identifier = '%s';";
char *sqlCmd = NULL;
int rc = 0;
char *zErrMsg = 0;
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
_kk_property_db_lock();
sqlCmd = sqlite3_mprintf(deleteCmd,identify);
INFO_PRINT("Table delete data sqlCmd:%s\n",sqlCmd);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
INFO_PRINT("Table delete data successfully\n");
}
sqlite3_free(sqlCmd);
_kk_property_db_unlock();
return SUCCESS_RETURN;
}
......
......@@ -10,21 +10,41 @@ const char *kk_tsl_rpt_status_string[] = {
};
static cJSON* kk_check_identify(const char * identify,cJSON* root,int index,int status)
{
int rev = 0,startIdx = 0;
int rev = 0,startIdx2 = 0,startIdx1 = 0;
char *Identify_str;
char tmp_Identity[64] = {0};
rev = kk_tsl_utils_memtok(identify,".",1,&startIdx);
rev = kk_tsl_utils_memtok(identify,'.',2,&startIdx2);
if(!rev){
cJSON* str = NULL;
cJSON* str_r = NULL;
kk_tsl_utils_memtok(identify,'.',1,&startIdx1);
str = rpc_cJSON_CreateObject();
Identify_str = identify + 1 + startIdx;
Identify_str = identify + 1 + startIdx2;
memset(tmp_Identity,0x0,sizeof(tmp_Identity));
memcpy(tmp_Identity,identify,startIdx);
memcpy(tmp_Identity,identify+startIdx1+1,startIdx2-startIdx1);
rpc_cJSON_AddNumberToObject(str, Identify_str,status);
rpc_cJSON_AddItemToObject(root,tmp_Identity,str);
str_r = rpc_cJSON_CreateObject();
rpc_cJSON_AddItemToObject(str_r,tmp_Identity,str);
memset(tmp_Identity,0x0,sizeof(tmp_Identity));
memcpy(tmp_Identity,identify,startIdx1);
rpc_cJSON_AddItemToObject(root,tmp_Identity,str_r);
return root;
}
else{
rev = kk_tsl_utils_memtok(identify,'.',1,&startIdx1);
if(!rev){
cJSON* str = NULL;
str = rpc_cJSON_CreateObject();
Identify_str = identify + 1 + startIdx1;
memset(tmp_Identity,0x0,sizeof(tmp_Identity));
memcpy(tmp_Identity,identify,startIdx1);
rpc_cJSON_AddNumberToObject(str, Identify_str,status);
rpc_cJSON_AddItemToObject(root,tmp_Identity,str);
return root;
}
}
return NULL;
......@@ -54,7 +74,6 @@ static int kk_tsl_report(EmberEUI64 mac,uint8_t EP,int status,uint16_t clusterId
root_tmp = kk_check_identify(g_tsl_zigbee_map_glb[index].map.Identity,root,index,status);
if(root_tmp != NULL){
kk_rpc_report_status(root_tmp,mac);
//rpc_cJSON_Delete(root_tmp);
return tsl_rpt_success;
}
else{
......@@ -65,7 +84,6 @@ static int kk_tsl_report(EmberEUI64 mac,uint8_t EP,int status,uint16_t clusterId
root_tmp = kk_check_identify(g_tsl_zigbee_map[index].Identity,root,index,status);
if(root_tmp != NULL){
kk_rpc_report_status(root_tmp,mac);
//rpc_cJSON_Delete(root_tmp);
return tsl_rpt_success;
}
else{
......@@ -74,7 +92,6 @@ static int kk_tsl_report(EmberEUI64 mac,uint8_t EP,int status,uint16_t clusterId
}
rpc_cJSON_AddNumberToObject(root, Identify,status);
kk_rpc_report_status(root,mac);
//rpc_cJSON_Delete(root);
return tsl_rpt_success;
}
......@@ -105,7 +122,7 @@ void kk_tsl_report_attribute(EmberEUI64 eui64,
g_tsl_zigbee_map[i].attributeId == attributeId &&
g_tsl_zigbee_map[i].zigbee_report!=NULL){
status = g_tsl_zigbee_map[i].zigbee_report(eui64,EP,clusterId,attributeId,dataType,len,data);
emberAfDebugPrintln("report status:%s",kk_tsl_rpt_status_string[status]);
emberAfDebugPrintln("report status:%d",status);
return ;
}
}
......@@ -129,6 +146,38 @@ void kk_tsl_report_attribute(EmberEUI64 eui64,
}
}
int kk_tsl_report_global_Brightness(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data)
{
uint8_t value = data[0];
emberAfAppPrintln("[tsl report:kk_tsl_report_global_Brightness] value:%d\n",value);
printf("[%s][%d]dataType:%d\n",__FUNCTION__,__LINE__,dataType);
if(dataType == ZCL_INT8U_ATTRIBUTE_TYPE){
printf("[%s][%d]len:%d\n",__FUNCTION__,__LINE__,len);
if(len==1){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_tsl_report(eui64,EP,value,clusterId,attributeId);
return tsl_rpt_success;
}
return tsl_rpt_invaild_len;
}
return tsl_rpt_invaild_type;
}
int kk_tsl_report_global_RGB(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data)
{
uint8_t value = data[0];
emberAfAppPrintln("[tsl report:kk_tsl_report_global_RGB] value:%d\n",value);
printf("[%s][%d]dataType:%d\n",__FUNCTION__,__LINE__,dataType);
if(dataType == ZCL_INT8U_ATTRIBUTE_TYPE){
printf("[%s][%d]len:%d\n",__FUNCTION__,__LINE__,len);
if(len==1){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_tsl_report(eui64,EP,value,clusterId,attributeId);
return tsl_rpt_success;
}
return tsl_rpt_invaild_len;
}
return tsl_rpt_invaild_type;
}
int kk_tsl_report_global_onoff(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data)
{
......
#ifndef __KK_TSL_PROPERTY_REPORT_H
#define __KK_TSL_PROPERTY_REPORT_H
#include "kk_test.h"
typedef enum{
tsl_rpt_success = 0,
tsl_rpt_err = -1,
tsl_rpt_invaild_val = -2,
tsl_rpt_invaild_len = -3,
tsl_rpt_invaild_type = -4,
}kk_tsl_rpt_status;
void kk_tsl_report_attribute(EmberEUI64 eui64,
uint8_t EP,
EmberAfClusterId clusterId,
EmberAfAttributeId attributeId,
uint8_t dataType,
uint8_t len,
uint8_t *data);
int kk_tsl_report_global_onoff(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data);
int kk_tsl_report_windowCovering_mode(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data);
int kk_tsl_report_windowCovering_position(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data);
#endif
#ifndef __KK_TSL_PROPERTY_REPORT_H
#define __KK_TSL_PROPERTY_REPORT_H
#include "kk_test.h"
typedef enum{
tsl_rpt_success = 0,
tsl_rpt_err = -1,
tsl_rpt_invaild_val = -2,
tsl_rpt_invaild_len = -3,
tsl_rpt_invaild_type = -4,
}kk_tsl_rpt_status;
void kk_tsl_report_attribute(EmberEUI64 eui64,
uint8_t EP,
EmberAfClusterId clusterId,
EmberAfAttributeId attributeId,
uint8_t dataType,
uint8_t len,
uint8_t *data);
int kk_tsl_report_global_onoff(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data);
int kk_tsl_report_windowCovering_mode(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data);
int kk_tsl_report_windowCovering_position(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data);
int kk_tsl_report_global_Brightness(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data);
int kk_tsl_report_global_RGB(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data);
#endif
......@@ -13,9 +13,14 @@ int kk_tsl_set_windowCovering_OperationMode(jrpc_context * ctx,EmberNodeId node,
int kk_tsl_set_windowCovering_mode(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_windowCovering_position(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_colorlight_OnOff(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_colorlight_ModeType(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_colorlight_Mode(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_colorlight_Brightness(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_colorlight_WhiteBrightness(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_colorlight_RGB_red(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_colorlight_RGB_green(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_colorlight_RGB_blue(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
......
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