-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...ain/java/com/jwoglom/pumpx2/pump/messages/request/control/EnterFillTubingModeRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} | ||
|
||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...n/java/com/jwoglom/pumpx2/pump/messages/response/control/EnterFillTubingModeResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...java/com/jwoglom/pumpx2/pump/messages/request/control/EnterFillTubingModeRequestTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...va/com/jwoglom/pumpx2/pump/messages/response/control/EnterFillTubingModeResponseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |