DanaRS: improve history sync
This commit is contained in:
parent
6c990a4423
commit
0dbfa6182f
3 changed files with 35 additions and 37 deletions
|
@ -8,6 +8,7 @@ import info.nightscout.androidaps.Constants
|
|||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.CommandQueue
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
|
@ -18,7 +19,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
|
|||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
|
||||
class QueueThread internal constructor(
|
||||
private val queue: CommandQueueImplementation,
|
||||
private val queue: CommandQueue,
|
||||
context: Context,
|
||||
private val aapsLogger: AAPSLogger,
|
||||
private val rxBus: RxBus,
|
||||
|
|
|
@ -6,12 +6,17 @@ import info.nightscout.androidaps.dana.DanaPump
|
|||
import info.nightscout.androidaps.danars.encryption.BleEncryption
|
||||
import javax.inject.Inject
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
class DanaRSPacketGeneralInitialScreenInformation(
|
||||
injector: HasAndroidInjector
|
||||
) : DanaRSPacket(injector) {
|
||||
|
||||
@Inject lateinit var danaPump: DanaPump
|
||||
|
||||
var isTempBasalInProgress = false
|
||||
var isExtendedInProgress = false
|
||||
var isDualBolusInProgress = false
|
||||
|
||||
init {
|
||||
opCode = BleEncryption.DANAR_PACKET__OPCODE_REVIEW__INITIAL_SCREEN_INFORMATION
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "New message")
|
||||
|
@ -22,42 +27,22 @@ class DanaRSPacketGeneralInitialScreenInformation(
|
|||
failed = true
|
||||
return
|
||||
} else failed = false
|
||||
var dataIndex = DATA_START
|
||||
var dataSize = 1
|
||||
val status = byteArrayToInt(getBytes(data, dataIndex, dataSize))
|
||||
val status = intFromBuff(data, 0, 1)
|
||||
danaPump.pumpSuspended = status and 0x01 == 0x01
|
||||
val isTempBasalInProgress = status and 0x10 == 0x10
|
||||
val isExtendedInProgress = status and 0x04 == 0x04
|
||||
val isDualBolusInProgress = status and 0x08 == 0x08
|
||||
dataIndex += dataSize
|
||||
dataSize = 2
|
||||
danaPump.dailyTotalUnits = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0
|
||||
dataIndex += dataSize
|
||||
dataSize = 2
|
||||
danaPump.maxDailyTotalUnits = (byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0).toInt()
|
||||
dataIndex += dataSize
|
||||
dataSize = 2
|
||||
danaPump.reservoirRemainingUnits = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0
|
||||
dataIndex += dataSize
|
||||
dataSize = 2
|
||||
danaPump.currentBasal = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0
|
||||
dataIndex += dataSize
|
||||
dataSize = 1
|
||||
val tempBasalPercent = byteArrayToInt(getBytes(data, dataIndex, dataSize))
|
||||
dataIndex += dataSize
|
||||
dataSize = 1
|
||||
danaPump.batteryRemaining = byteArrayToInt(getBytes(data, dataIndex, dataSize))
|
||||
dataIndex += dataSize
|
||||
dataSize = 2
|
||||
val extendedBolusAbsoluteRate = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0
|
||||
dataIndex += dataSize
|
||||
dataSize = 2
|
||||
danaPump.iob = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0
|
||||
isTempBasalInProgress = status and 0x10 == 0x10
|
||||
isExtendedInProgress = status and 0x04 == 0x04
|
||||
isDualBolusInProgress = status and 0x08 == 0x08
|
||||
danaPump.dailyTotalUnits = intFromBuff(data, 1, 2) / 100.0
|
||||
danaPump.maxDailyTotalUnits = intFromBuff(data, 3, 2) / 100
|
||||
danaPump.reservoirRemainingUnits = intFromBuff(data, 5, 2) / 100.0
|
||||
danaPump.currentBasal = intFromBuff(data, 7, 2) / 100.0
|
||||
val tempBasalPercent = intFromBuff(data, 9, 1)
|
||||
danaPump.batteryRemaining = intFromBuff(data, 10, 1)
|
||||
val extendedBolusAbsoluteRate = intFromBuff(data, 11, 2) / 100.0
|
||||
danaPump.iob = intFromBuff(data, 13, 2) / 100.0
|
||||
if (data.size >= 18) {
|
||||
//protocol 10+
|
||||
dataIndex += dataSize
|
||||
dataSize = 1
|
||||
danaPump.errorState = DanaPump.ErrorState[byteArrayToInt(getBytes(data, dataIndex, dataSize))]
|
||||
danaPump.errorState = DanaPump.ErrorState[intFromBuff(data, 15, 1)]
|
||||
?: DanaPump.ErrorState.NONE
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "ErrorState: " + danaPump.errorState.name)
|
||||
}
|
||||
|
|
|
@ -338,7 +338,9 @@ class DanaRSService : DaggerService() {
|
|||
|
||||
fun tempBasal(percent: Int, durationInHours: Int): Boolean {
|
||||
if (!isConnected) return false
|
||||
if (danaPump.isTempBasalInProgress) {
|
||||
val status = DanaRSPacketGeneralInitialScreenInformation(injector)
|
||||
sendMessage(status)
|
||||
if (status.isTempBasalInProgress) {
|
||||
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.stoppingtempbasal)))
|
||||
sendMessage(DanaRSPacketBasalSetCancelTemporaryBasal(injector))
|
||||
SystemClock.sleep(500)
|
||||
|
@ -348,6 +350,7 @@ class DanaRSService : DaggerService() {
|
|||
sendMessage(msgTBR)
|
||||
SystemClock.sleep(200)
|
||||
loadEvents()
|
||||
SystemClock.sleep(4500)
|
||||
val tbr = pumpSync.expectedPumpState().temporaryBasal
|
||||
danaPump.fromTemporaryBasal(tbr)
|
||||
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
|
||||
|
@ -355,7 +358,9 @@ class DanaRSService : DaggerService() {
|
|||
}
|
||||
|
||||
fun highTempBasal(percent: Int): Boolean {
|
||||
if (danaPump.isTempBasalInProgress) {
|
||||
val status = DanaRSPacketGeneralInitialScreenInformation(injector)
|
||||
sendMessage(status)
|
||||
if (status.isTempBasalInProgress) {
|
||||
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.stoppingtempbasal)))
|
||||
sendMessage(DanaRSPacketBasalSetCancelTemporaryBasal(injector))
|
||||
SystemClock.sleep(500)
|
||||
|
@ -364,6 +369,7 @@ class DanaRSService : DaggerService() {
|
|||
val msgTBR = DanaRSPacketAPSBasalSetTemporaryBasal(injector, percent)
|
||||
sendMessage(msgTBR)
|
||||
loadEvents()
|
||||
SystemClock.sleep(4500)
|
||||
val tbr = pumpSync.expectedPumpState().temporaryBasal
|
||||
danaPump.fromTemporaryBasal(tbr)
|
||||
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
|
||||
|
@ -375,7 +381,9 @@ class DanaRSService : DaggerService() {
|
|||
aapsLogger.error(LTag.PUMPCOMM, "Wrong duration param")
|
||||
return false
|
||||
}
|
||||
if (danaPump.isTempBasalInProgress) {
|
||||
val status = DanaRSPacketGeneralInitialScreenInformation(injector)
|
||||
sendMessage(status)
|
||||
if (status.isTempBasalInProgress) {
|
||||
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.stoppingtempbasal)))
|
||||
sendMessage(DanaRSPacketBasalSetCancelTemporaryBasal(injector))
|
||||
SystemClock.sleep(500)
|
||||
|
@ -384,6 +392,7 @@ class DanaRSService : DaggerService() {
|
|||
val msgTBR = DanaRSPacketAPSBasalSetTemporaryBasal(injector, percent)
|
||||
sendMessage(msgTBR)
|
||||
loadEvents()
|
||||
SystemClock.sleep(4500)
|
||||
val tbr = pumpSync.expectedPumpState().temporaryBasal
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Expected TBR found: $tbr")
|
||||
danaPump.fromTemporaryBasal(tbr)
|
||||
|
@ -397,6 +406,7 @@ class DanaRSService : DaggerService() {
|
|||
val msgCancel = DanaRSPacketBasalSetCancelTemporaryBasal(injector)
|
||||
sendMessage(msgCancel)
|
||||
loadEvents()
|
||||
SystemClock.sleep(4500)
|
||||
val tbr = pumpSync.expectedPumpState().temporaryBasal
|
||||
danaPump.fromTemporaryBasal(tbr)
|
||||
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
|
||||
|
@ -410,6 +420,7 @@ class DanaRSService : DaggerService() {
|
|||
sendMessage(msgExtended)
|
||||
SystemClock.sleep(200)
|
||||
loadEvents()
|
||||
SystemClock.sleep(4500)
|
||||
val eb = pumpSync.expectedPumpState().extendedBolus
|
||||
danaPump.fromExtendedBolus(eb)
|
||||
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
|
||||
|
@ -422,6 +433,7 @@ class DanaRSService : DaggerService() {
|
|||
val msgStop = DanaRSPacketBolusSetExtendedBolusCancel(injector)
|
||||
sendMessage(msgStop)
|
||||
loadEvents()
|
||||
SystemClock.sleep(4500)
|
||||
val eb = pumpSync.expectedPumpState().extendedBolus
|
||||
danaPump.fromExtendedBolus(eb)
|
||||
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
|
||||
|
|
Loading…
Reference in a new issue