[riot-notifications] [RIOT-OS/RIOT] ieee802154: add helpers for RSSI and dBm conversion (#15629)

Marian Buschsieweke notifications at github.com
Wed Jan 13 13:36:34 CET 2021


@maribu approved this pull request.

ACK. If you agree with the style nit, squash in right away.

Also: As this is a dependency for a bug fix PR, I think this should go in despite soft feature freeze. (And this PR isn't scary either, especially due to proper unit testing.)

> + * 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;

```suggestion
    int val = dbm <= min ? min : (dbm >= max ? max : dbm);
```

I personally think braces here increase readability. Feel free to ignore, if you disagree.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/15629#pullrequestreview-567177014
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210113/1f3a8783/attachment.htm>


More information about the notifications mailing list