#1楼主:【原创】ZigBee学习之14——ZStackAPI解读2文章发表于:2010-02-0615:50ZDO邦定API绑定机制允许一个应用服务在不知道目标地址的情况下向对方(的应用服务)发送数据包。发送时使用的目标地址将由应用支持子层从绑定表中自动获得,从而能使消息顺利被目标节点的一个或多个应用服务,乃至分组接收。由于所有邦定信息都在Zigbee协调器中,所以只有协调器才能接收邦定请求。ZDOBindingAPIZDPBindingServiceCommandZDP_EndDeviceBindReq()End_Device_Bind_reqZDP_EndDeviceBindRsp()End_Device_Bind_rspZDP_BindReq()Bind_reqZDP_BindRsp()Bind_rspZDP_UnbindReq()Unbind_reqZDP_UnbindRsp()Unbind_rspafStatus_tZDP_EndDeviceBindReq(zAddrType_t*dstAddr,uint16LocalCoordinator,byteepIntf,uint16ProfileID,byteNumInClusters,byte*InClusterList,byteNumOutClusters,byte*OutClusterList,byteSecuritySuite);构建并发送节点设备邦定请求(HandBingding)。LocalCoordinator-设备父协调器的16位网络地址NumInClusters-输入簇中的clusterID数目InClusterList-输入clusterIDs的数组afStatus_tZDP_EndDeviceBindRsp(byteTranSeq,zAddrType_t*dstAddr,byteStatus,byteSecurityEnable);Status-SUCCESS0NOT_SUPPORTED1TIMEOUT2NO_MATCH3afStatus_tZDP_BindReq(zAddrType_t*dstAddr,byte*SourceAddr,byteSrcEPIntf,byteClusterID,byte*DestinationAddr,byteDstEPIntf,byteSecuritySuite);请求协调器利用clusterID邦定应用ClusterID–要邦定的clusterIDDestinationAddr–接收消息的设备的64位地址afStatus_tZDP_BindRsp(byteTranSeq,zAddrType_t*dstAddr,byteStatus,byteSecurityEnable);Status-SUCCESS0NOT_SUPPORTED1TABLE_FULL2afStatus_tZDP_UnbindReq(zAddrType_t*dstAddr,byte*SourceAddr,byteSrcEPIntf,byteClusterID,byte*DestinationAddr,byteDstEPIntf,byteSecuritySuite);请求Zigbee协调器移除邦定。afStatus_tZDP_UnbindRsp(byteTranSeq,zAddrType_t*dstAddr,byteStatus,byteSecurityEnable);Status-SUCCESS0x00NOT_SUPPORTED1NO_ENTRY2ZDO管理API这些消息用来取得设备状态和更新表格ZDPManagementAPIZDPNetworkManagementServiceCommandZDP_MgmtNwkDiscReq()Mgmt_NWK_Disc_reqZDP_MgmtNwkDiscRsp()Mgmt_NWK_Disc_rspZDP_MgmtLqiReq()Mgmt_Lqi_reqZDP_MgmtLqiRsp()Mgmt_Lqi_rspZDP_MgmtRtgReq()Mgmt_Lqi_reqZDP_MgmtRtgRsp()Mgmt_Rtg_rspZDP_MgmtBindReq()Mgmt_Bind_reqZDP_MgmtBindRsp()Mgmt_Bind_rspZDP_MgmtLeaveReq()Mgmt_Leave_reqZDP_MgmtLeaveRsp()Mgmt_Leave_rspZDP_MgmtDirectJoinReq()Mgmt_Direct_Join_reqZDP_MgmtDirectJoinRsp()Mgmt_Direct_Join_rspZDP_MgmtPermitJoinReq()Mgmt_Permit_Join_reqZDP_MgmtPermitJoinRsp()Mgmt_Permit_Join_rspafStatus_tZDP_MgmtNwkDiscReq(zAddrType_t*dstAddr,uint32ScanChannels,byteStartIndex,byteSecurityEnable);如果设备支持这个命令,调用此函数将为目标设备产生一个扫描网络的请求。只有设置ZDO_MGMT_NWKDISC_REQUEST编译选项(ZDConfig.h)才能调用此函数。afStatus_tZDP_MgmtNwkDiscRsp(byteTranSeq,zAddrType_t*dstAddr,byteStatus,byteNetworkCount,byteStartIndex,byteNetworkCountList,networkDesc_t*NetworkList,byteSecurityEnable);若设置ZDO_MGMT_NWKDISC_RESPONSE编译选项,当接收到“ManagementNetworkDiscoveryRequest”消息后将自动产生这个消息。afStatus_tZDP_MgmtLqiReq(zAddrType_t*dstAddr,byteStartIndex,byteSecurityEnable);若设置ZDO_MGMT_LQI_REQUEST编译选项,调用此函数将为目标设备产生返回邻居列表的请求。ZStatus_tZDP_MgmtLqiRsp(byteTranSeq,zAddrType_t*dstAddr,byteStatus,byteNeighborLqiEntries,byteStartIndex,byteNeighborLqiCount,neighborLqiItem_t*NeighborLqiList,byteSecurityEnable);afStatus_tZDP_MgmtRtgReq(zAddrType_t*dstAddr,byteStartIndex,byteSecurityEnable);若设置ZDO_MGMT_RTG_REQUEST编译选项,调用此函数将为目标设备产生返回路由列表的请求。ZStatus_t–状态值,定义在ZComDef.h中的ZStatus_tZStatus_tZDP_MgmtRtgRsp(byteTranSeq,zAddrType_t*dstAddr,byteStatus,byteRoutingTableEntries,byteStartIndex,byteRoutingListCount,rtgItem_t*RoutingTableList,byteSecurityEnable);若设置ZDO_MGMT_RTG_REQUEST编译选项,当接收到“ManagementRoutingRequest”消息后将自动产生这个消息。afStatus_tZDP_MgmtBindReq(zAddrType_t*dstAddr,byteStartIndex,byteSecurityEnable);若设置ZDO_MGMT_BIND_REQUEST编译选项,调用此函数将为目标设备产生返回邦定表的请求。ZStatus_tZDP_MgmtBindRsp(byteTranSeq,zAddrType_t*dstAddr,byteStatus,byteBindingTableEntries,byteStartIndex,byteBindingTableListCount,apsBindingItem_t*BindingTableList,byteSecurityEnable);afStatus_tZDP_MgmtLeaveReq(zAddrType_t*dstAddr,byte*IEEEAddr,byteSecurityEnable);若设置ZDO_MGMT_LEAVE_REQUEST编译选项,调用此函数将请求目标设备脱离网络或者请求其他设备脱离网络ZStatus_tZDP_MgmtLeaveRsp(byteTranSeq,zAddrType_t*dstAddr,byteStatus,byteSecurityEnable);若设置ZDO_MGMT_LEAVE_REQUEST编译选项,当接收到“ManagementLeaveReques”消息后将自动产生这个消息。afStatus_tZDP_MgmtDirectJoinReq(zAddrType_t*dstAddr,byte*deviceAddr,bytecapInfo,byteSecurityEnable);若设置ZDO_MGMT_JOINDIRECT_REQUEST编译选项,调用此函数将请求目标设备直接加入其他设备。deviceAddr–要加入的设备的64位地址capInfo–要加入设备的性能CAPINFO_ALTPANCOORD0x01CAPINFO_DEVICETYPE_FFD0x02CAPINFO_Power_AC0x04CAPINFO_RCVR_ON_IDLE0x08CAPINFO_SECURITY_CAPABLE0x40CAPINFO_ALLOC_ADDR0x80ZStatus_tZDP_MgmtDirectJoinRsp(byteTranSeq,zAddrType_t*dstAddr,byteStatus,byteSecurityEnable);afStatus_tZDP_MgmtPermitJoinReq(zAddrType_t*dstAddr,byteduration,byteTcSignificance,byteSecurityEnable);实际是直接调用宏ZDP_SendData(),函数构建并发送Mgmt_Permit_Joining_req来请求远端设备允许或不允许关联。这个请求由调试工具或者网络管理设备产生,duration-协调器或路由器允许关联的时间(单位为秒),0x00和0xff分别表示没有时间限制的禁止和允许。TcSignificance-如果设为0x01且远端设备为真实中心设备的话,命令将影响中心设备的授权机制。ZStatus_tZDP_MgmtPermitJoinRsp(byte*TransSeq,zAddrType_t*dstAddr,byte*Statue,byteSecurityEnable);ZDO解析函数用来解析接收到的消息ZDO_NwkIEEEAddrResp_t*ZDO_ParseAddrRsp(zdoIncomingMsg_t*inMsg);解析NWK_addr_rsp和IEEE_addr_rsp消息inMsg-指向接收到的消息的指针ZDO_NwkIEEEAddrResp_t-指向解析后的结构的指针,结构体由osal_mem_alloc分配空间,所以需要调用osal_mem_free()来释放空间voidZDO_ParseNodeDescRsp(zdoIncomingMsg_t*inMsg,ZDO_NodeDescRsp_t*pNDRsp);解析Node_Desc_rsp消息pNDRsp-解析消息存放的地方voidZDO_ParsePowerDesc