Add StopDeliveryCommand, add test for NakResponse
This commit is contained in:
parent
93e4e924fa
commit
e7e6f52305
|
@ -0,0 +1,55 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.BitSet;
|
||||
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BeepType;
|
||||
|
||||
public class StopDeliveryCommand extends CommandBase {
|
||||
private static final short LENGTH = 7;
|
||||
private static final byte BODY_LENGTH = 5;
|
||||
|
||||
private final DeliveryType deliveryType;
|
||||
private final BeepType beepType;
|
||||
|
||||
public StopDeliveryCommand(int address, short sequenceNumber, boolean unknown, DeliveryType deliveryType, BeepType beepType) {
|
||||
super(CommandType.STOP_DELIVERY, address, sequenceNumber, unknown);
|
||||
this.deliveryType = deliveryType;
|
||||
this.beepType = beepType;
|
||||
}
|
||||
|
||||
@Override public byte[] getEncoded() {
|
||||
return appendCrc(ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
|
||||
.put(encodeHeader(address, sequenceNumber, LENGTH, unknown)) //
|
||||
.put(commandType.getValue()) //
|
||||
.put(BODY_LENGTH) //
|
||||
.putInt(1229869870) // FIXME ?? was: byte array of int 777211465 converted to little endian
|
||||
.put((byte) ((beepType.getValue() << 4) | deliveryType.getEncoded())) //
|
||||
.array());
|
||||
}
|
||||
|
||||
public enum DeliveryType {
|
||||
BASAL(true, false, false),
|
||||
TEMP_BASAL(false, true, false),
|
||||
BOLUS(false, false, true),
|
||||
ALL(true, true, true);
|
||||
|
||||
private final boolean basal;
|
||||
private final boolean tempBasal;
|
||||
private final boolean bolus;
|
||||
|
||||
DeliveryType(boolean basal, boolean tempBasal, boolean bolus) {
|
||||
this.basal = basal;
|
||||
this.tempBasal = tempBasal;
|
||||
this.bolus = bolus;
|
||||
}
|
||||
|
||||
public byte getEncoded() {
|
||||
BitSet bitSet = new BitSet(8);
|
||||
bitSet.set(0, this.basal);
|
||||
bitSet.set(1, this.tempBasal);
|
||||
bitSet.set(2, this.bolus);
|
||||
return bitSet.toByteArray()[0];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition;
|
||||
|
||||
// FIXME names
|
||||
public enum BeepType {
|
||||
SILENT((byte) 0x00),
|
||||
XXX((byte) 0x02); //// Used in low reservoir alert, user expiration alert, expiration alert, imminent expiration alert, lump of coal alert
|
||||
FOUR_TIMES_BIP_BEEP((byte) 0x02), // Used in low reservoir alert, user expiration alert, expiration alert, imminent expiration alert, lump of coal alert
|
||||
LONG_SINGLE_BEEP((byte) 0x06); // Used in stop delivery command
|
||||
|
||||
private byte value;
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ public class ProgramAlertsCommandTest {
|
|||
@Test
|
||||
public void testExpirationAlerts() throws DecoderException {
|
||||
List<AlertConfiguration> configurations = new ArrayList<>();
|
||||
configurations.add(new AlertConfiguration(AlertSlot.EXPIRATION, true, (short) 420, false, AlertTriggerType.TIME_TRIGGER, (short) 4305, BeepType.XXX, BeepRepetitionType.XXX3));
|
||||
configurations.add(new AlertConfiguration(AlertSlot.EXPIRATION_IMMINENT, true, (short) 0, false, AlertTriggerType.TIME_TRIGGER, (short) 4725, BeepType.XXX, BeepRepetitionType.XXX4));
|
||||
configurations.add(new AlertConfiguration(AlertSlot.EXPIRATION, true, (short) 420, false, AlertTriggerType.TIME_TRIGGER, (short) 4305, BeepType.FOUR_TIMES_BIP_BEEP, BeepRepetitionType.XXX3));
|
||||
configurations.add(new AlertConfiguration(AlertSlot.EXPIRATION_IMMINENT, true, (short) 0, false, AlertTriggerType.TIME_TRIGGER, (short) 4725, BeepType.FOUR_TIMES_BIP_BEEP, BeepRepetitionType.XXX4));
|
||||
|
||||
byte[] encoded = new ProgramAlertsCommand(37879811, (short) 3, true, configurations).getEncoded();
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class ProgramAlertsCommandTest {
|
|||
@Test
|
||||
public void testLowReservoirAlert() throws DecoderException {
|
||||
List<AlertConfiguration> configurations = new ArrayList<>();
|
||||
configurations.add(new AlertConfiguration(AlertSlot.LOW_RESERVOIR, true, (short) 0, false, AlertTriggerType.RESERVOIR_VOLUME_TRIGGER, (short) 200, BeepType.XXX, BeepRepetitionType.XXX));
|
||||
configurations.add(new AlertConfiguration(AlertSlot.LOW_RESERVOIR, true, (short) 0, false, AlertTriggerType.RESERVOIR_VOLUME_TRIGGER, (short) 200, BeepType.FOUR_TIMES_BIP_BEEP, BeepRepetitionType.XXX));
|
||||
|
||||
byte[] encoded = new ProgramAlertsCommand(37879811, (short) 8, false, configurations).getEncoded();
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class ProgramAlertsCommandTest {
|
|||
@Test
|
||||
public void testUserExpirationAlert() throws DecoderException {
|
||||
List<AlertConfiguration> configurations = new ArrayList<>();
|
||||
configurations.add(new AlertConfiguration(AlertSlot.USER_SET_EXPIRATION, true, (short) 0, false, AlertTriggerType.TIME_TRIGGER, (short) 4079, BeepType.XXX, BeepRepetitionType.XXX2));
|
||||
configurations.add(new AlertConfiguration(AlertSlot.USER_SET_EXPIRATION, true, (short) 0, false, AlertTriggerType.TIME_TRIGGER, (short) 4079, BeepType.FOUR_TIMES_BIP_BEEP, BeepRepetitionType.XXX2));
|
||||
|
||||
byte[] encoded = new ProgramAlertsCommand(37879811, (short) 15, false, configurations).getEncoded();
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class ProgramAlertsCommandTest {
|
|||
@Test
|
||||
public void testLumpOfCoalAlert() throws DecoderException {
|
||||
List<AlertConfiguration> configurations = new ArrayList<>();
|
||||
configurations.add(new AlertConfiguration(AlertSlot.EXPIRATION, true, (short) 55, false, AlertTriggerType.TIME_TRIGGER, (short) 5, BeepType.XXX, BeepRepetitionType.XXX5));
|
||||
configurations.add(new AlertConfiguration(AlertSlot.EXPIRATION, true, (short) 55, false, AlertTriggerType.TIME_TRIGGER, (short) 5, BeepType.FOUR_TIMES_BIP_BEEP, BeepRepetitionType.XXX5));
|
||||
|
||||
byte[] encoded = new ProgramAlertsCommand(37879811, (short) 10, false, configurations).getEncoded();
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command;
|
||||
|
||||
import org.apache.commons.codec.DecoderException;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.junit.Test;
|
||||
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BeepType;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
public class StopDeliveryCommandTest {
|
||||
@Test
|
||||
public void testStopTempBasal() throws DecoderException {
|
||||
byte[] encoded = new StopDeliveryCommand(37879811, (short) 0, false, StopDeliveryCommand.DeliveryType.TEMP_BASAL, BeepType.LONG_SINGLE_BEEP) //
|
||||
.getEncoded();
|
||||
|
||||
assertArrayEquals(Hex.decodeHex("0242000300071F05494E532E6201B1"), encoded);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuspendDelivery() throws DecoderException {
|
||||
byte[] encoded = new StopDeliveryCommand(37879811, (short) 2, false, StopDeliveryCommand.DeliveryType.ALL, BeepType.SILENT) //
|
||||
.getEncoded();
|
||||
|
||||
assertArrayEquals(Hex.decodeHex("0242000308071F05494E532E078287"), encoded);
|
||||
}
|
||||
|
||||
// TODO test cancel bolus
|
||||
}
|
|
@ -1,5 +1,30 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response;
|
||||
|
||||
// TODO capture NAK response
|
||||
import org.apache.commons.codec.DecoderException;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.junit.Test;
|
||||
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlarmType;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.NakErrorType;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodStatus;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
|
||||
public class NakResponseTest {
|
||||
@Test
|
||||
public void testValidResponse() throws DecoderException {
|
||||
byte[] encoded = Hex.decodeHex("0603070009");
|
||||
|
||||
NakResponse response = new NakResponse(encoded);
|
||||
assertArrayEquals(encoded, response.getEncoded());
|
||||
assertNotSame(encoded, response.getEncoded());
|
||||
assertEquals(ResponseType.NAK_RESPONSE, response.getResponseType());
|
||||
assertEquals(ResponseType.NAK_RESPONSE.getValue(), response.getMessageType());
|
||||
assertEquals(NakErrorType.ILLEGAL_PARAM, response.getNakErrorType());
|
||||
assertEquals(AlarmType.NONE, response.getAlarmType());
|
||||
assertEquals(PodStatus.RUNNING_BELOW_MIN_VOLUME, response.getPodStatus());
|
||||
assertEquals((byte) 0x00, response.getSecurityNakSyncCount());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue