[PATCH] osmo-trx[master]: Add support to set Rx/TxAntenna
Hello Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/6238 to look at the new patch set (#2). Add support to set Rx/TxAntenna Change-Id: I1735e6ab05a05b0312d6d679b16ebd4a2260fa23 --- M Transceiver52M/UHDDevice.cpp M Transceiver52M/USRPDevice.cpp M Transceiver52M/USRPDevice.h M Transceiver52M/osmo-trx.cpp M Transceiver52M/radioDevice.h 5 files changed, 253 insertions(+), 10 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/38/6238/2 diff --git a/Transceiver52M/UHDDevice.cpp b/Transceiver52M/UHDDevice.cpp index 1120299..1687a60 100644 --- a/Transceiver52M/UHDDevice.cpp +++ b/Transceiver52M/UHDDevice.cpp @@ -208,7 +208,9 @@ class uhd_device : public RadioDevice { public: uhd_device(size_t tx_sps, size_t rx_sps, InterfaceType type, - size_t chans, double offset); + size_t chans, double offset, + const std::vector& tx_paths, + const std::vector& rx_paths); ~uhd_device(); int open(const std::string , int ref, bool swap_channels); @@ -248,6 +250,11 @@ double getRxFreq(size_t chan); double getRxFreq(); + bool setRxAntenna(const std::string , size_t chan); + std::string getRxAntenna(size_t chan); + bool setTxAntenna(const std::string , size_t chan); + std::string getTxAntenna(size_t chan); + inline double getSampleRate() { return tx_rate; } inline double numberRead() { return rx_pkt_cnt; } inline double numberWritten() { return 0; } @@ -280,6 +287,7 @@ std::vector tx_gains, rx_gains; std::vector tx_freqs, rx_freqs; + std::vector tx_paths, rx_paths; size_t tx_spp, rx_spp; bool started; @@ -295,6 +303,7 @@ void init_gains(); void set_channels(bool swap); void set_rates(); + bool set_antennas(); bool parse_dev_type(); bool flush_recv(size_t num_pkts); int check_rx_md_err(uhd::rx_metadata_t , ssize_t num_smpls); @@ -353,7 +362,9 @@ } uhd_device::uhd_device(size_t tx_sps, size_t rx_sps, - InterfaceType iface, size_t chans, double offset) + InterfaceType iface, size_t chans, double offset, + const std::vector& tx_paths, + const std::vector& rx_paths) : tx_gain_min(0.0), tx_gain_max(0.0), rx_gain_min(0.0), rx_gain_max(0.0), tx_spp(0), rx_spp(0), @@ -365,6 +376,8 @@ this->chans = chans; this->offset = offset; this->iface = iface; + this->tx_paths = tx_paths; + this->rx_paths = rx_paths; } uhd_device::~uhd_device() @@ -439,6 +452,33 @@ ts_offset = static_cast(desc.offset * rx_rate); LOG(INFO) << "Rates configured for " << desc.str; +} + +bool uhd_device::set_antennas() +{ + unsigned int i; + + for (i = 0; i < tx_paths.size(); i++) { + if (tx_paths[i] == "") + continue; + LOG(DEBUG) << "Configuring channel " << i << " with antenna " << tx_paths[i]; + if (!setTxAntenna(tx_paths[i], i)) { + LOG(ALERT) << "Failed configuring channel " << i << " with antenna " << tx_paths[i]; + return false; + } + } + + for (i = 0; i < rx_paths.size(); i++) { + if (rx_paths[i] == "") + continue; + LOG(DEBUG) << "Configuring channel " << i << " with antenna " << rx_paths[i]; + if (!setRxAntenna(rx_paths[i], i)) { + LOG(ALERT) << "Failed configuring channel " << i << " with antenna " << rx_paths[i]; + return false; + } + } + LOG(INFO) << "Antennas configured successfully"; + return true; } double uhd_device::setTxGain(double db, size_t chan) @@ -641,6 +681,11 @@ set_channels(swap_channels); } catch (const std::exception ) { LOG(ALERT) << "Channel setting failed - " << e.what(); + return -1; + } + + if (!set_antennas()) { + LOG(ALERT) << "UHD antenna setting failed"; return -1; } @@ -1165,6 +1210,78 @@ return rx_freqs[chan]; } +bool uhd_device::setRxAntenna(const std::string , size_t chan) +{ + std::vector avail; + if (chan >= rx_paths.size()) { + LOG(ALERT) << "Requested non-existent channel " << chan; + return false; + } + + avail = usrp_dev->get_rx_antennas(chan); + if (std::find(avail.begin(), avail.end(), ant) == avail.end()) { + LOG(ALERT) << "Requested non-existent Rx antenna " << ant << " on channel " << chan; + LOG(INFO) << "Available Rx antennas: "; + for (std::vector::const_iterator i = avail.begin(); i != avail.end(); ++i) +
[PATCH] osmo-trx[master]: Add support to set Rx/TxAntenna
Review at https://gerrit.osmocom.org/6238 Add support to set Rx/TxAntenna Change-Id: I1735e6ab05a05b0312d6d679b16ebd4a2260fa23 --- M Transceiver52M/UHDDevice.cpp M Transceiver52M/USRPDevice.cpp M Transceiver52M/USRPDevice.h M Transceiver52M/osmo-trx.cpp M Transceiver52M/radioDevice.h 5 files changed, 273 insertions(+), 57 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/38/6238/1 diff --git a/Transceiver52M/UHDDevice.cpp b/Transceiver52M/UHDDevice.cpp index 09317a9..1cf6cb9 100644 --- a/Transceiver52M/UHDDevice.cpp +++ b/Transceiver52M/UHDDevice.cpp @@ -1,5 +1,5 @@ /* - * Device support for Ettus Research UHD driver + * Device support for Ettus Research UHD driver * * Copyright 2010,2011 Free Software Foundation, Inc. * Copyright (C) 2015 Ettus Research LLC @@ -143,8 +143,8 @@ public: /** Sample buffer constructor @param len number of 32-bit samples the buffer should hold - @param rate sample clockrate - @param timestamp + @param rate sample clockrate + @param timestamp */ smpl_buf(size_t len, double rate); ~smpl_buf(); @@ -172,7 +172,7 @@ */ std::string str_status(size_t ts) const; - /** Formatted error string + /** Formatted error string @param code an error code @return a formatted error string */ @@ -208,7 +208,9 @@ class uhd_device : public RadioDevice { public: uhd_device(size_t tx_sps, size_t rx_sps, InterfaceType type, - size_t chans, double offset); + size_t chans, double offset, + const std::vector& tx_paths, + const std::vector& rx_paths); ~uhd_device(); int open(const std::string , int ref, bool swap_channels); @@ -248,6 +250,11 @@ double getRxFreq(size_t chan); double getRxFreq(); + bool setRxAntenna(const std::string , size_t chan); + std::string getRxAntenna(size_t chan); + bool setTxAntenna(const std::string , size_t chan); + std::string getTxAntenna(size_t chan); + inline double getSampleRate() { return tx_rate; } inline double numberRead() { return rx_pkt_cnt; } inline double numberWritten() { return 0; } @@ -280,6 +287,7 @@ std::vector tx_gains, rx_gains; std::vector tx_freqs, rx_freqs; + std::vector tx_paths, rx_paths; size_t tx_spp, rx_spp; bool started; @@ -295,6 +303,7 @@ void init_gains(); void set_channels(bool swap); void set_rates(); + bool set_antennas(); bool parse_dev_type(); bool flush_recv(size_t num_pkts); int check_rx_md_err(uhd::rx_metadata_t , ssize_t num_smpls); @@ -353,7 +362,9 @@ } uhd_device::uhd_device(size_t tx_sps, size_t rx_sps, - InterfaceType iface, size_t chans, double offset) + InterfaceType iface, size_t chans, double offset, + const std::vector& tx_paths, + const std::vector& rx_paths) : tx_gain_min(0.0), tx_gain_max(0.0), rx_gain_min(0.0), rx_gain_max(0.0), tx_spp(0), rx_spp(0), @@ -365,6 +376,8 @@ this->chans = chans; this->offset = offset; this->iface = iface; + this->tx_paths = tx_paths; + this->rx_paths = rx_paths; } uhd_device::~uhd_device() @@ -439,6 +452,33 @@ ts_offset = static_cast(desc.offset * rx_rate); LOG(INFO) << "Rates configured for " << desc.str; +} + +bool uhd_device::set_antennas() +{ + unsigned int i; + + for (i = 0; i < tx_paths.size(); i++) { + if (tx_paths[i] == "") + continue; + LOG(DEBUG) << "Configuring channel " << i << " with antenna " << tx_paths[i]; + if (!setTxAntenna(tx_paths[i], i)) { + LOG(ALERT) << "Failed configuring channel " << i << " with antenna " << tx_paths[i]; + return false; + } + } + + for (i = 0; i < rx_paths.size(); i++) { + if (rx_paths[i] == "") + continue; + LOG(DEBUG) << "Configuring channel " << i << " with antenna " << tx_paths[i]; + if (!setRxAntenna(rx_paths[i], i)) { + LOG(ALERT) << "Failed configuring channel " << i << " with antenna " << rx_paths[i]; + return false; + } + } + LOG(INFO) << "Antennas configured successfully"; + return true; } double uhd_device::setTxGain(double db, size_t chan) @@ -644,6 +684,11 @@ return -1; } + if (!set_antennas()) { + LOG(ALERT) << "UHD antenna setting failed"; + return -1; + } + tx_freqs.resize(chans); rx_freqs.resize(chans); tx_gains.resize(chans); @@ -705,7 +750,7 @@