diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index db66ffec38..2465b9d9a5 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,10 +1,10 @@ Reporting bugs -------------- -- Note the precise time the problem occurred and describe the circumstances and steps that caused +- **Note the precise time the problem occurred** and describe the circumstances and steps that caused the problem - Note the Build version (found in the About dialog in the app, when pressing the three dots in the upper-right corner). - Obtain the app's log files, which can be found on the phone in _/storage/emulated/0/Android/data/info.nightscout.androidaps/_ See https://github.com/MilosKozak/AndroidAPS/wiki/Accessing-logfiles -- Open an issue at https://github.com/MilosKozak/AndroidAPS/issues/new \ No newline at end of file +- Open an issue at https://github.com/MilosKozak/AndroidAPS/issues/new diff --git a/README.md b/README.md index deeea159bc..d1e1e8a47c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # AndroidAPS -* Check the wiki: https://github.com/MilosKozak/AndroidAPS/wiki +* Check the wiki: http://wiki.androidaps.org * Everyone who’s been looping with AndroidAPS needs to fill out the form after 3 days of looping https://docs.google.com/forms/d/14KcMjlINPMJHVt28MDRupa4sz4DDIooI4SrW0P3HSN8/viewform?c=0&w=1 [![Gitter](https://badges.gitter.im/MilosKozak/AndroidAPS.svg)](https://gitter.im/MilosKozak/AndroidAPS?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) diff --git a/app/build.gradle b/app/build.gradle index 1f86c015dd..3b55fd2235 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,11 +63,12 @@ android { targetSdkVersion 25 multiDexEnabled true versionCode 1500 - version "2.0g-dev" + version "2.1.3-dev" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"' testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + // if you change minSdkVersion to less than 11, you need to change executeTask for wear ndk { moduleName "BleCommandUtil" @@ -77,7 +78,7 @@ android { // TODO remove once wear dependency com.google.android.gms:play-services-wearable:7.3.0 // has been upgraded (requiring significant code changes), which currently fails release // build with a deprecation warning - abortOnError false + // abortOnError false // (disabled entirely to avoid reports on the error, which would still be displayed // and it's easy to overlook that it's ignored) checkReleaseBuilds false @@ -106,12 +107,12 @@ android { ] } pumpcontrol { - applicationId "info.nightscout.androidaps" + applicationId "info.nightscout.aapspumpcontrol" dimension "standard" - resValue "string", "app_name", "AndroidAPS" - versionName version + resValue "string", "app_name", "Pumpcontrol" + versionName version + "-pumpcontrol" manifestPlaceholders = [ - appIcon: "@mipmap/blueowl", + appIcon: "@mipmap/ic_pumpcontrol", appIconRound: "@null" ] } @@ -121,7 +122,7 @@ android { resValue "string", "app_name", "NSClient" versionName version + "-nsclient" manifestPlaceholders = [ - appIcon: "@mipmap/yellowowl", + appIcon: "@mipmap/ic_yellowowl", appIconRound: "@null" ] } @@ -131,7 +132,7 @@ android { resValue "string", "app_name", "NSClient2" versionName version + "-nsclient" manifestPlaceholders = [ - appIcon: "@mipmap/yellowowl", + appIcon: "@mipmap/ic_yellowowl", appIconRound: "@null" ] } @@ -155,6 +156,7 @@ allprojects { flatDir { dirs 'libs' } + maven { url 'https://jitpack.io' } } } @@ -166,10 +168,10 @@ dependencies { wearApp project(':wear') implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation("com.crashlytics.sdk.android:crashlytics:2.6.7@aar") { + implementation("com.crashlytics.sdk.android:crashlytics:2.9.9@aar") { transitive = true; } - implementation("com.crashlytics.sdk.android:answers:1.3.12@aar") { + implementation("com.crashlytics.sdk.android:answers:1.4.7@aar") { transitive = true; } libs "MilosKozak:danars-support-lib:master@zip" @@ -194,9 +196,10 @@ dependencies { implementation "org.slf4j:slf4j-api:1.7.12" implementation "com.jjoe64:graphview:4.0.1" implementation "com.joanzapata.iconify:android-iconify-fontawesome:2.1.1" - implementation "com.google.android.gms:play-services-wearable:7.5.0" + implementation 'com.google.android.gms:play-services-wearable:10.2.1' implementation(name: "android-edittext-validator-v1.3.4-mod", ext: "aar") implementation(name: "sightparser-release", ext: "aar") + implementation 'com.madgag.spongycastle:core:1.58.0.0' implementation("com.google.android:flexbox:0.3.0") { exclude group: "com.android.support" @@ -216,6 +219,8 @@ dependencies { implementation "com.jakewharton:butterknife:${butterknifeVersion}" annotationProcessor "com.jakewharton:butterknife-compiler:${butterknifeVersion}" + implementation 'com.github.DavidProdinger:weekdays-selector:1.0.4' + testImplementation "junit:junit:4.12" testImplementation "org.json:json:20140107" testImplementation "org.mockito:mockito-core:2.7.22" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ea96e1f18c..bc12ee8a94 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,6 +12,7 @@ + @@ -31,10 +32,13 @@ android:name=".MainApp" android:allowBackup="true" android:icon="${appIcon}" - android:roundIcon="${appIconRound}" android:label="@string/app_name" + android:roundIcon="${appIconRound}" android:supportsRtl="true" android:theme="@style/AppTheme.NoActionBar"> + @@ -43,30 +47,30 @@ - - + + - + - + - + - + + + + + @@ -94,7 +102,7 @@ @@ -104,7 +112,7 @@ @@ -112,7 +120,7 @@ @@ -150,26 +158,82 @@ android:enabled="true" android:exported="false" /> - + + + + + + + + + + + + + + + + + + - + + + + android:label="@string/title_activity_setup_wizard" + android:theme="@style/AppTheme.NoActionBar" /> - - + + + + - \ No newline at end of file + diff --git a/app/src/main/assets/OpenAPSSMB/basal-set-temp.js b/app/src/main/assets/OpenAPSSMB/basal-set-temp.js index 1686ea2c47..9cb932022c 100644 --- a/app/src/main/assets/OpenAPSSMB/basal-set-temp.js +++ b/app/src/main/assets/OpenAPSSMB/basal-set-temp.js @@ -9,33 +9,32 @@ var tempBasalFunctions = {}; tempBasalFunctions.getMaxSafeBasal = function getMaxSafeBasal(profile) { - var max_daily_safety_multiplier = (isNaN(profile.max_daily_safety_multiplier) || profile.max_daily_safety_multiplier == null) ? 3 : profile.max_daily_safety_multiplier; - var current_basal_safety_multiplier = (isNaN(profile.current_basal_safety_multiplier) || profile.current_basal_safety_multiplier == null) ? 4 : profile.current_basal_safety_multiplier; - - return Math.min(profile.max_basal, max_daily_safety_multiplier * profile.max_daily_basal, current_basal_safety_multiplier * profile.current_basal); + var max_daily_safety_multiplier = (isNaN(profile.max_daily_safety_multiplier) || profile.max_daily_safety_multiplier == null) ? 3 : profile.max_daily_safety_multiplier; + var current_basal_safety_multiplier = (isNaN(profile.current_basal_safety_multiplier) || profile.current_basal_safety_multiplier == null) ? 4 : profile.current_basal_safety_multiplier; + + return Math.min(profile.max_basal, max_daily_safety_multiplier * profile.max_daily_basal, current_basal_safety_multiplier * profile.current_basal); }; tempBasalFunctions.setTempBasal = function setTempBasal(rate, duration, profile, rT, currenttemp) { //var maxSafeBasal = Math.min(profile.max_basal, 3 * profile.max_daily_basal, 4 * profile.current_basal); - + var maxSafeBasal = tempBasalFunctions.getMaxSafeBasal(profile); -var round_basal = require('./round-basal'); - - if (rate < 0) { - rate = 0; - } // if >30m @ 0 required, zero temp will be extended to 30m instead - else if (rate > maxSafeBasal) { - rate = maxSafeBasal; + var round_basal = require('./round-basal'); + + if (rate < 0) { + rate = 0; + } else if (rate > maxSafeBasal) { + rate = maxSafeBasal; } var suggestedRate = round_basal(rate, profile); - if (typeof(currenttemp) !== 'undefined' && typeof(currenttemp.duration) !== 'undefined' && typeof(currenttemp.rate) !== 'undefined' && currenttemp.duration > (duration-10) && currenttemp.duration <= 120 && suggestedRate <= currenttemp.rate * 1.2 && suggestedRate >= currenttemp.rate * 0.8) { + if (typeof(currenttemp) !== 'undefined' && typeof(currenttemp.duration) !== 'undefined' && typeof(currenttemp.rate) !== 'undefined' && currenttemp.duration > (duration-10) && currenttemp.duration <= 120 && suggestedRate <= currenttemp.rate * 1.2 && suggestedRate >= currenttemp.rate * 0.8 && duration > 0 ) { rT.reason += " "+currenttemp.duration+"m left and " + currenttemp.rate + " ~ req " + suggestedRate + "U/hr: no temp required"; return rT; } if (suggestedRate === profile.current_basal) { - if (profile.skip_neutral_temps) { + if (profile.skip_neutral_temps === true) { if (typeof(currenttemp) !== 'undefined' && typeof(currenttemp.duration) !== 'undefined' && currenttemp.duration > 0) { reason(rT, 'Suggested rate is same as profile rate, a temp basal is active, canceling current temp'); rT.duration = 0; @@ -58,4 +57,4 @@ var round_basal = require('./round-basal'); } }; -module.exports = tempBasalFunctions; \ No newline at end of file +module.exports = tempBasalFunctions; diff --git a/app/src/main/java/info/nightscout/androidaps/Constants.java b/app/src/main/java/info/nightscout/androidaps/Constants.java index ffe227dc1b..2ecabfe965 100644 --- a/app/src/main/java/info/nightscout/androidaps/Constants.java +++ b/app/src/main/java/info/nightscout/androidaps/Constants.java @@ -1,6 +1,6 @@ package info.nightscout.androidaps; -import info.nightscout.utils.T; +import info.nightscout.androidaps.utils.T; /** * Created by mike on 07.06.2016. @@ -68,4 +68,7 @@ public class Constants { //SMS Communicator public static final long SMS_CONFIRM_TIMEOUT = T.mins(5).msecs(); + //Storage [MB] + public static final long MINIMUM_FREE_SPACE = 200; + } diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index 6c3d6f9820..ad4a28c1f3 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -49,16 +49,16 @@ import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus; import info.nightscout.androidaps.setupwizard.SetupWizardActivity; import info.nightscout.androidaps.tabs.TabPageAdapter; -import info.nightscout.utils.AndroidPermission; -import info.nightscout.utils.LocaleHelper; -import info.nightscout.utils.OKDialog; -import info.nightscout.utils.PasswordProtection; -import info.nightscout.utils.SP; -import info.nightscout.utils.VersionChecker; +import info.nightscout.androidaps.utils.AndroidPermission; +import info.nightscout.androidaps.utils.LocaleHelper; +import info.nightscout.androidaps.utils.OKDialog; +import info.nightscout.androidaps.utils.PasswordProtection; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.VersionChecker; public class MainActivity extends AppCompatActivity { private static Logger log = LoggerFactory.getLogger(L.CORE); @@ -182,7 +182,7 @@ public class MainActivity extends AppCompatActivity { @Subscribe public void onStatusEvent(final EventRefreshGui ev) { - String lang = SP.getString("language", "en"); + String lang = SP.getString(R.string.key_language, "en"); LocaleHelper.setLocale(getApplicationContext(), lang); runOnUiThread(() -> { if (ev.recreate) { @@ -326,6 +326,7 @@ public class MainActivity extends AppCompatActivity { case AndroidPermission.CASE_LOCATION: case AndroidPermission.CASE_SMS: case AndroidPermission.CASE_BATTERY: + case AndroidPermission.CASE_PHONESTATE: break; } } @@ -377,10 +378,7 @@ public class MainActivity extends AppCompatActivity { case R.id.nav_about: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(MainApp.gs(R.string.app_name) + " " + BuildConfig.VERSION); - if (Config.NSCLIENT) - builder.setIcon(R.mipmap.yellowowl); - else - builder.setIcon(R.mipmap.blueowl); + builder.setIcon(MainApp.getIcon()); String message = "Build: " + BuildConfig.BUILDVERSION + "\n"; message += "Flavor: " + BuildConfig.FLAVOR + BuildConfig.BUILD_TYPE + "\n"; message += MainApp.gs(R.string.configbuilder_nightscoutversion_label) + " " + NSSettingsStatus.getInstance().nightscoutVersionName; diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index e9baabb9ca..36d9591532 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -29,59 +29,64 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Actions.ActionsFragment; -import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; -import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin; -import info.nightscout.androidaps.plugins.Food.FoodPlugin; -import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin; -import info.nightscout.androidaps.plugins.Insulin.InsulinOrefRapidActingPlugin; -import info.nightscout.androidaps.plugins.Insulin.InsulinOrefUltraRapidActingPlugin; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.Maintenance.MaintenancePlugin; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.androidaps.plugins.NSClientInternal.receivers.AckAlarmReceiver; -import info.nightscout.androidaps.plugins.NSClientInternal.receivers.DBAccessReceiver; -import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; -import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin; -import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin; -import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; -import info.nightscout.androidaps.plugins.Persistentnotification.PersistentNotificationPlugin; -import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfilePlugin; -import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; -import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfilePlugin; -import info.nightscout.androidaps.plugins.PumpCombo.ComboPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; -import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin; -import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin; -import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityAAPSPlugin; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityOref0Plugin; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityOref1Plugin; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityWeightedAveragePlugin; -import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; -import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin; -import info.nightscout.androidaps.plugins.Source.SourceGlimpPlugin; -import info.nightscout.androidaps.plugins.Source.SourceMM640gPlugin; -import info.nightscout.androidaps.plugins.Source.SourceNSClientPlugin; -import info.nightscout.androidaps.plugins.Source.SourcePoctechPlugin; -import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.androidaps.plugins.Wear.WearPlugin; -import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin; +import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin; +import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.constraints.dstHelper.DstHelperPlugin; +import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin; +import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin; +import info.nightscout.androidaps.plugins.constraints.storage.StorageConstraintPlugin; +import info.nightscout.androidaps.plugins.general.actions.ActionsFragment; import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin; +import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin; +import info.nightscout.androidaps.plugins.general.food.FoodPlugin; +import info.nightscout.androidaps.plugins.general.maintenance.LoggerUtils; +import info.nightscout.androidaps.plugins.general.maintenance.MaintenancePlugin; +import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.general.nsclient.receivers.AckAlarmReceiver; +import info.nightscout.androidaps.plugins.general.nsclient.receivers.DBAccessReceiver; +import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin; +import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin; +import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin; +import info.nightscout.androidaps.plugins.general.wear.WearPlugin; +import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin; +import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin; +import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin; +import info.nightscout.androidaps.plugins.insulin.InsulinOrefUltraRapidActingPlugin; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin; +import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin; +import info.nightscout.androidaps.plugins.profile.simple.SimpleProfilePlugin; +import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin; +import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; +import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin; +import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin; +import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin; +import info.nightscout.androidaps.plugins.pump.mdi.MDIPlugin; +import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin; +import info.nightscout.androidaps.plugins.source.SourceDexcomG5Plugin; +import info.nightscout.androidaps.plugins.source.SourceDexcomG6Plugin; +import info.nightscout.androidaps.plugins.source.SourceEversensePlugin; +import info.nightscout.androidaps.plugins.source.SourceGlimpPlugin; +import info.nightscout.androidaps.plugins.source.SourceMM640gPlugin; +import info.nightscout.androidaps.plugins.source.SourceNSClientPlugin; +import info.nightscout.androidaps.plugins.source.SourcePoctechPlugin; +import info.nightscout.androidaps.plugins.source.SourceTomatoPlugin; +import info.nightscout.androidaps.plugins.source.SourceXdripPlugin; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.receivers.KeepAliveReceiver; import info.nightscout.androidaps.receivers.NSAlarmReceiver; import info.nightscout.androidaps.services.Intents; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.androidaps.plugins.Maintenance.LoggerUtils; +import info.nightscout.androidaps.utils.FabricPrivacy; import io.fabric.sdk.android.Fabric; @@ -158,9 +163,8 @@ public class MainApp extends Application { if (Config.PUMPDRIVERS) pluginsList.add(DanaRKoreanPlugin.getPlugin()); if (Config.PUMPDRIVERS) pluginsList.add(DanaRv2Plugin.getPlugin()); if (Config.PUMPDRIVERS) pluginsList.add(DanaRSPlugin.getPlugin()); + if (Config.PUMPDRIVERS) pluginsList.add(LocalInsightPlugin.getPlugin()); pluginsList.add(CareportalPlugin.getPlugin()); - if (Config.PUMPDRIVERS && engineeringMode) - pluginsList.add(InsightPlugin.getPlugin()); // <-- Enable Insight plugin here if (Config.PUMPDRIVERS) pluginsList.add(ComboPlugin.getPlugin()); if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin()); pluginsList.add(VirtualPumpPlugin.getPlugin()); @@ -173,13 +177,17 @@ public class MainApp extends Application { if (Config.OTHERPROFILES) pluginsList.add(LocalProfilePlugin.getPlugin()); pluginsList.add(TreatmentsPlugin.getPlugin()); if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin()); + if (Config.SAFETY) pluginsList.add(StorageConstraintPlugin.getPlugin()); if (Config.APS) pluginsList.add(ObjectivesPlugin.getPlugin()); pluginsList.add(SourceXdripPlugin.getPlugin()); pluginsList.add(SourceNSClientPlugin.getPlugin()); pluginsList.add(SourceMM640gPlugin.getPlugin()); pluginsList.add(SourceGlimpPlugin.getPlugin()); pluginsList.add(SourceDexcomG5Plugin.getPlugin()); + pluginsList.add(SourceDexcomG6Plugin.getPlugin()); pluginsList.add(SourcePoctechPlugin.getPlugin()); + pluginsList.add(SourceTomatoPlugin.getPlugin()); + pluginsList.add(SourceEversensePlugin.getPlugin()); if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorPlugin.getPlugin()); pluginsList.add(FoodPlugin.getPlugin()); @@ -192,6 +200,9 @@ public class MainApp extends Application { pluginsList.add(ConfigBuilderPlugin.getPlugin()); + pluginsList.add(DstHelperPlugin.getPlugin()); + + ConfigBuilderPlugin.getPlugin().initialize(); } @@ -387,6 +398,24 @@ public class MainApp extends Application { return devBranch; } + public static int getIcon() { + if (Config.NSCLIENT) + return R.mipmap.ic_yellowowl; + else if (Config.PUMPCONTROL) + return R.mipmap.ic_pumpcontrol; + else + return R.mipmap.ic_launcher; + } + + public static int getNotificationIcon() { + if (Config.NSCLIENT) + return R.drawable.ic_notif_nsclient; + else if (Config.PUMPCONTROL) + return R.drawable.ic_notif_pumpcontrol; + else + return R.drawable.ic_notif_aaps; + } + @Override public void onTerminate() { if (L.isEnabled(L.CORE)) @@ -397,4 +426,9 @@ public class MainApp extends Application { sDatabaseHelper = null; } } + + public static int dpToPx(int dp) { + float scale = sResources.getDisplayMetrics().density; + return (int) (dp*scale + 0.5f); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/activities/AgreementActivity.java b/app/src/main/java/info/nightscout/androidaps/activities/AgreementActivity.java index 582b10d57d..32352e1371 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/AgreementActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/activities/AgreementActivity.java @@ -2,16 +2,14 @@ package info.nightscout.androidaps.activities; import android.app.Activity; import android.content.Intent; -import android.content.SharedPreferences; import android.os.Bundle; -import android.preference.PreferenceManager; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import info.nightscout.androidaps.MainActivity; import info.nightscout.androidaps.R; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; public class AgreementActivity extends Activity { boolean IUnderstand; diff --git a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.java b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.java index 7303eb9d97..c007d1fced 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.java @@ -34,16 +34,16 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.events.EventCustomCalculationFinished; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventIobCalculationProgress; -import info.nightscout.androidaps.plugins.Overview.OverviewFragment; -import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; -import info.nightscout.androidaps.plugins.Overview.graphData.GraphData; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.T; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress; +import info.nightscout.androidaps.plugins.general.overview.OverviewFragment; +import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin; +import info.nightscout.androidaps.plugins.general.overview.graphData.GraphData; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.T; public class HistoryBrowseActivity extends AppCompatActivity { private static Logger log = LoggerFactory.getLogger(HistoryBrowseActivity.class); diff --git a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java index 0cf891e8cd..c6ea0eaeb6 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java @@ -9,6 +9,7 @@ import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; +import android.preference.PreferenceScreen; import android.text.TextUtils; import info.nightscout.androidaps.Config; @@ -18,33 +19,33 @@ import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin; -import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin; -import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; -import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; -import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin; -import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin; -import info.nightscout.androidaps.plugins.PumpCombo.ComboPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; -import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin; -import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityAAPSPlugin; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityOref0Plugin; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityOref1Plugin; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityWeightedAveragePlugin; -import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; -import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin; -import info.nightscout.androidaps.plugins.Wear.WearPlugin; -import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; +import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin; +import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin; +import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin; +import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin; +import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin; +import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin; +import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin; +import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; +import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin; +import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin; +import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin; +import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin; +import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin; +import info.nightscout.androidaps.plugins.source.SourceDexcomG5Plugin; +import info.nightscout.androidaps.plugins.general.wear.WearPlugin; +import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin; +import info.nightscout.androidaps.utils.LocaleHelper; +import info.nightscout.androidaps.utils.OKDialog; +import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin; -import info.nightscout.utils.LocaleHelper; -import info.nightscout.utils.OKDialog; -import info.nightscout.utils.SP; public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener { MyPreferenceFragment myPreferenceFragment; @@ -164,7 +165,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre addPreferencesFromResourceIfEnabled(DanaRKoreanPlugin.getPlugin(), PluginType.PUMP); addPreferencesFromResourceIfEnabled(DanaRv2Plugin.getPlugin(), PluginType.PUMP); addPreferencesFromResourceIfEnabled(DanaRSPlugin.getPlugin(), PluginType.PUMP); - addPreferencesFromResourceIfEnabled(InsightPlugin.getPlugin(), PluginType.PUMP); + addPreferencesFromResourceIfEnabled(LocalInsightPlugin.getPlugin(), PluginType.PUMP); addPreferencesFromResourceIfEnabled(ComboPlugin.getPlugin(), PluginType.PUMP); if (DanaRPlugin.getPlugin().isEnabled(PluginType.PROFILE) @@ -192,6 +193,17 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre addPreferencesFromResourceIfEnabled(StatuslinePlugin.getPlugin(), PluginType.GENERAL); } + if (Config.NSCLIENT) { + PreferenceScreen scrnAdvancedSettings = (PreferenceScreen)findPreference(getString(R.string.key_advancedsettings)); + if (scrnAdvancedSettings != null) { + scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_res_warning))); + scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_res_critical))); + scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_bat_warning))); + scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_bat_critical))); + scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_show_statuslights))); + } + } + initSummary(getPreferenceScreen()); } diff --git a/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.java b/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.java index 04fd7a6be7..2a381cd0a8 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.java @@ -10,9 +10,8 @@ import android.view.MenuItem; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.activities.PreferencesActivity; import info.nightscout.androidaps.interfaces.PluginBase; -import info.nightscout.utils.PasswordProtection; +import info.nightscout.androidaps.utils.PasswordProtection; public class SingleFragmentActivity extends AppCompatActivity { diff --git a/app/src/main/java/info/nightscout/androidaps/activities/TDDStatsActivity.java b/app/src/main/java/info/nightscout/androidaps/activities/TDDStatsActivity.java index b46faec980..e42d31d7c0 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/TDDStatsActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/activities/TDDStatsActivity.java @@ -39,18 +39,18 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.TDD; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; -import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus; +import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; +import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin; +import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin; +import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin; import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.SP; -import info.nightscout.utils.SafeParse; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.SafeParse; public class TDDStatsActivity extends Activity { private static Logger log = LoggerFactory.getLogger(TDDStatsActivity.class); @@ -550,7 +550,7 @@ public class TDDStatsActivity extends Activity { PumpInterface danaRS = MainApp.getSpecificPlugin(DanaRSPlugin.class); PumpInterface danaV2 = MainApp.getSpecificPlugin(DanaRv2Plugin.class); PumpInterface danaKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class); - PumpInterface insight = MainApp.getSpecificPlugin(InsightPlugin.class); + PumpInterface insight = MainApp.getSpecificPlugin(LocalInsightPlugin.class); boolean startsYesterday = activePump == dana || activePump == danaRS || activePump == danaV2 || activePump == danaKorean || activePump == insight; diff --git a/app/src/main/java/info/nightscout/androidaps/data/ConstraintChecker.java b/app/src/main/java/info/nightscout/androidaps/data/ConstraintChecker.java index fc37f5f2a5..68664033d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/ConstraintChecker.java +++ b/app/src/main/java/info/nightscout/androidaps/data/ConstraintChecker.java @@ -42,10 +42,18 @@ public class ConstraintChecker implements ConstraintsInterface { return isSMBModeEnabled(new Constraint<>(true)); } + public Constraint isUAMEnabled() { + return isUAMEnabled(new Constraint<>(true)); + } + public Constraint isAdvancedFilteringEnabled() { return isAdvancedFilteringEnabled(new Constraint<>(true)); } + public Constraint isSuperBolusEnabled() { + return isSuperBolusEnabled(new Constraint<>(true)); + } + public Constraint getMaxBasalAllowed(Profile profile) { return applyBasalConstraints(new Constraint<>(Constants.REALLYHIGHBASALRATE), profile); } @@ -130,6 +138,18 @@ public class ConstraintChecker implements ConstraintsInterface { return value; } + @Override + public Constraint isUAMEnabled(Constraint value) { + + ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); + for (PluginBase p : constraintsPlugins) { + ConstraintsInterface constraint = (ConstraintsInterface) p; + if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; + constraint.isUAMEnabled(value); + } + return value; + } + @Override public Constraint isAdvancedFilteringEnabled(Constraint value) { ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); @@ -141,6 +161,17 @@ public class ConstraintChecker implements ConstraintsInterface { return value; } + @Override + public Constraint isSuperBolusEnabled(Constraint value) { + ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); + for (PluginBase p : constraintsPlugins) { + ConstraintsInterface constraint = (ConstraintsInterface) p; + if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; + constraint.isSuperBolusEnabled(value); + } + return value; + } + @Override public Constraint applyBasalConstraints(Constraint absoluteRate, Profile profile) { ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); diff --git a/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java b/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java index 51a1e18685..ef5cd69782 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java +++ b/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java @@ -2,15 +2,12 @@ package info.nightscout.androidaps.data; import android.content.Context; -import com.rits.cloning.Cloner; - import org.json.JSONObject; import java.util.Date; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.Source; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; /** * Created by mike on 29.05.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/data/GlucoseStatus.java b/app/src/main/java/info/nightscout/androidaps/data/GlucoseStatus.java index d8ee55b73a..d65bf6b99f 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/GlucoseStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/data/GlucoseStatus.java @@ -1,29 +1,20 @@ package info.nightscout.androidaps.data; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; import android.support.annotation.Nullable; -import android.text.Html; -import android.text.Spanned; - -import com.j256.ormlite.dao.Dao; -import com.j256.ormlite.stmt.PreparedQuery; -import com.j256.ormlite.stmt.QueryBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.sql.SQLException; import java.util.ArrayList; -import java.util.Date; import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.BgReading; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.Round; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.Round; /** * Created by mike on 04.01.2017. @@ -60,23 +51,29 @@ public class GlucoseStatus { } - @Nullable - public static GlucoseStatus getGlucoseStatusData(){ + public static GlucoseStatus getGlucoseStatusData() { return getGlucoseStatusData(false); } @Nullable public static GlucoseStatus getGlucoseStatusData(boolean allowOldData) { // load 45min - long fromtime = DateUtil.now() - 60 * 1000L * 45; - List data = MainApp.getDbHelper().getBgreadingsDataFromTime(fromtime, false); + //long fromtime = DateUtil.now() - 60 * 1000L * 45; + //List data = MainApp.getDbHelper().getBgreadingsDataFromTime(fromtime, false); + + List data = IobCobCalculatorPlugin.getPlugin().getBgReadings(); + + if (data == null) + return null; int sizeRecords = data.size(); if (sizeRecords == 0) { return null; } + sizeRecords = Math.min(sizeRecords, 9); + if (data.get(0).date < DateUtil.now() - 7 * 60 * 1000L && !allowOldData) { return null; } @@ -100,7 +97,7 @@ public class GlucoseStatus { ArrayList short_deltas = new ArrayList(); ArrayList long_deltas = new ArrayList(); - for (int i = 1; i < data.size(); i++) { + for (int i = 1; i < sizeRecords; i++) { if (data.get(i).value > 38) { BgReading then = data.get(i); long then_date = then.date; diff --git a/app/src/main/java/info/nightscout/androidaps/data/IobTotal.java b/app/src/main/java/info/nightscout/androidaps/data/IobTotal.java index a87b77be07..73f75b9c7d 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/IobTotal.java +++ b/app/src/main/java/info/nightscout/androidaps/data/IobTotal.java @@ -9,8 +9,8 @@ import org.slf4j.LoggerFactory; import java.util.Date; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.Round; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.Round; public class IobTotal { private static Logger log = LoggerFactory.getLogger(IobTotal.class); diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index 8d78ca19b6..23a7e62426 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -9,7 +9,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.text.DecimalFormat; -import java.util.Calendar; import java.util.TimeZone; import info.nightscout.androidaps.Constants; @@ -17,12 +16,13 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.FabricPrivacy; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.MidnightTime; public class Profile { private static Logger log = LoggerFactory.getLogger(Profile.class); @@ -381,7 +381,7 @@ public class Profile { } public double getIsf() { - return getIsfTimeFromMidnight(secondsFromMidnight(System.currentTimeMillis())); + return getIsfTimeFromMidnight(secondsFromMidnight()); } public double getIsf(long time) { @@ -397,11 +397,11 @@ public class Profile { public String getIsfList() { if (isf_v == null) isf_v = convertToSparseArray(isf); - return getValuesList(isf_v, null, new DecimalFormat("0.0"), getUnits() + "/U"); + return getValuesList(isf_v, null, new DecimalFormat("0.0"), getUnits() + MainApp.gs(R.string.profile_per_unit)); } public double getIc() { - return getIcTimeFromMidnight(secondsFromMidnight(System.currentTimeMillis())); + return getIcTimeFromMidnight(secondsFromMidnight()); } public double getIc(long time) { @@ -417,11 +417,11 @@ public class Profile { public String getIcList() { if (ic_v == null) ic_v = convertToSparseArray(ic); - return getValuesList(ic_v, null, new DecimalFormat("0.0"), "g/U"); + return getValuesList(ic_v, null, new DecimalFormat("0.0"), MainApp.gs(R.string.profile_carbs_per_unit)); } public double getBasal() { - return getBasalTimeFromMidnight(secondsFromMidnight(System.currentTimeMillis())); + return getBasalTimeFromMidnight(secondsFromMidnight()); } public double getBasal(long time) { @@ -438,7 +438,7 @@ public class Profile { public String getBasalList() { if (basal_v == null) basal_v = convertToSparseArray(basal); - return getValuesList(basal_v, null, new DecimalFormat("0.00"), "U/h"); + return getValuesList(basal_v, null, new DecimalFormat("0.00"), MainApp.gs(R.string.profile_ins_units_per_hout)); } public class BasalValue { @@ -465,7 +465,7 @@ public class Profile { } public double getTarget() { - return getTarget(secondsFromMidnight(System.currentTimeMillis())); + return getTarget(secondsFromMidnight()); } protected double getTarget(int timeAsSeconds) { @@ -473,7 +473,7 @@ public class Profile { } public double getTargetLow() { - return getTargetLowTimeFromMidnight(secondsFromMidnight(System.currentTimeMillis())); + return getTargetLowTimeFromMidnight(secondsFromMidnight()); } public double getTargetLow(long time) { @@ -487,7 +487,7 @@ public class Profile { } public double getTargetHigh() { - return getTargetHighTimeFromMidnight(secondsFromMidnight(System.currentTimeMillis())); + return getTargetHighTimeFromMidnight(secondsFromMidnight()); } public double getTargetHigh(long time) { @@ -518,24 +518,13 @@ public class Profile { } public static int secondsFromMidnight() { - Calendar c = Calendar.getInstance(); - long now = c.getTimeInMillis(); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - c.set(Calendar.MILLISECOND, 0); - long passed = now - c.getTimeInMillis(); + long passed = DateUtil.now() - MidnightTime.calc(); return (int) (passed / 1000); } public static int secondsFromMidnight(long date) { - Calendar c = Calendar.getInstance(); - c.setTimeInMillis(date); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - c.set(Calendar.MILLISECOND, 0); - long passed = date - c.getTimeInMillis(); + long midnight = MidnightTime.calc(date); + long passed = date - midnight; return (int) (passed / 1000); } diff --git a/app/src/main/java/info/nightscout/androidaps/data/ProfileIntervals.java b/app/src/main/java/info/nightscout/androidaps/data/ProfileIntervals.java index 9343596eee..8938b53936 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/ProfileIntervals.java +++ b/app/src/main/java/info/nightscout/androidaps/data/ProfileIntervals.java @@ -10,7 +10,6 @@ import java.util.ArrayList; import java.util.List; import info.nightscout.androidaps.interfaces.Interval; -import info.nightscout.utils.DateUtil; /** * Created by mike on 09.05.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java b/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java index 280c948a6a..461d8faa7b 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java +++ b/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java @@ -1,8 +1,5 @@ package info.nightscout.androidaps.data; -import android.text.Html; -import android.text.Spanned; - import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; @@ -11,8 +8,8 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.Round; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.Round; public class PumpEnactResult { private static Logger log = LoggerFactory.getLogger(L.APS); diff --git a/app/src/main/java/info/nightscout/androidaps/data/QuickWizard.java b/app/src/main/java/info/nightscout/androidaps/data/QuickWizard.java index 25c768cdda..80a6e1b457 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/QuickWizard.java +++ b/app/src/main/java/info/nightscout/androidaps/data/QuickWizard.java @@ -1,16 +1,12 @@ package info.nightscout.androidaps.data; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; - import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import info.nightscout.androidaps.MainApp; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 12.10.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java b/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java index 04f297d7a9..4262fe2133 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java +++ b/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java @@ -11,13 +11,13 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.TreatmentsInterface; -import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.BolusWizard; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.BolusWizard; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 25.12.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java index a2e06d0bb1..6fafdc4b6d 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java +++ b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java @@ -1,7 +1,5 @@ package info.nightscout.androidaps.db; -import android.content.res.Resources; - import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; @@ -14,15 +12,13 @@ import java.util.Objects; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv; -import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSSgv; +import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries; +import info.nightscout.androidaps.utils.DecimalFormatter; @DatabaseTable(tableName = DatabaseHelper.DATABASE_BGREADINGS) public class BgReading implements DataPointWithLabelInterface { @@ -220,14 +216,8 @@ public class BgReading implements DataPointWithLabelInterface { @Override public int getColor() { String units = ProfileFunctions.getInstance().getProfileUnits(); - Double lowLine = SP.getDouble("low_mark", 0d); - Double highLine = SP.getDouble("high_mark", 0d); - if (lowLine < 1) { - lowLine = Profile.fromMgdlToUnits(OverviewPlugin.bgTargetLow, units); - } - if (highLine < 1) { - highLine = Profile.fromMgdlToUnits(OverviewPlugin.bgTargetHigh, units); - } + Double lowLine = OverviewPlugin.getPlugin().determineLowLine(units); + Double highLine = OverviewPlugin.getPlugin().determineHighLine(units); int color = MainApp.gc(R.color.inrange); if (isPrediction()) return getPredectionColor(); diff --git a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java index 60c7553cc3..f0e70c0a25 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java +++ b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java @@ -13,7 +13,6 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.EnumSet; import java.util.LinkedHashMap; import java.util.List; @@ -26,14 +25,14 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.Interval; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSMbg; -import info.nightscout.androidaps.plugins.Overview.OverviewFragment; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.T; -import info.nightscout.utils.Translator; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSMbg; +import info.nightscout.androidaps.plugins.general.overview.OverviewFragment; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.T; +import info.nightscout.androidaps.utils.Translator; @DatabaseTable(tableName = DatabaseHelper.DATABASE_CAREPORTALEVENTS) public class CareportalEvent implements DataPointWithLabelInterface, Interval { @@ -90,8 +89,8 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval { return System.currentTimeMillis() - date; } - public long getHoursFromStart() { - return (System.currentTimeMillis() - date) / (60 * 60 * 1000); + public double getHoursFromStart() { + return (System.currentTimeMillis() - date) / (60 * 60 * 1000.0); } public String age() { diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 89eb892f05..6600632869 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -44,16 +44,19 @@ import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; -import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; -import info.nightscout.utils.JsonHelper; -import info.nightscout.utils.PercentageSplitter; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRNSHistorySync; +import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes; +import info.nightscout.androidaps.plugins.pump.insight.database.InsightBolusID; +import info.nightscout.androidaps.plugins.pump.insight.database.InsightHistoryOffset; +import info.nightscout.androidaps.plugins.pump.insight.database.InsightPumpID; +import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin; +import info.nightscout.androidaps.utils.JsonHelper; +import info.nightscout.androidaps.utils.PercentageSplitter; +import info.nightscout.androidaps.utils.ToastUtils; /** * This Helper contains all resource to provide a central DB management functionality. Only methods handling @@ -76,8 +79,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { public static final String DATABASE_CAREPORTALEVENTS = "CareportalEvents"; public static final String DATABASE_PROFILESWITCHES = "ProfileSwitches"; public static final String DATABASE_TDDS = "TDDs"; + public static final String DATABASE_INSIGHT_HISTORY_OFFSETS = "InsightHistoryOffsets"; + public static final String DATABASE_INSIGHT_BOLUS_IDS = "InsightBolusIDs"; + public static final String DATABASE_INSIGHT_PUMP_IDS = "InsightPumpIDs"; - private static final int DATABASE_VERSION = 9; + private static final int DATABASE_VERSION = 10; public static Long earliestDataChange = null; @@ -122,6 +128,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class); TableUtils.createTableIfNotExists(connectionSource, ProfileSwitch.class); TableUtils.createTableIfNotExists(connectionSource, TDD.class); + TableUtils.createTableIfNotExists(connectionSource, InsightHistoryOffset.class); + TableUtils.createTableIfNotExists(connectionSource, InsightBolusID.class); + TableUtils.createTableIfNotExists(connectionSource, InsightPumpID.class); } catch (SQLException e) { log.error("Can't create database", e); throw new RuntimeException(e); @@ -138,6 +147,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { log.debug("Upgrading database from v7 to v8"); } else if (oldVersion == 8 && newVersion == 9) { log.debug("Upgrading database from v8 to v9"); + } else if (oldVersion == 9 && newVersion == 10) { + TableUtils.createTableIfNotExists(connectionSource, InsightHistoryOffset.class); + TableUtils.createTableIfNotExists(connectionSource, InsightBolusID.class); + TableUtils.createTableIfNotExists(connectionSource, InsightPumpID.class); } else { log.info(DatabaseHelper.class.getName(), "onUpgrade"); TableUtils.dropTable(connectionSource, TempTarget.class, true); @@ -156,6 +169,12 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + @Override + public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { + log.info("Do nothing for downgrading..."); + log.debug("oldVersion: {}, newVersion: {}", oldVersion, newVersion); + } + public int getOldVersion() { return oldVersion; } @@ -321,6 +340,18 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return getDao(ProfileSwitch.class); } + private Dao getDaoInsightPumpID() throws SQLException { + return getDao(InsightPumpID.class); + } + + private Dao getDaoInsightBolusID() throws SQLException { + return getDao(InsightBolusID.class); + } + + private Dao getDaoInsightHistoryOffset() throws SQLException { + return getDao(InsightHistoryOffset.class); + } + public static long roundDateToSec(long date) { long rounded = date - date % 1000; if (rounded != date) @@ -390,24 +421,15 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { */ @Nullable public static BgReading lastBg() { - List bgList = null; + List bgList = IobCobCalculatorPlugin.getPlugin().getBgReadings(); - try { - Dao daoBgReadings = MainApp.getDbHelper().getDaoBgReadings(); - QueryBuilder queryBuilder = daoBgReadings.queryBuilder(); - queryBuilder.orderBy("date", false); - queryBuilder.limit(1L); - queryBuilder.where().gt("value", 38).and().eq("isValid", true); - PreparedQuery preparedQuery = queryBuilder.prepare(); - bgList = daoBgReadings.query(preparedQuery); - - } catch (SQLException e) { - log.error("Unhandled exception", e); - } - if (bgList != null && bgList.size() > 0) - return bgList.get(0); - else + if (bgList == null) return null; + + for (int i = 0; i < bgList.size(); i++) + if (bgList.get(i).value > 39) + return bgList.get(i); + return null; } /* @@ -435,14 +457,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { QueryBuilder queryBuilder = daoBgreadings.queryBuilder(); queryBuilder.orderBy("date", ascending); Where where = queryBuilder.where(); - where.ge("date", mills).and().gt("value", 38).and().eq("isValid", true); + where.ge("date", mills).and().ge("value", 39).and().eq("isValid", true); PreparedQuery preparedQuery = queryBuilder.prepare(); bgReadings = daoBgreadings.query(preparedQuery); return bgReadings; } catch (SQLException e) { log.error("Unhandled exception", e); } - return new ArrayList(); + return new ArrayList<>(); } public List getBgreadingsDataFromTime(long start, long end, boolean ascending) { @@ -452,14 +474,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { QueryBuilder queryBuilder = daoBgreadings.queryBuilder(); queryBuilder.orderBy("date", ascending); Where where = queryBuilder.where(); - where.between("date", start, end).and().gt("value", 38).and().eq("isValid", true); + where.between("date", start, end).and().ge("value", 39).and().eq("isValid", true); PreparedQuery preparedQuery = queryBuilder.prepare(); bgReadings = daoBgreadings.query(preparedQuery); return bgReadings; } catch (SQLException e) { log.error("Unhandled exception", e); } - return new ArrayList(); + return new ArrayList<>(); } public List getAllBgreadingsDataFromTime(long mills, boolean ascending) { @@ -1143,6 +1165,17 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return false; } + public ExtendedBolus getExtendedBolusByPumpId(long pumpId) { + try { + return getDaoExtendedBolus().queryBuilder() + .where().eq("pumpId", pumpId) + .queryForFirst(); + } catch (SQLException e) { + log.error("Unhandled exception", e); + } + return null; + } + public void delete(ExtendedBolus extendedBolus) { try { getDaoExtendedBolus().delete(extendedBolus); @@ -1650,5 +1683,67 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } + // ---------------- Insight history handling --------------- + + public void createOrUpdate(InsightHistoryOffset offset) { + try { + getDaoInsightHistoryOffset().createOrUpdate(offset); + } catch (SQLException e) { + log.error("Unhandled exception", e); + } + } + + public InsightHistoryOffset getInsightHistoryOffset(String pumpSerial) { + try { + return getDaoInsightHistoryOffset().queryForId(pumpSerial); + } catch (SQLException e) { + log.error("Unhandled exception", e); + } + return null; + } + + public void createOrUpdate(InsightBolusID bolusID) { + try { + getDaoInsightBolusID().createOrUpdate(bolusID); + } catch (SQLException e) { + log.error("Unhandled exception", e); + } + } + + public InsightBolusID getInsightBolusID(String pumpSerial, int bolusID, long timestamp) { + try { + return getDaoInsightBolusID().queryBuilder() + .where().eq("pumpSerial", pumpSerial) + .and().eq("bolusID", bolusID) + .and().between("timestamp", timestamp - 259200000, timestamp + 259200000) + .queryForFirst(); + } catch (SQLException e) { + log.error("Unhandled exception", e); + } + return null; + } + + public void createOrUpdate(InsightPumpID pumpID) { + try { + getDaoInsightPumpID().createOrUpdate(pumpID); + } catch (SQLException e) { + log.error("Unhandled exception", e); + } + } + + public InsightPumpID getPumpStoppedEvent(String pumpSerial, long before) { + try { + return getDaoInsightPumpID().queryBuilder() + .orderBy("timestamp", false) + .where().eq("pumpSerial", pumpSerial) + .and().in("eventType", "PumpStopped", "PumpPaused") + .and().lt("timestamp", before) + .queryForFirst(); + } catch (SQLException e) { + log.error("Unhandled exception", e); + } + return null; + } + // ---------------- Food handling --------------- } diff --git a/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java b/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java index b4fda73ab6..2f11b752c8 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java @@ -9,7 +9,6 @@ import android.graphics.Color; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; -import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,14 +21,14 @@ import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.Interval; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.JsonHelper; -import info.nightscout.utils.Round; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.JsonHelper; +import info.nightscout.androidaps.utils.Round; /** * Created by mike on 21.05.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java index 0527864fd2..0e589f0595 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java +++ b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java @@ -6,7 +6,6 @@ import android.support.annotation.Nullable; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; -import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,14 +18,14 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.Interval; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfilePlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.T; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.T; @DatabaseTable(tableName = DatabaseHelper.DATABASE_PROFILESWITCHES) public class ProfileSwitch implements Interval, DataPointWithLabelInterface { @@ -101,6 +100,11 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { return profile; } + /** + * Note: the name returned here is used as the PS name when uploading to NS. When such a PS is retrieved + * again from NS, the added parts must be removed again, see + * {@link info.nightscout.androidaps.utils.PercentageSplitter#pureName} + */ public String getCustomizedName() { String name = profileName; if(LocalProfilePlugin.LOCAL_PROFILE.equals(name)){ diff --git a/app/src/main/java/info/nightscout/androidaps/db/TempTarget.java b/app/src/main/java/info/nightscout/androidaps/db/TempTarget.java index 15692cbdfe..a496af802b 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/TempTarget.java +++ b/app/src/main/java/info/nightscout/androidaps/db/TempTarget.java @@ -6,14 +6,13 @@ import com.j256.ormlite.table.DatabaseTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Date; import java.util.Objects; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.interfaces.Interval; import info.nightscout.androidaps.logging.L; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; @DatabaseTable(tableName = DatabaseHelper.DATABASE_TEMPTARGETS) public class TempTarget implements Interval { diff --git a/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java b/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java index eeaa8c0ee7..336332790a 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java @@ -8,7 +8,6 @@ import org.slf4j.LoggerFactory; import java.util.Objects; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Iob; import info.nightscout.androidaps.data.IobTotal; @@ -16,12 +15,12 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.Interval; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 21.05.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventNetworkChange.java b/app/src/main/java/info/nightscout/androidaps/events/EventNetworkChange.java index 57050bdcc9..546d6f8624 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventNetworkChange.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventNetworkChange.java @@ -1,7 +1,7 @@ package info.nightscout.androidaps.events; -import info.nightscout.utils.StringUtils; +import info.nightscout.androidaps.utils.StringUtils; public class EventNetworkChange extends Event { diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventTreatmentChange.java b/app/src/main/java/info/nightscout/androidaps/events/EventTreatmentChange.java index 989b24b7f9..990f28a388 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventTreatmentChange.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventTreatmentChange.java @@ -2,7 +2,7 @@ package info.nightscout.androidaps.events; import android.support.annotation.Nullable; -import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.Treatment; /** * Created by mike on 04.06.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/APSInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/APSInterface.java index 2f37c47391..e2f3460701 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/APSInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/APSInterface.java @@ -1,6 +1,6 @@ package info.nightscout.androidaps.interfaces; -import info.nightscout.androidaps.plugins.Loop.APSResult; +import info.nightscout.androidaps.plugins.aps.loop.APSResult; /** * Created by mike on 10.06.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java index 310c94ac20..f1c79dd5cb 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java @@ -27,10 +27,18 @@ public interface ConstraintsInterface { return value; } + default Constraint isUAMEnabled(Constraint value) { + return value; + } + default Constraint isAdvancedFilteringEnabled(Constraint value) { return value; } + default Constraint isSuperBolusEnabled(Constraint value) { + return value; + } + default Constraint applyBasalConstraints(Constraint absoluteRate, Profile profile) { return absoluteRate; } diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java index 34b14d9b5d..2ad36fb747 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java @@ -1,7 +1,7 @@ package info.nightscout.androidaps.interfaces; import info.nightscout.androidaps.data.Iob; -import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.Treatment; /** * Created by mike on 17.04.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java index a1a35b7413..01be296539 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java @@ -8,8 +8,8 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.queue.CommandQueue; /** @@ -93,6 +93,8 @@ public abstract class PluginBase { return state == State.ENABLED && specialEnableCondition(); if (type == PluginType.CONSTRAINTS && pluginDescription.mainType == PluginType.PUMP && isEnabled(PluginType.PUMP)) return true; + if (type == PluginType.CONSTRAINTS && pluginDescription.mainType == PluginType.APS && isEnabled(PluginType.APS)) + return true; if (type == PluginType.PROFILE && pluginDescription.mainType == PluginType.PUMP) return isProfileInterfaceEnabled; return false; diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java index 34221b203f..e4a02883e8 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java @@ -1,8 +1,8 @@ package info.nightscout.androidaps.interfaces; -import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpCapability; -import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpTempBasalType; -import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpCapability; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpTempBasalType; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; /** * Created by mike on 08.12.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java index 614c6033d3..7e8f2ef181 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java @@ -2,9 +2,13 @@ package info.nightscout.androidaps.interfaces; import org.json.JSONObject; +import java.util.List; + import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; /** * Created by mike on 04.06.2016. @@ -33,6 +37,10 @@ public interface PumpInterface { double getBaseBasalRate(); // base basal rate, not temp basal + double getReservoirLevel(); + + int getBatteryLevel(); // in percent as integer + PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo); void stopBolusDelivering(); PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew); @@ -57,4 +65,9 @@ public interface PumpInterface { PumpEnactResult loadTDDs(); + + List getCustomActions(); + + void executeCustomAction(CustomActionType customActionType); + } diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java index f4514ad572..9d75382542 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java @@ -1,7 +1,7 @@ package info.nightscout.androidaps.interfaces; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; /** * Created by mike on 24.06.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java index dc437e04ab..0ef71dac2a 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java @@ -10,7 +10,7 @@ import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.data.Intervals; import info.nightscout.androidaps.data.ProfileIntervals; diff --git a/app/src/main/java/info/nightscout/androidaps/logging/L.java b/app/src/main/java/info/nightscout/androidaps/logging/L.java index 846825af6b..e8dfff95e5 100644 --- a/app/src/main/java/info/nightscout/androidaps/logging/L.java +++ b/app/src/main/java/info/nightscout/androidaps/logging/L.java @@ -3,7 +3,7 @@ package info.nightscout.androidaps.logging; import java.util.ArrayList; import java.util.List; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; public class L { @@ -96,17 +96,18 @@ public class L { public static final String CONFIGBUILDER = "CONFIGBUILDER"; public static final String UI = "UI"; public static final String LOCATION = "LOCATION"; + public static final String SMS = "SMS"; private static void initialize() { logElements = new ArrayList<>(); logElements.add(new LogElement(APS, true)); - logElements.add(new LogElement(AUTOSENS, true)); + logElements.add(new LogElement(AUTOSENS, false)); logElements.add(new LogElement(BGSOURCE, true)); - logElements.add(new LogElement(CONFIGBUILDER, true)); + logElements.add(new LogElement(CONFIGBUILDER, false)); logElements.add(new LogElement(CONSTRAINTS, true)); logElements.add(new LogElement(CORE, true)); logElements.add(new LogElement(DATABASE, true)); - logElements.add(new LogElement(DATAFOOD, true)); + logElements.add(new LogElement(DATAFOOD, false)); logElements.add(new LogElement(DATASERVICE, true)); logElements.add(new LogElement(DATATREATMENTS, true)); logElements.add(new LogElement(EVENTS, false, true)); @@ -119,6 +120,7 @@ public class L { logElements.add(new LogElement(PUMPBTCOMM, false)); logElements.add(new LogElement(PUMPCOMM, true)); logElements.add(new LogElement(PUMPQUEUE, true)); + logElements.add(new LogElement(SMS, true)); logElements.add(new LogElement(UI, true)); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightFragment.java deleted file mode 100644 index 5d3c3850b3..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightFragment.java +++ /dev/null @@ -1,114 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight; - -import android.app.Activity; -import android.os.Bundle; -import android.os.Handler; -import android.support.annotation.Nullable; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.LinearLayout; - -import com.squareup.otto.Subscribe; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightUpdateGui; -import info.nightscout.androidaps.plugins.PumpInsight.utils.StatusItem; -import info.nightscout.androidaps.plugins.PumpInsight.utils.ui.StatusItemViewAdapter; -import info.nightscout.utils.FabricPrivacy; - - -public class InsightFragment extends SubscriberFragment { - private static final Logger log = LoggerFactory.getLogger(L.PUMP); - private static final Handler sLoopHandler = new Handler(); - private static volatile boolean refresh = false; - private static volatile boolean pending = false; - StatusItemViewAdapter viewAdapter; - LinearLayout holder; - private final Runnable sRefreshLoop = new Runnable() { - @Override - public void run() { - pending = false; - updateGUI(); - if (refresh) { - scheduleRefresh(); - } - } - }; - - private synchronized void scheduleRefresh() { - if (!pending) { - pending = true; - sLoopHandler.postDelayed(sRefreshLoop, 30 * 1000L); - } - } - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - try { - final View view = inflater.inflate(R.layout.insightpump_fragment, container, false); - holder = (LinearLayout) view.findViewById(R.id.insightholder); - viewAdapter = new StatusItemViewAdapter(getActivity(), holder); - - return view; - } catch (Exception e) { - FabricPrivacy.logException(e); - } - - return null; - } - - - @Override - public void setUserVisibleHint(boolean visible) { - super.setUserVisibleHint(visible); - if (visible) { - refresh = true; - pending = false; - updateGUI(); - scheduleRefresh(); - } else { - refresh = false; - //sLoopHandler.removeCallbacksAndMessages(null); - } - } - - - @Subscribe - public void onStatusEvent(final EventInsightUpdateGui ev) { - updateGUI(); - } - - @Override - protected void updateGUI() { - final Activity activity = getActivity(); - if (activity != null && holder != null) - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - final InsightPlugin insightPlugin = InsightPlugin.getPlugin(); - final List l = insightPlugin.getStatusItems(refresh); - - holder.removeAllViews(); - - for (StatusItem row : l) { - viewAdapter.inflateStatus(row); - } - - } - }); - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java deleted file mode 100644 index c72da31fdf..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java +++ /dev/null @@ -1,935 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight; - -import android.content.DialogInterface; -import android.os.SystemClock; -import android.support.v4.app.FragmentActivity; -import android.support.v7.app.AlertDialog; - -import org.json.JSONException; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.List; - -import info.nightscout.androidaps.BuildConfig; -import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.data.DetailedBolusInfo; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.data.PumpEnactResult; -import info.nightscout.androidaps.db.ExtendedBolus; -import info.nightscout.androidaps.db.Source; -import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.interfaces.Constraint; -import info.nightscout.androidaps.interfaces.ConstraintsInterface; -import info.nightscout.androidaps.interfaces.PluginBase; -import info.nightscout.androidaps.interfaces.PluginDescription; -import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.interfaces.PumpDescription; -import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType; -import info.nightscout.androidaps.plugins.PumpInsight.connector.CancelBolusSilentlyTaskRunner; -import info.nightscout.androidaps.plugins.PumpInsight.connector.CancelTBRSilentlyTaskRunner; -import info.nightscout.androidaps.plugins.PumpInsight.connector.Connector; -import info.nightscout.androidaps.plugins.PumpInsight.connector.SetTBRTaskRunner; -import info.nightscout.androidaps.plugins.PumpInsight.connector.StatusTaskRunner; -import info.nightscout.androidaps.plugins.PumpInsight.connector.WriteBasalProfileTaskRunner; -import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightCallback; -import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightUpdateGui; -import info.nightscout.androidaps.plugins.PumpInsight.history.HistoryReceiver; -import info.nightscout.androidaps.plugins.PumpInsight.history.LiveHistory; -import info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers; -import info.nightscout.androidaps.plugins.PumpInsight.utils.StatusItem; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.SP; -import sugar.free.sightparser.applayer.descriptors.ActiveBolus; -import sugar.free.sightparser.applayer.descriptors.ActiveBolusType; -import sugar.free.sightparser.applayer.descriptors.MessagePriority; -import sugar.free.sightparser.applayer.descriptors.PumpStatus; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfileBlock; -import sugar.free.sightparser.applayer.messages.AppLayerMessage; -import sugar.free.sightparser.applayer.messages.remote_control.BolusMessage; -import sugar.free.sightparser.applayer.messages.remote_control.CancelBolusMessage; -import sugar.free.sightparser.applayer.messages.remote_control.ExtendedBolusMessage; -import sugar.free.sightparser.applayer.messages.remote_control.StandardBolusMessage; -import sugar.free.sightparser.applayer.messages.status.ActiveBolusesMessage; -import sugar.free.sightparser.handling.SingleMessageTaskRunner; -import sugar.free.sightparser.handling.TaskRunner; -import sugar.free.sightparser.pipeline.Status; - -import static info.nightscout.androidaps.plugins.PumpInsight.history.PumpIdCache.getRecordUniqueID; - - -/** - * Created by jamorham on 23/01/2018. - *

- * Connects to SightRemote app service using SightParser library - *

- * SightRemote and SightParser created by Tebbe Ubben - *

- * Original proof of concept SightProxy by jamorham - */ - -@SuppressWarnings("AccessStaticViaInstance") -public class InsightPlugin extends PluginBase implements PumpInterface, ConstraintsInterface { - private Logger log = LoggerFactory.getLogger(L.PUMP); - - private static volatile InsightPlugin plugin; - - public static InsightPlugin getPlugin() { - if (plugin == null) { - plugin = new InsightPlugin(); - } - return plugin; - } - - private static final long BUSY_WAIT_TIME = 20000; - private static Integer batteryPercent = 0; - private static Integer reservoirInUnits = 0; - private static boolean initialized = false; - private static volatile boolean update_pending = false; - private StatusTaskRunner.Result statusResult; - private long statusResultTime = -1; - private long lastDataTime = 0; - private boolean fauxTBRcancel = true; - private PumpDescription pumpDescription = new PumpDescription(); - private double basalRate = 0; - private Connector connector; - private volatile boolean connector_enabled = false; - private List profileBlocks; - - private InsightPlugin() { - super(new PluginDescription() - .mainType(PluginType.PUMP) - .fragmentClass(InsightFragment.class.getName()) - .pluginName(R.string.insightpump) - .shortName(R.string.insightpump_shortname) - .preferencesId(R.xml.pref_insightpump) - .description(R.string.description_pump_insight) - ); - if (L.isEnabled(L.PUMP)) - log.debug("InsightPlugin instantiated"); - pumpDescription.setPumpDescription(PumpType.AccuChekInsight); - } - - - private static void updateGui() { - update_pending = false; - MainApp.bus().post(new EventInsightUpdateGui()); - } - - private static void pushCallbackEvent(EventInsightCallback e) { - MainApp.bus().post(e); - } - - @Override - protected void onStart() { - if (!connector_enabled) { - synchronized (this) { - if (!connector_enabled) { - if (L.isEnabled(L.PUMP)) - log.debug("Instantiating connector"); - connector_enabled = true; - this.connector = Connector.get(); - this.connector.init(); - } - } - } - super.onStart(); - } - - protected void onStop() { - if (connector_enabled) { - synchronized (this) { - if (connector_enabled) { - if (L.isEnabled(L.PUMP)) - log.debug("Shutting down connector"); - Connector.get().shutdown(); - connector_enabled = false; - } - } - } - } - - @Override - public boolean isFakingTempsByExtendedBoluses() { - return true; - } - - @Override - public PumpEnactResult loadTDDs() { - PumpEnactResult result = new PumpEnactResult(); - result.success = true; - return result; - } - - @Override - public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity context) { - boolean allowHardwarePump = SP.getBoolean("allow_hardware_pump", false); - if (allowHardwarePump || context == null) { - pluginSwitcher.invoke(); - } else { - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setMessage(R.string.allow_hardware_pump_text) - .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - pluginSwitcher.invoke(); - SP.putBoolean("allow_hardware_pump", true); - log.debug("First time HW pump allowed!"); - } - }) - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - pluginSwitcher.cancel(); - log.debug("User does not allow switching to HW pump!"); - } - }); - builder.create().show(); - } - } - - @Override - public boolean isInitialized() { - return initialized; - } - - @Override - public boolean isSuspended() { - return !isPumpRunning(); - } - - @Override - public boolean isBusy() { - return false; - } - - @Override - public boolean isConnected() { - return Connector.get().isPumpConnected(); - } - - @Override - public boolean isConnecting() { - return Connector.get().isPumpConnecting(); - } - - @Override - public boolean isHandshakeInProgress() { - return false; - } - - @Override - public void finishHandshaking() { - } - - @Override - public void connect(String reason) { - if (L.isEnabled(L.PUMP)) - log.debug("InsightPlugin::connect()"); - try { - if (!connector.isPumpConnected()) { - if (Helpers.ratelimit("insight-connect-timer", 40)) { - if (L.isEnabled(L.PUMP)) - log.debug("Actually requesting a connect"); - connector.connectToPump(); - } - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Already connected"); - } - } catch (NullPointerException e) { - log.error("Could not sconnect - null pointer: " + e); - } - - // TODO review - if (!Config.NSCLIENT) - NSUpload.uploadDeviceStatus(); - } - - @Override - public void disconnect(String reason) { - if (L.isEnabled(L.PUMP)) - log.debug("InsightPlugin::disconnect()"); - try { - if (!SP.getBoolean("insight_always_connected", false)) { - if (L.isEnabled(L.PUMP)) - log.debug("Requesting disconnect"); - connector.disconnectFromPump(); - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Not disconnecting due to preference"); - } - } catch (NullPointerException e) { - log.error("Could not disconnect - null pointer: " + e); - } - } - - @Override - public void stopConnecting() { - if (L.isEnabled(L.PUMP)) - log.debug("InsightPlugin::stopConnecting()"); - try { - if (isConnecting()) { - if (!SP.getBoolean("insight_always_connected", false)) { - if (L.isEnabled(L.PUMP)) - log.debug("Requesting disconnect"); - connector.disconnectFromPump(); - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Not disconnecting due to preference"); - } - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Not currently trying to connect so not stopping connection"); - } - } catch (NullPointerException e) { - log.error("Could not stop connecting - null pointer: " + e); - } - } - - @Override - public void getPumpStatus() { - if (L.isEnabled(L.PUMP)) - log.debug("getPumpStatus"); - if (Connector.get().isPumpConnected()) { - if (L.isEnabled(L.PUMP)) - log.debug("is connected.. requesting status"); - try { - setStatusResult(fetchTaskRunner(new StatusTaskRunner(connector.getServiceConnector()), StatusTaskRunner.Result.class)); - if (L.isEnabled(L.PUMP)) - log.debug("GOT STATUS RESULT!!! PARTY WOOHOO!!!"); - statusResultTime = Helpers.tsl(); - processStatusResult(); - updateGui(); - connector.requestHistoryReSync(); - connector.requestHistorySync(); - } catch (Exception e) { - log.error("StatusTaskRunner wasn't successful."); - if (connector.getServiceConnector().isConnectedToService() && connector.getServiceConnector().getStatus() != Status.CONNECTED) { - if (Helpers.ratelimit("insight-reconnect", 2)) { - Connector.connectToPump(); - updateGui(); - } - } - } - } else { - if (L.isEnabled(L.PUMP)) - log.debug("not connected.. not requesting status"); - } - } - - public void setStatusResult(StatusTaskRunner.Result result) { - this.statusResult = result; - this.pumpDescription.basalMinimumRate = result.minimumBasalAmount; - this.pumpDescription.basalMaximumRate = result.maximumBasalAmount; - } - - @Override - public PumpEnactResult setNewBasalProfile(Profile profile) { - PumpEnactResult result = new PumpEnactResult(); - if (!isInitialized()) { - log.error("setNewBasalProfile not initialized"); - Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); - result.comment = MainApp.gs(R.string.pumpNotInitializedProfileNotSet); - return result; - } - MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); - List profileBlocks = new ArrayList<>(); - for (int i = 0; i < profile.getBasalValues().length; i++) { - Profile.BasalValue basalValue = profile.getBasalValues()[i]; - Profile.BasalValue nextValue = null; - if (profile.getBasalValues().length > i + 1) - nextValue = profile.getBasalValues()[i + 1]; - profileBlocks.add(new BRProfileBlock.ProfileBlock((((nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) / 60), Helpers.roundDouble(basalValue.value, 2))); - if (L.isEnabled(L.PUMP)) - log.debug("setNewBasalProfile: " + basalValue.value + " for " + Integer.toString(((nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) / 60)); - } - try { - fetchTaskRunner(new WriteBasalProfileTaskRunner(connector.getServiceConnector(), profileBlocks)); - MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); - Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60); - MainApp.bus().post(new EventNewNotification(notification)); - result.success = true; - result.enacted = true; - result.comment = "OK"; - this.profileBlocks = profileBlocks; - } catch (Exception e) { - Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); - result.comment = MainApp.gs(R.string.failedupdatebasalprofile); - } - return result; - } - - @Override - public boolean isThisProfileSet(Profile profile) { - if (!isInitialized() || profileBlocks == null) return true; - if (profile.getBasalValues().length != profileBlocks.size()) return false; - for (int i = 0; i < profileBlocks.size(); i++) { - BRProfileBlock.ProfileBlock profileBlock = profileBlocks.get(i); - Profile.BasalValue basalValue = profile.getBasalValues()[i]; - Profile.BasalValue nextValue = null; - if (profile.getBasalValues().length > i + 1) - nextValue = profile.getBasalValues()[i + 1]; - if (L.isEnabled(L.PUMP)) - log.debug("isThisProfileSet - Comparing block: Pump: " + profileBlock.getAmount() + " for " + profileBlock.getDuration() - + " Profile: " + basalValue.value + " for " + Integer.toString(((nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) / 60)); - if (profileBlock.getDuration() * 60 != (nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) - return false; - //Allow a little imprecision due to rounding errors - if (Math.abs(profileBlock.getAmount() - Helpers.roundDouble(basalValue.value, 2)) >= 0.01D) - return false; - } - return true; - } - - @Override - public long lastDataTime() { - return lastDataTime; - } - - @Override - public double getBaseBasalRate() { - return basalRate; - } - - public String getBaseBasalRateString() { - final DecimalFormat df = new DecimalFormat("#.##"); - return df.format(basalRate); - } - - @Override - public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { - final PumpEnactResult result = new PumpEnactResult(); - result.bolusDelivered = detailedBolusInfo.insulin; - result.carbsDelivered = detailedBolusInfo.carbs; - result.enacted = result.bolusDelivered > 0 || result.carbsDelivered > 0; - result.comment = MainApp.gs(R.string.virtualpump_resultok); - - result.percent = 100; - - int bolusId = 0; - - // is there an insulin component to the treatment? - if (detailedBolusInfo.insulin > 0) { - try { - bolusId = deliverBolus(detailedBolusInfo.insulin); - result.success = true; - detailedBolusInfo.pumpId = getRecordUniqueID(bolusId); - } catch (Exception e) { - return pumpEnactFailure(); - } - } else { - result.success = true; // always true with carb only treatments - } - - if (result.success) { - if (L.isEnabled(L.PUMP)) - log.debug("Success!"); - - Treatment t = new Treatment(); - t.isSMB = detailedBolusInfo.isSMB; - final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); - bolusingEvent.t = t; - bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivering), 0F); - bolusingEvent.bolusId = bolusId; - bolusingEvent.percent = 0; - MainApp.bus().post(bolusingEvent); - TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Failure to deliver treatment"); - } - - if (L.isEnabled(L.PUMP)) - log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result); - - updateGui(); - connector.tryToGetPumpStatusAgain(); - - if (result.success) while (true) { - try { - Thread.sleep(500); - final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); - ActiveBolusesMessage activeBolusesMessage = fetchSingleMessage(new ActiveBolusesMessage(), ActiveBolusesMessage.class); - ActiveBolus activeBolus = null; - if (activeBolusesMessage.getBolus1() != null && activeBolusesMessage.getBolus1().getBolusID() == bolusingEvent.bolusId) - activeBolus = activeBolusesMessage.getBolus1(); - else if (activeBolusesMessage.getBolus2() != null && activeBolusesMessage.getBolus2().getBolusID() == bolusingEvent.bolusId) - activeBolus = activeBolusesMessage.getBolus2(); - else if (activeBolusesMessage.getBolus3() != null && activeBolusesMessage.getBolus3().getBolusID() == bolusingEvent.bolusId) - activeBolus = activeBolusesMessage.getBolus3(); - if (activeBolus == null) break; - else { - int percentBefore = bolusingEvent.percent; - bolusingEvent.percent = (int) (100D / activeBolus.getInitialAmount() * (activeBolus.getInitialAmount() - activeBolus.getLeftoverAmount())); - bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivering), activeBolus.getInitialAmount() - activeBolus.getLeftoverAmount()); - if (percentBefore != bolusingEvent.percent) MainApp.bus().post(bolusingEvent); - } - } catch (Exception e) { - break; - } - } - - connector.requestHistorySync(2000); - return result; - } - - @Override - public void stopBolusDelivering() { - CancelBolusMessage cancelBolusMessage = new CancelBolusMessage(); - cancelBolusMessage.setMessagePriority(MessagePriority.HIGHEST); - cancelBolusMessage.setBolusId(EventOverviewBolusProgress.getInstance().bolusId); - try { - fetchSingleMessage(cancelBolusMessage); - } catch (Exception e) { - } - } - - // Temporary Basals - - @Override - public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) { - if (L.isEnabled(L.PUMP)) - log.debug("Set TBR absolute: " + absoluteRate); - if (getBaseBasalRate() == 0) { - if (L.isEnabled(L.PUMP)) - log.debug("Base basal rate appears to be zero!"); - return pumpEnactFailure(); - } - double percent = 100D / getBaseBasalRate() * absoluteRate; - if (L.isEnabled(L.PUMP)) - log.debug("Calculated requested rate: " + absoluteRate + " base rate: " + getBaseBasalRate() + " percentage: " + percent + "%"); - try { - if (percent > 250) { - if (L.isEnabled(L.PUMP)) - log.debug("Calculated rate is above 250%, switching to emulation using extended boluses"); - cancelTempBasal(true); - if (!setExtendedBolus((absoluteRate - getBaseBasalRate()) / 60D * ((double) durationInMinutes), durationInMinutes).success) { - //Fallback to TBR if setting an extended bolus didn't work - if (L.isEnabled(L.PUMP)) - log.debug("Setting an extended bolus didn't work, falling back to normal TBR"); - return setTempBasalPercent((int) percent, durationInMinutes, profile, true); - } - return new PumpEnactResult().success(true).enacted(true).absolute(absoluteRate).duration(durationInMinutes); - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Calculated rate is below or equal to 250%, using normal TBRs"); - cancelExtendedBolus(); - return setTempBasalPercent((int) percent, durationInMinutes, profile, true); - } - } catch (Exception e) { - return pumpEnactFailure(); - } - } - - - @Override - public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) { - if (L.isEnabled(L.PUMP)) - log.debug("Set TBR %"); - - percent = (int) Math.round(((double) percent) / 10d) * 10; - if (percent == 100) { - // This would cause a cancel if a tbr is in progress so treat as a cancel - return cancelTempBasal(false); - } else if (percent > 250) percent = 250; - - try { - fetchTaskRunner(new SetTBRTaskRunner(connector.getServiceConnector(), percent, durationInMinutes)); - final TemporaryBasal tempBasal = new TemporaryBasal() - .date(System.currentTimeMillis()) - .percent(percent) - .duration(durationInMinutes) - .source(Source.USER); - TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal); - updateGui(); - if (L.isEnabled(L.PUMP)) - log.debug("Set temp basal " + percent + "% for " + durationInMinutes + "m"); - connector.requestHistorySync(5000); - connector.tryToGetPumpStatusAgain(); - return new PumpEnactResult().success(true).enacted(true).percent(percent); - } catch (Exception e) { - return pumpEnactFailure(); - } - } - - - @Override - public PumpEnactResult cancelTempBasal(boolean enforceNew) { - if (L.isEnabled(L.PUMP)) - log.debug("Cancel TBR called"); - - try { - cancelExtendedBolus(); - SystemClock.sleep(1100); // to be sure db records are at least 1 sec off (for NS) - realTBRCancel(); - SystemClock.sleep(1100); // to be sure db records are at least 1 sec off (for NS) - updateGui(); - connector.requestHistorySync(5000); - connector.tryToGetPumpStatusAgain(); - return new PumpEnactResult().success(true).enacted(true).isTempCancel(true); - } catch (Exception e) { - return pumpEnactFailure(); - } - } - - private void realTBRCancel() throws Exception { - if (fetchTaskRunner(new CancelTBRSilentlyTaskRunner(connector.getServiceConnector()), Boolean.class) && TreatmentsPlugin.getPlugin().isTempBasalInProgress()) { - TemporaryBasal tempStop = new TemporaryBasal().date(System.currentTimeMillis()).source(Source.USER); - TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop); - } - } - - - // Extended Boluses - - @Override - public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { - if (L.isEnabled(L.PUMP)) - log.debug("Set Extended bolus " + insulin + " " + durationInMinutes); - try { - ExtendedBolusMessage extendedBolusMessage = new ExtendedBolusMessage(); - extendedBolusMessage.setAmount(insulin); - extendedBolusMessage.setDuration(durationInMinutes); - BolusMessage bolusMessage = fetchSingleMessage(extendedBolusMessage, BolusMessage.class); - final ExtendedBolus extendedBolus = new ExtendedBolus() - .date(System.currentTimeMillis()) - .insulin(insulin) - .durationInMinutes(durationInMinutes) - .source(Source.USER) - .pumpId(getRecordUniqueID(bolusMessage.getBolusId())); - TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); - updateGui(); - connector.requestHistorySync(30000); - connector.tryToGetPumpStatusAgain(); - return new PumpEnactResult().success(true).enacted(true).duration(durationInMinutes).bolusDelivered(insulin); - } catch (Exception e) { - return pumpEnactFailure(); - } - } - - @Override - public PumpEnactResult cancelExtendedBolus() { - if (L.isEnabled(L.PUMP)) - log.debug("Cancel Extended bolus called"); - - Integer bolusId = null; - - try { - bolusId = fetchTaskRunner(new CancelBolusSilentlyTaskRunner(connector.getServiceConnector(), ActiveBolusType.EXTENDED), Integer.class); - if (TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) { - ExtendedBolus exStop = new ExtendedBolus(System.currentTimeMillis()); - exStop.source = Source.USER; - TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(exStop); - } - if (bolusId != null) connector.requestHistorySync(5000); - connector.tryToGetPumpStatusAgain(); - updateGui(); - return new PumpEnactResult().success(true).enacted(bolusId != null); - } catch (Exception e) { - return pumpEnactFailure(); - } - } - - - private int deliverBolus(double bolusValue) throws Exception { - if (L.isEnabled(L.PUMP)) - log.debug("DeliverBolus: " + bolusValue); - - final StandardBolusMessage message = new StandardBolusMessage(); - message.setAmount(bolusValue); - - return fetchSingleMessage(message, BolusMessage.class).getBolusId(); - } - - @Override - public JSONObject getJSONStatus(Profile profile, String profileName) { - long now = System.currentTimeMillis(); - if (Helpers.msSince(connector.getLastContactTime()) > (60 * 60 * 1000)) { - if (L.isEnabled(L.PUMP)) - log.debug("getJSONStatus not returning as data likely stale"); - return null; - } - - final JSONObject pump = new JSONObject(); - final JSONObject battery = new JSONObject(); - final JSONObject status = new JSONObject(); - final JSONObject extended = new JSONObject(); - try { - battery.put("percent", batteryPercent); - status.put("status", isSuspended() ? "suspended" : "normal"); - status.put("timestamp", DateUtil.toISOString(connector.getLastContactTime())); - extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); - try { - extended.put("ActiveProfile", ProfileFunctions.getInstance().getProfileName()); - } catch (Exception e) { - } - TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); - if (tb != null) { - extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile)); - extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date)); - extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); - } - ExtendedBolus eb = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(now); - if (eb != null) { - extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); - extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); - extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes()); - } - extended.put("BaseBasalRate", getBaseBasalRate()); - status.put("timestamp", DateUtil.toISOString(now)); - - pump.put("battery", battery); - pump.put("status", status); - pump.put("extended", extended); - pump.put("reservoir", reservoirInUnits); - pump.put("clock", DateUtil.toISOString(now)); - } catch (JSONException e) { - log.error("Unhandled exception", e); - } - return pump; - } - - @Override - public String deviceID() { - return "InsightPump"; - } - - @Override - public PumpDescription getPumpDescription() { - return pumpDescription; - } - - @Override - public String shortStatus(boolean veryShort) { - String msg = gs(R.string.insightpump_shortname) + " Batt: " + batteryPercent + " Reserv: " + reservoirInUnits + " Basal: " + basalRate; - if (LiveHistory.getStatus().length() > 0) { - msg += LiveHistory.getStatus(); - } - return msg; - } - - private void processStatusResult() { - if (statusResult != null) { - batteryPercent = statusResult.battery; - reservoirInUnits = (int) statusResult.cartridge; - basalRate = statusResult.baseBasalRate; - profileBlocks = statusResult.basalProfile; - initialized = true; // basic communication test - } - } - - private String gs(int id) { - return MainApp.gs(id); - } - - private boolean isPumpRunning() { - if (statusResult == null) return true; // assume running if we have no information - return statusResult.pumpStatus == PumpStatus.STARTED; - } - - List getStatusItems(boolean refresh) { - final List l = new ArrayList<>(); - - // Todo last contact time - - l.add(new StatusItem(gs(R.string.status_no_colon), connector.getLastStatusMessage())); - l.add(new StatusItem(gs(R.string.changed), connector.getNiceLastStatusTime())); - - boolean pumpRunning; - // also check time since received - if (statusResult != null) { - - pumpRunning = isPumpRunning(); - if (pumpRunning) { - l.add(new StatusItem(gs(R.string.pump_basebasalrate_label), getBaseBasalRateString() + "U")); - } else { - l.add(new StatusItem(gs(R.string.combo_warning), gs(R.string.pump_stopped_uppercase), StatusItem.Highlight.CRITICAL)); - } - } - - final long offset_ms = Helpers.msSince(statusResultTime); - final long offset_minutes = offset_ms / 60000; - - if (statusResult != null) { - l.add(new StatusItem(gs(R.string.status_updated), Helpers.niceTimeScalar(Helpers.msSince(statusResultTime)) + " " + gs(R.string.ago))); - l.add(new StatusItem(gs(R.string.pump_battery_label), batteryPercent + "%", batteryPercent < 100 ? - (batteryPercent < 90 ? - (batteryPercent < 70 ? - (StatusItem.Highlight.BAD) : StatusItem.Highlight.NOTICE) : StatusItem.Highlight.NORMAL) : StatusItem.Highlight.GOOD)); - l.add(new StatusItem(gs(R.string.pump_reservoir_label), reservoirInUnits + "U")); - try { - if (statusResult.tbrAmount != 100) { - l.add(new StatusItem(gs(R.string.insight_active_tbr), statusResult.tbrAmount + "% " + gs(R.string.with) + " " - + Helpers.qs(statusResult.tbrLeftoverDuration - offset_minutes, 0) - + " " + gs(R.string.insight_min_left), StatusItem.Highlight.NOTICE)); - } - } catch (NullPointerException e) { - // currentTBRMessage may be null - } - - } - - if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) { - try { - l.add(new StatusItem(gs(R.string.pump_tempbasal_label), TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull())); - } catch (NullPointerException e) { - // - } - } - - if (statusResult != null) { - try { - statusActiveBolus(statusResult.activeBolus1, offset_minutes, l); - statusActiveBolus(statusResult.activeBolus2, offset_minutes, l); - statusActiveBolus(statusResult.activeBolus3, offset_minutes, l); - } catch (NullPointerException e) { - // getActiveBolusesMessage() may be null - } - } - - if (TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) { - try { - - l.add(new StatusItem(gs(R.string.virtualpump_extendedbolus_label), TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis()).toString())); - } catch (NullPointerException e) { - // - } - } - - l.add(new StatusItem(gs(R.string.log_book), HistoryReceiver.getStatusString())); - - if (LiveHistory.getStatus().length() > 0) { - l.add(new StatusItem(gs(R.string.insight_last_completed_action), LiveHistory.getStatus())); - } - - final String keep_alive_status = Connector.getKeepAliveString(); - if (keep_alive_status != null) { - l.add(new StatusItem(gs(R.string.insight_keep_alive_status), keep_alive_status)); - } - - final List status_statistics = connector.getStatusStatistics(); - if (status_statistics.size() > 0) { - l.addAll(status_statistics); - } - - if (Helpers.ratelimit("insight-status-ui-refresh", 10)) { - connector.tryToGetPumpStatusAgain(); - } - connector.requestHistorySync(); - if (refresh) scheduleGUIUpdate(); - - return l; - } - - private synchronized void scheduleGUIUpdate() { - if (!update_pending && connector.uiFresh()) { - update_pending = true; - Helpers.runOnUiThreadDelayed(new Runnable() { - @Override - public void run() { - updateGui(); - } - }, 1000); - } - } - - private void statusActiveBolus(ActiveBolus activeBolus, long offset_mins, List l) { - if (activeBolus == null) return; - switch (activeBolus.getBolusType()) { - - case STANDARD: - l.add(new StatusItem(activeBolus.getBolusType() + " " + gs(R.string.bolus), activeBolus.getInitialAmount() + "U", StatusItem.Highlight.NOTICE)); - break; - case EXTENDED: - l.add(new StatusItem(activeBolus.getBolusType() + " " + gs(R.string.bolus), activeBolus.getInitialAmount() + "U " + gs(R.string.insight_total_with) + " " - + activeBolus.getLeftoverAmount() + "U " + gs(R.string.insight_remaining_over) + " " + (activeBolus.getDuration() - offset_mins) + " " + gs(R.string.insight_min), StatusItem.Highlight.NOTICE)); - break; - case MULTIWAVE: - l.add(new StatusItem(activeBolus.getBolusType() + " " + gs(R.string.bolus), activeBolus.getInitialAmount() + "U " + gs(R.string.insight_upfront_with) + " " - + activeBolus.getLeftoverAmount() + "U " + gs(R.string.insight_remaining_over) + " " + (activeBolus.getDuration() - offset_mins) + " " + gs(R.string.insight_min), StatusItem.Highlight.NOTICE)); - - break; - default: - log.error("ERROR: unknown bolus type! " + activeBolus.getBolusType()); - } - } - - private void fetchTaskRunner(TaskRunner taskRunner) throws Exception { - fetchTaskRunner(taskRunner, Object.class); - } - - private void fetchSingleMessage(AppLayerMessage message) throws Exception { - fetchSingleMessage(message, AppLayerMessage.class); - } - - private T fetchTaskRunner(TaskRunner taskRunner, Class resultType) throws Exception { - try { - T result = (T) taskRunner.fetchAndWaitUsingLatch(BUSY_WAIT_TIME); - lastDataTime = System.currentTimeMillis(); - return result; - } catch (Exception e) { - log.error("Error while fetching " + taskRunner.getClass().getSimpleName() + ": " + e.getClass().getSimpleName()); - throw e; - } - } - - private T fetchSingleMessage(AppLayerMessage message, Class resultType) throws Exception { - try { - T result = (T) new SingleMessageTaskRunner(connector.getServiceConnector(), message).fetchAndWaitUsingLatch(BUSY_WAIT_TIME); - lastDataTime = System.currentTimeMillis(); - return result; - } catch (Exception e) { - log.error("Error while fetching " + message.getClass().getSimpleName() + ": " + e.getClass().getSimpleName()); - throw e; - } - } - - - private PumpEnactResult pumpEnactFailure() { - return new PumpEnactResult().success(false).enacted(false); - } - - // Constraints - - @Override - public Constraint applyBasalPercentConstraints(Constraint percentRate, Profile profile) { - percentRate.setIfGreater(0, String.format(MainApp.gs(R.string.limitingpercentrate), 0, MainApp.gs(R.string.itmustbepositivevalue)), this); - percentRate.setIfSmaller(getPumpDescription().maxTempPercent, String.format(MainApp.gs(R.string.limitingpercentrate), getPumpDescription().maxTempPercent, MainApp.gs(R.string.pumplimit)), this); - - return percentRate; - } - - @Override - public Constraint applyBolusConstraints(Constraint insulin) { - if (statusResult != null) { - insulin.setIfSmaller(statusResult.maximumBolusAmount, String.format(MainApp.gs(R.string.limitingbolus), statusResult.maximumBolusAmount, MainApp.gs(R.string.pumplimit)), this); - if (insulin.value() < statusResult.minimumBolusAmount) { - - //TODO: Add function to Constraints or use different approach - // This only works if the interface of the InsightPlugin is called last. - // If not, another contraint could theoretically set the value between 0 and minimumBolusAmount - - insulin.set(0d, String.format(MainApp.gs(R.string.limitingbolus), statusResult.minimumBolusAmount, MainApp.gs(R.string.pumplimit)), this); - } - } - return insulin; - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelBolusSilentlyTaskRunner.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelBolusSilentlyTaskRunner.java deleted file mode 100644 index 7b3108602e..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelBolusSilentlyTaskRunner.java +++ /dev/null @@ -1,66 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.connector; - -import sugar.free.sightparser.applayer.descriptors.ActiveBolusType; -import sugar.free.sightparser.applayer.descriptors.MessagePriority; -import sugar.free.sightparser.applayer.descriptors.alerts.Warning38BolusCancelled; -import sugar.free.sightparser.applayer.messages.AppLayerMessage; -import sugar.free.sightparser.applayer.messages.remote_control.CancelBolusMessage; -import sugar.free.sightparser.applayer.messages.remote_control.DismissAlertMessage; -import sugar.free.sightparser.applayer.messages.status.ActiveAlertMessage; -import sugar.free.sightparser.applayer.messages.status.ActiveBolusesMessage; -import sugar.free.sightparser.handling.SightServiceConnector; -import sugar.free.sightparser.handling.TaskRunner; - -// by Tebbe Ubben - -public class CancelBolusSilentlyTaskRunner extends TaskRunner { - - private ActiveBolusType bolusType; - private long cancelledAt; - private int bolusId; - - public CancelBolusSilentlyTaskRunner(SightServiceConnector serviceConnector, ActiveBolusType bolusType) { - super(serviceConnector); - this.bolusType = bolusType; - } - - @Override - protected AppLayerMessage run(AppLayerMessage message) throws Exception { - if (message == null) return new ActiveBolusesMessage(); - else if (message instanceof ActiveBolusesMessage) { - ActiveBolusesMessage bolusesMessage = (ActiveBolusesMessage) message; - CancelBolusMessage cancelBolusMessage = new CancelBolusMessage(); - if (bolusesMessage.getBolus1().getBolusType() == bolusType) - bolusId = bolusesMessage.getBolus1().getBolusID(); - else if (bolusesMessage.getBolus2().getBolusType() == bolusType) - bolusId = bolusesMessage.getBolus2().getBolusID(); - else if (bolusesMessage.getBolus3().getBolusType() == bolusType) - bolusId = bolusesMessage.getBolus3().getBolusID(); - else finish(null); - cancelBolusMessage.setBolusId(bolusId); - return cancelBolusMessage; - } else if (message instanceof CancelBolusMessage) { - cancelledAt = System.currentTimeMillis(); - ActiveAlertMessage activeAlertMessage = new ActiveAlertMessage(); - activeAlertMessage.setMessagePriority(MessagePriority.HIGHER); - return activeAlertMessage; - } else if (message instanceof ActiveAlertMessage) { - ActiveAlertMessage activeAlertMessage = (ActiveAlertMessage) message; - if (activeAlertMessage.getAlert() == null) { - if (System.currentTimeMillis() - cancelledAt >= 10000) finish(bolusId); - else { - ActiveAlertMessage activeAlertMessage2 = new ActiveAlertMessage(); - activeAlertMessage2.setMessagePriority(MessagePriority.HIGHER); - return activeAlertMessage2; - } - } else if (!(activeAlertMessage.getAlert() instanceof Warning38BolusCancelled)) finish(bolusId); - else { - DismissAlertMessage dismissAlertMessage = new DismissAlertMessage(); - dismissAlertMessage.setAlertID(activeAlertMessage.getAlertID()); - dismissAlertMessage.setMessagePriority(MessagePriority.HIGHER); - return dismissAlertMessage; - } - } else if (message instanceof DismissAlertMessage) finish(bolusId); - return null; - } -} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelTBRSilentlyTaskRunner.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelTBRSilentlyTaskRunner.java deleted file mode 100644 index 9a3068aef9..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelTBRSilentlyTaskRunner.java +++ /dev/null @@ -1,50 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.connector; - -import sugar.free.sightparser.applayer.descriptors.MessagePriority; -import sugar.free.sightparser.applayer.descriptors.alerts.Warning36TBRCancelled; -import sugar.free.sightparser.applayer.messages.AppLayerMessage; -import sugar.free.sightparser.applayer.messages.remote_control.CancelTBRMessage; -import sugar.free.sightparser.applayer.messages.remote_control.DismissAlertMessage; -import sugar.free.sightparser.applayer.messages.status.ActiveAlertMessage; -import sugar.free.sightparser.applayer.messages.status.CurrentTBRMessage; -import sugar.free.sightparser.handling.SightServiceConnector; -import sugar.free.sightparser.handling.TaskRunner; - -public class CancelTBRSilentlyTaskRunner extends TaskRunner { - - private long cancelledAt; - - public CancelTBRSilentlyTaskRunner(SightServiceConnector serviceConnector) { - super(serviceConnector); - } - - @Override - protected AppLayerMessage run(AppLayerMessage message) throws Exception { - if (message == null) return new CurrentTBRMessage(); - else if (message instanceof CurrentTBRMessage) { - if (((CurrentTBRMessage) message).getPercentage() == 100) finish(false); - else return new CancelTBRMessage(); - } else if (message instanceof CancelTBRMessage) { - ActiveAlertMessage activeAlertMessage = new ActiveAlertMessage(); - activeAlertMessage.setMessagePriority(MessagePriority.HIGHER); - return activeAlertMessage; - } else if (message instanceof ActiveAlertMessage) { - ActiveAlertMessage activeAlertMessage = (ActiveAlertMessage) message; - if (activeAlertMessage.getAlert() == null) { - if (System.currentTimeMillis() - cancelledAt >= 10000) finish(true); - else { - ActiveAlertMessage activeAlertMessage2 = new ActiveAlertMessage(); - activeAlertMessage2.setMessagePriority(MessagePriority.HIGHER); - return activeAlertMessage2; - } - } else if (!(activeAlertMessage.getAlert() instanceof Warning36TBRCancelled)) finish(true); - else { - DismissAlertMessage dismissAlertMessage = new DismissAlertMessage(); - dismissAlertMessage.setAlertID(activeAlertMessage.getAlertID()); - dismissAlertMessage.setMessagePriority(MessagePriority.HIGHER); - return dismissAlertMessage; - } - } else if (message instanceof DismissAlertMessage) finish(true); - return null; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/Connector.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/Connector.java deleted file mode 100644 index 4a90cd92ca..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/Connector.java +++ /dev/null @@ -1,574 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.connector; - -import android.content.Intent; -import android.os.PowerManager; - -import com.squareup.otto.Subscribe; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Formatter; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.events.EventFeatureRunning; -import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightUpdateGui; -import info.nightscout.androidaps.plugins.PumpInsight.history.HistoryReceiver; -import info.nightscout.androidaps.plugins.PumpInsight.history.LiveHistory; -import info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers; -import info.nightscout.androidaps.plugins.PumpInsight.utils.StatusItem; -import info.nightscout.utils.SP; -import sugar.free.sightparser.handling.ServiceConnectionCallback; -import sugar.free.sightparser.handling.SightServiceConnector; -import sugar.free.sightparser.handling.StatusCallback; -import sugar.free.sightparser.pipeline.Status; - -import static sugar.free.sightparser.handling.HistoryBroadcast.ACTION_START_RESYNC; -import static sugar.free.sightparser.handling.HistoryBroadcast.ACTION_START_SYNC; -import static sugar.free.sightparser.handling.SightService.COMPATIBILITY_VERSION; - -/** - * Created by jamorham on 23/01/2018. - *

- * Connects to SightRemote app service using SightParser library - *

- * SightRemote and SightParser created by Tebbe Ubben - *

- * Original proof of concept SightProxy by jamorham - */ - -public class Connector { - private static Logger log = LoggerFactory.getLogger(L.PUMP); - - // TODO connection statistics - - private static final String TAG = "InsightConnector"; - private static final String COMPANION_APP_PACKAGE = "sugar.free.sightremote"; - private final static long FRESH_MS = 70000; - private static final Map statistics = new HashMap<>(); - private static volatile Connector instance; - private static volatile HistoryReceiver historyReceiver; - private static volatile long stayConnectedTill = -1; - private static volatile long stayConnectedTime = 0; - private static volatile boolean disconnect_thread_running = false; - private volatile SightServiceConnector serviceConnector; - private volatile Status lastStatus = null; - private String compatabilityMessage = null; - private volatile long lastStatusTime = -1; - private volatile long lastContactTime = -1; - private boolean companionAppInstalled = false; - private int serviceReconnects = 0; - private StatusCallback statusCallback = new StatusCallback() { - @Override - public synchronized void onStatusChange(Status status, long statusTime, long waitTime) { - - if ((status != lastStatus) || (Helpers.msSince(lastStatusTime) > 2000)) { - if (L.isEnabled(L.PUMP)) - log.debug("Status change: " + status); - - updateStatusStatistics(lastStatus, lastStatusTime); - lastStatus = status; - lastStatusTime = Helpers.tsl(); - - if (status == Status.CONNECTED) { - lastContactTime = lastStatusTime; - extendKeepAliveIfActive(); - } - - MainApp.bus().post(new EventInsightUpdateGui()); - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Same status as before: " + status); - } - } - - }; - private ServiceConnectionCallback connectionCallback = new ServiceConnectionCallback() { - - @Override - public synchronized void onServiceConnected() { - if (L.isEnabled(L.PUMP)) - log.debug("On service connected"); - try { - final String remoteVersion = serviceConnector.getRemoteVersion(); - if (remoteVersion.equals(COMPATIBILITY_VERSION)) { - serviceConnector.connect(); - } else { - log.error("PROTOCOL VERSION MISMATCH! local: " + COMPATIBILITY_VERSION + " remote: " + remoteVersion); - statusCallback.onStatusChange(Status.INCOMPATIBLE, 0, 0); - compatabilityMessage = MainApp.gs(R.string.insight_incompatible_compantion_app_we_need_version) + " " + getLocalVersion(); - serviceConnector.disconnectFromService(); - - } - } catch (NullPointerException e) { - log.error("ERROR: null pointer when trying to connect to pump"); - } - statusCallback.onStatusChange(safeGetStatus(), 0, 0); - } - - @Override - public synchronized void onServiceDisconnected() { - if (L.isEnabled(L.PUMP)) - log.debug("Disconnected from service"); - if (Helpers.ratelimit("insight-automatic-reconnect", 30)) { - if (L.isEnabled(L.PUMP)) - log.debug("Scheduling automatic service reconnection"); - Helpers.runOnUiThreadDelayed(new Runnable() { - @Override - public void run() { - init(); - } - }, 20000); - } - } - }; - - private Connector() { - initializeHistoryReceiver(); - MainApp.bus().register(this); - } - - public static Connector get() { - if (instance == null) { - init_instance(); - } - return instance; - } - - private synchronized static void init_instance() { - if (instance == null) { - instance = new Connector(); - } - } - - private static boolean isCompanionAppInstalled() { - return Helpers.checkPackageExists(MainApp.instance(), TAG, COMPANION_APP_PACKAGE); - } - - public static void connectToPump() { - connectToPump(0); - } - - public synchronized static void connectToPump(long keep_alive) { - if (L.isEnabled(L.PUMP)) - log.debug("Attempting to connect to pump."); - if (keep_alive > 0 && Helpers.tsl() + keep_alive > stayConnectedTill) { - stayConnectedTime = keep_alive; - stayConnectedTill = Helpers.tsl() + keep_alive; - if (L.isEnabled(L.PUMP)) - log.debug("Staying connected till: " + Helpers.dateTimeText(stayConnectedTill)); - delayedDisconnectionThread(); - } - get().getServiceConnector().connect(); - } - - public static void disconnectFromPump() { - if (Helpers.tsl() >= stayConnectedTill) { - if (L.isEnabled(L.PUMP)) - log.debug("Requesting real pump disconnect"); - get().getServiceConnector().disconnect(); - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Cannot disconnect as due to keep alive till: " + Helpers.dateTimeText(stayConnectedTill)); - // TODO set a disconnection timer? - } - } - - static String getLocalVersion() { - return COMPATIBILITY_VERSION; - } - - private static String statusToString(Status status) { - switch (status) { - - case EXCHANGING_KEYS: - return MainApp.gs(R.string.connecting).toUpperCase(); - case WAITING_FOR_CODE_CONFIRMATION: - return MainApp.gs(R.string.insight_waiting_for_code).toUpperCase(); - case CODE_REJECTED: - return MainApp.gs(R.string.insight_code_rejected).toUpperCase(); - case APP_BINDING: - return MainApp.gs(R.string.insight_app_binding).toUpperCase(); - case CONNECTING: - return MainApp.gs(R.string.connecting).toUpperCase(); - case CONNECTED: - return MainApp.gs(R.string.connected).toUpperCase(); - case DISCONNECTED: - return MainApp.gs(R.string.disconnected).toUpperCase(); - case NOT_AUTHORIZED: - return MainApp.gs(R.string.insight_not_authorized).toUpperCase(); - case INCOMPATIBLE: - return MainApp.gs(R.string.insight_incompatible).toUpperCase(); - - default: - return status.toString(); - } - } - - private static synchronized void extendKeepAliveIfActive() { - if (keepAliveActive()) { - if (Helpers.ratelimit("extend-insight-keepalive", 10)) { - stayConnectedTill = Helpers.tsl() + stayConnectedTime; - if (L.isEnabled(L.PUMP)) - log.debug("Keep-alive extended until: " + Helpers.dateTimeText(stayConnectedTill)); - } - } - } - - private static boolean keepAliveActive() { - return Helpers.tsl() <= stayConnectedTill; - } - - public static String getKeepAliveString() { - if (keepAliveActive()) { - return MainApp.gs(R.string.insight_keepalive_format_string, - stayConnectedTime / 1000, Helpers.hourMinuteSecondString(stayConnectedTill)); - - } else { - return null; - } - } - - private static synchronized void delayedDisconnectionThread() { - if (keepAliveActive()) { - if (!disconnect_thread_running) { - disconnect_thread_running = true; - new Thread(new Runnable() { - @Override - public void run() { - final PowerManager.WakeLock wl = Helpers.getWakeLock("insight-disconnection-timer", 600000); - try { - while (disconnect_thread_running && keepAliveActive()) { - if (Helpers.ratelimit("insight-expiry-notice", 5)) { - if (L.isEnabled(L.PUMP)) - log.debug("Staying connected thread expires: " + Helpers.dateTimeText(stayConnectedTill)); - } - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - // - } - } - - if (disconnect_thread_running) { - if (L.isEnabled(L.PUMP)) - log.debug("Sending the real delayed disconnect"); - get().getServiceConnector().disconnect(); - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Disconnect thread already terminating"); - } - } finally { - Helpers.releaseWakeLock(wl); - disconnect_thread_running = false; - } - } - }).start(); - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Disconnect thread already running"); - } - } - } - - private static long percentage(long t, long total) { - return (long) (Helpers.roundDouble(((double) t * 100) / total, 0)); - } - - public synchronized void shutdown() { - if (instance != null) { - if (L.isEnabled(L.PUMP)) - log.debug("Attempting to shut down connector"); - try { - disconnect_thread_running = false; - try { - instance.serviceConnector.setConnectionCallback(null); - } catch (Exception e) { - // - } - try { - instance.serviceConnector.removeStatusCallback(statusCallback); - } catch (Exception e) { - // - } - try { - instance.serviceConnector.disconnect(); - } catch (Exception e) { - log.error("Exception disconnecting: " + e); - } - try { - instance.serviceConnector.disconnectFromService(); - } catch (Exception e) { - log.error("Excpetion disconnecting service: " + e); - } - instance.serviceConnector = null; - instance = null; - } catch (Exception e) { - log.error("Exception shutting down: " + e); - } - } - } - - @SuppressWarnings("AccessStaticViaInstance") - private synchronized void initializeHistoryReceiver() { - if (historyReceiver == null) { - historyReceiver = new HistoryReceiver(); - } - historyReceiver.registerHistoryReceiver(); - } - - public synchronized void init() { - if (L.isEnabled(L.PUMP)) - log.debug("Connector::init()"); - if (serviceConnector == null) { - companionAppInstalled = isCompanionAppInstalled(); - if (companionAppInstalled) { - serviceConnector = new SightServiceConnector(MainApp.instance()); - serviceConnector.removeStatusCallback(statusCallback); - serviceConnector.addStatusCallback(statusCallback); - serviceConnector.setConnectionCallback(connectionCallback); - serviceConnector.connectToService(); - if (L.isEnabled(L.PUMP)) - log.debug("Trying to connect"); - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Not trying init due to missing companion app"); - } - } else { - if (!serviceConnector.isConnectedToService()) { - if (serviceReconnects > 0) { - serviceConnector = null; - init(); - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Trying to reconnect to service (" + serviceReconnects + ")"); - serviceConnector.connectToService(); - serviceReconnects++; - } - } else { - serviceReconnects = 0; // everything ok - } - } - } - - public SightServiceConnector getServiceConnector() { - init(); - return serviceConnector; - } - - public String getCurrent() { - init(); - return safeGetStatus().toString(); - } - - public Status safeGetStatus() { - try { - if (isConnected()) return serviceConnector.getStatus(); - return Status.DISCONNECTED; - } catch (IllegalArgumentException e) { - return Status.INCOMPATIBLE; - } - } - - public Status getLastStatus() { - return lastStatus; - } - - public boolean isConnected() { - return serviceConnector != null && serviceConnector.isConnectedToService(); - } - - public boolean isPumpConnected() { - return isConnected() && getLastStatus() == Status.CONNECTED; - } - - public boolean isPumpConnecting() { - return isConnected() && getLastStatus() == Status.CONNECTING; - } - - public long getLastContactTime() { - return lastContactTime; - } - - public String getLastStatusMessage() { - - if (!companionAppInstalled) { - return MainApp.gs(R.string.insight_companion_app_not_installed); - } - - if (!isConnected()) { - if (L.isEnabled(L.PUMP)) - log.debug("Not connected to companion"); - if (Helpers.ratelimit("insight-app-not-connected", 5)) { - init(); - } - - if ((lastStatus == null) || (lastStatus != Status.INCOMPATIBLE)) { - if (compatabilityMessage != null) { - // if disconnected but previous state was incompatible - return compatabilityMessage; - } else { - return MainApp.gs(R.string.insight_not_connected_to_companion_app); - } - } - } - - if (lastStatus == null) { - return MainApp.gs(R.string.unknown); - } - - switch (lastStatus) { - case CONNECTED: - if (Helpers.msSince(lastStatusTime) > (60 * 10 * 1000)) { - tryToGetPumpStatusAgain(); - } - break; - case INCOMPATIBLE: - return statusToString(lastStatus) + " " + MainApp.gs(R.string.insight_needs) + " " + getLocalVersion(); - } - return statusToString(lastStatus); - } - - public String getNiceLastStatusTime() { - if (lastStatusTime < 1) { - return MainApp.gs(R.string.insight_startup_uppercase); - } else { - return Helpers.niceTimeScalar(Helpers.msSince(lastStatusTime)) + " " + MainApp.gs(R.string.ago); - } - } - - public boolean uiFresh() { - // todo check other changes - - if (Helpers.msSince(lastStatusTime) < FRESH_MS) { - return true; - } - if (Helpers.msSince(LiveHistory.getStatusTime()) < FRESH_MS) { - return true; - } - return false; - } - - @SuppressWarnings("AccessStaticViaInstance") - public void tryToGetPumpStatusAgain() { - if (Helpers.ratelimit("insight-retry-status-request", 5)) { - try { - ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("Insight. Status missing", null); - } catch (NullPointerException e) { - // - } - } - } - - public void requestHistorySync() { - requestHistorySync(0); - } - - public void requestHistoryReSync() { - requestHistoryReSync(0); - } - - public void requestHistorySync(long delay) { - if (Helpers.ratelimit("insight-history-sync-request", 10)) { - final Intent intent = new Intent(ACTION_START_SYNC); - sendBroadcastToCompanion(intent, delay); - } - } - - public void requestHistoryReSync(long delay) { - if (Helpers.ratelimit("insight-history-resync-request", 300)) { - final Intent intent = new Intent(ACTION_START_RESYNC); - sendBroadcastToCompanion(intent, delay); - } - } - - private void sendBroadcastToCompanion(final Intent intent, final long delay) { - new Thread(new Runnable() { - @Override - public void run() { - final PowerManager.WakeLock wl = Helpers.getWakeLock("insight-companion-delay", 60000); - intent.setPackage(COMPANION_APP_PACKAGE); - intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - try { - if (delay > 0) { - - Thread.sleep(delay); - } - } catch (InterruptedException e) { - // - } finally { - Helpers.releaseWakeLock(wl); - } - MainApp.instance().sendBroadcast(intent); - } - }).start(); - } - - public boolean lastStatusRecent() { - return true; // TODO evaluate whether current - } - - private void updateStatusStatistics(Status last, long since) { - if ((last != null) && (since > 0)) { - Long total = statistics.get(last); - if (total == null) total = 0L; - statistics.put(last, total + Helpers.msSince(since)); - if (L.isEnabled(L.PUMP)) - log.debug("Updated statistics for: " + last + " total: " + Helpers.niceTimeScalar(statistics.get(last))); - // TODO persist data - } - } - - public List getStatusStatistics() { - final List l = new ArrayList<>(); - long total = 0; - for (Map.Entry entry : statistics.entrySet()) { - total += getEntryTime(entry); - } - for (Map.Entry entry : statistics.entrySet()) { - if ((long) entry.getValue() > 1000) { - l.add(new StatusItem(MainApp.gs(R.string.statistics) + " " + Helpers.capitalize(entry.getKey().toString()), - new Formatter().format("%4s %12s", - percentage(getEntryTime(entry), total) + "%", - Helpers.niceTimeScalar(getEntryTime(entry))).toString())); - } - } - return l; - } - - private long getEntryTime(Map.Entry entry) { - return (long) entry.getValue() + (entry.getKey().equals(lastStatus) ? Helpers.msSince(lastStatusTime) : 0); - } - - @Subscribe - public void onStatusEvent(final EventFeatureRunning ev) { - new Thread(new Runnable() { - @Override - public void run() { - if (isConnected()) { - if (SP.getBoolean("insight_preemptive_connect", true)) { - switch (ev.getFeature()) { - case WIZARD: - if (L.isEnabled(L.PUMP)) - log.debug("Wizard feature detected, preconnecting to pump"); - connectToPump(120 * 1000); - break; - case MAIN: - if (L.isEnabled(L.PUMP)) - log.debug("Main feature detected, preconnecting to pump"); - connectToPump(30 * 1000); - break; - } - } - } - } - }).start(); - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/SetTBRTaskRunner.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/SetTBRTaskRunner.java deleted file mode 100644 index f18bb0d487..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/SetTBRTaskRunner.java +++ /dev/null @@ -1,41 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.connector; - -import sugar.free.sightparser.applayer.messages.AppLayerMessage; -import sugar.free.sightparser.applayer.messages.remote_control.ChangeTBRMessage; -import sugar.free.sightparser.applayer.messages.remote_control.SetTBRMessage; -import sugar.free.sightparser.applayer.messages.status.CurrentTBRMessage; -import sugar.free.sightparser.handling.SightServiceConnector; -import sugar.free.sightparser.handling.TaskRunner; - -// from Tebbe - note this uses 1 minute duration to silently cancel existing TBR - -public class SetTBRTaskRunner extends TaskRunner { - - private int amount; - private int duration; - - public SetTBRTaskRunner(SightServiceConnector serviceConnector, int amount, int duration) { - super(serviceConnector); - this.amount = amount; - this.duration = duration; - } - - @Override - protected AppLayerMessage run(AppLayerMessage message) throws Exception { - if (message == null) return new CurrentTBRMessage(); - else if (message instanceof CurrentTBRMessage) { - if (((CurrentTBRMessage) message).getPercentage() == 100) { - SetTBRMessage setTBRMessage = new SetTBRMessage(); - setTBRMessage.setDuration(duration); - setTBRMessage.setAmount(amount); - return setTBRMessage; - } else { - ChangeTBRMessage changeTBRMessage = new ChangeTBRMessage(); - changeTBRMessage.setDuration(duration); - changeTBRMessage.setAmount(amount); - return changeTBRMessage; - } - } else if (message instanceof SetTBRMessage) finish(amount); - return null; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/StatusTaskRunner.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/StatusTaskRunner.java deleted file mode 100644 index 1df56be468..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/StatusTaskRunner.java +++ /dev/null @@ -1,140 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.connector; - -import java.util.List; - -import sugar.free.sightparser.applayer.descriptors.ActiveBolus; -import sugar.free.sightparser.applayer.descriptors.PumpStatus; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.ActiveProfileBlock; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile1Block; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile2Block; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile3Block; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile4Block; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile5Block; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfileBlock; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.ConfigurationBlock; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.FactoryMinBRAmountBlock; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.FactoryMinBolusAmountBlock; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.MaxBRAmountBlock; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.MaxBolusAmountBlock; -import sugar.free.sightparser.applayer.messages.AppLayerMessage; -import sugar.free.sightparser.applayer.messages.configuration.ReadConfigurationBlockMessage; -import sugar.free.sightparser.applayer.messages.status.ActiveBolusesMessage; -import sugar.free.sightparser.applayer.messages.status.BatteryAmountMessage; -import sugar.free.sightparser.applayer.messages.status.CartridgeAmountMessage; -import sugar.free.sightparser.applayer.messages.status.CurrentBasalMessage; -import sugar.free.sightparser.applayer.messages.status.CurrentTBRMessage; -import sugar.free.sightparser.applayer.messages.status.PumpStatusMessage; -import sugar.free.sightparser.handling.SightServiceConnector; -import sugar.free.sightparser.handling.TaskRunner; - -/** - * Created by Tebbe Ubben on 12.03.2018. - */ - -public class StatusTaskRunner extends TaskRunner { - - private Result result = new Result(); - - public StatusTaskRunner(SightServiceConnector serviceConnector) { - super(serviceConnector); - } - - @Override - protected AppLayerMessage run(AppLayerMessage message) throws Exception { - if (message == null) return new PumpStatusMessage(); - else if (message instanceof PumpStatusMessage) { - result.pumpStatus = ((PumpStatusMessage) message).getPumpStatus(); - if (result.pumpStatus == PumpStatus.STOPPED) return new BatteryAmountMessage(); - else return new CurrentTBRMessage(); - } else if (message instanceof CurrentTBRMessage) { - CurrentTBRMessage currentTBRMessage = (CurrentTBRMessage) message; - result.tbrAmount = currentTBRMessage.getPercentage(); - result.tbrInitialDuration = currentTBRMessage.getInitialTime(); - result.tbrLeftoverDuration = currentTBRMessage.getLeftoverTime(); - return new ActiveBolusesMessage(); - } else if (message instanceof ActiveBolusesMessage) { - ActiveBolusesMessage activeBolusesMessage = (ActiveBolusesMessage) message; - result.activeBolus1 = activeBolusesMessage.getBolus1(); - result.activeBolus2 = activeBolusesMessage.getBolus2(); - result.activeBolus3 = activeBolusesMessage.getBolus3(); - return new CurrentBasalMessage(); - } else if (message instanceof CurrentBasalMessage) { - result.baseBasalRate = ((CurrentBasalMessage) message).getCurrentBasalAmount(); - return new BatteryAmountMessage(); - } else if (message instanceof BatteryAmountMessage) { - result.battery = ((BatteryAmountMessage) message).getBatteryAmount(); - return new CartridgeAmountMessage(); - } else if (message instanceof CartridgeAmountMessage) { - result.cartridge = ((CartridgeAmountMessage) message).getCartridgeAmount(); - ReadConfigurationBlockMessage readMessage = new ReadConfigurationBlockMessage(); - readMessage.setConfigurationBlockID(ActiveProfileBlock.ID); - return readMessage; - } else if (message instanceof ReadConfigurationBlockMessage) { - ConfigurationBlock configurationBlock = ((ReadConfigurationBlockMessage) message).getConfigurationBlock(); - if (configurationBlock instanceof ActiveProfileBlock) { - ActiveProfileBlock activeProfileBlock = (ActiveProfileBlock) configurationBlock; - ReadConfigurationBlockMessage readMessage = new ReadConfigurationBlockMessage(); - switch (activeProfileBlock.getActiveProfile()) { - case BR_PROFILE_1: - readMessage.setConfigurationBlockID(BRProfile1Block.ID); - break; - case BR_PROFILE_2: - readMessage.setConfigurationBlockID(BRProfile2Block.ID); - break; - case BR_PROFILE_3: - readMessage.setConfigurationBlockID(BRProfile3Block.ID); - break; - case BR_PROFILE_4: - readMessage.setConfigurationBlockID(BRProfile4Block.ID); - break; - case BR_PROFILE_5: - readMessage.setConfigurationBlockID(BRProfile5Block.ID); - break; - } - return readMessage; - } else if (configurationBlock instanceof BRProfileBlock) { - result.basalProfile = ((BRProfileBlock) configurationBlock).getProfileBlocks(); - ReadConfigurationBlockMessage readMessage = new ReadConfigurationBlockMessage(); - readMessage.setConfigurationBlockID(MaxBolusAmountBlock.ID); - return readMessage; - } else if (configurationBlock instanceof MaxBolusAmountBlock) { - result.maximumBolusAmount = ((MaxBolusAmountBlock) configurationBlock).getMaximumAmount(); - ReadConfigurationBlockMessage readMessage = new ReadConfigurationBlockMessage(); - readMessage.setConfigurationBlockID(MaxBRAmountBlock.ID); - return readMessage; - } else if (configurationBlock instanceof MaxBRAmountBlock) { - result.maximumBasalAmount = ((MaxBRAmountBlock) configurationBlock).getMaximumAmount(); - ReadConfigurationBlockMessage readMessage = new ReadConfigurationBlockMessage(); - readMessage.setConfigurationBlockID(FactoryMinBRAmountBlock.ID); - return readMessage; - } else if (configurationBlock instanceof FactoryMinBRAmountBlock) { - result.minimumBasalAmount = ((FactoryMinBRAmountBlock) configurationBlock).getMinimumAmount(); - ReadConfigurationBlockMessage readMessage = new ReadConfigurationBlockMessage(); - readMessage.setConfigurationBlockID(FactoryMinBolusAmountBlock.ID); - return readMessage; - } else if (configurationBlock instanceof FactoryMinBolusAmountBlock) { - result.minimumBolusAmount = ((FactoryMinBolusAmountBlock) configurationBlock).getMinimumAmount(); - finish(result); - } - } - return null; - } - - public static class Result { - public PumpStatus pumpStatus; - public double baseBasalRate; - public int battery; - public double cartridge ; - public int tbrAmount = 100; - public int tbrInitialDuration = 0; - public int tbrLeftoverDuration = 0; - public ActiveBolus activeBolus1; - public ActiveBolus activeBolus2; - public ActiveBolus activeBolus3; - public List basalProfile; - public double maximumBolusAmount; - public double maximumBasalAmount; - public double minimumBolusAmount; - public double minimumBasalAmount; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/WriteBasalProfileTaskRunner.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/WriteBasalProfileTaskRunner.java deleted file mode 100644 index 7012d200e7..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/WriteBasalProfileTaskRunner.java +++ /dev/null @@ -1,72 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.connector; - -import java.util.List; - -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.ActiveProfileBlock; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile1Block; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile2Block; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile3Block; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile4Block; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile5Block; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfileBlock; -import sugar.free.sightparser.applayer.descriptors.configuration_blocks.ConfigurationBlock; -import sugar.free.sightparser.applayer.messages.AppLayerMessage; -import sugar.free.sightparser.applayer.messages.configuration.CloseWriteSessionMessage; -import sugar.free.sightparser.applayer.messages.configuration.OpenWriteSessionMessage; -import sugar.free.sightparser.applayer.messages.configuration.ReadConfigurationBlockMessage; -import sugar.free.sightparser.applayer.messages.configuration.WriteConfigurationBlockMessage; -import sugar.free.sightparser.handling.SightServiceConnector; -import sugar.free.sightparser.handling.TaskRunner; - -/** - * Created by Tebbe Ubben on 10.03.2018. - */ - -public class WriteBasalProfileTaskRunner extends TaskRunner { - - private List profileBlocks; - private BRProfileBlock profileBlock; - - public WriteBasalProfileTaskRunner(SightServiceConnector serviceConnector, List profileBlocks) { - super(serviceConnector); - this.profileBlocks = profileBlocks; - } - - @Override - protected AppLayerMessage run(AppLayerMessage message) throws Exception { - if (message == null) { - ReadConfigurationBlockMessage readMessage = new ReadConfigurationBlockMessage(); - readMessage.setConfigurationBlockID(ActiveProfileBlock.ID); - return readMessage; - } else if (message instanceof ReadConfigurationBlockMessage) { - ConfigurationBlock configurationBlock = ((ReadConfigurationBlockMessage) message).getConfigurationBlock(); - ActiveProfileBlock activeProfileBlock = (ActiveProfileBlock) configurationBlock; - switch (activeProfileBlock.getActiveProfile()) { - case BR_PROFILE_1: - profileBlock = new BRProfile1Block(); - break; - case BR_PROFILE_2: - profileBlock = new BRProfile2Block(); - break; - case BR_PROFILE_3: - profileBlock = new BRProfile3Block(); - break; - case BR_PROFILE_4: - profileBlock = new BRProfile4Block(); - break; - case BR_PROFILE_5: - profileBlock = new BRProfile5Block(); - break; - } - profileBlock.setProfileBlocks(profileBlocks); - return new OpenWriteSessionMessage(); - } else if (message instanceof OpenWriteSessionMessage) { - WriteConfigurationBlockMessage writeMessage = new WriteConfigurationBlockMessage(); - writeMessage.setConfigurationBlock(profileBlock); - return writeMessage; - } else if (message instanceof WriteConfigurationBlockMessage) { - return new CloseWriteSessionMessage(); - } else if (message instanceof CloseWriteSessionMessage) finish(null); - return null; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/events/EventInsightCallback.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/events/EventInsightCallback.java deleted file mode 100644 index 753ac7f0e6..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/events/EventInsightCallback.java +++ /dev/null @@ -1,26 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.events; - -import java.util.UUID; - -import info.nightscout.androidaps.events.Event; - -/** - * Created by jamorham on 23/01/2018. - */ -public class EventInsightCallback extends Event { - - public UUID request_uuid; - public boolean success = false; - public String message = null; - public Object response_object = null; - - public EventInsightCallback() { - request_uuid = UUID.randomUUID(); - } - - @Override - public String toString() { - return "Event: " + request_uuid + " success: " + success + " msg: " + message + " Object: " + response_object; - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/events/EventInsightUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/events/EventInsightUpdateGui.java deleted file mode 100644 index 3741c607c4..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/events/EventInsightUpdateGui.java +++ /dev/null @@ -1,9 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.events; - -import info.nightscout.androidaps.events.EventUpdateGui; - -/** - * Created by jamorham on 23/01/2018. - */ -public class EventInsightUpdateGui extends EventUpdateGui { -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java deleted file mode 100644 index 49836e9f3b..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java +++ /dev/null @@ -1,243 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.history; - -import android.content.Intent; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.db.CareportalEvent; -import info.nightscout.androidaps.db.TDD; -import info.nightscout.androidaps.logging.L; -import info.nightscout.utils.DateUtil; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.SP; - -import org.json.JSONException; -import org.json.JSONObject; - -import sugar.free.sightparser.handling.HistoryBroadcast; - -import java.util.Date; - -import static info.nightscout.androidaps.plugins.PumpInsight.history.PumpIdCache.updatePumpSerialNumber; - -/** - * Created by jamorham on 27/01/2018. - *

- * Parse inbound logbook intents - */ - -class HistoryIntentAdapter { - private Logger log = LoggerFactory.getLogger(L.PUMP); - - private HistoryLogAdapter logAdapter = new HistoryLogAdapter(); - - private static long getDateExtra(Intent intent, String name) { - return ((Date) intent.getSerializableExtra(name)).getTime(); - } - - static long getRecordUniqueID(long pump_serial_number, long pump_record_id) { - updatePumpSerialNumber(pump_serial_number); - return (pump_serial_number * 10000000) + pump_record_id; - } - - void processTBRIntent(Intent intent) { - - final int pump_tbr_duration = intent.getIntExtra(HistoryBroadcast.EXTRA_DURATION, -1); - final int pump_tbr_percent = intent.getIntExtra(HistoryBroadcast.EXTRA_TBR_AMOUNT, -1); - long pump_record_id = intent.getLongExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1); - if (pump_record_id == -1) { - pump_record_id = intent.getIntExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1); - } - final long pump_serial_number = Long.parseLong(intent.getStringExtra(HistoryBroadcast.EXTRA_PUMP_SERIAL_NUMBER)); - final long start_time = getDateExtra(intent, HistoryBroadcast.EXTRA_START_TIME); - - if ((pump_tbr_duration == -1) || (pump_tbr_percent == -1) || (pump_record_id == -1)) { - log.error("Invalid TBR record!!!"); - return; - } - - final long record_unique_id = getRecordUniqueID(pump_serial_number, pump_record_id); - - if (L.isEnabled(L.PUMP)) - log.debug("Creating TBR record: " + pump_tbr_percent + "% " + pump_tbr_duration + "m" + " id:" + record_unique_id); - logAdapter.createTBRrecord(start_time, pump_tbr_percent, pump_tbr_duration, record_unique_id); - } - - void processDeliveredBolusIntent(Intent intent) { - - final String bolus_type = intent.getStringExtra(HistoryBroadcast.EXTRA_BOLUS_TYPE); - final int bolus_id = intent.getIntExtra(HistoryBroadcast.EXTRA_BOLUS_ID, -1); - long pump_record_id = intent.getLongExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1); - if (pump_record_id == -1) { - pump_record_id = intent.getIntExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1); - } - final long pump_serial_number = Long.parseLong(intent.getStringExtra(HistoryBroadcast.EXTRA_PUMP_SERIAL_NUMBER)); - final long event_time = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME); - final long start_time = getDateExtra(intent, HistoryBroadcast.EXTRA_START_TIME); - final double immediate_amount = intent.getDoubleExtra(HistoryBroadcast.EXTRA_IMMEDIATE_AMOUNT, -1); - final double extended_insulin = intent.getDoubleExtra(HistoryBroadcast.EXTRA_EXTENDED_AMOUNT, -1); - final int extended_minutes = intent.getIntExtra(HistoryBroadcast.EXTRA_DURATION, -1); - - final long record_unique_id = getRecordUniqueID(pump_serial_number, bolus_id > -1 ? bolus_id : pump_record_id); - - switch (bolus_type) { - case "STANDARD": - if (immediate_amount == -1) { - log.error("ERROR Standard bolus fails sanity check"); - return; - } - LiveHistory.setStatus(bolus_type + " BOLUS\n" + immediate_amount + "U ", event_time); - logAdapter.createStandardBolusRecord(start_time, immediate_amount, record_unique_id); - break; - - case "EXTENDED": - if ((extended_insulin == -1) || (extended_minutes == -1)) { - log.error("ERROR: Extended bolus fails sanity check"); - return; - } - LiveHistory.setStatus(bolus_type + " BOLUS\n" + extended_insulin + "U over " + extended_minutes + " min, ", event_time); - logAdapter.createExtendedBolusRecord(start_time, extended_insulin, extended_minutes, record_unique_id); - break; - - case "MULTIWAVE": - if ((immediate_amount == -1) || (extended_insulin == -1) || (extended_minutes == -1)) { - log.error("ERROR: Multiwave bolus fails sanity check"); - return; - } - LiveHistory.setStatus(bolus_type + " BOLUS\n" + immediate_amount + "U + " + extended_insulin + "U over " + extended_minutes + " min, ", event_time); - logAdapter.createStandardBolusRecord(start_time, immediate_amount, pump_serial_number + pump_record_id); - logAdapter.createExtendedBolusRecord(start_time, extended_insulin, extended_minutes, record_unique_id); - break; - default: - log.error("ERROR, UNKNWON BOLUS TYPE: " + bolus_type); - } - } - - void processDailyTotalIntent(Intent intent) { - long date = getDateExtra(intent, HistoryBroadcast.EXTRA_TOTAL_DATE); - double basal = intent.getDoubleExtra(HistoryBroadcast.EXTRA_BASAL_TOTAL, 0D); - double bolus = intent.getDoubleExtra(HistoryBroadcast.EXTRA_BOLUS_TOTAL, 0D); - TDD tdd = new TDD(date, bolus, basal, bolus + basal); - MainApp.getDbHelper().createOrUpdateTDD(tdd); - } - - void processCannulaFilledIntent(Intent intent) { - long date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME); - uploadCareportalEvent(date, CareportalEvent.SITECHANGE); - } - - void processCartridgeInsertedIntent(Intent intent) { - long date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME); - uploadCareportalEvent(date, CareportalEvent.INSULINCHANGE); - } - - void processBatteryInsertedIntent(Intent intent) { - long date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME); - uploadCareportalEvent(date, CareportalEvent.PUMPBATTERYCHANGE); - } - - private void uploadCareportalEvent(long date, String event) { - if (SP.getBoolean("insight_automatic_careportal_events", false)) { - if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date) != null) - return; - try { - JSONObject data = new JSONObject(); - String enteredBy = SP.getString("careportal_enteredby", ""); - if (!enteredBy.equals("")) data.put("enteredBy", enteredBy); - data.put("created_at", DateUtil.toISOString(date)); - data.put("eventType", event); - NSUpload.uploadCareportalEntryToNS(data); - } catch (JSONException e) { - e.printStackTrace(); - } - } - } - - void processOccurenceOfAlertIntent(Intent intent) { - if (SP.getBoolean("insight_automatic_careportal_events", false)) { - long date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME); - String alertType = intent.getStringExtra(HistoryBroadcast.EXTRA_ALERT_TYPE); - int alertText = getAlertText(alertType); - if (alertText == 0) return; - if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date) != null) - return; - logNote(date, MainApp.gs(alertText)); - } - } - - void processPumpStatusChangedIntent(Intent intent) { - long newStatusTime = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME); - if (SP.getBoolean("insight_automatic_careportal_events", false)) { - String newStatus = intent.getStringExtra(HistoryBroadcast.EXTRA_NEW_STATUS); - switch (newStatus) { - case "STARTED": - logNote(newStatusTime, MainApp.gs(R.string.pump_started)); - break; - case "STOPPED": - logNote(newStatusTime, MainApp.gs(R.string.pump_stopped)); - break; - case "PAUSED": - logNote(newStatusTime, MainApp.gs(R.string.pump_paused)); - break; - } - } - if (intent.hasExtra(HistoryBroadcast.EXTRA_OLD_STATUS_TIME)) { - String oldStatus = intent.getStringExtra(HistoryBroadcast.EXTRA_OLD_STATUS); - if (oldStatus.equals("STOPPED")) { - long oldStatusTime = getDateExtra(intent, HistoryBroadcast.EXTRA_OLD_STATUS_TIME); - int duration = (int) ((newStatusTime - oldStatusTime) / 60000); - - long serialNumber = Long.parseLong(intent.getStringExtra(HistoryBroadcast.EXTRA_PUMP_SERIAL_NUMBER)); - long recordId = intent.getLongExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1); - long uniqueRecordId = getRecordUniqueID(serialNumber, recordId); - - logAdapter.createTBRrecord(oldStatusTime, 0, duration, uniqueRecordId); - } - } - } - - private void logNote(long date, String note) { - try { - if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date) != null) - return; - JSONObject data = new JSONObject(); - String enteredBy = SP.getString("careportal_enteredby", ""); - if (!enteredBy.equals("")) data.put("enteredBy", enteredBy); - data.put("created_at", DateUtil.toISOString(date)); - data.put("eventType", CareportalEvent.NOTE); - data.put("notes", note); - NSUpload.uploadCareportalEntryToNS(data); - } catch (JSONException e) { - e.printStackTrace(); - } - } - - private int getAlertText(String type) { - if (type.equals("Error6MechanicalError")) return R.string.alert_e6; - if (type.equals("Error7ElectronicError")) return R.string.alert_e7; - if (type.equals("Error10RewindError")) return R.string.alert_e10; - if (type.equals("Error13LanguageError")) return R.string.alert_e13; - if (type.equals("Maintenance20CartridgeNotInserted")) return R.string.alert_m20; - if (type.equals("Maintenance21CartridgeEmpty")) return R.string.alert_m21; - if (type.equals("Maintenance22BatteryEmpty")) return R.string.alert_m22; - if (type.equals("Maintenance23AutomaticOff")) return R.string.alert_m23; - if (type.equals("Maintenance24Occlusion")) return R.string.alert_m24; - if (type.equals("Maintenance25LoantimeOver")) return R.string.alert_m25; - if (type.equals("Maintenance26CartridgeChangeNotCompleted")) return R.string.alert_m26; - if (type.equals("Maintenance27DataDownloadFailed")) return R.string.alert_m27; - if (type.equals("Maintenance28PauseModeTimeout")) return R.string.alert_m28; - if (type.equals("Maintenance29BatteryTypeNotSet")) return R.string.alert_m29; - if (type.equals("Maintenance30CartridgeTypeNotSet")) return R.string.alert_m30; - if (type.equals("Warning31CartridgeLow")) return R.string.alert_w31; - if (type.equals("Warning32BatteryLow")) return R.string.alert_w32; - if (type.equals("Warning33InvalidDateTime")) return R.string.alert_w33; - if (type.equals("Warning34EndOfWarranty")) return R.string.alert_w34; - if (type.equals("Warning36TBRCancelled")) return 0; - if (type.equals("Warning38BolusCancelled")) return 0; - if (type.equals("Warning39LoantimeWarning")) return R.string.alert_w39; - return 0; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryLogAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryLogAdapter.java deleted file mode 100644 index fc44f25418..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryLogAdapter.java +++ /dev/null @@ -1,136 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.history; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.data.DetailedBolusInfo; -import info.nightscout.androidaps.db.ExtendedBolus; -import info.nightscout.androidaps.db.Source; -import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.T; - -/** - * Created by jamorham on 27/01/2018. - *

- * Write to the History Log - */ - -class HistoryLogAdapter { - private Logger log = LoggerFactory.getLogger(L.PUMP); - - private static final long MAX_TIME_DIFFERENCE = T.secs(61).msecs(); - - void createTBRrecord(long eventDate, int percent, int duration, long record_id) { - - TemporaryBasal temporaryBasal = new TemporaryBasal().date(eventDate); - - final TemporaryBasal temporaryBasalFromHistory = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(eventDate); - - if (temporaryBasalFromHistory == null) { - if (L.isEnabled(L.PUMP)) - log.debug("Create new TBR: " + eventDate + " " + percent + " " + duration); - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Loaded existing TBR record: " + temporaryBasalFromHistory.toString()); - if (Math.abs(eventDate - temporaryBasalFromHistory.date) < MAX_TIME_DIFFERENCE) { - if (temporaryBasalFromHistory.source != Source.PUMP) { - if (temporaryBasalFromHistory.percentRate == percent) { - if (L.isEnabled(L.PUMP)) - log.debug("Things seem to match: %" + percent); - temporaryBasal = temporaryBasalFromHistory; - String _id = temporaryBasal._id; - if (NSUpload.isIdValid(_id)) { - NSUpload.removeCareportalEntryFromNS(_id); - } else { - UploadQueue.removeID("dbAdd", _id); - } - MainApp.getDbHelper().delete(temporaryBasalFromHistory); - } else { - if (L.isEnabled(L.PUMP)) - log.debug("This record has different percent rates: " + temporaryBasalFromHistory.percentRate + " vs us: " + percent); - } - } else { - if (L.isEnabled(L.PUMP)) - log.debug("This record is already a pump record!"); - } - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Time difference too big! : " + (eventDate - temporaryBasalFromHistory.date)); - } - } - - temporaryBasal.source(Source.PUMP) - .pumpId(record_id) - .percent(percent) - .duration(duration); - - TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal); - } - - void createExtendedBolusRecord(long eventDate, double insulin, int durationInMinutes, long record_id) { - - final ExtendedBolus extendedBolusFromHistory = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(eventDate); - - if (extendedBolusFromHistory == null) { - if (L.isEnabled(L.PUMP)) - log.debug("Create new EB: " + eventDate + " " + insulin + " " + durationInMinutes); - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Loaded existing EB record: " + extendedBolusFromHistory.log()); - if (Math.abs(eventDate - extendedBolusFromHistory.date) < MAX_TIME_DIFFERENCE) { - if (extendedBolusFromHistory.source != Source.PUMP) { - if (L.isEnabled(L.PUMP)) - log.debug("Date seem to match: " + DateUtil.dateAndTimeFullString(eventDate)); - String _id = extendedBolusFromHistory._id; - if (NSUpload.isIdValid(_id)) { - NSUpload.removeCareportalEntryFromNS(_id); - } else { - UploadQueue.removeID("dbAdd", _id); - } - MainApp.getDbHelper().delete(extendedBolusFromHistory); - } else { - if (L.isEnabled(L.PUMP)) - log.debug("This record is already a pump record!"); - } - } else { - if (L.isEnabled(L.PUMP)) - log.debug("Time difference too big! : " + (eventDate - extendedBolusFromHistory.date)); - } - } - - // TODO trap items below minimum period - - // TODO (mike) find and remove ending record with Source.USER - - ExtendedBolus extendedBolus = new ExtendedBolus() - .date(eventDate) - .insulin(insulin) - .durationInMinutes(durationInMinutes) - .source(Source.PUMP) - .pumpId(record_id); - - if (ProfileFunctions.getInstance().getProfile(extendedBolus.date) != null) // actual basal rate is needed for absolute rate calculation - TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); - } - - void createStandardBolusRecord(long eventDate, double insulin, long record_id) { - - //DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(eventDate.getTime()); - - // TODO do we need to do the same delete + insert that we are doing for temporary basals here too? - - final DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); - detailedBolusInfo.date = eventDate; - detailedBolusInfo.source = Source.PUMP; - detailedBolusInfo.pumpId = record_id; - detailedBolusInfo.insulin = insulin; - TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryReceiver.java deleted file mode 100644 index a66378ba54..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryReceiver.java +++ /dev/null @@ -1,134 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.history; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; - -import static info.nightscout.androidaps.plugins.PumpInsight.history.HistoryReceiver.Status.BUSY; -import static info.nightscout.androidaps.plugins.PumpInsight.history.HistoryReceiver.Status.SYNCED; -import static info.nightscout.androidaps.plugins.PumpInsight.history.HistoryReceiver.Status.SYNCING; -import static sugar.free.sightparser.handling.HistoryBroadcast.*; - -/** - * Created by jamorham on 27/01/2018. - */ - -public class HistoryReceiver { - - private static BroadcastReceiver historyReceiver; - private volatile static Status status = Status.IDLE; - private volatile HistoryIntentAdapter intentAdapter; - - public HistoryReceiver() { - initializeHistoryReceiver(); - } - - public static synchronized void registerHistoryReceiver() { - try { - MainApp.instance().unregisterReceiver(historyReceiver); - } catch (Exception e) { - // - } - - final IntentFilter filter = new IntentFilter(); - filter.addAction(ACTION_PUMP_STATUS_CHANGED); - filter.addAction(ACTION_BOLUS_PROGRAMMED); - filter.addAction(ACTION_BOLUS_DELIVERED); - filter.addAction(ACTION_END_OF_TBR); - filter.addAction(ACTION_DAILY_TOTAL); - filter.addAction(ACTION_SYNC_STARTED); - filter.addAction(ACTION_STILL_SYNCING); - filter.addAction(ACTION_SYNC_FINISHED); - filter.addAction(ACTION_CANNULA_FILLED); - filter.addAction(ACTION_CARTRIDGE_INSERTED); - filter.addAction(ACTION_BATTERY_INSERTED); - filter.addAction(ACTION_OCCURENCE_OF_ALERT); - filter.addAction(ACTION_PUMP_STATUS_CHANGED); - - MainApp.instance().registerReceiver(historyReceiver, filter); - } - - // History - - public static String getStatusString() { - return status.toString(); - } - - private synchronized void initializeHistoryReceiver() { - historyReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, final Intent intent) { - - final String action = intent.getAction(); - if (action == null) return; - - if (intentAdapter == null) { - synchronized (this) { - if (intentAdapter == null) { - intentAdapter = new HistoryIntentAdapter(); - } - } - } - - switch (action) { - case ACTION_SYNC_STARTED: - status = SYNCING; - break; - case ACTION_STILL_SYNCING: - status = BUSY; - break; - case ACTION_SYNC_FINISHED: - status = SYNCED; - break; - case ACTION_BOLUS_DELIVERED: - intentAdapter.processDeliveredBolusIntent(intent); - break; - case ACTION_END_OF_TBR: - intentAdapter.processTBRIntent(intent); - break; - case ACTION_DAILY_TOTAL: - intentAdapter.processDailyTotalIntent(intent); - break; - case ACTION_CANNULA_FILLED: - intentAdapter.processCannulaFilledIntent(intent); - break; - case ACTION_CARTRIDGE_INSERTED: - intentAdapter.processCartridgeInsertedIntent(intent); - break; - case ACTION_BATTERY_INSERTED: - intentAdapter.processBatteryInsertedIntent(intent); - break; - case ACTION_OCCURENCE_OF_ALERT: - intentAdapter.processOccurenceOfAlertIntent(intent); - break; - case ACTION_PUMP_STATUS_CHANGED: - intentAdapter.processPumpStatusChangedIntent(intent); - break; - } - } - }; - } - - enum Status { - IDLE(R.string.insight_history_idle), - SYNCING(R.string.insight_history_syncing), - BUSY(R.string.insight_history_busy), - SYNCED(R.string.insight_history_synced); - - private final int string_id; - - Status(int string_id) { - this.string_id = string_id; - } - - @Override - public String toString() { - return MainApp.gs(string_id); - } - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/LiveHistory.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/LiveHistory.java deleted file mode 100644 index 46af6bda98..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/LiveHistory.java +++ /dev/null @@ -1,33 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.history; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers; - -/** - * Created by jamorham on 27/01/2018. - * - * In memory status storage class - */ - -public class LiveHistory { - - private static String status = ""; - private static long status_time = -1; - - public static String getStatus() { - if (status.equals("")) return status; - return status + " " + Helpers.niceTimeScalar(Helpers.msSince(status_time)) + " " + MainApp.gs(R.string.ago); - } - - public static long getStatusTime() { - return status_time; - } - - static void setStatus(String mystatus, long eventtime) { - if (eventtime > status_time) { - status_time = eventtime; - status = mystatus; - } - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/PumpIdCache.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/PumpIdCache.java deleted file mode 100644 index 9a2bcfeff5..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/PumpIdCache.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.history; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import info.nightscout.androidaps.logging.L; -import info.nightscout.utils.SP; - -/** - * Created by jamorham on 01/02/2018. - */ - -public class PumpIdCache { - private static Logger log = LoggerFactory.getLogger(L.PUMP); - - private static final String INSIGHT_PUMP_ID_PREF = "insight-pump-id"; - private static long cachedPumpSerialNumber = -1; - - static void updatePumpSerialNumber(long pump_serial_number) { - if (pump_serial_number != cachedPumpSerialNumber) { - cachedPumpSerialNumber = pump_serial_number; - if (L.isEnabled(L.PUMP)) - log.debug("Updating pump serial number: " + pump_serial_number); - SP.putLong(INSIGHT_PUMP_ID_PREF, cachedPumpSerialNumber); - } - } - - public static long getRecordUniqueID(long record_id) { - if (cachedPumpSerialNumber == -1) { - cachedPumpSerialNumber = SP.getLong(INSIGHT_PUMP_ID_PREF, 0L); - } - return HistoryIntentAdapter.getRecordUniqueID(cachedPumpSerialNumber, record_id); - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/Helpers.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/Helpers.java deleted file mode 100644 index bfdca16588..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/Helpers.java +++ /dev/null @@ -1,197 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.utils; - -import android.content.Context; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.os.Handler; -import android.os.PowerManager; -import android.util.Log; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.util.HashMap; -import java.util.Map; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.logging.L; - -/** - * Created by jamorham on 24/01/2018. - *

- * Useful utility methods from xDrip+ - */ - -public class Helpers { - private static Logger log = LoggerFactory.getLogger(L.PUMP); - - - private static final Map rateLimits = new HashMap<>(); - // singletons to avoid repeated allocation - private static DecimalFormatSymbols dfs; - private static DecimalFormat df; - - // return true if below rate limit - public static synchronized boolean ratelimit(String name, int seconds) { - // check if over limit - if ((rateLimits.containsKey(name)) && (tsl() - rateLimits.get(name) < (seconds * 1000))) { - if (L.isEnabled(L.PUMP)) - log.debug(name + " rate limited: " + seconds + " seconds"); - return false; - } - // not over limit - rateLimits.put(name, tsl()); - return true; - } - - public static long tsl() { - return System.currentTimeMillis(); - } - - public static long msSince(long when) { - return (tsl() - when); - } - - public static long msTill(long when) { - return (when - tsl()); - } - - public static boolean checkPackageExists(Context context, String TAG, String packageName) { - try { - final PackageManager pm = context.getPackageManager(); - final PackageInfo pi = pm.getPackageInfo(packageName, 0); - return pi.packageName.equals(packageName); - } catch (PackageManager.NameNotFoundException e) { - return false; - } catch (Exception e) { - log.error("Exception trying to determine packages! " + e); - return false; - } - } - - public static boolean runOnUiThreadDelayed(Runnable theRunnable, long delay) { - return new Handler(MainApp.instance().getMainLooper()).postDelayed(theRunnable, delay); - } - - public static PowerManager.WakeLock getWakeLock(final String name, int millis) { - final PowerManager pm = (PowerManager) MainApp.instance().getSystemService(Context.POWER_SERVICE); - if (pm == null) return null; - final PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, name); - wl.acquire(millis); - return wl; - } - - public static void releaseWakeLock(PowerManager.WakeLock wl) { - if (wl == null) return; - if (wl.isHeld()) wl.release(); - } - - public static String niceTimeSince(long t) { - return niceTimeScalar(msSince(t)); - } - - public static String niceTimeTill(long t) { - return niceTimeScalar(-msSince(t)); - } - - public static String niceTimeScalar(long t) { - String unit = MainApp.gs(R.string.second); - t = t / 1000; - if (t > 59) { - unit = MainApp.gs(R.string.minute); - t = t / 60; - if (t > 59) { - unit = MainApp.gs(R.string.hour); - t = t / 60; - if (t > 24) { - unit = MainApp.gs(R.string.day); - t = t / 24; - if (t > 28) { - unit = MainApp.gs(R.string.week); - t = t / 7; - } - } - } - } - if (t != 1) unit = unit + MainApp.gs(R.string.time_plural); - return qs((double) t, 0) + " " + unit; - } - - public static String qs(double x, int digits) { - - if (digits == -1) { - digits = 0; - if (((int) x != x)) { - digits++; - if ((((int) x * 10) / 10 != x)) { - digits++; - if ((((int) x * 100) / 100 != x)) digits++; - } - } - } - - if (dfs == null) { - final DecimalFormatSymbols local_dfs = new DecimalFormatSymbols(); - local_dfs.setDecimalSeparator('.'); - dfs = local_dfs; // avoid race condition - } - - final DecimalFormat this_df; - // use singleton if on ui thread otherwise allocate new as DecimalFormat is not thread safe - if (Thread.currentThread().getId() == 1) { - if (df == null) { - final DecimalFormat local_df = new DecimalFormat("#", dfs); - local_df.setMinimumIntegerDigits(1); - df = local_df; // avoid race condition - } - this_df = df; - } else { - this_df = new DecimalFormat("#", dfs); - } - - this_df.setMaximumFractionDigits(digits); - return this_df.format(x); - } - - public static String niceTimeScalarRedux(long t) { - return niceTimeScalar(t).replaceFirst("^1 ", ""); - } - - public static String niceTimeScalarBrief(long t) { - // TODO i18n wont work for non-latin characterset - return niceTimeScalar(t).replaceFirst("([a-z])[a-z]*", "$1").replace(" ", ""); - } - - public static String hourMinuteString(long timestamp) { - return android.text.format.DateFormat.format("kk:mm", timestamp).toString(); - } - - public static String hourMinuteSecondString(long timestamp) { - return android.text.format.DateFormat.format("kk:mm:ss", timestamp).toString(); - } - - public static String dateTimeText(long timestamp) { - return android.text.format.DateFormat.format("yyyy-MM-dd kk:mm:ss", timestamp).toString(); - } - - public static String dateText(long timestamp) { - return android.text.format.DateFormat.format("yyyy-MM-dd", timestamp).toString(); - } - - public static String capitalize(String text) { - return text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase(); - } - - public static double roundDouble(double value, int places) { - if (places < 0) throw new IllegalArgumentException("Invalid decimal places"); - BigDecimal bd = new BigDecimal(value); - bd = bd.setScale(places, RoundingMode.HALF_UP); - return bd.doubleValue(); - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/StatusItem.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/StatusItem.java deleted file mode 100644 index 395dd51084..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/StatusItem.java +++ /dev/null @@ -1,64 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.utils; - -/** - * Created by jamorham on 26/01/2018. - * - * For representing row status items - */ - -public class StatusItem { - - public enum Highlight { - NORMAL, - GOOD, - BAD, - NOTICE, - CRITICAL - } - - public String name; - public String value; - public Highlight highlight; - public String button_name; - public Runnable runnable; - - - public StatusItem(String name, String value) { - this(name, value, Highlight.NORMAL); - } - - public StatusItem() { - this("line-break", "", Highlight.NORMAL); - } - - public StatusItem(String name, Highlight highlight) { - this("heading-break", name, highlight); - } - - public StatusItem(String name, Runnable runnable) { - this("button-break", "", Highlight.NORMAL, name, runnable); - } - - public StatusItem(String name, String value, Highlight highlight) { - this(name, value, highlight, null, null); - } - - public StatusItem(String name, String value, Highlight highlight, String button_name, Runnable runnable) { - this.name = name; - this.value = value; - this.highlight = highlight; - this.button_name = button_name; - this.runnable = runnable; - } - - public StatusItem(String name, Integer value) { - this(name, value, Highlight.NORMAL); - } - - public StatusItem(String name, Integer value, Highlight highlight) { - this.name = name; - this.value = Integer.toString(value); - this.highlight = highlight; - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/ui/StatusItemViewAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/ui/StatusItemViewAdapter.java deleted file mode 100644 index 87c40c19de..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/ui/StatusItemViewAdapter.java +++ /dev/null @@ -1,85 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpInsight.utils.ui; - -import android.app.Activity; -import android.graphics.Color; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.widget.LinearLayout; -import android.widget.TextView; - -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.PumpInsight.utils.StatusItem; - -/** - * Created by jamorham on 26/01/2018. - * - * Convert StatusItem to View - */ - -public class StatusItemViewAdapter { - - private final Activity activity; - private final ViewGroup holder; - - public StatusItemViewAdapter(Activity activity, ViewGroup holder) { - this.activity = activity; - this.holder = holder; - } - - public View inflateStatus(StatusItem statusItem) { - if (activity == null) return null; - final View child = activity.getLayoutInflater().inflate(R.layout.insightpump_statuselements, null); - final TextView name = (TextView) child.findViewById(R.id.insightstatuslabel); - final TextView value = (TextView)child.findViewById(R.id.insightstatusvalue); - final TextView spacer = (TextView)child.findViewById(R.id.insightstatusspacer); - final LinearLayout layout = (LinearLayout)child.findViewById(R.id.insightstatuslayout); - - if (statusItem.name.equals("line-break")) { - spacer.setVisibility(View.GONE); - name.setVisibility(View.GONE); - value.setVisibility(View.GONE); - layout.setPadding(10, 10, 10, 10); - } else if (statusItem.name.equals("heading-break")) { - value.setVisibility(View.GONE); - spacer.setVisibility(View.GONE); - name.setText(statusItem.value); - name.setGravity(Gravity.CENTER_HORIZONTAL); - name.setTextColor(Color.parseColor("#fff9c4")); - } else { - name.setText(statusItem.name); - value.setText(statusItem.value); - } - - final int this_color = getHighlightColor(statusItem); - name.setBackgroundColor(this_color); - value.setBackgroundColor(this_color); - spacer.setBackgroundColor(this_color); - - if (this_color != Color.TRANSPARENT) { - name.setTextColor(Color.WHITE); - spacer.setTextColor(Color.WHITE); - } - - if (holder != null) { - holder.addView(child); - } - return child; - } - - private static int getHighlightColor(StatusItem row) { - switch (row.highlight) { - case BAD: - return Color.parseColor("#480000"); - case NOTICE: - return Color.parseColor("#403000"); - case GOOD: - return Color.parseColor("#003000"); - case CRITICAL: - return Color.parseColor("#770000"); - default: - return Color.TRANSPARENT; - } - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorFragment.java deleted file mode 100644 index 3f218063ef..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorFragment.java +++ /dev/null @@ -1,92 +0,0 @@ -package info.nightscout.androidaps.plugins.SmsCommunicator; - - -import android.app.Activity; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.text.Html; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import com.squareup.otto.Subscribe; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collections; -import java.util.Comparator; - -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventSmsCommunicatorUpdateGui; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.FabricPrivacy; - -/** - * A simple {@link Fragment} subclass. - */ -public class SmsCommunicatorFragment extends SubscriberFragment { - private static Logger log = LoggerFactory.getLogger(SmsCommunicatorFragment.class); - - TextView logView; - - public SmsCommunicatorFragment() { - super(); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - try { - View view = inflater.inflate(R.layout.smscommunicator_fragment, container, false); - - logView = (TextView) view.findViewById(R.id.smscommunicator_log); - - updateGUI(); - return view; - } catch (Exception e) { - FabricPrivacy.logException(e); - } - - return null; - } - - @Subscribe - public void onStatusEvent(final EventSmsCommunicatorUpdateGui ev) { - updateGUI(); - } - - - @Override - protected void updateGUI() { - Activity activity = getActivity(); - if (activity != null) - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - class CustomComparator implements Comparator { - public int compare(SmsCommunicatorPlugin.Sms object1, SmsCommunicatorPlugin.Sms object2) { - return (int) (object1.date - object2.date); - } - } - Collections.sort(SmsCommunicatorPlugin.getPlugin().messages, new CustomComparator()); - int messagesToShow = 40; - - int start = Math.max(0, SmsCommunicatorPlugin.getPlugin().messages.size() - messagesToShow); - - String logText = ""; - for (int x = start; x < SmsCommunicatorPlugin.getPlugin().messages.size(); x++) { - SmsCommunicatorPlugin.Sms sms = SmsCommunicatorPlugin.getPlugin().messages.get(x); - if (sms.received) { - logText += DateUtil.timeString(sms.date) + " <<< " + (sms.processed ? "● " : "○ ") + sms.phoneNumber + " " + sms.text + "
"; - } else if (sms.sent) { - logText += DateUtil.timeString(sms.date) + " >>> " + (sms.processed ? "● " : "○ ") + sms.phoneNumber + " " + sms.text + "
"; - } - } - logView.setText(Html.fromHtml(logText)); - } - }); - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java deleted file mode 100644 index e5e1a6c18e..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java +++ /dev/null @@ -1,606 +0,0 @@ -package info.nightscout.androidaps.plugins.SmsCommunicator; - -import android.content.Intent; -import android.content.pm.ResolveInfo; -import android.os.Bundle; -import android.os.SystemClock; -import android.telephony.SmsManager; -import android.telephony.SmsMessage; - -import com.crashlytics.android.answers.CustomEvent; -import com.squareup.otto.Subscribe; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.text.Normalizer; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import info.nightscout.androidaps.Constants; -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.services.Intents; -import info.nightscout.androidaps.data.DetailedBolusInfo; -import info.nightscout.androidaps.data.GlucoseStatus; -import info.nightscout.androidaps.data.IobTotal; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.db.BgReading; -import info.nightscout.androidaps.db.DatabaseHelper; -import info.nightscout.androidaps.db.Source; -import info.nightscout.androidaps.events.EventPreferenceChange; -import info.nightscout.androidaps.events.EventRefreshOverview; -import info.nightscout.androidaps.interfaces.Constraint; -import info.nightscout.androidaps.interfaces.PluginBase; -import info.nightscout.androidaps.interfaces.PluginDescription; -import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventSmsCommunicatorUpdateGui; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.SP; -import info.nightscout.utils.SafeParse; -import info.nightscout.utils.T; -import info.nightscout.utils.XdripCalibrations; - -/** - * Created by mike on 05.08.2016. - */ -public class SmsCommunicatorPlugin extends PluginBase { - private static Logger log = LoggerFactory.getLogger(SmsCommunicatorPlugin.class); - - private static SmsCommunicatorPlugin smsCommunicatorPlugin; - - public static SmsCommunicatorPlugin getPlugin() { - - if (smsCommunicatorPlugin == null) { - smsCommunicatorPlugin = new SmsCommunicatorPlugin(); - } - return smsCommunicatorPlugin; - } - - private List allowedNumbers = new ArrayList<>(); - - class Sms { - String phoneNumber; - String text; - long date; - boolean received = false; - boolean sent = false; - boolean processed = false; - - String confirmCode; - double bolusRequested = 0d; - double tempBasal = 0d; - double calibrationRequested = 0d; - int duration = 0; - - Sms(SmsMessage message) { - phoneNumber = message.getOriginatingAddress(); - text = message.getMessageBody(); - date = message.getTimestampMillis(); - received = true; - } - - Sms(String phoneNumber, String text, long date) { - this.phoneNumber = phoneNumber; - this.text = text; - this.date = date; - sent = true; - } - - Sms(String phoneNumber, String text, long date, String confirmCode) { - this.phoneNumber = phoneNumber; - this.text = text; - this.date = date; - this.confirmCode = confirmCode; - sent = true; - } - - public String toString() { - return "SMS from " + phoneNumber + ": " + text; - } - } - - private Sms cancelTempBasalWaitingForConfirmation = null; - private Sms tempBasalWaitingForConfirmation = null; - private Sms bolusWaitingForConfirmation = null; - private Sms calibrationWaitingForConfirmation = null; - private Sms suspendWaitingForConfirmation = null; - private Date lastRemoteBolusTime = new Date(0); - - ArrayList messages = new ArrayList<>(); - - private SmsCommunicatorPlugin() { - super(new PluginDescription() - .mainType(PluginType.GENERAL) - .fragmentClass(SmsCommunicatorFragment.class.getName()) - .pluginName(R.string.smscommunicator) - .shortName(R.string.smscommunicator_shortname) - .preferencesId(R.xml.pref_smscommunicator) - .description(R.string.description_sms_communicator) - ); - processSettings(null); - } - - @Override - protected void onStart() { - MainApp.bus().register(this); - super.onStart(); - } - - @Override - protected void onStop() { - MainApp.bus().unregister(this); - } - - @Subscribe - public void processSettings(final EventPreferenceChange ev) { - if (ev == null || ev.isChanged(R.string.key_smscommunicator_allowednumbers)) { - String settings = SP.getString(R.string.key_smscommunicator_allowednumbers, ""); - - String pattern = ";"; - - String[] substrings = settings.split(pattern); - for (String number : substrings) { - String cleaned = number.replaceAll("\\s+", ""); - allowedNumbers.add(cleaned); - log.debug("Found allowed number: " + cleaned); - } - } - } - - private boolean isAllowedNumber(String number) { - for (String num : allowedNumbers) { - if (num.equals(number)) return true; - } - return false; - } - - public void handleNewData(Intent intent) { - Bundle bundle = intent.getExtras(); - if (bundle == null) return; - - Object[] pdus = (Object[]) bundle.get("pdus"); - if (pdus != null) { - // For every SMS message received - for (Object pdu : pdus) { - SmsMessage message = SmsMessage.createFromPdu((byte[]) pdu); - processSms(new Sms(message)); - } - } - } - - private void processSms(final Sms receivedSms) { - if (!isEnabled(PluginType.GENERAL)) { - log.debug("Ignoring SMS. Plugin disabled."); - return; - } - if (!isAllowedNumber(receivedSms.phoneNumber)) { - log.debug("Ignoring SMS from: " + receivedSms.phoneNumber + ". Sender not allowed"); - return; - } - - String reply = ""; - - messages.add(receivedSms); - log.debug(receivedSms.toString()); - - String[] splited = receivedSms.text.split("\\s+"); - Double amount; - Double tempBasal; - int duration = 0; - String passCode; - boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false); - - if (splited.length > 0) { - switch (splited[0].toUpperCase()) { - case "BG": - BgReading actualBG = DatabaseHelper.actualBg(); - BgReading lastBG = DatabaseHelper.lastBg(); - - String units = ProfileFunctions.getInstance().getProfileUnits(); - - if (actualBG != null) { - reply = MainApp.gs(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", "; - } else if (lastBG != null) { - Long agoMsec = System.currentTimeMillis() - lastBG.date; - int agoMin = (int) (agoMsec / 60d / 1000d); - reply = MainApp.gs(R.string.sms_lastbg) + " " + lastBG.valueToUnitsToString(units) + " " + String.format(MainApp.gs(R.string.sms_minago), agoMin) + ", "; - } - GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); - if (glucoseStatus != null) - reply += MainApp.gs(R.string.sms_delta) + " " + Profile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", "; - - TreatmentsPlugin.getPlugin().updateTotalIOBTreatments(); - IobTotal bolusIob = TreatmentsPlugin.getPlugin().getLastCalculationTreatments().round(); - TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals(); - IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().round(); - - reply += MainApp.gs(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U (" - + MainApp.gs(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U " - + MainApp.gs(R.string.sms_basal) + " " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)"; - - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - receivedSms.processed = true; - FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Bg")); - break; - case "LOOP": - if (splited.length > 1) - switch (splited[1].toUpperCase()) { - case "DISABLE": - case "STOP": - LoopPlugin loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class); - if (loopPlugin != null && loopPlugin.isEnabled(PluginType.LOOP)) { - loopPlugin.setPluginEnabled(PluginType.LOOP, false); - ConfigBuilderPlugin.getPlugin().storeSettings("SMS_LOOP_STOP"); - ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, new Callback() { - @Override - public void run() { - MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_STOP")); - String reply = MainApp.gs(R.string.smscommunicator_loophasbeendisabled) + " " + - MainApp.gs(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } - }); - } - receivedSms.processed = true; - FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Stop")); - break; - case "ENABLE": - case "START": - loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class); - if (loopPlugin != null && !loopPlugin.isEnabled(PluginType.LOOP)) { - loopPlugin.setPluginEnabled(PluginType.LOOP, true); - ConfigBuilderPlugin.getPlugin().storeSettings("SMS_LOOP_START"); - reply = MainApp.gs(R.string.smscommunicator_loophasbeenenabled); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_START")); - } - receivedSms.processed = true; - FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Start")); - break; - case "STATUS": - loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class); - if (loopPlugin != null) { - if (loopPlugin.isEnabled(PluginType.LOOP)) { - if (loopPlugin.isSuspended()) - reply = String.format(MainApp.gs(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend()); - else - reply = MainApp.gs(R.string.smscommunicator_loopisenabled); - } else { - reply = MainApp.gs(R.string.smscommunicator_loopisdisabled); - } - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } - receivedSms.processed = true; - FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Status")); - break; - case "RESUME": - LoopPlugin.getPlugin().suspendTo(0); - MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_RESUME")); - NSUpload.uploadOpenAPSOffline(0); - reply = MainApp.gs(R.string.smscommunicator_loopresumed); - sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Resume")); - break; - case "SUSPEND": - if (splited.length >= 3) - duration = SafeParse.stringToInt(splited[2]); - duration = Math.max(0, duration); - duration = Math.min(180, duration); - if (duration == 0) { - reply = MainApp.gs(R.string.smscommunicator_wrongduration); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } else if (remoteCommandsAllowed) { - passCode = generatePasscode(); - reply = String.format(MainApp.gs(R.string.smscommunicator_suspendreplywithcode), duration, passCode); - receivedSms.processed = true; - resetWaitingMessages(); - sendSMS(suspendWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis(), passCode)); - suspendWaitingForConfirmation.duration = duration; - FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Suspend")); - } else { - reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } - break; - } - break; - case "TREATMENTS": - if (splited.length > 1) - switch (splited[1].toUpperCase()) { - case "REFRESH": - Intent restartNSClient = new Intent(Intents.ACTION_RESTART); - TreatmentsPlugin.getPlugin().getService().resetTreatments(); - MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient); - List q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0); - reply = "TERATMENTS REFRESH " + q.size() + " receivers"; - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - receivedSms.processed = true; - FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Treatments_Refresh")); - break; - } - break; - case "NSCLIENT": - if (splited.length > 1) - switch (splited[1].toUpperCase()) { - case "RESTART": - Intent restartNSClient = new Intent(Intents.ACTION_RESTART); - MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient); - List q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0); - reply = "NSCLIENT RESTART " + q.size() + " receivers"; - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - receivedSms.processed = true; - FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Nsclient_Restart")); - break; - } - break; - case "PUMP": - case "DANAR": - ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("SMS", new Callback() { - @Override - public void run() { - PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); - if (result.success) { - if (pump != null) { - String reply = pump.shortStatus(true); - sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } - } else { - String reply = MainApp.gs(R.string.readstatusfailed); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } - } - }); - receivedSms.processed = true; - FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Pump")); - break; - case "BASAL": - if (splited.length > 1) { - if (splited[1].toUpperCase().equals("CANCEL") || splited[1].toUpperCase().equals("STOP")) { - if (remoteCommandsAllowed) { - passCode = generatePasscode(); - reply = String.format(MainApp.gs(R.string.smscommunicator_basalstopreplywithcode), passCode); - receivedSms.processed = true; - resetWaitingMessages(); - sendSMS(cancelTempBasalWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis(), passCode)); - FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Basal")); - } else { - reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } - } else { - tempBasal = SafeParse.stringToDouble(splited[1]); - Profile profile = ProfileFunctions.getInstance().getProfile(); - if (profile == null) { - reply = MainApp.gs(R.string.noprofile); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } else { - tempBasal = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(tempBasal), profile).value(); - if (remoteCommandsAllowed) { - passCode = generatePasscode(); - reply = String.format(MainApp.gs(R.string.smscommunicator_basalreplywithcode), tempBasal, passCode); - receivedSms.processed = true; - resetWaitingMessages(); - sendSMS(tempBasalWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis(), passCode)); - tempBasalWaitingForConfirmation.tempBasal = tempBasal; - FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Basal")); - } else { - reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } - } - } - } - break; - case "BOLUS": - if (System.currentTimeMillis() - lastRemoteBolusTime.getTime() < Constants.remoteBolusMinDistance) { - reply = MainApp.gs(R.string.smscommunicator_remotebolusnotallowed); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } else if (ConfigBuilderPlugin.getPlugin().getActivePump().isSuspended()) { - reply = MainApp.gs(R.string.pumpsuspended); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } else if (splited.length > 1) { - amount = SafeParse.stringToDouble(splited[1]); - amount = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount)).value(); - if (amount > 0d && remoteCommandsAllowed) { - passCode = generatePasscode(); - reply = String.format(MainApp.gs(R.string.smscommunicator_bolusreplywithcode), amount, passCode); - receivedSms.processed = true; - resetWaitingMessages(); - sendSMS(bolusWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis(), passCode)); - bolusWaitingForConfirmation.bolusRequested = amount; - FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Bolus")); - } else { - reply = MainApp.gs(R.string.smscommunicator_remotebolusnotallowed); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } - } - break; - case "CAL": - if (splited.length > 1) { - amount = SafeParse.stringToDouble(splited[1]); - if (amount > 0d && remoteCommandsAllowed) { - passCode = generatePasscode(); - reply = String.format(MainApp.gs(R.string.smscommunicator_calibrationreplywithcode), amount, passCode); - receivedSms.processed = true; - resetWaitingMessages(); - sendSMS(calibrationWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis(), passCode)); - calibrationWaitingForConfirmation.calibrationRequested = amount; - FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Cal")); - } else { - reply = MainApp.gs(R.string.smscommunicator_remotecalibrationnotallowed); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } - } - break; - default: // expect passCode here - if (bolusWaitingForConfirmation != null && !bolusWaitingForConfirmation.processed && - bolusWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - bolusWaitingForConfirmation.date < Constants.SMS_CONFIRM_TIMEOUT) { - bolusWaitingForConfirmation.processed = true; - DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); - detailedBolusInfo.insulin = bolusWaitingForConfirmation.bolusRequested; - detailedBolusInfo.source = Source.USER; - ConfigBuilderPlugin.getPlugin().getCommandQueue().bolus(detailedBolusInfo, new Callback() { - @Override - public void run() { - PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); - if (result.success) { - SystemClock.sleep(T.secs(15).msecs()); // wait some time to get history - String reply = String.format(MainApp.gs(R.string.smscommunicator_bolusdelivered), result.bolusDelivered); - if (pump != null) - reply += "\n" + pump.shortStatus(true); - lastRemoteBolusTime = new Date(); - sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } else { - SystemClock.sleep(T.secs(60).msecs()); // wait some time to get history - String reply = MainApp.gs(R.string.smscommunicator_bolusfailed); - if (pump != null) - reply += "\n" + pump.shortStatus(true); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } - } - }); - } else if (tempBasalWaitingForConfirmation != null && !tempBasalWaitingForConfirmation.processed && - tempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - tempBasalWaitingForConfirmation.date < Constants.SMS_CONFIRM_TIMEOUT) { - tempBasalWaitingForConfirmation.processed = true; - Profile profile = ProfileFunctions.getInstance().getProfile(); - if (profile != null) - ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalAbsolute(tempBasalWaitingForConfirmation.tempBasal, 30, true, profile, new Callback() { - @Override - public void run() { - if (result.success) { - String reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration); - reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); - sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } else { - String reply = MainApp.gs(R.string.smscommunicator_tempbasalfailed); - reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } - } - }); - } else if (cancelTempBasalWaitingForConfirmation != null && !cancelTempBasalWaitingForConfirmation.processed && - cancelTempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - cancelTempBasalWaitingForConfirmation.date < Constants.SMS_CONFIRM_TIMEOUT) { - cancelTempBasalWaitingForConfirmation.processed = true; - ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, new Callback() { - @Override - public void run() { - if (result.success) { - String reply = MainApp.gs(R.string.smscommunicator_tempbasalcanceled); - reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); - sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } else { - String reply = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed); - reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } - } - }); - } else if (calibrationWaitingForConfirmation != null && !calibrationWaitingForConfirmation.processed && - calibrationWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - calibrationWaitingForConfirmation.date < Constants.SMS_CONFIRM_TIMEOUT) { - calibrationWaitingForConfirmation.processed = true; - boolean result = XdripCalibrations.sendIntent(calibrationWaitingForConfirmation.calibrationRequested); - if (result) { - reply = MainApp.gs(R.string.smscommunicator_calibrationsent); - sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } else { - reply = MainApp.gs(R.string.smscommunicator_calibrationfailed); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } - } else if (suspendWaitingForConfirmation != null && !suspendWaitingForConfirmation.processed && - suspendWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - suspendWaitingForConfirmation.date < Constants.SMS_CONFIRM_TIMEOUT) { - suspendWaitingForConfirmation.processed = true; - ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, new Callback() { - @Override - public void run() { - if (result.success) { - LoopPlugin.getPlugin().suspendTo(System.currentTimeMillis() + suspendWaitingForConfirmation.duration * 60L * 1000); - NSUpload.uploadOpenAPSOffline(suspendWaitingForConfirmation.duration * 60); - MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_SUSPENDED")); - String reply = MainApp.gs(R.string.smscommunicator_loopsuspended) + " " + - MainApp.gs(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed); - sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } else { - String reply = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed); - reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); - sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis())); - } - } - }); - } else { - sendSMS(new Sms(receivedSms.phoneNumber, MainApp.gs(R.string.smscommunicator_unknowncommand), System.currentTimeMillis())); - } - resetWaitingMessages(); - break; - } - } - - MainApp.bus().post(new EventSmsCommunicatorUpdateGui()); - } - - public void sendNotificationToAllNumbers(String text) { - for (int i = 0; i < allowedNumbers.size(); i++) { - Sms sms = new Sms(allowedNumbers.get(i), text, System.currentTimeMillis()); - sendSMS(sms); - } - } - - private void sendSMSToAllNumbers(Sms sms) { - for (String number : allowedNumbers) { - sms.phoneNumber = number; - sendSMS(sms); - } - } - - private void sendSMS(Sms sms) { - SmsManager smsManager = SmsManager.getDefault(); - sms.text = stripAccents(sms.text); - if (sms.text.length() > 140) sms.text = sms.text.substring(0, 139); - try { - log.debug("Sending SMS to " + sms.phoneNumber + ": " + sms.text); - smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null); - messages.add(sms); - } catch (IllegalArgumentException e) { - Notification notification = new Notification(Notification.INVALID_PHONE_NUMBER, MainApp.gs(R.string.smscommunicator_invalidphonennumber), Notification.NORMAL); - MainApp.bus().post(new EventNewNotification(notification)); - } catch (java.lang.SecurityException e) { - Notification notification = new Notification(Notification.MISSING_SMS_PERMISSION, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.NORMAL); - MainApp.bus().post(new EventNewNotification(notification)); - } - } - - private String generatePasscode() { - int startChar1 = 'A'; // on iphone 1st char is uppercase :) - String passCode = Character.toString((char) (startChar1 + Math.random() * ('z' - 'a' + 1))); - int startChar2 = Math.random() > 0.5 ? 'a' : 'A'; - passCode += Character.toString((char) (startChar2 + Math.random() * ('z' - 'a' + 1))); - int startChar3 = Math.random() > 0.5 ? 'a' : 'A'; - passCode += Character.toString((char) (startChar3 + Math.random() * ('z' - 'a' + 1))); - return passCode; - } - - private void resetWaitingMessages() { - tempBasalWaitingForConfirmation = null; - cancelTempBasalWaitingForConfirmation = null; - bolusWaitingForConfirmation = null; - calibrationWaitingForConfirmation = null; - suspendWaitingForConfirmation = null; - } - - private static String stripAccents(String s) { - s = Normalizer.normalize(s, Normalizer.Form.NFD); - s = s.replaceAll("[\\p{InCombiningDiacriticalMarks}]", ""); - return s; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java deleted file mode 100644 index 460e550b8e..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java +++ /dev/null @@ -1,95 +0,0 @@ -package info.nightscout.androidaps.plugins.Source; - -import android.content.Intent; -import android.os.Bundle; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.db.BgReading; -import info.nightscout.androidaps.interfaces.BgSourceInterface; -import info.nightscout.androidaps.interfaces.PluginBase; -import info.nightscout.androidaps.interfaces.PluginDescription; -import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.SP; - -/** - * Created by mike on 28.11.2017. - */ - -public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterface { - private static Logger log = LoggerFactory.getLogger(L.BGSOURCE); - - private static SourceDexcomG5Plugin plugin = null; - - public static SourceDexcomG5Plugin getPlugin() { - if (plugin == null) - plugin = new SourceDexcomG5Plugin(); - return plugin; - } - - private SourceDexcomG5Plugin() { - super(new PluginDescription() - .mainType(PluginType.BGSOURCE) - .fragmentClass(BGSourceFragment.class.getName()) - .pluginName(R.string.DexcomG5) - .shortName(R.string.dexcomG5_shortname) - .preferencesId(R.xml.pref_dexcomg5) - .description(R.string.description_source_dexcom_g5) - ); - } - - @Override - public boolean advancedFilteringSupported() { - return true; - } - - @Override - public void handleNewData(Intent intent) { - // onHandleIntent Bundle{ data => [{"m_time":1511939180,"m_trend":"NotComputable","m_value":335}]; android.support.content.wakelockid => 95; }Bundle - - if (!isEnabled(PluginType.BGSOURCE)) return; - - Bundle bundle = intent.getExtras(); - if (bundle == null) return; - - BgReading bgReading = new BgReading(); - - String data = bundle.getString("data"); - if (L.isEnabled(L.BGSOURCE)) - log.debug("Received Dexcom Data", data); - - if (data == null) return; - - try { - JSONArray jsonArray = new JSONArray(data); - if (L.isEnabled(L.BGSOURCE)) - log.debug("Received Dexcom Data size:" + jsonArray.length()); - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject json = jsonArray.getJSONObject(i); - bgReading.value = json.getInt("m_value"); - bgReading.direction = json.getString("m_trend"); - bgReading.date = json.getLong("m_time") * 1000L; - bgReading.raw = 0; - boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5"); - if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { - NSUpload.uploadBg(bgReading); - } - if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { - NSUpload.sendToXdrip(bgReading); - } - } - - } catch (JSONException e) { - log.error("Exception: ", e); - } - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/SendToDataLayerThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/SendToDataLayerThread.java deleted file mode 100644 index 02c74defca..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/SendToDataLayerThread.java +++ /dev/null @@ -1,52 +0,0 @@ -package info.nightscout.androidaps.plugins.Wear.wearintegration; - -import android.os.AsyncTask; -import android.util.Log; - -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.wearable.DataApi; -import com.google.android.gms.wearable.DataMap; -import com.google.android.gms.wearable.Node; -import com.google.android.gms.wearable.NodeApi; -import com.google.android.gms.wearable.PutDataMapRequest; -import com.google.android.gms.wearable.PutDataRequest; -import com.google.android.gms.wearable.Wearable; - -import java.util.concurrent.TimeUnit; - -/** - * Created by emmablack on 12/26/14. - */ -class SendToDataLayerThread extends AsyncTask { - private GoogleApiClient googleApiClient; - private static final String TAG = "SendDataThread"; - String path; - - SendToDataLayerThread(String path, GoogleApiClient pGoogleApiClient) { - this.path = path; - googleApiClient = pGoogleApiClient; - } - - @Override - protected Void doInBackground(DataMap... params) { - try { - final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(15, TimeUnit.SECONDS); - for (Node node : nodes.getNodes()) { - for (DataMap dataMap : params) { - PutDataMapRequest putDMR = PutDataMapRequest.create(path); - putDMR.getDataMap().putAll(dataMap); - PutDataRequest request = putDMR.asPutDataRequest(); - DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient, request).await(15, TimeUnit.SECONDS); - if (result.getStatus().isSuccess()) { - Log.d(TAG, "DataMap: " + dataMap + " sent to: " + node.getDisplayName()); - } else { - Log.d(TAG, "ERROR: failed to send DataMap"); - } - } - } - } catch (Exception e) { - Log.e(TAG, "Got exception sending data to wear: " + e.toString()); - } - return null; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/APSResult.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/APSResult.java index 5135c6b87b..b3b0c091d5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/APSResult.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Loop; +package info.nightscout.androidaps.plugins.aps.loop; import android.text.Html; import android.text.Spanned; @@ -22,11 +22,11 @@ import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 09.06.2016. @@ -307,6 +307,11 @@ public class APSResult { PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); Profile profile = ProfileFunctions.getInstance().getProfile(); + if (profile == null) { + log.error("FALSE: No Profile"); + return false; + } + if (usePercent) { if (activeTemp == null && percent == 100) { if (L.isEnabled(L.APS)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java similarity index 99% rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java index 2c2bb1a2ee..69afe3d8e7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Loop; +package info.nightscout.androidaps.plugins.aps.loop; import org.json.JSONException; import org.json.JSONObject; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.java index 0c0e31fb03..0b11dd0ac3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Loop; +package info.nightscout.androidaps.plugins.aps.loop; import android.app.Activity; @@ -13,19 +13,16 @@ import android.widget.TextView; import com.crashlytics.android.answers.CustomEvent; import com.squareup.otto.Subscribe; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.Constraint; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui; -import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui; -import info.nightscout.utils.FabricPrivacy; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui; +import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui; +import info.nightscout.androidaps.utils.FabricPrivacy; public class LoopFragment extends SubscriberFragment { @BindView(R.id.loop_run) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java index ac5076be72..91bbccc515 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Loop; +package info.nightscout.androidaps.plugins.aps.loop; import android.annotation.SuppressLint; import android.app.Notification; @@ -34,6 +34,7 @@ import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.events.EventNewBG; +import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PluginBase; @@ -43,24 +44,24 @@ import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; -import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui; -import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui; -import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.androidaps.plugins.Wear.ActionStringHandler; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; +import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui; +import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui; +import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler; import info.nightscout.androidaps.events.EventAcceptOpenLoopChange; import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.commands.Command; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.SP; -import info.nightscout.utils.T; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.T; +import info.nightscout.androidaps.utils.ToastUtils; /** * Created by mike on 05.08.2016. @@ -175,6 +176,14 @@ public class LoopPlugin extends PluginBase { return loopSuspendedTill; } + @Subscribe + public void onStatusEvent(final EventTempTargetChange ev) { + new Thread(() -> invoke("EventTempTargetChange", true)).start(); + FabricPrivacy.getInstance().logCustom(new CustomEvent("TT_Loop_Run")); + } + + + public void suspendTo(long endTime) { loopSuspendedTill = endTime; isSuperBolus = false; @@ -409,8 +418,10 @@ public class LoopPlugin extends PluginBase { .setAutoCancel(true) .setPriority(Notification.PRIORITY_HIGH) .setCategory(Notification.CATEGORY_ALARM) - .setVisibility(Notification.VISIBILITY_PUBLIC) - .setLocalOnly(true); + .setVisibility(Notification.VISIBILITY_PUBLIC); + if (SP.getBoolean("wearcontrol", false)) { + builder.setLocalOnly(true); + } // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(MainApp.instance().getApplicationContext(), MainActivity.class); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/ScriptReader.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/ScriptReader.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/ScriptReader.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/ScriptReader.java index 988d08fb84..e3a64dbece 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/ScriptReader.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/ScriptReader.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Loop; +package info.nightscout.androidaps.plugins.aps.loop; import android.content.Context; import android.content.res.AssetManager; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopSetLastRunGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopSetLastRunGui.java similarity index 82% rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopSetLastRunGui.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopSetLastRunGui.java index 1ef5dc4c94..0d2a45f528 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopSetLastRunGui.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopSetLastRunGui.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Loop.events; +package info.nightscout.androidaps.plugins.aps.loop.events; import info.nightscout.androidaps.events.EventUpdateGui; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopUpdateGui.java similarity index 72% rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopUpdateGui.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopUpdateGui.java index d4417dbb12..f746dfb0a0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopUpdateGui.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopUpdateGui.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Loop.events; +package info.nightscout.androidaps.plugins.aps.loop.events; import info.nightscout.androidaps.events.EventUpdateGui; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventNewOpenLoopNotification.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventNewOpenLoopNotification.java similarity index 71% rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventNewOpenLoopNotification.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventNewOpenLoopNotification.java index 001d11661e..6a0a4dc0cf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventNewOpenLoopNotification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventNewOpenLoopNotification.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Loop.events; +package info.nightscout.androidaps.plugins.aps.loop.events; import info.nightscout.androidaps.events.Event; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalAdapterAMAJS.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalAdapterAMAJS.java index 50e79d1e37..7eb9a2d81d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalAdapterAMAJS.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.OpenAPSAMA; +package info.nightscout.androidaps.plugins.aps.openAPSAMA; import org.json.JSONArray; import org.json.JSONException; @@ -26,12 +26,12 @@ import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.Loop.ScriptReader; -import info.nightscout.androidaps.plugins.OpenAPSMA.LoggerCallback; -import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.aps.loop.ScriptReader; +import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback; +import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.SP; public class DetermineBasalAdapterAMAJS { private static Logger log = LoggerFactory.getLogger(L.APS); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalResultAMA.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalResultAMA.java index 77c8d8a860..46f1057e27 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalResultAMA.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.OpenAPSAMA; +package info.nightscout.androidaps.plugins.aps.openAPSAMA; import org.json.JSONException; import org.json.JSONObject; @@ -7,8 +7,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Loop.APSResult; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.aps.loop.APSResult; +import info.nightscout.androidaps.utils.DateUtil; public class DetermineBasalResultAMA extends APSResult { private static Logger log = LoggerFactory.getLogger(L.APS); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.java index 1874816ddc..f73a66bbfe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.OpenAPSAMA; +package info.nightscout.androidaps.plugins.aps.openAPSAMA; import android.app.Activity; import android.os.Bundle; @@ -19,12 +19,12 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; -import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.JSONFormatter; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui; +import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.JSONFormatter; public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnClickListener { private static Logger log = LoggerFactory.getLogger(L.APS); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java index 3bf1301416..3447c7c4f4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.OpenAPSAMA; +package info.nightscout.androidaps.plugins.aps.openAPSAMA; import org.json.JSONException; import org.slf4j.Logger; @@ -11,27 +11,26 @@ import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.TempTarget; -import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.Loop.APSResult; -import info.nightscout.androidaps.plugins.Loop.ScriptReader; -import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; -import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.HardLimits; -import info.nightscout.utils.Profiler; -import info.nightscout.utils.Round; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.aps.loop.APSResult; +import info.nightscout.androidaps.plugins.aps.loop.ScriptReader; +import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui; +import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.HardLimits; +import info.nightscout.androidaps.utils.Profiler; +import info.nightscout.androidaps.utils.Round; /** * Created by mike on 05.08.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalAdapterMAJS.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalAdapterMAJS.java index 1574665dc4..4baabf22ab 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalAdapterMAJS.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.OpenAPSMA; +package info.nightscout.androidaps.plugins.aps.openAPSMA; import org.json.JSONException; import org.json.JSONObject; @@ -23,9 +23,9 @@ import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Loop.ScriptReader; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.aps.loop.ScriptReader; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.SP; public class DetermineBasalAdapterMAJS { private static Logger log = LoggerFactory.getLogger(L.APS); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalResultMA.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalResultMA.java index d3e1869f87..bbbcf7f893 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalResultMA.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.OpenAPSMA; +package info.nightscout.androidaps.plugins.aps.openAPSMA; import org.json.JSONException; import org.json.JSONObject; @@ -7,7 +7,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Loop.APSResult; +import info.nightscout.androidaps.plugins.aps.loop.APSResult; public class DetermineBasalResultMA extends APSResult { private static Logger log = LoggerFactory.getLogger(L.APS); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/LoggerCallback.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/LoggerCallback.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/LoggerCallback.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/LoggerCallback.java index 8907166951..30ce388f5d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/LoggerCallback.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/LoggerCallback.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.OpenAPSMA; +package info.nightscout.androidaps.plugins.aps.openAPSMA; import org.mozilla.javascript.ScriptableObject; import org.slf4j.Logger; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAFragment.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAFragment.java index 12d7988a16..257a4abcb2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.OpenAPSMA; +package info.nightscout.androidaps.plugins.aps.openAPSMA; import android.app.Activity; import android.os.Bundle; @@ -12,12 +12,12 @@ import com.crashlytics.android.answers.CustomEvent; import com.squareup.otto.Subscribe; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; -import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.JSONFormatter; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui; +import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.JSONFormatter; public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClickListener { Button run; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAPlugin.java similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAPlugin.java index 5b59252ea1..24b4cb7929 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.OpenAPSMA; +package info.nightscout.androidaps.plugins.aps.openAPSMA; import org.json.JSONException; import org.slf4j.Logger; @@ -11,27 +11,26 @@ import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.TempTarget; -import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.Loop.APSResult; -import info.nightscout.androidaps.plugins.Loop.ScriptReader; -import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; -import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.HardLimits; -import info.nightscout.utils.Profiler; -import info.nightscout.utils.Round; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.aps.loop.APSResult; +import info.nightscout.androidaps.plugins.aps.loop.ScriptReader; +import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui; +import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.HardLimits; +import info.nightscout.androidaps.utils.Profiler; +import info.nightscout.androidaps.utils.Round; -import static info.nightscout.utils.HardLimits.checkOnlyHardLimits; -import static info.nightscout.utils.HardLimits.verifyHardLimits; +import static info.nightscout.androidaps.utils.HardLimits.checkOnlyHardLimits; +import static info.nightscout.androidaps.utils.HardLimits.verifyHardLimits; /** * Created by mike on 05.08.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/events/EventOpenAPSUpdateGui.java similarity index 71% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateGui.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/events/EventOpenAPSUpdateGui.java index 40f3c31973..de4292025d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateGui.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/events/EventOpenAPSUpdateGui.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.OpenAPSMA.events; +package info.nightscout.androidaps.plugins.aps.openAPSMA.events; import info.nightscout.androidaps.events.EventUpdateGui; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateResultGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/events/EventOpenAPSUpdateResultGui.java similarity index 81% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateResultGui.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/events/EventOpenAPSUpdateResultGui.java index 177133f155..fb5ea7e78f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateResultGui.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/events/EventOpenAPSUpdateResultGui.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.OpenAPSMA.events; +package info.nightscout.androidaps.plugins.aps.openAPSMA.events; import info.nightscout.androidaps.events.EventUpdateGui; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java index f974ff472e..bfff43f9d1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.OpenAPSSMB; +package info.nightscout.androidaps.plugins.aps.openAPSSMB; import org.json.JSONArray; import org.json.JSONException; @@ -26,12 +26,12 @@ import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.Loop.ScriptReader; -import info.nightscout.androidaps.plugins.OpenAPSMA.LoggerCallback; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.SP; -import info.nightscout.utils.SafeParse; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.aps.loop.ScriptReader; +import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.SafeParse; public class DetermineBasalAdapterSMBJS { private static Logger log = LoggerFactory.getLogger(L.APS); @@ -211,6 +211,7 @@ public class DetermineBasalAdapterSMBJS { double autosensDataRatio, boolean tempTargetSet, boolean microBolusAllowed, + boolean uamAllowed, boolean advancedFiltering ) throws JSONException { @@ -247,14 +248,16 @@ public class DetermineBasalAdapterSMBJS { // mProfile.put("min_5m_carbimpact", SP.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact)); //} mProfile.put("remainingCarbsCap", SMBDefaults.remainingCarbsCap); - mProfile.put("enableUAM", SP.getBoolean(R.string.key_use_uam, false)); + mProfile.put("enableUAM", uamAllowed); mProfile.put("A52_risk_enable", SMBDefaults.A52_risk_enable); - mProfile.put("enableSMB_with_COB", SP.getBoolean(R.string.key_enableSMB_with_COB, false)); - mProfile.put("enableSMB_with_temptarget", SP.getBoolean(R.string.key_enableSMB_with_temptarget, false)); - mProfile.put("allowSMB_with_high_temptarget", SP.getBoolean(R.string.key_allowSMB_with_high_temptarget, false)); - mProfile.put("enableSMB_always", SP.getBoolean(R.string.key_enableSMB_always, false) && advancedFiltering); - mProfile.put("enableSMB_after_carbs", SP.getBoolean(R.string.key_enableSMB_after_carbs, false) && advancedFiltering); - mProfile.put("maxSMBBasalMinutes", SP.getInt("key_smbmaxminutes", SMBDefaults.maxSMBBasalMinutes)); + + boolean smbEnabled = SP.getBoolean(MainApp.gs(R.string.key_use_smb), false); + mProfile.put("enableSMB_with_COB", smbEnabled && SP.getBoolean(R.string.key_enableSMB_with_COB, false)); + mProfile.put("enableSMB_with_temptarget", smbEnabled && SP.getBoolean(R.string.key_enableSMB_with_temptarget, false)); + mProfile.put("allowSMB_with_high_temptarget", smbEnabled && SP.getBoolean(R.string.key_allowSMB_with_high_temptarget, false)); + mProfile.put("enableSMB_always", smbEnabled && SP.getBoolean(R.string.key_enableSMB_always, false) && advancedFiltering); + mProfile.put("enableSMB_after_carbs", smbEnabled && SP.getBoolean(R.string.key_enableSMB_after_carbs, false) && advancedFiltering); + mProfile.put("maxSMBBasalMinutes", SP.getInt(R.string.key_smbmaxminutes, SMBDefaults.maxSMBBasalMinutes)); mProfile.put("carbsReqThreshold", SMBDefaults.carbsReqThreshold); mProfile.put("current_basal", basalrate); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalResultSMB.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalResultSMB.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalResultSMB.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalResultSMB.java index 364731bea5..9d0bd22557 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalResultSMB.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalResultSMB.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.OpenAPSSMB; +package info.nightscout.androidaps.plugins.aps.openAPSSMB; import org.json.JSONException; import org.json.JSONObject; @@ -6,8 +6,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Loop.APSResult; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.aps.loop.APSResult; +import info.nightscout.androidaps.utils.DateUtil; public class DetermineBasalResultSMB extends APSResult { private static final Logger log = LoggerFactory.getLogger(L.APS); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.java index d27f8b31d0..87572e2ad6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.OpenAPSSMB; +package info.nightscout.androidaps.plugins.aps.openAPSSMB; import android.app.Activity; import android.os.Bundle; @@ -22,12 +22,12 @@ import butterknife.OnClick; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; -import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.JSONFormatter; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui; +import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.JSONFormatter; public class OpenAPSSMBFragment extends SubscriberFragment { private static Logger log = LoggerFactory.getLogger(L.APS); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java similarity index 86% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java index d42ca9e89f..73914662d7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java @@ -1,11 +1,9 @@ -package info.nightscout.androidaps.plugins.OpenAPSSMB; +package info.nightscout.androidaps.plugins.aps.openAPSSMB; import org.json.JSONException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Date; - import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.GlucoseStatus; @@ -13,35 +11,35 @@ import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.TempTarget; -import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.Constraint; +import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.Loop.APSResult; -import info.nightscout.androidaps.plugins.Loop.ScriptReader; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; -import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.HardLimits; -import info.nightscout.utils.Profiler; -import info.nightscout.utils.Round; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.aps.loop.APSResult; +import info.nightscout.androidaps.plugins.aps.loop.ScriptReader; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui; +import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.HardLimits; +import info.nightscout.androidaps.utils.Profiler; +import info.nightscout.androidaps.utils.Round; +import info.nightscout.androidaps.utils.ToastUtils; /** * Created by mike on 05.08.2016. */ -public class OpenAPSSMBPlugin extends PluginBase implements APSInterface { +public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, ConstraintsInterface { private static Logger log = LoggerFactory.getLogger(L.APS); private static OpenAPSSMBPlugin openAPSSMBPlugin; @@ -150,7 +148,9 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface { if (L.isEnabled(L.APS)) Profiler.log(log, "getMealData()", startPart); - double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value(); + Constraint maxIOBAllowedConstraint = MainApp.getConstraintChecker().getMaxIOBAllowed(); + inputConstraints.copyReasons(maxIOBAllowedConstraint); + double maxIob = maxIOBAllowedConstraint.value(); minBg = verifyHardLimits(minBg, "minBg", HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]); maxBg = verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]); @@ -198,6 +198,10 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface { MainApp.getConstraintChecker().isAdvancedFilteringEnabled(advancedFiltering); inputConstraints.copyReasons(advancedFiltering); + Constraint uam = new Constraint<>(true); + MainApp.getConstraintChecker().isUAMEnabled(uam); + inputConstraints.copyReasons(uam); + if (L.isEnabled(L.APS)) Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart); if (L.isEnabled(L.APS)) @@ -209,6 +213,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface { lastAutosensResult.ratio, //autosensDataRatio isTempTarget, smbAllowed.value(), + uam.value(), advancedFiltering.value() ); } catch (JSONException e) { @@ -264,4 +269,9 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface { return newvalue; } + public Constraint isSuperBolusEnabled(Constraint value) { + value.set(false); + return value; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/SMBDefaults.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/SMBDefaults.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/SMBDefaults.java rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/SMBDefaults.java index 0ce8d2bb94..f6b8f20233 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/SMBDefaults.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/SMBDefaults.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.OpenAPSSMB; +package info.nightscout.androidaps.plugins.aps.openAPSSMB; /** * Created by mike on 10.12.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Common/SubscriberFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/common/SubscriberFragment.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/Common/SubscriberFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/common/SubscriberFragment.java index fabd83f0ea..3ac877b42d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Common/SubscriberFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/common/SubscriberFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Common; +package info.nightscout.androidaps.plugins.common; import android.support.v4.app.Fragment; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.java index 3df78c9a28..b374c78413 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ConfigBuilder; +package info.nightscout.androidaps.plugins.configBuilder; import android.content.Intent; @@ -39,13 +39,14 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.SensitivityInterface; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.Insulin.InsulinOrefRapidActingPlugin; -import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; -import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityOref0Plugin; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.PasswordProtection; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin; +import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin; + +import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.PasswordProtection; public class ConfigBuilderFragment extends SubscriberFragment { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.java index 588ba2ac93..3c3531da86 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ConfigBuilder; +package info.nightscout.androidaps.plugins.configBuilder; import android.support.annotation.Nullable; @@ -20,11 +20,11 @@ import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.SensitivityInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Insulin.InsulinOrefRapidActingPlugin; -import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityOref0Plugin; +import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin; +import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin; import info.nightscout.androidaps.queue.CommandQueue; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 05.08.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/DetailedBolusInfoStorage.java b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/DetailedBolusInfoStorage.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/DetailedBolusInfoStorage.java rename to app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/DetailedBolusInfoStorage.java index 9b4e1d0a28..b19948fc5e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/DetailedBolusInfoStorage.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/DetailedBolusInfoStorage.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ConfigBuilder; +package info.nightscout.androidaps.plugins.configBuilder; import android.support.annotation.Nullable; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ProfileFunctions.java b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctions.java similarity index 65% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ProfileFunctions.java rename to app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctions.java index 312c0cd9ae..6b9b353979 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ProfileFunctions.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctions.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ConfigBuilder; +package info.nightscout.androidaps.plugins.configBuilder; import android.content.Intent; import android.support.annotation.Nullable; @@ -16,15 +16,16 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.db.ProfileSwitch; +import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.events.EventProfileSwitchChange; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.FabricPrivacy; public class ProfileFunctions { private static Logger log = LoggerFactory.getLogger(L.PROFILE); @@ -139,4 +140,44 @@ public class ProfileFunctions { return null; } + public static ProfileSwitch prepareProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift, long date) { + ProfileSwitch profileSwitch = new ProfileSwitch(); + profileSwitch.date = date; + profileSwitch.source = Source.USER; + profileSwitch.profileName = profileName; + profileSwitch.profileJson = profileStore.getSpecificProfile(profileName).getData().toString(); + profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName(); + profileSwitch.durationInMinutes = duration; + profileSwitch.isCPP = percentage != 100 || timeshift != 0; + profileSwitch.timeshift = timeshift; + profileSwitch.percentage = percentage; + return profileSwitch; + } + + public static void doProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift) { + ProfileSwitch profileSwitch = prepareProfileSwitch(profileStore, profileName, duration, percentage, timeshift, System.currentTimeMillis()); + TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch); + FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch")); + } + + public static void doProfileSwitch(final int duration, final int percentage, final int timeshift) { + ProfileSwitch profileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(System.currentTimeMillis()); + if (profileSwitch != null) { + profileSwitch = new ProfileSwitch(); + profileSwitch.date = System.currentTimeMillis(); + profileSwitch.source = Source.USER; + profileSwitch.profileName = getInstance().getProfileName(System.currentTimeMillis(), false); + profileSwitch.profileJson = getInstance().getProfile().getData().toString(); + profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName(); + profileSwitch.durationInMinutes = duration; + profileSwitch.isCPP = percentage != 100 || timeshift != 0; + profileSwitch.timeshift = timeshift; + profileSwitch.percentage = percentage; + TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch); + FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch")); + } else { + log.error("No profile switch existing"); + } + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPlugin.java new file mode 100644 index 0000000000..2862cc3d7a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPlugin.java @@ -0,0 +1,125 @@ +package info.nightscout.androidaps.plugins.constraints.dstHelper; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Calendar; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.interfaces.Constraint; +import info.nightscout.androidaps.interfaces.ConstraintsInterface; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginDescription; +import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.utils.T; + +/** + * Created by Rumen on 31.10.2018. + */ +public class DstHelperPlugin extends PluginBase implements ConstraintsInterface { + private static Logger log = LoggerFactory.getLogger(L.CONSTRAINTS); + private int minutesToChange = 0; + + static DstHelperPlugin plugin = null; + + public static DstHelperPlugin getPlugin() { + if (plugin == null) + plugin = new DstHelperPlugin(); + return plugin; + } + + public DstHelperPlugin() { + super(new PluginDescription() + .mainType(PluginType.CONSTRAINTS) + .neverVisible(true) + .alwaysEnabled(true) + .showInList(false) + .pluginName(R.string.dst_plugin_name) + ); + } + + public int dstTest(Calendar c) throws Exception { +// c = Calendar.getInstance(TimeZone.getDefault()); +// c = Calendar.getInstance(TimeZone.getTimeZone("Australia/Lord_Howe")); +// c.setTimeInMillis(DateUtil.fromISODateString("2018-10-07T01:00:00Z").getTime()); + long zoneOffset = c.get(Calendar.ZONE_OFFSET); + long d1 = c.getTimeInMillis() - zoneOffset; + c.setTimeInMillis(d1); + int offset1 = c.get(Calendar.DST_OFFSET); + + c.add(Calendar.DATE, 1); + long d2 = c.getTimeInMillis(); + + int diffInHours = (int) ((d1 - d2) / -T.hours(1).msecs()); + long offsetDetectedTime = 0; + // comparing millis because change can be < 1 hour +// log.debug("Starting from: "+startTimeString + " to "+endTimeString); +// log.debug("start "+offset1+" end "+c.get(Calendar.DST_OFFSET)); + if (offset1 != c.get(Calendar.DST_OFFSET)) { + //we have a time change in next 24 hours, but when exactly +// log.debug("Daylight saving time detected between " + startTimeString + " and " + endTimeString); +// log.debug("Diff in hours is: "+diffInHours); + c.setTimeInMillis(d1 - zoneOffset); + offset1 = c.get(Calendar.DST_OFFSET); + for (int i = 0; i <= diffInHours * 4; i++) { + + if (offset1 != c.get(Calendar.DST_OFFSET)) { + log.debug("Detected offset in " + ((i / 4) - zoneOffset / T.hours(1).msecs()) + " hours value is " + (offset1 - c.get(Calendar.DST_OFFSET)) / T.mins(1).msecs() + " minutes"); + offsetDetectedTime = c.getTimeInMillis() - d1; + break; + } + c.add(Calendar.MINUTE, 15); + + } + } + int minutesLeft = (int) ((offsetDetectedTime / T.mins(1).msecs())); + /*log.debug("zoneoffset(minutes):"+zoneOffset/T.mins(1).msecs()); + log.debug("Start offset: "+offset1/T.mins(1).msecs()); + log.debug("End offset :" + c.get(Calendar.DST_OFFSET)/T.mins(1).msecs()); + log.debug("Now is:"+startTimeString); + log.debug("Detected in(min): "+(offsetDetectedTime/T.mins(1).msecs())); + log.debug("Returning value of: " + minutesLeft); */ + minutesToChange = minutesLeft; + return minutesLeft; + + } + + //Return false if time to DST change is less than 91 and positive + @Override + public Constraint isLoopInvocationAllowed(Constraint value) { + try { + this.dstTest(Calendar.getInstance()); + } catch (Exception e) { + e.printStackTrace(); + } + if (this.minutesToChange <= 90 && minutesToChange > 0 && value.value()) { + try { + LoopPlugin loopPlugin = LoopPlugin.getPlugin(); + if (loopPlugin.suspendedTo() == 0L) { +// loopPlugin.suspendTo(System.currentTimeMillis() + minutesToChange * T.mins(1).msecs()); + warnUser(Notification.DST_LOOP_DISABLED, MainApp.gs(R.string.dst_loop_disabled_warning)); + } else + log.debug("Loop already suspended"); + + } catch (Exception e) { + e.printStackTrace(); + } + value.set(false, "DST in 90 minutes or less", this); + } else if (minutesToChange <= 24 * T.hours(1).mins() && minutesToChange > 0) { + warnUser(Notification.DST_IN_24H, MainApp.gs(R.string.dst_in_24h_warning)); + } + return value; + } + + // display warning + void warnUser(int id, String warningText) { + Notification notification = new Notification(id, warningText, Notification.LOW); + MainApp.bus().post(new EventNewNotification(notification)); + } + +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.java index 3dcec0920f..b943571089 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ConstraintsObjectives; +package info.nightscout.androidaps.plugins.constraints.objectives; import android.app.Activity; import android.os.Bundle; @@ -22,9 +22,9 @@ import java.util.Date; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective; -import info.nightscout.utils.FabricPrivacy; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective; +import info.nightscout.androidaps.utils.FabricPrivacy; public class ObjectivesFragment extends SubscriberFragment { RecyclerView recyclerView; @@ -120,6 +120,7 @@ public class ObjectivesFragment extends SubscriberFragment { public void onBindViewHolder(@NonNull ViewHolder holder, int position) { Objective objective = ObjectivesPlugin.getPlugin().getObjectives().get(position); holder.title.setText(MainApp.gs(R.string.nth_objective, position + 1)); + holder.revert.setVisibility(View.INVISIBLE); if (objective.getObjective() != 0) { holder.objective.setVisibility(View.VISIBLE); holder.objective.setText(MainApp.gs(objective.getObjective())); @@ -145,6 +146,9 @@ public class ObjectivesFragment extends SubscriberFragment { holder.verify.setVisibility(View.VISIBLE); holder.verify.setEnabled(objective.isCompleted() || enableFake.isChecked()); holder.start.setVisibility(View.GONE); + if(objective.isRevertable()) { + holder.revert.setVisibility(View.VISIBLE); + } holder.progress.setVisibility(View.VISIBLE); holder.progress.removeAllViews(); for (Objective.Task task : objective.getTasks()) { @@ -169,8 +173,20 @@ public class ObjectivesFragment extends SubscriberFragment { scrollToCurrentObjective(); startUpdateTimer(); }); + holder.revert.setOnClickListener((view) -> { + objective.setAccomplishedOn(null); + objective.setStartedOn(null); + if (position > 0) { + Objective prevObj = ObjectivesPlugin.getPlugin().getObjectives().get(position - 1); + prevObj.setAccomplishedOn(null); + } + notifyDataSetChanged(); + scrollToCurrentObjective(); + }); } + + @Override public int getItemCount() { return ObjectivesPlugin.getPlugin().getObjectives().size(); @@ -185,6 +201,7 @@ public class ObjectivesFragment extends SubscriberFragment { public LinearLayout progress; public Button verify; public Button start; + public Button revert; public ViewHolder(View itemView) { super(itemView); @@ -195,6 +212,7 @@ public class ObjectivesFragment extends SubscriberFragment { progress = itemView.findViewById(R.id.objective_progress); verify = itemView.findViewById(R.id.objective_verify); start = itemView.findViewById(R.id.objective_start); + revert = itemView.findViewById(R.id.objective_back); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java similarity index 83% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java index cc50189346..1d18cd14b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ConstraintsObjectives; +package info.nightscout.androidaps.plugins.constraints.objectives; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,18 +16,18 @@ import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.events.EventObjectivesSaved; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective1; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective2; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective3; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective4; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective5; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective6; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective7; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective8; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesSaved; +import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective; +import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective1; +import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective2; +import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective3; +import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective4; +import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective5; +import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective6; +import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective7; +import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective8; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 05.08.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/events/EventObjectivesSaved.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/events/EventObjectivesSaved.java similarity index 57% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/events/EventObjectivesSaved.java rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/events/EventObjectivesSaved.java index 1822368cf9..d4dbb0251d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/events/EventObjectivesSaved.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/events/EventObjectivesSaved.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ConstraintsObjectives.events; +package info.nightscout.androidaps.plugins.constraints.objectives.events; import info.nightscout.androidaps.events.Event; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective.java rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java index 5127f64b34..83abe15688 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives; +package info.nightscout.androidaps.plugins.constraints.objectives.objectives; import android.support.annotation.StringRes; @@ -8,8 +8,8 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.utils.SP; -import info.nightscout.utils.T; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.T; public abstract class Objective { @@ -42,6 +42,10 @@ public abstract class Objective { return true; } + public boolean isRevertable() { + return false; + } + public boolean isAccomplished() { return accomplishedOn != null; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective1.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective1.java similarity index 82% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective1.java rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective1.java index 39127c4d45..65a716abab 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective1.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective1.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives; +package info.nightscout.androidaps.plugins.constraints.objectives.objectives; import java.util.List; @@ -7,14 +7,14 @@ import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; -import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin; +import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; public class Objective1 extends Objective { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective2.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java similarity index 83% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective2.java rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java index ac5485f953..6f97bfdd95 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives; +package info.nightscout.androidaps.plugins.constraints.objectives.objectives; import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; -import info.nightscout.utils.T; +import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin; +import info.nightscout.androidaps.utils.T; public class Objective2 extends Objective { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective3.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective3.java similarity index 71% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective3.java rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective3.java index 8a84e3c83c..4924d9434c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective3.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective3.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives; +package info.nightscout.androidaps.plugins.constraints.objectives.objectives; import info.nightscout.androidaps.R; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective4.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective4.java similarity index 73% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective4.java rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective4.java index 4cac10e514..1bbb4ef7c2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective4.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective4.java @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives; +package info.nightscout.androidaps.plugins.constraints.objectives.objectives; import java.util.List; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.Constraint; -import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin; -import info.nightscout.utils.T; +import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin; +import info.nightscout.androidaps.utils.T; public class Objective4 extends Objective { @@ -25,4 +25,9 @@ public class Objective4 extends Objective { } }); } + + @Override + public boolean isRevertable() { + return true; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective5.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective5.java similarity index 84% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective5.java rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective5.java index 8472f26c6c..b04062655a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective5.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective5.java @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives; +package info.nightscout.androidaps.plugins.constraints.objectives.objectives; import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.utils.T; +import info.nightscout.androidaps.utils.T; public class Objective5 extends Objective { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective6.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective6.java similarity index 74% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective6.java rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective6.java index 7867b28e70..284dfa3ab0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective6.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective6.java @@ -1,9 +1,9 @@ -package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives; +package info.nightscout.androidaps.plugins.constraints.objectives.objectives; import java.util.List; import info.nightscout.androidaps.R; -import info.nightscout.utils.T; +import info.nightscout.androidaps.utils.T; public class Objective6 extends Objective { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective7.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective7.java similarity index 73% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective7.java rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective7.java index 670cffe746..f90411ecfb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective7.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective7.java @@ -1,9 +1,9 @@ -package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives; +package info.nightscout.androidaps.plugins.constraints.objectives.objectives; import java.util.List; import info.nightscout.androidaps.R; -import info.nightscout.utils.T; +import info.nightscout.androidaps.utils.T; public class Objective7 extends Objective { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective8.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective8.java similarity index 74% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective8.java rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective8.java index 9ac4f9b6d7..7148f5e5ad 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective8.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective8.java @@ -1,9 +1,9 @@ -package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives; +package info.nightscout.androidaps.plugins.constraints.objectives.objectives; import java.util.List; import info.nightscout.androidaps.R; -import info.nightscout.utils.T; +import info.nightscout.androidaps.utils.T; public class Objective8 extends Objective { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.java similarity index 80% rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.java index 9229164eb0..65dc119c6a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.java @@ -1,5 +1,6 @@ -package info.nightscout.androidaps.plugins.ConstraintsSafety; +package info.nightscout.androidaps.plugins.constraints.safety; +import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.ConstraintChecker; @@ -12,16 +13,17 @@ import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; -import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin; -import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.HardLimits; -import info.nightscout.utils.Round; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin; +import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin; +import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.HardLimits; +import info.nightscout.androidaps.utils.Round; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 05.08.2016. @@ -94,6 +96,17 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface { return value; } + @Override + public Constraint isUAMEnabled(Constraint value) { + boolean enabled = SP.getBoolean(R.string.key_use_uam, false); + if (!enabled) + value.set(false, MainApp.gs(R.string.uamdisabledinpreferences), this); + boolean oref1Enabled = SensitivityOref1Plugin.getPlugin().isEnabled(PluginType.SENSITIVITY); + if (!oref1Enabled) + value.set(false, MainApp.gs(R.string.uamdisabledoref1notselected), this); + return value; + } + @Override public Constraint isAdvancedFilteringEnabled(Constraint value) { BgSourceInterface bgSource = ConfigBuilderPlugin.getPlugin().getActiveBgSource(); @@ -110,17 +123,19 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface { absoluteRate.setIfGreater(0d, String.format(MainApp.gs(R.string.limitingbasalratio), 0d, MainApp.gs(R.string.itmustbepositivevalue)), this); - double maxBasal = SP.getDouble(R.string.key_openapsma_max_basal, 1d); - absoluteRate.setIfSmaller(maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), maxBasal, MainApp.gs(R.string.maxvalueinpreferences)), this); + if (Config.APS) { + double maxBasal = SP.getDouble(R.string.key_openapsma_max_basal, 1d); + absoluteRate.setIfSmaller(maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), maxBasal, MainApp.gs(R.string.maxvalueinpreferences)), this); - // Check percentRate but absolute rate too, because we know real current basal in pump - Double maxBasalMult = SP.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d); - double maxFromBasalMult = Math.floor(maxBasalMult * profile.getBasal() * 100) / 100; - absoluteRate.setIfSmaller(maxFromBasalMult, String.format(MainApp.gs(R.string.limitingbasalratio), maxFromBasalMult, MainApp.gs(R.string.maxbasalmultiplier)), this); + // Check percentRate but absolute rate too, because we know real current basal in pump + Double maxBasalMult = SP.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d); + double maxFromBasalMult = Math.floor(maxBasalMult * profile.getBasal() * 100) / 100; + absoluteRate.setIfSmaller(maxFromBasalMult, String.format(MainApp.gs(R.string.limitingbasalratio), maxFromBasalMult, MainApp.gs(R.string.maxbasalmultiplier)), this); - Double maxBasalFromDaily = SP.getDouble(R.string.key_openapsama_max_daily_safety_multiplier, 3d); - double maxFromDaily = Math.floor(profile.getMaxDailyBasal() * maxBasalFromDaily * 100) / 100; - absoluteRate.setIfSmaller(maxFromDaily, String.format(MainApp.gs(R.string.limitingbasalratio), maxFromDaily, MainApp.gs(R.string.maxdailybasalmultiplier)), this); + Double maxBasalFromDaily = SP.getDouble(R.string.key_openapsama_max_daily_safety_multiplier, 3d); + double maxFromDaily = Math.floor(profile.getMaxDailyBasal() * maxBasalFromDaily * 100) / 100; + absoluteRate.setIfSmaller(maxFromDaily, String.format(MainApp.gs(R.string.limitingbasalratio), maxFromDaily, MainApp.gs(R.string.maxdailybasalmultiplier)), this); + } absoluteRate.setIfSmaller(HardLimits.maxBasal(), String.format(MainApp.gs(R.string.limitingbasalratio), HardLimits.maxBasal(), MainApp.gs(R.string.hardlimit)), this); @@ -187,7 +202,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface { return insulin; } - @Override + @Override public Constraint applyExtendedBolusConstraints(Constraint insulin) { insulin.setIfGreater(0d, String.format(MainApp.gs(R.string.limitingextendedbolus), 0d, MainApp.gs(R.string.itmustbepositivevalue)), this); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.java new file mode 100644 index 0000000000..197fd5c17a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.java @@ -0,0 +1,76 @@ +package info.nightscout.androidaps.plugins.constraints.storage; + +import android.os.Environment; +import android.os.StatFs; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; + +import info.nightscout.androidaps.Constants; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.interfaces.Constraint; +import info.nightscout.androidaps.interfaces.ConstraintsInterface; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginDescription; +import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; + +/** + * Created by Rumen on 06.03.2019. + */ +public class StorageConstraintPlugin extends PluginBase implements ConstraintsInterface { + private static Logger log = LoggerFactory.getLogger(L.CONSTRAINTS); + static StorageConstraintPlugin plugin = null; + + public static StorageConstraintPlugin getPlugin() { + if (plugin == null) + plugin = new StorageConstraintPlugin(); + return plugin; + } + + public StorageConstraintPlugin() { + super(new PluginDescription() + .mainType(PluginType.CONSTRAINTS) + .neverVisible(true) + .alwaysEnabled(true) + .showInList(false) + .pluginName(R.string.storage) + ); + } + + /** + * Constraints interface + **/ + + @Override + public Constraint isClosedLoopAllowed(Constraint value) { + long diskfree = getAvailableInternalMemorySize(); + if (L.isEnabled(L.CONSTRAINTS)) + log.debug("Internal storage free (Mb):" + diskfree); + if (diskfree < Constants.MINIMUM_FREE_SPACE) { + value.set(false, MainApp.gs(R.string.diskfull, Constants.MINIMUM_FREE_SPACE), this); + Notification notification = new Notification(Notification.DISKFULL, MainApp.gs(R.string.diskfull, Constants.MINIMUM_FREE_SPACE), Notification.NORMAL); + MainApp.bus().post(new EventNewNotification(notification)); + } else { + MainApp.bus().post(new EventDismissNotification(Notification.DISKFULL)); + } + + return value; + } + + public static long getAvailableInternalMemorySize() { + File path = Environment.getDataDirectory(); + StatFs stat = new StatFs(path.getPath()); + long blockSize = stat.getBlockSizeLong(); + long blocksAvailable = stat.getAvailableBlocksLong(); + int size = 1048576; // blocksize of 1 Mb + return ((blocksAvailable * blockSize) / size); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.java similarity index 72% rename from app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.java index a71b447d82..02ff6e6b5c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.java @@ -1,18 +1,25 @@ -package info.nightscout.androidaps.plugins.Actions; +package info.nightscout.androidaps.plugins.general.actions; import android.app.Activity; import android.content.Intent; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; import com.crashlytics.android.answers.CustomEvent; import com.squareup.otto.Subscribe; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import info.nightscout.androidaps.Config; import info.nightscout.androidaps.activities.HistoryBrowseActivity; import info.nightscout.androidaps.MainApp; @@ -25,18 +32,21 @@ import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog; -import info.nightscout.androidaps.plugins.Actions.dialogs.NewExtendedBolusDialog; -import info.nightscout.androidaps.plugins.Actions.dialogs.NewTempBasalDialog; -import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; -import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; -import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.SingleClickButton; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.dialogs.FillDialog; +import info.nightscout.androidaps.plugins.general.actions.dialogs.NewExtendedBolusDialog; +import info.nightscout.androidaps.plugins.general.actions.dialogs.NewTempBasalDialog; +import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment; +import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog; +import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.SingleClickButton; + /** * A simple {@link Fragment} subclass. @@ -49,6 +59,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL return actionsPlugin; } + View actionsFragmentView; SingleClickButton profileSwitch; SingleClickButton tempTarget; SingleClickButton extendedBolus; @@ -59,6 +70,9 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL SingleClickButton tddStats; SingleClickButton history; + private Map pumpCustomActions = new HashMap<>(); + private List pumpCustomButtons = new ArrayList<>(); + public ActionsFragment() { super(); } @@ -90,6 +104,8 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL history.setOnClickListener(this); tddStats.setOnClickListener(this); + actionsFragmentView = view; + updateGUI(); return view; } catch (Exception e) { @@ -192,13 +208,87 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL else tempTarget.setVisibility(View.VISIBLE); - if (!ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().supportsTDDs) tddStats.setVisibility(View.GONE); - else tddStats.setVisibility(View.VISIBLE); + if (!pump.getPumpDescription().supportsTDDs) + tddStats.setVisibility(View.GONE); + else + tddStats.setVisibility(View.VISIBLE); + + checkPumpCustomActions(); + } }); } + View.OnClickListener pumpCustomActionsListener = v -> { + + SingleClickButton btn = (SingleClickButton)v; + + CustomAction customAction = this.pumpCustomActions.get(btn.getText().toString()); + + ConfigBuilderPlugin.getPlugin().getActivePump().executeCustomAction(customAction.getCustomActionType()); + + }; + + + private void checkPumpCustomActions() { + + PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump(); + + removePumpCustomActions(); + + if (activePump == null) { + return; + } + + List customActions = activePump.getCustomActions(); + + if (customActions != null && customActions.size()>0) { + + LinearLayout ll = actionsFragmentView.findViewById(R.id.action_buttons_layout); + + for (CustomAction customAction : customActions) { + + SingleClickButton btn = new SingleClickButton(getContext(), null, android.R.attr.buttonStyle); + btn.setText(MainApp.gs(customAction.getName())); + + LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.5f); + layoutParams.setMargins(20, 8, 20, 8); // 10,3,10,3 + + btn.setLayoutParams(layoutParams); + btn.setOnClickListener(pumpCustomActionsListener); + + Drawable top = getResources().getDrawable(customAction.getIconResourceId()); + btn.setCompoundDrawablesWithIntrinsicBounds(null, top, null, null); + + ll.addView(btn); + + this.pumpCustomActions.put(MainApp.gs(customAction.getName()), customAction); + this.pumpCustomButtons.add(btn); + + } + } + + } + + + private void removePumpCustomActions() { + + if (pumpCustomActions.size()==0) + return; + + LinearLayout ll = actionsFragmentView.findViewById(R.id.action_buttons_layout); + + for (SingleClickButton customButton : pumpCustomButtons) { + ll.removeView(customButton); + } + + pumpCustomButtons.clear(); + pumpCustomActions.clear(); + } + + @Override public void onClick(View view) { FragmentManager manager = getFragmentManager(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsPlugin.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsPlugin.java index ff6275c9c9..5d47206e5c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Actions; +package info.nightscout.androidaps.plugins.general.actions; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PluginBase; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.java new file mode 100644 index 0000000000..e5e119baad --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.java @@ -0,0 +1,47 @@ +package info.nightscout.androidaps.plugins.general.actions.defs; + +import info.nightscout.androidaps.R; + +/** + * Created by andy on 9/20/18. + */ + +public class CustomAction { + + private int name; + private String iconName; + private CustomActionType customActionType; + private int iconResourceId; + + + public CustomAction(int nameResourceId, CustomActionType actionType) { + this.name = nameResourceId; + this.customActionType = actionType; + this.iconResourceId = R.drawable.icon_actions_profileswitch; + } + + public CustomAction(int nameResourceId, CustomActionType actionType, int iconResourceId) { + this.name = nameResourceId; + this.customActionType = actionType; + this.iconResourceId = iconResourceId; + } + + + public int getName() { + + return name; + } + + + + + public CustomActionType getCustomActionType() { + + return customActionType; + } + + + public int getIconResourceId() { + return iconResourceId; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomActionType.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomActionType.java new file mode 100644 index 0000000000..74ecf3c0e3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomActionType.java @@ -0,0 +1,11 @@ +package info.nightscout.androidaps.plugins.general.actions.defs; + +/** + * Created by andy on 9/20/18. + */ + +public interface CustomActionType { + + String getKey(); + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/FillDialog.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/FillDialog.java index 880bee86a8..45333040e1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/FillDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Actions.dialogs; +package info.nightscout.androidaps.plugins.general.actions.dialogs; import android.content.Context; import android.content.Intent; @@ -34,18 +34,18 @@ import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.interfaces.Constraint; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity; import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.NumberPicker; -import info.nightscout.utils.SP; -import info.nightscout.utils.SafeParse; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.utils.NumberPicker; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.SafeParse; +import info.nightscout.androidaps.utils.ToastUtils; -import static info.nightscout.utils.DateUtil.now; +import static info.nightscout.androidaps.utils.DateUtil.now; public class FillDialog extends DialogFragment implements OnClickListener { private static Logger log = LoggerFactory.getLogger(FillDialog.class); @@ -185,7 +185,7 @@ public class FillDialog extends DialogFragment implements OnClickListener { confirmMessage.add(MainApp.gs(R.string.fillwarning)); confirmMessage.add(""); confirmMessage.add(MainApp.gs(R.string.bolus) + ": " + "" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + "U" + ""); - if (!insulinAfterConstraints.equals(insulin)) + if (Math.abs(insulinAfterConstraints - insulin) > 0.01d) confirmMessage.add("" + MainApp.gs(R.string.bolusconstraintapplied) + ""); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/NewExtendedBolusDialog.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/NewExtendedBolusDialog.java index 710874a790..3ba1ff3177 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/NewExtendedBolusDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Actions.dialogs; +package info.nightscout.androidaps.plugins.general.actions.dialogs; import android.content.Context; import android.content.DialogInterface; @@ -12,7 +12,6 @@ import android.view.ViewGroup; import com.crashlytics.android.answers.CustomEvent; -import org.mozilla.javascript.tools.jsc.Main; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,12 +20,12 @@ import java.text.DecimalFormat; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.Constraint; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity; import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.NumberPicker; -import info.nightscout.utils.SafeParse; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.NumberPicker; +import info.nightscout.androidaps.utils.SafeParse; public class NewExtendedBolusDialog extends DialogFragment implements View.OnClickListener { private static Logger log = LoggerFactory.getLogger(NewExtendedBolusDialog.class); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/NewTempBasalDialog.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/NewTempBasalDialog.java index 95abf173db..ae8ca782d1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/NewTempBasalDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Actions.dialogs; +package info.nightscout.androidaps.plugins.general.actions.dialogs; import android.content.DialogInterface; import android.content.Intent; @@ -24,13 +24,13 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PumpDescription; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity; import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.NumberPicker; -import info.nightscout.utils.SafeParse; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.NumberPicker; +import info.nightscout.androidaps.utils.SafeParse; public class NewTempBasalDialog extends DialogFragment implements View.OnClickListener, RadioGroup.OnCheckedChangeListener { private static Logger log = LoggerFactory.getLogger(NewTempBasalDialog.class); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java index c0de76ee37..96cf65fc93 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java @@ -1,16 +1,75 @@ package info.nightscout.androidaps.plugins.general.automation; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + import java.util.ArrayList; import java.util.List; import info.nightscout.androidaps.plugins.general.automation.actions.Action; import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger; +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector; public class AutomationEvent { - Trigger trigger; - List actions = new ArrayList<>(); + private Trigger trigger = new TriggerConnector(); + private List actions = new ArrayList<>(); + private String title; - AutomationEvent() { + public void setTitle(String title) { this.title = title; } + + public void setTrigger(Trigger trigger) { this.trigger = trigger; } + + public Trigger getTrigger() { + return trigger; + } + + public List getActions() { + return actions; + } + + public void addAction(Action action) { actions.add(action); } + + public String getTitle() { + return title; + } + + public String toJSON() { + JSONObject o = new JSONObject(); + try { + // title + o.put("title", title); + // trigger + o.put("trigger", trigger.toJSON()); + // actions + JSONArray array = new JSONArray(); + for (Action a : actions) { + array.put(a.toJSON()); + } + o.put("actions", array); + } catch (JSONException e) { + e.printStackTrace(); + } + return o.toString(); + } + + public AutomationEvent fromJSON(String data) { + try { + JSONObject d = new JSONObject(data); + // title + title = d.optString("title", ""); + // trigger + trigger = Trigger.instantiate(d.getString("trigger")); + // actions + JSONArray array = d.getJSONArray("actions"); + actions.clear(); + for (int i = 0; i < array.length(); i++) { + actions.add(Action.instantiate(new JSONObject(array.getString(i)))); + } + } catch (JSONException e) { + e.printStackTrace(); + } + return this; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java index 0e9eccd84e..ea3d4a8e7d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java @@ -1,24 +1,400 @@ package info.nightscout.androidaps.plugins.general.automation; +import android.app.Activity; +import android.content.Context; import android.os.Bundle; +import android.support.annotation.DrawableRes; +import android.support.annotation.NonNull; +import android.support.v4.app.FragmentManager; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.Spinner; +import android.widget.TextView; +import java.util.HashSet; +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.general.automation.actions.Action; +import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseTriggerDialog; +import info.nightscout.androidaps.plugins.general.automation.dialogs.EditActionDialog; +import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog; +import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger; +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector; public class AutomationFragment extends SubscriberFragment { + @BindView(R.id.eventListView) + RecyclerView mEventListView; + + private EventListAdapter mEventListAdapter; + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.automation_fragment, container, false); + unbinder = ButterKnife.bind(this, view); + + final AutomationPlugin plugin = AutomationPlugin.getPlugin(); + mEventListAdapter = new EventListAdapter(plugin.getAutomationEvents(), getFragmentManager()); + mEventListView.setLayoutManager(new LinearLayoutManager(getContext())); + mEventListView.setAdapter(mEventListAdapter); + + EditEventDialog.setOnClickListener(event -> mEventListAdapter.notifyDataSetChanged()); + + updateGUI(); + return view; } @Override - protected void updateGUI() { - + public void updateGUI() { + Activity activity = getActivity(); + if (activity != null) + activity.runOnUiThread(() -> mEventListAdapter.notifyDataSetChanged()); } + + @OnClick(R.id.fabAddEvent) + void onClickAddEvent(View v) { + EditEventDialog dialog = EditEventDialog.newInstance(new AutomationEvent(), true); + dialog.show(getFragmentManager(), "EditEventDialog"); + } + + /** + * RecyclerViewAdapter to display event lists. + */ + public static class EventListAdapter extends RecyclerView.Adapter { + private final List mEventList; + private final FragmentManager mFragmentManager; + + public EventListAdapter(List events, FragmentManager fragmentManager) { + this.mEventList = events; + this.mFragmentManager = fragmentManager; + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.automation_event_item, parent, false); + return new ViewHolder(v, parent.getContext()); + } + + private void addImage(@DrawableRes int res, Context context, LinearLayout layout) { + ImageView iv = new ImageView(context); + iv.setImageResource(res); + iv.setLayoutParams(new LinearLayout.LayoutParams(MainApp.dpToPx(24),MainApp.dpToPx(24))); + layout.addView(iv); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + final AutomationEvent event = mEventList.get(position); + holder.eventTitle.setText(event.getTitle()); + holder.iconLayout.removeAllViews(); + + // trigger icons + HashSet triggerIcons = new HashSet<>(); + TriggerConnector.fillIconSet((TriggerConnector)event.getTrigger(), triggerIcons); + for(int res : triggerIcons) { + addImage(res, holder.context, holder.iconLayout); + } + + // arrow icon + ImageView iv = new ImageView(holder.context); + iv.setImageResource(R.drawable.ic_arrow_forward_white_24dp); + iv.setLayoutParams(new LinearLayout.LayoutParams(MainApp.dpToPx(24),MainApp.dpToPx(24))); + iv.setPadding(MainApp.dpToPx(4), 0, MainApp.dpToPx(4), 0); + holder.iconLayout.addView(iv); + + // action icons + HashSet actionIcons = new HashSet<>(); + for(Action action : event.getActions()) { + if (action.icon().isPresent()) + actionIcons.add(action.icon().get()); + } + for(int res : actionIcons) { + addImage(res, holder.context, holder.iconLayout); + } + + // remove event + holder.iconTrash.setOnClickListener(v -> { + mEventList.remove(event); + notifyDataSetChanged(); + }); + + // edit event + holder.rootLayout.setOnClickListener(v -> { + EditEventDialog dialog = EditEventDialog.newInstance(event, false); + dialog.show(mFragmentManager, "EditEventDialog"); + }); + } + + @Override + public int getItemCount() { + return mEventList.size(); + } + + static class ViewHolder extends RecyclerView.ViewHolder { + final RelativeLayout rootLayout; + final LinearLayout iconLayout; + final TextView eventTitle; + final Context context; + final ImageView iconTrash; + + public ViewHolder(View view, Context context) { + super(view); + this.context = context; + eventTitle = view.findViewById(R.id.viewEventTitle); + rootLayout = view.findViewById(R.id.rootLayout); + iconLayout = view.findViewById(R.id.iconLayout); + iconTrash = view.findViewById(R.id.iconTrash); + } + } + } + + /** + * RecyclerViewAdapter to display action lists. + */ + public static class ActionListAdapter extends RecyclerView.Adapter { + private final List mActionList; + private final FragmentManager mFragmentManager; + + public ActionListAdapter(FragmentManager manager, List events) { + this.mActionList = events; + this.mFragmentManager = manager; + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.automation_action_item, parent, false); + return new ViewHolder(v); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + final Action action = mActionList.get(position); + holder.actionTitle.setText(action.friendlyName()); + holder.layoutText.setOnClickListener(v -> { + if (action.hasDialog()) { + EditActionDialog dialog = EditActionDialog.newInstance(action); + dialog.show(mFragmentManager, "EditActionDialog"); + } + }); + holder.iconTrash.setOnClickListener(v -> { + mActionList.remove(action); + notifyDataSetChanged(); + }); + } + + @Override + public int getItemCount() { + return mActionList.size(); + } + + static class ViewHolder extends RecyclerView.ViewHolder { + TextView actionTitle; + TextView actionDescription; + LinearLayout layoutText; + ImageView iconTrash; + + public ViewHolder(View view) { + super(view); + layoutText = view.findViewById(R.id.layoutText); + actionTitle = view.findViewById(R.id.viewActionTitle); + actionDescription = view.findViewById(R.id.viewActionDescription); + iconTrash = view.findViewById(R.id.iconTrash); + } + } + } + + /** + * Custom Adapter to display triggers dynamically with nested linear layouts. + */ + public static class TriggerListAdapter { + private final LinearLayout mRootLayout; + private final Context mContext; + private final TriggerConnector mRootConnector; + private final FragmentManager mFragmentManager; + + public TriggerListAdapter(Context context, FragmentManager fragmentManager, LinearLayout rootLayout, TriggerConnector rootTrigger) { + mRootLayout = rootLayout; + mContext = context; + mFragmentManager = fragmentManager; + mRootConnector = rootTrigger; + build(); + } + + public Context getContext() { + return mContext; + } + + public LinearLayout getRootLayout() { + return mRootLayout; + } + + public FragmentManager getFragmentManager() { + return mFragmentManager; + } + + public void destroy() { + mRootLayout.removeAllViews(); + } + + private void build() { + for(int i = 0; i < mRootConnector.size(); ++i) { + final Trigger trigger = mRootConnector.get(i); + + // spinner + if (i > 0) { + createSpinner(trigger); + } + + // trigger layout + mRootLayout.addView(trigger.createView(mContext, mFragmentManager)); + + // buttons + createButtons(trigger); + } + + if (mRootConnector.size() == 0) { + Button buttonAdd = new Button(mContext); + buttonAdd.setText("Add New"); + buttonAdd.setOnClickListener(v -> { + ChooseTriggerDialog dialog = ChooseTriggerDialog.newInstance(); + dialog.setOnClickListener(newTriggerObject -> { + mRootConnector.add(newTriggerObject); + rebuild(); + }); + dialog.show(mFragmentManager, "ChooseTriggerDialog"); + }); + mRootLayout.addView(buttonAdd); + } + } + + private Spinner createSpinner() { + Spinner spinner = new Spinner(mContext); + ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_item, TriggerConnector.Type.labels()); + spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(spinnerArrayAdapter); + return spinner; + } + + private void createSpinner(Trigger trigger) { + final TriggerConnector connector = trigger.getConnector(); + final int initialPosition = connector.getConnectorType().ordinal(); + Spinner spinner = createSpinner(); + spinner.setSelection(initialPosition); + spinner.setBackgroundColor(MainApp.gc(R.color.black_overlay)); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT + ); + params.setMargins(0, MainApp.dpToPx(8), 0, MainApp.dpToPx(8)); + spinner.setLayoutParams(params); + spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + if (position != initialPosition) { + // conector type changed + changeConnector(trigger, connector, TriggerConnector.Type.values()[position]); + } + } + + @Override + public void onNothingSelected(AdapterView parent) { } + }); + mRootLayout.addView(spinner); + } + + private void createButtons(Trigger trigger) { + // do not create buttons for TriggerConnector + if (trigger instanceof TriggerConnector) { + return; + } + + // Button Layout + LinearLayout buttonLayout = new LinearLayout(mContext); + buttonLayout.setOrientation(LinearLayout.HORIZONTAL); + buttonLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + mRootLayout.addView(buttonLayout); + + // Button [-] + Button buttonRemove = new Button(mContext); + buttonRemove.setText("del"); + buttonRemove.setOnClickListener(v -> { + final TriggerConnector connector = trigger.getConnector(); + connector.remove(trigger); + connector.simplify().rebuildView(); + }); + buttonLayout.addView(buttonRemove); + + // Button [+] + Button buttonAdd = new Button(mContext); + buttonAdd.setText("add"); + buttonAdd.setOnClickListener(v -> { + ChooseTriggerDialog dialog = ChooseTriggerDialog.newInstance(); + dialog.show(mFragmentManager, "ChooseTriggerDialog"); + dialog.setOnClickListener(newTriggerObject -> { + TriggerConnector connector = trigger.getConnector(); + connector.add(connector.pos(trigger)+1, newTriggerObject); + connector.simplify().rebuildView(); + }); + }); + buttonLayout.addView(buttonAdd); + + // Button [*] + Button buttonCopy = new Button(mContext); + buttonCopy.setText("copy"); + buttonCopy.setOnClickListener(v -> { + TriggerConnector connector = trigger.getConnector(); + connector.add(connector.pos(trigger)+1, trigger.duplicate()); + connector.simplify().rebuildView(); + }); + buttonLayout.addView(buttonCopy); + } + + public static void changeConnector(final Trigger trigger, final TriggerConnector connector, final TriggerConnector.Type newConnectorType) { + if (connector.size() > 2) { + // split connector + int pos = connector.pos(trigger) - 1; + + TriggerConnector newConnector = new TriggerConnector(newConnectorType); + + // move trigger from pos and pos+1 into new connector + for(int i = 0; i < 2; ++i) { + Trigger t = connector.get(pos); + newConnector.add(t); + connector.remove(t); + } + + connector.add(pos, newConnector); + } else { + connector.changeConnectorType(newConnectorType); + } + + connector.simplify().rebuildView(); + } + + public void rebuild() { + destroy(); + build(); + } + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.java index 22526a50df..a65c4fee4b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.java @@ -18,7 +18,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.services.LocationService; public class AutomationPlugin extends PluginBase { @@ -31,10 +31,10 @@ public class AutomationPlugin extends PluginBase { return plugin; } - List automationEvents = new ArrayList<>(); - EventLocationChange eventLocationChange; - EventChargingState eventChargingState; - EventNetworkChange eventNetworkChange; + private final List automationEvents = new ArrayList<>(); + private EventLocationChange eventLocationChange; + private EventChargingState eventChargingState; + private EventNetworkChange eventNetworkChange; private AutomationPlugin() { super(new PluginDescription() @@ -64,6 +64,22 @@ public class AutomationPlugin extends PluginBase { MainApp.bus().unregister(this); } + public List getAutomationEvents() { + return automationEvents; + } + + public EventLocationChange getEventLocationChange() { + return eventLocationChange; + } + + public EventChargingState getEventChargingState() { + return eventChargingState; + } + + public EventNetworkChange getEventNetworkChange() { + return eventNetworkChange; + } + @Subscribe public void onEventPreferenceChange(EventPreferenceChange e) { if (e.isChanged(R.string.key_location)) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.java index b74243326e..546cc6b272 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.java @@ -1,9 +1,62 @@ package info.nightscout.androidaps.plugins.general.automation.actions; +import android.widget.LinearLayout; + +import com.google.common.base.Optional; + +import org.json.JSONException; +import org.json.JSONObject; + import info.nightscout.androidaps.queue.Callback; public abstract class Action { - abstract int friendlyName(); + public abstract int friendlyName(); + abstract void doAction(Callback callback); + + public void generateDialog(LinearLayout root) { } + + public boolean hasDialog() { return false; } + + public String toJSON() { + JSONObject o = new JSONObject(); + try { + o.put("type", this.getClass().getName()); + } catch (JSONException e) { + e.printStackTrace(); + } + return o.toString(); + } + + public abstract Optional icon(); + + public Action fromJSON(String data) { + return this; + } + + public static Action instantiate(JSONObject object) { + try { + String type = object.getString("type"); + JSONObject data = object.optJSONObject("data"); + Class clazz = Class.forName(type); + return ((Action) clazz.newInstance()).fromJSON(data != null ? data.toString() : ""); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | JSONException e) { + e.printStackTrace(); + } + return null; + } + + public void apply(Action a) { + try { + JSONObject object = new JSONObject(a.toJSON()); + String type = object.getString("type"); + JSONObject data = object.getJSONObject("data"); + if (type.equals(getClass().getName())) { + fromJSON(data.toString()); + } + } catch (JSONException e) { + e.printStackTrace(); + } + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.java index 059bdacaf3..794d4a31ce 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.java @@ -1,17 +1,19 @@ package info.nightscout.androidaps.plugins.general.automation.actions; +import com.google.common.base.Optional; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.queue.Callback; public class ActionLoopDisable extends Action { @Override - int friendlyName() { + public int friendlyName() { return R.string.disableloop; } @@ -33,4 +35,9 @@ public class ActionLoopDisable extends Action { callback.result(new PumpEnactResult().success(true).comment(R.string.alreadydisabled)).run(); } } + + @Override + public Optional icon() { + return Optional.of(R.drawable.ic_stop_24dp); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.java index 1ef1ec81a6..6e8839f353 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.java @@ -1,17 +1,19 @@ package info.nightscout.androidaps.plugins.general.automation.actions; +import com.google.common.base.Optional; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.queue.Callback; public class ActionLoopEnable extends Action { @Override - int friendlyName() { + public int friendlyName() { return R.string.enableloop; } @@ -28,4 +30,9 @@ public class ActionLoopEnable extends Action { callback.result(new PumpEnactResult().success(true).comment(R.string.alreadyenabled)).run(); } } + + @Override + public Optional icon() { + return Optional.of(R.drawable.ic_play_circle_outline_24dp); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.java index 71244c70f4..c734acd541 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.java @@ -1,18 +1,19 @@ package info.nightscout.androidaps.plugins.general.automation.actions; +import com.google.common.base.Optional; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.events.EventRefreshOverview; -import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.queue.Callback; public class ActionLoopResume extends Action { @Override - int friendlyName() { + public int friendlyName() { return R.string.resumeloop; } @@ -30,4 +31,9 @@ public class ActionLoopResume extends Action { callback.result(new PumpEnactResult().success(true).comment(R.string.notsuspended)).run(); } } + + @Override + public Optional icon() { + return Optional.of(R.drawable.ic_replay_24dp); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.java index eb9ddfd79c..4938a6939d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.java @@ -1,18 +1,20 @@ package info.nightscout.androidaps.plugins.general.automation.actions; +import com.google.common.base.Optional; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.events.EventRefreshOverview; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.queue.Callback; public class ActionLoopSuspend extends Action { - int minutes; + private int minutes; @Override - int friendlyName() { - return R.string.disableloop; + public int friendlyName() { + return R.string.suspendloop; } @Override @@ -27,4 +29,9 @@ public class ActionLoopSuspend extends Action { callback.result(new PumpEnactResult().success(true).comment(R.string.alreadysuspended)).run(); } } + + @Override + public Optional icon() { + return Optional.of(R.drawable.ic_pause_circle_outline_24dp); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java index 8cd8db0f4e..f033e3b679 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java @@ -1,33 +1,101 @@ package info.nightscout.androidaps.plugins.general.automation.actions; +import android.widget.LinearLayout; + +import com.google.common.base.Optional; + +import org.json.JSONException; +import org.json.JSONObject; + import info.nightscout.androidaps.Constants; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.general.automation.elements.InputBg; +import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration; +import info.nightscout.androidaps.plugins.general.automation.elements.Label; import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.JsonHelper; public class ActionStartTempTarget extends Action { + private String reason = ""; + private InputBg value; + private InputDuration duration = new InputDuration(0, InputDuration.TimeUnit.MINUTES); - double value; - int durationInMinutes; - String reason; - String units = Constants.MGDL; + public ActionStartTempTarget() { + value = new InputBg(Constants.MGDL); + } + + public ActionStartTempTarget(String units) { + value = new InputBg(units); + } @Override - int friendlyName() { + public int friendlyName() { return R.string.starttemptarget; } @Override void doAction(Callback callback) { - double converted = Profile.toMgdl(value, units); - TempTarget tempTarget = new TempTarget().date(DateUtil.now()).duration(durationInMinutes).reason(reason).source(Source.USER).low(converted).high(converted); + TempTarget tempTarget = new TempTarget().date(DateUtil.now()).duration((int)duration.getMinutes()).reason(reason).source(Source.USER).low(value.getMgdl()).high(value.getMgdl()); TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); if (callback != null) callback.result(new PumpEnactResult().success(true).comment(R.string.ok)).run(); } + + @Override + public void generateDialog(LinearLayout root) { + int unitResId = value.getUnits().equals(Constants.MGDL) ? R.string.mgdl : R.string.mmol; + + new LayoutBuilder() + .add(new Label(MainApp.gs(R.string.careportal_newnstreatment_percentage_label), MainApp.gs(unitResId), value)) + .add(new Label(MainApp.gs(R.string.careportal_newnstreatment_duration_min_label), "min", duration)) + .build(root); + } + + @Override + public boolean hasDialog() { + return true; + } + + @Override + public String toJSON() { + JSONObject o = new JSONObject(); + try { + o.put("type", ActionStartTempTarget.class.getName()); + JSONObject data = new JSONObject(); + data.put("reason", reason); + data.put("valueInMg", value.getMgdl()); + data.put("units", value.getUnits()); + data.put("durationInMinutes", duration.getMinutes()); + o.put("data", data); + } catch (JSONException e) { + e.printStackTrace(); + } + return o.toString(); + } + + @Override + public Action fromJSON(String data) { + try { + JSONObject d = new JSONObject(data); + reason = JsonHelper.safeGetString(d, "reason"); + value.setUnits(JsonHelper.safeGetString(d, "units")); + value.setMgdl(JsonHelper.safeGetInt(d, "valueInMg")); + duration.setMinutes(JsonHelper.safeGetDouble(d, "durationInMinutes")); + } catch (JSONException e) { + e.printStackTrace(); + } + return this; + } + + @Override + public Optional icon() { + return Optional.of(R.drawable.icon_cp_cgm_target); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseActionDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseActionDialog.java new file mode 100644 index 0000000000..12956dd108 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseActionDialog.java @@ -0,0 +1,139 @@ +package info.nightscout.androidaps.plugins.general.automation.dialogs; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.RadioButton; +import android.widget.RadioGroup; + +import java.util.ArrayList; +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import butterknife.Unbinder; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.general.automation.actions.Action; +import info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopDisable; +import info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopEnable; +import info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopResume; +import info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopSuspend; +import info.nightscout.androidaps.plugins.general.automation.actions.ActionStartTempTarget; + +public class ChooseActionDialog extends DialogFragment { + + public interface OnClickListener { + void onClick(Action newActionObject); + } + + private static OnClickListener mClickListener = null; + + private static final List actionDummyObjects = new ArrayList() {{ + add(new ActionLoopDisable()); + add(new ActionLoopEnable()); + add(new ActionLoopResume()); + add(new ActionLoopSuspend()); + add(new ActionStartTempTarget()); + }}; + + private Unbinder mUnbinder; + + @BindView(R.id.radioGroup) + RadioGroup mRadioGroup; + + public static ChooseActionDialog newInstance() { + Bundle args = new Bundle(); + + ChooseActionDialog fragment = new ChooseActionDialog(); + fragment.setArguments(args); + + return fragment; + } + + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.automation_dialog_choose_action, container, false); + mUnbinder = ButterKnife.bind(this, view); + + for(Action a : actionDummyObjects) { + RadioButton radioButton = new RadioButton(getContext()); + radioButton.setText(a.friendlyName()); + radioButton.setTag(a); + mRadioGroup.addView(radioButton); + } + + // restore checked radio button + int checkedIndex = 0; + if (savedInstanceState != null) { + checkedIndex = savedInstanceState.getInt("checkedIndex"); + } + + ((RadioButton)mRadioGroup.getChildAt(checkedIndex)).setChecked(true); + + return view; + } + + private int getCheckedIndex() { + for(int i = 0; i < mRadioGroup.getChildCount(); ++i) { + if (((RadioButton)mRadioGroup.getChildAt(i)).isChecked()) + return i; + } + return -1; + } + + private Class getActionClass() { + int radioButtonID = mRadioGroup.getCheckedRadioButtonId(); + RadioButton radioButton = mRadioGroup.findViewById(radioButtonID); + if (radioButton != null) { + Object tag = radioButton.getTag(); + if (tag instanceof Action) + return tag.getClass(); + } + return null; + } + + private Action instantiateAction() { + Class actionClass = getActionClass(); + if (actionClass != null) { + try { + return (Action) actionClass.newInstance(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } + + + public static void setOnClickListener(OnClickListener clickListener) { + mClickListener = clickListener; + } + + @Override + public void onDestroyView() { + mUnbinder.unbind(); + super.onDestroyView(); + } + + @OnClick(R.id.ok) + public void onButtonOk(View view) { + if (mClickListener != null) + mClickListener.onClick(instantiateAction()); + + dismiss(); + } + + @OnClick(R.id.cancel) + public void onButtonCancel(View view) { + dismiss(); + } + + @Override + public void onSaveInstanceState(Bundle bundle) { + bundle.putInt("checkedIndex", getCheckedIndex()); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseTriggerDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseTriggerDialog.java new file mode 100644 index 0000000000..cdb6b0739f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseTriggerDialog.java @@ -0,0 +1,132 @@ +package info.nightscout.androidaps.plugins.general.automation.dialogs; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.RadioButton; +import android.widget.RadioGroup; + +import java.util.ArrayList; +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import butterknife.Unbinder; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger; +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBg; +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTime; + +public class ChooseTriggerDialog extends DialogFragment { + + public interface OnClickListener { + void onClick(Trigger newTriggerObject); + } + + private static final List triggerDummyObjects = new ArrayList() {{ + add(new TriggerBg()); + add(new TriggerTime()); + }}; + + private Unbinder mUnbinder; + private OnClickListener mClickListener = null; + + @BindView(R.id.radioGroup) + RadioGroup mRadioGroup; + + public static ChooseTriggerDialog newInstance() { + Bundle args = new Bundle(); + + ChooseTriggerDialog fragment = new ChooseTriggerDialog(); + fragment.setArguments(args); + + return fragment; + } + + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.automation_dialog_choose_trigger, container, false); + mUnbinder = ButterKnife.bind(this, view); + + for(Trigger t : triggerDummyObjects) { + RadioButton radioButton = new RadioButton(getContext()); + radioButton.setText(t.friendlyName()); + radioButton.setTag(t); + mRadioGroup.addView(radioButton); + } + + // restore checked radio button + int checkedIndex = 0; + if (savedInstanceState != null) { + checkedIndex = savedInstanceState.getInt("checkedIndex"); + } + + ((RadioButton)mRadioGroup.getChildAt(checkedIndex)).setChecked(true); + + return view; + } + + private int getCheckedIndex() { + for(int i = 0; i < mRadioGroup.getChildCount(); ++i) { + if (((RadioButton)mRadioGroup.getChildAt(i)).isChecked()) + return i; + } + return -1; + } + + private Class getTriggerClass() { + int radioButtonID = mRadioGroup.getCheckedRadioButtonId(); + RadioButton radioButton = mRadioGroup.findViewById(radioButtonID); + if (radioButton != null) { + Object tag = radioButton.getTag(); + if (tag instanceof Trigger) + return tag.getClass(); + } + return null; + } + + private Trigger instantiateTrigger() { + Class triggerClass = getTriggerClass(); + if (triggerClass != null) { + try { + return (Trigger) triggerClass.newInstance(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } + + + public void setOnClickListener(OnClickListener clickListener) { + mClickListener = clickListener; + } + + @Override + public void onDestroyView() { + mUnbinder.unbind(); + super.onDestroyView(); + } + + @OnClick(R.id.ok) + public void onButtonOk(View view) { + if (mClickListener != null) + mClickListener.onClick(instantiateTrigger()); + + dismiss(); + } + + @OnClick(R.id.cancel) + public void onButtonCancel(View view) { + dismiss(); + } + + @Override + public void onSaveInstanceState(Bundle bundle) { + bundle.putInt("checkedIndex", getCheckedIndex()); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditActionDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditActionDialog.java new file mode 100644 index 0000000000..f0338afbfe --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditActionDialog.java @@ -0,0 +1,94 @@ +package info.nightscout.androidaps.plugins.general.automation.dialogs; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import org.json.JSONException; +import org.json.JSONObject; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import butterknife.Unbinder; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.general.automation.actions.Action; +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector; + +public class EditActionDialog extends DialogFragment { + private static Action resultAction; + + private Unbinder mUnbinder; + private Action mAction; + + @BindView(R.id.layout_root) + LinearLayout mRootLayout; + + @BindView(R.id.viewActionTitle) + TextView mViewActionTitle; + + public static EditActionDialog newInstance(Action action) { + Bundle args = new Bundle(); + EditActionDialog fragment = new EditActionDialog(); + fragment.setArguments(args); + resultAction = action; + + return fragment; + } + + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.automation_dialog_action, container, false); + mUnbinder = ButterKnife.bind(this, view); + + // get json data for action + String actionData = null; + if (savedInstanceState != null) { + actionData = savedInstanceState.getString("action"); + } + if (actionData == null) { + actionData = resultAction.toJSON(); + } + + // create action from json + try { + mAction = Action.instantiate(new JSONObject(actionData)); + } catch (JSONException e) { + e.printStackTrace(); + } + + + mViewActionTitle.setText(mAction.friendlyName()); + mRootLayout.removeAllViews(); + mAction.generateDialog(mRootLayout); + + return view; + } + + @Override + public void onDestroyView() { + mUnbinder.unbind(); + super.onDestroyView(); + } + + @OnClick(R.id.ok) + public void onButtonOk(View view) { + resultAction.apply(mAction); + dismiss(); + } + + @OnClick(R.id.cancel) + public void onButtonCancel(View view) { + dismiss(); + } + + @Override + public void onSaveInstanceState(Bundle bundle) { + bundle.putString("action", mAction.toJSON()); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.java new file mode 100644 index 0000000000..535aee578a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.java @@ -0,0 +1,175 @@ +package info.nightscout.androidaps.plugins.general.automation.dialogs; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.design.widget.TextInputEditText; +import android.support.v4.app.DialogFragment; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import android.widget.Toast; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import butterknife.Unbinder; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.general.automation.AutomationEvent; +import info.nightscout.androidaps.plugins.general.automation.AutomationFragment; +import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin; +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector; + +public class EditEventDialog extends DialogFragment { + public interface OnClickListener { + void onClick(AutomationEvent event); + } + + private static OnClickListener mClickListener = null; + private static AutomationEvent staticEvent; + + public static void setOnClickListener(OnClickListener clickListener) { + mClickListener = clickListener; + } + + @BindView(R.id.inputEventTitle) + TextInputEditText mEditEventTitle; + + @BindView(R.id.editTrigger) + TextView mEditTrigger; + + @BindView(R.id.editAction) + TextView mEditAction; + + @BindView(R.id.triggerDescription) + TextView mTriggerDescription; + + @BindView(R.id.actionListView) + RecyclerView mActionListView; + + private Unbinder mUnbinder; + private AutomationFragment.ActionListAdapter mActionListAdapter; + private AutomationEvent mEvent; + private boolean mAddNew; + + public static EditEventDialog newInstance(AutomationEvent event, boolean addNew) { + staticEvent = event; + + Bundle args = new Bundle(); + EditEventDialog fragment = new EditEventDialog(); + fragment.setArguments(args); + // clone event + try { + fragment.mEvent = new AutomationEvent().fromJSON(event.toJSON()); + } catch (Exception e) { + e.printStackTrace(); + } + fragment.mAddNew = addNew; + return fragment; + } + + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.automation_dialog_event, container, false); + mUnbinder = ButterKnife.bind(this, view); + + // load data from bundle + if (savedInstanceState != null) { + String eventData = savedInstanceState.getString("event"); + if (eventData != null) mEvent = new AutomationEvent().fromJSON(eventData); + mAddNew = savedInstanceState.getBoolean("addNew"); + } else if (mAddNew) { + mEvent.setTrigger(new TriggerConnector(TriggerConnector.Type.OR)); + } + + // event title + mEditEventTitle.setText(mEvent.getTitle()); + + // display root trigger + mTriggerDescription.setText(mEvent.getTrigger().friendlyDescription()); + + // setup trigger click event listener + EditTriggerDialog.setOnClickListener(trigger -> { + mEvent.setTrigger(trigger); + mTriggerDescription.setText(mEvent.getTrigger().friendlyDescription()); + }); + mEditTrigger.setOnClickListener(v -> { + EditTriggerDialog dialog = EditTriggerDialog.newInstance(mEvent.getTrigger()); + dialog.show(getFragmentManager(), "EditTriggerDialog"); + }); + + // setup action list view + mActionListAdapter = new AutomationFragment.ActionListAdapter(getFragmentManager(), mEvent.getActions()); + mActionListView.setLayoutManager(new LinearLayoutManager(getContext())); + mActionListView.setAdapter(mActionListAdapter); + + // setup action click event listener + ChooseActionDialog.setOnClickListener(newActionObject -> { + mEvent.addAction(newActionObject); + mActionListAdapter.notifyDataSetChanged(); + }); + mEditAction.setOnClickListener(v -> { + ChooseActionDialog dialog = ChooseActionDialog.newInstance(); + dialog.show(getFragmentManager(), "ChooseActionDialog"); + }); + + + return view; + } + + @Override + public void onDestroyView() { + mUnbinder.unbind(); + super.onDestroyView(); + } + + @OnClick(R.id.ok) + public void onButtonOk(View view) { + // check for title + String title = mEditEventTitle.getText().toString(); + if (title.isEmpty()) { + Toast.makeText(getContext(), R.string.automation_missing_task_name, Toast.LENGTH_LONG).show(); + return; + } + mEvent.setTitle(title); + + // check for at least one trigger + TriggerConnector con = (TriggerConnector) mEvent.getTrigger(); + if (con.size() == 0) { + Toast.makeText(getContext(), R.string.automation_missing_trigger, Toast.LENGTH_LONG).show(); + return; + } + + // check for at least one action + if (mEvent.getActions().isEmpty()) { + Toast.makeText(getContext(), R.string.automation_missing_action, Toast.LENGTH_LONG).show(); + return; + } + + // apply changes + staticEvent.fromJSON(mEvent.toJSON()); + + // add new + if (mAddNew) { + final AutomationPlugin plugin = AutomationPlugin.getPlugin(); + plugin.getAutomationEvents().add(mEvent); + } + + if (mClickListener != null) mClickListener.onClick(mEvent); + dismiss(); + } + + @OnClick(R.id.cancel) + public void onButtonCancel(View view) { + dismiss(); + } + + @Override + public void onSaveInstanceState(Bundle bundle) { + bundle.putString("event", mEvent.toJSON()); + bundle.putBoolean("addNew", mAddNew); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditTriggerDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditTriggerDialog.java new file mode 100644 index 0000000000..a22ed1380c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditTriggerDialog.java @@ -0,0 +1,85 @@ +package info.nightscout.androidaps.plugins.general.automation.dialogs; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import butterknife.Unbinder; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger; + +public class EditTriggerDialog extends DialogFragment { + + public interface OnClickListener { + void onClick(Trigger newTriggerObject); + } + + private static OnClickListener mClickListener = null; + + @BindView(R.id.layoutTrigger) + LinearLayout mLayoutTrigger; + + private Trigger mTrigger; + private Unbinder mUnbinder; + + public static EditTriggerDialog newInstance(Trigger trigger) { + Bundle args = new Bundle(); + args.putString("trigger", trigger.toJSON()); + EditTriggerDialog fragment = new EditTriggerDialog(); + fragment.setArguments(args); + return fragment; + } + + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.automation_dialog_edit_trigger, container, false); + mUnbinder = ButterKnife.bind(this, view); + + // load data from bundle + Bundle bundle = savedInstanceState != null ? savedInstanceState : getArguments(); + if (bundle != null) { + String triggerData = bundle.getString("trigger"); + if (triggerData != null) mTrigger = Trigger.instantiate(triggerData); + } + + // display root trigger + mLayoutTrigger.addView(mTrigger.createView(getContext(), getFragmentManager())); + + return view; + } + + public static void setOnClickListener(OnClickListener clickListener) { + mClickListener = clickListener; + } + + @Override + public void onDestroyView() { + mUnbinder.unbind(); + super.onDestroyView(); + } + + @OnClick(R.id.ok) + public void onButtonOk(View view) { + if (mClickListener != null) + mClickListener.onClick(mTrigger); + + dismiss(); + } + + @OnClick(R.id.cancel) + public void onButtonCancel(View view) { + dismiss(); + } + + @Override + public void onSaveInstanceState(Bundle bundle) { + bundle.putString("trigger", mTrigger.toJSON()); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.java new file mode 100644 index 0000000000..bc9f49625a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.java @@ -0,0 +1,7 @@ +package info.nightscout.androidaps.plugins.general.automation.elements; + +import android.widget.LinearLayout; + +public class Element { + public void addToLayout(LinearLayout root) { } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java new file mode 100644 index 0000000000..5118528611 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java @@ -0,0 +1,87 @@ +package info.nightscout.androidaps.plugins.general.automation.elements; + +import android.text.Editable; +import android.text.TextWatcher; +import android.widget.LinearLayout; + +import java.text.DecimalFormat; + +import info.nightscout.androidaps.Constants; +import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.utils.NumberPicker; + +public class InputBg extends Element { + final private TextWatcher textWatcher = new TextWatcher() { + @Override + public void afterTextChanged(Editable s) { + // TODO: validate inputs + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + }; + + private String units; + private double value; + private final double minValue, maxValue, step; + private final DecimalFormat decimalFormat; + + public InputBg(String units) { + this.units = units; + + // set default initial value + if (units.equals(Constants.MMOL)) { + // mmol + value = 5.5; + minValue = 2; + maxValue = 30; + step = 0.1; + decimalFormat = new DecimalFormat("0.0"); + } else { + // mg/dL + value = 100; + minValue = 36; + maxValue = 540; + step = 1; + decimalFormat = new DecimalFormat("0"); + } + } + + @Override + public void addToLayout(LinearLayout root) { + NumberPicker numberPicker = new NumberPicker(root.getContext(), null); + numberPicker.setParams(0d, minValue, maxValue, step, decimalFormat, false, textWatcher); + numberPicker.setValue(value); + numberPicker.setOnValueChangedListener(value -> this.value = value); + root.addView(numberPicker); + } + + public String getUnits() { + return units; + } + + public void setUnits(String units) { + if (!this.units.equals(units)) { + String previousUnits = this.units; + this.units = units; + value = Profile.toUnits(Profile.toMgdl(value, previousUnits), Profile.toMmol(value, previousUnits), units); + } + } + + public double getValue() { + return value; + } + + public int getMgdl() { + return (int)Profile.toMgdl(value, units); + } + + public void setMgdl(int value) { + this.value = Profile.fromMgdlToUnits(value, units); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java new file mode 100644 index 0000000000..79dd19c6cd --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java @@ -0,0 +1,61 @@ +package info.nightscout.androidaps.plugins.general.automation.elements; + +import android.widget.LinearLayout; + +import java.text.DecimalFormat; + +import info.nightscout.androidaps.utils.NumberPicker; + +public class InputDuration extends Element { + public enum TimeUnit { + MINUTES, + HOURS + } + + private TimeUnit unit; + private double value; + + public InputDuration(double value, TimeUnit unit) { + this.unit = unit; + this.value = value; + } + + @Override + public void addToLayout(LinearLayout root) { + NumberPicker numberPicker = new NumberPicker(root.getContext(), null); + if (unit.equals(TimeUnit.MINUTES)) { + // Minutes + numberPicker.setParams(0d, 0d, 24 * 60d, 10d, new DecimalFormat("0"), false); + } else { + // Hours + numberPicker.setParams(0d, 0d, 24d, 1d, new DecimalFormat("0"), false); + } + numberPicker.setValue(value); + numberPicker.setOnValueChangedListener(value -> this.value = value); + root.addView(numberPicker); + } + + public TimeUnit getUnit() { + return unit; + } + + public double getValue() { + return value; + } + + public void setMinutes(double value) { + if (unit.equals(TimeUnit.MINUTES)) { + this.value = value; + } else { + this.value = value / 60d; + } + } + + public double getMinutes() { + if (unit.equals(TimeUnit.MINUTES)) { + return value; + } else { + return value * 60d; + } + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Label.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Label.java new file mode 100644 index 0000000000..45defc218e --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Label.java @@ -0,0 +1,59 @@ +package info.nightscout.androidaps.plugins.general.automation.elements; + +import android.graphics.Typeface; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import info.nightscout.androidaps.MainApp; + +public class Label extends Element { + private final Element element; + private final String textPre; + private final String textPost; + + public Label(String textPre, String textPost, Element element) { + this.element = element; + this.textPre = textPre; + this.textPost = textPost; + } + + @Override + public void addToLayout(LinearLayout root) { + // container layout + LinearLayout layout = new LinearLayout(root.getContext()); + layout.setOrientation(LinearLayout.HORIZONTAL); + layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT)); + + // text view pre element + int px = MainApp.dpToPx(10); + TextView textViewPre = new TextView(root.getContext()); + textViewPre.setText(textPre); + textViewPre.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT)); + textViewPre.setWidth(MainApp.dpToPx(120)); + textViewPre.setPadding(px, px, px, px); + textViewPre.setTypeface(textViewPre.getTypeface(), Typeface.BOLD); + layout.addView(textViewPre); + + // add element to layout + element.addToLayout(layout); + + // text view post element + if (textPost != null) { + px = MainApp.dpToPx(5); + TextView textViewPost = new TextView(root.getContext()); + textViewPost.setText(textPost); + textViewPost.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT)); + textViewPost.setWidth(MainApp.dpToPx(45)); + textViewPost.setPadding(px, px, px, px); + textViewPost.setTypeface(textViewPost.getTypeface(), Typeface.BOLD); + layout.addView(textViewPost); + } + + // add layout to root layout + root.addView(layout); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilder.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilder.java new file mode 100644 index 0000000000..c41a5ee79a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilder.java @@ -0,0 +1,22 @@ +package info.nightscout.androidaps.plugins.general.automation.elements; + +import android.widget.LinearLayout; + +import java.util.ArrayList; + +public class LayoutBuilder { + private ArrayList mElements = new ArrayList<>(); + + public LayoutBuilder add(Element element) { + mElements.add(element); + return this; + } + + public void build(LinearLayout layout) { + layout.removeAllViews(); + for(Element e : mElements) { + e.addToLayout(layout); + } + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java index 8cfa2156d9..876db6099c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java @@ -1,64 +1,142 @@ package info.nightscout.androidaps.plugins.general.automation.triggers; +import android.support.v4.app.FragmentManager; +import android.content.Context; +import android.support.annotation.StringRes; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.google.common.base.Optional; + import org.json.JSONException; import org.json.JSONObject; +import java.util.ArrayList; +import java.util.List; + +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; public abstract class Trigger { - protected static final int ISLOWER = -2; - protected static final int ISEQUALORLOWER = -1; - protected static final int ISEQUAL = 0; - protected static final int ISEQUALORGREATER = 1; - protected static final int ISGREATER = 2; + public enum Comparator { + IS_LESSER, + IS_EQUAL_OR_LESSER, + IS_EQUAL, + IS_EQUAL_OR_GREATER, + IS_GREATER, + IS_NOT_AVAILABLE; - protected static final int ISNOTAVAILABLE = 10; + public @StringRes int getStringRes() { + switch (this) { + case IS_LESSER: + return R.string.islesser; + case IS_EQUAL_OR_LESSER: + return R.string.isequalorlesser; + case IS_EQUAL: + return R.string.isequal; + case IS_EQUAL_OR_GREATER: + return R.string.isequalorgreater; + case IS_GREATER: + return R.string.isgreater; + case IS_NOT_AVAILABLE: + return R.string.isnotavailable; + default: + return R.string.unknown; + } + } + + public boolean check(T obj1, T obj2) { + if (obj1 == null || obj2 == null) + return this.equals(Comparator.IS_NOT_AVAILABLE); + + int comparison = obj1.compareTo(obj2); + switch (this) { + case IS_LESSER: + return comparison < 0; + case IS_EQUAL_OR_LESSER: + return comparison <= 0; + case IS_EQUAL: + return comparison == 0; + case IS_EQUAL_OR_GREATER: + return comparison >= 0; + case IS_GREATER: + return comparison > 0; + default: + return false; + } + } + + public static List labels() { + List list = new ArrayList<>(); + for(Comparator c : values()) { + list.add(MainApp.gs(c.getStringRes())); + } + return list; + } + } + + protected TriggerConnector connector = null; Trigger() { } - abstract boolean shouldRun(); + public TriggerConnector getConnector() { + return connector; + } - abstract String toJSON(); + public abstract boolean shouldRun(); - abstract Trigger fromJSON(String data); + public abstract String toJSON(); - abstract int friendlyName(); + /*package*/ abstract Trigger fromJSON(String data); - abstract String friendlyDescription(); + public abstract int friendlyName(); + + public abstract String friendlyDescription(); + + public abstract Optional icon(); void notifyAboutRun(long time) { } - static Trigger instantiate(JSONObject object) { + public abstract Trigger duplicate(); + + public static Trigger instantiate(String json) { + try { + return instantiate(new JSONObject(json)); + } catch (JSONException e) { + e.printStackTrace(); + } + return null; + } + + public static Trigger instantiate(JSONObject object) { try { String type = object.getString("type"); - String data = object.getString("data"); + JSONObject data = object.getJSONObject("data"); Class clazz = Class.forName(type); - return ((Trigger) clazz.newInstance()).fromJSON(data); + return ((Trigger) clazz.newInstance()).fromJSON(data.toString()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | JSONException e) { e.printStackTrace(); } return null; - } - public static int toComparatorString(int comparator) { - switch (comparator) { - case ISLOWER: - return R.string.islower; - case ISEQUALORLOWER: - return R.string.isequalorlower; - case ISEQUAL: - return R.string.isequal; - case ISEQUALORGREATER: - return R.string.isequalorgreater; - case ISGREATER: - return R.string.isgreater; - case ISNOTAVAILABLE: - return R.string.isnotavailable; - } - return R.string.unknown; + public View createView(Context context, FragmentManager fragmentManager) { + final int padding = MainApp.dpToPx(4); + + LinearLayout root = new LinearLayout(context); + root.setPadding(padding, padding, padding, padding); + root.setOrientation(LinearLayout.VERTICAL); + root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + + TextView title = new TextView(context); + title.setText(friendlyName()); + root.addView(title); + + return root; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAnd.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAnd.java deleted file mode 100644 index 3e791afcc7..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAnd.java +++ /dev/null @@ -1,87 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.List; - -import info.nightscout.androidaps.R; - -public class TriggerAnd extends Trigger { - - private List list = new ArrayList<>(); - - @Override - synchronized boolean shouldRun() { - boolean result = true; - - for (Trigger t : list) { - result = result && t.shouldRun(); - } - return result; - } - - @Override - synchronized String toJSON() { - JSONObject o = new JSONObject(); - try { - o.put("type", TriggerAnd.class.getName()); - JSONArray array = new JSONArray(); - for (Trigger t : list) { - array.put(t.toJSON()); - } - o.put("data", array.toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - return o.toString(); - } - - @Override - Trigger fromJSON(String data) { - try { - JSONArray array = new JSONArray(data); - for (int i = 0; i < array.length(); i++) { - Trigger newItem = instantiate(new JSONObject(array.getString(i))); - list.add(newItem); - } - } catch (JSONException e) { - e.printStackTrace(); - } - return this; - } - - @Override - int friendlyName() { - return R.string.and; - } - - @Override - String friendlyDescription() { - int counter = 0; - StringBuilder result = new StringBuilder(); - for (Trigger t : list) { - if (counter++ > 0) result.append(R.string.and); - result.append(t.friendlyDescription()); - } - return result.toString(); - } - - synchronized void add(Trigger t) { - list.add(t); - } - - synchronized boolean remove(Trigger t) { - return list.remove(t); - } - - int size() { - return list.size(); - } - - Trigger get(int i) { - return list.get(i); - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java index 5939502163..cd3217b414 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java @@ -1,55 +1,99 @@ package info.nightscout.androidaps.plugins.general.automation.triggers; +import android.support.v4.app.FragmentManager; +import android.content.Context; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.LinearLayout; +import android.widget.Spinner; +import android.widget.TextView; + +import com.google.common.base.Optional; + import org.json.JSONException; import org.json.JSONObject; +import java.text.DecimalFormat; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.utils.JsonHelper; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.utils.JsonHelper; +import info.nightscout.androidaps.utils.NumberPicker; public class TriggerBg extends Trigger { - double threshold; - int comparator = ISEQUAL; - String units = ProfileFunctions.getInstance().getProfileUnits(); + private double threshold = 100.0; // FIXME + private Comparator comparator = Comparator.IS_EQUAL; + private String units = ProfileFunctions.getInstance().getProfileUnits(); + + final private TextWatcher textWatcher = new TextWatcher() { + @Override + public void afterTextChanged(Editable s) { + // TODO: validate inputs + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + }; + + public TriggerBg() { + super(); + } + + private TriggerBg(TriggerBg triggerBg) { + super(); + comparator = triggerBg.comparator; + units = triggerBg.units; + threshold = triggerBg.threshold; + } + + public double getThreshold() { + return threshold; + } + + public Comparator getComparator() { + return comparator; + } + + public String getUnits() { + return units; + } @Override - synchronized boolean shouldRun() { + public synchronized boolean shouldRun() { GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); - if (glucoseStatus == null && comparator == ISNOTAVAILABLE) + if (glucoseStatus == null && comparator.equals(Comparator.IS_NOT_AVAILABLE)) return true; if (glucoseStatus == null) return false; - switch (comparator) { - case ISLOWER: - return glucoseStatus.glucose < Profile.toMgdl(threshold, units); - case ISEQUALORLOWER: - return glucoseStatus.glucose <= Profile.toMgdl(threshold, units); - case ISEQUAL: - return glucoseStatus.glucose == Profile.toMgdl(threshold, units); - case ISEQUALORGREATER: - return glucoseStatus.glucose >= Profile.toMgdl(threshold, units); - case ISGREATER: - return glucoseStatus.glucose > Profile.toMgdl(threshold, units); - } - return false; + return comparator.check(glucoseStatus.glucose, Profile.toMgdl(threshold, units)); } @Override - synchronized String toJSON() { + public synchronized String toJSON() { JSONObject o = new JSONObject(); try { o.put("type", TriggerBg.class.getName()); JSONObject data = new JSONObject(); data.put("threshold", threshold); - data.put("comparator", comparator); + data.put("comparator", comparator.toString()); data.put("units", units); - o.put("data", data.toString()); + o.put("data", data); } catch (JSONException e) { e.printStackTrace(); } @@ -61,7 +105,7 @@ public class TriggerBg extends Trigger { try { JSONObject d = new JSONObject(data); threshold = JsonHelper.safeGetDouble(d, "threshold"); - comparator = JsonHelper.safeGetInt(d, "comparator"); + comparator = Comparator.valueOf(JsonHelper.safeGetString(d, "comparator")); units = JsonHelper.safeGetString(d, "units"); } catch (JSONException e) { e.printStackTrace(); @@ -70,16 +114,26 @@ public class TriggerBg extends Trigger { } @Override - int friendlyName() { + public int friendlyName() { return R.string.glucose; } @Override - String friendlyDescription() { - if (comparator == Trigger.ISNOTAVAILABLE) + public String friendlyDescription() { + if (comparator.equals(Comparator.IS_NOT_AVAILABLE)) return MainApp.gs(R.string.glucoseisnotavailable); else - return MainApp.gs(R.string.glucosecompared, Trigger.toComparatorString(comparator), threshold, units); + return MainApp.gs(R.string.glucosecompared, MainApp.gs(comparator.getStringRes()), threshold, units); + } + + @Override + public Optional icon() { + return Optional.of(R.drawable.icon_cp_bgcheck); + } + + @Override + public Trigger duplicate() { + return new TriggerBg(this); } TriggerBg threshold(double threshold) { @@ -87,7 +141,7 @@ public class TriggerBg extends Trigger { return this; } - TriggerBg comparator(int comparator) { + TriggerBg comparator(Comparator comparator) { this.comparator = comparator; return this; } @@ -96,4 +150,59 @@ public class TriggerBg extends Trigger { this.units = units; return this; } + + @Override + public View createView(Context context, FragmentManager fragmentManager) { + LinearLayout root = (LinearLayout) super.createView(context, fragmentManager); + + // spinner for comparator + Spinner spinner = new Spinner(context); + ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, Comparator.labels()); + spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(spinnerArrayAdapter); + LinearLayout.LayoutParams spinnerParams = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT + ); + spinnerParams.setMargins(0, MainApp.dpToPx(4), 0, MainApp.dpToPx(4)); + spinner.setLayoutParams(spinnerParams); + spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + comparator = Comparator.values()[position]; + } + + @Override + public void onNothingSelected(AdapterView parent) { } + }); + spinner.setSelection(comparator.ordinal()); + root.addView(spinner); + + // horizontal layout + LinearLayout layout = new LinearLayout(context); + layout.setOrientation(LinearLayout.HORIZONTAL); + layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + root.addView(layout); + + // input field for threshold + NumberPicker numberPicker = new NumberPicker(context, null); + numberPicker.setParams(0d, 0d, (double) 500, 1d, new DecimalFormat("0"), false, textWatcher); + numberPicker.setValue(threshold); + numberPicker.setOnValueChangedListener(value -> threshold = value); + layout.addView(numberPicker); + + // text view for unit + TextView tvUnits = new TextView(context); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.MATCH_PARENT + ); + params.setMargins(MainApp.dpToPx(6), 0, 0, 0); + tvUnits.setLayoutParams(params); + tvUnits.setText(units); + tvUnits.setGravity(Gravity.CENTER_VERTICAL); + layout.addView(tvUnits); + + return root; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.java new file mode 100644 index 0000000000..28ee9b0705 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.java @@ -0,0 +1,262 @@ +package info.nightscout.androidaps.plugins.general.automation.triggers; + +import android.support.v4.app.FragmentManager; +import android.content.Context; +import android.support.annotation.StringRes; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +import com.google.common.base.Optional; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.general.automation.AutomationFragment; +import info.nightscout.androidaps.utils.JsonHelper; + +public class TriggerConnector extends Trigger { + public enum Type { + AND, + OR, + XOR; + + public boolean apply(boolean a, boolean b) { + switch (this) { + case AND: + return a && b; + case OR: + return a || b; + case XOR: + return a ^ b; + } + return false; + } + + public @StringRes int getStringRes() { + switch (this) { + case OR: + return R.string.or; + case XOR: + return R.string.xor; + + default: + case AND: + return R.string.and; + } + } + + public static List labels() { + List list = new ArrayList<>(); + for(Type t : values()) { + list.add(MainApp.gs(t.getStringRes())); + } + return list; + } + } + + public static void fillIconSet(TriggerConnector connector, HashSet set) { + for(Trigger t : connector.list) { + if (t instanceof TriggerConnector) { + fillIconSet((TriggerConnector) t, set); + } else { + Optional icon = t.icon(); + if (icon.isPresent()) { + set.add(icon.get()); + } + } + } + } + + protected List list = new ArrayList<>(); + private Type connectorType; + + public TriggerConnector() { + connectorType = Type.AND; + } + + public TriggerConnector(Type connectorType) { + this.connectorType = connectorType; + } + + public void changeConnectorType(Type type) { this.connectorType = type; } + + public Type getConnectorType() { return connectorType; } + + public synchronized void add(Trigger t) { + list.add(t); + t.connector = this; + } + + public synchronized void add(int pos, Trigger t) { + list.add(pos, t); + t.connector = this; + } + + public synchronized boolean remove(Trigger t) { + return list.remove(t); + } + + public int size() { + return list.size(); + } + + public Trigger get(int i) { + return list.get(i); + } + + public int pos(Trigger trigger) { + for(int i = 0; i < list.size(); ++i) { + if (list.get(i) == trigger) return i; + } + return -1; + } + + @Override + public synchronized boolean shouldRun() { + boolean result = true; + + // check first trigger + if (list.size() > 0) + result = list.get(0).shouldRun(); + + // check all others + for (int i = 1; i < list.size(); ++i) { + result = connectorType.apply(result, list.get(i).shouldRun()); + } + + return result; + } + + @Override + public synchronized String toJSON() { + JSONObject o = new JSONObject(); + try { + o.put("type", TriggerConnector.class.getName()); + JSONObject data = new JSONObject(); + data.put("connectorType", connectorType.toString()); + JSONArray array = new JSONArray(); + for (Trigger t : list) { + array.put(t.toJSON()); + } + data.put("triggerList", array); + o.put("data", data); + } catch (JSONException e) { + e.printStackTrace(); + } + return o.toString(); + } + + @Override + Trigger fromJSON(String data) { + try { + JSONObject d = new JSONObject(data); + connectorType = Type.valueOf(JsonHelper.safeGetString(d, "connectorType")); + JSONArray array = d.getJSONArray("triggerList"); + list.clear(); + for (int i = 0; i < array.length(); i++) { + Trigger newItem = instantiate(new JSONObject(array.getString(i))); + add(newItem); + } + } catch (JSONException e) { + e.printStackTrace(); + } + return this; + } + + @Override + public int friendlyName() { + return connectorType.getStringRes(); + } + + @Override + public String friendlyDescription() { + int counter = 0; + StringBuilder result = new StringBuilder(); + for (Trigger t : list) { + if (counter++ > 0) result.append(" " + MainApp.gs(friendlyName()) + " "); + result.append(t.friendlyDescription()); + } + return result.toString(); + } + + @Override + public Optional icon() { + return Optional.absent(); + } + + @Override + public Trigger duplicate() { + return null; + } + + private AutomationFragment.TriggerListAdapter adapter; + + public void rebuildView() { + if (adapter != null) + adapter.rebuild(); + } + + @Override + public View createView(Context context, FragmentManager fragmentManager) { + final int padding = MainApp.dpToPx(5); + + LinearLayout root = new LinearLayout(context); + root.setOrientation(LinearLayout.VERTICAL); + root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + root.setPadding(padding,padding,padding,padding); + root.setBackgroundResource(R.drawable.border_automation_unit); + + LinearLayout triggerListLayout = new LinearLayout(context); + triggerListLayout.setOrientation(LinearLayout.VERTICAL); + triggerListLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + root.addView(triggerListLayout); + + adapter = new AutomationFragment.TriggerListAdapter(context, fragmentManager, triggerListLayout, this); + + return root; + } + + public TriggerConnector simplify() { + // simplify children + for(int i = 0; i < size(); ++i) { + if (get(i) instanceof TriggerConnector) { + TriggerConnector t = (TriggerConnector) get(i); + t.simplify(); + } + } + + // drop connector with only 1 element + if (size() == 1 && get(0) instanceof TriggerConnector) { + TriggerConnector c = (TriggerConnector) get(0); + remove(c); + changeConnectorType(c.getConnectorType()); + for (Trigger t : c.list) { + add(t); + } + c.list.clear(); + return simplify(); + } + + // merge connectors + if (connector != null && (connector.getConnectorType().equals(connectorType) || size() == 1)) { + final int pos = connector.pos(this); + connector.remove(this); + // move triggers of child connector into parent connector + for (int i = size()-1; i >= 0; --i) { + connector.add(pos, get(i)); + } + list.clear(); + return connector.simplify(); + } + + return this; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerOr.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerOr.java deleted file mode 100644 index 309838b25f..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerOr.java +++ /dev/null @@ -1,87 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.List; - -import info.nightscout.androidaps.R; - -public class TriggerOr extends Trigger { - - private List list = new ArrayList<>(); - - @Override - synchronized boolean shouldRun() { - boolean result = false; - - for (Trigger t : list) { - result = result || t.shouldRun(); - } - return result; - } - - @Override - synchronized String toJSON() { - JSONObject o = new JSONObject(); - try { - o.put("type", TriggerOr.class.getName()); - JSONArray array = new JSONArray(); - for (Trigger t : list) { - array.put(t.toJSON()); - } - o.put("data", array.toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - return o.toString(); - } - - @Override - Trigger fromJSON(String data) { - try { - JSONArray array = new JSONArray(data); - for (int i = 0; i < array.length(); i++) { - Trigger newItem = instantiate(new JSONObject(array.getString(i))); - list.add(newItem); - } - } catch (JSONException e) { - e.printStackTrace(); - } - return this; - } - - @Override - int friendlyName() { - return R.string.or; - } - - @Override - String friendlyDescription() { - int counter = 0; - StringBuilder result = new StringBuilder(); - for (Trigger t : list) { - if (counter++ > 0) result.append(R.string.or); - result.append(t.friendlyDescription()); - } - return result.toString(); - } - - synchronized void add(Trigger t) { - list.add(t); - } - - synchronized boolean remove(Trigger t) { - return list.remove(t); - } - - int size() { - return list.size(); - } - - Trigger get(int i) { - return list.get(i); - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java index b5f0e6e072..faeeafcb1d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java @@ -1,39 +1,152 @@ package info.nightscout.androidaps.plugins.general.automation.triggers; +import android.support.v4.app.FragmentManager; +import android.content.Context; +import android.support.annotation.StringRes; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +import com.dpro.widgets.WeekdaysPicker; +import com.google.common.base.Optional; + import org.json.JSONException; import org.json.JSONObject; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.JsonHelper; -import info.nightscout.utils.T; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.JsonHelper; +import info.nightscout.androidaps.utils.T; public class TriggerTime extends Trigger { - long lastRun; + public enum DayOfWeek { + MONDAY, + TUESDAY, + WEDNESDAY, + THURSDAY, + FRIDAY, + SATURDAY, + SUNDAY; + + private static final int[] calendarInts = new int[] { + Calendar.MONDAY, + Calendar.TUESDAY, + Calendar.WEDNESDAY, + Calendar.THURSDAY, + Calendar.FRIDAY, + Calendar.SATURDAY, + Calendar.SUNDAY + }; + + private static final int[] fullNames = new int[] { + R.string.weekday_monday, + R.string.weekday_tuesday, + R.string.weekday_wednesday, + R.string.weekday_thursday, + R.string.weekday_friday, + R.string.weekday_saturday, + R.string.weekday_sunday + }; + + private static final int[] shortNames = new int[] { + R.string.weekday_monday_short, + R.string.weekday_tuesday_short, + R.string.weekday_wednesday_short, + R.string.weekday_thursday_short, + R.string.weekday_friday_short, + R.string.weekday_saturday_short, + R.string.weekday_sunday_short + }; + + public int toCalendarInt() { + return calendarInts[ordinal()]; + } + + public static DayOfWeek fromCalendarInt(int day) { + for(int i = 0; i < calendarInts.length; ++i) { + if (calendarInts[i] == day) + return values()[i]; + } + return null; + } + + public @StringRes int getFullName() { + return fullNames[ordinal()]; + } + + public @StringRes int getShortName() { + return shortNames[ordinal()]; + } + } + + private final boolean[] weekdays = new boolean[DayOfWeek.values().length]; + + private long lastRun; // Single execution - long runAt; + private long runAt; // Recurring - boolean recurring; - boolean monday = true; - boolean tuesday = true; - boolean wednesday = true; - boolean thursday = true; - boolean friday = true; - boolean saturday = true; - boolean sunday = true; - int hour; - int minute; + private boolean recurring; + private int hour; + private int minute; - long validTo; + private long validTo; + + public TriggerTime() { + super(); + setAll(false); + } + + private TriggerTime(TriggerTime triggerTime) { + super(); + lastRun = triggerTime.lastRun; + runAt = triggerTime.runAt; + recurring = triggerTime.recurring; + hour = triggerTime.hour; + minute = triggerTime.minute; + validTo = triggerTime.validTo; + + for(int i = 0; i < weekdays.length; ++i) { + weekdays[i] = triggerTime.weekdays[i]; + } + } + + public void setAll(boolean value) { + for(DayOfWeek day : DayOfWeek.values()) { + set(day, value); + } + } + + public TriggerTime set(DayOfWeek day, boolean value) { + weekdays[day.ordinal()] = value; + return this; + } + + public boolean isSet(DayOfWeek day) { + return weekdays[day.ordinal()]; + } + + public long getLastRun() { + return lastRun; + } + + public long getRunAt() { + return runAt; + } + + public boolean isRecurring() { + return recurring; + } @Override - boolean shouldRun() { + public boolean shouldRun() { if (recurring) { if (validTo != 0 && DateUtil.now() > validTo) return false; @@ -46,13 +159,7 @@ public class TriggerTime extends Trigger { scheduledCal.set(Calendar.SECOND, 0); long scheduled = scheduledCal.getTimeInMillis(); - if (monday && scheduledDayOfWeek == Calendar.MONDAY || - tuesday && scheduledDayOfWeek == Calendar.TUESDAY || - wednesday && scheduledDayOfWeek == Calendar.WEDNESDAY || - thursday && scheduledDayOfWeek == Calendar.THURSDAY || - friday && scheduledDayOfWeek == Calendar.FRIDAY || - saturday && scheduledDayOfWeek == Calendar.SATURDAY || - sunday && scheduledDayOfWeek == Calendar.SUNDAY) { + if (isSet(DayOfWeek.fromCalendarInt(scheduledDayOfWeek))) { if (DateUtil.now() >= scheduled && DateUtil.now() - scheduled < T.mins(5).msecs()) { if (lastRun < scheduled) return true; @@ -68,25 +175,21 @@ public class TriggerTime extends Trigger { } @Override - String toJSON() { + public String toJSON() { JSONObject object = new JSONObject(); JSONObject data = new JSONObject(); try { data.put("lastRun", lastRun); data.put("runAt", runAt); data.put("recurring", recurring); - data.put("monday", monday); - data.put("tuesday", tuesday); - data.put("wednesday", wednesday); - data.put("thursday", thursday); - data.put("friday", friday); - data.put("saturday", saturday); - data.put("sunday", sunday); + for(int i = 0; i < weekdays.length; ++i) { + data.put(DayOfWeek.values()[i].name(), weekdays[i]); + } data.put("hour", hour); data.put("minute", minute); data.put("validTo", validTo); object.put("type", TriggerTime.class.getName()); - object.put("data", data.toString()); + object.put("data", data); } catch (JSONException e) { e.printStackTrace(); } @@ -101,13 +204,9 @@ public class TriggerTime extends Trigger { lastRun = JsonHelper.safeGetLong(o, "lastRun"); runAt = JsonHelper.safeGetLong(o, "runAt"); recurring = JsonHelper.safeGetBoolean(o, "recurring"); - monday = JsonHelper.safeGetBoolean(o, "monday"); - tuesday = JsonHelper.safeGetBoolean(o, "tuesday"); - wednesday = JsonHelper.safeGetBoolean(o, "wednesday"); - thursday = JsonHelper.safeGetBoolean(o, "thursday"); - friday = JsonHelper.safeGetBoolean(o, "friday"); - saturday = JsonHelper.safeGetBoolean(o, "saturday"); - sunday = JsonHelper.safeGetBoolean(o, "sunday"); + for(int i = 0; i < weekdays.length; ++i) { + weekdays[i] = JsonHelper.safeGetBoolean(o, DayOfWeek.values()[i].name()); + } hour = JsonHelper.safeGetInt(o, "hour"); minute = JsonHelper.safeGetInt(o, "minute"); validTo = JsonHelper.safeGetLong(o, "validTo"); @@ -118,12 +217,12 @@ public class TriggerTime extends Trigger { } @Override - int friendlyName() { + public int friendlyName() { return R.string.time; } @Override - String friendlyDescription() { + public String friendlyDescription() { if (recurring) { // TODO return "Every "; @@ -132,11 +231,21 @@ public class TriggerTime extends Trigger { } } + @Override + public Optional icon() { + return Optional.of(R.drawable.ic_access_alarm_24dp); + } + @Override void notifyAboutRun(long time) { lastRun = time; } + @Override + public Trigger duplicate() { + return new TriggerTime(this); + } + TriggerTime lastRun(long lastRun) { this.lastRun = lastRun; return this; @@ -152,41 +261,6 @@ public class TriggerTime extends Trigger { return this; } - TriggerTime monday(boolean monday) { - this.monday = monday; - return this; - } - - TriggerTime tuesday(boolean tuesday) { - this.tuesday = tuesday; - return this; - } - - TriggerTime wednesday(boolean wednesday) { - this.wednesday = wednesday; - return this; - } - - TriggerTime thursday(boolean thursday) { - this.thursday = thursday; - return this; - } - - TriggerTime friday(boolean friday) { - this.friday = friday; - return this; - } - - TriggerTime saturday(boolean saturday) { - this.saturday = saturday; - return this; - } - - TriggerTime sunday(boolean sunday) { - this.sunday = sunday; - return this; - } - TriggerTime validTo(long validTo) { this.validTo = validTo; return this; @@ -202,4 +276,28 @@ public class TriggerTime extends Trigger { return this; } + private List getSelectedDays() { + List selectedDays = new ArrayList<>(); + for(int i = 0; i < weekdays.length; ++i) { + DayOfWeek day = DayOfWeek.values()[i]; + boolean selected = weekdays[i]; + if (selected) selectedDays.add(day.toCalendarInt()); + } + return selectedDays; + } + + @Override + public View createView(Context context, FragmentManager fragmentManager) { + LinearLayout root = (LinearLayout) super.createView(context, fragmentManager); + + // TODO: Replace external tool WeekdaysPicker with a self-made GUI element + WeekdaysPicker weekdaysPicker = new WeekdaysPicker(context); + weekdaysPicker.setEditable(true); + weekdaysPicker.setSelectedDays(getSelectedDays()); + weekdaysPicker.setOnWeekdaysChangeListener((view, i, list) -> set(DayOfWeek.fromCalendarInt(i), list.contains(i))); + weekdaysPicker.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + + root.addView(weekdaysPicker); + return root; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalFragment.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalFragment.java index e39480691e..991fc962ee 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Careportal; +package info.nightscout.androidaps.plugins.general.careportal; import android.app.Activity; @@ -22,12 +22,12 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.events.EventCareportalEventChange; -import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; -import info.nightscout.androidaps.plugins.Overview.OverviewFragment; -import info.nightscout.utils.FabricPrivacy; +import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus; +import info.nightscout.androidaps.plugins.general.overview.OverviewFragment; +import info.nightscout.androidaps.utils.FabricPrivacy; public class CareportalFragment extends SubscriberFragment implements View.OnClickListener { private static Logger log = LoggerFactory.getLogger(CareportalFragment.class); @@ -229,8 +229,8 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli double sageWarn = nsSettings.getExtendedWarnValue("sage", "warn", 164); handleAge(sage, CareportalEvent.SENSORCHANGE, sageWarn, sageUrgent); - double pbageUrgent = nsSettings.getExtendedWarnValue("pgage", "urgent", 360); - double pbageWarn = nsSettings.getExtendedWarnValue("pgage", "warn", 240); + double pbageUrgent = nsSettings.getExtendedWarnValue("bage", "urgent", 360); + double pbageWarn = nsSettings.getExtendedWarnValue("bage", "warn", 240); handleAge(pbage, CareportalEvent.PUMPBATTERYCHANGE, pbageWarn, pbageUrgent); } ); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalPlugin.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalPlugin.java index 22aa4686b2..fa8f87ef46 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalPlugin.java @@ -1,6 +1,5 @@ -package info.nightscout.androidaps.plugins.Careportal; +package info.nightscout.androidaps.plugins.general.careportal; -import info.nightscout.androidaps.Config; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java index 2a169dc4f3..e4eccd18d9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Careportal.Dialogs; +package info.nightscout.androidaps.plugins.general.careportal.Dialogs; import android.app.Activity; @@ -48,20 +48,20 @@ import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; -import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DefaultValueHelper; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.HardLimits; -import info.nightscout.utils.JsonHelper; -import info.nightscout.utils.NumberPicker; -import info.nightscout.utils.SP; -import info.nightscout.utils.SafeParse; -import info.nightscout.utils.Translator; +import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DefaultValueHelper; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.HardLimits; +import info.nightscout.androidaps.utils.JsonHelper; +import info.nightscout.androidaps.utils.NumberPicker; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.SafeParse; +import info.nightscout.androidaps.utils.Translator; public class NewNSTreatmentDialog extends DialogFragment implements View.OnClickListener, DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener { private static Logger log = LoggerFactory.getLogger(NewNSTreatmentDialog.class); @@ -270,7 +270,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick if (profile == null) { editBg.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false, bgTextWatcher); editTemptarget.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false); - } else if (profile.getUnits().equals(Constants.MMOL)) { + } else if (units.equals(Constants.MMOL)) { editBg.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false, bgTextWatcher); editTemptarget.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false); } else { @@ -279,7 +279,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick } sensorRadioButton.setOnCheckedChangeListener((buttonView, isChecked) -> { - Double bg1 = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, profile.getUnits()); + Double bg1 = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, units); if (savedInstanceState != null && savedInstanceState.getDouble("editBg") != bg1) { editBg.setValue(savedInstanceState.getDouble("editBg")); } else { @@ -459,7 +459,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick if ((data.size() > 0) && (data.get(0).date > millis - 7 * 60 * 1000L) && (data.get(0).date < millis + 7 * 60 * 1000L)) { - editBg.setValue(Profile.fromMgdlToUnits(data.get(0).value, profile != null ? profile.getUnits() : Constants.MGDL)); + editBg.setValue(Profile.fromMgdlToUnits(data.get(0).value, units)); } } @@ -722,7 +722,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick public void createNSTreatment(JSONObject data) { if (options.executeProfileSwitch) { if (data.has("profile")) { - doProfileSwitch(profileStore, JsonHelper.safeGetString(data, "profile"), JsonHelper.safeGetInt(data, "duration"), JsonHelper.safeGetInt(data, "percentage"), JsonHelper.safeGetInt(data, "timeshift")); + ProfileFunctions.doProfileSwitch(profileStore, JsonHelper.safeGetString(data, "profile"), JsonHelper.safeGetInt(data, "duration"), JsonHelper.safeGetInt(data, "percentage"), JsonHelper.safeGetInt(data, "timeshift")); } } else if (options.executeTempTarget) { final int duration = JsonHelper.safeGetInt(data, "duration"); @@ -736,8 +736,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick .reason(reason) .source(Source.USER); if (tempTarget.durationInMinutes != 0) { - tempTarget.low(Profile.toMgdl(targetBottom, profile.getUnits())) - .high(Profile.toMgdl(targetTop, profile.getUnits())); + tempTarget.low(Profile.toMgdl(targetBottom, units)) + .high(Profile.toMgdl(targetTop, units)); } else { tempTarget.low(0).high(0); } @@ -746,7 +746,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick } } else { if (JsonHelper.safeGetString(data, "eventType").equals(CareportalEvent.PROFILESWITCH)) { - ProfileSwitch profileSwitch = prepareProfileSwitch( + ProfileSwitch profileSwitch = ProfileFunctions.prepareProfileSwitch( profileStore, JsonHelper.safeGetString(data, "profile"), JsonHelper.safeGetInt(data, "duration"), @@ -762,46 +762,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick } } - public static ProfileSwitch prepareProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift, long date) { - ProfileSwitch profileSwitch = new ProfileSwitch(); - profileSwitch.date = date; - profileSwitch.source = Source.USER; - profileSwitch.profileName = profileName; - profileSwitch.profileJson = profileStore.getSpecificProfile(profileName).getData().toString(); - profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName(); - profileSwitch.durationInMinutes = duration; - profileSwitch.isCPP = percentage != 100 || timeshift != 0; - profileSwitch.timeshift = timeshift; - profileSwitch.percentage = percentage; - return profileSwitch; - } - - public static void doProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift) { - ProfileSwitch profileSwitch = prepareProfileSwitch(profileStore, profileName, duration, percentage, timeshift, System.currentTimeMillis()); - TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch); - FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch")); - } - - public static void doProfileSwitch(final int duration, final int percentage, final int timeshift) { - ProfileSwitch profileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(System.currentTimeMillis()); - if (profileSwitch != null) { - profileSwitch = new ProfileSwitch(); - profileSwitch.date = System.currentTimeMillis(); - profileSwitch.source = Source.USER; - profileSwitch.profileName = ProfileFunctions.getInstance().getProfileName(System.currentTimeMillis(), false); - profileSwitch.profileJson = ProfileFunctions.getInstance().getProfile().getData().toString(); - profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName(); - profileSwitch.durationInMinutes = duration; - profileSwitch.isCPP = percentage != 100 || timeshift != 0; - profileSwitch.timeshift = timeshift; - profileSwitch.percentage = percentage; - TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch); - FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch")); - } else { - log.error("No profile switch existing"); - } - } - @Override public void onSaveInstanceState(Bundle savedInstanceState) { savedInstanceState.putString("notesEdit", notesEdit.getText().toString()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/OptionsToShow.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/OptionsToShow.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/Careportal/OptionsToShow.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/OptionsToShow.java index cbdbe38940..08f65a967f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/OptionsToShow.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/OptionsToShow.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Careportal; +package info.nightscout.androidaps.plugins.general.careportal; /** * Created by mike on 05.11.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Food/Food.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/Food.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/Food/Food.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/food/Food.java index 49da1d6ac5..2396fc9e3d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Food/Food.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/Food.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Food; +package info.nightscout.androidaps.plugins.general.food; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; @@ -8,7 +8,7 @@ import org.json.JSONObject; import java.util.Objects; -import info.nightscout.utils.JsonHelper; +import info.nightscout.androidaps.utils.JsonHelper; /** * Created by mike on 20.09.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.java index 677fac5fb2..6eb55db266 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Food; +package info.nightscout.androidaps.plugins.general.food; import android.app.Activity; import android.content.DialogInterface; @@ -31,10 +31,10 @@ import java.util.Set; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventFoodDatabaseChanged; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.SpinnerHelper; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.utils.SpinnerHelper; /** * Created by mike on 16.10.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodPlugin.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodPlugin.java index 84996f1a37..e5548417a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Food; +package info.nightscout.androidaps.plugins.general.food; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PluginBase; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodService.java similarity index 99% rename from app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodService.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodService.java index b2e23dfd69..2d8d5f847b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodService.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Food; +package info.nightscout.androidaps.plugins.general.food; import android.content.Intent; import android.os.Bundle; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/ImportExportPrefs.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/ImportExportPrefs.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.java index d108382c92..67bf604f41 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/ImportExportPrefs.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.java @@ -1,10 +1,9 @@ -package info.nightscout.androidaps.plugins.Maintenance; +package info.nightscout.androidaps.plugins.general.maintenance; import android.Manifest; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.Environment; @@ -29,9 +28,8 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.utils.OKDialog; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.utils.OKDialog; +import info.nightscout.androidaps.utils.ToastUtils; /** * Created by mike on 03.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/LoggerUtils.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/LoggerUtils.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/LoggerUtils.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/LoggerUtils.java index fc1cc0362a..29eeabdf5f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/LoggerUtils.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/LoggerUtils.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Maintenance; +package info.nightscout.androidaps.plugins.general.maintenance; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenanceFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenanceFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.java index f9c00d56c7..e0e9b58253 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenanceFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Maintenance; +package info.nightscout.androidaps.plugins.general.maintenance; import android.content.Intent; import android.os.Bundle; @@ -10,9 +10,9 @@ import android.view.ViewGroup; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.Food.FoodPlugin; -import info.nightscout.androidaps.plugins.Maintenance.activities.LogSettingActivity; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.general.food.FoodPlugin; +import info.nightscout.androidaps.plugins.general.maintenance.activities.LogSettingActivity; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; /** * diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenancePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenancePlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.java index 09ab7feee1..bd5e67345d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenancePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Maintenance; +package info.nightscout.androidaps.plugins.general.maintenance; import android.content.Context; import android.content.Intent; @@ -28,8 +28,8 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus; +import info.nightscout.androidaps.utils.SP; public class MaintenancePlugin extends PluginBase { @@ -73,8 +73,8 @@ public class MaintenancePlugin extends PluginBase { } public void sendLogs() { - String recipient = SP.getString("key_maintenance_logs_email", "logs@androidaps.org"); - int amount = SP.getInt("key_maintenance_logs_amount", 2); + String recipient = SP.getString(R.string.key_maintenance_logs_email, "logs@androidaps.org"); + int amount = SP.getInt(R.string.key_maintenance_logs_amount, 2); String logDirectory = LoggerUtils.getLogDirectory(); List logs = this.getLogfiles(logDirectory, amount); @@ -103,7 +103,7 @@ public class MaintenancePlugin extends PluginBase { Arrays.sort(files, (f1, f2) -> f1.getName().compareTo(f2.getName())); List delFiles = Arrays.asList(files); - int amount = SP.getInt("key_logshipper_amount", 2); + int amount = SP.getInt(R.string.key_logshipper_amount, 2); int keepIndex = amount - 1; if (keepIndex < delFiles.size()) { @@ -213,6 +213,10 @@ public class MaintenancePlugin extends PluginBase { builder.append("ADD TIME OF EVENT HERE: " + System.lineSeparator()); builder.append("ADD ISSUE DESCRIPTION OR GITHUB ISSUE REFERENCE NUMBER: " + System.lineSeparator()); builder.append("-------------------------------------------------------" + System.lineSeparator()); + builder.append("(Please remember this will send only very recent logs." + System.lineSeparator()); + builder.append("If you want to provide logs for event older than a few hours," + System.lineSeparator()); + builder.append("you have to do it manually)" + System.lineSeparator()); + builder.append("-------------------------------------------------------" + System.lineSeparator()); builder.append(MainApp.gs(R.string.app_name) + " " + BuildConfig.VERSION + System.lineSeparator()); if (Config.NSCLIENT) builder.append("NSCLIENT" + System.lineSeparator()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/activities/LogSettingActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/activities/LogSettingActivity.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.java index 7d21d561b9..9d7681ae38 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/activities/LogSettingActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Maintenance.activities; +package info.nightscout.androidaps.plugins.general.maintenance.activities; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.java index 9eff2ca84c..dc384a7378 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal; +package info.nightscout.androidaps.plugins.general.nsclient; import android.app.Activity; @@ -20,18 +20,14 @@ import android.widget.TextView; import com.crashlytics.android.answers.CustomEvent; import com.squareup.otto.Subscribe; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.events.EventPreferenceChange; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog; -import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart; -import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientUpdateGUI; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientNewLog; +import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart; +import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.SP; public class NSClientFragment extends SubscriberFragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener { private TextView logTextView; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java index 69de5934f8..1947c5911d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal; +package info.nightscout.androidaps.plugins.general.nsclient; import android.content.ComponentName; import android.content.Context; @@ -30,12 +30,12 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog; -import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus; -import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientUpdateGUI; -import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService; -import info.nightscout.utils.SP; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientNewLog; +import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientStatus; +import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI; +import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.ToastUtils; public class NSClientPlugin extends PluginBase { private Logger log = LoggerFactory.getLogger(L.NSCLIENT); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSUpload.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSUpload.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java index 8f3f31f6e7..40a411694b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSUpload.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal; +package info.nightscout.androidaps.plugins.general.nsclient; import android.content.Context; import android.content.Intent; @@ -25,7 +25,7 @@ import java.util.Locale; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.services.Intents; import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.Profile; @@ -35,14 +35,14 @@ import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Loop.APSResult; -import info.nightscout.androidaps.plugins.Loop.DeviceStatus; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.data.DbLogger; -import info.nightscout.utils.BatteryLevel; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.aps.loop.APSResult; +import info.nightscout.androidaps.plugins.aps.loop.DeviceStatus; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.data.DbLogger; +import info.nightscout.androidaps.utils.BatteryLevel; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 26.05.2017. @@ -470,14 +470,14 @@ public class NSUpload { DbLogger.dbAdd(intent, data.toString()); } - public static void uploadBg(BgReading reading) { + public static void uploadBg(BgReading reading, String source) { Context context = MainApp.instance().getApplicationContext(); Bundle bundle = new Bundle(); bundle.putString("action", "dbAdd"); bundle.putString("collection", "entries"); JSONObject data = new JSONObject(); try { - data.put("device", "AndroidAPS-DexcomG5"); + data.put("device", source); data.put("date", reading.date); data.put("dateString", DateUtil.toISOString(reading.date)); data.put("sgv", reading.value); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NsClientReceiverDelegate.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegate.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NsClientReceiverDelegate.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegate.java index ba6ec2c80b..8eeee8c43c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NsClientReceiverDelegate.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegate.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal; +package info.nightscout.androidaps.plugins.general.nsclient; import android.content.Context; import android.content.Intent; @@ -15,7 +15,7 @@ import info.nightscout.androidaps.events.EventNetworkChange; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.receivers.ChargingStateReceiver; import info.nightscout.androidaps.receivers.NetworkChangeReceiver; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; class NsClientReceiverDelegate { @@ -48,9 +48,7 @@ class NsClientReceiverDelegate { bus.post(event); context.registerReceiver(chargingStateReceiver, - new IntentFilter(Intent.ACTION_POWER_CONNECTED)); - context.registerReceiver(chargingStateReceiver, - new IntentFilter(Intent.ACTION_POWER_DISCONNECTED)); + new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); EventChargingState eventChargingState = chargingStateReceiver.grabChargingState(context); if (eventChargingState != null) @@ -97,7 +95,7 @@ class NsClientReceiverDelegate { } void processStateChange() { - boolean newAllowedState = allowedChargingState && allowedNetworkState; + boolean newAllowedState = allowedChargingState && allowedNetworkState; if (newAllowedState != allowed) { allowed = newAllowedState; bus.post(new EventPreferenceChange(R.string.key_nsclientinternal_paused)); @@ -109,7 +107,9 @@ class NsClientReceiverDelegate { boolean newAllowedState = true; - if (!ev.isCharging && chargingOnly) newAllowedState = false; + if (!ev.isCharging && chargingOnly) { + newAllowedState = false; + } return newAllowedState; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java index 9c0284029c..c2bb0d21ab 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal; +package info.nightscout.androidaps.plugins.general.nsclient; import android.content.Context; import android.content.Intent; @@ -17,7 +17,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DbRequest; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService; +import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService; /** * Created by mike on 21.02.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAddAck.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAddAck.java index ed9c4c3013..ead373d61d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAddAck.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.acks; +package info.nightscout.androidaps.plugins.general.nsclient.acks; import org.json.JSONArray; import org.json.JSONObject; @@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart; +import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart; import io.socket.client.Ack; /** diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAuthAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAuthAck.java similarity index 81% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAuthAck.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAuthAck.java index 56055351d9..62c1cf7f5d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAuthAck.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAuthAck.java @@ -1,10 +1,9 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.acks; +package info.nightscout.androidaps.plugins.general.nsclient.acks; import org.json.JSONObject; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.events.Event; -import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog; import io.socket.client.Ack; /** diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSUpdateAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSUpdateAck.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSUpdateAck.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSUpdateAck.java index 42534387b2..68ce3d9a37 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSUpdateAck.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSUpdateAck.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.acks; +package info.nightscout.androidaps.plugins.general.nsclient.acks; import org.json.JSONException; import org.json.JSONObject; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAckAlarm.java similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAckAlarm.java index f94f9e51aa..6873b59515 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAckAlarm.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts; +package info.nightscout.androidaps.plugins.general.nsclient.broadcasts; import android.content.Context; import android.content.Intent; @@ -8,8 +8,8 @@ import android.support.v4.content.LocalBroadcastManager; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.services.Intents; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSAlarm; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 11.06.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAlarm.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAlarm.java index 8f75d92365..9c1e3e7ae2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAlarm.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts; +package info.nightscout.androidaps.plugins.general.nsclient.broadcasts; import android.content.Context; import android.content.Intent; @@ -10,7 +10,7 @@ import org.json.JSONObject; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.services.Intents; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 26.06.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAnnouncement.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAnnouncement.java index 5e1b01f225..b26c055851 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAnnouncement.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts; +package info.nightscout.androidaps.plugins.general.nsclient.broadcasts; import android.content.Context; import android.content.Intent; @@ -10,7 +10,7 @@ import org.json.JSONObject; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.services.Intents; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 26.06.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastCals.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastCals.java index 4e49785f82..7d5dcddadc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastCals.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts; +package info.nightscout.androidaps.plugins.general.nsclient.broadcasts; import android.content.Context; import android.content.Intent; @@ -10,7 +10,7 @@ import org.json.JSONArray; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.services.Intents; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 26.06.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastClearAlarm.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastClearAlarm.java index e6fec32ffa..fe9a194ca2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastClearAlarm.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts; +package info.nightscout.androidaps.plugins.general.nsclient.broadcasts; import android.content.Context; import android.content.Intent; @@ -10,7 +10,7 @@ import org.json.JSONObject; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.services.Intents; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 26.06.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastDeviceStatus.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastDeviceStatus.java index 4915608673..412c321817 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastDeviceStatus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts; +package info.nightscout.androidaps.plugins.general.nsclient.broadcasts; import android.content.Context; import android.content.Intent; @@ -12,7 +12,7 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.services.Intents; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; public class BroadcastDeviceStatus { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastFood.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastFood.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastFood.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastFood.java index f38141ec6d..0a8c21251b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastFood.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastFood.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts; +package info.nightscout.androidaps.plugins.general.nsclient.broadcasts; import android.content.Context; import android.content.Intent; @@ -12,7 +12,7 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.services.Intents; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 20.02.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastMbgs.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastMbgs.java index e91c3e2fd6..9c059ae8a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastMbgs.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts; +package info.nightscout.androidaps.plugins.general.nsclient.broadcasts; import android.content.Context; import android.content.Intent; @@ -10,7 +10,7 @@ import org.json.JSONArray; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.services.Intents; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 26.06.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastProfile.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastProfile.java index 6bd6bbc81a..9411ed6e9e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastProfile.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts; +package info.nightscout.androidaps.plugins.general.nsclient.broadcasts; import android.content.Context; import android.content.Intent; @@ -9,7 +9,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.services.Intents; import info.nightscout.androidaps.data.ProfileStore; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastSgvs.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastSgvs.java index dea4cf8713..04e957811d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastSgvs.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts; +package info.nightscout.androidaps.plugins.general.nsclient.broadcasts; import android.content.Context; import android.content.Intent; @@ -12,7 +12,7 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.services.Intents; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 22.02.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastStatus.java similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastStatus.java index a0e8607efc..c037acc9bb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastStatus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts; +package info.nightscout.androidaps.plugins.general.nsclient.broadcasts; import android.content.Context; import android.content.Intent; @@ -13,9 +13,9 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.services.Intents; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; -import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus; +import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 24.02.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastTreatment.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastTreatment.java index 4f36d85348..e4ca7b577f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastTreatment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts; +package info.nightscout.androidaps.plugins.general.nsclient.broadcasts; import android.content.Intent; import android.os.Bundle; @@ -17,7 +17,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.services.Intents; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 20.02.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastUrgentAlarm.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastUrgentAlarm.java index c8988141d7..676dbe909d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastUrgentAlarm.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts; +package info.nightscout.androidaps.plugins.general.nsclient.broadcasts; import android.content.Context; import android.content.Intent; @@ -10,7 +10,7 @@ import org.json.JSONObject; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.services.Intents; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 26.06.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/AlarmAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/AlarmAck.java similarity index 72% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/AlarmAck.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/AlarmAck.java index 109331b34b..06fc06e943 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/AlarmAck.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/AlarmAck.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.data; +package info.nightscout.androidaps.plugins.general.nsclient.data; /** * Created by mike on 11.06.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbLogger.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/DbLogger.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbLogger.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/DbLogger.java index ec31141002..3aaf4ccac4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbLogger.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/DbLogger.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.data; +package info.nightscout.androidaps.plugins.general.nsclient.data; import android.content.Intent; import android.content.pm.ResolveInfo; @@ -11,7 +11,7 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.utils.ToastUtils; /** * Created by mike on 02.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSAlarm.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSAlarm.java index 7ad82220da..305a09d560 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSAlarm.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.data; +package info.nightscout.androidaps.plugins.general.nsclient.data; import org.json.JSONException; import org.json.JSONObject; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSCal.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSCal.java index 83fe44073e..b3e59d9448 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSCal.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.data; +package info.nightscout.androidaps.plugins.general.nsclient.data; import org.json.JSONException; import org.json.JSONObject; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.java index b48319f979..b2539a716e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.data; +package info.nightscout.androidaps.plugins.general.nsclient.data; import android.content.Intent; import android.os.Bundle; @@ -18,12 +18,12 @@ import java.util.Map; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; -import info.nightscout.androidaps.plugins.Loop.APSResult; +import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin; +import info.nightscout.androidaps.plugins.aps.loop.APSResult; import info.nightscout.androidaps.logging.BundleLogger; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.Round; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.Round; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 25.06.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSMbg.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSMbg.java index cd4cd9cdba..9e3475c27e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSMbg.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.data; +package info.nightscout.androidaps.plugins.general.nsclient.data; import org.json.JSONException; import org.json.JSONObject; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSettingsStatus.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSettingsStatus.java index dc3c9f742e..8511247e42 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSettingsStatus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.data; +package info.nightscout.androidaps.plugins.general.nsclient.data; import android.content.Intent; import android.content.pm.PackageManager; @@ -17,10 +17,10 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; +import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.logging.BundleLogger; /* diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSgv.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSgv.java index 2212884a3e..391b363d99 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSgv.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.data; +package info.nightscout.androidaps.plugins.general.nsclient.data; import org.json.JSONException; import org.json.JSONObject; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSTreatment.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSTreatment.java index d4ee20e2a1..39491445a0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSTreatment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.data; +package info.nightscout.androidaps.plugins.general.nsclient.data; import org.json.JSONException; import org.json.JSONObject; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientNewLog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientNewLog.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientNewLog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientNewLog.java index 82b11a812d..121085cb94 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientNewLog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientNewLog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.events; +package info.nightscout.androidaps.plugins.general.nsclient.events; import java.text.SimpleDateFormat; import java.util.Date; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientRestart.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientRestart.java similarity index 69% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientRestart.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientRestart.java index b968878da8..b5481ce741 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientRestart.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientRestart.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.events; +package info.nightscout.androidaps.plugins.general.nsclient.events; import info.nightscout.androidaps.events.Event; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientStatus.java similarity index 82% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientStatus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientStatus.java index 977c0e31fc..c3bf74321c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientStatus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.events; +package info.nightscout.androidaps.plugins.general.nsclient.events; import info.nightscout.androidaps.events.Event; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientUpdateGUI.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientUpdateGUI.java similarity index 72% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientUpdateGUI.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientUpdateGUI.java index dd78d2cd28..60d74a249d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientUpdateGUI.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientUpdateGUI.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.events; +package info.nightscout.androidaps.plugins.general.nsclient.events; import info.nightscout.androidaps.events.EventUpdateGui; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AckAlarmReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/AckAlarmReceiver.java similarity index 87% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AckAlarmReceiver.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/AckAlarmReceiver.java index f23533e9ab..7185072692 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AckAlarmReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/AckAlarmReceiver.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.receivers; +package info.nightscout.androidaps.plugins.general.nsclient.receivers; import android.content.BroadcastReceiver; import android.content.Context; @@ -13,10 +13,10 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck; -import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.data.AlarmAck; +import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService; +import info.nightscout.androidaps.utils.SP; public class AckAlarmReceiver extends BroadcastReceiver { private static Logger log = LoggerFactory.getLogger(L.NSCLIENT); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AutoStartReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/AutoStartReceiver.java similarity index 75% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AutoStartReceiver.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/AutoStartReceiver.java index dd5d3330ab..e91e203175 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AutoStartReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/AutoStartReceiver.java @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.receivers; +package info.nightscout.androidaps.plugins.general.nsclient.receivers; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService; +import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService; public class AutoStartReceiver extends BroadcastReceiver { public AutoStartReceiver() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/DBAccessReceiver.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/DBAccessReceiver.java index 896382d818..4d8b7eba2a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/DBAccessReceiver.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.receivers; +package info.nightscout.androidaps.plugins.general.nsclient.receivers; import android.content.BroadcastReceiver; import android.content.Context; @@ -17,11 +17,11 @@ import info.nightscout.androidaps.db.DbRequest; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.BundleLogger; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; -import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastTreatment; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue; +import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastTreatment; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; public class DBAccessReceiver extends BroadcastReceiver { private static Logger log = LoggerFactory.getLogger(L.NSCLIENT); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/RestartReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/RestartReceiver.java similarity index 73% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/RestartReceiver.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/RestartReceiver.java index a38ca842f9..0b221ee456 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/RestartReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/RestartReceiver.java @@ -1,13 +1,12 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.receivers; +package info.nightscout.androidaps.plugins.general.nsclient.receivers; -import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.v4.content.WakefulBroadcastReceiver; import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart; -import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService; +import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart; +import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService; public class RestartReceiver extends WakefulBroadcastReceiver { public RestartReceiver() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java index 2066aaa423..359c224158 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.services; +package info.nightscout.androidaps.plugins.general.nsclient.services; import android.app.Service; import android.content.Context; @@ -35,39 +35,39 @@ import info.nightscout.androidaps.events.EventConfigBuilderChange; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; -import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSAddAck; -import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSAuthAck; -import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSUpdateAck; -import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastAlarm; -import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastAnnouncement; -import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastCals; -import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastClearAlarm; -import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastDeviceStatus; -import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastFood; -import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastMbgs; -import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastProfile; -import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastSgvs; -import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastStatus; -import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastTreatment; -import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastUrgentAlarm; -import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment; -import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog; -import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart; -import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus; -import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientUpdateGUI; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.JsonHelper; -import info.nightscout.utils.SP; -import info.nightscout.utils.T; +import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue; +import info.nightscout.androidaps.plugins.general.nsclient.acks.NSAddAck; +import info.nightscout.androidaps.plugins.general.nsclient.acks.NSAuthAck; +import info.nightscout.androidaps.plugins.general.nsclient.acks.NSUpdateAck; +import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastAlarm; +import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastAnnouncement; +import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastCals; +import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastClearAlarm; +import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastDeviceStatus; +import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastFood; +import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastMbgs; +import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastProfile; +import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastSgvs; +import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastStatus; +import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastTreatment; +import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastUrgentAlarm; +import info.nightscout.androidaps.plugins.general.nsclient.data.AlarmAck; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSSgv; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSTreatment; +import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientNewLog; +import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart; +import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientStatus; +import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.JsonHelper; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.T; import io.socket.client.IO; import io.socket.client.Socket; import io.socket.emitter.Emitter; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/BolusProgressDialog.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/BolusProgressDialog.java index 1baac9a694..6cb5a1bc82 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/BolusProgressDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.Dialogs; +package info.nightscout.androidaps.plugins.general.overview.Dialogs; import android.app.Activity; @@ -21,9 +21,9 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; -import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusprogressIfRunning; +import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; public class BolusProgressDialog extends DialogFragment implements View.OnClickListener { private static Logger log = LoggerFactory.getLogger(L.UI); @@ -107,9 +107,9 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL @Override public void onPause() { + running = false; super.onPause(); MainApp.unsubscribe(this); - running = false; if (L.isEnabled(L.UI)) log.debug("onPause"); } @@ -173,10 +173,12 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL Activity activity = getActivity(); if (activity != null) { activity.runOnUiThread(() -> { - if (L.isEnabled(L.UI)) - log.debug("executing"); try { - dismiss(); + if (running) { + if (L.isEnabled(L.UI)) + log.debug("executing"); + dismiss(); + } } catch (Exception e) { log.error("Unhandled exception", e); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressHelperActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/BolusProgressHelperActivity.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressHelperActivity.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/BolusProgressHelperActivity.java index 6fddc218ac..b0bc7e96f5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressHelperActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/BolusProgressHelperActivity.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.Dialogs; +package info.nightscout.androidaps.plugins.general.overview.Dialogs; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/CalibrationDialog.java similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/CalibrationDialog.java index f1f62c0bc4..b950414237 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/CalibrationDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.Dialogs; +package info.nightscout.androidaps.plugins.general.overview.Dialogs; import android.content.Context; @@ -19,15 +19,14 @@ import org.slf4j.LoggerFactory; import java.text.DecimalFormat; import info.nightscout.androidaps.Constants; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.NumberPicker; -import info.nightscout.utils.SafeParse; -import info.nightscout.utils.XdripCalibrations; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.NumberPicker; +import info.nightscout.androidaps.utils.SafeParse; +import info.nightscout.androidaps.utils.XdripCalibrations; public class CalibrationDialog extends DialogFragment implements View.OnClickListener { private static Logger log = LoggerFactory.getLogger(CalibrationDialog.class); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/EditQuickWizardDialog.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/EditQuickWizardDialog.java index 50de25b656..053337e356 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/EditQuickWizardDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.Dialogs; +package info.nightscout.androidaps.plugins.general.overview.Dialogs; import android.os.Bundle; @@ -22,10 +22,10 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.QuickWizard; import info.nightscout.androidaps.data.QuickWizardEntry; -import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; -import info.nightscout.androidaps.plugins.Overview.events.EventQuickWizardChange; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.SafeParse; +import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventQuickWizardChange; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SafeParse; public class EditQuickWizardDialog extends DialogFragment implements View.OnClickListener { private static Logger log = LoggerFactory.getLogger(EditQuickWizardDialog.class); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/ErrorDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/ErrorDialog.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/ErrorDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/ErrorDialog.java index dc4fa21aca..549653f400 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/ErrorDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/ErrorDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.Dialogs; +package info.nightscout.androidaps.plugins.general.overview.Dialogs; import android.content.Intent; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/ErrorHelperActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/ErrorHelperActivity.java similarity index 83% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/ErrorHelperActivity.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/ErrorHelperActivity.java index c556a6c844..1107cf1a9f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/ErrorHelperActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/ErrorHelperActivity.java @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.plugins.Overview.Dialogs; +package info.nightscout.androidaps.plugins.general.overview.Dialogs; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.utils.SP; public class ErrorHelperActivity extends AppCompatActivity { public ErrorHelperActivity() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewCarbsDialog.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewCarbsDialog.java index 40450adf77..44d13fa570 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewCarbsDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.Dialogs; +package info.nightscout.androidaps.plugins.general.overview.Dialogs; import android.os.Bundle; import android.os.HandlerThread; @@ -21,8 +21,8 @@ import android.widget.RadioButton; import com.google.common.base.Joiner; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,16 +40,16 @@ import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.Constraint; -import info.nightscout.androidaps.plugins.Treatments.CarbsGenerator; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.DefaultValueHelper; -import info.nightscout.utils.NumberPicker; -import info.nightscout.utils.SP; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.plugins.treatments.CarbsGenerator; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.DefaultValueHelper; +import info.nightscout.androidaps.utils.NumberPicker; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.ToastUtils; -import static info.nightscout.utils.DateUtil.now; +import static info.nightscout.androidaps.utils.DateUtil.now; public class NewCarbsDialog extends DialogFragment implements OnClickListener, CompoundButton.OnCheckedChangeListener { private static Logger log = LoggerFactory.getLogger(NewCarbsDialog.class); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewInsulinDialog.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewInsulinDialog.java index 8545858d4e..f326805ba2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewInsulinDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.Dialogs; +package info.nightscout.androidaps.plugins.general.overview.Dialogs; import android.content.Context; import android.content.Intent; @@ -40,20 +40,20 @@ import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.NumberPicker; -import info.nightscout.utils.SP; -import info.nightscout.utils.SafeParse; -import info.nightscout.utils.T; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.NumberPicker; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.SafeParse; +import info.nightscout.androidaps.utils.T; +import info.nightscout.androidaps.utils.ToastUtils; -import static info.nightscout.utils.DateUtil.now; +import static info.nightscout.androidaps.utils.DateUtil.now; public class NewInsulinDialog extends DialogFragment implements OnClickListener { private static Logger log = LoggerFactory.getLogger(NewInsulinDialog.class); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewTreatmentDialog.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewTreatmentDialog.java index b1a8bf172a..b5e7b1dd74 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewTreatmentDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.Dialogs; +package info.nightscout.androidaps.plugins.general.overview.Dialogs; import android.content.Context; import android.content.DialogInterface; @@ -32,14 +32,14 @@ import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.NumberPicker; -import info.nightscout.utils.SafeParse; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.NumberPicker; +import info.nightscout.androidaps.utils.SafeParse; +import info.nightscout.androidaps.utils.ToastUtils; public class NewTreatmentDialog extends DialogFragment implements OnClickListener { private static Logger log = LoggerFactory.getLogger(NewTreatmentDialog.class); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/WizardDialog.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/WizardDialog.java index 1b6a4f2ff8..33b3019668 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/WizardDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.Dialogs; +package info.nightscout.androidaps.plugins.general.overview.Dialogs; import android.app.Activity; import android.content.Context; @@ -51,27 +51,26 @@ import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.events.EventFeatureRunning; -import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.BolusWizard; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.NumberPicker; -import info.nightscout.utils.SP; -import info.nightscout.utils.SafeParse; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.utils.BolusWizard; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.NumberPicker; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.SafeParse; +import info.nightscout.androidaps.utils.ToastUtils; public class WizardDialog extends DialogFragment implements OnClickListener, CompoundButton.OnCheckedChangeListener, Spinner.OnItemSelectedListener { private static Logger log = LoggerFactory.getLogger(WizardDialog.class); @@ -165,18 +164,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com } - @Subscribe - public void onStatusEvent(final EventNewBG e) { - Activity activity = getActivity(); - if (activity != null) - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - calculateInsulin(); - } - }); - } - @Subscribe public void onStatusEvent(final EventAutosensCalculationFinished e) { Activity activity = getActivity(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java similarity index 86% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java index a414d38310..59d3e50728 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java @@ -1,8 +1,9 @@ -package info.nightscout.androidaps.plugins.Overview; +package info.nightscout.androidaps.plugins.general.overview; import android.annotation.SuppressLint; import android.app.Activity; import android.app.NotificationManager; +import android.arch.core.util.Function; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; @@ -82,50 +83,52 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; -import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; -import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; -import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventIobCalculationProgress; -import info.nightscout.androidaps.plugins.Loop.APSResult; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus; -import info.nightscout.androidaps.plugins.Overview.Dialogs.CalibrationDialog; -import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; -import info.nightscout.androidaps.plugins.Overview.Dialogs.NewCarbsDialog; -import info.nightscout.androidaps.plugins.Overview.Dialogs.NewInsulinDialog; -import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog; -import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog; -import info.nightscout.androidaps.plugins.Overview.activities.QuickWizardListActivity; -import info.nightscout.androidaps.plugins.Overview.graphData.GraphData; -import info.nightscout.androidaps.plugins.Overview.notifications.NotificationRecyclerViewAdapter; -import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore; -import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin; -import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog; -import info.nightscout.androidaps.plugins.Wear.ActionStringHandler; +import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment; +import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog; +import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress; +import info.nightscout.androidaps.plugins.aps.loop.APSResult; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.CalibrationDialog; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.NewCarbsDialog; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.NewInsulinDialog; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.NewTreatmentDialog; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.WizardDialog; +import info.nightscout.androidaps.plugins.general.overview.activities.QuickWizardListActivity; +import info.nightscout.androidaps.plugins.general.overview.graphData.GraphData; +import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationRecyclerViewAdapter; +import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore; +import info.nightscout.androidaps.plugins.source.SourceDexcomG5Plugin; +import info.nightscout.androidaps.plugins.source.SourceDexcomG6Plugin; +import info.nightscout.androidaps.plugins.source.SourceXdripPlugin; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.treatments.fragments.ProfileViewerDialog; +import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler; import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.BolusWizard; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.DefaultValueHelper; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.OKDialog; -import info.nightscout.utils.Profiler; -import info.nightscout.utils.SP; -import info.nightscout.utils.SingleClickButton; -import info.nightscout.utils.T; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.utils.BolusWizard; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.DefaultValueHelper; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.OKDialog; +import info.nightscout.androidaps.utils.Profiler; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.SingleClickButton; +import info.nightscout.androidaps.utils.T; +import info.nightscout.androidaps.utils.ToastUtils; -import static info.nightscout.utils.DateUtil.now; +import static info.nightscout.androidaps.utils.DateUtil.now; public class OverviewFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener { private static Logger log = LoggerFactory.getLogger(L.OVERVIEW); @@ -162,6 +165,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, TextView sage; TextView pbage; + TextView iageView; + TextView cageView; + TextView reservoirView; + TextView sageView; + TextView batteryView; + LinearLayout statuslightsLayout; + RecyclerView notificationsView; LinearLayoutManager llm; @@ -258,8 +268,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sage = (TextView) view.findViewById(R.id.careportal_sensorage); pbage = (TextView) view.findViewById(R.id.careportal_pbage); - bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph); - iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph); + iageView = (TextView) view.findViewById(R.id.overview_insulinage); + cageView = (TextView) view.findViewById(R.id.overview_canulaage); + reservoirView = (TextView) view.findViewById(R.id.overview_reservoirlevel); + sageView = (TextView) view.findViewById(R.id.overview_sensorage); + batteryView = (TextView) view.findViewById(R.id.overview_batterylevel); + statuslightsLayout = (LinearLayout) view.findViewById(R.id.overview_statuslights); + + bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph); + iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph); treatmentButton = (SingleClickButton) view.findViewById(R.id.overview_treatmentbutton); treatmentButton.setOnClickListener(this); @@ -446,7 +463,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, super.onCreateContextMenu(menu, v, menuInfo); if (v == apsModeView) { final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); - final PumpDescription pumpDescription = ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription(); + final PumpDescription pumpDescription = + ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription(); if (!ProfileFunctions.getInstance().isProfileValid("ContexMenuCreation")) return; menu.setHeaderTitle(MainApp.gs(R.string.loop)); @@ -457,19 +475,23 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, menu.add(MainApp.gs(R.string.suspendloopfor2h)); menu.add(MainApp.gs(R.string.suspendloopfor3h)); menu.add(MainApp.gs(R.string.suspendloopfor10h)); - if (pumpDescription.tempDurationStep15mAllowed) - menu.add(MainApp.gs(R.string.disconnectpumpfor15m)); - if (pumpDescription.tempDurationStep30mAllowed) - menu.add(MainApp.gs(R.string.disconnectpumpfor30m)); - menu.add(MainApp.gs(R.string.disconnectpumpfor1h)); - menu.add(MainApp.gs(R.string.disconnectpumpfor2h)); - menu.add(MainApp.gs(R.string.disconnectpumpfor3h)); - } else { - menu.add(MainApp.gs(R.string.resume)); + } else { + if (!loopPlugin.isDisconnected()) { + menu.add(MainApp.gs(R.string.resume)); + } } } - if (!loopPlugin.isEnabled(PluginType.LOOP)) + + if (!loopPlugin.isEnabled(PluginType.LOOP)) { menu.add(MainApp.gs(R.string.enableloop)); + } + + if (!loopPlugin.isDisconnected()) { + showSuspendtPump(menu, pumpDescription); + } else { + menu.add(MainApp.gs(R.string.reconnect)); + } + } else if (v == activeProfileView) { menu.setHeaderTitle(MainApp.gs(R.string.profile)); menu.add(MainApp.gs(R.string.danar_viewprofile)); @@ -488,6 +510,17 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } } + private void showSuspendtPump(ContextMenu menu, + PumpDescription pumpDescription) { + if (pumpDescription.tempDurationStep15mAllowed) + menu.add(MainApp.gs(R.string.disconnectpumpfor15m)); + if (pumpDescription.tempDurationStep30mAllowed) + menu.add(MainApp.gs(R.string.disconnectpumpfor30m)); + menu.add(MainApp.gs(R.string.disconnectpumpfor1h)); + menu.add(MainApp.gs(R.string.disconnectpumpfor2h)); + menu.add(MainApp.gs(R.string.disconnectpumpfor3h)); + } + @Override public boolean onContextItemSelected(MenuItem item) { final Profile profile = ProfileFunctions.getInstance().getProfile(); @@ -516,7 +549,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, updateGUI("suspendmenu"); NSUpload.uploadOpenAPSOffline(0); return true; - } else if (item.getTitle().equals(MainApp.gs(R.string.resume))) { + } else if (item.getTitle().equals(MainApp.gs(R.string.resume)) || + item.getTitle().equals(MainApp.gs(R.string.reconnect))) { loopPlugin.suspendTo(0L); updateGUI("suspendmenu"); ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, new Callback() { @@ -631,6 +665,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, public void onClick(View v) { boolean xdrip = SourceXdripPlugin.getPlugin().isEnabled(PluginType.BGSOURCE); boolean g5 = SourceDexcomG5Plugin.getPlugin().isEnabled(PluginType.BGSOURCE); + boolean g6 = SourceDexcomG6Plugin.getPlugin().isEnabled(PluginType.BGSOURCE); String units = ProfileFunctions.getInstance().getProfileUnits(); FragmentManager manager = getFragmentManager(); @@ -653,7 +688,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, if (xdrip) { CalibrationDialog calibrationDialog = new CalibrationDialog(); calibrationDialog.show(manager, "CalibrationDialog"); - } else if (g5) { + } else if (g5 || g6) { try { Intent i = new Intent("com.dexcom.cgm.activities.MeterEntryActivity"); startActivity(i); @@ -669,6 +704,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, openCgmApp("com.dexcom.cgm.region5.mgdl"); else if (g5 && units.equals(Constants.MMOL)) openCgmApp("com.dexcom.cgm.region5.mmol"); + else if (g6 && units.equals(Constants.MGDL)) + openCgmApp("com.dexcom.g6.region3.mgdl"); + else if (g6 && units.equals(Constants.MMOL)) + openCgmApp("com.dexcom.g6.region3.mmol"); break; case R.id.overview_treatmentbutton: NewTreatmentDialog treatmentDialogFragment = new NewTreatmentDialog(); @@ -784,7 +823,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, confirmMessage += "\n" + MainApp.gs(R.string.bolus) + ": " + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U"; confirmMessage += "\n" + MainApp.gs(R.string.carbs) + ": " + carbsAfterConstraints + "g"; - if (!insulinAfterConstraints.equals(wizard.calculatedTotalInsulin) || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) { + if (Math.abs(insulinAfterConstraints - wizard.calculatedTotalInsulin) >= 0.01 || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setTitle(MainApp.gs(R.string.treatmentdeliveryerror)); builder.setMessage(MainApp.gs(R.string.constraints_violation) + "\n" + MainApp.gs(R.string.changeyourinput)); @@ -808,7 +847,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, return; } accepted = true; - if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) { + if (Math.abs(insulinAfterConstraints - wizard.calculatedTotalInsulin) >= 0.01 || finalCarbsAfterConstraints > 0) { if (wizard.superBolus) { final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); if (loopPlugin.isEnabled(PluginType.LOOP)) { @@ -1088,25 +1127,25 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun; if (Config.APS && pump.getPumpDescription().isTempBasalCapable) { apsModeView.setVisibility(View.VISIBLE); - apsModeView.setBackgroundColor(MainApp.gc(R.color.loopenabled)); - apsModeView.setTextColor(Color.BLACK); + apsModeView.setBackgroundColor(MainApp.gc(R.color.ribbonDefault)); + apsModeView.setTextColor(MainApp.gc(R.color.ribbonTextDefault)); final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); if (loopPlugin.isEnabled(PluginType.LOOP) && loopPlugin.isSuperBolus()) { - apsModeView.setBackgroundColor(MainApp.gc(R.color.looppumpsuspended)); + apsModeView.setBackgroundColor(MainApp.gc(R.color.ribbonWarning)); apsModeView.setText(String.format(MainApp.gs(R.string.loopsuperbolusfor), loopPlugin.minutesToEndOfSuspend())); - apsModeView.setTextColor(Color.WHITE); - } else if (loopPlugin.isEnabled(PluginType.LOOP) && loopPlugin.isDisconnected()) { - apsModeView.setBackgroundColor(MainApp.gc(R.color.looppumpsuspended)); + apsModeView.setTextColor(MainApp.gc(R.color.ribbonTextWarning)); + } else if (loopPlugin.isDisconnected()) { + apsModeView.setBackgroundColor(MainApp.gc(R.color.ribbonCritical)); apsModeView.setText(String.format(MainApp.gs(R.string.loopdisconnectedfor), loopPlugin.minutesToEndOfSuspend())); - apsModeView.setTextColor(Color.WHITE); + apsModeView.setTextColor(MainApp.gc(R.color.ribbonTextCritical)); } else if (loopPlugin.isEnabled(PluginType.LOOP) && loopPlugin.isSuspended()) { - apsModeView.setBackgroundColor(MainApp.gc(R.color.looppumpsuspended)); + apsModeView.setBackgroundColor(MainApp.gc(R.color.ribbonWarning)); apsModeView.setText(String.format(MainApp.gs(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend())); - apsModeView.setTextColor(Color.WHITE); + apsModeView.setTextColor(MainApp.gc(R.color.ribbonTextWarning)); } else if (pump.isSuspended()) { - apsModeView.setBackgroundColor(MainApp.gc(R.color.looppumpsuspended)); + apsModeView.setBackgroundColor(MainApp.gc(R.color.ribbonWarning)); apsModeView.setText(MainApp.gs(R.string.pumpsuspended)); - apsModeView.setTextColor(Color.WHITE); + apsModeView.setTextColor(MainApp.gc(R.color.ribbonTextWarning)); } else if (loopPlugin.isEnabled(PluginType.LOOP)) { if (closedLoopEnabled.value()) { apsModeView.setText(MainApp.gs(R.string.closedloop)); @@ -1114,9 +1153,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, apsModeView.setText(MainApp.gs(R.string.openloop)); } } else { - apsModeView.setBackgroundColor(MainApp.gc(R.color.loopdisabled)); + apsModeView.setBackgroundColor(MainApp.gc(R.color.ribbonCritical)); apsModeView.setText(MainApp.gs(R.string.disabledloop)); - apsModeView.setTextColor(Color.WHITE); + apsModeView.setTextColor(MainApp.gc(R.color.ribbonTextCritical)); } } else { apsModeView.setVisibility(View.GONE); @@ -1125,13 +1164,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, // temp target TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(); if (tempTarget != null) { - tempTargetView.setTextColor(Color.BLACK); - tempTargetView.setBackgroundColor(MainApp.gc(R.color.tempTargetBackground)); + tempTargetView.setTextColor(MainApp.gc(R.color.ribbonTextWarning)); + tempTargetView.setBackgroundColor(MainApp.gc(R.color.ribbonWarning)); tempTargetView.setVisibility(View.VISIBLE); tempTargetView.setText(Profile.toTargetRangeString(tempTarget.low, tempTarget.high, Constants.MGDL, units) + " " + DateUtil.untilString(tempTarget.end())); } else { - tempTargetView.setTextColor(Color.WHITE); - tempTargetView.setBackgroundColor(MainApp.gc(R.color.tempTargetDisabledBackground)); + tempTargetView.setTextColor(MainApp.gc(R.color.ribbonTextDefault)); + tempTargetView.setBackgroundColor(MainApp.gc(R.color.ribbonDefault)); tempTargetView.setText(Profile.toTargetRangeString(profile.getTargetLow(), profile.getTargetHigh(), units, units)); tempTargetView.setVisibility(View.VISIBLE); } @@ -1230,7 +1269,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } activeProfileView.setText(ProfileFunctions.getInstance().getProfileName()); - activeProfileView.setBackgroundColor(Color.GRAY); + if (profile.getPercentage() != 100 || profile.getTimeshift() != 0) { + activeProfileView.setBackgroundColor(MainApp.gc(R.color.ribbonWarning)); + activeProfileView.setTextColor(MainApp.gc(R.color.ribbonTextWarning)); + } else { + activeProfileView.setBackgroundColor(MainApp.gc(R.color.ribbonDefault)); + activeProfileView.setTextColor(MainApp.gc(R.color.ribbonTextDefault)); + } // QuickWizard button QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive(); @@ -1335,6 +1380,56 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, cobView.setText(cobText); } + if (statuslightsLayout != null) { + if (SP.getBoolean(R.string.key_show_statuslights, false)) { + CareportalEvent careportalEvent; + NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance(); + double iageUrgent = nsSettings.getExtendedWarnValue("iage", "urgent", 96); + double iageWarn = nsSettings.getExtendedWarnValue("iage", "warn", 72); + double cageUrgent = nsSettings.getExtendedWarnValue("cage", "urgent", 72); + double cageWarn = nsSettings.getExtendedWarnValue("cage", "warn", 48); + double sageUrgent = nsSettings.getExtendedWarnValue("sage", "urgent", 166); + double sageWarn = nsSettings.getExtendedWarnValue("sage", "warn", 164); + //double pbageUrgent = nsSettings.getExtendedWarnValue("pgage", "urgent", 360); + //double pbageWarn = nsSettings.getExtendedWarnValue("pgage", "warn", 240); + double batUrgent = SP.getDouble(R.string.key_statuslights_bat_critical, 5.0); + double batWarn = SP.getDouble(R.string.key_statuslights_bat_warning, 25.0); + double resUrgent = SP.getDouble(R.string.key_statuslights_res_critical, 10.0); + double resWarn = SP.getDouble(R.string.key_statuslights_res_warning, 80.0); + + if (cageView != null) { + careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE); + double canAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE; + applyStatuslight(cageView, "CAN", canAge, cageWarn, cageUrgent, Double.MAX_VALUE, true); + } + + if (iageView != null) { + careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE); + double insulinAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE; + applyStatuslight(iageView, "INS", insulinAge, iageWarn, iageUrgent, Double.MAX_VALUE, true); + } + + if (reservoirView != null) { + double reservoirLevel = pump.isInitialized() ? pump.getReservoirLevel() : -1; + applyStatuslight(reservoirView, "RES", reservoirLevel, resWarn, resUrgent, -1, false); + } + + if (sageView != null) { + careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE); + double sensorAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE; + applyStatuslight(sageView, "SEN", sensorAge, sageWarn, sageUrgent, Double.MAX_VALUE, true); + } + + if (batteryView != null) { + double batteryLevel = pump.isInitialized() ? pump.getBatteryLevel() : -1; + applyStatuslight(batteryView, "BAT", batteryLevel, batWarn, batUrgent, -1, false); + } + statuslightsLayout.setVisibility(View.VISIBLE); + } else { + statuslightsLayout.setVisibility(View.GONE); + } + } + boolean predictionsAvailable; if (Config.APS) predictionsAvailable = finalLastRun != null && finalLastRun.request.hasPredictions; @@ -1364,7 +1459,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, // Sensitivity if (sensitivityView != null) { - AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("Overview"); + AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensData("Overview"); if (autosensData != null) sensitivityView.setText(String.format("%.0f%%", autosensData.autosensResult.ratio * 100)); else @@ -1525,4 +1620,21 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } } + public static void applyStatuslight(TextView view, String text, double value, double warnThreshold, double urgentThreshold, double invalid, boolean checkAscending) { + Function check = checkAscending ? (Double threshold) -> value >= threshold : (Double threshold) -> value <= threshold; + if (value != invalid) { + view.setText(text); + if (check.apply(urgentThreshold)) { + view.setTextColor(MainApp.gc(R.color.ribbonCritical)); + } else if (check.apply(warnThreshold)) { + view.setTextColor(MainApp.gc(R.color.ribbonWarning)); + } else { + view.setTextColor(MainApp.gc(R.color.ribbonDefault)); + } + view.setVisibility(View.VISIBLE); + } else { + view.setVisibility(View.GONE); + } + + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.java index b184201908..b0981cc6ce 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview; +package info.nightscout.androidaps.plugins.general.overview; import com.squareup.otto.Subscribe; @@ -16,11 +16,11 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 05.08.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/activities/QuickWizardListActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/activities/QuickWizardListActivity.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.java index 237575c328..0bea854c19 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/activities/QuickWizardListActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.activities; +package info.nightscout.androidaps.plugins.general.overview.activities; import android.app.Activity; import android.os.Bundle; @@ -18,11 +18,11 @@ import com.squareup.otto.Subscribe; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.QuickWizard; -import info.nightscout.androidaps.plugins.Overview.Dialogs.EditQuickWizardDialog; -import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; -import info.nightscout.androidaps.plugins.Overview.events.EventQuickWizardChange; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.EditQuickWizardDialog; +import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventQuickWizardChange; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; public class QuickWizardListActivity extends AppCompatActivity implements View.OnClickListener { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissBolusprogressIfRunning.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusprogressIfRunning.java similarity index 84% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissBolusprogressIfRunning.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusprogressIfRunning.java index af336cd74c..2022a4d74b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissBolusprogressIfRunning.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusprogressIfRunning.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.events; +package info.nightscout.androidaps.plugins.general.overview.events; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.events.Event; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissNotification.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissNotification.java similarity index 77% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissNotification.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissNotification.java index 1fa71febbe..bc13c93970 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissNotification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissNotification.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.events; +package info.nightscout.androidaps.plugins.general.overview.events; import info.nightscout.androidaps.events.Event; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventNewNotification.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventNewNotification.java similarity index 63% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventNewNotification.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventNewNotification.java index 2a669d26d2..f6b62b7f83 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventNewNotification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventNewNotification.java @@ -1,7 +1,7 @@ -package info.nightscout.androidaps.plugins.Overview.events; +package info.nightscout.androidaps.plugins.general.overview.events; import info.nightscout.androidaps.events.Event; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; /** * Created by mike on 03.12.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventOverviewBolusProgress.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.java similarity index 78% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventOverviewBolusProgress.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.java index 18e8ff91bc..3a7c50faac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventOverviewBolusProgress.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.java @@ -1,9 +1,6 @@ -package info.nightscout.androidaps.plugins.Overview.events; +package info.nightscout.androidaps.plugins.general.overview.events; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.events.Event; public class EventOverviewBolusProgress extends Event { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventQuickWizardChange.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventQuickWizardChange.java similarity index 68% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventQuickWizardChange.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventQuickWizardChange.java index b72c2548e2..7b070d160e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventQuickWizardChange.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventQuickWizardChange.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.events; +package info.nightscout.androidaps.plugins.general.overview.events; import info.nightscout.androidaps.events.Event; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java index a4b3fc597a..c081567a4c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.graphData; +package info.nightscout.androidaps.plugins.general.overview.graphData; import android.graphics.Color; import android.graphics.DashPathEffect; @@ -28,24 +28,24 @@ import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; -import info.nightscout.androidaps.plugins.IobCobCalculator.BasalData; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.Loop.APSResult; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.AreaGraphSeries; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.DoubleDataPoint; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.FixedLineGraphSeries; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.Scale; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.ScaledDataPoint; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.Round; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.BasalData; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.aps.loop.APSResult; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.AreaGraphSeries; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DoubleDataPoint; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.FixedLineGraphSeries; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.Scale; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.ScaledDataPoint; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.TimeAsXAxisLabelFormatter; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.Round; /** * Created by mike on 18.10.2017. @@ -78,6 +78,8 @@ public class GraphData { if (bgReadingsArray == null || bgReadingsArray.size() == 0) { if (L.isEnabled(L.OVERVIEW)) log.debug("No BG data."); + maxY = 10; + minY = 0; return; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/AreaGraphSeries.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/AreaGraphSeries.java similarity index 99% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/AreaGraphSeries.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/AreaGraphSeries.java index 08da836210..21f0039860 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/AreaGraphSeries.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/AreaGraphSeries.java @@ -17,7 +17,7 @@ * with the "Linking Exception" along with this program; if not, * write to the author Jonas Gehring . */ -package info.nightscout.androidaps.plugins.Overview.graphExtensions; +package info.nightscout.androidaps.plugins.general.overview.graphExtensions; import android.graphics.Canvas; import android.graphics.Color; @@ -26,7 +26,6 @@ import android.graphics.Path; import com.jjoe64.graphview.GraphView; import com.jjoe64.graphview.series.BaseSeries; -import com.jjoe64.graphview.series.DataPointInterface; import java.util.Iterator; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/DataPointWithLabelInterface.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/DataPointWithLabelInterface.java index 20d478692a..60f8266a8e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/DataPointWithLabelInterface.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.graphExtensions; +package info.nightscout.androidaps.plugins.general.overview.graphExtensions; /** * GraphView * Copyright (C) 2014 Jonas Gehring diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DoubleDataPoint.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/DoubleDataPoint.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DoubleDataPoint.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/DoubleDataPoint.java index 5ac5224c65..b7094be44c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DoubleDataPoint.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/DoubleDataPoint.java @@ -1,9 +1,8 @@ -package info.nightscout.androidaps.plugins.Overview.graphExtensions; +package info.nightscout.androidaps.plugins.general.overview.graphExtensions; import com.jjoe64.graphview.series.DataPointInterface; import java.io.Serializable; -import java.util.Date; /** * Created by mike on 21.04.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/FixedLineGraphSeries.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/FixedLineGraphSeries.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/FixedLineGraphSeries.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/FixedLineGraphSeries.java index 922ac3a85b..1ccbcd85cf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/FixedLineGraphSeries.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/FixedLineGraphSeries.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.graphExtensions; +package info.nightscout.androidaps.plugins.general.overview.graphExtensions; /** * Created by mike on 24.04.2017. @@ -15,15 +15,6 @@ import com.jjoe64.graphview.series.DataPointInterface; import java.util.Iterator; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.Path; - -import com.jjoe64.graphview.GraphView; - -import java.util.Iterator; - /** * Series to plot the data as line. * The line can be styled with many options. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/PointsWithLabelGraphSeries.java similarity index 99% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/PointsWithLabelGraphSeries.java index 4a87a8508e..aaa38359a0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/PointsWithLabelGraphSeries.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.graphExtensions; +package info.nightscout.androidaps.plugins.general.overview.graphExtensions; /** * GraphView diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/Scale.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/Scale.java similarity index 86% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/Scale.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/Scale.java index 4aa1271679..21af9d4390 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/Scale.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/Scale.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.graphExtensions; +package info.nightscout.androidaps.plugins.general.overview.graphExtensions; /** * Created by mike on 18.10.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/ScaledDataPoint.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/ScaledDataPoint.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/ScaledDataPoint.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/ScaledDataPoint.java index 61f4102a30..ac63790a71 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/ScaledDataPoint.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/ScaledDataPoint.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.graphExtensions; +package info.nightscout.androidaps.plugins.general.overview.graphExtensions; import com.jjoe64.graphview.series.DataPointInterface; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/TimeAsXAxisLabelFormatter.java similarity index 84% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/TimeAsXAxisLabelFormatter.java index 323751e4c8..c5e5441470 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/TimeAsXAxisLabelFormatter.java @@ -1,12 +1,9 @@ -package info.nightscout.androidaps.plugins.Overview.graphExtensions; - -import android.content.Context; +package info.nightscout.androidaps.plugins.general.overview.graphExtensions; import com.jjoe64.graphview.DefaultLabelFormatter; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.Calendar; /** * Created by mike on 09.06.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/DismissNotificationService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/DismissNotificationService.java similarity index 86% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/DismissNotificationService.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/DismissNotificationService.java index ad102bdc11..a8d6fca1ba 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/DismissNotificationService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/DismissNotificationService.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.notifications; +package info.nightscout.androidaps.plugins.general.overview.notifications; import android.app.IntentService; import android.app.PendingIntent; @@ -6,7 +6,7 @@ import android.content.Intent; import android.support.annotation.Nullable; import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; public class DismissNotificationService extends IntentService { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/Notification.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/Notification.java index 23e9ec9643..3b6bcf615d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/Notification.java @@ -1,17 +1,14 @@ -package info.nightscout.androidaps.plugins.Overview.notifications; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +package info.nightscout.androidaps.plugins.general.overview.notifications; import java.util.Date; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.BgReading; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSAlarm; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus; +import info.nightscout.androidaps.utils.SP; // Added by Rumen for debugging @@ -68,6 +65,15 @@ public class Notification { public static final int NSMALFUNCTION = 40; public static final int NEWVERSIONDETECTED = 41; public static final int SENDLOGFILES = 42; + public static final int DEVICENOTPAIRED = 43; + public static final int MEDTRONIC_PUMP_ALARM = 44; + public static final int RILEYLINK_CONNECTION = 45; + public static final int PERMISSION_PHONESTATE = 46; + public static final int INSIGHT_DATE_TIME_UPDATED = 47; + public static final int INSIGHT_TIMEOUT_DURING_HANDSHAKE = 48; + public static final int DST_LOOP_DISABLED = 49; + public static final int DST_IN_24H = 50; + public static final int DISKFULL = 51; public int id; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationRecyclerViewAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationRecyclerViewAdapter.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationRecyclerViewAdapter.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationRecyclerViewAdapter.java index 9af6be3be3..de35e4bc8c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationRecyclerViewAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationRecyclerViewAdapter.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.notifications; +package info.nightscout.androidaps.plugins.general.overview.notifications; import android.support.v4.content.ContextCompat; import android.support.v7.widget.CardView; @@ -18,11 +18,11 @@ import java.util.Objects; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastAckAlarm; -import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastAckAlarm; +import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; public class NotificationRecyclerViewAdapter extends RecyclerView.Adapter { private static Logger log = LoggerFactory.getLogger(L.NOTIFICATION); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.java index 7c4469521d..8d327bf29f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.notifications; +package info.nightscout.androidaps.plugins.general.overview.notifications; import android.annotation.SuppressLint; import android.app.NotificationChannel; @@ -26,7 +26,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.services.AlarmSoundService; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 03.12.2016. @@ -126,12 +126,8 @@ public class NotificationStore { private void raiseSystemNotification(Notification n) { Context context = MainApp.instance().getApplicationContext(); NotificationManager mgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.blueowl); - int smallIcon = R.drawable.ic_notification; - if (Config.NSCLIENT) { - largeIcon = BitmapFactory.decodeResource(MainApp.instance().getResources(), R.mipmap.yellowowl); - smallIcon = R.drawable.nsclient_smallicon; - } + Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), MainApp.getIcon()); + int smallIcon = MainApp.getNotificationIcon(); Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationWithAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationWithAction.java similarity index 82% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationWithAction.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationWithAction.java index 6248231a59..2ff61b63c8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationWithAction.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationWithAction.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview.notifications; +package info.nightscout.androidaps.plugins.general.overview.notifications; public class NotificationWithAction extends Notification { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/DummyService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyService.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/DummyService.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyService.java index 56b3a2cd09..863046c0c4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/DummyService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyService.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Persistentnotification; +package info.nightscout.androidaps.plugins.general.persistentNotification; import android.app.Notification; import android.app.Service; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java similarity index 64% rename from app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java index cd69e88210..0287c21260 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Persistentnotification; +package info.nightscout.androidaps.plugins.general.persistentNotification; import android.annotation.SuppressLint; import android.app.Notification; @@ -11,11 +11,11 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Build; import android.support.v4.app.NotificationCompat; +import android.support.v4.app.RemoteInput; import android.support.v4.app.TaskStackBuilder; import com.squareup.otto.Subscribe; -import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainActivity; import info.nightscout.androidaps.MainApp; @@ -27,7 +27,6 @@ import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.events.EventExtendedBolusChange; import info.nightscout.androidaps.events.EventInitializationChanged; -import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshOverview; @@ -36,11 +35,12 @@ import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DecimalFormatter; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DecimalFormatter; /** * Created by adrian on 23/12/16. @@ -60,6 +60,18 @@ public class PersistentNotificationPlugin extends PluginBase { public static final int ONGOING_NOTIFICATION_ID = 4711; private final Context ctx; + /// For Android Auto + /// Intents are not declared in manifest and not consumed, this is intentionally because actually we can't do anything with + private static final String PACKAGE = "info.nightscout"; + private static final String READ_ACTION = + "info.nightscout.androidaps.ACTION_MESSAGE_READ"; + private static final String REPLY_ACTION = + "info.nightscout.androidaps.ACTION_MESSAGE_REPLY"; + private static final String CONVERSATION_ID = "conversation_id"; + private static final String EXTRA_VOICE_REPLY = "extra_voice_reply"; + /// End Android Auto + + public PersistentNotificationPlugin(Context ctx) { super(new PluginDescription() .mainType(PluginType.GENERAL) @@ -107,7 +119,8 @@ public class PersistentNotificationPlugin extends PluginBase { return null; } - String line1 = ""; + String line1; + String line1_aa; if (ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() == null || !ProfileFunctions.getInstance().isProfileValid("Notificiation")) return null; @@ -118,22 +131,25 @@ public class PersistentNotificationPlugin extends PluginBase { GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); if (lastBG != null) { - line1 = lastBG.valueToUnitsToString(units); + line1 = line1_aa = lastBG.valueToUnitsToString(units); if (glucoseStatus != null) { line1 += " Δ" + deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " avgΔ" + deltastring(glucoseStatus.avgdelta, glucoseStatus.avgdelta * Constants.MGDL_TO_MMOLL, units); + line1_aa += " " + lastBG.directionToSymbol(); } else { line1 += " " + MainApp.gs(R.string.old_data) + " "; + line1_aa += line1 + "."; } } else { - line1 = MainApp.gs(R.string.missed_bg_readings); + line1 = line1_aa = MainApp.gs(R.string.missed_bg_readings); } TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()); if (activeTemp != null) { line1 += " " + activeTemp.toStringShort(); + line1_aa += " " + activeTemp.toStringShort() + "."; } //IOB @@ -143,30 +159,72 @@ public class PersistentNotificationPlugin extends PluginBase { IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().round(); - String line2 = MainApp.gs(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U " + MainApp.gs(R.string.cob)+": " + IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "PersistentNotificationPlugin").generateCOBString();; - + String line2 = MainApp.gs(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U " + MainApp.gs(R.string.cob) + ": " + IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "PersistentNotificationPlugin").generateCOBString(); + String line2_aa = MainApp.gs(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U. " + MainApp.gs(R.string.cob) + ": " + IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "PersistentNotificationPlugin").generateCOBString() + "."; + + String line3 = DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getPlugin().getActivePump().getBaseBasalRate()) + " U/h"; + String line3_aa = DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getPlugin().getActivePump().getBaseBasalRate()) + " U/h."; line3 += " - " + ProfileFunctions.getInstance().getProfileName(); + line3_aa += " - " + ProfileFunctions.getInstance().getProfileName() + "."; + + /// For Android Auto + Intent msgReadIntent = new Intent() + .addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES) + .setAction(READ_ACTION) + .putExtra(CONVERSATION_ID, ONGOING_NOTIFICATION_ID) + .setPackage(PACKAGE); + + PendingIntent msgReadPendingIntent = + PendingIntent.getBroadcast(ctx, + ONGOING_NOTIFICATION_ID, + msgReadIntent, + PendingIntent.FLAG_UPDATE_CURRENT); + + Intent msgReplyIntent = new Intent() + .addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES) + .setAction(REPLY_ACTION) + .putExtra(CONVERSATION_ID, ONGOING_NOTIFICATION_ID) + .setPackage(PACKAGE); + + PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast( + ctx, + ONGOING_NOTIFICATION_ID, + msgReplyIntent, + PendingIntent.FLAG_UPDATE_CURRENT); + + // Build a RemoteInput for receiving voice input from devices + RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).build(); + + // Create the UnreadConversation + NotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder = + new NotificationCompat.CarExtender.UnreadConversation.Builder(line1_aa + "\n" + line2_aa) + .setLatestTimestamp(System.currentTimeMillis()) + .setReadPendingIntent(msgReadPendingIntent) + .setReplyAction(msgReplyPendingIntent, remoteInput); + + /// Add dot to produce a "more natural sounding result" + unreadConversationBuilder.addMessage(line3_aa); + /// End Android Auto NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, CHANNEL_ID); builder.setOngoing(true); builder.setOnlyAlertOnce(true); builder.setCategory(NotificationCompat.CATEGORY_STATUS); - if (Config.NSCLIENT){ - builder.setSmallIcon(R.drawable.nsclient_smallicon); - Bitmap largeIcon = BitmapFactory.decodeResource(ctx.getResources(), R.mipmap.yellowowl); - builder.setLargeIcon(largeIcon); - } else { - builder.setSmallIcon(R.drawable.ic_notification); - Bitmap largeIcon = BitmapFactory.decodeResource(ctx.getResources(), R.mipmap.blueowl); - builder.setLargeIcon(largeIcon); - } + builder.setSmallIcon(MainApp.getNotificationIcon()); + Bitmap largeIcon = BitmapFactory.decodeResource(ctx.getResources(), MainApp.getIcon()); + builder.setLargeIcon(largeIcon); builder.setContentTitle(line1); builder.setContentText(line2); builder.setSubText(line3); + /// Android Auto + builder.extend(new NotificationCompat.CarExtender() + .setUnreadConversation(unreadConversationBuilder.build())); + /// End Android Auto + Intent resultIntent = new Intent(ctx, MainActivity.class); @@ -225,7 +283,7 @@ public class PersistentNotificationPlugin extends PluginBase { } @Subscribe - public void onStatusEvent(final EventNewBG ev) { + public void onStatusEvent(final EventAutosensCalculationFinished ev) { triggerNotificationUpdate(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.java new file mode 100644 index 0000000000..4b05072eb1 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.java @@ -0,0 +1,59 @@ +package info.nightscout.androidaps.plugins.general.smsCommunicator; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Constants; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.utils.DateUtil; + +class AuthRequest { + private static Logger log = LoggerFactory.getLogger(L.SMS); + + Sms requester; + String confirmCode; + private Runnable action; + + private long date; + + private boolean processed; + private SmsCommunicatorPlugin plugin; + + AuthRequest(SmsCommunicatorPlugin plugin, Sms requester, String requestText, String confirmCode, SmsAction action) { + this.requester = requester; + this.confirmCode = confirmCode; + this.action = action; + this.plugin = plugin; + + this.date = DateUtil.now(); + + plugin.sendSMS(new Sms(requester.phoneNumber, requestText)); + } + + void action(String codeReceived) { + if (processed) { + if (L.isEnabled(L.SMS)) + log.debug("Already processed"); + return; + } + if (!confirmCode.equals(codeReceived)) { + processed = true; + if (L.isEnabled(L.SMS)) + log.debug("Wrong code"); + plugin.sendSMS(new Sms(requester.phoneNumber, R.string.sms_wrongcode)); + return; + } + if (DateUtil.now() - date < Constants.SMS_CONFIRM_TIMEOUT) { + processed = true; + if (L.isEnabled(L.SMS)) + log.debug("Processing confirmed SMS: " + requester.text); + if (action != null) + action.run(); + return; + } + if (L.isEnabled(L.SMS)) + log.debug("Timed out SMS: " + requester.text); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.java new file mode 100644 index 0000000000..2eedfa0a51 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.java @@ -0,0 +1,42 @@ +package info.nightscout.androidaps.plugins.general.smsCommunicator; + +import android.telephony.SmsMessage; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.utils.DateUtil; + +class Sms { + String phoneNumber; + String text; + long date; + boolean received = false; + boolean sent = false; + boolean processed = false; + boolean ignored = false; + + Sms(SmsMessage message) { + phoneNumber = message.getOriginatingAddress(); + text = message.getMessageBody(); + date = message.getTimestampMillis(); + received = true; + } + + Sms(String phoneNumber, String text) { + this.phoneNumber = phoneNumber; + this.text = text; + this.date = DateUtil.now(); + sent = true; + } + + Sms(String phoneNumber, int textId) { + this.phoneNumber = phoneNumber; + this.text = MainApp.gs(textId); + this.date = DateUtil.now(); + sent = true; + } + + public String toString() { + return "SMS from " + phoneNumber + ": " + text; + } +} + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.java new file mode 100644 index 0000000000..6b5d5b8747 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.java @@ -0,0 +1,33 @@ +package info.nightscout.androidaps.plugins.general.smsCommunicator; + +abstract class SmsAction implements Runnable { + Double aDouble; + Integer anInteger; + Integer secondInteger; + String aString; + + SmsAction() {} + + SmsAction(Double aDouble) { + this.aDouble = aDouble; + } + + SmsAction(Double aDouble, Integer secondInteger) { + this.aDouble = aDouble; + this.secondInteger = secondInteger; + } + + SmsAction(String aString, Integer secondInteger) { + this.aString = aString; + this.secondInteger = secondInteger; + } + + SmsAction(Integer anInteger) { + this.anInteger = anInteger; + } + + SmsAction(Integer anInteger, Integer secondInteger) { + this.anInteger = anInteger; + this.secondInteger = secondInteger; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorFragment.java new file mode 100644 index 0000000000..d1c4adf5fe --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorFragment.java @@ -0,0 +1,73 @@ +package info.nightscout.androidaps.plugins.general.smsCommunicator; + + +import android.app.Activity; +import android.os.Bundle; +import android.text.Html; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.squareup.otto.Subscribe; + +import java.util.Collections; +import java.util.Comparator; + +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.general.smsCommunicator.events.EventSmsCommunicatorUpdateGui; +import info.nightscout.androidaps.utils.DateUtil; + +public class SmsCommunicatorFragment extends SubscriberFragment { + TextView logView; + + public SmsCommunicatorFragment() { + super(); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.smscommunicator_fragment, container, false); + + logView = (TextView) view.findViewById(R.id.smscommunicator_log); + + return view; + } + + @Subscribe + public void onStatusEvent(final EventSmsCommunicatorUpdateGui ev) { + updateGUI(); + } + + @Override + protected void updateGUI() { + Activity activity = getActivity(); + if (activity != null) + activity.runOnUiThread(() -> { + class CustomComparator implements Comparator { + public int compare(Sms object1, Sms object2) { + return (int) (object1.date - object2.date); + } + } + Collections.sort(SmsCommunicatorPlugin.getPlugin().messages, new CustomComparator()); + int messagesToShow = 40; + + int start = Math.max(0, SmsCommunicatorPlugin.getPlugin().messages.size() - messagesToShow); + + String logText = ""; + for (int x = start; x < SmsCommunicatorPlugin.getPlugin().messages.size(); x++) { + Sms sms = SmsCommunicatorPlugin.getPlugin().messages.get(x); + if (sms.ignored) { + logText += DateUtil.timeString(sms.date) + " <<< " + "░ " + sms.phoneNumber + " " + sms.text + "
"; + } else if (sms.received) { + logText += DateUtil.timeString(sms.date) + " <<< " + (sms.processed ? "● " : "○ ") + sms.phoneNumber + " " + sms.text + "
"; + } else if (sms.sent) { + logText += DateUtil.timeString(sms.date) + " >>> " + (sms.processed ? "● " : "○ ") + sms.phoneNumber + " " + sms.text + "
"; + } + } + logView.setText(Html.fromHtml(logText)); + }); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java new file mode 100644 index 0000000000..e4ec65df11 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java @@ -0,0 +1,795 @@ +package info.nightscout.androidaps.plugins.general.smsCommunicator; + +import android.content.Intent; +import android.content.pm.ResolveInfo; +import android.os.Bundle; +import android.telephony.SmsManager; +import android.telephony.SmsMessage; + +import com.squareup.otto.Subscribe; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.text.Normalizer; +import java.util.ArrayList; +import java.util.List; + +import info.nightscout.androidaps.Constants; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.DetailedBolusInfo; +import info.nightscout.androidaps.data.GlucoseStatus; +import info.nightscout.androidaps.data.IobTotal; +import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.data.ProfileStore; +import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.db.DatabaseHelper; +import info.nightscout.androidaps.db.Source; +import info.nightscout.androidaps.events.EventPreferenceChange; +import info.nightscout.androidaps.events.EventRefreshOverview; +import info.nightscout.androidaps.interfaces.Constraint; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginDescription; +import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.interfaces.ProfileInterface; +import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.general.smsCommunicator.events.EventSmsCommunicatorUpdateGui; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.queue.Callback; +import info.nightscout.androidaps.services.Intents; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.SafeParse; +import info.nightscout.androidaps.utils.XdripCalibrations; + +/** + * Created by mike on 05.08.2016. + */ +public class SmsCommunicatorPlugin extends PluginBase { + private static Logger log = LoggerFactory.getLogger(L.SMS); + + private static SmsCommunicatorPlugin smsCommunicatorPlugin; + + public static SmsCommunicatorPlugin getPlugin() { + + if (smsCommunicatorPlugin == null) { + smsCommunicatorPlugin = new SmsCommunicatorPlugin(); + } + return smsCommunicatorPlugin; + } + + List allowedNumbers = new ArrayList<>(); + + AuthRequest messageToConfirm = null; + + long lastRemoteBolusTime = 0; + + ArrayList messages = new ArrayList<>(); + + SmsCommunicatorPlugin() { + super(new PluginDescription() + .mainType(PluginType.GENERAL) + .fragmentClass(SmsCommunicatorFragment.class.getName()) + .pluginName(R.string.smscommunicator) + .shortName(R.string.smscommunicator_shortname) + .preferencesId(R.xml.pref_smscommunicator) + .description(R.string.description_sms_communicator) + ); + processSettings(null); + } + + @Override + protected void onStart() { + MainApp.bus().register(this); + super.onStart(); + } + + @Override + protected void onStop() { + MainApp.bus().unregister(this); + } + + @Subscribe + public void processSettings(final EventPreferenceChange ev) { + if (ev == null || ev.isChanged(R.string.key_smscommunicator_allowednumbers)) { + String settings = SP.getString(R.string.key_smscommunicator_allowednumbers, ""); + + String pattern = ";"; + + String[] substrings = settings.split(pattern); + for (String number : substrings) { + String cleaned = number.replaceAll("\\s+", ""); + allowedNumbers.add(cleaned); + log.debug("Found allowed number: " + cleaned); + } + } + } + + boolean isCommand(String command, String number) { + switch(command.toUpperCase()) { + case "BG": + case "LOOP": + case "TREATMENTS": + case "NSCLIENT": + case "PUMP": + case "BASAL": + case "BOLUS": + case "EXTENDED": + case "CAL": + case "PROFILE": + return true; + } + if (messageToConfirm != null && messageToConfirm.requester.phoneNumber.equals(number)) + return true; + return false; + } + + boolean isAllowedNumber(String number) { + for (String num : allowedNumbers) { + if (num.equals(number)) return true; + } + return false; + } + + public void handleNewData(Intent intent) { + Bundle bundle = intent.getExtras(); + if (bundle == null) return; + + Object[] pdus = (Object[]) bundle.get("pdus"); + if (pdus != null) { + // For every SMS message received + for (Object pdu : pdus) { + SmsMessage message = SmsMessage.createFromPdu((byte[]) pdu); + processSms(new Sms(message)); + } + } + } + + void processSms(final Sms receivedSms) { + if (!isEnabled(PluginType.GENERAL)) { + log.debug("Ignoring SMS. Plugin disabled."); + return; + } + if (!isAllowedNumber(receivedSms.phoneNumber)) { + log.debug("Ignoring SMS from: " + receivedSms.phoneNumber + ". Sender not allowed"); + receivedSms.ignored = true; + messages.add(receivedSms); + MainApp.bus().post(new EventSmsCommunicatorUpdateGui()); + return; + } + + messages.add(receivedSms); + log.debug(receivedSms.toString()); + + String[] splitted = receivedSms.text.split("\\s+"); + boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false); + + if (splitted.length > 0 && isCommand(splitted[0].toUpperCase(), receivedSms.phoneNumber)) { + switch (splitted[0].toUpperCase()) { + case "BG": + processBG(splitted, receivedSms); + break; + case "LOOP": + if (!remoteCommandsAllowed) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed)); + else if (splitted.length == 2 || splitted.length == 3) + processLOOP(splitted, receivedSms); + else + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + break; + case "TREATMENTS": + if (splitted.length == 2) + processTREATMENTS(splitted, receivedSms); + else + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + break; + case "NSCLIENT": + if (splitted.length == 2) + processNSCLIENT(splitted, receivedSms); + else + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + break; + case "PUMP": + processPUMP(splitted, receivedSms); + break; + case "PROFILE": + if (!remoteCommandsAllowed) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed)); + else if (splitted.length == 2 || splitted.length == 3) + processPROFILE(splitted, receivedSms); + else + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + break; + case "BASAL": + if (!remoteCommandsAllowed) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed)); + else if (splitted.length == 2 || splitted.length == 3) + processBASAL(splitted, receivedSms); + else + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + break; + case "EXTENDED": + if (!remoteCommandsAllowed) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed)); + else if (splitted.length == 2 || splitted.length == 3) + processEXTENDED(splitted, receivedSms); + else + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + break; + case "BOLUS": + if (!remoteCommandsAllowed) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed)); + else if (splitted.length == 2 && DateUtil.now() - lastRemoteBolusTime < Constants.remoteBolusMinDistance) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotebolusnotallowed)); + else if (splitted.length == 2 && ConfigBuilderPlugin.getPlugin().getActivePump().isSuspended()) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.pumpsuspended)); + else if (splitted.length == 2) + processBOLUS(splitted, receivedSms); + else + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + break; + case "CAL": + if (!remoteCommandsAllowed) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed)); + else if (splitted.length == 2) + processCAL(splitted, receivedSms); + else + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + break; + default: // expect passCode here + if (messageToConfirm != null && messageToConfirm.requester.phoneNumber.equals(receivedSms.phoneNumber)) { + messageToConfirm.action(splitted[0]); + messageToConfirm = null; + } else + sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_unknowncommand)); + break; + } + } + + MainApp.bus().post(new EventSmsCommunicatorUpdateGui()); + } + + @SuppressWarnings("unused") + private void processBG(String[] splitted, Sms receivedSms) { + BgReading actualBG = DatabaseHelper.actualBg(); + BgReading lastBG = DatabaseHelper.lastBg(); + + String reply = ""; + + String units = ProfileFunctions.getInstance().getProfileUnits(); + + if (actualBG != null) { + reply = MainApp.gs(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", "; + } else if (lastBG != null) { + Long agoMsec = System.currentTimeMillis() - lastBG.date; + int agoMin = (int) (agoMsec / 60d / 1000d); + reply = MainApp.gs(R.string.sms_lastbg) + " " + lastBG.valueToUnitsToString(units) + " " + String.format(MainApp.gs(R.string.sms_minago), agoMin) + ", "; + } + GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); + if (glucoseStatus != null) + reply += MainApp.gs(R.string.sms_delta) + " " + Profile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", "; + + TreatmentsPlugin.getPlugin().updateTotalIOBTreatments(); + IobTotal bolusIob = TreatmentsPlugin.getPlugin().getLastCalculationTreatments().round(); + TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals(); + IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().round(); + + String cobText = MainApp.gs(R.string.value_unavailable_short); + CobInfo cobInfo = IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "SMS COB"); + + reply += MainApp.gs(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U (" + + MainApp.gs(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U " + + MainApp.gs(R.string.sms_basal) + " " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U), " + + MainApp.gs(R.string.cob) + ": " + cobInfo.generateCOBString(); + + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + receivedSms.processed = true; + } + + private void processLOOP(String[] splitted, Sms receivedSms) { + String reply; + switch (splitted[1].toUpperCase()) { + case "DISABLE": + case "STOP": + LoopPlugin loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class); + if (loopPlugin != null && loopPlugin.isEnabled(PluginType.LOOP)) { + loopPlugin.setPluginEnabled(PluginType.LOOP, false); + ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, new Callback() { + @Override + public void run() { + MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_STOP")); + String reply = MainApp.gs(R.string.smscommunicator_loophasbeendisabled) + " " + + MainApp.gs(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + }); + } else { + sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_loopisdisabled)); + } + receivedSms.processed = true; + break; + case "ENABLE": + case "START": + loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class); + if (loopPlugin != null && !loopPlugin.isEnabled(PluginType.LOOP)) { + loopPlugin.setPluginEnabled(PluginType.LOOP, true); + sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_loophasbeenenabled)); + MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_START")); + } else { + sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_loopisenabled)); + } + receivedSms.processed = true; + break; + case "STATUS": + loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class); + if (loopPlugin != null) { + if (loopPlugin.isEnabled(PluginType.LOOP)) { + if (loopPlugin.isSuspended()) + reply = String.format(MainApp.gs(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend()); + else + reply = MainApp.gs(R.string.smscommunicator_loopisenabled); + } else { + reply = MainApp.gs(R.string.smscommunicator_loopisdisabled); + } + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + receivedSms.processed = true; + break; + case "RESUME": + LoopPlugin.getPlugin().suspendTo(0); + MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_RESUME")); + NSUpload.uploadOpenAPSOffline(0); + sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_loopresumed)); + break; + case "SUSPEND": + int duration = 0; + if (splitted.length == 3) + duration = SafeParse.stringToInt(splitted[2]); + duration = Math.max(0, duration); + duration = Math.min(180, duration); + if (duration == 0) { + receivedSms.processed = true; + sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_wrongduration)); + return; + } else { + String passCode = generatePasscode(); + reply = String.format(MainApp.gs(R.string.smscommunicator_suspendreplywithcode), duration, passCode); + receivedSms.processed = true; + messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(duration) { + @Override + public void run() { + ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, new Callback() { + @Override + public void run() { + if (result.success) { + LoopPlugin.getPlugin().suspendTo(System.currentTimeMillis() + anInteger * 60L * 1000); + NSUpload.uploadOpenAPSOffline(anInteger * 60); + MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_SUSPENDED")); + String reply = MainApp.gs(R.string.smscommunicator_loopsuspended) + " " + + MainApp.gs(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed); + sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply)); + } else { + String reply = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } + }); + + } + }); + } + break; + default: + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + break; + } + } + + private void processTREATMENTS(String[] splitted, Sms receivedSms) { + if (splitted[1].toUpperCase().equals("REFRESH")) { + Intent restartNSClient = new Intent(Intents.ACTION_RESTART); + TreatmentsPlugin.getPlugin().getService().resetTreatments(); + MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient); + List q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0); + String reply = "TREATMENTS REFRESH " + q.size() + " receivers"; + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + receivedSms.processed = true; + } else + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + } + + private void processNSCLIENT(String[] splitted, Sms receivedSms) { + if (splitted[1].toUpperCase().equals("RESTART")) { + Intent restartNSClient = new Intent(Intents.ACTION_RESTART); + MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient); + List q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0); + String reply = "NSCLIENT RESTART " + q.size() + " receivers"; + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + receivedSms.processed = true; + } else + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + } + + @SuppressWarnings("unused") + private void processPUMP(String[] splitted, Sms receivedSms) { + ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("SMS", new Callback() { + @Override + public void run() { + PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); + if (result.success) { + if (pump != null) { + String reply = pump.shortStatus(true); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } else { + String reply = MainApp.gs(R.string.readstatusfailed); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } + }); + receivedSms.processed = true; + } + + private void processPROFILE(String[] splitted, Sms receivedSms) { + // load profiles + ProfileInterface anInterface = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface(); + if (anInterface == null) { + sendSMS(new Sms(receivedSms.phoneNumber, R.string.notconfigured)); + receivedSms.processed = true; + return; + } + ProfileStore store = anInterface.getProfile(); + if (store == null) { + sendSMS(new Sms(receivedSms.phoneNumber, R.string.notconfigured)); + receivedSms.processed = true; + return; + } + final ArrayList list = store.getProfileList(); + + if (splitted[1].toUpperCase().equals("STATUS")) { + sendSMS(new Sms(receivedSms.phoneNumber, ProfileFunctions.getInstance().getProfileName())); + } else if (splitted[1].toUpperCase().equals("LIST")) { + if (list.isEmpty()) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.invalidprofile)); + else { + String reply = ""; + for (int i = 0; i < list.size(); i++) { + if (i > 0) + reply += "\n"; + reply += (i + 1) + ". "; + reply += list.get(i); + } + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } else { + + int pindex = SafeParse.stringToInt(splitted[1]); + int percentage = 100; + if (splitted.length > 2) + percentage = SafeParse.stringToInt(splitted[2]); + + if (pindex > list.size()) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + else if (percentage == 0) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + else if (pindex == 0) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + else { + final Profile profile = store.getSpecificProfile((String) list.get(pindex - 1)); + if (profile == null) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.noprofile)); + else { + String passCode = generatePasscode(); + String reply = String.format(MainApp.gs(R.string.smscommunicator_profilereplywithcode), list.get(pindex - 1), percentage, passCode); + receivedSms.processed = true; + int finalPercentage = percentage; + messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction((String) list.get(pindex - 1), finalPercentage) { + @Override + public void run() { + ProfileFunctions.doProfileSwitch(store, (String) list.get(pindex - 1), 0, finalPercentage, 0); + sendSMS(new Sms(receivedSms.phoneNumber, R.string.profileswitchcreated)); + } + }); + } + } + } + receivedSms.processed = true; + } + + private void processBASAL(String[] splitted, Sms receivedSms) { + if (splitted[1].toUpperCase().equals("CANCEL") || splitted[1].toUpperCase().equals("STOP")) { + String passCode = generatePasscode(); + String reply = String.format(MainApp.gs(R.string.smscommunicator_basalstopreplywithcode), passCode); + receivedSms.processed = true; + messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction() { + @Override + public void run() { + ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, new Callback() { + @Override + public void run() { + if (result.success) { + String reply = MainApp.gs(R.string.smscommunicator_tempbasalcanceled); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply)); + } else { + String reply = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } + }); + } + }); + } else if (splitted[1].endsWith("%")) { + int tempBasalPct = SafeParse.stringToInt(StringUtils.removeEnd(splitted[1], "%")); + int duration = 30; + if (splitted.length > 2) + duration = SafeParse.stringToInt(splitted[2]); + final Profile profile = ProfileFunctions.getInstance().getProfile(); + + if (profile == null) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.noprofile)); + else if (tempBasalPct == 0 && !splitted[1].equals("0%")) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + else if (duration == 0) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + else { + tempBasalPct = MainApp.getConstraintChecker().applyBasalPercentConstraints(new Constraint<>(tempBasalPct), profile).value(); + String passCode = generatePasscode(); + String reply = String.format(MainApp.gs(R.string.smscommunicator_basalpctreplywithcode), tempBasalPct, duration, passCode); + receivedSms.processed = true; + messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(tempBasalPct, duration) { + @Override + public void run() { + ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalPercent(anInteger, secondInteger, true, profile, new Callback() { + @Override + public void run() { + if (result.success) { + String reply; + if (result.isPercent) + reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset_percent), result.percent, result.duration); + else + reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply)); + } else { + String reply = MainApp.gs(R.string.smscommunicator_tempbasalfailed); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } + }); + } + }); + } + } else { + Double tempBasal = SafeParse.stringToDouble(splitted[1]); + int duration = 30; + if (splitted.length > 2) + duration = SafeParse.stringToInt(splitted[2]); + final Profile profile = ProfileFunctions.getInstance().getProfile(); + if (profile == null) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.noprofile)); + else if (tempBasal == 0 && !splitted[1].equals("0")) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + else if (duration == 0) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + else { + tempBasal = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(tempBasal), profile).value(); + String passCode = generatePasscode(); + String reply = String.format(MainApp.gs(R.string.smscommunicator_basalreplywithcode), tempBasal, duration, passCode); + receivedSms.processed = true; + messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(tempBasal, duration) { + @Override + public void run() { + ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalAbsolute(aDouble, secondInteger, true, profile, new Callback() { + @Override + public void run() { + if (result.success) { + String reply; + if (result.isPercent) + reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset_percent), result.percent, result.duration); + else + reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply)); + } else { + String reply = MainApp.gs(R.string.smscommunicator_tempbasalfailed); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } + }); + } + }); + } + } + } + + private void processEXTENDED(String[] splitted, Sms receivedSms) { + if (splitted[1].toUpperCase().equals("CANCEL") || splitted[1].toUpperCase().equals("STOP")) { + String passCode = generatePasscode(); + String reply = String.format(MainApp.gs(R.string.smscommunicator_extendedstopreplywithcode), passCode); + receivedSms.processed = true; + messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction() { + @Override + public void run() { + ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelExtended(new Callback() { + @Override + public void run() { + if (result.success) { + String reply = MainApp.gs(R.string.smscommunicator_extendedcanceled); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply)); + } else { + String reply = MainApp.gs(R.string.smscommunicator_extendedcancelfailed); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } + }); + } + }); + } else if (splitted.length != 3) { + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + } else { + Double extended = SafeParse.stringToDouble(splitted[1]); + int duration = SafeParse.stringToInt(splitted[2]); + extended = MainApp.getConstraintChecker().applyExtendedBolusConstraints(new Constraint<>(extended)).value(); + if (extended == 0 || duration == 0) + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + else { + String passCode = generatePasscode(); + String reply = String.format(MainApp.gs(R.string.smscommunicator_extendedreplywithcode), extended, duration, passCode); + receivedSms.processed = true; + messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(extended, duration) { + @Override + public void run() { + ConfigBuilderPlugin.getPlugin().getCommandQueue().extendedBolus(aDouble, secondInteger, new Callback() { + @Override + public void run() { + if (result.success) { + String reply = String.format(MainApp.gs(R.string.smscommunicator_extendedset), aDouble, duration); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply)); + } else { + String reply = MainApp.gs(R.string.smscommunicator_extendedfailed); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } + }); + } + }); + } + } + } + + + private void processBOLUS(String[] splitted, Sms receivedSms) { + Double bolus = SafeParse.stringToDouble(splitted[1]); + bolus = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(bolus)).value(); + if (bolus > 0d) { + String passCode = generatePasscode(); + String reply = String.format(MainApp.gs(R.string.smscommunicator_bolusreplywithcode), bolus, passCode); + receivedSms.processed = true; + messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(bolus) { + @Override + public void run() { + DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); + detailedBolusInfo.insulin = aDouble; + detailedBolusInfo.source = Source.USER; + ConfigBuilderPlugin.getPlugin().getCommandQueue().bolus(detailedBolusInfo, new Callback() { + @Override + public void run() { + final boolean resultSuccess = result.success; + final double resultBolusDelivered = result.bolusDelivered; + ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("SMS", new Callback() { + @Override + public void run() { + PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); + if (resultSuccess) { + String reply = String.format(MainApp.gs(R.string.smscommunicator_bolusdelivered), resultBolusDelivered); + if (pump != null) + reply += "\n" + pump.shortStatus(true); + lastRemoteBolusTime = DateUtil.now(); + sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply)); + } else { + String reply = MainApp.gs(R.string.smscommunicator_bolusfailed); + if (pump != null) + reply += "\n" + pump.shortStatus(true); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } + }); + } + }); + } + }); + } else + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + } + + private void processCAL(String[] splitted, Sms receivedSms) { + Double cal = SafeParse.stringToDouble(splitted[1]); + if (cal > 0d) { + String passCode = generatePasscode(); + String reply = String.format(MainApp.gs(R.string.smscommunicator_calibrationreplywithcode), cal, passCode); + receivedSms.processed = true; + messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction() { + @Override + public void run() { + boolean result = XdripCalibrations.sendIntent(aDouble); + if (result) + sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_calibrationsent)); + else + sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_calibrationfailed)); + } + }); + } else + sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); + } + + public void sendNotificationToAllNumbers(String text) { + for (int i = 0; i < allowedNumbers.size(); i++) { + Sms sms = new Sms(allowedNumbers.get(i), text); + sendSMS(sms); + } + } + + private void sendSMSToAllNumbers(Sms sms) { + for (String number : allowedNumbers) { + sms.phoneNumber = number; + sendSMS(sms); + } + } + + void sendSMS(Sms sms) { + SmsManager smsManager = SmsManager.getDefault(); + sms.text = stripAccents(sms.text); + if (sms.text.length() > 140) sms.text = sms.text.substring(0, 139); + try { + if (L.isEnabled(L.SMS)) + log.debug("Sending SMS to " + sms.phoneNumber + ": " + sms.text); + smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null); + messages.add(sms); + } catch (IllegalArgumentException e) { + Notification notification = new Notification(Notification.INVALID_PHONE_NUMBER, MainApp.gs(R.string.smscommunicator_invalidphonennumber), Notification.NORMAL); + MainApp.bus().post(new EventNewNotification(notification)); + } catch (java.lang.SecurityException e) { + Notification notification = new Notification(Notification.MISSING_SMS_PERMISSION, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.NORMAL); + MainApp.bus().post(new EventNewNotification(notification)); + } + MainApp.bus().post(new EventSmsCommunicatorUpdateGui()); + } + + private String generatePasscode() { + int startChar1 = 'A'; // on iphone 1st char is uppercase :) + String passCode = Character.toString((char) (startChar1 + Math.random() * ('z' - 'a' + 1))); + int startChar2 = Math.random() > 0.5 ? 'a' : 'A'; + passCode += Character.toString((char) (startChar2 + Math.random() * ('z' - 'a' + 1))); + int startChar3 = Math.random() > 0.5 ? 'a' : 'A'; + passCode += Character.toString((char) (startChar3 + Math.random() * ('z' - 'a' + 1))); + passCode.replace('l', 'k').replace('I', 'J'); + return passCode; + } + + private static String stripAccents(String s) { + s = Normalizer.normalize(s, Normalizer.Form.NFD); + s = s.replaceAll("[\\p{InCombiningDiacriticalMarks}]", ""); + return s; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventSmsCommunicatorUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/events/EventSmsCommunicatorUpdateGui.java similarity index 69% rename from app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventSmsCommunicatorUpdateGui.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/events/EventSmsCommunicatorUpdateGui.java index 02956a5d67..7e50671c45 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventSmsCommunicatorUpdateGui.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/events/EventSmsCommunicatorUpdateGui.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.SmsCommunicator.events; +package info.nightscout.androidaps.plugins.general.smsCommunicator.events; import info.nightscout.androidaps.events.EventUpdateGui; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java index 5245921922..b92410d67f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Wear; +package info.nightscout.androidaps.plugins.general.wear; import android.app.NotificationManager; import android.content.Context; @@ -31,31 +31,31 @@ import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog; -import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.Loop.APSResult; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; -import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin; -import info.nightscout.androidaps.plugins.Treatments.CarbsGenerator; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.general.actions.dialogs.FillDialog; +import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.aps.loop.APSResult; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; +import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin; +import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin; +import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin; +import info.nightscout.androidaps.plugins.treatments.CarbsGenerator; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.BolusWizard; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.HardLimits; -import info.nightscout.utils.SP; -import info.nightscout.utils.SafeParse; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.utils.BolusWizard; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.HardLimits; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.SafeParse; +import info.nightscout.androidaps.utils.ToastUtils; /** * Created by adrian on 09/02/17. @@ -232,8 +232,8 @@ public class ActionStringHandler { 0d, percentage, useBolusIOB, useBasalIOB, false, useTrend); Double insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(bolusWizard.calculatedTotalInsulin)).value(); - if (insulinAfterConstraints - bolusWizard.calculatedTotalInsulin != 0) { - sendError("Insulin contraint violation!" + + if (Math.abs(insulinAfterConstraints - bolusWizard.calculatedTotalInsulin) >= 0.01) { + sendError("Insulin constraint violation!" + "\nCannot deliver " + format.format(bolusWizard.calculatedTotalInsulin) + "!"); return; } @@ -452,7 +452,7 @@ public class ActionStringHandler { PumpInterface danaRS = MainApp.getSpecificPlugin(DanaRSPlugin.class); PumpInterface danaV2 = MainApp.getSpecificPlugin(DanaRv2Plugin.class); PumpInterface danaKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class); - PumpInterface insight = MainApp.getSpecificPlugin(InsightPlugin.class); + PumpInterface insight = MainApp.getSpecificPlugin(LocalInsightPlugin.class); boolean startsYesterday = activePump == dana || activePump == danaRS || activePump == danaV2 || activePump == danaKorean || activePump == insight; @@ -693,7 +693,7 @@ public class ActionStringHandler { //send profile to pumpe new NewNSTreatmentDialog(); //init - NewNSTreatmentDialog.doProfileSwitch(0, percentage, timeshift); + ProfileFunctions.doProfileSwitch(0, percentage, timeshift); } private static void generateTempTarget(int duration, double low, double high) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearFragment.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearFragment.java index b1b47a4ae2..701784e9d9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearFragment.java @@ -1,6 +1,5 @@ -package info.nightscout.androidaps.plugins.Wear; +package info.nightscout.androidaps.plugins.general.wear; -import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.java similarity index 84% rename from app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.java index 72b2397213..2d7f13f221 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.java @@ -1,7 +1,8 @@ -package info.nightscout.androidaps.plugins.Wear; +package info.nightscout.androidaps.plugins.general.wear; import android.content.Context; import android.content.Intent; +import android.util.Log; import com.squareup.otto.Subscribe; @@ -9,7 +10,6 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventBolusRequested; import info.nightscout.androidaps.events.EventExtendedBolusChange; -import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshOverview; @@ -18,12 +18,13 @@ import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; -import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; -import info.nightscout.androidaps.plugins.Wear.wearintegration.WatchUpdaterService; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusprogressIfRunning; +import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.general.wear.wearintegration.WatchUpdaterService; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; +import info.nightscout.androidaps.utils.SP; /** * Created by adrian on 17/11/16. @@ -35,6 +36,8 @@ public class WearPlugin extends PluginBase { private final Context ctx; private static WearPlugin wearPlugin; + private static String TAG = "WearPlugin"; + public static WearPlugin getPlugin() { return wearPlugin; @@ -76,7 +79,10 @@ public class WearPlugin extends PluginBase { } private void sendDataToWatch(boolean status, boolean basals, boolean bgValue) { - if (isEnabled(getType())) { //only start service when this plugin is enabled + + //Log.d(TAG, "WR: WearPlugin:sendDataToWatch (status=" + status + ",basals=" + basals + ",bgValue=" + bgValue + ")"); + + if (isEnabled(getType())) { // only start service when this plugin is enabled if (bgValue) { ctx.startService(new Intent(ctx, WatchUpdaterService.class)); @@ -93,15 +99,20 @@ public class WearPlugin extends PluginBase { } void resendDataToWatch() { + //Log.d(TAG, "WR: WearPlugin:resendDataToWatch"); ctx.startService(new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_RESEND)); } void openSettings() { + //Log.d(TAG, "WR: WearPlugin:openSettings"); ctx.startService(new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_OPEN_SETTINGS)); } void requestNotificationCancel(String actionstring) { - Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_CANCEL_NOTIFICATION); + //Log.d(TAG, "WR: WearPlugin:requestNotificationCancel"); + + Intent intent = new Intent(ctx, WatchUpdaterService.class) + .setAction(WatchUpdaterService.ACTION_CANCEL_NOTIFICATION); intent.putExtra("actionstring", actionstring); ctx.startService(intent); } @@ -136,7 +147,7 @@ public class WearPlugin extends PluginBase { } @Subscribe - public void onStatusEvent(final EventNewBG ev) { + public void onStatusEvent(final EventAutosensCalculationFinished ev) { sendDataToWatch(true, true, true); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/SendToDataLayerThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/SendToDataLayerThread.java new file mode 100644 index 0000000000..aa6498563d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/SendToDataLayerThread.java @@ -0,0 +1,139 @@ +package info.nightscout.androidaps.plugins.general.wear.wearintegration; + +import android.os.AsyncTask; +import android.util.Log; + +import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.wearable.DataApi; +import com.google.android.gms.wearable.DataMap; +import com.google.android.gms.wearable.Node; +import com.google.android.gms.wearable.NodeApi; +import com.google.android.gms.wearable.PutDataMapRequest; +import com.google.android.gms.wearable.PutDataRequest; +import com.google.android.gms.wearable.Wearable; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantLock; + +/** + * Created by emmablack on 12/26/14. + */ +class SendToDataLayerThread extends AsyncTask { + private GoogleApiClient googleApiClient; + private static final String TAG = "SendToDataLayerThread"; + private String path; + private String logPrefix = ""; // "WR: "; + private static int concurrency = 0; + private static int state = 0; + private static final ReentrantLock lock = new ReentrantLock(); + private static long lastlock = 0; + private static final boolean testlockup = false; // always false in production + + + SendToDataLayerThread(String path, GoogleApiClient pGoogleApiClient) { + // Log.d(TAG, logPrefix + "SendToDataLayerThread: " + path); + this.path = path; + googleApiClient = pGoogleApiClient; + } + + + @Override + protected void onPreExecute() { + concurrency++; + if ((concurrency > 12) || ((concurrency > 3 && (lastlock != 0) && (tsl() - lastlock) > 300000))) { + // error if 9 concurrent threads or lock held for >5 minutes with concurrency of 4 + final String err = "Wear Integration deadlock detected!! " + ((lastlock != 0) ? "locked" : "") + " state:" + + state + " @" + hourMinuteString(tsl()); + // Home.toaststaticnext(err); + Log.e(TAG, logPrefix + err); + } + if (concurrency < 0) + Log.d(TAG, logPrefix + "Wear Integration impossible concurrency!!"); + + Log.d(TAG, logPrefix + "SendDataToLayerThread pre-execute concurrency: " + concurrency); + } + + + @Override + protected Void doInBackground(DataMap... params) { + if (testlockup) { + try { + Log.e(TAG, logPrefix + "WARNING RUNNING TEST LOCK UP CODE - NEVER FOR PRODUCTION"); + Thread.sleep(1000000); // DEEEBBUUGGGG + } catch (Exception e) { + } + } + sendToWear(params); + concurrency--; + Log.d(TAG, logPrefix + "SendDataToLayerThread post-execute concurrency: " + concurrency); + return null; + } + + + // Debug function to expose where it might be locking up + private synchronized void sendToWear(final DataMap... params) { + if (!lock.tryLock()) { + Log.d(TAG, logPrefix + "Concurrent access - waiting for thread unlock"); + lock.lock(); // enforce single threading + Log.d(TAG, logPrefix + "Thread unlocked - proceeding"); + } + lastlock = tsl(); + try { + if (state != 0) { + Log.e(TAG, logPrefix + "WEAR STATE ERROR: state=" + state); + } + state = 1; + final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(15, + TimeUnit.SECONDS); + + Log.d(TAG, logPrefix + "Nodes: " + nodes); + + state = 2; + for (Node node : nodes.getNodes()) { + state = 3; + for (DataMap dataMap : params) { + state = 4; + PutDataMapRequest putDMR = PutDataMapRequest.create(path); + state = 5; + putDMR.getDataMap().putAll(dataMap); + putDMR.setUrgent(); + state = 6; + PutDataRequest request = putDMR.asPutDataRequest(); + state = 7; + DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient, request).await(15, + TimeUnit.SECONDS); + state = 8; + if (result.getStatus().isSuccess()) { + Log.d(TAG, logPrefix + "DataMap: " + dataMap + " sent to: " + node.getDisplayName()); + } else { + Log.e(TAG, logPrefix + "ERROR: failed to send DataMap"); + result = Wearable.DataApi.putDataItem(googleApiClient, request).await(30, TimeUnit.SECONDS); + if (result.getStatus().isSuccess()) { + Log.d(TAG, logPrefix + "DataMap retry: " + dataMap + " sent to: " + node.getDisplayName()); + } else { + Log.e(TAG, logPrefix + "ERROR on retry: failed to send DataMap: " + + result.getStatus().toString()); + } + } + state = 9; + } + } + state = 0; + } catch (Exception e) { + Log.e(TAG, logPrefix + "Got exception in sendToWear: " + e.toString()); + } finally { + lastlock = 0; + lock.unlock(); + } + } + + + private static long tsl() { + return System.currentTimeMillis(); + } + + + private static String hourMinuteString(long timestamp) { + return android.text.format.DateFormat.format("kk:mm", timestamp).toString(); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java similarity index 84% rename from app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java index 8007e03164..52dbeed75c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java @@ -1,9 +1,17 @@ -package info.nightscout.androidaps.plugins.Wear.wearintegration; +package info.nightscout.androidaps.plugins.general.wear.wearintegration; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; +import android.os.AsyncTask; import android.os.BatteryManager; import android.os.Bundle; import android.os.Handler; @@ -14,8 +22,11 @@ import android.util.Log; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.wearable.CapabilityApi; +import com.google.android.gms.wearable.CapabilityInfo; import com.google.android.gms.wearable.DataMap; import com.google.android.gms.wearable.MessageEvent; +import com.google.android.gms.wearable.Node; import com.google.android.gms.wearable.PutDataMapRequest; import com.google.android.gms.wearable.PutDataRequest; import com.google.android.gms.wearable.Wearable; @@ -37,27 +48,29 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.TreatmentsInterface; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus; -import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.androidaps.plugins.Wear.ActionStringHandler; -import info.nightscout.androidaps.plugins.Wear.WearPlugin; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.SP; -import info.nightscout.utils.SafeParse; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus; +import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler; +import info.nightscout.androidaps.plugins.general.wear.WearPlugin; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.SafeParse; +import info.nightscout.androidaps.utils.ToastUtils; + +public class WatchUpdaterService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { -public class WatchUpdaterService extends WearableListenerService implements - GoogleApiClient.ConnectionCallbacks, - GoogleApiClient.OnConnectionFailedListener { public static final String ACTION_RESEND = WatchUpdaterService.class.getName().concat(".Resend"); public static final String ACTION_OPEN_SETTINGS = WatchUpdaterService.class.getName().concat(".OpenSettings"); public static final String ACTION_SEND_STATUS = WatchUpdaterService.class.getName().concat(".SendStatus"); @@ -92,6 +105,17 @@ public class WatchUpdaterService extends WearableListenerService implements private Handler handler; + // Phone + private static final String CAPABILITY_PHONE_APP = "phone_app_sync_bgs"; + private static final String MESSAGE_PATH_PHONE = "/phone_message_path"; + // Wear + private static final String CAPABILITY_WEAR_APP = "wear_app_sync_bgs"; + private static final String MESSAGE_PATH_WEAR = "/wear_message_path"; + private String mWearNodeId = null; + private String localnode = null; + private String logPrefix = ""; // "WR: " + + @Override public void onCreate() { mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); @@ -113,24 +137,24 @@ public class WatchUpdaterService extends WearableListenerService implements public void setSettings() { wear_integration = WearPlugin.getPlugin().isEnabled(PluginType.GENERAL); + // Log.d(TAG, "WR: wear_integration=" + wear_integration); if (wear_integration) { googleApiConnect(); } } - public void googleApiConnect() { + + private void googleApiConnect() { if (googleApiClient != null && (googleApiClient.isConnected() || googleApiClient.isConnecting())) { googleApiClient.disconnect(); } - googleApiClient = new GoogleApiClient.Builder(this) - .addConnectionCallbacks(this) - .addOnConnectionFailedListener(this) - .addApi(Wearable.API) - .build(); + googleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this) + .addOnConnectionFailedListener(this).addApi(Wearable.API).build(); Wearable.MessageApi.addListener(googleApiClient, this); if (googleApiClient.isConnected()) { - Log.d("WatchUpdater", "API client is connected"); + log.debug(logPrefix + "API client is connected"); } else { + // Log.d("WatchUpdater", logPrefix + "API client is not connected and is trying to connect"); googleApiClient.connect(); } } @@ -139,6 +163,8 @@ public class WatchUpdaterService extends WearableListenerService implements public int onStartCommand(Intent intent, int flags, int startId) { String action = intent != null ? intent.getAction() : null; + // Log.d(TAG, logPrefix + "onStartCommand: " + action); + if (wear_integration) { handler.post(() -> { if (googleApiClient.isConnected()) { @@ -178,13 +204,63 @@ public class WatchUpdaterService extends WearableListenerService implements } + private void updateWearSyncBgsCapability(CapabilityInfo capabilityInfo) { + Log.d("WatchUpdaterService", logPrefix + "CabilityInfo: " + capabilityInfo); + Set connectedNodes = capabilityInfo.getNodes(); + mWearNodeId = pickBestNodeId(connectedNodes); + } + + + private String pickBestNodeId(Set nodes) { + String bestNodeId = null; + // Find a nearby node or pick one arbitrarily + for (Node node : nodes) { + if (node.isNearby()) { + return node.getId(); + } + bestNodeId = node.getId(); + } + return bestNodeId; + } + + @Override public void onConnected(Bundle connectionHint) { + CapabilityApi.CapabilityListener capabilityListener = capabilityInfo -> { + updateWearSyncBgsCapability(capabilityInfo); + // Log.d(TAG, logPrefix + "onConnected onCapabilityChanged mWearNodeID:" + mWearNodeId); + // new CheckWearableConnected().execute(); + }; + + Wearable.CapabilityApi.addCapabilityListener(googleApiClient, capabilityListener, CAPABILITY_WEAR_APP); sendData(); } + + @Override + public void onPeerConnected(com.google.android.gms.wearable.Node peer) {// KS + super.onPeerConnected(peer); + String id = peer.getId(); + String name = peer.getDisplayName(); + // Log.d(TAG, logPrefix + "onPeerConnected peer name & ID: " + name + "|" + id); + } + + + @Override + public void onPeerDisconnected(com.google.android.gms.wearable.Node peer) {// KS + super.onPeerDisconnected(peer); + String id = peer.getId(); + String name = peer.getDisplayName(); + // Log.d(TAG, logPrefix + "onPeerDisconnected peer name & ID: " + name + "|" + id); + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + } + + @Override public void onMessageReceived(MessageEvent event) { + + // Log.d(TAG, logPrefix + "onMessageRecieved: " + event); + if (wear_integration) { if (event != null && event.getPath().equals(WEARABLE_RESEND_PATH)) { resendData(); @@ -215,6 +291,7 @@ public class WatchUpdaterService extends WearableListenerService implements private void sendData() { BgReading lastBG = DatabaseHelper.lastBg(); + // Log.d(TAG, logPrefix + "LastBg=" + lastBG); if (lastBG != null) { GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); @@ -229,18 +306,19 @@ public class WatchUpdaterService extends WearableListenerService implements return; } - new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(dataMap); + executeTask(new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient), dataMap); } } } + private DataMap dataMapSingleBG(BgReading lastBG, GlucoseStatus glucoseStatus) { String units = ProfileFunctions.getInstance().getProfileUnits(); Double lowLine = SafeParse.stringToDouble(mPrefs.getString("low_mark", "0")); Double highLine = SafeParse.stringToDouble(mPrefs.getString("high_mark", "0")); - //convert to mg/dl + // convert to mg/dl if (!units.equals(Constants.MGDL)) { lowLine *= Constants.MMOLL_TO_MGDL; highLine *= Constants.MMOLL_TO_MGDL; @@ -288,7 +366,6 @@ public class WatchUpdaterService extends WearableListenerService implements deltastring += "+"; } else { deltastring += "-"; - } boolean detailed = SP.getBoolean("wear_detailed_delta", false); @@ -353,7 +430,7 @@ public class WatchUpdaterService extends WearableListenerService implements } } entries.putDataMapArrayList("entries", dataMaps); - new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(entries); + executeTask(new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient), entries); } sendPreferences(); sendBasals(); @@ -502,7 +579,7 @@ public class WatchUpdaterService extends WearableListenerService implements dm.putDataMapArrayList("boluses", boluses); dm.putDataMapArrayList("predictions", predictions); - new SendToDataLayerThread(BASAL_DATA_PATH, googleApiClient).execute(dm); + executeTask(new SendToDataLayerThread(BASAL_DATA_PATH, googleApiClient), dm); } private DataMap tempDatamap(long startTime, double startBasal, long to, double toBasal, double amount) { @@ -549,6 +626,7 @@ public class WatchUpdaterService extends WearableListenerService implements dataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putString("openSettings", "openSettings"); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); + debugData("sendNotification", putDataRequest); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e("OpenSettings", "No connection to wearable available!"); @@ -564,6 +642,7 @@ public class WatchUpdaterService extends WearableListenerService implements dataMapRequest.getDataMap().putString("progressstatus", status); dataMapRequest.getDataMap().putInt("progresspercent", progresspercent); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); + debugData("sendBolusProgress", putDataRequest); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e("BolusProgress", "No connection to wearable available!"); @@ -583,6 +662,7 @@ public class WatchUpdaterService extends WearableListenerService implements log.debug("Requesting confirmation from wear: " + actionstring); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); + debugData("sendActionConfirmationRequest", putDataRequest); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e("confirmationRequest", "No connection to wearable available!"); @@ -602,6 +682,7 @@ public class WatchUpdaterService extends WearableListenerService implements log.debug("Requesting confirmation from wear: " + actionstring); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); + debugData("sendChangeConfirmationRequest", putDataRequest); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e("changeConfirmRequest", "No connection to wearable available!"); @@ -619,9 +700,10 @@ public class WatchUpdaterService extends WearableListenerService implements log.debug("Canceling notification on wear: " + actionstring); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); + debugData("sendCancelNotificationRequest", putDataRequest); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { - Log.e("cancelNotificationRequest", "No connection to wearable available!"); + Log.e("cancelNotificationReq", "No connection to wearable available!"); } } @@ -684,6 +766,7 @@ public class WatchUpdaterService extends WearableListenerService implements dataMapRequest.getDataMap().putBoolean("showBgi", mPrefs.getBoolean("wear_showbgi", false)); dataMapRequest.getDataMap().putInt("batteryLevel", (phoneBattery >= 30) ? 1 : 0); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); + debugData("sendStatus", putDataRequest); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e("SendStatus", "No connection to wearable available!"); @@ -700,12 +783,29 @@ public class WatchUpdaterService extends WearableListenerService implements dataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putBoolean("wearcontrol", wearcontrol); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); + debugData("sendPreferences", putDataRequest); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e("SendStatus", "No connection to wearable available!"); } } + + private void debugData(String source, Object data) { + // Log.d(TAG, "WR: " + source + " " + data); + } + + + private void executeTask(AsyncTask task, DataMap... parameters) { + task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Object[])parameters); + // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + // task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + // } else { + // task.execute(); + // } + } + + @NonNull private String generateStatusString(Profile profile, String currentBasal, String iobSum, String iobDetail, String bgiString) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatuslinePlugin.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatuslinePlugin.java index 9c4ec1551a..fe89cc8304 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatuslinePlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.XDripStatusline; +package info.nightscout.androidaps.plugins.general.xdripStatusline; import android.content.Context; import android.content.Intent; @@ -9,7 +9,6 @@ import android.support.annotation.NonNull; import com.squareup.otto.Subscribe; -import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.IobTotal; @@ -18,7 +17,6 @@ import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.events.EventAppInitialized; import info.nightscout.androidaps.events.EventConfigBuilderChange; import info.nightscout.androidaps.events.EventExtendedBolusChange; -import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.events.EventTempBasalChange; @@ -27,13 +25,13 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.TreatmentsInterface; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DecimalFormatter; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DecimalFormatter; /** * Created by adrian on 17/11/16. @@ -117,7 +115,7 @@ public class StatuslinePlugin extends PluginBase { if (ConfigBuilderPlugin.getPlugin().getActivePump() == null) return ""; - + LoopPlugin loopPlugin = LoopPlugin.getPlugin(); if (!loopPlugin.isEnabled(PluginType.LOOP)) { @@ -140,7 +138,7 @@ public class StatuslinePlugin extends PluginBase { IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round(); treatmentsInterface.updateTotalIOBTempBasals(); IobTotal basalIob = treatmentsInterface.getLastCalculationTempBasals().round(); - status += DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob)+"U"; + status += DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U"; if (mPrefs.getBoolean("xdripstatus_detailediob", true)) { @@ -184,7 +182,7 @@ public class StatuslinePlugin extends PluginBase { } @Subscribe - public void onStatusEvent(final EventNewBG ev) { + public void onStatusEvent(final EventAutosensCalculationFinished ev) { sendStatus(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/ActivityGraph.java b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/ActivityGraph.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/Insulin/ActivityGraph.java rename to app/src/main/java/info/nightscout/androidaps/plugins/insulin/ActivityGraph.java index 8bbd1d3e7f..fd8564cf73 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/ActivityGraph.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/ActivityGraph.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Insulin; +package info.nightscout.androidaps.plugins.insulin; import android.content.Context; import android.graphics.Color; @@ -12,7 +12,7 @@ import java.util.ArrayList; import java.util.List; import info.nightscout.androidaps.data.Iob; -import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.interfaces.InsulinInterface; /** diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinFragment.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinFragment.java index 79db5e1a8b..bcf445d0d1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Insulin; +package info.nightscout.androidaps.plugins.insulin; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -10,8 +10,8 @@ import android.widget.TextView; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.utils.FabricPrivacy; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.utils.FabricPrivacy; /** * Created by mike on 17.04.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePlugin.java similarity index 86% rename from app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePlugin.java index a2d80efd68..7700bf4c52 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePlugin.java @@ -1,18 +1,19 @@ -package info.nightscout.androidaps.plugins.Insulin; +package info.nightscout.androidaps.plugins.insulin; import com.squareup.otto.Bus; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Iob; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; /** * Created by adrian on 13.08.2017. @@ -62,7 +63,8 @@ public abstract class InsulinOrefBasePlugin extends PluginBase implements Insuli } public double getUserDefinedDia() { - return ProfileFunctions.getInstance().getProfile() != null ? ProfileFunctions.getInstance().getProfile().getDia() : MIN_DIA; + Profile profile = ProfileFunctions.getInstance().getProfile(); + return profile != null ? profile.getDia() : MIN_DIA; } public Iob iobCalcForTreatment(Treatment treatment, long time) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPlugin.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPlugin.java index c1fc44438f..3d32d2317b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPlugin.java @@ -1,8 +1,8 @@ -package info.nightscout.androidaps.plugins.Insulin; +package info.nightscout.androidaps.plugins.insulin; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by adrian on 14/08/17. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefRapidActingPlugin.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefRapidActingPlugin.java index c275aef3fd..5aceaaacaf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefRapidActingPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Insulin; +package info.nightscout.androidaps.plugins.insulin; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefUltraRapidActingPlugin.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefUltraRapidActingPlugin.java index 94e5910470..7e800cacc1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefUltraRapidActingPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Insulin; +package info.nightscout.androidaps.plugins.insulin; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensData.java similarity index 71% rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensData.java index 60a5851011..6a32c1084b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensData.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.IobCobCalculator; +package info.nightscout.androidaps.plugins.iob.iobCobCalculator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,15 +13,15 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.Scale; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityAAPSPlugin; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityWeightedAveragePlugin; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.Scale; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 25.04.2017. @@ -40,7 +40,7 @@ public class AutosensData implements DataPointWithLabelInterface { double min5minCarbImpact = 0d; double remaining = 0d; - public CarbsInPast(Treatment t) { + CarbsInPast(Treatment t) { time = t.date; carbs = t.carbs; remaining = t.carbs; @@ -56,6 +56,18 @@ public class AutosensData implements DataPointWithLabelInterface { min5minCarbImpact = SP.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact); } } + + CarbsInPast (CarbsInPast other) { + this.time = other.time; + this.carbs = other.carbs; + this.min5minCarbImpact = other.min5minCarbImpact; + this.remaining = other.remaining; + } + + @Override + public String toString() { + return String.format("CarbsInPast: time: %s carbs: %.02f min5minCI: %.02f remaining: %.2f", new Date(time).toLocaleString(), carbs, min5minCarbImpact, remaining); + } } public long time = 0L; @@ -89,11 +101,18 @@ public class AutosensData implements DataPointWithLabelInterface { @Override public String toString() { - return "AutosensData: " + new Date(time).toLocaleString() + " " + pastSensitivity + " Delta=" + delta + " avgDelta=" + avgDelta + " Bgi=" + bgi + " Deviation=" + deviation + " avgDeviation=" + avgDeviation + " Absorbed=" + absorbed + " CarbsFromBolus=" + carbsFromBolus + " COB=" + cob + " autosensRatio=" + autosensResult.ratio + " slopeFromMaxDeviation=" + slopeFromMaxDeviation + " slopeFromMinDeviation=" + slopeFromMinDeviation; + return String.format("AutosensData: %s pastSensitivity=%s delta=%.02f avgDelta=%.02f bgi=%.02f deviation=%.02f avgDeviation=%.02f absorbed=%.02f carbsFromBolus=%.02f cob=%.02f autosensRatio=%.02f slopeFromMaxDeviation=%.02f slopeFromMinDeviation=%.02f activeCarbsList=%s", + new Date(time).toLocaleString(), pastSensitivity, delta, avgDelta, bgi, deviation, avgDeviation, absorbed, carbsFromBolus, cob, autosensResult.ratio, slopeFromMaxDeviation, slopeFromMinDeviation, activeCarbsList.toString()); } - public int minOld() { - return (int) ((System.currentTimeMillis() - time) / 1000 / 60); + public List cloneCarbsList() { + List newActiveCarbsList = new ArrayList<>(); + + for(CarbsInPast c: activeCarbsList) { + newActiveCarbsList.add(new CarbsInPast(c)); + } + + return newActiveCarbsList; } // remove carbs older than timeframe @@ -111,7 +130,7 @@ public class AutosensData implements DataPointWithLabelInterface { if (c.remaining > 0) cob -= c.remaining; if (L.isEnabled(L.AUTOSENS)) - log.debug("Removing carbs at " + new Date(toTime).toLocaleString() + " + after " + maxAbsorptionHours + "h :" + new Date(c.time).toLocaleString()); + log.debug("Removing carbs at " + new Date(toTime).toLocaleString() + " after " + maxAbsorptionHours + "h > " + c.toString()); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensResult.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensResult.java index 7bd01fa7b2..082ebc057d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensResult.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.IobCobCalculator; +package info.nightscout.androidaps.plugins.iob.iobCobCalculator; import org.json.JSONException; import org.json.JSONObject; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/BasalData.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/BasalData.java similarity index 72% rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/BasalData.java rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/BasalData.java index d8bde8acbb..a4fa66fee1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/BasalData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/BasalData.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.IobCobCalculator; +package info.nightscout.androidaps.plugins.iob.iobCobCalculator; /** * Created by mike on 10.06.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/CobInfo.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/CobInfo.java similarity index 87% rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/CobInfo.java rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/CobInfo.java index d8b6d7674a..12d5cd5c11 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/CobInfo.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/CobInfo.java @@ -1,9 +1,9 @@ -package info.nightscout.androidaps.plugins.IobCobCalculator; +package info.nightscout.androidaps.plugins.iob.iobCobCalculator; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import info.nightscout.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.DecimalFormatter; public class CobInfo { /** All COB up to now, including carbs not yet processed by IobCob calculation. */ diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java index 951fa0b895..aac0985fba 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.IobCobCalculator; +package info.nightscout.androidaps.plugins.iob.iobCobCalculator; import android.os.SystemClock; import android.support.annotation.NonNull; @@ -31,17 +31,17 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData; -import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityOref1Plugin; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.T; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData; +import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.T; -import static info.nightscout.utils.DateUtil.now; +import static info.nightscout.androidaps.utils.DateUtil.now; /** * Created by mike on 24.04.2017. @@ -65,8 +65,6 @@ public class IobCobCalculatorPlugin extends PluginBase { private volatile List bgReadings = null; // newest at index 0 private volatile List bucketed_data = null; - private double dia = Constants.defaultDIA; - final Object dataLock = new Object(); boolean stopCalculationTrigger = false; @@ -118,11 +116,22 @@ public class IobCobCalculatorPlugin extends PluginBase { return rounded; } - void loadBgData(long now) { - long start = (long) (now - 60 * 60 * 1000L * (24 + dia)); - bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, now, false); - if (L.isEnabled(L.AUTOSENS)) - log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start) + " End date: " + DateUtil.dateAndTimeString(now)); + void loadBgData(long to) { + Profile profile = ProfileFunctions.getInstance().getProfile(to); + double dia = Constants.defaultDIA; + if (profile != null) dia = profile.getDia(); + long start = to - T.hours((long) (24 + dia)).msecs(); + if (DateUtil.isCloseToNow(to)) { + // if close to now expect there can be some readings with time in close future (caused by wrong time setting) + // so read all records + bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, false); + if (L.isEnabled(L.AUTOSENS)) + log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start)); + } else { + bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, to, false); + if (L.isEnabled(L.AUTOSENS)) + log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start) + " End date: " + DateUtil.dateAndTimeString(to)); + } } public boolean isAbout5minData() { @@ -146,8 +155,8 @@ public class IobCobCalculatorPlugin extends PluginBase { return false; } } - double averageDiff = totalDiff / (bgReadings.size() - 1) / 1000d; - boolean is5mindata = averageDiff < 10; + long averageDiff = totalDiff / bgReadings.size() / 1000; + boolean is5mindata = averageDiff < 1; if (L.isEnabled(L.AUTOSENS)) log.debug("Interval detection: values: " + bgReadings.size() + " averageDiff: " + averageDiff + "[s] is5minData: " + is5mindata); return is5mindata; @@ -231,13 +240,15 @@ public class IobCobCalculatorPlugin extends PluginBase { bucketed_data = new ArrayList<>(); bucketed_data.add(bgReadings.get(0)); + if (L.isEnabled(L.AUTOSENS)) + log.debug("Adding. bgTime: " + DateUtil.toISOString(bgReadings.get(0).date) + " lastbgTime: " + "none-first-value" + " " + bgReadings.get(0).toString()); int j = 0; for (int i = 1; i < bgReadings.size(); ++i) { long bgTime = bgReadings.get(i).date; long lastbgTime = bgReadings.get(i - 1).date; //log.error("Processing " + i + ": " + new Date(bgTime).toString() + " " + bgReadings.get(i).value + " Previous: " + new Date(lastbgTime).toString() + " " + bgReadings.get(i - 1).value); if (bgReadings.get(i).value < 39 || bgReadings.get(i - 1).value < 39) { - continue; + throw new IllegalStateException("<39"); } long elapsed_minutes = (bgTime - lastbgTime) / (60 * 1000); @@ -294,6 +305,13 @@ public class IobCobCalculatorPlugin extends PluginBase { long adjusted = (msecDiff - T.mins(5).msecs()) / 1000; if (L.isEnabled(L.AUTOSENS)) log.debug("Adjusting bucketed data time. Current: " + DateUtil.toISOString(current.date) + " to: " + DateUtil.toISOString(previous.date + T.mins(5).msecs()) + " by " + adjusted + " sec"); + if (Math.abs(adjusted) > 90) { + // too big adjustment, fallback to non 5 min data + if (L.isEnabled(L.AUTOSENS)) + log.debug("Fallback to non 5 min data"); + createBucketedDataRecalculated(); + return; + } current.date = previous.date + T.mins(5).msecs(); } @@ -599,10 +617,6 @@ public class IobCobCalculatorPlugin extends PluginBase { } if (ConfigBuilderPlugin.getPlugin() == null) return; // app still initializing - Profile profile = ProfileFunctions.getInstance().getProfile(); - if (profile == null) - return; // app still initializing - dia = profile.getDia(); if (ev == null) { // on init no need of reset return; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobOref1Thread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobOref1Thread.java rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java index 4032546f7a..e27f27c26f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobOref1Thread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.IobCobCalculator; +package info.nightscout.androidaps.plugins.iob.iobCobCalculator; import android.content.Context; import android.os.PowerManager; @@ -26,20 +26,24 @@ import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventIobCalculationProgress; -import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress; +import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.MidnightTime; +import info.nightscout.androidaps.utils.Profiler; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.T; -import static info.nightscout.utils.DateUtil.now; +import static info.nightscout.androidaps.utils.DateUtil.now; import static java.util.Calendar.MINUTE; /** @@ -58,7 +62,7 @@ public class IobCobOref1Thread extends Thread { private PowerManager.WakeLock mWakeLock; - public IobCobOref1Thread(IobCobCalculatorPlugin plugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) { + IobCobOref1Thread(IobCobCalculatorPlugin plugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) { super(); this.iobCobCalculatorPlugin = plugin; @@ -69,12 +73,15 @@ public class IobCobOref1Thread extends Thread { this.end = end; PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE); - mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "iobCobThread"); + if (powerManager != null) + mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MainApp.gs(R.string.app_name) + ":iobCobThread"); } @Override public final void run() { - mWakeLock.acquire(); + long start = DateUtil.now(); + if (mWakeLock != null) + mWakeLock.acquire(T.mins(10).msecs()); try { if (L.isEnabled(L.AUTOSENS)) log.debug("AUTOSENSDATA thread started: " + from); @@ -148,7 +155,7 @@ public class IobCobOref1Thread extends Thread { AutosensData autosensData = new AutosensData(); autosensData.time = bgTime; if (previous != null) - autosensData.activeCarbsList = new ArrayList<>(previous.activeCarbsList); + autosensData.activeCarbsList = previous.cloneCarbsList(); else autosensData.activeCarbsList = new ArrayList<>(); @@ -169,7 +176,7 @@ public class IobCobOref1Thread extends Thread { double bgi = -iob.activity * sens * 5; double deviation = delta - bgi; - double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000; + double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000d; double slopeFromMaxDeviation = 0; double slopeFromMinDeviation = 999; @@ -242,6 +249,7 @@ public class IobCobOref1Thread extends Thread { for (int ir = 0; ir < recentTreatments.size(); ir++) { autosensData.carbsFromBolus += recentTreatments.get(ir).carbs; autosensData.activeCarbsList.add(new AutosensData.CarbsInPast(recentTreatments.get(ir))); + autosensData.pastSensitivity += "[" + DecimalFormatter.to0Decimal(recentTreatments.get(ir).carbs) + "g]"; } @@ -339,19 +347,19 @@ public class IobCobOref1Thread extends Thread { // Exclude meal-related deviations (carb absorption) from autosens if (autosensData.type.equals("non-meal")) { if (Math.abs(deviation) < Constants.DEVIATION_TO_BE_EQUAL) { - autosensData.pastSensitivity = "="; + autosensData.pastSensitivity += "="; autosensData.validDeviation = true; } else if (deviation > 0) { - autosensData.pastSensitivity = "+"; + autosensData.pastSensitivity += "+"; autosensData.validDeviation = true; } else { - autosensData.pastSensitivity = "-"; + autosensData.pastSensitivity += "-"; autosensData.validDeviation = true; } } else if (autosensData.type.equals("uam")) { - autosensData.pastSensitivity = "u"; + autosensData.pastSensitivity += "u"; } else { - autosensData.pastSensitivity = "x"; + autosensData.pastSensitivity += "x"; } //log.debug("TIME: " + new Date(bgTime).toString() + " BG: " + bg + " SENS: " + sens + " DELTA: " + delta + " AVGDELTA: " + avgDelta + " IOB: " + iob.iob + " ACTIVITY: " + iob.activity + " BGI: " + bgi + " DEVIATION: " + deviation); @@ -389,10 +397,14 @@ public class IobCobOref1Thread extends Thread { MainApp.bus().post(new EventAutosensCalculationFinished(cause)); }).start(); } finally { - mWakeLock.release(); + if (mWakeLock != null) + mWakeLock.release(); MainApp.bus().post(new EventIobCalculationProgress("")); - if (L.isEnabled(L.AUTOSENS)) + if (L.isEnabled(L.AUTOSENS)) { log.debug("AUTOSENSDATA thread ended: " + from); + log.debug("Midnights: " + MidnightTime.log()); + } + Profiler.log(log, "IobCobOref1Thread", start); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java similarity index 87% rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java index 07df247a21..2970f07aca 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.IobCobCalculator; +package info.nightscout.androidaps.plugins.iob.iobCobCalculator; import android.content.Context; import android.os.PowerManager; @@ -24,22 +24,26 @@ import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventIobCalculationProgress; -import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityAAPSPlugin; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityWeightedAveragePlugin; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress; +import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.MidnightTime; +import info.nightscout.androidaps.utils.Profiler; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.T; -import static info.nightscout.utils.DateUtil.now; +import static info.nightscout.androidaps.utils.DateUtil.now; /** * Created by mike on 23.01.2018. @@ -57,7 +61,7 @@ public class IobCobThread extends Thread { private PowerManager.WakeLock mWakeLock; - public IobCobThread(IobCobCalculatorPlugin plugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) { + IobCobThread(IobCobCalculatorPlugin plugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) { super(); this.iobCobCalculatorPlugin = plugin; @@ -68,12 +72,15 @@ public class IobCobThread extends Thread { this.end = end; PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE); - mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "iobCobThread"); + if (powerManager != null) + mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MainApp.gs(R.string.app_name) + ":iobCobThread"); } @Override public final void run() { - mWakeLock.acquire(); + long start = DateUtil.now(); + if (mWakeLock != null) + mWakeLock.acquire(T.mins(10).msecs()); try { if (L.isEnabled(L.AUTOSENS)) log.debug("AUTOSENSDATA thread started: " + from); @@ -147,7 +154,7 @@ public class IobCobThread extends Thread { AutosensData autosensData = new AutosensData(); autosensData.time = bgTime; if (previous != null) - autosensData.activeCarbsList = new ArrayList<>(previous.activeCarbsList); + autosensData.activeCarbsList = previous.cloneCarbsList(); else autosensData.activeCarbsList = new ArrayList<>(); @@ -168,7 +175,7 @@ public class IobCobThread extends Thread { double bgi = -iob.activity * sens * 5; double deviation = delta - bgi; - double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000; + double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000d; double slopeFromMaxDeviation = 0; double slopeFromMinDeviation = 999; @@ -241,6 +248,7 @@ public class IobCobThread extends Thread { for (int ir = 0; ir < recentTreatments.size(); ir++) { autosensData.carbsFromBolus += recentTreatments.get(ir).carbs; autosensData.activeCarbsList.add(new AutosensData.CarbsInPast(recentTreatments.get(ir))); + autosensData.pastSensitivity += "[" + DecimalFormatter.to0Decimal(recentTreatments.get(ir).carbs) + "g]"; } @@ -284,17 +292,17 @@ public class IobCobThread extends Thread { // calculate autosens only without COB if (autosensData.cob <= 0) { if (Math.abs(deviation) < Constants.DEVIATION_TO_BE_EQUAL) { - autosensData.pastSensitivity = "="; + autosensData.pastSensitivity += "="; autosensData.validDeviation = true; } else if (deviation > 0) { - autosensData.pastSensitivity = "+"; + autosensData.pastSensitivity += "+"; autosensData.validDeviation = true; } else { - autosensData.pastSensitivity = "-"; + autosensData.pastSensitivity += "-"; autosensData.validDeviation = true; } } else { - autosensData.pastSensitivity = "C"; + autosensData.pastSensitivity += "C"; } //log.debug("TIME: " + new Date(bgTime).toString() + " BG: " + bg + " SENS: " + sens + " DELTA: " + delta + " AVGDELTA: " + avgDelta + " IOB: " + iob.iob + " ACTIVITY: " + iob.activity + " BGI: " + bgi + " DEVIATION: " + deviation); @@ -316,10 +324,14 @@ public class IobCobThread extends Thread { MainApp.bus().post(new EventAutosensCalculationFinished(cause)); }).start(); } finally { - mWakeLock.release(); + if (mWakeLock != null) + mWakeLock.release(); MainApp.bus().post(new EventIobCalculationProgress("")); - if (L.isEnabled(L.AUTOSENS)) + if (L.isEnabled(L.AUTOSENS)) { log.debug("AUTOSENSDATA thread ended: " + from); + log.debug("Midnights: " + MidnightTime.log()); + } + Profiler.log(log, "IobCobThread", start); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventAutosensCalculationFinished.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventAutosensCalculationFinished.java similarity index 82% rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventAutosensCalculationFinished.java rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventAutosensCalculationFinished.java index 2cb9b7ca4c..25622843e7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventAutosensCalculationFinished.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventAutosensCalculationFinished.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.IobCobCalculator.events; +package info.nightscout.androidaps.plugins.iob.iobCobCalculator.events; import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.events.EventLoop; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventIobCalculationProgress.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventIobCalculationProgress.java similarity index 76% rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventIobCalculationProgress.java rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventIobCalculationProgress.java index 08f2747e60..5a4a9a8eae 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventIobCalculationProgress.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventIobCalculationProgress.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.IobCobCalculator.events; +package info.nightscout.androidaps.plugins.iob.iobCobCalculator.events; import info.nightscout.androidaps.events.Event; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventNewHistoryData.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventNewHistoryData.java similarity index 77% rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventNewHistoryData.java rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventNewHistoryData.java index 8814741099..f84fdd1adf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventNewHistoryData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventNewHistoryData.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.IobCobCalculator.events; +package info.nightscout.androidaps.plugins.iob.iobCobCalculator.events; import info.nightscout.androidaps.events.Event; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.java index fc45928f89..ec5dc55fa8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ProfileLocal; +package info.nightscout.androidaps.plugins.profile.local; import android.app.Activity; @@ -15,9 +15,6 @@ import android.widget.TextView; import com.squareup.otto.Subscribe; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.text.DecimalFormat; import info.nightscout.androidaps.MainApp; @@ -25,16 +22,15 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.interfaces.PumpDescription; -import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; -import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; -import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.NumberPicker; -import info.nightscout.utils.SafeParse; -import info.nightscout.utils.TimeListEdit; +import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment; +import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog; +import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.NumberPicker; +import info.nightscout.androidaps.utils.SafeParse; +import info.nightscout.androidaps.utils.TimeListEdit; public class LocalProfileFragment extends SubscriberFragment { NumberPicker diaView; @@ -156,7 +152,7 @@ public class LocalProfileFragment extends SubscriberFragment { public String getSumLabel() { ProfileStore profile = LocalProfilePlugin.getPlugin().createProfileStore(); if (profile != null) - return " ∑" + DecimalFormatter.to2Decimal(profile.getDefaultProfile().baseBasalSum()) + "U"; + return " ∑" + DecimalFormatter.to2Decimal(profile.getDefaultProfile().baseBasalSum()) + MainApp.gs(R.string.insulin_unit_shortname); else return MainApp.gs(R.string.localprofile); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.java index 7a06860327..06f979876c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ProfileLocal; +package info.nightscout.androidaps.plugins.profile.local; import android.support.annotation.NonNull; @@ -18,8 +18,8 @@ import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 05.08.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.java similarity index 87% rename from app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.java index e3aeca0c45..66b895839d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ProfileNS; +package info.nightscout.androidaps.plugins.profile.ns; import android.app.Activity; import android.os.Bundle; @@ -22,13 +22,12 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.ProfileStore; -import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.ProfileNS.events.EventNSProfileUpdateGUI; -import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileGraph; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.OKDialog; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.profile.ns.events.EventNSProfileUpdateGUI; +import info.nightscout.androidaps.plugins.treatments.fragments.ProfileGraph; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.OKDialog; import static butterknife.OnItemSelected.Callback.NOTHING_SELECTED; @@ -52,6 +51,8 @@ public class NSProfileFragment extends SubscriberFragment { TextView isf; @BindView(R.id.profileview_basal) TextView basal; + @BindView(R.id.profileview_basaltotal) + TextView basaltotal; @BindView(R.id.profileview_target) TextView target; @BindView(R.id.basal_graph) @@ -116,6 +117,7 @@ public class NSProfileFragment extends SubscriberFragment { ic.setText(profile.getIcList()); isf.setText(profile.getIsfList()); basal.setText(profile.getBasalList()); + basaltotal.setText(String.format(MainApp.gs(R.string.profile_total), DecimalFormatter.to2Decimal(profile.baseBasalSum()))); target.setText(profile.getTargetList()); basalGraph.show(profile); } @@ -141,6 +143,7 @@ public class NSProfileFragment extends SubscriberFragment { ic.setText(""); isf.setText(""); basal.setText(""); + basaltotal.setText(""); target.setText(""); activateButton.setVisibility(View.GONE); } @@ -153,7 +156,7 @@ public class NSProfileFragment extends SubscriberFragment { Profile profile = store.getSpecificProfile(name); if (profile != null) { OKDialog.showConfirmation(getActivity(), MainApp.gs(R.string.activate_profile) + ": " + name + " ?", () -> - NewNSTreatmentDialog.doProfileSwitch(store, name, 0, 100, 0) + ProfileFunctions.doProfileSwitch(store, name, 0, 100, 0) ); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.java index 99e4ad9115..11c38d1492 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ProfileNS; +package info.nightscout.androidaps.plugins.profile.ns; import android.content.Intent; import android.os.Bundle; @@ -21,8 +21,8 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.ProfileInterface; -import info.nightscout.androidaps.plugins.ProfileNS.events.EventNSProfileUpdateGUI; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.profile.ns.events.EventNSProfileUpdateGUI; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 05.08.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/events/EventNSProfileUpdateGUI.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/events/EventNSProfileUpdateGUI.java similarity index 72% rename from app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/events/EventNSProfileUpdateGUI.java rename to app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/events/EventNSProfileUpdateGUI.java index d24c59e511..bb8b9509e8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/events/EventNSProfileUpdateGUI.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/events/EventNSProfileUpdateGUI.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ProfileNS.events; +package info.nightscout.androidaps.plugins.profile.ns.events; import info.nightscout.androidaps.events.EventUpdateGui; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/simple/SimpleProfileFragment.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfileFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/profile/simple/SimpleProfileFragment.java index b4338366bd..b8a7d16be5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/simple/SimpleProfileFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ProfileSimple; +package info.nightscout.androidaps.plugins.profile.simple; import android.app.Activity; @@ -15,18 +15,15 @@ import android.widget.TextView; import com.squareup.otto.Subscribe; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventInitializationChanged; -import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; -import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; -import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.utils.SafeParse; +import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment; +import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog; +import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.utils.SafeParse; public class SimpleProfileFragment extends SubscriberFragment { EditText diaView; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/simple/SimpleProfilePlugin.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/profile/simple/SimpleProfilePlugin.java index 09742bd3f9..d3d3952fae 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/simple/SimpleProfilePlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.ProfileSimple; +package info.nightscout.androidaps.plugins.profile.simple; import android.content.SharedPreferences; import android.preference.PreferenceManager; @@ -19,7 +19,7 @@ import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 05.08.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboFragment.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboFragment.java index e1ae0286de..a533821d59 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboFragment.java @@ -1,8 +1,7 @@ -package info.nightscout.androidaps.plugins.PumpCombo; +package info.nightscout.androidaps.plugins.pump.combo; import android.app.Activity; -import android.app.AlertDialog; import android.graphics.Color; import android.graphics.Typeface; import android.os.Bundle; @@ -15,19 +14,17 @@ import android.widget.TextView; import com.squareup.otto.Subscribe; -import org.apache.commons.lang3.StringUtils; - -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Bolus; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.pump.combo.events.EventComboPumpUpdateGUI; import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.events.EventQueueChanged; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; public class ComboFragment extends SubscriberFragment implements View.OnClickListener { private TextView stateView; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java index 3f30071327..a84e3db9a8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo; +package info.nightscout.androidaps.plugins.pump.combo; import android.content.DialogInterface; import android.os.SystemClock; @@ -39,32 +39,33 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyCommands; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.WarningOrErrorCode; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tdd; -import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.SP; - +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.combo.events.EventComboPumpUpdateGUI; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BasalProfile; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BolusProgressReporter; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.CommandResult; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpWarningCodes; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.RuffyCommands; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.RuffyScripter; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.WarningOrErrorCode; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Bolus; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistory; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistoryRequest; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Tdd; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 05.08.2016. */ @@ -435,6 +436,23 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint return pump.basalProfile.hourlyRates[currentHour]; } + @Override + public double getReservoirLevel() { + return pump.reservoirLevel; + } + + @Override + public int getBatteryLevel() { + switch (pump.state.batteryState) { + case PumpState.EMPTY: + return 5; + case PumpState.LOW: + return 25; + default: + return 100; + } + } + private static BolusProgressReporter bolusProgressReporter = (state, percent, delivered) -> { EventOverviewBolusProgress event = EventOverviewBolusProgress.getInstance(); switch (state) { @@ -653,11 +671,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint } } - /** - * Updates a DetailedBolusInfo from a pump bolus and adds it as a Treatment to the DB. - * Handles edge cases when dates aren't unique which are extremely unlikely to occur, - * but if they do, the user should be warned since a bolus will be missing from calculations. - */ + /** Creates a treatment record based on the request in DetailBolusInfo and the delivered bolus. */ private boolean addBolusToTreatments(DetailedBolusInfo detailedBolusInfo, Bolus lastPumpBolus) { DetailedBolusInfo dbi = detailedBolusInfo.copy(); dbi.date = calculateFakeBolusDate(lastPumpBolus); @@ -665,15 +679,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint dbi.source = Source.PUMP; dbi.insulin = lastPumpBolus.amount; try { - boolean treatmentCreated = TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, false); - if (!treatmentCreated) { - log.error("Adding treatment record overrode an existing record: " + dbi); - if (dbi.isSMB) { - Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_error_updating_treatment_record), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); - } - return false; - } + TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, true); } catch (Exception e) { log.error("Adding treatment record failed", e); if (dbi.isSMB) { @@ -1149,6 +1155,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint return historyResult.success; } + /** Return value indicates whether a new record was created. */ private boolean updateDbFromPumpHistory(@NonNull PumpHistory history) { boolean updated = false; for (Bolus pumpBolus : history.bolusHistory) { @@ -1158,8 +1165,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint dbi.source = Source.PUMP; dbi.insulin = pumpBolus.amount; dbi.eventType = CareportalEvent.CORRECTIONBOLUS; - if (TreatmentsPlugin.getPlugin().getService().getPumpRecordById(dbi.pumpId) == null) { - TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, false); + if (TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, true)) { updated = true; } } @@ -1374,4 +1380,15 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint maxIob.setIfSmaller(0d, String.format(MainApp.gs(R.string.limitingmaxiob), 0d, MainApp.gs(R.string.unsafeusage)), this); return maxIob; } + + @Override + public List getCustomActions() { + return null; + } + + @Override + public void executeCustomAction(CustomActionType customActionType) { + + } + } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPump.java similarity index 59% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPump.java index aef0f2abd5..cfe459fb58 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPump.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo; +package info.nightscout.androidaps.plugins.pump.combo; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -6,11 +6,11 @@ import android.support.annotation.Nullable; import java.util.ArrayList; import java.util.List; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpAlert; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tdd; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BasalProfile; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Bolus; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpAlert; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Tdd; class ComboPump { boolean initialized = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/events/EventComboPumpUpdateGUI.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/events/EventComboPumpUpdateGUI.java similarity index 57% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/events/EventComboPumpUpdateGUI.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/events/EventComboPumpUpdateGUI.java index e9bf3f8415..72359b7db2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/events/EventComboPumpUpdateGUI.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/events/EventComboPumpUpdateGUI.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.events; +package info.nightscout.androidaps.plugins.pump.combo.events; /** * Created by mike on 24.05.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BasalProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/BasalProfile.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BasalProfile.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/BasalProfile.java index fa9c2dceb0..9cdee1c9fd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BasalProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/BasalProfile.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter; import java.util.Arrays; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BolusProgressReporter.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/BolusProgressReporter.java similarity index 77% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BolusProgressReporter.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/BolusProgressReporter.java index 59d334fe6f..6fb7c54201 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BolusProgressReporter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/BolusProgressReporter.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter; public interface BolusProgressReporter { enum State { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/CommandResult.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/CommandResult.java index b595d13d28..180f10f69d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/CommandResult.java @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter; import android.support.annotation.Nullable; import java.util.LinkedList; import java.util.List; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistory; public class CommandResult { /** True if a condition indicating a broken pump setup/configuration is detected */ diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpErrorCodes.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpErrorCodes.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpErrorCodes.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpErrorCodes.java index 63cd81e3a6..d557c067c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpErrorCodes.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpErrorCodes.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter; public class PumpErrorCodes { public static final int CARTRIDGE_EMPTY = 1; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpState.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpState.java index 963cdd8b4c..117ea88eb9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpState.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter; /** State displayed on the main screen of the pump. */ public class PumpState { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpWarningCodes.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpWarningCodes.java similarity index 87% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpWarningCodes.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpWarningCodes.java index 60d1898834..b3f87e6b92 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpWarningCodes.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpWarningCodes.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter; public class PumpWarningCodes { public static final int CARTRIDGE_LOW = 1; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/RuffyCommands.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/RuffyCommands.java index 5918023d1e..0567e1cb12 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/RuffyCommands.java @@ -1,6 +1,6 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistoryRequest; public interface RuffyCommands { /** Issues a bolus issues updates on progress through via {@link BolusProgressReporter}. */ diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/RuffyScripter.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/RuffyScripter.java index e69cf3b462..eb01c92c60 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/RuffyScripter.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter; import android.content.ComponentName; import android.content.Context; @@ -26,18 +26,18 @@ import java.util.Date; import java.util.List; import java.util.Objects; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadQuickInfoCommand; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.BolusCommand; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.CancelTbrCommand; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.Command; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.CommandException; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ConfirmAlertCommand; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadBasalProfileCommand; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadHistoryCommand; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadPumpStateCommand; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.SetBasalProfileCommand; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.SetTbrCommand; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.ReadQuickInfoCommand; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistoryRequest; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.BolusCommand; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.CancelTbrCommand; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.Command; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.CommandException; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.ConfirmAlertCommand; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.ReadBasalProfileCommand; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.ReadHistoryCommand; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.ReadPumpStateCommand; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.SetBasalProfileCommand; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.SetTbrCommand; /** * Provides scripting 'runtime' and operations. consider moving operations into a separate diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/WarningOrErrorCode.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/WarningOrErrorCode.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/WarningOrErrorCode.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/WarningOrErrorCode.java index a4e21da289..ae4723046e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/WarningOrErrorCode.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/WarningOrErrorCode.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter; import android.support.annotation.Nullable; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BaseCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/BaseCommand.java similarity index 85% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BaseCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/BaseCommand.java index 5cc3e98b23..6cd89f2938 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BaseCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/BaseCommand.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands; import android.support.annotation.NonNull; @@ -12,10 +12,10 @@ import java.util.Calendar; import java.util.Collections; import java.util.List; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.CommandResult; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpWarningCodes; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.RuffyScripter; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Bolus; public abstract class BaseCommand implements Command { // RS will inject itself here diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/BolusCommand.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/BolusCommand.java index 4188716553..da18cc5c53 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/BolusCommand.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands; import android.os.SystemClock; @@ -11,18 +11,16 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.WarningOrErrorCode; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BolusProgressReporter; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpWarningCodes; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.WarningOrErrorCode; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.RuffyScripter; -import static info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter.State.DELIVERED; -import static info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter.State.DELIVERING; -import static info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter.State.PROGRAMMING; -import static info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter.State.STOPPED; -import static info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter.State.STOPPING; +import static info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BolusProgressReporter.State.DELIVERED; +import static info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BolusProgressReporter.State.DELIVERING; +import static info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BolusProgressReporter.State.PROGRAMMING; +import static info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BolusProgressReporter.State.STOPPED; +import static info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BolusProgressReporter.State.STOPPING; public class BolusCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(BolusCommand.class); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CancelTbrCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/CancelTbrCommand.java similarity index 83% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CancelTbrCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/CancelTbrCommand.java index b1787005e1..4b54c87c42 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CancelTbrCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/CancelTbrCommand.java @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands; import org.monkey.d.ruffy.ruffy.driver.display.MenuType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpWarningCodes; public class CancelTbrCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(CancelTbrCommand.class); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/Command.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/Command.java similarity index 69% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/Command.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/Command.java index 152befe00d..cd6c30439a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/Command.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/Command.java @@ -1,9 +1,9 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands; import java.util.List; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.RuffyScripter; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.CommandResult; /** * Interface for all commands to be executed by the pump. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CommandException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/CommandException.java similarity index 75% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CommandException.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/CommandException.java index 77c1db5437..e92e5e32cf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CommandException.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/CommandException.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands; public class CommandException extends RuntimeException { public CommandException(String message) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ConfirmAlertCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ConfirmAlertCommand.java similarity index 87% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ConfirmAlertCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ConfirmAlertCommand.java index 636b6a624d..0b1fcc3821 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ConfirmAlertCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ConfirmAlertCommand.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands; public class ConfirmAlertCommand extends BaseCommand { private final int warningCode; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadBasalProfileCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadBasalProfileCommand.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadBasalProfileCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadBasalProfileCommand.java index 2c23d5814b..b7145d233d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadBasalProfileCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadBasalProfileCommand.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands; import org.monkey.d.ruffy.ruffy.driver.display.Menu; import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute; @@ -9,8 +9,8 @@ import org.slf4j.LoggerFactory; import java.util.Arrays; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BasalProfile; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState; public class ReadBasalProfileCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(ReadBasalProfileCommand.class); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadHistoryCommand.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadHistoryCommand.java index 04298acd56..5f23b7e66d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadHistoryCommand.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands; import android.support.annotation.NonNull; @@ -12,12 +12,12 @@ import org.slf4j.LoggerFactory; import java.util.Calendar; import java.util.Date; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpAlert; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tbr; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tdd; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Bolus; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpAlert; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistory; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistoryRequest; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Tbr; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Tdd; public class ReadHistoryCommand extends BaseCommand { private static Logger log = LoggerFactory.getLogger(ReadHistoryCommand.class); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadPumpStateCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadPumpStateCommand.java similarity index 82% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadPumpStateCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadPumpStateCommand.java index cfa8d0f329..19beb26fe6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadPumpStateCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadPumpStateCommand.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands; public class ReadPumpStateCommand extends BaseCommand { @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadQuickInfoCommand.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadQuickInfoCommand.java index 654861fddb..eb68f1c5e1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadQuickInfoCommand.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands; import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute; import org.monkey.d.ruffy.ruffy.driver.display.MenuType; @@ -9,8 +9,8 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Bolus; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistory; public class ReadQuickInfoCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(ReadQuickInfoCommand.class); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetBasalProfileCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/SetBasalProfileCommand.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetBasalProfileCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/SetBasalProfileCommand.java index f403c2a89b..4d18b3d24e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetBasalProfileCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/SetBasalProfileCommand.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands; import android.os.SystemClock; @@ -12,8 +12,8 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BasalProfile; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState; public class SetBasalProfileCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(SetBasalProfileCommand.class); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetTbrCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/SetTbrCommand.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetTbrCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/SetTbrCommand.java index f618d50156..a4459cea66 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetTbrCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/SetTbrCommand.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands; import android.os.SystemClock; @@ -12,9 +12,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.WarningOrErrorCode; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpWarningCodes; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.WarningOrErrorCode; public class SetTbrCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(SetTbrCommand.class); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Bolus.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Bolus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Bolus.java index a5d989c331..cf1450feb2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Bolus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Bolus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history; import java.util.Date; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/HistoryRecord.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/HistoryRecord.java similarity index 67% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/HistoryRecord.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/HistoryRecord.java index 57e173bb49..3857a8b877 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/HistoryRecord.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/HistoryRecord.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history; public abstract class HistoryRecord { public final long timestamp; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpAlert.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpAlert.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpAlert.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpAlert.java index 413a9ca69b..0797d77151 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpAlert.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpAlert.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history; import java.util.Date; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistory.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpHistory.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistory.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpHistory.java index ecc8a1a29f..0fffe13c50 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistory.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpHistory.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history; import android.support.annotation.NonNull; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistoryRequest.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpHistoryRequest.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistoryRequest.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpHistoryRequest.java index e785c1d67c..a121ea9425 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistoryRequest.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpHistoryRequest.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history; import java.util.Date; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tbr.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Tbr.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tbr.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Tbr.java index 41ec245e89..401fc026b7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tbr.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Tbr.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history; import java.util.Date; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tdd.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Tdd.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tdd.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Tdd.java index 5f799f229e..35d3d31df9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tdd.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Tdd.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history; +package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history; import java.util.Date; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/data/DoseSettings.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/DoseSettings.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/data/DoseSettings.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/DoseSettings.java index 21a893e943..f0cd1dbbf9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/data/DoseSettings.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/DoseSettings.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCommon.data; +package info.nightscout.androidaps.plugins.pump.common.data; /** * Created by andy on 02/05/2018. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/DoseStepSize.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/DoseStepSize.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/DoseStepSize.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/DoseStepSize.java index 421c441c32..7e4bd7762e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/DoseStepSize.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/DoseStepSize.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCommon.defs; +package info.nightscout.androidaps.plugins.pump.common.defs; /** * Created by andy on 02/05/2018. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpCapability.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpCapability.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpCapability.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpCapability.java index d3e29ded0a..dc6059eed7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpCapability.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpCapability.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCommon.defs; +package info.nightscout.androidaps.plugins.pump.common.defs; /** * Created by andy on 03/05/2018. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpTempBasalType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpTempBasalType.java similarity index 63% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpTempBasalType.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpTempBasalType.java index 167e886ea7..90304ca45f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpTempBasalType.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpTempBasalType.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCommon.defs; +package info.nightscout.androidaps.plugins.pump.common.defs; /** * Created by andy on 02/05/2018. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpType.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java index 1c064d0cf0..e1e7f2bf2b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpType.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpCommon.defs; +package info.nightscout.androidaps.plugins.pump.common.defs; import java.util.HashMap; @@ -6,7 +6,7 @@ import java.util.Map; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.PumpCommon.data.DoseSettings; +import info.nightscout.androidaps.plugins.pump.common.data.DoseSettings; @@ -56,7 +56,7 @@ public enum PumpType { AnimasVibe("Animas Vibe", 0.05d, null, // AnimasBolus? new DoseSettings(0.05d, 30, 12*60, 0.05d), // PumpTempBasalType.Percent, // - new DoseSettings(10, 30, 24*60, 0d, 200d), PumpCapability.BasalRate_Duration30minAllowed, // + new DoseSettings(10, 30, 24*60, 0d, 300d), PumpCapability.BasalRate_Duration30minAllowed, // 0.025d, 5d, 0d, null, PumpCapability.VirtualPumpCapabilities), // AnimasPing("Animas Ping", AnimasVibe), diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java index c50e635eb8..d6f25f9c02 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR; +package info.nightscout.androidaps.plugins.pump.danaR; import android.support.annotation.Nullable; @@ -8,6 +8,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Date; +import java.util.List; import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.MainApp; @@ -27,17 +28,19 @@ import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; -import info.nightscout.androidaps.plugins.PumpDanaR.services.AbstractDanaRExecutionService; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.Round; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin; +import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes; +import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractDanaRExecutionService; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.Round; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 28.01.2018. @@ -152,6 +155,12 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte return DanaRPump.getInstance().currentBasal; } + @Override + public double getReservoirLevel() { return DanaRPump.getInstance().reservoirRemainingUnits; } + + @Override + public int getBatteryLevel() { return DanaRPump.getInstance().batteryRemaining; } + @Override public void stopBolusDelivering() { if (sExecutionService == null) { @@ -467,4 +476,16 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte } // TODO: daily total constraint + + @Override + public List getCustomActions() { + return null; + } + + + @Override + public void executeCustomAction(CustomActionType customActionType) { + + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/BluetoothDevicePreference.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/BluetoothDevicePreference.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/BluetoothDevicePreference.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/BluetoothDevicePreference.java index e39fdcfdaa..d02bf4690a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/BluetoothDevicePreference.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/BluetoothDevicePreference.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR; +package info.nightscout.androidaps.plugins.pump.danaR; import android.bluetooth.*; import android.content.Context; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.java index 33d371dca3..e044a2db27 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR; +package info.nightscout.androidaps.plugins.pump.danaR; import android.app.Activity; @@ -32,18 +32,18 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog; -import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity; -import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRUserOptionsActivity; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.dialogs.ProfileViewDialog; +import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRHistoryActivity; +import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRUserOptionsActivity; +import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus; +import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.events.EventQueueChanged; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.SetWarnColor; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.SetWarnColor; public class DanaRFragment extends SubscriberFragment { private static Logger log = LoggerFactory.getLogger(L.PUMP); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java index dfdca746cb..2f7484cd6f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR; +package info.nightscout.androidaps.plugins.pump.danaR; import android.content.ComponentName; import android.content.Context; @@ -22,14 +22,14 @@ import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; -import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed; -import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.Round; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStartWithSpeed; +import info.nightscout.androidaps.plugins.pump.danaR.services.DanaRExecutionService; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.Round; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 05.08.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.java index 3a6b3b5786..baa636ea81 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR; +package info.nightscout.androidaps.plugins.pump.danaR; import org.json.JSONArray; import org.json.JSONException; @@ -7,20 +7,19 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.text.DecimalFormat; -import java.util.Date; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.logging.L; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 04.07.2016. */ public class DanaRPump { - private Logger log = LoggerFactory.getLogger(L.PUMP); + private static Logger log = LoggerFactory.getLogger(L.PUMP); private static DanaRPump instance = null; @@ -30,6 +29,7 @@ public class DanaRPump { } public static void reset() { + log.debug("DanaRPump reset"); instance = null; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/Dialogs/ProfileViewDialog.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/Dialogs/ProfileViewDialog.java index 06906aa0b4..2b09b180cf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/Dialogs/ProfileViewDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.Dialogs; +package info.nightscout.androidaps.plugins.pump.danaR.dialogs; import android.os.Bundle; import android.support.v4.app.DialogFragment; @@ -8,14 +8,13 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.interfaces.ProfileInterface; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileGraph; -import info.nightscout.utils.DecimalFormatter; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.treatments.fragments.ProfileGraph; +import info.nightscout.androidaps.utils.DecimalFormatter; /** * Created by mike on 10.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/SerialIOThread.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/SerialIOThread.java index a319353d63..c8141d1265 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/SerialIOThread.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR; +package info.nightscout.androidaps.plugins.pump.danaR; import android.bluetooth.BluetoothSocket; import android.os.SystemClock; @@ -11,10 +11,10 @@ import java.io.InputStream; import java.io.OutputStream; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageHashTable; -import info.nightscout.androidaps.plugins.PumpDanaR.services.AbstractSerialIOThread; -import info.nightscout.utils.CRC; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageHashTable; +import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractSerialIOThread; +import info.nightscout.androidaps.utils.CRC; /** * Created by mike on 17.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRHistoryActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRHistoryActivity.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.java index 5a3e127b9a..95c9f25e37 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRHistoryActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.activities; +package info.nightscout.androidaps.plugins.pump.danaR.activities; import android.app.Activity; import android.os.Bundle; @@ -32,16 +32,16 @@ import info.nightscout.androidaps.db.DanaRHistoryRecord; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes; +import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus; +import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; +import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin; import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.ToastUtils; public class DanaRHistoryActivity extends Activity { private static Logger log = LoggerFactory.getLogger(L.PUMP); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRNSHistorySync.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRNSHistorySync.java index eab9e8bc6e..a15c8d2883 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRNSHistorySync.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.activities; +package info.nightscout.androidaps.plugins.pump.danaR.activities; import org.json.JSONException; import org.json.JSONObject; @@ -14,11 +14,11 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.DanaRHistoryRecord; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus; -import info.nightscout.utils.DateUtil; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes; +import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; /** * Created by mike on 20.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.java index d2d08a5d0b..0f2ec5f4d2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.activities; +package info.nightscout.androidaps.plugins.pump.danaR.activities; import android.app.Activity; import android.os.Bundle; @@ -20,12 +20,12 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; -import info.nightscout.utils.NumberPicker; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin; +import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin; +import info.nightscout.androidaps.utils.NumberPicker; /** * Created by Rumen Georgiev on 5/31/2018. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageBase.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageBase.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageBase.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageBase.java index 0fd444412f..57244ecc20 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageBase.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageBase.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import android.annotation.TargetApi; import android.os.Build; @@ -13,7 +13,7 @@ import java.util.Date; import java.util.GregorianCalendar; import info.nightscout.androidaps.logging.L; -import info.nightscout.utils.CRC; +import info.nightscout.androidaps.utils.CRC; /* * 00 01 02 03 04 05 06 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTable.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTable.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTable.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTable.java index e7f1adca07..d7ec39f6b7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTable.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTable.java @@ -1,7 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import java.util.HashMap; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageOriginalNames.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageOriginalNames.java similarity index 99% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageOriginalNames.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageOriginalNames.java index a285ce5120..2cba96f838 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageOriginalNames.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageOriginalNames.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusProgress.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusProgress.java similarity index 87% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusProgress.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusProgress.java index 873824f966..6fb1993237 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusProgress.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusProgress.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -6,8 +6,8 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; -import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.treatments.Treatment; public class MsgBolusProgress extends MessageBase { private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStart.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStart.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStart.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStart.java index 06200d1f0c..4b7cd2ff41 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStart.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStart.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartWithSpeed.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStartWithSpeed.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartWithSpeed.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStartWithSpeed.java index a3160ff887..0c174807b3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartWithSpeed.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStartWithSpeed.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStop.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStop.java similarity index 86% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStop.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStop.java index fe5d47c131..39531b8b10 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStop.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStop.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -6,8 +6,8 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; -import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.treatments.Treatment; public class MsgBolusStop extends MessageBase { private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgCheckValue.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValue.java similarity index 87% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgCheckValue.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValue.java index e04d9243e7..d40f8f0cd6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgCheckValue.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValue.java @@ -1,12 +1,12 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; /** * Created by mike on 30.06.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgError.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgError.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.java index a8e67a98a0..f697894778 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgError.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -6,8 +6,8 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; +import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; public class MsgError extends MessageBase { private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAlarm.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAlarm.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAlarm.java index 7adb335e93..8abbf55c31 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAlarm.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAll.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAll.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.java index 0fe64a20f5..7de2489c91 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAll.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.java @@ -1,15 +1,13 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Date; - import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.DanaRHistoryRecord; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus; +import info.nightscout.androidaps.utils.DateUtil; public class MsgHistoryAll extends MessageBase { private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAllDone.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAllDone.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAllDone.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAllDone.java index e78771f99d..7b110dd45f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAllDone.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAllDone.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryBasalHour.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBasalHour.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryBasalHour.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBasalHour.java index f56e2af273..2599cc7434 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryBasalHour.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBasalHour.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryBolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBolus.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryBolus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBolus.java index d675ddc488..88978be98c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBolus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryCarbo.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryCarbo.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryCarbo.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryCarbo.java index 6755800bba..5682c3c85f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryCarbo.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryCarbo.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryDailyInsulin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDailyInsulin.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryDailyInsulin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDailyInsulin.java index 68d46f0d20..2bed9419dd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryDailyInsulin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDailyInsulin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryDone.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDone.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryDone.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDone.java index 63e51e24ba..eeaffd33a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryDone.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDone.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryError.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryError.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryError.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryError.java index 8d6d0615d4..0666e8915a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryError.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryError.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryGlucose.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryGlucose.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryGlucose.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryGlucose.java index 10fd68e3ab..114d392f40 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryGlucose.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryGlucose.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryNew.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNew.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryNew.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNew.java index 01f7197434..e93c440fac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryNew.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNew.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryNewDone.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNewDone.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryNewDone.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNewDone.java index fb9118e629..c58f55f2cf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryNewDone.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNewDone.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryRefill.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryRefill.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryRefill.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryRefill.java index 238a606cfb..1ccae856af 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryRefill.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryRefill.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistorySuspend.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistorySuspend.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistorySuspend.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistorySuspend.java index 7182722f97..1dac016f4d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistorySuspend.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistorySuspend.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBasic.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBasic.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBasic.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBasic.java index 61150079cd..9b7d7feaed 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBasic.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBasic.java @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class MsgInitConnStatusBasic extends MessageBase { private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBolus.java similarity index 80% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBolus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBolus.java index df9447cc45..27d5aa5d2d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBolus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -6,10 +6,10 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; /** * Created by mike on 28.05.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusOption.java similarity index 81% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusOption.java index f8f82e16d0..220a4d5fc0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusOption.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -6,11 +6,11 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; /** * Created by mike on 28.05.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTime.java similarity index 82% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTime.java index 5404c58837..72e538355a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTime.java @@ -1,22 +1,20 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Date; - import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; +import info.nightscout.androidaps.utils.DateUtil; public class MsgInitConnStatusTime extends MessageBase { private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgPCCommStart.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgPCCommStart.java similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgPCCommStart.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgPCCommStart.java index 6f92c3241c..3d2084371c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgPCCommStart.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgPCCommStart.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgPCCommStop.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgPCCommStop.java similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgPCCommStop.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgPCCommStop.java index 255bb17532..e942f6b6e8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgPCCommStop.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgPCCommStop.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetActivateBasalProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetActivateBasalProfile.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetActivateBasalProfile.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetActivateBasalProfile.java index 2d222f9601..22f962713b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetActivateBasalProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetActivateBasalProfile.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetBasalProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetBasalProfile.java similarity index 87% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetBasalProfile.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetBasalProfile.java index 3e87e4bf41..7ea6719e30 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetBasalProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetBasalProfile.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -6,8 +6,8 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; public class MsgSetBasalProfile extends MessageBase { private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetCarbsEntry.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetCarbsEntry.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetCarbsEntry.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetCarbsEntry.java index 59cbcdafa0..a00b5bfd72 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetCarbsEntry.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetCarbsEntry.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStart.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetExtendedBolusStart.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStart.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetExtendedBolusStart.java index 2577435e11..dad437ac72 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStart.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetExtendedBolusStart.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStop.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetExtendedBolusStop.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStop.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetExtendedBolusStop.java index 504db719ea..a19efe7488 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStop.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetExtendedBolusStop.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetSingleBasalProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetSingleBasalProfile.java similarity index 86% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetSingleBasalProfile.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetSingleBasalProfile.java index eabf383b94..29c70c9379 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetSingleBasalProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetSingleBasalProfile.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -6,8 +6,8 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; public class MsgSetSingleBasalProfile extends MessageBase { private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTempBasalStart.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStart.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTempBasalStart.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStart.java index c756af3491..adc6a0b4da 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTempBasalStart.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStart.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTempBasalStop.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStop.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTempBasalStop.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStop.java index 7b14e8e3e3..19427ee965 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTempBasalStop.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStop.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTime.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTime.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTime.java index 6842344959..2840ff3faa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTime.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTime.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory; import java.util.Date; import info.nightscout.androidaps.logging.L; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.utils.DateUtil; /** * Created by mike on 09.12.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetUserOptions.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetUserOptions.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetUserOptions.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetUserOptions.java index 7484966dba..07e4ff669d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetUserOptions.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetUserOptions.java @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; /** * Created by mike on 05.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingActiveProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingActiveProfile.java similarity index 84% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingActiveProfile.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingActiveProfile.java index 57ab6367b0..1776c48a20 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingActiveProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingActiveProfile.java @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; /** * Created by mike on 05.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasal.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasal.java similarity index 86% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasal.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasal.java index 899a5a08f0..dc05848b34 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasal.java @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; /** * Created by mike on 05.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasalProfileAll.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasalProfileAll.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasalProfileAll.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasalProfileAll.java index f231412e06..89a4228ab7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasalProfileAll.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasalProfileAll.java @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; /** diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingGlucose.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingGlucose.java similarity index 87% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingGlucose.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingGlucose.java index ded78c6272..70964a98b2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingGlucose.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingGlucose.java @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; /** * Created by mike on 05.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMaxValues.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMaxValues.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMaxValues.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMaxValues.java index 3c640e1870..1eb3defb90 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMaxValues.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMaxValues.java @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; /** diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMeal.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMeal.java similarity index 83% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMeal.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMeal.java index 558b8953c0..b8be76560b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMeal.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMeal.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -7,11 +7,11 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; /** * Created by mike on 13.12.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingProfileRatios.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatios.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingProfileRatios.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatios.java index 5b6ea9b6cf..17f18cb160 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingProfileRatios.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatios.java @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; /** * Created by mike on 05.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingProfileRatiosAll.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatiosAll.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingProfileRatiosAll.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatiosAll.java index 10d424657b..becdf5a745 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingProfileRatiosAll.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatiosAll.java @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; /** * Created by mike on 05.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingPumpTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTime.java similarity index 85% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingPumpTime.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTime.java index 0e57c6c2f8..d22352e69f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingPumpTime.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTime.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -6,8 +6,8 @@ import org.slf4j.LoggerFactory; import java.util.Date; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.utils.DateUtil; public class MsgSettingPumpTime extends MessageBase { private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingShippingInfo.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingShippingInfo.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingShippingInfo.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingShippingInfo.java index b700b0baa0..7362ecfdb1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingShippingInfo.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingShippingInfo.java @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; /** * Created by mike on 05.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingUserOptions.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingUserOptions.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingUserOptions.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingUserOptions.java index e45e2050db..2dce2a6e1f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingUserOptions.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingUserOptions.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory; import java.util.Arrays; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; /** * Created by Rumen Georgiev on 6/11/2018. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatus.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatus.java index 474c29daa1..70c0d3b944 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatus.java @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class MsgStatus extends MessageBase { private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBasic.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBasic.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBasic.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBasic.java index 8f81220885..6a0635c378 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBasic.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBasic.java @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class MsgStatusBasic extends MessageBase { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBolusExtended.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtended.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBolusExtended.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtended.java index 30e41e2704..9b27561d5a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBolusExtended.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtended.java @@ -1,19 +1,17 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import android.support.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.Source; -import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; public class MsgStatusBolusExtended extends MessageBase { private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusProfile.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusProfile.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusProfile.java index 079357c6ee..f4ee2be0a6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusProfile.java @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; /** * Created by mike on 05.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusTempBasal.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusTempBasal.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusTempBasal.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusTempBasal.java index db6080f74a..76fa0e9f43 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusTempBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusTempBasal.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; import android.support.annotation.NonNull; @@ -8,8 +8,8 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; public class MsgStatusTempBasal extends MessageBase { private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/RecordTypes.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/RecordTypes.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/RecordTypes.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/RecordTypes.java index f0de05810a..36f3402cc7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/RecordTypes.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/RecordTypes.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.comm; +package info.nightscout.androidaps.plugins.pump.danaR.comm; /** * Created by mike on 28.05.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRNewStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.java similarity index 69% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRNewStatus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.java index 55b0ab0998..9efdee1057 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRNewStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.events; +package info.nightscout.androidaps.plugins.pump.danaR.events; import info.nightscout.androidaps.events.Event; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRSyncStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRSyncStatus.java similarity index 77% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRSyncStatus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRSyncStatus.java index f2a5dc7b2a..5fc0bd740f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRSyncStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRSyncStatus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.events; +package info.nightscout.androidaps.plugins.pump.danaR.events; import info.nightscout.androidaps.events.Event; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractDanaRExecutionService.java similarity index 79% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractDanaRExecutionService.java index f45f222861..9e3c1ff3ca 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractDanaRExecutionService.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.services; +package info.nightscout.androidaps.plugins.pump.danaR.services; import android.app.Service; import android.bluetooth.BluetoothAdapter; @@ -23,25 +23,25 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStop; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryAlarm; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryBasalHour; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryBolus; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryCarbo; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryDailyInsulin; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryDone; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryError; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryGlucose; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryRefill; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistorySuspend; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgPCCommStart; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgPCCommStop; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.utils.SP; -import info.nightscout.utils.ToastUtils; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStop; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryAlarm; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryBasalHour; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryBolus; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryCarbo; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryDailyInsulin; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryDone; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryError; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryGlucose; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryRefill; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistorySuspend; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgPCCommStart; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgPCCommStop; +import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.ToastUtils; /** * Created by mike on 28.01.2018. @@ -55,7 +55,6 @@ public abstract class AbstractDanaRExecutionService extends Service { protected BluetoothSocket mRfcommSocket; protected BluetoothDevice mBTDevice; - protected DanaRPump mDanaRPump = DanaRPump.getInstance(); protected Treatment mBolusingTreatment = null; protected boolean mConnectionInProgress = false; @@ -237,4 +236,15 @@ public abstract class AbstractDanaRExecutionService extends Service { result.comment = "OK"; return result; } + + protected void waitForWholeMinute() { + while (true) { + long time = DateUtil.now(); + long timeToWholeMinute = (60000 - time % 60000); + if (timeToWholeMinute > 59800 || timeToWholeMinute < 3000) + break; + MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.waitingfortimesynchronization, (int) (timeToWholeMinute / 1000)))); + SystemClock.sleep(Math.min(timeToWholeMinute, 100)); + } + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractSerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractSerialIOThread.java similarity index 62% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractSerialIOThread.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractSerialIOThread.java index 1cca0b2512..6d2cba9741 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractSerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractSerialIOThread.java @@ -1,6 +1,6 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.services; +package info.nightscout.androidaps.plugins.pump.danaR.services; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; /** * Created by mike on 28.01.2018. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java similarity index 76% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java index 425e72ea04..4c61c92a4f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaR.services; +package info.nightscout.androidaps.plugins.pump.danaR.services; import android.bluetooth.BluetoothDevice; import android.content.IntentFilter; @@ -22,50 +22,50 @@ import info.nightscout.androidaps.events.EventProfileSwitchChange; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.SerialIOThread; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusProgress; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStart; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStop; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgCheckValue; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetActivateBasalProfile; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetBasalProfile; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetCarbsEntry; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetExtendedBolusStart; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetExtendedBolusStop; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTempBasalStart; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTempBasalStop; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTime; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetUserOptions; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingActiveProfile; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingBasal; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingGlucose; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingMaxValues; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingMeal; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingProfileRatios; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingProfileRatiosAll; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingPumpTime; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingShippingInfo; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingUserOptions; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatus; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBasic; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBolusExtended; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusTempBasal; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; -import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.BolusProgressDialog; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.SerialIOThread; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusProgress; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStart; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStartWithSpeed; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStop; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgCheckValue; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetActivateBasalProfile; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetBasalProfile; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetCarbsEntry; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetExtendedBolusStart; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetExtendedBolusStop; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTempBasalStart; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTempBasalStop; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTime; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetUserOptions; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingActiveProfile; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingBasal; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingGlucose; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingMaxValues; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingMeal; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingProfileRatios; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingProfileRatiosAll; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingPumpTime; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingShippingInfo; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingUserOptions; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatus; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusBasic; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusBolusExtended; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusTempBasal; +import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus; +import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.commands.Command; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; public class DanaRExecutionService extends AbstractDanaRExecutionService { @@ -133,6 +133,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { } public void getPumpStatus() { + DanaRPump danaRPump = DanaRPump.getInstance(); try { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpstatus))); MsgStatus statusMsg = new MsgStatus(); @@ -141,7 +142,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended(); MsgCheckValue checkValue = new MsgCheckValue(); - if (mDanaRPump.isNewPump) { + if (danaRPump.isNewPump) { mSerialIOThread.sendMessage(checkValue); if (!checkValue.received) { return; @@ -157,11 +158,11 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingbolusstatus))); long now = System.currentTimeMillis(); - mDanaRPump.lastConnection = now; + danaRPump.lastConnection = now; Profile profile = ProfileFunctions.getInstance().getProfile(); PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); - if (profile != null && Math.abs(mDanaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) { + if (profile != null && Math.abs(danaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings))); mSerialIOThread.sendMessage(new MsgSettingBasal()); if (!pump.isThisProfileSet(profile) && !ConfigBuilderPlugin.getPlugin().getCommandQueue().isRunning(Command.CommandType.BASALPROFILE)) { @@ -169,7 +170,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { } } - if (mDanaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) { + if (danaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings))); mSerialIOThread.sendMessage(new MsgSettingShippingInfo()); mSerialIOThread.sendMessage(new MsgSettingActiveProfile()); @@ -184,29 +185,29 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { mSerialIOThread.sendMessage(new MsgSettingUserOptions()); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime))); mSerialIOThread.sendMessage(new MsgSettingPumpTime()); - long timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L; + long timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L; if (L.isEnabled(L.PUMP)) log.debug("Pump time difference: " + timeDiff + " seconds"); if (Math.abs(timeDiff) > 10) { mSerialIOThread.sendMessage(new MsgSetTime(new Date())); mSerialIOThread.sendMessage(new MsgSettingPumpTime()); - timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L; + timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L; if (L.isEnabled(L.PUMP)) log.debug("Pump time difference: " + timeDiff + " seconds"); } - mDanaRPump.lastSettingsRead = now; + danaRPump.lastSettingsRead = now; } MainApp.bus().post(new EventDanaRNewStatus()); MainApp.bus().post(new EventInitializationChanged()); NSUpload.uploadDeviceStatus(); - if (mDanaRPump.dailyTotalUnits > mDanaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) { + if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) { if (L.isEnabled(L.PUMP)) - log.debug("Approaching daily limit: " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits); + log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits); if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.gs(R.string.approachingdailylimit), Notification.URGENT); MainApp.bus().post(new EventNewNotification(reportFail)); - NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits + "U"); + NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U"); lastApproachingDailyLimit = System.currentTimeMillis(); } } @@ -216,8 +217,9 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { } public boolean tempBasal(int percent, int durationInHours) { + DanaRPump danaRPump = DanaRPump.getInstance(); if (!isConnected()) return false; - if (mDanaRPump.isTempBasalInProgress) { + if (danaRPump.isTempBasalInProgress) { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStop()); SystemClock.sleep(500); @@ -262,6 +264,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { } public boolean bolus(double amount, int carbs, long carbtime, final Treatment t) { + DanaRPump danaRPump = DanaRPump.getInstance(); if (!isConnected()) return false; if (BolusProgressDialog.stopPressed) return false; @@ -335,13 +338,13 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { ConfigBuilderPlugin.getPlugin().getCommandQueue().independentConnect("bolusingInterrupted", new Callback() { @Override public void run() { - if (mDanaRPump.lastBolusTime > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old - t.insulin = mDanaRPump.lastBolusAmount; + if (danaRPump.lastBolusTime > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old + t.insulin = danaRPump.lastBolusAmount; if (L.isEnabled(L.PUMP)) - log.debug("Used bolus amount from history: " + mDanaRPump.lastBolusAmount); + log.debug("Used bolus amount from history: " + danaRPump.lastBolusAmount); } else { if (L.isEnabled(L.PUMP)) - log.debug("Bolus amount in history too old: " + DateUtil.dateAndTimeFullString(mDanaRPump.lastBolusTime)); + log.debug("Bolus amount in history too old: " + DateUtil.dateAndTimeFullString(danaRPump.lastBolusTime)); } synchronized (o) { o.notify(); @@ -379,6 +382,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { } public boolean updateBasalsInPump(final Profile profile) { + DanaRPump danaRPump = DanaRPump.getInstance(); if (!isConnected()) return false; MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.updatingbasalrates))); double[] basal = DanaRPump.getInstance().buildDanaRProfileRecord(profile); @@ -386,7 +390,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { mSerialIOThread.sendMessage(msgSet); MsgSetActivateBasalProfile msgActivate = new MsgSetActivateBasalProfile((byte) 0); mSerialIOThread.sendMessage(msgActivate); - mDanaRPump.lastSettingsRead = 0; // force read full settings + danaRPump.lastSettingsRead = 0; // force read full settings getPumpStatus(); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); return true; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java index 54f0beb89b..3b4aa0ee4c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRKorean; +package info.nightscout.androidaps.plugins.pump.danaRKorean; import android.content.ComponentName; import android.content.Context; @@ -22,16 +22,16 @@ import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; -import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType; -import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStart; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.Round; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; +import info.nightscout.androidaps.plugins.pump.danaR.AbstractDanaRPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStart; +import info.nightscout.androidaps.plugins.pump.danaRKorean.services.DanaRKoreanExecutionService; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.Round; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 05.08.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/SerialIOThread.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/SerialIOThread.java index ea12b2b9c4..5c47d7c7d1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/SerialIOThread.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRKorean; +package info.nightscout.androidaps.plugins.pump.danaRKorean; import android.bluetooth.BluetoothSocket; import android.os.SystemClock; @@ -11,11 +11,11 @@ import java.io.InputStream; import java.io.OutputStream; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; -import info.nightscout.androidaps.plugins.PumpDanaR.services.AbstractSerialIOThread; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MessageHashTable_k; -import info.nightscout.utils.CRC; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractSerialIOThread; +import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MessageHashTable_k; +import info.nightscout.androidaps.utils.CRC; /** * Created by mike on 17.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MessageHashTable_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTable_k.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MessageHashTable_k.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTable_k.java index 422391c127..30ac710724 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MessageHashTable_k.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTable_k.java @@ -1,12 +1,12 @@ -package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm; +package info.nightscout.androidaps.plugins.pump.danaRKorean.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.HashMap; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.*; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.comm.*; /** * Created by mike on 28.05.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgCheckValue_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgCheckValue_k.java similarity index 81% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgCheckValue_k.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgCheckValue_k.java index 7bde73d5a1..731c25d4d1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgCheckValue_k.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgCheckValue_k.java @@ -1,12 +1,12 @@ -package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm; +package info.nightscout.androidaps.plugins.pump.danaRKorean.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; /** * Created by mike on 30.06.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBasic_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBasic_k.java similarity index 81% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBasic_k.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBasic_k.java index 32253b0007..5c9ac9707b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBasic_k.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBasic_k.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm; +package info.nightscout.androidaps.plugins.pump.danaRKorean.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -6,11 +6,11 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; public class MsgInitConnStatusBasic_k extends MessageBase { private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBolus_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBolus_k.java similarity index 70% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBolus_k.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBolus_k.java index 4be04f538f..b77f8ee61c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBolus_k.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBolus_k.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm; +package info.nightscout.androidaps.plugins.pump.danaRKorean.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -6,11 +6,12 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; /** * Created by mike on 28.05.2016. @@ -51,5 +52,9 @@ public class MsgInitConnStatusBolus_k extends MessageBase { } else { MainApp.bus().post(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED)); } + + // This is last message of initial sequence + if (ConfigBuilderPlugin.getPlugin().getActivePump() != null) + ConfigBuilderPlugin.getPlugin().getActivePump().finishHandshaking(); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusTime_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusTime_k.java similarity index 81% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusTime_k.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusTime_k.java index d713bb5a6c..103c3a2234 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusTime_k.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusTime_k.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm; +package info.nightscout.androidaps.plugins.pump.danaRKorean.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -8,14 +8,14 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; +import info.nightscout.androidaps.utils.DateUtil; public class MsgInitConnStatusTime_k extends MessageBase { private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgSettingBasalProfileAll_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgSettingBasalProfileAll_k.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgSettingBasalProfileAll_k.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgSettingBasalProfileAll_k.java index 2455f59e14..cb131634ec 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgSettingBasalProfileAll_k.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgSettingBasalProfileAll_k.java @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm; +package info.nightscout.androidaps.plugins.pump.danaRKorean.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; /** diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgSettingBasal_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgSettingBasal_k.java similarity index 80% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgSettingBasal_k.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgSettingBasal_k.java index b149ceb2ad..99ad848289 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgSettingBasal_k.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgSettingBasal_k.java @@ -1,12 +1,12 @@ -package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm; +package info.nightscout.androidaps.plugins.pump.danaRKorean.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; /** * Created by mike on 05.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatusBasic_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgStatusBasic_k.java similarity index 87% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatusBasic_k.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgStatusBasic_k.java index d22c6e376a..e7752cfb8f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatusBasic_k.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgStatusBasic_k.java @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm; +package info.nightscout.androidaps.plugins.pump.danaRKorean.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; public class MsgStatusBasic_k extends MessageBase { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatus_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgStatus_k.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatus_k.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgStatus_k.java index 4d8b012244..4ef29247b2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatus_k.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgStatus_k.java @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm; +package info.nightscout.androidaps.plugins.pump.danaRKorean.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; public class MsgStatus_k extends MessageBase { private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java similarity index 74% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java index d419d7c1f1..056d336805 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRKorean.services; +package info.nightscout.androidaps.plugins.pump.danaRKorean.services; import android.bluetooth.BluetoothDevice; import android.content.IntentFilter; @@ -22,41 +22,42 @@ import info.nightscout.androidaps.events.EventProfileSwitchChange; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusProgress; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStart; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStop; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetCarbsEntry; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetExtendedBolusStart; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetExtendedBolusStop; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetSingleBasalProfile; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTempBasalStart; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTempBasalStop; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTime; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingBasal; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingGlucose; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingMaxValues; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingMeal; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingProfileRatios; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingPumpTime; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingShippingInfo; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBolusExtended; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusTempBasal; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; -import info.nightscout.androidaps.plugins.PumpDanaR.services.AbstractDanaRExecutionService; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.SerialIOThread; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgCheckValue_k; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgSettingBasal_k; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgStatusBasic_k; -import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.BolusProgressDialog; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusProgress; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStart; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStop; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetCarbsEntry; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetExtendedBolusStart; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetExtendedBolusStop; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetSingleBasalProfile; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTempBasalStart; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTempBasalStop; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTime; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingBasal; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingGlucose; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingMaxValues; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingMeal; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingProfileRatios; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingPumpTime; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingShippingInfo; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusBolusExtended; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusTempBasal; +import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus; +import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractDanaRExecutionService; +import info.nightscout.androidaps.plugins.pump.danaRKorean.SerialIOThread; +import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MsgCheckValue_k; +import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MsgSettingBasal_k; +import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MsgStatusBasic_k; +import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.queue.commands.Command; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.T; public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { @@ -137,6 +138,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { } public void getPumpStatus() { + DanaRPump danaRPump = DanaRPump.getInstance(); try { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpstatus))); //MsgStatus_k statusMsg = new MsgStatus_k(); @@ -145,7 +147,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended(); MsgCheckValue_k checkValue = new MsgCheckValue_k(); - if (mDanaRPump.isNewPump) { + if (danaRPump.isNewPump) { mSerialIOThread.sendMessage(checkValue); if (!checkValue.received) { return; @@ -161,11 +163,11 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingbolusstatus))); long now = System.currentTimeMillis(); - mDanaRPump.lastConnection = now; + danaRPump.lastConnection = now; Profile profile = ProfileFunctions.getInstance().getProfile(); PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); - if (profile != null && Math.abs(mDanaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) { + if (profile != null && Math.abs(danaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings))); mSerialIOThread.sendMessage(new MsgSettingBasal()); if (!pump.isThisProfileSet(profile) && !ConfigBuilderPlugin.getPlugin().getCommandQueue().isRunning(Command.CommandType.BASALPROFILE)) { @@ -173,7 +175,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { } } - if (mDanaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) { + if (danaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings))); mSerialIOThread.sendMessage(new MsgSettingShippingInfo()); mSerialIOThread.sendMessage(new MsgSettingMeal()); @@ -184,29 +186,31 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { mSerialIOThread.sendMessage(new MsgSettingProfileRatios()); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime))); mSerialIOThread.sendMessage(new MsgSettingPumpTime()); - long timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L; + long timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L; if (L.isEnabled(L.PUMP)) log.debug("Pump time difference: " + timeDiff + " seconds"); if (Math.abs(timeDiff) > 10) { - mSerialIOThread.sendMessage(new MsgSetTime(new Date())); + waitForWholeMinute(); // Dana can set only whole minute + // add 10sec to be sure we are over minute (will be cutted off anyway) + mSerialIOThread.sendMessage(new MsgSetTime(new Date(DateUtil.now() + T.secs(10).msecs()))); mSerialIOThread.sendMessage(new MsgSettingPumpTime()); - timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L; + timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L; if (L.isEnabled(L.PUMP)) log.debug("Pump time difference: " + timeDiff + " seconds"); } - mDanaRPump.lastSettingsRead = now; + danaRPump.lastSettingsRead = now; } MainApp.bus().post(new EventDanaRNewStatus()); MainApp.bus().post(new EventInitializationChanged()); NSUpload.uploadDeviceStatus(); - if (mDanaRPump.dailyTotalUnits > mDanaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) { + if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) { if (L.isEnabled(L.PUMP)) - log.debug("Approaching daily limit: " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits); + log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits); if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.gs(R.string.approachingdailylimit), Notification.URGENT); MainApp.bus().post(new EventNewNotification(reportFail)); - NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits + "U"); + NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U"); lastApproachingDailyLimit = System.currentTimeMillis(); } } @@ -216,8 +220,9 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { } public boolean tempBasal(int percent, int durationInHours) { + DanaRPump danaRPump = DanaRPump.getInstance(); if (!isConnected()) return false; - if (mDanaRPump.isTempBasalInProgress) { + if (danaRPump.isTempBasalInProgress) { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStop()); SystemClock.sleep(500); @@ -318,12 +323,13 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { } public boolean updateBasalsInPump(final Profile profile) { + DanaRPump danaRPump = DanaRPump.getInstance(); if (!isConnected()) return false; MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.updatingbasalrates))); double[] basal = DanaRPump.getInstance().buildDanaRProfileRecord(profile); MsgSetSingleBasalProfile msgSet = new MsgSetSingleBasalProfile(basal); mSerialIOThread.sendMessage(msgSet); - mDanaRPump.lastSettingsRead = 0; // force read full settings + danaRPump.lastSettingsRead = 0; // force read full settings getPumpStatus(); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); return true; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java index e3c8f9de94..d2eb132f61 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS; +package info.nightscout.androidaps.plugins.pump.danaRS; import android.content.ComponentName; import android.content.Context; @@ -16,6 +16,8 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; + import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -36,27 +38,29 @@ import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; -import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start; -import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange; -import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.Round; -import info.nightscout.utils.SP; -import info.nightscout.utils.T; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment; +import info.nightscout.androidaps.plugins.configBuilder.DetailedBolusInfoStorage; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRFragment; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start; +import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSDeviceChange; +import info.nightscout.androidaps.plugins.pump.danaRS.services.DanaRSService; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.Round; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.T; /** * Created by mike on 03.09.2017. @@ -373,6 +377,12 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte return DanaRPump.getInstance().currentBasal; } + @Override + public double getReservoirLevel() { return DanaRPump.getInstance().reservoirRemainingUnits; } + + @Override + public int getBatteryLevel() { return DanaRPump.getInstance().batteryRemaining; } + @Override public synchronized PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value(); @@ -415,6 +425,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte if (!result.success) { String error = "" + DanaRS_Packet_Bolus_Set_Step_Bolus_Start.errorCode; switch (DanaRS_Packet_Bolus_Set_Step_Bolus_Start.errorCode) { + // 4 reported as max bolus violation. Check later case 0x10: error = MainApp.gs(R.string.maxbolusviolation); break; @@ -806,4 +817,14 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte return loadHistory(RecordTypes.RECORD_TYPE_DAILY); } + @Override + public List getCustomActions() { + return null; + } + + @Override + public void executeCustomAction(CustomActionType customActionType) { + + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/BLEScanActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/BLEScanActivity.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.java index 7594e917c5..502c18cbc9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/BLEScanActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.java @@ -1,16 +1,12 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.activities; +package info.nightscout.androidaps.plugins.pump.danaRS.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.content.DialogInterface; import android.os.Bundle; import android.os.Handler; -import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.ViewGroup; @@ -18,17 +14,14 @@ 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; +import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSDeviceChange; +import info.nightscout.androidaps.utils.SP; public class BLEScanActivity extends AppCompatActivity { private ListView listView = null; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingHelperActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.java similarity index 87% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingHelperActivity.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.java index c67534ac75..a98d541963 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingHelperActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.activities; +package info.nightscout.androidaps.plugins.pump.danaRS.activities; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingProgressDialog.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingProgressDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingProgressDialog.java index 08c0ce0372..1d9943a5f5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingProgressDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.activities; +package info.nightscout.androidaps.plugins.pump.danaRS.activities; import android.app.Activity; @@ -17,7 +17,7 @@ import com.squareup.otto.Subscribe; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSPairingSuccess; +import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess; public class PairingProgressDialog extends DialogFragment implements View.OnClickListener { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRSMessageHashTable.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRSMessageHashTable.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.java index bda5d42207..a81aa3c9bc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRSMessageHashTable.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.java @@ -1,9 +1,7 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import java.util.HashMap; -import info.nightscout.androidaps.logging.L; - /** * Created by mike on 28.05.2016. */ 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/pump/danaRS/comm/DanaRS_Packet.java similarity index 99% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java index d913f50b94..28a081aaa8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import android.annotation.TargetApi; import android.os.Build; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.java index c33cd7b405..c850eace0a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_History_Events.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_History_Events.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.java index dd3e5398c9..f6364290c2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_History_Events.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -17,10 +17,10 @@ import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.configBuilder.DetailedBolusInfoStorage; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); @@ -45,6 +45,12 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet { public DanaRS_Packet_APS_History_Events(long from) { this(); GregorianCalendar cal = new GregorianCalendar(); + + if (from > DateUtil.now()) { + log.debug("Asked to load from the future"); + from = 0; + } + if (from != 0) cal.setTimeInMillis(from); else diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Set_Event_History.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Set_Event_History.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.java index f31bdf66e2..fda5f33959 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Set_Event_History.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -9,8 +9,8 @@ import java.util.Calendar; import java.util.GregorianCalendar; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.utils.DateUtil; public class DanaRS_Packet_APS_Set_Event_History extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java similarity index 83% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java index 3cb5523dfc..5cbda121ce 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -9,10 +9,10 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_Basal_Get_Basal_Rate extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.java index 60b9f6da51..04aa4cefb3 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -6,7 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_Basal_Get_Profile_Basal_Rate extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.java similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.java index 1beadfd705..6da58c7a43 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -6,7 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_Basal_Get_Profile_Number extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.java index 748d88f242..5724c5ff80 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import android.support.annotation.NonNull; @@ -8,8 +8,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.utils.DateUtil; public class DanaRS_Packet_Basal_Get_Temporary_Basal_State extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.java index 188c1df093..cef7c8ab92 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.java index f0f2691315..0020e3ffa1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.java index a42176cc59..d6ae1c94a7 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.java index 4f39fcfd2f..ab6f4174da 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.java index 65ef6ae1b1..5fbda1d902 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.java index bde3b622db..82c282adad 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.java index 1f6106ab83..f2abcbc164 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java index 0e5a3d79c4..73c7a8d8f0 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -8,10 +8,10 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_Bolus_Get_Bolus_Option extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.java index 9b5636eaaf..5dca32bdd3 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -7,7 +7,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_Bolus_Get_CIR_CF_Array extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.java index 194edd5d55..b024dd056c 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -6,7 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_Bolus_Get_Calculation_Information extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.java index 476ae7167f..60da3683ac 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -6,7 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.java index 7d561bd679..5f1bbc5a39 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -6,7 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_Bolus_Get_Dual_Bolus extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.java index 785d8d3fbe..2b857e3fc8 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -6,7 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_Bolus_Get_Extended_Bolus extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.java index a07652218f..15d2678451 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -6,7 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_Bolus_Get_Extended_Bolus_State extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.java index fda8778d08..9e66d9458b 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -6,7 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.java index 15ad57d83a..37c9d9138e 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.java index a9968eb7eb..755fff3829 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -8,8 +8,8 @@ import org.slf4j.LoggerFactory; import java.util.Date; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.utils.DateUtil; public class DanaRS_Packet_Bolus_Get_Step_Bolus_Information extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.java index cc4a26f24f..2013bd74eb 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.java index 15bde78a76..50a6871bd4 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.java index 023458e5dc..da11d172fc 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.java index 504b21bbc9..4337663d6d 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.java index 587e87df9d..e8d9df360c 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.java index 2e7b9be1ff..206a61b6f5 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java index e50fbd70b5..7ff91fa9ef 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -6,7 +6,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.data.ConstraintChecker; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.logging.L; 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java index e12b3db7f1..5e3fe3fbcd 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -9,8 +9,8 @@ import info.nightscout.androidaps.R; import com.cozmo.danar.util.BleCommandUtil; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; public class DanaRS_Packet_Bolus_Set_Step_Bolus_Stop extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Keep_Connection.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.java index 8adf46f742..306787d4ee 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Set_History_Save.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.java index 1c9af359e2..7c0b652979 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Delivery_Status.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.java index c64680379f..0f5e4a8e02 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_More_Information.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.java index b1553a2c05..f14197ac41 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory; import java.util.Date; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_General_Get_More_Information extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Password.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.java index dc5cbc59f0..0a4d15d456 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -6,7 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_General_Get_Password extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java similarity index 85% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java index 5c26e2ce74..7c0a0ec2ae 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -8,9 +8,9 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_General_Get_Pump_Check extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.java similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.java index f2cb14cf73..e1efa91296 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -6,8 +6,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.utils.DateUtil; public class DanaRS_Packet_General_Get_Shipping_Information extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.java index 2a3b136279..c154ac3476 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -6,7 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_General_Get_Today_Delivery_Total extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.java index 0d07ecc33d..65bf066023 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java index d8e5b95c14..75b969b1bc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -6,7 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_General_Initial_Screen_Information extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.java index f66c3c4afe..21a15b1dbd 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.java index 9f7570d4ce..b8771c1939 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_History_.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.java index aab933e787..ceaf49908b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -10,9 +10,9 @@ import java.util.GregorianCalendar; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.DanaRHistoryRecord; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes; +import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus; +import info.nightscout.androidaps.utils.DateUtil; public abstract class DanaRS_Packet_History_ extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_History_Alarm.java similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Alarm.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.java index e586166783..437804b102 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_History_Alarm.java @@ -1,12 +1,10 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Date; - import info.nightscout.androidaps.logging.L; public class DanaRS_Packet_History_Alarm extends DanaRS_Packet_History_ { 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/pump/danaRS/comm/DanaRS_Packet_History_All_History.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_All_History.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.java index f6411dca5f..68940dd4c5 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_History_All_History.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_History_Basal.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Basal.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.java index 76d485695c..0a94f16a40 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_History_Basal.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Blood_Glucose.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.java index e66db9bb78..dc0e00d844 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_History_Bolus.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Bolus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.java index 41a2bd0995..64fb26dd09 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_History_Bolus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Carbohydrate.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.java index 58d9fac3dc..9cd931718d 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_History_Daily.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Daily.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.java index b480f76258..35a154f5e6 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_History_Daily.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_History_Prime.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Prime.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.java index 28ea4c30f0..7ec05fc0e0 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_History_Prime.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_History_Refill.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Refill.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.java index 685c8e519e..e031ee1460 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_History_Refill.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_History_Suspend.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Suspend.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.java index ef787746ce..20f4de5098 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_History_Suspend.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_History_Temporary.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Temporary.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.java index 68526b5fb2..65f86c5b7f 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_History_Temporary.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Alarm.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.java index 799b3c248c..4fc28e4cc9 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; public class DanaRS_Packet_Notify_Alarm extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java index 836a52cb65..3c916dc399 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -8,8 +8,8 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; -import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.treatments.Treatment; public class DanaRS_Packet_Notify_Delivery_Complete extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java index c2eb232dac..290e9743ef 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -8,8 +8,8 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; -import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.treatments.Treatment; public class DanaRS_Packet_Notify_Delivery_Rate_Display extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.java index 8239bb34b7..0d7d9af2c5 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.java index b4bcbaef98..d12ed52c79 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory; import java.util.Date; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_Option_Get_Pump_Time extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_User_Option.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.java index 6c6d7d7185..457b7ab2b8 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -6,7 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_Option_Get_User_Option extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.java index f43f82fb15..58bf00e6a6 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; 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/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_User_Option.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.java index a64e1e5142..30fc07cfd0 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; @@ -6,7 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; public class DanaRS_Packet_Option_Set_User_Option extends DanaRS_Packet { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); 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/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Review_Bolus_Avg.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.java index 7a2421c310..50edd71bd6 100644 --- 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/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +package info.nightscout.androidaps.plugins.pump.danaRS.comm; import com.cozmo.danar.util.BleCommandUtil; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSDeviceChange.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSDeviceChange.java similarity index 70% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSDeviceChange.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSDeviceChange.java index dd9b86ebce..224f939ad7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSDeviceChange.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSDeviceChange.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.events; +package info.nightscout.androidaps.plugins.pump.danaRS.events; import info.nightscout.androidaps.events.Event; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPacket.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPacket.java similarity index 65% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPacket.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPacket.java index e42b6b1440..e0c401a27f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPacket.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPacket.java @@ -1,7 +1,7 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.events; +package info.nightscout.androidaps.plugins.pump.danaRS.events; import info.nightscout.androidaps.events.Event; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet; /** * Created by mike on 01.09.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPairingSuccess.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPairingSuccess.java similarity index 70% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPairingSuccess.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPairingSuccess.java index 433cdec9bf..e332e9e0b2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPairingSuccess.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPairingSuccess.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.events; +package info.nightscout.androidaps.plugins.pump.danaRS.events; import info.nightscout.androidaps.events.Event; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java index be241dbbfd..69ca9f1901 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.services; +package info.nightscout.androidaps.plugins.pump.danaRS.services; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; @@ -26,17 +26,17 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRS.activities.PairingHelperActivity; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRSMessageHashTable; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet; -import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSPacket; -import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSPairingSuccess; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin; +import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSMessageHashTable; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet; +import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPacket; +import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 23.09.2017. @@ -144,9 +144,9 @@ public class BLEComm { if (L.isEnabled(L.PUMPBTCOMM)) log.debug("Trying to create a new connection from: " + from); + mBluetoothDeviceName = device.getName(); mBluetoothGatt = device.connectGatt(service.getApplicationContext(), false, mGattCallback); setCharacteristicNotification(getUARTReadBTGattChar(), true); - mBluetoothDeviceName = device.getName(); return true; } @@ -662,7 +662,13 @@ public class BLEComm { private void SendPumpCheck() { // 1st message sent to pump after connect - byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK, null, getConnectDeviceName()); + String devicename = getConnectDeviceName(); + if(devicename == null || devicename.equals("")){ + Notification n = new Notification(Notification.DEVICENOTPAIRED, MainApp.gs(R.string.pairfirst), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(n)); + return; + } + byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK, null, devicename); if (L.isEnabled(L.PUMPBTCOMM)) log.debug(">>>>> " + "ENCRYPTION__PUMP_CHECK (0x00)" + " " + DanaRS_Packet.toHexString(bytes)); writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java similarity index 81% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java index cb823a3c88..47b1fbfe2a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRS.services; +package info.nightscout.androidaps.plugins.pump.danaRS.services; import android.app.Service; import android.content.Intent; @@ -24,64 +24,64 @@ import info.nightscout.androidaps.events.EventProfileSwitchChange; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; -import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; -import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_APS_Basal_Set_Temporary_Basal; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_APS_History_Events; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_APS_Set_Event_History; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Get_Basal_Rate; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Get_Profile_Number; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Get_Temporary_Basal_State; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Set_Profile_Basal_Rate; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Set_Profile_Number; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Set_Temporary_Basal; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Bolus_Option; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_CIR_CF_Array; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Calculation_Information; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Extended_Bolus_State; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Step_Bolus_Information; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Extended_Bolus; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Stop; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_General_Get_Pump_Check; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_General_Get_Shipping_Information; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_General_Initial_Screen_Information; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_General_Set_History_Upload_Mode; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Alarm; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Basal; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Blood_Glucose; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Bolus; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Carbohydrate; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Daily; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Prime; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Refill; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Suspend; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_Delivery_Complete; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_Delivery_Rate_Display; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Get_Pump_Time; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Get_User_Option; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Set_Pump_Time; -import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Set_User_Option; -import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.BolusProgressDialog; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes; +import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus; +import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_APS_Basal_Set_Temporary_Basal; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_APS_History_Events; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_APS_Set_Event_History; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Get_Basal_Rate; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Get_Profile_Number; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Get_Temporary_Basal_State; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Set_Profile_Basal_Rate; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Set_Profile_Number; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Set_Temporary_Basal; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Get_Bolus_Option; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Get_CIR_CF_Array; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Get_Calculation_Information; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Get_Extended_Bolus_State; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Get_Step_Bolus_Information; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Set_Extended_Bolus; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Stop; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_General_Get_Pump_Check; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_General_Get_Shipping_Information; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_General_Initial_Screen_Information; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_General_Set_History_Upload_Mode; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Alarm; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Basal; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Blood_Glucose; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Bolus; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Carbohydrate; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Daily; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Prime; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Refill; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Suspend; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Notify_Delivery_Complete; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Notify_Delivery_Rate_Display; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Option_Get_Pump_Time; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Option_Get_User_Option; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Option_Set_Pump_Time; +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Option_Set_User_Option; +import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.commands.Command; -import info.nightscout.utils.DateUtil; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.SP; -import info.nightscout.utils.T; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.T; public class DanaRSService extends Service { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java index 86c07b89ff..9e3ca499d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRv2; +package info.nightscout.androidaps.plugins.pump.danaRv2; import android.content.ComponentName; import android.content.Context; @@ -19,19 +19,21 @@ import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; -import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType; -import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed; -import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.Round; -import info.nightscout.utils.SP; -import info.nightscout.utils.T; + +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment; +import info.nightscout.androidaps.plugins.configBuilder.DetailedBolusInfoStorage; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; + +import info.nightscout.androidaps.plugins.pump.danaR.AbstractDanaRPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStartWithSpeed; +import info.nightscout.androidaps.plugins.pump.danaRv2.services.DanaRv2ExecutionService; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.Round; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.T; /** * Created by mike on 05.08.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/SerialIOThread.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/SerialIOThread.java index 61047a8d5a..ba1fdc5cb2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/SerialIOThread.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRv2; +package info.nightscout.androidaps.plugins.pump.danaRv2; import android.bluetooth.BluetoothSocket; import android.os.SystemClock; @@ -11,11 +11,11 @@ import java.io.InputStream; import java.io.OutputStream; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; -import info.nightscout.androidaps.plugins.PumpDanaR.services.AbstractSerialIOThread; -import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MessageHashTable_v2; -import info.nightscout.utils.CRC; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractSerialIOThread; +import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MessageHashTable_v2; +import info.nightscout.androidaps.utils.CRC; /** * Created by mike on 17.07.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTable_v2.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTable_v2.java index c95a800128..66376290af 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTable_v2.java @@ -1,9 +1,9 @@ -package info.nightscout.androidaps.plugins.PumpDanaRv2.comm; +package info.nightscout.androidaps.plugins.pump.danaRv2.comm; import java.util.HashMap; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.*; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.comm.*; /** diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgCheckValue_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.java similarity index 87% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgCheckValue_v2.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.java index 034c7648a0..5af7705106 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgCheckValue_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRv2.comm; +package info.nightscout.androidaps.plugins.pump.danaRv2.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -8,14 +8,14 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; +import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin; /** * Created by mike on 30.06.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEvents_v2.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEvents_v2.java index b12116e1a0..b3c7d00612 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEvents_v2.java @@ -1,9 +1,8 @@ -package info.nightscout.androidaps.plugins.PumpDanaRv2.comm; +package info.nightscout.androidaps.plugins.pump.danaRv2.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Date; import java.util.GregorianCalendar; import info.nightscout.androidaps.MainApp; @@ -14,11 +13,11 @@ import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.configBuilder.DetailedBolusInfoStorage; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; public class MsgHistoryEvents_v2 extends MessageBase { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); @@ -26,23 +25,30 @@ public class MsgHistoryEvents_v2 extends MessageBase { public static long lastEventTimeLoaded = 0; - public MsgHistoryEvents_v2(long from) { - SetCommand(0xE003); - GregorianCalendar gfrom = new GregorianCalendar(); - gfrom.setTimeInMillis(from); - AddParamDate(gfrom); - done = false; - if (L.isEnabled(L.PUMPCOMM)) - log.debug("New message"); + public MsgHistoryEvents_v2() { + this(0); } - public MsgHistoryEvents_v2() { + public MsgHistoryEvents_v2(long from) { SetCommand(0xE003); - AddParamByte((byte) 0); - AddParamByte((byte) 1); - AddParamByte((byte) 1); - AddParamByte((byte) 0); - AddParamByte((byte) 0); + + if (from > DateUtil.now()) { + log.debug("Asked to load from the future"); + from = 0; + } + + if (from == 0) { + AddParamByte((byte) 0); + AddParamByte((byte) 1); + AddParamByte((byte) 1); + AddParamByte((byte) 0); + AddParamByte((byte) 0); + } else { + GregorianCalendar gfrom = new GregorianCalendar(); + gfrom.setTimeInMillis(from); + AddParamDate(gfrom); + } + done = false; if (L.isEnabled(L.PUMPCOMM)) log.debug("New message"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetAPSTempBasalStart_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetAPSTempBasalStart_v2.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetAPSTempBasalStart_v2.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetAPSTempBasalStart_v2.java index 42964a64c6..875cd4ac64 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetAPSTempBasalStart_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetAPSTempBasalStart_v2.java @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.PumpDanaRv2.comm; +package info.nightscout.androidaps.plugins.pump.danaRv2.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; public class MsgSetAPSTempBasalStart_v2 extends MessageBase { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetHistoryEntry_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetHistoryEntry_v2.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetHistoryEntry_v2.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetHistoryEntry_v2.java index 0c55b29a3f..b817495ba3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetHistoryEntry_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetHistoryEntry_v2.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRv2.comm; +package info.nightscout.androidaps.plugins.pump.danaRv2.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -7,7 +7,7 @@ import java.util.Date; import java.util.GregorianCalendar; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; public class MsgSetHistoryEntry_v2 extends MessageBase { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusAPS_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusAPS_v2.java similarity index 79% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusAPS_v2.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusAPS_v2.java index 5d0238f2f7..601a5d4933 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusAPS_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusAPS_v2.java @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.plugins.PumpDanaRv2.comm; +package info.nightscout.androidaps.plugins.pump.danaRv2.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; public class MsgStatusAPS_v2 extends MessageBase { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusBolusExtended_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusBolusExtended_v2.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusBolusExtended_v2.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusBolusExtended_v2.java index 5a442e39c1..578be6d4b6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusBolusExtended_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusBolusExtended_v2.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRv2.comm; +package info.nightscout.androidaps.plugins.pump.danaRv2.comm; import android.support.annotation.NonNull; @@ -6,8 +6,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; public class MsgStatusBolusExtended_v2 extends MessageBase { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusTempBasal_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusTempBasal_v2.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusTempBasal_v2.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusTempBasal_v2.java index fb26d2c0de..a92c534d92 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusTempBasal_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusTempBasal_v2.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRv2.comm; +package info.nightscout.androidaps.plugins.pump.danaRv2.comm; import android.support.annotation.NonNull; @@ -6,9 +6,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; +import info.nightscout.androidaps.utils.DateUtil; public class MsgStatusTempBasal_v2 extends MessageBase { private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java similarity index 76% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java index 073cbbde1e..8cabb8959d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpDanaRv2.services; +package info.nightscout.androidaps.plugins.pump.danaRv2.services; import android.bluetooth.BluetoothDevice; import android.content.Intent; @@ -23,57 +23,57 @@ import info.nightscout.androidaps.events.EventProfileSwitchChange; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; -import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusProgress; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStart; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStop; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetActivateBasalProfile; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetBasalProfile; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetCarbsEntry; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetExtendedBolusStart; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetExtendedBolusStop; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTempBasalStart; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTempBasalStop; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTime; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetUserOptions; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingActiveProfile; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingBasal; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingGlucose; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingMaxValues; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingMeal; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingProfileRatios; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingProfileRatiosAll; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingPumpTime; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingShippingInfo; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingUserOptions; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatus; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBasic; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; -import info.nightscout.androidaps.plugins.PumpDanaR.services.AbstractDanaRExecutionService; -import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; -import info.nightscout.androidaps.plugins.PumpDanaRv2.SerialIOThread; -import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgCheckValue_v2; -import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgHistoryEvents_v2; -import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetAPSTempBasalStart_v2; -import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetHistoryEntry_v2; -import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusBolusExtended_v2; -import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusTempBasal_v2; -import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.BolusProgressDialog; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusProgress; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStart; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStartWithSpeed; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStop; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetActivateBasalProfile; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetBasalProfile; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetCarbsEntry; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetExtendedBolusStart; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetExtendedBolusStop; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTempBasalStart; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTempBasalStop; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTime; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetUserOptions; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingActiveProfile; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingBasal; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingGlucose; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingMaxValues; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingMeal; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingProfileRatios; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingProfileRatiosAll; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingPumpTime; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingShippingInfo; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingUserOptions; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatus; +import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusBasic; +import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus; +import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractDanaRExecutionService; +import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin; +import info.nightscout.androidaps.plugins.pump.danaRv2.SerialIOThread; +import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgCheckValue_v2; +import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgHistoryEvents_v2; +import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgSetAPSTempBasalStart_v2; +import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgSetHistoryEntry_v2; +import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgStatusBolusExtended_v2; +import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgStatusTempBasal_v2; +import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.commands.Command; -import info.nightscout.utils.DateUtil; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.SP; -import info.nightscout.utils.T; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.T; public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { @@ -156,6 +156,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { } public void getPumpStatus() { + DanaRPump danaRPump = DanaRPump.getInstance(); try { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpstatus))); MsgStatus statusMsg = new MsgStatus(); @@ -164,7 +165,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { MsgStatusBolusExtended_v2 exStatusMsg = new MsgStatusBolusExtended_v2(); MsgCheckValue_v2 checkValue = new MsgCheckValue_v2(); - if (mDanaRPump.isNewPump) { + if (danaRPump.isNewPump) { mSerialIOThread.sendMessage(checkValue); if (!checkValue.received) { return; @@ -179,11 +180,11 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingextendedbolusstatus))); mSerialIOThread.sendMessage(exStatusMsg); - mDanaRPump.lastConnection = System.currentTimeMillis(); + danaRPump.lastConnection = System.currentTimeMillis(); Profile profile = ProfileFunctions.getInstance().getProfile(); PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); - if (profile != null && Math.abs(mDanaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) { + if (profile != null && Math.abs(danaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings))); mSerialIOThread.sendMessage(new MsgSettingBasal()); if (!pump.isThisProfileSet(profile) && !ConfigBuilderPlugin.getPlugin().getCommandQueue().isRunning(Command.CommandType.BASALPROFILE)) { @@ -193,7 +194,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime))); mSerialIOThread.sendMessage(new MsgSettingPumpTime()); - long timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L; + long timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L; if (L.isEnabled(L.PUMP)) log.debug("Pump time difference: " + timeDiff + " seconds"); if (Math.abs(timeDiff) > 3) { @@ -209,7 +210,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { MainApp.instance().startActivity(i); //deinitialize pump - mDanaRPump.lastConnection = 0; + danaRPump.lastConnection = 0; MainApp.bus().post(new EventDanaRNewStatus()); MainApp.bus().post(new EventInitializationChanged()); return; @@ -218,14 +219,14 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { // add 10sec to be sure we are over minute (will be cutted off anyway) mSerialIOThread.sendMessage(new MsgSetTime(new Date(DateUtil.now() + T.secs(10).msecs()))); mSerialIOThread.sendMessage(new MsgSettingPumpTime()); - timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L; + timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L; if (L.isEnabled(L.PUMP)) log.debug("Pump time difference: " + timeDiff + " seconds"); } } long now = System.currentTimeMillis(); - if (mDanaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) { + if (danaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings))); mSerialIOThread.sendMessage(new MsgSettingShippingInfo()); mSerialIOThread.sendMessage(new MsgSettingActiveProfile()); @@ -238,7 +239,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { mSerialIOThread.sendMessage(new MsgSettingProfileRatios()); mSerialIOThread.sendMessage(new MsgSettingUserOptions()); mSerialIOThread.sendMessage(new MsgSettingProfileRatiosAll()); - mDanaRPump.lastSettingsRead = now; + danaRPump.lastSettingsRead = now; } loadEvents(); @@ -246,13 +247,13 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { MainApp.bus().post(new EventDanaRNewStatus()); MainApp.bus().post(new EventInitializationChanged()); NSUpload.uploadDeviceStatus(); - if (mDanaRPump.dailyTotalUnits > mDanaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) { + if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) { if (L.isEnabled(L.PUMP)) - log.debug("Approaching daily limit: " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits); + log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits); if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.gs(R.string.approachingdailylimit), Notification.URGENT); MainApp.bus().post(new EventNewNotification(reportFail)); - NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits + "U"); + NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U"); lastApproachingDailyLimit = System.currentTimeMillis(); } } @@ -262,8 +263,9 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { } public boolean tempBasal(int percent, int durationInHours) { + DanaRPump danaRPump = DanaRPump.getInstance(); if (!isConnected()) return false; - if (mDanaRPump.isTempBasalInProgress) { + if (danaRPump.isTempBasalInProgress) { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStop()); SystemClock.sleep(500); @@ -277,8 +279,9 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { } public boolean highTempBasal(int percent) { + DanaRPump danaRPump = DanaRPump.getInstance(); if (!isConnected()) return false; - if (mDanaRPump.isTempBasalInProgress) { + if (danaRPump.isTempBasalInProgress) { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStop()); SystemClock.sleep(500); @@ -292,13 +295,14 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { } public boolean tempBasalShortDuration(int percent, int durationInMinutes) { + DanaRPump danaRPump = DanaRPump.getInstance(); if (durationInMinutes != 15 && durationInMinutes != 30) { log.error("Wrong duration param"); return false; } if (!isConnected()) return false; - if (mDanaRPump.isTempBasalInProgress) { + if (danaRPump.isTempBasalInProgress) { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStop()); SystemClock.sleep(500); @@ -449,6 +453,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { } public PumpEnactResult loadEvents() { + DanaRPump danaRPump = DanaRPump.getInstance(); if (!MainApp.getSpecificPlugin(DanaRv2Plugin.class).isInitialized()) { PumpEnactResult result = new PumpEnactResult().success(false); @@ -460,16 +465,10 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { if (!isConnected()) return new PumpEnactResult().success(false); SystemClock.sleep(300); - MsgHistoryEvents_v2 msg; - if (lastHistoryFetched == 0) { - msg = new MsgHistoryEvents_v2(); - if (L.isEnabled(L.PUMP)) - log.debug("Loading complete event history"); - } else { - msg = new MsgHistoryEvents_v2(lastHistoryFetched); - if (L.isEnabled(L.PUMP)) - log.debug("Loading event history from: " + DateUtil.dateAndTimeFullString(lastHistoryFetched)); - } + MsgHistoryEvents_v2 msg = new MsgHistoryEvents_v2(lastHistoryFetched); + if (L.isEnabled(L.PUMP)) + log.debug("Loading event history from: " + DateUtil.dateAndTimeFullString(lastHistoryFetched)); + mSerialIOThread.sendMessage(msg); while (!msg.done && mRfcommSocket.isConnected()) { SystemClock.sleep(100); @@ -479,11 +478,12 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded - T.mins(1).msecs(); else lastHistoryFetched = 0; - mDanaRPump.lastConnection = System.currentTimeMillis(); + danaRPump.lastConnection = System.currentTimeMillis(); return new PumpEnactResult().success(true); } public boolean updateBasalsInPump(final Profile profile) { + DanaRPump danaRPump = DanaRPump.getInstance(); if (!isConnected()) return false; MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.updatingbasalrates))); double[] basal = DanaRPump.getInstance().buildDanaRProfileRecord(profile); @@ -491,23 +491,12 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { mSerialIOThread.sendMessage(msgSet); MsgSetActivateBasalProfile msgActivate = new MsgSetActivateBasalProfile((byte) 0); mSerialIOThread.sendMessage(msgActivate); - mDanaRPump.lastSettingsRead = 0; // force read full settings + danaRPump.lastSettingsRead = 0; // force read full settings getPumpStatus(); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); return true; } - void waitForWholeMinute() { - while (true) { - long time = DateUtil.now(); - long timeToWholeMinute = (60000 - time % 60000); - if (timeToWholeMinute > 59800 || timeToWholeMinute < 3000) - break; - MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.waitingfortimesynchronization, (int) (timeToWholeMinute / 1000)))); - SystemClock.sleep(Math.min(timeToWholeMinute, 100)); - } - } - public PumpEnactResult setUserOptions() { if (!isConnected()) return new PumpEnactResult().success(false); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/EventLocalInsightUpdateGUI.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/EventLocalInsightUpdateGUI.java new file mode 100644 index 0000000000..89b001891c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/EventLocalInsightUpdateGUI.java @@ -0,0 +1,6 @@ +package info.nightscout.androidaps.plugins.pump.insight; + +import info.nightscout.androidaps.events.EventUpdateGui; + +public class EventLocalInsightUpdateGUI extends EventUpdateGui { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/InsightAlertService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/InsightAlertService.java new file mode 100644 index 0000000000..d851389aaf --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/InsightAlertService.java @@ -0,0 +1,260 @@ +package info.nightscout.androidaps.plugins.pump.insight; + +import android.app.Service; +import android.content.ComponentName; +import android.content.Intent; +import android.content.ServiceConnection; +import android.media.AudioAttributes; +import android.media.AudioManager; +import android.media.Ringtone; +import android.media.RingtoneManager; +import android.net.Uri; +import android.os.Binder; +import android.os.Build; +import android.os.Handler; +import android.os.IBinder; +import android.os.Looper; +import android.os.Vibrator; +import android.support.annotation.Nullable; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.pump.insight.activities.InsightAlertActivity; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.ConfirmAlertMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.SnoozeAlertMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetActiveAlertMessage; +import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.Alert; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertStatus; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertType; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.InsightState; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.InsightException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.AppLayerErrorException; +import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator; + +public class InsightAlertService extends Service implements InsightConnectionService.StateCallback { + + private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); + + private LocalBinder localBinder = new LocalBinder(); + private boolean connectionRequested; + private final Object $alertLock = new Object[0]; + private Alert alert; + private Thread thread; + private InsightAlertActivity alertActivity; + private Ringtone ringtone; + private Vibrator vibrator; + private boolean vibrating; + private InsightConnectionService connectionService; + private long ignoreTimestamp; + private AlertType ignoreType; + + private ServiceConnection serviceConnection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder binder) { + connectionService = ((InsightConnectionService.LocalBinder) binder).getService(); + connectionService.registerStateCallback(InsightAlertService.this); + onStateChanged(connectionService.getState()); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + connectionService = null; + } + }; + + private void retrieveRingtone() { + Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); + ringtone = RingtoneManager.getRingtone(this, uri); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + ringtone.setAudioAttributes(new AudioAttributes.Builder() + .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) + .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) + .setLegacyStreamType(AudioManager.STREAM_RING).build()); + } else ringtone.setStreamType(AudioManager.STREAM_RING); + } + + public Alert getAlert() { + synchronized ($alertLock) { + return alert; + } + } + + public void setAlertActivity(InsightAlertActivity alertActivity) { + this.alertActivity = alertActivity; + } + + public void ignore(AlertType alertType) { + synchronized ($alertLock) { + if (alertType == null) { + ignoreTimestamp = 0; + ignoreType = null; + } else { + ignoreTimestamp = System.currentTimeMillis(); + ignoreType = alertType; + } + } + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return localBinder; + } + + @Override + public void onCreate() { + vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); + bindService(new Intent(this, InsightConnectionService.class), serviceConnection, BIND_AUTO_CREATE); + } + + @Override + public void onDestroy() { + if (thread != null) thread.interrupt(); + unbindService(serviceConnection); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + return START_STICKY; + } + + @Override + public void onStateChanged(InsightState state) { + if (state == InsightState.CONNECTED) { + thread = new Thread(this::queryActiveAlert); + thread.start(); + + } else if (thread != null) thread.interrupt(); + } + + private void queryActiveAlert() { + while (!Thread.currentThread().isInterrupted()) { + try { + Alert alert = connectionService.requestMessage(new GetActiveAlertMessage()).await().getAlert(); + if (Thread.currentThread().isInterrupted()) { + connectionService.withdrawConnectionRequest(thread); + break; + } + synchronized ($alertLock) { + if ((this.alert == null && alert != null) + || (this.alert != null && alert == null) + || (this.alert != null && alert != null && !this.alert.equals(alert))) { + if (this.alert != null && (alert == null || this.alert.getAlertId() != alert.getAlertId())) stopAlerting(); + this.alert = alert; + if (alertActivity != null && alert != null) + new Handler(Looper.getMainLooper()).post(() -> alertActivity.update(alert)); + } + if (alert == null) { + stopAlerting(); + if (connectionRequested) { + connectionService.withdrawConnectionRequest(this); + connectionRequested = false; + } + if (alertActivity != null) + new Handler(Looper.getMainLooper()).post(() -> alertActivity.finish()); + } else if (!(alert.getAlertType() == ignoreType && System.currentTimeMillis() - ignoreTimestamp < 10000)) { + if (alert.getAlertStatus() == AlertStatus.ACTIVE) alert(); + else stopAlerting(); + if (!connectionRequested) { + connectionService.requestConnection(this); + connectionRequested = true; + } + if (alertActivity == null) { + Intent intent = new Intent(InsightAlertService.this, InsightAlertActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); + new Handler(Looper.getMainLooper()).post(() -> startActivity(intent)); + } + } + } + } catch (InterruptedException ignored) { + connectionService.withdrawConnectionRequest(thread); + break; + } catch (AppLayerErrorException e) { + log.info("Exception while fetching alert: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + } catch (InsightException e) { + log.info("Exception while fetching alert: " + e.getClass().getSimpleName()); + } catch (Exception e) { + log.error("Exception while fetching alert", e); + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + break; + } + } + if (connectionRequested) { + connectionService.withdrawConnectionRequest(thread); + connectionRequested = false; + } + if (alertActivity != null) + new Handler(Looper.getMainLooper()).post(() -> alertActivity.finish()); + stopAlerting(); + thread = null; + } + + private void alert() { + if (!vibrating) { + vibrator.vibrate(new long[] {0, 1000, 1000}, 0); + vibrating = true; + } + if (ringtone == null || !ringtone.isPlaying()) { + retrieveRingtone(); + ringtone.play(); + } + } + + private void stopAlerting() { + if (vibrating) { + vibrator.cancel(); + vibrating = false; + } + if (ringtone != null && ringtone.isPlaying()) ringtone.stop(); + } + + public void mute() { + new Thread(() -> { + try { + SnoozeAlertMessage snoozeAlertMessage = new SnoozeAlertMessage(); + snoozeAlertMessage.setAlertID(alert.getAlertId()); + connectionService.requestMessage(snoozeAlertMessage).await(); + } catch (AppLayerErrorException e) { + log.info("Exception while muting alert: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + ExceptionTranslator.makeToast(InsightAlertService.this, e); + } catch (InsightException e) { + log.info("Exception while muting alert: " + e.getClass().getSimpleName()); + ExceptionTranslator.makeToast(InsightAlertService.this, e); + } catch (Exception e) { + log.error("Exception while muting alert", e); + ExceptionTranslator.makeToast(InsightAlertService.this, e); + } + }).start(); + } + + public void confirm() { + new Thread(() -> { + try { + ConfirmAlertMessage confirmAlertMessage = new ConfirmAlertMessage(); + confirmAlertMessage.setAlertID(alert.getAlertId()); + connectionService.requestMessage(confirmAlertMessage).await(); + } catch (AppLayerErrorException e) { + log.info("Exception while confirming alert: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + ExceptionTranslator.makeToast(InsightAlertService.this, e); + } catch (InsightException e) { + log.info("Exception while confirming alert: " + e.getClass().getSimpleName()); + ExceptionTranslator.makeToast(InsightAlertService.this, e); + } catch (Exception e) { + log.error("Exception while confirming alert", e); + ExceptionTranslator.makeToast(InsightAlertService.this, e); + } + }).start(); + } + + public class LocalBinder extends Binder { + public InsightAlertService getService() { + return InsightAlertService.this; + } + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightFragment.java new file mode 100644 index 0000000000..26f5180f47 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightFragment.java @@ -0,0 +1,301 @@ +package info.nightscout.androidaps.plugins.pump.insight; + +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.squareup.otto.Subscribe; + +import java.util.ArrayList; +import java.util.List; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.TBROverNotificationBlock; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveBasalRate; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveBolus; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveTBR; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.CartridgeStatus; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.InsightState; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.TotalDailyDose; +import info.nightscout.androidaps.queue.Callback; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; + +public class LocalInsightFragment extends SubscriberFragment implements View.OnClickListener { + + private static final boolean ENABLE_OPERATING_MODE_BUTTON = false; + + private boolean viewsCreated; + private Button operatingMode; + private Button tbrOverNotification; + private Button refresh; + private LinearLayout statusItemContainer = null; + + private Callback operatingModeCallback; + private Callback tbrOverNotificationCallback; + private Callback refreshCallback; + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.local_insight_fragment, container, false); + statusItemContainer = view.findViewById(R.id.status_item_container); + tbrOverNotification = view.findViewById(R.id.tbr_over_notification); + tbrOverNotification.setOnClickListener(this); + operatingMode = view.findViewById(R.id.operating_mode); + operatingMode.setOnClickListener(this); + refresh = view.findViewById(R.id.refresh); + refresh.setOnClickListener(this); + viewsCreated = true; + return view; + } + + @Override + public synchronized void onDestroyView() { + super.onDestroyView(); + viewsCreated = false; + } + + @Override + public void onClick(View v) { + if (v == operatingMode) { + if (LocalInsightPlugin.getPlugin().getOperatingMode() != null) { + operatingMode.setEnabled(false); + operatingModeCallback = new Callback() { + @Override + public void run() { + new Handler(Looper.getMainLooper()).post(() -> { + operatingModeCallback = null; + updateGUI(); + }); + } + }; + switch (LocalInsightPlugin.getPlugin().getOperatingMode()) { + case PAUSED: + case STOPPED: + ConfigBuilderPlugin.getPlugin().getCommandQueue().startPump(operatingModeCallback); + break; + case STARTED: + ConfigBuilderPlugin.getPlugin().getCommandQueue().stopPump(operatingModeCallback); + } + } + } else if (v == tbrOverNotification) { + TBROverNotificationBlock notificationBlock = LocalInsightPlugin.getPlugin().getTBROverNotificationBlock(); + if (notificationBlock != null) { + tbrOverNotification.setEnabled(false); + tbrOverNotificationCallback = new Callback() { + @Override + public void run() { + new Handler(Looper.getMainLooper()).post(() -> { + tbrOverNotificationCallback = null; + updateGUI(); + }); + } + }; + ConfigBuilderPlugin.getPlugin().getCommandQueue() + .setTBROverNotification(tbrOverNotificationCallback, !notificationBlock.isEnabled()); + } + } else if (v == refresh) { + refresh.setEnabled(false); + refreshCallback = new Callback() { + @Override + public void run() { + new Handler(Looper.getMainLooper()).post(() -> { + refreshCallback = null; + updateGUI(); + }); + } + }; + ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("InsightRefreshButton", refreshCallback); + } + } + + @Subscribe + public void onUpdateGUIEvent(EventLocalInsightUpdateGUI event) { + updateGUI(); + } + + @Override + protected void updateGUI() { + if (!viewsCreated) return; + statusItemContainer.removeAllViews(); + if (!LocalInsightPlugin.getPlugin().isInitialized()) { + operatingMode.setVisibility(View.GONE); + tbrOverNotification.setVisibility(View.GONE); + refresh.setVisibility(View.GONE); + return; + } + refresh.setVisibility(View.VISIBLE); + refresh.setEnabled(refreshCallback == null); + TBROverNotificationBlock notificationBlock = LocalInsightPlugin.getPlugin().getTBROverNotificationBlock(); + tbrOverNotification.setVisibility(notificationBlock == null ? View.GONE : View.VISIBLE); + if (notificationBlock != null) + tbrOverNotification.setText(notificationBlock.isEnabled() ? R.string.disable_tbr_over_notification : R.string.enable_tbr_over_notification); + tbrOverNotification.setEnabled(tbrOverNotificationCallback == null); + List statusItems = new ArrayList<>(); + getConnectionStatusItem(statusItems); + getLastConnectedItem(statusItems); + getOperatingModeItem(statusItems); + getBatteryStatusItem(statusItems); + getCartridgeStatusItem(statusItems); + getTDDItems(statusItems); + getBaseBasalRateItem(statusItems); + getTBRItem(statusItems); + getBolusItems(statusItems); + for (int i = 0; i < statusItems.size(); i++) { + statusItemContainer.addView(statusItems.get(i)); + if (i != statusItems.size() - 1) + getLayoutInflater().inflate(R.layout.local_insight_status_delimitter, statusItemContainer); + } + } + + private View getStatusItem(String label, String value) { + View statusItem = getLayoutInflater().inflate(R.layout.local_insight_status_item, null); + ((TextView) statusItem.findViewById(R.id.label)).setText(label); + ((TextView) statusItem.findViewById(R.id.value)).setText(value); + return statusItem; + } + + private void getConnectionStatusItem(List statusItems) { + int string = 0; + InsightState state = LocalInsightPlugin.getPlugin().getConnectionService().getState(); + switch (state) { + case NOT_PAIRED: + string = R.string.not_paired; + break; + case DISCONNECTED: + string = R.string.disconnected; + break; + case CONNECTING: + case SATL_CONNECTION_REQUEST: + case SATL_KEY_REQUEST: + case SATL_SYN_REQUEST: + case SATL_VERIFY_CONFIRM_REQUEST: + case SATL_VERIFY_DISPLAY_REQUEST: + case APP_ACTIVATE_PARAMETER_SERVICE: + case APP_ACTIVATE_STATUS_SERVICE: + case APP_BIND_MESSAGE: + case APP_CONNECT_MESSAGE: + case APP_FIRMWARE_VERSIONS: + case APP_SYSTEM_IDENTIFICATION: + case AWAITING_CODE_CONFIRMATION: + string = R.string.connecting; + break; + case CONNECTED: + string = R.string.connected; + break; + case RECOVERING: + string = R.string.recovering; + break; + } + statusItems.add(getStatusItem(MainApp.gs(R.string.insight_status), MainApp.gs(string))); + if (state == InsightState.RECOVERING) { + statusItems.add(getStatusItem(MainApp.gs(R.string.recovery_duration), LocalInsightPlugin.getPlugin().getConnectionService().getRecoveryDuration() / 1000 + "s")); + } + } + + private void getLastConnectedItem(List statusItems) { + switch (LocalInsightPlugin.getPlugin().getConnectionService().getState()) { + case CONNECTED: + case NOT_PAIRED: + return; + default: + long lastConnection = LocalInsightPlugin.getPlugin().getConnectionService().getLastConnected(); + if (lastConnection == 0) return; + int min = (int) ((System.currentTimeMillis() - lastConnection) / 60000); + statusItems.add(getStatusItem(MainApp.gs(R.string.last_connected), DateUtil.timeString(lastConnection))); + } + } + + private void getOperatingModeItem(List statusItems) { + if (LocalInsightPlugin.getPlugin().getOperatingMode() == null) { + operatingMode.setVisibility(View.GONE); + return; + } + int string = 0; + if (ENABLE_OPERATING_MODE_BUTTON) operatingMode.setVisibility(View.VISIBLE); + operatingMode.setEnabled(operatingModeCallback == null); + switch (LocalInsightPlugin.getPlugin().getOperatingMode()) { + case STARTED: + operatingMode.setText(R.string.stop_pump); + string = R.string.started; + break; + case STOPPED: + operatingMode.setText(R.string.start_pump); + string = R.string.stopped; + break; + case PAUSED: + operatingMode.setText(R.string.start_pump); + string = R.string.paused; + break; + } + statusItems.add(getStatusItem(MainApp.gs(R.string.operating_mode), MainApp.gs(string))); + } + + private void getBatteryStatusItem(List statusItems) { + if (LocalInsightPlugin.getPlugin().getBatteryStatus() == null) return; + statusItems.add(getStatusItem(MainApp.gs(R.string.pump_battery_label), + LocalInsightPlugin.getPlugin().getBatteryStatus().getBatteryAmount() + "%")); + } + + private void getCartridgeStatusItem(List statusItems) { + CartridgeStatus cartridgeStatus = LocalInsightPlugin.getPlugin().getCartridgeStatus(); + if (cartridgeStatus == null) return; + String status; + if (cartridgeStatus.isInserted()) + status = DecimalFormatter.to2Decimal(LocalInsightPlugin.getPlugin().getCartridgeStatus().getRemainingAmount()) + "U"; + else status = MainApp.gs(R.string.not_inserted); + statusItems.add(getStatusItem(MainApp.gs(R.string.pump_reservoir_label), status)); + } + + private void getTDDItems(List statusItems) { + if (LocalInsightPlugin.getPlugin().getTotalDailyDose() == null) return; + TotalDailyDose tdd = LocalInsightPlugin.getPlugin().getTotalDailyDose(); + statusItems.add(getStatusItem(MainApp.gs(R.string.tdd_bolus), DecimalFormatter.to2Decimal(tdd.getBolus()))); + statusItems.add(getStatusItem(MainApp.gs(R.string.tdd_basal), DecimalFormatter.to2Decimal(tdd.getBasal()))); + statusItems.add(getStatusItem(MainApp.gs(R.string.tdd_total), DecimalFormatter.to2Decimal(tdd.getBolusAndBasal()))); + } + + private void getBaseBasalRateItem(List statusItems) { + if (LocalInsightPlugin.getPlugin().getActiveBasalRate() == null) return; + ActiveBasalRate activeBasalRate = LocalInsightPlugin.getPlugin().getActiveBasalRate(); + statusItems.add(getStatusItem(MainApp.gs(R.string.pump_basebasalrate_label), + DecimalFormatter.to2Decimal(activeBasalRate.getActiveBasalRate()) + " U/h (" + activeBasalRate.getActiveBasalProfileName() + ")")); + } + + private void getTBRItem(List statusItems) { + if (LocalInsightPlugin.getPlugin().getActiveTBR() == null) return; + ActiveTBR activeTBR = LocalInsightPlugin.getPlugin().getActiveTBR(); + statusItems.add(getStatusItem(MainApp.gs(R.string.pump_tempbasal_label), + MainApp.gs(R.string.tbr_formatter, activeTBR.getPercentage(), activeTBR.getInitialDuration() - activeTBR.getRemainingDuration(), activeTBR.getInitialDuration()))); + } + + private void getBolusItems(List statusItems) { + if (LocalInsightPlugin.getPlugin().getActiveBoluses() == null) return; + for (ActiveBolus activeBolus : LocalInsightPlugin.getPlugin().getActiveBoluses()) { + String label; + switch (activeBolus.getBolusType()) { + case MULTIWAVE: + label = MainApp.gs(R.string.multiwave_bolus); + break; + case EXTENDED: + label = MainApp.gs(R.string.extended_bolus); + break; + default: + continue; + } + statusItems.add(getStatusItem(label, MainApp.gs(R.string.eb_formatter, activeBolus.getRemainingAmount(), activeBolus.getInitialAmount(), activeBolus.getRemainingDuration()))); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java new file mode 100644 index 0000000000..22b329edbb --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -0,0 +1,1572 @@ +package info.nightscout.androidaps.plugins.pump.insight; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.os.Handler; +import android.os.IBinder; +import android.os.Looper; + +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.*; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.*; +import org.json.JSONException; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; + +import info.nightscout.androidaps.BuildConfig; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.DetailedBolusInfo; +import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.db.CareportalEvent; +import info.nightscout.androidaps.db.ExtendedBolus; +import info.nightscout.androidaps.db.Source; +import info.nightscout.androidaps.db.TDD; +import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.events.EventInitializationChanged; +import info.nightscout.androidaps.events.EventRefreshOverview; +import info.nightscout.androidaps.interfaces.Constraint; +import info.nightscout.androidaps.interfaces.ConstraintsInterface; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginDescription; +import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.interfaces.PumpDescription; +import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.HistoryReadingDirection; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.ReadHistoryEventsMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.StartReadingHistoryMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.StopReadingHistoryMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.BolusDeliveredEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.BolusProgrammedEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.CannulaFilledEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.DateTimeChangedEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.DefaultDateTimeSetEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.EndOfTBREvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.HistoryEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.OccurrenceOfAlertEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.OperatingModeChangedEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.PowerUpEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.SniffingDoneEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.StartOfTBREvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.TotalDailyDoseEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.TubeFilledEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.CancelBolusMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.CancelTBRMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.ChangeTBRMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.ConfirmAlertMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.DeliverBolusMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.SetDateTimeMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.SetOperatingModeMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.SetTBRMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetActiveAlertMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetActiveBasalRateMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetActiveBolusesMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetActiveTBRMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetBatteryStatusMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetCartridgeStatusMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetDateTimeMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetOperatingModeMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetPumpStatusRegisterMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetTotalDailyDoseMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.ResetPumpStatusRegisterMessage; +import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService; +import info.nightscout.androidaps.plugins.pump.insight.database.InsightBolusID; +import info.nightscout.androidaps.plugins.pump.insight.database.InsightHistoryOffset; +import info.nightscout.androidaps.plugins.pump.insight.database.InsightPumpID; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.InsightException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.AppLayerErrorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NoActiveTBRToCanceLException; +import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator; +import info.nightscout.androidaps.plugins.pump.insight.utils.ParameterBlockUtil; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; + +public class LocalInsightPlugin extends PluginBase implements PumpInterface, ConstraintsInterface, InsightConnectionService.StateCallback { + + private static LocalInsightPlugin instance = null; + + private Logger log = LoggerFactory.getLogger(L.PUMP); + + private PumpDescription pumpDescription; + private InsightAlertService alertService; + private InsightConnectionService connectionService; + private long timeOffset; + private ServiceConnection serviceConnection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder binder) { + if (binder instanceof InsightConnectionService.LocalBinder) { + connectionService = ((InsightConnectionService.LocalBinder) binder).getService(); + connectionService.registerStateCallback(LocalInsightPlugin.this); + } else if (binder instanceof InsightAlertService.LocalBinder) { + alertService = ((InsightAlertService.LocalBinder) binder).getService(); + } + if (connectionService != null && alertService != null) + MainApp.bus().post(new EventInitializationChanged()); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + connectionService = null; + } + }; + + private final Object $bolusLock = new Object[0]; + private int bolusID; + private boolean bolusCancelled; + private BasalProfile activeBasalProfile; + private List profileBlocks; + private boolean limitsFetched; + private double maximumBolusAmount; + private double maximumBasalAmount; + private double minimumBolusAmount; + private double minimumBasalAmount; + private long lastUpdated = -1; + private OperatingMode operatingMode; + private BatteryStatus batteryStatus; + private CartridgeStatus cartridgeStatus; + private TotalDailyDose totalDailyDose; + private ActiveBasalRate activeBasalRate; + private ActiveTBR activeTBR; + private List activeBoluses; + private boolean statusLoaded; + private TBROverNotificationBlock tbrOverNotificationBlock; + + public static LocalInsightPlugin getPlugin() { + if (instance == null) instance = new LocalInsightPlugin(); + return instance; + } + + public LocalInsightPlugin() { + super(new PluginDescription() + .pluginName(R.string.insight_local) + .shortName(R.string.insightpump_shortname) + .mainType(PluginType.PUMP) + .description(R.string.description_pump_insight_local) + .fragmentClass(LocalInsightFragment.class.getName()) + .preferencesId(R.xml.pref_insight_local)); + + pumpDescription = new PumpDescription(); + pumpDescription.setPumpDescription(PumpType.AccuChekInsight); + } + + public TBROverNotificationBlock getTBROverNotificationBlock() { + return tbrOverNotificationBlock; + } + + public long getLastUpdated() { + return lastUpdated; + } + + public InsightConnectionService getConnectionService() { + return connectionService; + } + + public OperatingMode getOperatingMode() { + return operatingMode; + } + + public BatteryStatus getBatteryStatus() { + return batteryStatus; + } + + public CartridgeStatus getCartridgeStatus() { + return cartridgeStatus; + } + + public TotalDailyDose getTotalDailyDose() { + return totalDailyDose; + } + + public ActiveBasalRate getActiveBasalRate() { + return activeBasalRate; + } + + public ActiveTBR getActiveTBR() { + return activeTBR; + } + + public List getActiveBoluses() { + return activeBoluses; + } + + @Override + protected void onStart() { + super.onStart(); + MainApp.instance().bindService(new Intent(MainApp.instance(), InsightConnectionService.class), serviceConnection, Context.BIND_AUTO_CREATE); + MainApp.instance().bindService(new Intent(MainApp.instance(), InsightAlertService.class), serviceConnection, Context.BIND_AUTO_CREATE); + } + + @Override + protected void onStop() { + super.onStop(); + MainApp.instance().unbindService(serviceConnection); + } + + @Override + public boolean isInitialized() { + return connectionService != null && alertService != null && connectionService.isPaired(); + } + + @Override + public boolean isSuspended() { + return operatingMode != null && operatingMode != OperatingMode.STARTED; + } + + @Override + public boolean isBusy() { + return false; + } + + @Override + public boolean isConnected() { + return connectionService != null + && alertService != null + && connectionService.hasRequestedConnection(this) + && connectionService.getState() == InsightState.CONNECTED; + } + + @Override + public boolean isConnecting() { + if (connectionService == null || alertService == null || !connectionService.hasRequestedConnection(this)) + return false; + InsightState state = connectionService.getState(); + return state == InsightState.CONNECTING + || state == InsightState.APP_CONNECT_MESSAGE + || state == InsightState.RECOVERING; + } + + @Override + public boolean isHandshakeInProgress() { + return false; + } + + @Override + public void finishHandshaking() { + + } + + @Override + public void connect(String reason) { + if (connectionService != null && alertService != null) + connectionService.requestConnection(this); + } + + @Override + public void disconnect(String reason) { + if (connectionService != null && alertService != null) + connectionService.withdrawConnectionRequest(this); + } + + @Override + public void stopConnecting() { + if (connectionService != null && alertService != null) + connectionService.withdrawConnectionRequest(this); + } + + @Override + public void getPumpStatus() { + try { + tbrOverNotificationBlock = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, TBROverNotificationBlock.class); + readHistory(); + fetchBasalProfile(); + fetchLimitations(); + updatePumpTimeIfNeeded(); + fetchStatus(); + } catch (AppLayerErrorException e) { + log.info("Exception while fetching status: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + } catch (InsightException e) { + log.info("Exception while fetching status: " + e.getClass().getCanonicalName()); + } catch (Exception e) { + log.error("Exception while fetching status", e); + } + } + + private void updatePumpTimeIfNeeded() throws Exception { + PumpTime pumpTime = connectionService.requestMessage(new GetDateTimeMessage()).await().getPumpTime(); + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.YEAR, pumpTime.getYear()); + calendar.set(Calendar.MONTH, pumpTime.getMonth() - 1); + calendar.set(Calendar.DAY_OF_MONTH, pumpTime.getDay()); + calendar.set(Calendar.HOUR_OF_DAY, pumpTime.getHour()); + calendar.set(Calendar.MINUTE, pumpTime.getMinute()); + calendar.set(Calendar.SECOND, pumpTime.getSecond()); + if (Math.abs(calendar.getTimeInMillis() - System.currentTimeMillis()) > 10000) { + calendar.setTime(new Date()); + pumpTime.setYear(calendar.get(Calendar.YEAR)); + pumpTime.setMonth(calendar.get(Calendar.MONTH) + 1); + pumpTime.setDay(calendar.get(Calendar.DAY_OF_MONTH)); + pumpTime.setHour(calendar.get(Calendar.HOUR_OF_DAY)); + pumpTime.setMinute(calendar.get(Calendar.MINUTE)); + pumpTime.setSecond(calendar.get(Calendar.SECOND)); + SetDateTimeMessage setDateTimeMessage = new SetDateTimeMessage(); + setDateTimeMessage.setPumpTime(pumpTime); + connectionService.requestMessage(setDateTimeMessage).await(); + Notification notification = new Notification(Notification.INSIGHT_DATE_TIME_UPDATED, MainApp.gs(R.string.pump_time_updated), Notification.INFO, 60); + MainApp.bus().post(new EventNewNotification(notification)); + } + } + + private void fetchBasalProfile() throws Exception { + activeBasalProfile = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, ActiveBRProfileBlock.class).getActiveBasalProfile(); + profileBlocks = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, BRProfile1Block.class).getProfileBlocks(); + } + + private void fetchStatus() throws Exception { + if (statusLoaded) { + GetPumpStatusRegisterMessage registerMessage = connectionService.requestMessage(new GetPumpStatusRegisterMessage()).await(); + ResetPumpStatusRegisterMessage resetMessage = new ResetPumpStatusRegisterMessage(); + resetMessage.setOperatingModeChanged(registerMessage.isOperatingModeChanged()); + resetMessage.setBatteryStatusChanged(registerMessage.isBatteryStatusChanged()); + resetMessage.setCartridgeStatusChanged(registerMessage.isCartridgeStatusChanged()); + resetMessage.setTotalDailyDoseChanged(registerMessage.isTotalDailyDoseChanged()); + resetMessage.setActiveTBRChanged(registerMessage.isActiveTBRChanged()); + resetMessage.setActiveBolusesChanged(registerMessage.isActiveBolusesChanged()); + connectionService.requestMessage(resetMessage).await(); + if (registerMessage.isOperatingModeChanged()) + operatingMode = connectionService.requestMessage(new GetOperatingModeMessage()).await().getOperatingMode(); + if (registerMessage.isBatteryStatusChanged()) + batteryStatus = connectionService.requestMessage(new GetBatteryStatusMessage()).await().getBatteryStatus(); + if (registerMessage.isCartridgeStatusChanged()) + cartridgeStatus = connectionService.requestMessage(new GetCartridgeStatusMessage()).await().getCartridgeStatus(); + if (registerMessage.isTotalDailyDoseChanged()) + totalDailyDose = connectionService.requestMessage(new GetTotalDailyDoseMessage()).await().getTDD(); + if (operatingMode == OperatingMode.STARTED) { + if (registerMessage.isActiveBasalRateChanged()) + activeBasalRate = connectionService.requestMessage(new GetActiveBasalRateMessage()).await().getActiveBasalRate(); + if (registerMessage.isActiveTBRChanged()) + activeTBR = connectionService.requestMessage(new GetActiveTBRMessage()).await().getActiveTBR(); + if (registerMessage.isActiveBolusesChanged()) + activeBoluses = connectionService.requestMessage(new GetActiveBolusesMessage()).await().getActiveBoluses(); + } else { + activeBasalRate = null; + activeTBR = null; + activeBoluses = null; + } + + } else { + ResetPumpStatusRegisterMessage resetMessage = new ResetPumpStatusRegisterMessage(); + resetMessage.setOperatingModeChanged(true); + resetMessage.setBatteryStatusChanged(true); + resetMessage.setCartridgeStatusChanged(true); + resetMessage.setTotalDailyDoseChanged(true); + resetMessage.setActiveBasalRateChanged(true); + resetMessage.setActiveTBRChanged(true); + resetMessage.setActiveBolusesChanged(true); + connectionService.requestMessage(resetMessage).await(); + operatingMode = connectionService.requestMessage(new GetOperatingModeMessage()).await().getOperatingMode(); + batteryStatus = connectionService.requestMessage(new GetBatteryStatusMessage()).await().getBatteryStatus(); + cartridgeStatus = connectionService.requestMessage(new GetCartridgeStatusMessage()).await().getCartridgeStatus(); + totalDailyDose = connectionService.requestMessage(new GetTotalDailyDoseMessage()).await().getTDD(); + if (operatingMode == OperatingMode.STARTED) { + activeBasalRate = connectionService.requestMessage(new GetActiveBasalRateMessage()).await().getActiveBasalRate(); + activeTBR = connectionService.requestMessage(new GetActiveTBRMessage()).await().getActiveTBR(); + activeBoluses = connectionService.requestMessage(new GetActiveBolusesMessage()).await().getActiveBoluses(); + } else { + activeBasalRate = null; + activeTBR = null; + activeBoluses = null; + } + statusLoaded = true; + } + lastUpdated = System.currentTimeMillis(); + new Handler(Looper.getMainLooper()).post(() -> { + MainApp.bus().post(new EventLocalInsightUpdateGUI()); + MainApp.bus().post(new EventRefreshOverview("LocalInsightPlugin::fetchStatus")); + }); + } + + private void fetchLimitations() throws Exception { + maximumBolusAmount = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, MaxBolusAmountBlock.class).getAmountLimitation(); + maximumBasalAmount = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, MaxBasalAmountBlock.class).getAmountLimitation(); + minimumBolusAmount = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, FactoryMinBolusAmountBlock.class).getAmountLimitation(); + minimumBasalAmount = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, FactoryMinBolusAmountBlock.class).getAmountLimitation(); + this.pumpDescription.basalMaximumRate = maximumBasalAmount; + this.pumpDescription.basalMinimumRate = minimumBasalAmount; + limitsFetched = true; + } + + @Override + public PumpEnactResult setNewBasalProfile(Profile profile) { + PumpEnactResult result = new PumpEnactResult(); + MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); + List profileBlocks = new ArrayList<>(); + for (int i = 0; i < profile.getBasalValues().length; i++) { + Profile.BasalValue basalValue = profile.getBasalValues()[i]; + Profile.BasalValue nextValue = null; + if (profile.getBasalValues().length > i + 1) + nextValue = profile.getBasalValues()[i + 1]; + BasalProfileBlock profileBlock = new BasalProfileBlock(); + profileBlock.setBasalAmount(basalValue.value); + profileBlock.setDuration((((nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) / 60)); + profileBlocks.add(profileBlock); + } + try { + ActiveBRProfileBlock activeBRProfileBlock = new ActiveBRProfileBlock(); + activeBRProfileBlock.setActiveBasalProfile(BasalProfile.PROFILE_1); + ParameterBlockUtil.writeConfigurationBlock(connectionService, activeBRProfileBlock); + activeBasalProfile = BasalProfile.PROFILE_1; + BRProfileBlock profileBlock = new BRProfile1Block(); + profileBlock.setProfileBlocks(profileBlocks); + ParameterBlockUtil.writeConfigurationBlock(connectionService, profileBlock); + MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); + Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60); + MainApp.bus().post(new EventNewNotification(notification)); + result.success = true; + result.enacted = true; + result.comment = MainApp.gs(R.string.virtualpump_resultok); + this.profileBlocks = profileBlocks; + try { + fetchStatus(); + } catch (Exception ignored) { + } + } catch (AppLayerErrorException e) { + log.info("Exception while setting profile: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + result.comment = ExceptionTranslator.getString(e); + } catch (InsightException e) { + log.info("Exception while setting profile: " + e.getClass().getCanonicalName()); + Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + result.comment = ExceptionTranslator.getString(e); + } catch (Exception e) { + log.error("Exception while setting profile", e); + Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + result.comment = ExceptionTranslator.getString(e); + } + return result; + } + + @Override + public boolean isThisProfileSet(Profile profile) { + if (!isInitialized() || profileBlocks == null) return true; + if (profile.getBasalValues().length != profileBlocks.size()) return false; + if (activeBasalProfile != BasalProfile.PROFILE_1) return false; + for (int i = 0; i < profileBlocks.size(); i++) { + BasalProfileBlock profileBlock = profileBlocks.get(i); + Profile.BasalValue basalValue = profile.getBasalValues()[i]; + Profile.BasalValue nextValue = null; + if (profile.getBasalValues().length > i + 1) + nextValue = profile.getBasalValues()[i + 1]; + if (profileBlock.getDuration() * 60 != (nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) + return false; + if (Math.abs(profileBlock.getBasalAmount() - basalValue.value) > 0.01D) + return false; + } + return true; + } + + @Override + public long lastDataTime() { + if (connectionService == null || alertService == null) return System.currentTimeMillis(); + return connectionService.getLastDataTime(); + } + + @Override + public double getBaseBasalRate() { + if (connectionService == null || alertService == null) return 0; + if (activeBasalRate != null) return activeBasalRate.getActiveBasalRate(); + else return 0; + } + + @Override + public double getReservoirLevel() { + if (cartridgeStatus == null) return 0; + return cartridgeStatus.getRemainingAmount(); + } + + @Override + public int getBatteryLevel() { + if (batteryStatus == null) return 0; + return batteryStatus.getBatteryAmount(); + } + + @Override + public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { + PumpEnactResult result = new PumpEnactResult(); + if (detailedBolusInfo.insulin > 0) { + try { + synchronized ($bolusLock) { + DeliverBolusMessage bolusMessage = new DeliverBolusMessage(); + bolusMessage.setBolusType(BolusType.STANDARD); + bolusMessage.setDuration(0); + bolusMessage.setExtendedAmount(0); + bolusMessage.setImmediateAmount(detailedBolusInfo.insulin); + bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId(); + bolusCancelled = false; + } + result.success = true; + result.enacted = true; + Treatment t = new Treatment(); + t.isSMB = detailedBolusInfo.isSMB; + final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); + bolusingEvent.t = t; + bolusingEvent.status = MainApp.gs(R.string.insight_delivered, 0d, detailedBolusInfo.insulin); + bolusingEvent.percent = 0; + MainApp.bus().post(bolusingEvent); + int trials = 0; + InsightBolusID insightBolusID = new InsightBolusID(); + insightBolusID.bolusID = bolusID; + insightBolusID.timestamp = System.currentTimeMillis(); + insightBolusID.pumpSerial = connectionService.getPumpSystemIdentification().getSerialNumber(); + MainApp.getDbHelper().createOrUpdate(insightBolusID); + detailedBolusInfo.date = insightBolusID.timestamp; + detailedBolusInfo.source = Source.PUMP; + detailedBolusInfo.pumpId = insightBolusID.id; + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); + while (true) { + synchronized ($bolusLock) { + if (bolusCancelled) break; + } + OperatingMode operatingMode = connectionService.requestMessage(new GetOperatingModeMessage()).await().getOperatingMode(); + if (operatingMode != OperatingMode.STARTED) break; + List activeBoluses = connectionService.requestMessage(new GetActiveBolusesMessage()).await().getActiveBoluses(); + ActiveBolus activeBolus = null; + for (ActiveBolus bolus : activeBoluses) { + if (bolus.getBolusID() == bolusID) { + activeBolus = bolus; + break; + } + } + if (activeBolus != null) { + trials = -1; + int percentBefore = bolusingEvent.percent; + bolusingEvent.percent = (int) (100D / activeBolus.getInitialAmount() * (activeBolus.getInitialAmount() - activeBolus.getRemainingAmount())); + bolusingEvent.status = MainApp.gs(R.string.insight_delivered, activeBolus.getInitialAmount() - activeBolus.getRemainingAmount(), activeBolus.getInitialAmount()); + if (percentBefore != bolusingEvent.percent) + MainApp.bus().post(bolusingEvent); + } else { + synchronized ($bolusLock) { + if (bolusCancelled || trials == -1 || trials++ >= 5) { + if (!bolusCancelled) { + bolusingEvent.status = MainApp.gs(R.string.insight_delivered, detailedBolusInfo.insulin, detailedBolusInfo.insulin); + bolusingEvent.percent = 100; + MainApp.bus().post(bolusingEvent); + } + break; + } + } + } + Thread.sleep(200); + } + readHistory(); + fetchStatus(); + } catch (AppLayerErrorException e) { + log.info("Exception while delivering bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); + } catch (InsightException e) { + log.info("Exception while delivering bolus: " + e.getClass().getCanonicalName()); + result.comment = ExceptionTranslator.getString(e); + } catch (Exception e) { + log.error("Exception while delivering bolus", e); + result.comment = ExceptionTranslator.getString(e); + } + } else if (detailedBolusInfo.carbs > 0) { + result.success = true; + result.enacted = true; + } + result.carbsDelivered = detailedBolusInfo.carbs; + return result; + } + + @Override + public void stopBolusDelivering() { + new Thread(() -> { + try { + synchronized ($bolusLock) { + alertService.ignore(AlertType.WARNING_38); + CancelBolusMessage cancelBolusMessage = new CancelBolusMessage(); + cancelBolusMessage.setBolusID(bolusID); + connectionService.requestMessage(cancelBolusMessage).await(); + bolusCancelled = true; + } + confirmAlert(AlertType.WARNING_38); + } catch (AppLayerErrorException e) { + log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + } catch (InsightException e) { + log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName()); + } catch (Exception e) { + log.error("Exception while canceling bolus", e); + } + }).start(); + } + + @Override + public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) { + PumpEnactResult result = new PumpEnactResult(); + if (activeBasalRate == null) return result; + if (activeBasalRate.getActiveBasalRate() == 0) return result; + double percent = 100D / activeBasalRate.getActiveBasalRate() * absoluteRate; + if (isFakingTempsByExtendedBoluses()) { + PumpEnactResult cancelEBResult = cancelExtendedBolusOnly(); + if (cancelEBResult.success) { + if (percent > 250) { + PumpEnactResult cancelTBRResult = cancelTempBasalOnly(); + if (cancelTBRResult.success) { + PumpEnactResult ebResult = setExtendedBolusOnly((absoluteRate - getBaseBasalRate()) / 60D + * ((double) durationInMinutes), durationInMinutes); + if (ebResult.success) { + result.success = true; + result.enacted = true; + result.isPercent = false; + result.absolute = absoluteRate; + result.duration = durationInMinutes; + result.comment = MainApp.gs(R.string.virtualpump_resultok); + } else { + result.comment = ebResult.comment; + } + } else { + result.comment = cancelTBRResult.comment; + } + } else { + return setTempBasalPercent((int) Math.round(percent), durationInMinutes, profile, enforceNew); + } + } else { + result.comment = cancelEBResult.comment; + } + } else { + return setTempBasalPercent((int) Math.round(percent), durationInMinutes, profile, enforceNew); + } + try { + fetchStatus(); + readHistory(); + } catch (AppLayerErrorException e) { + log.info("Exception after setting TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + } catch (InsightException e) { + log.info("Exception after setting TBR: " + e.getClass().getCanonicalName()); + } catch (Exception e) { + log.error("Exception after setting TBR", e); + } + return result; + } + + @Override + public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) { + PumpEnactResult result = new PumpEnactResult(); + percent = (int) Math.round(((double) percent) / 10d) * 10; + if (percent == 100) return cancelTempBasal(true); + else if (percent > 250) percent = 250; + try { + if (activeTBR != null) { + ChangeTBRMessage message = new ChangeTBRMessage(); + message.setDuration(durationInMinutes); + message.setPercentage(percent); + connectionService.requestMessage(message); + } else { + SetTBRMessage message = new SetTBRMessage(); + message.setDuration(durationInMinutes); + message.setPercentage(percent); + connectionService.requestMessage(message); + } + result.isPercent = true; + result.percent = percent; + result.duration = durationInMinutes; + result.success = true; + result.enacted = true; + result.comment = MainApp.gs(R.string.virtualpump_resultok); + readHistory(); + fetchStatus(); + } catch (AppLayerErrorException e) { + log.info("Exception while setting TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); + } catch (InsightException e) { + log.info("Exception while setting TBR: " + e.getClass().getCanonicalName()); + result.comment = ExceptionTranslator.getString(e); + } catch (Exception e) { + log.error("Exception while setting TBR", e); + result.comment = ExceptionTranslator.getString(e); + } + return result; + } + + @Override + public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { + PumpEnactResult result = cancelExtendedBolusOnly(); + if (result.success) result = setExtendedBolusOnly(insulin, durationInMinutes); + try { + fetchStatus(); + readHistory(); + } catch (AppLayerErrorException e) { + log.info("Exception after delivering extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + } catch (InsightException e) { + log.info("Exception after delivering extended bolus: " + e.getClass().getCanonicalName()); + } catch (Exception e) { + log.error("Exception after delivering extended bolus", e); + } + return result; + } + + public PumpEnactResult setExtendedBolusOnly(Double insulin, Integer durationInMinutes) { + PumpEnactResult result = new PumpEnactResult(); + try { + DeliverBolusMessage bolusMessage = new DeliverBolusMessage(); + bolusMessage.setBolusType(BolusType.EXTENDED); + bolusMessage.setDuration(durationInMinutes); + bolusMessage.setExtendedAmount(insulin); + bolusMessage.setImmediateAmount(0); + int bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId(); + InsightBolusID insightBolusID = new InsightBolusID(); + insightBolusID.bolusID = bolusID; + insightBolusID.timestamp = System.currentTimeMillis(); + insightBolusID.pumpSerial = connectionService.getPumpSystemIdentification().getSerialNumber(); + MainApp.getDbHelper().createOrUpdate(insightBolusID); + ExtendedBolus extendedBolus = new ExtendedBolus(); + extendedBolus.date = insightBolusID.timestamp; + extendedBolus.source = Source.PUMP; + extendedBolus.durationInMinutes = durationInMinutes; + extendedBolus.insulin = insulin; + extendedBolus.pumpId = insightBolusID.id; + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); + result.success = true; + result.enacted = true; + result.comment = MainApp.gs(R.string.virtualpump_resultok); + } catch (AppLayerErrorException e) { + log.info("Exception while delivering extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); + } catch (InsightException e) { + log.info("Exception while delivering extended bolus: " + e.getClass().getCanonicalName()); + result.comment = ExceptionTranslator.getString(e); + } catch (Exception e) { + log.error("Exception while delivering extended bolus", e); + result.comment = ExceptionTranslator.getString(e); + } + return result; + } + + @Override + public PumpEnactResult cancelTempBasal(boolean enforceNew) { + PumpEnactResult result = new PumpEnactResult(); + PumpEnactResult cancelEBResult = null; + if (isFakingTempsByExtendedBoluses()) cancelEBResult = cancelExtendedBolusOnly(); + PumpEnactResult cancelTBRResult = cancelTempBasalOnly(); + result.success = (cancelEBResult != null && cancelEBResult.success) && cancelTBRResult.success; + result.enacted = (cancelEBResult != null && cancelEBResult.enacted) || cancelTBRResult.enacted; + result.comment = cancelEBResult != null ? cancelEBResult.comment : cancelTBRResult.comment; + try { + fetchStatus(); + readHistory(); + } catch (AppLayerErrorException e) { + log.info("Exception after canceling TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + } catch (InsightException e) { + log.info("Exception after canceling TBR: " + e.getClass().getCanonicalName()); + } catch (Exception e) { + log.error("Exception after canceling TBR", e); + } + return result; + } + + private PumpEnactResult cancelTempBasalOnly() { + PumpEnactResult result = new PumpEnactResult(); + try { + alertService.ignore(AlertType.WARNING_36); + connectionService.requestMessage(new CancelTBRMessage()).await(); + result.success = true; + result.enacted = true; + result.isTempCancel = true; + confirmAlert(AlertType.WARNING_36); + alertService.ignore(null); + result.comment = MainApp.gs(R.string.virtualpump_resultok); + } catch (NoActiveTBRToCanceLException e) { + result.success = true; + result.comment = MainApp.gs(R.string.virtualpump_resultok); + } catch (AppLayerErrorException e) { + log.info("Exception while canceling TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); + } catch (InsightException e) { + log.info("Exception while canceling TBR: " + e.getClass().getCanonicalName()); + result.comment = ExceptionTranslator.getString(e); + } catch (Exception e) { + log.error("Exception while canceling TBR", e); + result.comment = ExceptionTranslator.getString(e); + } + return result; + } + + @Override + public PumpEnactResult cancelExtendedBolus() { + PumpEnactResult result = cancelExtendedBolusOnly(); + try { + fetchStatus(); + readHistory(); + } catch (AppLayerErrorException e) { + log.info("Exception after canceling extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + } catch (InsightException e) { + log.info("Exception after canceling extended bolus: " + e.getClass().getCanonicalName()); + } catch (Exception e) { + log.error("Exception after canceling extended bolus", e); + } + return result; + } + + private PumpEnactResult cancelExtendedBolusOnly() { + PumpEnactResult result = new PumpEnactResult(); + try { + for (ActiveBolus activeBolus : activeBoluses) { + if (activeBolus.getBolusType() == BolusType.EXTENDED || activeBolus.getBolusType() == BolusType.MULTIWAVE) { + alertService.ignore(AlertType.WARNING_38); + CancelBolusMessage cancelBolusMessage = new CancelBolusMessage(); + cancelBolusMessage.setBolusID(activeBolus.getBolusID()); + connectionService.requestMessage(cancelBolusMessage).await(); + confirmAlert(AlertType.WARNING_38); + alertService.ignore(null); + InsightBolusID insightBolusID = MainApp.getDbHelper().getInsightBolusID(connectionService.getPumpSystemIdentification().getSerialNumber(), + activeBolus.getBolusID(), System.currentTimeMillis()); + if (insightBolusID != null) { + ExtendedBolus extendedBolus = MainApp.getDbHelper().getExtendedBolusByPumpId(insightBolusID.id); + if (extendedBolus != null) { + extendedBolus.durationInMinutes = (int) ((System.currentTimeMillis() - extendedBolus.date) / 60000); + if (extendedBolus.durationInMinutes <= 0) { + ; + final String _id = extendedBolus._id; + if (NSUpload.isIdValid(_id)) + NSUpload.removeCareportalEntryFromNS(_id); + else UploadQueue.removeID("dbAdd", _id); + MainApp.getDbHelper().delete(extendedBolus); + } else + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); + } + result.enacted = true; + result.success = true; + } + } + } + result.success = true; + result.comment = MainApp.gs(R.string.virtualpump_resultok); + } catch (AppLayerErrorException e) { + log.info("Exception while canceling extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); + } catch (InsightException e) { + log.info("Exception while canceling extended bolus: " + e.getClass().getCanonicalName()); + result.comment = ExceptionTranslator.getString(e); + } catch (Exception e) { + log.error("Exception while canceling extended bolus", e); + result.comment = ExceptionTranslator.getString(e); + } + return result; + } + + private void confirmAlert(AlertType alertType) { + try { + long started = System.currentTimeMillis(); + while (System.currentTimeMillis() - started < 10000) { + GetActiveAlertMessage activeAlertMessage = connectionService.requestMessage(new GetActiveAlertMessage()).await(); + if (activeAlertMessage.getAlert() != null) { + if (activeAlertMessage.getAlert().getAlertType() == alertType) { + ConfirmAlertMessage confirmMessage = new ConfirmAlertMessage(); + confirmMessage.setAlertID(activeAlertMessage.getAlert().getAlertId()); + connectionService.requestMessage(confirmMessage).await(); + } else break; + } + } + } catch (AppLayerErrorException e) { + log.info("Exception while confirming alert: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + } catch (InsightException e) { + log.info("Exception while confirming alert: " + e.getClass().getCanonicalName()); + } catch (Exception e) { + log.error("Exception while confirming alert", e); + } + } + + @Override + public JSONObject getJSONStatus(Profile profile, String profileName) { + long now = System.currentTimeMillis(); + if (System.currentTimeMillis() - connectionService.getLastConnected() > (60 * 60 * 1000)) { + return null; + } + + final JSONObject pump = new JSONObject(); + final JSONObject battery = new JSONObject(); + final JSONObject status = new JSONObject(); + final JSONObject extended = new JSONObject(); + try { + status.put("timestamp", DateUtil.toISOString(connectionService.getLastConnected())); + extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); + try { + extended.put("ActiveProfile", ProfileFunctions.getInstance().getProfileName()); + } catch (Exception e) { + } + TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); + if (tb != null) { + extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile)); + extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date)); + extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); + } + ExtendedBolus eb = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(now); + if (eb != null) { + extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); + extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); + extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes()); + } + extended.put("BaseBasalRate", getBaseBasalRate()); + status.put("timestamp", DateUtil.toISOString(now)); + + pump.put("extended", extended); + if (statusLoaded) { + status.put("status", operatingMode != OperatingMode.STARTED ? "suspended" : "normal"); + pump.put("status", status); + battery.put("percent", batteryStatus.getBatteryAmount()); + pump.put("battery", battery); + pump.put("reservoir", cartridgeStatus.getRemainingAmount()); + } + pump.put("clock", DateUtil.toISOString(now)); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return pump; + } + + @Override + public String deviceID() { + if (connectionService == null || alertService == null) return null; + return connectionService.getPumpSystemIdentification().getSerialNumber(); + } + + public PumpEnactResult stopPump() { + PumpEnactResult result = new PumpEnactResult(); + try { + SetOperatingModeMessage operatingModeMessage = new SetOperatingModeMessage(); + operatingModeMessage.setOperatingMode(OperatingMode.STOPPED); + connectionService.requestMessage(operatingModeMessage).await(); + result.success = true; + result.enacted = true; + fetchStatus(); + readHistory(); + } catch (AppLayerErrorException e) { + log.info("Exception while stopping pump: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); + } catch (InsightException e) { + log.info("Exception while stopping pump: " + e.getClass().getCanonicalName()); + result.comment = ExceptionTranslator.getString(e); + } catch (Exception e) { + log.error("Exception while stopping pump", e); + result.comment = ExceptionTranslator.getString(e); + } + return result; + } + + public PumpEnactResult startPump() { + PumpEnactResult result = new PumpEnactResult(); + try { + SetOperatingModeMessage operatingModeMessage = new SetOperatingModeMessage(); + operatingModeMessage.setOperatingMode(OperatingMode.STARTED); + connectionService.requestMessage(operatingModeMessage).await(); + result.success = true; + result.enacted = true; + fetchStatus(); + readHistory(); + } catch (AppLayerErrorException e) { + log.info("Exception while starting pump: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); + } catch (InsightException e) { + log.info("Exception while starting pump: " + e.getClass().getCanonicalName()); + result.comment = ExceptionTranslator.getString(e); + } catch (Exception e) { + log.error("Exception while starting pump", e); + result.comment = ExceptionTranslator.getString(e); + } + return result; + } + + public PumpEnactResult setTBROverNotification(boolean enabled) { + PumpEnactResult result = new PumpEnactResult(); + boolean valueBefore = tbrOverNotificationBlock.isEnabled(); + tbrOverNotificationBlock.setEnabled(enabled); + try { + ParameterBlockUtil.writeConfigurationBlock(connectionService, tbrOverNotificationBlock); + result.success = true; + result.enacted = true; + } catch (AppLayerErrorException e) { + tbrOverNotificationBlock.setEnabled(valueBefore); + log.info("Exception while updating TBR notification block: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); + } catch (InsightException e) { + tbrOverNotificationBlock.setEnabled(valueBefore); + log.info("Exception while updating TBR notification block: " + e.getClass().getSimpleName()); + result.comment = ExceptionTranslator.getString(e); + } catch (Exception e) { + tbrOverNotificationBlock.setEnabled(valueBefore); + log.error("Exception while updating TBR notification block", e); + result.comment = ExceptionTranslator.getString(e); + } + return result; + } + + @Override + public PumpDescription getPumpDescription() { + return pumpDescription; + } + + @Override + public String shortStatus(boolean veryShort) { + StringBuilder ret = new StringBuilder(); + if (connectionService.getLastConnected() != 0) { + Long agoMsec = System.currentTimeMillis() - connectionService.getLastConnected(); + int agoMin = (int) (agoMsec / 60d / 1000d); + ret.append(MainApp.gs(R.string.short_status_last_connected, agoMin) + "\n"); + } + if (activeTBR != null) { + ret.append(MainApp.gs(R.string.short_status_tbr, activeTBR.getPercentage(), + activeTBR.getInitialDuration() - activeTBR.getRemainingDuration(), activeTBR.getInitialDuration()) + "\n"); + } + if (activeBoluses != null) for (ActiveBolus activeBolus : activeBoluses) { + if (activeBolus.getBolusType() == BolusType.STANDARD) continue; + ret.append(MainApp.gs(activeBolus.getBolusType() == BolusType.MULTIWAVE ? R.string.short_status_multiwave : R.string.short_status_extended, + activeBolus.getRemainingAmount(), activeBolus.getInitialAmount(), activeBolus.getRemainingDuration()) + "\n"); + } + if (!veryShort && totalDailyDose != null) { + ret.append(MainApp.gs(R.string.short_status_tdd, totalDailyDose.getBolusAndBasal()) + "\n"); + } + if (cartridgeStatus != null) { + ret.append(MainApp.gs(R.string.short_status_reservoir, cartridgeStatus.getRemainingAmount()) + "\n"); + } + if (batteryStatus != null) { + ret.append(MainApp.gs(R.string.short_status_battery, batteryStatus.getBatteryAmount()) + "\n"); + } + return ret.toString(); + } + + @Override + public boolean isFakingTempsByExtendedBoluses() { + return SP.getBoolean("insight_enable_tbr_emulation", false); + } + + @Override + public PumpEnactResult loadTDDs() { + return new PumpEnactResult().success(true); + } + + @Override + public List getCustomActions() { + return null; + } + + @Override + public void executeCustomAction(CustomActionType customActionType) { + + } + + private void readHistory() { + try { + PumpTime pumpTime = connectionService.requestMessage(new GetDateTimeMessage()).await().getPumpTime(); + String pumpSerial = connectionService.getPumpSystemIdentification().getSerialNumber(); + timeOffset = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis() - parseDate(pumpTime.getYear(), + pumpTime.getMonth(), pumpTime.getDay(), pumpTime.getHour(), pumpTime.getMinute(), pumpTime.getSecond()); + InsightHistoryOffset historyOffset = MainApp.getDbHelper().getInsightHistoryOffset(pumpSerial); + try { + List historyEvents = new ArrayList<>(); + if (historyOffset == null) { + StartReadingHistoryMessage startMessage = new StartReadingHistoryMessage(); + startMessage.setDirection(HistoryReadingDirection.BACKWARD); + startMessage.setOffset(0xFFFFFFFF); + connectionService.requestMessage(startMessage).await(); + historyEvents = connectionService.requestMessage(new ReadHistoryEventsMessage()).await().getHistoryEvents(); + } else { + StartReadingHistoryMessage startMessage = new StartReadingHistoryMessage(); + startMessage.setDirection(HistoryReadingDirection.FORWARD); + startMessage.setOffset(historyOffset.offset + 1); + connectionService.requestMessage(startMessage).await(); + while (true) { + List newEvents = connectionService.requestMessage(new ReadHistoryEventsMessage()).await().getHistoryEvents(); + if (newEvents.size() == 0) break; + historyEvents.addAll(newEvents); + } + } + Collections.sort(historyEvents); + Collections.reverse(historyEvents); + if (historyOffset != null) processHistoryEvents(pumpSerial, historyEvents); + if (historyEvents.size() > 0) { + historyOffset = new InsightHistoryOffset(); + historyOffset.pumpSerial = pumpSerial; + historyOffset.offset = historyEvents.get(0).getEventPosition(); + MainApp.getDbHelper().createOrUpdate(historyOffset); + } + } catch (AppLayerErrorException e) { + log.info("Exception while reading history: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + } catch (InsightException e) { + log.info("Exception while reading history: " + e.getClass().getSimpleName()); + } catch (Exception e) { + log.error("Exception while reading history", e); + } finally { + try { + connectionService.requestMessage(new StopReadingHistoryMessage()).await(); + } catch (Exception ignored) { + } + } + } catch (AppLayerErrorException e) { + log.info("Exception while reading history: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + } catch (InsightException e) { + log.info("Exception while reading history: " + e.getClass().getSimpleName()); + } catch (Exception e) { + log.error("Exception while reading history", e); + } + new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventRefreshOverview("LocalInsightPlugin::readHistory"))); + } + + private void processHistoryEvents(String serial, List historyEvents) { + List temporaryBasals = new ArrayList<>(); + List pumpStartedEvents = new ArrayList<>(); + for (HistoryEvent historyEvent : historyEvents) + if (!processHistoryEvent(serial, temporaryBasals, pumpStartedEvents, historyEvent)) + break; + Collections.reverse(temporaryBasals); + for (InsightPumpID pumpID : pumpStartedEvents) { + InsightPumpID stoppedEvent = MainApp.getDbHelper().getPumpStoppedEvent(pumpID.pumpSerial, pumpID.timestamp); + if (stoppedEvent == null || stoppedEvent.eventType.equals("PumpPaused")) continue; + long tbrStart = stoppedEvent.timestamp + 10000; + TemporaryBasal temporaryBasal = new TemporaryBasal(); + temporaryBasal.durationInMinutes = (int) ((pumpID.timestamp - tbrStart) / 60000); + temporaryBasal.date = tbrStart; + temporaryBasal.source = Source.PUMP; + temporaryBasal.pumpId = pumpID.id; + temporaryBasal.percentRate = 0; + temporaryBasal.isAbsolute = false; + temporaryBasals.add(temporaryBasal); + } + Collections.sort(temporaryBasals, (o1, o2) -> (int) (o1.date - o2.date)); + for (TemporaryBasal temporaryBasal : temporaryBasals) + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal); + } + + private boolean processHistoryEvent(String serial, List temporaryBasals, List pumpStartedEvents, HistoryEvent event) { + if (event instanceof DefaultDateTimeSetEvent) return false; + else if (event instanceof DateTimeChangedEvent) + processDateTimeChangedEvent((DateTimeChangedEvent) event); + else if (event instanceof CannulaFilledEvent) + processCannulaFilledEvent((CannulaFilledEvent) event); + else if (event instanceof TotalDailyDoseEvent) + processTotalDailyDoseEvent((TotalDailyDoseEvent) event); + else if (event instanceof TubeFilledEvent) processTubeFilledEvent((TubeFilledEvent) event); + else if (event instanceof SniffingDoneEvent) + processSniffingDoneEvent((SniffingDoneEvent) event); + else if (event instanceof PowerUpEvent) processPowerUpEvent((PowerUpEvent) event); + else if (event instanceof OperatingModeChangedEvent) + processOperatingModeChangedEvent(serial, pumpStartedEvents, (OperatingModeChangedEvent) event); + else if (event instanceof StartOfTBREvent) + processStartOfTBREvent(serial, temporaryBasals, (StartOfTBREvent) event); + else if (event instanceof EndOfTBREvent) + processEndOfTBREvent(serial, temporaryBasals, (EndOfTBREvent) event); + else if (event instanceof BolusProgrammedEvent) + processBolusProgrammedEvent(serial, (BolusProgrammedEvent) event); + else if (event instanceof BolusDeliveredEvent) + processBolusDeliveredEvent(serial, (BolusDeliveredEvent) event); + else if (event instanceof OccurrenceOfAlertEvent) + processOccurrenceOfAlertEvent((OccurrenceOfAlertEvent) event); + return true; + } + + private void processDateTimeChangedEvent(DateTimeChangedEvent event) { + long timeAfter = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), event.getEventHour(), event.getEventMinute(), event.getEventSecond()); + long timeBefore = parseDate(event.getBeforeYear(), event.getBeforeMonth(), event.getBeforeDay(), event.getBeforeHour(), event.getBeforeMinute(), event.getBeforeSecond()); + timeOffset -= timeAfter - timeBefore; + } + + private void processCannulaFilledEvent(CannulaFilledEvent event) { + long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), + event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset; + uploadCareportalEvent(timestamp, CareportalEvent.SITECHANGE); + } + + private void processTotalDailyDoseEvent(TotalDailyDoseEvent event) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date(0)); + calendar.set(Calendar.YEAR, event.getTotalYear()); + calendar.set(Calendar.MONTH, event.getTotalMonth() - 1); + calendar.set(Calendar.DAY_OF_MONTH, event.getTotalDay()); + TDD tdd = new TDD(); + tdd.basal = event.getBasalTotal(); + tdd.bolus = event.getBolusTotal(); + tdd.total = tdd.basal + tdd.bolus; + tdd.date = calendar.getTimeInMillis(); + MainApp.getDbHelper().createOrUpdateTDD(tdd); + } + + private void processTubeFilledEvent(TubeFilledEvent event) { + if (!SP.getBoolean("insight_log_tube_changes", false)) return; + long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), + event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset; + logNote(timestamp, MainApp.gs(R.string.tube_changed)); + } + + private void processSniffingDoneEvent(SniffingDoneEvent event) { + if (!SP.getBoolean("insight_log_site_changes", false)) return; + long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), + event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset; + uploadCareportalEvent(timestamp, CareportalEvent.INSULINCHANGE); + } + + private void processPowerUpEvent(PowerUpEvent event) { + if (!SP.getBoolean("insight_log_battery_changes", false)) return; + long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), + event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset; + uploadCareportalEvent(timestamp, CareportalEvent.PUMPBATTERYCHANGE); + } + + private void processOperatingModeChangedEvent(String serial, List pumpStartedEvents, OperatingModeChangedEvent event) { + long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), + event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset; + InsightPumpID pumpID = new InsightPumpID(); + pumpID.eventID = event.getEventPosition(); + pumpID.pumpSerial = serial; + pumpID.timestamp = timestamp; + switch (event.getNewValue()) { + case STARTED: + pumpID.eventType = "PumpStarted"; + pumpStartedEvents.add(pumpID); + if (SP.getBoolean("insight_log_operating_mode_changes", false)) + logNote(timestamp, MainApp.gs(R.string.pump_started)); + break; + case STOPPED: + pumpID.eventType = "PumpStopped"; + if (SP.getBoolean("insight_log_operating_mode_changes", false)) + logNote(timestamp, MainApp.gs(R.string.pump_stopped)); + break; + case PAUSED: + pumpID.eventType = "PumpPaused"; + if (SP.getBoolean("insight_log_operating_mode_changes", false)) + logNote(timestamp, MainApp.gs(R.string.pump_paused)); + break; + } + MainApp.getDbHelper().createOrUpdate(pumpID); + } + + private void processStartOfTBREvent(String serial, List temporaryBasals, StartOfTBREvent event) { + long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), + event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset; + InsightPumpID pumpID = new InsightPumpID(); + pumpID.eventID = event.getEventPosition(); + pumpID.pumpSerial = serial; + pumpID.timestamp = timestamp; + pumpID.eventType = "StartOfTBR"; + MainApp.getDbHelper().createOrUpdate(pumpID); + TemporaryBasal temporaryBasal = new TemporaryBasal(); + temporaryBasal.durationInMinutes = event.getDuration(); + temporaryBasal.source = Source.PUMP; + temporaryBasal.pumpId = pumpID.id; + temporaryBasal.percentRate = event.getAmount(); + temporaryBasal.isAbsolute = false; + temporaryBasal.date = timestamp; + temporaryBasals.add(temporaryBasal); + } + + private void processEndOfTBREvent(String serial, List temporaryBasals, EndOfTBREvent event) { + long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), + event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset; + InsightPumpID pumpID = new InsightPumpID(); + pumpID.eventID = event.getEventPosition(); + pumpID.pumpSerial = serial; + pumpID.eventType = "EndOfTBR"; + pumpID.timestamp = timestamp; + MainApp.getDbHelper().createOrUpdate(pumpID); + TemporaryBasal temporaryBasal = new TemporaryBasal(); + temporaryBasal.durationInMinutes = 0; + temporaryBasal.source = Source.PUMP; + temporaryBasal.pumpId = pumpID.id; + temporaryBasal.date = timestamp; + temporaryBasals.add(temporaryBasal); + } + + private void processBolusProgrammedEvent(String serial, BolusProgrammedEvent event) { + long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), + event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset; + InsightBolusID bolusID = MainApp.getDbHelper().getInsightBolusID(serial, event.getBolusID(), timestamp); + if (bolusID != null && bolusID.endID != null) { + bolusID.startID = event.getEventPosition(); + MainApp.getDbHelper().createOrUpdate(bolusID); + return; + } + if (bolusID == null || bolusID.startID != null) { + bolusID = new InsightBolusID(); + bolusID.timestamp = timestamp; + bolusID.bolusID = event.getBolusID(); + bolusID.pumpSerial = serial; + } + bolusID.startID = event.getEventPosition(); + MainApp.getDbHelper().createOrUpdate(bolusID); + if (event.getBolusType() == BolusType.STANDARD || event.getBolusType() == BolusType.MULTIWAVE) { + DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); + detailedBolusInfo.date = bolusID.timestamp; + detailedBolusInfo.source = Source.PUMP; + detailedBolusInfo.pumpId = bolusID.id; + detailedBolusInfo.insulin = event.getImmediateAmount(); + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); + } + if ((event.getBolusType() == BolusType.EXTENDED || event.getBolusType() == BolusType.MULTIWAVE)) { + ExtendedBolus extendedBolus = new ExtendedBolus(); + extendedBolus.date = bolusID.timestamp; + extendedBolus.source = Source.PUMP; + extendedBolus.durationInMinutes = event.getDuration(); + extendedBolus.insulin = event.getExtendedAmount(); + extendedBolus.pumpId = bolusID.id; + if (ProfileFunctions.getInstance().getProfile(extendedBolus.date) != null) + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); + } + } + + private void processBolusDeliveredEvent(String serial, BolusDeliveredEvent event) { + long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), + event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset; + long startTimestamp = parseRelativeDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), event.getEventHour(), + event.getEventMinute(), event.getEventSecond(), event.getStartHour(), event.getStartMinute(), event.getStartSecond()) + timeOffset; + InsightBolusID bolusID = MainApp.getDbHelper().getInsightBolusID(serial, event.getBolusID(), timestamp); + if (bolusID == null || bolusID.endID != null) { + bolusID = new InsightBolusID(); + bolusID.timestamp = startTimestamp; + bolusID.bolusID = event.getBolusID(); + bolusID.pumpSerial = serial; + } + bolusID.endID = event.getEventPosition(); + MainApp.getDbHelper().createOrUpdate(bolusID); + if (event.getBolusType() == BolusType.STANDARD || event.getBolusType() == BolusType.MULTIWAVE) { + DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); + detailedBolusInfo.date = bolusID.timestamp; + detailedBolusInfo.source = Source.PUMP; + detailedBolusInfo.pumpId = bolusID.id; + detailedBolusInfo.insulin = event.getImmediateAmount(); + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); + } + if (event.getBolusType() == BolusType.EXTENDED || event.getBolusType() == BolusType.MULTIWAVE) { + if (event.getDuration() == 0) { + ExtendedBolus extendedBolus = MainApp.getDbHelper().getExtendedBolusByPumpId(bolusID.id); + if (extendedBolus != null) { + final String _id = extendedBolus._id; + if (NSUpload.isIdValid(_id)) NSUpload.removeCareportalEntryFromNS(_id); + else UploadQueue.removeID("dbAdd", _id); + MainApp.getDbHelper().delete(extendedBolus); + } + } else { + ExtendedBolus extendedBolus = new ExtendedBolus(); + extendedBolus.date = bolusID.timestamp; + extendedBolus.source = Source.PUMP; + extendedBolus.durationInMinutes = event.getDuration(); + extendedBolus.insulin = event.getExtendedAmount(); + extendedBolus.pumpId = bolusID.id; + if (ProfileFunctions.getInstance().getProfile(extendedBolus.date) != null) + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); + } + } + } + + private void processOccurrenceOfAlertEvent(OccurrenceOfAlertEvent event) { + if (!SP.getBoolean("insight_log_alerts", false)) return; + long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), + event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset; + Integer code = null; + Integer title = null; + switch (event.getAlertType()) { + case ERROR_6: + code = R.string.alert_e6_code; + title = R.string.alert_e6_title; + break; + case ERROR_10: + code = R.string.alert_e10_code; + title = R.string.alert_e10_title; + break; + case ERROR_13: + code = R.string.alert_e13_code; + title = R.string.alert_e13_title; + break; + case MAINTENANCE_20: + code = R.string.alert_m20_code; + title = R.string.alert_m20_title; + break; + case MAINTENANCE_21: + code = R.string.alert_m21_code; + title = R.string.alert_m21_title; + break; + case MAINTENANCE_22: + code = R.string.alert_m22_code; + title = R.string.alert_m22_title; + break; + case MAINTENANCE_23: + code = R.string.alert_m23_code; + title = R.string.alert_m23_title; + break; + case MAINTENANCE_24: + code = R.string.alert_m24_code; + title = R.string.alert_m24_title; + break; + case MAINTENANCE_25: + code = R.string.alert_m25_code; + title = R.string.alert_m25_title; + break; + case MAINTENANCE_26: + code = R.string.alert_m26_code; + title = R.string.alert_m26_title; + break; + case MAINTENANCE_27: + code = R.string.alert_m27_code; + title = R.string.alert_m27_title; + break; + case MAINTENANCE_28: + code = R.string.alert_m28_code; + title = R.string.alert_m28_title; + break; + case MAINTENANCE_29: + code = R.string.alert_m29_code; + title = R.string.alert_m29_title; + break; + case MAINTENANCE_30: + code = R.string.alert_m30_code; + title = R.string.alert_m30_title; + break; + case WARNING_31: + code = R.string.alert_w31_code; + title = R.string.alert_w31_title; + break; + case WARNING_32: + code = R.string.alert_w32_code; + title = R.string.alert_w32_title; + break; + case WARNING_33: + code = R.string.alert_w33_code; + title = R.string.alert_w33_title; + break; + case WARNING_34: + code = R.string.alert_w34_code; + title = R.string.alert_w34_title; + break; + case WARNING_39: + code = R.string.alert_w39_code; + title = R.string.alert_w39_title; + break; + } + if (code != null) + logNote(timestamp, MainApp.gs(R.string.insight_alert_formatter, MainApp.gs(code), MainApp.gs(title))); + } + + private long parseDate(int year, int month, int day, int hour, int minute, int second) { + Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + calendar.set(Calendar.YEAR, year); + calendar.set(Calendar.MONTH, month - 1); + calendar.set(Calendar.DAY_OF_MONTH, day); + calendar.set(Calendar.HOUR_OF_DAY, hour); + calendar.set(Calendar.MINUTE, minute); + calendar.set(Calendar.SECOND, second); + return calendar.getTimeInMillis(); + } + + private void logNote(long date, String note) { + try { + if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date) != null) + return; + JSONObject data = new JSONObject(); + String enteredBy = SP.getString("careportal_enteredby", ""); + if (!enteredBy.equals("")) data.put("enteredBy", enteredBy); + data.put("created_at", DateUtil.toISOString(date)); + data.put("eventType", CareportalEvent.NOTE); + data.put("notes", note); + NSUpload.uploadCareportalEntryToNS(data); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + private long parseRelativeDate(int year, int month, int day, int hour, int minute, int second, int relativeHour, int relativeMinute, int relativeSecond) { + if (relativeHour * 60 * 60 + relativeMinute * 60 + relativeSecond >= hour * 60 * 60 * minute * 60 + second) + day--; + Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + calendar.set(Calendar.YEAR, year); + calendar.set(Calendar.MONTH, month - 1); + calendar.set(Calendar.DAY_OF_MONTH, day); + calendar.set(Calendar.HOUR_OF_DAY, relativeHour); + calendar.set(Calendar.MINUTE, relativeMinute); + calendar.set(Calendar.SECOND, relativeSecond); + return calendar.getTimeInMillis(); + } + + private void uploadCareportalEvent(long date, String event) { + if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date) != null) + return; + try { + JSONObject data = new JSONObject(); + String enteredBy = SP.getString("careportal_enteredby", ""); + if (!enteredBy.equals("")) data.put("enteredBy", enteredBy); + data.put("created_at", DateUtil.toISOString(date)); + data.put("eventType", event); + NSUpload.uploadCareportalEntryToNS(data); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + public Constraint applyBasalPercentConstraints(Constraint percentRate, Profile profile) { + percentRate.setIfGreater(0, String.format(MainApp.gs(R.string.limitingpercentrate), 0, MainApp.gs(R.string.itmustbepositivevalue)), this); + percentRate.setIfSmaller(getPumpDescription().maxTempPercent, String.format(MainApp.gs(R.string.limitingpercentrate), getPumpDescription().maxTempPercent, MainApp.gs(R.string.pumplimit)), this); + return percentRate; + } + + @Override + public Constraint applyBolusConstraints(Constraint insulin) { + if (!limitsFetched) return insulin; + insulin.setIfSmaller(maximumBolusAmount, String.format(MainApp.gs(R.string.limitingbolus), maximumBolusAmount, MainApp.gs(R.string.pumplimit)), this); + if (insulin.value() < minimumBolusAmount) { + + //TODO: Add function to Constraints or use different approach + // This only works if the interface of the InsightPlugin is called last. + // If not, another constraint could theoretically set the value between 0 and minimumBolusAmount + + insulin.set(0d, String.format(MainApp.gs(R.string.limitingbolus), minimumBolusAmount, MainApp.gs(R.string.pumplimit)), this); + } + return insulin; + } + + @Override + public void onStateChanged(InsightState state) { + if (state == InsightState.CONNECTED) { + statusLoaded = false; + new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventDismissNotification(Notification.INSIGHT_TIMEOUT_DURING_HANDSHAKE))); + } else if (state == InsightState.NOT_PAIRED) { + connectionService.withdrawConnectionRequest(this); + statusLoaded = false; + profileBlocks = null; + operatingMode = null; + batteryStatus = null; + cartridgeStatus = null; + totalDailyDose = null; + activeBasalRate = null; + activeTBR = null; + activeBoluses = null; + tbrOverNotificationBlock = null; + new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventRefreshOverview("LocalInsightPlugin::onStateChanged"))); + } + new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventLocalInsightUpdateGUI())); + } + + @Override + public void onPumpPaired() { + ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("Pump paired", null); + } + + @Override + public void onTimeoutDuringHandshake() { + Notification notification = new Notification(Notification.INSIGHT_TIMEOUT_DURING_HANDSHAKE, MainApp.gs(R.string.timeout_during_handshake), Notification.URGENT); + new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventNewNotification(notification))); + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightAlertActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightAlertActivity.java new file mode 100644 index 0000000000..c40cb99ed6 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightAlertActivity.java @@ -0,0 +1,257 @@ +package info.nightscout.androidaps.plugins.pump.insight.activities; + +import android.content.ComponentName; +import android.content.Intent; +import android.content.ServiceConnection; +import android.os.Bundle; +import android.os.IBinder; +import android.support.v4.content.ContextCompat; +import android.support.v7.app.AppCompatActivity; +import android.text.Html; +import android.view.View; +import android.view.WindowManager; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; + +import java.text.DecimalFormat; + +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.pump.insight.InsightAlertService; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.Alert; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertStatus; + +public class InsightAlertActivity extends AppCompatActivity { + + private Alert alert; + private InsightAlertService alertService; + + private ImageView icon; + private TextView errorCode; + private TextView errorTitle; + private TextView errorDescription; + private Button mute; + private Button confirm; + + private ServiceConnection serviceConnection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder binder) { + alertService = ((InsightAlertService.LocalBinder) binder).getService(); + alertService.setAlertActivity(InsightAlertActivity.this); + alert = alertService.getAlert(); + if (alert == null) finish(); + update(alert); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + alertService = null; + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_insight_alert); + + bindService(new Intent(this, InsightAlertService.class), serviceConnection, BIND_AUTO_CREATE); + + icon = findViewById(R.id.icon); + errorCode = findViewById(R.id.error_code); + errorTitle = findViewById(R.id.error_title); + errorDescription = findViewById(R.id.error_description); + mute = findViewById(R.id.mute); + confirm = findViewById(R.id.confirm); + + setFinishOnTouchOutside(false); + + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON + | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD + | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED + | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); + WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); + layoutParams.screenBrightness = 1.0F; + getWindow().setAttributes(layoutParams); + } + + @Override + protected void onDestroy() { + alertService.setAlertActivity(null); + unbindService(serviceConnection); + super.onDestroy(); + } + + public void update(Alert alert) { + this.alert = alert; + mute.setEnabled(true); + mute.setVisibility(alert.getAlertStatus() == AlertStatus.SNOOZED ? View.GONE : View.VISIBLE); + confirm.setEnabled(true); + int icon = 0; + int code = 0; + int title = 0; + String description = null; + switch (alert.getAlertCategory()) { + case ERROR: + icon = R.drawable.ic_error; + break; + case MAINTENANCE: + icon = R.drawable.ic_maintenance; + break; + case WARNING: + icon = R.drawable.ic_warning; + break; + case REMINDER: + icon = R.drawable.ic_reminder; + break; + } + DecimalFormat decimalFormat = new DecimalFormat("##0.00"); + int hours = alert.getTBRDuration() / 60; + int minutes = alert.getTBRDuration() - hours * 60; + switch (alert.getAlertType()) { + case REMINDER_01: + code = R.string.alert_r1_code; + title = R.string.alert_r1_title; + break; + case REMINDER_02: + code = R.string.alert_r2_code; + title = R.string.alert_r2_title; + break; + case REMINDER_03: + code = R.string.alert_r3_code; + title = R.string.alert_r3_title; + break; + case REMINDER_04: + code = R.string.alert_r4_code; + title = R.string.alert_r4_title; + break; + case REMINDER_07: + code = R.string.alert_r7_code; + title = R.string.alert_r7_title; + description = getString(R.string.alert_r7_description, alert.getTBRAmount(), new DecimalFormat("#0").format(hours) + ":" + new DecimalFormat("00").format(minutes)); + break; + case WARNING_31: + code = R.string.alert_w31_code; + title = R.string.alert_w31_title; + description = getString(R.string.alert_w31_description, decimalFormat.format(alert.getCartridgeAmount())); + break; + case WARNING_32: + code = R.string.alert_w32_code; + title = R.string.alert_w32_title; + description = getString(R.string.alert_w32_description); + break; + case WARNING_33: + code = R.string.alert_w33_code; + title = R.string.alert_w33_title; + description = getString(R.string.alert_w33_description); + break; + case WARNING_34: + code = R.string.alert_w34_code; + title = R.string.alert_w34_title; + description = getString(R.string.alert_w34_description); + break; + case WARNING_36: + code = R.string.alert_w36_code; + title = R.string.alert_w36_title; + description = getString(R.string.alert_w36_description, alert.getTBRAmount(), new DecimalFormat("#0").format(hours) + ":" + new DecimalFormat("00").format(minutes)); + break; + case WARNING_38: + code = R.string.alert_w38_code; + title = R.string.alert_w38_title; + description = getString(R.string.alert_w38_description, decimalFormat.format(alert.getProgrammedBolusAmount()), decimalFormat.format(alert.getDeliveredBolusAmount())); + break; + case WARNING_39: + code = R.string.alert_w39_code; + title = R.string.alert_w39_title; + break; + case MAINTENANCE_20: + code = R.string.alert_m20_code; + title = R.string.alert_m20_title; + description = getString(R.string.alert_m20_description); + break; + case MAINTENANCE_21: + code = R.string.alert_m21_code; + title = R.string.alert_m21_title; + description = getString(R.string.alert_m21_description); + break; + case MAINTENANCE_22: + code = R.string.alert_m22_code; + title = R.string.alert_m22_title; + description = getString(R.string.alert_m22_description); + break; + case MAINTENANCE_23: + code = R.string.alert_m23_code; + title = R.string.alert_m23_title; + description = getString(R.string.alert_m23_description); + break; + case MAINTENANCE_24: + code = R.string.alert_m24_code; + title = R.string.alert_m24_title; + description = getString(R.string.alert_m24_description); + break; + case MAINTENANCE_25: + code = R.string.alert_m25_code; + title = R.string.alert_m25_title; + description = getString(R.string.alert_m25_description); + break; + case MAINTENANCE_26: + code = R.string.alert_m26_code; + title = R.string.alert_m26_title; + description = getString(R.string.alert_m26_description); + break; + case MAINTENANCE_27: + code = R.string.alert_m27_code; + title = R.string.alert_m27_title; + description = getString(R.string.alert_m27_description); + break; + case MAINTENANCE_28: + code = R.string.alert_m28_code; + title = R.string.alert_m28_title; + description = getString(R.string.alert_m28_description); + break; + case MAINTENANCE_29: + code = R.string.alert_m29_code; + title = R.string.alert_m29_title; + description = getString(R.string.alert_m29_description); + break; + case MAINTENANCE_30: + code = R.string.alert_m30_code; + title = R.string.alert_m30_title; + description = getString(R.string.alert_m30_description); + break; + case ERROR_6: + code = R.string.alert_e6_code; + title = R.string.alert_e6_title; + description = getString(R.string.alert_e6_description); + break; + case ERROR_10: + code = R.string.alert_e10_code; + title = R.string.alert_e10_title; + description = getString(R.string.alert_e10_description); + break; + case ERROR_13: + code = R.string.alert_e13_code; + title = R.string.alert_e13_title; + description = getString(R.string.alert_e13_description); + break; + } + this.icon.setImageDrawable(ContextCompat.getDrawable(this, icon)); + this.errorCode.setText(code); + this.errorTitle.setText(title); + if (description == null) this.errorDescription.setVisibility(View.GONE); + else { + this.errorDescription.setVisibility(View.VISIBLE); + this.errorDescription.setText(Html.fromHtml(description)); + } + } + + public void muteClicked(View view) { + mute.setEnabled(false); + alertService.mute(); + } + + public void confirmClicked(View view) { + mute.setEnabled(false); + confirm.setEnabled(false); + alertService.confirm(); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightPairingActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightPairingActivity.java new file mode 100644 index 0000000000..7ea52ed271 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightPairingActivity.java @@ -0,0 +1,254 @@ +package info.nightscout.androidaps.plugins.pump.insight.activities; + +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; +import android.content.BroadcastReceiver; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.ServiceConnection; +import android.os.Bundle; +import android.os.IBinder; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.List; + +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.InsightState; +import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator; + +public class InsightPairingActivity extends AppCompatActivity implements InsightConnectionService.StateCallback, View.OnClickListener, InsightConnectionService.ExceptionCallback { + + private boolean scanning; + private LinearLayout deviceSearchSection; + private TextView pleaseWaitSection; + private LinearLayout codeCompareSection; + private LinearLayout pairingCompletedSection; + private Button yes; + private Button no; + private TextView code; + private Button exit; + private RecyclerView deviceList; + private DeviceAdapter deviceAdapter = new DeviceAdapter(); + + private InsightConnectionService service; + + private ServiceConnection serviceConnection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder binder) { + service = ((InsightConnectionService.LocalBinder) binder).getService(); + if (service.isPaired()) return; + else { + service.requestConnection(InsightPairingActivity.this); + service.registerStateCallback(InsightPairingActivity.this); + service.registerExceptionCallback(InsightPairingActivity.this); + onStateChanged(service.getState()); + } + } + + @Override + public void onServiceDisconnected(ComponentName name) { + + } + }; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_insight_pairing); + + deviceSearchSection = findViewById(R.id.device_search_section); + pleaseWaitSection = findViewById(R.id.please_wait_section); + codeCompareSection = findViewById(R.id.code_compare_section); + pairingCompletedSection = findViewById(R.id.pairing_completed_section); + yes = findViewById(R.id.yes); + no = findViewById(R.id.no); + code = findViewById(R.id.code); + exit = findViewById(R.id.exit); + deviceList = findViewById(R.id.device_list); + + yes.setOnClickListener(this); + no.setOnClickListener(this); + exit.setOnClickListener(this); + + deviceList.setLayoutManager(new LinearLayoutManager(this)); + deviceList.setAdapter(deviceAdapter); + + + bindService(new Intent(this, InsightConnectionService.class), serviceConnection, BIND_AUTO_CREATE); +} + + @Override + protected void onDestroy() { + if (service != null) { + service.withdrawConnectionRequest(InsightPairingActivity.this); + service.unregisterStateCallback(InsightPairingActivity.this); + service.unregisterExceptionCallback(InsightPairingActivity.this); + } + unbindService(serviceConnection); + super.onDestroy(); + } + + @Override + protected void onStart() { + super.onStart(); + if (service != null && service.getState() == InsightState.NOT_PAIRED) startBLScan(); + } + + @Override + protected void onStop() { + stopBLScan(); + super.onStop(); + } + + @Override + public void onStateChanged(InsightState state) { + runOnUiThread(() -> { + switch (state) { + case NOT_PAIRED: + startBLScan(); + deviceSearchSection.setVisibility(View.VISIBLE); + pleaseWaitSection.setVisibility(View.GONE); + codeCompareSection.setVisibility(View.GONE); + pairingCompletedSection.setVisibility(View.GONE); + break; + case CONNECTING: + case SATL_CONNECTION_REQUEST: + case SATL_KEY_REQUEST: + case SATL_VERIFY_DISPLAY_REQUEST: + case SATL_VERIFY_CONFIRM_REQUEST: + case APP_BIND_MESSAGE: + stopBLScan(); + deviceSearchSection.setVisibility(View.GONE); + pleaseWaitSection.setVisibility(View.VISIBLE); + codeCompareSection.setVisibility(View.GONE); + pairingCompletedSection.setVisibility(View.GONE); + break; + case AWAITING_CODE_CONFIRMATION: + stopBLScan(); + deviceSearchSection.setVisibility(View.GONE); + pleaseWaitSection.setVisibility(View.GONE); + codeCompareSection.setVisibility(View.VISIBLE); + pairingCompletedSection.setVisibility(View.GONE); + code.setText(service.getVerificationString()); + break; + case DISCONNECTED: + case CONNECTED: + stopBLScan(); + deviceSearchSection.setVisibility(View.GONE); + pleaseWaitSection.setVisibility(View.GONE); + codeCompareSection.setVisibility(View.GONE); + pairingCompletedSection.setVisibility(View.VISIBLE); + break; + } + }); + } + + private void startBLScan() { + if (!scanning) { + BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); + if (!bluetoothAdapter.isEnabled()) bluetoothAdapter.enable(); + IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); + intentFilter.addAction(BluetoothDevice.ACTION_FOUND); + registerReceiver(broadcastReceiver, intentFilter); + bluetoothAdapter.startDiscovery(); + scanning = true; + } + } + + private void stopBLScan() { + if (scanning) { + unregisterReceiver(broadcastReceiver); + BluetoothAdapter.getDefaultAdapter().cancelDiscovery(); + scanning = false; + } + } + @Override + public void onClick(View v) { + if (v == exit) finish(); + else if (v == yes) service.confirmVerificationString(); + else if (v == no) service.rejectVerificationString(); + } + + @Override + public void onExceptionOccur(Exception e) { + ExceptionTranslator.makeToast(this, e); + } + + private void deviceSelected(BluetoothDevice device) { + service.pair(device.getAddress()); + } + + private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) + BluetoothAdapter.getDefaultAdapter().startDiscovery(); + else if (action.equals(BluetoothDevice.ACTION_FOUND)) { + BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); + deviceAdapter.addDevice(bluetoothDevice); + } + } + }; + + private class DeviceAdapter extends RecyclerView.Adapter { + + private List bluetoothDevices = new ArrayList<>(); + + public void addDevice(BluetoothDevice bluetoothDevice) { + if (!bluetoothDevices.contains(bluetoothDevice)) { + bluetoothDevices.add(bluetoothDevice); + notifyDataSetChanged(); + } + } + + public void clear() { + bluetoothDevices.clear(); + notifyDataSetChanged(); + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.bluetooth_device, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + BluetoothDevice bluetoothDevice = bluetoothDevices.get(position); + holder.deviceName.setText(bluetoothDevice.getName() == null ? bluetoothDevice.getAddress() : bluetoothDevice.getName()); + holder.deviceName.setOnClickListener((v) -> deviceSelected(bluetoothDevice)); + } + + @Override + public int getItemCount() { + return bluetoothDevices.size(); + } + + public class ViewHolder extends RecyclerView.ViewHolder { + + private TextView deviceName; + + public ViewHolder(View itemView) { + super(itemView); + deviceName = (TextView) itemView; + } + } + + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightPairingInformationActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightPairingInformationActivity.java new file mode 100644 index 0000000000..8580b30dca --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightPairingInformationActivity.java @@ -0,0 +1,88 @@ +package info.nightscout.androidaps.plugins.pump.insight.activities; + +import android.content.ComponentName; +import android.content.Intent; +import android.content.ServiceConnection; +import android.os.Bundle; +import android.os.IBinder; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.TextView; + +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService; + +public class InsightPairingInformationActivity extends AppCompatActivity { + + private InsightConnectionService connectionService; + + private TextView serialNumber; + private TextView releaseSWVersion; + private TextView uiProcSWVersion; + private TextView pcProcSWVersion; + private TextView mdTelSWVersion; + private TextView safetyProcSWVersion; + private TextView btInfoPageVersion; + private TextView bluetoothAddress; + private TextView systemIdAppendix; + private TextView manufacturingDate; + + private ServiceConnection serviceConnection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder binder) { + connectionService = ((InsightConnectionService.LocalBinder) binder).getService(); + if (!connectionService.isPaired()) { + overridePendingTransition(0, 0); + finish(); + startActivity(new Intent(InsightPairingInformationActivity.this, InsightPairingActivity.class)); + } else { + serialNumber.setText(connectionService.getPumpSystemIdentification().getSerialNumber()); + manufacturingDate.setText(connectionService.getPumpSystemIdentification().getManufacturingDate()); + systemIdAppendix.setText(connectionService.getPumpSystemIdentification().getSystemIdAppendix() + ""); + releaseSWVersion.setText(connectionService.getPumpFirmwareVersions().getReleaseSWVersion()); + uiProcSWVersion.setText(connectionService.getPumpFirmwareVersions().getUiProcSWVersion()); + pcProcSWVersion.setText(connectionService.getPumpFirmwareVersions().getPcProcSWVersion()); + mdTelSWVersion.setText(connectionService.getPumpFirmwareVersions().getMdTelProcSWVersion()); + safetyProcSWVersion.setText(connectionService.getPumpFirmwareVersions().getSafetyProcSWVersion()); + btInfoPageVersion.setText(connectionService.getPumpFirmwareVersions().getBtInfoPageVersion()); + bluetoothAddress.setText(connectionService.getBluetoothAddress()); + } + } + + @Override + public void onServiceDisconnected(ComponentName name) { + connectionService = null; + } + }; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_insight_pairing_information); + serialNumber = findViewById(R.id.serial_number); + releaseSWVersion = findViewById(R.id.release_sw_version); + uiProcSWVersion = findViewById(R.id.ui_proc_sw_version); + pcProcSWVersion = findViewById(R.id.pc_proc_sw_version); + mdTelSWVersion = findViewById(R.id.md_tel_sw_version); + safetyProcSWVersion = findViewById(R.id.safety_proc_sw_version); + btInfoPageVersion = findViewById(R.id.bt_info_page_version); + bluetoothAddress = findViewById(R.id.bluetooth_address); + systemIdAppendix = findViewById(R.id.system_id_appendix); + manufacturingDate = findViewById(R.id.manufacturing_date); + bindService(new Intent(this, InsightConnectionService.class), serviceConnection, BIND_AUTO_CREATE); + } + + @Override + protected void onDestroy() { + unbindService(serviceConnection); + super.onDestroy(); + } + + public void deletePairing(View view) { + if (connectionService != null) { + connectionService.reset(); + finish(); + } + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/AppLayerMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/AppLayerMessage.java new file mode 100644 index 0000000000..7783abe063 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/AppLayerMessage.java @@ -0,0 +1,91 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.IncompatibleAppVersionException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.InvalidAppCRCException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.UnknownAppCommandException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.UnknownServiceException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.AppLayerErrorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.UnknownAppLayerErrorCodeException; +import info.nightscout.androidaps.plugins.pump.insight.ids.AppCommandIDs; +import info.nightscout.androidaps.plugins.pump.insight.ids.AppErrorIDs; +import info.nightscout.androidaps.plugins.pump.insight.ids.ServiceIDs; +import info.nightscout.androidaps.plugins.pump.insight.satl.DataMessage; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; +import info.nightscout.androidaps.plugins.pump.insight.utils.crypto.Cryptograph; + +public class AppLayerMessage implements Comparable { + + private static final byte VERSION = 0x20; + + private final MessagePriority messagePriority; + private final boolean inCRC; + private final boolean outCRC; + private final Service service; + + public AppLayerMessage(MessagePriority messagePriority, boolean inCRC, boolean outCRC, Service service) { + this.messagePriority = messagePriority; + this.inCRC = inCRC; + this.outCRC = outCRC; + this.service = service; + } + + protected ByteBuf getData() { + return new ByteBuf(0); + } + + protected void parse(ByteBuf byteBuf) throws Exception { + + } + + public ByteBuf serialize(Class clazz) { + byte[] data = getData().getBytes(); + ByteBuf byteBuf = new ByteBuf(4 + data.length + (outCRC ? 2 : 0)); + byteBuf.putByte(VERSION); + byteBuf.putByte(ServiceIDs.IDS.getID(getService())); + byteBuf.putUInt16LE(AppCommandIDs.IDS.getID(clazz)); + byteBuf.putBytes(data); + if (outCRC) byteBuf.putUInt16LE(Cryptograph.calculateCRC(data)); + return byteBuf; + } + + public static AppLayerMessage deserialize(ByteBuf byteBuf) throws Exception { + byte version = byteBuf.readByte(); + byte service = byteBuf.readByte(); + int command = byteBuf.readUInt16LE(); + int error = byteBuf.readUInt16LE(); + Class clazz = AppCommandIDs.IDS.getType(command); + if (clazz == null) throw new UnknownAppCommandException(); + if (version != VERSION) throw new IncompatibleAppVersionException(); + AppLayerMessage message = clazz.newInstance(); + if (ServiceIDs.IDS.getType(service) == null) throw new UnknownServiceException(); + if (error != 0) { + Class exceptionClass = AppErrorIDs.IDS.getType(error); + if (exceptionClass == null) throw new UnknownAppLayerErrorCodeException(error); + else throw exceptionClass.getConstructor(int.class).newInstance(error); + } + byte[] data = byteBuf.readBytes(byteBuf.getSize() - (message.inCRC ? 2 : 0)); + if (message.inCRC && Cryptograph.calculateCRC(data) != byteBuf.readUInt16LE()) throw new InvalidAppCRCException(); + message.parse(ByteBuf.from(data)); + return message; + } + + public static DataMessage wrap(AppLayerMessage message) { + DataMessage dataMessage = new DataMessage(); + dataMessage.setData(message.serialize(message.getClass())); + return dataMessage; + } + + public static AppLayerMessage unwrap(DataMessage dataMessage) throws Exception { + return deserialize(dataMessage.getData()); + } + + @Override + public int compareTo(AppLayerMessage o) { + return messagePriority.compareTo(o.messagePriority); + } + + public Service getService() { + return this.service; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/ReadParameterBlockMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/ReadParameterBlockMessage.java new file mode 100644 index 0000000000..221cf80462 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/ReadParameterBlockMessage.java @@ -0,0 +1,48 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.ParameterBlock; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.ids.ParameterBlockIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class ReadParameterBlockMessage extends AppLayerMessage { + + private Class parameterBlockId; + private ParameterBlock parameterBlock; + private Service service; + + public ReadParameterBlockMessage() { + super(MessagePriority.NORMAL, true, false, null); + } + + @Override + public Service getService() { + return service; + } + + public void setService(Service service) { + this.service = service; + } + + @Override + protected ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(2); + byteBuf.putUInt16LE(ParameterBlockIDs.IDS.getID(parameterBlockId)); + return byteBuf; + } + + @Override + protected void parse(ByteBuf byteBuf) throws Exception { + parameterBlock = ParameterBlockIDs.IDS.getType(byteBuf.readUInt16LE()).newInstance(); + byteBuf.shift(2); //Restriction level + parameterBlock.parse(byteBuf); + } + + public ParameterBlock getParameterBlock() { + return this.parameterBlock; + } + + public void setParameterBlockId(Class configurationBlockId) { + this.parameterBlockId = configurationBlockId; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/Service.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/Service.java new file mode 100644 index 0000000000..aeec3150d3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/Service.java @@ -0,0 +1,31 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer; + +public enum Service { + + CONNECTION((short) 0x0000, null), + STATUS((short) 0x0100, null), + HISTORY((short) 0x0200, null), + CONFIGURATION((short) 0x0200, "u+5Fhz6Gw4j1Kkas"), + PARAMETER((short) 0x0200, null), + REMOTE_CONTROL((short) 0x0100, "MAbcV2X6PVjxuz+R"); + + private short version; + private String servicePassword; + + Service(short version, String servicePassword) { + this.version = version; + this.servicePassword = servicePassword; + } + + public short getVersion() { + return this.version; + } + + public String getServicePassword() { + return this.servicePassword; + } + + public void setServicePassword(String servicePassword) { + this.servicePassword = servicePassword; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/CloseConfigurationWriteSessionMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/CloseConfigurationWriteSessionMessage.java new file mode 100644 index 0000000000..2e6133b79e --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/CloseConfigurationWriteSessionMessage.java @@ -0,0 +1,12 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; + +public class CloseConfigurationWriteSessionMessage extends AppLayerMessage { + + public CloseConfigurationWriteSessionMessage() { + super(MessagePriority.NORMAL, false, false, Service.CONFIGURATION); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/OpenConfigurationWriteSessionMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/OpenConfigurationWriteSessionMessage.java new file mode 100644 index 0000000000..0706742559 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/OpenConfigurationWriteSessionMessage.java @@ -0,0 +1,12 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; + +public class OpenConfigurationWriteSessionMessage extends AppLayerMessage { + + public OpenConfigurationWriteSessionMessage() { + super(MessagePriority.NORMAL, false, false, Service.CONFIGURATION); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/WriteConfigurationBlockMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/WriteConfigurationBlockMessage.java new file mode 100644 index 0000000000..a33530d48e --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/WriteConfigurationBlockMessage.java @@ -0,0 +1,41 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.ParameterBlock; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.ids.ParameterBlockIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class WriteConfigurationBlockMessage extends AppLayerMessage { + + private ParameterBlock parameterBlock; + private Class configurationBlockId; + + public WriteConfigurationBlockMessage() { + super(MessagePriority.NORMAL, false, true, Service.CONFIGURATION); + } + + @Override + protected ByteBuf getData() { + ByteBuf configBlockData = parameterBlock.getData(); + ByteBuf data = new ByteBuf(4 + configBlockData.getSize()); + data.putUInt16LE(ParameterBlockIDs.IDS.getID(parameterBlock.getClass())); + data.putUInt16LE(31); + data.putByteBuf(configBlockData); + return data; + } + + @Override + protected void parse(ByteBuf byteBuf) throws Exception { + configurationBlockId = ParameterBlockIDs.IDS.getType(byteBuf.readUInt16LE()); + } + + public Class getConfigurationBlockId() { + return this.configurationBlockId; + } + + public void setParameterBlock(ParameterBlock parameterBlock) { + this.parameterBlock = parameterBlock; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ActivateServiceMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ActivateServiceMessage.java new file mode 100644 index 0000000000..322864bffe --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ActivateServiceMessage.java @@ -0,0 +1,51 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.connection; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class ActivateServiceMessage extends AppLayerMessage { + + private byte serviceID; + private short version; + private byte[] servicePassword; + + public ActivateServiceMessage() { + super(MessagePriority.NORMAL, false, false, Service.CONNECTION); + } + + protected void parse(ByteBuf byteBuf) { + serviceID = byteBuf.readByte(); + version = byteBuf.readShort(); + } + + @Override + protected ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(19); + byteBuf.putByte(serviceID); + byteBuf.putShort(version); + byteBuf.putBytes(servicePassword); + return byteBuf; + } + + public byte getServiceID() { + return this.serviceID; + } + + public short getVersion() { + return this.version; + } + + public void setServiceID(byte serviceID) { + this.serviceID = serviceID; + } + + public void setVersion(short version) { + this.version = version; + } + + public void setServicePassword(byte[] servicePassword) { + this.servicePassword = servicePassword; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/BindMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/BindMessage.java new file mode 100644 index 0000000000..b636797464 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/BindMessage.java @@ -0,0 +1,20 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.connection; + +import org.spongycastle.util.encoders.Hex; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class BindMessage extends AppLayerMessage { + + public BindMessage() { + super(MessagePriority.NORMAL, false, false, Service.CONNECTION); + } + + @Override + protected ByteBuf getData() { + return ByteBuf.from(Hex.decode("3438310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ConnectMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ConnectMessage.java new file mode 100644 index 0000000000..c56864209c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ConnectMessage.java @@ -0,0 +1,20 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.connection; + +import org.spongycastle.util.encoders.Hex; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class ConnectMessage extends AppLayerMessage { + + public ConnectMessage() { + super(MessagePriority.NORMAL, false, false, Service.CONNECTION); + } + + @Override + protected ByteBuf getData() { + return ByteBuf.from(Hex.decode("0000080100196000")); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/DisconnectMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/DisconnectMessage.java new file mode 100644 index 0000000000..22ddbc7608 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/DisconnectMessage.java @@ -0,0 +1,20 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.connection; + +import org.spongycastle.util.encoders.Hex; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class DisconnectMessage extends AppLayerMessage { + + public DisconnectMessage() { + super(MessagePriority.NORMAL, false, false, Service.CONNECTION); + } + + @Override + protected ByteBuf getData() { + return ByteBuf.from(Hex.decode("0360")); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ServiceChallengeMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ServiceChallengeMessage.java new file mode 100644 index 0000000000..07be4dd469 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ServiceChallengeMessage.java @@ -0,0 +1,42 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.connection; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class ServiceChallengeMessage extends AppLayerMessage { + + private byte serviceID; + private byte[] randomData; + private short version; + + public ServiceChallengeMessage() { + super(MessagePriority.NORMAL, false, false, Service.CONNECTION); + } + + @Override + protected void parse(ByteBuf byteBuf) { + randomData = byteBuf.getBytes(16); + } + + @Override + protected ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(3); + byteBuf.putByte(serviceID); + byteBuf.putShort(version); + return byteBuf; + } + + public byte[] getRandomData() { + return this.randomData; + } + + public void setServiceID(byte serviceID) { + this.serviceID = serviceID; + } + + public void setVersion(short version) { + this.version = version; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/HistoryReadingDirection.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/HistoryReadingDirection.java new file mode 100644 index 0000000000..327304eb21 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/HistoryReadingDirection.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history; + +public enum HistoryReadingDirection { + + FORWARD, + BACKWARD; + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/ReadHistoryEventsMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/ReadHistoryEventsMessage.java new file mode 100644 index 0000000000..f4c8cb4557 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/ReadHistoryEventsMessage.java @@ -0,0 +1,34 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history; + +import java.util.ArrayList; +import java.util.List; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.HistoryEvent; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class ReadHistoryEventsMessage extends AppLayerMessage { + + private List historyEvents; + + public ReadHistoryEventsMessage() { + super(MessagePriority.NORMAL, true, false, Service.HISTORY); + } + + @Override + protected void parse(ByteBuf byteBuf) throws Exception { + historyEvents = new ArrayList<>(); + byteBuf.shift(2); + int frameCount = byteBuf.readUInt16LE(); + for (int i = 0; i < frameCount; i++) { + int length = byteBuf.readUInt16LE(); + historyEvents.add(HistoryEvent.deserialize(ByteBuf.from(byteBuf.readBytes(length)))); + } + } + + public List getHistoryEvents() { + return historyEvents; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/StartReadingHistoryMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/StartReadingHistoryMessage.java new file mode 100644 index 0000000000..9b8c2c6b16 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/StartReadingHistoryMessage.java @@ -0,0 +1,34 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.ids.HistoryReadingDirectionIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class StartReadingHistoryMessage extends AppLayerMessage { + + private long offset; + private HistoryReadingDirection direction; + + public StartReadingHistoryMessage() { + super(MessagePriority.NORMAL, false, true, Service.HISTORY); + } + + @Override + protected ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(8); + byteBuf.putUInt16LE(31); + byteBuf.putUInt16LE(HistoryReadingDirectionIDs.IDS.getID(direction)); + byteBuf.putUInt32LE(offset); + return byteBuf; + } + + public void setOffset(long offset) { + this.offset = offset; + } + + public void setDirection(HistoryReadingDirection direction) { + this.direction = direction; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/StopReadingHistoryMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/StopReadingHistoryMessage.java new file mode 100644 index 0000000000..56749fcffe --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/StopReadingHistoryMessage.java @@ -0,0 +1,12 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; + +public class StopReadingHistoryMessage extends AppLayerMessage { + + public StopReadingHistoryMessage() { + super(MessagePriority.NORMAL, false, false, Service.HISTORY); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BasalDeliveryChangedEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BasalDeliveryChangedEvent.java new file mode 100644 index 0000000000..1eb62c6c42 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BasalDeliveryChangedEvent.java @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class BasalDeliveryChangedEvent extends HistoryEvent { + + private double oldBasalRate; + private double newBasalRate; + + @Override + public void parse(ByteBuf byteBuf) { + oldBasalRate = byteBuf.readUInt32Decimal1000(); + newBasalRate = byteBuf.readUInt32Decimal1000(); + } + + public double getOldBasalRate() { + return oldBasalRate; + } + + public double getNewBasalRate() { + return newBasalRate; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BolusDeliveredEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BolusDeliveredEvent.java new file mode 100644 index 0000000000..05ba09ccf3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BolusDeliveredEvent.java @@ -0,0 +1,64 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.BolusType; +import info.nightscout.androidaps.plugins.pump.insight.ids.BolusTypeIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.BOCUtil; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class BolusDeliveredEvent extends HistoryEvent { + + private BolusType bolusType; + private int startHour; + private int startMinute; + private int startSecond; + private double immediateAmount; + private double extendedAmount; + private int duration; + private int bolusID; + + @Override + public void parse(ByteBuf byteBuf) { + bolusType = BolusTypeIDs.IDS.getType(byteBuf.readUInt16LE()); + byteBuf.shift(1); + startHour = BOCUtil.parseBOC(byteBuf.readByte()); + startMinute = BOCUtil.parseBOC(byteBuf.readByte()); + startSecond = BOCUtil.parseBOC(byteBuf.readByte()); + immediateAmount = byteBuf.readUInt16Decimal(); + extendedAmount = byteBuf.readUInt16Decimal(); + duration = byteBuf.readUInt16LE(); + byteBuf.shift(2); + bolusID = byteBuf.readUInt16LE(); + } + + public BolusType getBolusType() { + return bolusType; + } + + public int getStartHour() { + return startHour; + } + + public int getStartMinute() { + return startMinute; + } + + public int getStartSecond() { + return startSecond; + } + + public double getImmediateAmount() { + return immediateAmount; + } + + public double getExtendedAmount() { + return extendedAmount; + } + + public int getDuration() { + return duration; + } + + public int getBolusID() { + return bolusID; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BolusProgrammedEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BolusProgrammedEvent.java new file mode 100644 index 0000000000..0a456406d0 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BolusProgrammedEvent.java @@ -0,0 +1,45 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.BolusType; +import info.nightscout.androidaps.plugins.pump.insight.ids.BolusTypeIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class BolusProgrammedEvent extends HistoryEvent { + + private BolusType bolusType; + private double immediateAmount; + private double extendedAmount; + private int duration; + private int bolusID; + + @Override + public void parse(ByteBuf byteBuf) { + bolusType = BolusTypeIDs.IDS.getType(byteBuf.readUInt16LE()); + immediateAmount = byteBuf.readUInt16Decimal(); + extendedAmount = byteBuf.readUInt16Decimal(); + duration = byteBuf.readUInt16LE(); + byteBuf.shift(4); + bolusID = byteBuf.readUInt16LE(); + } + + + public BolusType getBolusType() { + return bolusType; + } + + public double getImmediateAmount() { + return immediateAmount; + } + + public double getExtendedAmount() { + return extendedAmount; + } + + public int getDuration() { + return duration; + } + + public int getBolusID() { + return bolusID; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CannulaFilledEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CannulaFilledEvent.java new file mode 100644 index 0000000000..4ee16e35e1 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CannulaFilledEvent.java @@ -0,0 +1,17 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class CannulaFilledEvent extends HistoryEvent { + + private double amount; + + @Override + public void parse(ByteBuf byteBuf) { + amount = byteBuf.readUInt16Decimal(); + } + + public double getAmount() { + return amount; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CartridgeInsertedEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CartridgeInsertedEvent.java new file mode 100644 index 0000000000..94ebcc442e --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CartridgeInsertedEvent.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +public class CartridgeInsertedEvent extends HistoryEvent { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CartridgeRemovedEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CartridgeRemovedEvent.java new file mode 100644 index 0000000000..f65d85b06e --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CartridgeRemovedEvent.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +public class CartridgeRemovedEvent extends HistoryEvent { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/DateTimeChangedEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/DateTimeChangedEvent.java new file mode 100644 index 0000000000..1397bb2529 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/DateTimeChangedEvent.java @@ -0,0 +1,49 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +import info.nightscout.androidaps.plugins.pump.insight.utils.BOCUtil; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class DateTimeChangedEvent extends HistoryEvent { + + private int beforeYear; + private int beforeMonth; + private int beforeDay; + private int beforeHour; + private int beforeMinute; + private int beforeSecond; + + @Override + public void parse(ByteBuf byteBuf) { + beforeYear = BOCUtil.parseBOC(byteBuf.readByte()) * 100 + BOCUtil.parseBOC(byteBuf.readByte()); + beforeMonth = BOCUtil.parseBOC(byteBuf.readByte()); + beforeDay = BOCUtil.parseBOC(byteBuf.readByte()); + byteBuf.shift(1); + beforeHour = BOCUtil.parseBOC(byteBuf.readByte()); + beforeMinute = BOCUtil.parseBOC(byteBuf.readByte()); + beforeSecond = BOCUtil.parseBOC(byteBuf.readByte()); + } + + public int getBeforeYear() { + return beforeYear; + } + + public int getBeforeMonth() { + return beforeMonth; + } + + public int getBeforeDay() { + return beforeDay; + } + + public int getBeforeHour() { + return beforeHour; + } + + public int getBeforeMinute() { + return beforeMinute; + } + + public int getBeforeSecond() { + return beforeSecond; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/DefaultDateTimeSetEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/DefaultDateTimeSetEvent.java new file mode 100644 index 0000000000..b3b468f09a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/DefaultDateTimeSetEvent.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +public class DefaultDateTimeSetEvent extends HistoryEvent { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/EndOfTBREvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/EndOfTBREvent.java new file mode 100644 index 0000000000..2edbec2dd4 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/EndOfTBREvent.java @@ -0,0 +1,43 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +import info.nightscout.androidaps.plugins.pump.insight.utils.BOCUtil; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class EndOfTBREvent extends HistoryEvent { + + private int startHour; + private int startMinute; + private int startSecond; + private int amount; + private int duration; + + @Override + public void parse(ByteBuf byteBuf) { + byteBuf.shift(1); + startHour = BOCUtil.parseBOC(byteBuf.readByte()); + startMinute = BOCUtil.parseBOC(byteBuf.readByte()); + startSecond = BOCUtil.parseBOC(byteBuf.readByte()); + amount = byteBuf.readUInt16LE(); + duration = byteBuf.readUInt16LE(); + } + + public int getStartHour() { + return startHour; + } + + public int getStartMinute() { + return startMinute; + } + + public int getStartSecond() { + return startSecond; + } + + public int getAmount() { + return amount; + } + + public int getDuration() { + return duration; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/HistoryEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/HistoryEvent.java new file mode 100644 index 0000000000..874c908ca5 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/HistoryEvent.java @@ -0,0 +1,83 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +import info.nightscout.androidaps.plugins.pump.insight.ids.HistoryEventIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.BOCUtil; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class HistoryEvent implements Comparable { + + private int eventYear; + private int eventMonth; + private int eventDay; + private int eventHour; + private int eventMinute; + private int eventSecond; + private long eventPosition; + + public static HistoryEvent deserialize(ByteBuf byteBuf) { + int eventID = byteBuf.readUInt16LE(); + Class eventClass = HistoryEventIDs.IDS.getType(eventID); + HistoryEvent event = null; + if (eventClass == null) event = new HistoryEvent(); + else { + try { + event = eventClass.newInstance(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } + } + event.parseHeader(byteBuf); + event.parse(byteBuf); + return event; + } + + public final void parseHeader(ByteBuf byteBuf) { + eventYear = BOCUtil.parseBOC(byteBuf.readByte()) * 100 + BOCUtil.parseBOC(byteBuf.readByte()); + eventMonth = BOCUtil.parseBOC(byteBuf.readByte()); + eventDay = BOCUtil.parseBOC(byteBuf.readByte()); + byteBuf.shift(1); + eventHour = BOCUtil.parseBOC(byteBuf.readByte()); + eventMinute = BOCUtil.parseBOC(byteBuf.readByte()); + eventSecond = BOCUtil.parseBOC(byteBuf.readByte()); + eventPosition = byteBuf.readUInt32LE(); + } + + public void parse(ByteBuf byteBuf) { + + } + + public int getEventYear() { + return eventYear; + } + + public int getEventMonth() { + return eventMonth; + } + + public int getEventDay() { + return eventDay; + } + + public int getEventHour() { + return eventHour; + } + + public int getEventMinute() { + return eventMinute; + } + + public int getEventSecond() { + return eventSecond; + } + + public long getEventPosition() { + return eventPosition; + } + + @Override + public int compareTo(HistoryEvent historyEvent) { + return (int) (eventPosition - historyEvent.eventPosition); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfAlertEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfAlertEvent.java new file mode 100644 index 0000000000..e6edc8c95c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfAlertEvent.java @@ -0,0 +1,25 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertType; +import info.nightscout.androidaps.plugins.pump.insight.ids.AlertTypeIncrementalIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public abstract class OccurrenceOfAlertEvent extends HistoryEvent { + + private AlertType alertType; + private int alertID; + + @Override + public void parse(ByteBuf byteBuf) { + alertType = AlertTypeIncrementalIDs.IDS.getType(byteBuf.readUInt16LE()); + alertID = byteBuf.readUInt16LE(); + } + + public AlertType getAlertType() { + return alertType; + } + + public int getAlertID() { + return alertID; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfErrorEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfErrorEvent.java new file mode 100644 index 0000000000..7d6c61e9c2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfErrorEvent.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +public class OccurrenceOfErrorEvent extends OccurrenceOfAlertEvent { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfMaintenanceEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfMaintenanceEvent.java new file mode 100644 index 0000000000..6884797250 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfMaintenanceEvent.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +public class OccurrenceOfMaintenanceEvent extends OccurrenceOfAlertEvent { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfWarningEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfWarningEvent.java new file mode 100644 index 0000000000..b504e4e09a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfWarningEvent.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +public class OccurrenceOfWarningEvent extends OccurrenceOfAlertEvent { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OperatingModeChangedEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OperatingModeChangedEvent.java new file mode 100644 index 0000000000..067b46e51f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OperatingModeChangedEvent.java @@ -0,0 +1,26 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.OperatingMode; +import info.nightscout.androidaps.plugins.pump.insight.ids.OperatingModeIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class OperatingModeChangedEvent extends HistoryEvent { + + private OperatingMode oldValue; + private OperatingMode newValue; + + @Override + public void parse(ByteBuf byteBuf) { + oldValue = OperatingModeIDs.IDS.getType(byteBuf.readUInt16LE()); + newValue = OperatingModeIDs.IDS.getType(byteBuf.readUInt16LE()); + } + + + public OperatingMode getOldValue() { + return oldValue; + } + + public OperatingMode getNewValue() { + return newValue; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/PowerDownEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/PowerDownEvent.java new file mode 100644 index 0000000000..ff73ce0383 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/PowerDownEvent.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +public class PowerDownEvent extends HistoryEvent { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/PowerUpEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/PowerUpEvent.java new file mode 100644 index 0000000000..d31690e9e9 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/PowerUpEvent.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +public class PowerUpEvent extends HistoryEvent { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/SniffingDoneEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/SniffingDoneEvent.java new file mode 100644 index 0000000000..4afe3c72ba --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/SniffingDoneEvent.java @@ -0,0 +1,18 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + + +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class SniffingDoneEvent extends HistoryEvent { + + private double amount; + + @Override + public void parse(ByteBuf byteBuf) { + amount = byteBuf.readUInt16Decimal(); + } + + public double getAmount() { + return amount; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/StartOfTBREvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/StartOfTBREvent.java new file mode 100644 index 0000000000..99795ed12c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/StartOfTBREvent.java @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class StartOfTBREvent extends HistoryEvent { + + private int amount; + private int duration; + + @Override + public void parse(ByteBuf byteBuf) { + amount = byteBuf.readUInt16LE(); + duration = byteBuf.readUInt16LE(); + } + + public int getAmount() { + return amount; + } + + public int getDuration() { + return duration; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/TotalDailyDoseEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/TotalDailyDoseEvent.java new file mode 100644 index 0000000000..c7f52ce1ef --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/TotalDailyDoseEvent.java @@ -0,0 +1,42 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +import info.nightscout.androidaps.plugins.pump.insight.utils.BOCUtil; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class TotalDailyDoseEvent extends HistoryEvent { + + private double basalTotal; + private double bolusTotal; + private int totalYear; + private int totalMonth; + private int totalDay; + + @Override + public void parse(ByteBuf byteBuf) { + basalTotal = byteBuf.readUInt32Decimal100(); + bolusTotal = byteBuf.readUInt32Decimal100(); + totalYear = BOCUtil.parseBOC(byteBuf.readByte()) * 100 + BOCUtil.parseBOC(byteBuf.readByte()); + totalMonth = BOCUtil.parseBOC(byteBuf.readByte()); + totalDay = BOCUtil.parseBOC(byteBuf.readByte()); + } + + public double getBasalTotal() { + return basalTotal; + } + + public double getBolusTotal() { + return bolusTotal; + } + + public int getTotalYear() { + return totalYear; + } + + public int getTotalMonth() { + return totalMonth; + } + + public int getTotalDay() { + return totalDay; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/TubeFilledEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/TubeFilledEvent.java new file mode 100644 index 0000000000..58a1851936 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/TubeFilledEvent.java @@ -0,0 +1,17 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events; + +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class TubeFilledEvent extends HistoryEvent { + + private double amount; + + @Override + public void parse(ByteBuf byteBuf) { + amount = byteBuf.readUInt16Decimal(); + } + + public double getAmount() { + return amount; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/ActiveBRProfileBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/ActiveBRProfileBlock.java new file mode 100644 index 0000000000..1d5630ea94 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/ActiveBRProfileBlock.java @@ -0,0 +1,30 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.BasalProfile; +import info.nightscout.androidaps.plugins.pump.insight.ids.ActiveBasalProfileIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class ActiveBRProfileBlock extends ParameterBlock { + + private BasalProfile activeBasalProfile; + + @Override + public void parse(ByteBuf byteBuf) { + activeBasalProfile = ActiveBasalProfileIDs.IDS.getType(byteBuf.readUInt16LE()); + } + + @Override + public ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(2); + byteBuf.putUInt16LE(ActiveBasalProfileIDs.IDS.getID(activeBasalProfile)); + return byteBuf; + } + + public BasalProfile getActiveBasalProfile() { + return activeBasalProfile; + } + + public void setActiveBasalProfile(BasalProfile activeBasalProfile) { + this.activeBasalProfile = activeBasalProfile; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile1Block.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile1Block.java new file mode 100644 index 0000000000..5f6be32181 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile1Block.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class BRProfile1Block extends BRProfileBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile1NameBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile1NameBlock.java new file mode 100644 index 0000000000..1135eac5ac --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile1NameBlock.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class BRProfile1NameBlock extends NameBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile2Block.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile2Block.java new file mode 100644 index 0000000000..0b961458f2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile2Block.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class BRProfile2Block extends BRProfileBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile2NameBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile2NameBlock.java new file mode 100644 index 0000000000..591dd4d08c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile2NameBlock.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class BRProfile2NameBlock extends NameBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile3Block.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile3Block.java new file mode 100644 index 0000000000..31e0ac0409 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile3Block.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class BRProfile3Block extends BRProfileBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile3NameBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile3NameBlock.java new file mode 100644 index 0000000000..390e3be0dc --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile3NameBlock.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class BRProfile3NameBlock extends NameBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile4Block.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile4Block.java new file mode 100644 index 0000000000..06eaeb943c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile4Block.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class BRProfile4Block extends BRProfileBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile4NameBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile4NameBlock.java new file mode 100644 index 0000000000..5e2a5eb811 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile4NameBlock.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class BRProfile4NameBlock extends NameBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile5Block.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile5Block.java new file mode 100644 index 0000000000..738ea270f1 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile5Block.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class BRProfile5Block extends BRProfileBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile5NameBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile5NameBlock.java new file mode 100644 index 0000000000..1ff159aeb2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile5NameBlock.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class BRProfile5NameBlock extends NameBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfileBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfileBlock.java new file mode 100644 index 0000000000..c6b4a515a1 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfileBlock.java @@ -0,0 +1,50 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.BasalProfileBlock; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public abstract class BRProfileBlock extends ParameterBlock { + + private List profileBlocks; + + @Override + public void parse(ByteBuf byteBuf) { + profileBlocks = new ArrayList<>(); + for (int i = 0; i < 24; i++) { + BasalProfileBlock basalProfileBlock = new BasalProfileBlock(); + basalProfileBlock.setDuration(byteBuf.readUInt16LE()); + profileBlocks.add(basalProfileBlock); + } + for (int i = 0; i < 24; i++) profileBlocks.get(i).setBasalAmount(byteBuf.readUInt16Decimal()); + Iterator iterator = profileBlocks.iterator(); + while (iterator.hasNext()) + if (iterator.next().getDuration() == 0) + iterator.remove(); + } + + @Override + public ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(96); + for (int i = 0; i < 24; i++) { + if (profileBlocks.size() > i) byteBuf.putUInt16LE(profileBlocks.get(i).getDuration()); + else byteBuf.putUInt16LE(0); + } + for (int i = 0; i < 24; i++) { + if (profileBlocks.size() > i) byteBuf.putUInt16Decimal(profileBlocks.get(i).getBasalAmount()); + else byteBuf.putUInt16Decimal(0); + } + return byteBuf; + } + + public List getProfileBlocks() { + return profileBlocks; + } + + public void setProfileBlocks(List profileBlocks) { + this.profileBlocks = profileBlocks; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMaxBasalAmountBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMaxBasalAmountBlock.java new file mode 100644 index 0000000000..9db116edaf --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMaxBasalAmountBlock.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class FactoryMaxBasalAmountBlock extends InsulinAmountLimitationBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMaxBolusAmountBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMaxBolusAmountBlock.java new file mode 100644 index 0000000000..9df9cf4dff --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMaxBolusAmountBlock.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class FactoryMaxBolusAmountBlock extends InsulinAmountLimitationBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMinBasalAmountBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMinBasalAmountBlock.java new file mode 100644 index 0000000000..70cd39c07b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMinBasalAmountBlock.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class FactoryMinBasalAmountBlock extends InsulinAmountLimitationBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMinBolusAmountBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMinBolusAmountBlock.java new file mode 100644 index 0000000000..46ae394834 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMinBolusAmountBlock.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class FactoryMinBolusAmountBlock extends InsulinAmountLimitationBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/InsulinAmountLimitationBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/InsulinAmountLimitationBlock.java new file mode 100644 index 0000000000..a753a62567 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/InsulinAmountLimitationBlock.java @@ -0,0 +1,28 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public abstract class InsulinAmountLimitationBlock extends ParameterBlock { + + private double amountLimitation; + + @Override + public void parse(ByteBuf byteBuf) { + amountLimitation = byteBuf.readUInt16Decimal(); + } + + @Override + public ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(2); + byteBuf.putUInt16Decimal(amountLimitation); + return byteBuf; + } + + public double getAmountLimitation() { + return this.amountLimitation; + } + + public void setAmountLimitation(double amountLimitation) { + this.amountLimitation = amountLimitation; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/MaxBasalAmountBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/MaxBasalAmountBlock.java new file mode 100644 index 0000000000..d09b4681c0 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/MaxBasalAmountBlock.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class MaxBasalAmountBlock extends InsulinAmountLimitationBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/MaxBolusAmountBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/MaxBolusAmountBlock.java new file mode 100644 index 0000000000..d53fe5e742 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/MaxBolusAmountBlock.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +public class MaxBolusAmountBlock extends InsulinAmountLimitationBlock { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/NameBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/NameBlock.java new file mode 100644 index 0000000000..d4cf2060cb --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/NameBlock.java @@ -0,0 +1,28 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public abstract class NameBlock extends ParameterBlock { + + private String name; + + @Override + public void parse(ByteBuf byteBuf) { + name = byteBuf.readUTF16(40); + } + + @Override + public ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(42); + byteBuf.putUTF16(name, 40); + return byteBuf; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/ParameterBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/ParameterBlock.java new file mode 100644 index 0000000000..6ed2ca15c1 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/ParameterBlock.java @@ -0,0 +1,10 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public abstract class ParameterBlock { + + public abstract void parse(ByteBuf byteBuf); + public abstract ByteBuf getData(); + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/SystemIdentificationBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/SystemIdentificationBlock.java new file mode 100644 index 0000000000..e4e5d10c70 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/SystemIdentificationBlock.java @@ -0,0 +1,26 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.SystemIdentification; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class SystemIdentificationBlock extends ParameterBlock { + + private SystemIdentification systemIdentification; + + @Override + public void parse(ByteBuf byteBuf) { + systemIdentification = new SystemIdentification(); + systemIdentification.setSerialNumber(byteBuf.readUTF16(18)); + systemIdentification.setSystemIdAppendix(byteBuf.readUInt32LE()); + systemIdentification.setManufacturingDate(byteBuf.readUTF16(22)); + } + + @Override + public ByteBuf getData() { + return null; + } + + public SystemIdentification getSystemIdentification() { + return systemIdentification; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/TBROverNotificationBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/TBROverNotificationBlock.java new file mode 100644 index 0000000000..aec41ded44 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/TBROverNotificationBlock.java @@ -0,0 +1,31 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks; + +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class TBROverNotificationBlock extends ParameterBlock { + + private boolean enabled; + private int melody; + + @Override + public void parse(ByteBuf byteBuf) { + enabled = byteBuf.readBoolean(); + melody = byteBuf.readUInt16LE(); + } + + @Override + public ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(4); + byteBuf.putBoolean(enabled); + byteBuf.putUInt16LE(melody); + return byteBuf; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/CancelBolusMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/CancelBolusMessage.java new file mode 100644 index 0000000000..559d5dfcbd --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/CancelBolusMessage.java @@ -0,0 +1,26 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class CancelBolusMessage extends AppLayerMessage { + + private int bolusID; + + public CancelBolusMessage() { + super(MessagePriority.HIGHEST, false, true, Service.REMOTE_CONTROL); + } + + @Override + protected ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(2); + byteBuf.putUInt16LE(bolusID); + return byteBuf; + } + + public void setBolusID(int bolusID) { + this.bolusID = bolusID; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/CancelTBRMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/CancelTBRMessage.java new file mode 100644 index 0000000000..09b1762d2f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/CancelTBRMessage.java @@ -0,0 +1,11 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; + +public class CancelTBRMessage extends AppLayerMessage { + public CancelTBRMessage() { + super(MessagePriority.HIGHER, false, false, Service.REMOTE_CONTROL); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/ChangeTBRMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/ChangeTBRMessage.java new file mode 100644 index 0000000000..f9ea0b9d2f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/ChangeTBRMessage.java @@ -0,0 +1,33 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class ChangeTBRMessage extends AppLayerMessage { + + private int percentage; + private int duration; + + public ChangeTBRMessage() { + super(MessagePriority.NORMAL, false, true, Service.REMOTE_CONTROL); + } + + @Override + protected ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(6); + byteBuf.putUInt16LE(percentage); + byteBuf.putUInt16LE(duration); + byteBuf.putUInt16LE(31); + return byteBuf; + } + + public void setPercentage(int percentage) { + this.percentage = percentage; + } + + public void setDuration(int duration) { + this.duration = duration; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/ConfirmAlertMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/ConfirmAlertMessage.java new file mode 100644 index 0000000000..1d8e905c1c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/ConfirmAlertMessage.java @@ -0,0 +1,26 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class ConfirmAlertMessage extends AppLayerMessage { + + private int alertID; + + public ConfirmAlertMessage() { + super(MessagePriority.NORMAL, false, true, Service.REMOTE_CONTROL); + } + + @Override + protected ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(2); + byteBuf.putUInt16LE(alertID); + return byteBuf; + } + + public void setAlertID(int alertID) { + this.alertID = alertID; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java new file mode 100644 index 0000000000..f1b4c3f6de --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java @@ -0,0 +1,63 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.BolusType; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.ids.BolusTypeIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class DeliverBolusMessage extends AppLayerMessage { + + private BolusType bolusType; + private double immediateAmount; + private double extendedAmount; + private int duration; + private int bolusId; + + public DeliverBolusMessage() { + super(MessagePriority.NORMAL, true, true, Service.REMOTE_CONTROL); + } + + @Override + protected ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(22); + byteBuf.putUInt16LE(805); + byteBuf.putUInt16LE(BolusTypeIDs.IDS.getID(bolusType)); + byteBuf.putUInt16LE(31); + byteBuf.putUInt16LE(0); + byteBuf.putUInt16Decimal(immediateAmount); + byteBuf.putUInt16Decimal(extendedAmount); + byteBuf.putUInt16LE(duration); + byteBuf.putUInt16LE(0); + byteBuf.putUInt16Decimal(immediateAmount); + byteBuf.putUInt16Decimal(extendedAmount); + byteBuf.putUInt16LE(duration); + return byteBuf; + } + + @Override + protected void parse(ByteBuf byteBuf) throws Exception { + bolusId = byteBuf.readUInt16LE(); + } + + public void setBolusType(BolusType bolusType) { + this.bolusType = bolusType; + } + + public void setImmediateAmount(double immediateAmount) { + this.immediateAmount = immediateAmount; + } + + public void setExtendedAmount(double extendedAmount) { + this.extendedAmount = extendedAmount; + } + + public void setDuration(int duration) { + this.duration = duration; + } + + public int getBolusId() { + return bolusId; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/GetAvailableBolusTypesMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/GetAvailableBolusTypesMessage.java new file mode 100644 index 0000000000..965d0bd3fd --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/GetAvailableBolusTypesMessage.java @@ -0,0 +1,28 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.AvailableBolusTypes; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class GetAvailableBolusTypesMessage extends AppLayerMessage { + + private AvailableBolusTypes availableBolusTypes; + + public GetAvailableBolusTypesMessage() { + super(MessagePriority.NORMAL, false, false, Service.REMOTE_CONTROL); + } + + @Override + protected void parse(ByteBuf byteBuf) throws Exception { + availableBolusTypes = new AvailableBolusTypes(); + availableBolusTypes.setStandardAvailable(byteBuf.readBoolean()); + availableBolusTypes.setExtendedAvailable(byteBuf.readBoolean()); + availableBolusTypes.setMultiwaveAvailable(byteBuf.readBoolean()); + } + + public AvailableBolusTypes getAvailableBolusTypes() { + return this.availableBolusTypes; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetDateTimeMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetDateTimeMessage.java new file mode 100644 index 0000000000..5fe99f2bdf --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetDateTimeMessage.java @@ -0,0 +1,32 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.PumpTime; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class SetDateTimeMessage extends AppLayerMessage { + + private PumpTime pumpTime; + + public SetDateTimeMessage() { + super(MessagePriority.NORMAL, false, true, Service.CONFIGURATION); + } + + @Override + protected ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(7); + byteBuf.putUInt16LE(pumpTime.getYear()); + byteBuf.putUInt8((short) pumpTime.getMonth()); + byteBuf.putUInt8((short) pumpTime.getDay()); + byteBuf.putUInt8((short) pumpTime.getHour()); + byteBuf.putUInt8((short) pumpTime.getMinute()); + byteBuf.putUInt8((short) pumpTime.getSecond()); + return byteBuf; + } + + public void setPumpTime(PumpTime pumpTime) { + this.pumpTime = pumpTime; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetOperatingModeMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetOperatingModeMessage.java new file mode 100644 index 0000000000..41dff43ed4 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetOperatingModeMessage.java @@ -0,0 +1,28 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.OperatingMode; +import info.nightscout.androidaps.plugins.pump.insight.ids.OperatingModeIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class SetOperatingModeMessage extends AppLayerMessage { + + private OperatingMode operatingMode; + + public SetOperatingModeMessage() { + super(MessagePriority.HIGHEST, false, true, Service.REMOTE_CONTROL); + } + + @Override + protected ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(2); + byteBuf.putUInt16LE(OperatingModeIDs.IDS.getID(operatingMode)); + return byteBuf; + } + + public void setOperatingMode(OperatingMode operatingMode) { + this.operatingMode = operatingMode; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetTBRMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetTBRMessage.java new file mode 100644 index 0000000000..0bdff3295d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetTBRMessage.java @@ -0,0 +1,33 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class SetTBRMessage extends AppLayerMessage { + + private int percentage; + private int duration; + + public SetTBRMessage() { + super(MessagePriority.NORMAL, false, true, Service.REMOTE_CONTROL); + } + + @Override + protected ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(6); + byteBuf.putUInt16LE(percentage); + byteBuf.putUInt16LE(duration); + byteBuf.putUInt16LE(31); + return byteBuf; + } + + public void setPercentage(int percentage) { + this.percentage = percentage; + } + + public void setDuration(int duration) { + this.duration = duration; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SnoozeAlertMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SnoozeAlertMessage.java new file mode 100644 index 0000000000..139ea7e82b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SnoozeAlertMessage.java @@ -0,0 +1,26 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class SnoozeAlertMessage extends AppLayerMessage { + + private int alertID; + + public SnoozeAlertMessage() { + super(MessagePriority.NORMAL, false, true, Service.REMOTE_CONTROL); + } + + @Override + protected ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(2); + byteBuf.putUInt16LE(alertID); + return byteBuf; + } + + public void setAlertID(int alertID) { + this.alertID = alertID; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveAlertMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveAlertMessage.java new file mode 100644 index 0000000000..899ba182e8 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveAlertMessage.java @@ -0,0 +1,54 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.status; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.Alert; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.ids.AlertCategoryIDs; +import info.nightscout.androidaps.plugins.pump.insight.ids.AlertStatusIDs; +import info.nightscout.androidaps.plugins.pump.insight.ids.AlertTypeIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class GetActiveAlertMessage extends AppLayerMessage { + + private Alert alert; + + public GetActiveAlertMessage() { + super(MessagePriority.NORMAL, true, false, Service.STATUS); + } + + @Override + protected void parse(ByteBuf byteBuf) { + Alert alert = new Alert(); + alert.setAlertId(byteBuf.readUInt16LE()); + alert.setAlertCategory(AlertCategoryIDs.IDS.getType(byteBuf.readUInt16LE())); + alert.setAlertType(AlertTypeIDs.IDS.getType(byteBuf.readUInt16LE())); + alert.setAlertStatus(AlertStatusIDs.IDS.getType(byteBuf.readUInt16LE())); + if (alert.getAlertType() != null) { + switch (alert.getAlertType()) { + case WARNING_38: + byteBuf.shift(4); + alert.setProgrammedBolusAmount(byteBuf.readUInt16Decimal()); + alert.setDeliveredBolusAmount(byteBuf.readUInt16Decimal()); + break; + case REMINDER_07: + case WARNING_36: + byteBuf.shift(2); + alert.setTBRAmount(byteBuf.readUInt16LE()); + alert.setTBRDuration(byteBuf.readUInt16LE()); + break; + case WARNING_31: + alert.setCartridgeAmount(byteBuf.readUInt16Decimal()); + break; + } + } + if (alert.getAlertCategory() != null + && alert.getAlertType() != null + && alert.getAlertStatus() != null) + this.alert = alert; + } + + public Alert getAlert() { + return this.alert; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveBasalRateMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveBasalRateMessage.java new file mode 100644 index 0000000000..4b68739583 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveBasalRateMessage.java @@ -0,0 +1,30 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.status; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveBasalRate; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.ids.ActiveBasalProfileIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class GetActiveBasalRateMessage extends AppLayerMessage { + + private ActiveBasalRate activeBasalRate; + + public GetActiveBasalRateMessage() { + super(MessagePriority.NORMAL, true, false, Service.STATUS); + } + + @Override + protected void parse(ByteBuf byteBuf) { + ActiveBasalRate activeBasalRate = new ActiveBasalRate(); + activeBasalRate.setActiveBasalProfile(ActiveBasalProfileIDs.IDS.getType(byteBuf.readUInt16LE())); + activeBasalRate.setActiveBasalProfileName(byteBuf.readUTF16(30)); + activeBasalRate.setActiveBasalRate(byteBuf.readUInt16Decimal()); + if (activeBasalRate.getActiveBasalProfile() != null) this.activeBasalRate = activeBasalRate; + } + + public ActiveBasalRate getActiveBasalRate() { + return this.activeBasalRate; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveBolusesMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveBolusesMessage.java new file mode 100644 index 0000000000..4bcb988afd --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveBolusesMessage.java @@ -0,0 +1,40 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.status; + +import java.util.ArrayList; +import java.util.List; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveBolus; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.ids.ActiveBolusTypeIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class GetActiveBolusesMessage extends AppLayerMessage { + + private List activeBoluses; + + public GetActiveBolusesMessage() { + super(MessagePriority.NORMAL, true, false, Service.STATUS); + } + + @Override + protected void parse(ByteBuf byteBuf) { + activeBoluses = new ArrayList<>(); + for (int i = 0; i < 3; i++) { + ActiveBolus activeBolus = new ActiveBolus(); + activeBolus.setBolusID(byteBuf.readUInt16LE()); + activeBolus.setBolusType(ActiveBolusTypeIDs.IDS.getType(byteBuf.readUInt16LE())); + byteBuf.shift(2); + byteBuf.shift(2); + activeBolus.setInitialAmount(byteBuf.readUInt16Decimal()); + activeBolus.setRemainingAmount(byteBuf.readUInt16Decimal()); + activeBolus.setRemainingDuration(byteBuf.readUInt16LE()); + if (activeBolus.getBolusType() != null) activeBoluses.add(activeBolus); + } + } + + public List getActiveBoluses() { + return this.activeBoluses; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveTBRMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveTBRMessage.java new file mode 100644 index 0000000000..b685c65304 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveTBRMessage.java @@ -0,0 +1,29 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.status; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveTBR; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class GetActiveTBRMessage extends AppLayerMessage { + + private ActiveTBR activeTBR; + + public GetActiveTBRMessage() { + super(MessagePriority.NORMAL, true, false, Service.STATUS); + } + + @Override + protected void parse(ByteBuf byteBuf) { + ActiveTBR activeTBR = new ActiveTBR(); + activeTBR.setPercentage(byteBuf.readUInt16LE()); + activeTBR.setRemainingDuration(byteBuf.readUInt16LE()); + activeTBR.setInitialDuration(byteBuf.readUInt16LE()); + if (activeTBR.getPercentage() != 100) this.activeTBR = activeTBR; + } + + public ActiveTBR getActiveTBR() { + return this.activeTBR; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetBatteryStatusMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetBatteryStatusMessage.java new file mode 100644 index 0000000000..af4b7dc17a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetBatteryStatusMessage.java @@ -0,0 +1,30 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.status; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.BatteryStatus; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.ids.BatteryTypeIDs; +import info.nightscout.androidaps.plugins.pump.insight.ids.SymbolStatusIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class GetBatteryStatusMessage extends AppLayerMessage { + + private BatteryStatus batteryStatus; + + public GetBatteryStatusMessage() { + super(MessagePriority.NORMAL, false, false, Service.STATUS); + } + + @Override + protected void parse(ByteBuf byteBuf) { + batteryStatus = new BatteryStatus(); + batteryStatus.setBatteryType(BatteryTypeIDs.IDS.getType(byteBuf.readUInt16LE())); + batteryStatus.setBatteryAmount(byteBuf.readUInt16LE()); + batteryStatus.setSymbolStatus(SymbolStatusIDs.IDS.getType(byteBuf.readUInt16LE())); + } + + public BatteryStatus getBatteryStatus() { + return this.batteryStatus; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetCartridgeStatusMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetCartridgeStatusMessage.java new file mode 100644 index 0000000000..33740c5ce1 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetCartridgeStatusMessage.java @@ -0,0 +1,31 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.status; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.CartridgeStatus; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.ids.CartridgeTypeIDs; +import info.nightscout.androidaps.plugins.pump.insight.ids.SymbolStatusIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class GetCartridgeStatusMessage extends AppLayerMessage { + + private CartridgeStatus cartridgeStatus; + + public GetCartridgeStatusMessage() { + super(MessagePriority.NORMAL, false, false, Service.STATUS); + } + + @Override + protected void parse(ByteBuf byteBuf) { + cartridgeStatus = new CartridgeStatus(); + cartridgeStatus.setInserted(byteBuf.readBoolean()); + cartridgeStatus.setCartridgeType(CartridgeTypeIDs.IDS.getType(byteBuf.readUInt16LE())); + cartridgeStatus.setSymbolStatus(SymbolStatusIDs.IDS.getType(byteBuf.readUInt16LE())); + cartridgeStatus.setRemainingAmount(byteBuf.readUInt16Decimal()); + } + + public CartridgeStatus getCartridgeStatus() { + return this.cartridgeStatus; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetDateTimeMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetDateTimeMessage.java new file mode 100644 index 0000000000..e29bc5eaa2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetDateTimeMessage.java @@ -0,0 +1,31 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.status; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.PumpTime; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class GetDateTimeMessage extends AppLayerMessage { + + private PumpTime pumpTime; + + public GetDateTimeMessage() { + super(MessagePriority.NORMAL, true, false, Service.STATUS); + } + + @Override + protected void parse(ByteBuf byteBuf) { + pumpTime = new PumpTime(); + pumpTime.setYear(byteBuf.readUInt16LE()); + pumpTime.setMonth(byteBuf.readUInt8()); + pumpTime.setDay(byteBuf.readUInt8()); + pumpTime.setHour(byteBuf.readUInt8()); + pumpTime.setMinute(byteBuf.readUInt8()); + pumpTime.setSecond(byteBuf.readUInt8()); + } + + public PumpTime getPumpTime() { + return this.pumpTime; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetFirmwareVersionsMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetFirmwareVersionsMessage.java new file mode 100644 index 0000000000..705a5e228c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetFirmwareVersionsMessage.java @@ -0,0 +1,35 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.status; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.FirmwareVersions; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class GetFirmwareVersionsMessage extends AppLayerMessage { + + private FirmwareVersions firmwareVersions; + + public GetFirmwareVersionsMessage() { + super(MessagePriority.NORMAL, false, false, Service.STATUS); + } + + @Override + protected void parse(ByteBuf byteBuf) { + firmwareVersions = new FirmwareVersions(); + firmwareVersions.setReleaseSWVersion(byteBuf.readASCII(13)); + firmwareVersions.setUiProcSWVersion(byteBuf.readASCII(11)); + firmwareVersions.setPcProcSWVersion(byteBuf.readASCII(11)); + firmwareVersions.setMdTelProcSWVersion(byteBuf.readASCII(11)); + firmwareVersions.setBtInfoPageVersion(byteBuf.readASCII(11)); + firmwareVersions.setSafetyProcSWVersion(byteBuf.readASCII(11)); + firmwareVersions.setConfigIndex(byteBuf.readUInt16LE()); + firmwareVersions.setHistoryIndex(byteBuf.readUInt16LE()); + firmwareVersions.setStateIndex(byteBuf.readUInt16LE()); + firmwareVersions.setVocabularyIndex(byteBuf.readUInt16LE()); + } + + public FirmwareVersions getFirmwareVersions() { + return this.firmwareVersions; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetOperatingModeMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetOperatingModeMessage.java new file mode 100644 index 0000000000..27053a2a6a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetOperatingModeMessage.java @@ -0,0 +1,26 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.status; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.OperatingMode; +import info.nightscout.androidaps.plugins.pump.insight.ids.OperatingModeIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class GetOperatingModeMessage extends AppLayerMessage { + + private OperatingMode operatingMode; + + public GetOperatingModeMessage() { + super(MessagePriority.NORMAL, true, false, Service.STATUS); + } + + @Override + protected void parse(ByteBuf byteBuf) { + this.operatingMode = OperatingModeIDs.IDS.getType(byteBuf.readUInt16LE()); + } + + public OperatingMode getOperatingMode() { + return this.operatingMode; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetPumpStatusRegisterMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetPumpStatusRegisterMessage.java new file mode 100644 index 0000000000..11d777c197 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetPumpStatusRegisterMessage.java @@ -0,0 +1,60 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.status; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class GetPumpStatusRegisterMessage extends AppLayerMessage { + + private boolean operatingModeChanged; + private boolean batteryStatusChanged; + private boolean cartridgeStatusChanged; + private boolean totalDailyDoseChanged; + private boolean activeBasalRateChanged; + private boolean activeTBRChanged; + private boolean activeBolusesChanged; + + public GetPumpStatusRegisterMessage() { + super(MessagePriority.NORMAL, false, false, Service.STATUS); + } + + @Override + protected void parse(ByteBuf byteBuf) { + operatingModeChanged = byteBuf.readBoolean(); + batteryStatusChanged = byteBuf.readBoolean(); + cartridgeStatusChanged = byteBuf.readBoolean(); + totalDailyDoseChanged = byteBuf.readBoolean(); + activeBasalRateChanged = byteBuf.readBoolean(); + activeTBRChanged = byteBuf.readBoolean(); + activeBolusesChanged = byteBuf.readBoolean(); + } + + public boolean isOperatingModeChanged() { + return this.operatingModeChanged; + } + + public boolean isBatteryStatusChanged() { + return this.batteryStatusChanged; + } + + public boolean isCartridgeStatusChanged() { + return this.cartridgeStatusChanged; + } + + public boolean isTotalDailyDoseChanged() { + return this.totalDailyDoseChanged; + } + + public boolean isActiveBasalRateChanged() { + return this.activeBasalRateChanged; + } + + public boolean isActiveTBRChanged() { + return this.activeTBRChanged; + } + + public boolean isActiveBolusesChanged() { + return this.activeBolusesChanged; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetTotalDailyDoseMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetTotalDailyDoseMessage.java new file mode 100644 index 0000000000..e622614eea --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetTotalDailyDoseMessage.java @@ -0,0 +1,28 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.status; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.TotalDailyDose; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class GetTotalDailyDoseMessage extends AppLayerMessage { + + private TotalDailyDose tdd; + + public GetTotalDailyDoseMessage() { + super(MessagePriority.NORMAL, true, false, Service.STATUS); + } + + @Override + protected void parse(ByteBuf byteBuf) { + tdd = new TotalDailyDose(); + tdd.setBolus(byteBuf.readUInt32Decimal100()); + tdd.setBasal(byteBuf.readUInt32Decimal100()); + tdd.setBolusAndBasal(byteBuf.readUInt32Decimal100()); + } + + public TotalDailyDose getTDD() { + return this.tdd; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/ResetPumpStatusRegisterMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/ResetPumpStatusRegisterMessage.java new file mode 100644 index 0000000000..eacdf14769 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/ResetPumpStatusRegisterMessage.java @@ -0,0 +1,63 @@ +package info.nightscout.androidaps.plugins.pump.insight.app_layer.status; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class ResetPumpStatusRegisterMessage extends AppLayerMessage { + + private boolean operatingModeChanged; + private boolean batteryStatusChanged; + private boolean cartridgeStatusChanged; + private boolean totalDailyDoseChanged; + private boolean activeBasalRateChanged; + private boolean activeTBRChanged; + private boolean activeBolusesChanged; + + public ResetPumpStatusRegisterMessage() { + super(MessagePriority.NORMAL, false, false, Service.STATUS); + } + + @Override + protected ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(28); + byteBuf.putBoolean(operatingModeChanged); + byteBuf.putBoolean(batteryStatusChanged); + byteBuf.putBoolean(cartridgeStatusChanged); + byteBuf.putBoolean(totalDailyDoseChanged); + byteBuf.putBoolean(activeBasalRateChanged); + byteBuf.putBoolean(activeTBRChanged); + byteBuf.putBoolean(activeBolusesChanged); + for (int i = 0; i < 7; i++) byteBuf.putBoolean(false); + return byteBuf; + } + + public void setOperatingModeChanged(boolean operatingModeChanged) { + this.operatingModeChanged = operatingModeChanged; + } + + public void setBatteryStatusChanged(boolean batteryStatusChanged) { + this.batteryStatusChanged = batteryStatusChanged; + } + + public void setCartridgeStatusChanged(boolean cartridgeStatusChanged) { + this.cartridgeStatusChanged = cartridgeStatusChanged; + } + + public void setTotalDailyDoseChanged(boolean totalDailyDoseChanged) { + this.totalDailyDoseChanged = totalDailyDoseChanged; + } + + public void setActiveBasalRateChanged(boolean activeBasalRateChanged) { + this.activeBasalRateChanged = activeBasalRateChanged; + } + + public void setActiveTBRChanged(boolean activeTBRChanged) { + this.activeTBRChanged = activeTBRChanged; + } + + public void setActiveBolusesChanged(boolean activeBolusesChanged) { + this.activeBolusesChanged = activeBolusesChanged; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/ConfigurationMessageRequest.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/ConfigurationMessageRequest.java new file mode 100644 index 0000000000..44812eb48b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/ConfigurationMessageRequest.java @@ -0,0 +1,33 @@ +package info.nightscout.androidaps.plugins.pump.insight.connection_service; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration.CloseConfigurationWriteSessionMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration.OpenConfigurationWriteSessionMessage; + +public class ConfigurationMessageRequest extends MessageRequest { + + private MessageRequest openRequest; + private MessageRequest closeRequest; + + public ConfigurationMessageRequest(T request, MessageRequest openRequest, MessageRequest closeRequest) { + super(request); + this.openRequest = openRequest; + this.closeRequest = closeRequest; + } + + @Override + public T await() throws Exception { + openRequest.await(); + T response = super.await(); + closeRequest.await(); + return response; + } + + @Override + public T await(long timeout) throws Exception { + openRequest.await(timeout); + T response = super.await(timeout); + closeRequest.await(timeout); + return response; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/InsightConnectionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/InsightConnectionService.java new file mode 100644 index 0000000000..e964c9fa20 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/InsightConnectionService.java @@ -0,0 +1,827 @@ +package info.nightscout.androidaps.plugins.pump.insight.connection_service; + +import android.app.Service; +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; +import android.bluetooth.BluetoothSocket; +import android.content.Intent; +import android.os.Binder; +import android.os.IBinder; +import android.os.PowerManager; +import android.support.annotation.Nullable; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.spongycastle.crypto.InvalidCipherTextException; + +import java.io.IOException; +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.List; + +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.ReadParameterBlockMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration.CloseConfigurationWriteSessionMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration.OpenConfigurationWriteSessionMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration.WriteConfigurationBlockMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.connection.ActivateServiceMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.connection.BindMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.connection.ConnectMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.connection.DisconnectMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.connection.ServiceChallengeMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.SystemIdentificationBlock; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetFirmwareVersionsMessage; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.FirmwareVersions; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.InsightState; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.SystemIdentification; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.ConnectionFailedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.ConnectionLostException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.DisconnectedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.InsightException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.InvalidNonceException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.InvalidSatlCommandException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.ReceivedPacketInInvalidStateException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.TimeoutException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.TooChattyPumpException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlCompatibleStateErrorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlDecryptVerifyFailedErrorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlIncompatibleVersionErrorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlInvalidCRCErrorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlInvalidCommIdErrorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlInvalidMacErrorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlInvalidMessageTypeErrorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlInvalidNonceErrorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlInvalidPacketErrorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlInvalidPayloadLengthErrorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlNoneErrorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlPairingRejectedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlUndefinedErrorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlWrongStateException; +import info.nightscout.androidaps.plugins.pump.insight.ids.ServiceIDs; +import info.nightscout.androidaps.plugins.pump.insight.satl.ConnectionRequest; +import info.nightscout.androidaps.plugins.pump.insight.satl.ConnectionResponse; +import info.nightscout.androidaps.plugins.pump.insight.satl.DataMessage; +import info.nightscout.androidaps.plugins.pump.insight.satl.ErrorMessage; +import info.nightscout.androidaps.plugins.pump.insight.satl.KeyRequest; +import info.nightscout.androidaps.plugins.pump.insight.satl.KeyResponse; +import info.nightscout.androidaps.plugins.pump.insight.satl.SatlMessage; +import info.nightscout.androidaps.plugins.pump.insight.satl.SynAckResponse; +import info.nightscout.androidaps.plugins.pump.insight.satl.SynRequest; +import info.nightscout.androidaps.plugins.pump.insight.satl.VerifyConfirmRequest; +import info.nightscout.androidaps.plugins.pump.insight.satl.VerifyConfirmResponse; +import info.nightscout.androidaps.plugins.pump.insight.satl.VerifyDisplayRequest; +import info.nightscout.androidaps.plugins.pump.insight.satl.VerifyDisplayResponse; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; +import info.nightscout.androidaps.plugins.pump.insight.utils.ConnectionEstablisher; +import info.nightscout.androidaps.plugins.pump.insight.utils.DelayedActionThread; +import info.nightscout.androidaps.plugins.pump.insight.utils.InputStreamReader; +import info.nightscout.androidaps.plugins.pump.insight.utils.Nonce; +import info.nightscout.androidaps.plugins.pump.insight.utils.OutputStreamWriter; +import info.nightscout.androidaps.plugins.pump.insight.utils.PairingDataStorage; +import info.nightscout.androidaps.plugins.pump.insight.utils.crypto.Cryptograph; +import info.nightscout.androidaps.plugins.pump.insight.utils.crypto.DerivedKeys; +import info.nightscout.androidaps.plugins.pump.insight.utils.crypto.KeyPair; +import info.nightscout.androidaps.utils.SP; + +public class InsightConnectionService extends Service implements ConnectionEstablisher.Callback, InputStreamReader.Callback, OutputStreamWriter.Callback { + + private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); + + private static final int BUFFER_SIZE = 1024; + private static final int TIMEOUT_DURING_HANDSHAKE_NOTIFICATION_THRESHOLD = 3; + private static final long RESPONSE_TIMEOUT = 6000; + + private List stateCallbacks = new ArrayList<>(); + private final List connectionRequests = new ArrayList<>(); + private List exceptionCallbacks = new ArrayList<>(); + private LocalBinder localBinder = new LocalBinder(); + private PairingDataStorage pairingDataStorage; + private InsightState state; + private PowerManager.WakeLock wakeLock; + private DelayedActionThread disconnectTimer; + private DelayedActionThread recoveryTimer; + private DelayedActionThread timeoutTimer; + private BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); + private BluetoothDevice bluetoothDevice; + private BluetoothSocket bluetoothSocket; + private ConnectionEstablisher connectionEstablisher; + private InputStreamReader inputStreamReader; + private OutputStreamWriter outputStreamWriter; + private KeyRequest keyRequest; + private ByteBuf buffer = new ByteBuf(BUFFER_SIZE); + private String verificationString; + private KeyPair keyPair; + private byte[] randomBytes; + private MessageQueue messageQueue = new MessageQueue(); + private List activatedServices = new ArrayList<>(); + private long lastDataTime; + private long lastConnected; + private long recoveryDuration = 0; + private int timeoutDuringHandshakeCounter; + + KeyPair getKeyPair() { + if (keyPair == null) keyPair = Cryptograph.generateRSAKey(); + return keyPair; + } + + byte[] getRandomBytes() { + if (randomBytes == null) { + randomBytes = new byte[28]; + new SecureRandom().nextBytes(randomBytes); + } + return randomBytes; + } + + public synchronized long getRecoveryDuration() { + return recoveryDuration; + } + + private void increaseRecoveryDuration() { + long maxRecoveryDuration = SP.getInt("insight_max_recovery_duration", 20); + maxRecoveryDuration = Math.min(maxRecoveryDuration, 20); + maxRecoveryDuration = Math.max(maxRecoveryDuration, 0); + long minRecoveryDuration = SP.getInt("insight_min_recovery_duration", 5); + minRecoveryDuration = Math.min(minRecoveryDuration, 20); + minRecoveryDuration = Math.max(minRecoveryDuration, 0); + recoveryDuration += 1000; + recoveryDuration = Math.max(recoveryDuration, minRecoveryDuration * 1000); + recoveryDuration = Math.min(recoveryDuration, maxRecoveryDuration * 1000); + } + + public long getLastConnected() { + return lastConnected; + } + + public long getLastDataTime() { + return lastDataTime; + } + + public FirmwareVersions getPumpFirmwareVersions() { + return pairingDataStorage.getFirmwareVersions(); + } + + public SystemIdentification getPumpSystemIdentification() { + return pairingDataStorage.getSystemIdentification(); + } + + public String getBluetoothAddress() { + return pairingDataStorage.getMacAddress(); + } + + public synchronized String getVerificationString() { + return verificationString; + } + + public synchronized void registerStateCallback(StateCallback stateCallback) { + stateCallbacks.add(stateCallback); + } + + public synchronized void unregisterStateCallback(StateCallback stateCallback) { + stateCallbacks.remove(stateCallback); + } + + public synchronized void registerExceptionCallback(ExceptionCallback exceptionCallback) { + exceptionCallbacks.add(exceptionCallback); + } + + public synchronized void unregisterExceptionCallback(ExceptionCallback exceptionCallback) { + exceptionCallbacks.remove(exceptionCallback); + } + + public synchronized void confirmVerificationString() { + setState(InsightState.SATL_VERIFY_CONFIRM_REQUEST); + sendSatlMessage(new VerifyConfirmRequest()); + } + + public synchronized void rejectVerificationString() { + handleException(new SatlPairingRejectedException()); + } + + public synchronized boolean isPaired() { + return pairingDataStorage.isPaired(); + } + + public synchronized MessageRequest requestMessage(T message) { + MessageRequest messageRequest; + if (getState() != InsightState.CONNECTED) { + messageRequest = new MessageRequest<>(message); + messageRequest.exception = new DisconnectedException(); + return messageRequest; + } + if (message instanceof WriteConfigurationBlockMessage) { + MessageRequest openRequest = new MessageRequest<>(new OpenConfigurationWriteSessionMessage()); + MessageRequest closeRequest = new MessageRequest<>(new CloseConfigurationWriteSessionMessage()); + messageRequest = new ConfigurationMessageRequest<>(message, openRequest, closeRequest); + messageQueue.enqueueRequest(openRequest); + messageQueue.enqueueRequest(messageRequest); + messageQueue.enqueueRequest(closeRequest); + } else { + messageRequest = new MessageRequest<>(message); + messageQueue.enqueueRequest(messageRequest); + } + requestNextMessage(); + return messageRequest; + } + + private void requestNextMessage() { + while (messageQueue.getActiveRequest() == null && messageQueue.hasPendingMessages()) { + messageQueue.nextRequest(); + info.nightscout.androidaps.plugins.pump.insight.app_layer.Service service = messageQueue.getActiveRequest().request.getService(); + if (service != info.nightscout.androidaps.plugins.pump.insight.app_layer.Service.CONNECTION && !activatedServices.contains(service)) { + if (service.getServicePassword() == null) { + ActivateServiceMessage activateServiceMessage = new ActivateServiceMessage(); + activateServiceMessage.setServiceID(ServiceIDs.IDS.getID(service)); + activateServiceMessage.setVersion(service.getVersion()); + activateServiceMessage.setServicePassword(new byte[16]); + sendAppLayerMessage(activateServiceMessage); + } else { + ServiceChallengeMessage serviceChallengeMessage = new ServiceChallengeMessage(); + serviceChallengeMessage.setServiceID(ServiceIDs.IDS.getID(service)); + serviceChallengeMessage.setVersion(service.getVersion()); + sendAppLayerMessage(serviceChallengeMessage); + } + } else sendAppLayerMessage(messageQueue.getActiveRequest().request); + } + } + + public synchronized InsightState getState() { + return state; + } + + @Override + public synchronized void onCreate() { + pairingDataStorage = new PairingDataStorage(this); + state = pairingDataStorage.isPaired() ? InsightState.DISCONNECTED : InsightState.NOT_PAIRED; + wakeLock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:InsightConnectionService"); + } + + private void setState(InsightState state) { + if (this.state == state) return; + if (this.state == InsightState.CONNECTED) lastConnected = System.currentTimeMillis(); + if ((state == InsightState.DISCONNECTED || state == InsightState.NOT_PAIRED) && wakeLock.isHeld()) + wakeLock.release(); + else if (!wakeLock.isHeld()) wakeLock.acquire(); + this.state = state; + for (StateCallback stateCallback : stateCallbacks) stateCallback.onStateChanged(state); + log.info("Insight state changed: " + state.name()); + } + + public synchronized void requestConnection(Object lock) { + if (connectionRequests.contains(lock)) return; + connectionRequests.add(lock); + if (disconnectTimer != null) { + disconnectTimer.interrupt(); + disconnectTimer = null; + } + if (state == InsightState.DISCONNECTED && pairingDataStorage.isPaired()) { + recoveryDuration = 0; + timeoutDuringHandshakeCounter = 0; + connect(); + } + } + + public synchronized void withdrawConnectionRequest(Object lock) { + if (!connectionRequests.contains(lock)) return; + connectionRequests.remove(lock); + if (connectionRequests.size() == 0) { + if (state == InsightState.RECOVERING) { + recoveryTimer.interrupt(); + recoveryTimer = null; + setState(InsightState.DISCONNECTED); + cleanup(true); + } else if (state != InsightState.DISCONNECTED) { + long disconnectTimeout = SP.getInt("insight_disconnect_delay", 5); + disconnectTimeout = Math.min(disconnectTimeout, 15); + disconnectTimeout = Math.max(disconnectTimeout, 0); + log.info("Last connection lock released, will disconnect in " + disconnectTimeout + " seconds"); + disconnectTimer = DelayedActionThread.runDelayed("Disconnect Timer", disconnectTimeout * 1000, this::disconnect); + } + } + } + + public synchronized boolean hasRequestedConnection(Object lock) { + return connectionRequests.contains(lock); + } + + private void cleanup(boolean closeSocket) { + messageQueue.completeActiveRequest(new ConnectionLostException()); + messageQueue.completePendingRequests(new ConnectionLostException()); + if (recoveryTimer != null) { + recoveryTimer.interrupt(); + recoveryTimer = null; + } + if (disconnectTimer != null) { + disconnectTimer.interrupt(); + disconnectTimer = null; + } + if (inputStreamReader != null) { + inputStreamReader.close(); + inputStreamReader = null; + } + if (outputStreamWriter != null) { + outputStreamWriter.close(); + outputStreamWriter = null; + } + if (connectionEstablisher != null) { + if (closeSocket) { + connectionEstablisher.close(closeSocket); + bluetoothSocket = null; + } + connectionEstablisher = null; + } + if (timeoutTimer != null) { + timeoutTimer.interrupt(); + timeoutTimer = null; + } + buffer.clear(); + verificationString = null; + keyPair = null; + randomBytes = null; + activatedServices.clear(); + if (!pairingDataStorage.isPaired()) { + bluetoothSocket = null; + bluetoothDevice = null; + pairingDataStorage.reset(); + } + } + + private synchronized void handleException(Exception e) { + switch (state) { + case NOT_PAIRED: + case DISCONNECTED: + case RECOVERING: + return; + } + log.info("Exception occurred: " + e.getClass().getSimpleName()); + if (pairingDataStorage.isPaired()) { + if (e instanceof TimeoutException && (state == InsightState.SATL_SYN_REQUEST || state == InsightState.APP_CONNECT_MESSAGE)) { + if (++timeoutDuringHandshakeCounter == TIMEOUT_DURING_HANDSHAKE_NOTIFICATION_THRESHOLD) { + for (StateCallback stateCallback : stateCallbacks) { + stateCallback.onTimeoutDuringHandshake(); + } + } + } + setState(connectionRequests.size() != 0 ? InsightState.RECOVERING : InsightState.DISCONNECTED); + if (e instanceof ConnectionFailedException) { + cleanup(((ConnectionFailedException) e).getDurationOfConnectionAttempt() <= 1000); + } else cleanup(true); + messageQueue.completeActiveRequest(e); + messageQueue.completePendingRequests(e); + if (connectionRequests.size() != 0) { + if (!(e instanceof ConnectionFailedException)) { + connect(); + } else { + increaseRecoveryDuration(); + if (recoveryDuration == 0) connect(); + else { + recoveryTimer = DelayedActionThread.runDelayed("RecoveryTimer", recoveryDuration, () -> { + recoveryTimer = null; + synchronized (InsightConnectionService.this) { + if (!Thread.currentThread().isInterrupted()) connect(); + } + }); + } + } + } + } else { + setState(InsightState.NOT_PAIRED); + cleanup(true); + } + for (ExceptionCallback exceptionCallback : exceptionCallbacks) + exceptionCallback.onExceptionOccur(e); + } + + private synchronized void disconnect() { + if (state == InsightState.CONNECTED) { + sendAppLayerMessage(new DisconnectMessage()); + sendSatlMessageAndWait(new info.nightscout.androidaps.plugins.pump.insight.satl.DisconnectMessage()); + } + cleanup(true); + setState(pairingDataStorage.isPaired() ? InsightState.DISCONNECTED : InsightState.NOT_PAIRED); + } + + public synchronized void reset() { + pairingDataStorage.reset(); + disconnect(); + } + + public synchronized void pair(String macAddress) { + if (pairingDataStorage.isPaired()) + throw new IllegalStateException("Pump must be unbonded first."); + if (connectionRequests.size() == 0) + throw new IllegalStateException("A connection lock must be hold for pairing"); + log.info("Pairing initiated"); + cleanup(true); + pairingDataStorage.setMacAddress(macAddress); + connect(); + } + + private synchronized void connect() { + if (bluetoothDevice == null) + bluetoothDevice = bluetoothAdapter.getRemoteDevice(pairingDataStorage.getMacAddress()); + setState(InsightState.CONNECTING); + connectionEstablisher = new ConnectionEstablisher(this, !pairingDataStorage.isPaired(), bluetoothAdapter, bluetoothDevice, bluetoothSocket); + connectionEstablisher.start(); + } + + @Override + public synchronized void onSocketCreated(BluetoothSocket bluetoothSocket) { + this.bluetoothSocket = bluetoothSocket; + } + + @Override + public synchronized void onConnectionSucceed() { + try { + recoveryDuration = 0; + inputStreamReader = new InputStreamReader(bluetoothSocket.getInputStream(), this); + outputStreamWriter = new OutputStreamWriter(bluetoothSocket.getOutputStream(), this); + inputStreamReader.start(); + outputStreamWriter.start(); + if (pairingDataStorage.isPaired()) { + setState(InsightState.SATL_SYN_REQUEST); + sendSatlMessage(new SynRequest()); + } else { + setState(InsightState.SATL_CONNECTION_REQUEST); + sendSatlMessage(new ConnectionRequest()); + } + } catch (IOException e) { + handleException(e); + } + } + + @Override + public synchronized void onReceiveBytes(byte[] buffer, int bytesRead) { + this.buffer.putBytes(buffer, bytesRead); + try { + while (SatlMessage.hasCompletePacket(this.buffer)) { + SatlMessage satlMessage = SatlMessage.deserialize(this.buffer, pairingDataStorage.getLastNonceReceived(), pairingDataStorage.getIncomingKey()); + if (pairingDataStorage.getIncomingKey() != null + && pairingDataStorage.getLastNonceReceived() != null + && !pairingDataStorage.getLastNonceReceived().isSmallerThan(satlMessage.getNonce())) { + throw new InvalidNonceException(); + } else processSatlMessage(satlMessage); + } + } catch (InsightException e) { + handleException(e); + } + } + + private byte[] prepareSatlMessage(SatlMessage satlMessage) { + satlMessage.setCommID(pairingDataStorage.getCommId()); + Nonce nonce = pairingDataStorage.getLastNonceSent(); + if (nonce != null) { + nonce.increment(); + pairingDataStorage.setLastNonceSent(nonce); + satlMessage.setNonce(nonce); + } + ByteBuf serialized = satlMessage.serialize(satlMessage.getClass(), pairingDataStorage.getOutgoingKey()); + if (timeoutTimer != null) timeoutTimer.interrupt(); + timeoutTimer = DelayedActionThread.runDelayed("TimeoutTimer", RESPONSE_TIMEOUT, () -> { + timeoutTimer = null; + handleException(new TimeoutException()); + }); + return serialized.getBytes(); + } + + private void sendSatlMessage(SatlMessage satlMessage) { + if (outputStreamWriter == null) return; + outputStreamWriter.write(prepareSatlMessage(satlMessage)); + } + + private void sendSatlMessageAndWait(SatlMessage satlMessage) { + if (outputStreamWriter == null) return; + outputStreamWriter.writeAndWait(prepareSatlMessage(satlMessage)); + } + + private void processSatlMessage(SatlMessage satlMessage) { + if (timeoutTimer != null) { + timeoutTimer.interrupt(); + timeoutTimer = null; + } + pairingDataStorage.setLastNonceReceived(satlMessage.getNonce()); + if (satlMessage instanceof ConnectionResponse) processConnectionResponse(); + else if (satlMessage instanceof KeyResponse) processKeyResponse((KeyResponse) satlMessage); + else if (satlMessage instanceof VerifyDisplayResponse) processVerifyDisplayResponse(); + else if (satlMessage instanceof VerifyConfirmResponse) + processVerifyConfirmResponse((VerifyConfirmResponse) satlMessage); + else if (satlMessage instanceof DataMessage) processDataMessage((DataMessage) satlMessage); + else if (satlMessage instanceof SynAckResponse) processSynAckResponse(); + else if (satlMessage instanceof ErrorMessage) + processErrorMessage((ErrorMessage) satlMessage); + else handleException(new InvalidSatlCommandException()); + } + + private void processConnectionResponse() { + if (state != InsightState.SATL_CONNECTION_REQUEST) { + handleException(new ReceivedPacketInInvalidStateException()); + return; + } + keyRequest = new KeyRequest(); + keyRequest.setPreMasterKey(getKeyPair().getPublicKeyBytes()); + keyRequest.setRandomBytes(getRandomBytes()); + setState(InsightState.SATL_KEY_REQUEST); + sendSatlMessage(keyRequest); + } + + private void processKeyResponse(KeyResponse keyResponse) { + if (state != InsightState.SATL_KEY_REQUEST) { + handleException(new ReceivedPacketInInvalidStateException()); + return; + } + try { + DerivedKeys derivedKeys = Cryptograph.deriveKeys(Cryptograph.combine(keyRequest.getSatlContent(), keyResponse.getSatlContent()), + Cryptograph.decryptRSA(getKeyPair().getPrivateKey(), keyResponse.getPreMasterSecret()), + getRandomBytes(), + keyResponse.getRandomData()); + pairingDataStorage.setCommId(keyResponse.getCommID()); + keyRequest = null; + randomBytes = null; + keyPair = null; + verificationString = derivedKeys.getVerificationString(); + pairingDataStorage.setOutgoingKey(derivedKeys.getOutgoingKey()); + pairingDataStorage.setIncomingKey(derivedKeys.getIncomingKey()); + pairingDataStorage.setLastNonceSent(new Nonce()); + setState(InsightState.SATL_VERIFY_DISPLAY_REQUEST); + sendSatlMessage(new VerifyDisplayRequest()); + } catch (InvalidCipherTextException e) { + handleException(e); + } + } + + private void processVerifyDisplayResponse() { + if (state != InsightState.SATL_VERIFY_DISPLAY_REQUEST) { + handleException(new ReceivedPacketInInvalidStateException()); + return; + } + setState(InsightState.AWAITING_CODE_CONFIRMATION); + } + + private void processVerifyConfirmResponse(VerifyConfirmResponse verifyConfirmResponse) { + if (state != InsightState.SATL_VERIFY_CONFIRM_REQUEST) { + handleException(new ReceivedPacketInInvalidStateException()); + return; + } + switch (verifyConfirmResponse.getPairingStatus()) { + case CONFIRMED: + verificationString = null; + setState(InsightState.APP_BIND_MESSAGE); + sendAppLayerMessage(new BindMessage()); + break; + case PENDING: + try { + Thread.sleep(200); + sendSatlMessage(new VerifyConfirmRequest()); + } catch (InterruptedException e) { + //Redirect interrupt flag + Thread.currentThread().interrupt(); + } + break; + case REJECTED: + handleException(new SatlPairingRejectedException()); + break; + } + } + + private void processSynAckResponse() { + if (state != InsightState.SATL_SYN_REQUEST) { + handleException(new ReceivedPacketInInvalidStateException()); + return; + } + setState(InsightState.APP_CONNECT_MESSAGE); + sendAppLayerMessage(new ConnectMessage()); + } + + private void processErrorMessage(ErrorMessage errorMessage) { + switch (errorMessage.getError()) { + case INVALID_NONCE: + handleException(new SatlInvalidNonceErrorException()); + break; + case INVALID_CRC: + handleException(new SatlInvalidCRCErrorException()); + break; + case INVALID_MAC_TRAILER: + handleException(new SatlInvalidMacErrorException()); + break; + case DECRYPT_VERIFY_FAILED: + handleException(new SatlDecryptVerifyFailedErrorException()); + break; + case INVALID_PAYLOAD_LENGTH: + handleException(new SatlInvalidPayloadLengthErrorException()); + break; + case INVALID_MESSAGE_TYPE: + handleException(new SatlInvalidMessageTypeErrorException()); + break; + case INCOMPATIBLE_VERSION: + handleException(new SatlIncompatibleVersionErrorException()); + break; + case COMPATIBLE_STATE: + handleException(new SatlCompatibleStateErrorException()); + break; + case INVALID_COMM_ID: + handleException(new SatlInvalidCommIdErrorException()); + break; + case INVALID_PACKET: + handleException(new SatlInvalidPacketErrorException()); + break; + case WRONG_STATE: + handleException(new SatlWrongStateException()); + break; + case UNDEFINED: + handleException(new SatlUndefinedErrorException()); + break; + case NONE: + handleException(new SatlNoneErrorException()); + break; + } + } + + private void processDataMessage(DataMessage dataMessage) { + switch (state) { + case CONNECTED: + case APP_BIND_MESSAGE: + case APP_CONNECT_MESSAGE: + case APP_ACTIVATE_PARAMETER_SERVICE: + case APP_ACTIVATE_STATUS_SERVICE: + case APP_FIRMWARE_VERSIONS: + case APP_SYSTEM_IDENTIFICATION: + break; + default: + handleException(new ReceivedPacketInInvalidStateException()); + } + try { + AppLayerMessage appLayerMessage = AppLayerMessage.unwrap(dataMessage); + if (appLayerMessage instanceof BindMessage) processBindMessage(); + else if (appLayerMessage instanceof ConnectMessage) processConnectMessage(); + else if (appLayerMessage instanceof ActivateServiceMessage) + processActivateServiceMessage(); + else if (appLayerMessage instanceof DisconnectMessage) ; + else if (appLayerMessage instanceof ServiceChallengeMessage) + processServiceChallengeMessage((ServiceChallengeMessage) appLayerMessage); + else if (appLayerMessage instanceof GetFirmwareVersionsMessage) + processFirmwareVersionsMessage((GetFirmwareVersionsMessage) appLayerMessage); + else if (appLayerMessage instanceof ReadParameterBlockMessage) + processReadParameterBlockMessage((ReadParameterBlockMessage) appLayerMessage); + else processGenericAppLayerMessage(appLayerMessage); + } catch (Exception e) { + if (state != InsightState.CONNECTED) { + handleException(e); + } else { + if (messageQueue.getActiveRequest() == null) { + handleException(new TooChattyPumpException()); + } else { + messageQueue.completeActiveRequest(e); + requestNextMessage(); + } + } + } + } + + private void processBindMessage() { + if (state != InsightState.APP_BIND_MESSAGE) { + handleException(new ReceivedPacketInInvalidStateException()); + return; + } + setState(InsightState.APP_ACTIVATE_STATUS_SERVICE); + ActivateServiceMessage activateServiceMessage = new ActivateServiceMessage(); + activateServiceMessage.setServiceID(ServiceIDs.IDS.getID(info.nightscout.androidaps.plugins.pump.insight.app_layer.Service.STATUS)); + activateServiceMessage.setServicePassword(new byte[16]); + activateServiceMessage.setVersion(info.nightscout.androidaps.plugins.pump.insight.app_layer.Service.STATUS.getVersion()); + sendAppLayerMessage(activateServiceMessage); + } + + private void processFirmwareVersionsMessage(GetFirmwareVersionsMessage message) { + if (state != InsightState.APP_FIRMWARE_VERSIONS) { + handleException(new ReceivedPacketInInvalidStateException()); + return; + } + pairingDataStorage.setFirmwareVersions(message.getFirmwareVersions()); + setState(InsightState.APP_ACTIVATE_PARAMETER_SERVICE); + ActivateServiceMessage activateServiceMessage = new ActivateServiceMessage(); + activateServiceMessage.setServiceID(ServiceIDs.IDS.getID(info.nightscout.androidaps.plugins.pump.insight.app_layer.Service.PARAMETER)); + activateServiceMessage.setServicePassword(new byte[16]); + activateServiceMessage.setVersion(info.nightscout.androidaps.plugins.pump.insight.app_layer.Service.PARAMETER.getVersion()); + sendAppLayerMessage(activateServiceMessage); + } + + private void processConnectMessage() { + if (state != InsightState.APP_CONNECT_MESSAGE) { + handleException(new ReceivedPacketInInvalidStateException()); + return; + } + setState(InsightState.CONNECTED); + } + + private void processActivateServiceMessage() { + if (state == InsightState.APP_ACTIVATE_PARAMETER_SERVICE) { + activatedServices.add(info.nightscout.androidaps.plugins.pump.insight.app_layer.Service.PARAMETER); + setState(InsightState.APP_SYSTEM_IDENTIFICATION); + ReadParameterBlockMessage message = new ReadParameterBlockMessage(); + message.setParameterBlockId(SystemIdentificationBlock.class); + message.setService(info.nightscout.androidaps.plugins.pump.insight.app_layer.Service.PARAMETER); + sendAppLayerMessage(message); + } else if (state == InsightState.APP_ACTIVATE_STATUS_SERVICE) { + activatedServices.add(info.nightscout.androidaps.plugins.pump.insight.app_layer.Service.STATUS); + setState(InsightState.APP_FIRMWARE_VERSIONS); + sendAppLayerMessage(new GetFirmwareVersionsMessage()); + } else { + if (messageQueue.getActiveRequest() == null) { + handleException(new TooChattyPumpException()); + } else { + activatedServices.add(messageQueue.getActiveRequest().request.getService()); + sendAppLayerMessage(messageQueue.getActiveRequest().request); + } + } + } + + private void processReadParameterBlockMessage(ReadParameterBlockMessage message) { + if (state == InsightState.APP_SYSTEM_IDENTIFICATION) { + if (!(message.getParameterBlock() instanceof SystemIdentificationBlock)) + handleException(new TooChattyPumpException()); + else { + SystemIdentification systemIdentification = ((SystemIdentificationBlock) message.getParameterBlock()).getSystemIdentification(); + pairingDataStorage.setSystemIdentification(systemIdentification); + pairingDataStorage.setPaired(true); + log.info("Pairing completed YEE-HAW ♪ ┏(・o・)┛ ♪ ┗( ・o・)┓ ♪"); + setState(InsightState.CONNECTED); + for (StateCallback stateCallback : stateCallbacks) stateCallback.onPumpPaired(); + } + } else processGenericAppLayerMessage(message); + } + + private void processServiceChallengeMessage(ServiceChallengeMessage serviceChallengeMessage) { + if (messageQueue.getActiveRequest() == null) { + handleException(new TooChattyPumpException()); + } else { + info.nightscout.androidaps.plugins.pump.insight.app_layer.Service service = messageQueue.getActiveRequest().request.getService(); + ActivateServiceMessage activateServiceMessage = new ActivateServiceMessage(); + activateServiceMessage.setServiceID(ServiceIDs.IDS.getID(service)); + activateServiceMessage.setVersion(service.getVersion()); + activateServiceMessage.setServicePassword(Cryptograph.getServicePasswordHash(service.getServicePassword(), serviceChallengeMessage.getRandomData())); + sendAppLayerMessage(activateServiceMessage); + } + } + + private void processGenericAppLayerMessage(AppLayerMessage appLayerMessage) { + if (messageQueue.getActiveRequest() == null) handleException(new TooChattyPumpException()); + else { + try { + messageQueue.completeActiveRequest(appLayerMessage); + lastDataTime = System.currentTimeMillis(); + } catch (Exception e) { + messageQueue.completeActiveRequest(e); + } + requestNextMessage(); + } + } + + void sendAppLayerMessage(AppLayerMessage appLayerMessage) { + sendSatlMessage(AppLayerMessage.wrap(appLayerMessage)); + } + + @Override + public synchronized void onConnectionFail(Exception e, long duration) { + handleException(new ConnectionFailedException(duration)); + } + + @Override + public synchronized void onErrorWhileReading(Exception e) { + handleException(new ConnectionLostException()); + } + + @Override + public synchronized void onErrorWhileWriting(Exception e) { + handleException(new ConnectionLostException()); + } + + @Override + public void onDestroy() { + disconnect(); + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return localBinder; + } + + public class LocalBinder extends Binder { + public InsightConnectionService getService() { + return InsightConnectionService.this; + } + } + + public interface StateCallback { + void onStateChanged(InsightState state); + + default void onPumpPaired() { + } + + default void onTimeoutDuringHandshake() { + } + } + + public interface ExceptionCallback { + void onExceptionOccur(Exception e); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/MessageQueue.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/MessageQueue.java new file mode 100644 index 0000000000..f54f437564 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/MessageQueue.java @@ -0,0 +1,66 @@ +package info.nightscout.androidaps.plugins.pump.insight.connection_service; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; + +public class MessageQueue { + + MessageRequest activeRequest; + final List messageRequests = new ArrayList<>(); + + public MessageRequest getActiveRequest() { + return activeRequest; + } + + public void completeActiveRequest(AppLayerMessage response) { + if (activeRequest == null) return; + synchronized (activeRequest) { + activeRequest.response = response; + activeRequest.notifyAll(); + } + activeRequest = null; + } + + public void completeActiveRequest(Exception exception) { + if (activeRequest == null) return; + synchronized (activeRequest) { + activeRequest.exception = exception; + activeRequest.notifyAll(); + } + activeRequest = null; + } + + public void completePendingRequests(Exception exception) { + for (MessageRequest messageRequest : messageRequests) { + synchronized (messageRequest) { + messageRequest.exception = exception; + messageRequest.notifyAll(); + } + } + messageRequests.clear(); + } + + public void enqueueRequest(MessageRequest messageRequest) { + messageRequests.add(messageRequest); + Collections.sort(messageRequests); + } + + public void nextRequest() { + if (messageRequests.size() != 0) { + activeRequest = messageRequests.get(0); + messageRequests.remove(0); + } + } + + public boolean hasPendingMessages() { + return messageRequests.size() != 0; + } + + public void reset() { + activeRequest = null; + messageRequests.clear(); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/MessageRequest.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/MessageRequest.java new file mode 100644 index 0000000000..70fdf63649 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/MessageRequest.java @@ -0,0 +1,47 @@ +package info.nightscout.androidaps.plugins.pump.insight.connection_service; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; + +public class MessageRequest implements Comparable { + + T request; + T response; + Exception exception; + + MessageRequest(T request) { + this.request = request; + } + + public T await() throws Exception { + synchronized (this) { + while (exception == null && response == null) wait(); + if (exception != null) throw exception; + return response; + } + } + + public T await(long timeout) throws Exception { + synchronized (this) { + while (exception == null && response == null) wait(timeout); + if (exception != null) throw exception; + return response; + } + } + + @Override + public int compareTo(MessageRequest messageRequest) { + return request.compareTo(messageRequest.request); + } + + public T getRequest() { + return this.request; + } + + public T getResponse() { + return this.response; + } + + public Exception getException() { + return this.exception; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/database/InsightBolusID.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/database/InsightBolusID.java new file mode 100644 index 0000000000..16fa232a40 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/database/InsightBolusID.java @@ -0,0 +1,29 @@ +package info.nightscout.androidaps.plugins.pump.insight.database; + +import com.j256.ormlite.field.DatabaseField; +import com.j256.ormlite.table.DatabaseTable; + +import info.nightscout.androidaps.db.DatabaseHelper; + +@DatabaseTable(tableName = DatabaseHelper.DATABASE_INSIGHT_BOLUS_IDS) +public class InsightBolusID { + + @DatabaseField(generatedId = true) + public Long id; + + @DatabaseField + public String pumpSerial; + + @DatabaseField + public Long timestamp; + + @DatabaseField + public Integer bolusID; + + @DatabaseField + public Long startID; + + @DatabaseField + public Long endID; + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/database/InsightHistoryOffset.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/database/InsightHistoryOffset.java new file mode 100644 index 0000000000..05f9d2d5e3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/database/InsightHistoryOffset.java @@ -0,0 +1,16 @@ +package info.nightscout.androidaps.plugins.pump.insight.database; + +import com.j256.ormlite.field.DatabaseField; +import com.j256.ormlite.table.DatabaseTable; + +import info.nightscout.androidaps.db.DatabaseHelper; + +@DatabaseTable(tableName = DatabaseHelper.DATABASE_INSIGHT_HISTORY_OFFSETS) +public class InsightHistoryOffset { + + @DatabaseField(id = true, canBeNull = false) + public String pumpSerial; + + @DatabaseField + public long offset; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/database/InsightPumpID.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/database/InsightPumpID.java new file mode 100644 index 0000000000..7bd70b9185 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/database/InsightPumpID.java @@ -0,0 +1,26 @@ +package info.nightscout.androidaps.plugins.pump.insight.database; + +import com.j256.ormlite.field.DatabaseField; +import com.j256.ormlite.table.DatabaseTable; + +import info.nightscout.androidaps.db.DatabaseHelper; + +@DatabaseTable(tableName = DatabaseHelper.DATABASE_INSIGHT_PUMP_IDS) +public class InsightPumpID { + + @DatabaseField(generatedId = true) + public Long id; + + @DatabaseField + public long timestamp; + + @DatabaseField + public String eventType; + + @DatabaseField + public String pumpSerial; + + @DatabaseField + public long eventID; + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/ActiveBasalRate.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/ActiveBasalRate.java new file mode 100644 index 0000000000..2fb078794b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/ActiveBasalRate.java @@ -0,0 +1,32 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public class ActiveBasalRate { + + private BasalProfile activeBasalProfile; + private String activeBasalProfileName; + private double activeBasalRate; + + public BasalProfile getActiveBasalProfile() { + return this.activeBasalProfile; + } + + public String getActiveBasalProfileName() { + return this.activeBasalProfileName; + } + + public double getActiveBasalRate() { + return this.activeBasalRate; + } + + public void setActiveBasalProfile(BasalProfile activeBasalProfile) { + this.activeBasalProfile = activeBasalProfile; + } + + public void setActiveBasalProfileName(String activeBasalProfileName) { + this.activeBasalProfileName = activeBasalProfileName; + } + + public void setActiveBasalRate(double activeBasalRate) { + this.activeBasalRate = activeBasalRate; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/ActiveBolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/ActiveBolus.java new file mode 100644 index 0000000000..f36e1d7de4 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/ActiveBolus.java @@ -0,0 +1,50 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public class ActiveBolus { + + private int bolusID; + private BolusType bolusType; + private double initialAmount; + private double remainingAmount; + private int remainingDuration; + + public int getBolusID() { + return this.bolusID; + } + + public BolusType getBolusType() { + return this.bolusType; + } + + public double getInitialAmount() { + return this.initialAmount; + } + + public double getRemainingAmount() { + return this.remainingAmount; + } + + public int getRemainingDuration() { + return this.remainingDuration; + } + + public void setBolusID(int bolusID) { + this.bolusID = bolusID; + } + + public void setBolusType(BolusType bolusType) { + this.bolusType = bolusType; + } + + public void setInitialAmount(double initialAmount) { + this.initialAmount = initialAmount; + } + + public void setRemainingAmount(double remainingAmount) { + this.remainingAmount = remainingAmount; + } + + public void setRemainingDuration(int remainingDuration) { + this.remainingDuration = remainingDuration; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/ActiveTBR.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/ActiveTBR.java new file mode 100644 index 0000000000..406dd8c8fc --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/ActiveTBR.java @@ -0,0 +1,32 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public class ActiveTBR { + + private int percentage; + private int remainingDuration; + private int initialDuration; + + public int getPercentage() { + return this.percentage; + } + + public int getRemainingDuration() { + return this.remainingDuration; + } + + public int getInitialDuration() { + return this.initialDuration; + } + + public void setPercentage(int percentage) { + this.percentage = percentage; + } + + public void setRemainingDuration(int remainingDuration) { + this.remainingDuration = remainingDuration; + } + + public void setInitialDuration(int initialDuration) { + this.initialDuration = initialDuration; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/Alert.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/Alert.java new file mode 100644 index 0000000000..8f6668c1ca --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/Alert.java @@ -0,0 +1,86 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public class Alert { + + private int alertId; + private AlertCategory alertCategory; + private AlertType alertType; + private AlertStatus alertStatus; + private int tbrAmount; + private int tbrDuration; + private double programmedBolusAmount; + private double deliveredBolusAmount; + private double cartridgeAmount; + + public int getAlertId() { + return this.alertId; + } + + public AlertCategory getAlertCategory() { + return this.alertCategory; + } + + public AlertType getAlertType() { + return this.alertType; + } + + public AlertStatus getAlertStatus() { + return this.alertStatus; + } + + public void setAlertId(int alertId) { + this.alertId = alertId; + } + + public void setAlertCategory(AlertCategory alertCategory) { + this.alertCategory = alertCategory; + } + + public void setAlertType(AlertType alertType) { + this.alertType = alertType; + } + + public void setAlertStatus(AlertStatus alertStatus) { + this.alertStatus = alertStatus; + } + + public int getTBRAmount() { + return tbrAmount; + } + + public void setTBRAmount(int tbrAmount) { + this.tbrAmount = tbrAmount; + } + + public int getTBRDuration() { + return tbrDuration; + } + + public void setTBRDuration(int tbrDuration) { + this.tbrDuration = tbrDuration; + } + + public double getProgrammedBolusAmount() { + return programmedBolusAmount; + } + + public void setProgrammedBolusAmount(double programmedBolusAmount) { + this.programmedBolusAmount = programmedBolusAmount; + } + + public double getDeliveredBolusAmount() { + return deliveredBolusAmount; + } + + public void setDeliveredBolusAmount(double deliveredBolusAmount) { + this.deliveredBolusAmount = deliveredBolusAmount; + } + + public void setCartridgeAmount(double cartridgeAmount) { + this.cartridgeAmount = cartridgeAmount; + } + + public double getCartridgeAmount() { + return cartridgeAmount; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/AlertCategory.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/AlertCategory.java new file mode 100644 index 0000000000..c2355f2b6a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/AlertCategory.java @@ -0,0 +1,9 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public enum AlertCategory { + + REMINDER, + MAINTENANCE, + WARNING, + ERROR; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/AlertStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/AlertStatus.java new file mode 100644 index 0000000000..b3842edfed --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/AlertStatus.java @@ -0,0 +1,7 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public enum AlertStatus { + + ACTIVE, + SNOOZED; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/AlertType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/AlertType.java new file mode 100644 index 0000000000..b2c8331a49 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/AlertType.java @@ -0,0 +1,31 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public enum AlertType { + + REMINDER_01, + REMINDER_02, + REMINDER_03, + REMINDER_04, + REMINDER_07, + WARNING_31, + WARNING_32, + WARNING_33, + WARNING_34, + WARNING_36, + WARNING_38, + WARNING_39, + MAINTENANCE_20, + MAINTENANCE_21, + MAINTENANCE_22, + MAINTENANCE_23, + MAINTENANCE_24, + MAINTENANCE_25, + MAINTENANCE_26, + MAINTENANCE_27, + MAINTENANCE_28, + MAINTENANCE_29, + MAINTENANCE_30, + ERROR_6, + ERROR_10, + ERROR_13; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/AvailableBolusTypes.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/AvailableBolusTypes.java new file mode 100644 index 0000000000..cbe6646212 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/AvailableBolusTypes.java @@ -0,0 +1,45 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public class AvailableBolusTypes { + + private boolean standardAvailable; + private boolean extendedAvailable; + private boolean multiwaveAvailable; + + public boolean isStandardAvailable() { + return this.standardAvailable; + } + + public void setStandardAvailable(boolean standardAvailable) { + this.standardAvailable = standardAvailable; + } + + public boolean isExtendedAvailable() { + return this.extendedAvailable; + } + + public void setExtendedAvailable(boolean extendedAvailable) { + this.extendedAvailable = extendedAvailable; + } + + public boolean isMultiwaveAvailable() { + return this.multiwaveAvailable; + } + + public void setMultiwaveAvailable(boolean multiwaveAvailable) { + this.multiwaveAvailable = multiwaveAvailable; + } + + public boolean isBolusTypeAvailable(BolusType bolusType) { + switch (bolusType) { + case STANDARD: + return standardAvailable; + case EXTENDED: + return extendedAvailable; + case MULTIWAVE: + return multiwaveAvailable; + default: + return false; + } + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/BasalProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/BasalProfile.java new file mode 100644 index 0000000000..89cc68cbd5 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/BasalProfile.java @@ -0,0 +1,10 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public enum BasalProfile { + + PROFILE_1, + PROFILE_2, + PROFILE_3, + PROFILE_4, + PROFILE_5; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/BasalProfileBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/BasalProfileBlock.java new file mode 100644 index 0000000000..bc70691d59 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/BasalProfileBlock.java @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public class BasalProfileBlock { + + private int duration; + private double basalAmount; + + public int getDuration() { + return this.duration; + } + + public double getBasalAmount() { + return this.basalAmount; + } + + public void setDuration(int duration) { + this.duration = duration; + } + + public void setBasalAmount(double basalAmount) { + this.basalAmount = basalAmount; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/BatteryStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/BatteryStatus.java new file mode 100644 index 0000000000..f8b33d287d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/BatteryStatus.java @@ -0,0 +1,32 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public class BatteryStatus { + + private BatteryType batteryType; + private int batteryAmount; + private SymbolStatus symbolStatus; + + public BatteryType getBatteryType() { + return this.batteryType; + } + + public int getBatteryAmount() { + return this.batteryAmount; + } + + public SymbolStatus getSymbolStatus() { + return this.symbolStatus; + } + + public void setBatteryType(BatteryType batteryType) { + this.batteryType = batteryType; + } + + public void setBatteryAmount(int batteryAmount) { + this.batteryAmount = batteryAmount; + } + + public void setSymbolStatus(SymbolStatus symbolStatus) { + this.symbolStatus = symbolStatus; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/BatteryType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/BatteryType.java new file mode 100644 index 0000000000..0cd5373c93 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/BatteryType.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public enum BatteryType { + + ALKALI, + LITHIUM, + NI_MH; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/BolusType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/BolusType.java new file mode 100644 index 0000000000..7af48fbfb7 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/BolusType.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public enum BolusType { + + STANDARD, + EXTENDED, + MULTIWAVE; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/CartridgeStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/CartridgeStatus.java new file mode 100644 index 0000000000..5c1edb031d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/CartridgeStatus.java @@ -0,0 +1,41 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public class CartridgeStatus { + + private boolean inserted; + private CartridgeType cartridgeType; + private SymbolStatus symbolStatus; + private double remainingAmount; + + public boolean isInserted() { + return this.inserted; + } + + public CartridgeType getCartridgeType() { + return this.cartridgeType; + } + + public SymbolStatus getSymbolStatus() { + return this.symbolStatus; + } + + public double getRemainingAmount() { + return this.remainingAmount; + } + + public void setInserted(boolean inserted) { + this.inserted = inserted; + } + + public void setCartridgeType(CartridgeType cartridgeType) { + this.cartridgeType = cartridgeType; + } + + public void setSymbolStatus(SymbolStatus symbolStatus) { + this.symbolStatus = symbolStatus; + } + + public void setRemainingAmount(double remainingAmount) { + this.remainingAmount = remainingAmount; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/CartridgeType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/CartridgeType.java new file mode 100644 index 0000000000..8c2f878387 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/CartridgeType.java @@ -0,0 +1,7 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public enum CartridgeType { + + PREFILLED, + SELF_FILLED; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/FirmwareVersions.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/FirmwareVersions.java new file mode 100644 index 0000000000..8930e47a4c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/FirmwareVersions.java @@ -0,0 +1,95 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public class FirmwareVersions { + + private String releaseSWVersion; + private String uiProcSWVersion; + private String pcProcSWVersion; + private String mdTelProcSWVersion; + private String btInfoPageVersion; + private String safetyProcSWVersion; + private int configIndex; + private int historyIndex; + private int stateIndex; + private int vocabularyIndex; + + public String getReleaseSWVersion() { + return this.releaseSWVersion; + } + + public String getUiProcSWVersion() { + return this.uiProcSWVersion; + } + + public String getPcProcSWVersion() { + return this.pcProcSWVersion; + } + + public String getMdTelProcSWVersion() { + return this.mdTelProcSWVersion; + } + + public String getBtInfoPageVersion() { + return this.btInfoPageVersion; + } + + public String getSafetyProcSWVersion() { + return this.safetyProcSWVersion; + } + + public int getConfigIndex() { + return this.configIndex; + } + + public int getHistoryIndex() { + return this.historyIndex; + } + + public int getStateIndex() { + return this.stateIndex; + } + + public int getVocabularyIndex() { + return this.vocabularyIndex; + } + + public void setReleaseSWVersion(String releaseSWVersion) { + this.releaseSWVersion = releaseSWVersion; + } + + public void setUiProcSWVersion(String uiProcSWVersion) { + this.uiProcSWVersion = uiProcSWVersion; + } + + public void setPcProcSWVersion(String pcProcSWVersion) { + this.pcProcSWVersion = pcProcSWVersion; + } + + public void setMdTelProcSWVersion(String mdTelProcSWVersion) { + this.mdTelProcSWVersion = mdTelProcSWVersion; + } + + public void setBtInfoPageVersion(String btInfoPageVersion) { + this.btInfoPageVersion = btInfoPageVersion; + } + + public void setSafetyProcSWVersion(String safetyProcSWVersion) { + this.safetyProcSWVersion = safetyProcSWVersion; + } + + public void setConfigIndex(int configIndex) { + this.configIndex = configIndex; + } + + public void setHistoryIndex(int historyIndex) { + this.historyIndex = historyIndex; + } + + public void setStateIndex(int stateIndex) { + this.stateIndex = stateIndex; + } + + public void setVocabularyIndex(int vocabularyIndex) { + this.vocabularyIndex = vocabularyIndex; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/InsightState.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/InsightState.java new file mode 100644 index 0000000000..2fe256663b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/InsightState.java @@ -0,0 +1,22 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public enum InsightState { + + NOT_PAIRED, + DISCONNECTED, + RECOVERING, + CONNECTING, + SATL_CONNECTION_REQUEST, + SATL_KEY_REQUEST, + SATL_VERIFY_DISPLAY_REQUEST, + AWAITING_CODE_CONFIRMATION, + SATL_VERIFY_CONFIRM_REQUEST, + SATL_SYN_REQUEST, + APP_CONNECT_MESSAGE, + APP_BIND_MESSAGE, + APP_ACTIVATE_STATUS_SERVICE, + APP_FIRMWARE_VERSIONS, + APP_ACTIVATE_PARAMETER_SERVICE, + APP_SYSTEM_IDENTIFICATION, + CONNECTED, +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/MessagePriority.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/MessagePriority.java new file mode 100644 index 0000000000..10a47283a3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/MessagePriority.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public enum MessagePriority { + + NORMAL, + HIGHER, + HIGHEST; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/OperatingMode.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/OperatingMode.java new file mode 100644 index 0000000000..d745394715 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/OperatingMode.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public enum OperatingMode { + + STARTED, + STOPPED, + PAUSED; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/PumpTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/PumpTime.java new file mode 100644 index 0000000000..9188e0d3c8 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/PumpTime.java @@ -0,0 +1,59 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public class PumpTime { + + private int year; + private int month; + private int day; + private int hour; + private int minute; + private int second; + + public int getYear() { + return this.year; + } + + public int getMonth() { + return this.month; + } + + public int getDay() { + return this.day; + } + + public int getHour() { + return this.hour; + } + + public int getMinute() { + return this.minute; + } + + public int getSecond() { + return this.second; + } + + public void setYear(int year) { + this.year = year; + } + + public void setMonth(int month) { + this.month = month; + } + + public void setDay(int day) { + this.day = day; + } + + public void setHour(int hour) { + this.hour = hour; + } + + public void setMinute(int minute) { + this.minute = minute; + } + + public void setSecond(int second) { + this.second = second; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/SymbolStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/SymbolStatus.java new file mode 100644 index 0000000000..567e6afb13 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/SymbolStatus.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public enum SymbolStatus { + + FULL, + LOW, + EMPTY; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/SystemIdentification.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/SystemIdentification.java new file mode 100644 index 0000000000..540052c0d5 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/SystemIdentification.java @@ -0,0 +1,32 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public class SystemIdentification { + + private String serialNumber; + private long systemIdAppendix; + private String manufacturingDate; + + public String getSerialNumber() { + return this.serialNumber; + } + + public long getSystemIdAppendix() { + return this.systemIdAppendix; + } + + public String getManufacturingDate() { + return this.manufacturingDate; + } + + public void setSerialNumber(String serialNumber) { + this.serialNumber = serialNumber; + } + + public void setSystemIdAppendix(long systemIdAppendix) { + this.systemIdAppendix = systemIdAppendix; + } + + public void setManufacturingDate(String manufacturingDate) { + this.manufacturingDate = manufacturingDate; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/TotalDailyDose.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/TotalDailyDose.java new file mode 100644 index 0000000000..7f197c8cb3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/descriptors/TotalDailyDose.java @@ -0,0 +1,32 @@ +package info.nightscout.androidaps.plugins.pump.insight.descriptors; + +public class TotalDailyDose { + + private double bolus; + private double basal; + private double bolusAndBasal; + + public double getBolus() { + return this.bolus; + } + + public double getBasal() { + return this.basal; + } + + public double getBolusAndBasal() { + return this.bolusAndBasal; + } + + public void setBolus(double bolus) { + this.bolus = bolus; + } + + public void setBasal(double basal) { + this.basal = basal; + } + + public void setBolusAndBasal(double bolusAndBasal) { + this.bolusAndBasal = bolusAndBasal; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/AppLayerException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/AppLayerException.java new file mode 100644 index 0000000000..aaf9dc695a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/AppLayerException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public abstract class AppLayerException extends InsightException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/CommandNotSupportedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/CommandNotSupportedException.java new file mode 100644 index 0000000000..fe950c8bac --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/CommandNotSupportedException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class CommandNotSupportedException extends InsightException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/ConnectionFailedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/ConnectionFailedException.java new file mode 100644 index 0000000000..524953f613 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/ConnectionFailedException.java @@ -0,0 +1,14 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class ConnectionFailedException extends InsightException { + + private long durationOfConnectionAttempt; + + public ConnectionFailedException(long durationOfConnectionAttempt) { + this.durationOfConnectionAttempt = durationOfConnectionAttempt; + } + + public long getDurationOfConnectionAttempt() { + return durationOfConnectionAttempt; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/ConnectionLostException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/ConnectionLostException.java new file mode 100644 index 0000000000..fc7b517d80 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/ConnectionLostException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class ConnectionLostException extends InsightException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/DisconnectedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/DisconnectedException.java new file mode 100644 index 0000000000..fe2fd75d81 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/DisconnectedException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class DisconnectedException extends InsightException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/IncompatibleAppVersionException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/IncompatibleAppVersionException.java new file mode 100644 index 0000000000..ce6b6edccb --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/IncompatibleAppVersionException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class IncompatibleAppVersionException extends AppLayerException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/IncompatibleSatlVersionException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/IncompatibleSatlVersionException.java new file mode 100644 index 0000000000..0a28aadb80 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/IncompatibleSatlVersionException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class IncompatibleSatlVersionException extends SatlException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InsightException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InsightException.java new file mode 100644 index 0000000000..4dc4161546 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InsightException.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public abstract class InsightException extends Exception { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidAppCRCException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidAppCRCException.java new file mode 100644 index 0000000000..643e9589f2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidAppCRCException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class InvalidAppCRCException extends AppLayerException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidMacTrailerException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidMacTrailerException.java new file mode 100644 index 0000000000..a3eda3700f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidMacTrailerException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class InvalidMacTrailerException extends SatlException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidNonceException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidNonceException.java new file mode 100644 index 0000000000..aedc99df1a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidNonceException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class InvalidNonceException extends SatlException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidPacketLengthsException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidPacketLengthsException.java new file mode 100644 index 0000000000..5a4373efbb --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidPacketLengthsException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class InvalidPacketLengthsException extends SatlException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidPreambleException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidPreambleException.java new file mode 100644 index 0000000000..7a5b4a1dd4 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidPreambleException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class InvalidPreambleException extends SatlException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidSatlCRCException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidSatlCRCException.java new file mode 100644 index 0000000000..ed6aa30d07 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidSatlCRCException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class InvalidSatlCRCException extends SatlException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidSatlCommandException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidSatlCommandException.java new file mode 100644 index 0000000000..ccaca09b29 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/InvalidSatlCommandException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class InvalidSatlCommandException extends SatlException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/ReceivedPacketInInvalidStateException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/ReceivedPacketInInvalidStateException.java new file mode 100644 index 0000000000..63b8c9019e --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/ReceivedPacketInInvalidStateException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class ReceivedPacketInInvalidStateException extends InsightException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/SatlException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/SatlException.java new file mode 100644 index 0000000000..736e4c1b22 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/SatlException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public abstract class SatlException extends InsightException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/SecondChannelFailedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/SecondChannelFailedException.java new file mode 100644 index 0000000000..f4eaa259f8 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/SecondChannelFailedException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class SecondChannelFailedException extends AppLayerException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/SocketCreationFailedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/SocketCreationFailedException.java new file mode 100644 index 0000000000..589a546a84 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/SocketCreationFailedException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class SocketCreationFailedException extends InsightException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/TimeoutException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/TimeoutException.java new file mode 100644 index 0000000000..f819bcdacb --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/TimeoutException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class TimeoutException extends InsightException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/TooChattyPumpException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/TooChattyPumpException.java new file mode 100644 index 0000000000..181d3112d1 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/TooChattyPumpException.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class TooChattyPumpException extends InsightException { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/UnknownAppCommandException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/UnknownAppCommandException.java new file mode 100644 index 0000000000..dbe39b56d2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/UnknownAppCommandException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class UnknownAppCommandException extends AppLayerException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/UnknownServiceException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/UnknownServiceException.java new file mode 100644 index 0000000000..b119e7b9ca --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/UnknownServiceException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions; + +public class UnknownServiceException extends AppLayerException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/AlreadyConnectedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/AlreadyConnectedException.java new file mode 100644 index 0000000000..65631f3154 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/AlreadyConnectedException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class AlreadyConnectedException extends AppLayerErrorException { + + public AlreadyConnectedException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/AppLayerErrorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/AppLayerErrorException.java new file mode 100644 index 0000000000..10d5bfea2c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/AppLayerErrorException.java @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +import info.nightscout.androidaps.plugins.pump.insight.exceptions.AppLayerException; + +public abstract class AppLayerErrorException extends AppLayerException { + + private int errorCode; + + public AppLayerErrorException(int errorCode) { + this.errorCode = errorCode; + } + + @Override + public String getMessage() { + return "Error code: " + errorCode; + } + + public int getErrorCode() { + return errorCode; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/BolusAmountNotInRangeException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/BolusAmountNotInRangeException.java new file mode 100644 index 0000000000..b87989d5f2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/BolusAmountNotInRangeException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class BolusAmountNotInRangeException extends AppLayerErrorException { + + public BolusAmountNotInRangeException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/BolusDurationNotInRangeException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/BolusDurationNotInRangeException.java new file mode 100644 index 0000000000..4b9eb1ebb1 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/BolusDurationNotInRangeException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class BolusDurationNotInRangeException extends AppLayerErrorException { + + public BolusDurationNotInRangeException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/BolusLagTimeFeatureDisabledException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/BolusLagTimeFeatureDisabledException.java new file mode 100644 index 0000000000..a7050d7c83 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/BolusLagTimeFeatureDisabledException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class BolusLagTimeFeatureDisabledException extends AppLayerErrorException { + + public BolusLagTimeFeatureDisabledException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/BolusTypeAndParameterMismatchException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/BolusTypeAndParameterMismatchException.java new file mode 100644 index 0000000000..8dbc6465b3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/BolusTypeAndParameterMismatchException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class BolusTypeAndParameterMismatchException extends AppLayerErrorException { + + public BolusTypeAndParameterMismatchException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/CommandExecutionFailedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/CommandExecutionFailedException.java new file mode 100644 index 0000000000..b7efb4998e --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/CommandExecutionFailedException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class CommandExecutionFailedException extends AppLayerErrorException { + + public CommandExecutionFailedException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ConfigMemoryAccessException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ConfigMemoryAccessException.java new file mode 100644 index 0000000000..b822fb0da4 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ConfigMemoryAccessException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class ConfigMemoryAccessException extends AppLayerErrorException { + + public ConfigMemoryAccessException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/CustomBolusNotConfiguredException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/CustomBolusNotConfiguredException.java new file mode 100644 index 0000000000..8aee22cb66 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/CustomBolusNotConfiguredException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class CustomBolusNotConfiguredException extends AppLayerErrorException { + + public CustomBolusNotConfiguredException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ImplausiblePortionLengthValueException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ImplausiblePortionLengthValueException.java new file mode 100644 index 0000000000..1d87fada0f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ImplausiblePortionLengthValueException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class ImplausiblePortionLengthValueException extends AppLayerErrorException { + + public ImplausiblePortionLengthValueException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/IncompatibleVersionException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/IncompatibleVersionException.java new file mode 100644 index 0000000000..0d596fc825 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/IncompatibleVersionException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class IncompatibleVersionException extends AppLayerErrorException { + + public IncompatibleVersionException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidAlertInstanceIdException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidAlertInstanceIdException.java new file mode 100644 index 0000000000..f35566eb54 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidAlertInstanceIdException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidAlertInstanceIdException extends AppLayerErrorException { + + public InvalidAlertInstanceIdException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidConfigBlockCRCException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidConfigBlockCRCException.java new file mode 100644 index 0000000000..07834a34bd --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidConfigBlockCRCException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidConfigBlockCRCException extends AppLayerErrorException { + + public InvalidConfigBlockCRCException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidConfigBlockIdException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidConfigBlockIdException.java new file mode 100644 index 0000000000..e6a3aff909 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidConfigBlockIdException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidConfigBlockIdException extends AppLayerErrorException { + + public InvalidConfigBlockIdException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidConfigBlockLengthException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidConfigBlockLengthException.java new file mode 100644 index 0000000000..90eb6556c5 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidConfigBlockLengthException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidConfigBlockLengthException extends AppLayerErrorException { + + public InvalidConfigBlockLengthException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidDateParameterException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidDateParameterException.java new file mode 100644 index 0000000000..a7770859e4 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidDateParameterException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidDateParameterException extends AppLayerErrorException { + + public InvalidDateParameterException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidDurationPresetException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidDurationPresetException.java new file mode 100644 index 0000000000..0bc787ec58 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidDurationPresetException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidDurationPresetException extends AppLayerErrorException { + + public InvalidDurationPresetException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidLagTimeException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidLagTimeException.java new file mode 100644 index 0000000000..2f14b1156d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidLagTimeException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidLagTimeException extends AppLayerErrorException { + + public InvalidLagTimeException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidParameterTypeException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidParameterTypeException.java new file mode 100644 index 0000000000..37bd17c41a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidParameterTypeException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidParameterTypeException extends AppLayerErrorException { + + public InvalidParameterTypeException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidPayloadCRCException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidPayloadCRCException.java new file mode 100644 index 0000000000..5e06eca9d5 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidPayloadCRCException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidPayloadCRCException extends AppLayerErrorException { + + public InvalidPayloadCRCException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidPayloadException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidPayloadException.java new file mode 100644 index 0000000000..ebb942dc73 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidPayloadException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidPayloadException extends AppLayerErrorException { + + public InvalidPayloadException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidPayloadLengthException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidPayloadLengthException.java new file mode 100644 index 0000000000..89b519c472 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidPayloadLengthException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidPayloadLengthException extends AppLayerErrorException { + + public InvalidPayloadLengthException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidServicePasswordException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidServicePasswordException.java new file mode 100644 index 0000000000..be8b41a188 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidServicePasswordException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidServicePasswordException extends AppLayerErrorException { + + public InvalidServicePasswordException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidTBRDurationException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidTBRDurationException.java new file mode 100644 index 0000000000..d5fa35e4fb --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidTBRDurationException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidTBRDurationException extends AppLayerErrorException { + + public InvalidTBRDurationException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidTBRFactorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidTBRFactorException.java new file mode 100644 index 0000000000..d27b0172b9 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidTBRFactorException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidTBRFactorException extends AppLayerErrorException { + + public InvalidTBRFactorException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidTBRTemplateException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidTBRTemplateException.java new file mode 100644 index 0000000000..d8f5c6f8d4 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidTBRTemplateException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidTBRTemplateException extends AppLayerErrorException { + + public InvalidTBRTemplateException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidTimeParameterException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidTimeParameterException.java new file mode 100644 index 0000000000..2170adc8af --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidTimeParameterException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidTimeParameterException extends AppLayerErrorException { + + public InvalidTimeParameterException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidValuesOfTwoChannelTransmission.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidValuesOfTwoChannelTransmission.java new file mode 100644 index 0000000000..8b51c6bf6e --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/InvalidValuesOfTwoChannelTransmission.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class InvalidValuesOfTwoChannelTransmission extends AppLayerErrorException { + + public InvalidValuesOfTwoChannelTransmission(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/MaximumNumberOfBolusTypeAlreadyRunningException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/MaximumNumberOfBolusTypeAlreadyRunningException.java new file mode 100644 index 0000000000..917b715a05 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/MaximumNumberOfBolusTypeAlreadyRunningException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class MaximumNumberOfBolusTypeAlreadyRunningException extends AppLayerErrorException { + + public MaximumNumberOfBolusTypeAlreadyRunningException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NoActiveTBRToCanceLException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NoActiveTBRToCanceLException.java new file mode 100644 index 0000000000..178a551896 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NoActiveTBRToCanceLException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class NoActiveTBRToCanceLException extends AppLayerErrorException { + + public NoActiveTBRToCanceLException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NoActiveTBRToChangeException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NoActiveTBRToChangeException.java new file mode 100644 index 0000000000..63811f59e2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NoActiveTBRToChangeException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class NoActiveTBRToChangeException extends AppLayerErrorException { + + public NoActiveTBRToChangeException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NoConfigBlockDataException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NoConfigBlockDataException.java new file mode 100644 index 0000000000..1a3b1dfc3b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NoConfigBlockDataException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class NoConfigBlockDataException extends AppLayerErrorException { + + public NoConfigBlockDataException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NoServicePasswordNeededException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NoServicePasswordNeededException.java new file mode 100644 index 0000000000..72f4d4bd89 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NoServicePasswordNeededException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class NoServicePasswordNeededException extends AppLayerErrorException { + + public NoServicePasswordNeededException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NoSuchBolusToCancelException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NoSuchBolusToCancelException.java new file mode 100644 index 0000000000..d3532d0dde --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NoSuchBolusToCancelException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class NoSuchBolusToCancelException extends AppLayerErrorException { + + public NoSuchBolusToCancelException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NotAllowedToAccessPositionZeroException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NotAllowedToAccessPositionZeroException.java new file mode 100644 index 0000000000..758d80d216 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NotAllowedToAccessPositionZeroException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class NotAllowedToAccessPositionZeroException extends AppLayerErrorException { + + public NotAllowedToAccessPositionZeroException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NotConnectedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NotConnectedException.java new file mode 100644 index 0000000000..a0b47aa4da --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NotConnectedException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class NotConnectedException extends AppLayerErrorException { + + public NotConnectedException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NotReferencedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NotReferencedException.java new file mode 100644 index 0000000000..f2469d1ffe --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/NotReferencedException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class NotReferencedException extends AppLayerErrorException { + + public NotReferencedException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/PauseModeNotAllowedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/PauseModeNotAllowedException.java new file mode 100644 index 0000000000..6da528ac27 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/PauseModeNotAllowedException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class PauseModeNotAllowedException extends AppLayerErrorException { + + public PauseModeNotAllowedException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/PositionProtectedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/PositionProtectedException.java new file mode 100644 index 0000000000..7670eb6fb8 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/PositionProtectedException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class PositionProtectedException extends AppLayerErrorException { + + public PositionProtectedException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/PumpAlreadyInThatStateException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/PumpAlreadyInThatStateException.java new file mode 100644 index 0000000000..574efb065b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/PumpAlreadyInThatStateException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class PumpAlreadyInThatStateException extends AppLayerErrorException { + + public PumpAlreadyInThatStateException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/PumpBusyException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/PumpBusyException.java new file mode 100644 index 0000000000..4d7fe90b43 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/PumpBusyException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class PumpBusyException extends AppLayerErrorException { + + public PumpBusyException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/PumpStoppedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/PumpStoppedException.java new file mode 100644 index 0000000000..31aae38bb0 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/PumpStoppedException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class PumpStoppedException extends AppLayerErrorException { + + public PumpStoppedException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ReadingHistoryAlreadyStartedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ReadingHistoryAlreadyStartedException.java new file mode 100644 index 0000000000..9091c8b999 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ReadingHistoryAlreadyStartedException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class ReadingHistoryAlreadyStartedException extends AppLayerErrorException { + + public ReadingHistoryAlreadyStartedException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ReadingHistoryNotStartedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ReadingHistoryNotStartedException.java new file mode 100644 index 0000000000..2a37f62b39 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ReadingHistoryNotStartedException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class ReadingHistoryNotStartedException extends AppLayerErrorException { + + public ReadingHistoryNotStartedException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/RunModeNotAllowedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/RunModeNotAllowedException.java new file mode 100644 index 0000000000..262e41ae21 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/RunModeNotAllowedException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class RunModeNotAllowedException extends AppLayerErrorException { + + public RunModeNotAllowedException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ServiceAlreadyActivatedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ServiceAlreadyActivatedException.java new file mode 100644 index 0000000000..4865697483 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ServiceAlreadyActivatedException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class ServiceAlreadyActivatedException extends AppLayerErrorException { + + public ServiceAlreadyActivatedException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ServiceCommandNotAvailableException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ServiceCommandNotAvailableException.java new file mode 100644 index 0000000000..7341cc67a9 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ServiceCommandNotAvailableException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class ServiceCommandNotAvailableException extends AppLayerErrorException { + + public ServiceCommandNotAvailableException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ServiceIncompatibleException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ServiceIncompatibleException.java new file mode 100644 index 0000000000..4c3fc8b1dc --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ServiceIncompatibleException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class ServiceIncompatibleException extends AppLayerErrorException { + + public ServiceIncompatibleException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ServiceNotActivatedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ServiceNotActivatedException.java new file mode 100644 index 0000000000..55329a2a5b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/ServiceNotActivatedException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class ServiceNotActivatedException extends AppLayerErrorException { + + public ServiceNotActivatedException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/StepCountOutOfRangeException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/StepCountOutOfRangeException.java new file mode 100644 index 0000000000..cb1a04fe74 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/StepCountOutOfRangeException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class StepCountOutOfRangeException extends AppLayerErrorException { + + public StepCountOutOfRangeException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/UnknownAppLayerErrorCodeException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/UnknownAppLayerErrorCodeException.java new file mode 100644 index 0000000000..4c08240102 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/UnknownAppLayerErrorCodeException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class UnknownAppLayerErrorCodeException extends AppLayerErrorException { + + public UnknownAppLayerErrorCodeException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/UnknownCommandException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/UnknownCommandException.java new file mode 100644 index 0000000000..edf06628dd --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/UnknownCommandException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class UnknownCommandException extends AppLayerErrorException { + + public UnknownCommandException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/UnknownServiceException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/UnknownServiceException.java new file mode 100644 index 0000000000..2992372e18 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/UnknownServiceException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class UnknownServiceException extends AppLayerErrorException { + + public UnknownServiceException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/WriteSessionAlreadyOpenException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/WriteSessionAlreadyOpenException.java new file mode 100644 index 0000000000..b4001d2f06 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/WriteSessionAlreadyOpenException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class WriteSessionAlreadyOpenException extends AppLayerErrorException { + + public WriteSessionAlreadyOpenException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/WriteSessionClosedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/WriteSessionClosedException.java new file mode 100644 index 0000000000..966afecb68 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/WriteSessionClosedException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class WriteSessionClosedException extends AppLayerErrorException { + + public WriteSessionClosedException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/WrongStateException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/WrongStateException.java new file mode 100644 index 0000000000..b4cc3af99e --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/app_layer_errors/WrongStateException.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors; + +public class WrongStateException extends AppLayerErrorException { + + public WrongStateException(int errorCode) { + super(errorCode); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlCompatibleStateErrorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlCompatibleStateErrorException.java new file mode 100644 index 0000000000..fde27a8f5f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlCompatibleStateErrorException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors; + +public class SatlCompatibleStateErrorException extends SatlErrorException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlDecryptVerifyFailedErrorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlDecryptVerifyFailedErrorException.java new file mode 100644 index 0000000000..74a68dc2ce --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlDecryptVerifyFailedErrorException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors; + +public class SatlDecryptVerifyFailedErrorException extends SatlErrorException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlErrorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlErrorException.java new file mode 100644 index 0000000000..26dc0e2719 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlErrorException.java @@ -0,0 +1,7 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors; + +import info.nightscout.androidaps.plugins.pump.insight.exceptions.InsightException; + +public abstract class SatlErrorException extends InsightException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlIncompatibleVersionErrorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlIncompatibleVersionErrorException.java new file mode 100644 index 0000000000..df152adf83 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlIncompatibleVersionErrorException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors; + +public class SatlIncompatibleVersionErrorException extends SatlErrorException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidCRCErrorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidCRCErrorException.java new file mode 100644 index 0000000000..2156bc48a0 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidCRCErrorException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors; + +public class SatlInvalidCRCErrorException extends SatlErrorException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidCommIdErrorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidCommIdErrorException.java new file mode 100644 index 0000000000..12e9ca7bb4 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidCommIdErrorException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors; + +public class SatlInvalidCommIdErrorException extends SatlErrorException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidMacErrorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidMacErrorException.java new file mode 100644 index 0000000000..75f547ef15 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidMacErrorException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors; + +public class SatlInvalidMacErrorException extends SatlErrorException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidMessageTypeErrorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidMessageTypeErrorException.java new file mode 100644 index 0000000000..6551a28c8f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidMessageTypeErrorException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors; + +public class SatlInvalidMessageTypeErrorException extends SatlErrorException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidNonceErrorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidNonceErrorException.java new file mode 100644 index 0000000000..8f9304c3c0 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidNonceErrorException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors; + +public class SatlInvalidNonceErrorException extends SatlErrorException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidPacketErrorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidPacketErrorException.java new file mode 100644 index 0000000000..ed3f50e98b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidPacketErrorException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors; + +public class SatlInvalidPacketErrorException extends SatlErrorException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidPayloadLengthErrorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidPayloadLengthErrorException.java new file mode 100644 index 0000000000..69646f265c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlInvalidPayloadLengthErrorException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors; + +public class SatlInvalidPayloadLengthErrorException extends SatlErrorException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlNoneErrorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlNoneErrorException.java new file mode 100644 index 0000000000..febe6a8ced --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlNoneErrorException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors; + +public class SatlNoneErrorException extends SatlErrorException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlPairingRejectedException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlPairingRejectedException.java new file mode 100644 index 0000000000..479efd150d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlPairingRejectedException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors; + +public class SatlPairingRejectedException extends SatlErrorException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlUndefinedErrorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlUndefinedErrorException.java new file mode 100644 index 0000000000..f655c8668d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlUndefinedErrorException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors; + +public class SatlUndefinedErrorException extends SatlErrorException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlWrongStateException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlWrongStateException.java new file mode 100644 index 0000000000..aa50c46ec9 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/exceptions/satl_errors/SatlWrongStateException.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors; + +public class SatlWrongStateException extends SatlErrorException { + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/ActiveBasalProfileIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/ActiveBasalProfileIDs.java new file mode 100644 index 0000000000..9d5a6e1f85 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/ActiveBasalProfileIDs.java @@ -0,0 +1,18 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.BasalProfile; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class ActiveBasalProfileIDs { + + public static final IDStorage IDS = new IDStorage<>(); + + static { + IDS.put(BasalProfile.PROFILE_1, 31); + IDS.put(BasalProfile.PROFILE_2, 227); + IDS.put(BasalProfile.PROFILE_3, 252); + IDS.put(BasalProfile.PROFILE_4, 805); + IDS.put(BasalProfile.PROFILE_5, 826); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/ActiveBolusTypeIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/ActiveBolusTypeIDs.java new file mode 100644 index 0000000000..f04e7ddbbc --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/ActiveBolusTypeIDs.java @@ -0,0 +1,16 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.BolusType; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class ActiveBolusTypeIDs { + + public static final IDStorage IDS = new IDStorage<>(); + + static { + IDS.put(BolusType.STANDARD, 227); + IDS.put(BolusType.EXTENDED, 252); + IDS.put(BolusType.MULTIWAVE, 805); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AlertCategoryIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AlertCategoryIDs.java new file mode 100644 index 0000000000..59a02b36d3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AlertCategoryIDs.java @@ -0,0 +1,17 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertCategory; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class AlertCategoryIDs { + + public static final IDStorage IDS = new IDStorage<>(); + + static { + IDS.put(AlertCategory.REMINDER, 227); + IDS.put(AlertCategory.MAINTENANCE, 252); + IDS.put(AlertCategory.WARNING, 805); + IDS.put(AlertCategory.ERROR, 826); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AlertStatusIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AlertStatusIDs.java new file mode 100644 index 0000000000..b249dfded2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AlertStatusIDs.java @@ -0,0 +1,15 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertStatus; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class AlertStatusIDs { + + public static final IDStorage IDS = new IDStorage<>(); + + static { + IDS.put(AlertStatus.ACTIVE, 31); + IDS.put(AlertStatus.SNOOZED, 227); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AlertTypeIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AlertTypeIDs.java new file mode 100644 index 0000000000..0688fb6cf2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AlertTypeIDs.java @@ -0,0 +1,39 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertType; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class AlertTypeIDs { + + public static final IDStorage IDS = new IDStorage<>(); + + static { + IDS.put(AlertType.REMINDER_01, 31); + IDS.put(AlertType.REMINDER_02, 227); + IDS.put(AlertType.REMINDER_03, 252); + IDS.put(AlertType.REMINDER_04, 805); + IDS.put(AlertType.REMINDER_07, 826); + IDS.put(AlertType.WARNING_31, 966); + IDS.put(AlertType.WARNING_32, 985); + IDS.put(AlertType.WARNING_33, 1354); + IDS.put(AlertType.WARNING_34, 1365); + IDS.put(AlertType.WARNING_36, 1449); + IDS.put(AlertType.WARNING_38, 1462); + IDS.put(AlertType.WARNING_39, 1647); + IDS.put(AlertType.MAINTENANCE_20, 1648); + IDS.put(AlertType.MAINTENANCE_21, 1676); + IDS.put(AlertType.MAINTENANCE_22, 1683); + IDS.put(AlertType.MAINTENANCE_23, 6182); + IDS.put(AlertType.MAINTENANCE_24, 6201); + IDS.put(AlertType.MAINTENANCE_25, 6341); + IDS.put(AlertType.MAINTENANCE_26, 6362); + IDS.put(AlertType.MAINTENANCE_27, 6915); + IDS.put(AlertType.MAINTENANCE_28, 6940); + IDS.put(AlertType.MAINTENANCE_29, 7136); + IDS.put(AlertType.MAINTENANCE_30, 7167); + IDS.put(AlertType.ERROR_6, 7532); + IDS.put(AlertType.ERROR_10, 7539); + IDS.put(AlertType.ERROR_13, 7567); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AlertTypeIncrementalIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AlertTypeIncrementalIDs.java new file mode 100644 index 0000000000..340648b8c7 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AlertTypeIncrementalIDs.java @@ -0,0 +1,39 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertType; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class AlertTypeIncrementalIDs { + + public static final IDStorage IDS = new IDStorage<>(); + + static { + IDS.put(AlertType.REMINDER_01, 1); + IDS.put(AlertType.REMINDER_02, 2); + IDS.put(AlertType.REMINDER_03, 3); + IDS.put(AlertType.REMINDER_04, 4); + IDS.put(AlertType.REMINDER_07, 7); + IDS.put(AlertType.WARNING_31, 31); + IDS.put(AlertType.WARNING_32, 32); + IDS.put(AlertType.WARNING_33, 33); + IDS.put(AlertType.WARNING_34, 34); + IDS.put(AlertType.WARNING_36, 36); + IDS.put(AlertType.WARNING_38, 38); + IDS.put(AlertType.WARNING_39, 39); + IDS.put(AlertType.MAINTENANCE_20, 20); + IDS.put(AlertType.MAINTENANCE_21, 21); + IDS.put(AlertType.MAINTENANCE_22, 22); + IDS.put(AlertType.MAINTENANCE_23, 23); + IDS.put(AlertType.MAINTENANCE_24, 24); + IDS.put(AlertType.MAINTENANCE_25, 25); + IDS.put(AlertType.MAINTENANCE_26, 26); + IDS.put(AlertType.MAINTENANCE_27, 27); + IDS.put(AlertType.MAINTENANCE_28, 28); + IDS.put(AlertType.MAINTENANCE_29, 29); + IDS.put(AlertType.MAINTENANCE_30, 30); + IDS.put(AlertType.ERROR_6, 6); + IDS.put(AlertType.ERROR_10, 10); + IDS.put(AlertType.ERROR_13, 13); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AppCommandIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AppCommandIDs.java new file mode 100644 index 0000000000..da52987a1f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AppCommandIDs.java @@ -0,0 +1,81 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.SetDateTimeMessage; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.ReadParameterBlockMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration.CloseConfigurationWriteSessionMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration.OpenConfigurationWriteSessionMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration.WriteConfigurationBlockMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.connection.ActivateServiceMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.connection.BindMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.connection.ConnectMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.connection.DisconnectMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.connection.ServiceChallengeMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.ReadHistoryEventsMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.StartReadingHistoryMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.StopReadingHistoryMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.CancelBolusMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.CancelTBRMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.ChangeTBRMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.ConfirmAlertMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.DeliverBolusMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.GetAvailableBolusTypesMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.SetOperatingModeMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.SetTBRMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.SnoozeAlertMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetActiveAlertMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetActiveBasalRateMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetActiveBolusesMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetActiveTBRMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetBatteryStatusMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetCartridgeStatusMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetDateTimeMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetFirmwareVersionsMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetOperatingModeMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetPumpStatusRegisterMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetTotalDailyDoseMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.ResetPumpStatusRegisterMessage; + +public class AppCommandIDs { + + public static final IDStorage, Integer> IDS = new IDStorage<>(); + + static { + IDS.put(ConnectMessage.class, 61451); + IDS.put(BindMessage.class, 62413); + IDS.put(DisconnectMessage.class, 61460); + IDS.put(ActivateServiceMessage.class, 61687); + IDS.put(ServiceChallengeMessage.class, 62418); + IDS.put(GetActiveAlertMessage.class, 985); + IDS.put(GetActiveBolusesMessage.class, 1647); + IDS.put(GetActiveTBRMessage.class, 1462); + IDS.put(GetAvailableBolusTypesMessage.class, 6362); + IDS.put(GetBatteryStatusMessage.class, 805); + IDS.put(GetCartridgeStatusMessage.class, 826); + IDS.put(GetDateTimeMessage.class, 227); + IDS.put(GetFirmwareVersionsMessage.class, 11992); + IDS.put(GetOperatingModeMessage.class, 252); + IDS.put(GetPumpStatusRegisterMessage.class, 31); + IDS.put(ResetPumpStatusRegisterMessage.class, 35476); + IDS.put(GetActiveBasalRateMessage.class, 1449); + IDS.put(GetTotalDailyDoseMessage.class, 966); + IDS.put(CancelTBRMessage.class, 6201); + IDS.put(CancelBolusMessage.class, 7136); + IDS.put(SetOperatingModeMessage.class, 6182); + IDS.put(ReadParameterBlockMessage.class, 7766); + IDS.put(WriteConfigurationBlockMessage.class, 7850); + IDS.put(CloseConfigurationWriteSessionMessage.class, 7861); + IDS.put(OpenConfigurationWriteSessionMessage.class, 7753); + IDS.put(DeliverBolusMessage.class, 6915); + IDS.put(SetTBRMessage.class, 6341); + IDS.put(ChangeTBRMessage.class, 42067); + IDS.put(ReadHistoryEventsMessage.class, 10408); + IDS.put(StartReadingHistoryMessage.class, 10324); + IDS.put(StopReadingHistoryMessage.class, 38887); + IDS.put(ConfirmAlertMessage.class, 1683); + IDS.put(SnoozeAlertMessage.class, 1676); + IDS.put(SetDateTimeMessage.class, 7167); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AppErrorIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AppErrorIDs.java new file mode 100644 index 0000000000..a06a18c56d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/AppErrorIDs.java @@ -0,0 +1,121 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.AlreadyConnectedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.AppLayerErrorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.BolusAmountNotInRangeException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.BolusDurationNotInRangeException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.BolusLagTimeFeatureDisabledException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.BolusTypeAndParameterMismatchException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.CommandExecutionFailedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.ConfigMemoryAccessException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.CustomBolusNotConfiguredException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.ImplausiblePortionLengthValueException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.IncompatibleVersionException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidAlertInstanceIdException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidConfigBlockCRCException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidConfigBlockIdException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidConfigBlockLengthException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidDateParameterException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidDurationPresetException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidLagTimeException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidParameterTypeException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidPayloadCRCException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidPayloadException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidPayloadLengthException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidServicePasswordException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidTBRDurationException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidTBRFactorException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidTBRTemplateException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidTimeParameterException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.InvalidValuesOfTwoChannelTransmission; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.MaximumNumberOfBolusTypeAlreadyRunningException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NoActiveTBRToCanceLException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NoActiveTBRToChangeException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NoConfigBlockDataException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NoServicePasswordNeededException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NoSuchBolusToCancelException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NotAllowedToAccessPositionZeroException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NotConnectedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NotReferencedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.PauseModeNotAllowedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.PositionProtectedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.PumpAlreadyInThatStateException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.PumpBusyException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.PumpStoppedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.ReadingHistoryAlreadyStartedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.ReadingHistoryNotStartedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.RunModeNotAllowedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.ServiceAlreadyActivatedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.ServiceCommandNotAvailableException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.ServiceIncompatibleException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.ServiceNotActivatedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.StepCountOutOfRangeException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.UnknownCommandException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.UnknownServiceException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.WriteSessionAlreadyOpenException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.WriteSessionClosedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.WrongStateException; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class AppErrorIDs { + + public static final IDStorage, Integer> IDS = new IDStorage<>(); + + static { + IDS.put(PumpStoppedException.class, 3178); + IDS.put(BolusAmountNotInRangeException.class, 6017); + IDS.put(PumpAlreadyInThatStateException.class, 3324); + IDS.put(InvalidServicePasswordException.class, 61593); + IDS.put(UnknownCommandException.class, 61455); + IDS.put(AlreadyConnectedException.class, 61530); + IDS.put(WrongStateException.class, 61680); + IDS.put(ServiceIncompatibleException.class, 61542); + IDS.put(UnknownServiceException.class, 61545); + IDS.put(NoServicePasswordNeededException.class, 61695); + IDS.put(ServiceAlreadyActivatedException.class, 61644); + IDS.put(IncompatibleVersionException.class, 61491); + IDS.put(InvalidPayloadLengthException.class, 61500); + IDS.put(NotConnectedException.class, 61525); + IDS.put(ServiceCommandNotAvailableException.class, 61605); + IDS.put(ServiceNotActivatedException.class, 61610); + IDS.put(PumpBusyException.class, 61635); + IDS.put(NotReferencedException.class, 5335); + IDS.put(StepCountOutOfRangeException.class, 5348); + IDS.put(InvalidPayloadCRCException.class, 2805); + IDS.put(InvalidParameterTypeException.class, 2810); + IDS.put(CommandExecutionFailedException.class, 22796); + IDS.put(InvalidAlertInstanceIdException.class, 3238); + IDS.put(InvalidTBRFactorException.class, 3241); + IDS.put(InvalidTBRDurationException.class, 3264); + IDS.put(InvalidTBRTemplateException.class, 6363); + IDS.put(PauseModeNotAllowedException.class, 3315); + IDS.put(RunModeNotAllowedException.class, 3279); + IDS.put(NoActiveTBRToCanceLException.class, 3840); + IDS.put(BolusTypeAndParameterMismatchException.class, 3925); + IDS.put(InvalidDurationPresetException.class, 5924); + IDS.put(BolusLagTimeFeatureDisabledException.class, 90); + IDS.put(BolusDurationNotInRangeException.class, 6014); + IDS.put(InvalidValuesOfTwoChannelTransmission.class, 0x0F96); + IDS.put(NoSuchBolusToCancelException.class, 4005); + IDS.put(MaximumNumberOfBolusTypeAlreadyRunningException.class, 4010); + IDS.put(CustomBolusNotConfiguredException.class, 6270); + IDS.put(InvalidDateParameterException.class, 4044); + IDS.put(InvalidTimeParameterException.class, 4080); + IDS.put(NoConfigBlockDataException.class, 4471); + IDS.put(InvalidConfigBlockIdException.class, 4472); + IDS.put(InvalidConfigBlockCRCException.class, 4487); + IDS.put(InvalidConfigBlockLengthException.class, 6286); + IDS.put(WriteSessionAlreadyOpenException.class, 4539); + IDS.put(WriteSessionClosedException.class, 4562); + IDS.put(ConfigMemoryAccessException.class, 4573); + IDS.put(ReadingHistoryAlreadyStartedException.class, 11794); + IDS.put(ReadingHistoryNotStartedException.class, 4680); + IDS.put(InvalidPayloadException.class, 6210); + IDS.put(ImplausiblePortionLengthValueException.class, 4824); + IDS.put(NotAllowedToAccessPositionZeroException.class, 4830); + IDS.put(PositionProtectedException.class, 4845); + IDS.put(InvalidLagTimeException.class, 3891); + IDS.put(NoActiveTBRToChangeException.class, 6322); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/BatteryTypeIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/BatteryTypeIDs.java new file mode 100644 index 0000000000..9485da4a55 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/BatteryTypeIDs.java @@ -0,0 +1,16 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.BatteryType; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class BatteryTypeIDs { + + public static final IDStorage IDS = new IDStorage<>(); + + static { + IDS.put(BatteryType.ALKALI, 31); + IDS.put(BatteryType.LITHIUM, 227); + IDS.put(BatteryType.NI_MH, 252); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/BolusTypeIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/BolusTypeIDs.java new file mode 100644 index 0000000000..6917f82e9f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/BolusTypeIDs.java @@ -0,0 +1,16 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.BolusType; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class BolusTypeIDs { + + public static final IDStorage IDS = new IDStorage<>(); + + static { + IDS.put(BolusType.STANDARD, 31); + IDS.put(BolusType.EXTENDED, 227); + IDS.put(BolusType.MULTIWAVE, 252); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/CartridgeTypeIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/CartridgeTypeIDs.java new file mode 100644 index 0000000000..9d48d8cdb2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/CartridgeTypeIDs.java @@ -0,0 +1,15 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.CartridgeType; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class CartridgeTypeIDs { + + public static final IDStorage IDS = new IDStorage<>(); + + static { + IDS.put(CartridgeType.PREFILLED, 31); + IDS.put(CartridgeType.SELF_FILLED, 227); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/HistoryEventIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/HistoryEventIDs.java new file mode 100644 index 0000000000..407f132aa1 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/HistoryEventIDs.java @@ -0,0 +1,51 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.BasalDeliveryChangedEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.BolusDeliveredEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.BolusProgrammedEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.CannulaFilledEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.CartridgeInsertedEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.CartridgeRemovedEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.DateTimeChangedEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.DefaultDateTimeSetEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.EndOfTBREvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.HistoryEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.OccurrenceOfErrorEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.OccurrenceOfMaintenanceEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.OccurrenceOfWarningEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.OperatingModeChangedEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.PowerDownEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.PowerUpEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.SniffingDoneEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.StartOfTBREvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.TotalDailyDoseEvent; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.TubeFilledEvent; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class HistoryEventIDs { + + public static final IDStorage, Integer> IDS = new IDStorage<>(); + + static { + IDS.put(BolusDeliveredEvent.class, 917); + IDS.put(BolusProgrammedEvent.class, 874); + IDS.put(CannulaFilledEvent.class, 3264); + IDS.put(DateTimeChangedEvent.class, 165); + IDS.put(DefaultDateTimeSetEvent.class, 170); + IDS.put(EndOfTBREvent.class, 771); + IDS.put(OccurrenceOfErrorEvent.class, 1011); + IDS.put(OccurrenceOfMaintenanceEvent.class, 1290); + IDS.put(OccurrenceOfWarningEvent.class, 1360); + IDS.put(OperatingModeChangedEvent.class, 195); + IDS.put(PowerUpEvent.class, 15); + IDS.put(PowerDownEvent.class, 51); + IDS.put(SniffingDoneEvent.class, 102); + IDS.put(StartOfTBREvent.class, 240); + IDS.put(TotalDailyDoseEvent.class, 960); + IDS.put(TubeFilledEvent.class, 105); + IDS.put(CartridgeInsertedEvent.class, 60); + IDS.put(CartridgeRemovedEvent.class, 85); + IDS.put(BasalDeliveryChangedEvent.class, 204); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/HistoryReadingDirectionIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/HistoryReadingDirectionIDs.java new file mode 100644 index 0000000000..f8b068d9af --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/HistoryReadingDirectionIDs.java @@ -0,0 +1,15 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.HistoryReadingDirection; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class HistoryReadingDirectionIDs { + + public static final IDStorage IDS = new IDStorage<>(); + + static { + IDS.put(HistoryReadingDirection.FORWARD, 31); + IDS.put(HistoryReadingDirection.BACKWARD, 227); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/OperatingModeIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/OperatingModeIDs.java new file mode 100644 index 0000000000..faf86d80d9 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/OperatingModeIDs.java @@ -0,0 +1,16 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.OperatingMode; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class OperatingModeIDs { + + public static final IDStorage IDS = new IDStorage<>(); + + static { + IDS.put(OperatingMode.STOPPED, 31); + IDS.put(OperatingMode.STARTED, 227); + IDS.put(OperatingMode.PAUSED, 252); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/PairingStatusIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/PairingStatusIDs.java new file mode 100644 index 0000000000..8325446e7d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/PairingStatusIDs.java @@ -0,0 +1,16 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.satl.PairingStatus; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class PairingStatusIDs { + + public static final IDStorage IDS = new IDStorage<>(); + + static { + IDS.put(PairingStatus.PENDING, 1683); + IDS.put(PairingStatus.REJECTED, 7850); + IDS.put(PairingStatus.CONFIRMED, 11835); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/ParameterBlockIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/ParameterBlockIDs.java new file mode 100644 index 0000000000..36813756f9 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/ParameterBlockIDs.java @@ -0,0 +1,51 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.FactoryMaxBasalAmountBlock; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.FactoryMinBasalAmountBlock; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.MaxBasalAmountBlock; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.ParameterBlock; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.TBROverNotificationBlock; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.ActiveBRProfileBlock; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.BRProfile1Block; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.BRProfile1NameBlock; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.BRProfile2Block; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.BRProfile2NameBlock; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.BRProfile3Block; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.BRProfile3NameBlock; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.BRProfile4Block; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.BRProfile4NameBlock; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.BRProfile5Block; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.BRProfile5NameBlock; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.FactoryMaxBolusAmountBlock; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.FactoryMinBolusAmountBlock; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.MaxBolusAmountBlock; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.SystemIdentificationBlock; + +public class ParameterBlockIDs { + + public static final IDStorage, Integer> IDS = new IDStorage<>(); + + static { + IDS.put(FactoryMaxBolusAmountBlock.class, 41222); + IDS.put(MaxBolusAmountBlock.class, 31); + IDS.put(FactoryMinBolusAmountBlock.class, 60183); + IDS.put(SystemIdentificationBlock.class, 35476); + IDS.put(BRProfile1Block.class, 7136); + IDS.put(BRProfile2Block.class, 7167); + IDS.put(BRProfile3Block.class, 7532); + IDS.put(BRProfile4Block.class, 7539); + IDS.put(BRProfile5Block.class, 7567); + IDS.put(BRProfile1NameBlock.class, 48265); + IDS.put(BRProfile2NameBlock.class, 48278); + IDS.put(BRProfile3NameBlock.class, 48975); + IDS.put(BRProfile4NameBlock.class, 48976); + IDS.put(BRProfile5NameBlock.class, 49068); + IDS.put(ActiveBRProfileBlock.class, 7568); + IDS.put(MaxBasalAmountBlock.class, 6940); + IDS.put(FactoryMinBasalAmountBlock.class, 60395); + IDS.put(FactoryMaxBasalAmountBlock.class, 41241); + IDS.put(TBROverNotificationBlock.class, 25814); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/SatlCommandIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/SatlCommandIDs.java new file mode 100644 index 0000000000..2423118507 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/SatlCommandIDs.java @@ -0,0 +1,39 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.satl.SatlMessage; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; +import info.nightscout.androidaps.plugins.pump.insight.satl.ConnectionRequest; +import info.nightscout.androidaps.plugins.pump.insight.satl.ConnectionResponse; +import info.nightscout.androidaps.plugins.pump.insight.satl.DataMessage; +import info.nightscout.androidaps.plugins.pump.insight.satl.DisconnectMessage; +import info.nightscout.androidaps.plugins.pump.insight.satl.ErrorMessage; +import info.nightscout.androidaps.plugins.pump.insight.satl.KeyRequest; +import info.nightscout.androidaps.plugins.pump.insight.satl.KeyResponse; +import info.nightscout.androidaps.plugins.pump.insight.satl.SynAckResponse; +import info.nightscout.androidaps.plugins.pump.insight.satl.SynRequest; +import info.nightscout.androidaps.plugins.pump.insight.satl.VerifyConfirmRequest; +import info.nightscout.androidaps.plugins.pump.insight.satl.VerifyConfirmResponse; +import info.nightscout.androidaps.plugins.pump.insight.satl.VerifyDisplayRequest; +import info.nightscout.androidaps.plugins.pump.insight.satl.VerifyDisplayResponse; + +public class SatlCommandIDs { + + public static final IDStorage, Byte> IDS = new IDStorage<>(); + + static { + IDS.put(DataMessage.class, (byte) 3); + IDS.put(ErrorMessage.class, (byte) 6); + IDS.put(ConnectionRequest.class, (byte) 9); + IDS.put(ConnectionResponse.class, (byte) 10); + IDS.put(KeyRequest.class, (byte) 12); + IDS.put(VerifyConfirmRequest.class, (byte) 14); + IDS.put(KeyResponse.class, (byte) 17); + IDS.put(VerifyDisplayRequest.class, (byte) 18); + IDS.put(VerifyDisplayResponse.class, (byte) 20); + IDS.put(SynRequest.class, (byte) 23); + IDS.put(SynAckResponse.class, (byte) 24); + IDS.put(DisconnectMessage.class, (byte) 27); + IDS.put(VerifyConfirmResponse.class, (byte) 30); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/SatlErrorIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/SatlErrorIDs.java new file mode 100644 index 0000000000..fe18afbff0 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/SatlErrorIDs.java @@ -0,0 +1,26 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.satl.SatlError; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class SatlErrorIDs { + + public static final IDStorage IDS = new IDStorage<>(); + + static { + IDS.put(SatlError.UNDEFINED, (byte) 0); + IDS.put(SatlError.INCOMPATIBLE_VERSION, (byte) 1); + IDS.put(SatlError.INVALID_COMM_ID, (byte) 2); + IDS.put(SatlError.INVALID_MAC_TRAILER, (byte) 3); + IDS.put(SatlError.INVALID_CRC, (byte) 4); + IDS.put(SatlError.INVALID_PACKET, (byte) 5); + IDS.put(SatlError.INVALID_NONCE, (byte) 6); + IDS.put(SatlError.DECRYPT_VERIFY_FAILED, (byte) 7); + IDS.put(SatlError.COMPATIBLE_STATE, (byte) 8); + IDS.put(SatlError.WRONG_STATE, (byte) 0x0F); + IDS.put(SatlError.INVALID_MESSAGE_TYPE, (byte) 51); + IDS.put(SatlError.INVALID_PAYLOAD_LENGTH, (byte) 60); + IDS.put(SatlError.NONE, (byte) 255); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/ServiceIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/ServiceIDs.java new file mode 100644 index 0000000000..f9a59bdda5 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/ServiceIDs.java @@ -0,0 +1,18 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class ServiceIDs { + + public static final IDStorage IDS = new IDStorage<>(); + + static { + IDS.put(Service.CONNECTION, (byte) 0); + IDS.put(Service.STATUS, (byte) 15); + IDS.put(Service.HISTORY, (byte) 60); + IDS.put(Service.CONFIGURATION, (byte) 85); + IDS.put(Service.REMOTE_CONTROL, (byte) 102); + IDS.put(Service.PARAMETER, (byte) 51); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/SymbolStatusIDs.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/SymbolStatusIDs.java new file mode 100644 index 0000000000..84aee7f092 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/ids/SymbolStatusIDs.java @@ -0,0 +1,16 @@ +package info.nightscout.androidaps.plugins.pump.insight.ids; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.SymbolStatus; +import info.nightscout.androidaps.plugins.pump.insight.utils.IDStorage; + +public class SymbolStatusIDs { + + public static final IDStorage IDS = new IDStorage<>(); + + static { + IDS.put(SymbolStatus.FULL, 31); + IDS.put(SymbolStatus.LOW, 227); + IDS.put(SymbolStatus.EMPTY, 252); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/ConnectionRequest.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/ConnectionRequest.java new file mode 100644 index 0000000000..9a6bf6ee15 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/ConnectionRequest.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +public class ConnectionRequest extends SatlMessage { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/ConnectionResponse.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/ConnectionResponse.java new file mode 100644 index 0000000000..46bd0fd787 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/ConnectionResponse.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +public class ConnectionResponse extends SatlMessage { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/DataMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/DataMessage.java new file mode 100644 index 0000000000..d41059f208 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/DataMessage.java @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class DataMessage extends SatlMessage { + + private ByteBuf data; + + @Override + protected void parse(ByteBuf byteBuf) { + data = byteBuf; + } + + public ByteBuf getData() { + return this.data; + } + + public void setData(ByteBuf data) { + this.data = data; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/DisconnectMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/DisconnectMessage.java new file mode 100644 index 0000000000..d1e9eb0c56 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/DisconnectMessage.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +public class DisconnectMessage extends SatlMessage { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/ErrorMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/ErrorMessage.java new file mode 100644 index 0000000000..3acab320b4 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/ErrorMessage.java @@ -0,0 +1,18 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +import info.nightscout.androidaps.plugins.pump.insight.ids.SatlErrorIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class ErrorMessage extends SatlMessage { + + private SatlError error; + + @Override + protected void parse(ByteBuf byteBuf) { + error = SatlErrorIDs.IDS.getType(byteBuf.readByte()); + } + + public SatlError getError() { + return this.error; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/KeyRequest.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/KeyRequest.java new file mode 100644 index 0000000000..a4a8a57438 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/KeyRequest.java @@ -0,0 +1,39 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +import java.util.Calendar; + +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class KeyRequest extends SatlMessage { + + private byte[] randomBytes; + private byte[] preMasterKey; + + @Override + protected ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(288); + byteBuf.putBytes(randomBytes); + byteBuf.putUInt32LE(translateDate()); + byteBuf.putBytes(preMasterKey); + return byteBuf; + } + + private static int translateDate() { + Calendar calendar = Calendar.getInstance(); + int second = calendar.get(Calendar.SECOND); + int minute = calendar.get(Calendar.MINUTE); + int hour = calendar.get(Calendar.HOUR_OF_DAY); + int day = calendar.get(Calendar.DAY_OF_MONTH); + int month = calendar.get(Calendar.MONTH); + int year = calendar.get(Calendar.YEAR); + return (year % 100 & 0x3f) << 26 | (month & 0x0f) << 22 | (day & 0x1f) << 17 | (hour & 0x1f) << 12 | (minute & 0x3f) << 6 | (second & 0x3f); + } + + public void setRandomBytes(byte[] randomBytes) { + this.randomBytes = randomBytes; + } + + public void setPreMasterKey(byte[] preMasterKey) { + this.preMasterKey = preMasterKey; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/KeyResponse.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/KeyResponse.java new file mode 100644 index 0000000000..1affbab763 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/KeyResponse.java @@ -0,0 +1,24 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class KeyResponse extends SatlMessage { + + private byte[] randomData; + private byte[] preMasterSecret; + + @Override + protected void parse(ByteBuf byteBuf) { + randomData = byteBuf.readBytes(28); + byteBuf.shift(4); + preMasterSecret = byteBuf.getBytes(256); + } + + public byte[] getRandomData() { + return this.randomData; + } + + public byte[] getPreMasterSecret() { + return this.preMasterSecret; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/PairingStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/PairingStatus.java new file mode 100644 index 0000000000..52131e2d1e --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/PairingStatus.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +public enum PairingStatus { + + CONFIRMED, + REJECTED, + PENDING; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/SatlError.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/SatlError.java new file mode 100644 index 0000000000..7e04018dc8 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/SatlError.java @@ -0,0 +1,18 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +public enum SatlError { + + UNDEFINED, + INCOMPATIBLE_VERSION, + INVALID_COMM_ID, + INVALID_MAC_TRAILER, + INVALID_CRC, + INVALID_PACKET, + INVALID_NONCE, + DECRYPT_VERIFY_FAILED, + COMPATIBLE_STATE, + WRONG_STATE, + INVALID_MESSAGE_TYPE, + INVALID_PAYLOAD_LENGTH, + NONE; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/SatlMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/SatlMessage.java new file mode 100644 index 0000000000..09d5d1626a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/SatlMessage.java @@ -0,0 +1,178 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +import java.util.Arrays; + +import info.nightscout.androidaps.plugins.pump.insight.exceptions.IncompatibleSatlVersionException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.InvalidMacTrailerException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.InvalidNonceException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.InvalidPacketLengthsException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.InvalidPreambleException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.InvalidSatlCRCException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.InvalidSatlCommandException; +import info.nightscout.androidaps.plugins.pump.insight.ids.SatlCommandIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; +import info.nightscout.androidaps.plugins.pump.insight.utils.Nonce; +import info.nightscout.androidaps.plugins.pump.insight.utils.crypto.Cryptograph; + +public abstract class SatlMessage { + + private static final long PREAMBLE = 4293840008L; + private static final byte VERSION = 0x20; + + private Nonce nonce; + private long commID = 0; + private byte[] satlContent; + + protected ByteBuf getData() { + return new ByteBuf(0); + } + + protected void parse(ByteBuf byteBuf) { + + } + + public ByteBuf serialize(Class clazz, byte[] key) { + ByteBuf byteBuf; + if (nonce == null || key == null) byteBuf = serializeCRC(clazz); + else byteBuf = serializeCTR(nonce.getProductionalBytes(), key, SatlCommandIDs.IDS.getID(clazz)); + satlContent = byteBuf.getBytes(8, byteBuf.getSize() - 16); + return byteBuf; + } + + private ByteBuf serializeCRC(Class clazz) { + ByteBuf data = getData(); + int length = data.getSize() + 31; + ByteBuf byteBuf = new ByteBuf(length + 8); + byteBuf.putUInt32LE(PREAMBLE); + byteBuf.putUInt16LE(length); + byteBuf.putUInt16LE(~length); + byteBuf.putByte(VERSION); + byteBuf.putByte(SatlCommandIDs.IDS.getID(clazz)); + byteBuf.putUInt16LE(data.getSize() + 2); + byteBuf.putUInt32LE(clazz == KeyRequest.class ? 1 : commID); + byteBuf.putBytes((byte) 0x00, 13); + byteBuf.putByteBuf(data); + byteBuf.putUInt16LE(Cryptograph.calculateCRC(byteBuf.getBytes(8, length - 10))); + byteBuf.putBytes((byte) 0x00, 8); + return byteBuf; + } + + private ByteBuf serializeCTR(ByteBuf nonce, byte[] key, byte commandId) { + ByteBuf data = getData(); + ByteBuf encryptedData = ByteBuf.from(Cryptograph.encryptDataCTR(data.getBytes(), key, nonce.getBytes())); + int length = 29 + encryptedData.getSize(); + ByteBuf byteBuf = new ByteBuf(length + 8); + byteBuf.putUInt32LE(PREAMBLE); + byteBuf.putUInt16LE(length); + byteBuf.putUInt16LE(~length); + byteBuf.putByte(VERSION); + byteBuf.putByte(commandId); + byteBuf.putUInt16LE(encryptedData.getSize()); + byteBuf.putUInt32LE(commID); + byteBuf.putByteBuf(nonce); + byteBuf.putByteBuf(encryptedData); + byteBuf.putBytes(Cryptograph.produceCCMTag(byteBuf.getBytes(16, 13), data.getBytes(), byteBuf.getBytes(8, 21), key)); + return byteBuf; + } + + public static SatlMessage deserialize(ByteBuf data, Nonce lastNonce, byte[] key) throws InvalidMacTrailerException, InvalidSatlCRCException, InvalidNonceException, InvalidPreambleException, InvalidPacketLengthsException, IncompatibleSatlVersionException, InvalidSatlCommandException { + SatlMessage satlMessage; + byte[] satlContent = data.getBytes(8, data.getSize() - 16); + if (key == null) satlMessage = deserializeCRC(data); + else satlMessage = deserializeCTR(data, lastNonce, key); + satlMessage.setSatlContent(satlContent); + return satlMessage; + } + + private static SatlMessage deserializeCTR(ByteBuf data, Nonce lastNonce, byte[] key) throws InvalidMacTrailerException, InvalidNonceException, InvalidPreambleException, InvalidPacketLengthsException, IncompatibleSatlVersionException, InvalidSatlCommandException { + long preamble = data.readUInt32LE(); + int packetLength = data.readUInt16LE(); + int packetLengthXOR = data.readUInt16LE() ^ 65535; + byte[] header = data.getBytes(21); + byte version = data.readByte(); + byte commandId = data.readByte(); + Class clazz = SatlCommandIDs.IDS.getType(commandId); + int dataLength = data.readUInt16LE(); + long commId = data.readUInt32LE(); + byte[] nonce = data.readBytes(13); + byte[] payload = data.readBytes(dataLength); + byte[] trailer = data.readBytes(8); + Nonce parsedNonce = Nonce.fromProductionalBytes(nonce); + payload = Cryptograph.encryptDataCTR(payload, key, nonce); + if (!Arrays.equals(trailer, Cryptograph.produceCCMTag(nonce, payload, header, key))) throw new InvalidMacTrailerException(); + if (!lastNonce.isSmallerThan(parsedNonce)) throw new InvalidNonceException(); + if (preamble != PREAMBLE) throw new InvalidPreambleException(); + if (packetLength != packetLengthXOR) throw new InvalidPacketLengthsException(); + if (version != VERSION) throw new IncompatibleSatlVersionException(); + if (clazz == null) throw new InvalidSatlCommandException(); + SatlMessage message = null; + try { + message = clazz.newInstance(); + } catch (Exception ignored) { + } + message.parse(ByteBuf.from(payload)); + message.setNonce(parsedNonce); + message.setCommID(commId); + return message; + } + + private static SatlMessage deserializeCRC(ByteBuf data) throws InvalidSatlCRCException, InvalidPreambleException, InvalidPacketLengthsException, IncompatibleSatlVersionException, InvalidSatlCommandException { + long preamble = data.readUInt32LE(); + int packetLength = data.readUInt16LE(); + int packetLengthXOR = data.readUInt16LE() ^ 65535; + byte[] crcContent = data.getBytes(packetLength - 10); + byte version = data.readByte(); + byte commandId = data.readByte(); + Class clazz = SatlCommandIDs.IDS.getType(commandId); + int dataLength = data.readUInt16LE(); + long commId = data.readUInt32LE(); + byte[] nonce = data.readBytes(13); + byte[] payload = data.readBytes(dataLength - 2); + int crc = data.readUInt16LE(); + data.shift(8); + if (crc != Cryptograph.calculateCRC(crcContent)) throw new InvalidSatlCRCException(); + if (preamble != PREAMBLE) throw new InvalidPreambleException(); + if (packetLength != packetLengthXOR) throw new InvalidPacketLengthsException(); + if (version != VERSION) throw new IncompatibleSatlVersionException(); + if (clazz == null) throw new InvalidSatlCommandException(); + SatlMessage message = null; + try { + message = clazz.newInstance(); + } catch (Exception ignored) { + } + message.parse(ByteBuf.from(payload)); + message.setNonce(Nonce.fromProductionalBytes(nonce)); + message.setCommID(commId); + return message; + } + + public static boolean hasCompletePacket(ByteBuf byteBuf) { + if (byteBuf.getSize() < 37) return false; + if (byteBuf.getSize() < byteBuf.getUInt16LE(4) + 8) return false; + return true; + } + + public Nonce getNonce() { + return this.nonce; + } + + public long getCommID() { + return this.commID; + } + + public byte[] getSatlContent() { + return this.satlContent; + } + + public void setNonce(Nonce nonce) { + this.nonce = nonce; + } + + public void setCommID(long commID) { + this.commID = commID; + } + + public void setSatlContent(byte[] satlContent) { + this.satlContent = satlContent; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/SynAckResponse.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/SynAckResponse.java new file mode 100644 index 0000000000..261d2fa01c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/SynAckResponse.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +public class SynAckResponse extends SatlMessage { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/SynRequest.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/SynRequest.java new file mode 100644 index 0000000000..9b47376495 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/SynRequest.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +public class SynRequest extends SatlMessage { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/VerifyConfirmRequest.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/VerifyConfirmRequest.java new file mode 100644 index 0000000000..dcca03a8f9 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/VerifyConfirmRequest.java @@ -0,0 +1,14 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +import info.nightscout.androidaps.plugins.pump.insight.ids.PairingStatusIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class VerifyConfirmRequest extends SatlMessage { + + @Override + protected ByteBuf getData() { + ByteBuf byteBuf = new ByteBuf(2); + byteBuf.putUInt16LE(PairingStatusIDs.IDS.getID(PairingStatus.CONFIRMED)); + return byteBuf; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/VerifyConfirmResponse.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/VerifyConfirmResponse.java new file mode 100644 index 0000000000..ed839f81a5 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/VerifyConfirmResponse.java @@ -0,0 +1,18 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +import info.nightscout.androidaps.plugins.pump.insight.ids.PairingStatusIDs; +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class VerifyConfirmResponse extends SatlMessage { + + private PairingStatus pairingStatus; + + @Override + protected void parse(ByteBuf byteBuf) { + pairingStatus = PairingStatusIDs.IDS.getType(byteBuf.readUInt16LE()); + } + + public PairingStatus getPairingStatus() { + return this.pairingStatus; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/VerifyDisplayRequest.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/VerifyDisplayRequest.java new file mode 100644 index 0000000000..4ed85b620c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/VerifyDisplayRequest.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +public class VerifyDisplayRequest extends SatlMessage { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/VerifyDisplayResponse.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/VerifyDisplayResponse.java new file mode 100644 index 0000000000..0d3dc52f3e --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/satl/VerifyDisplayResponse.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.plugins.pump.insight.satl; + +public class VerifyDisplayResponse extends SatlMessage { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/BOCUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/BOCUtil.java new file mode 100644 index 0000000000..6d0d93920f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/BOCUtil.java @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils; + +public final class BOCUtil { + + public static int parseBOC(byte b) { + return ((b & 0xF0) >> 4) * 10 + (b & 0x0F); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/ByteBuf.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/ByteBuf.java new file mode 100644 index 0000000000..107634acf9 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/ByteBuf.java @@ -0,0 +1,384 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils; + +import java.io.UnsupportedEncodingException; +import java.math.BigDecimal; +import java.math.RoundingMode; + +public class ByteBuf { + + private byte[] bytes; + private int size = 0; + + public ByteBuf(int length) { + bytes = new byte[length]; + } + + + public byte[] getBytes() { + byte[] bytes = new byte[size]; + System.arraycopy(this.bytes, 0, bytes, 0, size); + return bytes; + } + + public void shift(int offset) { + System.arraycopy(bytes, offset, bytes, 0, bytes.length - offset); + size -= offset; + } + + public byte getByte(int position) { + return bytes[position]; + } + + public byte getByte() { + return bytes[0]; + } + + public byte readByte() { + byte b = getByte(); + shift(1); + return b; + } + + public void putByte(byte b) { + bytes[size] = b; + size += 1; + } + + + + public void putBytes(byte b, int count) { + for (int i = 0; i < count; i++) bytes[size++] = b; + } + + + + public byte[] getBytes(int position, int length) { + byte[] copy = new byte[length]; + System.arraycopy(bytes, position, copy, 0, length); + return copy; + } + + public byte[] getBytes(int length) { + return getBytes(0, length); + } + + public byte[] readBytes(int length) { + byte[] copy = getBytes(length); + shift(length); + return copy; + } + + public byte[] readBytes() { + return readBytes(size); + } + + public void putBytes(byte[] bytes, int length) { + System.arraycopy(bytes, 0, this.bytes, size, length); + size += length; + } + + public void putBytes(byte[] bytes) { + putBytes(bytes, bytes.length); + } + + + + public byte[] getBytesLE(int position, int length) { + byte[] copy = new byte[length]; + for (int i = 0; i < length; i++) + copy[i] = bytes[length - 1 - i + position]; + return copy; + } + + public byte[] getBytesLE(int length) { + return getBytesLE(0, length); + } + + public byte[] readBytesLE(int length) { + byte[] copy = getBytesLE(length); + shift(length); + return copy; + } + + public void putBytesLE(byte[] bytes, int length) { + for (int i = 0; i < length; i++) + this.bytes[size + length - 1 - i] = bytes[i]; + size += length; + } + + public void putBytesLE(byte[] bytes) { + putBytesLE(bytes, bytes.length); + } + + + public void putByteBuf(ByteBuf byteBuf) { + putBytes(byteBuf.getBytes(), byteBuf.getSize()); + } + + + + public short getUInt8(int position) { + return (short) (bytes[position] & 0xFF); + } + + public short getUInt8() { + return getUInt8(0); + } + + public short readUInt8() { + short value = getUInt8(); + shift(1); + return value; + } + + public void putUInt8(short value) { + putByte((byte) (value & 0xFF)); + } + + + + public int getUInt16LE(int position) { + return (bytes[position++] & 0xFF | + (bytes[position] & 0xFF) << 8); + } + + public int getUInt16LE() { + return getUInt16LE(0); + } + + public int readUInt16LE() { + int i = getUInt16LE(); + shift(2); + return i; + } + + public void putUInt16LE(int i) { + putByte((byte) (i & 0xFF)); + putByte((byte) ((i >> 8) & 0xFF)); + } + + + + public double getUInt16Decimal(int position) { + return new BigDecimal(getUInt16LE(position)) + .divide(new BigDecimal(100), 2, RoundingMode.HALF_UP) + .doubleValue(); + } + + public double getUInt16Decimal() { + return getUInt16Decimal(0); + } + + public double readUInt16Decimal() { + double d = getUInt16Decimal(); + shift(2); + return d; + } + + public void putUInt16Decimal(double d) { + putUInt16LE(new BigDecimal(d) + .multiply(new BigDecimal(100)) + .setScale(0, RoundingMode.HALF_UP) + .intValue()); + } + + + + public double getUInt32Decimal100(int position) { + return new BigDecimal(getUInt32LE(position)) + .divide(new BigDecimal(100), 2, RoundingMode.HALF_UP) + .doubleValue(); + } + + public double getUInt32Decimal100() { + return getUInt32Decimal100(0); + } + + public double readUInt32Decimal100() { + double d = getUInt32Decimal100(); + shift(4); + return d; + } + + public void putUInt32Decimal100(double d) { + putUInt32LE(new BigDecimal(d) + .multiply(new BigDecimal(100)) + .setScale(0, RoundingMode.HALF_UP) + .longValue()); + } + + + + public double getUInt32Decimal1000(int position) { + return new BigDecimal(getUInt32LE(position)) + .divide(new BigDecimal(1000), 3, RoundingMode.HALF_UP) + .doubleValue(); + } + + public double getUInt32Decimal1000() { + return getUInt32Decimal1000(0); + } + + public double readUInt32Decimal1000() { + double d = getUInt32Decimal1000(); + shift(4); + return d; + } + + public void putUInt32Decimal1000(double d) { + putUInt32LE(new BigDecimal(d) + .multiply(new BigDecimal(1000)) + .setScale(0, RoundingMode.HALF_UP) + .longValue()); + } + + + + public short getShort(int position) { + return (short) (bytes[position++] << 8 | + bytes[position] & 0xFF); + } + + public short getShort() { + return getShort(0); + } + + public short readShort() { + short s = getShort(); + shift(2); + return s; + } + + public void putShort(short s) { + putByte((byte) (s >> 8)); + putByte((byte) s); + } + + + + public long getUInt32LE(int position) { + return ((long) bytes[position++] & 0xFF) | + ((long) bytes[position++] & 0xFF) << 8 | + ((long) bytes[position++] & 0xFF) << 16 | + ((long) bytes[position] & 0xFF) << 24; + } + + public long getUInt32LE() { + return getUInt32LE(0); + } + + public long readUInt32LE() { + long l = getUInt32LE(); + shift(4); + return l; + } + + public void putUInt32LE(long l) { + putByte((byte) (l & 0xFF)); + putByte((byte) ((l >> 8) & 0xFF)); + putByte((byte) ((l >> 16) & 0xFF)); + putByte((byte) ((l >> 24) & 0xFF)); + } + + + + public String getUTF16(int position, int stringLength) { + try { + String string = new String(getBytes(position, stringLength * 2 + 2), "UTF-16LE"); + return string.substring(0, string.indexOf(new String(new char[] {0, 0}))); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return null; + } + + public String getUTF16(int stringLength) { + return getUTF16(0, stringLength); + } + + public String readUTF16(int stringLength) { + String string = getUTF16(stringLength); + shift(stringLength * 2 + 2); + return string; + } + + public void putUTF16(String string, int stringLength) { + try { + putBytes(string.getBytes("UTF-16LE"), stringLength * 2); + putBytes((byte) 0, 2); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + + + + public String getASCII(int position, int stringLength) { + try { + String string = new String(getBytes(position, stringLength + 1), "US-ASCII"); + return string.substring(0, string.indexOf(0)); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return null; + } + + public String getASCII(int stringLength) { + return getASCII(0, stringLength); + } + + public String readASCII(int stringLength) { + String string = getASCII(stringLength); + shift(stringLength + 1); + return string; + } + + public void putASCII(String string, int stringLength) { + try { + putBytes(string.getBytes("UTF-16LE"), stringLength * 2); + putBytes((byte) 0, 1); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + + + + public boolean getBoolean(int position) { + return getUInt16LE(position) == 75; + } + + public boolean getBoolean() { + return getBoolean(0); + } + + public boolean readBoolean() { + boolean bool = getBoolean(); + shift(2); + return bool; + } + + public void putBoolean(boolean bool) { + putUInt16LE(bool ? 75 : 180); + } + + + + public static ByteBuf from(byte[] bytes, int length) { + ByteBuf byteBuf = new ByteBuf(length); + byteBuf.putBytes(bytes, length); + return byteBuf; + } + + public static ByteBuf from(byte[] bytes) { + return from(bytes, bytes.length); + } + + public int getSize() { + return this.size; + } + + public void clear() { + shift(size); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/ConnectionEstablisher.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/ConnectionEstablisher.java new file mode 100644 index 0000000000..ce6a299521 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/ConnectionEstablisher.java @@ -0,0 +1,79 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils; + +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; +import android.bluetooth.BluetoothSocket; + +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.UUID; + +public class ConnectionEstablisher extends Thread { + + private Callback callback; + private boolean forPairing; + private BluetoothAdapter bluetoothAdapter; + private BluetoothDevice bluetoothDevice; + private BluetoothSocket socket; + + public ConnectionEstablisher(Callback callback, boolean forPairing, BluetoothAdapter bluetoothAdapter, BluetoothDevice bluetoothDevice, BluetoothSocket socket) { + this.callback = callback; + this.forPairing = forPairing; + this.bluetoothAdapter = bluetoothAdapter; + this.bluetoothDevice = bluetoothDevice; + this.socket = socket; + } + + @Override + public void run() { + try { + if (!bluetoothAdapter.isEnabled()) { + bluetoothAdapter.enable(); + Thread.sleep(2000); + } + } catch (InterruptedException ignored) { + return; + } + if (forPairing && bluetoothDevice.getBondState() != BluetoothDevice.BOND_NONE) { + try { + Method removeBond = bluetoothDevice.getClass().getMethod("removeBond", (Class[]) null); + removeBond.invoke(bluetoothDevice, (Object[]) null); + } catch (ReflectiveOperationException e) { + if (!isInterrupted()) callback.onConnectionFail(e, 0); + return; + } + } + try { + if (socket == null) { + socket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805f9b34fb")); + callback.onSocketCreated(socket); + } + } catch (IOException e) { + if (!isInterrupted()) callback.onConnectionFail(e, 0); + return; + } + long connectionStart = System.currentTimeMillis(); + try { + socket.connect(); + if (!isInterrupted()) callback.onConnectionSucceed(); + } catch (IOException e) { + if (!isInterrupted()) callback.onConnectionFail(e, System.currentTimeMillis() - connectionStart); + } + } + + public void close(boolean closeSocket) { + try { + interrupt(); + if (closeSocket && socket != null && socket.isConnected()) socket.close(); + } catch (IOException ignored) { + } + } + + public interface Callback { + void onSocketCreated(BluetoothSocket bluetoothSocket); + + void onConnectionSucceed(); + + void onConnectionFail(Exception e, long duration); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/DelayedActionThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/DelayedActionThread.java new file mode 100644 index 0000000000..c801a1b2d3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/DelayedActionThread.java @@ -0,0 +1,28 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils; + +public class DelayedActionThread extends Thread { + + private long duration; + private Runnable runnable; + + private DelayedActionThread(String name, long duration, Runnable runnable) { + setName(name); + this.duration = duration; + this.runnable = runnable; + } + + @Override + public void run() { + try { + Thread.sleep(duration); + runnable.run(); + } catch (InterruptedException e) { + } + } + + public static DelayedActionThread runDelayed(String name, long duration, Runnable runnable) { + DelayedActionThread delayedActionThread = new DelayedActionThread(name, duration, runnable); + delayedActionThread.start(); + return delayedActionThread; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/ExceptionTranslator.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/ExceptionTranslator.java new file mode 100644 index 0000000000..7eda84d01b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/ExceptionTranslator.java @@ -0,0 +1,55 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils; + +import android.content.Context; +import android.os.Handler; +import android.os.Looper; +import android.widget.Toast; + +import java.util.HashMap; +import java.util.Map; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.ConnectionFailedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.ConnectionLostException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.DisconnectedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.SocketCreationFailedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.TimeoutException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.MaximumNumberOfBolusTypeAlreadyRunningException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NoActiveTBRToCanceLException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NoActiveTBRToChangeException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NoSuchBolusToCancelException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.PumpAlreadyInThatStateException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.PumpStoppedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.RunModeNotAllowedException; +import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlPairingRejectedException; + +public class ExceptionTranslator { + + private static final Map, Integer> TABLE = new HashMap<>(); + + static { + TABLE.put(ConnectionFailedException.class, R.string.connection_failed); + TABLE.put(ConnectionLostException.class, R.string.connection_lost); + TABLE.put(DisconnectedException.class, R.string.disconnected); + TABLE.put(SatlPairingRejectedException.class, R.string.pairing_rejected); + TABLE.put(SocketCreationFailedException.class, R.string.socket_creation_failed); + TABLE.put(TimeoutException.class, R.string.timeout); + TABLE.put(MaximumNumberOfBolusTypeAlreadyRunningException.class, R.string.maximum_number_of_bolus_type_already_running); + TABLE.put(NoActiveTBRToCanceLException.class, R.string.no_active_tbr_to_cancel); + TABLE.put(NoActiveTBRToChangeException.class, R.string.no_active_tbr_to_change); + TABLE.put(NoSuchBolusToCancelException.class, R.string.no_such_bolus_to_cancel); + TABLE.put(PumpAlreadyInThatStateException.class, R.string.pump_already_in_that_state_exception); + TABLE.put(PumpStoppedException.class, R.string.pump_stopped); + TABLE.put(RunModeNotAllowedException.class, R.string.run_mode_not_allowed); + } + + public static String getString(Exception exception) { + Integer res = TABLE.get(exception.getClass()); + return res == null ? exception.getClass().getSimpleName() : MainApp.gs(res); + } + + public static void makeToast(Context context, Exception exception) { + new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(context, getString(exception), Toast.LENGTH_LONG).show()); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/IDStorage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/IDStorage.java new file mode 100644 index 0000000000..05d3290eb2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/IDStorage.java @@ -0,0 +1,24 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils; + +import java.util.HashMap; +import java.util.Map; + +public class IDStorage { + + private Map types = new HashMap<>(); + private Map ids = new HashMap<>(); + + public void put(T type, I id) { + types.put(type, id); + ids.put(id, type); + } + + public T getType(I type) { + return ids.get(type); + } + + public I getID(T id) { + return types.get(id); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/InputStreamReader.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/InputStreamReader.java new file mode 100644 index 0000000000..7641aba369 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/InputStreamReader.java @@ -0,0 +1,51 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils; + +import java.io.IOException; +import java.io.InputStream; + +public class InputStreamReader extends Thread { + + private static final int BUFFER_SIZE = 1024; + + private InputStream inputStream; + private Callback callback; + + public InputStreamReader(InputStream inputStream, Callback callback) { + setName(getClass().getSimpleName()); + this.inputStream = inputStream; + this.callback = callback; + } + + @Override + public void run() { + byte[] buffer = new byte[BUFFER_SIZE]; + int bytesRead; + try { + while (!isInterrupted()) { + bytesRead = inputStream.read(buffer); + if (bytesRead == -1) callback.onErrorWhileReading(new IOException("Stream closed")); + else callback.onReceiveBytes(buffer, bytesRead); + } + } catch (IOException e) { + if (!isInterrupted()) callback.onErrorWhileReading(e); + } finally { + try { + inputStream.close(); + } catch (IOException e) { + } + } + } + + public void close() { + interrupt(); + try { + inputStream.close(); + } catch (IOException e) { + } + } + + public interface Callback { + void onReceiveBytes(byte[] buffer, int bytesRead); + void onErrorWhileReading(Exception e); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/Nonce.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/Nonce.java new file mode 100644 index 0000000000..60dddc60bf --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/Nonce.java @@ -0,0 +1,47 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils; + +import java.math.BigInteger; + +public class Nonce { + + private BigInteger bigInteger; + + public Nonce() { + bigInteger = BigInteger.ZERO; + } + + public Nonce(byte[] storageValue) { + bigInteger = new BigInteger(storageValue); + } + + public byte[] getStorageValue() { + return bigInteger.toByteArray(); + } + + public ByteBuf getProductionalBytes() { + ByteBuf byteBuf = new ByteBuf(13); + byteBuf.putBytesLE(bigInteger.toByteArray()); + byteBuf.putBytes((byte) 0x00, 13 - byteBuf.getSize()); + return byteBuf; + } + + public static Nonce fromProductionalBytes(byte[] bytes) { + ByteBuf byteBuf = new ByteBuf(14); + byteBuf.putByte((byte) 0x00); + byteBuf.putBytesLE(bytes); + return new Nonce(byteBuf.getBytes()); + } + + public void increment() { + bigInteger = bigInteger.add(BigInteger.ONE); + } + + public void increment(int count) { + bigInteger = bigInteger.add(BigInteger.valueOf(count)); + } + + public boolean isSmallerThan(Nonce greater) { + return bigInteger.compareTo(greater.bigInteger) < 0; + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/OutputStreamWriter.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/OutputStreamWriter.java new file mode 100644 index 0000000000..fa03cf7824 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/OutputStreamWriter.java @@ -0,0 +1,74 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils; + +import java.io.IOException; +import java.io.OutputStream; + +public class OutputStreamWriter extends Thread { + + private static final int BUFFER_SIZE = 1024; + + private OutputStream outputStream; + private Callback callback; + private final ByteBuf buffer = new ByteBuf(BUFFER_SIZE); + + public OutputStreamWriter(OutputStream outputStream, Callback callback) { + setName(getClass().getSimpleName()); + this.outputStream = outputStream; + this.callback = callback; + } + + @Override + public void run() { + try { + while (!isInterrupted()) { + synchronized (buffer) { + if (buffer.getSize() != 0) { + outputStream.write(buffer.readBytes()); + outputStream.flush(); + buffer.notifyAll(); + } + buffer.wait(); + } + } + } catch (IOException e) { + if (!isInterrupted()) callback.onErrorWhileWriting(e); + } catch (InterruptedException ignored) { + } finally { + try { + outputStream.close(); + } catch (IOException e) { + } + } + } + + public void write(byte[] bytes) { + synchronized (buffer) { + buffer.putBytes(bytes); + buffer.notifyAll(); + } + } + + public void writeAndWait(byte[] bytes) { + synchronized (buffer) { + buffer.putBytes(bytes); + buffer.notifyAll(); + try { + buffer.wait(); + } catch (InterruptedException e) { + } + } + } + + public void close() { + interrupt(); + try { + outputStream.close(); + } catch (IOException e) { + } + } + + public interface Callback { + void onErrorWhileWriting(Exception e); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/PairingDataStorage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/PairingDataStorage.java new file mode 100644 index 0000000000..57234698ff --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/PairingDataStorage.java @@ -0,0 +1,210 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils; + +import android.content.Context; +import android.content.SharedPreferences; + +import org.spongycastle.util.encoders.Hex; + +import info.nightscout.androidaps.plugins.pump.insight.descriptors.FirmwareVersions; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.SystemIdentification; + +public class PairingDataStorage { + + private SharedPreferences preferences; + + private boolean paired; + private String macAddress; + private Nonce lastNonceSent; + private Nonce lastNonceReceived; + private long commId; + private byte[] incomingKey; + private byte[] outgoingKey; + private FirmwareVersions firmwareVersions; + private SystemIdentification systemIdentification; + + public PairingDataStorage(Context context) { + this.preferences = context.getSharedPreferences(context.getPackageName() + ".PAIRING_DATA_STORAGE", Context.MODE_PRIVATE); + paired = preferences.getBoolean("paired", false); + macAddress = preferences.getString("macAddress", null); + String lastNonceSentHex = preferences.getString("lastNonceSent", null); + if (lastNonceSentHex != null) lastNonceSent = new Nonce(Hex.decode(lastNonceSentHex)); + String lastNonceReceivedHex = preferences.getString("lastNonceReceived", null); + if (lastNonceReceivedHex != null) lastNonceReceived = new Nonce(Hex.decode(lastNonceReceivedHex)); + commId = preferences.getLong("commId", 0); + String incomingKeyHex = preferences.getString("incomingKey", null); + incomingKey = incomingKeyHex == null ? null : Hex.decode(incomingKeyHex); + String outgoingKeyHex = preferences.getString("outgoingKey", null); + outgoingKey = outgoingKeyHex == null ? null : Hex.decode(outgoingKeyHex); + + String pumpSerial = preferences.getString("pumpSerial", null); + String manufacturingDate = preferences.getString("manufacturingDate", null); + long systemIdAppendix = preferences.getLong("systemIdAppendix", 0); + + if (pumpSerial != null) { + systemIdentification = new SystemIdentification(); + systemIdentification.setSerialNumber(pumpSerial); + systemIdentification.setManufacturingDate(manufacturingDate); + systemIdentification.setSystemIdAppendix(systemIdAppendix); + } + + String releaseSWVersion = preferences.getString("releaseSWVersion", null); + String uiProcSWVersion = preferences.getString("uiProcSWVersion", null); + String pcProcSWVersion = preferences.getString("pcProcSWVersion", null); + String mdTelProcSWVersion = preferences.getString("mdTelProcSWVersion", null); + String btInfoPageVersion = preferences.getString("btInfoPageVersion", null); + String safetyProcSWVersion = preferences.getString("safetyProcSWVersion", null); + int configIndex = preferences.getInt("configIndex", 0); + int historyIndex = preferences.getInt("historyIndex", 0); + int stateIndex = preferences.getInt("stateIndex", 0); + int vocabularyIndex = preferences.getInt("vocabularyIndex", 0); + if (releaseSWVersion != null) { + firmwareVersions = new FirmwareVersions(); + firmwareVersions.setReleaseSWVersion(releaseSWVersion); + firmwareVersions.setUiProcSWVersion(uiProcSWVersion); + firmwareVersions.setPcProcSWVersion(pcProcSWVersion); + firmwareVersions.setMdTelProcSWVersion(mdTelProcSWVersion); + firmwareVersions.setBtInfoPageVersion(btInfoPageVersion); + firmwareVersions.setSafetyProcSWVersion(safetyProcSWVersion); + firmwareVersions.setConfigIndex(configIndex); + firmwareVersions.setHistoryIndex(historyIndex); + firmwareVersions.setStateIndex(stateIndex); + firmwareVersions.setVocabularyIndex(vocabularyIndex); + } + } + + public void setPaired(boolean paired) { + this.paired = paired; + preferences.edit().putBoolean("paired", paired).apply(); + } + + public void setMacAddress(String macAddress) { + this.macAddress = macAddress; + preferences.edit().putString("macAddress", macAddress).apply(); + } + + public void setLastNonceSent(Nonce lastNonceSent) { + this.lastNonceSent = lastNonceSent; + preferences.edit().putString("lastNonceSent", lastNonceSent == null ? null : Hex.toHexString(lastNonceSent.getStorageValue())).apply(); + } + + public void setLastNonceReceived(Nonce lastNonceReceived) { + this.lastNonceReceived = lastNonceReceived; + preferences.edit().putString("lastNonceReceived", lastNonceReceived == null ? null : Hex.toHexString(lastNonceReceived.getStorageValue())).apply(); + } + + public void setCommId(long commId) { + this.commId = commId; + preferences.edit().putLong("commId", commId).apply(); + } + + public void setIncomingKey(byte[] incomingKey) { + this.incomingKey = incomingKey; + preferences.edit().putString("incomingKey", incomingKey == null ? null : Hex.toHexString(incomingKey)).apply(); + } + + public void setOutgoingKey(byte[] outgoingKey) { + this.outgoingKey = outgoingKey; + preferences.edit().putString("outgoingKey", outgoingKey == null ? null : Hex.toHexString(outgoingKey)).apply(); + } + + public SharedPreferences getPreferences() { + return this.preferences; + } + + public boolean isPaired() { + return this.paired; + } + + public String getMacAddress() { + return this.macAddress; + } + + public Nonce getLastNonceSent() { + return this.lastNonceSent; + } + + public Nonce getLastNonceReceived() { + return this.lastNonceReceived; + } + + public long getCommId() { + return this.commId; + } + + public byte[] getIncomingKey() { + return this.incomingKey; + } + + public byte[] getOutgoingKey() { + return this.outgoingKey; + } + + public FirmwareVersions getFirmwareVersions() { + return firmwareVersions; + } + + public void setFirmwareVersions(FirmwareVersions firmwareVersions) { + this.firmwareVersions = firmwareVersions; + if (firmwareVersions == null) { + preferences.edit() + .putString("releaseSWVersion", null) + .putString("uiProcSWVersion", null) + .putString("pcProcSWVersion", null) + .putString("mdTelProcSWVersion", null) + .putString("btInfoPageVersion", null) + .putString("safetyProcSWVersion", null) + .putInt("configIndex", 0) + .putInt("historyIndex", 0) + .putInt("stateIndex", 0) + .putInt("vocabularyIndex", 0) + .apply(); + } else { + preferences.edit() + .putString("releaseSWVersion", firmwareVersions.getReleaseSWVersion()) + .putString("uiProcSWVersion", firmwareVersions.getUiProcSWVersion()) + .putString("pcProcSWVersion", firmwareVersions.getPcProcSWVersion()) + .putString("mdTelProcSWVersion", firmwareVersions.getMdTelProcSWVersion()) + .putString("btInfoPageVersion", firmwareVersions.getBtInfoPageVersion()) + .putString("safetyProcSWVersion", firmwareVersions.getSafetyProcSWVersion()) + .putInt("configIndex", firmwareVersions.getConfigIndex()) + .putInt("historyIndex", firmwareVersions.getHistoryIndex()) + .putInt("stateIndex", firmwareVersions.getStateIndex()) + .putInt("vocabularyIndex", firmwareVersions.getVocabularyIndex()) + .apply(); + } + } + + public SystemIdentification getSystemIdentification() { + return systemIdentification; + } + + public void setSystemIdentification(SystemIdentification systemIdentification) { + this.systemIdentification = systemIdentification; + if (systemIdentification == null) { + preferences.edit() + .putString("pumpSerial", null) + .putString("manufacturingDate", null) + .putLong("systemIdAppendix", 0) + .apply(); + } else { + preferences.edit() + .putString("pumpSerial", systemIdentification.getSerialNumber()) + .putString("manufacturingDate", systemIdentification.getManufacturingDate()) + .putLong("systemIdAppendix", systemIdentification.getSystemIdAppendix()) + .apply(); + } + } + + public void reset() { + setPaired(false); + setMacAddress(null); + setCommId(0); + setIncomingKey(null); + setOutgoingKey(null); + setLastNonceReceived(null); + setLastNonceSent(null); + setFirmwareVersions(null); + setSystemIdentification(null); + setMacAddress(null); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/ParameterBlockUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/ParameterBlockUtil.java new file mode 100644 index 0000000000..4cd75f26e7 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/ParameterBlockUtil.java @@ -0,0 +1,24 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils; + +import info.nightscout.androidaps.plugins.pump.insight.app_layer.ReadParameterBlockMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration.WriteConfigurationBlockMessage; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.ParameterBlock; +import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService; + +public class ParameterBlockUtil { + + public static T readParameterBlock(InsightConnectionService connectionService, Service service, Class parameterBlock) throws Exception { + ReadParameterBlockMessage readMessage = new ReadParameterBlockMessage(); + readMessage.setService(service); + readMessage.setParameterBlockId(parameterBlock); + return (T) connectionService.requestMessage(readMessage).await().getParameterBlock(); + } + + public static void writeConfigurationBlock(InsightConnectionService connectionService, ParameterBlock parameterBlock) throws Exception { + WriteConfigurationBlockMessage writeMessage = new WriteConfigurationBlockMessage(); + writeMessage.setParameterBlock(parameterBlock); + connectionService.requestMessage(writeMessage).await(); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/crypto/CRC.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/crypto/CRC.java new file mode 100644 index 0000000000..16fe253c1d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/crypto/CRC.java @@ -0,0 +1,44 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils.crypto; + +/* + * Based on: http://introcs.cs.princeton.edu/java/61data/CRC16.java + * Table generated using: http://pycrc.org/ + * Command used: python pycrc.py --width 16 --poly 0x1021 --reflect-in True --reflect-out True --xor-in 0xffff --xor-out=0x0000 --generate TABLE + */ +class CRC { + + protected static final int[] TABLE = { + 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, + 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, + 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, + 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, + 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, + 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, + 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, + 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, + 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, + 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, + 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, + 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, + 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, + 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, + 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, + 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, + 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, + 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, + 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, + 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, + 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, + 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, + 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, + 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, + 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, + 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, + 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, + 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, + 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, + 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, + 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, + 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 + }; +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/crypto/Cryptograph.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/crypto/Cryptograph.java new file mode 100644 index 0000000000..bf34832b56 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/crypto/Cryptograph.java @@ -0,0 +1,215 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils.crypto; + +import org.spongycastle.crypto.AsymmetricCipherKeyPair; +import org.spongycastle.crypto.Digest; +import org.spongycastle.crypto.InvalidCipherTextException; +import org.spongycastle.crypto.digests.MD5Digest; +import org.spongycastle.crypto.digests.SHA1Digest; +import org.spongycastle.crypto.encodings.OAEPEncoding; +import org.spongycastle.crypto.engines.RSAEngine; +import org.spongycastle.crypto.engines.TwofishEngine; +import org.spongycastle.crypto.generators.RSAKeyPairGenerator; +import org.spongycastle.crypto.macs.HMac; +import org.spongycastle.crypto.modes.CBCBlockCipher; +import org.spongycastle.crypto.params.AsymmetricKeyParameter; +import org.spongycastle.crypto.params.KeyParameter; +import org.spongycastle.crypto.params.ParametersWithIV; +import org.spongycastle.crypto.params.RSAKeyGenerationParameters; +import org.spongycastle.crypto.params.RSAKeyParameters; +import org.spongycastle.crypto.params.RSAPrivateCrtKeyParameters; + +import java.math.BigInteger; +import java.security.SecureRandom; + +import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf; + +public class Cryptograph { + + private static final String keySeed = "master secret"; + private static final String verificationSeed = "finished"; + + private static byte[] getHmac(byte[] secret, byte[] data, Digest algorithm) { + HMac hmac = new HMac(algorithm); + hmac.init(new KeyParameter(secret)); + byte[] result = new byte[hmac.getMacSize()]; + hmac.update(data, 0, data.length); + hmac.doFinal(result, 0); + return result; + } + + private static byte[] getMultiHmac(byte[] secret, byte[] data, int bytes, Digest algorithm) { + byte[] nuData = data; + byte[] output = new byte[bytes]; + int size = 0; + while (size < bytes) { + nuData = getHmac(secret, nuData, algorithm); + byte[] preOutput = getHmac(secret, combine(nuData, data), algorithm); + System.arraycopy(preOutput, 0, output, size, Math.min(bytes - size, preOutput.length)); + size += preOutput.length; + } + return output; + } + + private static byte[] sha1MultiHmac(byte[] secret, byte[] data, int bytes) { + return getMultiHmac(secret, data, bytes, new SHA1Digest()); + } + + private static byte[] md5MultiHmac(byte[] secret, byte[] data, int bytes) { + return getMultiHmac(secret, data, bytes, new MD5Digest()); + } + + public static byte[] getServicePasswordHash(String servicePassword, byte[] salt) { + return multiHashXOR(servicePassword.getBytes(), combine("service pwd".getBytes(), salt), 16); + } + + private static byte[] byteArrayXOR(byte[] array1, byte[] array2) { + int length = Math.min(array1.length, array2.length); + byte[] xor = new byte[length]; + for (int i = 0; i < length; i++) { + xor[i] = (byte) (array1[i] ^ array2[i]); + } + return xor; + } + + private static byte[] multiHashXOR(byte[] secret, byte[] seed, int bytes) { + byte[] array1 = new byte[secret.length / 2]; + byte[] array2 = new byte[array1.length]; + System.arraycopy(secret, 0, array1, 0, array1.length); + System.arraycopy(secret, array1.length, array2, 0, array2.length); + byte[] md5 = md5MultiHmac(array1, seed, bytes); + byte[] sha1 = sha1MultiHmac(array2, seed, bytes); + return byteArrayXOR(md5, sha1); + } + + public static DerivedKeys deriveKeys(byte[] verificationSeed, byte[] secret, byte[] random, byte[] peerRandom) { + byte[] result = multiHashXOR(secret, combine(combine(keySeed.getBytes(), random), peerRandom), 32); + DerivedKeys derivedKeys = new DerivedKeys(); + derivedKeys.incomingKey = new byte[result.length / 2]; + derivedKeys.outgoingKey = new byte[derivedKeys.incomingKey.length]; + System.arraycopy(result, 0, derivedKeys.incomingKey, 0, derivedKeys.incomingKey.length); + System.arraycopy(result, derivedKeys.incomingKey.length, derivedKeys.outgoingKey, 0, derivedKeys.outgoingKey.length); + derivedKeys.verificationString = calculateVerificationString(verificationSeed, result); + return derivedKeys; + } + + private static String calculateVerificationString(byte[] verificationSeed, byte[] key) { + byte[] verificationData = multiHashXOR(key, combine(Cryptograph.verificationSeed.getBytes(), verificationSeed), 8); + long value = 0; + for (int i = 7; i >= 0; i--) { + long byteValue = verificationData[i]; + if (byteValue < 0) byteValue += 256; + value |= byteValue << (i * 8); + } + StringBuilder stringBuilder = new StringBuilder(); + for (int index = 0; index < 10; index++) { + if (index == 3 || index == 6) stringBuilder.append(" "); + stringBuilder.append(VerificationString.TABLE[((int) value) & 63]); + value >>= 6; + } + return stringBuilder.toString(); + } + + private static byte[] processRSA(AsymmetricKeyParameter key, byte[] data, boolean encrypt) throws InvalidCipherTextException { + OAEPEncoding cipher = new OAEPEncoding(new RSAEngine()); + cipher.init(encrypt, key); + return cipher.processBlock(data, 0, data.length); + } + + public static byte[] decryptRSA(RSAPrivateCrtKeyParameters key, byte[] data) throws InvalidCipherTextException { + return processRSA(key, data, false); + } + + public static KeyPair generateRSAKey() { + RSAKeyPairGenerator generator = new RSAKeyPairGenerator(); + generator.init(new RSAKeyGenerationParameters(BigInteger.valueOf(65537), new SecureRandom(), 2048, 8)); + AsymmetricCipherKeyPair ackp = generator.generateKeyPair(); + KeyPair keyPair = new KeyPair(); + keyPair.privateKey = (RSAPrivateCrtKeyParameters) ackp.getPrivate(); + keyPair.publicKey = (RSAKeyParameters) ackp.getPublic(); + return keyPair; + } + + public static byte[] combine(byte[] array1, byte[] array2) { + byte[] combined = new byte[array1.length + array2.length]; + System.arraycopy(array1, 0, combined, 0, array1.length); + System.arraycopy(array2, 0, combined, array1.length, array2.length); + return combined; + } + + private static byte[] produceCCMPrimitive(byte headerByte, byte[] nonce, short number) { + ByteBuf byteBuf = new ByteBuf(16); + byteBuf.putByte(headerByte); + byteBuf.putBytes(nonce); + byteBuf.putShort(number); + return byteBuf.getBytes(); + } + + private static byte[] produceIV(byte[] nonce, short payloadSize) { + return produceCCMPrimitive((byte) 0x59, nonce, payloadSize); + } + + private static byte[] produceCTRBlock(byte[] nonce, short counter) { + return produceCCMPrimitive((byte) 0x01, nonce, counter); + } + + private static byte[] blockCipherZeroPad(byte[] input) { + int modulus = input.length % 16; + if (modulus == 0) return input; + byte[] append = new byte[16 - modulus]; + for (int i = 0; i < 16 - modulus; i++) { + append[i] = 0x00; + } + return combine(input, append); + } + + public static byte[] encryptDataCTR(byte[] data, byte[] key, byte[] nonce) { + byte[] padded = blockCipherZeroPad(data); + int length = padded.length >> 4; + byte[] result = new byte[length * 16]; + TwofishEngine engine = new TwofishEngine(); + engine.init(true, new KeyParameter(key)); + for (int i = 0; i < length; i++) { + engine.processBlock(produceCTRBlock(nonce, (short) (i + 1)), 0, result, i * 16); + } + byte[] xor = byteArrayXOR(padded, result); + byte[] copy = new byte[Math.min(data.length, xor.length)]; + System.arraycopy(xor, 0, copy, 0, copy.length); + return copy; + } + + private static byte[] processHeader(byte[] header) { + ByteBuf byteBuf; + byteBuf = new ByteBuf(2 + header.length); + byteBuf.putShort((short) header.length); + byteBuf.putBytes(header); + return byteBuf.getBytes(); + } + + public static byte[] produceCCMTag(byte[] nonce, byte[] payload, byte[] header, byte[] key) { + TwofishEngine engine = new TwofishEngine(); + engine.init(true, new KeyParameter(key)); + byte[] initializationVector = new byte[engine.getBlockSize()]; + engine.processBlock(produceIV(nonce, (short) payload.length), 0, initializationVector, 0); + CBCBlockCipher cbc = new CBCBlockCipher(new TwofishEngine()); + cbc.init(true, new ParametersWithIV(new KeyParameter(key), initializationVector)); + byte[] processedHeader = blockCipherZeroPad(processHeader(header)); + byte[] processedPayload = blockCipherZeroPad(payload); + byte[] combine = combine(processedHeader, blockCipherZeroPad(processedPayload)); + byte[] result = new byte[combine.length]; + for (int i = 0; i < combine.length / 16; i++) + cbc.processBlock(combine, i * 16, result, i * 16); + byte[] result2 = new byte[8]; + System.arraycopy(result, result.length - 16, result2, 0, 8); + byte[] ctr = new byte[engine.getBlockSize()]; + engine.processBlock(produceCTRBlock(nonce, (short) 0), 0, ctr, 0); + return byteArrayXOR(result2, ctr); + } + + public static int calculateCRC(byte[] bytes) { + int crc = 0xffff; + for (byte b : bytes) { + crc = (crc >>> 8) ^ CRC.TABLE[(crc ^ b) & 0xff]; + } + return crc; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/crypto/DerivedKeys.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/crypto/DerivedKeys.java new file mode 100644 index 0000000000..0e35ceeb31 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/crypto/DerivedKeys.java @@ -0,0 +1,32 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils.crypto; + +public class DerivedKeys { + + byte[] incomingKey; + byte[] outgoingKey; + String verificationString; + + public byte[] getIncomingKey() { + return this.incomingKey; + } + + public byte[] getOutgoingKey() { + return this.outgoingKey; + } + + public String getVerificationString() { + return this.verificationString; + } + + public void setIncomingKey(byte[] incomingKey) { + this.incomingKey = incomingKey; + } + + public void setOutgoingKey(byte[] outgoingKey) { + this.outgoingKey = outgoingKey; + } + + public void setVerificationString(String verificationString) { + this.verificationString = verificationString; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/crypto/KeyPair.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/crypto/KeyPair.java new file mode 100644 index 0000000000..44025fcccc --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/crypto/KeyPair.java @@ -0,0 +1,28 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils.crypto; + +import org.spongycastle.crypto.params.RSAKeyParameters; +import org.spongycastle.crypto.params.RSAPrivateCrtKeyParameters; + +public class KeyPair { + + protected KeyPair() { + } + + RSAPrivateCrtKeyParameters privateKey; + RSAKeyParameters publicKey; + + public byte[] getPublicKeyBytes() { + byte[] modulus = publicKey.getModulus().toByteArray(); + byte[] bytes = new byte[256]; + System.arraycopy(modulus, 1, bytes, 0, 256); + return bytes; + } + + public RSAPrivateCrtKeyParameters getPrivateKey() { + return this.privateKey; + } + + public RSAKeyParameters getPublicKey() { + return this.publicKey; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/crypto/VerificationString.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/crypto/VerificationString.java new file mode 100644 index 0000000000..c40e96910f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/utils/crypto/VerificationString.java @@ -0,0 +1,15 @@ +package info.nightscout.androidaps.plugins.pump.insight.utils.crypto; + +class VerificationString { + + static char[] TABLE = new char[] { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', + 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', + 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', + '4', '5', '6', '7', '8', '9', '+', '/' + }; +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java index 7caca31891..bdd060183b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java @@ -1,10 +1,12 @@ -package info.nightscout.androidaps.plugins.PumpMDI; +package info.nightscout.androidaps.plugins.pump.mdi; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; + import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -17,8 +19,11 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; + /** * Created by mike on 05.08.2016. @@ -136,6 +141,12 @@ public class MDIPlugin extends PluginBase implements PumpInterface { return 0d; } + @Override + public double getReservoirLevel() { return -1; } + + @Override + public int getBatteryLevel() { return -1; } + @Override public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { PumpEnactResult result = new PumpEnactResult(); @@ -239,4 +250,14 @@ public class MDIPlugin extends PluginBase implements PumpInterface { return deviceID(); } + @Override + public List getCustomActions() { + return null; + } + + @Override + public void executeCustomAction(CustomActionType customActionType) { + + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpFragment.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpFragment.java index ef4c85e0a7..0b764f5382 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpVirtual; +package info.nightscout.androidaps.plugins.pump.virtual; import android.app.Activity; @@ -19,11 +19,14 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType; -import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.FabricPrivacy; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; +import info.nightscout.androidaps.plugins.pump.virtual.events.EventVirtualPumpUpdateGui; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.FabricPrivacy; + public class VirtualPumpFragment extends SubscriberFragment { private static Logger log = LoggerFactory.getLogger(VirtualPumpFragment.class); @@ -119,4 +122,6 @@ public class VirtualPumpFragment extends SubscriberFragment { } }); } + + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java index 3207791b88..e60cd78a64 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpVirtual; +package info.nightscout.androidaps.plugins.pump.virtual; import android.os.SystemClock; @@ -9,6 +9,8 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; + import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; @@ -26,16 +28,19 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType; -import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; +import info.nightscout.androidaps.plugins.pump.virtual.events.EventVirtualPumpUpdateGui; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; + /** * Created by mike on 05.08.2016. @@ -140,6 +145,16 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { return new PumpEnactResult(); } + @Override + public List getCustomActions() { + return null; + } + + @Override + public void executeCustomAction(CustomActionType customActionType) { + + } + @Override public boolean isInitialized() { return true; @@ -225,6 +240,12 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { } + @Override + public double getReservoirLevel() { return reservoirInUnits; } + + @Override + public int getBatteryLevel() { return batteryPercent; } + @Override public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/events/EventVirtualPumpUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/events/EventVirtualPumpUpdateGui.java similarity index 72% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/events/EventVirtualPumpUpdateGui.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/events/EventVirtualPumpUpdateGui.java index e035ea3aba..795134997a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/events/EventVirtualPumpUpdateGui.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/events/EventVirtualPumpUpdateGui.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.PumpVirtual.events; +package info.nightscout.androidaps.plugins.pump.virtual.events; import info.nightscout.androidaps.events.EventUpdateGui; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/AbstractSensitivityPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/AbstractSensitivityPlugin.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/AbstractSensitivityPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/AbstractSensitivityPlugin.java index 9f72f1b119..6c8a9e8ba5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/AbstractSensitivityPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/AbstractSensitivityPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Sensitivity; +package info.nightscout.androidaps.plugins.sensitivity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -8,11 +8,11 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.SensitivityInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.utils.Round; -import info.nightscout.utils.SP; -import info.nightscout.utils.SafeParse; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.utils.Round; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.SafeParse; public abstract class AbstractSensitivityPlugin extends PluginBase implements SensitivityInterface { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityAAPSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityAAPSPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.java index 432420df85..8e33b16302 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityAAPSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Sensitivity; +package info.nightscout.androidaps.plugins.sensitivity; import android.support.v4.util.LongSparseArray; @@ -18,12 +18,12 @@ import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 24.06.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref0Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref0Plugin.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref0Plugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref0Plugin.java index 53a8be8661..83800e1721 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref0Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref0Plugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Sensitivity; +package info.nightscout.androidaps.plugins.sensitivity; import android.support.v4.util.LongSparseArray; @@ -18,11 +18,11 @@ import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.utils.DateUtil; /** * Created by mike on 24.06.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java index 7d91c7fc4a..3ce5c4861c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Sensitivity; +package info.nightscout.androidaps.plugins.sensitivity; import android.support.v4.util.LongSparseArray; @@ -18,11 +18,11 @@ import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.utils.DateUtil; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.utils.DateUtil; /** * Created by mike on 19.06.2018. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityWeightedAveragePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityWeightedAveragePlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.java index 2aeb26bd1a..5b7268b560 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityWeightedAveragePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Sensitivity; +package info.nightscout.androidaps.plugins.sensitivity; import android.support.v4.util.LongSparseArray; @@ -16,12 +16,12 @@ import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 24.06.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/BGSourceFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/Source/BGSourceFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.java index 5c084eac29..211cbb0bb0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/BGSourceFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Source; +package info.nightscout.androidaps.plugins.source; import android.app.Activity; import android.content.DialogInterface; @@ -21,13 +21,13 @@ import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.BgReading; -import info.nightscout.androidaps.events.EventNewBG; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.T; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.T; /** * Created by mike on 16.10.2017. @@ -67,7 +67,7 @@ public class BGSourceFragment extends SubscriberFragment { } @Subscribe - public void onStatusEvent(final EventNewBG unused) { + public void onStatusEvent(final EventAutosensCalculationFinished unused) { updateGUI(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceDexcomG5Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceDexcomG5Plugin.java new file mode 100644 index 0000000000..3ba10564e6 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceDexcomG5Plugin.java @@ -0,0 +1,232 @@ +package info.nightscout.androidaps.plugins.source; + +import android.content.Intent; +import android.os.Bundle; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; + +import info.nightscout.androidaps.Constants; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.db.CareportalEvent; +import info.nightscout.androidaps.interfaces.BgSourceInterface; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginDescription; +import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.services.Intents; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; + +/** + * Created by mike on 28.11.2017. + */ + +public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterface { + private static Logger log = LoggerFactory.getLogger(L.BGSOURCE); + + private static SourceDexcomG5Plugin plugin = null; + + public static SourceDexcomG5Plugin getPlugin() { + if (plugin == null) + plugin = new SourceDexcomG5Plugin(); + return plugin; + } + + private SourceDexcomG5Plugin() { + super(new PluginDescription() + .mainType(PluginType.BGSOURCE) + .fragmentClass(BGSourceFragment.class.getName()) + .pluginName(R.string.DexcomG5) + .shortName(R.string.dexcomG5_shortname) + .preferencesId(R.xml.pref_bgsource) + .description(R.string.description_source_dexcom_g5) + ); + } + + @Override + public boolean advancedFilteringSupported() { + return true; + } + + @Override + public void handleNewData(Intent intent) { + // onHandleIntent Bundle{ data => [{"m_time":1511939180,"m_trend":"NotComputable","m_value":335}]; android.support.content.wakelockid => 95; }Bundle + + if (!isEnabled(PluginType.BGSOURCE)) return; + + if (intent.getAction().equals(Intents.DEXCOMG5_BG)) + handleNewDataOld(intent); + + if (intent.getAction().equals(Intents.DEXCOMG5_BG_NEW)) + handleNewDataNew(intent); + } + + public void handleNewDataOld(Intent intent) { + // onHandleIntent Bundle{ data => [{"m_time":1511939180,"m_trend":"NotComputable","m_value":335}]; android.support.content.wakelockid => 95; }Bundle + + Bundle bundle = intent.getExtras(); + if (bundle == null) return; + + BgReading bgReading = new BgReading(); + + String data = bundle.getString("data"); + if (L.isEnabled(L.BGSOURCE)) + log.debug("Received Dexcom Data", data); + + if (data == null) return; + + try { + JSONArray jsonArray = new JSONArray(data); + if (L.isEnabled(L.BGSOURCE)) + log.debug("Received Dexcom Data size:" + jsonArray.length()); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject json = jsonArray.getJSONObject(i); + bgReading.value = json.getInt("m_value"); + bgReading.direction = json.getString("m_trend"); + bgReading.date = json.getLong("m_time") * 1000L; + bgReading.raw = 0; + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5"); + if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { + NSUpload.uploadBg(bgReading, "AndroidAPS-DexcomG5"); + } + if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { + NSUpload.sendToXdrip(bgReading); + } + } + + } catch (JSONException e) { + log.error("Exception: ", e); + } + } + + public void handleNewDataNew(Intent intent) { + + Bundle bundle = intent.getExtras(); + if (bundle == null) return; + + if (L.isEnabled(L.BGSOURCE)) { + if (bundle.containsKey("transmitterSystemTime")) + log.debug("transmitterSystemTime: " + DateUtil.dateAndTimeFullString(bundle.getLong("transmitterSystemTime"))); + if (bundle.containsKey("transmitterRemainingTime")) + log.debug("transmitterRemainingTime: " + DateUtil.dateAndTimeFullString(bundle.getLong("transmitterRemainingTime"))); + log.debug("transmitterId: " + bundle.getString("transmitterId")); + if (bundle.containsKey("transmitterActivatedOn")) + log.debug("transmitterActivatedOn: " + DateUtil.dateAndTimeFullString(bundle.getLong("transmitterActivatedOn"))); + log.debug("transmitterVersion: " + bundle.getString("transmitterVersion")); + log.debug("transmitterSoftwareNumber: " + bundle.getString("transmitterSoftwareNumber")); + log.debug("transmitterStorageTimeDays: " + bundle.getInt("transmitterStorageTimeDays")); + log.debug("transmitterApiVersion: " + bundle.getInt("transmitterApiVersion")); + log.debug("transmitterMaxRuntimeDays: " + bundle.getInt("transmitterMaxRuntimeDays")); + log.debug("transmitterMaxStorageTimeDays: " + bundle.getInt("transmitterMaxStorageTimeDays")); + log.debug("transmitterCGMProcessorFirmwareVersion: " + bundle.getString("transmitterCGMProcessorFirmwareVersion")); + log.debug("transmitterBleRadioFirmwareVersion: " + bundle.getString("transmitterBleRadioFirmwareVersion")); + log.debug("transmitterHardwareVersion: " + bundle.getInt("transmitterHardwareVersion")); + log.debug("transmitterBleSoftDeviceVersion: " + bundle.getString("transmitterBleSoftDeviceVersion")); + log.debug("transmitterNordicAsicHwID: " + bundle.getInt("transmitterNordicAsicHwID")); + log.debug("transmitterSessionTimeDays: " + bundle.getInt("transmitterSessionTimeDays")); + log.debug("transmitterFeatureFlags: " + bundle.getInt("transmitterFeatureFlags")); + } + + if (bundle.containsKey("sensorInsertionTime")) { + long sensorInsertionTime = bundle.getLong("sensorInsertionTime"); + if (L.isEnabled(L.BGSOURCE)) + log.debug("sensorInsertionTime: " + DateUtil.dateAndTimeFullString(sensorInsertionTime)); + if (SP.getBoolean(R.string.key_dexcom_lognssensorchange, false)) { + try { + if (MainApp.getDbHelper().getCareportalEventFromTimestamp(sensorInsertionTime) == null) { + JSONObject data = new JSONObject(); + data.put("enteredBy", "AndroidAPS-DexcomG5"); + data.put("created_at", DateUtil.toISOString(sensorInsertionTime)); + data.put("eventType", CareportalEvent.SENSORCHANGE); + NSUpload.uploadCareportalEntryToNS(data); + } + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + } + } + + if (bundle.containsKey("glucoseValues")) { + int[] glucoseValues = bundle.getIntArray("glucoseValues"); + int[] glucoseRecordIDs = bundle.getIntArray("glucoseRecordIDs"); + long[] glucoseRecordedTimestamps = bundle.getLongArray("glucoseRecordedTimestamps"); + long[] glucoseSessionStartTimes = bundle.getLongArray("glucoseSessionStartTimes"); + long[] glucoseSystemTimestamps = bundle.getLongArray("glucoseSystemTimestamps"); + String[] glucoseTransmitterIDS = bundle.getStringArray("glucoseTransmitterIDS"); + long[] glucoseTransmitterTimestamps = bundle.getLongArray("glucoseTransmitterTimestamps"); + String[] glucoseTrendsArrows = bundle.getStringArray("glucoseTrendsArrows"); + boolean[] glucoseWasBackfilled = bundle.getBooleanArray("glucoseWasBackfilled"); + + if (L.isEnabled(L.BGSOURCE)) { + log.debug("glucoseValues", Arrays.toString(glucoseValues)); + log.debug("glucoseRecordIDs", Arrays.toString(glucoseRecordIDs)); + log.debug("glucoseRecordedTimestamps", Arrays.toString(glucoseRecordedTimestamps)); + log.debug("glucoseSessionStartTimes", Arrays.toString(glucoseSessionStartTimes)); + log.debug("glucoseSystemTimestamps", Arrays.toString(glucoseSystemTimestamps)); + log.debug("glucoseTransmitterIDS", Arrays.toString(glucoseTransmitterIDS)); + log.debug("glucoseTransmitterTimestamps", Arrays.toString(glucoseTransmitterTimestamps)); + log.debug("glucoseTrendsArrows", Arrays.toString(glucoseTrendsArrows)); + log.debug("glucoseWasBackfilled", Arrays.toString(glucoseWasBackfilled)); + } + + for (int i = 0; i < glucoseValues.length; i++) { + BgReading bgReading = new BgReading(); + bgReading.value = glucoseValues[i]; + bgReading.direction = glucoseTrendsArrows[i]; + bgReading.date = glucoseTransmitterTimestamps[i]; + bgReading.raw = 0; + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5"); + if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { + NSUpload.uploadBg(bgReading, "AndroidAPS-DexcomG5"); + } + if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { + NSUpload.sendToXdrip(bgReading); + } + } + } + + if (bundle.containsKey("meterValues")) { + String[] meterEntryTypes = bundle.getStringArray("meterEntryTypes"); + long[] meterTimestamps = bundle.getLongArray("meterTimestamps"); + int[] meterValues = bundle.getIntArray("meterValues"); + long[] meterRecordedTimestamps = bundle.getLongArray("meterRecordedTimestamps"); + int[] meterTransmitterIDs = bundle.getIntArray("meterTransmitterIDs"); + long[] meterTransmitterTimestamps = bundle.getLongArray("meterTransmitterTimestamps"); + + if (L.isEnabled(L.BGSOURCE)) { + log.debug("meterValues", Arrays.toString(meterValues)); + log.debug("meterEntryTypes", Arrays.toString(meterEntryTypes)); + log.debug("meterTimestamps", Arrays.toString(meterTimestamps)); + log.debug("meterTransmitterTimestamps", Arrays.toString(meterTransmitterTimestamps)); + log.debug("meterRecordedTimestamps", Arrays.toString(meterRecordedTimestamps)); + log.debug("meterTransmitterIDs", Arrays.toString(meterTransmitterIDs)); + } + + for (int i = 0; i < meterValues.length; i++) { + try { + if (MainApp.getDbHelper().getCareportalEventFromTimestamp(meterTimestamps[i]) == null) { + JSONObject data = new JSONObject(); + data.put("enteredBy", "AndroidAPS-DexcomG5"); + data.put("created_at", DateUtil.toISOString(meterTimestamps[i])); + data.put("eventType", CareportalEvent.BGCHECK); + data.put("glucoseType", "Finger"); + data.put("glucose", meterValues[i]); + data.put("units", Constants.MGDL); + NSUpload.uploadCareportalEntryToNS(data); + } + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + } + } + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceDexcomG6Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceDexcomG6Plugin.java new file mode 100644 index 0000000000..ad63a9b9ae --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceDexcomG6Plugin.java @@ -0,0 +1,174 @@ +package info.nightscout.androidaps.plugins.source; + +import android.content.Intent; +import android.os.Bundle; + +import org.json.JSONException; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; + +import info.nightscout.androidaps.Constants; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.db.CareportalEvent; +import info.nightscout.androidaps.interfaces.BgSourceInterface; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginDescription; +import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; + +/** + * Created by mike on 30.11.2018. + */ + +public class SourceDexcomG6Plugin extends PluginBase implements BgSourceInterface { + private static Logger log = LoggerFactory.getLogger(L.BGSOURCE); + + private static SourceDexcomG6Plugin plugin = null; + + public static SourceDexcomG6Plugin getPlugin() { + if (plugin == null) + plugin = new SourceDexcomG6Plugin(); + return plugin; + } + + private SourceDexcomG6Plugin() { + super(new PluginDescription() + .mainType(PluginType.BGSOURCE) + .fragmentClass(BGSourceFragment.class.getName()) + .pluginName(R.string.DexcomG6) + .shortName(R.string.dexcomG6_shortname) + .preferencesId(R.xml.pref_bgsource) + .description(R.string.description_source_dexcom_g6) + ); + } + + @Override + public boolean advancedFilteringSupported() { + return true; + } + + @Override + public void handleNewData(Intent intent) { + if (!isEnabled(PluginType.BGSOURCE)) return; + + Bundle bundle = intent.getExtras(); + if (bundle == null) return; + + if (L.isEnabled(L.BGSOURCE)) { + if (bundle.containsKey("transmitterSystemTime")) + log.debug("transmitterSystemTime: " + DateUtil.dateAndTimeFullString(bundle.getLong("transmitterSystemTime"))); + log.debug("transmitterId: " + bundle.getString("transmitterId")); + if (bundle.containsKey("transmitterActivatedOn")) + log.debug("transmitterActivatedOn: " + DateUtil.dateAndTimeFullString(bundle.getLong("transmitterActivatedOn"))); + log.debug("transmitterVersion: " + bundle.getString("transmitterVersion")); + log.debug("transmitterSoftwareNumber: " + bundle.getString("transmitterSoftwareNumber")); + log.debug("transmitterStorageTimeDays: " + bundle.getInt("transmitterStorageTimeDays")); + log.debug("transmitterApiVersion: " + bundle.getInt("transmitterApiVersion")); + log.debug("transmitterMaxRuntimeDays: " + bundle.getInt("transmitterMaxRuntimeDays")); + log.debug("transmitterMaxStorageTimeDays: " + bundle.getInt("transmitterMaxStorageTimeDays")); + log.debug("transmitterCGMProcessorFirmwareVersion: " + bundle.getString("transmitterCGMProcessorFirmwareVersion")); + log.debug("transmitterBleRadioFirmwareVersion: " + bundle.getString("transmitterBleRadioFirmwareVersion")); + log.debug("transmitterHardwareVersion: " + bundle.getInt("transmitterHardwareVersion")); + log.debug("transmitterBleSoftDeviceVersion: " + bundle.getString("transmitterBleSoftDeviceVersion")); + log.debug("transmitterNordicAsicHwID: " + bundle.getInt("transmitterNordicAsicHwID")); + log.debug("transmitterSessionTimeDays: " + bundle.getInt("transmitterSessionTimeDays")); + log.debug("transmitterFeatureFlags: " + bundle.getInt("transmitterFeatureFlags")); + + if (bundle.containsKey("sensorCode")) + log.debug("sensorCode: " + bundle.getString("sensorCode")); + } + + if (bundle.containsKey("sensorInsertionTime")) { + long sensorInsertionTime = bundle.getLong("sensorInsertionTime"); + if (L.isEnabled(L.BGSOURCE)) + log.debug("sensorInsertionTime: " + DateUtil.dateAndTimeFullString(sensorInsertionTime)); + if (SP.getBoolean(R.string.key_dexcom_lognssensorchange, false)) { + try { + if (MainApp.getDbHelper().getCareportalEventFromTimestamp(sensorInsertionTime) == null) { + JSONObject data = new JSONObject(); + data.put("enteredBy", "AndroidAPS-DexcomG6"); + data.put("created_at", DateUtil.toISOString(sensorInsertionTime)); + data.put("eventType", CareportalEvent.SENSORCHANGE); + NSUpload.uploadCareportalEntryToNS(data); + } + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + } + } + + if (bundle.containsKey("evgTimestamps")) { + long[] timestamps = bundle.getLongArray("evgTimestamps"); + long[] transmitterTimes = bundle.getLongArray("transmitterTimes"); + int[] evgs = bundle.getIntArray("evgs"); + int[] predictiveEVGs = bundle.getIntArray("predictiveEVGs"); + String[] trendArrows = bundle.getStringArray("trendArrows"); + + if (L.isEnabled(L.BGSOURCE)) { + log.debug("timestamps", Arrays.toString(timestamps)); + log.debug("transmitterTimes", Arrays.toString(transmitterTimes)); + log.debug("evgs", Arrays.toString(evgs)); + log.debug("predictiveEVGs", Arrays.toString(predictiveEVGs)); + log.debug("trendArrows", Arrays.toString(trendArrows)); + } + + for (int i = 0; i < transmitterTimes.length; i++) { + BgReading bgReading = new BgReading(); + bgReading.value = evgs[i]; + bgReading.direction = trendArrows[i]; + bgReading.date = timestamps[i]; + bgReading.raw = 0; + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG6"); + if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { + NSUpload.uploadBg(bgReading, "AndroidAPS-DexcomG6"); + } + if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { + NSUpload.sendToXdrip(bgReading); + } + } + } + + if (bundle.containsKey("meterValues")) { + int[] meterValues = bundle.getIntArray("meterValues"); + String[] meterEntryTypes = bundle.getStringArray("meterEntryTypes"); + long[] meterTimestamps = bundle.getLongArray("meterTimestamps"); + long[] meterTransmitterTimestamps = bundle.getLongArray("meterTransmitterTimestamps"); + long[] meterRecordedTimestamps = bundle.getLongArray("meterRecordedTimestamps"); + int[] meterRecordIDs = bundle.getIntArray("meterRecordIDs"); + + if (L.isEnabled(L.BGSOURCE)) { + log.debug("meterValues", Arrays.toString(meterValues)); + log.debug("meterEntryTypes", Arrays.toString(meterEntryTypes)); + log.debug("meterTimestamps", Arrays.toString(meterTimestamps)); + log.debug("meterTransmitterTimestamps", Arrays.toString(meterTransmitterTimestamps)); + log.debug("meterRecordedTimestamps", Arrays.toString(meterRecordedTimestamps)); + log.debug("meterRecordIDs", Arrays.toString(meterRecordIDs)); + } + + for (int i = 0; i < meterValues.length; i++) { + try { + if (MainApp.getDbHelper().getCareportalEventFromTimestamp(meterTimestamps[i]) == null) { + JSONObject data = new JSONObject(); + data.put("enteredBy", "AndroidAPS-DexcomG6"); + data.put("created_at", DateUtil.toISOString(meterTimestamps[i])); + data.put("eventType", CareportalEvent.BGCHECK); + data.put("glucoseType", "Finger"); + data.put("glucose", meterValues[i]); + data.put("units", Constants.MGDL); + NSUpload.uploadCareportalEntryToNS(data); + } + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + } + } + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceEversensePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceEversensePlugin.java new file mode 100644 index 0000000000..6f39e3d762 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceEversensePlugin.java @@ -0,0 +1,154 @@ +package info.nightscout.androidaps.plugins.source; + +import android.content.Intent; +import android.os.Bundle; + +import org.json.JSONException; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; + +import info.nightscout.androidaps.Constants; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.db.CareportalEvent; +import info.nightscout.androidaps.interfaces.BgSourceInterface; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginDescription; +import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; + +/** + * Created by mike on 28.11.2017. + */ + +public class SourceEversensePlugin extends PluginBase implements BgSourceInterface { + private static Logger log = LoggerFactory.getLogger(L.BGSOURCE); + + private static SourceEversensePlugin plugin = null; + + public static SourceEversensePlugin getPlugin() { + if (plugin == null) + plugin = new SourceEversensePlugin(); + return plugin; + } + + private SourceEversensePlugin() { + super(new PluginDescription() + .mainType(PluginType.BGSOURCE) + .fragmentClass(BGSourceFragment.class.getName()) + .pluginName(R.string.eversense) + .shortName(R.string.eversense_shortname) + .preferencesId(R.xml.pref_poctech) + .description(R.string.description_source_eversense) + ); + } + + @Override + public boolean advancedFilteringSupported() { + return false; + } + + @Override + public void handleNewData(Intent intent) { + + if (!isEnabled(PluginType.BGSOURCE)) return; + + Bundle bundle = intent.getExtras(); + if (bundle == null) return; + + if (L.isEnabled(L.BGSOURCE)) { + if (bundle.containsKey("currentCalibrationPhase")) + log.debug("currentCalibrationPhase: " + bundle.getString("currentCalibrationPhase")); + if (bundle.containsKey("placementModeInProgress")) + log.debug("placementModeInProgress: " + bundle.getBoolean("placementModeInProgress")); + if (bundle.containsKey("glucoseLevel")) + log.debug("glucoseLevel: " + bundle.getInt("glucoseLevel")); + if (bundle.containsKey("glucoseTrendDirection")) + log.debug("glucoseTrendDirection: " + bundle.getString("glucoseTrendDirection")); + if (bundle.containsKey("glucoseTimestamp")) + log.debug("glucoseTimestamp: " + DateUtil.dateAndTimeFullString(bundle.getLong("glucoseTimestamp"))); + if (bundle.containsKey("batteryLevel")) + log.debug("batteryLevel: " + bundle.getString("batteryLevel")); + if (bundle.containsKey("signalStrength")) + log.debug("signalStrength: " + bundle.getString("signalStrength")); + if (bundle.containsKey("transmitterVersionNumber")) + log.debug("transmitterVersionNumber: " + bundle.getString("transmitterVersionNumber")); + if (bundle.containsKey("isXLVersion")) + log.debug("isXLVersion: " + bundle.getBoolean("isXLVersion")); + if (bundle.containsKey("transmitterModelNumber")) + log.debug("transmitterModelNumber: " + bundle.getString("transmitterModelNumber")); + if (bundle.containsKey("transmitterSerialNumber")) + log.debug("transmitterSerialNumber: " + bundle.getString("transmitterSerialNumber")); + if (bundle.containsKey("transmitterAddress")) + log.debug("transmitterAddress: " + bundle.getString("transmitterAddress")); + if (bundle.containsKey("sensorInsertionTimestamp")) + log.debug("sensorInsertionTimestamp: " + DateUtil.dateAndTimeFullString(bundle.getLong("sensorInsertionTimestamp"))); + if (bundle.containsKey("transmitterVersionNumber")) + log.debug("transmitterVersionNumber: " + bundle.getString("transmitterVersionNumber")); + if (bundle.containsKey("transmitterConnectionState")) + log.debug("transmitterConnectionState: " + bundle.getString("transmitterConnectionState")); + } + + if (bundle.containsKey("glucoseLevels")) { + int[] glucoseLevels = bundle.getIntArray("glucoseLevels"); + int[] glucoseRecordNumbers = bundle.getIntArray("glucoseRecordNumbers"); + long[] glucoseTimestamps = bundle.getLongArray("glucoseTimestamps"); + + if (L.isEnabled(L.BGSOURCE)) { + log.debug("glucoseLevels", Arrays.toString(glucoseLevels)); + log.debug("glucoseRecordNumbers", Arrays.toString(glucoseRecordNumbers)); + log.debug("glucoseTimestamps", Arrays.toString(glucoseTimestamps)); + } + + for (int i = 0; i < glucoseLevels.length; i++) { + BgReading bgReading = new BgReading(); + bgReading.value = glucoseLevels[i]; + bgReading.date = glucoseTimestamps[i]; + bgReading.raw = 0; + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "Eversense"); + if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { + NSUpload.uploadBg(bgReading, "AndroidAPS-Eversense"); + } + if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { + NSUpload.sendToXdrip(bgReading); + } + } + } + + if (bundle.containsKey("calibrationGlucoseLevels")) { + int[] calibrationGlucoseLevels = bundle.getIntArray("calibrationGlucoseLevels"); + long[] calibrationTimestamps = bundle.getLongArray("calibrationTimestamps"); + long[] calibrationRecordNumbers = bundle.getLongArray("calibrationRecordNumbers"); + + if (L.isEnabled(L.BGSOURCE)) { + log.debug("calibrationGlucoseLevels", Arrays.toString(calibrationGlucoseLevels)); + log.debug("calibrationTimestamps", Arrays.toString(calibrationTimestamps)); + log.debug("calibrationRecordNumbers", Arrays.toString(calibrationRecordNumbers)); + } + + for (int i = 0; i < calibrationGlucoseLevels.length; i++) { + try { + if (MainApp.getDbHelper().getCareportalEventFromTimestamp(calibrationTimestamps[i]) == null) { + JSONObject data = new JSONObject(); + data.put("enteredBy", "AndroidAPS-Eversense"); + data.put("created_at", DateUtil.toISOString(calibrationTimestamps[i])); + data.put("eventType", CareportalEvent.BGCHECK); + data.put("glucoseType", "Finger"); + data.put("glucose", calibrationGlucoseLevels[i]); + data.put("units", Constants.MGDL); + NSUpload.uploadCareportalEntryToNS(data); + } + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + } + } + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceGlimpPlugin.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/source/SourceGlimpPlugin.java index 07fdba51ee..243fe60070 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceGlimpPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Source; +package info.nightscout.androidaps.plugins.source; import android.content.Intent; import android.os.Bundle; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceMM640gPlugin.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/source/SourceMM640gPlugin.java index 8bc6811ef4..daccbcedd7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceMM640gPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Source; +package info.nightscout.androidaps.plugins.source; import android.content.Intent; import android.os.Bundle; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceNSClientPlugin.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/source/SourceNSClientPlugin.java index de110edd4e..328f054aad 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceNSClientPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Source; +package info.nightscout.androidaps.plugins.source; import android.content.Intent; import android.os.Bundle; @@ -8,7 +8,6 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.BgReading; @@ -17,10 +16,10 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv; -import info.nightscout.utils.JsonHelper; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSSgv; +import info.nightscout.androidaps.utils.JsonHelper; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 05.08.2016. @@ -99,7 +98,7 @@ public class SourceNSClientPlugin extends PluginBase implements BgSourceInterfac public void detectSource(String source, long timeStamp) { if (timeStamp > lastBGTimeStamp) { - if (source.contains("G5 Native") || source.contains("G6 Native") || source.contains("AndroidAPS-DexcomG5")) + if (source.contains("G5 Native") || source.contains("G6 Native") || source.contains("AndroidAPS-DexcomG5") || source.contains("AndroidAPS-DexcomG6")) isAdvancedFilteringEnabled = true; else isAdvancedFilteringEnabled = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourcePoctechPlugin.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/source/SourcePoctechPlugin.java index df390522d3..ceecfb844f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourcePoctechPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Source; +package info.nightscout.androidaps.plugins.source; import android.content.Intent; import android.os.Bundle; @@ -9,7 +9,6 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -19,9 +18,9 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.utils.JsonHelper; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.JsonHelper; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 05.08.2016. @@ -80,7 +79,7 @@ public class SourcePoctechPlugin extends PluginBase implements BgSourceInterface bgReading.value = bgReading.value * Constants.MMOLL_TO_MGDL; boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "Poctech"); if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { - NSUpload.uploadBg(bgReading); + NSUpload.uploadBg(bgReading, "AndroidAPS-Poctech"); } if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { NSUpload.sendToXdrip(bgReading); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceTomatoPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceTomatoPlugin.java new file mode 100644 index 0000000000..211ec9a5a2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceTomatoPlugin.java @@ -0,0 +1,74 @@ +package info.nightscout.androidaps.plugins.source; + +import android.content.Intent; +import android.os.Bundle; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.interfaces.BgSourceInterface; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginDescription; +import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.utils.SP; + +/** + * Created by mike on 05.08.2016. + */ +public class SourceTomatoPlugin extends PluginBase implements BgSourceInterface { + private static Logger log = LoggerFactory.getLogger(L.BGSOURCE); + + private static SourceTomatoPlugin plugin = null; + + public static SourceTomatoPlugin getPlugin() { + if (plugin == null) + plugin = new SourceTomatoPlugin(); + return plugin; + } + + private SourceTomatoPlugin() { + super(new PluginDescription() + .mainType(PluginType.BGSOURCE) + .fragmentClass(BGSourceFragment.class.getName()) + .pluginName(R.string.tomato) + .preferencesId(R.xml.pref_poctech) + .shortName(R.string.tomato_short) + .description(R.string.description_source_tomato) + ); + } + + @Override + public boolean advancedFilteringSupported() { + return false; + } + + @Override + public void handleNewData(Intent intent) { + + if (!isEnabled(PluginType.BGSOURCE)) return; + + Bundle bundle = intent.getExtras(); + if (bundle == null) return; + + BgReading bgReading = new BgReading(); + + if (L.isEnabled(L.BGSOURCE)) + log.debug("Received Tomato Data"); + + bgReading.value = bundle.getDouble("com.fanqies.tomatofn.Extras.BgEstimate"); + bgReading.date = bundle.getLong("com.fanqies.tomatofn.Extras.Time"); + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "Tomato"); + if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { + NSUpload.uploadBg(bgReading, "AndroidAPS-Tomato"); + } + if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { + NSUpload.sendToXdrip(bgReading); + } + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceXdripPlugin.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/source/SourceXdripPlugin.java index a81bad41f4..1acefa724e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/SourceXdripPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Source; +package info.nightscout.androidaps.plugins.source; import android.content.Intent; import android.os.Bundle; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/CarbsGenerator.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/CarbsGenerator.java similarity index 79% rename from app/src/main/java/info/nightscout/androidaps/plugins/Treatments/CarbsGenerator.java rename to app/src/main/java/info/nightscout/androidaps/plugins/treatments/CarbsGenerator.java index 90436f5eb2..33b58e46cf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/CarbsGenerator.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/CarbsGenerator.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Treatments; +package info.nightscout.androidaps.plugins.treatments; import android.content.Intent; import android.support.annotation.Nullable; @@ -8,11 +8,12 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.Source; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity; import info.nightscout.androidaps.queue.Callback; +import info.nightscout.androidaps.utils.T; -import static info.nightscout.utils.DateUtil.now; +import static info.nightscout.androidaps.utils.DateUtil.now; public class CarbsGenerator { public static void generateCarbs(int amount, long startTime, int duration, @Nullable String notes) { @@ -35,7 +36,7 @@ public class CarbsGenerator { carbInfo.context = MainApp.instance(); carbInfo.source = Source.USER; carbInfo.notes = notes; - if (ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().storesCarbInfo && carbInfo.date <= now()) { + if (ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().storesCarbInfo && carbInfo.date <= now() && carbInfo.date > now()- T.mins(2).msecs()) { ConfigBuilderPlugin.getPlugin().getCommandQueue().bolus(carbInfo, new Callback() { @Override public void run() { @@ -50,6 +51,8 @@ public class CarbsGenerator { } }); } else { + // Don't send to pump if it is in the future or more than 5 minutes in the past + // as pumps might return those as as "now" when reading the history. TreatmentsPlugin.getPlugin().addToHistoryTreatment(carbInfo, false); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/Treatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/Treatment.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/Treatments/Treatment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/treatments/Treatment.java index bd3526c043..dbf1a89c37 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/Treatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/Treatment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Treatments; +package info.nightscout.androidaps.plugins.treatments; import android.graphics.Color; import android.support.annotation.Nullable; @@ -8,8 +8,6 @@ import com.j256.ormlite.table.DatabaseTable; import org.json.JSONException; import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.Date; import java.util.Objects; @@ -18,16 +16,15 @@ import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Iob; -import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.interfaces.InsulinInterface; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.JsonHelper; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface; +import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.JsonHelper; @DatabaseTable(tableName = Treatment.TABLE_TREATMENTS) public class Treatment implements DataPointWithLabelInterface { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentService.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java similarity index 99% rename from app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentService.java rename to app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java index 8c01db13fd..7bb4774911 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Treatments; +package info.nightscout.androidaps.plugins.treatments; import android.content.Intent; import android.os.IBinder; @@ -15,7 +15,6 @@ import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; import com.squareup.otto.Subscribe; -import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; @@ -38,8 +37,8 @@ import info.nightscout.androidaps.events.EventNsTreatment; import info.nightscout.androidaps.events.EventReloadTreatmentData; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData; -import info.nightscout.utils.JsonHelper; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData; +import info.nightscout.androidaps.utils.JsonHelper; /** diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsFragment.java similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsFragment.java index 32feb9fe7f..d30565b4a7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Treatments; +package info.nightscout.androidaps.plugins.treatments; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -10,21 +10,18 @@ import android.widget.TextView; import com.squareup.otto.Subscribe; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventExtendedBolusChange; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsBolusFragment; -import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsCareportalFragment; -import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsExtendedBolusesFragment; -import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsProfileSwitchFragment; -import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsTempTargetFragment; -import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsTemporaryBasalsFragment; -import info.nightscout.utils.FabricPrivacy; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsBolusFragment; +import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsCareportalFragment; +import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsExtendedBolusesFragment; +import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsProfileSwitchFragment; +import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsTempTargetFragment; +import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsTemporaryBasalsFragment; +import info.nightscout.androidaps.utils.FabricPrivacy; public class TreatmentsFragment extends SubscriberFragment implements View.OnClickListener { TextView treatmentsTab; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java index aeacddb89c..e176553a6a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Treatments; +package info.nightscout.androidaps.plugins.treatments; import android.content.Intent; import android.support.annotation.Nullable; @@ -39,20 +39,20 @@ import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityAAPSPlugin; -import info.nightscout.androidaps.plugins.Sensitivity.SensitivityWeightedAveragePlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.SP; -import info.nightscout.utils.T; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin; +import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.T; /** * Created by mike on 05.08.2016. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/dialogs/WizardInfoDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/Treatments/dialogs/WizardInfoDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.java index 25ffc946a2..c38672311b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/dialogs/WizardInfoDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Treatments.dialogs; +package info.nightscout.androidaps.plugins.treatments.dialogs; import android.os.Bundle; import android.support.v4.app.DialogFragment; @@ -6,17 +6,15 @@ import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.view.Window; import android.view.WindowManager; import android.widget.CheckBox; import android.widget.TextView; import org.json.JSONObject; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.JsonHelper; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.JsonHelper; public class WizardInfoDialog extends DialogFragment implements OnClickListener { JSONObject json; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileGraph.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileGraph.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileGraph.java rename to app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileGraph.java index 99019e5fd7..dd9e820907 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileGraph.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileGraph.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Treatments.fragments; +package info.nightscout.androidaps.plugins.treatments.fragments; import android.content.Context; import android.util.AttributeSet; @@ -11,7 +11,7 @@ import java.util.ArrayList; import java.util.List; import info.nightscout.androidaps.data.Profile; -import info.nightscout.utils.Round; +import info.nightscout.androidaps.utils.Round; /** * Created by Adrian on 15.04.2018. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.java index c2263d81b5..c8db29b617 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Treatments.fragments; +package info.nightscout.androidaps.plugins.treatments.fragments; import android.os.Bundle; import android.support.v4.app.DialogFragment; @@ -9,19 +9,15 @@ import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import butterknife.BindView; import butterknife.ButterKnife; import butterknife.Unbinder; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.ProfileSwitch; -import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; /** * Created by adrian on 17/08/17. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.java index b99ad97685..64e93f3f95 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Treatments.fragments; +package info.nightscout.androidaps.plugins.treatments.fragments; import android.app.Activity; import android.content.Context; @@ -21,8 +21,6 @@ import android.widget.TextView; import com.crashlytics.android.answers.CustomEvent; import com.squareup.otto.Subscribe; -import org.json.JSONObject; - import java.util.List; import info.nightscout.androidaps.MainApp; @@ -30,22 +28,22 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Iob; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.Source; -import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventTreatmentChange; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; -import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.androidaps.plugins.Treatments.dialogs.WizardInfoDialog; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; +import info.nightscout.androidaps.plugins.treatments.Treatment; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.treatments.dialogs.WizardInfoDialog; import info.nightscout.androidaps.services.Intents; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.SP; -import static info.nightscout.utils.DateUtil.now; +import static info.nightscout.androidaps.utils.DateUtil.now; public class TreatmentsBolusFragment extends SubscriberFragment implements View.OnClickListener { RecyclerView recyclerView; @@ -268,7 +266,7 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View. } @Subscribe - public void onStatusEvent(final EventNewBG ev) { + public void onStatusEvent(final EventAutosensCalculationFinished ev) { updateGUI(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsCareportalFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsCareportalFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.java index 56709963f7..2f45f67c3b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsCareportalFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Treatments.fragments; +package info.nightscout.androidaps.plugins.treatments.fragments; import android.app.Activity; import android.content.Context; @@ -25,12 +25,12 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.services.Intents; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.events.EventCareportalEventChange; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; -import info.nightscout.utils.DateUtil; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.SP; -import info.nightscout.utils.Translator; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.Translator; /** * Created by mike on 13/01/17. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsExtendedBolusesFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsExtendedBolusesFragment.java similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsExtendedBolusesFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsExtendedBolusesFragment.java index 037a1a0023..93f2a64006 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsExtendedBolusesFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsExtendedBolusesFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Treatments.fragments; +package info.nightscout.androidaps.plugins.treatments.fragments; import android.app.Activity; import android.content.Context; @@ -25,14 +25,14 @@ import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.events.EventExtendedBolusChange; -import info.nightscout.androidaps.events.EventNewBG; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.FabricPrivacy; public class TreatmentsExtendedBolusesFragment extends SubscriberFragment { @@ -186,7 +186,7 @@ public class TreatmentsExtendedBolusesFragment extends SubscriberFragment { } @Subscribe - public void onStatusEvent(final EventNewBG ev) { + public void onStatusEvent(final EventAutosensCalculationFinished ev) { updateGUI(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.java index 0edc704eb6..5da86217f0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Treatments.fragments; +package info.nightscout.androidaps.plugins.treatments.fragments; import android.app.Activity; import android.content.Context; @@ -28,18 +28,18 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.services.Intents; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.events.EventProfileSwitchChange; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 13/01/17. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempTargetFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.java similarity index 94% rename from app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempTargetFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.java index d60dfc9e4c..eda62a8318 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempTargetFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Treatments.fragments; +package info.nightscout.androidaps.plugins.treatments.fragments; import android.app.Activity; import android.content.Context; @@ -21,19 +21,19 @@ import com.squareup.otto.Subscribe; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.services.Intents; import info.nightscout.androidaps.data.Intervals; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.events.EventTempTargetChange; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 13/01/17. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTemporaryBasalsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTemporaryBasalsFragment.java similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTemporaryBasalsFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTemporaryBasalsFragment.java index 3185bd81ac..b928263ed5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTemporaryBasalsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTemporaryBasalsFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Treatments.fragments; +package info.nightscout.androidaps.plugins.treatments.fragments; import android.app.Activity; import android.content.Context; @@ -25,16 +25,16 @@ import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventTempBasalChange; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.FabricPrivacy; public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment { @@ -87,7 +87,7 @@ public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment { if (tempBasal.isAbsolute) { Profile profile = ProfileFunctions.getInstance().getProfile(tempBasal.date); if (profile != null) { - holder.absolute.setText(DecimalFormatter.to0Decimal(tempBasal.tempBasalConvertedToAbsolute(tempBasal.date, profile), " U/h")); + holder.absolute.setText(DecimalFormatter.to2Decimal(tempBasal.tempBasalConvertedToAbsolute(tempBasal.date, profile), " U/h")); holder.percent.setText(""); } else { holder.absolute.setText(MainApp.gs(R.string.noprofile)); @@ -212,7 +212,7 @@ public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment { } @Subscribe - public void onStatusEvent(final EventNewBG ignored) { + public void onStatusEvent(final EventAutosensCalculationFinished ignored) { updateGUI(); } diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java index 2ef2d5198a..eee92177ab 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java @@ -21,20 +21,21 @@ import info.nightscout.androidaps.events.EventBolusRequested; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; -import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressHelperActivity; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.BolusProgressDialog; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.BolusProgressHelperActivity; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusprogressIfRunning; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.commands.Command; import info.nightscout.androidaps.queue.commands.CommandBolus; import info.nightscout.androidaps.queue.commands.CommandCancelExtendedBolus; import info.nightscout.androidaps.queue.commands.CommandCancelTempBasal; import info.nightscout.androidaps.queue.commands.CommandExtendedBolus; +import info.nightscout.androidaps.queue.commands.CommandInsightSetTBROverNotification; import info.nightscout.androidaps.queue.commands.CommandLoadEvents; import info.nightscout.androidaps.queue.commands.CommandLoadHistory; import info.nightscout.androidaps.queue.commands.CommandLoadTDDs; @@ -42,6 +43,8 @@ import info.nightscout.androidaps.queue.commands.CommandReadStatus; import info.nightscout.androidaps.queue.commands.CommandSMBBolus; import info.nightscout.androidaps.queue.commands.CommandSetProfile; import info.nightscout.androidaps.queue.commands.CommandSetUserSettings; +import info.nightscout.androidaps.queue.commands.CommandStartPump; +import info.nightscout.androidaps.queue.commands.CommandStopPump; import info.nightscout.androidaps.queue.commands.CommandTempBasalAbsolute; import info.nightscout.androidaps.queue.commands.CommandTempBasalPercent; @@ -96,7 +99,7 @@ public class CommandQueue { } private synchronized void removeAll(Command.CommandType type) { - for (int i = 0; i < queue.size(); i++) { + for (int i = queue.size() - 1; i >= 0; i--) { if (queue.get(i).commandType == type) { queue.remove(i); } @@ -239,6 +242,21 @@ public class CommandQueue { return true; } + public void stopPump(Callback callback) { + add(new CommandStopPump(callback)); + notifyAboutNewCommand(); + } + + public void startPump(Callback callback) { + add(new CommandStartPump(callback)); + notifyAboutNewCommand(); + } + + public void setTBROverNotification(Callback callback, boolean enable) { + add(new CommandInsightSetTBROverNotification(callback, enable)); + notifyAboutNewCommand(); + } + public synchronized void cancelAllBoluses() { if (!isRunning(Command.CommandType.BOLUS)) { MainApp.bus().post(new EventDismissBolusprogressIfRunning(new PumpEnactResult().success(true).enacted(false))); diff --git a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java index 7c95498db4..c6aaab43b7 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java @@ -2,7 +2,6 @@ package info.nightscout.androidaps.queue; import android.bluetooth.BluetoothAdapter; import android.content.Context; -import android.content.ContextWrapper; import android.os.PowerManager; import android.os.SystemClock; @@ -15,10 +14,10 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusprogressIfRunning; import info.nightscout.androidaps.queue.events.EventQueueChanged; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 09.11.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java index 7207f5b8d1..97a7e68521 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java @@ -25,7 +25,10 @@ public abstract class Command { READSTATUS, LOADHISTORY, // TDDs and so far only Dana specific LOADEVENTS, // so far only Dana specific - SETUSERSETTINGS // so far only Dana specific + SETUSERSETTINGS, // so far only Dana specific, + START_PUMP, + STOP_PUMP, + INSIGHT_SET_TBR_OVER_ALARM } public CommandType commandType; diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandBolus.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandBolus.java index c239502187..1ce11dd359 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandBolus.java @@ -7,11 +7,11 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.overview.Dialogs.BolusProgressDialog; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusprogressIfRunning; import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.DecimalFormatter; /** * Created by mike on 09.11.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCancelExtendedBolus.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCancelExtendedBolus.java index 8dca488890..84ff1942a5 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCancelExtendedBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCancelExtendedBolus.java @@ -5,7 +5,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.queue.Callback; /** diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCancelTempBasal.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCancelTempBasal.java index 241ae015fb..d6ef30ed36 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCancelTempBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCancelTempBasal.java @@ -5,7 +5,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.queue.Callback; /** diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandExtendedBolus.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandExtendedBolus.java index ea513bbb6c..7609973cf0 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandExtendedBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandExtendedBolus.java @@ -5,7 +5,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.queue.Callback; /** diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandInsightSetTBROverNotification.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandInsightSetTBROverNotification.java new file mode 100644 index 0000000000..e65aa31a29 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandInsightSetTBROverNotification.java @@ -0,0 +1,32 @@ +package info.nightscout.androidaps.queue.commands; + +import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin; +import info.nightscout.androidaps.queue.Callback; + +public class CommandInsightSetTBROverNotification extends Command { + + private boolean enabled; + + public CommandInsightSetTBROverNotification(Callback callback, boolean enabled) { + commandType = CommandType.INSIGHT_SET_TBR_OVER_ALARM; + this.callback = callback; + this.enabled = enabled; + } + + @Override + public void execute() { + PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); + if (pump instanceof LocalInsightPlugin) { + PumpEnactResult result = ((LocalInsightPlugin) pump).setTBROverNotification(enabled); + if (callback != null) callback.result(result).run(); + } + } + + @Override + public String status() { + return "INSIGHTSETTBROVERNOTIFICATION"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadEvents.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadEvents.java index 0742075035..30791a1831 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadEvents.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadEvents.java @@ -7,7 +7,7 @@ import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.interfaces.DanaRInterface; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.queue.Callback; /** diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadHistory.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadHistory.java index 01ec6e1f16..fc6fd49d8f 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadHistory.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadHistory.java @@ -7,7 +7,7 @@ import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.interfaces.DanaRInterface; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.queue.Callback; /** diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadTDDs.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadTDDs.java index c072766310..e70b5f2261 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadTDDs.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadTDDs.java @@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.queue.Callback; /** diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandReadStatus.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandReadStatus.java index 7e5bded5ee..070aec809e 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandReadStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandReadStatus.java @@ -6,10 +6,10 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.LocalAlertUtils; -import info.nightscout.utils.T; +import info.nightscout.androidaps.utils.LocalAlertUtils; +import info.nightscout.androidaps.utils.T; /** * Created by mike on 09.11.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.java index 1bd958866e..4586389dc1 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.java @@ -6,12 +6,12 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.T; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.DecimalFormatter; +import info.nightscout.androidaps.utils.T; /** * Created by mike on 09.11.2017. diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetProfile.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetProfile.java index a9bf7258e3..6b8a610fa6 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetProfile.java @@ -11,9 +11,9 @@ import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; /** diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetUserSettings.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetUserSettings.java index c1bf69ce01..643dbed3ab 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetUserSettings.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetUserSettings.java @@ -7,7 +7,7 @@ import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.interfaces.DanaRInterface; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.queue.Callback; /** diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandStartPump.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandStartPump.java new file mode 100644 index 0000000000..24694a1778 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandStartPump.java @@ -0,0 +1,29 @@ +package info.nightscout.androidaps.queue.commands; + +import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin; +import info.nightscout.androidaps.queue.Callback; + +public class CommandStartPump extends Command { + + public CommandStartPump(Callback callback) { + commandType = CommandType.START_PUMP; + this.callback = callback; + } + + @Override + public void execute() { + PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); + if (pump instanceof LocalInsightPlugin) { + PumpEnactResult result = ((LocalInsightPlugin) pump).startPump(); + if (callback != null) callback.result(result).run(); + } + } + + @Override + public String status() { + return "STARTPUMP"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandStopPump.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandStopPump.java new file mode 100644 index 0000000000..6f1cd8ec77 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandStopPump.java @@ -0,0 +1,29 @@ +package info.nightscout.androidaps.queue.commands; + +import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin; +import info.nightscout.androidaps.queue.Callback; + +public class CommandStopPump extends Command { + + public CommandStopPump(Callback callback) { + commandType = CommandType.STOP_PUMP; + this.callback = callback; + } + + @Override + public void execute() { + PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); + if (pump instanceof LocalInsightPlugin) { + PumpEnactResult result = ((LocalInsightPlugin) pump).stopPump(); + if (callback != null) callback.result(result).run(); + } + } + + @Override + public String status() { + return "STOPPUMP"; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalAbsolute.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalAbsolute.java index 9e75fd0713..1e36a1ab04 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalAbsolute.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalAbsolute.java @@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.queue.Callback; /** diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java index 2bc44e269e..68da3b9865 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java @@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.queue.Callback; /** diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java index cc36f21a59..d6d9bb5fcb 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java @@ -18,13 +18,13 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.events.EventProfileSwitchChange; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.queue.commands.Command; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.FabricPrivacy; -import info.nightscout.utils.LocalAlertUtils; -import info.nightscout.utils.T; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.FabricPrivacy; +import info.nightscout.androidaps.utils.LocalAlertUtils; +import info.nightscout.androidaps.utils.T; /** diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java index d167bb9510..19d54b14aa 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java @@ -12,10 +12,10 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSAlarm; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.services.Intents; public class NSAlarmReceiver extends BroadcastReceiver { diff --git a/app/src/main/java/info/nightscout/androidaps/services/DataService.java b/app/src/main/java/info/nightscout/androidaps/services/DataService.java index cfc564770d..b98ff6bf94 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/services/DataService.java @@ -17,24 +17,27 @@ import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.events.EventNsFood; import info.nightscout.androidaps.events.EventNsTreatment; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSMbg; -import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync; -import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; -import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin; -import info.nightscout.androidaps.plugins.Source.SourceGlimpPlugin; -import info.nightscout.androidaps.plugins.Source.SourceMM640gPlugin; -import info.nightscout.androidaps.plugins.Source.SourceNSClientPlugin; -import info.nightscout.androidaps.plugins.Source.SourcePoctechPlugin; -import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSMbg; +import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin; +import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRNSHistorySync; +import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin; +import info.nightscout.androidaps.plugins.source.SourceDexcomG5Plugin; +import info.nightscout.androidaps.plugins.source.SourceDexcomG6Plugin; +import info.nightscout.androidaps.plugins.source.SourceEversensePlugin; +import info.nightscout.androidaps.plugins.source.SourceGlimpPlugin; +import info.nightscout.androidaps.plugins.source.SourceMM640gPlugin; +import info.nightscout.androidaps.plugins.source.SourceNSClientPlugin; +import info.nightscout.androidaps.plugins.source.SourcePoctechPlugin; +import info.nightscout.androidaps.plugins.source.SourceTomatoPlugin; +import info.nightscout.androidaps.plugins.source.SourceXdripPlugin; import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.logging.BundleLogger; -import info.nightscout.utils.JsonHelper; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.JsonHelper; +import info.nightscout.androidaps.utils.SP; public class DataService extends IntentService { @@ -68,8 +71,16 @@ public class DataService extends IntentService { SourceGlimpPlugin.getPlugin().handleNewData(intent); } else if (Intents.DEXCOMG5_BG.equals(action)) { SourceDexcomG5Plugin.getPlugin().handleNewData(intent); + } else if (Intents.DEXCOMG5_BG_NEW.equals(action)) { + SourceDexcomG5Plugin.getPlugin().handleNewData(intent); + } else if (Intents.DEXCOMG6_BG.equals(action)) { + SourceDexcomG6Plugin.getPlugin().handleNewData(intent); } else if (Intents.POCTECH_BG.equals(action)) { SourcePoctechPlugin.getPlugin().handleNewData(intent); + } else if (Intents.TOMATO_BG.equals(action)) { + SourceTomatoPlugin.getPlugin().handleNewData(intent); + } else if (Intents.EVERSENSE_BG.equals(action)) { + SourceEversensePlugin.getPlugin().handleNewData(intent); } else if (Intents.ACTION_NEW_SGV.equals(action)) { SourceNSClientPlugin.getPlugin().handleNewData(intent); } else if (Intents.ACTION_NEW_PROFILE.equals(action)) { diff --git a/app/src/main/java/info/nightscout/androidaps/services/Intents.java b/app/src/main/java/info/nightscout/androidaps/services/Intents.java index 6d3daf1ea9..5011215b45 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/Intents.java +++ b/app/src/main/java/info/nightscout/androidaps/services/Intents.java @@ -49,6 +49,10 @@ public interface Intents { String GLIMP_BG = "it.ct.glicemia.ACTION_GLUCOSE_MEASURED"; String DEXCOMG5_BG = "com.dexcom.cgm.DATA"; + String DEXCOMG5_BG_NEW = "com.dexcom.cgm.g5.AndroidAPSEVGCallback.BROADCAST"; + String DEXCOMG6_BG = "com.dexcom.cgm.AndroidAPSEVGCallback.BROADCAST"; + String EVERSENSE_BG = "com.senseonics.AndroidAPSEventSubscriber.BROADCAST"; String POCTECH_BG = "com.china.poctech.data"; + String TOMATO_BG = "com.fanqies.tomatofn.BgEstimate"; } diff --git a/app/src/main/java/info/nightscout/androidaps/services/LocationService.java b/app/src/main/java/info/nightscout/androidaps/services/LocationService.java index 2af3593ffa..b2d40b02bc 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/LocationService.java +++ b/app/src/main/java/info/nightscout/androidaps/services/LocationService.java @@ -17,7 +17,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventLocationChange; import info.nightscout.androidaps.logging.L; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; public class LocationService extends Service { private static Logger log = LoggerFactory.getLogger(L.LOCATION); diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java index c1421d7f0c..1d143d073f 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java @@ -21,24 +21,24 @@ import info.nightscout.androidaps.events.EventConfigBuilderChange; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; -import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; -import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesFragment; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.Maintenance.ImportExportPrefs; -import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus; -import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment; -import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfilePlugin; -import info.nightscout.androidaps.plugins.ProfileNS.NSProfileFragment; -import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; -import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfileFragment; -import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfilePlugin; +import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment; +import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog; +import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesFragment; +import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefs; +import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientStatus; +import info.nightscout.androidaps.plugins.profile.local.LocalProfileFragment; +import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin; +import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment; +import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin; +import info.nightscout.androidaps.plugins.profile.simple.SimpleProfileFragment; +import info.nightscout.androidaps.plugins.profile.simple.SimpleProfilePlugin; import info.nightscout.androidaps.setupwizard.elements.SWBreak; import info.nightscout.androidaps.setupwizard.elements.SWButton; import info.nightscout.androidaps.setupwizard.elements.SWEditString; @@ -50,10 +50,10 @@ import info.nightscout.androidaps.setupwizard.elements.SWPlugin; import info.nightscout.androidaps.setupwizard.elements.SWRadioButton; import info.nightscout.androidaps.setupwizard.events.EventSWLabel; import info.nightscout.androidaps.setupwizard.events.EventSWUpdate; -import info.nightscout.utils.AndroidPermission; -import info.nightscout.utils.LocaleHelper; -import info.nightscout.utils.PasswordProtection; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.AndroidPermission; +import info.nightscout.androidaps.utils.LocaleHelper; +import info.nightscout.androidaps.utils.PasswordProtection; +import info.nightscout.androidaps.utils.SP; public class SWDefinition { private static Logger log = LoggerFactory.getLogger(SWDefinition.class); diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java index 5102e36ac6..3dad4535ac 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.java @@ -24,14 +24,14 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventProfileStoreChanged; import info.nightscout.androidaps.events.EventProfileSwitchChange; import info.nightscout.androidaps.events.EventPumpStatusChanged; -import info.nightscout.androidaps.plugins.ConstraintsObjectives.events.EventObjectivesSaved; -import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus; +import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesSaved; +import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientStatus; import info.nightscout.androidaps.setupwizard.elements.SWItem; import info.nightscout.androidaps.setupwizard.events.EventSWUpdate; -import info.nightscout.utils.AndroidPermission; -import info.nightscout.utils.LocaleHelper; -import info.nightscout.utils.OKDialog; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.AndroidPermission; +import info.nightscout.androidaps.utils.LocaleHelper; +import info.nightscout.androidaps.utils.OKDialog; +import info.nightscout.androidaps.utils.SP; public class SetupWizardActivity extends AppCompatActivity { //logging diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWCheckbox.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWCheckbox.java index ed96b37944..d8194cbfc0 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWCheckbox.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWCheckbox.java @@ -14,7 +14,7 @@ import java.util.ArrayList; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by Rumen Georgiev on 5/9/2018. diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditString.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditString.java index 1f32e6622d..50e851ed6b 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditString.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditString.java @@ -5,7 +5,6 @@ import android.graphics.Typeface; import android.text.Editable; import android.text.InputType; import android.text.TextWatcher; -import android.view.View; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; @@ -14,7 +13,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.setupwizard.SWTextValidator; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; public class SWEditString extends SWItem { diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditUrl.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditUrl.java index 254723e4e1..7e6ead7d72 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditUrl.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditUrl.java @@ -17,7 +17,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.setupwizard.events.EventSWLabel; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; public class SWEditUrl extends SWItem { private static Logger log = LoggerFactory.getLogger(SWEditUrl.class); diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java index d9cfe3710d..4e8113c73c 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java @@ -15,7 +15,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.setupwizard.events.EventSWUpdate; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; public class SWItem { private static Logger log = LoggerFactory.getLogger(SWItem.class); @@ -81,7 +81,7 @@ public class SWItem { } public static LinearLayout generateLayout(View view) { - LinearLayout layout = (LinearLayout) view.findViewById(view.getId()); + LinearLayout layout = (LinearLayout) view; layout.removeAllViews(); return layout; } diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.java index 80f60eb678..060102ba9c 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.java @@ -17,8 +17,8 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.events.EventConfigBuilderChange; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.setupwizard.events.EventSWUpdate; public class SWPlugin extends SWItem { diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWRadioButton.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWRadioButton.java index cf7dbd55fe..67ef9c19ae 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWRadioButton.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWRadioButton.java @@ -12,7 +12,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; public class SWRadioButton extends SWItem { private static Logger log = LoggerFactory.getLogger(SWRadioButton.class); diff --git a/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java b/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java index 88f7d48d32..53b3700c72 100644 --- a/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java @@ -15,7 +15,7 @@ import java.util.ArrayList; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.logging.L; -import info.nightscout.utils.SP; +import info.nightscout.androidaps.utils.SP; /** * Created by mike on 30.05.2016. diff --git a/app/src/main/java/info/nightscout/utils/AndroidPermission.java b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java similarity index 78% rename from app/src/main/java/info/nightscout/utils/AndroidPermission.java rename to app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java index ca3cac82f1..3f6c3a3ce0 100644 --- a/app/src/main/java/info/nightscout/utils/AndroidPermission.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.Manifest; import android.app.Activity; @@ -10,10 +10,10 @@ import android.support.v4.content.ContextCompat; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.Overview.notifications.NotificationWithAction; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationWithAction; public class AndroidPermission { @@ -21,6 +21,7 @@ public class AndroidPermission { public static final int CASE_SMS = 0x2; public static final int CASE_LOCATION = 0x3; public static final int CASE_BATTERY = 0x4; + public static final int CASE_PHONESTATE = 0x5; public static void askForPermission(Activity activity, String[] permission, Integer requestCode) { boolean test = false; @@ -44,7 +45,7 @@ public class AndroidPermission { } public static synchronized void notifyForSMSPermissions(Activity activity) { - if (SP.getBoolean(R.string.smscommunicator_remotecommandsallowed, false)) { + if (SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { if (!checkForPermission(activity, Manifest.permission.RECEIVE_SMS)) { NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_SMS, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.URGENT); @@ -55,6 +56,16 @@ public class AndroidPermission { } else MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_SMS)); } + // Following is a bug in Android 8 + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) { + if (!checkForPermission(activity, Manifest.permission.READ_PHONE_STATE)) { + NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_PHONESTATE, MainApp.gs(R.string.smscommunicator_missingphonestatepermission), Notification.URGENT); + notification.action(MainApp.gs(R.string.request), () -> + AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_PHONE_STATE}, AndroidPermission.CASE_PHONESTATE)); + MainApp.bus().post(new EventNewNotification(notification)); + } else + MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_PHONESTATE)); + } } } diff --git a/app/src/main/java/info/nightscout/utils/BatteryLevel.java b/app/src/main/java/info/nightscout/androidaps/utils/BatteryLevel.java similarity index 96% rename from app/src/main/java/info/nightscout/utils/BatteryLevel.java rename to app/src/main/java/info/nightscout/androidaps/utils/BatteryLevel.java index ea55dd9e69..bc000a95b9 100644 --- a/app/src/main/java/info/nightscout/utils/BatteryLevel.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/BatteryLevel.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.content.Intent; import android.content.IntentFilter; diff --git a/app/src/main/java/info/nightscout/utils/BolusWizard.java b/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.java similarity index 97% rename from app/src/main/java/info/nightscout/utils/BolusWizard.java rename to app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.java index d20827ce9e..e47a74e17f 100644 --- a/app/src/main/java/info/nightscout/utils/BolusWizard.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -9,8 +9,8 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; /** * Created by mike on 11.10.2016. diff --git a/app/src/main/java/info/nightscout/utils/CRC.java b/app/src/main/java/info/nightscout/androidaps/utils/CRC.java similarity index 98% rename from app/src/main/java/info/nightscout/utils/CRC.java rename to app/src/main/java/info/nightscout/androidaps/utils/CRC.java index bc59d7e2ae..4c7086de85 100644 --- a/app/src/main/java/info/nightscout/utils/CRC.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/CRC.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; public final class CRC { diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/androidaps/utils/DateUtil.java similarity index 97% rename from app/src/main/java/info/nightscout/utils/DateUtil.java rename to app/src/main/java/info/nightscout/androidaps/utils/DateUtil.java index 0cf3a6c87a..9ce121962b 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/DateUtil.java @@ -1,7 +1,6 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.support.v4.util.LongSparseArray; -import android.text.format.DateUtils; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; @@ -184,6 +183,11 @@ public class DateUtil { return date - date % 1000; } + public static boolean isCloseToNow(long date) { + long diff = Math.abs(date - now()); + return diff < T.mins(2).msecs(); + } + public static GregorianCalendar gregorianCalendar() { return new GregorianCalendar(); } diff --git a/app/src/main/java/info/nightscout/utils/DecimalFormatter.java b/app/src/main/java/info/nightscout/androidaps/utils/DecimalFormatter.java similarity index 94% rename from app/src/main/java/info/nightscout/utils/DecimalFormatter.java rename to app/src/main/java/info/nightscout/androidaps/utils/DecimalFormatter.java index 620e636843..66464ed1c5 100644 --- a/app/src/main/java/info/nightscout/utils/DecimalFormatter.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/DecimalFormatter.java @@ -1,8 +1,8 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import java.text.DecimalFormat; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; /** * Created by mike on 11.07.2016. diff --git a/app/src/main/java/info/nightscout/utils/DefaultValueHelper.java b/app/src/main/java/info/nightscout/androidaps/utils/DefaultValueHelper.java similarity index 98% rename from app/src/main/java/info/nightscout/utils/DefaultValueHelper.java rename to app/src/main/java/info/nightscout/androidaps/utils/DefaultValueHelper.java index ba1aba90b8..40448d2680 100644 --- a/app/src/main/java/info/nightscout/utils/DefaultValueHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/DefaultValueHelper.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.R; diff --git a/app/src/main/java/info/nightscout/utils/FabricPrivacy.java b/app/src/main/java/info/nightscout/androidaps/utils/FabricPrivacy.java similarity index 87% rename from app/src/main/java/info/nightscout/utils/FabricPrivacy.java rename to app/src/main/java/info/nightscout/androidaps/utils/FabricPrivacy.java index 7f050e609a..0a0d559c55 100644 --- a/app/src/main/java/info/nightscout/utils/FabricPrivacy.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/FabricPrivacy.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import com.crashlytics.android.Crashlytics; import com.crashlytics.android.answers.Answers; @@ -110,12 +110,13 @@ public class FabricPrivacy { CustomEvent pluginStats = new CustomEvent("PluginStats"); pluginStats.putCustomAttribute("version", BuildConfig.VERSION); pluginStats.putCustomAttribute("HEAD", BuildConfig.HEAD); + pluginStats.putCustomAttribute("language", SP.getString(R.string.key_language,"default")); for (PluginBase plugin : MainApp.getPluginsList()) { - if (!plugin.pluginDescription.alwaysEnabled) { - if (plugin.isEnabled(plugin.getType())) - pluginStats.putCustomAttribute(plugin.getClass().getSimpleName(), "enabled"); - else - pluginStats.putCustomAttribute(plugin.getClass().getSimpleName(), "disabled"); + if (plugin.isEnabled(plugin.getType()) && !plugin.pluginDescription.alwaysEnabled) { + // Fabric allows no more than 20 attributes attached to an event. By reporting disabled plugins as + // well, we would exceed that threshold, so only report what is enabled + // TODO >2.0: consider reworking this to upload an event per enabled plugin instead. + pluginStats.putCustomAttribute(plugin.getClass().getSimpleName(), "enabled"); } } diff --git a/app/src/main/java/info/nightscout/utils/HardLimits.java b/app/src/main/java/info/nightscout/androidaps/utils/HardLimits.java similarity index 96% rename from app/src/main/java/info/nightscout/utils/HardLimits.java rename to app/src/main/java/info/nightscout/androidaps/utils/HardLimits.java index 1a36561b62..8b80c4c6fc 100644 --- a/app/src/main/java/info/nightscout/utils/HardLimits.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/HardLimits.java @@ -1,11 +1,11 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; /** * Created by mike on 22.02.2017. diff --git a/app/src/main/java/info/nightscout/utils/JSONFormatter.java b/app/src/main/java/info/nightscout/androidaps/utils/JSONFormatter.java similarity index 98% rename from app/src/main/java/info/nightscout/utils/JSONFormatter.java rename to app/src/main/java/info/nightscout/androidaps/utils/JSONFormatter.java index 499ba01652..159e90fda7 100644 --- a/app/src/main/java/info/nightscout/utils/JSONFormatter.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/JSONFormatter.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.text.Html; import android.text.Spanned; diff --git a/app/src/main/java/info/nightscout/utils/JsonHelper.java b/app/src/main/java/info/nightscout/androidaps/utils/JsonHelper.java similarity index 85% rename from app/src/main/java/info/nightscout/utils/JsonHelper.java rename to app/src/main/java/info/nightscout/androidaps/utils/JsonHelper.java index 503d0bf395..8f7d9611b1 100644 --- a/app/src/main/java/info/nightscout/utils/JsonHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/JsonHelper.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.support.annotation.Nullable; @@ -22,7 +22,7 @@ public class JsonHelper { public static Object safeGetObject(JSONObject json, String fieldName, Object defaultValue) { Object result = defaultValue; - if (json.has(fieldName)) { + if (json != null && json.has(fieldName)) { try { result = json.get(fieldName); } catch (JSONException ignored) { @@ -36,7 +36,7 @@ public class JsonHelper { public static String safeGetString(JSONObject json, String fieldName) { String result = null; - if (json.has(fieldName)) { + if (json != null && json.has(fieldName)) { try { result = json.getString(fieldName); } catch (JSONException ignored) { @@ -49,7 +49,7 @@ public class JsonHelper { public static String safeGetString(JSONObject json, String fieldName, String defaultValue) { String result = defaultValue; - if (json.has(fieldName)) { + if (json != null && json.has(fieldName)) { try { result = json.getString(fieldName); } catch (JSONException ignored) { @@ -62,7 +62,7 @@ public class JsonHelper { public static double safeGetDouble(JSONObject json, String fieldName) { double result = 0d; - if (json.has(fieldName)) { + if (json != null && json.has(fieldName)) { try { result = json.getDouble(fieldName); } catch (JSONException ignored) { @@ -75,7 +75,7 @@ public class JsonHelper { public static int safeGetInt(JSONObject json, String fieldName) { int result = 0; - if (json.has(fieldName)) { + if (json != null && json.has(fieldName)) { try { result = json.getInt(fieldName); } catch (JSONException ignored) { @@ -88,7 +88,7 @@ public class JsonHelper { public static long safeGetLong(JSONObject json, String fieldName) { long result = 0; - if (json.has(fieldName)) { + if (json != null && json.has(fieldName)) { try { result = json.getLong(fieldName); } catch (JSONException e) { @@ -101,7 +101,7 @@ public class JsonHelper { public static boolean safeGetBoolean(JSONObject json, String fieldName) { boolean result = false; - if (json.has(fieldName)) { + if (json != null && json.has(fieldName)) { try { result = json.getBoolean(fieldName); } catch (JSONException e) { diff --git a/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.java similarity index 90% rename from app/src/main/java/info/nightscout/utils/LocalAlertUtils.java rename to app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.java index 89c422ec53..d23020a56c 100644 --- a/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -10,13 +10,13 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.Loop.LoopPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; /** * Created by adrian on 17/12/17. diff --git a/app/src/main/java/info/nightscout/utils/LocaleHelper.java b/app/src/main/java/info/nightscout/androidaps/utils/LocaleHelper.java similarity index 98% rename from app/src/main/java/info/nightscout/utils/LocaleHelper.java rename to app/src/main/java/info/nightscout/androidaps/utils/LocaleHelper.java index c8faa83b9d..bf0b2796ee 100644 --- a/app/src/main/java/info/nightscout/utils/LocaleHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/LocaleHelper.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.content.Context; import android.content.SharedPreferences; diff --git a/app/src/main/java/info/nightscout/androidaps/utils/MidnightTime.java b/app/src/main/java/info/nightscout/androidaps/utils/MidnightTime.java new file mode 100644 index 0000000000..668ca02e96 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/utils/MidnightTime.java @@ -0,0 +1,46 @@ +package info.nightscout.androidaps.utils; + +import android.util.LongSparseArray; + +import java.util.Calendar; + +public class MidnightTime { + private static final LongSparseArray times = new LongSparseArray<>(); + + private static long hits = 0; + private static long misses = 0; + + public static long calc() { + Calendar c = Calendar.getInstance(); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + c.set(Calendar.MILLISECOND, 0); + return c.getTimeInMillis(); + } + + public static long calc(long time) { + Long m; + synchronized (times) { + m = times.get(time); + if (m != null) { + ++hits; + return m; + } + Calendar c = Calendar.getInstance(); + c.setTimeInMillis(time); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + c.set(Calendar.MILLISECOND, 0); + m = c.getTimeInMillis(); + times.append(time, m); + ++misses; + } + return m; + } + + public static String log() { + return "Hits: " + hits + " misses: " + misses + " stored: " + times.size(); + } +} diff --git a/app/src/main/java/info/nightscout/utils/NumberPicker.java b/app/src/main/java/info/nightscout/androidaps/utils/NumberPicker.java similarity index 92% rename from app/src/main/java/info/nightscout/utils/NumberPicker.java rename to app/src/main/java/info/nightscout/androidaps/utils/NumberPicker.java index 102abedc7d..f32b79c439 100644 --- a/app/src/main/java/info/nightscout/utils/NumberPicker.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/NumberPicker.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.content.Context; import android.os.Handler; @@ -34,6 +34,10 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener, View.OnTouchListener, View.OnClickListener { private static Logger log = LoggerFactory.getLogger(NumberPicker.class); + public interface OnValueChangedListener { + void onValueChanged(double value); + } + TextView editText; Button minusButton; Button plusButton; @@ -48,6 +52,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener, private Handler mHandler; private ScheduledExecutorService mUpdater; + private OnValueChangedListener mOnValueChangedListener; private class UpdateCounterTask implements Runnable { private boolean mInc; @@ -139,10 +144,15 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener, @Override public void afterTextChanged(Editable s) { value = SafeParse.stringToDouble(editText.getText().toString()); + callValueChangedListener(); } }); } + public void setOnValueChangedListener(OnValueChangedListener onValueChangedListener) { + mOnValueChangedListener = onValueChangedListener; + } + public void setTextWatcher(TextWatcher textWatcher) { this.textWatcher = textWatcher; editText.addTextChangedListener(textWatcher); @@ -164,6 +174,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener, this.step = step; this.formater = formater; this.allowZero = allowZero; + callValueChangedListener(); editText.setKeyListener(DigitsKeyListener.getInstance(minValue < 0, step != Math.rint(step))); @@ -178,6 +189,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener, if (textWatcher != null) editText.removeTextChangedListener(textWatcher); this.value = value; + callValueChangedListener(); updateEditText(); if (textWatcher != null) editText.addTextChangedListener(textWatcher); @@ -199,6 +211,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener, value += step * multiplier; if (value > maxValue) { value = maxValue; + callValueChangedListener(); ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.youareonallowedlimit)); stopUpdating(); } @@ -209,6 +222,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener, value -= step * multiplier; if (value < minValue) { value = minValue; + callValueChangedListener(); ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.youareonallowedlimit)); stopUpdating(); } @@ -222,6 +236,11 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener, editText.setText(formater.format(value)); } + private void callValueChangedListener() { + if (mOnValueChangedListener != null) + mOnValueChangedListener.onValueChanged(value); + } + private void startUpdating(boolean inc) { if (mUpdater != null) { log.debug("Another executor is still active"); diff --git a/app/src/main/java/info/nightscout/utils/OKDialog.java b/app/src/main/java/info/nightscout/androidaps/utils/OKDialog.java similarity index 98% rename from app/src/main/java/info/nightscout/utils/OKDialog.java rename to app/src/main/java/info/nightscout/androidaps/utils/OKDialog.java index 0e9d95a22c..00b3c29692 100644 --- a/app/src/main/java/info/nightscout/utils/OKDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/OKDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.app.Activity; import android.content.Context; diff --git a/app/src/main/java/info/nightscout/utils/PasswordProtection.java b/app/src/main/java/info/nightscout/androidaps/utils/PasswordProtection.java similarity index 98% rename from app/src/main/java/info/nightscout/utils/PasswordProtection.java rename to app/src/main/java/info/nightscout/androidaps/utils/PasswordProtection.java index 2a15dc7311..230be97e22 100644 --- a/app/src/main/java/info/nightscout/utils/PasswordProtection.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/PasswordProtection.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.app.AlertDialog; import android.content.Context; diff --git a/app/src/main/java/info/nightscout/androidaps/utils/PercentageSplitter.java b/app/src/main/java/info/nightscout/androidaps/utils/PercentageSplitter.java new file mode 100644 index 0000000000..b3f8156cfe --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/utils/PercentageSplitter.java @@ -0,0 +1,22 @@ +package info.nightscout.androidaps.utils; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Created by mike on 22.12.2017. + */ + +public class PercentageSplitter { + // Matches "Profile name (200%,-2h)", "Profile name (50%) + private static final Pattern splitPattern = Pattern.compile("(.+)\\(\\d+%(,-?\\d+h)?\\)"); + + /** Removes the suffix for percentage and timeshift from a profile name. This is the inverse of what + * {@link info.nightscout.androidaps.db.ProfileSwitch#getCustomizedName()} does. + * Since the customized name is used for the PS upload to NS, this is needed get the original profile name + * when retrieving the PS from NS again. */ + public static String pureName(String name) { + Matcher percentageMatch = splitPattern.matcher(name); + return percentageMatch.find() ? percentageMatch.group(1).trim() : name; + } +} diff --git a/app/src/main/java/info/nightscout/utils/Profiler.java b/app/src/main/java/info/nightscout/androidaps/utils/Profiler.java similarity index 88% rename from app/src/main/java/info/nightscout/utils/Profiler.java rename to app/src/main/java/info/nightscout/androidaps/utils/Profiler.java index 140adc6366..05eed9e97d 100644 --- a/app/src/main/java/info/nightscout/utils/Profiler.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/Profiler.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import org.slf4j.Logger; diff --git a/app/src/main/java/info/nightscout/utils/Round.java b/app/src/main/java/info/nightscout/androidaps/utils/Round.java similarity index 92% rename from app/src/main/java/info/nightscout/utils/Round.java rename to app/src/main/java/info/nightscout/androidaps/utils/Round.java index 26a4d5abce..ba7f7e3f86 100644 --- a/app/src/main/java/info/nightscout/utils/Round.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/Round.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; /** * Created by mike on 20.06.2016. diff --git a/app/src/main/java/info/nightscout/utils/SP.java b/app/src/main/java/info/nightscout/androidaps/utils/SP.java similarity index 91% rename from app/src/main/java/info/nightscout/utils/SP.java rename to app/src/main/java/info/nightscout/androidaps/utils/SP.java index d5a40e19f5..3b3a8e6907 100644 --- a/app/src/main/java/info/nightscout/utils/SP.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/SP.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.content.SharedPreferences; import android.preference.PreferenceManager; @@ -96,6 +96,18 @@ public class SP { editor.apply(); } + static public void putDouble(String key, double value) { + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putString(key, Double.toString(value)); + editor.apply(); + } + + static public void putDouble(int resourceID, double value) { + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putString(MainApp.gs(resourceID), Double.toString(value)); + editor.apply(); + } + static public void putLong(String key, long value) { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putLong(key, value); diff --git a/app/src/main/java/info/nightscout/utils/SafeParse.java b/app/src/main/java/info/nightscout/androidaps/utils/SafeParse.java similarity index 88% rename from app/src/main/java/info/nightscout/utils/SafeParse.java rename to app/src/main/java/info/nightscout/androidaps/utils/SafeParse.java index ff749f732b..5ee2a66177 100644 --- a/app/src/main/java/info/nightscout/utils/SafeParse.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/SafeParse.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -11,6 +11,7 @@ public class SafeParse { public static Double stringToDouble(String input) { Double result = 0d; input = input.replace(",", "."); + input = input.replace("−", "-"); if (input.equals("")) return 0d; try { @@ -24,6 +25,7 @@ public class SafeParse { public static Integer stringToInt(String input) { Integer result = 0; input = input.replace(",", "."); + input = input.replace("−", "-"); if (input.equals("")) return 0; try { @@ -37,6 +39,7 @@ public class SafeParse { public static Long stringToLong(String input) { Long result = 0L; input = input.replace(",", "."); + input = input.replace("−", "-"); if (input.equals("")) return 0L; try { diff --git a/app/src/main/java/info/nightscout/utils/SetWarnColor.java b/app/src/main/java/info/nightscout/androidaps/utils/SetWarnColor.java similarity index 95% rename from app/src/main/java/info/nightscout/utils/SetWarnColor.java rename to app/src/main/java/info/nightscout/androidaps/utils/SetWarnColor.java index a3a23695c7..e22197d83f 100644 --- a/app/src/main/java/info/nightscout/utils/SetWarnColor.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/SetWarnColor.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.graphics.Color; import android.widget.TextView; diff --git a/app/src/main/java/info/nightscout/utils/SingleClickButton.java b/app/src/main/java/info/nightscout/androidaps/utils/SingleClickButton.java similarity index 97% rename from app/src/main/java/info/nightscout/utils/SingleClickButton.java rename to app/src/main/java/info/nightscout/androidaps/utils/SingleClickButton.java index ef0d4d3aec..eef4ca57fe 100644 --- a/app/src/main/java/info/nightscout/utils/SingleClickButton.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/SingleClickButton.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.app.Activity; import android.content.Context; diff --git a/app/src/main/java/info/nightscout/utils/SpinnerHelper.java b/app/src/main/java/info/nightscout/androidaps/utils/SpinnerHelper.java similarity index 99% rename from app/src/main/java/info/nightscout/utils/SpinnerHelper.java rename to app/src/main/java/info/nightscout/androidaps/utils/SpinnerHelper.java index 84315825f5..a45fcd5a57 100644 --- a/app/src/main/java/info/nightscout/utils/SpinnerHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/SpinnerHelper.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.view.MotionEvent; import android.view.View; diff --git a/app/src/main/java/info/nightscout/utils/StringUtils.java b/app/src/main/java/info/nightscout/androidaps/utils/StringUtils.java similarity index 92% rename from app/src/main/java/info/nightscout/utils/StringUtils.java rename to app/src/main/java/info/nightscout/androidaps/utils/StringUtils.java index de16f7964e..cad2b76291 100644 --- a/app/src/main/java/info/nightscout/utils/StringUtils.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/StringUtils.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; /** * class contains useful String functions diff --git a/app/src/main/java/info/nightscout/utils/T.java b/app/src/main/java/info/nightscout/androidaps/utils/T.java similarity index 96% rename from app/src/main/java/info/nightscout/utils/T.java rename to app/src/main/java/info/nightscout/androidaps/utils/T.java index 99f4e573c3..2a9bcfc42c 100644 --- a/app/src/main/java/info/nightscout/utils/T.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/T.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; /** * Created by mike on 26.03.2018. diff --git a/app/src/main/java/info/nightscout/utils/TimeListEdit.java b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java similarity index 99% rename from app/src/main/java/info/nightscout/utils/TimeListEdit.java rename to app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java index ec03734b18..d120e102d1 100644 --- a/app/src/main/java/info/nightscout/utils/TimeListEdit.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.content.Context; import android.os.Handler; diff --git a/app/src/main/java/info/nightscout/utils/ToastUtils.java b/app/src/main/java/info/nightscout/androidaps/utils/ToastUtils.java similarity index 87% rename from app/src/main/java/info/nightscout/utils/ToastUtils.java rename to app/src/main/java/info/nightscout/androidaps/utils/ToastUtils.java index 4ad07a4885..d85b1510a0 100644 --- a/app/src/main/java/info/nightscout/utils/ToastUtils.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/ToastUtils.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.content.Context; import android.media.MediaPlayer; @@ -7,8 +7,8 @@ import android.os.Looper; import android.widget.Toast; import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; public class ToastUtils { diff --git a/app/src/main/java/info/nightscout/utils/Translator.java b/app/src/main/java/info/nightscout/androidaps/utils/Translator.java similarity index 98% rename from app/src/main/java/info/nightscout/utils/Translator.java rename to app/src/main/java/info/nightscout/androidaps/utils/Translator.java index 98fdd32779..ee83f856e4 100644 --- a/app/src/main/java/info/nightscout/utils/Translator.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/Translator.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; diff --git a/app/src/main/java/info/nightscout/utils/VersionChecker.java b/app/src/main/java/info/nightscout/androidaps/utils/VersionChecker.java similarity index 90% rename from app/src/main/java/info/nightscout/utils/VersionChecker.java rename to app/src/main/java/info/nightscout/androidaps/utils/VersionChecker.java index 00bfc50395..fd636b4596 100644 --- a/app/src/main/java/info/nightscout/utils/VersionChecker.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/VersionChecker.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.net.ConnectivityManager; import android.net.NetworkInfo; @@ -21,8 +21,8 @@ import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import static android.content.Context.CONNECTIVITY_SERVICE; @@ -43,7 +43,6 @@ public class VersionChecker { if (inputStream != null) { String result = findLine(inputStream); if (result != null) { - result = result.replace("version", "").replace("\"", "").replace("\\s+", "").trim(); int compare = result.compareTo(BuildConfig.VERSION_NAME.replace("\"", "")); if (compare == 0) { log.debug("Version equal to master"); @@ -75,14 +74,14 @@ public class VersionChecker { private static String findLine(InputStream inputStream) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String line; - String regex = "(.*)version(.*)\"(\\d+)\\.(\\d+)\"(.*)"; + String regex = "(.*)version(.*)\"(((\\d+)\\.)+(\\d+))\"(.*)"; Pattern p = Pattern.compile(regex); while ((line = bufferedReader.readLine()) != null) { Matcher m = p.matcher(line); if (m.matches()) { log.debug("+++ " + line); - return line; + return m.group(3); } else { log.debug("--- " + line); } diff --git a/app/src/main/java/info/nightscout/utils/XdripCalibrations.java b/app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.java similarity index 96% rename from app/src/main/java/info/nightscout/utils/XdripCalibrations.java rename to app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.java index 18c066b1da..99961a156b 100644 --- a/app/src/main/java/info/nightscout/utils/XdripCalibrations.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.java @@ -1,4 +1,4 @@ -package info.nightscout.utils; +package info.nightscout.androidaps.utils; import android.content.Context; import android.content.DialogInterface; @@ -15,7 +15,7 @@ import java.util.List; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.services.Intents; /** diff --git a/app/src/main/java/info/nightscout/utils/MidnightTime.java b/app/src/main/java/info/nightscout/utils/MidnightTime.java new file mode 100644 index 0000000000..523fe13826 --- /dev/null +++ b/app/src/main/java/info/nightscout/utils/MidnightTime.java @@ -0,0 +1,43 @@ +package info.nightscout.utils; + +import android.util.LongSparseArray; + +import java.util.Calendar; + +public class MidnightTime { + private static LongSparseArray times = new LongSparseArray(); + + private static long hits = 0; + private static long misses = 0; + + public static long calc() { + Calendar c = Calendar.getInstance(); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + c.set(Calendar.MILLISECOND, 0); + return c.getTimeInMillis(); + } + + public static long calc(long time) { + Long m = (Long) times.get(time); + if (m != null) { + ++hits; + return m; + } + Calendar c = Calendar.getInstance(); + c.setTimeInMillis(time); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + c.set(Calendar.MILLISECOND, 0); + m = c.getTimeInMillis(); + times.append(time, m); + ++misses; + return m; + } + + public static String log() { + return "Hits: " + hits + " misses: " + misses + " stored: " + times.size(); + } +} diff --git a/app/src/main/java/info/nightscout/utils/PercentageSplitter.java b/app/src/main/java/info/nightscout/utils/PercentageSplitter.java deleted file mode 100644 index 40dfdf2455..0000000000 --- a/app/src/main/java/info/nightscout/utils/PercentageSplitter.java +++ /dev/null @@ -1,30 +0,0 @@ -package info.nightscout.utils; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Created by mike on 22.12.2017. - */ - -public class PercentageSplitter { - // "Profile name (200%,2h)" - private static final Pattern percentagePattern = Pattern.compile("(.+)\\(\\d+%,\\d+h\\)"); - // "Profile name (200%)" - private static final Pattern percentageShiftPattern = Pattern.compile("(.+)\\(\\d+%\\)"); - - /** Removes the suffix for percentage and timeshift from a profile name. */ - public static String pureName(String name) { - Matcher percentageMatch = percentagePattern.matcher(name); - if (percentageMatch.find()) { - return percentageMatch.group(1).trim(); - } - - Matcher percentageShiftMatch = percentageShiftPattern.matcher(name); - if (percentageShiftMatch.find()) { - return percentageShiftMatch.group(1).trim(); - } - - return name; - } -} diff --git a/app/src/main/res/drawable-hdpi/ic_error.png b/app/src/main/res/drawable-hdpi/ic_error.png new file mode 100644 index 0000000000..5b57c7458f Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_error.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_maintenance.png b/app/src/main/res/drawable-hdpi/ic_maintenance.png new file mode 100644 index 0000000000..60f34eb201 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_maintenance.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_notification.png b/app/src/main/res/drawable-hdpi/ic_notif_aaps.png similarity index 100% rename from app/src/main/res/drawable-hdpi/ic_notification.png rename to app/src/main/res/drawable-hdpi/ic_notif_aaps.png diff --git a/app/src/main/res/drawable-hdpi/nsclient_smallicon.png b/app/src/main/res/drawable-hdpi/ic_notif_nsclient.png similarity index 100% rename from app/src/main/res/drawable-hdpi/nsclient_smallicon.png rename to app/src/main/res/drawable-hdpi/ic_notif_nsclient.png diff --git a/app/src/main/res/drawable-hdpi/ic_notif_pumpcontrol.png b/app/src/main/res/drawable-hdpi/ic_notif_pumpcontrol.png new file mode 100644 index 0000000000..5562fef378 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_notif_pumpcontrol.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_reminder.png b/app/src/main/res/drawable-hdpi/ic_reminder.png new file mode 100644 index 0000000000..b45924d4eb Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_reminder.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_warning.png b/app/src/main/res/drawable-hdpi/ic_warning.png new file mode 100644 index 0000000000..d7aa344bca Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_warning.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_error.png b/app/src/main/res/drawable-mdpi/ic_error.png new file mode 100644 index 0000000000..68a4b0e48c Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_error.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_maintenance.png b/app/src/main/res/drawable-mdpi/ic_maintenance.png new file mode 100644 index 0000000000..728313d9e7 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_maintenance.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_notification.png b/app/src/main/res/drawable-mdpi/ic_notif_aaps.png similarity index 100% rename from app/src/main/res/drawable-mdpi/ic_notification.png rename to app/src/main/res/drawable-mdpi/ic_notif_aaps.png diff --git a/app/src/main/res/drawable-mdpi/nsclient_smallicon.png b/app/src/main/res/drawable-mdpi/ic_notif_nsclient.png similarity index 100% rename from app/src/main/res/drawable-mdpi/nsclient_smallicon.png rename to app/src/main/res/drawable-mdpi/ic_notif_nsclient.png diff --git a/app/src/main/res/drawable-mdpi/ic_notif_pumpcontrol.png b/app/src/main/res/drawable-mdpi/ic_notif_pumpcontrol.png new file mode 100644 index 0000000000..3feb5d6248 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_notif_pumpcontrol.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_reminder.png b/app/src/main/res/drawable-mdpi/ic_reminder.png new file mode 100644 index 0000000000..2c269d5530 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_reminder.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_warning.png b/app/src/main/res/drawable-mdpi/ic_warning.png new file mode 100644 index 0000000000..1ff44a152a Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_warning.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_error.png b/app/src/main/res/drawable-xhdpi/ic_error.png new file mode 100644 index 0000000000..dee2d5af82 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_error.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_maintenance.png b/app/src/main/res/drawable-xhdpi/ic_maintenance.png new file mode 100644 index 0000000000..303e1780f9 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_maintenance.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_notification.png b/app/src/main/res/drawable-xhdpi/ic_notif_aaps.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/ic_notification.png rename to app/src/main/res/drawable-xhdpi/ic_notif_aaps.png diff --git a/app/src/main/res/drawable-xhdpi/nsclient_smallicon.png b/app/src/main/res/drawable-xhdpi/ic_notif_nsclient.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/nsclient_smallicon.png rename to app/src/main/res/drawable-xhdpi/ic_notif_nsclient.png diff --git a/app/src/main/res/drawable-xhdpi/ic_notif_pumpcontrol.png b/app/src/main/res/drawable-xhdpi/ic_notif_pumpcontrol.png new file mode 100644 index 0000000000..e5eb24b9da Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_notif_pumpcontrol.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_reminder.png b/app/src/main/res/drawable-xhdpi/ic_reminder.png new file mode 100644 index 0000000000..904a608285 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_reminder.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_warning.png b/app/src/main/res/drawable-xhdpi/ic_warning.png new file mode 100644 index 0000000000..652a1bb1d9 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_warning.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_error.png b/app/src/main/res/drawable-xxhdpi/ic_error.png new file mode 100644 index 0000000000..cf389b5d96 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_error.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_maintenance.png b/app/src/main/res/drawable-xxhdpi/ic_maintenance.png new file mode 100644 index 0000000000..952e7b9ef3 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_maintenance.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_notification.png b/app/src/main/res/drawable-xxhdpi/ic_notif_aaps.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/ic_notification.png rename to app/src/main/res/drawable-xxhdpi/ic_notif_aaps.png diff --git a/app/src/main/res/drawable-xxhdpi/nsclient_smallicon.png b/app/src/main/res/drawable-xxhdpi/ic_notif_nsclient.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/nsclient_smallicon.png rename to app/src/main/res/drawable-xxhdpi/ic_notif_nsclient.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_notif_pumpcontrol.png b/app/src/main/res/drawable-xxhdpi/ic_notif_pumpcontrol.png new file mode 100644 index 0000000000..12bf9fd364 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_notif_pumpcontrol.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_reminder.png b/app/src/main/res/drawable-xxhdpi/ic_reminder.png new file mode 100644 index 0000000000..e918305ba0 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_reminder.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_warning.png b/app/src/main/res/drawable-xxhdpi/ic_warning.png new file mode 100644 index 0000000000..7ab70f77c2 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_warning.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_error.png b/app/src/main/res/drawable-xxxhdpi/ic_error.png new file mode 100644 index 0000000000..b8743474f7 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_error.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_maintenance.png b/app/src/main/res/drawable-xxxhdpi/ic_maintenance.png new file mode 100644 index 0000000000..1046459dc3 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_maintenance.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_reminder.png b/app/src/main/res/drawable-xxxhdpi/ic_reminder.png new file mode 100644 index 0000000000..6aa4e934d0 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_reminder.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_warning.png b/app/src/main/res/drawable-xxxhdpi/ic_warning.png new file mode 100644 index 0000000000..607e14b7d2 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_warning.png differ diff --git a/app/src/main/res/drawable/border_automation_unit.xml b/app/src/main/res/drawable/border_automation_unit.xml new file mode 100644 index 0000000000..eb85656295 --- /dev/null +++ b/app/src/main/res/drawable/border_automation_unit.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_access_alarm_24dp.xml b/app/src/main/res/drawable/ic_access_alarm_24dp.xml new file mode 100644 index 0000000000..3e1d84e037 --- /dev/null +++ b/app/src/main/res/drawable/ic_access_alarm_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_add_black_24dp.xml b/app/src/main/res/drawable/ic_add_black_24dp.xml new file mode 100644 index 0000000000..0258249cc4 --- /dev/null +++ b/app/src/main/res/drawable/ic_add_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_arrow_forward_white_24dp.xml b/app/src/main/res/drawable/ic_arrow_forward_white_24dp.xml new file mode 100644 index 0000000000..5304b93e18 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_forward_white_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_notification.png b/app/src/main/res/drawable/ic_notif_aaps.png similarity index 100% rename from app/src/main/res/drawable/ic_notification.png rename to app/src/main/res/drawable/ic_notif_aaps.png diff --git a/app/src/main/res/drawable/ic_notif_pumpcontrol.png b/app/src/main/res/drawable/ic_notif_pumpcontrol.png new file mode 100644 index 0000000000..5562fef378 Binary files /dev/null and b/app/src/main/res/drawable/ic_notif_pumpcontrol.png differ diff --git a/app/src/main/res/drawable/ic_pause_circle_outline_24dp.xml b/app/src/main/res/drawable/ic_pause_circle_outline_24dp.xml new file mode 100644 index 0000000000..4a469646bd --- /dev/null +++ b/app/src/main/res/drawable/ic_pause_circle_outline_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_play_circle_outline_24dp.xml b/app/src/main/res/drawable/ic_play_circle_outline_24dp.xml new file mode 100644 index 0000000000..9997bf2034 --- /dev/null +++ b/app/src/main/res/drawable/ic_play_circle_outline_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_replay_24dp.xml b/app/src/main/res/drawable/ic_replay_24dp.xml new file mode 100644 index 0000000000..32942990ac --- /dev/null +++ b/app/src/main/res/drawable/ic_replay_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_stop_24dp.xml b/app/src/main/res/drawable/ic_stop_24dp.xml new file mode 100644 index 0000000000..88299804a8 --- /dev/null +++ b/app/src/main/res/drawable/ic_stop_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_trash_outline.xml b/app/src/main/res/drawable/ic_trash_outline.xml new file mode 100644 index 0000000000..a411c394e0 --- /dev/null +++ b/app/src/main/res/drawable/ic_trash_outline.xml @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/layout/actions_fill_dialog.xml b/app/src/main/res/layout/actions_fill_dialog.xml index 21fb5d3c66..27fdb02ee7 100644 --- a/app/src/main/res/layout/actions_fill_dialog.xml +++ b/app/src/main/res/layout/actions_fill_dialog.xml @@ -75,7 +75,7 @@ android:textStyle="bold" android:text="@string/overview_insulin_label" /> - + tools:context=".plugins.general.actions.ActionsFragment"> - - - - - - - - - + + + + + + + + + + + + + + +