mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-10-31 13:00:26 -04:00 
			
		
		
		
	SoapySDR: make sure device open is successful before starting. Fixes #1441
This commit is contained in:
		
							parent
							
								
									180c840633
								
							
						
					
					
						commit
						b54575041d
					
				| @ -30,6 +30,8 @@ Occasionally some devices may require to have the user specifying keyword parame | |||||||
| 
 | 
 | ||||||
| In such a case you will use the device user arguments (Preferences -> Devices -> User arguments) with the dialog as described [here](../../../sdrgui/deviceuserargs.md) | In such a case you will use the device user arguments (Preferences -> Devices -> User arguments) with the dialog as described [here](../../../sdrgui/deviceuserargs.md) | ||||||
| 
 | 
 | ||||||
|  | If you use Soapy Remote make sure you read [this Wiki page](https://github.com/f4exb/sdrangel/wiki/Soapy-Remote) first as user arguments are mandatory. | ||||||
|  | 
 | ||||||
| <h2>SoapySDR API implementation</h2> | <h2>SoapySDR API implementation</h2> | ||||||
| 
 | 
 | ||||||
| Not all parts are implemented. Currently the following have been left out: | Not all parts are implemented. Currently the following have been left out: | ||||||
|  | |||||||
| @ -42,10 +42,10 @@ SoapySDROutput::SoapySDROutput(DeviceAPI *deviceAPI) : | |||||||
|     m_deviceAPI(deviceAPI), |     m_deviceAPI(deviceAPI), | ||||||
|     m_deviceDescription("SoapySDROutput"), |     m_deviceDescription("SoapySDROutput"), | ||||||
|     m_running(false), |     m_running(false), | ||||||
|     m_thread(0) |     m_thread(nullptr) | ||||||
| { | { | ||||||
|     m_deviceAPI->setNbSinkStreams(1); |     m_deviceAPI->setNbSinkStreams(1); | ||||||
|     openDevice(); |     m_openSuccess = openDevice(); | ||||||
|     initGainSettings(m_settings); |     initGainSettings(m_settings); | ||||||
|     initTunableElementsSettings(m_settings); |     initTunableElementsSettings(m_settings); | ||||||
|     initStreamArgSettings(m_settings); |     initStreamArgSettings(m_settings); | ||||||
| @ -94,7 +94,7 @@ bool SoapySDROutput::openDevice() | |||||||
|         DeviceAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0]; |         DeviceAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0]; | ||||||
|         DeviceSoapySDRShared *deviceSoapySDRShared = (DeviceSoapySDRShared*) sinkBuddy->getBuddySharedPtr(); |         DeviceSoapySDRShared *deviceSoapySDRShared = (DeviceSoapySDRShared*) sinkBuddy->getBuddySharedPtr(); | ||||||
| 
 | 
 | ||||||
|         if (deviceSoapySDRShared == 0) |         if (!deviceSoapySDRShared) | ||||||
|         { |         { | ||||||
|             qCritical("SoapySDROutput::openDevice: the sink buddy shared pointer is null"); |             qCritical("SoapySDROutput::openDevice: the sink buddy shared pointer is null"); | ||||||
|             return false; |             return false; | ||||||
| @ -102,7 +102,7 @@ bool SoapySDROutput::openDevice() | |||||||
| 
 | 
 | ||||||
|         SoapySDR::Device *device = deviceSoapySDRShared->m_device; |         SoapySDR::Device *device = deviceSoapySDRShared->m_device; | ||||||
| 
 | 
 | ||||||
|         if (device == 0) |         if (!device) | ||||||
|         { |         { | ||||||
|             qCritical("SoapySDROutput::openDevice: cannot get device pointer from Tx buddy"); |             qCritical("SoapySDROutput::openDevice: cannot get device pointer from Tx buddy"); | ||||||
|             return false; |             return false; | ||||||
| @ -119,7 +119,7 @@ bool SoapySDROutput::openDevice() | |||||||
|         DeviceAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0]; |         DeviceAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0]; | ||||||
|         DeviceSoapySDRShared *deviceSoapySDRShared = (DeviceSoapySDRShared*) sourceBuddy->getBuddySharedPtr(); |         DeviceSoapySDRShared *deviceSoapySDRShared = (DeviceSoapySDRShared*) sourceBuddy->getBuddySharedPtr(); | ||||||
| 
 | 
 | ||||||
|         if (deviceSoapySDRShared == 0) |         if (!deviceSoapySDRShared) | ||||||
|         { |         { | ||||||
|             qCritical("SoapySDROutput::openDevice: the source buddy shared pointer is null"); |             qCritical("SoapySDROutput::openDevice: the source buddy shared pointer is null"); | ||||||
|             return false; |             return false; | ||||||
| @ -127,7 +127,7 @@ bool SoapySDROutput::openDevice() | |||||||
| 
 | 
 | ||||||
|         SoapySDR::Device *device = deviceSoapySDRShared->m_device; |         SoapySDR::Device *device = deviceSoapySDRShared->m_device; | ||||||
| 
 | 
 | ||||||
|         if (device == 0) |         if (!device) | ||||||
|         { |         { | ||||||
|             qCritical("SoapySDROutput::openDevice: cannot get device pointer from Rx buddy"); |             qCritical("SoapySDROutput::openDevice: cannot get device pointer from Rx buddy"); | ||||||
|             return false; |             return false; | ||||||
| @ -160,7 +160,7 @@ bool SoapySDROutput::openDevice() | |||||||
| 
 | 
 | ||||||
| void SoapySDROutput::closeDevice() | void SoapySDROutput::closeDevice() | ||||||
| { | { | ||||||
|     if (m_deviceShared.m_device == 0) { // was never open
 |     if (!m_deviceShared.m_device) { // was never open
 | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -173,7 +173,7 @@ void SoapySDROutput::closeDevice() | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     m_deviceShared.m_channel = -1; // publicly release channel
 |     m_deviceShared.m_channel = -1; // publicly release channel
 | ||||||
|     m_deviceShared.m_sink = 0; |     m_deviceShared.m_sink = nullptr; | ||||||
| 
 | 
 | ||||||
|     // No buddies so effectively close the device
 |     // No buddies so effectively close the device
 | ||||||
| 
 | 
 | ||||||
| @ -181,7 +181,7 @@ void SoapySDROutput::closeDevice() | |||||||
|     { |     { | ||||||
|         DeviceSoapySDR& deviceSoapySDR = DeviceSoapySDR::instance(); |         DeviceSoapySDR& deviceSoapySDR = DeviceSoapySDR::instance(); | ||||||
|         deviceSoapySDR.closeSoapySdr(m_deviceShared.m_device); |         deviceSoapySDR.closeSoapySdr(m_deviceShared.m_device); | ||||||
|         m_deviceShared.m_device = 0; |         m_deviceShared.m_device = nullptr; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -371,9 +371,9 @@ void SoapySDROutput::init() | |||||||
| 
 | 
 | ||||||
| SoapySDROutputThread *SoapySDROutput::findThread() | SoapySDROutputThread *SoapySDROutput::findThread() | ||||||
| { | { | ||||||
|     if (m_thread == 0) // this does not own the thread
 |     if (!m_thread) // this does not own the thread
 | ||||||
|     { |     { | ||||||
|         SoapySDROutputThread *soapySDROutputThread = 0; |         SoapySDROutputThread *soapySDROutputThread = nullptr; | ||||||
| 
 | 
 | ||||||
|         // find a buddy that has allocated the thread
 |         // find a buddy that has allocated the thread
 | ||||||
|         const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies(); |         const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies(); | ||||||
| @ -413,7 +413,7 @@ void SoapySDROutput::moveThreadToBuddy() | |||||||
|         if (buddySink) |         if (buddySink) | ||||||
|         { |         { | ||||||
|             buddySink->setThread(m_thread); |             buddySink->setThread(m_thread); | ||||||
|             m_thread = 0;  // zero for others
 |             m_thread = nullptr;  // zero for others
 | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -452,6 +452,11 @@ bool SoapySDROutput::start() | |||||||
|     // Note: this is quite similar to the BladeRF2 start handling. The main difference is that the channel allocation (enabling) process is
 |     // Note: this is quite similar to the BladeRF2 start handling. The main difference is that the channel allocation (enabling) process is
 | ||||||
|     // done in the thread object.
 |     // done in the thread object.
 | ||||||
| 
 | 
 | ||||||
|  |     if (!m_openSuccess) | ||||||
|  |     { | ||||||
|  |         qWarning("SoapySDROutput::start: cannot start device"); | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     if (!m_deviceShared.m_device) |     if (!m_deviceShared.m_device) | ||||||
|     { |     { | ||||||
| @ -559,7 +564,7 @@ void SoapySDROutput::stop() | |||||||
|     int requestedChannel = m_deviceAPI->getDeviceItemIndex(); |     int requestedChannel = m_deviceAPI->getDeviceItemIndex(); | ||||||
|     SoapySDROutputThread *soapySDROutputThread = findThread(); |     SoapySDROutputThread *soapySDROutputThread = findThread(); | ||||||
| 
 | 
 | ||||||
|     if (soapySDROutputThread == 0) { // no thread allocated
 |     if (!soapySDROutputThread) { // no thread allocated
 | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -570,7 +575,7 @@ void SoapySDROutput::stop() | |||||||
|         qDebug("SoapySDROutput::stop: SO mode. Just stop and delete the thread"); |         qDebug("SoapySDROutput::stop: SO mode. Just stop and delete the thread"); | ||||||
|         soapySDROutputThread->stopWork(); |         soapySDROutputThread->stopWork(); | ||||||
|         delete soapySDROutputThread; |         delete soapySDROutputThread; | ||||||
|         m_thread = 0; |         m_thread = nullptr; | ||||||
| 
 | 
 | ||||||
|         // remove old thread address from buddies (reset in all buddies)
 |         // remove old thread address from buddies (reset in all buddies)
 | ||||||
|         const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies(); |         const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies(); | ||||||
| @ -592,7 +597,7 @@ void SoapySDROutput::stop() | |||||||
|         { |         { | ||||||
|             fifos[i] = soapySDROutputThread->getFifo(i); |             fifos[i] = soapySDROutputThread->getFifo(i); | ||||||
| 
 | 
 | ||||||
|             if ((soapySDROutputThread->getFifo(i) != 0) && (i > highestActiveChannelIndex)) { |             if ((soapySDROutputThread->getFifo(i)) && (i > highestActiveChannelIndex)) { | ||||||
|                 highestActiveChannelIndex = i; |                 highestActiveChannelIndex = i; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
| @ -600,7 +605,7 @@ void SoapySDROutput::stop() | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         delete soapySDROutputThread; |         delete soapySDROutputThread; | ||||||
|         m_thread = 0; |         m_thread = nullptr; | ||||||
| 
 | 
 | ||||||
|         if (highestActiveChannelIndex >= 0) |         if (highestActiveChannelIndex >= 0) | ||||||
|         { |         { | ||||||
| @ -638,7 +643,7 @@ void SoapySDROutput::stop() | |||||||
|     else // remove channel from existing thread
 |     else // remove channel from existing thread
 | ||||||
|     { |     { | ||||||
|         qDebug("SoapySDROutput::stop: MO mode. Not changing MO configuration. Just remove FIFO reference"); |         qDebug("SoapySDROutput::stop: MO mode. Not changing MO configuration. Just remove FIFO reference"); | ||||||
|         soapySDROutputThread->setFifo(requestedChannel, 0); // remove FIFO
 |         soapySDROutputThread->setFifo(requestedChannel, nullptr); // remove FIFO
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     applySettings(m_settings, true); // re-apply forcibly to set sample rate with the new number of channels
 |     applySettings(m_settings, true); // re-apply forcibly to set sample rate with the new number of channels
 | ||||||
| @ -727,7 +732,7 @@ bool SoapySDROutput::setDeviceCenterFrequency(SoapySDR::Device *dev, int request | |||||||
| 
 | 
 | ||||||
| void SoapySDROutput::updateGains(SoapySDR::Device *dev, int requestedChannel, SoapySDROutputSettings& settings) | void SoapySDROutput::updateGains(SoapySDR::Device *dev, int requestedChannel, SoapySDROutputSettings& settings) | ||||||
| { | { | ||||||
|     if (dev == 0) { |     if (!dev) { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -747,7 +752,7 @@ void SoapySDROutput::updateGains(SoapySDR::Device *dev, int requestedChannel, So | |||||||
| 
 | 
 | ||||||
| void SoapySDROutput::updateTunableElements(SoapySDR::Device *dev, int requestedChannel, SoapySDROutputSettings& settings) | void SoapySDROutput::updateTunableElements(SoapySDR::Device *dev, int requestedChannel, SoapySDROutputSettings& settings) | ||||||
| { | { | ||||||
|     if (dev == 0) { |     if (!dev) { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -886,7 +891,7 @@ bool SoapySDROutput::applySettings(const SoapySDROutputSettings& settings, bool | |||||||
|         if (soapySDROutputThread) |         if (soapySDROutputThread) | ||||||
|         { |         { | ||||||
|             fifo = soapySDROutputThread->getFifo(requestedChannel); |             fifo = soapySDROutputThread->getFifo(requestedChannel); | ||||||
|             soapySDROutputThread->setFifo(requestedChannel, 0); |             soapySDROutputThread->setFifo(requestedChannel, nullptr); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         unsigned int fifoRate = std::max( |         unsigned int fifoRate = std::max( | ||||||
| @ -905,7 +910,7 @@ bool SoapySDROutput::applySettings(const SoapySDROutputSettings& settings, bool | |||||||
|         forwardChangeOwnDSP = true; |         forwardChangeOwnDSP = true; | ||||||
|         forwardChangeToBuddies = true; |         forwardChangeToBuddies = true; | ||||||
| 
 | 
 | ||||||
|         if (dev != 0) |         if (dev) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -936,7 +941,7 @@ bool SoapySDROutput::applySettings(const SoapySDROutputSettings& settings, bool | |||||||
|         reverseAPIKeys.append("log2Interp"); |         reverseAPIKeys.append("log2Interp"); | ||||||
|         forwardChangeOwnDSP = true; |         forwardChangeOwnDSP = true; | ||||||
| 
 | 
 | ||||||
|         if (outputThread != 0) |         if (outputThread) | ||||||
|         { |         { | ||||||
|             outputThread->setLog2Interpolation(requestedChannel, settings.m_log2Interp); |             outputThread->setLog2Interpolation(requestedChannel, settings.m_log2Interp); | ||||||
|             qDebug() << "SoapySDROutput::applySettings: set decimation to " << (1<<settings.m_log2Interp); |             qDebug() << "SoapySDROutput::applySettings: set decimation to " << (1<<settings.m_log2Interp); | ||||||
| @ -966,7 +971,7 @@ bool SoapySDROutput::applySettings(const SoapySDROutputSettings& settings, bool | |||||||
|         forwardChangeOwnDSP = true; |         forwardChangeOwnDSP = true; | ||||||
|         forwardChangeToBuddies = true; |         forwardChangeToBuddies = true; | ||||||
| 
 | 
 | ||||||
|         if (dev != 0) { |         if (dev) { | ||||||
|             setDeviceCenterFrequency(dev, requestedChannel, settings.m_centerFrequency, settings.m_LOppmTenths); |             setDeviceCenterFrequency(dev, requestedChannel, settings.m_centerFrequency, settings.m_LOppmTenths); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -975,7 +980,7 @@ bool SoapySDROutput::applySettings(const SoapySDROutputSettings& settings, bool | |||||||
|     { |     { | ||||||
|         reverseAPIKeys.append("antenna"); |         reverseAPIKeys.append("antenna"); | ||||||
| 
 | 
 | ||||||
|         if (dev != 0) |         if (dev) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -995,7 +1000,7 @@ bool SoapySDROutput::applySettings(const SoapySDROutputSettings& settings, bool | |||||||
|         reverseAPIKeys.append("bandwidth"); |         reverseAPIKeys.append("bandwidth"); | ||||||
|         forwardChangeToBuddies = true; |         forwardChangeToBuddies = true; | ||||||
| 
 | 
 | ||||||
|         if (dev != 0) |         if (dev) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -1016,7 +1021,7 @@ bool SoapySDROutput::applySettings(const SoapySDROutputSettings& settings, bool | |||||||
| 
 | 
 | ||||||
|         if (nvalue != settings.m_tunableElements.end() && ((m_settings.m_tunableElements[oname] != *nvalue) || force)) |         if (nvalue != settings.m_tunableElements.end() && ((m_settings.m_tunableElements[oname] != *nvalue) || force)) | ||||||
|         { |         { | ||||||
|             if (dev != 0) |             if (dev) | ||||||
|             { |             { | ||||||
|                 try |                 try | ||||||
|                 { |                 { | ||||||
| @ -1039,7 +1044,7 @@ bool SoapySDROutput::applySettings(const SoapySDROutputSettings& settings, bool | |||||||
|     { |     { | ||||||
|         reverseAPIKeys.append("globalGain"); |         reverseAPIKeys.append("globalGain"); | ||||||
| 
 | 
 | ||||||
|         if (dev != 0) |         if (dev) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -1061,7 +1066,7 @@ bool SoapySDROutput::applySettings(const SoapySDROutputSettings& settings, bool | |||||||
| 
 | 
 | ||||||
|         if (nvalue != settings.m_individualGains.end() && ((m_settings.m_individualGains[oname] != *nvalue) || force)) |         if (nvalue != settings.m_individualGains.end() && ((m_settings.m_individualGains[oname] != *nvalue) || force)) | ||||||
|         { |         { | ||||||
|             if (dev != 0) |             if (dev) | ||||||
|             { |             { | ||||||
|                 try |                 try | ||||||
|                 { |                 { | ||||||
| @ -1085,7 +1090,7 @@ bool SoapySDROutput::applySettings(const SoapySDROutputSettings& settings, bool | |||||||
|     { |     { | ||||||
|         reverseAPIKeys.append("autoGain"); |         reverseAPIKeys.append("autoGain"); | ||||||
| 
 | 
 | ||||||
|         if (dev != 0) |         if (dev) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -1103,7 +1108,7 @@ bool SoapySDROutput::applySettings(const SoapySDROutputSettings& settings, bool | |||||||
|     { |     { | ||||||
|         reverseAPIKeys.append("autoDCCorrection"); |         reverseAPIKeys.append("autoDCCorrection"); | ||||||
| 
 | 
 | ||||||
|         if ((dev != 0) && hasDCAutoCorrection()) |         if ((dev) && hasDCAutoCorrection()) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -1121,7 +1126,7 @@ bool SoapySDROutput::applySettings(const SoapySDROutputSettings& settings, bool | |||||||
|     { |     { | ||||||
|         reverseAPIKeys.append("dcCorrection"); |         reverseAPIKeys.append("dcCorrection"); | ||||||
| 
 | 
 | ||||||
|         if ((dev != 0) && hasDCCorrectionValue()) |         if ((dev) && hasDCCorrectionValue()) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -1139,7 +1144,7 @@ bool SoapySDROutput::applySettings(const SoapySDROutputSettings& settings, bool | |||||||
|     { |     { | ||||||
|         reverseAPIKeys.append("iqCorrection"); |         reverseAPIKeys.append("iqCorrection"); | ||||||
| 
 | 
 | ||||||
|         if ((dev != 0) && hasIQCorrectionValue()) |         if ((dev) && hasIQCorrectionValue()) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -1159,7 +1164,7 @@ bool SoapySDROutput::applySettings(const SoapySDROutputSettings& settings, bool | |||||||
| 
 | 
 | ||||||
|         if (nvalue != settings.m_streamArgSettings.end() && ((m_settings.m_streamArgSettings[oname] != *nvalue) || force)) |         if (nvalue != settings.m_streamArgSettings.end() && ((m_settings.m_streamArgSettings[oname] != *nvalue) || force)) | ||||||
|         { |         { | ||||||
|             if (dev != 0) |             if (dev) | ||||||
|             { |             { | ||||||
|                 try |                 try | ||||||
|                 { |                 { | ||||||
| @ -1184,7 +1189,7 @@ bool SoapySDROutput::applySettings(const SoapySDROutputSettings& settings, bool | |||||||
| 
 | 
 | ||||||
|         if (nvalue != settings.m_deviceArgSettings.end() && ((m_settings.m_deviceArgSettings[oname] != *nvalue) || force)) |         if (nvalue != settings.m_deviceArgSettings.end() && ((m_settings.m_deviceArgSettings[oname] != *nvalue) || force)) | ||||||
|         { |         { | ||||||
|             if (dev != 0) |             if (dev) | ||||||
|             { |             { | ||||||
|                 try |                 try | ||||||
|                 { |                 { | ||||||
|  | |||||||
| @ -193,6 +193,7 @@ public: | |||||||
| private: | private: | ||||||
|     DeviceAPI *m_deviceAPI; |     DeviceAPI *m_deviceAPI; | ||||||
|     QMutex m_mutex; |     QMutex m_mutex; | ||||||
|  |     bool m_openSuccess; | ||||||
|     SoapySDROutputSettings m_settings; |     SoapySDROutputSettings m_settings; | ||||||
|     QString m_deviceDescription; |     QString m_deviceDescription; | ||||||
|     bool m_running; |     bool m_running; | ||||||
|  | |||||||
| @ -30,6 +30,8 @@ Occasionally some devices may require to have the user specifying keyword parame | |||||||
| 
 | 
 | ||||||
| In such a case you will use the device user arguments (Preferences -> Devices -> User arguments) with the dialog as described [here](../../../sdrgui/deviceuserargs.md) | In such a case you will use the device user arguments (Preferences -> Devices -> User arguments) with the dialog as described [here](../../../sdrgui/deviceuserargs.md) | ||||||
| 
 | 
 | ||||||
|  | If you use Soapy Remote make sure you read [this Wiki page](https://github.com/f4exb/sdrangel/wiki/Soapy-Remote) first as user arguments are mandatory. | ||||||
|  | 
 | ||||||
| <h2>SoapySDR API implementation</h2> | <h2>SoapySDR API implementation</h2> | ||||||
| 
 | 
 | ||||||
| Not all parts are implemented. Currently the following have been left out: | Not all parts are implemented. Currently the following have been left out: | ||||||
|  | |||||||
| @ -47,7 +47,7 @@ SoapySDRInput::SoapySDRInput(DeviceAPI *deviceAPI) : | |||||||
|     m_thread(nullptr) |     m_thread(nullptr) | ||||||
| { | { | ||||||
|     m_sampleFifo.setLabel(m_deviceDescription); |     m_sampleFifo.setLabel(m_deviceDescription); | ||||||
|     openDevice(); |     m_openSuccess = openDevice(); | ||||||
|     initGainSettings(m_settings); |     initGainSettings(m_settings); | ||||||
|     initTunableElementsSettings(m_settings); |     initTunableElementsSettings(m_settings); | ||||||
|     initStreamArgSettings(m_settings); |     initStreamArgSettings(m_settings); | ||||||
| @ -106,7 +106,7 @@ bool SoapySDRInput::openDevice() | |||||||
|         DeviceAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0]; |         DeviceAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0]; | ||||||
|         DeviceSoapySDRShared *deviceSoapySDRShared = (DeviceSoapySDRShared*) sourceBuddy->getBuddySharedPtr(); |         DeviceSoapySDRShared *deviceSoapySDRShared = (DeviceSoapySDRShared*) sourceBuddy->getBuddySharedPtr(); | ||||||
| 
 | 
 | ||||||
|         if (deviceSoapySDRShared == 0) |         if (!deviceSoapySDRShared) | ||||||
|         { |         { | ||||||
|             qCritical("SoapySDRInput::openDevice: the source buddy shared pointer is null"); |             qCritical("SoapySDRInput::openDevice: the source buddy shared pointer is null"); | ||||||
|             return false; |             return false; | ||||||
| @ -114,7 +114,7 @@ bool SoapySDRInput::openDevice() | |||||||
| 
 | 
 | ||||||
|         SoapySDR::Device *device = deviceSoapySDRShared->m_device; |         SoapySDR::Device *device = deviceSoapySDRShared->m_device; | ||||||
| 
 | 
 | ||||||
|         if (device == 0) |         if (!device) | ||||||
|         { |         { | ||||||
|             qCritical("SoapySDRInput::openDevice: cannot get device pointer from Rx buddy"); |             qCritical("SoapySDRInput::openDevice: cannot get device pointer from Rx buddy"); | ||||||
|             return false; |             return false; | ||||||
| @ -131,7 +131,7 @@ bool SoapySDRInput::openDevice() | |||||||
|         DeviceAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0]; |         DeviceAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0]; | ||||||
|         DeviceSoapySDRShared *deviceSoapySDRShared = (DeviceSoapySDRShared*) sinkBuddy->getBuddySharedPtr(); |         DeviceSoapySDRShared *deviceSoapySDRShared = (DeviceSoapySDRShared*) sinkBuddy->getBuddySharedPtr(); | ||||||
| 
 | 
 | ||||||
|         if (deviceSoapySDRShared == 0) |         if (!deviceSoapySDRShared) | ||||||
|         { |         { | ||||||
|             qCritical("SoapySDRInput::openDevice: the sink buddy shared pointer is null"); |             qCritical("SoapySDRInput::openDevice: the sink buddy shared pointer is null"); | ||||||
|             return false; |             return false; | ||||||
| @ -139,7 +139,7 @@ bool SoapySDRInput::openDevice() | |||||||
| 
 | 
 | ||||||
|         SoapySDR::Device *device = deviceSoapySDRShared->m_device; |         SoapySDR::Device *device = deviceSoapySDRShared->m_device; | ||||||
| 
 | 
 | ||||||
|         if (device == 0) |         if (!device) | ||||||
|         { |         { | ||||||
|             qCritical("SoapySDRInput::openDevice: cannot get device pointer from Tx buddy"); |             qCritical("SoapySDRInput::openDevice: cannot get device pointer from Tx buddy"); | ||||||
|             return false; |             return false; | ||||||
| @ -172,7 +172,7 @@ bool SoapySDRInput::openDevice() | |||||||
| 
 | 
 | ||||||
| void SoapySDRInput::closeDevice() | void SoapySDRInput::closeDevice() | ||||||
| { | { | ||||||
|     if (m_deviceShared.m_device == 0) { // was never open
 |     if (!m_deviceShared.m_device) { // was never open
 | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -185,17 +185,17 @@ void SoapySDRInput::closeDevice() | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     m_deviceShared.m_channel = -1; // publicly release channel
 |     m_deviceShared.m_channel = -1; // publicly release channel
 | ||||||
|     m_deviceShared.m_source = 0; |     m_deviceShared.m_source = nullptr; | ||||||
| 
 | 
 | ||||||
|     // No buddies so effectively close the device and delete parameters
 |     // No buddies so effectively close the device and delete parameters
 | ||||||
| 
 | 
 | ||||||
|     if ((m_deviceAPI->getSinkBuddies().size() == 0) && (m_deviceAPI->getSourceBuddies().size() == 0)) |     if ((m_deviceAPI->getSinkBuddies().size() == 0) && (m_deviceAPI->getSourceBuddies().size() == 0)) | ||||||
|     { |     { | ||||||
|         delete m_deviceShared.m_deviceParams; |         delete m_deviceShared.m_deviceParams; | ||||||
|         m_deviceShared.m_deviceParams = 0; |         m_deviceShared.m_deviceParams = nullptr; | ||||||
|         DeviceSoapySDR& deviceSoapySDR = DeviceSoapySDR::instance(); |         DeviceSoapySDR& deviceSoapySDR = DeviceSoapySDR::instance(); | ||||||
|         deviceSoapySDR.closeSoapySdr(m_deviceShared.m_device); |         deviceSoapySDR.closeSoapySdr(m_deviceShared.m_device); | ||||||
|         m_deviceShared.m_device = 0; |         m_deviceShared.m_device = nullptr; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -399,7 +399,7 @@ SoapySDRInputThread *SoapySDRInput::findThread() | |||||||
| { | { | ||||||
|     if (!m_thread) // this does not own the thread
 |     if (!m_thread) // this does not own the thread
 | ||||||
|     { |     { | ||||||
|         SoapySDRInputThread *soapySDRInputThread = 0; |         SoapySDRInputThread *soapySDRInputThread = nullptr; | ||||||
| 
 | 
 | ||||||
|         // find a buddy that has allocated the thread
 |         // find a buddy that has allocated the thread
 | ||||||
|         const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies(); |         const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies(); | ||||||
| @ -480,6 +480,12 @@ bool SoapySDRInput::start() | |||||||
|     // Note: this is quite similar to the BladeRF2 start handling. The main difference is that the channel allocation (enabling) process is
 |     // Note: this is quite similar to the BladeRF2 start handling. The main difference is that the channel allocation (enabling) process is
 | ||||||
|     // done in the thread object.
 |     // done in the thread object.
 | ||||||
| 
 | 
 | ||||||
|  |     if (!m_openSuccess) | ||||||
|  |     { | ||||||
|  |         qWarning("SoapySDRInput::start: cannot start device"); | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     if (!m_deviceShared.m_device) |     if (!m_deviceShared.m_device) | ||||||
|     { |     { | ||||||
|         qDebug("SoapySDRInput::start: no device object"); |         qDebug("SoapySDRInput::start: no device object"); | ||||||
| @ -595,7 +601,7 @@ void SoapySDRInput::stop() | |||||||
|     int requestedChannel = m_deviceAPI->getDeviceItemIndex(); |     int requestedChannel = m_deviceAPI->getDeviceItemIndex(); | ||||||
|     SoapySDRInputThread *soapySDRInputThread = findThread(); |     SoapySDRInputThread *soapySDRInputThread = findThread(); | ||||||
| 
 | 
 | ||||||
|     if (soapySDRInputThread == 0) { // no thread allocated
 |     if (!soapySDRInputThread) { // no thread allocated
 | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -678,7 +684,7 @@ void SoapySDRInput::stop() | |||||||
|     else // remove channel from existing thread
 |     else // remove channel from existing thread
 | ||||||
|     { |     { | ||||||
|         qDebug("SoapySDRInput::stop: MI mode. Not changing MI configuration. Just remove FIFO reference"); |         qDebug("SoapySDRInput::stop: MI mode. Not changing MI configuration. Just remove FIFO reference"); | ||||||
|         soapySDRInputThread->setFifo(requestedChannel, 0); // remove FIFO
 |         soapySDRInputThread->setFifo(requestedChannel, nullptr); // remove FIFO
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     m_running = false; |     m_running = false; | ||||||
| @ -750,7 +756,7 @@ bool SoapySDRInput::setDeviceCenterFrequency(SoapySDR::Device *dev, int requeste | |||||||
| 
 | 
 | ||||||
| void SoapySDRInput::updateGains(SoapySDR::Device *dev, int requestedChannel, SoapySDRInputSettings& settings) | void SoapySDRInput::updateGains(SoapySDR::Device *dev, int requestedChannel, SoapySDRInputSettings& settings) | ||||||
| { | { | ||||||
|     if (dev == 0) { |     if (!dev) { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -770,7 +776,7 @@ void SoapySDRInput::updateGains(SoapySDR::Device *dev, int requestedChannel, Soa | |||||||
| 
 | 
 | ||||||
| void SoapySDRInput::updateTunableElements(SoapySDR::Device *dev, int requestedChannel, SoapySDRInputSettings& settings) | void SoapySDRInput::updateTunableElements(SoapySDR::Device *dev, int requestedChannel, SoapySDRInputSettings& settings) | ||||||
| { | { | ||||||
|     if (dev == 0) { |     if (!dev) { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -925,7 +931,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo | |||||||
|         forwardChangeOwnDSP = true; |         forwardChangeOwnDSP = true; | ||||||
|         forwardChangeToBuddies = true; |         forwardChangeToBuddies = true; | ||||||
| 
 | 
 | ||||||
|         if (dev != 0) |         if (dev) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -1020,7 +1026,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo | |||||||
|         forwardChangeOwnDSP = true; |         forwardChangeOwnDSP = true; | ||||||
|         forwardChangeToBuddies = true; |         forwardChangeToBuddies = true; | ||||||
| 
 | 
 | ||||||
|         if (dev != 0) { |         if (dev) { | ||||||
|             setDeviceCenterFrequency(dev, requestedChannel, deviceCenterFrequency, settings.m_LOppmTenths); |             setDeviceCenterFrequency(dev, requestedChannel, deviceCenterFrequency, settings.m_LOppmTenths); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -1029,7 +1035,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo | |||||||
|     { |     { | ||||||
|         reverseAPIKeys.append("antenna"); |         reverseAPIKeys.append("antenna"); | ||||||
| 
 | 
 | ||||||
|         if (dev != 0) |         if (dev) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -1049,7 +1055,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo | |||||||
|         reverseAPIKeys.append("bandwidth"); |         reverseAPIKeys.append("bandwidth"); | ||||||
|         forwardChangeToBuddies = true; |         forwardChangeToBuddies = true; | ||||||
| 
 | 
 | ||||||
|         if (dev != 0) |         if (dev) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -1070,7 +1076,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo | |||||||
| 
 | 
 | ||||||
|         if (nvalue != settings.m_tunableElements.end() && ((m_settings.m_tunableElements[oname] != *nvalue) ||force)) |         if (nvalue != settings.m_tunableElements.end() && ((m_settings.m_tunableElements[oname] != *nvalue) ||force)) | ||||||
|         { |         { | ||||||
|             if (dev != 0) |             if (dev) | ||||||
|             { |             { | ||||||
|                 try |                 try | ||||||
|                 { |                 { | ||||||
| @ -1093,7 +1099,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo | |||||||
|     { |     { | ||||||
|         reverseAPIKeys.append("globalGain"); |         reverseAPIKeys.append("globalGain"); | ||||||
| 
 | 
 | ||||||
|         if (dev != 0) |         if (dev) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -1115,7 +1121,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo | |||||||
| 
 | 
 | ||||||
|         if (nvalue != settings.m_individualGains.end() && ((m_settings.m_individualGains[oname] != *nvalue) || force)) |         if (nvalue != settings.m_individualGains.end() && ((m_settings.m_individualGains[oname] != *nvalue) || force)) | ||||||
|         { |         { | ||||||
|             if (dev != 0) |             if (dev) | ||||||
|             { |             { | ||||||
|                 try |                 try | ||||||
|                 { |                 { | ||||||
| @ -1139,7 +1145,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo | |||||||
|     { |     { | ||||||
|         reverseAPIKeys.append("autoGain"); |         reverseAPIKeys.append("autoGain"); | ||||||
| 
 | 
 | ||||||
|         if (dev != 0) |         if (dev) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -1157,7 +1163,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo | |||||||
|     { |     { | ||||||
|         reverseAPIKeys.append("autoDCCorrection"); |         reverseAPIKeys.append("autoDCCorrection"); | ||||||
| 
 | 
 | ||||||
|         if ((dev != 0) && hasDCAutoCorrection()) |         if ((dev) && hasDCAutoCorrection()) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -1175,7 +1181,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo | |||||||
|     { |     { | ||||||
|         reverseAPIKeys.append("dcCorrection"); |         reverseAPIKeys.append("dcCorrection"); | ||||||
| 
 | 
 | ||||||
|         if ((dev != 0) && hasDCCorrectionValue()) |         if ((dev) && hasDCCorrectionValue()) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -1193,7 +1199,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo | |||||||
|     { |     { | ||||||
|         reverseAPIKeys.append("iqCorrection"); |         reverseAPIKeys.append("iqCorrection"); | ||||||
| 
 | 
 | ||||||
|         if ((dev != 0) && hasIQCorrectionValue()) |         if ((dev) && hasIQCorrectionValue()) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
| @ -1213,7 +1219,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo | |||||||
| 
 | 
 | ||||||
|         if (nvalue != settings.m_streamArgSettings.end() && ((m_settings.m_streamArgSettings[oname] != *nvalue) || force)) |         if (nvalue != settings.m_streamArgSettings.end() && ((m_settings.m_streamArgSettings[oname] != *nvalue) || force)) | ||||||
|         { |         { | ||||||
|             if (dev != 0) |             if (dev) | ||||||
|             { |             { | ||||||
|                 try |                 try | ||||||
|                 { |                 { | ||||||
| @ -1238,7 +1244,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo | |||||||
| 
 | 
 | ||||||
|         if (nvalue != settings.m_deviceArgSettings.end() && ((m_settings.m_deviceArgSettings[oname] != *nvalue) || force)) |         if (nvalue != settings.m_deviceArgSettings.end() && ((m_settings.m_deviceArgSettings[oname] != *nvalue) || force)) | ||||||
|         { |         { | ||||||
|             if (dev != 0) |             if (dev) | ||||||
|             { |             { | ||||||
|                 try |                 try | ||||||
|                 { |                 { | ||||||
|  | |||||||
| @ -195,6 +195,7 @@ public: | |||||||
| private: | private: | ||||||
|     DeviceAPI *m_deviceAPI; |     DeviceAPI *m_deviceAPI; | ||||||
|     QMutex m_mutex; |     QMutex m_mutex; | ||||||
|  |     bool m_openSuccess; | ||||||
|     SoapySDRInputSettings m_settings; |     SoapySDRInputSettings m_settings; | ||||||
|     QString m_deviceDescription; |     QString m_deviceDescription; | ||||||
|     bool m_running; |     bool m_running; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user