handle Pod Alarm

This commit is contained in:
Andrei Vereha 2021-06-06 18:35:19 +02:00
parent 909eae3f3f
commit aa719e0b9f
4 changed files with 55 additions and 7 deletions

View file

@ -45,6 +45,7 @@ import org.json.JSONObject
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
import kotlin.random.Random
@Singleton @Singleton
class OmnipodDashPumpPlugin @Inject constructor( class OmnipodDashPumpPlugin @Inject constructor(
@ -131,6 +132,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
history.updateFromState(podStateManager), history.updateFromState(podStateManager),
podStateManager.updateActiveCommand() podStateManager.updateActiveCommand()
.map { handleCommandConfirmation(it) } .map { handleCommandConfirmation(it) }
.map { checkPodKaput() }
.ignoreElement(), .ignoreElement(),
) )
).blockingGet() ).blockingGet()
@ -141,6 +143,25 @@ class OmnipodDashPumpPlugin @Inject constructor(
} }
} }
private fun checkPodKaput() {
if (podStateManager.isPodKaput) {
val tbr = pumpSync.expectedPumpState().temporaryBasal
if (tbr?.rate == 0.0) {
return
}
pumpSync.syncTemporaryBasalWithPumpId(
timestamp = System.currentTimeMillis(),
rate = 0.0,
duration = T.mins(PodConstants.MAX_POD_LIFETIME.standardMinutes).msecs(),
isAbsolute = true,
type = PumpSync.TemporaryBasalType.PUMP_SUSPEND,
pumpId = Random.Default.nextLong(), // we don't use this, just make sure it's unique
pumpType = PumpType.OMNIPOD_DASH,
pumpSerial = serialNumber()
)
}
}
override fun setNewBasalProfile(profile: Profile): PumpEnactResult { override fun setNewBasalProfile(profile: Profile): PumpEnactResult {
val basalProgram = mapProfileToBasalProgram(profile) val basalProgram = mapProfileToBasalProgram(profile)
return executeProgrammingCommand( return executeProgrammingCommand(
@ -220,7 +241,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
val date = Date() val date = Date()
val ret = podStateManager.basalProgram?.rateAt(date) ?: 0.0 val ret = podStateManager.basalProgram?.rateAt(date) ?: 0.0
aapsLogger.info(LTag.PUMP, "baseBasalRate: %ret at $date}") aapsLogger.info(LTag.PUMP, "baseBasalRate: %ret at $date}")
return ret return if (podStateManager.alarmType != null) {
0.0
} else
ret
} }
override val reservoirLevel: Double override val reservoirLevel: Double

View file

@ -28,6 +28,7 @@ interface OmnipodDashPodStateManager {
val isActivationCompleted: Boolean val isActivationCompleted: Boolean
val isSuspended: Boolean val isSuspended: Boolean
val isPodRunning: Boolean val isPodRunning: Boolean
val isPodKaput: Boolean
var bluetoothConnectionState: BluetoothConnectionState var bluetoothConnectionState: BluetoothConnectionState
val lastUpdatedSystem: Long // System.currentTimeMillis() val lastUpdatedSystem: Long // System.currentTimeMillis()
@ -57,6 +58,7 @@ interface OmnipodDashPodStateManager {
val deliveryStatus: DeliveryStatus? val deliveryStatus: DeliveryStatus?
val minutesSinceActivation: Short? val minutesSinceActivation: Short?
val activeAlerts: EnumSet<AlertType>? val activeAlerts: EnumSet<AlertType>?
val alarmType: AlarmType?
var tempBasal: TempBasal? var tempBasal: TempBasal?
val tempBasalActive: Boolean val tempBasalActive: Boolean

View file

@ -55,6 +55,9 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
get() = podState.deliveryStatus?.equals(DeliveryStatus.SUSPENDED) get() = podState.deliveryStatus?.equals(DeliveryStatus.SUSPENDED)
?: false ?: false
override val isPodKaput: Boolean
get() = podState.podStatus in arrayOf(PodStatus.ALARM, PodStatus.DEACTIVATED)
override val isPodRunning: Boolean override val isPodRunning: Boolean
get() = podState.podStatus?.isRunning() ?: false get() = podState.podStatus?.isRunning() ?: false
@ -137,6 +140,9 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
override val activeAlerts: EnumSet<AlertType>? override val activeAlerts: EnumSet<AlertType>?
get() = podState.activeAlerts get() = podState.activeAlerts
override val alarmType: AlarmType?
get() = podState.alarmType
override var tempBasal: OmnipodDashPodStateManager.TempBasal? override var tempBasal: OmnipodDashPodStateManager.TempBasal?
get() = podState.tempBasal get() = podState.tempBasal
set(tempBasal) { set(tempBasal) {
@ -384,15 +390,24 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
} }
override fun updateFromAlarmStatusResponse(response: AlarmStatusResponse) { override fun updateFromAlarmStatusResponse(response: AlarmStatusResponse) {
// TODO
logger.error(
LTag.PUMP,
"Not implemented: OmnipodDashPodStateManagerImpl.updateFromAlarmStatusResponse(AlarmStatusResponse)"
)
logger.info( logger.info(
LTag.PUMP, LTag.PUMP,
"Received AlarmStatusReponse: $response" "Received AlarmStatusReponse: $response"
) )
podState.deliveryStatus = response.deliveryStatus
podState.podStatus = response.podStatus
podState.pulsesDelivered = response.totalPulsesDelivered
if (response.reservoirPulsesRemaining < 1023) {
podState.pulsesRemaining = response.reservoirPulsesRemaining
}
podState.sequenceNumberOfLastProgrammingCommand = response.sequenceNumberOfLastProgrammingCommand
podState.minutesSinceActivation = response.minutesSinceActivation
podState.activeAlerts = response.activeAlerts
podState.alarmType = response.alarmType
podState.lastUpdatedSystem = System.currentTimeMillis()
podState.lastStatusResponseReceived = SystemClock.elapsedRealtime()
store() store()
rxBus.send(EventOmnipodDashPumpValuesChanged()) rxBus.send(EventOmnipodDashPumpValuesChanged())
} }
@ -464,6 +479,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
var deliveryStatus: DeliveryStatus? = null var deliveryStatus: DeliveryStatus? = null
var minutesSinceActivation: Short? = null var minutesSinceActivation: Short? = null
var activeAlerts: EnumSet<AlertType>? = null var activeAlerts: EnumSet<AlertType>? = null
var alarmType: AlarmType? = null
var basalProgram: BasalProgram? = null var basalProgram: BasalProgram? = null
var tempBasal: OmnipodDashPodStateManager.TempBasal? = null var tempBasal: OmnipodDashPodStateManager.TempBasal? = null

View file

@ -212,7 +212,6 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
} }
private fun updateUi() { private fun updateUi() {
// TODO update bluetooth status
updateBluetoothStatus() updateBluetoothStatus()
updateOmnipodStatus() updateOmnipodStatus()
updatePodActionButtons() updatePodActionButtons()
@ -296,6 +295,13 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
errors.add(resourceHelper.gs(R.string.omnipod_common_pod_status_pod_fault_description, faultEventCode.value, faultEventCode.name)) errors.add(resourceHelper.gs(R.string.omnipod_common_pod_status_pod_fault_description, faultEventCode.value, faultEventCode.name))
} }
*/ */
podStateManager.alarmType?.let {
errors.add(resourceHelper.gs(
R.string.omnipod_common_pod_status_pod_fault_description,
it.value,
it.toString())
)
}
// base basal rate // base basal rate
podInfoBinding.baseBasalRate.text = if (podStateManager.basalProgram != null && !podStateManager.isSuspended) { podInfoBinding.baseBasalRate.text = if (podStateManager.basalProgram != null && !podStateManager.isSuspended) {