Medtronic-0.11.2-SNAPSHOT

- #122 - TBRs processing
- #139 - Set Time in Pump
- #126 - Calculate Battery
- #140 - Be aware of Time/TZ changes
This commit is contained in:
Andy Rozman 2019-06-23 00:01:11 +01:00
parent 654b8ab0f6
commit 5878a33ac7
24 changed files with 387 additions and 160 deletions

View file

@ -105,7 +105,7 @@ android {
multiDexEnabled true
versionCode 1500
// dev_version: 2.3.1-dev
version "medtronic-0.11.1-SNAPSHOT"
version "medtronic-0.11.2-SNAPSHOT"
buildConfigField "String", "VERSION", '"' + version + '"'
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'

View file

@ -282,6 +282,9 @@ public class MainApp extends Application {
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump();
if (action != null) {
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
switch (state) {
@ -290,17 +293,29 @@ public class MainApp extends Application {
case BluetoothAdapter.STATE_TURNING_ON:
break;
case BluetoothAdapter.STATE_ON:
case BluetoothAdapter.STATE_ON: {
if (activePump != null && "Medtronic".equals(activePump.deviceID())) {
Log.v("MainApp", "Bluetooth on");
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.BluetoothReconnected);
}
}
break;
}
} else {
if (activePump != null) {
activePump.timeDateOrTimeZoneChanged();
}
}
}
}
};
// Register for broadcasts on BluetoothAdapter state change
IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_DATE_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
registerReceiver(btReceiver, filter);
}

View file

@ -542,13 +542,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
GregorianCalendar gc = new GregorianCalendar();
gc.add(Calendar.DAY_OF_YEAR, (-1) * days);
Date d = new Date((gc.get(Calendar.YEAR)-1900), gc.get(Calendar.MONTH), gc.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
try {
QueryBuilder<TDD, String> queryBuilder = getDaoTDD().queryBuilder();
queryBuilder.orderBy("date", false);
Where<TDD, String> where = queryBuilder.where();
where.ge("date", d.getTime());
where.ge("date", gc.getTimeInMillis());
PreparedQuery<TDD> preparedQuery = queryBuilder.prepare();
tddList = getDaoTDD().query(preparedQuery);
} catch (SQLException e) {

View file

@ -6,9 +6,8 @@ import com.j256.ormlite.table.DatabaseTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Objects;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
/**
* Created by mike on 20.09.2017.
@ -45,4 +44,16 @@ public class TDD {
this.basal = basal;
this.total = total;
}
@Override
public String toString() {
return "TDD [" +
"date=" + date +
"date(str)=" + DateTimeUtil.toStringFromTimeInMillis(date) +
", bolus=" + bolus +
", basal=" + basal +
", total=" + total +
']';
}
}

View file

@ -71,4 +71,10 @@ public interface PumpInterface {
void executeCustomAction(CustomActionType customActionType);
/**
* This method will be called when time or Timezone changes, and pump driver can then do a specific action (for
* example update clock on pump).
*/
void timeDateOrTimeZoneChanged();
}

View file

@ -1396,4 +1396,10 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
return false;
}
@Override
public void timeDateOrTimeZoneChanged() {
}
}

View file

@ -158,6 +158,23 @@ public class DateTimeUtil {
}
public static String toString(GregorianCalendar gc) {
return getZeroPrefixed(gc.get(Calendar.DAY_OF_MONTH)) + "." + getZeroPrefixed(gc.get(Calendar.MONTH) + 1) + "."
+ gc.get(Calendar.YEAR) + " "
+ //
getZeroPrefixed(gc.get(Calendar.HOUR_OF_DAY)) + ":" + getZeroPrefixed(gc.get(Calendar.MINUTE)) + ":"
+ getZeroPrefixed(gc.get(Calendar.SECOND));
}
public static String toStringFromTimeInMillis(long timeInMillis) {
GregorianCalendar gc = new GregorianCalendar();
gc.setTimeInMillis(timeInMillis);
return toString(gc);
}
private static String getZeroPrefixed(int number) {
return (number < 10) ? "0" + number : "" + number;
}

View file

