登录站点

用户名

密码

我初学ZigBee的体会之三

已有 414 次阅读  2009-09-29 15:37   标签ZigBee  体会  初学 
在Coordinator上添加的发送程序中,也是要把几个参数搞清楚:

          u16AddrDst目标设备的网络地址),此处是指Router,因为我只用了一个Router,所以我指定为是0X0001,
          u8DstEP目标设备端口号),在此处是指Router,
          u8SrcEP源设备端口号),在此处是指Coordinator,
           其它保持原演示程序的规定,
           你的数据包中含有N个字节,就把N赋予u8TransactionDataLen,

                             这是解释部分:

        详细的函数文档可以参考JN-RM-2018:
        Stack_Status_e afdeDataRequest(APS_Addrmode_e eAddrMode,
                                       uint16 u16AddrDst,
                                       uint8  u8DstEP,
                                       uint8  u8SrcEP,
                                       uint16 u16ProfileId,
                                       uint8  u8ClusterId,
                                       AF_type_e        eType,
                                       uint8                 u8TransCount,
                                       AF_Transaction_s     *pauTransactions,
                                       APS_TxOptions_e       u8txOptions,
                                       NWK_DiscoverRoute_e   eDiscoverRoute,
                                       uint8                 u8RadiusCounter);
  Deion:
This submits an AFDE Data Request in order to create a KVP or MSG !!!!
ZDP API s use the MSG format of this (see the ZigBee Device Profile
     APIs Reference Manual).


  Parameters:
1.eAddrMode Address mode, one of:    实际中怎么选择呢 ?
                        APS_ADDRMODE_NOT_PRESENT - Indirect tx
                        APS_ADDRMODE_SHORT - Direct tx,
2.u16AddrDst      Network (short) address of destination device,
                目标器件的网络地址,Coordinator的地址一般是0000,
                Router的地址一般是 ? ? ?
                那具体程序中添多少数呢 ? ? ? is 0xFFFF, 0x0001,
                我认为u16AddrDst在这里是指Router !!! 是的,


                在我们提供的范例代码中,Co-ordinator的短地址被定义为
0x0000,而第一个End Device的地址被定义为0x0001. 这也是End Device的起始短地址,
如果你需要增加多个EndDevice,那么短地址将自动的被生成分配,
每一个短地址都比上一个增加0x0001.
如果您需要使用不同的短地址,打开config.h并且修改下面的定义:
    #define  COORDINATOR_ADR         0x0000
    #define  END_DEVICE_START_ADR    0x0001
需要注意需要注意的是,我们通常都是设置PAN Co-ordinator的地址为0x0000,
您在应用中最好也遵从这个约定。

ZigBee devices also have a 16-bit network address.
The Co-ordinator always has a network address of 0x0000.
Routers and End Devices are each assigned a network address
by their parent. The actual address that the device receives
depends on the address of the parent joined and on how many
network addresses the parent has already allocated.


3.u8DstEP         Endpoint on target device (in the range 0x01 to 0xF0),
                目标endpoint, 一般怎么规定 ?
                本程序中定义为:  WSN_DATA_SOURCE_ENDPOINT    0x41,  ******
                指Router吧 ? ****  我认为在这里是指Router !!!!!!!
                u8DstEP是目标设备的端口号,
                数据在通过协议栈请求发送的时候都需要指定发往哪个end point.

4.u8SrcEP         Endpoint on source device (in the range 0x01 to 0xF0),
                源地址的Endpoint 范围是 0x01 到 0xF0,
                本程序中定义为: WSN_DATA_SINK_ENDPOINT   0x40,  *******
                指Coordinator吧 ? 我认为在这里是指Coordinator !!!!!!!!
               
                u8SrcEP是源设备的端口号,


5.u16ProfileId    (value in the range 0 to 0xFFFF)
                所采用的profile ID,
                本程序中定义为: WSN_PROFILE_ID   0x123,
                这是由ZigBee联盟分配的 !!!

                Profile, 如果需要译成中文的话我习惯叫它规约,
                但是在这个手册里面我还是保留它的英文名称不再翻译,
                这样可以和Jennic的手册保持一致。每一个ZigBee的网络
                设备都应该使用同一个Profile, Profile定义了设备的应用场景,
                比如是家庭自动化(HC)或者是无限传感器网络(WSN),
                另外定义了设备的类型还有设备之间的信息交换规范.


6.u8ClusterId     Identifier of individual message (value in the range 0 to 0xFF),
                所采用的cluster ID,
                本程序中定义为: WSN_CID_SENSOR_READINGS  0x12, 它俩是一伙的,
                 这个值在Ccoordinate与router两边是一样的。

                Cluster, 通常我们翻译成“簇”。它定义了endpoint和endpoint
                之间的数据交换格式 !!! Cluster包含一系列有着逻辑含义的属性。
                通常profile都会定义自己的一系列cluster。每一个endpoint
                上都会定义自己发送和接收的cluster.

                That's because your application cluster ID and the
                cluster ID for the ZDP commands are on different endpoints.
                All ZDP clusters are on endpoint 0. Application
                clusters are allowed to use endpoints 1-240.
                 那 "8ClusterId" 就是"application cluster ID"了 ?

