WIP on Omnipod Dash set basal

This commit is contained in:
Bart Sopers 2021-02-14 19:45:43 +01:00
parent 34553bbcf6
commit 6972405809
2 changed files with 66 additions and 57 deletions

View file

@ -44,6 +44,7 @@ dependencies {
kapt "com.google.dagger:dagger-android-processor:$dagger_version" kapt "com.google.dagger:dagger-android-processor:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version" kapt "com.google.dagger:dagger-compiler:$dagger_version"
implementation "org.apache.commons:commons-lang3:$commonslang3_version"
implementation "commons-codec:commons-codec:$commonscodec_version" implementation "commons-codec:commons-codec:$commonscodec_version"
implementation "androidx.appcompat:appcompat:$appcompat_version" implementation "androidx.appcompat:appcompat:$appcompat_version"
implementation "com.google.android.material:material:$material_version" implementation "com.google.android.material:material:$material_version"

View file

@ -7,17 +7,16 @@ 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.HeaderEnabledCommand; import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.NonceEnabledCommand;
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ProgramReminder;
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.program.InsulinProgramElement; import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.program.InsulinProgramElement;
// Always followed by one of: 0x13, 0x16, 0x17 // Always followed by one of: 0x13, 0x16, 0x17
public final class ProgramInsulinCommand extends HeaderEnabledCommand { public final class ProgramInsulinCommand extends NonceEnabledCommand {
private final List<InsulinProgramElement> insulinProgramElements; private final List<InsulinProgramElement> max8HourInsulinProgramElements;
private final ProgramReminder programReminder; private final byte currentHalfHourEntryIndex;
private final byte currentHalfOurEntryIndex; private final short remainingEighthSecondsInCurrentHalfHourEntry;
private final short remainingPulsesInCurrentHalfHourEntry; private final short remainingPulsesInCurrentHalfHourEntry;
private final int delayUntilNextTenthPulseInUsec; private final DeliveryType deliveryType;
private final Command interlockCommand; private final Command interlockCommand;
private static final List<CommandType> ALLOWED_INTERLOCK_COMMANDS = Arrays.asList( private static final List<CommandType> ALLOWED_INTERLOCK_COMMANDS = Arrays.asList(
@ -26,34 +25,36 @@ public final class ProgramInsulinCommand extends HeaderEnabledCommand {
CommandType.PROGRAM_BOLUS CommandType.PROGRAM_BOLUS
); );
private ProgramInsulinCommand(int address, short sequenceNumber, boolean multiCommandFlag, ProgramReminder programReminder, List<InsulinProgramElement> insulinProgramElements, byte currentHalfOurEntryIndex, short remainingPulsesInCurrentHalfHourEntry, int delayUntilNextTenthPulseInUsec, Command interlockCommand) { private ProgramInsulinCommand(int address, short sequenceNumber, boolean multiCommandFlag, int nonce, List<InsulinProgramElement> max8HourInsulinProgramElements, byte currentHalfHourEntryIndex, short remainingEighthSecondsInCurrentHalfHourEntry, short remainingPulsesInCurrentHalfHourEntry, DeliveryType deliveryType, Command interlockCommand) {
super(CommandType.PROGRAM_INSULIN, address, sequenceNumber, multiCommandFlag); super(CommandType.PROGRAM_INSULIN, address, sequenceNumber, multiCommandFlag, nonce);
this.insulinProgramElements = new ArrayList<>(insulinProgramElements); this.max8HourInsulinProgramElements = new ArrayList<>(max8HourInsulinProgramElements);
this.programReminder = programReminder; this.currentHalfHourEntryIndex = currentHalfHourEntryIndex;
this.currentHalfOurEntryIndex = currentHalfOurEntryIndex; this.remainingEighthSecondsInCurrentHalfHourEntry = remainingEighthSecondsInCurrentHalfHourEntry;
this.remainingPulsesInCurrentHalfHourEntry = remainingPulsesInCurrentHalfHourEntry; this.remainingPulsesInCurrentHalfHourEntry = remainingPulsesInCurrentHalfHourEntry;
this.delayUntilNextTenthPulseInUsec = delayUntilNextTenthPulseInUsec; this.deliveryType = deliveryType;
this.interlockCommand = interlockCommand; this.interlockCommand = interlockCommand;
} }
public short getLength() { public short getLength() {
return (short) (insulinProgramElements.size() * 6 + 10); return (short) (max8HourInsulinProgramElements.size() * 6 + 10);
} }
public byte getBodyLength() { public byte getBodyLength() {
return (byte) (insulinProgramElements.size() * 6 + 8); return (byte) (max8HourInsulinProgramElements.size() * 6 + 8);
} }
@Override public byte[] getEncoded() { @Override public byte[] getEncoded() {
ByteBuffer commandBuffer = ByteBuffer.allocate(this.getLength()) // ByteBuffer commandBuffer = ByteBuffer.allocate(this.getLength()) //
.put(commandType.getValue()) // .put(commandType.getValue()) //
.put(getBodyLength()) // .put(getBodyLength()) //
.put(programReminder.getEncoded()) // .putInt(nonce) //
.put(currentHalfOurEntryIndex) // .put(deliveryType.getValue()) //
.putShort(remainingPulsesInCurrentHalfHourEntry) // .putShort(createChecksum()) //
.putInt(delayUntilNextTenthPulseInUsec); .put(currentHalfHourEntryIndex) //
.putShort(remainingEighthSecondsInCurrentHalfHourEntry) //
.putShort(remainingPulsesInCurrentHalfHourEntry);
for (InsulinProgramElement element : insulinProgramElements) { for (InsulinProgramElement element : max8HourInsulinProgramElements) {
commandBuffer.put(element.getEncoded()); commandBuffer.put(element.getEncoded());
} }
@ -64,43 +65,47 @@ public final class ProgramInsulinCommand extends HeaderEnabledCommand {
return command; return command;
} }
public static final class ProgramBasalBuilder extends HeaderEnabledBuilder<ProgramBasalBuilder, ProgramInsulinCommand> { private short createChecksum() {
private List<InsulinProgramElement> insulinProgramElements; return 0; // TODO
private ProgramReminder programReminder; }
public static final class Builder extends NonceEnabledBuilder<Builder, ProgramInsulinCommand> {
private List<InsulinProgramElement> max8HourInsulinProgramElements;
private Byte currentHalfOurEntryIndex; private Byte currentHalfOurEntryIndex;
private Short remainingEighthSecondsInCurrentHalfHourEntry;
private Short remainingPulsesInCurrentHalfHourEntry; private Short remainingPulsesInCurrentHalfHourEntry;
private Integer delayUntilNextTenthPulseInUsec; private DeliveryType deliveryType;
private Command interlockCommand; private Command interlockCommand;
public ProgramBasalBuilder setInsulinProgramElements(List<InsulinProgramElement> insulinProgramElements) { public Builder setMax8HourInsulinProgramElements(List<InsulinProgramElement> max8HourInsulinProgramElements) {
if (insulinProgramElements == null) { if (max8HourInsulinProgramElements == null) {
throw new IllegalArgumentException("insulinProgramElements can not be null"); throw new IllegalArgumentException("max8HourInsulinProgramElements can not be null");
} }
this.insulinProgramElements = new ArrayList<>(insulinProgramElements); this.max8HourInsulinProgramElements = new ArrayList<>(max8HourInsulinProgramElements);
return this; return this;
} }
public ProgramBasalBuilder setProgramReminder(ProgramReminder programReminder) { public Builder setCurrentHalfOurEntryIndex(byte currentHalfOurEntryIndex) {
this.programReminder = programReminder;
return this;
}
public ProgramBasalBuilder setCurrentHalfOurEntryIndex(byte currentHalfOurEntryIndex) {
this.currentHalfOurEntryIndex = currentHalfOurEntryIndex; this.currentHalfOurEntryIndex = currentHalfOurEntryIndex;
return this; return this;
} }
public ProgramBasalBuilder setRemainingPulsesInCurrentHalfHourEntry(short remainingPulsesInCurrentHalfHourEntry) { public Builder setRemainingEighthSecondsInCurrentHalfHourEntryIndex(short remainingEighthSecondsInCurrentHalfHourEntry) {
this.remainingEighthSecondsInCurrentHalfHourEntry = remainingEighthSecondsInCurrentHalfHourEntry;
return this;
}
public Builder setRemainingPulsesInCurrentHalfHourEntry(short remainingPulsesInCurrentHalfHourEntry) {
this.remainingPulsesInCurrentHalfHourEntry = remainingPulsesInCurrentHalfHourEntry; this.remainingPulsesInCurrentHalfHourEntry = remainingPulsesInCurrentHalfHourEntry;
return this; return this;
} }
public ProgramBasalBuilder setDelayUntilNextTenthPulseInUsec(Integer delayUntilNextTenthPulseInUsec) { public Builder setDeliveryType(DeliveryType deliveryType) {
this.delayUntilNextTenthPulseInUsec = delayUntilNextTenthPulseInUsec; this.deliveryType = deliveryType;
return this; return this;
} }
public ProgramBasalBuilder setInterlockCommand(Command interlockCommand) { public Builder setInterlockCommand(Command interlockCommand) {
if (!ALLOWED_INTERLOCK_COMMANDS.contains(interlockCommand.getCommandType())) { if (!ALLOWED_INTERLOCK_COMMANDS.contains(interlockCommand.getCommandType())) {
throw new IllegalArgumentException("Illegal interlock command type"); throw new IllegalArgumentException("Illegal interlock command type");
} }
@ -109,39 +114,42 @@ public final class ProgramInsulinCommand extends HeaderEnabledCommand {
} }
@Override protected final ProgramInsulinCommand buildCommand() { @Override protected final ProgramInsulinCommand buildCommand() {
if (insulinProgramElements == null) { if (max8HourInsulinProgramElements == null) {
throw new IllegalArgumentException("insulinProgramElements can not be null"); throw new IllegalArgumentException("insulinProgramElements can not be null");
} }
if (programReminder == null) {
throw new IllegalArgumentException("programReminder 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 (remainingEighthSecondsInCurrentHalfHourEntry == null) {
throw new IllegalArgumentException("remainingEighthSecondsInCurrentHalfHourEntry can not be null");
}
if (remainingPulsesInCurrentHalfHourEntry == null) { if (remainingPulsesInCurrentHalfHourEntry == null) {
throw new IllegalArgumentException("remainingPulsesInCurrentHalfHourEntry can not be null"); throw new IllegalArgumentException("remainingPulsesInCurrentHalfHourEntry can not be null");
} }
if (delayUntilNextTenthPulseInUsec == null) { if (deliveryType == null) {
throw new IllegalArgumentException("durationUntilNextTenthPulseInUsec can not be null"); throw new IllegalArgumentException("deliveryType can not be null");
} }
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, programReminder, insulinProgramElements, currentHalfOurEntryIndex, remainingPulsesInCurrentHalfHourEntry, delayUntilNextTenthPulseInUsec, interlockCommand); return new ProgramInsulinCommand(address, sequenceNumber, multiCommandFlag, nonce, max8HourInsulinProgramElements, currentHalfOurEntryIndex, remainingEighthSecondsInCurrentHalfHourEntry, remainingPulsesInCurrentHalfHourEntry, deliveryType, interlockCommand);
} }
} }
@Override public String toString() { public enum DeliveryType {
return "ProgramInsulinCommand{" + BASAL((byte) 0x00),
"insulinProgramElements=" + insulinProgramElements + TEMP_BASAL((byte) 0x01),
", programReminder=" + programReminder + BOLUS((byte) 0x02);
", currentHalfOurEntryIndex=" + currentHalfOurEntryIndex +
", remainingPulsesInCurrentHalfHourEntry=" + remainingPulsesInCurrentHalfHourEntry + private final byte value;
", delayUntilNextTenthPulseInUsec=" + delayUntilNextTenthPulseInUsec +
", commandType=" + commandType + DeliveryType(byte value) {
", address=" + address + this.value = value;
", sequenceNumber=" + sequenceNumber + }
", multiCommandFlag=" + multiCommandFlag +
'}'; public byte getValue() {
return value;
}
} }
} }