Skip to content

Commit 3067164

Browse files
committed
CLI command for program download
1 parent 8bfd124 commit 3067164

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/argparse.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::path::PathBuf;
2+
13
use crate::Result;
24
use clap::{command, Parser, Subcommand};
35

@@ -41,6 +43,13 @@ pub enum RcxMode {
4143
Ping,
4244
#[command(about = "Report ROM and FW versions")]
4345
Version,
46+
#[command(about = "Download a program to the specified slot")]
47+
Program {
48+
#[clap(help = "Program slot (0-9)")]
49+
slot: u8,
50+
#[clap(help = "Program file")]
51+
file: PathBuf,
52+
},
4453
}
4554

4655
pub fn parse_args() -> Result<Args> {

src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ async fn main() -> Result<()> {
2020
argparse::BrickType::Rcx { mode } => match mode {
2121
RcxMode::Ping => rcx::ping(),
2222
RcxMode::Version => rcx::version(),
23+
RcxMode::Program { slot, file } => rcx::program(slot, file),
2324
},
2425
}
2526
}

src/rcx.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::Result;
2+
use color_eyre::eyre::eyre;
23
use rcx::{tower::usb::UsbTower, Rcx};
4+
use std::path::PathBuf;
35

6+
const MAX_PROGRAM_SLOT: u8 = 9;
47
const DEVICE: &str = "/dev/usb/legousbtower0";
58

69
pub fn ping() -> Result<()> {
@@ -18,3 +21,10 @@ pub fn version() -> Result<()> {
1821
println!("RCX versions: {versions}");
1922
Ok(())
2023
}
24+
25+
pub fn program(slot: u8, _file: PathBuf) -> Result<()> {
26+
if slot > MAX_PROGRAM_SLOT {
27+
return Err(eyre!("Program slot must be 0-9"));
28+
}
29+
todo!()
30+
}

0 commit comments

Comments
 (0)