Repository navigation
Expand file tree
/
Copy pathbasic.rs
More file actions
executable file
·60 lines (48 loc) · 2.23 KB
/
Copy pathbasic.rs
File metadata and controls
executable file
·60 lines (48 loc) · 2.23 KB
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
use rigctld::{Daemon, Rig};
use tokio::time::{sleep, Duration};
#[tokio::main]
async fn main() {
// Start `rigctld`
let daemon = Daemon::default();
println!("rigctld version: {}", daemon.get_version().await.unwrap());
let mut rigctld = daemon.spawn().await.unwrap();
// Wait a few milliseconds until `rigctld` is ready.
// There is currently no way to check wether the daemon is running and already ready to accept incoming connections.
// Therefore sleep a while and connect to `rigctld`.
// The actual duration required to sleep depends on how long it takes for the daemon to connect to the actual rig.
// This may vary between devices. While using the dummy rig a duration of 250 ms seems reasonable.
sleep(Duration::from_millis(250)).await;
// Check wether rigctld is running.
// This checks only if the process is still up and running and not if the daemon is ready to accept incoming connections.
// `rigctld` may crash after start if e.g. the requested port is already taken by another process.
// This happens at runtime and thus the process starts flawlessly at first glance.
if !rigctld.is_running().unwrap() {
println!("Failed to start rigctld. Another instance already running?");
return;
}
// Establish connection to `rigctld`
let mut rig = Rig::new(daemon.get_host(), daemon.get_port());
rig.connect().await.unwrap();
// Set and get mode
let (mode, _) = rig.get_mode().await.unwrap();
println!("Rig started in mode {}", mode);
rig.set_mode(rigctld::Mode::LSB, 0).await.unwrap();
let (mode, _) = rig.get_mode().await.unwrap();
println!("Set rig to mode {}", mode);
let mut counter = 7000000;
while counter < 7200000 {
// Set frequency
rig.set_frequency(counter).await.unwrap();
// Get frequency
let freq = rig.get_frequency().await.unwrap();
println!("Current frequency {} Hz", freq);
counter += 10000;
sleep(Duration::from_millis(500)).await;
}
// Disconnect from `rigctld`
rig.disconnect();
// Kill the daemon
// Not really necessary here since the kernel will kill it anyway after this process ends
rigctld.kill().await.unwrap();
println!("Done.");
}