More cleanup after conversion

This commit is contained in:
Bart Sopers 2021-02-27 00:39:55 +01:00
parent ba65a47380
commit dcf7672a24
19 changed files with 185 additions and 319 deletions

View file

@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.OmnipodDashBleManager import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.OmnipodDashBleManager
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.event.PodEvent import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.event.PodEvent
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.event.PodEventType
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.GetVersionCommand import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.GetVersionCommand
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.GetVersionCommand.Companion.DEFAULT_UNIQUE_ID import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.GetVersionCommand.Companion.DEFAULT_UNIQUE_ID
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ActivationProgress import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ActivationProgress
@ -31,25 +30,26 @@ class OmnipodDashManagerImpl @Inject constructor(
return Observable.error(IllegalStateException("Pod is in an incorrect state")) return Observable.error(IllegalStateException("Pod is in an incorrect state"))
} }
private val observeConnectToPod: Observable<PodEvent> = Observable.defer { private val observeConnectToPod: Observable<PodEvent>
// TODO get() {
// send CONNECTING event here return Observable.defer {
bleManager.connect() bleManager.connect()
Observable.just(PodEvent(PodEventType.CONNECTED, null)) Observable.just(PodEvent.Connected(0)) // TODO should be returned in BleManager
}
} }
override fun activatePodPart1(): Observable<PodEvent> { override fun activatePodPart1(): Observable<PodEvent> {
// TODO val command = GetVersionCommand.Builder() //
.setSequenceNumber(podStateManager.messageSequenceNumber) //
.setUniqueId(DEFAULT_UNIQUE_ID) //
.build()
return Observable.concat( return Observable.concat(
observePodReadyForActivationPart1, observePodReadyForActivationPart1,
observeConnectToPod, observeConnectToPod,
Observable.defer { Observable.defer {
bleManager.sendCommand(GetVersionCommand.Builder() // bleManager.sendCommand(command)
.setSequenceNumber(podStateManager.messageSequenceNumber) // Observable.just(PodEvent.CommandSent(command)) // TODO should be returned in BleManager
.setUniqueId(DEFAULT_UNIQUE_ID) //
.build()
)
Observable.just(PodEvent(PodEventType.COMMAND_SENT, null))
} }
// ... Send more commands // ... Send more commands
) )

View file

@ -1,8 +1,16 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.event package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.event
import java.io.Serializable import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.Command
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.Response
sealed class PodEvent {
object Scanning : PodEvent()
object Pairing : PodEvent()
object Connecting : PodEvent()
class Connected(val uniqueId: Int) : PodEvent()
class CommandSending(val command: Command) : PodEvent()
class CommandSent(val command: Command) : PodEvent()
class ResponseReceived(val response: Response) : PodEvent()
}
class PodEvent(
val type: PodEventType,
val data: Serializable?
)

View file

@ -1,12 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.event
enum class PodEventType {
SCANNING,
PAIRING,
CONNECTING,
CONNECTED,
COMMAND_SENDING,
COMMAND_SENT,
RESPONSE_RECEIVED,
// ...
}

View file

@ -11,7 +11,7 @@ class ProgramAlertsCommand private constructor(
uniqueId: Int, uniqueId: Int,
sequenceNumber: Short, sequenceNumber: Short,
multiCommandFlag: Boolean, multiCommandFlag: Boolean,
alertConfigurations: List<AlertConfiguration>?, alertConfigurations: List<AlertConfiguration>,
nonce: Int nonce: Int
) : NonceEnabledCommand(CommandType.PROGRAM_ALERTS, uniqueId, sequenceNumber, multiCommandFlag, nonce) { ) : NonceEnabledCommand(CommandType.PROGRAM_ALERTS, uniqueId, sequenceNumber, multiCommandFlag, nonce) {
@ -52,6 +52,7 @@ class ProgramAlertsCommand private constructor(
class Builder : NonceEnabledCommandBuilder<Builder, ProgramAlertsCommand>() { class Builder : NonceEnabledCommandBuilder<Builder, ProgramAlertsCommand>() {
private var alertConfigurations: List<AlertConfiguration>? = null private var alertConfigurations: List<AlertConfiguration>? = null
fun setAlertConfigurations(alertConfigurations: List<AlertConfiguration>?): Builder { fun setAlertConfigurations(alertConfigurations: List<AlertConfiguration>?): Builder {
this.alertConfigurations = alertConfigurations this.alertConfigurations = alertConfigurations
return this return this
@ -59,7 +60,7 @@ class ProgramAlertsCommand private constructor(
override fun buildCommand(): ProgramAlertsCommand { override fun buildCommand(): ProgramAlertsCommand {
requireNotNull(alertConfigurations) { "alertConfigurations can not be null" } // !!? requireNotNull(alertConfigurations) { "alertConfigurations can not be null" } // !!?
return ProgramAlertsCommand(uniqueId!!, sequenceNumber!!, multiCommandFlag, alertConfigurations, nonce!!) // TODO this might crash if not all are set return ProgramAlertsCommand(uniqueId!!, sequenceNumber!!, multiCommandFlag, alertConfigurations!!, nonce!!) // TODO this might crash if not all are set
} }
} }

View file

@ -76,6 +76,7 @@ class ProgramBasalCommand private constructor(
private var basalProgram: BasalProgram? = null private var basalProgram: BasalProgram? = null
private var programReminder: ProgramReminder? = null private var programReminder: ProgramReminder? = null
private var currentTime: Date? = null private var currentTime: Date? = null
fun setBasalProgram(basalProgram: BasalProgram?): Builder { fun setBasalProgram(basalProgram: BasalProgram?): Builder {
this.basalProgram = basalProgram this.basalProgram = basalProgram
return this return this

View file

@ -57,6 +57,7 @@ class ProgramBolusCommand private constructor(
private var numberOfUnits: Double? = null private var numberOfUnits: Double? = null
private var delayBetweenPulsesInEighthSeconds: Byte? = null private var delayBetweenPulsesInEighthSeconds: Byte? = null
private var programReminder: ProgramReminder? = null private var programReminder: ProgramReminder? = null
fun setNumberOfUnits(numberOfUnits: Double): Builder { fun setNumberOfUnits(numberOfUnits: Double): Builder {
require(numberOfUnits > 0.0) { "Number of units should be greater than zero" } require(numberOfUnits > 0.0) { "Number of units should be greater than zero" }
require((numberOfUnits * 1000).toInt() % 50 == 0) { "Number of units must be dividable by 0.05" } require((numberOfUnits * 1000).toInt() % 50 == 0) { "Number of units must be dividable by 0.05" }
@ -78,6 +79,7 @@ class ProgramBolusCommand private constructor(
requireNotNull(numberOfUnits) { "numberOfUnits can not be null" } requireNotNull(numberOfUnits) { "numberOfUnits can not be null" }
requireNotNull(delayBetweenPulsesInEighthSeconds) { "delayBetweenPulsesInEighthSeconds can not be null" } requireNotNull(delayBetweenPulsesInEighthSeconds) { "delayBetweenPulsesInEighthSeconds can not be null" }
requireNotNull(programReminder) { "programReminder can not be null" } requireNotNull(programReminder) { "programReminder can not be null" }
val numberOfPulses = Math.round(numberOfUnits!! * 20).toShort() val numberOfPulses = Math.round(numberOfUnits!! * 20).toShort()
val byte10And11 = (numberOfPulses * delayBetweenPulsesInEighthSeconds!!).toShort() val byte10And11 = (numberOfPulses * delayBetweenPulsesInEighthSeconds!!).toShort()
val interlockCommand = ProgramInsulinCommand(uniqueId!!, sequenceNumber!!, multiCommandFlag, nonce!!, listOf(BolusShortInsulinProgramElement(numberOfPulses)), calculateChecksum(0x01.toByte(), byte10And11, numberOfPulses), val interlockCommand = ProgramInsulinCommand(uniqueId!!, sequenceNumber!!, multiCommandFlag, nonce!!, listOf(BolusShortInsulinProgramElement(numberOfPulses)), calculateChecksum(0x01.toByte(), byte10And11, numberOfPulses),

View file

@ -34,14 +34,6 @@ class ProgramInsulinCommand internal constructor(
} }
} }
fun calculateChecksum(bytes: ByteArray): Short {
var sum: Short = 0
for (b in bytes) {
sum = ((b.toInt() and 0xff) + sum).toShort()
}
return sum
}
override val encoded: ByteArray override val encoded: ByteArray
get() { get() {
val buffer = ByteBuffer.allocate(getLength().toInt()) // val buffer = ByteBuffer.allocate(getLength().toInt()) //

View file

@ -31,6 +31,7 @@ class ProgramTempBasalCommand private constructor(
private var programReminder: ProgramReminder? = null private var programReminder: ProgramReminder? = null
private var rateInUnitsPerHour: Double? = null private var rateInUnitsPerHour: Double? = null
private var durationInMinutes: Short? = null private var durationInMinutes: Short? = null
fun setProgramReminder(programReminder: ProgramReminder?): Builder { fun setProgramReminder(programReminder: ProgramReminder?): Builder {
this.programReminder = programReminder this.programReminder = programReminder
return this return this
@ -43,6 +44,7 @@ class ProgramTempBasalCommand private constructor(
fun setDurationInMinutes(durationInMinutes: Short): Builder { fun setDurationInMinutes(durationInMinutes: Short): Builder {
require(durationInMinutes % 30 == 0) { "durationInMinutes must be dividable by 30" } require(durationInMinutes % 30 == 0) { "durationInMinutes must be dividable by 30" }
this.durationInMinutes = durationInMinutes this.durationInMinutes = durationInMinutes
return this return this
} }
@ -51,6 +53,7 @@ class ProgramTempBasalCommand private constructor(
requireNotNull(programReminder) { "programReminder can not be null" } requireNotNull(programReminder) { "programReminder can not be null" }
requireNotNull(rateInUnitsPerHour) { "rateInUnitsPerHour can not be null" } requireNotNull(rateInUnitsPerHour) { "rateInUnitsPerHour can not be null" }
requireNotNull(durationInMinutes) { "durationInMinutes can not be null" } requireNotNull(durationInMinutes) { "durationInMinutes can not be null" }
val durationInSlots = (durationInMinutes!! / 30).toByte() val durationInSlots = (durationInMinutes!! / 30).toByte()
val pulsesPerSlot = ProgramTempBasalUtil.mapTempBasalToPulsesPerSlot(durationInSlots, rateInUnitsPerHour!!) val pulsesPerSlot = ProgramTempBasalUtil.mapTempBasalToPulsesPerSlot(durationInSlots, rateInUnitsPerHour!!)
val tenthPulsesPerSlot = ProgramTempBasalUtil.mapTempBasalToTenthPulsesPerSlot(durationInSlots.toInt(), rateInUnitsPerHour!!) val tenthPulsesPerSlot = ProgramTempBasalUtil.mapTempBasalToTenthPulsesPerSlot(durationInSlots.toInt(), rateInUnitsPerHour!!)

View file

@ -45,6 +45,7 @@ class SetUniqueIdCommand private constructor(
private var lotNumber: Int? = null private var lotNumber: Int? = null
private var podSequenceNumber: Int? = null private var podSequenceNumber: Int? = null
private var initializationTime: Date? = null private var initializationTime: Date? = null
fun setLotNumber(lotNumber: Int): Builder { fun setLotNumber(lotNumber: Int): Builder {
this.lotNumber = lotNumber this.lotNumber = lotNumber
return this return this

View file

@ -63,6 +63,7 @@ class SilenceAlertsCommand private constructor(
private var silenceSuspendInProgressAlert = false private var silenceSuspendInProgressAlert = false
private var silenceSuspendEndedAlert = false private var silenceSuspendEndedAlert = false
private var silencePodExpirationAlert = false private var silencePodExpirationAlert = false
fun setSilenceAutoOffAlert(silenceAutoOffAlert: Boolean): Builder { fun setSilenceAutoOffAlert(silenceAutoOffAlert: Boolean): Builder {
this.silenceAutoOffAlert = silenceAutoOffAlert this.silenceAutoOffAlert = silenceAutoOffAlert
return this return this

View file

@ -57,6 +57,7 @@ class StopDeliveryCommand private constructor(
private var deliveryType: DeliveryType? = null private var deliveryType: DeliveryType? = null
private var beepType: BeepType? = BeepType.LONG_SINGLE_BEEP private var beepType: BeepType? = BeepType.LONG_SINGLE_BEEP
fun setDeliveryType(deliveryType: DeliveryType?): Builder { fun setDeliveryType(deliveryType: DeliveryType?): Builder {
this.deliveryType = deliveryType this.deliveryType = deliveryType
return this return this
@ -70,6 +71,7 @@ class StopDeliveryCommand private constructor(
override fun buildCommand(): StopDeliveryCommand { override fun buildCommand(): StopDeliveryCommand {
requireNotNull(deliveryType) { "deliveryType can not be null" } requireNotNull(deliveryType) { "deliveryType can not be null" }
requireNotNull(beepType) { "beepType can not be null" } requireNotNull(beepType) { "beepType can not be null" }
return StopDeliveryCommand(uniqueId!!, sequenceNumber!!, multiCommandFlag, deliveryType!!, beepType!!, nonce!!) return StopDeliveryCommand(uniqueId!!, sequenceNumber!!, multiCommandFlag, deliveryType!!, beepType!!, nonce!!)
} }
} }

View file

@ -8,6 +8,7 @@ abstract class HeaderEnabledCommandBuilder<T : HeaderEnabledCommandBuilder<T, R>
protected var uniqueId: Int? = null protected var uniqueId: Int? = null
protected var sequenceNumber: Short? = null protected var sequenceNumber: Short? = null
protected var multiCommandFlag = false protected var multiCommandFlag = false
override fun build(): R { override fun build(): R {
requireNotNull(uniqueId) { "uniqueId can not be null" } requireNotNull(uniqueId) { "uniqueId can not be null" }
requireNotNull(sequenceNumber) { "sequenceNumber can not be null" } requireNotNull(sequenceNumber) { "sequenceNumber can not be null" }

View file

@ -7,7 +7,7 @@ class BasalProgram(
) { ) {
val segments: MutableList<Segment> = segments.toMutableList() val segments: MutableList<Segment> = segments.toMutableList()
get() = Collections.unmodifiableList(field) // TODO Adrian: moved method here get() = Collections.unmodifiableList(field)
fun addSegment(segment: Segment) { fun addSegment(segment: Segment) {
segments.add(segment) segments.add(segment)

View file

@ -1,10 +1,8 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition
enum class BeepType( // Used in stop delivery command enum class BeepType(val value: Byte) {
val value: Byte
) {
SILENT(0x00.toByte()), SILENT(0x00.toByte()),
FOUR_TIMES_BIP_BEEP(0x02.toByte()), // Used in low reservoir alert, user expiration alert, expiration alert, imminent expiration alert, lump of coal alert FOUR_TIMES_BIP_BEEP(0x02.toByte()), // Used in low reservoir alert, user expiration alert, expiration alert, imminent expiration alert, lump of coal alert
LONG_SINGLE_BEEP(0x06.toByte()); LONG_SINGLE_BEEP(0x06.toByte()); // Used in stop delivery command
} }

View file

@ -9,101 +9,25 @@ class SetUniqueIdResponse(
encoded: ByteArray encoded: ByteArray
) : ActivationResponseBase(ActivationResponseType.SET_UNIQUE_ID_RESPONSE, encoded) { ) : ActivationResponseBase(ActivationResponseType.SET_UNIQUE_ID_RESPONSE, encoded) {
private val messageType: Byte // TODO directly assign here val messageType: Byte = encoded[0]
private val messageLength: Short val messageLength: Short = (encoded[1].toInt() and 0xff).toShort()
private val pulseVolumeInTenThousandthMicroLiter: Short val pulseVolumeInTenThousandthMicroLiter: Short = ByteBuffer.wrap(byteArrayOf(encoded[2], encoded[3])).short
private val pumpRate: Short val pumpRate: Short = (encoded[4].toInt() and 0xff).toShort()
private val primePumpRate: Short val primePumpRate: Short = (encoded[5].toInt() and 0xff).toShort()
private val numberOfEngagingClutchDrivePulses: Short val numberOfEngagingClutchDrivePulses: Short = (encoded[6].toInt() and 0xff).toShort()
private val numberOfPrimePulses: Short val numberOfPrimePulses: Short = (encoded[7].toInt() and 0xff).toShort()
private val podExpirationTimeInHours: Short val podExpirationTimeInHours: Short = (encoded[8].toInt() and 0xff).toShort()
private val firmwareVersionMajor: Short val firmwareVersionMajor: Short = (encoded[9].toInt() and 0xff).toShort()
private val firmwareVersionMinor: Short val firmwareVersionMinor: Short = (encoded[10].toInt() and 0xff).toShort()
private val firmwareVersionInterim: Short val firmwareVersionInterim: Short = (encoded[11].toInt() and 0xff).toShort()
private val bleVersionMajor: Short val bleVersionMajor: Short = (encoded[12].toInt() and 0xff).toShort()
private val bleVersionMinor: Short val bleVersionMinor: Short = (encoded[13].toInt() and 0xff).toShort()
private val bleVersionInterim: Short val bleVersionInterim: Short = (encoded[14].toInt() and 0xff).toShort()
private val productId: Short val productId: Short = (encoded[15].toInt() and 0xff).toShort()
private val podStatus: PodStatus val podStatus: PodStatus = byValue(encoded[16], PodStatus.UNKNOWN)
private val lotNumber: Long val lotNumber: Long = ByteBuffer.wrap(byteArrayOf(0, 0, 0, 0, encoded[17], encoded[18], encoded[19], encoded[20])).long
private val podSequenceNumber: Long val podSequenceNumber: Long = ByteBuffer.wrap(byteArrayOf(0, 0, 0, 0, encoded[21], encoded[22], encoded[23], encoded[24])).long
private val uniqueIdReceivedInCommand: Long val uniqueIdReceivedInCommand: Long = ByteBuffer.wrap(byteArrayOf(0, 0, 0, 0, encoded[25], encoded[26], encoded[27], encoded[28])).long
fun getMessageType(): Byte {
return messageType
}
fun getMessageLength(): Short { // TODO value getters
return messageLength
}
fun getPulseVolumeInTenThousandthMicroLiter(): Short {
return pulseVolumeInTenThousandthMicroLiter
}
fun getDeliveryRate(): Short {
return pumpRate
}
fun getPrimeRate(): Short {
return primePumpRate
}
fun getNumberOfEngagingClutchDrivePulses(): Short {
return numberOfEngagingClutchDrivePulses
}
fun getNumberOfPrimePulses(): Short {
return numberOfPrimePulses
}
fun getPodExpirationTimeInHours(): Short {
return podExpirationTimeInHours
}
fun getFirmwareVersionMajor(): Short {
return firmwareVersionMajor
}
fun getFirmwareVersionMinor(): Short {
return firmwareVersionMinor
}
fun getFirmwareVersionInterim(): Short {
return firmwareVersionInterim
}
fun getBleVersionMajor(): Short {
return bleVersionMajor
}
fun getBleVersionMinor(): Short {
return bleVersionMinor
}
fun getBleVersionInterim(): Short {
return bleVersionInterim
}
fun getProductId(): Short {
return productId
}
fun getPodStatus(): PodStatus {
return podStatus
}
fun getLotNumber(): Long {
return lotNumber
}
fun getPodSequenceNumber(): Long {
return podSequenceNumber
}
fun getUniqueIdReceivedInCommand(): Long {
return uniqueIdReceivedInCommand
}
override fun toString(): String { override fun toString(): String {
return "SetUniqueIdResponse{" + return "SetUniqueIdResponse{" +
@ -132,25 +56,4 @@ class SetUniqueIdResponse(
'}' '}'
} }
init {
messageType = encoded[0]
messageLength = (encoded[1].toInt() and 0xff).toShort()
pulseVolumeInTenThousandthMicroLiter = ByteBuffer.wrap(byteArrayOf(encoded[2], encoded[3])).short
pumpRate = (encoded[4].toInt() and 0xff).toShort()
primePumpRate = (encoded[5].toInt() and 0xff).toShort()
numberOfEngagingClutchDrivePulses = (encoded[6].toInt() and 0xff).toShort()
numberOfPrimePulses = (encoded[7].toInt() and 0xff).toShort()
podExpirationTimeInHours = (encoded[8].toInt() and 0xff).toShort()
firmwareVersionMajor = (encoded[9].toInt() and 0xff).toShort()
firmwareVersionMinor = (encoded[10].toInt() and 0xff).toShort()
firmwareVersionInterim = (encoded[11].toInt() and 0xff).toShort()
bleVersionMajor = (encoded[12].toInt() and 0xff).toShort()
bleVersionMinor = (encoded[13].toInt() and 0xff).toShort()
bleVersionInterim = (encoded[14].toInt() and 0xff).toShort()
productId = (encoded[15].toInt() and 0xff).toShort()
podStatus = byValue(encoded[16], PodStatus.UNKNOWN)
lotNumber = ByteBuffer.wrap(byteArrayOf(0, 0, 0, 0, encoded[17], encoded[18], encoded[19], encoded[20])).long
podSequenceNumber = ByteBuffer.wrap(byteArrayOf(0, 0, 0, 0, encoded[21], encoded[22], encoded[23], encoded[24])).long
uniqueIdReceivedInCommand = ByteBuffer.wrap(byteArrayOf(0, 0, 0, 0, encoded[25], encoded[26], encoded[27], encoded[28])).long
}
} }

View file

@ -11,81 +11,21 @@ class VersionResponse(
encoded: ByteArray encoded: ByteArray
) : ActivationResponseBase(ActivationResponseType.GET_VERSION_RESPONSE, encoded) { ) : ActivationResponseBase(ActivationResponseType.GET_VERSION_RESPONSE, encoded) {
private val messageType: Byte = encoded[0] val messageType: Byte = encoded[0]
private val messageLength: Short = (encoded[1].toInt() and 0xff).toShort() val messageLength: Short = (encoded[1].toInt() and 0xff).toShort()
private val firmwareVersionMajor: Short = (encoded[2].toInt() and 0xff).toShort() val firmwareVersionMajor: Short = (encoded[2].toInt() and 0xff).toShort()
private val firmwareVersionMinor: Short = (encoded[3].toInt() and 0xff).toShort() val firmwareVersionMinor: Short = (encoded[3].toInt() and 0xff).toShort()
private val firmwareVersionInterim: Short = (encoded[4].toInt() and 0xff).toShort() val firmwareVersionInterim: Short = (encoded[4].toInt() and 0xff).toShort()
private val bleVersionMajor: Short = (encoded[5].toInt() and 0xff).toShort() val bleVersionMajor: Short = (encoded[5].toInt() and 0xff).toShort()
private val bleVersionMinor: Short = (encoded[6].toInt() and 0xff).toShort() val bleVersionMinor: Short = (encoded[6].toInt() and 0xff).toShort()
private val bleVersionInterim: Short = (encoded[7].toInt() and 0xff).toShort() val bleVersionInterim: Short = (encoded[7].toInt() and 0xff).toShort()
private val productId: Short = (encoded[8].toInt() and 0xff).toShort() val productId: Short = (encoded[8].toInt() and 0xff).toShort()
private val podStatus: PodStatus = byValue((encoded[9] and 0xf), PodStatus.UNKNOWN) val podStatus: PodStatus = byValue((encoded[9] and 0xf), PodStatus.UNKNOWN)
private val lotNumber: Long = ByteBuffer.wrap(byteArrayOf(0, 0, 0, 0, encoded[10], encoded[11], encoded[12], encoded[13])).long val lotNumber: Long = ByteBuffer.wrap(byteArrayOf(0, 0, 0, 0, encoded[10], encoded[11], encoded[12], encoded[13])).long
private val podSequenceNumber: Long = ByteBuffer.wrap(byteArrayOf(0, 0, 0, 0, encoded[14], encoded[15], encoded[16], encoded[17])).long val podSequenceNumber: Long = ByteBuffer.wrap(byteArrayOf(0, 0, 0, 0, encoded[14], encoded[15], encoded[16], encoded[17])).long
private val rssi: Byte = (encoded[18] and 0x3f) val rssi: Byte = (encoded[18] and 0x3f)
private val receiverLowerGain: Byte = ((encoded[18].toInt() shr 6 and 0x03).toByte()) val receiverLowerGain: Byte = ((encoded[18].toInt() shr 6 and 0x03).toByte())
private val uniqueIdReceivedInCommand: Long = ByteBuffer.wrap(byteArrayOf(0, 0, 0, 0, encoded[19], encoded[20], encoded[21], encoded[22])).long val uniqueIdReceivedInCommand: Long = ByteBuffer.wrap(byteArrayOf(0, 0, 0, 0, encoded[19], encoded[20], encoded[21], encoded[22])).long
fun getMessageType(): Byte {
return messageType
}
fun getMessageLength(): Short {
return messageLength
}
fun getFirmwareVersionMajor(): Short {
return firmwareVersionMajor
}
fun getFirmwareVersionMinor(): Short {
return firmwareVersionMinor
}
fun getFirmwareVersionInterim(): Short {
return firmwareVersionInterim
}
fun getBleVersionMajor(): Short {
return bleVersionMajor
}
fun getBleVersionMinor(): Short {
return bleVersionMinor
}
fun getBleVersionInterim(): Short {
return bleVersionInterim
}
fun getProductId(): Short {
return productId
}
fun getPodStatus(): PodStatus {
return podStatus
}
fun getLotNumber(): Long {
return lotNumber
}
fun getPodSequenceNumber(): Long {
return podSequenceNumber
}
fun getRssi(): Byte {
return rssi
}
fun getReceiverLowerGain(): Byte {
return receiverLowerGain
}
fun getUniqueIdReceivedInCommand(): Long {
return uniqueIdReceivedInCommand
}
override fun toString(): String { override fun toString(): String {
return "VersionResponse{" + return "VersionResponse{" +

View file

@ -36,14 +36,18 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
// TODO: dynamic get() fun instead of assignment // TODO: dynamic get() fun instead of assignment
override val isUniqueIdSet: Boolean = activationProgress.isAtLeast(ActivationProgress.SET_UNIQUE_ID) override val isUniqueIdSet: Boolean
get() = activationProgress.isAtLeast(ActivationProgress.SET_UNIQUE_ID)
override val isActivationCompleted: Boolean = activationProgress == ActivationProgress.COMPLETED override val isActivationCompleted: Boolean
get() = activationProgress == ActivationProgress.COMPLETED
override val isSuspended: Boolean = podState.deliveryStatus?.equals(DeliveryStatus.SUSPENDED) override val isSuspended: Boolean
get() = podState.deliveryStatus?.equals(DeliveryStatus.SUSPENDED)
?: true ?: true
override val isPodRunning: Boolean = podState.podStatus?.isRunning() ?: false override val isPodRunning: Boolean
get() = podState.podStatus?.isRunning() ?: false
override var lastConnection: Long override var lastConnection: Long
get() = podState.lastConnection get() = podState.lastConnection
@ -52,54 +56,77 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
store() store()
} }
override val lastUpdated: Long = podState.lastUpdated override val lastUpdated: Long
get() = podState.lastUpdated
override val messageSequenceNumber: Short = podState.messageSequenceNumber override val messageSequenceNumber: Short
get() = podState.messageSequenceNumber
override val sequenceNumberOfLastProgrammingCommand: Short? = podState.sequenceNumberOfLastProgrammingCommand override val sequenceNumberOfLastProgrammingCommand: Short?
get() = podState.sequenceNumberOfLastProgrammingCommand
override val activationTime: Long? = podState.activationTime override val activationTime: Long?
get() = podState.activationTime
override val uniqueId: Long? = podState.uniqueId override val uniqueId: Long?
get() = podState.uniqueId
override val bluetoothAddress: String? = podState.bluetoothAddress override val bluetoothAddress: String?
get() = podState.bluetoothAddress
override val bluetoothVersion: SoftwareVersion? = podState.bleVersion override val bluetoothVersion: SoftwareVersion?
get() = podState.bleVersion
override val firmwareVersion: SoftwareVersion? = podState.firmwareVersion override val firmwareVersion: SoftwareVersion?
get() = podState.firmwareVersion
override val lotNumber: Long? = podState.lotNumber override val lotNumber: Long?
get() = podState.lotNumber
override val podSequenceNumber: Long? = podState.podSequenceNumber override val podSequenceNumber: Long?
get() = podState.podSequenceNumber
override val pulseRate: Short? = podState.pulseRate override val pulseRate: Short?
get() = podState.pulseRate
override val primePulseRate: Short? = podState.primePulseRate override val primePulseRate: Short?
get() = podState.primePulseRate
override val podLifeInHours: Short? = podState.podLifeInHours override val podLifeInHours: Short?
get() = podState.podLifeInHours
override val firstPrimeBolusVolume: Short? = podState.firstPrimeBolusVolume override val firstPrimeBolusVolume: Short?
get() = podState.firstPrimeBolusVolume
override val secondPrimeBolusVolume: Short? = podState.secondPrimeBolusVolume override val secondPrimeBolusVolume: Short?
get() = podState.secondPrimeBolusVolume
override val pulsesDelivered: Short? = podState.pulsesDelivered override val pulsesDelivered: Short?
get() = podState.pulsesDelivered
override val pulsesRemaining: Short? = podState.pulsesRemaining override val pulsesRemaining: Short?
get() = podState.pulsesRemaining
override val podStatus: PodStatus? = podState.podStatus override val podStatus: PodStatus?
get() = podState.podStatus
override val deliveryStatus: DeliveryStatus? = podState.deliveryStatus override val deliveryStatus: DeliveryStatus?
get() = podState.deliveryStatus
override val minutesSinceActivation: Short? = podState.minutesSinceActivation override val minutesSinceActivation: Short?
get() = podState.minutesSinceActivation
override val activeAlerts: EnumSet<AlertSlot>? = podState.activeAlerts override val activeAlerts: EnumSet<AlertSlot>?
get() = podState.activeAlerts
override val tempBasal: OmnipodDashPodStateManager.TempBasal? = podState.tempBasal override val tempBasal: OmnipodDashPodStateManager.TempBasal?
get() = podState.tempBasal
override val tempBasalActive: Boolean override val tempBasalActive: Boolean
get() = tempBasal != null && tempBasal.startTime + tempBasal.durationInMinutes * 60 * 1000 > System.currentTimeMillis() get() = tempBasal != null && tempBasal!!.startTime + tempBasal!!.durationInMinutes * 60 * 1000 > System.currentTimeMillis()
override val basalProgram: BasalProgram? = podState.basalProgram override val basalProgram: BasalProgram?
get() = podState.basalProgram
override fun increaseMessageSequenceNumber() { override fun increaseMessageSequenceNumber() {
podState.messageSequenceNumber = ((podState.messageSequenceNumber.toInt() + 1) and 0x0f).toShort() podState.messageSequenceNumber = ((podState.messageSequenceNumber.toInt() + 1) and 0x0f).toShort()
@ -121,28 +148,28 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
} }
override fun updateFromVersionResponse(response: VersionResponse) { override fun updateFromVersionResponse(response: VersionResponse) {
podState.bleVersion = SoftwareVersion(response.getBleVersionMajor(), response.getBleVersionMinor(), response.getBleVersionInterim()) podState.bleVersion = SoftwareVersion(response.bleVersionMajor, response.bleVersionMinor, response.bleVersionInterim)
podState.firmwareVersion = SoftwareVersion(response.getFirmwareVersionMajor(), response.getFirmwareVersionMinor(), response.getFirmwareVersionInterim()) podState.firmwareVersion = SoftwareVersion(response.firmwareVersionMajor, response.firmwareVersionMinor, response.firmwareVersionInterim)
podState.podStatus = response.getPodStatus() podState.podStatus = response.podStatus
podState.lotNumber = response.getLotNumber() podState.lotNumber = response.lotNumber
podState.podSequenceNumber = response.getPodSequenceNumber() podState.podSequenceNumber = response.podSequenceNumber
podState.lastUpdated = System.currentTimeMillis() podState.lastUpdated = System.currentTimeMillis()
store() store()
} }
override fun updateFromSetUniqueIdResponse(response: SetUniqueIdResponse) { override fun updateFromSetUniqueIdResponse(response: SetUniqueIdResponse) {
podState.pulseRate = response.getDeliveryRate() podState.pulseRate = response.pumpRate
podState.primePulseRate = response.getPrimeRate() podState.primePulseRate = response.primePumpRate
podState.firstPrimeBolusVolume = response.getNumberOfPrimePulses() podState.firstPrimeBolusVolume = response.numberOfPrimePulses
podState.secondPrimeBolusVolume = response.getNumberOfEngagingClutchDrivePulses() podState.secondPrimeBolusVolume = response.numberOfEngagingClutchDrivePulses
podState.podLifeInHours = response.getPodExpirationTimeInHours() podState.podLifeInHours = response.podExpirationTimeInHours
podState.bleVersion = SoftwareVersion(response.getBleVersionMajor(), response.getBleVersionMinor(), response.getBleVersionInterim()) podState.bleVersion = SoftwareVersion(response.bleVersionMajor, response.bleVersionMinor, response.bleVersionInterim)
podState.firmwareVersion = SoftwareVersion(response.getFirmwareVersionMajor(), response.getFirmwareVersionMinor(), response.getFirmwareVersionInterim()) podState.firmwareVersion = SoftwareVersion(response.firmwareVersionMajor, response.firmwareVersionMinor, response.firmwareVersionInterim)
podState.podStatus = response.getPodStatus() podState.podStatus = response.podStatus
podState.lotNumber = response.getLotNumber() podState.lotNumber = response.lotNumber
podState.podSequenceNumber = response.getPodSequenceNumber() podState.podSequenceNumber = response.podSequenceNumber
podState.uniqueId = response.getUniqueIdReceivedInCommand() podState.uniqueId = response.uniqueIdReceivedInCommand
podState.lastUpdated = System.currentTimeMillis() podState.lastUpdated = System.currentTimeMillis()
store() store()

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodStatus import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodStatus
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.ResponseType
import org.apache.commons.codec.DecoderException import org.apache.commons.codec.DecoderException
import org.apache.commons.codec.binary.Hex import org.apache.commons.codec.binary.Hex
import org.junit.Assert import org.junit.Assert
@ -17,24 +16,24 @@ class SetUniqueIdResponseTest {
Assert.assertNotSame(encoded, response.encoded) Assert.assertNotSame(encoded, response.encoded)
Assert.assertEquals(ResponseType.ACTIVATION_RESPONSE, response.responseType) Assert.assertEquals(ResponseType.ACTIVATION_RESPONSE, response.responseType)
Assert.assertEquals(ResponseType.ActivationResponseType.SET_UNIQUE_ID_RESPONSE, response.activationResponseType) Assert.assertEquals(ResponseType.ActivationResponseType.SET_UNIQUE_ID_RESPONSE, response.activationResponseType)
Assert.assertEquals(ResponseType.ACTIVATION_RESPONSE.value, response.getMessageType()) Assert.assertEquals(ResponseType.ACTIVATION_RESPONSE.value, response.messageType)
Assert.assertEquals(27.toShort(), response.getMessageLength()) Assert.assertEquals(27.toShort(), response.messageLength)
Assert.assertEquals(5000.toShort(), response.getPulseVolumeInTenThousandthMicroLiter()) Assert.assertEquals(5000.toShort(), response.pulseVolumeInTenThousandthMicroLiter)
Assert.assertEquals(16.toShort(), response.getDeliveryRate()) Assert.assertEquals(16.toShort(), response.pumpRate)
Assert.assertEquals(8.toShort(), response.getPrimeRate()) Assert.assertEquals(8.toShort(), response.primePumpRate)
Assert.assertEquals(52.toShort(), response.getNumberOfEngagingClutchDrivePulses()) Assert.assertEquals(52.toShort(), response.numberOfEngagingClutchDrivePulses)
Assert.assertEquals(10.toShort(), response.getNumberOfPrimePulses()) Assert.assertEquals(10.toShort(), response.numberOfPrimePulses)
Assert.assertEquals(80.toShort(), response.getPodExpirationTimeInHours()) Assert.assertEquals(80.toShort(), response.podExpirationTimeInHours)
Assert.assertEquals(4.toShort(), response.getFirmwareVersionMajor()) Assert.assertEquals(4.toShort(), response.firmwareVersionMajor)
Assert.assertEquals(10.toShort(), response.getFirmwareVersionMinor()) Assert.assertEquals(10.toShort(), response.firmwareVersionMinor)
Assert.assertEquals(0.toShort(), response.getFirmwareVersionInterim()) Assert.assertEquals(0.toShort(), response.firmwareVersionInterim)
Assert.assertEquals(1.toShort(), response.getBleVersionMajor()) Assert.assertEquals(1.toShort(), response.bleVersionMajor)
Assert.assertEquals(3.toShort(), response.getBleVersionMinor()) Assert.assertEquals(3.toShort(), response.bleVersionMinor)
Assert.assertEquals(0.toShort(), response.getBleVersionInterim()) Assert.assertEquals(0.toShort(), response.bleVersionInterim)
Assert.assertEquals(4.toShort(), response.getProductId()) Assert.assertEquals(4.toShort(), response.productId)
Assert.assertEquals(PodStatus.UID_SET, response.getPodStatus()) Assert.assertEquals(PodStatus.UID_SET, response.podStatus)
Assert.assertEquals(135556289L, response.getLotNumber()) Assert.assertEquals(135556289L, response.lotNumber)
Assert.assertEquals(611540L, response.getPodSequenceNumber()) Assert.assertEquals(611540L, response.podSequenceNumber)
Assert.assertEquals(37879809L, response.getUniqueIdReceivedInCommand()) Assert.assertEquals(37879809L, response.uniqueIdReceivedInCommand)
} }
} }

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodStatus import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodStatus
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.ResponseType
import org.apache.commons.codec.DecoderException import org.apache.commons.codec.DecoderException
import org.apache.commons.codec.binary.Hex import org.apache.commons.codec.binary.Hex
import org.junit.Assert import org.junit.Assert
@ -17,20 +16,20 @@ class VersionResponseTest {
Assert.assertNotSame(encoded, response.encoded) Assert.assertNotSame(encoded, response.encoded)
Assert.assertEquals(ResponseType.ACTIVATION_RESPONSE, response.responseType) Assert.assertEquals(ResponseType.ACTIVATION_RESPONSE, response.responseType)
Assert.assertEquals(ResponseType.ActivationResponseType.GET_VERSION_RESPONSE, response.activationResponseType) Assert.assertEquals(ResponseType.ActivationResponseType.GET_VERSION_RESPONSE, response.activationResponseType)
Assert.assertEquals(ResponseType.ACTIVATION_RESPONSE.value, response.getMessageType()) Assert.assertEquals(ResponseType.ACTIVATION_RESPONSE.value, response.messageType)
Assert.assertEquals(21.toShort(), response.getMessageLength()) Assert.assertEquals(21.toShort(), response.messageLength)
Assert.assertEquals(4.toShort(), response.getFirmwareVersionMajor()) Assert.assertEquals(4.toShort(), response.firmwareVersionMajor)
Assert.assertEquals(10.toShort(), response.getFirmwareVersionMinor()) Assert.assertEquals(10.toShort(), response.firmwareVersionMinor)
Assert.assertEquals(0.toShort(), response.getFirmwareVersionInterim()) Assert.assertEquals(0.toShort(), response.firmwareVersionInterim)
Assert.assertEquals(1.toShort(), response.getBleVersionMajor()) Assert.assertEquals(1.toShort(), response.bleVersionMajor)
Assert.assertEquals(3.toShort(), response.getBleVersionMinor()) Assert.assertEquals(3.toShort(), response.bleVersionMinor)
Assert.assertEquals(0.toShort(), response.getBleVersionInterim()) Assert.assertEquals(0.toShort(), response.bleVersionInterim)
Assert.assertEquals(4.toShort(), response.getProductId()) Assert.assertEquals(4.toShort(), response.productId)
Assert.assertEquals(PodStatus.FILLED, response.getPodStatus()) Assert.assertEquals(PodStatus.FILLED, response.podStatus)
Assert.assertEquals(135556289L, response.getLotNumber()) Assert.assertEquals(135556289L, response.lotNumber)
Assert.assertEquals(611540L, response.getPodSequenceNumber()) Assert.assertEquals(611540L, response.podSequenceNumber)
Assert.assertEquals(0.toByte(), response.getRssi()) Assert.assertEquals(0.toByte(), response.rssi)
Assert.assertEquals(0.toByte(), response.getReceiverLowerGain()) Assert.assertEquals(0.toByte(), response.receiverLowerGain)
Assert.assertEquals(4294967295L, response.getUniqueIdReceivedInCommand()) Assert.assertEquals(4294967295L, response.uniqueIdReceivedInCommand)
} }
} }