From ed6cabe7fa0c596b9b4976515d200be92b7fc9a1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 13 Sep 2017 00:35:03 +0200 Subject: [PATCH 001/112] initial RS work --- app/build.gradle | 4 + app/src/main/AndroidManifest.xml | 11 + .../com/cozmo/danar/util/BleCommandUtil.java | 116 +++ .../info/nightscout/androidaps/Config.java | 2 +- .../info/nightscout/androidaps/MainApp.java | 6 +- .../androidaps/PreferencesActivity.java | 9 +- .../plugins/PumpDanaR/DanaRPump.java | 24 + .../plugins/PumpDanaRS/DanaRSPlugin.java | 765 ++++++++++++++++++ .../activities/BLEScanActivity.java | 232 ++++++ .../activities/PairingHelperActivity.java | 15 + .../activities/PairingProgressDialog.java | 148 ++++ .../comm/DanaRSMessageHashTable.java | 103 +++ .../PumpDanaRS/comm/DanaRS_Packet.java | 383 +++++++++ ...S_Packet_Basal_Cancel_Temporary_Basal.java | 36 + .../DanaRS_Packet_Basal_Get_Basal_Rate.java | 55 ++ ...S_Packet_Basal_Get_Profile_Basal_Rate.java | 61 ++ ...anaRS_Packet_Basal_Get_Profile_Number.java | 37 + .../DanaRS_Packet_Basal_Set_Basal_Rate.java | 53 ++ ...S_Packet_Basal_Set_Profile_Basal_Rate.java | 56 ++ ...anaRS_Packet_Basal_Set_Profile_Number.java | 48 ++ .../DanaRS_Packet_Basal_Set_Suspend_Off.java | 35 + .../DanaRS_Packet_Basal_Set_Suspend_On.java | 35 + ...naRS_Packet_Basal_Set_Temporary_Basal.java | 52 ++ ...RS_Packet_Basal_Temporary_Basal_State.java | 77 ++ .../DanaRS_Packet_Bolus_Get_Bolus_Option.java | 124 +++ .../DanaRS_Packet_Bolus_Get_CIR_CF_Array.java | 145 ++++ ...ket_Bolus_Get_Calculation_Information.java | 77 ++ ..._Carbohydrate_Calculation_Information.java | 47 ++ .../DanaRS_Packet_Bolus_Get_Dual_Bolus.java | 55 ++ ...anaRS_Packet_Bolus_Get_Extended_Bolus.java | 52 ++ ...Packet_Bolus_Get_Extended_Bolus_State.java | 62 ++ ..._Bolus_Get_Extended_Menu_Option_State.java | 42 + ...DanaRS_Packet_Bolus_Get_Initial_Bolus.java | 46 ++ ...cket_Bolus_Get_Step_Bolus_Information.java | 72 ++ .../DanaRS_Packet_Bolus_Set_Bolus_Option.java | 127 +++ .../DanaRS_Packet_Bolus_Set_CIR_CF_Array.java | 100 +++ .../DanaRS_Packet_Bolus_Set_Dual_Bolus.java | 60 ++ ...anaRS_Packet_Bolus_Set_Extended_Bolus.java | 56 ++ ...acket_Bolus_Set_Extended_Bolus_Cancel.java | 35 + ...DanaRS_Packet_Bolus_Set_Initial_Bolus.java | 60 ++ ...aRS_Packet_Bolus_Set_Step_Bolus_Start.java | 62 ++ ...naRS_Packet_Bolus_Set_Step_Bolus_Stop.java | 60 ++ .../DanaRS_Packet_Etc_Keep_Connection.java | 32 + .../DanaRS_Packet_Etc_Set_History_Save.java | 71 ++ ...DanaRS_Packet_General_Delivery_Status.java | 32 + ...S_Packet_General_Get_More_Information.java | 70 ++ .../DanaRS_Packet_General_Get_Password.java | 36 + .../DanaRS_Packet_General_Get_Pump_Check.java | 45 ++ ...cket_General_Get_Shipping_Information.java | 46 ++ ...cket_General_Get_Today_Delivery_Total.java | 47 ++ ...ket_General_Get_User_Time_Change_Flag.java | 32 + ...et_General_Initial_Screen_Information.java | 85 ++ ...acket_General_Set_History_Upload_Mode.java | 47 ++ ...neral_Set_User_Time_Change_Flag_Clear.java | 33 + .../comm/DanaRS_Packet_History_.java | 124 +++ .../comm/DanaRS_Packet_History_Alarm.java | 23 + .../DanaRS_Packet_History_All_History.java | 23 + .../comm/DanaRS_Packet_History_Basal.java | 23 + .../DanaRS_Packet_History_Blood_Glucose.java | 23 + .../comm/DanaRS_Packet_History_Bolus.java | 23 + .../DanaRS_Packet_History_Carbohydrate.java | 23 + .../comm/DanaRS_Packet_History_Daily.java | 23 + .../comm/DanaRS_Packet_History_Prime.java | 23 + .../comm/DanaRS_Packet_History_Refill.java | 23 + .../comm/DanaRS_Packet_History_Suspend.java | 23 + .../comm/DanaRS_Packet_History_Temporary.java | 23 + .../comm/DanaRS_Packet_Notify_Alarm.java | 88 ++ ...anaRS_Packet_Notify_Delivery_Complete.java | 54 ++ ...S_Packet_Notify_Delivery_Rate_Display.java | 56 ++ ...naRS_Packet_Notify_Missed_Bolus_Alarm.java | 54 ++ .../DanaRS_Packet_Option_Get_Pump_Time.java | 61 ++ .../DanaRS_Packet_Option_Get_User_Option.java | 114 +++ .../DanaRS_Packet_Option_Set_Pump_Time.java | 56 ++ .../DanaRS_Packet_Option_Set_User_Option.java | 58 ++ .../comm/DanaRS_Packet_Review_Bolus_Avg.java | 52 ++ .../events/EventDanaRSConnection.java | 21 + .../events/EventDanaRSDeviceChange.java | 8 + .../PumpDanaRS/events/EventDanaRSPacket.java | 15 + .../events/EventDanaRSPairingSuccess.java | 8 + .../PumpDanaRS/services/DanaRSService.java | 671 +++++++++++++++ .../plugins/PumpDanaRv2/DanaRv2Plugin.java | 2 +- .../jniLibs/arm64-v8a/libBleCommandUtil.so | Bin 0 -> 14000 bytes .../jniLibs/armeabi-v7a/libBleCommandUtil.so | Bin 0 -> 13728 bytes .../main/jniLibs/armeabi/libBleCommandUtil.so | Bin 0 -> 13724 bytes .../main/jniLibs/mips/libBleCommandUtil.so | Bin 0 -> 71484 bytes .../main/jniLibs/mips64/libBleCommandUtil.so | Bin 0 -> 14808 bytes app/src/main/jniLibs/x86/libBleCommandUtil.so | Bin 0 -> 13668 bytes .../main/jniLibs/x86_64/libBleCommandUtil.so | Bin 0 -> 14272 bytes .../res/layout/danars_blescanner_activity.xml | 22 + .../res/layout/danars_blescanner_item.xml | 33 + .../layout/danars_pairingprogressdialog.xml | 41 + app/src/main/res/values/strings.xml | 15 + app/src/main/res/xml/pref_danars.xml | 26 + 93 files changed, 6049 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/com/cozmo/danar/util/BleCommandUtil.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/BLEScanActivity.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingHelperActivity.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingProgressDialog.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRSMessageHashTable.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Cancel_Temporary_Basal.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Temporary_Basal_State.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Keep_Connection.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Set_History_Save.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Delivery_Status.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_More_Information.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Password.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Alarm.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_All_History.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Basal.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Blood_Glucose.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Bolus.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Carbohydrate.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Daily.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Prime.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Refill.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Suspend.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Temporary.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Alarm.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_User_Option.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_User_Option.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Review_Bolus_Avg.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSConnection.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSDeviceChange.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPacket.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPairingSuccess.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java create mode 100644 app/src/main/jniLibs/arm64-v8a/libBleCommandUtil.so create mode 100644 app/src/main/jniLibs/armeabi-v7a/libBleCommandUtil.so create mode 100644 app/src/main/jniLibs/armeabi/libBleCommandUtil.so create mode 100644 app/src/main/jniLibs/mips/libBleCommandUtil.so create mode 100644 app/src/main/jniLibs/mips64/libBleCommandUtil.so create mode 100644 app/src/main/jniLibs/x86/libBleCommandUtil.so create mode 100644 app/src/main/jniLibs/x86_64/libBleCommandUtil.so create mode 100644 app/src/main/res/layout/danars_blescanner_activity.xml create mode 100644 app/src/main/res/layout/danars_blescanner_item.xml create mode 100644 app/src/main/res/layout/danars_pairingprogressdialog.xml create mode 100644 app/src/main/res/xml/pref_danars.xml diff --git a/app/build.gradle b/app/build.gradle index 8d62dbe7f3..9631b4c5c0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,6 +47,10 @@ android { version "1.52" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", generateGitBuild() + + ndk { + moduleName "BleCommandUtil" + } } lintOptions { disable 'MissingTranslation' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7d792556b7..0c23c1ee23 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -50,6 +50,13 @@ + + + + + + + + diff --git a/app/src/main/java/com/cozmo/danar/util/BleCommandUtil.java b/app/src/main/java/com/cozmo/danar/util/BleCommandUtil.java new file mode 100644 index 0000000000..65be0a57f4 --- /dev/null +++ b/app/src/main/java/com/cozmo/danar/util/BleCommandUtil.java @@ -0,0 +1,116 @@ +package com.cozmo.danar.util; + +import android.content.Context; + +import info.nightscout.androidaps.MainApp; + +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; + public static final int DANAR_PACKET__TYPE_RESPONSE = 0xB2; + 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__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; + + public static final int DANAR_PACKET__OPCODE_NOTIFY__DELIVERY_COMPLETE = 0x01; + public static final int DANAR_PACKET__OPCODE_NOTIFY__DELIVERY_RATE_DISPLAY = 0x02; + public static final int DANAR_PACKET__OPCODE_NOTIFY__ALARM = 0x03; + public static final int DANAR_PACKET__OPCODE_NOTIFY__MISSED_BOLUS_ALARM = 0x04; + + public static final int DANAR_PACKET__OPCODE_REVIEW__INITIAL_SCREEN_INFORMATION = 0x02; + public static final int DANAR_PACKET__OPCODE_REVIEW__DELIVERY_STATUS = 0x03; + public static final int DANAR_PACKET__OPCODE_REVIEW__GET_PASSWORD = 0x04; + + public static final int DANAR_PACKET__OPCODE_REVIEW__BOLUS_AVG = 0x10; + public static final int DANAR_PACKET__OPCODE_REVIEW__BOLUS = 0x11; + public static final int DANAR_PACKET__OPCODE_REVIEW__DAILY = 0x12; + public static final int DANAR_PACKET__OPCODE_REVIEW__PRIME = 0x13; + public static final int DANAR_PACKET__OPCODE_REVIEW__REFILL = 0x14; + public static final int DANAR_PACKET__OPCODE_REVIEW__BLOOD_GLUCOSE = 0x15; + public static final int DANAR_PACKET__OPCODE_REVIEW__CARBOHYDRATE = 0x16; + public static final int DANAR_PACKET__OPCODE_REVIEW__TEMPORARY = 0x17; + public static final int DANAR_PACKET__OPCODE_REVIEW__SUSPEND = 0x18; + public static final int DANAR_PACKET__OPCODE_REVIEW__ALARM = 0x19; + public static final int DANAR_PACKET__OPCODE_REVIEW__BASAL = 0x1A; + public static final int DANAR_PACKET__OPCODE_REVIEW__ALL_HISTORY = 0x1F; + public static final int DANAR_PACKET__OPCODE_REVIEW__GET_SHIPPING_INFORMATION = 0x20; + public static final int DANAR_PACKET__OPCODE_REVIEW__GET_PUMP_CHECK = 0x21; + public static final int DANAR_PACKET__OPCODE_REVIEW__GET_USER_TIME_CHANGE_FLAG = 0x22; + public static final int DANAR_PACKET__OPCODE_REVIEW__SET_USER_TIME_CHANGE_FLAG_CLEAR = 0x23; + public static final int DANAR_PACKET__OPCODE_REVIEW__GET_MORE_INFORMATION = 0x24; + public static final int DANAR_PACKET__OPCODE_REVIEW__SET_HISTORY_UPLOAD_MODE = 0x25; + public static final int DANAR_PACKET__OPCODE_REVIEW__GET_TODAY_DELIVERY_TOTAL = 0x26; + + public static final int DANAR_PACKET__OPCODE_BOLUS__GET_STEP_BOLUS_INFORMATION = 0x40; + public static final int DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_BOLUS_STATE = 0x41; + public static final int DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_BOLUS = 0x42; + public static final int DANAR_PACKET__OPCODE_BOLUS__GET_DUAL_BOLUS = 0x43; + public static final int DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_STOP = 0x44; + public static final int DANAR_PACKET__OPCODE_BOLUS__GET_CARBOHYDRATE_CALCULATION_INFORMATION = 0x45; + public static final int DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_MENU_OPTION_STATE = 0x46; + public static final int DANAR_PACKET__OPCODE_BOLUS__SET_EXTENDED_BOLUS = 0x47; + public static final int DANAR_PACKET__OPCODE_BOLUS__SET_DUAL_BOLUS = 0x48; + public static final int DANAR_PACKET__OPCODE_BOLUS__SET_EXTENDED_BOLUS_CANCEL = 0x49; + public static final int DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_START = 0x4A; + public static final int DANAR_PACKET__OPCODE_BOLUS__GET_CALCULATION_INFORMATION = 0x4B; + public static final int DANAR_PACKET__OPCODE_BOLUS__GET_BOLUS_RATE = 0x4C; + public static final int DANAR_PACKET__OPCODE_BOLUS__SET_BOLUS_RATE = 0x4D; + public static final int DANAR_PACKET__OPCODE_BOLUS__GET_CIR_CF_ARRAY = 0x4E; + public static final int DANAR_PACKET__OPCODE_BOLUS__SET_CIR_CF_ARRAY = 0x4F; + public static final int DANAR_PACKET__OPCODE_BOLUS__GET_BOLUS_OPTION = 0x50; + public static final int DANAR_PACKET__OPCODE_BOLUS__SET_BOLUS_OPTION = 0x51; + + public static final int DANAR_PACKET__OPCODE_BASAL__SET_TEMPORARY_BASAL = 0x60; + public static final int DANAR_PACKET__OPCODE_BASAL__TEMPORARY_BASAL_STATE = 0x61; + public static final int DANAR_PACKET__OPCODE_BASAL__CANCEL_TEMPORARY_BASAL = 0x62; + public static final int DANAR_PACKET__OPCODE_BASAL__GET_PROFILE_NUMBER = 0x63; + public static final int DANAR_PACKET__OPCODE_BASAL__SET_PROFILE_NUMBER = 0x64; + public static final int DANAR_PACKET__OPCODE_BASAL__GET_PROFILE_BASAL_RATE = 0x65; + public static final int DANAR_PACKET__OPCODE_BASAL__SET_PROFILE_BASAL_RATE = 0x66; + public static final int DANAR_PACKET__OPCODE_BASAL__GET_BASAL_RATE = 0x67; + public static final int DANAR_PACKET__OPCODE_BASAL__SET_BASAL_RATE = 0x68; + public static final int DANAR_PACKET__OPCODE_BASAL__SET_SUSPEND_ON = 0x69; + public static final int DANAR_PACKET__OPCODE_BASAL__SET_SUSPEND_OFF = 0x6A; + + public static final int DANAR_PACKET__OPCODE_OPTION__GET_PUMP_TIME = 0x70; + public static final int DANAR_PACKET__OPCODE_OPTION__SET_PUMP_TIME = 0x71; + public static final int DANAR_PACKET__OPCODE_OPTION__GET_USER_OPTION = 0x72; + public static final int DANAR_PACKET__OPCODE_OPTION__SET_USER_OPTION = 0x73; + + 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"); + } + + private static native byte[] getEncryptedPacketJni(Object context, int opcode, byte[] bytes, String deviceName); + + private static native byte[] getDecryptedPacketJni(Object context, byte[] bytes); + + // --------------------------------------------------------- + + private static BleCommandUtil mInstance = null; + + public static BleCommandUtil getInstance() { + if (mInstance == null) { + mInstance = new BleCommandUtil(); + } + return mInstance; + } + + // --------------------------------------------------------- + + public byte[] getEncryptedPacket(int opcode, byte[] bytes, String deviceName) { + return getEncryptedPacketJni(MainApp.instance().getApplicationContext(), opcode, bytes, deviceName); + } + + public byte[] getDecryptedPacket(byte[] bytes) { + return getDecryptedPacketJni(MainApp.instance().getApplicationContext(), bytes); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/Config.java b/app/src/main/java/info/nightscout/androidaps/Config.java index e6c06583c9..98b735feae 100644 --- a/app/src/main/java/info/nightscout/androidaps/Config.java +++ b/app/src/main/java/info/nightscout/androidaps/Config.java @@ -44,6 +44,6 @@ public class Config { // DanaR specific public static final boolean logDanaBTComm = true; - public static final boolean logDanaMessageDetail = true; + public static boolean logDanaMessageDetail = true; public static final boolean logDanaSerialEngine = true; } diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index fcd92331b0..b6fd597207 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -52,6 +52,8 @@ import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService; +import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; +import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService; import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin; @@ -123,7 +125,8 @@ public class MainApp extends Application { pluginsList.add(SensitivityWeightedAveragePlugin.getPlugin()); if (Config.DANAR) pluginsList.add(DanaRPlugin.getPlugin()); if (Config.DANAR) pluginsList.add(DanaRKoreanPlugin.getPlugin()); - if (Config.DANARv2) pluginsList.add(DanaRv2Plugin.getPlugin()); + if (Config.DANAR) pluginsList.add(DanaRv2Plugin.getPlugin()); + if (Config.DANAR) pluginsList.add(DanaRSPlugin.getPlugin()); pluginsList.add(CareportalFragment.getPlugin()); if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin()); if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getInstance()); @@ -207,6 +210,7 @@ public class MainApp extends Application { startService(new Intent(this, DanaRExecutionService.class)); startService(new Intent(this, DanaRKoreanExecutionService.class)); startService(new Intent(this, DanaRv2ExecutionService.class)); + startService(new Intent(this, DanaRSService.class)); } keepAliveReceiver.setAlarm(this); } diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index c5abda1eae..6abd8d58fb 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -20,6 +20,7 @@ import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin; import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; +import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin; @@ -69,6 +70,8 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre EditTextPreference editTextPref = (EditTextPreference) pref; if (pref.getKey().contains("password") || pref.getKey().contains("secret")) { pref.setSummary("******"); + } else if (pref.getKey().equals(MainApp.sResources.getString(R.string.key_danars_name))) { + pref.setSummary(SP.getString(R.string.key_danars_name,"")); } else if (editTextPref.getText() != null && !editTextPref.getText().equals("")) { ((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage()); pref.setSummary(editTextPref.getText()); @@ -126,12 +129,16 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre DanaRPlugin danaRPlugin = MainApp.getSpecificPlugin(DanaRPlugin.class); DanaRKoreanPlugin danaRKoreanPlugin = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class); DanaRv2Plugin danaRv2Plugin = MainApp.getSpecificPlugin(DanaRv2Plugin.class); + DanaRSPlugin danaRSPlugin = MainApp.getSpecificPlugin(DanaRSPlugin.class); if (danaRPlugin.isEnabled(PluginBase.PUMP) || danaRKoreanPlugin.isEnabled(PluginBase.PUMP)) { addPreferencesFromResource(R.xml.pref_danar); } if (danaRv2Plugin != null && danaRv2Plugin.isEnabled(PluginBase.PUMP)) { addPreferencesFromResource(R.xml.pref_danarv2); } + if (danaRSPlugin != null && danaRSPlugin.isEnabled(PluginBase.PUMP)) { + addPreferencesFromResource(R.xml.pref_danars); + } if (danaRPlugin.isEnabled(PluginBase.PROFILE) || danaRKoreanPlugin.isEnabled(PluginBase.PROFILE) || danaRv2Plugin != null && danaRv2Plugin.isEnabled(PluginBase.PROFILE)) { addPreferencesFromResource(R.xml.pref_danarprofile); } @@ -141,7 +148,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre addPreferencesFromResource(R.xml.pref_virtualpump); } InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin = MainApp.getSpecificPlugin(InsulinOrefFreePeakPlugin.class); - if(insulinOrefFreePeakPlugin.isEnabled(PluginBase.INSULIN)){ + if (insulinOrefFreePeakPlugin.isEnabled(PluginBase.INSULIN)) { addPreferencesFromResource(R.xml.pref_insulinoreffreepeak); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java index 7948d00d96..021b4d7a3d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java @@ -78,6 +78,8 @@ public class DanaRPump { public boolean pumpSuspended; public boolean calculatorEnabled; public double dailyTotalUnits; + public double dailyTotalBolusUnits = 0; // RS only + public double dailyTotalBasalUnits = 0; // RS only public int maxDailyTotalUnits; public double bolusStep; @@ -108,6 +110,7 @@ public class DanaRPump { public int extendedBolusSoFarInMinutes; public Date extendedBolusStart; public int extendedBolusRemainingMinutes; + public double extendedBolusDeliveredSoFar; //RS only // Profile public int units; @@ -136,6 +139,27 @@ public class DanaRPump { public double maxBolus; public double maxBasal; + // DanaRS specific + + public String rs_password = ""; + + // User settings + public int timeDisplayType; + public int buttonScrollOnOff; + public int beepAndAlarm; + public int lcdOnTimeSec; + public int backlightOnTimeSec; + public int selectedLanguage; + public int shutdownHour; + public int lowReservoirRate; + public int cannulaVolume; + public int refillAmount; + + public double initialBolusAmount; + // Bolus settings + public int bolusCalculationOption; + public int missedBolusConfig; + public String getUnits() { return units == UNITS_MGDL ? Constants.MGDL : Constants.MMOL; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java new file mode 100644 index 0000000000..3b71df7d2b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -0,0 +1,765 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.os.IBinder; +import android.support.annotation.Nullable; + +import com.squareup.otto.Subscribe; + +import org.json.JSONException; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; +import java.util.Objects; + +import info.nightscout.androidaps.BuildConfig; +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.Constants; +import info.nightscout.androidaps.data.DetailedBolusInfo; +import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.data.ProfileStore; +import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.db.ExtendedBolus; +import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.interfaces.ConstraintsInterface; +import info.nightscout.androidaps.interfaces.DanaRInterface; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.ProfileInterface; +import info.nightscout.androidaps.interfaces.PumpDescription; +import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.events.EventAppExit; +import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange; +import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService; +import info.nightscout.utils.DateUtil; +import info.nightscout.utils.Round; +import info.nightscout.utils.SP; + +/** + * Created by mike on 03.09.2017. + */ + +public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface, ConstraintsInterface, ProfileInterface { + private static Logger log = LoggerFactory.getLogger(DanaRSPlugin.class); + + @Override + public int getType() { + return PluginBase.PUMP; + } + + @Override + public String getFragmentClass() { + return DanaRFragment.class.getName(); + } + + @Override + public String getName() { + return MainApp.instance().getString(R.string.danarspump); + } + + @Override + public String getNameShort() { + String name = MainApp.sResources.getString(R.string.danarspump_shortname); + if (!name.trim().isEmpty()) { + //only if translation exists + return name; + } + // use long name as fallback + return getName(); + } + + @Override + public boolean isEnabled(int type) { + if (type == PluginBase.PROFILE) return fragmentProfileEnabled && fragmentPumpEnabled; + else if (type == PluginBase.PUMP) return fragmentPumpEnabled; + else if (type == PluginBase.CONSTRAINTS) return fragmentPumpEnabled; + return false; + } + + @Override + public boolean isVisibleInTabs(int type) { + if (type == PluginBase.PROFILE || type == PluginBase.CONSTRAINTS) return false; + else if (type == PluginBase.PUMP) return fragmentPumpVisible; + return false; + } + + @Override + public boolean canBeHidden(int type) { + return true; + } + + @Override + public boolean hasFragment() { + return true; + } + + @Override + public boolean showInList(int type) { + return type == PUMP; + } + + @Override + public void setFragmentEnabled(int type, boolean fragmentEnabled) { + if (type == PluginBase.PROFILE) + this.fragmentProfileEnabled = fragmentEnabled; + else if (type == PluginBase.PUMP) + this.fragmentPumpEnabled = fragmentEnabled; + // if pump profile was enabled need to switch to another too + if (type == PluginBase.PUMP && !fragmentEnabled && this.fragmentProfileEnabled) { + setFragmentEnabled(PluginBase.PROFILE, false); + setFragmentVisible(PluginBase.PROFILE, false); + MainApp.getSpecificPlugin(NSProfilePlugin.class).setFragmentEnabled(PluginBase.PROFILE, true); + MainApp.getSpecificPlugin(NSProfilePlugin.class).setFragmentVisible(PluginBase.PROFILE, true); + } + } + + @Override + public void setFragmentVisible(int type, boolean fragmentVisible) { + if (type == PluginBase.PUMP) + this.fragmentPumpVisible = fragmentVisible; + } + + static boolean fragmentPumpEnabled = false; + static boolean fragmentProfileEnabled = false; + static boolean fragmentPumpVisible = false; + + public static DanaRSService danaRSService; + + public static String mDeviceAddress = ""; + public static String mDeviceName = ""; + + private static DanaRSPlugin plugin = null; + private static DanaRPump pump = DanaRPump.getInstance(); + public static PumpDescription pumpDescription = new PumpDescription(); + + public static DanaRSPlugin getPlugin() { + if (plugin == null) + plugin = new DanaRSPlugin(); + return plugin; + } + + DanaRSPlugin() { + Context context = MainApp.instance().getApplicationContext(); + Intent intent = new Intent(context, DanaRSService.class); + context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); + MainApp.bus().register(this); + onStatusEvent(new EventDanaRSDeviceChange()); // load device name + + pumpDescription.isBolusCapable = true; + pumpDescription.bolusStep = 0.05d; + + pumpDescription.isExtendedBolusCapable = true; + pumpDescription.extendedBolusStep = 0.05d; + pumpDescription.extendedBolusDurationStep = 30; + pumpDescription.extendedBolusMaxDuration = 8 * 60; + + pumpDescription.isTempBasalCapable = true; + pumpDescription.tempBasalStyle = PumpDescription.PERCENT; + + pumpDescription.maxTempPercent = 200; + pumpDescription.tempPercentStep = 10; + + pumpDescription.tempDurationStep = 60; + pumpDescription.tempMaxDuration = 24 * 60; + + + pumpDescription.isSetBasalProfileCapable = true; + pumpDescription.basalStep = 0.01d; + pumpDescription.basalMinimumRate = 0.04d; + + pumpDescription.isRefillingCapable = true; + } + + private ServiceConnection mConnection = new ServiceConnection() { + + public void onServiceDisconnected(ComponentName name) { + log.debug("Service is disconnected"); + danaRSService = null; + } + + public void onServiceConnected(ComponentName name, IBinder service) { + log.debug("Service is connected"); + DanaRSService.LocalBinder mLocalBinder = (DanaRSService.LocalBinder) service; + danaRSService = mLocalBinder.getServiceInstance(); + } + }; + + @SuppressWarnings("UnusedParameters") + @Subscribe + public void onStatusEvent(final EventAppExit e) { + MainApp.instance().getApplicationContext().unbindService(mConnection); + } + + @Subscribe + public void onStatusEvent(final EventDanaRSDeviceChange e) { + mDeviceAddress = SP.getString(R.string.key_danars_address, ""); + mDeviceName = SP.getString(R.string.key_danars_name, ""); + } + + public static void connect(String from) { + if (danaRSService != null && !mDeviceAddress.equals("") && !mDeviceName.equals("")) + danaRSService.connect(from, mDeviceAddress); + } + + public static boolean isConnected() { + return danaRSService != null && danaRSService.isConnected(); + } + + public static boolean isConnecting() { + return danaRSService != null && danaRSService.isConnecting(); + } + + public static void disconnect(String from) { + if (danaRSService != null) danaRSService.disconnect(from); + } + + public static void sendMessage(DanaRS_Packet message) { + if (danaRSService != null) danaRSService.sendMessage(message); + } + + // DanaR interface + + @Override + public boolean loadHistory(byte type) { + return danaRSService.loadHistory(type); + } + + // Constraints interface + + @Override + public boolean isLoopEnabled() { + return true; + } + + @Override + public boolean isClosedModeEnabled() { + return true; + } + + @Override + public boolean isAutosensModeEnabled() { + return true; + } + + @Override + public boolean isAMAModeEnabled() { + return true; + } + + @Override + public Double applyBasalConstraints(Double absoluteRate) { + double origAbsoluteRate = absoluteRate; + if (pump != null) { + if (absoluteRate > pump.maxBasal) { + absoluteRate = pump.maxBasal; + if (Config.logConstraintsChanges && origAbsoluteRate != Constants.basalAbsoluteOnlyForCheckLimit) + log.debug("Limiting rate " + origAbsoluteRate + "U/h by pump constraint to " + absoluteRate + "U/h"); + } + } + return absoluteRate; + } + + @Override + public Integer applyBasalConstraints(Integer percentRate) { + Integer origPercentRate = percentRate; + if (percentRate < 0) percentRate = 0; + if (percentRate > getPumpDescription().maxTempPercent) + percentRate = getPumpDescription().maxTempPercent; + if (!Objects.equals(percentRate, origPercentRate) && Config.logConstraintsChanges && !Objects.equals(origPercentRate, Constants.basalPercentOnlyForCheckLimit)) + log.debug("Limiting percent rate " + origPercentRate + "% to " + percentRate + "%"); + return percentRate; + } + + @Override + public Double applyBolusConstraints(Double insulin) { + double origInsulin = insulin; + if (pump != null) { + if (insulin > pump.maxBolus) { + insulin = pump.maxBolus; + if (Config.logConstraintsChanges && origInsulin != Constants.bolusOnlyForCheckLimit) + log.debug("Limiting bolus " + origInsulin + "U by pump constraint to " + insulin + "U"); + } + } + return insulin; + } + + @Override + public Integer applyCarbsConstraints(Integer carbs) { + return carbs; + } + + @Override + public Double applyMaxIOBConstraints(Double maxIob) { + return maxIob; + } + + // Profile interface + + @Nullable + @Override + public ProfileStore getProfile() { + if (pump.lastSettingsRead.getTime() == 0) + return null; // no info now + return pump.createConvertedProfile(); + } + + @Override + public String getUnits() { + return pump.getUnits(); + } + + @Override + public String getProfileName() { + return pump.createConvertedProfileName(); + } + + // Pump interface + + @Override + public boolean isInitialized() { + return pump.lastConnection.getTime() > 0; + } + + @Override + public boolean isSuspended() { + return pump.pumpSuspended; + } + + @Override + public boolean isBusy() { + if (danaRSService == null) return false; + return danaRSService.isConnected() || danaRSService.isConnecting(); + } + + @Override + public int setNewBasalProfile(Profile profile) { + if (danaRSService == null) { + log.error("setNewBasalProfile sExecutionService is null"); + return FAILED; + } + if (!isInitialized()) { + log.error("setNewBasalProfile not initialized"); + Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + return FAILED; + } else { + MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); + } + if (!danaRSService.updateBasalsInPump(profile)) { + Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + return FAILED; + } else { + MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); + MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); + return SUCCESS; + } + } + + @Override + public boolean isThisProfileSet(Profile profile) { + if (!isInitialized()) + return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS + if (pump.pumpProfiles == null) + return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS + int basalValues = pump.basal48Enable ? 48 : 24; + int basalIncrement = pump.basal48Enable ? 30 * 60 : 60 * 60; + for (int h = 0; h < basalValues; h++) { + Double pumpValue = pump.pumpProfiles[pump.activeProfile][h]; + Double profileValue = profile.getBasal((Integer) (h * basalIncrement)); + if (profileValue == null) return true; + if (Math.abs(pumpValue - profileValue) > getPumpDescription().basalStep) { + log.debug("Diff found. Hour: " + h + " Pump: " + pumpValue + " Profile: " + profileValue); + return false; + } + } + return true; + } + + @Override + public Date lastDataTime() { + return pump.lastConnection; + } + + @Override + public void refreshDataFromPump(String reason) { + if (!isConnected() && !isConnecting()) { + connect(reason); + } + } + + @Override + public double getBaseBasalRate() { + return pump.currentBasal; + } + + @Override + public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { + ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); + detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin); + if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) { + DetailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history + // v2 stores end time for bolus, we need to adjust time + // delivery speed is 12 U/min + detailedBolusInfo.date += detailedBolusInfo.insulin / 12d * 60 * 1000; + // clean carbs to prevent counting them as twice because they will picked up as another record + // I don't think it's necessary to copy DetailedBolusInfo right now for carbs records + double carbs = detailedBolusInfo.carbs; + detailedBolusInfo.carbs = 0; + int carbTime = detailedBolusInfo.carbTime; + detailedBolusInfo.carbTime = 0; + + Treatment t = new Treatment(); + boolean connectionOK = false; + if (detailedBolusInfo.insulin > 0 || carbs > 0) + connectionOK = danaRSService.bolus(detailedBolusInfo.insulin, (int) carbs, System.currentTimeMillis() + carbTime * 60 * 1000 + 1000, t); // +1000 to make the record different + PumpEnactResult result = new PumpEnactResult(); + result.success = connectionOK; + result.bolusDelivered = t.insulin; + result.carbsDelivered = detailedBolusInfo.carbs; + result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + if (Config.logPumpActions) + log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); + // remove carbs because it's get from history seprately + return result; + } else { + PumpEnactResult result = new PumpEnactResult(); + result.success = false; + result.bolusDelivered = 0d; + result.carbsDelivered = 0d; + result.comment = MainApp.instance().getString(R.string.danar_invalidinput); + log.error("deliverTreatment: Invalid input"); + return result; + } + } + + @Override + public void stopBolusDelivering() { + if (danaRSService == null) { + log.error("stopBolusDelivering sExecutionService is null"); + return; + } + danaRSService.bolusStop(); + } + + // This is called from APS + @Override + public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean force) { + // Recheck pump status if older than 30 min + if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) { + connect("setTempBasalAbsolute old data"); + } + + PumpEnactResult result = new PumpEnactResult(); + + ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); + absoluteRate = configBuilderPlugin.applyBasalConstraints(absoluteRate); + + final boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d; + final boolean doLowTemp = absoluteRate < getBaseBasalRate(); + final boolean doHighTemp = absoluteRate > getBaseBasalRate(); + + if (doTempOff) { + // If temp in progress + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + if (Config.logPumpActions) + log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)"); + return cancelTempBasal(false); + } + result.success = true; + result.enacted = false; + result.percent = 100; + result.isPercent = true; + result.isTempCancel = true; + if (Config.logPumpActions) + log.debug("setTempBasalAbsolute: doTempOff OK"); + return result; + } + + if (doLowTemp || doHighTemp) { + Integer percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue(); + if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue(); + else percentRate = Round.floorTo((double) percentRate, 10d).intValue(); + if (percentRate > 500) // Special high temp 500/15min + percentRate = 500; + // Check if some temp is already in progress + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + // Correct basal already set ? + if (MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).percentRate == percentRate) { + if (!force) { + result.success = true; + result.percent = percentRate; + result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory(); + result.enacted = false; + result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()).intValue(); + result.isPercent = true; + result.isTempCancel = false; + if (Config.logPumpActions) + log.debug("setTempBasalAbsolute: Correct temp basal already set (doLowTemp || doHighTemp)"); + return result; + } + } + } + // Convert duration from minutes to hours + if (Config.logPumpActions) + log.debug("setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)"); + // use special APS temp basal call ... 100+/15min .... 100-/30min + result = setHighTempBasalPercent(percentRate); + if (!result.success) { + log.error("setTempBasalAbsolute: Failed to set hightemp basal"); + return result; + } + if (Config.logPumpActions) + log.debug("setTempBasalAbsolute: hightemp basal set ok"); + return result; + } + // We should never end here + log.error("setTempBasalAbsolute: Internal error"); + result.success = false; + result.comment = "Internal error"; + return result; + } + + @Override + public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { + PumpEnactResult result = new PumpEnactResult(); + ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); + percent = configBuilderPlugin.applyBasalConstraints(percent); + if (percent < 0) { + result.isTempCancel = false; + result.enacted = false; + result.success = false; + result.comment = MainApp.instance().getString(R.string.danar_invalidinput); + log.error("setTempBasalPercent: Invalid input"); + return result; + } + if (percent > getPumpDescription().maxTempPercent) + percent = getPumpDescription().maxTempPercent; + if (pump.isTempBasalInProgress && pump.tempBasalPercent == percent) { + result.enacted = false; + result.success = true; + result.isTempCancel = false; + result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.duration = pump.tempBasalRemainingMin; + result.percent = pump.tempBasalPercent; + result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory(); + result.isPercent = true; + if (Config.logPumpActions) + log.debug("setTempBasalPercent: Correct value already set"); + return result; + } + int durationInHours = Math.max(durationInMinutes / 60, 1); + boolean connectionOK = danaRSService.tempBasal(percent, durationInHours); + if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) { + result.enacted = true; + result.success = true; + result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.isTempCancel = false; + result.duration = pump.tempBasalRemainingMin; + result.percent = pump.tempBasalPercent; + result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory(); + result.isPercent = true; + if (Config.logPumpActions) + log.debug("setTempBasalPercent: OK"); + return result; + } + result.enacted = false; + result.success = false; + result.comment = MainApp.instance().getString(R.string.tempbasaldeliveryerror); + log.error("setTempBasalPercent: Failed to set temp basal"); + return result; + } + + public PumpEnactResult setHighTempBasalPercent(Integer percent) { + PumpEnactResult result = new PumpEnactResult(); + boolean connectionOK = danaRSService.highTempBasal(percent); + if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) { + result.enacted = true; + result.success = true; + result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.isTempCancel = false; + result.duration = pump.tempBasalRemainingMin; + result.percent = pump.tempBasalPercent; + result.isPercent = true; + if (Config.logPumpActions) + log.debug("setHighTempBasalPercent: OK"); + return result; + } + result.enacted = false; + result.success = false; + result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); + log.error("setHighTempBasalPercent: Failed to set temp basal"); + return result; + } + + @Override + public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { + ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); + insulin = configBuilderPlugin.applyBolusConstraints(insulin); + // needs to be rounded + int durationInHalfHours = Math.max(durationInMinutes / 30, 1); + insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep * (1 + durationInHalfHours % 1)); + PumpEnactResult result = new PumpEnactResult(); + if (pump.isExtendedInProgress && Math.abs(pump.extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) { + result.enacted = false; + result.success = true; + result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.duration = pump.extendedBolusRemainingMinutes; + result.absolute = pump.extendedBolusAbsoluteRate; + result.isPercent = false; + result.isTempCancel = false; + if (Config.logPumpActions) + log.debug("setExtendedBolus: Correct extended bolus already set. Current: " + pump.extendedBolusAmount + " Asked: " + insulin); + return result; + } + boolean connectionOK = danaRSService.extendedBolus(insulin, durationInHalfHours); + if (connectionOK && pump.isExtendedInProgress && Math.abs(pump.extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) { + result.enacted = true; + result.success = true; + result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.isTempCancel = false; + result.duration = pump.extendedBolusRemainingMinutes; + result.absolute = pump.extendedBolusAbsoluteRate; + result.bolusDelivered = pump.extendedBolusAmount; + result.isPercent = false; + if (Config.logPumpActions) + log.debug("setExtendedBolus: OK"); + return result; + } + result.enacted = false; + result.success = false; + result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); + log.error("setExtendedBolus: Failed to extended bolus"); + return result; + } + + @Override + public PumpEnactResult cancelTempBasal(boolean force) { + PumpEnactResult result = new PumpEnactResult(); + if (pump.isTempBasalInProgress) { + danaRSService.tempBasalStop(); + result.enacted = true; + result.isTempCancel = true; + } + if (!pump.isTempBasalInProgress) { + result.success = true; + result.isTempCancel = true; + result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + if (Config.logPumpActions) + log.debug("cancelRealTempBasal: OK"); + return result; + } else { + result.success = false; + result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); + result.isTempCancel = true; + log.error("cancelRealTempBasal: Failed to cancel temp basal"); + return result; + } + } + + @Override + public PumpEnactResult cancelExtendedBolus() { + PumpEnactResult result = new PumpEnactResult(); + if (pump.isExtendedInProgress) { + danaRSService.extendedBolusStop(); + result.enacted = true; + result.isTempCancel = true; + } + if (!pump.isExtendedInProgress) { + result.success = true; + result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + if (Config.logPumpActions) + log.debug("cancelExtendedBolus: OK"); + return result; + } else { + result.success = false; + result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); + log.error("cancelExtendedBolus: Failed to cancel extended bolus"); + return result; + } + } + + @Override + public JSONObject getJSONStatus() { + if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) { + return null; + } + JSONObject pumpjson = new JSONObject(); + JSONObject battery = new JSONObject(); + JSONObject status = new JSONObject(); + JSONObject extended = new JSONObject(); + try { + battery.put("percent", pump.batteryRemaining); + status.put("status", pump.pumpSuspended ? "suspended" : "normal"); + status.put("timestamp", DateUtil.toISOString(pump.lastConnection)); + extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); + extended.put("PumpIOB", pump.iob); + if (pump.lastBolusTime.getTime() != 0) { + extended.put("LastBolus", pump.lastBolusTime.toLocaleString()); + extended.put("LastBolusAmount", pump.lastBolusAmount); + } + TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + if (tb != null) { + extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis())); + extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date)); + extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); + } + ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); + if (eb != null) { + extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); + extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); + extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes()); + } + extended.put("BaseBasalRate", getBaseBasalRate()); + try { + extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName()); + } catch (Exception e) { + } + + pumpjson.put("battery", battery); + pumpjson.put("status", status); + pumpjson.put("extended", extended); + pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits); + pumpjson.put("clock", DateUtil.toISOString(new Date())); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return pumpjson; + } + + @Override + public String deviceID() { + return pump.serialNumber; + } + + @Override + public PumpDescription getPumpDescription() { + return pumpDescription; + } + + @Override + public String shortStatus(boolean veryShort) { + return null; + } + + @Override + public boolean isFakingTempsByExtendedBoluses() { + return false; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/BLEScanActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/BLEScanActivity.java new file mode 100644 index 0000000000..8e973903f9 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/BLEScanActivity.java @@ -0,0 +1,232 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.activities; + +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; +import android.bluetooth.BluetoothManager; +import android.bluetooth.le.BluetoothLeScanner; +import android.bluetooth.le.ScanCallback; +import android.bluetooth.le.ScanResult; +import android.content.Context; +import android.os.Bundle; +import android.os.Handler; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange; +import info.nightscout.utils.SP; + +public class BLEScanActivity extends AppCompatActivity { + private static Logger log = LoggerFactory.getLogger(BLEScanActivity.class); + + private Context mContext = null; + + private ListView listView = null; + private ListAdapter mListAdapter = null; + private ArrayList mDevices = new ArrayList<>(); + ; + + private BluetoothAdapter mBluetoothAdapter = null; + private BluetoothLeScanner mBluetoothLeScanner = null; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.danars_blescanner_activity); + + mListAdapter = new ListAdapter(); + + listView = (ListView) findViewById(R.id.danars_blescanner_listview); + listView.setEmptyView(findViewById(R.id.danars_blescanner_nodevice)); + listView.setAdapter(mListAdapter); + + initView(); + } + + private void initView() { + mContext = getApplicationContext(); + + BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE); + mBluetoothAdapter = bluetoothManager.getAdapter(); + mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner(); + + // MIKE: test mBluetoothLeScanner for null (bt disabled) + + mListAdapter.notifyDataSetChanged(); + + } + + @Override + protected void onResume() { + super.onResume(); + + startScan(); + } + + @Override + protected void onPause() { + super.onPause(); + + stopScan(); + } + + private void startScan() { + mBluetoothLeScanner.startScan(mBleScanCallback); + } + + private void stopScan() { + mBluetoothLeScanner.stopScan(mBleScanCallback); + } + + private void addBleDevice(BluetoothDevice device) { + if (device == null || device.getName() == null || device.getName().equals("")) { + return; + } + BluetoothDeviceItem item = new BluetoothDeviceItem(device); + if (!isSNCheck(device.getName()) || mDevices.contains(item)) { + return; + } + + mDevices.add(item); + new Handler().post(new Runnable() { + public void run() { + mListAdapter.notifyDataSetChanged(); + } + }); + } + + private ScanCallback mBleScanCallback = new ScanCallback() { + @Override + public void onScanResult(int callbackType, ScanResult result) { + addBleDevice(result.getDevice()); + } + }; + + class ListAdapter extends BaseAdapter { + + @Override + public int getCount() { + return mDevices.size(); + } + + @Override + public BluetoothDeviceItem getItem(int i) { + return mDevices.get(i); + } + + @Override + public long getItemId(int i) { + return 0; + } + + @Override + public View getView(int i, View convertView, ViewGroup parent) { + View v = convertView; + ViewHolder holder; + + if (v == null) { + v = View.inflate(mContext, R.layout.danars_blescanner_item, null); + holder = new ViewHolder(v); + v.setTag(holder); + } else { + holder = (ViewHolder) v.getTag(); + } + + BluetoothDeviceItem item = getItem(i); + holder.setData(i, item); + return v; + } + + private class ViewHolder implements View.OnClickListener { + private BluetoothDeviceItem item = null; + + private TextView mName = null; + private TextView mAddress = null; + + public ViewHolder(View v) { + mName = (TextView) v.findViewById(R.id.ble_name); + mAddress = (TextView) v.findViewById(R.id.ble_address); + + v.setOnClickListener(ViewHolder.this); + } + + @Override + public void onClick(View v) { + SP.putString(R.string.key_danars_address, item.device.getAddress()); + SP.putString(R.string.key_danars_name, mName.getText().toString()); + MainApp.bus().post(new EventDanaRSDeviceChange()); + finish(); + } + + public void setData(int pos, BluetoothDeviceItem data) { + if (data != null) { + try { + String tTitle = data.device.getName(); + if (tTitle == null || tTitle.equals("")) { + tTitle = "(unknown)"; + } else if (tTitle.length() > 10) { + tTitle = tTitle.substring(0, 10); + } + mName.setText(tTitle); + + mAddress.setText(data.device.getAddress()); + + item = data; + } catch (Exception e) { + } + } + } + } + } + + // + private class BluetoothDeviceItem { + private BluetoothDevice device; + + public BluetoothDeviceItem(BluetoothDevice device) { + super(); + this.device = device; + } + + @Override + public boolean equals(Object o) { + if (device == null || o == null || !(o instanceof BluetoothDeviceItem)) { + return false; + } + BluetoothDeviceItem checkItem = (BluetoothDeviceItem) o; + if (checkItem.device == null) { + return false; + } + return stringEquals(device.getAddress(), checkItem.device.getAddress()); + } + + public boolean stringEquals(String arg1, String arg2) { + try { + return arg1.equals(arg2); + } catch (Exception e) { + return false; + } + } + } + + public static boolean isSNCheck(String sn) { + String regex = "^([a-zA-Z]{3})([0-9]{5})([a-zA-Z]{2})$"; + Pattern p = Pattern.compile(regex); + Matcher m = p.matcher(sn); + + return m.matches(); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingHelperActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingHelperActivity.java new file mode 100644 index 0000000000..c67534ac75 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingHelperActivity.java @@ -0,0 +1,15 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.activities; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; + +public class PairingHelperActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + PairingProgressDialog bolusProgressDialog = new PairingProgressDialog(); + bolusProgressDialog.setHelperActivity(this); + bolusProgressDialog.show(this.getSupportFragmentManager(), "PairingProgress"); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingProgressDialog.java new file mode 100644 index 0000000000..00cbdb4628 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingProgressDialog.java @@ -0,0 +1,148 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.activities; + + +import android.app.Activity; +import android.os.Bundle; +import android.os.Handler; +import android.os.HandlerThread; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.widget.Button; +import android.widget.ProgressBar; +import android.widget.TextView; + +import com.squareup.otto.Subscribe; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSPairingSuccess; + + +public class PairingProgressDialog extends DialogFragment implements View.OnClickListener { + + TextView statusView; + ProgressBar progressBar; + Button button; + PairingHelperActivity helperActivity; + + static int secondsPassed = 0; + public static boolean pairingEnded = false; + public static boolean running = true; + + private static Handler sHandler; + private static HandlerThread sHandlerThread; + + public PairingProgressDialog() { + super(); + // Required empty public constructor + if (sHandlerThread == null) { + sHandlerThread = new HandlerThread(PairingProgressDialog.class.getSimpleName()); + sHandlerThread.start(); + sHandler = new Handler(sHandlerThread.getLooper()); + } + secondsPassed = 0; + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.danars_pairingprogressdialog, container, false); + getDialog().setTitle(MainApp.sResources.getString(R.string.pairing)); + statusView = (TextView) view.findViewById(R.id.danars_paringprogress_status); + progressBar = (ProgressBar) view.findViewById(R.id.danars_paringprogress_progressbar); + button = (Button) view.findViewById(R.id.ok); + + progressBar.setMax(100); + progressBar.setProgress(0); + statusView.setText(MainApp.sResources.getString(R.string.waitingforpairing)); + button.setVisibility(View.GONE); + button.setOnClickListener(this); + setCancelable(false); + + sHandler.post(new Runnable() { + @Override + public void run() { + for (int i = 0; i < 20; i++) { + if (pairingEnded) { + Activity activity = getActivity(); + if (activity != null) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + progressBar.setProgress(100); + statusView.setText(R.string.pairingok); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + dismiss(); + } + }); + } else + dismiss(); + return; + } + progressBar.setProgress(i * 5); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + } + Activity activity = getActivity(); + if (activity != null) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + progressBar.setProgress(100); + statusView.setText(R.string.pairingtimedout); + button.setVisibility(View.VISIBLE); + } + }); + } + } + }); + return view; + } + + @Override + public void onResume() { + super.onResume(); + MainApp.bus().register(this); + running = true; + if (pairingEnded) dismiss(); + } + + @Override + public void dismiss() { + super.dismiss(); + if (helperActivity != null) { + helperActivity.finish(); + } + } + + @Override + public void onPause() { + super.onPause(); + MainApp.bus().unregister(this); + running = false; + } + + @Subscribe + public void onStatusEvent(final EventDanaRSPairingSuccess ev) { + pairingEnded = true; + } + + public void setHelperActivity(PairingHelperActivity activity) { + this.helperActivity = activity; + } + + @Override + public void onClick(View v) { + running = false; + dismiss(); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRSMessageHashTable.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRSMessageHashTable.java new file mode 100644 index 0000000000..fe81fe0acf --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRSMessageHashTable.java @@ -0,0 +1,103 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; + +import info.nightscout.androidaps.Config; + +/** + * Created by mike on 28.05.2016. + */ +public class DanaRSMessageHashTable { + private static Logger log = LoggerFactory.getLogger(DanaRSMessageHashTable.class); + + public static HashMap messages = null; + + static { + if (messages == null) { + boolean savedState = Config.logDanaMessageDetail; + Config.logDanaMessageDetail = false; + + messages = new HashMap<>(); + put(new DanaRS_Packet_Basal_Cancel_Temporary_Basal()); + put(new DanaRS_Packet_Basal_Get_Basal_Rate()); + put(new DanaRS_Packet_Basal_Get_Profile_Basal_Rate()); + put(new DanaRS_Packet_Basal_Get_Profile_Number()); + put(new DanaRS_Packet_Basal_Set_Basal_Rate()); + put(new DanaRS_Packet_Basal_Set_Profile_Basal_Rate()); + put(new DanaRS_Packet_Basal_Set_Profile_Number()); + put(new DanaRS_Packet_Basal_Set_Suspend_Off()); + put(new DanaRS_Packet_Basal_Set_Suspend_On()); + put(new DanaRS_Packet_Basal_Set_Temporary_Basal()); + put(new DanaRS_Packet_Basal_Temporary_Basal_State()); + put(new DanaRS_Packet_Bolus_Get_Bolus_Option()); + put(new DanaRS_Packet_Bolus_Get_Initial_Bolus()); + put(new DanaRS_Packet_Bolus_Get_Calculation_Information()); + put(new DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information()); + put(new DanaRS_Packet_Bolus_Get_CIR_CF_Array()); + put(new DanaRS_Packet_Bolus_Get_Dual_Bolus()); + put(new DanaRS_Packet_Bolus_Get_Extended_Bolus()); + put(new DanaRS_Packet_Bolus_Get_Extended_Bolus_State()); + put(new DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State()); + put(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); + put(new DanaRS_Packet_Bolus_Set_Bolus_Option()); + put(new DanaRS_Packet_Bolus_Set_Initial_Bolus()); + put(new DanaRS_Packet_Bolus_Set_CIR_CF_Array()); + put(new DanaRS_Packet_Bolus_Set_Dual_Bolus()); + put(new DanaRS_Packet_Bolus_Set_Extended_Bolus()); + put(new DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel()); + put(new DanaRS_Packet_Bolus_Set_Step_Bolus_Start()); + put(new DanaRS_Packet_Bolus_Set_Step_Bolus_Stop()); + put(new DanaRS_Packet_Etc_Keep_Connection()); + put(new DanaRS_Packet_Etc_Set_History_Save()); + put(new DanaRS_Packet_General_Delivery_Status()); + put(new DanaRS_Packet_General_Get_Password()); + put(new DanaRS_Packet_General_Initial_Screen_Information()); + put(new DanaRS_Packet_Notify_Alarm()); + put(new DanaRS_Packet_Notify_Delivery_Complete()); + put(new DanaRS_Packet_Notify_Delivery_Rate_Display()); + put(new DanaRS_Packet_Notify_Missed_Bolus_Alarm()); + put(new DanaRS_Packet_Option_Get_Pump_Time()); + put(new DanaRS_Packet_Option_Get_User_Option()); + put(new DanaRS_Packet_Option_Set_Pump_Time()); + put(new DanaRS_Packet_Option_Set_User_Option()); + //put(new DanaRS_Packet_History_()); + put(new DanaRS_Packet_History_Alarm()); + put(new DanaRS_Packet_History_All_History()); + put(new DanaRS_Packet_History_Basal()); + put(new DanaRS_Packet_History_Blood_Glucose()); + put(new DanaRS_Packet_History_Bolus()); + put(new DanaRS_Packet_Review_Bolus_Avg()); + put(new DanaRS_Packet_History_Carbohydrate()); + put(new DanaRS_Packet_History_Daily()); + put(new DanaRS_Packet_General_Get_More_Information()); + put(new DanaRS_Packet_General_Get_Pump_Check()); + put(new DanaRS_Packet_General_Get_Shipping_Information()); + put(new DanaRS_Packet_General_Get_Today_Delivery_Total()); + put(new DanaRS_Packet_General_Get_User_Time_Change_Flag()); + put(new DanaRS_Packet_History_Prime()); + put(new DanaRS_Packet_History_Refill()); + put(new DanaRS_Packet_General_Set_History_Upload_Mode()); + put(new DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear()); + put(new DanaRS_Packet_History_Suspend()); + put(new DanaRS_Packet_History_Temporary()); + + Config.logDanaMessageDetail = savedState; + } + } + + public static void put(DanaRS_Packet message) { + int command = message.getCommand(); + messages.put(command, message); + } + + public static DanaRS_Packet findMessage(Integer command) { + if (messages.containsKey(command)) { + return messages.get(command); + } else { + return new DanaRS_Packet(); + } + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet.java new file mode 100644 index 0000000000..bb865d4fb3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet.java @@ -0,0 +1,383 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import android.annotation.TargetApi; +import android.os.Build; + +import java.nio.charset.StandardCharsets; +import java.util.Date; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet { + protected static final int TYPE_START = 0; + protected static final int OPCODE_START = 1; + protected static final int DATA_START = 2; + + private boolean received; + protected int type = BleCommandUtil.DANAR_PACKET__TYPE_RESPONSE; // most of the messages, should be changed for others + protected int opCode; + + public DanaRS_Packet() { + received = false; + } + + public void setReceived() { + received = true; + } + + public boolean isReceived() { + return received; + } + + public int getType() { + return type; + } + + public int getOpCode() { + return opCode; + } + + public int getCommand() { + return ((type & 0xFF) << 8) + (opCode & 0xFF); + } + + public byte[] getRequestParams() { + return null; + }; + + // STATIC FUNCTIONS + + public static int getCommand(byte[] data) { + int type = byteArrayToInt(getBytes(data, TYPE_START, 1)); + int opCode = byteArrayToInt(getBytes(data, OPCODE_START, 1)); + return ((type & 0xFF) << 8) + (opCode & 0xFF); + } + + public void handleMessage(byte[] data) { + } + + public String getFriendlyName() { + return "UNKNOWN_PACKET"; + } + +/* + public static DanaRS_Packet parseResponse(byte[] data) { + DanaRS_Packet ret = null; + try { + + int type = byteArrayToInt(getBytes(data, TYPE_START, 1)); + int tOpCode = byteArrayToInt(getBytes(data, OPCODE_START, 1)); + if (type == BleCommandUtil.DANAR_PACKET__TYPE_NOTIFY) { + switch (tOpCode) { + // Notify + case BleCommandUtil.DANAR_PACKET__OPCODE_NOTIFY__DELIVERY_COMPLETE: + ret = new DanaRS_Packet_Notify_Delivery_Complete(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_NOTIFY__DELIVERY_RATE_DISPLAY: + ret = new DanaRS_Packet_Notify_Delivery_Rate_Display(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_NOTIFY__ALARM: + ret = new DanaRS_Packet_Notify_Alarm(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_NOTIFY__MISSED_BOLUS_ALARM: + ret = new DanaRS_Packet_Notify_Missed_Bolus_Alarm(); + break; + } + } else if (type == BleCommandUtil.DANAR_PACKET__TYPE_RESPONSE) { + switch (tOpCode) { + // Init + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__INITIAL_SCREEN_INFORMATION: + ret = new DanaRS_Packet_General_Initial_Screen_Information(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__DELIVERY_STATUS: + ret = new DanaRS_Packet_General_Delivery_Status(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_PASSWORD: + ret = new DanaRS_Packet_General_Get_Password(); + break; + + // Review + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BOLUS_AVG: + ret = new DanaRS_Packet_Review_Bolus_Avg(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BOLUS: + ret = new DanaRS_Packet_History_Bolus(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__DAILY: + ret = new DanaRS_Packet_History_Daily(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__PRIME: + ret = new DanaRS_Packet_History_Prime(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__REFILL: + ret = new DanaRS_Packet_History_Refill(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BLOOD_GLUCOSE: + ret = new DanaRS_Packet_History_Blood_Glucose(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__CARBOHYDRATE: + ret = new DanaRS_Packet_History_Carbohydrate(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__TEMPORARY: + ret = new DanaRS_Packet_History_Temporary(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SUSPEND: + ret = new DanaRS_Packet_History_Suspend(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALARM: + ret = new DanaRS_Packet_History_Alarm(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BASAL: + ret = new DanaRS_Packet_History_Basal(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALL_HISTORY: + ret = new DanaRS_Packet_History_All_History(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_SHIPPING_INFORMATION: + ret = new DanaRS_Packet_General_Get_Shipping_Information(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_PUMP_CHECK: + ret = new DanaRS_Packet_General_Get_Pump_Check(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_USER_TIME_CHANGE_FLAG: + ret = new DanaRS_Packet_General_Get_User_Time_Change_Flag(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SET_USER_TIME_CHANGE_FLAG_CLEAR: + ret = new DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_MORE_INFORMATION: + ret = new DanaRS_Packet_General_Get_More_Information(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SET_HISTORY_UPLOAD_MODE: + ret = new DanaRS_Packet_General_Set_History_Upload_Mode(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_TODAY_DELIVERY_TOTAL: + ret = new DanaRS_Packet_General_Get_Today_Delivery_Total(); + break; + + // Bolus + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_STEP_BOLUS_INFORMATION: + ret = new DanaRS_Packet_Bolus_Get_Step_Bolus_Information(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_BOLUS_STATE: + ret = new DanaRS_Packet_Bolus_Get_Extended_Bolus_State(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_BOLUS: + ret = new DanaRS_Packet_Bolus_Get_Extended_Bolus(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_DUAL_BOLUS: + ret = new DanaRS_Packet_Bolus_Get_Dual_Bolus(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_STOP: + ret = new DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_CARBOHYDRATE_CALCULATION_INFORMATION: + ret = new DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_MENU_OPTION_STATE: + ret = new DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_EXTENDED_BOLUS: + ret = new DanaRS_Packet_Bolus_Set_Extended_Bolus(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_DUAL_BOLUS: + ret = new DanaRS_Packet_Bolus_Set_Dual_Bolus(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_EXTENDED_BOLUS_CANCEL: + ret = new DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_START: + ret = new DanaRS_Packet_Bolus_Set_Step_Bolus_Start(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_CALCULATION_INFORMATION: + ret = new DanaRS_Packet_Bolus_Get_Calculation_Information(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_BOLUS_RATE: + ret = new DanaRS_Packet_Bolus_Get_Initial_Bolus(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_BOLUS_RATE: + ret = new DanaRS_Packet_Bolus_Set_Initial_Bolus(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_CIR_CF_ARRAY: + ret = new DanaRS_Packet_Bolus_Get_CIR_CF_Array(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_CIR_CF_ARRAY: + ret = new DanaRS_Packet_Bolus_Set_CIR_CF_Array(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_BOLUS_OPTION: + ret = new DanaRS_Packet_Bolus_Get_Bolus_Option(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_BOLUS_OPTION: + ret = new DanaRS_Packet_Bolus_Set_Bolus_Option(); + break; + + // Basal + case BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_TEMPORARY_BASAL: + ret = new DanaRS_Packet_Basal_Set_Temporary_Basal(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__TEMPORARY_BASAL_STATE: + ret = new DanaRS_Packet_Basal_Temporary_Basal_State(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__CANCEL_TEMPORARY_BASAL: + ret = new DanaRS_Packet_Basal_Cancel_Temporary_Basal(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__GET_PROFILE_NUMBER: + ret = new DanaRS_Packet_Basal_Get_Profile_Number(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_PROFILE_NUMBER: + ret = new DanaRS_Packet_Basal_Set_Profile_Number(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__GET_PROFILE_BASAL_RATE: + ret = new DanaRS_Packet_Basal_Get_Profile_Basal_Rate(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_PROFILE_BASAL_RATE: + ret = new DanaRS_Packet_Basal_Set_Profile_Basal_Rate(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__GET_BASAL_RATE: + ret = new DanaRS_Packet_Basal_Get_Basal_Rate(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_BASAL_RATE: + ret = new DanaRS_Packet_Basal_Set_Basal_Rate(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_SUSPEND_ON: + ret = new DanaRS_Packet_Basal_Set_Suspend_On(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_SUSPEND_OFF: + ret = new DanaRS_Packet_Basal_Set_Suspend_Off(); + break; + + // Option + case BleCommandUtil.DANAR_PACKET__OPCODE_OPTION__GET_PUMP_TIME: + ret = new DanaRS_Packet_Option_Get_Pump_Time(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_OPTION__SET_PUMP_TIME: + ret = new DanaRS_Packet_Option_Set_Pump_Time(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_OPTION__GET_USER_OPTION: + ret = new DanaRS_Packet_Option_Get_User_Option(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_OPTION__SET_USER_OPTION: + ret = new DanaRS_Packet_Option_Set_User_Option(); + break; + + // Etc + case BleCommandUtil.DANAR_PACKET__OPCODE_ETC__SET_HISTORY_SAVE: + ret = new DanaRS_Packet_Etc_Set_History_Save(); + break; + case BleCommandUtil.DANAR_PACKET__OPCODE_ETC__KEEP_CONNECTION: + ret = new DanaRS_Packet_Etc_Keep_Connection(); + break; + } + } + + } catch (Exception e) { + ret = null; + } + + return ret; + } +*/ + protected static byte[] getBytes(byte[] data, int srcStart, int srcLength) { + try { + byte[] ret = new byte[srcLength]; + + System.arraycopy(data, srcStart, ret, 0, srcLength); + + return ret; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + protected static int byteArrayToInt(byte[] b) { + int ret; + + switch (b.length) { + case 1: + ret = b[0] & 0x000000FF; + break; + case 2: + ret = ((b[1] & 0x000000FF) << 8) + (b[0] & 0x000000FF); + break; + case 3: + ret = ((b[2] & 0x000000FF) << 16) + ((b[1] & 0x000000FF) << 8) + (b[0] & 0x000000FF); + break; + case 4: + ret = ((b[3] & 0x000000FF) << 24) + ((b[2] & 0x000000FF) << 16) + ((b[1] & 0x000000FF) << 8) + (b[0] & 0x000000FF); + break; + default: + ret = -1; + break; + } + return ret; + } + + @TargetApi(Build.VERSION_CODES.KITKAT) + public static String stringFromBuff(byte[] buff, int offset, int length) { + byte[] strbuff = new byte[length]; + System.arraycopy(buff, offset, strbuff, 0, length); + return new String(strbuff, StandardCharsets.UTF_8); + } + + public static Date dateFromBuff(byte[] buff, int offset) { + Date date = + new Date( + 100 + byteArrayToInt(getBytes(buff, offset, 1)), + byteArrayToInt(getBytes(buff, offset + 1, 1)) - 1, + byteArrayToInt(getBytes(buff, offset + 2, 1)) + ); + return date; + } + + @TargetApi(Build.VERSION_CODES.KITKAT) + public static String asciiStringFromBuff(byte[] buff, int offset, int length) { + byte[] strbuff = new byte[length]; + System.arraycopy(buff, offset, strbuff, 0, length); + for (int pos = 0; pos < length; pos++) + strbuff[pos] += 65; // "A" + return new String(strbuff, StandardCharsets.UTF_8); + } + + public static String toHexString(byte[] buff) { + if (buff == null) + return ""; + + StringBuffer sb = new StringBuffer(); + + int count = 0; + for (byte element : buff) { + sb.append(String.format("%02X ", element)); + if (++count % 4 == 0) sb.append(" "); + } + + return sb.toString(); + } + + final private static char[] hexArray = "0123456789ABCDEF".toCharArray(); + + public static String bytesToHex(byte[] bytes) { + char[] hexChars = new char[bytes.length * 2]; + for (int j = 0; j < bytes.length; j++) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new String(hexChars); + } + + public static byte[] hexToBytes(String s) { + int len = s.length(); + byte[] data = new byte[len / 2]; + for (int i = 0; i < len; i += 2) { + data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + + Character.digit(s.charAt(i + 1), 16)); + } + return data; + } + + public static int ByteToInt(byte b) { + return b & 0x000000FF; + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Cancel_Temporary_Basal.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Cancel_Temporary_Basal.java new file mode 100644 index 0000000000..214284d8ef --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Cancel_Temporary_Basal.java @@ -0,0 +1,36 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Basal_Cancel_Temporary_Basal extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Cancel_Temporary_Basal.class); + + public int error; + + public DanaRS_Packet_Basal_Cancel_Temporary_Basal() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__CANCEL_TEMPORARY_BASAL; + if (Config.logDanaMessageDetail) { + log.debug("Canceling temp basal"); + } + } + + @Override + public void handleMessage(byte[] data) { + error = byteArrayToInt(getBytes(data, DATA_START, 1)); + if (Config.logDanaMessageDetail) { + log.debug("Result " + error); + } + } + + @Override + public String getFriendlyName() { + return "BASAL__CANCEL_TEMPORARY_BASAL"; + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java new file mode 100644 index 0000000000..feab29d2b5 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java @@ -0,0 +1,55 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Basal_Get_Basal_Rate extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Cancel_Temporary_Basal.class); + + + public DanaRS_Packet_Basal_Get_Basal_Rate() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__GET_BASAL_RATE; + if (Config.logDanaMessageDetail) { + log.debug("Requesting basal rates"); + } + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 2; + pump.maxBasal = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 1; + pump.basalStep = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + if (pump.pumpProfiles == null) pump.pumpProfiles = new double[4][]; + pump.pumpProfiles[pump.activeProfile] = new double[24]; + for (int i = 0, size = 24; i < size; i++) { + dataIndex += dataSize; + dataSize = 2; + pump.pumpProfiles[pump.activeProfile][i] = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + } + if (Config.logDanaMessageDetail) { + log.debug("Max basal: " + pump.maxBasal + " U"); + log.debug("Basal step: " + pump.basalStep + " U"); + for (int index = 0; index < 24; index++) + log.debug("Basal " + String.format("%02d", index) + "h: " + pump.pumpProfiles[pump.activeProfile][index]); + } + } + + @Override + public String getFriendlyName() { + return "BASAL__GET_BASAL_RATE"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.java new file mode 100644 index 0000000000..8eadb8298d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.java @@ -0,0 +1,61 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_Basal_Get_Profile_Basal_Rate extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Get_Profile_Basal_Rate.class); + + private int profileNumber; + + public DanaRS_Packet_Basal_Get_Profile_Basal_Rate() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__GET_PROFILE_BASAL_RATE; + } + + // 0 - 4 + public DanaRS_Packet_Basal_Get_Profile_Basal_Rate(int profileNumber) { + this(); + this.profileNumber = profileNumber; + if (Config.logDanaMessageDetail) { + log.debug("Requesting basal rates for profile " + profileNumber); + } + } + + @Override + public byte[] getRequestParams() { + byte[] request = new byte[1]; + request[0] = (byte) (profileNumber & 0xff); + return request; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 2; + + if (pump.pumpProfiles == null) pump.pumpProfiles = new double[4][]; + pump.pumpProfiles[profileNumber] = new double[24]; + for (int i = 0, size = 24; i < size; i++) { + pump.pumpProfiles[profileNumber][i] = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + dataIndex += dataSize; + dataSize = 2; + } + if (Config.logDanaMessageDetail) { + for (int index = 0; index < 24; index++) + log.debug("Basal " + String.format("%02d", index) + "h: " + pump.pumpProfiles[profileNumber][index]); + } + } + + @Override + public String getFriendlyName() { + return "BASAL__GET_PROFILE_BASAL_RATE"; + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.java new file mode 100644 index 0000000000..39e230a29e --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.java @@ -0,0 +1,37 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_Basal_Get_Profile_Number extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Get_Profile_Number.class); + + public DanaRS_Packet_Basal_Get_Profile_Number() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__GET_PROFILE_NUMBER; + if (Config.logDanaMessageDetail) { + log.debug("Requesting active profile"); + } + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 1; + pump.activeProfile = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + if (Config.logDanaMessageDetail) { + log.debug("Active profile: " + pump.activeProfile); + } + } + + @Override + public String getFriendlyName() { + return "BASAL__GET_PROFILE_NUMBER"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.java new file mode 100644 index 0000000000..6f56464c51 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.java @@ -0,0 +1,53 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Basal_Set_Basal_Rate extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Basal_Rate.class); + + private double[] profileBasalRate; + public int error; + + public DanaRS_Packet_Basal_Set_Basal_Rate() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_BASAL_RATE; + } + + public DanaRS_Packet_Basal_Set_Basal_Rate(double[] profileBasalRate) { + this(); + this.profileBasalRate = profileBasalRate; + if (Config.logDanaMessageDetail) { + log.debug("Setting new basal rates"); + } + } + + @Override + public byte[] getRequestParams() { + byte[] request = new byte[48]; + for (int i = 0, size = 24; i < size; i++) { + int rate = (int) (profileBasalRate[i] * 100d); + request[0 + (i * 2)] = (byte) (rate & 0xff); + request[1 + (i * 2)] = (byte) ((rate >>> 8) & 0xff); + } + return request; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + } + } + + @Override + public String getFriendlyName() { + return "BASAL__SET_BASAL_RATE"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.java new file mode 100644 index 0000000000..82a63f0ca7 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.java @@ -0,0 +1,56 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Basal_Set_Profile_Basal_Rate extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Profile_Basal_Rate.class); + + private int profileNumber; // 0 - 4 + private double[] profileBasalRate; + public int error; + + public DanaRS_Packet_Basal_Set_Profile_Basal_Rate() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_PROFILE_BASAL_RATE; + } + + public DanaRS_Packet_Basal_Set_Profile_Basal_Rate(int profileNumber, double[] profileBasalRate) { + this(); + this.profileNumber = profileNumber; + this.profileBasalRate = profileBasalRate; + if (Config.logDanaMessageDetail) { + log.debug("Setting new basal rates for profile " + profileNumber); + } + } + + @Override + public byte[] getRequestParams() { + byte[] request = new byte[49]; + request[0] = (byte) (profileNumber & 0xff); + for (int i = 0, size = 24; i < size; i++) { + int rate = (int) (profileBasalRate[i] * 100d); + request[1 + (i * 2)] = (byte) (rate & 0xff); + request[2 + (i * 2)] = (byte) ((rate >>> 8) & 0xff); + } + return request; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + } + } + + @Override + public String getFriendlyName() { + return "BASAL__SET_PROFILE_BASAL_RATE"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.java new file mode 100644 index 0000000000..fe47f89dfc --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.java @@ -0,0 +1,48 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Basal_Set_Profile_Number extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Profile_Number.class); + private int profileNumber; + public int error; + + public DanaRS_Packet_Basal_Set_Profile_Number() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_PROFILE_NUMBER; + } + public DanaRS_Packet_Basal_Set_Profile_Number(int profileNumber) { + this(); + this.profileNumber = profileNumber; + if (Config.logDanaMessageDetail) { + log.debug("Setting profile number " + profileNumber); + } + } + + @Override + public byte[] getRequestParams() { + byte[] request = new byte[1]; + request[0] = (byte) (profileNumber & 0xff); + return request; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + } + } + + @Override + public String getFriendlyName() { + return "BASAL__SET_PROFILE_NUMBER"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.java new file mode 100644 index 0000000000..1b9444c2d3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.java @@ -0,0 +1,35 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Basal_Set_Suspend_Off extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Suspend_Off.class); + public int error; + + public DanaRS_Packet_Basal_Set_Suspend_Off() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_SUSPEND_OFF; + if (Config.logDanaMessageDetail) { + log.debug("Turning off suspend"); + } + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + } + } + + @Override + public String getFriendlyName() { + return "BASAL__SET_SUSPEND_OFF"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.java new file mode 100644 index 0000000000..01e90e026c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.java @@ -0,0 +1,35 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Basal_Set_Suspend_On extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Suspend_On.class); + public int error; + + public DanaRS_Packet_Basal_Set_Suspend_On() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_SUSPEND_ON; + if (Config.logDanaMessageDetail) { + log.debug("Turning on suspend"); + } + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + } + } + + @Override + public String getFriendlyName() { + return "BASAL__SET_SUSPEND_ON"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.java new file mode 100644 index 0000000000..a81d85f016 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.java @@ -0,0 +1,52 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Basal_Set_Temporary_Basal extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Temporary_Basal.class); + + private int temporaryBasalRatio; + private int temporaryBasalDuration; + public int error; + + public DanaRS_Packet_Basal_Set_Temporary_Basal() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__SET_TEMPORARY_BASAL; + } + + public DanaRS_Packet_Basal_Set_Temporary_Basal(int temporaryBasalRatio, int temporaryBasalDuration) { + this(); + this.temporaryBasalRatio = temporaryBasalRatio; + this.temporaryBasalDuration = temporaryBasalDuration; + if (Config.logDanaMessageDetail) { + log.debug("Setting temporary basal of " + temporaryBasalRatio + "% for " + temporaryBasalDuration + " hours"); + } + } + + @Override + public byte[] getRequestParams() { + byte[] request = new byte[2]; + request[0] = (byte) (temporaryBasalRatio & 0xff); + request[1] = (byte) (temporaryBasalDuration & 0xff); + return request; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + } + } + + @Override + public String getFriendlyName() { + return "BASAL__SET_TEMPORARY_BASAL"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Temporary_Basal_State.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Temporary_Basal_State.java new file mode 100644 index 0000000000..aec45db5d6 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Temporary_Basal_State.java @@ -0,0 +1,77 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import android.support.annotation.NonNull; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_Basal_Temporary_Basal_State extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Temporary_Basal_State.class); + + public DanaRS_Packet_Basal_Temporary_Basal_State() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__TEMPORARY_BASAL_STATE; + if (Config.logDanaMessageDetail) { + log.debug("Requesting temporary basal status"); + } + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 1; + int error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.isTempBasalInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x01; + boolean isAPSTempBasalInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x02; + + dataIndex += dataSize; + dataSize = 1; + pump.tempBasalPercent = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + if (pump.tempBasalPercent > 200) pump.tempBasalPercent = (pump.tempBasalPercent - 200) * 10; + + dataIndex += dataSize; + dataSize = 1; + int durationHour = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + if (durationHour == 150) pump.tempBasalTotalSec = 15 * 60; + else if (durationHour == 160) pump.tempBasalTotalSec = 30 * 60; + else pump.tempBasalTotalSec = durationHour * 60 * 60; + + dataIndex += dataSize; + dataSize = 2; + int runningMin = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + int tempBasalRemainingMin = (pump.tempBasalTotalSec - runningMin * 60) / 60; + Date tempBasalStart = pump.isTempBasalInProgress ? getDateFromTempBasalSecAgo(runningMin * 60) : new Date(0); + + if (Config.logDanaMessageDetail) { + log.debug("Error code: " + error); + log.debug("Is temp basal running: " + pump.isTempBasalInProgress); + log.debug("Is APS temp basal running: " + isAPSTempBasalInProgress); + log.debug("Current temp basal percent: " + pump.tempBasalPercent); + log.debug("Current temp basal remaining min: " + tempBasalRemainingMin); + log.debug("Current temp basal total sec: " + pump.tempBasalTotalSec); + log.debug("Current temp basal start: " + tempBasalStart); + } + } + + @Override + public String getFriendlyName() { + return "BASAL__TEMPORARY_BASAL_STATE"; + } + + @NonNull + private Date getDateFromTempBasalSecAgo(int tempBasalAgoSecs) { + return new Date((long) (Math.ceil(System.currentTimeMillis() / 1000d) - tempBasalAgoSecs) * 1000); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java new file mode 100644 index 0000000000..068d672646 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java @@ -0,0 +1,124 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_Bolus_Get_Bolus_Option extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Get_Bolus_Option.class); + + public DanaRS_Packet_Bolus_Get_Bolus_Option() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_BOLUS_OPTION; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 1; + pump.isExtendedBolusEnabled = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 1; + + dataIndex += dataSize; + dataSize = 1; + pump.bolusCalculationOption = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.missedBolusConfig = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus01StartHour = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus01StartMin = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus01EndHour = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus01EndMin = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus02StartHour = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus02StartMin = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus02EndHour = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus02EndMin = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus03StartHour = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus03StartMin = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus03EndHour = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus03EndMin = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus04StartHour = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus04StartMin = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus04EndHour = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int missedBolus04EndMin = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("Extended bolus enabled: " + pump.isExtendedBolusEnabled); + log.debug("Missed bolus config: " + pump.missedBolusConfig); + log.debug("missedBolus01StartHour: " + missedBolus01StartHour); + log.debug("missedBolus01StartMin: " + missedBolus01StartMin); + log.debug("missedBolus01EndHour: " + missedBolus01EndHour); + log.debug("missedBolus01EndMin: " + missedBolus01EndMin); + log.debug("missedBolus02StartHour: " + missedBolus02StartHour); + log.debug("missedBolus02StartMin: " + missedBolus02StartMin); + log.debug("missedBolus02EndHour: " + missedBolus02EndHour); + log.debug("missedBolus02EndMin: " + missedBolus02EndMin); + log.debug("missedBolus03StartHour: " + missedBolus03StartHour); + log.debug("missedBolus03StartMin: " + missedBolus03StartMin); + log.debug("missedBolus03EndHour: " + missedBolus03EndHour); + log.debug("missedBolus03EndMin: " + missedBolus03EndMin); + log.debug("missedBolus04StartHour: " + missedBolus04StartHour); + log.debug("missedBolus04StartMin: " + missedBolus04StartMin); + log.debug("missedBolus04EndHour: " + missedBolus04EndHour); + log.debug("missedBolus04EndMin: " + missedBolus04EndMin); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__GET_BOLUS_OPTION"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.java new file mode 100644 index 0000000000..b8a86cc078 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.java @@ -0,0 +1,145 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_Bolus_Get_CIR_CF_Array extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Get_CIR_CF_Array.class); + + public DanaRS_Packet_Bolus_Get_CIR_CF_Array() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_CIR_CF_ARRAY; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 1; + int language = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.units = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.morningCIR = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + int cir02 = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.afternoonCIR = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + int cir04 = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.eveningCIR = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + int cir06 = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.nightCIR = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + double cf02, cf04, cf06; + + if (pump.units == DanaRPump.UNITS_MGDL) { + dataIndex += dataSize; + dataSize = 2; + pump.morningCF = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + cf02 = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.afternoonCF = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + cf04 = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.eveningCF = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + cf06 = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.nightCF = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + } else { + dataIndex += dataSize; + dataSize = 2; + pump.morningCF = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + cf02 = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + pump.afternoonCF = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + cf04 = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + pump.eveningCF = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + cf06 = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + pump.nightCF = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + } + + if (Config.logDanaMessageDetail) { + log.debug("Language: " + language); + log.debug("Pump units: " + (pump.units == DanaRPump.UNITS_MGDL ? "MGDL" : "MMOL")); + log.debug("Current pump morning CIR: " + pump.morningCIR); + log.debug("Current pump morning CF: " + pump.morningCF); + log.debug("Current pump afternoon CIR: " + pump.afternoonCIR); + log.debug("Current pump afternoon CF: " + pump.afternoonCF); + log.debug("Current pump evening CIR: " + pump.eveningCIR); + log.debug("Current pump evening CF: " + pump.eveningCF); + log.debug("Current pump night CIR: " + pump.nightCIR); + log.debug("Current pump night CF: " + pump.nightCF); + log.debug("cir02: " + cir02); + log.debug("cir04: " + cir04); + log.debug("cir06: " + cir06); + log.debug("cf02: " + cf02); + log.debug("cf04: " + cf04); + log.debug("cf06: " + cf06); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__GET_CIR_CF_ARRAY"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.java new file mode 100644 index 0000000000..f5acedf3ba --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.java @@ -0,0 +1,77 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_Bolus_Get_Calculation_Information extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Get_Calculation_Information.class); + + public DanaRS_Packet_Bolus_Get_Calculation_Information() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_CALCULATION_INFORMATION; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 1; + int error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + double currentBG = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + int carbohydrate = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.currentTarget = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.currentCIR = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.currentCF = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.iob = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 1; + pump.units = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (pump.units == DanaRPump.UNITS_MMOL) { + pump.currentCF = pump.currentCF / 100d; + pump.currentTarget = pump.currentTarget / 100d; + currentBG = currentBG / 100d; + } + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + log.debug("Pump units: " + (pump.units == DanaRPump.UNITS_MGDL ? "MGDL" : "MMOL")); + log.debug("Current BG: " + currentBG); + log.debug("Carbs: " + carbohydrate); + log.debug("Current target: " + pump.currentTarget); + log.debug("Current CIR: " + pump.currentCIR); + log.debug("Current CF: " + pump.currentCF); + log.debug("Pump IOB: " + pump.iob); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__GET_CALCULATION_INFORMATION"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.java new file mode 100644 index 0000000000..c581320c54 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.java @@ -0,0 +1,47 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.class); + + public DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_CARBOHYDRATE_CALCULATION_INFORMATION; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 1; + int error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + int carbs = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.currentCIR = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + log.debug("Carbs: " + carbs); + log.debug("Current CIR: " + pump.currentCIR); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__GET_CARBOHYDRATE_CALCULATION_INFORMATION"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.java new file mode 100644 index 0000000000..bd7a0b9ee6 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.java @@ -0,0 +1,55 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_Bolus_Get_Dual_Bolus extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Get_Dual_Bolus.class); + + public DanaRS_Packet_Bolus_Get_Dual_Bolus() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_DUAL_BOLUS; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 1; + int error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.bolusStep = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.extendedBolusAbsoluteRate = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + pump.maxBolus = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 1; + double bolusIncrement = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + log.debug("Bolus step: " + pump.bolusStep + " U"); + log.debug("Extended bolus running: " + pump.extendedBolusAbsoluteRate + " U/h"); + log.debug("Max bolus: " + pump.maxBolus + " U"); + log.debug("bolusIncrement: " + bolusIncrement + " U"); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__GET_DUAL_BOLUS"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.java new file mode 100644 index 0000000000..682d9b14bb --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.java @@ -0,0 +1,52 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_Bolus_Get_Extended_Bolus extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Get_Extended_Bolus.class); + + public DanaRS_Packet_Bolus_Get_Extended_Bolus() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_BOLUS; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 1; + int error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.extendedBolusAbsoluteRate = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + pump.maxBolus = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 1; + pump.bolusStep = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + log.debug("Extended bolus running: " + pump.extendedBolusAbsoluteRate + " U/h"); + log.debug("Max bolus: " + pump.maxBolus + " U"); + log.debug("Bolus step: " + pump.bolusStep + " U"); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__GET_EXTENDED_BOLUS"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.java new file mode 100644 index 0000000000..b22a9dfb47 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.java @@ -0,0 +1,62 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_Bolus_Get_Extended_Bolus_State extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Get_Extended_Bolus_State.class); + + public DanaRS_Packet_Bolus_Get_Extended_Bolus_State() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_BOLUS_STATE; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 1; + int error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.isExtendedInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x01; + + dataIndex += dataSize; + dataSize = 1; + pump.extendedBolusMinutes = byteArrayToInt(getBytes(data, dataIndex, dataSize)) * 30; + + dataIndex += dataSize; + dataSize = 2; + pump.extendedBolusAbsoluteRate = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + pump.extendedBolusSoFarInMinutes = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.extendedBolusDeliveredSoFar = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + log.debug("Is extended bolus running: " + pump.isExtendedInProgress); + log.debug("Extended bolus running: " + pump.extendedBolusAbsoluteRate + " U/h"); + log.debug("Extended bolus duration: " + pump.extendedBolusMinutes + " min"); + log.debug("Extended bolus so far: " + pump.extendedBolusSoFarInMinutes + " min"); + log.debug("Extended bolus delivered so far: " + pump.extendedBolusDeliveredSoFar + " U"); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__GET_EXTENDED_BOLUS_STATE"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.java new file mode 100644 index 0000000000..5a7ca55e30 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.java @@ -0,0 +1,42 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.class); + + public DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_EXTENDED_MENU_OPTION_STATE; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 1; + int extendedMenuOption = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.isExtendedInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x01; + + if (Config.logDanaMessageDetail) { + log.debug("extendedMenuOption: " + extendedMenuOption); + log.debug("Is extended bolus running: " + pump.isExtendedInProgress); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__GET_EXTENDED_MENU_OPTION_STATE"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.java new file mode 100644 index 0000000000..58fa4674ad --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.java @@ -0,0 +1,46 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Bolus_Get_Initial_Bolus extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Get_Initial_Bolus.class); + + public DanaRS_Packet_Bolus_Get_Initial_Bolus() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_BOLUS_RATE; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 2; + double initialBolusValue01 = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + double initialBolusValue02 = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + double initialBolusValue03 = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + double initialBolusValue04 = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + if (Config.logDanaMessageDetail) { + log.debug("Initial bolus amount 01: " + initialBolusValue01); + log.debug("Initial bolus amount 02: " + initialBolusValue02); + log.debug("Initial bolus amount 03: " + initialBolusValue03); + log.debug("Initial bolus amount 04: " + initialBolusValue04); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__GET_BOLUS_RATE"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.java new file mode 100644 index 0000000000..922b7886f2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.java @@ -0,0 +1,72 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_Bolus_Get_Step_Bolus_Information extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Get_Step_Bolus_Information.class); + + public DanaRS_Packet_Bolus_Get_Step_Bolus_Information() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__GET_STEP_BOLUS_INFORMATION; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 1; + int error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int bolusType = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.initialBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + Date lastBolusTime = new Date(); // it doesn't provide day only hour+min, workaround: expecting today + dataIndex += dataSize; + dataSize = 1; + lastBolusTime.setHours(byteArrayToInt(getBytes(data, dataIndex, dataSize))); + + dataIndex += dataSize; + dataSize = 1; + lastBolusTime.setMinutes(byteArrayToInt(getBytes(data, dataIndex, dataSize))); + + dataIndex += dataSize; + dataSize = 2; + pump.lastBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + pump.maxBolus = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 1; + pump.bolusStep = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + log.debug("BolusType: " + bolusType); + log.debug("Initial bolus amount: " + pump.initialBolusAmount + " U"); + log.debug("Last bolus time: " + lastBolusTime.toLocaleString()); + log.debug("Last bolus amount: " + pump.lastBolusAmount); + log.debug("Max bolus: " + pump.maxBolus + " U"); + log.debug("Bolus step: " + pump.bolusStep + " U"); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__GET_STEP_BOLUS_INFORMATION"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.java new file mode 100644 index 0000000000..e20baeaee6 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.java @@ -0,0 +1,127 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Bolus_Set_Bolus_Option extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Set_Bolus_Option.class); + private int extendedBolusOptionOnOff; + + private int bolusCalculationOption; + private int missedBolusConfig; + private int missedBolus01StartHour; + private int missedBolus01StartMin; + private int missedBolus01EndHour; + private int missedBolus01EndMin; + private int missedBolus02StartHour; + private int missedBolus02StartMin; + private int missedBolus02EndHour; + private int missedBolus02EndMin; + private int missedBolus03StartHour; + private int missedBolus03StartMin; + private int missedBolus03EndHour; + private int missedBolus03EndMin; + private int missedBolus04StartHour; + private int missedBolus04StartMin; + private int missedBolus04EndHour; + private int missedBolus04EndMin; + + public DanaRS_Packet_Bolus_Set_Bolus_Option() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_BOLUS_OPTION; + } + + public DanaRS_Packet_Bolus_Set_Bolus_Option( + int extendedBolusOptionOnOff, + int bolusCalculationOption, + int missedBolusConfig, + int missedBolus01StartHour, + int missedBolus01StartMin, + int missedBolus01EndHour, + int missedBolus01EndMin, + int missedBolus02StartHour, + int missedBolus02StartMin, + int missedBolus02EndHour, + int missedBolus02EndMin, + int missedBolus03StartHour, + int missedBolus03StartMin, + int missedBolus03EndHour, + int missedBolus03EndMin, + int missedBolus04StartHour, + int missedBolus04StartMin, + int missedBolus04EndHour, + int missedBolus04EndMin) { + this(); + this.extendedBolusOptionOnOff = extendedBolusOptionOnOff; + this.bolusCalculationOption = bolusCalculationOption; + this.missedBolusConfig = missedBolusConfig; + this.missedBolus01StartHour = missedBolus01StartHour; + this.missedBolus01StartMin = missedBolus01StartMin; + this.missedBolus01EndHour = missedBolus01EndHour; + this.missedBolus01EndMin = missedBolus01EndMin; + this.missedBolus02StartHour = missedBolus02StartHour; + this.missedBolus02StartMin = missedBolus02StartMin; + this.missedBolus02EndHour = missedBolus02EndHour; + this.missedBolus02EndMin = missedBolus02EndMin; + this.missedBolus03StartHour = missedBolus03StartHour; + this.missedBolus03StartMin = missedBolus03StartMin; + this.missedBolus03EndHour = missedBolus03EndHour; + this.missedBolus03EndMin = missedBolus03EndMin; + this.missedBolus04StartHour = missedBolus04StartHour; + this.missedBolus04StartMin = missedBolus04StartMin; + this.missedBolus04EndHour = missedBolus04EndHour; + this.missedBolus04EndMin = missedBolus04EndMin; + + if (Config.logDanaMessageDetail) { + log.debug("Setting bolus options"); + } + } + + @Override + public byte[] getRequestParams() { + byte[] request = new byte[19]; + request[0] = (byte) (extendedBolusOptionOnOff & 0xff); + request[1] = (byte) (bolusCalculationOption & 0xff); + request[2] = (byte) (missedBolusConfig & 0xff); + + request[3] = (byte) (missedBolus01StartHour & 0xff); + request[4] = (byte) (missedBolus01StartMin & 0xff); + request[5] = (byte) (missedBolus01EndHour & 0xff); + request[6] = (byte) (missedBolus01EndMin & 0xff); + + request[7] = (byte) (missedBolus02StartHour & 0xff); + request[8] = (byte) (missedBolus02StartMin & 0xff); + request[9] = (byte) (missedBolus02EndHour & 0xff); + request[10] = (byte) (missedBolus02EndMin & 0xff); + + request[11] = (byte) (missedBolus03StartHour & 0xff); + request[12] = (byte) (missedBolus03StartMin & 0xff); + request[13] = (byte) (missedBolus03EndHour & 0xff); + request[14] = (byte) (missedBolus03EndMin & 0xff); + + request[15] = (byte) (missedBolus04StartHour & 0xff); + request[16] = (byte) (missedBolus04StartMin & 0xff); + request[17] = (byte) (missedBolus04EndHour & 0xff); + request[18] = (byte) (missedBolus04EndMin & 0xff); + return request; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + int status = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("Result: " + status); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__SET_BOLUS_OPTION"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.java new file mode 100644 index 0000000000..cf6a459d83 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.java @@ -0,0 +1,100 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Bolus_Set_CIR_CF_Array extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Set_CIR_CF_Array.class); + + private int cir01; + private int cir02; + private int cir03; + private int cir04; + private int cir05; + private int cir06; + private int cir07; + private int cf01; + private int cf02; + private int cf03; + private int cf04; + private int cf05; + private int cf06; + private int cf07; + + public DanaRS_Packet_Bolus_Set_CIR_CF_Array() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_CIR_CF_ARRAY; + } + + public DanaRS_Packet_Bolus_Set_CIR_CF_Array(int cir01, int cir02, int cir03, int cir04, int cir05, int cir06, int cir07, int cf01, int cf02, int cf03, int cf04, int cf05, int cf06, int cf07) { + this(); + this.cir01 = cir01; + this.cir02 = cir02; + this.cir03 = cir03; + this.cir04 = cir04; + this.cir05 = cir05; + this.cir06 = cir06; + this.cir07 = cir07; + this.cf01 = cf01; + this.cf02 = cf02; + this.cf03 = cf03; + this.cf04 = cf04; + this.cf05 = cf05; + this.cf06 = cf06; + this.cf07 = cf07; + } + + @Override + public byte[] getRequestParams() { + byte[] request = new byte[28]; + request[0] = (byte) (cir01 & 0xff); + request[1] = (byte) ((cir01 >>> 8) & 0xff); + request[2] = (byte) (cir02 & 0xff); + request[3] = (byte) ((cir02 >>> 8) & 0xff); + request[4] = (byte) (cir03 & 0xff); + request[5] = (byte) ((cir03 >>> 8) & 0xff); + request[6] = (byte) (cir04 & 0xff); + request[7] = (byte) ((cir04 >>> 8) & 0xff); + request[8] = (byte) (cir05 & 0xff); + request[9] = (byte) ((cir05 >>> 8) & 0xff); + request[10] = (byte) (cir06 & 0xff); + request[11] = (byte) ((cir06 >>> 8) & 0xff); + request[12] = (byte) (cir07 & 0xff); + request[13] = (byte) ((cir07 >>> 8) & 0xff); + request[14] = (byte) (cf01 & 0xff); + request[15] = (byte) ((cf01 >>> 8) & 0xff); + request[16] = (byte) (cf02 & 0xff); + request[17] = (byte) ((cf02 >>> 8) & 0xff); + request[18] = (byte) (cf03 & 0xff); + request[19] = (byte) ((cf03 >>> 8) & 0xff); + request[20] = (byte) (cf04 & 0xff); + request[21] = (byte) ((cf04 >>> 8) & 0xff); + request[22] = (byte) (cf05 & 0xff); + request[23] = (byte) ((cf05 >>> 8) & 0xff); + request[24] = (byte) (cf06 & 0xff); + request[25] = (byte) ((cf06 >>> 8) & 0xff); + request[26] = (byte) (cf07 & 0xff); + request[27] = (byte) ((cf07 >>> 8) & 0xff); + return request; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + int status = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("Result: " + status); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__SET_CIR_CF_ARRAY"; + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.java new file mode 100644 index 0000000000..31c80a702a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.java @@ -0,0 +1,60 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Bolus_Set_Dual_Bolus extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Set_Dual_Bolus.class); + + private double amount; + private double extendedAmount; + private int extendedBolusDurationInHalfHours; + + public DanaRS_Packet_Bolus_Set_Dual_Bolus() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_DUAL_BOLUS; + } + + public DanaRS_Packet_Bolus_Set_Dual_Bolus(double amount, double extendedAmount, int extendedBolusDurationInHalfHours) { + this(); + this.amount = amount; + this.extendedAmount = extendedAmount; + this.extendedBolusDurationInHalfHours = extendedBolusDurationInHalfHours; + + if (Config.logDanaMessageDetail) + log.debug("Dual bolus start : " + amount + " U extended: " + extendedAmount + " U halfhours: " + extendedBolusDurationInHalfHours); + } + + @Override + public byte[] getRequestParams() { + int stepBolusRate = (int) (amount / 100d); + int extendedBolusRate = (int) (extendedAmount / 100d); + + byte[] request = new byte[5]; + request[0] = (byte) (stepBolusRate & 0xff); + request[1] = (byte) ((stepBolusRate >>> 8) & 0xff); + request[2] = (byte) (extendedBolusRate & 0xff); + request[3] = (byte) ((extendedBolusRate >>> 8) & 0xff); + request[4] = (byte) (extendedBolusDurationInHalfHours & 0xff); + return request; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + int status = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("Result: " + status); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__SET_DUAL_BOLUS"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.java new file mode 100644 index 0000000000..b663b3bf72 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.java @@ -0,0 +1,56 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Bolus_Set_Extended_Bolus extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Set_Extended_Bolus.class); + + private double extendedAmount; + private int extendedBolusDurationInHalfHours; + + public DanaRS_Packet_Bolus_Set_Extended_Bolus() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_EXTENDED_BOLUS; + } + + public DanaRS_Packet_Bolus_Set_Extended_Bolus(double extendedAmount, int extendedBolusDurationInHalfHours) { + this(); + this.extendedAmount = extendedAmount; + this.extendedBolusDurationInHalfHours = extendedBolusDurationInHalfHours; + + if (Config.logDanaMessageDetail) + log.debug("Extended bolus start : " + extendedAmount + " U halfhours: " + extendedBolusDurationInHalfHours); + } + + @Override + public byte[] getRequestParams() { + int extendedBolusRate = (int) (extendedAmount / 100d); + + byte[] request = new byte[3]; + request[0] = (byte) (extendedBolusRate & 0xff); + request[1] = (byte) ((extendedBolusRate >>> 8) & 0xff); + request[2] = (byte) (extendedBolusDurationInHalfHours & 0xff); + return request; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + int status = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("Result: " + status); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__SET_EXTENDED_BOLUS"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.java new file mode 100644 index 0000000000..10aa5f4979 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.java @@ -0,0 +1,35 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.class); + + public DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_EXTENDED_BOLUS_CANCEL; + + if (Config.logDanaMessageDetail) + log.debug("Cancel extended bolus"); + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + int status = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("Result: " + status); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__SET_EXTENDED_BOLUS_CANCEL"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.java new file mode 100644 index 0000000000..a475e7675d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.java @@ -0,0 +1,60 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Bolus_Set_Initial_Bolus extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Set_Initial_Bolus.class); + + private int bolusRate01; + private int bolusRate02; + private int bolusRate03; + private int bolusRate04; + + public DanaRS_Packet_Bolus_Set_Initial_Bolus() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_BOLUS_RATE; + } + + public DanaRS_Packet_Bolus_Set_Initial_Bolus(double bolusRate01, double bolusRate02, double bolusRate03, double bolusRate04) { + this(); + this.bolusRate01 = (int) (bolusRate01 / 100d); + this.bolusRate02 = (int) (bolusRate02 / 100d); + this.bolusRate03 = (int) (bolusRate03 / 100d); + this.bolusRate04 = (int) (bolusRate04 / 100d); + } + + @Override + public byte[] getRequestParams() { + byte[] request = new byte[8]; + request[0] = (byte) (bolusRate01 & 0xff); + request[1] = (byte) ((bolusRate01 >>> 8) & 0xff); + request[2] = (byte) (bolusRate02 & 0xff); + request[3] = (byte) ((bolusRate02 >>> 8) & 0xff); + request[4] = (byte) (bolusRate03 & 0xff); + request[5] = (byte) ((bolusRate03 >>> 8) & 0xff); + request[6] = (byte) (bolusRate04 & 0xff); + request[7] = (byte) ((bolusRate04 >>> 8) & 0xff); + return request; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + int status = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("Result: " + status); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__SET_BOLUS_RATE"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java new file mode 100644 index 0000000000..be389c668c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java @@ -0,0 +1,62 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; +import com.cozmo.danar.util.BleCommandUtil; +import info.nightscout.utils.HardLimits; + +public class DanaRS_Packet_Bolus_Set_Step_Bolus_Start extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Set_Step_Bolus_Start.class); + + private double amount; + private int speed; + + public DanaRS_Packet_Bolus_Set_Step_Bolus_Start() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_START; + } + + // Speed 0 => 12 sec/U, 1 => 30 sec/U, 2 => 60 sec/U + public DanaRS_Packet_Bolus_Set_Step_Bolus_Start(double amount, int speed) { + this(); + + // HARDCODED LIMIT + amount = MainApp.getConfigBuilder().applyBolusConstraints(amount); + if (amount < 0) amount = 0d; + if (amount > HardLimits.maxBolus()) amount = HardLimits.maxBolus(); + + this.amount = amount; + this.speed = speed; + + if (Config.logDanaMessageDetail) + log.debug("Bolus start : " + amount + " speed: " + speed); + } + + @Override + public byte[] getRequestParams() { + int stepBolusRate = (int) (amount * 100); + byte[] request = new byte[3]; + request[0] = (byte) (stepBolusRate & 0xff); + request[1] = (byte) ((stepBolusRate >>> 8) & 0xff); + request[2] = (byte) (speed & 0xff); + return request; + } + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + int status = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("Result: " + status); + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__SET_STEP_BOLUS_START"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java new file mode 100644 index 0000000000..1b52f36544 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java @@ -0,0 +1,60 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; + +import com.cozmo.danar.util.BleCommandUtil; + +import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; + +public class DanaRS_Packet_Bolus_Set_Step_Bolus_Stop extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.class); + private static Treatment t; + private static Double amount; + + public static boolean stopped = false; + public static boolean forced = false; + + public DanaRS_Packet_Bolus_Set_Step_Bolus_Stop() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_STOP; + } + + public DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(Double amount, Treatment t) { + this(); + this.t = t; + this.amount = amount; + forced = false; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + int status = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("Result: " + status); + } + EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); + stopped = true; + if (!forced) { + t.insulin = amount; + bolusingEvent.status = MainApp.sResources.getString(R.string.overview_bolusprogress_delivered); + bolusingEvent.percent = 100; + } else { + bolusingEvent.status = MainApp.sResources.getString(R.string.overview_bolusprogress_stoped); + } + MainApp.bus().post(bolusingEvent); + } + + @Override + public String getFriendlyName() { + return "BOLUS__SET_STEP_BOLUS_STOP"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Keep_Connection.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Keep_Connection.java new file mode 100644 index 0000000000..d30be3abf8 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Keep_Connection.java @@ -0,0 +1,32 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Etc_Keep_Connection extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Etc_Keep_Connection.class); + + public DanaRS_Packet_Etc_Keep_Connection() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_ETC__KEEP_CONNECTION; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + int error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + } + } + + @Override + public String getFriendlyName() { + return "ETC__KEEP_CONNECTION"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Set_History_Save.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Set_History_Save.java new file mode 100644 index 0000000000..6538b77932 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Set_History_Save.java @@ -0,0 +1,71 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Etc_Set_History_Save extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Etc_Set_History_Save.class); + + private int historyType; + private int historyYear; + private int historyMonth; + private int historyDate; + private int historyHour; + private int historyMinute; + private int historySecond; + private int historyCode; + private int historyValue; + + public DanaRS_Packet_Etc_Set_History_Save() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_ETC__SET_HISTORY_SAVE; + } + + public DanaRS_Packet_Etc_Set_History_Save(int historyType, int historyYear, int historyMonth, int historyDate, int historyHour, int historyMinute, int historySecond, int historyCode, int historyValue) { + this(); + this.historyType = historyType; + this.historyYear = historyYear; + this.historyMonth = historyMonth; + this.historyDate = historyDate; + this.historyHour = historyHour; + this.historyMinute = historyMinute; + this.historySecond = historySecond; + this.historyCode = historyCode; + this.historyValue = historyValue; + } + + @Override + public byte[] getRequestParams() { + byte[] request = new byte[10]; + request[0] = (byte) (historyType & 0xff); + request[1] = (byte) (historyYear & 0xff); + request[2] = (byte) (historyMonth & 0xff); + request[3] = (byte) (historyDate & 0xff); + request[4] = (byte) (historyHour & 0xff); + request[5] = (byte) (historyMinute & 0xff); + request[6] = (byte) (historySecond & 0xff); + request[7] = (byte) (historyCode & 0xff); + request[8] = (byte) (historyValue & 0xff); + request[9] = (byte) ((historyValue >>> 8) & 0xff); + return request; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + int error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + } + } + + @Override + public String getFriendlyName() { + return "ETC__SET_HISTORY_SAVE"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Delivery_Status.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Delivery_Status.java new file mode 100644 index 0000000000..d9e2599eb2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Delivery_Status.java @@ -0,0 +1,32 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_General_Delivery_Status extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_General_Delivery_Status.class); + + public DanaRS_Packet_General_Delivery_Status() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__DELIVERY_STATUS; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + int status = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + if (Config.logDanaMessageDetail) { + log.debug("Status: " + status); + } + } + + @Override + public String getFriendlyName() { + return "REVIEW__DELIVERY_STATUS"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_More_Information.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_More_Information.java new file mode 100644 index 0000000000..cd2de4094f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_More_Information.java @@ -0,0 +1,70 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; + +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_General_Get_More_Information extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_General_Get_More_Information.class); + + public DanaRS_Packet_General_Get_More_Information() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_MORE_INFORMATION; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 2; + pump.iob = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.dailyTotalUnits = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 1; + pump.isExtendedInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x01; + + dataIndex += dataSize; + dataSize = 2; + pump.extendedBolusRemainingMinutes = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + double remainRate = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + Date lastBolusTime = new Date(); // it doesn't provide day only hour+min, workaround: expecting today + dataIndex += dataSize; + dataSize = 1; + lastBolusTime.setHours(byteArrayToInt(getBytes(data, dataIndex, dataSize))); + + dataIndex += dataSize; + dataSize = 1; + lastBolusTime.setMinutes(byteArrayToInt(getBytes(data, dataIndex, dataSize))); + + dataIndex += dataSize; + dataSize = 2; + pump.lastBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("Daily total units: " + pump.dailyTotalUnits + " U"); + log.debug("Is extended in progress: " + pump.isExtendedInProgress); + log.debug("Extended bolus remaining minutes: " + pump.extendedBolusRemainingMinutes); + log.debug("Last bolus time: " + lastBolusTime.toLocaleString()); + log.debug("Last bolus amount: " + pump.lastBolusAmount); + } + } + + @Override + public String getFriendlyName() { + return "REVIEW__GET_MORE_INFORMATION"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Password.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Password.java new file mode 100644 index 0000000000..0d250db919 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Password.java @@ -0,0 +1,36 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_General_Get_Password extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_General_Get_Password.class); + + public DanaRS_Packet_General_Get_Password() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_PASSWORD; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int pass = ((data[DATA_START + 1] & 0x000000FF) << 8) + (data[DATA_START + 0] & 0x000000FF); + pass = pass ^ 3463; + pump.rs_password = Integer.toHexString(pass); + if (Config.logDanaMessageDetail) { + log.debug("Pump password: " + pump.rs_password); + } + } + + @Override + public String getFriendlyName() { + return "REVIEW__GET_PASSWORD"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java new file mode 100644 index 0000000000..d82d6229b9 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java @@ -0,0 +1,45 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_General_Get_Pump_Check extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_General_Get_Pump_Check.class); + + public DanaRS_Packet_General_Get_Pump_Check() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_PUMP_CHECK; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 1; + pump.model = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.protocol = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.productCode = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("Model: " + String.format("%02X ", pump.model)); + log.debug("Protocol: " + String.format("%02X ", pump.protocol)); + log.debug("Product Code: " + String.format("%02X ", pump.productCode)); + } + } + + @Override + public String getFriendlyName() { + return "REVIEW__GET_PUMP_CHECK"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.java new file mode 100644 index 0000000000..2cf9b1f124 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.java @@ -0,0 +1,46 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_General_Get_Shipping_Information extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.class); + + public DanaRS_Packet_General_Get_Shipping_Information() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_SHIPPING_INFORMATION; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 10; + pump.serialNumber = stringFromBuff(data, dataIndex, dataSize); + + dataIndex += dataSize; + dataSize = 3; + pump.shippingDate = dateFromBuff(data, dataIndex); + + dataIndex += dataSize; + dataSize = 3; + pump.shippingCountry = asciiStringFromBuff(data, dataIndex, dataSize); + + if (Config.logDanaMessageDetail) { + log.debug("Serial number: " + pump.serialNumber); + log.debug("Shipping date: " + pump.shippingDate); + log.debug("Shipping country: " + pump.shippingCountry); + } + } + + @Override + public String getFriendlyName() { + return "REVIEW__GET_SHIPPING_INFORMATION"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.java new file mode 100644 index 0000000000..a40d572611 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.java @@ -0,0 +1,47 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_General_Get_Today_Delivery_Total extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_General_Get_Today_Delivery_Total.class); + + public DanaRS_Packet_General_Get_Today_Delivery_Total() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_TODAY_DELIVERY_TOTAL; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 2; + pump.dailyTotalUnits = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + pump.dailyTotalBasalUnits = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + pump.dailyTotalBolusUnits = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + if (Config.logDanaMessageDetail) { + log.debug("Daily total: " + pump.dailyTotalUnits + " U"); + log.debug("Daily total bolus: " + pump.dailyTotalBolusUnits + " U"); + log.debug("Daily total basal: " + pump.dailyTotalBasalUnits + " U"); + } + } + + @Override + public String getFriendlyName() { + return "REVIEW__GET_TODAY_DELIVERY_TOTAL"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.java new file mode 100644 index 0000000000..695e3eace4 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.java @@ -0,0 +1,32 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_General_Get_User_Time_Change_Flag extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_General_Get_User_Time_Change_Flag.class); + + public DanaRS_Packet_General_Get_User_Time_Change_Flag() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__GET_USER_TIME_CHANGE_FLAG; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + int userTimeChangeFlag = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("UserTimeChangeFlag: " + userTimeChangeFlag); + } + } + + @Override + public String getFriendlyName() { + return "REVIEW__GET_USER_TIME_CHANGE_FLAG"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java new file mode 100644 index 0000000000..a6145302ad --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java @@ -0,0 +1,85 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_General_Initial_Screen_Information extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Get_Step_Bolus_Information.class); + + public DanaRS_Packet_General_Initial_Screen_Information() { + super(); + type = BleCommandUtil.DANAR_PACKET__TYPE_RESPONSE; + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__INITIAL_SCREEN_INFORMATION; + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 1; + int status = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + pump.pumpSuspended = (status & 0x01) == 0x01; + pump.isTempBasalInProgress = (status & 0x10) == 0x10; + pump.isExtendedInProgress = (status & 0x04) == 0x04; + pump.isDualBolusInProgress = (status & 0x08) == 0x08; + + dataIndex += dataSize; + dataSize = 2; + pump.dailyTotalUnits = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + pump.maxDailyTotalUnits = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.reservoirRemainingUnits = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + pump.currentBasal = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 1; + pump.tempBasalPercent = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.batteryRemaining = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.extendedBolusAbsoluteRate = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + pump.iob = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + if (Config.logDanaMessageDetail) { + log.debug("Pump suspended: " + pump.pumpSuspended); + log.debug("Temp basal in progress: " + pump.isTempBasalInProgress); + log.debug("Extended in progress: " + pump.isExtendedInProgress); + log.debug("Dual in progress: " + pump.isDualBolusInProgress); + log.debug("Daily units: " + pump.dailyTotalUnits); + log.debug("Max daily units: " + pump.maxDailyTotalUnits); + log.debug("Reservoir remaining units: " + pump.reservoirRemainingUnits); + log.debug("Battery: " + pump.batteryRemaining); + log.debug("Current basal: " + pump.currentBasal); + log.debug("Temp basal percent: " + pump.tempBasalPercent); + log.debug("Extended absolute rate: " + pump.extendedBolusAbsoluteRate); + } + } + + @Override + public String getFriendlyName() { + return "REVIEW__INITIAL_SCREEN_INFORMATION"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.java new file mode 100644 index 0000000000..7d9ec07ff1 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.java @@ -0,0 +1,47 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_General_Set_History_Upload_Mode extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_General_Set_History_Upload_Mode.class); + + private int mode; + + public DanaRS_Packet_General_Set_History_Upload_Mode() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SET_HISTORY_UPLOAD_MODE; + } + + public DanaRS_Packet_General_Set_History_Upload_Mode(int mode) { + this(); + this.mode = mode; + } + + @Override + public byte[] getRequestParams() { + byte[] request = new byte[1]; + request[0] = (byte) (mode & 0xff); + return request; + } + + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + int status = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("Result: " + status); + } + } + + @Override + public String getFriendlyName() { + return "REVIEW__SET_HISTORY_UPLOAD_MODE"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.java new file mode 100644 index 0000000000..9cc6b7b2e0 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.java @@ -0,0 +1,33 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.class); + + public DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SET_USER_TIME_CHANGE_FLAG_CLEAR; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + int status = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("Result: " + status); + } + } + + @Override + public String getFriendlyName() { + return "REVIEW__SET_USER_TIME_CHANGE_FLAG_CLEAR"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_.java new file mode 100644 index 0000000000..b449e489dd --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_.java @@ -0,0 +1,124 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + +import com.cozmo.danar.util.BleCommandUtil; + +public abstract class DanaRS_Packet_History_ extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_History_.class); + + private int year; + private int month; + private int day; + private int hour; + private int min; + private int sec; + + public boolean done; + public int totalCount; + + public DanaRS_Packet_History_() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BOLUS; + done = false; + totalCount = 0; + } + + public DanaRS_Packet_History_(Date from) { + this(); + GregorianCalendar cal = new GregorianCalendar(); + cal.setTime(from); + year = cal.get(Calendar.YEAR) - 1900 - 100; + month = cal.get(Calendar.MONTH) + 1; + day = cal.get(Calendar.DAY_OF_MONTH); + hour = cal.get(Calendar.HOUR_OF_DAY); + min = cal.get(Calendar.MINUTE); + sec = cal.get(Calendar.SECOND); + } + + public DanaRS_Packet_History_(int year, int month, int day, int hour, int min, int sec) { + this(); + this.year = year; + this.month = month; + this.day = day; + this.hour = hour; + this.min = min; + this.sec = sec; + } + + @Override + public byte[] getRequestParams() { + byte[] request = new byte[6]; + request[0] = (byte) (year & 0xff); + request[1] = (byte) (month & 0xff); + request[2] = (byte) (day & 0xff); + request[3] = (byte) (hour & 0xff); + request[4] = (byte) (min & 0xff); + request[5] = (byte) (sec & 0xff); + return request; + } + + @Override + public void handleMessage(byte[] data) { + int error = 0x00; + totalCount = 0; + if (data.length == 3) { + int dataIndex = DATA_START; + int dataSize = 1; + error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + done = error == 0x00; + } else if (data.length == 5) { + int dataIndex = DATA_START; + int dataSize = 1; + error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + done = error == 0x00; + + dataIndex += dataSize; + dataSize = 2; + totalCount = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + } else { + int dataIndex = DATA_START; + int dataSize = 1; + int historyType = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int historyYear = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int historyMonth = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int historyDay = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int historyHour = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int historyMinute = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int historySecond = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + Date date = new Date(100 + historyYear, historyMonth - 1, historyDay, historyHour, historyMinute, historySecond); + + dataIndex += dataSize; + dataSize = 1; + int historyCode = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + int historyValue = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + } + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Alarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Alarm.java new file mode 100644 index 0000000000..5fe57fefe4 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Alarm.java @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import java.util.Date; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_History_Alarm extends DanaRS_Packet_History_ { + + public DanaRS_Packet_History_Alarm() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALARM; + } + + public DanaRS_Packet_History_Alarm(Date from) { + super(from); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALARM; + } + + @Override + public String getFriendlyName() { + return "REVIEW__ALARM"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_All_History.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_All_History.java new file mode 100644 index 0000000000..a514d4eac7 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_All_History.java @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import java.util.Date; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_History_All_History extends DanaRS_Packet_History_ { + + public DanaRS_Packet_History_All_History() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALL_HISTORY; + } + + public DanaRS_Packet_History_All_History(Date from) { + super(from); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALL_HISTORY; + } + + @Override + public String getFriendlyName() { + return "REVIEW__ALL_HISTORY"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Basal.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Basal.java new file mode 100644 index 0000000000..4aec1d0352 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Basal.java @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import java.util.Date; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_History_Basal extends DanaRS_Packet_History_ { + + public DanaRS_Packet_History_Basal() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BASAL; + } + + public DanaRS_Packet_History_Basal(Date from) { + super(from); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BASAL; + } + + @Override + public String getFriendlyName() { + return "REVIEW__BASAL"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Blood_Glucose.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Blood_Glucose.java new file mode 100644 index 0000000000..22bb3b5c2e --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Blood_Glucose.java @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import java.util.Date; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_History_Blood_Glucose extends DanaRS_Packet_History_ { + + public DanaRS_Packet_History_Blood_Glucose() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BLOOD_GLUCOSE; + } + + public DanaRS_Packet_History_Blood_Glucose(Date from) { + super(from); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BLOOD_GLUCOSE; + } + + @Override + public String getFriendlyName() { + return "REVIEW__BLOOD_GLUCOSE"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Bolus.java new file mode 100644 index 0000000000..7451f921be --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Bolus.java @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import java.util.Date; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_History_Bolus extends DanaRS_Packet_History_ { + + public DanaRS_Packet_History_Bolus() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BOLUS; + } + + public DanaRS_Packet_History_Bolus(Date from) { + super(from); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BOLUS; + } + + @Override + public String getFriendlyName() { + return "REVIEW__BOLUS"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Carbohydrate.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Carbohydrate.java new file mode 100644 index 0000000000..df2f5c762d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Carbohydrate.java @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import java.util.Date; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_History_Carbohydrate extends DanaRS_Packet_History_ { + + public DanaRS_Packet_History_Carbohydrate() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__CARBOHYDRATE; + } + + public DanaRS_Packet_History_Carbohydrate(Date from) { + super(from); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__CARBOHYDRATE; + } + + @Override + public String getFriendlyName() { + return "REVIEW__CARBOHYDRATE"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Daily.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Daily.java new file mode 100644 index 0000000000..b55754ba2f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Daily.java @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import java.util.Date; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_History_Daily extends DanaRS_Packet_History_ { + + public DanaRS_Packet_History_Daily() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__DAILY; + } + + public DanaRS_Packet_History_Daily(Date from) { + super(from); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__DAILY; + } + + @Override + public String getFriendlyName() { + return "REVIEW__DAILY"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Prime.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Prime.java new file mode 100644 index 0000000000..b5dbf7ff93 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Prime.java @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import java.util.Date; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_History_Prime extends DanaRS_Packet_History_ { + + public DanaRS_Packet_History_Prime() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__PRIME; + } + + public DanaRS_Packet_History_Prime(Date from) { + super(from); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__PRIME; + } + + @Override + public String getFriendlyName() { + return "REVIEW__PRIME"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Refill.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Refill.java new file mode 100644 index 0000000000..66094e3fb6 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Refill.java @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import java.util.Date; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_History_Refill extends DanaRS_Packet_History_ { + + public DanaRS_Packet_History_Refill() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__REFILL; + } + + public DanaRS_Packet_History_Refill(Date from) { + super(from); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__REFILL; + } + + @Override + public String getFriendlyName() { + return "REVIEW__REFILL"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Suspend.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Suspend.java new file mode 100644 index 0000000000..20f1c3d6ff --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Suspend.java @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import java.util.Date; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_History_Suspend extends DanaRS_Packet_History_ { + + public DanaRS_Packet_History_Suspend() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SUSPEND; + } + + public DanaRS_Packet_History_Suspend(Date from) { + super(from); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SUSPEND; + } + + @Override + public String getFriendlyName() { + return "REVIEW__SUSPEND"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Temporary.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Temporary.java new file mode 100644 index 0000000000..7d63e1bfff --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Temporary.java @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import java.util.Date; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_History_Temporary extends DanaRS_Packet_History_ { + + public DanaRS_Packet_History_Temporary() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__TEMPORARY; + } + + public DanaRS_Packet_History_Temporary(Date from) { + super(from); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__TEMPORARY; + } + + @Override + public String getFriendlyName() { + return "REVIEW__TEMPORARY"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Alarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Alarm.java new file mode 100644 index 0000000000..88edd13a63 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Alarm.java @@ -0,0 +1,88 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; + +import com.cozmo.danar.util.BleCommandUtil; + +import info.nightscout.utils.NSUpload; + +public class DanaRS_Packet_Notify_Alarm extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Notify_Alarm.class); + + private int alarmCode; + + public DanaRS_Packet_Notify_Alarm() { + super(); + type = BleCommandUtil.DANAR_PACKET__TYPE_NOTIFY; + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_NOTIFY__ALARM; + } + + @Override + public void handleMessage(byte[] data) { + alarmCode = byteArrayToInt(getBytes(data, DATA_START, 1)); + String errorString = ""; + + switch (alarmCode) { + case 0x01: + // Battery 0% Alarm + errorString = MainApp.sResources.getString(R.string.batterydischarged); + break; + case 0x02: + // Pump Error + errorString = MainApp.sResources.getString(R.string.pumperror) + " " + alarmCode; + break; + case 0x03: + // Occlusion + errorString = MainApp.sResources.getString(R.string.occlusion); + break; + case 0x04: + // LOW BATTERY + errorString = MainApp.sResources.getString(R.string.lowbattery); + break; + case 0x05: + // Shutdown + errorString = MainApp.sResources.getString(R.string.lowbattery); + break; + case 0x06: + // Basal Compare + errorString = "BasalCompare ????"; + break; + case 0x09: + // Empty Reservoir + errorString = MainApp.sResources.getString(R.string.emptyreservoir); + break; + + // BT + case 0x07: + case 0xFF: + // Blood sugar measurement alert + errorString = MainApp.sResources.getString(R.string.bloodsugarmeasurementalert); + break; + + case 0x08: + case 0xFE: + // Remaining insulin level + errorString = MainApp.sResources.getString(R.string.remaininsulinalert); + break; + + case 0xFD: + // Blood sugar check miss alarm + errorString = "Blood sugar check miss alarm ???"; + break; + } + + if (Config.logDanaMessageDetail) + log.debug("Error detected: " + errorString); + NSUpload.uploadError(errorString); + } + + @Override + public String getFriendlyName() { + return "NOTIFY__ALARM"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java new file mode 100644 index 0000000000..88327e1201 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java @@ -0,0 +1,54 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; + +import com.cozmo.danar.util.BleCommandUtil; + +import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; + +public class DanaRS_Packet_Notify_Delivery_Complete extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Notify_Delivery_Complete.class); + + private static Treatment t; + private static double amount; + + public DanaRS_Packet_Notify_Delivery_Complete() { + super(); + type = BleCommandUtil.DANAR_PACKET__TYPE_NOTIFY; + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_NOTIFY__DELIVERY_COMPLETE; + } + + public DanaRS_Packet_Notify_Delivery_Complete(double amount, Treatment t) { + this(); + this.amount = amount; + this.t = t; + } + + @Override + public void handleMessage(byte[] data) { + double deliveredInsulin = byteArrayToInt(getBytes(data, DATA_START, 2)) / 100d; + + if (t != null) { + t.insulin = deliveredInsulin; + EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); + bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivering), deliveredInsulin); + bolusingEvent.t = t; + bolusingEvent.percent = Math.min((int) (deliveredInsulin / amount * 100), 100); + MainApp.bus().post(bolusingEvent); + } + + if (Config.logDanaMessageDetail) + log.debug("Delivered insulin: " + deliveredInsulin); + } + + @Override + public String getFriendlyName() { + return "NOTIFY__DELIVERY_COMPLETE"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java new file mode 100644 index 0000000000..26c12c27af --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java @@ -0,0 +1,56 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import com.cozmo.danar.util.BleCommandUtil; +import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; + +public class DanaRS_Packet_Notify_Delivery_Rate_Display extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Notify_Delivery_Rate_Display.class); + + private static Treatment t; + private static double amount; + + public static long lastReceive = 0; + + public DanaRS_Packet_Notify_Delivery_Rate_Display() { + super(); + type = BleCommandUtil.DANAR_PACKET__TYPE_NOTIFY; + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_NOTIFY__DELIVERY_RATE_DISPLAY; + } + + public DanaRS_Packet_Notify_Delivery_Rate_Display(double amount, Treatment t) { + this(); + this.amount = amount; + this.t = t; + lastReceive = System.currentTimeMillis(); + } + + @Override + public void handleMessage(byte[] data) { + double deliveredInsulin = byteArrayToInt(getBytes(data, DATA_START, 2)) / 100d; + + if (t != null) { + lastReceive = System.currentTimeMillis(); + t.insulin = deliveredInsulin; + EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); + bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivering), deliveredInsulin); + bolusingEvent.t = t; + bolusingEvent.percent = Math.min((int) (deliveredInsulin / amount * 100), 100); + MainApp.bus().post(bolusingEvent); + } + + if (Config.logDanaMessageDetail) + log.debug("Delivered insulin so far: " + deliveredInsulin); + } + + @Override + public String getFriendlyName() { + return "NOTIFY__DELIVERY_RATE_DISPLAY"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.java new file mode 100644 index 0000000000..3af0c209b5 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.java @@ -0,0 +1,54 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Notify_Missed_Bolus_Alarm extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Notify_Missed_Bolus_Alarm.class); + + public DanaRS_Packet_Notify_Missed_Bolus_Alarm() { + super(); + type = BleCommandUtil.DANAR_PACKET__TYPE_NOTIFY; + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_NOTIFY__MISSED_BOLUS_ALARM; + } + + @Override + public void handleMessage(byte[] data) { + int startHour; + int startMin; + int endHour; + int endMin; + + int dataIndex = DATA_START; + int dataSize = 1; + startHour = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + startMin = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + endHour = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + endMin = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + if (Config.logDanaMessageDetail) { + log.debug("Start hour: " + startHour); + log.debug("Start min: " + startMin); + log.debug("End hour: " + endHour); + log.debug("End min: " + endMin); + } + } + + @Override + public String getFriendlyName() { + return "NOTIFY__MISSED_BOLUS_ALARM"; + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.java new file mode 100644 index 0000000000..4bfebb5211 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.java @@ -0,0 +1,61 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_Option_Get_Pump_Time extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Option_Get_Pump_Time.class); + + public DanaRS_Packet_Option_Get_Pump_Time() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_OPTION__GET_PUMP_TIME; + if (Config.logDanaMessageDetail) { + log.debug("Requesting pump time"); + } + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + int year = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int month = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int day = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int hour = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int min = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int sec = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + Date time = new Date(100 + year, month - 1, day, hour, min, sec); + DanaRPump.getInstance().pumpTime = time; + + if (Config.logDanaMessageDetail) { + log.debug("Pump time " + time.toLocaleString()); + } + } + + @Override + public String getFriendlyName() { + return "OPTION__GET_PUMP_TIME"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_User_Option.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_User_Option.java new file mode 100644 index 0000000000..b4df373f9c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_User_Option.java @@ -0,0 +1,114 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Option_Get_User_Option extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Option_Get_User_Option.class); + + + public DanaRS_Packet_Option_Get_User_Option() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_OPTION__GET_USER_OPTION; + if (Config.logDanaMessageDetail) { + log.debug("Requesting user settings"); + } + } + + @Override + public void handleMessage(byte[] data) { + DanaRPump pump = DanaRPump.getInstance(); + + int dataIndex = DATA_START; + int dataSize = 1; + pump.timeDisplayType = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.buttonScrollOnOff = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.beepAndAlarm = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.lcdOnTimeSec = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.backlightOnTimeSec = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.selectedLanguage = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.units = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.shutdownHour = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + pump.lowReservoirRate = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.cannulaVolume = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 2; + pump.refillAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int selectableLanguage1 = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int selectableLanguage2 = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int selectableLanguage3 = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int selectableLanguage4 = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + dataIndex += dataSize; + dataSize = 1; + int selectableLanguage5 = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + + if (Config.logDanaMessageDetail) { + log.debug("timeDisplayType: " + pump.timeDisplayType); + log.debug("buttonScrollOnOff: " + pump.buttonScrollOnOff); + log.debug("beepAndAlarm: " + pump.beepAndAlarm); + log.debug("lcdOnTimeSec: " + pump.lcdOnTimeSec); + log.debug("backlightOnTimeSec: " + pump.backlightOnTimeSec); + log.debug("selectedLanguage: " + pump.selectedLanguage); + log.debug("Pump units: " + (pump.units == DanaRPump.UNITS_MGDL ? "MGDL" : "MMOL")); + log.debug("shutdownHour: " + pump.shutdownHour); + log.debug("lowReservoirRate: " + pump.lowReservoirRate); + log.debug("refillAmount: " + pump.refillAmount); + log.debug("selectableLanguage1: " + selectableLanguage1); + log.debug("selectableLanguage2: " + selectableLanguage2); + log.debug("selectableLanguage3: " + selectableLanguage3); + log.debug("selectableLanguage4: " + selectableLanguage4); + log.debug("selectableLanguage5: " + selectableLanguage5); + } + } + + @Override + public String getFriendlyName() { + return "OPTION__GET_USER_OPTION"; + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.java new file mode 100644 index 0000000000..e93e18796d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.java @@ -0,0 +1,56 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Option_Set_Pump_Time extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Option_Set_Pump_Time.class); + private Date date; + public int error; + + public DanaRS_Packet_Option_Set_Pump_Time() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_OPTION__SET_PUMP_TIME; + } + + public DanaRS_Packet_Option_Set_Pump_Time(Date date) { + this(); + this.date = date; + if (Config.logDanaMessageDetail) { + log.debug("Setting pump time " + date.toLocaleString()); + } + } + + @Override + public byte[] getRequestParams() { + byte[] request = new byte[6]; + request[0] = (byte) ((date.getYear() - 100) & 0xff); + request[1] = (byte) ((date.getMonth() + 1) & 0xff); + request[2] = (byte) (date.getDate() & 0xff); + request[3] = (byte) (date.getHours() & 0xff); + request[4] = (byte) (date.getMinutes() & 0xff); + request[5] = (byte) (date.getSeconds() & 0xff); + return request; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + } + } + + @Override + public String getFriendlyName() { + return "OPTION__SET_PUMP_TIME"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_User_Option.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_User_Option.java new file mode 100644 index 0000000000..49c6d35708 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_User_Option.java @@ -0,0 +1,58 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import com.cozmo.danar.util.BleCommandUtil; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +public class DanaRS_Packet_Option_Set_User_Option extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Option_Set_User_Option.class); + + private int error; + + public DanaRS_Packet_Option_Set_User_Option() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_OPTION__SET_USER_OPTION; + if (Config.logDanaMessageDetail) { + log.debug("Setting user settings"); + } + } + + @Override + public byte[] getRequestParams() { + DanaRPump pump = DanaRPump.getInstance(); + + byte[] request = new byte[13]; + request[0] = (byte) (pump.timeDisplayType & 0xff); + request[1] = (byte) (pump.buttonScrollOnOff & 0xff); + request[2] = (byte) (pump.beepAndAlarm & 0xff); + request[3] = (byte) (pump.lcdOnTimeSec & 0xff); + request[4] = (byte) (pump.backlightOnTimeSec & 0xff); + request[5] = (byte) (pump.selectedLanguage & 0xff); + request[6] = (byte) (pump.units & 0xff); + request[7] = (byte) (pump.shutdownHour & 0xff); + request[8] = (byte) (pump.lowReservoirRate & 0xff); + request[9] = (byte) (pump.cannulaVolume & 0xff); + request[10] = (byte) ((pump.cannulaVolume >>> 8) & 0xff); + request[11] = (byte) (pump.refillAmount & 0xff); + request[12] = (byte) ((pump.refillAmount >>> 8) & 0xff); + return request; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 1; + error = byteArrayToInt(getBytes(data, dataIndex, dataSize)); + if (Config.logDanaMessageDetail) { + log.debug("Result: " + error); + } + } + + @Override + public String getFriendlyName() { + return "OPTION__SET_USER_OPTION"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Review_Bolus_Avg.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Review_Bolus_Avg.java new file mode 100644 index 0000000000..e8440b12d2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Review_Bolus_Avg.java @@ -0,0 +1,52 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; + +import com.cozmo.danar.util.BleCommandUtil; + +public class DanaRS_Packet_Review_Bolus_Avg extends DanaRS_Packet { + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Review_Bolus_Avg.class); + + public DanaRS_Packet_Review_Bolus_Avg() { + super(); + opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BOLUS_AVG; + } + + @Override + public void handleMessage(byte[] data) { + int dataIndex = DATA_START; + int dataSize = 2; + double bolusAvg03 = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + double bolusAvg07 = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + double bolusAvg14 = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + double bolusAvg21 = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + + dataIndex += dataSize; + dataSize = 2; + double bolusAvg28 = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; + if (Config.logDanaMessageDetail) { + log.debug("Bolus average 3d: " + bolusAvg03 + " U"); + log.debug("Bolus average 7d: " + bolusAvg07 + " U"); + log.debug("Bolus average 14d: " + bolusAvg14 + " U"); + log.debug("Bolus average 21d: " + bolusAvg21 + " U"); + log.debug("Bolus average 28d: " + bolusAvg28 + " U"); + } + } + + @Override + public String getFriendlyName() { + return "REVIEW__BOLUS_AVG"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSConnection.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSConnection.java new file mode 100644 index 0000000000..5fd00402e0 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSConnection.java @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.events; + +import android.bluetooth.BluetoothDevice; + +/** + * Created by mike on 01.09.2017. + */ + +public class EventDanaRSConnection { + public EventDanaRSConnection(boolean isConnect, boolean isBusy, boolean isError, BluetoothDevice device) { + this.isConnect = isConnect; + this.isBusy = isBusy; + this.isError = isError; + this.device = device; + } + + public boolean isConnect; + public boolean isBusy; + public boolean isError; + public BluetoothDevice device; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSDeviceChange.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSDeviceChange.java new file mode 100644 index 0000000000..8ae02d47ff --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSDeviceChange.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.events; + +/** + * Created by mike on 05.09.2017. + */ + +public class EventDanaRSDeviceChange { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPacket.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPacket.java new file mode 100644 index 0000000000..5815399194 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPacket.java @@ -0,0 +1,15 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.events; + +import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet; + +/** + * Created by mike on 01.09.2017. + */ + +public class EventDanaRSPacket { + public EventDanaRSPacket(DanaRS_Packet data) { + this.data = data; + } + + public DanaRS_Packet data; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPairingSuccess.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPairingSuccess.java new file mode 100644 index 0000000000..d50091de55 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPairingSuccess.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.events; + +/** + * Created by mike on 01.09.2017. + */ + +public class EventDanaRSPairingSuccess { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java new file mode 100644 index 0000000000..e131c903f9 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java @@ -0,0 +1,671 @@ +package info.nightscout.androidaps.plugins.PumpDanaRS.services; + +import android.app.Service; +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.Binder; +import android.os.Handler; +import android.os.IBinder; +import android.os.PowerManager; + +import com.cozmo.danar.util.BleCommandUtil; +import com.squareup.otto.Subscribe; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRSMessageHashTable; +import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.events.EventAppExit; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.PumpDanaRS.activities.PairingHelperActivity; +import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSConnection; +import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSPacket; +import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSPairingSuccess; +import info.nightscout.utils.SP; + +public class DanaRSService extends Service { + private static Logger log = LoggerFactory.getLogger(DanaRSService.class); + + private static final long WRITE_DELAY_MILLIS = 50; + + public static String UART_READ_UUID = "0000fff1-0000-1000-8000-00805f9b34fb"; + public static String UART_WRITE_UUID = "0000fff2-0000-1000-8000-00805f9b34fb"; + + private byte PACKET_START_BYTE = (byte) 0xA5; + private byte PACKET_END_BYTE = (byte) 0x5A; + + private BluetoothManager mBluetoothManager = null; + private BluetoothAdapter mBluetoothAdapter = null; + private BluetoothDevice mBluetoothDevice = null; + private String mBluetoothDeviceAddress = null; + private String mBluetoothDeviceName = null; + private BluetoothGatt mBluetoothGatt = null; + + private boolean isConnected = false; + private boolean isConnecting = false; + + private BluetoothGattCharacteristic UART_Read; + private BluetoothGattCharacteristic UART_Write; + + private PowerManager.WakeLock mWakeLock; + private IBinder mBinder = new LocalBinder(); + + private Handler mHandler = null; + + private DanaRS_Packet processsedMessage = null; + private ArrayList mSendQueue = new ArrayList<>(); + + + public DanaRSService() { + mHandler = new Handler(); + try { + MainApp.bus().unregister(this); + } catch (RuntimeException x) { + // Ignore + } + initialize(); + MainApp.bus().register(this); + } + + public boolean bolus(double insulin, int carbs, long l, Treatment t) { + return false; + } + + public void bolusStop() { + } + + public boolean tempBasal(Integer percent, int durationInHours) { + return false; + } + + public boolean highTempBasal(Integer percent) { + return false; + } + + public void tempBasalStop() { + } + + public boolean extendedBolus(Double insulin, int durationInHalfHours) { + return false; + } + + public void extendedBolusStop() { + } + + public boolean updateBasalsInPump(Profile profile) { + return false; + } + + public boolean loadHistory(byte type) { + return false; + } + + + public class LocalBinder extends Binder { + public DanaRSService getServiceInstance() { + return DanaRSService.this; + } + } + + @Override + public IBinder onBind(Intent intent) { + return mBinder; + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + return START_STICKY; + } + + @Subscribe + public void onStatusEvent(EventAppExit event) { + if (Config.logFunctionCalls) + log.debug("EventAppExit received"); + + stopSelf(); + if (Config.logFunctionCalls) + log.debug("EventAppExit finished"); + } + + private boolean initialize() { + log.debug("Initializing service."); + + if (mBluetoothManager == null) { + mBluetoothManager = ((BluetoothManager) MainApp.instance().getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE)); + if (mBluetoothManager == null) { + log.debug("Unable to initialize BluetoothManager."); + return false; + } + } + + mBluetoothAdapter = mBluetoothManager.getAdapter(); + if (mBluetoothAdapter == null) { + log.debug("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) { + 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.debug("unspecified address."); + return false; + } + + isConnecting = true; + if ((mBluetoothDeviceAddress != null) && (address.equals(mBluetoothDeviceAddress)) && (mBluetoothGatt != null)) { + log.debug("Trying to use an existing mBluetoothGatt for connection."); + if (mBluetoothGatt.connect()) { + setCharacteristicNotification(getUARTReadBTGattChar(), true); + return true; + } + return false; + } + + BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); + if (device == null) { + log.debug("Device not found. Unable to connect."); + return false; + } + + mBluetoothGatt = device.connectGatt(getApplicationContext(), false, mGattCallback); + setCharacteristicNotification(getUARTReadBTGattChar(), true); + log.debug("Trying to create a new connection."); + mBluetoothDevice = device; + mBluetoothDeviceAddress = address; + mBluetoothDeviceName = device.getName(); + return true; + } + + public void disconnect(String from) { + log.debug("disconnect from: " + from); + if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { + return; + } + setCharacteristicNotification(getUARTReadBTGattChar(), false); + mBluetoothGatt.disconnect(); + isConnected = false; + } + + public void close() { + log.debug("BluetoothAdapter close"); + if (mBluetoothGatt == null) { + return; + } + mBluetoothGatt.close(); + mBluetoothGatt = null; + } + + public BluetoothDevice getConnectDevice() { + return mBluetoothDevice; + } + + public String getConnectDeviceAddress() { + return mBluetoothDeviceAddress; + } + + public String getConnectDeviceName() { + return mBluetoothDeviceName; + } + + private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { + public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { + log.debug("onConnectionStateChange"); + + if (newState == BluetoothProfile.STATE_CONNECTED) { + mBluetoothGatt.discoverServices(); + } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { + close(); + isConnected = false; + sendBTConnect(false, false, false, null); + } + } + + public void onServicesDiscovered(BluetoothGatt gatt, int status) { + log.debug("onServicesDiscovered"); + + isConnecting = false; + + if (status == BluetoothGatt.GATT_SUCCESS) { + findCharacteristic(); + } + + // 1st message sent to pump after connect + byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK, null, getConnectDeviceName()); + log.debug(">>>>> " + "ENCRYPTION__PUMP_CHECK (0x00)" + " " + DanaRS_Packet.toHexString(bytes)); + writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes); + } + + public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { + log.debug("onCharacteristicRead" + (characteristic != null ? ":" + DanaRS_Packet.toHexString(characteristic.getValue()) : "")); + readDataParsing(characteristic.getValue()); + } + + public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { + log.debug("onCharacteristicChanged" + (characteristic != null ? ":" + DanaRS_Packet.toHexString(characteristic.getValue()) : "")); + readDataParsing(characteristic.getValue()); + } + + public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { + log.debug("onCharacteristicWrite" + (characteristic != null ? ":" + DanaRS_Packet.toHexString(characteristic.getValue()) : "")); + 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); + } + } + } + }; + + public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { + log.debug("setCharacteristicNotification"); + if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { + log.debug("BluetoothAdapter not initialized_ERROR"); + return; + } + mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); + } + + public void readCharacteristic(BluetoothGattCharacteristic characteristic) { + log.debug("readCharacteristic"); + if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { + log.debug("BluetoothAdapter not initialized_ERROR"); + return; + } + mBluetoothGatt.readCharacteristic(characteristic); + } + + public void writeCharacteristic_NO_RESPONSE(final BluetoothGattCharacteristic characteristic, final byte[] data) { + if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { + log.debug("BluetoothAdapter not initialized_ERROR"); + return; + } + + new Thread(new Runnable() { + public void run() { + try { + Thread.sleep(WRITE_DELAY_MILLIS); + characteristic.setValue(data); + characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE); + mBluetoothGatt.writeCharacteristic(characteristic); + //log.debug("writeCharacteristic:" + DanaRS_Packet.toHexString(data)); + } catch (Exception e) { + } + } + }).start(); + } + + public 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; + } + + public BluetoothGattCharacteristic getUARTWriteBTGattChar() { + if (UART_Write == null) { + UART_Write = new BluetoothGattCharacteristic(UUID.fromString(UART_WRITE_UUID), BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE, 0); + } + return UART_Write; + } + + public List getSupportedGattServices() { + log.debug("getSupportedGattServices"); + if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { + log.debug("BluetoothAdapter not initialized_ERROR"); + return null; + } + + return mBluetoothGatt.getServices(); + } + + private void findCharacteristic() { + List gattServices = getSupportedGattServices(); + + if (gattServices == null) { + return; + } + String uuid = null; + + 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 byte[] readBuffer = new byte[1024]; + private int bufferLength = 0; + + private void readDataParsing(byte[] buffer) { + boolean startSignatureFound = false, packetIsValid = false; + boolean isProcessing; + + if (buffer == null || buffer.length == 0) { + return; + } + + // Append incomming data to input buffer + System.arraycopy(buffer, 0, readBuffer, bufferLength, buffer.length); + bufferLength += buffer.length; + + isProcessing = true; + + while (isProcessing) { + // 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 + 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 + int length = 0; + 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) { + // copy packet to input buffer + byte[] inputBuffer = new byte[length + 7]; + System.arraycopy(readBuffer, 0, inputBuffer, 0, length + 7); + // now we have encrypted packet in inputBuffer + try { + // decrypt the packet + inputBuffer = BleCommandUtil.getInstance().getDecryptedPacket(inputBuffer); + + 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') { + log.debug("<<<<< " + "ENCRYPTION__PUMP_CHECK (OK)" + " " + DanaRS_Packet.toHexString(inputBuffer)); + // Grab pairing key from preferences if exists + String pairingKey = SP.getString(R.string.key_danars_pairingkey, null); + 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); + 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] == 'B' && inputBuffer[3] == 'U' && inputBuffer[4] == 'S' && inputBuffer[5] == 'Y') { + log.debug("<<<<< " + "ENCRYPTION__PUMP_CHECK (BUSY)" + " " + DanaRS_Packet.toHexString(inputBuffer)); + sendBTConnect(false, true, false, null); + } else { + log.debug("<<<<< " + "ENCRYPTION__PUMP_CHECK (ERROR)" + " " + DanaRS_Packet.toHexString(inputBuffer)); + sendBTConnect(false, false, true, null); + } + break; + // 2nd packet, pairing key + case (byte) BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY: + 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: + 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: + log.debug("<<<<< " + "ENCRYPTION__PASSKEY_RETURN " + DanaRS_Packet.toHexString(inputBuffer)); + // Paring is successfull, sending time info + MainApp.bus().post(new EventDanaRSPairingSuccess()); + SendTimeInfo(); + byte[] pairingKey = {inputBuffer[2], inputBuffer[3]}; + // store pairing key to preferences + SP.putString(R.string.key_danars_pairingkey, DanaRS_Packet.bytesToHex(pairingKey)); + 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: + 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.getInstance().rs_password = Integer.toHexString(pass); + log.debug("Pump user password: " + Integer.toHexString(pass)); + sendBTConnect(true, false, false, getConnectDevice()); + 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) { + log.debug("<<<<< " + message.getFriendlyName() + " " + DanaRS_Packet.toHexString(inputBuffer)); + // process received data + message.handleMessage(inputBuffer); + message.setReceived(); + synchronized (message) { + // notify to sendMessage + message.notify(); + } + MainApp.bus().post(new EventDanaRSPacket(message)); + } else { + log.error("Unknown message received " + DanaRS_Packet.toHexString(inputBuffer)); + } + break; + } + } catch (Exception e) { + e.printStackTrace(); + } + // Cut off the message from readBuffer + System.arraycopy(readBuffer, length + 7, readBuffer, 0, bufferLength - (length + 7)); + bufferLength -= (length + 7); + 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(); + 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); + e.printStackTrace(); + } + } + + try { + Thread.sleep(200); + } catch (InterruptedException e) { + } + if (!message.isReceived()) { + log.warn("Reply not received " + message.getFriendlyName()); + } + } + + 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); + log.debug(">>>>> " + "ENCRYPTION__PASSKEY_REQUEST" + " " + 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); + log.debug(">>>>> " + "ENCRYPTION__TIME_INFORMATION" + " " + DanaRS_Packet.toHexString(bytes)); + writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes); + } + + private void sendBTConnect(boolean isConnected, boolean isBusy, boolean isError, BluetoothDevice device) { + if (isConnected) { + this.isConnected = true; + } else { + mSendQueue.clear(); + } + + MainApp.bus().post(new EventDanaRSConnection(isConnected, isBusy, isError, device)); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 65d3917381..eb08a06b96 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -210,7 +210,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, @Override public boolean isInitialized() { - return pump.lastConnection.getTime() > 0 && pump.isExtendedBolusEnabled; + return pump.lastConnection.getTime() > 0; } @Override diff --git a/app/src/main/jniLibs/arm64-v8a/libBleCommandUtil.so b/app/src/main/jniLibs/arm64-v8a/libBleCommandUtil.so new file mode 100644 index 0000000000000000000000000000000000000000..69e283b5feb97bb8a055667ad99ef5a9da19f549 GIT binary patch literal 14000 zcmeHO3vg7|c|Lb9g1dXQ((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!0A5RW3pwu|HHN}!_SPzx3}px4*u>We*c)nIR5UGp|Y=K&p`Vkxy5f_ zmDwuJdIMYjB>dveEKd}_@n~;;Td=;JSu6@HJgAsGQM#kx+X6S;Pn2oQEo9h^_Y5=@uQH|PYwDZe|IQ_MQJQ5?=moVPO8V+;dhewu@>N5)y9I~b{M`(%!%JPz|&;6(c7cFpjKrsX>*uiFDRio*z|F!4)vLh zakV~i{wfOcnV`v_b3iSicF;8D?##Hp7GI-&GSJT*9`}0|yz!!+oUfoB`~*t(;Y~jq zz6A5}r7xL_!vQ7Ard`Z2( zv1ZA-_SRry%{TBn?Hu_V>+u5|eQ)yCJF(biP}jv+tPk{GL63kQ{9PpzC934@x0TCro;@f=S<EEeD1STLUV+;y zaC-%AufXjU_ybx2?nba0o)Gz#gnUOr{?8NgKS; zEi3=*b@KZ)I_D`^bTawP+Iile_!fK?Pl#`z`wV&m^1CQRd3{ySYTp)96274p4ldCv z@Mf%+^M!xKKQq<7S*D^+&Jg@so)EqQ|J-!)+hvg#ly}cQj>VcN&BbHac)o=92UqWg z^7A}z!4hKR@4khMR2tzYOZf*dH6yX|F<@2UxwxdYJCs2;(J+NZ8hqP9Lozf2HSo9)>i)(mWOYA zgCdR2{0+e>jMRi)^gi%$Da*sBwhe*CcClQ)Hzj>1RS|l9ge#h$Qy-$euoLp*i7(mgHL7Sq*pbLD zLxOBbv=??GD3wzX@{4+c7NLx6QsjkQ3hJQ72qZs^E#xO21$={{m5KHOCj=Gq6yuBb zg8v|Izk)hL5V#|#z$t2vw~Wd0MSCB3B$vR&M0@Q-S$q&UD`+(ed)f$WZ$N&OCUho)EN<^97;06a;PMX|aA&{XLA<2>&IH-*aYprIOFbdhKc0%Qf}A}!hp_J0EflR^Ff literal 0 HcmV?d00001 diff --git a/app/src/main/jniLibs/armeabi-v7a/libBleCommandUtil.so b/app/src/main/jniLibs/armeabi-v7a/libBleCommandUtil.so new file mode 100644 index 0000000000000000000000000000000000000000..0c717bc3e836ca2b3bc7a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z!7?OG+{+p6fed#CW&l&%&)6+^3<|*2=%lIU5;+eA~ zb4#nM)rIe9+gy`bY4qDysfJD|>0VcB8@|w$t}c>`X34T#B1@8aIS6Yd^e$Yu^rnO% zXc4s~?sb|?>AU$A%?-6uaZzzG`bzQR0@FSOW*mMaW%|-ZH%a$i!;*~2r3NmAHwu}2 zmXO1Z<1W>W=W_Wg_yTScSI)7bwmN)=>~=0^MNQ3aR}sDuE?T~_zM*z{eJv}h?PzN2 zXpCZaD=VsVw$(9>CMNy`4LfGg{MeWs6QDdXiB?(~+^h&6eB*D3SA+^J8?Dlp$VIKq zwe$&b5k4cYw>w)~ogJ(QRd>7&PR_>q8m!U`9#L9+Xv~W6>3E~734LQaka4Du2}x@> z-MAMlU+H$W!9M?Np_qZIXy584{(p)1e2N_^`=7*d?DQI*PqX0O}(; zia`R3!FVBBDn$T_QyQY!B*5=}S{q2?M?7Z(C|-z;Vv6AVsK;3nCMX3^oKc-(j)3Ad zQ9d-84M1^7bQFsO66zPz;ddkLyJ(`L+(S@_I<={gY?OoQ0OYe}0Lobel*5RQ@=u(u z0d>+H!((xI9QAl1Ix6=7;&hZF2^?2yL)u?)I{a>^(a}0PzZZp`ugJ7@so4bpzZSxY z|DT2Sl1f~@UesybnE=Wu1cj)_3yl$M2H>5g*-QKXIoL?DL%hW0+lCIxpJZ3cl@8Fw z$B34AQP~9`n-HD$|9L=X#vrw+#O3=9>NJP?>D%u0GZ=HD9xrj;uc0GO$1G^b7p@zp zJAfgQoA?P90O-b}9xrjax6wiTFsv1#bH(a}XpG>G0E(k{X#gGhU%bTm9YF`yY>D@; a1zkzJ0ZhE85RTh`+WnyWD^+48PWL~3K&c}D literal 0 HcmV?d00001 diff --git a/app/src/main/jniLibs/armeabi/libBleCommandUtil.so b/app/src/main/jniLibs/armeabi/libBleCommandUtil.so new file mode 100644 index 0000000000000000000000000000000000000000..a51a8c7d9a16654b7d0e34c9d6e15b1a866b74f9 GIT binary patch literal 13724 zcmeHOeRNaTk-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m>$9dg z1^p@XS!nveG;0+6ZV#b9ni-=H_dI(*1;0ll{;@D<*rMVl{H_(|46a_ zAH&P9nuLpZQkp@XZUPLGlZxej)pnC1|d{~Y=V3Y$*&4D?oR z)R%Q=^BgWmi0^XP+EndaXVADQ$SKGqgxwM7B4pj#wbyFlbvJIfRBLX!rfHkDCUWJ~ zkt^3+rGTp zcnQZ=XN~#%{f{j|@!r8Lq%cTt1vO>*GTD)=(M?U?`F7{cO-6URr{Cz!P}4}N zH$B)hL`{Q3*;EtCG<9!D_b2}#ousBdBhyDs$?b!g?E|*Xj*ykdnJ=>fain2-aeivb zrnY6BZ)LJuy7@yxNh51eQ>riCGhz&+;(bXJa6{CT9!zKB#>j}Votkc9F%1TId3b3+sOIY z=CPbYUN$!z$9dTHwL{qcaU9!77PgJ9LlMh$;4j-PPGXzIaxMJa7IqxZavOy09Q)bU zv1sr^S@xa3%dQVn4dHxjb6J>!TOa3RhJOO#HgI{i4=h~_)p6Vhc6UJBd~DBHEF*2D z+WlqkE+^j_Xn%t(-{J(vaUCpw?r3gbC-Sjug5Py+KORH`=jVKfkcXv}BOK@E+mA5s zTg;mGEEYG7v%3BX_<0#}KHke%n1k!we1C@sX2Rb+i99SV_%6q><9uB1IE0(S_3^&I z;xec$O(?)Z?bz8@;>I36~Ld)+S&bZi?Fu(>SXLfzIWY1&~Co}1MRzcO#lD@ literal 0 HcmV?d00001 diff --git a/app/src/main/jniLibs/mips64/libBleCommandUtil.so b/app/src/main/jniLibs/mips64/libBleCommandUtil.so new file mode 100644 index 0000000000000000000000000000000000000000..a8a292ea13037eccfe791f25e6526e8947b64a24 GIT binary patch literal 14808 zcmeHO4RBo5bw2OyYPB-{Sz{T5G5D>tE3XYJFUD!s#8Y-9gB=1?fT6C3X0_V4`YHO^ zN^3`ETv*u-XeMM>8N2iY7zl2gCL$0l0{Hbi z@7=q4T1(hYXs6S1HBaZ>bMLwL+;h)8_niCQ-hIvW*Q$y_GC9aiW@)yCiHM5+E3Hha zlX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;rf~77_Wy*H>I9;_kRY& zck9zTXy*&2hr>5GJi_4^he<*a`MibVrAxn-wGf|xyRsJL&w$DKgB^=4^=fb;WON<#W}e-H|6H$F3HWxTKE76E3<(0`R*!B zsKVVi2B1Z!$5Z>Xu1 zaw@mfHEr2s!9b&wv$3LSqh!)>F{TvC!9o1It{e;)Le~sp+8<-~w!#5V|uY1DsLqJ2zLD)#wAh9f8*N=#xO3mokWYD4e~`yk*TU+`qVC@YqY zup9pb9MuVaVLt>E_5&nl68lG#bC4mEBKU=U5%8y+P}Gb5#W)tBp7x%o7yDPhh12*2 zoq!(H)7}x*o1N-zc~K{JT46PG(OQL z-Bl1jeJ4lBSTGgx&B zk5QrEq4}jG&L{DII6_ZW?WF!ic{?(6)(L)be%*hAMIq)(&`&S_3KcYWf?u2q;{Tk) z|1*ht!7t>ZceJ?=E8b1?+98Tx&o5nBYbHZE;PN$z<-UBki z3Hej + + + + + + + diff --git a/app/src/main/res/layout/danars_blescanner_item.xml b/app/src/main/res/layout/danars_blescanner_item.xml new file mode 100644 index 0000000000..2c620b532f --- /dev/null +++ b/app/src/main/res/layout/danars_blescanner_item.xml @@ -0,0 +1,33 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/danars_pairingprogressdialog.xml b/app/src/main/res/layout/danars_pairingprogressdialog.xml new file mode 100644 index 0000000000..fc8c97836f --- /dev/null +++ b/app/src/main/res/layout/danars_pairingprogressdialog.xml @@ -0,0 +1,41 @@ + + + + + + + + +