Change in osmo-trx[master]: radioDevice: better encapsulation in base class

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Wed Jun 13 21:33:36 UTC 2018


Harald Welte has uploaded this change for review. ( https://gerrit.osmocom.org/9622


Change subject: radioDevice: better encapsulation in base class
......................................................................

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
---
M Transceiver52M/device/lms/LMSDevice.cpp
M Transceiver52M/device/lms/LMSDevice.h
M Transceiver52M/device/radioDevice.h
M Transceiver52M/device/uhd/UHDDevice.cpp
M Transceiver52M/device/usrp1/USRPDevice.cpp
M Transceiver52M/device/usrp1/USRPDevice.h
6 files changed, 37 insertions(+), 32 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/22/9622/1

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 @@
 #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 @@
 }
 
 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..7d8d44b 100644
--- a/Transceiver52M/device/lms/LMSDevice.h
+++ b/Transceiver52M/device/lms/LMSDevice.h
@@ -65,7 +65,7 @@
 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..806ee8a 100644
--- a/Transceiver52M/device/radioDevice.h
+++ b/Transceiver52M/device/radioDevice.h
@@ -58,6 +58,13 @@
   /** Initialize the USRP */
   virtual int open(const std::string &args, int ref, bool swap_channels)=0;
 
+  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)
+	{ }
+
   virtual ~RadioDevice() { }
 
   /** Start the USRP */
@@ -164,8 +171,12 @@
   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;
   bool set_antennas() {
 	unsigned int i;
 
diff --git a/Transceiver52M/device/uhd/UHDDevice.cpp b/Transceiver52M/device/uhd/UHDDevice.cpp
index ddcad3a..e8cec68 100644
--- a/Transceiver52M/device/uhd/UHDDevice.cpp
+++ b/Transceiver52M/device/uhd/UHDDevice.cpp
@@ -287,7 +287,6 @@
 
 	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 +316,6 @@
 	bool set_freq(double freq, size_t chan, bool tx);
 
 	Thread *async_event_thrd;
-	InterfaceType iface;
 	Mutex tune_lock;
 };
 
@@ -364,22 +362,16 @@
 }
 
 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 +1049,8 @@
 	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 +1062,10 @@
 		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 +1548,9 @@
 }
 
 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 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 @@
 #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 @@
  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);

-- 
To view, visit https://gerrit.osmocom.org/9622
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib885675a7612a392aa7f75fca81269ddcff2f6ab
Gerrit-Change-Number: 9622
Gerrit-PatchSet: 1
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180613/0fa43a34/attachment.htm>


More information about the gerrit-log mailing list