Proper unsigned value support for CRSF Telemetry #7066
+99
−117
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Alters the deserialization of CRSF telemetry to properly support unsigned values, and removes the check for values being -1.
Details
The CRSF telemetry parser currently unpacks every value as signed, regardless of what the spec says for that parameter. There are unsigned values in the spec though, and the current code (going all the way back) does not present them properly. For example the GPS packet's heading value is unsigned and that means that any value greater than 327.67 degrees shows up as negative. Betaflight telemetry example:
In addition, the current code checks for values where every byte sent is 0xff and discards the value if that condition is met. There is nothing in the CRSF spec that says "send 0xff... to not update the value", the only mention is on the 0x09 Barometric Altitude description where the example contains a comment stating "OpenTX counts any 0xFFFF [altitude] value as incorrect". Due to this code being used always, any telemetry parameter anywhere will ignore 0xff, 0xffff, 0xffffff, or 0xffffffff. This has been removed for also not matching the CRSF spec.
I also removed the template function used to do the parsing. I am not sure who was like ooh this is gonna really optimize performance when the compiler unrolls that loop for me! It's stupid, just pass the size.
Now-Unsigned Telemetry Items
See? It works! Code size is also reduced by this change by 192 bytes.