Skip to content

Commit

Permalink
EnterFillTubingMode
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoglom committed Dec 23, 2024
1 parent f4edc81 commit 5aa848d
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@
import com.jwoglom.pumpx2.pump.messages.response.control.ResumePumpingResponse;
import com.jwoglom.pumpx2.pump.messages.request.control.ChangeControlIQSettingsRequest;
import com.jwoglom.pumpx2.pump.messages.response.control.ChangeControlIQSettingsResponse;
import com.jwoglom.pumpx2.pump.messages.request.control.EnterFillTubingModeRequest;
import com.jwoglom.pumpx2.pump.messages.response.control.EnterFillTubingModeResponse;
// IMPORT_END
import com.jwoglom.pumpx2.shared.L;

Expand Down Expand Up @@ -241,6 +243,7 @@ public enum Messages {
STOP_TEMP_RATE(StopTempRateRequest.class, StopTempRateResponse.class),
RESUME_PUMPING(ResumePumpingRequest.class, ResumePumpingResponse.class),
CHANGE_CONTROL_IQ_SETTINGS(ChangeControlIQSettingsRequest.class, ChangeControlIQSettingsResponse.class),
ENTER_FILL_TUBING_MODE(EnterFillTubingModeRequest.class, EnterFillTubingModeResponse.class),
// MESSAGES_END
;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.jwoglom.pumpx2.pump.messages.request.control;

import com.google.common.base.Preconditions;
import com.jwoglom.pumpx2.pump.messages.bluetooth.Characteristic;
import com.jwoglom.pumpx2.pump.messages.helpers.Bytes;
import com.jwoglom.pumpx2.pump.messages.Message;
import com.jwoglom.pumpx2.pump.messages.MessageType;
import com.jwoglom.pumpx2.pump.messages.annotations.MessageProps;
import com.jwoglom.pumpx2.pump.messages.response.control.EnterFillTubingModeResponse;

@MessageProps(
opCode=-108,
size=0,
type=MessageType.REQUEST,
characteristic=Characteristic.CONTROL,
signed=true,
modifiesInsulinDelivery=true,
response=EnterFillTubingModeResponse.class
)
public class EnterFillTubingModeRequest extends Message {
public EnterFillTubingModeRequest() {
this.cargo = EMPTY;
}

public void parse(byte[] raw) {
raw = this.removeSignedRequestHmacBytes(raw);
Preconditions.checkArgument(raw.length == props().size());
this.cargo = raw;

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.jwoglom.pumpx2.pump.messages.response.control;

import com.google.common.base.Preconditions;
import com.jwoglom.pumpx2.pump.messages.bluetooth.Characteristic;
import com.jwoglom.pumpx2.pump.messages.helpers.Bytes;
import com.jwoglom.pumpx2.pump.messages.Message;
import com.jwoglom.pumpx2.pump.messages.MessageType;
import com.jwoglom.pumpx2.pump.messages.annotations.MessageProps;
import com.jwoglom.pumpx2.pump.messages.request.control.EnterFillTubingModeRequest;

import java.math.BigInteger;

@MessageProps(
opCode=-107,
size=1,
type=MessageType.RESPONSE,
characteristic=Characteristic.CONTROL,
signed=true,
modifiesInsulinDelivery=true,
request=EnterFillTubingModeRequest.class
)
public class EnterFillTubingModeResponse extends Message {

private int status;

public EnterFillTubingModeResponse() {
this.cargo = EMPTY;
}

public EnterFillTubingModeResponse(int status) {
this.cargo = buildCargo(status);
this.status = status;
}

public void parse(byte[] raw) {
raw = this.removeSignedRequestHmacBytes(raw);
Preconditions.checkArgument(raw.length == props().size());
this.cargo = raw;
}


public static byte[] buildCargo(int status) {
return Bytes.combine(
new byte[]{ (byte) status }
);
}


public int getStatus() {
return status;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.jwoglom.pumpx2.pump.messages.request.control;

import static com.jwoglom.pumpx2.pump.messages.MessageTester.assertHexEquals;
import static com.jwoglom.pumpx2.pump.messages.MessageTester.initPumpState;

import com.jwoglom.pumpx2.pump.messages.MessageTester;
import com.jwoglom.pumpx2.pump.messages.bluetooth.CharacteristicUUID;
import com.jwoglom.pumpx2.pump.messages.request.control.EnterFillTubingModeRequest;

import org.apache.commons.codec.DecoderException;
import org.junit.Test;

public class EnterFillTubingModeRequestTest {
@Test
public void testEnterFillTubingModeRequest() throws DecoderException {
initPumpState("authenticationKey", 0L);

EnterFillTubingModeRequest expected = new EnterFillTubingModeRequest();

EnterFillTubingModeRequest parsedReq = (EnterFillTubingModeRequest) MessageTester.test(
"017a947a1851eaee1f5595738c382cc5dc5552a2",
122,
1,
CharacteristicUUID.CONTROL_CHARACTERISTICS,
expected,
"007a4aa8482c322b5fd69805e8"
);

assertHexEquals(expected.getCargo(), parsedReq.getCargo());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.jwoglom.pumpx2.pump.messages.response.control;

import static com.jwoglom.pumpx2.pump.messages.MessageTester.assertHexEquals;
import static com.jwoglom.pumpx2.pump.messages.MessageTester.initPumpState;

import static org.junit.Assert.assertEquals;

import com.jwoglom.pumpx2.pump.messages.MessageTester;
import com.jwoglom.pumpx2.pump.messages.bluetooth.CharacteristicUUID;

import org.apache.commons.codec.DecoderException;
import org.junit.Test;

public class EnterFillTubingModeResponseTest {
@Test
public void testEnterFillTubingModeResponse() throws DecoderException {
initPumpState("authenticationKey", 0L);

EnterFillTubingModeResponse expected = new EnterFillTubingModeResponse(
0
);

EnterFillTubingModeResponse parsedRes = (EnterFillTubingModeResponse) MessageTester.test(
"007a957a1900fea3ee1fe559e33c9fdc97594748e9c9631ee2db4458683f3412",
122,
1,
CharacteristicUUID.CONTROL_CHARACTERISTICS,
expected
);

assertHexEquals(expected.getCargo(), parsedRes.getCargo());
assertEquals(0, parsedRes.getStatus());
}
}

0 comments on commit 5aa848d

Please sign in to comment.