Commit 807f44b4 authored by chen.weican's avatar chen.weican

【修改内容】z3端支持二级identify的数据解析和上报

【提交人】陈伟灿
parent 9957d53d
#include "kk_tsl_property_report.h" #include "kk_tsl_property_report.h"
const char *kk_tsl_rpt_status_string[] = { const char *kk_tsl_rpt_status_string[] = {
"Success", "Success",
"Error", "Error",
"Invaild Value", "Invaild Value",
"Invaild Len", "Invaild Len",
"Invaild Type" "Invaild Type"
}; };
static int kk_tsl_report(EmberEUI64 mac,uint8_t EP,int status,uint16_t clusterId,uint16_t attributeId) static cJSON* kk_check_identify(const char * identify,cJSON* root,int index,int status)
{ {
cJSON* root; int rev = 0,startIdx = 0;
int index; char *Identify_str;
char *Identify; char tmp_Identity[64] = {0};
sub_dev_node_t *node = NULL;
kk_device_table_s *dev; rev = kk_tsl_utils_memtok(identify,".",1,&startIdx);
char macString[RPC_EUI64_STRING_LENGTH]; if(!rev){
rpc_eui64ToString(mac,macString); cJSON* str = NULL;
str = rpc_cJSON_CreateObject();
root = rpc_cJSON_CreateObject(); Identify_str = identify + 1 + startIdx;
memset(tmp_Identity,0x0,sizeof(tmp_Identity));
index = kk_get_tsl_index(EP,clusterId,attributeId); memcpy(tmp_Identity,identify,startIdx);
rpc_cJSON_AddNumberToObject(str, Identify_str,status);
if(index < 0){ rpc_cJSON_AddItemToObject(root,tmp_Identity,str);
dev = kk_device_find_by_mac(mac); return root;
if(dev!=NULL){ }
index = kk_get_tsl_glb_index(dev->productCode,EP,clusterId,attributeId); return NULL;
}
if(index < 0){ }
return tsl_rpt_err; static int kk_tsl_report(EmberEUI64 mac,uint8_t EP,int status,uint16_t clusterId,uint16_t attributeId)
}else{ {
Identify = g_tsl_zigbee_map_glb[index].map.Identity; cJSON* root,*root_tmp;
} int index;
}else{ char *Identify;
Identify = g_tsl_zigbee_map[index].Identity; sub_dev_node_t *node = NULL;
} kk_device_table_s *dev;
char macString[RPC_EUI64_STRING_LENGTH];
rpc_cJSON_AddNumberToObject(root, Identify,status);
kk_rpc_report_status(root,mac); rpc_eui64ToString(mac,macString);
return tsl_rpt_success;
} root = rpc_cJSON_CreateObject();
index = kk_get_tsl_index(EP,clusterId,attributeId);
if(index < 0){
dev = kk_device_find_by_mac(mac);
void kk_tsl_report_attribute(EmberEUI64 eui64, if(dev!=NULL){
uint8_t EP, index = kk_get_tsl_glb_index(dev->productCode,EP,clusterId,attributeId);
EmberAfClusterId clusterId, }
EmberAfAttributeId attributeId,
uint8_t dataType, if(index < 0){
uint8_t len, return tsl_rpt_err;
uint8_t *data) }else{
{ root_tmp = kk_check_identify(g_tsl_zigbee_map_glb[index].map.Identity,root,index,status);
int i,j,num,status; if(root_tmp != NULL){
char macString[19] = {0}; kk_rpc_report_status(root_tmp,mac);
sub_dev_node_t *node = NULL; //rpc_cJSON_Delete(root_tmp);
int res = 0; return tsl_rpt_success;
}
UTIL_LOG_INFO("\n********************kk tsl report attribute********************\n"); else{
emberAfDebugPrint("mac:"); Identify = g_tsl_zigbee_map_glb[index].map.Identity;
emberAfDebugPrintln(",ep:%d,clu:0x%04X,attr:0x%04X,dataType=0x%02x,len=%d,data:", }
EP,clusterId,attributeId,dataType,len); }
emberAfDebugPrintBuffer(data,len,true); }else{
root_tmp = kk_check_identify(g_tsl_zigbee_map[index].Identity,root,index,status);
num = kk_get_tsl_num(); if(root_tmp != NULL){
for(i=0;i<num;i++){ kk_rpc_report_status(root_tmp,mac);
if( g_tsl_zigbee_map[i].clusterId == clusterId && //rpc_cJSON_Delete(root_tmp);
g_tsl_zigbee_map[i].attributeId == attributeId && return tsl_rpt_success;
g_tsl_zigbee_map[i].zigbee_report!=NULL){ }
status = g_tsl_zigbee_map[i].zigbee_report(eui64,EP,clusterId,attributeId,dataType,len,data); else{
emberAfDebugPrintln("report status:%s",kk_tsl_rpt_status_string[status]); Identify = g_tsl_zigbee_map[index].Identity;
return ; }
} }
} rpc_cJSON_AddNumberToObject(root, Identify,status);
rpc_eui64ToString(eui64,macString); kk_rpc_report_status(root,mac);
res = kk_sub_tsl_get_device_by_mac(macString,&node); //rpc_cJSON_Delete(root);
if(res != tsl_rpt_success){ return tsl_rpt_success;
emberAfAppPrintln("[kk_tsl_report_attribute] error~~~~~~~~~\n"); }
return;
}
num = kk_get_tsl_glb_num(); void kk_tsl_report_attribute(EmberEUI64 eui64,
for(i=0;i<num;i++){ uint8_t EP,
if( g_tsl_zigbee_map_glb[i].map.clusterId == clusterId && EmberAfClusterId clusterId,
g_tsl_zigbee_map_glb[i].map.attributeId == attributeId && EmberAfAttributeId attributeId,
strncmp(node->productCode,g_tsl_zigbee_map_glb[i].ProductCode,strlen(node->productCode)) == 0 && uint8_t dataType,
g_tsl_zigbee_map_glb[i].map.zigbee_report!=NULL){ uint8_t len,
status = g_tsl_zigbee_map_glb[i].map.zigbee_report(eui64,EP,clusterId,attributeId,dataType,len,data); uint8_t *data)
emberAfDebugPrintln("--report status:%s",kk_tsl_rpt_status_string[status]); {
return ; int i,j,num,status;
} char macString[19] = {0};
} sub_dev_node_t *node = NULL;
} int res = 0;
UTIL_LOG_INFO("\n********************kk tsl report attribute********************\n");
int kk_tsl_report_global_onoff(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data) emberAfDebugPrint("mac:");
{ emberAfDebugPrintln(",ep:%d,clu:0x%04X,attr:0x%04X,dataType=0x%02x,len=%d,data:",
uint8_t OnOff; EP,clusterId,attributeId,dataType,len);
emberAfAppPrintln("[tsl report:Gloabl] OnOff~~~~~~~~~"); emberAfDebugPrintBuffer(data,len,true);
if(dataType == ZCL_BOOLEAN_ATTRIBUTE_TYPE){
if(len==1){ num = kk_get_tsl_num();
OnOff = data[0]; for(i=0;i<num;i++){
if(OnOff==0 || OnOff==1){ if( g_tsl_zigbee_map[i].clusterId == clusterId &&
kk_tsl_report(eui64,EP,OnOff,clusterId,attributeId); g_tsl_zigbee_map[i].attributeId == attributeId &&
return tsl_rpt_success; g_tsl_zigbee_map[i].zigbee_report!=NULL){
} status = g_tsl_zigbee_map[i].zigbee_report(eui64,EP,clusterId,attributeId,dataType,len,data);
return tsl_rpt_invaild_val; emberAfDebugPrintln("report status:%s",kk_tsl_rpt_status_string[status]);
} return ;
return tsl_rpt_invaild_len; }
} }
return tsl_rpt_invaild_type; rpc_eui64ToString(eui64,macString);
} res = kk_sub_tsl_get_device_by_mac(macString,&node);
if(res != tsl_rpt_success){
int kk_tsl_report_windowCovering_mode(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data) emberAfAppPrintln("[kk_tsl_report_attribute] error~~~~~~~~~\n");
{ return;
uint8_t mode; }
emberAfAppPrintln("[tsl report:Window Covering] Mode~~~~~~~~~");
num = kk_get_tsl_glb_num();
if(dataType == ZCL_BITMAP8_ATTRIBUTE_TYPE){ for(i=0;i<num;i++){
if(len==1){ if( g_tsl_zigbee_map_glb[i].map.clusterId == clusterId &&
if(data[0]&BIT(1)){ g_tsl_zigbee_map_glb[i].map.attributeId == attributeId &&
mode = WC_calibration_mode; strncmp(node->productCode,g_tsl_zigbee_map_glb[i].ProductCode,strlen(node->productCode)) == 0 &&
}else if(data[0]&BIT(0)){ g_tsl_zigbee_map_glb[i].map.zigbee_report!=NULL){
mode = WC_reversed_dir; status = g_tsl_zigbee_map_glb[i].map.zigbee_report(eui64,EP,clusterId,attributeId,dataType,len,data);
}else{ emberAfDebugPrintln("--report status:%s",kk_tsl_rpt_status_string[status]);
mode = WC_normal_dir; return ;
} }
}
kk_tsl_report(eui64,EP,mode,clusterId,attributeId); }
return tsl_rpt_success;
}
return tsl_rpt_invaild_len; int kk_tsl_report_global_onoff(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data)
} {
return tsl_rpt_invaild_type; uint8_t OnOff;
} emberAfAppPrintln("[tsl report:Gloabl] OnOff~~~~~~~~~");
int kk_tsl_report_windowCovering_position(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data) if(dataType == ZCL_BOOLEAN_ATTRIBUTE_TYPE){
{ if(len==1){
uint8_t position; OnOff = data[0];
emberAfAppPrintln("[tsl report:Window Covering] Position~~~~~~~~~"); if(OnOff==0 || OnOff==1){
kk_tsl_report(eui64,EP,OnOff,clusterId,attributeId);
if(dataType == ZCL_INT8U_ATTRIBUTE_TYPE){ return tsl_rpt_success;
if(len==1){ }
position = data[0]; return tsl_rpt_invaild_val;
kk_tsl_report(eui64,EP,position,clusterId,attributeId); }
return tsl_rpt_success; return tsl_rpt_invaild_len;
} }
return tsl_rpt_invaild_len; return tsl_rpt_invaild_type;
} }
return tsl_rpt_invaild_type;
} int kk_tsl_report_windowCovering_mode(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data)
{
uint8_t mode;
emberAfAppPrintln("[tsl report:Window Covering] Mode~~~~~~~~~");
if(dataType == ZCL_BITMAP8_ATTRIBUTE_TYPE){
if(len==1){
if(data[0]&BIT(1)){
mode = WC_calibration_mode;
}else if(data[0]&BIT(0)){
mode = WC_reversed_dir;
}else{
mode = WC_normal_dir;
}
kk_tsl_report(eui64,EP,mode,clusterId,attributeId);
return tsl_rpt_success;
}
return tsl_rpt_invaild_len;
}
return tsl_rpt_invaild_type;
}
int kk_tsl_report_windowCovering_position(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data)
{
uint8_t position;
emberAfAppPrintln("[tsl report:Window Covering] Position~~~~~~~~~");
if(dataType == ZCL_INT8U_ATTRIBUTE_TYPE){
if(len==1){
position = data[0];
kk_tsl_report(eui64,EP,position,clusterId,attributeId);
return tsl_rpt_success;
}
return tsl_rpt_invaild_len;
}
return tsl_rpt_invaild_type;
}
...@@ -40,11 +40,32 @@ cJSON *kk_topo_change_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJS ...@@ -40,11 +40,32 @@ cJSON *kk_topo_change_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJS
error_return: error_return:
return rpc_cJSON_CreateNull(); return rpc_cJSON_CreateNull();
} }
int kk_tsl_utils_memtok(_IN_ char *input, _IN_ char delimiter, _IN_ int index, _OU_ int *offset)
{
int item_index = 0;
int count = 0;
int input_len = 0;
if (input == NULL || offset == NULL) {
return -1;
}
input_len = strlen(input);
for (item_index = 0; item_index < input_len; item_index++) {
if (input[item_index] == delimiter && (item_index + 1) < input_len) {
count++;
if (count == index) {
*offset = item_index;
return 0;
}
}
}
return -1;
}
cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac) cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac)
{ {
sub_dev_node_t *node = NULL; sub_dev_node_t *node = NULL;
int res = 0; int res = 0,rev = 0;
rpc_nwk_info_s info; rpc_nwk_info_s info;
EmberStatus status; EmberStatus status;
int index = 0; int index = 0;
...@@ -52,8 +73,11 @@ cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJ ...@@ -52,8 +73,11 @@ cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJ
int num; int num;
uint8_t findFlag = 0xff; uint8_t findFlag = 0xff;
cJSON *propertyItem = NULL; cJSON *propertyItem = NULL;
cJSON *propertyItem1 = NULL;
EmberEUI64 eui64; EmberEUI64 eui64;
EmberNodeId nodeId = EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID; EmberNodeId nodeId = EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID;
int startIdx = 0;
char tmp_Identity[64] = {0};
UTIL_LOG_INFO("\n********************kk tsl property operation********************\n"); UTIL_LOG_INFO("\n********************kk tsl property operation********************\n");
if(params == NULL){ if(params == NULL){
...@@ -69,19 +93,53 @@ cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJ ...@@ -69,19 +93,53 @@ cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJ
num = kk_get_tsl_num(); num = kk_get_tsl_num();
for(index = 0; index < num; index++){ for(index = 0; index < num; index++){
propertyItem = rpc_cJSON_GetObjectItem(params, g_tsl_zigbee_map[index].Identity); rev = kk_tsl_utils_memtok(g_tsl_zigbee_map[index].Identity,".",1,&startIdx);
if(propertyItem != NULL){ if(!rev){
findFlag = 1; memset(tmp_Identity,0x0,sizeof(tmp_Identity));
break; memcpy(tmp_Identity, g_tsl_zigbee_map[index].Identity, startIdx);
propertyItem1 = rpc_cJSON_GetObjectItem(params,tmp_Identity);
if(propertyItem1 != NULL){
propertyItem = rpc_cJSON_GetObjectItem(propertyItem1,g_tsl_zigbee_map[index].Identity+startIdx+1);
if(propertyItem != NULL){
findFlag = 1;
break;
}
}
}
else{
propertyItem = rpc_cJSON_GetObjectItem(params, g_tsl_zigbee_map[index].Identity);
if(propertyItem != NULL){
findFlag = 1;
break;
}
} }
} }
if(findFlag==0xff){ if(findFlag==0xff){
num = kk_get_tsl_glb_num(); num = kk_get_tsl_glb_num();
for(index = 0; index < num; index++){ for(index = 0; index < num; index++){
propertyItem = rpc_cJSON_GetObjectItem(params, g_tsl_zigbee_map_glb[index].map.Identity); rev = kk_tsl_utils_memtok(g_tsl_zigbee_map_glb[index].map.Identity,".",1,&startIdx);
if(propertyItem != NULL){ if(!rev){
findFlag = 2; memset(tmp_Identity,0x0,sizeof(tmp_Identity));
break; memcpy(tmp_Identity, g_tsl_zigbee_map_glb[index].map.Identity, startIdx);
propertyItem1 = rpc_cJSON_GetObjectItem(params,tmp_Identity);
if(propertyItem1 != NULL){
propertyItem = rpc_cJSON_GetObjectItem(propertyItem1,g_tsl_zigbee_map_glb[index].map.Identity+startIdx+1);
if(propertyItem != NULL){
findFlag = 2;
break;
}
}
}
else{
propertyItem = rpc_cJSON_GetObjectItem(params, g_tsl_zigbee_map_glb[index].map.Identity);
if(propertyItem != NULL){
findFlag = 2;
break;
}
} }
} }
} }
......
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