ms: cache frequency

Don't waste time setting the same frequency again.

Change-Id: Ide9f45130955e1cc66610a50d6fc1cd79f30aca9
diff --git a/Transceiver52M/ms/bladerf_specific.h b/Transceiver52M/ms/bladerf_specific.h
index ba5c7f1..3dc4777 100644
--- a/Transceiver52M/ms/bladerf_specific.h
+++ b/Transceiver52M/ms/bladerf_specific.h
@@ -198,6 +198,7 @@
 
 	float rxgain, txgain;
 	static std::atomic<bool> stop_lower_threads_flag;
+	double rxfreq_cache, txfreq_cache;
 
 	struct ms_trx_config {
 		int tx_freq;
@@ -222,7 +223,9 @@
 	{
 		close_device();
 	}
-	blade_hw() : rxFullScale(2047), txFullScale(2047), rxtxdelay(-60), rxgain(30), txgain(30)
+	blade_hw()
+		: rxFullScale(2047), txFullScale(2047), rxtxdelay(-60), rxgain(30), txgain(30), rxfreq_cache(0),
+		  txfreq_cache(0)
 	{
 	}
 
@@ -320,15 +323,21 @@
 
 	bool tuneTx(double freq, size_t chan = 0)
 	{
+		if (txfreq_cache == freq)
+			return true;
 		msleep(15);
 		blade_check(bladerf_set_frequency, dev, BLADERF_CHANNEL_TX(0), (bladerf_frequency)freq);
+		txfreq_cache = freq;
 		msleep(15);
 		return true;
 	};
 	bool tuneRx(double freq, size_t chan = 0)
 	{
+		if (rxfreq_cache == freq)
+			return true;
 		msleep(15);
 		blade_check(bladerf_set_frequency, dev, BLADERF_CHANNEL_RX(0), (bladerf_frequency)freq);
+		rxfreq_cache = freq;
 		msleep(15);
 		return true;
 	};
diff --git a/Transceiver52M/ms/uhd_specific.h b/Transceiver52M/ms/uhd_specific.h
index c8361e9..5723fd4 100644
--- a/Transceiver52M/ms/uhd_specific.h
+++ b/Transceiver52M/ms/uhd_specific.h
@@ -78,12 +78,13 @@
 	const int rxtxdelay;
 	float rxgain, txgain;
 	static std::atomic<bool> stop_lower_threads_flag;
+	double rxfreq_cache, txfreq_cache;
 
 	virtual ~uhd_hw()
 	{
 		delete[] one_pkt_buf;
 	}
-	uhd_hw() : rxFullScale(32767), txFullScale(32767 * 0.3), rxtxdelay(-67)
+	uhd_hw() : rxFullScale(32767), txFullScale(32767 * 0.3), rxtxdelay(-67), rxfreq_cache(0), txfreq_cache(0)
 	{
 	}
 
@@ -93,15 +94,21 @@
 
 	bool tuneTx(double freq, size_t chan = 0)
 	{
+		if (txfreq_cache == freq)
+			return true;
 		msleep(25);
 		dev->set_tx_freq(freq, chan);
+		txfreq_cache = freq;
 		msleep(25);
 		return true;
 	};
 	bool tuneRx(double freq, size_t chan = 0)
 	{
+		if (rxfreq_cache == freq)
+			return true;
 		msleep(25);
 		dev->set_rx_freq(freq, chan);
+		rxfreq_cache = freq;
 		msleep(25);
 		return true;
 	};