@ -493,7 +493,10 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
return false;
}
@Override
public void timeDateOrTimeZoneChanged() {
}
}

View file

@ -832,4 +832,9 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
return false;
}
@Override
public void timeDateOrTimeZoneChanged() {
}
}

View file

@ -1583,4 +1583,10 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
public boolean canHandleDST() {
return true;
}
@Override
public void timeDateOrTimeZoneChanged() {
}
}

View file

@ -265,4 +265,10 @@ public class MDIPlugin extends PluginBase implements PumpInterface {
return true;
}
@Override
public void timeDateOrTimeZoneChanged() {
}
}

View file

@ -40,6 +40,8 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
import info.nightscout.androidaps.plugins.general.overview.dialogs.MessageHelperActivity;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
@ -57,6 +59,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUITask
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfileEntry;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.ClockDTO;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BasalProfileStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
@ -99,6 +102,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
public static boolean isBusy = false;
private List<Long> busyTimestamps = new ArrayList<>();
private boolean sentIdToFirebase = false;
private boolean hasTimeDateOrTimeZoneChanged = false;
private MedtronicPumpPlugin() {
@ -413,9 +417,23 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
// execute
if (statusRefresh != null) {
if (hasTimeDateOrTimeZoneChanged) {
checkTimeAndOptionallySetTime();
// read time if changed, set new time
hasTimeDateOrTimeZoneChanged = false;
workWithStatusRefresh(StatusRefreshAction.Add, MedtronicStatusRefreshType.PumpTime, 30L);
if (statusRefresh.containsKey(MedtronicStatusRefreshType.PumpTime)) {
statusRefresh.remove(MedtronicStatusRefreshType.PumpTime);
}
}
// execute
Set<MedtronicStatusRefreshType> refreshTypesNeededToReschedule = new HashSet<>();
for (Map.Entry<MedtronicStatusRefreshType, Long> refreshType : statusRefresh.entrySet()) {
@ -428,7 +446,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
break;
case PumpTime:
case PumpTime: {
checkTimeAndOptionallySetTime();
refreshTypesNeededToReschedule.add(refreshType.getKey());
resetTime = true;
}
break;
case BatteryStatus:
case RemainingInsulin: {
medtronicUIComm.executeCommand(refreshType.getKey().getCommandType());
@ -444,11 +468,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
break;
}
}
}
// reschedule
for (MedtronicStatusRefreshType refreshType : refreshTypesNeededToReschedule) {
scheduleNextRefresh(refreshType);
for (MedtronicStatusRefreshType refreshType2 : refreshTypesNeededToReschedule) {
scheduleNextRefresh(refreshType2);
}
}
@ -468,7 +491,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
}
return false;
return hasTimeDateOrTimeZoneChanged;
}
@ -519,7 +542,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
this.pumpState = PumpDriverState.Connected;
// time (1h)
medtronicUIComm.executeCommand(MedtronicCommandType.RealTimeClock);
checkTimeAndOptionallySetTime();
//medtronicUIComm.executeCommand(MedtronicCommandType.GetRealTimeClock);
scheduleNextRefresh(MedtronicStatusRefreshType.PumpTime, 30);
readPumpHistory();
@ -563,7 +587,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
sentIdToFirebase = true;
}
isInitialized = true;
// this.pumpState = PumpDriverState.Initialized;
@ -680,6 +703,47 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
private void checkTimeAndOptionallySetTime() {
if (isLoggingEnabled())
LOG.info("MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Start");
setRefreshButtonEnabled(false);
if (isPumpNotReachable()) {
LOG.debug("MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Pump Unreachable.");
setRefreshButtonEnabled(true);
return;
}
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
medtronicUIComm.executeCommand(MedtronicCommandType.GetRealTimeClock);
ClockDTO clock = MedtronicUtil.getPumpTime();
int timeDiff = Math.abs(clock.timeDifference);
if (timeDiff > 20) {
if (isLoggingEnabled())
LOG.info("MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference is {} s. Set time on pump.", timeDiff);
medtronicUIComm.executeCommand(MedtronicCommandType.SetRealTimeClock);
if (clock.timeDifference == 0) {
Notification notification = new Notification(Notification.INSIGHT_DATE_TIME_UPDATED, MainApp.gs(R.string.pump_time_updated), Notification.INFO, 60);
MainApp.bus().post(new EventNewNotification(notification));
}
} else {
if (isLoggingEnabled())
LOG.info("MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference is {} s. Do nothing.", timeDiff);
}
}
@NonNull
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
@ -779,9 +843,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
} finally {
MainApp.bus().post(new EventRefreshOverview("Bolus"));
finishAction("Bolus");
this.bolusDeliveryType = BolusDeliveryType.Idle;
triggerUIChange();
}
}
@ -1145,8 +1208,9 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
private synchronized Map<MedtronicStatusRefreshType, Long> workWithStatusRefresh(StatusRefreshAction action,
MedtronicStatusRefreshType statusRefreshType, Long time) {
private synchronized Map<MedtronicStatusRefreshType, Long> workWithStatusRefresh(StatusRefreshAction action, //
MedtronicStatusRefreshType statusRefreshType, //
Long time) {
switch (action) {
@ -1422,6 +1486,14 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
@Override
public void timeDateOrTimeZoneChanged() {
if (isLoggingEnabled())
LOG.warn(getLogPrefix() + "Time, Date and/or TimeZone changed. ");
this.hasTimeDateOrTimeZoneChanged = true;
}
private void refreshCustomActionsList() {
MainApp.bus().post(new EventCustomActionsChanged());

View file

@ -7,6 +7,8 @@ import org.joda.time.LocalDateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
@ -811,7 +813,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
ClockDTO clockDTO = new ClockDTO();
clockDTO.localDeviceTime = new LocalDateTime();
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.RealTimeClock);
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.GetRealTimeClock);
if (responseObject != null) {
clockDTO.pumpTime = (LocalDateTime) responseObject;
@ -858,6 +860,36 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
}
public Boolean setPumpTime() {
GregorianCalendar gc = new GregorianCalendar();
gc.add(Calendar.SECOND, 5);
if (isLogEnabled())
LOG.info("setPumpTime: " + DateTimeUtil.toString(gc));
int i = 1;
byte[] data = new byte[8];
data[0] = 7;
data[i] = (byte) gc.get(Calendar.HOUR_OF_DAY);
data[i + 1] = (byte) gc.get(Calendar.MINUTE);
data[i + 2] = (byte) gc.get(Calendar.SECOND);
byte[] yearByte = MedtronicUtil.getByteArrayFromUnsignedShort(gc.get(Calendar.YEAR), true);
data[i + 3] = yearByte[0];
data[i + 4] = yearByte[1];
data[i + 5] = (byte) (gc.get(Calendar.MONTH) + 1);
data[i + 6] = (byte) gc.get(Calendar.DAY_OF_MONTH);
//LOG.info("setPumpTime: Body: " + ByteUtil.getHex(data));
return setCommand(MedtronicCommandType.SetRealTimeClock, data);
}
private boolean setCommand(MedtronicCommandType commandType, byte[] body) {
for (int retries = 0; retries <= MAX_COMMAND_TRIES; retries++) {

View file

@ -52,7 +52,7 @@ public class MedtronicConverter {
return decodeModel(rawContent);
}
case RealTimeClock: {
case GetRealTimeClock: {
return decodeTime(rawContent);
}

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm.message;
import android.util.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View file

@ -87,11 +87,24 @@ public class MedtronicUIPostprocessor {
}
break;
case RealTimeClock: {
case GetRealTimeClock: {
processTime(uiTask);
}
break;
case SetRealTimeClock: {
boolean response = (Boolean) uiTask.returnData;
if (isLogEnabled())
LOG.debug("New time was {} set.", response ? "" : "NOT");
if (response) {
MedtronicUtil.getPumpTime().timeDifference = 0;
}
}
break;
case GetBatteryStatus: {
BatteryStatusDTO batteryStatusDTO = (BatteryStatusDTO) uiTask.returnData;

View file

@ -66,11 +66,16 @@ public class MedtronicUITask {
}
break;
case RealTimeClock: {
case GetRealTimeClock: {
returnData = communicationManager.getPumpTime();
}
break;
case SetRealTimeClock: {
returnData = communicationManager.setPumpTime();
}
break;
case GetBatteryStatus: {
returnData = communicationManager.getRemainingBattery();
}

View file

@ -10,7 +10,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.GregorianCalendar;
@ -31,7 +30,6 @@ import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.configBuilder.DetailedBolusInfoStorage;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntryType;
@ -50,7 +48,6 @@ import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.SP;
//import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
/**
* Created by andy on 10/12/18.
@ -67,7 +64,6 @@ public class MedtronicHistoryData {
private boolean isInit = false;
private Gson gson;
//private List<PumpHistoryEntry> fakeTBRs;
private DatabaseHelper databaseHelper = MainApp.getDbHelper();
private ClockDTO pumpTime;
@ -387,7 +383,7 @@ public class MedtronicHistoryData {
LOG.debug("ProcessHistoryData: Bolus [count={}, items={}]", treatments.size(), gson.toJson(treatments));
if (treatments.size() > 0) {
processEntries(treatments, ProcessHistoryRecord.Bolus);
processBolusEntries(treatments);
}
// TBR
@ -396,7 +392,7 @@ public class MedtronicHistoryData {
LOG.debug("ProcessHistoryData: TBRs NOT Processed [count={}, items={}]", tbrs.size(), gson.toJson(tbrs));
if (tbrs.size() > 0) {
//processEntries(tbrs, ProcessHistoryRecord.TBR);
processTBREntries(tbrs);
}
// 'Delivery Suspend'
@ -470,11 +466,11 @@ public class MedtronicHistoryData {
}
private void processEntries(List<PumpHistoryEntry> entryList, ProcessHistoryRecord processHistoryRecord) {
private void processBolusEntries(List<PumpHistoryEntry> entryList) {
int dateDifference = getOldestDateDifference(entryList);
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntries(dateDifference, processHistoryRecord);
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntries(dateDifference, ProcessHistoryRecord.Bolus);
// LOG.debug(processHistoryRecord.getDescription() + " List (before filter): {}, FromDb={}", gsonPretty.toJson(entryList),
// gsonPretty.toJson(entriesFromHistory));
@ -490,80 +486,117 @@ public class MedtronicHistoryData {
if (isCollectionEmpty(entriesFromHistory)) {
for (PumpHistoryEntry treatment : entryList) {
if (isLogEnabled())
LOG.debug("Add " + processHistoryRecord.getDescription() + " (no db entries): " + treatment);
addEntry(treatment, null, processHistoryRecord);
LOG.debug("Add Bolus (no db entries): " + treatment);
addBolus(treatment, null);
}
} else {
for (PumpHistoryEntry treatment : entryList) {
DbObjectBase treatmentDb = findDbEntry(treatment, entriesFromHistory);
if (isLogEnabled())
LOG.debug("Add " + processHistoryRecord.getDescription() + " {} - (entryFromDb={}) ", treatment, treatmentDb);
LOG.debug("Add Bolus {} - (entryFromDb={}) ", treatment, treatmentDb);
addEntry(treatment, treatmentDb, processHistoryRecord);
addBolus(treatment, (Treatment) treatmentDb);
}
}
}
private void processTBREntries(List<PumpHistoryEntry> entryList, ProcessHistoryRecord processHistoryRecord) {
int dateDifference = getOldestDateDifference(entryList);
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntries(dateDifference, processHistoryRecord);
// LOG.debug(processHistoryRecord.getDescription() + " List (before filter): {}, FromDb={}", gsonPretty.toJson(entryList),
// gsonPretty.toJson(entriesFromHistory));
private void processTBREntries(List<PumpHistoryEntry> entryList) {
Collections.reverse(entryList);
filterOutAlreadyAddedEntries(entryList, entriesFromHistory);
TempBasalPair tbr = (TempBasalPair) entryList.get(0).getDecodedDataEntry("Object");
boolean readOldItem = false;
if (tbr.isCancelTBR()) {
PumpHistoryEntry oneMoreEntryFromHistory = getOneMoreEntryFromHistory(PumpHistoryEntryType.TempBasalCombined);
if (oneMoreEntryFromHistory != null) {
entryList.add(0, oneMoreEntryFromHistory);
readOldItem = true;
} else {
entryList.remove(0);
}
}
int dateDifference = getOldestDateDifference(entryList);
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntries(dateDifference, ProcessHistoryRecord.TBR);
LOG.debug(ProcessHistoryRecord.TBR.getDescription() + " List (before filter): {}, FromDb={}", gson.toJson(entryList),
gson.toJson(entriesFromHistory));
//filterOutAlreadyAddedEntries(entryList, entriesFromHistory);
if (entryList.isEmpty())
return;
// LOG.debug(processHistoryRecord.getDescription() + " List (after filter): {}, FromDb={}", gsonPretty.toJson(entryList),
// gsonPretty.toJson(entriesFromHistory));
PumpHistoryEntry startRecord = null;
// LOG.debug(processHistoryRecord.getDescription() + " List (after filter): {}, FromDb={}", gson.toJson(entryList),
// gson.toJson(entriesFromHistory));
//PumpHistoryEntry startRecord = null;
TempBasalProcessDTO processDTO = null;
List<TempBasalProcessDTO> processList = new ArrayList<>();
for (PumpHistoryEntry treatment : entryList) {
TempBasalPair tbr = (TempBasalPair) treatment.getDecodedDataEntry("Object");
TempBasalPair tbr2 = (TempBasalPair) treatment.getDecodedDataEntry("Object");
if (!tbr.isCancelTBR()) {
if (tbr2.isCancelTBR()) {
processDTO.itemTwo = treatment;
if (readOldItem) {
processDTO.processOperation = TempBasalProcessDTO.Operation.Edit;
readOldItem = false;
} else {
processDTO.processOperation = TempBasalProcessDTO.Operation.Add;
}
boolean isPossibleCancel = false;
if (tbr.getInsulinRate() > 0.0d) {
startRecord = treatment;
} else {
isPossibleCancel = true;
if (startRecord == null) {
if (processDTO != null) {
processList.add(processDTO);
}
processDTO = new TempBasalProcessDTO();
processDTO.itemOne = treatment;
}
}
if (!isCollectionEmpty(processList)) {
for (TempBasalProcessDTO tempBasalProcessDTO : processList) {
if (tempBasalProcessDTO.processOperation == TempBasalProcessDTO.Operation.Edit) {
// edit
TemporaryBasal tempBasal = databaseHelper.findTempBasalByPumpId(tempBasalProcessDTO.itemOne.getPumpId());
tempBasal.durationInMinutes = tempBasalProcessDTO.getDuration();
databaseHelper.createOrUpdate(tempBasal);
if (isLogEnabled())
LOG.debug("Add " + processHistoryRecord.getDescription() + " (no db entries): " + treatment);
addEntry(treatment, null, processHistoryRecord);
}
LOG.debug("Edit " + ProcessHistoryRecord.TBR.getDescription() + " - (entryFromDb={}) ", tempBasal);
if (isCollectionEmpty(entriesFromHistory)) {
} else {
for (PumpHistoryEntry treatment : entryList) {
// add
PumpHistoryEntry treatment = tempBasalProcessDTO.itemOne;
TempBasalPair tbr2 = (TempBasalPair) treatment.getDecodedData().get("Object");
tbr2.setDurationMinutes(tempBasalProcessDTO.getDuration());
DbObjectBase treatmentDb = findDbEntry(treatment, entriesFromHistory);
if (isLogEnabled())
LOG.debug("Add " + processHistoryRecord.getDescription() + " {} - (entryFromDb={}) ", treatment, treatmentDb);
addEntry(treatment, treatmentDb, processHistoryRecord);
}
}
if (isLogEnabled())
LOG.debug("Add " + ProcessHistoryRecord.TBR.getDescription() + " {} - (entryFromDb={}) ", treatment, treatmentDb);
addTBR(treatment, (TemporaryBasal) treatmentDb);
} // if
} // for
} // collection
}
@ -576,8 +609,8 @@ public class MedtronicHistoryData {
if (entriesFromHistory.size() == 0) {
return null;
} else if (entriesFromHistory.size() == 1) {
DbObjectBase treatment1 = entriesFromHistory.get(0);
LocalDateTime ldt = new LocalDateTime(treatment1.getDate());
//DbObjectBase treatment1 = entriesFromHistory.get(0);
//LocalDateTime ldt = new LocalDateTime(treatment1.getDate());
return entriesFromHistory.get(0);
}
@ -614,18 +647,6 @@ public class MedtronicHistoryData {
}
private void addEntry(PumpHistoryEntry treatment, DbObjectBase treatmentDb, ProcessHistoryRecord processHistoryRecord) {
if (processHistoryRecord == ProcessHistoryRecord.Bolus) {
addBolus(treatment, (Treatment) treatmentDb);
} else if (processHistoryRecord == ProcessHistoryRecord.TBR) {
addTBR(treatment, (TemporaryBasal) treatmentDb);
} else {
addTBR(treatment, (TemporaryBasal) treatmentDb);
}
}
private List<? extends DbObjectBase> getDatabaseEntries(int dateDifference, ProcessHistoryRecord processHistoryRecord) {
if (processHistoryRecord == ProcessHistoryRecord.Bolus) {
return TreatmentsPlugin.getPlugin().getTreatmentsFromHistoryXMinutesAgo(
@ -794,7 +815,7 @@ public class MedtronicHistoryData {
}
public void processSuspends(List<TempBasalProcessDTO> tempBasalProcessList) {
private void processSuspends(List<TempBasalProcessDTO> tempBasalProcessList) {
for (TempBasalProcessDTO tempBasalProcess : tempBasalProcessList) {
@ -816,10 +837,7 @@ public class MedtronicHistoryData {
databaseHelper.createOrUpdate(tempBasal);
} else {
continue;
}
}
}
@ -855,9 +873,9 @@ public class MedtronicHistoryData {
// not full suspends, need to retrive one more record and discard first one (R S R S) -> ([S] R S R [xS])
filteredItems.remove(0);
PumpHistoryEntry oneMoreEntryFromHistory = getOneMoreEntryFromHistory();
PumpHistoryEntry oneMoreEntryFromHistory = getOneMoreEntryFromHistory(PumpHistoryEntryType.Suspend);
if (oneMoreEntryFromHistory != null) {
filteredItems.add(getOneMoreEntryFromHistory());
filteredItems.add(oneMoreEntryFromHistory);
} else {
filteredItems.remove(filteredItems.size() - 1); // remove last (unpaired R)
}
@ -867,7 +885,7 @@ public class MedtronicHistoryData {
if (filteredItems.get(0).getEntryType() == PumpHistoryEntryType.Resume) {
// get one more from history (R S R) -> ([S] R S R)
PumpHistoryEntry oneMoreEntryFromHistory = getOneMoreEntryFromHistory();
PumpHistoryEntry oneMoreEntryFromHistory = getOneMoreEntryFromHistory(PumpHistoryEntryType.Suspend);
if (oneMoreEntryFromHistory != null) {
filteredItems.add(oneMoreEntryFromHistory);
} else {
@ -936,11 +954,9 @@ public class MedtronicHistoryData {
break;
}
if (!finishedItems) {
tempData.add(filteredItem);
}
}
}
if (!finishedItems) {
@ -960,11 +976,9 @@ public class MedtronicHistoryData {
break;
}
if (!finishedItems) {
tempData.add(filteredItem);
}
}
}
if (!finishedItems) {
@ -972,7 +986,6 @@ public class MedtronicHistoryData {
return outList;
}
showLogs("NoDeliveryRewindPrimeRecords: Records to evaluate: ", gson.toJson(tempData));
List<PumpHistoryEntry> items = getFilteredItems(tempData, //
@ -993,7 +1006,8 @@ public class MedtronicHistoryData {
processDTO.itemOne = items.get(items.size() - 1);
processDTO.processOperation = TempBasalProcessDTO.Operation.Add;
return Arrays.asList(processDTO);
outList.add(processDTO);
return outList;
}
@ -1006,15 +1020,16 @@ public class MedtronicHistoryData {
processDTO.itemOne = items.get(0);
processDTO.processOperation = TempBasalProcessDTO.Operation.Add;
return Arrays.asList(processDTO);
outList.add(processDTO);
return outList;
}
return outList;
}
private PumpHistoryEntry getOneMoreEntryFromHistory() {
List<PumpHistoryEntry> filteredItems = getFilteredItems(this.allHistory, PumpHistoryEntryType.Suspend);
private PumpHistoryEntry getOneMoreEntryFromHistory(PumpHistoryEntryType entryType) {
List<PumpHistoryEntry> filteredItems = getFilteredItems(this.allHistory, entryType);
return filteredItems.size() == 0 ? null : filteredItems.get(0);
}

View file

@ -25,7 +25,12 @@ public class BatteryStatusDTO {
double percent = (voltage - batteryType.lowVoltage) / (batteryType.highVoltage - batteryType.lowVoltage);
return (int)(percent * 100.0d);
int percentInt = (int) (percent * 100.0d);
if (percentInt > 100)
percentInt = 100;
return percentInt;
}
@ -37,7 +42,6 @@ public class BatteryStatusDTO {
}
public enum BatteryStatusType {
Normal,
Low,

View file

@ -11,9 +11,14 @@ public class TempBasalProcessDTO {
public Operation processOperation = Operation.None;
public int getDuration() {
if (itemTwo == null) {
TempBasalPair tbr = (TempBasalPair) itemOne.getDecodedDataEntry("Object");
return tbr.getDurationMinutes();
} else {
int difference = DateTimeUtil.getATechDateDiferenceAsMinutes(itemOne.atechDateTime, itemTwo.atechDateTime);
return difference;
}
}
public static enum Operation {

View file

@ -13,12 +13,12 @@ import info.nightscout.androidaps.R;
public enum BatteryType {
None(R.string.medtronic_pump_battery_no, 0, 0),
Alkaline(R.string.medtronic_pump_battery_alkaline,1.20f, 1.47f), //
Lithium(R.string.medtronic_pump_battery_lithium,1.32f, 1.58f);
Alkaline(R.string.medtronic_pump_battery_alkaline, 1.20d, 1.47d), //
Lithium(R.string.medtronic_pump_battery_lithium, 1.25d, 1.64d);
private final String description;
public float lowVoltage;
public float highVoltage;
public double lowVoltage;
public double highVoltage;
static Map<String, BatteryType> mapByDescription;
@ -30,7 +30,7 @@ public enum BatteryType {
}
}
BatteryType(int resId, float lowVoltage, float highVoltage) {
BatteryType(int resId, double lowVoltage, double highVoltage) {
this.description = MainApp.gs(resId);
this.lowVoltage = lowVoltage;
this.highVoltage = highVoltage;

View file

@ -67,7 +67,10 @@ public enum MedtronicCommandType implements Serializable // , MinimedCommandType
// PumpId(113, "Pump Id", MinimedTargetType.PumpConfiguration, MedtronicDeviceType.All,
// MinimedCommandParameterType.NoParameters), // init
RealTimeClock(112, "Real Time Clock", MedtronicDeviceType.All, MinimedCommandParameterType.NoParameters, //
SetRealTimeClock(0x40, "Set Pump Time", MedtronicDeviceType.All, MinimedCommandParameterType.NoParameters, //
0), //
GetRealTimeClock(112, "Get Pump Time", MedtronicDeviceType.All, MinimedCommandParameterType.NoParameters, //
7, R.string.medtronic_cmd_desc_get_time), // 0x70
GetBatteryStatus(0x72, "Get Battery Status", MedtronicDeviceType.All, MinimedCommandParameterType.NoParameters), //

View file

@ -12,7 +12,7 @@ public enum MedtronicStatusRefreshType {
Configuration(0, null), //
RemainingInsulin(-1, MedtronicCommandType.GetRemainingInsulin), //
BatteryStatus(55, MedtronicCommandType.GetBatteryStatus), //
PumpTime(60, MedtronicCommandType.RealTimeClock) //
PumpTime(60, MedtronicCommandType.GetRealTimeClock) //
;
private int refreshTime;

View file

@ -481,4 +481,11 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
}
@Override
public void timeDateOrTimeZoneChanged() {
}
}