zigbee进阶分析
九、邻居列表,路由列表,绑定列表
1.表的大小
邻居列表,路由列表,绑定列表的大小在stack里设定,单位是条目(entry)
Neighbour and Routing table sizes要与HCL Profile相符。
2.读取邻居列表
下面程序代码给出了如何进入邻居列表,读取邻居列表中end device的个数
#include “TablesCoordRouter.h”
#include “nwk.h”
PRIVATE void vReadNeighbourTable(void)
{
int i;
for (i = 0; i < gsNIB.nwkNeighborTableSize; i++)
{
if ( (gsNIB.nwkNeighborTable.eDevicetype ==ZIGBEE_ENDDEVICE)&& (gsNIB.nwkNeighborTable.eRelationship ==NEIGHBOR_CHILD)&& (gsNIB.nwkNeighborTable.u16Addr!= 0xffff))
{
u8NeighbourListCount++;
}
}
}
如果换做是End device上读取邻居列表,那么头文件TablesCoordRouter.h应该将换成TablesED.h
The Neighbour table structure NWK_NeighborTable_s is defined in nwk.h.
3.读取和清除路由表Reading and Purging Routing Tables
路由表资源有限,当节点上的路由表满了之后,如果目的节点不再路由表中,此时向目的节点发数据,可以通过树发送。
下面的代码是监视路由表,在路由表满了之后进行清除操作。
#include “TablesCoordRouter.h”
#include “nwk.h”
PRIVATE void vCheckRoutingTable(void)
{
int i;
bool_t bAllEntriesActive = TRUE;
for (i = 0; i < gsNIB.nwkRoutingTableSize; i++)
{
if (gsNIB.nwkRoutingTable.eStatus != ACTIVE)检查每一条路由条目是否活跃
{
bAllEntriesActive = FALSE;只要有一条路由条目不是处于活跃状态,
}
}
if (bAllEntriesActive)
{
vDeleteRoutingTable();
}
}
PRIVATE void vDeleteRoutingTable(void)这个函数是将路由表的条目都复原吗?
{
int i;
for (i = 0; i < gsNIB.nwkRoutingTableSize; i++)
{
gsNIB.nwkRoutingTable.u16AddrDst = 0xfffd;
gsNIB.nwkRoutingTable.u16AddrNextHop = 0xfffd;
gsNIB.nwkRoutingTable.eStatus = 0x03;
}
}
4.读取绑定表
略
十、地址分配
1.基于树形拓扑的地址分配
Cskip:When a device joins the network, it is allocated a 16-bit network address. End
Devices receive a single address. Routers effectively receive a range of addresses
that is sufficient to contain all possible descendants of that Router. The algorithm that is used to calculate this allocation is known as Cskip.
Cskip用于计算可能的子节点的个数,It has four parameters:
Cm – total number of children that any parent device may have
Rm – total number of Router children that any parent device may have
Lm – maximum depth of the network (i.e. the level at which parent devices
may no longer have children)
d – actual depth of the device under consideration
2.zigbee协议栈设定Cskip的参数
在JZ_sConfig进行设定
JZS_sConfig.u8MaxChildren
JZS_sConfig.u8MaxRouters;
JZS_sConfig.u8MaxDepth;
注意,需要在启动stack之前设定,比如在AppColdStart()里设定。
注意,上面3个参数的最大值分别是20,20,8.
3.子节点容量
The number of Router children is specified by the Cskip parameter Rm. The number of End Device children is the difference between Rm and the Cskip parameter Cm(i.e. maximum children). That is:
Max. End Devices = Cm – Rm
When a parent node issues a beacon in response to a Beacon Request by a node wishing to join the network, the beacon contains two flags indicating the states of the Router and End Device capacities. It also contains a flag indicating whether the parent node is permitting joining – this is the Association Permit flag. When a parent runs out of capacity for either kind of child, it sets the Association Permit flag in the beacon to FALSE, even though there may be capacity left for the other kind of device. This means that no more devices will be allowed to join. However, this prevents a parent from having its maximum number of End Devices and Routers simultaneously. In addition, it can prevent a temporarily orphaned child from re-associating with its former parent, even though it still has a place in the Neighbour table of the old parent (in which its old network address remains allocated to it).
4.修改节点加入行为
略
5.动态网状拓扑路由
尽管网络地址的分配是树形结构,但是,多数信息的传递是使用网状路由,本地节点与远端节点通信,用mesh网络可以找到最佳路由。
6.树状路由
When a Router or the Co-ordinator receives a frame,如果节点无法使用网状路由,它会使用树状路由,就像节点地址分配的算法,节点可以根据目的节点的地址选择哪个分支作为路由。
十一、重启节点的影响
略