refactor(proxy): Extract device connection logic to new twinleaf-core crate #6
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.
Motivation
The core change is the introduction of the
twinleaf-core
crate. This is, in the future, meant to expose common workflows as a library API that were already written fortwinleaf-tools
, for future use with Trendline. In particular,tio-proxy
was mixing useful behavior for discovering and identifying Twinleaf serial port devices with functionality in themain.rs
.Although this refactor moves
twinleaf-tools
away from the primary example of how to use thetwinleaf
crate, this also aligns it closer to being purely a developer-focused CLI while leavingtwinleaf-core
as the primary example of interfacing with the devices. In this particular refactor, most of the proxy and interface logic still remains insidetio-proxy.rs
.Future work may be done, as an example, to have the
--auto
flag automatically connect to a sensor if it is the only one connected in a HUB-USB.Changes
enum_devices
and the associated logic for finding sensor URLs fromtio-proxy
totwinleaf_core::workflows::connect
.auto_detect_sensor
function encapsulates the logic of finding a single, valid Twinleaf device.tio-proxy
Refactoring:tio-proxy
binary now depends ontwinleaf-core
.connect::enum_devices
andconnect::auto_detect_sensor
functionsanyhow
(unused),serde
(unused), andthiserror
to support the new core library.Cargo.toml
to reflect these changes.How to Test
Verify that the functionality of tio-proxy remains unchanged.
If a single sensor is connected, run
tio-proxy --auto
and confirm it connects successfully.cargo run --bin tio-proxy -- --auto
If multiple serial ports are available, run
tio-proxy --enum
and confirm it detects all of them.cargo run --bin tio-proxy -- --enum
If a sensor is connected through a hub, run
tio-proxy --auto
and confirm the hub returns the dev name when runningtio-tool rpc dev.name
tio-tool rpc dev.name Reply: "HUB-USB-8TTS" [72, 85, 66, 45, 85, 83, 66, 45, 56, 84, 84, 83]
Then, specify the port number such that the sensor's dev name is returned.
tio-tool rpc dev.name Reply: "VMR" [86, 77, 82]