Commit 35084464 authored by 陈伟灿's avatar 陈伟灿

Merge branch 'yjq' into 'master'

Yjq

See merge request chenweican/k-sdk!21
parents 59823294 6a935c47
......@@ -291,6 +291,7 @@ APPLICATION_FILES= \
./ZB/kk_plat_ota.c\
./ZB/kk_rgb_hsl_convert.c\
./ZB/kk_color_space.c\
./ZB/sub_device_manage.c\
./kk_test.c\
./rpc_api/src/rpc_common.c\
./rpc_api/src/rpc_onoff.c\
......
......@@ -7,8 +7,8 @@
void RGB_to_HSL_base(unsigned char red, unsigned char green, unsigned char blue,double *H,double *S,double *L);
void RGB_to_HSL(unsigned char red, unsigned char green, unsigned char blue,unsigned short *H,unsigned char *S,unsigned char *L);
void HSL_to_RGB_base(double H,double S,double L,unsigned char *red, unsigned char *green, unsigned char *blue);
void HSL_to_RGB(unsigned short H,unsigned char S,unsigned char L,unsigned char *red, unsigned char *green, unsigned char *blue);
......
......@@ -2,6 +2,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "kk_product_code.h"
#include "kk_zb_com.h"
......@@ -130,6 +132,7 @@ void kk_read_attr_response(EmberNodeId nodeId,
}
}
kk_colorlight_attr_read(nodeId,ep,cluster,attribute,status,dataType,dataSize,data);
}
void emberAfPluginDeviceTableNewDeviceCallback(EmberEUI64 nodeEui64)
{
......
#ifndef __KK_DEVICE_MANAGER_H
#define __KK_DEVICE_MANAGER_H
#include "kk_test.h"
#include "kk_product_code.h"
#include "kk_zb_com.h"
/****************** ******************************************************************
* File Name : kk_device_manager.h
......
......@@ -63,6 +63,7 @@ static kk_device_table_s *kk_device_table_create()
}
MEMSET(node, 0, sizeof(kk_device_table_s));
MEMSET(&node->manage, 0, sizeof(SubDevManage_s));
return node;
}
......
......@@ -143,9 +143,7 @@ void kk_tsl_report_attribute(EmberEUI64 eui64,
func = item->reportFunc;
if(func != NULL){
emberAfDebugPrintln("123123123");
func(eui64,EP,clusterId,attributeId,dataType,len,data);
emberAfDebugPrintln("456456456");
}else{
}
......@@ -368,122 +366,75 @@ int kk_tsl_report_CO2(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,Emb
return kk_tsl_report_Concentration(eui64,EP,clusterId,attributeId,dataType,len,data);
}
static int s_HSLCount = 0;
static unsigned short s_H = 0;
static unsigned char s_S = 0;
static unsigned char s_L = 0;
static int kk_tsl_report_colorControl_RGB_Str(EmberEUI64 eui64)
{
kk_device_table_s *dev;
kk_dev_config_map *dev_info = NULL;
kk_dev_config_item *item = NULL;
cJSON *root;
int rev = 0;
int startIdx = 0;
cJSON* root_color = NULL;
char tmp_Identity[64] = {0};
unsigned char r,g,b;
if(s_HSLCount >= 3 && s_H != 0 && s_S != 0){
HSL_to_RGB(s_H*360/254,s_S*100/254,s_L,&r,&g,&b);
s_HSLCount = 0;
s_H = 0;
s_S = 0;
//printf("[%s][%d]%d %d %d\n",__FUNCTION__,__LINE__,r,g,b);
dev = kk_device_find_by_mac(eui64);
if(dev == NULL){
return tsl_rpt_err;
}
dev_info = kk_device_config_find(dev->productCode);
if(dev_info == NULL){
return tsl_rpt_err;
}
item = &dev_info->item;
while(item!=NULL){
if(strstr(item->identity,".red") != NULL){
if(root_color == NULL){
root_color = rpc_cJSON_CreateObject();
}
rev = kk_tsl_utils_memtok(item->identity,'.',1,&startIdx);
if(!rev){
memcpy(tmp_Identity,item->identity,startIdx);
rpc_cJSON_AddNumberToObject(root_color, item->identity + 1 + startIdx,r);
}
}
else if(strstr(item->identity,".green") != NULL){
if(root_color == NULL){
root_color = rpc_cJSON_CreateObject();
}
rev = kk_tsl_utils_memtok(item->identity,'.',1,&startIdx);
if(!rev){
memcpy(tmp_Identity,item->identity,startIdx);
rpc_cJSON_AddNumberToObject(root_color, item->identity + 1 + startIdx,g);
}
}
else if(strstr(item->identity,".blue") != NULL){
if(root_color == NULL){
root_color = rpc_cJSON_CreateObject();
}
rev = kk_tsl_utils_memtok(item->identity,'.',1,&startIdx);
if(!rev){
memcpy(tmp_Identity,item->identity,startIdx);
rpc_cJSON_AddNumberToObject(root_color, item->identity + 1 + startIdx,b);
}
}
item = item->next;
}
if(root_color != NULL){
root = rpc_cJSON_CreateObject();
rpc_cJSON_AddItemToObject(root,tmp_Identity,root_color);
kk_msg_report_property(root,eui64);
return tsl_rpt_success;
}
}
return tsl_rpt_err;
}
int kk_tsl_report_colorControl_Brightness(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data)
{
uint8_t value = data[0];
emberAfAppPrintln("[tsl report:kk_tsl_report_global_Brightness] value:%d\n",value);
kk_device_table_s *dev;
UTIL_LOG_INFO("[tsl report:kk_tsl_report_global_Brightness] value:%d\n",value);
dev = kk_device_find_by_mac(eui64);
if(dev == NULL){
return tsl_rpt_err;
}
if(dataType == ZCL_INT8U_ATTRIBUTE_TYPE){
if(len==1){
kk_tsl_report(eui64,EP,value,clusterId,attributeId);
s_L = value;
s_HSLCount++;
kk_tsl_report_colorControl_RGB_Str(eui64);
if(s_HSLCount >= 3){
s_HSLCount = 0;
}
}
if(len==1){
dev->manage.dev.ColorLighting.color.HSL.L = value;
dev->manage.dev.ColorLighting.color.HSL.HSL_flag |= BIT(2);
dev->manage.dev.ColorLighting.time = halCommonGetInt32uMillisecondTick();
emberAfCorePrintln("HSL.L = %d",dev->manage.dev.ColorLighting.color.HSL.L);
kk_tsl_report(eui64,EP,value,clusterId,attributeId);
return tsl_rpt_success;
}
return tsl_rpt_invaild_len;
}
return tsl_rpt_invaild_type;
}
int kk_tsl_report_colorControl_RGB(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,EmberAfAttributeId attributeId,uint8_t dataType,uint8_t len,uint8_t *data)
{
uint8_t value = data[0];
kk_device_table_s *dev;
kk_dev_config_map *dev_info = NULL;
kk_dev_config_item *item = NULL;
cJSON *root;
int rev = 0;
int startIdx = 0;
cJSON* root_color = NULL;
char tmp_Identity[64] = {0};
COLOR_RGB g_rgb = {0,0,0};
UTIL_LOG_INFO("[tsl report:kk_tsl_report_global_RGB] value:%d\n",value);
emberAfAppPrintln("[tsl report:kk_tsl_report_global_RGB] value:%d\n",value);
dev = kk_device_find_by_mac(eui64);
if(dev == NULL){
return tsl_rpt_err;
}
if(dataType == ZCL_INT8U_ATTRIBUTE_TYPE){
if(attributeId == 0x0001){
s_S = value;
s_HSLCount++;
kk_tsl_report_colorControl_RGB_Str(eui64);
dev->manage.dev.ColorLighting.color.HSL.S = value * 100 / 254 ;
dev->manage.dev.ColorLighting.color.HSL.HSL_flag |= BIT(1);
dev->manage.dev.ColorLighting.time = halCommonGetInt32uMillisecondTick();
emberAfCorePrintln("HSL.S = %d",dev->manage.dev.ColorLighting.color.HSL.S);
}
else if(attributeId == 0x0){
s_H = value;
s_HSLCount++;
kk_tsl_report_colorControl_RGB_Str(eui64);
else if(attributeId == 0x0000){
dev->manage.dev.ColorLighting.color.HSL.H = value * 360 / 254 ;
dev->manage.dev.ColorLighting.color.HSL.HSL_flag |= BIT(0);
dev->manage.dev.ColorLighting.time = halCommonGetInt32uMillisecondTick();
emberAfCorePrintln("HSL.H = %d",dev->manage.dev.ColorLighting.color.HSL.H);
}
}
return tsl_rpt_success;
return tsl_rpt_err;
}
......
......@@ -140,10 +140,8 @@ cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJ
}
else{
propertyItem = rpc_cJSON_GetObjectItem(params, item->identity);
if(propertyItem != NULL){
// printf("[%s][%d]item->identity:%s\n",__FUNCTION__,__LINE__,item->identity);
findFlag = 1;
}
}
......@@ -156,12 +154,7 @@ cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJ
value = propertyItem->valueint;
}
func = item->controlFunc;
if(func != NULL){
res = func(ctx,nodeId,item->endpoint,&value);
}
else{
// printf("[%s][%d] can not find the func!!!\n",__FUNCTION__,__LINE__);
}
res = func(ctx,nodeId,item->endpoint,&value);
findFlag = 0;
}
item = item->next;
......@@ -309,24 +302,25 @@ error_return:
static uint8_t s_RgbCount = 0;
static COLOR_RGB s_rgb;
static int kk_zclColorControlMovetohueandsat(EmberNodeId node,unsigned char ep)
{
unsigned short h;
unsigned short s,l;
int h,s,l;
COLOR_HSL hsl;
EmberStatus status = 0;
if(s_RgbCount >= 3){
//RGBtoHSL(&s_rgb,&hsl);
RGB_to_HSL_base(s_rgb.red, s_rgb.green, s_rgb.blue,h,s,l);
emberAfAppPrintln("[kk_zclColorControlMovetohueandsat]");
RGB_to_HSL(s_rgb.red, s_rgb.green, s_rgb.blue,&h,&s,&l);
emberAfAppPrintln("[kk_zclColorControlMovetohueandsat] h:%d,s:%d,l:%d\n,",h,s,l);
status = zclColorControlMovetohueandsat(node,ep,h*254/360,s*254/100,0,0,0,0);
status |= zclLevel_MoveToLevel(node,ep,l,0,NULL,NULL);
kk_device_table_s* dev = kk_device_find_by_node(node);
dev->manage.dev.ColorLighting.color.HSL.L = l;
dev->manage.dev.ColorLighting.CloorSetFlag = true;
emberAfAppPrintln("Save l:%d",l);
status = zclColorControlMovetohueandsat(node,ep,h*254,s*254,0,0,0,0);
s_RgbCount = 0;
}
return status;
return 0;
}
int kk_tsl_set_colorlight_RGB_red(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data)
{
......@@ -394,7 +388,6 @@ int kk_tsl_set_colorlight_mode(jrpc_context * ctx,EmberNodeId node,unsigned char
mode = kk_find_extra_data(node,"Mode");
while(mode!=NULL){
if(ix++==value){
kk_global_len = mode->len + 1;
kk_global_buffer[0] = mode->len;
memcpy(&kk_global_buffer[1],mode->data,kk_global_buffer[0] - 1);
......
#ifndef __KK_ZB_COM_H
#define __KK_ZB_COM_H
#include "app/framework/include/af.h"
#include "zb_device_id.h"
typedef struct
{
unsigned char CloorModeFlag;
unsigned char CapabilitiesFlag;
unsigned char CloorMode;
unsigned char Capabilities;
unsigned int time;
unsigned char CloorSetFlag;
union{
struct {
unsigned char HSL_flag;//bit 0:H; bit 1:S; bit 2:L
unsigned short H;
unsigned char S;
unsigned char L;
}HSL;
}color;
}ColorLighting_s;
typedef struct{
union{
ColorLighting_s ColorLighting;
}dev;
}SubDevManage_s;
typedef struct kk_device_table_s{
EmberEUI64 mac;
......@@ -10,6 +33,7 @@ typedef struct kk_device_table_s{
uint16_t deviceId;
uint16_t identifyCnt;
char productCode[33];
SubDevManage_s manage;
struct kk_device_table_s *next;
}kk_device_table_s;
......
......@@ -113,6 +113,33 @@ EmberStatus kk_zdo_leave_request(EmberNodeId target,bool removeChildren,bool rej
emberAfAppPrintln("Leave %p0x%X", "Request: ", status);
}
EmberStatus zclGReadAttrs(uint16_t node,
uint8_t srcEP,
uint8_t dstEP,
bool multicast,
uint16_t clusterId,
uint8_t len,
uint16_t* attrIds,
bool svr)
{
EmberStatus status;
zclBufferSetup(ZCL_GLOBAL_COMMAND | ((svr==true)?
ZCL_FRAME_CONTROL_CLIENT_TO_SERVER
:ZCL_FRAME_CONTROL_SERVER_TO_CLIENT),
clusterId,
ZCL_READ_ATTRIBUTES_COMMAND_ID);
for(uint8_t i=0;i<len;i++){
zclBufferAddByte(LOW_BYTE(attrIds[i]));
zclBufferAddByte(HIGH_BYTE(attrIds[i]));
}
rpcBufferPrint();
status = rpcSendCommand(node,srcEP,dstEP,multicast);
return status;
}
EmberStatus zclGRead(uint16_t node,
uint8_t srcEP,
......
......@@ -33,7 +33,7 @@ void kk_rpc_test(void);
#define KK_RPC_REPORT_FUNCTION_TABLE {\
{"kk_tsl_report_global_onoff",kk_tsl_report_global_onoff},\
{"kk_tsl_report_colorControl_Brightness",kk_tsl_report_colorControl_Brightness},\
{"kk_tsl_report_colorControl_RGB",kk_tsl_report_colorControl_RGB},\
{"kk_tsl_report_colorControl_RGB",kk_tsl_report_colorControl_RGB},\
}
kk_rpc_set_api_s kk_rpc_set_api[];
......@@ -155,6 +155,16 @@ EmberStatus zclGRead(uint16_t node,
uint16_t clusterId,
uint16_t attrId,
bool svr);
EmberStatus zclGReadAttrs(uint16_t node,
uint8_t srcEP,
uint8_t dstEP,
bool multicast,
uint16_t clusterId,
uint8_t len,
uint16_t* attrIds,
bool svr);
EmberStatus zclGWrite(uint16_t node,
uint8_t srcEP,
uint8_t dstEP,
......@@ -167,7 +177,6 @@ EmberStatus zclGWrite(uint16_t node,
bool svr);
EmberStatus zclOnOff_On(uint16_t node,uint8_t ep);
EmberStatus zclOnOff_Off(uint16_t node,uint8_t ep);
EmberStatus zclOnOff_Toggle(uint16_t node,uint8_t ep);
......
#include "sub_device_manage.h"
#include "kk_device_manager.h"
#include "kk_zb_com.h"
typedef void(*subDevManageFunc)(kk_device_table_s* dev);
typedef struct{
uint16_t deviceId;
subDevManageFunc func;
}SubDevDispatch_s;
void kk_ColorLighting_manage(kk_device_table_s* dev);
SubDevDispatch_s SubDevDispatch[] = {
{DEVICE_ID_HA_DIMMABLE_LIGHT,kk_ColorLighting_manage},
{DEVICE_ID_HA_COLOR_DIMMABLE_LIGHT,kk_ColorLighting_manage},
};
static int report_colorLighting_RGB(kk_device_table_s* dev)
{
kk_dev_config_map *dev_info = NULL;
kk_dev_config_item *item = NULL;
cJSON *root;
int rev = 0;
int startIdx = 0;
cJSON* root_color = NULL;
char tmp_Identity[64] = {0};
emberAfCorePrintln("[report_colorLighting_RGB] %d",__LINE__);
unsigned short H = dev->manage.dev.ColorLighting.color.HSL.H;
unsigned char S = dev->manage.dev.ColorLighting.color.HSL.S;
unsigned char L = dev->manage.dev.ColorLighting.color.HSL.L;
unsigned char red,green,blue;
HSL_to_RGB(H,S,L,&red,&green,&blue);
emberAfAppPrintln("%d,%d,%d",H,S,L);
emberAfAppPrintln("%d,%d,%d",red,green,blue);
dev_info = kk_device_config_find(dev->productCode);
if(dev_info == NULL){
return tsl_rpt_err;
}
item = &dev_info->item;
while(item!=NULL){
if(strstr(item->identity,".red") != NULL){
if(root_color == NULL){
root_color = rpc_cJSON_CreateObject();
}
rev = kk_tsl_utils_memtok(item->identity,'.',1,&startIdx);
if(!rev){
memcpy(tmp_Identity,item->identity,startIdx);
rpc_cJSON_AddNumberToObject(root_color, item->identity + 1 + startIdx,red);
}
}
else if(strstr(item->identity,".green") != NULL){
if(root_color == NULL){
root_color = rpc_cJSON_CreateObject();
}
rev = kk_tsl_utils_memtok(item->identity,'.',1,&startIdx);
if(!rev){
memcpy(tmp_Identity,item->identity,startIdx);
rpc_cJSON_AddNumberToObject(root_color, item->identity + 1 + startIdx,green);
}
}
else if(strstr(item->identity,".blue") != NULL){
if(root_color == NULL){
root_color = rpc_cJSON_CreateObject();
}
rev = kk_tsl_utils_memtok(item->identity,'.',1,&startIdx);
if(!rev){
memcpy(tmp_Identity,item->identity,startIdx);
rpc_cJSON_AddNumberToObject(root_color, item->identity + 1 + startIdx,blue);
}
}
item = item->next;
}
if(root_color != NULL){
root = rpc_cJSON_CreateObject();
rpc_cJSON_AddItemToObject(root,tmp_Identity,root_color);
kk_msg_report_property(root,dev->mac);
return tsl_rpt_success;
}
return tsl_rpt_err;
}
void kk_colorlight_attr_read(uint16_t nodeId,
uint8_t ep,
uint16_t cluster,
uint16_t attribute,
uint8_t status,
uint8_t dataType,
uint8_t dataSize,
uint8_t *data)
{
kk_device_table_s* dev;
ColorLighting_s *ptr;
if(cluster!=ZCL_COLOR_CONTROL_CLUSTER_ID) return ;
if(ep!=KK_PRIMARY_EP) return ;
UTIL_LOG_INFO("\n********************kk_colorlight_attr_read********************\n");
dev = kk_device_find_by_node(nodeId);
if(dev ==NULL) return ;
ptr = &dev->manage.dev.ColorLighting;
if(attribute==ZCL_COLOR_CONTROL_COLOR_MODE_ATTRIBUTE_ID){
if(status == EMBER_ZCL_STATUS_SUCCESS){
ptr->CloorModeFlag = DevManage_Success;
ptr->CloorMode = *data;
emberAfCorePrintln("[CloorMode]val:%d",*data);
}else if(status == EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE){
ptr->CloorModeFlag = DevManage_NotSupport;
emberAfCorePrintln("[CloorMode]not support!!!");
}else{
ptr->CloorModeFlag = DevManage_Fail;
emberAfCorePrintln("[CloorMode]fail,status=0X%X!!!",status);
}
}
if(attribute==ZCL_COLOR_CONTROL_COLOR_CAPABILITIES_ATTRIBUTE_ID){
if(status == EMBER_ZCL_STATUS_SUCCESS){
ptr->CapabilitiesFlag = DevManage_Success;
ptr->Capabilities = *data;
emberAfCorePrintln("[Capabilities]val:%d",*data);
}else if(status == EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE){
ptr->CapabilitiesFlag = DevManage_NotSupport;
emberAfCorePrintln("[Capabilities]not support!!!");
}else{
ptr->CapabilitiesFlag = DevManage_Fail;
emberAfCorePrintln("[Capabilities]fail,status=0X%X!!!",status);
}
}
}
void kk_ColorLighting_manage(kk_device_table_s* dev)
{
EmberAfStatus status;
ColorLighting_s *ptr;
if(dev == NULL) return ;
ptr = &dev->manage.dev.ColorLighting;
uint32_t time = halCommonGetInt32uMillisecondTick();
if(ptr->CloorModeFlag==DevManage_Unkown ||
ptr->CapabilitiesFlag==DevManage_Unkown){
uint16_t attr[2] = {ZCL_COLOR_CONTROL_COLOR_MODE_ATTRIBUTE_ID,ZCL_COLOR_CONTROL_COLOR_CAPABILITIES_ATTRIBUTE_ID};
status = zclGReadAttrs(dev->nodeId,1,1,false,ZCL_COLOR_CONTROL_CLUSTER_ID,2,attr,true);
emberAfCorePrintln("[ColorLighting_manage] read mode and capabilities from 0x%04X",dev->nodeId);
}
if(ptr->color.HSL.HSL_flag!=0){
if(ptr->time != 0){
if((time-ptr->time) >= 1000*3){
if(ptr->CloorSetFlag==true && ptr->color.HSL.HSL_flag==0x03){
report_colorLighting_RGB(dev);
ptr->CloorSetFlag = false;
emberAfCorePrintln("$$$$$$$$[ColorLighting_manage] %d",__LINE__);
return;
}
ptr->time = 0;
ptr->color.HSL.HSL_flag = 0;
ptr->CloorSetFlag = false;
emberAfCorePrintln("!!!!!!!!!![ColorLighting_manage] %d",__LINE__);
return;
}
}
if(ptr->CloorSetFlag==true && ptr->color.HSL.HSL_flag==0x07){
report_colorLighting_RGB(dev);
ptr->CloorSetFlag = false;
ptr->color.HSL.HSL_flag = 0;
ptr->time = 0;
emberAfCorePrintln("@@@@@@@@@@[ColorLighting_manage] %d",__LINE__);
return;
}
}
}
void kk_sub_dev_manage(void)
{
static uint32_t LastTime;
uint32_t time = halCommonGetInt32uMillisecondTick();
kk_device_table_s *ptr = kk_get_device_table_pointer();
if((time-LastTime)>=1000){
LastTime = time;
while(ptr!=NULL){
for(int i=0;i<sizeof(SubDevDispatch)/sizeof(SubDevDispatch_s);i++){
if(ptr->deviceId == SubDevDispatch[i].deviceId && SubDevDispatch[i].func!=NULL){
SubDevDispatch[i].func(ptr);
}
}
ptr = ptr->next;
}
}
}
#ifndef __SUB_DEVICE_MANAGE_H
#define __SUB_DEVICE_MANAGE_H
#include "kk_zb_com.h"
typedef enum {
ColorMode_HSL = 0x00,
ColorMode_XY = 0x01,
ColorMode_Temperature = 0x02
}ColorModeAttrVal;
typedef enum{
DevManage_Unkown = 0x00,
DevManage_Success = 0x01,
DevManage_NotSupport = 0x02,
DevManage_Fail = 0x03,
}DevManageAttrEnum;
void kk_colorlight_attr_read(uint16_t nodeId,
uint8_t ep,
uint16_t cluster,
uint16_t attribute,
uint8_t status,
uint8_t dataType,
uint8_t dataSize,
uint8_t *data);
void kk_ColorLighting_manage(kk_device_table_s* dev);
#endif
......@@ -200,6 +200,7 @@ void emberAfMainTickCallback(void)
static unsigned int last_time;
unsigned int time = halCommonGetInt32uMillisecondTick();
kk_sub_dev_manage();
if((time-last_time)>=3000){
last_time = time;
......
......@@ -12,7 +12,7 @@
#include "kk_tsl_property_set.h"
#include "kk_msg_report.h"
#include "kk_device_table_db.h"
#include "sub_device_manage.h"
#define KK_REPORT_DEVICE_JOINED_TYPE "/thing/topo/add"
......
......@@ -849,8 +849,8 @@ bool rpc_ReadAttributesResponseCallback(EmberAfClusterId clusterId,
free(bufferTemp);
}else{
rpc_cJSON_AddStatusToObject(item_attr,Status);
bufferSize += 2;
emberAfAppPrintln("Status=%d\n",Status);
bufferSize += 3;
emberAfAppPrintln("Status=0x%X\n",Status);
attributeId = HIGH_LOW_TO_INT(bufferPtr[ATTRIBUTE_BUFFER_ATTRIBUTEID_HIGH_BITS],bufferPtr[ATTRIBUTE_BUFFER_ATTRIBUTEID_LOW_BITS]);
kk_read_attr_response(nodeId,
ep,
......
......@@ -110,8 +110,31 @@ void kk_message_process(char *messageString)
test_123(cnt);
}
if(MEMCOMPARE(messageString,"AT+COLOR\r\n",len)==0){
//zclColorControlMovetohueandsat(node,ep,h,s,0,0,0,0);
if(MEMCOMPARE(messageString,"AT+TEST1\r\n",len)==0){
uint16_t h;
unsigned char s,l;
RGB_to_HSL(100, 150, 200,&h,&s,&l);
emberAfAppPrintln("%d,%d,%d",h,s,l);
emberAfAppPrintln("%d,%d,%d",h*254/360,s*254/100,l);
kk_device_table_s* dev = kk_device_find_by_node(0x5996);
dev->manage.dev.ColorLighting.color.HSL.L = l;
zclLevel_MoveToLevel(0x5996,1,l,0,NULL,NULL);
zclColorControlMovetohueandsat(0x5996,1,h*254/360,s*254/100,0,0,0,0);
emberAfAppPrint("AT+TEST1\r\n" );
}
if(MEMCOMPARE(messageString,"AT+TEST2\r\n",len)==0){
uint16_t h;
unsigned char s,l;
RGB_to_HSL(20, 24, 22,&h,&s,&l);
emberAfAppPrintln("%d,%d,%d",h,s,l);
emberAfAppPrintln("%d,%d,%d",h*254/360,s*254/100,l);
kk_device_table_s* dev = kk_device_find_by_node(0x5996);
dev->manage.dev.ColorLighting.color.HSL.L = l;
zclLevel_MoveToLevel(0x5996,1,l,0,NULL,NULL);
zclColorControlMovetohueandsat(0x5996,1,h*254/360,s*254/100,0,0,0,0);
emberAfAppPrint("AT+TEST2\r\n" );
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -28,7 +28,7 @@
#include "app/util/serial/command-interpreter2.h"
#include "app/util/zigbee-framework/zigbee-device-common.h"
#include "network-cli.h"
#include "kk_zb_com.h"
#define emberAfAppPrint(...) emberAfPrint(EMBER_AF_PRINT_APP, __VA_ARGS__)
......
......@@ -33,7 +33,7 @@ void halInit(void)
void setMicroRebootHandler(void (*handler)(void))
{
microRebootHandler = handler;
microRebootHandler = handler;
}
void halReboot(void)
......
typedef enum {
EMBER_AF_FILE_DESCRIPTOR_OPERATION_NONE = 0x00,
EMBER_AF_FILE_DESCRIPTOR_OPERATION_READ = 0x01,
EMBER_AF_FILE_DESCRIPTOR_OPERATION_WRITE = 0x02,
EMBER_AF_FILE_DESCRIPTOR_OPERATION_EXCEPT = 0x03,
EMBER_AF_FILE_DESCRIPTOR_OPERATION_MAX
EMBER_AF_FILE_DESCRIPTOR_OPERATION_NONE = 0x00,
EMBER_AF_FILE_DESCRIPTOR_OPERATION_READ = 0x01,
EMBER_AF_FILE_DESCRIPTOR_OPERATION_WRITE = 0x02,
EMBER_AF_FILE_DESCRIPTOR_OPERATION_EXCEPT = 0x03,
EMBER_AF_FILE_DESCRIPTOR_OPERATION_MAX
} EmberAfFileDescriptorOperation;
typedef void (*EmberAfFileDescriptorReadyCallback)(void* data, EmberAfFileDescriptorOperation operation);
typedef struct {
EmberAfFileDescriptorReadyCallback callback;
void* dataPassedToCallback;
EmberAfFileDescriptorOperation operation;
int fileDescriptor;
EmberAfFileDescriptorReadyCallback callback;
void* dataPassedToCallback;
EmberAfFileDescriptorOperation operation;
int fileDescriptor;
} EmberAfFileDescriptorDispatchStruct;
EmberStatus emberAfPluginFileDescriptorDispatchAdd(EmberAfFileDescriptorDispatchStruct* dispatchStruct);
......
......@@ -147,16 +147,16 @@ void emberAfPluginGatewayTickCallback(void)
void emberAfPluginGatewayInitCallback(void)
{
int fdList[MAX_FDS];
int count = 0;
int i;
EmberAfFileDescriptorDispatchStruct dispatchStruct = {
NULL, // callback
NULL, // data passed to callback
EMBER_AF_FILE_DESCRIPTOR_OPERATION_READ,
-1,
};
dispatchStruct.fileDescriptor = emberSerialGetInputFd(0);
int count = 0;
int i;
EmberAfFileDescriptorDispatchStruct dispatchStruct = {
NULL, // callback
NULL, // data passed to callback
EMBER_AF_FILE_DESCRIPTOR_OPERATION_READ,
-1,
};
dispatchStruct.fileDescriptor = emberSerialGetInputFd(0);
if (dispatchStruct.fileDescriptor != -1
&& EMBER_SUCCESS != emberAfPluginFileDescriptorDispatchAdd(&dispatchStruct)) {
emberAfCorePrintln("Error: Gateway Plugin failed to register serial Port 0 FD");
......@@ -165,7 +165,7 @@ void emberAfPluginGatewayInitCallback(void)
#if defined(ZA_CLI_FULL)
if (dispatchStruct.fileDescriptor != -1
&& EMBER_SUCCESS != emberAfPluginFileDescriptorDispatchAdd(&dispatchStruct)) {
emberAfCorePrintln("Error: Gateway Plugin failed to register serial Port 1 FD");
emberAfCorePrintln("Error: Gateway Plugin failed to register serial Port 1 FD");
}
#endif
// For SPI, we need the nHOST_INT line as well
......@@ -245,7 +245,7 @@ static void ezspSerialPortCallback(EzspSerialPortEvent event, int fileDescriptor
fileDescriptor,
};
debugPrint("Registered EZSP FD %d", fileDescriptor);
debugPrint("Registered EZSP FD %d", fileDescriptor);
if (EMBER_SUCCESS != emberAfPluginFileDescriptorDispatchAdd(&dispatchStruct)) {
emberAfCorePrintln("Error: Gateway Plugin failed to register EZSP FD %d", fileDescriptor);
}
......
......@@ -1209,7 +1209,10 @@ void emAfCliVersionCommand(void)
if (ncpStackType != EZSP_STACK_TYPE_MESH) {
emberAfAppPrint("ERROR: stack type 0x%x is not expected!",
ncpStackType);
assert(false);
ezspErrorHandler(EZSP_ASH_NCP_FATAL_ERROR);
UTIL_LOG_ERR("\n!!!!!!!!!!!!!ncpStackType != EZSP_STACK_TYPE_MESH!!!!!!!!!\n");
//assert(false);
}
// verify that the NCP EZSP Protocol version is what is expected
......
......@@ -87,8 +87,8 @@ static int STDIN = 0;
// is the pipe number. The first two are the data pipes,
// the second two are the control pipes.
static int pipeFileDescriptors[NUM_PORTS][4] = {
{ INVALID_FD, INVALID_FD, INVALID_FD, INVALID_FD },
{ INVALID_FD, INVALID_FD, INVALID_FD, INVALID_FD }
{ INVALID_FD, INVALID_FD, INVALID_FD, INVALID_FD },
{ INVALID_FD, INVALID_FD, INVALID_FD, INVALID_FD }
};
#define DATA_READER(__port) pipeFileDescriptors[(__port)][0]
#define DATA_WRITER(__port) pipeFileDescriptors[(__port)][1]
......@@ -212,81 +212,81 @@ EmberStatus emberSerialInit(uint8_t port,
static EmberStatus serialInitInternal(uint8_t port)
{
// Create two pipes, control and data.
// Fork
// Parent closes the write end of the data pipe and read end of the control,
// child closes the read end of the data pipe and write end of the control.
// Child sits and waits for input via readline() (or read())
// When it receives input it writes it to the data pipe. It then blocks
// on a read call to the control pipe (if it is running the CLI).
// Parent loops normally, calling emberSerialReadByte() or emberSeriaReadLine()
// to get the input. These calls map to reads of the data pipe, the former
// would NOT be blocking while the latter would be.
// Parent calls indirectly readyForSerialInput() after reading an entire
// line of data (via the next emberSerialReadByte()).
// Create two pipes, control and data.
// Fork
// Parent closes the write end of the data pipe and read end of the control,
// child closes the read end of the data pipe and write end of the control.
// Child sits and waits for input via readline() (or read())
// When it receives input it writes it to the data pipe. It then blocks
// on a read call to the control pipe (if it is running the CLI).
// Parent loops normally, calling emberSerialReadByte() or emberSeriaReadLine()
// to get the input. These calls map to reads of the data pipe, the former
// would NOT be blocking while the latter would be.
// Parent calls indirectly readyForSerialInput() after reading an entire
// line of data (via the next emberSerialReadByte()).
int status;
int i;
pid_t pid;
for (i = 0; i < 2; i++) {
char* string = (i == 0
? "data"
: "control");
int* pipePtr = (i == 0
? &(pipeFileDescriptors[port][0])
: &(pipeFileDescriptors[port][2]));
status = pipe(pipePtr);
if (status != 0) {
fprintf(stderr,
"FATAL: Could not create %s pipe (%d): %s",
string,
status,
strerror(status));
assert(false);
}
debugPrint("Serial Port %d, Created %s Pipe, Reader: %d, Writer %d\n",
port,
string,
pipePtr[0],
pipePtr[1]);
}
// Change the data reader to non-blocking so that we will
// continue to be able to execute ezspTick().
setNonBlockingFD(DATA_READER(port));
pid = fork();
if (pid == 0) { // Child
amParent = false;
while (debugChildProcess) {
// block indefinitely waiting for debugger to attach
sleep(1);
}
childRun(port);
return EMBER_ERR_FATAL; // should never get here
} else if (pid == -1) {
fprintf(stderr, "FATAL: Could not fork! (%d): %s\n",
errno,
strerror(errno));
assert(false);
}
// Parent
debugPrint("fork(): My child's pid is %d\n", pid);
// BugzId:12928 Parent retains allCommands for other children it might spawn
close(DATA_WRITER(port));
close(CONTROL_READER(port));
DATA_WRITER(port) = INVALID_FD;
CONTROL_READER(port) = INVALID_FD;
// BugzId:12928 Leave STDIN open for subsequent forked children to use
childPid[port] = pid;
setMicroRebootHandler(&emberSerialCleanup);
return EMBER_SUCCESS;
pid_t pid;
for (i = 0; i < 2; i++) {
char* string = (i == 0
? "data"
: "control");
int* pipePtr = (i == 0
? &(pipeFileDescriptors[port][0])
: &(pipeFileDescriptors[port][2]));
status = pipe(pipePtr);
if (status != 0) {
fprintf(stderr,
"FATAL: Could not create %s pipe (%d): %s",
string,
status,
strerror(status));
assert(false);
}
debugPrint("Serial Port %d, Created %s Pipe, Reader: %d, Writer %d\n",
port,
string,
pipePtr[0],
pipePtr[1]);
}
// Change the data reader to non-blocking so that we will
// continue to be able to execute ezspTick().
setNonBlockingFD(DATA_READER(port));
pid = fork();
if (pid == 0) { // Child
amParent = false;
while (debugChildProcess) {
// block indefinitely waiting for debugger to attach
sleep(1);
}
childRun(port);
return EMBER_ERR_FATAL; // should never get here
} else if (pid == -1) {
fprintf(stderr, "FATAL: Could not fork! (%d): %s\n",
errno,
strerror(errno));
assert(false);
}
// Parent
debugPrint("fork(): My child's pid is %d\n", pid);
// BugzId:12928 Parent retains allCommands for other children it might spawn
close(DATA_WRITER(port));
close(CONTROL_READER(port));
DATA_WRITER(port) = INVALID_FD;
CONTROL_READER(port) = INVALID_FD;
// BugzId:12928 Leave STDIN open for subsequent forked children to use
childPid[port] = pid;
setMicroRebootHandler(&emberSerialCleanup);
return EMBER_SUCCESS;
}
// Checks to see if there is a remote connection in place, or if a new
......@@ -385,35 +385,35 @@ void emberSerialSetPrompt(const char* thePrompt)
static void setNonBlockingFD(int fd)
{
int flags = fcntl(fd, F_GETFL);
int status = fcntl(fd, F_SETFD, flags | O_NONBLOCK);
if (status != 0) {
fprintf(stderr,
"FATAL: Could not set pipe reader to non-blocking (%d): %s\n",
errno,
strerror(errno));
assert(false);
}
int flags = fcntl(fd, F_GETFL);
int status = fcntl(fd, F_SETFD, flags | O_NONBLOCK);
if (status != 0) {
fprintf(stderr,
"FATAL: Could not set pipe reader to non-blocking (%d): %s\n",
errno,
strerror(errno));
assert(false);
}
}
// It is expected this is only called within the parent process.
void emberSerialCleanup(void)
{
uint8_t port;
for (port = 0; port < 2; port++) {
if (childPid[port] != INVALID_PID) {
int status;
close(DATA_READER(port));
close(CONTROL_WRITER(port));
DATA_READER(port) = INVALID_FD;
CONTROL_WRITER(port) = INVALID_FD;
debugPrint("Waiting for child on port %d to terminate.\n", port);
kill(childPid[port], SIGTERM);
wait(&status);
debugPrint("Child on port %d exited with status: %d\n", port, status);
childPid[port] = INVALID_PID;
}
}
uint8_t port;
for (port = 0; port < 2; port++) {
if (childPid[port] != INVALID_PID) {
int status;
close(DATA_READER(port));
close(CONTROL_WRITER(port));
DATA_READER(port) = INVALID_FD;
CONTROL_WRITER(port) = INVALID_FD;
debugPrint("Waiting for child on port %d to terminate.\n", port);
kill(childPid[port], SIGTERM);
wait(&status);
debugPrint("Child on port %d exited with status: %d\n", port, status);
childPid[port] = INVALID_PID;
}
}
gatewayBackchannelStop();
}
......@@ -490,10 +490,10 @@ void emberSerialCommandCompletionInitCli(cliSerialCmdEntry cliCmdList[],
int emberSerialGetInputFd(uint8_t port)
{
if (port > (NUM_PORTS - 1)) {
return INVALID_FD;
}
return DATA_READER(port);
if (port > (NUM_PORTS - 1)) {
return INVALID_FD;
}
return DATA_READER(port);
}
static bool readyForSerialInput(uint8_t port)
......@@ -1279,27 +1279,27 @@ static void signalHandler(int signal)
static void installSignalHandler(void)
{
int i = 0;
int signals[] = { SIGTERM, SIGINT, SIGPIPE, SIGTTIN, SIGTTOU, 0 };
struct sigaction sigAction;
MEMSET(&sigAction, 0, sizeof(struct sigaction));
sigAction.sa_handler = signalHandler;
while (signals[i] != 0) {
if (-1 == sigaction(signals[i], &sigAction, NULL)) {
debugPrint("Could not install signal handler.\n");
} else {
const char* signalName = strsignal(signals[i]);
debugPrint("%s installed signal handler for %s (%d).\n",
(amParent ? "Parent" : "Child"),
(signalName == NULL
? "???"
: signalName),
signals[i]);
}
i++;
}
int i = 0;
int signals[] = { SIGTERM, SIGINT, SIGPIPE, SIGTTIN, SIGTTOU, 0 };
struct sigaction sigAction;
MEMSET(&sigAction, 0, sizeof(struct sigaction));
sigAction.sa_handler = signalHandler;
while (signals[i] != 0) {
if (-1 == sigaction(signals[i], &sigAction, NULL)) {
debugPrint("Could not install signal handler.\n");
} else {
const char* signalName = strsignal(signals[i]);
debugPrint("%s installed signal handler for %s (%d).\n",
(amParent ? "Parent" : "Child"),
(signalName == NULL
? "???"
: signalName),
signals[i]);
}
i++;
}
}
//------------------------------------------------------------------------------
......@@ -1307,12 +1307,12 @@ static void installSignalHandler(void)
static void debugPrint(const char* formatString, ...)
{
if (debugOn) {
va_list ap = { 0 };
fprintf(stderr, "[linux-serial debug] ");
va_start(ap, formatString);
vfprintf(stderr, formatString, ap);
va_end(ap);
fflush(stderr);
}
if (debugOn) {
va_list ap = { 0 };
fprintf(stderr, "[linux-serial debug] ");
va_start(ap, formatString);
vfprintf(stderr, formatString, ap);
va_end(ap);
fflush(stderr);
}
}
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