add ethernet setup scripts#40
Conversation
There was a problem hiding this comment.
Pull request overview
Adds operator-facing helper scripts (Linux/NetworkManager + Windows/PowerShell) to configure a direct-link Ethernet setup for communicating with the MCU from the Topside repo, and documents how to use them.
Changes:
- Added
tools/k2-ethernet.shto configure a NetworkManager Ethernet profile for10.77.0.1/24and optionally validate connectivity via ping. - Added
tools/k2-ethernet.ps1to configure a Windows Ethernet adapter for10.77.0.1/24and optionally validate connectivity via ping. - Updated
docs/SETUP.mdandREADME.mdwith automated setup instructions (keeping manual Windows static IP steps as fallback).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tools/k2-ethernet.sh | New Bash helper to select an Ethernet interface and configure a NetworkManager connection for the MCU direct link. |
| tools/k2-ethernet.ps1 | New PowerShell helper to select an Ethernet adapter and set a static IPv4 address for the MCU direct link. |
| docs/SETUP.md | Documents the automated scripts and retains manual Windows static-IP steps. |
| README.md | Adds quick-start commands for running the new Ethernet helper scripts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| down() { | ||
| local iface="$1" | ||
| local conn="${CON_PREFIX}-${iface}" | ||
|
|
||
| if nmcli -t -f NAME connection show | grep -Fxq "$conn"; then | ||
| run_nmcli connection down "$conn" || true | ||
| echo "Disconnected ${conn}." | ||
| else | ||
| echo "No ${conn} connection exists." | ||
| fi |
There was a problem hiding this comment.
The down action only brings the NetworkManager connection down; it does not remove/delete the k2-direct-<iface> connection or revert any settings. Either rename the action to reflect that it only disconnects, or update down() to delete the connection (or add a separate delete/reset action) so the CLI behavior matches user expectations.
There was a problem hiding this comment.
Good catch on the exact semantics. I agree this is technically accurate, but for this operator helper I think keeping a reusable non-autoconnect NetworkManager profile is the more useful behavior. down disconnects that profile rather than deleting it, and I do not think adding delete/recreate behavior improves the field workflow here.
| Both scripts show a menu of Ethernet adapters and mark the most likely USB Ethernet adapter as recommended. Use `status` to inspect the current setup and `down` to remove the direct-link configuration: | ||
|
|
||
| ```bash | ||
| ./tools/k2-ethernet.sh status | ||
| ./tools/k2-ethernet.sh down | ||
| ``` |
There was a problem hiding this comment.
The docs say down will “remove the direct-link configuration”, but on Linux the script’s down action only disconnects the NetworkManager connection and leaves the k2-direct-<iface> connection definition behind. Clarify the docs to match current behavior (disconnect vs delete), or adjust the script/commands so down actually removes the configuration.
There was a problem hiding this comment.
Agreed that the wording can be read more strictly than intended. I am leaving this as-is for now because the behavior is intentional: down is the quick operator path for disconnecting the reusable helper profile, not a destructive cleanup/reset operation. If we later want a full cleanup path, I would add an explicit delete or reset action instead of changing down.
| function Clear-K2Link { | ||
| if (-not (Test-IsAdmin)) { | ||
| throw "Run this script from an Administrator PowerShell session." | ||
| } | ||
|
|
||
| $adapter = Select-K2Adapter | ||
| Remove-K2Address $adapter | ||
| Set-NetIPInterface -InterfaceIndex $adapter.ifIndex -AddressFamily IPv4 -Dhcp Enabled | Out-Null | ||
| Write-Host "Removed $HostIp from $($adapter.Name)." |
There was a problem hiding this comment.
Clear-K2Link always enables DHCP on the selected adapter. If the adapter was previously configured with a static IPv4 address (or DHCP was intentionally disabled), running down will not just remove the K2 address but will also change the adapter’s prior configuration. Consider capturing the adapter’s current DHCP setting before making changes (and restoring it on down), or only toggling DHCP when the script can determine it previously disabled it.
There was a problem hiding this comment.
Fixed in 740a412. The Windows script now saves the selected adapter DHCP state before up, restores DHCP only when that saved state was enabled, and leaves DHCP/static configuration unchanged if there is no matching saved state.
Adds the K2 direct-link Ethernet setup scripts to Topside so operators can configure the MCU Ethernet adapter from the app repo.
Changes:
tools/k2-ethernet.shtools/k2-ethernet.ps1The scripts select an Ethernet adapter from a menu, recommend the likely USB Ethernet adapter, configure the PC as
10.77.0.1/24, and try to ping the MCU at10.77.0.2without failing setup if the ping does not respond.Validated:
bash -n tools/k2-ethernet.shtools/k2-ethernet.ps1git diff --checkuv run --frozen --group dev pytest(6 passed)This branch is based on
mainand intentionally does not include the separate MCU port docs branch.