Index: /ossiedev/branches/june/trunk/platform/USRP_UHD/xml/USRP_UHD.scd.xml
===================================================================
--- /ossiedev/branches/june/trunk/platform/USRP_UHD/xml/USRP_UHD.scd.xml	(revision 10608)
+++ /ossiedev/branches/june/trunk/platform/USRP_UHD/xml/USRP_UHD.scd.xml	(revision 11094)
@@ -17,17 +17,20 @@
         <supportsinterface repid="IDL:CF/TestableObject:1.0" supportsname="TestableObject" />
         <ports>
-            <provides repid="IDL:standardInterfaces/TX_Control:1.0" providesname="U2_TX_Control">
+            <provides repid="IDL:standardInterfaces/TX_Control:1.0" providesname="UHD_TX_Control">
                 <porttype type="control" />
             </provides>
-            <provides repid="IDL:standardInterfaces/RX_Control:1.0" providesname="U2_RX_Control">
+            <provides repid="IDL:standardInterfaces/RX_Control:1.0" providesname="UHD_RX_Control">
                 <porttype type="control" />
             </provides>
-            <provides repid="IDL:standardInterfaces/complexShort:1.0" providesname="U2_TX_Data">
+            <provides repid="IDL:standardInterfaces/complexShort:1.0" providesname="UHD_TX_Data_1">
                 <porttype type="data" />
             </provides>
-            <uses repid="IDL:standardInterfaces/complexShort:1.0" usesname="U2_RX_Data_1">
+            <provides repid="IDL:standardInterfaces/complexShort:1.0" providesname="UHD_TX_Data_2">
+                <porttype type="data" />
+            </provides>            
+            <uses repid="IDL:standardInterfaces/complexShort:1.0" usesname="UHD_RX_Data_1">
                 <porttype type="data" />
             </uses>
-            <uses repid="IDL:standardInterfaces/complexShort:1.0" usesname="U2_RX_Data_2">
+            <uses repid="IDL:standardInterfaces/complexShort:1.0" usesname="UHD_RX_Data_2">
                 <porttype type="data" />
             </uses>
@@ -48,6 +51,6 @@
             <inheritsinterface repid="IDL:CF/TestableObject:1.0" />
         </interface>
-        <interface repid="IDL:standardInterfaces/TX_Control:1.0" name="U2_TX_Control" />
-        <interface repid="IDL:standardInterfaces/RX_Control:1.0" name="U2_RX_Control" />
+        <interface repid="IDL:standardInterfaces/TX_Control:1.0" name="UHD_TX_Control" />
+        <interface repid="IDL:standardInterfaces/RX_Control:1.0" name="UHD_RX_Control" />
     </interfaces>
 </softwarecomponent>
Index: /ossiedev/branches/june/trunk/platform/USRP_UHD/src/USRP_UHD.h
===================================================================
--- /ossiedev/branches/june/trunk/platform/USRP_UHD/src/USRP_UHD.h	(revision 11034)
+++ /ossiedev/branches/june/trunk/platform/USRP_UHD/src/USRP_UHD.h	(revision 11094)
@@ -30,4 +30,10 @@
 
 #include <uhd/usrp/multi_usrp.hpp>
+#include <uhd/property_tree.hpp>
+#include <uhd/usrp/dboard_id.hpp>
+#include <uhd/usrp/mboard_eeprom.hpp>
+#include <uhd/usrp/subdev_spec.hpp>
+#include <uhd/usrp/dboard_eeprom.hpp>
+#include <uhd/usrp/dboard_manager.hpp>
 
 #include "ossie/cf.h"
@@ -43,4 +49,6 @@
 #define ADC_RATE 100e6
 #define USRP_UHD_MAX_TX_SAMPLES 4192
+#define MAX_TX_CHANNEL	2
+#define MAX_RX_CHANNEL	2
 
 // Definitions for provides ports
@@ -173,18 +181,19 @@
     USRP_UHD_TX_Control_i* tx_control_port;
 
-    standardInterfaces_i::complexShort_u* rx_data_1_port;
-    standardInterfaces_i::complexShort_u* rx_data_2_port;
-
-    standardInterfaces_i::complexShort_p* tx_data_port;
+    standardInterfaces_i::complexShort_u* rx_data_ports[MAX_RX_CHANNEL];
+    standardInterfaces_i::complexShort_p* tx_data_ports[MAX_TX_CHANNEL];
 
 // usrp_uhd variables
     uhd::usrp::multi_usrp::sptr sdev;
     uhd::device::sptr dev;
-    std::vector<std::complex<short> > rx_buff;
+
+
     omni_thread *rx_thread;
     omni_thread *tx_thread;
 
+    void rx_error_helper(uhd::rx_metadata_t::error_code_t error);
     void rx_data_process();
     void tx_data_process();
+    void probe_usrp();
 
     long set_rx_packet_count;
@@ -203,3 +212,10 @@
     bool full_duplex;	
     bool did_rx;	   
-};
+
+    size_t mb_count;
+    size_t db_count;
+    size_t tx_channels;
+    size_t rx_channels;
+
+
+};
Index: /ossiedev/branches/june/trunk/platform/USRP_UHD/src/port_impl.cpp
===================================================================
--- /ossiedev/branches/june/trunk/platform/USRP_UHD/src/port_impl.cpp	(revision 11039)
+++ /ossiedev/branches/june/trunk/platform/USRP_UHD/src/port_impl.cpp	(revision 11094)
@@ -34,77 +34,100 @@
 void USRP_UHD_TX_Control_i::set_number_of_channels(CORBA::ULong nchan)
 {
-    DEBUG(3, USRP_UHD, "Setting number of TX channels to " << nchan<< " is not supported");
-
+	omni_mutex_lock l(usrp_uhd->tx_control_access);
+    uhd::property_tree::sptr tree = usrp_uhd->dev->get_tree();
+	uhd::fs_path db_path, mb_path = "/mboards";
+
+	int assigned_channel = 0;
+	std::string subdev_spec;
+	for(int i=0;(i<usrp_uhd->mb_count)&&(assigned_channel<nchan);i++){
+		mb_path = "/mboards";
+		mb_path = mb_path / tree->list("/mboards")[i];
+
+		for(int j=0;(j<usrp_uhd->db_count)&&(assigned_channel<nchan);j++){
+			db_path = mb_path / "dboards" / tree->list( mb_path / "dboards")[j];
+			uhd::usrp::dboard_eeprom_t prom = tree->access<uhd::usrp::dboard_eeprom_t>(db_path / "tx_eeprom").get();
+			if (prom.id != uhd::usrp::dboard_id_t::none()){
+				subdev_spec = subdev_spec + tree->list( mb_path / "dboards")[j] + ":"
+						+ tree->list(db_path / "tx_frontends").at(0) + " ";
+				assigned_channel++;
+
+			}
+
+
+		}
+		DEBUG(3, USRP_UHD, "subdev of tx channel@MB"<<i<<" = "<<subdev_spec)
+		usrp_uhd->sdev->set_tx_subdev_spec(uhd::usrp::subdev_spec_t(subdev_spec),i);
+
+	}
+	usrp_uhd->tx_channels = usrp_uhd->sdev->get_tx_num_channels();
+	DEBUG(3, USRP_UHD, "# of Tx Channels Requested="<<nchan<<", Real="<<usrp_uhd->tx_channels)
+}
+
+void USRP_UHD_TX_Control_i::get_number_of_channels(CORBA::ULong &num)
+{
 ///\TODO: Define if we need this interface. Number of channels is defined at transmit or receive
-
-//omni_mutex_lock l(usrp_uhd->tx_control_access);
-
-//usrp_uhd->usrp_uhd_ptr->set_nchannels(nchan);
-}
-
-void USRP_UHD_TX_Control_i::get_number_of_channels(CORBA::ULong &num)
-{
-///\TODO: Define if we need this interface. Number of channels is defined at transmit or receive
-    DEBUG(3, USRP_UHD, "Getting number of TX channels is not supported");
-//omni_mutex_lock l(usrp_uhd->tx_control_access);
-
-//num = usrp_uhd->usrp_uhd_ptr->nchannels();
+	omni_mutex_lock l(usrp_uhd->tx_control_access);
+	num = usrp_uhd->sdev->get_tx_num_channels();
+	DEBUG(3, USRP_UHD, "Tx get number of channels = "<<num)
 }
 
 void USRP_UHD_TX_Control_i::get_gain_range(CORBA::ULong channel, CORBA::Float &gmin, CORBA::Float &gmax, CORBA::Float &gstep)
 {
-    if (channel == 0) {
-        if (usrp_uhd->sdev) {
-            uhd::gain_range_t range = usrp_uhd->sdev->get_tx_gain_range();
-            // All values in range are in dB
-            gmin = range.start();
-            gmax = range.stop();
-            gstep = range.step();
-        }
-    } else {
-        return; ///\todo throw bad channel exception
-    }
+	omni_mutex_lock l(usrp_uhd->tx_control_access);
+	if (usrp_uhd->sdev) {
+		uhd::gain_range_t range = usrp_uhd->sdev->get_tx_gain_range(channel);
+		// All values in range are in dB
+		gmin = range.start();
+		gmax = range.stop();
+		gstep = range.step();
+		DEBUG(3, USRP_UHD, "Tx gain range = "<<range.to_pp_string())
+	}
+	else{
+
+	}
 }
 
 void USRP_UHD_TX_Control_i::set_gain(CORBA::ULong channel, CORBA::Float gain)
 {
+	omni_mutex_lock l(usrp_uhd->tx_control_access);
+
+	if (usrp_uhd->sdev) {
+		usrp_uhd->sdev->set_tx_gain(gain,channel);
+		DEBUG(3, USRP_UHD, "Tx set gain = "<<gain)
+	}
+	else {
+
+	}
+}
+
+void USRP_UHD_TX_Control_i::get_gain(CORBA::ULong channel, CORBA::Float &gain)
+{
     omni_mutex_lock l(usrp_uhd->tx_control_access);
-
-    if (channel == 0) {
-        if (usrp_uhd->sdev) {
-            usrp_uhd->sdev->set_tx_gain(gain);
-        }
-    } else {
-        return; ///\todo throw bad channel exception
-    }
-}
-
-void USRP_UHD_TX_Control_i::get_gain(CORBA::ULong channel, CORBA::Float &gain)
-{
-    omni_mutex_lock l(usrp_uhd->tx_control_access);
-    if (channel == 0) {
-        if (usrp_uhd->sdev) {
-            gain = usrp_uhd->sdev->get_tx_gain();
-        }
-    } else {
-        return; ///\todo throw bad channel exception
-    }
+    if (usrp_uhd->sdev) {
+		gain = usrp_uhd->sdev->get_tx_gain(channel);
+		DEBUG(3, USRP_UHD, "Tx get gain = "<<gain);
+    }
+    else{
+
+    }
+
 }
 
 void USRP_UHD_TX_Control_i::get_frequency_range(CORBA::ULong channel, CORBA::Float &fmin, CORBA::Float &fmax, CORBA::Float &fstep)
 {
-
-
-   if (channel == 0) {
-        if (usrp_uhd->sdev) {
-            uhd::freq_range_t range = usrp_uhd->sdev->get_tx_freq_range();
-            // All values in range are in dB
-            fmin = range.start();
-            fmax = range.stop();
-            fstep = 0.0; // There is no step value in uhd::freq_range
-        }
-    } else {
-        return; ///\todo throw bad channel exception
-    }
+	omni_mutex_lock l(usrp_uhd->tx_control_access);
+
+	if (usrp_uhd->sdev) {
+		uhd::freq_range_t range = usrp_uhd->sdev->get_tx_freq_range(channel);
+		// All values in range are in dB
+		fmin = range.start();
+		fmax = range.stop();
+		fstep = range.step();
+		DEBUG(3, USRP_UHD, "Tx Frequency range = "<<range.to_pp_string())
+
+	}
+	else{
+
+	}
             
 }
