diff --git a/devices/hackrf/devicehackrfshared.cpp b/devices/hackrf/devicehackrfshared.cpp index 276e9802b..a9b195329 100644 --- a/devices/hackrf/devicehackrfshared.cpp +++ b/devices/hackrf/devicehackrfshared.cpp @@ -19,6 +19,6 @@ #include "devicehackrfshared.h" -MESSAGE_CLASS_DEFINITION(DeviceHackRFShared::MsgSynchronizeFrequency, Message) +MESSAGE_CLASS_DEFINITION(DeviceHackRFShared::MsgSynchronizeSampleRate, Message) const unsigned int DeviceHackRFShared::m_sampleFifoMinRate = 48000; // 48kS/s knee diff --git a/devices/hackrf/devicehackrfshared.h b/devices/hackrf/devicehackrfshared.h index d5606da63..cfb7cd100 100644 --- a/devices/hackrf/devicehackrfshared.h +++ b/devices/hackrf/devicehackrfshared.h @@ -28,24 +28,24 @@ class DEVICES_API DeviceHackRFShared { public: - class DEVICES_API MsgSynchronizeFrequency : public Message + class DEVICES_API MsgSynchronizeSampleRate : public Message { MESSAGE_CLASS_DECLARATION public: - uint64_t getFrequency() const { return m_frequency; } + uint64_t getDeviceSampleRate() const { return m_deviceSampleRate; } - static MsgSynchronizeFrequency *create(uint64_t frequency) + static MsgSynchronizeSampleRate *create(uint64_t deviceSampleRate) { - return new MsgSynchronizeFrequency(frequency); + return new MsgSynchronizeSampleRate(deviceSampleRate); } private: - uint64_t m_frequency; + uint64_t m_deviceSampleRate; - MsgSynchronizeFrequency(uint64_t frequency) : + MsgSynchronizeSampleRate(uint64_t deviceSampleRate) : Message(), - m_frequency(frequency) + m_deviceSampleRate(deviceSampleRate) { } }; diff --git a/plugins/samplesink/hackrfoutput/hackrfoutput.cpp b/plugins/samplesink/hackrfoutput/hackrfoutput.cpp index 409ca2e45..d2114ada8 100644 --- a/plugins/samplesink/hackrfoutput/hackrfoutput.cpp +++ b/plugins/samplesink/hackrfoutput/hackrfoutput.cpp @@ -286,30 +286,23 @@ bool HackRFOutput::handleMessage(const Message& message) return true; } - else if (DeviceHackRFShared::MsgSynchronizeFrequency::match(message)) + else if (DeviceHackRFShared::MsgSynchronizeSampleRate::match(message)) { - DeviceHackRFShared::MsgSynchronizeFrequency& freqMsg = (DeviceHackRFShared::MsgSynchronizeFrequency&) message; - qint64 centerFrequency = DeviceSampleSink::calculateCenterFrequency( - freqMsg.getFrequency(), - 0, - m_settings.m_log2Interp, - (DeviceSampleSink::fcPos_t) m_settings.m_fcPos, - m_settings.m_devSampleRate); - qDebug("HackRFOutput::handleMessage: MsgSynchronizeFrequency: centerFrequency: %lld Hz", centerFrequency); + DeviceHackRFShared::MsgSynchronizeSampleRate& cmd = (DeviceHackRFShared::MsgSynchronizeSampleRate&) message; + qDebug() << "HackRFOutput::handleMessage: MsgSynchronizeSampleRate: " << cmd.getDeviceSampleRate(); + HackRFOutputSettings settings = m_settings; - settings.m_centerFrequency = centerFrequency; + settings.m_devSampleRate = cmd.getDeviceSampleRate(); + + MsgConfigureHackRF* message = MsgConfigureHackRF::create(settings, QList{"devSampleRate"}, false); + m_inputMessageQueue.push(message); if (m_guiMessageQueue) { - MsgConfigureHackRF* messageToGUI = MsgConfigureHackRF::create(settings, QList{"centerFrequency"}, false); + MsgConfigureHackRF* messageToGUI = MsgConfigureHackRF::create(settings, QList{"devSampleRate"}, false); m_guiMessageQueue->push(messageToGUI); } - m_settings.m_centerFrequency = settings.m_centerFrequency; - int sampleRate = m_settings.m_devSampleRate/(1<getDeviceEngineInputMessageQueue()->push(notif); - return true; } else @@ -394,6 +387,13 @@ bool HackRFOutput::applySettings(const HackRFOutputSettings& settings, const QLi settings.m_devSampleRate); } } + + if (m_deviceAPI->getSourceBuddies().size() > 0) + { + DeviceAPI *buddy = m_deviceAPI->getSourceBuddies()[0]; + DeviceHackRFShared::MsgSynchronizeSampleRate *sampleRateMsg = DeviceHackRFShared::MsgSynchronizeSampleRate::create(settings.m_devSampleRate); + buddy->getSamplingDeviceInputMessageQueue()->push(sampleRateMsg); + } } if (settingsKeys.contains("log2Interp") || force) @@ -405,13 +405,13 @@ bool HackRFOutput::applySettings(const HackRFOutputSettings& settings, const QLi } } - if (settingsKeys.contains("centerFrequency") || + if (m_running &&(settingsKeys.contains("centerFrequency") || settingsKeys.contains("devSampleRate") || settingsKeys.contains("log2Interp") || settingsKeys.contains("fcPos") || settingsKeys.contains("transverterMode") || settingsKeys.contains("transverterDeltaFrequency") || - settingsKeys.contains("LOppmTenths") || force) + settingsKeys.contains("LOppmTenths") || force)) { qint64 deviceCenterFrequency = DeviceSampleSink::calculateDeviceCenterFrequency( settings.m_centerFrequency, @@ -422,13 +422,6 @@ bool HackRFOutput::applySettings(const HackRFOutputSettings& settings, const QLi settings.m_transverterMode); setDeviceCenterFrequency(deviceCenterFrequency, settings.m_LOppmTenths); - if (m_deviceAPI->getSourceBuddies().size() > 0) - { - DeviceAPI *buddy = m_deviceAPI->getSourceBuddies()[0]; - DeviceHackRFShared::MsgSynchronizeFrequency *freqMsg = DeviceHackRFShared::MsgSynchronizeFrequency::create(deviceCenterFrequency); - buddy->getSamplingDeviceInputMessageQueue()->push(freqMsg); - } - forwardChange = true; } diff --git a/plugins/samplesink/hackrfoutput/hackrfoutputthread.cpp b/plugins/samplesink/hackrfoutput/hackrfoutputthread.cpp index 2db333cc5..82d3076e0 100644 --- a/plugins/samplesink/hackrfoutput/hackrfoutputthread.cpp +++ b/plugins/samplesink/hackrfoutput/hackrfoutputthread.cpp @@ -72,27 +72,34 @@ void HackRFOutputThread::run() m_running = true; m_startWaiter.wakeAll(); - if (hackrf_is_streaming(m_dev) == HACKRF_TRUE) { - qDebug("HackRFInputThread::run: HackRF is streaming already"); - } - else - { - qDebug("HackRFInputThread::run: HackRF is not streaming"); - - rc = (hackrf_error) hackrf_start_tx(m_dev, tx_callback, this); + qDebug("HackRFOutputThread::run: HackRF is streaming already"); + rc = (hackrf_error) hackrf_stop_tx(m_dev); if (rc == HACKRF_SUCCESS) { - qDebug("HackRFOutputThread::run: started HackRF Tx"); + qDebug("HackRFOutputThread::run: stopped HackRF Tx"); } else { - qDebug("HackRFOutputThread::run: failed to start HackRF Tx: %s", hackrf_error_name(rc)); + qDebug("HackRFOutputThread::run: failed to stop HackRF Tx: %s", hackrf_error_name(rc)); } } + usleep(200000); + + rc = (hackrf_error) hackrf_start_tx(m_dev, tx_callback, this); + + if (rc == HACKRF_SUCCESS) + { + qDebug("HackRFOutputThread::run: started HackRF Tx"); + } + else + { + qDebug("HackRFOutputThread::run: failed to start HackRF Tx: %s", hackrf_error_name(rc)); + } + while ((m_running) && (hackrf_is_streaming(m_dev) == HACKRF_TRUE)) { usleep(200000); diff --git a/plugins/samplesource/hackrfinput/hackrfinput.cpp b/plugins/samplesource/hackrfinput/hackrfinput.cpp index 82b9a112e..6c2f7fd01 100644 --- a/plugins/samplesource/hackrfinput/hackrfinput.cpp +++ b/plugins/samplesource/hackrfinput/hackrfinput.cpp @@ -152,9 +152,6 @@ bool HackRFInput::start() return false; } - // applySettings needs to called before thread is started, - // otherwise HackRF will not start correctly - applySettings(m_settings, QList(), true); m_hackRFThread = new HackRFInputThread(m_dev, &m_sampleFifo); @@ -164,6 +161,7 @@ bool HackRFInput::start() m_hackRFThread->setIQOrder(m_settings.m_iqOrder); m_hackRFThread->startWork(); m_running = true; + applySettings(m_settings, QList(), true); mutexLocker.unlock(); @@ -301,32 +299,23 @@ bool HackRFInput::handleMessage(const Message& message) return true; } - else if (DeviceHackRFShared::MsgSynchronizeFrequency::match(message)) + else if (DeviceHackRFShared::MsgSynchronizeSampleRate::match(message)) { - DeviceHackRFShared::MsgSynchronizeFrequency& freqMsg = (DeviceHackRFShared::MsgSynchronizeFrequency&) message; - qint64 centerFrequency = DeviceSampleSource::calculateCenterFrequency( - freqMsg.getFrequency(), - 0, - m_settings.m_log2Decim, - (DeviceSampleSource::fcPos_t) m_settings.m_fcPos, - m_settings.m_devSampleRate, - DeviceSampleSource::FSHIFT_TXSYNC); - qDebug("HackRFInput::handleMessage: MsgSynchronizeFrequency: centerFrequency: %lld Hz", centerFrequency); + DeviceHackRFShared::MsgSynchronizeSampleRate& cmd = (DeviceHackRFShared::MsgSynchronizeSampleRate&) message; + qDebug() << "HackRFInput::handleMessage: MsgSynchronizeSampleRate: " << cmd.getDeviceSampleRate(); + HackRFInputSettings settings = m_settings; - settings.m_centerFrequency = centerFrequency; + settings.m_devSampleRate = cmd.getDeviceSampleRate(); + + MsgConfigureHackRF* message = MsgConfigureHackRF::create(settings, QList{"devSampleRate"}, false); + m_inputMessageQueue.push(message); if (m_guiMessageQueue) { - QList settingsKeys({"log2Decim", "fcPos", "devSampleRate", "centerFrequency"}); - MsgConfigureHackRF* messageToGUI = MsgConfigureHackRF::create(settings, settingsKeys, false); + MsgConfigureHackRF* messageToGUI = MsgConfigureHackRF::create(settings, QList{"devSampleRate"}, false); m_guiMessageQueue->push(messageToGUI); } - m_settings.m_centerFrequency = settings.m_centerFrequency; - int sampleRate = m_settings.m_devSampleRate/(1<getDeviceEngineInputMessageQueue()->push(notif); - return true; } else @@ -388,6 +377,13 @@ bool HackRFInput::applySettings(const HackRFInputSettings& settings, const QList } } } + + if (m_deviceAPI->getSourceBuddies().size() > 0) + { + DeviceAPI *buddy = m_deviceAPI->getSourceBuddies()[0]; + DeviceHackRFShared::MsgSynchronizeSampleRate *sampleRateMsg = DeviceHackRFShared::MsgSynchronizeSampleRate::create(settings.m_devSampleRate); + buddy->getSamplingDeviceInputMessageQueue()->push(sampleRateMsg); + } } if (settingsKeys.contains("log2Decim") || force) @@ -522,7 +518,7 @@ bool HackRFInput::applySettings(const HackRFInputSettings& settings, const QList m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqCorrection); } - if (setFrequency) + if (m_running && setFrequency) { qint64 deviceCenterFrequency = DeviceSampleSource::calculateDeviceCenterFrequency( m_settings.m_centerFrequency, @@ -535,13 +531,6 @@ bool HackRFInput::applySettings(const HackRFInputSettings& settings, const QList qDebug() << "HackRFInput::applySettings deviceCenterFrequency:" << deviceCenterFrequency; setDeviceCenterFrequency(deviceCenterFrequency, m_settings.m_LOppmTenths); - if (m_deviceAPI->getSinkBuddies().size() > 0) // forward to buddy if necessary - { - DeviceAPI *buddy = m_deviceAPI->getSinkBuddies()[0]; - DeviceHackRFShared::MsgSynchronizeFrequency *freqMsg = DeviceHackRFShared::MsgSynchronizeFrequency::create(deviceCenterFrequency); - buddy->getSamplingDeviceInputMessageQueue()->push(freqMsg); - } - forwardChange = true; } diff --git a/plugins/samplesource/hackrfinput/hackrfinputthread.cpp b/plugins/samplesource/hackrfinput/hackrfinputthread.cpp index e93e68eee..54d27c870 100644 --- a/plugins/samplesource/hackrfinput/hackrfinputthread.cpp +++ b/plugins/samplesource/hackrfinput/hackrfinputthread.cpp @@ -83,23 +83,31 @@ void HackRFInputThread::run() if (hackrf_is_streaming(m_dev) == HACKRF_TRUE) { qDebug("HackRFInputThread::run: HackRF is streaming already"); - } - else - { - qDebug("HackRFInputThread::run: HackRF is not streaming"); - - rc = (hackrf_error) hackrf_start_rx(m_dev, rx_callback, this); + rc = (hackrf_error) hackrf_stop_rx(m_dev); if (rc == HACKRF_SUCCESS) { - qDebug("HackRFInputThread::run: started HackRF Rx"); + qDebug("HackRFInputThread::run: stopped HackRF Rx"); } else { - qDebug("HackRFInputThread::run: failed to start HackRF Rx: %s", hackrf_error_name(rc)); + qDebug("HackRFInputThread::run: failed to stop HackRF Rx: %s", hackrf_error_name(rc)); } } + usleep(200000); + + rc = (hackrf_error) hackrf_start_rx(m_dev, rx_callback, this); + + if (rc == HACKRF_SUCCESS) + { + qDebug("HackRFInputThread::run: started HackRF Rx"); + } + else + { + qDebug("HackRFInputThread::run: failed to start HackRF Rx: %s", hackrf_error_name(rc)); + } + while ((m_running) && (hackrf_is_streaming(m_dev) == HACKRF_TRUE)) { usleep(200000);