1pub const ALL_COMMANDS: &[&str] = &[
19 "id",
20 "battery",
21 "clock",
22 "freq",
23 "mode",
24 "squelch",
25 "power",
26 "att",
27 "meter",
28 "lock",
29 "dualband",
30 "bt",
31 "vox",
32 "fm",
33 "vfo",
34 "up",
35 "down",
36 "tune",
37 "recall",
38 "channel",
39 "channels",
40 "step",
41 "gps",
42 "urcall",
43 "cq",
44 "reflector",
45 "unreflector",
46 "aprs",
47 "dstar",
48 "last",
49 "status",
50 "check",
51 "verbose",
52 "quiet",
53 "confirm",
54 "help",
55 "quit",
56];
57
58#[must_use]
61pub fn for_command(cmd: &str) -> Option<&'static str> {
62 match cmd {
63 "id" | "identify" => Some(ID_HELP),
64 "battery" | "bat" => Some(BATTERY_HELP),
65 "clock" | "time" => Some(CLOCK_HELP),
66 "freq" | "frequency" => Some(FREQ_HELP),
67 "mode" => Some(MODE_HELP),
68 "squelch" | "sq" => Some(SQUELCH_HELP),
69 "power" | "pwr" => Some(POWER_HELP),
70 "att" | "attenuator" => Some(ATT_HELP),
71 "meter" | "smeter" => Some(METER_HELP),
72 "lock" => Some(LOCK_HELP),
73 "dualband" | "dual" => Some(DUALBAND_HELP),
74 "bt" | "bluetooth" => Some(BT_HELP),
75 "vox" => Some(VOX_HELP),
76 "fm" => Some(FM_HELP),
77 "vfo" => Some(VFO_HELP),
78 "up" => Some(UP_HELP),
79 "down" => Some(DOWN_HELP),
80 "tune" => Some(TUNE_HELP),
81 "recall" => Some(RECALL_HELP),
82 "ch" | "channel" => Some(CHANNEL_HELP),
83 "channels" => Some(CHANNELS_HELP),
84 "step" => Some(STEP_HELP),
85 "gps" => Some(GPS_HELP),
86 "urcall" | "ur" => Some(URCALL_HELP),
87 "cq" => Some(CQ_HELP),
88 "reflector" | "ref" => Some(REFLECTOR_HELP),
89 "unreflector" | "unlink" | "unref" => Some(UNREFLECTOR_HELP),
90 "aprs" => Some(APRS_HELP),
91 "dstar" => Some(DSTAR_HELP),
92 "last" | "repeat" => Some(LAST_HELP),
93 "status" => Some(STATUS_HELP),
94 "check" => Some(CHECK_HELP),
95 "verbose" | "quiet" => Some(VERBOSE_HELP),
96 "confirm" => Some(CONFIRM_HELP),
97 "help" | "?" => Some(HELP_HELP),
98 "quit" | "exit" | "q" => Some(QUIT_HELP),
99 _ => None,
100 }
101}
102
103pub const CAT_MODE_HELP: &str = "-- Information --
113help: Show this help text
114id: Radio model and identification
115battery: Battery charge level
116clock: Radio real-time clock
117quit: Exit the program
118-- Reading radio state --
119freq: Frequency on band A (or: freq b)
120mode: Operating mode on band A (or: mode b)
121squelch: Squelch level on band A (or: squelch b)
122power: Transmit power on band A (or: power b)
123att (attenuator): Attenuator on or off (or: att b)
124meter: Signal strength meter, S0 to S9 (or: meter b)
125lock: Key lock on or off
126dualband: Dual band display on or off
127bt (bluetooth): Bluetooth on or off
128vox: Voice-operated transmit on or off
129fm: FM broadcast radio on or off
130vfo: Full variable frequency oscillator state (or: vfo b)
131-- Changing settings --
132mode a fm: Set mode. Options: fm, nfm, am, dv, lsb, usb, cw
133squelch a 3: Set squelch level, 0 through 5
134power a high: Set power. Options: high, medium, low, extra-low
135att a on: Set attenuator on or off
136lock on: Set key lock on or off
137dualband on: Set dual band on or off
138bt on: Set Bluetooth on or off
139vox on: Set voice-operated transmit on or off
140vox gain 5: Set voice-operated transmit gain, 0 through 9
141vox delay 3: Set voice-operated transmit delay, 0 through 6
142fm on: Set FM broadcast radio on or off
143step a 5: Set frequency step size by index, 0 through 11
144-- Tuning --
145up: Step frequency up on band A (or: up b)
146down: Step frequency down on band A (or: down b)
147tune a 146.520: Tune band A to a frequency in megahertz
148recall a 5: Recall memory channel 5 on band A
149-- Memory channels --
150ch 5: Read memory channel 5
151channels: List programmed channels, default 0 through 19
152channels 0 100: List programmed channels 0 through 99
153-- D-STAR digital voice --
154urcall: Read destination callsign (D-STAR your-call field)
155urcall W1AW: Set destination callsign
156cq: Set destination to CQ CQ CQ (general call)
157reflector REF030 C: Connect to reflector, module C
158unreflector: Disconnect from reflector
159-- GPS --
160gps on on: Set GPS receiver on, PC output on
161gps off off: Set GPS receiver off, PC output off
162-- APRS packet radio mode --
163aprs start MYCALL 7: Enter APRS mode with callsign and SSID
164-- D-STAR gateway mode --
165dstar start MYCALL XRF030C: Enter D-STAR gateway with reflector";
166
167pub const APRS_MODE_HELP: &str = "You are in APRS packet radio mode.
169-- APRS commands --
170monitor: Continuously listen for APRS events (Ctrl-C to stop)
171msg W1AW Hello there: Send an APRS message to a station
172position 35.30 -82.46 Portable: Send a position beacon
173beacon: Send a status beacon
174stations: List recently heard stations
175igate r/35.30/-82.46/100: Bridge RF to APRS-IS with a filter
176aprs stop: Leave APRS mode, return to normal radio control
177quit: Exit the program";
178
179pub const DSTAR_MODE_HELP: &str = "You are in D-STAR digital voice gateway mode.
181-- D-STAR gateway commands --
182monitor: Start listening for voice and reflector events (Ctrl-C to stop)
183link REF030C: Connect to a reflector and start monitoring
184 Supported prefixes: REF (DPlus), XRF/XLX (DExtra), DCS
185unlink: Disconnect from the reflector
186echo: Test your audio. Records your transmission, plays it back
187text Hello: Set a text message to embed in your next voice transmission
188text clear: Remove the outgoing text message
189heard: List recently heard stations
190status: Modem and reflector connection status
191dstar stop: Leave D-STAR mode, return to normal radio control
192quit: Exit the program";
193
194const ID_HELP: &str = "id: Read the radio model and identification.
199Syntax: id
200Example: id
201Related commands: status, clock";
202
203const BATTERY_HELP: &str = "battery: Read the current battery charge level.
204Syntax: battery
205Output is one of: empty, one third, two thirds, full, charging.
206Example: battery
207Related commands: status";
208
209const CLOCK_HELP: &str = "clock: Read the radio's real-time clock.
210Syntax: clock
211Example: clock
212Related commands: status";
213
214const FREQ_HELP: &str = "freq: Read the current frequency on a band.
215Syntax: freq [a or b]
216Default band is A.
217Example: freq
218Example: freq b
219Related commands: tune, up, down, vfo, channel";
220
221const MODE_HELP: &str = "mode: Read or set the operating mode on a band.
222Syntax: mode [a or b] [mode_name]
223Valid modes: fm, nfm, am, dv, lsb, usb, cw, dr, wfm.
224Example: mode a
225Example: mode a fm
226Example: mode b dv
227Related commands: freq, vfo";
228
229const SQUELCH_HELP: &str = "squelch: Read or set the squelch level on a band.
230Syntax: squelch [a or b] [0 through 5]
231Example: squelch
232Example: squelch a 3
233Related commands: meter";
234
235const POWER_HELP: &str = "power: Read or set the transmit power on a band.
236Syntax: power [a or b] [level]
237Valid levels: high, medium, low, extra-low.
238Example: power a
239Example: power a high
240Related commands: vox";
241
242const ATT_HELP: &str = "att: Read or set the attenuator on a band.
243Syntax: att [a or b] [on or off]
244Example: att a
245Example: att a on
246Related commands: freq";
247
248const METER_HELP: &str = "meter: Read the signal strength meter on a band.
249Syntax: meter [a or b]
250Output is a letter-number pair from S0 to S9.
251Example: meter
252Example: meter b
253Related commands: squelch, status";
254
255const LOCK_HELP: &str = "lock: Read or set the key lock state.
256Syntax: lock [on or off]
257Example: lock
258Example: lock on
259Related commands: status";
260
261const DUALBAND_HELP: &str = "dualband: Read or set the dual-band display mode.
262Syntax: dualband [on or off]
263Example: dualband
264Example: dualband on";
265
266const BT_HELP: &str = "bt: Read or set the Bluetooth state.
267Syntax: bt [on or off]
268Example: bt
269Example: bt off";
270
271const VOX_HELP: &str = "vox: Read or set voice-operated transmit.
272Syntax: vox [on or off]
273Syntax: vox gain [0 through 9]
274Syntax: vox delay [0 through 6]
275Example: vox on
276Example: vox gain 5
277Example: vox delay 3";
278
279const FM_HELP: &str = "fm: Read or set the FM broadcast radio receiver.
280Syntax: fm [on or off]
281Example: fm on";
282
283const VFO_HELP: &str = "vfo: Read the full variable frequency oscillator state.
284Syntax: vfo [a or b]
285Reports frequency, step size, transmit offset, and mode.
286Example: vfo
287Example: vfo b";
288
289const UP_HELP: &str = "up: Step the frequency up by one increment.
290Syntax: up [a or b]
291Example: up
292Example: up b
293Related commands: down, step, tune";
294
295const DOWN_HELP: &str = "down: Step the frequency down by one increment.
296Syntax: down [a or b]
297Example: down
298Example: down b
299Related commands: up, step, tune";
300
301const TUNE_HELP: &str = "tune: Tune a band to a specific frequency in megahertz.
302Syntax: tune [a or b] [frequency in megahertz]
303Example: tune a 146.520
304Example: tune b 446.000
305Related commands: freq, up, down";
306
307const RECALL_HELP: &str = "recall: Recall a memory channel on a band.
308Syntax: recall [a or b] [channel number]
309Example: recall a 5
310Related commands: channel, channels";
311
312const CHANNEL_HELP: &str = "channel: Read a single memory channel by number.
313Syntax: ch [channel number]
314Example: ch 5
315Related commands: channels, recall";
316
317const CHANNELS_HELP: &str = "channels: List programmed memory channels in a range.
318Syntax: channels [start] [end]
319Default range is 0 through 19.
320Example: channels
321Example: channels 0 100
322Related commands: channel, recall";
323
324const STEP_HELP: &str = "step: Read or set the frequency step size.
325Syntax: step [a or b] [index 0 through 11]
326Index maps: 0=5, 1=6.25, 2=8.33, 3=9, 4=10, 5=12.5, 6=15 kilohertz.
327Index maps: 7=20, 8=25, 9=30, 10=50, 11=100 kilohertz.
328Example: step a 5
329Related commands: up, down";
330
331const GPS_HELP: &str = "gps: Set the GPS receiver and PC output configuration.
332Syntax: gps [on or off] [on or off]
333First argument controls the GPS receiver.
334Second argument controls PC serial output of NMEA sentences.
335Example: gps on on
336Example: gps off off";
337
338const URCALL_HELP: &str = "urcall: Read or set the D-STAR destination callsign.
339Syntax: urcall [callsign] [suffix]
340Example: urcall
341Example: urcall W1AW
342Example: urcall W1AW P
343Related commands: cq, reflector";
344
345const CQ_HELP: &str = "cq: Set the D-STAR destination to CQ CQ CQ.
346Syntax: cq
347Sets the urcall field to the general call destination.
348Example: cq
349Related commands: urcall";
350
351const REFLECTOR_HELP: &str = "reflector: Connect to a D-STAR reflector.
352Syntax: reflector [name] [module]
353Example: reflector REF030 C
354Related commands: unreflector, dstar";
355
356const UNREFLECTOR_HELP: &str = "unreflector: Disconnect from the linked reflector.
357Syntax: unreflector
358Example: unreflector
359Related commands: reflector";
360
361const APRS_HELP: &str = "aprs: Enter or leave APRS packet radio mode.
362Syntax: aprs start [callsign] [ssid]
363Syntax: aprs stop
364Example: aprs start W1AW 7
365Related commands: beacon, msg, position";
366
367const DSTAR_HELP: &str = "dstar: Enter or leave D-STAR gateway mode.
368Syntax: dstar start [callsign] [reflector]
369Syntax: dstar stop
370Example: dstar start W1AW XRF030C
371Related commands: link, unlink, echo";
372
373const LAST_HELP: &str = "last: Re-announce previous output lines.
374Syntax: last
375Syntax: last [number]
376Syntax: last all
377Example: last
378Example: last 5
379Example: last all";
380
381const STATUS_HELP: &str = "status: Dump the full radio state in one block.
382Syntax: status
383Reads model, firmware, battery, clock, lock, both bands' settings.
384Takes 2 to 3 seconds because it issues many CAT commands.
385Example: status";
386
387const CHECK_HELP: &str = "check: Run the accessibility compliance self-check.
388Syntax: check
389Exercises every formatter, runs the lint, prints a report.
390Example: check";
391
392const VERBOSE_HELP: &str = "verbose: Toggle verbose monitor output.
393Syntax: verbose
394Syntax: verbose [on or off]
395Syntax: quiet (same as verbose off)
396Example: verbose off";
397
398const CONFIRM_HELP: &str = "confirm: Toggle transmit-command confirmation.
399Syntax: confirm [on or off]
400When on, beacon, position, msg, cq, echo, and link prompt first.
401Default is on. Disabling lasts for the current session.
402Example: confirm off
403Example: confirm on";
404
405const HELP_HELP: &str = "help: Show help text.
406Syntax: help
407Syntax: help [command]
408Syntax: help all
409Example: help
410Example: help freq";
411
412const QUIT_HELP: &str = "quit: Exit the program.
413Syntax: quit
414Aliases: exit, q
415Example: quit";
416
417#[cfg(test)]
418mod tests {
419 use super::*;
420 use crate::lint;
421
422 #[test]
423 fn all_commands_have_help() {
424 for cmd in ALL_COMMANDS {
425 assert!(
426 for_command(cmd).is_some(),
427 "command {cmd:?} is listed in ALL_COMMANDS but has no help entry",
428 );
429 }
430 }
431
432 #[test]
433 fn every_help_text_passes_lint() {
434 for cmd in ALL_COMMANDS {
435 let text = for_command(cmd).expect("entry exists");
436 if let Err(violations) = lint::check_output(text) {
437 panic!(
438 "help for {cmd:?} violates accessibility rules: {violations:?}\ntext:\n{text}"
439 );
440 }
441 }
442 }
443
444 #[test]
445 fn unknown_command_returns_none() {
446 assert_eq!(for_command("nosuchcommand"), None);
447 }
448
449 #[test]
450 fn freq_help_includes_example() {
451 let text = for_command("freq").expect("freq has help");
452 assert!(text.contains("Example:"));
453 assert!(text.contains("Syntax:"));
454 }
455
456 #[test]
457 fn mode_help_texts_pass_lint() {
458 lint::check_output(CAT_MODE_HELP).expect("CAT_MODE_HELP lints clean");
459 lint::check_output(APRS_MODE_HELP).expect("APRS_MODE_HELP lints clean");
460 lint::check_output(DSTAR_MODE_HELP).expect("DSTAR_MODE_HELP lints clean");
461 }
462}