@@ -112,8 +135,8 @@
 void USRP_UHD_TX_Control_i::set_frequency(CORBA::ULong channel, CORBA::Float f)
 {
-    DEBUG(3, USRP_UHD, "In TX Control set frequency channel: " << channel << ", frequency: " << f);
-
-    if (channel == 0) {
-        uhd::tune_result_t result = usrp_uhd->sdev->set_tx_freq(f);
+	omni_mutex_lock l(usrp_uhd->tx_control_access);
+
+    if (usrp_uhd->sdev) {
+        uhd::tune_result_t result = usrp_uhd->sdev->set_tx_freq(f,channel);
 
         DEBUG(3, USRP_UHD, "USRP_UHD TX tune_result:" <<std::endl<<
@@ -123,6 +146,5 @@
               " \tActual_DSP_freq="   << result.actual_dsp_freq);
     } else {
-        DEBUG(3, USRP_UHD, "USRP_UHD TX set_frequency (invalid channel)");
-        return;
+
     }
 
@@ -131,7 +153,11 @@
 void USRP_UHD_TX_Control_i::get_frequency(CORBA::ULong channel, CORBA::Float &f)
 {
-	f = usrp_uhd->sdev->get_tx_freq();
-	DEBUG(3, USRP_UHD, "In TX Control get frequency channel: " << channel << ", frequency: " << f);
-
+	omni_mutex_lock l(usrp_uhd->tx_control_access);
+	if(usrp_uhd->sdev){
+		f = usrp_uhd->sdev->get_tx_freq(channel);
+	}
+	else{
+
+	}
 }
 
@@ -157,6 +183,6 @@
 {
 
-    DEBUG(3, USRP_UHD, "USRP_UHD TX setting " << values.length() << " values, value[0].id " << values[0].id)
-#if 0
+    DEBUG(3, USRP_UHD, "TX set_values: " << values.length() << " values, value[0].id " << values[0].id)
+
     for (unsigned int i =0; i < values.length(); ++i) {
         if (strcmp(values[i].id, "SET_MUX") == 0 ) {
@@ -169,18 +195,24 @@
             CORBA::ULong atx;
             values[i].value >>= atx;
-            DEBUG(3, USRP_UHD, "Set Auto TX/RX for side 1 to " << atx)
+            DEBUG(3, USRP_UHD, "Set Auto TX/RX for DB1 to " << atx)
             omni_mutex_lock l(usrp_uhd->tx_control_access);
-            if (usrp_uhd->tx_db0_control && usrp_uhd->rx_db0_control) {
-                if (atx) {
-                    usrp_uhd->tx_db0_control->set_auto_tr(true);
-                    usrp_uhd->rx_db0_control->set_auto_tr(true);
-                } else {
-                    usrp_uhd->tx_db0_control->set_auto_tr(false);
-                    usrp_uhd->rx_db0_control->set_auto_tr(false);
-                }
-            }
+			usrp_uhd->sdev->get_tx_dboard_iface(0)->set_pin_ctrl(uhd::usrp::dboard_iface::UNIT_TX,atx,0x0);
+			usrp_uhd->sdev->get_tx_dboard_iface(0)->set_pin_ctrl(uhd::usrp::dboard_iface::UNIT_RX,atx,0x0);
+			usrp_uhd->sdev->get_rx_dboard_iface(0)->set_pin_ctrl(uhd::usrp::dboard_iface::UNIT_TX,atx,0x0);
+			usrp_uhd->sdev->get_rx_dboard_iface(0)->set_pin_ctrl(uhd::usrp::dboard_iface::UNIT_RX,atx,0x0);
+
+        } else if (strcmp(values[i].id, "SET_AUTO_TR_2") == 0) {
+			CORBA::ULong atx;
+			values[i].value >>= atx;
+			DEBUG(3, USRP_UHD, "Set Auto TX/RX for DB2 to " << atx)
+			omni_mutex_lock l(usrp_uhd->tx_control_access);
+			usrp_uhd->sdev->get_tx_dboard_iface(1)->set_pin_ctrl(uhd::usrp::dboard_iface::UNIT_TX,atx,0x0);
+			usrp_uhd->sdev->get_tx_dboard_iface(1)->set_pin_ctrl(uhd::usrp::dboard_iface::UNIT_RX,atx,0x0);
+			usrp_uhd->sdev->get_rx_dboard_iface(1)->set_pin_ctrl(uhd::usrp::dboard_iface::UNIT_TX,atx,0x0);
+			usrp_uhd->sdev->get_rx_dboard_iface(1)->set_pin_ctrl(uhd::usrp::dboard_iface::UNIT_RX,atx,0x0);
+
         }
     }
-#endif
+
 }
 
@@ -189,19 +221,33 @@
     omni_mutex_lock l(usrp_uhd->tx_control_access);
     ///\TODO: rate matching in UHD works a little different. Review
-    double master_clock = usrp_uhd->sdev->get_master_clock_rate();
-    double request_da_rate = master_clock/(double)I;
-    usrp_uhd->sdev->set_tx_rate(request_da_rate,channel);
-    double real_da_rate = usrp_uhd->sdev->get_tx_rate(channel);
-    DEBUG(3, USRP_UHD, "Requested Tx sample rate ="<<request_da_rate<<", Real Tx sample rate ="<<real_da_rate)
+    if(usrp_uhd->sdev){
+		double master_clock = usrp_uhd->sdev->get_master_clock_rate();
+		double request_da_rate = master_clock/(double)I;
+		usrp_uhd->sdev->set_tx_rate(request_da_rate,channel);
+		double real_da_rate = usrp_uhd->sdev->get_tx_rate(channel);
+		DEBUG(3, USRP_UHD, "Requested Tx sample rate ="<<request_da_rate<<", Real Tx sample rate ="<<real_da_rate)
+    }
+    else{
+
+    }
 }
 
 void USRP_UHD_TX_Control_i::get_interpolation_range(CORBA::ULong channel, CORBA::ULong &imin, CORBA::ULong &imax, CORBA::ULong &istep)
 {
-	double master_clock = usrp_uhd->sdev->get_master_clock_rate();
-	uhd::meta_range_t tx_range = usrp_uhd->sdev->get_tx_rates(channel);
-    imax = master_clock/tx_range.start();
-    imin = master_clock/tx_range.stop();
-    istep = master_clock/tx_range.step();
-    DEBUG(3, USRP_UHD, "Interpolation min="<<imin<<", max="<<imax<<", step="<<istep)
+	omni_mutex_lock l(usrp_uhd->tx_control_access);
+	if(usrp_uhd->sdev){
+		double master_clock = usrp_uhd->sdev->get_master_clock_rate();
+		uhd::meta_range_t tx_range = usrp_uhd->sdev->get_tx_rates(channel);
+		imax = master_clock/tx_range.start();
+		imin = master_clock/tx_range.stop();
+		istep = master_clock*tx_range.step()/(tx_range.stop()*tx_range.start());
+		if(istep < 1)
+			istep = 1;
+		double step = master_clock*tx_range.step()/(tx_range.stop()*tx_range.start());
+		DEBUG(3, USRP_UHD, "Interpolation min="<<imin<<", max="<<imax<<", step="<<istep)
+	}
+	else{
+
+	}
 }
 
@@ -213,17 +259,39 @@
 void USRP_UHD_RX_Control_i::set_number_of_channels(CORBA::ULong nchan)
 {
-    DEBUG(1, USRP_UHD, "Request to set number of channels to " << nchan<<" not supported")
-
-//omni_mutex_lock l(usrp_uhd->rx_control_access);
-
-//usrp_uhd->usrp_uhd_ptr->set_nchannels(nchan);
+	omni_mutex_lock l(usrp_uhd->rx_control_access);
+    uhd::property_tree::sptr tree = usrp_uhd->dev->get_tree();
+	uhd::fs_path db_path, mb_path = "/mboards";
+
+	int assigned_channel = 0;
+	std::string subdev_spec;
+	for(int i=0;(i<usrp_uhd->mb_count)&&(assigned_channel<nchan);i++){
+		mb_path = "/mboards";
+		mb_path = mb_path / tree->list("/mboards")[i];
+
+		for(int j=0;(j<usrp_uhd->db_count)&&(assigned_channel<nchan);j++){
+			db_path = mb_path / "dboards" / tree->list( mb_path / "dboards")[j];
+			uhd::usrp::dboard_eeprom_t prom = tree->access<uhd::usrp::dboard_eeprom_t>(db_path / "rx_eeprom").get();
+			if (prom.id != uhd::usrp::dboard_id_t::none()){
+				subdev_spec = subdev_spec + tree->list( mb_path / "dboards")[j] + ":"
+						+ tree->list(db_path / "rx_frontends").at(0) + " ";
+				assigned_channel++;
+
+			}
+
+
+		}
+		DEBUG(3, USRP_UHD, "subdev of rx channel@MB"<<i<<" = "<<subdev_spec)
+		usrp_uhd->sdev->set_rx_subdev_spec(uhd::usrp::subdev_spec_t(subdev_spec),i);
+
+	}
+	usrp_uhd->rx_channels = usrp_uhd->sdev->get_rx_num_channels();
+	DEBUG(3, USRP_UHD, "# of Rx Channels Requested="<<nchan<<", Real="<<usrp_uhd->rx_channels)
 }
 
 void USRP_UHD_RX_Control_i::get_number_of_channels(CORBA::ULong &num)
 {
-    DEBUG(1, USRP_UHD, "Request to get number of channels not supported")
-//omni_mutex_lock l(usrp_uhd->rx_control_access);
-
-//num = usrp_uhd->usrp_uhd_ptr->nchannels();
+	omni_mutex_lock l(usrp_uhd->rx_control_access);
+	num = usrp_uhd->sdev->get_rx_num_channels();
+	DEBUG(3, USRP_UHD, "Rx get number of channels = "<<num)
 }
 
@@ -233,5 +301,5 @@
 
     if (channel == 0 && usrp_uhd->sdev) {
-        uhd::gain_range_t range = usrp_uhd->sdev->get_rx_gain_range();
+        uhd::gain_range_t range = usrp_uhd->sdev->get_rx_gain_range(channel);
         // All values in range are in dB
         gmin = range.start();
@@ -243,61 +311,59 @@
 void USRP_UHD_RX_Control_i::set_gain(CORBA::ULong channel, CORBA::Float gain)
 {
-    DEBUG(1, USRP_UHD, "set gain to "<<gain);
-
-    omni_mutex_lock l(usrp_uhd->rx_control_access);
-
-    if (channel == 0) {
-        if (usrp_uhd->sdev)
-            usrp_uhd->sdev->set_rx_gain(gain);
+	omni_mutex_lock l(usrp_uhd->rx_control_access);
+
+	if (usrp_uhd->sdev) {
+		usrp_uhd->sdev->set_rx_gain(gain,channel);
+		DEBUG(3, USRP_UHD, "Rx set gain = "<<gain)
+	}
+	else {
+
+	}
+}
+
+void USRP_UHD_RX_Control_i::get_gain(CORBA::ULong channel, CORBA::Float &gain)
+{
+    omni_mutex_lock l(usrp_uhd->rx_control_access);
+    if (usrp_uhd->sdev) {
+		gain = usrp_uhd->sdev->get_rx_gain(channel);
+		DEBUG(3, USRP_UHD, "Rx get gain = "<<gain);
+    }
+    else{
+
+    }
+}
+
+void USRP_UHD_RX_Control_i::get_frequency_range(CORBA::ULong channel, CORBA::Float &fmin, CORBA::Float &fmax, CORBA::Float &fstep)
+{
+    omni_mutex_lock l(usrp_uhd->rx_control_access);
+
+	if (usrp_uhd->sdev) {
+		uhd::freq_range_t range = usrp_uhd->sdev->get_rx_freq_range(channel);
+		// All values in range are in dB
+		fmin = range.start();
+		fmax = range.stop();
+		fstep = range.step();
+		DEBUG(3, USRP_UHD, "Rx Frequency range = "<<range.to_pp_string())
+
+	}
+	else{
+
+	}
+}
+
+void USRP_UHD_RX_Control_i::set_frequency(CORBA::ULong channel, CORBA::Float f)
+{
+    omni_mutex_lock l(usrp_uhd->rx_control_access);
+
+    if (usrp_uhd->sdev) {
+        uhd::tune_result_t result = usrp_uhd->sdev->set_rx_freq(f,channel);
+
+        DEBUG(3, USRP_UHD, "USRP_UHD RX tune_result:" <<std::endl<<
+              " \tTarget_RF_Freq=" << result.target_rf_freq <<std::endl<<
+              " \tActual_RF_Freq=" << result.actual_rf_freq <<std::endl<<
+              " \tTarget_DSP_freq="   << result.target_dsp_freq <<std::endl<<
+              " \tActual_DSP_freq="   << result.actual_dsp_freq);
     } else {
-        DEBUG(1, USRP_UHD, "Attempt to set gain on non-existent db.");
-        return; ///\todo throw bad channel exception
-    }
-}
-
-void USRP_UHD_RX_Control_i::get_gain(CORBA::ULong channel, CORBA::Float &gain)
-{
-    omni_mutex_lock l(usrp_uhd->rx_control_access);
-    if (channel == 0 && usrp_uhd->sdev)
-        gain = usrp_uhd->sdev->get_rx_gain();
-    else
-        return; ///\todo throw bad channel exception
-}
-
-void USRP_UHD_RX_Control_i::get_frequency_range(CORBA::ULong channel, CORBA::Float &fmin, CORBA::Float &fmax, CORBA::Float &fstep)
-{
-    omni_mutex_lock l(usrp_uhd->rx_control_access);
-
-    if (channel == 0) {
-        if (usrp_uhd->sdev) {
-            uhd::freq_range_t range = usrp_uhd->sdev->get_rx_freq_range();
-            // All values in range are in dB
-            fmin = range.start();
-            fmax = range.stop();
-            fstep = 0.0; // There is no step value in uhd::freq_range
-        }
-    } else {
-        return; ///\todo throw bad channel exception
-    }
-}
-
-void USRP_UHD_RX_Control_i::set_frequency(CORBA::ULong channel, CORBA::Float f)
-{
-    DEBUG(3, USRP_UHD, "In RX Control set frequency channel: " << channel << ", frequency: " << f);
-
-    omni_mutex_lock l(usrp_uhd->rx_control_access);
-
-    if (channel == 0) {
-        uhd::tune_result_t result = usrp_uhd->sdev->set_rx_freq(f);
-/*
-        DEBUG(3, USRP_UHD, "USRP_UHD RX tune_result:" <<
-              " target_inter_freq=" << result.target_inter_freq <<
-              " actual_inter_freq=" << result.actual_inter_freq <<
-              " target_dsp_freq="   << result.target_dsp_freq <<
-              " actual_dsp_freq="   << result.actual_dsp_freq);
-              */
-    } else {
-        DEBUG(3, USRP_UHD, "USRP_UHD TX set_frequency (invalid channel)");
-        return;
+
     }
 }
@@ -305,7 +371,11 @@
 void USRP_UHD_RX_Control_i::get_frequency(CORBA::ULong channel, CORBA::Float &f)
 {
-    DEBUG(1, USRP_UHD, "RX get_frequency not supported!!");
-
-    f = 0.0;
+	omni_mutex_lock l(usrp_uhd->rx_control_access);
+	if(usrp_uhd->sdev){
+		f = usrp_uhd->sdev->get_rx_freq(channel);
+	}
+	else{
+
+	}
 }
 
@@ -326,11 +396,10 @@
     omni_mutex_lock l(usrp_uhd->rx_control_access);
     DEBUG(0, USRP_UHD, "USRP_RX_Control stop Called")
-
-    usrp_uhd->rx_active = false;//false;
+    usrp_uhd->rx_active = false;
 }
 
 void USRP_UHD_RX_Control_i::set_values(const CF::Properties &values)
 {
-/*    DEBUG(3, USRP_UHD, "USRP_UHD RX setting " << values.length() << " values, value[0].id " << values[0].id)
+    DEBUG(3, USRP_UHD, "RX set_values: " << values.length() << " values, value[0].id " << values[0].id)
 
     for (unsigned int i =0; i < values.length(); ++i) {
@@ -349,10 +418,20 @@
             CORBA::ULong ant;
             values[i].value >>= ant;
-            DEBUG(3, USRP_UHD, "Setting receive antenna to  " << ant)
             omni_mutex_lock l(usrp_uhd->rx_control_access);
-            if (usrp_uhd->rx_db0_control)
-                usrp_uhd->rx_db0_control->select_rx_antenna(ant);
+            std::vector<std::string>rx_antennas0 = usrp_uhd->sdev->get_rx_antennas(0);
+            DEBUG(3, USRP_UHD, "Setting receive antenna to  " << rx_antennas0[ant])
+
+            usrp_uhd->sdev->set_rx_antenna(rx_antennas0[ant]);
+
+        } else if (strcmp(values[i].id, "SET_RX_ANT_2") == 0 ) {
+            CORBA::ULong ant;
+            values[i].value >>= ant;
+            omni_mutex_lock l(usrp_uhd->rx_control_access);
+            std::vector<std::string>rx_antennas1 = usrp_uhd->sdev->get_rx_antennas(1);
+            DEBUG(3, USRP_UHD, "Setting receive antenna to  " << rx_antennas1[ant])
+            usrp_uhd->sdev->set_rx_antenna(rx_antennas1[ant]);
+
         }
-    }*/
+    }
 }
 
@@ -360,14 +439,29 @@
 {
     omni_mutex_lock l(usrp_uhd->rx_control_access);
-    if(channel == 0 && usrp_uhd->sdev)
-        usrp_uhd->sdev->set_rx_rate(ADC_RATE/D);
+    ///\TODO: rate matching in UHD works a little different. Review
+    double master_clock = usrp_uhd->sdev->get_master_clock_rate();
+    double request_da_rate = master_clock/(double)D;
+    usrp_uhd->sdev->set_rx_rate(request_da_rate,channel);
+    double real_da_rate = usrp_uhd->sdev->get_rx_rate(channel);
+    DEBUG(3, USRP_UHD, "Requested Rx sample rate ="<<request_da_rate<<", Real Rx sample rate ="<<real_da_rate)
 }
 
 void USRP_UHD_RX_Control_i::get_decimation_range(CORBA::ULong channel, CORBA::ULong &dmin, CORBA::ULong &dmax, CORBA::ULong &dstep)
 {
-    DEBUG(1, USRP_UHD, "get_decimation_rate not supported!!")
-    dmin = 0;
-    dmax = 0;
-    dstep = 0;
+	omni_mutex_lock l(usrp_uhd->rx_control_access);
+	if(usrp_uhd->sdev){
+		double master_clock = usrp_uhd->sdev->get_master_clock_rate();
+		uhd::meta_range_t rx_range = usrp_uhd->sdev->get_rx_rates(channel);
+		dmax = master_clock/rx_range.start();
+		dmin = master_clock/rx_range.stop();
+		dstep = master_clock*rx_range.step()/(rx_range.stop()*rx_range.start());
+		if(dstep < 1)
+			dstep = 1;
+
+		DEBUG(3, USRP_UHD, "Decimation min="<<dmin<<", max="<<dmax<<", step="<<dstep)
+	}
+	else{
+
+	}
 }
 
@@ -375,5 +469,4 @@
 {
     omni_mutex_lock l(usrp_uhd->rx_control_access);
-
     usrp_uhd->rx_packet_size = N;
 }
Index: /ossiedev/branches/june/trunk/platform/USRP_UHD/src/USRP_UHD.cpp
===================================================================
--- /ossiedev/branches/june/trunk/platform/USRP_UHD/src/USRP_UHD.cpp	(revision 11034)
+++ /ossiedev/branches/june/trunk/platform/USRP_UHD/src/USRP_UHD.cpp	(revision 11094)
@@ -26,4 +26,7 @@
 #include <vector>
 #include <complex>
+#include <boost/program_options.hpp>
+#include <boost/format.hpp>
+#include <boost/thread.hpp>
 
 #include "ossie/cf.h"
@@ -39,5 +42,5 @@
         set_rx_packet_count(-1),
         rx_packet_count(1024),
-        rx_packet_size(256),
+        rx_packet_size(8192),
         rx_data_size(2),
         number_of_channels(1),
@@ -50,13 +53,15 @@
 {
 // Create USRP_UHD Control ports for TX and RX
-    rx_control_port = new USRP_UHD_RX_Control_i(this, "U2_RX_Control", "DomainName1");
-    tx_control_port = new USRP_UHD_TX_Control_i(this, "U2_TX_Control", "DomainName1");
+    rx_control_port = new USRP_UHD_RX_Control_i(this, "UHD_RX_Control", "DomainName1");
+    tx_control_port = new USRP_UHD_TX_Control_i(this, "UHD_TX_Control", "DomainName1");
 
 // Create the ports for TX data
-    tx_data_port = new standardInterfaces_i::complexShort_p("U2_TX_Data", "DomainName1");
+    for(int i=0;i<MAX_TX_CHANNEL;i++)
+    	tx_data_ports[i] = new standardInterfaces_i::complexShort_p(boost::str(boost::format("UHD_TX_Data_%d") % (i+1)).c_str(), "DomainName1");
 
 // Create the ports for RX Data
-    rx_data_1_port = new standardInterfaces_i::complexShort_u("U2_RX_Data_1", "DomainName1");
-    rx_data_2_port = new standardInterfaces_i::complexShort_u("U2_RX_Data_2", "DomainName1");
+    for(int i=0;i<MAX_RX_CHANNEL;i++)
+    	rx_data_ports[i] = new standardInterfaces_i::complexShort_u(boost::str(boost::format("UHD_RX_Data_%d") % (i+1)).c_str(), "DomainName1");
+
 }
 
@@ -81,15 +86,18 @@
     if (!CORBA::is_nil(p = rx_control_port->getPort(portName)))
         return p._retn();
-    else if (!CORBA::is_nil(p = rx_data_1_port->getPort(portName)))
+    else if (!CORBA::is_nil(p = tx_control_port->getPort(portName)))
         return p._retn();
-    else if (!CORBA::is_nil(p = rx_data_1_port->getPort(portName))) {
-        return p._retn();
-    } else if (!CORBA::is_nil(p = tx_control_port->getPort(portName))) {
-        return p._retn();
-    } else if (!CORBA::is_nil(p = tx_data_port->getPort(portName))) {
-        return p._retn();
+    else {
+    	for(int i=0;i<MAX_RX_CHANNEL;i++)
+    		if (!CORBA::is_nil(p = rx_data_ports[i]->getPort(portName)))
+    		        return p._retn();
+
+    	for(int i=0;i<MAX_TX_CHANNEL;i++)
+    		if (!CORBA::is_nil(p = tx_data_ports[i]->getPort(portName)))
+    		        return p._retn();
     }
+
     std::cerr << "Couldn't find port " << portName << "Throwing exception" << std::endl;
-    throw CF::PortSupplier::UnknownPort();
+   // throw CF::PortSupplier::UnknownPort();
 }
 
@@ -100,5 +108,8 @@
     DEBUG(1, USRP_UHD, "Creating the usrp device with: "<< args)
     sdev = uhd::usrp::multi_usrp::make(args);
-    dev = sdev->get_device();
+    dev = sdev->get_device();//uhd::device::make(args);
+    probe_usrp();
+    rx_control_port->set_number_of_channels(1);
+    tx_control_port->set_number_of_channels(1);
     sdev->set_rx_antenna("RX2");
     sdev->set_rx_antenna("TX/RX");
@@ -127,4 +138,31 @@
 }
 
