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-corecrate. 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-proxywas mixing useful behavior for discovering and identifying Twinleaf serial port devices with functionality in themain.rs.Although this refactor moves
twinleaf-toolsaway from the primary example of how to use thetwinleafcrate, this also aligns it closer to being purely a developer-focused CLI while leavingtwinleaf-coreas 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
--autoflag automatically connect to a sensor if it is the only one connected in a HUB-USB.Changes
enum_devicesand the associated logic for finding sensor URLs fromtio-proxytotwinleaf_core::workflows::connect.auto_detect_sensorfunction encapsulates the logic of finding a single, valid Twinleaf device.tio-proxyRefactoring:tio-proxybinary now depends ontwinleaf-core.connect::enum_devicesandconnect::auto_detect_sensorfunctionsanyhow(unused),serde(unused), andthiserrorto support the new core library.Cargo.tomlto reflect these changes.How to Test
Verify that the functionality of tio-proxy remains unchanged.
If a single sensor is connected, run
tio-proxy --autoand confirm it connects successfully.cargo run --bin tio-proxy -- --autoIf multiple serial ports are available, run
tio-proxy --enumand confirm it detects all of them.cargo run --bin tio-proxy -- --enumIf a sensor is connected through a hub, run
tio-proxy --autoand confirm the hub returns the dev name when runningtio-tool rpc dev.nametio-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]