Browse Source

USRP: Add option for 8-bit data transfers, to help avoid overruns at high sample rates.

chirpmodem-v8.0.0
Jon Beniston 1 month ago
parent
commit
debf235651
  1. 7
      plugins/samplesource/usrpinput/readme.md
  2. 29
      plugins/samplesource/usrpinput/usrpinput.cpp
  3. 9
      plugins/samplesource/usrpinput/usrpinputgui.cpp
  4. 1
      plugins/samplesource/usrpinput/usrpinputgui.h
  5. 26
      plugins/samplesource/usrpinput/usrpinputgui.ui
  6. 10
      plugins/samplesource/usrpinput/usrpinputsettings.cpp
  7. 1
      plugins/samplesource/usrpinput/usrpinputsettings.h
  8. 20
      plugins/samplesource/usrpinput/usrpinputthread.cpp
  9. 3
      plugins/samplesource/usrpinput/usrpinputthread.h
  10. 3
      sdrbase/resources/webapi/doc/swagger/include/USRP.yaml
  11. 3
      swagger/sdrangel/api/swagger/include/USRP.yaml
  12. 22
      swagger/sdrangel/code/qt5/client/SWGUSRPInputSettings.cpp
  13. 6
      swagger/sdrangel/code/qt5/client/SWGUSRPInputSettings.h

7
plugins/samplesource/usrpinput/readme.md

@ -101,6 +101,13 @@ Use this toggle button to switch the sample rate input next (8) between host to @@ -101,6 +101,13 @@ Use this toggle button to switch the sample rate input next (8) between host to
The I/Q stream from the USRP device can be decimated by a power of two by software inside the plugin before being sent to the baseband. Possible values are increasing powers of two: 1 (no decimation), 2, 4, 8, 16, 32.
<h3>9A: Sample format</h3>
The format of the samples from the device to the host, over USB or Ethernet: 16b (16 bits, the default) or 8b (8 bits). 8 bits halves the traffic,
which avoids overruns (16) at high sample rates.
It costs dynamic range (about 48 dB rather than 96), which is plenty for most digital signals, but set the gain so the signal is well above the noise,
and not much below full scale.
<h3>10: Gain Mode</h3>
Choose between automatic or manual gain control.

29
plugins/samplesource/usrpinput/usrpinput.cpp

