This commit is contained in:
Milos Kozak 2022-06-21 18:52:01 +02:00
commit 7f4f5de34d
37 changed files with 403 additions and 521 deletions

View file

@ -16,12 +16,12 @@ import info.nightscout.androidaps.dependencyInjection.AutotuneModule
import info.nightscout.androidaps.diaconn.di.DiaconnG8Module
import info.nightscout.androidaps.insight.di.InsightDatabaseModule
import info.nightscout.androidaps.insight.di.InsightModule
import info.nightscout.androidaps.plugin.general.openhumans.dagger.OpenHumansModule
import info.nightscout.androidaps.plugin.general.openhumans.di.OpenHumansModule
import info.nightscout.androidaps.plugins.pump.common.di.PumpCommonModule
import info.nightscout.androidaps.plugins.pump.common.di.RileyLinkModule
import info.nightscout.androidaps.plugins.pump.medtronic.di.MedtronicModule
import info.nightscout.androidaps.plugins.pump.omnipod.dash.dagger.OmnipodDashModule
import info.nightscout.androidaps.plugins.pump.omnipod.eros.dagger.OmnipodErosModule
import info.nightscout.androidaps.plugins.pump.omnipod.dash.di.OmnipodDashModule
import info.nightscout.androidaps.plugins.pump.omnipod.eros.di.OmnipodErosModule
import info.nightscout.shared.di.SharedModule
import javax.inject.Singleton

View file

