diff options
| author | Rasmus Melchior Jacobsen <[email protected]> | 2023-04-27 10:48:38 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-05-01 22:42:36 +0200 |
| commit | fc268df6f56661d5f43450c7a03850044ae8e136 (patch) | |
| tree | b48b4543442552b46aceba5bd7f930997d67cd57 /tests/utils/src | |
| parent | 4ea6662e55f32ff90b564c1c611f5ac4e0d8ab1c (diff) | |
Support overflow detection for more than one ring-period
Diffstat (limited to 'tests/utils/src')
| -rw-r--r-- | tests/utils/src/bin/saturate_serial.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/tests/utils/src/bin/saturate_serial.rs b/tests/utils/src/bin/saturate_serial.rs index 28480516d..18ca12fb7 100644 --- a/tests/utils/src/bin/saturate_serial.rs +++ b/tests/utils/src/bin/saturate_serial.rs | |||
| @@ -1,18 +1,19 @@ | |||
| 1 | use std::path::Path; | 1 | use std::path::Path; |
| 2 | use std::time::Duration; | 2 | use std::time::Duration; |
| 3 | use std::{env, io, thread}; | 3 | use std::{env, io, process, thread}; |
| 4 | 4 | ||
| 5 | use rand::random; | 5 | use rand::random; |
| 6 | use serial::SerialPort; | 6 | use serial::SerialPort; |
| 7 | 7 | ||
| 8 | pub fn main() { | 8 | pub fn main() { |
| 9 | if let Some(port_name) = env::args().nth(1) { | 9 | if let Some(port_name) = env::args().nth(1) { |
| 10 | let sleep = env::args().position(|x| x == "--sleep").is_some(); | 10 | let idles = env::args().position(|x| x == "--idles").is_some(); |
| 11 | 11 | ||
| 12 | println!("Saturating port {:?} with 115200 8N1", port_name); | 12 | println!("Saturating port {:?} with 115200 8N1", port_name); |
| 13 | println!("Sleep: {}", sleep); | 13 | println!("Idles: {}", idles); |
| 14 | println!("Process ID: {}", process::id()); | ||
| 14 | let mut port = serial::open(&port_name).unwrap(); | 15 | let mut port = serial::open(&port_name).unwrap(); |
| 15 | if saturate(&mut port, sleep).is_err() { | 16 | if saturate(&mut port, idles).is_err() { |
| 16 | eprintln!("Unable to saturate port"); | 17 | eprintln!("Unable to saturate port"); |
| 17 | } | 18 | } |
| 18 | } else { | 19 | } else { |
| @@ -23,7 +24,7 @@ pub fn main() { | |||
| 23 | } | 24 | } |
| 24 | } | 25 | } |
| 25 | 26 | ||
| 26 | fn saturate<T: SerialPort>(port: &mut T, sleep: bool) -> io::Result<()> { | 27 | fn saturate<T: SerialPort>(port: &mut T, idles: bool) -> io::Result<()> { |
| 27 | port.reconfigure(&|settings| { | 28 | port.reconfigure(&|settings| { |
| 28 | settings.set_baud_rate(serial::Baud115200)?; | 29 | settings.set_baud_rate(serial::Baud115200)?; |
| 29 | settings.set_char_size(serial::Bits8); | 30 | settings.set_char_size(serial::Bits8); |
| @@ -39,7 +40,7 @@ fn saturate<T: SerialPort>(port: &mut T, sleep: bool) -> io::Result<()> { | |||
| 39 | 40 | ||
| 40 | port.write_all(&buf)?; | 41 | port.write_all(&buf)?; |
| 41 | 42 | ||
| 42 | if sleep { | 43 | if idles { |
| 43 | let micros = (random::<usize>() % 1000) as u64; | 44 | let micros = (random::<usize>() % 1000) as u64; |
| 44 | println!("Sleeping {}us", micros); | 45 | println!("Sleeping {}us", micros); |
| 45 | port.flush().unwrap(); | 46 | port.flush().unwrap(); |
| @@ -49,4 +50,4 @@ fn saturate<T: SerialPort>(port: &mut T, sleep: bool) -> io::Result<()> { | |||
| 49 | written += len; | 50 | written += len; |
| 50 | println!("Written: {}", written); | 51 | println!("Written: {}", written); |
| 51 | } | 52 | } |
| 52 | } \ No newline at end of file | 53 | } |
