Add DefaultStatusResponse

This commit is contained in:
Bart Sopers 2021-02-10 19:36:45 +01:00
parent eb46c973a3
commit e77f08cd23
4 changed files with 203 additions and 1 deletions

View file

@ -32,7 +32,6 @@ public class SetUniqueIdCommand extends CommandBase {
.putInt(lotNumber) //
.putInt(podSequenceNumber) //
.array());
}
private static byte[] encodeInitializationTime(Date date) {

View file

@ -0,0 +1,26 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition;
public enum DeliveryStatus {
SUSPENDED((byte) 0x00),
BASAL_ACTIVE((byte) 0x01),
TEMP_BASAL_ACTIVE((byte) 0x02),
PRIMING((byte) 0x04),
BOLUS_AND_BASAL_ACTIVE((byte) 0x05),
BOLUS_AND_TEMP_BASAL_ACTIVE((byte) 0x06),
UNKNOWN((byte) 0xff);
private byte value;
DeliveryStatus(byte value) {
this.value = value;
}
public static DeliveryStatus byValue(byte value) {
for (DeliveryStatus status : values()) {
if (status.value == value) {
return status;
}
}
return UNKNOWN;
}
}

View file

@ -0,0 +1,136 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response;
import java.util.Arrays;
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.DeliveryStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodStatus;
public class DefaultStatusResponse extends ResponseBase {
private final byte messageType;
private final DeliveryStatus deliveryStatus;
private final PodStatus podStatus;
private final short totalPulsesDelivered;
private final short sequenceNumberOfLastProgrammingCommand;
private final short bolusPulsesRemaining;
private final boolean occlusionAlertActive;
private final boolean alert1Active;
private final boolean alert2Active;
private final boolean alert3Active;
private final boolean alert4Active;
private final boolean alert5Active;
private final boolean alert6Active;
private final boolean alert7Active;
private final short minutesSinceActivation;
private final short reservoirPulsesRemaining;
public DefaultStatusResponse(byte[] encoded) {
super(ResponseType.DEFAULT_STATUS_RESPONSE, encoded);
this.messageType = encoded[0];
this.deliveryStatus = DeliveryStatus.byValue((byte) ((encoded[1] >> 4) & 0x0f));
this.podStatus = PodStatus.byValue((byte) (encoded[1] & 0x0f));
this.totalPulsesDelivered = (short) (((encoded[2] & 0x0f) << 12) | ((encoded[3] & 0xff) << 1) | ((encoded[4] & 0xff) >>> 7));
this.sequenceNumberOfLastProgrammingCommand = (byte) ((encoded[4] >>> 3) & 0x0f);
this.bolusPulsesRemaining = (short) (((encoded[4] & 0x07) << 10) | (encoded[5] & 0xff));
short activeAlerts = (short) (((encoded[6] & 0xff) << 1) | (encoded[7] >>> 7));
this.occlusionAlertActive = (activeAlerts & 1) == 1;
this.alert1Active = ((activeAlerts >> 1) & 1) == 1;
this.alert2Active = ((activeAlerts >> 2) & 1) == 1;
this.alert3Active = ((activeAlerts >> 3) & 1) == 1;
this.alert4Active = ((activeAlerts >> 4) & 1) == 1;
this.alert5Active = ((activeAlerts >> 5) & 1) == 1;
this.alert6Active = ((activeAlerts >> 6) & 1) == 1;
this.alert7Active = ((activeAlerts >> 7) & 1) == 1;
this.minutesSinceActivation = (short) (((encoded[7] & 0x7f) << 6) | (((encoded[8] & 0xff) >>> 2) & 0x3f));
this.reservoirPulsesRemaining = (short) (((encoded[8] << 8) | encoded[9]) & 0x3ff);
}
public byte getMessageType() {
return messageType;
}
public DeliveryStatus getDeliveryStatus() {
return deliveryStatus;
}
public PodStatus getPodStatus() {
return podStatus;
}
public short getTotalPulsesDelivered() {
return totalPulsesDelivered;
}
public short getSequenceNumberOfLastProgrammingCommand() {
return sequenceNumberOfLastProgrammingCommand;
}
public short getBolusPulsesRemaining() {
return bolusPulsesRemaining;
}
public boolean isOcclusionAlertActive() {
return occlusionAlertActive;
}
public boolean isAlert1Active() {
return alert1Active;
}
public boolean isAlert2Active() {
return alert2Active;
}
public boolean isAlert3Active() {
return alert3Active;
}
public boolean isAlert4Active() {
return alert4Active;
}
public boolean isAlert5Active() {
return alert5Active;
}
public boolean isAlert6Active() {
return alert6Active;
}
public boolean isAlert7Active() {
return alert7Active;
}
public short getMinutesSinceActivation() {
return minutesSinceActivation;
}
public short getReservoirPulsesRemaining() {
return reservoirPulsesRemaining;
}
@Override public String toString() {
return "DefaultStatusResponse{" +
"messageType=" + messageType +
", deliveryStatus=" + deliveryStatus +
", podStatus=" + podStatus +
", totalPulsesDelivered=" + totalPulsesDelivered +
", sequenceNumberOfLastProgrammingCommand=" + sequenceNumberOfLastProgrammingCommand +
", bolusPulsesRemaining=" + bolusPulsesRemaining +
", occlusionAlertActive=" + occlusionAlertActive +
", alert1Active=" + alert1Active +
", alert2Active=" + alert2Active +
", alert3Active=" + alert3Active +
", alert4Active=" + alert4Active +
", alert5Active=" + alert5Active +
", alert6Active=" + alert6Active +
", alert7Active=" + alert7Active +
", minutesSinceActivation=" + minutesSinceActivation +
", reservoirPulsesRemaining=" + reservoirPulsesRemaining +
", responseType=" + responseType +
", encoded=" + Arrays.toString(encoded) +
'}';
}
}

View file

@ -0,0 +1,41 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.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.DeliveryStatus;
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.assertFalse;
import static org.junit.Assert.assertNotSame;
public class DefaultStatusResponseTest {
@Test
public void testValidResponse() throws DecoderException {
byte[] encoded = Hex.decodeHex("1D1800A02800000463FF");
DefaultStatusResponse response = new DefaultStatusResponse(encoded);
assertArrayEquals(encoded, response.getEncoded());
assertNotSame(encoded, response.getEncoded());
assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE, response.getResponseType());
assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE.getValue(), response.getMessageType());
assertEquals(DeliveryStatus.BASAL_ACTIVE, response.getDeliveryStatus());
assertEquals(PodStatus.RUNNING_ABOVE_MIN_VOLUME, response.getPodStatus());
assertEquals((short) 320, response.getTotalPulsesDelivered());
assertEquals((short) 5, response.getSequenceNumberOfLastProgrammingCommand());
assertEquals((short) 0, response.getBolusPulsesRemaining());
assertFalse(response.isOcclusionAlertActive());
assertFalse(response.isAlert1Active());
assertFalse(response.isAlert2Active());
assertFalse(response.isAlert3Active());
assertFalse(response.isAlert4Active());
assertFalse(response.isAlert5Active());
assertFalse(response.isAlert6Active());
assertFalse(response.isAlert7Active());
assertEquals((short) 280, response.getMinutesSinceActivation());
assertEquals((short) 1023, response.getReservoirPulsesRemaining());
}
}