diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/response/DefaultStatusResponse.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/response/DefaultStatusResponse.kt index 1b64063954..584349de78 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/response/DefaultStatusResponse.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/response/DefaultStatusResponse.kt @@ -16,7 +16,8 @@ class DefaultStatusResponse( val deliveryStatus: DeliveryStatus = byValue((encoded[1].toInt() shr 4 and 0x0f).toByte(), DeliveryStatus.UNKNOWN) val podStatus: PodStatus = byValue((encoded[1] and 0x0f), PodStatus.UNKNOWN) val totalPulsesDelivered: Short = - ((encoded[2] and 0x0f shl 12 or (encoded[3].toInt() and 0xff shl 1) or (encoded[4].toInt() and 0xff ushr 7)).toShort()) + (encoded[2] and 0x0f shl 9 or (encoded[3].toInt() and 0xff shl 1) or (encoded[4].toInt() and 0xff ushr 7)).toShort() + val sequenceNumberOfLastProgrammingCommand: Short = (encoded[4] ushr 3 and 0x0f).toShort() val bolusPulsesRemaining: Short = ((encoded[4] and 0x07 shl 10 or (encoded[5].toInt() and 0xff) and 2047).toShort()) val activeAlerts: EnumSet = diff --git a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/response/DefaultStatusResponseTest.kt b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/response/DefaultStatusResponseTest.kt index f24e02e87c..9de6513fd4 100644 --- a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/response/DefaultStatusResponseTest.kt +++ b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/response/DefaultStatusResponseTest.kt @@ -25,4 +25,82 @@ class DefaultStatusResponseTest { Assert.assertEquals(280.toShort(), response.minutesSinceActivation) Assert.assertEquals(1023.toShort(), response.reservoirPulsesRemaining) } + + /** + * response (hex) 08202EAA0C0A1D1905281000004387D3039A + Status response: 29 + Pod status: RUNNING_BELOW_MIN_VOLUME + Basal active: true + Temp Basal active: false + Immediate bolus active: false + Extended bolus active: false + Bolus pulses remaining: 0 + sequence number of last programing command: 2 + Total full pulses delivered: 2640 + Full reservoir pulses remaining: 979 + Time since activation: 4321 + Alert 1 is InActive + Alert 2 is InActive + Alert 3 is InActive + Alert 4 is InActive + Alert 5 is InActive + Alert 6 is InActive + Alert 7 is InActive + Occlusion alert active false + */ + @Test @Throws(DecoderException::class) fun testValidResponseBelowMin() { + val encoded = Hex.decodeHex("1D1905281000004387D3039A") + val response = DefaultStatusResponse(encoded) + Assert.assertArrayEquals(encoded, response.encoded) + Assert.assertNotSame(encoded, response.encoded) + Assert.assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE, response.responseType) + Assert.assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE.value, response.messageType) + Assert.assertEquals(DeliveryStatus.BASAL_ACTIVE, response.deliveryStatus) + Assert.assertEquals(PodStatus.RUNNING_BELOW_MIN_VOLUME, response.podStatus) + Assert.assertEquals(2.toShort(), response.sequenceNumberOfLastProgrammingCommand) + Assert.assertEquals(0.toShort(), response.bolusPulsesRemaining) + Assert.assertEquals(0, response.activeAlerts.size) + Assert.assertEquals(4321.toShort(), response.minutesSinceActivation) + Assert.assertEquals(979.toShort(), response.reservoirPulsesRemaining) + Assert.assertEquals(2640.toShort(), response.totalPulsesDelivered) + } + + /** + * response (hex) 08202EAA080A1D180519C00E0039A7FF8085 + Status response: 29 + Pod status: RUNNING_ABOVE_MIN_VOLUME + Basal active: true + Temp Basal active: false + Immediate bolus active: false + Extended bolus active: false + Bolus pulses remaining: 14 + sequence number of last programing command: 8 + Total full pulses delivered: 2611 + Full reservoir pulses remaining: 1023 + Time since activation: 3689 + Alert 1 is InActive + Alert 2 is InActive + Alert 3 is InActive + Alert 4 is InActive + Alert 5 is InActive + Alert 6 is InActive + Alert 7 is InActive + Occlusion alert active false + */ + @Test @Throws(DecoderException::class) fun testValidResponseBolusPulsesRemaining() { + val encoded = Hex.decodeHex("1D180519C00E0039A7FF8085") + val response = DefaultStatusResponse(encoded) + Assert.assertArrayEquals(encoded, response.encoded) + Assert.assertNotSame(encoded, response.encoded) + Assert.assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE, response.responseType) + Assert.assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE.value, response.messageType) + Assert.assertEquals(DeliveryStatus.BASAL_ACTIVE, response.deliveryStatus) + Assert.assertEquals(PodStatus.RUNNING_ABOVE_MIN_VOLUME, response.podStatus) + Assert.assertEquals(8.toShort(), response.sequenceNumberOfLastProgrammingCommand) + Assert.assertEquals(14.toShort(), response.bolusPulsesRemaining) + Assert.assertEquals(0, response.activeAlerts.size) + Assert.assertEquals(3689.toShort(), response.minutesSinceActivation) + Assert.assertEquals(1023.toShort(), response.reservoirPulsesRemaining) + Assert.assertEquals(2611.toShort(), response.totalPulsesDelivered) + } }