Skip to content

Fix SEL CWS data-frame sample misalignment (samples 1-49 read 16 bytes early)#540

Merged
clackner-gpa merged 1 commit into
masterfrom
SELOffsetError
May 27, 2026
Merged

Fix SEL CWS data-frame sample misalignment (samples 1-49 read 16 bytes early)#540
clackner-gpa merged 1 commit into
masterfrom
SELOffsetError

Conversation

@ritchiecarroll
Copy link
Copy Markdown
Member

Summary

  • SEL CWS FrameParser.ParseFrame advanced the buffer by 32 bytes (timestamp +
    first sample) after the base parser handled sample 0, omitting the 16-byte
    common header. Samples 1-49 of every 50-sample packet were therefore read 16
    bytes (4 analog channels) too early.
  • Effect: each misaligned sample returned [VC(prev), IA(prev), IB(prev), IC(prev), VA(cur), VB(cur)] mislabeled as [VA,VB,VC,IA,IB,IC]; only the
    first sample per packet was correct, corrupting analog values and phase
    estimates.
  • Fix: advance offset/length by 48 (header 16 + timestamp 8 + first sample
    24) so all 50 samples align; sample 49 now ends exactly at the 1224-byte
    frame boundary.

Root cause

base.ParseFrame takes offset by value and leaves the caller's offset at the
frame start, so the manual loop must skip the entire initial frame (48 bytes),
not just its body (32). The bare 32 literal hid the missing header.

Not affected

On-wire framing and the voltage-first channel order (VA,VB,VC,IA,IB,IC,
confirmed by config-frame SignalNames) parse correctly. This was a local
offset-arithmetic defect, not a protocol/device issue.

The initial CWS data frame spans 48 bytes: 16-byte common header + 8-byte
nanosecond timestamp + first 24-byte sample. ParseFrame advanced only 32
(timestamp + first sample) before parsing the remaining 49 samples, omitting
the common header. This read samples 1-49 of every packet 16 bytes (4 analog
channels) too early, scrambling channel/sample alignment -- only the first
sample of each 50-sample packet was correct -- and corrupting derived phase
estimates.

Advance offset/length by 48 instead of 32 so all 50 samples align and sample
49 ends exactly at the 1224-byte frame boundary. On-wire framing and the
voltage-first channel order (VA,VB,VC,IA,IB,IC) were already correct.
@clackner-gpa clackner-gpa merged commit aa03c6f into master May 27, 2026
7 checks passed
@clackner-gpa clackner-gpa deleted the SELOffsetError branch May 27, 2026 13:08
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.

2 participants