- changes on service starting (moved from cnst to onStart method)

- change RileyLinkBLE to stop reader
- added log for start and stop of service
This commit is contained in:
Andy Rozman 2020-05-10 14:08:56 +01:00
parent c00d6344e5
commit 80f5b3cf4b
9 changed files with 112 additions and 105 deletions

View file

@ -114,10 +114,13 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
public abstract void initPumpStatusData(); public abstract void initPumpStatusData();
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
// TODO: moved from constructor .... test if it works
aapsLogger.debug(LTag.PUMP, this.deviceID() + " onStart()");
initPumpStatusData(); initPumpStatusData();
Intent intent = new Intent(context, getServiceClass()); Intent intent = new Intent(context, getServiceClass());
@ -136,6 +139,8 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
@Override @Override
protected void onStop() { protected void onStop() {
aapsLogger.debug(LTag.PUMP, this.deviceID() + " onStop()");
context.unbindService(serviceConnection); context.unbindService(serviceConnection);
serviceRunning = false; serviceRunning = false;

View file

@ -56,7 +56,7 @@ public class RFSpy {
private UUID radioServiceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO); private UUID radioServiceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO);
private UUID radioDataUUID = UUID.fromString(GattAttributes.CHARA_RADIO_DATA); private UUID radioDataUUID = UUID.fromString(GattAttributes.CHARA_RADIO_DATA);
private UUID radioVersionUUID = UUID.fromString(GattAttributes.CHARA_RADIO_VERSION); private UUID radioVersionUUID = UUID.fromString(GattAttributes.CHARA_RADIO_VERSION);
private UUID responseCountUUID = UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT); //private UUID responseCountUUID = UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT);
private RileyLinkFirmwareVersion firmwareVersion; private RileyLinkFirmwareVersion firmwareVersion;
private String bleVersion; // We don't use it so no need of sofisticated logic private String bleVersion; // We don't use it so no need of sofisticated logic
private Double currentFrequencyMHz; private Double currentFrequencyMHz;
@ -421,14 +421,7 @@ public class RFSpy {
} }
public RFSpyResponse resetRileyLink() { public void stopReader() {
RFSpyResponse resp = null; reader.stop();
try {
resp = writeToData(new Reset(), EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
aapsLogger.debug(LTag.PUMPBTCOMM, "Reset command send, response: {}", resp);
} catch (Exception e) {
e.toString();
}
return resp;
} }
} }

View file

@ -29,11 +29,12 @@ public class RFSpyReader {
private int acquireCount = 0; private int acquireCount = 0;
private int releaseCount = 0; private int releaseCount = 0;
private boolean stopAtNull = true; private boolean stopAtNull = true;
private static boolean isRunning = false;
RFSpyReader(AAPSLogger aapsLogger, RileyLinkBLE rileyLinkBle) { RFSpyReader(AAPSLogger aapsLogger, RileyLinkBLE rileyLinkBle) {
this.rileyLinkBle = rileyLinkBle;
this.aapsLogger = aapsLogger; this.aapsLogger = aapsLogger;
setRileyLinkBle(rileyLinkBle);
} }
@ -87,6 +88,8 @@ public class RFSpyReader {
public void start() { public void start() {
isRunning = true;
readerTask = new AsyncTask<Void, Void, Void>() { readerTask = new AsyncTask<Void, Void, Void>() {
@Override @Override
@ -94,7 +97,7 @@ public class RFSpyReader {
UUID serviceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO); UUID serviceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO);
UUID radioDataUUID = UUID.fromString(GattAttributes.CHARA_RADIO_DATA); UUID radioDataUUID = UUID.fromString(GattAttributes.CHARA_RADIO_DATA);
BLECommOperationResult result; BLECommOperationResult result;
while (true) { while (isRunning) {
try { try {
acquireCount++; acquireCount++;
waitForRadioData.acquire(); waitForRadioData.acquire();
@ -129,7 +132,13 @@ public class RFSpyReader {
aapsLogger.error(LTag.PUMPBTCOMM, "Interrupted while waiting for data"); aapsLogger.error(LTag.PUMPBTCOMM, "Interrupted while waiting for data");
} }
} }
return null;
} }
}.execute(); }.execute();
} }
public void stop() {
isRunning = false;
}
} }

View file

@ -101,6 +101,7 @@ public abstract class RileyLinkService extends DaggerService {
super.onDestroy(); super.onDestroy();
//LOG.error("I die! I die!"); //LOG.error("I die! I die!");
rfspy.stopReader();
rileyLinkBLE.disconnect(); // dispose of Gatt (disconnect and close) rileyLinkBLE.disconnect(); // dispose of Gatt (disconnect and close)
if (mBroadcastReceiver != null) { if (mBroadcastReceiver != null) {

View file

@ -160,6 +160,14 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
this.serviceTaskExecutor = serviceTaskExecutor; this.serviceTaskExecutor = serviceTaskExecutor;
displayConnectionMessages = false; displayConnectionMessages = false;
}
@Override
protected void onStart() {
super.onStart();
aapsLogger.debug(LTag.PUMP, this.deviceID() + " started.");
serviceConnection = new ServiceConnection() { serviceConnection = new ServiceConnection() {
@ -186,12 +194,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}).start(); }).start();
} }
}; };
}
@Override
protected void onStart() {
super.onStart();
} }
@Override @Override

