From d14789cf029b4506c5d54821f2ec4be0be6a1a40 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Sun, 1 Sep 2019 23:30:11 +0200 Subject: [PATCH] Apply new understandings of beep types --- .../message/command/BeepConfigCommand.java | 8 ++-- .../pump/omnipod/defs/BeepConfigType.java | 41 +++++++++++++++++++ .../plugins/pump/omnipod/defs/BeepType.java | 8 +--- .../comm/action/service/PairServiceTest.java | 4 +- .../command/BeepConfigCommandTest.java | 6 +-- .../message/response/StatusResponseTest.java | 6 +-- 6 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/BeepConfigType.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommand.java index 6e77a7f5d1..09c1290d1f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommand.java @@ -4,11 +4,11 @@ import org.joda.time.Duration; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.MessageBlock; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.BeepType; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.BeepConfigType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.MessageBlockType; public class BeepConfigCommand extends MessageBlock { - private final BeepType beepType; + private final BeepConfigType beepType; private final boolean basalCompletionBeep; private final Duration basalIntervalBeep; private final boolean tempBasalCompletionBeep; @@ -16,7 +16,7 @@ public class BeepConfigCommand extends MessageBlock { private final boolean bolusCompletionBeep; private final Duration bolusIntervalBeep; - public BeepConfigCommand(BeepType beepType, boolean basalCompletionBeep, Duration basalIntervalBeep, + public BeepConfigCommand(BeepConfigType beepType, boolean basalCompletionBeep, Duration basalIntervalBeep, boolean tempBasalCompletionBeep, Duration tempBasalIntervalBeep, boolean bolusCompletionBeep, Duration bolusIntervalBeep) { this.beepType = beepType; @@ -30,7 +30,7 @@ public class BeepConfigCommand extends MessageBlock { encode(); } - public BeepConfigCommand(BeepType beepType) { + public BeepConfigCommand(BeepConfigType beepType) { this(beepType, false, Duration.ZERO, false, Duration.ZERO, false, Duration.ZERO); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/BeepConfigType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/BeepConfigType.java new file mode 100644 index 0000000000..3ef731e5c8 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/BeepConfigType.java @@ -0,0 +1,41 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.defs; + + +// BeepConfigType is used only for the $1E Beep Config Command. +public enum BeepConfigType { + // 0x0 always returns an error response for Beep Config (use 0xF for no beep) + BEEP_BEEP_BEEP_BEEP((byte) 0x01), + BIP_BEEP_BIP_BEEP_BIP_BEEP_BIP_BEEP((byte) 0x02), + BIP_BIP((byte) 0x03), + BEEP((byte) 0x04), + BEEP_BEEP_BEEP((byte) 0x05), + BEEEEEEP((byte) 0x06), + BIP_BIP_BIP_BIP_BIP_BIP((byte) 0x07), + BEEEP_BEEEP((byte) 0x08), + // 0x9 and 0xA always return an error response for Beep Config + BEEP_BEEP((byte) 0xB), + BEEEP((byte) 0xC), + BIP_BEEEEEP((byte) 0xD), + FIVE_SECONDS_BEEP((byte) 0xE), // can only be used if Pod is currently suspended + NO_BEEP((byte) 0xF); + + private byte value; + + BeepConfigType(byte value) { + this.value = value; + } + + public static BeepConfigType fromByte(byte value) { + for (BeepConfigType type : values()) { + if (type.value == value) { + return type; + } + } + throw new IllegalArgumentException("Unknown BeepConfigType: " + value); + } + + public byte getValue() { + return value; + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/BeepType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/BeepType.java index 7cf08b8714..e230276467 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/BeepType.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/BeepType.java @@ -1,5 +1,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.defs; +// BeepType is used for the $19 Configure Alerts and $1F Cancel Commands public enum BeepType { NO_BEEP((byte) 0x00), BEEP_BEEP_BEEP_BEEP((byte) 0x01), @@ -9,12 +10,7 @@ public enum BeepType { BEEP_BEEP_BEEP((byte) 0x05), BEEEEEEP((byte) 0x06), BIP_BIP_BIP_BIP_BIP_BIP((byte) 0x07), - BEEEP_BEEEP((byte) 0x08), - BEEP_BEEP((byte) 0xB), - BEEEP((byte) 0xC), - BIP_BEEEEEP((byte) 0xD), - FIVE_SECONDS_BEEP((byte) 0xE), - BEEP_CONFIG_NO_BEEP((byte) 0xF); + BEEEP_BEEEP((byte) 0x08); private byte value; diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/service/PairServiceTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/service/PairServiceTest.java index fe7773ff7b..4800d38ee2 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/service/PairServiceTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/service/PairServiceTest.java @@ -7,12 +7,12 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodMessage; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.VersionResponse; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSetupState; +import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -47,7 +47,7 @@ public class PairServiceTest { VersionResponse versionResponse = new PairService().executeAssignAddressCommand(communicationService, setupState); // verify - verify(communicationService).exchangeMessages(eq(VersionResponse.class), eq(setupState), messageCaptor.capture(), eq(Constants.DEFAULT_ADDRESS), eq(0x1f173217)); + verify(communicationService).exchangeMessages(eq(VersionResponse.class), eq(setupState), messageCaptor.capture(), eq(OmnipodConst.DEFAULT_ADDRESS), eq(0x1f173217)); verifyNoMoreInteractions(communicationService); verifyZeroInteractions(response); diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommandTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommandTest.java index fc04d3f6c8..5435e477d7 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommandTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommandTest.java @@ -4,14 +4,14 @@ import org.joda.time.Duration; import org.junit.Test; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.BeepType; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.BeepConfigType; import static org.junit.Assert.assertArrayEquals; public class BeepConfigCommandTest { @Test public void testConfidenceReminders() { - BeepConfigCommand beepConfigCommand = new BeepConfigCommand(BeepType.BIP_BEEP_BIP_BEEP_BIP_BEEP_BIP_BEEP, true, + BeepConfigCommand beepConfigCommand = new BeepConfigCommand(BeepConfigType.BIP_BEEP_BIP_BEEP_BIP_BEEP_BIP_BEEP, true, Duration.ZERO, true, Duration.ZERO, true, Duration.ZERO); assertArrayEquals(ByteUtil.fromHexString("1e0402404040"), beepConfigCommand.getRawData()); @@ -19,7 +19,7 @@ public class BeepConfigCommandTest { @Test public void testProgramReminders() { - BeepConfigCommand beepConfigCommand = new BeepConfigCommand(BeepType.BEEP_CONFIG_NO_BEEP, true, + BeepConfigCommand beepConfigCommand = new BeepConfigCommand(BeepConfigType.NO_BEEP, true, Duration.ZERO, false, Duration.standardMinutes(60), false, Duration.standardMinutes(60)); assertArrayEquals(ByteUtil.fromHexString("1e040f403c3c"), beepConfigCommand.getRawData()); diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponseTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponseTest.java index 6ac202622a..2c74ed1f74 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponseTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponseTest.java @@ -3,10 +3,10 @@ package info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response; import org.joda.time.Duration; import org.junit.Test; -import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryStatus; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus; +import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -58,9 +58,9 @@ public class StatusResponseTest { StatusResponse statusResponse = new StatusResponse(bytes); assertEquals(Duration.standardMinutes(8191).getMillis(), statusResponse.getTimeActive().getMillis()); - assertEquals(Constants.POD_PULSE_SIZE * 1023, statusResponse.getInsulinNotDelivered(), 0.000001); + assertEquals(OmnipodConst.POD_PULSE_SIZE * 1023, statusResponse.getInsulinNotDelivered(), 0.000001); assertNull("Reservoir level should be null", statusResponse.getReservoirLevel()); - assertEquals(Constants.POD_PULSE_SIZE * 8191, statusResponse.getInsulin(), 0.0000001); + assertEquals(OmnipodConst.POD_PULSE_SIZE * 8191, statusResponse.getInsulin(), 0.0000001); assertEquals(15, statusResponse.getPodMessageCounter()); assertEquals(8, statusResponse.getAlerts().getAlertSlots().size()); }