ardop_interface/lib.rs
1//! An Async Rust interface to the ARDOP TNC
2//!
3//! [Documentation](https://docs.rs/ardop_interface) |
4//! [Crate](https://crates.io/crates/ardop_interface) |
5//! [Git](https://github.com/cbs228/ardop_interface)
6//!
7//! # Introduction
8//!
9//! `ardop_interface` integrates with the Amateur Radio Digital
10//! Open Protocol ([ARDOP](https://ardop.groups.io/g/main)) soundcard
11//! modem softare. The ARDOP modem is intended to provide reliable,
12//! low-speed connectivity over High Frequency (HF) radio links.
13//!
14//! *This crate is not ARDOP.* This crate is only an interface. With
15//! this interface, and separate ARDOP modem software, you can build
16//! full-featured Rust applications that communicate over the radio.
17//!
18//! # Minimal Example
19//!
20//! ```no_run
21//! use std::net::SocketAddr;
22//! use async_std::task;
23//! use futures::prelude::*;
24//!
25//! use ardop_interface::tnc::*;
26//!
27//! fn main() {
28//! task::block_on(async {
29//! let addr = "127.0.0.1:8515".parse().unwrap();
30//! let mut tnc = ArdopTnc::new(&addr, "MYC4LL")
31//! .await
32//! .unwrap();
33//! let mut conn = tnc.connect("T4GET", 500, false, 3)
34//! .await
35//! .expect("TNC failure")
36//! .expect("Connection failed");
37//! conn.write_all(b"Hello, world!\n").await.unwrap();
38//! conn.close().await;
39//! })
40//! }
41//! ```
42//!
43//! See the
44//! [`examples/`](https://github.com/cbs228/ardop_interface/tree/master/examples)
45//! directory in the source code repository for a complete client
46//! and server. The examples also demonstrate the `async_std` crate,
47//! argument parsing, and logging.
48//!
49//! # The ARDOP Modem
50//!
51//! Like most amateur radio modems, ARDOP is designed to interface
52//! with analog, single-sideband (SSB) transceivers via a sound
53//! card interface. A computer—which may be a simple, single-board
54//! computer—turns data into sound, and back again.
55//!
56//! ARDOP is designed to:
57//!
58//! * Automatically retry failed transmissions. This mode of
59//! operation is called *automatic repeat request* (ARQ),
60//! and it helps ensure that data reaches its final destination.
61//!
62//! * Use the fastest available mode for the signal-to-noise ratio
63//! and band conditions
64//!
65//! * Support unattended, automatic station operation
66//!
67//! * Perform well on the high frequency (HF) bands
68//!
69//! Best of all, ARDOP has an open development model. Full protocol
70//! specifications are available, and open-source implementations of
71//! the modem exist.
72//!
73//! ARDOP is intended for use by licensed radio amateurs. If you'd
74//! like to get started with the hobby, you should find a club,
75//! "hamfest," or "hamvention" near you!
76//!
77//! # The Rust Interface
78//!
79//! The ARDOP software has a standardized "terminal node controller"
80//! (TNC) interface for clients to use. To use the TNC, clients must
81//! make two simultaneous TCP connections and perform a great deal
82//! of serialization and de-serialization. This crate handles many
83//! of these details for you.
84//!
85//! This crate exposes an `async` API that many rustaceans will
86//! find familiar: socket programming. The
87//! [`ArqStream`](arq/index.html) object is designed
88//! to mimic an async `TcpStream`. Once a connection is made,
89//! data is exchanged with asynchronous reads from, and writes to,
90//! the `ArqStream` object.
91//!
92//! The `async` API allows ARDOP to coexist with native TCP sockets,
93//! GUIs, and other I/O processes while maintaining a small system
94//! resource footprint.
95//!
96//! # Development Status
97//!
98//! This crate is experimental. Its API will not stabilize until
99//! `ardop_interface` can be built without `unstable` features of
100//! [`async_std`](https://docs.rs/async-std/).
101//!
102//! # Prerequisites
103//!
104//! Rust 1.40 or later is required.
105//!
106//! Obtain a compatible implementation of ARDOP. You must use
107//! ARDOP software which implements protocol **version one**.
108//! The ARDOP v2 specification has been withdrawn by its authors, and
109//! version three is presently in development. The TNC interface on
110//! which this crate depends can change during major releases.
111//!
112//! These instructions assume the use of John Wiseman's `ardopc`, version 1.
113//! Other implementations will probably work, but this crate has not
114//! been tested against them. You may be able to obtain this software at
115//! <http://www.cantab.net/users/john.wiseman/Downloads/Beta/TeensyProjects.zip>
116//! or from the ARDOP [forums](https://ardop.groups.io/g/users/topics).
117//!
118//! You will need your system's C/C++ compiler in order to build `ardopc`.
119//! Debian-based distributions can install these with:
120//!
121//! ```bash
122//! sudo apt-get install build-essential
123//! ```
124//!
125//! Unpack the archive, `cd` into the `ARDOPC` subdirectory, and
126//! run `make` to build the software. There is also a Visual Studio
127//! project for Windows users. Alternatively, binary builds may be
128//! available in
129//! <http://www.cantab.net/users/john.wiseman/Downloads/Beta/>.
130//!
131//! You should now be able to invoke ARDOP as
132//!
133//! ```bash
134//! ./ardopc PORT INDEV OUTDEV
135//! ```
136//!
137//! where
138//! * `PORT` is the desired TCP control port (typically `8515`)
139//! * `INDEV` is the ALSA device name for your "`line in`"
140//! soundcard port. If your system has pulseaudio, you may use
141//! it with the `pulse` device.
142//! * `OUTDEV` is the ALSA device name for your "`line out`"
143//! soundcard port. If your system has pulseaudio, you may use
144//! it with the `pulse` device.
145//!
146//! # Running the Examples
147//!
148//! The examples are not published to `crates.io.` You will need
149//! to clone our source repository instead:
150//!
151//! ```bash
152//! git clone https://github.com/cbs228/ardop_interface.git
153//! ```
154//!
155//! To conduct a local test of ARDOP, you must run two instances
156//! of the ARDOP modem. To make an acoustic channel between the
157//! two the modems, place your microphone in close proximity to
158//! your speakers. Alternatively, on linux, you may also use the
159//! PulseAudio null sink:
160//!
161//! ```bash
162//! pacmd load-module module-null-sink sink_name=Virtual1
163//! pacmd set-default-sink Virtual1
164//! pacmd set-default-source Virtual1.monitor
165//! ```
166//!
167//! `ardopc` was designed for the ALSA sound APIs. Performance
168//! may be degraded when running with pulseaudio. On some systems,
169//! it may help to keep the pulseaudio volume control
170//! (`pavucontrol`) program open while ardopc is running.
171//!
172//! Start two instances of ardopc
173//!
174//! ```bash
175//! ./ardopc 8515 pulse pulse &
176//! ./ardopc 8520 pulse pulse &
177//! ```
178//!
179//! Build and run the `echoserver` package with
180//!
181//! ```bash
182//! cargo run --package echoserver -- localhost:8515 MYCALL-S 200
183//! ```
184//!
185//! Replace `MYCALL` with your callsign. The `-S` is a
186//! Service Set Identifier (SSID), which is an arbitrary
187//! single-character extension to your callsign.
188//!
189//! Now run the `echoclient` with
190//!
191//! ```bash
192//! cargo run --package echoclient -- localhost:8520 MYCALL-C MYCALL-S 200
193//! ```
194//!
195//! The `echoclient` will send a number of pre-programmed
196//! text stanzas to the `echoserver`, which will parrot them
197//! back. Both the client and server will print their progress
198//! to stderr. The demo succeeds if the client prints
199//!
200//! ```txt
201//! Echo server echoed all stanzas correctly.
202//! ```
203//!
204//! You can also use the `echoserver` interactively via a
205//! line-oriented chat program, like `ARIM`.
206//!
207//! When you are finished, remove the null sink if you are
208//! using it.
209//!
210//! ```bash
211//! pacmd unload-module module-null-sink
212//! ```
213//!
214//! # Unsupported ARDOP Features
215//!
216//! At present, this crate only supports the ARDOP `ARQ`
217//! connection-oriented protocol, which is TCP-like. ARDOP also
218//! has a connectionless `FEC` protocol, which is UDP-like.
219//! `ardop_interface` does not currently support FEC mode.
220//!
221//! The following other features are currently not implemented
222//! by this crate.
223//!
224//! * **Rig control**: No type of rig control is presently
225//! integrated. This crate cannot provide the following
226//! functionality, at present.
227//!
228//! * **Tuning**: `ardop_interface` knows nothing about your rig
229//! and cannot adjust its frequency or mode.
230//!
231//! * **Keying**: This crate does not key your radio's PTT.
232//! The ARDOP TNC may be able to do this for you. `ardopc` can
233//! key transmitters over a serial connection.
234//!
235//! * **Scanning**: The ARDOP frequency agility / scanning functions
236//! in `LISTEN` mode are not supported
237//!
238//! # Next Steps
239//!
240//! What sorts of protocols would you like to see on the air?
241//! With a reliable, TCP-like link between stations, the
242//! ionosphere is the limit!
243//!
244//! # Further Reading
245//!
246//! * [`tnc`](tnc/index.html): Main TNC command and control via the
247//! `ArdopTnc`
248//! * [`arq`](arq/index.html): Reliable ARQ connections with
249//! `ArqStream`
250
251#![recursion_limit = "128"]
252#[allow(unused_imports)]
253extern crate async_std;
254#[macro_use]
255extern crate custom_derive;
256#[macro_use]
257extern crate enum_derive;
258#[allow(unused_imports)]
259#[macro_use]
260extern crate nom;
261extern crate bytes;
262#[macro_use]
263extern crate futures;
264extern crate futures_codec;
265#[macro_use]
266extern crate lazy_static;
267#[macro_use]
268extern crate log;
269extern crate num;
270extern crate regex;
271
272pub mod arq;
273pub mod tnc;
274
275mod framing;
276mod protocol;
277mod tncio;