Add Encodable interface

This commit is contained in:
Bart Sopers 2021-02-12 21:47:16 +01:00
parent d944df725f
commit d1bf9cefad
8 changed files with 34 additions and 18 deletions

View file

@ -1,7 +1,7 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command;
public interface Command {
CommandType getCommandType();
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.Encodable;
byte[] getEncoded();
public interface Command extends Encodable {
CommandType getCommandType();
}

View file

@ -3,6 +3,8 @@ 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.Encodable;
public final class SilenceAlertsCommand extends CommandBase {
private static final short LENGTH = (short) 7;
private static final byte BODY_LENGTH = (byte) 5;
@ -34,7 +36,7 @@ public final class SilenceAlertsCommand extends CommandBase {
'}';
}
private static final class SilenceAlertCommandParameters {
private static final class SilenceAlertCommandParameters implements Encodable {
private final boolean silenceAutoOffAlert;
private final boolean silenceMultiCommandAlert;
private final boolean silenceExpirationImminentAlert;
@ -55,7 +57,8 @@ public final class SilenceAlertsCommand extends CommandBase {
this.silencePodExpirationAlert = silencePodExpirationAlert;
}
private byte[] getEncoded() {
@Override
public byte[] getEncoded() {
BitSet bitSet = new BitSet(8);
bitSet.set(0, this.silenceAutoOffAlert);
bitSet.set(1, this.silenceMultiCommandAlert);

View file

@ -4,6 +4,7 @@ import java.nio.ByteBuffer;
import java.util.BitSet;
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BeepType;
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.Encodable;
public final class StopDeliveryCommand extends CommandBase {
private static final short LENGTH = 7;
@ -24,7 +25,7 @@ public final class StopDeliveryCommand extends CommandBase {
.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())) //
.put((byte) ((beepType.getValue() << 4) | deliveryType.getEncoded()[0])) //
.array());
}
@ -39,7 +40,7 @@ public final class StopDeliveryCommand extends CommandBase {
'}';
}
public enum DeliveryType {
public enum DeliveryType implements Encodable {
BASAL(true, false, false),
TEMP_BASAL(false, true, false),
BOLUS(false, false, true),
@ -55,12 +56,12 @@ public final class StopDeliveryCommand extends CommandBase {
this.bolus = bolus;
}
public byte getEncoded() {
@Override 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];
return bitSet.toByteArray();
}
}

View file

@ -1,4 +1,9 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.interlock;
public class BasalInterlock {
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.Encodable;
public class BasalInterlock implements Encodable {
@Override public byte[] getEncoded() {
return new byte[0];
}
}

View file

@ -2,7 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definiti
import java.nio.ByteBuffer;
public class AlertConfiguration {
public class AlertConfiguration implements Encodable {
private AlertSlot slot;
private boolean enabled;
private short durationInMinutes;
@ -23,7 +23,7 @@ public class AlertConfiguration {
this.beepRepetition = beepRepetition;
}
public byte[] getEncoded() {
@Override public byte[] getEncoded() {
byte firstByte = (byte) (slot.getValue() << 4);
if (enabled) {
firstByte |= 1 << 3;

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition;
public interface Encodable {
byte[] getEncoded();
}

View file

@ -1,6 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition;
public class ProgramReminder {
public class ProgramReminder implements Encodable {
private final boolean atStart;
private final boolean atEnd;
private final byte atInterval;
@ -11,9 +11,9 @@ public class ProgramReminder {
this.atInterval = atIntervalInMinutes;
}
public byte getEncoded() {
return (byte) (((this.atStart ? 0 : 1) << 7)
@Override public byte[] getEncoded() {
return new byte[]{(byte) (((this.atStart ? 0 : 1) << 7)
| ((this.atEnd ? 0 : 1) << 6)
| (this.atInterval & 0x3f));
| (this.atInterval & 0x3f))};
}
}

View file

@ -2,7 +2,9 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definiti
import java.nio.ByteBuffer;
public class InsulinProgramElement {
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.Encodable;
public class InsulinProgramElement implements Encodable {
private final byte numberOfHalfOurEntries; // 4 bits
private final short numberOfPulsesPerHalfOurEntry; // 10 bits
private final boolean extraAlternatePulse;
@ -13,7 +15,7 @@ public class InsulinProgramElement {
this.extraAlternatePulse = extraAlternatePulse;
}
public byte[] getEncoded() {
@Override public byte[] getEncoded() {
byte firstByte = (byte) ((((numberOfHalfOurEntries - 1) & 0x0f) << 4)
| ((extraAlternatePulse ? 1 : 0) << 3)
| ((numberOfPulsesPerHalfOurEntry >>> 8) & 0x03));