diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ConfigParser.cpp | 10 | ||||
| -rw-r--r-- | src/Utils.cpp | 53 | ||||
| -rw-r--r-- | src/Utils.h | 8 | ||||
| -rw-r--r-- | src/output/SDR.cpp | 34 | 
4 files changed, 94 insertions, 11 deletions
diff --git a/src/ConfigParser.cpp b/src/ConfigParser.cpp index 68ee74b..1219ae7 100644 --- a/src/ConfigParser.cpp +++ b/src/ConfigParser.cpp @@ -251,7 +251,7 @@ static void parse_configfile(              throw std::runtime_error("Configuration error");          }          else if (sdr_device_config.frequency == 0) { -            sdr_device_config.frequency = parseChannel(chan); +            sdr_device_config.frequency = parse_channel(chan);          }          else if (sdr_device_config.frequency != 0 && chan != "") {              std::cerr << "       UHD output: cannot define both frequency and channel.\n"; @@ -305,7 +305,7 @@ static void parse_configfile(              throw std::runtime_error("Configuration error");          }          else if (outputsoapy_conf.frequency == 0) { -            outputsoapy_conf.frequency =  parseChannel(chan); +            outputsoapy_conf.frequency = parse_channel(chan);          }          else if (outputsoapy_conf.frequency != 0 && chan != "") {              std::cerr << "       soapy output: cannot define both frequency and channel.\n"; @@ -333,7 +333,7 @@ static void parse_configfile(              throw std::runtime_error("Configuration error");          }          else if (outputdexter_conf.frequency == 0) { -            outputdexter_conf.frequency =  parseChannel(chan); +            outputdexter_conf.frequency = parse_channel(chan);          }          else if (outputdexter_conf.frequency != 0 && chan != "") {              std::cerr << "       dexter output: cannot define both frequency and channel.\n"; @@ -362,7 +362,7 @@ static void parse_configfile(              throw std::runtime_error("Configuration error");          }          else if (outputlime_conf.frequency == 0) { -            outputlime_conf.frequency =  parseChannel(chan); +            outputlime_conf.frequency = parse_channel(chan);          }          else if (outputlime_conf.frequency != 0 && chan != "") {              std::cerr << "       Lime output: cannot define both frequency and channel.\n"; @@ -391,7 +391,7 @@ static void parse_configfile(              throw std::runtime_error("Configuration error");          }          else if (outputbladerf_conf.frequency == 0) { -            outputbladerf_conf.frequency =  parseChannel(chan); +            outputbladerf_conf.frequency = parse_channel(chan);          }          else if (outputbladerf_conf.frequency != 0 && chan != "") {              std::cerr << "       BladeRF output: cannot define both frequency and channel.\n"; diff --git a/src/Utils.cpp b/src/Utils.cpp index 20297ea..788d125 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -244,7 +244,7 @@ void set_thread_name(const char *name)  #endif  } -double parseChannel(const std::string& chan) +double parse_channel(const std::string& chan)  {      double freq;      if      (chan == "5A") freq = 174928000; @@ -286,12 +286,59 @@ double parseChannel(const std::string& chan)      else if (chan == "13E") freq = 237488000;      else if (chan == "13F") freq = 239200000;      else { -        std::cerr << "       soapy output: channel " << chan << " does not exist in table\n"; -        throw std::out_of_range("soapy channel selection error"); +        std::cerr << "Channel " << chan << " does not exist in table\n"; +        throw std::out_of_range("channel out of range");      }      return freq;  } +std::optional<std::string> convert_frequency_to_channel(double frequency) +{ +    const int freq = round(frequency); +    std::string chan; +    if      (freq == 174928000) chan = "5A"; +    else if (freq == 176640000) chan = "5B"; +    else if (freq == 178352000) chan = "5C"; +    else if (freq == 180064000) chan = "5D"; +    else if (freq == 181936000) chan = "6A"; +    else if (freq == 183648000) chan = "6B"; +    else if (freq == 185360000) chan = "6C"; +    else if (freq == 187072000) chan = "6D"; +    else if (freq == 188928000) chan = "7A"; +    else if (freq == 190640000) chan = "7B"; +    else if (freq == 192352000) chan = "7C"; +    else if (freq == 194064000) chan = "7D"; +    else if (freq == 195936000) chan = "8A"; +    else if (freq == 197648000) chan = "8B"; +    else if (freq == 199360000) chan = "8C"; +    else if (freq == 201072000) chan = "8D"; +    else if (freq == 202928000) chan = "9A"; +    else if (freq == 204640000) chan = "9B"; +    else if (freq == 206352000) chan = "9C"; +    else if (freq == 208064000) chan = "9D"; +    else if (freq == 209936000) chan = "10A"; +    else if (freq == 211648000) chan = "10B"; +    else if (freq == 213360000) chan = "10C"; +    else if (freq == 215072000) chan = "10D"; +    else if (freq == 216928000) chan = "11A"; +    else if (freq == 218640000) chan = "11B"; +    else if (freq == 220352000) chan = "11C"; +    else if (freq == 222064000) chan = "11D"; +    else if (freq == 223936000) chan = "12A"; +    else if (freq == 225648000) chan = "12B"; +    else if (freq == 227360000) chan = "12C"; +    else if (freq == 229072000) chan = "12D"; +    else if (freq == 230784000) chan = "13A"; +    else if (freq == 232496000) chan = "13B"; +    else if (freq == 234208000) chan = "13C"; +    else if (freq == 235776000) chan = "13D"; +    else if (freq == 237488000) chan = "13E"; +    else if (freq == 239200000) chan = "13F"; +    else { return std::nullopt; } + +    return chan; +} +  std::chrono::milliseconds transmission_frame_duration(unsigned int dabmode)  {      using namespace std::chrono; diff --git a/src/Utils.h b/src/Utils.h index 367dd48..584a756 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -31,6 +31,7 @@  #   include "config.h"  #endif +#include <optional>  #include <string>  #include <chrono>  #include <cstdio> @@ -54,8 +55,11 @@ int set_realtime_prio(int prio);  // Set the name of the thread  void set_thread_name(const char *name); -// Convert a channel like 10A to a frequency -double parseChannel(const std::string& chan); +// Convert a channel like 10A to a frequency in Hz +double parse_channel(const std::string& chan); + +// Convert a frequency in Hz to a channel. +std::optional<std::string> convert_frequency_to_channel(double frequency);  // dabMode is either 1, 2, 3, 4, corresponding to TM I, TM II, TM III and TM IV.  // throws a runtime_error if dabMode is not one of these values. diff --git a/src/output/SDR.cpp b/src/output/SDR.cpp index e466287..91c31f0 100644 --- a/src/output/SDR.cpp +++ b/src/output/SDR.cpp @@ -78,7 +78,8 @@ SDR::SDR(SDRDeviceConfig& config, std::shared_ptr<SDRDevice> device) :      RC_ADD_PARAMETER(txgain, "TX gain");      RC_ADD_PARAMETER(rxgain, "RX gain for DPD feedback");      RC_ADD_PARAMETER(bandwidth, "Analog front-end bandwidth"); -    RC_ADD_PARAMETER(freq, "Transmission frequency"); +    RC_ADD_PARAMETER(freq, "Transmission frequency in Hz"); +    RC_ADD_PARAMETER(channel, "Transmission frequency as channel");      RC_ADD_PARAMETER(muting, "Mute the output by stopping the transmitter");      RC_ADD_PARAMETER(temp, "Temperature in degrees C of the device");      RC_ADD_PARAMETER(underruns, "Counter of number of underruns"); @@ -389,6 +390,18 @@ void SDR::set_parameter(const string& parameter, const string& value)          m_device->tune(m_config.lo_offset, m_config.frequency);          m_config.frequency = m_device->get_tx_freq();      } +    else if (parameter == "channel") { +        try { +            const double frequency = parse_channel(value); + +            m_config.frequency = frequency; +            m_device->tune(m_config.lo_offset, m_config.frequency); +            m_config.frequency = m_device->get_tx_freq(); +        } +        catch (const std::out_of_range& e) { +            throw ParameterError("Cannot parse channel"); +        } +    }      else if (parameter == "muting") {          ss >> m_config.muting;      } @@ -416,6 +429,16 @@ const string SDR::get_parameter(const string& parameter) const      else if (parameter == "freq") {          ss << m_config.frequency;      } +    else if (parameter == "channel") { +        const auto maybe_freq = convert_frequency_to_channel(m_config.frequency); + +        if (maybe_freq.has_value()) { +            ss << *maybe_freq; +        } +        else { +            throw ParameterError("Frequency is outside list of channels"); +        } +    }      else if (parameter == "muting") {          ss << m_config.muting;      } @@ -488,6 +511,15 @@ const json::map_t SDR::get_all_values() const      stat["muting"].v = m_config.muting;      stat["temp"].v = std::nullopt; +    const auto maybe_freq = convert_frequency_to_channel(m_config.frequency); + +    if (maybe_freq.has_value()) { +        stat["channel"].v = *maybe_freq; +    } +    else { +        stat["channel"].v = std::nullopt; +    } +      if (m_device) {          const std::optional<double> temp = m_device->get_temperature();          if (temp) {  | 
