Skip to content

Conversation

events555
Copy link
Contributor

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 for twinleaf-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 the main.rs.

Although this refactor moves twinleaf-tools away from the primary example of how to use the twinleaf crate, this also aligns it closer to being purely a developer-focused CLI while leaving twinleaf-core as the primary example of interfacing with the devices. In this particular refactor, most of the proxy and interface logic still remains inside tio-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

  • New twinleaf-core Crate:
    • Added a new library crate twinleaf-core to the workspace.
    • Its purpose is to provide APIs for high-level "workflows" (connect, rpc, log, etc.).
    • Created the first workflow module: twinleaf_core::workflows::connect.
  • Device Connection Workflow:
    • Moved enum_devices and the associated logic for finding sensor URLs from tio-proxy to twinleaf_core::workflows::connect.
    • The new auto_detect_sensor function encapsulates the logic of finding a single, valid Twinleaf device.
    • Introduced a ConnectError enum for structured error reporting (e.g., MultipleSensorsFound, AutoDetectionFailed).
  • tio-proxy Refactoring:
    • The tio-proxy binary now depends on twinleaf-core.
    • It uses the new connect::enum_devices and connect::auto_detect_sensor functions
  • Dependencies:
    • Added anyhow (unused), serde (unused), and thiserror to support the new core library.
    • Updated the workspace 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 running tio-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]

@events555 events555 requested a review from tkornack June 13, 2025 20:32
@events555 events555 added the enhancement New feature or request label Jun 13, 2025
@events555 events555 marked this pull request as draft July 24, 2025 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant