Also retrieve battery level for Medtronic and show it in RileyLink status fragment

This commit is contained in:
Bart Sopers 2021-01-07 00:05:07 +01:00
parent 71eca73b3a
commit 169443e5f7
9 changed files with 93 additions and 166 deletions

View file

@ -48,7 +48,6 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.common.ManufacturerType; import info.nightscout.androidaps.plugins.common.ManufacturerType;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
import info.nightscout.androidaps.queue.commands.CustomCommand;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract; import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
@ -86,6 +85,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPu
import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService; import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.queue.commands.CustomCommand;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.TimeChangeType; import info.nightscout.androidaps.utils.TimeChangeType;
@ -327,11 +327,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
} }
@Override public RileyLinkPumpInfo getPumpInfo() { @Override public RileyLinkPumpInfo getPumpInfo() {
String pumpDescription = pumpType.getDescription();
String frequency = resourceHelper.gs(medtronicPumpStatus.pumpFrequency.equals("medtronic_pump_frequency_us_ca") ? R.string.medtronic_pump_frequency_us_ca : R.string.medtronic_pump_frequency_worldwide); String frequency = resourceHelper.gs(medtronicPumpStatus.pumpFrequency.equals("medtronic_pump_frequency_us_ca") ? R.string.medtronic_pump_frequency_us_ca : R.string.medtronic_pump_frequency_worldwide);
String model = medtronicPumpStatus.medtronicDeviceType == null ? "???" : "Medtronic " + medtronicPumpStatus.medtronicDeviceType.getPumpModel(); String model = medtronicPumpStatus.medtronicDeviceType == null ? "???" : "Medtronic " + medtronicPumpStatus.medtronicDeviceType.getPumpModel();
String serialNumber = medtronicPumpStatus.serialNumber; String serialNumber = medtronicPumpStatus.serialNumber;
return new RileyLinkPumpInfo(pumpDescription, frequency, model, serialNumber); return new RileyLinkPumpInfo(frequency, model, serialNumber);
} }
@Override public long getLastConnectionTimeMillis() { @Override public long getLastConnectionTimeMillis() {

View file

@ -509,11 +509,10 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
} }
@Override public RileyLinkPumpInfo getPumpInfo() { @Override public RileyLinkPumpInfo getPumpInfo() {
String pumpDescription = "Eros";
String frequency = resourceHelper.gs(R.string.omnipod_frequency); String frequency = resourceHelper.gs(R.string.omnipod_frequency);
String connectedModel = podStateManager.isPodInitialized() ? "Eros Pod" : "-"; String connectedModel = "Eros";
String serialNumber = podStateManager.isPodInitialized() ? String.valueOf(podStateManager.getAddress()) : "-"; String serialNumber = podStateManager.isPodInitialized() ? String.valueOf(podStateManager.getAddress()) : "-";
return new RileyLinkPumpInfo(pumpDescription, frequency, connectedModel, serialNumber); return new RileyLinkPumpInfo(frequency, connectedModel, serialNumber);
} }
// Required by RileyLinkPumpDevice interface. // Required by RileyLinkPumpDevice interface.
@ -615,8 +614,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
@Override @Override
public int getBatteryLevel() { public int getBatteryLevel() {
if (aapsOmnipodManager.isUseRileyLinkBatteryLevel()) { if (aapsOmnipodManager.isUseRileyLinkBatteryLevel()) {
Integer batteryLevel = omnipodRileyLinkCommunicationManager.getBatteryLevel(); return Optional.ofNullable(rileyLinkServiceData.batteryLevel).orElse(0);
return batteryLevel == null ? 0 : batteryLevel;
} }
return 0; return 0;

View file

@ -8,7 +8,6 @@ import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState; import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
@ -16,7 +15,6 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLink
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.ble.defs.RileyLinkBLEError; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkBLEError;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.action.OmnipodAction; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.action.OmnipodAction;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.MessageBlock; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.MessageBlock;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.OmnipodMessage; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.OmnipodMessage;
@ -52,7 +50,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateMa
*/ */
@Singleton @Singleton
public class OmnipodRileyLinkCommunicationManager extends RileyLinkCommunicationManager<OmnipodPacket> { public class OmnipodRileyLinkCommunicationManager extends RileyLinkCommunicationManager<OmnipodPacket> {
private Integer batteryLevel;
// This empty constructor must be kept, otherwise dagger injection might break! // This empty constructor must be kept, otherwise dagger injection might break!
@Inject @Inject
@ -86,18 +83,7 @@ public class OmnipodRileyLinkCommunicationManager extends RileyLinkCommunication
} }
@Override protected OmnipodPacket sendAndListen(OmnipodPacket msg, int timeout_ms, int repeatCount, int retryCount, Integer extendPreamble_ms) throws RileyLinkCommunicationException { @Override protected OmnipodPacket sendAndListen(OmnipodPacket msg, int timeout_ms, int repeatCount, int retryCount, Integer extendPreamble_ms) throws RileyLinkCommunicationException {
OmnipodPacket response = super.sendAndListen(msg, timeout_ms, repeatCount, retryCount, extendPreamble_ms); return super.sendAndListen(msg, timeout_ms, repeatCount, retryCount, extendPreamble_ms);
PumpInterface activePump = activePluginProvider.getActivePump();
if (activePump instanceof OmnipodPumpPlugin && ((OmnipodPumpPlugin) activePump).isUseRileyLinkBatteryLevel()) {
updateBatteryLevel();
}
return response;
}
public Integer getBatteryLevel() {
return batteryLevel;
} }
public <T extends MessageBlock> T sendCommand(Class<T> responseClass, PodStateManager podStateManager, MessageBlock command) { public <T extends MessageBlock> T sendCommand(Class<T> responseClass, PodStateManager podStateManager, MessageBlock command) {
@ -402,8 +388,4 @@ public class OmnipodRileyLinkCommunicationManager extends RileyLinkCommunication
throw new RileyLinkUnreachableException(); throw new RileyLinkUnreachableException();
} }
private void updateBatteryLevel() {
batteryLevel = rfspy.getBatteryLevel();
}
} }

