Skip to content

add ethernet setup scripts#40

Merged
lindestad merged 2 commits into
mainfrom
add-k2-ethernet-scripts
May 6, 2026
Merged

add ethernet setup scripts#40
lindestad merged 2 commits into
mainfrom
add-k2-ethernet-scripts

Conversation

@lindestad
Copy link
Copy Markdown
Collaborator

Adds the K2 direct-link Ethernet setup scripts to Topside so operators can configure the MCU Ethernet adapter from the app repo.

Changes:

  • copy the Fedora/Linux NetworkManager helper from K2-Zephyr as tools/k2-ethernet.sh
  • copy the Windows Administrator PowerShell helper as tools/k2-ethernet.ps1
  • document the helper commands in the README and setup guide
  • keep the manual Windows static-IP steps as a fallback

The 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 at 10.77.0.2 without failing setup if the ping does not respond.

Validated:

  • bash -n tools/k2-ethernet.sh
  • PowerShell parser check for tools/k2-ethernet.ps1
  • git diff --check
  • uv run --frozen --group dev pytest (6 passed)

This branch is based on main and intentionally does not include the separate MCU port docs branch.

@lindestad lindestad marked this pull request as ready for review April 30, 2026 18:47
@lindestad lindestad requested review from Gutteerz and Copilot April 30, 2026 18:47
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.sh to configure a NetworkManager Ethernet profile for 10.77.0.1/24 and optionally validate connectivity via ping.
  • Added tools/k2-ethernet.ps1 to configure a Windows Ethernet adapter for 10.77.0.1/24 and optionally validate connectivity via ping.
  • Updated docs/SETUP.md and README.md with 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.

Comment thread tools/k2-ethernet.sh
Comment on lines +179 to +188
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
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/SETUP.md
Comment on lines +52 to +57
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
```
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tools/k2-ethernet.ps1
Comment on lines +106 to +114
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)."
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lindestad lindestad merged commit 29f162d into main May 6, 2026
1 check passed
@lindestad lindestad deleted the add-k2-ethernet-scripts branch May 6, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants