修改Z-Stack的PAN_ID

1、在Z-Stack协议安装文件夹下的documents下的Z-Stack Developer's Guide.pdf文档,找到9.2  Configuring the PAN ID and network to join 

有以下说明

This is an optional configuration item to control which network a ZigBee Router or End Device will join. The
ZDO_CONFIG_PAN_ID parameter in f8wConfig.cfg can be set to a value (between 0 and 0xFFFE). A coordinator
will use this value as the PANId of the network that it starts. A router or end-device will only join a network that has
a PANId configured in this parameter. To turn this feature off, set the parameter to a value of 0xFFFF.

For further control of the joining procedure, the ZDO_NetworkDiscoveryConfirmCB function in the
ZDApp.c should be modified. ZDO_NetworkDiscoveryConfirmCB() is called when the network layer has
finished with the Network Discovery process [started by calling NLME_NetworkDiscoveryRequest()
defined in the Stack API document].

 

2、如果使用过Sensor-Demo这个全程,见文档CC2530ZDK_Sensor_Demo_Users_Guide.pdf

5.3.1 Network Settings
The software that is programmed on the CC2530ZDK uses IEEE 802.15.4 channel 11 (2405 MHz).
The PAN ID used is dependent on the last 2 bytes of the Coordinator’s IEEE address (i.e.
ZDAPP_CONFIG_PAN_ID=0xFFFF in the file f8wConfig.cfg in Z-Stack).

It is possible to choose another channel and PAN ID by using other settings in the file f8wConfig.cfg in
Z-Stack. See also Z-Stack Developer’s Guide [5] for further information.

 

以上两种方法其实讲的是同一种方法,两个参数的名字不同,难道是其中一个TI的文档没有更新?

在我使用的ZStack-CC2530-2.3.1-1.4.0版的协议中,f8wConfig.cfg里的参数不是ZDO_CONFIG_PAN_ID,而是ZDAPP_CONFIG_PAN_ID。

用这种方法,就是修改tool下的f8wConfig.cfg文件里的参数,编译后再down到板子里。down完之后,网络运行过程中想要修改就不能用这种方法了。


3、现在我想实现如下功能:

协调器跟PC通过RS232连接,我想在协调器在运行过程中,PC可以命令协调器修改PAN_ID。

使用函数:void zb_WriteConfiguration( uint8 configId, uint8 len, void *pValue ) 

文档:Z-Stack Simple API.pdf中对这个函数的解释如下:

The zb_WriteConfiguration function is used to write a Configuration Property to nonvolatile memory. 

第一个参数configId在OSAL下的ZComDef.h文件中定义。

其中有一条:

#define ZCD_NV_PANID                      0x0083

 

那么通过如下语句可以实现目的:

uint16 pan_id;

pan_id=0x1122;//你想要的ID

zb_WriteConfiguration(ZCD_NV_PANID, sizeof(uint16),  &pan_id) ;

zb_SystemReset();//重启后才会启用新的PAN_ID,不然只是修改了NV里面的数据。

 

如果没有添加zb_SystemReset();这条语句,通过zb_ReadConfiguration()函数读取的PAN_ID也是0x1122,说明zb_WriteConfiguration已经把数据成功写进NV里了。

但是用zb_GetDeviceInfo(ZB_INFO_PAN_ID,&pan_id);读出来的却还是旧的PAN_ID,因为系统没有启用新的PAN_ID来建立网络。

这时调用 zb_SystemReset();让系统重启一下,再用zb_ReadConfiguration()和zb_GetDeviceInfo()读出来的数据就是一样的了。

运行中修改协调器PAN ID和Channel,协调器广播至所有的设备重启加入新建后的网络 


以上方法又不对了!!!

以下方法经过验证是可以的:

 

pan_id = 0x1122;     

 

_NIB.nwkPanId = pan_id;

 

NLME_UpdateNV(0x01);

 

zb_SystemReset();

 

这样就可以建立一个新的pan_id的网络了,而且也可以和节点进行正常通信。

 

NLME_UpdateNV()这个函数可以在Z-Stack API.pdf文档里找到。

 

也可以参照这篇博文:http://blog.sina.com.cn/s/blog_63e7da980100oi4q.html

 

 

 

用zb_GetDeviceInfo(ZB_INFO_PAN_ID,&pan_id);这个函数读取的pan_id是修改后的数据;

 

但是为何用zb_ReadConfiguration(ZCD_NV_PANID, sizeof(uint16), &pan_id);读取出来的是旧的数据呢?没有更新NV?


posted @ 2012-03-13 10:37  枫部落  阅读(8540)  评论(0编辑  收藏  举报
点击这里给我发消息