diff --git a/app/build.gradle b/app/build.gradle index 58c4d73eac..c633d46524 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,6 +33,7 @@ ext { repositories { jcenter { url "https://jcenter.bintray.com/" } mavenCentral() + google() } def generateGitBuild = { -> @@ -280,8 +281,7 @@ dependencies { implementation "com.joanzapata.iconify:android-iconify-fontawesome:2.2.2" implementation 'com.madgag.spongycastle:core:1.58.0.0' // Omnipod wizard - implementation(name: "com.atech-software.android.library.wizardpager-1.1.1", ext: "aar") - + implementation(name: "com.atech-software.android.library.wizardpager-1.1.4", ext: "aar") implementation("com.google.android:flexbox:0.3.0") { exclude group: "com.android.support" } @@ -333,7 +333,7 @@ dependencies { // Phone checker implementation 'com.scottyab:rootbeer-lib:0.0.8' - + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha03' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test:rules:1.3.0-beta01' diff --git a/app/libs/com.atech-software.android.library.wizardpager-1.1.1.aar b/app/libs/com.atech-software.android.library.wizardpager-1.1.1.aar deleted file mode 100644 index 57e2f806bb..0000000000 Binary files a/app/libs/com.atech-software.android.library.wizardpager-1.1.1.aar and /dev/null differ diff --git a/app/libs/com.atech-software.android.library.wizardpager-1.1.4.aar b/app/libs/com.atech-software.android.library.wizardpager-1.1.4.aar new file mode 100644 index 0000000000..af0c6511cf Binary files /dev/null and b/app/libs/com.atech-software.android.library.wizardpager-1.1.4.aar differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8f3db8e179..531e88e83a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -263,17 +263,6 @@ - - - - - - - diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 7ba9957ed8..d96fda8d3b 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -57,7 +57,6 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHi 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.omnipod.driver.db.PodHistory; import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin; import info.nightscout.androidaps.utils.JsonHelper; import info.nightscout.androidaps.utils.PercentageSplitter; @@ -88,7 +87,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { public static final String DATABASE_INSIGHT_HISTORY_OFFSETS = "InsightHistoryOffsets"; public static final String DATABASE_INSIGHT_BOLUS_IDS = "InsightBolusIDs"; public static final String DATABASE_INSIGHT_PUMP_IDS = "InsightPumpIDs"; - public static final String DATABASE_POD_HISTORY = "PodHistory"; private static final int DATABASE_VERSION = 12; @@ -142,7 +140,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, InsightHistoryOffset.class); TableUtils.createTableIfNotExists(connectionSource, InsightBolusID.class); TableUtils.createTableIfNotExists(connectionSource, InsightPumpID.class); - TableUtils.createTableIfNotExists(connectionSource, PodHistory.class); + TableUtils.createTableIfNotExists(connectionSource, OmnipodHistoryRecord.class); database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DATABASE_INSIGHT_BOLUS_IDS + "\", " + System.currentTimeMillis() + " " + "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DATABASE_INSIGHT_BOLUS_IDS + "\")"); database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DATABASE_INSIGHT_PUMP_IDS + "\", " + System.currentTimeMillis() + " " + @@ -219,7 +217,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.dropTable(connectionSource, CareportalEvent.class, true); TableUtils.dropTable(connectionSource, ProfileSwitch.class, true); TableUtils.dropTable(connectionSource, TDD.class, true); - TableUtils.dropTable(connectionSource, PodHistory.class, true); + TableUtils.dropTable(connectionSource, OmnipodHistoryRecord.class, true); TableUtils.createTableIfNotExists(connectionSource, TempTarget.class); TableUtils.createTableIfNotExists(connectionSource, BgReading.class); TableUtils.createTableIfNotExists(connectionSource, DanaRHistoryRecord.class); @@ -229,7 +227,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class); TableUtils.createTableIfNotExists(connectionSource, ProfileSwitch.class); TableUtils.createTableIfNotExists(connectionSource, TDD.class); - TableUtils.createTableIfNotExists(connectionSource, PodHistory.class); + TableUtils.createTableIfNotExists(connectionSource, OmnipodHistoryRecord.class); updateEarliestDataChange(0); } catch (SQLException e) { aapsLogger.error("Unhandled exception", e); @@ -364,8 +362,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return getDao(InsightHistoryOffset.class); } - private Dao getDaoPodHistory() throws SQLException { - return getDao(PodHistory.class); + private Dao getDaoPodHistory() throws SQLException { + return getDao(OmnipodHistoryRecord.class); } public long roundDateToSec(long date) { @@ -1865,25 +1863,25 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { // ---------------- PodHistory handling --------------- - public void createOrUpdate(PodHistory podHistory) { + public void createOrUpdate(OmnipodHistoryRecord omnipodHistoryRecord) { try { - getDaoPodHistory().createOrUpdate(podHistory); + getDaoPodHistory().createOrUpdate(omnipodHistoryRecord); } catch (SQLException e) { aapsLogger.error("Unhandled exception", e); } } - public List getPodHistoryFromTime(long from, boolean ascending) { + public List getAllOmnipodHistoryRecordsFromTimeStamp(long from, boolean ascending) { try { - Dao daoPodHistory = getDaoPodHistory(); - List podHistories; - QueryBuilder queryBuilder = daoPodHistory.queryBuilder(); + Dao daoPodHistory = getDaoPodHistory(); + List podHistories; + QueryBuilder queryBuilder = daoPodHistory.queryBuilder(); queryBuilder.orderBy("date", ascending); //queryBuilder.limit(100L); Where where = queryBuilder.where(); where.ge("date", from); - PreparedQuery preparedQuery = queryBuilder.prepare(); + PreparedQuery preparedQuery = queryBuilder.prepare(); podHistories = daoPodHistory.query(preparedQuery); return podHistories; } catch (SQLException e) { diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java index 0e9f9d82b2..4468692189 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java @@ -16,7 +16,8 @@ import info.nightscout.androidaps.interfaces.DatabaseHelperInterface; @Singleton public class DatabaseHelperProvider implements DatabaseHelperInterface { - @Inject DatabaseHelperProvider() {} + @Inject DatabaseHelperProvider() { + } @NotNull @Override public List getAllBgreadingsDataFromTime(long mills, boolean ascending) { return MainApp.getDbHelper().getAllBgreadingsDataFromTime(mills, ascending); @@ -30,6 +31,10 @@ public class DatabaseHelperProvider implements DatabaseHelperInterface { MainApp.getDbHelper().createOrUpdate(record); } + @Override public void createOrUpdate(@NotNull OmnipodHistoryRecord record) { + MainApp.getDbHelper().createOrUpdate(record); + } + @NotNull @Override public List getDanaRHistoryRecordsByType(byte type) { return MainApp.getDbHelper().getDanaRHistoryRecordsByType(type); } @@ -86,10 +91,14 @@ public class DatabaseHelperProvider implements DatabaseHelperInterface { return MainApp.getDbHelper().getTemporaryBasalsDataFromTime(mills, ascending); } - @NotNull @Override public CareportalEvent getCareportalEventFromTimestamp(long timestamp) { + @Override public CareportalEvent getCareportalEventFromTimestamp(long timestamp) { return MainApp.getDbHelper().getCareportalEventFromTimestamp(timestamp); } + @NotNull @Override public List getAllOmnipodHistoryRecordsFromTimestamp(long timestamp, boolean ascending) { + return MainApp.getDbHelper().getAllOmnipodHistoryRecordsFromTimeStamp(timestamp, ascending); + } + @NotNull @Override public List getTDDsForLastXDays(int days) { return MainApp.getDbHelper().getTDDsForLastXDays(days); } diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt index 544580925a..a748e57eb1 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt @@ -26,6 +26,7 @@ import javax.inject.Singleton CommandQueueModule::class, ObjectivesModule::class, WizardModule::class, + RileyLinkModule::class, MedtronicModule::class, APSModule::class, PreferencesModule::class, diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt index cde5137ac9..07c8cd1495 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt @@ -34,7 +34,6 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyL import info.nightscout.androidaps.plugins.pump.insight.LocalInsightFragment import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicFragment import info.nightscout.androidaps.plugins.pump.medtronic.dialog.RileyLinkStatusDeviceMedtronic -import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodFragment import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpFragment import info.nightscout.androidaps.plugins.source.BGSourceFragment import info.nightscout.androidaps.plugins.treatments.TreatmentsFragment @@ -66,7 +65,6 @@ abstract class FragmentsModule { @ContributesAndroidInjector abstract fun contributesLoopFragment(): LoopFragment @ContributesAndroidInjector abstract fun contributesMaintenanceFragment(): MaintenanceFragment @ContributesAndroidInjector abstract fun contributesMedtronicFragment(): MedtronicFragment - @ContributesAndroidInjector abstract fun contributesOmnipodFragment(): OmnipodFragment @ContributesAndroidInjector abstract fun contributesNSProfileFragment(): NSProfileFragment @ContributesAndroidInjector abstract fun contributesNSClientFragment(): NSClientFragment @ContributesAndroidInjector abstract fun contributesSmsCommunicatorFragment(): SmsCommunicatorFragment diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/MedtronicModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/MedtronicModule.kt index f813a6d49d..cadac7d13c 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/MedtronicModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/MedtronicModule.kt @@ -2,33 +2,12 @@ package info.nightscout.androidaps.dependencyInjection import dagger.Module import dagger.android.ContributesAndroidInjector -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SendAndListen -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SetPreamble -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioPacket -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioResponse -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.* import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUITask @Module @Suppress("unused") abstract class MedtronicModule { - @ContributesAndroidInjector abstract fun rileyLinkCommunicationManagerProvider(): RileyLinkCommunicationManager @ContributesAndroidInjector abstract fun medtronicCommunicationManagerProvider(): MedtronicCommunicationManager @ContributesAndroidInjector abstract fun medtronicUITaskProvider(): MedtronicUITask - @ContributesAndroidInjector abstract fun serviceTaskProvider(): ServiceTask - @ContributesAndroidInjector abstract fun pumpTaskProvider(): PumpTask - @ContributesAndroidInjector abstract fun discoverGattServicesTaskProvider(): DiscoverGattServicesTask - @ContributesAndroidInjector abstract fun initializePumpManagerTaskProvider(): InitializePumpManagerTask - @ContributesAndroidInjector abstract fun resetRileyLinkConfigurationTaskProvider(): ResetRileyLinkConfigurationTask - @ContributesAndroidInjector abstract fun wakeAndTuneTaskProvider(): WakeAndTuneTask - @ContributesAndroidInjector abstract fun radioResponseProvider(): RadioResponse - @ContributesAndroidInjector abstract fun rileyLinkBLEProvider(): RileyLinkBLE - @ContributesAndroidInjector abstract fun rfSpyProvider(): RFSpy - @ContributesAndroidInjector abstract fun sendAndListenProvider(): SendAndListen - @ContributesAndroidInjector abstract fun setPreambleProvider(): SetPreamble - @ContributesAndroidInjector abstract fun radioPacketProvider(): RadioPacket } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/OmnipodModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/OmnipodModule.kt deleted file mode 100644 index ccb538dfbd..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/OmnipodModule.kt +++ /dev/null @@ -1,28 +0,0 @@ -package info.nightscout.androidaps.dependencyInjection - -import dagger.Module -import dagger.android.ContributesAndroidInjector -import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager -import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState -import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodHistoryActivity -import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodManagementActivity -import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages.InitPodRefreshAction -import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager -import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUITask - -@Module -@Suppress("unused") -abstract class OmnipodModule { - - // Activities - @ContributesAndroidInjector abstract fun contributesPodManagementActivity(): PodManagementActivity - @ContributesAndroidInjector abstract fun contributesPodHistoryActivity(): PodHistoryActivity - - @ContributesAndroidInjector abstract fun omnipodCommunicationManagerProvider(): OmnipodCommunicationManager - @ContributesAndroidInjector abstract fun omnipodUITaskProvider(): OmnipodUITask - @ContributesAndroidInjector abstract fun aapsOmnipodManagerProvider(): AapsOmnipodManager - @ContributesAndroidInjector abstract fun initPodRefreshAction(): InitPodRefreshAction - @ContributesAndroidInjector abstract fun podSessionState(): PodSessionState - - -} diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/RileyLinkModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/RileyLinkModule.kt new file mode 100644 index 0000000000..b74b2e4263 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/RileyLinkModule.kt @@ -0,0 +1,30 @@ +package info.nightscout.androidaps.dependencyInjection + +import dagger.Module +import dagger.android.ContributesAndroidInjector +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SendAndListen +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SetPreamble +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioPacket +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioResponse +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.* + +@Module +@Suppress("unused") +abstract class RileyLinkModule { + @ContributesAndroidInjector abstract fun rileyLinkCommunicationManagerProvider(): RileyLinkCommunicationManager + @ContributesAndroidInjector abstract fun serviceTaskProvider(): ServiceTask + @ContributesAndroidInjector abstract fun pumpTaskProvider(): PumpTask + @ContributesAndroidInjector abstract fun discoverGattServicesTaskProvider(): DiscoverGattServicesTask + @ContributesAndroidInjector abstract fun initializePumpManagerTaskProvider(): InitializePumpManagerTask + @ContributesAndroidInjector abstract fun resetRileyLinkConfigurationTaskProvider(): ResetRileyLinkConfigurationTask + @ContributesAndroidInjector abstract fun wakeAndTuneTaskProvider(): WakeAndTuneTask + @ContributesAndroidInjector abstract fun radioResponseProvider(): RadioResponse + @ContributesAndroidInjector abstract fun rileyLinkBLEProvider(): RileyLinkBLE + @ContributesAndroidInjector abstract fun rfSpyProvider(): RFSpy + @ContributesAndroidInjector abstract fun sendAndListenProvider(): SendAndListen + @ContributesAndroidInjector abstract fun setPreambleProvider(): SetPreamble + @ContributesAndroidInjector abstract fun radioPacketProvider(): RadioPacket +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ServicesModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ServicesModule.kt index f961c3a863..ec71d8a4ad 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ServicesModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ServicesModule.kt @@ -10,7 +10,6 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.Riley import info.nightscout.androidaps.plugins.pump.insight.InsightAlertService import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService -import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService import info.nightscout.androidaps.services.AlarmSoundService import info.nightscout.androidaps.services.DataService import info.nightscout.androidaps.services.LocationService @@ -30,5 +29,4 @@ abstract class ServicesModule { @ContributesAndroidInjector abstract fun contributesInsightConnectionService(): InsightConnectionService @ContributesAndroidInjector abstract fun contributesRileyLinkService(): RileyLinkService @ContributesAndroidInjector abstract fun contributesRileyLinkMedtronicService(): RileyLinkMedtronicService - @ContributesAndroidInjector abstract fun contributesRileyLinkOmnipodService(): RileyLinkOmnipodService } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt index 22973b3caf..20a6493ea8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt @@ -25,7 +25,7 @@ import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction import info.nightscout.androidaps.plugins.general.overview.StatusLightHandler import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.utils.SingleClickButton +import info.nightscout.androidaps.utils.ui.SingleClickButton import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.buildHelper.BuildHelper import info.nightscout.androidaps.utils.extensions.plusAssign diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt deleted file mode 100644 index 09e80f50d5..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt +++ /dev/null @@ -1,458 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod - -import android.content.Intent -import android.graphics.Color -import android.os.Bundle -import android.os.Handler -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import dagger.android.support.DaggerFragment -import info.nightscout.androidaps.MainApp -import info.nightscout.androidaps.R -import info.nightscout.androidaps.events.EventPreferenceChange -import info.nightscout.androidaps.interfaces.ActivePluginProvider -import info.nightscout.androidaps.interfaces.CommandQueueProvider -import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.plugins.pump.common.defs.PumpType -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity -import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodStatusRequest -import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState -import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodManagementActivity -import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState -import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus -import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodAcknowledgeAlertsChanged -import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange -import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged -import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefreshButtonState -import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst -import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil -import info.nightscout.androidaps.queue.Callback -import info.nightscout.androidaps.utils.DateUtil -import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.utils.Round -import info.nightscout.androidaps.utils.T -import info.nightscout.androidaps.utils.WarnColors -import info.nightscout.androidaps.utils.alertDialogs.OKDialog -import info.nightscout.androidaps.utils.resources.ResourceHelper -import info.nightscout.androidaps.utils.sharedPreferences.SP -import io.reactivex.android.schedulers.AndroidSchedulers -import io.reactivex.disposables.CompositeDisposable -import io.reactivex.disposables.Disposable -import io.reactivex.schedulers.Schedulers -import kotlinx.android.synthetic.main.omnipod_fragment.* -import javax.inject.Inject - -class OmnipodFragment : DaggerFragment() { - - @Inject lateinit var aapsLogger: AAPSLogger - @Inject lateinit var mainApp: MainApp - @Inject lateinit var fabricPrivacy: FabricPrivacy - @Inject lateinit var resourceHelper: ResourceHelper - @Inject lateinit var rxBus: RxBusWrapper - @Inject lateinit var commandQueue: CommandQueueProvider - @Inject lateinit var activePlugin: ActivePluginProvider - @Inject lateinit var omnipodPumpPlugin: OmnipodPumpPlugin - @Inject lateinit var warnColors: WarnColors - @Inject lateinit var omnipodPumpStatus: OmnipodPumpStatus - @Inject lateinit var sp: SP - @Inject lateinit var omnipodUtil: OmnipodUtil - - private var disposable: CompositeDisposable = CompositeDisposable() - - private val loopHandler = Handler() - private lateinit var refreshLoop: Runnable - - operator fun CompositeDisposable.plusAssign(disposable: Disposable) { - add(disposable) - } - - init { - refreshLoop = Runnable { - activity?.runOnUiThread { updateGUI() } - loopHandler.postDelayed(refreshLoop, T.mins(1).msecs()) - } - } - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.omnipod_fragment, container, false) - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - omnipod_rl_status.text = resourceHelper.gs(RileyLinkServiceState.NotStarted.getResourceId(RileyLinkTargetDevice.Omnipod)) - - omnipod_pod_status.setTextColor(Color.WHITE) - omnipod_pod_status.text = "{fa-bed}" - - omnipod_pod_mgmt.setOnClickListener { - if (omnipodPumpPlugin.rileyLinkService?.verifyConfiguration() == true) { - startActivity(Intent(context, PodManagementActivity::class.java)) - } else { - displayNotConfiguredDialog() - } - } - - omnipod_refresh.setOnClickListener { - if (omnipodPumpPlugin.rileyLinkService?.verifyConfiguration() != true) { - displayNotConfiguredDialog() - } else { - omnipod_refresh.isEnabled = false - omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequest.GetPodState); - commandQueue.readStatus("Clicked Refresh", object : Callback() { - override fun run() { - activity?.runOnUiThread { omnipod_refresh.isEnabled = true } - } - }) - } - } - - omnipod_stats.setOnClickListener { - if (omnipodPumpPlugin.rileyLinkService?.verifyConfiguration() == true) { - startActivity(Intent(context, RileyLinkStatusActivity::class.java)) - } else { - displayNotConfiguredDialog() - } - } - - omnipod_pod_active_alerts_ack.setOnClickListener { - if (omnipodPumpPlugin.rileyLinkService?.verifyConfiguration() != true) { - displayNotConfiguredDialog() - } else { - omnipod_pod_active_alerts_ack.isEnabled = false - omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequest.AcknowledgeAlerts); - commandQueue.readStatus("Clicked Alert Ack", null) - } - } - - omnipod_pod_debug.setOnClickListener { - if (omnipodPumpPlugin.rileyLinkService?.verifyConfiguration() != true) { - displayNotConfiguredDialog() - } else { - omnipod_pod_debug.isEnabled = false - omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequest.GetPodPulseLog); - commandQueue.readStatus("Clicked Refresh", object : Callback() { - override fun run() { - activity?.runOnUiThread { omnipod_pod_debug.isEnabled = true } - } - }) - } - } - - omnipod_lastconnection.setTextColor(Color.WHITE) - - setVisibilityOfPodDebugButton() - - updateGUI() - } - - override fun onResume() { - super.onResume() - loopHandler.postDelayed(refreshLoop, T.mins(1).msecs()) - disposable += rxBus - .toObservable(EventOmnipodRefreshButtonState::class.java) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ omnipod_refresh.isEnabled = it.newState }, { fabricPrivacy.logException(it) }) - disposable += rxBus - .toObservable(EventOmnipodDeviceStatusChange::class.java) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ - aapsLogger.info(LTag.PUMP, "onStatusEvent(EventOmnipodDeviceStatusChange): {}", it) - setDeviceStatus() - }, { fabricPrivacy.logException(it) }) - disposable += rxBus - .toObservable(EventOmnipodPumpValuesChanged::class.java) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ updateGUI() }, { fabricPrivacy.logException(it) }) - disposable += rxBus - .toObservable(EventOmnipodAcknowledgeAlertsChanged::class.java) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ updateAcknowledgeAlerts() }, { fabricPrivacy.logException(it) }) - disposable += rxBus - .toObservable(EventPreferenceChange::class.java) - .observeOn(Schedulers.io()) - .subscribe({ - setVisibilityOfPodDebugButton() - }, { fabricPrivacy.logException(it) }) - } - - fun setVisibilityOfPodDebugButton() { - val isEnabled = sp.getBoolean(OmnipodConst.Prefs.PodDebuggingOptionsEnabled, false) - - if (isEnabled) - omnipod_pod_debug.visibility = View.VISIBLE - else - omnipod_pod_debug.visibility = View.GONE - } - - private fun displayNotConfiguredDialog() { - context?.let { - OKDialog.show(it, resourceHelper.gs(R.string.combo_warning), - resourceHelper.gs(R.string.omnipod_error_operation_not_possible_no_configuration), null) - } - } - - override fun onPause() { - super.onPause() - disposable.clear() - loopHandler.removeCallbacks(refreshLoop) - } - - @Synchronized - private fun setDeviceStatus() { - //val omnipodPumpStatus: OmnipodPumpStatus = OmnipodUtil.getPumpStatus() - // omnipodPumpStatus.rileyLinkServiceState = checkStatusSet(omnipodPumpStatus.rileyLinkServiceState, - // RileyLinkUtil.getServiceState()) as RileyLinkServiceState? - - aapsLogger.info(LTag.PUMP, "setDeviceStatus: [pumpStatus={}]", omnipodPumpStatus) - - val resourceId = omnipodPumpStatus.rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.Omnipod) - val rileyLinkError = omnipodPumpPlugin.rileyLinkService?.error - - omnipod_rl_status.text = - when { - omnipodPumpStatus.rileyLinkServiceState == RileyLinkServiceState.NotStarted -> resourceHelper.gs(resourceId) - omnipodPumpStatus.rileyLinkServiceState.isConnecting -> "{fa-bluetooth-b spin} " + resourceHelper.gs(resourceId) - omnipodPumpStatus.rileyLinkServiceState.isError && rileyLinkError == null -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId) - omnipodPumpStatus.rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump)) - else -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId) - } - omnipod_rl_status.setTextColor(if (rileyLinkError != null) Color.RED else Color.WHITE) - - // omnipodPumpStatus.rileyLinkError = checkStatusSet(omnipodPumpStatus.rileyLinkError, - // RileyLinkUtil.getError()) as RileyLinkError? - - omnipod_errors.text = - omnipodPumpStatus.rileyLinkError?.let { - resourceHelper.gs(it.getResourceId(RileyLinkTargetDevice.Omnipod)) - } ?: "-" - - val driverState = omnipodUtil.getDriverState(); - - aapsLogger.info(LTag.PUMP, "getDriverState: [driverState={}]", driverState) - - if (driverState == OmnipodDriverState.NotInitalized) { - omnipod_pod_address.text = resourceHelper.gs(R.string.omnipod_pod_name_no_info) - omnipod_pod_expiry.text = "-" - omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_not_initalized) - omnipodPumpStatus.podAvailable = false - omnipodPumpStatus.podNumber == null - } else if (driverState == OmnipodDriverState.Initalized_NoPod) { - omnipod_pod_address.text = resourceHelper.gs(R.string.omnipod_pod_name_no_info) - omnipod_pod_expiry.text = "-" - omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_no_pod_connected) - omnipodPumpStatus.podAvailable = false - omnipodPumpStatus.podNumber == null - } else if (driverState == OmnipodDriverState.Initalized_PodInitializing) { - omnipod_pod_address.text = omnipodPumpStatus.podSessionState.address.toString() - omnipod_pod_expiry.text = "-" - omnipod_pod_status.text = omnipodPumpStatus.podSessionState.getSetupProgress().name - omnipodPumpStatus.podAvailable = false - omnipodPumpStatus.podNumber == omnipodPumpStatus.podSessionState.address.toString() - } else { - omnipodPumpStatus.podLotNumber = "" + omnipodPumpStatus.podSessionState.lot - omnipodPumpStatus.podAvailable = true - omnipod_pod_address.text = omnipodPumpStatus.podSessionState.address.toString() - omnipod_pod_expiry.text = omnipodPumpStatus.podSessionState.expiryDateAsString - omnipodPumpStatus.podNumber = omnipodPumpStatus.podSessionState.address.toString() - - //pumpStatus.podSessionState = checkStatusSet(pumpStatus.podSessionState, - // OmnipodUtil.getPodSessionState()) as PodSessionState? - - var podDeviceState = omnipodPumpStatus.podDeviceState - - when (podDeviceState) { - null, - PodDeviceState.Sleeping -> omnipod_pod_status.text = "{fa-bed} " // + pumpStatus.pumpDeviceState.name()); - PodDeviceState.NeverContacted, - PodDeviceState.WakingUp, - PodDeviceState.PumpUnreachable, - PodDeviceState.ErrorWhenCommunicating, - PodDeviceState.TimeoutWhenCommunicating, - PodDeviceState.InvalidConfiguration -> omnipod_pod_status.text = " " + resourceHelper.gs(podDeviceState.resourceId) - - PodDeviceState.Active -> { - - omnipod_pod_status.text = "Active"; -// val cmd = OmnipodUtil.getCurrentCommand() -// if (cmd == null) -// omnipod_pod_status.text = " " + resourceHelper.gs(pumpStatus.pumpDeviceState.resourceId) -// else { -// aapsLogger.debug(LTag.PUMP,"Command: " + cmd) -// val cmdResourceId = cmd.resourceId -// if (cmd == MedtronicCommandType.GetHistoryData) { -// omnipod_pod_status.text = OmnipodUtil.frameNumber?.let { -// resourceHelper.gs(cmdResourceId, OmnipodUtil.pageNumber, OmnipodUtil.frameNumber) -// } -// ?: resourceHelper.gs(R.string.medtronic_cmd_desc_get_history_request, OmnipodUtil.pageNumber) -// } else { -// omnipod_pod_status.text = " " + (cmdResourceId?.let { resourceHelper.gs(it) } -// ?: cmd.getCommandDescription()) -// } -// } - } - - else -> aapsLogger.warn(LTag.PUMP, "Unknown pump state: " + omnipodPumpStatus.podDeviceState) - } - - } - -// pumpStatus.pumpDeviceState = checkStatusSet(pumpStatus.pumpDeviceState, -// OmnipodUtil.getPumpDeviceState()) as PumpDeviceState? -// -// when (pumpStatus.pumpDeviceState) { -// null, -// PumpDeviceState.Sleeping -> omnipod_pod_status.text = "{fa-bed} " // + pumpStatus.pumpDeviceState.name()); -// PumpDeviceState.NeverContacted, -// PumpDeviceState.WakingUp, -// PumpDeviceState.PumpUnreachable, -// PumpDeviceState.ErrorWhenCommunicating, -// PumpDeviceState.TimeoutWhenCommunicating, -// PumpDeviceState.InvalidConfiguration -> omnipod_pod_status.text = " " + resourceHelper.gs(pumpStatus.pumpDeviceState.resourceId) -// PumpDeviceState.Active -> { -// val cmd = OmnipodUtil.getCurrentCommand() -// if (cmd == null) -// omnipod_pod_status.text = " " + resourceHelper.gs(pumpStatus.pumpDeviceState.resourceId) -// else { -// aapsLogger.debug(LTag.PUMP,"Command: " + cmd) -// val cmdResourceId = cmd.resourceId -// if (cmd == MedtronicCommandType.GetHistoryData) { -// omnipod_pod_status.text = OmnipodUtil.frameNumber?.let { -// resourceHelper.gs(cmdResourceId, OmnipodUtil.pageNumber, OmnipodUtil.frameNumber) -// } -// ?: resourceHelper.gs(R.string.medtronic_cmd_desc_get_history_request, OmnipodUtil.pageNumber) -// } else { -// omnipod_pod_status.text = " " + (cmdResourceId?.let { resourceHelper.gs(it) } -// ?: cmd.getCommandDescription()) -// } -// } -// } -// else -> aapsLogger.warn(LTag.PUMP,"Unknown pump state: " + pumpStatus.pumpDeviceState) -// } - - val status = commandQueue.spannedStatus() - if (status.toString() == "") { - omnipod_queue.visibility = View.GONE - } else { - omnipod_queue.visibility = View.VISIBLE - omnipod_queue.text = status - } - } - - private fun checkStatusSet(object1: Any?, object2: Any?): Any? { - return if (object1 == null) { - object2 - } else { - if (object1 != object2) { - object2 - } else - object1 - } - } - - // GUI functions - fun updateGUI() { - val plugin = omnipodPumpPlugin - //val omnipodPumpStatus = OmnipodUtil.getPumpStatus() - var pumpType = omnipodPumpStatus.pumpType - - if (pumpType == null) { - aapsLogger.warn(LTag.PUMP, "PumpType was not set, reseting to Omnipod.") - pumpType = PumpType.Insulet_Omnipod; - } - - setDeviceStatus() - - if (omnipodPumpStatus.podAvailable) { - // last connection - if (omnipodPumpStatus.lastConnection != 0L) { - //val minAgo = DateUtil.minAgo(pumpStatus.lastConnection) - val min = (System.currentTimeMillis() - omnipodPumpStatus.lastConnection) / 1000 / 60 - if (omnipodPumpStatus.lastConnection + 60 * 1000 > System.currentTimeMillis()) { - omnipod_lastconnection.setText(R.string.combo_pump_connected_now) - //omnipod_lastconnection.setTextColor(Color.WHITE) - } else { //if (pumpStatus.lastConnection + 30 * 60 * 1000 < System.currentTimeMillis()) { - - if (min < 60) { - omnipod_lastconnection.text = resourceHelper.gs(R.string.minago, min) - } else if (min < 1440) { - val h = (min / 60).toInt() - omnipod_lastconnection.text = (resourceHelper.gq(R.plurals.objective_hours, h, h) + " " - + resourceHelper.gs(R.string.ago)) - } else { - val h = (min / 60).toInt() - val d = h / 24 - // h = h - (d * 24); - omnipod_lastconnection.text = (resourceHelper.gq(R.plurals.objective_days, d, d) + " " - + resourceHelper.gs(R.string.ago)) - } - //omnipod_lastconnection.setTextColor(Color.RED) - } -// } else { -// omnipod_lastconnection.text = minAgo -// //omnipod_lastconnection.setTextColor(Color.WHITE) -// } - } - - // last bolus - val bolus = omnipodPumpStatus.lastBolusAmount - val bolusTime = omnipodPumpStatus.lastBolusTime - if (bolus != null && bolusTime != null && omnipodPumpStatus.podAvailable) { - val agoMsc = System.currentTimeMillis() - omnipodPumpStatus.lastBolusTime.time - val bolusMinAgo = agoMsc.toDouble() / 60.0 / 1000.0 - val unit = resourceHelper.gs(R.string.insulin_unit_shortname) - val ago: String - if (agoMsc < 60 * 1000) { - ago = resourceHelper.gs(R.string.combo_pump_connected_now) - } else if (bolusMinAgo < 60) { - ago = DateUtil.minAgo(resourceHelper, omnipodPumpStatus.lastBolusTime.time) - } else { - ago = DateUtil.hourAgo(omnipodPumpStatus.lastBolusTime.time, resourceHelper) - } - omnipod_lastbolus.text = resourceHelper.gs(R.string.omnipod_last_bolus, pumpType.determineCorrectBolusSize(bolus), unit, ago) - } else { - omnipod_lastbolus.text = "" - } - - // base basal rate - omnipod_basabasalrate.text = resourceHelper.gs(R.string.pump_basebasalrate, pumpType.determineCorrectBasalSize(plugin.baseBasalRate)) - - omnipod_tempbasal.text = activePlugin.activeTreatments - .getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: "" - - // reservoir - if (Round.isSame(omnipodPumpStatus.reservoirRemainingUnits, 75.0)) { - omnipod_reservoir.text = resourceHelper.gs(R.string.omnipod_reservoir_over50) - } else { - omnipod_reservoir.text = resourceHelper.gs(R.string.omnipod_reservoir_left, omnipodPumpStatus.reservoirRemainingUnits) - } - warnColors.setColorInverse(omnipod_reservoir, omnipodPumpStatus.reservoirRemainingUnits, 50.0, 20.0) - - } else { - omnipod_basabasalrate.text = "" - omnipod_reservoir.text = "" - omnipod_tempbasal.text = "" - omnipod_lastbolus.text = "" - omnipod_lastconnection.text = "" - omnipod_lastconnection.setTextColor(Color.WHITE) - } - - omnipod_errors.text = omnipodPumpStatus.errorInfo - - updateAcknowledgeAlerts() - - omnipod_refresh.isEnabled = omnipodPumpStatus.podAvailable - - } - - private fun updateAcknowledgeAlerts() { - omnipod_pod_active_alerts_ack.isEnabled = omnipodPumpStatus.ackAlertsAvailable - omnipod_pod_active_alerts.text = omnipodPumpStatus.ackAlertsText - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/BolusProgressIndicationConsumer.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/BolusProgressIndicationConsumer.java deleted file mode 100644 index 35d07e3622..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/BolusProgressIndicationConsumer.java +++ /dev/null @@ -1,7 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.comm; - -// TODO replace with Consumer when our min API level >= 24 -@FunctionalInterface -public interface BolusProgressIndicationConsumer { - void accept(double estimatedUnitsDelivered, int percentage); -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/AssignAddressAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/AssignAddressAction.java deleted file mode 100644 index b5e46e38b5..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/AssignAddressAction.java +++ /dev/null @@ -1,54 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.comm.action; - -import org.joda.time.DateTimeZone; - -import java.util.Collections; - -import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalMessageAddressException; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalVersionResponseTypeException; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodMessage; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.AssignAddressCommand; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.VersionResponse; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSetupState; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateChangedHandler; -import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; - -public class AssignAddressAction implements OmnipodAction { - private final int address; - private final PodStateChangedHandler podStateChangedHandler; - - public AssignAddressAction(PodStateChangedHandler podStateChangedHandler, int address) { - this.address = address; - this.podStateChangedHandler = podStateChangedHandler; - } - - @Override - public PodSessionState execute(OmnipodCommunicationManager communicationService) { - PodSetupState setupState = new PodSetupState(address, 0x00, 0x00); - - AssignAddressCommand assignAddress = new AssignAddressCommand(setupState.getAddress()); - OmnipodMessage assignAddressMessage = new OmnipodMessage(OmnipodConst.DEFAULT_ADDRESS, - Collections.singletonList(assignAddress), setupState.getMessageNumber()); - - VersionResponse assignAddressResponse = communicationService.exchangeMessages(VersionResponse.class, setupState, assignAddressMessage, - OmnipodConst.DEFAULT_ADDRESS, setupState.getAddress()); - - if (!assignAddressResponse.isAssignAddressVersionResponse()) { - throw new IllegalVersionResponseTypeException("assignAddress", "setupPod"); - } - if (assignAddressResponse.getAddress() != address) { - throw new IllegalMessageAddressException(address, assignAddressResponse.getAddress()); - } - - DateTimeZone timeZone = DateTimeZone.getDefault(); - - PodSessionState podState = new PodSessionState(timeZone, address, assignAddressResponse.getPiVersion(), - assignAddressResponse.getPmVersion(), assignAddressResponse.getLot(), assignAddressResponse.getTid(), - setupState.getPacketNumber(), 0x00, communicationService.injector); // At this point, for an unknown reason, the pod starts counting messages from 0 again - - podState.setStateChangedHandler(podStateChangedHandler); - return podState; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/InsertCannulaAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/InsertCannulaAction.java deleted file mode 100644 index 9a433ab86a..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/InsertCannulaAction.java +++ /dev/null @@ -1,71 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.comm.action; - -import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.InsertCannulaService; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.ActionInitializationException; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; - -public class InsertCannulaAction implements OmnipodAction { - - private final PodSessionState podState; - private final InsertCannulaService service; - private final BasalSchedule initialBasalSchedule; - - public InsertCannulaAction(InsertCannulaService insertCannulaService, PodSessionState podState, BasalSchedule initialBasalSchedule) { - if (insertCannulaService == null) { - throw new ActionInitializationException("Insert cannula service cannot be null"); - } - if (podState == null) { - throw new ActionInitializationException("Pod state cannot be null"); - } - if (initialBasalSchedule == null) { - throw new ActionInitializationException("Initial basal schedule cannot be null"); - } - this.service = insertCannulaService; - this.podState = podState; - this.initialBasalSchedule = initialBasalSchedule; - } - - public static void updateCannulaInsertionStatus(PodSessionState podState, StatusResponse statusResponse, AAPSLogger aapsLogger) { - if (podState.getSetupProgress().equals(SetupProgress.CANNULA_INSERTING) && - statusResponse.getPodProgressStatus().isReadyForDelivery()) { - aapsLogger.debug(LTag.PUMPBTCOMM, "Updating SetupProgress from CANNULA_INSERTING to COMPLETED"); - podState.setSetupProgress(SetupProgress.COMPLETED); - } - } - - @Override - public StatusResponse execute(OmnipodCommunicationManager communicationService) { - if (podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) { - throw new IllegalSetupProgressException(SetupProgress.PRIMING_FINISHED, podState.getSetupProgress()); - } - - if (podState.getSetupProgress().isBefore(SetupProgress.INITIAL_BASAL_SCHEDULE_SET)) { - service.programInitialBasalSchedule(communicationService, podState, initialBasalSchedule); - podState.setSetupProgress(SetupProgress.INITIAL_BASAL_SCHEDULE_SET); - } - if (podState.getSetupProgress().isBefore(SetupProgress.STARTING_INSERT_CANNULA)) { - service.executeExpirationRemindersAlertCommand(communicationService, podState); - podState.setSetupProgress(SetupProgress.STARTING_INSERT_CANNULA); - } - - if (podState.getSetupProgress().isBefore(SetupProgress.CANNULA_INSERTING)) { - StatusResponse statusResponse = service.executeInsertionBolusCommand(communicationService, podState); - podState.setSetupProgress(SetupProgress.CANNULA_INSERTING); - return statusResponse; - } else if (podState.getSetupProgress().equals(SetupProgress.CANNULA_INSERTING)) { - // Check status - StatusResponse statusResponse = communicationService.executeAction(new GetStatusAction(podState)); - updateCannulaInsertionStatus(podState, statusResponse, communicationService.aapsLogger); - return statusResponse; - } else { - throw new IllegalSetupProgressException(null, podState.getSetupProgress()); - } - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/PrimeAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/PrimeAction.java deleted file mode 100644 index 380eb0ce3d..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/PrimeAction.java +++ /dev/null @@ -1,61 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.comm.action; - -import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.PrimeService; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.ActionInitializationException; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; - -public class PrimeAction implements OmnipodAction { - - private final PrimeService service; - private final PodSessionState podState; - - public PrimeAction(PrimeService primeService, PodSessionState podState) { - if (primeService == null) { - throw new ActionInitializationException("Prime service cannot be null"); - } - if (podState == null) { - throw new ActionInitializationException("Pod state cannot be null"); - } - this.service = primeService; - this.podState = podState; - } - - public static void updatePrimingStatus(PodSessionState podState, StatusResponse statusResponse, AAPSLogger aapsLogger) { - if (podState.getSetupProgress().equals(SetupProgress.PRIMING) && statusResponse.getPodProgressStatus().equals(PodProgressStatus.PRIMING_COMPLETED)) { - aapsLogger.debug(LTag.PUMPBTCOMM, "Updating SetupProgress from PRIMING to PRIMING_FINISHED"); - podState.setSetupProgress(SetupProgress.PRIMING_FINISHED); - } - } - - @Override - public StatusResponse execute(OmnipodCommunicationManager communicationService) { - if (podState.getSetupProgress().isBefore(SetupProgress.POD_CONFIGURED)) { - throw new IllegalSetupProgressException(SetupProgress.POD_CONFIGURED, podState.getSetupProgress()); - } - if (podState.getSetupProgress().isBefore(SetupProgress.STARTING_PRIME)) { - service.executeDisableTab5Sub16FaultConfigCommand(communicationService, podState); - service.executeFinishSetupReminderAlertCommand(communicationService, podState); - podState.setSetupProgress(SetupProgress.STARTING_PRIME); - } - - if (podState.getSetupProgress().isBefore(SetupProgress.PRIMING)) { - StatusResponse statusResponse = service.executePrimeBolusCommand(communicationService, podState); - podState.setSetupProgress(SetupProgress.PRIMING); - return statusResponse; - } else if (podState.getSetupProgress().equals(SetupProgress.PRIMING)) { - // Check status - StatusResponse statusResponse = communicationService.executeAction(new GetStatusAction(podState)); - updatePrimingStatus(podState, statusResponse, communicationService.aapsLogger); - return statusResponse; - } else { - throw new IllegalSetupProgressException(null, podState.getSetupProgress()); - } - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/SetupPodAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/SetupPodAction.java deleted file mode 100644 index 52979c91f3..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/SetupPodAction.java +++ /dev/null @@ -1,67 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.comm.action; - -import org.joda.time.DateTime; - -import java.util.Collections; - -import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalMessageAddressException; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPacketTypeException; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPodProgressException; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalVersionResponseTypeException; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodMessage; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.SetupPodCommand; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.VersionResponse; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.PacketType; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; -import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; - -public class SetupPodAction implements OmnipodAction { - private final PodSessionState podState; - - public SetupPodAction(PodSessionState podState) { - this.podState = podState; - } - - @Override - public VersionResponse execute(OmnipodCommunicationManager communicationService) { - if (!podState.getSetupProgress().equals(SetupProgress.ADDRESS_ASSIGNED)) { - throw new IllegalSetupProgressException(SetupProgress.ADDRESS_ASSIGNED, podState.getSetupProgress()); - } - DateTime activationDate = DateTime.now(podState.getTimeZone()); - - SetupPodCommand setupPodCommand = new SetupPodCommand(podState.getAddress(), activationDate, - podState.getLot(), podState.getTid()); - OmnipodMessage message = new OmnipodMessage(OmnipodConst.DEFAULT_ADDRESS, - Collections.singletonList(setupPodCommand), podState.getMessageNumber()); - VersionResponse setupPodResponse; - try { - setupPodResponse = communicationService.exchangeMessages(VersionResponse.class, podState, - message, OmnipodConst.DEFAULT_ADDRESS, podState.getAddress()); - } catch (IllegalPacketTypeException ex) { - if (PacketType.ACK.equals(ex.getActual())) { - // Pod is already configured - podState.setSetupProgress(SetupProgress.POD_CONFIGURED); - return null; - } - throw ex; - } - - if (!setupPodResponse.isSetupPodVersionResponse()) { - throw new IllegalVersionResponseTypeException("setupPod", "assignAddress"); - } - if (setupPodResponse.getAddress() != podState.getAddress()) { - throw new IllegalMessageAddressException(podState.getAddress(), setupPodResponse.getAddress()); - } - if (setupPodResponse.getPodProgressStatus() != PodProgressStatus.PAIRING_COMPLETED) { - throw new IllegalPodProgressException(PodProgressStatus.PAIRING_COMPLETED, setupPodResponse.getPodProgressStatus()); - } - - podState.setSetupProgress(SetupProgress.POD_CONFIGURED); - - return setupPodResponse; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/exception/IllegalSetupProgressException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/exception/IllegalSetupProgressException.java deleted file mode 100644 index 852d5ea3c2..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/exception/IllegalSetupProgressException.java +++ /dev/null @@ -1,26 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.comm.exception; - -import java.util.Locale; - -import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress; -import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException; - -public class IllegalSetupProgressException extends OmnipodException { - private final SetupProgress expected; - private final SetupProgress actual; - - public IllegalSetupProgressException(SetupProgress expected, SetupProgress actual) { - super(String.format(Locale.getDefault(), "Illegal setup progress: %s, expected: %s", actual, expected), true); - this.expected = expected; - this.actual = actual; - } - - public SetupProgress getExpected() { - return expected; - } - - public SetupProgress getActual() { - return actual; - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodPodType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodPodType.java deleted file mode 100644 index 849a22e5b0..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodPodType.java +++ /dev/null @@ -1,6 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.defs; - -public enum OmnipodPodType { - Eros, // - Dash -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/PodDeviceState.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/PodDeviceState.java deleted file mode 100644 index 2670f63295..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/PodDeviceState.java +++ /dev/null @@ -1,38 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.defs; - -import info.nightscout.androidaps.R; - -/** - * Created by andy on 4.8.2019 - */ -// TODO remove this class and use PumpDeviceState instead -public enum PodDeviceState { - - // FIXME - NeverContacted(R.string.medtronic_pump_status_never_contacted), // - Sleeping(R.string.medtronic_pump_status_sleeping), // - WakingUp(R.string.medtronic_pump_status_waking_up), // - Active(R.string.medtronic_pump_status_active), // - ErrorWhenCommunicating(R.string.medtronic_pump_status_error_comm), // - TimeoutWhenCommunicating(R.string.medtronic_pump_status_timeout_comm), // - // ProblemContacting(R.string.medtronic_pump_status_problem_contacting), // - PumpUnreachable(R.string.medtronic_pump_status_pump_unreachable), // - InvalidConfiguration(R.string.medtronic_pump_status_invalid_config); - - Integer resourceId = null; - - - PodDeviceState() { - - } - - - PodDeviceState(int resourceId) { - this.resourceId = resourceId; - } - - - public Integer getResourceId() { - return resourceId; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/SetupProgress.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/SetupProgress.java deleted file mode 100644 index 72a3b5438a..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/SetupProgress.java +++ /dev/null @@ -1,21 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.defs; - -public enum SetupProgress { - ADDRESS_ASSIGNED, - POD_CONFIGURED, - STARTING_PRIME, - PRIMING, - PRIMING_FINISHED, - INITIAL_BASAL_SCHEDULE_SET, - STARTING_INSERT_CANNULA, - CANNULA_INSERTING, - COMPLETED; - - public boolean isBefore(SetupProgress other) { - return this.ordinal() < other.ordinal(); - } - - public boolean isAfter(SetupProgress other) { - return this.ordinal() > other.ordinal(); - } -} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodSessionState.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodSessionState.java deleted file mode 100644 index 862976afbc..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodSessionState.java +++ /dev/null @@ -1,306 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.defs.state; - -import com.google.gson.Gson; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Duration; - -import java.util.HashMap; -import java.util.Map; - -import javax.inject.Inject; - -import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoFaultEvent; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSet; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSlot; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertType; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryStatus; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.FirmwareVersion; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.NonceState; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule; -import info.nightscout.androidaps.plugins.pump.omnipod.util.OmniCRC; -import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; -import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; -import info.nightscout.androidaps.utils.DateUtil; -import info.nightscout.androidaps.utils.sharedPreferences.SP; - - -public class PodSessionState extends PodState { - - @Inject transient AAPSLogger aapsLogger; - @Inject transient SP sp; - @Inject transient OmnipodUtil omnipodUtil; - @Inject transient DateUtil dateUtil; - - private transient PodStateChangedHandler stateChangedHandler; - - // TODO - // the problem you have with injection in this class is that you are mixing - // data storing and handlind. Move these member variables to extra class you can - // easy serialize and load it here by setData(dataInOtherClass) - private final Map configuredAlerts; - private DateTimeZone timeZone; - private DateTime activatedAt; - private DateTime expiresAt; - private final FirmwareVersion piVersion; - private final FirmwareVersion pmVersion; - private final int lot; - private final int tid; - private Double reservoirLevel; - private boolean suspended; - private NonceState nonceState; - private SetupProgress setupProgress; - private AlertSet activeAlerts; - private BasalSchedule basalSchedule; - private DeliveryStatus lastDeliveryStatus; - - public PodSessionState(DateTimeZone timeZone, int address, FirmwareVersion piVersion, - FirmwareVersion pmVersion, int lot, int tid, int packetNumber, int messageNumber, HasAndroidInjector injector) { - super(address, messageNumber, packetNumber); - injectDaggerClass(injector); - if (timeZone == null) { - throw new IllegalArgumentException("Time zone can not be null"); - } - - suspended = false; - configuredAlerts = new HashMap<>(); - configuredAlerts.put(AlertSlot.SLOT7, AlertType.FINISH_SETUP_REMINDER); - - this.timeZone = timeZone; - this.setupProgress = SetupProgress.ADDRESS_ASSIGNED; - this.piVersion = piVersion; - this.pmVersion = pmVersion; - this.lot = lot; - this.tid = tid; - this.nonceState = new NonceState(lot, tid); - handleUpdates(); - } - - @Deprecated - public void injectDaggerClass(HasAndroidInjector injector) { - injector.androidInjector().inject(this); - } - - @Deprecated - public void setStateChangedHandler(PodStateChangedHandler handler) { - // FIXME this is an ugly workaround for not being able to serialize the PodStateChangedHandler - if (stateChangedHandler != null) { - throw new IllegalStateException("A PodStateChangedHandler has already been already registered"); - } - stateChangedHandler = handler; - } - - public AlertType getConfiguredAlertType(AlertSlot alertSlot) { - return configuredAlerts.get(alertSlot); - } - - public void putConfiguredAlert(AlertSlot alertSlot, AlertType alertType) { - configuredAlerts.put(alertSlot, alertType); - handleUpdates(); - } - - public void removeConfiguredAlert(AlertSlot alertSlot) { - configuredAlerts.remove(alertSlot); - handleUpdates(); - } - - public DateTime getActivatedAt() { - return activatedAt == null ? null : activatedAt.withZone(timeZone); - } - - public DateTime getExpiresAt() { - return expiresAt == null ? null : expiresAt.withZone(timeZone); - } - - public String getExpiryDateAsString() { - return expiresAt == null ? "???" : dateUtil.dateAndTimeString(expiresAt.toDate()); - } - - public FirmwareVersion getPiVersion() { - return piVersion; - } - - public FirmwareVersion getPmVersion() { - return pmVersion; - } - - public int getLot() { - return lot; - } - - public int getTid() { - return tid; - } - - public Double getReservoirLevel() { - return reservoirLevel; - } - - public synchronized void resyncNonce(int syncWord, int sentNonce, int sequenceNumber) { - int sum = (sentNonce & 0xFFFF) - + OmniCRC.crc16lookup[sequenceNumber] - + (this.lot & 0xFFFF) - + (this.tid & 0xFFFF); - int seed = ((sum & 0xFFFF) ^ syncWord); - - this.nonceState = new NonceState(lot, tid, (byte) (seed & 0xFF)); - handleUpdates(); - } - - public int getCurrentNonce() { - return nonceState.getCurrentNonce(); - } - - public synchronized void advanceToNextNonce() { - nonceState.advanceToNextNonce(); - handleUpdates(); - } - - public SetupProgress getSetupProgress() { - return setupProgress; - } - - public synchronized void setSetupProgress(SetupProgress setupProgress) { - if (setupProgress == null) { - throw new IllegalArgumentException("Setup state cannot be null"); - } - this.setupProgress = setupProgress; - handleUpdates(); - } - - public boolean isSuspended() { - return suspended; - } - - public boolean hasActiveAlerts() { - return activeAlerts != null && activeAlerts.size() > 0; - } - - public AlertSet getActiveAlerts() { - return activeAlerts; - } - - public DateTimeZone getTimeZone() { - return timeZone; - } - - public void setTimeZone(DateTimeZone timeZone) { - if (timeZone == null) { - throw new IllegalArgumentException("Time zone can not be null"); - } - this.timeZone = timeZone; - handleUpdates(); - } - - public DateTime getTime() { - DateTime now = DateTime.now(); - return now.withZone(timeZone); - } - - public Duration getScheduleOffset() { - DateTime now = getTime(); - DateTime startOfDay = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), - 0, 0, 0, timeZone); - return new Duration(startOfDay, now); - } - - public boolean hasNonceState() { - return true; - } - - @Override - public void setPacketNumber(int packetNumber) { - super.setPacketNumber(packetNumber); - handleUpdates(); - } - - @Override - public void setMessageNumber(int messageNumber) { - super.setMessageNumber(messageNumber); - handleUpdates(); - } - - public BasalSchedule getBasalSchedule() { - return basalSchedule; - } - - public void setBasalSchedule(BasalSchedule basalSchedule) { - this.basalSchedule = basalSchedule; - handleUpdates(); - } - - public DeliveryStatus getLastDeliveryStatus() { - return lastDeliveryStatus; - } - - @Override - public void setFaultEvent(PodInfoFaultEvent faultEvent) { - super.setFaultEvent(faultEvent); - suspended = true; - handleUpdates(); - } - - @Override - public void updateFromStatusResponse(StatusResponse statusResponse) { - DateTime activatedAtCalculated = getTime().minus(statusResponse.getTimeActive()); - if (activatedAt == null) { - activatedAt = activatedAtCalculated; - } - DateTime expiresAtCalculated = activatedAtCalculated.plus(OmnipodConst.NOMINAL_POD_LIFE); - if (expiresAt == null || expiresAtCalculated.isBefore(expiresAt) || expiresAtCalculated.isAfter(expiresAt.plusMinutes(1))) { - expiresAt = expiresAtCalculated; - } - - boolean newSuspendedState = statusResponse.getDeliveryStatus() == DeliveryStatus.SUSPENDED; - if (suspended != newSuspendedState) { - aapsLogger.info(LTag.PUMPCOMM, "Updating pod suspended state in updateFromStatusResponse. newSuspendedState={}, statusResponse={}", newSuspendedState, statusResponse.toString()); - suspended = newSuspendedState; - } - activeAlerts = statusResponse.getAlerts(); - lastDeliveryStatus = statusResponse.getDeliveryStatus(); - reservoirLevel = statusResponse.getReservoirLevel(); - handleUpdates(); - } - - private void handleUpdates() { - Gson gson = omnipodUtil.getGsonInstance(); - String gsonValue = gson.toJson(this); - aapsLogger.info(LTag.PUMPCOMM, "PodSessionState-SP: Saved Session State to SharedPreferences: " + gsonValue); - sp.putString(OmnipodConst.Prefs.PodState, gsonValue); - if (stateChangedHandler != null) { - stateChangedHandler.handle(this); - } - } - - @Override - public String toString() { - return "PodSessionState{" + - "configuredAlerts=" + configuredAlerts + - ", stateChangedHandler=" + stateChangedHandler + - ", activatedAt=" + activatedAt + - ", expiresAt=" + expiresAt + - ", piVersion=" + piVersion + - ", pmVersion=" + pmVersion + - ", lot=" + lot + - ", tid=" + tid + - ", reservoirLevel=" + reservoirLevel + - ", suspended=" + suspended + - ", timeZone=" + timeZone + - ", nonceState=" + nonceState + - ", setupProgress=" + setupProgress + - ", activeAlerts=" + activeAlerts + - ", basalSchedule=" + basalSchedule + - ", lastDeliveryStatus=" + lastDeliveryStatus + - ", address=" + address + - ", packetNumber=" + packetNumber + - ", messageNumber=" + messageNumber + - ", faultEvent=" + faultEvent + - '}'; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodSetupState.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodSetupState.java deleted file mode 100644 index 26b5802258..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodSetupState.java +++ /dev/null @@ -1,43 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.defs.state; - -import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; - -public class PodSetupState extends PodState { - public PodSetupState(int address, int packetNumber, int messageNumber) { - super(address, packetNumber, messageNumber); - } - - @Override - public boolean hasNonceState() { - return false; - } - - @Override - public int getCurrentNonce() { - throw new UnsupportedOperationException("PodSetupState does not have a nonce state"); - } - - @Override - public void advanceToNextNonce() { - throw new UnsupportedOperationException("PodSetupState does not have a nonce state"); - } - - @Override - public void resyncNonce(int syncWord, int sentNonce, int sequenceNumber) { - throw new UnsupportedOperationException("PodSetupState does not have a nonce state"); - } - - @Override - public void updateFromStatusResponse(StatusResponse statusResponse) { - } - - @Override - public String toString() { - return "PodSetupState{" + - "address=" + address + - ", packetNumber=" + packetNumber + - ", messageNumber=" + messageNumber + - ", faultEvent=" + faultEvent + - '}'; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodState.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodState.java deleted file mode 100644 index c6987c879e..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodState.java +++ /dev/null @@ -1,68 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.defs.state; - -import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoFaultEvent; - -public abstract class PodState { - protected final int address; - protected int packetNumber; - protected int messageNumber; - - protected PodInfoFaultEvent faultEvent; - - public PodState(int address, int packetNumber, int messageNumber) { - this.address = address; - this.packetNumber = packetNumber; - this.messageNumber = messageNumber; - } - - public abstract boolean hasNonceState(); - - public abstract int getCurrentNonce(); - - public abstract void advanceToNextNonce(); - - public abstract void resyncNonce(int syncWord, int sentNonce, int sequenceNumber); - - public abstract void updateFromStatusResponse(StatusResponse statusResponse); - - public int getAddress() { - return address; - } - - public int getMessageNumber() { - return messageNumber; - } - - public void setMessageNumber(int messageNumber) { - this.messageNumber = messageNumber; - } - - public int getPacketNumber() { - return packetNumber; - } - - public void setPacketNumber(int packetNumber) { - this.packetNumber = packetNumber; - } - - public void increaseMessageNumber() { - setMessageNumber((messageNumber + 1) & 0b1111); - } - - public void increasePacketNumber() { - setPacketNumber((packetNumber + 1) & 0b11111); - } - - public boolean hasFaultEvent() { - return faultEvent != null; - } - - public PodInfoFaultEvent getFaultEvent() { - return faultEvent; - } - - public void setFaultEvent(PodInfoFaultEvent faultEvent) { - this.faultEvent = faultEvent; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodStateChangedHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodStateChangedHandler.java deleted file mode 100644 index 6e706131a2..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodStateChangedHandler.java +++ /dev/null @@ -1,6 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.defs.state; - -@FunctionalInterface -public interface PodStateChangedHandler { - void handle(PodSessionState podState); -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodDriverState.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodDriverState.java deleted file mode 100644 index c2910dab89..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodDriverState.java +++ /dev/null @@ -1,10 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.driver; - -public enum OmnipodDriverState { - - NotInitalized, // when we start - Initalized_NoPod, // driver is initalized, but there is no pod - Initalized_PodInitializing, // driver is initalized, pod is initalizing - Initalized_PodAttached, // driver is initalized, pod is there - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java deleted file mode 100644 index 7a6c025433..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java +++ /dev/null @@ -1,111 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Date; - -import info.nightscout.androidaps.data.DetailedBolusInfo; -import info.nightscout.androidaps.data.PumpEnactResult; -import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.plugins.bus.RxBusWrapper; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPumpPluginInterface; -import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; - -/** - * Created by andy on 4.8.2019 - */ - -public class OmnipodUIPostprocessor { - - - private static final Logger LOG = LoggerFactory.getLogger(LTag.PUMP.name()); - - private OmnipodPumpStatus pumpStatus; - private OmnipodPumpPluginInterface omnipodPumpPlugin; - private RxBusWrapper rxBus; - - - public OmnipodUIPostprocessor(OmnipodPumpPluginInterface plugin, OmnipodPumpStatus pumpStatus) { - this.pumpStatus = pumpStatus; - this.omnipodPumpPlugin = plugin; - this.rxBus = plugin.getRxBus(); - } - - - // this is mostly intended for command that return certain statuses (Remaining Insulin, ...), and - // where responses won't be directly used - public void postProcessData(OmnipodUITask uiTask) { - - switch (uiTask.commandType) { - - case SetBolus: { - if (uiTask.returnData != null) { - - PumpEnactResult result = uiTask.returnData; - - DetailedBolusInfo detailedBolusInfo = (DetailedBolusInfo) uiTask.getObjectFromParameters(0); - - if (result.success) { - boolean isSmb = detailedBolusInfo.isSMB; - - if (!isSmb) { - pumpStatus.lastBolusAmount = detailedBolusInfo.insulin; - pumpStatus.lastBolusTime = new Date(); - } - } - } - } - break; - - case CancelTemporaryBasal: { - pumpStatus.tempBasalStart = 0; - pumpStatus.tempBasalEnd = 0; - pumpStatus.tempBasalAmount = null; - pumpStatus.tempBasalLength = null; - } - break; - -// case PairAndPrimePod: { -// if (uiTask.returnData.success) { -// omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.PairAndPrime, false); -// omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.FillCanulaSetBasalProfile, true); -// } -// omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.DeactivatePod, true); -// } -// break; -// -// case FillCanulaAndSetBasalProfile: { -// if (uiTask.returnData.success) { -// omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.FillCanulaSetBasalProfile, false); -// } -// omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.DeactivatePod, true); -// } -// break; -// -// case DeactivatePod: -// case ResetPodStatus: { -// omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.PairAndPrime, true); -// omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.DeactivatePod, false); -// } -// break; - - - default: - if (isLogEnabled()) - LOG.trace("Post-processing not implemented for {}.", uiTask.commandType.name()); - - } - - - } - - - private boolean isLogEnabled() { - return true; //L.isEnabled(LTag.PUMP); - } - - public RxBusWrapper getRxBus() { - return this.rxBus; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodDeviceStatusChange.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodDeviceStatusChange.kt deleted file mode 100644 index b87dbdb08c..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodDeviceStatusChange.kt +++ /dev/null @@ -1,42 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.events - -import info.nightscout.androidaps.events.Event -import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState -import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState -import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState - -/** - * Created by andy on 4.8.2019 - */ -class EventOmnipodDeviceStatusChange : EventRileyLinkDeviceStatusChange { - - var podSessionState: PodSessionState? = null - var podDeviceState: PodDeviceState? = null - - @JvmOverloads - constructor(rileyLinkServiceState: RileyLinkServiceState?, rileyLinkError: RileyLinkError? = null) : super(rileyLinkServiceState, rileyLinkError) { - } - - constructor(podSessionState: PodSessionState?) { - this.podSessionState = podSessionState - } - - constructor(errorDescription: String?) { - this.errorDescription = errorDescription - } - - constructor(podDeviceState: PodDeviceState?, errorDescription: String?) { - this.podDeviceState = podDeviceState - this.errorDescription = errorDescription - } - - override fun toString(): String { - return ("EventOmnipodDeviceStatusChange [" // - + "rileyLinkServiceState=" + rileyLinkServiceState - + ", rileyLinkError=" + rileyLinkError // - + ", podSessionState=" + podSessionState // - + ", podDeviceState=" + podDeviceState + "]") - } -} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodUtil.java deleted file mode 100644 index c79aa9fdb6..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodUtil.java +++ /dev/null @@ -1,244 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.util; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializer; - -import org.apache.commons.lang3.StringUtils; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.format.ISODateTimeFormat; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.interfaces.ActivePluginProvider; -import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.plugins.bus.RxBusWrapper; -import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodManager; -import info.nightscout.androidaps.plugins.pump.omnipod.data.RLHistoryItemOmnipod; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPodType; - -import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; -import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState; -import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; -import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange; -import info.nightscout.androidaps.utils.resources.ResourceHelper; -import info.nightscout.androidaps.utils.sharedPreferences.SP; - -/** - * Created by andy on 4/8/19. - */ -@Singleton -public class OmnipodUtil { - - private final AAPSLogger aapsLogger; - private final RxBusWrapper rxBus; - private final RileyLinkUtil rileyLinkUtil; - private final OmnipodPumpStatus omnipodPumpStatus; - private final ActivePluginProvider activePlugins; - private final SP sp; - private final ResourceHelper resourceHelper; - private final HasAndroidInjector injector; - - private boolean lowLevelDebug = true; - private OmnipodCommandType currentCommand; - private Gson gsonInstance = createGson(); - //private static PodSessionState podSessionState; - //private static PodDeviceState podDeviceState; - private OmnipodPodType omnipodPodType; - private OmnipodDriverState driverState = OmnipodDriverState.NotInitalized; - - - @Inject - public OmnipodUtil( - AAPSLogger aapsLogger, - RxBusWrapper rxBus, - RileyLinkUtil rileyLinkUtil, - OmnipodPumpStatus omnipodPumpStatus, - SP sp, - ResourceHelper resourceHelper, - ActivePluginProvider activePlugins, - HasAndroidInjector injector - ) { - this.aapsLogger = aapsLogger; - this.rxBus = rxBus; - this.rileyLinkUtil = rileyLinkUtil; - this.omnipodPumpStatus = omnipodPumpStatus; - this.sp = sp; - this.resourceHelper = resourceHelper; - this.activePlugins = activePlugins; - this.injector = injector; - } - - - public boolean isLowLevelDebug() { - return lowLevelDebug; - } - - - public void setLowLevelDebug(boolean lowLevelDebug) { - this.lowLevelDebug = lowLevelDebug; - } - - - public OmnipodCommandType getCurrentCommand() { - return currentCommand; - } - - - public void setCurrentCommand(OmnipodCommandType currentCommand) { - this.currentCommand = currentCommand; - - if (currentCommand != null) - rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItemOmnipod(currentCommand)); - } - - - public OmnipodDriverState getDriverState() { - return driverState; - } - - - public void setDriverState(OmnipodDriverState state) { - if (driverState == state) - return; - - driverState = state; - omnipodPumpStatus.driverState = state; - - // TODO maybe remove -// if (OmnipodUtil.omnipodPumpStatus != null) { -// OmnipodUtil.omnipodPumpStatus.driverState = state; -// } -// -// if (OmnipodUtil.omnipodPumpPlugin != null) { -// OmnipodUtil.omnipodPumpPlugin.setDriverState(state); -// } - } - - - private Gson createGson() { - GsonBuilder gsonBuilder = new GsonBuilder() - .registerTypeAdapter(DateTime.class, (JsonSerializer) (dateTime, typeOfSrc, context) -> - new JsonPrimitive(ISODateTimeFormat.dateTime().print(dateTime))) - .registerTypeAdapter(DateTime.class, (JsonDeserializer) (json, typeOfT, context) -> - ISODateTimeFormat.dateTime().parseDateTime(json.getAsString())) - .registerTypeAdapter(DateTimeZone.class, (JsonSerializer) (timeZone, typeOfSrc, context) -> - new JsonPrimitive(timeZone.getID())) - .registerTypeAdapter(DateTimeZone.class, (JsonDeserializer) (json, typeOfT, context) -> - DateTimeZone.forID(json.getAsString())); - - return gsonBuilder.create(); - } - - - public void setPodSessionState(PodSessionState podSessionState) { - omnipodPumpStatus.podSessionState = podSessionState; - rxBus.send(new EventOmnipodDeviceStatusChange(podSessionState)); - } - - - public void setPodDeviceState(PodDeviceState podDeviceState) { - omnipodPumpStatus.podDeviceState = podDeviceState; - } - - - public void setOmnipodPodType(OmnipodPodType omnipodPodType) { - this.omnipodPodType = omnipodPodType; - } - - - public OmnipodPodType getOmnipodPodType() { - return this.omnipodPodType; - } - - - public PodDeviceState getPodDeviceState() { - return omnipodPumpStatus.podDeviceState; - } - - - public PodSessionState getPodSessionState() { - return omnipodPumpStatus.podSessionState; - } - - - public boolean isOmnipodEros() { - return this.activePlugins.getActivePump().model() == PumpType.Insulet_Omnipod; - } - - - public boolean isOmnipodDash() { - return this.activePlugins.getActivePump().model() == PumpType.Insulet_Omnipod_Dash; - } - - - public void setPumpType(PumpType pumpType_) { - omnipodPumpStatus.pumpType = pumpType_; - } - - public PumpType getPumpType() { - return omnipodPumpStatus.pumpType; - } - - - public Gson getGsonInstance() { - return this.gsonInstance; - } - - public Integer getNextPodAddress() { - if (sp.contains(OmnipodConst.Prefs.NextPodAddress)) { - int nextPodAddress = sp.getInt(OmnipodConst.Prefs.NextPodAddress, 0); - if (OmnipodManager.isValidAddress(nextPodAddress)) { - return nextPodAddress; - } - } - return null; - } - - public boolean hasNextPodAddress() { - return getNextPodAddress() != null; - } - - public void setNextPodAddress(int address) { - sp.putInt(OmnipodConst.Prefs.NextPodAddress, address); - } - - public void removeNextPodAddress() { - sp.remove(OmnipodConst.Prefs.NextPodAddress); - } - - public AAPSLogger getAapsLogger() { - return this.aapsLogger; - } - - public SP getSp() { - return this.sp; - } - - public PodSessionState loadSessionState() { - String podState = sp.getString(OmnipodConst.Prefs.PodState, ""); - - aapsLogger.info(LTag.PUMP, "PodSessionState-SP: loaded from SharedPreferences: " + podState); - - if (StringUtils.isNotEmpty(podState)) { - PodSessionState podSessionState = gsonInstance.fromJson(podState, PodSessionState.class); - podSessionState.injectDaggerClass(injector); - setPodSessionState(podSessionState); - - return podSessionState; - } - - return null; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/OmnipodDashPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/OmnipodDashPumpPlugin.java deleted file mode 100644 index 29e21e41ab..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/OmnipodDashPumpPlugin.java +++ /dev/null @@ -1,308 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod_dash; - -import android.content.Context; -import android.os.Bundle; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Arrays; -import java.util.List; - -import javax.inject.Inject; - -import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.BuildConfig; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.interfaces.ActivePluginProvider; -import info.nightscout.androidaps.interfaces.CommandQueueProvider; -import info.nightscout.androidaps.interfaces.PluginDescription; -import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.plugins.bus.RxBusWrapper; -import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; -import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState; -import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; -import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodFragment; -import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPumpPluginInterface; -import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged; -import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefreshButtonState; -import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService; -import info.nightscout.androidaps.plugins.pump.omnipod_dash.comm.OmnipodDashCommunicationManager; -import info.nightscout.androidaps.utils.DateUtil; -import info.nightscout.androidaps.utils.FabricPrivacy; -import info.nightscout.androidaps.utils.TimeChangeType; -import info.nightscout.androidaps.utils.resources.ResourceHelper; -import info.nightscout.androidaps.utils.sharedPreferences.SP; - -/** - * Created by andy on 23.04.18. - * - * @author Andy Rozman (andy.rozman@gmail.com) - */ -// FIXME this is just placeholder for now, but this should use most of OmnipodPumpPlugin implementation -public class OmnipodDashPumpPlugin extends OmnipodPumpPlugin implements OmnipodPumpPluginInterface { - - // TODO Dagger - //private static final Logger LOG = LoggerFactory.getLogger(L.PUMP); - - //private RileyLinkOmnipodService omnipodService; - //private OmnipodPumpStatus pumpStatusLocal = null; - - // variables for handling statuses and history - private boolean firstRun = true; - private boolean isRefresh = false; - private boolean isBasalProfileInvalid = false; - private boolean basalProfileChanged = false; - private boolean isInitialized = false; - - public static boolean isBusy = false; - //private List busyTimestamps = new ArrayList<>(); - //private boolean sentIdToFirebase = false; - //private boolean hasTimeDateOrTimeZoneChanged = false; - - private Profile currentProfile; - - //@Inject - public OmnipodDashPumpPlugin(HasAndroidInjector injector, - AAPSLogger aapsLogger, - RxBusWrapper rxBus, - Context context, - ResourceHelper resourceHelper, - ActivePluginProvider activePlugin, - SP sp, - CommandQueueProvider commandQueue, - FabricPrivacy fabricPrivacy, - DateUtil dateUtil - ) { - super(new PluginDescription() // - .mainType(PluginType.PUMP) // - .fragmentClass(OmnipodFragment.class.getName()) // - .pluginName(R.string.omnipod_dash_name) // - .shortName(R.string.omnipod_dash_name_short) // - .preferencesId(R.xml.pref_omnipod) // - .description(R.string.description_pump_omnipod_dash), // - PumpType.Insulet_Omnipod_Dash, - injector, aapsLogger, rxBus, context, resourceHelper, activePlugin, sp, commandQueue, fabricPrivacy, dateUtil - ); - - displayConnectionMessages = false; - - //OmnipodUtil.setOmnipodPodType(OmnipodPodType.Dash); - - if (omnipodCommunicationManager == null) { - omnipodCommunicationManager = OmnipodDashCommunicationManager.getInstance(); - } - - // DG omnipodUIComm = new OmnipodUIComm(omnipodCommunicationManager, this, this.omnipodPumpStatus); - - //OmnipodUtil.setPlugin(this); - - // FIXME -// serviceConnection = new ServiceConnection() { -// -// public void onServiceDisconnected(ComponentName name) { -// if (isLoggingEnabled()) -// aapsLogger.debug(LTag.PUMP, "RileyLinkOmnipodService is disconnected"); -// omnipodService = null; -// } -// -// public void onServiceConnected(ComponentName name, IBinder service) { -// if (isLoggingEnabled()) -// aapsLogger.debug(LTag.PUMP, "RileyLinkOmnipodService is connected"); -// RileyLinkOmnipodService.LocalBinder mLocalBinder = (RileyLinkOmnipodService.LocalBinder) service; -// omnipodService = mLocalBinder.getServiceInstance(); -// -// new Thread(() -> { -// -// for (int i = 0; i < 20; i++) { -// SystemClock.sleep(5000); -// -// if (OmnipodUtil.getPumpStatus() != null) { -// if (isLoggingEnabled()) -// aapsLogger.debug(LTag.PUMP, "Starting OmniPod-RileyLink service"); -// if (OmnipodUtil.getPumpStatus().setNotInPreInit()) { -// break; -// } -// } -// } -// }).start(); -// } -// }; - } - - private String getLogPrefix() { - return "OmnipodPlugin::"; - } - - - // FIXME - public Class getServiceClass() { - return RileyLinkOmnipodService.class; - } - - - @Override - public String deviceID() { - return "Omnipod Dash"; - } - - - // Pump Plugin - - private boolean isServiceSet() { - return true; //omnipodService != null; - } - - private boolean isServiceInitialized() { - return true; - } - - - @Override - public boolean isInitialized() { - if (displayConnectionMessages) - aapsLogger.debug(LTag.PUMP, getLogPrefix() + "isInitialized"); - return isServiceSet() && isInitialized; - } - - - @Override - public boolean isConnected() { - if (displayConnectionMessages) - aapsLogger.debug(LTag.PUMP, getLogPrefix() + "isConnected"); - return isServiceSet() && isServiceInitialized(); - } - - - @Override - public boolean isConnecting() { - if (displayConnectionMessages) - aapsLogger.debug(LTag.PUMP, getLogPrefix() + "isConnecting"); - return !isServiceSet() || !isServiceInitialized(); - } - - - @Override - public void getPumpStatus() { - - if (firstRun) { - initializePump(!isRefresh); - } - -// getPodPumpStatus(); -// -// if (firstRun) { -// initializePump(!isRefresh); -// } else { -// refreshAnyStatusThatNeedsToBeRefreshed(); -// } -// -// MainApp.bus().post(new EventMedtronicPumpValuesChanged()); - } - - - public void resetStatusState() { - firstRun = true; - isRefresh = true; - } - - - private void setRefreshButtonEnabled(boolean enabled) { - rxBus.send(new EventOmnipodRefreshButtonState(enabled)); - } - - - private void initializePump(boolean realInit) { - - aapsLogger.info(LTag.PUMP, getLogPrefix() + "initializePump - start"); - - if (omnipodCommunicationManager == null) { - omnipodCommunicationManager = OmnipodDashCommunicationManager.getInstance(); - } - -// setRefreshButtonEnabled(false); -// -// getPodPumpStatus(); -// -// if (isRefresh) { -// if (isPumpNotReachable()) { -// if (isLoggingEnabled()) -// LOG.error(getLogPrefix() + "initializePump::Pump unreachable."); -// MedtronicUtil.sendNotification(MedtronicNotificationType.PumpUnreachable); -// -// setRefreshButtonEnabled(true); -// -// return; -// } -// -// MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable); -// } -// -// this.pumpState = PumpDriverState.Connected; -// -// pumpStatusLocal.setLastCommunicationToNow(); -// setRefreshButtonEnabled(true); - - // TODO need to read status and BasalProfile if pod inited and pod status and set correct commands enabled - - if (!isRefresh) { - pumpState = PumpDriverState.Initialized; - } - - if (!sentIdToFirebase) { - Bundle params = new Bundle(); - params.putString("version", BuildConfig.VERSION); - //fabricPrivacy.logCustom().logEvent("OmnipodPumpInit", params); - - sentIdToFirebase = true; - } - - isInitialized = true; - // this.pumpState = PumpDriverState.Initialized; - - this.firstRun = false; - } - - - protected void triggerUIChange() { - rxBus.send(new EventOmnipodPumpValuesChanged()); - } - - - // OPERATIONS not supported by Pump or Plugin - - //private List customActions = null; - - - @Override - public List getCustomActions() { - - if (customActions == null) { - this.customActions = Arrays.asList( -// customActionPairAndPrime, // -// customActionFillCanullaSetBasalProfile, // -// customActionDeactivatePod, // -// customActionResetPod - ); - } - - return this.customActions; - } - - - @Override - public void timezoneOrDSTChanged(TimeChangeType timeChangeType) { - -// if (isLoggingEnabled()) -// LOG.warn(getLogPrefix() + "Time, Date and/or TimeZone changed. "); -// -// this.hasTimeDateOrTimeZoneChanged = true; - } - - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/comm/OmnipodDashCommunicationManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/comm/OmnipodDashCommunicationManager.java deleted file mode 100644 index 3247f02c8d..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/comm/OmnipodDashCommunicationManager.java +++ /dev/null @@ -1,124 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod_dash.comm; - -import android.content.Context; - -import info.nightscout.androidaps.data.DetailedBolusInfo; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.data.PumpEnactResult; -import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoRecentPulseLog; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; - -/** - * Created by andy on 4.8.2019 - */ -// TODO refactor to use dagger, just commented out errors -// TODO is this class used? remove if not -public class OmnipodDashCommunicationManager implements OmnipodCommunicationManagerInterface { - - // TODO Dagger - -// private static final Logger LOG = LoggerFactory.getLogger(L.PUMPCOMM); - - // i didn't find where you instantiate this - private static OmnipodDashCommunicationManager omnipodCommunicationManager; - private String errorMessage; - - - public OmnipodDashCommunicationManager(Context context, RFSpy rfspy) { - omnipodCommunicationManager = this; -// OmnipodUtil.getPumpStatus().previousConnection = SP.getLong( -// RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L); - } - - private PodSessionState getPodSessionState() { - return null; - } - - @Deprecated - public static OmnipodDashCommunicationManager getInstance() { - return omnipodCommunicationManager; - } - - //@Override - protected void configurePumpSpecificSettings() { - //pumpStatus = OmnipodUtil.getPumpStatus(); - } - - public String getErrorResponse() { - return this.errorMessage; - } - -// private boolean isLogEnabled() { -// return L.isEnabled(L.PUMPCOMM); -// } - - @Override - public PumpEnactResult initPod(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, Profile profile) { - return null; - } - - @Override - public PumpEnactResult getPodStatus() { - return null; - } - - @Override - public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) { - return null; - } - - @Override - public PumpEnactResult setBasalProfile(Profile profile) { - return null; - } - - @Override - public PumpEnactResult resetPodStatus() { - return null; - } - - @Override - public PumpEnactResult setBolus(DetailedBolusInfo detailedBolusInfo) { - return null; - } - - public PumpEnactResult setBolus(Double parameter, boolean isSmb) { - return null; - } - - @Override - public PumpEnactResult cancelBolus() { - return null; - } - - @Override - public PumpEnactResult setTemporaryBasal(TempBasalPair tbr) { - return null; - } - - @Override - public PumpEnactResult cancelTemporaryBasal() { - return null; - } - - @Override - public PumpEnactResult acknowledgeAlerts() { - return null; - } - - @Override - public PumpEnactResult setTime() { - return null; - } - - @Override - public PodInfoRecentPulseLog readPulseLog() { - return null; - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/driver/OmnipodDashPumpStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/driver/OmnipodDashPumpStatus.java deleted file mode 100644 index 617322af00..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/driver/OmnipodDashPumpStatus.java +++ /dev/null @@ -1,24 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod_dash.driver; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import info.nightscout.androidaps.plugins.bus.RxBusWrapper; -import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; -import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; -import info.nightscout.androidaps.utils.resources.ResourceHelper; -import info.nightscout.androidaps.utils.sharedPreferences.SP; - -@Singleton -public class OmnipodDashPumpStatus extends OmnipodPumpStatus { - - @Inject - public OmnipodDashPumpStatus(ResourceHelper resourceHelper, - SP sp, - RxBusWrapper rxBus, - RileyLinkUtil rileyLinkUtil) { - super(resourceHelper, sp, rxBus, rileyLinkUtil); - this.pumpType = PumpType.Insulet_Omnipod_Dash; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt index f5ac9d64ce..499fe8afa8 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt @@ -39,12 +39,12 @@ class LocalAlertUtils @Inject constructor( return T.mins(sp.getInt(resourceHelper.gs(R.string.key_missed_bg_readings_threshold), 30).toLong()).msecs() } - private fun pumpUnreachableThreshold(): Long { + fun pumpUnreachableThreshold(): Long { return T.mins(sp.getInt(resourceHelper.gs(R.string.key_pump_unreachable_threshold), 30).toLong()).msecs() } fun checkPumpUnreachableAlarm(lastConnection: Long, isStatusOutdated: Boolean, isDisconnected: Boolean) { - val alarmTimeoutExpired = lastConnection + pumpUnreachableThreshold() < System.currentTimeMillis() + val alarmTimeoutExpired = isAlarmTimeoutExpired(lastConnection, pumpUnreachableThreshold()) val nextAlarmOccurrenceReached = sp.getLong("nextPumpDisconnectedAlarm", 0L) < System.currentTimeMillis() if (config.APS && sp.getBoolean(resourceHelper.gs(R.string.key_enable_pump_unreachable_alert), true) && isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !isDisconnected) { @@ -60,6 +60,14 @@ class LocalAlertUtils @Inject constructor( if (!isStatusOutdated && !alarmTimeoutExpired) rxBus.send(EventDismissNotification(Notification.PUMP_UNREACHABLE)) } + private fun isAlarmTimeoutExpired(lastConnection: Long, unreachableThreshold: Long): Boolean { + if (activePlugin.activePump.pumpDescription.hasCustomUnreachableAlertCheck) { + return activePlugin.activePump.isUnreachableAlertTimeoutExceeded(unreachableThreshold) + } else { + return lastConnection + pumpUnreachableThreshold() < System.currentTimeMillis() + } + } + /*Presnoozes the alarms with 5 minutes if no snooze exists. * Call only at startup! */ diff --git a/app/src/main/res/layout/actions_fragment.xml b/app/src/main/res/layout/actions_fragment.xml index ebb517dcb7..427000813d 100644 --- a/app/src/main/res/layout/actions_fragment.xml +++ b/app/src/main/res/layout/actions_fragment.xml @@ -25,7 +25,7 @@ android:padding="10dip" app:columnCount="2"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Extended bolus delivery error Sight ago - enableSMB_always + enableSMB_always enableSMB_with_COB enableSMB_with_temptarget enableSMB_after_carbs @@ -915,18 +915,18 @@ Max daily safety multiplier Current basal safety multiplier n/a - virtualpump_type + virtualpump_type Virtual Pump Type Pump Definition Bolus: Step=%1$s\nExtended Bolus: [Step=%2$s, Duration=%3$smin-%4$sh]\nBasal: Step=%5$s\nTBR: %6$s (by %7$s), Duration=%8$smin-%9$sh\n%10$s Autobackfill BG Wizard Settings - wearwizard_bg - wearwizard_tt - wearwizard_trend - wearwizard_cob - wearwizard_bolusiob - wearwizard_basaliob + wearwizard_bg + wearwizard_tt + wearwizard_trend + wearwizard_cob + wearwizard_bolusiob + wearwizard_basaliob Calculations included in the Wizard result: Display Settings General Settings @@ -965,8 +965,8 @@ Poctech Receive BG values from Poctech app Receive BG values from Tomato app (MiaoMiao device) - high_temptarget_raises_sensitivity - low_temptarget_lowers_sensitivity + high_temptarget_raises_sensitivity + low_temptarget_lowers_sensitivity High temptarget raises sensitivity = 100]]> Low temptarget lowers sensitivity @@ -1243,9 +1243,6 @@ REMOVE Preconditions: - - - Change profile to Change profile to %1$s Last connection to pump @@ -1286,7 +1283,6 @@ Clear finished Clear started Do you want reset objective start? You may lose your progress. - Time and/or Timezone change on pump No pump selected Select units you want to display values in Upload local profile changes to NS @@ -1386,7 +1382,6 @@ Authorization failed Absolute insulin Master password is used for backup encryption and to override security in application. Remember it or store on a safe place. - Passwords don\'t match Current master password Status lights Copy settings from NS @@ -1399,161 +1394,6 @@ skin Skin - - - Never contacted - Waking up - Error with communication - Timeout on communication - Pump unreachable - Invalid configuration - Active - Sleeping - - - - - - Omnipod - POD - Pump integration for Omnipod, requires RileyLink (with at least 2.0 firmware) device. - - - pref_omnipod_beep_bolus_enabled - pref_omnipod_beep_basal_enabled - pref_omnipod_beep_smb_enabled - pref_omnipod_beep_tbr_enabled - pref_omnipod_pod_debugging_options_enabled - pref_omnipod_timechange_enabled - Bolus Beep Enabled - Basal Beep Enabled - SMB Beep Enabled - TBR Beep Enabled - Pod Debugging Options Enabled - DST/Timezone Detection Enabled - - - Pod Mgmt - Pod Status - %1$.2f U left - Over 50 U - Pod Address - Pod Expires - No info - No Pod connected - Not initialized - Active Pod Alerts - Ack Alerts - %1$.2f %2$s (%3$s) - - - Omnipod (433.91 MHz) - - - - Operation is not possible.\n\nYou need to configure Omnipod first, before you can use this operation. - Operation is not possible.\n\n You need to wait few minutes, until AAPS tries to set profile for first time. - Illegal PodInitActionType: %1$s - No active pod. - - Command verification failed. - An unexpected error occurred. Please report! (type: %1$s). - Communication failed: received invalid input parameters. - Communication failed: timeout. - Communication failed: an unexpected error occurred. Please report! - Communication failed: message integrity verification failed. - Communication failed: received an invalid packet from the Pod. - Communication failed: the Pod is in a wrong state. - Communication failed: received an invalid response from the Pod. - Communication failed: received a message with an invalid sequence number from the Pod. - Communication failed: received a message with an invalid address from the Pod. - Communication failed: failed to decode message from the Pod. - Communication failed: nonce resync failed. - Communication failed: nonce out of sync. - Communication failed: not enough data received from the Pod. - A Pod fault (%1$03d %2$s) has been detected. Please deactivate your Pod and start a new one. - Communication failed: the Pod returned an error response. - - - Pod Management - Init Pod - Deactivate Pod - Reset Pod - Pod History - - Set Bolus - Cancel Bolus - Set Temporary Basal - Cancel Temporary Basal (Internally by driver) - Cancel Temporary Basal (Forced by user) - Set Basal Schedule - Get Pod Status - Get Pod Info - Set Time - Configure Alerts - Acknowledge Alerts - Suspend Delivery - Resume Delivery - Unknown Entry - - %1$.1f U - %1$.1f U, CH=%2$.1f g - Rate: %1$.1f U, Duration: %2$d min - - If you press OK, the Pod state will be forcibly reset and you will not be able to communicate with the Pod anymore. Do this only if you can not communicate with the Pod anymore. If you can still communicate with the Pod, please use the Deactivate Pod option. - Pod History not available at the moment. - - Omnipod - Omnipod - Omnipod - - - Fill the Pod - \nFill the new Pod with enough insulin for 3 days.\n\nListen for two beeps from the Pod during the filling process. These indicate that the minimum amount of 85U has been inserted. Be sure to completely empty the fill syringe, even after hearing the two beeps.\n\nAfter filling the Pod, please press Next.\n\nNote: do not remove the Pod\'s needle cap at this time. - Priming - Trying to pair with the new Pod and prime it.\n\nWhen all items are checked, you can press Next.\n\nNote: please keep the Pod very close to the RileyLink at this time. - Attach the Pod - \nPrepare the infusion site. Remove the Pod\'s needle cap and adhesive backing and attach the Pod to the infusion site.\n\nIf the cannula sticks out, please press Cancel and discard your Pod.\n\nPress Next to insert the cannula and begin basal delivery. - Inserting cannula - Trying to set initial basal schedule and insert the cannula.\n\nWhen all items are checked, you can press Next. - - Pod Info - \nThe Pod is now active.\n\nYour basal schedule has been programmed and the cannula has been inserted.\n\nPlease verify that the cannula has been inserted correctly and replace your Pod if you feel hasn\'t. - - Deactivate Pod - \nPress Next to deactivate the Pod.\n\nNote: This will suspend all insulin delivery and deactivate the Pod. - Deactivating the Pod - Deactivating the Pod.\n\nWhen all items are checked, you can press Next.\n\nNote: If deactivating continuously fails, please press Cancel and use the Reset Pod option to forcibly reset the Pod state. - - Pod deactivated.\n\nPlease remove the Pod from your body and discard it. - - Pair Pod - Prime Pod - Fill Cannula - Set Basal Profile - Cancel Delivery - Deactivate Pod - - - - - - Omnipod Dash - DASH - Pump integration for Omnipod Dash. - Finish pairing reminder - Finish setup reminder - Pod will expire soon - Pod will expire soon - Shutdown is imminent - Low reservoir - Unknown alert - Setting basal profile might have failed. Delivery might be suspended! Please refresh Pod status. - Setting temp basal might have failed. If there was a temp basal already running, that may have been cancelled! Please refresh pod status. - Setting time might have failed. Delivery might be suspended! Please refresh Pod status. - Unable to verify whether the bolus succeeded. Please verify that your Pod is bolusing or cancel the bolus. - RL Stats - Pulse Log Compare profiles Profile helper Default profile diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 29f4ef5bc7..7425a772b4 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -52,36 +52,5 @@ #ff0000 - - - - - - + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_omnipod.xml b/omnipod/src/main/res/xml/pref_omnipod.xml similarity index 100% rename from app/src/main/res/xml/pref_omnipod.xml rename to omnipod/src/main/res/xml/pref_omnipod.xml diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AcknowledgeAlertsCommandTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AcknowledgeAlertsCommandTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AcknowledgeAlertsCommandTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AcknowledgeAlertsCommandTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AssignAddressCommandTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AssignAddressCommandTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AssignAddressCommandTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AssignAddressCommandTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BasalScheduleExtraCommandTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BasalScheduleExtraCommandTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BasalScheduleExtraCommandTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BasalScheduleExtraCommandTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommandTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommandTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommandTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommandTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BolusExtraCommandTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BolusExtraCommandTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BolusExtraCommandTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BolusExtraCommandTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/CancelDeliveryCommandTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/CancelDeliveryCommandTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/CancelDeliveryCommandTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/CancelDeliveryCommandTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigureAlertsCommandTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigureAlertsCommandTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigureAlertsCommandTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigureAlertsCommandTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/DeactivatePodCommandTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/DeactivatePodCommandTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/DeactivatePodCommandTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/DeactivatePodCommandTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/FaultConfigCommandTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/FaultConfigCommandTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/FaultConfigCommandTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/FaultConfigCommandTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/GetStatusCommandTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/GetStatusCommandTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/GetStatusCommandTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/GetStatusCommandTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/SetInsulinScheduleCommandTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/SetInsulinScheduleCommandTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/SetInsulinScheduleCommandTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/SetInsulinScheduleCommandTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/SetupPodCommandTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/SetupPodCommandTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/SetupPodCommandTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/SetupPodCommandTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/TempBasalExtraCommandTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/TempBasalExtraCommandTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/TempBasalExtraCommandTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/TempBasalExtraCommandTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/defs/schedule/BasalTableEntryTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/defs/schedule/BasalTableEntryTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/defs/schedule/BasalTableEntryTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/defs/schedule/BasalTableEntryTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/ErrorResponseTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/ErrorResponseTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/ErrorResponseTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/ErrorResponseTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponseTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponseTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponseTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponseTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/VersionResponseTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/VersionResponseTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/VersionResponseTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/VersionResponseTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoActiveAlertsTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoActiveAlertsTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoActiveAlertsTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoActiveAlertsTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoDataLogTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoDataLogTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoDataLogTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoDataLogTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultAndInitializationTimeTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultAndInitializationTimeTest.java similarity index 77% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultAndInitializationTimeTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultAndInitializationTimeTest.java index a7baff4f06..2998dc4f83 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultAndInitializationTimeTest.java +++ b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultAndInitializationTimeTest.java @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.po import org.joda.time.DateTime; import org.joda.time.Duration; +import org.junit.Assert; import org.junit.Test; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; @@ -19,10 +20,10 @@ public class PodInfoFaultAndInitializationTimeTest { assertTrue(Duration.standardMinutes(1).isEqual(podInfoFaultAndInitializationTime.getTimeFaultEvent())); DateTime dateTime = podInfoFaultAndInitializationTime.getInitializationTime(); - assertEquals(2018, dateTime.getYear()); - assertEquals(9, dateTime.getMonthOfYear()); - assertEquals(25, dateTime.getDayOfMonth()); - assertEquals(23, dateTime.getHourOfDay()); - assertEquals(14, dateTime.getMinuteOfHour()); + Assert.assertEquals(2018, dateTime.getYear()); + Assert.assertEquals(9, dateTime.getMonthOfYear()); + Assert.assertEquals(25, dateTime.getDayOfMonth()); + Assert.assertEquals(23, dateTime.getHourOfDay()); + Assert.assertEquals(14, dateTime.getMinuteOfHour()); } } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultEventTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultEventTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultEventTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultEventTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoOlderPulseLogTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoOlderPulseLogTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoOlderPulseLogTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoOlderPulseLogTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoRecentPulseLogTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoRecentPulseLogTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoRecentPulseLogTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoRecentPulseLogTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoResponseTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoResponseTest.java similarity index 100% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoResponseTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoResponseTest.java diff --git a/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/AapsPodStateManagerTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/AapsPodStateManagerTest.java new file mode 100644 index 0000000000..6c9e2b520c --- /dev/null +++ b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/AapsPodStateManagerTest.java @@ -0,0 +1,99 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.defs.state; + +import org.joda.time.DateTime; +import org.joda.time.DateTimeUtils; +import org.joda.time.DateTimeZone; +import org.joda.time.Duration; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; + +import info.nightscout.androidaps.logging.AAPSLogger; +import info.nightscout.androidaps.plugins.bus.RxBusWrapper; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.FirmwareVersion; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsPodStateManager; +import info.nightscout.androidaps.utils.sharedPreferences.SP; + +import static org.junit.Assert.assertEquals; + +@RunWith(PowerMockRunner.class) +public class AapsPodStateManagerTest { + @Mock AAPSLogger aapsLogger; + @Mock SP sp; + @Mock OmnipodPumpStatus omnipodPumpStatus; + RxBusWrapper rxBus = new RxBusWrapper(); + + @Test + public void times() { + DateTimeZone timeZone = DateTimeZone.UTC; + DateTimeZone.setDefault(timeZone); + + DateTime now = new DateTime(2020, 1, 1, 1, 2, 3, timeZone); + + DateTimeUtils.setCurrentMillisFixed(now.getMillis()); + + AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus); + podStateManager.initState(0x0); + podStateManager.setInitializationParameters(0, 0, new FirmwareVersion(1, 1, 1), + new FirmwareVersion(2, 2, 2), timeZone, PodProgressStatus.ABOVE_FIFTY_UNITS); + + assertEquals(now, podStateManager.getTime()); + assertEquals(Duration.standardHours(1).plus(Duration.standardMinutes(2).plus(Duration.standardSeconds(3))), podStateManager.getScheduleOffset()); + } + + @Test + public void changeSystemTimeZoneWithoutChangingPodTimeZone() { + DateTimeZone timeZone = DateTimeZone.UTC; + DateTimeZone.setDefault(timeZone); + + DateTime now = new DateTime(2020, 1, 1, 1, 2, 3, timeZone); + + DateTimeUtils.setCurrentMillisFixed(now.getMillis()); + + AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus); + podStateManager.initState(0x0); + podStateManager.setInitializationParameters(0, 0, new FirmwareVersion(1, 1, 1), + new FirmwareVersion(2, 2, 2), timeZone, PodProgressStatus.ABOVE_FIFTY_UNITS); + + DateTimeZone newTimeZone = DateTimeZone.forOffsetHours(2); + DateTimeZone.setDefault(newTimeZone); + + // The system time zone has been updated, but the pod session state's time zone hasn't + // So the pods time should not have been changed + assertEquals(now, podStateManager.getTime()); + assertEquals(Duration.standardHours(1).plus(Duration.standardMinutes(2).plus(Duration.standardSeconds(3))), podStateManager.getScheduleOffset()); + } + + @Test + public void changeSystemTimeZoneAndChangePodTimeZone() { + DateTimeZone timeZone = DateTimeZone.UTC; + DateTimeZone.setDefault(timeZone); + + DateTime now = new DateTime(2020, 1, 1, 1, 2, 3, timeZone); + + DateTimeUtils.setCurrentMillisFixed(now.getMillis()); + + AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus); + podStateManager.initState(0x0); + podStateManager.setInitializationParameters(0, 0, new FirmwareVersion(1, 1, 1), + new FirmwareVersion(2, 2, 2), timeZone, PodProgressStatus.ABOVE_FIFTY_UNITS); + + DateTimeZone newTimeZone = DateTimeZone.forOffsetHours(2); + DateTimeZone.setDefault(newTimeZone); + podStateManager.setTimeZone(newTimeZone); + + // Both the system time zone have been updated + // So the pods time should have been changed (to +2 hours) + assertEquals(now.withZone(newTimeZone), podStateManager.getTime()); + assertEquals(Duration.standardHours(3).plus(Duration.standardMinutes(2).plus(Duration.standardSeconds(3))), podStateManager.getScheduleOffset()); + } + + @After + public void tearDown() { + DateTimeUtils.setCurrentMillisSystem(); + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManagerTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManagerTest.java similarity index 89% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManagerTest.java rename to omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManagerTest.java index 5def4c92d4..dec4ca9f03 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManagerTest.java +++ b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManagerTest.java @@ -4,6 +4,7 @@ import org.joda.time.Duration; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.powermock.api.mockito.PowerMockito; import java.util.List; @@ -13,7 +14,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedu import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; public class AapsOmnipodManagerTest { @Rule @@ -35,7 +35,7 @@ public class AapsOmnipodManagerTest { value3.timeAsSeconds = 50400; value3.value = 3.05D; - when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[]{ + PowerMockito.when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[]{ value1, value2, value3 @@ -79,7 +79,7 @@ public class AapsOmnipodManagerTest { thrown.expectMessage("Entries can not be empty"); Profile profile = mock(Profile.class); - when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[0]); + PowerMockito.when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[0]); AapsOmnipodManager.mapProfileToBasalSchedule(profile); } @@ -95,7 +95,7 @@ public class AapsOmnipodManagerTest { value.timeAsSeconds = 1800; value.value = 0.5D; - when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[]{ + PowerMockito.when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[]{ value, }); @@ -117,7 +117,7 @@ public class AapsOmnipodManagerTest { value2.timeAsSeconds = 86400; value2.value = 0.5D; - when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[]{ + PowerMockito.when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[]{ value1, value2 }); @@ -136,7 +136,7 @@ public class AapsOmnipodManagerTest { value.timeAsSeconds = -1; value.value = 0.5D; - when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[]{ + PowerMockito.when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[]{ value, }); @@ -151,7 +151,7 @@ public class AapsOmnipodManagerTest { value.timeAsSeconds = 0; value.value = 0.04D; - when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[]{ + PowerMockito.when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[]{ value, }); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java index 78db788350..4f4d13e287 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java @@ -24,7 +24,6 @@ import android.widget.Toast; import androidx.appcompat.widget.Toolbar; - import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; @@ -35,16 +34,12 @@ import java.util.Map; import javax.inject.Inject; - import info.nightscout.androidaps.activities.NoSplashAppCompatActivity; import info.nightscout.androidaps.interfaces.ActivePluginProvider; -import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; -import info.nightscout.androidaps.plugins.common.ManufacturerType; import info.nightscout.androidaps.plugins.pump.common.R; import info.nightscout.androidaps.plugins.pump.common.ble.BlePreCheck; -import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.GattAttributes; @@ -110,24 +105,9 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity { sp.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress); - PumpInterface activePump = activePlugin.getActivePump(); - - if (activePump.manufacturer() == ManufacturerType.Medtronic) { - RileyLinkPumpDevice rileyLinkPump = (RileyLinkPumpDevice) activePump; - rileyLinkPump.getRileyLinkService().verifyConfiguration(); // force reloading of address - - rileyLinkPump.triggerPumpConfigurationChangedEvent(); - - } else if (activePlugin.getActivePump().manufacturer() == ManufacturerType.Insulet) { - if (activePump.model() == PumpType.Insulet_Omnipod_Dash) { - aapsLogger.error("Omnipod Dash not yet implemented."); - } else { - RileyLinkPumpDevice rileyLinkPump = (RileyLinkPumpDevice) activePump; - rileyLinkPump.getRileyLinkService().verifyConfiguration(); // force reloading of address - - rileyLinkPump.triggerPumpConfigurationChangedEvent(); - } - } + RileyLinkPumpDevice rileyLinkPump = (RileyLinkPumpDevice) activePlugin.getActivePump(); + rileyLinkPump.getRileyLinkService().verifyConfiguration(); // force reloading of address + rileyLinkPump.triggerPumpConfigurationChangedEvent(); finish(); }); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java index b8395241e2..3d7acfc167 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java @@ -3,9 +3,9 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink; import javax.inject.Inject; import dagger.android.HasAndroidInjector; +import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus; import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkCommunicationException; @@ -17,6 +17,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.Radi import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioResponse; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RLMessageType; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkBLEError; +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask; @@ -35,29 +36,20 @@ public abstract class RileyLinkCommunicationManager { @Inject protected SP sp; @Inject protected RileyLinkServiceData rileyLinkServiceData; @Inject protected ServiceTaskExecutor serviceTaskExecutor; - + @Inject protected RFSpy rfspy; + @Inject protected HasAndroidInjector injector; + @Inject protected ActivePluginProvider activePluginProvider; private final int SCAN_TIMEOUT = 1500; private final int ALLOWED_PUMP_UNREACHABLE = 10 * 60 * 1000; // 10 minutes - public final HasAndroidInjector injector; - protected final RFSpy rfspy; protected int receiverDeviceAwakeForMinutes = 1; // override this in constructor of specific implementation protected String receiverDeviceID; // String representation of receiver device (ex. Pump (xxxxxx) or Pod (yyyyyy)) protected long lastGoodReceiverCommunicationTime = 0; - // protected PumpStatus pumpStatus; private long nextWakeUpRequired = 0L; - private int timeoutCount = 0; - public RileyLinkCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) { - this.injector = injector; - injector.androidInjector().inject(this); - this.rfspy = rfspy; - } - - // All pump communications go through this function. protected RLMessage sendAndListen(RLMessage msg, int timeout_ms) throws RileyLinkCommunicationException { @@ -98,10 +90,10 @@ public abstract class RileyLinkCommunicationManager { rfSpyResponse.wasTimeout(), rfSpyResponse.isUnknownCommand(), rfSpyResponse.isInvalidParam()); if (rfSpyResponse.wasTimeout()) { - if (hasTunning()) { + if (rileyLinkServiceData.targetDevice.isTuneUpEnabled()) { timeoutCount++; - long diff = System.currentTimeMillis() - getPumpStatus().lastConnection; + long diff = System.currentTimeMillis() - getPumpDevice().getLastConnectionTimeMillis(); if (diff > ALLOWED_PUMP_UNREACHABLE) { aapsLogger.warn(LTag.PUMPCOMM, "We reached max time that Pump can be unreachable. Starting Tuning."); @@ -139,10 +131,6 @@ public abstract class RileyLinkCommunicationManager { return rfspy != null ? rfspy.notConnectedCount : 0; } - public boolean hasTunning() { - return true; - } - // FIXME change wakeup // TODO we might need to fix this. Maybe make pump awake for shorter time (battery factor for pump) - Andy @@ -413,7 +401,8 @@ public abstract class RileyLinkCommunicationManager { lastGoodReceiverCommunicationTime = System.currentTimeMillis(); sp.putLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, lastGoodReceiverCommunicationTime); - getPumpStatus().setLastCommunicationToNow(); + + getPumpDevice().setLastCommunicationToNow(); } @@ -434,7 +423,9 @@ public abstract class RileyLinkCommunicationManager { } } - public abstract PumpStatus getPumpStatus(); + private RileyLinkPumpDevice getPumpDevice() { + return (RileyLinkPumpDevice) activePluginProvider.getActivePump(); + } public abstract boolean isDeviceReachable(); } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkUtil.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkUtil.java index ff524b2ed2..18e07f1e72 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkUtil.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkUtil.java @@ -38,9 +38,6 @@ public class RileyLinkUtil { private RileyLinkEncodingType encoding; private Encoding4b6b encoding4b6b; - // TODO maybe not needed - private RileyLinkTargetFrequency rileyLinkTargetFrequency; - @Inject public RileyLinkUtil() { } @@ -158,8 +155,4 @@ public class RileyLinkUtil { public Encoding4b6b getEncoding4b6b() { return encoding4b6b; } - - public void setRileyLinkTargetFrequency(RileyLinkTargetFrequency rileyLinkTargetFrequency_) { - this.rileyLinkTargetFrequency = rileyLinkTargetFrequency_; - } } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java index a74a14e4a6..128152aa31 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java @@ -5,6 +5,7 @@ import android.os.SystemClock; import java.util.UUID; import javax.inject.Inject; +import javax.inject.Singleton; import dagger.android.HasAndroidInjector; @@ -40,6 +41,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP; /** * Created by geoff on 5/26/16. */ +@Singleton public class RFSpy { @Inject AAPSLogger aapsLogger; @@ -58,16 +60,21 @@ public class RFSpy { private UUID radioServiceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO); private UUID radioDataUUID = UUID.fromString(GattAttributes.CHARA_RADIO_DATA); private UUID radioVersionUUID = UUID.fromString(GattAttributes.CHARA_RADIO_VERSION); - private UUID responseCountUUID = UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT); + //private UUID responseCountUUID = UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT); private RileyLinkFirmwareVersion firmwareVersion; private String bleVersion; // We don't use it so no need of sofisticated logic private Double currentFrequencyMHz; + @Inject public RFSpy(HasAndroidInjector injector, RileyLinkBLE rileyLinkBle) { - injector.androidInjector().inject(this); this.injector = injector; this.rileyLinkBle = rileyLinkBle; + } + + @Inject + public void onInit() { + aapsLogger.debug("RileyLinkServiceData:" + rileyLinkServiceData); reader = new RFSpyReader(aapsLogger, rileyLinkBle); } @@ -301,6 +308,7 @@ public class RFSpy { private void configureRadioForRegion(RileyLinkTargetFrequency frequency) { // we update registers only on first run, or if region changed + aapsLogger.error(LTag.PUMPBTCOMM, "RileyLinkTargetFrequency: " + frequency); switch (frequency) { case Medtronic_WorldWide: { @@ -423,14 +431,7 @@ public class RFSpy { } - public RFSpyResponse resetRileyLink() { - RFSpyResponse resp = null; - try { - resp = writeToData(new Reset(), EXPECTED_MAX_BLUETOOTH_LATENCY_MS); - aapsLogger.debug(LTag.PUMPBTCOMM, "Reset command send, response: {}", resp); - } catch (Exception e) { - e.toString(); - } - return resp; + public void stopReader() { + reader.stop(); } } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpyReader.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpyReader.java index 5a3d459154..99836d9021 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpyReader.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpyReader.java @@ -29,11 +29,13 @@ public class RFSpyReader { private int acquireCount = 0; private int releaseCount = 0; private boolean stopAtNull = true; + private static boolean isRunning = false; RFSpyReader(AAPSLogger aapsLogger, RileyLinkBLE rileyLinkBle) { - this.rileyLinkBle = rileyLinkBle; this.aapsLogger = aapsLogger; + // xyz setRileyLinkBle(rileyLinkBle); + this.rileyLinkBle = rileyLinkBle; } @@ -45,6 +47,7 @@ public class RFSpyReader { } void setRileyLinkEncodingType(RileyLinkEncodingType encodingType) { + aapsLogger.debug("setRileyLinkEncodingType: " + encodingType); stopAtNull = !(encodingType == RileyLinkEncodingType.Manchester || // encodingType == RileyLinkEncodingType.FourByteSixByteRileyLink); } @@ -87,6 +90,8 @@ public class RFSpyReader { public void start() { + isRunning = true; + readerTask = new AsyncTask() { @Override @@ -94,7 +99,7 @@ public class RFSpyReader { UUID serviceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO); UUID radioDataUUID = UUID.fromString(GattAttributes.CHARA_RADIO_DATA); BLECommOperationResult result; - while (true) { + while (isRunning) { try { acquireCount++; waitForRadioData.acquire(); @@ -129,7 +134,13 @@ public class RFSpyReader { aapsLogger.error(LTag.PUMPBTCOMM, "Interrupted while waiting for data"); } } + return null; } }.execute(); } + + public void stop() { + isRunning = false; + } + } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java index bf71a19fe5..6c90c62e24 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java @@ -18,8 +18,8 @@ import java.util.UUID; import java.util.concurrent.Semaphore; import javax.inject.Inject; +import javax.inject.Singleton; -import dagger.android.HasAndroidInjector; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; @@ -40,6 +40,7 @@ import info.nightscout.androidaps.plugins.pump.common.utils.ThreadUtil; * Created by geoff on 5/26/16. * Added: State handling, configuration of RF for different configuration ranges, connection handling */ +@Singleton public class RileyLinkBLE { @Inject AAPSLogger aapsLogger; @@ -58,13 +59,11 @@ public class RileyLinkBLE { private Runnable radioResponseCountNotified; private boolean mIsConnected = false; - - public RileyLinkBLE(HasAndroidInjector injector, final Context context) { - injector.androidInjector().inject(this); + @Inject + public RileyLinkBLE(final Context context) { this.context = context; this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); - aapsLogger.debug(LTag.PUMPBTCOMM, "BT Adapter: " + this.bluetoothAdapter); bluetoothGattCallback = new BluetoothGattCallback() { @Override @@ -152,8 +151,8 @@ public class RileyLinkBLE { } else if ((newState == BluetoothProfile.STATE_CONNECTING) || // (newState == BluetoothProfile.STATE_DISCONNECTING)) { - // aapsLogger.debug(LTag.PUMPBTCOMM,"We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" : - // "Disconnecting"); + aapsLogger.debug(LTag.PUMPBTCOMM,"We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" : + "Disconnecting"); } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnected, context); if (manualDisconnect) @@ -243,8 +242,6 @@ public class RileyLinkBLE { if (rileyLinkFound) { mIsConnected = true; rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkReady, context); - // RileyLinkUtil.sendNotification(new - // ServiceNotification(RileyLinkConst.Intents.RileyLinkReady), null); } else { mIsConnected = false; rileyLinkServiceData.setServiceState(RileyLinkServiceState.RileyLinkError, @@ -259,6 +256,11 @@ public class RileyLinkBLE { }; } + @Inject + public void onInit() { + aapsLogger.debug(LTag.PUMPBTCOMM, "BT Adapter: " + this.bluetoothAdapter); + } + private boolean isAnyRileyLinkServiceFound(BluetoothGattService service) { @@ -273,7 +275,6 @@ public class RileyLinkBLE { if (isAnyRileyLinkServiceFound(serviceI)) { return true; } - } } @@ -434,6 +435,7 @@ public class RileyLinkBLE { rval.resultCode = BLECommOperationResult.RESULT_NONE; aapsLogger.error(LTag.PUMPBTCOMM, "BT Device not supported"); // TODO: 11/07/2016 UI update for user + // xyz rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.NoBluetoothAdapter); } else { BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID) .getCharacteristic(charaUUID); @@ -493,6 +495,7 @@ public class RileyLinkBLE { rval.resultCode = BLECommOperationResult.RESULT_NONE; aapsLogger.error(LTag.PUMPBTCOMM, "BT Device not supported"); // TODO: 11/07/2016 UI update for user + // xyz rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.NoBluetoothAdapter); } else { BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID) .getCharacteristic(charaUUID); @@ -535,6 +538,7 @@ public class RileyLinkBLE { rval.resultCode = BLECommOperationResult.RESULT_NONE; aapsLogger.error(LTag.PUMPBTCOMM, "BT Device not supported"); // TODO: 11/07/2016 UI update for user + // xyz rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.NoBluetoothAdapter); } else { BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID).getCharacteristic( charaUUID); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/data/RLHistoryItem.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/data/RLHistoryItem.java index c845a3afe2..7b25cf63ec 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/data/RLHistoryItem.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/data/RLHistoryItem.java @@ -2,17 +2,11 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data; import org.joda.time.LocalDateTime; - - - import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; -//import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType; -//import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState; import info.nightscout.androidaps.utils.resources.ResourceHelper; -//import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType; /** @@ -21,7 +15,6 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper; public class RLHistoryItem { - //private MedtronicCommandType medtronicCommandType; protected LocalDateTime dateTime; protected RLHistoryItemSource source; protected RileyLinkServiceState serviceState; @@ -29,9 +22,8 @@ public class RLHistoryItem { protected RileyLinkTargetDevice targetDevice; protected PumpDeviceState pumpDeviceState; - //private OmnipodCommandType omnipodCommandType; - public RLHistoryItem(LocalDateTime dateTime, RLHistoryItemSource source, RileyLinkTargetDevice targetDevice) { + public RLHistoryItem(LocalDateTime dateTime, RLHistoryItemSource source, RileyLinkTargetDevice targetDevice) { this.dateTime = dateTime; this.source = source; this.targetDevice = targetDevice; @@ -46,7 +38,6 @@ public class RLHistoryItem { this.source = RLHistoryItemSource.RileyLink; } - public RLHistoryItem(PumpDeviceState pumpDeviceState, RileyLinkTargetDevice targetDevice) { this.pumpDeviceState = pumpDeviceState; this.dateTime = new LocalDateTime(); @@ -54,64 +45,34 @@ public class RLHistoryItem { this.source = RLHistoryItemSource.MedtronicPump; } - -// public RLHistoryItem(MedtronicCommandType medtronicCommandType) { -// this.dateTime = new LocalDateTime(); -// this.medtronicCommandType = medtronicCommandType; -// source = RLHistoryItemSource.MedtronicCommand; -// } -// -// -// public RLHistoryItem(OmnipodCommandType omnipodCommandType) { -// this.dateTime = new LocalDateTime(); -// this.omnipodCommandType = omnipodCommandType; -// source = RLHistoryItemSource.OmnipodCommand; -// } - - public LocalDateTime getDateTime() { return dateTime; } - public RileyLinkServiceState getServiceState() { return serviceState; } - public RileyLinkError getErrorCode() { return errorCode; } - public String getDescription(ResourceHelper resourceHelper) { - - // TODO extend when we have Omnipod switch (this.source) { case RileyLink: - return "State: " + resourceHelper.gs(serviceState.getResourceId(targetDevice)) + return "State: " + resourceHelper.gs(serviceState.getResourceId()) + (this.errorCode == null ? "" : ", Error Code: " + errorCode); - case MedtronicPump: return resourceHelper.gs(pumpDeviceState.getResourceId()); - -// case MedtronicCommand: -// return medtronicCommandType.name(); -// -// case OmnipodCommand: -// return omnipodCommandType.name(); - default: return "Unknown Description"; } } - public RLHistoryItemSource getSource() { return source; } - public PumpDeviceState getPumpDeviceState() { return pumpDeviceState; } @@ -129,14 +90,12 @@ public class RLHistoryItem { this.desc = desc; } - public String getDesc() { return desc; } } public static class Comparator implements java.util.Comparator { - @Override public int compare(RLHistoryItem o1, RLHistoryItem o2) { return o2.dateTime.compareTo(o1.getDateTime()); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/defs/RileyLinkPumpDevice.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/defs/RileyLinkPumpDevice.java index 71c2b5d20a..996eb5a358 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/defs/RileyLinkPumpDevice.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/defs/RileyLinkPumpDevice.java @@ -4,18 +4,15 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.Riley public interface RileyLinkPumpDevice { - void setIsBusy(boolean isBusy_); - - boolean isBusy(); - - void resetRileyLinkConfiguration(); - - boolean hasTuneUp(); - - void doTuneUpDevice(); + void setBusy(boolean busy); void triggerPumpConfigurationChangedEvent(); RileyLinkService getRileyLinkService(); + RileyLinkPumpInfo getPumpInfo(); + + long getLastConnectionTimeMillis(); + + void setLastCommunicationToNow(); } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/defs/RileyLinkPumpInfo.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/defs/RileyLinkPumpInfo.java new file mode 100644 index 0000000000..9759a9adc7 --- /dev/null +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/defs/RileyLinkPumpInfo.java @@ -0,0 +1,31 @@ +package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs; + +public class RileyLinkPumpInfo { + private final String connectedDeviceModel; + private final String pumpDescription; + private final String connectedDeviceSerialNumber; + private final String pumpFrequency; + + public RileyLinkPumpInfo(String pumpDescription, String pumpFrequency, String connectedDeviceModel, String connectedDeviceSerialNumber) { + this.pumpDescription = pumpDescription; + this.pumpFrequency = pumpFrequency; + this.connectedDeviceModel = connectedDeviceModel; + this.connectedDeviceSerialNumber = connectedDeviceSerialNumber; + } + + public String getConnectedDeviceModel() { + return connectedDeviceModel; + } + + public String getPumpDescription() { + return pumpDescription; + } + + public String getConnectedDeviceSerialNumber() { + return connectedDeviceSerialNumber; + } + + public String getPumpFrequency() { + return pumpFrequency; + } +} diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/defs/RileyLinkServiceState.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/defs/RileyLinkServiceState.java index 31c5f981f3..97ce0c6ce1 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/defs/RileyLinkServiceState.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/defs/RileyLinkServiceState.java @@ -22,7 +22,7 @@ public enum RileyLinkServiceState { RileyLinkInitializing(R.string.rileylink_state_rl_init), // (S) start Gatt discovery (OK -> RileyLinkReady, Error -> // BluetoothEnabled) ?? RileyLinkError(R.string.rileylink_state_rl_error), // (E) - RileyLinkReady(R.string.rileylink_state_connected), // (OK) if tunning was already done we go to PumpConnectorReady + RileyLinkReady(R.string.rileylink_state_rl_ready), // (OK) if tunning was already done we go to PumpConnectorReady // Tunning TuneUpDevice(R.string.rileylink_state_pc_tune_up), // (S) @@ -40,43 +40,23 @@ public enum RileyLinkServiceState { // RileyLinkConnected, // -> TuneUpPump (on 1st), else PumpConnectorReady // PumpConnected, // - ; int resourceId; - Integer resourceIdPod; - RileyLinkServiceState(int resourceId) { this.resourceId = resourceId; } - - RileyLinkServiceState(int resourceId, int resourceIdPod) { - this.resourceId = resourceId; - this.resourceIdPod = resourceIdPod; + public boolean isReady() { + return (this == PumpConnectorReady); } - - public static boolean isReady(RileyLinkServiceState serviceState) { - return (/* serviceState == RileyLinkReady || */serviceState == PumpConnectorReady); + public int getResourceId() { + return this.resourceId; } - - public int getResourceId(RileyLinkTargetDevice targetDevice) { - if (this.resourceIdPod != null) { - - return (targetDevice == null || targetDevice == RileyLinkTargetDevice.MedtronicPump) ? // - this.resourceId - : this.resourceIdPod; - } else { - return this.resourceId; - } - } - - public boolean isConnecting() { - return (this == RileyLinkServiceState.BluetoothInitializing || // // this == RileyLinkServiceState.BluetoothError || // this == RileyLinkServiceState.BluetoothReady || // @@ -86,9 +66,7 @@ public enum RileyLinkServiceState { ); } - public boolean isError() { - return (this == RileyLinkServiceState.BluetoothError || // // this == RileyLinkServiceState.PumpConnectorError || // this == RileyLinkServiceState.RileyLinkError); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/defs/RileyLinkTargetDevice.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/defs/RileyLinkTargetDevice.java index 99b4ecd40a..8934ae555b 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/defs/RileyLinkTargetDevice.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/defs/RileyLinkTargetDevice.java @@ -15,18 +15,15 @@ public enum RileyLinkTargetDevice { private int resourceId; private boolean tuneUpEnabled; - RileyLinkTargetDevice(int resourceId, boolean tuneUpEnabled) { this.resourceId = resourceId; this.tuneUpEnabled = tuneUpEnabled; } - public boolean isTuneUpEnabled() { return tuneUpEnabled; } - public int getResourceId() { return resourceId; } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java index e4b6f154af..42f303b3cf 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java @@ -15,13 +15,11 @@ import javax.inject.Inject; import dagger.android.support.DaggerFragment; import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.plugins.common.ManufacturerType; -import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract; import info.nightscout.androidaps.plugins.pump.common.R; -import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus; -import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkFirmwareVersion; +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice; +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpInfo; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData; import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil; @@ -36,7 +34,6 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re @Inject ActivePluginProvider activePlugin; @Inject ResourceHelper resourceHelper; - //@Inject MedtronicUtil medtronicUtil; @Inject AAPSLogger aapsLogger; @Inject RileyLinkServiceData rileyLinkServiceData; @Inject DateUtil dateUtil; @@ -103,7 +100,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re RileyLinkTargetDevice targetDevice = rileyLinkServiceData.targetDevice; - this.connectionStatus.setText(resourceHelper.gs(rileyLinkServiceData.rileyLinkServiceState.getResourceId(targetDevice))); + this.connectionStatus.setText(resourceHelper.gs(rileyLinkServiceData.rileyLinkServiceState.getResourceId())); if (rileyLinkServiceData != null) { this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress); @@ -122,69 +119,24 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re } - PumpPluginAbstract pumpPlugin = (PumpPluginAbstract)activePlugin.getActivePump(); + RileyLinkPumpDevice pumpPlugin = (RileyLinkPumpDevice) activePlugin.getActivePump(); + RileyLinkPumpInfo pumpInfo = pumpPlugin.getPumpInfo(); + this.deviceType.setText(rileyLinkServiceData.targetDevice.getResourceId()); + this.deviceModel.setText(pumpInfo.getPumpDescription()); + this.serialNumber.setText(pumpInfo.getConnectedDeviceSerialNumber()); + this.pumpFrequency.setText(pumpInfo.getPumpFrequency()); + this.connectedDevice.setText(pumpInfo.getConnectedDeviceModel()); - if (pumpPlugin.manufacturer()== ManufacturerType.Medtronic) { - //MedtronicPumpStatus medtronicPumpStatus = (MedtronicPumpStatus)pumpPlugin.getPumpStatusData(); + if (rileyLinkServiceData.lastGoodFrequency != null) { + this.lastUsedFrequency.setText(String.format(Locale.ENGLISH, "%.2f MHz", + rileyLinkServiceData.lastGoodFrequency)); + } - PumpStatus pumpStatusData = pumpPlugin.getPumpStatusData(); - - this.deviceType.setText(resourceHelper.gs(RileyLinkTargetDevice.MedtronicPump.getResourceId())); - this.deviceModel.setText(pumpPlugin.getPumpType().getDescription()); - this.serialNumber.setText(pumpStatusData.getCustomDataAsString("SERIAL_NUMBER")); // medtronicPumpStatus.serialNumber); - this.pumpFrequency.setText(resourceHelper.gs(pumpStatusData.getCustomDataAsString("PUMP_FREQUENCY").equals("medtronic_pump_frequency_us_ca") ? R.string.medtronic_pump_frequency_us_ca : R.string.medtronic_pump_frequency_worldwide)); - - if (pumpStatusData.getCustomDataAsString("PUMP_MODEL") != null) - this.connectedDevice.setText("Medtronic " + pumpStatusData.getCustomDataAsString("PUMP_MODEL")); - else - this.connectedDevice.setText("???"); - - if (rileyLinkServiceData.lastGoodFrequency != null) - this.lastUsedFrequency.setText(String.format(Locale.ENGLISH, "%.2f MHz", - rileyLinkServiceData.lastGoodFrequency)); - - if (pumpStatusData.lastConnection != 0) - this.lastDeviceContact.setText(StringUtil.toDateTimeString(dateUtil, new LocalDateTime( - pumpStatusData.lastDataTime))); - else - this.lastDeviceContact.setText(resourceHelper.gs(R.string.common_never)); + long lastConnectionTimeMillis = pumpPlugin.getLastConnectionTimeMillis(); + if (lastConnectionTimeMillis == 0) { + this.lastDeviceContact.setText(resourceHelper.gs(R.string.common_never)); } else { - - //OmnipodPumpStatus omnipodPumpStatus = (OmnipodPumpStatus)pumpPlugin.getPumpStatusData(); - PumpStatus pumpStatusData = pumpPlugin.getPumpStatusData(); - - this.deviceType.setText(resourceHelper.gs(RileyLinkTargetDevice.Omnipod.getResourceId())); - this.deviceModel.setText(pumpPlugin.getPumpType() == PumpType.Insulet_Omnipod ? "Eros" : "Dash"); - - if (pumpPlugin.getPumpType()== PumpType.Insulet_Omnipod_Dash) { - aapsLogger.error("Omnipod Dash not yet supported !!!"); - - this.pumpFrequency.setText("-"); - } else { - - this.pumpFrequency.setText(resourceHelper.gs(R.string.omnipod_frequency)); - - if (pumpStatusData != null) { - - if (pumpStatusData.getCustomData("POD_AVAILABLE", Boolean.class)) { - this.serialNumber.setText(pumpStatusData.getCustomDataAsString("POD_LOT_NUMBER")); - this.connectedDevice.setText(pumpStatusData.pumpType == PumpType.Insulet_Omnipod ? "Eros Pod" : "Dash Pod"); - } else { - this.serialNumber.setText("??"); - this.connectedDevice.setText("-"); - } - - if (rileyLinkServiceData.lastGoodFrequency != null) - this.lastUsedFrequency.setText(String.format(Locale.ENGLISH, "%.2f MHz", - rileyLinkServiceData.lastGoodFrequency)); - - if (pumpStatusData.lastConnection != 0) - this.lastDeviceContact.setText(StringUtil.toDateTimeString(dateUtil, new LocalDateTime( - pumpStatusData.lastDataTime))); - else - this.lastDeviceContact.setText(resourceHelper.gs(R.string.common_never)); - } - } + this.lastDeviceContact.setText(StringUtil.toDateTimeString(dateUtil, new LocalDateTime(lastConnectionTimeMillis))); } } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java index 7fefacc8c5..e8e0139524 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java @@ -143,7 +143,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { return true; } else if (action.equals(RileyLinkConst.Intents.RileyLinkReady)) { - aapsLogger.warn(LTag.PUMPCOMM, "MedtronicConst.Intents.RileyLinkReady"); + aapsLogger.warn(LTag.PUMPCOMM, "RileyLinkConst.Intents.RileyLinkReady"); // sendIPCNotification(RT2Const.IPC.MSG_note_WakingPump); rileyLinkService.rileyLinkBLE.enableNotifications(); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java index 08503155af..0e340918c8 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java @@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service; import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import org.jetbrains.annotations.NotNull; @@ -45,10 +44,10 @@ public abstract class RileyLinkService extends DaggerService { @Inject protected ResourceHelper resourceHelper; @Inject protected RileyLinkServiceData rileyLinkServiceData; @Inject protected ActivePluginProvider activePlugin; + @Inject protected RileyLinkBLE rileyLinkBLE; // android-bluetooth management + @Inject protected RFSpy rfspy; // interface for RL xxx Mhz radio. - @NotNull protected RileyLinkBLE rileyLinkBLE; // android-bluetooth management, must be set in initRileyLinkServiceData protected BluetoothAdapter bluetoothAdapter; - protected RFSpy rfspy; // interface for RL xxx Mhz radio. protected RileyLinkBroadcastReceiver mBroadcastReceiver; protected RileyLinkBluetoothStateReceiver bluetoothStateReceiver; @@ -99,6 +98,7 @@ public abstract class RileyLinkService extends DaggerService { super.onDestroy(); //LOG.error("I die! I die!"); + // xyz rfspy.stopReader(); rileyLinkBLE.disconnect(); // dispose of Gatt (disconnect and close) if (mBroadcastReceiver != null) { @@ -112,21 +112,6 @@ public abstract class RileyLinkService extends DaggerService { } - /** - * Prefix for Device specific broadcast identifier prefix (for example MSG_PUMP_ for pump or - * MSG_POD_ for Omnipod) - * - * @return - */ - public abstract String getDeviceSpecificBroadcastsIdentifierPrefix(); - - - public abstract boolean handleDeviceSpecificBroadcasts(Intent intent); - - - public abstract void registerDeviceSpecificBroadcasts(IntentFilter intentFilter); - - public abstract RileyLinkCommunicationManager getDeviceCommunicationManager(); // Here is where the wake-lock begins: @@ -199,13 +184,6 @@ public abstract class RileyLinkService extends DaggerService { } } - - public void sendServiceTransportResponse(ServiceTransport transport, ServiceResult serviceResult) { - } - - - - // FIXME: This needs to be run in a session so that is interruptable, has a separate thread, etc. public void doTuneUpDevice() { diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java index f3362e0db7..13bebc22b8 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service; import javax.inject.Inject; import javax.inject.Singleton; +import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; @@ -15,7 +16,6 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLin import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; - /** * Created by andy on 16/05/2018. */ @@ -26,12 +26,14 @@ public class RileyLinkServiceData { @Inject AAPSLogger aapsLogger; @Inject RileyLinkUtil rileyLinkUtil; @Inject RxBusWrapper rxBus; + @Inject ActivePluginProvider activePlugin; boolean tuneUpDone = false; public RileyLinkError rileyLinkError; public RileyLinkServiceState rileyLinkServiceState = RileyLinkServiceState.NotStarted; + private long lastServiceStateChange = 0L; public RileyLinkFirmwareVersion firmwareVersion; - public RileyLinkTargetFrequency rileyLinkTargetFrequency; + public RileyLinkTargetFrequency rileyLinkTargetFrequency; // TODO this might not be correct place public String rileylinkAddress; long lastTuneUpTime = 0L; @@ -42,14 +44,15 @@ public class RileyLinkServiceData { // radio version public RileyLinkFirmwareVersion versionCC110; - public RileyLinkTargetDevice targetDevice; + public RileyLinkTargetDevice targetDevice; // TODO this might not be correct place // Medtronic Pump public String pumpID; public byte[] pumpIDBytes; @Inject - public RileyLinkServiceData() {} + public RileyLinkServiceData() { + } public void setPumpID(String pumpId, byte[] pumpIdBytes) { this.pumpID = pumpId; @@ -64,24 +67,26 @@ public class RileyLinkServiceData { return workWithServiceState(null, null, false); } - public void setServiceState(RileyLinkServiceState newState, RileyLinkError errorCode) { workWithServiceState(newState, errorCode, true); } + public long getLastServiceStateChange() { + return lastServiceStateChange; + } private synchronized RileyLinkServiceState workWithServiceState(RileyLinkServiceState newState, RileyLinkError errorCode, boolean set) { if (set) { rileyLinkServiceState = newState; + lastServiceStateChange = System.currentTimeMillis(); this.rileyLinkError = errorCode; aapsLogger.info(LTag.PUMP, "RileyLink State Changed: {} {}", newState, errorCode == null ? "" : " - Error State: " + errorCode.name()); rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(rileyLinkServiceState, errorCode, targetDevice)); rxBus.send(new EventRileyLinkDeviceStatusChange(newState, errorCode)); - return null; } else { diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/DiscoverGattServicesTask.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/DiscoverGattServicesTask.java index a9d84d63d5..74396ec4a1 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/DiscoverGattServicesTask.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/DiscoverGattServicesTask.java @@ -5,8 +5,6 @@ import javax.inject.Inject; import dagger.android.HasAndroidInjector; import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice; /** @@ -33,13 +31,6 @@ public class DiscoverGattServicesTask extends ServiceTask { @Override public void run() { - - if (activePlugin.getActivePump().model() == PumpType.Insulet_Omnipod_Dash) { - // TODO different init classes, this can be probably removed later - aapsLogger.warn(LTag.PUMPCOMM, "Discovery Gatt Services not implemeneted for Dash."); - return; - } - RileyLinkPumpDevice pumpDevice = (RileyLinkPumpDevice) activePlugin.getActivePump(); if (needToConnect) { diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/InitializePumpManagerTask.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/InitializePumpManagerTask.java index 73aab9c4f9..70e6440f0f 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/InitializePumpManagerTask.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/InitializePumpManagerTask.java @@ -9,7 +9,6 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.common.ManufacturerType; -import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/ResetRileyLinkConfigurationTask.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/ResetRileyLinkConfigurationTask.java index 3263253e5e..da8db8fee4 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/ResetRileyLinkConfigurationTask.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/ResetRileyLinkConfigurationTask.java @@ -6,8 +6,8 @@ import dagger.android.HasAndroidInjector; import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.pump.common.events.EventRefreshButtonState; +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport; /** * Created by andy on 9/16/18. @@ -16,29 +16,23 @@ public class ResetRileyLinkConfigurationTask extends PumpTask { @Inject ActivePluginProvider activePlugin; @Inject RxBusWrapper rxBus; + @Inject RFSpy rfSpy; public ResetRileyLinkConfigurationTask(HasAndroidInjector injector) { super(injector); } - - public ResetRileyLinkConfigurationTask(HasAndroidInjector injector, ServiceTransport transport) { - super(injector, transport); - } - - @Override public void run() { - RileyLinkPumpDevice pumpAbstract = (RileyLinkPumpDevice) activePlugin.getActivePump(); + RileyLinkPumpDevice rileyLinkPumpDevice = (RileyLinkPumpDevice) activePlugin.getActivePump(); rxBus.send(new EventRefreshButtonState(false)); - pumpAbstract.setIsBusy(true); - pumpAbstract.resetRileyLinkConfiguration(); - pumpAbstract.setIsBusy(false); + rileyLinkPumpDevice.setBusy(true); + rfSpy.resetRileyLinkConfiguration(); + rileyLinkPumpDevice.setBusy(false); rxBus.send(new EventRefreshButtonState(true)); } - } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/WakeAndTuneTask.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/WakeAndTuneTask.java index d3011eede2..0411903fe2 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/WakeAndTuneTask.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/WakeAndTuneTask.java @@ -7,7 +7,6 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.pump.common.events.EventRefreshButtonState; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport; /** * Created by geoff on 7/16/16. @@ -19,24 +18,17 @@ public class WakeAndTuneTask extends PumpTask { private static final String TAG = "WakeAndTuneTask"; - public WakeAndTuneTask(HasAndroidInjector injector) { super(injector); } - - public WakeAndTuneTask(HasAndroidInjector injector, ServiceTransport transport) { - super(injector, transport); - } - - @Override public void run() { - RileyLinkPumpDevice pumpDevice = (RileyLinkPumpDevice)activePlugin.getActivePump(); + RileyLinkPumpDevice pumpDevice = (RileyLinkPumpDevice) activePlugin.getActivePump(); rxBus.send(new EventRefreshButtonState(false)); - pumpDevice.setIsBusy(true); - pumpDevice.doTuneUpDevice(); - pumpDevice.setIsBusy(false); + pumpDevice.setBusy(true); + pumpDevice.getRileyLinkService().doTuneUpDevice(); + pumpDevice.setBusy(false); rxBus.send(new EventRefreshButtonState(true)); } } diff --git a/rileylink/src/main/res/values/strings.xml b/rileylink/src/main/res/values/strings.xml index ddb9beaf9b..8f4d134211 100644 --- a/rileylink/src/main/res/values/strings.xml +++ b/rileylink/src/main/res/values/strings.xml @@ -42,6 +42,7 @@ Tuning up RileyLink and Pump Problem connecting to Pump Connected + RileyLink ready Device is not RileyLink @@ -56,11 +57,6 @@ Medtronic Pump Omnipod - - Omnipod (433.91 MHz) - US & Canada (916 MHz) - Worldwide (868 Mhz) - medtronic_pump_encoding_4b6b_local medtronic_pump_encoding_4b6b_rileylink @@ -69,9 +65,6 @@ %1$.1f %2$s (%3$s) - - - %1$d day %1$d days @@ -80,10 +73,6 @@ %1$d hour %1$d hours - - - - \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 19da851b52..4fb6743f5f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ -include ':app', ':wear', ':core', ':dana', ':danar', ':danars', ':rileylink', ':medtronic' +include ':app', ':wear', ':core', ':dana', ':danar', ':danars', ':rileylink', ':medtronic', ':omnipod'