From f7b9da508626e66bc929e5b5e8bb55265e1dc733 Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Fri, 23 Jun 2023 14:27:05 -0400 Subject: [PATCH 01/14] add "from secrets" denotation --- .woodpecker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.woodpecker.yml b/.woodpecker.yml index d1e0c67..62ea18d 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -14,6 +14,7 @@ pipeline: checksum: - "target/aarch64-unknown-linux-musl/release/seymour_life" api_key: ${FORGEJO_API_KEY} + secrets: [ FORGEJO_API_KEY ] target: ${CI_COMMIT_TAG} draft: true prerelease: true -- 2.45.3 From d4b47c109fb24c171d3f9cb8b8db3c9708fece66 Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Fri, 23 Jun 2023 14:32:45 -0400 Subject: [PATCH 02/14] secrets take 2 --- .woodpecker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 62ea18d..4ad25b2 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -14,7 +14,7 @@ pipeline: checksum: - "target/aarch64-unknown-linux-musl/release/seymour_life" api_key: ${FORGEJO_API_KEY} - secrets: [ FORGEJO_API_KEY ] + secrets: [ forgejo_api_key ] target: ${CI_COMMIT_TAG} draft: true prerelease: true -- 2.45.3 From 41e1f8eda30dd7cf6f22f50208101d5d58e1bae2 Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Fri, 23 Jun 2023 14:47:48 -0400 Subject: [PATCH 03/14] third time's the charm? --- .woodpecker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 4ad25b2..db6fac1 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -13,8 +13,8 @@ pipeline: - "target/aarch64-unknown-linux-musl/release/seymour_life" checksum: - "target/aarch64-unknown-linux-musl/release/seymour_life" - api_key: ${FORGEJO_API_KEY} - secrets: [ forgejo_api_key ] + api_key: ${FORGEJO_API} + secrets: [ forgejo_api ] target: ${CI_COMMIT_TAG} draft: true prerelease: true -- 2.45.3 From 5d42a34f1636094ad1b33e722316f1104700c97e Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Fri, 23 Jun 2023 14:52:54 -0400 Subject: [PATCH 04/14] once again, I am asking for your api key --- .woodpecker.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index db6fac1..58a5d5a 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -14,7 +14,9 @@ pipeline: checksum: - "target/aarch64-unknown-linux-musl/release/seymour_life" api_key: ${FORGEJO_API} - secrets: [ forgejo_api ] + secrets: + - source: forgejo_api + target: FORGEJO_API target: ${CI_COMMIT_TAG} draft: true prerelease: true -- 2.45.3 From 108132ef9e8b3cf8bafc320d74a29a23b4463066 Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Fri, 23 Jun 2023 15:01:41 -0400 Subject: [PATCH 05/14] Comment out releases for now Clearly, I don't really know what's going on here. So rather than further pollute the public repo, I'm going to set up another repo to play with. --- .woodpecker.yml | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 58a5d5a..6d21a7a 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -3,21 +3,21 @@ pipeline: image: nixos/nix:latest commands: - nix-shell --run 'cargo build --release --target aarch64-unknown-linux-musl' - publish: - when: - event: tag - image: woodpeckerci/plugin-gitea-release - settings: - base_url: https://git.blizzard.systems - files: - - "target/aarch64-unknown-linux-musl/release/seymour_life" - checksum: - - "target/aarch64-unknown-linux-musl/release/seymour_life" - api_key: ${FORGEJO_API} - secrets: - - source: forgejo_api - target: FORGEJO_API - target: ${CI_COMMIT_TAG} - draft: true - prerelease: true - title: .woodpecker/title.txt + # publish: + # when: + # event: tag + # image: woodpeckerci/plugin-gitea-release + # settings: + # base_url: https://git.blizzard.systems + # files: + # - "target/aarch64-unknown-linux-musl/release/seymour_life" + # checksum: + # - "target/aarch64-unknown-linux-musl/release/seymour_life" + # api_key: ${FORGEJO_API} + # secrets: + # - source: forgejo_api + # target: FORGEJO_API + # target: ${CI_COMMIT_TAG} + # draft: true + # prerelease: true + # title: .woodpecker/title.txt -- 2.45.3 From c403dfa7c1ccaec5f7b93fdfb39e719fa0c4cda6 Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 26 Jun 2023 11:04:01 -0400 Subject: [PATCH 06/14] Attempt to reduce init time To be tested --- src/device.rs | 32 ++++++++++++++++---------------- src/tty.rs | 14 ++++++++------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/device.rs b/src/device.rs index 975f4f8..c44860b 100755 --- a/src/device.rs +++ b/src/device.rs @@ -16,7 +16,8 @@ pub enum State{ LoginPrompt, DebugMenu, LifecycleMenu, - BrightnessMenu + BrightnessMenu, + ShellPrompt } #[derive(Debug)] @@ -112,6 +113,10 @@ impl Device{ usb_port.write_to_device(Command::Newline); _ = usb_port.read_from_device(None); initial_state = State::LoginPrompt; + }, + Response::UBoot=>{ + log::error!("A device was interrupted during the boot process! Please ensure all devices are completely booted and on the main screen, then restart this program."); + return Err("Failed TTY init. Device in u-boot state, must be manually rebooted.".to_string()); }, //Response::Empty parsing here is potentially in bad faith Response::Other | Response::Empty | Response::ShellPrompt | Response::FailedDebugMenu | Response::DebugInit | @@ -126,9 +131,7 @@ impl Device{ initial_state = State::LoginPrompt; }, Response::ShellPrompt => { - usb_port.write_to_device(Command::Shutdown); - while usb_port.read_from_device(None) != Response::LoginPrompt {} - initial_state = State::LoginPrompt; + initial_state = State::ShellPrompt; }, _ => { log::error!("Unknown state for TTY {:?}!!! Consult logs immediately.",usb_port); @@ -199,13 +202,15 @@ impl Device{ Response::ShellPrompt => break, _ => { log::error!("Unexpected response from device {}!",self.serial); - log::debug!("brightness menu, catch-all, first loop, {}, {:?}",self.serial,self.usb_tty); + log::debug!("brightness menu, catch-all, login loop, {}, {:?}",self.serial,self.usb_tty); log::error!("Unsure how to continue. Expect data from device {} to be erratic until next cycle.",self.serial); //break; }, }; }; - //_ = self.usb_tty.read_from_device(None); + self.current_state = State::ShellPrompt; + }, + State::ShellPrompt => { self.usb_tty.write_to_device(Command::DebugMenu); loop { match self.usb_tty.read_from_device(None) { @@ -219,14 +224,11 @@ impl Device{ Response::DebugMenu => break, Response::FailedDebugMenu => { - while self.usb_tty.read_from_device(None) != Response::LoginPrompt {}; - self.usb_tty.write_to_device(Command::Login); - while self.usb_tty.read_from_device(None) != Response::ShellPrompt {}; self.usb_tty.write_to_device(Command::DebugMenu); }, _ => { log::error!("Unexpected response from device {}!", self.serial); - log::debug!("brightness menu, catch-all, second loop, {}, {:?}",self.serial,self.usb_tty); + log::debug!("brightness menu, catch-all, shell prompt loop, {}, {:?}",self.serial,self.usb_tty); log::error!("Unsure how to continue. Expect data from device {} to be erratic until next cycle.",self.serial); //break; }, @@ -276,6 +278,9 @@ impl Device{ }, }; }; + self.current_state = State::ShellPrompt; + }, + State::ShellPrompt => { self.usb_tty.write_to_device(Command::DebugMenu); loop { let read_in = self.usb_tty.read_from_device(None); @@ -283,16 +288,11 @@ impl Device{ Response::PreShellPrompt | Response::Empty | Response::ShuttingDown | Response::DebugInit | Response::EmptyNewline | Response::Rebooting => {}, Response::LoginPrompt => { - self.usb_tty.write_to_device(Command::Login); - while self.usb_tty.read_from_device(None) != Response::ShellPrompt {}; self.usb_tty.write_to_device(Command::DebugMenu); }, Response::DebugMenu => break, Response::FailedDebugMenu => { - while self.usb_tty.read_from_device(None) != Response::LoginPrompt {}; - self.usb_tty.write_to_device(Command::Login); - while self.usb_tty.read_from_device(None) != Response::ShellPrompt {}; self.usb_tty.write_to_device(Command::DebugMenu); }, _ => { @@ -381,7 +381,6 @@ impl Device{ self.usb_tty.write_to_device(Command::DebugMenu); while self.usb_tty.read_from_device(None) != Response::DebugMenu {} self.current_state = State::DebugMenu; - self.reboot(); self.load_values(); self.save_values(); return true @@ -529,6 +528,7 @@ impl Device{ } pub fn reboot(&mut self) -> () { self.usb_tty.write_to_device(Command::Quit); + self.usb_tty.write_to_device(Command::Reboot); let mut successful_reboot:bool = false; //let mut exited_menu:bool = false; loop{ diff --git a/src/tty.rs b/src/tty.rs index c1e8afe..414d5a8 100755 --- a/src/tty.rs +++ b/src/tty.rs @@ -26,7 +26,7 @@ pub enum Command{ Login, DebugMenu, Newline, - Shutdown, + Reboot, GetSerial, } @@ -49,6 +49,7 @@ pub enum Response{ EmptyNewline, DebugInit, Serial(Option), + UBoot, } @@ -64,26 +65,27 @@ const COMMAND_MAP:Lazy> = Lazy::new(||HashMap::from([ (Command::UpMenuLevel, "\\"), (Command::Login,"root\n"), (Command::RedrawMenu,"?"), - (Command::DebugMenu," python3 -m debugmenu; shutdown -r now\n"), + (Command::DebugMenu,"python3 -m debugmenu\n"), (Command::Newline,"\n"), - (Command::Shutdown,"shutdown -r now\n"), + (Command::Reboot,"shutdown -r now\n"), (Command::GetSerial,"echo 'y1q' | python3 -m debugmenu\n"), ])); -const RESPONSES:[(&str,Response);13] = [ +const RESPONSES:[(&str,Response);14] = [ + ("uboot=>",Response::UBoot), ("Last login:",Response::PreShellPrompt), ("reboot: Restarting",Response::Rebooting), ("command not found",Response::FailedDebugMenu), ("login:",Response::LoginPrompt), ("Password:",Response::PasswordPrompt), ("DtCtrlCfgDeviceSerialNum",Response::Serial(None)), + (">",Response::DebugMenu), + ("Loading App-Framework",Response::DebugInit), ("root@",Response::ShellPrompt), ("EXIT Debug menu",Response::ShuttingDown), ("Check NIBP In Progress: True",Response::BPOn), ("Check NIBP In Progress: False",Response::BPOff), ("SureTemp Probe Pulls:",Response::TempCount(None)), - (">",Response::DebugMenu), - ("Loading App-Framework",Response::DebugInit), ]; pub struct TTY{ -- 2.45.3 From a59a3c590d3ee5bd1025955056b6f23b440deff0 Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 26 Jun 2023 11:12:40 -0400 Subject: [PATCH 07/14] Catch first major error go_to_* functions fell to catch-all for bad debug command response; should treat as shell --- src/device.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/device.rs b/src/device.rs index c44860b..9745eea 100755 --- a/src/device.rs +++ b/src/device.rs @@ -199,7 +199,7 @@ impl Device{ Response::PreShellPrompt | Response::Empty | Response::ShuttingDown | Response::DebugInit | Response::EmptyNewline | Response::Rebooting => {}, Response::PasswordPrompt => {self.usb_tty.write_to_device(Command::Newline);}, - Response::ShellPrompt => break, + Response::FailedDebugMenu | Response::ShellPrompt => break, _ => { log::error!("Unexpected response from device {}!",self.serial); log::debug!("brightness menu, catch-all, login loop, {}, {:?}",self.serial,self.usb_tty); @@ -269,7 +269,7 @@ impl Device{ Response::PreShellPrompt | Response::Empty | Response::ShuttingDown | Response::DebugInit | Response::EmptyNewline | Response::Rebooting => {}, Response::PasswordPrompt => {self.usb_tty.write_to_device(Command::Newline);}, - Response::ShellPrompt => break, + Response::FailedDebugMenu | Response::ShellPrompt => break, _ => { log::error!("Unexpected response from device {}!",self.serial); log::debug!("lifecycle menu, catch-all, first loop, {}, {:?}",self.serial,self.usb_tty); -- 2.45.3 From 1300e040d78690d02c697610353f9507409d258e Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 26 Jun 2023 11:29:47 -0400 Subject: [PATCH 08/14] Remove reboot from auto_serial We have a whole state machine here. Might as well use it. --- src/device.rs | 70 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/src/device.rs b/src/device.rs index 9745eea..2ff90f3 100755 --- a/src/device.rs +++ b/src/device.rs @@ -353,38 +353,56 @@ impl Device{ return true } pub fn auto_set_serial(&mut self) -> bool{ - self.reboot(); - self.usb_tty.write_to_device(Command::Login); - while self.usb_tty.read_from_device(None) != Response::ShellPrompt {} - self.usb_tty.write_to_device(Command::GetSerial); - loop{ - let return_value = self.usb_tty.read_from_device(None); - match return_value{ - Response::Serial(Some(contains_serial)) =>{ - for line in contains_serial.split("\n").collect::>(){ - if !line.contains(':') { continue; } - let (section,value) = line.split_once(':').unwrap(); - if section.contains(SERIAL_HEADER){ - self.serial = value.trim().replace("\"",""); + loop { + match self.current_state { + State::LoginPrompt => { + self.usb_tty.write_to_device(Command::Login); + while self.usb_tty.read_from_device(None) != Response::ShellPrompt {}; + self.current_state = State::ShellPrompt; + }, + State::Shutdown => { + while self.usb_tty.read_from_device(None) != Response::LoginPrompt{}; + self.current_state = State::LoginPrompt; + }, + State::DebugMenu | State::LifecycleMenu | State::BrightnessMenu => { + self.usb_tty.write_to_device(Command::Quit); + _ = self.usb_tty.read_from_device(None); + self.current_state = State::ShellPrompt; + }, + State::ShellPrompt => { + self.usb_tty.write_to_device(Command::GetSerial); + loop{ + let return_value = self.usb_tty.read_from_device(None); + match return_value{ + Response::Serial(Some(contains_serial)) =>{ + for line in contains_serial.split("\n").collect::>(){ + if !line.contains(':') { continue; } + let (section,value) = line.split_once(':').unwrap(); + if section.contains(SERIAL_HEADER){ + self.serial = value.trim().replace("\"",""); + } + } + log::info!("Serial found for device {}",self.serial); + break; + }, + Response::DebugInit | Response::Empty | Response::EmptyNewline => { continue; } + _ => { + log::error!("Bad value: {:?}",return_value); + return false + }, } } - log::info!("Serial found for device {}",self.serial); - break; - }, - Response::DebugInit | Response::Empty | Response::EmptyNewline => { continue; } - _ => { - log::error!("Bad value: {:?}",return_value); - return false + self.usb_tty.write_to_device(Command::DebugMenu); + while self.usb_tty.read_from_device(None) != Response::DebugMenu {} + self.current_state = State::DebugMenu; + self.load_values(); + self.save_values(); + return true }, } } - self.usb_tty.write_to_device(Command::DebugMenu); - while self.usb_tty.read_from_device(None) != Response::DebugMenu {} - self.current_state = State::DebugMenu; - self.load_values(); - self.save_values(); - return true } + pub fn manual_set_serial(&mut self, serial:&str) -> &mut Self{ self.serial = serial.to_string(); self.load_values(); -- 2.45.3 From e92b0522b82b05fd8d262bee77ef89bf87f0962e Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 26 Jun 2023 11:44:58 -0400 Subject: [PATCH 09/14] Increase complexity of read tree --- src/device.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/device.rs b/src/device.rs index 2ff90f3..9357d91 100755 --- a/src/device.rs +++ b/src/device.rs @@ -133,14 +133,32 @@ impl Device{ Response::ShellPrompt => { initial_state = State::ShellPrompt; }, + Response::DebugMenu => { + usb_port.write_to_device(Command::Newline); + match usb_port.read_from_device(None) { + Response::DebugMenu | Response::ShellPrompt => { + initial_state = State::ShellPrompt; + }, + _ => { + log::error!("Unknown state for TTY {:?}!!! Consult logs immediately.",usb_port); + log::debug!("Last known state: DebugMenu."); + log::debug!("Assumed but incorrect current state: successfully exited debug menu"); + return Err("Failed TTY init. Unknown state, cannot trust.".to_string()); + } + }; + }, _ => { log::error!("Unknown state for TTY {:?}!!! Consult logs immediately.",usb_port); + log::debug!("Last known state: DebugMenu."); + log::debug!("Assumed but incorrect current state: attempted to exit debug menu"); return Err("Failed TTY init. Unknown state, cannot trust.".to_string()); } }; }, + //Serial response shouldn't exist, emptynewline is already filtered in main Response::Serial(_) | Response::EmptyNewline => { log::error!("Unknown state for TTY {:?}!!! Consult logs immediately.",usb_port); + log::debug!("How did I get here???"); return Err("Failed TTY init. Unknown state, cannot trust.".to_string()); }, }; -- 2.45.3 From 0a0f502410b1af31c67ac3fa8f67ba4b0294360b Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 26 Jun 2023 11:48:54 -0400 Subject: [PATCH 10/14] Adjust priority so temp checks don't fail --- src/tty.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tty.rs b/src/tty.rs index 414d5a8..a4297b6 100755 --- a/src/tty.rs +++ b/src/tty.rs @@ -79,13 +79,13 @@ const RESPONSES:[(&str,Response);14] = [ ("login:",Response::LoginPrompt), ("Password:",Response::PasswordPrompt), ("DtCtrlCfgDeviceSerialNum",Response::Serial(None)), + ("Check NIBP In Progress: True",Response::BPOn), + ("Check NIBP In Progress: False",Response::BPOff), + ("SureTemp Probe Pulls:",Response::TempCount(None)), (">",Response::DebugMenu), ("Loading App-Framework",Response::DebugInit), ("root@",Response::ShellPrompt), ("EXIT Debug menu",Response::ShuttingDown), - ("Check NIBP In Progress: True",Response::BPOn), - ("Check NIBP In Progress: False",Response::BPOff), - ("SureTemp Probe Pulls:",Response::TempCount(None)), ]; pub struct TTY{ -- 2.45.3 From c6c34462bbf549810c97d6694f92f0f809daa37e Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Mon, 26 Jun 2023 13:00:16 -0400 Subject: [PATCH 11/14] Attempt to resolve #10 --- src/tty.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/tty.rs b/src/tty.rs index a4297b6..87076d5 100755 --- a/src/tty.rs +++ b/src/tty.rs @@ -71,6 +71,12 @@ const COMMAND_MAP:Lazy> = Lazy::new(||HashMap::from([ (Command::GetSerial,"echo 'y1q' | python3 -m debugmenu\n"), ])); +const COMMAND_RESPONSES: [&str;3] = [ + "python3 -m debugmenu", + "q", + "root", +]; + const RESPONSES:[(&str,Response);14] = [ ("uboot=>",Response::UBoot), ("Last login:",Response::PreShellPrompt), @@ -143,7 +149,12 @@ impl TTY{ let read_line:String = String::from_utf8_lossy(read_buffer.as_slice()).to_string(); if read_line.eq("\r\n") { return Response::EmptyNewline; - } + } + for command in COMMAND_RESPONSES{ + if read_line.trim().eq(command.trim()){ + return self.read_from_device(None); + } + }; for (string,enum_value) in RESPONSES{ if read_line.contains(string){ if(enum_value == Response::BPOn) || (enum_value == Response::BPOff) { -- 2.45.3 From 32789a4546e9121e27ade9b4aed2a98f281002ba Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Tue, 27 Jun 2023 09:00:06 -0400 Subject: [PATCH 12/14] Add catch for uboot Apparently, you can just run "boot" in a uboot prompt to get to the login prompt. --- src/device.rs | 5 +++-- src/tty.rs | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/device.rs b/src/device.rs index 9357d91..0f48f61 100755 --- a/src/device.rs +++ b/src/device.rs @@ -115,8 +115,9 @@ impl Device{ initial_state = State::LoginPrompt; }, Response::UBoot=>{ - log::error!("A device was interrupted during the boot process! Please ensure all devices are completely booted and on the main screen, then restart this program."); - return Err("Failed TTY init. Device in u-boot state, must be manually rebooted.".to_string()); + usb_port.write_to_device(Command::Boot); + while usb_port.read_from_device(None) != Response::LoginPrompt {} + initial_state = State::LoginPrompt; }, //Response::Empty parsing here is potentially in bad faith Response::Other | Response::Empty | Response::ShellPrompt | Response::FailedDebugMenu | Response::DebugInit | diff --git a/src/tty.rs b/src/tty.rs index 87076d5..876532b 100755 --- a/src/tty.rs +++ b/src/tty.rs @@ -28,6 +28,7 @@ pub enum Command{ Newline, Reboot, GetSerial, + Boot, } #[derive(Clone,Eq,Derivative,Debug)] @@ -68,6 +69,7 @@ const COMMAND_MAP:Lazy> = Lazy::new(||HashMap::from([ (Command::DebugMenu,"python3 -m debugmenu\n"), (Command::Newline,"\n"), (Command::Reboot,"shutdown -r now\n"), + (Command::Boot,"boot\n"), (Command::GetSerial,"echo 'y1q' | python3 -m debugmenu\n"), ])); -- 2.45.3 From b27da2155e97a42933fc0767b444125823eafbda Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Thu, 29 Jun 2023 09:58:20 -0400 Subject: [PATCH 13/14] Attempt to generalise serial init --- Cargo.lock | 7 ++ Cargo.toml | 1 + src/main.rs | 212 +++++++++++++++++++++++++++++----------------------- 3 files changed, 126 insertions(+), 94 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f61b6a0..45ef427 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -302,6 +302,12 @@ dependencies = [ "log", ] +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "heck" version = "0.4.1" @@ -618,6 +624,7 @@ dependencies = [ "clap", "derivative", "fern", + "glob", "log", "once_cell", "rppal", diff --git a/Cargo.toml b/Cargo.toml index 81c36cf..b54fcb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ once_cell = "1.17.1" derivative = "2.2.0" time = "0.2.23" clap = { version = "4.3.2", features = ["derive"] } +glob = "0.3.1" [dev-dependencies] time = "0.2.23" diff --git a/src/main.rs b/src/main.rs index c307afc..61b49c1 100755 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,7 @@ fn input_filtering(prompt:Option<&str>) -> String{ log::debug!("{}:{}",internal_prompt,user_input); return user_input; } - +//Path::new(&&str).is_dir() -> bool fn main(){ let args = Args::parse(); setup_logs(&args.debug); @@ -80,106 +80,130 @@ fn main(){ log::info!("Testing all available USB ports for connected devices. This may take several minutes, and devices may reboot several times."); let gpio = &mut GpioPins::new(); - match std::fs::read_dir("/dev/serial/by-path"){ - Ok(available_ttys)=>{ - let mut possible_devices:Vec> = Vec::new(); - let mut tty_test_threads:Vec>> = Vec::new(); - for possible_tty in available_ttys.into_iter(){ - tty_test_threads.push( - thread::spawn(move ||{ - let tty_ref = possible_tty.as_ref(); - match tty_ref{ - Ok(tty_real_ref)=>{ - let tty_path = tty_real_ref.path(); - let tty_name = tty_path.to_string_lossy(); - log::debug!("Testing port {}",&tty_name); - let possible_port = TTY::new(&tty_name); - match possible_port{ - Some(mut port) =>{ - port.write_to_device(tty::Command::Newline); - let response = port.read_from_device(Some(":")); - if response != Response::Empty{ - log::debug!("{} is valid port!",tty_name); - let new_device = Device::new(port,Some(response)); - match new_device{ - Ok(mut device) => { - device.darken_screen(); - if !args.manual { - device.auto_set_serial(); - } - Some(device) - }, - Err(_) => None - } - } - else { None } - }, - None=>{None} - } - }, - Err(error)=>{ - log::debug!("{}",error); - None + let mut available_ttys:Vec> = Vec::new(); + for entry in glob::glob("/dev/serial/*").expect("Failed to read glob pattern"){ + match entry{ + Ok(real_path) =>{ + match fs::read_dir::<&Path>(real_path.as_ref()){ + Ok(possible_ttys) =>{ + possible_ttys.into_iter().for_each(|tty| { + if let Ok(single_tty) = tty { + available_ttys.push(single_tty.path().into()); + } + }); + break; + } + Err(error) =>{ + log::error!("Invalid permissions to /dev directory... did you run with sudo?"); + log::error!("{}",error); + return; + } + } + } + Err(error) =>{ + log::error!("{}",error); + } + } + } + if available_ttys.is_empty(){ + for entry in glob::glob("/dev/ttyUSB*").expect("Unable to read glob"){ + match entry{ + Ok(possible_tty) => available_ttys.push(Path::new(&possible_tty).into()), + Err(error) => { + log::error!("Invalid permissions to /dev directory... did you run with sudo?"); + log::error!("{}",error); + return; + } + }; + } + } + + if available_ttys.is_empty(){ + log::error!("No serial devices detected! Please ensure all connections."); + return; + } + let mut possible_devices:Vec> = Vec::new(); + let mut tty_test_threads:Vec>> = Vec::new(); + for possible_tty in available_ttys.into_iter(){ + tty_test_threads.push( + thread::spawn(move ||{ + let tty_name = possible_tty.to_string_lossy(); + log::debug!("Testing port {}",&tty_name); + let possible_port = TTY::new(&tty_name); + match possible_port{ + Some(mut port) =>{ + port.write_to_device(tty::Command::Newline); + let response = port.read_from_device(Some(":")); + if response != Response::Empty{ + log::debug!("{} is valid port!",tty_name); + let new_device = Device::new(port,Some(response)); + match new_device{ + Ok(mut device) => { + device.darken_screen(); + if !args.manual { + device.auto_set_serial(); + } + Some(device) + }, + Err(_) => None } } - })); - } - for thread in tty_test_threads{ - let output = thread.join().unwrap_or_else(|x|{log::trace!("{:?}",x); None}); - possible_devices.push(output); - } - - let mut serials_set:bool = true; - let mut devices:Vec = Vec::new(); - for possible_device in possible_devices.into_iter(){ - if let Some(device) = possible_device{ - if device.get_serial().eq("uninitialised"){ - serials_set = false; - } - devices.push(device); + else { None } + }, + None=>{None} } - } + })); + } + for thread in tty_test_threads{ + let output = thread.join().unwrap_or_else(|x|{log::trace!("{:?}",x); None}); + possible_devices.push(output); + } - log::info!("--------------------------------------"); - log::info!("Number of devices detected: {}",devices.len()); - log::info!("--------------------------------------\n\n"); - - log::info!("Setting up probe wells for all devices. This may take several minutes..."); - for device in devices.iter_mut(){ - if !serials_set || args.manual { - device.brighten_screen(); - device.manual_set_serial(&input_filtering(Some("Enter the serial of the device with the bright screen: ")).to_string()); - device.darken_screen(); - } - log::info!("Checking probe well of device {}",device.get_serial()); - log::debug!("Number of unassigned addresses: {}",gpio.get_unassigned_addresses().len()); - if !find_gpio(device, gpio){ - device.set_pin_address(21); - log::error!("Unable to find probe-well for device {}. Please ensure that the probe well is installed properly, and the calibration key is plugged in.",device.get_serial()); - device.brighten_screen(); - panic!(); - } - } - - let mut iteration_threads = Vec::new(); - while let Some(mut device) = devices.pop(){ - iteration_threads.push(thread::spawn(move||{ - device.init_temp_count(); - for i in 1..=iteration_count{ - log::info!("Starting iteration {} of {} for device {}...", - i,iteration_count,device.get_serial()); - device.test_cycle(None); - } - })); - } - for thread in iteration_threads{ - thread.join().unwrap(); + let mut serials_set:bool = true; + let mut devices:Vec = Vec::new(); + for possible_device in possible_devices.into_iter(){ + if let Some(device) = possible_device{ + if device.get_serial().eq("uninitialised"){ + serials_set = false; } + devices.push(device); } - Err(_)=>{ - log::error!("Invalid serial location! Please make sure that /dev/serial/by-path exists."); - break; + } + + log::info!("--------------------------------------"); + log::info!("Number of devices detected: {}",devices.len()); + log::info!("--------------------------------------\n\n"); + + log::info!("Setting up probe wells for all devices. This may take several minutes..."); + for device in devices.iter_mut(){ + if !serials_set || args.manual { + device.brighten_screen(); + device.manual_set_serial(&input_filtering(Some("Enter the serial of the device with the bright screen: ")).to_string()); + device.darken_screen(); } + log::info!("Checking probe well of device {}",device.get_serial()); + log::debug!("Number of unassigned addresses: {}",gpio.get_unassigned_addresses().len()); + if !find_gpio(device, gpio){ + device.set_pin_address(21); + log::error!("Unable to find probe-well for device {}. Please ensure that the probe well is installed properly, and the calibration key is plugged in.",device.get_serial()); + device.brighten_screen(); + panic!(); + } + } + + let mut iteration_threads = Vec::new(); + while let Some(mut device) = devices.pop(){ + iteration_threads.push(thread::spawn(move||{ + device.init_temp_count(); + for i in 1..=iteration_count{ + log::info!("Starting iteration {} of {} for device {}...", + i,iteration_count,device.get_serial()); + device.test_cycle(None); + } + })); + } + for thread in iteration_threads{ + thread.join().unwrap(); } if input_filtering(Some("Would you like to run the tests again? (y/N): ")).to_string().contains("y") {} else { break; } -- 2.45.3 From 04e79dca2b525ecc7316b140e2ab91a5c7e0ed10 Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Thu, 29 Jun 2023 10:04:47 -0400 Subject: [PATCH 14/14] Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 45ef427..b91d292 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -618,7 +618,7 @@ dependencies = [ [[package]] name = "seymour_life" -version = "2.3.2" +version = "2.3.3" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index b54fcb6..02a5089 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "seymour_life" -version = "2.3.2" +version = "2.3.3" edition = "2021" #This feature is currently limited to nightly versions of cargo. #forced-target="aarch64-unknown-linux-musl" diff --git a/src/main.rs b/src/main.rs index 61b49c1..2b5522a 100755 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ struct Args{ } -const VERSION:&str="2.3.2"; +const VERSION:&str="2.3.3"; const DEBUG_ITERATION_COUNT:u64=50000; fn int_input_filtering(prompt:Option<&str>) -> u64{ -- 2.45.3