osmo-trx: Add an option to swap channels on UmTRX.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
diff --git a/Transceiver52M/UHDDevice.cpp b/Transceiver52M/UHDDevice.cpp
index 9043318..9038bc1 100644
--- a/Transceiver52M/UHDDevice.cpp
+++ b/Transceiver52M/UHDDevice.cpp
@@ -290,7 +290,7 @@
 	uhd_device(size_t sps, size_t chans, bool diversity, double offset);
 	~uhd_device();
 
-	int open(const std::string &args, bool extref);
+	int open(const std::string &args, bool extref, bool swap_channels);
 	bool start();
 	bool stop();
 	bool restart();
@@ -694,7 +694,7 @@
 	return true;
 }
 
-int uhd_device::open(const std::string &args, bool extref)
+int uhd_device::open(const std::string &args, bool extref, bool swap_channels)
 {
 	// Find UHD devices
 	uhd::device_addr_t addr(args);
@@ -720,7 +720,7 @@
 	// Verify and set channels
 	if ((dev_type == B210) && (chans == 2)) {
 	} else if ((dev_type == UMTRX) && (chans == 2)) {
-		uhd::usrp::subdev_spec_t subdev_spec("A:0 B:0");
+		uhd::usrp::subdev_spec_t subdev_spec(swap_channels?"B:0 A:0":"A:0 B:0");
 		usrp_dev->set_tx_subdev_spec(subdev_spec);
 		usrp_dev->set_rx_subdev_spec(subdev_spec);
 	} else if (chans != 1) {
diff --git a/Transceiver52M/USRPDevice.cpp b/Transceiver52M/USRPDevice.cpp
index bba8bb9..568f0e5 100644
--- a/Transceiver52M/USRPDevice.cpp
+++ b/Transceiver52M/USRPDevice.cpp
@@ -89,7 +89,7 @@
 #endif
 }
 
-int USRPDevice::open(const std::string &, bool)
+int USRPDevice::open(const std::string &, bool, bool)
 {
   writeLock.unlock();
 
diff --git a/Transceiver52M/USRPDevice.h b/Transceiver52M/USRPDevice.h
index 0807127..3f06c88 100644
--- a/Transceiver52M/USRPDevice.h
+++ b/Transceiver52M/USRPDevice.h
@@ -99,7 +99,7 @@
   USRPDevice(size_t sps, size_t chans = 1, bool diversity = false);
 
   /** Instantiate the USRP */
-  int open(const std::string &, bool);
+  int open(const std::string &, bool, bool);
 
   /** Start the USRP */
   bool start();
diff --git a/Transceiver52M/osmo-trx.cpp b/Transceiver52M/osmo-trx.cpp
index 048b9f8..7b9fd7c 100644
--- a/Transceiver52M/osmo-trx.cpp
+++ b/Transceiver52M/osmo-trx.cpp
@@ -71,6 +71,7 @@
 	bool diversity;
 	double offset;
 	double rssi_offset;
+	bool swap_channels;
 };
 
 ConfigurationTable gConfig;
@@ -187,6 +188,7 @@
 	ost << "   Diversity............... " << divstr << std::endl;
 	ost << "   Tuning offset........... " << config->offset << std::endl;
 	ost << "   RSSI to dBm offset...... " << config->rssi_offset << std::endl;
+	ost << "   Swap channels........... " << config->swap_channels << std::endl;
 	std::cout << ost << std::endl;
 
 	return true;
@@ -295,7 +297,8 @@
 		"  -f    Enable C0 filler table\n"
 		"  -o    Set baseband frequency offset (default=auto)\n"
 		"  -r    Random burst test mode with TSC\n"
-		"  -R    RSSI to dBm offset in dB (default=0)\n",
+		"  -R    RSSI to dBm offset in dB (default=0)\n"
+		"  -S    Swap channels (UmTRX only)\n",
 		"EMERG, ALERT, CRT, ERR, WARNING, NOTICE, INFO, DEBUG");
 }
 
@@ -312,8 +315,9 @@
 	config->diversity = false;
 	config->offset = 0.0;
 	config->rssi_offset = 0.0;
+	config->swap_channels = false;
 
-	while ((option = getopt(argc, argv, "ha:l:i:p:c:dxfo:s:r:R:")) != -1) {
+	while ((option = getopt(argc, argv, "ha:l:i:p:c:dxfo:s:r:R:S")) != -1) {
 		switch (option) {
 		case 'h':
 			print_help();
@@ -356,6 +360,9 @@
 		case 'R':
 			config->rssi_offset = atof(optarg);
 			break;
+		case 'S':
+			config->swap_channels = true;
+			break;
 		default:
 			print_help();
 			exit(0);
@@ -400,7 +407,7 @@
 	/* Create the low level device object */
 	usrp = RadioDevice::make(config.sps, config.chans,
 				 config.diversity, config.offset);
-	type = usrp->open(config.dev_args, config.extref);
+	type = usrp->open(config.dev_args, config.extref, config.swap_channels);
 	if (type < 0) {
 		LOG(ALERT) << "Failed to create radio device" << std::endl;
 		goto shutdown;
diff --git a/Transceiver52M/radioDevice.h b/Transceiver52M/radioDevice.h
index 6273bcc..dd4928c 100644
--- a/Transceiver52M/radioDevice.h
+++ b/Transceiver52M/radioDevice.h
@@ -41,7 +41,7 @@
                            bool diversity = false, double offset = 0.0);
 
   /** Initialize the USRP */
-  virtual int open(const std::string &args = "", bool extref = false)=0;
+  virtual int open(const std::string &args = "", bool extref = false, bool swap_channels = false)=0;
 
   virtual ~RadioDevice() { }