zigbee关联表AssociatedDevList

来源:互联网 发布:cf手游刷枪软件安卓版 编辑:程序博客网 时间:2024/06/13 01:50

关联表的操作

AssociatedDevList 表为与此设备相关联的设备表,并不是 ZigBee 网络中的所有设备信息表。表中信息的 IEEE 地址是唯一的,每个设备加入它的父节点时会在表中添加一个记录,但是子节点断电离开网络时不会删除该条记录,如果有多个子节点,频繁更换父节点会造成 AssociatedDevList 表满或溢出,使其它子节点无法加入该父节点,因此需要及时的删除一些已离开的子节点记录。

5.1、关联表的定义

在 nwk_globals.C 文件中有对关联表的定义,代码如下:

#if defined(RTR_NWK)

// Statically defined Associated Device List

associated_devices_t AssociatedDevList[NWK_MAX_DEVICES];

#endif

5.2、关联表的结构

在 AssocList.h 文件中有对关联表结构 associated_devices_t 的定义,代码如下:

typedef struct

{

uint16 shortAddr;

uint16 addrIdx;

byte nodeRelation;

byte devStatus;

byte assocCnt;

linkInfo_t linkInfo;

} associated_devices_t;

devStatus 可以设置为以下的值

#define DEV_LINK_STATUS    0x01 // link is in-active ? 活动联接

#define DEV_LINK_REPAIR 0x02 // link repair in progress ?正在修复联接

#define DEV_SEC_INIT_STATUS    0x04 // security init 初后的安全

#define DEV_SEC_AUTH_STATUS 0x08 // security authenticated 验正过的安全

在 ZComDef.h 文件中有对 linkInfo_t 的定义,代码如下:

typedef struct

{

uint8 txCost;

uint8 rxCost;

// counter of transmission success/failures

// average of received rssi values

uint8 inKeySeqNum; // security key sequence number

uint32 inFrmCntr;

// security frame counter..

} linkInfo_t;

 

 

5.3、关联表记录的查看

可以直接从 AssociatedDevList[NWK_MAX_DEVICES]数组中查看关联设备的信息,比如:

for (uint8 x=0;x<NWK_MAX_DEVICES;x++)

{

byte nr = AssociatedDevList[x].nodeRelation;

}

5.4、关联表记录的删除
关联表的删除可以有多种方法,可以用 AssocList.h 文件中的函数,也可以直接在 NV
区中删除,下面只对 AssocList.h 文件中的函数部分举例说明,代码如下:

AddrMgrEntry_t addrEntry;
NLME_LeaveReq_t req;
uint8 i = Z_EXTADDR_LEN + 1;

// Set up device info
addrEntry.user = ADDRMGR_USER_DEFAULT;
addrEntry.index = index;
if (AddrMgrEntryGet( &addrEntry ))
{
for (i = 0; i < Z_EXTADDR_LEN; i++ )
{
if ( addrEntry.extAddr != 0 ){ break;}
}
}
if(i < Z_EXTADDR_LEN){
// Remove device
req.extAddr = addrEntry.extAddr;
req.removeChildren = TRUE;
req.rejoin = TRUE;
req.silent = FALSE;
NLME_LeaveReq( &req );
}else{
AssocRemove(addrEntry.extAddr);
ZDApp_NVUpdate();
}


ZigBee的AssociatedDevList详解





原创粉丝点击