微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > 射频无线通信设计 > 如何更改短地址?

如何更改短地址?

时间:10-02 整理:3721RD 点击:
向大家询问一下,如果我采用随机地址分配方式,如何人为的设置短地址?

如题补充一下,看到ZigBee协议栈分析仪捕获的数据包,想着如何可以在协调器给终端分配地址的时候,将这个地址换成为一个其他可以认为设置的地址,岂不是不用反查就能够得到设备的短地址。但是具体协调器分配地址应该是在MAC层或者NLME层,所以只能通过截取的方式更改,具体应该如何实现,希望高人指点一二。

这个貌似不好改,我记得TI留出了一个接口,TI默认是动态分配地址。

通过修改设备的mac信息或者nib数据库应该可以改掉自己的网络短地址的。但是问题是,自己改掉自己可以,如何通知自己的父设备呢?如果不通知的话,岂不是自己的父设备中保存的全部是“不存在”的子设备。
还有一个问题,改这个网络地址有多大用处?
大家一起讨论下。

ZigBee Pro采用的随机地址分配,然后返回来看了下ZigBee Wireless Networking,看到这么一段话,前面将的是针对ZigBee Pro。Another common way to assign addresses in ZigBee Pro that circumvents the address conflict altogether is to choose unique addresses ahead of time, with a commissioning tool. That way, all addresses are unique by design. See Chapter 8, “ CommissioningZigBee Networks, ” for more on commissioning.

翻译一下:大概意思就是说通过指定地址的方式,绕过地址广播,可以防止地址冲突。具体方式还在分析中,研究一下Chapter8。

当年版主曾经这么说过,但是太笼统了,带我自己研究出来后,给大家分享。
http://bbs.eeworld.com.cn/thread-299561-1-1.html

仔细分析了Chapter 8,讲的都是基本概念,没有什么大的用途,于是还是求助于TI老大,看了官网的牛人写下了这么一些话:
The short address is assigned by the protocol; hence, it is dynamically assigned when deploying a NWK with fresh nodes joining the network. The short address is used as a unique identifier for a node in the network.

Normally the coordinator starts the network and uses the short address 0x0000. Then it assigns other addresses to the joining devices that associate with it. Joining routers can then also assign addresses to devices joining them. In ZigBee non-PRO these addresses are assigned according to the CSKIP algorithm which assigns them in a tree structure way to assure that all addresses in a network are unique.

While in ZigBee PRO the protocol uses a random short address generation and initiates a broadcast to see whether the address is already taken. If it is taken the address conflict is handled such that all devices with the conflicting address generate a new one (end devices get it from their parent router/coordinator).

There are special cases where one uses NV-restore etc. where the device saves the address it got assigned earlier and then uses it again when powering up again.

Also one could use the NV-restore feature to preprogram all devices beforehand, but then it is not so easy to make sure that the devices put together in one Network all have unique identifiers.

翻译一下:前面将ZigBee协议栈是通过自动分配的方式分配地址的,而pro中,也是自动分配,但是可以采用NV-restore的方式,将信息提前写入到NV中,同时初始化时将会调用NV中的配置信息,达到初始化的目的

But in stack profile 0x02, also called ZigBee Pro, it is possible to set the network short address explicitly. In this case, the commissioning tools would know the short address to assign to each node, perhaps based on some formula involving hotel room number. Then, when the node is reset, it can either use the rejoin as above, or even silent join (with StartupControl set to mode 0x00) so that it can be done a little faster (no waiting for negotiation with the trust center). It’s assumed in this case that the tool has all the necessary keys and has communicated them to the nodes.

TI论坛上,老外的原话:
Just for the record, I don't know if it's solves your problem but I ended here while looking for something similar and the solution I found was to change the node address from within the code:

_NIB.nwkDevAddress = <new address>;
ZMacSetReq( ZMacShortAddress, (byte*)&_NIB.nwkDevAddress );

