Skip to content

Commit

Permalink
G6 session requests
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoglom committed Dec 25, 2024
1 parent 8521bcd commit c53d64c
Show file tree
Hide file tree
Showing 14 changed files with 507 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@
import com.jwoglom.pumpx2.pump.messages.response.currentStatus.OtherNotificationStatusResponse;
import com.jwoglom.pumpx2.pump.messages.request.control.DismissNotificationRequest;
import com.jwoglom.pumpx2.pump.messages.response.control.DismissNotificationResponse;
import com.jwoglom.pumpx2.pump.messages.request.control.SetG6TransmitterIdRequest;
import com.jwoglom.pumpx2.pump.messages.response.control.SetG6TransmitterIdResponse;
import com.jwoglom.pumpx2.pump.messages.request.control.StartG6SensorSessionRequest;
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_END
import com.jwoglom.pumpx2.shared.L;

Expand Down Expand Up @@ -253,6 +259,9 @@ public enum Messages {
SET_QUICK_BOLUS_SETTINGS(SetQuickBolusSettingsRequest.class, SetQuickBolusSettingsResponse.class),
OTHER_NOTIFICATION_STATUS(OtherNotificationStatusRequest.class, OtherNotificationStatusResponse.class),
DISMISS_NOTIFICATION(DismissNotificationRequest.class, DismissNotificationResponse.class),
SET_G6_TRANSMITTER_ID(SetG6TransmitterIdRequest.class, SetG6TransmitterIdResponse.class),
START_G6_SENSOR_SESSION(StartG6SensorSessionRequest.class, StartG6SensorSessionResponse.class),
STOP_G6_SENSOR_SESSION(StopG6SensorSessionRequest.class, StopG6SensorSessionResponse.class),
// MESSAGES_END
;

Expand Down
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;
}
}
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;
}


}
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;

}


}
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;

}



}
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;
}

}
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;
}
}
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());
}
}
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());
}
}
Loading

0 comments on commit c53d64c

Please sign in to comment.