Skip to content

Commit

Permalink
removed disable-serial option
Browse files Browse the repository at this point in the history
  • Loading branch information
thatzok committed Jun 2, 2024
1 parent d17a43c commit 61b48e1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 64 deletions.
61 changes: 1 addition & 60 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() {
port_name = <std::option::Option<std::string::String> as Clone>::clone(&opts.port).unwrap();
}

if !opts.disable_serial && (port_name.len() < 1) {
if (port_name.len() < 1) {
println!("Kein COMport angegeben.");
return;
}
Expand All @@ -52,7 +52,6 @@ fn main() {
println!("SENDING -> {:?}", vec);
}

if !opts.disable_serial {
let baud_rate = opts.baud;

let mut port = serialport::new(&port_name, baud_rate)
Expand All @@ -64,71 +63,13 @@ fn main() {
}

let _ = port.write(&vec);
}

return;
}

// default, wenn keine anderen Optionen ausgewählt,
if opts.disable_serial {
real_main_no_serial(&opts)
} else {
real_main(port_name, &opts);
}
}

fn real_main_no_serial(opts: &Opts) {
let debug = opts.debug;

let verbose = opts.verbose;

let mut vehicle_state = init_vehicle_state();

let mut api_state = -1;

let interval = Duration::from_millis(opts.sleeptime);
let mut next_time = Instant::now() + interval;

loop {
let api_bus_result = getapidata(&opts);

if api_bus_result.is_err() {
// eprintln!("getapidata error: {}", api_bus_result.unwrap_err());
if api_state != 0 {
if verbose {
println!("Bitte einsteigen und hinsetzen.");
}
api_state = 0;
}
} else {
let api_bus = api_bus_result.unwrap();
// println!("{:?}", api_bus);
if api_state != 1 {
if verbose {
println!("Hingesetzt. Jetzt gehts los!");
}
api_state = 1;
}

let newstate = get_vehicle_state(api_bus);
if debug {
print_vehicle_state(&newstate);
}

// compare and create cmd buf
let cmdbuf = compare_vehicle_states(&vehicle_state, &newstate, &opts, false);

// replace after compare for next round
vehicle_state = newstate;

if opts.debug_serial && (cmdbuf.len() > 0) {
println!("SENDING -> {:?}", cmdbuf);
}
}

sleep(next_time - Instant::now());
next_time += interval;
}
}

fn real_main(port_name: String, opts: &Opts) {
Expand Down
4 changes: 0 additions & 4 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ pub struct Opts {
#[structopt(long)]
pub debug_command: bool,

/// disable and ignore serial port, nothing is written to serial comport
#[structopt(long)]
pub disable_serial: bool,

/// show all available comports
#[structopt(short, long)]
pub list: bool,
Expand Down

0 comments on commit 61b48e1

Please sign in to comment.