現(xiàn)對(duì)z-stack里幾個(gè)網(wǎng)絡(luò)參數(shù)的設(shè)置以及如何獲取總結(jié)一下。
信道配置: Zigbee在3個(gè)頻段定義了27個(gè)物理信道:868MHz頻段中定義了1個(gè)信道,915MHz頻段中定義了2個(gè)信道,信道間隔為2MHz,2.4GHz頻段上定義了16個(gè)信道,信道間隔為5MHz. Z-stack中可以在f8wConfig.cfg里設(shè)置信道,相關(guān)部分如下: /* Default channel is Channel 11 - 0x0B */ // Channels are defined in the following: // 0 : 868 MHz 0x00000001 // 1 - 10 : 915 MHz 0x000007FE // 11 - 26 : 2.4 GHz 0x07FFF800 // //-DMAX_CHANNELS_868MHZ 0x00000001 //-DMAX_CHANNELS_915MHZ 0x000007FE //-DMAX_CHANNELS_24GHZ 0x07FFF800 //-DDEFAULT_CHANLIST=0x04000000 // 26 - 0x1A //-DDEFAULT_CHANLIST=0x02000000 // 25 - 0x19 //-DDEFAULT_CHANLIST=0x01000000 // 24 - 0x18 //-DDEFAULT_CHANLIST=0x00800000 // 23 - 0x17 //-DDEFAULT_CHANLIST=0x00400000 // 22 - 0x16 //-DDEFAULT_CHANLIST=0x00200000 // 21 - 0x15 //-DDEFAULT_CHANLIST=0x00100000 // 20 - 0x14 //-DDEFAULT_CHANLIST=0x00080000 // 19 - 0x13 //-DDEFAULT_CHANLIST=0x00040000 // 18 - 0x12 //-DDEFAULT_CHANLIST=0x00020000 // 17 - 0x11 //-DDEFAULT_CHANLIST=0x00010000 // 16 - 0x10 //-DDEFAULT_CHANLIST=0x00008000 // 15 - 0x0F //-DDEFAULT_CHANLIST=0x00004000 // 14 - 0x0E //-DDEFAULT_CHANLIST=0x00002000 // 13 - 0x0D //-DDEFAULT_CHANLIST=0x00001000 // 12 - 0x0C -DDEFAULT_CHANLIST=0x00000800 // 11 - 0x0B 這里默認(rèn)使用的是編號(hào)為11的信道 當(dāng)建網(wǎng)過(guò)程開(kāi)始后,網(wǎng)絡(luò)層將請(qǐng)求MAC層對(duì)規(guī)定的信道或由物理層默認(rèn)的有效信道進(jìn)行能量檢測(cè)掃描,以檢測(cè)可能的干擾。網(wǎng)絡(luò)層管理實(shí)體對(duì)能量掃描的結(jié)果以遞增的方式排序,丟棄那些能量值超出可允許能量水平的信道,然后再由網(wǎng)絡(luò)層管理實(shí)體執(zhí)行一次主動(dòng)掃描,結(jié)合檢查PAN描述符,對(duì)剩下的信道選擇一個(gè)合適的建立網(wǎng)絡(luò)。 若要在應(yīng)用中查看信道,可以這樣獲得,_NIB.nwkLogicalChannel,讀取這個(gè)就OK了。(NIB -NWK Information base-. 其中包含一些網(wǎng)絡(luò)屬性 PANID ,NETWORK ADDRESS 等等。其中_nib.nwkpanID是本網(wǎng)的ID標(biāo)識(shí),_NIB.extendedPANID按照字面意思是外網(wǎng)ID) PANID: 在確定信道以后,下一步將是確定PANID,如果ZDAPP_CONFIG_PAN_ID被定義為0xFFFF,那么協(xié)調(diào)器將根據(jù)自身的IEEE地址建立一個(gè)隨機(jī)的PANID(0~0x3FFF),如ZDAPP_CONFIG_PAN_ID沒(méi)有被定義為0xFFFF,那么網(wǎng)絡(luò)的PANID將由ZDAPP_CONFIG_PAN_ID確定。 “如果ZDAPP_CONFIG_PAN_ID被定義為0xFFFF,那么協(xié)調(diào)器將根據(jù)自身的IEEE地址建立一個(gè)隨機(jī)的PANID(0~0x3FFF)”這句話怎么理解呢,我經(jīng)過(guò)試驗(yàn)發(fā)現(xiàn),這個(gè)隨機(jī)的PANID并非完全隨機(jī),它有規(guī)律,與IEEE地址有一定的關(guān)系:要么就是IEEE地址的低16位,要么就是一個(gè)與IEEE地址低16位非常相似的值。如IEEE地址為0x8877665544332211,PANID很有可能就是2211,或相似的值;IEEE地址為0x8877665544337777,PANID很有可能就是3777,或其它相似的值; Z-stack中相關(guān)部分代碼如下: /* Define the default PAN ID. * * Setting this to a value other than 0xFFFF causes * ZDO_COORD to use this value as its PAN ID and * Routers and end devices to join PAN with this ID */ -DZDAPP_CONFIG_PAN_ID=0xFFFF 若要在應(yīng)用中查看PANID可以這樣獲得,_NIB.nwkPanId,讀取這個(gè)就OK了。 發(fā)射功率: 傳送范圍的大小是和發(fā)射功率還有信道環(huán)境有關(guān), 傳送速率和傳送范圍之間沒(méi)有直接聯(lián)系。所以呢,適當(dāng)?shù)脑龃蟀l(fā)射功率可增大傳送范圍。但也是有一定的限制的。具體詳見(jiàn)datasheet。 在mac_radio_def.h里有可以設(shè)置: #define MAC_RADIO_CHANNEL_DEFAULT 11 #define MAC_RADIO_TX_POWER_DEFAULT 0x1F #define MAC_RADIO_TX_POWER_MAX_MINUS_DBM 25 這些只是舉例說(shuō)明一下,這些參數(shù)的意義,以及在z-stack里的什么地方修改。還有很多其它的參數(shù),可以查看相關(guān)的源文件。 [mac_radio_def.h] #define MAC_RADIO_SET_CHANNEL(x) st( FSCTRLL = FREQ_2405MHZ + 5 * ((x) - 11); ) #define MAC_RADIO_SET_TX_POWER(x) st( TXCTRLL = x; ) #define MAC_RADIO_SET_PAN_ID(x) st( PANIDL = (x) & 0xFF; PANIDH = (x) >> 8; ) [mac_radio.c] void macRadioInit(void) { /* variable initialization for this module */ reqChannel = MAC_RADIO_CHANNEL_DEFAULT; macPhyChannel = MAC_RADIO_CHANNEL_DEFAULT; reqTxPower = MAC_RADIO_TX_POWER_DEFAULT; macPhyTxPower = MAC_RADIO_TX_POWER_DEFAULT; } [mac_low_level.h] uint8 macRadioRandomByte(void); void macRadioSetPanCoordinator(uint8 panCoordinator); void macRadioSetPanID(uint16 panID); void macRadioSetShortAddr(uint16 shortAddr); void macRadioSetIEEEAddr(uint8 * pIEEEAddr); void macRadioSetTxPower(uint8 txPower); void macRadioSetChannel(uint8 channel); void macRadioStartScan(uint8 scanType); void macRadioStopScan(void); void macRadioEnergyDetectStart(void); uint8 macRadioEnergyDetectStop(void);
設(shè)置發(fā)射功率: CC2530 設(shè)置RF的發(fā)送功率寄存器為T(mén)XPOWER,全局搜索一下可以看到以下代碼
[csharp] view plaincopy 
- #define MAC_RADIO_SET_PAN_COORDINATOR(b) st( FRMFILT0 = (FRMFILT0 & ~PAN_COORDINATOR) | (PAN_COORDINATOR * (b!=0)); )
- #define MAC_RADIO_SET_CHANNEL(x) st( FREQCTRL = FREQ_2405MHZ + 5 * ((x) - 11); )
- #define MAC_RADIO_SET_TX_POWER(x) st( TXPOWER = x; )</font>
-
- #define MAC_RADIO_SET_PAN_ID(x) st( PAN_ID0 = (x) & 0xFF; PAN_ID1 = (x) >> 8; )
- #define MAC_RADIO_SET_SHORT_ADDR(x) st( SHORT_ADDR0 = (x) & 0xFF; SHORT_ADDR1 = (x) >> 8; )
繼續(xù)跟蹤MAC_RADIO_SET_TX_POWER
[csharp] view plaincopy 
- /**************************************************************************************************
- * @fn macRadioUpdateTxPower
- *
- * @brief Update the radio's transmit power if a new power level has been requested
- *
- * @param reqTxPower - file scope variable that holds the last request power level
- * macPhyTxPower - global variable that holds radio's set power level
- *
- * @return none
- **************************************************************************************************
- */
- MAC_INTERNAL_API void macRadioUpdateTxPower(void)
- {
- halIntState_t s;
-
- /*
- * If the requested power setting is different from the actual radio setting,
- * attempt to udpate to the new power setting.
- */
- HAL_ENTER_CRITICAL_SECTION(s);
- if (reqTxPower != macPhyTxPower)
- {
- /*
- * Radio power cannot be updated when the radio is physically transmitting.
- * If there is a possibility radio is transmitting, do not change the power
- * setting. This function will be called again after the current transmit
- * completes.
- */
- if (!macRxOutgoingAckFlag && !MAC_TX_IS_PHYSICALLY_ACTIVE())
- {
- /*
- * Set new power level; update the shadow value and write
- * the new value to the radio hardware.
- */
- macPhyTxPower = reqTxPower;
- <font color="#ff0000"> MAC_RADIO_SET_TX_POWER(macPhyTxPower);</font>
- }
- }
- HAL_EXIT_CRITICAL_SECTION(s);
- }
在這里我們可以看到TXPOWER的設(shè)置值實(shí)際上應(yīng)該是reqTxOower,讓我看一下reqTxOower在哪里設(shè)置吧,繼續(xù)跟蹤可以發(fā)現(xiàn)reqTxPower在函數(shù)MAC_INTERNAL_API uint8 macRadioSetTxPower(uint8 txPower)中得到更新,一路跟蹤下去可以在函數(shù)uint8 MAC_MlmeSetReq(uint8 pibAttribute, void *pValue)看到以下代碼
[csharp] view plaincopy 
- case MAC_PHY_TRANSMIT_POWER:
- /* Legacy transmit power attribute */
- #if !defined HAL_MAC_USE_REGISTER_POWER_VALUES && \
- !defined HAL_PA_LNA && !defined HAL_PA_LNA_CC2590
- /* Legacy transmit power attribute value for CC2530 alone,
- * or runtime selection support build means a negative absolute value.
- * However, when used as register power values or
- * with HAL_PA_LNAxxx definition (without runtime selection)
- * the attribute value is not a negative absolute value. */
- macPib.phyTransmitPower = (uint8)(-(int8)macPib.phyTransmitPower);
- #endif /* !defined HAL_MAC_USE_REGISTER_POWER_VALUES && ... */
- /* pass through to next case -- do not break*/
-
- #endif /* MAC_OBSOLETE_PHY_TRANSMIT_POWER */
-
- case MAC_PHY_TRANSMIT_POWER_SIGNED:
- (void)macRadioSetTxPower(macPib.phyTransmitPower);
- break;
到這里為止Z-Stack發(fā)送功率的設(shè)置流程已經(jīng)明確,但是我找遍Z-Stack的工程也沒(méi)有找到調(diào)用uint8 MAC_MlmeSetReq(uint8 pibAttribute, void *pValue)的地方想來(lái)應(yīng)該是封裝在TI提供的LIB文件中了,
修改TXPOWER的方法有兩種:一、在uint8 macRadioSetTxPower(uint8 txPower)函數(shù)中通過(guò)修改macPib.phyTransmitPower = (uint8)(-(int8)macPib.phyTransmitPower);的值來(lái)修改TXPOWER參數(shù),系統(tǒng)復(fù)位后將使用調(diào)用該函數(shù)設(shè)置發(fā)送功率。修改macPib.phyTransmitPower = (uint8)(-(int8)macPib.phyTransmitPower);可以通過(guò)修改以下結(jié)構(gòu)體中的紅色部分來(lái)修改
[csharp] view plaincopy 
- static CODE const macPib_t macPibDefaults =
- {
- 54, /* ackWaitDuration */
- FALSE, /* associationPermit */
- TRUE, /* autoRequest */
- FALSE, /* battLifeExt */
- 6, /* battLifeExtPeriods */
-
- NULL, /* *pMacBeaconPayload */
- 0, /* beaconPayloadLength */
- MAC_BO_NON_BEACON, /* beaconOrder */
- 0, /* beaconTxTime */
- 0, /* bsn */
-
- {0, SADDR_MODE_EXT}, /* coordExtendedAddress */
- MAC_SHORT_ADDR_NONE, /* coordShortAddress */
- 0, /* dsn */
- FALSE, /* gtsPermit */
- 4, /* maxCsmaBackoffs */
-
- 3, /* minBe */
- 0xFFFF, /* panId */
- FALSE, /* promiscuousMode */
- FALSE, /* rxOnWhenIdle */
- MAC_SHORT_ADDR_NONE, /* shortAddress */
-
- MAC_SO_NONE, /* superframeOrder */
- 0x01F4, /* transactionPersistenceTime */
- FALSE, /* assocciatedPanCoord */
- 5, /* maxBe */
- 1220, /* maxFrameTotalWaitTime */
-
- 3, /* maxFrameRetries */
- 32, /* ResponseWaitTime */
- 0, /* syncSymbolOffset */
- TRUE, /* timeStampSupported */
- FALSE, /* securityEnabled */
-
- /* Proprietary */
- #if defined (HAL_PA_LNA)
- 19, /* phyTransmitPower for CC2591 */
- #elif defined (HAL_PA_LNA_CC2590)
- 11, /* phyTransmitPower for CC2590 */
- #else
- <span style="color:#ff0000;">0, /* phyTransmitPower without frontend */</span>
- #endif
- MAC_CHAN_11, /* logicalChannel */
- {0, SADDR_MODE_EXT}, /* extendedAddress */
- 1, /* altBe */
- MAC_BO_NON_BEACON, /* deviceBeaconOrder */
- };
該值可以再-22到3之間變化具體可以參考
[csharp] view plaincopy 
- const uint8 CODE macRadioDefsTxPwrBare[] =
- {
- 3, /* tramsmit power level of the first entry */
- (uint8)(int8)-22, /* transmit power level of the last entry */
- /* 3 dBm */ 0xF5, /* characterized as 4.5 dBm in datasheet */ //0
- /* 2 dBm */ 0xE5, /* characterized as 2.5 dBm in datasheet */
- /* 1 dBm */ 0xD5, /* characterized as 1 dBm in datasheet */
- /* 0 dBm */ 0xD5, /* characterized as 1 dBm in datasheet */
- /* -1 dBm */ 0xC5, /* characterized as -0.5 dBm in datasheet */
- /* -2 dBm */ 0xB5, /* characterized as -1.5 dBm in datasheet */
- /* -3 dBm */ 0xA5, /* characterized as -3 dBm in datasheet */
- /* -4 dBm */ 0x95, /* characterized as -4 dBm in datasheet */
- /* -5 dBm */ 0x95,
- /* -6 dBm */ 0x85, /* characterized as -6 dBm in datasheet */
- /* -7 dBm */ 0x85,
- /* -8 dBm */ 0x75, /* characterized as -8 dBm in datasheet */
- /* -9 dBm */ 0x75,
- /* -10 dBm */ 0x65, /* characterized as -10 dBm in datasheet */
- /* -11 dBm */ 0x65,
- /* -12 dBm */ 0x55, /* characterized as -12 dBm in datasheet */
- /* -13 dBm */ 0x55,
- /* -14 dBm */ 0x45, /* characterized as -14 dBm in datasheet */
- /* -15 dBm */ 0x45,
- /* -16 dBm */ 0x35, /* characterized as -16 dBm in datasheet */
- /* -17 dBm */ 0x35,
- /* -18 dBm */ 0x25, /* characterized as -18 dBm in datasheet */
- /* -19 dBm */ 0x25,
- /* -20 dBm */ 0x15, /* characterized as -20 dBm in datasheet */
- /* -21 dBm */ 0x15,
- /* -22 dBm */ 0x05 /* characterized as -22 dBm in datasheet */
- };
二、就是使用MT功能
[csharp] view plaincopy 
- void MT_SysSetTxPower(uint8 *pBuf)
- {
- /* A local variable to hold the signed dBm value of TxPower that is being requested. */
- uint8 signed_dBm_of_TxPower_requeseted;
-
- /*
- * A local variable to hold the signed dBm value of TxPower that can be set which is closest to
- * the requested dBm value of TxPower, but which is also valid according to a complex set of
- * compile-time and run-time configuration which is interpreted by the macRadioSetTxPower()
- * function.
- */
- uint8 signed_dBm_of_TxPower_range_corrected;
-
- /* Parse the requested dBm from the RPC message. */
- signed_dBm_of_TxPower_requeseted = pBuf[MT_RPC_POS_DAT0];
-
- /*
- * MAC_MlmeSetReq() will store an out-of-range dBm parameter value into the NIB. So it is not
- * possible to learn the actual dBm value that will be set by invoking MACMlmeGetReq().
- * But this actual dBm value is a required return value in the SRSP to this SREQ. Therefore,
- * it is necessary to make this redundant pre-call to macRadioSetTxPower() here in order to run
- * the code that will properly constrain the requested dBm to a valid range based on both the
- * compile-time and the run-time configurations that affect the available valid ranges
- * (i.e. MAC_MlmeSetReq() itself will invoke for a second time the macRadioSetTxPower() function).
- */
- <font color="#ff0000"> signed_dBm_of_TxPower_range_corrected = macRadioSetTxPower(signed_dBm_of_TxPower_requeseted);</font>
-
- /*
- * Call the function to store the requested dBm in the MAC PIB and to set the TxPower as closely
- * as possible within the TxPower range that is valid for the compile-time and run-time
- * configuration.
- */
- (void)MAC_MlmeSetReq(MAC_PHY_TRANSMIT_POWER_SIGNED, &signed_dBm_of_TxPower_requeseted);
-
- /* Build and send back the response that includes the actual dBm TxPower that can be set. */
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_SYS),
- MT_SYS_SET_TX_POWER, 1,
- &signed_dBm_of_TxPower_range_corrected);
- }
|