medtronic-0.11.8-SNAPSHOT

- #147 - Prevent update of tive if over 24h
- #148 - Pump History Dialog has filter
- #146 - Battery not updated every hour
- #149 - If BasalProfile fails its never retried
This commit is contained in:
Andy Rozman 2019-06-29 16:24:47 +01:00
parent f0b8aefc14
commit 982a5001b3
12 changed files with 78 additions and 75 deletions

View file

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

View file

@ -75,7 +75,6 @@ import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin;
import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin;
import info.nightscout.androidaps.plugins.pump.mdi.MDIPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin;
@ -96,7 +95,6 @@ import info.nightscout.androidaps.receivers.KeepAliveReceiver;
import info.nightscout.androidaps.receivers.NSAlarmReceiver;
import info.nightscout.androidaps.services.Intents;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.SP;
import io.fabric.sdk.android.Fabric;
import static info.nightscout.androidaps.plugins.general.versionChecker.VersionCheckerUtilsKt.triggerCheckVersion;

View file

@ -75,6 +75,7 @@ public class Notification {
public static final int DST_IN_24H = 50;
public static final int DISKFULL = 51;
public static final int OLDVERSION = 52;
public static final int OVER_24H_TIME_CHANGE_REQUESTED = 53;
public int id;

View file

@ -114,6 +114,7 @@ public class ByteUtil {
return shortHexString(abyte0);
}
public static String shortHexString(byte val) {
return getHexCompact(val);
}

View file

@ -10,7 +10,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import info.nightscout.androidaps.logging.L;
@ -82,7 +81,7 @@ public class DateTimeUtil {
int second = (int) atechDateTime;
try {
return new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minute, second);
return new GregorianCalendar(year, month - 1, dayOfMonth, hourOfDay, minute, second);
} catch (Exception ex) {
if (L.isEnabled(L.PUMPCOMM))
LOG.error("DateTimeUtil", String.format("Error creating GregorianCalendar from values [atechDateTime=%d, year=%d, month=%d, day=%d, hour=%d, minute=%d, second=%d]", atechDateTime, year, month, dayOfMonth, hourOfDay, minute, second));
@ -153,19 +152,19 @@ public class DateTimeUtil {
}
public static long toATechDate(Date date) {
long atechDateTime = 0L;
atechDateTime += (date.getYear() + 1900) * 10000000000L;
atechDateTime += (date.getMonth() + 1) * 100000000L;
atechDateTime += date.getDate() * 1000000L;
atechDateTime += date.getHours() * 10000L;
atechDateTime += date.getMinutes() * 100L;
atechDateTime += date.getSeconds();
return atechDateTime;
}
// public static long toATechDate(Date date) {
//
// long atechDateTime = 0L;
//
// atechDateTime += (date.getYear() + 1900) * 10000000000L;
// atechDateTime += (date.getMonth() + 1) * 100000000L;
// atechDateTime += date.getDate() * 1000000L;
// atechDateTime += date.getHours() * 10000L;
// atechDateTime += date.getMinutes() * 100L;
// atechDateTime += date.getSeconds();
//
// return atechDateTime;
// }
public static String toString(long atechDateTime) {
@ -200,6 +199,7 @@ public class DateTimeUtil {
+ getZeroPrefixed(gc.get(Calendar.SECOND));
}
public static String toStringFromTimeInMillis(long timeInMillis) {
GregorianCalendar gc = new GregorianCalendar();
@ -208,6 +208,7 @@ public class DateTimeUtil {
return toString(gc);
}
private static String getZeroPrefixed(int number) {
return (number < 10) ? "0" + number : "" + number;
}
@ -224,9 +225,11 @@ public class DateTimeUtil {
}
public static boolean isSameDayATDAndMillis(long atechDateTime, long date) {
public static boolean isSameDayATDAndMillis(long atechDateTime, long timeInMillis) {
GregorianCalendar dt = new GregorianCalendar();
dt.setTimeInMillis(timeInMillis);
Date dt = new Date(date);
long entryDate = toATechDate(dt);
return (isSameDay(atechDateTime, entryDate));
@ -235,34 +238,12 @@ public class DateTimeUtil {
public static long toMillisFromATD(long atechDateTime) {
int year = (int) (atechDateTime / 10000000000L);
atechDateTime -= year * 10000000000L;
GregorianCalendar gc = toGregorianCalendar(atechDateTime);
int month = (int) (atechDateTime / 100000000L);
atechDateTime -= month * 100000000L;
int dayOfMonth = (int) (atechDateTime / 1000000L);
atechDateTime -= dayOfMonth * 1000000L;
int hourOfDay = (int) (atechDateTime / 10000L);
atechDateTime -= hourOfDay * 10000L;
int minute = (int) (atechDateTime / 100L);
atechDateTime -= minute * 100L;
int second = (int) atechDateTime;
Date d = new Date();
d.setDate(dayOfMonth);
d.setMonth(month - 1);
d.setYear(year - 1900);
d.setHours(hourOfDay);
d.setMinutes(minute);
d.setSeconds(second);
return d.getTime();
return gc.getTimeInMillis();
}
public static int getATechDateDiferenceAsMinutes(Long date1, Long date2) {
Minutes minutes = Minutes.minutesBetween(toLocalDateTime(date1), toLocalDateTime(date2));

View file

@ -75,6 +75,8 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.SP;
import static info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil.sendNotification;
/**
* Created by andy on 23.04.18.
*
@ -425,12 +427,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
// read time if changed, set new time
hasTimeDateOrTimeZoneChanged = false;
workWithStatusRefresh(StatusRefreshAction.Add, MedtronicStatusRefreshType.PumpTime, 30L);
if (statusRefresh.containsKey(MedtronicStatusRefreshType.PumpTime)) {
statusRefresh.remove(MedtronicStatusRefreshType.PumpTime);
}
}
@ -544,8 +540,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
// time (1h)
checkTimeAndOptionallySetTime();
//medtronicUIComm.executeCommand(MedtronicCommandType.GetRealTimeClock);
scheduleNextRefresh(MedtronicStatusRefreshType.PumpTime, 30);
readPumpHistory();
@ -601,14 +595,27 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
if (medtronicUITask.getResponseType() == MedtronicUIResponseType.Error) {
medtronicUIComm.executeCommand(MedtronicCommandType.GetBasalProfileSTD);
}
}
@Override
public boolean isThisProfileSet(Profile profile) {
LOG.debug("isThisProfileSet: basalInitalized={}", getMDTPumpStatus().basalProfileStatus);
MedtronicPumpStatus mdtPumpStatus = getMDTPumpStatus();
LOG.debug("isThisProfileSet: basalInitalized={}", mdtPumpStatus.basalProfileStatus);
if (!isInitialized)
return true;
if (mdtPumpStatus.basalProfileStatus == BasalProfileStatus.NotInitialized) {
// this shouldn't happen, but if there was problem we try again
getBasalProfiles();
return isProfileSame(profile);
} else if (mdtPumpStatus.basalProfileStatus == BasalProfileStatus.ProfileChanged) {
return false;
} else {
}
return (getMDTPumpStatus().basalProfileStatus != BasalProfileStatus.ProfileOK) || isProfileSame(profile);
}
@ -738,14 +745,22 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
if (timeDiff > 20) {
if (isLoggingEnabled())
LOG.info("MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference is {} s. Set time on pump.", timeDiff);
if ((clock.localDeviceTime.getYear() < 2015) || (timeDiff <= 24 * 60 * 60)) {
medtronicUIComm.executeCommand(MedtronicCommandType.SetRealTimeClock);
if (isLoggingEnabled())
LOG.info("MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference is {} s. Set time on pump.", timeDiff);
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));
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 (timeDiff > 24 * 60 * 60) {
LOG.error("MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference is {}, over 24h requested. Doing nothing.", timeDiff);
sendNotification(MedtronicNotificationType.TimeChangeOver24h);
}
}
} else {
@ -753,6 +768,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
LOG.info("MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference is {} s. Do nothing.", timeDiff);
}
scheduleNextRefresh(MedtronicStatusRefreshType.PumpTime, 0);
}

View file

@ -57,9 +57,8 @@ public class MedtronicUIPostprocessor {
case GetBasalProfileSTD: {
BasalProfile basalProfile = (BasalProfile) uiTask.returnData;
Double[] profilesByHour = basalProfile.getProfilesByHour();
try {
Double[] profilesByHour = basalProfile.getProfilesByHour();
if (profilesByHour != null) {
pumpStatus.basalsByHour = profilesByHour;
@ -67,9 +66,10 @@ public class MedtronicUIPostprocessor {
} else {
uiTask.responseType = MedtronicUIResponseType.Error;
uiTask.errorDescription = "No profile found.";
LOG.error("Basal Profile was NOT valid. [{}]", basalProfile.basalProfileToStringError());
}
} catch (Exception ex) {
LOG.error("Basal Profile was returned, but was invalid.");
LOG.error("Basal Profile was returned, but was invalid. [{}]", basalProfile.basalProfileToStringError());
uiTask.responseType = MedtronicUIResponseType.Error;
uiTask.errorDescription = "No profile found.";
}
@ -115,7 +115,7 @@ public class MedtronicUIPostprocessor {
case GetBatteryStatus: {
BatteryStatusDTO batteryStatusDTO = (BatteryStatusDTO) uiTask.returnData;
pumpStatus.batteryRemaining = (batteryStatusDTO.getCalculatedPercent(pumpStatus.batteryType));
pumpStatus.batteryRemaining = batteryStatusDTO.getCalculatedPercent(pumpStatus.batteryType);
if (batteryStatusDTO.voltage != null) {
pumpStatus.batteryVoltage = batteryStatusDTO.voltage;

View file

@ -1220,7 +1220,7 @@ public class MedtronicHistoryData {
List<PumpHistoryEntry> filteredItems = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile);
if (isLogEnabled())
LOG.debug("hasBasalProfileChanged. Items: " + filteredItems);
LOG.debug("hasBasalProfileChanged. Items: " + gson.toJson(filteredItems));
return (filteredItems.size() > 0);
}
@ -1253,6 +1253,7 @@ public class MedtronicHistoryData {
if (isLogEnabled())
LOG.debug("processLastBasalProfileChange. item found, setting new basalProfileLocally: " + newProfile);
BasalProfile basalProfile = (BasalProfile) newProfile.getDecodedData().get("Object");
mdtPumpStatus.basalsByHour = basalProfile.getProfilesByHour();
}
}

View file

@ -140,6 +140,10 @@ public class BasalProfile {
return sb.toString();
}
public String basalProfileToStringError() {
return "Basal Profile [rawData=" + ByteUtil.shortHexString(this.getRawData()) + "]";
}
public String basalProfileToString() {
StringBuffer sb = new StringBuffer("Basal Profile [");

View file

@ -14,7 +14,7 @@ public enum BatteryType {
None(R.string.medtronic_pump_battery_no, 0, 0),
Alkaline(R.string.medtronic_pump_battery_alkaline, 1.20d, 1.47d), //
Lithium(R.string.medtronic_pump_battery_lithium, 1.25d, 1.64d);
Lithium(R.string.medtronic_pump_battery_lithium, 1.22d, 1.64d);
private final String description;
public double lowVoltage;

View file

@ -18,6 +18,7 @@ public enum MedtronicNotificationType {
PumpWrongMaxBasalSet(R.string.medtronic_error_pump_wrong_max_basal_set, Notification.NORMAL), //
PumpWrongTimeUrgent(R.string.combo_notification_check_time_date, Notification.URGENT),
PumpWrongTimeNormal(R.string.combo_notification_check_time_date, Notification.NORMAL),
TimeChangeOver24h(Notification.OVER_24H_TIME_CHANGE_REQUESTED, R.string.medtronic_error_pump_24h_time_change_requested, Notification.URGENT),
//
;

View file

@ -1,15 +1,15 @@
package info.nightscout.androidaps.plugins.pump.medtronic.driver;
import org.joda.time.LocalDateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import org.joda.time.LocalDateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PumpDescription;
@ -75,7 +75,7 @@ public class MedtronicPumpStatus extends PumpStatus {
private Map<String, PumpType> medtronicPumpMap = null;
private Map<String, MedtronicDeviceType> medtronicDeviceTypeMap = null;
private RileyLinkTargetFrequency targetFrequency;
public BasalProfileStatus basalProfileStatus;
public BasalProfileStatus basalProfileStatus = BasalProfileStatus.NotInitialized;
public BatteryType batteryType = BatteryType.None;
@ -255,7 +255,7 @@ public class MedtronicPumpStatus extends PumpStatus {
String encodingTypeStr = SP.getString(MedtronicConst.Prefs.Encoding, null);
if (encodingTypeStr==null) {
if (encodingTypeStr == null) {
return false;
}
@ -270,7 +270,7 @@ public class MedtronicPumpStatus extends PumpStatus {
String batteryTypeStr = SP.getString(MedtronicConst.Prefs.BatteryType, null);
if (batteryTypeStr==null)
if (batteryTypeStr == null)
return false;
BatteryType batteryType = BatteryType.getByDescription(batteryTypeStr);