Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/wireless-programmer/src/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ fn parse_reach_mode(mode: &str) -> wp_client::ReachMode {
match mode {
"lan" => wp_client::ReachMode::Lan,
"usb" => wp_client::ReachMode::Usb,
"z21" => wp_client::ReachMode::Z21,
_ => wp_client::ReachMode::Ap,
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/wireless-programmer/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ pub struct CommonArgs {
pub struct ScanArgs {
#[command(flatten)]
pub common: ClientCommon,
/// `ap` (Soft-AP radio, default), `lan` (mDNS `_longfred-ota._tcp`), or `usb`.
#[arg(long, default_value = "ap", value_parser = ["ap", "lan", "usb"])]
/// `ap` (Soft-AP radio, default), `lan` (mDNS `_longfred-ota._tcp`), `usb`, or `z21`.
#[arg(long, default_value = "ap", value_parser = ["ap", "lan", "usb", "z21"])]
pub mode: String,
}

Expand Down Expand Up @@ -152,7 +152,7 @@ pub struct ProbeArgs {
pub struct ProgramArgs {
#[command(flatten)]
pub common: ClientCommon,
/// Driver identifier.
/// Driver identifier (e.g. `wifred`, `longfred`, `fred`).
#[arg(long)]
pub driver: String,
/// Candidate key.
Expand Down
27 changes: 22 additions & 5 deletions crates/wireless-programmer/src/cli/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,27 @@ fn build_request(args: &ProgramArgs) -> Result<ProgramRequestWire, CliError> {
None => Vec::new(),
};

let wifi = WifiCredentialsWire {
ssid: required(args.wifi_ssid.clone(), "--wifi-ssid")?,
psk: wifi_psk(args)?,
let wifi = if args.driver == "fred" {
WifiCredentialsWire {
ssid: args.wifi_ssid.clone().unwrap_or_default(),
psk: wifi_psk(args).ok().flatten(),
}
} else {
WifiCredentialsWire {
ssid: required(args.wifi_ssid.clone(), "--wifi-ssid")?,
psk: wifi_psk(args)?,
}
};

// With mDNS discovery the device finds the host itself, so a fixed host
// and port stop being mandatory.
let server = if args.server_automatic {
let server = if args.driver == "fred" {
ThrottleServerWire {
host: args.server_host.clone().unwrap_or_default(),
port: args.server_port.unwrap_or(0),
automatic: None,
}
} else if args.server_automatic {
ThrottleServerWire {
host: args.server_host.clone().unwrap_or_default(),
port: args.server_port.unwrap_or(DEFAULT_WITHROTTLE_PORT),
Expand All @@ -69,7 +82,11 @@ fn build_request(args: &ProgramArgs) -> Result<ProgramRequestWire, CliError> {
};

Ok(ProgramRequestWire {
identity: required(args.identity.clone(), "--identity")?,
identity: if args.driver == "fred" {
args.identity.clone().unwrap_or_default()
} else {
required(args.identity.clone(), "--identity")?
},
wifi,
server,
roster,
Expand Down
28 changes: 26 additions & 2 deletions crates/wireless-programmer/src/drivers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ use wp_core::{
CommissioningNet, DeviceCandidate, DeviceDriver, DriverCapabilities, DriverError, Observation,
Outcome, ProgramRequest, ProgressSink, Transport,
};
use wp_drivers::{LongFredDriver, WiFredDriver};
use wp_drivers::{FredDriver, LongFredDriver, WiFredDriver};

/// All registered drivers.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Driver {
/// NewHeiko WiFred.
WiFred,
/// LongFred Soft-AP programming.
LongFred,
/// Digitrax FRED via Z21 LAN LocoNet dispatch.
Fred,
}

impl Driver {
Expand All @@ -26,6 +28,7 @@ impl Driver {
match self {
Driver::WiFred => "wifred",
Driver::LongFred => "longfred",
Driver::Fred => "fred",
}
}

Expand All @@ -34,6 +37,7 @@ impl Driver {
match self {
Driver::WiFred => "NewHeiko WiFred",
Driver::LongFred => "LongFred",
Driver::Fred => "Digitrax FRED",
}
}

Expand All @@ -47,6 +51,12 @@ impl Driver {
prefix: 24,
},
Driver::LongFred => wp_drivers::longfred::commissioning_net(),
Driver::Fred => CommissioningNet {
host: Ipv4Addr::UNSPECIFIED,
port: 0,
source: Ipv4Addr::UNSPECIFIED,
prefix: 0,
},
}
}

Expand All @@ -55,6 +65,7 @@ impl Driver {
match id {
"wifred" => Some(Driver::WiFred),
"longfred" => Some(Driver::LongFred),
"fred" => Some(Driver::Fred),
_ => None,
}
}
Expand All @@ -65,6 +76,7 @@ impl Driver {
pub struct DriverRegistry {
wifred: WiFredDriver,
longfred: LongFredDriver,
fred: FredDriver,
}

impl DriverRegistry {
Expand All @@ -73,6 +85,7 @@ impl DriverRegistry {
Self {
wifred: WiFredDriver::new(),
longfred: LongFredDriver::new(),
fred: FredDriver::new(),
}
}

Expand All @@ -81,6 +94,7 @@ impl DriverRegistry {
vec![
(Driver::WiFred, self.wifred.capabilities()),
(Driver::LongFred, self.longfred.capabilities()),
(Driver::Fred, self.fred.capabilities()),
]
}

Expand Down Expand Up @@ -117,6 +131,7 @@ impl DriverRegistry {
match driver {
Driver::WiFred => self.wifred.validate(req),
Driver::LongFred => self.longfred.validate(req),
Driver::Fred => self.fred.validate(req),
}
}

Expand All @@ -129,6 +144,7 @@ impl DriverRegistry {
match driver {
Driver::WiFred => self.wifred.probe(transport).await,
Driver::LongFred => self.longfred.probe(transport).await,
Driver::Fred => self.fred.probe(transport).await,
}
}

Expand All @@ -143,6 +159,7 @@ impl DriverRegistry {
match driver {
Driver::WiFred => self.wifred.program(transport, req, progress).await,
Driver::LongFred => self.longfred.program(transport, req, progress).await,
Driver::Fred => self.fred.program(transport, req, progress).await,
}
}

Expand All @@ -151,6 +168,7 @@ impl DriverRegistry {
match driver {
Driver::WiFred => self.wifred.capabilities().supports_firmware_update,
Driver::LongFred => self.longfred.capabilities().supports_firmware_update,
Driver::Fred => false,
}
}

Expand All @@ -171,6 +189,9 @@ impl DriverRegistry {
.update_firmware(transport, image, progress)
.await
}
Driver::Fred => Err(DriverError::Other(
"firmware update is not supported".into(),
)),
}
}

Expand Down Expand Up @@ -199,6 +220,9 @@ impl DriverRegistry {
Driver::LongFred => Err(DriverError::Other(
"LongFred has no LED identify in programming mode".into(),
)),
Driver::Fred => Err(DriverError::Other(
"FRED has no LED identify over Z21 LAN".into(),
)),
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/wireless-programmer/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ impl ServerInner {
let scanned = match mode {
wp_proto::ReachMode::Lan => self.runtime.scan_lan(),
wp_proto::ReachMode::Usb => self.runtime.scan_usb(),
wp_proto::ReachMode::Z21 => self.runtime.scan_z21(),
wp_proto::ReachMode::Ap => self.runtime.scan(),
};
match scanned {
Expand Down
Loading
Loading