-
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
159 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
40 changes: 40 additions & 0 deletions
40
...src/main/java/com/jwoglom/pumpx2/pump/messages/request/control/DisconnectPumpRequest.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.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.DisconnectPumpResponse; | ||
|
||
/* | ||
* I don't actually think calling this command is required... since an app can just disconnect | ||
* from the device over Bluetooth and forget the pairing key, and the user needs to re-trigger | ||
* a pair in order to connect again anyway (either via menu on tslim X2 or entering "pairing mode" | ||
* on the Mobi) | ||
*/ | ||
@MessageProps( | ||
opCode=-66, | ||
size=0, | ||
type=MessageType.REQUEST, | ||
characteristic=Characteristic.CONTROL, | ||
signed=true, | ||
response=DisconnectPumpResponse.class, | ||
minApi=KnownApiVersion.MOBI_API_V3_5 | ||
) | ||
public class DisconnectPumpRequest extends Message { | ||
public DisconnectPumpRequest() { | ||
this.cargo = EMPTY; | ||
} | ||
|
||
public void parse(byte[] raw) { | ||
raw = this.removeSignedRequestHmacBytes(raw); | ||
Preconditions.checkArgument(raw.length == props().size()); | ||
this.cargo = raw; | ||
|
||
} | ||
|
||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...c/main/java/com/jwoglom/pumpx2/pump/messages/response/control/DisconnectPumpResponse.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.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.DisconnectPumpRequest; | ||
|
||
import java.math.BigInteger; | ||
|
||
@MessageProps( | ||
opCode=-65, | ||
size=1, | ||
type=MessageType.RESPONSE, | ||
characteristic=Characteristic.CONTROL, | ||
signed=true, | ||
request=DisconnectPumpRequest.class, | ||
minApi=KnownApiVersion.MOBI_API_V3_5 | ||
) | ||
public class DisconnectPumpResponse extends Message { | ||
|
||
private int status; | ||
|
||
public DisconnectPumpResponse() {} | ||
|
||
public DisconnectPumpResponse(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; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...test/java/com/jwoglom/pumpx2/pump/messages/request/control/DisconnectPumpRequestTest.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.bluetooth.CharacteristicUUID; | ||
import com.jwoglom.pumpx2.pump.messages.request.control.DisconnectPumpRequest; | ||
|
||
import org.apache.commons.codec.DecoderException; | ||
import org.junit.Test; | ||
|
||
public class DisconnectPumpRequestTest { | ||
@Test | ||
public void testDisconnectPumpRequest() throws DecoderException { | ||
initPumpState("authenticationKey", 0L); | ||
|
||
// empty cargo | ||
DisconnectPumpRequest expected = new DisconnectPumpRequest(); | ||
|
||
DisconnectPumpRequest parsedReq = (DisconnectPumpRequest) MessageTester.test( | ||
"01debede18da38f31f38413194c36c036e110c25", | ||
-34, | ||
1, | ||
CharacteristicUUID.CONTROL_CHARACTERISTICS, | ||
expected, | ||
"00deff81b3f10f7af28dcfb8fc" | ||
); | ||
|
||
assertHexEquals(expected.getCargo(), parsedReq.getCargo()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...st/java/com/jwoglom/pumpx2/pump/messages/response/control/DisconnectPumpResponseTest.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.response.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 org.apache.commons.codec.DecoderException; | ||
import org.junit.Test; | ||
|
||
public class DisconnectPumpResponseTest { | ||
@Test | ||
public void testDisconnectPumpResponse() throws DecoderException { | ||
initPumpState("authenticationKey", 0L); | ||
|
||
DisconnectPumpResponse expected = new DisconnectPumpResponse( | ||
0 | ||
); | ||
|
||
DisconnectPumpResponse parsedRes = (DisconnectPumpResponse) MessageTester.test( | ||
"00debfde1900000000003fad35823cf021e2dad26d3f485cd5b4557dfe88ef21", | ||
-34, | ||
1, | ||
CharacteristicUUID.CONTROL_CHARACTERISTICS, | ||
expected | ||
); | ||
|
||
assertHexEquals(expected.getCargo(), parsedRes.getCargo()); | ||
} | ||
} |