Fix SEL CWS data-frame sample misalignment (samples 1-49 read 16 bytes early)#540
Merged
Conversation
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
approved these changes
May 27, 2026
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.
Summary
FrameParser.ParseFrameadvanced 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.
[VC(prev), IA(prev), IB(prev), IC(prev), VA(cur), VB(cur)]mislabeled as[VA,VB,VC,IA,IB,IC]; only thefirst sample per packet was correct, corrupting analog values and phase
estimates.
offset/lengthby 48 (header 16 + timestamp 8 + first sample24) so all 50 samples align; sample 49 now ends exactly at the 1224-byte
frame boundary.
Root cause
base.ParseFrametakesoffsetby value and leaves the caller's offset at theframe start, so the manual loop must skip the entire initial frame (48 bytes),
not just its body (32). The bare
32literal 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.