diff --git a/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/Messages.java b/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/Messages.java index 3bcf0c5..1a1a84d 100644 --- a/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/Messages.java +++ b/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/Messages.java @@ -170,6 +170,8 @@ import com.jwoglom.pumpx2.pump.messages.response.control.StopG6SensorSessionResponse; import com.jwoglom.pumpx2.pump.messages.request.control.PlaySoundRequest; import com.jwoglom.pumpx2.pump.messages.response.control.PlaySoundResponse; +import com.jwoglom.pumpx2.pump.messages.request.control.DisconnectPumpRequest; +import com.jwoglom.pumpx2.pump.messages.response.control.DisconnectPumpResponse; // IMPORT_END import com.jwoglom.pumpx2.shared.L; @@ -265,6 +267,7 @@ public enum Messages { START_G6_SENSOR_SESSION(StartG6SensorSessionRequest.class, StartG6SensorSessionResponse.class), STOP_G6_SENSOR_SESSION(StopG6SensorSessionRequest.class, StopG6SensorSessionResponse.class), PLAY_SOUND(PlaySoundRequest.class, PlaySoundResponse.class), + DISCONNECT_PUMP(DisconnectPumpRequest.class, DisconnectPumpResponse.class), // MESSAGES_END ; diff --git a/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/request/control/DisconnectPumpRequest.java b/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/request/control/DisconnectPumpRequest.java new file mode 100644 index 0000000..b867910 --- /dev/null +++ b/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/request/control/DisconnectPumpRequest.java @@ -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; + + } + + +} \ No newline at end of file diff --git a/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/response/control/DisconnectPumpResponse.java b/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/response/control/DisconnectPumpResponse.java new file mode 100644 index 0000000..ed3bc45 --- /dev/null +++ b/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/response/control/DisconnectPumpResponse.java @@ -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; + } + +} \ No newline at end of file diff --git a/messages/src/test/java/com/jwoglom/pumpx2/pump/messages/request/control/DisconnectPumpRequestTest.java b/messages/src/test/java/com/jwoglom/pumpx2/pump/messages/request/control/DisconnectPumpRequestTest.java new file mode 100644 index 0000000..6fa4934 --- /dev/null +++ b/messages/src/test/java/com/jwoglom/pumpx2/pump/messages/request/control/DisconnectPumpRequestTest.java @@ -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()); + } +} \ No newline at end of file diff --git a/messages/src/test/java/com/jwoglom/pumpx2/pump/messages/response/control/DisconnectPumpResponseTest.java b/messages/src/test/java/com/jwoglom/pumpx2/pump/messages/response/control/DisconnectPumpResponseTest.java new file mode 100644 index 0000000..d72b374 --- /dev/null +++ b/messages/src/test/java/com/jwoglom/pumpx2/pump/messages/response/control/DisconnectPumpResponseTest.java @@ -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()); + } +} \ No newline at end of file