协议栈里面说,在Pro中,子节点的随机地址是由其父节点自动分配的。但是如果自动分配的于现有的相重复,子节点自动更改随机地址,但是原先保留的绑定等信息不更改。
特别是在ZDApp中,ZDO_NWK_DISC_CNF事件内
else if ( devStartMode == MODE_REJOIN )
{
devState = DEV_NWK_REJOIN;

// Before trying to do rejoin, check if the device has a valid short address
// If not, generate a random short address for itself
if ( _NIB.nwkDevAddress == INVALID_NODE_ADDR )
{
_NIB.nwkDevAddress = osal_rand();
ZMacSetReq( ZMacShortAddress, (byte*)&_NIB.nwkDevAddress );
}
}

也就是重新加入的情况下也是如此的。

有没有哪位道友有不同的看法?

你这里说的是重新加入的情况。那就来讨论一下这种重加入的情况(MODE_REJOIN):
1、正常来说,这种情况最有可能发生在终端设备身上。比如,在某个时间上,终端设备不能与自己的父设备通信了,(父设备离线,或者网络信号不好等),这时终端需要重新寻找新的父设备,否则就不能与其他的无线设备通信了。这时候终端设备的状态就切换为MODE_REJOIN了。在这种状态下进行网络发现,就执行到你贴出的代码中了。此时终端设备其实还是作为一个设备存在网络中的,要想通信必须有自己的网络地址。在这里应该只是以防万一,确认一下自己的网络地址是否有效。如果无效则自己给自己分配一个随机的地址来通信,等再找到新的父设备后,自然就获得新的网络地址了。所以这里获得的这个地址对于整个网络通信来说是没有影响。

2、对于路由设备,这种情况应该很不可能出现,因为路由设备一旦入网,正常情况下是不会自己退网的,也就不太可能变成MODE_REJOIN状态了。

3、所以我觉着上述代码,跟你说的自己定义设备的网络地址的关系不大。

4、关于怎么实现自己定义网络地址的功能,我觉着关键是父子设备间来相互通知好。否则终端设备自己把自己的地址改了,而不通知自己的父设备,那他就没办法通信了。路由设备把自己的地址改了,应该还可以进行无线通信(没有试验过,但理论上应该没有关系),但他的父设备中就保存了一个无效的子设备消息了。

5、具体实现上,应该没有太大难度,只要修改相应的信息库就可以了。子设备你前面已经提到改动的地方了。父设备有个子设备列表,直接改掉应该是可以的。我没有试验过,你可以试试。要注意的是,在改动之前,相互通知并确认好就可以了。

6、不清楚你的具体应用场景,费这个麻烦有必要吗?

7、暂时就想到这么多,希望对你有用。有什么问题再一起讨论。也希望其他的大牛们能一起出出主意。

ZigBee Wireless Networking里面写到,如果采用随机地址
The probability of a pair of nodes choosing the same address reaches 50% at around 300 nodes, and 99% at 777 nodes, so you’re pretty much guaranteed a conflict within about 800 nodes or so.
因此,如果要组件一个比较大的网络,要是上万了,采用随机地址的方式反而是不可行的。所以想能够指定地址,也方便数据传送。例如指定地址,0x0001-0x1000之类的,也省去了一个一个的读取。
前面我说的更改子节点地址的方式,后面还需要增加一个广播函数,ZDApp_AnnounceNewAddress(),这个函数的意思就是告诉其他设备,自己的状态,防止地址冲突等。同时也告诉了其父节点自己的状态。
这样,每次初始化设备的时候不会产生地址冲突,可以提高整体网络初始化的时间。
你说的父设备有个子设备列表,这个我还没有看到,才学ZigBee一个来月,也只是个初学者,正好这个你说到了,我会好好再去分析一下。也希望能得到各位大牛的指导。

你好,你现在是通过什么方式实现网络短地址的自定义的呢

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top