Zigbee 设置信道,PANID,发射功率

现对z-stack里几个网络参数的设置以及如何获取总结一下。

信道配置:

Zigbee在3个频段定义了27个物理信道:868MHz频段中定义了1个信道,915MHz频段中定义了2个信道,信道间隔为2MHz,2.4GHz频段上定义了16个信道,信道间隔为5MHz.

信道编号

中心频率/MHz

信道间隔/MHz

频率上限/MHz

频率下限/MHz

k=0

868.3

868.6

868.0

k=1,2,…,10

906+2(k-1)

2

928.0

902.0

k=11,12,…,26

2401+5(k-11)

5

2483.5

2400.0

Z-stack中可以在f8wConfig.cfg里设置信道,相关部分如下:

/* 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    这里默认使用的是编号为11的信道

当建网过程开始后,网络层将请求MAC层对规定的信道或由物理层默认的有效信道进行能量检测扫描,以检测可能的干扰。网络层管理实体对能量扫描的结果以递增的方式排序,丢弃那些能量值超出可允许能量水平的信道,然后再由网络层管理实体执行一次主动扫描,结合检查PAN描述符,对剩下的信道选择一个合适的建立网络。

若要在应用中查看信道,可以这样获得,_NIB.nwkLogicalChannel,读取这个就OK了。(NIB -NWK Information base-. 其中包含一些网络属性 PANID ,NETWORK ADDRESS 等等。其中_nib.nwkpanID是本网的ID标识,_NIB.extendedPANID按照字面意思是外网ID)

PANID:

在确定信道以后,下一步将是确定PANID,如果ZDAPP_CONFIG_PAN_ID被定义为0xFFFF,那么协调器将根据自身的IEEE地址建立一个随机的PANID(0~0x3FFF),如ZDAPP_CONFIG_PAN_ID没有被定义为0xFFFF,那么网络的PANID将由ZDAPP_CONFIG_PAN_ID确定。

“如果ZDAPP_CONFIG_PAN_ID被定义为0xFFFF,那么协调器将根据自身的IEEE地址建立一个随机的PANID(0~0x3FFF)”这句话怎么理解呢,我经过试验发现,这个随机的PANID并非完全随机,它有规律,与IEEE地址有一定的关系:要么就是IEEE地址的低16位,要么就是一个与IEEE地址低16位非常相似的值。如IEEE地址为0x8877665544332211,PANID很有可能就是2211,或相似的值;IEEE地址为0x8877665544337777,PANID很有可能就是3777,或其它相似的值;

Z-stack中相关部分代码如下:

/* 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

若要在应用中查看PANID可以这样获得,_NIB.nwkPanId,读取这个就OK了。

发射功率:

传送范围的大小是和发射功率还有信道环境有关, 传送速率和传送范围之间没有直接联系。所以呢,适当的增大发射功率可增大传送范围。但也是有一定的限制的。具体详见datasheet。

在mac_radio_def.h里有可以设置:

#define MAC_RADIO_CHANNEL_DEFAULT               11

#define MAC_RADIO_TX_POWER_DEFAULT              0x1F

#define MAC_RADIO_TX_POWER_MAX_MINUS_DBM        25

这些只是举例说明一下,这些参数的意义,以及在z-stack里的什么地方修改。还有很多其它的参数,可以查看相关的源文件。

[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);


设置发射功率:

CC2530 设置RF的发送功率寄存器为TXPOWER,全局搜索一下可以看到以下代码


[csharp] view plain copy
print ?
  1. #define MAC_RADIO_SET_PAN_COORDINATOR(b)              st( FRMFILT0 = (FRMFILT0 & ~PAN_COORDINATOR) | (PAN_COORDINATOR * (b!=0)); )  
  2. #define MAC_RADIO_SET_CHANNEL(x)                      st( FREQCTRL = FREQ_2405MHZ + 5 * ((x) - 11); )  
  3. #define MAC_RADIO_SET_TX_POWER(x)                     st( TXPOWER = x; )</font>  
  4.  
  5. #define MAC_RADIO_SET_PAN_ID(x)                       st( PAN_ID0 = (x) & 0xFF; PAN_ID1 = (x) >> 8; )  
  6. #define MAC_RADIO_SET_SHORT_ADDR(x)                   st( SHORT_ADDR0 = (x) & 0xFF; SHORT_ADDR1 = (x) >> 8; )  
#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; )

继续跟踪MAC_RADIO_SET_TX_POWER

[csharp] view plain copy
print ?
  1. /************************************************************************************************** 
  2. * @fn          macRadioUpdateTxPower 
  3. * 
  4. * @brief       Update the radio’s transmit power if a new power level has been requested 
  5. * 
  6. * @param       reqTxPower - file scope variable that holds the last request power level 
  7. *              macPhyTxPower - global variable that holds radio’s set power level 
  8. * 
  9. * @return      none 
  10. ************************************************************************************************** 
  11. */  
  12. MAC_INTERNAL_API void macRadioUpdateTxPower(void)  
  13. {  
  14.   halIntState_t  s;  
  15.   
  16.   /* 
  17.    *  If the requested power setting is different from the actual radio setting, 
  18.    *  attempt to udpate to the new power setting. 
  19.    */  
  20.   HAL_ENTER_CRITICAL_SECTION(s);  
  21.   if (reqTxPower != macPhyTxPower)  
  22.   {  
  23.     /* 
  24.      *  Radio power cannot be updated when the radio is physically transmitting. 
  25.      *  If there is a possibility radio is transmitting, do not change the power 
  26.      *  setting.  This function will be called again after the current transmit 
  27.      *  completes. 
  28.      */  
  29.     if (!macRxOutgoingAckFlag && !MAC_TX_IS_PHYSICALLY_ACTIVE())  
  30.     {  
  31.       /* 
  32.        *  Set new power level;  update the shadow value and write 
  33.        *  the new value to the radio hardware. 
  34.        */  
  35.       macPhyTxPower = reqTxPower;  
  36. <font color=”#ff0000”>      MAC_RADIO_SET_TX_POWER(macPhyTxPower);</font>  
  37.     }  
  38.   }  
  39.   HAL_EXIT_CRITICAL_SECTION(s);  
  40. }  
