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

View file

@ -56,7 +56,7 @@ public class RFSpy {
private UUID radioServiceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO);
private UUID radioDataUUID = UUID.fromString(GattAttributes.CHARA_RADIO_DATA);
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 String bleVersion; // We don't use it so no need of sofisticated logic
private Double currentFrequencyMHz;
@ -421,14 +421,7 @@ public class RFSpy {
}
public RFSpyResponse resetRileyLink() {
RFSpyResponse resp = null;
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;
public void stopReader() {
reader.stop();
}
}

View file

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

View file

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

View file

@ -160,6 +160,14 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
this.serviceTaskExecutor = serviceTaskExecutor;
displayConnectionMessages = false;
}
@Override
protected void onStart() {
super.onStart();
aapsLogger.debug(LTag.PUMP, this.deviceID() + " started.");
serviceConnection = new ServiceConnection() {
@ -186,12 +194,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}).start();
}
};
}
@Override
protected void onStart() {
super.onStart();
}
@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() {
try {
String regexSN = "[0-9]{6}";

View file

@ -118,9 +118,10 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
private Profile currentProfile;
boolean omnipodServiceRunning = false;
//boolean omnipodServiceRunning = false;
private long nextPodCheck = 0L;
protected boolean isOmnipodEros = true;
//OmnipodDriverState driverState = OmnipodDriverState.NotInitalized;
@Inject
@ -157,71 +158,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
this.omnipodUtil = omnipodUtil;
this.omnipodPumpStatus = omnipodPumpStatus;
//OmnipodUtil.setDriverState();
// TODO loop
// if (OmnipodUtil.isOmnipodEros()) {
// OmnipodUtil.setPlugin(this);
// OmnipodUtil.setOmnipodPodType(OmnipodPodType.Eros);
// OmnipodUtil.setPumpType(PumpType.Insulet_Omnipod);
// }
// // TODO ccc
serviceConnection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
aapsLogger.debug(LTag.PUMP, "RileyLinkOmnipodService is disconnected");
rileyLinkOmnipodService = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
aapsLogger.debug(LTag.PUMP, "RileyLinkOmnipodService is connected");
RileyLinkOmnipodService.LocalBinder mLocalBinder = (RileyLinkOmnipodService.LocalBinder) service;
rileyLinkOmnipodService = mLocalBinder.getServiceInstance();
new Thread(() -> {
for (int i = 0; i < 20; i++) {
SystemClock.sleep(5000);
aapsLogger.debug(LTag.PUMP, "Starting Omnipod-RileyLink service");
if (rileyLinkOmnipodService.setNotInPreInit()) {
break;
}
}
// if (OmnipodPumpPlugin.this.omnipodPumpStatus != null) {
//
// aapsLogger.debug(LTag.PUMP, "Starting OmniPod-RileyLink service");
// if (omnipodService.setNotInPreInit()) {
// if (omnipodCommunicationManager == null) {
// omnipodCommunicationManager = AapsOmnipodManager.getInstance();
// omnipodCommunicationManager.setPumpStatus(OmnipodPumpPlugin.this.omnipodPumpStatus);
// omnipodServiceRunning = true;
// } else {
// omnipodCommunicationManager.setPumpStatus(OmnipodPumpPlugin.this.omnipodPumpStatus);
// }
//
// omnipodUtil.setOmnipodPodType(OmnipodPodType.Eros);
// //omnipodUtil.setPlugin(OmnipodPumpPlugin.this);
//
// omnipodUIComm = new OmnipodUIComm(omnipodCommunicationManager, plugin, OmnipodPumpPlugin.this.omnipodPumpStatus);
// break;
// }
// }
//
// SystemClock.sleep(5000);
//}
}).start();
}
};
this.isOmnipodEros = true;
}
protected OmnipodPumpPlugin(PluginDescription pluginDescription, PumpType pumpType,
@ -248,6 +185,76 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override
protected void onStart() {
super.onStart();
//OmnipodUtil.setDriverState();
// TODO loop
// if (OmnipodUtil.isOmnipodEros()) {
// OmnipodUtil.setPlugin(this);
// OmnipodUtil.setOmnipodPodType(OmnipodPodType.Eros);
// OmnipodUtil.setPumpType(PumpType.Insulet_Omnipod);
// }
// // TODO ccc
if (isOmnipodEros) {
serviceConnection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
aapsLogger.debug(LTag.PUMP, "RileyLinkOmnipodService is disconnected");
rileyLinkOmnipodService = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
aapsLogger.debug(LTag.PUMP, "RileyLinkOmnipodService is connected");
RileyLinkOmnipodService.LocalBinder mLocalBinder = (RileyLinkOmnipodService.LocalBinder) service;
rileyLinkOmnipodService = mLocalBinder.getServiceInstance();
new Thread(() -> {
for (int i = 0; i < 20; i++) {
SystemClock.sleep(5000);
aapsLogger.debug(LTag.PUMP, "Starting Omnipod-RileyLink service");
if (rileyLinkOmnipodService.setNotInPreInit()) {
break;
}
}
// if (OmnipodPumpPlugin.this.omnipodPumpStatus != null) {
//
// aapsLogger.debug(LTag.PUMP, "Starting OmniPod-RileyLink service");
// if (omnipodService.setNotInPreInit()) {
// if (omnipodCommunicationManager == null) {
// omnipodCommunicationManager = AapsOmnipodManager.getInstance();
// omnipodCommunicationManager.setPumpStatus(OmnipodPumpPlugin.this.omnipodPumpStatus);
// omnipodServiceRunning = true;
// } else {
// omnipodCommunicationManager.setPumpStatus(OmnipodPumpPlugin.this.omnipodPumpStatus);
// }
//
// omnipodUtil.setOmnipodPodType(OmnipodPodType.Eros);
// //omnipodUtil.setPlugin(OmnipodPumpPlugin.this);
//
// omnipodUIComm = new OmnipodUIComm(omnipodCommunicationManager, plugin, OmnipodPumpPlugin.this.omnipodPumpStatus);
// break;
// }
// }
//
// SystemClock.sleep(5000);
//}
}).start();
}
};
}
disposable.add(rxBus
.toObservable(EventPreferenceChange.class)
.observeOn(Schedulers.io())
@ -261,6 +268,9 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
rileyLinkOmnipodService.verifyConfiguration();
}, fabricPrivacy::logException)
);
//rileyLinkOmnipodService.verifyConfiguration();
//initPumpStatusData();
}

View file

@ -116,12 +116,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
if (sp.contains(OmnipodConst.Prefs.PodState) && omnipodUtil.getPodSessionState() == null) {
try {
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) {
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
public String deviceID() {
return "Omnipod Dash";