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 0000000000..641efb745b Binary files /dev/null and b/app/src/main/jniLibs/arm64-v8a/libBleEncryption.so differ 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 0000000000..560c7a8905 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libBleEncryption.so differ diff --git a/app/src/main/jniLibs/x86/libBleEncryption.so b/app/src/main/jniLibs/x86/libBleEncryption.so new file mode 100644 index 0000000000..59487f74cf Binary files /dev/null and b/app/src/main/jniLibs/x86/libBleEncryption.so differ diff --git a/app/src/main/jniLibs/x86_64/libBleEncryption.so b/app/src/main/jniLibs/x86_64/libBleEncryption.so new file mode 100644 index 0000000000..53a606a968 Binary files /dev/null and b/app/src/main/jniLibs/x86_64/libBleEncryption.so differ 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