Type serial_port, source, and sensor_model fields with existing enums - #74
Type serial_port, source, and sensor_model fields with existing enums#74andrewfo wants to merge 3 commits into
Conversation
|
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. |
5dabd7d to
4ce3036
Compare
|
@andrewfo I just recently merged some changes that may simplify your PR a little. Recommend rebasing. |
|
That didn't have as much effect as I expected. |
| #[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) })] |
There was a problem hiding this comment.
This needs a util function now
There was a problem hiding this comment.
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
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>
decbccf to
280ed9c
Compare
joe-saronic
left a comment
There was a problem hiding this comment.
LGTM. Kinda surprised that type inference worked inside the map = annotations.
Summary
Replaces raw
u8fields with the strongly-typed enums that already exist in the crate but were never applied to these structs.ImuSetup.serial_port→ConnectionPort(resolves the// TODO: create SerialPort enum— the existingConnectionPortalready models exactly these port values, so no new enum is needed).ExtSensorStatus,ExtSensorInfo,ExtSensorMeasSet:source→ConnectionPort,sensor_model→ExtSensorModel. Both enums were defined inext_sensor_status.rsfor precisely these fields.Each field uses binrw
#[br(map = ...)]/#[bw(map = ...)]for theu8⇄ enum conversion, so wire format is unchanged.Notes
test-files/correct_sbf_output.logis updated to reflect the enumDebugoutput (source: InternalSpi,sensor_model: Adis1650x) instead of raw32/10.Testing
cargo test— all tests pass.