@ -8,6 +8,8 @@ import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.graphics.Paint
import android.os.Handler
import android.os.HandlerThread
import android.view.View
import android.widget.RemoteViews
import dagger.android.HasAndroidInjector
@ -26,7 +28,6 @@ import info.nightscout.androidaps.plugins.general.overview.OverviewData
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.TrendCalculator
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.shared.sharedPreferences.SP
@ -53,6 +54,7 @@ class Widget : AppWidgetProvider() {
@Inject lateinit var sp: SP
@Inject lateinit var constraintChecker: ConstraintChecker
private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
private val intentAction = "OpenApp"
override fun onReceive(context: Context, intent: Intent?) {
@ -88,16 +90,17 @@ class Widget : AppWidgetProvider() {
views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent)
views.setInt(R.id.widget_layout, "setBackgroundColor", Color.argb(alpha, 0, 0, 0))
updateBg(views)
updateTemporaryBasal(views)
updateExtendedBolus(views)
updateIobCob(views)
updateTemporaryTarget(views)
updateProfile(views)
updateSensitivity(views)
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views)
handler.post {
updateBg(views)
updateTemporaryBasal(views)
updateExtendedBolus(views)
updateIobCob(views)
updateTemporaryTarget(views)
updateProfile(views)
updateSensitivity(views)
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views)
}
}
private fun updateBg(views: RemoteViews) {

View file

@ -10,7 +10,7 @@ buildscript {
room_version = '2.4.2'
lifecycle_version = '2.4.1'
dagger_version = '2.42'
coroutines_version = '1.6.2'
coroutines_version = '1.6.3'
activity_version = '1.4.0'
fragmentktx_version = '1.4.1'
ormLite_version = '4.46'

View file

@ -91,16 +91,17 @@ class MedtronicPumpPlugin @Inject constructor(
aapsSchedulers: AapsSchedulers,
pumpSync: PumpSync,
pumpSyncStorage: info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage
) : PumpPluginAbstract(PluginDescription() //
.mainType(PluginType.PUMP) //
.fragmentClass(MedtronicFragment::class.java.name) //
.pluginIcon(R.drawable.ic_veo_128)
.pluginName(R.string.medtronic_name) //
.shortName(R.string.medtronic_name_short) //
.preferencesId(R.xml.pref_medtronic)
.description(R.string.description_pump_medtronic), //
PumpType.MEDTRONIC_522_722, // we default to most basic model, correct model from config is loaded later
injector, rh, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy, dateUtil, aapsSchedulers, pumpSync, pumpSyncStorage
) : PumpPluginAbstract(
PluginDescription() //
.mainType(PluginType.PUMP) //
.fragmentClass(MedtronicFragment::class.java.name) //
.pluginIcon(R.drawable.ic_veo_128)
.pluginName(R.string.medtronic_name) //
.shortName(R.string.medtronic_name_short) //
.preferencesId(R.xml.pref_medtronic)
.description(R.string.description_pump_medtronic), //
PumpType.MEDTRONIC_522_722, // we default to most basic model, correct model from config is loaded later
injector, rh, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy, dateUtil, aapsSchedulers, pumpSync, pumpSyncStorage
), Pump, RileyLinkPumpDevice, PumpSyncEntriesCreator {
private var rileyLinkMedtronicService: RileyLinkMedtronicService? = null
@ -234,18 +235,16 @@ class MedtronicPumpPlugin @Inject constructor(
// Pump Plugin
private var isServiceSet: Boolean = false
override fun getRileyLinkService(): RileyLinkMedtronicService? = rileyLinkMedtronicService
override val rileyLinkService: RileyLinkMedtronicService? = rileyLinkMedtronicService
override fun getPumpInfo(): RileyLinkPumpInfo {
val frequency = rh.gs(if (medtronicPumpStatus.pumpFrequency == "medtronic_pump_frequency_us_ca") R.string.medtronic_pump_frequency_us_ca else R.string.medtronic_pump_frequency_worldwide)
val model = if (!medtronicUtil.isModelSet) "???" else "Medtronic " + medtronicPumpStatus.medtronicDeviceType.pumpModel
val serialNumber = medtronicPumpStatus.serialNumber
return RileyLinkPumpInfo(frequency, model, serialNumber)
}
override val pumpInfo: RileyLinkPumpInfo
get() = RileyLinkPumpInfo(
rh.gs(if (medtronicPumpStatus.pumpFrequency == "medtronic_pump_frequency_us_ca") R.string.medtronic_pump_frequency_us_ca else R.string.medtronic_pump_frequency_worldwide),
if (!medtronicUtil.isModelSet) "???" else "Medtronic " + medtronicPumpStatus.medtronicDeviceType.pumpModel,
medtronicPumpStatus.serialNumber
)
override fun getLastConnectionTimeMillis(): Long {
return medtronicPumpStatus.lastConnection
}
override val lastConnectionTimeMillis: Long = medtronicPumpStatus.lastConnection
override fun setLastCommunicationToNow() {
medtronicPumpStatus.setLastCommunicationToNow()
@ -326,7 +325,8 @@ class MedtronicPumpPlugin @Inject constructor(
}
if (rileyLinkServiceState != RileyLinkServiceState.PumpConnectorReady //
&& rileyLinkServiceState != RileyLinkServiceState.RileyLinkReady //
&& rileyLinkServiceState != RileyLinkServiceState.TuneUpDevice) {
&& rileyLinkServiceState != RileyLinkServiceState.TuneUpDevice
) {
aapsLogger.debug(LTag.PUMP, "RileyLink unreachable.")
return false
}
@ -334,8 +334,10 @@ class MedtronicPumpPlugin @Inject constructor(
}
private fun refreshAnyStatusThatNeedsToBeRefreshed() {
val statusRefresh = workWithStatusRefresh(StatusRefreshAction.GetData, null,
null)!!
val statusRefresh = workWithStatusRefresh(
StatusRefreshAction.GetData, null,
null
)!!
if (!doWeHaveAnyStatusNeededRefreshing(statusRefresh)) {
return
}
@ -491,7 +493,7 @@ class MedtronicPumpPlugin @Inject constructor(
val basalsByHour: DoubleArray? = medtronicPumpStatus.basalsByHour
aapsLogger.debug(
LTag.PUMP, "Current Basals (h): "
+ (basalsByHour?.let { getProfilesByHourToString(it) } ?: "null"))
+ (basalsByHour?.let { getProfilesByHourToString(it) } ?: "null"))
// int index = 0;
if (basalsByHour == null) return true // we don't want to set profile again, unless we are sure
@ -594,9 +596,13 @@ class MedtronicPumpPlugin @Inject constructor(
return PumpEnactResult(injector) //
.success(false) //
.enacted(false) //
.comment(rh.gs(R.string.medtronic_cmd_bolus_could_not_be_delivered_no_insulin,
medtronicPumpStatus.reservoirRemainingUnits,
detailedBolusInfo.insulin))
.comment(
rh.gs(
R.string.medtronic_cmd_bolus_could_not_be_delivered_no_insulin,
medtronicPumpStatus.reservoirRemainingUnits,
detailedBolusInfo.insulin
)
)
}
bolusDeliveryType = BolusDeliveryType.DeliveryPrepared
if (isPumpNotReachable) {
@ -619,8 +625,10 @@ class MedtronicPumpPlugin @Inject constructor(
bolusDeliveryType = BolusDeliveryType.Delivering
// LOG.debug("MedtronicPumpPlugin::deliverBolus - Start delivery");
val responseTask = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(MedtronicCommandType.SetBolus,
arrayListOf(detailedBolusInfo.insulin))
val responseTask = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(
MedtronicCommandType.SetBolus,
arrayListOf(detailedBolusInfo.insulin)
)
val response = responseTask?.result as Boolean?
setRefreshButtonEnabled(true)
@ -757,8 +765,10 @@ class MedtronicPumpPlugin @Inject constructor(
}
// now start new TBR
val responseTask = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(MedtronicCommandType.SetTemporaryBasal,
arrayListOf(absoluteRate, durationInMinutes))
val responseTask = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(
MedtronicCommandType.SetTemporaryBasal,
arrayListOf(absoluteRate, durationInMinutes)
)
val response = responseTask?.result as Boolean?
aapsLogger.info(LTag.PUMP, logPrefix + "setTempBasalAbsolute - setTBR. Response: " + response)
return if (response == null || !response) {
@ -784,13 +794,13 @@ class MedtronicPumpPlugin @Inject constructor(
@Deprecated("Not used, TBRs fixed in history, should be removed.")
private fun cancelTBRWithTemporaryId() {
val tbrs : MutableList<PumpDbEntryTBR> = pumpSyncStorage.getTBRs()
if (tbrs.size > 0 && medtronicPumpStatus.runningTBRWithTemp!=null) {
val tbrs: MutableList<PumpDbEntryTBR> = pumpSyncStorage.getTBRs()
if (tbrs.size > 0 && medtronicPumpStatus.runningTBRWithTemp != null) {
aapsLogger.info(LTag.PUMP, logPrefix + "cancelTBRWithTemporaryId - TBR items: ${tbrs.size}")
var item : PumpDbEntryTBR? = null
var item: PumpDbEntryTBR? = null
if (tbrs.size==1) {
if (tbrs.size == 1) {
item = tbrs[0]
} else {
for (tbr in tbrs) {
@ -801,7 +811,7 @@ class MedtronicPumpPlugin @Inject constructor(
}
}
if (item!=null) {
if (item != null) {
aapsLogger.debug(LTag.PUMP, "DD: cancelTBRWithTemporaryId: tempIdEntry=${item}")
@ -809,23 +819,25 @@ class MedtronicPumpPlugin @Inject constructor(
aapsLogger.debug(
LTag.PUMP, "syncTemporaryBasalWithTempId " +
"[date=${item.date}, " +
"rate=${item.rate}, " +
"duration=${differenceS} s, " +
"isAbsolute=${!item.isAbsolute}, temporaryId=${item.temporaryId}, " +
"pumpId=NO, pumpType=${medtronicPumpStatus.pumpType}, " +
"pumpSerial=${medtronicPumpStatus.serialNumber}]")
"[date=${item.date}, " +
"rate=${item.rate}, " +
"duration=${differenceS} s, " +
"isAbsolute=${!item.isAbsolute}, temporaryId=${item.temporaryId}, " +
"pumpId=NO, pumpType=${medtronicPumpStatus.pumpType}, " +
"pumpSerial=${medtronicPumpStatus.serialNumber}]"
)
val result = pumpSync.syncTemporaryBasalWithTempId(
timestamp = item.date,
rate = item.rate,
duration= differenceS * 1000L,
duration = differenceS * 1000L,
isAbsolute = item.isAbsolute,
temporaryId = item.temporaryId,
type = item.tbrType,
pumpId = null,
pumpType = medtronicPumpStatus.pumpType,
pumpSerial = medtronicPumpStatus.serialNumber)
pumpSerial = medtronicPumpStatus.serialNumber
)
aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithTempId - Result: $result")
}
@ -834,7 +846,7 @@ class MedtronicPumpPlugin @Inject constructor(
aapsLogger.info(LTag.PUMP, logPrefix + "cancelTBRWithTemporaryId - TBR items: ${tbrs.size}, runningTBRWithTemp=${medtronicPumpStatus.runningTBRWithTemp}")
}
if (medtronicPumpStatus.runningTBRWithTemp!=null) {
if (medtronicPumpStatus.runningTBRWithTemp != null) {
medtronicPumpStatus.runningTBRWithTemp = null
}
}
@ -846,7 +858,10 @@ class MedtronicPumpPlugin @Inject constructor(
} else {
var absoluteValue = profile.getBasal() * (percent / 100.0)
absoluteValue = pumpDescription.pumpType.determineCorrectBasalSize(absoluteValue)
aapsLogger.warn(LTag.PUMP, "setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% ($percent). This will start setTempBasalAbsolute, with calculated value ($absoluteValue). Result might not be 100% correct.")
aapsLogger.warn(
LTag.PUMP,
"setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% ($percent). This will start setTempBasalAbsolute, with calculated value ($absoluteValue). Result might not be 100% correct."
)
setTempBasalAbsolute(absoluteValue, durationInMinutes, profile, enforceNew, tbrType)
}
}
@ -870,7 +885,8 @@ class MedtronicPumpPlugin @Inject constructor(
scheduleNextRefresh(MedtronicStatusRefreshType.PumpTime, -1)
}
if (medtronicPumpStatus.basalProfileStatus !== BasalProfileStatus.NotInitialized
&& medtronicHistoryData.hasBasalProfileChanged()) {
&& medtronicHistoryData.hasBasalProfileChanged()
) {
medtronicHistoryData.processLastBasalProfileChange(pumpDescription.pumpType, medtronicPumpStatus)
}
val previousState = pumpState
@ -890,7 +906,7 @@ class MedtronicPumpPlugin @Inject constructor(
private fun readPumpHistoryLogic() {
val debugHistory = false
var targetDate: LocalDateTime? = null
val targetDate: LocalDateTime?
if (lastPumpHistoryEntry == null) { // first read
if (debugHistory) aapsLogger.debug(LTag.PUMP, logPrefix + "readPumpHistoryLogic(): lastPumpHistoryEntry: null")
val lastPumpHistoryEntryTime = lastPumpEntryTime
@ -898,13 +914,11 @@ class MedtronicPumpPlugin @Inject constructor(
timeMinus36h = timeMinus36h.minusHours(36)
medtronicHistoryData.setIsInInit(true)
if (lastPumpHistoryEntryTime == 0L) {
if (debugHistory) aapsLogger.debug(
LTag.PUMP, logPrefix + "readPumpHistoryLogic(): lastPumpHistoryEntryTime: 0L - targetDate: "
+ targetDate)
if (debugHistory) aapsLogger.debug(LTag.PUMP, logPrefix + "readPumpHistoryLogic(): lastPumpHistoryEntryTime: 0L")
targetDate = timeMinus36h
} else {
// LocalDateTime lastHistoryRecordTime = DateTimeUtil.toLocalDateTime(lastPumpHistoryEntryTime);
if (debugHistory) aapsLogger.debug(LTag.PUMP, logPrefix + "readPumpHistoryLogic(): lastPumpHistoryEntryTime: " + lastPumpHistoryEntryTime + " - targetDate: " + targetDate)
if (debugHistory) aapsLogger.debug(LTag.PUMP, logPrefix + "readPumpHistoryLogic(): lastPumpHistoryEntryTime: " + lastPumpHistoryEntryTime)
//medtronicHistoryData.setLastHistoryRecordTime(lastPumpHistoryEntryTime)
var lastHistoryRecordTime = DateTimeUtil.toLocalDateTime(lastPumpHistoryEntryTime)
lastHistoryRecordTime = lastHistoryRecordTime.minusHours(12) // we get last 12 hours of history to
@ -922,8 +936,10 @@ class MedtronicPumpPlugin @Inject constructor(
//aapsLogger.debug(LTag.PUMP, "HST: Target Date: " + targetDate);
@Suppress("UNCHECKED_CAST")
val responseTask2 = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(MedtronicCommandType.GetHistoryData,
arrayListOf(/*lastPumpHistoryEntry*/ null, targetDate) as? ArrayList<Any>?)
val responseTask2 = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(
MedtronicCommandType.GetHistoryData,
arrayListOf(/*lastPumpHistoryEntry*/ null, targetDate) as? ArrayList<Any>?
)
if (debugHistory) aapsLogger.debug(LTag.PUMP, "HST: After task")
val historyResult = responseTask2?.result as PumpHistoryResult?
if (debugHistory) aapsLogger.debug(LTag.PUMP, "HST: History Result: " + historyResult.toString())
@ -981,8 +997,10 @@ class MedtronicPumpPlugin @Inject constructor(
}
MedtronicStatusRefreshType.PumpTime, MedtronicStatusRefreshType.Configuration, MedtronicStatusRefreshType.BatteryStatus, MedtronicStatusRefreshType.PumpHistory -> {
workWithStatusRefresh(StatusRefreshAction.Add, refreshType,
getTimeInFutureFromMinutes(refreshType.refreshTime + additionalTimeInMinutes))
workWithStatusRefresh(
StatusRefreshAction.Add, refreshType,
getTimeInFutureFromMinutes(refreshType.refreshTime + additionalTimeInMinutes)
)
}
}
}
@ -993,9 +1011,11 @@ class MedtronicPumpPlugin @Inject constructor(
}
@Synchronized
private fun workWithStatusRefresh(action: StatusRefreshAction, //
statusRefreshType: MedtronicStatusRefreshType?, //
time: Long?): Map<MedtronicStatusRefreshType, Long>? {
private fun workWithStatusRefresh(
action: StatusRefreshAction, //
statusRefreshType: MedtronicStatusRefreshType?, //
time: Long?
): Map<MedtronicStatusRefreshType, Long>? {
return when (action) {
StatusRefreshAction.Add -> {
statusRefreshMap[statusRefreshType!!] = time!!
@ -1086,14 +1106,16 @@ class MedtronicPumpPlugin @Inject constructor(
runningTBR.tbrType,
runningTBR.pumpId!!,
runningTBR.pumpType,
runningTBR.serialNumber)
runningTBR.serialNumber
)
val differenceTimeMin = floor(differenceTime / (60.0 * 1000.0))
aapsLogger.debug(
LTag.PUMP, "canceling running TBR - syncTemporaryBasalWithPumpId [date=${runningTBR.date}, " +
"pumpId=${runningTBR.pumpId}, rate=${runningTBR.rate} U, duration=${differenceTimeMin.toInt()}, " +
"pumpSerial=${medtronicPumpStatus.serialNumber}] - Result: $result")
"pumpId=${runningTBR.pumpId}, rate=${runningTBR.rate} U, duration=${differenceTimeMin.toInt()}, " +
"pumpSerial=${medtronicPumpStatus.serialNumber}] - Result: $result"
)
}
}
@ -1145,8 +1167,10 @@ class MedtronicPumpPlugin @Inject constructor(
.enacted(false) //
.comment(rh.gs(R.string.medtronic_cmd_set_profile_pattern_overflow, profileInvalid))
}
val responseTask = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(MedtronicCommandType.SetBasalProfileSTD,
arrayListOf(basalProfile))
val responseTask = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(
MedtronicCommandType.SetBasalProfileSTD,
arrayListOf(basalProfile)
)
val response = responseTask?.result as Boolean?
aapsLogger.info(LTag.PUMP, logPrefix + "Basal Profile was set: " + response)
return if (response == null || !response) {
@ -1184,18 +1208,24 @@ class MedtronicPumpPlugin @Inject constructor(
// OPERATIONS not supported by Pump or Plugin
private var customActions: List<CustomAction>? = null
private val customActionWakeUpAndTune = CustomAction(R.string.medtronic_custom_action_wake_and_tune,
MedtronicCustomActionType.WakeUpAndTune)
private val customActionWakeUpAndTune = CustomAction(
R.string.medtronic_custom_action_wake_and_tune,
MedtronicCustomActionType.WakeUpAndTune
)
private val customActionClearBolusBlock = CustomAction(
R.string.medtronic_custom_action_clear_bolus_block, MedtronicCustomActionType.ClearBolusBlock, false)
R.string.medtronic_custom_action_clear_bolus_block, MedtronicCustomActionType.ClearBolusBlock, false
)
private val customActionResetRLConfig = CustomAction(
R.string.medtronic_custom_action_reset_rileylink, MedtronicCustomActionType.ResetRileyLinkConfiguration, true)
R.string.medtronic_custom_action_reset_rileylink, MedtronicCustomActionType.ResetRileyLinkConfiguration, true
)
override fun getCustomActions(): List<CustomAction>? {
if (customActions == null) {
customActions = listOf(customActionWakeUpAndTune, //
customActions = listOf(
customActionWakeUpAndTune, //
customActionClearBolusBlock, //
customActionResetRLConfig)
customActionResetRLConfig
)
}
return customActions
}

View file

@ -4,10 +4,8 @@ import android.content.Intent
import android.content.res.Configuration
import android.os.Binder
import android.os.IBinder
import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkEncodingType
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkTargetFrequency
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice
@ -21,6 +19,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceTyp
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
import info.nightscout.shared.logging.LTag
import javax.inject.Inject
import javax.inject.Singleton
@ -33,7 +32,6 @@ class RileyLinkMedtronicService : RileyLinkService() {
@Inject lateinit var medtronicPumpPlugin: MedtronicPumpPlugin
@Inject lateinit var medtronicUtil: MedtronicUtil
@Inject lateinit var medtronicPumpStatus: MedtronicPumpStatus
@Inject lateinit var rfSpy: RFSpy
@Inject lateinit var medtronicCommunicationManager: MedtronicCommunicationManager
@Inject lateinit var medtronicUIComm: MedtronicUIComm
@ -79,7 +77,7 @@ class RileyLinkMedtronicService : RileyLinkService() {
// get most recently used RileyLink address and name
rileyLinkServiceData.rileyLinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "")
rileyLinkServiceData.rileyLinkName = sp.getString(RileyLinkConst.Prefs.RileyLinkName, "")
rfspy.startReader()
rfSpy.startReader()
aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkMedtronicService newly constructed")
}

View file

@ -2,34 +2,21 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm
import android.util.Log
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil
import org.mockito.Mock
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.AAPSLoggerTest
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder
import kotlin.Throws
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RawHistoryPage
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntryType
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.TempBasalProcessDTO
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
import info.nightscout.androidaps.utils.rx.TestAapsSchedulers
import info.nightscout.androidaps.utils.serialisation.SealedClassHelper.gson
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers
import org.mockito.Mockito
import org.mockito.MockitoAnnotations
import java.lang.Exception
//import uk.org.lidalia.slf4jtest.TestLogger;
//import uk.org.lidalia.slf4jtest.TestLoggerFactory;
@ -44,50 +31,30 @@ class MedtronicHistoryDataUTest : TestBase() {
// "16 00 12 EC 14 47 13 33 00 14 F2 14 47 13 00 16 01 14 F2 14 47 13 33 00 1C C9 15 47 13 00 16 00 1C C9 15 47 13 33 4E 31 D3 15 47 13 00 16 01 31 D3 15 47 13 33 00 1A F1 15 47 13 00 16 00 1A F1 15 47 13 33 50 1D F1 15 47 13 00 16 01 1D F1 15 47 13 33 50 11 D8 16 47 13 00 16 01 11 D8 16 47 13 33 50 31 FB 16 47 13 00 16 01 31 FB 16 47 13 33 50 12 E3 17 47 13 00 16 01 12 E3 17 47 13 33 00 1E FB 17 47 13 00 16 00 1E FB 17 47 13 33 D8 21 FB 17 47 13 00 16 01 21 FB 17 47 13 07 00 00 05 CC 27 93 6D 27 93 05 0C 00 E8 00 00 00 00 05 CC 05 CC 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0C 00 E8 00 00 00 33 00 36 C4 00 48 13 00 16 00 36 C4 00 48 13 33 D8 29 C9 00 48 13 00 16 01 29 C9 00 48 13 33 00 12 E7 00 48 13 00 16 00 12 E7 00 48 13 33 BC 19 C9 01 48 13 00 16 01 19 C9 01 48 13 33 00 26 CE 01 48 13 00 16 00 26 CE 01 48 13 33 44 29 CE 01 48 13 00 16 01 29 CE 01 48 13 33 00 13 D3 01 48 13 00 16 00 13 D3 01 48 13 33 64 31 F1 01 48 13 00 16 01 31 F1 01 48 13 33 00 0B F7 01 48 13 00 16 00 0B F7 01 48 13 33 00 12 D8 02 48 13 00 16 01 12 D8 02 48 13 33 00 10 F1 02 48 13 00 16 00 10 F1 02 48 13 33 00 30 C4 03 48 13 00 16 01 30 C4 03 48 13 33 00 04 CA 03 48 13 00 16 00 04 CA 03 48 13 33 00 2F D3 03 48 13 00 16 01 2F D3 03 48 13 33 00 30 D8 03 48 13 00 16 00 30 D8 03 48 13 33 00 13 E7 03 48 13 00 16 01 13 E7 03 48 13 33 00 2E FB 03 48 13 00 16 00 2E FB 03 48 13 19 00 00 C1 04 08 13 07 00 00 04 0C 28 93 6D 28 93 05 0C 00 E8 00 00 00 00 04 0C 04 0C 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0C 00 E8 00 00 00 06 3E 03 7A 19 DC 48 49 13 0C 3E 0C E6 08 09 13 07 00 00 01 E4 29 93 6D 29 93 05 0C 00 E8 00 00 00 00 01 E4 01 E4 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0C 00 E8 00 00 00 1A 00 13 D2 0D 0A 13 1A 01 28 D2 0D 0A 13 21 00 2A D8 0D 0A 13 03 00 00 00 0E 2D D9 2D 0A 13 33 98 26 DE 0D 4A 13 00 16 01 26 DE 0D 4A 13 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5D 70"
// )
//lateinit var rxBus: RxBus
lateinit var medtronicHistoryData: MedtronicHistoryData
lateinit var medtronicPumpStatus : MedtronicPumpStatus
lateinit var medtronicPumpStatus: MedtronicPumpStatus
@Before
fun setup() {
MockitoAnnotations.initMocks(this)
rxBus = RxBus(TestAapsSchedulers(), aapsLogger)
medtronicPumpStatus = MedtronicPumpStatus(
rh, sp, rxBus,
rileyLinkUtil
medtronicPumpStatus = MedtronicPumpStatus(rh, sp, rxBus, rileyLinkUtil)
medtronicUtil = MedtronicUtil(aapsLogger, rxBus, rileyLinkUtil, medtronicPumpStatus)
decoder = MedtronicPumpHistoryDecoder(aapsLogger, medtronicUtil, byteUtil)
medtronicHistoryData = MedtronicHistoryData(
packetInjector, aapsLogger, sp, rh, rxBus, activePlugin,
medtronicUtil, decoder, medtronicPumpStatus, pumpSync, pumpSyncStorage
)
medtronicUtil = MedtronicUtil(
aapsLogger, rxBus, rileyLinkUtil,
medtronicPumpStatus
)
decoder = MedtronicPumpHistoryDecoder(
aapsLogger,
medtronicUtil, byteUtil
)
medtronicHistoryData = MedtronicHistoryData(packetInjector, aapsLogger, sp, rh, rxBus, activePlugin,
medtronicUtil, decoder,
medtronicPumpStatus,
pumpSync,
pumpSyncStorage)
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "trace")
}
//@Test
@Throws(Exception::class) fun testTBR() {
var historyPageData = ByteUtil
val historyPageData = ByteUtil
.createByteArrayFromString(
"16 00 12 EC 14 47 13 33 00 14 F2 14 47 13 00 16 01 14 F2 14 47 13 33 00 1C C9 15 47 13 00 16 00 1C C9 15 47 13 33 4E 31 D3 15 47 13 00 16 01 31 D3 15 47 13 33 00 1A F1 15 47 13 00 16 00 1A F1 15 47 13 33 50 1D F1 15 47 13 00 16 01 1D F1 15 47 13 33 50 11 D8 16 47 13 00 16 01 11 D8 16 47 13 33 50 31 FB 16 47 13 00 16 01 31 FB 16 47 13 33 50 12 E3 17 47 13 00 16 01 12 E3 17 47 13 33 00 1E FB 17 47 13 00 16 00 1E FB 17 47 13 33 D8 21 FB 17 47 13 00 16 01 21 FB 17 47 13 07 00 00 05 CC 27 93 6D 27 93 05 0C 00 E8 00 00 00 00 05 CC 05 CC 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0C 00 E8 00 00 00 33 00 36 C4 00 48 13 00 16 00 36 C4 00 48 13 33 D8 29 C9 00 48 13 00 16 01 29 C9 00 48 13 33 00 12 E7 00 48 13 00 16 00 12 E7 00 48 13 33 BC 19 C9 01 48 13 00 16 01 19 C9 01 48 13 33 00 26 CE 01 48 13 00 16 00 26 CE 01 48 13 33 44 29 CE 01 48 13 00 16 01 29 CE 01 48 13 33 00 13 D3 01 48 13 00 16 00 13 D3 01 48 13 33 64 31 F1 01 48 13 00 16 01 31 F1 01 48 13 33 00 0B F7 01 48 13 00 16 00 0B F7 01 48 13 33 00 12 D8 02 48 13 00 16 01 12 D8 02 48 13 33 00 10 F1 02 48 13 00 16 00 10 F1 02 48 13 33 00 30 C4 03 48 13 00 16 01 30 C4 03 48 13 33 00 04 CA 03 48 13 00 16 00 04 CA 03 48 13 33 00 2F D3 03 48 13 00 16 01 2F D3 03 48 13 33 00 30 D8 03 48 13 00 16 00 30 D8 03 48 13 33 00 13 E7 03 48 13 00 16 01 13 E7 03 48 13 33 00 2E FB 03 48 13 00 16 00 2E FB 03 48 13 19 00 00 C1 04 08 13 07 00 00 04 0C 28 93 6D 28 93 05 0C 00 E8 00 00 00 00 04 0C 04 0C 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0C 00 E8 00 00 00 06 3E 03 7A 19 DC 48 49 13 0C 3E 0C E6 08 09 13 07 00 00 01 E4 29 93 6D 29 93 05 0C 00 E8 00 00 00 00 01 E4 01 E4 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0C 00 E8 00 00 00 1A 00 13 D2 0D 0A 13 1A 01 28 D2 0D 0A 13 21 00 2A D8 0D 0A 13 03 00 00 00 0E 2D D9 2D 0A 13 33 98 26 DE 0D 4A 13 00 16 01 26 DE 0D 4A 13 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5D 70"
)
@ -141,10 +108,10 @@ class MedtronicHistoryDataUTest : TestBase() {
.createByteArrayFromString(
"33 20 53 78 15 51 16 00 16 01 53 78 15 51 16 33 00 6F 40 16 51 16 00 16 00 6F 40 16 51 16 7B 16 6F 40 16 11 16 2C 1E 00 33 30 71 40 16 51 16 00 16 01 71 40 16 51 16 33 00 6E 45 16 51 16 00 16 00 6E 45 16 51 16 7B 16 6E 45 16 11 16 2C 1E 00 33 3A 70 45 16 51 16 00 16 01 70 45 16 51 16 33 00 71 5E 16 51 16 00 16 00 71 5E 16 51 16 7B 16 71 5E 16 11 16 2C 1E 00 33 40 73 5E 16 51 16 00 16 01 73 5E 16 51 16 33 00 74 6D 16 51 16 00 16 00 74 6D 16 51 16 7B 16 74 6D 16 11 16 2C 1E 00 33 14 76 6D 16 51 16 00 16 01 76 6D 16 51 16 33 00 77 72 16 51 16 00 16 00 77 72 16 51 16 7B 16 77 72 16 11 16 2C 1E 00 7B 17 40 40 17 11 16 2E 1E 00 33 28 51 41 17 51 16 00 16 01 51 41 17 51 16 33 00 56 46 17 51 16 00 16 00 56 46 17 51 16 7B 17 56 46 17 11 16 2E 1E 00 33 34 59 46 17 51 16 00 16 01 59 46 17 51 16 33 00 70 4A 17 51 16 00 16 00 70 4A 17 51 16 7B 17 70 4A 17 11 16 2E 1E 00 33 58 72 4A 17 51 16 00 16 01 72 4A 17 51 16 33 00 6E 59 17 51 16 00 16 00 6E 59 17 51 16 7B 17 6E 59 17 11 16 2E 1E 00 33 18 70 59 17 51 16 00 16 01 70 59 17 51 16 33 00 70 5E 17 51 16 00 16 00 70 5E 17 51 16 7B 17 70 5E 17 11 16 2E 1E 00 33 0C 72 5E 17 51 16 00 16 01 72 5E 17 51 16 33 00 72 63 17 51 16 00 16 00 72 63 17 51 16 7B 17 72 63 17 11 16 2E 1E 00 33 1C 70 72 17 51 16 00 16 01 70 72 17 51 16 33 00 51 78 17 51 16 00 16 00 51 78 17 51 16 7B 17 52 78 17 11 16 2E 1E 00 33 12 54 78 17 51 16 00 16 01 54 78 17 51 16 07 00 00 04 4E 51 96 00 00 00 6E 51 96 05 00 00 00 00 00 00 00 04 4E 03 A2 54 00 AC 10 00 00 00 00 00 00 00 00 00 AC 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 33 00 46 46 00 52 16 00 16 00 46 46 00 52 16 7B 00 47 46 00 12 16 00 1E 00 33 20 47 64 00 52 16 00 16 01 47 64 00 52 16 33 00 6D 77 00 52 16 00 16 00 6D 77 00 52 16 7B 00 6D 77 00 12 16 00 1E 00 33 12 70 77 00 52 16 00 16 01 70 77 00 52 16 33 00 58 78 00 52 16 00 16 00 58 78 00 52 16 7B 00 59 78 00 12 16 00 1E 00 33 00 5C 78 00 52 16 00 16 02 5C 78 00 52 16 21 00 66 79 00 12 16 03 00 00 00 9C 74 42 21 12 16 03 00 03 00 03 6E 4D 01 12 16 33 00 79 4E 01 52 16 00 16 00 79 4E 01 52 16 7B 01 79 4E 01 12 16 02 1E 00 33 2A 6B 4F 01 52 16 00 16 01 6B 4F 01 52 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2E D1"
//"33 20 53 78 15 51 16 00 16 01 53 78 15 51 16 33 00 6F 40 16 51 16 00 16 00 6F 40 16 51 16 7B 16 6F 40 16 11 16 2C 1E 00 33 30 71 40 16 51 16 00 16 01 71 40 16 51 16 33 00 6E 45
// 16 51 16 00 16 00 6E 45 16 51 16 7B 16 6E 45 16 11 16 2C 1E 00 33 3A 70 45 16 51 16 00 16 01 70 45 16 51 16 33 00 71 5E 16 51 16 00 16 00 71 5E 16 51 16 7B 16 71 5E 16 11 16 2C 1E 00 33 40 73 5E 16 51 16 00 16 01 73 5E 16 51 16 33 00 74 6D 16 51 16 00 16 00 74 6D 16 51 16 7B 16 74 6D 16 11 16 2C 1E 00 33 14 76 6D 16 51 16 00 16 01 76 6D 16 51 16 33 00 77 72 16 51 16 00 16 00 77 72 16 51 16 7B 16 77 72 16 11 16 2C 1E 00 7B 17 40 40 17 11 16 2E 1E 00 33 28 51 41 17 51 16 00 16 01 51 41 17 51 16 33 00 56 46 17 51 16 00 16 00 56 46 17 51 16 7B 17 56 46 17 11 16 2E 1E 00 33 34 59 46 17 51 16 00 16 01 59 46 17 51 16 33 00 70 4A 17 51 16 00 16 00 70 4A 17 51 16 7B 17 70 4A 17 11 16 2E 1E 00 33 58 72 4A 17 51 16 00 16 01 72 4A 17 51 16 33 00 6E 59 17 51 16 00 16 00 6E 59 17 51 16 7B 17 6E 59 17 11 16 2E 1E 00 33 18 70 59 17 51 16 00 16 01 70 59 17 51 16 33 00 70 5E 17 51 16 00 16 00 70 5E 17 51 16 7B 17 70 5E 17 11 16 2E 1E 00 33 0C 72 5E 17 51 16 00 16 01 72 5E 17 51 16 33 00 72 63 17 51 16 00 16 00 72 63 17 51 16 7B 17 72 63 17 11 16 2E 1E 00 33 1C 70 72 17 51 16 00 16 01 70 72 17 51 16 33 00 51 78 17 51 16 00 16 00 51 78 17 51 16 7B 17 52 78 17 11 16 2E 1E 00 33 12 54 78 17 51 16 00 16 01 54 78 17 51 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4D 6D"
// 16 51 16 00 16 00 6E 45 16 51 16 7B 16 6E 45 16 11 16 2C 1E 00 33 3A 70 45 16 51 16 00 16 01 70 45 16 51 16 33 00 71 5E 16 51 16 00 16 00 71 5E 16 51 16 7B 16 71 5E 16 11 16 2C 1E 00 33 40 73 5E 16 51 16 00 16 01 73 5E 16 51 16 33 00 74 6D 16 51 16 00 16 00 74 6D 16 51 16 7B 16 74 6D 16 11 16 2C 1E 00 33 14 76 6D 16 51 16 00 16 01 76 6D 16 51 16 33 00 77 72 16 51 16 00 16 00 77 72 16 51 16 7B 16 77 72 16 11 16 2C 1E 00 7B 17 40 40 17 11 16 2E 1E 00 33 28 51 41 17 51 16 00 16 01 51 41 17 51 16 33 00 56 46 17 51 16 00 16 00 56 46 17 51 16 7B 17 56 46 17 11 16 2E 1E 00 33 34 59 46 17 51 16 00 16 01 59 46 17 51 16 33 00 70 4A 17 51 16 00 16 00 70 4A 17 51 16 7B 17 70 4A 17 11 16 2E 1E 00 33 58 72 4A 17 51 16 00 16 01 72 4A 17 51 16 33 00 6E 59 17 51 16 00 16 00 6E 59 17 51 16 7B 17 6E 59 17 11 16 2E 1E 00 33 18 70 59 17 51 16 00 16 01 70 59 17 51 16 33 00 70 5E 17 51 16 00 16 00 70 5E 17 51 16 7B 17 70 5E 17 11 16 2E 1E 00 33 0C 72 5E 17 51 16 00 16 01 72 5E 17 51 16 33 00 72 63 17 51 16 00 16 00 72 63 17 51 16 7B 17 72 63 17 11 16 2E 1E 00 33 1C 70 72 17 51 16 00 16 01 70 72 17 51 16 33 00 51 78 17 51 16 00 16 00 51 78 17 51 16 7B 17 52 78 17 11 16 2E 1E 00 33 12 54 78 17 51 16 00 16 01 54 78 17 51 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4D 6D"
)
medtronicUtil.medtronicPumpModel =MedtronicDeviceType.Medtronic_723_Revel
medtronicUtil.medtronicPumpModel = MedtronicDeviceType.Medtronic_723_Revel
medtronicUtil.isModelSet = true
val historyPage = RawHistoryPage(aapsLogger)
@ -152,7 +119,7 @@ class MedtronicHistoryDataUTest : TestBase() {
val pumpHistoryEntries: MutableList<PumpHistoryEntry> = decoder.processPageAndCreateRecords(historyPage)
println("PumpHistoryEntries: " + pumpHistoryEntries.size)
val rewindRecords: MutableList<PumpHistoryEntry> = medtronicHistoryData.getFilteredItems(pumpHistoryEntries, PumpHistoryEntryType.Rewind)
val rewindRecords: MutableList<PumpHistoryEntry> = medtronicHistoryData.getFilteredItems(pumpHistoryEntries, PumpHistoryEntryType.Rewind)
preProcessListTBR(pumpHistoryEntries)
@ -172,7 +139,7 @@ class MedtronicHistoryDataUTest : TestBase() {
println("PumpHistoryEntries: getFilteredItems: " + tbrs.size)
println("PumpHistoryEntries: getRewindItems: $rewindRecords.size : " + gson.toJson(rewindRecords) )
println("PumpHistoryEntries: getRewindItems: $rewindRecords.size : " + gson.toJson(rewindRecords))
val processList: MutableList<TempBasalProcessDTO> = medtronicHistoryData.createTBRProcessList(tbrs, rewindRecords)

View file

@ -2,19 +2,14 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump
//import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RawHistoryPage
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
import info.nightscout.androidaps.utils.rx.TestAapsSchedulers
import org.junit.Assert
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.mockito.Mock
/**
* Created by andy on 11/1/18.
@ -28,17 +23,17 @@ class MedtronicPumpHistoryDecoderUTest : TestBase() {
//@Mock lateinit var rileyLinkUtil: RileyLinkUtil
//@Mock lateinit var sp: SP
private var medtronicPumpStatus: MedtronicPumpStatus? = null
private lateinit var medtronicPumpStatus: MedtronicPumpStatus
//private var medtronicUtil: MedtronicUtil? = null
//private var decoder: MedtronicPumpHistoryDecoder? = null
var rxBusWrapper = RxBus(TestAapsSchedulers(), aapsLogger)
@Before fun setup() {
medtronicPumpStatus =
MedtronicPumpStatus(rh, sp, rxBusWrapper, rileyLinkUtil)
MedtronicPumpStatus(rh, sp, rxBus, rileyLinkUtil)
medtronicUtil =
MedtronicUtil(aapsLogger, rxBusWrapper, rileyLinkUtil, medtronicPumpStatus!!)
decoder = MedtronicPumpHistoryDecoder(aapsLogger, medtronicUtil!!, ByteUtil())
MedtronicUtil(aapsLogger, rxBus, rileyLinkUtil, medtronicPumpStatus)
decoder = MedtronicPumpHistoryDecoder(aapsLogger, medtronicUtil, ByteUtil())
}
/*
@ -191,12 +186,11 @@ class MedtronicPumpHistoryDecoderUTest : TestBase() {
): List<PumpHistoryEntry> {
val historyPageData = ByteUtil.createByteArrayFromString(historyPageString)
aapsLogger.debug("History Page Length:" + historyPageData.size)
medtronicUtil!!.medtronicPumpModel = medtronicDeviceType
medtronicUtil!!.isModelSet = true
medtronicUtil.medtronicPumpModel = medtronicDeviceType
medtronicUtil.isModelSet = true
val historyPage = RawHistoryPage(aapsLogger)
historyPage.appendData(historyPageData)
val pumpHistoryEntries: List<PumpHistoryEntry> =
decoder!!.processPageAndCreateRecords(historyPage)
val pumpHistoryEntries: List<PumpHistoryEntry> = decoder.processPageAndCreateRecords(historyPage)
displayHistoryRecords(pumpHistoryEntries)
return pumpHistoryEntries
}

View file

@ -1,70 +1,37 @@
package info.nightscout.androidaps.plugins.pump.medtronic.data
import java.lang.reflect.Type
import com.google.gson.reflect.TypeToken
import com.google.gson.Gson
import com.google.gson.internal.LinkedTreeMap
// import dagger.android.AndroidInjector
// import dagger.android.HasAndroidInjector
import com.google.gson.reflect.TypeToken
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.TempBasalPair
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.mockito.Mock
import java.lang.reflect.Type
@Suppress("UNCHECKED_CAST")
@Suppress("UNCHECKED_CAST")
class MedtronicHistoryDataUTest : TestBase() {
//@Mock lateinit var activePlugin: ActivePlugin
//@Mock lateinit var medtronicUtil: MedtronicUtil
//@Mock lateinit var medtronicPumpHistoryDecoder: MedtronicPumpHistoryDecoder
@Mock lateinit var medtronicPumpStatus: MedtronicPumpStatus
// @Mock lateinit var pumpSync: PumpSync
// @Mock lateinit var pumpSyncStorage: PumpSyncStorage
//@Mock lateinit var rxBus: RxBus
// val packetInjector = HasAndroidInjector {
// AndroidInjector {
//
// }
// }
@Before
fun setUp() {
medtronicUtil = MedtronicUtil(
aapsLogger, rxBus, rileyLinkUtil,
medtronicPumpStatus
)
decoder = MedtronicPumpHistoryDecoder(
aapsLogger,
medtronicUtil, byteUtil
)
medtronicUtil = MedtronicUtil(aapsLogger, rxBus, rileyLinkUtil, medtronicPumpStatus)
decoder = MedtronicPumpHistoryDecoder(aapsLogger, medtronicUtil, byteUtil)
}
@Test
fun createTBRProcessList() {
var unitToTest = MedtronicHistoryData(packetInjector, aapsLogger, sp, rh, rxBus, activePlugin,
medtronicUtil, decoder,
medtronicPumpStatus,
pumpSync,
pumpSyncStorage)
val unitToTest = MedtronicHistoryData(
packetInjector, aapsLogger, sp, rh, rxBus, activePlugin,
medtronicUtil, decoder, medtronicPumpStatus, pumpSync, pumpSyncStorage
)
val gson = Gson()
@ -74,26 +41,26 @@ class MedtronicHistoryDataUTest : TestBase() {
val yourClassList: MutableList<PumpHistoryEntry> = gson.fromJson(fileText, listType)
for (pumpHistoryEntry in yourClassList) {
val stringObject = pumpHistoryEntry.decodedData["Object"] as LinkedTreeMap<String,Object>
val stringObject = pumpHistoryEntry.decodedData["Object"] as LinkedTreeMap<String, Any>
val rate : Double = stringObject.get("insulinRate") as Double
val durationMinutes: Double = stringObject.get("durationMinutes") as Double
val durationMinutesInt : Int = durationMinutes.toInt()
val rate: Double = stringObject["insulinRate"] as Double
val durationMinutes: Double = stringObject["durationMinutes"] as Double
val durationMinutesInt: Int = durationMinutes.toInt()
var tmbPair = TempBasalPair(rate, false, durationMinutesInt)
val tmbPair = TempBasalPair(rate, false, durationMinutesInt)
pumpHistoryEntry.decodedData.remove("Object")
pumpHistoryEntry.addDecodedData("Object", tmbPair)
}
System.out.println("TBR Pre-Process List: " + gson.toJson(yourClassList))
println("TBR Pre-Process List: " + gson.toJson(yourClassList))
val createTBRProcessList = unitToTest.createTBRProcessList(yourClassList, mutableListOf())
System.out.println("TBR Process List: " + createTBRProcessList.size)
println("TBR Process List: " + createTBRProcessList.size)
for (tempBasalProcessDTO in createTBRProcessList) {
System.out.println(tempBasalProcessDTO.toTreatmentString())
println(tempBasalProcessDTO.toTreatmentString())
}
}
@ -101,11 +68,13 @@ class MedtronicHistoryDataUTest : TestBase() {
@Test
fun createTBRProcessList_SpecialCase() {
var unitToTest = MedtronicHistoryData(packetInjector, aapsLogger, sp, rh, rxBus, activePlugin,
medtronicUtil, decoder,
medtronicPumpStatus,
pumpSync,
pumpSyncStorage)
val unitToTest = MedtronicHistoryData(
packetInjector, aapsLogger, sp, rh, rxBus, activePlugin,
medtronicUtil, decoder,
medtronicPumpStatus,
pumpSync,
pumpSyncStorage
)
val gson = Gson()
@ -115,26 +84,26 @@ class MedtronicHistoryDataUTest : TestBase() {
val yourClassList: MutableList<PumpHistoryEntry> = gson.fromJson(fileText, listType)
for (pumpHistoryEntry in yourClassList) {
val stringObject = pumpHistoryEntry.decodedData["Object"] as LinkedTreeMap<String,Object>
val stringObject = pumpHistoryEntry.decodedData["Object"] as LinkedTreeMap<String, Any>
val rate : Double = stringObject.get("insulinRate") as Double
val durationMinutes: Double = stringObject.get("durationMinutes") as Double
val durationMinutesInt : Int = durationMinutes.toInt()
val rate: Double = stringObject["insulinRate"] as Double
val durationMinutes: Double = stringObject["durationMinutes"] as Double
val durationMinutesInt: Int = durationMinutes.toInt()
var tmbPair = TempBasalPair(rate, false, durationMinutesInt)
val tmbPair = TempBasalPair(rate, false, durationMinutesInt)
pumpHistoryEntry.decodedData.remove("Object")
pumpHistoryEntry.addDecodedData("Object", tmbPair)
}
System.out.println("TBR Pre-Process List (Special): " + gson.toJson(yourClassList))
println("TBR Pre-Process List (Special): " + gson.toJson(yourClassList))
val createTBRProcessList = unitToTest.createTBRProcessList(yourClassList, mutableListOf())
System.out.println("TBR Process List (Special): " + createTBRProcessList.size)
println("TBR Process List (Special): " + createTBRProcessList.size)
for (tempBasalProcessDTO in createTBRProcessList) {
System.out.println(tempBasalProcessDTO.toTreatmentString())
println(tempBasalProcessDTO.toTreatmentString())
}
}

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.pump.omnipod.common.dagger
package info.nightscout.androidaps.plugins.pump.omnipod.common.di
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.pump.omnipod.common.dagger
package info.nightscout.androidaps.plugins.pump.omnipod.common.di
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

View file

@ -5,7 +5,7 @@ import androidx.annotation.IdRes
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModelProvider
import info.nightscout.androidaps.plugins.pump.omnipod.common.R
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.action.InitializePodViewModel
import javax.inject.Inject

View file

@ -5,7 +5,7 @@ import androidx.annotation.IdRes
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModelProvider
import info.nightscout.androidaps.plugins.pump.omnipod.common.R
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.action.InsertCannulaViewModel
import javax.inject.Inject

View file

@ -9,7 +9,7 @@ import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import info.nightscout.androidaps.plugins.pump.omnipod.common.R
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.info.AttachPodViewModel
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.fragment.InfoFragmentBase
import javax.inject.Inject

View file

@ -4,7 +4,7 @@ import android.os.Bundle
import androidx.annotation.IdRes
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModelProvider
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.info.PodActivatedViewModel
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.fragment.InfoFragmentBase
import javax.inject.Inject

View file

@ -5,7 +5,7 @@ import androidx.annotation.IdRes
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModelProvider
import info.nightscout.androidaps.plugins.pump.omnipod.common.R
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.info.StartPodActivationViewModel
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.fragment.InfoFragmentBase
import javax.inject.Inject

View file

@ -9,7 +9,7 @@ import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import info.nightscout.androidaps.plugins.pump.omnipod.common.R
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.fragment.ActionFragmentBase
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.deactivation.viewmodel.action.DeactivatePodViewModel
import javax.inject.Inject

View file

@ -4,7 +4,7 @@ import android.os.Bundle
import androidx.annotation.IdRes
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModelProvider
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.fragment.InfoFragmentBase
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.deactivation.viewmodel.info.PodDeactivatedViewModel
import javax.inject.Inject

View file

@ -4,7 +4,7 @@ import android.os.Bundle
import androidx.annotation.IdRes
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModelProvider
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.fragment.InfoFragmentBase
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.deactivation.viewmodel.info.PodDiscardedViewModel
import javax.inject.Inject

View file

@ -5,7 +5,7 @@ import androidx.annotation.IdRes
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModelProvider
import info.nightscout.androidaps.plugins.pump.omnipod.common.R
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.fragment.InfoFragmentBase
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.deactivation.viewmodel.info.StartPodDeactivationViewModel
import javax.inject.Inject

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.dagger
package info.nightscout.androidaps.plugins.pump.omnipod.dash.di
import android.content.Context
import dagger.Module

View file

@ -1,10 +1,10 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.dagger
package info.nightscout.androidaps.plugins.pump.omnipod.dash.di
import dagger.Binds
import dagger.Module
import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.ActivityScope
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.OmnipodWizardModule
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.ActivityScope
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.OmnipodWizardModule
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManagerImpl
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.OmnipodDashBleManager

View file

@ -1,11 +1,11 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.dagger
package info.nightscout.androidaps.plugins.pump.omnipod.dash.di
import androidx.lifecycle.ViewModel
import dagger.Binds
import dagger.Module
import dagger.multibindings.IntoMap
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.ViewModelKey
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.ViewModelKey
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.action.InitializePodViewModel
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.action.InsertCannulaViewModel
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.info.AttachPodViewModel

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.dagger
package info.nightscout.androidaps.plugins.pump.omnipod.eros.di
import android.content.Context
import dagger.Module

View file

@ -1,10 +1,10 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.dagger
package info.nightscout.androidaps.plugins.pump.omnipod.eros.di
import dagger.Module
import dagger.Provides
import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.ActivityScope
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.OmnipodWizardModule
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.ActivityScope
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.OmnipodWizardModule
import info.nightscout.androidaps.plugins.pump.omnipod.eros.data.RLHistoryItemOmnipod
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.manager.ErosPodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsErosPodStateManager

View file

@ -1,11 +1,11 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.dagger
package info.nightscout.androidaps.plugins.pump.omnipod.eros.di
import androidx.lifecycle.ViewModel
import dagger.Binds
import dagger.Module
import dagger.multibindings.IntoMap
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.dagger.ViewModelKey
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.OmnipodPluginQualifier
import info.nightscout.androidaps.plugins.pump.omnipod.common.di.ViewModelKey
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.action.InitializePodViewModel
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.action.InsertCannulaViewModel
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.info.AttachPodViewModel

View file

@ -69,7 +69,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
rileyLinkServiceData.rileyLinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
rileyLinkServiceData.rileyLinkName = sp.getString(RileyLinkConst.Prefs.RileyLinkName, "");
rfspy.startReader();
rfSpy.startReader();
aapsLogger.debug(LTag.PUMPBTCOMM, "RileyLinkOmnipodService newly constructed");
}

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.ui
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.os.Handler
import android.os.HandlerThread
@ -15,6 +14,7 @@ import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.events.EventPreferenceChange
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.CommandQueue
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
@ -48,10 +48,9 @@ import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.protection.ProtectionCheck
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.androidaps.utils.ui.UIRunnable
import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.kotlin.plusAssign
import org.apache.commons.lang3.StringUtils
@ -59,7 +58,6 @@ import org.joda.time.DateTime
import org.joda.time.Duration
import java.util.*
import javax.inject.Inject
import kotlin.collections.ArrayList
class OmnipodErosOverviewFragment : DaggerFragment() {
companion object {
@ -96,17 +94,17 @@ class OmnipodErosOverviewFragment : DaggerFragment() {
}
}
var _binding: OmnipodErosOverviewBinding? = null
var _rileyLinkStatusBinding: OmnipodErosOverviewRileyLinkStatusBinding? = null
var _podInfoBinding: OmnipodCommonOverviewPodInfoBinding? = null
var _buttonBinding: OmnipodCommonOverviewButtonsBinding? = null
private var _binding: OmnipodErosOverviewBinding? = null
private var _rileyLinkStatusBinding: OmnipodErosOverviewRileyLinkStatusBinding? = null
private var _podInfoBinding: OmnipodCommonOverviewPodInfoBinding? = null
private var _buttonBinding: OmnipodCommonOverviewButtonsBinding? = null
// These properties are only valid between onCreateView and
// onDestroyView.
val binding get() = _binding!!
val rileyLinkStatusBinding get() = _rileyLinkStatusBinding!!
val podInfoBinding get() = _podInfoBinding!!
val buttonBinding get() = _buttonBinding!!
private val binding get() = _binding!!
private val rileyLinkStatusBinding get() = _rileyLinkStatusBinding!!
private val podInfoBinding get() = _podInfoBinding!!
private val buttonBinding get() = _buttonBinding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
OmnipodErosOverviewBinding.inflate(inflater, container, false).also {
@ -256,9 +254,9 @@ class OmnipodErosOverviewFragment : DaggerFragment() {
val errors = ArrayList<String>()
if (omnipodErosPumpPlugin.rileyLinkService != null) {
val rileyLinkErrorDescription = omnipodErosPumpPlugin.rileyLinkService.errorDescription
val rileyLinkErrorDescription = omnipodErosPumpPlugin.rileyLinkService?.errorDescription
if (StringUtils.isNotEmpty(rileyLinkErrorDescription)) {
errors.add(rileyLinkErrorDescription)
errors.add(rileyLinkErrorDescription!!)
}
}

View file

@ -2,10 +2,10 @@ package info.nightscout.androidaps.plugin.general.openhumans
import android.annotation.SuppressLint
import android.util.Base64
import info.nightscout.androidaps.plugin.general.openhumans.dagger.BaseUrl
import info.nightscout.androidaps.plugin.general.openhumans.dagger.ClientId
import info.nightscout.androidaps.plugin.general.openhumans.dagger.ClientSecret
import info.nightscout.androidaps.plugin.general.openhumans.dagger.RedirectUrl
import info.nightscout.androidaps.plugin.general.openhumans.di.BaseUrl
import info.nightscout.androidaps.plugin.general.openhumans.di.ClientId
import info.nightscout.androidaps.plugin.general.openhumans.di.ClientSecret
import info.nightscout.androidaps.plugin.general.openhumans.di.RedirectUrl
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.*

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugin.general.openhumans.dagger
package info.nightscout.androidaps.plugin.general.openhumans.di
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugin.general.openhumans.dagger
package info.nightscout.androidaps.plugin.general.openhumans.di
import androidx.lifecycle.ViewModel
import dagger.Binds

View file

@ -17,8 +17,8 @@ import com.google.android.material.appbar.MaterialToolbar
import com.google.android.material.button.MaterialButton
import dagger.android.support.DaggerAppCompatActivity
import info.nightscout.androidaps.plugin.general.openhumans.R
import info.nightscout.androidaps.plugin.general.openhumans.dagger.AuthUrl
import info.nightscout.androidaps.plugin.general.openhumans.dagger.ViewModelFactory
import info.nightscout.androidaps.plugin.general.openhumans.di.AuthUrl
import info.nightscout.androidaps.plugin.general.openhumans.di.ViewModelFactory
import javax.inject.Inject
class OHLoginActivity : DaggerAppCompatActivity() {

View file

@ -87,7 +87,7 @@ class RileyLinkBLEConfigActivity : DaggerAppCompatActivity() {
sp.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress)
sp.putString(RileyLinkConst.Prefs.RileyLinkName, deviceName)
val rileyLinkPump = activePlugin.activePump as RileyLinkPumpDevice
rileyLinkPump.rileyLinkService.verifyConfiguration(true) // force reloading of address to assure that the RL gets reconnected (even if the address didn't change)
rileyLinkPump.rileyLinkService?.verifyConfiguration(true) // force reloading of address to assure that the RL gets reconnected (even if the address didn't change)
rileyLinkPump.triggerPumpConfigurationChangedEvent()
finish()
}

View file

@ -1,18 +0,0 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService;
public interface RileyLinkPumpDevice {
void setBusy(boolean busy);
void triggerPumpConfigurationChangedEvent();
RileyLinkService getRileyLinkService();
RileyLinkPumpInfo getPumpInfo();
long getLastConnectionTimeMillis();
void setLastCommunicationToNow();
}

View file

@ -0,0 +1,13 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService
interface RileyLinkPumpDevice {
fun setBusy(busy: Boolean)
fun triggerPumpConfigurationChangedEvent()
val rileyLinkService: RileyLinkService?
val pumpInfo: RileyLinkPumpInfo
val lastConnectionTimeMillis: Long
fun setLastCommunicationToNow()
}

View file

@ -1,232 +0,0 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service;
/**
* Created by andy on 10/23/18.
*/
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import dagger.android.DaggerBroadcastReceiver;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.interfaces.ActivePlugin;
import info.nightscout.shared.logging.AAPSLogger;
import info.nightscout.shared.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkFirmwareVersion;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.DiscoverGattServicesTask;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.InitializePumpManagerTask;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTask;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask;
import info.nightscout.shared.sharedPreferences.SP;
/**
* I added this class outside of RileyLinkService, because for now it's very important part of RL framework and
* where we get a lot of problems. Especially merging between AAPS and RileyLinkAAPS. I might put it back at
* later time
*/
public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
@Inject HasAndroidInjector injector;
@Inject SP sp;
@Inject AAPSLogger aapsLogger;
@Inject RileyLinkServiceData rileyLinkServiceData;
@Inject ServiceTaskExecutor serviceTaskExecutor;
@Inject ActivePlugin activePlugin;
RileyLinkService serviceInstance;
protected Map<String, List<String>> broadcastIdentifiers = null;
//String deviceSpecificPrefix;
public RileyLinkBroadcastReceiver(RileyLinkService serviceInstance) {
this.serviceInstance = serviceInstance;
createBroadcastIdentifiers();
}
private void createBroadcastIdentifiers() {
this.broadcastIdentifiers = new HashMap<>();
// Bluetooth
this.broadcastIdentifiers.put("Bluetooth", Arrays.asList( //
RileyLinkConst.Intents.BluetoothConnected, //
RileyLinkConst.Intents.BluetoothReconnected));
// TuneUp
this.broadcastIdentifiers.put("TuneUp", Arrays.asList( //
RileyLinkConst.IPC.MSG_PUMP_tunePump, //
RileyLinkConst.IPC.MSG_PUMP_quickTune));
// RileyLink
this.broadcastIdentifiers.put("RileyLink", Arrays.asList( //
RileyLinkConst.Intents.RileyLinkDisconnected, //
RileyLinkConst.Intents.RileyLinkReady, //
RileyLinkConst.Intents.RileyLinkDisconnected, //
RileyLinkConst.Intents.RileyLinkNewAddressSet, //
RileyLinkConst.Intents.RileyLinkDisconnect));
}
private RileyLinkService getServiceInstance() {
RileyLinkPumpDevice pumpDevice = (RileyLinkPumpDevice) activePlugin.getActivePump();
return pumpDevice.getRileyLinkService();
}
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (intent == null) {
aapsLogger.error(LTag.PUMPBTCOMM, "onReceive: received null intent");
} else {
String action = intent.getAction();
if (action == null) {
aapsLogger.error("onReceive: null action");
} else {
aapsLogger.debug(LTag.PUMPBTCOMM, "Received Broadcast: " + action);
if (!processBluetoothBroadcasts(action) && //
!processRileyLinkBroadcasts(action, context) && //
!processTuneUpBroadcasts(action) && //
!processApplicationSpecificBroadcasts(action, intent) //
) {
aapsLogger.error(LTag.PUMPBTCOMM, "Unhandled broadcast: action=" + action);
}
}
}
}
public void registerBroadcasts(Context context) {
IntentFilter intentFilter = new IntentFilter();
for (Map.Entry<String, List<String>> stringListEntry : broadcastIdentifiers.entrySet()) {
for (String intentKey : stringListEntry.getValue()) {
intentFilter.addAction(intentKey);
}
}
LocalBroadcastManager.getInstance(context).registerReceiver(this, intentFilter);
}
private boolean processRileyLinkBroadcasts(String action, Context context) {
RileyLinkService rileyLinkService = getServiceInstance();
if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnected)) {
if (((BluetoothManager)context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter().isEnabled()) {
rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.RileyLinkUnreachable);
} else {
rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled);
}
return true;
} else if (action.equals(RileyLinkConst.Intents.RileyLinkReady)) {
aapsLogger.warn(LTag.PUMPBTCOMM, "RileyLinkConst.Intents.RileyLinkReady");
// sendIPCNotification(RT2Const.IPC.MSG_note_WakingPump);
rileyLinkService.rileyLinkBLE.enableNotifications();
rileyLinkService.rfspy.startReader(); // call startReader from outside?
rileyLinkService.rfspy.initializeRileyLink();
String bleVersion = rileyLinkService.rfspy.getBLEVersionCached();
RileyLinkFirmwareVersion rlVersion = rileyLinkServiceData.firmwareVersion;
aapsLogger.debug(LTag.PUMPBTCOMM, "RfSpy version (BLE113): " + bleVersion);
rileyLinkService.rileyLinkServiceData.versionBLE113 = bleVersion;
// if (isLoggingEnabled())
aapsLogger.debug(LTag.PUMPBTCOMM, "RfSpy Radio version (CC110): " + rlVersion.name());
this.rileyLinkServiceData.firmwareVersion = rlVersion;
ServiceTask task = new InitializePumpManagerTask(injector, context);
serviceTaskExecutor.startTask(task);
aapsLogger.info(LTag.PUMPBTCOMM, "Announcing RileyLink open For business");
return true;
} else if (action.equals(RileyLinkConst.Intents.RileyLinkNewAddressSet)) {
String RileylinkBLEAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
if (RileylinkBLEAddress.equals("")) {
aapsLogger.error("No Rileylink BLE Address saved in app");
} else {
// showBusy("Configuring Service", 50);
// rileyLinkBLE.findRileyLink(RileylinkBLEAddress);
rileyLinkService.reconfigureRileyLink(RileylinkBLEAddress);
// MainApp.getServiceClientConnection().setThisRileylink(RileylinkBLEAddress);
}
return true;
} else if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnect)) {
rileyLinkService.disconnectRileyLink();
return true;
} else {
return false;
}
}
public boolean processBluetoothBroadcasts(String action) {
if (action.equals(RileyLinkConst.Intents.BluetoothConnected)) {
aapsLogger.debug(LTag.PUMPBTCOMM, "Bluetooth - Connected");
serviceTaskExecutor.startTask(new DiscoverGattServicesTask(injector));
return true;
} else if (action.equals(RileyLinkConst.Intents.BluetoothReconnected)) {
aapsLogger.debug(LTag.PUMPBTCOMM, "Bluetooth - Reconnecting");
getServiceInstance().bluetoothInit();
serviceTaskExecutor.startTask(new DiscoverGattServicesTask(injector, true));
return true;
} else {
return false;
}
}
private boolean processTuneUpBroadcasts(String action) {
if (this.broadcastIdentifiers.get("TuneUp").contains(action)) {
if (serviceInstance.getRileyLinkTargetDevice().isTuneUpEnabled()) {
serviceTaskExecutor.startTask(new WakeAndTuneTask(injector));
}
return true;
} else {
return false;
}
}
public boolean processApplicationSpecificBroadcasts(String action, Intent intent) {
return false;
}
public void unregisterBroadcasts(Context context) {
LocalBroadcastManager.getInstance(context).unregisterReceiver(this);
}
}

View file

@ -0,0 +1,160 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service
import android.bluetooth.BluetoothManager
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Handler
import android.os.HandlerThread
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import dagger.android.DaggerBroadcastReceiver
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.DiscoverGattServicesTask
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.InitializePumpManagerTask
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTask
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.shared.sharedPreferences.SP
import javax.inject.Inject
class RileyLinkBroadcastReceiver : DaggerBroadcastReceiver() {
@Inject lateinit var injector: HasAndroidInjector
@Inject lateinit var sp: SP
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var rileyLinkServiceData: RileyLinkServiceData
@Inject lateinit var serviceTaskExecutor: ServiceTaskExecutor
@Inject lateinit var activePlugin: ActivePlugin
private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
private val broadcastIdentifiers: MutableMap<String, List<String>> = HashMap()
init {
createBroadcastIdentifiers()
}
private val rileyLinkService: RileyLinkService?
get() = (activePlugin.activePump as RileyLinkPumpDevice).rileyLinkService
private fun createBroadcastIdentifiers() {
// Bluetooth
broadcastIdentifiers["Bluetooth"] = listOf(
RileyLinkConst.Intents.BluetoothConnected,
RileyLinkConst.Intents.BluetoothReconnected
)
// TuneUp
broadcastIdentifiers["TuneUp"] = listOf(
RileyLinkConst.IPC.MSG_PUMP_tunePump,
RileyLinkConst.IPC.MSG_PUMP_quickTune
)
// RileyLink
broadcastIdentifiers["RileyLink"] = listOf(
RileyLinkConst.Intents.RileyLinkDisconnected,
RileyLinkConst.Intents.RileyLinkReady,
RileyLinkConst.Intents.RileyLinkDisconnected,
RileyLinkConst.Intents.RileyLinkNewAddressSet,
RileyLinkConst.Intents.RileyLinkDisconnect
)
}
override fun onReceive(context: Context, intent: Intent) {
super.onReceive(context, intent)
val action = intent.action ?: return
handler.post {
aapsLogger.debug(LTag.PUMPBTCOMM, "Received Broadcast: $action")
if (!processBluetoothBroadcasts(action) && !processRileyLinkBroadcasts(action, context) && !processTuneUpBroadcasts(action))
aapsLogger.error(LTag.PUMPBTCOMM, "Unhandled broadcast: action=$action")
}
}
fun registerBroadcasts(context: Context) {
val intentFilter = IntentFilter()
for ((_, value) in broadcastIdentifiers)
for (intentKey in value)
intentFilter.addAction(intentKey)
LocalBroadcastManager.getInstance(context).registerReceiver(this, intentFilter)
}
fun unregisterBroadcasts(context: Context) {
LocalBroadcastManager.getInstance(context).unregisterReceiver(this)
}
private fun processRileyLinkBroadcasts(action: String, context: Context): Boolean =
when (action) {
RileyLinkConst.Intents.RileyLinkDisconnected -> {
if ((context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager).adapter.isEnabled)
rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.RileyLinkUnreachable)
else
rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled)
true
}
RileyLinkConst.Intents.RileyLinkReady -> {
aapsLogger.warn(LTag.PUMPBTCOMM, "RileyLinkConst.Intents.RileyLinkReady")
// sendIPCNotification(RT2Const.IPC.MSG_note_WakingPump);
rileyLinkService?.rileyLinkBLE?.enableNotifications()
rileyLinkService?.rfSpy?.startReader() // call startReader from outside?
rileyLinkService?.rfSpy?.initializeRileyLink()
val bleVersion = rileyLinkService?.rfSpy?.bleVersionCached
val rlVersion = rileyLinkServiceData.firmwareVersion
aapsLogger.debug(LTag.PUMPBTCOMM, "RfSpy version (BLE113): $bleVersion")
rileyLinkService?.rileyLinkServiceData?.versionBLE113 = bleVersion
aapsLogger.debug(LTag.PUMPBTCOMM, "RfSpy Radio version (CC110): " + rlVersion.name)
rileyLinkServiceData.firmwareVersion = rlVersion
val task: ServiceTask = InitializePumpManagerTask(injector, context)
serviceTaskExecutor.startTask(task)
aapsLogger.info(LTag.PUMPBTCOMM, "Announcing RileyLink open For business")
true
}
RileyLinkConst.Intents.RileyLinkNewAddressSet -> {
val rileylinkBLEAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "")
if (rileylinkBLEAddress == "") {
aapsLogger.error("No Rileylink BLE Address saved in app")
} else rileyLinkService?.reconfigureRileyLink(rileylinkBLEAddress)
true
}
RileyLinkConst.Intents.RileyLinkDisconnect -> {
rileyLinkService?.disconnectRileyLink()
true
}
else -> false
}
private fun processBluetoothBroadcasts(action: String): Boolean =
when (action) {
RileyLinkConst.Intents.BluetoothConnected -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "Bluetooth - Connected")
serviceTaskExecutor.startTask(DiscoverGattServicesTask(injector))
true
}
RileyLinkConst.Intents.BluetoothReconnected -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "Bluetooth - Reconnecting")
rileyLinkService?.bluetoothInit()
serviceTaskExecutor.startTask(DiscoverGattServicesTask(injector, true))
true
}
else -> false
}
private fun processTuneUpBroadcasts(action: String): Boolean =
if (broadcastIdentifiers["TuneUp"]?.contains(action) == true) {
if (rileyLinkService?.rileyLinkTargetDevice?.isTuneUpEnabled == true) serviceTaskExecutor.startTask(WakeAndTuneTask(injector))
true
} else false
}

View file

@ -41,18 +41,18 @@ abstract class RileyLinkService : DaggerService() {
@Inject lateinit var rileyLinkServiceData: RileyLinkServiceData
@Inject lateinit var activePlugin: ActivePlugin
@Inject lateinit var rileyLinkBLE: RileyLinkBLE // android-bluetooth management
@Inject lateinit var rfspy: RFSpy // interface for RL xxx Mhz radio.
@Inject lateinit var rfSpy: RFSpy // interface for RL xxx Mhz radio.
private val bluetoothAdapter: BluetoothAdapter? get() = (context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager?)?.adapter
protected var mBroadcastReceiver: RileyLinkBroadcastReceiver? = null
protected var broadcastReceiver: RileyLinkBroadcastReceiver? = null
private var bluetoothStateReceiver: RileyLinkBluetoothStateReceiver? = null
override fun onCreate() {
super.onCreate()
rileyLinkUtil.encoding = encoding
initRileyLinkServiceData()
mBroadcastReceiver = RileyLinkBroadcastReceiver(this)
mBroadcastReceiver?.registerBroadcasts(this)
broadcastReceiver = RileyLinkBroadcastReceiver()
broadcastReceiver?.registerBroadcasts(this)
bluetoothStateReceiver = RileyLinkBluetoothStateReceiver()
bluetoothStateReceiver?.registerBroadcasts(this)
}
@ -80,7 +80,7 @@ abstract class RileyLinkService : DaggerService() {
super.onDestroy()
rileyLinkBLE.disconnect() // dispose of Gatt (disconnect and close)
mBroadcastReceiver?.unregisterBroadcasts(this)
broadcastReceiver?.unregisterBroadcasts(this)
bluetoothStateReceiver?.unregisterBroadcasts(this)
}
@ -139,7 +139,7 @@ abstract class RileyLinkService : DaggerService() {
}
}
// FIXME: This needs to be run in a session so that is interruptible, has a separate thread, etc.
// FIXME: This needs to be run in a session so that is incorruptible, has a separate thread, etc.
fun doTuneUpDevice() {
rileyLinkServiceData.setRileyLinkServiceState(RileyLinkServiceState.TuneUpDevice)
setPumpDeviceState(PumpDeviceState.Sleeping)
@ -178,7 +178,7 @@ abstract class RileyLinkService : DaggerService() {
get() = rileyLinkServiceData.targetDevice
fun changeRileyLinkEncoding(encodingType: RileyLinkEncodingType?) {
rfspy.setRileyLinkEncoding(encodingType)
rfSpy.setRileyLinkEncoding(encodingType)
}
val error: RileyLinkError?