1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//! `rfe` is a Rust library for communicating with
//! [RF Explorer](https://www.j3.rf-explorer.com/) spectrum analyzers and signal
//! generators over a USB virtual serial port.
//!
//! It provides high-level device types for RF Explorer hardware and lower-level
//! building blocks for similar serial devices that use the same message
//! container pattern.
//!
//! ## Connecting to an RF Explorer
//!
//! `rfe` can search for an attached RF Explorer without knowing its port name or
//! baud rate. It tries USB serial ports with the VID and PID used by the RF
//! Explorer's Silicon Labs CP210x USB-to-UART bridge.
//!
//! ```no_run
//! use rfe::{SignalGenerator, SpectrumAnalyzer};
//!
//! let spectrum_analyzer =
//! SpectrumAnalyzer::connect().expect("RF Explorer spectrum analyzer should be connected");
//! let signal_generator =
//! SignalGenerator::connect().expect("RF Explorer signal generator should be connected");
//! ```
//!
//! You can also connect to a known serial port and baud rate.
//!
//! ```no_run
//! use rfe::{SignalGenerator, SpectrumAnalyzer};
//!
//! let spectrum_analyzer =
//! SpectrumAnalyzer::connect_with_name_and_baud_rate("COM2", 500_000)?;
//! let signal_generator =
//! SignalGenerator::connect_with_name_and_baud_rate("COM1", 500_000)?;
//! # Ok::<(), rfe::ConnectionError>(())
//! ```
//!
//! ## Collecting spectrum analyzer sweeps
//!
//! `rfe` provides three APIs for reading spectrum analyzer sweeps.
//!
//! ### Waiting for the next sweep
//!
//! [`SpectrumAnalyzer::wait_for_next_sweep()`] blocks until the device reports a
//! new sweep or the timeout elapses.
//!
//! ```no_run
//! use rfe::SpectrumAnalyzer;
//!
//! let rfe = SpectrumAnalyzer::connect().expect("RF Explorer should be connected");
//! let sweep = rfe.wait_for_next_sweep()?;
//! println!("{:?}", sweep);
//! # Ok::<(), rfe::Error>(())
//! ```
//!
//! ### Reading the latest cached sweep
//!
//! [`SpectrumAnalyzer::sweep()`] returns the most recently measured sweep, or
//! `None` if no sweep has been received yet.
//!
//! ```no_run
//! use rfe::SpectrumAnalyzer;
//!
//! let rfe = SpectrumAnalyzer::connect().expect("RF Explorer should be connected");
//! let sweep = rfe.sweep();
//! ```
//!
//! ### Receiving sweeps with a callback
//!
//! [`SpectrumAnalyzer::set_sweep_callback()`] registers a callback that runs on a
//! separate thread whenever a sweep is received.
//!
//! ```no_run
//! use rfe::SpectrumAnalyzer;
//!
//! let rfe = SpectrumAnalyzer::connect().expect("RF Explorer should be connected");
//! rfe.set_sweep_callback(|sweep, start_freq, stop_freq| {
//! println!(
//! "Received sweep from {}-{} MHz",
//! start_freq.as_mhz(),
//! stop_freq.as_mhz()
//! );
//! println!("{sweep:?}");
//! });
//! ```
//!
//! ## Generating a signal with an RF Explorer Signal Generator
//!
//! ```no_run
//! use rfe::{
//! signal_generator::{Attenuation, PowerLevel, SignalGenerator},
//! Frequency,
//! };
//!
//! let rfe = SignalGenerator::connect().expect("RF Explorer should be connected");
//! rfe.start_cw(Frequency::from_mhz(2412), Attenuation::Off, PowerLevel::Low)?;
//! # Ok::<(), rfe::Error>(())
//! ```
/// RF Explorer signal generator types and commands.
/// RF Explorer spectrum analyzer types and commands.
pub use *;
pub use ScreenData;
pub use SignalGenerator;
pub use SpectrumAnalyzer;