MDT refactor pass 11
This commit is contained in:
parent
85558620fc
commit
6add8a8d86
20 changed files with 255 additions and 301 deletions
|
@ -30,6 +30,8 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOref1Thread
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOref1Thread
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobThread
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobThread
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioResponse
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.*
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.*
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUITask
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUITask
|
||||||
|
@ -199,6 +201,8 @@ interface AppComponent : AndroidInjector<MainApp> {
|
||||||
fun injectInitializePumpManagerTask(initializePumpManagerTask: InitializePumpManagerTask)
|
fun injectInitializePumpManagerTask(initializePumpManagerTask: InitializePumpManagerTask)
|
||||||
fun injectResetRileyLinkConfigurationTask(resetRileyLinkConfigurationTask: ResetRileyLinkConfigurationTask)
|
fun injectResetRileyLinkConfigurationTask(resetRileyLinkConfigurationTask: ResetRileyLinkConfigurationTask)
|
||||||
fun injectWakeAndTuneTask(wakeAndTuneTask: WakeAndTuneTask)
|
fun injectWakeAndTuneTask(wakeAndTuneTask: WakeAndTuneTask)
|
||||||
|
fun injectRadioResponse(radioResponse: RadioResponse)
|
||||||
|
fun injectRileyLinkBLE(rileyLinkBLE: RileyLinkBLE)
|
||||||
|
|
||||||
@Component.Builder
|
@Component.Builder
|
||||||
interface Builder {
|
interface Builder {
|
||||||
|
|
|
@ -47,6 +47,8 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOref1Thread
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOref1Thread
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobThread
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobThread
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioResponse
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.*
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.*
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUITask
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUITask
|
||||||
|
@ -292,6 +294,8 @@ open class AppModule {
|
||||||
@ContributesAndroidInjector fun initializePumpManagerTaskProvider(): InitializePumpManagerTask
|
@ContributesAndroidInjector fun initializePumpManagerTaskProvider(): InitializePumpManagerTask
|
||||||
@ContributesAndroidInjector fun resetRileyLinkConfigurationTaskProvider(): ResetRileyLinkConfigurationTask
|
@ContributesAndroidInjector fun resetRileyLinkConfigurationTaskProvider(): ResetRileyLinkConfigurationTask
|
||||||
@ContributesAndroidInjector fun wakeAndTuneTaskProvider(): WakeAndTuneTask
|
@ContributesAndroidInjector fun wakeAndTuneTaskProvider(): WakeAndTuneTask
|
||||||
|
@ContributesAndroidInjector fun radioResponseProvider(): RadioResponse
|
||||||
|
@ContributesAndroidInjector fun rileyLinkBLEProvider(): RileyLinkBLE
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
fun bindActivePluginProvider(pluginStore: PluginStore): ActivePluginProvider
|
fun bindActivePluginProvider(pluginStore: PluginStore): ActivePluginProvider
|
||||||
|
|
|
@ -49,7 +49,6 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
protected String receiverDeviceID; // String representation of receiver device (ex. Pump (xxxxxx) or Pod (yyyyyy))
|
protected String receiverDeviceID; // String representation of receiver device (ex. Pump (xxxxxx) or Pod (yyyyyy))
|
||||||
protected long lastGoodReceiverCommunicationTime = 0;
|
protected long lastGoodReceiverCommunicationTime = 0;
|
||||||
// protected PumpStatus pumpStatus;
|
// protected PumpStatus pumpStatus;
|
||||||
protected RileyLinkServiceData rileyLinkServiceData;
|
|
||||||
private long nextWakeUpRequired = 0L;
|
private long nextWakeUpRequired = 0L;
|
||||||
|
|
||||||
private int timeoutCount = 0;
|
private int timeoutCount = 0;
|
||||||
|
@ -59,7 +58,6 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
injector.androidInjector().inject(this);
|
injector.androidInjector().inject(this);
|
||||||
this.rfspy = rfspy;
|
this.rfspy = rfspy;
|
||||||
this.rileyLinkServiceData = rileyLinkUtil.getRileyLinkServiceData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,7 +90,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
RFSpyResponse rfSpyResponse = rfspy.transmitThenReceive(new RadioPacket(msg.getTxData()),
|
RFSpyResponse rfSpyResponse = rfspy.transmitThenReceive(new RadioPacket(msg.getTxData()),
|
||||||
(byte) 0, (byte) repeatCount, (byte) 0, (byte) 0, timeout_ms, (byte) retryCount, extendPreamble_ms);
|
(byte) 0, (byte) repeatCount, (byte) 0, (byte) 0, timeout_ms, (byte) retryCount, extendPreamble_ms);
|
||||||
|
|
||||||
RadioResponse radioResponse = rfSpyResponse.getRadioResponse();
|
RadioResponse radioResponse = rfSpyResponse.getRadioResponse(injector);
|
||||||
E response = createResponseMessage(radioResponse.getPayload(), clazz);
|
E response = createResponseMessage(radioResponse.getPayload(), clazz);
|
||||||
|
|
||||||
if (response.isValid()) {
|
if (response.isValid()) {
|
||||||
|
@ -122,7 +120,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showPumpMessages) {
|
if (showPumpMessages) {
|
||||||
aapsLogger.info(LTag.PUMPBTCOMM, "Received:" + ByteUtil.shortHexString(rfSpyResponse.getRadioResponse().getPayload()));
|
aapsLogger.info(LTag.PUMPBTCOMM, "Received:" + ByteUtil.shortHexString(rfSpyResponse.getRadioResponse(injector).getPayload()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
@ -246,7 +244,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
if (resp.wasTimeout()) {
|
if (resp.wasTimeout()) {
|
||||||
aapsLogger.error(LTag.PUMPBTCOMM, "scanForPump: Failed to find pump at frequency {}", frequencies[i]);
|
aapsLogger.error(LTag.PUMPBTCOMM, "scanForPump: Failed to find pump at frequency {}", frequencies[i]);
|
||||||
} else if (resp.looksLikeRadioPacket()) {
|
} else if (resp.looksLikeRadioPacket()) {
|
||||||
RadioResponse radioResponse = new RadioResponse();
|
RadioResponse radioResponse = new RadioResponse(injector);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -334,7 +332,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
if (resp.wasTimeout()) {
|
if (resp.wasTimeout()) {
|
||||||
aapsLogger.warn(LTag.PUMPBTCOMM, "tune_tryFrequency: no pump response at frequency {}", freqMHz);
|
aapsLogger.warn(LTag.PUMPBTCOMM, "tune_tryFrequency: no pump response at frequency {}", freqMHz);
|
||||||
} else if (resp.looksLikeRadioPacket()) {
|
} else if (resp.looksLikeRadioPacket()) {
|
||||||
RadioResponse radioResponse = new RadioResponse();
|
RadioResponse radioResponse = new RadioResponse(injector);
|
||||||
try {
|
try {
|
||||||
radioResponse.init(resp.getRaw());
|
radioResponse.init(resp.getRaw());
|
||||||
|
|
||||||
|
|
|
@ -46,13 +46,12 @@ import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicDe
|
||||||
@Singleton
|
@Singleton
|
||||||
public class RileyLinkUtil {
|
public class RileyLinkUtil {
|
||||||
|
|
||||||
public List<RLHistoryItem> historyRileyLink = new ArrayList<>();
|
private List<RLHistoryItem> historyRileyLink = new ArrayList<>();
|
||||||
public RileyLinkCommunicationManager rileyLinkCommunicationManager;
|
public RileyLinkCommunicationManager rileyLinkCommunicationManager;
|
||||||
|
@Deprecated
|
||||||
static ServiceTask currentTask;
|
static ServiceTask currentTask;
|
||||||
private RileyLinkServiceData rileyLinkServiceData;
|
|
||||||
private RileyLinkTargetFrequency rileyLinkTargetFrequency;
|
private RileyLinkTargetFrequency rileyLinkTargetFrequency;
|
||||||
|
|
||||||
private RileyLinkTargetDevice targetDevice;
|
|
||||||
private RileyLinkEncodingType encoding;
|
private RileyLinkEncodingType encoding;
|
||||||
private RileyLinkSelectPreference rileyLinkSelectPreference;
|
private RileyLinkSelectPreference rileyLinkSelectPreference;
|
||||||
private Encoding4b6b encoding4b6b;
|
private Encoding4b6b encoding4b6b;
|
||||||
|
@ -104,62 +103,8 @@ public class RileyLinkUtil {
|
||||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setServiceState(RileyLinkServiceState newState) {
|
|
||||||
setServiceState(newState, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RileyLinkServiceState getServiceState() {
|
|
||||||
return workWithServiceState(null, null, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setServiceState(RileyLinkServiceState newState, RileyLinkError errorCode) {
|
|
||||||
workWithServiceState(newState, errorCode, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private synchronized RileyLinkServiceState workWithServiceState(RileyLinkServiceState newState,
|
|
||||||
RileyLinkError errorCode, boolean set) {
|
|
||||||
|
|
||||||
if (set) {
|
|
||||||
|
|
||||||
rileyLinkServiceData.serviceState = newState;
|
|
||||||
rileyLinkServiceData.errorCode = errorCode;
|
|
||||||
|
|
||||||
aapsLogger.info(LTag.PUMP, "RileyLink State Changed: {} {}", newState, errorCode == null ? "" : " - Error State: "
|
|
||||||
+ errorCode.name());
|
|
||||||
|
|
||||||
historyRileyLink.add(new RLHistoryItem(rileyLinkServiceData.serviceState,
|
|
||||||
rileyLinkServiceData.errorCode, targetDevice));
|
|
||||||
rxBus.send(new EventMedtronicDeviceStatusChange(newState, errorCode));
|
|
||||||
return null;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return (rileyLinkServiceData == null || rileyLinkServiceData.serviceState == null) ? //
|
|
||||||
RileyLinkServiceState.NotStarted
|
|
||||||
: rileyLinkServiceData.serviceState;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public RileyLinkServiceData getRileyLinkServiceData() {
|
|
||||||
return rileyLinkServiceData;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setRileyLinkServiceData(RileyLinkServiceData rileyLinkServiceData) {
|
|
||||||
this.rileyLinkServiceData = rileyLinkServiceData;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean hasPumpBeenTunned() {
|
|
||||||
return rileyLinkServiceData.tuneUpDone;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME remove ?
|
// FIXME remove ?
|
||||||
|
@Deprecated
|
||||||
public static void setCurrentTask(ServiceTask task) {
|
public static void setCurrentTask(ServiceTask task) {
|
||||||
if (currentTask == null) {
|
if (currentTask == null) {
|
||||||
currentTask = task;
|
currentTask = task;
|
||||||
|
@ -169,6 +114,7 @@ public class RileyLinkUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static void finishCurrentTask(ServiceTask task) {
|
public static void finishCurrentTask(ServiceTask task) {
|
||||||
if (task != currentTask) {
|
if (task != currentTask) {
|
||||||
//LOG.error("finishCurrentTask: task does not match");
|
//LOG.error("finishCurrentTask: task does not match");
|
||||||
|
@ -257,42 +203,26 @@ public class RileyLinkUtil {
|
||||||
return new BleAdvertisedData(uuids, name);
|
return new BleAdvertisedData(uuids, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<RLHistoryItem> getRileyLinkHistory() {
|
public List<RLHistoryItem> getRileyLinkHistory() {
|
||||||
return historyRileyLink;
|
return historyRileyLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public RileyLinkTargetDevice getTargetDevice() {
|
|
||||||
return targetDevice;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setTargetDevice(RileyLinkTargetDevice targetDevice) {
|
|
||||||
this.targetDevice = targetDevice;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setRileyLinkSelectPreference(RileyLinkSelectPreference rileyLinkSelectPreference) {
|
public void setRileyLinkSelectPreference(RileyLinkSelectPreference rileyLinkSelectPreference) {
|
||||||
this.rileyLinkSelectPreference = rileyLinkSelectPreference;
|
this.rileyLinkSelectPreference = rileyLinkSelectPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public RileyLinkSelectPreference getRileyLinkSelectPreference() {
|
public RileyLinkSelectPreference getRileyLinkSelectPreference() {
|
||||||
return rileyLinkSelectPreference;
|
return rileyLinkSelectPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Encoding4b6b getEncoding4b6b() {
|
public Encoding4b6b getEncoding4b6b() {
|
||||||
return encoding4b6b;
|
return encoding4b6b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setFirmwareVersion(RileyLinkFirmwareVersion firmwareVersion) {
|
public void setFirmwareVersion(RileyLinkFirmwareVersion firmwareVersion) {
|
||||||
this.firmwareVersion = firmwareVersion;
|
this.firmwareVersion = firmwareVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public RileyLinkFirmwareVersion getFirmwareVersion() {
|
public RileyLinkFirmwareVersion getFirmwareVersion() {
|
||||||
return firmwareVersion;
|
return firmwareVersion;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,15 +12,16 @@ import android.content.Context;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
|
|
||||||
import info.nightscout.androidaps.logging.L;
|
import javax.inject.Inject;
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
|
||||||
|
import dagger.android.HasAndroidInjector;
|
||||||
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.GattAttributes;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.GattAttributes;
|
||||||
|
@ -31,6 +32,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.operation
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.operations.DescriptorWriteOperation;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.operations.DescriptorWriteOperation;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.ThreadUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.ThreadUtil;
|
||||||
|
|
||||||
|
@ -40,7 +42,9 @@ import info.nightscout.androidaps.plugins.pump.common.utils.ThreadUtil;
|
||||||
*/
|
*/
|
||||||
public class RileyLinkBLE {
|
public class RileyLinkBLE {
|
||||||
|
|
||||||
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPBTCOMM);
|
@Inject AAPSLogger aapsLogger;
|
||||||
|
@Inject RileyLinkServiceData rileyLinkServiceData;
|
||||||
|
@Inject RileyLinkUtil rileyLinkUtil;
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
public boolean gattDebugEnabled = true;
|
public boolean gattDebugEnabled = true;
|
||||||
|
@ -55,24 +59,24 @@ public class RileyLinkBLE {
|
||||||
private boolean mIsConnected = false;
|
private boolean mIsConnected = false;
|
||||||
|
|
||||||
|
|
||||||
public RileyLinkBLE(final Context context) {
|
public RileyLinkBLE(HasAndroidInjector injector, final Context context) {
|
||||||
|
injector.androidInjector().inject(this);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "BT Adapter: " + this.bluetoothAdapter);
|
||||||
LOG.debug("BT Adapter: " + this.bluetoothAdapter);
|
|
||||||
bluetoothGattCallback = new BluetoothGattCallback() {
|
bluetoothGattCallback = new BluetoothGattCallback() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicChanged(final BluetoothGatt gatt,
|
public void onCharacteristicChanged(final BluetoothGatt gatt,
|
||||||
final BluetoothGattCharacteristic characteristic) {
|
final BluetoothGattCharacteristic characteristic) {
|
||||||
super.onCharacteristicChanged(gatt, characteristic);
|
super.onCharacteristicChanged(gatt, characteristic);
|
||||||
if (gattDebugEnabled && isLogEnabled()) {
|
if (gattDebugEnabled) {
|
||||||
LOG.trace(ThreadUtil.sig() + "onCharacteristicChanged "
|
aapsLogger.debug(LTag.PUMPBTCOMM, ThreadUtil.sig() + "onCharacteristicChanged "
|
||||||
+ GattAttributes.lookup(characteristic.getUuid()) + " "
|
+ GattAttributes.lookup(characteristic.getUuid()) + " "
|
||||||
+ ByteUtil.getHex(characteristic.getValue()));
|
+ ByteUtil.getHex(characteristic.getValue()));
|
||||||
if (characteristic.getUuid().equals(UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT))) {
|
if (characteristic.getUuid().equals(UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT))) {
|
||||||
LOG.debug("Response Count is " + ByteUtil.shortHexString(characteristic.getValue()));
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Response Count is " + ByteUtil.shortHexString(characteristic.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (radioResponseCountNotified != null) {
|
if (radioResponseCountNotified != null) {
|
||||||
|
@ -87,8 +91,8 @@ public class RileyLinkBLE {
|
||||||
super.onCharacteristicRead(gatt, characteristic, status);
|
super.onCharacteristicRead(gatt, characteristic, status);
|
||||||
|
|
||||||
final String statusMessage = getGattStatusMessage(status);
|
final String statusMessage = getGattStatusMessage(status);
|
||||||
if (gattDebugEnabled && isLogEnabled()) {
|
if (gattDebugEnabled) {
|
||||||
LOG.trace(ThreadUtil.sig() + "onCharacteristicRead ("
|
aapsLogger.debug(LTag.PUMPBTCOMM, ThreadUtil.sig() + "onCharacteristicRead ("
|
||||||
+ GattAttributes.lookup(characteristic.getUuid()) + ") " + statusMessage + ":"
|
+ GattAttributes.lookup(characteristic.getUuid()) + ") " + statusMessage + ":"
|
||||||
+ ByteUtil.getHex(characteristic.getValue()));
|
+ ByteUtil.getHex(characteristic.getValue()));
|
||||||
}
|
}
|
||||||
|
@ -102,8 +106,8 @@ public class RileyLinkBLE {
|
||||||
super.onCharacteristicWrite(gatt, characteristic, status);
|
super.onCharacteristicWrite(gatt, characteristic, status);
|
||||||
|
|
||||||
final String uuidString = GattAttributes.lookup(characteristic.getUuid());
|
final String uuidString = GattAttributes.lookup(characteristic.getUuid());
|
||||||
if (gattDebugEnabled && isLogEnabled()) {
|
if (gattDebugEnabled) {
|
||||||
LOG.trace(ThreadUtil.sig() + "onCharacteristicWrite " + getGattStatusMessage(status) + " "
|
aapsLogger.debug(LTag.PUMPBTCOMM, ThreadUtil.sig() + "onCharacteristicWrite " + getGattStatusMessage(status) + " "
|
||||||
+ uuidString + " " + ByteUtil.shortHexString(characteristic.getValue()));
|
+ uuidString + " " + ByteUtil.shortHexString(characteristic.getValue()));
|
||||||
}
|
}
|
||||||
mCurrentOperation.gattOperationCompletionCallback(characteristic.getUuid(), characteristic.getValue());
|
mCurrentOperation.gattOperationCompletionCallback(characteristic.getUuid(), characteristic.getValue());
|
||||||
|
@ -116,7 +120,7 @@ public class RileyLinkBLE {
|
||||||
|
|
||||||
// https://github.com/NordicSemiconductor/puck-central-android/blob/master/PuckCentral/app/src/main/java/no/nordicsemi/puckcentral/bluetooth/gatt/GattManager.java#L117
|
// https://github.com/NordicSemiconductor/puck-central-android/blob/master/PuckCentral/app/src/main/java/no/nordicsemi/puckcentral/bluetooth/gatt/GattManager.java#L117
|
||||||
if (status == 133) {
|
if (status == 133) {
|
||||||
LOG.error("Got the status 133 bug, closing gatt");
|
aapsLogger.error(LTag.PUMPBTCOMM, "Got the status 133 bug, closing gatt");
|
||||||
disconnect();
|
disconnect();
|
||||||
SystemClock.sleep(500);
|
SystemClock.sleep(500);
|
||||||
return;
|
return;
|
||||||
|
@ -136,29 +140,27 @@ public class RileyLinkBLE {
|
||||||
stateMessage = "UNKNOWN newState (" + newState + ")";
|
stateMessage = "UNKNOWN newState (" + newState + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.warn(LTag.PUMPBTCOMM, "onConnectionStateChange " + getGattStatusMessage(status) + " " + stateMessage);
|
||||||
LOG.warn("onConnectionStateChange " + getGattStatusMessage(status) + " " + stateMessage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newState == BluetoothProfile.STATE_CONNECTED) {
|
if (newState == BluetoothProfile.STATE_CONNECTED) {
|
||||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||||
RileyLinkUtil.getInstance().sendBroadcastMessage(RileyLinkConst.Intents.BluetoothConnected);
|
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.BluetoothConnected);
|
||||||
} else {
|
} else {
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "BT State connected, GATT status {} ({})", status, getGattStatusMessage(status));
|
||||||
LOG.debug("BT State connected, GATT status {} ({})", status, getGattStatusMessage(status));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ((newState == BluetoothProfile.STATE_CONNECTING) || //
|
} else if ((newState == BluetoothProfile.STATE_CONNECTING) || //
|
||||||
(newState == BluetoothProfile.STATE_DISCONNECTING)) {
|
(newState == BluetoothProfile.STATE_DISCONNECTING)) {
|
||||||
// LOG.debug("We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" :
|
// aapsLogger.debug(LTag.PUMPBTCOMM,"We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" :
|
||||||
// "Disconnecting");
|
// "Disconnecting");
|
||||||
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
|
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
|
||||||
RileyLinkUtil.getInstance().sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnected);
|
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnected);
|
||||||
if (manualDisconnect)
|
if (manualDisconnect)
|
||||||
close();
|
close();
|
||||||
LOG.warn("RileyLink Disconnected.");
|
aapsLogger.warn(LTag.PUMPBTCOMM, "RileyLink Disconnected.");
|
||||||
} else {
|
} else {
|
||||||
LOG.warn("Some other state: (status={},newState={})", status, newState);
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Some other state: (status={},newState={})", status, newState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,8 +168,8 @@ public class RileyLinkBLE {
|
||||||
@Override
|
@Override
|
||||||
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
||||||
super.onDescriptorWrite(gatt, descriptor, status);
|
super.onDescriptorWrite(gatt, descriptor, status);
|
||||||
if (gattDebugEnabled && isLogEnabled()) {
|
if (gattDebugEnabled) {
|
||||||
LOG.warn("onDescriptorWrite " + GattAttributes.lookup(descriptor.getUuid()) + " "
|
aapsLogger.warn(LTag.PUMPBTCOMM, "onDescriptorWrite " + GattAttributes.lookup(descriptor.getUuid()) + " "
|
||||||
+ getGattStatusMessage(status) + " written: " + ByteUtil.getHex(descriptor.getValue()));
|
+ getGattStatusMessage(status) + " written: " + ByteUtil.getHex(descriptor.getValue()));
|
||||||
}
|
}
|
||||||
mCurrentOperation.gattOperationCompletionCallback(descriptor.getUuid(), descriptor.getValue());
|
mCurrentOperation.gattOperationCompletionCallback(descriptor.getUuid(), descriptor.getValue());
|
||||||
|
@ -178,8 +180,8 @@ public class RileyLinkBLE {
|
||||||
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
||||||
super.onDescriptorRead(gatt, descriptor, status);
|
super.onDescriptorRead(gatt, descriptor, status);
|
||||||
mCurrentOperation.gattOperationCompletionCallback(descriptor.getUuid(), descriptor.getValue());
|
mCurrentOperation.gattOperationCompletionCallback(descriptor.getUuid(), descriptor.getValue());
|
||||||
if (gattDebugEnabled && isLogEnabled()) {
|
if (gattDebugEnabled) {
|
||||||
LOG.warn("onDescriptorRead " + getGattStatusMessage(status) + " status " + descriptor);
|
aapsLogger.warn(LTag.PUMPBTCOMM, "onDescriptorRead " + getGattStatusMessage(status) + " status " + descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,8 +189,8 @@ public class RileyLinkBLE {
|
||||||
@Override
|
@Override
|
||||||
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
|
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
|
||||||
super.onMtuChanged(gatt, mtu, status);
|
super.onMtuChanged(gatt, mtu, status);
|
||||||
if (gattDebugEnabled && isLogEnabled()) {
|
if (gattDebugEnabled) {
|
||||||
LOG.warn("onMtuChanged " + mtu + " status " + status);
|
aapsLogger.warn(LTag.PUMPBTCOMM, "onMtuChanged " + mtu + " status " + status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,8 +198,8 @@ public class RileyLinkBLE {
|
||||||
@Override
|
@Override
|
||||||
public void onReadRemoteRssi(final BluetoothGatt gatt, int rssi, int status) {
|
public void onReadRemoteRssi(final BluetoothGatt gatt, int rssi, int status) {
|
||||||
super.onReadRemoteRssi(gatt, rssi, status);
|
super.onReadRemoteRssi(gatt, rssi, status);
|
||||||
if (gattDebugEnabled && isLogEnabled()) {
|
if (gattDebugEnabled) {
|
||||||
LOG.warn("onReadRemoteRssi " + getGattStatusMessage(status) + ": " + rssi);
|
aapsLogger.warn(LTag.PUMPBTCOMM, "onReadRemoteRssi " + getGattStatusMessage(status) + ": " + rssi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,8 +207,8 @@ public class RileyLinkBLE {
|
||||||
@Override
|
@Override
|
||||||
public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
|
public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
|
||||||
super.onReliableWriteCompleted(gatt, status);
|
super.onReliableWriteCompleted(gatt, status);
|
||||||
if (gattDebugEnabled && isLogEnabled()) {
|
if (gattDebugEnabled) {
|
||||||
LOG.warn("onReliableWriteCompleted status " + status);
|
aapsLogger.warn(LTag.PUMPBTCOMM, "onReliableWriteCompleted status " + status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,27 +234,26 @@ public class RileyLinkBLE {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gattDebugEnabled && isLogEnabled()) {
|
if (gattDebugEnabled) {
|
||||||
LOG.warn("onServicesDiscovered " + getGattStatusMessage(status));
|
aapsLogger.warn(LTag.PUMPBTCOMM, "onServicesDiscovered " + getGattStatusMessage(status));
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.info("Gatt device is RileyLink device: " + rileyLinkFound);
|
aapsLogger.info(LTag.PUMPBTCOMM, "Gatt device is RileyLink device: " + rileyLinkFound);
|
||||||
|
|
||||||
if (rileyLinkFound) {
|
if (rileyLinkFound) {
|
||||||
mIsConnected = true;
|
mIsConnected = true;
|
||||||
RileyLinkUtil.getInstance().sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkReady);
|
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkReady);
|
||||||
// RileyLinkUtil.sendNotification(new
|
// RileyLinkUtil.sendNotification(new
|
||||||
// ServiceNotification(RileyLinkConst.Intents.RileyLinkReady), null);
|
// ServiceNotification(RileyLinkConst.Intents.RileyLinkReady), null);
|
||||||
} else {
|
} else {
|
||||||
mIsConnected = false;
|
mIsConnected = false;
|
||||||
RileyLinkUtil.getInstance().setServiceState(RileyLinkServiceState.RileyLinkError,
|
rileyLinkServiceData.setServiceState(RileyLinkServiceState.RileyLinkError,
|
||||||
RileyLinkError.DeviceIsNotRileyLink);
|
RileyLinkError.DeviceIsNotRileyLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "onServicesDiscovered " + getGattStatusMessage(status));
|
||||||
LOG.debug("onServicesDiscovered " + getGattStatusMessage(status));
|
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkGattFailed);
|
||||||
RileyLinkUtil.getInstance().sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkGattFailed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -261,9 +262,7 @@ public class RileyLinkBLE {
|
||||||
|
|
||||||
private boolean isAnyRileyLinkServiceFound(BluetoothGattService service) {
|
private boolean isAnyRileyLinkServiceFound(BluetoothGattService service) {
|
||||||
|
|
||||||
boolean found = false;
|
boolean found = GattAttributes.isRileyLink(service.getUuid());
|
||||||
|
|
||||||
found = GattAttributes.isRileyLink(service.getUuid());
|
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -313,7 +312,7 @@ public class RileyLinkBLE {
|
||||||
|
|
||||||
stringBuilder.append("\n\n");
|
stringBuilder.append("\n\n");
|
||||||
|
|
||||||
LOG.warn(stringBuilder.toString());
|
aapsLogger.warn(LTag.PUMPBTCOMM, stringBuilder.toString());
|
||||||
|
|
||||||
List<BluetoothGattService> includedServices = service.getIncludedServices();
|
List<BluetoothGattService> includedServices = service.getIncludedServices();
|
||||||
|
|
||||||
|
@ -324,7 +323,7 @@ public class RileyLinkBLE {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void registerRadioResponseCountNotification(Runnable notifier) {
|
void registerRadioResponseCountNotification(Runnable notifier) {
|
||||||
radioResponseCountNotified = notifier;
|
radioResponseCountNotified = notifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,11 +341,10 @@ public class RileyLinkBLE {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bluetoothConnectionGatt.discoverServices()) {
|
if (bluetoothConnectionGatt.discoverServices()) {
|
||||||
if (isLogEnabled())
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Starting to discover GATT Services.");
|
||||||
LOG.warn("Starting to discover GATT Services.");
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LOG.error("Cannot discover GATT Services.");
|
aapsLogger.error(LTag.PUMPBTCOMM, "Cannot discover GATT Services.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,7 +354,7 @@ public class RileyLinkBLE {
|
||||||
BLECommOperationResult result = setNotification_blocking(UUID.fromString(GattAttributes.SERVICE_RADIO), //
|
BLECommOperationResult result = setNotification_blocking(UUID.fromString(GattAttributes.SERVICE_RADIO), //
|
||||||
UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT));
|
UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT));
|
||||||
if (result.resultCode != BLECommOperationResult.RESULT_SUCCESS) {
|
if (result.resultCode != BLECommOperationResult.RESULT_SUCCESS) {
|
||||||
LOG.error("Error setting response count notification");
|
aapsLogger.error(LTag.PUMPBTCOMM, "Error setting response count notification");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -364,36 +362,34 @@ public class RileyLinkBLE {
|
||||||
|
|
||||||
|
|
||||||
public void findRileyLink(String RileyLinkAddress) {
|
public void findRileyLink(String RileyLinkAddress) {
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "RileyLink address: " + RileyLinkAddress);
|
||||||
LOG.debug("RileyLink address: " + RileyLinkAddress);
|
|
||||||
// Must verify that this is a valid MAC, or crash.
|
// Must verify that this is a valid MAC, or crash.
|
||||||
|
|
||||||
rileyLinkDevice = bluetoothAdapter.getRemoteDevice(RileyLinkAddress);
|
rileyLinkDevice = bluetoothAdapter.getRemoteDevice(RileyLinkAddress);
|
||||||
// if this succeeds, we get a connection state change callback?
|
// if this succeeds, we get a connection state change callback?
|
||||||
|
|
||||||
if (rileyLinkDevice!=null) {
|
if (rileyLinkDevice != null) {
|
||||||
connectGatt();
|
connectGatt();
|
||||||
} else {
|
} else {
|
||||||
LOG.error("RileyLink device not found with address: " + RileyLinkAddress);
|
aapsLogger.error(LTag.PUMPBTCOMM, "RileyLink device not found with address: " + RileyLinkAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// This function must be run on UI thread.
|
// This function must be run on UI thread.
|
||||||
public void connectGatt() {
|
public void connectGatt() {
|
||||||
if (this.rileyLinkDevice==null) {
|
if (this.rileyLinkDevice == null) {
|
||||||
LOG.error("RileyLink device is null, can't do connectGatt.");
|
aapsLogger.error(LTag.PUMPBTCOMM, "RileyLink device is null, can't do connectGatt.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bluetoothConnectionGatt = rileyLinkDevice.connectGatt(context, true, bluetoothGattCallback);
|
bluetoothConnectionGatt = rileyLinkDevice.connectGatt(context, true, bluetoothGattCallback);
|
||||||
// , BluetoothDevice.TRANSPORT_LE
|
// , BluetoothDevice.TRANSPORT_LE
|
||||||
if (bluetoothConnectionGatt == null) {
|
if (bluetoothConnectionGatt == null) {
|
||||||
LOG.error("Failed to connect to Bluetooth Low Energy device at " + bluetoothAdapter.getAddress());
|
aapsLogger.error(LTag.PUMPBTCOMM, "Failed to connect to Bluetooth Low Energy device at " + bluetoothAdapter.getAddress());
|
||||||
} else {
|
} else {
|
||||||
if (gattDebugEnabled) {
|
if (gattDebugEnabled) {
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Gatt Connected.");
|
||||||
LOG.debug("Gatt Connected.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -401,8 +397,7 @@ public class RileyLinkBLE {
|
||||||
|
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
mIsConnected = false;
|
mIsConnected = false;
|
||||||
if (isLogEnabled())
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Closing GATT connection");
|
||||||
LOG.warn("Closing GATT connection");
|
|
||||||
// Close old conenction
|
// Close old conenction
|
||||||
if (bluetoothConnectionGatt != null) {
|
if (bluetoothConnectionGatt != null) {
|
||||||
// Not sure if to disconnect or to close first..
|
// Not sure if to disconnect or to close first..
|
||||||
|
@ -420,7 +415,7 @@ public class RileyLinkBLE {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public BLECommOperationResult setNotification_blocking(UUID serviceUUID, UUID charaUUID) {
|
private BLECommOperationResult setNotification_blocking(UUID serviceUUID, UUID charaUUID) {
|
||||||
BLECommOperationResult rval = new BLECommOperationResult();
|
BLECommOperationResult rval = new BLECommOperationResult();
|
||||||
if (bluetoothConnectionGatt != null) {
|
if (bluetoothConnectionGatt != null) {
|
||||||
|
|
||||||
|
@ -428,7 +423,7 @@ public class RileyLinkBLE {
|
||||||
gattOperationSema.acquire();
|
gattOperationSema.acquire();
|
||||||
SystemClock.sleep(1); // attempting to yield thread, to make sequence of events easier to follow
|
SystemClock.sleep(1); // attempting to yield thread, to make sequence of events easier to follow
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOG.error("setNotification_blocking: interrupted waiting for gattOperationSema");
|
aapsLogger.error(LTag.PUMPBTCOMM, "setNotification_blocking: interrupted waiting for gattOperationSema");
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
if (mCurrentOperation != null) {
|
if (mCurrentOperation != null) {
|
||||||
|
@ -437,7 +432,7 @@ public class RileyLinkBLE {
|
||||||
if (bluetoothConnectionGatt.getService(serviceUUID) == null) {
|
if (bluetoothConnectionGatt.getService(serviceUUID) == null) {
|
||||||
// Catch if the service is not supported by the BLE device
|
// Catch if the service is not supported by the BLE device
|
||||||
rval.resultCode = BLECommOperationResult.RESULT_NONE;
|
rval.resultCode = BLECommOperationResult.RESULT_NONE;
|
||||||
LOG.error("BT Device not supported");
|
aapsLogger.error(LTag.PUMPBTCOMM, "BT Device not supported");
|
||||||
// TODO: 11/07/2016 UI update for user
|
// TODO: 11/07/2016 UI update for user
|
||||||
} else {
|
} else {
|
||||||
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID)
|
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID)
|
||||||
|
@ -447,8 +442,7 @@ public class RileyLinkBLE {
|
||||||
List<BluetoothGattDescriptor> list = chara.getDescriptors();
|
List<BluetoothGattDescriptor> list = chara.getDescriptors();
|
||||||
if (gattDebugEnabled) {
|
if (gattDebugEnabled) {
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Found descriptor: " + list.get(i).toString());
|
||||||
LOG.debug("Found descriptor: " + list.get(i).toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BluetoothGattDescriptor descr = list.get(0);
|
BluetoothGattDescriptor descr = list.get(0);
|
||||||
|
@ -468,7 +462,7 @@ public class RileyLinkBLE {
|
||||||
gattOperationSema.release();
|
gattOperationSema.release();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.error("setNotification_blocking: not configured!");
|
aapsLogger.error(LTag.PUMPBTCOMM, "setNotification_blocking: not configured!");
|
||||||
rval.resultCode = BLECommOperationResult.RESULT_NOT_CONFIGURED;
|
rval.resultCode = BLECommOperationResult.RESULT_NOT_CONFIGURED;
|
||||||
}
|
}
|
||||||
return rval;
|
return rval;
|
||||||
|
@ -476,7 +470,7 @@ public class RileyLinkBLE {
|
||||||
|
|
||||||
|
|
||||||
// call from main
|
// call from main
|
||||||
public BLECommOperationResult writeCharacteristic_blocking(UUID serviceUUID, UUID charaUUID, byte[] value) {
|
BLECommOperationResult writeCharacteristic_blocking(UUID serviceUUID, UUID charaUUID, byte[] value) {
|
||||||
BLECommOperationResult rval = new BLECommOperationResult();
|
BLECommOperationResult rval = new BLECommOperationResult();
|
||||||
if (bluetoothConnectionGatt != null) {
|
if (bluetoothConnectionGatt != null) {
|
||||||
rval.value = value;
|
rval.value = value;
|
||||||
|
@ -484,7 +478,7 @@ public class RileyLinkBLE {
|
||||||
gattOperationSema.acquire();
|
gattOperationSema.acquire();
|
||||||
SystemClock.sleep(1); // attempting to yield thread, to make sequence of events easier to follow
|
SystemClock.sleep(1); // attempting to yield thread, to make sequence of events easier to follow
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOG.error("writeCharacteristic_blocking: interrupted waiting for gattOperationSema");
|
aapsLogger.error(LTag.PUMPBTCOMM, "writeCharacteristic_blocking: interrupted waiting for gattOperationSema");
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,7 +491,7 @@ public class RileyLinkBLE {
|
||||||
// app that created the bluetoothConnectionGatt has been destroyed/created,
|
// app that created the bluetoothConnectionGatt has been destroyed/created,
|
||||||
// e.g. when the user switches from portrait to landscape.
|
// e.g. when the user switches from portrait to landscape.
|
||||||
rval.resultCode = BLECommOperationResult.RESULT_NONE;
|
rval.resultCode = BLECommOperationResult.RESULT_NONE;
|
||||||
LOG.error("BT Device not supported");
|
aapsLogger.error(LTag.PUMPBTCOMM, "BT Device not supported");
|
||||||
// TODO: 11/07/2016 UI update for user
|
// TODO: 11/07/2016 UI update for user
|
||||||
} else {
|
} else {
|
||||||
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID)
|
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID)
|
||||||
|
@ -516,21 +510,21 @@ public class RileyLinkBLE {
|
||||||
gattOperationSema.release();
|
gattOperationSema.release();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.error("writeCharacteristic_blocking: not configured!");
|
aapsLogger.error(LTag.PUMPBTCOMM, "writeCharacteristic_blocking: not configured!");
|
||||||
rval.resultCode = BLECommOperationResult.RESULT_NOT_CONFIGURED;
|
rval.resultCode = BLECommOperationResult.RESULT_NOT_CONFIGURED;
|
||||||
}
|
}
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public BLECommOperationResult readCharacteristic_blocking(UUID serviceUUID, UUID charaUUID) {
|
BLECommOperationResult readCharacteristic_blocking(UUID serviceUUID, UUID charaUUID) {
|
||||||
BLECommOperationResult rval = new BLECommOperationResult();
|
BLECommOperationResult rval = new BLECommOperationResult();
|
||||||
if (bluetoothConnectionGatt != null) {
|
if (bluetoothConnectionGatt != null) {
|
||||||
try {
|
try {
|
||||||
gattOperationSema.acquire();
|
gattOperationSema.acquire();
|
||||||
SystemClock.sleep(1); // attempting to yield thread, to make sequence of events easier to follow
|
SystemClock.sleep(1); // attempting to yield thread, to make sequence of events easier to follow
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOG.error("readCharacteristic_blocking: Interrupted waiting for gattOperationSema");
|
aapsLogger.error(LTag.PUMPBTCOMM, "readCharacteristic_blocking: Interrupted waiting for gattOperationSema");
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
if (mCurrentOperation != null) {
|
if (mCurrentOperation != null) {
|
||||||
|
@ -539,7 +533,7 @@ public class RileyLinkBLE {
|
||||||
if (bluetoothConnectionGatt.getService(serviceUUID) == null) {
|
if (bluetoothConnectionGatt.getService(serviceUUID) == null) {
|
||||||
// Catch if the service is not supported by the BLE device
|
// Catch if the service is not supported by the BLE device
|
||||||
rval.resultCode = BLECommOperationResult.RESULT_NONE;
|
rval.resultCode = BLECommOperationResult.RESULT_NONE;
|
||||||
LOG.error("BT Device not supported");
|
aapsLogger.error(LTag.PUMPBTCOMM, "BT Device not supported");
|
||||||
// TODO: 11/07/2016 UI update for user
|
// TODO: 11/07/2016 UI update for user
|
||||||
} else {
|
} else {
|
||||||
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID).getCharacteristic(
|
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID).getCharacteristic(
|
||||||
|
@ -559,7 +553,7 @@ public class RileyLinkBLE {
|
||||||
mCurrentOperation = null;
|
mCurrentOperation = null;
|
||||||
gattOperationSema.release();
|
gattOperationSema.release();
|
||||||
} else {
|
} else {
|
||||||
LOG.error("readCharacteristic_blocking: not configured!");
|
aapsLogger.error(LTag.PUMPBTCOMM, "readCharacteristic_blocking: not configured!");
|
||||||
rval.resultCode = BLECommOperationResult.RESULT_NOT_CONFIGURED;
|
rval.resultCode = BLECommOperationResult.RESULT_NOT_CONFIGURED;
|
||||||
}
|
}
|
||||||
return rval;
|
return rval;
|
||||||
|
@ -582,9 +576,4 @@ public class RileyLinkBLE {
|
||||||
|
|
||||||
return statusMessage;
|
return statusMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLogEnabled() {
|
|
||||||
return L.isEnabled(L.PUMPBTCOMM);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data;
|
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data;
|
||||||
|
|
||||||
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkCommunicationException;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkCommunicationException;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.RileyLinkCommand;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.RileyLinkCommand;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RFSpyRLResponse;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RFSpyRLResponse;
|
||||||
|
@ -48,12 +49,12 @@ public class RFSpyResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public RadioResponse getRadioResponse() throws RileyLinkCommunicationException {
|
public RadioResponse getRadioResponse(HasAndroidInjector injector) throws RileyLinkCommunicationException {
|
||||||
if (looksLikeRadioPacket()) {
|
if (looksLikeRadioPacket()) {
|
||||||
radioResponse = new RadioResponse(command);
|
radioResponse = new RadioResponse(injector, command);
|
||||||
radioResponse.init(raw);
|
radioResponse.init(raw);
|
||||||
} else {
|
} else {
|
||||||
radioResponse = new RadioResponse();
|
radioResponse = new RadioResponse(injector);
|
||||||
}
|
}
|
||||||
return radioResponse;
|
return radioResponse;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data;
|
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data;
|
||||||
|
|
||||||
import org.apache.commons.lang3.NotImplementedException;
|
import org.apache.commons.lang3.NotImplementedException;
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.logging.L;
|
import javax.inject.Inject;
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
|
||||||
|
import dagger.android.HasAndroidInjector;
|
||||||
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkCommunicationException;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkCommunicationException;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.RileyLinkCommand;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.RileyLinkCommand;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkBLEError;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkBLEError;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkCommandType;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkCommandType;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkFirmwareVersion;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkFirmwareVersion;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.CRC;
|
import info.nightscout.androidaps.plugins.pump.common.utils.CRC;
|
||||||
|
|
||||||
|
@ -19,26 +22,24 @@ import info.nightscout.androidaps.plugins.pump.common.utils.CRC;
|
||||||
*/
|
*/
|
||||||
public class RadioResponse {
|
public class RadioResponse {
|
||||||
|
|
||||||
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPBTCOMM);
|
|
||||||
|
|
||||||
public boolean decodedOK = false;
|
@Inject AAPSLogger aapsLogger;
|
||||||
|
@Inject RileyLinkServiceData rileyLinkServiceData;
|
||||||
|
|
||||||
|
private boolean decodedOK = false;
|
||||||
public int rssi;
|
public int rssi;
|
||||||
public int responseNumber;
|
private int responseNumber;
|
||||||
public byte[] decodedPayload = new byte[0];
|
private byte[] decodedPayload = new byte[0];
|
||||||
public byte receivedCRC;
|
private byte receivedCRC;
|
||||||
private RileyLinkCommand command;
|
private RileyLinkCommand command;
|
||||||
|
|
||||||
|
|
||||||
public RadioResponse() {
|
public RadioResponse(HasAndroidInjector injector) {
|
||||||
|
injector.androidInjector().inject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RadioResponse(HasAndroidInjector injector, RileyLinkCommand command /* , byte[] raw */) {
|
||||||
// public RadioResponse(byte[] rxData) {
|
this(injector);
|
||||||
// init(rxData);
|
|
||||||
// }
|
|
||||||
|
|
||||||
public RadioResponse(RileyLinkCommand command /* , byte[] raw */) {
|
|
||||||
this.command = command;
|
this.command = command;
|
||||||
// init(raw);
|
// init(raw);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +75,7 @@ public class RadioResponse {
|
||||||
}
|
}
|
||||||
byte[] encodedPayload;
|
byte[] encodedPayload;
|
||||||
|
|
||||||
if (RileyLinkFirmwareVersion.isSameVersion(RileyLinkUtil.getInstance().getRileyLinkServiceData().versionCC110,
|
if (RileyLinkFirmwareVersion.isSameVersion(rileyLinkServiceData.versionCC110,
|
||||||
RileyLinkFirmwareVersion.Version2)) {
|
RileyLinkFirmwareVersion.Version2)) {
|
||||||
encodedPayload = ByteUtil.substring(rxData, 3, rxData.length - 3);
|
encodedPayload = ByteUtil.substring(rxData, 3, rxData.length - 3);
|
||||||
rssi = rxData[1];
|
rssi = rxData[1];
|
||||||
|
@ -116,7 +117,7 @@ public class RadioResponse {
|
||||||
receivedCRC = decodeThis[decodeThis.length - 1];
|
receivedCRC = decodeThis[decodeThis.length - 1];
|
||||||
byte calculatedCRC = CRC.crc8(decodedPayload);
|
byte calculatedCRC = CRC.crc8(decodedPayload);
|
||||||
if (receivedCRC != calculatedCRC) {
|
if (receivedCRC != calculatedCRC) {
|
||||||
LOG.error(String.format("RadioResponse: CRC mismatch, calculated 0x%02x, received 0x%02x",
|
aapsLogger.error(LTag.PUMPCOMM, String.format("RadioResponse: CRC mismatch, calculated 0x%02x, received 0x%02x",
|
||||||
calculatedCRC, receivedCRC));
|
calculatedCRC, receivedCRC));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -131,7 +132,7 @@ public class RadioResponse {
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
decodedOK = false;
|
decodedOK = false;
|
||||||
LOG.error("Failed to decode radio data: " + ByteUtil.shortHexString(encodedPayload));
|
aapsLogger.error(LTag.PUMPBTCOMM, "Failed to decode radio data: " + ByteUtil.shortHexString(encodedPayload));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,12 @@ public class RileyLinkStatusActivity extends NoSplashAppCompatActivity {
|
||||||
|
|
||||||
@Inject ResourceHelper resourceHelper;
|
@Inject ResourceHelper resourceHelper;
|
||||||
@Inject RileyLinkUtil rileyLinkUtil;
|
@Inject RileyLinkUtil rileyLinkUtil;
|
||||||
|
@Inject RileyLinkServiceData rileyLinkServiceData;
|
||||||
|
|
||||||
TextView connectionStatus;
|
TextView connectionStatus;
|
||||||
TextView configuredAddress;
|
TextView configuredAddress;
|
||||||
TextView connectedDevice;
|
TextView connectedDevice;
|
||||||
TextView connectionError;
|
TextView connectionError;
|
||||||
RileyLinkServiceData rileyLinkServiceData;
|
|
||||||
|
|
||||||
private SectionsPagerAdapter mSectionsPagerAdapter;
|
private SectionsPagerAdapter mSectionsPagerAdapter;
|
||||||
private FloatingActionButton floatingActionButton;
|
private FloatingActionButton floatingActionButton;
|
||||||
|
@ -77,8 +77,6 @@ public class RileyLinkStatusActivity extends NoSplashAppCompatActivity {
|
||||||
this.connectedDevice = findViewById(R.id.rls_t1_connected_device);
|
this.connectedDevice = findViewById(R.id.rls_t1_connected_device);
|
||||||
this.connectionError = findViewById(R.id.rls_t1_connection_error);
|
this.connectionError = findViewById(R.id.rls_t1_connection_error);
|
||||||
|
|
||||||
rileyLinkServiceData = rileyLinkUtil.getRileyLinkServiceData();
|
|
||||||
|
|
||||||
// // 7-12
|
// // 7-12
|
||||||
// int[] ids = {R.id.rls_t1_tv02, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, //
|
// int[] ids = {R.id.rls_t1_tv02, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, //
|
||||||
// R.id.rls_t1_tv08, R.id.rls_t1_tv09, R.id.rls_t1_tv10, R.id.rls_t1_tv11, R.id.rls_t1_tv12};
|
// R.id.rls_t1_tv08, R.id.rls_t1_tv09, R.id.rls_t1_tv10, R.id.rls_t1_tv11, R.id.rls_t1_tv12};
|
||||||
|
@ -98,7 +96,7 @@ public class RileyLinkStatusActivity extends NoSplashAppCompatActivity {
|
||||||
public void refreshData(int position) {
|
public void refreshData(int position) {
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
// FIXME i18n
|
// FIXME i18n
|
||||||
this.connectionStatus.setText(rileyLinkServiceData.serviceState.name());
|
this.connectionStatus.setText(rileyLinkServiceData.rileyLinkServiceState.name());
|
||||||
this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress);
|
this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress);
|
||||||
// FIXME
|
// FIXME
|
||||||
this.connectedDevice.setText("???");
|
this.connectedDevice.setText("???");
|
||||||
|
|
|
@ -17,7 +17,6 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
|
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkFirmwareVersion;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkFirmwareVersion;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
||||||
|
@ -37,6 +36,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
|
||||||
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||||
@Inject ResourceHelper resourceHelper;
|
@Inject ResourceHelper resourceHelper;
|
||||||
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
|
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
|
||||||
|
@Inject RileyLinkServiceData rileyLinkServiceData;
|
||||||
|
|
||||||
TextView connectionStatus;
|
TextView connectionStatus;
|
||||||
TextView configuredAddress;
|
TextView configuredAddress;
|
||||||
|
@ -50,8 +50,6 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
|
||||||
TextView lastDeviceContact;
|
TextView lastDeviceContact;
|
||||||
TextView firmwareVersion;
|
TextView firmwareVersion;
|
||||||
|
|
||||||
RileyLinkServiceData rileyLinkServiceData;
|
|
||||||
|
|
||||||
boolean first = false;
|
boolean first = false;
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,7 +64,6 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
rileyLinkServiceData = rileyLinkUtil.getRileyLinkServiceData();
|
|
||||||
|
|
||||||
this.connectionStatus = getActivity().findViewById(R.id.rls_t1_connection_status);
|
this.connectionStatus = getActivity().findViewById(R.id.rls_t1_connection_status);
|
||||||
this.configuredAddress = getActivity().findViewById(R.id.rls_t1_configured_address);
|
this.configuredAddress = getActivity().findViewById(R.id.rls_t1_configured_address);
|
||||||
|
@ -101,12 +98,9 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
|
||||||
|
|
||||||
public void refreshData() {
|
public void refreshData() {
|
||||||
|
|
||||||
RileyLinkTargetDevice targetDevice = rileyLinkUtil.getTargetDevice();
|
RileyLinkTargetDevice targetDevice = rileyLinkServiceData.targetDevice;
|
||||||
|
|
||||||
if (rileyLinkUtil.getServiceState() == null)
|
this.connectionStatus.setText(resourceHelper.gs(rileyLinkServiceData.rileyLinkServiceState.getResourceId(targetDevice)));
|
||||||
this.connectionStatus.setText(resourceHelper.gs(RileyLinkServiceState.NotStarted.getResourceId(targetDevice)));
|
|
||||||
else
|
|
||||||
this.connectionStatus.setText(resourceHelper.gs(rileyLinkUtil.getServiceState().getResourceId(targetDevice)));
|
|
||||||
|
|
||||||
if (rileyLinkServiceData != null) {
|
if (rileyLinkServiceData != null) {
|
||||||
this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress);
|
this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress);
|
||||||
|
|
|
@ -46,18 +46,16 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
|
||||||
@Inject HasAndroidInjector injector;
|
@Inject HasAndroidInjector injector;
|
||||||
@Inject RileyLinkUtil rileyLinkUtil;
|
@Inject RileyLinkUtil rileyLinkUtil;
|
||||||
@Inject SP sp;
|
@Inject SP sp;
|
||||||
|
@Inject RileyLinkServiceData rileyLinkServiceData;
|
||||||
|
|
||||||
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
|
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
|
||||||
|
|
||||||
RileyLinkService serviceInstance;
|
RileyLinkService serviceInstance;
|
||||||
protected Map<String, List<String>> broadcastIdentifiers = null;
|
protected Map<String, List<String>> broadcastIdentifiers = null;
|
||||||
String deviceSpecificPrefix;
|
String deviceSpecificPrefix;
|
||||||
Context context;
|
|
||||||
|
|
||||||
|
public RileyLinkBroadcastReceiver(RileyLinkService serviceInstance) {
|
||||||
public RileyLinkBroadcastReceiver(RileyLinkService serviceInstance, Context context) {
|
|
||||||
this.serviceInstance = serviceInstance;
|
this.serviceInstance = serviceInstance;
|
||||||
this.context = context;
|
|
||||||
|
|
||||||
createBroadcastIdentifiers();
|
createBroadcastIdentifiers();
|
||||||
}
|
}
|
||||||
|
@ -120,7 +118,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void registerBroadcasts() {
|
public void registerBroadcasts(Context context) {
|
||||||
|
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
|
|
||||||
|
@ -143,9 +141,9 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
|
||||||
|
|
||||||
if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnected)) {
|
if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnected)) {
|
||||||
if (BluetoothAdapter.getDefaultAdapter().isEnabled()) {
|
if (BluetoothAdapter.getDefaultAdapter().isEnabled()) {
|
||||||
rileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.RileyLinkUnreachable);
|
rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.RileyLinkUnreachable);
|
||||||
} else {
|
} else {
|
||||||
rileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled);
|
rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -155,25 +153,22 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
|
||||||
LOG.warn("MedtronicConst.Intents.RileyLinkReady");
|
LOG.warn("MedtronicConst.Intents.RileyLinkReady");
|
||||||
// sendIPCNotification(RT2Const.IPC.MSG_note_WakingPump);
|
// sendIPCNotification(RT2Const.IPC.MSG_note_WakingPump);
|
||||||
|
|
||||||
if (this.serviceInstance.rileyLinkBLE == null)
|
serviceInstance.rileyLinkBLE.enableNotifications();
|
||||||
return false;
|
serviceInstance.rfspy.startReader(); // call startReader from outside?
|
||||||
|
|
||||||
this.serviceInstance.rileyLinkBLE.enableNotifications();
|
serviceInstance.rfspy.initializeRileyLink();
|
||||||
this.serviceInstance.rfspy.startReader(); // call startReader from outside?
|
String bleVersion = serviceInstance.rfspy.getBLEVersionCached();
|
||||||
|
RileyLinkFirmwareVersion rlVersion = serviceInstance.rfspy.getRLVersionCached();
|
||||||
this.serviceInstance.rfspy.initializeRileyLink();
|
|
||||||
String bleVersion = this.serviceInstance.rfspy.getBLEVersionCached();
|
|
||||||
RileyLinkFirmwareVersion rlVersion = this.serviceInstance.rfspy.getRLVersionCached();
|
|
||||||
|
|
||||||
// if (isLoggingEnabled())
|
// if (isLoggingEnabled())
|
||||||
LOG.debug("RfSpy version (BLE113): " + bleVersion);
|
LOG.debug("RfSpy version (BLE113): " + bleVersion);
|
||||||
this.serviceInstance.rileyLinkServiceData.versionBLE113 = bleVersion;
|
serviceInstance.rileyLinkServiceData.versionBLE113 = bleVersion;
|
||||||
|
|
||||||
// if (isLoggingEnabled())
|
// if (isLoggingEnabled())
|
||||||
LOG.debug("RfSpy Radio version (CC110): " + rlVersion.name());
|
LOG.debug("RfSpy Radio version (CC110): " + rlVersion.name());
|
||||||
this.serviceInstance.rileyLinkServiceData.versionCC110 = rlVersion;
|
serviceInstance.rileyLinkServiceData.versionCC110 = rlVersion;
|
||||||
|
|
||||||
ServiceTask task = new InitializePumpManagerTask(injector, rileyLinkUtil.getTargetDevice());
|
ServiceTask task = new InitializePumpManagerTask(injector);
|
||||||
ServiceTaskExecutor.startTask(task);
|
ServiceTaskExecutor.startTask(task);
|
||||||
if (isLoggingEnabled())
|
if (isLoggingEnabled())
|
||||||
LOG.info("Announcing RileyLink open For business");
|
LOG.info("Announcing RileyLink open For business");
|
||||||
|
@ -186,13 +181,13 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
|
||||||
} else {
|
} else {
|
||||||
// showBusy("Configuring Service", 50);
|
// showBusy("Configuring Service", 50);
|
||||||
// rileyLinkBLE.findRileyLink(RileylinkBLEAddress);
|
// rileyLinkBLE.findRileyLink(RileylinkBLEAddress);
|
||||||
this.serviceInstance.reconfigureRileyLink(RileylinkBLEAddress);
|
serviceInstance.reconfigureRileyLink(RileylinkBLEAddress);
|
||||||
// MainApp.getServiceClientConnection().setThisRileylink(RileylinkBLEAddress);
|
// MainApp.getServiceClientConnection().setThisRileylink(RileylinkBLEAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnect)) {
|
} else if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnect)) {
|
||||||
this.serviceInstance.disconnectRileyLink();
|
serviceInstance.disconnectRileyLink();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -247,7 +242,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.startsWith(this.deviceSpecificPrefix)) {
|
if (action.startsWith(this.deviceSpecificPrefix)) {
|
||||||
return this.serviceInstance.handleDeviceSpecificBroadcasts(intent);
|
return serviceInstance.handleDeviceSpecificBroadcasts(intent);
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -262,7 +257,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
|
||||||
return (L.isEnabled(L.PUMPCOMM));
|
return (L.isEnabled(L.PUMPCOMM));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregisterBroadcasts() {
|
public void unregisterBroadcasts(Context context) {
|
||||||
LocalBroadcastManager.getInstance(context).unregisterReceiver(this);
|
LocalBroadcastManager.getInstance(context).unregisterReceiver(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import javax.inject.Inject;
|
||||||
import dagger.android.DaggerService;
|
import dagger.android.DaggerService;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||||
|
@ -36,17 +37,18 @@ public abstract class RileyLinkService extends DaggerService {
|
||||||
@Inject protected AAPSLogger aapsLogger;
|
@Inject protected AAPSLogger aapsLogger;
|
||||||
@Inject protected SP sp;
|
@Inject protected SP sp;
|
||||||
@Inject protected Context context;
|
@Inject protected Context context;
|
||||||
|
@Inject protected RxBusWrapper rxBus;
|
||||||
@Inject protected RileyLinkUtil rileyLinkUtil;
|
@Inject protected RileyLinkUtil rileyLinkUtil;
|
||||||
@Inject protected MedtronicUtil medtronicUtil; // TODO should be avoided here as it's MDT
|
@Inject protected MedtronicUtil medtronicUtil; // TODO should be avoided here as it's MDT
|
||||||
|
@Inject protected RileyLinkServiceData rileyLinkServiceData;
|
||||||
|
|
||||||
@NotNull protected RileyLinkBLE rileyLinkBLE; // android-bluetooth management, must be set in initRileyLinkServiceData
|
@NotNull protected RileyLinkBLE rileyLinkBLE; // android-bluetooth management, must be set in initRileyLinkServiceData
|
||||||
protected BluetoothAdapter bluetoothAdapter;
|
protected BluetoothAdapter bluetoothAdapter;
|
||||||
protected RFSpy rfspy; // interface for RL xxx Mhz radio.
|
protected RFSpy rfspy; // interface for RL xxx Mhz radio.
|
||||||
protected RileyLinkBroadcastReceiver mBroadcastReceiver;
|
protected RileyLinkBroadcastReceiver mBroadcastReceiver;
|
||||||
protected RileyLinkServiceData rileyLinkServiceData;
|
|
||||||
protected RileyLinkBluetoothStateReceiver bluetoothStateReceiver;
|
protected RileyLinkBluetoothStateReceiver bluetoothStateReceiver;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
@ -54,8 +56,8 @@ public abstract class RileyLinkService extends DaggerService {
|
||||||
rileyLinkUtil.setEncoding(getEncoding());
|
rileyLinkUtil.setEncoding(getEncoding());
|
||||||
initRileyLinkServiceData();
|
initRileyLinkServiceData();
|
||||||
|
|
||||||
mBroadcastReceiver = new RileyLinkBroadcastReceiver(this, this.context);
|
mBroadcastReceiver = new RileyLinkBroadcastReceiver(this);
|
||||||
mBroadcastReceiver.registerBroadcasts();
|
mBroadcastReceiver.registerBroadcasts(this);
|
||||||
|
|
||||||
|
|
||||||
bluetoothStateReceiver = new RileyLinkBluetoothStateReceiver();
|
bluetoothStateReceiver = new RileyLinkBluetoothStateReceiver();
|
||||||
|
@ -96,7 +98,7 @@ public abstract class RileyLinkService extends DaggerService {
|
||||||
rileyLinkBLE.disconnect(); // dispose of Gatt (disconnect and close)
|
rileyLinkBLE.disconnect(); // dispose of Gatt (disconnect and close)
|
||||||
|
|
||||||
if (mBroadcastReceiver != null) {
|
if (mBroadcastReceiver != null) {
|
||||||
mBroadcastReceiver.unregisterBroadcasts();
|
mBroadcastReceiver.unregisterBroadcasts(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bluetoothStateReceiver != null) {
|
if (bluetoothStateReceiver != null) {
|
||||||
|
@ -133,20 +135,20 @@ public abstract class RileyLinkService extends DaggerService {
|
||||||
|
|
||||||
public boolean bluetoothInit() {
|
public boolean bluetoothInit() {
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "bluetoothInit: attempting to get an adapter");
|
aapsLogger.debug(LTag.PUMPCOMM, "bluetoothInit: attempting to get an adapter");
|
||||||
rileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothInitializing);
|
rileyLinkServiceData.setRileyLinkServiceState(RileyLinkServiceState.BluetoothInitializing);
|
||||||
|
|
||||||
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
|
||||||
if (bluetoothAdapter == null) {
|
if (bluetoothAdapter == null) {
|
||||||
aapsLogger.error("Unable to obtain a BluetoothAdapter.");
|
aapsLogger.error("Unable to obtain a BluetoothAdapter.");
|
||||||
rileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.NoBluetoothAdapter);
|
rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.NoBluetoothAdapter);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (!bluetoothAdapter.isEnabled()) {
|
if (!bluetoothAdapter.isEnabled()) {
|
||||||
aapsLogger.error("Bluetooth is not enabled.");
|
aapsLogger.error("Bluetooth is not enabled.");
|
||||||
rileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled);
|
rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled);
|
||||||
} else {
|
} else {
|
||||||
rileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothReady);
|
rileyLinkServiceData.setRileyLinkServiceState(RileyLinkServiceState.BluetoothReady);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,7 +160,7 @@ public abstract class RileyLinkService extends DaggerService {
|
||||||
// returns true if our Rileylink configuration changed
|
// returns true if our Rileylink configuration changed
|
||||||
public boolean reconfigureRileyLink(String deviceAddress) {
|
public boolean reconfigureRileyLink(String deviceAddress) {
|
||||||
|
|
||||||
rileyLinkUtil.setServiceState(RileyLinkServiceState.RileyLinkInitializing);
|
rileyLinkServiceData.setRileyLinkServiceState(RileyLinkServiceState.RileyLinkInitializing);
|
||||||
|
|
||||||
if (rileyLinkBLE.isConnected()) {
|
if (rileyLinkBLE.isConnected()) {
|
||||||
if (deviceAddress.equals(rileyLinkServiceData.rileylinkAddress)) {
|
if (deviceAddress.equals(rileyLinkServiceData.rileylinkAddress)) {
|
||||||
|
@ -179,7 +181,7 @@ public abstract class RileyLinkService extends DaggerService {
|
||||||
} else {
|
} else {
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "Using RL " + deviceAddress);
|
aapsLogger.debug(LTag.PUMPCOMM, "Using RL " + deviceAddress);
|
||||||
|
|
||||||
if (rileyLinkUtil.getServiceState() == RileyLinkServiceState.NotStarted) {
|
if (rileyLinkServiceData.getRileyLinkServiceState() == RileyLinkServiceState.NotStarted) {
|
||||||
if (!bluetoothInit()) {
|
if (!bluetoothInit()) {
|
||||||
aapsLogger.error("RileyLink can't get activated, Bluetooth is not functioning correctly. {}",
|
aapsLogger.error("RileyLink can't get activated, Bluetooth is not functioning correctly. {}",
|
||||||
getError() != null ? getError().name() : "Unknown error (null)");
|
getError() != null ? getError().name() : "Unknown error (null)");
|
||||||
|
@ -201,7 +203,7 @@ public abstract class RileyLinkService extends DaggerService {
|
||||||
// FIXME: This needs to be run in a session so that is interruptable, has a separate thread, etc.
|
// FIXME: This needs to be run in a session so that is interruptable, has a separate thread, etc.
|
||||||
public void doTuneUpDevice() {
|
public void doTuneUpDevice() {
|
||||||
|
|
||||||
rileyLinkUtil.setServiceState(RileyLinkServiceState.TuneUpDevice);
|
rileyLinkServiceData.setRileyLinkServiceState(RileyLinkServiceState.TuneUpDevice);
|
||||||
medtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
|
medtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
|
||||||
|
|
||||||
double lastGoodFrequency = 0.0d;
|
double lastGoodFrequency = 0.0d;
|
||||||
|
@ -226,10 +228,10 @@ public abstract class RileyLinkService extends DaggerService {
|
||||||
|
|
||||||
if (newFrequency == 0.0d) {
|
if (newFrequency == 0.0d) {
|
||||||
// error tuning pump, pump not present ??
|
// error tuning pump, pump not present ??
|
||||||
rileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.TuneUpOfDeviceFailed);
|
rileyLinkServiceData.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.TuneUpOfDeviceFailed);
|
||||||
} else {
|
} else {
|
||||||
getDeviceCommunicationManager().clearNotConnectedCount();
|
getDeviceCommunicationManager().clearNotConnectedCount();
|
||||||
rileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorReady);
|
rileyLinkServiceData.setRileyLinkServiceState(RileyLinkServiceState.PumpConnectorReady);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +243,7 @@ public abstract class RileyLinkService extends DaggerService {
|
||||||
rileyLinkServiceData.rileylinkAddress = null;
|
rileyLinkServiceData.rileylinkAddress = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
rileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothReady);
|
rileyLinkServiceData.setRileyLinkServiceState(RileyLinkServiceState.BluetoothReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull public RileyLinkBLE getRileyLinkBLE() {
|
@NotNull public RileyLinkBLE getRileyLinkBLE() {
|
||||||
|
|
|
@ -1,21 +1,35 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service;
|
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkFirmwareVersion;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkFirmwareVersion;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicDeviceStatusChange;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by andy on 16/05/2018.
|
* Created by andy on 16/05/2018.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Singleton
|
||||||
public class RileyLinkServiceData {
|
public class RileyLinkServiceData {
|
||||||
|
|
||||||
public boolean tuneUpDone = false;
|
@Inject AAPSLogger aapsLogger;
|
||||||
|
@Inject RileyLinkUtil rileyLinkUtil;
|
||||||
|
@Inject RxBusWrapper rxBus;
|
||||||
|
|
||||||
|
boolean tuneUpDone = false;
|
||||||
public RileyLinkError errorCode;
|
public RileyLinkError errorCode;
|
||||||
public RileyLinkServiceState serviceState = RileyLinkServiceState.NotStarted;
|
public RileyLinkServiceState rileyLinkServiceState = RileyLinkServiceState.NotStarted;
|
||||||
public String rileylinkAddress;
|
public String rileylinkAddress;
|
||||||
public long lastTuneUpTime = 0L;
|
long lastTuneUpTime = 0L;
|
||||||
public Double lastGoodFrequency;
|
public Double lastGoodFrequency;
|
||||||
|
|
||||||
// bt version
|
// bt version
|
||||||
|
@ -29,15 +43,45 @@ public class RileyLinkServiceData {
|
||||||
public String pumpID;
|
public String pumpID;
|
||||||
public byte[] pumpIDBytes;
|
public byte[] pumpIDBytes;
|
||||||
|
|
||||||
|
@Inject
|
||||||
public RileyLinkServiceData(RileyLinkTargetDevice targetDevice) {
|
public RileyLinkServiceData() {}
|
||||||
this.targetDevice = targetDevice;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setPumpID(String pumpId, byte[] pumpIdBytes) {
|
public void setPumpID(String pumpId, byte[] pumpIdBytes) {
|
||||||
this.pumpID = pumpId;
|
this.pumpID = pumpId;
|
||||||
this.pumpIDBytes = pumpIdBytes;
|
this.pumpIDBytes = pumpIdBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRileyLinkServiceState(RileyLinkServiceState newState) {
|
||||||
|
setServiceState(newState, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RileyLinkServiceState getRileyLinkServiceState() {
|
||||||
|
return workWithServiceState(null, null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setServiceState(RileyLinkServiceState newState, RileyLinkError errorCode) {
|
||||||
|
workWithServiceState(newState, errorCode, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private synchronized RileyLinkServiceState workWithServiceState(RileyLinkServiceState newState, RileyLinkError errorCode, boolean set) {
|
||||||
|
|
||||||
|
if (set) {
|
||||||
|
|
||||||
|
rileyLinkServiceState = newState;
|
||||||
|
this.errorCode = errorCode;
|
||||||
|
|
||||||
|
aapsLogger.info(LTag.PUMP, "RileyLink State Changed: {} {}", newState, errorCode == null ? "" : " - Error State: " + errorCode.name());
|
||||||
|
|
||||||
|
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(rileyLinkServiceState, errorCode, targetDevice));
|
||||||
|
rxBus.send(new EventMedtronicDeviceStatusChange(newState, errorCode));
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return rileyLinkServiceState;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,20 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks;
|
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
|
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by geoff on 7/9/16.
|
* Created by geoff on 7/9/16.
|
||||||
|
@ -25,66 +23,62 @@ import info.nightscout.androidaps.utils.SP;
|
||||||
*/
|
*/
|
||||||
public class InitializePumpManagerTask extends ServiceTask {
|
public class InitializePumpManagerTask extends ServiceTask {
|
||||||
|
|
||||||
|
@Inject AAPSLogger aapsLogger;
|
||||||
@Inject ActivePluginProvider activePlugin;
|
@Inject ActivePluginProvider activePlugin;
|
||||||
|
@Inject SP sp;
|
||||||
|
@Inject RileyLinkServiceData rileyLinkServiceData;
|
||||||
|
@Inject RileyLinkUtil rileyLinkUtil;
|
||||||
|
|
||||||
private static final String TAG = "InitPumpManagerTask";
|
public InitializePumpManagerTask(HasAndroidInjector injector) {
|
||||||
private RileyLinkTargetDevice targetDevice;
|
|
||||||
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
|
|
||||||
|
|
||||||
public InitializePumpManagerTask(HasAndroidInjector injector, RileyLinkTargetDevice targetDevice) {
|
|
||||||
super(injector);
|
super(injector);
|
||||||
this.targetDevice = targetDevice;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public InitializePumpManagerTask(HasAndroidInjector injector, ServiceTransport transport) {
|
public InitializePumpManagerTask(HasAndroidInjector injector, ServiceTransport transport) {
|
||||||
super(injector, transport);
|
super(injector, transport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
double lastGoodFrequency = 0.0d;
|
double lastGoodFrequency;
|
||||||
|
|
||||||
if (RileyLinkUtil.getInstance().getRileyLinkServiceData().lastGoodFrequency == null) {
|
if (rileyLinkServiceData.lastGoodFrequency == null) {
|
||||||
|
|
||||||
lastGoodFrequency = SP.getDouble(RileyLinkConst.Prefs.LastGoodDeviceFrequency, 0.0d);
|
lastGoodFrequency = sp.getDouble(RileyLinkConst.Prefs.LastGoodDeviceFrequency, 0.0d);
|
||||||
lastGoodFrequency = Math.round(lastGoodFrequency * 1000d) / 1000d;
|
lastGoodFrequency = Math.round(lastGoodFrequency * 1000d) / 1000d;
|
||||||
|
|
||||||
RileyLinkUtil.getInstance().getRileyLinkServiceData().lastGoodFrequency = lastGoodFrequency;
|
rileyLinkServiceData.lastGoodFrequency = lastGoodFrequency;
|
||||||
|
|
||||||
// if (RileyLinkUtil.getRileyLinkTargetFrequency() == null) {
|
// if (RileyLinkUtil.getRileyLinkTargetFrequency() == null) {
|
||||||
// String pumpFrequency = SP.getString(MedtronicConst.Prefs.PumpFrequency, null);
|
// String pumpFrequency = SP.getString(MedtronicConst.Prefs.PumpFrequency, null);
|
||||||
// }
|
// }
|
||||||
} else {
|
} else {
|
||||||
lastGoodFrequency = RileyLinkUtil.getInstance().getRileyLinkServiceData().lastGoodFrequency;
|
lastGoodFrequency = rileyLinkServiceData.lastGoodFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
RileyLinkCommunicationManager rileyLinkCommunicationManager = ((PumpPluginAbstract)activePlugin.getActivePump()).getRileyLinkService().getDeviceCommunicationManager();
|
RileyLinkCommunicationManager rileyLinkCommunicationManager = ((PumpPluginAbstract) activePlugin.getActivePump()).getRileyLinkService().getDeviceCommunicationManager();
|
||||||
|
|
||||||
if ((lastGoodFrequency > 0.0d)
|
if ((lastGoodFrequency > 0.0d)
|
||||||
&& rileyLinkCommunicationManager.isValidFrequency(lastGoodFrequency)) {
|
&& rileyLinkCommunicationManager.isValidFrequency(lastGoodFrequency)) {
|
||||||
|
|
||||||
RileyLinkUtil.getInstance().setServiceState(RileyLinkServiceState.RileyLinkReady);
|
rileyLinkServiceData.setRileyLinkServiceState(RileyLinkServiceState.RileyLinkReady);
|
||||||
|
|
||||||
if (L.isEnabled(L.PUMPCOMM))
|
aapsLogger.info(LTag.PUMPBTCOMM, "Setting radio frequency to {} MHz", lastGoodFrequency);
|
||||||
LOG.info("Setting radio frequency to {} MHz", lastGoodFrequency);
|
|
||||||
|
|
||||||
rileyLinkCommunicationManager.setRadioFrequencyForPump(lastGoodFrequency);
|
rileyLinkCommunicationManager.setRadioFrequencyForPump(lastGoodFrequency);
|
||||||
|
|
||||||
boolean foundThePump = rileyLinkCommunicationManager.tryToConnectToDevice();
|
boolean foundThePump = rileyLinkCommunicationManager.tryToConnectToDevice();
|
||||||
|
|
||||||
if (foundThePump) {
|
if (foundThePump) {
|
||||||
RileyLinkUtil.getInstance().setServiceState(RileyLinkServiceState.PumpConnectorReady);
|
rileyLinkServiceData.setRileyLinkServiceState(RileyLinkServiceState.PumpConnectorReady);
|
||||||
} else {
|
} else {
|
||||||
RileyLinkUtil.getInstance().setServiceState(RileyLinkServiceState.PumpConnectorError,
|
rileyLinkServiceData.setServiceState(RileyLinkServiceState.PumpConnectorError,
|
||||||
RileyLinkError.NoContactWithDevice);
|
RileyLinkError.NoContactWithDevice);
|
||||||
RileyLinkUtil.getInstance().sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_tunePump);
|
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_tunePump);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
RileyLinkUtil.getInstance().sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_tunePump);
|
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_tunePump);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.
|
||||||
*/
|
*/
|
||||||
public class ServiceTask implements Runnable {
|
public class ServiceTask implements Runnable {
|
||||||
|
|
||||||
private static final String TAG = "ServiceTask(base)";
|
|
||||||
public boolean completed = false;
|
public boolean completed = false;
|
||||||
protected ServiceTransport mTransport;
|
protected ServiceTransport mTransport;
|
||||||
protected HasAndroidInjector injector;
|
protected HasAndroidInjector injector;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLin
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState
|
||||||
|
@ -60,6 +61,7 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
@Inject lateinit var rileyLinkUtil: RileyLinkUtil
|
@Inject lateinit var rileyLinkUtil: RileyLinkUtil
|
||||||
@Inject lateinit var medtronicUtil: MedtronicUtil
|
@Inject lateinit var medtronicUtil: MedtronicUtil
|
||||||
@Inject lateinit var medtronicPumpStatus: MedtronicPumpStatus
|
@Inject lateinit var medtronicPumpStatus: MedtronicPumpStatus
|
||||||
|
@Inject lateinit var rileyLinkServiceData: RileyLinkServiceData
|
||||||
|
|
||||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
|
@ -174,17 +176,14 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun setDeviceStatus() {
|
private fun setDeviceStatus() {
|
||||||
medtronicPumpStatus.rileyLinkServiceState = checkStatusSet(medtronicPumpStatus.rileyLinkServiceState,
|
val resourceId = rileyLinkServiceData.rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.MedtronicPump)
|
||||||
rileyLinkUtil.getServiceState()) as RileyLinkServiceState?
|
|
||||||
|
|
||||||
val resourceId = medtronicPumpStatus.rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.MedtronicPump)
|
|
||||||
val rileyLinkError = medtronicPumpPlugin.rileyLinkService?.error
|
val rileyLinkError = medtronicPumpPlugin.rileyLinkService?.error
|
||||||
medtronic_rl_status.text =
|
medtronic_rl_status.text =
|
||||||
when {
|
when {
|
||||||
medtronicPumpStatus.rileyLinkServiceState == RileyLinkServiceState.NotStarted -> resourceHelper.gs(resourceId)
|
rileyLinkServiceData.rileyLinkServiceState == RileyLinkServiceState.NotStarted -> resourceHelper.gs(resourceId)
|
||||||
medtronicPumpStatus.rileyLinkServiceState.isConnecting -> "{fa-bluetooth-b spin} " + resourceHelper.gs(resourceId)
|
rileyLinkServiceData.rileyLinkServiceState.isConnecting -> "{fa-bluetooth-b spin} " + resourceHelper.gs(resourceId)
|
||||||
medtronicPumpStatus.rileyLinkServiceState.isError && rileyLinkError == null -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
|
rileyLinkServiceData.rileyLinkServiceState.isError && rileyLinkError == null -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
|
||||||
medtronicPumpStatus.rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump))
|
rileyLinkServiceData.rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump))
|
||||||
else -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
|
else -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
|
||||||
}
|
}
|
||||||
medtronic_rl_status.setTextColor(if (rileyLinkError != null) Color.RED else Color.WHITE)
|
medtronic_rl_status.setTextColor(if (rileyLinkError != null) Color.RED else Color.WHITE)
|
||||||
|
|
|
@ -56,6 +56,7 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkConfigurationTask;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkConfigurationTask;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask;
|
||||||
|
@ -99,6 +100,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
private final MedtronicUtil medtronicUtil;
|
private final MedtronicUtil medtronicUtil;
|
||||||
private final MedtronicPumpStatus medtronicPumpStatus;
|
private final MedtronicPumpStatus medtronicPumpStatus;
|
||||||
private final MedtronicHistoryData medtronicHistoryData;
|
private final MedtronicHistoryData medtronicHistoryData;
|
||||||
|
private final RileyLinkServiceData rileyLinkServiceData;
|
||||||
|
|
||||||
protected static MedtronicPumpPlugin plugin = null;
|
protected static MedtronicPumpPlugin plugin = null;
|
||||||
private RileyLinkMedtronicService rileyLinkMedtronicService;
|
private RileyLinkMedtronicService rileyLinkMedtronicService;
|
||||||
|
@ -129,7 +131,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
RileyLinkUtil rileyLinkUtil,
|
RileyLinkUtil rileyLinkUtil,
|
||||||
MedtronicUtil medtronicUtil,
|
MedtronicUtil medtronicUtil,
|
||||||
MedtronicPumpStatus medtronicPumpStatus,
|
MedtronicPumpStatus medtronicPumpStatus,
|
||||||
MedtronicHistoryData medtronicHistoryData
|
MedtronicHistoryData medtronicHistoryData,
|
||||||
|
RileyLinkServiceData rileyLinkServiceData
|
||||||
) {
|
) {
|
||||||
|
|
||||||
super(new PluginDescription() //
|
super(new PluginDescription() //
|
||||||
|
@ -149,6 +152,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
this.sp = sp;
|
this.sp = sp;
|
||||||
this.medtronicPumpStatus = medtronicPumpStatus;
|
this.medtronicPumpStatus = medtronicPumpStatus;
|
||||||
this.medtronicHistoryData = medtronicHistoryData;
|
this.medtronicHistoryData = medtronicHistoryData;
|
||||||
|
this.rileyLinkServiceData = rileyLinkServiceData;
|
||||||
|
|
||||||
displayConnectionMessages = false;
|
displayConnectionMessages = false;
|
||||||
|
|
||||||
|
@ -408,7 +412,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
private boolean isPumpNotReachable() {
|
private boolean isPumpNotReachable() {
|
||||||
|
|
||||||
RileyLinkServiceState rileyLinkServiceState = rileyLinkUtil.getServiceState();
|
RileyLinkServiceState rileyLinkServiceState = rileyLinkServiceData.rileyLinkServiceState;
|
||||||
|
|
||||||
if (rileyLinkServiceState == null) {
|
if (rileyLinkServiceState == null) {
|
||||||
aapsLogger.debug(LTag.PUMP, "RileyLink unreachable. RileyLinkServiceState is null.");
|
aapsLogger.debug(LTag.PUMP, "RileyLink unreachable. RileyLinkServiceState is null.");
|
||||||
|
|
|
@ -24,6 +24,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RLMe
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioPacket;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioPacket;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioResponse;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioResponse;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RLMessageType;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RLMessageType;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
||||||
|
@ -66,6 +67,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
@Inject MedtronicConverter medtronicConverter;
|
@Inject MedtronicConverter medtronicConverter;
|
||||||
@Inject MedtronicUtil medtronicUtil;
|
@Inject MedtronicUtil medtronicUtil;
|
||||||
@Inject MedtronicPumpHistoryDecoder medtronicPumpHistoryDecoder;
|
@Inject MedtronicPumpHistoryDecoder medtronicPumpHistoryDecoder;
|
||||||
|
@Inject RileyLinkServiceData rileyLinkServiceData;
|
||||||
|
|
||||||
private final int MAX_COMMAND_TRIES = 3;
|
private final int MAX_COMMAND_TRIES = 3;
|
||||||
private final int DEFAULT_TIMEOUT = 2000;
|
private final int DEFAULT_TIMEOUT = 2000;
|
||||||
|
@ -154,7 +156,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
if (rfSpyResponse.wasTimeout()) {
|
if (rfSpyResponse.wasTimeout()) {
|
||||||
aapsLogger.error(LTag.PUMPBTCOMM, "isDeviceReachable. Failed to find pump (timeout).");
|
aapsLogger.error(LTag.PUMPBTCOMM, "isDeviceReachable. Failed to find pump (timeout).");
|
||||||
} else if (rfSpyResponse.looksLikeRadioPacket()) {
|
} else if (rfSpyResponse.looksLikeRadioPacket()) {
|
||||||
RadioResponse radioResponse = new RadioResponse();
|
RadioResponse radioResponse = new RadioResponse(injector);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -470,11 +472,11 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
public byte[] createPumpMessageContent(RLMessageType type) {
|
public byte[] createPumpMessageContent(RLMessageType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PowerOn:
|
case PowerOn:
|
||||||
return medtronicUtil.buildCommandPayload(MedtronicCommandType.RFPowerOn, //
|
return medtronicUtil.buildCommandPayload(rileyLinkServiceData, MedtronicCommandType.RFPowerOn, //
|
||||||
new byte[]{2, 1, (byte) receiverDeviceAwakeForMinutes}); // maybe this is better FIXME
|
new byte[]{2, 1, (byte) receiverDeviceAwakeForMinutes}); // maybe this is better FIXME
|
||||||
|
|
||||||
case ReadSimpleData:
|
case ReadSimpleData:
|
||||||
return medtronicUtil.buildCommandPayload(MedtronicCommandType.PumpModel, null);
|
return medtronicUtil.buildCommandPayload(rileyLinkServiceData, MedtronicCommandType.PumpModel, null);
|
||||||
}
|
}
|
||||||
return new byte[0];
|
return new byte[0];
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import javax.inject.Singleton;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
|
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BasalProfileStatus;
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BasalProfileStatus;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType;
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType;
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType;
|
||||||
|
@ -40,7 +39,6 @@ public class MedtronicPumpStatus extends PumpStatus {
|
||||||
public Double maxBasal;
|
public Double maxBasal;
|
||||||
|
|
||||||
// statuses
|
// statuses
|
||||||
public RileyLinkServiceState rileyLinkServiceState = RileyLinkServiceState.NotStarted;
|
|
||||||
public RileyLinkError rileyLinkError;
|
public RileyLinkError rileyLinkError;
|
||||||
public PumpDeviceState pumpDeviceState = PumpDeviceState.NeverContacted;
|
public PumpDeviceState pumpDeviceState = PumpDeviceState.NeverContacted;
|
||||||
public MedtronicDeviceType medtronicDeviceType = null;
|
public MedtronicDeviceType medtronicDeviceType = null;
|
||||||
|
|
|
@ -20,7 +20,6 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.Rile
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager;
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager;
|
||||||
|
@ -46,7 +45,6 @@ public class RileyLinkMedtronicService extends RileyLinkService {
|
||||||
@Inject MedtronicUIPostprocessor medtronicUIPostprocessor;
|
@Inject MedtronicUIPostprocessor medtronicUIPostprocessor;
|
||||||
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||||
|
|
||||||
|
|
||||||
private MedtronicUIComm medtronicUIComm;
|
private MedtronicUIComm medtronicUIComm;
|
||||||
private MedtronicCommunicationManager medtronicCommunicationManager;
|
private MedtronicCommunicationManager medtronicCommunicationManager;
|
||||||
private IBinder mBinder = new LocalBinder();
|
private IBinder mBinder = new LocalBinder();
|
||||||
|
@ -94,17 +92,14 @@ public class RileyLinkMedtronicService extends RileyLinkService {
|
||||||
frequencies[0] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_us_ca);
|
frequencies[0] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_us_ca);
|
||||||
frequencies[1] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_worldwide);
|
frequencies[1] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_worldwide);
|
||||||
|
|
||||||
rileyLinkServiceData = new RileyLinkServiceData(RileyLinkTargetDevice.MedtronicPump);
|
rileyLinkServiceData.targetDevice = RileyLinkTargetDevice.MedtronicPump;
|
||||||
|
|
||||||
rileyLinkUtil.setRileyLinkServiceData(rileyLinkServiceData);
|
|
||||||
rileyLinkUtil.setTargetDevice(RileyLinkTargetDevice.MedtronicPump);
|
|
||||||
|
|
||||||
setPumpIDString(sp.getString(MedtronicConst.Prefs.PumpSerial, "000000"));
|
setPumpIDString(sp.getString(MedtronicConst.Prefs.PumpSerial, "000000"));
|
||||||
|
|
||||||
// get most recently used RileyLink address
|
// get most recently used RileyLink address
|
||||||
rileyLinkServiceData.rileylinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
|
rileyLinkServiceData.rileylinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
|
||||||
|
|
||||||
rileyLinkBLE = new RileyLinkBLE(this.context); // or this
|
rileyLinkBLE = new RileyLinkBLE(injector, this); // or this
|
||||||
rfspy = new RFSpy(rileyLinkBLE);
|
rfspy = new RFSpy(rileyLinkBLE);
|
||||||
rfspy.startReader();
|
rfspy.startReader();
|
||||||
|
|
||||||
|
@ -185,7 +180,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
|
||||||
// PumpInterface - REMOVE
|
// PumpInterface - REMOVE
|
||||||
|
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
return RileyLinkServiceState.isReady(rileyLinkUtil.getRileyLinkServiceData().serviceState);
|
return RileyLinkServiceState.isReady(rileyLinkServiceData.rileyLinkServiceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import info.nightscout.androidaps.plugins.general.overview.notifications.Notific
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.ClockDTO;
|
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.ClockDTO;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.PumpSettingDTO;
|
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.PumpSettingDTO;
|
||||||
|
@ -55,17 +56,19 @@ public class MedtronicUtil {
|
||||||
private final AAPSLogger aapsLogger;
|
private final AAPSLogger aapsLogger;
|
||||||
private final RxBusWrapper rxBus;
|
private final RxBusWrapper rxBus;
|
||||||
private final RileyLinkUtil rileyLinkUtil;
|
private final RileyLinkUtil rileyLinkUtil;
|
||||||
|
private final RileyLinkServiceData rileyLinkServiceData;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public MedtronicUtil(
|
public MedtronicUtil(
|
||||||
AAPSLogger aapsLogger,
|
AAPSLogger aapsLogger,
|
||||||
RxBusWrapper rxBus,
|
RxBusWrapper rxBus,
|
||||||
RileyLinkUtil rileyLinkUtil
|
RileyLinkUtil rileyLinkUtil,
|
||||||
|
RileyLinkServiceData rileyLinkServiceData
|
||||||
) {
|
) {
|
||||||
this.aapsLogger = aapsLogger;
|
this.aapsLogger = aapsLogger;
|
||||||
this.rxBus = rxBus;
|
this.rxBus = rxBus;
|
||||||
this.rileyLinkUtil = rileyLinkUtil;
|
this.rileyLinkUtil = rileyLinkUtil;
|
||||||
|
this.rileyLinkServiceData = rileyLinkServiceData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalTime getTimeFrom30MinInterval(int interval) {
|
public LocalTime getTimeFrom30MinInterval(int interval) {
|
||||||
|
@ -241,12 +244,12 @@ public class MedtronicUtil {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
public byte[] buildCommandPayload(MedtronicCommandType commandType, byte[] parameters) {
|
public byte[] buildCommandPayload(RileyLinkServiceData rileyLinkServiceData, MedtronicCommandType commandType, byte[] parameters) {
|
||||||
return buildCommandPayload((byte) commandType.commandCode, parameters);
|
return buildCommandPayload(rileyLinkServiceData, (byte) commandType.commandCode, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public byte[] buildCommandPayload(byte commandType, byte[] parameters) {
|
public byte[] buildCommandPayload(RileyLinkServiceData rileyLinkServiceData, byte commandType, byte[] parameters) {
|
||||||
// A7 31 65 51 C0 00 52
|
// A7 31 65 51 C0 00 52
|
||||||
|
|
||||||
byte commandLength = (byte) (parameters == null ? 2 : 2 + parameters.length);
|
byte commandLength = (byte) (parameters == null ? 2 : 2 + parameters.length);
|
||||||
|
@ -254,7 +257,7 @@ public class MedtronicUtil {
|
||||||
ByteBuffer sendPayloadBuffer = ByteBuffer.allocate(ENVELOPE_SIZE + commandLength); // + CRC_SIZE
|
ByteBuffer sendPayloadBuffer = ByteBuffer.allocate(ENVELOPE_SIZE + commandLength); // + CRC_SIZE
|
||||||
sendPayloadBuffer.order(ByteOrder.BIG_ENDIAN);
|
sendPayloadBuffer.order(ByteOrder.BIG_ENDIAN);
|
||||||
|
|
||||||
byte[] serialNumberBCD = rileyLinkUtil.getRileyLinkServiceData().pumpIDBytes;
|
byte[] serialNumberBCD = rileyLinkServiceData.pumpIDBytes;
|
||||||
|
|
||||||
sendPayloadBuffer.put((byte) 0xA7);
|
sendPayloadBuffer.put((byte) 0xA7);
|
||||||
sendPayloadBuffer.put(serialNumberBCD[0]);
|
sendPayloadBuffer.put(serialNumberBCD[0]);
|
||||||
|
@ -398,7 +401,7 @@ public class MedtronicUtil {
|
||||||
public void setPumpDeviceState(PumpDeviceState pumpDeviceState) {
|
public void setPumpDeviceState(PumpDeviceState pumpDeviceState) {
|
||||||
this.pumpDeviceState = pumpDeviceState;
|
this.pumpDeviceState = pumpDeviceState;
|
||||||
|
|
||||||
rileyLinkUtil.historyRileyLink.add(new RLHistoryItem(pumpDeviceState, RileyLinkTargetDevice.MedtronicPump));
|
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(pumpDeviceState, RileyLinkTargetDevice.MedtronicPump));
|
||||||
|
|
||||||
rxBus.send(new EventMedtronicDeviceStatusChange(pumpDeviceState));
|
rxBus.send(new EventMedtronicDeviceStatusChange(pumpDeviceState));
|
||||||
}
|
}
|
||||||
|
@ -426,7 +429,7 @@ public class MedtronicUtil {
|
||||||
this.currentCommand = currentCommand;
|
this.currentCommand = currentCommand;
|
||||||
|
|
||||||
if (currentCommand != null)
|
if (currentCommand != null)
|
||||||
rileyLinkUtil.historyRileyLink.add(new RLHistoryItem(currentCommand));
|
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(currentCommand));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue