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?