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
......@@ -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