-
Notifications
You must be signed in to change notification settings - Fork 2.1k
sys/inet/ieee802154/radio: fix wrong rssi conversions treewide #15616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys/inet/ieee802154/radio: fix wrong rssi conversions treewide #15616
Conversation
Added the RFC tag because I'm a bit confused about how the RSSI reporting is being done TBH. |
Maybe if @benpicco has the reference to #14371 (comment) this could be clarified? Seems that comment motivated the change. |
radio_info->rssi = _hwval_to_ieee802154_dbm(hwlqi) + IEEE802154_RADIO_RSSI_OFFSET; | ||
radio_info->rssi = _hwval_to_ieee802154_dbm(hwlqi) - IEEE802154_RADIO_RSSI_OFFSET; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
63b25e3
to
e49420c
Compare
Rebased to master |
There was a problem hiding this 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.
/* We calculate RSSI from LQI, since it's already 8-bit | ||
saturated */ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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? :)
There was a problem hiding this comment.
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.
Rebased. |
e49420c
to
621a5b1
Compare
I'm fine with squashing :-) |
c484985
to
49c90cd
Compare
squashed |
There was a problem hiding this 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.
thanks for the fix!! |
Thanks for the thorough review @jia200x! |
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: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