JuliaTelecom / UHDBindings.jl

Julia C bindings for UHD to monitor USRP devices.
MIT License
5 stars 3 forks source link

Error checking in populateBuffer! #11

Closed dd0 closed 1 year ago

dd0 commented 1 year ago

Added an option to raise exceptions if received packet metadata indicates an error (see #10). This is disabled by default if the streamer is configured in continuous mode, to avoid breaking existing code that can ignore overflow errors and doesn't care about the exact number of samples received.

The exceptions are not exported to avoid adding generic names such as OverflowException to the global namespace.

RGerzaguet commented 1 year ago

Thanks for this initial PR. Looks very good to me. 2 small remarks

dd0 commented 1 year ago

Hi,

The difference between a timeout and other errors is that a timeout only shows that the samples aren't available yet, but might arrive later, while the others all mean that something went wrong (samples dropped due to overflow, or a command / communication error). For example, if you schedule the recording for the future and immediately call recv!:

UHDBindings.restartStreamer(
    radio.rx,
    stream_mode = UHDBindings.LibUHD.UHD_STREAM_MODE_NUM_SAMPS_AND_MORE,
    num_samps = length(buffer),
    stream_now = false,
    full_sec_delay = 1,
    frac_sec_delay = 0)
UHDBindings.recv!(buffer, radio)

The first few calls to populateBuffer! will fail with a timeout because the SDR isn't streaming, and recv! will spin in the loop until it starts. I don't think that we should return an error here -- this looks like a reasonable way to use the API for delayed reception.

I created a branch with this commit in my fork, if that's what you meant: https://github.com/dd0/UHDBindings.jl/tree/error-checking I can also change the PR to target another branch instead of main in the main repository, but (as far as I understand) that has to be an already-existing branch that a maintainer would have to create first.

RGerzaguet commented 1 year ago

Ok thanks for the feedback. Let's merge and tag a new intermediate version :)