mirror of
https://github.com/italicsjenga/mppt-modbus.git
synced 2024-12-23 16:51:30 +11:00
add "dry-run" flag
This commit is contained in:
parent
d3702731a3
commit
758fc26846
32
src/main.rs
32
src/main.rs
|
@ -35,6 +35,10 @@ struct Args {
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
get_serial_ports: bool,
|
get_serial_ports: bool,
|
||||||
|
|
||||||
|
/// Preview changes without writing to EEPROM
|
||||||
|
#[clap(long)]
|
||||||
|
dry_run: bool,
|
||||||
|
|
||||||
/// Use fake data - for testing
|
/// Use fake data - for testing
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
fake: bool,
|
fake: bool,
|
||||||
|
@ -121,15 +125,33 @@ fn main() {
|
||||||
match modbus {
|
match modbus {
|
||||||
Some(modbus) => {
|
Some(modbus) => {
|
||||||
let offset = match_offset(&name) as u16;
|
let offset = match_offset(&name) as u16;
|
||||||
println!("Writing {} to offset {}", val, offset);
|
let text = if args.dry_run {
|
||||||
modbus
|
"Dry run - would write"
|
||||||
.write_register(EEPROM_BEGIN as u16 + offset, val)
|
} else {
|
||||||
.expect("could not set va lue");
|
"Writing"
|
||||||
|
};
|
||||||
|
println!(
|
||||||
|
"{} {} ({}) to offset {}",
|
||||||
|
text,
|
||||||
|
val,
|
||||||
|
t.get_scaled_from(val),
|
||||||
|
offset
|
||||||
|
);
|
||||||
|
if !args.dry_run {
|
||||||
|
modbus
|
||||||
|
.write_register(EEPROM_BEGIN as u16 + offset, val)
|
||||||
|
.expect("could not set value");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
println!("No modbus device connected");
|
println!("No modbus device connected");
|
||||||
let offset = match_offset(&name) as u16;
|
let offset = match_offset(&name) as u16;
|
||||||
println!("Would write {} to offset {}", val, offset);
|
println!(
|
||||||
|
"Would write {} ({}) to offset {}",
|
||||||
|
val,
|
||||||
|
t.get_scaled_from(val),
|
||||||
|
offset
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue