- tbr start is succesful, but tbr is not displayed

This commit is contained in:
Andy Rozman 2018-07-22 16:45:26 +01:00
parent 47427ec68e
commit 0b180d3d65
25 changed files with 808 additions and 237 deletions

View file

@ -59,6 +59,7 @@ public class Notification {
public static final int ZERO_VALUE_IN_PROFILE = 31;
public static final int PROFILE_SWITCH_MISSING = 32;
public static final int NOT_ENG_MODE_OR_RELEASE = 33;
public static final int MEDTRONIC_PUMP_ALARM = 34;
public int id;
public Date date;
@ -68,6 +69,7 @@ public class Notification {
public NSAlarm nsAlarm = null;
public Integer soundId = null;
public Notification() {
}
@ -181,10 +183,10 @@ public class Notification {
return false;
}
public static boolean isAlarmForStaleData(){
public static boolean isAlarmForStaleData() {
long snoozedTo = SP.getLong("snoozedTo", 0L);
if(snoozedTo != 0L){
if(System.currentTimeMillis() < SP.getLong("snoozedTo", 0L)) {
if (snoozedTo != 0L) {
if (System.currentTimeMillis() < SP.getLong("snoozedTo", 0L)) {
//log.debug("Alarm is snoozed for next "+(SP.getLong("snoozedTo", 0L)-System.currentTimeMillis())/1000+" seconds");
return false;
}
@ -200,12 +202,12 @@ public class Notification {
//log.debug("bgReadingAgoMin value is:"+bgReadingAgoMin);
//log.debug("Stale alarm snoozed to: "+(System.currentTimeMillis() - snoozedTo)/60000L);
Double threshold = NSSettingsStatus.getInstance().getThreshold("alarmTimeagoWarnMins");
//log.debug("OpenAPS Alerts enabled: "+openAPSEnabledAlerts);
// if no thresshold from Ns get it loccally
if(threshold == null) threshold = SP.getDouble(R.string.key_nsalarm_staledatavalue,15D);
// No threshold of OpenAPS Alarm so using the one for BG
// Added OpenAPSEnabledAlerts to alarm check
if((bgReadingAgoMin > threshold && SP.getBoolean(R.string.key_nsalarm_staledata, false))||(bgReadingAgoMin > threshold && openAPSEnabledAlerts)){
//log.debug("OpenAPS Alerts enabled: "+openAPSEnabledAlerts);
// if no thresshold from Ns get it loccally
if (threshold == null) threshold = SP.getDouble(R.string.key_nsalarm_staledatavalue, 15D);
// No threshold of OpenAPS Alarm so using the one for BG
// Added OpenAPSEnabledAlerts to alarm check
if ((bgReadingAgoMin > threshold && SP.getBoolean(R.string.key_nsalarm_staledata, false)) || (bgReadingAgoMin > threshold && openAPSEnabledAlerts)) {
return true;
}
//snoozing for threshold

View file

@ -43,19 +43,20 @@ import info.nightscout.utils.DecimalFormatter;
// When using this class, make sure that your first step is to create mConnection (see MedtronicPumpPlugin)
// FIXME remove PumpDriver instances, just keep methods that do something here
public abstract class PumpPluginAbstract extends PluginBase implements PumpInterface, ConstraintsInterface {
private static final Logger LOG = LoggerFactory.getLogger(PumpPluginAbstract.class);
protected PumpDescription pumpDescription = new PumpDescription();
protected PumpStatus pumpStatusData;
//protected PumpStatus pumpStatusData;
protected PumpDriverInterface pumpDriver;
protected PumpStatus pumpStatus;
protected String internalName;
protected ServiceConnection serviceConnection = null;
protected boolean serviceRunning = false;
protected static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult()
@ -125,6 +126,8 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
Intent intent = new Intent(context, getServiceClass());
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
serviceRunning = true;
MainApp.bus().register(this);
onStartCustomActions();
super.onStart();
@ -136,6 +139,8 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
Context context = MainApp.instance().getApplicationContext();
context.unbindService(serviceConnection);
serviceRunning = false;
MainApp.bus().unregister(this);
}

View file

@ -86,19 +86,19 @@ public abstract class PumpStatus {
// FIXME cleanup this is from RT2
public long getTimeIndex() {
return (long) Math.ceil(time.getTime() / 60000d);
}
// public long getTimeIndex() {
// return (long) Math.ceil(time.getTime() / 60000d);
// }
//
// public void setTimeIndex(long timeIndex) {
// this.timeIndex = timeIndex;
// }
//
// public long timeIndex;
//
// public Date time;
public void setTimeIndex(long timeIndex) {
this.timeIndex = timeIndex;
}
public long timeIndex;
public Date time;
public double remainUnits = 0;
//public double remainUnits = 0;
public int remainBattery = 0;
public double currentBasal = 0;
@ -108,8 +108,8 @@ public abstract class PumpStatus {
public int tempBasalRemainMin = 0;
public Date tempBasalStart;
public Date last_bolus_time;
public double last_bolus_amount = 0;
//public Date last_bolus_time;
//public double last_bolus_amount = 0;
}

View file

@ -15,6 +15,8 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.Radio
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RLMessage;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RLMessageType;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkTargetFrequency;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.RileyLinkServiceData;
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.message.PumpMessage;
@ -69,6 +71,9 @@ public abstract class RileyLinkCommunicationManager {
}
private int timeoutCount = 0;
// All pump communications go through this function.
protected PumpMessage sendAndListen(RLMessage msg, int timeout_ms) {
@ -76,17 +81,29 @@ public abstract class RileyLinkCommunicationManager {
LOG.info("Sent:" + ByteUtil.shortHexString(msg.getTxData()));
}
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(msg.getTxData()), timeout_ms);
PumpMessage rval = new PumpMessage(resp.getRadioResponse().getPayload());
RFSpyResponse rfSpyResponse = rfspy.transmitThenReceive(new RadioPacket(msg.getTxData()), timeout_ms);
PumpMessage rval = new PumpMessage(rfSpyResponse.getRadioResponse().getPayload());
if (rval.isValid()) {
// Mark this as the last time we heard from the pump.
rememberLastGoodPumpCommunicationTime();
} else {
LOG.warn("Response is invalid. !!!");
LOG.warn("Response is invalid. !!! - ", rfSpyResponse.wasInterrupted(), rfSpyResponse.wasTimeout());
if (rfSpyResponse.wasTimeout()) {
timeoutCount++;
if (timeoutCount >= 5) {
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.NoContactWithDevice);
timeoutCount = 0;
tuneForPump();
//RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_quickTune);
}
}
}
if (showPumpMessages) {
LOG.info("Received:" + ByteUtil.shortHexString(resp.getRadioResponse().getPayload()));
LOG.info("Received:" + ByteUtil.shortHexString(rfSpyResponse.getRadioResponse().getPayload()));
}
return rval;
}
@ -132,6 +149,11 @@ public abstract class RileyLinkCommunicationManager {
long nextWakeUpRequired = 0L;
public int getNotConnectedCount() {
return rfspy != null ? rfspy.notConnectedCount : 0;
}
// FIXME change wakeup
// TODO we might need to fix this. Maybe make pump awake for shorter time (battery factor for pump) - Andy
public void wakeUp(int duration_minutes, boolean force) {
@ -219,7 +241,7 @@ public abstract class RileyLinkCommunicationManager {
for (int j = 0; j < tries; j++) {
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData);
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 0, (byte) 0, (byte) 0, 3000, (byte) 0);
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 0, (byte) 0, (byte) 0, 1500, (byte) 0);
if (resp.wasTimeout()) {
LOG.error("scanForPump: Failed to find pump at frequency {}", frequencies[i]);
} else if (resp.looksLikeRadioPacket()) {
@ -239,12 +261,23 @@ public abstract class RileyLinkCommunicationManager {
trial.averageRSSI = (double) (sumRSSI) / (double) (trial.tries);
results.trials.add(trial);
}
results.sort(); // sorts in ascending order
LOG.debug("Sorted scan results:");
StringBuilder stringBuilder = new StringBuilder("Scan results:\n");
for (int k = 0; k < results.trials.size(); k++) {
FrequencyTrial one = results.trials.get(k);
LOG.debug("Scan Result[{}]: Freq={}, avg RSSI = {}", k, one.frequencyMHz, one.averageRSSI);
stringBuilder.append(String.format("Scan Result[%s]: Freq=%s, avg RSSI = %s\n", "" + k, "" + one.frequencyMHz, "" + one.averageRSSI));
//LOG.debug("Scan Result[{}]: Freq={}, avg RSSI = {}", k, one.frequencyMHz, one.averageRSSI);
}
LOG.debug(stringBuilder.toString());
results.sort(); // sorts in ascending order
FrequencyTrial bestTrial = results.trials.get(results.trials.size() - 1);
results.bestFrequencyMHz = bestTrial.frequencyMHz;
if (bestTrial.successes > 0) {
@ -257,17 +290,6 @@ public abstract class RileyLinkCommunicationManager {
}
// public RLMessage makeRLMessage(RLMessageType type) {
// return makeRLMessage(type, null);
// }
//public abstract RLMessage makeRLMessage(RLMessageType type, byte[] data);
//public abstract RLMessage makeRLMessage(byte[] data);
public abstract byte[] createPumpMessageContent(RLMessageType type);
@ -351,7 +373,7 @@ public abstract class RileyLinkCommunicationManager {
private void rememberLastGoodPumpCommunicationTime() {
lastGoodReceiverCommunicationTime = System.currentTimeMillis();
SP.putLong(MedtronicConst.Prefs.LastGoodPumpCommunicationTime, lastGoodReceiverCommunicationTime);
SP.putLong(MedtronicConst.Statistics.LastGoodPumpCommunicationTime, lastGoodReceiverCommunicationTime);
MedtronicUtil.getPumpStatus().setLastCommunicationToNow();
}
@ -359,7 +381,7 @@ public abstract class RileyLinkCommunicationManager {
private long getLastGoodReceiverCommunicationTime() {
// If we have a value of zero, we need to load from prefs.
if (lastGoodReceiverCommunicationTime == 0L) {
lastGoodReceiverCommunicationTime = SP.getLong(MedtronicConst.Prefs.LastGoodPumpCommunicationTime, 0L);
lastGoodReceiverCommunicationTime = SP.getLong(MedtronicConst.Statistics.LastGoodPumpCommunicationTime, 0L);
// Might still be zero, but that's fine.
}
double minutesAgo = (System.currentTimeMillis() - lastGoodReceiverCommunicationTime) / (1000.0 * 60.0);
@ -373,4 +395,9 @@ public abstract class RileyLinkCommunicationManager {
}
public void clearNotConnectedCount() {
if (rfspy != null) {
rfspy.notConnectedCount = 0;
}
}
}

View file

@ -36,7 +36,7 @@ public class RFSpy {
private RileyLinkBLE rileyLinkBle;
private RFSpyReader reader;
private int previousRegion = 0;
//private int previousRegion = 0;
private RileyLinkTargetFrequency selectedTargetFrequency;
private UUID radioServiceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO);
@ -72,17 +72,7 @@ public class RFSpy {
}
// 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.
public String getVersion() {
BLECommOperationResult result = rileyLinkBle.readCharacteristic_blocking(radioServiceUUID, radioVersionUUID);
if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) {
return StringUtil.fromBytes(result.value);
} else {
LOG.error("getVersion failed with code: " + result.resultCode);
return "(null)";
}
}
public int notConnectedCount = 0;
// The caller has to know how long the RFSpy will be busy with what was sent to it.
@ -109,11 +99,13 @@ public class RFSpy {
RFSpyResponse resp = new RFSpyResponse(rawResponse);
if (rawResponse == null) {
LOG.error("writeToData: No response from RileyLink");
notConnectedCount++;
} else {
if (resp.wasInterrupted()) {
LOG.error("writeToData: RileyLink was interrupted");
} else if (resp.wasTimeout()) {
LOG.error("writeToData: RileyLink reports timeout");
notConnectedCount++;
} else if (resp.isOK()) {
LOG.warn("writeToData: RileyLink reports OK");
} else {
@ -149,6 +141,18 @@ public class RFSpy {
}
// 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.
public String getVersion() {
BLECommOperationResult result = rileyLinkBle.readCharacteristic_blocking(radioServiceUUID, radioVersionUUID);
if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) {
return StringUtil.fromBytes(result.value);
} else {
LOG.error("getVersion failed with code: " + result.resultCode);
return "(null)";
}
}
public RFSpyResponse getRadioVersion() {
RFSpyResponse resp = writeToData(getCommandArray(RFSpyCommand.GetVersion, null), EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
if (resp == null) {

View file

@ -35,7 +35,7 @@ import info.nightscout.androidaps.plugins.PumpCommon.utils.ThreadUtil;
/**
* Created by geoff on 5/26/16.
* Added: State handling, configuration of RF for different configuration ranges, connection handling
* Added: State handling, configuration of RF for different configuration ranges, connection handling - Andy
*/
public class RileyLinkBLE {

View file

@ -451,7 +451,7 @@ public abstract class RileyLinkService extends Service {
double lastGoodFrequency = 0.0d;
if (rileyLinkServiceData.lastGoodFrequency == null) {
lastGoodFrequency = SP.getDouble(MedtronicConst.Prefs.LastGoodPumpFrequency, 0.0d);
lastGoodFrequency = SP.getDouble(MedtronicConst.Statistics.LastGoodPumpFrequency, 0.0d);
} else {
lastGoodFrequency = rileyLinkServiceData.lastGoodFrequency;
}
@ -474,12 +474,14 @@ public abstract class RileyLinkService extends Service {
if ((newFrequency != 0.0) && (newFrequency != lastGoodFrequency)) {
LOG.info("Saving new pump frequency of {}MHz", newFrequency);
SP.putDouble(MedtronicConst.Prefs.LastGoodPumpFrequency, newFrequency);
SP.putDouble(MedtronicConst.Statistics.LastGoodPumpFrequency, newFrequency);
rileyLinkServiceData.lastGoodFrequency = newFrequency;
rileyLinkServiceData.tuneUpDone = true;
rileyLinkServiceData.lastTuneUpTime = System.currentTimeMillis();
}
getRileyLinkCommunicationManager().clearNotConnectedCount();
if (newFrequency == 0.0d) {
// error tuning pump, pump not present ??
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.TuneUpOfPumpFailed);

View file

@ -34,7 +34,7 @@ public class InitializePumpManagerTask extends ServiceTask {
public void run() {
// FIXME
double lastGoodFrequency = SP.getDouble(MedtronicConst.Prefs.LastGoodPumpFrequency, 0.0);
double lastGoodFrequency = SP.getDouble(MedtronicConst.Statistics.LastGoodPumpFrequency, 0.0);
if ((lastGoodFrequency > 0.0d) && RileyLinkUtil.getRileyLinkCommunicationManager().isValidFrequency(lastGoodFrequency)) {
@ -55,6 +55,7 @@ public class InitializePumpManagerTask extends ServiceTask {
//RileyLinkUtil.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_note_Idle), null);
} else {
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_tunePump);
}
}
}

View file

@ -35,10 +35,14 @@ import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.PumpCommon.dialog.RileylinkSettingsActivity;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog;
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity;
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicCommandType;
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.PumpMedtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.PumpMedtronic.events.EventMedtronicDeviceStatusChange;
import info.nightscout.androidaps.plugins.PumpMedtronic.events.EventMedtronicPumpValuesChanged;
@ -185,14 +189,14 @@ public class MedtronicFragment extends SubscriberFragment {
MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus();
if (eventStatusChange.rileyLinkServiceState != null)
pumpStatus.rileyLinkServiceState = eventStatusChange.rileyLinkServiceState;
if (eventStatusChange.rileyLinkError != null)
pumpStatus.rileyLinkError = eventStatusChange.rileyLinkError;
if (eventStatusChange.pumpDeviceState != null)
pumpStatus.pumpDeviceState = eventStatusChange.pumpDeviceState;
// if (eventStatusChange.rileyLinkServiceState != null)
// pumpStatus.rileyLinkServiceState = eventStatusChange.rileyLinkServiceState;
//
// if (eventStatusChange.rileyLinkError != null)
// pumpStatus.rileyLinkError = eventStatusChange.rileyLinkError;
//
// if (eventStatusChange.pumpDeviceState != null)
// pumpStatus.pumpDeviceState = eventStatusChange.pumpDeviceState;
setDeviceStatus(pumpStatus);
//pumpStatusIconView.setTextColor(Color.WHITE);
@ -207,6 +211,9 @@ public class MedtronicFragment extends SubscriberFragment {
private void setDeviceStatus(MedtronicPumpStatus pumpStatus) {
pumpStatus.rileyLinkServiceState = (RileyLinkServiceState) checkStatusSet(pumpStatus.rileyLinkServiceState, RileyLinkUtil.getServiceState());
if (pumpStatus.rileyLinkServiceState != null) {
int resourceId = pumpStatus.rileyLinkServiceState.getResourceId(getTargetDevice());
@ -214,7 +221,7 @@ public class MedtronicFragment extends SubscriberFragment {
rileyLinkStatus.setTextSize(14);
if (pumpStatus.rileyLinkServiceState == RileyLinkServiceState.NotStarted) {
rileyLinkStatus.setText(" " + getTranslation(resourceId));
rileyLinkStatus.setText(getTranslation(resourceId));
rileyLinkStatus.setTextSize(14);
} else if (pumpStatus.rileyLinkServiceState.isConnecting()) {
rileyLinkStatus.setText("{fa-bluetooth-b spin} " + getTranslation(resourceId));
@ -226,48 +233,64 @@ public class MedtronicFragment extends SubscriberFragment {
}
}
pumpStatus.rileyLinkError = (RileyLinkError) checkStatusSet(pumpStatus.rileyLinkError, RileyLinkUtil.getError());
if (pumpStatus.rileyLinkError != null) {
int resourceId = pumpStatus.rileyLinkError.getResourceId(getTargetDevice());
errorsView.setText(getTranslation(resourceId));
}
} else
errorsView.setText("-");
pumpStatus.pumpDeviceState = (PumpDeviceState) checkStatusSet(pumpStatus.pumpDeviceState, MedtronicUtil.getPumpDeviceState());
if (pumpStatus.pumpDeviceState != null) {
// TODO Pump State
switch (pumpStatus.pumpDeviceState) {
case Sleeping:
pumpStatusIconView.setText("{fa-bed} " + pumpStatus.pumpDeviceState.name());
pumpStatusIconView.setText("{fa-bed} "); // + pumpStatus.pumpDeviceState.name());
break;
case NeverContacted:
case WakingUp:
case ProblemContacting:
case InvalidConfiguration:
pumpStatusIconView.setText(" " + pumpStatus.pumpDeviceState.name());
break;
// FIXME
case Active:
pumpStatusIconView.setText(" " + pumpStatus.pumpDeviceState.name());
break;
// FIXME
case ErrorWhenCommunicating:
pumpStatusIconView.setText(" " + pumpStatus.pumpDeviceState.name());
case TimeoutWhenCommunicating:
case InvalidConfiguration:
pumpStatusIconView.setText(" " + getTranslation(pumpStatus.pumpDeviceState.getResourceId()));
break;
// FIXME
case TimeoutWhenCommunicating:
pumpStatusIconView.setText(" " + pumpStatus.pumpDeviceState.name());
break;
case Active: {
MedtronicCommandType cmd = MedtronicUtil.getCurrentCommand();
if (cmd == null)
pumpStatusIconView.setText(" " + pumpStatus.pumpDeviceState.name());
else
pumpStatusIconView.setText(" " + cmd.name());
}
break;
// // FIXME
//
// pumpStatusIconView.setText(" " + pumpStatus.pumpDeviceState.name());
// break;
//
// // FIXME
//
// pumpStatusIconView.setText(" " + pumpStatus.pumpDeviceState.name());
// break;
default:
LOG.warn("Unknown pump state: " + pumpStatus.pumpDeviceState);
}
} else {
pumpStatusIconView.setText("{fa-bed} ");
}
if (queueView != null) {
// FIXME
//queueView.setVisibility(View.GONE);
Spanned status = ConfigBuilderPlugin.getCommandQueue().spannedStatus();
if (status.toString().equals("")) {
queueView.setVisibility(View.GONE);
@ -281,6 +304,18 @@ public class MedtronicFragment extends SubscriberFragment {
}
public Object checkStatusSet(Object object1, Object object2) {
if (object1 == null) {
return object1;
} else {
if (!object1.equals(object2)) {
return object2;
} else
return object1;
}
}
public RileyLinkTargetDevice getTargetDevice() {
return RileyLinkTargetDevice.MedtronicPump;
}
@ -326,14 +361,20 @@ public class MedtronicFragment extends SubscriberFragment {
setDeviceStatus(pumpStatus);
if (pumpStatus.lastConnection != 0) {
Long agoMsec = System.currentTimeMillis() - pumpStatus.lastConnection;
int agoMin = (int) (agoMsec / 60d / 1000d);
lastConnectionView.setText(DateUtil.timeString(pumpStatus.lastConnection) + " (" + String.format(MainApp.sResources.getString(R.string.minago), agoMin) + ")");
SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d);
// last connection
String minAgo = DateUtil.minAgo(pumpStatus.lastConnection);
long min = (System.currentTimeMillis() - pumpStatus.lastConnection) / 1000 / 60;
if (pumpStatus.lastConnection + 60 * 1000 > System.currentTimeMillis()) {
lastConnectionView.setText(R.string.combo_pump_connected_now);
lastConnectionView.setTextColor(Color.WHITE);
} else if (pumpStatus.lastConnection + 30 * 60 * 1000 < System.currentTimeMillis()) {
lastConnectionView.setText(MainApp.gs(R.string.combo_no_pump_connection, min));
lastConnectionView.setTextColor(Color.RED);
} else {
lastConnectionView.setText(minAgo);
lastConnectionView.setTextColor(Color.WHITE);
}
// last bolus
Double bolus = pumpStatus.lastBolusAmount;
Date bolusTime = pumpStatus.lastBolusTime;
@ -354,10 +395,12 @@ public class MedtronicFragment extends SubscriberFragment {
lastBolusView.setText("");
}
//dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
//SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
basaBasalRateView.setText("(" + (pumpStatus.activeProfileName) + ") " + DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) + " U/h");
// base basal rate
basaBasalRateView.setText("(" + (pumpStatus.activeProfileName) + ") " + MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate()));
// FIXME temp basal - check - maybe set as combo ??
if (ConfigBuilderPlugin.getActivePump().isFakingTempsByExtendedBoluses()) {
if (TreatmentsPlugin.getPlugin().isInHistoryRealTempBasalInProgress()) {
tempBasalView.setText(TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
@ -373,12 +416,13 @@ public class MedtronicFragment extends SubscriberFragment {
}
}
reservoirView.setText(DecimalFormatter.to0Decimal(pumpStatus.reservoirRemainingUnits) + " / " + pumpStatus.reservoirFullUnits + " U");
SetWarnColor.setColorInverse(reservoirView, pumpStatus.reservoirRemainingUnits, 50d, 20d);
// battery
batteryView.setText("{fa-battery-" + (pumpStatus.batteryRemaining / 25) + "}");
SetWarnColor.setColorInverse(batteryView, pumpStatus.batteryRemaining, 51d, 26d);
//iobView.setText(pump.iob + " U");
// reservoir
reservoirView.setText(DecimalFormatter.to0Decimal(pumpStatus.reservoirRemainingUnits) + " / " + pumpStatus.reservoirFullUnits + " " + MainApp.gs(R.string.insulin_unit_shortname));
SetWarnColor.setColorInverse(reservoirView, pumpStatus.reservoirRemainingUnits, 50d, 20d);
errorsView.setText(pumpStatus.getErrorInfo());

View file

@ -10,21 +10,27 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.PumpCommon.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.ui.MedtronicUIComm;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.ui.MedtronicUITask;
import info.nightscout.androidaps.plugins.PumpMedtronic.data.dto.TempBasalPair;
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicCommandType;
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicStatusRefreshType;
import info.nightscout.androidaps.plugins.PumpMedtronic.driver.MedtronicPumpDriver;
import info.nightscout.androidaps.plugins.PumpMedtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.PumpMedtronic.events.EventMedtronicPumpValuesChanged;
@ -138,7 +144,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
// needs to be changed in configuration, after all functionalities are done
pumpDescription.isBolusCapable = true;
pumpDescription.isTempBasalCapable = false; // WIP
pumpDescription.isTempBasalCapable = true; // WIP
pumpDescription.isExtendedBolusCapable = false;
pumpDescription.isSetBasalProfileCapable = false;
@ -157,17 +163,32 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
//pumpStatusLocal.setNotInPreInit();
// set first Medtronic Pump Start
if (!SP.contains(MedtronicConst.Prefs.FirstPumpStart)) {
SP.putLong(MedtronicConst.Prefs.FirstPumpStart, System.currentTimeMillis());
if (!SP.contains(MedtronicConst.Statistics.FirstPumpStart)) {
SP.putLong(MedtronicConst.Statistics.FirstPumpStart, System.currentTimeMillis());
}
}
public void onStartCustomActions() {
// check status every minute
new Thread(() -> {
do {
SystemClock.sleep(60000);
if (doWeHaveAnyStatusNeededRefereshing()) {
ConfigBuilderPlugin.getCommandQueue().readStatus("Manual Status Request", null);
}
} while (serviceRunning);
}).start();
//pumpStatusLocal.setNotInPreInit();
}
public Class getServiceClass() {
return RileyLinkMedtronicService.class;
}
@ -250,48 +271,148 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
if (this.pumpStatusLocal == null) {
// FIXME I don't know why this happens
LOG.debug("getPumpStatus: reset pumoStatusLocal ");
LOG.debug("getPumpStatus: reset pumpStatusLocal ");
this.pumpStatusLocal = MedtronicUtil.getPumpStatus();
}
if (firstRun) {
initializePump();
initializePump(true);
} else {
refreshAnyStatusThatNeedsToBeRefreshed();
}
LOG.error("MedtronicPumpPlugin::getPumpStatus NOT IMPLEMENTED.");
LOG.debug("getPumpStatus: {}", this.pumpStatusLocal);
LOG.debug("getPumpStatus: {}", MedtronicUtil.getPumpStatus());
//LOG.debug("getPumpStatus: {}", this.pumpStatusLocal);
//LOG.debug("getPumpStatus: {}", MedtronicUtil.getPumpStatus());
pumpStatusLocal.setLastCommunicationToNow();
//getMDTPumpStatus().setLastCommunicationToNow();
MainApp.bus().post(new EventMedtronicPumpValuesChanged());
}
private void initializePump() {
LOG.error("MedtronicPumpPlugin::initializePump NOT IMPLEMENTED.");
private void refreshAnyStatusThatNeedsToBeRefreshed() {
if (!doWeHaveAnyStatusNeededRefereshing()) {
return;
}
// TODO
boolean resetTime = false;
for (Map.Entry<MedtronicStatusRefreshType, Long> refreshType : statusRefreshMap.entrySet()) {
if (refreshType.getValue() > 0 && System.currentTimeMillis() > refreshType.getValue()) {
switch (refreshType.getKey()) {
case PumpHistory: {
readPumpHistory();
}
break;
case PumpTime:
case BatteryStatus:
case RemainingInsulin:
case Configuration: {
medtronicUIComm.executeCommand(refreshType.getKey().getCommandType());
scheduleNextRefresh(refreshType.getKey());
resetTime = true;
}
break;
}
}
}
if (resetTime)
pumpStatusLocal.setLastCommunicationToNow();
//LOG.error("MedtronicPumpPlugin::refreshAnyStatusThatNeedsToBeRefreshed NOT IMPLEMENTED.");
}
Map<MedtronicStatusRefreshType, Long> statusRefreshMap = new HashMap<>();
private boolean doWeHaveAnyStatusNeededRefereshing() {
for (Map.Entry<MedtronicStatusRefreshType, Long> refreshType : statusRefreshMap.entrySet()) {
if (refreshType.getValue() > 0 && System.currentTimeMillis() > refreshType.getValue()) {
return true;
}
}
return false;
}
private void initializePump(boolean realInit) {
LOG.error("MedtronicPumpPlugin::initializePump NOT fully IMPLEMENTED.");
getMDTPumpStatus();
// model (once)
if (MedtronicUtil.getMedtronicPumpModel() == null) {
medtronicUIComm.executeCommand(MedtronicCommandType.PumpModel);
} else {
if (pumpStatusLocal.medtronicDeviceType != MedtronicUtil.getMedtronicPumpModel()) {
// TODO error
}
}
// pump history handling - special, updates every 5 minutes ???
readPumpHistory();
//scheduleNextRefresh(MedtronicStatusRefreshType.PumpHistory);
// TODO rewrite reading of data to be done in background or different thread perhaps ??
// remaining insulin (>50 = 4h; 50-20 = 1h; 15m)
medtronicUIComm.executeCommand(MedtronicCommandType.GetRemainingInsulin);
scheduleNextRefresh(MedtronicStatusRefreshType.RemainingInsulin, 10);
// remaining power (1h)
// TODO remaining power (1h)
medtronicUIComm.executeCommand(MedtronicCommandType.GetBatteryStatus);
scheduleNextRefresh(MedtronicStatusRefreshType.BatteryStatus, 20);
// configuration (1h -> maybe just if something configured (something we are interested in))
// configuration (once and then if history shows config changes)
medtronicUIComm.executeCommand(MedtronicCommandType.getSettings(MedtronicUtil.getMedtronicPumpModel()));
// read profile
// TODO time (1h)
medtronicUIComm.executeCommand(MedtronicCommandType.RealTimeClock);
scheduleNextRefresh(MedtronicStatusRefreshType.PumpTime, 30);
// read profile (once, later its controlled by isThisProfileSet method)
medtronicUIComm.executeCommand(MedtronicCommandType.GetBasalProfileSTD);
//if ()
// TODO handle if tunning was needed (more than 5 timeouts)
int errorCount = medtronicUIComm.getInvalidResponsesCount();
if (errorCount >= 5) {
LOG.error("Number of error counts was 5 or more. Starting tunning.");
medtronicUIComm.startTunning();
return;
}
pumpStatusLocal.setLastCommunicationToNow();
this.firstRun = false;
}
@Override
public boolean isThisProfileSet(Profile profile) {
//LOG.error("MedtronicPumpPlugin::isThisProfileSet NOT IMPLEMENTED.");
// FIXME refactor this, reread profile only if history says that profile has changed... This will
// delay change of profile.
if (!isConnected()) {
return true;
@ -311,9 +432,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
int hour = basalValue.timeAsSeconds / (60 * 60);
//LOG.debug("Basal profile::Pump rate={}, NS rate={}", basalsByHour[index], basalValue.value);
//LOG.debug("Basal profile::Pump time={}, NS time={}", index, basalValue.timeAsSeconds / (60 * 60));
if (MedtronicUtil.isSame(basalsByHour[index], basalValue.value)) {
if (index != hour) {
invalid = true;
@ -331,7 +449,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
if (!invalid) {
LOG.debug("Basal profile is same as AAPS one.");
} else {
LOG.debug("Basal profile on Pump is differentr than AAPS one.");
LOG.debug("Basal profile on Pump is different than the AAPS one.");
}
} else {
@ -383,8 +501,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
Boolean response = (Boolean) responseTask.returnData;
if (response) {
}
// TODO display bolus
// TODO change remaining insulin
readPumpHistory();
@ -500,7 +618,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
} finally {
// pump.activity = null;
// MainApp.bus().post(new EventComboPumpUpdateGUI());
// MainApp.bus().post(new EventRefreshOverview("Bolus"));
MainApp.bus().post(new EventRefreshOverview("Bolus"));
// cancelBolus = false;
triggerUIChange();
}
@ -510,18 +628,68 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
public void stopBolusDelivering() {
}
// if enforceNew===true current temp basal is canceled and new TBR set (duration is prolonged),
// if false and the same rate is requested enacted=false and success=true is returned and TBR is not changed
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
LOG.error("MedtronicPumpPlugin::setTempBasalAbsolute Not fully implemented - Just base command.");
getMDTPumpStatus();
LOG.info("MedtronicPumpPlugin::setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes);
// read current TBR
TempBasalPair tbrCurrent = readTBR();
if (tbrCurrent == null) {
LOG.warn("MedtronicPumpPlugin::setTempBasalAbsolute - Could not read current TBR, canceling operation.");
// TODO translate
return new PumpEnactResult().success(false).enacted(false).comment("Couldn't read current TBR.");
} else {
LOG.info("MedtronicPumpPlugin::setTempBasalAbsolute: Current Basal: " + tbrCurrent.getDurationMinutes() + tbrCurrent.getInsulinRate());
}
// FIXME doesn't work correctly. Read current TBR first
if (!enforceNew) {
if (MedtronicUtil.isSame(tbrCurrent.getInsulinRate(), absoluteRate)) {
LOG.info("MedtronicPumpPlugin::setTempBasalAbsolute - No enforceNew and same rate. Exiting.");
return new PumpEnactResult().success(true).enacted(false);
}
// if not the same rate, we cancel and start new
}
// if TBR is running we will cancel it.
if (tbrCurrent.getInsulinRate() != 0.0f && tbrCurrent.getDurationMinutes() > 0) {
LOG.info("MedtronicPumpPlugin::setTempBasalAbsolute - TBR running - so canceling it.");
// CANCEL
MedtronicUITask responseTask2 = medtronicUIComm.executeCommand(MedtronicCommandType.CancelTBR);
Boolean response = (Boolean) responseTask2.returnData;
if (response) {
LOG.info("MedtronicPumpPlugin::setTempBasalAbsolute - Current TBR cancelled.");
} else {
LOG.error("MedtronicPumpPlugin::setTempBasalAbsolute - Cancel TBR failed.");
return new PumpEnactResult().success(false).enacted(false).comment("Couldn't cancel current TBR. Stopping operation. ");
}
}
// now start new TBR
MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.SetTemporaryBasal, absoluteRate, durationInMinutes);
Boolean response = (Boolean) responseTask.returnData;
if (response) {
//pumpStatusLocal.tempBasalStart = new Date(); // TODO maybe not needed
//pumpStatusLocal.tempBasalRemainMin = durationInMinutes;
// FIXME put this into UIPostProcessor
pumpStatusLocal.tempBasalStart = new Date();
pumpStatusLocal.tempBasalAmount = absoluteRate;
pumpStatusLocal.tempBasalLength = durationInMinutes;
}
readPumpHistory();
@ -531,6 +699,58 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
private void readPumpHistory() {
LOG.error("MedtronicPumpPlugin::readPumpHistory NOT IMPLEMENTED.");
// TODO implement logic here
boolean relevantConfigurationChangeFound = false;
// TODO reset next refresh date, also set refreshdate if configuration changed
scheduleNextRefresh(MedtronicStatusRefreshType.PumpHistory);
if (relevantConfigurationChangeFound) {
scheduleNextRefresh(MedtronicStatusRefreshType.Configuration, -1);
}
// FIXME set last read
}
private void scheduleNextRefresh(MedtronicStatusRefreshType refreshType) {
scheduleNextRefresh(refreshType, 0);
}
private void scheduleNextRefresh(MedtronicStatusRefreshType refreshType, int additionalTimeInMinutes) {
switch (refreshType) {
case RemainingInsulin: {
Double remaining = pumpStatusLocal.reservoirRemainingUnits;
int min = 0;
if (remaining > 50)
min = 4 * 60;
else if (remaining > 20)
min = 60;
else
min = 15;
statusRefreshMap.put(refreshType, getTimeInFutureFromMinutes(min));
}
break;
case Configuration:
case PumpHistory: {
statusRefreshMap.put(refreshType, getTimeInFutureFromMinutes(refreshType.getRefreshTime() + additionalTimeInMinutes));
}
break;
}
}
private long getTimeInFutureFromMinutes(int minutes) {
return System.currentTimeMillis() + getTimeInMs(minutes);
}
private long getTimeInMs(int minutes) {
return minutes * 60 * 1000L;
}
@ -543,17 +763,47 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
//return OPERATION_NOT_YET_SUPPORTED;
}
private TempBasalPair readTBR() {
MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.ReadTemporaryBasal);
if (responseTask.hasData()) {
TempBasalPair tbr = (TempBasalPair) responseTask.returnData;
return tbr;
} else {
return null;
}
}
// TODO
@Override
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
LOG.error("MedtronicPumpPlugin::cancelTempBasal Not fully implemented - Just base command.");
MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.CancelTBR);
Boolean response = (Boolean) responseTask.returnData;
TempBasalPair tbrCurrent = readTBR();
if (tbrCurrent != null) {
if (tbrCurrent.getInsulinRate() == 0.0f && tbrCurrent.getDurationMinutes() == 0) {
LOG.info("MedtronicPumpPlugin::cancelTempBasal - TBR already canceled.");
return new PumpEnactResult().success(true).enacted(false);
}
} else {
LOG.warn("MedtronicPumpPlugin::cancelTempBasal - Could not read currect TBR, canceling operation.");
return new PumpEnactResult().success(false).enacted(false).comment("Couldn't read current TBR. ");
}
MedtronicUITask responseTask2 = medtronicUIComm.executeCommand(MedtronicCommandType.CancelTBR);
Boolean response = (Boolean) responseTask2.returnData;
if (response) {
LOG.info("MedtronicPumpPlugin::cancelTempBasal - Cancel TBR successful.");
} else {
LOG.info("MedtronicPumpPlugin::cancelTempBasal - Cancel TBR failed.");
}
readPumpHistory();
@ -576,16 +826,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
@Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
LOG.error("MedtronicPumpPlugin::setTempBasalPercent NOT IMPLEMENTED.");
return null;
}
@Override
public PumpEnactResult setNewBasalProfile(Profile profile) {
LOG.error("MedtronicPumpPlugin::setNewBasalProfile NOT IMPLEMENTED.");
LOG.debug("isSetBasalProfileCapable:" + this.pumpDescription.isSetBasalProfileCapable);
LOG.warn("MedtronicPumpPlugin::setNewBasalProfile NOT IMPLEMENTED.");
return new PumpEnactResult().success(false).enacted(false).comment(MainApp.gs(R.string.medtronic_cmd_profile_not_set));
}

View file

@ -9,7 +9,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkCommunicationManager;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RFSpy;
@ -599,11 +599,11 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
}
public List<PumpSettingDTO> getPumpSettings() {
public Map<String, PumpSettingDTO> getPumpSettings() {
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.getSettings(MedtronicUtil.getMedtronicPumpModel()));
return responseObject == null ? null : (List<PumpSettingDTO>) responseObject;
return responseObject == null ? null : (Map<String, PumpSettingDTO>) responseObject;
}
@ -794,7 +794,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
//Integer resp = getRemainingBattery();
//pumpStatus.batteryRemaining = resp == null ? -1 : resp;
pumpStatus.remainUnits = getRemainingInsulin();
//pumpStatus.remainUnits = getRemainingInsulin();
/* current basal */
//TempBasalPair basalRate = getCurrentBasalRate();
@ -821,7 +821,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// get pump time
LocalDateTime clockResult = getPumpTime();
if (clockResult != null) {
pumpStatus.time = clockResult.toDate();
//pumpStatus.time = clockResult.toDate();
}
// get last sync time

View file

@ -7,8 +7,8 @@ import org.joda.time.LocalTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
import info.nightscout.androidaps.plugins.PumpCommon.utils.HexDump;
@ -199,32 +199,33 @@ public class MedtronicConverter {
}
public List<PumpSettingDTO> decodeSettings512(byte[] rd) {
public Map<String, PumpSettingDTO> decodeSettings512(byte[] rd) {
List<PumpSettingDTO> outList = new ArrayList<>();
Map<String, PumpSettingDTO> map = new HashMap<>();
//List<PumpSettingDTO> outList = new ArrayList<>();
outList.add(new PumpSettingDTO("PCFG_AUTOOFF_TIMEOUT", "" + rd[0], PumpConfigurationGroup.General));
addSettingToMap("PCFG_AUTOOFF_TIMEOUT", "" + rd[0], PumpConfigurationGroup.General, map);
if (rd[1] == 4) {
outList.add(new PumpSettingDTO("PCFG_ALARM_MODE", "Silent", PumpConfigurationGroup.Sound));
addSettingToMap("PCFG_ALARM_MODE", "Silent", PumpConfigurationGroup.Sound, map);
} else {
outList.add(new PumpSettingDTO("PCFG_ALARM_MODE", "Normal", PumpConfigurationGroup.Sound));
outList.add(new PumpSettingDTO("PCFG_ALARM_BEEP_VOLUME", "" + rd[1], PumpConfigurationGroup.Sound));
addSettingToMap("PCFG_ALARM_MODE", "Normal", PumpConfigurationGroup.Sound, map);
addSettingToMap("PCFG_ALARM_BEEP_VOLUME", "" + rd[1], PumpConfigurationGroup.Sound, map);
}
outList.add(new PumpSettingDTO("PCFG_AUDIO_BOLUS_ENABLED", parseResultEnable(rd[2]), PumpConfigurationGroup.Bolus));
addSettingToMap("PCFG_AUDIO_BOLUS_ENABLED", parseResultEnable(rd[2]), PumpConfigurationGroup.Bolus, map);
if (rd[2] == 1) {
outList.add(new PumpSettingDTO("PCFG_AUDIO_BOLUS_STEP_SIZE", "" + decodeBolusInsulin(ByteUtil.asUINT8(rd[3])), PumpConfigurationGroup.Bolus));
addSettingToMap("PCFG_AUDIO_BOLUS_STEP_SIZE", "" + decodeBolusInsulin(ByteUtil.asUINT8(rd[3])), PumpConfigurationGroup.Bolus, map);
}
outList.add(new PumpSettingDTO("PCFG_VARIABLE_BOLUS_ENABLED", parseResultEnable(rd[4]), PumpConfigurationGroup.Bolus));
outList.add(new PumpSettingDTO("PCFG_MAX_BOLUS", "" + decodeMaxBolus(rd), PumpConfigurationGroup.Bolus));
outList.add(new PumpSettingDTO("PCFG_MAX_BASAL", "" + decodeBasalInsulin(ByteUtil.makeUnsignedShort(rd[getSettingIndexMaxBasal()], rd[getSettingIndexMaxBasal() + 1])), PumpConfigurationGroup.Basal));
outList.add(new PumpSettingDTO("CFG_BASE_CLOCK_MODE", rd[getSettingIndexTimeDisplayFormat()] == 0 ? "12h" : "24h", PumpConfigurationGroup.General));
outList.add(new PumpSettingDTO("PCFG_INSULIN_CONCENTRATION", "" + (rd[9] != 0 ? 50 : 100), PumpConfigurationGroup.Insulin));
outList.add(new PumpSettingDTO("PCFG_BASAL_PROFILES_ENABLED", parseResultEnable(rd[10]), PumpConfigurationGroup.Basal));
addSettingToMap("PCFG_VARIABLE_BOLUS_ENABLED", parseResultEnable(rd[4]), PumpConfigurationGroup.Bolus, map);
addSettingToMap("PCFG_MAX_BOLUS", "" + decodeMaxBolus(rd), PumpConfigurationGroup.Bolus, map);
addSettingToMap("PCFG_MAX_BASAL", "" + decodeBasalInsulin(ByteUtil.makeUnsignedShort(rd[getSettingIndexMaxBasal()], rd[getSettingIndexMaxBasal() + 1])), PumpConfigurationGroup.Basal, map);
addSettingToMap("CFG_BASE_CLOCK_MODE", rd[getSettingIndexTimeDisplayFormat()] == 0 ? "12h" : "24h", PumpConfigurationGroup.General, map);
addSettingToMap("PCFG_INSULIN_CONCENTRATION", "" + (rd[9] != 0 ? 50 : 100), PumpConfigurationGroup.Insulin, map);
addSettingToMap("PCFG_BASAL_PROFILES_ENABLED", parseResultEnable(rd[10]), PumpConfigurationGroup.Basal, map);
if (rd[10] == 1) {
String patt;
@ -246,46 +247,51 @@ public class MedtronicConverter {
break;
}
outList.add(new PumpSettingDTO("PCFG_ACTIVE_BASAL_PROFILE", patt, PumpConfigurationGroup.Basal));
addSettingToMap("PCFG_ACTIVE_BASAL_PROFILE", patt, PumpConfigurationGroup.Basal, map);
}
outList.add(new PumpSettingDTO("CFG_MM_RF_ENABLED", parseResultEnable(rd[12]), PumpConfigurationGroup.General));
outList.add(new PumpSettingDTO("CFG_MM_BLOCK_ENABLED", parseResultEnable(rd[13]), PumpConfigurationGroup.General));
addSettingToMap("CFG_MM_RF_ENABLED", parseResultEnable(rd[12]), PumpConfigurationGroup.General, map);
addSettingToMap("CFG_MM_BLOCK_ENABLED", parseResultEnable(rd[13]), PumpConfigurationGroup.General, map);
outList.add(new PumpSettingDTO("PCFG_TEMP_BASAL_TYPE", rd[14] != 0 ? "Percent" : "Units", PumpConfigurationGroup.Basal));
addSettingToMap("PCFG_TEMP_BASAL_TYPE", rd[14] != 0 ? "Percent" : "Units", PumpConfigurationGroup.Basal, map);
if (rd[14] == 1) {
outList.add(new PumpSettingDTO("PCFG_TEMP_BASAL_PERCENT", "" + rd[15], PumpConfigurationGroup.Basal));
addSettingToMap("PCFG_TEMP_BASAL_PERCENT", "" + rd[15], PumpConfigurationGroup.Basal, map);
}
outList.add(new PumpSettingDTO("CFG_PARADIGM_LINK_ENABLE", parseResultEnable(rd[16]), PumpConfigurationGroup.General));
addSettingToMap("CFG_PARADIGM_LINK_ENABLE", parseResultEnable(rd[16]), PumpConfigurationGroup.General, map);
decodeInsulinActionSetting(rd, outList);
decodeInsulinActionSetting(rd, map);
return outList;
return map;
}
public List<PumpSettingDTO> decodeSettings(byte[] rd) {
List<PumpSettingDTO> outList = decodeSettings512(rd);
public void addSettingToMap(String key, String value, PumpConfigurationGroup group, Map<String, PumpSettingDTO> map) {
map.put(key, new PumpSettingDTO(key, value, group));
}
outList.add(new PumpSettingDTO("PCFG_MM_RESERVOIR_WARNING_TYPE_TIME", rd[18] != 0 ? "PCFG_MM_RESERVOIR_WARNING_TYPE_TIME" : "PCFG_MM_RESERVOIR_WARNING_TYPE_UNITS", PumpConfigurationGroup.Other));
outList.add(new PumpSettingDTO("PCFG_MM_SRESERVOIR_WARNING_POINT", "" + ByteUtil.asUINT8(rd[19]), PumpConfigurationGroup.Other));
public Map<String, PumpSettingDTO> decodeSettings(byte[] rd) {
Map<String, PumpSettingDTO> map = decodeSettings512(rd);
outList.add(new PumpSettingDTO("CFG_MM_KEYPAD_LOCKED", parseResultEnable(rd[20]), PumpConfigurationGroup.Other));
addSettingToMap("PCFG_MM_RESERVOIR_WARNING_TYPE_TIME", rd[18] != 0 ? "PCFG_MM_RESERVOIR_WARNING_TYPE_TIME" : "PCFG_MM_RESERVOIR_WARNING_TYPE_UNITS", PumpConfigurationGroup.Other, map);
addSettingToMap("PCFG_MM_SRESERVOIR_WARNING_POINT", "" + ByteUtil.asUINT8(rd[19]), PumpConfigurationGroup.Other, map);
addSettingToMap("CFG_MM_KEYPAD_LOCKED", parseResultEnable(rd[20]), PumpConfigurationGroup.Other, map);
if (MedtronicDeviceType.isSameDevice(pumpModel, MedtronicDeviceType.Medtronic_523andHigher)) {
outList.add(new PumpSettingDTO("PCFG_BOLUS_SCROLL_STEP_SIZE", "" + rd[21], PumpConfigurationGroup.Bolus));
outList.add(new PumpSettingDTO("PCFG_CAPTURE_EVENT_ENABLE", parseResultEnable(rd[22]), PumpConfigurationGroup.Other));
outList.add(new PumpSettingDTO("PCFG_OTHER_DEVICE_ENABLE", parseResultEnable(rd[23]), PumpConfigurationGroup.Other));
outList.add(new PumpSettingDTO("PCFG_OTHER_DEVICE_PAIRED_STATE", parseResultEnable(rd[24]), PumpConfigurationGroup.Other));
addSettingToMap("PCFG_BOLUS_SCROLL_STEP_SIZE", "" + rd[21], PumpConfigurationGroup.Bolus, map);
addSettingToMap("PCFG_CAPTURE_EVENT_ENABLE", parseResultEnable(rd[22]), PumpConfigurationGroup.Other, map);
addSettingToMap("PCFG_OTHER_DEVICE_ENABLE", parseResultEnable(rd[23]), PumpConfigurationGroup.Other, map);
addSettingToMap("PCFG_OTHER_DEVICE_PAIRED_STATE", parseResultEnable(rd[24]), PumpConfigurationGroup.Other, map);
}
return outList;
return map;
}
@ -307,9 +313,9 @@ public class MedtronicConverter {
// 512
public void decodeInsulinActionSetting(byte ai[], List<PumpSettingDTO> outList) {
public void decodeInsulinActionSetting(byte[] ai, Map<String, PumpSettingDTO> map) {
if (MedtronicDeviceType.isSameDevice(pumpModel, MedtronicDeviceType.Medtronic_512_712)) {
outList.add(new PumpSettingDTO("PCFG_INSULIN_ACTION_TYPE", (ai[17] != 0 ? "Regular" : "Fast"), PumpConfigurationGroup.Insulin));
addSettingToMap("PCFG_INSULIN_ACTION_TYPE", (ai[17] != 0 ? "Regular" : "Fast"), PumpConfigurationGroup.Insulin, map);
} else {
int i = ai[17];
String s = "";
@ -323,7 +329,7 @@ public class MedtronicConverter {
s = "Curve: " + i;
}
outList.add(new PumpSettingDTO("PCFG_INSULIN_ACTION_TYPE", s, PumpConfigurationGroup.Insulin));
addSettingToMap("PCFG_INSULIN_ACTION_TYPE", s, PumpConfigurationGroup.Insulin, map);
}
}

View file

@ -3,6 +3,8 @@ package info.nightscout.androidaps.plugins.PumpMedtronic.comm.ui;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.MedtronicCommunicationManager;
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicCommandType;
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
@ -90,4 +92,11 @@ public class MedtronicUIComm {
}
public int getInvalidResponsesCount() {
return getCommunicationManager().getNotConnectedCount();
}
public void startTunning() {
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_tunePump);
}
}

View file

@ -1,11 +1,19 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.ui;
import org.joda.time.LocalDateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.Map;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpMedtronic.data.dto.BasalProfile;
import info.nightscout.androidaps.plugins.PumpMedtronic.data.dto.BatteryStatusDTO;
import info.nightscout.androidaps.plugins.PumpMedtronic.data.dto.PumpSettingDTO;
import info.nightscout.androidaps.plugins.PumpMedtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
@ -48,10 +56,48 @@ public class MedtronicUIPostprocessor {
}
break;
case CancelTBR: {
pumpStatus.tempBasalStart = null;
pumpStatus.tempBasalAmount = null;
pumpStatus.tempBasalLength = null;
}
break;
case RealTimeClock: {
processTime(uiTask);
}
break;
case GetBatteryStatus: {
BatteryStatusDTO batteryStatusDTO = (BatteryStatusDTO) uiTask.returnData;
if (batteryStatusDTO.batteryStatusType == BatteryStatusDTO.BatteryStatusType.Low)
pumpStatus.batteryRemaining = 18;
else
pumpStatus.batteryRemaining = 70;
}
break;
case PumpModel: {
if (pumpStatus.medtronicDeviceType != MedtronicUtil.getMedtronicPumpModel()) {
// TODO error
LOG.error("Configured pump is different then pump detected !!");
}
}
break;
case Settings_512:
case Settings: {
postProcessSettings(uiTask);
}
break;
// no postprocessing
case PumpModel:
break;
default:
LOG.warn("Post-processing not implemented for {}.", uiTask.commandType.name());
@ -61,5 +107,90 @@ public class MedtronicUIPostprocessor {
}
private void processTime(MedtronicUITask uiTask) {
LocalDateTime ldt = (LocalDateTime) uiTask.returnData;
Date d1 = ldt.toDate();
long currentTimeMillis = System.currentTimeMillis();
long diff = Math.abs(d1.getTime() - currentTimeMillis);
LOG.warn("Pump Time: " + ldt + ", DeviceTime=" + d1 + //
//", epoch: " + d1.getTime() + ", current: " + currentTimeMillis + //
", diff: " + diff / 1000 + " s");
if (diff >= 10 * 60 * 1000) {
LOG.debug("Pump clock needs update, pump time: " + ldt + " (" + ldt + ")");
Notification notification = new Notification(Notification.MEDTRONIC_PUMP_ALARM, MainApp.gs(R.string.combo_notification_check_time_date), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
} else if (diff >= 4 * 60 * 1000) {
LOG.debug("Pump clock needs update, pump time: " + ldt + " (" + ldt + ")");
Notification notification = new Notification(Notification.MEDTRONIC_PUMP_ALARM, MainApp.gs(R.string.combo_notification_check_time_date), Notification.NORMAL);
MainApp.bus().post(new EventNewNotification(notification));
}
}
private void postProcessSettings(MedtronicUITask uiTask) {
Map<String, PumpSettingDTO> settings = (Map<String, PumpSettingDTO>) uiTask.returnData;
MedtronicUtil.setSettings(settings);
PumpSettingDTO checkValue = null;
// check profile
if (!"Yes".equals(settings.get("PCFG_BASAL_PROFILES_ENABLED").value)) {
//Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
//MainApp.bus().post(new EventNewNotification(notification));
// TODO profile not enabled
LOG.error("Basal profiles are not enabled on pump.");
} else {
checkValue = settings.get("PCFG_ACTIVE_BASAL_PROFILE");
if (!"STD".equals(checkValue.value)) {
// TODO wrong profile
LOG.error("Basal profile set on pump is incorrect (must be STD).");
}
}
// TBR
checkValue = settings.get("PCFG_TEMP_BASAL_TYPE");
if (!"Units".equals(checkValue.value)) {
// TODO wrong TBR type
LOG.error("Wrong TBR type set on pump (must be Absolute).");
}
// MAXes
checkValue = settings.get("PCFG_MAX_BOLUS");
if (!MedtronicUtil.isSame(Double.parseDouble(checkValue.value), pumpStatus.maxBolus)) {
// TODO wrong max Bolus type
LOG.error("Wrong Max Bolus set on Pump (must be {}).", pumpStatus.maxBolus);
}
checkValue = settings.get("PCFG_MAX_BASAL");
double maxSet = Double.parseDouble(checkValue.value);
if (!MedtronicUtil.isSame(Double.parseDouble(checkValue.value), pumpStatus.maxBasal)) {
// TODO wrong max Bolus type
LOG.error("Wrong Max Basal set on Pump (must be {}).", pumpStatus.maxBasal);
}
//addSettingToMap("PCFG_MAX_BOLUS", "" + decodeMaxBolus(rd), PumpConfigurationGroup.Bolus, map);
//addSettingToMap("PCFG_MAX_BASAL", "" + decodeBasalInsulin(ByteUtil.makeUnsignedShort(rd[getSettingIndexMaxBasal()], rd[getSettingIndexMaxBasal() + 1])), PumpConfigurationGroup.Basal, map);
//addSettingToMap("PCFG_BASAL_PROFILES_ENABLED", parseResultEnable(rd[10]), PumpConfigurationGroup.Basal, map);
//addSettingToMap("PCFG_ACTIVE_BASAL_PROFILE", patt, PumpConfigurationGroup.Basal, map);
//addSettingToMap("PCFG_TEMP_BASAL_TYPE", rd[14] != 0 ? "Percent" : "Units", PumpConfigurationGroup.Basal, map);
}
}

View file

@ -216,4 +216,7 @@ public class MedtronicUITask {
}
public boolean hasData() {
return (returnData != null);
}
}

View file

@ -61,7 +61,6 @@ public enum MedtronicCommandType implements Serializable //, MinimedCommandTypeI
RealTimeClock(112, "Real Time Clock", MinimedTargetType.PumpConfiguration, MedtronicDeviceType.All, MinimedCommandParameterType.NoParameters, 7), // 0x70
GetBatteryStatus(0x72, "Get Battery Status", MinimedTargetType.PumpConfiguration, MedtronicDeviceType.All, MinimedCommandParameterType.NoParameters), //
// GetBattery((byte) 0x72), //
GetRemainingInsulin(0x73, "Read Remaining Insulin", MinimedTargetType.PumpConfiguration, MedtronicDeviceType.All, MinimedCommandParameterType.NoParameters, 2), // 115

View file

@ -28,27 +28,24 @@ public enum MedtronicDeviceType {
Medtronic_722(MedtronicConverterType.Pump515Converter, MedtronicConverterType.CGMS522Converter, "722"), //
Medtronic_522_722(Medtronic_522, Medtronic_722), //
Medtronic_523(MedtronicConverterType.Pump523Converter, MedtronicConverterType.CGMS523Converter, "523"), //
Medtronic_723(MedtronicConverterType.Pump523Converter, MedtronicConverterType.CGMS523Converter, "723"), //
Medtronic_553_Revel(MedtronicConverterType.Pump523Converter, MedtronicConverterType.CGMS523Converter, "553"), //
Medtronic_753_Revel(MedtronicConverterType.Pump523Converter, MedtronicConverterType.CGMS523Converter, "753"), //
Medtronic_523_Revel(MedtronicConverterType.Pump523Converter, MedtronicConverterType.CGMS523Converter, "523"), //
Medtronic_723_Revel(MedtronicConverterType.Pump523Converter, MedtronicConverterType.CGMS523Converter, "723"), //
Medtronic_554_Veo(MedtronicConverterType.Pump523Converter, MedtronicConverterType.CGMS523Converter, "554"), //
Medtronic_754_Veo(MedtronicConverterType.Pump523Converter, MedtronicConverterType.CGMS523Converter, "754"), //
//Minimed_640G(MedtronicConverterType.Pump523Converter, MedtronicConverterType.CGMS523Converter, "640G", null),
Medtronic_512andHigher(Medtronic_512, Medtronic_712, Medtronic_515, Medtronic_715, Medtronic_522, Medtronic_722, //
Medtronic_523, Medtronic_723, Medtronic_553_Revel, Medtronic_753_Revel, Medtronic_554_Veo, Medtronic_754_Veo), //
Medtronic_523_Revel, Medtronic_723_Revel, Medtronic_554_Veo, Medtronic_754_Veo), //
Medtronic_515andHigher(Medtronic_515, Medtronic_715, Medtronic_522, Medtronic_722, Medtronic_523, Medtronic_723, //
Medtronic_553_Revel, Medtronic_753_Revel, Medtronic_554_Veo, Medtronic_754_Veo), //
Medtronic_522andHigher(Medtronic_522, Medtronic_722, Medtronic_523, Medtronic_723, Medtronic_553_Revel, Medtronic_753_Revel, //
Medtronic_515andHigher(Medtronic_515, Medtronic_715, Medtronic_522, Medtronic_722, Medtronic_523_Revel, Medtronic_723_Revel, //
Medtronic_554_Veo, Medtronic_754_Veo), //
Medtronic_523andHigher(Medtronic_523, Medtronic_723, Medtronic_553_Revel, Medtronic_753_Revel, Medtronic_554_Veo, //
Medtronic_522andHigher(Medtronic_522, Medtronic_722, Medtronic_523_Revel, Medtronic_723_Revel, //
Medtronic_554_Veo, Medtronic_754_Veo), //
Medtronic_523andHigher(Medtronic_523_Revel, Medtronic_723_Revel, Medtronic_554_Veo, //
Medtronic_754_Veo), //
Medtronic_553andHigher(Medtronic_553_Revel, Medtronic_753_Revel, Medtronic_554_Veo, Medtronic_754_Veo), //
//Medtronic_553andHigher(Medtronic_553_Revel, Medtronic_753_Revel, Medtronic_554_Veo, Medtronic_754_Veo), //
Medtronic_554andHigher(Medtronic_554_Veo, Medtronic_754_Veo), //
// CGMS

View file

@ -0,0 +1,39 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.defs;
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
/**
* Created by andy on 6/28/18.
*/
public enum MedtronicStatusRefreshType {
PumpHistory(5, null), //
Configuration(0, null), //
RemainingInsulin(-1, MedtronicCommandType.GetRemainingInsulin), //
BatteryStatus(60, MedtronicCommandType.GetBatteryStatus), //
PumpTime(60, MedtronicCommandType.RealTimeClock) //
;
private int refreshTime;
private MedtronicCommandType commandType;
MedtronicStatusRefreshType(int refreshTime, MedtronicCommandType commandType) {
this.refreshTime = refreshTime;
this.commandType = commandType;
}
public int getRefreshTime() {
return refreshTime;
}
public MedtronicCommandType getCommandType() {
if (this == Configuration) {
return MedtronicCommandType.getSettings(MedtronicUtil.getMedtronicPumpModel());
} else
return commandType;
}
}

View file

@ -1,19 +1,21 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.defs;
import info.nightscout.androidaps.R;
/**
* Created by andy on 6/11/18.
*/
public enum PumpDeviceState {
NeverContacted, //
NeverContacted(R.string.medtronic_pump_status_never_contacted), //
Sleeping, //
WakingUp, //
WakingUp(R.string.medtronic_pump_status_waking_up), //
Active, //
ErrorWhenCommunicating, //
TimeoutWhenCommunicating, //
ProblemContacting, //
InvalidConfiguration;
ErrorWhenCommunicating(R.string.medtronic_pump_status_error_comm), //
TimeoutWhenCommunicating(R.string.medtronic_pump_status_timeout_comm), //
ProblemContacting(R.string.medtronic_pump_status_problem_contacting), //
InvalidConfiguration(R.string.medtronic_pump_status_invalid_config);
Integer resourceId = null;
@ -27,4 +29,7 @@ public enum PumpDeviceState {
this.resourceId = resourceId;
}
public Integer getResourceId() {
return resourceId;
}
}

View file

@ -17,7 +17,7 @@ import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
/**
* Created by andy on 4/28/18.
*/
@Deprecated
public class MedtronicPumpDriver extends VirtualPumpDriver /*implements PumpInterface*/ {
private static final Logger LOG = LoggerFactory.getLogger(MedtronicPumpDriver.class);

View file

@ -20,6 +20,7 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkTargetFrequency;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType;
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicConst;
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
@ -35,11 +36,11 @@ public class MedtronicPumpStatus extends PumpStatus {
public String errorDescription = null;
public String serialNumber;
public PumpType pumpType = null;
//public PumpType pumpType = null;
public String pumpFrequency = null;
public String rileyLinkAddress = null;
public Integer maxBolus;
public Integer maxBasal;
public Double maxBolus;
public Double maxBasal;
private String[] frequencies;
private boolean isFrequencyUS = false;
@ -49,42 +50,27 @@ public class MedtronicPumpStatus extends PumpStatus {
String regexSN = "[0-9]{6}";
private Map<String, PumpType> medtronicPumpMap = null;
private Map<String, MedtronicDeviceType> medtronicDeviceTypeMap = null;
// statuses
public RileyLinkServiceState rileyLinkServiceState = RileyLinkServiceState.NotStarted;
public RileyLinkError rileyLinkError;
public PumpDeviceState pumpDeviceState = PumpDeviceState.NeverContacted;
public MedtronicDeviceType medtronicDeviceType = null;
// fixme
// public long getTimeIndex() {
// return (long) Math.ceil(time.getTime() / 60000d);
// }
//
//
// public void setTimeIndex(long timeIndex) {
// this.timeIndex = timeIndex;
// }
//
//
// public long timeIndex;
//
// public Date time;
//public double remainingUnits = 0;
public int remainBattery = 0;
public double currentBasal = 0;
public int tempBasalInProgress = 0;
public int tempBasalRatio = 0;
public double tempBasalAmount = 0.0d;
public int tempBasalRemainMin = 0;
public Date tempBasalStart;
//public Date last_bolus_time; in main class
//public double last_bolus_amount = 0;
public Double tempBasalAmount = 0.0d;
public Integer tempBasalLength = 0;
// fixme
@ -102,7 +88,32 @@ public class MedtronicPumpStatus extends PumpStatus {
this.reservoirRemainingUnits = 75d;
this.batteryRemaining = 75;
if (this.medtronicPumpMap == null) createMedtronicPumpMap();
if (this.medtronicPumpMap == null)
createMedtronicPumpMap();
if (this.medtronicDeviceTypeMap == null)
createMedtronicDeviceTypeMap();
this.lastConnection = SP.getLong(MedtronicConst.Statistics.LastGoodPumpCommunicationTime, 0L);
Date d = new Date();
d.setTime(this.lastConnection);
this.lastDataTime = d;
}
private void createMedtronicDeviceTypeMap() {
medtronicDeviceTypeMap = new HashMap<>();
medtronicDeviceTypeMap.put("512", MedtronicDeviceType.Medtronic_512);
medtronicDeviceTypeMap.put("712", MedtronicDeviceType.Medtronic_712);
medtronicDeviceTypeMap.put("515", MedtronicDeviceType.Medtronic_515);
medtronicDeviceTypeMap.put("715", MedtronicDeviceType.Medtronic_715);
medtronicDeviceTypeMap.put("522", MedtronicDeviceType.Medtronic_522);
medtronicDeviceTypeMap.put("722", MedtronicDeviceType.Medtronic_722);
medtronicDeviceTypeMap.put("523", MedtronicDeviceType.Medtronic_523_Revel);
medtronicDeviceTypeMap.put("723", MedtronicDeviceType.Medtronic_723_Revel);
medtronicDeviceTypeMap.put("554", MedtronicDeviceType.Medtronic_554_Veo);
medtronicDeviceTypeMap.put("754", MedtronicDeviceType.Medtronic_754_Veo);
}
@ -137,6 +148,8 @@ public class MedtronicPumpStatus extends PumpStatus {
if (this.medtronicPumpMap == null)
createMedtronicPumpMap();
if (this.medtronicDeviceTypeMap == null)
createMedtronicDeviceTypeMap();
String serialNr = SP.getString(MedtronicConst.Prefs.PumpSerial, null);
@ -169,6 +182,7 @@ public class MedtronicPumpStatus extends PumpStatus {
return;
} else {
this.pumpType = medtronicPumpMap.get(pumpTypePart);
this.medtronicDeviceType = medtronicDeviceTypeMap.get(pumpTypePart);
if (pumpTypePart.startsWith("7"))
this.reservoirFullUnits = "300";
@ -214,21 +228,9 @@ public class MedtronicPumpStatus extends PumpStatus {
}
String value = SP.getString(MedtronicConst.Prefs.MaxBolus, "25");
maxBolus = checkParameterValue(MedtronicConst.Prefs.MaxBolus, "25.0", 25.0d);
maxBolus = Integer.parseInt(value);
if (maxBolus > 25) {
SP.putString(MedtronicConst.Prefs.MaxBolus, "25");
}
value = SP.getString(MedtronicConst.Prefs.MaxBasal, "35");
maxBasal = Integer.parseInt(value);
if (maxBasal > 35) {
SP.putString(MedtronicConst.Prefs.MaxBasal, "35");
}
maxBasal = checkParameterValue(MedtronicConst.Prefs.MaxBasal, "35.0", 35.0d);
startService();
@ -254,6 +256,27 @@ public class MedtronicPumpStatus extends PumpStatus {
}
private double checkParameterValue(String key, String defaultValue, double defaultValueDouble) {
double val = 0.0d;
String value = SP.getString(key, defaultValue);
try {
val = Double.parseDouble(value);
} catch (Exception ex) {
LOG.error("Error parsing setting: {}, value found {}", key, value);
val = defaultValueDouble;
}
if (val > defaultValueDouble) {
SP.putString(MedtronicConst.Prefs.MaxBolus, "25.0");
val = defaultValueDouble;
}
return val;
}
public String getErrorInfo() {
verifyConfiguration();

View file

@ -16,11 +16,19 @@ public class MedtronicConst {
public static final String PumpFrequency = PrefPrefix + "frequency";
public static final String MaxBolus = PrefPrefix + "max_bolus";
public static final String MaxBasal = PrefPrefix + "max_basal";
public static final String FirstPumpStart = Prefix + "first_pump_use";
}
public class Statistics {
public static final String StatsPrefix = "medtronic_";
static final String TBRsSet = StatsPrefix + "tbrs_set";
static final String StandardBoluses = StatsPrefix + "std_boluses_delivered";
static final String SMBBoluses = StatsPrefix + "smb_boluses_delivered";
public static final String FirstPumpStart = Prefix + "first_pump_use";
public static final String LastGoodPumpCommunicationTime = Prefix + "lastGoodPumpCommunicationTime";
public static final String LastGoodPumpFrequency = Prefix + "LastGoodPumpFrequency";
}

View file

@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.List;
import java.util.Map;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
@ -14,6 +15,7 @@ import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
import info.nightscout.androidaps.plugins.PumpCommon.utils.HexDump;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.MedtronicCommunicationManager;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.message.MessageType;
import info.nightscout.androidaps.plugins.PumpMedtronic.data.dto.PumpSettingDTO;
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicCommandType;
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType;
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.PumpDeviceState;
@ -34,6 +36,7 @@ public class MedtronicUtil extends RileyLinkUtil {
private static RileyLinkMedtronicService medtronicService;
private static MedtronicPumpStatus medtronicPumpStatus;
private static MedtronicCommandType currentCommand;
private static Map<String, PumpSettingDTO> settings;
public static LocalTime getTimeFrom30MinInterval(int interval) {
@ -277,7 +280,7 @@ public class MedtronicUtil extends RileyLinkUtil {
MedtronicUtil.currentCommand = currentCommand;
}
public static MedtronicCommandType getCurrectCommand() {
public static MedtronicCommandType getCurrentCommand() {
return MedtronicUtil.currentCommand;
}
@ -286,4 +289,12 @@ public class MedtronicUtil extends RileyLinkUtil {
return (Math.abs(diff) <= 0.000001);
}
public static void setSettings(Map<String, PumpSettingDTO> settings) {
MedtronicUtil.settings = settings;
}
public static Map<String, PumpSettingDTO> getSettings() {
return settings;
}
}

View file

@ -1124,5 +1124,11 @@
<string name="rileylink_error_pod_unreachable">Pod unreachable</string>
<string name="medtronic_cmd_profile_not_set">Remote Basal profile setting is not supported. Please modify Basal profile on your pump manually.</string>
<string name="medtronic_pump_status_never_contacted">Never contacted</string>
<string name="medtronic_pump_status_waking_up">Waking up</string>
<string name="medtronic_pump_status_error_comm">Error with communication</string>
<string name="medtronic_pump_status_timeout_comm">Timeout on communication</string>
<string name="medtronic_pump_status_problem_contacting">Problem contacting Pump</string>
<string name="medtronic_pump_status_invalid_config">Invalid configuration</string>
</resources>

View file

@ -32,6 +32,7 @@
android:selectAllOnFocus="true"
android:singleLine="true"
android:inputType="number"
android:digits="0123456789."
android:title="@string/medtronic_pump_max_basal" />
<EditTextPreference
@ -40,6 +41,7 @@
android:selectAllOnFocus="true"
android:singleLine="true"
android:inputType="number"
android:digits="0123456789."
android:title="@string/medtronic_pump_max_bolus" />
<Preference