Merged in antmerlino/nuttx/xbee-getset-txpwr (pull request #747)

Xbee getset txpwr

* drivers/wireless/ieee802154/xbee: Minor improvements to debug facilities.

* drivers/wireless/ieee802154/xbee: Add support for setting/getting tx power.

    TODO: The input/output arguments from the MLME primitive are intended to be an int32_t dbm value. However this change simply reports the power level register of the XBee. Need to add look-up table to back calculate the dbm value.

    # Conflicts:
    #	drivers/wireless/ieee802154/xbee/xbee.c

Approved-by: GregoryN <gnutt@nuttx.org>
This commit is contained in:
Anthony Merlino
2018-11-01 19:05:04 +00:00
committed by GregoryN
parent 7f10234468
commit 260d29a187
3 changed files with 148 additions and 2 deletions
+92 -1
View File
@@ -630,6 +630,23 @@ static void xbee_process_apiframes(FAR struct xbee_priv_s *priv,
wlinfo("XBee Retries: %d\n",
frame->io_data[frame->io_offset]);
}
else if (memcmp(command, "MM", 2) == 0)
{
wlinfo("Mac Mode: %d\n",
frame->io_data[frame->io_offset]);
}
else if (memcmp(command, "PL", 2) == 0)
{
wlinfo("Power Level: %d\n",
frame->io_data[frame->io_offset]);
priv->pwrlvl = frame->io_data[frame->io_offset++];
}
else if (memcmp(command, "PM", 2) == 0)
{
wlinfo("Boost Mode (Power Mode): %d\n",
frame->io_data[frame->io_offset]);
priv->boostmode = frame->io_data[frame->io_offset++];
}
else
{
wlwarn("Unhandled AT Response: %.*s\n", 2, command);
@@ -775,6 +792,8 @@ static void xbee_process_rxframe(FAR struct xbee_priv_s *priv,
frame->io_len--; /* Remove the checksum */
xbee_notify(priv, primitive);
wlinfo("Received frame. RSSI: -%d dbm\n", dataind->rssi);
}
/****************************************************************************
@@ -812,7 +831,14 @@ static void xbee_process_txstatus(FAR struct xbee_priv_s *priv, uint8_t frameid,
break;
}
wlinfo("TX done. Frame ID: %d Status: 0x%02X\n", frameid, status);
if (status != IEEE802154_STATUS_SUCCESS)
{
wlwarn("TX done. Frame ID: %d Status: 0x%02x\n", frameid, status);
}
else
{
wlinfo("TX done. Frame ID: %d Status: 0x%02x\n", frameid, status);
}
xbee_notify(priv, primitive);
}
@@ -1437,6 +1463,67 @@ void xbee_set_chan(FAR struct xbee_priv_s *priv, uint8_t chan)
xbee_send_apiframe(priv, frame, 9);
}
/****************************************************************************
* Name: xbee_set_powerlevel
*
* Description:
* Sends API frame with AT command request in order to set the RF power level
* of the device.
*
****************************************************************************/
void xbee_set_powerlevel(FAR struct xbee_priv_s *priv, uint8_t level)
{
uint8_t frame[9];
priv->pwrlvl = level;
frame[0] = XBEE_STARTBYTE;
frame[1] = 0;
frame[2] = 5;
frame[3] = XBEE_APIFRAME_ATCOMMMAND;
frame[4] = 0;
frame[5] = 'P';
frame[6] = 'L';
frame[7] = level;
xbee_insert_checksum(frame, 9);
xbee_send_apiframe(priv, frame, 9);
}
/****************************************************************************
* Name: xbee_set_boostmode
*
* Description:
* Sends API frame with AT command request in order to set the Boost mode
* setting of the device. NOTE: XBee Pro always enables boost mode and
* does not support this command
*
****************************************************************************/
void xbee_set_boostmode(FAR struct xbee_priv_s *priv, uint8_t mode)
{
uint8_t frame[9];
if (mode > 1) return;
priv->boostmode = mode;
frame[0] = XBEE_STARTBYTE;
frame[1] = 0;
frame[2] = 5;
frame[3] = XBEE_APIFRAME_ATCOMMMAND;
frame[4] = 0;
frame[5] = 'P';
frame[6] = 'M';
frame[7] = mode;
xbee_insert_checksum(frame, 9);
xbee_send_apiframe(priv, frame, 9);
}
/****************************************************************************
* Name: xbee_set_epassocflags
*
@@ -1561,6 +1648,10 @@ void xbee_regdump(FAR struct xbee_priv_s *priv)
xbee_send_atquery(priv, "CE");
xbee_send_atquery(priv, "A1");
xbee_send_atquery(priv, "A2");
xbee_send_atquery(priv, "AI");
xbee_send_atquery(priv, "SP");
xbee_send_atquery(priv, "RR");
xbee_send_atquery(priv, "MM");
xbee_send_atquery(priv, "PL");
xbee_send_atquery(priv, "PM");
}
+35
View File
@@ -198,6 +198,8 @@ struct xbee_priv_s
/****************** PHY attributes ***********************/
uint8_t chan;
uint8_t pwrlvl;
bool boostmode;
};
/****************************************************************************
@@ -349,6 +351,28 @@ void xbee_send_atquery(FAR struct xbee_priv_s *priv, FAR const char *atcommand);
#define xbee_query_chan(priv) xbee_atquery(priv, "CH")
/****************************************************************************
* Name: xbee_query_powerlevel
*
* Description:
* Sends API frame with AT command request in order to get the RF Power
* Level from the device.
*
****************************************************************************/
#define xbee_query_powerlevel(priv) xbee_atquery(priv, "PL")
/****************************************************************************
* Name: xbee_query_powermode
*
* Description:
* Sends API frame with AT command request in order to get the RF Power Mode
* from the device.
*
****************************************************************************/
#define xbee_query_powermode(priv) xbee_atquery(priv, "PM")
/****************************************************************************
* Name: xbee_query_assoc
*
@@ -393,6 +417,17 @@ void xbee_set_saddr(FAR struct xbee_priv_s *priv, FAR const uint8_t *saddr);
void xbee_set_chan(FAR struct xbee_priv_s *priv, uint8_t chan);
/****************************************************************************
* Name: xbee_set_powerlevel
*
* Description:
* Sends API frame with AT command request in order to set the RF power level
* of the device.
*
****************************************************************************/
void xbee_set_powerlevel(FAR struct xbee_priv_s *priv, uint8_t level);
/****************************************************************************
* Name: xbee_set_epassocflags
*
+21 -1
View File
@@ -56,7 +56,7 @@
#define XBEE_ASSOC_POLLDELAY 100
#define XBEE_RESPONSE_TIMEOUT MSEC2TICK(100)
#define XBEE_RESPONSE_TIMEOUT MSEC2TICK(200)
/****************************************************************************
* Private Types
@@ -457,6 +457,17 @@ int xbee_req_get(XBEEHANDLE xbee, enum ieee802154_attr_e attr,
}
break;
case IEEE802154_ATTR_PHY_TX_POWER:
{
/* TODO: Convert pwrlvl and boost mode settings to int32_t dbm. This
* depends on whether device is XBee or XBee Pro to do this look-up.
*/
xbee_query_powerlevel(priv);
attrval->phy.txpwr = priv->pwrlvl;
}
break;
case IEEE802154_ATTR_RADIO_REGDUMP:
{
xbee_regdump(priv);
@@ -529,6 +540,15 @@ int xbee_req_set(XBEEHANDLE xbee, enum ieee802154_attr_e attr,
}
}
break;
case IEEE802154_ATTR_PHY_TX_POWER:
{
/* TODO: Convert int32_t dbm input to closest PM/PL settings. Need to
* know whether device is XBee or XBee Pro to do this look-up.
*/
xbee_set_powerlevel(priv, attrval->phy.txpwr);
}
break;
#if 0
case IEEE802154_ATTR_MAC_COORD_SADDR:
{