pothosware / SoapyBladeRF

Soapy SDR plugin for the Blade RF
https://github.com/pothosware/SoapyBladeRF/wiki
23 stars 19 forks source link

Units for timestamp keyword on setFrequency() are inconsistent with the rest of SoapySDR #60

Open wifimaker opened 6 months ago

wifimaker commented 6 months ago

Calling bladeRF_SoapySDR::setFrequency() with a "timestamp" keyword argument currently requires the timestamp to be in units of "bladeRF ticks". The rest of SoapySDR uses units of nanoseconds. For consistency, I propose that the "timestamp" keyword argument should also be in nanoseconds. Timestamps returned by bladeRF_SoapySDR::readStream() are already in nanoseconds and having consistent units will allow timestamps from received buffers to be directly used when scheduling frequency changes.

Philosophically, an argument can also be made that Soapy should be hiding backend specific details from the user, so BladeRF specific units should be hidden.

The necessary change to the source is:

diff --git a/bladeRF_Settings.cpp b/bladeRF_Settings.cpp
index 3d06548..4f95ef1 100644
--- a/bladeRF_Settings.cpp
+++ b/bladeRF_Settings.cpp
@@ -490,6 +490,9 @@ void bladeRF_SoapySDR::setFrequency(const int direction, const size_t channel, c

         auto value = args.find("timestamp");
         long long timestamp = value == args.end() ? 0 : std::stoll(value->second);
+        if(timestamp != 0) {
+          timestamp = _timeNsToRxTicks(timestamp);
+        }

         retune(direction, channel, timestamp, quickTuneIter->second);
         return;

Checking against 0 is a convenience, in that allows "BLADERF_RETUNE_NOW" to still function. I'm not aware that SoapySDR has an equivalent function that BLADERF_RETUNE_NOW can be mapped to in order to hide this bladeRF specifity.