mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
#1221 resolves null pointer exception in tuner editor when attempting to restart an error tuner. (#1222)
Co-authored-by: Dennis Sheirer <dsheirer@github.com>
This commit is contained in:
@@ -54,6 +54,8 @@ public enum TunerClass
|
||||
public static final EnumSet<TunerClass> SUPPORTED_USB_TUNERS = EnumSet.of(AIRSPY, HACKRF, RTL2832,
|
||||
FUNCUBE_DONGLE_PRO, FUNCUBE_DONGLE_PRO_PLUS);
|
||||
|
||||
public static final EnumSet<TunerClass> FUNCUBE_TUNERS = EnumSet.of(FUNCUBE_DONGLE_PRO, FUNCUBE_DONGLE_PRO_PLUS);
|
||||
|
||||
/**
|
||||
* Indicates if this tuner class entry is a supported USB tuner class.
|
||||
*/
|
||||
@@ -62,6 +64,14 @@ public enum TunerClass
|
||||
return SUPPORTED_USB_TUNERS.contains(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the tuner class is a funcube dongle with a matching sound card interface
|
||||
*/
|
||||
public boolean isFuncubeTuner()
|
||||
{
|
||||
return FUNCUBE_TUNERS.contains(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a USB tuner class from the USB vid and pid
|
||||
* @param vendor id
|
||||
|
||||
@@ -104,7 +104,7 @@ public class AirspyTunerEditor extends TunerEditor<AirspyTuner, AirspyTunerConfi
|
||||
getFrequencyPanel().updateControls();
|
||||
getSampleRateCombo().setEnabled(hasTuner() && !getTuner().getTunerController().isLocked());
|
||||
getTunerInfoButton().setEnabled(hasTuner());
|
||||
updateGainComponents(hasTuner() ? getConfiguration().getGain() : null);
|
||||
updateGainComponents((hasTuner() && hasConfiguration()) ? getConfiguration().getGain() : null);
|
||||
|
||||
if(hasTuner())
|
||||
{
|
||||
|
||||
@@ -60,11 +60,28 @@ public abstract class DiscoveredTuner implements ITunerErrorListener
|
||||
* Sets the status of the discovered tuner and notifies registered listeners of the status change.
|
||||
* @param tunerStatus to set
|
||||
*/
|
||||
protected void setTunerStatus(TunerStatus tunerStatus)
|
||||
private void setTunerStatus(TunerStatus tunerStatus)
|
||||
{
|
||||
TunerStatus previous = mTunerStatus;
|
||||
mTunerStatus = tunerStatus;
|
||||
broadcast(this, previous, mTunerStatus);
|
||||
setTunerStatus(tunerStatus, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status of the discovered tuner and optionally notifies registered listeners of the status change.
|
||||
* @param tunerStatus to set
|
||||
* @param notifyListeners true to notify and false to not notify
|
||||
*/
|
||||
private void setTunerStatus(TunerStatus tunerStatus, boolean notifyListeners)
|
||||
{
|
||||
if(mTunerStatus != tunerStatus)
|
||||
{
|
||||
TunerStatus previous = mTunerStatus;
|
||||
mTunerStatus = tunerStatus;
|
||||
|
||||
if(notifyListeners)
|
||||
{
|
||||
broadcast(this, previous, mTunerStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,8 +232,9 @@ public abstract class DiscoveredTuner implements ITunerErrorListener
|
||||
public void setErrorMessage(String errorMessage)
|
||||
{
|
||||
mErrorMessage = errorMessage;
|
||||
setTunerStatus(TunerStatus.ERROR);
|
||||
mLog.info("Tuner Error - Stopping - " + getId() + " Error: " + errorMessage);
|
||||
stop();
|
||||
setTunerStatus(TunerStatus.ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,7 +264,7 @@ public abstract class DiscoveredTuner implements ITunerErrorListener
|
||||
/**
|
||||
* Attempts to restart a tuner that's currently in an error state
|
||||
*/
|
||||
public void reset()
|
||||
public void restart()
|
||||
{
|
||||
if(getTunerStatus() == TunerStatus.ERROR)
|
||||
{
|
||||
@@ -254,7 +272,9 @@ public abstract class DiscoveredTuner implements ITunerErrorListener
|
||||
|
||||
if(isEnabled())
|
||||
{
|
||||
//Change status to enabled so that we can attempt to start, but don't notify listeners yet.
|
||||
setTunerStatus(TunerStatus.ENABLED);
|
||||
start();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -109,20 +109,9 @@ public class DiscoveredUSBTuner extends DiscoveredTuner
|
||||
}
|
||||
catch(SourceException se)
|
||||
{
|
||||
|
||||
//Set error message to flag this tuner with error status and invoke stop()
|
||||
setErrorMessage(se.getMessage());
|
||||
|
||||
mLog.error("Unable to start tuner [" + getTunerClass() + "] - error: " + getErrorMessage());
|
||||
|
||||
try
|
||||
{
|
||||
stop();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//No-op on attempted cleanup
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,9 +241,9 @@ public class TunerManager implements IDiscoveredTunerStatusListener
|
||||
* @param bus usb for the tuner
|
||||
* @param port usb for the tuner
|
||||
*/
|
||||
private void removeUsbTuner(int bus, int port)
|
||||
private DiscoveredTuner removeUsbTuner(int bus, int port)
|
||||
{
|
||||
mDiscoveredTunerModel.removeUsbTuner(bus, port);
|
||||
return mDiscoveredTunerModel.removeUsbTuner(bus, port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -489,12 +489,26 @@ public class TunerManager implements IDiscoveredTunerStatusListener
|
||||
|
||||
if(tunerClass.isSupportedUsbTuner())
|
||||
{
|
||||
addUsbTuner(bus, port, tunerClass);
|
||||
if(tunerClass.isFuncubeTuner())
|
||||
{
|
||||
//Funcube tuners take a few momements to setup the sound card interface. Delay adding
|
||||
//the tuner so that it can be started correctly.
|
||||
ThreadPool.SCHEDULED.schedule(() -> addUsbTuner(bus, port, tunerClass), 2, TimeUnit.SECONDS);
|
||||
}
|
||||
else
|
||||
{
|
||||
addUsbTuner(bus, port, tunerClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LibUsb.HOTPLUG_EVENT_DEVICE_LEFT:
|
||||
removeUsbTuner(bus, port);
|
||||
DiscoveredTuner removed = removeUsbTuner(bus, port);
|
||||
|
||||
if(removed != null)
|
||||
{
|
||||
mLog.info("Tuner Unplugged: " + removed.getId());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -246,8 +246,10 @@ public class DiscoveredTunerModel extends AbstractTableModel implements Listener
|
||||
* @param bus usb
|
||||
* @param port usb
|
||||
*/
|
||||
public void removeUsbTuner(int bus, int port)
|
||||
public DiscoveredTuner removeUsbTuner(int bus, int port)
|
||||
{
|
||||
DiscoveredTuner removed = null;
|
||||
|
||||
mLock.lock();
|
||||
|
||||
try
|
||||
@@ -259,12 +261,15 @@ public class DiscoveredTunerModel extends AbstractTableModel implements Listener
|
||||
if(discoveredTuner != null)
|
||||
{
|
||||
removeDiscoveredTuner(discoveredTuner);
|
||||
removed = discoveredTuner;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
mLock.unlock();
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,6 @@ import io.github.dsheirer.source.tuner.manager.IDiscoveredTunerStatusListener;
|
||||
import io.github.dsheirer.source.tuner.manager.TunerManager;
|
||||
import io.github.dsheirer.source.tuner.manager.TunerStatus;
|
||||
import io.github.dsheirer.util.SwingUtils;
|
||||
import io.github.dsheirer.util.ThreadPool;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -372,11 +371,7 @@ public abstract class TunerEditor<T extends Tuner,C extends TunerConfiguration>
|
||||
if(!hasTuner() && getDiscoveredTuner().getTunerStatus() == TunerStatus.ERROR)
|
||||
{
|
||||
mLog.info("Restarting " + getDiscoveredTuner().getTunerClass() + " tuner");
|
||||
getDiscoveredTuner().reset();
|
||||
if(getDiscoveredTuner().isEnabled())
|
||||
{
|
||||
ThreadPool.CACHED.submit(() -> getDiscoveredTuner().start());
|
||||
}
|
||||
getDiscoveredTuner().restart();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -469,15 +464,18 @@ public abstract class TunerEditor<T extends Tuner,C extends TunerConfiguration>
|
||||
@Override
|
||||
public void tunerStatusUpdated(DiscoveredTuner discoveredTuner, TunerStatus previous, TunerStatus current)
|
||||
{
|
||||
SwingUtils.run(() -> tunerStatusUpdated());
|
||||
|
||||
if(current == TunerStatus.ENABLED)
|
||||
SwingUtils.run(() ->
|
||||
{
|
||||
if(hasTuner())
|
||||
tunerStatusUpdated();
|
||||
|
||||
if(current == TunerStatus.ENABLED)
|
||||
{
|
||||
getTuner().addTunerEventListener(this);
|
||||
if(hasTuner())
|
||||
{
|
||||
getTuner().addTunerEventListener(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -507,12 +505,7 @@ public abstract class TunerEditor<T extends Tuner,C extends TunerConfiguration>
|
||||
{
|
||||
mDiscoveredTuner.getTuner().removeTunerEventListener(this);
|
||||
}
|
||||
|
||||
mDiscoveredTuner = null;
|
||||
}
|
||||
|
||||
mUserPreferences = null;
|
||||
mTunerManager = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user