Merge branch 'dev' into medtronic_andy
This commit is contained in:
commit
289902633e
|
@ -63,14 +63,14 @@ android {
|
|||
targetSdkVersion 25
|
||||
multiDexEnabled true
|
||||
versionCode 1500
|
||||
// dev_version: 2.0i
|
||||
// dev_version: 2.1
|
||||
version "medtronic-0.7"
|
||||
buildConfigField "String", "VERSION", '"' + version + '"'
|
||||
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
|
||||
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'
|
||||
buildConfigField "String", "DEV_VERSION", '"2.0"'
|
||||
buildConfigField "String", "DEV_DATE", '"13.2.2019"'
|
||||
buildConfigField "String", "DEV_CHECKIN", '"65c5aebbdadf7872e9358c019702bdb964faaed7"'
|
||||
buildConfigField "String", "DEV_VERSION", '"2.1"'
|
||||
buildConfigField "String", "DEV_DATE", '"2.3.2019"'
|
||||
buildConfigField "String", "DEV_CHECKIN", '"2ad2b11541159cb1723a44c241c8d681a8548dc5"'
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
|
||||
ndk {
|
||||
|
@ -103,19 +103,19 @@ android {
|
|||
applicationId "info.nightscout.androidaps"
|
||||
dimension "standard"
|
||||
resValue "string", "app_name", "AndroidAPS"
|
||||
versionName version
|
||||
versionName version + "-pumpcontrol"
|
||||
manifestPlaceholders = [
|
||||
appIcon : "@mipmap/ic_launcher",
|
||||
appIcon: "@mipmap/ic_launcher",
|
||||
appIconRound: "@mipmap/ic_launcher_round"
|
||||
]
|
||||
}
|
||||
pumpcontrol {
|
||||
applicationId "info.nightscout.androidaps"
|
||||
applicationId "info.nightscout.aapspumpcontrol"
|
||||
dimension "standard"
|
||||
resValue "string", "app_name", "AndroidAPS"
|
||||
resValue "string", "app_name", "Pumpcontrol"
|
||||
versionName version
|
||||
manifestPlaceholders = [
|
||||
appIcon : "@mipmap/blueowl",
|
||||
appIcon: "@mipmap/ic_pumpcontrol",
|
||||
appIconRound: "@null"
|
||||
]
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ android {
|
|||
resValue "string", "app_name", "NSClient"
|
||||
versionName version + "-nsclient"
|
||||
manifestPlaceholders = [
|
||||
appIcon : "@mipmap/yellowowl",
|
||||
appIcon: "@mipmap/ic_yellowowl",
|
||||
appIconRound: "@null"
|
||||
]
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ android {
|
|||
resValue "string", "app_name", "NSClient2"
|
||||
versionName version + "-nsclient"
|
||||
manifestPlaceholders = [
|
||||
appIcon : "@mipmap/yellowowl",
|
||||
appIcon: "@mipmap/ic_yellowowl",
|
||||
appIconRound: "@null"
|
||||
]
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ android {
|
|||
unitTests.includeAndroidResources = true
|
||||
}
|
||||
|
||||
useLibrary "org.apache.http.legacy"
|
||||
useLibrary "org.apache.http.legacy"
|
||||
}
|
||||
|
||||
allprojects {
|
||||
|
|
|
@ -46,34 +46,34 @@
|
|||
</activity>
|
||||
<activity android:name=".activities.PreferencesActivity" />
|
||||
<activity
|
||||
android:name=".plugins.Overview.Dialogs.BolusProgressHelperActivity"
|
||||
android:name=".plugins.general.overview.Dialogs.BolusProgressHelperActivity"
|
||||
android:theme="@style/Theme.AppCompat.Translucent" />
|
||||
<activity
|
||||
android:name=".plugins.Overview.Dialogs.ErrorHelperActivity"
|
||||
android:name=".plugins.general.overview.Dialogs.ErrorHelperActivity"
|
||||
android:theme="@style/Theme.AppCompat.Translucent" />
|
||||
<activity
|
||||
android:name=".plugins.Overview.Dialogs.MessageHelperActivity"
|
||||
android:theme="@style/Theme.AppCompat.Translucent" />
|
||||
|
||||
<activity android:name=".activities.AgreementActivity" />
|
||||
<activity android:name=".plugins.PumpDanaR.activities.DanaRHistoryActivity" />
|
||||
<activity android:name=".plugins.PumpDanaR.activities.DanaRUserOptionsActivity" />
|
||||
<activity android:name=".plugins.pump.danaR.activities.DanaRHistoryActivity" />
|
||||
<activity android:name=".plugins.pump.danaR.activities.DanaRUserOptionsActivity" />
|
||||
<activity android:name=".activities.TDDStatsActivity" />
|
||||
<activity android:name=".plugins.Overview.activities.QuickWizardListActivity">
|
||||
<activity android:name=".plugins.general.overview.activities.QuickWizardListActivity">
|
||||
<intent-filter>
|
||||
<action android:name="info.nightscout.androidaps.plugins.Overview.activities.QuickWizardListActivity" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".plugins.PumpDanaRS.activities.BLEScanActivity">
|
||||
<activity android:name=".plugins.pump.danaRS.activities.BLEScanActivity">
|
||||
<intent-filter>
|
||||
<action android:name="info.nightscout.androidaps.plugins.PumpDanaRS.activities.BLEScanActivity" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".plugins.PumpDanaRS.activities.PairingHelperActivity" />
|
||||
<activity android:name=".plugins.pump.danaRS.activities.PairingHelperActivity" />
|
||||
<activity android:name=".activities.HistoryBrowseActivity" />
|
||||
|
||||
<receiver
|
||||
|
@ -96,6 +96,8 @@
|
|||
<action android:name="com.dexcom.cgm.g5.AndroidAPSEVGCallback.BROADCAST" />
|
||||
<!-- Receiver from Poctech -->
|
||||
<action android:name="com.china.poctech.data" />
|
||||
<!-- Receiver from Tomato -->
|
||||
<action android:name="com.fanqies.tomatofn.BgEstimate" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<!-- Receiver keepalive, scheduled every 30 min -->
|
||||
|
@ -103,7 +105,7 @@
|
|||
|
||||
<!-- Auto start -->
|
||||
<receiver
|
||||
android:name=".plugins.NSClientInternal.receivers.AutoStartReceiver"
|
||||
android:name=".plugins.general.nsclient.receivers.AutoStartReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
|
@ -113,7 +115,7 @@
|
|||
|
||||
<!-- NSClient -->
|
||||
<receiver
|
||||
android:name=".plugins.NSClientInternal.receivers.RestartReceiver"
|
||||
android:name=".plugins.general.nsclient.receivers.RestartReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
|
@ -121,7 +123,7 @@
|
|||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver
|
||||
android:name=".plugins.NSClientInternal.receivers.DBAccessReceiver"
|
||||
android:name=".plugins.general.nsclient.receivers.DBAccessReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
|
@ -152,30 +154,30 @@
|
|||
android:name=".services.DataService"
|
||||
android:exported="false" />
|
||||
<service
|
||||
android:name=".plugins.PumpDanaR.services.DanaRExecutionService"
|
||||
android:name=".plugins.pump.danaR.services.DanaRExecutionService"
|
||||
android:enabled="true"
|
||||
android:exported="false" />
|
||||
<service
|
||||
android:name=".plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService"
|
||||
android:name=".plugins.pump.danaRKorean.services.DanaRKoreanExecutionService"
|
||||
android:enabled="true"
|
||||
android:exported="false" />
|
||||
<service
|
||||
android:name=".plugins.PumpDanaRv2.services.DanaRv2ExecutionService"
|
||||
android:name=".plugins.pump.danaRv2.services.DanaRv2ExecutionService"
|
||||
android:enabled="true"
|
||||
android:exported="false" />
|
||||
<service
|
||||
android:name=".plugins.PumpDanaRS.services.DanaRSService"
|
||||
android:name=".plugins.pump.danaRS.services.DanaRSService"
|
||||
android:enabled="true"
|
||||
android:exported="true" />
|
||||
<service
|
||||
android:name=".plugins.Wear.wearintegration.WatchUpdaterService"
|
||||
android:name=".plugins.general.wear.wearintegration.WatchUpdaterService"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<service
|
||||
android:name=".plugins.NSClientInternal.services.NSClientService"
|
||||
android:name=".plugins.general.nsclient.services.NSClientService"
|
||||
android:enabled="true"
|
||||
android:exported="true" />
|
||||
<service
|
||||
|
@ -183,12 +185,12 @@
|
|||
android:enabled="true"
|
||||
android:exported="true" />
|
||||
<service
|
||||
android:name=".plugins.Overview.notifications.DismissNotificationService"
|
||||
android:name=".plugins.general.overview.notifications.DismissNotificationService"
|
||||
android:exported="false" />
|
||||
|
||||
<service android:name=".plugins.Persistentnotification.DummyService" />
|
||||
<service android:name=".plugins.PumpInsightLocal.connection_service.InsightConnectionService" />
|
||||
<service android:name=".plugins.PumpInsightLocal.InsightAlertService" />
|
||||
<service android:name=".plugins.general.persistentNotification.DummyService" />
|
||||
<service android:name=".plugins.pump.insight.connection_service.InsightConnectionService" />
|
||||
<service android:name=".plugins.pump.insight.InsightAlertService" />
|
||||
|
||||
<meta-data
|
||||
android:name="io.fabric.ApiKey"
|
||||
|
@ -203,17 +205,17 @@
|
|||
<activity
|
||||
android:name=".activities.SingleFragmentActivity"
|
||||
android:theme="@style/AppTheme" />
|
||||
<activity android:name=".plugins.Maintenance.activities.LogSettingActivity"></activity>
|
||||
<activity android:name=".plugins.general.maintenance.activities.LogSettingActivity"></activity>
|
||||
<activity
|
||||
android:name=".plugins.PumpInsightLocal.activities.InsightPairingActivity"
|
||||
android:name=".plugins.pump.insight.activities.InsightPairingActivity"
|
||||
android:theme="@style/AppTheme"
|
||||
android:label="@string/insight_pairing" />
|
||||
<activity
|
||||
android:name=".plugins.PumpInsightLocal.activities.InsightAlertActivity"
|
||||
android:name=".plugins.pump.insight.activities.InsightAlertActivity"
|
||||
android:label="@string/pump_alert"
|
||||
android:theme="@style/InsightAlertDialog" />
|
||||
<activity
|
||||
android:name=".plugins.PumpInsightLocal.activities.InsightPairingInformationActivity"
|
||||
android:name=".plugins.pump.insight.activities.InsightPairingInformationActivity"
|
||||
android:theme="@style/AppTheme"
|
||||
android:label="@string/pairing_information" />
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
@ -378,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;
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
package info.nightscout.androidaps;
|
||||
|
||||
import android.app.Application;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.PluralsRes;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.crashlytics.android.Crashlytics;
|
||||
import com.crashlytics.android.answers.Answers;
|
||||
|
@ -34,69 +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.Loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.plugins.Maintenance.LoggerUtils;
|
||||
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.PumpCommon.hw.rileylink.RileyLinkConst;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
|
||||
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.PumpInsightLocal.LocalInsightPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.MedtronicPumpPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicConst;
|
||||
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.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.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.general.actions.ActionsFragment;
|
||||
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.utils.SP;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
|
||||
public class MainApp extends Application {
|
||||
|
@ -122,7 +112,6 @@ public class MainApp extends Application {
|
|||
public static boolean devBranch;
|
||||
public static boolean engineeringMode;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
@ -164,8 +153,7 @@ public class MainApp extends Application {
|
|||
// Register all tabs in app here
|
||||
pluginsList.add(OverviewPlugin.getPlugin());
|
||||
pluginsList.add(IobCobCalculatorPlugin.getPlugin());
|
||||
if (Config.ACTION)
|
||||
pluginsList.add(ActionsFragment.getPlugin());
|
||||
if (Config.ACTION) pluginsList.add(ActionsFragment.getPlugin());
|
||||
pluginsList.add(InsulinOrefRapidActingPlugin.getPlugin());
|
||||
pluginsList.add(InsulinOrefUltraRapidActingPlugin.getPlugin());
|
||||
pluginsList.add(InsulinOrefFreePeakPlugin.getPlugin());
|
||||
|
@ -177,34 +165,24 @@ 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 && engineeringMode) pluginsList.add(LocalInsightPlugin.getInstance());
|
||||
if (Config.PUMPDRIVERS) pluginsList.add(LocalInsightPlugin.getPlugin());
|
||||
pluginsList.add(CareportalPlugin.getPlugin());
|
||||
if (Config.PUMPDRIVERS) pluginsList.add(ComboPlugin.getPlugin());
|
||||
if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin());
|
||||
if (Config.PUMPDRIVERS && engineeringMode) {
|
||||
pluginsList.add(MedtronicPumpPlugin.getPlugin());
|
||||
}
|
||||
if (Config.PUMPDRIVERS)
|
||||
pluginsList.add(ComboPlugin.getPlugin());
|
||||
if (Config.MDI)
|
||||
pluginsList.add(MDIPlugin.getPlugin());
|
||||
pluginsList.add(VirtualPumpPlugin.getPlugin());
|
||||
if (Config.APS)
|
||||
pluginsList.add(LoopPlugin.getPlugin());
|
||||
if (Config.APS)
|
||||
pluginsList.add(OpenAPSMAPlugin.getPlugin());
|
||||
if (Config.APS)
|
||||
pluginsList.add(OpenAPSAMAPlugin.getPlugin());
|
||||
if (Config.APS)
|
||||
pluginsList.add(OpenAPSSMBPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(LoopPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(OpenAPSMAPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(OpenAPSSMBPlugin.getPlugin());
|
||||
pluginsList.add(NSProfilePlugin.getPlugin());
|
||||
if (Config.OTHERPROFILES)
|
||||
pluginsList.add(SimpleProfilePlugin.getPlugin());
|
||||
if (Config.OTHERPROFILES)
|
||||
pluginsList.add(LocalProfilePlugin.getPlugin());
|
||||
if (Config.OTHERPROFILES) pluginsList.add(SimpleProfilePlugin.getPlugin());
|
||||
if (Config.OTHERPROFILES) pluginsList.add(LocalProfilePlugin.getPlugin());
|
||||
pluginsList.add(TreatmentsPlugin.getPlugin());
|
||||
if (Config.SAFETY)
|
||||
pluginsList.add(SafetyPlugin.getPlugin());
|
||||
if (Config.APS)
|
||||
pluginsList.add(ObjectivesPlugin.getPlugin());
|
||||
if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(ObjectivesPlugin.getPlugin());
|
||||
pluginsList.add(SourceXdripPlugin.getPlugin());
|
||||
pluginsList.add(SourceNSClientPlugin.getPlugin());
|
||||
pluginsList.add(SourceMM640gPlugin.getPlugin());
|
||||
|
@ -212,6 +190,7 @@ public class MainApp extends Application {
|
|||
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());
|
||||
|
@ -224,6 +203,8 @@ public class MainApp extends Application {
|
|||
|
||||
pluginsList.add(ConfigBuilderPlugin.getPlugin());
|
||||
|
||||
pluginsList.add(DstHelperPlugin.getPlugin());
|
||||
|
||||
ConfigBuilderPlugin.getPlugin().initialize();
|
||||
}
|
||||
|
||||
|
@ -239,7 +220,6 @@ public class MainApp extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void registerLocalBroadcastReceiver() {
|
||||
lbm = LocalBroadcastManager.getInstance(this);
|
||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_TREATMENT));
|
||||
|
@ -314,13 +294,11 @@ public class MainApp extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void stopKeepAliveService() {
|
||||
if (keepAliveReceiver != null)
|
||||
KeepAliveReceiver.cancelAlarm(this);
|
||||
}
|
||||
|
||||
|
||||
public static void subscribe(Object subscriber) {
|
||||
try {
|
||||
bus().register(subscriber);
|
||||
|
@ -329,7 +307,6 @@ public class MainApp extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static void unsubscribe(Object subscriber) {
|
||||
try {
|
||||
bus().unregister(subscriber);
|
||||
|
@ -338,42 +315,34 @@ public class MainApp extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static Bus bus() {
|
||||
return sBus;
|
||||
}
|
||||
|
||||
|
||||
public static String gs(int id) {
|
||||
return sResources.getString(id);
|
||||
}
|
||||
|
||||
|
||||
public static String gs(int id, Object... args) {
|
||||
return sResources.getString(id, args);
|
||||
}
|
||||
|
||||
|
||||
public static String gq(@PluralsRes int id, int quantity, Object... args) {
|
||||
return sResources.getQuantityString(id, quantity, args);
|
||||
}
|
||||
|
||||
|
||||
public static int gc(int id) {
|
||||
return sResources.getColor(id);
|
||||
}
|
||||
|
||||
|
||||
public static MainApp instance() {
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
|
||||
public static DatabaseHelper getDbHelper() {
|
||||
return sDatabaseHelper;
|
||||
}
|
||||
|
||||
|
||||
public static void closeDbHelper() {
|
||||
if (sDatabaseHelper != null) {
|
||||
sDatabaseHelper.close();
|
||||
|
@ -381,17 +350,14 @@ public class MainApp extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static ConstraintChecker getConstraintChecker() {
|
||||
return sConstraintsChecker;
|
||||
}
|
||||
|
||||
|
||||
public static ArrayList<PluginBase> getPluginsList() {
|
||||
return pluginsList;
|
||||
}
|
||||
|
||||
|
||||
public static ArrayList<PluginBase> getSpecificPluginsList(PluginType type) {
|
||||
ArrayList<PluginBase> newList = new ArrayList<>();
|
||||
|
||||
|
@ -406,7 +372,6 @@ public class MainApp extends Application {
|
|||
return newList;
|
||||
}
|
||||
|
||||
|
||||
public static ArrayList<PluginBase> getSpecificPluginsVisibleInList(PluginType type) {
|
||||
ArrayList<PluginBase> newList = new ArrayList<>();
|
||||
|
||||
|
@ -422,7 +387,6 @@ public class MainApp extends Application {
|
|||
return newList;
|
||||
}
|
||||
|
||||
|
||||
public static ArrayList<PluginBase> getSpecificPluginsListByInterface(Class interfaceClass) {
|
||||
ArrayList<PluginBase> newList = new ArrayList<>();
|
||||
|
||||
|
@ -437,7 +401,6 @@ public class MainApp extends Application {
|
|||
return newList;
|
||||
}
|
||||
|
||||
|
||||
public static ArrayList<PluginBase> getSpecificPluginsVisibleInListByInterface(Class interfaceClass, PluginType type) {
|
||||
ArrayList<PluginBase> newList = new ArrayList<>();
|
||||
|
||||
|
@ -453,13 +416,12 @@ public class MainApp extends Application {
|
|||
return newList;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public static <T extends PluginBase> T getSpecificPlugin(Class<T> pluginClass) {
|
||||
if (pluginsList != null) {
|
||||
for (PluginBase p : pluginsList) {
|
||||
if (pluginClass.isAssignableFrom(p.getClass()))
|
||||
return (T)p;
|
||||
return (T) p;
|
||||
}
|
||||
} else {
|
||||
log.error("pluginsList=null");
|
||||
|
@ -467,23 +429,33 @@ public class MainApp extends Application {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isEngineeringModeOrRelease() {
|
||||
if (!Config.APS)
|
||||
return true;
|
||||
return engineeringMode || !devBranch;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isEngineeringMode() {
|
||||
return engineeringMode;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isDev() {
|
||||
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() {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -19,39 +19,36 @@ 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.PumpMedtronic.MedtronicPumpPlugin;
|
||||
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.utils.LocaleHelper;
|
||||
import info.nightscout.utils.OKDialog;
|
||||
import info.nightscout.utils.SP;
|
||||
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;
|
||||
|
||||
public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
MyPreferenceFragment myPreferenceFragment;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -63,7 +60,6 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
|||
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
MainApp.bus().post(new EventPreferenceChange(key));
|
||||
|
@ -71,47 +67,41 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
|||
String lang = sharedPreferences.getString("language", "en");
|
||||
LocaleHelper.setLocale(getApplicationContext(), lang);
|
||||
MainApp.bus().post(new EventRefreshGui(true));
|
||||
// recreate() does not update language so better close settings
|
||||
//recreate() does not update language so better close settings
|
||||
finish();
|
||||
}
|
||||
if (key.equals("short_tabtitles")) {
|
||||
MainApp.bus().post(new EventRefreshGui());
|
||||
}
|
||||
if (key.equals(MainApp.gs(R.string.key_openapsama_useautosens))
|
||||
&& SP.getBoolean(R.string.key_openapsama_useautosens, false)) {
|
||||
OKDialog.show(this, MainApp.gs(R.string.configbuilder_sensitivity),
|
||||
MainApp.gs(R.string.sensitivity_warning), null);
|
||||
if (key.equals(MainApp.gs(R.string.key_openapsama_useautosens)) && SP.getBoolean(R.string.key_openapsama_useautosens, false)) {
|
||||
OKDialog.show(this, MainApp.gs(R.string.configbuilder_sensitivity), MainApp.gs(R.string.sensitivity_warning), null);
|
||||
}
|
||||
|
||||
updatePrefSummary(myPreferenceFragment.getPreference(key));
|
||||
}
|
||||
|
||||
|
||||
private static void updatePrefSummary(Preference pref) {
|
||||
if (pref instanceof ListPreference) {
|
||||
ListPreference listPref = (ListPreference)pref;
|
||||
ListPreference listPref = (ListPreference) pref;
|
||||
pref.setSummary(listPref.getEntry());
|
||||
}
|
||||
if (pref instanceof EditTextPreference) {
|
||||
EditTextPreference editTextPref = (EditTextPreference)pref;
|
||||
EditTextPreference editTextPref = (EditTextPreference) pref;
|
||||
if (pref.getKey().contains("password") || pref.getKey().contains("secret")) {
|
||||
pref.setSummary("******");
|
||||
} else if (pref.getKey().equals(MainApp.gs(R.string.key_danars_name))) {
|
||||
pref.setSummary(SP.getString(R.string.key_danars_name, ""));
|
||||
} else if (editTextPref.getText() != null) {
|
||||
((EditTextPreference)pref).setDialogMessage(editTextPref.getDialogMessage());
|
||||
((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage());
|
||||
pref.setSummary(editTextPref.getText());
|
||||
} else if (pref.getKey().contains("smscommunicator_allowednumbers")
|
||||
&& TextUtils.isEmpty(editTextPref.getText().trim())) {
|
||||
} else if (pref.getKey().contains("smscommunicator_allowednumbers") && TextUtils.isEmpty(editTextPref.getText().trim())) {
|
||||
pref.setSummary(MainApp.gs(R.string.smscommunicator_allowednumbers_summary));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void initSummary(Preference p) {
|
||||
if (p instanceof PreferenceGroup) {
|
||||
PreferenceGroup pGrp = (PreferenceGroup)p;
|
||||
PreferenceGroup pGrp = (PreferenceGroup) p;
|
||||
for (int i = 0; i < pGrp.getPreferenceCount(); i++) {
|
||||
initSummary(pGrp.getPreference(i));
|
||||
}
|
||||
|
@ -121,23 +111,19 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
|||
}
|
||||
|
||||
public static class MyPreferenceFragment extends PreferenceFragment {
|
||||
|
||||
private Integer id;
|
||||
|
||||
|
||||
@Override
|
||||
public void setArguments(Bundle args) {
|
||||
super.setArguments(args);
|
||||
id = args.getInt("id");
|
||||
}
|
||||
|
||||
|
||||
void addPreferencesFromResourceIfEnabled(PluginBase p, PluginType type) {
|
||||
if (p.isEnabled(type) && p.getPreferencesId() != -1)
|
||||
addPreferencesFromResource(p.getPreferencesId());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -178,7 +164,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);
|
||||
addPreferencesFromResourceIfEnabled(MedtronicPumpPlugin.getPlugin(), PluginType.PUMP);
|
||||
|
||||
|
@ -220,14 +206,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
|||
initSummary(getPreferenceScreen());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("id", id);
|
||||
}
|
||||
|
||||
|
||||
public Preference getPreference(String key) {
|
||||
return findPreference(key);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<BgReading> data = MainApp.getDbHelper().getBgreadingsDataFromTime(fromtime, false);
|
||||
//long fromtime = DateUtil.now() - 60 * 1000L * 45;
|
||||
//List<BgReading> data = MainApp.getDbHelper().getBgreadingsDataFromTime(fromtime, false);
|
||||
|
||||
List<BgReading> 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<Double> short_deltas = new ArrayList<Double>();
|
||||
ArrayList<Double> long_deltas = new ArrayList<Double>();
|
||||
|
||||
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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,13 +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.utils.MidnightTime;
|
||||
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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -47,19 +47,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.PumpInsightLocal.database.InsightBolusID;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.database.InsightHistoryOffset;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.database.InsightPumpID;
|
||||
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
|
||||
|
@ -454,24 +454,15 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
*/
|
||||
@Nullable
|
||||
public static BgReading lastBg() {
|
||||
List<BgReading> bgList = null;
|
||||
List<BgReading> bgList = IobCobCalculatorPlugin.getPlugin().getBgReadings();
|
||||
|
||||
try {
|
||||
Dao<BgReading, Long> daoBgReadings = MainApp.getDbHelper().getDaoBgReadings();
|
||||
QueryBuilder<BgReading, Long> queryBuilder = daoBgReadings.queryBuilder();
|
||||
queryBuilder.orderBy("date", false);
|
||||
queryBuilder.limit(1L);
|
||||
queryBuilder.where().ge("value", 39).and().eq("isValid", true);
|
||||
PreparedQuery<BgReading> 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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
@ -104,7 +103,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
|
|||
/**
|
||||
* 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.utils.PercentageSplitter#pureName}
|
||||
* {@link info.nightscout.androidaps.utils.PercentageSplitter#pureName}
|
||||
*/
|
||||
public String getCustomizedName() {
|
||||
String name = profileName;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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<StatusItem> l = insightPlugin.getStatusItems(refresh);
|
||||
|
||||
holder.removeAllViews();
|
||||
|
||||
for (StatusItem row : l) {
|
||||
viewAdapter.inflateStatus(row);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,954 +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.Actions.defs.CustomAction;
|
||||
import info.nightscout.androidaps.plugins.Actions.defs.CustomActionType;
|
||||
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.
|
||||
* <p>
|
||||
* Connects to SightRemote app service using SightParser library
|
||||
* <p>
|
||||
* SightRemote and SightParser created by Tebbe Ubben
|
||||
* <p>
|
||||
* 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<BRProfileBlock.ProfileBlock> 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<BRProfileBlock.ProfileBlock> 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getReservoirLevel() { return reservoirInUnits; }
|
||||
|
||||
@Override
|
||||
public int getBatteryLevel() { return batteryPercent; }
|
||||
|
||||
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<StatusItem> getStatusItems(boolean refresh) {
|
||||
final List<StatusItem> 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<StatusItem> 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<StatusItem> 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> T fetchTaskRunner(TaskRunner taskRunner, Class<T> 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 extends AppLayerMessage> T fetchSingleMessage(AppLayerMessage message, Class<T> 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<Integer> applyBasalPercentConstraints(Constraint<Integer> 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<Double> applyBolusConstraints(Constraint<Double> 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;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<CustomAction> getCustomActions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
|
||||
return 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
* <p>
|
||||
* Connects to SightRemote app service using SightParser library
|
||||
* <p>
|
||||
* SightRemote and SightParser created by Tebbe Ubben
|
||||
* <p>
|
||||
* 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<Status, Long> 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.insight_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<StatusItem> getStatusStatistics() {
|
||||
final List<StatusItem> 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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<BRProfileBlock.ProfileBlock> basalProfile;
|
||||
public double maximumBolusAmount;
|
||||
public double maximumBasalAmount;
|
||||
public double minimumBolusAmount;
|
||||
public double minimumBasalAmount;
|
||||
}
|
||||
}
|
|
@ -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<BRProfileBlock.ProfileBlock> profileBlocks;
|
||||
private BRProfileBlock profileBlock;
|
||||
|
||||
public WriteBasalProfileTaskRunner(SightServiceConnector serviceConnector, List<BRProfileBlock.ProfileBlock> 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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 {
|
||||
}
|
|
@ -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.
|
||||
* <p>
|
||||
* 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;
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
* <p>
|
||||
* 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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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.
|
||||
* <p>
|
||||
* Useful utility methods from xDrip+
|
||||
*/
|
||||
|
||||
public class Helpers {
|
||||
private static Logger log = LoggerFactory.getLogger(L.PUMP);
|
||||
|
||||
|
||||
private static final Map<String, Long> 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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.configuration;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.AppLayerMessage;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.MessagePriority;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.Service;
|
||||
|
||||
public class CloseConfigurationWriteSessionMessage extends AppLayerMessage {
|
||||
|
||||
public CloseConfigurationWriteSessionMessage() {
|
||||
super(MessagePriority.NORMAL, false, false, Service.CONFIGURATION);
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.configuration;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.AppLayerMessage;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.MessagePriority;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.Service;
|
||||
|
||||
public class OpenConfigurationWriteSessionMessage extends AppLayerMessage {
|
||||
|
||||
public OpenConfigurationWriteSessionMessage() {
|
||||
super(MessagePriority.NORMAL, false, false, Service.CONFIGURATION);
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.connection;
|
||||
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.AppLayerMessage;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.Service;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.MessagePriority;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.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"));
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.connection;
|
||||
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.AppLayerMessage;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.Service;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.MessagePriority;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.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"));
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history;
|
||||
|
||||
public enum HistoryReadingDirection {
|
||||
|
||||
FORWARD,
|
||||
BACKWARD;
|
||||
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.AppLayerMessage;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.Service;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.MessagePriority;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.utils.ByteBuf;
|
||||
|
||||
public class StopReadingHistoryMessage extends AppLayerMessage {
|
||||
|
||||
public StopReadingHistoryMessage() {
|
||||
super(MessagePriority.NORMAL, false, false, Service.HISTORY);
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events;
|
||||
|
||||
public class CartridgeInsertedEvent extends HistoryEvent {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events;
|
||||
|
||||
public class CartridgeRemovedEvent extends HistoryEvent {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events;
|
||||
|
||||
public class DefaultDateTimeSetEvent extends HistoryEvent {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events;
|
||||
|
||||
public class OccurrenceOfErrorEvent extends OccurrenceOfAlertEvent {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events;
|
||||
|
||||
public class OccurrenceOfMaintenanceEvent extends OccurrenceOfAlertEvent {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events;
|
||||
|
||||
public class OccurrenceOfWarningEvent extends OccurrenceOfAlertEvent {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events;
|
||||
|
||||
public class PowerDownEvent extends HistoryEvent {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events;
|
||||
|
||||
public class PowerUpEvent extends HistoryEvent {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class BRProfile1Block extends BRProfileBlock {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class BRProfile1NameBlock extends NameBlock {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class BRProfile2Block extends BRProfileBlock {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class BRProfile2NameBlock extends NameBlock {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class BRProfile3Block extends BRProfileBlock {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class BRProfile3NameBlock extends NameBlock {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class BRProfile4Block extends BRProfileBlock {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class BRProfile4NameBlock extends NameBlock {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class BRProfile5Block extends BRProfileBlock {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class BRProfile5NameBlock extends NameBlock {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class FactoryMaxBasalAmountBlock extends InsulinAmountLimitationBlock {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class FactoryMaxBolusAmountBlock extends InsulinAmountLimitationBlock {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class FactoryMinBasalAmountBlock extends InsulinAmountLimitationBlock {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class FactoryMinBolusAmountBlock extends InsulinAmountLimitationBlock {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class MaxBasalAmountBlock extends InsulinAmountLimitationBlock {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
public class MaxBolusAmountBlock extends InsulinAmountLimitationBlock {
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.utils.ByteBuf;
|
||||
|
||||
public abstract class ParameterBlock {
|
||||
|
||||
public abstract void parse(ByteBuf byteBuf);
|
||||
public abstract ByteBuf getData();
|
||||
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.remote_control;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.AppLayerMessage;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.Service;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.MessagePriority;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.utils.ByteBuf;
|
||||
|
||||
public class CancelTBRMessage extends AppLayerMessage {
|
||||
public CancelTBRMessage() {
|
||||
super(MessagePriority.HIGHER, false, false, Service.REMOTE_CONTROL);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.remote_control;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.AppLayerMessage;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.Service;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.MessagePriority;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.OperatingMode;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.ids.OperatingModeIDs;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.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;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.status;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.AppLayerMessage;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.Service;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.MessagePriority;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.OperatingMode;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.ids.OperatingModeIDs;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.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;
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors;
|
||||
|
||||
public enum AlertStatus {
|
||||
|
||||
ACTIVE,
|
||||
SNOOZED;
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors;
|
||||
|
||||
public enum BatteryType {
|
||||
|
||||
ALKALI,
|
||||
LITHIUM,
|
||||
NI_MH;
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors;
|
||||
|
||||
public enum BolusType {
|
||||
|
||||
STANDARD,
|
||||
EXTENDED,
|
||||
MULTIWAVE;
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors;
|
||||
|
||||
public enum CartridgeType {
|
||||
|
||||
PREFILLED,
|
||||
SELF_FILLED;
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors;
|
||||
|
||||
public enum MessagePriority {
|
||||
|
||||
NORMAL,
|
||||
HIGHER,
|
||||
HIGHEST;
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors;
|
||||
|
||||
public enum OperatingMode {
|
||||
|
||||
STARTED,
|
||||
STOPPED,
|
||||
PAUSED;
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors;
|
||||
|
||||
public enum SymbolStatus {
|
||||
|
||||
FULL,
|
||||
LOW,
|
||||
EMPTY;
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.exceptions;
|
||||
|
||||
public abstract class AppLayerException extends InsightException {
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.exceptions;
|
||||
|
||||
public class ConnectionLostException extends InsightException {
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.exceptions;
|
||||
|
||||
public class DisconnectedException extends InsightException {
|
||||
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.exceptions;
|
||||
|
||||
public abstract class InsightException extends Exception {
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.exceptions;
|
||||
|
||||
public class InvalidAppCRCException extends AppLayerException {
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.exceptions;
|
||||
|
||||
public class InvalidMacTrailerException extends SatlException {
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpInsightLocal.exceptions;
|
||||
|
||||
public class InvalidNonceException extends SatlException {
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue