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
This commit is contained in:
parent
ce70ba529c
commit
61707e8b23
|
@ -40,17 +40,14 @@ constexpr double LMSDevice::masterClockRate;
|
||||||
#define LMS_MIN_BW_SUPPORTED 2.5e6 /* 2.5mHz, minimum supported by LMS */
|
#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)
|
#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>& tx_paths,
|
||||||
const std::vector<std::string>& rx_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...";
|
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_rx.resize(chans);
|
||||||
m_lms_stream_tx.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,
|
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 > &tx_paths,
|
||||||
const std::vector < std::string > &rx_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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ private:
|
||||||
std::vector<uint32_t> m_last_tx_underruns;
|
std::vector<uint32_t> m_last_tx_underruns;
|
||||||
std::vector<uint32_t> m_last_tx_overruns;
|
std::vector<uint32_t> m_last_tx_overruns;
|
||||||
|
|
||||||
size_t chans;
|
|
||||||
double actualSampleRate; ///< the actual USRP sampling rate
|
double actualSampleRate; ///< the actual USRP sampling rate
|
||||||
|
|
||||||
unsigned long long samplesRead; ///< number of samples read from LMS
|
unsigned long long samplesRead; ///< number of samples read from LMS
|
||||||
|
@ -65,7 +64,7 @@ private:
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** Object constructor */
|
/** 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>& tx_paths,
|
||||||
const std::vector<std::string>& rx_paths);
|
const std::vector<std::string>& rx_paths);
|
||||||
|
|
||||||
|
|
|
@ -164,8 +164,20 @@ class RadioDevice {
|
||||||
virtual double numberRead()=0;
|
virtual double numberRead()=0;
|
||||||
virtual double numberWritten()=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;
|
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() {
|
bool set_antennas() {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
|
|
|
@ -282,12 +282,10 @@ private:
|
||||||
enum TxWindowType tx_window;
|
enum TxWindowType tx_window;
|
||||||
enum uhd_dev_type dev_type;
|
enum uhd_dev_type dev_type;
|
||||||
|
|
||||||
size_t rx_sps, chans;
|
|
||||||
double tx_rate, rx_rate;
|
double tx_rate, rx_rate;
|
||||||
|
|
||||||
double tx_gain_min, tx_gain_max;
|
double tx_gain_min, tx_gain_max;
|
||||||
double rx_gain_min, rx_gain_max;
|
double rx_gain_min, rx_gain_max;
|
||||||
double offset;
|
|
||||||
|
|
||||||
std::vector<double> tx_gains, rx_gains;
|
std::vector<double> tx_gains, rx_gains;
|
||||||
std::vector<double> tx_freqs, rx_freqs;
|
std::vector<double> tx_freqs, rx_freqs;
|
||||||
|
@ -317,7 +315,6 @@ private:
|
||||||
bool set_freq(double freq, size_t chan, bool tx);
|
bool set_freq(double freq, size_t chan, bool tx);
|
||||||
|
|
||||||
Thread *async_event_thrd;
|
Thread *async_event_thrd;
|
||||||
InterfaceType iface;
|
|
||||||
Mutex tune_lock;
|
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,
|
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>& tx_paths,
|
||||||
const std::vector<std::string>& rx_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),
|
rx_gain_min(0.0), rx_gain_max(0.0),
|
||||||
tx_spp(0), rx_spp(0),
|
tx_spp(0), rx_spp(0),
|
||||||
started(false), aligned(false), rx_pkt_cnt(0), drop_cnt(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)
|
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()
|
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);
|
uhd::tune_request_t treq(freq);
|
||||||
|
|
||||||
if (dev_type == UMTRX) {
|
if (dev_type == UMTRX) {
|
||||||
if (offset != 0.0)
|
if (lo_offset != 0.0)
|
||||||
return uhd::tune_request_t(freq, offset);
|
return uhd::tune_request_t(freq, lo_offset);
|
||||||
|
|
||||||
// Don't use DSP tuning, because LMS6002D PLL steps are small enough.
|
// 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
|
// 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;
|
treq.dsp_freq = 0.0;
|
||||||
return treq;
|
return treq;
|
||||||
} else if (chans == 1) {
|
} else if (chans == 1) {
|
||||||
if (offset == 0.0)
|
if (lo_offset == 0.0)
|
||||||
return treq;
|
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)) {
|
} else if ((dev_type != B210) || (chans > 2) || (chan > 1)) {
|
||||||
LOG(ALERT) << chans << " channels unsupported";
|
LOG(ALERT) << chans << " channels unsupported";
|
||||||
return treq;
|
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,
|
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>& tx_paths,
|
||||||
const std::vector<std::string>& rx_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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,11 +58,14 @@ const dboardConfigType dboardConfig = TXA_RXB;
|
||||||
|
|
||||||
const double USRPDevice::masterClockRate = 52.0e6;
|
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...";
|
LOG(INFO) << "creating USRP device...";
|
||||||
|
|
||||||
this->tx_sps = tx_sps;
|
|
||||||
decimRate = (unsigned int) round(masterClockRate/((GSMRATE) * (double) tx_sps));
|
decimRate = (unsigned int) round(masterClockRate/((GSMRATE) * (double) tx_sps));
|
||||||
actualSampleRate = masterClockRate/decimRate;
|
actualSampleRate = masterClockRate/decimRate;
|
||||||
rxGain = 0;
|
rxGain = 0;
|
||||||
|
@ -648,9 +651,9 @@ bool USRPDevice::setRxFreq(double wFreq) { return true;};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RadioDevice *RadioDevice::make(size_t tx_sps, size_t rx_sps,
|
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>& tx_paths,
|
||||||
const std::vector<std::string>& rx_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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,9 @@ private:
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** Object constructor */
|
/** 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 */
|
/** Instantiate the USRP */
|
||||||
int open(const std::string &, int, bool);
|
int open(const std::string &, int, bool);
|
||||||
|
|
Loading…
Reference in New Issue