2015-02-27 星期五 21:52:42
代码见TI中自带的 Sapi.c SimpleCollector.c SimpleSwitch.c。
1、协调器建立网络流程
见上一篇。
2、开关加入网络流程
见上一篇。
3、绑定
-
流程
-
代码跟踪
采集节点(协调器)允许绑定,zb_AllowBind( 0xFF );
终端请求绑定,zb_BindDevice(TRUE, TOGGLE_LIGHT_CMD_ID, NULL);
3、通讯
-
终端(switch)发送
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
void
zb_HandleKeys( uint8 shift, uint8 keys )
{
......
// Send the command to toggle light
zb_SendDataRequest( 0xFFFE, TOGGLE_LIGHT_CMD_ID, 0,
(uint8 *)NULL, myAppSeqNumber, 0, 0 );
......
}
void
zb_SendDataRequest ( uint16 destination, uint16 commandId, uint8 len,
uint8 *pData, uint8 handle, uint8 txOptions, uint8 radius )
{
......
//zlz,采用绑定的方式
// Set the destination address
if
(destination == ZB_BINDING_ADDR)
{
// Binding
dstAddr.addrMode = afAddrNotPresent;
}
else
{
// Use short address
dstAddr.addr.shortAddr = destination;
dstAddr.addrMode = afAddr16Bit;
if
( ADDR_NOT_BCAST != NLME_IsAddressBroadcast( destination ) )
{
txOptions &= ~AF_ACK_REQUEST;
}
}
......
......
// Send the message
status = AF_DataRequest(&dstAddr, &sapi_epDesc, commandId, len,
pData, &handle, txOptions, radius);
......
}
|
-
采集节点(协调器)接收
1
2
3
4
5
6
7
8
9
10
11
|
UINT16 SAPI_ProcessEvent( byte task_id, UINT16 events )
{
......
case
AF_INCOMING_MSG_CMD:
pMSGpkt = (afIncomingMSGPacket_t *) pMsg;
SAPI_ReceiveDataIndication( pMSGpkt->srcAddr.addr.shortAddr, pMSGpkt->clusterId,
pMSGpkt->cmd.DataLength, pMSGpkt->cmd.Data);
break
;
......
}
|