Need help SoapySDR python (getHardwareTime function)

Hi All,

I need you help for the function getHardwareTime from SoapySDR,

Can someone explain me how this function work, Every time I try to get the time from this function, this function return me 0. What this function need to work properly ?

Thanks for you help !
Jerome

You can view the code I use to test the function below:


import SoapySDR
from SoapySDR import * #SOAPY_SDR_ constants
import numpy as np
import pyqtgraph as pg
import time

def generateTxBuffer(Samplerate,SignalTime,FreqSignal,Amplitude=0.3):

#SampleRate must be 10 * Frequency Signal

x = np.linspace(0, SignalTime , Samplerate*SignalTime)
y= Amplitude*np.sin(2*np.pi*FreqSignal* x).astype(np.complex64)

return x,y

#-------------------------------------------------------
#- init variable
#-------------------------------------------------------

Sample_rateRX = 5e6 # hz
Sample_rateTX = 5e6 # hz
rxChan=0
txChan=0
AntennaRX=‘LNAL’
AntennaTX=‘BAND1’
GainRX= 20 #db
GainTX = 0 #db
FrequencyRX= 2.4e9 #hz
FrequencyTX= 2.4e9 #hz

Pulse_lenght= 1 #second
Pulse_frequency= 50000 # hz
Pulse_amplitude= 0.3

RXbuffer_time= 3 #second

Receive_RX_buffer_lenght= 2 #second

#-------------------------------------------------------
#- init SDR
#-------------------------------------------------------

args = dict(driver=“lime”)
sdr = SoapySDR.Device(args)

if not sdr.hasHardwareTime():
raise Exception(‘this device does not support timed streaming’)

#-------------------------------------------------------
#- Set sample rate RX & TX
#-------------------------------------------------------

sdr.setSampleRate(SOAPY_SDR_RX, rxChan, Sample_rateRX)
sdr.setSampleRate(SOAPY_SDR_TX, txChan, Sample_rateTX)
print(“Actual Rx Rate %f Msps”%(sdr.getSampleRate(SOAPY_SDR_RX, rxChan)/1e6))
print(“Actual Tx Rate %f Msps”%(sdr.getSampleRate(SOAPY_SDR_TX, txChan)/1e6))

#-------------------------------------------------------
#- Set Antenna RX & TX
#-------------------------------------------------------
sdr.setAntenna(SOAPY_SDR_RX, rxChan, AntennaRX)
sdr.setAntenna(SOAPY_SDR_TX, txChan, AntennaTX)

#-------------------------------------------------------
#- Set Gain RX & TX
#-------------------------------------------------------

sdr.setGain(SOAPY_SDR_RX, rxChan,GainRX)
sdr.setGain(SOAPY_SDR_TX, rxChan, GainTX)

#-------------------------------------------------------
#- Set Frequency RX & TX
#-------------------------------------------------------

sdr.setFrequency(SOAPY_SDR_RX, rxChan , FrequencyRX)
sdr.setFrequency(SOAPY_SDR_TX, txChan , FrequencyTX)

#-------------------------------------------------------
#- Set Frequency RX & TX
#-------------------------------------------------------
print(“Create Rx and Tx streams”)
rxStream = sdr.setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32,[rxChan])
txStream = sdr.setupStream(SOAPY_SDR_TX, SOAPY_SDR_CF32,[txChan])
time.sleep(1) #sleep to activate the configuration

#-------------------------------------------------------
#- TX send buffer
#-------------------------------------------------------

sdr.activateStream(txStream)

x,txPulse = generateTxBuffer(Sample_rateTX,Pulse_lenght,Pulse_frequency,Pulse_amplitude)

print(“Time:”,sdr.getHardwareTime())

#------------------------------------------------------
#- Transmit & receive data
#------------------------------------------------------

#-------------------------------------------------------
#- Cleanup streams
#-------------------------------------------------------

print(“Cleanup streams”)
sdr.deactivateStream(txStream)
sdr.closeStream(rxStream)
sdr.closeStream(txStream)

Hardware timestamps are being taken from Rx stream, if you’re not running it, timestamp will not be updated

Hi @Ricardas,

Thanks for your help! I made a quick test and it’s work !

Do you know for the readatream and the writestream function, how work the flags SOAPY_SDR_HAS_TIME & SOAPY_SDR_END_BURST ?

Hi,

passing flags to writestream:
SOAPY_SDR_HAS_TIME - samples will be sent when specified HW timestamp is reached. If buffer arrives at hardware too late (packet timestamp is less than current HW timestamp), it will not be sent.
SOAPY_SDR_END_BURST - send samples to HW immediately once the end of submitted buffer is reached (normally sends when transfer size is reached).

As far as I can tell passing these flags readsream has no effect.

Thanks @IgnasJ for the answer,

Difficult to find this kind of information on the website of SOAPYSDR.

I have a last question for you,

What is the relation between the activatestream RX function and readstream function ?

The way I understand it is when you call the activatestream function, the driver start filling a internal buffer and with the readstream function you can access the data of this buffer. It’s correct ?

Thanks for your help !

Yes