Skip to content

Commit

Permalink
Removed find_serial_comports option
Browse files Browse the repository at this point in the history
  • Loading branch information
thatzok committed Jun 2, 2024
1 parent 00ad552 commit d17a43c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 68 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ serde = { version = "1.0", features = ["derive"] }
reqwest = { version = "0.11", features = ["json","blocking"] }
serialport = "4.3.0"
structopt = "0.3"
configparser = "3.0.4"
16 changes: 2 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use structopt::StructOpt;

use crate::api::getapidata;
use crate::opts::Opts;
use crate::serial::find_serial_comports;
use crate::serial::show_serial_comports;
use crate::vehicle::compare_vehicle_states;
use crate::vehicle::get_vehicle_state;
Expand All @@ -34,16 +33,6 @@ fn main() {
return;
}

if opts.find.is_some() {
// let port_name_result = find_serial_comports(&opts);

if let Ok(bla) = find_serial_comports(&opts) {
port_name = bla;
} else {
print!("Keinen COMport mit dem Text gefunden.");
return;
}
}

if opts.port.is_some() {
port_name = <std::option::Option<std::string::String> as Clone>::clone(&opts.port).unwrap();
Expand All @@ -55,7 +44,7 @@ fn main() {
}

if opts.clear {
println!("Sende Nullwerte an Comport");
println!("send empty vehicle data to comport");

let empty_vehicle = init_vehicle_state();
let vec = compare_vehicle_states(&empty_vehicle, &empty_vehicle, &opts, true);
Expand Down Expand Up @@ -90,8 +79,7 @@ fn main() {

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


let verbose = opts.verbose;

let mut vehicle_state = init_vehicle_state();
Expand Down
20 changes: 8 additions & 12 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ use structopt::StructOpt;

#[derive(StructOpt, Debug)]
pub struct Opts {
/// comport für Kommandos an das Armaturenbrett
/// comport Arduino/ESP32 ist connected to
#[structopt(short, long)]
pub port: Option<String>,

/// Find port with name
#[structopt(short, long)]
pub find: Option<String>,

/// IP des PC auf dem TheBus läuft
#[structopt(short, long, default_value = "127.0.0.1")]
pub ip: String,
Expand All @@ -22,31 +18,31 @@ pub struct Opts {
#[structopt(short, long, default_value = "200")]
pub sleeptime: u64,

/// debugging einschalten
/// enable debugging
#[structopt(short, long)]
pub debug: bool,

/// debugging serial einschalten
/// enable debugging of serial comport
#[structopt(long)]
pub debug_serial: bool,

/// debugging command einschalten
/// enable debugging of commands
#[structopt(long)]
pub debug_command: bool,

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

/// Alle verfügbaren comports anzeigen
/// show all available comports
#[structopt(short, long)]
pub list: bool,

/// Ausführliche Ausgabe einschalten
/// enable verbose output
#[structopt(short, long)]
pub verbose: bool,

/// Alle Werte zurücksetzen
/// reset all vehicle values
#[structopt(short, long)]
pub clear: bool,
}
42 changes: 0 additions & 42 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,45 +44,3 @@ pub fn show_serial_comports() {
}
}

pub fn find_serial_comports(opts: &Opts) -> Result<String, &str> {
// println!("Suche ...");

match available_ports() {
Ok(ports) => {
for p in ports {
// print!(" {}", p.port_name);
match p.port_type {
SerialPortType::UsbPort(info) => {
let zeile = format!(
"{} {} {}",
p.port_name,
info.manufacturer.as_ref().map_or("", String::as_str),
info.product.as_ref().map_or("", String::as_str)
);

// println!("{:?}", zeile);
let aa = zeile.as_str().to_lowercase();
let a = aa.as_str();
let bb = opts.find.as_ref().unwrap().as_str().to_lowercase();
let b = bb.as_str();

let pp = p.port_name.to_string();

if a.contains(b) {
// println!("GEFUNDEN");
return Ok(pp);
}
}
SerialPortType::BluetoothPort => {}
SerialPortType::PciPort => {}
SerialPortType::Unknown => {}
}
}
}
Err(e) => {
eprintln!("{:?}", e);
eprintln!("Error listing serial ports");
}
}
Err("Nicht gefunden.")
}

0 comments on commit d17a43c

Please sign in to comment.