7.eType      使用的数据帧类型, 有两种格式:
                AF_KVP (0x01) – KVP ,
                AF_MSG (0x02) – MSG       它规定了MSG格式 !!!
8.u8TransCount    Number of transactions within the data request (value in
                the range 0 to 0x0F),本次请求发送的数据事务的数量。
                这里可能需要解释一下,就目前的理解:
                数据请求一次可以发送多个数据包,
                这个参数就表示了数据包的数量,不过我们通常在应用中只发送一个,
                所以这个参数通常就是 1 。

9.*pauTransactions:   Pointer to transaction structure,

10.u8txOptions:        Specifies transmission options for request. The following
                   values can be logical ORed together:
       APS_TXOPTION_NONE (0x00)    没有任何选项,
       SECURITY_ENABLE_TRANSMISSION (0x01)    使用安全传输,
       USE_NWK_KEY (0x02),    使用网络键,
       ACKNOWLEDGED_TRANSMISSION (0x03),   采用确认传输模式,
       In the case of a device which receives a sent with Acknowledgment,
       APS Ack should be transmitted,

11.
eDiscoverRoute:
      设定所采用的路由发现模式:
1.
SUPPRESS_ROUTE_DISCOVERY (0x00) 使用强制路由发现模式,采用这种模式如果路由表已经建立,
那么数据将使用现有的路由表路由,如果路由表没有建立那么数据将沿着树状路径路由。
我们采用这种方案,
  If you just have a Coordinator and some End Device children,
  the only topology you can have is star. As soon as you add some routers,
  the network may then organise itself into a tree/mesh.
注意下面这段话:
You can force it to send data along the branches of the tree by
setting the eDiscoverRoute parameter of afdeDataRequest() to
SUPPRESS_ROUTE_DISCOVERY. Otherwise if you set it to ENABLE_ROUTE_DISCOVERY,
meshing will be used where possible. Note that End Devices always
communicate through their parents,


2.
ENABLE_ROUTE_DISCOVERY (0x01) 路由发现使能,采用这种模式,如果路由表已经建立,
那么数据将使用现有路由,如果路由表没有建立那么此次数据发送请求将引发路由探索动作。

3.
FORCE_ROUTE_DISCOVERY (0x02) 这一模式将明确的引发路由探索操作,路由表将重新的建立。

12.
u8RadiusCounter:
        数据发送的深度,也就是数据包所发送的转发次数限制,
        如果设置为0那么协议栈将采用2倍的MaxDepth。



           对参数和变量的说明:   见JN-RM-2014,


1.    AF_Transaction_s:     这是一个结构变量的名字,

typedef struct
{
uint8     u8SequenceNum;         标识KVP和MSG数据帧的序列号,这个号应该是单增的,
                                 用来跟踪数据的丢包,
union
{
         AF_Msg_Transaction_s   sMsg;
         AF_Kvp_Transaction_s   sKvp;
}u;
}AF_Transaction_s;

  MSG and KVP 的区别,
MSG s consist of Length and Data. KVP s are more complex,
featuring additional fields such as attribute ID, data type and
command type. You can use KVP to SET and GET values on a remote node.
  Also with KVP there is the possibility of the stack sending an automatic
response back to the sender application.
Generally, if you need End to End acknowledgment, I would suggest using KVP.
Otherwise use MSG.

In my opinion, Kvp is shorter than MSG , so if your data
is not so large or you want to use Attribute ID in your code or
If you need end-to-end response I guess you have better use Kvp .


JN-UG-3045指出:
5.2 MSG vs KVP
There are two types of data service available: MSG and KVP.
MSG is a simpler format containing just data and data length fields.
The Application Note JN-AN-1015 “ use MSG s.
KVP is more complicated, featuring additional fields such as data type,
attribute andvalues. This is described in the ZigBee Stack User
Guide (JN-UG-3017). Themessage format is used in some ZigBee public
profiles, as it is useful where interoperability is required.
However, one notable benefit of KVP is that it is possibleto
make the stack automatically generate a response , which is
sent from tremote node back to the local node.



For AF_Msg_Transaction_s and F_Kvp_Transaction_s, see below:

AF_Msg_Transaction_s:
typedef struct
{
uint8    u8TransactionDataLen;
uint8    au8TransactionData[afcMaxMsgPayloadSize];   // 这个定义了什么呢 ?
} AF_Msg_Transaction_s;


u8TransactionDataLen;
    是代表数据包的大小,如果是MSG数据包的格式时,最大的包为82个字节。


  1。直接传输:PAN Co-ordinatro可以将数据直接发送给End Device。End Device接收到数据
     后可以发送确认消息给Co-ordinator.
     这种数据传输方式就要求End Device随时都处于数据接收的状态,也就是要求其随时
     都要处于唤醒的状态。
        我采用这种工作方式,和Router通讯,

上一篇: 3G入门理论知识详细介绍 下一篇: 我初学ZigBee的体会之四

分享 举报