/**************************************************************************************************
* @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的设置值实际上应该是reqTxOower,让我看一下reqTxOower在哪里设置吧,继续跟踪可以发现reqTxPower在函数MAC_INTERNAL_API uint8 macRadioSetTxPower(uint8 txPower)中得到更新,一路跟踪下去可以在函数uint8 MAC_MlmeSetReq(uint8 pibAttribute, void *pValue)看到以下代码

[csharp] view plain copy
print ?
  1.     case MAC_PHY_TRANSMIT_POWER:  
  2.       /* Legacy transmit power attribute */  
  3. #if !defined HAL_MAC_USE_REGISTER_POWER_VALUES && \  
  4.   !defined HAL_PA_LNA && !defined HAL_PA_LNA_CC2590  
  5.       /* Legacy transmit power attribute value for CC2530 alone, 
  6.        * or runtime selection support build means a negative absolute value. 
  7.        * However, when used as register power values or 
  8.        * with HAL_PA_LNAxxx definition (without runtime selection) 
  9.        * the attribute value is not a negative absolute value. */  
  10.       macPib.phyTransmitPower = (uint8)(-(int8)macPib.phyTransmitPower);  
  11. #endif /* !defined HAL_MAC_USE_REGISTER_POWER_VALUES && … */  
  12.       /* pass through to next case – do not break*/  
  13.  
  14. #endif /* MAC_OBSOLETE_PHY_TRANSMIT_POWER */  
  15.   
  16.     case MAC_PHY_TRANSMIT_POWER_SIGNED:  
  17.       (void)macRadioSetTxPower(macPib.phyTransmitPower);  
  18.       break;  
    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;</pre><br>

到这里为止Z-Stack发送功率的设置流程已经明确,但是我找遍Z-Stack的工程也没有找到调用uint8 MAC_MlmeSetReq(uint8 pibAttribute, void *pValue)的地方想来应该是封装在TI提供的LIB文件中了,
修改TXPOWER的方法有两种:一、在uint8 macRadioSetTxPower(uint8 txPower)函数中通过修改macPib.phyTransmitPower = (uint8)(-(int8)macPib.phyTransmitPower);的值来修改TXPOWER参数,系统复位后将使用调用该函数设置发送功率。修改macPib.phyTransmitPower
= (uint8)(-(int8)macPib.phyTransmitPower);可以通过修改以下结构体中的红色部分来修改

