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

添加窗帘物模型WorkMode,Position属性上报

parent 3ee908ac
...@@ -392,7 +392,7 @@ ...@@ -392,7 +392,7 @@
// Use this macro to check if Network Creator Security plugin is included // Use this macro to check if Network Creator Security plugin is included
#define EMBER_AF_PLUGIN_NETWORK_CREATOR_SECURITY #define EMBER_AF_PLUGIN_NETWORK_CREATOR_SECURITY
// User options for plugin Network Creator Security // User options for plugin Network Creator Security
#define EMBER_AF_PLUGIN_NETWORK_CREATOR_SECURITY_NETWORK_OPEN_TIME_S 180 #define EMBER_AF_PLUGIN_NETWORK_CREATOR_SECURITY_NETWORK_OPEN_TIME_S 120
#define EMBER_AF_PLUGIN_NETWORK_CREATOR_SECURITY_TRUST_CENTER_SUPPORT #define EMBER_AF_PLUGIN_NETWORK_CREATOR_SECURITY_TRUST_CENTER_SUPPORT
#define EMBER_AF_PLUGIN_NETWORK_CREATOR_SECURITY_ALLOW_HA_DEVICES_TO_STAY #define EMBER_AF_PLUGIN_NETWORK_CREATOR_SECURITY_ALLOW_HA_DEVICES_TO_STAY
......
...@@ -19,7 +19,7 @@ enum { ...@@ -19,7 +19,7 @@ enum {
ZCL_DATA56_ATTRIBUTE_TYPE = 0x0E, // 56-bit data ZCL_DATA56_ATTRIBUTE_TYPE = 0x0E, // 56-bit data
ZCL_DATA64_ATTRIBUTE_TYPE = 0x0F, // 64-bit data ZCL_DATA64_ATTRIBUTE_TYPE = 0x0F, // 64-bit data
ZCL_BOOLEAN_ATTRIBUTE_TYPE = 0x10, // Boolean ZCL_BOOLEAN_ATTRIBUTE_TYPE = 0x10, // Boolean
ZCL_BITMAP8_ATTRIBUTE_TYPE = 0x18, // 8-bit bitmap ZCL_BITMAP8_ATTRIBUTE_TYPE = 0x18, // 8-bit bitmap
ZCL_BITMAP16_ATTRIBUTE_TYPE = 0x19, // 16-bit bitmap ZCL_BITMAP16_ATTRIBUTE_TYPE = 0x19, // 16-bit bitmap
ZCL_BITMAP24_ATTRIBUTE_TYPE = 0x1A, // 24-bit bitmap ZCL_BITMAP24_ATTRIBUTE_TYPE = 0x1A, // 24-bit bitmap
ZCL_BITMAP32_ATTRIBUTE_TYPE = 0x1B, // 32-bit bitmap ZCL_BITMAP32_ATTRIBUTE_TYPE = 0x1B, // 32-bit bitmap
......
...@@ -104,12 +104,15 @@ void kk_rpc_reportDevices(EmberEUI64 mac) ...@@ -104,12 +104,15 @@ void kk_rpc_reportDevices(EmberEUI64 mac)
kk_sub_tsl_add(mac,TEST_PRODUCT_CODE); kk_sub_tsl_add(mac,TEST_PRODUCT_CODE);
kk_rpc_report_devices(devicesJson,testMac_GW); kk_rpc_report_devices(devicesJson,testMac_GW);
} }
int kk_rpc_report_LightStatus(EmberEUI64 mac,int status,uint16_t clusterId,uint16_t attributeId)
int kk_rpc_report_attribute_status(EmberEUI64 mac,uint8_t EP,int status,uint16_t clusterId,uint16_t attributeId)
{ {
cJSON* root; cJSON* root;
int res = 0; int res = 0;
int num = 0; int num = 0;
int pCtrlIdx = 0; int pCtrlIdx = 0;
uint8_t endpoint_tmp = 0;
uint16_t clusterId_tmp = 0; uint16_t clusterId_tmp = 0;
uint16_t attributeId_tmp = 0; uint16_t attributeId_tmp = 0;
int i = 0; int i = 0;
...@@ -134,7 +137,10 @@ int kk_rpc_report_LightStatus(EmberEUI64 mac,int status,uint16_t clusterId,uint1 ...@@ -134,7 +137,10 @@ int kk_rpc_report_LightStatus(EmberEUI64 mac,int status,uint16_t clusterId,uint1
{ {
clusterId_tmp = g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[i].clusterId; clusterId_tmp = g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[i].clusterId;
attributeId_tmp = g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[i].attributeId; attributeId_tmp = g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[i].attributeId;
if(clusterId_tmp == clusterId && attributeId_tmp == 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); rpc_cJSON_AddNumberToObject(root, g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[i].Identity,status);
break; break;
...@@ -143,34 +149,36 @@ int kk_rpc_report_LightStatus(EmberEUI64 mac,int status,uint16_t clusterId,uint1 ...@@ -143,34 +149,36 @@ int kk_rpc_report_LightStatus(EmberEUI64 mac,int status,uint16_t clusterId,uint1
kk_rpc_report_status(root,mac); kk_rpc_report_status(root,mac);
return 0; return 0;
} }
int lightStatusSet(jrpc_context * ctx,const char *mac,void* data) int kk_zcl_onoff_set(jrpc_context * ctx,const char *mac,unsigned char ep,void* data)
{ {
uint8_t eui64[EUI64_SIZE]; uint8_t eui64[EUI64_SIZE];
uint8_t LightStatus = 0; uint8_t OnOffStatus = 0;
EmberStatus status = 0; EmberStatus status = 0;
EmberNodeId node = 0xffff;
LightStatus = *(uint8_t*)data; OnOffStatus = *(uint8_t*)data;
bool flag= 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++){
emberAfCorePrintln("i=%d,val=%02x",i,eui64[i]); emberAfCorePrintln("i=%d,val=%02x",i,eui64[i]);
} }
EmberNodeId node = emberAfDeviceTableGetNodeIdFromEui64(eui64);
if(node==0xffff){
emberAfCorePrintln("\r\n not find device!\r\n" );
if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
emberAfCorePrintln("\r\nnode=0x%02X,LightStatus=%d\r\n",node,LightStatus);
if(flag){
if(LightStatus==1){ if(macMatch){
status = zclOnOff_On(node,1); 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,OnOffStatus);
if(OnOffStatus==1){
status = zclOnOff_On(node,ep);
emberAfCorePrintln("\r\nzclOnOff_On\r\n" ); emberAfCorePrintln("\r\nzclOnOff_On\r\n" );
}else if(LightStatus==0){ }else if(OnOffStatus==0){
status = zclOnOff_Off(node,1); status = zclOnOff_Off(node,ep);
emberAfCorePrintln("\r\nzclOnOff_Off\r\n" ); emberAfCorePrintln("\r\nzclOnOff_Off\r\n" );
}else{ }else{
if(ctx) if(ctx)
...@@ -178,7 +186,7 @@ int lightStatusSet(jrpc_context * ctx,const char *mac,void* data) ...@@ -178,7 +186,7 @@ int lightStatusSet(jrpc_context * ctx,const char *mac,void* data)
goto error_return; goto error_return;
} }
}else{ }else{
emberAfCorePrintln("\r\n22222\r\n" ); emberAfCorePrintln("\r\n not find device by mac!\r\n" );
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);
goto error_return; goto error_return;
...@@ -186,8 +194,6 @@ int lightStatusSet(jrpc_context * ctx,const char *mac,void* data) ...@@ -186,8 +194,6 @@ int lightStatusSet(jrpc_context * ctx,const char *mac,void* data)
return status; return status;
error_return: error_return:
return -1; return -1;
} }
#if 0 #if 0
int kk_test_fuc(char *mac,const char *params) int kk_test_fuc(char *mac,const char *params)
...@@ -269,7 +275,7 @@ cJSON *rpc_read_attribue(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac ...@@ -269,7 +275,7 @@ cJSON *rpc_read_attribue(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac
if(propertyItem != NULL) if(propertyItem != NULL)
{ {
int value = rpc_get_u8(propertyItem->valuestring); int value = rpc_get_u8(propertyItem->valuestring);
res = g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].zigbee_set(ctx,mac->valuestring,&value); 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) if(ret < 0)
{ {
goto error_return; goto error_return;
...@@ -314,8 +320,8 @@ cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac) ...@@ -314,8 +320,8 @@ cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac)
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
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;
} }
num = kk_get_Identity_Num(pCtrlIdx); num = kk_get_Identity_Num(pCtrlIdx);
for(index = 0; index < num; index++){ for(index = 0; index < num; index++){
propertyItem = rpc_cJSON_GetObjectItem(params, g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].Identity); propertyItem = rpc_cJSON_GetObjectItem(params, g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].Identity);
if(propertyItem != NULL) if(propertyItem != NULL)
...@@ -327,9 +333,9 @@ cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac) ...@@ -327,9 +333,9 @@ cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac)
value = propertyItem->valueint; value = propertyItem->valueint;
} }
res = g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].zigbee_set(ctx,mac->valuestring,&value); 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) if(res < 0)
{ {
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;
} }
...@@ -343,30 +349,17 @@ error_return: ...@@ -343,30 +349,17 @@ error_return:
return rpc_cJSON_CreateNull(); return rpc_cJSON_CreateNull();
} }
int rpc_nwkPermitJoin(jrpc_context * ctx,const char *mac,void* data) int rpc_nwkPermitJoin(jrpc_context * ctx,const char *mac,unsigned char ep,void* data)
{ {
EmberStatus status; EmberStatus status;
uint8_t isEnable = *(uint8_t*)data; uint8_t isEnable = *(uint8_t*)data;
#if 0
if(params == NULL){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}else if(params->type == cJSON_Object){
OpenOrClose = rpc_cJSON_GetObjectItem(params, "NetChannelState");
}else{
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
isEnable = rpc_get_u8(OpenOrClose->valuestring);
#endif
if(isEnable == 0){ if(isEnable == 0){
status = nwkPermitJoinCMD(FALSE); status = nwkPermitJoinCMD(FALSE);
emberAfCorePrintln("Disable Permit join\r\n"); emberAfCorePrintln("Disable Permit join\r\n");
}else if(isEnable == 1){ }else if(isEnable == 1){
status = nwkPermitJoinCMD(TRUE); status = nwkPermitJoinCMD(TRUE);
emberAfCorePrintln("Enable Permit join 180s\r\n"); emberAfCorePrintln("Enable Permit join %ds\r\n",EMBER_AF_PLUGIN_NETWORK_CREATOR_SECURITY_NETWORK_OPEN_TIME_S);
}else{ }else{
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;
...@@ -406,3 +399,110 @@ void emberAfPluginDeviceTableNewDeviceCallback(EmberEUI64 nodeEui64) ...@@ -406,3 +399,110 @@ void emberAfPluginDeviceTableNewDeviceCallback(EmberEUI64 nodeEui64)
kk_rpc_reportDevices(deviceTable[deviceTableIndex].eui64); kk_rpc_reportDevices(deviceTable[deviceTableIndex].eui64);
} }
int kk_report_global_onoff_attribute(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data)
{
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;
}
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)
{
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)
{
uint8_t position;
if(dataType == ZCL_INT16U_ATTRIBUTE_TYPE){
if(len==2){
position = HIGH_LOW_TO_INT(data[1], data[0]);
kk_rpc_report_attribute_status(eui64,EP,position,clusterId,attributeId);
return 0;
}
return -2;
}
return -3;
}
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,
uint8_t EP,
EmberAfClusterId clusterId,
EmberAfAttributeId attributeId,
uint8_t dataType,
uint8_t len,
uint8_t *data)
{
int i,num,result;
num = sizeof(kk_report_map)/sizeof(kk_rpc_report_map_s);
kk_rpc_report_map_s *report_item = kk_report_map;
for(i=0;i<num;i++,report_item++){
if(report_item->clusterId==clusterId &&
report_item->attributeId == attributeId){
result = report_item->func(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);
}
...@@ -17,19 +17,37 @@ ...@@ -17,19 +17,37 @@
#define KK_REPORT_ATTRIBUTE_METHOD "thing.event.property.post" #define KK_REPORT_ATTRIBUTE_METHOD "thing.event.property.post"
#define KK_READ_ATTRIBUTE_METHOD "thing.service.property.get" #define KK_READ_ATTRIBUTE_METHOD "thing.service.property.get"
#define ZIGBEE_COO_PRODUCT_CODE "2"
#define TEST_PRODUCT_CODE "24" #define TEST_PRODUCT_CODE "24"
#define GW2CCU_PROTOCOL "tcp" #define GW2CCU_PROTOCOL "tcp"
#define GW_DEVICE_CODE "1122334455667788" #define GW_DEVICE_CODE "1122334455667788"
#define KK_EP(x) (x)
#define KK_DUMMY_EP KK_EP(0)
#define KK_PRIMARY_EP KK_EP(1)
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);
int lightStatusSet(jrpc_context * ctx,const char *mac,void* data); int kk_zcl_onoff_set(jrpc_context * ctx,const char *mac,unsigned char ep,void* data);
int kk_sendData2CCU(char* data, int len); int kk_sendData2CCU(char* data, int len);
int rpc_nwkPermitJoin(jrpc_context * ctx,const char *mac,void* data); 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 \ #define RPC_KK_TEST_FUNCTION_TABLE \
{(rpc_function*)rpc_Control,"/thing/service/property/set"},\ {(rpc_function*)rpc_Control,"/thing/service/property/set"},\
......
...@@ -3,25 +3,24 @@ ...@@ -3,25 +3,24 @@
kk_tsl_zigbee_map_t g_tsl_zigbee_map [] = { kk_tsl_zigbee_map_t g_tsl_zigbee_map [] = {
{ {
TEST_PRODUCT_CODE, ZIGBEE_COO_PRODUCT_CODE,
3, 4,
{ {
{KK_TSL_DATA_TYPE_TEXT,"OperationMode",lightStatusSet,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID}, {KK_TSL_DATA_TYPE_TEXT,"NetChannelState",KK_DUMMY_EP,rpc_nwkPermitJoin,0,0},
{KK_TSL_DATA_TYPE_TEXT,"WorkMode",lightStatusSet,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID}, {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,"Position",lightStatusSet,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},
} }
}, },
{ {
"2", TEST_PRODUCT_CODE,
4, 3,
{ {
{KK_TSL_DATA_TYPE_TEXT,"NetChannelState",rpc_nwkPermitJoin,0,0}, {KK_TSL_DATA_TYPE_TEXT,"OperationMode",KK_PRIMARY_EP,kk_zcl_onoff_set,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID},//开
{KK_TSL_DATA_TYPE_TEXT,"test12",lightStatusSet,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID}, {KK_TSL_DATA_TYPE_TEXT,"WorkMode",KK_PRIMARY_EP,kk_zcl_onoff_set,ZCL_WINDOW_COVERING_CLUSTER_ID,ZCL_MODE_ATTRIBUTE_ID},
{KK_TSL_DATA_TYPE_TEXT,"test123",lightStatusSet,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID}, {KK_TSL_DATA_TYPE_TEXT,"Position",KK_PRIMARY_EP,kk_zcl_onoff_set,ZCL_WINDOW_COVERING_CLUSTER_ID,ZCL_CURRENT_LIFT_ATTRIBUTE_ID},
{KK_TSL_DATA_TYPE_TEXT,"test1234",lightStatusSet,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID},
} }
}, },
}; };
int kk_find_ctrl_obj(const char *productCode) int kk_find_ctrl_obj(const char *productCode)
......
...@@ -5,12 +5,13 @@ ...@@ -5,12 +5,13 @@
#define PROPERTIES_MAX_NUM 20 #define PROPERTIES_MAX_NUM 20
typedef int (*zigbee_property_set)(jrpc_context * ctx,const char *mac,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 (*zigbee_property_report)(EmberEUI64 mac,bool LightStatus,uint16_t clusterId,uint16_t attributeId);
typedef struct{ typedef struct{
int type; int type;
char* Identity; char* Identity;
unsigned char endpoint;
zigbee_property_set zigbee_set; zigbee_property_set zigbee_set;
unsigned short clusterId; unsigned short clusterId;
unsigned short attributeId; unsigned short attributeId;
......
...@@ -485,8 +485,10 @@ int jrpc_send_msg(cJSON * msgJson) { ...@@ -485,8 +485,10 @@ int jrpc_send_msg(cJSON * msgJson) {
return return_value; return return_value;
} }
#define ATTRIBUTE_BUFFER_ATTRIBUTEID_ID 1
#define ATTRIBUTE_BUFFER_REPORT_DATA_TYPE 2
#define ATTRIBUTE_BUFFER_REPORT_DATA_VALUE 3
#define ATTRIBUTE_BUFFER_REPORT_DATA_TYPE 2
// Attribute reading buffer location definitions // Attribute reading buffer location definitions
#define ATTRIBUTE_BUFFER_ATTRIBUTEID_LOW_BITS 0 #define ATTRIBUTE_BUFFER_ATTRIBUTEID_LOW_BITS 0
#define ATTRIBUTE_BUFFER_ATTRIBUTEID_HIGH_BITS 1 #define ATTRIBUTE_BUFFER_ATTRIBUTEID_HIGH_BITS 1
...@@ -532,12 +534,16 @@ bool rpc_ReportAttributesCallback(EmberAfClusterId clusterId, ...@@ -532,12 +534,16 @@ bool rpc_ReportAttributesCallback(EmberAfClusterId clusterId,
uint16_t bufLen) uint16_t bufLen)
{ {
EmberEUI64 nodeEui64; EmberEUI64 nodeEui64;
EmberAfAttributeId attributeId;
EmberNodeId nodeId = emberAfCurrentCommand()->source; EmberNodeId nodeId = emberAfCurrentCommand()->source;
uint8_t ep = emberAfCurrentCommand()->apsFrame->sourceEndpoint; uint8_t ep = emberAfCurrentCommand()->apsFrame->sourceEndpoint;
emberAfDeviceTableGetEui64FromNodeId(nodeId, nodeEui64); emberAfDeviceTableGetEui64FromNodeId(nodeId, nodeEui64);
uint8_t * bufferTemp; uint8_t * bufferTemp;
uint8_t * bufferPtr = buffer; uint8_t * bufferPtr = buffer;
uint8_t i, bufferSize,typeSize; uint8_t i, bufferSize,typeSize;
uint8_t dataLen,dataType;
uint8_t *dataPtr;
kk_print_debug("\n********************report callback**********************\n"); kk_print_debug("\n********************report callback**********************\n");
emberAfAppPrint("[ "); emberAfAppPrint("[ ");
...@@ -553,39 +559,30 @@ bool rpc_ReportAttributesCallback(EmberAfClusterId clusterId, ...@@ -553,39 +559,30 @@ bool rpc_ReportAttributesCallback(EmberAfClusterId clusterId,
emberAfPrintBigEndianEui64(nodeEui64); emberAfPrintBigEndianEui64(nodeEui64);
emberAfAppPrintln(",EP=%d,cluster=0x%04X\n",ep,clusterId); emberAfAppPrintln(",EP=%d,cluster=0x%04X\n",ep,clusterId);
cJSON *item = rpc_cJSON_CreateObject();
cJSON *array_attr = rpc_cJSON_CreateObject();
rpc_cJSON_AddMACToObject(item,nodeEui64);
rpc_cJSON_AddNodeToObject(item,nodeId);
rpc_cJSON_AddEndpointToObject(item,ep);
rpc_cJSON_AddClusterToObject(item,clusterId);
array_attr = rpc_cJSON_CreateArray();
rpc_cJSON_AddItemToObject(item,"attributes",array_attr);
for (i = 0; i < bufLen; ) { for (i = 0; i < bufLen - 4; ) {
if(emberAfIsStringAttributeType(bufferPtr[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE])){ dataType = bufferPtr[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE];
bufferSize = bufferPtr[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE + 1]; if(emberAfIsStringAttributeType(dataType)){
dataLen = bufferPtr[ATTRIBUTE_BUFFER_REPORT_DATA_VALUE ];
typeSize = 1; typeSize = 1;
}else if(emberAfIsLongStringAttributeType(bufferPtr[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE])){ }else if(emberAfIsLongStringAttributeType(dataType)){
bufferSize = HIGH_LOW_TO_INT(bufferPtr[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE + 2], bufferPtr[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE + 1]); dataLen = HIGH_LOW_TO_INT(bufferPtr[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE + 2],
bufferPtr[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE + 1]);
typeSize = 2; typeSize = 2;
}else { }else {
typeSize = 0; typeSize = 0;
bufferSize = emberAfGetDataSize( dataLen = emberAfGetDataSize(
bufferPtr[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE]); bufferPtr[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE]);
} }
bufferSize = bufferSize + 3 + typeSize; dataPtr = &bufferPtr[ATTRIBUTE_BUFFER_REPORT_DATA_VALUE];
bufferSize = ATTRIBUTE_BUFFER_REPORT_DATA_VALUE + dataLen + typeSize;
bufferTemp = (uint8_t*)malloc(bufferSize); bufferTemp = (uint8_t*)malloc(bufferSize);
memcpy(bufferTemp, bufferPtr, bufferSize); memcpy(bufferTemp, bufferPtr, bufferSize);
bufferPtr = bufferPtr + bufferSize; bufferPtr +=bufferSize;
i = i + bufferSize; i +=bufferSize;
emberAfAppPrintln("i=%d,bufferSize=%d\n",i,bufferSize); emberAfAppPrintln("i=%d,bufferSize=%d\n",i,bufferSize);
emberAfAppPrintln("Reported attribute: 0x%02X%02X, Type: %02X", emberAfAppPrintln("Reported attribute: 0x%02X%02X, Type: %02X",
...@@ -593,37 +590,17 @@ bool rpc_ReportAttributesCallback(EmberAfClusterId clusterId, ...@@ -593,37 +590,17 @@ bool rpc_ReportAttributesCallback(EmberAfClusterId clusterId,
bufferTemp[ATTRIBUTE_BUFFER_ATTRIBUTEID_LOW_BITS], bufferTemp[ATTRIBUTE_BUFFER_ATTRIBUTEID_LOW_BITS],
bufferTemp[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE]); bufferTemp[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE]);
cJSON *item_attr = rpc_cJSON_CreateObject();
rpc_cJSON_AddItemToArray(array_attr,item_attr); attributeId = HIGH_LOW_TO_INT(bufferTemp[ATTRIBUTE_BUFFER_ATTRIBUTEID_HIGH_BITS],bufferTemp[ATTRIBUTE_BUFFER_ATTRIBUTEID_LOW_BITS]);
EmberAfAttributeId attributeId = HIGH_LOW_TO_INT(bufferTemp[ATTRIBUTE_BUFFER_ATTRIBUTEID_HIGH_BITS],bufferTemp[ATTRIBUTE_BUFFER_ATTRIBUTEID_LOW_BITS]);
EmberEUI64 eui64;
if(emberAfDeviceTableGetEui64FromNodeId(nodeId,eui64)){
if(clusterId==ZCL_ON_OFF_CLUSTER_ID && attributeId==ZCL_ON_OFF_ATTRIBUTE_ID){
if(bufferTemp[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE]==ZCL_BOOLEAN_ATTRIBUTE_TYPE){
uint8_t LightStatus = bufferTemp[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE+1];
if(LightStatus==0||LightStatus==1){
kk_rpc_report_LightStatus(eui64,LightStatus,clusterId,attributeId);
}
}
}
}
rpc_cJSON_AddAttributeToObject(item_attr,attributeId);
rpc_cJSON_AddDataTypeToObject(item_attr,bufferTemp[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE]);
int dataLen = bufferSize-3-typeSize; if(emberAfDeviceTableGetEui64FromNodeId(nodeId,nodeEui64)){
rpc_cJSON_AddLengthToObject(item_attr,dataLen); kk_dispatch_report_attribute(nodeEui64,ep,clusterId,attributeId,dataType,dataLen,dataPtr);
rpc_cJSON_AddDataToObject(item_attr,&bufferTemp[ATTRIBUTE_BUFFER_REPORT_DATA_TYPE+1+typeSize],dataLen); }
free(bufferTemp); free(bufferTemp);
} }
//rpc_report_attribute(item);
return false; return false;
} }
......
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