ms: cache frequency

Don't waste time setting the same frequency again.

Change-Id: Ide9f45130955e1cc66610a50d6fc1cd79f30aca9
This commit is contained in:
Eric
2023-05-02 15:34:19 +02:00
parent da5ffd6e01
commit c0f0a6105a
2 changed files with 18 additions and 2 deletions

View File

@@ -198,6 +198,7 @@ struct blade_hw {
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 @@ struct blade_hw {
{
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 @@ struct blade_hw {
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;
};

View File

@@ -78,12 +78,13 @@ struct uhd_hw {
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 @@ struct uhd_hw {
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;
};