+void USRP_UHD_i::rx_error_helper(uhd::rx_metadata_t::error_code_t error)
+{
+    switch(error){
+        case uhd::rx_metadata_t::ERROR_CODE_NONE:
+            break;
+        case uhd::rx_metadata_t::ERROR_CODE_TIMEOUT:
+            DEBUG(2, USRP_UHD, "Got timeout before all samples received, possible packet loss")
+            break;
+        case uhd::rx_metadata_t::ERROR_CODE_LATE_COMMAND:
+        	DEBUG(2, USRP_UHD, "UHD::ERROR_CODE_LATE_COMMAND")
+        	break;
+        case uhd::rx_metadata_t::ERROR_CODE_BROKEN_CHAIN:
+        	DEBUG(2, USRP_UHD, "UHD::ERROR_CODE_BROKEN_CHAIN")
+        	break;
+        case uhd::rx_metadata_t::ERROR_CODE_OVERFLOW:
+        	//DEBUG(2, USRP_UHD, "UHD::ERROR_CODE_OVERFLOW")
+        	break;
+        case uhd::rx_metadata_t::ERROR_CODE_ALIGNMENT:
+        	DEBUG(2, USRP_UHD, "UHD::ERROR_CODE_ALIGNMENT")
+        	break;
+        case uhd::rx_metadata_t::ERROR_CODE_BAD_PACKET:
+        	DEBUG(2, USRP_UHD, "UHD::ERROR_CODE_BAD_PACKET")
+        	break;
+        default:
+            DEBUG(3, USRP_UHD, "Got Error Code 0x"<<error)
+    }
+}
 
 void USRP_UHD_i::rx_data_process()
