Skip to content

Type serial_port, source, and sensor_model fields with existing enums - #74

Open
andrewfo wants to merge 3 commits into
saronic-technologies:masterfrom
andrewfo:type-sensor-enum-fields
Open

Type serial_port, source, and sensor_model fields with existing enums#74
andrewfo wants to merge 3 commits into
saronic-technologies:masterfrom
andrewfo:type-sensor-enum-fields

Conversation

@andrewfo

Copy link
Copy Markdown
Contributor

Summary

Replaces raw u8 fields with the strongly-typed enums that already exist in the crate but were never applied to these structs.

  • ImuSetup.serial_portConnectionPort (resolves the // TODO: create SerialPort enum — the existing ConnectionPort already models exactly these port values, so no new enum is needed).
  • ExtSensorStatus, ExtSensorInfo, ExtSensorMeasSet: sourceConnectionPort, sensor_modelExtSensorModel. Both enums were defined in ext_sensor_status.rs for precisely these fields.

Each field uses binrw #[br(map = ...)] / #[bw(map = ...)] for the u8 ⇄ enum conversion, so wire format is unchanged.

Notes

  • The parser snapshot test-files/correct_sbf_output.log is updated to reflect the enum Debug output (source: InternalSpi, sensor_model: Adis1650x) instead of raw 32 / 10.
  • No public wire-format or behavior change; only the parsed Rust types are richer.

Testing

cargo test — all tests pass.

@therishidesai

Copy link
Copy Markdown
Collaborator

Thanks for the contribution. I was wondering why the output log file changed in this PR. May need to rebase against main

@andrewfo

Copy link
Copy Markdown
Contributor Author

Thanks for the contribution. I was wondering why the output log file changed in this PR. May need to rebase against main

yeah the log diff is expected - that file's just the Debug dump of the parsed messages, so once those fields become enums instead of u8, every line that prints them changes (source: 32 → source: InternalSpi, sensor_model: 10 → sensor_model: Adis1650x). it's only because ExtSensorMeas shows up that many times - straight 1:1 text swap, no values or ordering moved, wire format untouched.

the branch is a bit behind master so I'll rebase, won't change the log diff though, that enum output is the same either way.

@andrewfo
andrewfo force-pushed the type-sensor-enum-fields branch from 5dabd7d to 4ce3036 Compare July 27, 2026 16:15
@joe-saronic

Copy link
Copy Markdown
Contributor

@andrewfo I just recently merged some changes that may simplify your PR a little. Recommend rebasing.

joe-saronic
joe-saronic previously approved these changes Jul 27, 2026
@joe-saronic

Copy link
Copy Markdown
Contributor

That didn't have as much effect as I expected.

Comment thread src/messages/imu_setup.rs Outdated
#[br(map = |x: u8| ConnectionPort::from(x))]
#[bw(map = |x: &ConnectionPort| u8::from(*x))]
pub serial_port: ConnectionPort,
#[br(map = |x| if x == crate::DO_NOT_USE_F4 { None } else { Some(x) })]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs a util function now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

rebased on master and moved the enum mapping into binrw_util (map_enum/unmap_enum), swapped all the inline closures for it. also made ExtSensorModel use the num_enum derives like ConnectionPort so the manual From impl is gone. tests pass, ci green

@joe-saronic
joe-saronic dismissed their stale review July 28, 2026 21:06

Base changed

andrewfo and others added 3 commits July 31, 2026 11:11
Replaces the raw u8 with the existing ConnectionPort enum via binrw
read/write maps, resolving the TODO.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…Port and ExtSensorModel

Replaces raw u8 fields in ExtSensorStatus, ExtSensorInfo, and ExtSensorMeasSet
with the existing enums via binrw read/write maps. Updates snapshot accordingly.
Replaces the inline From/Into closures on ConnectionPort and
ExtSensorModel fields with shared map_enum/unmap_enum helpers, and
derives num_enum FromPrimitive/IntoPrimitive on ExtSensorModel instead
of the hand-written From<u8> impl.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@andrewfo
andrewfo force-pushed the type-sensor-enum-fields branch from decbccf to 280ed9c Compare July 31, 2026 16:15

@joe-saronic joe-saronic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Kinda surprised that type inference worked inside the map = annotations.

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.

3 participants