Skip to content

feat(M4-P0B): three-stream binary V2 envelope with bounded CRC and atomic decode - #335

Merged
masarray merged 1 commit into
mainfrom
feat/m4-multisv-binary-v2
Oct 25, 2026
Merged

masarray merged 1 commit into
mainfrom
feat/m4-multisv-binary-v2

Conversation

@masarray

Copy link
Copy Markdown
Owner

M4-P0B — Binary 3-stream roster protocol envelope (host foundation)

Stacked on P0A #334 until it merges. Implements the binary contract, not MCU start/stop/TX tasks.

Implemented

  • New M4ThreeSvBinaryCodec with fixed 28-byte versioned ARM3 / V2 header and exactly 3 independently validated, length-prefixed existing ARSV V1 binary device records.
  • Aggregate sample clock field explicitly 4000 samples/s; validates 3 records (4I+4V 64B and 16 leaves each) and independently keyed MAC/APPID/VLAN/svID. Repeated APPID 0x4000 with distinct MACs accepted.
  • Allocation-free encode_into(span<uint8_t>) / decode(span<const uint8_t>), bounded profile lengths, big-endian numbers, CRC32 across envelope, nested per-record CRC, zero-reserved fields and full length equality.
  • All-or-nothing decode: candidate 3-stream roster is validated completely before overwriting caller's active output. Bad checksum, length, version, stream identity or data shape are rejected.
  • C++ regression test with real SCD-equivalent fixture: roundtrip all 3 profiles, byte stability, test buffer-too-small, CRC damage, unsupported schema, bad per-stream length, duplicate full SV identity and unsupported rate.

Still NOT delivered in this PR

Firmware V2 serial transfer/atomic staging/commit/readback; three EMAC TX streams; PTP-aligned scheduler; three isolated waveform-bank controls; GUI navigation. Follow #333 and the ARD for those packages.

Merge strategy

  1. Merge P0A feat(M4-P0A): compile 3 SCD Merging Unit SV profiles with bounded common 4kHz roster #334 only after GCC/Clang/MSVC C++ and other relevant CI pass.
  2. Retarget this PR onto main after P0A merges.
  3. Merge P0B after multi-compiler C++ CI, retaining M3.H.3 original stable assets untouched.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T10:28:10.972965Z db29357 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: db29357931

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +96 to +99
if (!valid_roster(p)) return std::nullopt;
std::size_t total = header_bytes;
for (const auto& profile : p) {
const auto size = SvDeviceProfileBinaryCodec::encoded_size(profile);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Validate profile lengths before comparing stream identities

When two input profiles have matching MAC/APPID/VLAN fields and equally oversized sv_id_length values, valid_roster() compares their IDs before the nested V1 codec validates those lengths. The resulting string_view comparison reads beyond the fixed 96-byte arrays instead of returning invalid_profile; an AddressSanitizer reproduction with lengths of 65535 reports a stack-buffer-overflow. Validate each profile through the existing V1 validation path before performing identity comparisons.

AGENTS.md reference: AGENTS.md:L57-L64

Useful? React with 👍 / 👎.

Comment on lines +61 to +63
p.leaf_count == 16U &&
p.payload_size_bytes == 64U &&
p.asdu_options.sample_synchronized;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Enforce the supported 4I+4V layout at the envelope boundary

A roster containing sixteen INT32 leaves per stream passes both encode and decode successfully, despite having no Quality leaves: these count/size checks do not establish the required eight ordered INT32+Quality pairs. The nested V1 codec intentionally accepts broader layouts, whereas the existing deployment gates in esp32p4_profile_support.hpp and compiled_profile_adapter.hpp reject them, along with unsupported ASDU options. Consequently, the new envelope can publish a supposedly validated M4 roster that the device rejects. Reuse a shared device-capability validator so this boundary preserves the existing layout and option restrictions.

AGENTS.md reference: AGENTS.md:L30-L31

Useful? React with 👍 / 👎.

@masarray
masarray force-pushed the feat/m4-multisv-binary-v2 branch from db29357 to bc353ab Compare October 25, 2026 10:33
@masarray
masarray changed the base branch from feat/m4-three-sv-scl-roster to main October 25, 2026 10:33
@masarray
masarray merged commit bcc497a into main Oct 25, 2026
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