[csharp] view plain copy
print ?
  1. static CODE const macPib_t macPibDefaults =  
  2. {  
  3.   54,                                         /* ackWaitDuration */  
  4.   FALSE,                                      /* associationPermit */  
  5.   TRUE,                                       /* autoRequest */  
  6.   FALSE,                                      /* battLifeExt */  
  7.   6,                                          /* battLifeExtPeriods */  
  8.   
  9.   NULL,                                       /* *pMacBeaconPayload */  
  10.   0,                                          /* beaconPayloadLength */  
  11.   MAC_BO_NON_BEACON,                          /* beaconOrder */  
  12.   0,                                          /* beaconTxTime */  
  13.   0,                                          /* bsn */  
  14.   
  15.   {0, SADDR_MODE_EXT},                        /* coordExtendedAddress */  
  16.   MAC_SHORT_ADDR_NONE,                        /* coordShortAddress */  
  17.   0,                                          /* dsn */  
  18.   FALSE,                                      /* gtsPermit */  
  19.   4,                                          /* maxCsmaBackoffs */  
  20.   
  21.   3,                                          /* minBe */  
  22.   0xFFFF,                                     /* panId */  
  23.   FALSE,                                      /* promiscuousMode */  
  24.   FALSE,                                      /* rxOnWhenIdle */  
  25.   MAC_SHORT_ADDR_NONE,                        /* shortAddress */  
  26.   
  27.   MAC_SO_NONE,                                /* superframeOrder */  
  28.   0x01F4,                                     /* transactionPersistenceTime */  
  29.   FALSE,                                      /* assocciatedPanCoord */  
  30.   5,                                          /* maxBe */  
  31.   1220,                                       /* maxFrameTotalWaitTime */  
  32.   
  33.   3,                                          /* maxFrameRetries */  
  34.   32,                                         /* ResponseWaitTime */  
  35.   0,                                          /* syncSymbolOffset */  
  36.   TRUE,                                       /* timeStampSupported */  
  37.   FALSE,                                      /* securityEnabled */  
  38.   
  39.   /* Proprietary */  
  40. #if defined (HAL_PA_LNA)  
  41.   19,                                         /* phyTransmitPower for CC2591 */  
  42. #elif defined (HAL_PA_LNA_CC2590)  
  43.   11,                                         /* phyTransmitPower for CC2590 */  
  44. #else  
  45. <span style=”color:#ff0000;”>0,                                          /* phyTransmitPower without frontend */</span>  
  46. #endif  
  47.   MAC_CHAN_11,                                /* logicalChannel */  
  48.   {0, SADDR_MODE_EXT},                        /* extendedAddress */  
  49.   1,                                          /* altBe */  
  50.   MAC_BO_NON_BEACON,                          /* deviceBeaconOrder */  
  51. };  
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

0, /* phyTransmitPower without frontend */

endif

MAC_CHAN_11, /* logicalChannel */
{0, SADDR_MODE_EXT}, /* extendedAddress */
1, /* altBe */
MAC_BO_NON_BEACON, /* deviceBeaconOrder */
};
该值可以再-22到3之间变化具体可以参考

[csharp] view plain copy
print ?
  1. const uint8 CODE macRadioDefsTxPwrBare[] =  
  2. {  
  3.   3,  / tramsmit power level of the first entry /  
  4.   (uint8)(int8)-22, / transmit power level of the last entry /  
  5.   /   3 dBm /   0xF5,   / characterized as  4.5 dBm in datasheet /    //0  
  6.   /   2 dBm /   0xE5,   / characterized as  2.5 dBm in datasheet /  
  7.   /   1 dBm /   0xD5,   / characterized as  1   dBm in datasheet /  
  8.   /   0 dBm /   0xD5,   / characterized as  1   dBm in datasheet /  
  9.   /  -1 dBm /   0xC5,   / characterized as -0.5 dBm in datasheet /  
  10.   /  -2 dBm /   0xB5,   / characterized as -1.5 dBm in datasheet /  
  11.   /  -3 dBm /   0xA5,   / characterized as -3   dBm in datasheet /  
  12.   /  -4 dBm /   0x95,   / characterized as -4   dBm in datasheet /  
  13.   /  -5 dBm /   0x95,  
  14.   /  -6 dBm /   0x85,   / characterized as -6   dBm in datasheet /  
  15.   /  -7 dBm /   0x85,  
  16.   /  -8 dBm /   0x75,   / characterized as -8   dBm in datasheet /  
  17.   /  -9 dBm /   0x75,  
  18.   / -10 dBm /   0x65,   / characterized as -10  dBm in datasheet /  
  19.   / -11 dBm /   0x65,  
  20.   / -12 dBm /   0x55,   / characterized as -12  dBm in datasheet /  
  21.   / -13 dBm /   0x55,  
  22.   / -14 dBm /   0x45,   / characterized as -14  dBm in datasheet /  
  23.   / -15 dBm /   0x45,  
  24.   / -16 dBm /   0x35,   / characterized as -16  dBm in datasheet /  
  25.   / -17 dBm /   0x35,  
  26.   / -18 dBm /   0x25,   / characterized as -18  dBm in datasheet /  
  27.   / -19 dBm /   0x25,  
  28.   / -20 dBm /   0x15,   / characterized as -20  dBm in datasheet /  
  29.   / -21 dBm /   0x15,  
  30.   / -22 dBm /   0x05    / characterized as -22  dBm in datasheet /  
  31. };  
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 plain copy
print ?
  1. void MT_SysSetTxPower(uint8 pBuf)  
  2. {  
  3.   / A local variable to hold the signed dBm value of TxPower that is being requested. /  
  4.   uint8 signed_dBm_of_TxPower_requeseted;  
  5.   
  6.   / 
  7.     A local variable to hold the signed dBm value of TxPower that can be set which is closest to 
  8.     the requested dBm value of TxPower, but which is also valid according to a complex set of 
  9.     compile-time and run-time configuration which is interpreted by the macRadioSetTxPower() 
  10.     function. 
  11.    /  
  12.   uint8 signed_dBm_of_TxPower_range_corrected;  
  13.   
  14.   / Parse the requested dBm from the RPC message. /  
  15.   signed_dBm_of_TxPower_requeseted = pBuf[MT_RPC_POS_DAT0];  
  16.   
  17.   / 
  18.     MAC_MlmeSetReq() will store an out-of-range dBm parameter value into the NIB. So it is not 
  19.     possible to learn the actual dBm value that will be set by invoking MACMlmeGetReq(). 
  20.     But this actual dBm value is a required return value in the SRSP to this SREQ. Therefore, 
  21.     it is necessary to make this redundant pre-call to macRadioSetTxPower() here in order to run 
  22.     the code that will properly constrain the requested dBm to a valid range based on both the 
  23.     compile-time and the run-time configurations that affect the available valid ranges 
  24.     (i.e. MAC_MlmeSetReq() itself will invoke for a second time the macRadioSetTxPower() function). 
  25.    /  
  26. <font color=”#ff0000”>  signed_dBm_of_TxPower_range_corrected = macRadioSetTxPower(signed_dBm_of_TxPower_requeseted);</font>  
  27.   
  28.   / 
  29.     Call the function to store the requested dBm in the MAC PIB and to set the TxPower as closely 
  30.     as possible within the TxPower range that is valid for the compile-time and run-time 
  31.     configuration. 
  32.    /  
  33.   (void)MAC_MlmeSetReq(MAC_PHY_TRANSMIT_POWER_SIGNED, &signed_dBm_of_TxPower_requeseted);  
  34.   
  35.   / Build and send back the response that includes the actual dBm TxPower that can be set. */  
  36.   MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_SYS),  
  37.                                        MT_SYS_SET_TX_POWER, 1,  
  38.                                        &signed_dBm_of_TxPower_range_corrected);  
  39. }  
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);
}
转载:http://bbs.leekie.net/thread-5-1-1.html

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值