From 538e8fd2fa219d277da31749f67abe63d5302f75 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 28 Jan 2017 20:48:32 +0100 Subject: [PATCH 1/2] better detect & display old pump firmware --- .../plugins/DanaR/DanaRFragment.java | 37 +++++++++------ .../androidaps/plugins/DanaR/DanaRPump.java | 2 +- .../plugins/DanaR/SerialIOThread.java | 8 ++++ .../DanaR/Services/ExecutionService.java | 14 ++++-- .../DanaR/comm/MsgSettingShippingInfo.java | 5 -- app/src/main/res/layout/danar_fragment.xml | 47 +++++++++++++++---- app/src/main/res/values/strings.xml | 2 + 7 files changed, 79 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java index b7fae2a125..a3d162e7e7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java @@ -63,6 +63,7 @@ public class DanaRFragment extends Fragment implements FragmentBase { TextView batteryView; TextView reservoirView; TextView iobView; + TextView firmwareView; Button viewProfileButton; Button historyButton; @@ -103,6 +104,7 @@ public class DanaRFragment extends Fragment implements FragmentBase { batteryView = (TextView) view.findViewById(R.id.danar_battery); reservoirView = (TextView) view.findViewById(R.id.danar_reservoir); iobView = (TextView) view.findViewById(R.id.danar_iob); + firmwareView = (TextView) view.findViewById(R.id.danar_firmware); viewProfileButton = (Button) view.findViewById(R.id.danar_viewprofile); historyButton = (Button) view.findViewById(R.id.danar_history); @@ -194,24 +196,24 @@ public class DanaRFragment extends Fragment implements FragmentBase { @SuppressLint("SetTextI18n") @Override public void run() { - - if (DanaRPlugin.getDanaRPump().lastConnection.getTime() != 0) { - Long agoMsec = new Date().getTime() - DanaRPlugin.getDanaRPump().lastConnection.getTime(); + DanaRPump pump = DanaRPlugin.getDanaRPump(); + if (pump.lastConnection.getTime() != 0) { + Long agoMsec = new Date().getTime() - pump.lastConnection.getTime(); int agoMin = (int) (agoMsec / 60d / 1000d); - lastConnectionView.setText(DateUtil.timeString(DanaRPlugin.getDanaRPump().lastConnection) + " (" + String.format(MainApp.sResources.getString(R.string.minago), agoMin) + ")"); + lastConnectionView.setText(DateUtil.timeString(pump.lastConnection) + " (" + String.format(MainApp.sResources.getString(R.string.minago), agoMin) + ")"); SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d); } - if (DanaRPlugin.getDanaRPump().lastBolusTime.getTime() != 0) { - Long agoMsec = new Date().getTime() - DanaRPlugin.getDanaRPump().lastBolusTime.getTime(); + if (pump.lastBolusTime.getTime() != 0) { + Long agoMsec = new Date().getTime() - pump.lastBolusTime.getTime(); double agoHours = agoMsec / 60d / 60d / 1000d; if (agoHours < 6) // max 6h back - lastBolusView.setText(DateUtil.timeString(DanaRPlugin.getDanaRPump().lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(getPlugin().getDanaRPump().lastBolusAmount) + " U"); + lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(getPlugin().getDanaRPump().lastBolusAmount) + " U"); else lastBolusView.setText(""); } - dailyUnitsView.setText(DecimalFormatter.to0Decimal(DanaRPlugin.getDanaRPump().dailyTotalUnits) + " / " + DanaRPlugin.getDanaRPump().maxDailyTotalUnits + " U"); - SetWarnColor.setColor(dailyUnitsView, DanaRPlugin.getDanaRPump().dailyTotalUnits, DanaRPlugin.getDanaRPump().maxDailyTotalUnits * 0.75d, DanaRPlugin.getDanaRPump().maxDailyTotalUnits * 0.9d); - basaBasalRateView.setText("( " + (DanaRPlugin.getDanaRPump().activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h"); + dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U"); + SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d); + basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h"); if (getPlugin().isRealTempBasalInProgress()) { tempBasalView.setText(getPlugin().getRealTempBasal().toString()); } else { @@ -222,11 +224,16 @@ public class DanaRFragment extends Fragment implements FragmentBase { } else { extendedBolusView.setText(""); } - reservoirView.setText(DecimalFormatter.to0Decimal(DanaRPlugin.getDanaRPump().reservoirRemainingUnits) + " / 300 U"); - SetWarnColor.setColorInverse(reservoirView, DanaRPlugin.getDanaRPump().reservoirRemainingUnits, 50d, 20d); - batteryView.setText("{fa-battery-" + (DanaRPlugin.getDanaRPump().batteryRemaining / 25) + "}"); - SetWarnColor.setColorInverse(batteryView, DanaRPlugin.getDanaRPump().batteryRemaining, 51d, 26d); - iobView.setText(DanaRPlugin.getDanaRPump().iob + " U"); + reservoirView.setText(DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + " / 300 U"); + SetWarnColor.setColorInverse(reservoirView, pump.reservoirRemainingUnits, 50d, 20d); + batteryView.setText("{fa-battery-" + (pump.batteryRemaining / 25) + "}"); + SetWarnColor.setColorInverse(batteryView, pump.batteryRemaining, 51d, 26d); + iobView.setText(pump.iob + " U"); + if (pump.isNewPump) { + firmwareView.setText(String.format(getString(R.string.danar_model), pump.model, pump.protocol, pump.productCode)); + } else { + firmwareView.setText("OLD"); + } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java index 535b80a296..50a29eb050 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java @@ -36,7 +36,7 @@ public class DanaRPump { public String serialNumber = ""; public Date shippingDate = new Date(0); public String shippingCountry = ""; - public boolean isNewPump = false; + public boolean isNewPump = true; public int password = -1; public Date pumpTime = new Date(0); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/SerialIOThread.java index f4fc489d0c..aff6dc31ed 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/SerialIOThread.java @@ -77,6 +77,10 @@ public class SerialIOThread extends Thread { if (Config.logDanaMessageDetail) log.debug("<<<<< " + message.getMessageName() + " " + message.toHexString(extractedBuff)); + if (message.getCommand() == 0xF0F1) { + DanaRPlugin.getDanaRPump().isNewPump = true; + log.debug("New firmware confirmed"); + } // process the message content message.received = true; @@ -176,6 +180,10 @@ public class SerialIOThread extends Thread { } if (!message.received) { log.warn("Reply not received " + message.getMessageName()); + if (message.getCommand() == 0xF0F1) { + DanaRPlugin.getDanaRPump().isNewPump = false; + log.debug("Old firmware detected"); + } } scheduleDisconnection(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java index 66acc7292e..e201d0f9f4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java @@ -226,6 +226,7 @@ public class ExecutionService extends Service { if (!getPumpStatus()) { mSerialIOThread.disconnect("getPumpStatus failed"); waitMsec(3000); + getBTSocketForSelectedPump(); } } } @@ -276,18 +277,21 @@ public class ExecutionService extends Service { MsgStatusBasic statusBasicMsg = new MsgStatusBasic(); MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal(); MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended(); + MsgCheckValue checkValue = new MsgCheckValue(); - mSerialIOThread.sendMessage(new MsgSettingShippingInfo()); // TODO: show it somewhere + if (danaRPump.isNewPump) { + mSerialIOThread.sendMessage(checkValue); + if (!checkValue.received) { + return false; + } + } + mSerialIOThread.sendMessage(tempStatusMsg); // do this before statusBasic because here is temp duration mSerialIOThread.sendMessage(exStatusMsg); mSerialIOThread.sendMessage(statusMsg); mSerialIOThread.sendMessage(statusBasicMsg); - if (danaRPump.isNewPump) { - mSerialIOThread.sendMessage(new MsgCheckValue()); - } - if (!statusMsg.received) { mSerialIOThread.sendMessage(statusMsg); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingShippingInfo.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingShippingInfo.java index 66b14e4b80..faa68c5eb7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingShippingInfo.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingShippingInfo.java @@ -24,15 +24,10 @@ public class MsgSettingShippingInfo extends MessageBase { pump.serialNumber = stringFromBuff(bytes, 0, 10); pump.shippingDate = dateFromBuff(bytes, 10); pump.shippingCountry = asciiStringFromBuff(bytes, 13, 3); - if (pump.shippingDate.getTime() > new Date(116, 4, 1).getTime()) { - pump.isNewPump = true; - } else - pump.isNewPump = false; if (Config.logDanaMessageDetail) { log.debug("Serial number: " + pump.serialNumber); log.debug("Shipping date: " + pump.shippingDate); log.debug("Shipping country: " + pump.shippingCountry); - log.debug("Is new pump: " + pump.isNewPump); } } } diff --git a/app/src/main/res/layout/danar_fragment.xml b/app/src/main/res/layout/danar_fragment.xml index 00463f5dd0..051bcf55e3 100644 --- a/app/src/main/res/layout/danar_fragment.xml +++ b/app/src/main/res/layout/danar_fragment.xml @@ -252,23 +252,50 @@ + android:layout_height="wrap_content" + android:layout_marginTop="10dp" + android:orientation="horizontal"> + + + + + + + +