transceiver: make the transmit drive loop bus dependent

With the introduction of the B100, there is USB support
using UHD devices. The characteristics of the trasmit
side burst submissions are more reflective of the bus
type than the device or driver.

Use a fixed latency interval for network devices and the
adaptive underrun approach for USB devices - regardless
of driver or device type.

The GPMC based transport on the E100 appears unaffected
by either latency scheme, which defaults to network.

Signed-off-by: Thomas Tsou <ttsou@vt.edu>

git-svn-id: http://wush.net/svn/range/software/public/openbts/trunk@2677 19bc5d8c-e614-43d4-8b26-e1612bc8e597
diff --git a/Transceiver52M/Transceiver.cpp b/Transceiver52M/Transceiver.cpp
index 20c6aad..d152b2d 100644
--- a/Transceiver52M/Transceiver.cpp
+++ b/Transceiver52M/Transceiver.cpp
@@ -714,27 +714,27 @@
     while (radioClock->get() + mTransmitLatency > mTransmitDeadlineClock) {
       // if underrun, then we're not providing bursts to radio/USRP fast
       //   enough.  Need to increase latency by one GSM frame.
-#ifndef USE_UHD
-      if (mRadioInterface->isUnderrun()) {
-        // only do latency update every 10 frames, so we don't over update
-	if (radioClock->get() > mLatencyUpdateTime + GSM::Time(10,0)) {
-	  mTransmitLatency = mTransmitLatency + GSM::Time(1,0);
-	  LOG(INFO) << "new latency: " << mTransmitLatency;
-	  mLatencyUpdateTime = radioClock->get();
-	}
+      if (mRadioInterface->getBus() == RadioDevice::USB) {
+        if (mRadioInterface->isUnderrun()) {
+          // only do latency update every 10 frames, so we don't over update
+          if (radioClock->get() > mLatencyUpdateTime + GSM::Time(10,0)) {
+            mTransmitLatency = mTransmitLatency + GSM::Time(1,0);
+            LOG(INFO) << "new latency: " << mTransmitLatency;
+            mLatencyUpdateTime = radioClock->get();
+          }
+        }
+        else {
+          // if underrun hasn't occurred in the last sec (216 frames) drop
+          //    transmit latency by a timeslot
+          if (mTransmitLatency > GSM::Time(1,1)) {
+              if (radioClock->get() > mLatencyUpdateTime + GSM::Time(216,0)) {
+              mTransmitLatency.decTN();
+              LOG(INFO) << "reduced latency: " << mTransmitLatency;
+              mLatencyUpdateTime = radioClock->get();
+            }
+          }
+        }
       }
-      else {
-        // if underrun hasn't occurred in the last sec (216 frames) drop
-        //    transmit latency by a timeslot
-	if (mTransmitLatency > GSM::Time(1,1)) {
-            if (radioClock->get() > mLatencyUpdateTime + GSM::Time(216,0)) {
-	    mTransmitLatency.decTN();
-	    LOG(INFO) << "reduced latency: " << mTransmitLatency;
-	    mLatencyUpdateTime = radioClock->get();
-	  }
-	}
-      }
-#endif
       // time to push burst to transmit FIFO
       pushRadioVector(mTransmitDeadlineClock);
       mTransmitDeadlineClock.incTN();
diff --git a/Transceiver52M/UHDDevice.cpp b/Transceiver52M/UHDDevice.cpp
index 261eabc..e72fcfe 100644
--- a/Transceiver52M/UHDDevice.cpp
+++ b/Transceiver52M/UHDDevice.cpp
@@ -22,6 +22,7 @@
 #include "radioDevice.h"
 #include "Threads.h"
 #include "Logger.h"
+#include <uhd/property_tree.hpp>
 #include <uhd/usrp/single_usrp.hpp>
 #include <uhd/utils/thread_priority.hpp>
 #include <uhd/utils/msg.hpp>
@@ -154,6 +155,7 @@
 	bool stop();
 	void restart(uhd::time_spec_t ts);
 	void setPriority();
+	enum busType getBus() { return bus; }
 
 	int readSamples(short *buf, int len, bool *overrun, 
 			TIMESTAMP timestamp, bool *underrun, unsigned *RSSI);
@@ -201,6 +203,7 @@
 
 private:
 	uhd::usrp::single_usrp::sptr usrp_dev;
+	enum busType bus;
 
 	double desired_smpl_rt, actual_smpl_rt;
 
@@ -373,22 +376,40 @@
 
 bool uhd_device::open()
 {
-	LOG(INFO) << "creating USRP device...";
+	std::string dev_str;
+	uhd::property_tree::sptr prop_tree;
 
 	// Register msg handler
 	uhd::msg::register_handler(&uhd_msg_handler);
 
 	// Allow all UHD devices
+	LOG(INFO) << "Creating transceiver with first found UHD device";
 	uhd::device_addr_t dev_addr("");
 	try {
 		usrp_dev = uhd::usrp::single_usrp::make(dev_addr);
-	}
-	
-	catch(...) {
-		LOG(ERROR) << "USRP make failed";
+	} catch(...) {
+		LOG(ERROR) << "UHD make failed";
 		return false;
 	}
 
+	// Set the device name and bus type 
+	dev_str = usrp_dev->get_mboard_name();
+	LOG(NOTICE) << "Found " << dev_str;
+
+	prop_tree = usrp_dev->get_device()->get_tree();
+	dev_str = prop_tree->access<std::string>("/name").get();
+
+	size_t res1 = dev_str.find("B100");
+	size_t res2 = dev_str.find("B-Series");
+
+	if ((res1 != std::string::npos) || (res2 != std::string::npos)) {
+		bus = USB;
+		LOG(NOTICE) << "Using USB bus for " << dev_str;
+	} else {
+		bus = NET;
+		LOG(NOTICE) << "Using network bus for " << dev_str;
+	}
+
 	// Number of samples per over-the-wire packet
 	tx_spp = usrp_dev->get_device()->get_max_send_samps_per_packet();
 	rx_spp = usrp_dev->get_device()->get_max_recv_samps_per_packet();
diff --git a/Transceiver52M/USRPDevice.h b/Transceiver52M/USRPDevice.h
index d35ca25..700f1ca 100644
--- a/Transceiver52M/USRPDevice.h
+++ b/Transceiver52M/USRPDevice.h
@@ -126,6 +126,9 @@
   /** Set priority not supported */
   void setPriority() { return; }
 
+  /** Only USB bus supported */
+  busType getBus() { return USB; }
+
   /**
 	Read samples from the USRP.
 	@param buf preallocated buf to contain read result
diff --git a/Transceiver52M/radioDevice.h b/Transceiver52M/radioDevice.h
index f10da3e..47012a1 100644
--- a/Transceiver52M/radioDevice.h
+++ b/Transceiver52M/radioDevice.h
@@ -27,6 +27,9 @@
 class RadioDevice {
 
   public:
+  /* Available transport bus types */
+  enum busType { USB, NET };
+
   static RadioDevice *make(double desiredSampleRate, bool skipRx = false);
 
   /** Initialize the USRP */
@@ -38,6 +41,9 @@
   /** Stop the USRP */
   virtual bool stop()=0;
 
+  /** Get the bus type */
+  virtual enum busType getBus()=0;
+
   /** Enable thread priority */
   virtual void setPriority()=0;
 
diff --git a/Transceiver52M/radioInterface.h b/Transceiver52M/radioInterface.h
index 31716b3..cac20de 100644
--- a/Transceiver52M/radioInterface.h
+++ b/Transceiver52M/radioInterface.h
@@ -138,6 +138,9 @@
   /** set thread priority on current thread */
   void setPriority() { mRadio->setPriority(); }
 
+  /** get transport bus type of attached device */ 
+  enum RadioDevice::busType getBus() { return mRadio->getBus(); }
+
 protected:
 
   /** drive synchronization of Tx/Rx of USRP */