Merge pull request 'v2.1.0' (#3) from devel into stable
All checks were successful
Basic Cargo Checks / docker-build (push) Successful in 32s
Basic Cargo Checks / docker-check (push) Successful in 2m27s

Reviewed-on: #3
This commit is contained in:
Blizzard Finnegan 2023-06-09 10:08:34 -04:00
commit 7b3e9c8900
6 changed files with 364 additions and 85 deletions

View file

@ -0,0 +1,43 @@
name: Basic Cargo Checks
run-name: ${{ github.actor }} is testing
on: [push]
jobs:
docker-check:
runs-on: docker
steps:
- name: Grab misc. dependencies
run: |
apt update && apt install -y librust-libudev-sys-dev build-essential
- name: Check out repository code
uses: actions/checkout@v3
- name: Grab Rust toolchain
uses: https://github.com/actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: aarch64-unknown-linux-gnu
override: true
- name: Run check
uses: https://github.com/actions-rs/cargo@v1
with:
command: check
docker-build:
runs-on: docker
steps:
- name: Grab misc. dependencies
run: |
apt update && apt install -y librust-libudev-sys-dev build-essential
- name: Check out repository code
uses: actions/checkout@v3
- name: Grab Rust toolchain
uses: https://github.com/actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: aarch64-unknown-linux-gnu
override: true
- name: Run check
uses: https://github.com/actions-rs/cargo@v1
with:
command: build
args: --release

195
Cargo.lock generated
View file

@ -41,6 +41,55 @@ dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is-terminal",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d"
[[package]]
name = "anstyle-parse"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]]
name = "autocfg"
version = "1.1.0"
@ -92,6 +141,48 @@ dependencies = [
"winapi",
]
[[package]]
name = "clap"
version = "4.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "401a4694d2bf92537b6867d94de48c4842089645fdcdf6c71865b175d836e9c2"
dependencies = [
"clap_builder",
"clap_derive",
"once_cell",
]
[[package]]
name = "clap_builder"
version = "4.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72394f3339a76daf211e57d4bcb374410f3965dcc606dd0e03738c7888766980"
dependencies = [
"anstream",
"anstyle",
"bitflags",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8cd2b2a819ad6eec39e8f1d6b53001af1e5469f8c177579cdaeb313115b825f"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.15",
]
[[package]]
name = "clap_lex"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
[[package]]
name = "codespan-reporting"
version = "0.11.1"
@ -102,6 +193,12 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "const_fn"
version = "0.4.9"
@ -175,6 +272,27 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
[[package]]
name = "errno"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a"
dependencies = [
"errno-dragonfly",
"libc",
"windows-sys",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "fern"
version = "0.6.2"
@ -184,6 +302,18 @@ dependencies = [
"log",
]
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermit-abi"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
[[package]]
name = "iana-time-zone"
version = "0.1.56"
@ -208,6 +338,29 @@ dependencies = [
"cxx-build",
]
[[package]]
name = "io-lifetimes"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2"
dependencies = [
"hermit-abi",
"libc",
"windows-sys",
]
[[package]]
name = "is-terminal"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f"
dependencies = [
"hermit-abi",
"io-lifetimes",
"rustix",
"windows-sys",
]
[[package]]
name = "itoa"
version = "1.0.6"
@ -258,6 +411,12 @@ dependencies = [
"cc",
]
[[package]]
name = "linux-raw-sys"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519"
[[package]]
name = "log"
version = "0.4.17"
@ -392,6 +551,20 @@ dependencies = [
"semver",
]
[[package]]
name = "rustix"
version = "0.37.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]]
name = "ryu"
version = "1.0.13"
@ -469,6 +642,7 @@ name = "seymour_poc_rust"
version = "2.0.1"
dependencies = [
"chrono",
"clap",
"derivative",
"fern",
"log",
@ -551,6 +725,12 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.109"
@ -643,6 +823,12 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "version_check"
version = "0.9.4"
@ -749,6 +935,15 @@ dependencies = [
"windows-targets",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.48.0"

View file

@ -16,6 +16,7 @@ chrono = "0.4.24"
once_cell = "1.17.1"
derivative = "2.2.0"
time = "0.2.23"
clap = { version = "4.3.2", features = ["derive"] }
[dev-dependencies]
time = "0.2.23"

2
build_requirements.md Normal file
View file

@ -0,0 +1,2 @@
librust-udev-sys-dev
pkg-config

View file

@ -284,6 +284,9 @@ impl Device{
pub fn get_serial(&mut self) -> &str{
&self.serial
}
pub fn get_location(&mut self) -> String{
std::format!("{:?}",self.usb_tty)
}
pub fn set_pin_address(&mut self, address:u8) -> &mut Self{
self.address = Some(address.clone());
let temp = self.gpio.get(address);

View file

@ -1,8 +1,21 @@
use seymour_poc_rust::{device::Device, tty::{self,TTY,Response},gpio_facade::GpioPins};
use std::{io::{stdin,stdout,Write},thread::{self, JoinHandle},path::Path,fs};
use seymour_poc_rust::{device::Device,
tty::{self,TTY,Response},
gpio_facade::GpioPins};
use std::{io::{stdin,stdout,Write},
thread::{self, JoinHandle},
path::Path,
fs};
use chrono::{DateTime,Local};
use clap::Parser;
const VERSION:&str="2.0.1";
#[derive(Parser,Debug)]
#[command(author,version,about)]
struct Args{
#[arg(short,long,action)]
debug:bool
}
const VERSION:&str="2.1.0";
fn int_input_filtering(prompt:Option<&str>) -> u64{
let internal_prompt = prompt.unwrap_or(">>>");
@ -37,107 +50,129 @@ fn input_filtering(prompt:Option<&str>) -> String{
fn main(){
setup_logs();
let args = Args::parse();
log::info!("Seymour Life Testing version: {}",VERSION);
let gpio = &mut GpioPins::new();
match std::fs::read_dir("/dev/serial/by-path"){
Ok(available_ttys)=>{
let mut possible_devices:Vec<Option<Device>> = Vec::new();
let mut tty_test_threads:Vec<JoinHandle<Option<Device>>> = 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::info!("Testing port {}. This may take a moment...",&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(device) => Some(device),
Err(_) => None
if args.debug{
log::debug!("Debug enabled!");
}
loop{
let gpio = &mut GpioPins::new();
match std::fs::read_dir("/dev/serial/by-path"){
Ok(available_ttys)=>{
let mut possible_devices:Vec<Option<Device>> = Vec::new();
let mut tty_test_threads:Vec<JoinHandle<Option<Device>>> = 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::info!("Testing port {}. This may take a moment...",&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();
Some(device)
},
Err(_) => None
}
}
}
else { None }
},
None=>{None}
else { None }
},
None=>{None}
}
},
Err(error)=>{
log::debug!("{}",error);
None
}
},
Err(error)=>{
//log::warn!("Invalid TTY location");
log::debug!("{}",error);
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 devices:Vec<Device> = Vec::new();
for possible_device in possible_devices.into_iter(){
if let Some(device) = possible_device{
devices.push(device);
}));
}
for thread in tty_test_threads{
let output = thread.join().unwrap_or_else(|x|{log::trace!("{:?}",x); None});
possible_devices.push(output);
}
}
log::info!("Number of devices detected: {}",devices.len());
let mut devices:Vec<Device> = Vec::new();
for possible_device in possible_devices.into_iter(){
if let Some(device) = possible_device{
devices.push(device);
}
}
log::info!("Dimming all screens...");
for device in devices.iter_mut(){
device.darken_screen();
}
log::info!("\n\n--------------------------------------");
log::info!("Number of devices detected: {}",devices.len());
log::info!("--------------------------------------\n\n");
for device in devices.iter_mut(){
device.brighten_screen()
.set_serial(&input_filtering(Some("Enter the serial of the device with the bright screen: ")).to_string())
.darken_screen();
log::debug!("Number of unassigned addresses: {}",gpio.get_unassigned_addresses().len());
for &address in gpio.get_unassigned_addresses(){
device.set_pin_address(address).start_temp();
if device.is_temp_running(){
device.stop_temp();
gpio.remove_address(address);
break;
for device in devices.iter_mut(){
device.brighten_screen();
if args.debug{
let location = device.get_location();
device.set_serial(&location);
}
else{
device.stop_temp();
device.set_serial(&input_filtering(Some("Enter the serial of the device with the bright screen: ")).to_string());
}
device.darken_screen();
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 GPIO for device {}. Please ensure that the probe well is installed properly, and the calibration key is plugged in.",device.get_location());
}
}
}
let mut iteration_count:u64 = 0;
while iteration_count < 1{
iteration_count = int_input_filtering(Some("Enter the number of iterations to complete: "));
}
let mut iteration_count:u64 = 0;
while iteration_count < 1{
iteration_count = int_input_filtering(Some("Enter the number of iterations to complete: "));
}
let mut iteration_threads = Vec::new();
while let Some(mut device) = devices.pop(){
iteration_threads.push(thread::spawn(move||{
for i in 1..=iteration_count{
log::info!("Starting iteration {} of {} for device {}...",
i,iteration_count,device.get_serial());
device.test_cycle(None, None);
}
}));
let mut iteration_threads = Vec::new();
while let Some(mut device) = devices.pop(){
iteration_threads.push(thread::spawn(move||{
for i in 1..=iteration_count{
log::info!("Starting iteration {} of {} for device {}...",
i,iteration_count,device.get_serial());
device.test_cycle(None, None);
}
}));
}
for thread in iteration_threads{
thread.join().unwrap();
}
}
for thread in iteration_threads{
thread.join().unwrap();
Err(_)=>{
log::error!("Invalid serial location! Please make sure that /dev/serial/by-path exists.");
break;
}
}
Err(_)=>{
log::error!("Invalid serial location! Please make sure that /dev/serial/by-path exists.");
if input_filtering(Some("Would you like to run the tests again? (y/N): ")).to_string().contains("y") {}
else { break; }
}
}
fn find_gpio(device:&mut Device,gpio:&mut GpioPins) -> bool{
for &address in gpio.get_unassigned_addresses(){
device.set_pin_address(address).start_temp();
if device.is_temp_running(){
device.stop_temp();
gpio.remove_address(address);
return true;
}
else {
device.stop_temp();
}
}
return false;
}
pub fn setup_logs(){