pothosware / SoapyPlutoSDR

Soapy SDR plugin for PlutoSDR
https://github.com/pothosware/SoapyPlutoSDR/wiki
GNU Lesser General Public License v2.1
53 stars 22 forks source link

Fix for TX chunks smaller than channel buffer size #6

Closed zuckschwerdt closed 5 years ago

zuckschwerdt commented 5 years ago

The iio channel always transfers a full buffer (4k), but SoapyRemote with a default MTU of 1500 will only supply 357 elements per call to writeStream(). This change incrementally fills the TX channels and writes the buffer to hardware (push in iio lingo) only when it's full. The channels are also flushed on closeStream() and deactivateStream(). Also removes the intermediate type conversion buffer (buffer) which isn't needed as we use iio_channel_convert_inverse() to copy element-wise anyway.

Fixes the root cause for pothosware/SoapyRemote#56.

guruofquality commented 5 years ago

If it helps limesdr for example works with fixed sized usb transfers. Each call to writeStream fills the outgoing USB buffer until its full, then it starts writing to the next buffer. The only exception to this if the flag SOAPY_SDR_END_BURST is specified, the buffer is zero padded and flushed out -- if this call to writeStream() consumed all of the samples passed in.

zuckschwerdt commented 5 years ago

I'll add SOAPY_SDR_END_BURST, thanks!

zuckschwerdt commented 5 years ago

I've now added SOAPY_SDR_END_BURST flag to control buffer flush on writeStream.

zuckschwerdt commented 5 years ago

Oh, yes. That makes more sense. I'll have to test if SoapyRemote passes the flag on every call or only the last though. I.e. the app says e.g. "write 6k and SOAPY_SDR_END_BURST" then SoapyRemote will chunk that into pieces that always fit in the buffer. Native the 6k would result in 4k with numElems!=items and then 2k and END_BURST. I also should zero out the remaining buffer before flush, don't merge yet.

guruofquality commented 5 years ago

Yea, so the server for example clears HAS_TIME flags &= ~(SOAPY_SDR_HAS_TIME); //clear time for subsequent writes in the write loop so its only set once on the first write, but other flags like END_BURST will show up again for subsequent calls. Other similar loops in this ecosystem do the same thing. Clear head flags like time, but keep tail flags like end burst.

zuckschwerdt commented 5 years ago

Well thought out. I justed checked and SoapyRemote indeed only passes that flag on the last chunk as expected. Thanks for all the suggestions and help!