Skip to content

Add support for LinkPi SmartHUB power port - #1729

Open
Kwiboo wants to merge 1 commit into
labgrid-project:masterfrom
Kwiboo:linkpismarthub
Open

Kwiboo wants to merge 1 commit into
labgrid-project:masterfrom
Kwiboo:linkpismarthub

Conversation

@Kwiboo

@Kwiboo Kwiboo commented Sep 9, 2025

Copy link
Copy Markdown
Contributor

Description
LinkPi SmartHUB is a 12-port USB3.0 HUB utilizing four RTS5411 USB3.0 4-port HUB controllers, a FT232R USB UART IC and a STM32F103RB MCU for port power control. Maximum output power of each USB port is up to 15W.

Add a LinkPiSmartHUBPowerPort resource and a LinkPiSmartHUBPowerDriver with an accompanying linkpismarthub agent to support power on/off the ports of the LinkPi SmartHUB using a simple line-based protocol over a serial port.

Known commands:

  • onoff <port> <1|0> - switch port power on/off
  • state - get current power state of all ports
  • SetOWP <1|0> <1|0> ... - set the power-on state of all ports
  • GetOWP - get the power-on state of all ports

Responses are in JSON format, e.g.:

> onoff 5 1
< {"Cmd":"OnOffResp","SeqNum":1,"ret":0}
> state
< {"Cmd":"StateResp","SeqNum":2,"state":[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]}
> SetOWP 0 0 0 0 0 0 0 0 0 0 0 1
< {"Cmd":"SetOWPResp","SeqNum":3,"ret":0}
> GetOWP
< {"Cmd":"GetOWPResp","SeqNum":4,"owp":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]}

A version announcement is continuously sent every second:

< {"Cmd":"VerResp","ver":"SmartHUB_<ver>","uid":"<uid>"}

Please note that the port name printed on the hub does not match the internal port index used with the commands.

Links

Information on the LinkPi SmartHUB is hard to find, following links mention it:

Checklist

  • Documentation for the feature
  • Tests for the feature
  • The arguments and description in doc/configuration.rst have been updated
  • PR has been tested

@codecov

codecov Bot commented Sep 9, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.92929% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.3%. Comparing base (cfb4813) to head (56f3347).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/remote/client.py 0.0% 3 Missing ⚠️
labgrid/remote/exporter.py 71.4% 2 Missing ⚠️
labgrid/driver/powerdriver.py 97.4% 1 Missing ⚠️
labgrid/resource/udev.py 93.3% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1729     +/-   ##
========================================
+ Coverage    66.1%   66.3%   +0.1%     
========================================
  Files         194     195      +1     
  Lines       16204   16302     +98     
========================================
+ Hits        10726   10816     +90     
- Misses       5478    5486      +8     
Flag Coverage Δ
3.11 66.2% <92.9%> (+0.1%) ⬆️
3.12 66.3% <92.9%> (+0.1%) ⬆️
3.13 66.2% <92.9%> (+0.1%) ⬆️
3.14 66.2% <92.9%> (+0.1%) ⬆️
3.15 66.2% <92.9%> (+0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@Kwiboo
Kwiboo force-pushed the linkpismarthub branch 3 times, most recently from b741e89 to d956ef3 Compare September 13, 2025 11:29
@Kwiboo
Kwiboo force-pushed the linkpismarthub branch 2 times, most recently from 3549390 to b5bc7df Compare October 5, 2025 08:58
@Kwiboo
Kwiboo force-pushed the linkpismarthub branch 2 times, most recently from c782167 to 2f70e4c Compare November 28, 2025 16:17
@Kwiboo
Kwiboo force-pushed the linkpismarthub branch 2 times, most recently from 3953541 to 931b1fd Compare February 6, 2026 17:47
Comment thread labgrid/util/agents/linkpismarthub.py Resolved
@Kwiboo
Kwiboo force-pushed the linkpismarthub branch 2 times, most recently from 7adefe0 to b1bdb6c Compare April 6, 2026 20:47
@Kwiboo

Kwiboo commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

@Emantor was there a reason why you assigned this PR to me? Should I approve my own PR? Was my response to your question not enough? What is missing/needed to get this merged?

@Emantor

Emantor commented Jun 23, 2026

Copy link
Copy Markdown
Member

We still have a simultaneous access problem that is unsolved with the current integration, this needs either better error handling to signal the correct error back to the user or the ability to wait for the previous access to finish.

@Kwiboo

Kwiboo commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

this needs either better error handling to signal the correct error back to the user

@Emantor any suggestion on how such better error handling or signal would look like? (I do not fully understand what is unsolved)

Should current SerialException instead be wrapped in a different exception when there is simultaneous access?

exception=SerialException('device reports readiness to read but returned no data (device disconnected or multiple access on port?)')

Using serial.Serial(..., exclusive=True) triggers a different SerialException when there is simultaneous access:

exception=SerialException(11, 'Could not exclusively lock port /dev/ttyUSB9: [Errno 11] Resource temporarily unavailable')

Would this be a more correct error?

@Kwiboo
Kwiboo force-pushed the linkpismarthub branch 4 times, most recently from d570433 to 5417390 Compare June 27, 2026 20:30
@Kwiboo

Kwiboo commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

We still have a simultaneous access problem that is unsolved with the current integration, this needs either better error handling to signal the correct error back to the user or the ability to wait for the previous access to finish.

This was changed to use serial.Serial(..., exclusive=True), something that triggers a different SerialException when there is simultaneous access:

exception=SerialException(11, 'Could not exclusively lock port /dev/ttyUSB9: [Errno 11] Resource temporarily unavailable')

@Emantor Would this be a more correct error? Or do you have any other suggestions or guidance?

@Emantor

Emantor commented Nov 20, 2026

Copy link
Copy Markdown
Member

We still have a simultaneous access problem that is unsolved with the current integration, this needs either better error handling to signal the correct error back to the user or the ability to wait for the previous access to finish.

This was changed to use serial.Serial(..., exclusive=True), something that triggers a different SerialException when there is simultaneous access:

exception=SerialException(11, 'Could not exclusively lock port /dev/ttyUSB9: [Errno 11] Resource temporarily unavailable')

@Emantor Would this be a more correct error? Or do you have any other suggestions or guidance?

Yeah, that sounds okay. This will need a rebase for the conflicts (probably trivial).

LinkPi SmartHUB is a 12-port USB3.0 HUB utilizing four RTS5411 USB3.0
4-port HUB controllers, a FT232R USB UART IC and a STM32F103RB MCU for
port power control.

Add a LinkPiSmartHUBPowerPort resource and a LinkPiSmartHUBPowerDriver
with an accompanying linkpismarthub agent to support power on/off the
ports of the LinkPi SmartHUB using a simple line-based protocol over a
serial port.

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants