mirror of
https://github.com/italicsjenga/mppt-modbus.git
synced 2025-01-09 16:51:47 +11:00
subcommands
This commit is contained in:
parent
e9e3530e09
commit
8b8428cc6c
31
src/main.rs
31
src/main.rs
|
@ -1,6 +1,6 @@
|
||||||
use std::{path::Path, process::Command};
|
use std::{path::Path, process::Command};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::{Parser, Subcommand};
|
||||||
use libmodbus_rs::{Modbus, ModbusClient, ModbusRTU};
|
use libmodbus_rs::{Modbus, ModbusClient, ModbusRTU};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ struct MpptEeprom {
|
||||||
EVa_ref_fixed_pct_init: f32,
|
EVa_ref_fixed_pct_init: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser)]
|
||||||
#[clap(author, about, long_about = None)]
|
#[clap(author, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
/// Serial port to connect to MPPT
|
/// Serial port to connect to MPPT
|
||||||
|
@ -126,6 +126,18 @@ struct Args {
|
||||||
/// list serial ports on this system
|
/// list serial ports on this system
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
get_serial_ports: bool,
|
get_serial_ports: bool,
|
||||||
|
|
||||||
|
#[clap(subcommand)]
|
||||||
|
command: Option<Commands>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
enum Commands {
|
||||||
|
/// Get single EEPROM value
|
||||||
|
Get { name: String },
|
||||||
|
|
||||||
|
/// Set single EEPROM value
|
||||||
|
Set { name: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Info {
|
struct Info {
|
||||||
|
@ -167,7 +179,7 @@ fn main() {
|
||||||
.expect("failed to execute process");
|
.expect("failed to execute process");
|
||||||
let s = match std::str::from_utf8(&output.stdout) {
|
let s = match std::str::from_utf8(&output.stdout) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(e) => panic!("Invalid UTF-8 sequence: {}", e),
|
Err(e) => panic!("Failed reading internal command output: {}", e),
|
||||||
};
|
};
|
||||||
println!("{}", s);
|
println!("{}", s);
|
||||||
return;
|
return;
|
||||||
|
@ -184,6 +196,19 @@ fn main() {
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match args.command {
|
||||||
|
Some(Commands::Get { name }) => {
|
||||||
|
println!("get var {}", name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Some(Commands::Set { name }) => {
|
||||||
|
println!("set var {}", name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
None => (),
|
||||||
|
}
|
||||||
|
|
||||||
println!("Connecting to device on {}", args.serial_port);
|
println!("Connecting to device on {}", args.serial_port);
|
||||||
let mut modbus = Modbus::new_rtu(&args.serial_port, baud, parity, data_bit, stop_bit)
|
let mut modbus = Modbus::new_rtu(&args.serial_port, baud, parity, data_bit, stop_bit)
|
||||||
.expect("Could not create modbus device");
|
.expect("Could not create modbus device");
|
||||||
|
|
Loading…
Reference in a new issue