From 7b0bc81c476d9ff7a8253ab844fb6cea091bfdbe Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 24 Mar 2020 09:01:10 +0100 Subject: [PATCH 01/53] Upgrade RS encryption library --- .gitignore | 1 - app/build.gradle | 26 - .../plugins/pump/danaRS/DanaRSPlugin.java | 4 +- .../pump/danaRS/comm/DanaRS_Packet.java | 5 +- ...RS_Packet_APS_Basal_Set_Temporary_Basal.kt | 4 +- .../comm/DanaRS_Packet_APS_History_Events.kt | 4 +- .../DanaRS_Packet_APS_Set_Event_History.kt | 4 +- .../DanaRS_Packet_Basal_Get_Basal_Rate.kt | 4 +- ...aRS_Packet_Basal_Get_Profile_Basal_Rate.kt | 4 +- .../DanaRS_Packet_Basal_Get_Profile_Number.kt | 4 +- ..._Packet_Basal_Get_Temporary_Basal_State.kt | 4 +- .../DanaRS_Packet_Basal_Set_Basal_Rate.kt | 4 +- ...Packet_Basal_Set_Cancel_Temporary_Basal.kt | 4 +- ...aRS_Packet_Basal_Set_Profile_Basal_Rate.kt | 4 +- .../DanaRS_Packet_Basal_Set_Profile_Number.kt | 4 +- .../DanaRS_Packet_Basal_Set_Suspend_Off.kt | 4 +- .../DanaRS_Packet_Basal_Set_Suspend_On.kt | 4 +- ...DanaRS_Packet_Basal_Set_Temporary_Basal.kt | 4 +- .../DanaRS_Packet_Bolus_Get_Bolus_Option.kt | 4 +- .../DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt | 4 +- ...acket_Bolus_Get_Calculation_Information.kt | 4 +- ...et_Carbohydrate_Calculation_Information.kt | 4 +- .../DanaRS_Packet_Bolus_Get_Dual_Bolus.kt | 4 +- .../DanaRS_Packet_Bolus_Get_Extended_Bolus.kt | 4 +- ...S_Packet_Bolus_Get_Extended_Bolus_State.kt | 4 +- ...et_Bolus_Get_Extended_Menu_Option_State.kt | 4 +- .../DanaRS_Packet_Bolus_Get_Initial_Bolus.kt | 4 +- ...Packet_Bolus_Get_Step_Bolus_Information.kt | 4 +- .../DanaRS_Packet_Bolus_Set_Bolus_Option.kt | 4 +- .../DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt | 4 +- .../DanaRS_Packet_Bolus_Set_Dual_Bolus.kt | 4 +- .../DanaRS_Packet_Bolus_Set_Extended_Bolus.kt | 4 +- ..._Packet_Bolus_Set_Extended_Bolus_Cancel.kt | 4 +- .../DanaRS_Packet_Bolus_Set_Initial_Bolus.kt | 4 +- ...anaRS_Packet_Bolus_Set_Step_Bolus_Start.kt | 4 +- ...DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt | 4 +- .../comm/DanaRS_Packet_Etc_Keep_Connection.kt | 4 +- .../DanaRS_Packet_Etc_Set_History_Save.kt | 4 +- .../DanaRS_Packet_General_Delivery_Status.kt | 4 +- ...aRS_Packet_General_Get_More_Information.kt | 4 +- .../DanaRS_Packet_General_Get_Password.kt | 4 +- .../DanaRS_Packet_General_Get_Pump_Check.kt | 4 +- ...Packet_General_Get_Shipping_Information.kt | 4 +- ...Packet_General_Get_Today_Delivery_Total.kt | 4 +- ...acket_General_Get_User_Time_Change_Flag.kt | 4 +- ...cket_General_Initial_Screen_Information.kt | 6 +- ..._Packet_General_Set_History_Upload_Mode.kt | 4 +- ...General_Set_User_Time_Change_Flag_Clear.kt | 7 +- .../comm/DanaRS_Packet_History_Alarm.kt | 4 +- .../comm/DanaRS_Packet_History_All_History.kt | 4 +- .../comm/DanaRS_Packet_History_Basal.kt | 4 +- .../DanaRS_Packet_History_Blood_Glucose.kt | 4 +- .../comm/DanaRS_Packet_History_Bolus.kt | 4 +- .../DanaRS_Packet_History_Carbohydrate.kt | 4 +- .../comm/DanaRS_Packet_History_Daily.kt | 4 +- .../comm/DanaRS_Packet_History_Prime.kt | 4 +- .../comm/DanaRS_Packet_History_Refill.kt | 4 +- .../comm/DanaRS_Packet_History_Suspend.kt | 4 +- .../comm/DanaRS_Packet_History_Temporary.kt | 4 +- .../danaRS/comm/DanaRS_Packet_Notify_Alarm.kt | 6 +- .../DanaRS_Packet_Notify_Delivery_Complete.kt | 6 +- ...aRS_Packet_Notify_Delivery_Rate_Display.kt | 6 +- ...DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt | 6 +- .../DanaRS_Packet_Option_Get_Pump_Time.kt | 4 +- .../DanaRS_Packet_Option_Get_User_Option.kt | 4 +- .../DanaRS_Packet_Option_Set_Pump_Time.kt | 4 +- .../DanaRS_Packet_Option_Set_User_Option.kt | 4 +- .../comm/DanaRS_Packet_Review_Bolus_Avg.kt | 4 +- .../danaRS/encryption/BleEncryption.java} | 62 +- .../plugins/pump/danaRS/services/BLEComm.java | 681 ------------------ .../plugins/pump/danaRS/services/BLEComm.kt | 556 ++++++++++++++ .../pump/danaRS/services/DanaRSService.java | 14 +- .../jniLibs/arm64-v8a/libBleEncryption.so | Bin 0 -> 22680 bytes .../jniLibs/armeabi-v7a/libBleEncryption.so | Bin 0 -> 26448 bytes app/src/main/jniLibs/x86/libBleEncryption.so | Bin 0 -> 22296 bytes .../main/jniLibs/x86_64/libBleEncryption.so | Bin 0 -> 22944 bytes .../danaRS/comm/DanaRSMessageHashTableTest.kt | 4 +- 77 files changed, 745 insertions(+), 877 deletions(-) rename app/src/main/java/{com/cozmo/danar/util/BleCommandUtil.java => info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java} (76%) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt create mode 100644 app/src/main/jniLibs/arm64-v8a/libBleEncryption.so create mode 100644 app/src/main/jniLibs/armeabi-v7a/libBleEncryption.so create mode 100644 app/src/main/jniLibs/x86/libBleEncryption.so create mode 100644 app/src/main/jniLibs/x86_64/libBleEncryption.so diff --git a/.gitignore b/.gitignore index c7ed9df2f5..961dd40194 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ build/ .idea/* !.idea/codeStyles/ -app/src/main/jniLibs full/ debug/ release/ diff --git a/app/build.gradle b/app/build.gradle index adc28fb221..73524734ed 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -340,30 +340,6 @@ dependencies { androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' } - -task downloadZipFile(type: Download) { - src 'https://github.com/MilosKozak/danars-support-lib/archive/master.zip' - dest new File(buildDir, 'danars.zip') -} - -task downloadAndUnzipFile(dependsOn: downloadZipFile, type: Copy) { - from zipTree(downloadZipFile.dest) - def outputDir = file("${buildDir}/unpacked/dist") - into outputDir -} - - -task copyLibs(dependsOn: downloadAndUnzipFile, type: Copy) { - def src = file("${buildDir}/unpacked/dist/danars-support-lib-master") - def target = file("src/main/jniLibs/") - - from src - into target -} - -task full_clean(type: Delete) { - delete file("src/main/jniLibs") -} /* // Run 'adb' shell command to clear application data of main app for 'debug' variant task clearMainAppData(type: Exec) { @@ -395,8 +371,6 @@ tasks.whenTaskAdded { task -> } } */ -clean.dependsOn full_clean -preBuild.dependsOn copyLibs printf('--------------\n') printf('isMaster: %s\n', isMaster().toString()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java index 13c41933f5..b9d4af7497 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java @@ -195,9 +195,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR public void connect(String from) { getAapsLogger().debug(LTag.PUMP, "RS connect from: " + from); if (danaRSService != null && !mDeviceAddress.equals("") && !mDeviceName.equals("")) { - final Object o = new Object(); - - danaRSService.connect(from, mDeviceAddress, o); + danaRSService.connect(from, mDeviceAddress); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java index 0e77d7588b..9bb70720fb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java @@ -3,9 +3,8 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm; import android.annotation.TargetApi; import android.os.Build; -import com.cozmo.danar.util.BleCommandUtil; +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.nio.charset.StandardCharsets; import java.util.Date; @@ -21,7 +20,7 @@ public class DanaRS_Packet { private boolean received; public boolean failed; - protected int type = BleCommandUtil.DANAR_PACKET__TYPE_RESPONSE; // most of the messages, should be changed for others + protected int type = BleEncryption.DANAR_PACKET__TYPE_RESPONSE; // most of the messages, should be changed for others protected int opCode; public DanaRS_Packet() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.kt index d223641bba..89a2c3fac3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -14,7 +14,7 @@ class DanaRS_Packet_APS_Basal_Set_Temporary_Basal( var error = 0 init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__APS_SET_TEMPORARY_BASAL + opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__APS_SET_TEMPORARY_BASAL aapsLogger.debug(LTag.PUMPCOMM, "New message: percent: $percent") if (percent < 0) percent = 0 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt index 08b4502daa..27b88c1380 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.R import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.db.ExtendedBolus @@ -36,7 +36,7 @@ open class DanaRS_Packet_APS_History_Events( private var sec = 0 init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE__APS_HISTORY_EVENTS + opCode = BleEncryption.DANAR_PACKET__OPCODE__APS_HISTORY_EVENTS val cal = GregorianCalendar() if (from > DateUtil.now()) { aapsLogger.debug(LTag.PUMPCOMM, "Asked to load from the future") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt index 266554d3be..861854d77b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -16,7 +16,7 @@ class DanaRS_Packet_APS_Set_Event_History( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY + opCode = BleEncryption.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY if ((packetType == DanaRPump.CARBS || packetType == DanaRPump.BOLUS) && param1 <= 0) this.param1 = 0 aapsLogger.debug(LTag.PUMPCOMM, "Set history entry: " + DateUtil.dateAndTimeString(time) + " type: " + packetType + " param1: " + param1 + " param2: " + param2) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.kt index aa0a74e97c..8cdbbe2d65 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -20,7 +20,7 @@ class DanaRS_Packet_Basal_Get_Basal_Rate( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__GET_BASAL_RATE + opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__GET_BASAL_RATE aapsLogger.debug(LTag.PUMPCOMM, "Requesting basal rates") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.kt index 54793b555d..9b0de5603c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -13,7 +13,7 @@ open class DanaRS_Packet_Basal_Get_Profile_Basal_Rate( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__GET_PROFILE_BASAL_RATE + opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__GET_PROFILE_BASAL_RATE aapsLogger.debug(LTag.PUMPCOMM, "Requesting basal rates for profile $profileNumber") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.kt index c37242b740..bdd586e948 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -11,7 +11,7 @@ class DanaRS_Packet_Basal_Get_Profile_Number( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__GET_PROFILE_NUMBER + opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__GET_PROFILE_NUMBER aapsLogger.debug(LTag.PUMPCOMM, "Requesting active profile") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt index fdc5c16480..bb5f0d8d98 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -13,7 +13,7 @@ class DanaRS_Packet_Basal_Get_Temporary_Basal_State( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__TEMPORARY_BASAL_STATE + opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__TEMPORARY_BASAL_STATE aapsLogger.debug(LTag.PUMPCOMM, "Requesting temporary basal status") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.kt index ea5dd4ee29..28d7b6b693 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -11,7 +11,7 @@ class DanaRS_Packet_Basal_Set_Basal_Rate( init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_BASAL_RATE + opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__SET_BASAL_RATE aapsLogger.debug(LTag.PUMPCOMM, "Setting new basal rates") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.kt index 1d67a20a89..c30b938002 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -9,7 +9,7 @@ class DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__CANCEL_TEMPORARY_BASAL + opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__CANCEL_TEMPORARY_BASAL aapsLogger.debug(LTag.PUMPCOMM, "Canceling temp basal") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.kt index a65746f8e8..189a704e0c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -11,7 +11,7 @@ class DanaRS_Packet_Basal_Set_Profile_Basal_Rate( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_PROFILE_BASAL_RATE + opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__SET_PROFILE_BASAL_RATE aapsLogger.debug(LTag.PUMPCOMM, "Setting new basal rates for profile $profileNumber") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.kt index b61c046682..2056889532 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -10,7 +10,7 @@ class DanaRS_Packet_Basal_Set_Profile_Number( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_PROFILE_NUMBER + opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__SET_PROFILE_NUMBER aapsLogger.debug(LTag.PUMPCOMM, "Setting profile number $profileNumber") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.kt index 85e2f70456..eff81eb0bb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -9,7 +9,7 @@ class DanaRS_Packet_Basal_Set_Suspend_Off( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_SUSPEND_OFF + opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__SET_SUSPEND_OFF aapsLogger.debug(LTag.PUMPCOMM, "Turning off suspend") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.kt index c603549d91..e3a3f9d228 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -9,7 +9,7 @@ class DanaRS_Packet_Basal_Set_Suspend_On( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_SUSPEND_ON + opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__SET_SUSPEND_ON aapsLogger.debug(LTag.PUMPCOMM, "Turning on suspend") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.kt index cde564fbc0..f4318fb0b3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -11,7 +11,7 @@ open class DanaRS_Packet_Basal_Set_Temporary_Basal( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_TEMPORARY_BASAL + opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__SET_TEMPORARY_BASAL aapsLogger.debug(LTag.PUMPCOMM, "Setting temporary basal of $temporaryBasalRatio% for $temporaryBasalDuration hours") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.kt index 36512ccec1..8918094938 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -20,7 +20,7 @@ class DanaRS_Packet_Bolus_Get_Bolus_Option( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_BOLUS_OPTION + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_BOLUS_OPTION aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt index b157ad9978..d981da5033 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -11,7 +11,7 @@ class DanaRS_Packet_Bolus_Get_CIR_CF_Array( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_CIR_CF_ARRAY + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_CIR_CF_ARRAY aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.kt index 7dacd08599..6c19045a2f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -12,7 +12,7 @@ class DanaRS_Packet_Bolus_Get_Calculation_Information( init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_CALCULATION_INFORMATION + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_CALCULATION_INFORMATION aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.kt index ba69221673..c1bd0aeb40 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -11,7 +11,7 @@ class DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_CARBOHYDRATE_CALCULATION_INFORMATION + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_CARBOHYDRATE_CALCULATION_INFORMATION aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.kt index 2fbe624322..97d40dd0af 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -11,7 +11,7 @@ class DanaRS_Packet_Bolus_Get_Dual_Bolus( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_DUAL_BOLUS + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_DUAL_BOLUS aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.kt index 3cd50febdb..9d96debe56 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -11,7 +11,7 @@ class DanaRS_Packet_Bolus_Get_Extended_Bolus( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_BOLUS + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_BOLUS aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt index c48b08150b..ef24b5cec1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -11,7 +11,7 @@ class DanaRS_Packet_Bolus_Get_Extended_Bolus_State( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_BOLUS_STATE + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_BOLUS_STATE aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt index 44bcaea4c6..cd16a68bb7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -11,7 +11,7 @@ class DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_MENU_OPTION_STATE + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_MENU_OPTION_STATE aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.kt index 5b3fe17f1f..50f5864e81 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -9,7 +9,7 @@ class DanaRS_Packet_Bolus_Get_Initial_Bolus( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_BOLUS_RATE + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_BOLUS_RATE aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt index e6c8121506..395d90b6ae 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -13,7 +13,7 @@ class DanaRS_Packet_Bolus_Get_Step_Bolus_Information( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_STEP_BOLUS_INFORMATION + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_STEP_BOLUS_INFORMATION aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.kt index 34f3967351..21d9b39d56 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -29,7 +29,7 @@ class DanaRS_Packet_Bolus_Set_Bolus_Option( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_BOLUS_OPTION + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_BOLUS_OPTION aapsLogger.debug(LTag.PUMPCOMM, "Setting bolus options") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt index e31a770db7..137c1633b6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -23,7 +23,7 @@ class DanaRS_Packet_Bolus_Set_CIR_CF_Array( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_CIR_CF_ARRAY + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_CIR_CF_ARRAY aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.kt index d0fef47f82..919039319b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -13,7 +13,7 @@ class DanaRS_Packet_Bolus_Set_Dual_Bolus( init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_DUAL_BOLUS + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_DUAL_BOLUS aapsLogger.debug(LTag.PUMPCOMM, "Dual bolus start : $amount U extended: $extendedAmount U halfhours: $extendedBolusDurationInHalfHours") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.kt index 620a4722ab..222152c2a8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -12,7 +12,7 @@ class DanaRS_Packet_Bolus_Set_Extended_Bolus( init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_EXTENDED_BOLUS + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_EXTENDED_BOLUS aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus start : $extendedAmount U halfhours: $extendedBolusDurationInHalfHours") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.kt index 8596219ba4..868dd5f7b6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -9,7 +9,7 @@ class DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_EXTENDED_BOLUS_CANCEL + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_EXTENDED_BOLUS_CANCEL aapsLogger.debug(LTag.PUMPCOMM, "Cancel extended bolus") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.kt index fb1154c43f..eecd43c6ca 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -13,7 +13,7 @@ class DanaRS_Packet_Bolus_Set_Initial_Bolus( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_BOLUS_RATE + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_BOLUS_RATE aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt index ce9aaf9e1b..ef14999e22 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -17,7 +17,7 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_Start( init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_START + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_START // Speed 0 => 12 sec/U, 1 => 30 sec/U, 2 => 60 sec/U // HARDCODED LIMIT - if there is one that could be created amount = constraintChecker.applyBolusConstraints(Constraint(amount)).value() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt index f84becafc5..462d639a0c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -18,7 +18,7 @@ open class DanaRS_Packet_Bolus_Set_Step_Bolus_Stop( init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_STOP + opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_STOP } override fun handleMessage(data: ByteArray) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.kt index dd29887ef0..1038881c2e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -9,7 +9,7 @@ class DanaRS_Packet_Etc_Keep_Connection( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_ETC__KEEP_CONNECTION + opCode = BleEncryption.DANAR_PACKET__OPCODE_ETC__KEEP_CONNECTION aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.kt index 99fe5da588..ae1fac6bff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -19,7 +19,7 @@ class DanaRS_Packet_Etc_Set_History_Save( init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_ETC__SET_HISTORY_SAVE + opCode = BleEncryption.DANAR_PACKET__OPCODE_ETC__SET_HISTORY_SAVE aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.kt index 524b8e13c8..21937923fc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -9,7 +9,7 @@ class DanaRS_Packet_General_Delivery_Status( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__DELIVERY_STATUS + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__DELIVERY_STATUS aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt index b8e7e6bb53..875b91f397 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -13,7 +13,7 @@ class DanaRS_Packet_General_Get_More_Information( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_MORE_INFORMATION + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__GET_MORE_INFORMATION aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.kt index 5a1358c38b..58cdf77ae9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -11,7 +11,7 @@ class DanaRS_Packet_General_Get_Password( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_PASSWORD + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__GET_PASSWORD aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt index 7c6f2fab5c..bf3338b52f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -18,7 +18,7 @@ class DanaRS_Packet_General_Get_Pump_Check( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_PUMP_CHECK + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__GET_PUMP_CHECK aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt index 00ebd4118a..6bf3296af1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -12,7 +12,7 @@ class DanaRS_Packet_General_Get_Shipping_Information( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_SHIPPING_INFORMATION + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__GET_SHIPPING_INFORMATION aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.kt index 31310e3d08..fe9c676ca9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -11,7 +11,7 @@ class DanaRS_Packet_General_Get_Today_Delivery_Total( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_TODAY_DELIVERY_TOTAL + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__GET_TODAY_DELIVERY_TOTAL aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.kt index 99c0cc2879..45e68600d7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -9,7 +9,7 @@ class DanaRS_Packet_General_Get_User_Time_Change_Flag( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_USER_TIME_CHANGE_FLAG + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__GET_USER_TIME_CHANGE_FLAG aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt index fab00aca3d..574791a005 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -11,8 +11,8 @@ class DanaRS_Packet_General_Initial_Screen_Information( ) : DanaRS_Packet() { init { - type = BleCommandUtil.DANAR_PACKET__TYPE_RESPONSE - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__INITIAL_SCREEN_INFORMATION + type = BleEncryption.DANAR_PACKET__TYPE_RESPONSE + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__INITIAL_SCREEN_INFORMATION aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.kt index b6b884f27d..e26e13e6f0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -10,7 +10,7 @@ class DanaRS_Packet_General_Set_History_Upload_Mode( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SET_HISTORY_UPLOAD_MODE + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__SET_HISTORY_UPLOAD_MODE aapsLogger.debug(LTag.PUMPCOMM, "New message: mode: $mode") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt index 132141b808..969f226fb0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt @@ -1,18 +1,15 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.logging.L -import info.nightscout.androidaps.logging.L.isEnabled import info.nightscout.androidaps.logging.LTag -import org.slf4j.LoggerFactory class DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear( private val aapsLogger: AAPSLogger ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SET_USER_TIME_CHANGE_FLAG_CLEAR + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__SET_USER_TIME_CHANGE_FLAG_CLEAR aapsLogger.debug(LTag.PUMPCOMM, "New message") } override fun handleMessage(data: ByteArray) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt index 9b0c7ef4c6..bcf3ffc1df 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -12,7 +12,7 @@ class DanaRS_Packet_History_Alarm @JvmOverloads constructor( ) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALARM + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__ALARM aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt index a8010b2127..2b42507888 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -12,7 +12,7 @@ class DanaRS_Packet_History_All_History( ) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALL_HISTORY + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__ALL_HISTORY aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt index 0ac22574d5..09173ed5c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -12,7 +12,7 @@ class DanaRS_Packet_History_Basal @JvmOverloads constructor( ) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BASAL + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__BASAL aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt index 6ebbeaed53..7f07e71680 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -12,7 +12,7 @@ class DanaRS_Packet_History_Blood_Glucose @JvmOverloads constructor( ) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BLOOD_GLUCOSE + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__BLOOD_GLUCOSE aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt index 47996fc8c6..d6f8b51707 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -12,7 +12,7 @@ class DanaRS_Packet_History_Bolus @JvmOverloads constructor( ) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BOLUS + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__BOLUS aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt index 1084434962..ed3b49a8d7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -12,7 +12,7 @@ class DanaRS_Packet_History_Carbohydrate @JvmOverloads constructor( ) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__CARBOHYDRATE + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__CARBOHYDRATE aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt index 93e974728d..645cab8272 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -12,7 +12,7 @@ class DanaRS_Packet_History_Daily @JvmOverloads constructor( ) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__DAILY + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__DAILY aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt index 0306e6f129..da209b0a8a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -12,7 +12,7 @@ class DanaRS_Packet_History_Prime @JvmOverloads constructor( ) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__PRIME + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__PRIME aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt index 672c5e2cc4..8b470a0170 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -12,7 +12,7 @@ class DanaRS_Packet_History_Refill @JvmOverloads constructor( ) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__REFILL + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__REFILL aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt index 9868cd10a4..2e5ad23dd9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -12,7 +12,7 @@ class DanaRS_Packet_History_Suspend @JvmOverloads constructor( ) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SUSPEND + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__SUSPEND aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt index b185748495..5689ca82c5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -12,7 +12,7 @@ class DanaRS_Packet_History_Temporary( ) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__TEMPORARY + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__TEMPORARY aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt index 5cc82d93a5..7650ff3704 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -13,8 +13,8 @@ class DanaRS_Packet_Notify_Alarm( ) : DanaRS_Packet() { init { - type = BleCommandUtil.DANAR_PACKET__TYPE_NOTIFY - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_NOTIFY__ALARM + type = BleEncryption.DANAR_PACKET__TYPE_NOTIFY + opCode = BleEncryption.DANAR_PACKET__OPCODE_NOTIFY__ALARM aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt index 246f2c7fe5..03d884933b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -18,8 +18,8 @@ class DanaRS_Packet_Notify_Delivery_Complete( ) : DanaRS_Packet() { init { - type = BleCommandUtil.DANAR_PACKET__TYPE_NOTIFY - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_NOTIFY__DELIVERY_COMPLETE + type = BleEncryption.DANAR_PACKET__TYPE_NOTIFY + opCode = BleEncryption.DANAR_PACKET__OPCODE_NOTIFY__DELIVERY_COMPLETE aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt index 9705c53669..a63bad6f23 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -19,8 +19,8 @@ class DanaRS_Packet_Notify_Delivery_Rate_Display( init { - type = BleCommandUtil.DANAR_PACKET__TYPE_NOTIFY - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_NOTIFY__DELIVERY_RATE_DISPLAY + type = BleEncryption.DANAR_PACKET__TYPE_NOTIFY + opCode = BleEncryption.DANAR_PACKET__OPCODE_NOTIFY__DELIVERY_RATE_DISPLAY } override fun handleMessage(data: ByteArray) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt index ad5fdbdef6..f15582f3d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -9,8 +9,8 @@ class DanaRS_Packet_Notify_Missed_Bolus_Alarm( ) : DanaRS_Packet() { init { - type = BleCommandUtil.DANAR_PACKET__TYPE_NOTIFY - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_NOTIFY__MISSED_BOLUS_ALARM + type = BleEncryption.DANAR_PACKET__TYPE_NOTIFY + opCode = BleEncryption.DANAR_PACKET__OPCODE_NOTIFY__MISSED_BOLUS_ALARM aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt index 2b18603d11..b582a0b492 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -13,7 +13,7 @@ class DanaRS_Packet_Option_Get_Pump_Time( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_OPTION__GET_PUMP_TIME + opCode = BleEncryption.DANAR_PACKET__OPCODE_OPTION__GET_PUMP_TIME aapsLogger.debug(LTag.PUMPCOMM, "Requesting pump time") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.kt index 07694f6380..a012b1302b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -11,7 +11,7 @@ class DanaRS_Packet_Option_Get_User_Option( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_OPTION__GET_USER_OPTION + opCode = BleEncryption.DANAR_PACKET__OPCODE_OPTION__GET_USER_OPTION aapsLogger.debug(LTag.PUMPCOMM, "Requesting user settings") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt index ec1a44c789..54a38af3de 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.utils.DateUtil @@ -14,7 +14,7 @@ class DanaRS_Packet_Option_Set_Pump_Time( var error = 0 init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_OPTION__SET_PUMP_TIME + opCode = BleEncryption.DANAR_PACKET__OPCODE_OPTION__SET_PUMP_TIME aapsLogger.debug(LTag.PUMPCOMM, "Setting pump time " + DateUtil.dateAndTimeString(time)) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.kt index 2ca965fc60..d266bf765b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -12,7 +12,7 @@ class DanaRS_Packet_Option_Set_User_Option( init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_OPTION__SET_USER_OPTION + opCode = BleEncryption.DANAR_PACKET__OPCODE_OPTION__SET_USER_OPTION aapsLogger.debug(LTag.PUMPCOMM, "Setting user settings") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.kt index c99a56a2b8..ee953d8581 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -9,7 +9,7 @@ class DanaRS_Packet_Review_Bolus_Avg( ) : DanaRS_Packet() { init { - opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BOLUS_AVG + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__BOLUS_AVG aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/com/cozmo/danar/util/BleCommandUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java similarity index 76% rename from app/src/main/java/com/cozmo/danar/util/BleCommandUtil.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java index a417b379e8..edd36f583e 100644 --- a/app/src/main/java/com/cozmo/danar/util/BleCommandUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java @@ -1,10 +1,18 @@ -package com.cozmo.danar.util; +package info.nightscout.androidaps.plugins.pump.danaRS.encryption; import android.content.Context; -import info.nightscout.androidaps.MainApp; +import javax.inject.Inject; +import javax.inject.Singleton; + +@Singleton +public class BleEncryption { + private Context context; + + @Inject BleEncryption(Context context) { + this.context = context; + } -public class BleCommandUtil { public static final int DANAR_PACKET__TYPE_ENCRYPTION_REQUEST = 0x01; public static final int DANAR_PACKET__TYPE_ENCRYPTION_RESPONSE = 0x02; public static final int DANAR_PACKET__TYPE_COMMAND = 0xA1; @@ -12,10 +20,13 @@ public class BleCommandUtil { public static final int DANAR_PACKET__TYPE_NOTIFY = 0xC3; public static final int DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK = 0x00; + public static final int DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION = 0x01; public static final int DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY = 0xD0; public static final int DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_REQUEST = 0xD1; public static final int DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_RETURN = 0xD2; - public static final int DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION = 0x01; + // Easy Mode + public static final int DANAR_PACKET__OPCODE_ENCRYPTION__GET_PUMP_CHECK = 0xF3; + public static final int DANAR_PACKET__OPCODE_ENCRYPTION__GET_EASYMENU_CHECK = 0xF4; public static final int DANAR_PACKET__OPCODE_NOTIFY__DELIVERY_COMPLETE = 0x01; public static final int DANAR_PACKET__OPCODE_NOTIFY__DELIVERY_RATE_DISPLAY = 0x02; @@ -86,35 +97,50 @@ public class BleCommandUtil { public static final int DANAR_PACKET__OPCODE__APS_HISTORY_EVENTS = 0xC2; public static final int DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY = 0xC3; + // Easy Mode + public static final int DANAR_PACKET__OPCODE_OPTION__GET_EASY_MENU_OPTION = 0x74; + public static final int DANAR_PACKET__OPCODE_OPTION__SET_EASY_MENU_OPTION = 0x75; + public static final int DANAR_PACKET__OPCODE_ETC__SET_HISTORY_SAVE = 0xE0; public static final int DANAR_PACKET__OPCODE_ETC__KEEP_CONNECTION = 0xFF; static { - System.loadLibrary("BleCommandUtil"); + System.loadLibrary("BleEncryption"); } - private static native byte[] getEncryptedPacketJni(Object context, int opcode, byte[] bytes, String deviceName); + private static native byte[] encryptPacketJni(Object context, int opcode, byte[] bytes, String deviceName); - private static native byte[] getDecryptedPacketJni(Object context, byte[] bytes); + private static native byte[] decryptPacketJni(Object context, byte[] bytes); - // --------------------------------------------------------- + private static native void setPairingKeysJni(byte[] pairingKey, byte[] randomPairingKey, byte randomSyncKey); - private static BleCommandUtil mInstance = null; + private static native void setEnhancedEncryptionJni(boolean isSecurityVersion); - public static BleCommandUtil getInstance() { - if (mInstance == null) { - mInstance = new BleCommandUtil(); - } - return mInstance; - } + private static native byte[] encryptSecondLevelPacketJni(Object context, byte[] bytes); - // --------------------------------------------------------- + private static native byte[] decryptSecondLevelPacketJni(Object context, byte[] bytes); public byte[] getEncryptedPacket(int opcode, byte[] bytes, String deviceName) { - return getEncryptedPacketJni(MainApp.instance().getApplicationContext(), opcode, bytes, deviceName); + return encryptPacketJni(context, opcode, bytes, deviceName); } public byte[] getDecryptedPacket(byte[] bytes) { - return getDecryptedPacketJni(MainApp.instance().getApplicationContext(), bytes); + return decryptPacketJni(context, bytes); + } + + public void setPairingKeys(byte[] pairingKey, byte[] randomPairingKey, byte randomSyncKey) { + setPairingKeysJni(pairingKey, randomPairingKey, randomSyncKey); + } + + public void setEnhancedEncryption(boolean isSecureVersion) { + setEnhancedEncryptionJni(isSecureVersion); + } + + public byte[] encryptSecondLevelPacket(byte[] bytes) { + return encryptSecondLevelPacketJni(context, bytes); + } + + public byte[] ecryptSecondLevelPacket(byte[] bytes) { + return decryptSecondLevelPacketJni(context, bytes); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java deleted file mode 100644 index 75ceba52ee..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java +++ /dev/null @@ -1,681 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS.services; - -import android.bluetooth.BluetoothAdapter; -import android.bluetooth.BluetoothDevice; -import android.bluetooth.BluetoothGatt; -import android.bluetooth.BluetoothGattCallback; -import android.bluetooth.BluetoothGattCharacteristic; -import android.bluetooth.BluetoothGattService; -import android.bluetooth.BluetoothManager; -import android.bluetooth.BluetoothProfile; -import android.content.Context; -import android.content.Intent; -import android.os.SystemClock; - -import com.cozmo.danar.util.BleCommandUtil; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.ScheduledFuture; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.events.EventPumpStatusChanged; -import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; -import info.nightscout.androidaps.plugins.bus.RxBus; -import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; -import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; -import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; -import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin; -import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSMessageHashTable; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet; -import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess; -import info.nightscout.androidaps.utils.SP; - -/** - * Created by mike on 23.09.2017. - */ - -public class BLEComm { - private Logger log = StacktraceLoggerWrapper.getLogger(L.PUMPBTCOMM); - - private final long WRITE_DELAY_MILLIS = 50; - - private String UART_READ_UUID = "0000fff1-0000-1000-8000-00805f9b34fb"; - private String UART_WRITE_UUID = "0000fff2-0000-1000-8000-00805f9b34fb"; - - private final byte PACKET_START_BYTE = (byte) 0xA5; - private final byte PACKET_END_BYTE = (byte) 0x5A; - private Context context; - private DanaRPump danaRPump; - private DanaRSMessageHashTable danaRSMessageHashTable; - - public BLEComm(Context context, DanaRSMessageHashTable danaRSMessageHashTable, DanaRPump danaRPump) { - this.context = context; - this.danaRPump = danaRPump; - this.danaRSMessageHashTable = danaRSMessageHashTable; - initialize(); - } - - private ScheduledFuture scheduledDisconnection = null; - - private DanaRS_Packet processsedMessage = null; - private final ArrayList mSendQueue = new ArrayList<>(); - - private BluetoothManager mBluetoothManager = null; - private BluetoothAdapter mBluetoothAdapter = null; - private String mBluetoothDeviceName = null; - private BluetoothGatt mBluetoothGatt = null; - - protected boolean isConnected = false; - protected boolean isConnecting = false; - - private BluetoothGattCharacteristic UART_Read; - private BluetoothGattCharacteristic UART_Write; - - private boolean initialize() { - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("Initializing BLEComm."); - - if (mBluetoothManager == null) { - mBluetoothManager = ((BluetoothManager) MainApp.instance().getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE)); - if (mBluetoothManager == null) { - log.error("Unable to initialize BluetoothManager."); - return false; - } - } - - mBluetoothAdapter = mBluetoothManager.getAdapter(); - if (mBluetoothAdapter == null) { - log.error("Unable to obtain a BluetoothAdapter."); - return false; - } - - return true; - } - - public boolean isConnected() { - return isConnected; - } - - public boolean isConnecting() { - return isConnecting; - } - - public boolean connect(String from, String address, Object confirmConnect) { - BluetoothManager tBluetoothManager = ((BluetoothManager) MainApp.instance().getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE)); - if (tBluetoothManager == null) { - return false; - } - - BluetoothAdapter tBluetoothAdapter = tBluetoothManager.getAdapter(); - if (tBluetoothAdapter == null) { - return false; - } - - if (mBluetoothAdapter == null) { - if (!initialize()) { - return false; - } - } - - if (address == null) { - log.error("unspecified address."); - return false; - } - - isConnecting = true; - - BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); - if (device == null) { - log.error("Device not found. Unable to connect from: " + from); - return false; - } - - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("Trying to create a new connection from: " + from); - mBluetoothDeviceName = device.getName(); - mBluetoothGatt = device.connectGatt(context, false, mGattCallback); - setCharacteristicNotification(getUARTReadBTGattChar(), true); - return true; - } - - public void stopConnecting() { - isConnecting = false; - } - - public synchronized void disconnect(String from) { - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("disconnect from: " + from); - - // cancel previous scheduled disconnection to prevent closing upcomming connection - if (scheduledDisconnection != null) - scheduledDisconnection.cancel(false); - scheduledDisconnection = null; - - if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { - log.error("disconnect not possible: (mBluetoothAdapter == null) " + (mBluetoothAdapter == null)); - log.error("disconnect not possible: (mBluetoothGatt == null) " + (mBluetoothGatt == null)); - return; - } - setCharacteristicNotification(getUARTReadBTGattChar(), false); - mBluetoothGatt.disconnect(); - isConnected = false; - SystemClock.sleep(2000); - } - - public synchronized void close() { - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("BluetoothAdapter close"); - if (mBluetoothGatt == null) { - return; - } - - mBluetoothGatt.close(); - mBluetoothGatt = null; - } - - - private String getConnectDeviceName() { - return mBluetoothDeviceName; - } - - private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { - public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { - onConnectionStateChangeSynchronized(gatt, status, newState); // call it synchronized - } - - public void onServicesDiscovered(BluetoothGatt gatt, int status) { - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("onServicesDiscovered"); - if (status == BluetoothGatt.GATT_SUCCESS) { - findCharacteristic(); - } - SendPumpCheck(); - // 1st message sent to pump after connect - } - - public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("onCharacteristicRead" + (characteristic != null ? ":" + DanaRS_Packet.toHexString(characteristic.getValue()) : "")); - addToReadBuffer(characteristic.getValue()); - readDataParsing(); - } - - public void onCharacteristicChanged(BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) { - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("onCharacteristicChanged" + (characteristic != null ? ":" + DanaRS_Packet.toHexString(characteristic.getValue()) : "")); - addToReadBuffer(characteristic.getValue()); - new Thread(() -> readDataParsing()).start(); - } - - public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("onCharacteristicWrite" + (characteristic != null ? ":" + DanaRS_Packet.toHexString(characteristic.getValue()) : "")); - new Thread(() -> { - synchronized (mSendQueue) { - // after message sent, check if there is the rest of the message waiting and send it - if (mSendQueue.size() > 0) { - byte[] bytes = mSendQueue.get(0); - mSendQueue.remove(0); - writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes); - } - } - }).start(); - } - }; - - private synchronized void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("setCharacteristicNotification"); - if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { - log.error("BluetoothAdapter not initialized_ERROR"); - isConnecting = false; - isConnected = false; - return; - } - mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); - } - - public synchronized void readCharacteristic(BluetoothGattCharacteristic characteristic) { - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("readCharacteristic"); - if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { - log.error("BluetoothAdapter not initialized_ERROR"); - isConnecting = false; - isConnected = false; - return; - } - mBluetoothGatt.readCharacteristic(characteristic); - } - - private synchronized void writeCharacteristic_NO_RESPONSE(final BluetoothGattCharacteristic characteristic, final byte[] data) { - new Thread(() -> { - SystemClock.sleep(WRITE_DELAY_MILLIS); - - if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { - log.error("BluetoothAdapter not initialized_ERROR"); - isConnecting = false; - isConnected = false; - return; - } - - characteristic.setValue(data); - characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE); - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("writeCharacteristic:" + DanaRS_Packet.toHexString(data)); - mBluetoothGatt.writeCharacteristic(characteristic); - }).start(); - } - - private BluetoothGattCharacteristic getUARTReadBTGattChar() { - if (UART_Read == null) { - UART_Read = new BluetoothGattCharacteristic(UUID.fromString(UART_READ_UUID), BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_NOTIFY, 0); - } - return UART_Read; - } - - private BluetoothGattCharacteristic getUARTWriteBTGattChar() { - if (UART_Write == null) { - UART_Write = new BluetoothGattCharacteristic(UUID.fromString(UART_WRITE_UUID), BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE, 0); - } - return UART_Write; - } - - private List getSupportedGattServices() { - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("getSupportedGattServices"); - if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { - log.error("BluetoothAdapter not initialized_ERROR"); - isConnecting = false; - isConnected = false; - return null; - } - - return mBluetoothGatt.getServices(); - } - - private void findCharacteristic() { - List gattServices = getSupportedGattServices(); - - if (gattServices == null) { - return; - } - String uuid; - - for (BluetoothGattService gattService : gattServices) { - List gattCharacteristics = gattService.getCharacteristics(); - for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { - uuid = gattCharacteristic.getUuid().toString(); - if (UART_READ_UUID.equals(uuid)) { - UART_Read = gattCharacteristic; - setCharacteristicNotification(UART_Read, true); - } - if (UART_WRITE_UUID.equals(uuid)) { - UART_Write = gattCharacteristic; - } - } - } - } - - private synchronized void onConnectionStateChangeSynchronized(BluetoothGatt gatt, int status, int newState) { - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("onConnectionStateChange"); - - if (newState == BluetoothProfile.STATE_CONNECTED) { - mBluetoothGatt.discoverServices(); - } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { - close(); - isConnected = false; - isConnecting = false; - RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED)); - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("Device was disconnected " + gatt.getDevice().getName());//Device was disconnected - } - } - - private final byte[] readBuffer = new byte[1024]; - private int bufferLength = 0; - - private void addToReadBuffer(byte[] buffer) { - //log.debug("addToReadBuffer " + DanaRS_Packet.toHexString(buffer)); - if (buffer == null || buffer.length == 0) { - return; - } - synchronized (readBuffer) { - // Append incomming data to input buffer - System.arraycopy(buffer, 0, readBuffer, bufferLength, buffer.length); - bufferLength += buffer.length; - } - } - - private void readDataParsing() { - boolean startSignatureFound = false, packetIsValid = false; - boolean isProcessing; - - isProcessing = true; - - while (isProcessing) { - int length = 0; - byte[] inputBuffer = null; - synchronized (readBuffer) { - // Find packet start [A5 A5] - if (bufferLength >= 6) { - for (int idxStartByte = 0; idxStartByte < bufferLength - 2; idxStartByte++) { - if ((readBuffer[idxStartByte] == PACKET_START_BYTE) && (readBuffer[idxStartByte + 1] == PACKET_START_BYTE)) { - if (idxStartByte > 0) { - // if buffer doesn't start with signature remove the leading trash - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("Shifting the input buffer by " + idxStartByte + " bytes"); - System.arraycopy(readBuffer, idxStartByte, readBuffer, 0, bufferLength - idxStartByte); - bufferLength -= idxStartByte; - } - startSignatureFound = true; - break; - } - } - } - // A5 A5 LEN TYPE CODE PARAMS CHECKSUM1 CHECKSUM2 5A 5A - // ^---- LEN -----^ - // total packet length 2 + 1 + readBuffer[2] + 2 + 2 - if (startSignatureFound) { - length = readBuffer[2]; - // test if there is enough data loaded - if (length + 7 > bufferLength) - return; - // Verify packed end [5A 5A] - if ((readBuffer[length + 5] == PACKET_END_BYTE) && (readBuffer[length + 6] == PACKET_END_BYTE)) { - packetIsValid = true; - } - } - 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 - try { - System.arraycopy(readBuffer, length + 7, readBuffer, 0, bufferLength - (length + 7)); - } catch (Exception e) { - log.error("length: " + length + "bufferLength: " + bufferLength); - throw e; - } - bufferLength -= (length + 7); - // now we have encrypted packet in inputBuffer - } - } - if (packetIsValid) { - try { - // decrypt the packet - inputBuffer = BleCommandUtil.getInstance().getDecryptedPacket(inputBuffer); - - if (inputBuffer == null) { - log.error("Null decryptedInputBuffer"); - return; - } - - switch (inputBuffer[0]) { - // initial handshake packet - case (byte) BleCommandUtil.DANAR_PACKET__TYPE_ENCRYPTION_RESPONSE: - switch (inputBuffer[1]) { - // 1st packet - case (byte) BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK: - if (inputBuffer.length == 4 && inputBuffer[2] == 'O' && inputBuffer[3] == 'K') { - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("<<<<< " + "ENCRYPTION__PUMP_CHECK (OK)" + " " + DanaRS_Packet.toHexString(inputBuffer)); - // Grab pairing key from preferences if exists - String pairingKey = SP.getString(MainApp.gs(R.string.key_danars_pairingkey) + DanaRSPlugin.mDeviceName, null); - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("Using stored pairing key: " + pairingKey); - if (pairingKey != null) { - byte[] encodedPairingKey = DanaRS_Packet.hexToBytes(pairingKey); - byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY, encodedPairingKey, null); - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug(">>>>> " + "ENCRYPTION__CHECK_PASSKEY" + " " + DanaRS_Packet.toHexString(bytes)); - writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes); - } else { - // Stored pairing key does not exists, request pairing - SendPairingRequest(); - } - - } else if (inputBuffer.length == 6 && inputBuffer[2] == 'P' && inputBuffer[3] == 'U' && inputBuffer[4] == 'M' && inputBuffer[5] == 'P') { - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("<<<<< " + "ENCRYPTION__PUMP_CHECK (PUMP)" + " " + DanaRS_Packet.toHexString(inputBuffer)); - mSendQueue.clear(); - RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, MainApp.gs(R.string.pumperror))); - NSUpload.uploadError(MainApp.gs(R.string.pumperror)); - Notification n = new Notification(Notification.PUMPERROR, MainApp.gs(R.string.pumperror), Notification.URGENT); - RxBus.Companion.getINSTANCE().send(new EventNewNotification(n)); - } else if (inputBuffer.length == 6 && inputBuffer[2] == 'B' && inputBuffer[3] == 'U' && inputBuffer[4] == 'S' && inputBuffer[5] == 'Y') { - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("<<<<< " + "ENCRYPTION__PUMP_CHECK (BUSY)" + " " + DanaRS_Packet.toHexString(inputBuffer)); - mSendQueue.clear(); - RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, MainApp.gs(R.string.pumpbusy))); - } else { - // ERROR in response, wrong serial number - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("<<<<< " + "ENCRYPTION__PUMP_CHECK (ERROR)" + " " + DanaRS_Packet.toHexString(inputBuffer)); - mSendQueue.clear(); - RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, MainApp.gs(R.string.connectionerror))); - SP.remove(MainApp.gs(R.string.key_danars_pairingkey) + DanaRSPlugin.mDeviceName); - Notification n = new Notification(Notification.WRONGSERIALNUMBER, MainApp.gs(R.string.wrongpassword), Notification.URGENT); - RxBus.Companion.getINSTANCE().send(new EventNewNotification(n)); - } - break; - // 2nd packet, pairing key - case (byte) BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY: - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("<<<<< " + "ENCRYPTION__CHECK_PASSKEY" + " " + DanaRS_Packet.toHexString(inputBuffer)); - if (inputBuffer[2] == (byte) 0x00) { - // Paring is not requested, sending time info - SendTimeInfo(); - } else { - // Pairing on pump is requested - SendPairingRequest(); - } - break; - case (byte) BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_REQUEST: - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("<<<<< " + "ENCRYPTION__PASSKEY_REQUEST " + DanaRS_Packet.toHexString(inputBuffer)); - if (inputBuffer[2] != (byte) 0x00) { - disconnect("passkey request failed"); - } - break; - // Paring response, OK button on pump pressed - case (byte) BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_RETURN: - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("<<<<< " + "ENCRYPTION__PASSKEY_RETURN " + DanaRS_Packet.toHexString(inputBuffer)); - // Paring is successfull, sending time info - RxBus.Companion.getINSTANCE().send(new EventDanaRSPairingSuccess()); - SendTimeInfo(); - byte[] pairingKey = {inputBuffer[2], inputBuffer[3]}; - // store pairing key to preferences - SP.putString(MainApp.gs(R.string.key_danars_pairingkey) + DanaRSPlugin.mDeviceName, DanaRS_Packet.bytesToHex(pairingKey)); - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("Got pairing key: " + DanaRS_Packet.bytesToHex(pairingKey)); - break; - // time and user password information. last packet in handshake - case (byte) BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION: - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("<<<<< " + "ENCRYPTION__TIME_INFORMATION " + /*message.getMessageName() + " " + */ DanaRS_Packet.toHexString(inputBuffer)); - int size = inputBuffer.length; - int pass = ((inputBuffer[size - 1] & 0x000000FF) << 8) + ((inputBuffer[size - 2] & 0x000000FF)); - pass = pass ^ 3463; - danaRPump.setRsPassword(Integer.toHexString(pass)); - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("Pump user password: " + Integer.toHexString(pass)); - - RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED)); - isConnected = true; - isConnecting = false; - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("RS connected and status read"); - break; - } - break; - // common data packet - default: - DanaRS_Packet message; - // Retrieve message code from received buffer and last message sent - int originalCommand = processsedMessage != null ? processsedMessage.getCommand() : 0xFFFF; - int receivedCommand = DanaRS_Packet.getCommand(inputBuffer); - if (originalCommand == receivedCommand) { - // it's response to last message - message = processsedMessage; - } else { - // it's not response to last message, create new instance - message = danaRSMessageHashTable.findMessage(receivedCommand); - } - if (message != null) { - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug("<<<<< " + message.getFriendlyName() + " " + DanaRS_Packet.toHexString(inputBuffer)); - // process received data - message.handleMessage(inputBuffer); - message.setReceived(); - synchronized (message) { - // notify to sendMessage - message.notify(); - } - } else { - log.error("Unknown message received " + DanaRS_Packet.toHexString(inputBuffer)); - } - break; - } - } catch (Exception e) { - log.error("Unhandled exception", e); - } - startSignatureFound = false; - packetIsValid = false; - if (bufferLength < 6) { - // stop the loop - isProcessing = false; - } - } else { - // stop the loop - isProcessing = false; - } - } - } - - public void sendMessage(DanaRS_Packet message) { - processsedMessage = message; - if (message == null) - return; - - byte[] command = {(byte) message.getType(), (byte) message.getOpCode()}; - byte[] params = message.getRequestParams(); - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug(">>>>> " + message.getFriendlyName() + " " + DanaRS_Packet.toHexString(command) + " " + DanaRS_Packet.toHexString(params)); - byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(message.getOpCode(), params, null); - // If there is another message not completely sent, add to queue only - if (mSendQueue.size() > 0) { - // Split to parts per 20 bytes max - for (; ; ) { - if (bytes.length > 20) { - byte[] addBytes = new byte[20]; - System.arraycopy(bytes, 0, addBytes, 0, addBytes.length); - byte[] reBytes = new byte[bytes.length - addBytes.length]; - System.arraycopy(bytes, addBytes.length, reBytes, 0, reBytes.length); - bytes = reBytes; - synchronized (mSendQueue) { - mSendQueue.add(addBytes); - } - } else { - synchronized (mSendQueue) { - mSendQueue.add(bytes); - } - break; - } - } - - } else { - if (bytes.length > 20) { - // Cut first 20 bytes - byte[] sendBytes = new byte[20]; - System.arraycopy(bytes, 0, sendBytes, 0, sendBytes.length); - byte[] reBytes = new byte[bytes.length - sendBytes.length]; - System.arraycopy(bytes, sendBytes.length, reBytes, 0, reBytes.length); - bytes = reBytes; - // and send - writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), sendBytes); - // The rest split to parts per 20 bytes max - for (; ; ) { - if (bytes.length > 20) { - byte[] addBytes = new byte[20]; - System.arraycopy(bytes, 0, addBytes, 0, addBytes.length); - reBytes = new byte[bytes.length - addBytes.length]; - System.arraycopy(bytes, addBytes.length, reBytes, 0, reBytes.length); - bytes = reBytes; - synchronized (mSendQueue) { - mSendQueue.add(addBytes); - } - } else { - synchronized (mSendQueue) { - mSendQueue.add(bytes); - } - break; - } - } - } else { - writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes); - } - } - // The rest from queue is send from onCharasteristicWrite (after sending 1st part) - synchronized (message) { - try { - message.wait(5000); - } catch (InterruptedException e) { - log.error("sendMessage InterruptedException", e); - log.error("Unhandled exception", e); - } - } - - //SystemClock.sleep(200); - if (!message.isReceived()) { - log.warn("Reply not received " + message.getFriendlyName()); - message.handleMessageNotReceived(); - } - } - - private void SendPairingRequest() { - // Start activity which is waiting 20sec - // On pump pairing request is displayed and is waiting for conformation - Intent i = new Intent(); - i.setClass(MainApp.instance(), PairingHelperActivity.class); - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - MainApp.instance().startActivity(i); - - byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_REQUEST, null, null); - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug(">>>>> " + "ENCRYPTION__PASSKEY_REQUEST" + " " + DanaRS_Packet.toHexString(bytes)); - writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes); - } - - private void SendPumpCheck() { - // 1st message sent to pump after connect - String devicename = getConnectDeviceName(); - if (devicename == null || devicename.equals("")) { - Notification n = new Notification(Notification.DEVICENOTPAIRED, MainApp.gs(R.string.pairfirst), Notification.URGENT); - RxBus.Companion.getINSTANCE().send(new EventNewNotification(n)); - return; - } - byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK, null, devicename); - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug(">>>>> " + "ENCRYPTION__PUMP_CHECK (0x00)" + " " + DanaRS_Packet.toHexString(bytes)); - writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes); - } - - private void SendTimeInfo() { - byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION, null, null); - if (L.isEnabled(L.PUMPBTCOMM)) - log.debug(">>>>> " + "ENCRYPTION__TIME_INFORMATION" + " " + DanaRS_Packet.toHexString(bytes)); - writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes); - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt new file mode 100644 index 0000000000..b079d5c241 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt @@ -0,0 +1,556 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.services + +import android.bluetooth.* +import android.content.Context +import android.content.Intent +import android.os.SystemClock +import info.nightscout.androidaps.R +import info.nightscout.androidaps.events.EventPumpStatusChanged +import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin +import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSMessageHashTable +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess +import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.androidaps.utils.sharedPreferences.SP +import okhttp3.internal.notify +import okhttp3.internal.waitMillis +import java.util.* +import java.util.concurrent.ScheduledFuture +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class BLEComm @Inject internal constructor( + private val aapsLogger: AAPSLogger, + private val resourceHelper: ResourceHelper, + private val context: Context, + private val rxBus: RxBusWrapper, + private val sp: SP, + private val danaRSMessageHashTable: DanaRSMessageHashTable, + private val danaRPump: DanaRPump, + private val bleEncryption: BleEncryption +) { + + companion object { + private const val WRITE_DELAY_MILLIS: Long = 50 + private const val UART_READ_UUID = "0000fff1-0000-1000-8000-00805f9b34fb" + private const val UART_WRITE_UUID = "0000fff2-0000-1000-8000-00805f9b34fb" + + private const val PACKET_START_BYTE = 0xA5.toByte() + private const val PACKET_END_BYTE = 0x5A.toByte() + } + + private var scheduledDisconnection: ScheduledFuture<*>? = null + private var processedMessage: DanaRS_Packet? = null + private val mSendQueue = ArrayList() + private var mBluetoothManager: BluetoothManager? = null + private var mBluetoothAdapter: BluetoothAdapter? = null + private var connectDeviceName: String? = null + private var mBluetoothGatt: BluetoothGatt? = null + + var isConnected = false + var isConnecting = false + private var uartRead: BluetoothGattCharacteristic? = null + private var uartWrite: BluetoothGattCharacteristic? = null + + init { + initialize() + } + + private fun initialize(): Boolean { + aapsLogger.debug(LTag.PUMPBTCOMM, "Initializing BLEComm.") + if (mBluetoothManager == null) { + mBluetoothManager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager + if (mBluetoothManager == null) { + aapsLogger.error("Unable to initialize BluetoothManager.") + return false + } + } + mBluetoothAdapter = mBluetoothManager?.adapter + if (mBluetoothAdapter == null) { + aapsLogger.error("Unable to obtain a BluetoothAdapter.") + return false + } + return true + } + + fun connect(from: String, address: String?): Boolean { + // test existing BT device + val tBluetoothManager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager? + ?: return false + tBluetoothManager.adapter ?: return false + + if (address == null) { + aapsLogger.error("unspecified address.") + return false + } + + if (mBluetoothAdapter == null) { + if (!initialize()) { + return false + } + } + isConnecting = true + val device = mBluetoothAdapter?.getRemoteDevice(address) + if (device == null) { + aapsLogger.error("Device not found. Unable to connect from: $from") + return false + } + aapsLogger.debug(LTag.PUMPBTCOMM, "Trying to create a new connection from: $from") + connectDeviceName = device.name + mBluetoothGatt = device.connectGatt(context, false, mGattCallback) + setCharacteristicNotification(uartReadBTGattChar, true) + return true + } + + fun stopConnecting() { + isConnecting = false + } + + @Synchronized + fun disconnect(from: String) { + aapsLogger.debug(LTag.PUMPBTCOMM, "disconnect from: $from") + + // cancel previous scheduled disconnection to prevent closing upcoming connection + scheduledDisconnection?.cancel(false) + scheduledDisconnection = null + + if (mBluetoothAdapter == null || mBluetoothGatt == null) { + aapsLogger.error("disconnect not possible: (mBluetoothAdapter == null) " + (mBluetoothAdapter == null)) + aapsLogger.error("disconnect not possible: (mBluetoothGatt == null) " + (mBluetoothGatt == null)) + return + } + setCharacteristicNotification(uartReadBTGattChar, false) + mBluetoothGatt?.disconnect() + isConnected = false + SystemClock.sleep(2000) + } + + @Synchronized fun close() { + aapsLogger.debug(LTag.PUMPBTCOMM, "BluetoothAdapter close") + mBluetoothGatt?.close() + mBluetoothGatt = null + } + + private val mGattCallback: BluetoothGattCallback = object : BluetoothGattCallback() { + override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) { + onConnectionStateChangeSynchronized(gatt, newState) // call it synchronized + } + + override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) { + aapsLogger.debug(LTag.PUMPBTCOMM, "onServicesDiscovered") + if (status == BluetoothGatt.GATT_SUCCESS) { + findCharacteristic() + } + sendPumpCheck() + // 1st message sent to pump after connect + } + + override fun onCharacteristicRead(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) { + aapsLogger.debug(LTag.PUMPBTCOMM, "onCharacteristicRead: " + DanaRS_Packet.toHexString(characteristic.value)) + addToReadBuffer(characteristic.value) + readDataParsing() + } + + override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic) { + aapsLogger.debug(LTag.PUMPBTCOMM, "onCharacteristicChanged: " + DanaRS_Packet.toHexString(characteristic.value)) + addToReadBuffer(characteristic.value) + Thread(Runnable { readDataParsing() }).start() + } + + override fun onCharacteristicWrite(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) { + aapsLogger.debug(LTag.PUMPBTCOMM, "onCharacteristicWrite: " + DanaRS_Packet.toHexString(characteristic.value)) + Thread(Runnable { + synchronized(mSendQueue) { + // after message sent, check if there is the rest of the message waiting and send it + if (mSendQueue.size > 0) { + val bytes = mSendQueue[0] + mSendQueue.removeAt(0) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } + } + }).start() + } + } + + @Synchronized + private fun setCharacteristicNotification(characteristic: BluetoothGattCharacteristic?, enabled: Boolean) { + aapsLogger.debug(LTag.PUMPBTCOMM, "setCharacteristicNotification") + if (mBluetoothAdapter == null || mBluetoothGatt == null) { + aapsLogger.error("BluetoothAdapter not initialized_ERROR") + isConnecting = false + isConnected = false + return + } + mBluetoothGatt!!.setCharacteristicNotification(characteristic, enabled) + } + + @Synchronized + private fun writeCharacteristicNoResponse(characteristic: BluetoothGattCharacteristic, data: ByteArray) { + Thread(Runnable { + SystemClock.sleep(WRITE_DELAY_MILLIS) + if (mBluetoothAdapter == null || mBluetoothGatt == null) { + aapsLogger.error("BluetoothAdapter not initialized_ERROR") + isConnecting = false + isConnected = false + return@Runnable + } + characteristic.value = data + characteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE + aapsLogger.debug("writeCharacteristic:" + DanaRS_Packet.toHexString(data)) + mBluetoothGatt!!.writeCharacteristic(characteristic) + }).start() + } + + private val uartReadBTGattChar: BluetoothGattCharacteristic + get() = uartRead + ?: BluetoothGattCharacteristic(UUID.fromString(UART_READ_UUID), BluetoothGattCharacteristic.PROPERTY_READ or BluetoothGattCharacteristic.PROPERTY_NOTIFY, 0).also { uartRead = it } + + private val uartWriteBTGattChar: BluetoothGattCharacteristic + get() = uartWrite + ?: BluetoothGattCharacteristic(UUID.fromString(UART_WRITE_UUID), BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE, 0).also { uartWrite = it } + + private fun getSupportedGattServices(): List? { + aapsLogger.debug(LTag.PUMPBTCOMM, "getSupportedGattServices") + if (mBluetoothAdapter == null || mBluetoothGatt == null) { + aapsLogger.error("BluetoothAdapter not initialized_ERROR") + isConnecting = false + isConnected = false + return null + } + return mBluetoothGatt?.services + } + + private fun findCharacteristic() { + val gattServices = getSupportedGattServices() ?: return + var uuid: String + for (gattService in gattServices) { + val gattCharacteristics = gattService.characteristics + for (gattCharacteristic in gattCharacteristics) { + uuid = gattCharacteristic.uuid.toString() + if (UART_READ_UUID == uuid) { + uartRead = gattCharacteristic + setCharacteristicNotification(uartRead, true) + } + if (UART_WRITE_UUID == uuid) { + uartWrite = gattCharacteristic + } + } + } + } + + @Synchronized + private fun onConnectionStateChangeSynchronized(gatt: BluetoothGatt, newState: Int) { + aapsLogger.debug(LTag.PUMPBTCOMM, "onConnectionStateChange") + if (newState == BluetoothProfile.STATE_CONNECTED) { + gatt.discoverServices() + } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { + close() + isConnected = false + isConnecting = false + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED)) + aapsLogger.debug(LTag.PUMPBTCOMM, "Device was disconnected " + gatt.device.name) //Device was disconnected + } + } + + private val readBuffer = ByteArray(1024) + private var bufferLength = 0 + + private fun addToReadBuffer(buffer: ByteArray) { + //log.debug("addToReadBuffer " + DanaRS_Packet.toHexString(buffer)); + if (buffer.isEmpty()) { + return + } + synchronized(readBuffer) { + // Append incoming data to input buffer + System.arraycopy(buffer, 0, readBuffer, bufferLength, buffer.size) + bufferLength += buffer.size + } + } + + private fun readDataParsing() { + var startSignatureFound = false + var packetIsValid = false + var isProcessing: Boolean + isProcessing = true + var inputBuffer: ByteArray? = null + + while (isProcessing) { + var length = 0 + synchronized(readBuffer) { + + // Find packet start [A5 A5] + if (bufferLength >= 6) { + for (idxStartByte in 0 until bufferLength - 2) { + if (readBuffer[idxStartByte] == PACKET_START_BYTE && readBuffer[idxStartByte + 1] == PACKET_START_BYTE) { + if (idxStartByte > 0) { + // if buffer doesn't start with signature remove the leading trash + aapsLogger.debug(LTag.PUMPBTCOMM, "Shifting the input buffer by $idxStartByte bytes") + System.arraycopy(readBuffer, idxStartByte, readBuffer, 0, bufferLength - idxStartByte) + bufferLength -= idxStartByte + } + startSignatureFound = true + break + } + } + } + // A5 A5 LEN TYPE CODE PARAMS CHECKSUM1 CHECKSUM2 5A 5A + // ^---- LEN -----^ + // total packet length 2 + 1 + readBuffer[2] + 2 + 2 + if (startSignatureFound) { + length = readBuffer[2].toInt() + // test if there is enough data loaded + if (length + 7 > bufferLength) return + // Verify packed end [5A 5A] + if (readBuffer[length + 5] == PACKET_END_BYTE && readBuffer[length + 6] == PACKET_END_BYTE) { + packetIsValid = true + } + } + if (packetIsValid) { + inputBuffer = ByteArray(length + 7) + // copy packet to input buffer + System.arraycopy(readBuffer, 0, inputBuffer, 0, length + 7) + // Cut off the message from readBuffer + try { + System.arraycopy(readBuffer, length + 7, readBuffer, 0, bufferLength - (length + 7)) + } catch (e: Exception) { + aapsLogger.error("length: " + length + "bufferLength: " + bufferLength) + throw e + } + bufferLength -= length + 7 + // now we have encrypted packet in inputBuffer + } + } + if (packetIsValid) { + try { + // decrypt the packet + bleEncryption.getDecryptedPacket(inputBuffer)?.let { decryptedBuffer -> + when (decryptedBuffer[0]) { + BleEncryption.DANAR_PACKET__TYPE_ENCRYPTION_RESPONSE.toByte() -> when (decryptedBuffer[1]) { + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK.toByte() -> if (decryptedBuffer.size == 4 && decryptedBuffer[2] == 'O'.toByte() && decryptedBuffer[3] == 'K'.toByte()) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (OK)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + // Grab pairing key from preferences if exists + val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_pairingkey) + DanaRSPlugin.mDeviceName, "") + aapsLogger.debug(LTag.PUMPBTCOMM, "Using stored pairing key: $pairingKey") + if (pairingKey.isNotEmpty()) { + val encodedPairingKey = DanaRS_Packet.hexToBytes(pairingKey) + val bytes = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY, encodedPairingKey, null) + aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__CHECK_PASSKEY" + " " + DanaRS_Packet.toHexString(bytes)) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } else { + // Stored pairing key does not exists, request pairing + sendPairingRequest() + } + } else if (decryptedBuffer.size == 6 && decryptedBuffer[2] == 'P'.toByte() && decryptedBuffer[3] == 'U'.toByte() && decryptedBuffer[4] == 'M'.toByte() && decryptedBuffer[5] == 'P'.toByte()) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (PUMP)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + mSendQueue.clear() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.pumperror))) + NSUpload.uploadError(resourceHelper.gs(R.string.pumperror)) + val n = Notification(Notification.PUMPERROR, resourceHelper.gs(R.string.pumperror), Notification.URGENT) + rxBus.send(EventNewNotification(n)) + } else if (decryptedBuffer.size == 6 && decryptedBuffer[2] == 'B'.toByte() && decryptedBuffer[3] == 'U'.toByte() && decryptedBuffer[4] == 'S'.toByte() && decryptedBuffer[5] == 'Y'.toByte()) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (BUSY)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + mSendQueue.clear() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.pumpbusy))) + } else { + // ERROR in response, wrong serial number + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (ERROR)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + mSendQueue.clear() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.connectionerror))) + sp.remove(resourceHelper.gs(R.string.key_danars_pairingkey) + DanaRSPlugin.mDeviceName) + val n = Notification(Notification.WRONGSERIALNUMBER, resourceHelper.gs(R.string.wrongpassword), Notification.URGENT) + rxBus.send(EventNewNotification(n)) + } + + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY.toByte() -> { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__CHECK_PASSKEY" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + if (decryptedBuffer[2] == 0x00.toByte()) { + // Paring is not requested, sending time info + sendTimeInfo() + } else { + // Pairing on pump is requested + sendPairingRequest() + } + } + + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_REQUEST.toByte() -> { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PASSKEY_REQUEST " + DanaRS_Packet.toHexString(decryptedBuffer)) + if (decryptedBuffer[2] != 0x00.toByte()) { + disconnect("passkey request failed") + } + } + + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_RETURN.toByte() -> { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PASSKEY_RETURN " + DanaRS_Packet.toHexString(decryptedBuffer)) + // Paring is successful, sending time info + rxBus.send(EventDanaRSPairingSuccess()) + sendTimeInfo() + val pairingKey = byteArrayOf(decryptedBuffer[2], decryptedBuffer[3]) + // store pairing key to preferences + sp.putString(resourceHelper.gs(R.string.key_danars_pairingkey) + DanaRSPlugin.mDeviceName, DanaRS_Packet.bytesToHex(pairingKey)) + aapsLogger.debug(LTag.PUMPBTCOMM, "Got pairing key: " + DanaRS_Packet.bytesToHex(pairingKey)) + } + + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION.toByte() -> { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__TIME_INFORMATION " + /*message.getMessageName() + " " + */DanaRS_Packet.toHexString(decryptedBuffer)) + val size = decryptedBuffer.size + var pass: Int = (decryptedBuffer[size - 1].toInt() and 0x000000FF shl 8) + (decryptedBuffer[size - 2].toInt() and 0x000000FF) + pass = pass xor 3463 + danaRPump.rsPassword = Integer.toHexString(pass) + aapsLogger.debug(LTag.PUMPBTCOMM, "Pump user password: " + Integer.toHexString(pass)) + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED)) + isConnected = true + isConnecting = false + aapsLogger.debug(LTag.PUMPBTCOMM, "RS connected and status read") + } + } + + else -> { + // Retrieve message code from received buffer and last message sent + val originalCommand = processedMessage?.command ?: 0xFFFF + val receivedCommand = DanaRS_Packet.getCommand(decryptedBuffer) + val message: DanaRS_Packet? = if (originalCommand == receivedCommand) { + // it's response to last message + processedMessage + } else { + // it's not response to last message, create new instance + danaRSMessageHashTable.findMessage(receivedCommand) + } + if (message != null) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + message.friendlyName + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + // process received data + message.handleMessage(decryptedBuffer) + message.setReceived() + synchronized(message) { + // notify to sendMessage + message.notify() + } + } else { + aapsLogger.error("Unknown message received " + DanaRS_Packet.toHexString(decryptedBuffer)) + } + } + } + } ?: throw IllegalStateException("Null decryptedInputBuffer") + } catch (e: Exception) { + aapsLogger.error("Unhandled exception", e) + } + startSignatureFound = false + packetIsValid = false + if (bufferLength < 6) { + // stop the loop + isProcessing = false + } + } else { + // stop the loop + isProcessing = false + } + } + } + + fun sendMessage(message: DanaRS_Packet?) { + processedMessage = message + if (message == null) return + val command = byteArrayOf(message.type.toByte(), message.opCode.toByte()) + val params = message.requestParams + aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + message.friendlyName + " " + DanaRS_Packet.toHexString(command) + " " + DanaRS_Packet.toHexString(params)) + var bytes = bleEncryption.getEncryptedPacket(message.opCode, params, null) + // If there is another message not completely sent, add to queue only + if (mSendQueue.size > 0) { + // Split to parts per 20 bytes max + while (true) { + if (bytes.size > 20) { + val addBytes = ByteArray(20) + System.arraycopy(bytes, 0, addBytes, 0, addBytes.size) + val reBytes = ByteArray(bytes.size - addBytes.size) + System.arraycopy(bytes, addBytes.size, reBytes, 0, reBytes.size) + bytes = reBytes + synchronized(mSendQueue) { mSendQueue.add(addBytes) } + } else { + synchronized(mSendQueue) { mSendQueue.add(bytes) } + break + } + } + } else { + if (bytes.size > 20) { + // Cut first 20 bytes + val sendBytes = ByteArray(20) + System.arraycopy(bytes, 0, sendBytes, 0, sendBytes.size) + var reBytes = ByteArray(bytes.size - sendBytes.size) + System.arraycopy(bytes, sendBytes.size, reBytes, 0, reBytes.size) + bytes = reBytes + // and send + writeCharacteristicNoResponse(uartWriteBTGattChar, sendBytes) + // The rest split to parts per 20 bytes max + while (true) { + if (bytes.size > 20) { + val addBytes = ByteArray(20) + System.arraycopy(bytes, 0, addBytes, 0, addBytes.size) + reBytes = ByteArray(bytes.size - addBytes.size) + System.arraycopy(bytes, addBytes.size, reBytes, 0, reBytes.size) + bytes = reBytes + synchronized(mSendQueue) { mSendQueue.add(addBytes) } + } else { + synchronized(mSendQueue) { mSendQueue.add(bytes) } + break + } + } + } else { + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } + } + // The rest from queue is send from onCharacteristicWrite (after sending 1st part) + synchronized(message) { + try { + message.waitMillis(5000) + } catch (e: InterruptedException) { + aapsLogger.error("sendMessage InterruptedException", e) + } + } + + //SystemClock.sleep(200); + if (!message.isReceived) { + aapsLogger.warn(LTag.PUMPBTCOMM, "Reply not received " + message.friendlyName) + message.handleMessageNotReceived() + } + } + + private fun sendPairingRequest() { + // Start activity which is waiting 20sec + // On pump pairing request is displayed and is waiting for conformation + val i = Intent() + i.setClass(context, PairingHelperActivity::class.java) + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + context.startActivity(i) + val bytes = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_REQUEST, null, null) + aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__PASSKEY_REQUEST" + " " + DanaRS_Packet.toHexString(bytes)) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } + + private fun sendPumpCheck() { + // 1st message sent to pump after connect + val deviceName = connectDeviceName + if (deviceName == null || deviceName == "") { + val n = Notification(Notification.DEVICENOTPAIRED, resourceHelper.gs(R.string.pairfirst), Notification.URGENT) + rxBus.send(EventNewNotification(n)) + return + } + val bytes = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK, null, deviceName) + aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__PUMP_CHECK (0x00)" + " " + DanaRS_Packet.toHexString(bytes)) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } + + private fun sendTimeInfo() { + val bytes = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION, null, null) + aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__TIME_INFORMATION" + " " + DanaRS_Packet.toHexString(bytes)) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java index df12f7b0c3..cb6484bafd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java @@ -101,10 +101,11 @@ public class DanaRSService extends DaggerService { @Inject ActivePluginProvider activePlugin; @Inject ConstraintChecker constraintChecker; @Inject DetailedBolusInfoStorage detailedBolusInfoStorage; + @Inject BLEComm bleComm; + @Inject FabricPrivacy fabricPrivacy; private CompositeDisposable disposable = new CompositeDisposable(); - private BLEComm bleComm; private IBinder mBinder = new LocalBinder(); @@ -116,14 +117,13 @@ public class DanaRSService extends DaggerService { @Override public void onCreate() { super.onCreate(); - bleComm = new BLEComm(this, danaRSMessageHashTable, danaRPump); disposable.add(rxBus .toObservable(EventAppExit.class) .observeOn(Schedulers.io()) .subscribe(event -> { aapsLogger.debug(LTag.PUMPCOMM, "EventAppExit received"); stopSelf(); - }, exception -> FabricPrivacy.getInstance().logException(exception)) + }, fabricPrivacy::logException) ); } @@ -134,15 +134,15 @@ public class DanaRSService extends DaggerService { } public boolean isConnected() { - return bleComm.isConnected; + return bleComm.isConnected(); } public boolean isConnecting() { - return bleComm.isConnecting; + return bleComm.isConnecting(); } - public boolean connect(String from, String address, Object confirmConnect) { - return bleComm.connect(from, address, confirmConnect); + public boolean connect(String from, String address) { + return bleComm.connect(from, address); } public void stopConnecting() { diff --git a/app/src/main/jniLibs/arm64-v8a/libBleEncryption.so b/app/src/main/jniLibs/arm64-v8a/libBleEncryption.so new file mode 100644 index 0000000000000000000000000000000000000000..641efb745b5c23483796bfc031ce1cf7bf1ae240 GIT binary patch literal 22680 zcmeHP3wTu3wceA%V;%|5@Q_ym+BP#lcnM^DF=RlK2pAJos>ozA8JL;8$O9yTC3S2s zD)th!)moK+*v<@~RH-J_ThZ8Fu)aX0N^flvZ97Tu(N?`PYMlG8efFN53=>el`t`ft z$H_O@XRp^@d+oK>ew>-Jb?LH8Q*=5eFNHnHsP^hG6=D;JdyB*k3LDE|di)>H#&O!g zeW+9J*4tE&EZGRPPHhaqCug}@&$+&Td00{F;|HmwyNG$Iae6o~$g@36pqx-`bsRW7TKEWqT$#*6AsDEGf z66Rz@qP+p_Df)X@lybzW-E@4&+?TDmij8~x%EyO{8SQ+n@x9l!esuhWr@wc_&q$Y% z_?$~OxW?f_cAbdN76~vjM zG>OuPGELkYL^)iP)DQB;e=QN}T=}J0KyHc*y7a(pAvIDhEcB1}Jd%W#O&kui?KWOJKAD#8v zH|D?c=nX3`y8F$+(YCj0R!zEe*4)cieQ;01Q}5ilWsu7|FZAw5TX#3Tw)l;MZ_j`J z{)b1}m%efGftz+)u3K4p{15MK*i!Yo2_HOj;+lyS(MKBp_Q=!0;|u>;*mikI)`6l> zs^P)fU1)N^OJSyXoNI{`SS3%ym4uVO$bL!~l^4O_$>2{90RP1Ra2oeya?ZuTj9`C{ z6*{%8GPaY`o7mm+Rroq~;z%N5P)NbY+RX{!H=(<7lD^KJT8;3IX2)Cz+ z9U_HsjTd@Ws+bri#GJ67$8K zQXgS|y=Zrs(Ep&YPlf2$v;pjJwUD#zLbbs|qTM2tq))}UDqxR*R|)#V7pQmv;=dD7yp>n;W%vt3uDt5T5T(u4BNs=SC!i~PlTA7>Qsy#2L@_r-I zi`}m3sl>qg`KX|kz6huz@eW5_Jv_|e z@{~K)I=vOl<#D^p;eSl{2OOseE>>Mx+)(ABxao7K{_u6~Dt9e{&R*+c-YRds*ICh@ zpwd}UQSD;TVTpUA*QL62U45;qay_f?mR3}+%dV@YJK@oy<`QM4DC_FWT+^qEN?8Tn zINW8g zO#{!2LmAtlfy;Frq3_kewd<*74P3j93~1nDD&nmi(7;9N=kOK{T$qBx4{6{c^>g@P z4P3j=c~t|aHL$$i)WEgt_;w9ku1AR{tbxllG{HaAz{S)=VD{nWXM(dCJ23LsmqkZB zcX3l@O2+YwOyv#v;ke%b*Qw%o{W;WAF5$Gi{yWsCY3eVao~x<9jC!f2ehl@SHTC1D z@7B~$p#Geu{x<5JntCVdDU15r|10X#H1%%Ob2at%Q7_fh|AG3=n))ZG@7B~mMg2Lo zo(bEq%=t~v#bVR99N&^KM!1fMvN3%U-4h1wN;=zY+Ae#LKs zy_0u=!6!1@utW{WgoJP4WvKKS~`|6f$!&JH~Y`43V42wah zYxSix7KPd-w1nEOZ3!zzOAmC|t4xTPE@n;THCygHiTdq2Q_of%YdWczApe{Q(H2Z* zHAJ5Vy8WPgA9OG2(t4f&-TO*fD4>8Yy|KurV^-f_W|cfX1G8Ef;AwyX7qYL;@r^_Y znqb@bmV8}fQP4lWrD6q(Ru!-)^()Y}swL=O)uPuK%6%zpCBe{#1NtA>qQSO%Te=m4 z#pLzo6pUdbJu7Tc(-BKf2s{M_Hqu*Qi%v&f%Fz#IBLirs2lfx3A3F4-1T;Rfqka6Q zK=G=aAmHYati}gfc}L7S0sE>=9G1pvcpZ4Xfz{-j8jJFeWaW??$gQFKUAUhP-AbWb zyJ8HLL2d}+b-B(KEq^vQN_c{o=oTGs_K%Ciaf|KIUH)q#4*~x!#)fD*l|hy==s>g~ z;6fPNkaBIr0UN)U0=r;L^^297sbl+WBF8moAJ-D_Ul+;KG1{u62cUxiI+*uE2f)b( zGf4-~alHMS7X7zi8wGsIH7#9=-qMXR4f)4LEEwYgj4}C!PiO3*_IsdTP#GH`T0Lw? z^fN%W9dz%3Zl5l-XD8{Yq=th2F_8d#0lHZ8FwT-E55ABEU&w-Gbk!DZE8%Y|xxZNyDetOCuez-#l)5Pk^R+z-=R{z85z$3{m!a9w1#auvoW z!&0)5wUWNBjkZ?OH%@oGt=|}`<9m(j%V_sW=+$gbhcBFGD}omsf7$FzL&{ z_w!|{OJByl)|YdO}7gphqS#;CY2NBKu3%~1hmRD|eceo9T^lL7z8{<%reYje|Wn%s07mj1T3c%w+9$ezzc4~`LBL-W z$v_--=tRCio4bbh+1QMDqIrPwM$kUuOXiFbB4-qeoB=+iFrG7fPq64fIm7!HixTab za)$R2(Dln1D$nV1M!*gl^sjs_az-|bmW#O}9yi)tU=g{%qUM5<5Q}<3wy05OvwG&D z9K)>MY+KZV9Hqurp&DO+{kb=GPsx2L4W0!{twHpK#}{}gzC8EkHgH%xzMzwKuAsih zLRZb)FX>MgUqlm+uN8=|X)O8!vhxKg z4c?7QtXu}g*EBW0ycgs)aF~cMFZi|b#p@!zoWN=0Yb)f&V+eVS@G`ziZX^E`u}5~k z%@%bDeCZ0r7uqKqdjO~S^4w>OQhZ^4Qs?8Nr?K%c*m#)6#y1aOtp1G)&g3mjOtq-djO+#i3hSzCRvx1LLOh2j1}vWv1eYFkUjVs8|^fG4qv-g*Wh^~ z*XjkF=S}Ft^X9dS8#qklO>Rd`-sE+WH=W?^^EG4WcF3i5R-SW-H7|uNq%kKN+9RYi z!I#j+8qmaHKUQHIw6LG5uvLJm`Cg0#Ls+zfspDTV#1?(V&W`qOUL5@Visu5f zf6RkEF}n`1LBU={*M$A#tNN*Pn+&Y+ShJE5*@b;#=V%rU4`C$+NuhXXvYHIdF7wEGa`cU5-I(<*ixSbQa(8lkFu!RA?Mi1QY z0uA+{Q!#`{U#<`J1G<@;K_>I0PD0``ne;fb~e!%g~P!^Pw01yS$DI1zmha#x6D(r5~9euj}WiI2jk)6t;lcq?j=17PodWcD}Ywd3>=>>DJ;gzCseGlYFePM4{%)rdV{55^CBVpBKd;G8f$ zOtjc1B&9_^IW5{l9H;k_Gf&{42k9U`Tpsx+bUQ(|L33d6F)9Xwo{b0Qb zepMb;Fb61&t^4P(qXBP4&OXFz7v!4L*vNLAx1?>c-F2(CGKYL{n|CJP*CKY*Sb`pZ zhOX2HITjR0(4}XW7(;FB45#t)v!i$gIiwr$Ux4_>cL36XFA6VW z));I-cF8c~3<|N1vx9}G^D#jiJl1;_344NGYr}t#4T0<0ddNz;htXd9R+|;=tNE=> z=rIm)`yJLwe$$2V*6M;7Qgv}am(kE=G;}#fqYL@R=*D>7>2U~MKu@&X*TF}+#D;@^ zIC9r_U|Wor%wJ*Z6ZnwRqKN(00@$6#tNbS0U25(+WX*&ASvtrBp38)+_edsk5YN@p zrj&z_BRi3cF^2v6g0p9}FB!;9z-8&sCQ8d-%1cHQ@}e~cUkEE|emzCU4A7&$-N2t# zN8q`Rki~VB_C8(S6gr2YkBnQ)H|bQz9AQOX%;ERYHHcW?IaU(`upPH4#Xvzk25hYc z#FG(gpXoZB=lyEi1bsussAN8WlE(2X`20I(^!dJ=RrG1>o?e`-_bNF1Rg|MLP6C)m zdCpR%U@o1EGnC1w(|PY2)US`6559iqy_j=? zuvXz`&@_iNE0ZGd=N(4O3Eh2j!Va1v%$O5&BIh+Lt0TMGR<{ss3eLZ>p$EQaf^+8n z@GQWI#^79H%@=F2el%E*eHKL@w0u~PjiP>OVOWoS3_6(y1Hc&!hj5O(nxE}pPAG>R z_*pP=AI_UIB4uO;;N_aV8@3JkCni0=3@Q^NlrsZ3`wl{O7GwwfI0sk8MW{_W(+&D@ zu1on-&WoT6w%y0io5|OWM|?Rr%ZwPkW^t~^&w+8iJfY=7_yXxdYu{$j9HTzlC*Vx( zTJTKB3D~dQ6lgmK_a|^hw>rZ6g}s;MNOun6t~@>$x4qSe$J$up+Y|au=Qu(CIW3u5 zUwAe*N^;dbpE&QOb9unz-qL{cF|#<^^&&qn!d^DuAFrN^+Q+v@+K@6H_86<$#*XuN zMLm!2XB)eE79Y0_&iCTB0T0E005Z94{K6-7IP-*0?uHF$Z_#WY%g?$VvR{q9&^eZ% zqccy9Uk6CG?vNFGm>PVSg!=)(41*6@&CjwqPI+!iFpO z%Z|*Ss^`hvhjDIeL7pM_bny6)YxRH`k#Dk4H{x87`wF!IU1)FoeR=*Yb!laDI>i2t zWD=f+wh!(?YJEDUbJgSvsvjJIUj8jynxzI=)-a;=PUMs^wJ@wgJ?I? zfb|5<>vJKC?8$Kc74%;fnF>6E4i`x{_O*$9*9}V;2jmZDnhKLS!J86ahwjinfW4pS z1GmjCTlBD4pHW?&P2xEyty_2G!^i2YlG*try;&j;@H2Ge zfpOf|dArDQvfVt7H@5H*{9l7^4X=o5v zd~Zi`u#RMWZ`U_h$J$7zA;Dh1PV;;g^EBq@U6`XgC!+0fwAU8)!yMd!b(@@n+p&&} z<2qDa|2a4Vb`-qG*&SF5#(AkP(2M7~O5L1Y(hmXSxehQnM-yHCaEcLTrF*P%)ELEm z7p*UmpA1L3a?D;`jWd2WE^vrdiTl2$4axVyVD-5L$>lK6)3Xa2XEk1?sN>(ZriJh{ zZ-)AwOYSfr*2xcp;NRQ!V9N~bVQ5Q%irWJOy`Vd1I3EBiDOs<6myX_)D14+Y{Fz6>vSieqzF$;1f1U z(oaR>f?;Lmzmx3o=Z$)`1)j8o)D$|>)_*Y}`Lw03F7 zeud(;6Z;OzkF>u(n8u;S9Erc~h$c<7IPXlZ&a|+qJQnfc? zV}_b1L>@}SQC=aKPosOK6beCG#inQ#)ggc;$NabJWz`TSzfXbHj>+pRz>>ubkADstw zVy!{X{kpK1=|-%U(3*qqUs#mpUNh*;f}Zvxomh|X9D(tmXJ{vP9 z;hi=s*JbM9rY!6s41m+VsCVKG+bZk-GjYk>XgPJ;#rP11F&^AK8MBm zG>2hq1Psp?@V!6a@1XO3d{TcHH_SqGS3q7EW3H9QVelOR zE0^**xU6SSFAM&tl|_2!%`b7D>9{XP`{lfS6K}r&?dQSo3Fi_0p|f?$d3xBX3w<}D z@9Mf|a8oMis9)P}8Z>&l&R`sdy4okBaXb2yiau3C=1IT__o6P7 z3cdo#w;lT5ind6`cIc12laZd;(L6;yB008TX@4L^B+G?};%6UxDPK@5}8+p9bR7gD(y8NGABo zCEq^tixa3HGpKF!3Ex3B;=IB_XBd6YHZTUxK~40W8}n4Olb&JVd4zc~E5;5?7m+dv32x=lD;1(Wto@x@EfIB70#-4vx@8Kr&jol zm~NtS;Xa0-!Dq>_SnM#$iuPD6j52~!j|KFI&R7h-$#&quKpx6MeA&~3@=cVDDEIs| z7P}W^-rr&|`hDAya4hyJ%2jv}{UOSeDCu{_t3HawW}|#D5{nh0Z2UA9TaWUh&ttJ2 zC?hBjpk!Y_50r;cwxevsm(e2x$3=S5rMt0+>9$PKO-#+;b^0wWed>=wSNe^{%GAjt z9!z;)&|O3BhmUg{{RD6e9_VdH$(9K`-QyzO)%b*g9}k_A;kN+X4x3P)li}|N*all2 zN`fc7pC*3Ta2ratWLPE@1b-c$!gpga{u{d`!|+oB6@C)sAlP^h0R;UdfM7PZanh`jNc`!53`s9r8_i5quKhvp<9VB@iXS&j>plKk?b^BGhoyjjoom6IIrA1Q5I^qxIs(q}oVCDN3!JsU zSqq%Cz*!5NwZK^moVCDN3!JsU|1%57_a`L2FF|hQ+Qdr`Wc{Ut`X3YO_^t%MBz;dp zJtFGjwGHe-@$v%sE&=&|2ijNDH9{?zAY)nBBhvNp7qM!7Bjm|<8f1x=49IsDv`r+|C9A4id@YtU7y6lH&?i()-h!>dsyGr@K zJlB>RHvgl%`nR)n>!yG4hrJtLxcSIUpMLkU5BI;m`_cRN)E;`W_pWa*SoFUyp8xP) z{$BIuoH2v```otiKN)=A&{2(@J>Pk3gTX&z!o;d;n~N?y{$rp zzyFQ3VA-lyUi~2SnSJ@ZA1sZgY%RQKXW+_*Z2x)Z134c*{ltl>BVzwN_EPHTla70q zjC=kU-@CZ%`g7_^zJJC4Otb9RcIo>q>2I$w{jq)S1;+d#=dFJ3wSA>cKYq92Z-*CF z-toqYV8zuRb-QnTME~ne-^!l!^Mk(&|EWIX^8dR1w)L0%YHgnK$uQ^qYg&K!?BoYK zBKMB;zV)NKe>UYmx?a92>(ASF-J15yUvoW+e>!vcft62<6=x%vS@W&4XV0E*%`A1+ zxyv%Et1@fnEttPx-W-=X(?v&(nH$};b$C%trZszZc1~uNr@nrD-37B|$rs72tFB&G z;jXLRQ0sDMyQ(W^)mK+nxI9j8)vSt&jg>Rk*H-)7uKLWmvlo^vbe6j2IOjS`*UodV z%_%#7-t0LG=Pf8(;9Te~bc^%H$T4w`V$9r=~JOpu7 zoRwY|ny&_#Dj09nVPvvOV*M9g6yB6uMB3}S5rFd&+L3uuf~Vnza--yz`BRo}3PQ;z z^O3Amp2E>#wdCh7SR@{iXxix>m!y~cDwMG-+)y7Rzs$$7%oB1*N4k~#GEdUsE5Rkd z%g;YnD8-bvEX}^KqKPveX+rK4&f78V( zr7TONU?D)-Ps;ldZnW_?(0fxQePa8&ff$aDaC0WtH}d_a($11!wlB*^fS~?M{ycp7 zn6A9#YANZ|THpA~`ct@}v6uXEzLf8s9U=Np{!5pXC-r(BFm3yCeN=Jly7{{xbIe60Wg literal 0 HcmV?d00001 diff --git a/app/src/main/jniLibs/armeabi-v7a/libBleEncryption.so b/app/src/main/jniLibs/armeabi-v7a/libBleEncryption.so new file mode 100644 index 0000000000000000000000000000000000000000..560c7a890510c5a429c6fd95ae2192a192035533 GIT binary patch literal 26448 zcmeHw3wTu3)%HGfNhZl8nFNrCQ6^kuB1xD8Z4^Arp6{AF{KPI4bx9zW@bR%HEaZnLK5Yv zz$>7V4rv5xeFXV4Y$0O=dWxCk{3AbL>`0XiQ?-oU4IsLduK_aO4X9QC1kC`-S9wfA zT!pPN~q33&u6e*(M^Xzs*k<_XPr z-Wh#4apke=tL~WipFr-$i`;6vhgWNAXpVU-%A#ugmde zz|*d0%&){ZA%9v#ekbCeOlGV|$^Q=8Cwx!#VWJlU`ZFTRKZN)hdr)4FxJ!wD zfOs$Dalzjxe>mu$xKZ{uidUk38RR!B<-ddW{T^|n67Leg|0>4X;^g`#KyTO0kPqop ze;(;$h3xA|Y#3`rbmdrd2&Mk-KtB!irYrH^gMWJ(V~dseI?$P6Wo!)6iQYD($B#k3 zQs{q(xN{<7HYFYdyeosT5~Ndk3*<>3#n?_I{wetVV8(zw?nC+)kY|CCZ$$Yj=vS5R zNyKMEpWBrDw-CSMrU808K<|FgqkcgAs8jz5{H7}Mn34Y(^i94%`CAbmYa6itYUoD? z{m^4#ec?8=GZXeu?R!7+Z-~hMF3N4kK$xe{9}WEW^^B2U68#T=pSBIqUrOx(e^lZ5 zcO(A<@~0~CU9kI)!Ox<^&!fBm`!y?Z&t>x6M(qPV)&5rGzl!#&@jleMcI<%t3P3+8 zlQApWMe^MX{#CXCd6uI7e$)rz`452p(-HDshm5VrPgU|+adDZ~UTm*(ddurr;q2U* ztg^hcEUUJLaBih@R&|+YwY#porkc{^(o4&$?Um*CIN2<(v#dDZSy!CrtSu`pvX^_x ztC!v4T+JMnc89}5Bpj7gufHJ3pi_;`)H>^CRlDrfWljg&MDg?g>sA4mfv!tail(Fyh~UWTC# zapy9o#@wEoGCrX6r$pqU=VC0b<5^^oVrbu9$)g^*y+o$gzRFp=YN@-}UR%7FXTm@c zY$&D@t*vvSxk~e@oK-eEoDE^A9y+lMrRra2hkp0O_9T5-`NTi%`Rk3r*}7kd6LM~Ors0Db|Jd`%_Ag)B`~07KSFZW! z*dK~KSDiaIcjy7X;VIA4b6)?+GZ#beeDdLn#i^C&U-G^A_swgL>(9T{JpTpb?XY2Px$BdfaXZGF zif^8Gx9)Cg<19crfYx5>lZyc5jR0f=NGJ5rIyUm5brr4c=^?ud09xye1YnuSu++jH zSAMXB?za!6(3*`N(ltE^fMEc#eHMTovYYzQ8VM`VD?YJE%>j^qV7bR_PJW|4SYi!& z$XCd>Xah$+M7~CknZLjNMeAUCZ2XP2EHHUDwg~(oKP4Z+GO+(4AEZYMP<@UkC@=Ee zL?uk?R`pT+6-&%-Jl2R5b&p9tKTb)fzM}4YRsW5s!h_`Z<1bHC;Q>m=#W0b=p-8mqZ8H>hGI7ohD!Z};cQz7V*qF*3}vVGm(A>T87IbbAS7plBtGPJNIt29m>sF_;`7j84)<7=zYP!f^KEgfUQk zOc(=2fN&OLpA$~N{*iDzV?Bh?*@J{JxSb)4jwumFN4`in5q1h>exVEe;){g9BLPG3 zw_mLJK9qmxk-zER+4#3L|JeJ58m@~7S4M;#5#c2f;RO-l!iaEQM0k2ccv3_-BO*K| zBAgl#9vTrgMuc?{;fogrW8 zF|gP5?yW!0%XDSB@};3m@}(4GzGP0#m&Rn|OP1-25MPA&BE%0#J6jJ)I|7HKXKmro z(UZ)gZx44cbH0>nWWh)Gsbw#?!l8FgE|M%pX0Zhi_`)5p7I^bmnou$XWivo8!&o8a zOV*47*NzHCYnF>mBOVinAY~HI+twFtGzX*EN%5s_obQMaAZO~4xxwwm^%84cFA1%n zaAYS+t(P>dbAtk~w$+Ec;gaRZdP#?{(3&qzPmKjXoAHpe&3Z_BA`tFaBuxhgTWWpo z@V|sR8b~S^(o$_pj!E0hNqGe;D0WPG!g_UHy<09XSV7778R}*jqo?lQja(KEm7E+W zh{I3lsY+#o{>x1dHT(zdh) z@-@vU2P>wcrqy`A$b!GyOV((EH8R$PJMK`dkuMddzUE?<#5QWF%wuQr8?Hl=pY!)~ z{)I-$Ei}eJ4@IC@WGsh07NqXKHZ2$}REYCNY!YLUvY6++HIgjXBktsu+ko^X)3=X~ zbKl}d&FRrMKkODp|G}+w!&1}ZR?Kuypv@cLl|E|#x+*aqlYA^+azK_s_^>OLYEjGun@@qw7oiMN zQf&*b0{s|x>Q8$qehmC&`%}1{+dq+)K<*JiGBTMGd4t1vw1c&bxs$O6?!p)i>;*{Z zlXZZ*0O!!xjssM!vLSE4&q}6~t@@Uc)Mb!+4QwTsc)RKi*Dj>*uJPv+pCZN6>fs$3 zz2l?`cv?B>SCLcpvv>$&O7AsWvo~V%~X?S>OpBhGxZrHfvg!9 z*Gx7_o~}M7l_*-NSG3}VRt#J#0<^LhS}6lJ0iz&|m>Z4M^Wrb-d3{dMsv@o%d9T~Z zdz~K=_<66}@{L~C$nys4kb2z{{k_hAgs8;R?%_Fu^?VHT;Ss68s`~5BEBY&? zezbdq<7zR-5f0@+V{brXuM@r0oJv(=Z}7OPv7Hebqp+;8ovH6|jae(hq3Z`}Y-dJa z88o)spAVT#1_$X(<9c7RjgF}VA4Ov}uCZfMUhD3%QgP4nZI~%go(YwhD=;fHr*0Bo z{*3f>2Kw^DV?XWJ4a%9@%G#DM7auKq>)O%5Xf2KLTJ4i!5mGOou@6XA%*)%2_hC-H z4|DPR()3oEukTal>-!?+>-&`XS}jw2VdKRWWp;65Svd4k*Es2YXsaFL`cBh3%O@@$ zk*DFa?EA)dcvx#ZygViEu2Gm_GbjX2WxTz7H`h~&7!GajQvIhjncDEd^1jlm#jh$F zxu)t%2Q>9y1@f&QEtmVYRngU?*4?GhRfVdnbrqzmb;~!2BR*qhlB%GTdUC>LJ$Xeb z#*Yfw9tEZ04wPgwDq^yQQlX+kJYauk(8_0>U8r~(`k@(>Ry~5SN&KnUDh=gYR98K1 zl9_8!UiCc9S3T<@Rz2&W=@}J5`oz*hQfi>^8~u8hU7jyfT5IhA*;DN9^1~%_Djq74 zCEV{??`p^$ig}Xc70M5|9$Yf9Vnp7&6$h|ZNo_67YrqIVdHY>L_WqL3F;~gGlV&)i zTR)IYt!#8QI8l!@4VvNlO5md|n&CM0is)%??+%uSLvNfICtZM*&vPrsRuD(o$`_2W zJghYuDpV^|h^!n_aZ|sQx1E@ZF!Q!XGmE)h8|b>7v0Q-6Cuhz*dC4woML6`-2{|RJ zKcz`Y8Q-7Mc!FkNxmB{y45`>va<%x1OZFK<$$-zq@HSslA^VKEe?;<>Q0sMkJmMU& zwoXmmU%p8s+NnkpUs=RpO)xa0A=g?$s~)TCSA8bkcJT+2?#l?LO>vN6ptf)r)R@)L2 z*LTqZ$`P!3|H%%cOebxfN9MF6Il3w8ae;FZz$x4j3+Y(POSfSk5AXt(0!RlBG{=hK zEkDY;#&wNL|ESg(LHsL!9DI`lg0l!LK8` zHu`o)L0_MtdqkcJtfrKco8>0v1T*Y&)G8zJE+2K58IP5|H;EPtR z|9#koI7P!g#4QSVII!Nx%o_03G)8UJPpi+p26odl&N{tt-tSJ|F|X(!LZ8sxzC!4p zA=pL;exdRFNW+rot(vB!ym!1sw!>~JEm$@Fzk*Y=Y#~<+yikMokuQB6+Hs1tSfC5r z9GoRJYs5`bBGWWz6dha(9c+?t>;xGY+8&QKBM)tUQi?Vi@+gmT1S^C8B8@#MC7KFs zL?ztu9(2QQtpxvxhsAh1gaZCVJp;6DNQlBKMahz%#Y73w$fGRV~+;v<7 z@z4NDG5uB+(Mnl@9<(wF{O)ho`Lzw2&1x&IQ(B?f8ta|yO(LmHGEHp+&1k0k7Mgm{ zl*bvf;w#aQ4sOvn*qwRFZrVm0@POT9sjuR8gO+jSK#ahvd zwP;-WI@EUZVgX~D0d22pUVf_iXyKZ?qnQ6b2INb|BRIdn$}a``zSInyVNA#9id9t# zRyL^_Ux(J)RS`qJeQ5e-V*sE zP@-fyt&1&2ex`wOkNW&8N}rDfeOf=^v?TRqKEiz+ntw7Qpr-wol2&l?1**a4tJH`( z+m-w|C)FCyC@Erp%2P^8-bv~~RL*~1gPrD>)M)e(9i)+4I2OiLW-7)=6Kp2SFbO@j)r(zl294H>a7IIW z;7P_#gvaom0P>7qhmQA-lWs!Kora!!Ge*vvfTtUWpT8LtE#NgKBPlQGybiRDXz}p# zbP_X=u0?uuzw82RWHau@T2!_I?FzTPct9j21?=t$??!koZ9#II%#> zDtXHaQMzbQ%L$oO1)hr`%fL0 ztPYYb0!ROOX40gmbK6o(Fj=!%dRl*6V`Awe5PMPfbUu4(%wLCWz0WJN=MLlut{CsH zVDBNWtKH0H^Cr0p+++ilzO$d6V9EmhA0Yn3WfW6-w<;8=-a7Bk6ngu;$*y_sEqvx6 zS&{>+r4oH>_iW4)fS&=@1AKsLKnY+zfTTRx^Am;U1B#UQUnZq2qXxBC=fz_6z^*TQ4H8A-0ML+|l48m$M~MY}aME|`RLTkv7TtEpwY&kTpBELYkYhc=fh zVLFdoMiOC{tqUwgNP|$gqXIo}j4{b_xreO_+^v-PfkJ^+F;QsYnw~qA7E*6oz&&Vz zQEy4Y9Iyy+YDaF$X74;cCXV1eV*&S{1;!H{g%Q+9UkiI?M^IbLsV&A1T&6}RXGAUe z9(gvFsUaWzY%!=!2Q|SJ>s=rGi6$0)FvGhp7%$9##z+>~Q|W9lF9WT_Zj)A{pxC3H z4&tN*+Al@g8h9<84(4H;G#TYyMl>?8QzmROj)I&qE?Suyu`}QeoAS_8KAz&2pbqN7s#v9(c&kP z0V{8vQlj1z)ufA9M;e;j_WcAuMs5ZWeSh=8h{N~ZxQ5uxF^?KKhn>kWO;O+) z1+E6aoEAVD8?EPSQ$5zE2}*ivvY|53b5~6an1uBQcU16(r7~CJ!yhF zp^>bZ&}i6d$TOYS81J$S<#}>kK%B-(IX{b^A|u=+p9j!5AMX!$#G`h7uJ5!4C%c=u zr^I*@n&KZ%#vXfJmr-b6@Kfr8-h{_LktVec!HNG%-5QNnGMag*^V-%UUumzqt;?9I zK@E*-end%69+lI$Hb}qY$^xg@(H!b-@ zn%at%1yZF1TdB<`B|zT!-ofdk^5pc*m!&^5g3=S3NHfXjje+;R(hkk*O1Mq~E#ds+ zveGK`6y#tCHk^u z>3qFy0nzp?F~Eo7v0jY#OJBdQD4ATN58o zqEn|XBRjl+XwF>t)>qop!Y=KQnF}7_lxMGwtgljy8I-D0#b`8$+q$j<&W-bl=u`L= zs8w)1IH;^j`O5OroDVsg5+i!Bi}&Dx77z4-`K!N~%IikRAouI!E0iQ3AE+<)_AA%k z98oTUdqk?*+pknVHlm!&gF!EjiZJUJ1boan#wrHPN8_wW&r!UDU;LL;ZC zaXUs%6CXKE@Dq9D%;F=b8W)UNNO6xFl1gkin?b+O09OFV;sYewD{W|=10PLxCA+kn1wU(0_puCKeGgXFGnH{# zXwpPj`Fq^T0wgjF8mD=wZ`gCbccA3JI6aW2TItHQ-;b!RT8_r)f2}@^b*k*L^$gy@ zaiLM8j7;(#+}B}1n_+bqodeMhT!%f~rO=nB+VI`PW_-Z40q|RVoFt#;+@k1Dzgg?o zKz}-n3c5xO>aKzQv^eFWF(JvAOPcg*F~bkcci$yFy5_IeLX#%0NmUoT++~`KMXSGA zG8R2!AXU}SmFsVgD5-J+|A>CaHF-uIb_aap>U%11;H!(W@POA}LispU|OC z==}Hg>rk)gkWP3mh4N1Mp|>LV-Xy?1)6}z_Kf{j<{^*9N&H6`iK6AvNjKxtHi)l8X zvDnzE!C0IGjTuVRe0>w0x@nr|)Q#o|L&@;-!|+=^%@UVF=2OuDIG!{TjL!PGqX#ROli=dlKVbFO(O>9 z!ah8AphgS^M2&ZzO>n#Oe+^#G0qFcw@W#gEb_q#>n|`~Mxn9l-cKHUi2fd&+f~c_; z5ws?$^e}SMN#zjl)p<$oBySuf7Lttf?$jtZmWN_3-(B;ClE z1a0>^A*rNoALcB_f?e7S)Xj)%f9tF0nYuB$?)!9_(Lz8Nts676Bo3vRxosbP>yddv zO4NxzE7&S-7QJ~1BGv(M%!LujrSsF6RNVCkw=Kxl-66g+%NM-pyFaL9`aU7{Dv9}u zy9_1qN3}1Q#rU*KA?wMxUG=QEtH7RlREsfHb8QyBJPI=3RQ%DCg`NJ`_h}~!YO}<} zKYD^_9rZl~T64P$*$?ivE`c_Z@v&s^ZJ$}hhp?kbj!PlqNkh=UG+Xt38l1tl37Upq zcWAe=;6-K_p&3bhwVN-6*hwn=d`Cf0gAZ5|S)zpnxBIj^48cSV^GDJP_G+7CX}|1k z=rG{K!>sTUF0deY38tyGuKlB^&ZW?My=yym^fe37>9-w^G2<(exKBHUpiV!x>Onj! zI^LPJ;(cmE&XO22yWvM|$-$uDZI9%)vzH`a0#0AE!k=Ezu%Ss4N%BTVj5$7_X>5&-X(wAJfbUIQkBJE7_8QE>))<$r z>A?}27Jc)+PL>$Nh-2(!Edsu*wM`lLrf7ZhUe_=&N)*y#+orv#F(+o4kN@L!tC%j1 z5-){Jy~6@CgF2?S#Iy_J_3eq7`r}rlr}km6uNGm3xPcX`1EV zLyQHs(|2ck^WHtdOtA&Av%Pt-bK-7UjTz;hydUMUz8yLrHzBMaaWM`g&vajrJhTn-94=3OUQQ^-zMsT4*)ER zyqPDyPFyeEQgEHl?g@>l zi2Lq>9^po2>1xxMAuD#^YF3e%^#g8_< zcs8a=Cyp+NKija>n+MDIj>9r^4o$xOd3WrK%p54m7RgIK@2&>U=Aj+0YaeIhLv5^4 z*H>UPY}GgI?2Kj@uEZO}#(V?x7G+6li@`537<&R*GpL$y(vv}2j0aEjiHE5l7IcGi zN$m5ZU{@B@NgDHsjsU(hmB)UT_(-!+6vXKTP2w>44&-b82=XOh)VvgWqC39N7y~~s zj0g%0I4Y$@bA4>vYke#+y8VW7GiHl$_N9=m8>3KcJjR9^oZVjvWptax*{Hw1+xlkI z2D!gC=11dmGXvJ^mWueT>vB`ucJv8`cRFIQD#!TJtpPQex~^N( zXt9$#CEZ-Mtv0kVvENgUb&>T)^jqJEzGR$p1?xj9^!jd$P2H@;1|57b1m6o=8G9Yy zAMZl=V_?j&jBNkn*{G`Z&GBb9Id$ANrf$vi7K}W?=y1p$rm^O|G`07B+gNj?i#Wd5 zbt&|I*9Fjy1+RSI9{?%>m=j>Y_LbfvlC8ieOBg*v+g5o2a2Gq??MT)DPR7b#sI0F=@O=+n8| z`lB#=b?N$w*xWN)S5TPGioqMs)4HPR@ zWl?@PkEEmW&Mhb2HqLuJ52Gytan~r^SxZE{O~ikg*eE85x!@^Fkd3}MQ*6Um5N0uu z-(MH~P_B!8dxasNw1+8VUUQ0(xQ&G|aZJ;4A0(yidCApR+eK z>%^f2@qFCy=0&-zF0J3}lI1XC1QTAEbxjHUgar?tpSnwEwCoZv%252T=S{B*@MoWZ zI(&T5DXWT0q31g5GB7Vd#?Rgm(tJ{ZiN=VJU)8<*P-;xuoYa(-#B`y3x-~A4kgjcu zPuI3jvg!jF_}-%MJy7=XK9z4S!s`LX^e0+uQkoed@cjC}<>}=-?*Y$yJ9EIJ6g+^@#JrXeA+@D_iz4*~V9c#-iz4+#NWDdodIPYIOZ`Bv zuKQ5G)T@+OsHF7-TdaB@Y582ghjY81v*Q-Scj<^^w_-erORGV{A91a?&N3Kv7CPknMi7%hlI=k%#`mlm^w&|;V> z_gY=Ep{04>#n5f1_JFQ3MhEqhS=`szW@EtvZ>l|c1}oS_t)|u|?P9^_x`hA>KGjXF zx9p;J%QbersqPUk#tkXJnDu-k)(BULB$*y7go~j)r@Xtgk1yX9KgTN05OJE|zbEfv zsQHwx(LCa9tRn=BpUj-@((~0_6wTRjLCARVWGZB|pv~l41~FmwP;qr$yer)$G+?}L zC@?Pl+e=qqHO2N9vh*Yh%nQ;eiSL zVO>B?7sk^5eIr)tuUxqA+^U#`U2##FZLIq~aL@#O;z9TY%gpT(HA#7fpf9(eD_1io z@8F4rX$Ma%{w`K)V`Wal*n?8#JYg)?2F5p`#UjQiE2xX1$tRQH!CBe(IxH{@p&JpR zT~vHQ0@hLqa}q9FNnZ@zeUhwSdh%ju=}F9Ou)*PR_?{i`6Zo?gxGILRc?kE?-#{V0 z72#&geD%%rJKPx8SXcC8Q7`Hq`*FGUvG0^?9=qfc9^2<)kFj8^WOhYEMqP`6+xW}g zEZUJ*Z(YQKS08l%KOE_9WZJe#xF=&*L_d zm)UOiDl28LA^)fU=6`Rp-?IJeAp1RghrP?%*az$w`;dLiK4pJnU$9Qr%}%mDc7}!6 z1$GIYN-IPOF>tO#Az2tEqzD_)7I*&Bn7>C_#vK2&(-btbX7&pEHG3WRAhoaq?04)i z`vZHAwX>t_&+ISk6Bb~9XJ4`ttcRUqr`cI1v460ynM(ONPVpdruj22O5$`%4mf!SO zD(-yw?crhhy@H43x0{FMcL@*E@AU5cs)%7|3u>6+gl;6cXU4GNo0Pg(Au$)3) z2e|X)_YxkK-{0q9`F$4;%kMjRSbi_&Vfnp?hvoM|9+uzq7dh^H`MrRL<@fD8EWhXT zu>20i;k=i}<@a13mf!2qC$o`%4EO^;8{l2QJAmH<4g&TAehYXL@EYLPfIWbnfad|v z0e%VC26z(C1o$~%3!nk;Q@}>RLx6g~1Aq+x;_U<63s?iV2jB&)0@MLK05_l-Pzk62 zxByE54#0ZI?F23b6a$t3?gT6Z+zu!L+zOZjC;*6nJU}kM2KX*uI^ZV2RKR4wBtQ

!wT2Bp_igxdcx`jD)_0U+y>I$) zitBv!z?5(LFub-6<%53>uRRJ}@M(DMabWk~!fQVU-uQ)FZeu6aYxZq9A=BFfjBK_O zxD|mO;Df-0J>j*7frG$DfE#;d`hk;jeZrJ(I3>qTz*K$*Fr~j1l+*VBQ~J<8Io$?K za#jM99ByEe{~ll@vuA<#BJepd$zwV#%TokQbbP=>e-AL#->sw{0VX=ffl2-zB_0H( zawnDeX(fKcSK+lgP;M14<<|p0OLUcV(-}EE1(?$7fvNl%;GMvYXORzFcrLtl53nEj zHQ*T%%d-TS|c#dT;|1|DBiQ_Rsveu&(*Pd_Jgx&7g2|{D%KY zSmbnqoK7Uo$Z%vCnO7X=C6_Vry5CmjUy&`6*FO)-y#95Xa`{M_|Ge%u+ZEZ~Z>u|t z>#&*YA+r3p=_FEbbiY&9!2M2H1NS>IT;M|Y9I4kqS<(wDa3j=&N?c?!;r2SZ@#%k0(T>dd$sXQijQKUcjDXJvKmO1B$#+&CR5vaB4J$au_U zmAJBNP*J)`N8#*tLD(GTSVg@xu9J5$b3ah|9euX9Ba7UTr1^pdSTN_L>%TidugT9 z?7;O zjm$Hdd8RPWROXq6EXqcHb`Gnxvf6A`i@-!yJBiia$Z99E+9|AdDyyA_EXqbcmCQzo zY!t~xnQRowMyYHR%SO2zl*6r{wK*u4gK{}2mxFRSD3^nBIVhKdauZQ*Vm5PFnFDY1 zf{DyAi8*d$j>*h1g*m1&$24S7HuAyM0j>^kb%3h_Tpi%*09OaNI>6Ndt`2Z@fU5&s z9pLH!R|mK{z|{e+4sdmVtEzmppVIvEpXWas_>Ttuqk;cu;6EDpj|Tq#&;Z>9ram9e zVC*BnCxC81A0PyX#&_KDfFXcofR%tB0oDOt1ze5qyGH`r@O{Ky0KQ6N3u^E^E3i$F z@ARt2Z`nf;Pg0;20VLtfQNH`o0DK`FuAwqffFSD8F$#WOVtRlLi8xwezX3k`b+`tf z#4{b@&G>x)MH$_9M))D*6W*d={AADL&nWR1fKi3tr8WYX?jTDACjN9s9pQgK4x$kR zJ`Mpc0y`it?n&b5UjzFP$5BiTwekPYep( z|MDKJ)Su&w5&abLr9RCx0(=WYYF8`c@pz9;W;K=(kdSrf-T)_WiAU-0qbz z_hpQ@ruwdJ^KU-(O8Va?Y`DFh^_nm4`hLY9emiYW;o?8GoqFLPGjE-E|E%+xwMEl^ zv18sZZI5hza_ZT=zy3>_Dg4#@?;3~n6#qPL_`zS@`yIy*uC6UvH}~UFH~8ztldlc^ z>)ml51#)hRogFo1$$<}cmNq>0`Rb0tQ>r%o>9*%97oO>I-t&^-4e!{j)aUjb>inc` z%cKGpRAD{KKDadHlMcoOtgJ%cmQkelWh}%Usut zt(l3<3*NjceFZE&L%xjJY`Jlo)oQ(QnzN~_RafV(y=j8F?aq?7Ir(y5L~6Rp`(CQf!twoh@EmgVG3vgb^*rkgGOq7)V`yjA8~ zyQ&($rpbKi!Q^T^B;*#59yT@Z+&1JDym6w4{4M@p_aZ4;CQ&bIZ25EW$DQUoKwa&8fOXU+>*w1dWbH82%xc<=+QV#U_s>aa)roO z$4VMc2_8b4T8`=y+zFsDmclgN642Nj*$zbU*&$;z22(j2hY4&5Q#nc_OwSJidZ*fXd|pXr3alDea~CNG-PkVbT$)OdX%ks7h1H0kH=GYB`z@2@c{L zSM?!!^gIGUIrn{sucQEGm)qU F{|{vETmS$7 literal 0 HcmV?d00001 diff --git a/app/src/main/jniLibs/x86/libBleEncryption.so b/app/src/main/jniLibs/x86/libBleEncryption.so new file mode 100644 index 0000000000000000000000000000000000000000..59487f74cfe4019219eac6aebcc9ba7f73088e1e GIT binary patch literal 22296 zcmeHPe|%Kcm4A~AIOxC&HFYVbHQKZ#Erulg5}_2(M?o2iz@SB97$y^v8j>`bP;|*k zb~1Ke9I8N^QDJHDJUU2pEJ4sCD-Hz3;u5$z(#6 z-R@t!eD2&|=bn4+Irp4|3taOq0?jn>0zfR+=b{ zMiJ}GAR3^N6=e)&dnCnUTOdgcqnJz4>jO(ADR7S-HYG{YV+h2{dL*SsQ2z+(8Pb7} zf%Rq|(~vjA9+Wefb<5uL7Ob2vNoHt59fMha2kMa>_7Fe1mzJY`2z}^lQ%wIhz|c=+2B%BXejxsYG**&P-+&># zg>vSLSpQi`+GpgyhPZ8}B>m2SKS6vh1UxCy=`g2e`eaFZ9C@}shx*UO)bAwR^^)WO z9P95xycS~E3T80>Q%t7vFH6!?qy0;0U;Y_M3LE)Sx}+6Ps%?lNe>w9zXkY)Ig-?C0gchr2KsMCRe`8>)BN7m6j}CaEnw@yw06f zS;lxliAO1QSKL?bEiNl%nGRi8T=a-k46uVs+zr3Vs zeQ_z`stx7&1+G%p@)h}>2)FWw@Gif=BiN{q{I=5KzYF#i9(P%3!4l6#Ps!h@BV&Aj zU+jPXVN`m&N@KgyU63d7t>8LrUPc&a?Gf*4J+;|byH2E z^Ji%JdQYjR0!n&IgN`?Y#aFvvlxg~UYt7l`eTc5#|-U|1Iaw*?a;PSel ztm`T(sjwAZ6qOcG!Ar{48>((hY$Lb9h%3DX?k|1G$P|efAzX_vxY+umXMaBB zH-DJ^($9NGUD)@hZ{C%*a7ym&zkcJpn-4X;Hr?tjp89nE*$19@_?7t`+n*eNi}Hto z$EqLy;@vCPz52(KRh!E?C%%2`XM29S;lj_hym0&4Nq?MqW?AF%r|o0@tzsu>fXNmQ z*C0OZpLCKI;b$P8fRKg&Q!HJH0MjYKbc-=?olo?T_Hjl9Ol;&KKga{}gAd0p{1wFH zAg{UMgD4e7eZbW4?&_6p_D``EuqZktgb+P0SB| z7!I%S4cLOnNO#xlyK1E*)%y;iRJCRVk0SPU*zVrf5c>?xH8g}y0BHR6m)e`B?>KXrfBJHN&cj3Z!hBK&d|V0r|C0tv}Cr+gbkZCTG>X1NaT@ z|0~&;;yW+NeonP6Wq|AsIa5HSV$&RU&6&m?tr_Z)46C{lm>(mt!JS6S>Qpp+4dc^$ z?Ao%#FdSV<@M@sa96|M{>g-ov^t~Yajt;8FGGA5Cs*XNZpzMOL-R3(osJ@l?lKO$_ zJlr|@$IeY8U#%qpVU;8L+8{q?KSBh+swwnzDY2(n=*Je?b-cYmPa?lsN z0>jqoS+CkN?NUq-~i88zw*xXnBB6H;{H=a)4AxU6WzgDOJ50DLM|dz7NBt zGNfzD0aY2$lzz1%v8qX~$+ekC86-SIYC*Vj0;#oU zL|Mo_QdFf|Q@VX^V^pO>Q##Zms-sP9_qEHM4@Wa!R1c}j9#)|2g0Icy>*MU{|>^HmchWQ;fTN@hkgj@<30Q zHG|8RA=0Gxg-Eq}HdAZZ%vaql$q!wJR8E`0{yq-KY1692fKoHSI;+W0gN1%tC?O10 zY3foM(FNGitt!uGO5<$h8M%IgC~49hjdiJpo@!#Ef+)H59mD(ClHi(IkPai-hU#o7SNc0h4 zuGugO>c7Db)!$=|LKo${H5ZYiE(GAy>Pgfvb$RfDsV+}LU7n6nmkyyWVqijDo;KB` z!&Da}40S=uP?rv!)d|(*i+W%2>e9i{>RP2Yj;PD7cy-yO)?C0$*1 z33X|Mx_kc(N zbhGD+vV6oab!rgoDD?hXfbVii;qu8Jp zvV#kP>i3cs@mnWp^~4&Ok7baEVKzafxze#@nCkBTi!pEf6~H4uU(YB;fop{V3#?S& zZLBtRxYpERBn%x!%FyB3i|BBn-f6rJ*N&va{t}LH=&H9@l;xpKVoet8jnU*La!hEl zz$WI<7R;d~*xo>y&p-mQzcrCE`-{+0=yN?&Q0Z+2jEDL=^=nb4=@7$od)pdRn(8fJ zM$qub*h3;EZv^?l&zv=dwHjdZ^Sc?vs`_rxoZ3!!q3r@DqVNWQ(0L=RtG$uYHD6>d zs{FgoBvO7INo3g>s{j6#AU0NrFaf(o*1L&gE(}pPZj3G*9E-K1DolYo9fn+36&LPqmeWWNw*deSm%Rhs^`sT~v1HC81?(N$?1 zF*dO<5yDuQ_KIqKJ7%Qy<;lqCE0oAwWRYq=C1}uf=iQpSAV)YF4T9BTK8c-# z_V5~1a3s5h)Zv0+n{K#BKQmD1^Ur`^J2L!3iQo%HhA%bXbxjmoM{LG)?m%^i?Z>ct z^rwPP@v1Azbmoj;g~ixn+_47ATVGAtSg5X0E9~o-dEd%ge&<2=PTFvmPhd3QeAIZ`yI9b4V{mcc)xv+4n@ z+NR~v4aO!H8!1)kQyqs@XRlgyC|C@H+$IN&QSLIgbip`BQ_DlEo^X$<^n+;4(U0Ze zHmjP1^58Tei8(VFgbbt*4????LDH!ygT9VAVjT6&EQq6jvPu7pSo(d{DLD1%lWPy4 zMMTpg1e)75(-S6v%Hi-qaZuFfYoQwsCuIVDvA5-MFiFiEfIuC6Y7MK6;~gB$pcc7) zo}plLvz30i{_`R|s5u5`Ae26RQ>s-B1X6PVBQ}%+q2G%MVpMj{zfx@QaWe6g$;T9} zdN5{VsqUk-nk;zHpr42N2GSzqpNGpr9x~ZH+H`U1RW;bDoRkW?l;e`b6xc5}D<|b< zhkaJJTz@@Afyz@D>GR6*_VYIED37-vv5o1*Y0N3OjB>LR!1nPtd^wf#Vxj6h1&CAn zhNk_375kf0IlnJdt3)vxwjV)R^{Jef3e{?~?>AMs_I|;ReqW0?(2{FYV)Ib-8<7VM zr#?sP+uoNP+f7pYkx^s1S(4LUs5(xCCJhB16$@-_KazAY;EQ4|)Ra>g`SCjCq}38o zPKI8BKB4e7urLlweutHYLqDx2J@*l=#0w@-aH#=flb z4cG;nsZ|t|(dj19={a;NOq8#BaJ1PeWHKl>3z?i_r{`$DcpN$?IyJ0@u!1J{J_l?d z=A1Yd8jxGPy!ZDBlhf{N=XjOJBgC6bELS^#?wLF`uG-85@lSpxkkd~q4JtLM#UKr#x zs*a~r=PtEshg!Wo`0Sg)zlmAp^qYYe-2275*{SsY40j^0QJn3@F0qjl3jwE}IYt*T zbo;1iA{N@lID2d4VQ+Q+9_$R_m{a?OdFW(ZOn7nV^h$8DPITy5A&85^N;)i#O5fdL zcyCohn;EW~dH11raiL%L``{HAlo%e{P_U!Jzzj!iDA;}-%rs(h>%1iW<^x8h)(&#a z3z_*a9GF_-NQtM0Fh}A%{AlJ2I3{--Hm*fr2#G^g4yn#Z%nOmvn!~~kNU~Vldo{-+ z^!X#V9tSc1ICJ$|562@hE_YsI@HcOWF=H7SdfyRn9E{#^1e`r`Yt=!mx}WzAC#-Vo zoa<(NDEoQu3rp1lJrMUJ$#ScGJcmcC9&tzx(0K{1vg(t|X54h(J_Q#myufGr7>FIT{2P+JqLig~)}7 z-xb;6;F7MNG$c4Iht4Ql1xZ6THVO1WQySz}o9{xB?5`9ABD=`qyU-*1-I08f?*gp# z3X#Xe=Zr!AGx$aS=6wa^;XJC(K}VxnLm?1UPKEP^h^RNE!@Y0YgF+@t&vb#bqntwS%np+ zCGQb6egMONl%zm1nelh(J3O7rlA5@{ACbJ(cz)HD! zOwH+U6MqA2vQCwv5LZDmRnc{{c;rWrXK^z`YB?DB+ zbaCr8(4`2|0tZeVw)s?QWxv=bDYcPpCkFoG*UV+s^oJw+wFjqycHz13YITOTakJQK z+GF;bK^0p?XJ7bL81njuuOhBzC*oJX&*#l-Eg8Tq>Y&+-S0>&JySks-P29SQ3)}#~ zczcSy?SQeo0t)SdTrc%4Reck;ZSnidHKsrCYA$h%;16imYCq&r8FrEA5|`hal8TiB zs{$4&4NC~$C{PZoc|GbrP3ch`2UKUbTGgRew}pGSz++=9D2*=g!}idJRmYy#L7Arz zcp<=a7!I?(4_>3(D*4VoDf{_$lgQ4qh`g>)1D(?SDD9kQVT9Gh7fPb1>^r|&_Gjx& zM5!fGIx(gcM?AJHvmuUnY*|qcPHcbQ0Vgn8EkH%bMAe)FS{3}YIk{pJkd`Yq2g*6Y zW6Cr42hwt}VaCG7RSo+~-x1jaNX>0OYOOg+Z+px^y)a)St)VVn?vIXepK@tf>1TARpCcFN6LZA&PR#Py3U z!vQRUIs?Jtq~QRW{|oYy<>sbrK~RKEVi-|24exI#L8FEPToOTCNaW@jBhsVSUxYyh zz{MFI4fP*W)JnU$!m1{B-C~2(upr>1 z2}U&bSOLq3X+K+h9czs9gu}tYKgHY6h&@`E1yq0A9>Eg99>Eg99`(=?(H`~a_NZ6Q zJ3xDMKy`Gh&JMMzO|6EB`H1$Y7w?Yz4SUop>`|O`I4i6J6$%b?!1+3iq!t*7@o94{ zFbs1e014){K2r<~V}{S9|CMGApGuaY7GQXP20gm%SPbPztgV-3DljwSb!{j?BQwY_ z#v{;kahtPvRJ^gdH1e%+mM&r<;BD$AJaw*a8ZHfg(n$CtOGN72ORy|*bEDArhTNWf}R%vW&N|xGXb@U6!*FF3Tv5UzS&!4Y@2M^HD8Q zZvuSF$F8es>G1oG2 zlmosDcMagB8s&y-0QU_AQP)5Rh;t2C80Q+`6+gBc?i!dChHDVPXSfD>b?nj&*MNm_ zt^wS3;7{Nh=m^Z!8}26u6m<=TC9JQ$Mf4?xxN$0dN0mRk&EPi&M;joVMuw9rqskPDE@XQp9Ga zPdE&R=`chN8kGSxua}NPf57oa)!Cy~9Z;*g;W)gEDXu<9LC0=qxIarZ_Gcyz^$Z-2 za1T^k{b#ZEw<;6F0jV&Bc>}@87>2m5s8c3jb_Hr^fblY12FhdZ1c#j0-?_>hY$gu1 zJGZcjWKIlt2Eu8BaCGO*oRC;Cg>_fYz}0w^ZHyVL`|w6>bc1j@pl@DG?;T5Wiy-bo zPJ9&>f1@hXs4}sAX!RX~pD$|L-?G-c#l44mdd!75)L(HRzt&C!$Py#blb^LRe3e$mp)hV0xq8d?T11N0r&+Z*s=K5M{f` zTQRN%V;etoe4oPjB0eNq3R0oIB90q)BZZkj-0_sZpL50>x!&X>QjYD(rA>v2knt91R86<+@HCa!mQ|G~#{|8mK)*=D)cZnXx`!z7gPzhly2~2P~1k3EP2CfJ0yYpYJf(*-==IhdLR+f&F^K5!fWR z=r|okDZtT-`X9yCD-UACN#7$7VWt6QC9WnO7!I?MFru(ia8 z`xgEmZ-gcTHhIw%5n%GK5wHQgwD5Q$ypOVXU3R^IOTl{>{9of?I5$}%I7zD&i-h-d zIL!Zx9tL~=P}pq1_Tmjx{tx#s*k49@O}uLWyBRM!^Z&Pp!Tvf5%W(w&n~t~B-$FVb zHtEm$xCqw>xFF!NV{zVM%*jmR)aO|*;0E6dhkIl38E{Dlqxg7_@f7~M;bL%{H^yY|UZh5vSojoevn}Tr>l_j6Kk+Wr*!Kq~DBqGve)t(=g}T z5N}7^kGKT$HU+-Kf#c!u9K@UP|6K)$?SpU#5pO>WT!>5F#XFRU=bR6R`2x~p@N*90 zHQ-kP;yK{QR>Wzbp$V}d{PNFb4qWEIWe!~Cz-10x=D=kRT;{-K4qWEIWe)s5aDd+? z>BE~SI}otVlA7}MZ>nrTn%|YN;yrzyWAK=QVPFiuhoyhx1Z-`}*p{ye4PuYR z7h6&g@ZzAEHOAOl@xDaDmaNPRI z$A91W;y?ek`n|7zb?`q9J^u6UyDHkA|Lebee#TeM9hmmyo2S3ooAXI)*Jt-l_}-|0 zz2XyFj-L3!FRI4)CQrP!boGwqvtNBK^NlIBD-KF0(?59j?r-dGopsxiyI$&f`|0;@ zaZL3q7m^-WHs?oA-SNb{?|k>MoBpz=`M<7D37>iSclN6X^1pxUKXm-$pT1m>_o>RY zHD5b?!xtL@3s1GAzIM-5|J|2+^OcK7XRLYQm1ovHysiJfx4LI;sQ<&#pO&mTd)#yX z&uqWi^tr6GA2)Rd|Lnc)_PttN`P|)wi;~|R=bC=!FCT3G^uHZB|LFMQKRxuw4?pwm z(C?j-Uf;S?9s8fh78K3@!Hsg`%3oh&e!wq%()3x`+1b-)rLS{UdJ59ZO4BQ*&X_)9 zYK}WI-Ocl~^o^d1N__AseO6X>)=lY?ioD+P%A2Q5F+aStzN~D0iKnuxs>1Eba+htG z;w>vHaTmFYOQ)2SY}{~Tc}3YbJZ^7#ZuZQAnXYy299OPuUEx$u;Y|h8re^2NoI0am zhHIv0ojW&onk#o!c4qpd2q{aJta9l6R&FfKr0g*b#kYtU^IL!G%SsB;bFy;qwv!}f zRTkmXQC`oE@uvx*BmrCy_KeQ8zJx~k%mf*Xqqq^yGbN-OW%pvT?{DT}p5 zuF4`kWsH1CCLgT`Wz^-PQH7_3i1b8x33|d;>F`@oCca;leT zXk1YyW#QX&#rdv^3fFyt8rOzmH##Z<8vJAltU5M)3`-)PHw+yU8F8aYFq!eu9;ia( zJ5D_NW8nFu`QWHYJlEluM|jL101QKhsL_8Y4?dIwaT1QUh@l68^@v1F+l05(g}oyj zZ4?7-l=%>r&jJJ->68(Uwu_++X@HA|O&As;(B2V_wvC|;>3BH4_e1+bINB%%lNJ<- z_N@Cl0__&lv|$Xicd_F@R(zp}c8zefZ4Bv1$HRRKWvCMPX~P*NARkK~ZRi#R!Yx3c z?Pp*a;drh_yo9SoAdhJC8vw(QVloY7MIo^K2F_fEwKpFewvlD^vgp2(iDYD`*;eL)B;fO+f7jV95Nph z?sXKHaMD_2mKgH_G9MEknrpM z-RtN6aXI-+*52!}*V=onz4l`sKh*N)CRi+rd=ix#m1s>-@&uvxPRT*ITqOzruTid6 zh5>EGD^HN)VT))?!X&{*XqzYx3T_ry3DbC;^azH{`eoyZZ!`{Uf*rFB(@zc~MnGX^}Dt<*Lbc{QvJi)9m&s)27Y%Z#O{WF%mCw z=PkDvD9=Ch;JFvC>OQypmHq=sZ@hi-iMJPxxK!iRpQ{F8m^1`_5flx^-#G;SZ$sc) zSo^6;-ZZW}LyY$Yz^jy0rT$wS{}czxcLaaNSdMs2;BOT8#km|YMzr%j^rk5vh84G9 z6rfM=SALTt9ufG@1pmA^{wBen_chKqp9Tz12_V^-A>2P&Ow#qj{xmWSk1$u+$HpO5 z>HaFmzr}%4F7SB*FYP%#g#A5`BfU-6@dipnJNtz_y;pF=cU2C5FWS$T$?G}7{z<}4 zWdg@vDeSLCmD=CYbR~8nz%iVV_C@hW)PGQVY6&4kCmX?;Plr=q+lzj#G)+2^E4^zZX+{qyfeb#aYWUg9qI6c-^(L^%In_X@N`XFxSI zUszaOg9t11lsr(l)LmMpcuI;r4jqKOM~3_fn5-V9(p% zUzk33(&XFz`0h_0KJd!lbF7}yDK8xVh7S z)A6Ex04?-Lqe=>1Bro?oD8@WwyI3Y-_OLV_GzK&t^ibdB9*f41#*+FU|A?iAjT4Q{ z)r=tl{QS=XE&uu-?Xmcu`i*;7o75cHOb=1WF4;FvDvd-!q(5?>D}5{Lqs2Z};x~!` z$cV$&3w(VcY2&d&{g#j4gqKSc(V9$nbNs9~;ib*QztMyz|HaKTw^9CbXEOY}6xj2-@>J3z<=nE;V{s`4+YK8hPgu{B{?7;0Pe}b|) zCQsS3G)o<`22@2+$2dWFA3{-FlkN-GB!o}ykxY8v0-87hCcSagP1MpK(9+T-NiWa? z@9C>gXJ7z}bi+DsJQ~&mTE8Bs>(c|Zy?UUaC*V4eAJ97U1Fja`0NMcBDCh~+qa|;@ zqWY*edWRMyt3vzH7ZY1cu$0*94uJ0!xUIvs2_2-TL)$@-YiK(Ht$N@XG;PrXdv)(_ zRrel)@)LUIAwBSk9&kMm9&gJ4v6<*6^~}S1;5_IX+lOsxpKIAfY{B9Fxe4ua6D{q- zElxu_;PlV6I{mj;I3Z^&9@v@-v-H5uYyd;sFjHHvHqIf6VM~L7y2rJlVPuj~ zyTRLT(>?9F(MSURkrswZU??W+A2}TI-WE$h+YtI42AW%;8;q(p_XSt}6C)nbo>aHF zo@^aRT75K3-7eVSJ!REBXY&mowe0Yx9%dPA!h{$96|!qV*0h|3#k?t$|XUT-V`OT_W@Lpomf&YnvK z!{y_-%QFB}-<80qel(+@1Y;z(={D z!*?J4gI7VIt#Jl?3(07PoXN^+<4O>9gK_JgMq)=$=|;|PF%#8YXM>GUZR{kxw*z6e zPdAv6e(Mzy3%~D!bI4|g-wN5(RgjfbCEv4ej^CQhwNel=^`RAL(f)eW9kiYcZ+Gg( zI1(lg>ii(jA?jz7_TE98OinL zNJhmJ$*7qkxgL@Hgo{V=T~Ik#B-isu_UTX%?OrsPw-Ui{)nmxW9O@+JWg+e35!V)) zfFyvZ-j9B(zGqlkx&oT%>F_xrM+x3wB^j)_q;c?Ir9{t}FBPxj!6oCBwLE0VI*mrM z!Ql-J*VJZ&+t$(Oi!*R2IB|e^;(AckZCeSnUPxMff`ZU#tm8tbtn)m3;bfA@^G_Y& zRJW}oP6v00(|DTmy`MPG^Jk}jZ&K+AuJ zZzMQSP(%Wvo0Mos#3dlcY_R{7hJ3X48tlLHZxYjIT3@2ch!$qfd@29-qZ1MTQu{;t z*SnLM4!@>B28&Pd~nz5YgGp5QvvO^Z11J!h%62 zG-DHUx)=JQ4m8baA{dQi0%C;>WU<27d8}~XwS@|h<}j^4#z4wxJstY#>F^zaAfMJ$ zl5X!td5CG<36jCYF6H(Xa7ElsEf48-OlzW>rnQ19P3yZqW$xL9DyB67^R(tda$1v& zoYuq{oz|SsJgo)BG_3_DI;{x-H>K-rT2te}o=*sM@w6sZF|D^SsX?YS5qLM@Dr$|n zim`K7@$qg8y?`w_T=fZDBVD!j7Un6qYBL16tEePhwGrhZT(uq~gNa?rRZZZExQbf7 zl&gqta#cUJR^+PRe9T<+D5!810kf;PkaQKvNLLYO)K#3%>?(mVxk_N7t|A0n_5Hcb zRn&NJBCHwARm3V>RnMdbaTO7aM&g94s5Ry)#?D>E$Ga^Qro8KW7>wkfe<|A%v%y4I zwq41p^k4e266GO$SrTEslrI;9E8cGg~<7VwA1-PV39j< zs$j;@5rQ?xHgF^qdK&Jy#0HKOk-MZ@<2Gdg4SR6Luf;LDAcz?q!~yO_NQnv2&rdxeP#eF2GRCnNN9!Z(6lD7~M5yM+ zT+xoOBlMBbU*H7Yuo_GG(u zLRs3O9Y@P3smdt`c3_s4d4p_0z*3LNWolBh%AqwPMj}qDi^y@&o&LIBtDE`;f zU@*M1pGE~EPxmL@*-fZmW=td$S{g@5r?ofHtRtcIs4cmZF!t7^Xf8z8H6~`8nc3QU zG~rUrmuz{dp`Ah3k2h#1tQNm^BJ>942$09)X91XwsXn@|0`-`>tuxRGw`5=ze0Vw> zZj$kTkv{^p#}Ruyh`k;}6I`o=sKf2rVZ09Ebr4}hw+`6+caPvFX_OMxMsd;5gUIPt zca2O^n`;kS4#B^NLwTG%X;7v^jOkE_uG0}!X8D7RbT9-8uHo<)S~m;F?$8eqjt$yj zzxHW^cF3=tY0wV(wa+@VF3#3vxQ=^6Hj1H{Os?yxR})eAY#>n3se5WW)#m)1PiX=f z1zq0VxY9Wbn{Tx5^^d&K(7KqCuFxw`!t_Rm$#5aZbgDk=XtCtdL=JAmT_25Sp1%$g z4s+LA*C)pgdjgEv2N*MU3x^qvF&j&=v_^PbK`~Mvu%3Q^bjDN%LvKPgX2J*RE?3yz z>UV|JU0Qfixi;Fm!D!9AoE#h|VBvkgI1UK~#i>M4jWv|-IoO6uOZ3rLQX+J zxAOW}0jqHrSqfOa7CvK*kORdL~j zv>Ci3B;O-DnmUYQcQWH0;b)!s7fuI~HLoIoMj);+q>^ zN0UyYuEnTDbEArY41NRlgzk^Q=M!E9{)}xtmzxnocM^RJ=+UNT5Gp+el|`tpQ0ow; z&b6q!^aPs8r-ski&kc+AA4!Z&X?9Uf_u1PA-{HEpbZDD-gDy1aNC;@pV+<hg5XRd-oc=ZtpMcP)%SHux3h zV+-pu3}N$eMz^|#-W-)(@6a}4{Zv8&$b38kl5l5AJ295@2J}Ej;1JtDtmlXTeBP>i zTXEBW6k8D7)_GG+@9Wh zD%J?+oqZ-3(0s%ELoJVJ&=XOfM&(;AF!i>0@%N82Q>QXImG|zda2$ zdg|67HfJyvTxIN$Qg4lgReJpV^O7i&5Lh z)(6-mj|NHb8`2m*8Z?f25}%yV8&jVFV4S^C&a^0JA5s9;H?3z2WL-VTPm$w9?0L!Y z9mm~{0>@nobnodB^D2ofR);>LJ?4= zca%5-ovjcx7(ga0&am6@RwJ{&38YSSSGM=UCe@e0#)0ZIJ%FI7Cx&+AAqMg+3>vNt z-Vma3zq%_W%{y?9>YF7P83pI`DCIgcg=E^TX<5`*gq08-S{wKf=4~^z4Qk^R#GZIFnl?$)5r_+omZ%s?B*wkX#)kQqnX_tCQ1xf{uh2p^r?{?7Q(kM?|mC(rD5@YectIGn}*?-{R|jPv~oqcO+ks)`>yNWbNh#`s2qjGK|9+ z$4bk^ERi8Ro=sg`nQ$>n?C@dVmz3wv*$H;cJC@qpLJys%)s?aZh9baIbZwJSumQX2 zPJ1{|w-!4tr{P+Q4U{vm*J;o`%2n?S?1xl6%iK-KV^hU#R$aF~;{tB8XzQ)|z66(G z1*QrTV#&RZ`y7iL_d5!4Vi@x`o~`5Vlm6f5$GFV&Z+suh;tw}X{({F4F;$aTP$dNV zur!Rr1{<*@(nuXesWsPO>2vz6xik+ruZ4wVgQT%a#Tj)~>NNk7+_d5jI5Z3pMdh-IS8F%tO-Oi5^C z+;iaKW|%2ZQYVy%j2TOfB&M-QOy`l9j+?=h1;J8+63Z52hth(To=*H@|phXF$jg??EZLAmub8wK26(jMDQ$8BRjA9!r zDPi7NO%QZijV0Z@v648_64_WuPU0J@?o6KRXy!0H5>Rww^*ceONhcdLZ>%IP zW@9ChgKVrgiEpg#=54c$l@y8DSZQD|={0SvxGfDSY5vpSO~~XLOCr z!rt39-n^W4ALRGB|GV+Alf?%a;Ob(_+aJ~DoS)(Llw0aTsF-$2RUlw9MVXLEP$(oh z?6lO0*dhT_vXERU$c{&m?~hV0bSA$c8xZO4YP5@p(S=`JU1)e@l4jqFrH``LS-jsv zbm3J-PfyY^@sXqSh+@c)ngJwXb_!s+;r=9S#Q8qlk^Ht)jCGe9eijX5WfYOf+MS9H z(OO63M>v@>qwEPbpcY!mo1g<)tY_@jT61*B+rO#hd|ik+nXQQ8{V(k-*g7>AuLU}L?wdL_OdI$qiqf(%C#9Cmom z;x1wY+#M`}^3WA1(R&}Z8^IBD1BEX3^JB8<{Y}T+3)*d0g9WYI5&@C5u%aZRg!ef{ zSpY#eHI4|n1+n@8iWZy^b51Z^>N^1ZAc(Wfn^cKxz6boNtw2Ej1;)EF0i$hu5oL$H z-|4sgiW3_-F%iVn$BCFZ;Pj{dm|df61Km_PYUL9zxzlfZ4G7%YZ2?f5N1)9YQDOtQ ziJ?-T0f-FX<5V#ZU_B5J|32e=$b!DvmZQuE(8I8^?*oX8QR?kPHcx(>+h@-J63yHI zfF^DwM~oVWik68fKk6Ekc;@m)SMGkiEMv9^rs#K z0^`@tcq^Nvy*X#6H9=cPptW2|9 zlQKN133;FJ>39YAg~KVtARfZwvPJ0y9&C|^@cDT40B?(6c{@d@cLSdkhkqFLPT=Vz zC?7acc>*uuXWub(T#@#pgqu@`C4O6lX^xa(X^fR@+kscoJK^vngpqs+bztMR9|3wL z=x@c)-(Ymoa~`kU-f)_(f z_O2RcW+Z#*vmE`W1|L6cww3e*d_x591+(w&%644d;cJIA+8(t&mY8_f8flXF^TEHc zFB~3C0WcW9#TLW=F!*(RB9XonGAMs?LJa?A@a29M4zurI57vHCl%M){1pMRiLFT7W zjQD$!K8ZSrmJV(FlFp@ zBu0`a3;8~D;zEZt_*Mu;KP6$0M`P(0=NON3vdVEalrH=n9ukC z(PqF2fNOEpk`I`Uc~S#dhWW4o@Ce`zz=sj{M*znqo@ZZwFxs*P|iigfK z^zc)*qI{KCBfn*W?K&F|X$Ovbte!0f0!Iv1FB5ef8DjWxBw%&FpkwPFLl^2kHz0p! zE?&WpQaR>H0iP4FS-^Gy4+(fez%v3469fAt0k0Qunt*c!yj#Gf0N`Ol2=FW>vUKku4xYyQH0 z-5mST6 zTJ)9b#jC%4B}1r-u~}p zcYkuK_@Nh*{;+afR{C?VvCPMnmO|TbJsIXRdJPeCO34wO;$o(f;*UmcISy z6F>Xvk3(-1jDKhCvw_stPRuEBJT+0>a@QZfB!BcSV|>nx?Ck8E85v95)x|{_73CRK zQ>Nuin_~B5W_alSDq}@)RW*J%C}T!ec2;i2_>!8M%Ia@Tnk0X~XIVwXva;gpirOkq zah9iI`J|ePiZV}$yR>{#S=ox^6DzAKzE|w2$(Woyy=c07iO24q>|U~TO7YU%qN!7| z?bD}BE1Kq>UcAIJdGb{E@8d12C@ada zXW8+|6-CLaF2PR_)wq`^S>+Wq#qxqKtF)-Nyhh-bmDgr1sVyxlnuuTg%PLw`UcG8L zhc#777Ew#w)g`*LordB zOvCYi@=&^<94_;Hq#zLM;~J0f3H+EidHNkadL$gntC9aAT}JBUPqIO_EAzjE+XaE- zC^yP=MXn3>DKFO#30nlCT&JXdDL)qlT9Tx^ zTyG?75sdNjavbPxmvXg~m-${o>K{E)Uh+vupJJx9K-T5@Afa4$Lb?ASdHVgKc=;azM?RJN zhf1+-NXYK~K$nkPeKffhY8-qtC9aQ{v@P3 zR4U8yTPfrv+$;x9v>^L08~kOQ{7}EcD*5C6|FV#mYUKV<{?2N=zWDks$g6lsdAZ*i z?cy5a$4kmfxEE~XJ1H;s5%PCz^TfbNyQQ3Lm)?V*@ssj$|61~GAP0G*yd?FYa4Grt z{1-2OG)`VwELxr~AT@4!q}>vA5(R2g+8_Dd(>plFJjp0vy#CX`lZxy(K1IlHjl)ZG nB>WU~xraBiZWr=0e@L42gRE0K5!)pa@PLp{k%|N@uB!YmQ*kw& literal 0 HcmV?d00001 diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt index 34f7c64def..7896cbc234 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import com.cozmo.danar.util.BleCommandUtil +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker @@ -31,6 +31,6 @@ class DanaRSMessageHashTableTest : DanaRSTestBase() { val danaRSMessageHashTable = DanaRSMessageHashTable(aapsLogger, rxBus, resourceHelper, danaRPump, danaRSPlugin, activePlugin, constraintChecker, detailedBolusInfoStorage) val forTesting: DanaRS_Packet = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, 0, 0, 0) val testPacket: DanaRS_Packet = danaRSMessageHashTable.findMessage(forTesting.command) - Assert.assertEquals(BleCommandUtil.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY.toLong(), testPacket.getOpCode().toLong()) + Assert.assertEquals(BleEncryption.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY.toLong(), testPacket.getOpCode().toLong()) } } \ No newline at end of file From b872b82cd9f6b5c181f4cab46eaa025c131fce45 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 24 Mar 2020 18:17:28 +0100 Subject: [PATCH 02/53] kt, share some MDT code --- .../plugins/pump/common/ble/BlePreCheck.kt | 88 +++++++ .../dialog/RileyLinkBLEScanActivity.java | 59 +---- .../pump/common/utils/LocationHelper.java | 70 ------ .../plugins/pump/danaRS/DanaRSPlugin.java | 24 +- .../danaRS/activities/BLEScanActivity.java | 217 ------------------ .../pump/danaRS/activities/BLEScanActivity.kt | 172 ++++++++++++++ .../activities/PairingHelperActivity.kt | 2 + .../plugins/pump/danaRS/services/BLEComm.kt | 84 +++---- .../service/RileyLinkMedtronicService.java | 9 +- 9 files changed, 326 insertions(+), 399 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/common/ble/BlePreCheck.kt delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/LocationHelper.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/ble/BlePreCheck.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/ble/BlePreCheck.kt new file mode 100644 index 0000000000..2d623902bb --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/ble/BlePreCheck.kt @@ -0,0 +1,88 @@ +package info.nightscout.androidaps.plugins.pump.common.ble + +import android.Manifest +import android.bluetooth.BluetoothAdapter +import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager +import android.location.LocationManager +import android.provider.Settings +import androidx.appcompat.app.AppCompatActivity +import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat +import info.nightscout.androidaps.R +import info.nightscout.androidaps.utils.OKDialog +import info.nightscout.androidaps.utils.OKDialog.showConfirmation +import info.nightscout.androidaps.utils.resources.ResourceHelper +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class BlePreCheck @Inject constructor( + val resourceHelper: ResourceHelper +) { + + companion object { + private const val PERMISSION_REQUEST_COARSE_LOCATION = 30241 // arbitrary. + } + + fun prerequisitesCheck(activity: AppCompatActivity): Boolean { + if (!activity.packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { + OKDialog.show(activity, resourceHelper.gs(R.string.app_name), resourceHelper.gs(R.string.rileylink_scanner_ble_not_supported)) + return false + } else { + // Use this check to determine whether BLE is supported on the device. Then + // you can selectively disable BLE-related features. + if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + // your code that requires permission + ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION), PERMISSION_REQUEST_COARSE_LOCATION) + } + + val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter() + // Ensures Bluetooth is available on the device and it is enabled. If not, + // displays a dialog requesting user permission to enable Bluetooth. + if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled) { + OKDialog.show(activity, resourceHelper.gs(R.string.app_name), resourceHelper.gs(R.string.rileylink_scanner_ble_not_enabled)) + return false + } else { + // Will request that GPS be enabled for devices running Marshmallow or newer. + if (!isLocationEnabled(activity)) { + requestLocation(activity) + return false + } + } + } + return true + } + + /** + * Determine if GPS is currently enabled. + * + * + * On Android 6 (Marshmallow), location needs to be enabled for Bluetooth discovery to work. + * + * @param context The current app context. + * @return true if location is enabled, false otherwise. + */ + private fun isLocationEnabled(context: Context): Boolean { + val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager + return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || + locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) + } + + /** + * Prompt the user to enable GPS location if it isn't already on. + * + * @param activity The currently visible activity. + */ + private fun requestLocation(activity: AppCompatActivity) { + if (isLocationEnabled(activity)) { + return + } + + // Shamelessly borrowed from http://stackoverflow.com/a/10311877/868533 + showConfirmation(activity, resourceHelper.gs(R.string.location_not_found_title), resourceHelper.gs(R.string.location_not_found_message), Runnable { + activity.startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)) + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java index e292808ded..7695344183 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java @@ -1,6 +1,5 @@ package info.nightscout.androidaps.plugins.pump.common.dialog; -import android.Manifest; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.le.BluetoothLeScanner; @@ -10,7 +9,6 @@ import android.bluetooth.le.ScanResult; import android.bluetooth.le.ScanSettings; import android.content.Context; import android.content.Intent; -import android.content.pm.PackageManager; import android.os.Bundle; import android.os.Handler; import android.os.ParcelUuid; @@ -26,13 +24,12 @@ import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.widget.Toolbar; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -43,10 +40,10 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.activities.NoSplashAppCompatActivity; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; +import info.nightscout.androidaps.plugins.pump.common.ble.BlePreCheck; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.GattAttributes; -import info.nightscout.androidaps.plugins.pump.common.utils.LocationHelper; import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus; import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpConfigurationChanged; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; @@ -60,9 +57,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity { @Inject SP sp; @Inject RxBusWrapper rxBus; @Inject ResourceHelper resourceHelper; - - private static final int PERMISSION_REQUEST_COARSE_LOCATION = 30241; // arbitrary. - private static final int REQUEST_ENABLE_BT = 30242; // arbitrary + @Inject BlePreCheck blePrecheck; private static String TAG = "RileyLinkBLEScanActivity"; @@ -156,36 +151,13 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity { public void prepareForScanning() { - // https://developer.android.com/training/permissions/requesting.html - // http://developer.radiusnetworks.com/2015/09/29/is-your-beacon-app-ready-for-android-6.html - if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { - Toast.makeText(this, R.string.rileylink_scanner_ble_not_supported, Toast.LENGTH_SHORT).show(); - } else { - // Use this check to determine whether BLE is supported on the device. Then - // you can selectively disable BLE-related features. - if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { - // your code that requires permission - ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, - PERMISSION_REQUEST_COARSE_LOCATION); - } + boolean checkOK = blePrecheck.prerequisitesCheck(this); - // Ensures Bluetooth is available on the device and it is enabled. If not, - // displays a dialog requesting user permission to enable Bluetooth. - if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) { - Toast.makeText(this, R.string.rileylink_scanner_ble_not_enabled, Toast.LENGTH_SHORT).show(); - } else { - - // Will request that GPS be enabled for devices running Marshmallow or newer. - if (!LocationHelper.isLocationEnabled(this)) { - LocationHelper.requestLocationForBluetooth(this); - } - - mLEScanner = mBluetoothAdapter.getBluetoothLeScanner(); - settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build(); - filters = Arrays.asList(new ScanFilter.Builder().setServiceUuid( - ParcelUuid.fromString(GattAttributes.SERVICE_RADIO)).build()); - - } + if (checkOK) { + mLEScanner = mBluetoothAdapter.getBluetoothLeScanner(); + settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build(); + filters = Collections.singletonList(new ScanFilter.Builder().setServiceUuid( + ParcelUuid.fromString(GattAttributes.SERVICE_RADIO)).build()); } // disable currently selected RL, so that we can discover it @@ -193,19 +165,6 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity { } - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode == REQUEST_ENABLE_BT) { - if (resultCode == RESULT_OK) { - // User allowed Bluetooth to turn on - } else if (resultCode == RESULT_CANCELED) { - // Error, or user said "NO" - finish(); - } - } - } - private ScanCallback mScanCallback2 = new ScanCallback() { @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/LocationHelper.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/LocationHelper.java deleted file mode 100644 index 065f0ec4d6..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/LocationHelper.java +++ /dev/null @@ -1,70 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.common.utils; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.location.LocationManager; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.utils.OKDialog; - -/** - * Helper for checking if location services are enabled on the device. - */ -public class LocationHelper { - - /** - * Determine if GPS is currently enabled. - *

- * On Android 6 (Marshmallow), location needs to be enabled for Bluetooth discovery to work. - * - * @param context The current app context. - * @return true if location is enabled, false otherwise. - */ - public static boolean isLocationEnabled(Context context) { - LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); - - return (locationManager != null && // - (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || // - locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))); - - // return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); - } - - - /** - * Prompt the user to enable GPS location if it isn't already on. - * - * @param parent The currently visible activity. - */ - public static void requestLocation(final Activity parent) { - if (LocationHelper.isLocationEnabled(parent)) { - return; - } - - // Shamelessly borrowed from http://stackoverflow.com/a/10311877/868533 - OKDialog.showConfirmation(parent, MainApp.gs(R.string.location_not_found_title), MainApp.gs(R.string.location_not_found_message), () -> { - parent.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); - }); - } - - - /** - * Prompt the user to enable GPS location on devices that need it for Bluetooth discovery. - *

- * Android 6 (Marshmallow) needs GPS enabled for Bluetooth discovery to work. - * - * @param activity The currently visible activity. - */ - public static void requestLocationForBluetooth(Activity activity) { - // Location needs to be enabled for Bluetooth discovery on Marshmallow. - LocationHelper.requestLocation(activity); - } - - // public static Boolean locationPermission(ActivityWithMenu act) { - // return ActivityCompat.checkSelfPermission(act, Manifest.permission.ACCESS_FINE_LOCATION) == - // PackageManager.PERMISSION_GRANTED; - // } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java index b9d4af7497..3e865cb0e4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java @@ -61,6 +61,7 @@ import info.nightscout.androidaps.utils.DecimalFormatter; import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.T; +import info.nightscout.androidaps.utils.ToastUtils; import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.sharedPreferences.SP; import io.reactivex.disposables.CompositeDisposable; @@ -77,16 +78,16 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR private final TreatmentsPlugin treatmentsPlugin; private final SP sp; private final RxBusWrapper rxBus; - private final CommandQueueProvider commandQueue; private final DanaRPump danaRPump; private final DetailedBolusInfoStorage detailedBolusInfoStorage; + private final FabricPrivacy fabricPrivacy; - private static DanaRSService danaRSService; + private DanaRSService danaRSService; - private static String mDeviceAddress = ""; - public static String mDeviceName = ""; + private String mDeviceAddress = ""; + public String mDeviceName = ""; - public static PumpDescription pumpDescription = new PumpDescription(); + public PumpDescription pumpDescription = new PumpDescription(); // Bolus & history handling public int bolusStartErrorCode; // from start message @@ -112,7 +113,8 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR SP sp, CommandQueueProvider commandQueue, DanaRPump danaRPump, - DetailedBolusInfoStorage detailedBolusInfoStorage + DetailedBolusInfoStorage detailedBolusInfoStorage, + FabricPrivacy fabricPrivacy ) { super(new PluginDescription() .mainType(PluginType.PUMP) @@ -130,9 +132,9 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR this.profileFunction = profileFunction; this.treatmentsPlugin = treatmentsPlugin; this.sp = sp; - this.commandQueue = commandQueue; this.danaRPump = danaRPump; this.detailedBolusInfoStorage = detailedBolusInfoStorage; + this.fabricPrivacy = fabricPrivacy; pumpDescription.setPumpDescription(PumpType.DanaRS); } @@ -153,12 +155,12 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR disposable.add(rxBus .toObservable(EventAppExit.class) .observeOn(Schedulers.io()) - .subscribe(event -> context.unbindService(mConnection), exception -> FabricPrivacy.getInstance().logException(exception)) + .subscribe(event -> context.unbindService(mConnection), fabricPrivacy::logException) ); disposable.add(rxBus .toObservable(EventDanaRSDeviceChange.class) .observeOn(Schedulers.io()) - .subscribe(event -> loadAddress(), exception -> FabricPrivacy.getInstance().logException(exception)) + .subscribe(event -> loadAddress(), fabricPrivacy::logException) ); loadAddress(); // load device name super.onStart(); @@ -195,7 +197,9 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR public void connect(String from) { getAapsLogger().debug(LTag.PUMP, "RS connect from: " + from); if (danaRSService != null && !mDeviceAddress.equals("") && !mDeviceName.equals("")) { - danaRSService.connect(from, mDeviceAddress); + boolean success = danaRSService.connect(from, mDeviceAddress); + if (!success) + ToastUtils.showToastInUiThread(context, resourceHelper.gs(R.string.rileylink_scanner_ble_not_supported)); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.java deleted file mode 100644 index 89f794259e..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.java +++ /dev/null @@ -1,217 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS.activities; - -import android.bluetooth.BluetoothAdapter; -import android.bluetooth.BluetoothDevice; -import android.bluetooth.le.BluetoothLeScanner; -import android.bluetooth.le.ScanCallback; -import android.bluetooth.le.ScanResult; -import android.content.pm.ActivityInfo; -import android.os.Bundle; -import android.os.Handler; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.ListView; -import android.widget.TextView; - -import java.util.ArrayList; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.activities.NoSplashAppCompatActivity; -import info.nightscout.androidaps.plugins.bus.RxBus; -import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSDeviceChange; -import info.nightscout.androidaps.utils.SP; - -public class BLEScanActivity extends NoSplashAppCompatActivity { - private ListAdapter mListAdapter = null; - private ArrayList mDevices = new ArrayList<>(); - - private BluetoothLeScanner mBluetoothLeScanner = null; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.danars_blescanner_activity); - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); - - mListAdapter = new ListAdapter(); - - ListView listView = findViewById(R.id.danars_blescanner_listview); - listView.setEmptyView(findViewById(R.id.danars_blescanner_nodevice)); - listView.setAdapter(mListAdapter); - - mListAdapter.notifyDataSetChanged(); - } - - @Override - protected void onResume() { - super.onResume(); - - BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); - if (mBluetoothAdapter != null) { - if (!mBluetoothAdapter.isEnabled()) mBluetoothAdapter.enable(); - mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner(); - - if (mBluetoothLeScanner == null) { - mBluetoothAdapter.enable(); - mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner(); - } - startScan(); - } - } - - @Override - protected void onPause() { - super.onPause(); - - stopScan(); - } - - private void startScan() { - if (mBluetoothLeScanner != null) - mBluetoothLeScanner.startScan(mBleScanCallback); - } - - private void stopScan() { - if (mBluetoothLeScanner != null) - mBluetoothLeScanner.stopScan(mBleScanCallback); - } - - private void addBleDevice(BluetoothDevice device) { - if (device == null || device.getName() == null || device.getName().equals("")) { - return; - } - BluetoothDeviceItem item = new BluetoothDeviceItem(device); - if (!isSNCheck(device.getName()) || mDevices.contains(item)) { - return; - } - - mDevices.add(item); - new Handler().post(() -> mListAdapter.notifyDataSetChanged()); - } - - private ScanCallback mBleScanCallback = new ScanCallback() { - @Override - public void onScanResult(int callbackType, ScanResult result) { - addBleDevice(result.getDevice()); - } - }; - - class ListAdapter extends BaseAdapter { - - @Override - public int getCount() { - return mDevices.size(); - } - - @Override - public BluetoothDeviceItem getItem(int i) { - return mDevices.get(i); - } - - @Override - public long getItemId(int i) { - return 0; - } - - @Override - public View getView(int i, View convertView, ViewGroup parent) { - View v = convertView; - ViewHolder holder; - - if (v == null) { - v = View.inflate(getApplicationContext(), R.layout.danars_blescanner_item, null); - holder = new ViewHolder(v); - v.setTag(holder); - } else { - holder = (ViewHolder) v.getTag(); - } - - BluetoothDeviceItem item = getItem(i); - holder.setData(item); - return v; - } - - private class ViewHolder implements View.OnClickListener { - private BluetoothDeviceItem item = null; - - private TextView mName; - private TextView mAddress; - - ViewHolder(View v) { - mName = v.findViewById(R.id.ble_name); - mAddress = v.findViewById(R.id.ble_address); - - v.setOnClickListener(ViewHolder.this); - } - - @Override - public void onClick(View v) { - SP.putString(R.string.key_danars_address, item.device.getAddress()); - SP.putString(R.string.key_danars_name, mName.getText().toString()); - item.device.createBond(); - RxBus.Companion.getINSTANCE().send(new EventDanaRSDeviceChange()); - finish(); - } - - public void setData(BluetoothDeviceItem data) { - if (data != null) { - try { - String tTitle = data.device.getName(); - if (tTitle == null || tTitle.equals("")) { - tTitle = "(unknown)"; - } else if (tTitle.length() > 10) { - tTitle = tTitle.substring(0, 10); - } - mName.setText(tTitle); - - mAddress.setText(data.device.getAddress()); - - item = data; - } catch (Exception ignored) { - } - } - } - } - } - - // - private class BluetoothDeviceItem { - private BluetoothDevice device; - - BluetoothDeviceItem(BluetoothDevice device) { - super(); - this.device = device; - } - - @Override - public boolean equals(Object o) { - if (device == null || !(o instanceof BluetoothDeviceItem)) { - return false; - } - BluetoothDeviceItem checkItem = (BluetoothDeviceItem) o; - if (checkItem.device == null) { - return false; - } - return stringEquals(device.getAddress(), checkItem.device.getAddress()); - } - - boolean stringEquals(String arg1, String arg2) { - try { - return arg1.equals(arg2); - } catch (Exception e) { - return false; - } - } - } - - public static boolean isSNCheck(String sn) { - String regex = "^([a-zA-Z]{3})([0-9]{5})([a-zA-Z]{2})$"; - Pattern p = Pattern.compile(regex); - Matcher m = p.matcher(sn); - - return m.matches(); - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.kt new file mode 100644 index 0000000000..d51dc5ab05 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.kt @@ -0,0 +1,172 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.activities + +import android.annotation.SuppressLint +import android.bluetooth.BluetoothAdapter +import android.bluetooth.BluetoothDevice +import android.bluetooth.le.BluetoothLeScanner +import android.bluetooth.le.ScanCallback +import android.bluetooth.le.ScanResult +import android.content.pm.ActivityInfo +import android.os.Bundle +import android.os.Handler +import android.view.View +import android.view.ViewGroup +import android.widget.BaseAdapter +import android.widget.TextView +import info.nightscout.androidaps.R +import info.nightscout.androidaps.activities.NoSplashAppCompatActivity +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.pump.common.ble.BlePreCheck +import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSDeviceChange +import info.nightscout.androidaps.utils.sharedPreferences.SP +import kotlinx.android.synthetic.main.danars_blescanner_activity.* +import java.util.* +import java.util.regex.Pattern +import javax.inject.Inject + +class BLEScanActivity : NoSplashAppCompatActivity() { + + @Inject lateinit var sp: SP + @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var blePreCheck: BlePreCheck + + private var listAdapter: ListAdapter? = null + private val devices = ArrayList() + private var bluetoothLeScanner: BluetoothLeScanner? = null + + @SuppressLint("SourceLockedOrientationActivity") + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.danars_blescanner_activity) + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + + blePreCheck.prerequisitesCheck(this) + + listAdapter = ListAdapter() + danars_blescanner_listview.emptyView = findViewById(R.id.danars_blescanner_nodevice) + danars_blescanner_listview.adapter = listAdapter + listAdapter?.notifyDataSetChanged() + } + + override fun onResume() { + super.onResume() + + BluetoothAdapter.getDefaultAdapter()?.let { bluetoothAdapter -> + if (!bluetoothAdapter.isEnabled) bluetoothAdapter.enable() + bluetoothLeScanner = bluetoothAdapter.bluetoothLeScanner + startScan() + } + } + + override fun onPause() { + super.onPause() + stopScan() + } + + private fun startScan() { + if (bluetoothLeScanner != null) bluetoothLeScanner!!.startScan(mBleScanCallback) + } + + private fun stopScan() { + if (bluetoothLeScanner != null) bluetoothLeScanner!!.stopScan(mBleScanCallback) + } + + private fun addBleDevice(device: BluetoothDevice?) { + if (device == null || device.name == null || device.name == "") { + return + } + val item = BluetoothDeviceItem(device) + if (!isSNCheck(device.name) || devices.contains(item)) { + return + } + devices.add(item) + Handler().post { listAdapter!!.notifyDataSetChanged() } + } + + private val mBleScanCallback: ScanCallback = object : ScanCallback() { + override fun onScanResult(callbackType: Int, result: ScanResult) { + addBleDevice(result.device) + } + } + + internal inner class ListAdapter : BaseAdapter() { + override fun getCount(): Int = devices.size + override fun getItem(i: Int): BluetoothDeviceItem = devices[i] + override fun getItemId(i: Int): Long = 0 + + override fun getView(i: Int, convertView: View?, parent: ViewGroup?): View { + var v = convertView + val holder: ViewHolder + if (v == null) { + v = View.inflate(applicationContext, R.layout.danars_blescanner_item, null) + holder = ViewHolder(v) + v.tag = holder + } else { + // reuse view if already exists + holder = v.tag as ViewHolder + } + val item = getItem(i) + holder.setData(item) + return v!! + } + + private inner class ViewHolder internal constructor(v: View) : View.OnClickListener { + private lateinit var item: BluetoothDeviceItem + private val name: TextView = v.findViewById(R.id.ble_name) + private val address: TextView = v.findViewById(R.id.ble_address) + + init { + v.setOnClickListener(this@ViewHolder) + } + + override fun onClick(v: View) { + sp.putString(R.string.key_danars_address, item.device.address) + sp.putString(R.string.key_danars_name, name.text.toString()) + item.device.createBond() + rxBus.send(EventDanaRSDeviceChange()) + finish() + } + + fun setData(data: BluetoothDeviceItem) { + var tTitle = data.device.name + if (tTitle == null || tTitle == "") { + tTitle = "(unknown)" + } else if (tTitle.length > 10) { + tTitle = tTitle.substring(0, 10) + } + name.text = tTitle + address.text = data.device.address + item = data + } + + } + } + + // + inner class BluetoothDeviceItem internal constructor(val device: BluetoothDevice) { + + override fun equals(other: Any?): Boolean { + if (other !is BluetoothDeviceItem) { + return false + } + return stringEquals(device.address, other.device.address) + } + + private fun stringEquals(arg1: String, arg2: String): Boolean { + return try { + arg1 == arg2 + } catch (e: Exception) { + false + } + } + + override fun hashCode(): Int = device.hashCode() + } + + private fun isSNCheck(sn: String?): Boolean { + val regex = "^([a-zA-Z]{3})([0-9]{5})([a-zA-Z]{2})$" + val p = Pattern.compile(regex) + val m = p.matcher(sn) + return m.matches() + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt index ba73e1b368..03d31c10a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt @@ -1,11 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.activities +import android.annotation.SuppressLint import android.content.pm.ActivityInfo import android.os.Bundle import info.nightscout.androidaps.activities.NoSplashAppCompatActivity import info.nightscout.androidaps.plugins.pump.danaRS.dialogs.PairingProgressDialog class PairingHelperActivity : NoSplashAppCompatActivity() { + @SuppressLint("SourceLockedOrientationActivity") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) PairingProgressDialog() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt index b079d5c241..1260573c34 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt @@ -37,6 +37,7 @@ class BLEComm @Inject internal constructor( private val sp: SP, private val danaRSMessageHashTable: DanaRSMessageHashTable, private val danaRPump: DanaRPump, + private val danaRSPlugin: DanaRSPlugin, private val bleEncryption: BleEncryption ) { @@ -52,66 +53,51 @@ class BLEComm @Inject internal constructor( private var scheduledDisconnection: ScheduledFuture<*>? = null private var processedMessage: DanaRS_Packet? = null private val mSendQueue = ArrayList() - private var mBluetoothManager: BluetoothManager? = null - private var mBluetoothAdapter: BluetoothAdapter? = null + private var bluetoothManager: BluetoothManager? = null + private var bluetoothAdapter: BluetoothAdapter? = null private var connectDeviceName: String? = null - private var mBluetoothGatt: BluetoothGatt? = null + private var bluetoothGatt: BluetoothGatt? = null var isConnected = false var isConnecting = false private var uartRead: BluetoothGattCharacteristic? = null private var uartWrite: BluetoothGattCharacteristic? = null - init { - initialize() - } - - private fun initialize(): Boolean { + @Synchronized + fun connect(from: String, address: String?): Boolean { aapsLogger.debug(LTag.PUMPBTCOMM, "Initializing BLEComm.") - if (mBluetoothManager == null) { - mBluetoothManager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager - if (mBluetoothManager == null) { + if (bluetoothManager == null) { + bluetoothManager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager + if (bluetoothManager == null) { aapsLogger.error("Unable to initialize BluetoothManager.") return false } } - mBluetoothAdapter = mBluetoothManager?.adapter - if (mBluetoothAdapter == null) { + bluetoothAdapter = bluetoothManager?.adapter + if (bluetoothAdapter == null) { aapsLogger.error("Unable to obtain a BluetoothAdapter.") return false } - return true - } - - fun connect(from: String, address: String?): Boolean { - // test existing BT device - val tBluetoothManager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager? - ?: return false - tBluetoothManager.adapter ?: return false if (address == null) { aapsLogger.error("unspecified address.") return false } - if (mBluetoothAdapter == null) { - if (!initialize()) { - return false - } - } isConnecting = true - val device = mBluetoothAdapter?.getRemoteDevice(address) + val device = bluetoothAdapter?.getRemoteDevice(address) if (device == null) { aapsLogger.error("Device not found. Unable to connect from: $from") return false } aapsLogger.debug(LTag.PUMPBTCOMM, "Trying to create a new connection from: $from") connectDeviceName = device.name - mBluetoothGatt = device.connectGatt(context, false, mGattCallback) + bluetoothGatt = device.connectGatt(context, false, mGattCallback) setCharacteristicNotification(uartReadBTGattChar, true) return true } + @Synchronized fun stopConnecting() { isConnecting = false } @@ -124,21 +110,21 @@ class BLEComm @Inject internal constructor( scheduledDisconnection?.cancel(false) scheduledDisconnection = null - if (mBluetoothAdapter == null || mBluetoothGatt == null) { - aapsLogger.error("disconnect not possible: (mBluetoothAdapter == null) " + (mBluetoothAdapter == null)) - aapsLogger.error("disconnect not possible: (mBluetoothGatt == null) " + (mBluetoothGatt == null)) + if (bluetoothAdapter == null || bluetoothGatt == null) { + aapsLogger.error("disconnect not possible: (mBluetoothAdapter == null) " + (bluetoothAdapter == null)) + aapsLogger.error("disconnect not possible: (mBluetoothGatt == null) " + (bluetoothGatt == null)) return } setCharacteristicNotification(uartReadBTGattChar, false) - mBluetoothGatt?.disconnect() + bluetoothGatt?.disconnect() isConnected = false SystemClock.sleep(2000) } @Synchronized fun close() { aapsLogger.debug(LTag.PUMPBTCOMM, "BluetoothAdapter close") - mBluetoothGatt?.close() - mBluetoothGatt = null + bluetoothGatt?.close() + bluetoothGatt = null } private val mGattCallback: BluetoothGattCallback = object : BluetoothGattCallback() { @@ -185,20 +171,20 @@ class BLEComm @Inject internal constructor( @Synchronized private fun setCharacteristicNotification(characteristic: BluetoothGattCharacteristic?, enabled: Boolean) { aapsLogger.debug(LTag.PUMPBTCOMM, "setCharacteristicNotification") - if (mBluetoothAdapter == null || mBluetoothGatt == null) { + if (bluetoothAdapter == null || bluetoothGatt == null) { aapsLogger.error("BluetoothAdapter not initialized_ERROR") isConnecting = false isConnected = false return } - mBluetoothGatt!!.setCharacteristicNotification(characteristic, enabled) + bluetoothGatt!!.setCharacteristicNotification(characteristic, enabled) } @Synchronized private fun writeCharacteristicNoResponse(characteristic: BluetoothGattCharacteristic, data: ByteArray) { Thread(Runnable { SystemClock.sleep(WRITE_DELAY_MILLIS) - if (mBluetoothAdapter == null || mBluetoothGatt == null) { + if (bluetoothAdapter == null || bluetoothGatt == null) { aapsLogger.error("BluetoothAdapter not initialized_ERROR") isConnecting = false isConnected = false @@ -207,7 +193,7 @@ class BLEComm @Inject internal constructor( characteristic.value = data characteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE aapsLogger.debug("writeCharacteristic:" + DanaRS_Packet.toHexString(data)) - mBluetoothGatt!!.writeCharacteristic(characteristic) + bluetoothGatt!!.writeCharacteristic(characteristic) }).start() } @@ -220,15 +206,15 @@ class BLEComm @Inject internal constructor( ?: BluetoothGattCharacteristic(UUID.fromString(UART_WRITE_UUID), BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE, 0).also { uartWrite = it } private fun getSupportedGattServices(): List? { - aapsLogger.debug(LTag.PUMPBTCOMM, "getSupportedGattServices") - if (mBluetoothAdapter == null || mBluetoothGatt == null) { - aapsLogger.error("BluetoothAdapter not initialized_ERROR") - isConnecting = false - isConnected = false - return null - } - return mBluetoothGatt?.services + aapsLogger.debug(LTag.PUMPBTCOMM, "getSupportedGattServices") + if (bluetoothAdapter == null || bluetoothGatt == null) { + aapsLogger.error("BluetoothAdapter not initialized_ERROR") + isConnecting = false + isConnected = false + return null } + return bluetoothGatt?.services + } private fun findCharacteristic() { val gattServices = getSupportedGattServices() ?: return @@ -339,7 +325,7 @@ class BLEComm @Inject internal constructor( BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK.toByte() -> if (decryptedBuffer.size == 4 && decryptedBuffer[2] == 'O'.toByte() && decryptedBuffer[3] == 'K'.toByte()) { aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (OK)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) // Grab pairing key from preferences if exists - val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_pairingkey) + DanaRSPlugin.mDeviceName, "") + val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName, "") aapsLogger.debug(LTag.PUMPBTCOMM, "Using stored pairing key: $pairingKey") if (pairingKey.isNotEmpty()) { val encodedPairingKey = DanaRS_Packet.hexToBytes(pairingKey) @@ -366,7 +352,7 @@ class BLEComm @Inject internal constructor( aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (ERROR)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) mSendQueue.clear() rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.connectionerror))) - sp.remove(resourceHelper.gs(R.string.key_danars_pairingkey) + DanaRSPlugin.mDeviceName) + sp.remove(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName) val n = Notification(Notification.WRONGSERIALNUMBER, resourceHelper.gs(R.string.wrongpassword), Notification.URGENT) rxBus.send(EventNewNotification(n)) } @@ -396,7 +382,7 @@ class BLEComm @Inject internal constructor( sendTimeInfo() val pairingKey = byteArrayOf(decryptedBuffer[2], decryptedBuffer[3]) // store pairing key to preferences - sp.putString(resourceHelper.gs(R.string.key_danars_pairingkey) + DanaRSPlugin.mDeviceName, DanaRS_Packet.bytesToHex(pairingKey)) + sp.putString(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName, DanaRS_Packet.bytesToHex(pairingKey)) aapsLogger.debug(LTag.PUMPBTCOMM, "Got pairing key: " + DanaRS_Packet.bytesToHex(pairingKey)) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java index 84beb5871d..17f7b03a17 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java @@ -53,9 +53,6 @@ public class RileyLinkMedtronicService extends RileyLinkService { public RileyLinkMedtronicService() { super(); instance = this; - aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkMedtronicService newly constructed"); - MedtronicUtil.setMedtronicService(this); - pumpStatus = (MedtronicPumpStatus) medtronicPumpPlugin.getPumpStatusData(); } @@ -68,6 +65,12 @@ public class RileyLinkMedtronicService extends RileyLinkService { return instance.medtronicCommunicationManager; } + @Override public void onCreate() { + super.onCreate(); + aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkMedtronicService newly created"); + MedtronicUtil.setMedtronicService(this); + pumpStatus = (MedtronicPumpStatus) medtronicPumpPlugin.getPumpStatusData(); + } @Override public void onConfigurationChanged(Configuration newConfig) { From d1d49a8db23c5ccf80f710ca27f0b9a63b84d9f9 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 24 Mar 2020 21:00:43 +0100 Subject: [PATCH 03/53] improve PairingProgressDialog --- app/src/main/AndroidManifest.xml | 4 +- .../dependencyInjection/FragmentsModule.kt | 2 + .../activities/PairingHelperActivity.kt | 18 +++- .../danaRS/dialogs/PairingProgressDialog.java | 91 +++++++++++-------- 4 files changed, 76 insertions(+), 39 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index caf37d462d..01df007470 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -81,7 +81,9 @@ - + diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt index dbd9cdf424..361521ca10 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt @@ -33,6 +33,7 @@ import info.nightscout.androidaps.plugins.profile.local.LocalProfileFragment import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment import info.nightscout.androidaps.plugins.pump.combo.ComboFragment import info.nightscout.androidaps.plugins.pump.danaR.DanaRFragment +import info.nightscout.androidaps.plugins.pump.danaRS.dialogs.PairingProgressDialog import info.nightscout.androidaps.plugins.pump.insight.LocalInsightFragment import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicFragment import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpFragment @@ -83,6 +84,7 @@ abstract class FragmentsModule { @ContributesAndroidInjector abstract fun contributesVirtualPumpFragment(): VirtualPumpFragment + @ContributesAndroidInjector abstract fun contributesPairingProgressDialog(): PairingProgressDialog @ContributesAndroidInjector abstract fun contributesBolusProgressDialog(): BolusProgressDialog @ContributesAndroidInjector abstract fun contributesCalibrationDialog(): CalibrationDialog @ContributesAndroidInjector abstract fun contributesCarbsDialog(): CarbsDialog diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt index 03d31c10a2..5a2ab565ae 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt @@ -1,18 +1,32 @@ package info.nightscout.androidaps.plugins.pump.danaRS.activities import android.annotation.SuppressLint +import android.content.Intent import android.content.pm.ActivityInfo import android.os.Bundle import info.nightscout.androidaps.activities.NoSplashAppCompatActivity import info.nightscout.androidaps.plugins.pump.danaRS.dialogs.PairingProgressDialog class PairingHelperActivity : NoSplashAppCompatActivity() { + var dialog: PairingProgressDialog? = null + @SuppressLint("SourceLockedOrientationActivity") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - PairingProgressDialog() + dialog = PairingProgressDialog() .setHelperActivity(this) - .show(supportFragmentManager, "PairingProgress") + dialog?.show(supportFragmentManager, "PairingProgress") requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } + + override fun onDestroy() { + super.onDestroy() + dialog = null + } + + override fun onNewIntent(intent: Intent?) { + super.onNewIntent(intent) + dialog?.resetToNewPairing() + } + } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/dialogs/PairingProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/dialogs/PairingProgressDialog.java index 9518dac337..dcf17dc355 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/dialogs/PairingProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/dialogs/PairingProgressDialog.java @@ -14,19 +14,25 @@ import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; -import androidx.fragment.app.DialogFragment; +import javax.inject.Inject; -import info.nightscout.androidaps.MainApp; +import dagger.android.support.DaggerDialogFragment; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.bus.RxBus; +import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity; import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess; import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.resources.ResourceHelper; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.schedulers.Schedulers; -public class PairingProgressDialog extends DialogFragment { +public class PairingProgressDialog extends DaggerDialogFragment { + + @Inject ResourceHelper resourceHelper; + @Inject RxBusWrapper rxBus; + @Inject FabricPrivacy fabricPrivacy; + private CompositeDisposable disposable = new CompositeDisposable(); private TextView statusView; @@ -36,41 +42,21 @@ public class PairingProgressDialog extends DialogFragment { private static boolean pairingEnded = false; - private static Handler sHandler; - private static HandlerThread sHandlerThread; + private static Handler handler; + private static HandlerThread handlerThread; + + private static Runnable runnable; public PairingProgressDialog() { super(); // Required empty public constructor - if (sHandlerThread == null) { - sHandlerThread = new HandlerThread(PairingProgressDialog.class.getSimpleName()); - sHandlerThread.start(); - sHandler = new Handler(sHandlerThread.getLooper()); + if (handlerThread == null) { + handlerThread = new HandlerThread(PairingProgressDialog.class.getSimpleName()); + handlerThread.start(); + handler = new Handler(handlerThread.getLooper()); } - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.danars_pairingprogressdialog, container, false); - - getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); - getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); - setCancelable(false); - getDialog().setCanceledOnTouchOutside(false); - - statusView = view.findViewById(R.id.danars_pairingprogress_status); - progressBar = view.findViewById(R.id.danars_pairingprogress_progressbar); - button = view.findViewById(R.id.ok); - - progressBar.setMax(100); - progressBar.setProgress(0); - statusView.setText(MainApp.gs(R.string.waitingforpairing)); - button.setVisibility(View.GONE); - button.setOnClickListener(v -> dismiss()); - - sHandler.post(() -> { + runnable = () -> { for (int i = 0; i < 20; i++) { if (pairingEnded) { Activity activity = getActivity(); @@ -102,17 +88,36 @@ public class PairingProgressDialog extends DialogFragment { button.setVisibility(View.VISIBLE); }); } - }); + }; + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.danars_pairingprogressdialog, container, false); + + getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); + getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); + setCancelable(false); + getDialog().setCanceledOnTouchOutside(false); + + statusView = view.findViewById(R.id.danars_pairingprogress_status); + progressBar = view.findViewById(R.id.danars_pairingprogress_progressbar); + button = view.findViewById(R.id.ok); + + setViews(); + return view; } @Override public void onResume() { super.onResume(); - disposable.add(RxBus.Companion.getINSTANCE() + disposable.add(rxBus .toObservable(EventDanaRSPairingSuccess.class) .observeOn(Schedulers.io()) - .subscribe(event -> pairingEnded = true, exception -> FabricPrivacy.getInstance().logException(exception)) + .subscribe(event -> pairingEnded = true, fabricPrivacy::logException) ); if (pairingEnded) dismiss(); getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); @@ -132,6 +137,20 @@ public class PairingProgressDialog extends DialogFragment { disposable.clear(); } + private void setViews() { + progressBar.setMax(100); + progressBar.setProgress(0); + statusView.setText(resourceHelper.gs(R.string.waitingforpairing)); + button.setVisibility(View.GONE); + button.setOnClickListener(v -> dismiss()); + handler.post(runnable); + } + + public void resetToNewPairing() { + handler.removeCallbacks(runnable); + setViews(); + } + public PairingProgressDialog setHelperActivity(PairingHelperActivity activity) { this.helperActivity = activity; return this; From 5ce8b998d9f2530cbcb74abe92df6a16264295f8 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 26 Mar 2020 20:25:20 +0100 Subject: [PATCH 04/53] RS v3 encryption --- app/src/main/AndroidManifest.xml | 2 + .../dependencyInjection/ActivitiesModule.kt | 2 + .../pump/danaR/AbstractDanaRPlugin.java | 30 +- .../plugins/pump/danaR/DanaRFragment.kt | 22 ++ .../plugins/pump/danaRS/DanaRSPlugin.java | 7 + .../danaRS/activities/EnterPinActivity.kt | 99 ++++++ .../danaRS/comm/DanaRSMessageHashTable.kt | 2 +- ...cket_General_Initial_Screen_Information.kt | 1 - .../danaRS/comm/DanaRS_Packet_Notify_Alarm.kt | 14 +- .../pump/danaRS/encryption/BleEncryption.java | 2 +- .../plugins/pump/danaRS/services/BLEComm.kt | 310 +++++++++++++----- .../extensions/HexByteArrayConversion.kt | 32 ++ .../textValidator/DefaultEditTextValidator.kt | 23 +- .../ValidatingEditTextPreference.kt | 3 +- .../res/layout/danars_enter_pin_activity.xml | 90 +++++ app/src/main/res/values/strings.xml | 12 + app/src/main/res/values/validator.xml | 4 + .../comm/DanaRS_Packet_Notify_AlarmTest.kt | 2 +- 18 files changed, 549 insertions(+), 108 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/EnterPinActivity.kt create mode 100644 app/src/main/java/info/nightscout/androidaps/utils/extensions/HexByteArrayConversion.kt create mode 100644 app/src/main/res/layout/danars_enter_pin_activity.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 01df007470..c89a41390a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -84,6 +84,8 @@ + diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt index e7411ad56b..57c8aea06e 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt @@ -13,6 +13,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyL import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRHistoryActivity import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRUserOptionsActivity import info.nightscout.androidaps.plugins.pump.danaRS.activities.BLEScanActivity +import info.nightscout.androidaps.plugins.pump.danaRS.activities.EnterPinActivity import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity import info.nightscout.androidaps.plugins.pump.insight.activities.InsightAlertActivity import info.nightscout.androidaps.plugins.pump.insight.activities.InsightPairingActivity @@ -28,6 +29,7 @@ abstract class ActivitiesModule { @ContributesAndroidInjector abstract fun contributeBolusProgressHelperActivity(): BolusProgressHelperActivity @ContributesAndroidInjector abstract fun contributeDanaRHistoryActivity(): DanaRHistoryActivity @ContributesAndroidInjector abstract fun contributeDanaRUserOptionsActivity(): DanaRUserOptionsActivity + @ContributesAndroidInjector abstract fun contributeEnterPinActivity(): EnterPinActivity @ContributesAndroidInjector abstract fun contributeErrorHelperActivity(): ErrorHelperActivity @ContributesAndroidInjector abstract fun contributesHistoryBrowseActivity(): HistoryBrowseActivity @ContributesAndroidInjector abstract fun contributesInsightAlertActivity(): InsightAlertActivity diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java index b448990575..6de5376b89 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java @@ -15,6 +15,8 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.events.EventConfigBuilderChange; +import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.interfaces.CommandQueueProvider; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.ConstraintsInterface; @@ -42,6 +44,8 @@ import info.nightscout.androidaps.utils.DecimalFormatter; import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.sharedPreferences.SP; +import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.schedulers.Schedulers; /** * Created by mike on 28.01.2018. @@ -50,6 +54,8 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP; public abstract class AbstractDanaRPlugin extends PumpPluginBase implements PumpInterface, DanaRInterface, ConstraintsInterface { protected AbstractDanaRExecutionService sExecutionService; + protected CompositeDisposable disposable = new CompositeDisposable(); + protected boolean useExtendedBoluses = false; protected PumpDescription pumpDescription = new PumpDescription(); @@ -86,6 +92,28 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump this.sp = sp; } + @Override protected void onStart() { + super.onStart(); + disposable.add(rxBus + .toObservable(EventConfigBuilderChange.class) + .observeOn(Schedulers.io()) + .subscribe(event -> danaRPump.setLastConnection(0)) + ); + disposable.add(rxBus + .toObservable(EventPreferenceChange.class) + .observeOn(Schedulers.io()) + .subscribe(event -> { + if (event.isChanged(getResourceHelper(), R.string.key_danar_bt_name)) + danaRPump.setLastConnection(0); + }) + ); + } + + @Override protected void onStop() { + super.onStop(); + disposable.clear(); + } + @Override public boolean isSuspended() { return danaRPump.getPumpSuspended(); @@ -488,6 +516,4 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump public void timeDateOrTimeZoneChanged() { } - - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt index 2e7104c9e1..e9e001ced0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt @@ -11,6 +11,7 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.TDDStatsActivity import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.events.EventExtendedBolusChange +import info.nightscout.androidaps.events.EventInitializationChanged import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.events.EventTempBasalChange import info.nightscout.androidaps.interfaces.ActivePluginProvider @@ -24,13 +25,16 @@ import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRHistoryActi import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRUserOptionsActivity import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin +import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.queue.events.EventQueueChanged import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.OKDialog import info.nightscout.androidaps.utils.SetWarnColor import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.extensions.plusAssign import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import kotlinx.android.synthetic.main.danar_fragment.* @@ -43,8 +47,10 @@ class DanaRFragment : DaggerFragment() { @Inject lateinit var commandQueue: CommandQueueProvider @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var danaRKoreanPlugin: DanaRKoreanPlugin + @Inject lateinit var danaRSPlugin: DanaRSPlugin @Inject lateinit var danaRPump: DanaRPump @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var sp: SP private var disposable: CompositeDisposable = CompositeDisposable() @@ -93,12 +99,28 @@ class DanaRFragment : DaggerFragment() { danaRPump.lastConnection = 0 commandQueue.readStatus("Clicked connect to pump", null) } + if (danaRSPlugin.isEnabled()) + danar_btconnection.setOnLongClickListener { + activity?.let { + OKDialog.showConfirmation(it, resourceHelper.gs(R.string.resetpairing), Runnable { + sp.remove(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName) + sp.remove(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName) + sp.remove(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName) + sp.remove(resourceHelper.gs(R.string.key_danars_v3_randomsynckey) + danaRSPlugin.mDeviceName) + }) + } + true + } } @Synchronized override fun onResume() { super.onResume() loopHandler.postDelayed(refreshLoop, T.mins(1).msecs()) + disposable += rxBus + .toObservable(EventInitializationChanged::class.java) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe({ updateGUI() }, { fabricPrivacy.logException(it) }) disposable += rxBus .toObservable(EventDanaRNewStatus::class.java) .observeOn(AndroidSchedulers.mainThread()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java index 3e865cb0e4..759b473d75 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java @@ -27,6 +27,7 @@ import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.events.EventAppExit; +import info.nightscout.androidaps.events.EventConfigBuilderChange; import info.nightscout.androidaps.interfaces.CommandQueueProvider; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.ConstraintsInterface; @@ -157,6 +158,11 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR .observeOn(Schedulers.io()) .subscribe(event -> context.unbindService(mConnection), fabricPrivacy::logException) ); + disposable.add(rxBus + .toObservable(EventConfigBuilderChange.class) + .observeOn(Schedulers.io()) + .subscribe(event -> danaRPump.setLastConnection(0)) + ); disposable.add(rxBus .toObservable(EventDanaRSDeviceChange.class) .observeOn(Schedulers.io()) @@ -191,6 +197,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR private void loadAddress() { mDeviceAddress = sp.getString(R.string.key_danars_address, ""); mDeviceName = sp.getString(R.string.key_danars_name, ""); + danaRPump.setLastConnection(0); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/EnterPinActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/EnterPinActivity.kt new file mode 100644 index 0000000000..524dfc9976 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/EnterPinActivity.kt @@ -0,0 +1,99 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.activities + +import android.os.Bundle +import android.util.Base64 +import info.nightscout.androidaps.R +import info.nightscout.androidaps.activities.NoSplashAppCompatActivity +import info.nightscout.androidaps.events.EventPumpStatusChanged +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin +import info.nightscout.androidaps.plugins.pump.danaRS.services.BLEComm +import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.OKDialog +import info.nightscout.androidaps.utils.extensions.hexStringToByteArray +import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.androidaps.utils.sharedPreferences.SP +import info.nightscout.androidaps.utils.textValidator.DefaultEditTextValidator +import info.nightscout.androidaps.utils.textValidator.EditTextValidator +import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.disposables.CompositeDisposable +import kotlinx.android.synthetic.main.danars_enter_pin_activity.* +import kotlinx.android.synthetic.main.okcancel.* +import javax.inject.Inject +import kotlin.experimental.xor + +class EnterPinActivity : NoSplashAppCompatActivity() { + + @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var fabricPrivacy: FabricPrivacy + @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var danaRSPlugin: DanaRSPlugin + @Inject lateinit var sp: SP + @Inject lateinit var bleComm: BLEComm + + private val disposable = CompositeDisposable() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.danars_enter_pin_activity) + + val p1 = DefaultEditTextValidator(rs_v3_pin1, this) + .setTestErrorString(resourceHelper.gs(R.string.error_mustbe12hexadidits), this) + .setCustomRegexp(resourceHelper.gs(R.string.twelvehexanumber), this) + .setTestType(EditTextValidator.TEST_REGEXP, this) + val p2 = DefaultEditTextValidator(rs_v3_pin2, this) + .setTestErrorString(resourceHelper.gs(R.string.error_mustbe8hexadidits), this) + .setCustomRegexp(resourceHelper.gs(R.string.eighthexanumber), this) + .setTestType(EditTextValidator.TEST_REGEXP, this) + + ok.setOnClickListener { + if (p1.testValidity(false) && p2.testValidity(false)) { + val result = checkPairingCheckSum( + rs_v3_pin1.text.toString().hexStringToByteArray(), + rs_v3_pin2.text.toString().substring(0..5).hexStringToByteArray(), + rs_v3_pin2.text.toString().substring(6..7).hexStringToByteArray()) + if (result) { + bleComm.finishV3Pairing() + finish() + } + else OKDialog.show(this, resourceHelper.gs(R.string.error), resourceHelper.gs(R.string.danar_invalidinput)) + } + } + cancel.setOnClickListener { finish() } + } + + override fun onResume() { + super.onResume() + disposable.add(rxBus + .toObservable(EventPumpStatusChanged::class.java) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe({ if (it.status == EventPumpStatusChanged.Status.DISCONNECTED) finish() }) { fabricPrivacy.logException(it) } + ) + } + + override fun onPause() { + super.onPause() + disposable.clear() + } + + private fun checkPairingCheckSum(pairingKey: ByteArray, randomPairingKey: ByteArray, checksum: ByteArray): Boolean { + + // pairingKey ByteArray(6) + // randomPairingKey ByteArray(3) + // checksum ByteArray(1) + + var pairingKeyCheckSum: Byte = 0 + for (i in pairingKey.indices) + pairingKeyCheckSum = pairingKeyCheckSum xor pairingKey[i] + + sp.putString(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName, Base64.encodeToString(pairingKey, Base64.DEFAULT)) + + for (i in randomPairingKey.indices) + pairingKeyCheckSum = pairingKeyCheckSum xor randomPairingKey[i] + + sp.putString(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName, Base64.encodeToString(randomPairingKey, Base64.DEFAULT)) + + return checksum[0] == pairingKeyCheckSum + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt index c589bbe633..224ecd9ae5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt @@ -69,7 +69,7 @@ class DanaRSMessageHashTable @Inject constructor( put(DanaRS_Packet_General_Delivery_Status(aapsLogger)) put(DanaRS_Packet_General_Get_Password(aapsLogger, danaRPump)) put(DanaRS_Packet_General_Initial_Screen_Information(aapsLogger, danaRPump)) - put(DanaRS_Packet_Notify_Alarm(aapsLogger, resourceHelper)) + put(DanaRS_Packet_Notify_Alarm(aapsLogger, resourceHelper, rxBus)) put(DanaRS_Packet_Notify_Delivery_Complete(aapsLogger, rxBus, resourceHelper, danaRSPlugin)) put(DanaRS_Packet_Notify_Delivery_Rate_Display(aapsLogger, rxBus, resourceHelper, danaRSPlugin)) put(DanaRS_Packet_Notify_Missed_Bolus_Alarm(aapsLogger)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt index 574791a005..03471e7408 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt @@ -11,7 +11,6 @@ class DanaRS_Packet_General_Initial_Screen_Information( ) : DanaRS_Packet() { init { - type = BleEncryption.DANAR_PACKET__TYPE_RESPONSE opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__INITIAL_SCREEN_INFORMATION aapsLogger.debug(LTag.PUMPCOMM, "New message") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt index 7650ff3704..f461c65f3c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt @@ -4,12 +4,16 @@ import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.nsclient.NSUpload +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification import info.nightscout.androidaps.utils.resources.ResourceHelper class DanaRS_Packet_Notify_Alarm( private val aapsLogger: AAPSLogger, - private val resourceHelper: ResourceHelper + private val resourceHelper: ResourceHelper, + private val rxBus: RxBusWrapper ) : DanaRS_Packet() { init { @@ -29,11 +33,11 @@ class DanaRS_Packet_Notify_Alarm( 0x03 -> // Occlusion errorString = resourceHelper.gs(R.string.occlusion) 0x04 -> // LOW BATTERY - errorString = resourceHelper.gs(R.string.lowbattery) + errorString = resourceHelper.gs(R.string.pumpshutdown) 0x05 -> // Shutdown errorString = resourceHelper.gs(R.string.lowbattery) 0x06 -> // Basal Compare - errorString = "BasalCompare ????" + errorString = resourceHelper.gs(R.string.basalcompare) 0x09 -> // Empty Reservoir errorString = resourceHelper.gs(R.string.emptyreservoir) 0x07, 0xFF -> // Blood sugar measurement alert @@ -41,7 +45,7 @@ class DanaRS_Packet_Notify_Alarm( 0x08, 0xFE -> // Remaining insulin level errorString = resourceHelper.gs(R.string.remaininsulinalert) 0xFD -> // Blood sugar check miss alarm - errorString = "Blood sugar check miss alarm ???" + errorString = resourceHelper.gs(R.string.missedbolus) } // No error no need to upload anything if (errorString == "") { @@ -49,6 +53,8 @@ class DanaRS_Packet_Notify_Alarm( aapsLogger.debug(LTag.PUMPCOMM, "Error detected: $errorString") return } + val notification = Notification(Notification.USERMESSAGE, errorString, Notification.URGENT) + rxBus.send(EventNewNotification(notification)) NSUpload.uploadError(errorString) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java index edd36f583e..b4fea5d8be 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java @@ -140,7 +140,7 @@ public class BleEncryption { return encryptSecondLevelPacketJni(context, bytes); } - public byte[] ecryptSecondLevelPacket(byte[] bytes) { + public byte[] decryptSecondLevelPacket(byte[] bytes) { return decryptSecondLevelPacketJni(context, bytes); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt index 1260573c34..1e6a5f1642 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt @@ -4,6 +4,7 @@ import android.bluetooth.* import android.content.Context import android.content.Intent import android.os.SystemClock +import android.util.Base64 import info.nightscout.androidaps.R import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.logging.AAPSLogger @@ -14,11 +15,13 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotifi import info.nightscout.androidaps.plugins.general.overview.notifications.Notification import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin +import info.nightscout.androidaps.plugins.pump.danaRS.activities.EnterPinActivity import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSMessageHashTable import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess +import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import okhttp3.internal.notify @@ -58,8 +61,17 @@ class BLEComm @Inject internal constructor( private var connectDeviceName: String? = null private var bluetoothGatt: BluetoothGatt? = null + private var v3Encryption: Boolean = false + set(newValue) { + bleEncryption.setEnhancedEncryption(newValue) + field = newValue + } + private var isEasyMode: Boolean = false + private var isUnitUD: Boolean = false + var isConnected = false var isConnecting = false + private var encryptedDataRead = false private var uartRead: BluetoothGattCharacteristic? = null private var uartWrite: BluetoothGattCharacteristic? = null @@ -106,6 +118,14 @@ class BLEComm @Inject internal constructor( fun disconnect(from: String) { aapsLogger.debug(LTag.PUMPBTCOMM, "disconnect from: $from") + if (!encryptedDataRead) { + // there was no response from pump after started encryption + // assume pairing keys are invalid + sp.remove(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName) + sp.remove(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName) + sp.remove(resourceHelper.gs(R.string.key_danars_v3_randomsynckey) + danaRSPlugin.mDeviceName) + ToastUtils.showToastInUiThread(context, R.string.invalidpairing) + } // cancel previous scheduled disconnection to prevent closing upcoming connection scheduledDisconnection?.cancel(false) scheduledDisconnection = null @@ -118,6 +138,7 @@ class BLEComm @Inject internal constructor( setCharacteristicNotification(uartReadBTGattChar, false) bluetoothGatt?.disconnect() isConnected = false + encryptedDataRead = false SystemClock.sleep(2000) } @@ -142,19 +163,20 @@ class BLEComm @Inject internal constructor( } override fun onCharacteristicRead(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) { - aapsLogger.debug(LTag.PUMPBTCOMM, "onCharacteristicRead: " + DanaRS_Packet.toHexString(characteristic.value)) - addToReadBuffer(characteristic.value) - readDataParsing() + // for v3 after initial handshake it's encrypted - useless + // aapsLogger.debug(LTag.PUMPBTCOMM, "onCharacteristicRead: " + DanaRS_Packet.toHexString(characteristic.value)) + readDataParsing(characteristic.value) } override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic) { - aapsLogger.debug(LTag.PUMPBTCOMM, "onCharacteristicChanged: " + DanaRS_Packet.toHexString(characteristic.value)) - addToReadBuffer(characteristic.value) - Thread(Runnable { readDataParsing() }).start() + // for v3 after initial handshake it's encrypted - useless + // aapsLogger.debug(LTag.PUMPBTCOMM, "onCharacteristicChanged: " + DanaRS_Packet.toHexString(characteristic.value)) + readDataParsing(characteristic.value) } override fun onCharacteristicWrite(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) { - aapsLogger.debug(LTag.PUMPBTCOMM, "onCharacteristicWrite: " + DanaRS_Packet.toHexString(characteristic.value)) + // for v3 after initial handshake it's encrypted - useless + // aapsLogger.debug(LTag.PUMPBTCOMM, "onCharacteristicWrite: " + DanaRS_Packet.toHexString(characteristic.value)) Thread(Runnable { synchronized(mSendQueue) { // after message sent, check if there is the rest of the message waiting and send it @@ -175,9 +197,10 @@ class BLEComm @Inject internal constructor( aapsLogger.error("BluetoothAdapter not initialized_ERROR") isConnecting = false isConnected = false + encryptedDataRead = false return } - bluetoothGatt!!.setCharacteristicNotification(characteristic, enabled) + bluetoothGatt?.setCharacteristicNotification(characteristic, enabled) } @Synchronized @@ -188,13 +211,15 @@ class BLEComm @Inject internal constructor( aapsLogger.error("BluetoothAdapter not initialized_ERROR") isConnecting = false isConnected = false + encryptedDataRead = false return@Runnable } characteristic.value = data characteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE - aapsLogger.debug("writeCharacteristic:" + DanaRS_Packet.toHexString(data)) - bluetoothGatt!!.writeCharacteristic(characteristic) + //aapsLogger.debug("writeCharacteristic:" + DanaRS_Packet.toHexString(data)) + bluetoothGatt?.writeCharacteristic(characteristic) }).start() + waitMillis(50) } private val uartReadBTGattChar: BluetoothGattCharacteristic @@ -211,6 +236,7 @@ class BLEComm @Inject internal constructor( aapsLogger.error("BluetoothAdapter not initialized_ERROR") isConnecting = false isConnected = false + encryptedDataRead = false return null } return bluetoothGatt?.services @@ -243,6 +269,8 @@ class BLEComm @Inject internal constructor( close() isConnected = false isConnecting = false + v3Encryption = false + encryptedDataRead = false rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED)) aapsLogger.debug(LTag.PUMPBTCOMM, "Device was disconnected " + gatt.device.name) //Device was disconnected } @@ -263,13 +291,20 @@ class BLEComm @Inject internal constructor( } } - private fun readDataParsing() { + private fun readDataParsing(receviedData: ByteArray) { + //aapsLogger.debug(LTag.PUMPBTCOMM, "readDataParsing") var startSignatureFound = false var packetIsValid = false var isProcessing: Boolean isProcessing = true var inputBuffer: ByteArray? = null + // decrypt 2nd level after successful connection + val incomingBuffer = if (v3Encryption && isConnected) + bleEncryption.decryptSecondLevelPacket(receviedData).also { encryptedDataRead = true } + else receviedData + addToReadBuffer(incomingBuffer) + while (isProcessing) { var length = 0 synchronized(readBuffer) { @@ -321,85 +356,163 @@ class BLEComm @Inject internal constructor( // decrypt the packet bleEncryption.getDecryptedPacket(inputBuffer)?.let { decryptedBuffer -> when (decryptedBuffer[0]) { - BleEncryption.DANAR_PACKET__TYPE_ENCRYPTION_RESPONSE.toByte() -> when (decryptedBuffer[1]) { - BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK.toByte() -> if (decryptedBuffer.size == 4 && decryptedBuffer[2] == 'O'.toByte() && decryptedBuffer[3] == 'K'.toByte()) { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (OK)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) - // Grab pairing key from preferences if exists - val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName, "") - aapsLogger.debug(LTag.PUMPBTCOMM, "Using stored pairing key: $pairingKey") - if (pairingKey.isNotEmpty()) { - val encodedPairingKey = DanaRS_Packet.hexToBytes(pairingKey) - val bytes = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY, encodedPairingKey, null) - aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__CHECK_PASSKEY" + " " + DanaRS_Packet.toHexString(bytes)) - writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) - } else { - // Stored pairing key does not exists, request pairing - sendPairingRequest() - } - } else if (decryptedBuffer.size == 6 && decryptedBuffer[2] == 'P'.toByte() && decryptedBuffer[3] == 'U'.toByte() && decryptedBuffer[4] == 'M'.toByte() && decryptedBuffer[5] == 'P'.toByte()) { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (PUMP)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) - mSendQueue.clear() - rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.pumperror))) - NSUpload.uploadError(resourceHelper.gs(R.string.pumperror)) - val n = Notification(Notification.PUMPERROR, resourceHelper.gs(R.string.pumperror), Notification.URGENT) - rxBus.send(EventNewNotification(n)) - } else if (decryptedBuffer.size == 6 && decryptedBuffer[2] == 'B'.toByte() && decryptedBuffer[3] == 'U'.toByte() && decryptedBuffer[4] == 'S'.toByte() && decryptedBuffer[5] == 'Y'.toByte()) { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (BUSY)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) - mSendQueue.clear() - rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.pumpbusy))) - } else { - // ERROR in response, wrong serial number - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (ERROR)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) - mSendQueue.clear() - rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.connectionerror))) - sp.remove(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName) - val n = Notification(Notification.WRONGSERIALNUMBER, resourceHelper.gs(R.string.wrongpassword), Notification.URGENT) - rxBus.send(EventNewNotification(n)) - } + BleEncryption.DANAR_PACKET__TYPE_ENCRYPTION_RESPONSE.toByte() -> + when (decryptedBuffer[1]) { + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK.toByte() -> + if (decryptedBuffer.size == 4 && decryptedBuffer[2] == 'O'.toByte() && decryptedBuffer[3] == 'K'.toByte()) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (OK)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + v3Encryption = false + // Grab pairing key from preferences if exists + val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName, "") + aapsLogger.debug(LTag.PUMPBTCOMM, "Using stored pairing key: $pairingKey") + if (pairingKey.isNotEmpty()) { + val encodedPairingKey = DanaRS_Packet.hexToBytes(pairingKey) + val bytes = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY, encodedPairingKey, null) + aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__CHECK_PASSKEY" + " " + DanaRS_Packet.toHexString(bytes)) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } else { + // Stored pairing key does not exists, request pairing + sendPairingRequest() + } + } else if (decryptedBuffer.size == 9 && decryptedBuffer[2] == 'O'.toByte() && decryptedBuffer[3] == 'K'.toByte()) { + // v3 2nd layer encryption + v3Encryption = true + val model = decryptedBuffer[5] + // val protocol = decryptedBuffer[7] + if (model == 0x05.toByte()) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK V3 (OK)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + // Dana RS Pump + val randomPairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName, "") + val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName, "") + if (randomPairingKey.isNotEmpty() && pairingKey.isNotEmpty()) { + val randomSyncKey = String.format("%02x", decryptedBuffer[decryptedBuffer.size - 1]) + sp.putString(resourceHelper.gs(R.string.key_danars_v3_randomsynckey) + danaRSPlugin.mDeviceName, randomSyncKey) + val tPairingKey = Base64.decode(pairingKey, Base64.DEFAULT) + val tRandomPairingKey = Base64.decode(randomPairingKey, Base64.DEFAULT) + var tRandomSyncKey: Byte = 0 + if (randomSyncKey.isNotEmpty()) { + tRandomSyncKey = randomSyncKey.toInt(16).toByte() + } + bleEncryption.setPairingKeys(tPairingKey, tRandomPairingKey, tRandomSyncKey) + sendV3PairingInformation(0) + } else { + sendV3PairingInformation(1) + } + } else if (model == 0x06.toByte()) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK V3 EASY (OK)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + // Dana RS Easy + val bytes: ByteArray = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__GET_EASYMENU_CHECK, null, null) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } + } else if (decryptedBuffer.size == 6 && decryptedBuffer[2] == 'P'.toByte() && decryptedBuffer[3] == 'U'.toByte() && decryptedBuffer[4] == 'M'.toByte() && decryptedBuffer[5] == 'P'.toByte()) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (PUMP)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + mSendQueue.clear() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.pumperror))) + NSUpload.uploadError(resourceHelper.gs(R.string.pumperror)) + val n = Notification(Notification.PUMPERROR, resourceHelper.gs(R.string.pumperror), Notification.URGENT) + rxBus.send(EventNewNotification(n)) + } else if (decryptedBuffer.size == 6 && decryptedBuffer[2] == 'B'.toByte() && decryptedBuffer[3] == 'U'.toByte() && decryptedBuffer[4] == 'S'.toByte() && decryptedBuffer[5] == 'Y'.toByte()) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (BUSY)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + mSendQueue.clear() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.pumpbusy))) + } else { + // ERROR in response, wrong serial number + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (ERROR)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + mSendQueue.clear() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.connectionerror))) + sp.remove(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName) + val n = Notification(Notification.WRONGSERIALNUMBER, resourceHelper.gs(R.string.wrongpassword), Notification.URGENT) + rxBus.send(EventNewNotification(n)) + } - BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY.toByte() -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__CHECK_PASSKEY" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) - if (decryptedBuffer[2] == 0x00.toByte()) { - // Paring is not requested, sending time info + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION.toByte() -> { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__TIME_INFORMATION " + /*message.getMessageName() + " " + */DanaRS_Packet.toHexString(decryptedBuffer)) + if (v3Encryption) { + // decryptedBuffer[2] : 0x00 OK 0x01 Error, No pairing + if (decryptedBuffer[2] == 0x00.toByte()) { + val randomPairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName, "") + val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName, "") + if (randomPairingKey.isNotEmpty() && pairingKey.isNotEmpty()) { + // expecting successful connect + isConnected = true + isConnecting = false + aapsLogger.debug(LTag.PUMPBTCOMM, "Connect !!") + } else { + context.startActivity(Intent(context, EnterPinActivity::class.java).also { it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) }) + aapsLogger.debug(LTag.PUMPBTCOMM, "Request pairing keys !!") + } + } else { + sendV3PairingInformation(1) + } + + } else { + val size = decryptedBuffer.size + var pass: Int = (decryptedBuffer[size - 1].toInt() and 0x000000FF shl 8) + (decryptedBuffer[size - 2].toInt() and 0x000000FF) + pass = pass xor 3463 + danaRPump.rsPassword = Integer.toHexString(pass) + aapsLogger.debug(LTag.PUMPBTCOMM, "Pump user password: " + Integer.toHexString(pass)) + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED)) + isConnected = true + isConnecting = false + aapsLogger.debug(LTag.PUMPBTCOMM, "RS connected and status read") + } + } + + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY.toByte() -> { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__CHECK_PASSKEY" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + if (decryptedBuffer[2] == 0x00.toByte()) { + // Paring is not requested, sending time info + sendTimeInfo() + } else { + // Pairing on pump is requested + sendPairingRequest() + } + } + + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_REQUEST.toByte() -> { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PASSKEY_REQUEST " + DanaRS_Packet.toHexString(decryptedBuffer)) + if (decryptedBuffer[2] != 0x00.toByte()) { + disconnect("passkey request failed") + } + } + + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_RETURN.toByte() -> { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PASSKEY_RETURN " + DanaRS_Packet.toHexString(decryptedBuffer)) + // Paring is successful, sending time info + rxBus.send(EventDanaRSPairingSuccess()) sendTimeInfo() - } else { - // Pairing on pump is requested - sendPairingRequest() + val pairingKey = byteArrayOf(decryptedBuffer[2], decryptedBuffer[3]) + // store pairing key to preferences + sp.putString(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName, DanaRS_Packet.bytesToHex(pairingKey)) + aapsLogger.debug(LTag.PUMPBTCOMM, "Got pairing key: " + DanaRS_Packet.bytesToHex(pairingKey)) + } + + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__GET_PUMP_CHECK.toByte() -> { + if (decryptedBuffer[2] == 0x05.toByte()) { + // not easy mode, request time info + val bytes: ByteArray = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION, null, null) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } else { + // easy mode + val bytes: ByteArray = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__GET_EASYMENU_CHECK, null, null) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } + } + + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__GET_EASYMENU_CHECK.toByte() -> { + isEasyMode = decryptedBuffer[2] == 0x01.toByte() + isUnitUD = decryptedBuffer[3] == 0x01.toByte() + + // request time information + if (v3Encryption) { + sendV3PairingInformation(1) + } else { + val bytes: ByteArray = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION, null, null) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } } } - BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_REQUEST.toByte() -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PASSKEY_REQUEST " + DanaRS_Packet.toHexString(decryptedBuffer)) - if (decryptedBuffer[2] != 0x00.toByte()) { - disconnect("passkey request failed") - } - } - - BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_RETURN.toByte() -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PASSKEY_RETURN " + DanaRS_Packet.toHexString(decryptedBuffer)) - // Paring is successful, sending time info - rxBus.send(EventDanaRSPairingSuccess()) - sendTimeInfo() - val pairingKey = byteArrayOf(decryptedBuffer[2], decryptedBuffer[3]) - // store pairing key to preferences - sp.putString(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName, DanaRS_Packet.bytesToHex(pairingKey)) - aapsLogger.debug(LTag.PUMPBTCOMM, "Got pairing key: " + DanaRS_Packet.bytesToHex(pairingKey)) - } - - BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION.toByte() -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__TIME_INFORMATION " + /*message.getMessageName() + " " + */DanaRS_Packet.toHexString(decryptedBuffer)) - val size = decryptedBuffer.size - var pass: Int = (decryptedBuffer[size - 1].toInt() and 0x000000FF shl 8) + (decryptedBuffer[size - 2].toInt() and 0x000000FF) - pass = pass xor 3463 - danaRPump.rsPassword = Integer.toHexString(pass) - aapsLogger.debug(LTag.PUMPBTCOMM, "Pump user password: " + Integer.toHexString(pass)) - rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED)) - isConnected = true - isConnecting = false - aapsLogger.debug(LTag.PUMPBTCOMM, "RS connected and status read") - } - } - else -> { // Retrieve message code from received buffer and last message sent val originalCommand = processedMessage?.command ?: 0xFFFF @@ -449,6 +562,8 @@ class BLEComm @Inject internal constructor( val params = message.requestParams aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + message.friendlyName + " " + DanaRS_Packet.toHexString(command) + " " + DanaRS_Packet.toHexString(params)) var bytes = bleEncryption.getEncryptedPacket(message.opCode, params, null) + if (v3Encryption) + bytes = bleEncryption.encryptSecondLevelPacket(bytes) // If there is another message not completely sent, add to queue only if (mSendQueue.size > 0) { // Split to parts per 20 bytes max @@ -509,13 +624,30 @@ class BLEComm @Inject internal constructor( } } + fun finishV3Pairing() { + val randomPairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName, "") + val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName, "") + if (randomPairingKey.isNotEmpty() && pairingKey.isNotEmpty()) { + val tPairingKey = Base64.decode(pairingKey, Base64.DEFAULT) + val tRandomPairingKey = Base64.decode(randomPairingKey, Base64.DEFAULT) + val tRandomSyncKey: Byte = 0 + bleEncryption.setPairingKeys(tPairingKey, tRandomPairingKey, tRandomSyncKey) + sendV3PairingInformation(0) + } + } + + // 0x00 Start encryption, 0x01 Request pairing + private fun sendV3PairingInformation(requestNewPairing: Int) { + val params = byteArrayOf(requestNewPairing.toByte()) + val bytes: ByteArray = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION, params, null) + aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__TIME_INFORMATION" + " " + DanaRS_Packet.toHexString(bytes)) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } + private fun sendPairingRequest() { // Start activity which is waiting 20sec // On pump pairing request is displayed and is waiting for conformation - val i = Intent() - i.setClass(context, PairingHelperActivity::class.java) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(i) + context.startActivity(Intent(context, PairingHelperActivity::class.java).also { it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) }) val bytes = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_REQUEST, null, null) aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__PASSKEY_REQUEST" + " " + DanaRS_Packet.toHexString(bytes)) writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/extensions/HexByteArrayConversion.kt b/app/src/main/java/info/nightscout/androidaps/utils/extensions/HexByteArrayConversion.kt new file mode 100644 index 0000000000..9852ecbbf4 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/utils/extensions/HexByteArrayConversion.kt @@ -0,0 +1,32 @@ +package info.nightscout.androidaps.utils.extensions + +private val HEX_CHARS = "0123456789ABCDEF".toCharArray() + +fun ByteArray.toHex() : String{ + val result = StringBuffer() + + forEach { + val octet = it.toInt() + val firstIndex = (octet and 0xF0).ushr(4) + val secondIndex = octet and 0x0F + result.append(HEX_CHARS[firstIndex]) + result.append(HEX_CHARS[secondIndex]) + } + + return result.toString() +} + +fun String.hexStringToByteArray() : ByteArray { + + val result = ByteArray(length / 2) + + for (i in 0 until length step 2) { + val firstIndex = HEX_CHARS.indexOf(this[i]); + val secondIndex = HEX_CHARS.indexOf(this[i + 1]); + + val octet = firstIndex.shl(4).or(secondIndex) + result.set(i.shr(1), octet.toByte()) + } + + return result +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/DefaultEditTextValidator.kt b/app/src/main/java/info/nightscout/androidaps/utils/textValidator/DefaultEditTextValidator.kt index 4c15100edd..21146a9a72 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/DefaultEditTextValidator.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/textValidator/DefaultEditTextValidator.kt @@ -15,6 +15,9 @@ class DefaultEditTextValidator : EditTextValidator { protected var testErrorString: String? = null protected var emptyAllowed = false protected lateinit var editTextView: EditText + private var tw: TextWatcher? = null + private var defaultEmptyErrorString: String? = null + protected var testType: Int protected var classType: String? = null protected var customRegexp: String? = null @@ -26,8 +29,6 @@ class DefaultEditTextValidator : EditTextValidator { protected var maxNumber = 0 protected var floatminNumber = 0f protected var floatmaxNumber = 0f - private var tw: TextWatcher? = null - private var defaultEmptyErrorString: String? = null @Suppress("unused") constructor(editTextView: EditText, context: Context) { @@ -167,44 +168,50 @@ class DefaultEditTextValidator : EditTextValidator { } @Suppress("unused") - fun setClassType(classType: String?, testErrorString: String?, context: Context) { + fun setClassType(classType: String?, testErrorString: String?, context: Context) : DefaultEditTextValidator{ testType = EditTextValidator.TEST_CUSTOM this.classType = classType this.testErrorString = testErrorString resetValidators(context) + return this } @Suppress("unused") - fun setCustomRegexp(customRegexp: String?, context: Context) { + fun setCustomRegexp(customRegexp: String?, context: Context) : DefaultEditTextValidator { testType = EditTextValidator.TEST_REGEXP this.customRegexp = customRegexp resetValidators(context) + return this } @Suppress("unused") - fun setEmptyAllowed(emptyAllowed: Boolean, context: Context) { + fun setEmptyAllowed(emptyAllowed: Boolean, context: Context) : DefaultEditTextValidator { this.emptyAllowed = emptyAllowed resetValidators(context) + return this } - fun setEmptyErrorString(emptyErrorString: String?) { + fun setEmptyErrorString(emptyErrorString: String?) : DefaultEditTextValidator { emptyErrorStringActual = if (!TextUtils.isEmpty(emptyErrorString)) { emptyErrorString } else { defaultEmptyErrorString } + return this } @Suppress("unused") - fun setTestErrorString(testErrorString: String?, context: Context) { + fun setTestErrorString(testErrorString: String?, context: Context) : DefaultEditTextValidator { this.testErrorString = testErrorString resetValidators(context) + return this } @Suppress("unused") - fun setTestType(testType: Int, context: Context) { + fun setTestType(testType: Int, context: Context) : DefaultEditTextValidator { this.testType = testType resetValidators(context) + return this } override fun testValidity(): Boolean { diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/ValidatingEditTextPreference.kt b/app/src/main/java/info/nightscout/androidaps/utils/textValidator/ValidatingEditTextPreference.kt index 190a3bea73..0d605c17e8 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/ValidatingEditTextPreference.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/textValidator/ValidatingEditTextPreference.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.utils.textValidator +import android.annotation.SuppressLint import android.content.Context import android.util.AttributeSet import androidx.core.content.res.TypedArrayUtils @@ -22,7 +23,7 @@ class ValidatingEditTextPreference(ctx: Context, attrs: AttributeSet, defStyleAt constructor(ctx: Context, attrs: AttributeSet, defStyle: Int) : this(ctx, attrs, defStyle, 0) - constructor(ctx: Context, attrs: AttributeSet) + @SuppressLint("RestrictedApi") constructor(ctx: Context, attrs: AttributeSet) : this(ctx, attrs, TypedArrayUtils.getAttr(ctx, R.attr.editTextPreferenceStyle, R.attr.editTextPreferenceStyle)) diff --git a/app/src/main/res/layout/danars_enter_pin_activity.xml b/app/src/main/res/layout/danars_enter_pin_activity.xml new file mode 100644 index 0000000000..0a232b6cc1 --- /dev/null +++ b/app/src/main/res/layout/danars_enter_pin_activity.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0c6bcfbe4d..3ac901f44f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -417,6 +417,7 @@ Open Settings on Wear Pump Error Low Battery + Delivering less than preset basal rate Pump Shutdown Pump Battery Discharged DanaR Korean @@ -731,12 +732,16 @@ Pairing timed out Pairing danars_pairing_key_ + danars_v3_randompairing_key_ + danars_v3_pairing_key_ + danars_v3_randomsync_key_ danars_address danars_name No device found so far Empty reservoir Blood sugar measurement alert Remaining insulin level + Missed bolus DanaRS Dana Selected pump @@ -1736,4 +1741,11 @@ On each follower phone install Authenticator app that support RFC 6238 TOTP tokens. Popular free apps are:\n • Authy\n • Google Authenticator\n • LastPass Authenticator\n • FreeOTP Authenticator DO NOT SHARE this code online!\nUse it only to setup Authenticator App on follower phones. By reseting authenticator you make all already provisioned authenticators invalid. You will need to set up them again! + PIN1 + PIN2 + Press OK on the pump\nand enter 2 displayed numbers\nKeep display on pump ON by pressing minus button until you finish entering code. + 1: (12 digits) + 2: (8 digits) + Reset pairing information? + Invalid pairing information. Requesting new pairing diff --git a/app/src/main/res/values/validator.xml b/app/src/main/res/values/validator.xml index 15c40b743c..aef7116a48 100644 --- a/app/src/main/res/values/validator.xml +++ b/app/src/main/res/values/validator.xml @@ -16,9 +16,13 @@ Format not valid Must be 4 digit number Must be 6 digit number + Must be 12 characters of ABCDEF0123456789 + Must be 8 characters of ABCDEF0123456789 Not a minimum length Pin should be 3 to 6 digits, not same or in series ^\\d{4} + ^[A-F0-9]{12}$ + ^[A-F0-9]{8}$ \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_AlarmTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_AlarmTest.kt index 8aba3da2ba..58e0b738db 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_AlarmTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_AlarmTest.kt @@ -14,7 +14,7 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_Notify_AlarmTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_Notify_Alarm(aapsLogger, resourceHelper) + val packet = DanaRS_Packet_Notify_Alarm(aapsLogger, resourceHelper, rxBus) // test params Assert.assertEquals(null, packet.requestParams) // test message decoding From 75cd9bccdcef9aa5bcb5c1f66a8817f5c29886e3 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 27 Mar 2020 21:48:42 +0100 Subject: [PATCH 05/53] switch pumps properly --- .../plugins/pump/danaR/AbstractDanaRPlugin.java | 4 +++- .../androidaps/plugins/pump/danaR/DanaRFragment.kt | 2 +- .../androidaps/plugins/pump/danaRS/DanaRSPlugin.java | 8 +++++--- .../androidaps/plugins/pump/danaRS/services/BLEComm.kt | 6 +++++- .../java/info/nightscout/androidaps/queue/CommandQueue.kt | 2 ++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java index 6de5376b89..1982a0e7be 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java @@ -103,8 +103,10 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump .toObservable(EventPreferenceChange.class) .observeOn(Schedulers.io()) .subscribe(event -> { - if (event.isChanged(getResourceHelper(), R.string.key_danar_bt_name)) + if (event.isChanged(getResourceHelper(), R.string.key_danar_bt_name)) { danaRPump.setLastConnection(0); + danaRPump.setLastSettingsRead(0); + getCommandQueue().readStatus("DeviceChanged", null); } }) ); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt index e9e001ced0..7f9eb34c7f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt @@ -171,7 +171,7 @@ class DanaRFragment : DaggerFragment() { // GUI functions @Synchronized - internal fun updateGUI() { + fun updateGUI() { if (danar_dailyunits == null) return val pump = danaRPump val plugin: PumpInterface = activePlugin.activePump diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java index 759b473d75..7dcc0c29ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java @@ -166,9 +166,9 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR disposable.add(rxBus .toObservable(EventDanaRSDeviceChange.class) .observeOn(Schedulers.io()) - .subscribe(event -> loadAddress(), fabricPrivacy::logException) + .subscribe(event -> changePump(), fabricPrivacy::logException) ); - loadAddress(); // load device name + changePump(); // load device name super.onStart(); } @@ -194,10 +194,12 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR } }; - private void loadAddress() { + public void changePump() { mDeviceAddress = sp.getString(R.string.key_danars_address, ""); mDeviceName = sp.getString(R.string.key_danars_name, ""); danaRPump.setLastConnection(0); + danaRPump.setLastSettingsRead(0); + getCommandQueue().readStatus("DeviceChanged", null); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt index 1e6a5f1642..2f537e7d87 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt @@ -96,6 +96,9 @@ class BLEComm @Inject internal constructor( return false } + isConnected = false + v3Encryption = false + encryptedDataRead = false isConnecting = true val device = bluetoothAdapter?.getRemoteDevice(address) if (device == null) { @@ -118,13 +121,14 @@ class BLEComm @Inject internal constructor( fun disconnect(from: String) { aapsLogger.debug(LTag.PUMPBTCOMM, "disconnect from: $from") - if (!encryptedDataRead) { + if (!encryptedDataRead && v3Encryption) { // there was no response from pump after started encryption // assume pairing keys are invalid sp.remove(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName) sp.remove(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName) sp.remove(resourceHelper.gs(R.string.key_danars_v3_randomsynckey) + danaRSPlugin.mDeviceName) ToastUtils.showToastInUiThread(context, R.string.invalidpairing) + danaRSPlugin.changePump() } // cancel previous scheduled disconnection to prevent closing upcoming connection scheduledDisconnection?.cancel(false) diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt index fd93f772aa..20a11124d4 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt @@ -374,12 +374,14 @@ class CommandQueue @Inject constructor( callback?.result(PumpEnactResult(injector).success(true).enacted(false))?.run() return false } + /* this is breaking setting of profile at all if not engineering mode if (!buildHelper.isEngineeringModeOrRelease()) { val notification = Notification(Notification.NOT_ENG_MODE_OR_RELEASE, resourceHelper.gs(R.string.not_eng_mode_or_release), Notification.URGENT) rxBus.send(EventNewNotification(notification)) callback?.result(PumpEnactResult(injector).success(false).enacted(false).comment(resourceHelper.gs(R.string.not_eng_mode_or_release)))?.run() return false } + */ // Compare with pump limits val basalValues = profile.basalValues for (basalValue in basalValues) { From 5e50ca8793d45c986201315297c37b19f54449d1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 28 Mar 2020 20:55:28 +0100 Subject: [PATCH 06/53] Improved switching between Dana pumps, code cleanup --- .../pump/danaR/AbstractDanaRPlugin.java | 8 +- .../plugins/pump/danaR/DanaRFragment.kt | 6 +- .../plugins/pump/danaR/DanaRPump.kt | 26 +- .../plugins/pump/danaR/comm/MsgCheckValue.kt | 6 +- .../danaR/services/DanaRExecutionService.java | 3 +- .../pump/danaRKorean/comm/MsgCheckValue_k.kt | 6 +- .../services/DanaRKoreanExecutionService.java | 3 +- .../plugins/pump/danaRS/DanaRSPlugin.java | 5 +- .../danaRS/comm/DanaRSMessageHashTable.kt | 3 + .../DanaRS_Packet_General_Get_Pump_Check.kt | 6 +- ...aRS_Packet_General_Get_Shipping_Version.kt | 28 + ...cket_General_Initial_Screen_Information.kt | 10 +- ...DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt | 27 + .../pump/danaRS/encryption/BleEncryption.java | 4 + .../plugins/pump/danaRS/services/BLEComm.kt | 494 ++++++++++-------- .../pump/danaRS/services/DanaRSService.java | 4 +- .../pump/danaRv2/comm/MsgCheckValue_v2.kt | 10 +- .../services/DanaRv2ExecutionService.java | 5 +- .../interfaces/ConstraintsCheckerTest.kt | 2 +- .../pump/danaR/comm/MsgCheckValueTest.kt | 2 +- .../plugins/pump/danaRS/DanaRSPluginTest.kt | 3 +- ...S_Packet_Bolus_Set_Step_Bolus_StartTest.kt | 3 +- ...Packet_General_Get_Shipping_VerisonTest.kt | 20 + ...Packet_Notify_Delivery_Rate_DisplayTest.kt | 3 +- ...RS_Packet_Review_Get_Pump_Dec_RatioTest.kt | 22 + .../pump/danaRv2/comm/MsgCheckValue_v2Test.kt | 2 +- 26 files changed, 434 insertions(+), 277 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Version.kt create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_VerisonTest.kt create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_RatioTest.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java index 1982a0e7be..cb8740bbcf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java @@ -97,16 +97,16 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump disposable.add(rxBus .toObservable(EventConfigBuilderChange.class) .observeOn(Schedulers.io()) - .subscribe(event -> danaRPump.setLastConnection(0)) + .subscribe(event -> danaRPump.reset()) ); disposable.add(rxBus .toObservable(EventPreferenceChange.class) .observeOn(Schedulers.io()) .subscribe(event -> { if (event.isChanged(getResourceHelper(), R.string.key_danar_bt_name)) { - danaRPump.setLastConnection(0); - danaRPump.setLastSettingsRead(0); - getCommandQueue().readStatus("DeviceChanged", null); } + danaRPump.reset(); + getCommandQueue().readStatus("DeviceChanged", null); + } }) ); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt index 7f9eb34c7f..6cace72c5f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt @@ -210,8 +210,8 @@ class DanaRFragment : DaggerFragment() { danar_battery.text = "{fa-battery-" + pump.batteryRemaining / 25 + "}" SetWarnColor.setColorInverse(danar_battery, pump.batteryRemaining.toDouble(), 51.0, 26.0) danar_iob.text = resourceHelper.gs(R.string.formatinsulinunits, pump.iob) - if (pump.model != 0 || pump.protocol != 0 || pump.productCode != 0) { - danar_firmware.text = resourceHelper.gs(R.string.danar_model, pump.model, pump.protocol, pump.productCode) + if (pump.btModel != 0 || pump.protocol != 0 || pump.productCode != 0) { + danar_firmware.text = resourceHelper.gs(R.string.danar_model, pump.btModel, pump.protocol, pump.productCode) } else { @Suppress("SetTextI18n") danar_firmware.text = "OLD" @@ -229,7 +229,7 @@ class DanaRFragment : DaggerFragment() { //hide user options button if not an RS pump or old firmware // also excludes pump with model 03 because of untested error val isKorean = danaRKoreanPlugin.isEnabled(PluginType.PUMP) - if (isKorean || danar_firmware.text === "OLD" || pump.model == 3) { + if (isKorean || danar_firmware.text === "OLD" || pump.btModel == 3) { danar_user_options.visibility = View.GONE } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt index 0621fd80ad..eb5bb627fc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt @@ -26,6 +26,20 @@ class DanaRPump @Inject constructor( private val injector: HasAndroidInjector ) { + enum class ErrorState(val code: Int) { + NONE(0x00), + SUSPENDED(0x01), + DAILYMAX(0x02), + BOLUSBLOCK(0x04), + ORDERDELIVERING(0x08), + NOPRIME(0x10); + + companion object { + private val map = values().associateBy(ErrorState::code) + operator fun get(value: Int) = map[value] + } + } + var lastConnection: Long = 0 var lastSettingsRead: Long = 0 @@ -33,12 +47,14 @@ class DanaRPump @Inject constructor( var serialNumber = "" var shippingDate: Long = 0 var shippingCountry = "" - var isNewPump = true - var password = -1 + var bleModel = "" // RS v3: like BPN-1.0.1 + var isNewPump = true // R only , providing model info + var password = -1 // R, RSv1 var pumpTime: Long = 0 - var model = 0 + var btModel = 0 var protocol = 0 var productCode = 0 + var errorState: ErrorState = ErrorState.NONE var isConfigUD = false var isExtendedBolusEnabled = false var isEasyModeEnabled = false @@ -49,6 +65,7 @@ class DanaRPump @Inject constructor( var dailyTotalUnits = 0.0 var dailyTotalBolusUnits = 0.0 // RS only var dailyTotalBasalUnits = 0.0 // RS only + var decRatio = 0 // RS v3: [%] for pump IOB calculation var maxDailyTotalUnits = 0 var bolusStep = 0.1 var basalStep = 0.1 @@ -207,6 +224,7 @@ class DanaRPump @Inject constructor( fun reset() { aapsLogger.debug(LTag.PUMP, "DanaRPump reset") lastConnection = 0 + lastSettingsRead = 0 } companion object { @@ -234,6 +252,8 @@ class DanaRPump @Inject constructor( const val PROFILECHANGE = 13 const val CARBS = 14 const val PRIMECANNULA = 15 + + // Dana R btModel const val DOMESTIC_MODEL = 0x01 const val EXPORT_MODEL = 0x03 } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValue.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValue.kt index abb6c34d8d..3cc8701a38 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValue.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValue.kt @@ -19,14 +19,14 @@ class MsgCheckValue( override fun handleMessage(bytes: ByteArray) { danaRPump.isNewPump = true aapsLogger.debug(LTag.PUMPCOMM, "New firmware confirmed") - danaRPump.model = intFromBuff(bytes, 0, 1) + danaRPump.btModel = intFromBuff(bytes, 0, 1) danaRPump.protocol = intFromBuff(bytes, 1, 1) danaRPump.productCode = intFromBuff(bytes, 2, 1) - if (danaRPump.model != DanaRPump.EXPORT_MODEL) { + if (danaRPump.btModel != DanaRPump.EXPORT_MODEL) { danaRPlugin.disconnect("Wrong Model") aapsLogger.debug(LTag.PUMPCOMM, "Wrong model selected") } - aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.model)) + aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.btModel)) aapsLogger.debug(LTag.PUMPCOMM, "Protocol: " + String.format("%02X ", danaRPump.protocol)) aapsLogger.debug(LTag.PUMPCOMM, "Product Code: " + String.format("%02X ", danaRPump.productCode)) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java index b71ed5abea..4178bd3d57 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java @@ -225,8 +225,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { if (danaRPump.getPumpTime() == 0) { // initial handshake was not successfull // deinitialize pump - danaRPump.setLastConnection(0); - danaRPump.setLastSettingsRead(0); + danaRPump.reset(); rxBus.send(new EventDanaRNewStatus()); rxBus.send(new EventInitializationChanged()); return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgCheckValue_k.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgCheckValue_k.kt index 16ae6967a2..412d13cf3d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgCheckValue_k.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgCheckValue_k.kt @@ -21,14 +21,14 @@ class MsgCheckValue_k( override fun handleMessage(bytes: ByteArray) { danaRPump.isNewPump = true aapsLogger.debug(LTag.PUMPCOMM, "New firmware confirmed") - danaRPump.model = intFromBuff(bytes, 0, 1) + danaRPump.btModel = intFromBuff(bytes, 0, 1) danaRPump.protocol = intFromBuff(bytes, 1, 1) danaRPump.productCode = intFromBuff(bytes, 2, 1) - if (danaRPump.model != DanaRPump.DOMESTIC_MODEL) { + if (danaRPump.btModel != DanaRPump.DOMESTIC_MODEL) { danaRKoreanPlugin.disconnect("Wrong Model") aapsLogger.debug(LTag.PUMPCOMM, "Wrong model selected") } - aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.model)) + aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.btModel)) aapsLogger.debug(LTag.PUMPCOMM, "Protocol: " + String.format("%02X ", danaRPump.protocol)) aapsLogger.debug(LTag.PUMPCOMM, "Product Code: " + String.format("%02X ", danaRPump.productCode)) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java index f695448820..d40583e9db 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java @@ -212,8 +212,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { if (danaRPump.getPumpTime() == 0) { // initial handshake was not successfull // deinitialize pump - danaRPump.setLastConnection(0); - danaRPump.setLastSettingsRead(0); + danaRPump.reset(); rxBus.send(new EventDanaRNewStatus()); rxBus.send(new EventInitializationChanged()); return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java index 7dcc0c29ff..35f1e81a21 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java @@ -161,7 +161,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR disposable.add(rxBus .toObservable(EventConfigBuilderChange.class) .observeOn(Schedulers.io()) - .subscribe(event -> danaRPump.setLastConnection(0)) + .subscribe(event -> danaRPump.reset()) ); disposable.add(rxBus .toObservable(EventDanaRSDeviceChange.class) @@ -197,8 +197,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR public void changePump() { mDeviceAddress = sp.getString(R.string.key_danars_address, ""); mDeviceName = sp.getString(R.string.key_danars_name, ""); - danaRPump.setLastConnection(0); - danaRPump.setLastSettingsRead(0); + danaRPump.reset(); getCommandQueue().readStatus("DeviceChanged", null); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt index 224ecd9ae5..2f3b8b170a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt @@ -101,5 +101,8 @@ class DanaRSMessageHashTable @Inject constructor( put(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, 0)) put(DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, detailedBolusInfoStorage, 0)) put(DanaRS_Packet_APS_Set_Event_History(aapsLogger, 0, 0, 0, 0)) + // v3 + put(DanaRS_Packet_General_Get_Shipping_Version(aapsLogger, danaRPump)) + put(DanaRS_Packet_Review_Get_Pump_Dec_Ratio(aapsLogger, danaRPump)) } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt index bf3338b52f..5646c6f370 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt @@ -1,6 +1,5 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -8,6 +7,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.resources.ResourceHelper class DanaRS_Packet_General_Get_Pump_Check( @@ -30,14 +30,14 @@ class DanaRS_Packet_General_Get_Pump_Check( failed = false var dataIndex = DATA_START var dataSize = 1 - danaRPump.model = byteArrayToInt(getBytes(data, dataIndex, dataSize)) + danaRPump.btModel = byteArrayToInt(getBytes(data, dataIndex, dataSize)) dataIndex += dataSize dataSize = 1 danaRPump.protocol = byteArrayToInt(getBytes(data, dataIndex, dataSize)) dataIndex += dataSize dataSize = 1 danaRPump.productCode = byteArrayToInt(getBytes(data, dataIndex, dataSize)) - aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.model)) + aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.btModel)) aapsLogger.debug(LTag.PUMPCOMM, "Protocol: " + String.format("%02X ", danaRPump.protocol)) aapsLogger.debug(LTag.PUMPCOMM, "Product Code: " + String.format("%02X ", danaRPump.productCode)) if (danaRPump.productCode < 2) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Version.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Version.kt new file mode 100644 index 0000000000..9d3d83fbf4 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Version.kt @@ -0,0 +1,28 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.comm + +import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import java.nio.charset.Charset + +class DanaRS_Packet_General_Get_Shipping_Version( + private val aapsLogger: AAPSLogger, + private val danaRPump: DanaRPump +) : DanaRS_Packet() { + + init { + opCode = BleEncryption.DANAR_PACKET__OPCODE_GENERAL__GET_SHIPPING_VERSION + aapsLogger.debug(LTag.PUMPCOMM, "New message") + } + + override fun handleMessage(data: ByteArray) { + danaRPump.bleModel = data.copyOfRange(DATA_START, data.size).toString(Charset.forName("US-ASCII")) + failed = false + aapsLogger.debug(LTag.PUMPCOMM, "BLE Model: " + danaRPump.bleModel) + } + + override fun getFriendlyName(): String { + return "GENERAL__GET_SHIPPING_VERSION" + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt index 03471e7408..0510c28271 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt @@ -1,9 +1,9 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_General_Initial_Screen_Information( private val aapsLogger: AAPSLogger, @@ -51,6 +51,14 @@ class DanaRS_Packet_General_Initial_Screen_Information( dataIndex += dataSize dataSize = 2 danaRPump.iob = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0 + if (data.size >= 18) { + //protocol 10+ + dataIndex += dataSize + dataSize = 1 + danaRPump.errorState = DanaRPump.ErrorState[byteArrayToInt(getBytes(data, dataIndex, dataSize))] + ?: DanaRPump.ErrorState.NONE + aapsLogger.debug(LTag.PUMPCOMM, "ErrorState: " + danaRPump.errorState.name) + } aapsLogger.debug(LTag.PUMPCOMM, "Pump suspended: " + danaRPump.pumpSuspended) aapsLogger.debug(LTag.PUMPCOMM, "Temp basal in progress: " + danaRPump.isTempBasalInProgress) aapsLogger.debug(LTag.PUMPCOMM, "Extended in progress: " + danaRPump.isExtendedInProgress) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt new file mode 100644 index 0000000000..23d903de0b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt @@ -0,0 +1,27 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.comm + +import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption + +class DanaRS_Packet_Review_Get_Pump_Dec_Ratio( + private val aapsLogger: AAPSLogger, + private val danaRPump: DanaRPump +) : DanaRS_Packet() { + + init { + opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__GET_PUMP_DEC_RATIO + aapsLogger.debug(LTag.PUMPCOMM, "New message") + } + + override fun handleMessage(data: ByteArray) { + danaRPump.decRatio = intFromBuff(data, 0, 1) * 5 + failed = false + aapsLogger.debug(LTag.PUMPCOMM, "Dec ratio: ${danaRPump.decRatio}%") + } + + override fun getFriendlyName(): String { + return "REVIEW__GET_PUMP_DEC_RATIO" + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java index b4fea5d8be..425a5a87a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java @@ -97,6 +97,10 @@ public class BleEncryption { public static final int DANAR_PACKET__OPCODE__APS_HISTORY_EVENTS = 0xC2; public static final int DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY = 0xC3; + // v3 specific + public static final int DANAR_PACKET__OPCODE_REVIEW__GET_PUMP_DEC_RATIO = 0x80; + public static final int DANAR_PACKET__OPCODE_GENERAL__GET_SHIPPING_VERSION = 0x81; + // Easy Mode public static final int DANAR_PACKET__OPCODE_OPTION__GET_EASY_MENU_OPTION = 0x74; public static final int DANAR_PACKET__OPCODE_OPTION__SET_EASY_MENU_OPTION = 0x75; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt index 2f537e7d87..9145cb6559 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt @@ -162,7 +162,7 @@ class BLEComm @Inject internal constructor( if (status == BluetoothGatt.GATT_SUCCESS) { findCharacteristic() } - sendPumpCheck() + sendConnect() // 1st message sent to pump after connect } @@ -295,7 +295,7 @@ class BLEComm @Inject internal constructor( } } - private fun readDataParsing(receviedData: ByteArray) { + private fun readDataParsing(receivedData: ByteArray) { //aapsLogger.debug(LTag.PUMPBTCOMM, "readDataParsing") var startSignatureFound = false var packetIsValid = false @@ -305,8 +305,8 @@ class BLEComm @Inject internal constructor( // decrypt 2nd level after successful connection val incomingBuffer = if (v3Encryption && isConnected) - bleEncryption.decryptSecondLevelPacket(receviedData).also { encryptedDataRead = true } - else receviedData + bleEncryption.decryptSecondLevelPacket(receivedData).also { encryptedDataRead = true } + else receivedData addToReadBuffer(incomingBuffer) while (isProcessing) { @@ -356,196 +356,42 @@ class BLEComm @Inject internal constructor( } } if (packetIsValid) { - try { - // decrypt the packet - bleEncryption.getDecryptedPacket(inputBuffer)?.let { decryptedBuffer -> - when (decryptedBuffer[0]) { - BleEncryption.DANAR_PACKET__TYPE_ENCRYPTION_RESPONSE.toByte() -> - when (decryptedBuffer[1]) { - BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK.toByte() -> - if (decryptedBuffer.size == 4 && decryptedBuffer[2] == 'O'.toByte() && decryptedBuffer[3] == 'K'.toByte()) { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (OK)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) - v3Encryption = false - // Grab pairing key from preferences if exists - val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName, "") - aapsLogger.debug(LTag.PUMPBTCOMM, "Using stored pairing key: $pairingKey") - if (pairingKey.isNotEmpty()) { - val encodedPairingKey = DanaRS_Packet.hexToBytes(pairingKey) - val bytes = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY, encodedPairingKey, null) - aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__CHECK_PASSKEY" + " " + DanaRS_Packet.toHexString(bytes)) - writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) - } else { - // Stored pairing key does not exists, request pairing - sendPairingRequest() - } - } else if (decryptedBuffer.size == 9 && decryptedBuffer[2] == 'O'.toByte() && decryptedBuffer[3] == 'K'.toByte()) { - // v3 2nd layer encryption - v3Encryption = true - val model = decryptedBuffer[5] - // val protocol = decryptedBuffer[7] - if (model == 0x05.toByte()) { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK V3 (OK)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) - // Dana RS Pump - val randomPairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName, "") - val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName, "") - if (randomPairingKey.isNotEmpty() && pairingKey.isNotEmpty()) { - val randomSyncKey = String.format("%02x", decryptedBuffer[decryptedBuffer.size - 1]) - sp.putString(resourceHelper.gs(R.string.key_danars_v3_randomsynckey) + danaRSPlugin.mDeviceName, randomSyncKey) - val tPairingKey = Base64.decode(pairingKey, Base64.DEFAULT) - val tRandomPairingKey = Base64.decode(randomPairingKey, Base64.DEFAULT) - var tRandomSyncKey: Byte = 0 - if (randomSyncKey.isNotEmpty()) { - tRandomSyncKey = randomSyncKey.toInt(16).toByte() - } - bleEncryption.setPairingKeys(tPairingKey, tRandomPairingKey, tRandomSyncKey) - sendV3PairingInformation(0) - } else { - sendV3PairingInformation(1) - } - } else if (model == 0x06.toByte()) { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK V3 EASY (OK)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) - // Dana RS Easy - val bytes: ByteArray = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__GET_EASYMENU_CHECK, null, null) - writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) - } - } else if (decryptedBuffer.size == 6 && decryptedBuffer[2] == 'P'.toByte() && decryptedBuffer[3] == 'U'.toByte() && decryptedBuffer[4] == 'M'.toByte() && decryptedBuffer[5] == 'P'.toByte()) { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (PUMP)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) - mSendQueue.clear() - rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.pumperror))) - NSUpload.uploadError(resourceHelper.gs(R.string.pumperror)) - val n = Notification(Notification.PUMPERROR, resourceHelper.gs(R.string.pumperror), Notification.URGENT) - rxBus.send(EventNewNotification(n)) - } else if (decryptedBuffer.size == 6 && decryptedBuffer[2] == 'B'.toByte() && decryptedBuffer[3] == 'U'.toByte() && decryptedBuffer[4] == 'S'.toByte() && decryptedBuffer[5] == 'Y'.toByte()) { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (BUSY)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) - mSendQueue.clear() - rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.pumpbusy))) - } else { - // ERROR in response, wrong serial number - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (ERROR)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) - mSendQueue.clear() - rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.connectionerror))) - sp.remove(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName) - val n = Notification(Notification.WRONGSERIALNUMBER, resourceHelper.gs(R.string.wrongpassword), Notification.URGENT) - rxBus.send(EventNewNotification(n)) - } + // decrypt the packet + bleEncryption.getDecryptedPacket(inputBuffer)?.let { decryptedBuffer -> + if (decryptedBuffer[0] == BleEncryption.DANAR_PACKET__TYPE_ENCRYPTION_RESPONSE.toByte()) { + when (decryptedBuffer[1]) { + // 1st packet exchange + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK.toByte() -> + processConnectResponse(decryptedBuffer) - BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION.toByte() -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__TIME_INFORMATION " + /*message.getMessageName() + " " + */DanaRS_Packet.toHexString(decryptedBuffer)) - if (v3Encryption) { - // decryptedBuffer[2] : 0x00 OK 0x01 Error, No pairing - if (decryptedBuffer[2] == 0x00.toByte()) { - val randomPairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName, "") - val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName, "") - if (randomPairingKey.isNotEmpty() && pairingKey.isNotEmpty()) { - // expecting successful connect - isConnected = true - isConnecting = false - aapsLogger.debug(LTag.PUMPBTCOMM, "Connect !!") - } else { - context.startActivity(Intent(context, EnterPinActivity::class.java).also { it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) }) - aapsLogger.debug(LTag.PUMPBTCOMM, "Request pairing keys !!") - } - } else { - sendV3PairingInformation(1) - } + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION.toByte() -> + processEncryptionResponse(decryptedBuffer) - } else { - val size = decryptedBuffer.size - var pass: Int = (decryptedBuffer[size - 1].toInt() and 0x000000FF shl 8) + (decryptedBuffer[size - 2].toInt() and 0x000000FF) - pass = pass xor 3463 - danaRPump.rsPassword = Integer.toHexString(pass) - aapsLogger.debug(LTag.PUMPBTCOMM, "Pump user password: " + Integer.toHexString(pass)) - rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED)) - isConnected = true - isConnecting = false - aapsLogger.debug(LTag.PUMPBTCOMM, "RS connected and status read") - } - } + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY.toByte() -> + processPasskeyCheck(decryptedBuffer) - BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY.toByte() -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__CHECK_PASSKEY" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) - if (decryptedBuffer[2] == 0x00.toByte()) { - // Paring is not requested, sending time info - sendTimeInfo() - } else { - // Pairing on pump is requested - sendPairingRequest() - } - } + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_REQUEST.toByte() -> + processPairingRequest(decryptedBuffer) - BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_REQUEST.toByte() -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PASSKEY_REQUEST " + DanaRS_Packet.toHexString(decryptedBuffer)) - if (decryptedBuffer[2] != 0x00.toByte()) { - disconnect("passkey request failed") - } - } + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_RETURN.toByte() -> + processPairingRequest2(decryptedBuffer) - BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_RETURN.toByte() -> { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PASSKEY_RETURN " + DanaRS_Packet.toHexString(decryptedBuffer)) - // Paring is successful, sending time info - rxBus.send(EventDanaRSPairingSuccess()) - sendTimeInfo() - val pairingKey = byteArrayOf(decryptedBuffer[2], decryptedBuffer[3]) - // store pairing key to preferences - sp.putString(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName, DanaRS_Packet.bytesToHex(pairingKey)) - aapsLogger.debug(LTag.PUMPBTCOMM, "Got pairing key: " + DanaRS_Packet.bytesToHex(pairingKey)) - } - - BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__GET_PUMP_CHECK.toByte() -> { - if (decryptedBuffer[2] == 0x05.toByte()) { - // not easy mode, request time info - val bytes: ByteArray = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION, null, null) - writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) - } else { - // easy mode - val bytes: ByteArray = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__GET_EASYMENU_CHECK, null, null) - writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) - } - } - - BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__GET_EASYMENU_CHECK.toByte() -> { - isEasyMode = decryptedBuffer[2] == 0x01.toByte() - isUnitUD = decryptedBuffer[3] == 0x01.toByte() - - // request time information - if (v3Encryption) { - sendV3PairingInformation(1) - } else { - val bytes: ByteArray = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION, null, null) - writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) - } - } - } - - else -> { - // Retrieve message code from received buffer and last message sent - val originalCommand = processedMessage?.command ?: 0xFFFF - val receivedCommand = DanaRS_Packet.getCommand(decryptedBuffer) - val message: DanaRS_Packet? = if (originalCommand == receivedCommand) { - // it's response to last message - processedMessage - } else { - // it's not response to last message, create new instance - danaRSMessageHashTable.findMessage(receivedCommand) - } - if (message != null) { - aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + message.friendlyName + " " + DanaRS_Packet.toHexString(decryptedBuffer)) - // process received data - message.handleMessage(decryptedBuffer) - message.setReceived() - synchronized(message) { - // notify to sendMessage - message.notify() - } - } else { - aapsLogger.error("Unknown message received " + DanaRS_Packet.toHexString(decryptedBuffer)) - } + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__GET_PUMP_CHECK.toByte() -> { + // not easy mode, request time info + if (decryptedBuffer[2] == 0x05.toByte()) sendTimeInfo() + // easy mode + else sendEasyMenuCheck() } + + BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__GET_EASYMENU_CHECK.toByte() -> + processEasyMenuCheck(decryptedBuffer) } - } ?: throw IllegalStateException("Null decryptedInputBuffer") - } catch (e: Exception) { - aapsLogger.error("Unhandled exception", e) - } + + } else { + // Retrieve message code from received buffer and last message sent + processMessage(decryptedBuffer) + } + } ?: throw IllegalStateException("Null decryptedInputBuffer") startSignatureFound = false packetIsValid = false if (bufferLength < 6) { @@ -559,6 +405,216 @@ class BLEComm @Inject internal constructor( } } + // 1st packet v1 v3 message sent to pump after connect + private fun sendConnect() { + val deviceName = connectDeviceName + if (deviceName == null || deviceName == "") { + val n = Notification(Notification.DEVICENOTPAIRED, resourceHelper.gs(R.string.pairfirst), Notification.URGENT) + rxBus.send(EventNewNotification(n)) + return + } + val bytes = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK, null, deviceName) + aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__PUMP_CHECK (0x00)" + " " + DanaRS_Packet.toHexString(bytes)) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } + + // 1st packet response + private fun processConnectResponse(decryptedBuffer: ByteArray) { + // response OK v1 + if (decryptedBuffer.size == 4 && decryptedBuffer[2] == 'O'.toByte() && decryptedBuffer[3] == 'K'.toByte()) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (OK)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + v3Encryption = false + // Grab pairing key from preferences if exists + val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName, "") + aapsLogger.debug(LTag.PUMPBTCOMM, "Using stored pairing key: $pairingKey") + if (pairingKey.isNotEmpty()) { + sendPasskeyCheck(pairingKey) + } else { + // Stored pairing key does not exists, request pairing + sendPairingRequest() + } + // response OK v3 + } else if (decryptedBuffer.size == 9 && decryptedBuffer[2] == 'O'.toByte() && decryptedBuffer[3] == 'K'.toByte()) { + // v3 2nd layer encryption + v3Encryption = true + val model = decryptedBuffer[5] + // val protocol = decryptedBuffer[7] + if (model == 0x05.toByte()) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK V3 (OK)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + // Dana RS Pump + val randomPairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName, "") + val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName, "") + if (randomPairingKey.isNotEmpty() && pairingKey.isNotEmpty()) { + val randomSyncKey = String.format("%02x", decryptedBuffer[decryptedBuffer.size - 1]) + sp.putString(resourceHelper.gs(R.string.key_danars_v3_randomsynckey) + danaRSPlugin.mDeviceName, randomSyncKey) + val tPairingKey = Base64.decode(pairingKey, Base64.DEFAULT) + val tRandomPairingKey = Base64.decode(randomPairingKey, Base64.DEFAULT) + var tRandomSyncKey: Byte = 0 + if (randomSyncKey.isNotEmpty()) { + tRandomSyncKey = randomSyncKey.toInt(16).toByte() + } + bleEncryption.setPairingKeys(tPairingKey, tRandomPairingKey, tRandomSyncKey) + sendV3PairingInformation(0) + } else { + sendV3PairingInformation(1) + } + } else if (model == 0x06.toByte()) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK V3 EASY (OK)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + // Dana RS Easy + val bytes: ByteArray = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__GET_EASYMENU_CHECK, null, null) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } + // response PUMP : error status + } else if (decryptedBuffer.size == 6 && decryptedBuffer[2] == 'P'.toByte() && decryptedBuffer[3] == 'U'.toByte() && decryptedBuffer[4] == 'M'.toByte() && decryptedBuffer[5] == 'P'.toByte()) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (PUMP)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + mSendQueue.clear() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.pumperror))) + NSUpload.uploadError(resourceHelper.gs(R.string.pumperror)) + val n = Notification(Notification.PUMPERROR, resourceHelper.gs(R.string.pumperror), Notification.URGENT) + rxBus.send(EventNewNotification(n)) + // response BUSY: error status + } else if (decryptedBuffer.size == 6 && decryptedBuffer[2] == 'B'.toByte() && decryptedBuffer[3] == 'U'.toByte() && decryptedBuffer[4] == 'S'.toByte() && decryptedBuffer[5] == 'Y'.toByte()) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (BUSY)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + mSendQueue.clear() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.pumpbusy))) + } else { + // ERROR in response, wrong serial number + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (ERROR)" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + mSendQueue.clear() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.connectionerror))) + sp.remove(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName) + val n = Notification(Notification.WRONGSERIALNUMBER, resourceHelper.gs(R.string.wrongpassword), Notification.URGENT) + rxBus.send(EventNewNotification(n)) + } + } + + // 2nd packet v1 check passkey + private fun sendPasskeyCheck(pairingKey: String) { + val encodedPairingKey = DanaRS_Packet.hexToBytes(pairingKey) + val bytes = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY, encodedPairingKey, null) + aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__CHECK_PASSKEY" + " " + DanaRS_Packet.toHexString(bytes)) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } + + // 2nd packet v1 response + private fun processPasskeyCheck(decryptedBuffer: ByteArray) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__CHECK_PASSKEY" + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + // Paring is not requested, sending time info + if (decryptedBuffer[2] == 0x00.toByte()) sendTimeInfo() + // Pairing on pump is requested + else sendPairingRequest() + } + + // 2nd packet v3 + // 0x00 Start encryption, 0x01 Request pairing + private fun sendV3PairingInformation(requestNewPairing: Int) { + val params = byteArrayOf(requestNewPairing.toByte()) + val bytes: ByteArray = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION, params, null) + aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__TIME_INFORMATION" + " " + DanaRS_Packet.toHexString(bytes)) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } + + // 2nd packet response + private fun processEncryptionResponse(decryptedBuffer: ByteArray) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__TIME_INFORMATION " + /*message.getMessageName() + " " + */DanaRS_Packet.toHexString(decryptedBuffer)) + if (v3Encryption) { + // decryptedBuffer[2] : 0x00 OK 0x01 Error, No pairing + if (decryptedBuffer[2] == 0x00.toByte()) { + val randomPairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName, "") + val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName, "") + if (randomPairingKey.isNotEmpty() && pairingKey.isNotEmpty()) { + // expecting successful connect + isConnected = true + isConnecting = false + aapsLogger.debug(LTag.PUMPBTCOMM, "Connect !!") + } else { + context.startActivity(Intent(context, EnterPinActivity::class.java).also { it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) }) + aapsLogger.debug(LTag.PUMPBTCOMM, "Request pairing keys !!") + } + } else { + sendV3PairingInformation(1) + } + + } else { + val size = decryptedBuffer.size + var pass: Int = (decryptedBuffer[size - 1].toInt() and 0x000000FF shl 8) + (decryptedBuffer[size - 2].toInt() and 0x000000FF) + pass = pass xor 3463 + danaRPump.rsPassword = Integer.toHexString(pass) + aapsLogger.debug(LTag.PUMPBTCOMM, "Pump user password: " + Integer.toHexString(pass)) + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED)) + isConnected = true + isConnecting = false + aapsLogger.debug(LTag.PUMPBTCOMM, "RS connected and status read") + } + } + + // 3rd packet v1 existing pairing + private fun sendTimeInfo() { + val bytes = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION, null, null) + aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__TIME_INFORMATION" + " " + DanaRS_Packet.toHexString(bytes)) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } + + //2nd or 3rd packet v1 pairing doesn't exist + private fun sendPairingRequest() { + // Start activity which is waiting 20sec + // On pump pairing request is displayed and is waiting for conformation + context.startActivity(Intent(context, PairingHelperActivity::class.java).also { it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) }) + val bytes = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_REQUEST, null, null) + aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__PASSKEY_REQUEST" + " " + DanaRS_Packet.toHexString(bytes)) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } + + // 3rd packet v3 : only after entering PIN codes + fun finishV3Pairing() { + val randomPairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName, "") + val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName, "") + if (randomPairingKey.isNotEmpty() && pairingKey.isNotEmpty()) { + val tPairingKey = Base64.decode(pairingKey, Base64.DEFAULT) + val tRandomPairingKey = Base64.decode(randomPairingKey, Base64.DEFAULT) + val tRandomSyncKey: Byte = 0 + bleEncryption.setPairingKeys(tPairingKey, tRandomPairingKey, tRandomSyncKey) + sendV3PairingInformation(0) + } else throw java.lang.IllegalStateException("This should not be reached") + } + + // 2nd or 3rd packet v1 response + private fun processPairingRequest(decryptedBuffer: ByteArray) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PASSKEY_REQUEST " + DanaRS_Packet.toHexString(decryptedBuffer)) + if (decryptedBuffer[2] != 0x00.toByte()) { + disconnect("passkey request failed") + } + } + + // 2nd or 3rd packet v1 response + private fun processPairingRequest2(decryptedBuffer: ByteArray) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PASSKEY_RETURN " + DanaRS_Packet.toHexString(decryptedBuffer)) + // Paring is successful, sending time info + rxBus.send(EventDanaRSPairingSuccess()) + sendTimeInfo() + val pairingKey = byteArrayOf(decryptedBuffer[2], decryptedBuffer[3]) + // store pairing key to preferences + sp.putString(resourceHelper.gs(R.string.key_danars_pairingkey) + danaRSPlugin.mDeviceName, DanaRS_Packet.bytesToHex(pairingKey)) + aapsLogger.debug(LTag.PUMPBTCOMM, "Got pairing key: " + DanaRS_Packet.bytesToHex(pairingKey)) + } + + // 3rd packet Easy menu pump + private fun sendEasyMenuCheck() { + val bytes: ByteArray = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__GET_EASYMENU_CHECK, null, null) + writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) + } + + // 3rd packet Easy menu response + private fun processEasyMenuCheck(decryptedBuffer: ByteArray) { + isEasyMode = decryptedBuffer[2] == 0x01.toByte() + isUnitUD = decryptedBuffer[3] == 0x01.toByte() + + // request time information + if (v3Encryption) sendV3PairingInformation(1) + else sendTimeInfo() + } + + // the rest of packets fun sendMessage(message: DanaRS_Packet?) { processedMessage = message if (message == null) return @@ -628,51 +684,27 @@ class BLEComm @Inject internal constructor( } } - fun finishV3Pairing() { - val randomPairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName, "") - val pairingKey = sp.getString(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName, "") - if (randomPairingKey.isNotEmpty() && pairingKey.isNotEmpty()) { - val tPairingKey = Base64.decode(pairingKey, Base64.DEFAULT) - val tRandomPairingKey = Base64.decode(randomPairingKey, Base64.DEFAULT) - val tRandomSyncKey: Byte = 0 - bleEncryption.setPairingKeys(tPairingKey, tRandomPairingKey, tRandomSyncKey) - sendV3PairingInformation(0) + // process common packet response + private fun processMessage(decryptedBuffer: ByteArray) { + val originalCommand = processedMessage?.command ?: 0xFFFF + val receivedCommand = DanaRS_Packet.getCommand(decryptedBuffer) + val message: DanaRS_Packet? = if (originalCommand == receivedCommand) { + // it's response to last message + processedMessage + } else { + // it's not response to last message, create new instance + danaRSMessageHashTable.findMessage(receivedCommand) } + if (message != null) { + aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + message.friendlyName + " " + DanaRS_Packet.toHexString(decryptedBuffer)) + // process received data + message.handleMessage(decryptedBuffer) + message.setReceived() + synchronized(message) { + // notify to sendMessage + message.notify() + } + } else aapsLogger.error("Unknown message received " + DanaRS_Packet.toHexString(decryptedBuffer)) } - // 0x00 Start encryption, 0x01 Request pairing - private fun sendV3PairingInformation(requestNewPairing: Int) { - val params = byteArrayOf(requestNewPairing.toByte()) - val bytes: ByteArray = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION, params, null) - aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__TIME_INFORMATION" + " " + DanaRS_Packet.toHexString(bytes)) - writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) - } - - private fun sendPairingRequest() { - // Start activity which is waiting 20sec - // On pump pairing request is displayed and is waiting for conformation - context.startActivity(Intent(context, PairingHelperActivity::class.java).also { it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) }) - val bytes = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_REQUEST, null, null) - aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__PASSKEY_REQUEST" + " " + DanaRS_Packet.toHexString(bytes)) - writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) - } - - private fun sendPumpCheck() { - // 1st message sent to pump after connect - val deviceName = connectDeviceName - if (deviceName == null || deviceName == "") { - val n = Notification(Notification.DEVICENOTPAIRED, resourceHelper.gs(R.string.pairfirst), Notification.URGENT) - rxBus.send(EventNewNotification(n)) - return - } - val bytes = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK, null, deviceName) - aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__PUMP_CHECK (0x00)" + " " + DanaRS_Packet.toHexString(bytes)) - writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) - } - - private fun sendTimeInfo() { - val bytes = bleEncryption.getEncryptedPacket(BleEncryption.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION, null, null) - aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + "ENCRYPTION__TIME_INFORMATION" + " " + DanaRS_Packet.toHexString(bytes)) - writeCharacteristicNoResponse(uartWriteBTGattChar, bytes) - } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java index cb6484bafd..4affd0d7c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java @@ -189,7 +189,7 @@ public class DanaRSService extends DaggerService { if (danaRPump.getPumpTime() == 0) { // initial handshake was not successfull // deinitialize pump - danaRPump.setLastConnection(0); + danaRPump.reset(); rxBus.send(new EventDanaRNewStatus()); rxBus.send(new EventInitializationChanged()); return; @@ -221,7 +221,7 @@ public class DanaRSService extends DaggerService { context.startActivity(i); //deinitialize pump - danaRPump.setLastConnection(0); + danaRPump.reset(); rxBus.send(new EventDanaRNewStatus()); rxBus.send(new EventInitializationChanged()); return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.kt index d680490a15..87628c0d1a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.kt @@ -38,11 +38,11 @@ class MsgCheckValue_v2( override fun handleMessage(bytes: ByteArray) { danaRPump.isNewPump = true aapsLogger.debug(LTag.PUMPCOMM, "New firmware confirmed") - danaRPump.model = intFromBuff(bytes, 0, 1) + danaRPump.btModel = intFromBuff(bytes, 0, 1) danaRPump.protocol = intFromBuff(bytes, 1, 1) danaRPump.productCode = intFromBuff(bytes, 2, 1) - if (danaRPump.model != DanaRPump.EXPORT_MODEL) { - danaRPump.lastConnection = 0 + if (danaRPump.btModel != DanaRPump.EXPORT_MODEL) { + danaRPump.reset() val notification = Notification(Notification.WRONG_DRIVER, resourceHelper.gs(R.string.pumpdrivercorrected), Notification.NORMAL) rxBus.send(EventNewNotification(notification)) danaRPlugin.disconnect("Wrong Model") @@ -59,7 +59,7 @@ class MsgCheckValue_v2( return } if (danaRPump.protocol != 2) { - danaRPump.lastConnection = 0 + danaRPump.reset() val notification = Notification(Notification.WRONG_DRIVER, resourceHelper.gs(R.string.pumpdrivercorrected), Notification.NORMAL) rxBus.send(EventNewNotification(notification)) danaRKoreanPlugin.disconnect("Wrong Model") @@ -74,7 +74,7 @@ class MsgCheckValue_v2( commandQueue.readStatus("PumpDriverChange", null) // force new connection return } - aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.model)) + aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.btModel)) aapsLogger.debug(LTag.PUMPCOMM, "Protocol: " + String.format("%02X ", danaRPump.protocol)) aapsLogger.debug(LTag.PUMPCOMM, "Product Code: " + String.format("%02X ", danaRPump.productCode)) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java index 76f3083385..cb45d18bbd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java @@ -230,8 +230,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { if (danaRPump.getPumpTime() == 0) { // initial handshake was not successfull // deinitialize pump - danaRPump.setLastConnection(0); - danaRPump.setLastSettingsRead(0); + danaRPump.reset(); rxBus.send(new EventDanaRNewStatus()); rxBus.send(new EventInitializationChanged()); return; @@ -250,7 +249,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { context.startActivity(i); //deinitialize pump - danaRPump.setLastConnection(0); + danaRPump.reset(); rxBus.send(new EventDanaRNewStatus()); rxBus.send(new EventInitializationChanged()); return; diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt index 763cd748cc..545b8fc119 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt @@ -115,7 +115,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp) comboPlugin = ComboPlugin(injector, aapsLogger, rxBus, resourceHelper, profileFunction, treatmentsPlugin, sp, commandQueue, context) danaRPlugin = DanaRPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, treatmentsPlugin, sp, commandQueue, danaRPump) - danaRSPlugin = DanaRSPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage) + danaRSPlugin = DanaRSPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, fabricPrivacy) insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, resourceHelper, treatmentsPlugin, sp, commandQueue, profileFunction, context) openAPSSMBPlugin = OpenAPSSMBPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits) openAPSAMAPlugin = OpenAPSAMAPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValueTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValueTest.kt index ec3588fbe7..b9d959c631 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValueTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValueTest.kt @@ -20,6 +20,6 @@ class MsgCheckValueTest : DanaRTestBase() { val array = ByteArray(100) putByteToArray(array, 0, DanaRPump.EXPORT_MODEL.toByte()) packet.handleMessage(array) - Assert.assertEquals(DanaRPump.EXPORT_MODEL, danaRPump.model) + Assert.assertEquals(DanaRPump.EXPORT_MODEL, danaRPump.btModel) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt index a9a13dbc90..89e4bd5fad 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt @@ -13,7 +13,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import org.junit.Assert import org.junit.Before import org.junit.Test @@ -66,6 +65,6 @@ class DanaRSPluginTest : DanaRSTestBase() { Mockito.`when`(resourceHelper.gs(eq(R.string.limitingbasalratio), anyObject(), anyObject())).thenReturn("limitingbasalratio") Mockito.`when`(resourceHelper.gs(eq(R.string.limitingpercentrate), anyObject(), anyObject())).thenReturn("limitingpercentrate") - danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage) + danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, fabricPrivacy) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt index 420b0a73d8..7b5b94522f 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt @@ -9,7 +9,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import org.junit.Assert import org.junit.Before import org.junit.Test @@ -47,7 +46,7 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() { @Before fun mock() { - danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage) + danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, fabricPrivacy) Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_VerisonTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_VerisonTest.kt new file mode 100644 index 0000000000..f962560115 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_VerisonTest.kt @@ -0,0 +1,20 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.comm + +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +class DanaRS_Packet_General_Get_Shipping_VerisonTest : DanaRSTestBase() { + + @Test fun runTest() { + val packet = DanaRS_Packet_General_Get_Shipping_Version(aapsLogger, danaRPump) + // test message decoding + val ver = byteArrayOf((-78).toByte(), (-127).toByte(), (66).toByte(), (80).toByte(), (78).toByte(), (45).toByte(), (51).toByte(), (46).toByte(), (48).toByte(), (46).toByte(), (48).toByte()) + packet.handleMessage(ver) + Assert.assertFalse(packet.failed) + Assert.assertEquals("BPN-3.0.0", danaRPump.bleModel) + Assert.assertEquals("GENERAL__GET_SHIPPING_VERSION", packet.friendlyName) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt index 06f69cadbd..3d46558207 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt @@ -11,7 +11,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.treatments.Treatment -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.DefaultValueHelper import org.junit.Assert import org.junit.Before @@ -66,7 +65,7 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() { @Before fun mock() { - danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage) + danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, fabricPrivacy) danaRSPlugin.bolusingTreatment = Treatment(treatmentInjector) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_RatioTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_RatioTest.kt new file mode 100644 index 0000000000..4bd5bbbd1a --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_RatioTest.kt @@ -0,0 +1,22 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.comm + +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +@PrepareForTest() +class DanaRS_Packet_Review_Get_Pump_Dec_RatioTest : DanaRSTestBase() { + + @Test fun runTest() { + val packet = DanaRS_Packet_Review_Get_Pump_Dec_Ratio(aapsLogger, danaRPump) + + val array = ByteArray(100) + putByteToArray(array, 0, 4.toByte()) + packet.handleMessage(array) + Assert.assertEquals(20, danaRPump.decRatio) + Assert.assertEquals("REVIEW__GET_PUMP_DEC_RATIO", packet.friendlyName) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2Test.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2Test.kt index 71a361e8c5..77bf756890 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2Test.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2Test.kt @@ -33,6 +33,6 @@ class MsgCheckValue_v2Test : DanaRTestBase() { val packet = MsgCheckValue_v2(aapsLogger, rxBus, resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, danaRv2Plugin, configBuilderPlugin, commandQueue) // test message decoding packet.handleMessage(createArray(34, 3.toByte())) - Assert.assertEquals(DanaRPump.EXPORT_MODEL, danaRPump.model) + Assert.assertEquals(DanaRPump.EXPORT_MODEL, danaRPump.btModel) } } \ No newline at end of file From a85ec262d32a7b491b92ce20b86c60a1f64a752c Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 28 Mar 2020 22:40:56 +0100 Subject: [PATCH 07/53] Display Dana model --- .../plugins/pump/danaR/DanaRFragment.kt | 9 ++------- .../androidaps/plugins/pump/danaR/DanaRPump.kt | 17 ++++++++++++++++- .../plugins/pump/danaR/comm/MsgCheckValue.kt | 6 +++--- .../pump/danaRKorean/comm/MsgCheckValue_k.kt | 6 +++--- .../DanaRS_Packet_General_Get_Pump_Check.kt | 4 ++-- .../pump/danaRv2/comm/MsgCheckValue_v2.kt | 6 +++--- app/src/main/res/values/strings.xml | 2 +- .../pump/danaR/comm/MsgCheckValueTest.kt | 2 +- .../pump/danaRv2/comm/MsgCheckValue_v2Test.kt | 2 +- 9 files changed, 32 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt index 6cace72c5f..fcc84f1314 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt @@ -210,12 +210,7 @@ class DanaRFragment : DaggerFragment() { danar_battery.text = "{fa-battery-" + pump.batteryRemaining / 25 + "}" SetWarnColor.setColorInverse(danar_battery, pump.batteryRemaining.toDouble(), 51.0, 26.0) danar_iob.text = resourceHelper.gs(R.string.formatinsulinunits, pump.iob) - if (pump.btModel != 0 || pump.protocol != 0 || pump.productCode != 0) { - danar_firmware.text = resourceHelper.gs(R.string.danar_model, pump.btModel, pump.protocol, pump.productCode) - } else { - @Suppress("SetTextI18n") - danar_firmware.text = "OLD" - } + danar_firmware.text = resourceHelper.gs(R.string.danar_model, pump.modelFriendlyName(), pump.hwModel, pump.protocol, pump.productCode) danar_basalstep.text = pump.basalStep.toString() danar_bolusstep.text = pump.bolusStep.toString() danar_serialnumber.text = pump.serialNumber @@ -229,7 +224,7 @@ class DanaRFragment : DaggerFragment() { //hide user options button if not an RS pump or old firmware // also excludes pump with model 03 because of untested error val isKorean = danaRKoreanPlugin.isEnabled(PluginType.PUMP) - if (isKorean || danar_firmware.text === "OLD" || pump.btModel == 3) { + if (isKorean || pump.hwModel == 0 || pump.hwModel == 3) { danar_user_options.visibility = View.GONE } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt index eb5bb627fc..213efac04d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt @@ -51,7 +51,7 @@ class DanaRPump @Inject constructor( var isNewPump = true // R only , providing model info var password = -1 // R, RSv1 var pumpTime: Long = 0 - var btModel = 0 + var hwModel = 0 var protocol = 0 var productCode = 0 var errorState: ErrorState = ErrorState.NONE @@ -227,6 +227,21 @@ class DanaRPump @Inject constructor( lastSettingsRead = 0 } + fun modelFriendlyName(): String = + when (hwModel) { + 0x01 -> "DanaR Korean" + 0x03 -> + if (protocol == 0x00) "DanaR old" + else if (protocol == 0x02) "DanaR v2" + else "DanaR" // 0x01 and 0x03 known + 0x05 -> + if (protocol < 10) "DanaRS" + else "DanaRS v3" + 0x06 -> "DanaRS Korean" + 0x07 -> "Dana-i" + else -> "Unknown Dana pump" + } + companion object { const val UNITS_MGDL = 0 const val UNITS_MMOL = 1 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValue.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValue.kt index 3cc8701a38..f573ef0475 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValue.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValue.kt @@ -19,14 +19,14 @@ class MsgCheckValue( override fun handleMessage(bytes: ByteArray) { danaRPump.isNewPump = true aapsLogger.debug(LTag.PUMPCOMM, "New firmware confirmed") - danaRPump.btModel = intFromBuff(bytes, 0, 1) + danaRPump.hwModel = intFromBuff(bytes, 0, 1) danaRPump.protocol = intFromBuff(bytes, 1, 1) danaRPump.productCode = intFromBuff(bytes, 2, 1) - if (danaRPump.btModel != DanaRPump.EXPORT_MODEL) { + if (danaRPump.hwModel != DanaRPump.EXPORT_MODEL) { danaRPlugin.disconnect("Wrong Model") aapsLogger.debug(LTag.PUMPCOMM, "Wrong model selected") } - aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.btModel)) + aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.hwModel)) aapsLogger.debug(LTag.PUMPCOMM, "Protocol: " + String.format("%02X ", danaRPump.protocol)) aapsLogger.debug(LTag.PUMPCOMM, "Product Code: " + String.format("%02X ", danaRPump.productCode)) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgCheckValue_k.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgCheckValue_k.kt index 412d13cf3d..1742c4b1dd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgCheckValue_k.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgCheckValue_k.kt @@ -21,14 +21,14 @@ class MsgCheckValue_k( override fun handleMessage(bytes: ByteArray) { danaRPump.isNewPump = true aapsLogger.debug(LTag.PUMPCOMM, "New firmware confirmed") - danaRPump.btModel = intFromBuff(bytes, 0, 1) + danaRPump.hwModel = intFromBuff(bytes, 0, 1) danaRPump.protocol = intFromBuff(bytes, 1, 1) danaRPump.productCode = intFromBuff(bytes, 2, 1) - if (danaRPump.btModel != DanaRPump.DOMESTIC_MODEL) { + if (danaRPump.hwModel != DanaRPump.DOMESTIC_MODEL) { danaRKoreanPlugin.disconnect("Wrong Model") aapsLogger.debug(LTag.PUMPCOMM, "Wrong model selected") } - aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.btModel)) + aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.hwModel)) aapsLogger.debug(LTag.PUMPCOMM, "Protocol: " + String.format("%02X ", danaRPump.protocol)) aapsLogger.debug(LTag.PUMPCOMM, "Product Code: " + String.format("%02X ", danaRPump.productCode)) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt index 5646c6f370..be57043e89 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt @@ -30,14 +30,14 @@ class DanaRS_Packet_General_Get_Pump_Check( failed = false var dataIndex = DATA_START var dataSize = 1 - danaRPump.btModel = byteArrayToInt(getBytes(data, dataIndex, dataSize)) + danaRPump.hwModel = byteArrayToInt(getBytes(data, dataIndex, dataSize)) dataIndex += dataSize dataSize = 1 danaRPump.protocol = byteArrayToInt(getBytes(data, dataIndex, dataSize)) dataIndex += dataSize dataSize = 1 danaRPump.productCode = byteArrayToInt(getBytes(data, dataIndex, dataSize)) - aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.btModel)) + aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.hwModel)) aapsLogger.debug(LTag.PUMPCOMM, "Protocol: " + String.format("%02X ", danaRPump.protocol)) aapsLogger.debug(LTag.PUMPCOMM, "Product Code: " + String.format("%02X ", danaRPump.productCode)) if (danaRPump.productCode < 2) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.kt index 87628c0d1a..7d0b2b5e53 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.kt @@ -38,10 +38,10 @@ class MsgCheckValue_v2( override fun handleMessage(bytes: ByteArray) { danaRPump.isNewPump = true aapsLogger.debug(LTag.PUMPCOMM, "New firmware confirmed") - danaRPump.btModel = intFromBuff(bytes, 0, 1) + danaRPump.hwModel = intFromBuff(bytes, 0, 1) danaRPump.protocol = intFromBuff(bytes, 1, 1) danaRPump.productCode = intFromBuff(bytes, 2, 1) - if (danaRPump.btModel != DanaRPump.EXPORT_MODEL) { + if (danaRPump.hwModel != DanaRPump.EXPORT_MODEL) { danaRPump.reset() val notification = Notification(Notification.WRONG_DRIVER, resourceHelper.gs(R.string.pumpdrivercorrected), Notification.NORMAL) rxBus.send(EventNewNotification(notification)) @@ -74,7 +74,7 @@ class MsgCheckValue_v2( commandQueue.readStatus("PumpDriverChange", null) // force new connection return } - aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.btModel)) + aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.hwModel)) aapsLogger.debug(LTag.PUMPCOMM, "Protocol: " + String.format("%02X ", danaRPump.protocol)) aapsLogger.debug(LTag.PUMPCOMM, "Product Code: " + String.format("%02X ", danaRPump.productCode)) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3ac901f44f..86b7c02cbc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -485,7 +485,7 @@ Useful when data from unfiltered sources like xDrip gets noisy. Advanced Settings key_advancedsettings - Model: %1$02X Protocol: %2$02X Code: %3$02X + %1$s\nModel: %2$02X\nProtocol: %3$02X\nCode: %4$02X Profile Default value: 3 This is a key OpenAPS safety cap. What this does is limit your basals to be 3x (in this people) your biggest basal rate. You likely will not need to change this, but you should be aware that’s what is discussed about “3x max daily; 4x current” for safety caps. Default value: 4 This is the other half of the key OpenAPS safety caps, and the other half of “3x max daily; 4x current” of the safety caps. This means your basal, regardless of max basal set on your pump, cannot be any higher than this number times the current level of your basal. This is to prevent people from getting into dangerous territory by setting excessively high max basals before understanding how the algorithm works. Again, the default is 4x; most people will never need to adjust this and are instead more likely to need to adjust other settings if they feel like they are “running into” this safety cap. diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValueTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValueTest.kt index b9d959c631..2b5058241d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValueTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValueTest.kt @@ -20,6 +20,6 @@ class MsgCheckValueTest : DanaRTestBase() { val array = ByteArray(100) putByteToArray(array, 0, DanaRPump.EXPORT_MODEL.toByte()) packet.handleMessage(array) - Assert.assertEquals(DanaRPump.EXPORT_MODEL, danaRPump.btModel) + Assert.assertEquals(DanaRPump.EXPORT_MODEL, danaRPump.hwModel) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2Test.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2Test.kt index 77bf756890..4bd8ad6e57 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2Test.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2Test.kt @@ -33,6 +33,6 @@ class MsgCheckValue_v2Test : DanaRTestBase() { val packet = MsgCheckValue_v2(aapsLogger, rxBus, resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, danaRv2Plugin, configBuilderPlugin, commandQueue) // test message decoding packet.handleMessage(createArray(34, 3.toByte())) - Assert.assertEquals(DanaRPump.EXPORT_MODEL, danaRPump.btModel) + Assert.assertEquals(DanaRPump.EXPORT_MODEL, danaRPump.hwModel) } } \ No newline at end of file From df03a8a2c014b025d0d1236780bc627f2b5ec064 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 29 Mar 2020 11:40:57 +0200 Subject: [PATCH 08/53] DanaRSPlugin, DanaRSService -> kt, allign with R code --- .../interfaces/PumpDescription.java | 5 + .../smsCommunicator/SmsCommunicatorPlugin.kt | 2 +- .../plugins/pump/danaR/DanaRPlugin.java | 2 +- .../plugins/pump/danaR/DanaRPump.kt | 8 +- .../plugins/pump/danaR/comm/MsgBolusStart.kt | 3 +- .../pump/danaR/comm/MsgBolusStartWithSpeed.kt | 3 +- .../pump/danaRKorean/DanaRKoreanPlugin.java | 2 +- .../plugins/pump/danaRS/DanaRSPlugin.java | 843 ------------------ .../plugins/pump/danaRS/DanaRSPlugin.kt | 658 ++++++++++++++ .../danaRS/comm/DanaRSMessageHashTable.kt | 11 +- .../comm/DanaRS_Packet_APS_History_Events.kt | 11 +- ...anaRS_Packet_Bolus_Set_Step_Bolus_Start.kt | 12 +- ...DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt | 12 +- .../DanaRS_Packet_Notify_Delivery_Complete.kt | 14 +- ...aRS_Packet_Notify_Delivery_Rate_Display.kt | 14 +- .../plugins/pump/danaRS/services/BLEComm.kt | 3 +- .../pump/danaRS/services/DanaRSService.java | 565 ------------ .../pump/danaRS/services/DanaRSService.kt | 462 ++++++++++ .../plugins/pump/danaRv2/DanaRv2Plugin.java | 2 +- .../danaRS/comm/DanaRSMessageHashTableTest.kt | 7 +- .../DanaRS_Packet_APS_History_EventsTest.kt | 5 +- ...S_Packet_Bolus_Set_Step_Bolus_StartTest.kt | 2 +- ...RS_Packet_Bolus_Set_Step_Bolus_StopTest.kt | 7 +- ...aRS_Packet_Notify_Delivery_CompleteTest.kt | 9 +- ...Packet_Notify_Delivery_Rate_DisplayTest.kt | 4 +- 25 files changed, 1187 insertions(+), 1479 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java index e4a02883e8..65e735e53a 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java @@ -15,6 +15,11 @@ public class PumpDescription { resetSettings(); } + public PumpDescription (PumpType pumpType) { + this(); + setPumpDescription(pumpType); + } + public static final int NONE = 0; public static final int PERCENT = 0x01; public static final int ABSOLUTE = 0x02; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index 78a0bf0ffc..7019a2a65d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -709,7 +709,7 @@ class SmsCommunicatorPlugin @Inject constructor( sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat))) return } - time = midnight + T.secs(seconds.toLong()).msecs() + time = midnight + T.secs(seconds.toLong()).msecs() // TODO: this is wrong during leap day } grams = constraintChecker.applyCarbsConstraints(Constraint(grams)).value() if (grams == 0) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat))) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java index 3c6ce84c42..91fa4207b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java @@ -165,7 +165,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { result.bolusDelivered = t.insulin; result.carbsDelivered = detailedBolusInfo.carbs; if (!result.success) - result.comment = String.format(resourceHelper.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, danaRPump.getMessageStartErrorCode()); + result.comment = String.format(resourceHelper.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, danaRPump.getBolusStartErrorCode()); else result.comment = resourceHelper.gs(R.string.virtualpump_resultok); aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt index 213efac04d..b9a5509b54 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt @@ -141,15 +141,15 @@ class DanaRPump @Inject constructor( return if (units == UNITS_MGDL) Constants.MGDL else Constants.MMOL } - // DanaR,Rv2,RK specific flags - // last start bolus erroCode - var messageStartErrorCode: Int = 0 - var historyDoneReceived: Boolean = false + var bolusStartErrorCode: Int = 0 // last start bolus erroCode + var historyDoneReceived: Boolean = false // true when last history message is received var bolusingTreatment: Treatment? = null // actually delivered treatment var bolusAmountToBeDelivered = 0.0 // amount to be delivered var bolusProgressLastTimeStamp: Long = 0 // timestamp of last bolus progress message var bolusStopped = false // bolus finished var bolusStopForced = false // bolus forced to stop by user + var bolusDone = false // success end + var lastEventTimeLoaded: Long = 0 // timestamp of last received event fun createConvertedProfile(): ProfileStore? { pumpProfiles?.let { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStart.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStart.kt index 695c3f1ec0..320d8b85d3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStart.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStart.kt @@ -4,7 +4,6 @@ import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker -import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump class MsgBolusStart( @@ -31,6 +30,6 @@ class MsgBolusStart( failed = false aapsLogger.debug(LTag.PUMPBTCOMM, "Messsage response: $errorCode OK") } - danaRPump.messageStartErrorCode = errorCode + danaRPump.bolusStartErrorCode = errorCode } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStartWithSpeed.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStartWithSpeed.kt index 3ea3eed8f1..2925172735 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStartWithSpeed.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStartWithSpeed.kt @@ -4,7 +4,6 @@ import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker -import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump class MsgBolusStartWithSpeed( @@ -33,6 +32,6 @@ class MsgBolusStartWithSpeed( failed = false aapsLogger.debug(LTag.PUMPBTCOMM, "Messsage response: $errorCode OK") } - danaRPump.messageStartErrorCode = errorCode + danaRPump.bolusStartErrorCode = errorCode } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java index 809cf77e6f..4ae99b25e8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java @@ -168,7 +168,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { result.bolusDelivered = t.insulin; result.carbsDelivered = detailedBolusInfo.carbs; if (!result.success) - result.comment = resourceHelper.gs(R.string.boluserrorcode, detailedBolusInfo.insulin, t.insulin, danaRPump.getMessageStartErrorCode()); + result.comment = resourceHelper.gs(R.string.boluserrorcode, detailedBolusInfo.insulin, t.insulin, danaRPump.getBolusStartErrorCode()); else result.comment = resourceHelper.gs(R.string.virtualpump_resultok); aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java deleted file mode 100644 index 35f1e81a21..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java +++ /dev/null @@ -1,843 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS; - -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.ServiceConnection; -import android.os.IBinder; - -import androidx.annotation.NonNull; -import androidx.preference.Preference; - -import org.jetbrains.annotations.NotNull; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.List; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.BuildConfig; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.data.DetailedBolusInfo; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.data.PumpEnactResult; -import info.nightscout.androidaps.db.ExtendedBolus; -import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.events.EventAppExit; -import info.nightscout.androidaps.events.EventConfigBuilderChange; -import info.nightscout.androidaps.interfaces.CommandQueueProvider; -import info.nightscout.androidaps.interfaces.Constraint; -import info.nightscout.androidaps.interfaces.ConstraintsInterface; -import info.nightscout.androidaps.interfaces.DanaRInterface; -import info.nightscout.androidaps.interfaces.PluginDescription; -import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.interfaces.PumpDescription; -import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.interfaces.PumpPluginBase; -import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.plugins.bus.RxBusWrapper; -import info.nightscout.androidaps.plugins.common.ManufacturerType; -import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker; -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction; -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.events.EventDismissNotification; -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.bolusInfo.DetailedBolusInfoStorage; -import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; -import info.nightscout.androidaps.plugins.pump.danaR.DanaRFragment; -import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; -import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes; -import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSDeviceChange; -import info.nightscout.androidaps.plugins.pump.danaRS.services.DanaRSService; -import info.nightscout.androidaps.plugins.treatments.Treatment; -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; -import info.nightscout.androidaps.utils.DateUtil; -import info.nightscout.androidaps.utils.DecimalFormatter; -import info.nightscout.androidaps.utils.FabricPrivacy; -import info.nightscout.androidaps.utils.Round; -import info.nightscout.androidaps.utils.T; -import info.nightscout.androidaps.utils.ToastUtils; -import info.nightscout.androidaps.utils.resources.ResourceHelper; -import info.nightscout.androidaps.utils.sharedPreferences.SP; -import io.reactivex.disposables.CompositeDisposable; -import io.reactivex.schedulers.Schedulers; - -@Singleton -public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaRInterface, ConstraintsInterface { - private CompositeDisposable disposable = new CompositeDisposable(); - - private final Context context; - private final ResourceHelper resourceHelper; - private final ConstraintChecker constraintChecker; - private final ProfileFunction profileFunction; - private final TreatmentsPlugin treatmentsPlugin; - private final SP sp; - private final RxBusWrapper rxBus; - private final DanaRPump danaRPump; - private final DetailedBolusInfoStorage detailedBolusInfoStorage; - private final FabricPrivacy fabricPrivacy; - - private DanaRSService danaRSService; - - private String mDeviceAddress = ""; - public String mDeviceName = ""; - - public PumpDescription pumpDescription = new PumpDescription(); - - // Bolus & history handling - public int bolusStartErrorCode; // from start message - public Treatment bolusingTreatment; // actually delivered treatment - public double bolusAmountToBeDelivered = 0.0; // amount to be delivered - public boolean bolusStopped = false; // bolus finished - public boolean bolusStopForced = false; // bolus forced to stop by user - public boolean bolusDone = false; // success end - public long bolusProgressLastTimeStamp = 0; // timestamp of last bolus progress message - public boolean apsHistoryDone = false; // true when last history message is received - public long lastEventTimeLoaded = 0; // timestamp of last received event - - @Inject - public DanaRSPlugin( - HasAndroidInjector injector, - AAPSLogger aapsLogger, - RxBusWrapper rxBus, - Context context, - ResourceHelper resourceHelper, - ConstraintChecker constraintChecker, - ProfileFunction profileFunction, - TreatmentsPlugin treatmentsPlugin, - SP sp, - CommandQueueProvider commandQueue, - DanaRPump danaRPump, - DetailedBolusInfoStorage detailedBolusInfoStorage, - FabricPrivacy fabricPrivacy - ) { - super(new PluginDescription() - .mainType(PluginType.PUMP) - .fragmentClass(DanaRFragment.class.getName()) - .pluginName(R.string.danarspump) - .shortName(R.string.danarspump_shortname) - .preferencesId(R.xml.pref_danars) - .description(R.string.description_pump_dana_rs), - injector, aapsLogger, resourceHelper, commandQueue - ); - this.context = context; - this.rxBus = rxBus; - this.resourceHelper = resourceHelper; - this.constraintChecker = constraintChecker; - this.profileFunction = profileFunction; - this.treatmentsPlugin = treatmentsPlugin; - this.sp = sp; - this.danaRPump = danaRPump; - this.detailedBolusInfoStorage = detailedBolusInfoStorage; - this.fabricPrivacy = fabricPrivacy; - - pumpDescription.setPumpDescription(PumpType.DanaRS); - } - - @Override - public void updatePreferenceSummary(@NotNull Preference pref) { - super.updatePreferenceSummary(pref); - - if (pref.getKey().equals(resourceHelper.gs(R.string.key_danars_name))) - pref.setSummary(sp.getString(R.string.key_danars_name, "")); - } - - @Override - protected void onStart() { - Intent intent = new Intent(context, DanaRSService.class); - context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); - - disposable.add(rxBus - .toObservable(EventAppExit.class) - .observeOn(Schedulers.io()) - .subscribe(event -> context.unbindService(mConnection), fabricPrivacy::logException) - ); - disposable.add(rxBus - .toObservable(EventConfigBuilderChange.class) - .observeOn(Schedulers.io()) - .subscribe(event -> danaRPump.reset()) - ); - disposable.add(rxBus - .toObservable(EventDanaRSDeviceChange.class) - .observeOn(Schedulers.io()) - .subscribe(event -> changePump(), fabricPrivacy::logException) - ); - changePump(); // load device name - super.onStart(); - } - - @Override - protected void onStop() { - context.unbindService(mConnection); - - disposable.clear(); - super.onStop(); - } - - private ServiceConnection mConnection = new ServiceConnection() { - - public void onServiceDisconnected(ComponentName name) { - getAapsLogger().debug(LTag.PUMP, "Service is disconnected"); - danaRSService = null; - } - - public void onServiceConnected(ComponentName name, IBinder service) { - getAapsLogger().debug(LTag.PUMP, "Service is connected"); - DanaRSService.LocalBinder mLocalBinder = (DanaRSService.LocalBinder) service; - danaRSService = mLocalBinder.getServiceInstance(); - } - }; - - public void changePump() { - mDeviceAddress = sp.getString(R.string.key_danars_address, ""); - mDeviceName = sp.getString(R.string.key_danars_name, ""); - danaRPump.reset(); - getCommandQueue().readStatus("DeviceChanged", null); - } - - @Override - public void connect(String from) { - getAapsLogger().debug(LTag.PUMP, "RS connect from: " + from); - if (danaRSService != null && !mDeviceAddress.equals("") && !mDeviceName.equals("")) { - boolean success = danaRSService.connect(from, mDeviceAddress); - if (!success) - ToastUtils.showToastInUiThread(context, resourceHelper.gs(R.string.rileylink_scanner_ble_not_supported)); - } - } - - @Override - public boolean isConnected() { - return danaRSService != null && danaRSService.isConnected(); - } - - @Override - public boolean isConnecting() { - return danaRSService != null && danaRSService.isConnecting(); - } - - @Override - public boolean isHandshakeInProgress() { - return false; - } - - @Override - public void finishHandshaking() { - } - - @Override - public void disconnect(String from) { - getAapsLogger().debug(LTag.PUMP, "RS disconnect from: " + from); - if (danaRSService != null) danaRSService.disconnect(from); - } - - @Override - public void stopConnecting() { - if (danaRSService != null) danaRSService.stopConnecting(); - } - - @Override - public void getPumpStatus() { - if (danaRSService != null) { - danaRSService.getPumpStatus(); - pumpDescription.basalStep = danaRPump.getBasalStep(); - pumpDescription.bolusStep = danaRPump.getBolusStep(); - } - } - - // DanaR interface - - @Override - public PumpEnactResult loadHistory(byte type) { - return danaRSService.loadHistory(type); - } - - @Override - public PumpEnactResult loadEvents() { - return danaRSService.loadEvents(); - } - - @Override - public PumpEnactResult setUserOptions() { - return danaRSService.setUserSettings(); - } - - // Constraints interface - - @NonNull - @Override - public Constraint applyBasalConstraints(Constraint absoluteRate, @NonNull Profile profile) { - absoluteRate.setIfSmaller(getAapsLogger(), danaRPump.getMaxBasal(), resourceHelper.gs(R.string.limitingbasalratio, danaRPump.getMaxBasal(), resourceHelper.gs(R.string.pumplimit)), this); - return absoluteRate; - } - - @NonNull - @Override - public Constraint applyBasalPercentConstraints(Constraint percentRate, @NonNull Profile profile) { - percentRate.setIfGreater(getAapsLogger(), 0, resourceHelper.gs(R.string.limitingpercentrate, 0, resourceHelper.gs(R.string.itmustbepositivevalue)), this); - percentRate.setIfSmaller(getAapsLogger(), getPumpDescription().maxTempPercent, resourceHelper.gs(R.string.limitingpercentrate, getPumpDescription().maxTempPercent, resourceHelper.gs(R.string.pumplimit)), this); - - return percentRate; - } - - - @NonNull - @Override - public Constraint applyBolusConstraints(Constraint insulin) { - insulin.setIfSmaller(getAapsLogger(), danaRPump.getMaxBolus(), resourceHelper.gs(R.string.limitingbolus, danaRPump.getMaxBolus(), resourceHelper.gs(R.string.pumplimit)), this); - return insulin; - } - - @NonNull - @Override - public Constraint applyExtendedBolusConstraints(@NonNull Constraint insulin) { - return applyBolusConstraints(insulin); - } - - // Pump interface - - @Override - public boolean isInitialized() { - return danaRPump.getLastConnection() > 0 && danaRPump.getMaxBasal() > 0; - } - - @Override - public boolean isSuspended() { - return danaRPump.getPumpSuspended(); - } - - @Override - public boolean isBusy() { - if (danaRSService == null) return false; - return danaRSService.isConnected() || danaRSService.isConnecting(); - } - - @NonNull @Override - public PumpEnactResult setNewBasalProfile(Profile profile) { - PumpEnactResult result = new PumpEnactResult(getInjector()); - - if (danaRSService == null) { - getAapsLogger().error("setNewBasalProfile sExecutionService is null"); - result.comment = "setNewBasalProfile sExecutionService is null"; - return result; - } - if (!isInitialized()) { - getAapsLogger().error("setNewBasalProfile not initialized"); - Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, resourceHelper.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT); - rxBus.send(new EventNewNotification(notification)); - result.comment = resourceHelper.gs(R.string.pumpNotInitializedProfileNotSet); - return result; - } else { - rxBus.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); - } - if (!danaRSService.updateBasalsInPump(profile)) { - Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, resourceHelper.gs(R.string.failedupdatebasalprofile), Notification.URGENT); - rxBus.send(new EventNewNotification(notification)); - result.comment = resourceHelper.gs(R.string.failedupdatebasalprofile); - return result; - } else { - rxBus.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); - rxBus.send(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); - Notification notification = new Notification(Notification.PROFILE_SET_OK, resourceHelper.gs(R.string.profile_set_ok), Notification.INFO, 60); - rxBus.send(new EventNewNotification(notification)); - result.success = true; - result.enacted = true; - result.comment = "OK"; - return result; - } - } - - @Override - public boolean isThisProfileSet(Profile profile) { - if (!isInitialized()) - return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS - if (danaRPump.getPumpProfiles() == null) - return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS - int basalValues = danaRPump.getBasal48Enable() ? 48 : 24; - int basalIncrement = danaRPump.getBasal48Enable() ? 30 * 60 : 60 * 60; - for (int h = 0; h < basalValues; h++) { - Double pumpValue = danaRPump.getPumpProfiles()[danaRPump.getActiveProfile()][h]; - Double profileValue = profile.getBasalTimeFromMidnight(h * basalIncrement); - if (Math.abs(pumpValue - profileValue) > getPumpDescription().basalStep) { - getAapsLogger().debug(LTag.PUMP, "Diff found. Hour: " + h + " Pump: " + pumpValue + " Profile: " + profileValue); - return false; - } - } - return true; - } - - @Override - public long lastDataTime() { - return danaRPump.getLastConnection(); - } - - @Override - public double getBaseBasalRate() { - return danaRPump.getCurrentBasal(); - } - - @Override - public double getReservoirLevel() { - return danaRPump.getReservoirRemainingUnits(); - } - - @Override - public int getBatteryLevel() { - return danaRPump.getBatteryRemaining(); - } - - @NonNull @Override - public synchronized PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { - detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value(); - if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) { - int preferencesSpeed = sp.getInt(R.string.key_danars_bolusspeed, 0); - int speed = 12; - switch (preferencesSpeed) { - case 0: - speed = 12; - break; - case 1: - speed = 30; - break; - case 2: - speed = 60; - break; - } - // RS stores end time for bolus, we need to adjust time - // default delivery speed is 12 sec/U - detailedBolusInfo.date = DateUtil.now() + (long) (speed * detailedBolusInfo.insulin * 1000); - // clean carbs to prevent counting them as twice because they will picked up as another record - // I don't think it's necessary to copy DetailedBolusInfo right now for carbs records - double carbs = detailedBolusInfo.carbs; - detailedBolusInfo.carbs = 0; - int carbTime = detailedBolusInfo.carbTime; - if (carbTime == 0) carbTime--; // better set 1 min back to prevents clash with insulin - detailedBolusInfo.carbTime = 0; - - detailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history - - Treatment t = new Treatment(); - t.isSMB = detailedBolusInfo.isSMB; - boolean connectionOK = false; - if (detailedBolusInfo.insulin > 0 || carbs > 0) - connectionOK = danaRSService.bolus(detailedBolusInfo.insulin, (int) carbs, DateUtil.now() + T.mins(carbTime).msecs(), t); - PumpEnactResult result = new PumpEnactResult(getInjector()); - result.success = connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep; - result.bolusDelivered = t.insulin; - result.carbsDelivered = detailedBolusInfo.carbs; - if (!result.success) { - String error = "" + bolusStartErrorCode; - switch (bolusStartErrorCode) { - // 4 reported as max bolus violation. Check later - case 0x10: - error = resourceHelper.gs(R.string.maxbolusviolation); - break; - case 0x20: - error = resourceHelper.gs(R.string.commanderror); - break; - case 0x40: - error = resourceHelper.gs(R.string.speederror); - break; - case 0x80: - error = resourceHelper.gs(R.string.insulinlimitviolation); - break; - } - result.comment = String.format(resourceHelper.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, error); - } else - result.comment = resourceHelper.gs(R.string.virtualpump_resultok); - getAapsLogger().debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); - return result; - } else { - PumpEnactResult result = new PumpEnactResult(getInjector()); - result.success = false; - result.bolusDelivered = 0d; - result.carbsDelivered = 0d; - result.comment = resourceHelper.gs(R.string.danar_invalidinput); - getAapsLogger().error("deliverTreatment: Invalid input"); - return result; - } - } - - @Override - public void stopBolusDelivering() { - if (danaRSService == null) { - getAapsLogger().error("stopBolusDelivering sExecutionService is null"); - return; - } - danaRSService.bolusStop(); - } - - // This is called from APS - @NonNull @Override - public synchronized PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) { - // Recheck pump status if older than 30 min - - //This should not be needed while using queue because connection should be done before calling this - //if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) { - // connect("setTempBasalAbsolute old data"); - //} - - PumpEnactResult result = new PumpEnactResult(getInjector()); - - absoluteRate = constraintChecker.applyBasalConstraints(new Constraint<>(absoluteRate), profile).value(); - - final boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d; - final boolean doLowTemp = absoluteRate < getBaseBasalRate(); - final boolean doHighTemp = absoluteRate > getBaseBasalRate(); - - if (doTempOff) { - // If temp in progress - if (treatmentsPlugin.isTempBasalInProgress()) { - getAapsLogger().debug(LTag.PUMP, "setTempBasalAbsolute: Stopping temp basal (doTempOff)"); - return cancelTempBasal(false); - } - result.success = true; - result.enacted = false; - result.percent = 100; - result.isPercent = true; - result.isTempCancel = true; - getAapsLogger().debug(LTag.PUMP, "setTempBasalAbsolute: doTempOff OK"); - return result; - } - - if (doLowTemp || doHighTemp) { - Integer percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue(); - if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue(); - else percentRate = Round.floorTo((double) percentRate, 10d).intValue(); - if (percentRate > 500) // Special high temp 500/15min - percentRate = 500; - // Check if some temp is already in progress - TemporaryBasal activeTemp = treatmentsPlugin.getTempBasalFromHistory(System.currentTimeMillis()); - if (activeTemp != null) { - getAapsLogger().debug(LTag.PUMP, "setTempBasalAbsolute: currently running: " + activeTemp.toString()); - // Correct basal already set ? - if (activeTemp.percentRate == percentRate && activeTemp.getPlannedRemainingMinutes() > 4) { - if (!enforceNew) { - result.success = true; - result.percent = percentRate; - result.enacted = false; - result.duration = activeTemp.getPlannedRemainingMinutes(); - result.isPercent = true; - result.isTempCancel = false; - getAapsLogger().debug(LTag.PUMP, "setTempBasalAbsolute: Correct temp basal already set (doLowTemp || doHighTemp)"); - return result; - } - } - } - // Convert duration from minutes to hours - getAapsLogger().debug(LTag.PUMP, "setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)"); - if (percentRate == 0 && durationInMinutes > 30) { - result = setTempBasalPercent(percentRate, durationInMinutes, profile, enforceNew); - } else { - // use special APS temp basal call ... 100+/15min .... 100-/30min - result = setHighTempBasalPercent(percentRate); - } - if (!result.success) { - getAapsLogger().error("setTempBasalAbsolute: Failed to set hightemp basal"); - return result; - } - getAapsLogger().debug(LTag.PUMP, "setTempBasalAbsolute: hightemp basal set ok"); - return result; - } - // We should never end here - getAapsLogger().error("setTempBasalAbsolute: Internal error"); - result.success = false; - result.comment = "Internal error"; - return result; - } - - @NonNull @Override - public synchronized PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) { - DanaRPump pump = danaRPump; - PumpEnactResult result = new PumpEnactResult(getInjector()); - percent = constraintChecker.applyBasalPercentConstraints(new Constraint<>(percent), profile).value(); - if (percent < 0) { - result.isTempCancel = false; - result.enacted = false; - result.success = false; - result.comment = resourceHelper.gs(R.string.danar_invalidinput); - getAapsLogger().error("setTempBasalPercent: Invalid input"); - return result; - } - if (percent > getPumpDescription().maxTempPercent) - percent = getPumpDescription().maxTempPercent; - long now = System.currentTimeMillis(); - TemporaryBasal activeTemp = treatmentsPlugin.getTempBasalFromHistory(now); - if (activeTemp != null && activeTemp.percentRate == percent && activeTemp.getPlannedRemainingMinutes() > 4 && !enforceNew) { - result.enacted = false; - result.success = true; - result.isTempCancel = false; - result.comment = resourceHelper.gs(R.string.virtualpump_resultok); - result.duration = pump.getTempBasalRemainingMin(); - result.percent = pump.getTempBasalPercent(); - result.isPercent = true; - getAapsLogger().debug(LTag.PUMP, "setTempBasalPercent: Correct value already set"); - return result; - } - boolean connectionOK; - if (durationInMinutes == 15 || durationInMinutes == 30) { - connectionOK = danaRSService.tempBasalShortDuration(percent, durationInMinutes); - } else { - int durationInHours = Math.max(durationInMinutes / 60, 1); - connectionOK = danaRSService.tempBasal(percent, durationInHours); - } - if (connectionOK && pump.isTempBasalInProgress() && pump.getTempBasalPercent() == percent) { - result.enacted = true; - result.success = true; - result.comment = resourceHelper.gs(R.string.virtualpump_resultok); - result.isTempCancel = false; - result.duration = pump.getTempBasalRemainingMin(); - result.percent = pump.getTempBasalPercent(); - result.isPercent = true; - getAapsLogger().debug(LTag.PUMP, "setTempBasalPercent: OK"); - return result; - } - result.enacted = false; - result.success = false; - result.comment = resourceHelper.gs(R.string.tempbasaldeliveryerror); - getAapsLogger().error("setTempBasalPercent: Failed to set temp basal"); - return result; - } - - private synchronized PumpEnactResult setHighTempBasalPercent(Integer percent) { - DanaRPump pump = danaRPump; - PumpEnactResult result = new PumpEnactResult(getInjector()); - boolean connectionOK = danaRSService.highTempBasal(percent); - if (connectionOK && pump.isTempBasalInProgress() && pump.getTempBasalPercent() == percent) { - result.enacted = true; - result.success = true; - result.comment = resourceHelper.gs(R.string.virtualpump_resultok); - result.isTempCancel = false; - result.duration = pump.getTempBasalRemainingMin(); - result.percent = pump.getTempBasalPercent(); - result.isPercent = true; - getAapsLogger().debug(LTag.PUMP, "setHighTempBasalPercent: OK"); - return result; - } - result.enacted = false; - result.success = false; - result.comment = resourceHelper.gs(R.string.danar_valuenotsetproperly); - getAapsLogger().error("setHighTempBasalPercent: Failed to set temp basal"); - return result; - } - - @NonNull @Override - public synchronized PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { - DanaRPump pump = danaRPump; - insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value(); - // needs to be rounded - int durationInHalfHours = Math.max(durationInMinutes / 30, 1); - insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep); - PumpEnactResult result = new PumpEnactResult(getInjector()); - ExtendedBolus runningEB = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis()); - if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) { - result.enacted = false; - result.success = true; - result.comment = resourceHelper.gs(R.string.virtualpump_resultok); - result.duration = pump.getExtendedBolusRemainingMinutes(); - result.absolute = pump.getExtendedBolusAbsoluteRate(); - result.isPercent = false; - result.isTempCancel = false; - getAapsLogger().debug(LTag.PUMP, "setExtendedBolus: Correct extended bolus already set. Current: " + pump.getExtendedBolusAmount() + " Asked: " + insulin); - return result; - } - boolean connectionOK = danaRSService.extendedBolus(insulin, durationInHalfHours); - if (connectionOK && pump.isExtendedInProgress() && Math.abs(pump.getExtendedBolusAbsoluteRate() - insulin) < getPumpDescription().extendedBolusStep) { - result.enacted = true; - result.success = true; - result.comment = resourceHelper.gs(R.string.virtualpump_resultok); - result.isTempCancel = false; - result.duration = pump.getExtendedBolusRemainingMinutes(); - result.absolute = pump.getExtendedBolusAbsoluteRate(); - result.bolusDelivered = pump.getExtendedBolusAmount(); - result.isPercent = false; - getAapsLogger().debug(LTag.PUMP, "setExtendedBolus: OK"); - return result; - } - result.enacted = false; - result.success = false; - result.comment = resourceHelper.gs(R.string.danar_valuenotsetproperly); - getAapsLogger().error("setExtendedBolus: Failed to extended bolus"); - return result; - } - - @NonNull @Override - public synchronized PumpEnactResult cancelTempBasal(boolean force) { - PumpEnactResult result = new PumpEnactResult(getInjector()); - TemporaryBasal runningTB = treatmentsPlugin.getTempBasalFromHistory(System.currentTimeMillis()); - if (runningTB != null) { - danaRSService.tempBasalStop(); - result.enacted = true; - result.isTempCancel = true; - } - if (!danaRPump.isTempBasalInProgress()) { - result.success = true; - result.isTempCancel = true; - result.comment = resourceHelper.gs(R.string.virtualpump_resultok); - getAapsLogger().debug(LTag.PUMP, "cancelRealTempBasal: OK"); - return result; - } else { - result.success = false; - result.comment = resourceHelper.gs(R.string.danar_valuenotsetproperly); - result.isTempCancel = true; - getAapsLogger().error("cancelRealTempBasal: Failed to cancel temp basal"); - return result; - } - } - - @NonNull @Override - public synchronized PumpEnactResult cancelExtendedBolus() { - PumpEnactResult result = new PumpEnactResult(getInjector()); - ExtendedBolus runningEB = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis()); - if (runningEB != null) { - danaRSService.extendedBolusStop(); - result.enacted = true; - result.isTempCancel = true; - } - if (!danaRPump.isExtendedInProgress()) { - result.success = true; - result.comment = resourceHelper.gs(R.string.virtualpump_resultok); - getAapsLogger().debug(LTag.PUMP, "cancelExtendedBolus: OK"); - return result; - } else { - result.success = false; - result.comment = resourceHelper.gs(R.string.danar_valuenotsetproperly); - getAapsLogger().error("cancelExtendedBolus: Failed to cancel extended bolus"); - return result; - } - } - - @NonNull @Override - public JSONObject getJSONStatus(Profile profile, String profileName) { - DanaRPump pump = danaRPump; - long now = System.currentTimeMillis(); - if (pump.getLastConnection() + 5 * 60 * 1000L < System.currentTimeMillis()) { - return new JSONObject(); - } - JSONObject pumpjson = new JSONObject(); - JSONObject battery = new JSONObject(); - JSONObject status = new JSONObject(); - JSONObject extended = new JSONObject(); - try { - battery.put("percent", pump.getBatteryRemaining()); - status.put("status", pump.getPumpSuspended() ? "suspended" : "normal"); - status.put("timestamp", DateUtil.toISOString(pump.getLastConnection())); - extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); - if (pump.getLastBolusTime() != 0) { - extended.put("LastBolus", DateUtil.dateAndTimeString(pump.getLastBolusTime())); - extended.put("LastBolusAmount", pump.getLastBolusAmount()); - } - TemporaryBasal tb = treatmentsPlugin.getTempBasalFromHistory(now); - if (tb != null) { - extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile)); - extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date)); - extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); - } - ExtendedBolus eb = treatmentsPlugin.getExtendedBolusFromHistory(now); - if (eb != null) { - extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); - extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); - extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes()); - } - extended.put("BaseBasalRate", getBaseBasalRate()); - try { - extended.put("ActiveProfile", profileFunction.getProfileName()); - } catch (Exception e) { - getAapsLogger().error("Unhandled exception", e); - } - - pumpjson.put("battery", battery); - pumpjson.put("status", status); - pumpjson.put("extended", extended); - pumpjson.put("reservoir", (int) pump.getReservoirRemainingUnits()); - pumpjson.put("clock", DateUtil.toISOString(now)); - } catch (JSONException e) { - getAapsLogger().error("Unhandled exception", e); - } - return pumpjson; - } - - @NonNull @Override - public ManufacturerType manufacturer() { - return ManufacturerType.Sooil; - } - - @NonNull @Override - public PumpType model() { - return PumpType.DanaRS; - } - - @NonNull @Override - public String serialNumber() { - return danaRPump.getSerialNumber(); - } - - @NonNull @Override - public PumpDescription getPumpDescription() { - return pumpDescription; - } - - @NonNull @Override - public String shortStatus(boolean veryShort) { - DanaRPump pump = danaRPump; - String ret = ""; - if (pump.getLastConnection() != 0) { - long agoMsec = System.currentTimeMillis() - pump.getLastConnection(); - int agoMin = (int) (agoMsec / 60d / 1000d); - ret += "LastConn: " + agoMin + " minago\n"; - } - if (pump.getLastBolusTime() != 0) { - ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.getLastBolusAmount()) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.getLastBolusTime()) + "\n"; - } - TemporaryBasal activeTemp = treatmentsPlugin.getRealTempBasalFromHistory(System.currentTimeMillis()); - if (activeTemp != null) { - ret += "Temp: " + activeTemp.toStringFull() + "\n"; - } - ExtendedBolus activeExtendedBolus = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis()); - if (activeExtendedBolus != null) { - ret += "Extended: " + activeExtendedBolus.toString() + "\n"; - } - if (!veryShort) { - ret += "TDD: " + DecimalFormatter.to0Decimal(pump.getDailyTotalUnits()) + " / " + pump.getMaxDailyTotalUnits() + " U\n"; - } - ret += "Reserv: " + DecimalFormatter.to0Decimal(pump.getReservoirRemainingUnits()) + "U\n"; - ret += "Batt: " + pump.getBatteryRemaining() + "\n"; - return ret; - } - - @Override - public boolean isFakingTempsByExtendedBoluses() { - return false; - } - - @NonNull @Override - public PumpEnactResult loadTDDs() { - return loadHistory(RecordTypes.RECORD_TYPE_DAILY); - } - - @Override - public List getCustomActions() { - return null; - } - - @Override - public void executeCustomAction(CustomActionType customActionType) { - - } - - @Override - public boolean canHandleDST() { - return false; - } - - @Override - public void timeDateOrTimeZoneChanged() { - - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt new file mode 100644 index 0000000000..fdfb55ca5a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt @@ -0,0 +1,658 @@ +package info.nightscout.androidaps.plugins.pump.danaRS + +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.content.ServiceConnection +import android.os.IBinder +import android.text.format.DateFormat +import androidx.preference.Preference +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.BuildConfig +import info.nightscout.androidaps.R +import info.nightscout.androidaps.data.DetailedBolusInfo +import info.nightscout.androidaps.data.Profile +import info.nightscout.androidaps.data.PumpEnactResult +import info.nightscout.androidaps.events.EventAppExit +import info.nightscout.androidaps.events.EventConfigBuilderChange +import info.nightscout.androidaps.interfaces.* +import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.common.ManufacturerType +import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction +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.events.EventDismissNotification +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.bolusInfo.DetailedBolusInfoStorage +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType +import info.nightscout.androidaps.plugins.pump.danaR.DanaRFragment +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes +import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSDeviceChange +import info.nightscout.androidaps.plugins.pump.danaRS.services.DanaRSService +import info.nightscout.androidaps.plugins.treatments.Treatment +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin +import info.nightscout.androidaps.utils.* +import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.androidaps.utils.sharedPreferences.SP +import io.reactivex.disposables.CompositeDisposable +import io.reactivex.schedulers.Schedulers +import org.json.JSONException +import org.json.JSONObject +import javax.inject.Inject +import javax.inject.Singleton +import kotlin.math.abs +import kotlin.math.max + +@Singleton +class DanaRSPlugin @Inject constructor( + injector: HasAndroidInjector, + aapsLogger: AAPSLogger, + private val rxBus: RxBusWrapper, + private val context: Context, + resourceHelper: ResourceHelper, + private val constraintChecker: ConstraintChecker, + private val profileFunction: ProfileFunction, + private val treatmentsPlugin: TreatmentsPlugin, + private val sp: SP, + commandQueue: CommandQueueProvider, + private val danaRPump: DanaRPump, + private val detailedBolusInfoStorage: DetailedBolusInfoStorage, + private val fabricPrivacy: FabricPrivacy +) : PumpPluginBase(PluginDescription() + .mainType(PluginType.PUMP) + .fragmentClass(DanaRFragment::class.java.name) + .pluginName(R.string.danarspump) + .shortName(R.string.danarspump_shortname) + .preferencesId(R.xml.pref_danars) + .description(R.string.description_pump_dana_rs), + injector, aapsLogger, resourceHelper, commandQueue +), PumpInterface, DanaRInterface, ConstraintsInterface { + + private val disposable = CompositeDisposable() + private var danaRSService: DanaRSService? = null + private var mDeviceAddress = "" + var mDeviceName = "" + private var pumpDesc = PumpDescription(PumpType.DanaRS) + + override fun updatePreferenceSummary(pref: Preference) { + super.updatePreferenceSummary(pref) + if (pref.key == resourceHelper.gs(R.string.key_danars_name)) pref.summary = sp.getString(R.string.key_danars_name, "") + } + + override fun onStart() { + super.onStart() + val intent = Intent(context, DanaRSService::class.java) + context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE) + disposable.add(rxBus + .toObservable(EventAppExit::class.java) + .observeOn(Schedulers.io()) + .subscribe({ context.unbindService(mConnection) }) { fabricPrivacy.logException(it) } + ) + disposable.add(rxBus + .toObservable(EventConfigBuilderChange::class.java) + .observeOn(Schedulers.io()) + .subscribe { danaRPump.reset() } + ) + disposable.add(rxBus + .toObservable(EventDanaRSDeviceChange::class.java) + .observeOn(Schedulers.io()) + .subscribe({ changePump() }) { fabricPrivacy.logException(it) } + ) + changePump() // load device name + } + + override fun onStop() { + context.unbindService(mConnection) + disposable.clear() + super.onStop() + } + + private val mConnection: ServiceConnection = object : ServiceConnection { + override fun onServiceDisconnected(name: ComponentName) { + aapsLogger.debug(LTag.PUMP, "Service is disconnected") + danaRSService = null + } + + override fun onServiceConnected(name: ComponentName, service: IBinder) { + aapsLogger.debug(LTag.PUMP, "Service is connected") + val mLocalBinder = service as DanaRSService.LocalBinder + danaRSService = mLocalBinder.serviceInstance + } + } + + fun changePump() { + mDeviceAddress = sp.getString(R.string.key_danars_address, "") + mDeviceName = sp.getString(R.string.key_danars_name, "") + danaRPump.reset() + commandQueue.readStatus("DeviceChanged", null) + } + + override fun connect(from: String) { + aapsLogger.debug(LTag.PUMP, "RS connect from: $from") + if (danaRSService != null && mDeviceAddress != "" && mDeviceName != "") { + val success = danaRSService?.connect(from, mDeviceAddress) ?: false + if (!success) ToastUtils.showToastInUiThread(context, resourceHelper.gs(R.string.rileylink_scanner_ble_not_supported)) + } + } + + override fun isConnected(): Boolean { + return danaRSService?.isConnected ?: false + } + + override fun isConnecting(): Boolean { + return danaRSService?.isConnecting ?: false + } + + override fun isHandshakeInProgress(): Boolean { + return false + } + + override fun finishHandshaking() {} + override fun disconnect(from: String) { + aapsLogger.debug(LTag.PUMP, "RS disconnect from: $from") + danaRSService?.disconnect(from) + } + + override fun stopConnecting() { + danaRSService?.stopConnecting() + } + + override fun getPumpStatus() { + danaRSService?.readPumpStatus() + pumpDesc.basalStep = danaRPump.basalStep + pumpDesc.bolusStep = danaRPump.bolusStep + } + + // DanaR interface + override fun loadHistory(type: Byte): PumpEnactResult { + return danaRSService?.loadHistory(type) ?: PumpEnactResult(injector).success(false) + } + + override fun loadEvents(): PumpEnactResult { + return danaRSService?.loadEvents() ?: PumpEnactResult(injector).success(false) + } + + override fun setUserOptions(): PumpEnactResult { + return danaRSService?.setUserSettings() ?: PumpEnactResult(injector).success(false) + } + + // Constraints interface + override fun applyBasalConstraints(absoluteRate: Constraint, profile: Profile): Constraint { + absoluteRate.setIfSmaller(aapsLogger, danaRPump.maxBasal, resourceHelper.gs(R.string.limitingbasalratio, danaRPump.maxBasal, resourceHelper.gs(R.string.pumplimit)), this) + return absoluteRate + } + + override fun applyBasalPercentConstraints(percentRate: Constraint, profile: Profile): Constraint { + percentRate.setIfGreater(aapsLogger, 0, resourceHelper.gs(R.string.limitingpercentrate, 0, resourceHelper.gs(R.string.itmustbepositivevalue)), this) + percentRate.setIfSmaller(aapsLogger, pumpDescription.maxTempPercent, resourceHelper.gs(R.string.limitingpercentrate, pumpDescription.maxTempPercent, resourceHelper.gs(R.string.pumplimit)), this) + return percentRate + } + + override fun applyBolusConstraints(insulin: Constraint): Constraint { + insulin.setIfSmaller(aapsLogger, danaRPump.maxBolus, resourceHelper.gs(R.string.limitingbolus, danaRPump.maxBolus, resourceHelper.gs(R.string.pumplimit)), this) + return insulin + } + + override fun applyExtendedBolusConstraints(insulin: Constraint): Constraint { + return applyBolusConstraints(insulin) + } + + // Pump interface + override fun isInitialized(): Boolean { + return danaRPump.lastConnection > 0 && danaRPump.maxBasal > 0 + } + + override fun isSuspended(): Boolean { + return danaRPump.pumpSuspended + } + + override fun isBusy(): Boolean { + return danaRSService?.isConnected ?: false || danaRSService?.isConnecting ?: false + } + + override fun setNewBasalProfile(profile: Profile): PumpEnactResult { + val result = PumpEnactResult(injector) + if (!isInitialized) { + aapsLogger.error("setNewBasalProfile not initialized") + val notification = Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, resourceHelper.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT) + rxBus.send(EventNewNotification(notification)) + result.comment = resourceHelper.gs(R.string.pumpNotInitializedProfileNotSet) + return result + } else { + rxBus.send(EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)) + } + return if (danaRSService?.updateBasalsInPump(profile) != true) { + val notification = Notification(Notification.FAILED_UDPATE_PROFILE, resourceHelper.gs(R.string.failedupdatebasalprofile), Notification.URGENT) + rxBus.send(EventNewNotification(notification)) + result.comment = resourceHelper.gs(R.string.failedupdatebasalprofile) + result + } else { + rxBus.send(EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)) + rxBus.send(EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)) + val notification = Notification(Notification.PROFILE_SET_OK, resourceHelper.gs(R.string.profile_set_ok), Notification.INFO, 60) + rxBus.send(EventNewNotification(notification)) + result.success = true + result.enacted = true + result.comment = "OK" + result + } + } + + override fun isThisProfileSet(profile: Profile): Boolean { + if (!isInitialized) return true // TODO: not sure what's better. so far TRUE to prevent too many SMS + if (danaRPump.pumpProfiles == null) return true // TODO: not sure what's better. so far TRUE to prevent too many SMS + val basalValues = if (danaRPump.basal48Enable) 48 else 24 + val basalIncrement = if (danaRPump.basal48Enable) 30 * 60 else 60 * 60 + for (h in 0 until basalValues) { + val pumpValue = danaRPump.pumpProfiles!![danaRPump.activeProfile][h] + val profileValue = profile.getBasalTimeFromMidnight(h * basalIncrement) + if (abs(pumpValue - profileValue) > pumpDescription.basalStep) { + aapsLogger.debug(LTag.PUMP, "Diff found. Hour: $h Pump: $pumpValue Profile: $profileValue") + return false + } + } + return true + } + + override fun lastDataTime(): Long { + return danaRPump.lastConnection + } + + override fun getBaseBasalRate(): Double { + return danaRPump.currentBasal + } + + override fun getReservoirLevel(): Double { + return danaRPump.reservoirRemainingUnits + } + + override fun getBatteryLevel(): Int { + return danaRPump.batteryRemaining + } + + @Synchronized + override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { + detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(Constraint(detailedBolusInfo.insulin)).value() + return if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) { + val preferencesSpeed = sp.getInt(R.string.key_danars_bolusspeed, 0) + var speed = 12 + when (preferencesSpeed) { + 0 -> speed = 12 + 1 -> speed = 30 + 2 -> speed = 60 + } + // RS stores end time for bolus, we need to adjust time + // default delivery speed is 12 sec/U + detailedBolusInfo.date = DateUtil.now() + (speed * detailedBolusInfo.insulin * 1000).toLong() + // clean carbs to prevent counting them as twice because they will picked up as another record + // I don't think it's necessary to copy DetailedBolusInfo right now for carbs records + val carbs = detailedBolusInfo.carbs + detailedBolusInfo.carbs = 0.0 + var carbTime = detailedBolusInfo.carbTime + if (carbTime == 0) carbTime-- // better set 1 min back to prevents clash with insulin + detailedBolusInfo.carbTime = 0 + detailedBolusInfoStorage.add(detailedBolusInfo) // will be picked up on reading history + val t = Treatment() + t.isSMB = detailedBolusInfo.isSMB + var connectionOK = false + if (detailedBolusInfo.insulin > 0 || carbs > 0) connectionOK = danaRSService?.bolus(detailedBolusInfo.insulin, carbs.toInt(), DateUtil.now() + T.mins(carbTime.toLong()).msecs(), t) ?: false + val result = PumpEnactResult(injector) + result.success = connectionOK && abs(detailedBolusInfo.insulin - t.insulin) < pumpDesc.bolusStep + result.bolusDelivered = t.insulin + result.carbsDelivered = detailedBolusInfo.carbs + if (!result.success) { + var error = "" + danaRPump.bolusStartErrorCode + when (danaRPump.bolusStartErrorCode) { + 0x10 -> error = resourceHelper.gs(R.string.maxbolusviolation) + 0x20 -> error = resourceHelper.gs(R.string.commanderror) + 0x40 -> error = resourceHelper.gs(R.string.speederror) + 0x80 -> error = resourceHelper.gs(R.string.insulinlimitviolation) + } + result.comment = String.format(resourceHelper.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, error) + } else result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered) + result + } else { + val result = PumpEnactResult(injector) + result.success = false + result.bolusDelivered = 0.0 + result.carbsDelivered = 0.0 + result.comment = resourceHelper.gs(R.string.danar_invalidinput) + aapsLogger.error("deliverTreatment: Invalid input") + result + } + } + + override fun stopBolusDelivering() { + danaRSService?.bolusStop() + } + + // This is called from APS + @Synchronized + override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean): PumpEnactResult { + var result = PumpEnactResult(injector) + val absoluteAfterConstrain = constraintChecker.applyBasalConstraints(Constraint(absoluteRate), profile).value() + val doTempOff = baseBasalRate - absoluteAfterConstrain == 0.0 + val doLowTemp = absoluteAfterConstrain < baseBasalRate + val doHighTemp = absoluteAfterConstrain > baseBasalRate + if (doTempOff) { + // If temp in progress + if (treatmentsPlugin.isTempBasalInProgress) { + aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Stopping temp basal (doTempOff)") + return cancelTempBasal(false) + } + result.success = true + result.enacted = false + result.percent = 100 + result.isPercent = true + result.isTempCancel = true + aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: doTempOff OK") + return result + } + if (doLowTemp || doHighTemp) { + var percentRate = java.lang.Double.valueOf(absoluteAfterConstrain / baseBasalRate * 100).toInt() + percentRate = if (percentRate < 100) Round.ceilTo(percentRate.toDouble(), 10.0).toInt() else Round.floorTo(percentRate.toDouble(), 10.0).toInt() + if (percentRate > 500) // Special high temp 500/15min + percentRate = 500 + // Check if some temp is already in progress + val activeTemp = treatmentsPlugin.getTempBasalFromHistory(System.currentTimeMillis()) + if (activeTemp != null) { + aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: currently running: $activeTemp") + // Correct basal already set ? + if (activeTemp.percentRate == percentRate && activeTemp.plannedRemainingMinutes > 4) { + if (!enforceNew) { + result.success = true + result.percent = percentRate + result.enacted = false + result.duration = activeTemp.plannedRemainingMinutes + result.isPercent = true + result.isTempCancel = false + aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Correct temp basal already set (doLowTemp || doHighTemp)") + return result + } + } + } + // Convert duration from minutes to hours + aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Setting temp basal $percentRate% for $durationInMinutes mins (doLowTemp || doHighTemp)") + result = if (percentRate == 0 && durationInMinutes > 30) { + setTempBasalPercent(percentRate, durationInMinutes, profile, enforceNew) + } else { + // use special APS temp basal call ... 100+/15min .... 100-/30min + setHighTempBasalPercent(percentRate) + } + if (!result.success) { + aapsLogger.error("setTempBasalAbsolute: Failed to set hightemp basal") + return result + } + aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: hightemp basal set ok") + return result + } + // We should never end here + aapsLogger.error("setTempBasalAbsolute: Internal error") + result.success = false + result.comment = "Internal error" + return result + } + + @Synchronized + override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean): PumpEnactResult { + val pump = danaRPump + val result = PumpEnactResult(injector) + var percentAfterConstraint = constraintChecker.applyBasalPercentConstraints(Constraint(percent), profile).value() + if (percentAfterConstraint < 0) { + result.isTempCancel = false + result.enacted = false + result.success = false + result.comment = resourceHelper.gs(R.string.danar_invalidinput) + aapsLogger.error("setTempBasalPercent: Invalid input") + return result + } + if (percentAfterConstraint > pumpDescription.maxTempPercent) percentAfterConstraint = pumpDescription.maxTempPercent + val now = System.currentTimeMillis() + val activeTemp = treatmentsPlugin.getTempBasalFromHistory(now) + if (activeTemp != null && activeTemp.percentRate == percentAfterConstraint && activeTemp.plannedRemainingMinutes > 4 && !enforceNew) { + result.enacted = false + result.success = true + result.isTempCancel = false + result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + result.duration = pump.tempBasalRemainingMin + result.percent = pump.tempBasalPercent + result.isPercent = true + aapsLogger.debug(LTag.PUMP, "setTempBasalPercent: Correct value already set") + return result + } + val connectionOK: Boolean + connectionOK = if (durationInMinutes == 15 || durationInMinutes == 30) { + danaRSService?.tempBasalShortDuration(percentAfterConstraint, durationInMinutes) ?: false + } else { + val durationInHours = max(durationInMinutes / 60, 1) + danaRSService?.tempBasal(percentAfterConstraint, durationInHours) ?: false + } + if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percentAfterConstraint) { + result.enacted = true + result.success = true + result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + result.isTempCancel = false + result.duration = pump.tempBasalRemainingMin + result.percent = pump.tempBasalPercent + result.isPercent = true + aapsLogger.debug(LTag.PUMP, "setTempBasalPercent: OK") + return result + } + result.enacted = false + result.success = false + result.comment = resourceHelper.gs(R.string.tempbasaldeliveryerror) + aapsLogger.error("setTempBasalPercent: Failed to set temp basal") + return result + } + + @Synchronized private fun setHighTempBasalPercent(percent: Int): PumpEnactResult { + val pump = danaRPump + val result = PumpEnactResult(injector) + val connectionOK = danaRSService?.highTempBasal(percent) ?: false + if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) { + result.enacted = true + result.success = true + result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + result.isTempCancel = false + result.duration = pump.tempBasalRemainingMin + result.percent = pump.tempBasalPercent + result.isPercent = true + aapsLogger.debug(LTag.PUMP, "setHighTempBasalPercent: OK") + return result + } + result.enacted = false + result.success = false + result.comment = resourceHelper.gs(R.string.danar_valuenotsetproperly) + aapsLogger.error("setHighTempBasalPercent: Failed to set temp basal") + return result + } + + @Synchronized + override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult { + val pump = danaRPump + var insulinAfterConstraint = constraintChecker.applyExtendedBolusConstraints(Constraint(insulin)).value() + // needs to be rounded + val durationInHalfHours = max(durationInMinutes / 30, 1) + insulinAfterConstraint = Round.roundTo(insulinAfterConstraint, pumpDescription.extendedBolusStep) + val result = PumpEnactResult(injector) + val runningEB = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis()) + if (runningEB != null && abs(runningEB.insulin - insulinAfterConstraint) < pumpDescription.extendedBolusStep) { + result.enacted = false + result.success = true + result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + result.duration = pump.extendedBolusRemainingMinutes + result.absolute = pump.extendedBolusAbsoluteRate + result.isPercent = false + result.isTempCancel = false + aapsLogger.debug(LTag.PUMP, "setExtendedBolus: Correct extended bolus already set. Current: " + pump.extendedBolusAmount + " Asked: " + insulinAfterConstraint) + return result + } + val connectionOK = danaRSService?.extendedBolus(insulinAfterConstraint, durationInHalfHours) ?: false + if (connectionOK && pump.isExtendedInProgress && abs(pump.extendedBolusAbsoluteRate - insulinAfterConstraint) < pumpDescription.extendedBolusStep) { + result.enacted = true + result.success = true + result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + result.isTempCancel = false + result.duration = pump.extendedBolusRemainingMinutes + result.absolute = pump.extendedBolusAbsoluteRate + result.bolusDelivered = pump.extendedBolusAmount + result.isPercent = false + aapsLogger.debug(LTag.PUMP, "setExtendedBolus: OK") + return result + } + result.enacted = false + result.success = false + result.comment = resourceHelper.gs(R.string.danar_valuenotsetproperly) + aapsLogger.error("setExtendedBolus: Failed to extended bolus") + return result + } + + @Synchronized + override fun cancelTempBasal(force: Boolean): PumpEnactResult { + val result = PumpEnactResult(injector) + val runningTB = treatmentsPlugin.getTempBasalFromHistory(System.currentTimeMillis()) + if (runningTB != null) { + danaRSService?.tempBasalStop() + result.enacted = true + result.isTempCancel = true + } + return if (!danaRPump.isTempBasalInProgress) { + result.success = true + result.isTempCancel = true + result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + aapsLogger.debug(LTag.PUMP, "cancelRealTempBasal: OK") + result + } else { + result.success = false + result.comment = resourceHelper.gs(R.string.danar_valuenotsetproperly) + result.isTempCancel = true + aapsLogger.error("cancelRealTempBasal: Failed to cancel temp basal") + result + } + } + + @Synchronized override fun cancelExtendedBolus(): PumpEnactResult { + val result = PumpEnactResult(injector) + val runningEB = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis()) + if (runningEB != null) { + danaRSService?.extendedBolusStop() + result.enacted = true + result.isTempCancel = true + } + return if (!danaRPump.isExtendedInProgress) { + result.success = true + result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + aapsLogger.debug(LTag.PUMP, "cancelExtendedBolus: OK") + result + } else { + result.success = false + result.comment = resourceHelper.gs(R.string.danar_valuenotsetproperly) + aapsLogger.error("cancelExtendedBolus: Failed to cancel extended bolus") + result + } + } + + override fun getJSONStatus(profile: Profile, profileName: String): JSONObject { + val pump = danaRPump + val now = System.currentTimeMillis() + if (pump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) { + return JSONObject() + } + val pumpJson = JSONObject() + val battery = JSONObject() + val status = JSONObject() + val extended = JSONObject() + try { + battery.put("percent", pump.batteryRemaining) + status.put("status", if (pump.pumpSuspended) "suspended" else "normal") + status.put("timestamp", DateUtil.toISOString(pump.lastConnection)) + extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION) + if (pump.lastBolusTime != 0L) { + extended.put("LastBolus", DateUtil.dateAndTimeString(pump.lastBolusTime)) + extended.put("LastBolusAmount", pump.lastBolusAmount) + } + val tb = treatmentsPlugin.getTempBasalFromHistory(now) + if (tb != null) { + extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile)) + extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date)) + extended.put("TempBasalRemaining", tb.plannedRemainingMinutes) + } + val eb = treatmentsPlugin.getExtendedBolusFromHistory(now) + if (eb != null) { + extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()) + extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)) + extended.put("ExtendedBolusRemaining", eb.plannedRemainingMinutes) + } + extended.put("BaseBasalRate", baseBasalRate) + try { + extended.put("ActiveProfile", profileFunction.getProfileName()) + } catch (e: Exception) { + aapsLogger.error("Unhandled exception", e) + } + pumpJson.put("battery", battery) + pumpJson.put("status", status) + pumpJson.put("extended", extended) + pumpJson.put("reservoir", pump.reservoirRemainingUnits.toInt()) + pumpJson.put("clock", DateUtil.toISOString(now)) + } catch (e: JSONException) { + aapsLogger.error("Unhandled exception", e) + } + return pumpJson + } + + override fun manufacturer(): ManufacturerType { + return ManufacturerType.Sooil + } + + override fun model(): PumpType { + return PumpType.DanaRS + } + + override fun serialNumber(): String { + return danaRPump.serialNumber + } + + override fun getPumpDescription(): PumpDescription { + return pumpDesc + } + + override fun shortStatus(veryShort: Boolean): String { + val pump = danaRPump + var ret = "" + if (pump.lastConnection != 0L) { + val agoMillis = System.currentTimeMillis() - pump.lastConnection + val agoMin = (agoMillis / 60.0 / 1000.0).toInt() + ret += "LastConn: $agoMin minago\n" + } + if (pump.lastBolusTime != 0L) + ret += "LastBolus: ${DecimalFormatter.to2Decimal(pump.lastBolusAmount)}U @${DateFormat.format("HH:mm", pump.lastBolusTime)}" + + val activeTemp = treatmentsPlugin.getRealTempBasalFromHistory(System.currentTimeMillis()) + if (activeTemp != null) + ret += "Temp: ${activeTemp.toStringFull()}" + + val activeExtendedBolus = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis()) + if (activeExtendedBolus != null) + ret += "Extended: $activeExtendedBolus\n" + + if (!veryShort) { + ret += "TDD: ${DecimalFormatter.to0Decimal(pump.dailyTotalUnits)} / ${pump.maxDailyTotalUnits} U" + } + ret += "Reserv: ${DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits)} U" + ret += "Batt: ${pump.batteryRemaining}" + return ret + } + + override fun isFakingTempsByExtendedBoluses(): Boolean = false + override fun loadTDDs(): PumpEnactResult = loadHistory(RecordTypes.RECORD_TYPE_DAILY) + override fun getCustomActions(): List? = null + override fun executeCustomAction(customActionType: CustomActionType) {} + override fun canHandleDST(): Boolean = false + override fun timeDateOrTimeZoneChanged() {} +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt index 2f3b8b170a..4f3d86c51d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt @@ -18,7 +18,6 @@ class DanaRSMessageHashTable @Inject constructor( rxBus: RxBusWrapper, resourceHelper: ResourceHelper, danaRPump: DanaRPump, - danaRSPlugin: DanaRSPlugin, activePlugin: ActivePluginProvider, constraintChecker: ConstraintChecker, detailedBolusInfoStorage: DetailedBolusInfoStorage @@ -62,16 +61,16 @@ class DanaRSMessageHashTable @Inject constructor( put(DanaRS_Packet_Bolus_Set_Dual_Bolus(aapsLogger)) put(DanaRS_Packet_Bolus_Set_Extended_Bolus(aapsLogger)) put(DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel(aapsLogger)) - put(DanaRS_Packet_Bolus_Set_Step_Bolus_Start(aapsLogger, danaRSPlugin, constraintChecker)) - put(DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(aapsLogger, rxBus, resourceHelper, danaRSPlugin)) + put(DanaRS_Packet_Bolus_Set_Step_Bolus_Start(aapsLogger, danaRPump, constraintChecker)) + put(DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(aapsLogger, rxBus, resourceHelper, danaRPump)) put(DanaRS_Packet_Etc_Keep_Connection(aapsLogger)) put(DanaRS_Packet_Etc_Set_History_Save(aapsLogger)) put(DanaRS_Packet_General_Delivery_Status(aapsLogger)) put(DanaRS_Packet_General_Get_Password(aapsLogger, danaRPump)) put(DanaRS_Packet_General_Initial_Screen_Information(aapsLogger, danaRPump)) put(DanaRS_Packet_Notify_Alarm(aapsLogger, resourceHelper, rxBus)) - put(DanaRS_Packet_Notify_Delivery_Complete(aapsLogger, rxBus, resourceHelper, danaRSPlugin)) - put(DanaRS_Packet_Notify_Delivery_Rate_Display(aapsLogger, rxBus, resourceHelper, danaRSPlugin)) + put(DanaRS_Packet_Notify_Delivery_Complete(aapsLogger, rxBus, resourceHelper, danaRPump)) + put(DanaRS_Packet_Notify_Delivery_Rate_Display(aapsLogger, rxBus, resourceHelper, danaRPump)) put(DanaRS_Packet_Notify_Missed_Bolus_Alarm(aapsLogger)) put(DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump)) put(DanaRS_Packet_Option_Get_User_Option(aapsLogger, danaRPump)) @@ -99,7 +98,7 @@ class DanaRSMessageHashTable @Inject constructor( put(DanaRS_Packet_History_Temporary(aapsLogger, rxBus)) // APS put(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, 0)) - put(DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, detailedBolusInfoStorage, 0)) + put(DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, 0)) put(DanaRS_Packet_APS_Set_Event_History(aapsLogger, 0, 0, 0, 0)) // v3 put(DanaRS_Packet_General_Get_Shipping_Version(aapsLogger, danaRPump)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt index 27b88c1380..97700ba30e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt @@ -1,6 +1,5 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.R import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.db.ExtendedBolus @@ -13,7 +12,7 @@ import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump -import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.resources.ResourceHelper import java.util.* @@ -23,7 +22,7 @@ open class DanaRS_Packet_APS_History_Events( private val rxBus: RxBusWrapper, private val resourceHelper: ResourceHelper, private val activePlugin: ActivePluginProvider, - private val danaRSPlugin: DanaRSPlugin, + private val danaRPump: DanaRPump, private val detailedBolusInfoStorage: DetailedBolusInfoStorage, private var from: Long ) : DanaRS_Packet() { @@ -50,7 +49,7 @@ open class DanaRS_Packet_APS_History_Events( min = cal[Calendar.MINUTE] sec = cal[Calendar.SECOND] aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + DateUtil.dateAndTimeString(cal.timeInMillis)) - danaRSPlugin.apsHistoryDone = false + danaRPump.historyDoneReceived = false } override fun getRequestParams(): ByteArray { @@ -68,7 +67,7 @@ open class DanaRS_Packet_APS_History_Events( val recordCode = intFromBuff(data, 0, 1).toByte() // Last record if (recordCode == 0xFF.toByte()) { - danaRSPlugin.apsHistoryDone = true + danaRPump.historyDoneReceived = true aapsLogger.debug(LTag.PUMPCOMM, "Last record received") return } @@ -191,7 +190,7 @@ open class DanaRS_Packet_APS_History_Events( status = "UNKNOWN " + DateUtil.timeString(datetime) } } - if (datetime > danaRSPlugin.lastEventTimeLoaded) danaRSPlugin.lastEventTimeLoaded = datetime + if (datetime > danaRPump.lastEventTimeLoaded) danaRPump.lastEventTimeLoaded = datetime rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.processinghistory) + ": " + status)) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt index ef14999e22..d9dc8f0d95 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt @@ -1,15 +1,15 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker -import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Bolus_Set_Step_Bolus_Start( private val aapsLogger: AAPSLogger, - private val danaRSPlugin: DanaRSPlugin, + private val danaRPump: DanaRPump, constraintChecker: ConstraintChecker, private var amount: Double = 0.0, private var speed: Int = 0 @@ -34,12 +34,12 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_Start( } override fun handleMessage(data: ByteArray) { - danaRSPlugin.bolusStartErrorCode = intFromBuff(data, 0, 1) - if (danaRSPlugin.bolusStartErrorCode == 0) { + danaRPump.bolusStartErrorCode = intFromBuff(data, 0, 1) + if (danaRPump.bolusStartErrorCode == 0) { failed = false aapsLogger.debug(LTag.PUMPCOMM, "Result OK") } else { - aapsLogger.error("Result Error: ${danaRSPlugin.bolusStartErrorCode}") + aapsLogger.error("Result Error: ${danaRPump.bolusStartErrorCode}") failed = true } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt index 462d639a0c..c5c1ace3b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt @@ -1,19 +1,19 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress -import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.resources.ResourceHelper open class DanaRS_Packet_Bolus_Set_Step_Bolus_Stop( private val aapsLogger: AAPSLogger, private val rxBus: RxBusWrapper, private val resourceHelper: ResourceHelper, - private val danaRSPlugin: DanaRSPlugin + private val danaRPump: DanaRPump ) : DanaRS_Packet() { @@ -31,10 +31,10 @@ open class DanaRS_Packet_Bolus_Set_Step_Bolus_Stop( failed = true } val bolusingEvent = EventOverviewBolusProgress - danaRSPlugin.bolusStopped = true - if (!danaRSPlugin.bolusStopForced) { + danaRPump.bolusStopped = true + if (!danaRPump.bolusStopForced) { // delivery ended without user intervention - danaRSPlugin.bolusingTreatment.insulin = danaRSPlugin.bolusAmountToBeDelivered + danaRPump.bolusingTreatment?.insulin = danaRPump.bolusAmountToBeDelivered bolusingEvent.status = resourceHelper.gs(R.string.overview_bolusprogress_delivered) bolusingEvent.percent = 100 } else { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt index 03d884933b..c4e5d5a06d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress -import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.resources.ResourceHelper import kotlin.math.min @@ -14,7 +14,7 @@ class DanaRS_Packet_Notify_Delivery_Complete( private val aapsLogger: AAPSLogger, private val rxBus: RxBusWrapper, private val resourceHelper: ResourceHelper, - private val danaRSPlugin: DanaRSPlugin + private val danaRPump: DanaRPump ) : DanaRS_Packet() { init { @@ -25,12 +25,12 @@ class DanaRS_Packet_Notify_Delivery_Complete( override fun handleMessage(data: ByteArray) { val deliveredInsulin = byteArrayToInt(getBytes(data, DATA_START, 2)) / 100.0 - danaRSPlugin.bolusingTreatment.insulin = deliveredInsulin + danaRPump.bolusingTreatment?.insulin = deliveredInsulin val bolusingEvent = EventOverviewBolusProgress bolusingEvent.status = resourceHelper.gs(R.string.bolusdelivering, deliveredInsulin) - bolusingEvent.t = danaRSPlugin.bolusingTreatment - bolusingEvent.percent = min((deliveredInsulin / danaRSPlugin.bolusAmountToBeDelivered * 100).toInt(), 100) - danaRSPlugin.bolusDone = true + bolusingEvent.t = danaRPump.bolusingTreatment + bolusingEvent.percent = min((deliveredInsulin / danaRPump.bolusAmountToBeDelivered * 100).toInt(), 100) + danaRPump.bolusDone = true rxBus.send(bolusingEvent) aapsLogger.debug(LTag.PUMPCOMM, "Delivered insulin: $deliveredInsulin") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt index a63bad6f23..0a256ed088 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress -import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.resources.ResourceHelper import kotlin.math.min @@ -14,7 +14,7 @@ class DanaRS_Packet_Notify_Delivery_Rate_Display( private val aapsLogger: AAPSLogger, private val rxBus: RxBusWrapper, private val resourceHelper: ResourceHelper, - private val danaRSPlugin: DanaRSPlugin + private val danaRPump: DanaRPump ) : DanaRS_Packet() { @@ -25,12 +25,12 @@ class DanaRS_Packet_Notify_Delivery_Rate_Display( override fun handleMessage(data: ByteArray) { val deliveredInsulin = byteArrayToInt(getBytes(data, DATA_START, 2)) / 100.0 - danaRSPlugin.bolusProgressLastTimeStamp = System.currentTimeMillis() - danaRSPlugin.bolusingTreatment.insulin = deliveredInsulin + danaRPump.bolusProgressLastTimeStamp = System.currentTimeMillis() + danaRPump.bolusingTreatment?.insulin = deliveredInsulin val bolusingEvent = EventOverviewBolusProgress bolusingEvent.status = resourceHelper.gs(R.string.bolusdelivering, deliveredInsulin) - bolusingEvent.t = danaRSPlugin.bolusingTreatment - bolusingEvent.percent = min((deliveredInsulin / danaRSPlugin.bolusAmountToBeDelivered * 100).toInt(), 100) + bolusingEvent.t = danaRPump.bolusingTreatment + bolusingEvent.percent = min((deliveredInsulin / danaRPump.bolusAmountToBeDelivered * 100).toInt(), 100) failed = bolusingEvent.percent < 100 rxBus.send(bolusingEvent) aapsLogger.debug(LTag.PUMPCOMM, "Delivered insulin so far: $deliveredInsulin") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt index 9145cb6559..e691156d0d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt @@ -615,9 +615,8 @@ class BLEComm @Inject internal constructor( } // the rest of packets - fun sendMessage(message: DanaRS_Packet?) { + fun sendMessage(message: DanaRS_Packet) { processedMessage = message - if (message == null) return val command = byteArrayOf(message.type.toByte(), message.opCode.toByte()) val params = message.requestParams aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + message.friendlyName + " " + DanaRS_Packet.toHexString(command) + " " + DanaRS_Packet.toHexString(params)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java deleted file mode 100644 index 4affd0d7c1..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java +++ /dev/null @@ -1,565 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS.services; - -import android.content.Context; -import android.content.Intent; -import android.os.Binder; -import android.os.IBinder; -import android.os.SystemClock; - -import javax.inject.Inject; - -import dagger.android.DaggerService; -import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.Constants; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.activities.ErrorHelperActivity; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.data.PumpEnactResult; -import info.nightscout.androidaps.dialogs.BolusProgressDialog; -import info.nightscout.androidaps.events.EventAppExit; -import info.nightscout.androidaps.events.EventInitializationChanged; -import info.nightscout.androidaps.events.EventProfileNeedsUpdate; -import info.nightscout.androidaps.events.EventPumpStatusChanged; -import info.nightscout.androidaps.interfaces.ActivePluginProvider; -import info.nightscout.androidaps.interfaces.CommandQueueProvider; -import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.plugins.bus.RxBusWrapper; -import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker; -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction; -import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; -import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; -import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; -import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage; -import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; -import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes; -import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus; -import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSMessageHashTable; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_APS_Basal_Set_Temporary_Basal; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_APS_History_Events; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_APS_Set_Event_History; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Get_Basal_Rate; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Get_Profile_Number; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Get_Temporary_Basal_State; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Set_Profile_Basal_Rate; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Set_Profile_Number; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Set_Temporary_Basal; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Get_Bolus_Option; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Get_CIR_CF_Array; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Get_Calculation_Information; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Get_Extended_Bolus_State; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Get_Step_Bolus_Information; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Set_Extended_Bolus; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Stop; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_General_Get_Pump_Check; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_General_Get_Shipping_Information; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_General_Initial_Screen_Information; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_General_Set_History_Upload_Mode; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Alarm; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Basal; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Blood_Glucose; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Bolus; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Carbohydrate; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Daily; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Prime; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Refill; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Suspend; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Option_Get_Pump_Time; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Option_Get_User_Option; -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Option_Set_Pump_Time; -import info.nightscout.androidaps.plugins.treatments.Treatment; -import info.nightscout.androidaps.queue.Callback; -import info.nightscout.androidaps.queue.commands.Command; -import info.nightscout.androidaps.utils.DateUtil; -import info.nightscout.androidaps.utils.FabricPrivacy; -import info.nightscout.androidaps.utils.T; -import info.nightscout.androidaps.utils.resources.ResourceHelper; -import info.nightscout.androidaps.utils.sharedPreferences.SP; -import io.reactivex.disposables.CompositeDisposable; -import io.reactivex.schedulers.Schedulers; - -public class DanaRSService extends DaggerService { - @Inject HasAndroidInjector injector; - @Inject AAPSLogger aapsLogger; - @Inject RxBusWrapper rxBus; - @Inject SP sp; - @Inject ResourceHelper resourceHelper; - @Inject ProfileFunction profileFunction; - @Inject CommandQueueProvider commandQueue; - @Inject Context context; - @Inject DanaRSPlugin danaRSPlugin; - @Inject DanaRPump danaRPump; - @Inject DanaRSMessageHashTable danaRSMessageHashTable; - @Inject ActivePluginProvider activePlugin; - @Inject ConstraintChecker constraintChecker; - @Inject DetailedBolusInfoStorage detailedBolusInfoStorage; - @Inject BLEComm bleComm; - @Inject FabricPrivacy fabricPrivacy; - - private CompositeDisposable disposable = new CompositeDisposable(); - - - private IBinder mBinder = new LocalBinder(); - - private Treatment bolusingTreatment = null; - - private long lastHistoryFetched = 0; - private long lastApproachingDailyLimit = 0; - - @Override - public void onCreate() { - super.onCreate(); - disposable.add(rxBus - .toObservable(EventAppExit.class) - .observeOn(Schedulers.io()) - .subscribe(event -> { - aapsLogger.debug(LTag.PUMPCOMM, "EventAppExit received"); - stopSelf(); - }, fabricPrivacy::logException) - ); - } - - @Override - public void onDestroy() { - disposable.clear(); - super.onDestroy(); - } - - public boolean isConnected() { - return bleComm.isConnected(); - } - - public boolean isConnecting() { - return bleComm.isConnecting(); - } - - public boolean connect(String from, String address) { - return bleComm.connect(from, address); - } - - public void stopConnecting() { - bleComm.stopConnecting(); - } - - public void disconnect(String from) { - bleComm.disconnect(from); - } - - @SuppressWarnings("unused") - public void sendMessage(DanaRS_Packet message) { - bleComm.sendMessage(message); - } - - public void getPumpStatus() { - try { - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpstatus))); - - bleComm.sendMessage(new DanaRS_Packet_General_Initial_Screen_Information(aapsLogger, danaRPump)); - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingextendedbolusstatus))); - bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Extended_Bolus_State(aapsLogger, danaRPump)); - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingbolusstatus))); - bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump)); // last bolus, bolusStep, maxBolus - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingtempbasalstatus))); - bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)); - - danaRPump.setLastConnection(System.currentTimeMillis()); - - Profile profile = profileFunction.getProfile(); - PumpInterface pump = activePlugin.getActivePump(); - if (profile != null && Math.abs(danaRPump.getCurrentBasal() - profile.getBasal()) >= pump.getPumpDescription().basalStep) { - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpsettings))); - bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Basal_Rate(aapsLogger, rxBus, resourceHelper, danaRPump)); // basal profile, basalStep, maxBasal - if (!pump.isThisProfileSet(profile) && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE)) { - rxBus.send(new EventProfileNeedsUpdate()); - } - } - - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumptime))); - bleComm.sendMessage(new DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump)); - - long timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L; - if (danaRPump.getPumpTime() == 0) { - // initial handshake was not successfull - // deinitialize pump - danaRPump.reset(); - rxBus.send(new EventDanaRNewStatus()); - rxBus.send(new EventInitializationChanged()); - return; - } - long now = System.currentTimeMillis(); - if (danaRPump.getLastSettingsRead() + 60 * 60 * 1000L < now || !pump.isInitialized()) { - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpsettings))); - bleComm.sendMessage(new DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump)); // serial no - bleComm.sendMessage(new DanaRS_Packet_General_Get_Pump_Check(aapsLogger, danaRPump, rxBus, resourceHelper)); // firmware - bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Profile_Number(aapsLogger, danaRPump)); - bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Bolus_Option(aapsLogger, rxBus, resourceHelper, danaRPump)); // isExtendedEnabled - bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Basal_Rate(aapsLogger, rxBus, resourceHelper, danaRPump)); // basal profile, basalStep, maxBasal - bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Calculation_Information(aapsLogger, danaRPump)); // target - bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_CIR_CF_Array(aapsLogger, danaRPump)); - bleComm.sendMessage(new DanaRS_Packet_Option_Get_User_Option(aapsLogger, danaRPump)); // Getting user options - danaRPump.setLastSettingsRead(now); - } - - aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: " + timeDiff + " seconds"); - if (Math.abs(timeDiff) > 3) { - if (Math.abs(timeDiff) > 60 * 60 * 1.5) { - aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: " + timeDiff + " seconds - large difference"); - //If time-diff is very large, warn user until we can synchronize history readings properly - Intent i = new Intent(context, ErrorHelperActivity.class); - i.putExtra("soundid", R.raw.error); - i.putExtra("status", resourceHelper.gs(R.string.largetimediff)); - i.putExtra("title", resourceHelper.gs(R.string.largetimedifftitle)); - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(i); - - //deinitialize pump - danaRPump.reset(); - rxBus.send(new EventDanaRNewStatus()); - rxBus.send(new EventInitializationChanged()); - return; - } else { - if (danaRPump.getProtocol() >= 6) { - bleComm.sendMessage(new DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, DateUtil.now())); - } else { - waitForWholeMinute(); // Dana can set only whole minute - // add 10sec to be sure we are over minute (will be cutted off anyway) - bleComm.sendMessage(new DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, DateUtil.now() + T.secs(10).msecs())); - } - bleComm.sendMessage(new DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump)); - timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L; - aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: " + timeDiff + " seconds"); - } - } - - loadEvents(); - - rxBus.send(new EventDanaRNewStatus()); - rxBus.send(new EventInitializationChanged()); - //NSUpload.uploadDeviceStatus(); - if (danaRPump.getDailyTotalUnits() > danaRPump.getMaxDailyTotalUnits() * Constants.dailyLimitWarning) { - aapsLogger.debug(LTag.PUMPCOMM, "Approaching daily limit: " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits()); - if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { - Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT); - rxBus.send(new EventNewNotification(reportFail)); - NSUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits() + "U"); - lastApproachingDailyLimit = System.currentTimeMillis(); - } - } - } catch (Exception e) { - aapsLogger.error(LTag.PUMPCOMM, "Unhandled exception", e); - } - aapsLogger.debug(LTag.PUMPCOMM, "Pump status loaded"); - } - - public PumpEnactResult loadEvents() { - - if (!danaRSPlugin.isInitialized()) { - PumpEnactResult result = new PumpEnactResult(injector).success(false); - result.comment = "pump not initialized"; - return result; - } - - SystemClock.sleep(1000); - - DanaRS_Packet_APS_History_Events msg; - if (lastHistoryFetched == 0) { - msg = new DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, detailedBolusInfoStorage, 0); - aapsLogger.debug(LTag.PUMPCOMM, "Loading complete event history"); - } else { - msg = new DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, detailedBolusInfoStorage, lastHistoryFetched); - aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + DateUtil.dateAndTimeString(lastHistoryFetched)); - } - bleComm.sendMessage(msg); - while (!danaRSPlugin.apsHistoryDone && bleComm.isConnected()) { - SystemClock.sleep(100); - } - if (danaRSPlugin.lastEventTimeLoaded != 0) - lastHistoryFetched = danaRSPlugin.lastEventTimeLoaded - T.mins(1).msecs(); - else - lastHistoryFetched = 0; - aapsLogger.debug(LTag.PUMPCOMM, "Events loaded"); - danaRPump.setLastConnection(System.currentTimeMillis()); - return new PumpEnactResult(injector).success(true); - } - - - public PumpEnactResult setUserSettings() { - bleComm.sendMessage(new DanaRS_Packet_Option_Get_User_Option(aapsLogger, danaRPump)); - return new PumpEnactResult(injector).success(true); - } - - - public boolean bolus(final double insulin, int carbs, long carbtime, Treatment t) { - if (!isConnected()) return false; - if (BolusProgressDialog.stopPressed) return false; - - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.startingbolus))); - bolusingTreatment = t; - final int preferencesSpeed = sp.getInt(R.string.key_danars_bolusspeed, 0); - danaRSPlugin.bolusingTreatment = t; - danaRSPlugin.bolusAmountToBeDelivered = insulin; - danaRSPlugin.bolusStopped = false; - danaRSPlugin.bolusStopForced = false; - danaRSPlugin.bolusProgressLastTimeStamp = DateUtil.now(); - - DanaRS_Packet_Bolus_Set_Step_Bolus_Start start = new DanaRS_Packet_Bolus_Set_Step_Bolus_Start(aapsLogger, danaRSPlugin, constraintChecker, insulin, preferencesSpeed); - if (carbs > 0) { -// MsgSetCarbsEntry msg = new MsgSetCarbsEntry(carbtime, carbs); #### -// bleComm.sendMessage(msg); - DanaRS_Packet_APS_Set_Event_History msgSetHistoryEntry_v2 = new DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, carbtime, carbs, 0); - bleComm.sendMessage(msgSetHistoryEntry_v2); - lastHistoryFetched = Math.min(lastHistoryFetched, carbtime - T.mins(1).msecs()); - } - - final long bolusStart = System.currentTimeMillis(); - if (insulin > 0) { - if (!danaRSPlugin.bolusStopped) { - bleComm.sendMessage(start); - } else { - t.insulin = 0d; - return false; - } - - while (!danaRSPlugin.bolusStopped && !start.failed && !danaRSPlugin.bolusDone) { - SystemClock.sleep(100); - if ((System.currentTimeMillis() - danaRSPlugin.bolusProgressLastTimeStamp) > 15 * 1000L) { // if i didn't receive status for more than 20 sec expecting broken comm - danaRSPlugin.bolusStopped = true; - danaRSPlugin.bolusStopForced = true; - aapsLogger.debug(LTag.PUMPCOMM, "Communication stopped"); - } - } - } - - final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE; - bolusingEvent.setT(t); - bolusingEvent.setPercent(99); - - bolusingTreatment = null; - int speed = 12; - switch (preferencesSpeed) { - case 0: - speed = 12; - break; - case 1: - speed = 30; - break; - case 2: - speed = 60; - break; - } - long bolusDurationInMSec = (long) (insulin * speed * 1000); - long expectedEnd = bolusStart + bolusDurationInMSec + 2000; - while (System.currentTimeMillis() < expectedEnd) { - long waitTime = expectedEnd - System.currentTimeMillis(); - bolusingEvent.setStatus(String.format(resourceHelper.gs(R.string.waitingforestimatedbolusend), waitTime / 1000)); - rxBus.send(bolusingEvent); - SystemClock.sleep(1000); - } - // do not call loadEvents() directly, reconnection may be needed - commandQueue.loadEvents(new Callback() { - @Override - public void run() { - // reread bolus status - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingbolusstatus))); - bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump)); // last bolus - bolusingEvent.setPercent(100); - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.disconnecting))); - } - }); - return !start.failed; - } - - public void bolusStop() { - aapsLogger.debug(LTag.PUMPCOMM, "bolusStop >>>>> @ " + (bolusingTreatment == null ? "" : bolusingTreatment.insulin)); - DanaRS_Packet_Bolus_Set_Step_Bolus_Stop stop = new DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(aapsLogger, rxBus, resourceHelper, danaRSPlugin); - danaRSPlugin.bolusStopForced = true; - if (isConnected()) { - bleComm.sendMessage(stop); - while (!danaRSPlugin.bolusStopped) { - bleComm.sendMessage(stop); - SystemClock.sleep(200); - } - } else { - danaRSPlugin.bolusStopped = true; - } - } - - public boolean tempBasal(Integer percent, int durationInHours) { - if (!isConnected()) return false; - if (danaRPump.isTempBasalInProgress()) { - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal))); - bleComm.sendMessage(new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger)); - SystemClock.sleep(500); - } - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))); - bleComm.sendMessage(new DanaRS_Packet_Basal_Set_Temporary_Basal(aapsLogger, percent, durationInHours)); - SystemClock.sleep(200); - bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)); - loadEvents(); - rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); - return true; - } - - public boolean highTempBasal(Integer percent) { - if (danaRPump.isTempBasalInProgress()) { - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal))); - bleComm.sendMessage(new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger)); - SystemClock.sleep(500); - } - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))); - bleComm.sendMessage(new DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, percent)); - bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)); - loadEvents(); - rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); - return true; - } - - public boolean tempBasalShortDuration(Integer percent, int durationInMinutes) { - if (durationInMinutes != 15 && durationInMinutes != 30) { - aapsLogger.error(LTag.PUMPCOMM, "Wrong duration param"); - return false; - } - - if (danaRPump.isTempBasalInProgress()) { - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal))); - bleComm.sendMessage(new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger)); - SystemClock.sleep(500); - } - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))); - bleComm.sendMessage(new DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, percent)); - bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)); - loadEvents(); - rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); - return true; - } - - public boolean tempBasalStop() { - if (!isConnected()) return false; - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal))); - bleComm.sendMessage(new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger)); - bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)); - loadEvents(); - rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); - return true; - } - - public boolean extendedBolus(Double insulin, int durationInHalfHours) { - if (!isConnected()) return false; - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingextendedbolus))); - bleComm.sendMessage(new DanaRS_Packet_Bolus_Set_Extended_Bolus(aapsLogger, insulin, durationInHalfHours)); - SystemClock.sleep(200); - bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Extended_Bolus_State(aapsLogger, danaRPump)); - loadEvents(); - rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); - return true; - } - - public boolean extendedBolusStop() { - if (!isConnected()) return false; - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingextendedbolus))); - bleComm.sendMessage(new DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel(aapsLogger)); - bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Extended_Bolus_State(aapsLogger, danaRPump)); - loadEvents(); - rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); - return true; - } - - public boolean updateBasalsInPump(Profile profile) { - if (!isConnected()) return false; - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.updatingbasalrates))); - Double[] basal = danaRPump.buildDanaRProfileRecord(profile); - DanaRS_Packet_Basal_Set_Profile_Basal_Rate msgSet = new DanaRS_Packet_Basal_Set_Profile_Basal_Rate(aapsLogger, 0, basal); - bleComm.sendMessage(msgSet); - DanaRS_Packet_Basal_Set_Profile_Number msgActivate = new DanaRS_Packet_Basal_Set_Profile_Number(aapsLogger, 0); - bleComm.sendMessage(msgActivate); - danaRPump.setLastSettingsRead(0); // force read full settings - getPumpStatus(); - rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); - return true; - } - - public PumpEnactResult loadHistory(byte type) { - PumpEnactResult result = new PumpEnactResult(injector); - if (!isConnected()) return result; - DanaRS_Packet_History_ msg = null; - switch (type) { - case RecordTypes.RECORD_TYPE_ALARM: - msg = new DanaRS_Packet_History_Alarm(aapsLogger, rxBus); - break; - case RecordTypes.RECORD_TYPE_PRIME: - msg = new DanaRS_Packet_History_Prime(aapsLogger, rxBus); - break; - case RecordTypes.RECORD_TYPE_BASALHOUR: - msg = new DanaRS_Packet_History_Basal(aapsLogger, rxBus); - break; - case RecordTypes.RECORD_TYPE_BOLUS: - msg = new DanaRS_Packet_History_Bolus(aapsLogger, rxBus); - break; - case RecordTypes.RECORD_TYPE_CARBO: - msg = new DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus); - break; - case RecordTypes.RECORD_TYPE_DAILY: - msg = new DanaRS_Packet_History_Daily(aapsLogger, rxBus); - break; - case RecordTypes.RECORD_TYPE_GLUCOSE: - msg = new DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus); - break; - case RecordTypes.RECORD_TYPE_REFILL: - msg = new DanaRS_Packet_History_Refill(aapsLogger, rxBus); - break; - case RecordTypes.RECORD_TYPE_SUSPEND: - msg = new DanaRS_Packet_History_Suspend(aapsLogger, rxBus); - break; - } - if (msg != null) { - bleComm.sendMessage(new DanaRS_Packet_General_Set_History_Upload_Mode(aapsLogger, 1)); - SystemClock.sleep(200); - bleComm.sendMessage(msg); - while (!msg.getDone() && isConnected()) { - SystemClock.sleep(100); - } - SystemClock.sleep(200); - bleComm.sendMessage(new DanaRS_Packet_General_Set_History_Upload_Mode(aapsLogger, 0)); - } - result.success = true; - result.comment = "OK"; - return result; - } - - - public class LocalBinder extends Binder { - public DanaRSService getServiceInstance() { - return DanaRSService.this; - } - - } - - @Override - public IBinder onBind(Intent intent) { - return mBinder; - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - return START_STICKY; - } - - void waitForWholeMinute() { - while (true) { - long time = DateUtil.now(); - long timeToWholeMinute = (60000 - time % 60000); - if (timeToWholeMinute > 59800 || timeToWholeMinute < 300) - break; - rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.waitingfortimesynchronization, (int) (timeToWholeMinute / 1000)))); - SystemClock.sleep(Math.min(timeToWholeMinute, 100)); - } - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt new file mode 100644 index 0000000000..1497904916 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt @@ -0,0 +1,462 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.services + +import android.app.Service +import android.content.Context +import android.content.Intent +import android.os.Binder +import android.os.IBinder +import android.os.SystemClock +import dagger.android.DaggerService +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.Constants +import info.nightscout.androidaps.R +import info.nightscout.androidaps.activities.ErrorHelperActivity +import info.nightscout.androidaps.data.Profile +import info.nightscout.androidaps.data.PumpEnactResult +import info.nightscout.androidaps.dialogs.BolusProgressDialog +import info.nightscout.androidaps.events.EventAppExit +import info.nightscout.androidaps.events.EventInitializationChanged +import info.nightscout.androidaps.events.EventProfileNeedsUpdate +import info.nightscout.androidaps.events.EventPumpStatusChanged +import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.interfaces.CommandQueueProvider +import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification +import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification +import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes +import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus +import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin +import info.nightscout.androidaps.plugins.pump.danaRS.comm.* +import info.nightscout.androidaps.plugins.treatments.Treatment +import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.T +import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.androidaps.utils.sharedPreferences.SP +import io.reactivex.disposables.CompositeDisposable +import io.reactivex.schedulers.Schedulers +import javax.inject.Inject +import kotlin.math.abs +import kotlin.math.min + +class DanaRSService : DaggerService() { + @Inject lateinit var injector: HasAndroidInjector + @Inject lateinit var aapsLogger: AAPSLogger + @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var sp: SP + @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var profileFunction: ProfileFunction + @Inject lateinit var commandQueue: CommandQueueProvider + @Inject lateinit var context: Context + @Inject lateinit var danaRSPlugin: DanaRSPlugin + @Inject lateinit var danaRPump: DanaRPump + @Inject lateinit var danaRSMessageHashTable: DanaRSMessageHashTable + @Inject lateinit var activePlugin: ActivePluginProvider + @Inject lateinit var constraintChecker: ConstraintChecker + @Inject lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage + @Inject lateinit var bleComm: BLEComm + @Inject lateinit var fabricPrivacy: FabricPrivacy + + private val disposable = CompositeDisposable() + private val mBinder: IBinder = LocalBinder() + private var bolusingTreatment: Treatment? = null + private var lastHistoryFetched: Long = 0 + private var lastApproachingDailyLimit: Long = 0 + + override fun onCreate() { + super.onCreate() + disposable.add(rxBus + .toObservable(EventAppExit::class.java) + .observeOn(Schedulers.io()) + .subscribe({ stopSelf() }) { fabricPrivacy.logException(it) } + ) + } + + override fun onDestroy() { + disposable.clear() + super.onDestroy() + } + + val isConnected: Boolean + get() = bleComm.isConnected + + val isConnecting: Boolean + get() = bleComm.isConnecting + + fun connect(from: String, address: String): Boolean { + return bleComm.connect(from, address) + } + + fun stopConnecting() { + bleComm.stopConnecting() + } + + fun disconnect(from: String) { + bleComm.disconnect(from) + } + + fun sendMessage(message: DanaRS_Packet) { + bleComm.sendMessage(message) + } + + fun readPumpStatus() { + try { + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpstatus))) + sendMessage(DanaRS_Packet_General_Initial_Screen_Information(aapsLogger, danaRPump)) + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingextendedbolusstatus))) + sendMessage(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(aapsLogger, danaRPump)) + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingbolusstatus))) + sendMessage(DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump)) // last bolus, bolusStep, maxBolus + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingtempbasalstatus))) + sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)) + danaRPump.lastConnection = System.currentTimeMillis() + val profile = profileFunction.getProfile() + val pump = activePlugin.activePump + if (profile != null && abs(danaRPump.currentBasal - profile.basal) >= pump.pumpDescription.basalStep) { + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpsettings))) + sendMessage(DanaRS_Packet_Basal_Get_Basal_Rate(aapsLogger, rxBus, resourceHelper, danaRPump)) // basal profile, basalStep, maxBasal + if (!pump.isThisProfileSet(profile) && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE)) { + rxBus.send(EventProfileNeedsUpdate()) + } + } + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumptime))) + sendMessage(DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump)) + var timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L + if (danaRPump.pumpTime == 0L) { + // initial handshake was not successful + // de-initialize pump + danaRPump.reset() + rxBus.send(EventDanaRNewStatus()) + rxBus.send(EventInitializationChanged()) + return + } + val now = System.currentTimeMillis() + if (danaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized) { + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpsettings))) + sendMessage(DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump)) // serial no + sendMessage(DanaRS_Packet_General_Get_Pump_Check(aapsLogger, danaRPump, rxBus, resourceHelper)) // firmware + sendMessage(DanaRS_Packet_Basal_Get_Profile_Number(aapsLogger, danaRPump)) + sendMessage(DanaRS_Packet_Bolus_Get_Bolus_Option(aapsLogger, rxBus, resourceHelper, danaRPump)) // isExtendedEnabled + sendMessage(DanaRS_Packet_Basal_Get_Basal_Rate(aapsLogger, rxBus, resourceHelper, danaRPump)) // basal profile, basalStep, maxBasal + sendMessage(DanaRS_Packet_Bolus_Get_Calculation_Information(aapsLogger, danaRPump)) // target + sendMessage(DanaRS_Packet_Bolus_Get_CIR_CF_Array(aapsLogger, danaRPump)) + sendMessage(DanaRS_Packet_Option_Get_User_Option(aapsLogger, danaRPump)) // Getting user options + danaRPump.lastSettingsRead = now + } + aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: $timeDiff seconds") + if (abs(timeDiff) > 3) { + if (abs(timeDiff) > 60 * 60 * 1.5) { + aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: $timeDiff seconds - large difference") + //If time-diff is very large, warn user until we can synchronize history readings properly + val i = Intent(context, ErrorHelperActivity::class.java) + i.putExtra("soundid", R.raw.error) + i.putExtra("status", resourceHelper.gs(R.string.largetimediff)) + i.putExtra("title", resourceHelper.gs(R.string.largetimedifftitle)) + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + context.startActivity(i) + + //de-initialize pump + danaRPump.reset() + rxBus.send(EventDanaRNewStatus()) + rxBus.send(EventInitializationChanged()) + return + } else { + if (danaRPump.protocol >= 6) { + sendMessage(DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, DateUtil.now())) + } else { + waitForWholeMinute() // Dana can set only whole minute + // add 10sec to be sure we are over minute (will be cut off anyway) + sendMessage(DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, DateUtil.now() + T.secs(10).msecs())) + } + sendMessage(DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump)) + timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L + aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: $timeDiff seconds") + } + } + loadEvents() + rxBus.send(EventDanaRNewStatus()) + rxBus.send(EventInitializationChanged()) + //NSUpload.uploadDeviceStatus(); + if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) { + aapsLogger.debug(LTag.PUMPCOMM, "Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits) + if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { + val reportFail = Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT) + rxBus.send(EventNewNotification(reportFail)) + NSUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U") + lastApproachingDailyLimit = System.currentTimeMillis() + } + } + } catch (e: Exception) { + aapsLogger.error(LTag.PUMPCOMM, "Unhandled exception", e) + } + aapsLogger.debug(LTag.PUMPCOMM, "Pump status loaded") + } + + fun loadEvents(): PumpEnactResult { + if (!danaRSPlugin.isInitialized) { + val result = PumpEnactResult(injector).success(false) + result.comment = "pump not initialized" + return result + } + SystemClock.sleep(1000) + val msg: DanaRS_Packet_APS_History_Events + if (lastHistoryFetched == 0L) { + msg = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, 0) + aapsLogger.debug(LTag.PUMPCOMM, "Loading complete event history") + } else { + msg = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, lastHistoryFetched) + aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + DateUtil.dateAndTimeString(lastHistoryFetched)) + } + sendMessage(msg) + while (!danaRPump.historyDoneReceived && bleComm.isConnected) { + SystemClock.sleep(100) + } + lastHistoryFetched = if (danaRPump.lastEventTimeLoaded != 0L) danaRPump.lastEventTimeLoaded - T.mins(1).msecs() else 0 + aapsLogger.debug(LTag.PUMPCOMM, "Events loaded") + danaRPump.lastConnection = System.currentTimeMillis() + return PumpEnactResult(injector).success(true) + } + + fun setUserSettings(): PumpEnactResult { + sendMessage(DanaRS_Packet_Option_Get_User_Option(aapsLogger, danaRPump)) + return PumpEnactResult(injector).success(true) + } + + fun bolus(insulin: Double, carbs: Int, carbTime: Long, t: Treatment): Boolean { + if (!isConnected) return false + if (BolusProgressDialog.stopPressed) return false + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.startingbolus))) + bolusingTreatment = t + val preferencesSpeed = sp.getInt(R.string.key_danars_bolusspeed, 0) + danaRPump.bolusingTreatment = t + danaRPump.bolusAmountToBeDelivered = insulin + danaRPump.bolusStopped = false + danaRPump.bolusStopForced = false + danaRPump.bolusProgressLastTimeStamp = DateUtil.now() + val start = DanaRS_Packet_Bolus_Set_Step_Bolus_Start(aapsLogger, danaRPump, constraintChecker, insulin, preferencesSpeed) + if (carbs > 0) { +// MsgSetCarbsEntry msg = new MsgSetCarbsEntry(carbTime, carbs); #### +// sendMessage(msg); + val msgSetHistoryEntryV2 = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, carbTime, carbs, 0) + sendMessage(msgSetHistoryEntryV2) + lastHistoryFetched = min(lastHistoryFetched, carbTime - T.mins(1).msecs()) + } + val bolusStart = System.currentTimeMillis() + if (insulin > 0) { + if (!danaRPump.bolusStopped) { + sendMessage(start) + } else { + t.insulin = 0.0 + return false + } + while (!danaRPump.bolusStopped && !start.failed && !danaRPump.bolusDone) { + SystemClock.sleep(100) + if (System.currentTimeMillis() - danaRPump.bolusProgressLastTimeStamp > 15 * 1000L) { // if i didn't receive status for more than 20 sec expecting broken comm + danaRPump.bolusStopped = true + danaRPump.bolusStopForced = true + aapsLogger.debug(LTag.PUMPCOMM, "Communication stopped") + } + } + } + val bolusingEvent = EventOverviewBolusProgress + bolusingEvent.t = t + bolusingEvent.percent = 99 + bolusingTreatment = null + var speed = 12 + when (preferencesSpeed) { + 0 -> speed = 12 + 1 -> speed = 30 + 2 -> speed = 60 + } + val bolusDurationInMSec = (insulin * speed * 1000).toLong() + val expectedEnd = bolusStart + bolusDurationInMSec + 2000 + while (System.currentTimeMillis() < expectedEnd) { + val waitTime = expectedEnd - System.currentTimeMillis() + bolusingEvent.status = String.format(resourceHelper.gs(R.string.waitingforestimatedbolusend), waitTime / 1000) + rxBus.send(bolusingEvent) + SystemClock.sleep(1000) + } + // do not call loadEvents() directly, reconnection may be needed + commandQueue.loadEvents(object : Callback() { + override fun run() { + // reread bolus status + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingbolusstatus))) + sendMessage(DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump)) // last bolus + bolusingEvent.percent = 100 + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.disconnecting))) + } + }) + return !start.failed + } + + fun bolusStop() { + aapsLogger.debug(LTag.PUMPCOMM, "bolusStop >>>>> @ " + if (bolusingTreatment == null) "" else bolusingTreatment?.insulin) + val stop = DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(aapsLogger, rxBus, resourceHelper, danaRPump) + danaRPump.bolusStopForced = true + if (isConnected) { + sendMessage(stop) + while (!danaRPump.bolusStopped) { + sendMessage(stop) + SystemClock.sleep(200) + } + } else { + danaRPump.bolusStopped = true + } + } + + fun tempBasal(percent: Int, durationInHours: Int): Boolean { + if (!isConnected) return false + if (danaRPump.isTempBasalInProgress) { + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal))) + sendMessage(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger)) + SystemClock.sleep(500) + } + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))) + sendMessage(DanaRS_Packet_Basal_Set_Temporary_Basal(aapsLogger, percent, durationInHours)) + SystemClock.sleep(200) + sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)) + loadEvents() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) + return true + } + + fun highTempBasal(percent: Int): Boolean { + if (danaRPump.isTempBasalInProgress) { + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal))) + sendMessage(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger)) + SystemClock.sleep(500) + } + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))) + sendMessage(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, percent)) + sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)) + loadEvents() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) + return true + } + + fun tempBasalShortDuration(percent: Int, durationInMinutes: Int): Boolean { + if (durationInMinutes != 15 && durationInMinutes != 30) { + aapsLogger.error(LTag.PUMPCOMM, "Wrong duration param") + return false + } + if (danaRPump.isTempBasalInProgress) { + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal))) + sendMessage(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger)) + SystemClock.sleep(500) + } + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))) + sendMessage(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, percent)) + sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)) + loadEvents() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) + return true + } + + fun tempBasalStop(): Boolean { + if (!isConnected) return false + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal))) + sendMessage(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger)) + sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)) + loadEvents() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) + return true + } + + fun extendedBolus(insulin: Double, durationInHalfHours: Int): Boolean { + if (!isConnected) return false + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingextendedbolus))) + sendMessage(DanaRS_Packet_Bolus_Set_Extended_Bolus(aapsLogger, insulin, durationInHalfHours)) + SystemClock.sleep(200) + sendMessage(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(aapsLogger, danaRPump)) + loadEvents() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) + return true + } + + fun extendedBolusStop(): Boolean { + if (!isConnected) return false + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingextendedbolus))) + sendMessage(DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel(aapsLogger)) + sendMessage(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(aapsLogger, danaRPump)) + loadEvents() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) + return true + } + + fun updateBasalsInPump(profile: Profile): Boolean { + if (!isConnected) return false + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.updatingbasalrates))) + val basal = danaRPump.buildDanaRProfileRecord(profile) + val msgSet = DanaRS_Packet_Basal_Set_Profile_Basal_Rate(aapsLogger, 0, basal) + sendMessage(msgSet) + val msgActivate = DanaRS_Packet_Basal_Set_Profile_Number(aapsLogger, 0) + sendMessage(msgActivate) + danaRPump.lastSettingsRead = 0 // force read full settings + readPumpStatus() + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) + return true + } + + fun loadHistory(type: Byte): PumpEnactResult { + val result = PumpEnactResult(injector) + if (!isConnected) return result + var msg: DanaRS_Packet_History_? = null + when (type) { + RecordTypes.RECORD_TYPE_ALARM -> msg = DanaRS_Packet_History_Alarm(aapsLogger, rxBus) + RecordTypes.RECORD_TYPE_PRIME -> msg = DanaRS_Packet_History_Prime(aapsLogger, rxBus) + RecordTypes.RECORD_TYPE_BASALHOUR -> msg = DanaRS_Packet_History_Basal(aapsLogger, rxBus) + RecordTypes.RECORD_TYPE_BOLUS -> msg = DanaRS_Packet_History_Bolus(aapsLogger, rxBus) + RecordTypes.RECORD_TYPE_CARBO -> msg = DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus) + RecordTypes.RECORD_TYPE_DAILY -> msg = DanaRS_Packet_History_Daily(aapsLogger, rxBus) + RecordTypes.RECORD_TYPE_GLUCOSE -> msg = DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus) + RecordTypes.RECORD_TYPE_REFILL -> msg = DanaRS_Packet_History_Refill(aapsLogger, rxBus) + RecordTypes.RECORD_TYPE_SUSPEND -> msg = DanaRS_Packet_History_Suspend(aapsLogger, rxBus) + } + if (msg != null) { + sendMessage(DanaRS_Packet_General_Set_History_Upload_Mode(aapsLogger, 1)) + SystemClock.sleep(200) + sendMessage(msg) + while (!msg.done && isConnected) { + SystemClock.sleep(100) + } + SystemClock.sleep(200) + sendMessage(DanaRS_Packet_General_Set_History_Upload_Mode(aapsLogger, 0)) + } + result.success = true + result.comment = "OK" + return result + } + + inner class LocalBinder : Binder() { + val serviceInstance: DanaRSService + get() = this@DanaRSService + } + + override fun onBind(intent: Intent): IBinder { + return mBinder + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + return Service.START_STICKY + } + + private fun waitForWholeMinute() { + while (true) { + val time = DateUtil.now() + val timeToWholeMinute = 60000 - time % 60000 + if (timeToWholeMinute > 59800 || timeToWholeMinute < 300) break + rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.waitingfortimesynchronization, (timeToWholeMinute / 1000).toInt()))) + SystemClock.sleep(min(timeToWholeMinute, 100)) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java index e783d13d78..46785fb900 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java @@ -188,7 +188,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { result.bolusDelivered = t.insulin; result.carbsDelivered = detailedBolusInfo.carbs; if (!result.success) - result.comment = String.format(resourceHelper.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, danaRPump.getMessageStartErrorCode()); + result.comment = String.format(resourceHelper.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, danaRPump.getBolusStartErrorCode()); else result.comment = resourceHelper.gs(R.string.virtualpump_resultok); aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt index 7896cbc234..0ebefe9403 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -16,10 +16,9 @@ import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) +@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class, DanaRSPlugin::class) class DanaRSMessageHashTableTest : DanaRSTestBase() { - @Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage @@ -28,7 +27,7 @@ class DanaRSMessageHashTableTest : DanaRSTestBase() { fun runTest() { `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) - val danaRSMessageHashTable = DanaRSMessageHashTable(aapsLogger, rxBus, resourceHelper, danaRPump, danaRSPlugin, activePlugin, constraintChecker, detailedBolusInfoStorage) + val danaRSMessageHashTable = DanaRSMessageHashTable(aapsLogger, rxBus, resourceHelper, danaRPump, activePlugin, constraintChecker, detailedBolusInfoStorage) val forTesting: DanaRS_Packet = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, 0, 0, 0) val testPacket: DanaRS_Packet = danaRSMessageHashTable.findMessage(forTesting.command) Assert.assertEquals(BleEncryption.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY.toLong(), testPacket.getOpCode().toLong()) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt index 1072c72e09..2b88f1c450 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt @@ -14,17 +14,16 @@ import org.powermock.modules.junit4.PowerMockRunner import java.util.* @RunWith(PowerMockRunner::class) -@PrepareForTest(RxBusWrapper::class, DetailedBolusInfoStorage::class) +@PrepareForTest(RxBusWrapper::class, DetailedBolusInfoStorage::class, DanaRSPlugin::class) class DanaRS_Packet_APS_History_EventsTest : DanaRSTestBase() { @Mock lateinit var activePlugin: ActivePluginProvider - @Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage @Test fun runTest() { val now = DateUtil.now() - val testPacket = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, detailedBolusInfoStorage, now) + val testPacket = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, now) // test getRequestedParams val returnedValues = testPacket.requestParams val expectedValues = getCalender(now) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt index 7b5b94522f..9420b1f7b6 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt @@ -31,7 +31,7 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() { private lateinit var danaRSPlugin: DanaRSPlugin @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Set_Step_Bolus_Start(aapsLogger, danaRSPlugin, constraintChecker) + val packet = DanaRS_Packet_Bolus_Set_Step_Bolus_Start(aapsLogger, danaRPump, constraintChecker) // test params val testparams = packet.requestParams Assert.assertEquals(0.toByte(), testparams[0]) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt index d4854c12cd..70276dc23b 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt @@ -18,13 +18,12 @@ import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest(RxBusWrapper::class) +@PrepareForTest(RxBusWrapper::class, DanaRSPlugin::class) class DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest : DanaRSTestBase() { @Mock lateinit var defaultValueHelper: DefaultValueHelper @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var activePlugin: ActivePluginProvider - @Mock lateinit var danaRSPlugin: DanaRSPlugin private var treatmentInjector: HasAndroidInjector = HasAndroidInjector { AndroidInjector { @@ -40,8 +39,8 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest : DanaRSTestBase() { @Test fun runTest() { `when`(resourceHelper.gs(Mockito.anyInt())).thenReturn("SomeString") - danaRSPlugin.bolusingTreatment = Treatment(treatmentInjector) - val testPacket = DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(aapsLogger, rxBus, resourceHelper, danaRSPlugin) + danaRPump.bolusingTreatment = Treatment(treatmentInjector) + val testPacket = DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(aapsLogger, rxBus, resourceHelper, danaRPump) // test message decoding testPacket.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte())) Assert.assertEquals(false, testPacket.failed) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt index a7246493e6..b3c3317e4d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt @@ -19,11 +19,10 @@ import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest(RxBusWrapper::class) +@PrepareForTest(RxBusWrapper::class, DanaRSPlugin::class) class DanaRS_Packet_Notify_Delivery_CompleteTest : DanaRSTestBase() { @Mock lateinit var defaultValueHelper: DefaultValueHelper - @Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var activePlugin: ActivePluginProvider @@ -41,13 +40,13 @@ class DanaRS_Packet_Notify_Delivery_CompleteTest : DanaRSTestBase() { @Test fun runTest() { `when`(resourceHelper.gs(anyInt(), anyDouble())).thenReturn("SomeString") - danaRSPlugin.bolusingTreatment = Treatment(treatmentInjector) - val packet = DanaRS_Packet_Notify_Delivery_Complete(aapsLogger, rxBus, resourceHelper, danaRSPlugin) + danaRPump.bolusingTreatment = Treatment(treatmentInjector) + val packet = DanaRS_Packet_Notify_Delivery_Complete(aapsLogger, rxBus, resourceHelper, danaRPump) // test params Assert.assertEquals(null, packet.requestParams) // test message decoding packet.handleMessage(createArray(17, 0.toByte())) - Assert.assertEquals(true, danaRSPlugin.bolusDone) + Assert.assertEquals(true, danaRPump.bolusDone) Assert.assertEquals("NOTIFY__DELIVERY_COMPLETE", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt index 3d46558207..4bacb5673d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt @@ -50,7 +50,7 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() { @Test fun runTest() { `when`(resourceHelper.gs(ArgumentMatchers.anyInt(), anyObject())).thenReturn("SomeString") // val packet = DanaRS_Packet_Notify_Delivery_Rate_Display(1.0, Treatment(treatmentInjector)) - val packet = DanaRS_Packet_Notify_Delivery_Rate_Display(aapsLogger, rxBus, resourceHelper, danaRSPlugin) + val packet = DanaRS_Packet_Notify_Delivery_Rate_Display(aapsLogger, rxBus, resourceHelper, danaRPump) // test params Assert.assertEquals(null, packet.requestParams) // test message decoding @@ -66,6 +66,6 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() { @Before fun mock() { danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, fabricPrivacy) - danaRSPlugin.bolusingTreatment = Treatment(treatmentInjector) + danaRPump.bolusingTreatment = Treatment(treatmentInjector) } } \ No newline at end of file From 0fa627372550b869c734c32a0d522ca7c3bdc47c Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 29 Mar 2020 21:21:01 +0200 Subject: [PATCH 09/53] replace deprecated calls --- .../plugins/pump/danaR/comm/MsgHistoryAll.kt | 4 +- .../pump/danaR/comm/MsgSettingPumpTime.kt | 9 ++-- ...Packet_Bolus_Get_Step_Bolus_Information.kt | 36 +++++----------- ...aRS_Packet_General_Get_More_Information.kt | 40 ++++++------------ .../danaRS/comm/DanaRS_Packet_History_.kt | 31 +++++++------- .../DanaRS_Packet_Option_Get_Pump_Time.kt | 11 +++-- .../DanaRS_Packet_Option_Set_Pump_Time.kt | 18 ++++---- .../comm/MsgSetAPSTempBasalStart_v2.kt | 1 + ...et_Bolus_Get_Step_Bolus_InformationTest.kt | 29 +++++++++---- ...Packet_General_Get_More_InformationTest.kt | 36 +++++++++++----- .../comm/DanaRS_Packet_History_AlarmTest.kt | 41 +++++++++++++++++-- .../DanaRS_Packet_Option_Get_Pump_TimeTest.kt | 21 +++++----- .../DanaRS_Packet_Option_Set_Pump_TimeTest.kt | 13 +++--- 13 files changed, 163 insertions(+), 127 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt index 8c50099756..6d1d4a2bc4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt @@ -25,8 +25,8 @@ open class MsgHistoryAll( val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes val dailyBasal = intFromBuff(bytes, 4, 2) * 0.01 val dailyBolus = intFromBuff(bytes, 6, 2) * 0.01 - val paramByte5 = intFromBuff(bytes, 4, 1).toByte() - val paramByte6 = intFromBuff(bytes, 5, 1).toByte() + //val paramByte5 = intFromBuff(bytes, 4, 1).toByte() + //val paramByte6 = intFromBuff(bytes, 5, 1).toByte() val paramByte7 = intFromBuff(bytes, 6, 1).toByte() val paramByte8 = intFromBuff(bytes, 7, 1).toByte() val value = intFromBuff(bytes, 8, 2).toDouble() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTime.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTime.kt index df356ca744..07b3825b84 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTime.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTime.kt @@ -4,6 +4,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.utils.DateUtil +import org.joda.time.DateTime import java.util.* class MsgSettingPumpTime( @@ -17,14 +18,14 @@ class MsgSettingPumpTime( } override fun handleMessage(bytes: ByteArray) { - val time = Date( - 100 + intFromBuff(bytes, 5, 1), - intFromBuff(bytes, 4, 1) - 1, + val time = DateTime( + 2000 + intFromBuff(bytes, 5, 1), + intFromBuff(bytes, 4, 1), intFromBuff(bytes, 3, 1), intFromBuff(bytes, 2, 1), intFromBuff(bytes, 1, 1), intFromBuff(bytes, 0, 1) - ).time + ).millis aapsLogger.debug(LTag.PUMPCOMM, "Pump time: " + DateUtil.dateAndTimeString(time) + " Phone time: " + Date()) danaRPump.pumpTime = time } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt index 395d90b6ae..dca14ce099 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt @@ -5,6 +5,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.utils.DateUtil +import org.joda.time.DateTime import java.util.* class DanaRS_Packet_Bolus_Get_Step_Bolus_Information( @@ -18,32 +19,15 @@ class DanaRS_Packet_Bolus_Get_Step_Bolus_Information( } override fun handleMessage(data: ByteArray) { - var dataIndex = DATA_START - var dataSize = 1 - val error = byteArrayToInt(getBytes(data, dataIndex, dataSize)) - dataIndex += dataSize - dataSize = 1 - val bolusType = byteArrayToInt(getBytes(data, dataIndex, dataSize)) - dataIndex += dataSize - dataSize = 2 - danaRPump.initialBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0 - val lbt = Date() // it doesn't provide day only hour+min, workaround: expecting today - dataIndex += dataSize - dataSize = 1 - lbt.hours = byteArrayToInt(getBytes(data, dataIndex, dataSize)) - dataIndex += dataSize - dataSize = 1 - lbt.minutes = byteArrayToInt(getBytes(data, dataIndex, dataSize)) - danaRPump.lastBolusTime = lbt.time - dataIndex += dataSize - dataSize = 2 - danaRPump.lastBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0 - dataIndex += dataSize - dataSize = 2 - danaRPump.maxBolus = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0 - dataIndex += dataSize - dataSize = 1 - danaRPump.bolusStep = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0 + val error = intFromBuff(data, 0, 1) + val bolusType = intFromBuff(data, 1, 1) + danaRPump.initialBolusAmount = intFromBuff(data, 2, 2) / 100.0 + val hours = intFromBuff(data, 4, 1) + val minutes = intFromBuff(data, 5, 1) + danaRPump.lastBolusTime = DateTime.now().withHourOfDay(hours).withMinuteOfHour(minutes).millis + danaRPump.lastBolusAmount = intFromBuff(data, 6, 2) / 100.0 + danaRPump.maxBolus = intFromBuff(data, 8, 2) / 100.0 + danaRPump.bolusStep = intFromBuff(data, 10, 1) / 100.0 failed = error != 0 aapsLogger.debug(LTag.PUMPCOMM, "Result: $error") aapsLogger.debug(LTag.PUMPCOMM, "BolusType: $bolusType") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt index 875b91f397..eb7d617d3b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt @@ -1,11 +1,11 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.DateUtil -import java.util.* +import org.joda.time.DateTime class DanaRS_Packet_General_Get_More_Information( private val aapsLogger: AAPSLogger, @@ -22,37 +22,21 @@ class DanaRS_Packet_General_Get_More_Information( failed = true return } - var dataIndex = DATA_START - var dataSize = 2 - danaRPump.iob = byteArrayToInt(getBytes(data, dataIndex, dataSize)).toDouble() - dataIndex += dataSize - dataSize = 2 - danaRPump.dailyTotalUnits = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0 - dataIndex += dataSize - dataSize = 1 - danaRPump.isExtendedInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x01 - dataIndex += dataSize - dataSize = 2 - danaRPump.extendedBolusRemainingMinutes = byteArrayToInt(getBytes(data, dataIndex, dataSize)) - dataIndex += dataSize - dataSize = 2 - //val remainRate = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0 - val lastBolusTime = Date() // it doesn't provide day only hour+min, workaround: expecting today - dataIndex += dataSize - dataSize = 1 - lastBolusTime.hours = byteArrayToInt(getBytes(data, dataIndex, dataSize)) - dataIndex += dataSize - dataSize = 1 - lastBolusTime.minutes = byteArrayToInt(getBytes(data, dataIndex, dataSize)) - dataIndex += dataSize - dataSize = 2 - danaRPump.lastBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)).toDouble() + danaRPump.iob = intFromBuff(data, 0, 2) / 100.0 + danaRPump.dailyTotalUnits = intFromBuff(data, 2, 2) / 100.0 + danaRPump.isExtendedInProgress = intFromBuff(data, 4, 1) == 0x01 + danaRPump.extendedBolusRemainingMinutes = intFromBuff(data, 5, 2) + // val remainRate = intFromBuff(data, 7, 2) / 100.0 + val hours = intFromBuff(data, 9, 1) + val minutes = intFromBuff(data, 10, 1) + danaRPump.lastBolusTime = DateTime.now().withHourOfDay(hours).withMinuteOfHour(minutes).millis + danaRPump.lastBolusAmount = intFromBuff(data, 11, 2) / 100.0 // On DanaRS DailyUnits can't be more than 160 if (danaRPump.dailyTotalUnits > 160) failed = true aapsLogger.debug(LTag.PUMPCOMM, "Daily total units: " + danaRPump.dailyTotalUnits.toString() + " U") aapsLogger.debug(LTag.PUMPCOMM, "Is extended in progress: " + danaRPump.isExtendedInProgress) aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus remaining minutes: " + danaRPump.extendedBolusRemainingMinutes) - aapsLogger.debug(LTag.PUMPCOMM, "Last bolus time: " + DateUtil.dateAndTimeAndSecondsString(lastBolusTime.time)) + aapsLogger.debug(LTag.PUMPCOMM, "Last bolus time: " + DateUtil.dateAndTimeAndSecondsString(danaRPump.lastBolusTime)) aapsLogger.debug(LTag.PUMPCOMM, "Last bolus amount: " + danaRPump.lastBolusAmount) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt index e8da961028..4273f6ca0d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt @@ -8,6 +8,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus import info.nightscout.androidaps.utils.DateUtil +import org.joda.time.DateTime import java.util.* abstract class DanaRS_Packet_History_( @@ -25,6 +26,7 @@ abstract class DanaRS_Packet_History_( var done = false var totalCount = 0 + val danaRHistoryRecord = DanaRHistoryRecord() init { val cal = GregorianCalendar() @@ -79,14 +81,13 @@ abstract class DanaRS_Packet_History_( val historySecond = byteArrayToInt(getBytes(data, DATA_START + 6, 1)) val paramByte7 = historySecond.toByte() val dailyBolus: Double = ((data[DATA_START + 6].toInt() and 0xFF shl 8) + (data[DATA_START + 7].toInt() and 0xFF)) * 0.01 - val date = Date(100 + historyYear, historyMonth - 1, historyDay) - val datetime = Date(100 + historyYear, historyMonth - 1, historyDay, historyHour, historyMinute) - val datetimewihtsec = Date(100 + historyYear, historyMonth - 1, historyDay, historyHour, historyMinute, historySecond) + val date = DateTime(2000 + historyYear, historyMonth, historyDay, 0, 0) + val datetime = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute) + val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond) val historyCode = byteArrayToInt(getBytes(data, DATA_START + 7, 1)) val paramByte8 = historyCode.toByte() val value: Int = (data[DATA_START + 8].toInt() and 0xFF shl 8) + (data[DATA_START + 9].toInt() and 0xFF) - aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + DateUtil.dateAndTimeString(datetimewihtsec) + " Code: " + historyCode + " Value: " + value) - val danaRHistoryRecord = DanaRHistoryRecord() + aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + DateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value) danaRHistoryRecord.setBytes(data) // danaRHistoryRecord.recordCode is different from DanaR codes // set in switch for every type @@ -94,7 +95,7 @@ abstract class DanaRS_Packet_History_( when (recordCode) { 0x02 -> { danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_BOLUS - danaRHistoryRecord.recordDate = datetime.time + danaRHistoryRecord.recordDate = datetime.millis when (0xF0 and paramByte8.toInt()) { 0xA0 -> { danaRHistoryRecord.bolusType = "DS" @@ -125,7 +126,7 @@ abstract class DanaRS_Packet_History_( 0x03 -> { danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_DAILY messageType += "dailyinsulin" - danaRHistoryRecord.recordDate = date.time + danaRHistoryRecord.recordDate = date.millis danaRHistoryRecord.recordDailyBasal = dailyBasal danaRHistoryRecord.recordDailyBolus = dailyBolus } @@ -133,49 +134,49 @@ abstract class DanaRS_Packet_History_( 0x04 -> { danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_PRIME messageType += "prime" - danaRHistoryRecord.recordDate = datetimewihtsec.time + danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordValue = value * 0.01 } 0x05 -> { danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_REFILL messageType += "refill" - danaRHistoryRecord.recordDate = datetimewihtsec.time + danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordValue = value * 0.01 } 0x0b -> { danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_BASALHOUR messageType += "basal hour" - danaRHistoryRecord.recordDate = datetimewihtsec.time + danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordValue = value * 0.01 } 0x99 -> { danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_TEMP_BASAL messageType += "tb" - danaRHistoryRecord.recordDate = datetimewihtsec.time + danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordValue = value * 0.01 } 0x06 -> { danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_GLUCOSE messageType += "glucose" - danaRHistoryRecord.recordDate = datetimewihtsec.time + danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordValue = value.toDouble() } 0x07 -> { danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_CARBO messageType += "carbo" - danaRHistoryRecord.recordDate = datetimewihtsec.time + danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordValue = value.toDouble() } 0x0a -> { danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_ALARM messageType += "alarm" - danaRHistoryRecord.recordDate = datetimewihtsec.time + danaRHistoryRecord.recordDate = datetimewihtsec.millis var strAlarm = "None" when (paramByte8.toInt()) { 67 -> strAlarm = "Check" @@ -190,7 +191,7 @@ abstract class DanaRS_Packet_History_( 0x09 -> { danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_SUSPEND messageType += "suspend" - danaRHistoryRecord.recordDate = datetimewihtsec.time + danaRHistoryRecord.recordDate = datetimewihtsec.millis var strRecordValue = "Off" if (paramByte8.toInt() == 79) strRecordValue = "On" danaRHistoryRecord.stringRecordValue = strRecordValue diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt index b582a0b492..4db309afe0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt @@ -1,11 +1,11 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.DateUtil -import java.util.* +import org.joda.time.DateTime class DanaRS_Packet_Option_Get_Pump_Time( private val aapsLogger: AAPSLogger, @@ -36,10 +36,9 @@ class DanaRS_Packet_Option_Get_Pump_Time( dataIndex += dataSize dataSize = 1 val sec = byteArrayToInt(getBytes(data, dataIndex, dataSize)) - val time = Date(100 + year, month - 1, day, hour, min, sec) - danaRPump.pumpTime = time.time - failed = year == month && month == day && day == hour && hour == min && min == sec && sec == 1 - aapsLogger.debug(LTag.PUMPCOMM, "Pump time " + DateUtil.dateAndTimeString(time)) + val time = DateTime(2000 + year, month, day, hour, min, sec) + danaRPump.pumpTime = time.millis + aapsLogger.debug(LTag.PUMPCOMM, "Pump time " + DateUtil.dateAndTimeString(time.millis)) } override fun handleMessageNotReceived() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt index 54a38af3de..73cf49c6df 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt @@ -1,10 +1,10 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.DateUtil -import java.util.* +import org.joda.time.DateTime class DanaRS_Packet_Option_Set_Pump_Time( private val aapsLogger: AAPSLogger, @@ -19,14 +19,14 @@ class DanaRS_Packet_Option_Set_Pump_Time( } override fun getRequestParams(): ByteArray { - val date = Date(time) + val date = DateTime(time) val request = ByteArray(6) - request[0] = (date.year - 100 and 0xff).toByte() - request[1] = (date.month + 1 and 0xff).toByte() - request[2] = (date.date and 0xff).toByte() - request[3] = (date.hours and 0xff).toByte() - request[4] = (date.minutes and 0xff).toByte() - request[5] = (date.seconds and 0xff).toByte() + request[0] = (date.year - 2000 and 0xff).toByte() + request[1] = (date.monthOfYear and 0xff).toByte() + request[2] = (date.dayOfMonth and 0xff).toByte() + request[3] = (date.hourOfDay and 0xff).toByte() + request[4] = (date.minuteOfHour and 0xff).toByte() + request[5] = (date.secondOfMinute and 0xff).toByte() return request } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetAPSTempBasalStart_v2.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetAPSTempBasalStart_v2.kt index 95d2b56b77..2ff8c669ef 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetAPSTempBasalStart_v2.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetAPSTempBasalStart_v2.kt @@ -4,6 +4,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase +@Suppress("UNUSED_PARAMETER") class MsgSetAPSTempBasalStart_v2( private val aapsLogger: AAPSLogger, private var percent: Int, diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt index 86239a8ea1..c3ac9a12d6 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt @@ -5,6 +5,7 @@ import org.junit.Test import org.junit.runner.RunWith import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner +import java.util.* @RunWith(PowerMockRunner::class) @PrepareForTest() @@ -12,14 +13,26 @@ class DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest : DanaRSTestBase() { @Test fun runTest() { val packet = DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump) - Assert.assertEquals(null, packet.requestParams) - // test message decoding - packet.handleMessage(createArray(34, 0.toByte())) - Assert.assertEquals(false, packet.failed) - packet.handleMessage(createArray(34, 1.toByte())) - val valueRequested: Int = (1 and 0x000000FF shl 8) + (1 and 0x000000FF) - Assert.assertEquals(valueRequested / 100.0, danaRPump.lastBolusAmount, 0.0) - Assert.assertEquals(true, packet.failed) + + val array = createArray(13, 0.toByte()) // 11 + 2 + putByteToArray(array, 0, 2) // error 2 + putByteToArray(array, 1, 3) // bolus type 3 + putIntToArray(array, 2, 600) // initial bolus amount 6 + putByteToArray(array, 4, 13) // 13h + putByteToArray(array, 5, 20) // 20min + putIntToArray(array, 6, 1250) // last bolus amount 12.5 + putIntToArray(array, 8, 2500) // max bolus 25 + putByteToArray(array, 10, 100) // bolus step 1 + + packet.handleMessage(array) + Assert.assertTrue(packet.failed) + Assert.assertEquals(6.0, danaRPump.initialBolusAmount, 0.01) + val lastBolus = Date(danaRPump.lastBolusTime) + Assert.assertEquals(13, lastBolus.hours) + Assert.assertEquals(20, lastBolus.minutes) + Assert.assertEquals(12.5, danaRPump.lastBolusAmount, 0.01) + Assert.assertEquals(25.0, danaRPump.maxBolus, 0.01) + Assert.assertEquals(1.0, danaRPump.bolusStep, 0.01) Assert.assertEquals("BOLUS__GET_STEP_BOLUS_INFORMATION", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt index 327aa1c8a6..12ff721a2b 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt @@ -3,25 +3,39 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner +import java.util.* @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_General_Get_More_InformationTest : DanaRSTestBase() { @Test fun runTest() { var packet = DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump) - Assert.assertEquals(null, packet.requestParams) - // test message decoding - // test for the length message - packet.handleMessage(createArray(13, 0.toByte())) - Assert.assertEquals(true, packet.failed) + + packet.handleMessage(createArray(14, 0.toByte())) + Assert.assertTrue(packet.failed) + packet = DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump) - packet.handleMessage(createArray(15, 0.toByte())) - Assert.assertEquals(false, packet.failed) - packet.handleMessage(createArray(15, 161.toByte())) - Assert.assertEquals(true, packet.failed) + val array = createArray(15, 0.toByte()) // 13 + 2 + putIntToArray(array, 0, 600) // iob 6 + putIntToArray(array, 2, 1250) // daily units 12.5 + putByteToArray(array, 4, 1) // is extended in progress + putIntToArray(array, 5, 150) // extended remaining minutes 150 + putByteToArray(array, 9, 15) // hours 15 + putByteToArray(array, 10, 25) // minutes 25 + putIntToArray(array, 11, 170) // last bolus manout 1.70 + + packet.handleMessage(array) + Assert.assertFalse(packet.failed) + Assert.assertEquals(6.0, danaRPump.iob, 0.01) + Assert.assertEquals(12.5, danaRPump.dailyTotalUnits, 0.01) + Assert.assertTrue(danaRPump.isExtendedInProgress) + Assert.assertEquals(150, danaRPump.extendedBolusRemainingMinutes) + val lastBolus = Date(danaRPump.lastBolusTime) + Assert.assertEquals(15, lastBolus.hours) + Assert.assertEquals(25, lastBolus.minutes) + Assert.assertEquals(1.7, danaRPump.lastBolusAmount, 0.01) + Assert.assertEquals("REVIEW__GET_MORE_INFORMATION", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt index 743d3f66e7..bc10832af9 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt @@ -1,17 +1,52 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.db.DatabaseHelper +import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes import org.junit.Assert +import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.Mockito.`when` +import org.powermock.api.mockito.PowerMockito import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner +import java.util.* @RunWith(PowerMockRunner::class) -@PrepareForTest() +@PrepareForTest(MainApp::class) class DanaRS_Packet_History_AlarmTest : DanaRSTestBase() { - @Test fun runTest() { - val packet = DanaRS_Packet_History_Alarm(aapsLogger, rxBus, System.currentTimeMillis()) + @Mock lateinit var databaseHelper: DatabaseHelper + + @Before + fun mock() { + PowerMockito.mockStatic(MainApp::class.java) + `when`(MainApp.getDbHelper()).thenReturn(databaseHelper) + } + + @Test + fun runTest() { + val packet = DanaRS_Packet_History_Alarm(aapsLogger, rxBus, 0) + + val array = createArray(12, 0.toByte()) // 10 + 2 + putByteToArray(array, 0, 0x0A) // record code alarm + putByteToArray(array, 1, 19) // year 2019 + putByteToArray(array, 2, 2) // month february + putByteToArray(array, 3, 4) // day 4 + putByteToArray(array, 4, 20) // hour 20 + putByteToArray(array, 5, 11) // min 11 + putByteToArray(array, 6, 35) // second 35 + putByteToArray(array, 7, 79) // occlusion + putByteToArray(array, 8, 1) // value + putByteToArray(array, 9, 100) // value + + packet.handleMessage(array) + Assert.assertEquals(RecordTypes.RECORD_TYPE_ALARM, packet.danaRHistoryRecord.recordCode) + Assert.assertEquals(Date(119, 1, 4, 20, 11, 35).time, packet.danaRHistoryRecord.recordDate) + Assert.assertEquals("Occlusion", packet.danaRHistoryRecord.recordAlarm) + Assert.assertEquals(3.56, packet.danaRHistoryRecord.recordValue, 0.01) Assert.assertEquals("REVIEW__ALARM", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt index 8f74812e9e..2ac915644f 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt @@ -1,25 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import org.joda.time.DateTime import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Option_Get_Pump_TimeTest : DanaRSTestBase() { @Test fun runTest() { val packet = DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump) - // test params - Assert.assertEquals(null, packet.requestParams) - // test message decoding - packet.handleMessage(createArray(8, 0.toByte())) - Assert.assertEquals(false, packet.failed) - // this should fail - packet.handleMessage(createArray(8, 1.toByte())) - Assert.assertEquals(true, packet.failed) + val array = createArray(8, 0.toByte()) // 6 + 2 + putByteToArray(array, 0, 19) // year 2019 + putByteToArray(array, 1, 2) // month february + putByteToArray(array, 2, 4) // day 4 + putByteToArray(array, 3, 20) // hour 20 + putByteToArray(array, 4, 11) // min 11 + putByteToArray(array, 5, 35) // second 35 + + packet.handleMessage(array) + Assert.assertEquals(DateTime(2019, 2, 4, 20, 11, 35).millis, danaRPump.pumpTime) Assert.assertEquals("OPTION__GET_PUMP_TIME", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt index 5fd034e5b6..bf34d76510 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt @@ -1,22 +1,25 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.utils.DateUtil import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner import java.util.* @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Option_Set_Pump_TimeTest : DanaRSTestBase() { @Test fun runTest() { - val packet = DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, DateUtil.now()) + val date = Date() + val packet = DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, date.time) // test params val params = packet.requestParams - Assert.assertEquals((Date().date and 0xff).toByte(), params[2]) + Assert.assertEquals((date.year - 100 and 0xff).toByte(), params[0]) // 2019 -> 19 + Assert.assertEquals((date.month + 1 and 0xff).toByte(), params[1]) + Assert.assertEquals((date.date and 0xff).toByte(), params[2]) + Assert.assertEquals((date.hours and 0xff).toByte(), params[3]) + Assert.assertEquals((date.minutes and 0xff).toByte(), params[4]) + Assert.assertEquals((date.seconds and 0xff).toByte(), params[5]) // test message decoding packet.handleMessage(createArray(3, 0.toByte())) Assert.assertEquals(false, packet.failed) From 8d3ad42ff762e0112d69dd9a6dd7062402507090 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 30 Mar 2020 21:14:56 +0200 Subject: [PATCH 10/53] Better detect failed encryption --- .../plugins/pump/danaRS/services/BLEComm.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt index e691156d0d..8e5937238d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt @@ -19,6 +19,8 @@ import info.nightscout.androidaps.plugins.pump.danaRS.activities.EnterPinActivit import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSMessageHashTable import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Etc_Keep_Connection +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_General_Get_Pump_Check import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess import info.nightscout.androidaps.utils.ToastUtils @@ -72,6 +74,7 @@ class BLEComm @Inject internal constructor( var isConnected = false var isConnecting = false private var encryptedDataRead = false + private var encryptedCommandSent = false private var uartRead: BluetoothGattCharacteristic? = null private var uartWrite: BluetoothGattCharacteristic? = null @@ -99,6 +102,7 @@ class BLEComm @Inject internal constructor( isConnected = false v3Encryption = false encryptedDataRead = false + encryptedCommandSent = false isConnecting = true val device = bluetoothAdapter?.getRemoteDevice(address) if (device == null) { @@ -121,7 +125,7 @@ class BLEComm @Inject internal constructor( fun disconnect(from: String) { aapsLogger.debug(LTag.PUMPBTCOMM, "disconnect from: $from") - if (!encryptedDataRead && v3Encryption) { + if (!encryptedDataRead && encryptedCommandSent && v3Encryption) { // there was no response from pump after started encryption // assume pairing keys are invalid sp.remove(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName) @@ -143,6 +147,7 @@ class BLEComm @Inject internal constructor( bluetoothGatt?.disconnect() isConnected = false encryptedDataRead = false + encryptedCommandSent = false SystemClock.sleep(2000) } @@ -202,6 +207,7 @@ class BLEComm @Inject internal constructor( isConnecting = false isConnected = false encryptedDataRead = false + encryptedCommandSent = false return } bluetoothGatt?.setCharacteristicNotification(characteristic, enabled) @@ -216,6 +222,7 @@ class BLEComm @Inject internal constructor( isConnecting = false isConnected = false encryptedDataRead = false + encryptedCommandSent = false return@Runnable } characteristic.value = data @@ -241,6 +248,7 @@ class BLEComm @Inject internal constructor( isConnecting = false isConnected = false encryptedDataRead = false + encryptedCommandSent = false return null } return bluetoothGatt?.services @@ -275,6 +283,7 @@ class BLEComm @Inject internal constructor( isConnecting = false v3Encryption = false encryptedDataRead = false + encryptedCommandSent = false rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED)) aapsLogger.debug(LTag.PUMPBTCOMM, "Device was disconnected " + gatt.device.name) //Device was disconnected } @@ -527,6 +536,7 @@ class BLEComm @Inject internal constructor( isConnected = true isConnecting = false aapsLogger.debug(LTag.PUMPBTCOMM, "Connect !!") + // Send one message to confirm communication } else { context.startActivity(Intent(context, EnterPinActivity::class.java).also { it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) }) aapsLogger.debug(LTag.PUMPBTCOMM, "Request pairing keys !!") @@ -616,6 +626,7 @@ class BLEComm @Inject internal constructor( // the rest of packets fun sendMessage(message: DanaRS_Packet) { + encryptedCommandSent = true processedMessage = message val command = byteArrayOf(message.type.toByte(), message.opCode.toByte()) val params = message.requestParams From 58fe62c45afca477eb3c7f0faaf1ad4b16de53fe Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 2 Apr 2020 21:46:30 +0200 Subject: [PATCH 11/53] concurrency extension --- .../plugins/pump/danaRS/services/BLEComm.kt | 8 ++--- .../nightscout/androidaps/utils/CryptoUtil.kt | 33 +------------------ .../utils/extensions/Concurrency.kt | 22 +++++++++++++ 3 files changed, 26 insertions(+), 37 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/utils/extensions/Concurrency.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt index 8e5937238d..e46aff33d7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt @@ -19,15 +19,13 @@ import info.nightscout.androidaps.plugins.pump.danaRS.activities.EnterPinActivit import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSMessageHashTable import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Etc_Keep_Connection -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_General_Get_Pump_Check import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess import info.nightscout.androidaps.utils.ToastUtils +import info.nightscout.androidaps.utils.extensions.notify +import info.nightscout.androidaps.utils.extensions.waitMillis import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP -import okhttp3.internal.notify -import okhttp3.internal.waitMillis import java.util.* import java.util.concurrent.ScheduledFuture import javax.inject.Inject @@ -230,7 +228,7 @@ class BLEComm @Inject internal constructor( //aapsLogger.debug("writeCharacteristic:" + DanaRS_Packet.toHexString(data)) bluetoothGatt?.writeCharacteristic(characteristic) }).start() - waitMillis(50) + SystemClock.sleep(50) } private val uartReadBTGattChar: BluetoothGattCharacteristic diff --git a/app/src/main/java/info/nightscout/androidaps/utils/CryptoUtil.kt b/app/src/main/java/info/nightscout/androidaps/utils/CryptoUtil.kt index 745f4449ee..ad271e7344 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/CryptoUtil.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/CryptoUtil.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.utils +import info.nightscout.androidaps.utils.extensions.toHex import org.spongycastle.util.encoders.Base64 import java.nio.ByteBuffer import java.security.MessageDigest @@ -13,38 +14,6 @@ import javax.crypto.spec.GCMParameterSpec import javax.crypto.spec.PBEKeySpec import javax.crypto.spec.SecretKeySpec -private val HEX_CHARS = "0123456789abcdef" -private val HEX_CHARS_ARRAY = "0123456789abcdef".toCharArray() - -fun String.hexStringToByteArray() : ByteArray { - - val upperCased = this.toLowerCase() - val result = ByteArray(length / 2) - for (i in 0 until length step 2) { - val firstIndex = HEX_CHARS.indexOf(upperCased[i]); - val secondIndex = HEX_CHARS.indexOf(upperCased[i + 1]); - - val octet = firstIndex.shl(4).or(secondIndex) - result.set(i.shr(1), octet.toByte()) - } - - return result -} - -fun ByteArray.toHex() : String{ - val result = StringBuffer() - - forEach { - val octet = it.toInt() - val firstIndex = (octet and 0xF0).ushr(4) - val secondIndex = octet and 0x0F - result.append(HEX_CHARS_ARRAY[firstIndex]) - result.append(HEX_CHARS_ARRAY[secondIndex]) - } - - return result.toString() -} - object CryptoUtil { private const val IV_LENGTH_BYTE = 12 diff --git a/app/src/main/java/info/nightscout/androidaps/utils/extensions/Concurrency.kt b/app/src/main/java/info/nightscout/androidaps/utils/extensions/Concurrency.kt new file mode 100644 index 0000000000..b958a0ea24 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/utils/extensions/Concurrency.kt @@ -0,0 +1,22 @@ +package info.nightscout.androidaps.utils.extensions + + +@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "NOTHING_TO_INLINE") +inline fun Any.wait() = (this as Object).wait() + +/** + * Lock and wait a duration in milliseconds and nanos. + * Unlike [java.lang.Object.wait] this interprets 0 as "don't wait" instead of "wait forever". + */ +@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") +fun Any.waitMillis(timeout: Long, nanos: Int = 0) { + if (timeout > 0L || nanos > 0) { + (this as Object).wait(timeout, nanos) + } +} + +@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "NOTHING_TO_INLINE") +inline fun Any.notify() = (this as Object).notify() + +@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "NOTHING_TO_INLINE") +inline fun Any.notifyAll() = (this as Object).notifyAll() From 0d89262dfabf49716d4607aff9d58550bcb9ef10 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 6 Apr 2020 10:35:00 +0200 Subject: [PATCH 12/53] fix SmsPluginCommunicatorTest --- .../general/smsCommunicator/SmsCommunicatorPluginTest.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt index d5b7ddd5f5..2ce83f0164 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt @@ -13,6 +13,7 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.PluginType +import info.nightscout.androidaps.interfaces.PumpDescription import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction @@ -156,6 +157,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { `when`(virtualPumpPlugin.shortStatus(ArgumentMatchers.anyBoolean())).thenReturn("Virtual Pump") `when`(virtualPumpPlugin.isSuspended).thenReturn(false) + `when`(virtualPumpPlugin.pumpDescription).thenReturn(PumpDescription()) `when`(treatmentsPlugin.lastCalculationTreatments).thenReturn(IobTotal(0)) `when`(treatmentsPlugin.lastCalculationTempBasals).thenReturn(IobTotal(0)) From f595560baadeafacc93f25b15882ebbfc6e99996 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 19 Apr 2020 12:57:08 +0200 Subject: [PATCH 13/53] RS insulin and canula change logging --- .../androidaps/dialogs/FillDialog.kt | 48 ++++++++++--------- .../danaRS/comm/DanaRSMessageHashTable.kt | 7 +-- .../comm/DanaRS_Packet_APS_History_Events.kt | 8 ++++ .../pump/danaRS/services/DanaRSService.kt | 4 +- .../plugins/treatments/TreatmentsPlugin.java | 2 +- app/src/main/res/values/strings.xml | 6 +++ app/src/main/res/xml/pref_danars.xml | 12 +++++ .../danaRS/comm/DanaRSMessageHashTableTest.kt | 2 +- .../DanaRS_Packet_APS_History_EventsTest.kt | 2 +- 9 files changed, 60 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt index df1664b68a..3fbdc7112c 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt @@ -25,6 +25,7 @@ import info.nightscout.androidaps.utils.HtmlHelper import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.SafeParse import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.androidaps.utils.sharedPreferences.SP import kotlinx.android.synthetic.main.dialog_fill.* import kotlinx.android.synthetic.main.notes.* import kotlinx.android.synthetic.main.okcancel.* @@ -121,12 +122,12 @@ class FillDialog : DialogFragmentWithDate() { } if (siteChange) { aapsLogger.debug("USER ENTRY: SITE CHANGE") - generateCareportalEvent(CareportalEvent.SITECHANGE, eventTime, notes) + generateCareportalEvent(CareportalEvent.SITECHANGE, eventTime, notes, resourceHelper, sp) } if (insulinChange) { // add a second for case of both checked aapsLogger.debug("USER ENTRY: INSULIN CHANGE") - generateCareportalEvent(CareportalEvent.INSULINCHANGE, eventTime + 1000, notes) + generateCareportalEvent(CareportalEvent.INSULINCHANGE, eventTime + 1000, notes, resourceHelper, sp) } }, null) } @@ -160,27 +161,28 @@ class FillDialog : DialogFragmentWithDate() { }) } - private fun generateCareportalEvent(eventType: String, time: Long, notes: String) { - val careportalEvent = CareportalEvent() - careportalEvent.source = Source.USER - careportalEvent.date = time - careportalEvent.json = generateJson(eventType, time, notes).toString() - careportalEvent.eventType = eventType - MainApp.getDbHelper().createOrUpdate(careportalEvent) - NSUpload.uploadEvent(eventType, time, notes) - } - - private fun generateJson(careportalEvent: String, time: Long, notes: String): JSONObject { - val data = JSONObject() - try { - data.put("eventType", careportalEvent) - data.put("created_at", DateUtil.toISOString(time)) - data.put("mills", time) - data.put("enteredBy", sp.getString("careportal_enteredby", resourceHelper.gs(R.string.app_name))) - if (notes.isNotEmpty()) data.put("notes", notes) - } catch (ignored: JSONException) { + companion object { + fun generateCareportalEvent(eventType: String, time: Long, notes: String, resourceHelper: ResourceHelper, sp: SP) { + val careportalEvent = CareportalEvent() + careportalEvent.source = Source.USER + careportalEvent.date = time + careportalEvent.json = generateJson(eventType, time, notes, resourceHelper, sp).toString() + careportalEvent.eventType = eventType + MainApp.getDbHelper().createOrUpdate(careportalEvent) + NSUpload.uploadEvent(eventType, time, notes) } - return data - } + private fun generateJson(careportalEvent: String, time: Long, notes: String, resourceHelper: ResourceHelper, sp: SP): JSONObject { + val data = JSONObject() + try { + data.put("eventType", careportalEvent) + data.put("created_at", DateUtil.toISOString(time)) + data.put("mills", time) + data.put("enteredBy", sp.getString("careportal_enteredby", resourceHelper.gs(R.string.app_name))) + if (notes.isNotEmpty()) data.put("notes", notes) + } catch (ignored: JSONException) { + } + return data + } + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt index 4f3d86c51d..c158cce9a5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt @@ -6,8 +6,8 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump -import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.androidaps.utils.sharedPreferences.SP import java.util.* import javax.inject.Inject import javax.inject.Singleton @@ -20,7 +20,8 @@ class DanaRSMessageHashTable @Inject constructor( danaRPump: DanaRPump, activePlugin: ActivePluginProvider, constraintChecker: ConstraintChecker, - detailedBolusInfoStorage: DetailedBolusInfoStorage + detailedBolusInfoStorage: DetailedBolusInfoStorage, + sp: SP ) { var messages: HashMap = HashMap() @@ -98,7 +99,7 @@ class DanaRSMessageHashTable @Inject constructor( put(DanaRS_Packet_History_Temporary(aapsLogger, rxBus)) // APS put(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, 0)) - put(DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, 0)) + put(DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, sp, 0)) put(DanaRS_Packet_APS_Set_Event_History(aapsLogger, 0, 0, 0, 0)) // v3 put(DanaRS_Packet_General_Get_Shipping_Version(aapsLogger, danaRPump)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt index 97700ba30e..1ee7086bd8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt @@ -2,9 +2,11 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import info.nightscout.androidaps.R import info.nightscout.androidaps.data.DetailedBolusInfo +import info.nightscout.androidaps.db.CareportalEvent import info.nightscout.androidaps.db.ExtendedBolus import info.nightscout.androidaps.db.Source import info.nightscout.androidaps.db.TemporaryBasal +import info.nightscout.androidaps.dialogs.FillDialog import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.logging.AAPSLogger @@ -15,6 +17,7 @@ import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.androidaps.utils.sharedPreferences.SP import java.util.* open class DanaRS_Packet_APS_History_Events( @@ -24,6 +27,7 @@ open class DanaRS_Packet_APS_History_Events( private val activePlugin: ActivePluginProvider, private val danaRPump: DanaRPump, private val detailedBolusInfoStorage: DetailedBolusInfoStorage, + private val sp: SP, private var from: Long ) : DanaRS_Packet() { @@ -156,11 +160,15 @@ open class DanaRS_Packet_APS_History_Events( DanaRPump.REFILL -> { aapsLogger.debug(LTag.PUMPCOMM, "EVENT REFILL (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U") + if (sp.getBoolean(R.string.key_rs_loginsulinchange, true)) + FillDialog.generateCareportalEvent(CareportalEvent.INSULINCHANGE, datetime, resourceHelper.gs(R.string.danarspump), resourceHelper, sp) status = "REFILL " + DateUtil.timeString(datetime) } DanaRPump.PRIME -> { aapsLogger.debug(LTag.PUMPCOMM, "EVENT PRIME (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U") + if (sp.getBoolean(R.string.key_rs_logcanulachange, true)) + FillDialog.generateCareportalEvent(CareportalEvent.SITECHANGE, datetime, resourceHelper.gs(R.string.danarspump), resourceHelper, sp) status = "PRIME " + DateUtil.timeString(datetime) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt index 1497904916..3cdb8f3857 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt @@ -211,10 +211,10 @@ class DanaRSService : DaggerService() { SystemClock.sleep(1000) val msg: DanaRS_Packet_APS_History_Events if (lastHistoryFetched == 0L) { - msg = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, 0) + msg = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, sp, 0) aapsLogger.debug(LTag.PUMPCOMM, "Loading complete event history") } else { - msg = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, lastHistoryFetched) + msg = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, sp, lastHistoryFetched) aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + DateUtil.dateAndTimeString(lastHistoryFetched)) } sendMessage(msg) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java index 9704d82f43..910c4d1cfb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java @@ -288,7 +288,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface /** * Returns all Treatments after specified timestamp. Also returns invalid entries (required to - * map "Fill Canulla" entries to history (and not to add double bolus for it) + * map "Fill Canula" entries to history (and not to add double bolus for it) * * @param fromTimestamp * @return diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 019338b92c..6f0d1e46e3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1815,4 +1815,10 @@ Predictions Deviation slope graphconfig + rs_loginsulinchange + Log reservoir change + Add \"Insulin Change\" event to careportal when detected in history + rs_logcanulachange + Log canula change + Add \"Site Change\" event to careportal when detected in history diff --git a/app/src/main/res/xml/pref_danars.xml b/app/src/main/res/xml/pref_danars.xml index 2bd7446a61..baf7bc4405 100644 --- a/app/src/main/res/xml/pref_danars.xml +++ b/app/src/main/res/xml/pref_danars.xml @@ -35,6 +35,18 @@ android:key="@string/key_danars_bolusspeed" android:title="@string/bolusspeed" /> + + + + diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt index 0ebefe9403..1db5d5ffc1 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt @@ -27,7 +27,7 @@ class DanaRSMessageHashTableTest : DanaRSTestBase() { fun runTest() { `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) - val danaRSMessageHashTable = DanaRSMessageHashTable(aapsLogger, rxBus, resourceHelper, danaRPump, activePlugin, constraintChecker, detailedBolusInfoStorage) + val danaRSMessageHashTable = DanaRSMessageHashTable(aapsLogger, rxBus, resourceHelper, danaRPump, activePlugin, constraintChecker, detailedBolusInfoStorage, sp) val forTesting: DanaRS_Packet = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, 0, 0, 0) val testPacket: DanaRS_Packet = danaRSMessageHashTable.findMessage(forTesting.command) Assert.assertEquals(BleEncryption.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY.toLong(), testPacket.getOpCode().toLong()) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt index 2b88f1c450..51d31a907d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt @@ -23,7 +23,7 @@ class DanaRS_Packet_APS_History_EventsTest : DanaRSTestBase() { @Test fun runTest() { val now = DateUtil.now() - val testPacket = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, now) + val testPacket = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, sp, now) // test getRequestedParams val returnedValues = testPacket.requestParams val expectedValues = getCalender(now) From e526ad4617bf50a08f957f44d22b996e27a593d5 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 20 Apr 2020 21:28:29 +0200 Subject: [PATCH 14/53] model string --- .../plugins/pump/danaR/DanaRFragment.kt | 38 +++++++++---------- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt index d747301ec0..83c7077825 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt @@ -178,7 +178,7 @@ class DanaRFragment : DaggerFragment() { if (pump.lastConnection != 0L) { val agoMsec = System.currentTimeMillis() - pump.lastConnection val agoMin = (agoMsec.toDouble() / 60.0 / 1000.0).toInt() - danar_lastconnection.text = DateUtil.timeString(pump.lastConnection) + " (" + resourceHelper.gs(R.string.minago, agoMin) + ")" + danar_lastconnection?.text = DateUtil.timeString(pump.lastConnection) + " (" + resourceHelper.gs(R.string.minago, agoMin) + ")" SetWarnColor.setColor(danar_lastconnection, agoMin.toDouble(), 16.0, 31.0) } if (pump.lastBolusTime != 0L) { @@ -186,46 +186,46 @@ class DanaRFragment : DaggerFragment() { val agoHours = agoMsec.toDouble() / 60.0 / 60.0 / 1000.0 if (agoHours < 6) // max 6h back - danar_lastbolus.text = DateUtil.timeString(pump.lastBolusTime) + " " + DateUtil.sinceString(pump.lastBolusTime, resourceHelper) + " " + resourceHelper.gs(R.string.formatinsulinunits, pump.lastBolusAmount) + danar_lastbolus?.text = DateUtil.timeString(pump.lastBolusTime) + " " + DateUtil.sinceString(pump.lastBolusTime, resourceHelper) + " " + resourceHelper.gs(R.string.formatinsulinunits, pump.lastBolusAmount) else - danar_lastbolus.text = "" + danar_lastbolus?.text = "" } - danar_dailyunits.text = resourceHelper.gs(R.string.reservoirvalue, pump.dailyTotalUnits, pump.maxDailyTotalUnits) + danar_dailyunits?.text = resourceHelper.gs(R.string.reservoirvalue, pump.dailyTotalUnits, pump.maxDailyTotalUnits) SetWarnColor.setColor(danar_dailyunits, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75, pump.maxDailyTotalUnits * 0.9) - danar_basabasalrate.text = "( " + (pump.activeProfile + 1) + " ) " + resourceHelper.gs(R.string.pump_basebasalrate, plugin.baseBasalRate) + danar_basabasalrate?.text = "( " + (pump.activeProfile + 1) + " ) " + resourceHelper.gs(R.string.pump_basebasalrate, plugin.baseBasalRate) // DanaRPlugin, DanaRKoreanPlugin if (activePlugin.activePump.isFakingTempsByExtendedBoluses == true) { - danar_tempbasal.text = activePlugin.activeTreatments.getRealTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() + danar_tempbasal?.text = activePlugin.activeTreatments.getRealTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: "" } else { // v2 plugin - danar_tempbasal.text = activePlugin.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() + danar_tempbasal?.text = activePlugin.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: "" } - danar_extendedbolus.text = activePlugin.activeTreatments.getExtendedBolusFromHistory(System.currentTimeMillis())?.toString() + danar_extendedbolus?.text = activePlugin.activeTreatments.getExtendedBolusFromHistory(System.currentTimeMillis())?.toString() ?: "" - danar_reservoir.text = resourceHelper.gs(R.string.reservoirvalue, pump.reservoirRemainingUnits, 300) + danar_reservoir?.text = resourceHelper.gs(R.string.reservoirvalue, pump.reservoirRemainingUnits, 300) SetWarnColor.setColorInverse(danar_reservoir, pump.reservoirRemainingUnits, 50.0, 20.0) - danar_battery.text = "{fa-battery-" + pump.batteryRemaining / 25 + "}" + danar_battery?.text = "{fa-battery-" + pump.batteryRemaining / 25 + "}" SetWarnColor.setColorInverse(danar_battery, pump.batteryRemaining.toDouble(), 51.0, 26.0) - danar_iob.text = resourceHelper.gs(R.string.formatinsulinunits, pump.iob) - danar_firmware.text = resourceHelper.gs(R.string.danar_model, pump.modelFriendlyName(), pump.hwModel, pump.protocol, pump.productCode) - danar_basalstep.text = pump.basalStep.toString() - danar_bolusstep.text = pump.bolusStep.toString() - danar_serialnumber.text = pump.serialNumber + danar_iob?.text = resourceHelper.gs(R.string.formatinsulinunits, pump.iob) + danar_firmware?.text = resourceHelper.gs(R.string.dana_model, pump.modelFriendlyName(), pump.hwModel, pump.protocol, pump.productCode) + danar_basalstep?.text = pump.basalStep.toString() + danar_bolusstep?.text = pump.bolusStep.toString() + danar_serialnumber?.text = pump.serialNumber val status = commandQueue.spannedStatus() if (status.toString() == "") { - danar_queue.visibility = View.GONE + danar_queue?.visibility = View.GONE } else { - danar_queue.visibility = View.VISIBLE - danar_queue.text = status + danar_queue?.visibility = View.VISIBLE + danar_queue?.text = status } //hide user options button if not an RS pump or old firmware // also excludes pump with model 03 because of untested error val isKorean = danaRKoreanPlugin.isEnabled(PluginType.PUMP) if (isKorean || pump.hwModel == 0 || pump.hwModel == 3) { - danar_user_options.visibility = View.GONE + danar_user_options?.visibility = View.GONE } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9f65f79867..9b3e148dc9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -529,7 +529,7 @@ Useful when data from unfiltered sources like xDrip gets noisy. Advanced Settings key_advancedsettings - %1$s\nModel: %2$02X\nProtocol: %3$02X\nCode: %4$02X + %1$s\nModel: %2$02X\nProtocol: %3$02X\nCode: %4$02X Profile Default value: 3 This is a key OpenAPS safety cap. What this does is limit your basals to be 3x (in this people) your biggest basal rate. You likely will not need to change this, but you should be aware that’s what is discussed about “3x max daily; 4x current” for safety caps. Default value: 4 This is the other half of the key OpenAPS safety caps, and the other half of “3x max daily; 4x current” of the safety caps. This means your basal, regardless of max basal set on your pump, cannot be any higher than this number times the current level of your basal. This is to prevent people from getting into dangerous territory by setting excessively high max basals before understanding how the algorithm works. Again, the default is 4x; most people will never need to adjust this and are instead more likely to need to adjust other settings if they feel like they are “running into” this safety cap. From c84e7ec326b18de8bdff4f870206e1ccc114896e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 24 Apr 2020 23:23:39 +0200 Subject: [PATCH 15/53] fix tests --- .../utils/extensions/HexByteArrayConversion.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/extensions/HexByteArrayConversion.kt b/app/src/main/java/info/nightscout/androidaps/utils/extensions/HexByteArrayConversion.kt index 9852ecbbf4..7492135983 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/extensions/HexByteArrayConversion.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/extensions/HexByteArrayConversion.kt @@ -1,6 +1,8 @@ package info.nightscout.androidaps.utils.extensions -private val HEX_CHARS = "0123456789ABCDEF".toCharArray() +import java.util.* + +private val HEX_CHARS = "0123456789abcdef".toCharArray() fun ByteArray.toHex() : String{ val result = StringBuffer() @@ -20,9 +22,10 @@ fun String.hexStringToByteArray() : ByteArray { val result = ByteArray(length / 2) + val lowerCased = this.toLowerCase(Locale.getDefault()) for (i in 0 until length step 2) { - val firstIndex = HEX_CHARS.indexOf(this[i]); - val secondIndex = HEX_CHARS.indexOf(this[i + 1]); + val firstIndex = HEX_CHARS.indexOf(lowerCased[i]); + val secondIndex = HEX_CHARS.indexOf(lowerCased[i + 1]); val octet = firstIndex.shl(4).or(secondIndex) result.set(i.shr(1), octet.toByte()) From a5108ca4c4cce2913eb4a57c0d75ccc401217c24 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 29 Apr 2020 23:27:48 +0200 Subject: [PATCH 16/53] RS injection refactor --- .../dependencyInjection/AppModule.kt | 2 +- .../dependencyInjection/DanaRSCommModule.kt | 79 +++++++++ .../danaRS/comm/DanaRSMessageHashTable.kt | 154 ++++++++---------- .../pump/danaRS/comm/DanaRS_Packet.java | 26 ++- ...RS_Packet_APS_Basal_Set_Temporary_Basal.kt | 8 +- .../comm/DanaRS_Packet_APS_History_Events.kt | 20 +-- .../DanaRS_Packet_APS_Set_Event_History.kt | 8 +- .../DanaRS_Packet_Basal_Get_Basal_Rate.kt | 18 +- ...aRS_Packet_Basal_Get_Profile_Basal_Rate.kt | 14 +- .../DanaRS_Packet_Basal_Get_Profile_Number.kt | 12 +- ..._Packet_Basal_Get_Temporary_Basal_State.kt | 12 +- .../DanaRS_Packet_Basal_Set_Basal_Rate.kt | 8 +- ...Packet_Basal_Set_Cancel_Temporary_Basal.kt | 8 +- ...aRS_Packet_Basal_Set_Profile_Basal_Rate.kt | 8 +- .../DanaRS_Packet_Basal_Set_Profile_Number.kt | 8 +- .../DanaRS_Packet_Basal_Set_Suspend_Off.kt | 8 +- .../DanaRS_Packet_Basal_Set_Suspend_On.kt | 8 +- ...DanaRS_Packet_Basal_Set_Temporary_Basal.kt | 8 +- .../DanaRS_Packet_Bolus_Get_Bolus_Option.kt | 15 +- .../DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt | 12 +- ...acket_Bolus_Get_Calculation_Information.kt | 11 +- ...et_Carbohydrate_Calculation_Information.kt | 12 +- .../DanaRS_Packet_Bolus_Get_Dual_Bolus.kt | 12 +- .../DanaRS_Packet_Bolus_Get_Extended_Bolus.kt | 12 +- ...S_Packet_Bolus_Get_Extended_Bolus_State.kt | 12 +- ...et_Bolus_Get_Extended_Menu_Option_State.kt | 12 +- .../DanaRS_Packet_Bolus_Get_Initial_Bolus.kt | 8 +- ...Packet_Bolus_Get_Step_Bolus_Information.kt | 13 +- .../DanaRS_Packet_Bolus_Set_Bolus_Option.kt | 8 +- .../DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt | 8 +- .../DanaRS_Packet_Bolus_Set_Dual_Bolus.kt | 9 +- .../DanaRS_Packet_Bolus_Set_Extended_Bolus.kt | 9 +- ..._Packet_Bolus_Set_Extended_Bolus_Cancel.kt | 8 +- .../DanaRS_Packet_Bolus_Set_Initial_Bolus.kt | 8 +- ...anaRS_Packet_Bolus_Set_Step_Bolus_Start.kt | 11 +- ...DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt | 13 +- .../comm/DanaRS_Packet_Etc_Keep_Connection.kt | 8 +- .../DanaRS_Packet_Etc_Set_History_Save.kt | 9 +- .../DanaRS_Packet_General_Delivery_Status.kt | 8 +- ...aRS_Packet_General_Get_More_Information.kt | 10 +- .../DanaRS_Packet_General_Get_Password.kt | 12 +- .../DanaRS_Packet_General_Get_Pump_Check.kt | 14 +- ...Packet_General_Get_Shipping_Information.kt | 12 +- ...aRS_Packet_General_Get_Shipping_Version.kt | 10 +- ...Packet_General_Get_Today_Delivery_Total.kt | 12 +- ...acket_General_Get_User_Time_Change_Flag.kt | 8 +- ...cket_General_Initial_Screen_Information.kt | 10 +- ..._Packet_General_Set_History_Upload_Mode.kt | 8 +- ...General_Set_User_Time_Change_Flag_Clear.kt | 9 +- .../danaRS/comm/DanaRS_Packet_History_.kt | 10 +- .../comm/DanaRS_Packet_History_Alarm.kt | 10 +- .../comm/DanaRS_Packet_History_All_History.kt | 10 +- .../comm/DanaRS_Packet_History_Basal.kt | 10 +- .../DanaRS_Packet_History_Blood_Glucose.kt | 10 +- .../comm/DanaRS_Packet_History_Bolus.kt | 10 +- .../DanaRS_Packet_History_Carbohydrate.kt | 10 +- .../comm/DanaRS_Packet_History_Daily.kt | 10 +- .../comm/DanaRS_Packet_History_Prime.kt | 10 +- .../comm/DanaRS_Packet_History_Refill.kt | 10 +- .../comm/DanaRS_Packet_History_Suspend.kt | 6 +- .../comm/DanaRS_Packet_History_Temporary.kt | 10 +- .../danaRS/comm/DanaRS_Packet_Notify_Alarm.kt | 14 +- .../DanaRS_Packet_Notify_Delivery_Complete.kt | 14 +- ...aRS_Packet_Notify_Delivery_Rate_Display.kt | 13 +- ...DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt | 8 +- .../DanaRS_Packet_Option_Get_Pump_Time.kt | 10 +- .../DanaRS_Packet_Option_Get_User_Option.kt | 12 +- .../DanaRS_Packet_Option_Set_Pump_Time.kt | 6 +- .../DanaRS_Packet_Option_Set_User_Option.kt | 11 +- .../comm/DanaRS_Packet_Review_Bolus_Avg.kt | 8 +- ...DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt | 10 +- .../plugins/pump/danaRS/services/BLEComm.kt | 4 +- .../pump/danaRS/services/DanaRSService.kt | 104 ++++++------ .../danaRS/comm/DanaRSMessageHashTableTest.kt | 26 ++- ...acket_APS_Basal_Set_Temporary_BasalTest.kt | 22 ++- .../DanaRS_Packet_APS_History_EventsTest.kt | 20 ++- ...DanaRS_Packet_APS_Set_Event_HistoryTest.kt | 18 +- .../DanaRS_Packet_Basal_Get_Basal_RateTest.kt | 14 +- ...Packet_Basal_Get_Profile_Basal_RateTest.kt | 23 ++- ...aRS_Packet_Basal_Get_Profile_NumberTest.kt | 13 +- ...ket_Basal_Get_Temporary_Basal_StateTest.kt | 13 +- .../DanaRS_Packet_Basal_Set_Basal_RateTest.kt | 12 +- ...et_Basal_Set_Cancel_Temporary_BasalTest.kt | 12 +- ...Packet_Basal_Set_Profile_Basal_RateTest.kt | 12 +- ...aRS_Packet_Basal_Set_Profile_NumberTest.kt | 12 +- ...DanaRS_Packet_Basal_Set_Suspend_OffTest.kt | 12 +- .../DanaRS_Packet_Basal_Set_Suspend_OnTest.kt | 12 +- ...RS_Packet_Basal_Set_Temporary_BasalTest.kt | 13 +- ...anaRS_Packet_Bolus_Get_Bolus_OptionTest.kt | 15 +- ...anaRS_Packet_Bolus_Get_CIR_CF_ArrayTest.kt | 15 +- ...t_Bolus_Get_Calculation_InformationTest.kt | 13 +- ...arbohydrate_Calculation_InformationTest.kt | 13 +- .../DanaRS_Packet_Bolus_Get_Dual_BolusTest.kt | 15 +- ...aRS_Packet_Bolus_Get_Extended_BolusTest.kt | 13 +- ...cket_Bolus_Get_Extended_Bolus_StateTest.kt | 13 +- ...olus_Get_Extended_Menu_Option_StateTest.kt | 15 +- ...naRS_Packet_Bolus_Get_Initial_BolusTest.kt | 14 +- ...et_Bolus_Get_Step_Bolus_InformationTest.kt | 13 +- ...anaRS_Packet_Bolus_Set_Bolus_OptionTest.kt | 14 +- ...anaRS_Packet_Bolus_Set_CIR_CF_ArrayTest.kt | 14 +- .../DanaRS_Packet_Bolus_Set_Dual_BolusTest.kt | 14 +- ...aRS_Packet_Bolus_Set_Extended_BolusTest.kt | 14 +- ...ket_Bolus_Set_Extended_Bolus_CancelTest.kt | 14 +- ...naRS_Packet_Bolus_Set_Initial_BolusTest.kt | 14 +- ...S_Packet_Bolus_Set_Step_Bolus_StartTest.kt | 13 +- ...RS_Packet_Bolus_Set_Step_Bolus_StopTest.kt | 14 +- .../DanaRS_Packet_Etc_Keep_ConnectionTest.kt | 14 +- .../DanaRS_Packet_Etc_Set_History_SaveTest.kt | 12 +- ...naRS_Packet_General_Delivery_StatusTest.kt | 12 +- ...Packet_General_Get_More_InformationTest.kt | 15 +- .../DanaRS_Packet_General_Get_PasswordTest.kt | 17 +- ...anaRS_Packet_General_Get_Pump_CheckTest.kt | 17 +- ...et_General_Get_Shipping_InformationTest.kt | 15 +- ...Packet_General_Get_Shipping_VerisonTest.kt | 13 +- ...et_General_Get_Today_Delivery_TotalTest.kt | 17 +- ...t_General_Get_User_Time_Change_FlagTest.kt | 16 +- ..._General_Initial_Screen_InformationTest.kt | 17 +- ...ket_General_Set_History_Upload_ModeTest.kt | 14 +- ...ral_Set_User_Time_Change_Flag_ClearTest.kt | 14 +- .../comm/DanaRS_Packet_History_AlarmTest.kt | 13 +- .../DanaRS_Packet_History_All_HistoryTest.kt | 15 +- .../comm/DanaRS_Packet_History_BasalTest.kt | 15 +- ...DanaRS_Packet_History_Blood_GlucoseTest.kt | 15 +- .../comm/DanaRS_Packet_History_BolusTest.kt | 15 +- .../DanaRS_Packet_History_CarbohydrateTest.kt | 15 +- .../comm/DanaRS_Packet_History_DailyTest.kt | 15 +- .../comm/DanaRS_Packet_History_PrimeTest.kt | 15 +- .../comm/DanaRS_Packet_History_RefillTest.kt | 15 +- .../comm/DanaRS_Packet_History_SuspendTest.kt | 15 +- .../DanaRS_Packet_History_TemporaryTest.kt | 15 +- .../comm/DanaRS_Packet_Notify_AlarmTest.kt | 14 +- ...aRS_Packet_Notify_Delivery_CompleteTest.kt | 14 +- ...Packet_Notify_Delivery_Rate_DisplayTest.kt | 14 +- ...RS_Packet_Notify_Missed_Bolus_AlarmTest.kt | 14 +- .../DanaRS_Packet_Option_Get_Pump_TimeTest.kt | 13 +- ...anaRS_Packet_Option_Get_User_OptionTest.kt | 15 +- .../DanaRS_Packet_Option_Set_Pump_TimeTest.kt | 14 +- ...anaRS_Packet_Option_Set_User_OptionTest.kt | 15 +- .../DanaRS_Packet_Review_Bolus_AvgTest.kt | 12 +- ...RS_Packet_Review_Get_Pump_Dec_RatioTest.kt | 15 +- 140 files changed, 1396 insertions(+), 646 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/dependencyInjection/DanaRSCommModule.kt diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index 6d334aa3d4..44fdc075f7 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -74,7 +74,7 @@ import info.nightscout.androidaps.utils.wizard.BolusWizard import info.nightscout.androidaps.utils.wizard.QuickWizardEntry import javax.inject.Singleton -@Module(includes = [AppModule.AppBindings::class, PluginsModule::class]) +@Module(includes = [AppModule.AppBindings::class, PluginsModule::class, DanaRSCommModule::class]) open class AppModule { @Provides diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/DanaRSCommModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/DanaRSCommModule.kt new file mode 100644 index 0000000000..fa915f8246 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/DanaRSCommModule.kt @@ -0,0 +1,79 @@ +package info.nightscout.androidaps.dependencyInjection + +import dagger.Module +import dagger.android.ContributesAndroidInjector +import info.nightscout.androidaps.plugins.pump.danaRS.comm.* + +@Module +@Suppress("unused") +abstract class DanaRSCommModule { + + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet(): DanaRS_Packet + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(): DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Basal_Get_Basal_Rate(): DanaRS_Packet_Basal_Get_Basal_Rate + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Basal_Get_Profile_Basal_Rate(): DanaRS_Packet_Basal_Get_Profile_Basal_Rate + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Basal_Get_Profile_Number(): DanaRS_Packet_Basal_Get_Profile_Number + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Basal_Set_Basal_Rate(): DanaRS_Packet_Basal_Set_Basal_Rate + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Basal_Set_Profile_Basal_Rate(): DanaRS_Packet_Basal_Set_Profile_Basal_Rate + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Basal_Set_Profile_Number(): DanaRS_Packet_Basal_Set_Profile_Number + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Basal_Set_Suspend_Off(): DanaRS_Packet_Basal_Set_Suspend_Off + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Basal_Set_Suspend_On(): DanaRS_Packet_Basal_Set_Suspend_On + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Basal_Set_Temporary_Basal(): DanaRS_Packet_Basal_Set_Temporary_Basal + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Basal_Get_Temporary_Basal_State(): DanaRS_Packet_Basal_Get_Temporary_Basal_State + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Get_Bolus_Option(): DanaRS_Packet_Bolus_Get_Bolus_Option + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Get_Initial_Bolus(): DanaRS_Packet_Bolus_Get_Initial_Bolus + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Get_Calculation_Information(): DanaRS_Packet_Bolus_Get_Calculation_Information + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information(): DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Get_CIR_CF_Array(): DanaRS_Packet_Bolus_Get_CIR_CF_Array + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Get_Dual_Bolus(): DanaRS_Packet_Bolus_Get_Dual_Bolus + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Get_Extended_Bolus(): DanaRS_Packet_Bolus_Get_Extended_Bolus + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Get_Extended_Bolus_State(): DanaRS_Packet_Bolus_Get_Extended_Bolus_State + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Get_Extended_Menu_Option_State(): DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Get_Step_Bolus_Information(): DanaRS_Packet_Bolus_Get_Step_Bolus_Information + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Set_Bolus_Option(): DanaRS_Packet_Bolus_Set_Bolus_Option + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Set_Initial_Bolus(): DanaRS_Packet_Bolus_Set_Initial_Bolus + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Set_CIR_CF_Array(): DanaRS_Packet_Bolus_Set_CIR_CF_Array + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Set_Dual_Bolus(): DanaRS_Packet_Bolus_Set_Dual_Bolus + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Set_Extended_Bolus(): DanaRS_Packet_Bolus_Set_Extended_Bolus + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel(): DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Set_Step_Bolus_Start(): DanaRS_Packet_Bolus_Set_Step_Bolus_Start + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Bolus_Set_Step_Bolus_Stop(): DanaRS_Packet_Bolus_Set_Step_Bolus_Stop + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Etc_Keep_Connection(): DanaRS_Packet_Etc_Keep_Connection + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Etc_Set_History_Save(): DanaRS_Packet_Etc_Set_History_Save + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_General_Delivery_Status(): DanaRS_Packet_General_Delivery_Status + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_General_Get_Password(): DanaRS_Packet_General_Get_Password + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_General_Initial_Screen_Information(): DanaRS_Packet_General_Initial_Screen_Information + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Notify_Alarm(): DanaRS_Packet_Notify_Alarm + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Notify_Delivery_Complete(): DanaRS_Packet_Notify_Delivery_Complete + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Notify_Delivery_Rate_Display(): DanaRS_Packet_Notify_Delivery_Rate_Display + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Notify_Missed_Bolus_Alarm(): DanaRS_Packet_Notify_Missed_Bolus_Alarm + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Option_Get_Pump_Time(): DanaRS_Packet_Option_Get_Pump_Time + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Option_Get_User_Option(): DanaRS_Packet_Option_Get_User_Option + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Option_Set_Pump_Time(): DanaRS_Packet_Option_Set_Pump_Time + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Option_Set_User_Option(): DanaRS_Packet_Option_Set_User_Option + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_History_(): DanaRS_Packet_History_ + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_History_Alarm(): DanaRS_Packet_History_Alarm + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_History_All_History(): DanaRS_Packet_History_All_History + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_History_Basal(): DanaRS_Packet_History_Basal + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_History_Blood_Glucose(): DanaRS_Packet_History_Blood_Glucose + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_History_Bolus(): DanaRS_Packet_History_Bolus + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Review_Bolus_Avg(): DanaRS_Packet_Review_Bolus_Avg + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_History_Carbohydrate(): DanaRS_Packet_History_Carbohydrate + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_History_Daily(): DanaRS_Packet_History_Daily + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_General_Get_More_Information(): DanaRS_Packet_General_Get_More_Information + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_General_Get_Pump_Check(): DanaRS_Packet_General_Get_Pump_Check + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_General_Get_Shipping_Information(): DanaRS_Packet_General_Get_Shipping_Information + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_General_Get_Today_Delivery_Total(): DanaRS_Packet_General_Get_Today_Delivery_Total + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_General_Get_User_Time_Change_Flag(): DanaRS_Packet_General_Get_User_Time_Change_Flag + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_History_Prime(): DanaRS_Packet_History_Prime + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_History_Refill(): DanaRS_Packet_History_Refill + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_General_Set_History_Upload_Mode(): DanaRS_Packet_General_Set_History_Upload_Mode + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_General_Set_User_Time_Change_Flag_Clear(): DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_History_Suspend(): DanaRS_Packet_History_Suspend + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_History_Temporary(): DanaRS_Packet_History_Temporary + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_APS_Basal_Set_Temporary_Basal(): DanaRS_Packet_APS_Basal_Set_Temporary_Basal + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_APS_History_Events(): DanaRS_Packet_APS_History_Events + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_APS_Set_Event_History(): DanaRS_Packet_APS_Set_Event_History + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_General_Get_Shipping_Version(): DanaRS_Packet_General_Get_Shipping_Version + @ContributesAndroidInjector abstract fun contributesDanaRS_Packet_Review_Get_Pump_Dec_Ratio(): DanaRS_Packet_Review_Get_Pump_Dec_Ratio +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt index cb6cbcee17..fea80dc506 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt @@ -1,29 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.interfaces.ActivePluginProvider -import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker -import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage -import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump -import info.nightscout.androidaps.utils.resources.ResourceHelper -import info.nightscout.androidaps.utils.sharedPreferences.SP import java.util.* import javax.inject.Inject import javax.inject.Singleton @Singleton class DanaRSMessageHashTable @Inject constructor( - aapsLogger: AAPSLogger, - rxBus: RxBusWrapper, - resourceHelper: ResourceHelper, - danaRPump: DanaRPump, - activePlugin: ActivePluginProvider, - constraintChecker: ConstraintChecker, - detailedBolusInfoStorage: DetailedBolusInfoStorage, - sp: SP, - injector: HasAndroidInjector + val injector: HasAndroidInjector ) { var messages: HashMap = HashMap() @@ -33,78 +17,78 @@ class DanaRSMessageHashTable @Inject constructor( } fun findMessage(command: Int): DanaRS_Packet { - return messages[command] ?: DanaRS_Packet() + return messages[command] ?: DanaRS_Packet(injector) } init { - put(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger)) - put(DanaRS_Packet_Basal_Get_Basal_Rate(aapsLogger, rxBus, resourceHelper, danaRPump)) - put(DanaRS_Packet_Basal_Get_Profile_Basal_Rate(aapsLogger, danaRPump)) - put(DanaRS_Packet_Basal_Get_Profile_Number(aapsLogger, danaRPump)) - put(DanaRS_Packet_Basal_Set_Basal_Rate(aapsLogger, arrayOf())) - put(DanaRS_Packet_Basal_Set_Profile_Basal_Rate(aapsLogger, 0, arrayOf())) - put(DanaRS_Packet_Basal_Set_Profile_Number(aapsLogger)) - put(DanaRS_Packet_Basal_Set_Suspend_Off(aapsLogger)) - put(DanaRS_Packet_Basal_Set_Suspend_On(aapsLogger)) - put(DanaRS_Packet_Basal_Set_Temporary_Basal(aapsLogger)) - put(DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)) - put(DanaRS_Packet_Bolus_Get_Bolus_Option(aapsLogger, rxBus, resourceHelper, danaRPump)) - put(DanaRS_Packet_Bolus_Get_Initial_Bolus(aapsLogger)) - put(DanaRS_Packet_Bolus_Get_Calculation_Information(aapsLogger, danaRPump)) - put(DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information(aapsLogger, danaRPump)) - put(DanaRS_Packet_Bolus_Get_CIR_CF_Array(aapsLogger, danaRPump)) - put(DanaRS_Packet_Bolus_Get_Dual_Bolus(aapsLogger, danaRPump)) - put(DanaRS_Packet_Bolus_Get_Extended_Bolus(aapsLogger, danaRPump)) - put(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(aapsLogger, danaRPump)) - put(DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State(aapsLogger, danaRPump)) - put(DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump)) - put(DanaRS_Packet_Bolus_Set_Bolus_Option(aapsLogger)) - put(DanaRS_Packet_Bolus_Set_Initial_Bolus(aapsLogger)) - put(DanaRS_Packet_Bolus_Set_CIR_CF_Array(aapsLogger)) - put(DanaRS_Packet_Bolus_Set_Dual_Bolus(aapsLogger)) - put(DanaRS_Packet_Bolus_Set_Extended_Bolus(aapsLogger)) - put(DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel(aapsLogger)) - put(DanaRS_Packet_Bolus_Set_Step_Bolus_Start(aapsLogger, danaRPump, constraintChecker)) - put(DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(aapsLogger, rxBus, resourceHelper, danaRPump)) - put(DanaRS_Packet_Etc_Keep_Connection(aapsLogger)) - put(DanaRS_Packet_Etc_Set_History_Save(aapsLogger)) - put(DanaRS_Packet_General_Delivery_Status(aapsLogger)) - put(DanaRS_Packet_General_Get_Password(aapsLogger, danaRPump)) - put(DanaRS_Packet_General_Initial_Screen_Information(aapsLogger, danaRPump)) - put(DanaRS_Packet_Notify_Alarm(aapsLogger, resourceHelper, rxBus)) - put(DanaRS_Packet_Notify_Delivery_Complete(aapsLogger, rxBus, resourceHelper, danaRPump)) - put(DanaRS_Packet_Notify_Delivery_Rate_Display(aapsLogger, rxBus, resourceHelper, danaRPump)) - put(DanaRS_Packet_Notify_Missed_Bolus_Alarm(aapsLogger)) - put(DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump)) - put(DanaRS_Packet_Option_Get_User_Option(aapsLogger, danaRPump)) - put(DanaRS_Packet_Option_Set_Pump_Time(aapsLogger)) - put(DanaRS_Packet_Option_Set_User_Option(aapsLogger, danaRPump)) - //put(new DanaRS_Packet_History_()); - put(DanaRS_Packet_History_Alarm(aapsLogger, rxBus)) - put(DanaRS_Packet_History_All_History(aapsLogger, rxBus)) - put(DanaRS_Packet_History_Basal(aapsLogger, rxBus)) - put(DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus)) - put(DanaRS_Packet_History_Bolus(aapsLogger, rxBus)) - put(DanaRS_Packet_Review_Bolus_Avg(aapsLogger)) - put(DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus)) - put(DanaRS_Packet_History_Daily(aapsLogger, rxBus)) - put(DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump)) - put(DanaRS_Packet_General_Get_Pump_Check(aapsLogger, danaRPump, rxBus, resourceHelper)) - put(DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump)) - put(DanaRS_Packet_General_Get_Today_Delivery_Total(aapsLogger, danaRPump)) - put(DanaRS_Packet_General_Get_User_Time_Change_Flag(aapsLogger)) - put(DanaRS_Packet_History_Prime(aapsLogger, rxBus)) - put(DanaRS_Packet_History_Refill(aapsLogger, rxBus)) - put(DanaRS_Packet_General_Set_History_Upload_Mode(aapsLogger)) - put(DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear(aapsLogger)) - put(DanaRS_Packet_History_Suspend(aapsLogger, rxBus)) - put(DanaRS_Packet_History_Temporary(aapsLogger, rxBus)) + put(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(injector)) + put(DanaRS_Packet_Basal_Get_Basal_Rate(injector)) + put(DanaRS_Packet_Basal_Get_Profile_Basal_Rate(injector)) + put(DanaRS_Packet_Basal_Get_Profile_Number(injector)) + put(DanaRS_Packet_Basal_Set_Basal_Rate(injector, arrayOf())) + put(DanaRS_Packet_Basal_Set_Profile_Basal_Rate(injector, 0, arrayOf())) + put(DanaRS_Packet_Basal_Set_Profile_Number(injector)) + put(DanaRS_Packet_Basal_Set_Suspend_Off(injector)) + put(DanaRS_Packet_Basal_Set_Suspend_On(injector)) + put(DanaRS_Packet_Basal_Set_Temporary_Basal(injector)) + put(DanaRS_Packet_Basal_Get_Temporary_Basal_State(injector)) + put(DanaRS_Packet_Bolus_Get_Bolus_Option(injector)) + put(DanaRS_Packet_Bolus_Get_Initial_Bolus(injector)) + put(DanaRS_Packet_Bolus_Get_Calculation_Information(injector)) + put(DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information(injector)) + put(DanaRS_Packet_Bolus_Get_CIR_CF_Array(injector)) + put(DanaRS_Packet_Bolus_Get_Dual_Bolus(injector)) + put(DanaRS_Packet_Bolus_Get_Extended_Bolus(injector)) + put(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(injector)) + put(DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State(injector)) + put(DanaRS_Packet_Bolus_Get_Step_Bolus_Information(injector)) + put(DanaRS_Packet_Bolus_Set_Bolus_Option(injector)) + put(DanaRS_Packet_Bolus_Set_Initial_Bolus(injector)) + put(DanaRS_Packet_Bolus_Set_CIR_CF_Array(injector)) + put(DanaRS_Packet_Bolus_Set_Dual_Bolus(injector)) + put(DanaRS_Packet_Bolus_Set_Extended_Bolus(injector)) + put(DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel(injector)) + put(DanaRS_Packet_Bolus_Set_Step_Bolus_Start(injector)) + put(DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(injector)) + put(DanaRS_Packet_Etc_Keep_Connection(injector)) + put(DanaRS_Packet_Etc_Set_History_Save(injector)) + put(DanaRS_Packet_General_Delivery_Status(injector)) + put(DanaRS_Packet_General_Get_Password(injector)) + put(DanaRS_Packet_General_Initial_Screen_Information(injector)) + put(DanaRS_Packet_Notify_Alarm(injector)) + put(DanaRS_Packet_Notify_Delivery_Complete(injector)) + put(DanaRS_Packet_Notify_Delivery_Rate_Display(injector)) + put(DanaRS_Packet_Notify_Missed_Bolus_Alarm(injector)) + put(DanaRS_Packet_Option_Get_Pump_Time(injector)) + put(DanaRS_Packet_Option_Get_User_Option(injector)) + put(DanaRS_Packet_Option_Set_Pump_Time(injector)) + put(DanaRS_Packet_Option_Set_User_Option(injector)) + //put(new DanaRS_Packet_History_(injector)); + put(DanaRS_Packet_History_Alarm(injector)) + put(DanaRS_Packet_History_All_History(injector)) + put(DanaRS_Packet_History_Basal(injector)) + put(DanaRS_Packet_History_Blood_Glucose(injector)) + put(DanaRS_Packet_History_Bolus(injector)) + put(DanaRS_Packet_Review_Bolus_Avg(injector)) + put(DanaRS_Packet_History_Carbohydrate(injector)) + put(DanaRS_Packet_History_Daily(injector)) + put(DanaRS_Packet_General_Get_More_Information(injector)) + put(DanaRS_Packet_General_Get_Pump_Check(injector)) + put(DanaRS_Packet_General_Get_Shipping_Information(injector)) + put(DanaRS_Packet_General_Get_Today_Delivery_Total(injector)) + put(DanaRS_Packet_General_Get_User_Time_Change_Flag(injector)) + put(DanaRS_Packet_History_Prime(injector)) + put(DanaRS_Packet_History_Refill(injector)) + put(DanaRS_Packet_General_Set_History_Upload_Mode(injector)) + put(DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear(injector)) + put(DanaRS_Packet_History_Suspend(injector)) + put(DanaRS_Packet_History_Temporary(injector)) // APS - put(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, 0)) - put(DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, sp, injector, 0)) - put(DanaRS_Packet_APS_Set_Event_History(aapsLogger, 0, 0, 0, 0)) + put(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(injector, 0)) + put(DanaRS_Packet_APS_History_Events(injector, 0)) + put(DanaRS_Packet_APS_Set_Event_History(injector, 0, 0, 0, 0)) // v3 - put(DanaRS_Packet_General_Get_Shipping_Version(aapsLogger, danaRPump)) - put(DanaRS_Packet_Review_Get_Pump_Dec_Ratio(aapsLogger, danaRPump)) + put(DanaRS_Packet_General_Get_Shipping_Version(injector)) + put(DanaRS_Packet_Review_Get_Pump_Dec_Ratio(injector)) } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java index 9bb70720fb..275ba6f145 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java @@ -3,16 +3,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm; import android.annotation.TargetApi; import android.os.Build; +import dagger.android.HasAndroidInjector; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.logging.AAPSLogger; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption; + import org.slf4j.Logger; import java.nio.charset.StandardCharsets; import java.util.Date; +import javax.inject.Inject; + import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; public class DanaRS_Packet { - private static final Logger log = StacktraceLoggerWrapper.getLogger(DanaRS_Packet.class); + + @Inject AAPSLogger aapsLogger; + + protected HasAndroidInjector injector; protected static final int TYPE_START = 0; protected static final int OPCODE_START = 1; @@ -23,9 +33,11 @@ public class DanaRS_Packet { protected int type = BleEncryption.DANAR_PACKET__TYPE_RESPONSE; // most of the messages, should be changed for others protected int opCode; - public DanaRS_Packet() { + public DanaRS_Packet(HasAndroidInjector injector) { received = false; failed = false; + this.injector = injector; + injector.androidInjector().inject(this); } public void setReceived() { @@ -54,7 +66,7 @@ public class DanaRS_Packet { // STATIC FUNCTIONS - public static int getCommand(byte[] data) { + public int getCommand(byte[] data) { int type = byteArrayToInt(getBytes(data, TYPE_START, 1)); int opCode = byteArrayToInt(getBytes(data, OPCODE_START, 1)); return ((type & 0xFF) << 8) + (opCode & 0xFF); @@ -70,7 +82,7 @@ public class DanaRS_Packet { return "UNKNOWN_PACKET"; } - protected static byte[] getBytes(byte[] data, int srcStart, int srcLength) { + protected byte[] getBytes(byte[] data, int srcStart, int srcLength) { try { byte[] ret = new byte[srcLength]; @@ -78,7 +90,7 @@ public class DanaRS_Packet { return ret; } catch (Exception e) { - log.error("Unhandled exception", e); + aapsLogger.error(LTag.PUMPBTCOMM, "Unhandled exception", e); } return null; } @@ -148,7 +160,7 @@ public class DanaRS_Packet { return new String(strbuff, StandardCharsets.UTF_8); } - public static long dateFromBuff(byte[] buff, int offset) { + public long dateFromBuff(byte[] buff, int offset) { return new Date( 100 + byteArrayToInt(getBytes(buff, offset, 1)), @@ -159,7 +171,7 @@ public class DanaRS_Packet { @TargetApi(Build.VERSION_CODES.KITKAT) - public static String asciiStringFromBuff(byte[] buff, int offset, int length) { + public String asciiStringFromBuff(byte[] buff, int offset, int length) { byte[] strbuff = new byte[length]; System.arraycopy(buff, offset, strbuff, 0, length); for (int pos = 0; pos < length; pos++) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.kt index 89a2c3fac3..bfcfeac676 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.kt @@ -1,13 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_APS_Basal_Set_Temporary_Basal( - private val aapsLogger: AAPSLogger, + injector: HasAndroidInjector, private var percent: Int -) : DanaRS_Packet() { +) : DanaRS_Packet(injector) { var temporaryBasalRatio = 0 var temporaryBasalDuration = 0 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt index 5ca6eac5a2..14da2a9b8e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt @@ -10,7 +10,6 @@ import info.nightscout.androidaps.db.TemporaryBasal import info.nightscout.androidaps.dialogs.FillDialog import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.interfaces.ActivePluginProvider -import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage @@ -20,18 +19,19 @@ import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import java.util.* +import javax.inject.Inject open class DanaRS_Packet_APS_History_Events( - private val aapsLogger: AAPSLogger, - private val rxBus: RxBusWrapper, - private val resourceHelper: ResourceHelper, - private val activePlugin: ActivePluginProvider, - private val danaRPump: DanaRPump, - private val detailedBolusInfoStorage: DetailedBolusInfoStorage, - private val sp: SP, - private val injector: HasAndroidInjector, + injector: HasAndroidInjector, private var from: Long -) : DanaRS_Packet() { +) : DanaRS_Packet(injector) { + + @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var activePlugin: ActivePluginProvider + @Inject lateinit var danaRPump: DanaRPump + @Inject lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage + @Inject lateinit var sp: SP private var year = 0 private var month = 0 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt index 861854d77b..7f6c1e342f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt @@ -1,19 +1,19 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.DateUtil import java.util.* class DanaRS_Packet_APS_Set_Event_History( - private val aapsLogger: AAPSLogger, + injector: HasAndroidInjector, private var packetType: Int, private var time: Long, private var param1: Int, private var param2: Int -) : DanaRS_Packet() { +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.kt index 8cdbbe2d65..b25bc2c587 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.kt @@ -1,23 +1,25 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R -import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper 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 import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.resources.ResourceHelper import java.util.* +import javax.inject.Inject class DanaRS_Packet_Basal_Get_Basal_Rate( - private val aapsLogger: AAPSLogger, - private val rxBus: RxBusWrapper, - private val resourceHelper: ResourceHelper, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__GET_BASAL_RATE @@ -31,7 +33,7 @@ class DanaRS_Packet_Basal_Get_Basal_Rate( dataIndex += dataSize dataSize = 1 danaRPump.basalStep = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0 - danaRPump.pumpProfiles = Array(4) {Array(48) {0.0} } + danaRPump.pumpProfiles = Array(4) { Array(48) { 0.0 } } var i = 0 val size = 24 while (i < size) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.kt index 9b0de5603c..bbac168239 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.kt @@ -1,16 +1,18 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import java.util.* +import javax.inject.Inject open class DanaRS_Packet_Basal_Get_Profile_Basal_Rate( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump, + injector: HasAndroidInjector, private val profileNumber: Int = 0 -) : DanaRS_Packet() { +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__GET_PROFILE_BASAL_RATE @@ -26,7 +28,7 @@ open class DanaRS_Packet_Basal_Get_Profile_Basal_Rate( override fun handleMessage(data: ByteArray) { var dataIndex = DATA_START var dataSize = 2 - danaRPump.pumpProfiles = Array(4) {Array(48) {0.0} } + danaRPump.pumpProfiles = Array(4) { Array(48) { 0.0 } } var i = 0 val size = 24 while (i < size) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.kt index bdd586e948..c973a5aa11 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.kt @@ -1,14 +1,16 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import javax.inject.Inject class DanaRS_Packet_Basal_Get_Profile_Number( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__GET_PROFILE_NUMBER diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt index bb5f0d8d98..709438d8df 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt @@ -1,16 +1,18 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.DateUtil +import javax.inject.Inject import kotlin.math.ceil class DanaRS_Packet_Basal_Get_Temporary_Basal_State( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__TEMPORARY_BASAL_STATE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.kt index 28d7b6b693..f16bc7c0cf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.kt @@ -1,13 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Basal_Set_Basal_Rate( - private val aapsLogger: AAPSLogger, + injector: HasAndroidInjector, private var profileBasalRate: Array -) : DanaRS_Packet() { +) : DanaRS_Packet(injector) { init { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.kt index c30b938002..c7fa4c3536 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal( - private val aapsLogger: AAPSLogger -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__CANCEL_TEMPORARY_BASAL diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.kt index 189a704e0c..ddf0adba78 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.kt @@ -1,14 +1,14 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Basal_Set_Profile_Basal_Rate( - private val aapsLogger: AAPSLogger, + injector: HasAndroidInjector, private var profileNumber: Int, private var profileBasalRate: Array -) : DanaRS_Packet() { +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__SET_PROFILE_BASAL_RATE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.kt index 2056889532..7c0994196b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.kt @@ -1,13 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Basal_Set_Profile_Number( - private val aapsLogger: AAPSLogger, + injector: HasAndroidInjector, private var profileNumber: Int = 0 -) : DanaRS_Packet() { +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__SET_PROFILE_NUMBER diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.kt index eff81eb0bb..3608ee30ca 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Basal_Set_Suspend_Off( - private val aapsLogger: AAPSLogger - ) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__SET_SUSPEND_OFF diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.kt index e3a3f9d228..df5bee1aac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Basal_Set_Suspend_On( - private val aapsLogger: AAPSLogger -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__SET_SUSPEND_ON diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.kt index f4318fb0b3..cbd91aa051 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.kt @@ -1,14 +1,14 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption open class DanaRS_Packet_Basal_Set_Temporary_Basal( - private val aapsLogger: AAPSLogger, + injector: HasAndroidInjector, private var temporaryBasalRatio: Int = 0, private var temporaryBasalDuration: Int = 0 -) : DanaRS_Packet() { +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BASAL__SET_TEMPORARY_BASAL diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.kt index 8918094938..432f0792dd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.kt @@ -1,23 +1,24 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R -import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper 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 import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.resources.ResourceHelper +import javax.inject.Inject class DanaRS_Packet_Bolus_Get_Bolus_Option( - private val aapsLogger: AAPSLogger, - private val rxBus: RxBusWrapper, - private val resourceHelper: ResourceHelper, - private val danaRPump: DanaRPump + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { -) : DanaRS_Packet() { + @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_BOLUS_OPTION diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt index d981da5033..4af5c48fac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt @@ -1,14 +1,16 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import javax.inject.Inject class DanaRS_Packet_Bolus_Get_CIR_CF_Array( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_CIR_CF_ARRAY diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.kt index 6c19045a2f..8f618bce4f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.kt @@ -1,15 +1,16 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import javax.inject.Inject class DanaRS_Packet_Bolus_Get_Calculation_Information( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_CALCULATION_INFORMATION diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.kt index c1bd0aeb40..ad7a5de3b7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.kt @@ -1,14 +1,16 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import javax.inject.Inject class DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_CARBOHYDRATE_CALCULATION_INFORMATION diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.kt index 97d40dd0af..8334d04028 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.kt @@ -1,14 +1,16 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import javax.inject.Inject class DanaRS_Packet_Bolus_Get_Dual_Bolus( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_DUAL_BOLUS diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.kt index 9d96debe56..4795b08482 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.kt @@ -1,14 +1,16 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import javax.inject.Inject class DanaRS_Packet_Bolus_Get_Extended_Bolus( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_BOLUS diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt index ef24b5cec1..ecf337987e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt @@ -1,14 +1,16 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import javax.inject.Inject class DanaRS_Packet_Bolus_Get_Extended_Bolus_State( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_BOLUS_STATE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt index cd16a68bb7..001107cfa2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt @@ -1,14 +1,16 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import javax.inject.Inject class DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_MENU_OPTION_STATE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.kt index 50f5864e81..c301490a9f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Bolus_Get_Initial_Bolus( - private val aapsLogger: AAPSLogger -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_BOLUS_RATE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt index dca14ce099..6a90788340 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt @@ -1,17 +1,18 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.DateUtil import org.joda.time.DateTime -import java.util.* +import javax.inject.Inject class DanaRS_Packet_Bolus_Get_Step_Bolus_Information( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__GET_STEP_BOLUS_INFORMATION diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.kt index 21d9b39d56..ebf19f1459 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.kt @@ -1,11 +1,11 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Bolus_Set_Bolus_Option( - private val aapsLogger: AAPSLogger, + injector: HasAndroidInjector, private var extendedBolusOptionOnOff: Int = 0, private var bolusCalculationOption: Int = 0, private var missedBolusConfig: Int = 0, @@ -26,7 +26,7 @@ class DanaRS_Packet_Bolus_Set_Bolus_Option( private var missedBolus04EndHour: Int = 0, private var missedBolus04EndMin: Int = 0 -) : DanaRS_Packet() { +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_BOLUS_OPTION diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt index 137c1633b6..cf2bfa44d1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt @@ -1,11 +1,11 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Bolus_Set_CIR_CF_Array( - private val aapsLogger: AAPSLogger, + injector: HasAndroidInjector, private var cir01: Int = 0, private var cir02: Int = 0, private var cir03: Int = 0, @@ -20,7 +20,7 @@ class DanaRS_Packet_Bolus_Set_CIR_CF_Array( private var cf05: Int = 0, private var cf06: Int = 0, private var cf07: Int = 0 -) : DanaRS_Packet() { +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_CIR_CF_ARRAY diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.kt index 919039319b..d9c18cb839 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.kt @@ -1,16 +1,15 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Bolus_Set_Dual_Bolus( - private val aapsLogger: AAPSLogger, + injector: HasAndroidInjector, private var amount: Double = 0.0, private var extendedAmount: Double = 0.0, private var extendedBolusDurationInHalfHours: Int = 0 -) : DanaRS_Packet() { - +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_DUAL_BOLUS diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.kt index 222152c2a8..095f9f5080 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.kt @@ -1,15 +1,14 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Bolus_Set_Extended_Bolus( - private val aapsLogger: AAPSLogger, + injector: HasAndroidInjector, private var extendedAmount: Double = 0.0, private var extendedBolusDurationInHalfHours: Int = 0 -) : DanaRS_Packet() { - +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_EXTENDED_BOLUS diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.kt index 868dd5f7b6..4b36940aaf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel( - private val aapsLogger: AAPSLogger -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_EXTENDED_BOLUS_CANCEL diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.kt index eecd43c6ca..0229c9434c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.kt @@ -1,16 +1,16 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Bolus_Set_Initial_Bolus( - private val aapsLogger: AAPSLogger, + injector: HasAndroidInjector, private var bolusRate01: Int = 0, private var bolusRate02: Int = 0, private var bolusRate03: Int = 0, private var bolusRate04: Int = 0 -) : DanaRS_Packet() { +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_BOLUS_RATE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt index d9dc8f0d95..9dfc6016c7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt @@ -1,20 +1,21 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.interfaces.Constraint -import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import javax.inject.Inject class DanaRS_Packet_Bolus_Set_Step_Bolus_Start( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump, - constraintChecker: ConstraintChecker, + injector: HasAndroidInjector, private var amount: Double = 0.0, private var speed: Int = 0 -) : DanaRS_Packet() { +) : DanaRS_Packet(injector) { + @Inject lateinit var danaRPump: DanaRPump + @Inject lateinit var constraintChecker: ConstraintChecker init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_START diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt index c5c1ace3b4..cf42e445ee 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt @@ -1,21 +1,22 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R -import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.resources.ResourceHelper +import javax.inject.Inject open class DanaRS_Packet_Bolus_Set_Step_Bolus_Stop( - private val aapsLogger: AAPSLogger, - private val rxBus: RxBusWrapper, - private val resourceHelper: ResourceHelper, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_STOP diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.kt index 1038881c2e..89ae76b68e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Etc_Keep_Connection( - private val aapsLogger: AAPSLogger -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_ETC__KEEP_CONNECTION diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.kt index ae1fac6bff..2859aa8496 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.kt @@ -1,11 +1,11 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Etc_Set_History_Save( - private val aapsLogger: AAPSLogger, + injector: HasAndroidInjector, private var historyType: Int = 0, private var historyYear: Int = 0, private var historyMonth: Int = 0, @@ -15,8 +15,7 @@ class DanaRS_Packet_Etc_Set_History_Save( private var historySecond: Int = 0, private var historyCode: Int = 0, private var historyValue: Int = 0 -) : DanaRS_Packet() { - +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_ETC__SET_HISTORY_SAVE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.kt index 21937923fc..eb71b50be1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_General_Delivery_Status( - private val aapsLogger: AAPSLogger -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__DELIVERY_STATUS diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt index eb7d617d3b..2d0dee2c53 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt @@ -1,16 +1,18 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.DateUtil import org.joda.time.DateTime +import javax.inject.Inject class DanaRS_Packet_General_Get_More_Information( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__GET_MORE_INFORMATION diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.kt index 58cdf77ae9..dcbbb54136 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.kt @@ -1,14 +1,16 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import javax.inject.Inject class DanaRS_Packet_General_Get_Password( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__GET_PASSWORD diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt index be57043e89..dc942cdfe9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R -import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification @@ -9,13 +9,15 @@ import info.nightscout.androidaps.plugins.general.overview.notifications.Notific import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.resources.ResourceHelper +import javax.inject.Inject class DanaRS_Packet_General_Get_Pump_Check( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump, - private val rxBus: RxBusWrapper, - private val resourceHelper: ResourceHelper -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__GET_PUMP_CHECK diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt index 6bf3296af1..99eed59d76 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt @@ -1,15 +1,17 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.DateUtil +import javax.inject.Inject class DanaRS_Packet_General_Get_Shipping_Information( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__GET_SHIPPING_INFORMATION diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Version.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Version.kt index 9d3d83fbf4..e13912f666 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Version.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Version.kt @@ -1,15 +1,17 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import java.nio.charset.Charset +import javax.inject.Inject class DanaRS_Packet_General_Get_Shipping_Version( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_GENERAL__GET_SHIPPING_VERSION diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.kt index fe9c676ca9..2075528d8a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.kt @@ -1,14 +1,16 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import javax.inject.Inject class DanaRS_Packet_General_Get_Today_Delivery_Total( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__GET_TODAY_DELIVERY_TOTAL diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.kt index 45e68600d7..6ff8fa6231 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_General_Get_User_Time_Change_Flag( - private val aapsLogger: AAPSLogger -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__GET_USER_TIME_CHANGE_FLAG diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt index 0510c28271..586577be09 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt @@ -1,14 +1,16 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import javax.inject.Inject class DanaRS_Packet_General_Initial_Screen_Information( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__INITIAL_SCREEN_INFORMATION diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.kt index e26e13e6f0..969dd36c87 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.kt @@ -1,13 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_General_Set_History_Upload_Mode( - private val aapsLogger: AAPSLogger, + injector: HasAndroidInjector, private var mode: Int = 0 -) : DanaRS_Packet() { +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__SET_HISTORY_UPLOAD_MODE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt index 969f226fb0..4190545f99 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt @@ -1,17 +1,18 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear( - private val aapsLogger: AAPSLogger -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__SET_USER_TIME_CHANGE_FLAG_CLEAR aapsLogger.debug(LTag.PUMPCOMM, "New message") } + override fun handleMessage(data: ByteArray) { val result = intFromBuff(data, 0, 1) if (result == 0) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt index 4273f6ca0d..00b00a0fc0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.db.DanaRHistoryRecord -import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes @@ -10,12 +10,14 @@ import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus import info.nightscout.androidaps.utils.DateUtil import org.joda.time.DateTime import java.util.* +import javax.inject.Inject abstract class DanaRS_Packet_History_( - protected val aapsLogger: AAPSLogger, - protected val rxBus: RxBusWrapper, + injector: HasAndroidInjector, protected val from: Long -) : DanaRS_Packet() { +) : DanaRS_Packet(injector) { + + @Inject lateinit var rxBus: RxBusWrapper protected var year = 0 protected var month = 0 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt index bcf3ffc1df..eef5b0bac1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt @@ -1,15 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_History_Alarm @JvmOverloads constructor( - aapsLogger: AAPSLogger, - rxBus: RxBusWrapper, + injector: HasAndroidInjector, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(injector, from) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__ALARM diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt index 2b42507888..298d0005c9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt @@ -1,15 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_History_All_History( - aapsLogger: AAPSLogger, - rxBus: RxBusWrapper, + injector: HasAndroidInjector, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(injector, from) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__ALL_HISTORY diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt index 09173ed5c1..afd2469f64 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt @@ -1,15 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_History_Basal @JvmOverloads constructor( - aapsLogger: AAPSLogger, - rxBus: RxBusWrapper, + injector: HasAndroidInjector, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(injector, from) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__BASAL diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt index 7f07e71680..eda50d6749 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt @@ -1,15 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_History_Blood_Glucose @JvmOverloads constructor( - aapsLogger: AAPSLogger, - rxBus: RxBusWrapper, + injector: HasAndroidInjector, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(injector, from) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__BLOOD_GLUCOSE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt index d6f8b51707..6970681afb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt @@ -1,15 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_History_Bolus @JvmOverloads constructor( - aapsLogger: AAPSLogger, - rxBus: RxBusWrapper, + injector: HasAndroidInjector, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(injector, from) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__BOLUS diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt index ed3b49a8d7..2ddeae6a9a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt @@ -1,15 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_History_Carbohydrate @JvmOverloads constructor( - aapsLogger: AAPSLogger, - rxBus: RxBusWrapper, + injector: HasAndroidInjector, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(injector, from) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__CARBOHYDRATE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt index 645cab8272..4ce5d88af5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt @@ -1,15 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_History_Daily @JvmOverloads constructor( - aapsLogger: AAPSLogger, - rxBus: RxBusWrapper, + injector: HasAndroidInjector, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(injector, from) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__DAILY diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt index da209b0a8a..93dd90576f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt @@ -1,15 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_History_Prime @JvmOverloads constructor( - aapsLogger: AAPSLogger, - rxBus: RxBusWrapper, + injector: HasAndroidInjector, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(injector, from) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__PRIME diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt index 8b470a0170..adeff980df 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt @@ -1,15 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_History_Refill @JvmOverloads constructor( - aapsLogger: AAPSLogger, - rxBus: RxBusWrapper, + injector: HasAndroidInjector, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(injector, from) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__REFILL diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt index 2e5ad23dd9..614b728971 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt @@ -1,15 +1,15 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper class DanaRS_Packet_History_Suspend @JvmOverloads constructor( - aapsLogger: AAPSLogger, - rxBus: RxBusWrapper, + injector: HasAndroidInjector, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(injector, from) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__SUSPEND diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt index 5689ca82c5..045457a699 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt @@ -1,15 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_History_Temporary( - aapsLogger: AAPSLogger, - rxBus: RxBusWrapper, + injector: HasAndroidInjector, from: Long = 0 -) : DanaRS_Packet_History_(aapsLogger, rxBus, from) { +) : DanaRS_Packet_History_(injector, from) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__TEMPORARY diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt index f461c65f3c..de92b18367 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt @@ -1,20 +1,22 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R -import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.resources.ResourceHelper +import javax.inject.Inject class DanaRS_Packet_Notify_Alarm( - private val aapsLogger: AAPSLogger, - private val resourceHelper: ResourceHelper, - private val rxBus: RxBusWrapper -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var resourceHelper: ResourceHelper init { type = BleEncryption.DANAR_PACKET__TYPE_NOTIFY diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt index c4e5d5a06d..fd059dfe57 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt @@ -1,21 +1,23 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R -import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.resources.ResourceHelper +import javax.inject.Inject import kotlin.math.min class DanaRS_Packet_Notify_Delivery_Complete( - private val aapsLogger: AAPSLogger, - private val rxBus: RxBusWrapper, - private val resourceHelper: ResourceHelper, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var danaRPump: DanaRPump init { type = BleEncryption.DANAR_PACKET__TYPE_NOTIFY diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt index 0a256ed088..27d6c011a8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt @@ -1,22 +1,23 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R -import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.resources.ResourceHelper +import javax.inject.Inject import kotlin.math.min class DanaRS_Packet_Notify_Delivery_Rate_Display( - private val aapsLogger: AAPSLogger, - private val rxBus: RxBusWrapper, - private val resourceHelper: ResourceHelper, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var danaRPump: DanaRPump init { type = BleEncryption.DANAR_PACKET__TYPE_NOTIFY diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt index f15582f3d0..afe2599866 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Notify_Missed_Bolus_Alarm( - private val aapsLogger: AAPSLogger -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { init { type = BleEncryption.DANAR_PACKET__TYPE_NOTIFY diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt index 4db309afe0..e6bca23320 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt @@ -1,16 +1,18 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.DateUtil import org.joda.time.DateTime +import javax.inject.Inject class DanaRS_Packet_Option_Get_Pump_Time( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_OPTION__GET_PUMP_TIME diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.kt index a012b1302b..6e44cdace8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.kt @@ -1,14 +1,16 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import javax.inject.Inject class DanaRS_Packet_Option_Get_User_Option( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_OPTION__GET_USER_OPTION diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt index 73cf49c6df..d6bb703beb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt @@ -1,15 +1,15 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.utils.DateUtil import org.joda.time.DateTime class DanaRS_Packet_Option_Set_Pump_Time( - private val aapsLogger: AAPSLogger, + injector: HasAndroidInjector, private var time: Long = 0 -) : DanaRS_Packet() { +) : DanaRS_Packet(injector) { var error = 0 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.kt index d266bf765b..01ca99c2e5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.kt @@ -1,15 +1,16 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import javax.inject.Inject class DanaRS_Packet_Option_Set_User_Option( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_OPTION__SET_USER_OPTION diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.kt index ee953d8581..04751087eb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption class DanaRS_Packet_Review_Bolus_Avg( - private val aapsLogger: AAPSLogger -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__BOLUS_AVG diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt index 23d903de0b..182f58c3fe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt @@ -1,14 +1,16 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.logging.AAPSLogger +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption +import javax.inject.Inject class DanaRS_Packet_Review_Get_Pump_Dec_Ratio( - private val aapsLogger: AAPSLogger, - private val danaRPump: DanaRPump -) : DanaRS_Packet() { + injector: HasAndroidInjector +) : DanaRS_Packet(injector) { + + @Inject lateinit var danaRPump: DanaRPump init { opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__GET_PUMP_DEC_RATIO diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt index e46aff33d7..255a86d1f3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt @@ -5,6 +5,7 @@ import android.content.Context import android.content.Intent import android.os.SystemClock import android.util.Base64 +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.logging.AAPSLogger @@ -33,6 +34,7 @@ import javax.inject.Singleton @Singleton class BLEComm @Inject internal constructor( + private val injector: HasAndroidInjector, private val aapsLogger: AAPSLogger, private val resourceHelper: ResourceHelper, private val context: Context, @@ -695,7 +697,7 @@ class BLEComm @Inject internal constructor( // process common packet response private fun processMessage(decryptedBuffer: ByteArray) { val originalCommand = processedMessage?.command ?: 0xFFFF - val receivedCommand = DanaRS_Packet.getCommand(decryptedBuffer) + val receivedCommand = DanaRS_Packet(injector).getCommand(decryptedBuffer) val message: DanaRS_Packet? = if (originalCommand == receivedCommand) { // it's response to last message processedMessage diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt index 3d8a5c6a40..9c2e37214e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt @@ -112,25 +112,25 @@ class DanaRSService : DaggerService() { fun readPumpStatus() { try { rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpstatus))) - sendMessage(DanaRS_Packet_General_Initial_Screen_Information(aapsLogger, danaRPump)) + sendMessage(DanaRS_Packet_General_Initial_Screen_Information(injector)) rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingextendedbolusstatus))) - sendMessage(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(aapsLogger, danaRPump)) + sendMessage(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(injector)) rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingbolusstatus))) - sendMessage(DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump)) // last bolus, bolusStep, maxBolus + sendMessage(DanaRS_Packet_Bolus_Get_Step_Bolus_Information(injector)) // last bolus, bolusStep, maxBolus rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingtempbasalstatus))) - sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)) + sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(injector)) danaRPump.lastConnection = System.currentTimeMillis() val profile = profileFunction.getProfile() val pump = activePlugin.activePump if (profile != null && abs(danaRPump.currentBasal - profile.basal) >= pump.pumpDescription.basalStep) { rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpsettings))) - sendMessage(DanaRS_Packet_Basal_Get_Basal_Rate(aapsLogger, rxBus, resourceHelper, danaRPump)) // basal profile, basalStep, maxBasal + sendMessage(DanaRS_Packet_Basal_Get_Basal_Rate(injector)) // basal profile, basalStep, maxBasal if (!pump.isThisProfileSet(profile) && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE)) { rxBus.send(EventProfileNeedsUpdate()) } } rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumptime))) - sendMessage(DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump)) + sendMessage(DanaRS_Packet_Option_Get_Pump_Time(injector)) var timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L if (danaRPump.pumpTime == 0L) { // initial handshake was not successful @@ -143,14 +143,14 @@ class DanaRSService : DaggerService() { val now = System.currentTimeMillis() if (danaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized) { rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpsettings))) - sendMessage(DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump)) // serial no - sendMessage(DanaRS_Packet_General_Get_Pump_Check(aapsLogger, danaRPump, rxBus, resourceHelper)) // firmware - sendMessage(DanaRS_Packet_Basal_Get_Profile_Number(aapsLogger, danaRPump)) - sendMessage(DanaRS_Packet_Bolus_Get_Bolus_Option(aapsLogger, rxBus, resourceHelper, danaRPump)) // isExtendedEnabled - sendMessage(DanaRS_Packet_Basal_Get_Basal_Rate(aapsLogger, rxBus, resourceHelper, danaRPump)) // basal profile, basalStep, maxBasal - sendMessage(DanaRS_Packet_Bolus_Get_Calculation_Information(aapsLogger, danaRPump)) // target - sendMessage(DanaRS_Packet_Bolus_Get_CIR_CF_Array(aapsLogger, danaRPump)) - sendMessage(DanaRS_Packet_Option_Get_User_Option(aapsLogger, danaRPump)) // Getting user options + sendMessage(DanaRS_Packet_General_Get_Shipping_Information(injector)) // serial no + sendMessage(DanaRS_Packet_General_Get_Pump_Check(injector)) // firmware + sendMessage(DanaRS_Packet_Basal_Get_Profile_Number(injector)) + sendMessage(DanaRS_Packet_Bolus_Get_Bolus_Option(injector)) // isExtendedEnabled + sendMessage(DanaRS_Packet_Basal_Get_Basal_Rate(injector)) // basal profile, basalStep, maxBasal + sendMessage(DanaRS_Packet_Bolus_Get_Calculation_Information(injector)) // target + sendMessage(DanaRS_Packet_Bolus_Get_CIR_CF_Array(injector)) + sendMessage(DanaRS_Packet_Option_Get_User_Option(injector)) // Getting user options danaRPump.lastSettingsRead = now } aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: $timeDiff seconds") @@ -172,13 +172,13 @@ class DanaRSService : DaggerService() { return } else { if (danaRPump.protocol >= 6) { - sendMessage(DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, DateUtil.now())) + sendMessage(DanaRS_Packet_Option_Set_Pump_Time(injector, DateUtil.now())) } else { waitForWholeMinute() // Dana can set only whole minute // add 10sec to be sure we are over minute (will be cut off anyway) - sendMessage(DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, DateUtil.now() + T.secs(10).msecs())) + sendMessage(DanaRS_Packet_Option_Set_Pump_Time(injector, DateUtil.now() + T.secs(10).msecs())) } - sendMessage(DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump)) + sendMessage(DanaRS_Packet_Option_Get_Pump_Time(injector)) timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: $timeDiff seconds") } @@ -211,10 +211,10 @@ class DanaRSService : DaggerService() { SystemClock.sleep(1000) val msg: DanaRS_Packet_APS_History_Events if (lastHistoryFetched == 0L) { - msg = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, sp, injector, 0) + msg = DanaRS_Packet_APS_History_Events(injector, 0) aapsLogger.debug(LTag.PUMPCOMM, "Loading complete event history") } else { - msg = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, sp, injector, lastHistoryFetched) + msg = DanaRS_Packet_APS_History_Events(injector, lastHistoryFetched) aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + DateUtil.dateAndTimeString(lastHistoryFetched)) } sendMessage(msg) @@ -228,7 +228,7 @@ class DanaRSService : DaggerService() { } fun setUserSettings(): PumpEnactResult { - sendMessage(DanaRS_Packet_Option_Get_User_Option(aapsLogger, danaRPump)) + sendMessage(DanaRS_Packet_Option_Get_User_Option(injector)) return PumpEnactResult(injector).success(true) } @@ -243,11 +243,11 @@ class DanaRSService : DaggerService() { danaRPump.bolusStopped = false danaRPump.bolusStopForced = false danaRPump.bolusProgressLastTimeStamp = DateUtil.now() - val start = DanaRS_Packet_Bolus_Set_Step_Bolus_Start(aapsLogger, danaRPump, constraintChecker, insulin, preferencesSpeed) + val start = DanaRS_Packet_Bolus_Set_Step_Bolus_Start(injector, insulin, preferencesSpeed) if (carbs > 0) { // MsgSetCarbsEntry msg = new MsgSetCarbsEntry(carbTime, carbs); #### // sendMessage(msg); - val msgSetHistoryEntryV2 = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, carbTime, carbs, 0) + val msgSetHistoryEntryV2 = DanaRS_Packet_APS_Set_Event_History(injector, DanaRPump.CARBS, carbTime, carbs, 0) sendMessage(msgSetHistoryEntryV2) lastHistoryFetched = min(lastHistoryFetched, carbTime - T.mins(1).msecs()) } @@ -291,7 +291,7 @@ class DanaRSService : DaggerService() { override fun run() { // reread bolus status rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.gettingbolusstatus))) - sendMessage(DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump)) // last bolus + sendMessage(DanaRS_Packet_Bolus_Get_Step_Bolus_Information(injector)) // last bolus bolusingEvent.percent = 100 rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.disconnecting))) } @@ -301,7 +301,7 @@ class DanaRSService : DaggerService() { fun bolusStop() { aapsLogger.debug(LTag.PUMPCOMM, "bolusStop >>>>> @ " + if (bolusingTreatment == null) "" else bolusingTreatment?.insulin) - val stop = DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(aapsLogger, rxBus, resourceHelper, danaRPump) + val stop = DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(injector) danaRPump.bolusStopForced = true if (isConnected) { sendMessage(stop) @@ -318,13 +318,13 @@ class DanaRSService : DaggerService() { if (!isConnected) return false if (danaRPump.isTempBasalInProgress) { rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal))) - sendMessage(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger)) + sendMessage(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(injector)) SystemClock.sleep(500) } rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))) - sendMessage(DanaRS_Packet_Basal_Set_Temporary_Basal(aapsLogger, percent, durationInHours)) + sendMessage(DanaRS_Packet_Basal_Set_Temporary_Basal(injector, percent, durationInHours)) SystemClock.sleep(200) - sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)) + sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(injector)) loadEvents() rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) return true @@ -333,12 +333,12 @@ class DanaRSService : DaggerService() { fun highTempBasal(percent: Int): Boolean { if (danaRPump.isTempBasalInProgress) { rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal))) - sendMessage(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger)) + sendMessage(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(injector)) SystemClock.sleep(500) } rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))) - sendMessage(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, percent)) - sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)) + sendMessage(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(injector, percent)) + sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(injector)) loadEvents() rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) return true @@ -351,12 +351,12 @@ class DanaRSService : DaggerService() { } if (danaRPump.isTempBasalInProgress) { rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal))) - sendMessage(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger)) + sendMessage(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(injector)) SystemClock.sleep(500) } rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))) - sendMessage(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, percent)) - sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)) + sendMessage(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(injector, percent)) + sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(injector)) loadEvents() rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) return true @@ -365,8 +365,8 @@ class DanaRSService : DaggerService() { fun tempBasalStop(): Boolean { if (!isConnected) return false rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal))) - sendMessage(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger)) - sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)) + sendMessage(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(injector)) + sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(injector)) loadEvents() rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) return true @@ -375,9 +375,9 @@ class DanaRSService : DaggerService() { fun extendedBolus(insulin: Double, durationInHalfHours: Int): Boolean { if (!isConnected) return false rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingextendedbolus))) - sendMessage(DanaRS_Packet_Bolus_Set_Extended_Bolus(aapsLogger, insulin, durationInHalfHours)) + sendMessage(DanaRS_Packet_Bolus_Set_Extended_Bolus(injector, insulin, durationInHalfHours)) SystemClock.sleep(200) - sendMessage(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(aapsLogger, danaRPump)) + sendMessage(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(injector)) loadEvents() rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) return true @@ -386,8 +386,8 @@ class DanaRSService : DaggerService() { fun extendedBolusStop(): Boolean { if (!isConnected) return false rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingextendedbolus))) - sendMessage(DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel(aapsLogger)) - sendMessage(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(aapsLogger, danaRPump)) + sendMessage(DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel(injector)) + sendMessage(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(injector)) loadEvents() rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) return true @@ -397,9 +397,9 @@ class DanaRSService : DaggerService() { if (!isConnected) return false rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.updatingbasalrates))) val basal = danaRPump.buildDanaRProfileRecord(profile) - val msgSet = DanaRS_Packet_Basal_Set_Profile_Basal_Rate(aapsLogger, 0, basal) + val msgSet = DanaRS_Packet_Basal_Set_Profile_Basal_Rate(injector, 0, basal) sendMessage(msgSet) - val msgActivate = DanaRS_Packet_Basal_Set_Profile_Number(aapsLogger, 0) + val msgActivate = DanaRS_Packet_Basal_Set_Profile_Number(injector, 0) sendMessage(msgActivate) danaRPump.lastSettingsRead = 0 // force read full settings readPumpStatus() @@ -412,25 +412,25 @@ class DanaRSService : DaggerService() { if (!isConnected) return result var msg: DanaRS_Packet_History_? = null when (type) { - RecordTypes.RECORD_TYPE_ALARM -> msg = DanaRS_Packet_History_Alarm(aapsLogger, rxBus) - RecordTypes.RECORD_TYPE_PRIME -> msg = DanaRS_Packet_History_Prime(aapsLogger, rxBus) - RecordTypes.RECORD_TYPE_BASALHOUR -> msg = DanaRS_Packet_History_Basal(aapsLogger, rxBus) - RecordTypes.RECORD_TYPE_BOLUS -> msg = DanaRS_Packet_History_Bolus(aapsLogger, rxBus) - RecordTypes.RECORD_TYPE_CARBO -> msg = DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus) - RecordTypes.RECORD_TYPE_DAILY -> msg = DanaRS_Packet_History_Daily(aapsLogger, rxBus) - RecordTypes.RECORD_TYPE_GLUCOSE -> msg = DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus) - RecordTypes.RECORD_TYPE_REFILL -> msg = DanaRS_Packet_History_Refill(aapsLogger, rxBus) - RecordTypes.RECORD_TYPE_SUSPEND -> msg = DanaRS_Packet_History_Suspend(aapsLogger, rxBus) + RecordTypes.RECORD_TYPE_ALARM -> msg = DanaRS_Packet_History_Alarm(injector) + RecordTypes.RECORD_TYPE_PRIME -> msg = DanaRS_Packet_History_Prime(injector) + RecordTypes.RECORD_TYPE_BASALHOUR -> msg = DanaRS_Packet_History_Basal(injector) + RecordTypes.RECORD_TYPE_BOLUS -> msg = DanaRS_Packet_History_Bolus(injector) + RecordTypes.RECORD_TYPE_CARBO -> msg = DanaRS_Packet_History_Carbohydrate(injector) + RecordTypes.RECORD_TYPE_DAILY -> msg = DanaRS_Packet_History_Daily(injector) + RecordTypes.RECORD_TYPE_GLUCOSE -> msg = DanaRS_Packet_History_Blood_Glucose(injector) + RecordTypes.RECORD_TYPE_REFILL -> msg = DanaRS_Packet_History_Refill(injector) + RecordTypes.RECORD_TYPE_SUSPEND -> msg = DanaRS_Packet_History_Suspend(injector) } if (msg != null) { - sendMessage(DanaRS_Packet_General_Set_History_Upload_Mode(aapsLogger, 1)) + sendMessage(DanaRS_Packet_General_Set_History_Upload_Mode(injector, 1)) SystemClock.sleep(200) sendMessage(msg) while (!msg.done && isConnected) { SystemClock.sleep(100) } SystemClock.sleep(200) - sendMessage(DanaRS_Packet_General_Set_History_Upload_Mode(aapsLogger, 0)) + sendMessage(DanaRS_Packet_General_Set_History_Upload_Mode(injector, 0)) } result.success = true result.comment = "OK" diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt index c5ed222313..d50ee1ba25 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt @@ -1,11 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump -import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import org.junit.Assert import org.junit.Test @@ -16,19 +17,36 @@ import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class, DanaRSPlugin::class) +@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) class DanaRSMessageHashTableTest : DanaRSTestBase() { @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet) { + it.aapsLogger = aapsLogger + } + if (it is DanaRS_Packet_Bolus_Set_Step_Bolus_Start) { + it.constraintChecker = constraintChecker + } + if (it is DanaRS_Packet_Bolus_Set_Step_Bolus_Start) { + it.danaRPump = danaRPump + } + if (it is DanaRS_Packet_APS_History_Events) { + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) - val danaRSMessageHashTable = DanaRSMessageHashTable(aapsLogger, rxBus, resourceHelper, danaRPump, activePlugin, constraintChecker, detailedBolusInfoStorage, sp, injector) - val forTesting: DanaRS_Packet = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, 0, 0, 0) + val danaRSMessageHashTable = DanaRSMessageHashTable(packetInjector) + val forTesting: DanaRS_Packet = DanaRS_Packet_APS_Set_Event_History(packetInjector, DanaRPump.CARBS, 0, 0, 0) val testPacket: DanaRS_Packet = danaRSMessageHashTable.findMessage(forTesting.command) Assert.assertEquals(BleEncryption.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY.toLong(), testPacket.getOpCode().toLong()) } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest.kt index 835a56be84..8672867161 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,30 +12,38 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_APS_Basal_Set_Temporary_Basal) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { // under 100% should last 30 min - var packet = DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, 0) + var packet = DanaRS_Packet_APS_Basal_Set_Temporary_Basal(packetInjector, 0) Assert.assertEquals(0, packet.temporaryBasalRatio) Assert.assertEquals(DanaRS_Packet_APS_Basal_Set_Temporary_Basal.PARAM30MIN, packet.temporaryBasalDuration) //constructor with param - packet = DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, 10) + packet = DanaRS_Packet_APS_Basal_Set_Temporary_Basal(packetInjector, 10) Assert.assertEquals(10, packet.temporaryBasalRatio) Assert.assertEquals(DanaRS_Packet_APS_Basal_Set_Temporary_Basal.PARAM30MIN, packet.temporaryBasalDuration) // over 100% should last 15 min - packet = DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, 150) + packet = DanaRS_Packet_APS_Basal_Set_Temporary_Basal(packetInjector, 150) Assert.assertEquals(150, packet.temporaryBasalRatio) Assert.assertEquals(DanaRS_Packet_APS_Basal_Set_Temporary_Basal.PARAM15MIN, packet.temporaryBasalDuration) // test low hard limit - packet = DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, -1) + packet = DanaRS_Packet_APS_Basal_Set_Temporary_Basal(packetInjector, -1) Assert.assertEquals(0, packet.temporaryBasalRatio) Assert.assertEquals(DanaRS_Packet_APS_Basal_Set_Temporary_Basal.PARAM30MIN, packet.temporaryBasalDuration) // test high hard limit - packet = DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, 550) + packet = DanaRS_Packet_APS_Basal_Set_Temporary_Basal(packetInjector, 550) Assert.assertEquals(500, packet.temporaryBasalRatio) Assert.assertEquals(DanaRS_Packet_APS_Basal_Set_Temporary_Basal.PARAM15MIN, packet.temporaryBasalDuration) // test message generation - packet = DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, 260) + packet = DanaRS_Packet_APS_Basal_Set_Temporary_Basal(packetInjector, 260) val generatedCode = packet.requestParams Assert.assertEquals(3, generatedCode.size.toLong()) Assert.assertEquals(4.toByte(), generatedCode[0]) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt index 49871ade89..97c7fbe1a5 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage @@ -20,10 +22,24 @@ class DanaRS_Packet_APS_History_EventsTest : DanaRSTestBase() { @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_APS_History_Events) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + it.resourceHelper = resourceHelper + it.activePlugin = activePlugin + it.danaRPump = danaRPump + it.detailedBolusInfoStorage = detailedBolusInfoStorage + it.sp = sp + } + } + } + @Test fun runTest() { val now = DateUtil.now() - val testPacket = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, sp, injector, now) + val testPacket = DanaRS_Packet_APS_History_Events(packetInjector, now) // test getRequestedParams val returnedValues = testPacket.requestParams val expectedValues = getCalender(now) @@ -45,7 +61,7 @@ class DanaRS_Packet_APS_History_EventsTest : DanaRSTestBase() { Assert.assertEquals("APS_HISTORY_EVENTS", testPacket.friendlyName) } - fun getCalender(from: Long): ByteArray { + private fun getCalender(from: Long): ByteArray { val cal = GregorianCalendar() if (from != 0L) cal.timeInMillis = from else cal[2000, 0, 1, 0, 0] = 0 val ret = ByteArray(6) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt index 33e343ee08..b252c07830 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.utils.DateUtil import org.junit.Assert @@ -12,21 +14,29 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_APS_Set_Event_HistoryTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_APS_Set_Event_History) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { // test for negative carbs val now = DateUtil.now() - var historyTest = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, now, -1, 0) + var historyTest = DanaRS_Packet_APS_Set_Event_History(packetInjector, DanaRPump.CARBS, now, -1, 0) var testparams = historyTest.requestParams Assert.assertEquals(0.toByte(), testparams[8]) // 5g carbs - historyTest = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, now, 5, 0) + historyTest = DanaRS_Packet_APS_Set_Event_History(packetInjector, DanaRPump.CARBS, now, 5, 0) testparams = historyTest.requestParams Assert.assertEquals(5.toByte(), testparams[8]) // 150g carbs - historyTest = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, now, 150, 0) + historyTest = DanaRS_Packet_APS_Set_Event_History(packetInjector, DanaRPump.CARBS, now, 150, 0) testparams = historyTest.requestParams Assert.assertEquals(150.toByte(), testparams[8]) // test message generation - historyTest = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, now, 5, 0) + historyTest = DanaRS_Packet_APS_Set_Event_History(packetInjector, DanaRPump.CARBS, now, 5, 0) testparams = historyTest.requestParams Assert.assertEquals(5.toByte(), testparams[8]) Assert.assertEquals(11, testparams.size) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_RateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_RateTest.kt index 2c5b7ffec1..aa79c64b03 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_RateTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_RateTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.plugins.bus.RxBusWrapper import org.junit.Assert import org.junit.Test @@ -11,9 +13,19 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(RxBusWrapper::class) class DanaRS_Packet_Basal_Get_Basal_RateTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Basal_Get_Basal_Rate) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + it.resourceHelper = resourceHelper + it.danaRPump = danaRPump + } + } + } @Test fun runTest() { - val packet = DanaRS_Packet_Basal_Get_Basal_Rate(aapsLogger, rxBus, resourceHelper, danaRPump) + val packet = DanaRS_Packet_Basal_Get_Basal_Rate(packetInjector) // test message decoding // rate is 0.01 val array = ByteArray(100) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_RateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_RateTest.kt index 59e6356f16..7cc2d5cb5c 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_RateTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_RateTest.kt @@ -1,23 +1,32 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Basal_Get_Profile_Basal_RateTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Basal_Get_Profile_Basal_Rate) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val testPacket = DanaRS_Packet_Basal_Get_Profile_Basal_Rate(aapsLogger, danaRPump, 1) + val testPacket = DanaRS_Packet_Basal_Get_Profile_Basal_Rate(packetInjector, 1) // test if pumpProfile array is set right - val basal01 = DanaRS_Packet.byteArrayToInt(DanaRS_Packet.getBytes(createArray(50, 1.toByte()), 2, 2)) / 100.0 - val basal05 = DanaRS_Packet.byteArrayToInt(DanaRS_Packet.getBytes(createArray(50, 5.toByte()), 2, 2)) / 100.0 - val basal12 = DanaRS_Packet.byteArrayToInt(DanaRS_Packet.getBytes(createArray(50, 12.toByte()), 2, 2)) / 100.0 + val basal01 = DanaRS_Packet.byteArrayToInt(DanaRS_Packet(packetInjector).getBytes(createArray(50, 1.toByte()), 2, 2)) / 100.0 + val basal05 = DanaRS_Packet.byteArrayToInt(DanaRS_Packet(packetInjector).getBytes(createArray(50, 5.toByte()), 2, 2)) / 100.0 + val basal12 = DanaRS_Packet.byteArrayToInt(DanaRS_Packet(packetInjector).getBytes(createArray(50, 12.toByte()), 2, 2)) / 100.0 // basal rate > 1U/hr - val basal120 = DanaRS_Packet.byteArrayToInt(DanaRS_Packet.getBytes(createArray(50, 120.toByte()), 2, 2)) / 100.0 + val basal120 = DanaRS_Packet.byteArrayToInt(DanaRS_Packet(packetInjector).getBytes(createArray(50, 120.toByte()), 2, 2)) / 100.0 val params = testPacket.requestParams assertEquals(1.toByte(), params[0]) testPacket.handleMessage(createArray(50, 0.toByte())) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_NumberTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_NumberTest.kt index f8468573cd..458370fdc5 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_NumberTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_NumberTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,8 +12,17 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_Basal_Get_Profile_NumberTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Basal_Get_Profile_Number) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Basal_Get_Profile_Number(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Basal_Get_Profile_Number(packetInjector) val array = ByteArray(100) putByteToArray(array, 0, 1.toByte()) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt index f8e3472c8e..115dba03b0 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,8 +12,17 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Basal_Get_Temporary_Basal_State) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Basal_Get_Temporary_Basal_State(packetInjector) // test message decoding val array = ByteArray(100) putByteToArray(array, 0, 1.toByte()) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.kt index d4e2b2de06..58d89e6220 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,9 +12,17 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_Basal_Set_Basal_RateTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Basal_Set_Basal_Rate) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { // test message decoding - val packet = DanaRS_Packet_Basal_Set_Basal_Rate(aapsLogger, createArray(24, 5.0)) + val packet = DanaRS_Packet_Basal_Set_Basal_Rate(packetInjector, createArray(24, 5.0)) val requested = packet.requestParams var lookingFor = (5 * 100 and 0xff).toByte() Assert.assertEquals(lookingFor, requested[24]) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.kt index 4c127cf437..a48dc769eb 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,8 +12,16 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger) + val packet = DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(packetInjector) // test message decoding packet.handleMessage(createArray(3, 0.toByte())) Assert.assertEquals(false, packet.failed) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_RateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_RateTest.kt index d2d918726f..035387ac85 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_RateTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_RateTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,8 +12,16 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_Basal_Set_Profile_Basal_RateTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Basal_Set_Profile_Basal_Rate) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Basal_Set_Profile_Basal_Rate(aapsLogger, 1, createArray(24, 1.0)) + val packet = DanaRS_Packet_Basal_Set_Profile_Basal_Rate(packetInjector, 1, createArray(24, 1.0)) // test params val testparams = packet.requestParams // is profile 1 diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_NumberTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_NumberTest.kt index 8b15bf2863..a39c2efde9 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_NumberTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_NumberTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,8 +12,16 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_Basal_Set_Profile_NumberTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Basal_Set_Profile_Number) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Basal_Set_Profile_Number(aapsLogger, 1) + val packet = DanaRS_Packet_Basal_Set_Profile_Number(packetInjector, 1) // test params val testparams = packet.requestParams // is profile 1 diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_OffTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_OffTest.kt index aa6d5832ad..50ce4c0c35 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_OffTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_OffTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,8 +12,16 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_Basal_Set_Suspend_OffTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Basal_Set_Suspend_Off) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Basal_Set_Suspend_Off(aapsLogger) + val packet = DanaRS_Packet_Basal_Set_Suspend_Off(packetInjector) // test message decoding packet.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte())) Assert.assertEquals(false, packet.failed) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_OnTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_OnTest.kt index cb12a85d1d..3665cd96b1 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_OnTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_OnTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,8 +12,16 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_Basal_Set_Suspend_OnTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Basal_Set_Suspend_On) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Basal_Set_Suspend_On(aapsLogger) + val packet = DanaRS_Packet_Basal_Set_Suspend_On(packetInjector) // test message decoding packet.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte())) Assert.assertEquals(false, packet.failed) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_BasalTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_BasalTest.kt index d15dff5c39..6fccfdcb81 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_BasalTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_BasalTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -7,11 +9,18 @@ import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Basal_Set_Temporary_BasalTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Basal_Set_Temporary_Basal) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val testPacket = DanaRS_Packet_Basal_Set_Temporary_Basal(aapsLogger, 50, 20) + val testPacket = DanaRS_Packet_Basal_Set_Temporary_Basal(packetInjector, 50, 20) // params val params = testPacket.requestParams // is ratio 50 diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_OptionTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_OptionTest.kt index 1b83b1df86..ac17776c70 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_OptionTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_OptionTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.plugins.bus.RxBusWrapper import org.junit.Assert import org.junit.Test @@ -11,8 +13,19 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(RxBusWrapper::class) class DanaRS_Packet_Bolus_Get_Bolus_OptionTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Get_Bolus_Option) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + it.resourceHelper = resourceHelper + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Get_Bolus_Option(aapsLogger, rxBus, resourceHelper, danaRPump) + val packet = DanaRS_Packet_Bolus_Get_Bolus_Option(packetInjector) // test message decoding //if dataArray is 1 pump.isExtendedBolusEnabled should be true packet.handleMessage(createArray(21, 1.toByte())) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_ArrayTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_ArrayTest.kt index 19f9fc5fbd..997014a92b 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_ArrayTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_ArrayTest.kt @@ -1,18 +1,27 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Bolus_Get_CIR_CF_ArrayTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Get_CIR_CF_Array) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Get_CIR_CF_Array(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Bolus_Get_CIR_CF_Array(packetInjector) // test params Assert.assertEquals(null, packet.requestParams) // test message decoding diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_InformationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_InformationTest.kt index 4a805821b1..f09c01657f 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_InformationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_InformationTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,8 +12,17 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_Bolus_Get_Calculation_InformationTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Get_Calculation_Information) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Get_Calculation_Information(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Bolus_Get_Calculation_Information(packetInjector) Assert.assertEquals(null, packet.requestParams) // test message decoding packet.handleMessage(createArray(24, 0.toByte())) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_InformationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_InformationTest.kt index b344cf3ade..effd2fa235 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_InformationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_InformationTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,8 +12,17 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_InformationTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information(packetInjector) Assert.assertEquals(null, packet.requestParams) // test message decoding packet.handleMessage(createArray(24, 0.toByte())) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_BolusTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_BolusTest.kt index 315ac6f045..19ade4619b 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_BolusTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_BolusTest.kt @@ -1,17 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Bolus_Get_Dual_BolusTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Get_Dual_Bolus) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Get_Dual_Bolus(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Bolus_Get_Dual_Bolus(packetInjector) // test params Assert.assertEquals(null, packet.requestParams) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_BolusTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_BolusTest.kt index a62d960cdc..3d54ad98bc 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_BolusTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_BolusTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,8 +12,17 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_Bolus_Get_Extended_BolusTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Get_Extended_Bolus) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Get_Extended_Bolus(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Bolus_Get_Extended_Bolus(packetInjector) // test params Assert.assertEquals(null, packet.requestParams) // test message decoding diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_StateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_StateTest.kt index c950a2b8e7..1e2af1ae1e 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_StateTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_StateTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,8 +12,17 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_Bolus_Get_Extended_Bolus_StateTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Get_Extended_Bolus_State) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Get_Extended_Bolus_State(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Bolus_Get_Extended_Bolus_State(packetInjector) // test params Assert.assertEquals(null, packet.requestParams) // test message decoding diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_StateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_StateTest.kt index 4dab05c2cf..c489cc6677 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_StateTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_StateTest.kt @@ -1,17 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Bolus_Get_Extended_Menu_Option_StateTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State(packetInjector) Assert.assertEquals(null, packet.requestParams) // test message decoding packet.handleMessage(createArray(34, 0.toByte())) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_BolusTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_BolusTest.kt index c9f2529bb7..6976effbdb 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_BolusTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_BolusTest.kt @@ -1,17 +1,25 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Bolus_Get_Initial_BolusTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Get_Initial_Bolus) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Get_Initial_Bolus(aapsLogger) + val packet = DanaRS_Packet_Bolus_Get_Initial_Bolus(packetInjector) Assert.assertEquals(null, packet.requestParams) // test message decoding packet.handleMessage(createArray(34, 0.toByte())) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt index c3ac9a12d6..254862a8db 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -11,8 +13,17 @@ import java.util.* @PrepareForTest() class DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Get_Step_Bolus_Information) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Bolus_Get_Step_Bolus_Information(packetInjector) val array = createArray(13, 0.toByte()) // 11 + 2 putByteToArray(array, 0, 2) // error 2 diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_OptionTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_OptionTest.kt index b79f14552b..b4bfc7018a 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_OptionTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_OptionTest.kt @@ -1,17 +1,25 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Bolus_Set_Bolus_OptionTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Set_Bolus_Option) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Set_Bolus_Option(aapsLogger, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + val packet = DanaRS_Packet_Bolus_Set_Bolus_Option(packetInjector, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) // test params val testparams = packet.requestParams Assert.assertEquals(0.toByte(), testparams[0]) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_ArrayTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_ArrayTest.kt index df29bd2439..b749f9fb99 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_ArrayTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_ArrayTest.kt @@ -1,17 +1,25 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Bolus_Set_CIR_CF_ArrayTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Set_CIR_CF_Array) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Set_CIR_CF_Array(aapsLogger, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + val packet = DanaRS_Packet_Bolus_Set_CIR_CF_Array(packetInjector, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) // test params val testparams = packet.requestParams Assert.assertEquals(0.toByte(), testparams[0]) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_BolusTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_BolusTest.kt index 0e60b237d7..2aeba32298 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_BolusTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_BolusTest.kt @@ -1,17 +1,25 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Bolus_Set_Dual_BolusTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Set_Dual_Bolus) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Set_Dual_Bolus(aapsLogger, 0.0, 0.0, 1) + val packet = DanaRS_Packet_Bolus_Set_Dual_Bolus(packetInjector, 0.0, 0.0, 1) // test params val testparams = packet.requestParams Assert.assertEquals(0.toByte(), testparams[0]) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_BolusTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_BolusTest.kt index 173a87b423..55f3620850 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_BolusTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_BolusTest.kt @@ -1,17 +1,25 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Bolus_Set_Extended_BolusTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Set_Extended_Bolus) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Set_Extended_Bolus(aapsLogger, 1.0, 1) + val packet = DanaRS_Packet_Bolus_Set_Extended_Bolus(packetInjector, 1.0, 1) // test params val testparams = packet.requestParams Assert.assertEquals(100.toByte(), testparams[0]) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_CancelTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_CancelTest.kt index adf2ec11f2..2f0615f9c2 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_CancelTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_CancelTest.kt @@ -1,17 +1,25 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Bolus_Set_Extended_Bolus_CancelTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel(aapsLogger) + val packet = DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel(packetInjector) Assert.assertEquals(null, packet.requestParams) // test message decoding packet.handleMessage(createArray(34, 0.toByte())) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_BolusTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_BolusTest.kt index 29513ced1a..1fb3c6928d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_BolusTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_BolusTest.kt @@ -1,17 +1,25 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Bolus_Set_Initial_BolusTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Set_Initial_Bolus) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Set_Initial_Bolus(aapsLogger, 0, 0, 0, 100) + val packet = DanaRS_Packet_Bolus_Set_Initial_Bolus(packetInjector, 0, 0, 0, 100) // test params val testparams = packet.requestParams Assert.assertEquals(0.toByte(), testparams[0]) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt index 7b740531a0..d4b53cffcd 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt @@ -6,7 +6,6 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import org.junit.Assert @@ -29,8 +28,18 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() { private lateinit var danaRSPlugin: DanaRSPlugin + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Bolus_Set_Step_Bolus_Start) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + it.constraintChecker = constraintChecker + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Bolus_Set_Step_Bolus_Start(aapsLogger, danaRPump, constraintChecker) + val packet = DanaRS_Packet_Bolus_Set_Step_Bolus_Start(packetInjector) // test params val testparams = packet.requestParams Assert.assertEquals(0.toByte(), testparams[0]) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt index 8b0f24ff32..2605b0ba72 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt @@ -4,10 +4,8 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.treatments.Treatment -import info.nightscout.androidaps.utils.DefaultValueHelper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -23,8 +21,14 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest : DanaRSTestBase() { @Mock lateinit var activePlugin: ActivePluginProvider - private var treatmentInjector: HasAndroidInjector = HasAndroidInjector { + private val packetInjector = HasAndroidInjector { AndroidInjector { + if (it is DanaRS_Packet_Bolus_Set_Step_Bolus_Stop) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + it.resourceHelper = resourceHelper + it.danaRPump = danaRPump + } if (it is Treatment) { it.defaultValueHelper = defaultValueHelper it.resourceHelper = resourceHelper @@ -37,8 +41,8 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest : DanaRSTestBase() { @Test fun runTest() { `when`(resourceHelper.gs(Mockito.anyInt())).thenReturn("SomeString") - danaRPump.bolusingTreatment = Treatment(treatmentInjector) - val testPacket = DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(aapsLogger, rxBus, resourceHelper, danaRPump) + danaRPump.bolusingTreatment = Treatment(packetInjector) + val testPacket = DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(packetInjector) // test message decoding testPacket.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte())) Assert.assertEquals(false, testPacket.failed) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_ConnectionTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_ConnectionTest.kt index e1b90f30da..1a8b2e6fbc 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_ConnectionTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_ConnectionTest.kt @@ -1,17 +1,25 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Etc_Keep_ConnectionTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Etc_Keep_Connection) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Etc_Keep_Connection(aapsLogger) + val packet = DanaRS_Packet_Etc_Keep_Connection(packetInjector) Assert.assertEquals(null, packet.requestParams) // test message decoding packet.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte())) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_SaveTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_SaveTest.kt index a089eafd9a..cb82f0b277 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_SaveTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_SaveTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,8 +12,16 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_Etc_Set_History_SaveTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Etc_Set_History_Save) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Etc_Set_History_Save(aapsLogger, 0, 0, 0, 0, 0, 0, 0, 0, 2) + val packet = DanaRS_Packet_Etc_Set_History_Save(packetInjector, 0, 0, 0, 0, 0, 0, 0, 0, 2) // test params val testparams = packet.requestParams Assert.assertEquals(2.toByte(), testparams[8]) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_StatusTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_StatusTest.kt index fd32e3ca30..6515062bb0 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_StatusTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_StatusTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,8 +12,16 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_General_Delivery_StatusTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_General_Delivery_Status) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_General_Delivery_Status(aapsLogger) + val packet = DanaRS_Packet_General_Delivery_Status(packetInjector) Assert.assertEquals(null, packet.requestParams) // test message decoding packet.handleMessage(createArray(15, 0.toByte())) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt index 12ff721a2b..d3f96c2e11 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -9,13 +11,22 @@ import java.util.* @RunWith(PowerMockRunner::class) class DanaRS_Packet_General_Get_More_InformationTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_General_Get_More_Information) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - var packet = DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump) + var packet = DanaRS_Packet_General_Get_More_Information(packetInjector) packet.handleMessage(createArray(14, 0.toByte())) Assert.assertTrue(packet.failed) - packet = DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump) + packet = DanaRS_Packet_General_Get_More_Information(packetInjector) val array = createArray(15, 0.toByte()) // 13 + 2 putIntToArray(array, 0, 600) // iob 6 putIntToArray(array, 2, 1250) // daily units 12.5 diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_PasswordTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_PasswordTest.kt index 88f3ac3496..eac2fc9127 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_PasswordTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_PasswordTest.kt @@ -1,23 +1,32 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_General_Get_PasswordTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_General_Get_Password) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - var packet = DanaRS_Packet_General_Get_Password(aapsLogger, danaRPump) + var packet = DanaRS_Packet_General_Get_Password(packetInjector) Assert.assertEquals(null, packet.requestParams) // test message decoding // test for the length message packet.handleMessage(createArray(1, 0.toByte())) Assert.assertEquals(true, packet.failed) - packet = DanaRS_Packet_General_Get_Password(aapsLogger, danaRPump) + packet = DanaRS_Packet_General_Get_Password(packetInjector) packet.handleMessage(createArray(15, 0.toByte())) Assert.assertEquals(false, packet.failed) Assert.assertEquals("REVIEW__GET_PASSWORD", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_CheckTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_CheckTest.kt index 5248c2b699..ed6a23541f 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_CheckTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_CheckTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.plugins.bus.RxBusWrapper import org.junit.Assert import org.junit.Test @@ -11,14 +13,25 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(RxBusWrapper::class) class DanaRS_Packet_General_Get_Pump_CheckTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_General_Get_Pump_Check) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + it.resourceHelper = resourceHelper + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - var packet = DanaRS_Packet_General_Get_Pump_Check(aapsLogger, danaRPump, rxBus, resourceHelper) + var packet = DanaRS_Packet_General_Get_Pump_Check(packetInjector) Assert.assertEquals(null, packet.requestParams) // test message decoding // test for the length message packet.handleMessage(createArray(1, 0.toByte())) Assert.assertEquals(true, packet.failed) - packet = DanaRS_Packet_General_Get_Pump_Check(aapsLogger, danaRPump, rxBus, resourceHelper) + packet = DanaRS_Packet_General_Get_Pump_Check(packetInjector) packet.handleMessage(createArray(15, 0.toByte())) Assert.assertEquals(false, packet.failed) Assert.assertEquals("REVIEW__GET_PUMP_CHECK", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt index 3de89db27b..d8c4e0fe66 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -8,15 +10,24 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) class DanaRS_Packet_General_Get_Shipping_InformationTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_General_Get_Shipping_Information) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - var packet = DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump) + var packet = DanaRS_Packet_General_Get_Shipping_Information(packetInjector) Assert.assertEquals(null, packet.requestParams) // test message decoding // test for the length message packet.handleMessage(createArray(1, 0.toByte())) Assert.assertEquals(true, packet.failed) // everything ok :) - packet = DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump) + packet = DanaRS_Packet_General_Get_Shipping_Information(packetInjector) packet.handleMessage(createArray(18, 0.toByte())) Assert.assertEquals(false, packet.failed) Assert.assertEquals("REVIEW__GET_SHIPPING_INFORMATION", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_VerisonTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_VerisonTest.kt index f962560115..7aef230f52 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_VerisonTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_VerisonTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -8,8 +10,17 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) class DanaRS_Packet_General_Get_Shipping_VerisonTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_General_Get_Shipping_Version) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_General_Get_Shipping_Version(aapsLogger, danaRPump) + val packet = DanaRS_Packet_General_Get_Shipping_Version(packetInjector) // test message decoding val ver = byteArrayOf((-78).toByte(), (-127).toByte(), (66).toByte(), (80).toByte(), (78).toByte(), (45).toByte(), (51).toByte(), (46).toByte(), (48).toByte(), (46).toByte(), (48).toByte()) packet.handleMessage(ver) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_TotalTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_TotalTest.kt index 1e89db2771..8c2092a425 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_TotalTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_TotalTest.kt @@ -1,23 +1,32 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_General_Get_Today_Delivery_TotalTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_General_Get_Today_Delivery_Total) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - var packet = DanaRS_Packet_General_Get_Today_Delivery_Total(aapsLogger, danaRPump) + var packet = DanaRS_Packet_General_Get_Today_Delivery_Total(packetInjector) Assert.assertEquals(null, packet.requestParams) // test message decoding // test for the length message packet.handleMessage(createArray(1, 0.toByte())) Assert.assertEquals(true, packet.failed) - packet = DanaRS_Packet_General_Get_Today_Delivery_Total(aapsLogger, danaRPump) + packet = DanaRS_Packet_General_Get_Today_Delivery_Total(packetInjector) packet.handleMessage(createArray(18, 0.toByte())) Assert.assertEquals(false, packet.failed) packet.handleMessage(createArray(15, 1.toByte())) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_FlagTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_FlagTest.kt index 18f89e1096..2dc51fb3af 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_FlagTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_FlagTest.kt @@ -1,23 +1,31 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_General_Get_User_Time_Change_FlagTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_General_Get_User_Time_Change_Flag) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - var packet = DanaRS_Packet_General_Get_User_Time_Change_Flag(aapsLogger) + var packet = DanaRS_Packet_General_Get_User_Time_Change_Flag(packetInjector) Assert.assertEquals(null, packet.requestParams) // test message decoding // test for the length message packet.handleMessage(createArray(1, 0.toByte())) Assert.assertEquals(true, packet.failed) - packet = DanaRS_Packet_General_Get_User_Time_Change_Flag(aapsLogger) + packet = DanaRS_Packet_General_Get_User_Time_Change_Flag(packetInjector) packet.handleMessage(createArray(18, 0.toByte())) Assert.assertEquals(false, packet.failed) Assert.assertEquals("REVIEW__GET_USER_TIME_CHANGE_FLAG", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_InformationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_InformationTest.kt index 15e9f8e99b..9f878e0be1 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_InformationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_InformationTest.kt @@ -1,23 +1,32 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_General_Initial_Screen_InformationTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_General_Initial_Screen_Information) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - var packet = DanaRS_Packet_General_Initial_Screen_Information(aapsLogger, danaRPump) + var packet = DanaRS_Packet_General_Initial_Screen_Information(packetInjector) Assert.assertEquals(null, packet.requestParams) // test message decoding // test for the length message packet.handleMessage(createArray(1, 0.toByte())) Assert.assertEquals(true, packet.failed) - packet = DanaRS_Packet_General_Initial_Screen_Information(aapsLogger, danaRPump) + packet = DanaRS_Packet_General_Initial_Screen_Information(packetInjector) packet.handleMessage(createArray(17, 1.toByte())) Assert.assertEquals(false, packet.failed) Assert.assertEquals(true, danaRPump.pumpSuspended) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_ModeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_ModeTest.kt index d918e9d682..b0e0867b4c 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_ModeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_ModeTest.kt @@ -1,17 +1,25 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_General_Set_History_Upload_ModeTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_General_Set_History_Upload_Mode) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_General_Set_History_Upload_Mode(aapsLogger, 1) + val packet = DanaRS_Packet_General_Set_History_Upload_Mode(packetInjector, 1) // test params Assert.assertEquals(1.toByte(), packet.requestParams[0]) // test message decoding diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_ClearTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_ClearTest.kt index 45e472af3c..2ee55972da 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_ClearTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_ClearTest.kt @@ -1,17 +1,25 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_General_Set_User_Time_Change_Flag_ClearTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear(aapsLogger) + val packet = DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear(packetInjector) // test params Assert.assertEquals(null, packet.requestParams) // test message decoding diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt index bc10832af9..4ebf521537 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.db.DatabaseHelper import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes @@ -26,9 +28,18 @@ class DanaRS_Packet_History_AlarmTest : DanaRSTestBase() { `when`(MainApp.getDbHelper()).thenReturn(databaseHelper) } + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_History_Alarm) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_History_Alarm(aapsLogger, rxBus, 0) + val packet = DanaRS_Packet_History_Alarm(packetInjector, 0) val array = createArray(12, 0.toByte()) // 10 + 2 putByteToArray(array, 0, 0x0A) // record code alarm diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt index 1f7dd00783..8730eaddec 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt @@ -1,17 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_History_All_HistoryTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_History_All_History) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_History_All_History(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_All_History(packetInjector, System.currentTimeMillis()) Assert.assertEquals("REVIEW__ALL_HISTORY", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt index 8451e90b0f..08910af3b0 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt @@ -1,17 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_History_BasalTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_History_Basal) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_History_Basal(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Basal(packetInjector, System.currentTimeMillis()) Assert.assertEquals("REVIEW__BASAL", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt index 0442ea98b9..c6ad86d977 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt @@ -1,17 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_History_Blood_GlucoseTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_History_Blood_Glucose) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Blood_Glucose(packetInjector, System.currentTimeMillis()) Assert.assertEquals("REVIEW__BLOOD_GLUCOSE", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt index badaa0aa10..0417bc22ae 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt @@ -1,17 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_History_BolusTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_History_Bolus) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_History_Bolus(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Bolus(packetInjector, System.currentTimeMillis()) Assert.assertEquals("REVIEW__BOLUS", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt index 22a99fcc53..8efec691e0 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt @@ -1,17 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_History_CarbohydrateTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_History_Carbohydrate) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Carbohydrate(packetInjector, System.currentTimeMillis()) Assert.assertEquals("REVIEW__CARBOHYDRATE", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt index 91d4bea862..2a4bc6b533 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt @@ -1,17 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_History_DailyTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_History_Daily) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_History_Daily(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Daily(packetInjector, System.currentTimeMillis()) Assert.assertEquals("REVIEW__DAILY", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt index 19c8d2ef4e..f56216ce4c 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt @@ -1,17 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_History_PrimeTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_History_Prime) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_History_Prime(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Prime(packetInjector, System.currentTimeMillis()) Assert.assertEquals("REVIEW__PRIME", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt index 8b75ec344f..d83499bce4 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt @@ -1,17 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_History_RefillTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_History_Refill) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_History_Refill(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Refill(packetInjector, System.currentTimeMillis()) Assert.assertEquals("REVIEW__REFILL", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt index 66b06f4ed7..f02425c546 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt @@ -1,17 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_History_SuspendTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_History_Suspend) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_History_Suspend(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Suspend(packetInjector, System.currentTimeMillis()) Assert.assertEquals("REVIEW__SUSPEND", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt index a4e436a373..76dc831eed 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt @@ -1,17 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_History_TemporaryTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_History_Temporary) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_History_Temporary(aapsLogger, rxBus, System.currentTimeMillis()) + val packet = DanaRS_Packet_History_Temporary(packetInjector, System.currentTimeMillis()) Assert.assertEquals("REVIEW__TEMPORARY", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_AlarmTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_AlarmTest.kt index 58e0b738db..f10bb50efd 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_AlarmTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_AlarmTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import org.junit.Assert import org.junit.Before @@ -13,8 +15,18 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(NSUpload::class) class DanaRS_Packet_Notify_AlarmTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Notify_Alarm) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + it.resourceHelper = resourceHelper + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Notify_Alarm(aapsLogger, resourceHelper, rxBus) + val packet = DanaRS_Packet_Notify_Alarm(packetInjector) // test params Assert.assertEquals(null, packet.requestParams) // test message decoding diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt index 83d9d06182..31c9bbe726 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt @@ -4,10 +4,8 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.treatments.Treatment -import info.nightscout.androidaps.utils.DefaultValueHelper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -25,8 +23,14 @@ class DanaRS_Packet_Notify_Delivery_CompleteTest : DanaRSTestBase() { @Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var activePlugin: ActivePluginProvider - private var treatmentInjector: HasAndroidInjector = HasAndroidInjector { + private val packetInjector = HasAndroidInjector { AndroidInjector { + if (it is DanaRS_Packet_Notify_Delivery_Complete) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + it.resourceHelper = resourceHelper + it.danaRPump = danaRPump + } if (it is Treatment) { it.defaultValueHelper = defaultValueHelper it.resourceHelper = resourceHelper @@ -39,8 +43,8 @@ class DanaRS_Packet_Notify_Delivery_CompleteTest : DanaRSTestBase() { @Test fun runTest() { `when`(resourceHelper.gs(anyInt(), anyDouble())).thenReturn("SomeString") - danaRPump.bolusingTreatment = Treatment(treatmentInjector) - val packet = DanaRS_Packet_Notify_Delivery_Complete(aapsLogger, rxBus, resourceHelper, danaRPump) + danaRPump.bolusingTreatment = Treatment(packetInjector) + val packet = DanaRS_Packet_Notify_Delivery_Complete(packetInjector) // test params Assert.assertEquals(null, packet.requestParams) // test message decoding diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt index 69bf3789b1..03712fa1c0 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt @@ -7,11 +7,9 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.treatments.Treatment -import info.nightscout.androidaps.utils.DefaultValueHelper import org.junit.Assert import org.junit.Before import org.junit.Test @@ -34,8 +32,14 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() { private lateinit var danaRSPlugin: DanaRSPlugin - private var treatmentInjector: HasAndroidInjector = HasAndroidInjector { + private val packetInjector = HasAndroidInjector { AndroidInjector { + if (it is DanaRS_Packet_Notify_Delivery_Rate_Display) { + it.aapsLogger = aapsLogger + it.rxBus = rxBus + it.resourceHelper = resourceHelper + it.danaRPump = danaRPump + } if (it is Treatment) { it.defaultValueHelper = defaultValueHelper it.resourceHelper = resourceHelper @@ -48,7 +52,7 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() { @Test fun runTest() { `when`(resourceHelper.gs(ArgumentMatchers.anyInt(), anyObject())).thenReturn("SomeString") // val packet = DanaRS_Packet_Notify_Delivery_Rate_Display(1.0, Treatment(treatmentInjector)) - val packet = DanaRS_Packet_Notify_Delivery_Rate_Display(aapsLogger, rxBus, resourceHelper, danaRPump) + val packet = DanaRS_Packet_Notify_Delivery_Rate_Display(packetInjector) // test params Assert.assertEquals(null, packet.requestParams) // test message decoding @@ -64,6 +68,6 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() { @Before fun mock() { danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, fabricPrivacy) - danaRPump.bolusingTreatment = Treatment(treatmentInjector) + danaRPump.bolusingTreatment = Treatment(packetInjector) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_AlarmTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_AlarmTest.kt index 9583c89d4e..9eae04dbec 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_AlarmTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_AlarmTest.kt @@ -1,17 +1,25 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Notify_Missed_Bolus_AlarmTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Notify_Missed_Bolus_Alarm) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Notify_Missed_Bolus_Alarm(aapsLogger) + val packet = DanaRS_Packet_Notify_Missed_Bolus_Alarm(packetInjector) // test params Assert.assertEquals(null, packet.requestParams) // test message decoding diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt index 2ac915644f..4d63163c4b 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.joda.time.DateTime import org.junit.Assert import org.junit.Test @@ -9,8 +11,17 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) class DanaRS_Packet_Option_Get_Pump_TimeTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Option_Get_Pump_Time) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Option_Get_Pump_Time(packetInjector) val array = createArray(8, 0.toByte()) // 6 + 2 putByteToArray(array, 0, 19) // year 2019 putByteToArray(array, 1, 2) // month february diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_OptionTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_OptionTest.kt index 32e3b051c6..4412f5b1fb 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_OptionTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_OptionTest.kt @@ -1,17 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Option_Get_User_OptionTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Option_Get_User_Option) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Option_Get_User_Option(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Option_Get_User_Option(packetInjector) // test params Assert.assertEquals(null, packet.requestParams) // test message decoding diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt index bf34d76510..f2fd2ad61c 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -9,12 +11,20 @@ import java.util.* @RunWith(PowerMockRunner::class) class DanaRS_Packet_Option_Set_Pump_TimeTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Option_Set_Pump_Time) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { val date = Date() - val packet = DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, date.time) + val packet = DanaRS_Packet_Option_Set_Pump_Time(packetInjector, date.time) // test params val params = packet.requestParams - Assert.assertEquals((date.year - 100 and 0xff).toByte(), params[0]) // 2019 -> 19 + Assert.assertEquals((date.year - 100 and 0xff).toByte(), params[0]) // 2019 -> 19 Assert.assertEquals((date.month + 1 and 0xff).toByte(), params[1]) Assert.assertEquals((date.date and 0xff).toByte(), params[2]) Assert.assertEquals((date.hours and 0xff).toByte(), params[3]) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_OptionTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_OptionTest.kt index 30d076e037..6f53976045 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_OptionTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_OptionTest.kt @@ -1,17 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Option_Set_User_OptionTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Option_Set_User_Option) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Option_Set_User_Option(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Option_Set_User_Option(packetInjector) // test params val params = packet.requestParams Assert.assertEquals((danaRPump.lcdOnTimeSec and 0xff).toByte(), params[3]) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_AvgTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_AvgTest.kt index ff5dc4ce80..2842e99c74 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_AvgTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_AvgTest.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -10,8 +12,16 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_Review_Bolus_AvgTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Review_Bolus_Avg) { + it.aapsLogger = aapsLogger + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Review_Bolus_Avg(aapsLogger) + val packet = DanaRS_Packet_Review_Bolus_Avg(packetInjector) // test params Assert.assertEquals(null, packet.requestParams) // test message decoding diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_RatioTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_RatioTest.kt index 4bd5bbbd1a..9c5a6f824c 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_RatioTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_RatioTest.kt @@ -1,17 +1,26 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() class DanaRS_Packet_Review_Get_Pump_Dec_RatioTest : DanaRSTestBase() { + private val packetInjector = HasAndroidInjector { + AndroidInjector { + if (it is DanaRS_Packet_Review_Get_Pump_Dec_Ratio) { + it.aapsLogger = aapsLogger + it.danaRPump = danaRPump + } + } + } + @Test fun runTest() { - val packet = DanaRS_Packet_Review_Get_Pump_Dec_Ratio(aapsLogger, danaRPump) + val packet = DanaRS_Packet_Review_Get_Pump_Dec_Ratio(packetInjector) val array = ByteArray(100) putByteToArray(array, 0, 4.toByte()) From bce3d3b6b9a1f7b628163d2b07dadddc3f116e74 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 2 May 2020 00:17:39 +0200 Subject: [PATCH 17/53] Verify RSv1 password --- .../dependencyInjection/AppComponent.kt | 3 +- .../dependencyInjection/AppModule.kt | 2 +- .../plugins/pump/danaR/DanaRPump.kt | 6 +- .../plugins/pump/danaRS/DanaRSPlugin.kt | 77 ++++++++++--------- .../plugins/pump/danaRS/services/BLEComm.kt | 21 +++-- app/src/main/res/values/strings.xml | 3 +- app/src/main/res/values/validator.xml | 2 + app/src/main/res/xml/pref_danars.xml | 21 ++--- 8 files changed, 76 insertions(+), 59 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt index 91153bd867..0bb89f83c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt @@ -67,7 +67,8 @@ import javax.inject.Singleton PreferencesModule::class, OverviewModule::class, DataClassesModule::class, - SMSModule::class + SMSModule::class, + DanaRSCommModule::class ] ) interface AppComponent : AndroidInjector { diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index 48b599c488..871f88a503 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -74,7 +74,7 @@ import info.nightscout.androidaps.utils.wizard.BolusWizard import info.nightscout.androidaps.utils.wizard.QuickWizardEntry import javax.inject.Singleton -@Module(includes = [AppModule.AppBindings::class, PluginsModule::class, DanaRSCommModule::class]) +@Module(includes = [AppModule.AppBindings::class, PluginsModule::class]) open class AppModule { @Provides diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt index b9a5509b54..8b50a1670a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt @@ -119,6 +119,7 @@ class DanaRPump @Inject constructor( // DanaRS specific var rsPassword = "" + var v3RSPump = false; // User settings var timeDisplayType = 0 @@ -219,7 +220,10 @@ class DanaRPump @Inject constructor( } val isPasswordOK: Boolean - get() = !(password != -1 && password != sp.getInt(R.string.key_danar_password, -1)) + get() = password == sp.getInt(R.string.key_danar_password, -2) + + val isRSPasswordOK: Boolean + get() = rsPassword.equals(sp.getString(R.string.key_danars_password, ""), ignoreCase = true) fun reset() { aapsLogger.debug(LTag.PUMP, "DanaRPump reset") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt index 53062a3c93..7bed59fdfa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt @@ -81,7 +81,15 @@ class DanaRSPlugin @Inject constructor( override fun updatePreferenceSummary(pref: Preference) { super.updatePreferenceSummary(pref) - if (pref.key == resourceHelper.gs(R.string.key_danars_name)) pref.summary = sp.getString(R.string.key_danars_name, "") + + if (pref.key == resourceHelper.gs(R.string.key_danars_name)) { + val value = sp.getStringOrNull(R.string.key_danars_name, null) + pref.summary = value + ?: resourceHelper.gs(R.string.rileylink_error_address_not_set_short) + } + if (pref.key == resourceHelper.gs(R.string.key_danars_password)) { + if (danaRPump.v3RSPump) pref + } } override fun onStart() { @@ -204,7 +212,7 @@ class DanaRSPlugin @Inject constructor( // Pump interface override fun isInitialized(): Boolean { - return danaRPump.lastConnection > 0 && danaRPump.maxBasal > 0 + return danaRPump.lastConnection > 0 && danaRPump.maxBasal > 0 && danaRPump.isRSPasswordOK } override fun isSuspended(): Boolean { @@ -402,7 +410,6 @@ class DanaRSPlugin @Inject constructor( @Synchronized override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean): PumpEnactResult { - val pump = danaRPump val result = PumpEnactResult(injector) var percentAfterConstraint = constraintChecker.applyBasalPercentConstraints(Constraint(percent), profile).value() if (percentAfterConstraint < 0) { @@ -421,8 +428,8 @@ class DanaRSPlugin @Inject constructor( result.success = true result.isTempCancel = false result.comment = resourceHelper.gs(R.string.virtualpump_resultok) - result.duration = pump.tempBasalRemainingMin - result.percent = pump.tempBasalPercent + result.duration = danaRPump.tempBasalRemainingMin + result.percent = danaRPump.tempBasalPercent result.isPercent = true aapsLogger.debug(LTag.PUMP, "setTempBasalPercent: Correct value already set") return result @@ -435,13 +442,13 @@ class DanaRSPlugin @Inject constructor( val durationInHours = max(durationInMinutes / 60, 1) danaRSService?.tempBasal(percentAfterConstraint, durationInHours) ?: false } - if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percentAfterConstraint) { + if (connectionOK && danaRPump.isTempBasalInProgress && danaRPump.tempBasalPercent == percentAfterConstraint) { result.enacted = true result.success = true result.comment = resourceHelper.gs(R.string.virtualpump_resultok) result.isTempCancel = false - result.duration = pump.tempBasalRemainingMin - result.percent = pump.tempBasalPercent + result.duration = danaRPump.tempBasalRemainingMin + result.percent = danaRPump.tempBasalPercent result.isPercent = true aapsLogger.debug(LTag.PUMP, "setTempBasalPercent: OK") return result @@ -454,16 +461,15 @@ class DanaRSPlugin @Inject constructor( } @Synchronized private fun setHighTempBasalPercent(percent: Int): PumpEnactResult { - val pump = danaRPump val result = PumpEnactResult(injector) val connectionOK = danaRSService?.highTempBasal(percent) ?: false - if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) { + if (connectionOK && danaRPump.isTempBasalInProgress && danaRPump.tempBasalPercent == percent) { result.enacted = true result.success = true result.comment = resourceHelper.gs(R.string.virtualpump_resultok) result.isTempCancel = false - result.duration = pump.tempBasalRemainingMin - result.percent = pump.tempBasalPercent + result.duration = danaRPump.tempBasalRemainingMin + result.percent = danaRPump.tempBasalPercent result.isPercent = true aapsLogger.debug(LTag.PUMP, "setHighTempBasalPercent: OK") return result @@ -477,7 +483,6 @@ class DanaRSPlugin @Inject constructor( @Synchronized override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult { - val pump = danaRPump var insulinAfterConstraint = constraintChecker.applyExtendedBolusConstraints(Constraint(insulin)).value() // needs to be rounded val durationInHalfHours = max(durationInMinutes / 30, 1) @@ -488,23 +493,23 @@ class DanaRSPlugin @Inject constructor( result.enacted = false result.success = true result.comment = resourceHelper.gs(R.string.virtualpump_resultok) - result.duration = pump.extendedBolusRemainingMinutes - result.absolute = pump.extendedBolusAbsoluteRate + result.duration = danaRPump.extendedBolusRemainingMinutes + result.absolute = danaRPump.extendedBolusAbsoluteRate result.isPercent = false result.isTempCancel = false - aapsLogger.debug(LTag.PUMP, "setExtendedBolus: Correct extended bolus already set. Current: " + pump.extendedBolusAmount + " Asked: " + insulinAfterConstraint) + aapsLogger.debug(LTag.PUMP, "setExtendedBolus: Correct extended bolus already set. Current: " + danaRPump.extendedBolusAmount + " Asked: " + insulinAfterConstraint) return result } val connectionOK = danaRSService?.extendedBolus(insulinAfterConstraint, durationInHalfHours) ?: false - if (connectionOK && pump.isExtendedInProgress && abs(pump.extendedBolusAbsoluteRate - insulinAfterConstraint) < pumpDescription.extendedBolusStep) { + if (connectionOK && danaRPump.isExtendedInProgress && abs(danaRPump.extendedBolusAbsoluteRate - insulinAfterConstraint) < pumpDescription.extendedBolusStep) { result.enacted = true result.success = true result.comment = resourceHelper.gs(R.string.virtualpump_resultok) result.isTempCancel = false - result.duration = pump.extendedBolusRemainingMinutes - result.absolute = pump.extendedBolusAbsoluteRate - result.bolusDelivered = pump.extendedBolusAmount + result.duration = danaRPump.extendedBolusRemainingMinutes + result.absolute = danaRPump.extendedBolusAbsoluteRate + result.bolusDelivered = danaRPump.extendedBolusAmount result.isPercent = false aapsLogger.debug(LTag.PUMP, "setExtendedBolus: OK") return result @@ -562,9 +567,8 @@ class DanaRSPlugin @Inject constructor( } override fun getJSONStatus(profile: Profile, profileName: String): JSONObject { - val pump = danaRPump val now = System.currentTimeMillis() - if (pump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) { + if (danaRPump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) { return JSONObject() } val pumpJson = JSONObject() @@ -572,13 +576,13 @@ class DanaRSPlugin @Inject constructor( val status = JSONObject() val extended = JSONObject() try { - battery.put("percent", pump.batteryRemaining) - status.put("status", if (pump.pumpSuspended) "suspended" else "normal") - status.put("timestamp", DateUtil.toISOString(pump.lastConnection)) + battery.put("percent", danaRPump.batteryRemaining) + status.put("status", if (danaRPump.pumpSuspended) "suspended" else "normal") + status.put("timestamp", DateUtil.toISOString(danaRPump.lastConnection)) extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION) - if (pump.lastBolusTime != 0L) { - extended.put("LastBolus", DateUtil.dateAndTimeString(pump.lastBolusTime)) - extended.put("LastBolusAmount", pump.lastBolusAmount) + if (danaRPump.lastBolusTime != 0L) { + extended.put("LastBolus", DateUtil.dateAndTimeString(danaRPump.lastBolusTime)) + extended.put("LastBolusAmount", danaRPump.lastBolusAmount) } val tb = treatmentsPlugin.getTempBasalFromHistory(now) if (tb != null) { @@ -601,7 +605,7 @@ class DanaRSPlugin @Inject constructor( pumpJson.put("battery", battery) pumpJson.put("status", status) pumpJson.put("extended", extended) - pumpJson.put("reservoir", pump.reservoirRemainingUnits.toInt()) + pumpJson.put("reservoir", danaRPump.reservoirRemainingUnits.toInt()) pumpJson.put("clock", DateUtil.toISOString(now)) } catch (e: JSONException) { aapsLogger.error("Unhandled exception", e) @@ -626,15 +630,14 @@ class DanaRSPlugin @Inject constructor( } override fun shortStatus(veryShort: Boolean): String { - val pump = danaRPump var ret = "" - if (pump.lastConnection != 0L) { - val agoMillis = System.currentTimeMillis() - pump.lastConnection + if (danaRPump.lastConnection != 0L) { + val agoMillis = System.currentTimeMillis() - danaRPump.lastConnection val agoMin = (agoMillis / 60.0 / 1000.0).toInt() ret += "LastConn: $agoMin minago\n" } - if (pump.lastBolusTime != 0L) - ret += "LastBolus: ${DecimalFormatter.to2Decimal(pump.lastBolusAmount)}U @${DateFormat.format("HH:mm", pump.lastBolusTime)}" + if (danaRPump.lastBolusTime != 0L) + ret += "LastBolus: ${DecimalFormatter.to2Decimal(danaRPump.lastBolusAmount)}U @${DateFormat.format("HH:mm", danaRPump.lastBolusTime)}" val activeTemp = treatmentsPlugin.getRealTempBasalFromHistory(System.currentTimeMillis()) if (activeTemp != null) @@ -645,10 +648,10 @@ class DanaRSPlugin @Inject constructor( ret += "Extended: $activeExtendedBolus\n" if (!veryShort) { - ret += "TDD: ${DecimalFormatter.to0Decimal(pump.dailyTotalUnits)} / ${pump.maxDailyTotalUnits} U" + ret += "TDD: ${DecimalFormatter.to0Decimal(danaRPump.dailyTotalUnits)} / ${danaRPump.maxDailyTotalUnits} U" } - ret += "Reserv: ${DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits)} U" - ret += "Batt: ${pump.batteryRemaining}" + ret += "Reserv: ${DecimalFormatter.to0Decimal(danaRPump.reservoirRemainingUnits)} U" + ret += "Batt: ${danaRPump.batteryRemaining}" return ret } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt index 255a86d1f3..c3a60805d2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt @@ -12,6 +12,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.nsclient.NSUpload +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 import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -22,6 +23,7 @@ import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSMessageHashTabl import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess +import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.extensions.notify import info.nightscout.androidaps.utils.extensions.waitMillis @@ -67,6 +69,7 @@ class BLEComm @Inject internal constructor( set(newValue) { bleEncryption.setEnhancedEncryption(newValue) field = newValue + danaRPump.v3RSPump = newValue } private var isEasyMode: Boolean = false private var isUnitUD: Boolean = false @@ -550,11 +553,19 @@ class BLEComm @Inject internal constructor( var pass: Int = (decryptedBuffer[size - 1].toInt() and 0x000000FF shl 8) + (decryptedBuffer[size - 2].toInt() and 0x000000FF) pass = pass xor 3463 danaRPump.rsPassword = Integer.toHexString(pass) - aapsLogger.debug(LTag.PUMPBTCOMM, "Pump user password: " + Integer.toHexString(pass)) - rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED)) - isConnected = true - isConnecting = false - aapsLogger.debug(LTag.PUMPBTCOMM, "RS connected and status read") + aapsLogger.debug(LTag.PUMPBTCOMM, "Pump user password: " + danaRPump.rsPassword) + if (!danaRPump.isRSPasswordOK) { + aapsLogger.error(LTag.PUMPBTCOMM, "Wrong pump password") + rxBus.send(EventNewNotification(Notification(Notification.WRONG_PUMP_PASSWORD, resourceHelper.gs(R.string.wrongpumppassword), Notification.URGENT))) + disconnect("WrongPassword") + SystemClock.sleep(T.mins(1).msecs()) + } else { + rxBus.send(EventDismissNotification(Notification.WRONG_PUMP_PASSWORD)) + rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED)) + isConnected = true + isConnecting = false + aapsLogger.debug(LTag.PUMPBTCOMM, "RS connected and status read") + } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2fbd5522ea..315b0e66a7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -379,6 +379,7 @@ Refill Suspend Connecting for %1$d s + Pump password (v1 only) Pump password Wrong pump password! Pump is busy @@ -805,7 +806,6 @@ DanaRS Dana Selected pump - Pair new pump Bolus speed danars_bolusspeed Set basal step to 0.01 U/h @@ -1844,4 +1844,5 @@ statuslights_copy_ns Copy NS settings (if exists)? statuslights_overview_advanced + danars_password diff --git a/app/src/main/res/values/validator.xml b/app/src/main/res/values/validator.xml index aef7116a48..4de9c5fab1 100644 --- a/app/src/main/res/values/validator.xml +++ b/app/src/main/res/values/validator.xml @@ -18,11 +18,13 @@ Must be 6 digit number Must be 12 characters of ABCDEF0123456789 Must be 8 characters of ABCDEF0123456789 + Must be 4 characters of ABCDEF0123456789 Not a minimum length Pin should be 3 to 6 digits, not same or in series ^\\d{4} ^[A-F0-9]{12}$ ^[A-F0-9]{8}$ + ^[A-F0-9]{4}$ \ No newline at end of file diff --git a/app/src/main/res/xml/pref_danars.xml b/app/src/main/res/xml/pref_danars.xml index baf7bc4405..1e35b65ee9 100644 --- a/app/src/main/res/xml/pref_danars.xml +++ b/app/src/main/res/xml/pref_danars.xml @@ -8,24 +8,19 @@ app:initialExpandedChildrenCount="0"> + android:key="@string/key_danars_name" + android:summary="" + android:title="@string/selectedpump"> - - Date: Sun, 3 May 2020 16:10:48 +0200 Subject: [PATCH 18/53] forgotten code --- .../nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt index 7bed59fdfa..2960bebf8c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt @@ -87,9 +87,6 @@ class DanaRSPlugin @Inject constructor( pref.summary = value ?: resourceHelper.gs(R.string.rileylink_error_address_not_set_short) } - if (pref.key == resourceHelper.gs(R.string.key_danars_password)) { - if (danaRPump.v3RSPump) pref - } } override fun onStart() { From abb950512289038b9b97bbc05f2db60ccee21881 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sun, 3 May 2020 18:52:26 +0200 Subject: [PATCH 19/53] Insight: Disable vibration on bolus for firmware version 3 --- .../insight/app_layer/remote_control/DeliverBolusMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java index f1b4c3f6de..e15c01cfae 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java @@ -22,7 +22,7 @@ public class DeliverBolusMessage extends AppLayerMessage { @Override protected ByteBuf getData() { ByteBuf byteBuf = new ByteBuf(22); - byteBuf.putUInt16LE(805); + byteBuf.putUInt16LE(31); byteBuf.putUInt16LE(BolusTypeIDs.IDS.getID(bolusType)); byteBuf.putUInt16LE(31); byteBuf.putUInt16LE(0); From 591cef11e522e215ca2a745ec1e0e60cf6d5780e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 3 May 2020 19:48:48 +0200 Subject: [PATCH 20/53] 2.6.1.3 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 38457916a4..cce6b64992 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -109,7 +109,7 @@ android { targetSdkVersion 28 multiDexEnabled true versionCode 1500 - version "2.6.1.2" + version "2.6.1.3" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' From 1c075c526eac2a38e8f764e00e8049526eabffe4 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Mon, 4 May 2020 17:36:37 +0200 Subject: [PATCH 21/53] 2.6.1.4 --- app/build.gradle | 2 +- .../insight/app_layer/remote_control/DeliverBolusMessage.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index cce6b64992..893f13632c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -109,7 +109,7 @@ android { targetSdkVersion 28 multiDexEnabled true versionCode 1500 - version "2.6.1.3" + version "2.6.1.4" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java index e15c01cfae..e0d0f2461a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java @@ -22,7 +22,7 @@ public class DeliverBolusMessage extends AppLayerMessage { @Override protected ByteBuf getData() { ByteBuf byteBuf = new ByteBuf(22); - byteBuf.putUInt16LE(31); + byteBuf.putUInt16LE(252); byteBuf.putUInt16LE(BolusTypeIDs.IDS.getID(bolusType)); byteBuf.putUInt16LE(31); byteBuf.putUInt16LE(0); From ad472beb4abbde281ab0222d2ee2d077bedcfe8b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 6 May 2020 01:27:38 +0200 Subject: [PATCH 22/53] danars di start --- app/build.gradle | 1 + .../dependencyInjection/ActivitiesModule.kt | 4 -- .../dependencyInjection/AppComponent.kt | 4 +- .../general/maintenance/ImportExportPrefs.kt | 4 +- .../res/layout/danars_blescanner_item.xml | 33 --------- app/src/main/res/values/strings.xml | 6 -- danars/.gitignore | 1 + danars/build.gradle | 71 +++++++++++++++++++ danars/consumer-rules.pro | 0 danars/proguard-rules.pro | 21 ++++++ danars/src/main/AndroidManifest.xml | 6 ++ .../DanaRSActivitiesModule.kt | 14 ++++ .../pump/danaRS/activities/BLEScanActivity.kt | 2 +- .../activities/PairingHelperActivity.kt | 0 .../danaRS/dialogs/PairingProgressDialog.java | 8 +-- .../danaRS/events/EventDanaRSDeviceChange.kt | 0 .../events/EventDanaRSPairingSuccess.kt | 0 .../res/layout/danars_blescanner_activity.xml | 6 +- .../res/layout/danars_blescanner_item.xml | 27 +++++++ .../layout/danars_pairingprogressdialog.xml | 0 danars/src/main/res/values/strings.xml | 14 ++++ settings.gradle | 2 +- 22 files changed, 169 insertions(+), 55 deletions(-) delete mode 100644 app/src/main/res/layout/danars_blescanner_item.xml create mode 100644 danars/.gitignore create mode 100644 danars/build.gradle create mode 100644 danars/consumer-rules.pro create mode 100644 danars/proguard-rules.pro create mode 100644 danars/src/main/AndroidManifest.xml create mode 100644 danars/src/main/java/info/nightscout/androidaps/danars/dependencyInjection/DanaRSActivitiesModule.kt rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.kt (99%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/dialogs/PairingProgressDialog.java (94%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSDeviceChange.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPairingSuccess.kt (100%) rename {app => danars}/src/main/res/layout/danars_blescanner_activity.xml (88%) create mode 100644 danars/src/main/res/layout/danars_blescanner_item.xml rename {app => danars}/src/main/res/layout/danars_pairingprogressdialog.xml (100%) create mode 100644 danars/src/main/res/values/strings.xml diff --git a/app/build.gradle b/app/build.gradle index 8a404945f3..e3a302680b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -243,6 +243,7 @@ dependencies { wearApp project(':wear') implementation project(':core') + implementation project(':danars') implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.google.android.gms:play-services-wearable:17.0.0' diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt index 1afa263919..f4b6e9a27a 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt @@ -13,9 +13,7 @@ import info.nightscout.androidaps.plugins.pump.common.dialog.RileyLinkBLEScanAct import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRHistoryActivity import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRUserOptionsActivity -import info.nightscout.androidaps.plugins.pump.danaRS.activities.BLEScanActivity import info.nightscout.androidaps.plugins.pump.danaRS.activities.EnterPinActivity -import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity import info.nightscout.androidaps.plugins.pump.insight.activities.InsightAlertActivity import info.nightscout.androidaps.plugins.pump.insight.activities.InsightPairingActivity import info.nightscout.androidaps.plugins.pump.insight.activities.InsightPairingInformationActivity @@ -26,7 +24,6 @@ import info.nightscout.androidaps.setupwizard.SetupWizardActivity @Suppress("unused") abstract class ActivitiesModule { - @ContributesAndroidInjector abstract fun contributesBLEScanActivity(): BLEScanActivity @ContributesAndroidInjector abstract fun contributeBolusProgressHelperActivity(): BolusProgressHelperActivity @ContributesAndroidInjector abstract fun contributeDanaRHistoryActivity(): DanaRHistoryActivity @ContributesAndroidInjector abstract fun contributeDanaRUserOptionsActivity(): DanaRUserOptionsActivity @@ -39,7 +36,6 @@ abstract class ActivitiesModule { @ContributesAndroidInjector abstract fun contributesLogSettingActivity(): LogSettingActivity @ContributesAndroidInjector abstract fun contributeMainActivity(): MainActivity @ContributesAndroidInjector abstract fun contributesMedtronicHistoryActivity(): MedtronicHistoryActivity - @ContributesAndroidInjector abstract fun contributesPairingHelperActivity(): PairingHelperActivity @ContributesAndroidInjector abstract fun contributesPreferencesActivity(): PreferencesActivity @ContributesAndroidInjector abstract fun contributesQuickWizardListActivity(): QuickWizardListActivity @ContributesAndroidInjector abstract fun contributesRequestDexcomPermissionActivity(): RequestDexcomPermissionActivity diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt index f5b4139053..67feb4b4bf 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt @@ -6,6 +6,7 @@ import dagger.android.AndroidInjectionModule import dagger.android.AndroidInjector import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.core.dependencyInjection.CoreModule +import info.nightscout.androidaps.danars.dependencyInjection.DanaRSActivitiesModule import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.ProfileStore import info.nightscout.androidaps.data.PumpEnactResult @@ -71,7 +72,8 @@ import javax.inject.Singleton DataClassesModule::class, SMSModule::class, UIModule::class, - DanaRSCommModule::class + DanaRSCommModule::class, + DanaRSActivitiesModule::class ] ) interface AppComponent : AndroidInjector { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt index b859a1dee5..4d9021bb71 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt @@ -217,7 +217,7 @@ class ImportExportPrefs @Inject constructor( fun importSharedPreferences(fragment: Fragment) { fragment.activity?.let { fragmentAct -> - val callForPrefFile = fragmentAct.prepareCall(PrefsFileContract()) { + val callForPrefFile = fragmentAct.registerForActivityResult(PrefsFileContract()) { it?.let { importSharedPreferences(fragmentAct, it) } @@ -227,7 +227,7 @@ class ImportExportPrefs @Inject constructor( } fun importSharedPreferences(activity: FragmentActivity) { - val callForPrefFile = activity.prepareCall(PrefsFileContract()) { + val callForPrefFile = activity.registerForActivityResult(PrefsFileContract()) { it?.let { importSharedPreferences(activity, it) } diff --git a/app/src/main/res/layout/danars_blescanner_item.xml b/app/src/main/res/layout/danars_blescanner_item.xml deleted file mode 100644 index 2c620b532f..0000000000 --- a/app/src/main/res/layout/danars_blescanner_item.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cc4f698551..a27829b954 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -798,17 +798,11 @@ Activate profile Date INVALID - Waiting for pairing on pump - Pairing OK - Pairing timed out Pairing danars_pairing_key_ danars_v3_randompairing_key_ danars_v3_pairing_key_ danars_v3_randomsync_key_ - danars_address - danars_name - No device found so far Empty reservoir Blood sugar measurement alert Remaining insulin level diff --git a/danars/.gitignore b/danars/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/danars/.gitignore @@ -0,0 +1 @@ +/build diff --git a/danars/build.gradle b/danars/build.gradle new file mode 100644 index 0000000000..96753367b4 --- /dev/null +++ b/danars/build.gradle @@ -0,0 +1,71 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-kapt' + +android { + compileSdkVersion 28 + + defaultConfig { + minSdkVersion 23 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles 'consumer-rules.pro' + } + + kotlinOptions { + jvmTarget = '1.8' + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + debug { + testCoverageEnabled(project.hasProperty('coverage')) + } + firebaseDisable { + System.setProperty("disableFirebase", "true") + ext.enableCrashlytics = false + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + implementation project(':core') + + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion" + + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.core:core-ktx:1.2.0' + implementation "androidx.activity:activity:${activityVersion}" + implementation "androidx.activity:activity-ktx:${activityVersion}" + + + implementation "com.google.dagger:dagger-android:$dagger_version" + implementation "com.google.dagger:dagger-android-support:$dagger_version" + annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version" + annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version" + kapt "com.google.dagger:dagger-android-processor:$dagger_version" + kapt "com.google.dagger:dagger-compiler:$dagger_version" + + //RxBus + implementation "io.reactivex.rxjava2:rxandroid:2.1.1" + + testImplementation 'junit:junit:4.13' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} + diff --git a/danars/consumer-rules.pro b/danars/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/danars/proguard-rules.pro b/danars/proguard-rules.pro new file mode 100644 index 0000000000..f1b424510d --- /dev/null +++ b/danars/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/danars/src/main/AndroidManifest.xml b/danars/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..128d47771d --- /dev/null +++ b/danars/src/main/AndroidManifest.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/dependencyInjection/DanaRSActivitiesModule.kt b/danars/src/main/java/info/nightscout/androidaps/danars/dependencyInjection/DanaRSActivitiesModule.kt new file mode 100644 index 0000000000..269fa7a131 --- /dev/null +++ b/danars/src/main/java/info/nightscout/androidaps/danars/dependencyInjection/DanaRSActivitiesModule.kt @@ -0,0 +1,14 @@ +package info.nightscout.androidaps.danars.dependencyInjection + +import dagger.Module +import dagger.android.ContributesAndroidInjector +import info.nightscout.androidaps.plugins.pump.danaRS.activities.BLEScanActivity +import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity + +@Module +@Suppress("unused") +abstract class DanaRSActivitiesModule { + + @ContributesAndroidInjector abstract fun contributesBLEScanActivity(): BLEScanActivity + @ContributesAndroidInjector abstract fun contributesPairingHelperActivity(): PairingHelperActivity +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.kt similarity index 99% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.kt index d51dc5ab05..79024ca402 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.kt +++ b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.kt @@ -13,8 +13,8 @@ import android.view.View import android.view.ViewGroup import android.widget.BaseAdapter import android.widget.TextView -import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.NoSplashAppCompatActivity +import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.common.ble.BlePreCheck import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSDeviceChange diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/dialogs/PairingProgressDialog.java b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/dialogs/PairingProgressDialog.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/dialogs/PairingProgressDialog.java rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/dialogs/PairingProgressDialog.java index dcf17dc355..48a567c840 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/dialogs/PairingProgressDialog.java +++ b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/dialogs/PairingProgressDialog.java @@ -17,7 +17,7 @@ import android.widget.TextView; import javax.inject.Inject; import dagger.android.support.DaggerDialogFragment; -import info.nightscout.androidaps.R; +import info.nightscout.androidaps.danars.R; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity; import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess; @@ -63,7 +63,7 @@ public class PairingProgressDialog extends DaggerDialogFragment { if (activity != null) { activity.runOnUiThread(() -> { progressBar.setProgress(100); - statusView.setText(R.string.pairingok); + statusView.setText(R.string.danars_pairingok); try { Thread.sleep(1000); } catch (InterruptedException ignored) { @@ -84,7 +84,7 @@ public class PairingProgressDialog extends DaggerDialogFragment { if (activity != null) { activity.runOnUiThread(() -> { progressBar.setProgress(100); - statusView.setText(R.string.pairingtimedout); + statusView.setText(R.string.danars_pairingtimedout); button.setVisibility(View.VISIBLE); }); } @@ -140,7 +140,7 @@ public class PairingProgressDialog extends DaggerDialogFragment { private void setViews() { progressBar.setMax(100); progressBar.setProgress(0); - statusView.setText(resourceHelper.gs(R.string.waitingforpairing)); + statusView.setText(resourceHelper.gs(R.string.danars_waitingforpairing)); button.setVisibility(View.GONE); button.setOnClickListener(v -> dismiss()); handler.post(runnable); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSDeviceChange.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSDeviceChange.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSDeviceChange.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSDeviceChange.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPairingSuccess.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPairingSuccess.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPairingSuccess.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPairingSuccess.kt diff --git a/app/src/main/res/layout/danars_blescanner_activity.xml b/danars/src/main/res/layout/danars_blescanner_activity.xml similarity index 88% rename from app/src/main/res/layout/danars_blescanner_activity.xml rename to danars/src/main/res/layout/danars_blescanner_activity.xml index 654f8c1fb6..fe9e25879c 100644 --- a/app/src/main/res/layout/danars_blescanner_activity.xml +++ b/danars/src/main/res/layout/danars_blescanner_activity.xml @@ -4,7 +4,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context=".plugins.pump.danaRS.activities.BLEScanActivity"> + tools:context="info.nightscout.androidaps.plugins.pump.danaRS.activities.BLEScanActivity"> diff --git a/danars/src/main/res/layout/danars_blescanner_item.xml b/danars/src/main/res/layout/danars_blescanner_item.xml new file mode 100644 index 0000000000..9a39302163 --- /dev/null +++ b/danars/src/main/res/layout/danars_blescanner_item.xml @@ -0,0 +1,27 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/danars_pairingprogressdialog.xml b/danars/src/main/res/layout/danars_pairingprogressdialog.xml similarity index 100% rename from app/src/main/res/layout/danars_pairingprogressdialog.xml rename to danars/src/main/res/layout/danars_pairingprogressdialog.xml diff --git a/danars/src/main/res/values/strings.xml b/danars/src/main/res/values/strings.xml new file mode 100644 index 0000000000..f3f951e035 --- /dev/null +++ b/danars/src/main/res/values/strings.xml @@ -0,0 +1,14 @@ + + + danars_address + danars_name + + Pairing + No device found so far + Pairing OK + Pairing timed out + Waiting for pairing on pump + OK + Cancel + + diff --git a/settings.gradle b/settings.gradle index f7c8a5fc0a..cd2caae7bd 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':wear', ':core' \ No newline at end of file +include ':app', ':wear', ':core', ':danars' From 73d132649de5085ad49c0e4a79d08c6d7fa1eab8 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 8 May 2020 11:37:14 +0200 Subject: [PATCH 23/53] fix tests --- .../interfaces/ConstraintsCheckerTest.kt | 2 +- .../plugins/pump/danaRS/DanaRSPluginTest.kt | 6 +----- .../danaRS/comm/DanaRSMessageHashTableTest.kt | 21 +------------------ .../DanaRS_Packet_APS_History_EventsTest.kt | 5 ++++- ...DanaRS_Packet_APS_Set_Event_HistoryTest.kt | 5 ++++- ...ket_Basal_Get_Temporary_Basal_StateTest.kt | 5 ++++- ...et_Bolus_Get_Step_Bolus_InformationTest.kt | 17 ++++----------- ...S_Packet_Bolus_Set_Step_Bolus_StartTest.kt | 6 +----- ...RS_Packet_Bolus_Set_Step_Bolus_StopTest.kt | 6 +----- ...Packet_General_Get_More_InformationTest.kt | 19 ++++------------- ...et_General_Get_Shipping_InformationTest.kt | 13 ++++-------- .../comm/DanaRS_Packet_History_AlarmTest.kt | 10 ++++----- .../DanaRS_Packet_History_All_HistoryTest.kt | 9 ++++---- .../comm/DanaRS_Packet_History_BasalTest.kt | 9 ++++---- ...DanaRS_Packet_History_Blood_GlucoseTest.kt | 9 ++++---- .../comm/DanaRS_Packet_History_BolusTest.kt | 9 ++++---- .../DanaRS_Packet_History_CarbohydrateTest.kt | 9 ++++---- .../comm/DanaRS_Packet_History_DailyTest.kt | 9 ++++---- .../comm/DanaRS_Packet_History_PrimeTest.kt | 9 ++++---- .../comm/DanaRS_Packet_History_RefillTest.kt | 9 ++++---- .../comm/DanaRS_Packet_History_SuspendTest.kt | 9 ++++---- .../DanaRS_Packet_History_TemporaryTest.kt | 9 ++++---- ...aRS_Packet_Notify_Delivery_CompleteTest.kt | 6 +----- ...Packet_Notify_Delivery_Rate_DisplayTest.kt | 13 ++---------- .../DanaRS_Packet_Option_Get_Pump_TimeTest.kt | 17 ++++----------- .../DanaRS_Packet_Option_Set_Pump_TimeTest.kt | 9 ++++---- 26 files changed, 84 insertions(+), 166 deletions(-) diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt index 6cd8b0e2ca..7f5806e962 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt @@ -115,7 +115,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { comboPlugin = ComboPlugin(injector, aapsLogger, rxBus, resourceHelper, profileFunction, treatmentsPlugin, sp, commandQueue, context) danaRPlugin = DanaRPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, treatmentsPlugin, sp, commandQueue, danaRPump, dateUtil) danaRSPlugin = DanaRSPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil) - insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, resourceHelper, treatmentsPlugin, sp, commandQueue, profileFunction, context, dateUtil) + insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, resourceHelper, treatmentsPlugin, sp, commandQueue, profileFunction, context, Config(), dateUtil) openAPSSMBPlugin = OpenAPSSMBPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits, profiler, fabricPrivacy) openAPSAMAPlugin = OpenAPSAMAPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits, profiler, fabricPrivacy) safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, buildHelper, treatmentsPlugin, Config()) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt index 5485c6ae9d..effe08b5f8 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt @@ -63,10 +63,6 @@ class DanaRSPluginTest : DanaRSTestBase() { Mockito.`when`(resourceHelper.gs(eq(R.string.limitingbasalratio), anyObject(), anyObject())).thenReturn("limitingbasalratio") Mockito.`when`(resourceHelper.gs(eq(R.string.limitingpercentrate), anyObject(), anyObject())).thenReturn("limitingpercentrate") -<<<<<<< HEAD - danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, fabricPrivacy) -======= - danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, dateUtil) ->>>>>>> origin/dev + danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt index 4bcf9b4c92..4ad7df5359 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt @@ -1,23 +1,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -<<<<<<< HEAD import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -======= -import android.content.Context -import com.cozmo.danar.util.BleCommandUtil ->>>>>>> origin/dev import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump -<<<<<<< HEAD import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption -======= -import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin -import info.nightscout.androidaps.utils.DateUtil ->>>>>>> origin/dev import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -30,11 +20,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) class DanaRSMessageHashTableTest : DanaRSTestBase() { -<<<<<<< HEAD -======= - @Mock lateinit var context: Context - @Mock lateinit var danaRSPlugin: DanaRSPlugin ->>>>>>> origin/dev @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage @@ -43,6 +28,7 @@ class DanaRSMessageHashTableTest : DanaRSTestBase() { AndroidInjector { if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil } if (it is DanaRS_Packet_Bolus_Set_Step_Bolus_Start) { it.constraintChecker = constraintChecker @@ -60,13 +46,8 @@ class DanaRSMessageHashTableTest : DanaRSTestBase() { fun runTest() { `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) -<<<<<<< HEAD val danaRSMessageHashTable = DanaRSMessageHashTable(packetInjector) val forTesting: DanaRS_Packet = DanaRS_Packet_APS_Set_Event_History(packetInjector, DanaRPump.CARBS, 0, 0, 0) -======= - val danaRSMessageHashTable = DanaRSMessageHashTable(aapsLogger, rxBus, resourceHelper, danaRPump, danaRSPlugin, activePlugin, constraintChecker, detailedBolusInfoStorage, injector, DateUtil(context, resourceHelper)) - val forTesting: DanaRS_Packet = DanaRS_Packet_APS_Set_Event_History(aapsLogger, dateUtil, DanaRPump.CARBS, 0, 0, 0) ->>>>>>> origin/dev val testPacket: DanaRS_Packet = danaRSMessageHashTable.findMessage(forTesting.command) Assert.assertEquals(BleEncryption.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY.toLong(), testPacket.getOpCode().toLong()) } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt index 6b7835ffbd..20aaa5591d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt @@ -26,8 +26,11 @@ class DanaRS_Packet_APS_History_EventsTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_APS_History_Events) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_APS_History_Events) { it.rxBus = rxBus it.resourceHelper = resourceHelper it.activePlugin = activePlugin diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt index b252c07830..36146b4ca9 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt @@ -16,8 +16,11 @@ class DanaRS_Packet_APS_Set_Event_HistoryTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_APS_Set_Event_History) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_APS_Set_Event_History) { } } } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt index 115dba03b0..56e308fc1f 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt @@ -14,8 +14,11 @@ class DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_Basal_Get_Temporary_Basal_State) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_Basal_Get_Temporary_Basal_State) { it.danaRPump = danaRPump } } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt index 0979f33075..9d250d8872 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt @@ -15,15 +15,17 @@ class DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_Bolus_Get_Step_Bolus_Information) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_Bolus_Get_Step_Bolus_Information) { it.danaRPump = danaRPump } } } @Test fun runTest() { -<<<<<<< HEAD val packet = DanaRS_Packet_Bolus_Get_Step_Bolus_Information(packetInjector) val array = createArray(13, 0.toByte()) // 11 + 2 @@ -45,17 +47,6 @@ class DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest : DanaRSTestBase() { Assert.assertEquals(12.5, danaRPump.lastBolusAmount, 0.01) Assert.assertEquals(25.0, danaRPump.maxBolus, 0.01) Assert.assertEquals(1.0, danaRPump.bolusStep, 0.01) -======= - val packet = DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump, dateUtil) - Assert.assertEquals(null, packet.requestParams) - // test message decoding - packet.handleMessage(createArray(34, 0.toByte())) - Assert.assertEquals(false, packet.failed) - packet.handleMessage(createArray(34, 1.toByte())) - val valueRequested: Int = (1 and 0x000000FF shl 8) + (1 and 0x000000FF) - Assert.assertEquals(valueRequested / 100.0, danaRPump.lastBolusAmount, 0.0) - Assert.assertEquals(true, packet.failed) ->>>>>>> origin/dev Assert.assertEquals("BOLUS__GET_STEP_BOLUS_INFORMATION", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt index da0bbc434f..b69ffe2ee3 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt @@ -54,11 +54,7 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() { @Before fun mock() { -<<<<<<< HEAD - danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, fabricPrivacy) -======= - danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, dateUtil) ->>>>>>> origin/dev + danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil) Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt index f0d67530c5..0b68225a54 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt @@ -2,14 +2,10 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.db.Treatment import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin -<<<<<<< HEAD -import info.nightscout.androidaps.plugins.treatments.Treatment -======= -import info.nightscout.androidaps.db.Treatment ->>>>>>> origin/dev import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt index ee57e0b1f2..7d93a60dbd 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_InformationTest.kt @@ -13,15 +13,17 @@ class DanaRS_Packet_General_Get_More_InformationTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_General_Get_More_Information) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_General_Get_More_Information) { it.danaRPump = danaRPump } } } @Test fun runTest() { -<<<<<<< HEAD var packet = DanaRS_Packet_General_Get_More_Information(packetInjector) packet.handleMessage(createArray(14, 0.toByte())) @@ -48,19 +50,6 @@ class DanaRS_Packet_General_Get_More_InformationTest : DanaRSTestBase() { Assert.assertEquals(25, lastBolus.minutes) Assert.assertEquals(1.7, danaRPump.lastBolusAmount, 0.01) -======= - var packet = DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump, dateUtil) - Assert.assertEquals(null, packet.requestParams) - // test message decoding - // test for the length message - packet.handleMessage(createArray(13, 0.toByte())) - Assert.assertEquals(true, packet.failed) - packet = DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump, dateUtil) - packet.handleMessage(createArray(15, 0.toByte())) - Assert.assertEquals(false, packet.failed) - packet.handleMessage(createArray(15, 161.toByte())) - Assert.assertEquals(true, packet.failed) ->>>>>>> origin/dev Assert.assertEquals("REVIEW__GET_MORE_INFORMATION", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt index 8f2d792423..f9247b152b 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt @@ -12,30 +12,25 @@ class DanaRS_Packet_General_Get_Shipping_InformationTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_General_Get_Shipping_Information) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_General_Get_Shipping_Information) { it.danaRPump = danaRPump } } } @Test fun runTest() { -<<<<<<< HEAD var packet = DanaRS_Packet_General_Get_Shipping_Information(packetInjector) -======= - var packet = DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump, dateUtil) ->>>>>>> origin/dev Assert.assertEquals(null, packet.requestParams) // test message decoding // test for the length message packet.handleMessage(createArray(1, 0.toByte())) Assert.assertEquals(true, packet.failed) // everything ok :) -<<<<<<< HEAD packet = DanaRS_Packet_General_Get_Shipping_Information(packetInjector) -======= - packet = DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump, dateUtil) ->>>>>>> origin/dev packet.handleMessage(createArray(18, 0.toByte())) Assert.assertEquals(false, packet.failed) Assert.assertEquals("REVIEW__GET_SHIPPING_INFORMATION", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt index 0485d8a06e..7b64daa632 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt @@ -20,7 +20,6 @@ import java.util.* @PrepareForTest(MainApp::class) class DanaRS_Packet_History_AlarmTest : DanaRSTestBase() { -<<<<<<< HEAD @Mock lateinit var databaseHelper: DatabaseHelper @Before @@ -31,8 +30,11 @@ class DanaRS_Packet_History_AlarmTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_History_Alarm) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_History_Alarm) { it.rxBus = rxBus } } @@ -59,10 +61,6 @@ class DanaRS_Packet_History_AlarmTest : DanaRSTestBase() { Assert.assertEquals(Date(119, 1, 4, 20, 11, 35).time, packet.danaRHistoryRecord.recordDate) Assert.assertEquals("Occlusion", packet.danaRHistoryRecord.recordAlarm) Assert.assertEquals(3.56, packet.danaRHistoryRecord.recordValue, 0.01) -======= - @Test fun runTest() { - val packet = DanaRS_Packet_History_Alarm(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) ->>>>>>> origin/dev Assert.assertEquals("REVIEW__ALARM", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt index 7aea8d84a9..6913ec5da1 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt @@ -12,19 +12,18 @@ class DanaRS_Packet_History_All_HistoryTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_History_All_History) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_History_All_History) { it.rxBus = rxBus } } } @Test fun runTest() { -<<<<<<< HEAD val packet = DanaRS_Packet_History_All_History(packetInjector, System.currentTimeMillis()) -======= - val packet = DanaRS_Packet_History_All_History(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) ->>>>>>> origin/dev Assert.assertEquals("REVIEW__ALL_HISTORY", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt index a34513a30a..227e305eba 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt @@ -12,19 +12,18 @@ class DanaRS_Packet_History_BasalTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_History_Basal) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_History_Basal) { it.rxBus = rxBus } } } @Test fun runTest() { -<<<<<<< HEAD val packet = DanaRS_Packet_History_Basal(packetInjector, System.currentTimeMillis()) -======= - val packet = DanaRS_Packet_History_Basal(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) ->>>>>>> origin/dev Assert.assertEquals("REVIEW__BASAL", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt index 152bc1e7fc..9c1474ebe2 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt @@ -12,19 +12,18 @@ class DanaRS_Packet_History_Blood_GlucoseTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_History_Blood_Glucose) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_History_Blood_Glucose) { it.rxBus = rxBus } } } @Test fun runTest() { -<<<<<<< HEAD val packet = DanaRS_Packet_History_Blood_Glucose(packetInjector, System.currentTimeMillis()) -======= - val packet = DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) ->>>>>>> origin/dev Assert.assertEquals("REVIEW__BLOOD_GLUCOSE", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt index 44fede7ae9..202f52d0be 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt @@ -12,19 +12,18 @@ class DanaRS_Packet_History_BolusTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_History_Bolus) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_History_Bolus) { it.rxBus = rxBus } } } @Test fun runTest() { -<<<<<<< HEAD val packet = DanaRS_Packet_History_Bolus(packetInjector, System.currentTimeMillis()) -======= - val packet = DanaRS_Packet_History_Bolus(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) ->>>>>>> origin/dev Assert.assertEquals("REVIEW__BOLUS", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt index 4e2544107e..93d40faac9 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt @@ -12,19 +12,18 @@ class DanaRS_Packet_History_CarbohydrateTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_History_Carbohydrate) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_History_Carbohydrate) { it.rxBus = rxBus } } } @Test fun runTest() { -<<<<<<< HEAD val packet = DanaRS_Packet_History_Carbohydrate(packetInjector, System.currentTimeMillis()) -======= - val packet = DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) ->>>>>>> origin/dev Assert.assertEquals("REVIEW__CARBOHYDRATE", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt index 5564ba584c..00b407f32a 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt @@ -12,19 +12,18 @@ class DanaRS_Packet_History_DailyTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_History_Daily) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_History_Daily) { it.rxBus = rxBus } } } @Test fun runTest() { -<<<<<<< HEAD val packet = DanaRS_Packet_History_Daily(packetInjector, System.currentTimeMillis()) -======= - val packet = DanaRS_Packet_History_Daily(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) ->>>>>>> origin/dev Assert.assertEquals("REVIEW__DAILY", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt index 592d45be98..59ed19ac48 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt @@ -12,19 +12,18 @@ class DanaRS_Packet_History_PrimeTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_History_Prime) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_History_Prime) { it.rxBus = rxBus } } } @Test fun runTest() { -<<<<<<< HEAD val packet = DanaRS_Packet_History_Prime(packetInjector, System.currentTimeMillis()) -======= - val packet = DanaRS_Packet_History_Prime(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) ->>>>>>> origin/dev Assert.assertEquals("REVIEW__PRIME", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt index 84ea21d91c..832d52f6e6 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt @@ -12,19 +12,18 @@ class DanaRS_Packet_History_RefillTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_History_Refill) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_History_Refill) { it.rxBus = rxBus } } } @Test fun runTest() { -<<<<<<< HEAD val packet = DanaRS_Packet_History_Refill(packetInjector, System.currentTimeMillis()) -======= - val packet = DanaRS_Packet_History_Refill(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) ->>>>>>> origin/dev Assert.assertEquals("REVIEW__REFILL", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt index 7b0300aaef..f1f612fe13 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt @@ -12,19 +12,18 @@ class DanaRS_Packet_History_SuspendTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_History_Suspend) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_History_Suspend) { it.rxBus = rxBus } } } @Test fun runTest() { -<<<<<<< HEAD val packet = DanaRS_Packet_History_Suspend(packetInjector, System.currentTimeMillis()) -======= - val packet = DanaRS_Packet_History_Suspend(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) ->>>>>>> origin/dev Assert.assertEquals("REVIEW__SUSPEND", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt index e0dc156d8a..0a74282ddd 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt @@ -12,19 +12,18 @@ class DanaRS_Packet_History_TemporaryTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_History_Temporary) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_History_Temporary) { it.rxBus = rxBus } } } @Test fun runTest() { -<<<<<<< HEAD val packet = DanaRS_Packet_History_Temporary(packetInjector, System.currentTimeMillis()) -======= - val packet = DanaRS_Packet_History_Temporary(aapsLogger, rxBus, dateUtil, System.currentTimeMillis()) ->>>>>>> origin/dev Assert.assertEquals("REVIEW__TEMPORARY", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt index 065fc9ce6f..9e437107b1 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt @@ -2,14 +2,10 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.db.Treatment import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin -<<<<<<< HEAD -import info.nightscout.androidaps.plugins.treatments.Treatment -======= -import info.nightscout.androidaps.db.Treatment ->>>>>>> origin/dev import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt index b026c4f7bf..d015035113 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt @@ -3,17 +3,13 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.db.Treatment import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin -<<<<<<< HEAD -import info.nightscout.androidaps.plugins.treatments.Treatment -======= -import info.nightscout.androidaps.db.Treatment ->>>>>>> origin/dev import org.junit.Assert import org.junit.Before import org.junit.Test @@ -71,12 +67,7 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() { @Before fun mock() { -<<<<<<< HEAD - danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, fabricPrivacy) + danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil) danaRPump.bolusingTreatment = Treatment(packetInjector) -======= - danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage, dateUtil) - danaRSPlugin.bolusingTreatment = Treatment(treatmentInjector) ->>>>>>> origin/dev } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt index 7298f57d19..1c64b0d82a 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt @@ -13,15 +13,17 @@ class DanaRS_Packet_Option_Get_Pump_TimeTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_Option_Get_Pump_Time) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_Option_Get_Pump_Time) { it.danaRPump = danaRPump } } } @Test fun runTest() { -<<<<<<< HEAD val packet = DanaRS_Packet_Option_Get_Pump_Time(packetInjector) val array = createArray(8, 0.toByte()) // 6 + 2 putByteToArray(array, 0, 19) // year 2019 @@ -33,17 +35,6 @@ class DanaRS_Packet_Option_Get_Pump_TimeTest : DanaRSTestBase() { packet.handleMessage(array) Assert.assertEquals(DateTime(2019, 2, 4, 20, 11, 35).millis, danaRPump.pumpTime) -======= - val packet = DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump, dateUtil) - // test params - Assert.assertEquals(null, packet.requestParams) - // test message decoding - packet.handleMessage(createArray(8, 0.toByte())) - Assert.assertEquals(false, packet.failed) - // this should fail - packet.handleMessage(createArray(8, 1.toByte())) - Assert.assertEquals(true, packet.failed) ->>>>>>> origin/dev Assert.assertEquals("OPTION__GET_PUMP_TIME", packet.friendlyName) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt index f9ca5fe57d..67a9eed70d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt @@ -13,19 +13,18 @@ class DanaRS_Packet_Option_Set_Pump_TimeTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { - if (it is DanaRS_Packet_Option_Set_Pump_Time) { + if (it is DanaRS_Packet) { it.aapsLogger = aapsLogger + it.dateUtil = dateUtil + } + if (it is DanaRS_Packet_Option_Set_Pump_Time) { } } } @Test fun runTest() { -<<<<<<< HEAD val date = Date() val packet = DanaRS_Packet_Option_Set_Pump_Time(packetInjector, date.time) -======= - val packet = DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, dateUtil, DateUtil.now()) ->>>>>>> origin/dev // test params val params = packet.requestParams Assert.assertEquals((date.year - 100 and 0xff).toByte(), params[0]) // 2019 -> 19 From 61a077542cdd0975b29b01fc76b63f8af66c6624 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 8 May 2020 11:56:02 +0200 Subject: [PATCH 24/53] DanaRPump -> danars --- .../androidaps/plugins/pump/danaR/comm/MsgBolusStop.kt | 1 - .../pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt | 2 +- app/src/main/res/values/strings.xml | 2 -- .../plugins/pump/danaR/comm/MsgSettingUserOptionsTest.kt | 1 - .../info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt | 2 +- danars/src/main/res/values/strings.xml | 2 ++ 6 files changed, 4 insertions(+), 6 deletions(-) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt (99%) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStop.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStop.kt index bdabef46da..3d4fade70d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStop.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStop.kt @@ -1,6 +1,5 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm -import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt index 89b3239b11..676290cbba 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt @@ -195,7 +195,7 @@ open class DanaRS_Packet_APS_History_Events( status = "PRIMECANNULA " + dateUtil.timeString(datetime) } - else -> { + else -> { aapsLogger.debug(LTag.PUMPCOMM, "Event: " + recordCode + " " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Param1: " + param1 + " Param2: " + param2) status = "UNKNOWN " + dateUtil.timeString(datetime) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0d4218e877..35a25bca9b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -557,7 +557,6 @@ nsclientinternal_url nsclientinternal_api_secret danar_bt_name - danar_password Clear log nsclientinternal_autoscroll nsclientinternal_paused @@ -1758,7 +1757,6 @@ statuslights_copy_ns Copy NS settings (if exists)? statuslights_overview_advanced - danars_password Original skin Buttons are always displayed on bottom of screen skin diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingUserOptionsTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingUserOptionsTest.kt index f18dde576b..2be556b1e1 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingUserOptionsTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingUserOptionsTest.kt @@ -5,7 +5,6 @@ import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner -import kotlin.experimental.and @RunWith(PowerMockRunner::class) class MsgSettingUserOptionsTest : DanaRTestBase() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt similarity index 99% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt index 11f679bbb1..e33ddb1dbc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt +++ b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.kt @@ -2,7 +2,7 @@ package info.nightscout.androidaps.plugins.pump.danaR import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Constants -import info.nightscout.androidaps.R +import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.interfaces.ProfileStore import info.nightscout.androidaps.logging.AAPSLogger diff --git a/danars/src/main/res/values/strings.xml b/danars/src/main/res/values/strings.xml index f3f951e035..5cef8b70b6 100644 --- a/danars/src/main/res/values/strings.xml +++ b/danars/src/main/res/values/strings.xml @@ -2,6 +2,8 @@ danars_address danars_name + danar_password + danars_password Pairing No device found so far From 040c76d83989a72fd8b3131233d0af855f51d7b4 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 8 May 2020 14:59:30 +0200 Subject: [PATCH 25/53] move pass 1 --- .../activities/MyPreferenceFragment.kt | 1 - .../dependencyInjection/ActivitiesModule.kt | 1 + .../dependencyInjection/PluginsModule.kt | 1 - .../plugins/aps/loop/LoopPlugin.java | 89 ++++--- .../general/maintenance/ImportExportPrefs.kt | 1 - .../plugins/general/nsclient/UploadQueue.java | 3 +- .../PersistentNotificationPlugin.kt | 1 - .../plugins/pump/combo/ComboPlugin.java | 2 +- .../pump/common/PumpPluginAbstract.java | 2 +- .../pump/danaR/AbstractDanaRPlugin.java | 2 +- .../plugins/pump/danaR/DanaRPlugin.java | 2 +- .../danaR/activities/DanaRHistoryActivity.kt | 10 +- .../plugins/pump/danaR/comm/MsgHistoryAll.kt | 2 +- .../pump/danaRKorean/DanaRKoreanPlugin.java | 2 +- .../plugins/pump/danaRv2/DanaRv2Plugin.java | 4 +- .../pump/medtronic/MedtronicPumpPlugin.java | 2 +- .../pump/omnipod/OmnipodPumpPlugin.java | 1 - .../plugins/treatments/TreatmentsPlugin.java | 23 +- .../androidNotification/NotificationHolder.kt | 9 +- app/src/main/jniLibs/README.md | 1 - app/src/main/res/values/strings.xml | 41 ---- .../bolusInfo/DetailedBolusInfoStorageTest.kt | 2 - core/build.gradle | 1 + .../activities/BolusProgressHelperActivity.kt | 0 .../activities/DialogAppCompatActivity.kt | 0 .../activities/ErrorHelperActivity.kt | 5 +- .../androidaps/dialogs/BolusProgressDialog.kt | 4 +- .../androidaps/dialogs/ErrorDialog.kt | 13 +- .../androidaps/events/EventAppExit.kt | 0 .../androidaps/events/EventChargingState.kt | 0 .../events/EventConfigBuilderChange.kt | 0 .../events/EventInitializationChanged.kt | 0 .../androidaps/events/EventNetworkChange.kt | 0 .../events/EventProfileNeedsUpdate.kt | 0 .../events/EventPumpStatusChanged.kt | 4 +- .../androidaps/events/EventStatus.kt | 2 +- .../androidaps/interfaces/DanaRInterface.java | 0 .../interfaces/IobCobCalculatorInterface.java | 3 + .../androidaps/interfaces/LoopInterface.kt | 24 ++ .../interfaces/NotificationHolderInterface.kt | 10 + .../interfaces/UploadQueueInterface.java | 8 + .../plugins/aps/loop/DeviceStatus.java | 0 .../plugins/general/nsclient/NSUpload.java | 232 ++++++++++-------- .../EventDismissBolusProgressIfRunning.kt | 0 .../events/EventOverviewBolusProgress.kt | 0 .../bolusInfo/DetailedBolusInfoStorage.kt | 2 - .../receivers/NetworkChangeReceiver.kt | 0 .../receivers/ReceiverStatusStore.kt | 0 .../androidaps/services/AlarmSoundService.kt | 6 +- .../androidaps/utils/StringUtils.java | 3 - .../extensions/HexByteArrayConversion.kt | 0 .../textValidator/DefaultEditTextValidator.kt | 2 +- .../textValidator/EditTextValidator.java | 0 .../ValidatingEditTextPreference.kt | 2 +- .../validators/AlphaNumericValidator.kt | 0 .../validators/AlphaValidator.kt | 0 .../textValidator/validators/AndValidator.kt | 0 .../validators/CreditCardValidator.kt | 0 .../textValidator/validators/DateValidator.kt | 0 .../validators/DigitLengthRangeValidator.kt | 0 .../validators/DomainValidator.kt | 0 .../validators/DummyValidator.kt | 0 .../validators/EmailValidator.kt | 0 .../validators/EmptyValidator.kt | 0 .../validators/FloatNumericRangeValidator.kt | 0 .../validators/HttpsUrlValidator.kt | 0 .../validators/IpAddressValidator.kt | 0 .../validators/MinDigitLengthValidator.kt | 0 .../validators/MultiPhoneValidator.kt | 0 .../validators/MultiValidator.kt | 0 .../textValidator/validators/NotValidator.kt | 0 .../validators/NumericRangeValidator.kt | 0 .../validators/NumericValidator.kt | 0 .../textValidator/validators/OrValidator.kt | 0 .../validators/PatternValidator.kt | 0 .../validators/PersonFullNameValidator.kt | 0 .../validators/PersonNameValidator.kt | 0 .../validators/PhoneValidator.kt | 0 .../validators/PinStrengthValidator.kt | 0 .../validators/RegexpValidator.kt | 0 .../validators/SameValueValidator.kt | 0 .../textValidator/validators/Validator.kt | 0 .../validators/WebUrlValidator.kt | 0 .../main/res/layout/dialog_bolusprogress.xml | 0 .../src/main/res/layout/dialog_error.xml | 0 .../src/main/res/layout/okcancel.xml | 0 {app => core}/src/main/res/raw/error.mp3 | Bin .../src/main/res/values/fet_attrs.xml | 0 core/src/main/res/values/strings.xml | 28 +++ .../src/main/res/values/validator.xml | 0 danars/build.gradle | 3 + .../plugins/pump/danaR/DanaRFragment.kt | 0 .../plugins/pump/danaR/comm/RecordTypes.kt | 0 .../pump/danaR/events/EventDanaRNewStatus.kt | 0 .../plugins/pump/danaRS/DanaRSPlugin.kt | 51 ++-- .../danaRS/activities/EnterPinActivity.kt | 4 +- .../danaRS/comm/DanaRSMessageHashTable.kt | 0 .../pump/danaRS/comm/DanaRS_Packet.java | 0 ...RS_Packet_APS_Basal_Set_Temporary_Basal.kt | 0 .../comm/DanaRS_Packet_APS_History_Events.kt | 4 +- .../DanaRS_Packet_APS_Set_Event_History.kt | 0 .../DanaRS_Packet_Basal_Get_Basal_Rate.kt | 2 +- ...aRS_Packet_Basal_Get_Profile_Basal_Rate.kt | 0 .../DanaRS_Packet_Basal_Get_Profile_Number.kt | 0 ..._Packet_Basal_Get_Temporary_Basal_State.kt | 0 .../DanaRS_Packet_Basal_Set_Basal_Rate.kt | 0 ...Packet_Basal_Set_Cancel_Temporary_Basal.kt | 0 ...aRS_Packet_Basal_Set_Profile_Basal_Rate.kt | 0 .../DanaRS_Packet_Basal_Set_Profile_Number.kt | 0 .../DanaRS_Packet_Basal_Set_Suspend_Off.kt | 0 .../DanaRS_Packet_Basal_Set_Suspend_On.kt | 0 ...DanaRS_Packet_Basal_Set_Temporary_Basal.kt | 0 .../DanaRS_Packet_Bolus_Get_Bolus_Option.kt | 1 + .../DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt | 0 ...acket_Bolus_Get_Calculation_Information.kt | 0 ...et_Carbohydrate_Calculation_Information.kt | 0 .../DanaRS_Packet_Bolus_Get_Dual_Bolus.kt | 0 .../DanaRS_Packet_Bolus_Get_Extended_Bolus.kt | 0 ...S_Packet_Bolus_Get_Extended_Bolus_State.kt | 0 ...et_Bolus_Get_Extended_Menu_Option_State.kt | 0 .../DanaRS_Packet_Bolus_Get_Initial_Bolus.kt | 0 ...Packet_Bolus_Get_Step_Bolus_Information.kt | 0 .../DanaRS_Packet_Bolus_Set_Bolus_Option.kt | 0 .../DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt | 0 .../DanaRS_Packet_Bolus_Set_Dual_Bolus.kt | 0 .../DanaRS_Packet_Bolus_Set_Extended_Bolus.kt | 0 ..._Packet_Bolus_Set_Extended_Bolus_Cancel.kt | 0 .../DanaRS_Packet_Bolus_Set_Initial_Bolus.kt | 0 ...anaRS_Packet_Bolus_Set_Step_Bolus_Start.kt | 0 ...DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt | 0 .../comm/DanaRS_Packet_Etc_Keep_Connection.kt | 0 .../DanaRS_Packet_Etc_Set_History_Save.kt | 0 .../DanaRS_Packet_General_Delivery_Status.kt | 0 ...aRS_Packet_General_Get_More_Information.kt | 0 .../DanaRS_Packet_General_Get_Password.kt | 0 .../DanaRS_Packet_General_Get_Pump_Check.kt | 0 ...Packet_General_Get_Shipping_Information.kt | 0 ...aRS_Packet_General_Get_Shipping_Version.kt | 0 ...Packet_General_Get_Today_Delivery_Total.kt | 0 ...acket_General_Get_User_Time_Change_Flag.kt | 0 ...cket_General_Initial_Screen_Information.kt | 0 ..._Packet_General_Set_History_Upload_Mode.kt | 0 ...General_Set_User_Time_Change_Flag_Clear.kt | 0 .../danaRS/comm/DanaRS_Packet_History_.kt | 0 .../comm/DanaRS_Packet_History_Alarm.kt | 0 .../comm/DanaRS_Packet_History_All_History.kt | 0 .../comm/DanaRS_Packet_History_Basal.kt | 0 .../DanaRS_Packet_History_Blood_Glucose.kt | 0 .../comm/DanaRS_Packet_History_Bolus.kt | 0 .../DanaRS_Packet_History_Carbohydrate.kt | 0 .../comm/DanaRS_Packet_History_Daily.kt | 0 .../comm/DanaRS_Packet_History_Prime.kt | 0 .../comm/DanaRS_Packet_History_Refill.kt | 0 .../comm/DanaRS_Packet_History_Suspend.kt | 0 .../comm/DanaRS_Packet_History_Temporary.kt | 0 .../danaRS/comm/DanaRS_Packet_Notify_Alarm.kt | 0 .../DanaRS_Packet_Notify_Delivery_Complete.kt | 0 ...aRS_Packet_Notify_Delivery_Rate_Display.kt | 0 ...DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt | 0 .../DanaRS_Packet_Option_Get_Pump_Time.kt | 0 .../DanaRS_Packet_Option_Get_User_Option.kt | 0 .../DanaRS_Packet_Option_Set_Pump_Time.kt | 0 .../DanaRS_Packet_Option_Set_User_Option.kt | 0 .../comm/DanaRS_Packet_Review_Bolus_Avg.kt | 0 ...DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt | 0 .../pump/danaRS/encryption/BleEncryption.java | 0 .../plugins/pump/danaRS/services/BLEComm.kt | 0 .../pump/danaRS/services/DanaRSService.kt | 1 - .../jniLibs/arm64-v8a/libBleEncryption.so | Bin .../jniLibs/armeabi-v7a/libBleEncryption.so | Bin .../src/main/jniLibs/x86/libBleEncryption.so | Bin .../main/jniLibs/x86_64/libBleEncryption.so | Bin .../res/layout/danars_enter_pin_activity.xml | 0 danars/src/main/res/values/strings.xml | 19 +- .../src/main/res/xml/pref_danars.xml | 0 175 files changed, 349 insertions(+), 287 deletions(-) delete mode 100644 app/src/main/jniLibs/README.md rename {app => core}/src/main/java/info/nightscout/androidaps/activities/BolusProgressHelperActivity.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/activities/DialogAppCompatActivity.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/activities/ErrorHelperActivity.kt (86%) rename {app => core}/src/main/java/info/nightscout/androidaps/dialogs/BolusProgressDialog.kt (98%) rename {app => core}/src/main/java/info/nightscout/androidaps/dialogs/ErrorDialog.kt (89%) rename {app => core}/src/main/java/info/nightscout/androidaps/events/EventAppExit.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/events/EventChargingState.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/events/EventConfigBuilderChange.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/events/EventInitializationChanged.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/events/EventNetworkChange.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/events/EventProfileNeedsUpdate.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.kt (94%) rename {app => core}/src/main/java/info/nightscout/androidaps/events/EventStatus.kt (84%) rename {app => core}/src/main/java/info/nightscout/androidaps/interfaces/DanaRInterface.java (100%) create mode 100644 core/src/main/java/info/nightscout/androidaps/interfaces/LoopInterface.kt create mode 100644 core/src/main/java/info/nightscout/androidaps/interfaces/NotificationHolderInterface.kt create mode 100644 core/src/main/java/info/nightscout/androidaps/interfaces/UploadQueueInterface.java rename {app => core}/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java (66%) rename {app => core}/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusProgressIfRunning.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt (95%) rename {app => core}/src/main/java/info/nightscout/androidaps/receivers/NetworkChangeReceiver.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/receivers/ReceiverStatusStore.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.kt (91%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/StringUtils.java (86%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/extensions/HexByteArrayConversion.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/DefaultEditTextValidator.kt (99%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/EditTextValidator.java (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/ValidatingEditTextPreference.kt (97%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/AlphaNumericValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/AlphaValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/AndValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/CreditCardValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DateValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DigitLengthRangeValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DomainValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DummyValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/EmailValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/EmptyValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/FloatNumericRangeValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/HttpsUrlValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/IpAddressValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/MinDigitLengthValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/MultiPhoneValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/MultiValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/NotValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/NumericRangeValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/NumericValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/OrValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PatternValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PersonFullNameValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PersonNameValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PhoneValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PinStrengthValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/RegexpValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/SameValueValidator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/Validator.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/WebUrlValidator.kt (100%) rename {app => core}/src/main/res/layout/dialog_bolusprogress.xml (100%) rename {app => core}/src/main/res/layout/dialog_error.xml (100%) rename {app => core}/src/main/res/layout/okcancel.xml (100%) rename {app => core}/src/main/res/raw/error.mp3 (100%) rename {app => core}/src/main/res/values/fet_attrs.xml (100%) rename {app => core}/src/main/res/values/validator.xml (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/RecordTypes.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt (93%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/EnterPinActivity.kt (97%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt (98%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.kt (98%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.kt (99%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Version.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt (99%) rename {app => danars}/src/main/jniLibs/arm64-v8a/libBleEncryption.so (100%) rename {app => danars}/src/main/jniLibs/armeabi-v7a/libBleEncryption.so (100%) rename {app => danars}/src/main/jniLibs/x86/libBleEncryption.so (100%) rename {app => danars}/src/main/jniLibs/x86_64/libBleEncryption.so (100%) rename {app => danars}/src/main/res/layout/danars_enter_pin_activity.xml (100%) rename {app => danars}/src/main/res/xml/pref_danars.xml (100%) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt index 0b8fc440ca..f7872853f5 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt @@ -41,7 +41,6 @@ import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin -import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt index f4b6e9a27a..dbfd40c33d 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt @@ -4,6 +4,7 @@ import dagger.Module import dagger.android.ContributesAndroidInjector import info.nightscout.androidaps.MainActivity import info.nightscout.androidaps.activities.* +import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.historyBrowser.HistoryBrowseActivity import info.nightscout.androidaps.plugins.general.maintenance.activities.LogSettingActivity import info.nightscout.androidaps.plugins.general.maintenance.activities.PrefImportListActivity diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt index de00d631e4..e7b1903389 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt @@ -41,7 +41,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.omnipod.OmnipodPumpPlugin import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java index c5c723731c..f04035277e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java @@ -41,9 +41,11 @@ import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.CommandQueueProvider; import info.nightscout.androidaps.interfaces.Constraint; +import info.nightscout.androidaps.interfaces.LoopInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.AAPSLogger; @@ -53,7 +55,6 @@ import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui; import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker; -import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; @@ -65,15 +66,15 @@ import info.nightscout.androidaps.queue.commands.Command; import info.nightscout.androidaps.receivers.ReceiverStatusStore; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.HardLimits; import info.nightscout.androidaps.utils.T; import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.sharedPreferences.SP; -import info.nightscout.androidaps.utils.HardLimits; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.schedulers.Schedulers; @Singleton -public class LoopPlugin extends PluginBase { +public class LoopPlugin extends PluginBase implements LoopInterface { private final HasAndroidInjector injector; private final SP sp; private final RxBusWrapper rxBus; @@ -89,6 +90,7 @@ public class LoopPlugin extends PluginBase { private final IobCobCalculatorPlugin iobCobCalculatorPlugin; private final ReceiverStatusStore receiverStatusStore; private final FabricPrivacy fabricPrivacy; + private final NSUpload nsUpload; private final HardLimits hardLimits; private CompositeDisposable disposable = new CompositeDisposable(); @@ -101,21 +103,15 @@ public class LoopPlugin extends PluginBase { private boolean isSuperBolus; private boolean isDisconnected; - public class LastRun { - public APSResult request = null; - public APSResult constraintsProcessed = null; - public PumpEnactResult tbrSetByPump = null; - public PumpEnactResult smbSetByPump = null; - public String source = null; - public long lastAPSRun = DateUtil.now(); - public long lastTBREnact = 0; - public long lastSMBEnact = 0; - public long lastTBRRequest = 0; - public long lastSMBRequest = 0; - public long lastOpenModeAccept; + @Nullable public LastRun lastRun = null; + + @Nullable @Override public LastRun getLastRun() { + return lastRun; } - @Nullable public LastRun lastRun = null; + @Override public void setLastRun(@Nullable LastRun lastRun) { + this.lastRun = lastRun; + } @Inject public LoopPlugin( @@ -135,6 +131,7 @@ public class LoopPlugin extends PluginBase { IobCobCalculatorPlugin iobCobCalculatorPlugin, ReceiverStatusStore receiverStatusStore, FabricPrivacy fabricPrivacy, + NSUpload nsUpload, HardLimits hardLimits ) { super(new PluginDescription() @@ -161,6 +158,7 @@ public class LoopPlugin extends PluginBase { this.iobCobCalculatorPlugin = iobCobCalculatorPlugin; this.receiverStatusStore = receiverStatusStore; this.fabricPrivacy = fabricPrivacy; + this.nsUpload = nsUpload; this.hardLimits = hardLimits; loopSuspendedTill = sp.getLong("loopSuspendedTill", 0L); @@ -292,7 +290,7 @@ public class LoopPlugin extends PluginBase { return true; } - public boolean isLGS(){ + public boolean isLGS() { Constraint closedLoopEnabled = constraintChecker.isClosedLoopAllowed(); Double MaxIOBallowed = constraintChecker.getMaxIOBAllowed().value(); String APSmode = sp.getString(R.string.key_aps_mode, "open"); @@ -403,18 +401,18 @@ public class LoopPlugin extends PluginBase { } if (lastRun == null) lastRun = new LastRun(); - lastRun.request = result; - lastRun.constraintsProcessed = resultAfterConstraints; - lastRun.lastAPSRun = DateUtil.now(); - lastRun.source = ((PluginBase) usedAPS).getName(); - lastRun.tbrSetByPump = null; - lastRun.smbSetByPump = null; - lastRun.lastTBREnact = 0; - lastRun.lastTBRRequest = 0; - lastRun.lastSMBEnact = 0; - lastRun.lastSMBRequest = 0; + lastRun.setRequest(result); + lastRun.setConstraintsProcessed(resultAfterConstraints); + lastRun.setLastAPSRun(DateUtil.now()); + lastRun.setSource(((PluginBase) usedAPS).getName()); + lastRun.setTbrSetByPump(null); + lastRun.setSmbSetByPump(null); + lastRun.setLastTBREnact(0); + lastRun.setLastTBRRequest(0); + lastRun.setLastSMBEnact(0); + lastRun.setLastSMBRequest(0); - NSUpload.uploadDeviceStatus(this, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore); + nsUpload.uploadDeviceStatus(this, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore); if (isSuspended()) { getAapsLogger().debug(LTag.APS, resourceHelper.gs(R.string.loopsuspended)); @@ -437,27 +435,27 @@ public class LoopPlugin extends PluginBase { final PumpEnactResult waiting = new PumpEnactResult(getInjector()); waiting.queued = true; if (resultAfterConstraints.tempBasalRequested) - lastRun.tbrSetByPump = waiting; + lastRun.setTbrSetByPump(waiting); if (resultAfterConstraints.bolusRequested) - lastRun.smbSetByPump = waiting; + lastRun.setSmbSetByPump(waiting); rxBus.send(new EventLoopUpdateGui()); fabricPrivacy.logCustom("APSRequest"); applyTBRRequest(resultAfterConstraints, profile, new Callback() { @Override public void run() { if (result.enacted || result.success) { - lastRun.tbrSetByPump = result; - lastRun.lastTBRRequest = lastRun.lastAPSRun; - lastRun.lastTBREnact = DateUtil.now(); + lastRun.setTbrSetByPump(result); + lastRun.setLastTBRRequest(lastRun.getLastAPSRun()); + lastRun.setLastTBREnact(DateUtil.now()); rxBus.send(new EventLoopUpdateGui()); applySMBRequest(resultAfterConstraints, new Callback() { @Override public void run() { //Callback is only called if a bolus was acutally requested if (result.enacted || result.success) { - lastRun.smbSetByPump = result; - lastRun.lastSMBRequest = lastRun.lastAPSRun; - lastRun.lastSMBEnact = DateUtil.now(); + lastRun.setTbrSetByPump(result); + lastRun.setLastTBRRequest(lastRun.getLastAPSRun()); + lastRun.setLastTBREnact(DateUtil.now()); } else { new Thread(() -> { SystemClock.sleep(1000); @@ -472,8 +470,8 @@ public class LoopPlugin extends PluginBase { } }); } else { - lastRun.tbrSetByPump = null; - lastRun.smbSetByPump = null; + lastRun.setTbrSetByPump(null); + lastRun.setSmbSetByPump(null); } } else { if (resultAfterConstraints.isChangeRequested() && allowNotification) { @@ -531,15 +529,15 @@ public class LoopPlugin extends PluginBase { public void acceptChangeRequest() { Profile profile = profileFunction.getProfile(); final LoopPlugin lp = this; - applyTBRRequest(lastRun.constraintsProcessed, profile, new Callback() { + applyTBRRequest(lastRun.getConstraintsProcessed(), profile, new Callback() { @Override public void run() { if (result.enacted) { - lastRun.tbrSetByPump = result; - lastRun.lastTBRRequest = lastRun.lastAPSRun; - lastRun.lastTBREnact = DateUtil.now(); - lastRun.lastOpenModeAccept = DateUtil.now(); - NSUpload.uploadDeviceStatus(lp, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore); + lastRun.setTbrSetByPump(result); + lastRun.setLastTBRRequest(lastRun.getLastAPSRun()); + lastRun.setLastTBREnact(DateUtil.now()); + lastRun.setLastOpenModeAccept(DateUtil.now()); + nsUpload.uploadDeviceStatus(lp, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore); sp.incInt(R.string.key_ObjectivesmanualEnacts); } rxBus.send(new EventAcceptOpenLoopChange()); @@ -773,6 +771,7 @@ public class LoopPlugin extends PluginBase { event.eventType = CareportalEvent.OPENAPSOFFLINE; event.json = data.toString(); MainApp.getDbHelper().createOrUpdate(event); - NSUpload.uploadOpenAPSOffline(event); + nsUpload.uploadOpenAPSOffline(event); } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt index 4d9021bb71..4fa6c43fce 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt @@ -20,7 +20,6 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.maintenance.formats.* -import info.nightscout.androidaps.plugins.general.smsCommunicator.otp.OneTimePassword import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.alertDialogs.OKDialog diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java index 0786aae250..d9bd5a6307 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java @@ -16,6 +16,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DbRequest; +import info.nightscout.androidaps.interfaces.UploadQueueInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; @@ -27,7 +28,7 @@ import info.nightscout.androidaps.utils.SP; /** * Created by mike on 21.02.2016. */ -public class UploadQueue { +public class UploadQueue implements UploadQueueInterface { private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); public static String status() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt index e8d32ed386..ca4b8c1720 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt @@ -14,7 +14,6 @@ import info.nightscout.androidaps.Constants import info.nightscout.androidaps.MainActivity import info.nightscout.androidaps.R import info.nightscout.androidaps.data.Profile -import info.nightscout.androidaps.db.DatabaseHelper import info.nightscout.androidaps.events.* import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java index ace9df0a97..de9b4e66fc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java @@ -485,7 +485,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr getAapsLogger().error("deliverTreatment: Invalid input"); return new PumpEnactResult(getInjector()).success(false).enacted(false) .bolusDelivered(0d).carbsDelivered(0d) - .comment(getResourceHelper().gs(R.string.danar_invalidinput)); + .comment(getResourceHelper().gs(R.string.invalidinput)); } else if (detailedBolusInfo.insulin > 0) { // bolus needed, ask pump to deliver it return deliverBolus(detailedBolusInfo); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java index 0bb38acb76..6d06f2e788 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java @@ -413,7 +413,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI // neither carbs nor bolus requested aapsLogger.error("deliverTreatment: Invalid input"); return new PumpEnactResult(getInjector()).success(false).enacted(false).bolusDelivered(0d).carbsDelivered(0d) - .comment(getResourceHelper().gs(R.string.danar_invalidinput)); + .comment(getResourceHelper().gs(R.string.invalidinput)); } else if (detailedBolusInfo.insulin > 0) { // bolus needed, ask pump to deliver it return deliverBolus(detailedBolusInfo); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java index 064e7c8d5b..b055cacda3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java @@ -224,7 +224,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump result.isTempCancel = false; result.enacted = false; result.success = false; - result.comment = getResourceHelper().gs(R.string.danar_invalidinput); + result.comment = getResourceHelper().gs(R.string.invalidinput); getAapsLogger().error("setTempBasalPercent: Invalid input"); return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java index d0d1442225..aae520eb06 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java @@ -180,7 +180,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { result.success = false; result.bolusDelivered = 0d; result.carbsDelivered = 0d; - result.comment = resourceHelper.gs(R.string.danar_invalidinput); + result.comment = resourceHelper.gs(R.string.invalidinput); aapsLogger.error("deliverTreatment: Invalid input"); return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt index 18ffab8460..eb63a70a0e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt @@ -151,7 +151,7 @@ class DanaRHistoryActivity : NoSplashAppCompatActivity() { holder.duration.text = DecimalFormatter.to0Decimal(record.recordDuration.toDouble()) holder.alarm.text = record.recordAlarm when (showingType) { - RecordTypes.RECORD_TYPE_ALARM -> { + RecordTypes.RECORD_TYPE_ALARM -> { holder.time.visibility = View.VISIBLE holder.value.visibility = View.VISIBLE holder.stringValue.visibility = View.GONE @@ -163,7 +163,7 @@ class DanaRHistoryActivity : NoSplashAppCompatActivity() { holder.alarm.visibility = View.VISIBLE } - RecordTypes.RECORD_TYPE_BOLUS -> { + RecordTypes.RECORD_TYPE_BOLUS -> { holder.time.visibility = View.VISIBLE holder.value.visibility = View.VISIBLE holder.stringValue.visibility = View.GONE @@ -175,7 +175,7 @@ class DanaRHistoryActivity : NoSplashAppCompatActivity() { holder.alarm.visibility = View.GONE } - RecordTypes.RECORD_TYPE_DAILY -> { + RecordTypes.RECORD_TYPE_DAILY -> { holder.dailyBasal.text = resourceHelper.gs(R.string.formatinsulinunits, record.recordDailyBasal) holder.dailyBolus.text = resourceHelper.gs(R.string.formatinsulinunits, record.recordDailyBolus) holder.dailyTotal.text = resourceHelper.gs(R.string.formatinsulinunits, record.recordDailyBolus + record.recordDailyBasal) @@ -191,7 +191,7 @@ class DanaRHistoryActivity : NoSplashAppCompatActivity() { holder.alarm.visibility = View.GONE } - RecordTypes.RECORD_TYPE_GLUCOSE -> { + RecordTypes.RECORD_TYPE_GLUCOSE -> { holder.value.text = Profile.toUnitsString(record.recordValue, record.recordValue * Constants.MGDL_TO_MMOLL, profileFunction.getUnits()) holder.time.visibility = View.VISIBLE holder.value.visibility = View.VISIBLE @@ -216,7 +216,7 @@ class DanaRHistoryActivity : NoSplashAppCompatActivity() { holder.alarm.visibility = View.GONE } - RecordTypes.RECORD_TYPE_SUSPEND -> { + RecordTypes.RECORD_TYPE_SUSPEND -> { holder.time.visibility = View.VISIBLE holder.value.visibility = View.GONE holder.stringValue.visibility = View.VISIBLE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt index 3572e0eb54..b25a5b9b1f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt @@ -136,7 +136,7 @@ open class MsgHistoryAll( danaRHistoryRecord.stringRecordValue = strRecordValue } - 17.toByte() -> failed = true + 17.toByte() -> failed = true } MainApp.getDbHelper().createOrUpdate(danaRHistoryRecord) rxBus.send(EventDanaRSyncStatus(dateUtil.dateAndTimeString(danaRHistoryRecord.recordDate) + " " + messageType)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java index 201b43f184..ad079c06ce 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java @@ -182,7 +182,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { result.success = false; result.bolusDelivered = 0d; result.carbsDelivered = 0d; - result.comment = resourceHelper.gs(R.string.danar_invalidinput); + result.comment = resourceHelper.gs(R.string.invalidinput); aapsLogger.error("deliverTreatment: Invalid input"); return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java index d9f41d0b3f..992819a136 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java @@ -200,7 +200,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { result.success = false; result.bolusDelivered = 0d; result.carbsDelivered = 0d; - result.comment = resourceHelper.gs(R.string.danar_invalidinput); + result.comment = resourceHelper.gs(R.string.invalidinput); aapsLogger.error("deliverTreatment: Invalid input"); return result; } @@ -301,7 +301,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { result.isTempCancel = false; result.enacted = false; result.success = false; - result.comment = resourceHelper.gs(R.string.danar_invalidinput); + result.comment = resourceHelper.gs(R.string.invalidinput); aapsLogger.error("setTempBasalPercent: Invalid input"); return result; } 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 95a3f68c12..77df3be676 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 @@ -201,7 +201,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter if (pref.getKey().equals(getResourceHelper().gs(R.string.key_rileylink_mac_address))) { String value = sp.getStringOrNull(R.string.key_rileylink_mac_address, null); - pref.setSummary(value == null ? getResourceHelper().gs(R.string.rileylink_error_address_not_set_short) : value); + pref.setSummary(value == null ? getResourceHelper().gs(R.string.not_set_short) : value); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java index 0c51b5901c..8d5c7b8b41 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java @@ -24,7 +24,6 @@ import javax.inject.Inject; import javax.inject.Singleton; import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.activities.ErrorHelperActivity; import info.nightscout.androidaps.data.DetailedBolusInfo; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java index 3dd183bff6..4d28d2dcdd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java @@ -75,6 +75,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface private final ResourceHelper resourceHelper; private final ProfileFunction profileFunction; private final ActivePluginProvider activePlugin; + private final NSUpload nsUpload; private final FabricPrivacy fabricPrivacy; private final DateUtil dateUtil; @@ -101,6 +102,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface SP sp, ProfileFunction profileFunction, ActivePluginProvider activePlugin, + NSUpload nsUpload, FabricPrivacy fabricPrivacy, DateUtil dateUtil ) { @@ -122,6 +124,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface this.activePlugin = activePlugin; this.fabricPrivacy = fabricPrivacy; this.dateUtil = dateUtil; + this.nsUpload = nsUpload; } @Override @@ -553,13 +556,13 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface if (newRecordCreated) { if (extendedBolus.durationInMinutes == 0) { if (activePlugin.getActivePump().isFakingTempsByExtendedBoluses()) - NSUpload.uploadTempBasalEnd(extendedBolus.date, true, extendedBolus.pumpId); + nsUpload.uploadTempBasalEnd(extendedBolus.date, true, extendedBolus.pumpId); else - NSUpload.uploadExtendedBolusEnd(extendedBolus.date, extendedBolus.pumpId); + nsUpload.uploadExtendedBolusEnd(extendedBolus.date, extendedBolus.pumpId); } else if (activePlugin.getActivePump().isFakingTempsByExtendedBoluses()) - NSUpload.uploadTempBasalStartAbsolute(new TemporaryBasal(extendedBolus), extendedBolus.insulin); + nsUpload.uploadTempBasalStartAbsolute(new TemporaryBasal(extendedBolus), extendedBolus.insulin); else - NSUpload.uploadExtendedBolus(extendedBolus); + nsUpload.uploadExtendedBolus(extendedBolus); } return newRecordCreated; } @@ -586,11 +589,11 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface boolean newRecordCreated = MainApp.getDbHelper().createOrUpdate(tempBasal); if (newRecordCreated) { if (tempBasal.durationInMinutes == 0) - NSUpload.uploadTempBasalEnd(tempBasal.date, false, tempBasal.pumpId); + nsUpload.uploadTempBasalEnd(tempBasal.date, false, tempBasal.pumpId); else if (tempBasal.isAbsolute) - NSUpload.uploadTempBasalStartAbsolute(tempBasal, null); + nsUpload.uploadTempBasalStartAbsolute(tempBasal, null); else - NSUpload.uploadTempBasalStartPercent(tempBasal, profileFunction.getProfile(tempBasal.date)); + nsUpload.uploadTempBasalStartPercent(tempBasal, profileFunction.getProfile(tempBasal.date)); } return newRecordCreated; } @@ -641,7 +644,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface //log.debug("Adding new Treatment record" + carbsTreatment); } if (newRecordCreated && detailedBolusInfo.isValid) - NSUpload.uploadTreatmentRecord(detailedBolusInfo); + nsUpload.uploadTreatmentRecord(detailedBolusInfo); if (!allowUpdate && !creatOrUpdateResult.success) { getAapsLogger().error("Treatment could not be added to DB", new Exception()); @@ -710,7 +713,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface public void addToHistoryTempTarget(TempTarget tempTarget) { //log.debug("Adding new TemporaryBasal record" + profileSwitch.log()); MainApp.getDbHelper().createOrUpdate(tempTarget); - NSUpload.uploadTempTarget(tempTarget, profileFunction); + nsUpload.uploadTempTarget(tempTarget, profileFunction); } @Override @@ -733,7 +736,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface //log.debug("Adding new TemporaryBasal record" + profileSwitch.log()); rxBus.send(new EventDismissNotification(Notification.PROFILE_SWITCH_MISSING)); MainApp.getDbHelper().createOrUpdate(profileSwitch); - NSUpload.uploadProfileSwitch(profileSwitch); + nsUpload.uploadProfileSwitch(profileSwitch); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/utils/androidNotification/NotificationHolder.kt b/app/src/main/java/info/nightscout/androidaps/utils/androidNotification/NotificationHolder.kt index 6ee23a85f5..028c63086e 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/androidNotification/NotificationHolder.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/androidNotification/NotificationHolder.kt @@ -10,6 +10,7 @@ import androidx.core.app.TaskStackBuilder import info.nightscout.androidaps.MainActivity import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R +import info.nightscout.androidaps.interfaces.NotificationHolderInterface import info.nightscout.androidaps.utils.resources.IconsProvider import info.nightscout.androidaps.utils.resources.ResourceHelper import javax.inject.Inject @@ -20,11 +21,11 @@ class NotificationHolder @Inject constructor( private val resourceHelper: ResourceHelper, private val context: Context, private val iconsProvider: IconsProvider -) { +) : NotificationHolderInterface { - val channelID = "AndroidAPS-Ongoing" - val notificationID = 4711 - var notification: Notification + override val channelID = "AndroidAPS-Ongoing" + override val notificationID = 4711 + override lateinit var notification: Notification init { val stackBuilder = TaskStackBuilder.create(context) diff --git a/app/src/main/jniLibs/README.md b/app/src/main/jniLibs/README.md deleted file mode 100644 index 7041df4e10..0000000000 --- a/app/src/main/jniLibs/README.md +++ /dev/null @@ -1 +0,0 @@ -# danars-support-lib \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 35a25bca9b..b36ff01254 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -62,7 +62,6 @@ Pump integration for DANA Diabecare R pumps Pump integration for domestic DANA Diabecare R pumps Pump integration for DANA Diabecare R pumps with upgraded firmware - Pump integration for DANA Diabecare RS pumps Pump integration for people who do multiple daily injections for their diabetes therapy Pump integration for pumps which don\'t have any driver yet (Open Loop) Sensitivity is calculated the same way like Oref0, but you can specify timeframe to the past. Minimal carb absorption is calculated from max carb absorption time from preferences. @@ -161,7 +160,6 @@ Plugin is disabled Constraints violation Bolus delivery error - Tempbasal delivery error Basal value [%] Accept new temp basal: Treatment @@ -283,9 +281,6 @@ in directory: %1$s DanaR - Connecting - Connected - Disconnected Dana pump settings End User License Agreement MUST NOT BE USED TO MAKE MEDICAL DECISIONS. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. @@ -297,8 +292,6 @@ Pump IOB Daily units Last bolus - Invalid input data - Value not set properly Reload profile View profile SMS Communicator @@ -328,7 +321,6 @@ DanaR profile settings DIA [h] Duration of Insulin Activity - Failed to update basal profile Reload Uploading E bolus @@ -351,7 +343,6 @@ Glucose Refill Suspend - Connecting for %1$d s Pump password (v1 only) Pump password Wrong pump password! @@ -363,8 +354,6 @@ Occlusion Stop STOP PRESSED - Waiting for pump - Going to deliver %1$.2fU You reached allowed limit Loop has been disabled Loop has been enabled @@ -406,11 +395,9 @@ Meal Corr Actions - AndroidAPS started NS upload only (disabled sync) NS upload only. Not effective on SGV unless a local source like xDrip is selected. Not effective on Profiles while NS-Profiles is used. Pump not initialized! - Pump not initialized, profile not set! Prime/Fill Please make sure the amount matches the specification of your infusion set! Other @@ -439,7 +426,6 @@ DanaR Korean Basal rate: Setting of basal profile failed - Basal profile in pump updated Disable EasyUI mode in pump Enable extended boluses on pump Change mode from U/d to U/h on pump @@ -531,7 +517,6 @@ Setting extended bolus Stopping extended bolus Updating basal rates - Disconnecting Executing Virtual pump settings Upload status to NS @@ -609,7 +594,6 @@ COB Superbolus Log app start to NS - ns_logappstartedevent Exiting application to apply settings. DanaRv2 Which type of insulin are you using? @@ -751,20 +735,12 @@ Date INVALID Pairing - danars_pairing_key_ - danars_v3_randompairing_key_ - danars_v3_pairing_key_ - danars_v3_randomsync_key_ Empty reservoir Blood sugar measurement alert Remaining insulin level Missed bolus - DanaRS - Dana Selected pump Bolus speed - danars_bolusspeed - Set basal step to 0.01 U/h Serial number wizard_include_cob wizard_include_trend_bg @@ -938,7 +914,6 @@ History browser Notify on SMB Show SMB on the watch like a standard bolus. - ns_create_announcements_from_errors Create announcements from errors Create Nightscout announcement for error dialogs and local alerts (also viewable in Careportal under Treatments) EVR @@ -994,20 +969,15 @@ SMB disabled in preferences UAM disabled in preferences UAM disabled because it rely on Oref1 sensitivity plugin - Limiting max basal rate to %1$.2f U/h because of %2$s - pump limit openapsma_max_basal openapsama_current_basal_safety_multiplier openapsama_max_daily_safety_multiplier - it must be positive value max basal multiplier max daily basal multiplier openapsma_max_iob A bolus was delivered within the last 3 minutes, skipping SMB Basal set correctly - Limiting max percent rate to %1$d%% because of %2$s treatmentssafety_maxbolus - Limiting bolus to %1$.1f U because of %2$s Limiting extended bolus to %1$.1f U because of %2$s Limiting max IOB to %1$.1f U because of %2$s Limiting carbs to %1$d g because of %2$s @@ -1044,7 +1014,6 @@ Setup Wizard FINISH Select your language - Asked: %1$.2fU Delivered: %2$.2fU Error code: %3$s First insulin increment Second insulin increment Third insulin increment @@ -1183,12 +1152,7 @@ Preferred APS mode Total Calc - Handshaking Send today\'s log files to developers along with this time. Unexpected situation. - Max bolus violation - Command error - Speed error - Insulin limit violation Minimal request change [%] Open Loop will popup new change request only if change is bigger than this value in %. Default value is 20% short_tabtitles @@ -1521,7 +1485,6 @@ TuneUp Failed Pump unreachable Pod unreachable - Not set Medtronic Pump @@ -1636,7 +1599,6 @@ Time and/or Timezone change on pump No pump selected Select units you want to display values in - ns_uploadlocalprofile Upload local profile changes to NS wear_detailediob wear_showbgi @@ -1674,7 +1636,6 @@ BG Tools Show calcuation - Error 12h 24h Automation event @@ -1741,10 +1702,8 @@ Predictions Deviation slope graphconfig - rs_loginsulinchange Log reservoir change Add \"Insulin Change\" event to careportal when detected in history - rs_logcanulachange Log canula change Add \"Site Change\" event to careportal when detected in history Authorization failed diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorageTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorageTest.kt index 28117e5583..9f483da250 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorageTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorageTest.kt @@ -2,13 +2,11 @@ package info.nightscout.androidaps.plugins.pump.common.bolusInfo import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.data.DetailedBolusInfo -import info.nightscout.androidaps.logging.AAPSLogger import org.junit.Assert.assertEquals import org.junit.Assert.assertNull import org.junit.Before import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) diff --git a/core/build.gradle b/core/build.gradle index bde94da837..b3045c0f35 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -46,6 +46,7 @@ dependencies { implementation "androidx.preference:preference-ktx:1.1.1" implementation "androidx.activity:activity:${activityVersion}" implementation "androidx.activity:activity-ktx:${activityVersion}" + implementation 'com.google.android.material:material:1.1.0' implementation "com.google.dagger:dagger-android:$dagger_version" implementation "com.google.dagger:dagger-android-support:$dagger_version" diff --git a/app/src/main/java/info/nightscout/androidaps/activities/BolusProgressHelperActivity.kt b/core/src/main/java/info/nightscout/androidaps/activities/BolusProgressHelperActivity.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/activities/BolusProgressHelperActivity.kt rename to core/src/main/java/info/nightscout/androidaps/activities/BolusProgressHelperActivity.kt diff --git a/app/src/main/java/info/nightscout/androidaps/activities/DialogAppCompatActivity.kt b/core/src/main/java/info/nightscout/androidaps/activities/DialogAppCompatActivity.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/activities/DialogAppCompatActivity.kt rename to core/src/main/java/info/nightscout/androidaps/activities/DialogAppCompatActivity.kt diff --git a/app/src/main/java/info/nightscout/androidaps/activities/ErrorHelperActivity.kt b/core/src/main/java/info/nightscout/androidaps/activities/ErrorHelperActivity.kt similarity index 86% rename from app/src/main/java/info/nightscout/androidaps/activities/ErrorHelperActivity.kt rename to core/src/main/java/info/nightscout/androidaps/activities/ErrorHelperActivity.kt index ce02742381..11affb41d3 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/ErrorHelperActivity.kt +++ b/core/src/main/java/info/nightscout/androidaps/activities/ErrorHelperActivity.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.activities import android.os.Bundle -import info.nightscout.androidaps.R +import info.nightscout.androidaps.core.R import info.nightscout.androidaps.dialogs.ErrorDialog import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -9,6 +9,7 @@ import javax.inject.Inject class ErrorHelperActivity : DialogAppCompatActivity() { @Inject lateinit var sp : SP + @Inject lateinit var nsUpload: NSUpload @Override override fun onCreate(savedInstanceState: Bundle?) { @@ -21,7 +22,7 @@ class ErrorHelperActivity : DialogAppCompatActivity() { errorDialog.show(supportFragmentManager, "Error") if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) { - NSUpload.uploadError(intent.getStringExtra("status")) + nsUpload.uploadError(intent.getStringExtra("status")) } } } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/BolusProgressDialog.kt b/core/src/main/java/info/nightscout/androidaps/dialogs/BolusProgressDialog.kt similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/dialogs/BolusProgressDialog.kt rename to core/src/main/java/info/nightscout/androidaps/dialogs/BolusProgressDialog.kt index 8152c25ab0..98e459a5b9 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/BolusProgressDialog.kt +++ b/core/src/main/java/info/nightscout/androidaps/dialogs/BolusProgressDialog.kt @@ -9,8 +9,8 @@ import android.view.ViewGroup import android.view.Window import android.view.WindowManager import dagger.android.support.DaggerDialogFragment -import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.BolusProgressHelperActivity +import info.nightscout.androidaps.core.R import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.logging.AAPSLogger @@ -71,7 +71,7 @@ class BolusProgressDialog : DaggerDialogFragment() { savedInstanceState?.let { amount = it.getDouble("amount") } - overview_bolusprogress_title.text = resourceHelper.gs(R.string.overview_bolusprogress_goingtodeliver, amount) + overview_bolusprogress_title.text = resourceHelper.gs(R.string.goingtodeliver, amount) overview_bolusprogress_stop.setOnClickListener { aapsLogger.debug(LTag.UI, "Stop bolus delivery button pressed") stopPressed = true diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ErrorDialog.kt b/core/src/main/java/info/nightscout/androidaps/dialogs/ErrorDialog.kt similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/dialogs/ErrorDialog.kt rename to core/src/main/java/info/nightscout/androidaps/dialogs/ErrorDialog.kt index 07917899bf..9d2035b279 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ErrorDialog.kt +++ b/core/src/main/java/info/nightscout/androidaps/dialogs/ErrorDialog.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.dialogs +import android.content.Context import android.content.Intent import android.os.Build import android.os.Bundle @@ -9,9 +10,8 @@ import android.view.ViewGroup import android.view.Window import android.view.WindowManager import dagger.android.support.DaggerDialogFragment -import info.nightscout.androidaps.MainApp -import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.ErrorHelperActivity +import info.nightscout.androidaps.core.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.services.AlarmSoundService import kotlinx.android.synthetic.main.dialog_error.* @@ -19,7 +19,6 @@ import javax.inject.Inject class ErrorDialog : DaggerDialogFragment() { @Inject lateinit var aapsLogger: AAPSLogger - @Inject lateinit var mainApp: MainApp var helperActivity: ErrorHelperActivity? = null var status: String = "" @@ -82,16 +81,16 @@ class ErrorDialog : DaggerDialogFragment() { private fun startAlarm() { if (sound != 0) { - val alarm = Intent(mainApp, AlarmSoundService::class.java) + val alarm = Intent(context, AlarmSoundService::class.java) alarm.putExtra("soundid", sound) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - mainApp.startForegroundService(alarm) + context?.startForegroundService(alarm) } else { - mainApp.startService(alarm) + context?.startService(alarm) } } } private fun stopAlarm() = - mainApp.stopService(Intent(mainApp, AlarmSoundService::class.java)) + context?.stopService(Intent(context, AlarmSoundService::class.java)) } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventAppExit.kt b/core/src/main/java/info/nightscout/androidaps/events/EventAppExit.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/events/EventAppExit.kt rename to core/src/main/java/info/nightscout/androidaps/events/EventAppExit.kt diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventChargingState.kt b/core/src/main/java/info/nightscout/androidaps/events/EventChargingState.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/events/EventChargingState.kt rename to core/src/main/java/info/nightscout/androidaps/events/EventChargingState.kt diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventConfigBuilderChange.kt b/core/src/main/java/info/nightscout/androidaps/events/EventConfigBuilderChange.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/events/EventConfigBuilderChange.kt rename to core/src/main/java/info/nightscout/androidaps/events/EventConfigBuilderChange.kt diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventInitializationChanged.kt b/core/src/main/java/info/nightscout/androidaps/events/EventInitializationChanged.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/events/EventInitializationChanged.kt rename to core/src/main/java/info/nightscout/androidaps/events/EventInitializationChanged.kt diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventNetworkChange.kt b/core/src/main/java/info/nightscout/androidaps/events/EventNetworkChange.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/events/EventNetworkChange.kt rename to core/src/main/java/info/nightscout/androidaps/events/EventNetworkChange.kt diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventProfileNeedsUpdate.kt b/core/src/main/java/info/nightscout/androidaps/events/EventProfileNeedsUpdate.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/events/EventProfileNeedsUpdate.kt rename to core/src/main/java/info/nightscout/androidaps/events/EventProfileNeedsUpdate.kt diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.kt b/core/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.kt similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.kt rename to core/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.kt index cc92defe8d..0b9ce7ebf0 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.kt +++ b/core/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.events -import info.nightscout.androidaps.R +import info.nightscout.androidaps.core.R import info.nightscout.androidaps.utils.resources.ResourceHelper class EventPumpStatusChanged : EventStatus { @@ -46,7 +46,7 @@ class EventPumpStatusChanged : EventStatus { // status for startup wizard override fun getStatus(resourceHelper: ResourceHelper): String { return when (status) { - Status.CONNECTING -> String.format(resourceHelper.gs(R.string.danar_history_connectingfor), secondsElapsed) + Status.CONNECTING -> String.format(resourceHelper.gs(R.string.connectingfor), secondsElapsed) Status.HANDSHAKING -> resourceHelper.gs(R.string.handshaking) Status.CONNECTED -> resourceHelper.gs(R.string.connected) Status.PERFORMING -> performingAction diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventStatus.kt b/core/src/main/java/info/nightscout/androidaps/events/EventStatus.kt similarity index 84% rename from app/src/main/java/info/nightscout/androidaps/events/EventStatus.kt rename to core/src/main/java/info/nightscout/androidaps/events/EventStatus.kt index 360b62f0e9..88c8073e69 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventStatus.kt +++ b/core/src/main/java/info/nightscout/androidaps/events/EventStatus.kt @@ -3,6 +3,6 @@ package info.nightscout.androidaps.events import info.nightscout.androidaps.utils.resources.ResourceHelper // pass string to startup wizard -abstract class EventStatus :Event() { +abstract class EventStatus : Event() { abstract fun getStatus(resourceHelper: ResourceHelper) : String } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/DanaRInterface.java b/core/src/main/java/info/nightscout/androidaps/interfaces/DanaRInterface.java similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/interfaces/DanaRInterface.java rename to core/src/main/java/info/nightscout/androidaps/interfaces/DanaRInterface.java diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/IobCobCalculatorInterface.java b/core/src/main/java/info/nightscout/androidaps/interfaces/IobCobCalculatorInterface.java index 2d06449082..75a57b2c07 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/IobCobCalculatorInterface.java +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/IobCobCalculatorInterface.java @@ -2,10 +2,13 @@ package info.nightscout.androidaps.interfaces; import androidx.collection.LongSparseArray; +import info.nightscout.androidaps.data.IobTotal; +import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData; public interface IobCobCalculatorInterface { LongSparseArray getAutosensDataTable(); + IobTotal[] calculateIobArrayInDia(Profile profile); String lastDataTime(); AutosensData getAutosensData(long toTime); } diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/LoopInterface.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/LoopInterface.kt new file mode 100644 index 0000000000..2ec67b461b --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/LoopInterface.kt @@ -0,0 +1,24 @@ +package info.nightscout.androidaps.interfaces + +import info.nightscout.androidaps.data.PumpEnactResult +import info.nightscout.androidaps.plugins.aps.loop.APSResult +import info.nightscout.androidaps.utils.DateUtil + +interface LoopInterface { + + class LastRun { + var request: APSResult? = null + var constraintsProcessed: APSResult? = null + var tbrSetByPump: PumpEnactResult? = null + var smbSetByPump: PumpEnactResult? = null + var source: String? = null + var lastAPSRun = DateUtil.now() + var lastTBREnact: Long = 0 + var lastSMBEnact: Long = 0 + var lastTBRRequest: Long = 0 + var lastSMBRequest: Long = 0 + var lastOpenModeAccept: Long = 0 + } + + var lastRun: LastRun? +} \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/NotificationHolderInterface.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/NotificationHolderInterface.kt new file mode 100644 index 0000000000..cbba8f326a --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/NotificationHolderInterface.kt @@ -0,0 +1,10 @@ +package info.nightscout.androidaps.interfaces + +import android.app.Notification + +interface NotificationHolderInterface { + val channelID : String + val notificationID : Int + var notification: Notification + +} \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/UploadQueueInterface.java b/core/src/main/java/info/nightscout/androidaps/interfaces/UploadQueueInterface.java new file mode 100644 index 0000000000..d051d43501 --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/UploadQueueInterface.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.interfaces; + +import info.nightscout.androidaps.db.DbRequest; + +public interface UploadQueueInterface { + + void add(DbRequest dbRequest); +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java b/core/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java rename to core/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java b/core/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java similarity index 66% rename from app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java rename to core/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java index 48a2b31b35..85331b0f3a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java +++ b/core/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java @@ -1,31 +1,29 @@ package info.nightscout.androidaps.plugins.general.nsclient; +import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.ResolveInfo; import android.os.Build; import android.os.Bundle; import androidx.annotation.Nullable; -import androidx.preference.PreferenceManager; import org.apache.commons.lang3.StringUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.slf4j.Logger; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Locale; -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; +import javax.inject.Singleton; + +import info.nightscout.androidaps.core.R; import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.interfaces.ProfileStore; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.DbRequest; @@ -33,27 +31,50 @@ import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.interfaces.IobCobCalculatorInterface; +import info.nightscout.androidaps.interfaces.LoopInterface; +import info.nightscout.androidaps.interfaces.ProfileFunction; +import info.nightscout.androidaps.interfaces.ProfileStore; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.interfaces.UploadQueueInterface; +import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.plugins.aps.loop.APSResult; import info.nightscout.androidaps.plugins.aps.loop.DeviceStatus; -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; -import info.nightscout.androidaps.interfaces.ProfileFunction; -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.receivers.ReceiverStatusStore; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.JsonHelper; -import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.resources.ResourceHelper; +import info.nightscout.androidaps.utils.sharedPreferences.SP; /** * Created by mike on 26.05.2017. */ +@Singleton public class NSUpload { - private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); - public static void uploadTempBasalStartAbsolute(TemporaryBasal temporaryBasal, Double originalExtendedAmount) { + private final AAPSLogger aapsLogger; + private final ResourceHelper resourceHelper; + private final SP sp; + private final Context context; + private final UploadQueueInterface uploadQueue; + + public NSUpload( + AAPSLogger aapsLogger, + ResourceHelper resourceHelper, + SP sp, + Context context, + UploadQueueInterface uploadQueue + ) { + this.aapsLogger = aapsLogger; + this.resourceHelper = resourceHelper; + this.sp = sp; + this.context = context; + this.uploadQueue = uploadQueue; + } + + public void uploadTempBasalStartAbsolute(TemporaryBasal temporaryBasal, Double originalExtendedAmount) { try { JSONObject data = new JSONObject(); data.put("eventType", CareportalEvent.TEMPBASAL); @@ -63,19 +84,18 @@ public class NSUpload { if (temporaryBasal.pumpId != 0) data.put("pumpId", temporaryBasal.pumpId); data.put("created_at", DateUtil.toISOString(temporaryBasal.date)); - data.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name)); + data.put("enteredBy", "openaps://" + "AndroidAPS"); if (originalExtendedAmount != null) data.put("originalExtendedAmount", originalExtendedAmount); // for back synchronization - UploadQueue.add(new DbRequest("dbAdd", "treatments", data)); + uploadQueue.add(new DbRequest("dbAdd", "treatments", data)); } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } - public static void uploadTempBasalStartPercent(TemporaryBasal temporaryBasal, Profile profile) { + public void uploadTempBasalStartPercent(TemporaryBasal temporaryBasal, Profile profile) { try { - SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); - boolean useAbsolute = SP.getBoolean("ns_sync_use_absolute", false); + boolean useAbsolute = sp.getBoolean("ns_sync_use_absolute", false); double absoluteRate = 0; if (profile != null) { absoluteRate = profile.getBasal(temporaryBasal.date) * temporaryBasal.percentRate / 100d; @@ -97,31 +117,31 @@ public class NSUpload { if (temporaryBasal.pumpId != 0) data.put("pumpId", temporaryBasal.pumpId); data.put("created_at", DateUtil.toISOString(temporaryBasal.date)); - data.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name)); - UploadQueue.add(new DbRequest("dbAdd", "treatments", data)); + data.put("enteredBy", "openaps://" + "AndroidAPS"); + uploadQueue.add(new DbRequest("dbAdd", "treatments", data)); } } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } - public static void uploadTempBasalEnd(long time, boolean isFakedTempBasal, long pumpId) { + public void uploadTempBasalEnd(long time, boolean isFakedTempBasal, long pumpId) { try { JSONObject data = new JSONObject(); data.put("eventType", CareportalEvent.TEMPBASAL); data.put("created_at", DateUtil.toISOString(time)); - data.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name)); + data.put("enteredBy", "openaps://" + "AndroidAPS"); if (isFakedTempBasal) data.put("isFakedTempBasal", isFakedTempBasal); if (pumpId != 0) data.put("pumpId", pumpId); - UploadQueue.add(new DbRequest("dbAdd", "treatments", data)); + uploadQueue.add(new DbRequest("dbAdd", "treatments", data)); } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } - public static void uploadExtendedBolus(ExtendedBolus extendedBolus) { + public void uploadExtendedBolus(ExtendedBolus extendedBolus) { try { JSONObject data = new JSONObject(); data.put("eventType", CareportalEvent.COMBOBOLUS); @@ -133,14 +153,14 @@ public class NSUpload { if (extendedBolus.pumpId != 0) data.put("pumpId", extendedBolus.pumpId); data.put("created_at", DateUtil.toISOString(extendedBolus.date)); - data.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name)); - UploadQueue.add(new DbRequest("dbAdd", "treatments", data)); + data.put("enteredBy", "openaps://" + "AndroidAPS"); + uploadQueue.add(new DbRequest("dbAdd", "treatments", data)); } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } - public static void uploadExtendedBolusEnd(long time, long pumpId) { + public void uploadExtendedBolusEnd(long time, long pumpId) { try { JSONObject data = new JSONObject(); data.put("eventType", CareportalEvent.COMBOBOLUS); @@ -150,59 +170,59 @@ public class NSUpload { data.put("enteredinsulin", 0); data.put("relative", 0); data.put("created_at", DateUtil.toISOString(time)); - data.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name)); + data.put("enteredBy", "openaps://" + "AndroidAPS"); if (pumpId != 0) data.put("pumpId", pumpId); - UploadQueue.add(new DbRequest("dbAdd", "treatments", data)); + uploadQueue.add(new DbRequest("dbAdd", "treatments", data)); } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } - public static void uploadDeviceStatus(LoopPlugin loopPlugin, IobCobCalculatorPlugin iobCobCalculatorPlugin, ProfileFunction profileFunction, PumpInterface pumpInterface, ReceiverStatusStore receiverStatusStore) { + public void uploadDeviceStatus(LoopInterface loopPlugin, IobCobCalculatorInterface iobCobCalculatorPlugin, ProfileFunction profileFunction, PumpInterface pumpInterface, ReceiverStatusStore receiverStatusStore) { Profile profile = profileFunction.getProfile(); String profileName = profileFunction.getProfileName(); if (profile == null) { - log.error("Profile is null. Skipping upload"); + aapsLogger.error("Profile is null. Skipping upload"); return; } DeviceStatus deviceStatus = new DeviceStatus(); try { - LoopPlugin.LastRun lastRun = loopPlugin.lastRun; - if (lastRun != null && lastRun.lastAPSRun > System.currentTimeMillis() - 300 * 1000L) { + LoopInterface.LastRun lastRun = loopPlugin.getLastRun(); + if (lastRun != null && lastRun.getLastAPSRun() > System.currentTimeMillis() - 300 * 1000L) { // do not send if result is older than 1 min - APSResult apsResult = lastRun.request; - apsResult.json().put("timestamp", DateUtil.toISOString(lastRun.lastAPSRun)); + APSResult apsResult = lastRun.getRequest(); + apsResult.json().put("timestamp", DateUtil.toISOString(lastRun.getLastAPSRun())); deviceStatus.suggested = apsResult.json(); - deviceStatus.iob = lastRun.request.iob.json(); - deviceStatus.iob.put("time", DateUtil.toISOString(lastRun.lastAPSRun)); + deviceStatus.iob = lastRun.getRequest().iob.json(); + deviceStatus.iob.put("time", DateUtil.toISOString(lastRun.getLastAPSRun())); JSONObject requested = new JSONObject(); - if (lastRun.tbrSetByPump != null && lastRun.tbrSetByPump.enacted) { // enacted - deviceStatus.enacted = lastRun.request.json(); - deviceStatus.enacted.put("rate", lastRun.tbrSetByPump.json(profile).get("rate")); - deviceStatus.enacted.put("duration", lastRun.tbrSetByPump.json(profile).get("duration")); + if (lastRun.getTbrSetByPump() != null && lastRun.getTbrSetByPump().enacted) { // enacted + deviceStatus.enacted = lastRun.getRequest().json(); + deviceStatus.enacted.put("rate", lastRun.getTbrSetByPump().json(profile).get("rate")); + deviceStatus.enacted.put("duration", lastRun.getTbrSetByPump().json(profile).get("duration")); deviceStatus.enacted.put("recieved", true); - requested.put("duration", lastRun.request.duration); - requested.put("rate", lastRun.request.rate); + requested.put("duration", lastRun.getRequest().duration); + requested.put("rate", lastRun.getRequest().rate); requested.put("temp", "absolute"); deviceStatus.enacted.put("requested", requested); } - if (lastRun.smbSetByPump != null && lastRun.smbSetByPump.enacted) { // enacted + if (lastRun.getTbrSetByPump() != null && lastRun.getTbrSetByPump().enacted) { // enacted if (deviceStatus.enacted == null) { - deviceStatus.enacted = lastRun.request.json(); + deviceStatus.enacted = lastRun.getRequest().json(); } - deviceStatus.enacted.put("smb", lastRun.smbSetByPump.bolusDelivered); - requested.put("smb", lastRun.request.smb); + deviceStatus.enacted.put("smb", lastRun.getTbrSetByPump().bolusDelivered); + requested.put("smb", lastRun.getRequest().smb); deviceStatus.enacted.put("requested", requested); } } else { if (L.isEnabled(LTag.NSCLIENT)) - log.debug("OpenAPS data too old to upload, sending iob only"); + aapsLogger.debug("OpenAPS data too old to upload, sending iob only"); IobTotal[] iob = iobCobCalculatorPlugin.calculateIobArrayInDia(profile); if (iob.length > 0) { deviceStatus.iob = iob[0].json(); @@ -219,13 +239,13 @@ public class NSUpload { deviceStatus.uploaderBattery = batteryLevel; deviceStatus.created_at = DateUtil.toISOString(new Date()); - UploadQueue.add(new DbRequest("dbAdd", "devicestatus", deviceStatus.mongoRecord())); + uploadQueue.add(new DbRequest("dbAdd", "devicestatus", deviceStatus.mongoRecord())); } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } - public static void uploadTreatmentRecord(DetailedBolusInfo detailedBolusInfo) { + public void uploadTreatmentRecord(DetailedBolusInfo detailedBolusInfo) { JSONObject data = new JSONObject(); try { data.put("eventType", detailedBolusInfo.eventType); @@ -248,21 +268,21 @@ public class NSUpload { data.put("notes", detailedBolusInfo.notes); } } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } uploadCareportalEntryToNS(data); } - public static void uploadProfileSwitch(ProfileSwitch profileSwitch) { + public void uploadProfileSwitch(ProfileSwitch profileSwitch) { try { JSONObject data = getJson(profileSwitch); uploadCareportalEntryToNS(data); } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } - public static void uploadTempTarget(TempTarget tempTarget, ProfileFunction profileFunction) { + public void uploadTempTarget(TempTarget tempTarget, ProfileFunction profileFunction) { try { JSONObject data = new JSONObject(); data.put("eventType", CareportalEvent.TEMPORARYTARGET); @@ -274,21 +294,21 @@ public class NSUpload { data.put("units", profileFunction.getUnits()); } data.put("created_at", DateUtil.toISOString(tempTarget.date)); - data.put("enteredBy", MainApp.gs(R.string.app_name)); + data.put("enteredBy", "AndroidAPS"); uploadCareportalEntryToNS(data); } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } - public static void updateProfileSwitch(ProfileSwitch profileSwitch) { + public void updateProfileSwitch(ProfileSwitch profileSwitch) { try { JSONObject data = getJson(profileSwitch); if (profileSwitch._id != null) { - UploadQueue.add(new DbRequest("dbUpdate", "treatments", profileSwitch._id, data)); + uploadQueue.add(new DbRequest("dbUpdate", "treatments", profileSwitch._id, data)); } } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } @@ -305,12 +325,12 @@ public class NSUpload { data.put("percentage", profileSwitch.percentage); } data.put("created_at", DateUtil.toISOString(profileSwitch.date)); - data.put("enteredBy", MainApp.gs(R.string.app_name)); + data.put("enteredBy", "AndroidAPS"); return data; } - public static void uploadCareportalEntryToNS(JSONObject data) { + public void uploadCareportalEntryToNS(JSONObject data) { try { if (data.has("preBolus") && data.has("carbs")) { JSONObject prebolus = new JSONObject(); @@ -325,48 +345,48 @@ public class NSUpload { uploadCareportalEntryToNS(prebolus); } DbRequest dbr = new DbRequest("dbAdd", "treatments", data); - log.debug("Prepared: " + dbr.log()); - UploadQueue.add(dbr); + aapsLogger.debug("Prepared: " + dbr.log()); + uploadQueue.add(dbr); } catch (Exception e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } - public static void removeCareportalEntryFromNS(String _id) { - UploadQueue.add(new DbRequest("dbRemove", "treatments", _id)); + public void removeCareportalEntryFromNS(String _id) { + uploadQueue.add(new DbRequest("dbRemove", "treatments", _id)); } - public static void uploadOpenAPSOffline(CareportalEvent event) { + public void uploadOpenAPSOffline(CareportalEvent event) { try { JSONObject data = new JSONObject(event.json); data.put("created_at", DateUtil.toISOString(event.date)); - data.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name)); - UploadQueue.add(new DbRequest("dbAdd", "treatments", data)); + data.put("enteredBy", "openaps://" + "AndroidAPS"); + uploadQueue.add(new DbRequest("dbAdd", "treatments", data)); } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } - public static void uploadError(String error) { + public void uploadError(String error) { uploadError(error, new Date()); } - public static void uploadError(String error, Date date) { + public void uploadError(String error, Date date) { JSONObject data = new JSONObject(); try { data.put("eventType", "Announcement"); data.put("created_at", DateUtil.toISOString(date)); - data.put("enteredBy", SP.getString("careportal_enteredby", MainApp.gs(R.string.app_name))); + data.put("enteredBy", sp.getString("careportal_enteredby", "AndroidAPS")); data.put("notes", error); data.put("isAnnouncement", true); } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } - UploadQueue.add(new DbRequest("dbAdd", "treatments", data)); + uploadQueue.add(new DbRequest("dbAdd", "treatments", data)); } - public static void uploadBg(BgReading reading, String source) { + public void uploadBg(BgReading reading, String source) { JSONObject data = new JSONObject(); try { data.put("device", source); @@ -376,56 +396,56 @@ public class NSUpload { data.put("direction", reading.direction); data.put("type", "sgv"); } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } - UploadQueue.add(new DbRequest("dbAdd", "entries", data)); + uploadQueue.add(new DbRequest("dbAdd", "entries", data)); } - public static void uploadAppStart() { - if (SP.getBoolean(R.string.key_ns_logappstartedevent, true)) { + public void uploadAppStart() { + if (sp.getBoolean(R.string.key_ns_logappstartedevent, true)) { JSONObject data = new JSONObject(); try { data.put("eventType", "Note"); data.put("created_at", DateUtil.toISOString(new Date())); - data.put("notes", MainApp.gs(R.string.androidaps_start) + " - " + Build.MANUFACTURER + " " + Build.MODEL); + data.put("notes", resourceHelper.gs(R.string.androidaps_start) + " - " + Build.MANUFACTURER + " " + Build.MODEL); } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } - UploadQueue.add(new DbRequest("dbAdd", "treatments", data)); + uploadQueue.add(new DbRequest("dbAdd", "treatments", data)); } } - public static void uploadProfileStore(JSONObject profileStore) { - if (SP.getBoolean(R.string.key_ns_uploadlocalprofile, false)) { - UploadQueue.add(new DbRequest("dbAdd", "profile", profileStore)); + public void uploadProfileStore(JSONObject profileStore) { + if (sp.getBoolean(R.string.key_ns_uploadlocalprofile, false)) { + uploadQueue.add(new DbRequest("dbAdd", "profile", profileStore)); } } - public static void uploadEvent(String careportalEvent, long time, @Nullable String notes) { + public void uploadEvent(String careportalEvent, long time, @Nullable String notes) { JSONObject data = new JSONObject(); try { data.put("eventType", careportalEvent); data.put("created_at", DateUtil.toISOString(time)); - data.put("enteredBy", SP.getString("careportal_enteredby", MainApp.gs(R.string.app_name))); + data.put("enteredBy", sp.getString("careportal_enteredby", "AndroidAPS")); if (notes != null) { data.put("notes", notes); } } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } - UploadQueue.add(new DbRequest("dbAdd", "treatments", data)); + uploadQueue.add(new DbRequest("dbAdd", "treatments", data)); } - public static void removeFoodFromNS(String _id) { + public void removeFoodFromNS(String _id) { try { - UploadQueue.add(new DbRequest("dbRemove", "food", _id)); + uploadQueue.add(new DbRequest("dbRemove", "food", _id)); } catch (Exception e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } - public static void sendToXdrip(BgReading bgReading) { + public void sendToXdrip(BgReading bgReading) { final String XDRIP_PLUS_NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR"; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US); @@ -450,22 +470,22 @@ public class NSUpload { bundle.putString("data", entriesBody.toString()); final Intent intent = new Intent(XDRIP_PLUS_NS_EMULATOR); intent.putExtras(bundle).addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - MainApp.instance().sendBroadcast(intent); - List receivers = MainApp.instance().getPackageManager().queryBroadcastReceivers(intent, 0); + context.sendBroadcast(intent); + List receivers = context.getPackageManager().queryBroadcastReceivers(intent, 0); if (receivers.size() < 1) { - log.debug("No xDrip receivers found. "); + aapsLogger.debug("No xDrip receivers found. "); } else { - log.debug(receivers.size() + " xDrip receivers"); + aapsLogger.debug(receivers.size() + " xDrip receivers"); } } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } } - public static void createNSTreatment(JSONObject data, ProfileStore profileStore, ProfileFunction profileFunction, long eventTime) { + public void createNSTreatment(JSONObject data, ProfileStore profileStore, ProfileFunction profileFunction, long eventTime) { if (JsonHelper.safeGetString(data, "eventType", "").equals(CareportalEvent.PROFILESWITCH)) { ProfileSwitch profileSwitch = profileFunction.prepareProfileSwitch( profileStore, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusProgressIfRunning.kt b/core/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusProgressIfRunning.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusProgressIfRunning.kt rename to core/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusProgressIfRunning.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.kt b/core/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.kt rename to core/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt rename to core/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt index 51a63f62bb..b74fc2ac00 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt @@ -2,9 +2,7 @@ package info.nightscout.androidaps.plugins.pump.common.bolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.logging.StacktraceLoggerWrapper import info.nightscout.androidaps.utils.T import java.util.* import javax.inject.Inject diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/NetworkChangeReceiver.kt b/core/src/main/java/info/nightscout/androidaps/receivers/NetworkChangeReceiver.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/receivers/NetworkChangeReceiver.kt rename to core/src/main/java/info/nightscout/androidaps/receivers/NetworkChangeReceiver.kt diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/ReceiverStatusStore.kt b/core/src/main/java/info/nightscout/androidaps/receivers/ReceiverStatusStore.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/receivers/ReceiverStatusStore.kt rename to core/src/main/java/info/nightscout/androidaps/receivers/ReceiverStatusStore.kt diff --git a/app/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.kt b/core/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.kt similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.kt rename to core/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.kt index 0d261b5071..140cfda5b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.kt +++ b/core/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.kt @@ -6,17 +6,17 @@ import android.media.AudioManager import android.media.MediaPlayer import android.os.IBinder import dagger.android.DaggerService -import info.nightscout.androidaps.R +import info.nightscout.androidaps.core.R +import info.nightscout.androidaps.interfaces.NotificationHolderInterface import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.utils.androidNotification.NotificationHolder import info.nightscout.androidaps.utils.resources.ResourceHelper import javax.inject.Inject class AlarmSoundService : DaggerService() { @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var resourceHelper: ResourceHelper - @Inject lateinit var notificationHolder: NotificationHolder + @Inject lateinit var notificationHolder: NotificationHolderInterface private var player: MediaPlayer? = null private var resourceId = R.raw.error diff --git a/app/src/main/java/info/nightscout/androidaps/utils/StringUtils.java b/core/src/main/java/info/nightscout/androidaps/utils/StringUtils.java similarity index 86% rename from app/src/main/java/info/nightscout/androidaps/utils/StringUtils.java rename to core/src/main/java/info/nightscout/androidaps/utils/StringUtils.java index ebd31dea17..01b92a680f 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/StringUtils.java +++ b/core/src/main/java/info/nightscout/androidaps/utils/StringUtils.java @@ -1,8 +1,5 @@ package info.nightscout.androidaps.utils; -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; - /** * class contains useful String functions */ diff --git a/app/src/main/java/info/nightscout/androidaps/utils/extensions/HexByteArrayConversion.kt b/core/src/main/java/info/nightscout/androidaps/utils/extensions/HexByteArrayConversion.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/extensions/HexByteArrayConversion.kt rename to core/src/main/java/info/nightscout/androidaps/utils/extensions/HexByteArrayConversion.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/DefaultEditTextValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/DefaultEditTextValidator.kt similarity index 99% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/DefaultEditTextValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/DefaultEditTextValidator.kt index 21146a9a72..2956a8d2b8 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/DefaultEditTextValidator.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/DefaultEditTextValidator.kt @@ -7,7 +7,7 @@ import android.text.TextUtils import android.text.TextWatcher import android.widget.EditText import com.google.android.material.textfield.TextInputLayout -import info.nightscout.androidaps.R +import info.nightscout.androidaps.core.R import info.nightscout.androidaps.utils.textValidator.validators.* class DefaultEditTextValidator : EditTextValidator { diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/EditTextValidator.java b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/EditTextValidator.java similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/EditTextValidator.java rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/EditTextValidator.java diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/ValidatingEditTextPreference.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/ValidatingEditTextPreference.kt similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/ValidatingEditTextPreference.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/ValidatingEditTextPreference.kt index 6130d7acf6..ae75641b4c 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/ValidatingEditTextPreference.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/ValidatingEditTextPreference.kt @@ -6,7 +6,7 @@ import android.util.AttributeSet import androidx.preference.EditTextPreference import androidx.preference.EditTextPreference.OnBindEditTextListener import androidx.preference.PreferenceViewHolder -import info.nightscout.androidaps.R +import info.nightscout.androidaps.core.R class ValidatingEditTextPreference(ctx: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : EditTextPreference(ctx, attrs, defStyleAttr, defStyleRes) { diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/AlphaNumericValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/AlphaNumericValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/AlphaNumericValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/AlphaNumericValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/AlphaValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/AlphaValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/AlphaValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/AlphaValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/AndValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/AndValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/AndValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/AndValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/CreditCardValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/CreditCardValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/CreditCardValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/CreditCardValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DateValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DateValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DateValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DateValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DigitLengthRangeValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DigitLengthRangeValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DigitLengthRangeValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DigitLengthRangeValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DomainValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DomainValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DomainValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DomainValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DummyValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DummyValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DummyValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/DummyValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/EmailValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/EmailValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/EmailValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/EmailValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/EmptyValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/EmptyValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/EmptyValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/EmptyValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/FloatNumericRangeValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/FloatNumericRangeValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/FloatNumericRangeValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/FloatNumericRangeValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/HttpsUrlValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/HttpsUrlValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/HttpsUrlValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/HttpsUrlValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/IpAddressValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/IpAddressValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/IpAddressValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/IpAddressValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/MinDigitLengthValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/MinDigitLengthValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/MinDigitLengthValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/MinDigitLengthValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/MultiPhoneValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/MultiPhoneValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/MultiPhoneValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/MultiPhoneValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/MultiValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/MultiValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/MultiValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/MultiValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/NotValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/NotValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/NotValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/NotValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/NumericRangeValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/NumericRangeValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/NumericRangeValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/NumericRangeValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/NumericValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/NumericValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/NumericValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/NumericValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/OrValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/OrValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/OrValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/OrValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PatternValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PatternValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PatternValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PatternValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PersonFullNameValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PersonFullNameValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PersonFullNameValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PersonFullNameValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PersonNameValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PersonNameValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PersonNameValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PersonNameValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PhoneValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PhoneValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PhoneValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PhoneValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PinStrengthValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PinStrengthValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PinStrengthValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/PinStrengthValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/RegexpValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/RegexpValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/RegexpValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/RegexpValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/SameValueValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/SameValueValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/SameValueValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/SameValueValidator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/Validator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/Validator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/Validator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/Validator.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/WebUrlValidator.kt b/core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/WebUrlValidator.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/WebUrlValidator.kt rename to core/src/main/java/info/nightscout/androidaps/utils/textValidator/validators/WebUrlValidator.kt diff --git a/app/src/main/res/layout/dialog_bolusprogress.xml b/core/src/main/res/layout/dialog_bolusprogress.xml similarity index 100% rename from app/src/main/res/layout/dialog_bolusprogress.xml rename to core/src/main/res/layout/dialog_bolusprogress.xml diff --git a/app/src/main/res/layout/dialog_error.xml b/core/src/main/res/layout/dialog_error.xml similarity index 100% rename from app/src/main/res/layout/dialog_error.xml rename to core/src/main/res/layout/dialog_error.xml diff --git a/app/src/main/res/layout/okcancel.xml b/core/src/main/res/layout/okcancel.xml similarity index 100% rename from app/src/main/res/layout/okcancel.xml rename to core/src/main/res/layout/okcancel.xml diff --git a/app/src/main/res/raw/error.mp3 b/core/src/main/res/raw/error.mp3 similarity index 100% rename from app/src/main/res/raw/error.mp3 rename to core/src/main/res/raw/error.mp3 diff --git a/app/src/main/res/values/fet_attrs.xml b/core/src/main/res/values/fet_attrs.xml similarity index 100% rename from app/src/main/res/values/fet_attrs.xml rename to core/src/main/res/values/fet_attrs.xml diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index b69a63c11c..2842da7183 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -17,6 +17,34 @@ hypo_target low_mark high_mark + ns_create_announcements_from_errors + ns_logappstartedevent + ns_uploadlocalprofile + + + Error + Not set + Failed to update basal profile + Basal profile in pump updated + Invalid input data + Tempbasal delivery error + Going to deliver %1$.2fU + Waiting for pump + Connecting for %1$d s + Handshaking + Connecting + Connected + Disconnected + Disconnecting + AndroidAPS started + + + Limiting max basal rate to %1$.2f U/h because of %2$s + pump limit + Limiting max percent rate to %1$d%% because of %2$s + it must be positive value + Limiting bolus to %1$.1f U because of %2$s + Pump not initialized, profile not set! Confirmation diff --git a/app/src/main/res/values/validator.xml b/core/src/main/res/values/validator.xml similarity index 100% rename from app/src/main/res/values/validator.xml rename to core/src/main/res/values/validator.xml diff --git a/danars/build.gradle b/danars/build.gradle index 96753367b4..a80ef58dfb 100644 --- a/danars/build.gradle +++ b/danars/build.gradle @@ -50,9 +50,12 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.core:core-ktx:1.2.0' + implementation "androidx.preference:preference-ktx:1.1.1" implementation "androidx.activity:activity:${activityVersion}" implementation "androidx.activity:activity-ktx:${activityVersion}" + // Graphview cannot be upgraded + implementation "com.jjoe64:graphview:4.0.1" implementation "com.google.dagger:dagger-android:$dagger_version" implementation "com.google.dagger:dagger-android-support:$dagger_version" diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/RecordTypes.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/RecordTypes.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/RecordTypes.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/RecordTypes.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt index 8eb3b26d4e..2cf3e44656 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt +++ b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.kt @@ -8,8 +8,7 @@ import android.os.IBinder import android.text.format.DateFormat import androidx.preference.Preference import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.BuildConfig -import info.nightscout.androidaps.R +import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.PumpEnactResult @@ -34,7 +33,6 @@ import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSDeviceChange import info.nightscout.androidaps.plugins.pump.danaRS.services.DanaRSService -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.* import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -56,13 +54,14 @@ class DanaRSPlugin @Inject constructor( resourceHelper: ResourceHelper, private val constraintChecker: ConstraintChecker, private val profileFunction: ProfileFunction, - private val treatmentsPlugin: TreatmentsPlugin, + private val activePluginProvider: ActivePluginProvider, private val sp: SP, commandQueue: CommandQueueProvider, private val danaRPump: DanaRPump, private val detailedBolusInfoStorage: DetailedBolusInfoStorage, private val fabricPrivacy: FabricPrivacy, - private val dateUtil: DateUtil + private val dateUtil: DateUtil, + private val config: ConfigInterface ) : PumpPluginBase(PluginDescription() .mainType(PluginType.PUMP) .fragmentClass(DanaRFragment::class.java.name) @@ -85,7 +84,7 @@ class DanaRSPlugin @Inject constructor( if (pref.key == resourceHelper.gs(R.string.key_danars_name)) { val value = sp.getStringOrNull(R.string.key_danars_name, null) pref.summary = value - ?: resourceHelper.gs(R.string.rileylink_error_address_not_set_short) + ?: resourceHelper.gs(R.string.not_set_short) } } @@ -320,7 +319,7 @@ class DanaRSPlugin @Inject constructor( 0x80 -> error = resourceHelper.gs(R.string.insulinlimitviolation) } result.comment = String.format(resourceHelper.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, error) - } else result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + } else result.comment = resourceHelper.gs(R.string.ok) aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered) result } else { @@ -328,7 +327,7 @@ class DanaRSPlugin @Inject constructor( result.success = false result.bolusDelivered = 0.0 result.carbsDelivered = 0.0 - result.comment = resourceHelper.gs(R.string.danar_invalidinput) + result.comment = resourceHelper.gs(R.string.invalidinput) aapsLogger.error("deliverTreatment: Invalid input") result } @@ -348,7 +347,7 @@ class DanaRSPlugin @Inject constructor( val doHighTemp = absoluteAfterConstrain > baseBasalRate if (doTempOff) { // If temp in progress - if (treatmentsPlugin.isTempBasalInProgress) { + if (activePluginProvider.activeTreatments.isTempBasalInProgress) { aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Stopping temp basal (doTempOff)") return cancelTempBasal(false) } @@ -366,7 +365,7 @@ class DanaRSPlugin @Inject constructor( if (percentRate > 500) // Special high temp 500/15min percentRate = 500 // Check if some temp is already in progress - val activeTemp = treatmentsPlugin.getTempBasalFromHistory(System.currentTimeMillis()) + val activeTemp = activePluginProvider.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis()) if (activeTemp != null) { aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: currently running: $activeTemp") // Correct basal already set ? @@ -413,18 +412,18 @@ class DanaRSPlugin @Inject constructor( result.isTempCancel = false result.enacted = false result.success = false - result.comment = resourceHelper.gs(R.string.danar_invalidinput) + result.comment = resourceHelper.gs(R.string.invalidinput) aapsLogger.error("setTempBasalPercent: Invalid input") return result } if (percentAfterConstraint > pumpDescription.maxTempPercent) percentAfterConstraint = pumpDescription.maxTempPercent val now = System.currentTimeMillis() - val activeTemp = treatmentsPlugin.getTempBasalFromHistory(now) + val activeTemp = activePluginProvider.activeTreatments.getTempBasalFromHistory(now) if (activeTemp != null && activeTemp.percentRate == percentAfterConstraint && activeTemp.plannedRemainingMinutes > 4 && !enforceNew) { result.enacted = false result.success = true result.isTempCancel = false - result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + result.comment = resourceHelper.gs(R.string.ok) result.duration = danaRPump.tempBasalRemainingMin result.percent = danaRPump.tempBasalPercent result.isPercent = true @@ -442,7 +441,7 @@ class DanaRSPlugin @Inject constructor( if (connectionOK && danaRPump.isTempBasalInProgress && danaRPump.tempBasalPercent == percentAfterConstraint) { result.enacted = true result.success = true - result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + result.comment = resourceHelper.gs(R.string.ok) result.isTempCancel = false result.duration = danaRPump.tempBasalRemainingMin result.percent = danaRPump.tempBasalPercent @@ -463,7 +462,7 @@ class DanaRSPlugin @Inject constructor( if (connectionOK && danaRPump.isTempBasalInProgress && danaRPump.tempBasalPercent == percent) { result.enacted = true result.success = true - result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + result.comment = resourceHelper.gs(R.string.ok) result.isTempCancel = false result.duration = danaRPump.tempBasalRemainingMin result.percent = danaRPump.tempBasalPercent @@ -485,11 +484,11 @@ class DanaRSPlugin @Inject constructor( val durationInHalfHours = max(durationInMinutes / 30, 1) insulinAfterConstraint = Round.roundTo(insulinAfterConstraint, pumpDescription.extendedBolusStep) val result = PumpEnactResult(injector) - val runningEB = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis()) + val runningEB = activePluginProvider.activeTreatments.getExtendedBolusFromHistory(System.currentTimeMillis()) if (runningEB != null && abs(runningEB.insulin - insulinAfterConstraint) < pumpDescription.extendedBolusStep) { result.enacted = false result.success = true - result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + result.comment = resourceHelper.gs(R.string.ok) result.duration = danaRPump.extendedBolusRemainingMinutes result.absolute = danaRPump.extendedBolusAbsoluteRate result.isPercent = false @@ -502,7 +501,7 @@ class DanaRSPlugin @Inject constructor( if (connectionOK && danaRPump.isExtendedInProgress && abs(danaRPump.extendedBolusAbsoluteRate - insulinAfterConstraint) < pumpDescription.extendedBolusStep) { result.enacted = true result.success = true - result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + result.comment = resourceHelper.gs(R.string.ok) result.isTempCancel = false result.duration = danaRPump.extendedBolusRemainingMinutes result.absolute = danaRPump.extendedBolusAbsoluteRate @@ -521,7 +520,7 @@ class DanaRSPlugin @Inject constructor( @Synchronized override fun cancelTempBasal(force: Boolean): PumpEnactResult { val result = PumpEnactResult(injector) - val runningTB = treatmentsPlugin.getTempBasalFromHistory(System.currentTimeMillis()) + val runningTB = activePluginProvider.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis()) if (runningTB != null) { danaRSService?.tempBasalStop() result.enacted = true @@ -530,7 +529,7 @@ class DanaRSPlugin @Inject constructor( return if (!danaRPump.isTempBasalInProgress) { result.success = true result.isTempCancel = true - result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + result.comment = resourceHelper.gs(R.string.ok) aapsLogger.debug(LTag.PUMP, "cancelRealTempBasal: OK") result } else { @@ -544,7 +543,7 @@ class DanaRSPlugin @Inject constructor( @Synchronized override fun cancelExtendedBolus(): PumpEnactResult { val result = PumpEnactResult(injector) - val runningEB = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis()) + val runningEB = activePluginProvider.activeTreatments.getExtendedBolusFromHistory(System.currentTimeMillis()) if (runningEB != null) { danaRSService?.extendedBolusStop() result.enacted = true @@ -552,7 +551,7 @@ class DanaRSPlugin @Inject constructor( } return if (!danaRPump.isExtendedInProgress) { result.success = true - result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + result.comment = resourceHelper.gs(R.string.ok) aapsLogger.debug(LTag.PUMP, "cancelExtendedBolus: OK") result } else { @@ -581,13 +580,13 @@ class DanaRSPlugin @Inject constructor( extended.put("LastBolus", dateUtil.dateAndTimeString(danaRPump.lastBolusTime)) extended.put("LastBolusAmount", danaRPump.lastBolusAmount) } - val tb = treatmentsPlugin.getTempBasalFromHistory(now) + val tb = activePluginProvider.activeTreatments.getTempBasalFromHistory(now) if (tb != null) { extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile)) extended.put("TempBasalStart", dateUtil.dateAndTimeString(tb.date)) extended.put("TempBasalRemaining", tb.plannedRemainingMinutes) } - val eb = treatmentsPlugin.getExtendedBolusFromHistory(now) + val eb = activePluginProvider.activeTreatments.getExtendedBolusFromHistory(now) if (eb != null) { extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()) extended.put("ExtendedBolusStart", dateUtil.dateAndTimeString(eb.date)) @@ -636,11 +635,11 @@ class DanaRSPlugin @Inject constructor( if (danaRPump.lastBolusTime != 0L) ret += "LastBolus: ${DecimalFormatter.to2Decimal(danaRPump.lastBolusAmount)}U @${DateFormat.format("HH:mm", danaRPump.lastBolusTime)}" - val activeTemp = treatmentsPlugin.getRealTempBasalFromHistory(System.currentTimeMillis()) + val activeTemp = activePluginProvider.activeTreatments.getRealTempBasalFromHistory(System.currentTimeMillis()) if (activeTemp != null) ret += "Temp: ${activeTemp.toStringFull()}" - val activeExtendedBolus = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis()) + val activeExtendedBolus = activePluginProvider.activeTreatments.getExtendedBolusFromHistory(System.currentTimeMillis()) if (activeExtendedBolus != null) ret += "Extended: $activeExtendedBolus\n" diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/EnterPinActivity.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/EnterPinActivity.kt similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/EnterPinActivity.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/EnterPinActivity.kt index 13eebbaa0e..2c25053da2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/EnterPinActivity.kt +++ b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/EnterPinActivity.kt @@ -2,8 +2,8 @@ package info.nightscout.androidaps.plugins.pump.danaRS.activities import android.os.Bundle import android.util.Base64 -import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.NoSplashAppCompatActivity +import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin @@ -56,7 +56,7 @@ class EnterPinActivity : NoSplashAppCompatActivity() { bleComm.finishV3Pairing() finish() } - else OKDialog.show(this, resourceHelper.gs(R.string.error), resourceHelper.gs(R.string.danar_invalidinput)) + else OKDialog.show(this, resourceHelper.gs(R.string.error), resourceHelper.gs(R.string.invalidinput)) } } cancel.setOnClickListener { finish() } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt index 676290cbba..3427c46b2a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt +++ b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R +import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.db.CareportalEvent import info.nightscout.androidaps.db.ExtendedBolus @@ -195,7 +195,7 @@ open class DanaRS_Packet_APS_History_Events( status = "PRIMECANNULA " + dateUtil.timeString(datetime) } - else -> { + else -> { aapsLogger.debug(LTag.PUMPCOMM, "Event: " + recordCode + " " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Param1: " + param1 + " Param2: " + param2) status = "UNKNOWN " + dateUtil.timeString(datetime) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.kt similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.kt index b25bc2c587..76dde13995 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.kt +++ b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R +import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.kt similarity index 99% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.kt index 432f0792dd..252ce8761a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.kt +++ b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.kt @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R +import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Version.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Version.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Version.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Version.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Get_Pump_Dec_Ratio.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/encryption/BleEncryption.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt similarity index 99% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt rename to danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt index c40eda80fb..43dc6eb34e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt +++ b/danars/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.kt @@ -9,7 +9,6 @@ import android.os.SystemClock import dagger.android.DaggerService import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Constants -import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.PumpEnactResult diff --git a/app/src/main/jniLibs/arm64-v8a/libBleEncryption.so b/danars/src/main/jniLibs/arm64-v8a/libBleEncryption.so similarity index 100% rename from app/src/main/jniLibs/arm64-v8a/libBleEncryption.so rename to danars/src/main/jniLibs/arm64-v8a/libBleEncryption.so diff --git a/app/src/main/jniLibs/armeabi-v7a/libBleEncryption.so b/danars/src/main/jniLibs/armeabi-v7a/libBleEncryption.so similarity index 100% rename from app/src/main/jniLibs/armeabi-v7a/libBleEncryption.so rename to danars/src/main/jniLibs/armeabi-v7a/libBleEncryption.so diff --git a/app/src/main/jniLibs/x86/libBleEncryption.so b/danars/src/main/jniLibs/x86/libBleEncryption.so similarity index 100% rename from app/src/main/jniLibs/x86/libBleEncryption.so rename to danars/src/main/jniLibs/x86/libBleEncryption.so diff --git a/app/src/main/jniLibs/x86_64/libBleEncryption.so b/danars/src/main/jniLibs/x86_64/libBleEncryption.so similarity index 100% rename from app/src/main/jniLibs/x86_64/libBleEncryption.so rename to danars/src/main/jniLibs/x86_64/libBleEncryption.so diff --git a/app/src/main/res/layout/danars_enter_pin_activity.xml b/danars/src/main/res/layout/danars_enter_pin_activity.xml similarity index 100% rename from app/src/main/res/layout/danars_enter_pin_activity.xml rename to danars/src/main/res/layout/danars_enter_pin_activity.xml diff --git a/danars/src/main/res/values/strings.xml b/danars/src/main/res/values/strings.xml index 5cef8b70b6..73b38830ee 100644 --- a/danars/src/main/res/values/strings.xml +++ b/danars/src/main/res/values/strings.xml @@ -4,13 +4,28 @@ danars_name danar_password danars_password + danars_bolusspeed + danars_pairing_key_ + danars_v3_randompairing_key_ + danars_v3_pairing_key_ + danars_v3_randomsync_key_ + rs_logcanulachange + rs_loginsulinchange Pairing No device found so far Pairing OK Pairing timed out Waiting for pairing on pump - OK - Cancel + DanaRS + Dana + Pump integration for DANA Diabecare RS pumps + Max bolus violation + Command error + Speed error + Insulin limit violation + Asked: %1$.2fU Delivered: %2$.2fU Error code: %3$s + Value not set properly + Set basal step to 0.01 U/h diff --git a/app/src/main/res/xml/pref_danars.xml b/danars/src/main/res/xml/pref_danars.xml similarity index 100% rename from app/src/main/res/xml/pref_danars.xml rename to danars/src/main/res/xml/pref_danars.xml From 7fc631a7296f6d9baa6ecafa17659a3b76e4e1b8 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 9 May 2020 10:52:20 +0200 Subject: [PATCH 26/53] RS -> danaRS finished --- .../info/nightscout/androidaps/MainApp.java | 10 +- .../androidaps/db/DatabaseHelper.java | 4 +- .../androidaps/db/DatabaseHelperProvider.java | 68 +++++++++++++ .../dependencyInjection/AppModule.kt | 8 +- .../dependencyInjection/FragmentsModule.kt | 2 +- .../androidaps/dialogs/CarbsDialog.kt | 3 +- .../androidaps/dialogs/CareDialog.kt | 3 +- .../androidaps/dialogs/FillDialog.kt | 31 +----- .../plugins/aps/loop/LoopPlugin.java | 7 +- .../objectives/ObjectivesFragment.kt | 4 +- .../automation/actions/ActionNotification.kt | 3 +- .../Dialogs/NewNSTreatmentDialog.java | 3 +- .../plugins/general/food/FoodFragment.kt | 3 +- .../general/nsclient/NSClientFragment.java | 7 +- .../general/nsclient/NSClientPlugin.java | 4 - .../plugins/general/nsclient/UploadQueue.java | 87 ++++++++++------- .../nsclient/services/NSClientService.java | 62 ++++++------ .../general/overview/OverviewFragment.kt | 8 +- .../general/overview/graphData/GraphData.kt | 4 +- .../plugins/general/wear/WearPlugin.kt | 2 +- .../wearintegration/WatchUpdaterService.java | 8 +- .../profile/local/LocalProfilePlugin.kt | 5 +- .../plugins/pump/combo/ComboPlugin.java | 4 +- .../pump/common/PumpPluginAbstract.java | 4 +- .../pump/danaR/AbstractDanaRPlugin.java | 4 +- .../pump/danaR/comm/MessageHashTableR.kt | 4 +- .../plugins/pump/danaR/comm/MsgError.kt | 5 +- .../plugins/pump/danaR/comm/MsgHistoryAll.kt | 2 +- .../danaR/services/DanaRExecutionService.java | 3 +- .../comm/MessageHashTableRKorean.kt | 4 +- .../services/DanaRKoreanExecutionService.java | 3 +- .../pump/danaRv2/comm/MessageHashTableRv2.kt | 4 +- .../services/DanaRv2ExecutionService.java | 3 +- .../pump/insight/LocalInsightPlugin.java | 27 ++--- .../plugins/pump/mdi/MDIPlugin.java | 4 +- .../medtronic/data/MedtronicHistoryData.java | 5 +- .../wizard/pages/InitPodRefreshAction.java | 3 +- .../plugins/pump/virtual/VirtualPumpPlugin.kt | 4 +- .../androidaps/plugins/source/DexcomPlugin.kt | 11 ++- .../plugins/source/EversensePlugin.kt | 9 +- .../plugins/source/PoctechPlugin.kt | 7 +- .../androidaps/plugins/source/TomatoPlugin.kt | 7 +- .../fragments/TreatmentsBolusFragment.kt | 10 +- .../fragments/TreatmentsCareportalFragment.kt | 10 +- .../TreatmentsExtendedBolusesFragment.kt | 6 +- .../TreatmentsProfileSwitchFragment.kt | 6 +- .../TreatmentsTempTargetFragment.java | 6 +- .../TreatmentsTemporaryBasalsFragment.kt | 6 +- .../androidaps/receivers/KeepAliveReceiver.kt | 6 +- .../androidaps/services/DataService.java | 4 +- .../nightscout/androidaps/utils/HardLimits.kt | 13 +-- .../androidaps/utils/LocalAlertUtils.kt | 5 +- .../androidaps/utils/stats/TddCalculator.kt | 4 +- app/src/main/res/layout/okcancel.xml | 44 +++++++++ app/src/main/res/values/colors.xml | 2 - app/src/main/res/values/strings.xml | 92 +----------------- .../activities/TDDStatsActivity.java | 27 ++--- .../androidaps}/dialogs/NtpProgressDialog.kt | 6 +- .../androidaps/dialogs/ProfileViewerDialog.kt | 12 +-- .../events/EventDanaRSyncStatus.kt | 2 +- .../events/EventExtendedBolusChange.kt | 0 .../nightscout/androidaps/events/EventLoop.kt | 0 .../androidaps}/events/EventNtpStatus.kt | 2 +- .../androidaps/events/EventTempBasalChange.kt | 0 .../interfaces/DatabaseHelperInterface.kt | 18 +++- .../androidaps/interfaces/PumpInterface.java | 2 +- .../plugins/general/nsclient/NSUpload.java | 41 +++++++- .../treatments/fragments/ProfileGraph.kt | 0 .../queue/events/EventQueueChanged.kt | 0 .../utils/DigitsKeyListenerWithComma.java | 0 .../androidaps/utils/NumberPicker.java | 2 +- .../nightscout/androidaps/utils/WarnColors.kt | 2 +- .../CompositeDisposablePlusAssign.kt | 0 .../utils/extensions/Concurrency.kt | 0 core/src/main/res/layout/close.xml | 19 ++++ .../main/res/layout/danar_statsactivity.xml | 0 .../main/res/layout/dialog_profileviewer.xml | 0 .../main/res/layout/number_picker_layout.xml | 0 .../src/main/res/layout/spinner_centered.xml | 0 {app => core}/src/main/res/raw/boluserror.mp3 | Bin core/src/main/res/values/colors.xml | 4 + core/src/main/res/values/strings.xml | 32 ++++++ danars/build.gradle | 6 ++ .../plugins/pump/danaR/DanaRFragment.kt | 8 +- .../danaR/activities/DanaRHistoryActivity.kt | 34 +++---- .../activities/DanaRUserOptionsActivity.kt | 27 +++-- .../plugins/pump/danaRS/DanaRSPlugin.kt | 4 +- .../pump/danaRS/comm/DanaRS_Packet.java | 13 +-- .../comm/DanaRS_Packet_APS_History_Events.kt | 7 +- .../DanaRS_Packet_Bolus_Get_Bolus_Option.kt | 1 - ...DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.kt | 2 +- .../DanaRS_Packet_General_Get_Pump_Check.kt | 2 +- .../danaRS/comm/DanaRS_Packet_History_.kt | 7 +- .../danaRS/comm/DanaRS_Packet_Notify_Alarm.kt | 5 +- .../DanaRS_Packet_Notify_Delivery_Complete.kt | 2 +- ...aRS_Packet_Notify_Delivery_Rate_Display.kt | 2 +- .../plugins/pump/danaRS/services/BLEComm.kt | 7 +- .../pump/danaRS/services/DanaRSService.kt | 4 +- .../src/main/res/layout/danar_fragment.xml | 0 .../main/res/layout/danar_history_item.xml | 0 .../main/res/layout/danar_historyactivity.xml | 0 .../layout/danar_user_options_activity.xml | 0 danars/src/main/res/layout/okcancel.xml | 44 +++++++++ danars/src/main/res/values/strings.xml | 62 ++++++++++++ 104 files changed, 666 insertions(+), 407 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java create mode 100644 app/src/main/res/layout/okcancel.xml rename {app => core}/src/main/java/info/nightscout/androidaps/activities/TDDStatsActivity.java (94%) rename {app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives => core/src/main/java/info/nightscout/androidaps}/dialogs/NtpProgressDialog.kt (94%) rename {app => core}/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt (89%) rename {app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR => core/src/main/java/info/nightscout/androidaps}/events/EventDanaRSyncStatus.kt (63%) rename {app => core}/src/main/java/info/nightscout/androidaps/events/EventExtendedBolusChange.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/events/EventLoop.kt (100%) rename {app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives => core/src/main/java/info/nightscout/androidaps}/events/EventNtpStatus.kt (61%) rename {app => core}/src/main/java/info/nightscout/androidaps/events/EventTempBasalChange.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileGraph.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/queue/events/EventQueueChanged.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/DigitsKeyListenerWithComma.java (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/NumberPicker.java (99%) rename app/src/main/java/info/nightscout/androidaps/utils/SetWarnColor.kt => core/src/main/java/info/nightscout/androidaps/utils/WarnColors.kt (97%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/extensions/CompositeDisposablePlusAssign.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/extensions/Concurrency.kt (100%) create mode 100644 core/src/main/res/layout/close.xml rename {app => core}/src/main/res/layout/danar_statsactivity.xml (100%) rename {app => core}/src/main/res/layout/dialog_profileviewer.xml (100%) rename {app => core}/src/main/res/layout/number_picker_layout.xml (100%) rename {app => core}/src/main/res/layout/spinner_centered.xml (100%) rename {app => core}/src/main/res/raw/boluserror.mp3 (100%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt (84%) rename {app => danars}/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.kt (88%) rename {app => danars}/src/main/res/layout/danar_fragment.xml (100%) rename {app => danars}/src/main/res/layout/danar_history_item.xml (100%) rename {app => danars}/src/main/res/layout/danar_historyactivity.xml (100%) rename {app => danars}/src/main/res/layout/danar_user_options_activity.xml (100%) create mode 100644 danars/src/main/res/layout/okcancel.xml diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 85d8f83ed7..27d60be03c 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -23,6 +23,7 @@ import javax.inject.Inject; import dagger.android.AndroidInjector; import dagger.android.DaggerApplication; import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.StaticInjector; import info.nightscout.androidaps.dependencyInjection.DaggerAppComponent; @@ -45,7 +46,7 @@ import info.nightscout.androidaps.utils.ActivityMonitor; import info.nightscout.androidaps.utils.LocaleHelper; import info.nightscout.androidaps.utils.sharedPreferences.SP; -public class MainApp extends DaggerApplication implements DatabaseHelperInterface { +public class MainApp extends DaggerApplication { static MainApp sInstance; private static Resources sResources; @@ -57,6 +58,7 @@ public class MainApp extends DaggerApplication implements DatabaseHelperInterfac @Inject ActivityMonitor activityMonitor; @Inject VersionCheckerUtils versionCheckersUtils; @Inject SP sp; + @Inject NSUpload nsUpload; @Inject ConfigBuilderPlugin configBuilderPlugin; @Inject KeepAliveReceiver.KeepAliveManager keepAliveManager; @@ -99,7 +101,7 @@ public class MainApp extends DaggerApplication implements DatabaseHelperInterfac pluginStore.setPlugins(plugins); configBuilderPlugin.initialize(); - NSUpload.uploadAppStart(); + nsUpload.uploadAppStart(); new Thread(() -> keepAliveManager.setAlarm(this)).start(); doMigrations(); @@ -173,8 +175,4 @@ public class MainApp extends DaggerApplication implements DatabaseHelperInterfac keepAliveManager.cancelAlarm(this); super.onTerminate(); } - - @NotNull @Override public List getAllBgreadingsDataFromTime(long mills, boolean ascending) { - return getDbHelper().getAllBgreadingsDataFromTime(mills, ascending); - } } diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index abc6df92c9..b5e5c89819 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -1733,7 +1733,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } */ - public void createProfileSwitchFromJsonIfNotExists(ActivePluginProvider activePluginProvider, JSONObject trJson) { + public void createProfileSwitchFromJsonIfNotExists(ActivePluginProvider activePluginProvider, NSUpload nsUpload, JSONObject trJson) { try { ProfileSwitch profileSwitch = new ProfileSwitch(MainApp.instance()); profileSwitch.date = trJson.getLong("mills"); @@ -1759,7 +1759,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { if (L.isEnabled(LTag.DATABASE)) log.debug("Profile switch prefilled with JSON from local store"); // Update data in NS - NSUpload.updateProfileSwitch(profileSwitch); + nsUpload.updateProfileSwitch(profileSwitch); } else { if (L.isEnabled(LTag.DATABASE)) log.debug("JSON for profile switch doesn't exist. Ignoring: " + trJson.toString()); diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java new file mode 100644 index 0000000000..60c7578b74 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java @@ -0,0 +1,68 @@ +package info.nightscout.androidaps.db; + +import com.j256.ormlite.dao.CloseableIterator; + +import org.jetbrains.annotations.NotNull; + +import java.sql.SQLException; +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.interfaces.DatabaseHelperInterface; + +@Singleton +public class DatabaseHelperProvider implements DatabaseHelperInterface { + + @Inject DatabaseHelperProvider() {} + + @NotNull @Override public List getAllBgreadingsDataFromTime(long mills, boolean ascending) { + return MainApp.getDbHelper().getAllBgreadingsDataFromTime(mills, ascending); + } + + @Override public void createOrUpdate(@NotNull CareportalEvent careportalEvent) { + MainApp.getDbHelper().createOrUpdate(careportalEvent); + } + + @Override public void createOrUpdate(@NotNull DanaRHistoryRecord record) { + MainApp.getDbHelper().createOrUpdate(record); + } + + @NotNull @Override public List getDanaRHistoryRecordsByType(byte type) { + return MainApp.getDbHelper().getDanaRHistoryRecordsByType(type); + } + + @NotNull @Override public List getTDDs() { + return MainApp.getDbHelper().getTDDs(); + } + + @Override public long size(@NotNull String table) { + return MainApp.getDbHelper().size(table); + } + + @Override public void create(@NotNull DbRequest record) { + try { + MainApp.getDbHelper().create(record); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Override public void deleteAllDbRequests() { + MainApp.getDbHelper().deleteAllDbRequests(); + } + + @Override public int deleteDbRequest(@NotNull String id) { + return MainApp.getDbHelper().deleteDbRequest(id); + } + + @Override public void deleteDbRequestbyMongoId(@NotNull String action, @NotNull String _id) { + MainApp.getDbHelper().deleteDbRequestbyMongoId(action, _id); + } + + @NotNull @Override public CloseableIterator getDbRequestInterator() { + return MainApp.getDbHelper().getDbRequestInterator(); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index e405ab91fd..16543e8a86 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -8,13 +8,16 @@ import dagger.Provides import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Config import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.db.DatabaseHelperProvider import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.configBuilder.PluginStore import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation +import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.queue.CommandQueue import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.androidNotification.NotificationHolder import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.storage.FileStorage @@ -61,11 +64,12 @@ open class AppModule { @Binds fun bindContext(mainApp: MainApp): Context @Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector - @Binds fun bindDatabaseHelperInterface(mainApp: MainApp): DatabaseHelperInterface @Binds fun bindActivePluginProvider(pluginStore: PluginStore): ActivePluginProvider @Binds fun commandQueueProvider(commandQueue: CommandQueue): CommandQueueProvider @Binds fun configInterfaceProvider(config: Config): ConfigInterface @Binds fun treatmentInterfaceProvider(treatmentsPlugin: TreatmentsPlugin): TreatmentsInterface - + @Binds fun provideDatabaseHelperInterface(databaseHelperProvider: DatabaseHelperProvider): DatabaseHelperInterface + @Binds fun provideUploadQueueInterface(uploadQueue: UploadQueue): UploadQueueInterface + @Binds fun provideNotificationHolderInterface(notificationHolder: NotificationHolder): NotificationHolderInterface } } diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt index 89783c9e4f..8748891d07 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt @@ -10,7 +10,7 @@ import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBFragment import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesFragment import info.nightscout.androidaps.plugins.constraints.objectives.activities.ObjectivesExamDialog -import info.nightscout.androidaps.plugins.constraints.objectives.dialogs.NtpProgressDialog +import info.nightscout.androidaps.dialogs.NtpProgressDialog import info.nightscout.androidaps.plugins.general.actions.ActionsFragment import info.nightscout.androidaps.plugins.general.automation.AutomationFragment import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseActionDialog diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt index 28abd8eb60..31ced947d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt @@ -40,6 +40,7 @@ class CarbsDialog : DialogFragmentWithDate() { @Inject lateinit var treatmentsPlugin: TreatmentsPlugin @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin + @Inject lateinit var nsUpload: NSUpload @Inject lateinit var carbsGenerator: CarbsGenerator companion object { @@ -233,7 +234,7 @@ class CarbsDialog : DialogFragmentWithDate() { } else { aapsLogger.debug("USER ENTRY: CARBS $carbsAfterConstraints time: $time duration: $duration") carbsGenerator.generateCarbs(carbsAfterConstraints, time, duration, notes) - NSUpload.uploadEvent(CareportalEvent.NOTE, DateUtil.now() - 2000, resourceHelper.gs(R.string.generated_ecarbs_note, carbsAfterConstraints, duration, timeOffset)) + nsUpload.uploadEvent(CareportalEvent.NOTE, DateUtil.now() - 2000, resourceHelper.gs(R.string.generated_ecarbs_note, carbsAfterConstraints, duration, timeOffset)) } } }, null) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt index 1eda2e060e..f9fa675438 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt @@ -36,6 +36,7 @@ class CareDialog : DialogFragmentWithDate() { @Inject lateinit var mainApp: MainApp @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction + @Inject lateinit var nsUpload: NSUpload @Inject lateinit var translator: Translator enum class EventType { @@ -197,7 +198,7 @@ class CareDialog : DialogFragmentWithDate() { careportalEvent.json = json.toString() aapsLogger.debug("USER ENTRY: CAREPORTAL ${careportalEvent.eventType} json: ${careportalEvent.json}") MainApp.getDbHelper().createOrUpdate(careportalEvent) - NSUpload.uploadCareportalEntryToNS(json) + nsUpload.uploadCareportalEntryToNS(json) }, null) } return true diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt index eb5e9ccf59..580b27228c 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt @@ -40,9 +40,9 @@ class FillDialog : DialogFragmentWithDate() { @Inject lateinit var constraintChecker: ConstraintChecker @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var ctx: Context + @Inject lateinit var nsUpload: NSUpload @Inject lateinit var commandQueue: CommandQueueProvider @Inject lateinit var activePlugin: ActivePluginProvider - @Inject lateinit var injector: HasAndroidInjector override fun onSaveInstanceState(savedInstanceState: Bundle) { super.onSaveInstanceState(savedInstanceState) @@ -124,12 +124,12 @@ class FillDialog : DialogFragmentWithDate() { } if (siteChange) { aapsLogger.debug("USER ENTRY: SITE CHANGE") - generateCareportalEvent(CareportalEvent.SITECHANGE, eventTime, notes, resourceHelper, sp, injector) + nsUpload.generateCareportalEvent(CareportalEvent.SITECHANGE, eventTime, notes) } if (insulinChange) { // add a second for case of both checked aapsLogger.debug("USER ENTRY: INSULIN CHANGE") - generateCareportalEvent(CareportalEvent.INSULINCHANGE, eventTime + 1000, notes, resourceHelper, sp, injector) + nsUpload.generateCareportalEvent(CareportalEvent.INSULINCHANGE, eventTime + 1000, notes) } }, null) } @@ -162,29 +162,4 @@ class FillDialog : DialogFragmentWithDate() { } }) } - - companion object { - fun generateCareportalEvent(eventType: String, time: Long, notes: String, resourceHelper: ResourceHelper, sp: SP, injector: HasAndroidInjector) { - val careportalEvent = CareportalEvent(injector) - careportalEvent.source = Source.USER - careportalEvent.date = time - careportalEvent.json = generateJson(eventType, time, notes, resourceHelper, sp).toString() - careportalEvent.eventType = eventType - MainApp.getDbHelper().createOrUpdate(careportalEvent) - NSUpload.uploadEvent(eventType, time, notes) - } - - private fun generateJson(careportalEvent: String, time: Long, notes: String, resourceHelper: ResourceHelper, sp: SP): JSONObject { - val data = JSONObject() - try { - data.put("eventType", careportalEvent) - data.put("created_at", DateUtil.toISOString(time)) - data.put("mills", time) - data.put("enteredBy", sp.getString("careportal_enteredby", resourceHelper.gs(R.string.app_name))) - if (notes.isNotEmpty()) data.put("notes", notes) - } catch (ignored: JSONException) { - } - return data - } - } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java index f04035277e..6b25f97882 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java @@ -22,6 +22,7 @@ import javax.inject.Singleton; import dagger.Lazy; import dagger.android.HasAndroidInjector; +import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainActivity; import info.nightscout.androidaps.MainApp; @@ -103,7 +104,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface { private boolean isSuperBolus; private boolean isDisconnected; - @Nullable public LastRun lastRun = null; + @Nullable private LastRun lastRun = null; @Nullable @Override public LastRun getLastRun() { return lastRun; @@ -412,7 +413,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface { lastRun.setLastSMBEnact(0); lastRun.setLastSMBRequest(0); - nsUpload.uploadDeviceStatus(this, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore); + nsUpload.uploadDeviceStatus(this, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore, BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); if (isSuspended()) { getAapsLogger().debug(LTag.APS, resourceHelper.gs(R.string.loopsuspended)); @@ -537,7 +538,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface { lastRun.setLastTBRRequest(lastRun.getLastAPSRun()); lastRun.setLastTBREnact(DateUtil.now()); lastRun.setLastOpenModeAccept(DateUtil.now()); - nsUpload.uploadDeviceStatus(lp, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore); + nsUpload.uploadDeviceStatus(lp, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore, BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); sp.incInt(R.string.key_ObjectivesmanualEnacts); } rxBus.send(new EventAcceptOpenLoopChange()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt index 1e01d814f6..69a8892bdc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.kt @@ -22,8 +22,8 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.constraints.objectives.activities.ObjectivesExamDialog -import info.nightscout.androidaps.plugins.constraints.objectives.dialogs.NtpProgressDialog -import info.nightscout.androidaps.plugins.constraints.objectives.events.EventNtpStatus +import info.nightscout.androidaps.dialogs.NtpProgressDialog +import info.nightscout.androidaps.events.EventNtpStatus import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesUpdateGui import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective.ExamTask import info.nightscout.androidaps.receivers.ReceiverStatusStore diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotification.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotification.kt index 7a730585c1..43342f35e5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotification.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotification.kt @@ -22,6 +22,7 @@ import javax.inject.Inject class ActionNotification(injector: HasAndroidInjector) : Action(injector) { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var nsUpload: NSUpload var text = InputString(injector) @@ -32,7 +33,7 @@ class ActionNotification(injector: HasAndroidInjector) : Action(injector) { override fun doAction(callback: Callback) { val notification = NotificationUserMessage(text.value) rxBus.send(EventNewNotification(notification)) - NSUpload.uploadError(text.value) + nsUpload.uploadError(text.value) rxBus.send(EventRefreshOverview("ActionNotification")) callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java index 8fe577ced3..52d7a25c49 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java @@ -78,6 +78,7 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O @Inject ActivePluginProvider activePlugin; @Inject TreatmentsPlugin treatmentsPlugin; @Inject HardLimits hardLimits; + @Inject NSUpload nsUpload; @Inject Translator translator; @Inject DateUtil dateUtil; @@ -714,7 +715,7 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O private void confirmNSTreatmentCreation() { final JSONObject data = gatherData(); - OKDialog.showConfirmation(getContext(), translator.translate(JsonHelper.safeGetString(data, "eventType", resourceHelper.gs(R.string.overview_treatment_label))), buildConfirmText(data), () -> NSUpload.createNSTreatment(data, profileStore, profileFunction, eventTime.getTime())); + OKDialog.showConfirmation(getContext(), translator.translate(JsonHelper.safeGetString(data, "eventType", resourceHelper.gs(R.string.overview_treatment_label))), buildConfirmText(data), () -> nsUpload.createNSTreatment(data, profileStore, profileFunction, eventTime.getTime())); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt index c54e383afc..d4efd0ff96 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt @@ -35,6 +35,7 @@ class FoodFragment : DaggerFragment() { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var foodPlugin: FoodPlugin + @Inject lateinit var nsUpload: NSUpload private val disposable = CompositeDisposable() private lateinit var unfiltered: List @@ -200,7 +201,7 @@ class FoodFragment : DaggerFragment() { activity?.let { activity -> showConfirmation(activity, resourceHelper.gs(R.string.confirmation), resourceHelper.gs(R.string.removerecord) + "\n" + food.name, DialogInterface.OnClickListener { _: DialogInterface?, _: Int -> if (food._id != null && food._id != "") { - NSUpload.removeFoodFromNS(food._id) + nsUpload.removeFoodFromNS(food._id) } foodPlugin.service?.delete(food) }, null) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.java index 89d0f65bc7..27310dad90 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.java @@ -33,6 +33,7 @@ public class NSClientFragment extends DaggerFragment implements View.OnClickList @Inject SP sp; @Inject ResourceHelper resourceHelper; @Inject RxBusWrapper rxBus; + @Inject UploadQueue uploadQueue; @Inject FabricPrivacy fabricPrivacy; private CompositeDisposable disposable = new CompositeDisposable(); @@ -119,13 +120,13 @@ public class NSClientFragment extends DaggerFragment implements View.OnClickList break; case R.id.nsclientinternal_clearqueue: OKDialog.showConfirmation(getContext(), resourceHelper.gs(R.string.nsclientinternal), resourceHelper.gs(R.string.clearqueueconfirm), () -> { - UploadQueue.clearQueue(); + uploadQueue.clearQueue(); updateGui(); fabricPrivacy.logCustom("NSClientClearQueue"); }); break; case R.id.nsclientinternal_showqueue: - rxBus.send(new EventNSClientNewLog("QUEUE", nsClientPlugin.queue().textList())); + rxBus.send(new EventNSClientNewLog("QUEUE", uploadQueue.textList())); break; } } @@ -154,7 +155,7 @@ public class NSClientFragment extends DaggerFragment implements View.OnClickList logScrollview.fullScroll(ScrollView.FOCUS_DOWN); } urlTextView.setText(nsClientPlugin.url()); - Spanned queuetext = Html.fromHtml(resourceHelper.gs(R.string.queue) + " " + UploadQueue.size() + ""); + Spanned queuetext = Html.fromHtml(resourceHelper.gs(R.string.queue) + " " + uploadQueue.size() + ""); queueTextView.setText(queuetext); statusTextView.setText(nsClientPlugin.status); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java index da77936384..9443e23e39 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java @@ -253,10 +253,6 @@ public class NSClientPlugin extends PluginBase { rxBus.send(new EventPreferenceChange(resourceHelper, R.string.key_nsclientinternal_paused)); } - public UploadQueue queue() { - return NSClientService.uploadQueue; - } - public String url() { return NSClientService.nsURL; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java index d9bd5a6307..08fecd9283 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java @@ -8,71 +8,86 @@ import com.j256.ormlite.dao.CloseableIterator; import org.json.JSONException; import org.json.JSONObject; -import org.slf4j.Logger; import java.sql.SQLException; -import info.nightscout.androidaps.MainApp; +import javax.inject.Inject; + import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DbRequest; +import info.nightscout.androidaps.interfaces.DatabaseHelperInterface; import info.nightscout.androidaps.interfaces.UploadQueueInterface; -import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; -import info.nightscout.androidaps.plugins.bus.RxBus; +import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientResend; import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService; -import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.sharedPreferences.SP; /** * Created by mike on 21.02.2016. */ public class UploadQueue implements UploadQueueInterface { - private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); + private final AAPSLogger aapsLogger; + private final DatabaseHelperInterface databaseHelper; + private final Context context; + private final SP sp; + private final RxBusWrapper rxBus; - public static String status() { - return "QUEUE: " + MainApp.getDbHelper().size(DatabaseHelper.DATABASE_DBREQUESTS); + @Inject + public UploadQueue( + AAPSLogger aapsLogger, + DatabaseHelperInterface databaseHelper, + Context context, + SP sp, + RxBusWrapper rxBus + ) { + this.aapsLogger = aapsLogger; + this.databaseHelper = databaseHelper; + this.context = context; + this.sp = sp; + this.rxBus = rxBus; } - public static long size() { - return MainApp.getDbHelper().size(DatabaseHelper.DATABASE_DBREQUESTS); + public String status() { + return "QUEUE: " + databaseHelper.size(DatabaseHelper.DATABASE_DBREQUESTS); } - private static void startService() { + public long size() { + return databaseHelper.size(DatabaseHelper.DATABASE_DBREQUESTS); + } + + private void startService() { if (NSClientService.handler == null) { - Context context = MainApp.instance(); context.startService(new Intent(context, NSClientService.class)); SystemClock.sleep(2000); } } - public static void add(final DbRequest dbr) { - if (SP.getBoolean(R.string.key_ns_noupload, false)) return; - if (L.isEnabled(LTag.NSCLIENT)) - log.debug("Adding to queue: " + dbr.log()); + public void add(final DbRequest dbr) { + if (sp.getBoolean(R.string.key_ns_noupload, false)) return; + aapsLogger.debug(LTag.NSCLIENT, "Adding to queue: " + dbr.log()); try { - MainApp.getDbHelper().create(dbr); + databaseHelper.create(dbr); } catch (Exception e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } - RxBus.getINSTANCE().send(new EventNSClientResend("newdata")); + rxBus.send(new EventNSClientResend("newdata")); } - static void clearQueue() { + void clearQueue() { startService(); if (NSClientService.handler != null) { NSClientService.handler.post(() -> { - if (L.isEnabled(LTag.NSCLIENT)) - log.debug("ClearQueue"); - MainApp.getDbHelper().deleteAllDbRequests(); - if (L.isEnabled(LTag.NSCLIENT)) - log.debug(status()); + aapsLogger.debug(LTag.NSCLIENT, "ClearQueue"); + databaseHelper.deleteAllDbRequests(); + aapsLogger.debug(LTag.NSCLIENT, status()); }); } } - public static void removeID(final JSONObject record) { + public void removeID(final JSONObject record) { startService(); if (NSClientService.handler != null) { NSClientService.handler.post(() -> { @@ -83,26 +98,24 @@ public class UploadQueue implements UploadQueueInterface { } else { return; } - if (MainApp.getDbHelper().deleteDbRequest(id) == 1) { - if (L.isEnabled(LTag.NSCLIENT)) - log.debug("Removed item from UploadQueue. " + UploadQueue.status()); + if (databaseHelper.deleteDbRequest(id) == 1) { + aapsLogger.debug(LTag.NSCLIENT, "Removed item from UploadQueue. " + status()); } } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } }); } } - public static void removeID(final String action, final String _id) { + public void removeID(final String action, final String _id) { if (_id == null || _id.equals("")) return; startService(); if (NSClientService.handler != null) { NSClientService.handler.post(() -> { - MainApp.getDbHelper().deleteDbRequestbyMongoId(action, _id); - if (L.isEnabled(LTag.NSCLIENT)) - log.debug("Removing " + _id + " from UploadQueue. " + UploadQueue.status()); + databaseHelper.deleteDbRequestbyMongoId(action, _id); + aapsLogger.debug(LTag.NSCLIENT, "Removing " + _id + " from UploadQueue. " + status()); }); } } @@ -111,7 +124,7 @@ public class UploadQueue implements UploadQueueInterface { String result = ""; CloseableIterator iterator; try { - iterator = MainApp.getDbHelper().getDbRequestInterator(); + iterator = databaseHelper.getDbRequestInterator(); try { while (iterator.hasNext()) { DbRequest dbr = iterator.next(); @@ -124,7 +137,7 @@ public class UploadQueue implements UploadQueueInterface { iterator.close(); } } catch (SQLException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java index 3187ccc924..195bb577cf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java @@ -31,15 +31,15 @@ import javax.inject.Inject; import dagger.android.DaggerService; import dagger.android.HasAndroidInjector; import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.interfaces.ProfileStore; import info.nightscout.androidaps.db.DbRequest; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventConfigBuilderChange; import info.nightscout.androidaps.events.EventNsFood; import info.nightscout.androidaps.events.EventPreferenceChange; +import info.nightscout.androidaps.interfaces.DatabaseHelperInterface; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.interfaces.ProfileStore; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.LTag; @@ -83,7 +83,7 @@ public class NSClientService extends DaggerService { @Inject AAPSLogger aapsLogger; @Inject NSSettingsStatus nsSettingsStatus; @Inject NSDeviceStatus nsDeviceStatus; - @Inject MainApp mainApp; + @Inject DatabaseHelperInterface databaseHelper; @Inject RxBusWrapper rxBus; @Inject ResourceHelper resourceHelper; @Inject SP sp; @@ -91,6 +91,7 @@ public class NSClientService extends DaggerService { @Inject BuildHelper buildHelper; @Inject Config config; @Inject DateUtil dateUtil; + @Inject UploadQueue uploadQueue; private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); private CompositeDisposable disposable = new CompositeDisposable(); @@ -124,8 +125,6 @@ public class NSClientService extends DaggerService { private String nsAPIhashCode = ""; - public static UploadQueue uploadQueue = new UploadQueue(); - private final ArrayList reconnections = new ArrayList<>(); private int WATCHDOG_INTERVAL_MINUTES = 2; private int WATCHDOG_RECONNECT_IN = 15; @@ -143,7 +142,7 @@ public class NSClientService extends DaggerService { @Override public void onCreate() { super.onCreate(); - PowerManager powerManager = (PowerManager) mainApp.getApplicationContext().getSystemService(Context.POWER_SERVICE); + PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:NSClientService"); mWakeLock.acquire(); @@ -528,7 +527,7 @@ public class NSClientService extends DaggerService { @Override public void call(final Object... args) { NSClientService.handler.post(() -> { - PowerManager powerManager = (PowerManager) mainApp.getApplicationContext().getSystemService(Context.POWER_SERVICE); + PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:NSClientService_onDataUpdate"); wakeLock.acquire(); @@ -604,7 +603,7 @@ public class NSClientService extends DaggerService { NSTreatment treatment = new NSTreatment(jsonTreatment); // remove from upload queue if Ack is failing - UploadQueue.removeID(jsonTreatment); + uploadQueue.removeID(jsonTreatment); //Find latest date in treatment if (treatment.getMills() != null && treatment.getMills() < System.currentTimeMillis()) if (treatment.getMills() > latestDateInReceivedData) @@ -636,7 +635,7 @@ public class NSClientService extends DaggerService { for (Integer index = 0; index < devicestatuses.length(); index++) { JSONObject jsonStatus = devicestatuses.getJSONObject(index); // remove from upload queue if Ack is failing - UploadQueue.removeID(jsonStatus); + uploadQueue.removeID(jsonStatus); } nsDeviceStatus.handleNewData(devicestatuses); } @@ -652,7 +651,7 @@ public class NSClientService extends DaggerService { JSONObject jsonFood = foods.getJSONObject(index); // remove from upload queue if Ack is failing - UploadQueue.removeID(jsonFood); + uploadQueue.removeID(jsonFood); String action = JsonHelper.safeGetString(jsonFood, "action"); @@ -684,7 +683,7 @@ public class NSClientService extends DaggerService { for (Integer index = 0; index < mbgs.length(); index++) { JSONObject jsonMbg = mbgs.getJSONObject(index); // remove from upload queue if Ack is failing - UploadQueue.removeID(jsonMbg); + uploadQueue.removeID(jsonMbg); } handleNewMbg(mbgs, isDelta); } @@ -695,7 +694,7 @@ public class NSClientService extends DaggerService { // Retreive actual calibration for (Integer index = 0; index < cals.length(); index++) { // remove from upload queue if Ack is failing - UploadQueue.removeID(cals.optJSONObject(index)); + uploadQueue.removeID(cals.optJSONObject(index)); } handleNewCal(cals, isDelta); } @@ -709,7 +708,7 @@ public class NSClientService extends DaggerService { NSSgv sgv = new NSSgv(jsonSgv); // Handle new sgv here // remove from upload queue if Ack is failing - UploadQueue.removeID(jsonSgv); + uploadQueue.removeID(jsonSgv); //Find latest date in sgv if (sgv.getMills() != null && sgv.getMills() < System.currentTimeMillis()) if (sgv.getMills() > latestDateInReceivedData) @@ -795,7 +794,7 @@ public class NSClientService extends DaggerService { } public void resend(final String reason) { - if (UploadQueue.size() == 0) + if (uploadQueue.size() == 0) return; if (!isConnected || !hasWriteAuth) return; @@ -804,8 +803,7 @@ public class NSClientService extends DaggerService { if (mSocket == null || !mSocket.connected()) return; if (lastResendTime > System.currentTimeMillis() - 10 * 1000L) { - if (L.isEnabled(LTag.NSCLIENT)) - log.debug("Skipping resend by lastResendTime: " + ((System.currentTimeMillis() - lastResendTime) / 1000L) + " sec"); + aapsLogger.debug(LTag.NSCLIENT, "Skipping resend by lastResendTime: " + ((System.currentTimeMillis() - lastResendTime) / 1000L) + " sec"); return; } lastResendTime = System.currentTimeMillis(); @@ -815,7 +813,7 @@ public class NSClientService extends DaggerService { CloseableIterator iterator; int maxcount = 30; try { - iterator = mainApp.getDbHelper().getDbRequestInterator(); + iterator = databaseHelper.getDbRequestInterator(); try { while (iterator.hasNext() && maxcount > 0) { DbRequest dbr = iterator.next(); @@ -852,7 +850,7 @@ public class NSClientService extends DaggerService { private void handleAnnouncement(JSONObject announcement) { NSAlarm nsAlarm = new NSAlarm(announcement); - Notification notification = new NotificationWithAction(mainApp, nsAlarm); + Notification notification = new NotificationWithAction(injector, nsAlarm); rxBus.send(new EventNewNotification(notification)); rxBus.send(new EventNSClientNewLog("ANNOUNCEMENT", JsonHelper.safeGetString(announcement, "message", "received"))); aapsLogger.debug(LTag.NSCLIENT, announcement.toString()); @@ -862,7 +860,7 @@ public class NSClientService extends DaggerService { long snoozedTo = sp.getLong(R.string.key_snoozedTo, 0L); if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) { NSAlarm nsAlarm = new NSAlarm(alarm); - Notification notification = new NotificationWithAction(mainApp, nsAlarm); + Notification notification = new NotificationWithAction(injector, nsAlarm); rxBus.send(new EventNewNotification(notification)); } rxBus.send(new EventNSClientNewLog("ALARM", JsonHelper.safeGetString(alarm, "message", "received"))); @@ -873,7 +871,7 @@ public class NSClientService extends DaggerService { long snoozedTo = sp.getLong(R.string.key_snoozedTo, 0L); if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) { NSAlarm nsAlarm = new NSAlarm(alarm); - Notification notification = new NotificationWithAction(mainApp, nsAlarm); + Notification notification = new NotificationWithAction(injector, nsAlarm); rxBus.send(new EventNewNotification(notification)); } rxBus.send(new EventNSClientNewLog("URGENTALARM", JsonHelper.safeGetString(alarm, "message", "received"))); @@ -887,7 +885,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_NEW_CAL); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(mainApp).sendBroadcast(intent); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } public void handleNewMbg(JSONArray mbgs, boolean isDelta) { @@ -897,7 +895,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_NEW_MBG); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(mainApp).sendBroadcast(intent); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } public void handleNewProfile(ProfileStore profile, boolean isDelta) { @@ -907,7 +905,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_NEW_PROFILE); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(mainApp).sendBroadcast(intent); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); if (sp.getBoolean(R.string.key_nsclient_localbroadcasts, false)) { bundle = new Bundle(); @@ -916,7 +914,7 @@ public class NSClientService extends DaggerService { intent = new Intent(Intents.ACTION_NEW_PROFILE); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - mainApp.sendBroadcast(intent); + this.sendBroadcast(intent); } } @@ -929,7 +927,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_NEW_SGV); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(mainApp).sendBroadcast(intent); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } if (sp.getBoolean(R.string.key_nsclient_localbroadcasts, false)) { @@ -940,7 +938,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_NEW_SGV); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - mainApp.sendBroadcast(intent); + this.sendBroadcast(intent); } } } @@ -954,7 +952,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(mainApp).sendBroadcast(intent); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } if (sp.getBoolean(R.string.key_nsclient_localbroadcasts, false)) { @@ -966,7 +964,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - mainApp.getApplicationContext().sendBroadcast(intent); + this.getApplicationContext().sendBroadcast(intent); } } } @@ -980,7 +978,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(mainApp).sendBroadcast(intent); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } if (sp.getBoolean(R.string.key_nsclient_localbroadcasts, false)) { @@ -992,7 +990,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - mainApp.getApplicationContext().sendBroadcast(intent); + this.getApplicationContext().sendBroadcast(intent); } } } @@ -1004,7 +1002,7 @@ public class NSClientService extends DaggerService { Intent intent = new Intent(Intents.ACTION_REMOVED_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - LocalBroadcastManager.getInstance(mainApp).sendBroadcast(intent); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); if (sp.getBoolean(R.string.key_nsclient_localbroadcasts, false)) { @@ -1014,7 +1012,7 @@ public class NSClientService extends DaggerService { intent = new Intent(Intents.ACTION_REMOVED_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - mainApp.getApplicationContext().sendBroadcast(intent); + this.getApplicationContext().sendBroadcast(intent); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index 2a462fb44a..bda7d5b249 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -20,6 +20,7 @@ import android.view.View.OnLongClickListener import android.view.ViewGroup import android.widget.LinearLayout import android.widget.TextView +import androidx.core.text.toSpanned import androidx.recyclerview.widget.LinearLayoutManager import com.jjoe64.graphview.GraphView import dagger.android.HasAndroidInjector @@ -344,8 +345,9 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList if (loopPlugin.isEnabled(PluginType.LOOP)) { val lastRun = loopPlugin.lastRun loopPlugin.invoke("Accept temp button", false) - if (lastRun?.lastAPSRun != null && lastRun.constraintsProcessed.isChangeRequested) { - OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.pump_tempbasal_label), lastRun.constraintsProcessed.toSpanned(), Runnable { + if (lastRun?.lastAPSRun != null && lastRun.constraintsProcessed?.isChangeRequested == true) { + OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.pump_tempbasal_label), lastRun.constraintsProcessed?.toSpanned() + ?: "".toSpanned(), Runnable { aapsLogger.debug("USER ENTRY: ACCEPT TEMP BASAL") overview_accepttempbutton?.visibility = View.GONE (context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).cancel(Constants.notificationID) @@ -442,7 +444,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList val showAcceptButton = !closedLoopEnabled.value() && // Open mode needed lastRun != null && (lastRun.lastOpenModeAccept == 0L || lastRun.lastOpenModeAccept < lastRun.lastAPSRun) &&// never accepted or before last result - lastRun.constraintsProcessed.isChangeRequested // change is requested + lastRun.constraintsProcessed?.isChangeRequested == true // change is requested if (showAcceptButton && pump.isInitialized && !pump.isSuspended && loopPlugin.isEnabled(PluginType.LOOP)) { overview_accepttempbutton?.visibility = View.VISIBLE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.kt index 02ccf1480f..70e4f9f8fc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.kt @@ -16,10 +16,10 @@ import info.nightscout.androidaps.data.IobTotal import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.db.BgReading import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.interfaces.LoopInterface import info.nightscout.androidaps.interfaces.TreatmentsInterface import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin.LastRun import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.general.overview.graphExtensions.* @@ -197,7 +197,7 @@ class GraphData(injector: HasAndroidInjector, private val graph: GraphView, priv basalScale.setMultiplier(maxY * scale / maxBasalValueFound) } - fun addTargetLine(fromTime: Long, toTimeParam: Long, profile: Profile, lastRun: LastRun?) { + fun addTargetLine(fromTime: Long, toTimeParam: Long, profile: Profile, lastRun: LoopInterface.LastRun?) { var toTime = toTimeParam val targetsSeriesArray: MutableList = ArrayList() var lastTarget = -1.0 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt index abff22eae3..02b201f5ab 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt @@ -104,7 +104,7 @@ class WearPlugin @Inject constructor( .observeOn(Schedulers.io()) .subscribe({ event: EventDismissBolusProgressIfRunning -> if (event.result == null) return@subscribe - val status: String = if (event.result.success) { + val status: String = if (event.result!!.success) { resourceHelper.gs(R.string.success) } else { resourceHelper.gs(R.string.nosuccess) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java index e0a0657826..dd0babf951 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java @@ -531,9 +531,9 @@ public class WatchUpdaterService extends WearableListenerService implements Goog } - final LoopPlugin.LastRun finalLastRun = loopPlugin.lastRun; - if (sp.getBoolean("wear_predictions", true) && finalLastRun != null && finalLastRun.request.hasPredictions && finalLastRun.constraintsProcessed != null) { - List predArray = finalLastRun.constraintsProcessed.getPredictions(); + final LoopPlugin.LastRun finalLastRun = loopPlugin.getLastRun(); + if (sp.getBoolean("wear_predictions", true) && finalLastRun != null && finalLastRun.getRequest().hasPredictions && finalLastRun.getConstraintsProcessed() != null) { + List predArray = finalLastRun.getConstraintsProcessed().getPredictions(); if (!predArray.isEmpty()) { for (BgReading bg : predArray) { @@ -715,7 +715,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog //OpenAPS status if (config.getAPS()) { //we are AndroidAPS - openApsStatus = loopPlugin.lastRun != null && loopPlugin.lastRun.lastTBREnact != 0 ? loopPlugin.lastRun.lastTBREnact : -1; + openApsStatus = loopPlugin.getLastRun() != null && loopPlugin.getLastRun().getLastTBREnact() != 0 ? loopPlugin.getLastRun().getLastTBREnact() : -1; } else { //NSClient or remote openApsStatus = NSDeviceStatus.getOpenApsTimestamp(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt index 8d2761cfa3..7944707e57 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt @@ -37,7 +37,8 @@ class LocalProfilePlugin @Inject constructor( private val rxBus: RxBusWrapper, resourceHelper: ResourceHelper, private val sp: SP, - private val profileFunction: ProfileFunction + private val profileFunction: ProfileFunction, + private val nsUpload: NSUpload ) : PluginBase(PluginDescription() .mainType(PluginType.PROFILE) .fragmentClass(LocalProfileFragment::class.java.name) @@ -140,7 +141,7 @@ class LocalProfilePlugin @Inject constructor( if (name.contains(".")) namesOK = false } if (namesOK) - rawProfile?.let { NSUpload.uploadProfileStore(it.data) } + rawProfile?.let { nsUpload.uploadProfileStore(it.data) } else activity?.let { OKDialog.show(it, "", resourceHelper.gs(R.string.profilenamecontainsdot)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java index de9b4e66fc..50f40318d9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java @@ -1259,7 +1259,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr } @NonNull @Override - public JSONObject getJSONStatus(Profile profile, String profileName) { + public JSONObject getJSONStatus(Profile profile, String profileName, String version) { if (!pump.initialized) { return null; } @@ -1281,7 +1281,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr pumpJson.put("status", statusJson); JSONObject extendedJson = new JSONObject(); - extendedJson.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); + extendedJson.put("Version", version); extendedJson.put("ActiveProfile", profileFunction.getProfileName()); PumpState ps = pump.state; if (ps.tbrActive) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java index 6d06f2e788..6227d2ea2a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java @@ -324,7 +324,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI @NonNull @Override - public JSONObject getJSONStatus(Profile profile, String profileName) { + public JSONObject getJSONStatus(Profile profile, String profileName, String version) { if ((getPumpStatusData().lastConnection + 5 * 60 * 1000L) < System.currentTimeMillis()) { return new JSONObject(); @@ -337,7 +337,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI try { battery.put("percent", getPumpStatusData().batteryRemaining); status.put("status", getPumpStatusData().pumpStatusType != null ? getPumpStatusData().pumpStatusType.getStatus() : "normal"); - extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); + extended.put("Version", version); try { extended.put("ActiveProfile", profileName); } catch (Exception ignored) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java index b055cacda3..3e0a853dc5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java @@ -366,7 +366,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump } @NonNull @Override - public JSONObject getJSONStatus(Profile profile, String profilename) { + public JSONObject getJSONStatus(Profile profile, String profilename, String version) { DanaRPump pump = danaRPump; long now = System.currentTimeMillis(); if (pump.getLastConnection() + 5 * 60 * 1000L < System.currentTimeMillis()) { @@ -380,7 +380,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump battery.put("percent", pump.getBatteryRemaining()); status.put("status", pump.getPumpSuspended() ? "suspended" : "normal"); status.put("timestamp", DateUtil.toISOString(pump.getLastConnection())); - extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); + extended.put("Version", version); if (pump.getLastBolusTime() != 0) { extended.put("LastBolus", dateUtil.dateAndTimeString(pump.getLastBolusTime())); extended.put("LastBolusAmount", pump.getLastBolusAmount()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableR.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableR.kt index dd4c59cee4..630bb9ecad 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableR.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableR.kt @@ -7,6 +7,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin @@ -28,6 +29,7 @@ class MessageHashTableR @Inject constructor( configBuilderPlugin: ConfigBuilderPlugin, commandQueue: CommandQueueProvider, activePlugin: ActivePluginProvider, + nsUpload: NSUpload, injector: HasAndroidInjector, dateUtil: DateUtil ) : MessageHashTableBase { @@ -54,7 +56,7 @@ class MessageHashTableR @Inject constructor( put(MsgSetTempBasalStop(aapsLogger)) // 0x0403 CMD_PUMPSET_EXERCISE_STOP put(MsgSetExtendedBolusStop(aapsLogger)) // 0x0406 CMD_PUMPSET_EXPANS_INS_STOP put(MsgSetExtendedBolusStart(aapsLogger, constraintChecker, 0.0, 0)) // 0x0407 CMD_PUMPSET_EXPANS_INS_S - put(MsgError(aapsLogger, rxBus, resourceHelper, danaRPump)) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS + put(MsgError(aapsLogger, rxBus, resourceHelper, danaRPump, nsUpload)) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS put(MsgPCCommStart(aapsLogger)) // 0x3001 CMD_CONNECT put(MsgPCCommStop(aapsLogger)) // 0x3002 CMD_DISCONNECT put(MsgHistoryBolus(aapsLogger, rxBus, dateUtil)) // 0x3101 CMD_HISTORY_MEAL_INS diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.kt index 6069520870..08d4c57324 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.kt @@ -13,7 +13,8 @@ class MsgError( private val aapsLogger: AAPSLogger, private val rxBus: RxBusWrapper, private val resourceHelper: ResourceHelper, - private val danaRPump: DanaRPump + private val danaRPump: DanaRPump, + private val nsUpload: NSUpload ) : MessageBase() { init { @@ -41,6 +42,6 @@ class MsgError( failed = false } aapsLogger.debug(LTag.PUMPCOMM, "Error detected: $errorString") - NSUpload.uploadError(errorString) + nsUpload.uploadError(errorString) } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt index b25a5b9b1f..26f48639d2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.kt @@ -5,7 +5,7 @@ import info.nightscout.androidaps.db.DanaRHistoryRecord import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus +import info.nightscout.androidaps.events.EventDanaRSyncStatus import info.nightscout.androidaps.utils.DateUtil open class MsgHistoryAll( diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java index 73fe0ec10c..2a357761f5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java @@ -83,6 +83,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { @Inject MessageHashTableR messageHashTableR; @Inject ActivePluginProvider activePlugin; @Inject ProfileFunction profileFunction; + @Inject NSUpload nsUpload; @Inject SP sp; @Inject HasAndroidInjector injector; @@ -214,7 +215,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT); rxBus.send(new EventNewNotification(reportFail)); - NSUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits() + "U"); + nsUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits() + "U"); lastApproachingDailyLimit = System.currentTimeMillis(); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKorean.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKorean.kt index 882ab11739..67ce3eb6b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKorean.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKorean.kt @@ -7,6 +7,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.comm.* @@ -30,6 +31,7 @@ class MessageHashTableRKorean @Inject constructor( commandQueue: CommandQueueProvider, activePlugin: ActivePluginProvider, dateUtil: DateUtil, + nsUpload: NSUpload, injector: HasAndroidInjector ) : MessageHashTableBase { @@ -52,7 +54,7 @@ class MessageHashTableRKorean @Inject constructor( put(MsgSetTempBasalStop(aapsLogger)) // 0x0403 CMD_PUMPSET_EXERCISE_STOP put(MsgSetExtendedBolusStop(aapsLogger)) // 0x0406 CMD_PUMPSET_EXPANS_INS_STOP put(MsgSetExtendedBolusStart(aapsLogger, constraintChecker, 0.0, 0)) // 0x0407 CMD_PUMPSET_EXPANS_INS_S - put(MsgError(aapsLogger, rxBus, resourceHelper, danaRPump)) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS + put(MsgError(aapsLogger, rxBus, resourceHelper, danaRPump, nsUpload)) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS put(MsgPCCommStart(aapsLogger)) // 0x3001 CMD_CONNECT put(MsgPCCommStop(aapsLogger)) // 0x3002 CMD_DISCONNECT put(MsgHistoryBolus(aapsLogger, rxBus, dateUtil)) // 0x3101 CMD_HISTORY_MEAL_INS diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java index 2f00754404..d8da9b78c2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java @@ -75,6 +75,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { @Inject MessageHashTableRKorean messageHashTableRKorean; @Inject ActivePluginProvider activePlugin; @Inject ProfileFunction profileFunction; + @Inject NSUpload nsUpload; @Inject DateUtil dateUtil; public DanaRKoreanExecutionService() { @@ -203,7 +204,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT); rxBus.send(new EventNewNotification(reportFail)); - NSUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits() + "U"); + nsUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits() + "U"); lastApproachingDailyLimit = System.currentTimeMillis(); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTableRv2.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTableRv2.kt index 8833ea6b3f..836de3d6cc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTableRv2.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTableRv2.kt @@ -7,6 +7,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump @@ -35,6 +36,7 @@ class MessageHashTableRv2 @Inject constructor( activePlugin: ActivePluginProvider, detailedBolusInfoStorage: DetailedBolusInfoStorage, treatmentsPlugin: TreatmentsPlugin, + nsUpload: NSUpload, injector: HasAndroidInjector, dateUtil: DateUtil ) : MessageHashTableBase { @@ -60,7 +62,7 @@ class MessageHashTableRv2 @Inject constructor( put(MsgSetTempBasalStop(aapsLogger)) // 0x0403 CMD_PUMPSET_EXERCISE_STOP put(MsgSetExtendedBolusStop(aapsLogger)) // 0x0406 CMD_PUMPSET_EXPANS_INS_STOP put(MsgSetExtendedBolusStart(aapsLogger, constraintChecker, 0.0, 0)) // 0x0407 CMD_PUMPSET_EXPANS_INS_S - put(MsgError(aapsLogger, rxBus, resourceHelper, danaRPump)) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS + put(MsgError(aapsLogger, rxBus, resourceHelper, danaRPump, nsUpload)) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS put(MsgPCCommStart(aapsLogger)) // 0x3001 CMD_CONNECT put(MsgPCCommStop(aapsLogger)) // 0x3002 CMD_DISCONNECT put(MsgHistoryBolus(aapsLogger, rxBus, dateUtil)) // 0x3101 CMD_HISTORY_MEAL_INS diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java index 4c664ea1df..f072d3a8e1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java @@ -99,6 +99,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { @Inject DetailedBolusInfoStorage detailedBolusInfoStorage; @Inject TreatmentsPlugin treatmentsPlugin; @Inject ProfileFunction profileFunction; + @Inject NSUpload nsUpload; @Inject SP sp; @Inject DateUtil dateUtil; @@ -255,7 +256,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT); rxBus.send(new EventNewNotification(reportFail)); - NSUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits() + "U"); + nsUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits() + "U"); lastApproachingDailyLimit = System.currentTimeMillis(); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java index d44470bad1..f8d1cf1ce5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -27,7 +27,6 @@ import javax.inject.Inject; import javax.inject.Singleton; import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -39,6 +38,7 @@ import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TDD; import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.interfaces.CommandQueueProvider; @@ -46,6 +46,7 @@ import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpPluginBase; @@ -53,7 +54,6 @@ import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.common.ManufacturerType; -import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; @@ -132,7 +132,6 @@ import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_erro import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NoActiveTBRToCanceLException; import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator; import info.nightscout.androidaps.plugins.pump.insight.utils.ParameterBlockUtil; -import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.TimeChangeType; @@ -149,7 +148,9 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, private final SP sp; private final CommandQueueProvider commandQueue; private final ProfileFunction profileFunction; + private final NSUpload nsUpload; private final Context context; + private final UploadQueue uploadQueue; private final DateUtil dateUtil; public static final String ALERT_CHANNEL_ID = "AndroidAPS-InsightAlert"; @@ -209,7 +210,9 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, SP sp, CommandQueueProvider commandQueue, ProfileFunction profileFunction, + NSUpload nsUpload, Context context, + UploadQueue uploadQueue, Config config, DateUtil dateUtil ) { @@ -230,7 +233,9 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, this.sp = sp; this.commandQueue = commandQueue; this.profileFunction = profileFunction; + this.nsUpload = nsUpload; this.context = context; + this.uploadQueue = uploadQueue; this.dateUtil = dateUtil; pumpDescription = new PumpDescription(); @@ -929,8 +934,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, if (extendedBolus.durationInMinutes <= 0) { final String _id = extendedBolus._id; if (NSUpload.isIdValid(_id)) - NSUpload.removeCareportalEntryFromNS(_id); - else UploadQueue.removeID("dbAdd", _id); + nsUpload.removeCareportalEntryFromNS(_id); + else uploadQueue.removeID("dbAdd", _id); MainApp.getDbHelper().delete(extendedBolus); } else treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus); @@ -978,7 +983,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, } @NonNull @Override - public JSONObject getJSONStatus(Profile profile, String profileName) { + public JSONObject getJSONStatus(Profile profile, String profileName, String version) { long now = System.currentTimeMillis(); if (connectionService == null) return null; if (System.currentTimeMillis() - connectionService.getLastConnected() > (60 * 60 * 1000)) { @@ -991,7 +996,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, final JSONObject extended = new JSONObject(); try { status.put("timestamp", DateUtil.toISOString(connectionService.getLastConnected())); - extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); + extended.put("Version", version); try { extended.put("ActiveProfile", profileFunction.getProfileName()); } catch (Exception e) { @@ -1451,8 +1456,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, ExtendedBolus extendedBolus = MainApp.getDbHelper().getExtendedBolusByPumpId(bolusID.id); if (extendedBolus != null) { final String _id = extendedBolus._id; - if (NSUpload.isIdValid(_id)) NSUpload.removeCareportalEntryFromNS(_id); - else UploadQueue.removeID("dbAdd", _id); + if (NSUpload.isIdValid(_id)) nsUpload.removeCareportalEntryFromNS(_id); + else uploadQueue.removeID("dbAdd", _id); MainApp.getDbHelper().delete(extendedBolus); } } else { @@ -1583,7 +1588,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, careportalEvent.eventType = CareportalEvent.NOTE; careportalEvent.json = data.toString(); MainApp.getDbHelper().createOrUpdate(careportalEvent); - NSUpload.uploadCareportalEntryToNS(data); + nsUpload.uploadCareportalEntryToNS(data); } catch (JSONException e) { aapsLogger.error("Unhandled exception", e); } @@ -1617,7 +1622,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, careportalEvent.eventType = event; careportalEvent.json = data.toString(); MainApp.getDbHelper().createOrUpdate(careportalEvent); - NSUpload.uploadCareportalEntryToNS(data); + nsUpload.uploadCareportalEntryToNS(data); } catch (JSONException e) { aapsLogger.error("Unhandled exception", e); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java index b5d7fafb4e..44550ebea6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java @@ -227,14 +227,14 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface { } @NonNull @Override - public JSONObject getJSONStatus(Profile profile, String profileName) { + public JSONObject getJSONStatus(Profile profile, String profileName, String version) { long now = System.currentTimeMillis(); JSONObject pump = new JSONObject(); JSONObject status = new JSONObject(); JSONObject extended = new JSONObject(); try { status.put("status", "normal"); - extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); + extended.put("Version", version); try { extended.put("ActiveProfile", profileName); } catch (Exception e) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java index d8f5c47b4f..76f011da16 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java @@ -78,6 +78,7 @@ public class MedtronicHistoryData { private final AAPSLogger aapsLogger; private final SP sp; private final ActivePluginProvider activePlugin; + private final NSUpload nsUpload; private final MedtronicUtil medtronicUtil; private final MedtronicPumpHistoryDecoder medtronicPumpHistoryDecoder; @@ -106,6 +107,7 @@ public class MedtronicHistoryData { AAPSLogger aapsLogger, SP sp, ActivePluginProvider activePlugin, + NSUpload nsUpload, MedtronicUtil medtronicUtil, MedtronicPumpHistoryDecoder medtronicPumpHistoryDecoder ) { @@ -115,6 +117,7 @@ public class MedtronicHistoryData { this.aapsLogger = aapsLogger; this.sp = sp; this.activePlugin = activePlugin; + this.nsUpload = nsUpload; this.medtronicUtil = medtronicUtil; this.medtronicPumpHistoryDecoder = medtronicPumpHistoryDecoder; } @@ -543,7 +546,7 @@ public class MedtronicHistoryData { careportalEvent.eventType = event; careportalEvent.json = data.toString(); MainApp.getDbHelper().createOrUpdate(careportalEvent); - NSUpload.uploadCareportalEntryToNS(data); + nsUpload.uploadCareportalEntryToNS(data); } catch (JSONException e) { aapsLogger.error("Unhandled exception", e); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java index 37c6d420f7..70dac25789 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java @@ -35,6 +35,7 @@ public class InitPodRefreshAction extends AbstractCancelAction implements Finish @Inject OmnipodUtil omnipodUtil; @Inject AAPSLogger aapsLogger; @Inject SP sp; + @Inject NSUpload nsUpload; public InitPodRefreshAction(HasAndroidInjector injector, PodManagementActivity podManagementActivity, PodActionType actionType) { injector.androidInjector().inject(this); @@ -86,7 +87,7 @@ public class InitPodRefreshAction extends AbstractCancelAction implements Finish careportalEvent.eventType = event; careportalEvent.json = data.toString(); MainApp.getDbHelper().createOrUpdate(careportalEvent); - NSUpload.uploadCareportalEntryToNS(data); + nsUpload.uploadCareportalEntryToNS(data); } catch (JSONException e) { aapsLogger.error(LTag.PUMPCOMM, "Unhandled exception when uploading SiteChange event.", e); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt index 3db377a230..e8916b5647 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt @@ -337,7 +337,7 @@ class VirtualPumpPlugin @Inject constructor( return result } - override fun getJSONStatus(profile: Profile, profileName: String): JSONObject { + override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject { val now = System.currentTimeMillis() if (!sp.getBoolean("virtualpump_uploadstatus", false)) { return JSONObject() @@ -349,7 +349,7 @@ class VirtualPumpPlugin @Inject constructor( try { battery.put("percent", batteryPercent) status.put("status", "normal") - extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION) + extended.put("Version", version) try { extended.put("ActiveProfile", profileName) } catch (ignored: Exception) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt index 7e854f7e96..41d1c07ddc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt @@ -31,7 +31,8 @@ class DexcomPlugin @Inject constructor( private val sp: SP, private val mainApp: MainApp, resourceHelper: ResourceHelper, - aapsLogger: AAPSLogger + aapsLogger: AAPSLogger, + private val nsUpload: NSUpload ) : PluginBase(PluginDescription() .mainType(PluginType.BGSOURCE) .fragmentClass(BGSourceFragment::class.java.name) @@ -78,10 +79,10 @@ class DexcomPlugin @Inject constructor( bgReading.raw = 0.0 if (MainApp.getDbHelper().createIfNotExists(bgReading, "Dexcom$sensorType")) { if (sp.getBoolean(R.string.key_dexcomg5_nsupload, false)) { - NSUpload.uploadBg(bgReading, "AndroidAPS-Dexcom$sensorType") + nsUpload.uploadBg(bgReading, "AndroidAPS-Dexcom$sensorType") } if (sp.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { - NSUpload.sendToXdrip(bgReading) + nsUpload.sendToXdrip(bgReading) } } } @@ -108,7 +109,7 @@ class DexcomPlugin @Inject constructor( careportalEvent.eventType = CareportalEvent.BGCHECK careportalEvent.json = jsonObject.toString() MainApp.getDbHelper().createOrUpdate(careportalEvent) - NSUpload.uploadCareportalEntryToNS(jsonObject) + nsUpload.uploadCareportalEntryToNS(jsonObject) } } } @@ -128,7 +129,7 @@ class DexcomPlugin @Inject constructor( careportalEvent.eventType = CareportalEvent.SENSORCHANGE careportalEvent.json = jsonObject.toString() MainApp.getDbHelper().createOrUpdate(careportalEvent) - NSUpload.uploadCareportalEntryToNS(jsonObject) + nsUpload.uploadCareportalEntryToNS(jsonObject) } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt index 6b0021fbcf..9141d57214 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt @@ -29,7 +29,8 @@ class EversensePlugin @Inject constructor( private val sp: SP, resourceHelper: ResourceHelper, aapsLogger: AAPSLogger, - private val dateUtil: DateUtil + private val dateUtil: DateUtil, + private val nsUpload: NSUpload ) : PluginBase(PluginDescription() .mainType(PluginType.BGSOURCE) .fragmentClass(BGSourceFragment::class.java.name) @@ -77,10 +78,10 @@ class EversensePlugin @Inject constructor( bgReading.raw = 0.0 val isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "Eversense") if (isNew && sp.getBoolean(R.string.key_dexcomg5_nsupload, false)) { - NSUpload.uploadBg(bgReading, "AndroidAPS-Eversense") + nsUpload.uploadBg(bgReading, "AndroidAPS-Eversense") } if (isNew && sp.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { - NSUpload.sendToXdrip(bgReading) + nsUpload.sendToXdrip(bgReading) } } } @@ -103,7 +104,7 @@ class EversensePlugin @Inject constructor( data.put("glucoseType", "Finger") data.put("glucose", calibrationGlucoseLevels[i]) data.put("units", Constants.MGDL) - NSUpload.uploadCareportalEntryToNS(data) + nsUpload.uploadCareportalEntryToNS(data) } } catch (e: JSONException) { aapsLogger.error("Unhandled exception", e) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/PoctechPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/PoctechPlugin.kt index c33cfaee0f..2032dd4479 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/PoctechPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/PoctechPlugin.kt @@ -26,7 +26,8 @@ class PoctechPlugin @Inject constructor( injector: HasAndroidInjector, resourceHelper: ResourceHelper, aapsLogger: AAPSLogger, - private val sp: SP + private val sp: SP, + private val nsUpload: NSUpload ) : PluginBase(PluginDescription() .mainType(PluginType.BGSOURCE) .fragmentClass(BGSourceFragment::class.java.name) @@ -58,10 +59,10 @@ class PoctechPlugin @Inject constructor( if (safeGetString(json, "units", Constants.MGDL) == "mmol/L") bgReading.value = bgReading.value * Constants.MMOLL_TO_MGDL val isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "Poctech") if (isNew && sp.getBoolean(R.string.key_dexcomg5_nsupload, false)) { - NSUpload.uploadBg(bgReading, "AndroidAPS-Poctech") + nsUpload.uploadBg(bgReading, "AndroidAPS-Poctech") } if (isNew && sp.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { - NSUpload.sendToXdrip(bgReading) + nsUpload.sendToXdrip(bgReading) } } } catch (e: JSONException) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/TomatoPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/TomatoPlugin.kt index db4c658614..1ba7958b61 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/TomatoPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/TomatoPlugin.kt @@ -22,7 +22,8 @@ class TomatoPlugin @Inject constructor( injector: HasAndroidInjector, resourceHelper: ResourceHelper, aapsLogger: AAPSLogger, - private val sp: SP + private val sp: SP, + private val nsUpload: NSUpload ) : PluginBase(PluginDescription() .mainType(PluginType.BGSOURCE) .fragmentClass(BGSourceFragment::class.java.name) @@ -46,10 +47,10 @@ class TomatoPlugin @Inject constructor( bgReading.date = bundle.getLong("com.fanqies.tomatofn.Extras.Time") val isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "Tomato") if (isNew && sp.getBoolean(R.string.key_dexcomg5_nsupload, false)) { - NSUpload.uploadBg(bgReading, "AndroidAPS-Tomato") + nsUpload.uploadBg(bgReading, "AndroidAPS-Tomato") } if (isNew && sp.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { - NSUpload.sendToXdrip(bgReading) + nsUpload.sendToXdrip(bgReading) } } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt index 63574ea8d2..e6d2f02883 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt @@ -42,6 +42,8 @@ class TreatmentsBolusFragment : DaggerFragment() { @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var treatmentsPlugin: TreatmentsPlugin @Inject lateinit var profileFunction: ProfileFunction + @Inject lateinit var nsUpload: NSUpload + @Inject lateinit var uploadQueue: UploadQueue @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, @@ -68,9 +70,9 @@ class TreatmentsBolusFragment : DaggerFragment() { val futureTreatments = treatmentsPlugin.service.getTreatmentDataFromTime(DateUtil.now() + 1000, true) for (treatment in futureTreatments) { if (NSUpload.isIdValid(treatment._id)) - NSUpload.removeCareportalEntryFromNS(treatment._id) + nsUpload.removeCareportalEntryFromNS(treatment._id) else - UploadQueue.removeID("dbAdd", treatment._id) + uploadQueue.removeID("dbAdd", treatment._id) treatmentsPlugin.service.delete(treatment) } updateGui() @@ -166,9 +168,9 @@ class TreatmentsBolusFragment : DaggerFragment() { treatmentsPlugin.service.update(treatment) } else { if (NSUpload.isIdValid(treatment._id)) - NSUpload.removeCareportalEntryFromNS(treatment._id) + nsUpload.removeCareportalEntryFromNS(treatment._id) else - UploadQueue.removeID("dbAdd", treatment._id) + uploadQueue.removeID("dbAdd", treatment._id) treatmentsPlugin.service.delete(treatment) } updateGui() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt index 9307238211..191957a8f3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt @@ -38,6 +38,8 @@ class TreatmentsCareportalFragment : DaggerFragment() { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var translator: Translator + @Inject lateinit var nsUpload: NSUpload + @Inject lateinit var uploadQueue: UploadQueue @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, @@ -66,9 +68,9 @@ class TreatmentsCareportalFragment : DaggerFragment() { val careportalEvent = events[i] if (careportalEvent.json.contains(resourceHelper.gs(R.string.androidaps_start))) { if (NSUpload.isIdValid(careportalEvent._id)) - NSUpload.removeCareportalEntryFromNS(careportalEvent._id) + nsUpload.removeCareportalEntryFromNS(careportalEvent._id) else - UploadQueue.removeID("dbAdd", careportalEvent._id) + uploadQueue.removeID("dbAdd", careportalEvent._id) MainApp.getDbHelper().delete(careportalEvent) } } @@ -136,9 +138,9 @@ class TreatmentsCareportalFragment : DaggerFragment() { resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(careportalEvent.date) OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable { if (NSUpload.isIdValid(careportalEvent._id)) - NSUpload.removeCareportalEntryFromNS(careportalEvent._id) + nsUpload.removeCareportalEntryFromNS(careportalEvent._id) else - UploadQueue.removeID("dbAdd", careportalEvent._id) + uploadQueue.removeID("dbAdd", careportalEvent._id) MainApp.getDbHelper().delete(careportalEvent) }, null) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsExtendedBolusesFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsExtendedBolusesFragment.kt index d2dcd632ea..91e3b098fc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsExtendedBolusesFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsExtendedBolusesFragment.kt @@ -40,6 +40,8 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() { @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var fabricPrivacy: FabricPrivacy + @Inject lateinit var nsUpload: NSUpload + @Inject lateinit var uploadQueue: UploadQueue @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, @@ -116,8 +118,8 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() { ${resourceHelper.gs(R.string.date)}: ${dateUtil.dateAndTimeString(extendedBolus.date)} """.trimIndent(), DialogInterface.OnClickListener { _: DialogInterface, _: Int -> val id = extendedBolus._id - if (NSUpload.isIdValid(id)) NSUpload.removeCareportalEntryFromNS(id) - else UploadQueue.removeID("dbAdd", id) + if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id) + else uploadQueue.removeID("dbAdd", id) MainApp.getDbHelper().delete(extendedBolus) }, null) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt index 77934e304c..886c0ec34e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt @@ -43,6 +43,8 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() { @Inject lateinit var localProfilePlugin: LocalProfilePlugin @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var fabricPrivacy: FabricPrivacy + @Inject lateinit var nsUpload: NSUpload + @Inject lateinit var uploadQueue: UploadQueue @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, @@ -135,8 +137,8 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() { resourceHelper.gs(R.string.careportal_profileswitch) + ": " + profileSwitch.profileName + "\n" + resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(profileSwitch.date), Runnable { val id = profileSwitch._id - if (NSUpload.isIdValid(id)) NSUpload.removeCareportalEntryFromNS(id) - else UploadQueue.removeID("dbAdd", id) + if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id) + else uploadQueue.removeID("dbAdd", id) MainApp.getDbHelper().delete(profileSwitch) }) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.java index 7df7db72be..980e9efe7d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.java @@ -47,6 +47,8 @@ public class TreatmentsTempTargetFragment extends DaggerFragment { @Inject RxBusWrapper rxBus; @Inject ProfileFunction profileFunction; @Inject ResourceHelper resourceHelper; + @Inject NSUpload nsUpload; + @Inject UploadQueue uploadQueue; @Inject FabricPrivacy fabricPrivacy; @Inject DateUtil dateUtil; @@ -146,9 +148,9 @@ public class TreatmentsTempTargetFragment extends DaggerFragment { (dialog, id) -> { final String _id = tempTarget._id; if (NSUpload.isIdValid(_id)) { - NSUpload.removeCareportalEntryFromNS(_id); + nsUpload.removeCareportalEntryFromNS(_id); } else { - UploadQueue.removeID("dbAdd", _id); + uploadQueue.removeID("dbAdd", _id); } MainApp.getDbHelper().delete(tempTarget); }, null); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTemporaryBasalsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTemporaryBasalsFragment.kt index 4ff6b15950..8b8aee6b91 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTemporaryBasalsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTemporaryBasalsFragment.kt @@ -44,6 +44,8 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() { @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var profileFunction: ProfileFunction + @Inject lateinit var nsUpload: NSUpload + @Inject lateinit var uploadQueue: UploadQueue @Inject lateinit var dateUtil: DateUtil override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, @@ -165,8 +167,8 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() { """.trimIndent(), DialogInterface.OnClickListener { _: DialogInterface?, _: Int -> val id = tempBasal._id - if (NSUpload.isIdValid(id)) NSUpload.removeCareportalEntryFromNS(id) - else UploadQueue.removeID("dbAdd", id) + if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id) + else uploadQueue.removeID("dbAdd", id) MainApp.getDbHelper().delete(tempBasal) }, null) } diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt index a3dda44325..b6705ac733 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt @@ -8,15 +8,16 @@ import android.content.Intent import android.os.PowerManager import android.os.SystemClock import dagger.android.DaggerBroadcastReceiver +import info.nightscout.androidaps.BuildConfig import info.nightscout.androidaps.Config import info.nightscout.androidaps.events.EventProfileNeedsUpdate import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider +import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.queue.commands.Command @@ -39,6 +40,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var receiverStatusStore: ReceiverStatusStore @Inject lateinit var config: Config + @Inject lateinit var nsUpload: NSUpload @Inject lateinit var dateUtil: DateUtil companion object { @@ -108,7 +110,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { else if (DateUtil.isOlderThan(activePlugin.activeAPS.lastAPSRun, 5)) shouldUploadStatus = true if (DateUtil.isOlderThan(lastIobUpload, IOB_UPDATE_FREQUENCY) && shouldUploadStatus) { lastIobUpload = DateUtil.now() - NSUpload.uploadDeviceStatus(loopPlugin, iobCobCalculatorPlugin, profileFunction, activePlugin.activePump, receiverStatusStore) + nsUpload.uploadDeviceStatus(loopPlugin, iobCobCalculatorPlugin, profileFunction, activePlugin.activePump, receiverStatusStore, BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION) } } diff --git a/app/src/main/java/info/nightscout/androidaps/services/DataService.java b/app/src/main/java/info/nightscout/androidaps/services/DataService.java index 83891275a2..cf1833e892 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/services/DataService.java @@ -20,6 +20,7 @@ import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.BundleLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.nsclient.data.NSMbg; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; @@ -42,6 +43,7 @@ public class DataService extends DaggerIntentService { @Inject AAPSLogger aapsLogger; @Inject SP sp; @Inject RxBusWrapper rxBus; + @Inject NSUpload nsUpload; @Inject SmsCommunicatorPlugin smsCommunicatorPlugin; @Inject DexcomPlugin dexcomPlugin; @Inject EversensePlugin eversensePlugin; @@ -210,7 +212,7 @@ public class DataService extends DaggerIntentService { } else if (eventType.equals(CareportalEvent.COMBOBOLUS)) { MainApp.getDbHelper().createExtendedBolusFromJsonIfNotExists(json); } else if (eventType.equals(CareportalEvent.PROFILESWITCH)) { - MainApp.getDbHelper().createProfileSwitchFromJsonIfNotExists(activePlugin, json); + MainApp.getDbHelper().createProfileSwitchFromJsonIfNotExists(activePlugin, nsUpload, json); } else if (eventType.equals(CareportalEvent.SITECHANGE) || eventType.equals(CareportalEvent.INSULINCHANGE) || eventType.equals(CareportalEvent.SENSORCHANGE) || diff --git a/app/src/main/java/info/nightscout/androidaps/utils/HardLimits.kt b/app/src/main/java/info/nightscout/androidaps/utils/HardLimits.kt index c9e2835ceb..bec9c0fa16 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/HardLimits.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/HardLimits.kt @@ -12,11 +12,12 @@ import javax.inject.Singleton @Singleton class HardLimits @Inject constructor( - val aapsLogger: AAPSLogger, - val rxBus: RxBusWrapper, - val sp: SP, - val resourceHelper: ResourceHelper, - val context: Context + private val aapsLogger: AAPSLogger, + private val rxBus: RxBusWrapper, + private val sp: SP, + private val resourceHelper: ResourceHelper, + private val context: Context, + private val nsUpload: NSUpload ) { val CHILD = 0 @@ -90,7 +91,7 @@ class HardLimits @Inject constructor( msg += ".\n" msg += String.format(resourceHelper.gs(R.string.valuelimitedto), value, newvalue) aapsLogger.error(msg) - NSUpload.uploadError(msg) + nsUpload.uploadError(msg) ToastUtils.showToastInUiThread(context, rxBus, msg, R.raw.error) } return newvalue diff --git a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt index eff444aa6e..f5ac9d64ce 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt @@ -31,6 +31,7 @@ class LocalAlertUtils @Inject constructor( private val profileFunction: ProfileFunction, private val iobCobCalculatorPlugin: IobCobCalculatorPlugin, private val config: Config, + private val nsUpload: NSUpload, private val dateUtil: DateUtil ) { @@ -53,7 +54,7 @@ class LocalAlertUtils @Inject constructor( sp.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + pumpUnreachableThreshold()) rxBus.send(EventNewNotification(n)) if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) { - NSUpload.uploadError(n.text) + nsUpload.uploadError(n.text) } } if (!isStatusOutdated && !alarmTimeoutExpired) rxBus.send(EventDismissNotification(Notification.PUMP_UNREACHABLE)) @@ -101,7 +102,7 @@ class LocalAlertUtils @Inject constructor( sp.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + missedReadingsThreshold()) rxBus.send(EventNewNotification(n)) if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) { - NSUpload.uploadError(n.text) + nsUpload.uploadError(n.text) } } } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/stats/TddCalculator.kt b/app/src/main/java/info/nightscout/androidaps/utils/stats/TddCalculator.kt index 6ee3024fc6..1e567dd94a 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/stats/TddCalculator.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/stats/TddCalculator.kt @@ -11,6 +11,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.treatments.TreatmentService import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.DateUtil @@ -32,8 +33,9 @@ class TddCalculator @Inject constructor( val activePlugin: ActivePluginProvider, val profileFunction: ProfileFunction, fabricPrivacy: FabricPrivacy, + nsUpload: NSUpload, private val dateUtil: DateUtil -) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, activePlugin, fabricPrivacy, dateUtil) { +) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil) { init { service = TreatmentService(injector) // plugin is not started diff --git a/app/src/main/res/layout/okcancel.xml b/app/src/main/res/layout/okcancel.xml new file mode 100644 index 0000000000..f1322fd566 --- /dev/null +++ b/app/src/main/res/layout/okcancel.xml @@ -0,0 +1,44 @@ + + + + +