-
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
344 additions
and
4 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
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
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
47 changes: 47 additions & 0 deletions
47
...es/src/main/java/com/jwoglom/pumpx2/pump/messages/request/control/SetTempRateRequest.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,47 @@ | ||
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.models.SupportedDevices; | ||
import com.jwoglom.pumpx2.pump.messages.response.control.SetTempRateResponse; | ||
|
||
@MessageProps( | ||
opCode=-92, | ||
size=6, // 30 with signed | ||
type=MessageType.REQUEST, | ||
characteristic=Characteristic.CONTROL, | ||
signed=true, | ||
minApi=KnownApiVersion.MOBI_API_V3_5, | ||
supportedDevices=SupportedDevices.MOBI_ONLY, | ||
response=SetTempRateResponse.class | ||
) | ||
public class SetTempRateRequest extends Message { | ||
|
||
public SetTempRateRequest() {} | ||
|
||
public SetTempRateRequest(byte[] raw) { | ||
parse(raw); | ||
|
||
} | ||
|
||
public void parse(byte[] raw) { | ||
raw = this.removeSignedRequestHmacBytes(raw); | ||
Preconditions.checkArgument(raw.length == props().size()); | ||
this.cargo = raw; | ||
|
||
} | ||
|
||
|
||
public static byte[] buildCargo(int rate) { | ||
return Bytes.combine( | ||
new byte[]{0,0,0,0,0,0} | ||
); | ||
} | ||
|
||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...s/src/main/java/com/jwoglom/pumpx2/pump/messages/request/control/StopTempRateRequest.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,36 @@ | ||
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.models.SupportedDevices; | ||
import com.jwoglom.pumpx2.pump.messages.response.control.StopTempRateResponse; | ||
|
||
@MessageProps( | ||
opCode=-90, | ||
size=0, | ||
type=MessageType.REQUEST, | ||
characteristic=Characteristic.CONTROL, | ||
signed=true, | ||
minApi=KnownApiVersion.MOBI_API_V3_5, | ||
supportedDevices=SupportedDevices.MOBI_ONLY, | ||
response=StopTempRateResponse.class | ||
) | ||
public class StopTempRateRequest extends Message { | ||
public StopTempRateRequest() { | ||
this.cargo = EMPTY; | ||
} | ||
|
||
public void parse(byte[] raw) { | ||
raw = this.removeSignedRequestHmacBytes(raw); | ||
Preconditions.checkArgument(raw.length == props().size()); | ||
this.cargo = raw; | ||
|
||
} | ||
|
||
|
||
} |
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
49 changes: 49 additions & 0 deletions
49
.../src/main/java/com/jwoglom/pumpx2/pump/messages/response/control/SetTempRateResponse.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,49 @@ | ||
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.models.SupportedDevices; | ||
import com.jwoglom.pumpx2.pump.messages.request.control.SetTempRateRequest; | ||
|
||
import java.math.BigInteger; | ||
|
||
@MessageProps( | ||
opCode=-91, | ||
size=4, | ||
type=MessageType.RESPONSE, | ||
characteristic=Characteristic.CONTROL, | ||
signed=true, | ||
minApi=KnownApiVersion.MOBI_API_V3_5, | ||
supportedDevices=SupportedDevices.MOBI_ONLY, | ||
request=SetTempRateRequest.class | ||
) | ||
public class SetTempRateResponse extends Message { | ||
|
||
|
||
public SetTempRateResponse() {} | ||
|
||
public SetTempRateResponse(byte[] raw) { | ||
this.cargo = buildCargo(raw); | ||
|
||
} | ||
|
||
public void parse(byte[] raw) { | ||
raw = this.removeSignedRequestHmacBytes(raw); | ||
Preconditions.checkArgument(raw.length == props().size()); | ||
this.cargo = raw; | ||
|
||
} | ||
|
||
|
||
public static byte[] buildCargo(byte[] raw) { | ||
return Bytes.combine( | ||
raw); | ||
} | ||
|
||
|
||
} |
59 changes: 59 additions & 0 deletions
59
...src/main/java/com/jwoglom/pumpx2/pump/messages/response/control/StopTempRateResponse.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,59 @@ | ||
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.models.SupportedDevices; | ||
import com.jwoglom.pumpx2.pump.messages.request.control.StopTempRateRequest; | ||
|
||
import java.math.BigInteger; | ||
|
||
@MessageProps( | ||
opCode=-89, | ||
size=3, | ||
type=MessageType.RESPONSE, | ||
characteristic=Characteristic.CONTROL, | ||
signed=true, | ||
minApi=KnownApiVersion.MOBI_API_V3_5, | ||
supportedDevices=SupportedDevices.MOBI_ONLY, | ||
request=StopTempRateRequest.class | ||
) | ||
public class StopTempRateResponse extends Message { | ||
|
||
private int bit1; | ||
private int bit2; | ||
private int bit3; | ||
|
||
public StopTempRateResponse() { | ||
} | ||
|
||
public StopTempRateResponse(byte[] raw) { | ||
parse(raw); | ||
} | ||
|
||
public void parse(byte[] raw) { | ||
raw = this.removeSignedRequestHmacBytes(raw); | ||
Preconditions.checkArgument(raw.length == props().size()); | ||
this.cargo = raw; | ||
this.bit1 = raw[0]; | ||
this.bit2 = raw[1]; | ||
this.bit3 = raw[2]; | ||
|
||
} | ||
|
||
public int getBit1() { | ||
return bit1; | ||
} | ||
|
||
public int getBit2() { | ||
return bit2; | ||
} | ||
|
||
public int getBit3() { | ||
return bit3; | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...rc/test/java/com/jwoglom/pumpx2/pump/messages/request/control/SetTempRateRequestTest.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,37 @@ | ||
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 org.apache.commons.codec.DecoderException; | ||
import org.junit.Test; | ||
|
||
public class SetTempRateRequestTest { | ||
@Test | ||
public void testSetTempRateRequest_95pct_15min() throws DecoderException { | ||
// TimeSinceResetResponse[currentTime=512443560,pumpTimeSinceReset=1906112,cargo={-88,68,-117,30,-64,21,29,0}] | ||
initPumpState(PacketArrayList.IGNORE_INVALID_HMAC, 1906112L); | ||
|
||
// Temp Rate 95% for 15m | ||
SetTempRateRequest expected = new SetTempRateRequest( | ||
new byte[]{-96,-69,13,0,95,0} | ||
); | ||
|
||
SetTempRateRequest parsedReq = (SetTempRateRequest) MessageTester.test( | ||
// Untitled_2_Live_-_Humans_iPhone 2 | ||
// 2024-03-28T00:26:21.525000+00:00 | ||
"0122a4221ea0bb0d005f001c998b1e37eacb5339", | ||
34, | ||
1, | ||
CharacteristicUUID.CONTROL_CHARACTERISTICS, | ||
expected, | ||
"00227c57675fc47f8c9bf5dec1f0d31d42a4b7" | ||
); | ||
|
||
assertHexEquals(expected.getCargo(), parsedReq.getCargo()); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...c/test/java/com/jwoglom/pumpx2/pump/messages/request/control/StopTempRateRequestTest.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,34 @@ | ||
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.StopTempRateRequest; | ||
|
||
import org.apache.commons.codec.DecoderException; | ||
import org.junit.Test; | ||
|
||
public class StopTempRateRequestTest { | ||
@Test | ||
public void testStopTempRateRequest() throws DecoderException { | ||
// TimeSinceResetResponse[currentTime=512443560,pumpTimeSinceReset=1906112,cargo={-88,68,-117,30,-64,21,29,0}] | ||
initPumpState(PacketArrayList.IGNORE_INVALID_HMAC, 1906112L); | ||
|
||
// empty cargo | ||
StopTempRateRequest expected = new StopTempRateRequest(); | ||
|
||
StopTempRateRequest parsedReq = (StopTempRateRequest) MessageTester.test( | ||
"012ca62c182c998b1e92605660ce66863620411d", | ||
44, | ||
2, | ||
CharacteristicUUID.CONTROL_CHARACTERISTICS, | ||
expected, | ||
"002c0d420615066cb0f317766c" | ||
); | ||
|
||
assertHexEquals(expected.getCargo(), parsedReq.getCargo()); | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
.../test/java/com/jwoglom/pumpx2/pump/messages/response/control/SetTempRateResponseTest.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 SetTempRateResponseTest { | ||
@Test | ||
public void testSetTempRateResponse() throws DecoderException { | ||
initPumpState("authenticationKey", 0L); | ||
|
||
SetTempRateResponse expected = new SetTempRateResponse( | ||
// byte[] raw | ||
); | ||
|
||
SetTempRateResponse parsedRes = (SetTempRateResponse) MessageTester.test( | ||
"xxxx", | ||
3, | ||
1, | ||
CharacteristicUUID.CONTROL_CHARACTERISTICS, | ||
expected | ||
); | ||
|
||
assertHexEquals(expected.getCargo(), parsedRes.getCargo()); | ||
} | ||
} |
Oops, something went wrong.