hamlib_client/
vfo.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 crate::error::RigCtlError;
18use std::fmt;
19use std::fmt::{Display, Formatter};
20use std::str::FromStr;
21
22#[derive(Debug, Copy, Clone, PartialEq, Eq)]
23pub enum VFO {
24    VFOA,
25    VFOB,
26    VFOC,
27    CurrVfo,
28    VFO,
29    MEM,
30    Main,
31    Sub,
32    TX,
33    RX,
34    None,
35}
36
37impl Display for VFO {
38    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
39        match self {
40            VFO::VFOA => write!(f, "VFOA"),
41            VFO::VFOB => write!(f, "VFOB"),
42            VFO::VFOC => write!(f, "VFOC"),
43            VFO::CurrVfo => write!(f, "currVfo"),
44            VFO::VFO => write!(f, "VFO"),
45            VFO::MEM => write!(f, "MEM"),
46            VFO::Main => write!(f, "Main"),
47            VFO::Sub => write!(f, "Sub"),
48            VFO::TX => write!(f, "TX"),
49            VFO::RX => write!(f, "RX"),
50            VFO::None => write!(f, "None"),
51        }
52    }
53}
54
55impl FromStr for VFO {
56    type Err = RigCtlError;
57    fn from_str(s: &str) -> Result<Self, Self::Err> {
58        match s {
59            "VFOA" => Ok(VFO::VFOA),
60            "VFOB" => Ok(VFO::VFOB),
61            "VFOC" => Ok(VFO::VFOC),
62            "currVFO" => Ok(VFO::CurrVfo),
63            "VFO" => Ok(VFO::VFO),
64            "MEM" => Ok(VFO::MEM),
65            "Main" => Ok(VFO::Main),
66            "Sub" => Ok(VFO::Sub),
67            "TX" => Ok(VFO::TX),
68            "RX" => Ok(VFO::RX),
69            "None" => Ok(VFO::None),
70            _ => Err(RigCtlError::RawDataError(format!("Unable to parse VFO with string \"{}\"", &s))),
71        }
72    }
73}