Repository navigation
Decode poll data as consumers get it (pad a short poll), and read field values in one place - #53
Merged
Merged
Conversation
…lues in one place
A data subscriber (registerForDeviceData) and the bus's latest value get each poll result at its actual length.
The decoders read whole records of the record's size (resp.b plus the timestamp), as the poll store keeps them, so
a poll with a variable read length (an LSM6DS FIFO read, r{...}) decoded to nothing unless the consumer padded it.
RaftMicroPy didn't, nor did RaftROS's example; RaftROS's AutoPub did.
- DeviceTypeRecords::decodePollData pads a last record cut short with zeros, as the poll store does, and decodes;
decodeNewestPollRecord keeps only the newest record and returns how many the poll held. Static overloads take
the decode function and sizes, and working space, for a consumer on the bus task.
- AttrFieldDesc::getValue reads one element of a field from a decoded record and applies what is still to be
scaled; elemCount() and isIntegral() go with it. DeviceManager, RaftMicroPy and RaftROS each had their own copy.
- The decoders are unchanged: test_runtime_decoder already compares the three decoder kinds on truncated buffers.
- New Linux test test_poll_data_decode: for every built-in record, a short last record decodes as the zero-padded
data does; a real LSM6DS3TR-C FIFO poll gives every sample and the newest; getValue reads every field and every
element of array attributes as its struct bytes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d value reader; name[i] for array elements getBusDeviceNamedValue reads the value with AttrFieldDesc::getValue, and an array attribute's element is named with an index (e.g. "diff[3]"). The latest decoded poll response is the newest record of a poll that holds several (the bus implementation decodes it with decodeNewestPollRecord). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Every decoder (generated, runtime attribute decoder, code interpreter) reads whole records of the record's size:
resp.bplus the 2-byte timestamp. The bus's poll store pads each result to that size, but data subscribers (registerForDeviceData) and the latest value get each poll at its actual length.A poll with a variable read length (an LSM6DS FIFO read,
r{...}) is shorter than the record, so it decoded to nothing unless the consumer padded it:The code that reads a value out of a decoded record was also written three times (DeviceManager, RaftMicroPy, RaftROS), and the copies differed on arrays.
Change
DeviceTypeRecords::decodePollData: pads a last record cut short with zeros, as the poll store does, and decodes.DeviceTypeRecords::decodeNewestPollRecord: keeps only the newest record and returns how many the poll held (a FIFO poll holds several).AttrFieldDesc::getValue: reads one element of a field and applies what is still to be scaled. It comes withelemCount()andisIntegral().getBusDeviceNamedValue) use it, and an array element is named with an index, e.g.diff[3].test_runtime_decoderalready compares the three decoder kinds on truncated buffers.Tests
test_poll_data_decode(663 checks):decodePollData;getValuereads every field and every element of the 19 array attributes as its struct bytes.make checkpasses.Used by
Each of these needs this PR:
On the CogPro (ESP32-S3), a script now gets IMU values matching a direct register read, and the touch strip's 16-element
diffarray as a list. This is expected to become the CogPro's production firmware.🤖 Generated with Claude Code