-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve protocol header documentation
Signed-off-by: Jacob Laursen <[email protected]>
- Loading branch information
Showing
7 changed files
with
169 additions
and
29 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
34 changes: 34 additions & 0 deletions
34
...a/src/main/java/org/openhab/binding/bluetooth/grundfosalpha/internal/protocol/Header.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 @@ | ||
/* | ||
* Copyright (c) 2010-2025 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.bluetooth.grundfosalpha.internal.protocol; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
/** | ||
* This defines protocol header related constants. | ||
* | ||
* @author Jacob Laursen - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class Header { | ||
/** | ||
* Header length including {@link MessageStartDelimiter} and size byte. | ||
*/ | ||
public static final int LENGTH = 5; | ||
|
||
/** | ||
* Identifier for requests (last three bytes of header). | ||
* The first two bytes appear to be swapped in the initial response message header. | ||
*/ | ||
public static final byte[] REQUEST_IDENTIFIER = { (byte) 0xe7, (byte) 0xf8, (byte) 0x0a }; | ||
} |
37 changes: 37 additions & 0 deletions
37
.../org/openhab/binding/bluetooth/grundfosalpha/internal/protocol/MessageStartDelimiter.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 @@ | ||
/* | ||
* Copyright (c) 2010-2025 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.bluetooth.grundfosalpha.internal.protocol; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
/** | ||
* This defines the start delimiters for different kinds of messages. | ||
* | ||
* @author Jacob Laursen - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public enum MessageStartDelimiter { | ||
Reply((byte) 0x24), | ||
Message((byte) 0x26), | ||
Request((byte) 0x27); | ||
|
||
private final byte value; | ||
|
||
MessageStartDelimiter(byte value) { | ||
this.value = value; | ||
} | ||
|
||
public byte getValue() { | ||
return value; | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
...t/java/org/openhab/binding/bluetooth/grundfosalpha/internal/protocol/MessageTypeTest.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 @@ | ||
/* | ||
* Copyright (c) 2010-2025 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.bluetooth.grundfosalpha.internal.protocol; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.junit.jupiter.api.Test; | ||
import org.openhab.core.util.HexUtils; | ||
|
||
/** | ||
* Tests for {@link MessageType}. | ||
* | ||
* @author Jacob Laursen - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class MessageTypeTest { | ||
@Test | ||
void requestFlowHead() { | ||
String expected = "27 07 E7 F8 0A 03 5D 01 21 52 1F"; | ||
assertThat(HexUtils.bytesToHex(MessageType.FlowHead.request(), " "), is(expected)); | ||
} | ||
|
||
@Test | ||
void requestPower() { | ||
String expected = "27 07 E7 F8 0A 03 57 00 45 8A CD"; | ||
assertThat(HexUtils.bytesToHex(MessageType.Power.request(), " "), is(expected)); | ||
} | ||
} |