View file

@ -187,21 +187,6 @@ public class RileyLinkMedtronicService extends RileyLinkService {
} }
@Override
public String getDeviceSpecificBroadcastsIdentifierPrefix() {
return null;
}
public boolean handleDeviceSpecificBroadcasts(Intent intent) {
return false;
}
@Override
public void registerDeviceSpecificBroadcasts(IntentFilter intentFilter) {
}
public boolean verifyConfiguration() { public boolean verifyConfiguration() {
try { try {
String regexSN = "[0-9]{6}"; String regexSN = "[0-9]{6}";

View file

@ -118,9 +118,10 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
private Profile currentProfile; private Profile currentProfile;
boolean omnipodServiceRunning = false; //boolean omnipodServiceRunning = false;
private long nextPodCheck = 0L; private long nextPodCheck = 0L;
protected boolean isOmnipodEros = true;
//OmnipodDriverState driverState = OmnipodDriverState.NotInitalized; //OmnipodDriverState driverState = OmnipodDriverState.NotInitalized;
@Inject @Inject
@ -157,6 +158,34 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
this.omnipodUtil = omnipodUtil; this.omnipodUtil = omnipodUtil;
this.omnipodPumpStatus = omnipodPumpStatus; this.omnipodPumpStatus = omnipodPumpStatus;
this.isOmnipodEros = true;
}
protected OmnipodPumpPlugin(PluginDescription pluginDescription, PumpType pumpType,
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
Context context,
ResourceHelper resourceHelper,
ActivePluginProvider activePlugin,
info.nightscout.androidaps.utils.sharedPreferences.SP sp,
CommandQueueProvider commandQueue,
FabricPrivacy fabricPrivacy) {
super(pluginDescription, pumpType, injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy);
}
@Deprecated
public static OmnipodPumpPlugin getPlugin() {
if (plugin == null)
throw new IllegalStateException("Plugin not injected jet");
return plugin;
}
@Override
protected void onStart() {
super.onStart();
//OmnipodUtil.setDriverState(); //OmnipodUtil.setDriverState();
// TODO loop // TODO loop
@ -168,6 +197,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
// // TODO ccc // // TODO ccc
if (isOmnipodEros) {
serviceConnection = new ServiceConnection() { serviceConnection = new ServiceConnection() {
@ -224,30 +254,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
}; };
} }
protected OmnipodPumpPlugin(PluginDescription pluginDescription, PumpType pumpType,
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
Context context,
ResourceHelper resourceHelper,
ActivePluginProvider activePlugin,
info.nightscout.androidaps.utils.sharedPreferences.SP sp,
CommandQueueProvider commandQueue,
FabricPrivacy fabricPrivacy) {
super(pluginDescription, pumpType, injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy);
}
@Deprecated
public static OmnipodPumpPlugin getPlugin() {
if (plugin == null)
throw new IllegalStateException("Plugin not injected jet");
return plugin;
}
@Override
protected void onStart() {
super.onStart();
disposable.add(rxBus disposable.add(rxBus
.toObservable(EventPreferenceChange.class) .toObservable(EventPreferenceChange.class)
.observeOn(Schedulers.io()) .observeOn(Schedulers.io())
@ -261,6 +268,9 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
rileyLinkOmnipodService.verifyConfiguration(); rileyLinkOmnipodService.verifyConfiguration();
}, fabricPrivacy::logException) }, fabricPrivacy::logException)
); );
//rileyLinkOmnipodService.verifyConfiguration(); //rileyLinkOmnipodService.verifyConfiguration();
//initPumpStatusData(); //initPumpStatusData();
} }

View file

@ -116,12 +116,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
if (sp.contains(OmnipodConst.Prefs.PodState) && omnipodUtil.getPodSessionState() == null) { if (sp.contains(OmnipodConst.Prefs.PodState) && omnipodUtil.getPodSessionState() == null) {
try { try {
omnipodUtil.loadSessionState(); omnipodUtil.loadSessionState();
// Gson gson = omnipodUtil.getGsonInstance();
// String storedPodState = sp.getString(OmnipodConst.Prefs.PodState, "");
// aapsLogger.info(LTag.PUMPCOMM, "PodSessionState-SP: loaded from SharedPreferences: " + storedPodState);
// podState = gson.fromJson(storedPodState, PodSessionState.class);
// podState.injectDaggerClass(injector);
// omnipodUtil.setPodSessionState(podState);
} catch (Exception ex) { } catch (Exception ex) {
aapsLogger.error(LTag.PUMPCOMM, "Could not deserialize Pod state", ex); aapsLogger.error(LTag.PUMPCOMM, "Could not deserialize Pod state", ex);
} }

View file

@ -152,6 +152,13 @@ public class OmnipodDashPumpPlugin extends OmnipodPumpPlugin implements OmnipodP
} }
@Override
public void onStart() {
this.isOmnipodEros = false;
super.onStart();
}
@Override @Override
public String deviceID() { public String deviceID() {
return "Omnipod Dash"; return "Omnipod Dash";