mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-11-04 05:30:32 -05:00 
			
		
		
		
	HackRF: open device by serial number
This commit is contained in:
		
							parent
							
								
									01b2c42a5f
								
							
						
					
					
						commit
						0a29f34b94
					
				@ -33,6 +33,33 @@ hackrf_device *DeviceHackRF::open_hackrf(int sequence)
 | 
				
			|||||||
    return open_hackrf_from_sequence(sequence);
 | 
					    return open_hackrf_from_sequence(sequence);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					hackrf_device *DeviceHackRF::open_hackrf(const char * const serial)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    hackrf_error rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // TODO: this may not work if several HackRF Devices are running concurrently. It should be handled globally in the application
 | 
				
			||||||
 | 
					    rc = (hackrf_error) hackrf_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (rc != HACKRF_SUCCESS)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        fprintf(stderr, "DeviceHackRF::open_hackrf: failed to initiate HackRF library %s\n", hackrf_error_name(rc));
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    hackrf_device *hackrf_ptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    rc = (hackrf_error) hackrf_open_by_serial(serial, &hackrf_ptr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (rc == HACKRF_SUCCESS)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return hackrf_ptr;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
hackrf_device *DeviceHackRF::open_hackrf_from_sequence(int sequence)
 | 
					hackrf_device *DeviceHackRF::open_hackrf_from_sequence(int sequence)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    hackrf_device_list_t *hackrf_devices = hackrf_device_list();
 | 
					    hackrf_device_list_t *hackrf_devices = hackrf_device_list();
 | 
				
			||||||
 | 
				
			|||||||
@ -23,6 +23,7 @@ class DeviceHackRF
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    static hackrf_device *open_hackrf(int sequence);
 | 
					    static hackrf_device *open_hackrf(int sequence);
 | 
				
			||||||
 | 
					    static hackrf_device *open_hackrf(const char * const serial);
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    static hackrf_device *open_hackrf_from_sequence(int sequence);
 | 
					    static hackrf_device *open_hackrf_from_sequence(int sequence);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -60,7 +60,6 @@ bool HackRFOutput::openDevice()
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_sampleSourceFifo.resize(m_settings.m_devSampleRate/(1<<(m_settings.m_log2Interp <= 4 ? m_settings.m_log2Interp : 4)));
 | 
					    m_sampleSourceFifo.resize(m_settings.m_devSampleRate/(1<<(m_settings.m_log2Interp <= 4 ? m_settings.m_log2Interp : 4)));
 | 
				
			||||||
    int device = m_deviceAPI->getSampleSinkSequence();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (m_deviceAPI->getSourceBuddies().size() > 0)
 | 
					    if (m_deviceAPI->getSourceBuddies().size() > 0)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -84,9 +83,9 @@ bool HackRFOutput::openDevice()
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if ((m_dev = DeviceHackRF::open_hackrf(device)) == 0)
 | 
					        if ((m_dev = DeviceHackRF::open_hackrf(qPrintable(m_deviceAPI->getSampleSinkSerial()))) == 0)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            qCritical("HackRFOutput::openDevice: could not open HackRF #%d", device);
 | 
					            qCritical("HackRFOutput::openDevice: could not open HackRF %s", qPrintable(m_deviceAPI->getSampleSinkSerial()));
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -65,8 +65,6 @@ bool HackRFInput::openDevice()
 | 
				
			|||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int device = m_deviceAPI->getSampleSourceSequence();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (m_deviceAPI->getSinkBuddies().size() > 0)
 | 
					    if (m_deviceAPI->getSinkBuddies().size() > 0)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        DeviceSinkAPI *buddy = m_deviceAPI->getSinkBuddies()[0];
 | 
					        DeviceSinkAPI *buddy = m_deviceAPI->getSinkBuddies()[0];
 | 
				
			||||||
@ -89,9 +87,9 @@ bool HackRFInput::openDevice()
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if ((m_dev = DeviceHackRF::open_hackrf(device)) == 0)
 | 
					        if ((m_dev = DeviceHackRF::open_hackrf(qPrintable(m_deviceAPI->getSampleSourceSerial()))) == 0)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            qCritical("HackRFInput::openDevice: could not open HackRF #%d", device);
 | 
					            qCritical("HackRFInput::openDevice: could not open HackRF %s", qPrintable(m_deviceAPI->getSampleSourceSerial()));
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user