@ -465,8 +465,9 @@ bool USRPInput::acquireChannel(const USRPInputSettings& settings) @@ -465,8 +465,9 @@ bool USRPInput::acquireChannel(const USRPInputSettings& settings)
}
// set up the stream
std::string cpu_format("sc16");
std::string wire_format("sc16");
const bool sc8 = settings.m_wireFormat == 1;
std::string cpu_format(sc8 ? "sc8" : "sc16");
std::string wire_format(sc8 ? "sc8" : "sc16");
std::vector<size_t> channel_nums;
channel_nums.push_back(m_deviceShared.m_channel);
@ -578,7 +579,7 @@ bool USRPInput::start() @@ -578,7 +579,7 @@ bool USRPInput::start()
{
QMutexLocker threadLocker(&m_threadMutex);
thread->setStream(m_streamId, m_bufSamples);
thread->setStream(m_streamId, m_bufSamples, settings.m_wireFormat == 1);
}
thread->setLog2Decimation(settings.m_log2SoftDecim);
@ -1086,6 +1087,15 @@ bool USRPInput::applySettings(const USRPInputSettings& settings, const QList<QSt @@ -1086,6 +1087,15 @@ bool USRPInput::applySettings(const USRPInputSettings& settings, const QList<QSt
m_deviceShared.m_log2Soft = settings.m_log2SoftDecim; // for buddies
}
// The wire format's the stream's, so a change while running restarts it, with the new settings
bool restart = false;
if (settingsKeys.contains("wireFormat") && (settings.m_wireFormat != m_settings.m_wireFormat))
{
QMutexLocker threadLocker(&m_threadMutex);
restart = m_usrpInputThread != nullptr;
}
// Applying settings to the device can take a long time (E.g. sample rate, clock source and bandwidth),
// so when running, they are applied in the device engine thread, rather than blocking the GUI thread.
// Values actually set are reported back via DeviceUSRPShared::MsgReportDeviceSettings.
@ -1145,6 +1155,12 @@ bool USRPInput::applySettings(const USRPInputSettings& settings, const QList<QSt @@ -1145,6 +1155,12 @@ bool USRPInput::applySettings(const USRPInputSettings& settings, const QList<QSt
m_replayBuffer.setLoop(m_settings.m_replayLoop);
}
if (restart)
{
m_inputMessageQueue.push(MsgStartStop::create(false));
m_inputMessageQueue.push(MsgStartStop::create(true));
}
// forward changes to buddies or oneself
// If the device coerces the sample rate, this will be sent again with the actual rate, once reported
@ -1382,6 +1398,9 @@ void USRPInput::webapiUpdateDeviceSettings( @@ -1382,6 +1398,9 @@ void USRPInput::webapiUpdateDeviceSettings(
if (deviceSettingsKeys.contains("log2SoftDecim")) {
settings.m_log2SoftDecim = qBound(0, response.getUsrpInputSettings()->getLog2SoftDecim(), 6);
}
if (deviceSettingsKeys.contains("wireFormat")) {
settings.m_wireFormat = response.getUsrpInputSettings()->getWireFormat() == 1 ? 1 : 0;
}
if (deviceSettingsKeys.contains("lpfBW")) {
settings.m_lpfBW = response.getUsrpInputSettings()->getLpfBw();
}
@ -1437,6 +1456,7 @@ void USRPInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& respo @@ -1437,6 +1456,7 @@ void USRPInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& respo
response.getUsrpInputSettings()->setGainMode((int) settings.m_gainMode);
response.getUsrpInputSettings()->setIqCorrection(settings.m_iqCorrection ? 1 : 0);
response.getUsrpInputSettings()->setLog2SoftDecim(settings.m_log2SoftDecim);
response.getUsrpInputSettings()->setWireFormat(settings.m_wireFormat);
response.getUsrpInputSettings()->setLpfBw(settings.m_lpfBW);
response.getUsrpInputSettings()->setTransverterDeltaFrequency(settings.m_transverterDeltaFrequency);
response.getUsrpInputSettings()->setTransverterMode(settings.m_transverterMode ? 1 : 0);
@ -1558,6 +1578,9 @@ void USRPInput::webapiReverseSendSettings(const QList<QString>& deviceSettingsKe @@ -1558,6 +1578,9 @@ void USRPInput::webapiReverseSendSettings(const QList<QString>& deviceSettingsKe
if (deviceSettingsKeys.contains("log2SoftDecim") || force) {
swgUsrpInputSettings->setLog2SoftDecim(settings.m_log2SoftDecim);
}
if (deviceSettingsKeys.contains("wireFormat") || force) {
swgUsrpInputSettings->setWireFormat(settings.m_wireFormat);
}
if (deviceSettingsKeys.contains("lpfBW") || force) {
swgUsrpInputSettings->setLpfBw(settings.m_lpfBW);
}

9
plugins/samplesource/usrpinput/usrpinputgui.cpp

@ -424,6 +424,7 @@ void USRPInputGUI::displaySettings() @@ -424,6 +424,7 @@ void USRPInputGUI::displaySettings()
ui->iqImbalance->setChecked(m_settings.m_iqCorrection);
ui->swDecim->setCurrentIndex(m_settings.m_log2SoftDecim);
ui->wireFormat->setCurrentIndex(m_settings.m_wireFormat);
updateSampleRate();
@ -590,6 +591,13 @@ void USRPInputGUI::on_sampleRate_changed(quint64 value) @@ -590,6 +591,13 @@ void USRPInputGUI::on_sampleRate_changed(quint64 value)
sendSettings();
}
void USRPInputGUI::on_wireFormat_currentIndexChanged(int index)
{
m_settings.m_wireFormat = index == 1 ? 1 : 0;
m_settingsKeys.append("wireFormat");
sendSettings();
}
void USRPInputGUI::on_swDecim_currentIndexChanged(int index)
{
if ((index <0) || (index > 6)) {
@ -827,6 +835,7 @@ void USRPInputGUI::makeUIConnections() @@ -827,6 +835,7 @@ void USRPInputGUI::makeUIConnections()
QObject::connect(ui->iqImbalance, &ButtonSwitch::toggled, this, &USRPInputGUI::on_iqImbalance_toggled);
QObject::connect(ui->sampleRate, &ValueDial::changed, this, &USRPInputGUI::on_sampleRate_changed);
QObject::connect(ui->swDecim, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &USRPInputGUI::on_swDecim_currentIndexChanged);
QObject::connect(ui->wireFormat, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &USRPInputGUI::on_wireFormat_currentIndexChanged);
QObject::connect(ui->lpf, &ValueDial::changed, this, &USRPInputGUI::on_lpf_changed);
QObject::connect(ui->loOffset, &ValueDialZ::changed, this, &USRPInputGUI::on_loOffset_changed);
QObject::connect(ui->gainMode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &USRPInputGUI::on_gainMode_currentIndexChanged);

1
plugins/samplesource/usrpinput/usrpinputgui.h

@ -96,6 +96,7 @@ private slots: @@ -96,6 +96,7 @@ private slots:
void on_iqImbalance_toggled(bool checked);
void on_sampleRate_changed(quint64 value);
void on_swDecim_currentIndexChanged(int index);
void on_wireFormat_currentIndexChanged(int index);
void on_lpf_changed(quint64 value);
void on_loOffset_changed(qint64 value);
void on_gainMode_currentIndexChanged(int index);

26
plugins/samplesource/usrpinput/usrpinputgui.ui

@ -451,6 +451,32 @@ @@ -451,6 +451,32 @@
</item>
</widget>
</item>
<item>
<widget class="QComboBox" name="wireFormat">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Sample format over USB or Ethernet: 16 or 8 bits. 8 bits halves the traffic, which avoids overruns at high sample rates, at the cost of dynamic range</string>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>16b</string>
</property>
</item>
<item>
<property name="text">
<string>8b</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>

10
plugins/samplesource/usrpinput/usrpinputsettings.cpp

@ -36,6 +36,7 @@ void USRPInputSettings::resetToDefaults() @@ -36,6 +36,7 @@ void USRPInputSettings::resetToDefaults()
m_dcBlock = false;
m_iqCorrection = false;
m_log2SoftDecim = 0;
m_wireFormat = 0;
m_lpfBW = 10e6f;
m_gain = 50;
m_antennaPath = "TX/RX";
@ -82,6 +83,7 @@ QByteArray USRPInputSettings::serialize() const @@ -82,6 +83,7 @@ QByteArray USRPInputSettings::serialize() const
s.writeU32(21, m_gpioDir);
s.writeU32(22, m_gpioPins);
s.writeString(23, m_title);
s.writeS32(24, m_wireFormat);
return s.final();
}
@ -136,6 +138,8 @@ bool USRPInputSettings::deserialize(const QByteArray& data) @@ -136,6 +138,8 @@ bool USRPInputSettings::deserialize(const QByteArray& data)
d.readU32(22, &uintval, 0);
m_gpioPins = uintval & 0xFF;
d.readString(23, &m_title, "USRP");
d.readS32(24, &m_wireFormat, 0);
m_wireFormat = m_wireFormat == 1 ? 1 : 0;
return true;
}
@ -173,6 +177,9 @@ void USRPInputSettings::applySettings(const QStringList& settingsKeys, const USR @@ -173,6 +177,9 @@ void USRPInputSettings::applySettings(const QStringList& settingsKeys, const USR
if (settingsKeys.contains("log2SoftDecim")) {
m_log2SoftDecim = settings.m_log2SoftDecim;
}
if (settingsKeys.contains("wireFormat")) {
m_wireFormat = settings.m_wireFormat;
}
if (settingsKeys.contains("lpfBW")) {
m_lpfBW = settings.m_lpfBW;
}
@ -254,6 +261,9 @@ QString USRPInputSettings::getDebugString(const QStringList& settingsKeys, bool @@ -254,6 +261,9 @@ QString USRPInputSettings::getDebugString(const QStringList& settingsKeys, bool
if (settingsKeys.contains("log2SoftDecim") || force) {
ostr << " m_log2SoftDecim: " << m_log2SoftDecim;
}
if (settingsKeys.contains("wireFormat") || force) {
ostr << " m_wireFormat: " << m_wireFormat;
}
if (settingsKeys.contains("lpfBW") || force) {
ostr << " m_lpfBW: " << m_lpfBW;
}

1
plugins/samplesource/usrpinput/usrpinputsettings.h

@ -46,6 +46,7 @@ struct USRPInputSettings @@ -46,6 +46,7 @@ struct USRPInputSettings
bool m_dcBlock;
bool m_iqCorrection;
uint32_t m_log2SoftDecim;
int m_wireFormat; //!< Samples over USB or Ethernet: 0 16 bit (sc16), 1 8 bit (sc8, half the traffic)
float m_lpfBW; //!< Analog lowpass filter bandwidth (Hz)
uint32_t m_gain; //!< Optimally distributed gain (dB)
QString m_antennaPath;

20
plugins/samplesource/usrpinput/usrpinputthread.cpp

@ -39,6 +39,7 @@ USRPInputThread::USRPInputThread(DeviceUSRPParams *deviceParams, int channel, Sa @@ -39,6 +39,7 @@ USRPInputThread::USRPInputThread(DeviceUSRPParams *deviceParams, int channel, Sa
m_overflows(0),
m_timeouts(0),
m_buf(nullptr),
m_buf8(nullptr),
m_bufSamples(0),
m_sampleFifo(sampleFifo),
m_replayBuffer(replayBuffer),
@ -57,18 +58,21 @@ USRPInputThread::~USRPInputThread() @@ -57,18 +58,21 @@ USRPInputThread::~USRPInputThread()
{
stopWork();
delete[] m_buf;
delete[] m_buf8;
}
// Set stream once it has been created. Must be called before startWork()
void USRPInputThread::setStream(uhd::rx_streamer::sptr stream, size_t bufSamples)
void USRPInputThread::setStream(uhd::rx_streamer::sptr stream, size_t bufSamples, bool sc8)
{
m_stream = stream;
m_bufSamples = bufSamples;
m_convertBuffer.resize(bufSamples);
delete[] m_buf;
delete[] m_buf8;
// *2 as samples are I+Q
m_buf = new qint16[2*bufSamples];
std::fill(m_buf, m_buf + 2*bufSamples, 0);
m_buf8 = sc8 ? new qint8[2*bufSamples] : nullptr;
}
void USRPInputThread::issueStreamCmd(bool start)
@ -181,7 +185,7 @@ void USRPInputThread::stopWork() @@ -181,7 +185,7 @@ void USRPInputThread::stopWork()
size_t USRPInputThread::recv(uhd::rx_metadata_t& md, double timeout)
{
if (!m_deviceParams) {
return m_stream->recv(m_buf, m_bufSamples, md, timeout);
return m_stream->recv(m_buf8 ? (void *) m_buf8 : (void *) m_buf, m_bufSamples, md, timeout);
}
// Only wait for a short time while holding the lock, so if our stream isn't receiving data
@ -197,7 +201,7 @@ size_t USRPInputThread::recv(uhd::rx_metadata_t& md, double timeout) @@ -197,7 +201,7 @@ size_t USRPInputThread::recv(uhd::rx_metadata_t& md, double timeout)
{
std::lock_guard<DeviceUSRPRecvLock> recvLock(m_deviceParams->m_recvLock);
samplesReceived = m_stream->recv(m_buf, m_bufSamples, md, lockedTimeout);
samplesReceived = m_stream->recv(m_buf8 ? (void *) m_buf8 : (void *) m_buf, m_bufSamples, md, lockedTimeout);
}
if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_TIMEOUT) {
@ -274,7 +278,17 @@ void USRPInputThread::run() @@ -274,7 +278,17 @@ void USRPInputThread::run()
qDebug("USRPInputThread::run - bad packet error");
if (samples_received > 0)
{
// 8 bit samples widened to 16, full scale as 16 bit samples' (outside the device's receive lock)
if (m_buf8)
{
for (size_t i = 0; i < 2 * samples_received; i++) {
m_buf[i] = (qint16) (m_buf8[i] * 256);
}
}
callbackIQ(m_buf, 2 * samples_received);
}
}
}
catch (std::exception& e)

3
plugins/samplesource/usrpinput/usrpinputthread.h

@ -56,7 +56,7 @@ public: @@ -56,7 +56,7 @@ public:
ReplayBuffer<qint16> *replayBuffer, MessageQueue *reportQueue, QObject* parent = nullptr);
~USRPInputThread();
void setStream(uhd::rx_streamer::sptr stream, size_t bufSamples);
void setStream(uhd::rx_streamer::sptr stream, size_t bufSamples, bool sc8 = false);
void releaseStream();
virtual void startWork();
virtual void stopWork();
@ -93,6 +93,7 @@ private: @@ -93,6 +93,7 @@ private:
uhd::rx_streamer::sptr m_stream;
qint16 *m_buf;
qint8 *m_buf8; //!< With sc8, what's received, before widening into m_buf
size_t m_bufSamples;
SampleVector m_convertBuffer;
SampleSinkFifo* m_sampleFifo;

3
sdrbase/resources/webapi/doc/swagger/include/USRP.yaml

@ -61,6 +61,9 @@ USRPInputSettings: @@ -61,6 +61,9 @@ USRPInputSettings:
type: integer
format: int8
description: "GPIO pin-state bit mask, with one bit per pin."
wireFormat:
type: integer
description: "Samples over USB or Ethernet: 0 16 bit (sc16), 1 8 bit (sc8: half the traffic, for high sample rates)."
useReverseAPI:
description: Synchronize with reverse API (1 for yes, 0 for no)
type: integer

3
swagger/sdrangel/api/swagger/include/USRP.yaml

@ -61,6 +61,9 @@ USRPInputSettings: @@ -61,6 +61,9 @@ USRPInputSettings:
type: integer
format: int8
description: "GPIO pin-state bit mask, with one bit per pin."
wireFormat:
type: integer
description: "Samples over USB or Ethernet: 0 16 bit (sc16), 1 8 bit (sc8: half the traffic, for high sample rates)."
useReverseAPI:
description: Synchronize with reverse API (1 for yes, 0 for no)
type: integer

22
swagger/sdrangel/code/qt5/client/SWGUSRPInputSettings.cpp

@ -60,6 +60,8 @@ SWGUSRPInputSettings::SWGUSRPInputSettings() { @@ -60,6 +60,8 @@ SWGUSRPInputSettings::SWGUSRPInputSettings() {
m_gpio_dir_isSet = false;
gpio_pins = 0;
m_gpio_pins_isSet = false;
wire_format = 0;
m_wire_format_isSet = false;
use_reverse_api = 0;
m_use_reverse_api_isSet = false;
reverse_api_address = nullptr;
@ -108,6 +110,8 @@ SWGUSRPInputSettings::init() { @@ -108,6 +110,8 @@ SWGUSRPInputSettings::init() {
m_gpio_dir_isSet = false;
gpio_pins = 0;
m_gpio_pins_isSet = false;
wire_format = 0;
m_wire_format_isSet = false;
use_reverse_api = 0;
m_use_reverse_api_isSet = false;
reverse_api_address = new QString("");
@ -193,6 +197,8 @@ SWGUSRPInputSettings::fromJsonObject(QJsonObject &pJson) { @@ -193,6 +197,8 @@ SWGUSRPInputSettings::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&gpio_pins, pJson["gpioPins"], "qint32", "");
::SWGSDRangel::setValue(&wire_format, pJson["wireFormat"], "qint32", "");
::SWGSDRangel::setValue(&use_reverse_api, pJson["useReverseAPI"], "qint32", "");
::SWGSDRangel::setValue(&reverse_api_address, pJson["reverseAPIAddress"], "QString", "QString");
@ -265,6 +271,9 @@ SWGUSRPInputSettings::asJsonObject() { @@ -265,6 +271,9 @@ SWGUSRPInputSettings::asJsonObject() {
if(m_gpio_pins_isSet){
obj->insert("gpioPins", QJsonValue(gpio_pins));
}
if(m_wire_format_isSet){
obj->insert("wireFormat", QJsonValue(wire_format));
}
if(m_use_reverse_api_isSet){
obj->insert("useReverseAPI", QJsonValue(use_reverse_api));
}
@ -441,6 +450,16 @@ SWGUSRPInputSettings::setGpioPins(qint32 gpio_pins) { @@ -441,6 +450,16 @@ SWGUSRPInputSettings::setGpioPins(qint32 gpio_pins) {
this->m_gpio_pins_isSet = true;
}
qint32
SWGUSRPInputSettings::getWireFormat() {
return wire_format;
}
void
SWGUSRPInputSettings::setWireFormat(qint32 wire_format) {
this->wire_format = wire_format;
this->m_wire_format_isSet = true;
}
qint32
SWGUSRPInputSettings::getUseReverseApi() {
return use_reverse_api;
@ -534,6 +553,9 @@ SWGUSRPInputSettings::isSet(){ @@ -534,6 +553,9 @@ SWGUSRPInputSettings::isSet(){
if(m_gpio_pins_isSet){
isObjectUpdated = true; break;
}
if(m_wire_format_isSet){
isObjectUpdated = true; break;
}
if(m_use_reverse_api_isSet){
isObjectUpdated = true; break;
}

6
swagger/sdrangel/code/qt5/client/SWGUSRPInputSettings.h

@ -90,6 +90,9 @@ public: @@ -90,6 +90,9 @@ public:
qint32 getGpioPins();
void setGpioPins(qint32 gpio_pins);
qint32 getWireFormat();
void setWireFormat(qint32 wire_format);
qint32 getUseReverseApi();
void setUseReverseApi(qint32 use_reverse_api);
@ -154,6 +157,9 @@ private: @@ -154,6 +157,9 @@ private:
qint32 gpio_pins;
bool m_gpio_pins_isSet;
qint32 wire_format;
bool m_wire_format_isSet;
qint32 use_reverse_api;
bool m_use_reverse_api_isSet;

Loading…
Cancel
Save