Commit 029f91c1 authored by 尹佳钦's avatar 尹佳钦

12

parent f7c22541
...@@ -222,7 +222,7 @@ int kk_zcl_windowCovering_OperationMode_set(jrpc_context * ctx,const char *mac,u ...@@ -222,7 +222,7 @@ int kk_zcl_windowCovering_OperationMode_set(jrpc_context * ctx,const char *mac,u
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS); set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return; goto error_return;
} }
emberAfCorePrintln("\r\nnode=0x%02X,ep=%d,OnOffStatus=%d\r\n",node,ep,OnOffStatus); emberAfCorePrintln("\r\nnode=0x%02X,ep=%d,OnOffStatus=%d\r\n",node,ep,Operation);
if(Operation==0){ if(Operation==0){
status = WindowCover_UpOpen(node,ep); status = WindowCover_UpOpen(node,ep);
...@@ -252,11 +252,12 @@ error_return: ...@@ -252,11 +252,12 @@ error_return:
int kk_zcl_windowCovering_mode_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)
{ {
uint8_t eui64[EUI64_SIZE]; uint8_t eui64[EUI64_SIZE];
uint8_t OnOffStatus = 0; uint8_t mode = 0;
uint8_t WCmode = 0;
EmberStatus status = 0; EmberStatus status = 0;
EmberNodeId node = 0xffff; EmberNodeId node = 0xffff;
OnOffStatus = *(uint8_t*)data; mode = *(uint8_t*)data;
bool macMatch= rpc_get_mac(mac,eui64); bool macMatch= rpc_get_mac(mac,eui64);
emberAfCorePrintBuffer(eui64,EUI64_SIZE,true); emberAfCorePrintBuffer(eui64,EUI64_SIZE,true);
for(int i=0;i<EUI64_SIZE;i++){ for(int i=0;i<EUI64_SIZE;i++){
...@@ -272,14 +273,36 @@ int kk_zcl_windowCovering_mode_set(jrpc_context * ctx,const char *mac,unsigned c ...@@ -272,14 +273,36 @@ int kk_zcl_windowCovering_mode_set(jrpc_context * ctx,const char *mac,unsigned c
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS); set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return; goto error_return;
} }
emberAfCorePrintln("\r\nnode=0x%02X,ep=%d,OnOffStatus=%d\r\n",node,ep,OnOffStatus); emberAfCorePrintln("\r\nnode=0x%02X,ep=%d,mode=%d\r\n",node,ep,mode);
if(OnOffStatus==1){ if(mode==WC_calibration_mode){
status = zclOnOff_On(node,ep); WCmode |= BIT(1);
emberAfCorePrintln("\r\nzclOnOff_On\r\n" );
}else if(OnOffStatus==0){ status = zclGWrite(node,1,ep,false,ZCL_WINDOW_COVERING_CLUSTER_ID,
status = zclOnOff_Off(node,ep); ZCL_MODE_ATTRIBUTE_ID,
emberAfCorePrintln("\r\nzclOnOff_Off\r\n" ); 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{ }else{
if(ctx) if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS); set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
...@@ -563,11 +586,7 @@ int kk_report_global_onoff_attribute(EmberEUI64 eui64,uint8_t EP,EmberAfClusterI ...@@ -563,11 +586,7 @@ int kk_report_global_onoff_attribute(EmberEUI64 eui64,uint8_t EP,EmberAfClusterI
} }
enum {
WC_normal_dir = 0,//"正转"
WC_reversed_dir = 1,//"反转"
WC_calibration_mode = 2,//"校验"
}windowCoveringMode;
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_mode_attribute(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data)
{ {
uint8_t mode; uint8_t mode;
...@@ -591,9 +610,9 @@ int kk_report_windowCovering_mode_attribute(EmberEUI64 eui64,uint8_t EP,EmberAfC ...@@ -591,9 +610,9 @@ int kk_report_windowCovering_mode_attribute(EmberEUI64 eui64,uint8_t EP,EmberAfC
int kk_report_windowCovering_position_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)
{ {
uint8_t position; uint8_t position;
if(dataType == ZCL_INT16U_ATTRIBUTE_TYPE){ if(dataType == ZCL_INT8U_ATTRIBUTE_TYPE){
if(len==2){ if(len==1){
position = HIGH_LOW_TO_INT(data[1], data[0]); position = data[0];
kk_rpc_report_attribute_status(eui64,EP,position,clusterId,attributeId); kk_rpc_report_attribute_status(eui64,EP,position,clusterId,attributeId);
return 0; return 0;
...@@ -604,20 +623,6 @@ int kk_report_windowCovering_position_attribute(EmberEUI64 eui64,uint8_t EP,Embe ...@@ -604,20 +623,6 @@ int kk_report_windowCovering_position_attribute(EmberEUI64 eui64,uint8_t EP,Embe
} }
typedef int(*kk_rpc_report_attr_func)(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data);
typedef struct{
EmberAfClusterId clusterId;
EmberAfAttributeId attributeId;
kk_rpc_report_attr_func func;
}kk_rpc_report_map_s;
static kk_rpc_report_map_s kk_report_map[]={
{ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID,kk_report_global_onoff_attribute},
{ZCL_WINDOW_COVERING_CLUSTER_ID,ZCL_MODE_ATTRIBUTE_ID,kk_report_windowCovering_mode_attribute},
{ZCL_WINDOW_COVERING_CLUSTER_ID,ZCL_CURRENT_LIFT_ATTRIBUTE_ID,}
};
void kk_dispatch_report_attribute(EmberEUI64 eui64, void kk_dispatch_report_attribute(EmberEUI64 eui64,
uint8_t EP, uint8_t EP,
EmberAfClusterId clusterId, EmberAfClusterId clusterId,
...@@ -626,21 +631,25 @@ void kk_dispatch_report_attribute(EmberEUI64 eui64, ...@@ -626,21 +631,25 @@ void kk_dispatch_report_attribute(EmberEUI64 eui64,
uint8_t len, uint8_t len,
uint8_t *data) uint8_t *data)
{ {
int i,num,result; int i,j,result;
num = sizeof(kk_report_map)/sizeof(kk_rpc_report_map_s); kk_tsl_zigbee_map_t *device_item;
kk_rpc_report_map_s *report_item = kk_report_map; kk_zigbee_ctrl_map_t *report_item;
for(i=0;i<num;i++,report_item++){ for(i=0;i<PROPERTIES_MAX_NUM;i++){
if(report_item->clusterId==clusterId && device_item = &g_tsl_zigbee_map[i];
report_item->attributeId == attributeId){ report_item = &device_item[i].zigbee_ctrl;
result = report_item->func(eui64,EP,clusterId,attributeId,dataType,len,data); for(j=0;j<device_item[i].num;j++){
if(!result){ if(report_item[j].clusterId == clusterId &&
emberAfAppPrintln("result=%d",result); report_item[j].attributeId == attributeId){
emberAfAppPrintln("mac:"); result = report_item[j].zigbee_report(eui64,EP,clusterId,attributeId,dataType,len,data);
emberAfPrintBigEndianEui64(eui64); if(!result){
emberAfAppPrintln(",ep=%d,clu=0x%x,attr=0x%x,type=0x%x,len=%d",EP,clusterId,attributeId,dataType,len); emberAfAppPrintln("result=%d",result);
emberAfAppPrintBuffer(data,len,true); emberAfAppPrintln("mac:");
} emberAfPrintBigEndianEui64(eui64);
return ; 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); emberAfAppPrintln("not find report item!!!ep=%d,clu=0x%x,attr=0x%x\n",EP,clusterId,attributeId);
......
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
#define KK_PRIMARY_EP KK_EP(1) #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_Control(jrpc_context * ctx, cJSON * params, cJSON *id,cJSON *mac);
cJSON *rpc_read_attribue(jrpc_context * ctx, cJSON * params, cJSON *id,cJSON *mac); cJSON *rpc_read_attribue(jrpc_context * ctx, cJSON * params, cJSON *id,cJSON *mac);
...@@ -40,6 +43,11 @@ int kk_zcl_windowCovering_OperationMode_set(jrpc_context * ctx,const char *mac,u ...@@ -40,6 +43,11 @@ int kk_zcl_windowCovering_OperationMode_set(jrpc_context * ctx,const char *mac,u
int kk_zcl_windowCovering_mode_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_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);
int kk_sendData2CCU(char* data, int len); int kk_sendData2CCU(char* data, int len);
...@@ -66,6 +74,11 @@ void kk_dispatch_report_attribute(EmberEUI64 eui64, ...@@ -66,6 +74,11 @@ void kk_dispatch_report_attribute(EmberEUI64 eui64,
enum {
WC_normal_dir = 0,//"正转"
WC_reversed_dir = 1,//"反转"
WC_calibration_mode = 2,//"校验"
}windowCoveringMode;
......
#include "kk_tsl_zigbee_map.h" #include "kk_tsl_zigbee_map.h"
#include "kk_test.h" #include "kk_test.h"
kk_tsl_zigbee_map_t g_tsl_zigbee_map [] = { kk_tsl_zigbee_map_t g_tsl_zigbee_map [] = {
{ {
ZIGBEE_COO_PRODUCT_CODE, ZIGBEE_COO_PRODUCT_CODE,
4, 1,
{ {
{KK_TSL_DATA_TYPE_TEXT,"NetChannelState",KK_DUMMY_EP,rpc_nwkPermitJoin,0,0}, {KK_TSL_DATA_TYPE_TEXT,"NetChannelState",KK_DUMMY_EP,rpc_nwkPermitJoin,0,0,NULL},
{KK_TSL_DATA_TYPE_TEXT,"test12",KK_PRIMARY_EP,kk_zcl_onoff_set,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID},
{KK_TSL_DATA_TYPE_TEXT,"test123",KK_PRIMARY_EP,kk_zcl_onoff_set,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID},
{KK_TSL_DATA_TYPE_TEXT,"test1234",KK_PRIMARY_EP,kk_zcl_onoff_set,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID},
} }
}, },
{ {
TEST_PRODUCT_CODE, TEST_PRODUCT_CODE,
3, 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_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_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_ATTRIBUTE_ID}, {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},
} }
}, },
}; };
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define PROPERTIES_MAX_NUM 20 #define PROPERTIES_MAX_NUM 20
typedef int (*zigbee_property_set)(jrpc_context * ctx,const char *mac,unsigned char ep,void* data); typedef int (*zigbee_property_set)(jrpc_context * ctx,const char *mac,unsigned char ep,void* data);
//typedef int (*zigbee_property_report)(EmberEUI64 mac,bool LightStatus,uint16_t clusterId,uint16_t attributeId); 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{ typedef struct{
int type; int type;
...@@ -15,7 +15,7 @@ typedef struct{ ...@@ -15,7 +15,7 @@ typedef struct{
zigbee_property_set zigbee_set; zigbee_property_set zigbee_set;
unsigned short clusterId; unsigned short clusterId;
unsigned short attributeId; unsigned short attributeId;
//zigbee_property_report zigbee_report; kk_zigbee_property_report zigbee_report;
}kk_zigbee_ctrl_map_t; }kk_zigbee_ctrl_map_t;
typedef struct{ typedef struct{
......
...@@ -12,6 +12,17 @@ EmberStatus zclGRead(uint16_t node, ...@@ -12,6 +12,17 @@ EmberStatus zclGRead(uint16_t node,
uint16_t clusterId, uint16_t clusterId,
uint16_t attrId, uint16_t attrId,
bool svr); bool svr);
EmberStatus zclGWrite(uint16_t node,
uint8_t srcEP,
uint8_t dstEP,
bool multicast,
uint16_t clusterId,
uint16_t attrId,
uint8_t dataType,
uint8_t dataLen,
uint8_t *data,
bool svr);
cJSON *rpc_zclGRead(jrpc_context * ctx, cJSON * params, cJSON *id); cJSON *rpc_zclGRead(jrpc_context * ctx, cJSON * params, cJSON *id);
......
...@@ -79,9 +79,14 @@ EmberStatus zclGWrite(uint16_t node, ...@@ -79,9 +79,14 @@ EmberStatus zclGWrite(uint16_t node,
bool multicast, bool multicast,
uint16_t clusterId, uint16_t clusterId,
uint16_t attrId, uint16_t attrId,
uint8_t dataType,
uint8_t dataLen,
uint8_t *data,
bool svr) bool svr)
{ {
EmberStatus status; EmberStatus status = EMBER_ERR_FATAL;
int i;
if(data==NULL||dataLen==0) return status;
zclBufferSetup(ZCL_GLOBAL_COMMAND | ((svr==true)? zclBufferSetup(ZCL_GLOBAL_COMMAND | ((svr==true)?
ZCL_FRAME_CONTROL_CLIENT_TO_SERVER ZCL_FRAME_CONTROL_CLIENT_TO_SERVER
...@@ -91,6 +96,10 @@ EmberStatus zclGWrite(uint16_t node, ...@@ -91,6 +96,10 @@ EmberStatus zclGWrite(uint16_t node,
zclBufferAddByte(LOW_BYTE(attrId)); zclBufferAddByte(LOW_BYTE(attrId));
zclBufferAddByte(HIGH_BYTE(attrId)); zclBufferAddByte(HIGH_BYTE(attrId));
zclBufferAddByte(dataType);
for(i=0;i<dataLen;i++){
zclBufferAddByte(data[i]);
}
rpcBufferPrint(); rpcBufferPrint();
status = rpcSendCommand(node,srcEP,dstEP,multicast); status = rpcSendCommand(node,srcEP,dstEP,multicast);
......
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