ZigBee 2007中绑定的理解

ZigBee 2007中绑定的理解

  853人阅读  评论(0)  收藏  举报

ZigBee中的绑定 
ZigBee中的绑定与端点EndPoint息息相关,其实EndPoint就像是TCP/IP中的端口,每个端口对应于不同的应用层。由于采用一个字节来表示EndPoint,可以具有0~255个端点,但是0端点被预留用于ZDO与ZigBee协议栈的其它层通信,实现各个层的初始化和配置。端点255用于向所有端点广播。此外,端点241到254也是保留端点,具有特殊用途,通常用户不要使用这个范围的端点。因此用户可使用的端点为1~240,也就是可以有240个端点,即240个应用。 
所有端点都是使用APS提供的服务,透过NWK和安全服务提供层与端点相连接,提供数据传送服务,因此能够失配各种兼容的设备。 
typedef struct 

byte endPoint; //端点号,也就是端口号 
byte *task_id; //对应端口的任务ID号 
SimpleDescriptionFormat_t *simpleDesc; //设备的简单描述,说明本端点可以提供哪些命令 
afNetworkLatencyReq_t latencyReq;      //枚举类型 
} endPointDesc_t;

//设备的简单描述结构 
typedef struct 

byte    EndPoint;             //端点号 
uint16 AppProfId;            // Profile ID,是由ZigBee联盟分配的,用于描述设备的应用场景,比如家庭自动化或者是无线传感器网络,它定义了设备之间信息交换的规范后者说规约 
uint16 AppDeviceId;          // 设备ID号 
byte    AppDevVer:4;         // 设备版本 
byte    Reserved:4; //AF_V1_SUPPORT uses for AppFlags:4. Reserved 
byte    AppNumInClusters;    //输入命令个数 
cId_t   *pAppInClusterList;    //输入命令列表 
byte    AppNumOutClusters;   //输出命令个数 
cId_t   *pAppOutClusterList;   //输出命令列表 
} SimpleDescriptionFormat_t;

在SimpleSensorEB中简单描述符为 
const SimpleDescriptionFormat_t zb_SimpleDesc = 

  MY_ENDPOINT_ID,             //  Endpoint 
  MY_PROFILE_ID,              //  Profile ID 
  DEV_ID_SENSOR,              //  Device ID 
  DEVICE_VERSION_SENSOR,      //  Device Version 
  0,                          //  Reserved 
  NUM_IN_CMD_SENSOR,          //  Number of Input Commands 
  (cId_t *) NULL,             //  Input Command List 
  NUM_OUT_CMD_SENSOR,         //  Number of Output Commands 
  (cId_t *) zb_OutCmdList     //  Output Command List只有一个输出命令ID 
};

其中在SAPI_Init(byte task_id)中对endPointDesc_t结构赋值如下: 
sapi_epDesc.task_id = &sapi_TaskID;//任务号 
sapi_epDesc.endPoint = zb_SimpleDesc.EndPoint;//端点号 
sapi_epDesc.latencyReq = noLatencyReqs;//无延迟 
由于在本例子中只有一个应用,即采集温度,因此只需要一个端点描述符。假如有多个应用则需要多个端点描述符,同时占用三个端点号,在不同应用中发送数据时采用不同的端点描述符。 
比如在本例中发送数据的语句为 
status = AF_DataRequest(&dstAddr, &sapi_epDesc, commandId, len, 
                          pData, &handle, txOptions, radius); 
该语句利用AF层的AF_Datarequest函数来发送数据,需要传入的参数包括目标地址,端点描述符,命令ID,长度,实际数据指针,处理方式(比如需不需要确认),发送选项,半径。 
假如描述符匹配成功,则 
case Match_Desc_rsp: 
      { 
        zAddrType_t dstAddr; 
        ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg );

        if ( sapi_bindInProgress != 0xffff ) 
        { 
          // Create a binding table entry 
          dstAddr.addrMode = Addr16Bit; 
          dstAddr.addr.shortAddr = pRsp->nwkAddr;

          if ( APSME_BindRequest( sapi_epDesc.simpleDesc->EndPoint, 
                     sapi_bindInProgress, &dstAddr, pRsp->epList[0] ) == ZSuccess ) 
          { 
            osal_stop_timerEx(sapi_TaskID,  ZB_BIND_TIMER); 
            osal_start_timerEx( ZDAppTaskID, ZDO_NWK_UPDATE_NV, 250 );

            // Find IEEE addr 
            ZDP_IEEEAddrReq( pRsp->nwkAddr, ZDP_ADDR_REQTYPE_SINGLE, 0, 0 ); 
#if defined ( MT_SAPI_CB_FUNC ) 
            zb_MTCallbackBindConfirm( sapi_bindInProgress, ZB_SUCCESS ); 
#endif              
            // Send bind confirm callback to application 
#if ( SAPI_CB_FUNC ) 
            zb_BindConfirm( sapi_bindInProgress, ZB_SUCCESS ); 
#endif 
            sapi_bindInProgress = 0xffff; 
          } 
        } 
      } 
      break;

BINDING KuangJunBin:本文是作者根据TI Z-Stack开发文档,ZigBee Specification-2007,《Zigbee Wireless Networking》等英文资料整合和翻译而,采用中英双语对照方便读者理解,文中翻译不当之处,望广大同行不吝赐教。推广ZigBee技术,提高国内电子行业的国际影响力,是我们无线通讯工程师的愿景。本文欢迎转载,请保留作者信息和出处,作为支持我继续努力前行的动力,谢谢! E-mail:kuangjunbin@gmail.com In the Zigbee 2006 release,the binding mechanism is implemented in all devices and is called source binding. Binding allows an application to send a packet without knowing the destination address,the APS layer determines the destination address from its binding table,and then forwards the message on to the destination application(or multiple applications)or group. ZigBee2006版本中规定,在全部节点中实现绑定机制,并将其称为源绑定绑定机制允许一个应用服务在不知道目标地址的情况下向对方(的应用服务)发送数据包。发送时使用的目标地址将由应用支持子层(APS)从绑定表中自动获得,从而能使消息顺利被目标节点一个或多个应用服务,乃至分组接收。 Binding Table 1.Defined in RAM,but can be saved in Flash if the NV_RESTORE compiler option is used 2.Stored on source node(REFLECTOR compiler option required) 3.Entries map messages to their intended destination 4.Each entry in the binding table contains the following: typedef struct { uint16 srcIdx;//Source index uint8 srcEP;//Source endpoint uint8 dstGroupMode;//Specifies normal or group addressing uint16 dstIdx;//Destination index or group address uint8 dstEP;//Destination endpoint uint8 numClusterIds;//Number of cluster IDs in the clusterIdList below uint16 clusterIdList[MAX_BINDING_CLUSTER_IDS]; }BindingEntry_t; 绑定表 1. 绑定表存放的位置是内存中预先定义的RAM块,如果编译选项NV_RESTORE被激活,也能保存在Flash里。 2. 绑定表放置在源节点(需要激活编译选项REFLECTOR)。 3. 绑定表的条目把需要发送的消息映射到它们的目标地址上。 4. 绑定表中每个条目(entry)包括以下内容: 绑定表条目结构体的定义
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值