View file

@ -2,14 +2,17 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble;
import android.os.SystemClock; import android.os.SystemClock;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import dagger.android.HasAndroidInjector; import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.events.EventRefreshOverview;
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.R; import info.nightscout.androidaps.plugins.pump.common.R;
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;
@ -40,12 +43,16 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
*/ */
@Singleton @Singleton
public class RFSpy { public class RFSpy {
private static final long DEFAULT_BATTERY_CHECK_INTERVAL_MILLIS = 30 * 60 * 1_000; // 30 minutes;
private static final long LOW_BATTERY_BATTERY_CHECK_INTERVAL_MILLIS = 10 * 60 * 1_000; // 10 minutes;
private static final int LOW_BATTERY_PERCENTAGE_THRESHOLD = 20;
@Inject AAPSLogger aapsLogger; @Inject AAPSLogger aapsLogger;
@Inject ResourceHelper resourceHelper; @Inject ResourceHelper resourceHelper;
@Inject SP sp; @Inject SP sp;
@Inject RileyLinkServiceData rileyLinkServiceData; @Inject RileyLinkServiceData rileyLinkServiceData;
@Inject RileyLinkUtil rileyLinkUtil; @Inject RileyLinkUtil rileyLinkUtil;
@Inject RxBusWrapper rxBus;
private final HasAndroidInjector injector; private final HasAndroidInjector injector;
@ -59,11 +66,9 @@ public class RFSpy {
private final UUID radioVersionUUID = UUID.fromString(GattAttributes.CHARA_RADIO_VERSION); private final UUID radioVersionUUID = UUID.fromString(GattAttributes.CHARA_RADIO_VERSION);
private final UUID batteryServiceUUID = UUID.fromString(GattAttributes.SERVICE_BATTERY); private final UUID batteryServiceUUID = UUID.fromString(GattAttributes.SERVICE_BATTERY);
private final UUID batteryLevelUUID = UUID.fromString(GattAttributes.CHARA_BATTERY_UNK); private final UUID batteryLevelUUID = UUID.fromString(GattAttributes.CHARA_BATTERY_UNK);
//private UUID responseCountUUID = UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT);
private RileyLinkFirmwareVersion firmwareVersion;
private String bleVersion; // We don't use it so no need of sofisticated logic private String bleVersion; // We don't use it so no need of sofisticated logic
private Double currentFrequencyMHz; private Double currentFrequencyMHz;
private long nextBatteryCheck = 0;
@Inject @Inject
public RFSpy(HasAndroidInjector injector, RileyLinkBLE rileyLinkBle) { public RFSpy(HasAndroidInjector injector, RileyLinkBLE rileyLinkBle) {
@ -77,17 +82,10 @@ public class RFSpy {
reader = new RFSpyReader(aapsLogger, rileyLinkBle); reader = new RFSpyReader(aapsLogger, rileyLinkBle);
} }
public RileyLinkFirmwareVersion getRLVersionCached() {
return firmwareVersion;
}
public String getBLEVersionCached() { public String getBLEVersionCached() {
return bleVersion; return bleVersion;
} }
// Call this after the RL services are discovered. // Call this after the RL services are discovered.
// Starts an async task to read when data is available // Starts an async task to read when data is available
public void startReader() { public void startReader() {
@ -95,7 +93,6 @@ public class RFSpy {
reader.start(); reader.start();
} }
// Here should go generic RL initialisation + protocol adjustments depending on // Here should go generic RL initialisation + protocol adjustments depending on
// firmware version // firmware version
public void initializeRileyLink() { public void initializeRileyLink() {
@ -105,14 +102,13 @@ public class RFSpy {
rileyLinkServiceData.firmwareVersion = getFirmwareVersion(aapsLogger, bleVersion, cc1110Version); rileyLinkServiceData.firmwareVersion = getFirmwareVersion(aapsLogger, bleVersion, cc1110Version);
} }
// Call this from the "response count" notification handler. // Call this from the "response count" notification handler.
private void newDataIsAvailable() { private void newDataIsAvailable() {
// pass the message to the reader (which should be internal to RFSpy) // pass the message to the reader (which should be internal to RFSpy)
reader.newDataIsAvailable(); reader.newDataIsAvailable();
} }
public Integer getBatteryLevel() { public Integer retrieveBatteryLevel() {
BLECommOperationResult result = rileyLinkBle.readCharacteristic_blocking(batteryServiceUUID, batteryLevelUUID); BLECommOperationResult result = rileyLinkBle.readCharacteristic_blocking(batteryServiceUUID, batteryLevelUUID);
if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) { if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) {
int value = result.value[0]; int value = result.value[0];
@ -124,7 +120,6 @@ public class RFSpy {
} }
} }
// This gets the version from the BLE113, not from the CC1110. // This gets the version from the BLE113, not from the CC1110.
// I.e., this gets the version from the BLE interface, not from the radio. // I.e., this gets the version from the BLE interface, not from the radio.
public String getVersion() { public String getVersion() {
@ -208,14 +203,12 @@ public class RFSpy {
aapsLogger.error(LTag.PUMPBTCOMM, "BLE Write operation failed, code=" + writeCheck.resultCode); aapsLogger.error(LTag.PUMPBTCOMM, "BLE Write operation failed, code=" + writeCheck.resultCode);
return null; // will be a null (invalid) response return null; // will be a null (invalid) response
} }
SystemClock.sleep(100); SystemClock.sleep(100);
// Log.i(TAG,ThreadUtil.sig()+String.format(" writeToData:(timeout %d) %s",(responseTimeout_ms),ByteUtil.shortHexString(prepended)));
byte[] rawResponse = reader.poll(responseTimeout_ms);
return rawResponse;
return reader.poll(responseTimeout_ms);
} }
// The caller has to know how long the RFSpy will be busy with what was sent to it. // The caller has to know how long the RFSpy will be busy with what was sent to it.
private RFSpyResponse writeToData(RileyLinkCommand command, int responseTimeout_ms) { private RFSpyResponse writeToData(RileyLinkCommand command, int responseTimeout_ms) {
@ -236,55 +229,26 @@ public class RFSpy {
resetNotConnectedCount(); resetNotConnectedCount();
} else { } else {
if (resp.looksLikeRadioPacket()) { if (resp.looksLikeRadioPacket()) {
// RadioResponse radioResp = resp.getRadioResponse();
// byte[] responsePayload = radioResp.getPayload();
aapsLogger.debug(LTag.PUMPBTCOMM, "writeToData: received radio response. Will decode at upper level"); aapsLogger.debug(LTag.PUMPBTCOMM, "writeToData: received radio response. Will decode at upper level");
resetNotConnectedCount(); resetNotConnectedCount();
} }
// Log.i(TAG, "writeToData: raw response is " + ByteUtil.shortHexString(rawResponse));
} }
return resp; return resp;
} }
private void resetNotConnectedCount() { private void resetNotConnectedCount() {
this.notConnectedCount = 0; this.notConnectedCount = 0;
} }
private byte[] getByteArray(byte... input) { private byte[] getByteArray(byte... input) {
return input; return input;
} }
private byte[] getCommandArray(RileyLinkCommandType command, byte[] body) {
int bodyLength = body == null ? 0 : body.length;
byte[] output = new byte[bodyLength + 1];
output[0] = command.code;
if (body != null) {
for (int i = 0; i < body.length; i++) {
output[i + 1] = body[i];
}
}
return output;
}
public RFSpyResponse transmitThenReceive(RadioPacket pkt, byte sendChannel, byte repeatCount, byte delay_ms, public RFSpyResponse transmitThenReceive(RadioPacket pkt, byte sendChannel, byte repeatCount, byte delay_ms,
byte listenChannel, int timeout_ms, byte retryCount) { byte listenChannel, int timeout_ms, byte retryCount) {
return transmitThenReceive(pkt, sendChannel, repeatCount, delay_ms, listenChannel, timeout_ms, retryCount, null); return transmitThenReceive(pkt, sendChannel, repeatCount, delay_ms, listenChannel, timeout_ms, retryCount, null);
} }
public RFSpyResponse transmitThenReceive(RadioPacket pkt, int timeout_ms) {
return transmitThenReceive(pkt, (byte) 0, (byte) 0, (byte) 0, (byte) 0, timeout_ms, (byte) 0);
}
public RFSpyResponse transmitThenReceive(RadioPacket pkt, byte sendChannel, byte repeatCount, byte delay_ms, public RFSpyResponse transmitThenReceive(RadioPacket pkt, byte sendChannel, byte repeatCount, byte delay_ms,
byte listenChannel, int timeout_ms, byte retryCount, Integer extendPreamble_ms) { byte listenChannel, int timeout_ms, byte retryCount, Integer extendPreamble_ms) {
@ -294,16 +258,29 @@ public class RFSpy {
SendAndListen command = new SendAndListen(injector, sendChannel, repeatCount, delay_ms, listenChannel, timeout_ms, SendAndListen command = new SendAndListen(injector, sendChannel, repeatCount, delay_ms, listenChannel, timeout_ms,
retryCount, extendPreamble_ms, pkt); retryCount, extendPreamble_ms, pkt);
return writeToData(command, sendDelay + receiveDelay + EXPECTED_MAX_BLUETOOTH_LATENCY_MS); RFSpyResponse rfSpyResponse = writeToData(command, sendDelay + receiveDelay + EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
if (System.currentTimeMillis() >= nextBatteryCheck) {
updateBatteryLevel();
}
return rfSpyResponse;
} }
private void updateBatteryLevel() {
rileyLinkServiceData.batteryLevel = retrieveBatteryLevel();
nextBatteryCheck = System.currentTimeMillis() +
(Optional.ofNullable(rileyLinkServiceData.batteryLevel).orElse(0) <= LOW_BATTERY_PERCENTAGE_THRESHOLD ? LOW_BATTERY_BATTERY_CHECK_INTERVAL_MILLIS : DEFAULT_BATTERY_CHECK_INTERVAL_MILLIS);
// The Omnipod plugin reports the RL battery as the pump battery (as the Omnipod battery level is unknown)
// So update overview when the battery level has been updated
rxBus.send(new EventRefreshOverview("RL battery level updated", false));
}
private RFSpyResponse updateRegister(CC111XRegister reg, int val) { private RFSpyResponse updateRegister(CC111XRegister reg, int val) {
RFSpyResponse resp = writeToData(new UpdateRegister(reg, (byte) val), EXPECTED_MAX_BLUETOOTH_LATENCY_MS); return writeToData(new UpdateRegister(reg, (byte) val), EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
return resp;
} }
public void setBaseFrequency(double freqMHz) { public void setBaseFrequency(double freqMHz) {
int value = (int) (freqMHz * 1000000 / ((double) (RILEYLINK_FREQ_XTAL) / Math.pow(2.0, 16.0))); int value = (int) (freqMHz * 1000000 / ((double) (RILEYLINK_FREQ_XTAL) / Math.pow(2.0, 16.0)));
updateRegister(CC111XRegister.freq0, (byte) (value & 0xff)); updateRegister(CC111XRegister.freq0, (byte) (value & 0xff));
@ -316,69 +293,56 @@ public class RFSpy {
configureRadioForRegion(rileyLinkServiceData.rileyLinkTargetFrequency); configureRadioForRegion(rileyLinkServiceData.rileyLinkTargetFrequency);
} }
private void configureRadioForRegion(RileyLinkTargetFrequency frequency) { private void configureRadioForRegion(RileyLinkTargetFrequency frequency) {
// we update registers only on first run, or if region changed // we update registers only on first run, or if region changed
aapsLogger.error(LTag.PUMPBTCOMM, "RileyLinkTargetFrequency: " + frequency); aapsLogger.error(LTag.PUMPBTCOMM, "RileyLinkTargetFrequency: " + frequency);
switch (frequency) { switch (frequency) {
case Medtronic_WorldWide: { case Medtronic_WorldWide:
// updateRegister(CC111X_MDMCFG4, (byte) 0x59);
setRXFilterMode(RXFilterMode.Wide); setRXFilterMode(RXFilterMode.Wide);
// updateRegister(CC111X_MDMCFG3, (byte) 0x66);
// updateRegister(CC111X_MDMCFG2, (byte) 0x33);
updateRegister(CC111XRegister.mdmcfg1, 0x62); updateRegister(CC111XRegister.mdmcfg1, 0x62);
updateRegister(CC111XRegister.mdmcfg0, 0x1A); updateRegister(CC111XRegister.mdmcfg0, 0x1A);
updateRegister(CC111XRegister.deviatn, 0x13); updateRegister(CC111XRegister.deviatn, 0x13);
setMedtronicEncoding(); setMedtronicEncoding();
} break;
break;
case Medtronic_US: { case Medtronic_US:
// updateRegister(CC111X_MDMCFG4, (byte) 0x99);
setRXFilterMode(RXFilterMode.Narrow); setRXFilterMode(RXFilterMode.Narrow);
// updateRegister(CC111X_MDMCFG3, (byte) 0x66);
// updateRegister(CC111X_MDMCFG2, (byte) 0x33);
updateRegister(CC111XRegister.mdmcfg1, 0x61); updateRegister(CC111XRegister.mdmcfg1, 0x61);
updateRegister(CC111XRegister.mdmcfg0, 0x7E); updateRegister(CC111XRegister.mdmcfg0, 0x7E);
updateRegister(CC111XRegister.deviatn, 0x15); updateRegister(CC111XRegister.deviatn, 0x15);
setMedtronicEncoding(); setMedtronicEncoding();
} break;
break;
case Omnipod: { case Omnipod:
RFSpyResponse r = null;
// RL initialization for Omnipod is a copy/paste from OmniKit implementation. // RL initialization for Omnipod is a copy/paste from OmniKit implementation.
// Last commit from original repository: 5c3beb4144 // Last commit from original repository: 5c3beb4144
// so if something is terribly wrong, please check git diff PodCommsSession.swift since that commit // so if something is terribly wrong, please check git diff PodCommsSession.swift since that commit
r = updateRegister(CC111XRegister.pktctrl1, 0x20); updateRegister(CC111XRegister.pktctrl1, 0x20);
r = updateRegister(CC111XRegister.agcctrl0, 0x00); updateRegister(CC111XRegister.agcctrl0, 0x00);
r = updateRegister(CC111XRegister.fsctrl1, 0x06); updateRegister(CC111XRegister.fsctrl1, 0x06);
r = updateRegister(CC111XRegister.mdmcfg4, 0xCA); updateRegister(CC111XRegister.mdmcfg4, 0xCA);
r = updateRegister(CC111XRegister.mdmcfg3, 0xBC); updateRegister(CC111XRegister.mdmcfg3, 0xBC);
r = updateRegister(CC111XRegister.mdmcfg2, 0x06); updateRegister(CC111XRegister.mdmcfg2, 0x06);
r = updateRegister(CC111XRegister.mdmcfg1, 0x70); updateRegister(CC111XRegister.mdmcfg1, 0x70);
r = updateRegister(CC111XRegister.mdmcfg0, 0x11); updateRegister(CC111XRegister.mdmcfg0, 0x11);
r = updateRegister(CC111XRegister.deviatn, 0x44); updateRegister(CC111XRegister.deviatn, 0x44);
r = updateRegister(CC111XRegister.mcsm0, 0x18); updateRegister(CC111XRegister.mcsm0, 0x18);
r = updateRegister(CC111XRegister.foccfg, 0x17); updateRegister(CC111XRegister.foccfg, 0x17);
r = updateRegister(CC111XRegister.fscal3, 0xE9); updateRegister(CC111XRegister.fscal3, 0xE9);
r = updateRegister(CC111XRegister.fscal2, 0x2A); updateRegister(CC111XRegister.fscal2, 0x2A);
r = updateRegister(CC111XRegister.fscal1, 0x00); updateRegister(CC111XRegister.fscal1, 0x00);
r = updateRegister(CC111XRegister.fscal0, 0x1F); updateRegister(CC111XRegister.fscal0, 0x1F);
r = updateRegister(CC111XRegister.test1, 0x31); updateRegister(CC111XRegister.test1, 0x31);
r = updateRegister(CC111XRegister.test0, 0x09); updateRegister(CC111XRegister.test0, 0x09);
r = updateRegister(CC111XRegister.paTable0, 0x84); updateRegister(CC111XRegister.paTable0, 0x84);
r = updateRegister(CC111XRegister.sync1, 0xA5); updateRegister(CC111XRegister.sync1, 0xA5);
r = updateRegister(CC111XRegister.sync0, 0x5A); updateRegister(CC111XRegister.sync0, 0x5A);
r = setRileyLinkEncoding(RileyLinkEncodingType.Manchester); setRileyLinkEncoding(RileyLinkEncodingType.Manchester);
r = setPreamble(0x6665); setPreamble(0x6665);
break;
}
break;
default: default:
aapsLogger.warn(LTag.PUMPBTCOMM, "No region configuration for RfSpy and {}", frequency.name()); aapsLogger.warn(LTag.PUMPBTCOMM, "No region configuration for RfSpy and {}", frequency.name());
break; break;
@ -386,7 +350,6 @@ public class RFSpy {
} }
} }
private void setMedtronicEncoding() { private void setMedtronicEncoding() {
RileyLinkEncodingType encoding = RileyLinkEncodingType.FourByteSixByteLocal; RileyLinkEncodingType encoding = RileyLinkEncodingType.FourByteSixByteLocal;
@ -402,7 +365,6 @@ public class RFSpy {
aapsLogger.debug(LTag.PUMPBTCOMM, "Set Encoding for Medtronic: " + encoding.name()); aapsLogger.debug(LTag.PUMPBTCOMM, "Set Encoding for Medtronic: " + encoding.name());
} }
private RFSpyResponse setPreamble(int preamble) { private RFSpyResponse setPreamble(int preamble) {
RFSpyResponse resp = null; RFSpyResponse resp = null;
try { try {
@ -413,7 +375,6 @@ public class RFSpy {
return resp; return resp;
} }
public RFSpyResponse setRileyLinkEncoding(RileyLinkEncodingType encoding) { public RFSpyResponse setRileyLinkEncoding(RileyLinkEncodingType encoding) {
RFSpyResponse resp = writeToData(new SetHardwareEncoding(encoding), EXPECTED_MAX_BLUETOOTH_LATENCY_MS); RFSpyResponse resp = writeToData(new SetHardwareEncoding(encoding), EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
@ -425,9 +386,7 @@ public class RFSpy {
return resp; return resp;
} }
private void setRXFilterMode(RXFilterMode mode) { private void setRXFilterMode(RXFilterMode mode) {
byte drate_e = (byte) 0x9; // exponent of symbol rate (16kbps) byte drate_e = (byte) 0x9; // exponent of symbol rate (16kbps)
byte chanbw = mode.value; byte chanbw = mode.value;
@ -441,9 +400,4 @@ public class RFSpy {
if (this.currentFrequencyMHz != null) if (this.currentFrequencyMHz != null)
this.setBaseFrequency(this.currentFrequencyMHz); this.setBaseFrequency(this.currentFrequencyMHz);
} }
public void stopReader() {
reader.stop();
}
} }

View file

@ -1,13 +1,11 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs; package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs;
public class RileyLinkPumpInfo { public class RileyLinkPumpInfo {
private final String connectedDeviceModel;
private final String pumpDescription;
private final String connectedDeviceSerialNumber;
private final String pumpFrequency; private final String pumpFrequency;
private final String connectedDeviceModel;
private final String connectedDeviceSerialNumber;
public RileyLinkPumpInfo(String pumpDescription, String pumpFrequency, String connectedDeviceModel, String connectedDeviceSerialNumber) { public RileyLinkPumpInfo(String pumpFrequency, String connectedDeviceModel, String connectedDeviceSerialNumber) {
this.pumpDescription = pumpDescription;
this.pumpFrequency = pumpFrequency; this.pumpFrequency = pumpFrequency;
this.connectedDeviceModel = connectedDeviceModel; this.connectedDeviceModel = connectedDeviceModel;
this.connectedDeviceSerialNumber = connectedDeviceSerialNumber; this.connectedDeviceSerialNumber = connectedDeviceSerialNumber;
@ -17,10 +15,6 @@ public class RileyLinkPumpInfo {
return connectedDeviceModel; return connectedDeviceModel;
} }
public String getPumpDescription() {
return pumpDescription;
}
public String getConnectedDeviceSerialNumber() { public String getConnectedDeviceSerialNumber() {
return connectedDeviceSerialNumber; return connectedDeviceSerialNumber;
} }

View file

@ -6,10 +6,9 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.LocalDateTime; import org.joda.time.LocalDateTime;
import java.util.Locale; import java.util.Optional;
import javax.inject.Inject; import javax.inject.Inject;
@ -18,6 +17,7 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.plugins.pump.common.R; import info.nightscout.androidaps.plugins.pump.common.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.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpInfo; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpInfo;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
@ -43,7 +43,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
private TextView connectionStatus; private TextView connectionStatus;
private TextView configuredRileyLinkAddress; private TextView configuredRileyLinkAddress;
private TextView configuredRileyLinkName; private TextView configuredRileyLinkName;
private TextView connectedDevice; private TextView batteryLevel;
private TextView connectionError; private TextView connectionError;
private TextView deviceType; private TextView deviceType;
private TextView deviceModel; private TextView deviceModel;
@ -65,7 +65,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
this.connectionStatus = getActivity().findViewById(R.id.rls_t1_connection_status); this.connectionStatus = getActivity().findViewById(R.id.rls_t1_connection_status);
this.configuredRileyLinkAddress = getActivity().findViewById(R.id.rls_t1_configured_riley_link_address); this.configuredRileyLinkAddress = getActivity().findViewById(R.id.rls_t1_configured_riley_link_address);
this.configuredRileyLinkName = getActivity().findViewById(R.id.rls_t1_configured_riley_link_name); this.configuredRileyLinkName = getActivity().findViewById(R.id.rls_t1_configured_riley_link_name);
this.connectedDevice = getActivity().findViewById(R.id.rls_t1_connected_device); this.batteryLevel = getActivity().findViewById(R.id.rls_t1_battery_level);
this.connectionError = getActivity().findViewById(R.id.rls_t1_connection_error); this.connectionError = getActivity().findViewById(R.id.rls_t1_connection_error);
this.deviceType = getActivity().findViewById(R.id.rls_t1_device_type); this.deviceType = getActivity().findViewById(R.id.rls_t1_device_type);
this.deviceModel = getActivity().findViewById(R.id.rls_t1_device_model); this.deviceModel = getActivity().findViewById(R.id.rls_t1_device_model);
@ -85,31 +85,28 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
// BS FIXME rileyLinkServiceData is injected so I suppose it cannot be null? // BS FIXME rileyLinkServiceData is injected so I suppose it cannot be null?
if (rileyLinkServiceData != null) { if (rileyLinkServiceData != null) {
this.configuredRileyLinkAddress.setText(StringUtils.isEmpty(rileyLinkServiceData.rileyLinkAddress) ? PLACEHOLDER : rileyLinkServiceData.rileyLinkAddress); this.configuredRileyLinkAddress.setText(Optional.ofNullable(rileyLinkServiceData.rileyLinkAddress).orElse(PLACEHOLDER));
this.configuredRileyLinkName.setText(StringUtils.isEmpty(rileyLinkServiceData.rileyLinkName) ? PLACEHOLDER : rileyLinkServiceData.rileyLinkName); this.configuredRileyLinkName.setText(Optional.ofNullable(rileyLinkServiceData.rileyLinkName).orElse(PLACEHOLDER));
this.connectionError.setText(rileyLinkServiceData.rileyLinkError == null ? //
PLACEHOLDER
: resourceHelper.gs(rileyLinkServiceData.rileyLinkError.getResourceId(targetDevice)));
if (firmwareVersion == null) { Integer batteryLevel = rileyLinkServiceData.batteryLevel;
this.firmwareVersion.setText("BLE113: " + PLACEHOLDER + "\nCC110: " + PLACEHOLDER); this.batteryLevel.setText(batteryLevel == null ? PLACEHOLDER : resourceHelper.gs(R.string.rileylink_battery_level_value, batteryLevel));
} else {
this.firmwareVersion.setText("BLE113: " + rileyLinkServiceData.versionBLE113 + RileyLinkError rileyLinkError = rileyLinkServiceData.rileyLinkError;
"\nCC110: " + rileyLinkServiceData.versionCC110); this.connectionError.setText(rileyLinkError == null ? PLACEHOLDER : resourceHelper.gs(rileyLinkError.getResourceId(targetDevice)));
}
this.firmwareVersion.setText(resourceHelper.gs(R.string.rileylink_firmware_version_value,
Optional.ofNullable(rileyLinkServiceData.versionBLE113).orElse(PLACEHOLDER), Optional.ofNullable(rileyLinkServiceData.versionCC110).orElse(PLACEHOLDER)));
} }
RileyLinkPumpDevice pumpPlugin = (RileyLinkPumpDevice) activePlugin.getActivePump(); RileyLinkPumpDevice pumpPlugin = (RileyLinkPumpDevice) activePlugin.getActivePump();
RileyLinkPumpInfo pumpInfo = pumpPlugin.getPumpInfo(); RileyLinkPumpInfo pumpInfo = pumpPlugin.getPumpInfo();
this.deviceType.setText(rileyLinkServiceData.targetDevice.getResourceId()); this.deviceType.setText(rileyLinkServiceData.targetDevice.getResourceId());
this.deviceModel.setText(pumpInfo.getPumpDescription()); this.deviceModel.setText(pumpInfo.getConnectedDeviceModel());
this.serialNumber.setText(pumpInfo.getConnectedDeviceSerialNumber()); this.serialNumber.setText(pumpInfo.getConnectedDeviceSerialNumber());
this.pumpFrequency.setText(pumpInfo.getPumpFrequency()); this.pumpFrequency.setText(pumpInfo.getPumpFrequency());
this.connectedDevice.setText(pumpInfo.getConnectedDeviceModel());
if (rileyLinkServiceData.lastGoodFrequency != null) { if (rileyLinkServiceData.lastGoodFrequency != null) {
this.lastUsedFrequency.setText(String.format(Locale.ENGLISH, "%.2f MHz", this.lastUsedFrequency.setText(resourceHelper.gs(R.string.rileylink_pump_frequency_value, rileyLinkServiceData.lastGoodFrequency));
rileyLinkServiceData.lastGoodFrequency));
} }
long lastConnectionTimeMillis = pumpPlugin.getLastConnectionTimeMillis(); long lastConnectionTimeMillis = pumpPlugin.getLastConnectionTimeMillis();

View file

@ -20,6 +20,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLin
* Created by andy on 16/05/2018. * Created by andy on 16/05/2018.
*/ */
// FIXME encapsulation
@Singleton @Singleton
public class RileyLinkServiceData { public class RileyLinkServiceData {
@ -36,6 +37,7 @@ public class RileyLinkServiceData {
public RileyLinkTargetFrequency rileyLinkTargetFrequency; public RileyLinkTargetFrequency rileyLinkTargetFrequency;
public String rileyLinkAddress; public String rileyLinkAddress;
public String rileyLinkName; public String rileyLinkName;
public Integer batteryLevel;
long lastTuneUpTime = 0L; long lastTuneUpTime = 0L;
public Double lastGoodFrequency; public Double lastGoodFrequency;
@ -76,7 +78,6 @@ public class RileyLinkServiceData {
} }
private synchronized RileyLinkServiceState workWithServiceState(RileyLinkServiceState newState, RileyLinkError errorCode, boolean set) { private synchronized RileyLinkServiceState workWithServiceState(RileyLinkServiceState newState, RileyLinkError errorCode, boolean set) {
if (set) { if (set) {
rileyLinkServiceState = newState; rileyLinkServiceState = newState;
lastServiceStateChange = System.currentTimeMillis(); lastServiceStateChange = System.currentTimeMillis();
@ -90,7 +91,6 @@ public class RileyLinkServiceData {
} else { } else {
return rileyLinkServiceState; return rileyLinkServiceState;
} }
} }
} }

View file

@ -42,7 +42,7 @@
android:layout_marginLeft="30dp" android:layout_marginLeft="30dp"
android:layout_weight="35" android:layout_weight="35"
android:gravity="center_vertical" android:gravity="center_vertical"
android:text="@string/rileylink_configured_riley_link_address" /> android:text="@string/rileylink_address" />
<TextView <TextView
android:id="@+id/rls_t1_configured_riley_link_address" android:id="@+id/rls_t1_configured_riley_link_address"
@ -69,7 +69,7 @@
android:layout_marginLeft="30dp" android:layout_marginLeft="30dp"
android:layout_weight="35" android:layout_weight="35"
android:gravity="center_vertical" android:gravity="center_vertical"
android:text="@string/rileylink_configured_riley_link_name" /> android:text="@string/rileylink_name" />
<TextView <TextView
android:id="@+id/rls_t1_configured_riley_link_name" android:id="@+id/rls_t1_configured_riley_link_name"
@ -96,10 +96,10 @@
android:layout_marginLeft="30dp" android:layout_marginLeft="30dp"
android:layout_weight="35" android:layout_weight="35"
android:gravity="center_vertical" android:gravity="center_vertical"
android:text="@string/rileylink_connected_device" /> android:text="@string/rileylink_battery_level" />
<TextView <TextView
android:id="@+id/rls_t1_connected_device" android:id="@+id/rls_t1_battery_level"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"

View file

@ -30,9 +30,10 @@
<string name="medtronic_pump_status">Pump Status</string> <string name="medtronic_pump_status">Pump Status</string>
<string name="title_activity_rileylink_settings">RileyLink Settings</string> <string name="title_activity_rileylink_settings">RileyLink Settings</string>
<string name="rileylink_title">RileyLink</string> <string name="rileylink_title">RileyLink</string>
<string name="rileylink_configured_riley_link_address">Configured RileyLink Address:</string> <string name="rileylink_address">Address:</string>
<string name="rileylink_configured_riley_link_name">Configured RileyLink Name:</string> <string name="rileylink_name">Name:</string>
<string name="rileylink_connected_device">Connected Device:</string> <string name="rileylink_battery_level">Battery Level:</string>
<string name="rileylink_battery_level_value">%1$d%%</string>
<string name="rileylink_connection_status">Connection Status:</string> <string name="rileylink_connection_status">Connection Status:</string>
<string name="rileylink_connection_error">Connection Error:</string> <string name="rileylink_connection_error">Connection Error:</string>
<string name="rileylink_device">Device</string> <string name="rileylink_device">Device</string>
@ -41,8 +42,10 @@
<string name="rileylink_last_used_frequency">Last Used Frequency:</string> <string name="rileylink_last_used_frequency">Last Used Frequency:</string>
<string name="rileylink_last_device_contact">Last Device Contact:</string> <string name="rileylink_last_device_contact">Last Device Contact:</string>
<string name="rileylink_firmware_version">Firmware Version:</string> <string name="rileylink_firmware_version">Firmware Version:</string>
<string name="rileylink_firmware_version_value">BLE113: %1$s\nCC110: %2$s</string>
<string name="rileylink_pump_serial_number">Pump Serial Number:</string> <string name="rileylink_pump_serial_number">Pump Serial Number:</string>
<string name="rileylink_pump_frequency">Pump Frequency:</string> <string name="rileylink_pump_frequency">Pump Frequency:</string>
<string name="rileylink_pump_frequency_value">%1$.2f MHz</string>
<!-- RL State --> <!-- RL State -->
<string name="rileylink_state_bt_init">Bluetooth Initializing…</string> <string name="rileylink_state_bt_init">Bluetooth Initializing…</string>