@@ -146,15 +184,23 @@
     sdev->issue_stream_cmd(stream_cmd);
 
-    uhd::stream_args_t stream_args("sc16");
+    uhd::stream_args_t stream_args("sc16"); //complex floats
     stream_args.args["noclear"] = "1";
+    for (size_t chan = 0; chan < rx_channels; chan++)
+        stream_args.channels.push_back(chan); //linear mapping
     uhd::rx_streamer::sptr rx_stream = sdev->get_rx_stream(stream_args);
-
+    DEBUG(3, USRP_UHD, "Rx Channels = " << rx_channels)
     PortTypes::ShortSequence I;
     PortTypes::ShortSequence Q;
     
 ///\TODO Make sure rx_packet_size is >= than USRP_UHD_MIN_RX_SAMPLES!!!!!
-    rx_buff.resize(rx_packet_size);
+    std::vector<std::vector< std::complex<short> > > rx_buff(
+    		rx_channels, std::vector< std::complex<short> >(rx_packet_size)
+    );
     I.length(rx_packet_size);
     Q.length(rx_packet_size);
+
+    std::vector<std::complex<short> *> rx_buff_ptrs;
+    for (size_t i = 0; i < rx_buff.size(); i++)
+    	rx_buff_ptrs.push_back(&rx_buff[i].front());
 
     DEBUG(3, USRP_UHD, "RX packet count " << rx_packet_count)
@@ -168,25 +214,27 @@
 			did_rx = true;
 		}
+		//DEBUG(9, USRP_UHD, "issue cmd")
 
         
 //TODO get rid of num_rx_samps variable
-        size_t num_rx_samps = rx_stream->recv( &rx_buff.front(), rx_packet_size, md);
+        size_t num_rx_samps = rx_stream->recv( rx_buff_ptrs, rx_packet_size, md);
+		//DEBUG(9, USRP_UHD, "recv data")
 	
         //Handle UHD error codes
-        switch(md.error_code){
-            case uhd::rx_metadata_t::ERROR_CODE_NONE:
-                break;
-            case uhd::rx_metadata_t::ERROR_CODE_TIMEOUT:
-                DEBUG(3, USRP_UHD, "Got timeout before all samples received, possible packet loss")
-                break;
-            default:
-                DEBUG(3, USRP_UHD, "Got error code 0x"<<md.error_code)
+        rx_error_helper(md.error_code);
+
+        for(int j=0;j<rx_channels;j++){
+
+			for (unsigned int i = 0; i < num_rx_samps; i++) {
+				I[i] = (CORBA::Short) rx_buff[j][i].real();
+				Q[i] = (CORBA::Short) rx_buff[j][i].imag();
+			}
+
+			//DEBUG(9, USRP_UHD, "before push packet")
+			rx_data_ports[j]->pushPacket(I, Q);
+			//DEBUG(9, USRP_UHD, "after push packet")
         }
 
-		for (unsigned int i = 0; i < num_rx_samps; i++) {
-			I[i] = (CORBA::Short) rx_buff[i].real();
-			Q[i] = (CORBA::Short) rx_buff[i].imag();
-		}
-		rx_data_1_port->pushPacket(I, Q);
+
 
 		if (rx_packet_count != -1)
@@ -220,8 +268,9 @@
     const unsigned int tx_buf_len(USRP_UHD_MAX_TX_SAMPLES);
 
-    uhd::stream_args_t stream_args("sc16");
+    uhd::stream_args_t stream_args("sc16"); //complex short
     stream_args.args["noclear"] = "1";
+    for (size_t chan = 0; chan < tx_channels; chan++)
+        stream_args.channels.push_back(chan); //linear mapping
     uhd::tx_streamer::sptr tx_stream = sdev->get_tx_stream(stream_args);
-
 
     uhd::tx_metadata_t md3;
@@ -238,42 +287,69 @@
     //md.time_spec = uhd::time_spec_t((time_t)0 );
 
-    std::vector< std::complex<short int> > tx_buff(tx_buf_len);
 
     DEBUG(3, USRP_UHD, "Starting tx_data_process thread.")
     
     tx_active = true; // Cleared to stop TX in USRP_UHD_TX_Control->stop()
-
+    size_t samps_to_send = 0;
+    std::vector<std::complex<short> *> tx_buff_ptrs;
+    DEBUG(3, USRP_UHD, "Max Number of Sample="<<tx_stream->get_max_num_samps())
     while (tx_active) {
-		//if running half duplex mode we want to stop Rx streaming while transmitting
-		if (full_duplex == false && did_rx == true)  {
-				did_rx = false;
-			uhd::rx_metadata_t md;
-			size_t num_rx_samps = dev->recv( &rx_buff.front(), rx_packet_size, md,
-												uhd::io_type_t::COMPLEX_INT16,
-												uhd::device::RECV_MODE_FULL_BUFF);
-			sdev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS);
-
+
+		for(int i=0;i<tx_channels;i++){
+
+			tx_data_ports[i]->getData(I_in, Q_in);
+			samps_to_send = I_in->length();
+
+		    std::vector<std::complex<short> > tx_buff(samps_to_send);
+
+			for (unsigned int j = 0; j < samps_to_send; ++j) {
+				tx_buff[j] = std::complex<short int> (convertToLE((*I_in)[j]),convertToLE((*Q_in)[j]));
+			}
+
+			tx_buff_ptrs.push_back(&tx_buff.front());
+	        tx_data_ports[i]->bufferEmptied();
 		}
 
-
-        tx_data_port->getData(I_in, Q_in);
-        size_t samps_to_send = I_in->length();
-        
-        if(samps_to_send > tx_buf_len){
-            std::cerr << "USRP_UHD Tx Buffer Overflow. Throwing Exception"<<std::endl;
-            throw std::runtime_error("USRP_UHD buffer overflow");
-        }
-
-        for (unsigned int i = 0; i < samps_to_send; ++i) {
-            tx_buff[i] = std::complex<short int> (convertToLE((*I_in)[i]),convertToLE((*Q_in)[i]));
-        }
-
         //send the entire packet (driver fragments internally)
-        size_t num_tx_samps = tx_stream->send( &tx_buff.front(), samps_to_send, md3);
-        tx_data_port->bufferEmptied();
+        size_t num_tx_samps = tx_stream->send(tx_buff_ptrs, samps_to_send, md3);
+
+
 		
     }
-    
     DEBUG(3, USRP_UHD, "Exiting tx_data_process thread.")
     tx_thread->exit();
 }
