📄 light.c
字号:
if (puTransactionInd->uFrame.sKvp.eCommandTypeID == SET_ACKNOWLEDGMENT)
{
bReturnVal = TRUE;
}
/* check command frame is valid and for correct endpoint*/
if ( (eAddrMode != APS_ADDRMODE_NOT_PRESENT)
|| (u8DstEP != sLight.u8Endpoint))
{
puTransactionRsp->uFrame.sKvp.eErrorCode = KVP_INVALID_ENDPOINT;
return bReturnVal;
}
/* only accept SET commands */
if (puTransactionInd->uFrame.sKvp.eCommandTypeID != SET)
{
puTransactionRsp->uFrame.sKvp.eErrorCode = KVP_INVALID_COMMAND_TYPE;
return bReturnVal;
}
/* Check node is actually bound to another */
if (sLight.eBound != E_BIND_BOUND)
{
puTransactionRsp->uFrame.sKvp.eErrorCode = KVP_INVALID_ENDPOINT;
return bReturnVal;
}
/* Extract data and control switch */
if (puTransactionInd->uFrame.sKvp.u16AttributeID == ATTRIBUTE_ON_OFF)
{
if (puTransactionInd->uFrame.sKvp.uAttributeData.UnsignedInt8 == VALUE_ON)
{
vLedControl(LED2, TRUE);
}
else if (puTransactionInd->uFrame.sKvp.uAttributeData.UnsignedInt8 == VALUE_OFF)
{
vLedControl(LED2, FALSE);
}
else
{
puTransactionRsp->uFrame.sKvp.eErrorCode = KVP_INVALID_ATTRIBUTE_DATA;
return bReturnVal;
}
puTransactionRsp->uFrame.sKvp.eErrorCode = KVP_SUCCESS;
return bReturnVal;
}
else
{
puTransactionRsp->uFrame.sKvp.eErrorCode = KVP_UNSUPPORTED_ATTRIBUTE;
return bReturnVal;
}
}
/****************************************************************************
*
* NAME: JZA_vAfKvpResponse
*
* DESCRIPTION:
* Used to send response to incoming KVP frame
*
* PARAMETERS: Name RW Usage
* eAddrMode R Address mode of incoming frame
* u16AddrSrc R Network address of source node
* u8SrcEP R Endpoint address of source node
* u8LQI R Link Quality Indication
* u8DstEP R Destination endpoint address
* u8ClusterId R Cluster ID of incoming frame
* *puTransactionInd R Pointer to incoming frame
*
* RETURNS:
* void
*
****************************************************************************/
PUBLIC void JZA_vAfKvpResponse(APS_Addrmode_e eAddrMode,
uint16 u16AddrSrc,
uint8 u8SrcEP,
uint8 u8LQI,
uint8 u8DstEP,
uint8 u8ClusterID,
AF_Transaction_s *puTransactionInd)
{
}
/****************************************************************************
*
* NAME: JZA_pu8AfMsgObject
*
* DESCRIPTION:
* Receives incoming MSG data frames.
*
* PARAMETERS: Name RW Usage
* eAddrMode R Address mode of incoming frame
* u16AddrSrc R Network address of source node
* u8SrcEP R Endpoint address of source node
* u8LQI R Link Quality Indication
* u8DstEP R Destination endpoint address
* u8ClusterId R Cluster ID of incoming frame
* *pu8ClusterIDRsp R Pointer to cluster ID of response frame
* *puTransactionInd R Pointer to incoming frame
* *puTransactionRsp R Pointer to response frame
* RETURNS:
* FALSE
*
****************************************************************************/
PUBLIC bool_t JZA_bAfMsgObject(APS_Addrmode_e eAddrMode,
uint16 u16AddrSrc,
uint8 u8SrcEP,
uint8 u8LQI,
uint8 u8DstEP,
uint8 u8ClusterID,
uint8 *pu8ClusterIDRsp,
AF_Transaction_s *puTransactionInd,
AF_Transaction_s *puTransactionRsp)
{
return FALSE;
}
/****************************************************************************
*
* NAME: JZA_vZdpResponse
*
* DESCRIPTION:
* Receives responses to Binding or MatchDescriptor requests
*
* PARAMETERS: Name RW Usage
* u8Type R Type of response
* u8LQI R Link Quality Indication
* *pu8Payload R Pointer to response
* u8PayloadLen R Length of response
*
* RETURNS:
* void
*
****************************************************************************/
PUBLIC void JZA_vZdpResponse(uint8 u8Type, uint8 u8Lqi, uint8 *pu8Payload,
uint8 u8PayloadLen)
{
/* if already matched with another node, ignore any incoming responses */
if (sLight.eBound != E_BIND_BINDING)
{
return;
}
switch (u8Type)
{
case ZDP_MatchDescRsp:
/* this would be used to receive responses if a Match Descriptor Request
had been used */
break;
case ZDP_EndDeviceBindRsp:
/* response to an End Device Bind request has been received. Can now
start operating as a light. Turn off LED to indicate successful matching */
if (pu8Payload[0] == ZDP_SUCCESS_VALID)
{
sLight.eBound = E_BIND_BOUND;
vLedControl(LED2, FALSE);
}
else
{
sLight.eBound = E_BIND_NONE;
}
break;
default:
break;
}
}
/****************************************************************************
*
* NAME: JZA_vStackEvent
*
* DESCRIPTION:
* Used to receive additional stack events such as Data Request confirm
*
* PARAMETERS: Name RW Usage
* eEventId R ID number of stack event
* *puStackEvent R Pointer to union containing
* stack event data
*
* RETURNS:
* void
*
****************************************************************************/
PUBLIC void JZA_vStackEvent(teJZS_EventIdentifier eEventId,
tuJZS_StackEvent *puStackEvent)
{
if (eEventId == JZS_EVENT_NWK_JOINED_AS_ROUTER)
{
sLight.bStackReady = TRUE;
vAddDesc();
}
}
/****************************************************************************/
/*** Local Functions ***/
/****************************************************************************/
/****************************************************************************
*
* NAME: vInit
*
* DESCRIPTION:
* Initialises the hardware
*
* RETURNS:
* void
*
****************************************************************************/
PRIVATE void vInit(void)
{
/* Initialise buttons, LEDs and program variables */
vButtonInitRfd();
vLedInitRfd();
vLedControl(LED1, TRUE);
vLedControl(LED2, TRUE);
sLight.eBound = E_BIND_NONE;
sLight.u8Endpoint = 0x31;
sLight.bStackReady = FALSE;
}
/****************************************************************************
*
* NAME: vPerformEndBindRequest
*
* DESCRIPTION:
* Sends a request to the coordinator to bind the node with another.
*
*
* RETURNS:
* void
*
****************************************************************************/
PRIVATE void vPerformEndBindRequest(uint8 u8Endpoint)
{
AF_SIMPLE_DESCRIPTOR *pAfSimpleDesc;
uint16 u16BindingTarget = 0x0000;
/* recall endpoints simple descriptor from the application framework */
pAfSimpleDesc = afmeSearchEndpoint(u8Endpoint);
/* create and send a request for binding */
if(pAfSimpleDesc)
{
zdpEndDeviceBindReq(u16BindingTarget,
pAfSimpleDesc->u8EndPoint,
pAfSimpleDesc->u16ProfileId,
pAfSimpleDesc->u8OutClusterCount,
pAfSimpleDesc->au8OutClusterList,
pAfSimpleDesc->u8InClusterCount,
pAfSimpleDesc->au8InClusterList,
APS_TXOPTION_NONE);
}
/* update programs biding state variable */
sLight.eBound = E_BIND_BINDING;
}
/****************************************************************************
*
* NAME: vAddDesc
*
* DESCRIPTION:
* Adds simple descriptor
*
*
* RETURNS:
* void
*
****************************************************************************/
PRIVATE void vAddDesc(void)
{
/* Define simple descriptor for the Light's endpoint according to
the ZigBee Home Control, Lighting Public Profile */
uint8 u8DeviceVer = DEVICEVERSION;
uint16 u16ProfileId = PROFILEID_HC;
uint8 u8Flags = 0x00;
uint8 u8EndPoint = sLight.u8Endpoint;
uint16 u16DeviceId = DEVICEID_HCL_SRC;
/* Light has 1 endpoint, with 1 input cluster */
uint8 u8InputClusterCnt = 1;
uint8 au8InputClusterList[] = {CLUSTERID_ON_OFF_SRC};
uint8 u8OutputClusterCnt = 0;
uint8 au8OutputClusterList[] = {};
(void)afmeAddSimpleDesc(u8EndPoint, u16ProfileId, u16DeviceId,
u8DeviceVer, u8Flags, u8InputClusterCnt,
au8InputClusterList, u8OutputClusterCnt,
au8OutputClusterList);
}
/****************************************************************************/
/*** END OF FILE ***/
/****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -