Skip to content

Conversation

fjmolinas
Copy link
Contributor

Contribution description

I'm under the impression that the rssi conversion is wrongly done in many places involved with the radio_hal. The api says:

    /**
     * @brief RSSI of the received frame.
     *
     * The RSSI is a measure of the RF power in dBm for the received frame.
     * The minimum and maximum values are 0 (-174 dBm) and 254 (80 dBm).
     */
    uint8_t rssi;

But in practice what was being done for cc2538 was a wrong compensation (with some weird double negations) which led to a -28db penalty in the reported value.

A similar case happend for nrf52840.

Then all users of this reported value where using the value as dB and not adjusting by the offset.

I came across this issue when comparing Vanilla OpenWSN and RIOT OpenWSN side by side and realizing there was an unexplained penalty in the reported RSSI.

I went back in history to look at when these changes where made specially for cc2538, I honestly got quite confused with the whole discussion so maybe I'm wrong about the values?

Testing procedure

  • Look at the code

  • tests/ieee802154_hal should print correct rssi.

Related Issues

Related to #14672
Related to #14791
Related to #14791

@fjmolinas fjmolinas added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: network Area: Networking labels Dec 11, 2020
@fjmolinas fjmolinas added the Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR label Dec 11, 2020
@fjmolinas
Copy link
Contributor Author

Added the RFC tag because I'm a bit confused about how the RSSI reporting is being done TBH.

@fjmolinas
Copy link
Contributor Author

Maybe if @benpicco has the reference to #14371 (comment) this could be clarified? Seems that comment motivated the change.

@miri64 miri64 requested a review from roberthartung December 11, 2020 14:18
radio_info->rssi = _hwval_to_ieee802154_dbm(hwlqi) + IEEE802154_RADIO_RSSI_OFFSET;
radio_info->rssi = _hwval_to_ieee802154_dbm(hwlqi) - IEEE802154_RADIO_RSSI_OFFSET;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, can it overflow?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it comes from the hardware, I would prefer to have it clamped. As described above, we never know what might happen in the radio

@fjmolinas fjmolinas force-pushed the pr_ieee802154_rssi_conversion branch from 63b25e3 to e49420c Compare January 13, 2021 08:29
@fjmolinas fjmolinas requested a review from miri64 as a code owner January 13, 2021 08:29
@fjmolinas fjmolinas added the State: waiting for other PR State: The PR requires another PR to be merged first label Jan 13, 2021
@fjmolinas
Copy link
Contributor Author

Rebased to master

@fjmolinas
Copy link
Contributor Author

@jia200x rebase on top of #15629

@benpicco benpicco requested a review from maribu January 13, 2021 09:49
Copy link
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment regarding the nRF802154 radio. But likely I'm just missing context to understand this.

Comment on lines 233 to 234
/* We calculate RSSI from LQI, since it's already 8-bit
saturated */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing context, but this comment confuses me more than it helps. I also don't quite understand how RSSI can be calculated from LQI. There doesn't seem to be a consistent definition (at least when also considering non-802.15.4 devices) for the LQI. But it seems to be mostly based on bit error rates, on "how easy a received signal can be demodulated" (citing the CC1101 datasheet), or the signal to noise ratio.

So as far as I understood, the LQI can be quite good for a weak signal (if both receiver and transmitter perform optimal and no interference, noise, scattering, reflection or other effects impacting the signal quality are present). Similar, a high RSSI doesn't necessarily mean a high LQI: E.g. when the receiver is right next to the sender, but also right next to an interfering device (e.g. an 802.11 device) the link quality can be poor.

So to my best knowledge, RSSI and LQI are orthogonal to each other and one cannot compute one from the other.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jia200x mind suggesting a better comment since I took this from your suggestion :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comes from the datasheet:

When a packet is received a link quality indicator (LQI) is also generated and appended immediately after the last received octet. When using
IEEE 802.15.4 compliant frame this will be just after the MSDU since the FCS is not reported. In the case of a non-complient frame it will be
appended after the full frame. The LQI reported by hardware must be converted to IEEE 802.15.4 range by an 8-bit saturating multiplication by 4,
as shown in the code example for ED sampling. The LQI is only valid for frames equal to or longer than three octets. When receiving a frame the
RSSI (reported as negative dB) will be measured at three points during the reception. These three values will be sorted and the middle one selected
(median 3) for then to be remapped within the LQI range. The following figure illustrates the LQI measurement and how the data is arranged in
the DataRAM:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add a reference to the datasheet for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So to my best knowledge, RSSI and LQI are orthogonal to each other and one cannot compute one from the other.

This was my understanding too. I agree it looks weird. That's what I interpret from the datasheet at least.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively, we can introduce a CAP. That would help to optimize the binary later

Copy link
Contributor Author

@fjmolinas fjmolinas Jan 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the standard I'm not convinced the value is wrong ieee802154-2020 p.457:

10.2.7 Link quality indicator (LQI)
The LQI measurement is a characterization of the strength and/or quality of a received packet. The
measurement may be implemented using receiver ED, a signal-to-noise ratio estimation, or a combination of
these methods. The use of the LQI result by the network or application layers is not specified in this
standard.
The LQI measurement shall be performed for each received packet. The minimum and maximum LQI
values (0x00 and 0xff) should be associated with the lowest and highest quality compliant signals detectable
by the receiver, and LQI values in between should be uniformly distributed between these two limits. At
least eight unique values of LQI shall be used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then let's leave it as it is now. I had the same impression as @maribu , but I htink the standard is the reference here.
I know that comment about LQI and RSSI was written somewhere (at86rf2xx?), but I think it will be better to follow the standard here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maribu are you ok with that? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the RM reference to the comment.

@fjmolinas
Copy link
Contributor Author

Rebased.

@fjmolinas fjmolinas force-pushed the pr_ieee802154_rssi_conversion branch from e49420c to 621a5b1 Compare January 13, 2021 16:48
@fjmolinas
Copy link
Contributor Author

@maribu @jia200x let me know if its Ok to squash

@maribu
Copy link
Member

maribu commented Jan 13, 2021

I'm fine with squashing :-)

@fjmolinas fjmolinas removed the State: waiting for other PR State: The PR requires another PR to be merged first label Jan 13, 2021
@fjmolinas fjmolinas force-pushed the pr_ieee802154_rssi_conversion branch from c484985 to 49c90cd Compare January 13, 2021 18:45
@fjmolinas fjmolinas added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jan 13, 2021
@fjmolinas
Copy link
Contributor Author

squashed

Copy link
Member

@jia200x jia200x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. We should have this one before the Hard Feature freeze and this is not considered I high impact feature. Let's get it there.

@jia200x jia200x merged commit db44967 into RIOT-OS:master Jan 13, 2021
@jia200x
Copy link
Member

jia200x commented Jan 13, 2021

thanks for the fix!!

@fjmolinas
Copy link
Contributor Author

Thanks for the thorough review @jia200x!

@fjmolinas fjmolinas deleted the pr_ieee802154_rssi_conversion branch January 13, 2021 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants