WIP on Omnipod Dash set basal and some refactoring
This commit is contained in:
parent
6972405809
commit
c183a68798
|
@ -4,6 +4,7 @@ import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.NonceEnabledCommand;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.NonceEnabledCommand;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.builder.NonceEnabledCommandBuilder;
|
||||||
|
|
||||||
public final class DeactivateCommand extends NonceEnabledCommand {
|
public final class DeactivateCommand extends NonceEnabledCommand {
|
||||||
private static final short LENGTH = 6;
|
private static final short LENGTH = 6;
|
||||||
|
@ -31,7 +32,7 @@ public final class DeactivateCommand extends NonceEnabledCommand {
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Builder extends NonceEnabledBuilder<Builder, DeactivateCommand> {
|
public static final class Builder extends NonceEnabledCommandBuilder<Builder, DeactivateCommand> {
|
||||||
@Override protected final DeactivateCommand buildCommand() {
|
@Override protected final DeactivateCommand buildCommand() {
|
||||||
return new DeactivateCommand(Builder.this.address, sequenceNumber, multiCommandFlag, nonce);
|
return new DeactivateCommand(Builder.this.address, sequenceNumber, multiCommandFlag, nonce);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.HeaderEnabledCommand;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.HeaderEnabledCommand;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.builder.HeaderEnabledCommandBuilder;
|
||||||
|
|
||||||
public final class GetVersionCommand extends HeaderEnabledCommand {
|
public final class GetVersionCommand extends HeaderEnabledCommand {
|
||||||
public static final int DEFAULT_ADDRESS = -1; // FIXME move
|
public static final int DEFAULT_ADDRESS = -1; // FIXME move
|
||||||
|
@ -33,7 +34,7 @@ public final class GetVersionCommand extends HeaderEnabledCommand {
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Builder extends HeaderEnabledBuilder<Builder, GetVersionCommand> {
|
public static final class Builder extends HeaderEnabledCommandBuilder<Builder, GetVersionCommand> {
|
||||||
@Override protected final GetVersionCommand buildCommand() {
|
@Override protected final GetVersionCommand buildCommand() {
|
||||||
return new GetVersionCommand(address, sequenceNumber, multiCommandFlag);
|
return new GetVersionCommand(address, sequenceNumber, multiCommandFlag);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.NonceEnabledCommand;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.NonceEnabledCommand;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.builder.NonceEnabledCommandBuilder;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertConfiguration;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertConfiguration;
|
||||||
|
|
||||||
public final class ProgramAlertsCommand extends NonceEnabledCommand {
|
public final class ProgramAlertsCommand extends NonceEnabledCommand {
|
||||||
|
@ -46,7 +47,7 @@ public final class ProgramAlertsCommand extends NonceEnabledCommand {
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Builder extends NonceEnabledBuilder<Builder, ProgramAlertsCommand> {
|
public static final class Builder extends NonceEnabledCommandBuilder<Builder, ProgramAlertsCommand> {
|
||||||
private List<AlertConfiguration> alertConfigurations;
|
private List<AlertConfiguration> alertConfigurations;
|
||||||
|
|
||||||
public Builder setAlertConfigurations(List<AlertConfiguration> alertConfigurations) {
|
public Builder setAlertConfigurations(List<AlertConfiguration> alertConfigurations) {
|
||||||
|
|
|
@ -6,33 +6,131 @@ import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.Command;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.Command;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.program.InsulinProgramElement;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.builder.CommandBuilder;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.Encodable;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ProgramReminder;
|
||||||
|
|
||||||
// Always preceded by 0x1a ProgramInsulinCommand
|
// Always preceded by 0x1a ProgramInsulinCommand
|
||||||
public final class ProgramBasalCommand implements Command {
|
public final class ProgramBasalCommand implements Command {
|
||||||
private final List<InsulinProgramElement> uniqueInsulinProgramElements;
|
private final List<InsulinProgramElement> insulinProgramElements;
|
||||||
|
private final ProgramReminder programReminder;
|
||||||
|
private final byte currentInsulinProgramElementIndex;
|
||||||
|
private final short remainingTenthPulsesInCurrentInsulinProgramElement;
|
||||||
|
private final int delayUntilNextTenthPulseInUsec;
|
||||||
|
|
||||||
private ProgramBasalCommand(List<InsulinProgramElement> uniqueInsulinProgramElements) {
|
private ProgramBasalCommand(List<InsulinProgramElement> insulinProgramElements, ProgramReminder programReminder, byte currentInsulinProgramElementIndex, short remainingTenthPulsesInCurrentInsulinProgramElement, int delayUntilNextTenthPulseInUsec) {
|
||||||
this.uniqueInsulinProgramElements = new ArrayList<>(uniqueInsulinProgramElements);
|
this.insulinProgramElements = new ArrayList<>(insulinProgramElements);
|
||||||
|
this.programReminder = programReminder;
|
||||||
|
this.currentInsulinProgramElementIndex = currentInsulinProgramElementIndex;
|
||||||
|
this.remainingTenthPulsesInCurrentInsulinProgramElement = remainingTenthPulsesInCurrentInsulinProgramElement;
|
||||||
|
this.delayUntilNextTenthPulseInUsec = delayUntilNextTenthPulseInUsec;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getLength() {
|
public short getLength() {
|
||||||
return (short) (uniqueInsulinProgramElements.size() * 2 + 14);
|
return (short) (insulinProgramElements.size() * 2 + 14);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getBodyLength() {
|
public byte getBodyLength() {
|
||||||
return (byte) (uniqueInsulinProgramElements.size() * 2 + 12);
|
return (byte) (insulinProgramElements.size() * 2 + 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public byte[] getEncoded() {
|
@Override public byte[] getEncoded() {
|
||||||
return ByteBuffer.allocate(getLength()) //
|
ByteBuffer buffer = ByteBuffer.allocate(getLength()) //
|
||||||
// TODO
|
.put(getCommandType().getValue()) //
|
||||||
.array();
|
.put(getBodyLength()) //
|
||||||
|
.put(programReminder.getEncoded()) //
|
||||||
|
.put(currentInsulinProgramElementIndex) //
|
||||||
|
.putShort(remainingTenthPulsesInCurrentInsulinProgramElement) //
|
||||||
|
.putInt(delayUntilNextTenthPulseInUsec);
|
||||||
|
for (InsulinProgramElement insulinProgramElement : insulinProgramElements) {
|
||||||
|
buffer.put(insulinProgramElement.getEncoded());
|
||||||
|
}
|
||||||
|
return buffer.array();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public CommandType getCommandType() {
|
@Override public CommandType getCommandType() {
|
||||||
return CommandType.PROGRAM_BASAL;
|
return CommandType.PROGRAM_BASAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO builder
|
@Override public String toString() {
|
||||||
|
return "ProgramBasalCommand{" +
|
||||||
|
"uniqueInsulinProgramElements=" + insulinProgramElements +
|
||||||
|
", programReminder=" + programReminder +
|
||||||
|
", currentInsulinProgramElementIndex=" + currentInsulinProgramElementIndex +
|
||||||
|
", remainingTenthPulsesInCurrentInsulinProgramElement=" + remainingTenthPulsesInCurrentInsulinProgramElement +
|
||||||
|
", delayUntilNextTenthPulseInUsec=" + delayUntilNextTenthPulseInUsec +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class InsulinProgramElement implements Encodable {
|
||||||
|
private final short totalTenthPulses;
|
||||||
|
private final int delayBetweenTenthPulses;
|
||||||
|
|
||||||
|
public InsulinProgramElement(byte totalTenthPulses, short delayBetweenTenthPulses) {
|
||||||
|
this.totalTenthPulses = totalTenthPulses;
|
||||||
|
this.delayBetweenTenthPulses = delayBetweenTenthPulses;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public byte[] getEncoded() {
|
||||||
|
return ByteBuffer.allocate(6) //
|
||||||
|
.putShort(totalTenthPulses) //
|
||||||
|
.putInt(delayBetweenTenthPulses) //
|
||||||
|
.array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Builder implements CommandBuilder<ProgramBasalCommand> {
|
||||||
|
private List<InsulinProgramElement> insulinProgramElements;
|
||||||
|
private ProgramReminder programReminder;
|
||||||
|
private Byte currentInsulinProgramElementIndex;
|
||||||
|
private Short remainingTenthPulsesInCurrentInsulinProgramElement;
|
||||||
|
private Integer delayUntilNextTenthPulseInUsec;
|
||||||
|
|
||||||
|
public Builder setInsulinProgramElements(List<InsulinProgramElement> insulinProgramElements) {
|
||||||
|
if (insulinProgramElements == null) {
|
||||||
|
throw new IllegalArgumentException("insulinProgramElements can not be null");
|
||||||
|
}
|
||||||
|
this.insulinProgramElements = new ArrayList<>(insulinProgramElements);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setProgramReminder(ProgramReminder programReminder) {
|
||||||
|
this.programReminder = programReminder;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setCurrentInsulinProgramElementIndex(Byte currentInsulinProgramElementIndex) {
|
||||||
|
this.currentInsulinProgramElementIndex = currentInsulinProgramElementIndex;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setRemainingTenthPulsesInCurrentInsulinProgramElement(Short remainingTenthPulsesInCurrentInsulinProgramElement) {
|
||||||
|
this.remainingTenthPulsesInCurrentInsulinProgramElement = remainingTenthPulsesInCurrentInsulinProgramElement;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setDelayUntilNextTenthPulseInUsec(Integer delayUntilNextTenthPulseInUsec) {
|
||||||
|
this.delayUntilNextTenthPulseInUsec = delayUntilNextTenthPulseInUsec;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public ProgramBasalCommand build() {
|
||||||
|
if (insulinProgramElements == null) {
|
||||||
|
throw new IllegalArgumentException("insulinProgramElements can not be null");
|
||||||
|
}
|
||||||
|
if (programReminder == null) {
|
||||||
|
throw new IllegalArgumentException("programReminder can not be null");
|
||||||
|
}
|
||||||
|
if (currentInsulinProgramElementIndex == null) {
|
||||||
|
throw new IllegalArgumentException("currentInsulinProgramElementIndex can not be null");
|
||||||
|
}
|
||||||
|
if (remainingTenthPulsesInCurrentInsulinProgramElement == null) {
|
||||||
|
throw new IllegalArgumentException("remainingTenthPulsesInCurrentInsulinProgramElement can not be null");
|
||||||
|
}
|
||||||
|
if (delayUntilNextTenthPulseInUsec == null) {
|
||||||
|
throw new IllegalArgumentException("delayUntilNextTenthPulseInUsec can not be null");
|
||||||
|
}
|
||||||
|
return new ProgramBasalCommand(insulinProgramElements, programReminder, currentInsulinProgramElementIndex, remainingTenthPulsesInCurrentInsulinProgramElement, delayUntilNextTenthPulseInUsec);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,14 @@ import java.util.List;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.Command;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.Command;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.NonceEnabledCommand;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.NonceEnabledCommand;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.program.InsulinProgramElement;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.builder.NonceEnabledCommandBuilder;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.Encodable;
|
||||||
|
|
||||||
// Always followed by one of: 0x13, 0x16, 0x17
|
// Always followed by one of: 0x13, 0x16, 0x17
|
||||||
public final class ProgramInsulinCommand extends NonceEnabledCommand {
|
public final class ProgramInsulinCommand extends NonceEnabledCommand {
|
||||||
private final List<InsulinProgramElement> max8HourInsulinProgramElements;
|
private final List<InsulinProgramElement> insulinProgramElements;
|
||||||
private final byte currentHalfHourEntryIndex;
|
private final byte currentHalfHourEntryIndex;
|
||||||
|
private final short checksum;
|
||||||
private final short remainingEighthSecondsInCurrentHalfHourEntry;
|
private final short remainingEighthSecondsInCurrentHalfHourEntry;
|
||||||
private final short remainingPulsesInCurrentHalfHourEntry;
|
private final short remainingPulsesInCurrentHalfHourEntry;
|
||||||
private final DeliveryType deliveryType;
|
private final DeliveryType deliveryType;
|
||||||
|
@ -25,10 +27,11 @@ public final class ProgramInsulinCommand extends NonceEnabledCommand {
|
||||||
CommandType.PROGRAM_BOLUS
|
CommandType.PROGRAM_BOLUS
|
||||||
);
|
);
|
||||||
|
|
||||||
private ProgramInsulinCommand(int address, short sequenceNumber, boolean multiCommandFlag, int nonce, List<InsulinProgramElement> max8HourInsulinProgramElements, byte currentHalfHourEntryIndex, short remainingEighthSecondsInCurrentHalfHourEntry, short remainingPulsesInCurrentHalfHourEntry, DeliveryType deliveryType, Command interlockCommand) {
|
private ProgramInsulinCommand(int address, short sequenceNumber, boolean multiCommandFlag, int nonce, List<InsulinProgramElement> insulinProgramElements, byte currentHalfHourEntryIndex, short checksum, short remainingEighthSecondsInCurrentHalfHourEntry, short remainingPulsesInCurrentHalfHourEntry, DeliveryType deliveryType, Command interlockCommand) {
|
||||||
super(CommandType.PROGRAM_INSULIN, address, sequenceNumber, multiCommandFlag, nonce);
|
super(CommandType.PROGRAM_INSULIN, address, sequenceNumber, multiCommandFlag, nonce);
|
||||||
this.max8HourInsulinProgramElements = new ArrayList<>(max8HourInsulinProgramElements);
|
this.insulinProgramElements = new ArrayList<>(insulinProgramElements);
|
||||||
this.currentHalfHourEntryIndex = currentHalfHourEntryIndex;
|
this.currentHalfHourEntryIndex = currentHalfHourEntryIndex;
|
||||||
|
this.checksum = checksum;
|
||||||
this.remainingEighthSecondsInCurrentHalfHourEntry = remainingEighthSecondsInCurrentHalfHourEntry;
|
this.remainingEighthSecondsInCurrentHalfHourEntry = remainingEighthSecondsInCurrentHalfHourEntry;
|
||||||
this.remainingPulsesInCurrentHalfHourEntry = remainingPulsesInCurrentHalfHourEntry;
|
this.remainingPulsesInCurrentHalfHourEntry = remainingPulsesInCurrentHalfHourEntry;
|
||||||
this.deliveryType = deliveryType;
|
this.deliveryType = deliveryType;
|
||||||
|
@ -36,11 +39,11 @@ public final class ProgramInsulinCommand extends NonceEnabledCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getLength() {
|
public short getLength() {
|
||||||
return (short) (max8HourInsulinProgramElements.size() * 6 + 10);
|
return (short) (insulinProgramElements.size() * 6 + 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getBodyLength() {
|
public byte getBodyLength() {
|
||||||
return (byte) (max8HourInsulinProgramElements.size() * 6 + 8);
|
return (byte) (insulinProgramElements.size() * 6 + 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public byte[] getEncoded() {
|
@Override public byte[] getEncoded() {
|
||||||
|
@ -49,39 +52,40 @@ public final class ProgramInsulinCommand extends NonceEnabledCommand {
|
||||||
.put(getBodyLength()) //
|
.put(getBodyLength()) //
|
||||||
.putInt(nonce) //
|
.putInt(nonce) //
|
||||||
.put(deliveryType.getValue()) //
|
.put(deliveryType.getValue()) //
|
||||||
.putShort(createChecksum()) //
|
.putShort(checksum) //
|
||||||
.put(currentHalfHourEntryIndex) //
|
.put(currentHalfHourEntryIndex) //
|
||||||
.putShort(remainingEighthSecondsInCurrentHalfHourEntry) //
|
.putShort(remainingEighthSecondsInCurrentHalfHourEntry) //
|
||||||
.putShort(remainingPulsesInCurrentHalfHourEntry);
|
.putShort(remainingPulsesInCurrentHalfHourEntry);
|
||||||
|
|
||||||
for (InsulinProgramElement element : max8HourInsulinProgramElements) {
|
for (InsulinProgramElement element : insulinProgramElements) {
|
||||||
commandBuffer.put(element.getEncoded());
|
commandBuffer.put(element.getEncoded());
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] command = commandBuffer.array();
|
byte[] command = commandBuffer.array();
|
||||||
|
byte[] interlock = interlockCommand.getEncoded();
|
||||||
|
short totalLength = (short) (command.length + interlock.length + HEADER_LENGTH);
|
||||||
|
|
||||||
// TODO interlock and header
|
return ByteBuffer.allocate(totalLength) //
|
||||||
|
.put(encodeHeader(address, sequenceNumber, totalLength, multiCommandFlag)) //
|
||||||
return command;
|
.put(command) //
|
||||||
|
.put(interlock) //
|
||||||
|
.array();
|
||||||
}
|
}
|
||||||
|
|
||||||
private short createChecksum() {
|
public static final class Builder extends NonceEnabledCommandBuilder<Builder, ProgramInsulinCommand> {
|
||||||
return 0; // TODO
|
private List<InsulinProgramElement> insulinProgramElements;
|
||||||
}
|
|
||||||
|
|
||||||
public static final class Builder extends NonceEnabledBuilder<Builder, ProgramInsulinCommand> {
|
|
||||||
private List<InsulinProgramElement> max8HourInsulinProgramElements;
|
|
||||||
private Byte currentHalfOurEntryIndex;
|
private Byte currentHalfOurEntryIndex;
|
||||||
|
private Short checksum;
|
||||||
private Short remainingEighthSecondsInCurrentHalfHourEntry;
|
private Short remainingEighthSecondsInCurrentHalfHourEntry;
|
||||||
private Short remainingPulsesInCurrentHalfHourEntry;
|
private Short remainingPulsesInCurrentHalfHourEntry;
|
||||||
private DeliveryType deliveryType;
|
private DeliveryType deliveryType;
|
||||||
private Command interlockCommand;
|
private Command interlockCommand;
|
||||||
|
|
||||||
public Builder setMax8HourInsulinProgramElements(List<InsulinProgramElement> max8HourInsulinProgramElements) {
|
public Builder setInsulinProgramElements(List<InsulinProgramElement> insulinProgramElements) {
|
||||||
if (max8HourInsulinProgramElements == null) {
|
if (insulinProgramElements == null) {
|
||||||
throw new IllegalArgumentException("max8HourInsulinProgramElements can not be null");
|
throw new IllegalArgumentException("insulinProgramElements can not be null");
|
||||||
}
|
}
|
||||||
this.max8HourInsulinProgramElements = new ArrayList<>(max8HourInsulinProgramElements);
|
this.insulinProgramElements = new ArrayList<>(insulinProgramElements);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,6 +94,11 @@ public final class ProgramInsulinCommand extends NonceEnabledCommand {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder setChecksum(short checksum) {
|
||||||
|
this.checksum = checksum;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Builder setRemainingEighthSecondsInCurrentHalfHourEntryIndex(short remainingEighthSecondsInCurrentHalfHourEntry) {
|
public Builder setRemainingEighthSecondsInCurrentHalfHourEntryIndex(short remainingEighthSecondsInCurrentHalfHourEntry) {
|
||||||
this.remainingEighthSecondsInCurrentHalfHourEntry = remainingEighthSecondsInCurrentHalfHourEntry;
|
this.remainingEighthSecondsInCurrentHalfHourEntry = remainingEighthSecondsInCurrentHalfHourEntry;
|
||||||
return this;
|
return this;
|
||||||
|
@ -114,12 +123,15 @@ public final class ProgramInsulinCommand extends NonceEnabledCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected final ProgramInsulinCommand buildCommand() {
|
@Override protected final ProgramInsulinCommand buildCommand() {
|
||||||
if (max8HourInsulinProgramElements == null) {
|
if (insulinProgramElements == null) {
|
||||||
throw new IllegalArgumentException("insulinProgramElements can not be null");
|
throw new IllegalArgumentException("insulinProgramElements can not be null");
|
||||||
}
|
}
|
||||||
if (currentHalfOurEntryIndex == null) {
|
if (currentHalfOurEntryIndex == null) {
|
||||||
throw new IllegalArgumentException("currentHalfOurEntryIndex can not be null");
|
throw new IllegalArgumentException("currentHalfOurEntryIndex can not be null");
|
||||||
}
|
}
|
||||||
|
if (checksum == null) {
|
||||||
|
throw new IllegalArgumentException("checksum can not be null");
|
||||||
|
}
|
||||||
if (remainingEighthSecondsInCurrentHalfHourEntry == null) {
|
if (remainingEighthSecondsInCurrentHalfHourEntry == null) {
|
||||||
throw new IllegalArgumentException("remainingEighthSecondsInCurrentHalfHourEntry can not be null");
|
throw new IllegalArgumentException("remainingEighthSecondsInCurrentHalfHourEntry can not be null");
|
||||||
}
|
}
|
||||||
|
@ -132,7 +144,7 @@ public final class ProgramInsulinCommand extends NonceEnabledCommand {
|
||||||
if (interlockCommand == null) {
|
if (interlockCommand == null) {
|
||||||
throw new IllegalArgumentException("interlockCommand can not be null");
|
throw new IllegalArgumentException("interlockCommand can not be null");
|
||||||
}
|
}
|
||||||
return new ProgramInsulinCommand(address, sequenceNumber, multiCommandFlag, nonce, max8HourInsulinProgramElements, currentHalfOurEntryIndex, remainingEighthSecondsInCurrentHalfHourEntry, remainingPulsesInCurrentHalfHourEntry, deliveryType, interlockCommand);
|
return new ProgramInsulinCommand(address, sequenceNumber, multiCommandFlag, nonce, insulinProgramElements, currentHalfOurEntryIndex, checksum, remainingEighthSecondsInCurrentHalfHourEntry, remainingPulsesInCurrentHalfHourEntry, deliveryType, interlockCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,4 +164,43 @@ public final class ProgramInsulinCommand extends NonceEnabledCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String toString() {
|
||||||
|
return "ProgramInsulinCommand{" +
|
||||||
|
"insulinProgramElements=" + insulinProgramElements +
|
||||||
|
", currentHalfHourEntryIndex=" + currentHalfHourEntryIndex +
|
||||||
|
", checksum=" + checksum +
|
||||||
|
", remainingEighthSecondsInCurrentHalfHourEntry=" + remainingEighthSecondsInCurrentHalfHourEntry +
|
||||||
|
", remainingPulsesInCurrentHalfHourEntry=" + remainingPulsesInCurrentHalfHourEntry +
|
||||||
|
", deliveryType=" + deliveryType +
|
||||||
|
", interlockCommand=" + interlockCommand +
|
||||||
|
", nonce=" + nonce +
|
||||||
|
", commandType=" + commandType +
|
||||||
|
", address=" + address +
|
||||||
|
", sequenceNumber=" + sequenceNumber +
|
||||||
|
", multiCommandFlag=" + multiCommandFlag +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class InsulinProgramElement implements Encodable {
|
||||||
|
private final byte numberOfHalfOurEntries; // 4 bits
|
||||||
|
private final short numberOfPulsesPerHalfOurEntry; // 10 bits
|
||||||
|
private final boolean extraAlternatePulse;
|
||||||
|
|
||||||
|
public InsulinProgramElement(byte numberOfHalfOurEntries, short numberOfPulsesPerHalfOurEntry, boolean extraAlternatePulse) {
|
||||||
|
this.numberOfHalfOurEntries = numberOfHalfOurEntries;
|
||||||
|
this.numberOfPulsesPerHalfOurEntry = numberOfPulsesPerHalfOurEntry;
|
||||||
|
this.extraAlternatePulse = extraAlternatePulse;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public byte[] getEncoded() {
|
||||||
|
byte firstByte = (byte) ((((numberOfHalfOurEntries - 1) & 0x0f) << 4) //
|
||||||
|
| ((extraAlternatePulse ? 1 : 0) << 3) //
|
||||||
|
| ((numberOfPulsesPerHalfOurEntry >>> 8) & 0x03));
|
||||||
|
|
||||||
|
return ByteBuffer.allocate(2) //
|
||||||
|
.put(firstByte) //
|
||||||
|
.put((byte) (numberOfPulsesPerHalfOurEntry & 0xff)) //
|
||||||
|
.array();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Date;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.HeaderEnabledCommand;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.HeaderEnabledCommand;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.builder.HeaderEnabledCommandBuilder;
|
||||||
|
|
||||||
public final class SetUniqueIdCommand extends HeaderEnabledCommand {
|
public final class SetUniqueIdCommand extends HeaderEnabledCommand {
|
||||||
private static final int DEFAULT_ADDRESS = -1;
|
private static final int DEFAULT_ADDRESS = -1;
|
||||||
|
@ -62,7 +63,7 @@ public final class SetUniqueIdCommand extends HeaderEnabledCommand {
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Builder extends HeaderEnabledBuilder<Builder, SetUniqueIdCommand> {
|
public static final class Builder extends HeaderEnabledCommandBuilder<Builder, SetUniqueIdCommand> {
|
||||||
private Integer lotNumber;
|
private Integer lotNumber;
|
||||||
private Integer podSequenceNumber;
|
private Integer podSequenceNumber;
|
||||||
private Date initializationTime;
|
private Date initializationTime;
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.BitSet;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.NonceEnabledCommand;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.NonceEnabledCommand;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.builder.NonceEnabledCommandBuilder;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.Encodable;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.Encodable;
|
||||||
|
|
||||||
public final class SilenceAlertsCommand extends NonceEnabledCommand {
|
public final class SilenceAlertsCommand extends NonceEnabledCommand {
|
||||||
|
@ -74,7 +75,7 @@ public final class SilenceAlertsCommand extends NonceEnabledCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder extends NonceEnabledBuilder<Builder, SilenceAlertsCommand> {
|
public static class Builder extends NonceEnabledCommandBuilder<Builder, SilenceAlertsCommand> {
|
||||||
private boolean silenceAutoOffAlert;
|
private boolean silenceAutoOffAlert;
|
||||||
private boolean silenceMultiCommandAlert;
|
private boolean silenceMultiCommandAlert;
|
||||||
private boolean silenceExpirationImminentAlert;
|
private boolean silenceExpirationImminentAlert;
|
||||||
|
|
|
@ -4,8 +4,8 @@ import java.nio.ByteBuffer;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.HeaderEnabledCommand;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.NonceEnabledCommand;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.NonceEnabledCommand;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.builder.NonceEnabledCommandBuilder;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BeepType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BeepType;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.Encodable;
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.Encodable;
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ public final class StopDeliveryCommand extends NonceEnabledCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Builder extends NonceEnabledBuilder<Builder, StopDeliveryCommand> {
|
public static final class Builder extends NonceEnabledCommandBuilder<Builder, StopDeliveryCommand> {
|
||||||
private DeliveryType deliveryType;
|
private DeliveryType deliveryType;
|
||||||
private BeepType beepType = BeepType.LONG_SINGLE_BEEP;
|
private BeepType beepType = BeepType.LONG_SINGLE_BEEP;
|
||||||
|
|
||||||
|
|
|
@ -37,40 +37,4 @@ public abstract class HeaderEnabledCommand implements Command {
|
||||||
.array();
|
.array();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static abstract class HeaderEnabledBuilder<T extends HeaderEnabledBuilder<T, R>, R extends Command> implements Builder<R> {
|
|
||||||
protected Integer address;
|
|
||||||
protected Short sequenceNumber;
|
|
||||||
protected boolean multiCommandFlag = false;
|
|
||||||
|
|
||||||
public R build() {
|
|
||||||
if (address == null) {
|
|
||||||
throw new IllegalArgumentException("address can not be null");
|
|
||||||
}
|
|
||||||
if (sequenceNumber == null) {
|
|
||||||
throw new IllegalArgumentException("sequenceNumber can not be null");
|
|
||||||
}
|
|
||||||
return buildCommand();
|
|
||||||
}
|
|
||||||
|
|
||||||
public final T setAddress(int address) {
|
|
||||||
this.address = address;
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final T setSequenceNumber(short sequenceNumber) {
|
|
||||||
this.sequenceNumber = sequenceNumber;
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final T setMultiCommandFlag(boolean multiCommandFlag) {
|
|
||||||
this.multiCommandFlag = multiCommandFlag;
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract R buildCommand();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected interface Builder<R extends Command> {
|
|
||||||
R build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,19 +8,4 @@ public abstract class NonceEnabledCommand extends HeaderEnabledCommand {
|
||||||
this.nonce = nonce;
|
this.nonce = nonce;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static abstract class NonceEnabledBuilder<T extends NonceEnabledBuilder<T, R>, R extends Command> extends HeaderEnabledBuilder<T, R> {
|
|
||||||
protected Integer nonce;
|
|
||||||
|
|
||||||
public final R build() {
|
|
||||||
if (nonce == null) {
|
|
||||||
throw new IllegalArgumentException("nonce can not be null");
|
|
||||||
}
|
|
||||||
return super.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public final T setNonce(int nonce) {
|
|
||||||
this.nonce = nonce;
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.builder;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.Command;
|
||||||
|
|
||||||
|
public interface CommandBuilder<R extends Command> {
|
||||||
|
R build();
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.builder;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.Command;
|
||||||
|
|
||||||
|
public abstract class HeaderEnabledCommandBuilder<T extends HeaderEnabledCommandBuilder<T, R>, R extends Command> implements CommandBuilder<R> {
|
||||||
|
protected Integer address;
|
||||||
|
protected Short sequenceNumber;
|
||||||
|
protected boolean multiCommandFlag = false;
|
||||||
|
|
||||||
|
public R build() {
|
||||||
|
if (address == null) {
|
||||||
|
throw new IllegalArgumentException("address can not be null");
|
||||||
|
}
|
||||||
|
if (sequenceNumber == null) {
|
||||||
|
throw new IllegalArgumentException("sequenceNumber can not be null");
|
||||||
|
}
|
||||||
|
return buildCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final T setAddress(int address) {
|
||||||
|
this.address = address;
|
||||||
|
return (T) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final T setSequenceNumber(short sequenceNumber) {
|
||||||
|
this.sequenceNumber = sequenceNumber;
|
||||||
|
return (T) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final T setMultiCommandFlag(boolean multiCommandFlag) {
|
||||||
|
this.multiCommandFlag = multiCommandFlag;
|
||||||
|
return (T) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract R buildCommand();
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.builder;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.Command;
|
||||||
|
|
||||||
|
public abstract class NonceEnabledCommandBuilder<T extends NonceEnabledCommandBuilder<T, R>, R extends Command> extends HeaderEnabledCommandBuilder<T, R> {
|
||||||
|
protected Integer nonce;
|
||||||
|
|
||||||
|
public final R build() {
|
||||||
|
if (nonce == null) {
|
||||||
|
throw new IllegalArgumentException("nonce can not be null");
|
||||||
|
}
|
||||||
|
return super.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final T setNonce(int nonce) {
|
||||||
|
this.nonce = nonce;
|
||||||
|
return (T) this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,28 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.program;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
public InsulinProgramElement(byte numberOfHalfOurEntries, short numberOfPulsesPerHalfOurEntry, boolean extraAlternatePulse) {
|
|
||||||
this.numberOfHalfOurEntries = numberOfHalfOurEntries;
|
|
||||||
this.numberOfPulsesPerHalfOurEntry = numberOfPulsesPerHalfOurEntry;
|
|
||||||
this.extraAlternatePulse = extraAlternatePulse;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public byte[] getEncoded() {
|
|
||||||
byte firstByte = (byte) ((((numberOfHalfOurEntries - 1) & 0x0f) << 4) //
|
|
||||||
| ((extraAlternatePulse ? 1 : 0) << 3) //
|
|
||||||
| ((numberOfPulsesPerHalfOurEntry >>> 8) & 0x03));
|
|
||||||
|
|
||||||
return ByteBuffer.allocate(2) //
|
|
||||||
.put(firstByte) //
|
|
||||||
.put((byte) (numberOfPulsesPerHalfOurEntry & 0xff)) //
|
|
||||||
.array();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue