Skip to content

Commit

Permalink
Change ip for last two octets (#83)
Browse files Browse the repository at this point in the history
Co-authored-by: Gijs de Jong <[email protected]>
Co-authored-by: Gijs de Jong <[email protected]>
Co-authored-by: Mark Honkoop <[email protected]>
  • Loading branch information
4 people authored Jul 5, 2023
1 parent e4e77aa commit b77bae1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/nao/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,19 @@ impl Nao {
String::from_utf8(output.stdout).wrap_err("failed to decode UTF-8")
}

pub async fn set_last_ip_octets(&self, first_octet: u8, second_octet: u8) -> Result<()> {
self.ssh_to_nao()
.arg("sudo")
.arg("sh")
.arg("~/configure_network")
.arg(first_octet.to_string())
.arg(second_octet.to_string())
.spawn()
.wrap_err("failed to execute configure_network ssh command")?;

Ok(())
}

pub async fn set_network(&self, network: Network) -> Result<()> {
let command_string = [
Network::SplA,
Expand All @@ -312,6 +325,7 @@ impl Nao {
Network::SplD,
Network::SplE,
Network::SplF,
Network::Dnt5G,
]
.into_iter()
.map(|possible_network| {
Expand Down
39 changes: 39 additions & 0 deletions tools/pepsi/src/change_ip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use clap::Args;
use color_eyre::Result;

use nao::Nao;

use crate::parsers::NaoAddress;

#[derive(Args)]
pub struct Arguments {
/// The NAO to update the IP address e.g. 10.0.8.42
#[arg(required = true)]
pub nao: NaoAddress,

/// The third octet of the new ip address for the robot.
pub first_octet: u8,

/// The last octet of the new ip address for the robot.
pub second_octet: u8,
}

pub async fn change_ip(arguments: Arguments) -> Result<()> {
let nao = Nao::new(arguments.nao.ip);

let result = nao
.set_last_ip_octets(arguments.first_octet, arguments.second_octet)
.await;

if result.is_ok() {
println!(
"The new IP address is: {}.{}.{}.{}",
arguments.nao.ip.octets()[0],
arguments.nao.ip.octets()[1],
arguments.first_octet,
arguments.second_octet
);
}

result
}
7 changes: 7 additions & 0 deletions tools/pepsi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use color_eyre::{config::HookBuilder, eyre::WrapErr, Result};
use crate::aliveness::{aliveness, Arguments as AlivenessArguments};
use analyze::{analyze, Arguments as AnalyzeArguments};
use cargo::{cargo, Arguments as CargoArguments, Command as CargoCommand};
use change_ip::{change_ip, Arguments as ChangeIpArguments};
use communication::{communication, Arguments as CommunicationArguments};
use completions::{completions, Arguments as CompletionArguments};
use gammaray::{gammaray, Arguments as GammarayArguments};
Expand All @@ -26,6 +27,7 @@ use wireless::{wireless, Arguments as WirelessArguments};
mod aliveness;
mod analyze;
mod cargo;
mod change_ip;
mod communication;
mod completions;
mod gammaray;
Expand Down Expand Up @@ -58,6 +60,9 @@ async fn main() -> Result<()> {
let repository = repository_root.map(Repository::new);

match arguments.command {
Command::ChangeIp(arguments) => change_ip(arguments)
.await
.wrap_err("failed to execute change_ip command")?,
Command::Analyze(arguments) => analyze(arguments, &repository?)
.await
.wrap_err("failed to execute analyze command")?,
Expand Down Expand Up @@ -138,6 +143,8 @@ struct Arguments {

#[derive(Subcommand)]
enum Command {
/// Change ip address of NAOs
ChangeIp(ChangeIpArguments),
/// Analyze source code
#[clap(subcommand)]
Analyze(AnalyzeArguments),
Expand Down

0 comments on commit b77bae1

Please sign in to comment.