diff --git a/app/build.gradle b/app/build.gradle index 3f51dcfb93..e396f2749a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -105,14 +105,14 @@ android { multiDexEnabled true versionCode 1500 // dev_version: 2.3.1-dev - version "medtronic-0.10.3-SNAPSHOT" + version "medtronic-0.10.4-SNAPSHOT" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"' buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' buildConfigField "String", "DEV_VERSION", '"2.3.1-dev"' - buildConfigField "String", "DEV_DATE", '"2.5.2019"' - buildConfigField "String", "DEV_CHECKIN", '"75d469a9db4bad6c619de8d36006e935c12b6ff1"' + buildConfigField "String", "DEV_DATE", '"31.5.2019"' + buildConfigField "String", "DEV_CHECKIN", '"e61cbecb2e9f568f6216533034e75733fecb8a36"' testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" // if you change minSdkVersion to less than 11, you need to change executeTask for wear diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 08c9f1ad97..9d0dd1eb41 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -156,7 +156,7 @@ public class MainApp extends Application { File engineeringModeSemaphore = new File(extFilesDir, "engineering_mode"); engineeringMode = engineeringModeSemaphore.exists() && engineeringModeSemaphore.isFile(); - devBranch = BuildConfig.VERSION.contains("-") || BuildConfig.VERSION.matches(".*[a-zA-Z]+.*"); + devBranch = BuildConfig.VERSION.contains("dev"); sBus = L.isEnabled(L.EVENTS) && devBranch ? new LoggingBus(ThreadEnforcer.ANY) : new Bus(ThreadEnforcer.ANY); @@ -186,11 +186,9 @@ public class MainApp extends Application { if (Config.PUMPDRIVERS) pluginsList.add(LocalInsightPlugin.getPlugin()); pluginsList.add(CareportalPlugin.getPlugin()); if (Config.PUMPDRIVERS) pluginsList.add(ComboPlugin.getPlugin()); + if (Config.PUMPDRIVERS) pluginsList.add(MedtronicPumpPlugin.getPlugin()); if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin()); pluginsList.add(VirtualPumpPlugin.getPlugin()); - if (Config.PUMPDRIVERS && engineeringMode) { - pluginsList.add(MedtronicPumpPlugin.getPlugin()); - } if (Config.APS) pluginsList.add(LoopPlugin.getPlugin()); if (Config.APS) pluginsList.add(OpenAPSMAPlugin.getPlugin()); if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtils.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtils.kt index 8791030abb..54ef1a8b8c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtils.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtils.kt @@ -57,7 +57,7 @@ private fun checkVersion() = if (isConnected()) { val request = HttpGet("https://raw.githubusercontent.com/MilosKozak/AndroidAPS/master/app/build.gradle") val response: HttpResponse = DefaultHttpClient().execute(request) val version: String? = response.entity.content?.findVersion() - compareWithCurrentVersion(version, BuildConfig.VERSION_NAME) + compareWithCurrentVersion(version, BuildConfig.DEV_VERSION) } catch (e: IOException) { log.debug("Github master version check error: $e") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.java index d7b8195e36..a25caeebd7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.java @@ -30,6 +30,8 @@ public abstract class PumpStatus { public double reservoirRemainingUnits = 0d; public String reservoirFullUnits = "???"; public int batteryRemaining = 0; // percent, so 0-100 + public Double batteryVoltage = null; + // iob public String iob = null; @@ -42,15 +44,7 @@ public abstract class PumpStatus { public ProfileStore profileStore; public String units; // Constants.MGDL or Constants.MMOL public PumpStatusType pumpStatusType = PumpStatusType.Running; - // TODO maybe not needed anymore in 2.0 - public Double constraintBasalRateAbsolute; - public Integer constraintBasalRatePercent; - public Double constraintBolus; - public Integer constraintCarbs; - public Double constraintMaxIob; public Double[] basalsByHour; - // public double remainUnits = 0; - public int remainBattery = 0; public double currentBasal = 0; public int tempBasalInProgress = 0; public int tempBasalRatio = 0; @@ -66,20 +60,6 @@ public abstract class PumpStatus { } - // FIXME cleanup this is from RT2 - - // 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 abstract void initSettings(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java index d7836b0968..69837afd7c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java @@ -237,8 +237,9 @@ public abstract class RileyLinkCommunicationManager { radioResponse.init(resp.getRaw()); if (radioResponse.isValid()) { - sumRSSI += calculateRssi(radioResponse.rssi); - trial.rssiList.add(radioResponse.rssi); + int rssi = calculateRssi(radioResponse.rssi); + sumRSSI += rssi; + trial.rssiList.add(rssi); trial.successes++; } else { LOG.warn("Failed to parse radio response: " + ByteUtil.shortHexString(resp.getRaw())); @@ -272,8 +273,7 @@ public abstract class RileyLinkCommunicationManager { FrequencyTrial one = results.trials.get(k); stringBuilder.append(String.format("Scan Result[%s]: Freq=%s, avg RSSI = %s\n", "" + k, "" - + one.frequencyMHz, "" + one.averageRSSI + ", RSSIs =" + one.rssiList + ", averageRSSI_Old=" - + one.averageRSSI2)); + + one.frequencyMHz, "" + one.averageRSSI + ", RSSIs =" + one.rssiList)); } LOG.info(stringBuilder.toString()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/RadioResponse.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/RadioResponse.java index 3f26e6ff40..646d7aac9a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/RadioResponse.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/RadioResponse.java @@ -72,15 +72,17 @@ public class RadioResponse { // This does not look like something valid heard from a RileyLink device return; } - rssi = rxData[0]; - responseNumber = rxData[1]; byte[] encodedPayload; if (RileyLinkFirmwareVersion.isSameVersion(RileyLinkUtil.getRileyLinkServiceData().versionCC110, RileyLinkFirmwareVersion.Version2)) { encodedPayload = ByteUtil.substring(rxData, 3, rxData.length - 3); + rssi = rxData[1]; + responseNumber = rxData[2]; } else { encodedPayload = ByteUtil.substring(rxData, 2, rxData.length - 2); + rssi = rxData[0]; + responseNumber = rxData[1]; } try { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.java index d68cdd0296..8cfb400201 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.java @@ -10,6 +10,7 @@ import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.os.Handler; +import android.os.SystemClock; import android.text.Spanned; import android.view.LayoutInflater; import android.view.View; @@ -34,11 +35,13 @@ import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.common.SubscriberFragment; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.overview.dialogs.MessageHelperActivity; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity; +import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState; import info.nightscout.androidaps.plugins.pump.medtronic.dialog.MedtronicHistoryActivity; @@ -148,12 +151,22 @@ public class MedtronicFragment extends SubscriberFragment { @OnClick(R.id.medtronic_history) void onHistoryClick() { - startActivity(new Intent(getContext(), MedtronicHistoryActivity.class)); + if (MedtronicUtil.getPumpStatus().verifyConfiguration()) { + startActivity(new Intent(getContext(), MedtronicHistoryActivity.class)); + } else { + MedtronicUtil.displayNotConfiguredDialog(); + } } @OnClick(R.id.medtronic_refresh) void onRefreshClick() { + + if (!MedtronicUtil.getPumpStatus().verifyConfiguration()) { + MedtronicUtil.displayNotConfiguredDialog(); + return; + } + if (refreshButtonStatic != null) refreshButtonStatic.setEnabled(false); @@ -178,13 +191,17 @@ public class MedtronicFragment extends SubscriberFragment { @OnClick(R.id.medtronic_stats) void onStatsClick() { - startActivity(new Intent(getContext(), RileyLinkStatusActivity.class)); + if (MedtronicUtil.getPumpStatus().verifyConfiguration()) { + startActivity(new Intent(getContext(), RileyLinkStatusActivity.class)); + } else { + MedtronicUtil.displayNotConfiguredDialog(); + } } @Subscribe public void onStatusEvent(final EventPumpStatusChanged c) { - + updateGUI(); } @@ -481,8 +498,12 @@ public class MedtronicFragment extends SubscriberFragment { } // battery - batteryView.setText("{fa-battery-" + (pumpStatus.batteryRemaining / 25) + "} " + pumpStatus.batteryRemaining + "%"); - SetWarnColor.setColorInverse(batteryView, pumpStatus.batteryRemaining, 51d, 26d); + if (MedtronicUtil.getBatteryType()== BatteryType.None || pumpStatus.batteryVoltage==null) { + batteryView.setText("{fa-battery-" + (pumpStatus.batteryRemaining / 25) + "} "); + } else { + batteryView.setText("{fa-battery-" + (pumpStatus.batteryRemaining / 25) + "} " + pumpStatus.batteryRemaining + "%" + String.format(" (%.2f V)", pumpStatus.batteryVoltage)); + } + SetWarnColor.setColorInverse(batteryView, pumpStatus.batteryRemaining, 25d, 10d); // reservoir reservoirView.setText(DecimalFormatter.to0Decimal(pumpStatus.reservoirRemainingUnits) + " / " diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java index 527de8c68c..88bc56a85e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java @@ -66,6 +66,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandTy import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCustomActionType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicNotificationType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicStatusRefreshType; +import info.nightscout.androidaps.plugins.pump.medtronic.dialog.MedtronicHistoryActivity; import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus; import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpValuesChanged; import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService; @@ -1415,9 +1416,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter switch (mcat) { - case WakeUpAndTune: - ServiceTaskExecutor.startTask(new WakeAndTuneTask()); - break; + case WakeUpAndTune: { + if (MedtronicUtil.getPumpStatus().verifyConfiguration()) { + ServiceTaskExecutor.startTask(new WakeAndTuneTask()); + } else { + MedtronicUtil.displayNotConfiguredDialog(); + } + } break; case ClearBolusBlock: { this.busyTimestamps.clear(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverter.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverter.java index 132221b527..f8404540d9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverter.java @@ -175,17 +175,7 @@ public class MedtronicConverter { double d = (ByteUtil.toInt(rawData[1], rawData[2])*1.0d) / 100.0d; batteryStatus.voltage = d; - - // double perc = (d - BatteryType.Alkaline.lowVoltage) / (BatteryType.Alkaline.highVoltage - - // BatteryType.Alkaline.lowVoltage); - // - // LOG.warn("Percent status: " + perc); - // LOG.warn("Unknown status: " + rawData[0]); - // LOG.warn("Full result: " + d); - // - // int percent = (int) (perc * 100.0d); - - // return percent; + batteryStatus.extendedDataReceived = true; } return batteryStatus; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java index 33aed92cf8..3fb2b6d6e0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java @@ -186,10 +186,8 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder tdds = filterTDDs(tddsIn); - LOG.error(getLogPrefix() + "TDDs found: {}.\n{}", tdds.size(), gsonPretty.toJson(tdds)); + if (isLogEnabled()) + LOG.debug(getLogPrefix() + "TDDs found: {}.\n{}", tdds.size(), gsonPretty.toJson(tdds)); List tddsDb = databaseHelper.getTDDsForLastXDays(3); @@ -509,6 +510,12 @@ public class MedtronicHistoryData { TempBasalPair tbr = (TempBasalPair) treatment.getDecodedDataEntry("Object"); + if (!tbr.isCancelTBR()) { + + } else { + + } + boolean isPossibleCancel = false; if (tbr.getInsulinRate() > 0.0d) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java index 067041fce4..0e8b3e093c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java @@ -12,8 +12,11 @@ public class BatteryStatusDTO { @Expose public BatteryStatusType batteryStatusType; + @Expose public Double voltage; + public boolean extendedDataReceived = false; + public int getCalculatedPercent(BatteryType batteryType) { if (voltage==null || batteryType==BatteryType.None) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/DailyTotalsDTO.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/DailyTotalsDTO.java index c5d163ee8c..5a08899760 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/DailyTotalsDTO.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/DailyTotalsDTO.java @@ -4,6 +4,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.base.MoreObjects; +import com.google.gson.annotations.Expose; import info.nightscout.androidaps.db.TDD; import info.nightscout.androidaps.logging.L; @@ -40,8 +41,11 @@ public class DailyTotalsDTO { private Integer sensorCalcCount; private Integer sensorDataCount; + @Expose private Double insulinTotal = 0.0d; + @Expose private Double insulinBasal = 0.0d; + @Expose private Double insulinBolus = 0.0d; private Double insulinCarbs; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TemporaryBasalRateDTO.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TemporaryBasalRateDTO.java deleted file mode 100644 index 870271d998..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TemporaryBasalRateDTO.java +++ /dev/null @@ -1,111 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.medtronic.data.dto; - -import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil; - -/** - * Application: GGC - GNU Gluco Control - * Plug-in: Pump Tool (support for Pump devices) - *

- * See AUTHORS for copyright information. - *

- * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later - * version. - *

- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - *

- * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free - * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - *

- * Filename: BolusDTO Description: Bolus DTO - *

- * Author: Andy {andy@atech-software.com} - */ -@Deprecated -public class TemporaryBasalRateDTO extends PumpTimeStampedRecord { - - private Float amount; - private TBRUnit unit = TBRUnit.Percent; // percent, U - private Integer duration; // min - - - // private ATechDate aTechDate; - - public TemporaryBasalRateDTO() { - // this.decimalPrecission = 2; - } - - - public Integer getDuration() { - return duration; - } - - - public void setDuration(Integer duration) { - this.duration = duration; - } - - - private String getDurationString() { - int minutes = this.duration; - - int h = minutes / 60; - - minutes -= (h * 60); - - return StringUtil.getLeadingZero(h, 2) + ":" + StringUtil.getLeadingZero(minutes, 2); - } - - - public String getValue() { - float val = amount; - String sign = ""; - - if (val < 0) { - sign = "-"; - val *= -1; - } - - return String.format("TBR_VALUE=%s%s;TBR_UNIT=%s;DURATION=%s", sign, getFormattedDecimal(val), getUnit() - .getDescription(), getDurationString()); - } - - - public Float getAmount() { - return amount; - } - - - public void setAmount(Float amount) { - this.amount = amount; - } - - - public TBRUnit getUnit() { - return unit; - } - - - public void setUnit(TBRUnit unit) { - this.unit = unit; - } - - public enum TBRUnit { - Percent("%"), // - Unit("U"); - - String unit; - - - TBRUnit(String unit) { - this.unit = unit; - } - - - public String getDescription() { - return unit; - } - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java index 0a6c366a27..93cfe1e75a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java @@ -139,7 +139,7 @@ public class MedtronicPumpStatus extends PumpStatus { } - public void verifyConfiguration() { + public boolean verifyConfiguration() { try { // FIXME don't reload information several times @@ -155,11 +155,11 @@ public class MedtronicPumpStatus extends PumpStatus { if (serialNr == null) { this.errorDescription = MainApp.gs(R.string.medtronic_error_serial_not_set); - return; + return false; } else { if (!serialNr.matches(regexSN)) { this.errorDescription = MainApp.gs(R.string.medtronic_error_serial_invalid); - return; + return false; } else { if (!serialNr.equals(this.serialNumber)) { this.serialNumber = serialNr; @@ -172,13 +172,13 @@ public class MedtronicPumpStatus extends PumpStatus { if (pumpType == null) { this.errorDescription = MainApp.gs(R.string.medtronic_error_pump_type_not_set); - return; + return false; } else { String pumpTypePart = pumpType.substring(0, 3); if (!pumpTypePart.matches("[0-9]{3}")) { this.errorDescription = MainApp.gs(R.string.medtronic_error_pump_type_invalid); - return; + return false; } else { this.pumpType = medtronicPumpMap.get(pumpTypePart); this.medtronicDeviceType = medtronicDeviceTypeMap.get(pumpTypePart); @@ -194,11 +194,11 @@ public class MedtronicPumpStatus extends PumpStatus { if (pumpFrequency == null) { this.errorDescription = MainApp.gs(R.string.medtronic_error_pump_frequency_not_set); - return; + return false; } else { if (!pumpFrequency.equals(frequencies[0]) && !pumpFrequency.equals(frequencies[1])) { this.errorDescription = MainApp.gs(R.string.medtronic_error_pump_frequency_invalid); - return; + return false; } else { this.pumpFrequency = pumpFrequency; this.isFrequencyUS = pumpFrequency.equals(frequencies[0]); @@ -222,7 +222,7 @@ public class MedtronicPumpStatus extends PumpStatus { if (isLogEnabled()) LOG.debug("RileyLink address invalid: null"); this.errorDescription = MainApp.gs(R.string.medtronic_error_rileylink_address_invalid); - return; + return false; } else { if (!rileyLinkAddress.matches(regexMac)) { this.errorDescription = MainApp.gs(R.string.medtronic_error_rileylink_address_invalid); @@ -255,6 +255,10 @@ public class MedtronicPumpStatus extends PumpStatus { String encodingTypeStr = SP.getString(MedtronicConst.Prefs.Encoding, null); + if (encodingTypeStr==null) { + return false; + } + RileyLinkEncodingType newEncodingType = RileyLinkEncodingType.getByDescription(encodingTypeStr); if (this.encodingType == null) { @@ -266,17 +270,24 @@ public class MedtronicPumpStatus extends PumpStatus { String batteryTypeStr = SP.getString(MedtronicConst.Prefs.BatteryType, null); + if (batteryTypeStr==null) + return false; + BatteryType batteryType = BatteryType.getByDescription(batteryTypeStr); if (this.batteryType != batteryType) { this.batteryType = batteryType; + MedtronicUtil.setBatteryType(this.batteryType); } reconfigureService(); + return true; + } catch (Exception ex) { this.errorDescription = ex.getMessage(); LOG.error("Error on Verification: " + ex.getMessage(), ex); + return false; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.java index 6eb676a66a..73d63dac9f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.medtronic.util; +import android.content.Intent; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -14,7 +16,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.general.overview.dialogs.MessageHelperActivity; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; @@ -27,6 +31,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunica import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.ClockDTO; import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.PumpSettingDTO; +import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicNotificationType; @@ -57,6 +62,7 @@ public class MedtronicUtil extends RileyLinkUtil { public static Gson gsonInstance = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); public static Gson gsonInstancePretty = new GsonBuilder().excludeFieldsWithoutExposeAnnotation() .setPrettyPrinting().create(); + private static BatteryType batteryType = BatteryType.None; public static Gson getGsonInstance() { @@ -506,4 +512,27 @@ public class MedtronicUtil extends RileyLinkUtil { public static ClockDTO getPumpTime() { return MedtronicUtil.pumpTime; } + + public static void setBatteryType(BatteryType batteryType) { + MedtronicUtil.batteryType = batteryType; + } + + + public static BatteryType getBatteryType() { + return MedtronicUtil.batteryType; + } + + + public static void displayNotConfiguredDialog() { + new Thread(() -> { + + Intent i = new Intent(MainApp.instance(), MessageHelperActivity.class); + i.putExtra("status", MainApp.gs(R.string.medtronic_error_operation_not_possible_no_configuration)); + i.putExtra("title", MainApp.gs(R.string.combo_warning)); + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + MainApp.instance().startActivity(i); + + }).start(); + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java index 6cbf2594e3..0cf67efa25 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java @@ -290,7 +290,7 @@ public class TreatmentService extends OrmLiteBaseService { } } catch (SQLException e) { - log.error("Unhandled exception", e); + log.error("Unhandled SQL exception: {}", e.getMessage(), e); } return new UpdateReturn(false, false); } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntryUTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntryUTest.java index e5da941848..0d1c437560 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntryUTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntryUTest.java @@ -3,6 +3,8 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump; import org.junit.Assert; import org.junit.Test; +import java.util.Date; + /** * Created by andy on 4/9/19. */ @@ -20,4 +22,29 @@ public class PumpHistoryEntryUTest { Assert.assertTrue(phe.isAfter(queryObject)); } + @Test + public void testDatesTDD() { + long[] data = { 1557010799726L, + 1557010799651L, + 1557010799393L, + 1557010799289L, + 1557010799109L, + 1556924400709L, + 1556924400521L, + 1556924400353L, + 1556924399948L, + 1556924399910L }; + + for (long datum : data) { + Date d = new Date(); + d.setTime(datum); + + System.out.println("Date: " + d); + } + + + + + } + }