Skip to content

Decode poll data as consumers get it (pad a short poll), and read field values in one place - #53

Merged
robdobsn merged 2 commits into
mainfrom
feature/decode-subscriber-data
Nov 9, 2026
Merged

robdobsn merged 2 commits into
mainfrom
feature/decode-subscriber-data

Conversation

@robdobsn

@robdobsn robdobsn commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Problem

Every decoder (generated, runtime attribute decoder, code interpreter) reads whole records of the record's size: resp.b plus 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:

  • RaftMicroPy didn't: the CogPro's IMU reached scripts with no values.
  • The bus's latest value is unpadded too, so DeviceManager named values for such a device were never valid.
  • RaftROS: AutoPub padded; its example didn't.

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).
  • Static overloads take the decode function, sizes and caller-owned working space, for a consumer on the bus task.
  • AttrFieldDesc::getValue: reads one element of a field and applies what is still to be scaled. It comes with elemCount() and isIntegral().
  • Named values (getBusDeviceNamedValue) use it, and an array element is named with an index, e.g. diff[3].
  • The decoders themselves are unchanged. test_runtime_decoder already compares the three decoder kinds on truncated buffers.

Tests

  • New Linux test test_poll_data_decode (663 checks):
    • for every built-in record, data with a short last record decodes as the zero-padded data does, and the newest record matches;
    • a real LSM6DS3TR-C FIFO poll (68 bytes against a 248-byte record) decodes to nothing directly, and gives all 5 samples and the newest through decodePollData;
    • getValue reads every field and every element of the 19 array attributes as its struct bytes.
  • make check passes.

Used by

Each of these needs this PR:

  • RaftI2C: latest value and decoded responses.
  • RaftMicroPy: script data.
  • RaftROS: AutoPub and the example.

On the CogPro (ESP32-S3), a script now gets IMU values matching a direct register read, and the touch strip's 16-element diff array as a list. This is expected to become the CogPro's production firmware.

🤖 Generated with Claude Code

robdobsn and others added 2 commits November 9, 2026 18:09
…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>
@robdobsn
robdobsn merged commit ac09857 into main Nov 9, 2026
1 check passed
@robdobsn
robdobsn deleted the feature/decode-subscriber-data branch November 9, 2026 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant