aboutsummaryrefslogtreecommitdiffstats
path: root/Transceiver52M
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2018-06-13 23:21:57 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2018-06-14 12:38:04 +0200
commit61707e8b23564e3a3b1123f231e428cae0759cc7 (patch)
tree82e3a5dfe9ca71e069979ca6a8f9bfe32d7b3cfe /Transceiver52M
parentce70ba529cfd5c32e5c9f2652affb36d6a8d1b09 (diff)
radioDevice: better encapsulation in base class
It's not good style to have the derived classes initialize members inherited from the base class using "this->foo = bar". Rather, let's make the base class have a constructor, and call that constructor to initialize the members of the base class. While doing this * rename 'offset' to 'lo_offset' to avoid confusion with timestamp offset * move 'InterfaceType' into the base class * move 'chans' into the base class * move 'rx_sps' into the base class * mark base class members as 'protected' Change-Id: Ib885675a7612a392aa7f75fca81269ddcff2f6ab
Diffstat (limited to 'Transceiver52M')
-rw-r--r--Transceiver52M/device/lms/LMSDevice.cpp13
-rw-r--r--Transceiver52M/device/lms/LMSDevice.h3
-rw-r--r--Transceiver52M/device/radioDevice.h14
-rw-r--r--Transceiver52M/device/uhd/UHDDevice.cpp27
-rw-r--r--Transceiver52M/device/usrp1/USRPDevice.cpp11
-rw-r--r--Transceiver52M/device/usrp1/USRPDevice.h4
6 files changed, 38 insertions, 34 deletions
diff --git a/Transceiver52M/device/lms/LMSDevice.cpp b/Transceiver52M/device/lms/LMSDevice.cpp
index 68d4b97..c4d5f96 100644
--- a/Transceiver52M/device/lms/LMSDevice.cpp
+++ b/Transceiver52M/device/lms/LMSDevice.cpp
@@ -40,17 +40,14 @@ constexpr double LMSDevice::masterClockRate;
#define LMS_MIN_BW_SUPPORTED 2.5e6 /* 2.5mHz, minimum supported by LMS */
#define LMS_CALIBRATE_BW_HZ OSMO_MAX(GSM_CARRIER_BW, LMS_MIN_BW_SUPPORTED)
-LMSDevice::LMSDevice(size_t tx_sps, size_t chans,
+LMSDevice::LMSDevice(size_t tx_sps, size_t rx_sps, InterfaceType iface, size_t chans, double lo_offset,
const std::vector<std::string>& tx_paths,
const std::vector<std::string>& rx_paths):
- m_lms_dev(NULL), chans(chans)
+ RadioDevice(tx_sps, rx_sps, iface, chans, lo_offset, tx_paths, rx_paths),
+ m_lms_dev(NULL)
{
LOG(INFO) << "creating LMS device...";
- this->tx_sps = tx_sps;
- this->tx_paths = tx_paths;
- this->rx_paths = rx_paths;
-
m_lms_stream_rx.resize(chans);
m_lms_stream_tx.resize(chans);
@@ -624,9 +621,9 @@ bool LMSDevice::setRxFreq(double wFreq, size_t chan)
}
RadioDevice *RadioDevice::make(size_t tx_sps, size_t rx_sps,
- InterfaceType iface, size_t chans, double offset,
+ InterfaceType iface, size_t chans, double lo_offset,
const std::vector < std::string > &tx_paths,
const std::vector < std::string > &rx_paths)
{
- return new LMSDevice(tx_sps, chans, tx_paths, rx_paths);
+ return new LMSDevice(tx_sps, rx_sps, iface, chans, lo_offset, tx_paths, rx_paths);
}
diff --git a/Transceiver52M/device/lms/LMSDevice.h b/Transceiver52M/device/lms/LMSDevice.h
index 0fe4c15..349efbb 100644
--- a/Transceiver52M/device/lms/LMSDevice.h
+++ b/Transceiver52M/device/lms/LMSDevice.h
@@ -46,7 +46,6 @@ private:
std::vector<uint32_t> m_last_tx_underruns;
std::vector<uint32_t> m_last_tx_overruns;
- size_t chans;
double actualSampleRate; ///< the actual USRP sampling rate
unsigned long long samplesRead; ///< number of samples read from LMS
@@ -65,7 +64,7 @@ private:
public:
/** Object constructor */
- LMSDevice(size_t tx_sps, size_t chans,
+ LMSDevice(size_t tx_sps, size_t rx_sps, InterfaceType iface, size_t chans, double lo_offset,
const std::vector<std::string>& tx_paths,
const std::vector<std::string>& rx_paths);
diff --git a/Transceiver52M/device/radioDevice.h b/Transceiver52M/device/radioDevice.h
index a9328ec..5d001fb 100644
--- a/Transceiver52M/device/radioDevice.h
+++ b/Transceiver52M/device/radioDevice.h
@@ -164,8 +164,20 @@ class RadioDevice {
virtual double numberRead()=0;
virtual double numberWritten()=0;
+ protected:
+ size_t tx_sps, rx_sps;
+ InterfaceType iface;
+ size_t chans;
+ double lo_offset;
std::vector<std::string> tx_paths, rx_paths;
- size_t tx_sps;
+
+ RadioDevice(size_t tx_sps, size_t rx_sps, InterfaceType type, size_t chans, double offset,
+ const std::vector<std::string>& tx_paths,
+ const std::vector<std::string>& rx_paths):
+ tx_sps(tx_sps), rx_sps(rx_sps), iface(type), chans(chans), lo_offset(offset),
+ tx_paths(tx_paths), rx_paths(rx_paths)
+ { }
+
bool set_antennas() {
unsigned int i;
diff --git a/Transceiver52M/device/uhd/UHDDevice.cpp b/Transceiver52M/device/uhd/UHDDevice.cpp
index ddcad3a..4af8f87 100644
--- a/Transceiver52M/device/uhd/UHDDevice.cpp
+++ b/Transceiver52M/device/uhd/UHDDevice.cpp
@@ -282,12 +282,10 @@ private:
enum TxWindowType tx_window;
enum uhd_dev_type dev_type;
- size_t rx_sps, chans;
double tx_rate, rx_rate;
double tx_gain_min, tx_gain_max;
double rx_gain_min, rx_gain_max;
- double offset;
std::vector<double> tx_gains, rx_gains;
std::vector<double> tx_freqs, rx_freqs;
@@ -317,7 +315,6 @@ private:
bool set_freq(double freq, size_t chan, bool tx);
Thread *async_event_thrd;
- InterfaceType iface;
Mutex tune_lock;
};
@@ -364,22 +361,16 @@ static void thread_enable_cancel(bool cancel)
}
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 lo_offset,
const std::vector<std::string>& tx_paths,
const std::vector<std::string>& rx_paths)
- : tx_gain_min(0.0), tx_gain_max(0.0),
+ : RadioDevice(tx_sps, rx_sps, iface, chans, lo_offset, tx_paths, 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),
started(false), aligned(false), rx_pkt_cnt(0), drop_cnt(0),
prev_ts(0,0), ts_initial(0), ts_offset(0), async_event_thrd(NULL)
{
- this->tx_sps = tx_sps;
- this->rx_sps = rx_sps;
- this->chans = chans;
- this->offset = offset;
- this->iface = iface;
- this->tx_paths = tx_paths;
- this->rx_paths = rx_paths;
}
uhd_device::~uhd_device()
@@ -1057,8 +1048,8 @@ uhd::tune_request_t uhd_device::select_freq(double freq, size_t chan, bool tx)
uhd::tune_request_t treq(freq);
if (dev_type == UMTRX) {
- if (offset != 0.0)
- return uhd::tune_request_t(freq, offset);
+ if (lo_offset != 0.0)
+ return uhd::tune_request_t(freq, lo_offset);
// Don't use DSP tuning, because LMS6002D PLL steps are small enough.
// We end up with DSP tuning just for 2-3Hz, which is meaningless and
@@ -1070,10 +1061,10 @@ uhd::tune_request_t uhd_device::select_freq(double freq, size_t chan, bool tx)
treq.dsp_freq = 0.0;
return treq;
} else if (chans == 1) {
- if (offset == 0.0)
+ if (lo_offset == 0.0)
return treq;
- return uhd::tune_request_t(freq, offset);
+ return uhd::tune_request_t(freq, lo_offset);
} else if ((dev_type != B210) || (chans > 2) || (chan > 1)) {
LOG(ALERT) << chans << " channels unsupported";
return treq;
@@ -1556,9 +1547,9 @@ std::string smpl_buf::str_code(ssize_t code)
}
RadioDevice *RadioDevice::make(size_t tx_sps, size_t rx_sps,
- InterfaceType iface, size_t chans, double offset,
+ InterfaceType iface, size_t chans, double lo_offset,
const std::vector<std::string>& tx_paths,
const std::vector<std::string>& rx_paths)
{
- return new uhd_device(tx_sps, rx_sps, iface, chans, offset, tx_paths, rx_paths);
+ return new uhd_device(tx_sps, rx_sps, iface, chans, lo_offset, tx_paths, rx_paths);
}
diff --git a/Transceiver52M/device/usrp1/USRPDevice.cpp b/Transceiver52M/device/usrp1/USRPDevice.cpp
index 07ba1c9..7a31c97 100644
--- a/Transceiver52M/device/usrp1/USRPDevice.cpp
+++ b/Transceiver52M/device/usrp1/USRPDevice.cpp
@@ -58,11 +58,14 @@ const dboardConfigType dboardConfig = TXA_RXB;
const double USRPDevice::masterClockRate = 52.0e6;
-USRPDevice::USRPDevice(size_t tx_sps)
+USRPDevice::USRPDevice(size_t tx_sps, size_t rx_sps, InterfaceType iface,
+ size_t chans, double lo_offset,
+ const std::vector<std::string>& tx_paths,
+ const std::vector<std::string>& rx_paths):
+ RadioDevice(tx_sps, rx_sps, iface, chans, lo_offset, tx_paths, rx_paths)
{
LOG(INFO) << "creating USRP device...";
- this->tx_sps = tx_sps;
decimRate = (unsigned int) round(masterClockRate/((GSMRATE) * (double) tx_sps));
actualSampleRate = masterClockRate/decimRate;
rxGain = 0;
@@ -648,9 +651,9 @@ bool USRPDevice::setRxFreq(double wFreq) { return true;};
#endif
RadioDevice *RadioDevice::make(size_t tx_sps, size_t rx_sps,
- InterfaceType iface, size_t chans, double offset,
+ InterfaceType iface, size_t chans, double lo_offset,
const std::vector<std::string>& tx_paths,
const std::vector<std::string>& rx_paths)
{
- return new USRPDevice(tx_sps);
+ return new USRPDevice(tx_sps, rx_sps, iface, chans, lo_offset, tx_paths, rx_paths);
}
diff --git a/Transceiver52M/device/usrp1/USRPDevice.h b/Transceiver52M/device/usrp1/USRPDevice.h
index ff5b273..451b5a9 100644
--- a/Transceiver52M/device/usrp1/USRPDevice.h
+++ b/Transceiver52M/device/usrp1/USRPDevice.h
@@ -95,7 +95,9 @@ private:
public:
/** Object constructor */
- USRPDevice(size_t tx_sps);
+ USRPDevice(size_t tx_sps, size_t rx_sps, InterfaceType iface, size_t chans, double lo_offset,
+ const std::vector<std::string>& tx_paths,
+ const std::vector<std::string>& rx_paths);
/** Instantiate the USRP */
int open(const std::string &, int, bool);