hamlib_client/
adif.rs

1/*
2 * Copyright (C) 2024 Luca Cireddu <sardylan@gmail.com>
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License as published by the Free Software
6 * Foundation, version 3.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with
13 * this program. If not, see <https://www.gnu.org/licenses/>.
14 *
15 */
16
17use std::fmt::{Display, Formatter};
18use std::str::FromStr;
19
20#[derive(Debug, Eq, PartialEq, Copy, Clone)]
21pub enum Mode {
22    AM,
23    ARDOP,
24    ATV,
25    CHIP,
26    CLO,
27    CONTESTI,
28    CW,
29    DIGITALVOICE,
30    DOMINO,
31    DYNAMIC,
32    FAX,
33    FM,
34    FSK441,
35    FT8,
36    HELL,
37    ISCAT,
38    JT4,
39    JT6M,
40    JT9,
41    JT44,
42    JT65,
43    MFSK,
44    MSK144,
45    MT63,
46    OLIVIA,
47    OPERA,
48    PAC,
49    PAX,
50    PKT,
51    PSK,
52    PSK2K,
53    Q15,
54    QRA64,
55    ROS,
56    RTTY,
57    RTTYM,
58    SSB,
59    SSTV,
60    T10,
61    THOR,
62    THRB,
63    TOR,
64    V4,
65    VOI,
66    WINMOR,
67    WSPR,
68    None,
69}
70
71impl Display for Mode {
72    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
73        write!(f, "{:?}", self)
74    }
75}
76
77impl From<&str> for Mode {
78    fn from(value: &str) -> Self {
79        Mode::from_str(value).unwrap()
80    }
81}
82
83impl From<&&str> for Mode {
84    fn from(value: &&str) -> Self {
85        Mode::from_str(value).unwrap()
86    }
87}
88
89impl FromStr for Mode {
90    type Err = ();
91
92    fn from_str(s: &str) -> Result<Self, Self::Err> {
93        match s {
94            "AM" => Ok(Mode::AM),
95            "ARDOP" => Ok(Mode::ARDOP),
96            "ATV" => Ok(Mode::ATV),
97            "CHIP" => Ok(Mode::CHIP),
98            "CLO" => Ok(Mode::CLO),
99            "CONTESTI" => Ok(Mode::CONTESTI),
100            "CW" => Ok(Mode::CW),
101            "DIGITALVOICE" => Ok(Mode::DIGITALVOICE),
102            "DOMINO" => Ok(Mode::DOMINO),
103            "DYNAMIC" => Ok(Mode::DYNAMIC),
104            "FAX" => Ok(Mode::FAX),
105            "FM" => Ok(Mode::FM),
106            "FSK441" => Ok(Mode::FSK441),
107            "FT8" => Ok(Mode::FT8),
108            "HELL" => Ok(Mode::HELL),
109            "ISCAT" => Ok(Mode::ISCAT),
110            "JT4" => Ok(Mode::JT4),
111            "JT6M" => Ok(Mode::JT6M),
112            "JT9" => Ok(Mode::JT9),
113            "JT44" => Ok(Mode::JT44),
114            "JT65" => Ok(Mode::JT65),
115            "MFSK" => Ok(Mode::MFSK),
116            "MSK144" => Ok(Mode::MSK144),
117            "MT63" => Ok(Mode::MT63),
118            "OLIVIA" => Ok(Mode::OLIVIA),
119            "OPERA" => Ok(Mode::OPERA),
120            "PAC" => Ok(Mode::PAC),
121            "PAX" => Ok(Mode::PAX),
122            "PKT" => Ok(Mode::PKT),
123            "PSK" => Ok(Mode::PSK),
124            "PSK2K" => Ok(Mode::PSK2K),
125            "Q15" => Ok(Mode::Q15),
126            "QRA64" => Ok(Mode::QRA64),
127            "ROS" => Ok(Mode::ROS),
128            "RTTY" => Ok(Mode::RTTY),
129            "RTTYM" => Ok(Mode::RTTYM),
130            "SSB" => Ok(Mode::SSB),
131            "SSTV" => Ok(Mode::SSTV),
132            "T10" => Ok(Mode::T10),
133            "THOR" => Ok(Mode::THOR),
134            "THRB" => Ok(Mode::THRB),
135            "TOR" => Ok(Mode::TOR),
136            "V4" => Ok(Mode::V4),
137            "VOI" => Ok(Mode::VOI),
138            "WINMOR" => Ok(Mode::WINMOR),
139            "WSPR" => Ok(Mode::WSPR),
140            _ => Ok(Mode::None),
141        }
142    }
143}
144
145#[derive(Debug, Copy, Clone)]
146pub enum PropagationMode {
147    AS,
148    AUE,
149    AUR,
150    BS,
151    ECH,
152    EME,
153    ES,
154    F2,
155    FAI,
156    GWAVE,
157    INTERNET,
158    ION,
159    IRL,
160    LOS,
161    MS,
162    RPT,
163    RS,
164    SAT,
165    TEP,
166    TR,
167    None,
168}
169
170impl Display for PropagationMode {
171    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
172        match self {
173            Self::AS => {
174                write!(f, "Aircraft Scatter")
175            }
176            Self::AUE => {
177                write!(f, "Aurora-E")
178            }
179            Self::AUR => {
180                write!(f, "Aurora")
181            }
182            Self::BS => {
183                write!(f, "Back scatter")
184            }
185            Self::ECH => {
186                write!(f, "EchoLink")
187            }
188            Self::EME => {
189                write!(f, "Earth-Moon-Earth")
190            }
191            Self::ES => {
192                write!(f, "Sporadic E")
193            }
194            Self::F2 => {
195                write!(f, "F2 Reflection")
196            }
197            Self::FAI => {
198                write!(f, "Field Aligned Irregularities")
199            }
200            Self::GWAVE => {
201                write!(f, "Ground Wave")
202            }
203            Self::INTERNET => {
204                write!(f, "Internet-assisted")
205            }
206            Self::ION => {
207                write!(f, "Ionoscatter")
208            }
209            Self::IRL => {
210                write!(f, "IRLP")
211            }
212            Self::LOS => {
213                write!(
214                    f,
215                    "Line of Sight (includes transmission through obstacles such as walls)"
216                )
217            }
218            Self::MS => {
219                write!(f, "Meteor scatter")
220            }
221            Self::RPT => {
222                write!(f, "Terrestrial or atmospheric repeater or transponder")
223            }
224            Self::RS => {
225                write!(f, "Rain scatter")
226            }
227            Self::SAT => {
228                write!(f, "Satellite")
229            }
230            Self::TEP => {
231                write!(f, "Trans-equatorial")
232            }
233            Self::TR => {
234                write!(f, "Tropospheric ducting")
235            }
236            Self::None => {
237                write!(f, "")
238            }
239        }
240    }
241}