Commit a66362ff authored by 尹佳钦's avatar 尹佳钦

文件结构整理

parent f4929f7d
......@@ -281,8 +281,9 @@ APPLICATION_FILES= \
./ZB/zb_device_id.c\
./ZB/kk_device_manager.c\
./ZB/kk_product_code.c\
./ZB/kk_device_control.c\
./ZB/kk_zigbee_api.c\
./ZB/kk_tsl_property_report.c\
./ZB/kk_tsl_property_set.c\
./kk_test.c\
./kk_sub_tsl.c\
./kk_tsl_zigbee_map.c\
......
#ifndef __KK_DEVICE_CONTROL_H
#define __KK_DEVICE_CONTROL_H
#endif
......@@ -220,7 +220,7 @@ static void kk_device_table_load(void)
FILE *fp;
int i;
EmberEUI64 mac;
uint16_t nodeId;//to do:诡异
uint16_t nodeId;
uint16_t deviceId;
uint16_t len;
char pCode[33];
......
#include "kk_tsl_property_report.h"
const char *kk_tsl_rpt_status_string[] = {
"Success",
"Error",
"Invaild Value",
"Invaild Len",
"Invaild Type"
};
static int kk_tsl_report(EmberEUI64 mac,uint8_t EP,int status,uint16_t clusterId,uint16_t attributeId)
{
cJSON* root;
int index;
sub_dev_node_t *node = NULL;
char macString[RPC_EUI64_STRING_LENGTH];
rpc_eui64ToString(mac,macString);
root = rpc_cJSON_CreateObject();
index = kk_get_tsl_index(EP,clusterId,attributeId);
if(index < 0) return tsl_rpt_err;
rpc_cJSON_AddNumberToObject(root, g_tsl_zigbee_map[index].Identity,status);
kk_rpc_report_status(root,mac);
return tsl_rpt_success;
}
void kk_tsl_report_attribute(EmberEUI64 eui64,
uint8_t EP,
EmberAfClusterId clusterId,
EmberAfAttributeId attributeId,
uint8_t dataType,
uint8_t len,
uint8_t *data)
{
int i,j,num,status;
UTIL_LOG_INFO("\n********************kk tsl report attribute********************\n");
emberAfDebugPrint("mac:");
emberAfGetEui64(eui64);
emberAfPrintBigEndianEui64(eui64);
emberAfDebugPrintln(",ep:%d,clu:0x%04X,attr:0x%04X,dataType=0x%02x,len=%d,data:",
EP,clusterId,attributeId,dataType,len);
emberAfDebugPrintBuffer(data,len,true);
num = kk_get_tsl_num();
for(i=0;i<num;i++){
if( g_tsl_zigbee_map[i].clusterId == clusterId &&
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]);
return ;
}
}
}
int kk_tsl_report_global_onoff(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data)
{
uint8_t OnOff;
emberAfAppPrintln("[tsl report:Gloabl] OnOff~~~~~~~~~");
if(dataType == ZCL_BOOLEAN_ATTRIBUTE_TYPE){
if(len==1){
OnOff = data[0];
if(OnOff==0 || OnOff==1){
kk_tsl_report(eui64,EP,OnOff,clusterId,attributeId);
return tsl_rpt_success;
}
return tsl_rpt_invaild_val;
}
return tsl_rpt_invaild_len;
}
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;
}
#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
#include "kk_tsl_property_set.h"
//emberAfAppPrintln("[tsl report:Gloabl] OnOff~~~~~~~~~");
//cJSON *rpc_Control(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;
int res = 0;
rpc_nwk_info_s info;
EmberStatus status;
int index = 0;
int num;
cJSON *propertyItem = NULL;
EmberEUI64 eui64;
EmberNodeId nodeId = EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID;
UTIL_LOG_INFO("\n********************kk tsl property operation********************\n");
if(params == NULL){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}else{
res = kk_sub_tsl_get_device_by_mac(mac->valuestring, &node);
if (res != SUCCESS_RETURN) {
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
num = kk_get_tsl_num();
for(index = 0; index < num; index++){
propertyItem = rpc_cJSON_GetObjectItem(params, g_tsl_zigbee_map[index].Identity);
if(propertyItem != NULL)
{
int value = 0;
if(propertyItem->type != cJSON_Number){
value = rpc_get_u8(propertyItem->valuestring);
}else{
value = propertyItem->valueint;
}
if(rpc_get_mac(mac->valuestring,eui64)==false){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
nodeId = emberAfDeviceTableGetNodeIdFromEui64(eui64);
emberAfDebugPrint("mac:");
emberAfPrintBigEndianEui64(eui64);
emberAfDebugPrintln(",node:0x%04X",nodeId);
res = g_tsl_zigbee_map[index].zigbee_set(ctx,mac->valuestring,g_tsl_zigbee_map[index].endpoint,&value);
if(res < 0)
{
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
else{
return rpc_cJSON_CreateNumber(res);
}
}
}
}
error_return:
return rpc_cJSON_CreateNull();
}
int kk_tsl_set_windowCovering_OperationMode(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data)
{
uint8_t Operation = 0;
EmberStatus status = 0;
Operation = *(uint8_t*)data;
emberAfAppPrintln("[tsl set:Window Covering Operation Mode],mode=0x%02x",Operation);
if(node==EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID){
if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
if(Operation==0){
status = WindowCover_UpOpen(node,ep);
emberAfAppPrintln("Up/Open");
}else if(Operation==1){
status = WindowCover_DownClose(node,ep);
emberAfAppPrintln("Down/Close");
}else if(Operation==2){
status = WindowCover_Stop(node,ep);
emberAfAppPrintln("Stop");
}else{
if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
emberAfAppPrintln("status=0x%02x",status);
return status;
error_return:
return -1;
}
int kk_tsl_set_windowCovering_mode(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data)
{
uint8_t mode = 0;
uint8_t WCmode = 0;
EmberStatus status = 0;
mode = *(uint8_t*)data;
emberAfAppPrintln("[tsl set:Window Covering Run Mode],mode=0x%02x",mode);
if(mode==WC_calibration_mode){
WCmode |= BIT(1);
status = zclGWrite(node,1,ep,false,ZCL_WINDOW_COVERING_CLUSTER_ID,
ZCL_MODE_ATTRIBUTE_ID,
ZCL_BITMAP8_ATTRIBUTE_TYPE,
1,
WCmode,
true);
emberAfAppPrintln("Calibration Mode");
}else if(mode==WC_reversed_dir){
WCmode |= BIT(0);
status = zclGWrite(node,1,ep,false,ZCL_WINDOW_COVERING_CLUSTER_ID,
ZCL_MODE_ATTRIBUTE_ID,
ZCL_BITMAP8_ATTRIBUTE_TYPE,
1,
WCmode,
true);
emberAfAppPrintln("Dir:reversed");
}else if(mode==WC_normal_dir){
WCmode = 0;
status = zclGWrite(node,1,ep,false,ZCL_WINDOW_COVERING_CLUSTER_ID,
ZCL_MODE_ATTRIBUTE_ID,
ZCL_BITMAP8_ATTRIBUTE_TYPE,
1,
WCmode,
true);
emberAfAppPrintln("Dir:Normal");
}else{
if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
emberAfAppPrintln("status=0x%02x",status);
return status;
error_return:
return -1;
}
int kk_tsl_set_windowCovering_position(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data)
{
uint8_t position = 0;
EmberStatus status = 0;
position = *(uint8_t*)data;
emberAfAppPrintln("[tsl set:Window Covering Position],position=0x%02x",position);
status = WindowCover_GotoLiftPercentage(node,ep,position);
emberAfAppPrintln("status=0x%02x",status);
return status;
error_return:
return -1;
}
#ifndef __KK_TSL_PROPERTY_SET_H
#define __KK_TSL_PROPERTY_SET_H
#include "kk_test.h"
cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON * params, cJSON *id,cJSON *mac);
int kk_tsl_set_windowCovering_OperationMode(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
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);
#endif
......@@ -3,7 +3,7 @@
#include "kk_tsl_zigbee_map.h"
extern kk_tsl_zigbee_map_t g_tsl_zigbee_map [];
extern int kk_get_map_Num(void);
static void kk_rpc_send_message(cJSON *data,char *msgtype,char *method,EmberEUI64 mac)
{
......@@ -80,6 +80,9 @@ void kk_rpc_reportLeftDevices(EmberEUI64 mac)
kk_rpc_report_left_devices(devicesJson,testMac_GW);
kk_sub_tsl_delete(mac);
kk_device_table_delete(mac);
}
int kk_sendData2CCU(char* data, int len){
......@@ -123,49 +126,7 @@ void kk_rpc_reportDevices(EmberEUI64 mac,const char* productCode)
}
int kk_rpc_report_attribute_status(EmberEUI64 mac,uint8_t EP,int status,uint16_t clusterId,uint16_t attributeId)
{
cJSON* root;
int res = 0;
int num = 0;
int pCtrlIdx = 0;
uint8_t endpoint_tmp = 0;
uint16_t clusterId_tmp = 0;
uint16_t attributeId_tmp = 0;
int i = 0;
sub_dev_node_t *node = NULL;
char macString[RPC_EUI64_STRING_LENGTH];
rpc_eui64ToString(mac,macString);
root = rpc_cJSON_CreateObject();
res = kk_sub_tsl_get_device_by_mac(macString, &node);
if (res != SUCCESS_RETURN) {
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return -1;
}
pCtrlIdx = kk_find_ctrl_obj(node->productCode);
if(pCtrlIdx == -1){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return -1;
}
num = kk_get_Identity_Num(pCtrlIdx);
for(i = 0; i < num; i++)
{
clusterId_tmp = g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[i].clusterId;
attributeId_tmp = g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[i].attributeId;
endpoint_tmp = g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[i].endpoint;
if(endpoint_tmp == EP &&
clusterId_tmp == clusterId &&
attributeId_tmp == attributeId)
{
rpc_cJSON_AddNumberToObject(root, g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[i].Identity,status);
break;
}
}
kk_rpc_report_status(root,mac);
return 0;
}
int kk_zcl_onoff_set(jrpc_context * ctx,const char *mac,unsigned char ep,void* data)
{
uint8_t eui64[EUI64_SIZE];
......@@ -216,318 +177,14 @@ error_return:
//EmberStatus WindowCover_DownClose(uint16_t node,uint8_t ep);
//EmberStatus WindowCover_Stop(uint16_t node,uint8_t ep);
int kk_zcl_windowCovering_OperationMode_set(jrpc_context * ctx,const char *mac,unsigned char ep,void* data)
{
uint8_t eui64[EUI64_SIZE];
uint8_t Operation = 0;
EmberStatus status = 0;
EmberNodeId node = 0xffff;
Operation = *(uint8_t*)data;
bool macMatch= rpc_get_mac(mac,eui64);
emberAfCorePrintBuffer(eui64,EUI64_SIZE,true);
for(int i=0;i<EUI64_SIZE;i++){
emberAfCorePrintln("i=%d,val=%02x",i,eui64[i]);
}
if(macMatch){
node = emberAfDeviceTableGetNodeIdFromEui64(eui64);
if(node==0xffff){
emberAfCorePrintln("\r\n not find device by node!\r\n" );
if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
emberAfCorePrintln("\r\nnode=0x%02X,ep=%d,OnOffStatus=%d\r\n",node,ep,Operation);
if(Operation==0){
status = WindowCover_UpOpen(node,ep);
emberAfCorePrintln("\r\nUp/Open,status=0x%x\r\n",status);
}else if(Operation==1){
status = WindowCover_DownClose(node,ep);
emberAfCorePrintln("\r\nDown/Close,status=0x%x\r\n",status);
}else if(Operation==2){
status = WindowCover_Stop(node,ep);
emberAfCorePrintln("\r\nStop,status=0x%x\r\n",status);
}else{
if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
}else{
emberAfCorePrintln("\r\n not find device by mac!\r\n" );
if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
return status;
error_return:
return -1;
}
int kk_zcl_windowCovering_mode_set(jrpc_context * ctx,const char *mac,unsigned char ep,void* data)
{
uint8_t eui64[EUI64_SIZE];
uint8_t mode = 0;
uint8_t WCmode = 0;
EmberStatus status = 0;
EmberNodeId node = 0xffff;
mode = *(uint8_t*)data;
bool macMatch= rpc_get_mac(mac,eui64);
emberAfCorePrintBuffer(eui64,EUI64_SIZE,true);
for(int i=0;i<EUI64_SIZE;i++){
emberAfCorePrintln("i=%d,val=%02x",i,eui64[i]);
}
if(macMatch){
node = emberAfDeviceTableGetNodeIdFromEui64(eui64);
if(node==0xffff){
emberAfCorePrintln("\r\n not find device by node!\r\n" );
if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
emberAfCorePrintln("\r\nnode=0x%02X,ep=%d,mode=%d\r\n",node,ep,mode);
if(mode==WC_calibration_mode){
WCmode |= BIT(1);
status = zclGWrite(node,1,ep,false,ZCL_WINDOW_COVERING_CLUSTER_ID,
ZCL_MODE_ATTRIBUTE_ID,
ZCL_BITMAP8_ATTRIBUTE_TYPE,
1,
WCmode,
true);
emberAfCorePrintln("\r\nWC_normal_dir\r\n" );
}else if(mode==WC_reversed_dir){
WCmode |= BIT(0);
status = zclGWrite(node,1,ep,false,ZCL_WINDOW_COVERING_CLUSTER_ID,
ZCL_MODE_ATTRIBUTE_ID,
ZCL_BITMAP8_ATTRIBUTE_TYPE,
1,
WCmode,
true);
emberAfCorePrintln("\r\nWC_reversed_dir\r\n" );
}else if(mode==WC_normal_dir){
WCmode = 0;
status = zclGWrite(node,1,ep,false,ZCL_WINDOW_COVERING_CLUSTER_ID,
ZCL_MODE_ATTRIBUTE_ID,
ZCL_BITMAP8_ATTRIBUTE_TYPE,
1,
WCmode,
true);
emberAfCorePrintln("\r\nWC_normal_dir\r\n" );
}else{
if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
}else{
emberAfCorePrintln("\r\n not find device by mac!\r\n" );
if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
return status;
error_return:
return -1;
}
int kk_zcl_windowCovering_position_set(jrpc_context * ctx,const char *mac,unsigned char ep,void* data)
{
uint8_t eui64[EUI64_SIZE];
uint8_t position = 0;
EmberStatus status = 0;
EmberNodeId node = 0xffff;
position = *(uint8_t*)data;
bool macMatch= rpc_get_mac(mac,eui64);
emberAfCorePrintBuffer(eui64,EUI64_SIZE,true);
for(int i=0;i<EUI64_SIZE;i++){
emberAfCorePrintln("i=%d,val=%02x",i,eui64[i]);
}
if(macMatch){
node = emberAfDeviceTableGetNodeIdFromEui64(eui64);
if(node==0xffff){
emberAfCorePrintln("\r\n not find device by node!\r\n" );
if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
emberAfCorePrintln("\r\nnode=0x%02X,ep=%d,position=%d\r\n",node,ep,position);
status = WindowCover_GotoLiftPercentage(node,ep,position);
emberAfCorePrintln("status=0x%x",status);
}else{
emberAfCorePrintln("\r\n not find device by mac!\r\n" );
if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
return status;
error_return:
return -1;
}
#if 0
int kk_test_fuc(char *mac,const char *params)
{
sub_dev_node_t *node = NULL;
int res = 0;
int pCtrlIdx = 0;
int num =0;
int index = 0;
cJSON *propertyItem = NULL;
cJSON *root;
root=cJSON_Parse((char*)params);
res = kk_sub_tsl_get_device_by_mac(mac, &node);
if (res != SUCCESS_RETURN) {
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
}
printf("[%s][%d]node->product_type:%s\n",__FUNCTION__,__LINE__,node->product_type);
pCtrlIdx = kk_find_ctrl_obj(node->product_type);
if(pCtrlIdx == -1){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
num = kk_get_Identity_Num(pCtrlIdx);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
for(index = 0; index < num; index++){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
printf("[%s][%d]------->%s\n",__FUNCTION__,__LINE__,g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].Identity);
//kk_sub_tsl_get_Identifier_by_index(mac,index,&identifier);
propertyItem = rpc_cJSON_GetObjectItem(root, g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].Identity);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if(propertyItem != NULL)
{
int value = rpc_get_u8(propertyItem->valuestring);
printf("[%s][%d]value:%d\n",__FUNCTION__,__LINE__,value);
res = g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].zigbee_set(NULL,mac,&value);
if(res < 0)
{
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return -1;
}
else{
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return 0;
}
}
}
return 0;
}
#endif
cJSON *rpc_read_attribue(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac)
{
rpc_nwk_info_s info;
EmberStatus status;
int num = 0,index = 0;
cJSON *propertyItem = NULL;
sub_dev_node_t *node = NULL;
int pCtrlIdx = 0;
int res = 0,ret = 0;
if(params == NULL){
emberAfCorePrintln("\r\nparams == NULL\r\n" );
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}else{
res = kk_sub_tsl_get_device_by_mac(mac->valuestring, &node);
if (res != SUCCESS_RETURN) {
goto error_return;
}
pCtrlIdx = kk_find_ctrl_obj(node->productCode);
if(pCtrlIdx < SUCCESS_RETURN){
goto error_return;
}
num = kk_get_Identity_Num(pCtrlIdx);
for(index = 0; index < num; index++){
propertyItem = rpc_cJSON_GetObjectItem(params, g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].Identity);
if(propertyItem != NULL)
{
int value = rpc_get_u8(propertyItem->valuestring);
res = g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].zigbee_set(ctx,mac->valuestring,g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].endpoint,&value);
if(ret < 0)
{
goto error_return;
}
else{
return rpc_cJSON_CreateNumber(ret);
}
}
}
}
error_return:
return rpc_cJSON_CreateNull();
}
cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac)
{
sub_dev_node_t *node = NULL;
int res = 0;
int num = 0;
int pCtrlIdx = 0;
rpc_nwk_info_s info;
EmberStatus status;
int index = 0;
cJSON *propertyItem = NULL;
if(params == NULL){
emberAfCorePrintln("\r\nparams == NULL\r\n" );
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}else{
res = kk_sub_tsl_get_device_by_mac(mac->valuestring, &node);
if (res != SUCCESS_RETURN) {
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
pCtrlIdx = kk_find_ctrl_obj(node->productCode);
if(pCtrlIdx == -1){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
num = kk_get_Identity_Num(pCtrlIdx);
for(index = 0; index < num; index++){
propertyItem = rpc_cJSON_GetObjectItem(params, g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].Identity);
if(propertyItem != NULL)
{
int value = 0;
if(propertyItem->type != cJSON_Number){
value = rpc_get_u8(propertyItem->valuestring);
}else{
value = propertyItem->valueint;
}
res = g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].zigbee_set(ctx,mac->valuestring,g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].endpoint,&value);
if(res < 0)
{
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
else{
return rpc_cJSON_CreateNumber(res);
}
}
}
}
error_return:
return rpc_cJSON_CreateNull();
}
int rpc_nwkPermitJoin(jrpc_context * ctx,const char *mac,unsigned char ep,void* data)
{
......@@ -584,64 +241,7 @@ void kk_network_check(void)
int kk_report_global_onoff_attribute(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data)
{
emberAfAppPrintln("kk_report_global_onoff_attribute");
uint8_t OnOff;
if(dataType == ZCL_BOOLEAN_ATTRIBUTE_TYPE){
if(len==1){
OnOff = data[0];
if(OnOff==0||OnOff==1){//todo:
kk_rpc_report_attribute_status(eui64,EP,OnOff,clusterId,attributeId);
return 0;
}
return -1;
}
return -2;
}
return -3;
}
int kk_report_windowCovering_mode_attribute(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data)
{
emberAfAppPrintln("kk_report_windowCovering_mode_attribute");
uint8_t 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_rpc_report_attribute_status(eui64,EP,mode,clusterId,attributeId);
return 0;
}
return -2;
}
return -3;
}
int kk_report_windowCovering_position_attribute(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data)
{
emberAfAppPrintln("kk_report_windowCovering_mode_attribute");
uint8_t position;
if(dataType == ZCL_INT8U_ATTRIBUTE_TYPE){
if(len==1){
position = data[0];
kk_rpc_report_attribute_status(eui64,EP,position,clusterId,attributeId);
return 0;
}
return -2;
}
return -3;
}
......@@ -662,56 +262,5 @@ void emberAfMainTickCallback(void)
}
void kk_dispatch_report_attribute(EmberEUI64 eui64,
uint8_t EP,
EmberAfClusterId clusterId,
EmberAfAttributeId attributeId,
uint8_t dataType,
uint8_t len,
uint8_t *data)
{
emberAfAppPrintln("kk_dispatch_report_attribute");
int i,j,result;
int map_num,property_num;
kk_tsl_zigbee_map_t *device_item;
kk_zigbee_ctrl_map_t *report_item;
map_num = kk_get_map_Num();
emberAfAppPrintln("map_num=%d",map_num);
for(i=0;i<map_num;i++){
emberAfAppPrintln("i=%d",i);
device_item = &g_tsl_zigbee_map[i];
if(device_item != NULL){
report_item = &device_item->zigbee_ctrl;
if(report_item==NULL){
emberAfAppPrintln("not find in map table-2");
return;
}
}else{
emberAfAppPrintln("not find in map table-1");
return;
}
property_num = (device_item->num>PROPERTIES_MAX_NUM)?PROPERTIES_MAX_NUM:device_item->num;
for(j=0;j<property_num;j++){
emberAfAppPrintln("i=%d,j=%d,num=%d",i,j,device_item->num);
if(report_item[j].clusterId == clusterId &&
report_item[j].attributeId == attributeId){
if(report_item[j].zigbee_report!=NULL){
result = report_item[j].zigbee_report(eui64,EP,clusterId,attributeId,dataType,len,data);
if(!result){
emberAfAppPrintln("result=%d",result);
emberAfAppPrintln("mac:");
emberAfPrintBigEndianEui64(eui64);
emberAfAppPrintln(",ep=%d,clu=0x%x,attr=0x%x,type=0x%x,len=%d",EP,clusterId,attributeId,dataType,len);
emberAfAppPrintBuffer(data,len,true);
}
return ;
}
}
}
}
emberAfAppPrintln("not find report item!!!ep=%d,clu=0x%x,attr=0x%x\n",EP,clusterId,attributeId);
}
......@@ -8,6 +8,8 @@
#include "zb_device_id.h"
#include "kk_device_manager.h"
#include "kk_zigbee_api.h"
#include "kk_tsl_property_report.h"
#include "kk_tsl_property_set.h"
#define KK_REPORT_DEVICE_JOINED_TYPE "/thing/topo/add"
#define KK_REPORT_DEVICE_LEFT_TYPE "/thing/topo/delete"
......@@ -26,28 +28,12 @@
#define GW_DEVICE_CODE "1122334455667788"
#define KK_EP(x) (x)
#define KK_DUMMY_EP KK_EP(0)
#define KK_PRIMARY_EP KK_EP(1)
#define KK_DUMMY_CLUSTER_ID 0xffff
#define KK_DUMMY_ATTRIBUTE_ID 0xffff
cJSON *rpc_Control(jrpc_context * ctx, cJSON * params, cJSON *id,cJSON *mac);
cJSON *rpc_read_attribue(jrpc_context * ctx, cJSON * params, cJSON *id,cJSON *mac);
int kk_zcl_onoff_set(jrpc_context * ctx,const char *mac,unsigned char ep,void* data);
int kk_zcl_windowCovering_OperationMode_set(jrpc_context * ctx,const char *mac,unsigned char ep,void* data);
int kk_zcl_windowCovering_mode_set(jrpc_context * ctx,const char *mac,unsigned char ep,void* data);
int kk_zcl_windowCovering_position_set(jrpc_context * ctx,const char *mac,unsigned char ep,void* data);
int kk_report_global_onoff_attribute(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data);
int kk_report_windowCovering_mode_attribute(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data);
int kk_report_windowCovering_position_attribute(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data);
......@@ -57,18 +43,12 @@ int kk_sendData2CCU(char* data, int len);
int rpc_nwkPermitJoin(jrpc_context * ctx,const char *mac,unsigned char ep,void* data);
void kk_dispatch_report_attribute(EmberEUI64 eui64,
uint8_t EP,
EmberAfClusterId clusterId,
EmberAfAttributeId attributeId,
uint8_t dataType,
uint8_t len,
uint8_t *data);
#define RPC_KK_TEST_FUNCTION_TABLE \
{(rpc_function*)rpc_Control,"/thing/service/property/set"},\
{(rpc_function*)rpc_Control,KK_READ_ATTRIBUTE_METHOD}
{(rpc_function*)kk_tsl_property_operation,"/thing/service/property/set"},\
{(rpc_function*)kk_tsl_property_operation,KK_READ_ATTRIBUTE_METHOD}
......
......@@ -3,44 +3,28 @@
#include "kk_product_code.h"
kk_tsl_zigbee_map_t g_tsl_zigbee_map [] = {
{
ZIGBEE_COO_PRODUCT_CODE,
1,
{
{KK_TSL_DATA_TYPE_TEXT,"NetChannelState",KK_DUMMY_EP,rpc_nwkPermitJoin,0,0,NULL},
}
},
{
TEST_PRODUCT_CODE,
3,
{
{KK_TSL_DATA_TYPE_TEXT,"OperationMode",KK_PRIMARY_EP,kk_zcl_windowCovering_OperationMode_set,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID,kk_report_global_onoff_attribute},//开
{KK_TSL_DATA_TYPE_TEXT,"WorkMode",KK_PRIMARY_EP,kk_zcl_windowCovering_mode_set,ZCL_WINDOW_COVERING_CLUSTER_ID,ZCL_MODE_ATTRIBUTE_ID,kk_report_windowCovering_mode_attribute},
{KK_TSL_DATA_TYPE_TEXT,"Position",KK_PRIMARY_EP,kk_zcl_windowCovering_position_set,ZCL_WINDOW_COVERING_CLUSTER_ID,ZCL_CURRENT_LIFT_PERCENTAGE_ATTRIBUTE_ID,kk_report_windowCovering_position_attribute},
}
},
kk_tsl_zigbee_map_t g_tsl_zigbee_map[] = {
{"NetChannelState",KK_DUMMY_EP,rpc_nwkPermitJoin,0xffff,0xffff,NULL},
{"OperationMode",KK_PRIMARY_EP,kk_tsl_set_windowCovering_OperationMode,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID,kk_tsl_report_global_onoff},//开
{"WorkMode",KK_PRIMARY_EP,kk_tsl_set_windowCovering_mode,ZCL_WINDOW_COVERING_CLUSTER_ID,ZCL_MODE_ATTRIBUTE_ID,kk_tsl_report_windowCovering_mode},
{"Position",KK_PRIMARY_EP,kk_tsl_set_windowCovering_position,ZCL_WINDOW_COVERING_CLUSTER_ID,ZCL_CURRENT_LIFT_PERCENTAGE_ATTRIBUTE_ID,kk_tsl_report_windowCovering_position},
};
int kk_find_ctrl_obj(const char *productCode)
int kk_get_tsl_index(unsigned char EP,unsigned short clusterId,unsigned short attributeId)
{
int map_num = sizeof(g_tsl_zigbee_map) / sizeof(kk_tsl_zigbee_map_t);
int index = 0;
for(index = 0;index < map_num; index++)
{
if(!strcmp(productCode,g_tsl_zigbee_map[index].productCode))
{
return index;
int i;
for(i=0;i<sizeof(g_tsl_zigbee_map)/sizeof(kk_tsl_zigbee_map_t);i++){
if( EP == g_tsl_zigbee_map[i].endpoint &&
clusterId == g_tsl_zigbee_map[i].clusterId &&
attributeId == g_tsl_zigbee_map[i].attributeId){
return i;
}
}
return -1;
}
int kk_get_Identity_Num(int index)
{
return g_tsl_zigbee_map[index].num;
}
int kk_get_map_Num(void)
int kk_get_tsl_num(void)
{
return sizeof(g_tsl_zigbee_map) / sizeof(kk_tsl_zigbee_map_t);
}
......
......@@ -3,25 +3,31 @@
#include "RPC_API.h"
#include "kk_tsl_common.h"
#define PROPERTIES_MAX_NUM 20
#define KK_EP(x) (x)
typedef int (*zigbee_property_set)(jrpc_context * ctx,const char *mac,unsigned char ep,void* data);
#define KK_DUMMY_EP KK_EP(0)
#define KK_PRIMARY_EP KK_EP(1)
#define KK_DUMMY_CLUSTER_ID 0xffff
#define KK_DUMMY_ATTRIBUTE_ID 0xffff
typedef int (*zigbee_property_set)(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
typedef int(*kk_zigbee_property_report)(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data);
typedef struct{
int type;
char* Identity;
unsigned char endpoint;
zigbee_property_set zigbee_set;
unsigned short clusterId;
unsigned short attributeId;
kk_zigbee_property_report zigbee_report;
}kk_zigbee_ctrl_map_t;
typedef struct{
char *productCode;
int num;
kk_zigbee_ctrl_map_t zigbee_ctrl[PROPERTIES_MAX_NUM];
}kk_tsl_zigbee_map_t;
extern kk_tsl_zigbee_map_t g_tsl_zigbee_map[];
int kk_get_tsl_index(unsigned char EP,unsigned short clusterId,unsigned short attributeId);
int kk_get_tsl_num(void);
#endif
......@@ -632,7 +632,7 @@ bool rpc_ReportAttributesCallback(EmberAfClusterId clusterId,
if(emberAfDeviceTableGetEui64FromNodeId(nodeId,nodeEui64)){
emberAfAppPrintln("nodeId=0x%x",nodeId);
kk_dispatch_report_attribute(nodeEui64,ep,clusterId,attributeId,dataType,dataLen,dataPtr);
kk_tsl_report_attribute(nodeEui64,ep,clusterId,attributeId,dataType,dataLen,dataPtr);
}
......
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