Skip to content

Commit

Permalink
Add pepsi wireless scan (#1413)
Browse files Browse the repository at this point in the history
* Add pepsi wireless scan

* Do not perform wireless scan when using --prepare

---------

Co-authored-by: Julian Schuler <[email protected]>
  • Loading branch information
julianschuler and julianschuler authored Jul 21, 2024
1 parent 076bfa6 commit 5a5a818
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions crates/nao/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,24 @@ impl Nao {
String::from_utf8(output.stdout).wrap_err("failed to decode UTF-8")
}

pub async fn scan_networks(&self) -> Result<()> {
let output = self
.ssh_to_nao()
.arg("iwctl")
.arg("station")
.arg("wlan0")
.arg("scan")
.output()
.await
.wrap_err("failed to execute iwctl ssh command")?;

if !output.status.success() {
bail!("iwctl ssh command exited with {}", output.status);
}

Ok(())
}

pub async fn set_network(&self, network: Network) -> Result<()> {
let command_string = [
Network::SplA,
Expand Down
2 changes: 1 addition & 1 deletion tools/pepsi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pepsi"
version = "3.15.0"
version = "3.16.0"
edition.workspace = true
license.workspace = true
homepage.workspace = true
Expand Down
4 changes: 4 additions & 0 deletions tools/pepsi/src/pre_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ pub async fn pre_game(arguments: Arguments, repository: &Repository) -> Result<(
.wrap_err("failed to set player numbers")?;

if !arguments.prepare {
wireless(WirelessArguments::Scan { naos: naos.clone() })
.await
.wrap_err("failed to scan for networks")?;

wireless(WirelessArguments::Set {
network: arguments.network,
naos: naos.clone(),
Expand Down
21 changes: 21 additions & 0 deletions tools/pepsi/src/wireless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ pub enum Arguments {
#[arg(required = true)]
naos: Vec<NaoAddress>,
},
/// Scan for networks
Scan {
/// The NAOs to execute that command on e.g. 20w or 10.1.24.22
#[arg(required = true)]
naos: Vec<NaoAddress>,
},
/// Set active network
Set {
/// The network to connect the wireless device to (None disconnects from anything)
Expand All @@ -40,6 +46,7 @@ pub enum Arguments {
pub async fn wireless(arguments: Arguments) -> Result<()> {
match arguments {
Arguments::Status { naos } => status(naos).await,
Arguments::Scan { naos } => scan(naos).await,
Arguments::List { naos } => available_networks(naos).await,
Arguments::Set { network, naos } => set(naos, network).await,
};
Expand All @@ -61,6 +68,20 @@ async fn status(naos: Vec<NaoAddress>) {
.await;
}

async fn scan(naos: Vec<NaoAddress>) {
ProgressIndicator::map_tasks(
naos,
"Starting network scan...",
|nao_address, _progress_bar| async move {
let nao = Nao::try_new_with_ping(nao_address.ip).await?;
nao.scan_networks()
.await
.wrap_err_with(|| format!("failed to scan for networks on {nao_address}"))
},
)
.await;
}

async fn available_networks(naos: Vec<NaoAddress>) {
ProgressIndicator::map_tasks(
naos,
Expand Down

0 comments on commit 5a5a818

Please sign in to comment.