diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java index f392485f4b..d1e1b8ba6a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java @@ -58,6 +58,7 @@ public class DanaRFragment extends SubscriberFragment { TextView firmwareView; TextView basalStepView; TextView bolusStepView; + TextView serialNumberView; Button viewProfileButton; Button historyButton; Button statsButton; @@ -106,6 +107,7 @@ public class DanaRFragment extends SubscriberFragment { statsButton = (Button) view.findViewById(R.id.danar_stats); basalStepView = (TextView) view.findViewById(R.id.danar_basalstep); bolusStepView = (TextView) view.findViewById(R.id.danar_bolusstep); + serialNumberView = (TextView) view.findViewById(R.id.danar_serialnumber); viewProfileButton.setOnClickListener(new View.OnClickListener() { @@ -242,6 +244,7 @@ public class DanaRFragment extends SubscriberFragment { } basalStepView.setText("" + pump.basalStep); bolusStepView.setText("" + pump.bolusStep); + serialNumberView.setText("" + pump.serialNumber); } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java index a6145302ad..d05777d20d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java @@ -37,7 +37,7 @@ public class DanaRS_Packet_General_Initial_Screen_Information extends DanaRS_Pac dataIndex += dataSize; dataSize = 2; - pump.maxDailyTotalUnits = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + pump.maxDailyTotalUnits = (int) (byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d); dataIndex += dataSize; dataSize = 2; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java index 3687601a42..2daf21ffdd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java @@ -64,6 +64,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Se import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Stop; +import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_General_Get_Pump_Check; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_General_Get_Shipping_Information; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_General_Initial_Screen_Information; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_; @@ -141,7 +142,8 @@ public class DanaRSService extends Service { Date now = new Date(); if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !MainApp.getSpecificPlugin(DanaRSPlugin.class).isInitialized()) { - sendMessage(new DanaRS_Packet_General_Get_Shipping_Information()); + sendMessage(new DanaRS_Packet_General_Get_Shipping_Information()); // serial no + sendMessage(new DanaRS_Packet_General_Get_Pump_Check()); // firmware sendMessage(new DanaRS_Packet_Basal_Get_Profile_Number()); sendMessage(new DanaRS_Packet_Bolus_Get_Bolus_Option()); // isExtendedEnabled sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // bolusStep, maxBolus @@ -259,6 +261,7 @@ public class DanaRSService extends Service { } MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal))); sendMessage(new DanaRS_Packet_Basal_Set_Temporary_Basal(percent, durationInHours)); + SystemClock.sleep(200); sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State()); loadEvents(); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); @@ -283,6 +286,7 @@ public class DanaRSService extends Service { if (!isConnected()) return false; MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus))); sendMessage(new DanaRS_Packet_Bolus_Set_Extended_Bolus(insulin, durationInHalfHours)); + SystemClock.sleep(200); sendMessage(new DanaRS_Packet_Bolus_Get_Extended_Bolus_State()); loadEvents(); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); @@ -626,6 +630,7 @@ public class DanaRSService extends Service { while (isProcessing) { int length = 0; + byte[] inputBuffer = null; synchronized (readBuffer) { // Find packet start [A5 A5] if (bufferLength >= 6) { @@ -655,10 +660,8 @@ public class DanaRSService extends Service { packetIsValid = true; } } - } - if (packetIsValid) { - byte[] inputBuffer = new byte[length + 7]; - synchronized (readBuffer) { + if (packetIsValid) { + inputBuffer = new byte[length + 7]; // copy packet to input buffer System.arraycopy(readBuffer, 0, inputBuffer, 0, length + 7); // Cut off the message from readBuffer @@ -669,8 +672,10 @@ public class DanaRSService extends Service { throw e; } bufferLength -= (length + 7); + // now we have encrypted packet in inputBuffer } - // now we have encrypted packet in inputBuffer + } + if (packetIsValid) { try { // decrypt the packet inputBuffer = BleCommandUtil.getInstance().getDecryptedPacket(inputBuffer); diff --git a/app/src/main/res/layout/danar_fragment.xml b/app/src/main/res/layout/danar_fragment.xml index 82af40b141..2e8639ecad 100644 --- a/app/src/main/res/layout/danar_fragment.xml +++ b/app/src/main/res/layout/danar_fragment.xml @@ -5,604 +5,666 @@ tools:context="info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment"> - + android:layout_height="match_parent"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + + + diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml index 413350d6eb..e93062fe52 100644 --- a/app/src/main/res/layout/overview_fragment.xml +++ b/app/src/main/res/layout/overview_fragment.xml @@ -17,7 +17,7 @@ Bolus speed danars_bolusspeed Set basal step to 0.01 U/h + Serial number