+
+void print_tree(const uhd::fs_path &path, uhd::property_tree::sptr tree){
+    std::cout << path << std::endl;
+    BOOST_FOREACH(const std::string &name, tree->list(path)){
+        print_tree(path / name, tree);
+    }
+}
+
+
+void USRP_UHD_i::probe_usrp()
+{
+	DEBUG(3, USRP_UHD, "Probing daughter board of USRP..")
+    uhd::property_tree::sptr tree = dev->get_tree();
+	uhd::fs_path db_path, mb_path = "/mboards";
+	mb_count = tree->list("/mboards").size();
+	std::cout<<" The number of MB : "<<mb_count<<std::endl;
+	for(int i=0;i<mb_count;i++){
+		mb_path = "/mboards";
+		mb_path = mb_path / tree->list("/mboards")[i];
+		db_count = tree->list( mb_path / "dboards").size();
+		std::cout<<"  The number of DB slot: "<<db_count<<std::endl;
+		for(int j=0;j<db_count;j++){
+			db_path = mb_path / "dboards" / tree->list( mb_path / "dboards")[j];
+			uhd::usrp::dboard_eeprom_t prom = tree->access<uhd::usrp::dboard_eeprom_t>(db_path / "tx_eeprom").get();
+			std::cout<<"   TxDB ID : "<<prom.id.to_string()<<std::endl;
+
+			prom = tree->access<uhd::usrp::dboard_eeprom_t>(db_path / "rx_eeprom").get();
+			std::cout<<"   RxDB ID : "<<prom.id.to_string()<<std::endl;
+		}
+
+
+	}
+
+}
