ieee802154: add helpers for RSSI and dBm conversion
This commit is contained in:
parent
605220ce06
commit
49f4ecc595
@ -422,6 +422,49 @@ static inline eui64_t *ieee802154_get_iid(eui64_t *eui64, const uint8_t *addr,
|
|||||||
return eui64;
|
return eui64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert from RSSI scale to dBm.
|
||||||
|
*
|
||||||
|
* The RSSI calculation is based on the IEEE 802.15.4 2020 specification and
|
||||||
|
* it's represented as one octet of integer.
|
||||||
|
*
|
||||||
|
* RSSI equal to zero maps to -174 dBm and has the same scale as dBm (1 RSSI
|
||||||
|
* step == 1 dBm). Therefore an RSSI value of 254 maps to +80 dBm.
|
||||||
|
*
|
||||||
|
* @note RSSI == 255 is defined as reserved by the standard and ignored by this
|
||||||
|
* function.
|
||||||
|
*
|
||||||
|
* @param[in] rssi RF power in RSSI scale
|
||||||
|
*
|
||||||
|
* @return RF power in dBm scale
|
||||||
|
*/
|
||||||
|
static inline int16_t ieee802154_rssi_to_dbm(uint8_t rssi)
|
||||||
|
{
|
||||||
|
return rssi + IEEE802154_RADIO_RSSI_OFFSET;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert from dBm scale to RSSI.
|
||||||
|
*
|
||||||
|
* The RSSI calculation is based on the IEEE 802.15.4 2020 specification and
|
||||||
|
* it's represented as one octet of integer.
|
||||||
|
*
|
||||||
|
* RSSI equal to zero maps to -174 dBm and has the same scale as dBm (1 RSSI
|
||||||
|
* step == 1 dBm). Therefore an RSSI value of 254 maps to +80 dBm.
|
||||||
|
*
|
||||||
|
* @param[in] dbm RF power in dBm scale.
|
||||||
|
*
|
||||||
|
* @return RF power in RSSI scale.
|
||||||
|
*/
|
||||||
|
static inline uint8_t ieee802154_dbm_to_rssi(int16_t dbm)
|
||||||
|
{
|
||||||
|
const int min = IEEE802154_RADIO_RSSI_OFFSET;
|
||||||
|
const int max = min + (UINT8_MAX - 1);
|
||||||
|
|
||||||
|
int val = dbm <= min ? min : (dbm >= max ? max : dbm);
|
||||||
|
return val - IEEE802154_RADIO_RSSI_OFFSET;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user