Skip to content

Commit

Permalink
PlaySoundRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoglom committed Dec 26, 2024
1 parent 1931710 commit 6beb481
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@
import com.jwoglom.pumpx2.pump.messages.response.control.StartG6SensorSessionResponse;
import com.jwoglom.pumpx2.pump.messages.request.control.StopG6SensorSessionRequest;
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_END
import com.jwoglom.pumpx2.shared.L;

Expand Down Expand Up @@ -262,6 +264,7 @@ public enum Messages {
SET_G6_TRANSMITTER_ID(SetG6TransmitterIdRequest.class, SetG6TransmitterIdResponse.class),
START_G6_SENSOR_SESSION(StartG6SensorSessionRequest.class, StartG6SensorSessionResponse.class),
STOP_G6_SENSOR_SESSION(StopG6SensorSessionRequest.class, StopG6SensorSessionResponse.class),
PLAY_SOUND(PlaySoundRequest.class, PlaySoundResponse.class),
// MESSAGES_END
;

Expand Down
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.PlaySoundResponse;

@MessageProps(
opCode=-12,
size=0,
type=MessageType.REQUEST,
characteristic=Characteristic.CONTROL,
signed=true,
response=PlaySoundResponse.class
)
public class PlaySoundRequest extends Message {
public PlaySoundRequest() {
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,44 @@
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.PlaySoundRequest;

import java.math.BigInteger;

@MessageProps(
opCode=-11,
size=1,
type=MessageType.RESPONSE,
characteristic=Characteristic.CONTROL,
signed=true,
request=PlaySoundRequest.class
)
public class PlaySoundResponse extends Message {
private int status;

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

public PlaySoundResponse(byte[] raw) {
parse(raw);
}

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

}


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.PlaySoundRequest;

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

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

PlaySoundRequest expected = new PlaySoundRequest();

PlaySoundRequest parsedReq = (PlaySoundRequest) MessageTester.test(
"01cef4ce182337f31f36da5eea5ed250773df9b0",
-50,
1,
CharacteristicUUID.CONTROL_CHARACTERISTICS,
expected,
"00ce91daca790983cb56d5fff1"
);

assertHexEquals(expected.getCargo(), parsedReq.getCargo());
}
}
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 PlaySoundResponseTest {
@Test
public void testPlaySoundResponse() throws DecoderException {
initPumpState("authenticationKey", 0L);

PlaySoundResponse expected = new PlaySoundResponse(
new byte[]{0}
);

PlaySoundResponse parsedRes = (PlaySoundResponse) MessageTester.test(
"00cef5ce1900cef0f21fbf00d7c6462ba60db8d201b730849ce4458962818856",
-50,
1,
CharacteristicUUID.CONTROL_CHARACTERISTICS,
expected
);

assertHexEquals(expected.getCargo(), parsedRes.getCargo());
}
}

0 comments on commit 6beb481

Please sign in to comment.