-
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
14 changed files
with
507 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
58 changes: 58 additions & 0 deletions
58
...main/java/com/jwoglom/pumpx2/pump/messages/request/control/SetG6TransmitterIdRequest.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,58 @@ | ||
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.models.KnownApiVersion; | ||
import com.jwoglom.pumpx2.pump.messages.response.control.SetG6TransmitterIdResponse; | ||
|
||
@MessageProps( | ||
opCode=-80, | ||
size=16, | ||
type=MessageType.REQUEST, | ||
characteristic=Characteristic.CONTROL, | ||
signed=true, | ||
response=SetG6TransmitterIdResponse.class, | ||
minApi=KnownApiVersion.MOBI_API_V3_5 | ||
) | ||
public class SetG6TransmitterIdRequest extends Message { | ||
public static final int TXID_LENGTH = 6; | ||
|
||
private String txId; | ||
|
||
public SetG6TransmitterIdRequest() { | ||
this.cargo = EMPTY; | ||
} | ||
|
||
public SetG6TransmitterIdRequest(byte[] raw) { | ||
this.cargo = raw; | ||
parse(raw); | ||
} | ||
|
||
public SetG6TransmitterIdRequest(String txId) { | ||
this.cargo = buildCargo(txId); | ||
this.txId = txId; | ||
} | ||
|
||
public void parse(byte[] raw) { | ||
raw = this.removeSignedRequestHmacBytes(raw); | ||
Preconditions.checkArgument(raw.length == props().size()); | ||
this.cargo = raw; | ||
this.txId = Bytes.readString(raw, 0, TXID_LENGTH); | ||
} | ||
|
||
|
||
public static byte[] buildCargo(String txId) { | ||
return Bytes.combine( | ||
Bytes.writeString(txId, 6), | ||
new byte[10] | ||
); | ||
} | ||
|
||
public String getTxId() { | ||
return txId; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...in/java/com/jwoglom/pumpx2/pump/messages/request/control/StartG6SensorSessionRequest.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,53 @@ | ||
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.StartG6SensorSessionResponse; | ||
|
||
@MessageProps( | ||
opCode=-78, | ||
size=2, | ||
type=MessageType.REQUEST, | ||
characteristic=Characteristic.CONTROL, | ||
signed=true, | ||
response=StartG6SensorSessionResponse.class | ||
) | ||
public class StartG6SensorSessionRequest extends Message { | ||
public static final int NO_CODE = 0; | ||
|
||
private int sensorCode; | ||
|
||
public StartG6SensorSessionRequest() { | ||
this.cargo = buildCargo(NO_CODE); | ||
this.sensorCode = NO_CODE; | ||
} | ||
|
||
public StartG6SensorSessionRequest(int sensorCode) { | ||
this.cargo = buildCargo(sensorCode); | ||
this.sensorCode = sensorCode; | ||
} | ||
|
||
public void parse(byte[] raw) { | ||
raw = this.removeSignedRequestHmacBytes(raw); | ||
Preconditions.checkArgument(raw.length == props().size()); | ||
this.cargo = raw; | ||
this.sensorCode = Bytes.readShort(raw, 0); | ||
|
||
} | ||
|
||
public static byte[] buildCargo(int sensorCode) { | ||
return Bytes.combine( | ||
Bytes.firstTwoBytesLittleEndian(sensorCode) | ||
); | ||
} | ||
|
||
public int getSensorCode() { | ||
return sensorCode; | ||
} | ||
|
||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...ain/java/com/jwoglom/pumpx2/pump/messages/request/control/StopG6SensorSessionRequest.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,32 @@ | ||
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.StopG6SensorSessionResponse; | ||
|
||
@MessageProps( | ||
opCode=-76, | ||
size=0, | ||
type=MessageType.REQUEST, | ||
characteristic=Characteristic.CONTROL, | ||
signed=true, | ||
response=StopG6SensorSessionResponse.class | ||
) | ||
public class StopG6SensorSessionRequest extends Message { | ||
public StopG6SensorSessionRequest() { | ||
this.cargo = EMPTY; | ||
} | ||
|
||
public void parse(byte[] raw) { | ||
raw = this.removeSignedRequestHmacBytes(raw); | ||
Preconditions.checkArgument(raw.length == props().size()); | ||
this.cargo = raw; | ||
|
||
} | ||
|
||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...in/java/com/jwoglom/pumpx2/pump/messages/response/control/SetG6TransmitterIdResponse.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,40 @@ | ||
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.models.KnownApiVersion; | ||
import com.jwoglom.pumpx2.pump.messages.request.control.SetG6TransmitterIdRequest; | ||
|
||
import java.math.BigInteger; | ||
|
||
@MessageProps( | ||
opCode=-79, | ||
size=0, | ||
type=MessageType.RESPONSE, | ||
characteristic=Characteristic.CONTROL, | ||
signed=true, | ||
request=SetG6TransmitterIdRequest.class, | ||
minApi=KnownApiVersion.MOBI_API_V3_5 | ||
) | ||
public class SetG6TransmitterIdResponse extends Message { | ||
|
||
|
||
public SetG6TransmitterIdResponse() { | ||
this.cargo = EMPTY; | ||
|
||
} | ||
|
||
public void parse(byte[] raw) { | ||
raw = this.removeSignedRequestHmacBytes(raw); | ||
Preconditions.checkArgument(raw.length == props().size()); | ||
this.cargo = raw; | ||
|
||
} | ||
|
||
|
||
|
||
} |
51 changes: 51 additions & 0 deletions
51
.../java/com/jwoglom/pumpx2/pump/messages/response/control/StartG6SensorSessionResponse.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,51 @@ | ||
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.StartG6SensorSessionRequest; | ||
|
||
import java.math.BigInteger; | ||
|
||
@MessageProps( | ||
opCode=-77, | ||
size=1, | ||
type=MessageType.RESPONSE, | ||
characteristic=Characteristic.CONTROL, | ||
signed=true, | ||
request=StartG6SensorSessionRequest.class | ||
) | ||
public class StartG6SensorSessionResponse extends Message { | ||
|
||
private int status; | ||
|
||
public StartG6SensorSessionResponse() {} | ||
|
||
public StartG6SensorSessionResponse(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; | ||
this.status = raw[0]; | ||
|
||
} | ||
|
||
|
||
public static byte[] buildCargo(int status) { | ||
return Bytes.combine( | ||
new byte[]{ (byte) status }); | ||
} | ||
|
||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...n/java/com/jwoglom/pumpx2/pump/messages/response/control/StopG6SensorSessionResponse.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.StopG6SensorSessionRequest; | ||
|
||
import java.math.BigInteger; | ||
|
||
@MessageProps( | ||
opCode=-75, | ||
size=1, | ||
type=MessageType.RESPONSE, | ||
characteristic=Characteristic.CONTROL, | ||
signed=true, | ||
request=StopG6SensorSessionRequest.class | ||
) | ||
public class StopG6SensorSessionResponse extends Message { | ||
|
||
private int status; | ||
|
||
public StopG6SensorSessionResponse() { | ||
this.cargo = EMPTY; | ||
} | ||
|
||
public StopG6SensorSessionResponse(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; | ||
this.status = raw[0]; | ||
} | ||
|
||
public static byte[] buildCargo(int status) { | ||
return Bytes.combine( | ||
Bytes.firstByteLittleEndian(status) | ||
); | ||
} | ||
|
||
|
||
// 0 = success | ||
public int getStatus() { | ||
return status; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
.../java/com/jwoglom/pumpx2/pump/messages/request/control/SetG6TransmitterIdRequestTest.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,39 @@ | ||
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 static org.junit.Assert.assertEquals; | ||
|
||
import com.jwoglom.pumpx2.pump.messages.MessageTester; | ||
import com.jwoglom.pumpx2.pump.messages.PacketArrayList; | ||
import com.jwoglom.pumpx2.pump.messages.bluetooth.CharacteristicUUID; | ||
import com.jwoglom.pumpx2.pump.messages.request.control.SetG6TransmitterIdRequest; | ||
|
||
import org.apache.commons.codec.DecoderException; | ||
import org.junit.Test; | ||
|
||
public class SetG6TransmitterIdRequestTest { | ||
@Test | ||
public void testSetG6TransmitterIdRequest_8L459R() throws DecoderException { | ||
initPumpState(PacketArrayList.IGNORE_INVALID_HMAC, 1L); | ||
|
||
// empty cargo | ||
SetG6TransmitterIdRequest expected = new SetG6TransmitterIdRequest( | ||
"8L459R" | ||
); | ||
|
||
SetG6TransmitterIdRequest parsedReq = (SetG6TransmitterIdRequest) MessageTester.test( | ||
"0221b02128384c34353952000000000000000000", | ||
33, | ||
1, | ||
CharacteristicUUID.CONTROL_CHARACTERISTICS, | ||
expected, | ||
"012100da09f31f74a5fbd08dc7fc210ddd3cb101", | ||
"00218f1dc87134edb724ae" | ||
); | ||
|
||
assertHexEquals(expected.getCargo(), parsedReq.getCargo()); | ||
assertEquals("8L459R", parsedReq.getTxId()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ava/com/jwoglom/pumpx2/pump/messages/request/control/StartG6SensorSessionRequestTest.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,32 @@ | ||
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.PacketArrayList; | ||
import com.jwoglom.pumpx2.pump.messages.bluetooth.CharacteristicUUID; | ||
import com.jwoglom.pumpx2.pump.messages.request.control.StartG6SensorSessionRequest; | ||
|
||
import org.apache.commons.codec.DecoderException; | ||
import org.junit.Test; | ||
|
||
public class StartG6SensorSessionRequestTest { | ||
@Test | ||
public void testStartG6SensorSessionRequest_code9311() throws DecoderException { | ||
initPumpState(PacketArrayList.IGNORE_INVALID_HMAC, 1L); | ||
|
||
StartG6SensorSessionRequest expected = new StartG6SensorSessionRequest(9311); | ||
|
||
StartG6SensorSessionRequest parsedReq = (StartG6SensorSessionRequest) MessageTester.test( | ||
"012eb22e1a5f24210af31f6806b4cc57d79bb047", | ||
46, | ||
1, | ||
CharacteristicUUID.CONTROL_CHARACTERISTICS, | ||
expected, | ||
"002e5f4261e734aaa05941d57f7901" | ||
); | ||
|
||
assertHexEquals(expected.getCargo(), parsedReq.getCargo()); | ||
} | ||
} |
Oops, something went wrong.