Skip to content

Commit

Permalink
fix(cbus): implementd InterfaceRequirementsTest and fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Aug 8, 2022
1 parent d3f7132 commit 4e43951
Show file tree
Hide file tree
Showing 5 changed files with 293 additions and 38 deletions.
8 changes: 8 additions & 0 deletions plc4go/protocols/cbus/readwrite/model/ConfirmationType.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plc4go/protocols/cbus/readwrite/model/StaticHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func ReadCALData(readBuffer utils.ReadBuffer) (CALData, error) {
func readBytesFromHex(logicalName string, readBuffer utils.ReadBuffer, srchk bool) ([]byte, error) {
payloadLength := findHexEnd(readBuffer)
if payloadLength == 0 {
return nil, errors.New("Length is 0")
return nil, utils.ParseAssertError{Message: "Length is 0"}
}
hexBytes, err := readBuffer.ReadByteArray(logicalName, payloadLength)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static CALData readCALData(ReadBuffer readBuffer) throws ParseException {
private static byte[] readBytesFromHex(String logicalName, ReadBuffer readBuffer, boolean srchk) throws ParseException {
int payloadLength = findHexEnd(readBuffer);
if (payloadLength == 0) {
throw new ParseException("Length is 0");
throw new ParseAssertException("Length is 0");
}

byte[] hexBytes = readBuffer.readByteArray(logicalName, payloadLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,58 +47,304 @@ void setUp() {
// from: https://updates.clipsal.com/ClipsalSoftwareDownload/DL/downloads/OpenCBus/C-Bus%20Interface%20Requirements.pdf
@Nested
class InterfaceRequirementsTest {
// TODO: implement those


// 8.5
// 8.2
@Nested
class Level4InterfaceImplementationRequirements {
class Level1InterfaceImplementationRequirements {

@Test
void Reset() throws Exception {
byte[] bytes = "~~~\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);
// 8.2.4
@Nested
class SerialInterfaceInitialisation {

assertMessageMatches(bytes, msg);
@Test
void Step_1_Reset() throws Exception {
byte[] bytes = "~~~\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void Step_2_SetInterfaceOptions3() throws Exception {
byte[] bytes = "@A3420002\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void Step_3_SetInterfaceOptions1_PUN() throws Exception {
byte[] bytes = "@A3410058\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void Step_4_SetInterfaceOptions1() throws Exception {
byte[] bytes = "@A3300058\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}
}

@Test
void SetInterfaceOptions3() throws Exception {
byte[] bytes = "@A342000A\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);
// 8.2.5
@Nested
class ConfirmationOfTransmission {
@Test
void SomeCommand() throws Exception {
byte[] bytes = "\\0538000121A1g\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
cBusOptions = C_BUS_OPTIONS_WITH_SRCHK;
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
assertMessageMatches(bytes, msg);
}

@Test
void success() throws Exception {
byte[] bytes = "g.".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void checksumFailure() throws Exception {
byte[] bytes = "g!".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void tooManyRetransmissions() throws Exception {
byte[] bytes = "g#".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void corruptionInTransmission() throws Exception {
byte[] bytes = "g$".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void noSystemClock() throws Exception {
byte[] bytes = "g%".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}
}
}

@Test
void SetInterfaceOptions1_PUN() throws Exception {
byte[] bytes = "@A3410079\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);
// 8.3
@Nested
class Level2InterfaceImplementationRequirements {

assertMessageMatches(bytes, msg);
// 8.3.4
@Nested
class SerialInterfaceInitialisation {
@Test
void Step_1_Reset() throws Exception {
byte[] bytes = "~~~\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void Step_2_AnyApplicationFilter() throws Exception {
byte[] bytes = "@A3210038\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void Step_3_SetInterfaceOptions3() throws Exception {
byte[] bytes = "@A3420002\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void Step_4_SetInterfaceOptions1_PUN() throws Exception {
byte[] bytes = "@A3410059\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void Step_5_SetInterfaceOptions1() throws Exception {
byte[] bytes = "@A3300059\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}
}

@Test
void SetInterfaceOptions1() throws Exception {
byte[] bytes = "@A3300079\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);
// 8.3.5
@Nested
class ProgrammingTheSerialInterfaceToFilterSALMessageTraffic {

assertMessageMatches(bytes, msg);
@Test
void Step_1_SelectOnlyLighting() throws Exception {
byte[] bytes = "@A3210038\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void Step_2_SelectHeatingAsSecondApplication() throws Exception {
byte[] bytes = "@A3220088\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}
}
}

// 8.4
@Nested
class Level3InterfaceImplementationRequirements {
// No specific tests
}

// 8.5
@Nested
class Level4InterfaceImplementationRequirements {

// 8.5.4
@Nested
class SerialInterfaceInitialisation {
@Test
void Step_1_Reset() throws Exception {
byte[] bytes = "~~~\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void Step_2_AnyApplicationFilter() throws Exception {
byte[] bytes = "@A3210038\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void Step_3_SetInterfaceOptions3() throws Exception {
byte[] bytes = "@A342000A\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void Step_4_SetInterfaceOptions1_PUN() throws Exception {
byte[] bytes = "@A3410079\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}

@Test
void Step_5_SetInterfaceOptions1() throws Exception {
byte[] bytes = "@A3300079\r".getBytes(StandardCharsets.UTF_8);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions);
assertThat(msg).isNotNull();
System.out.println(msg);

assertMessageMatches(bytes, msg);
}
}
}

// 8.6
@Nested
class Level5InterfaceImplementationRequirements {
// No specific tests
}

// 8.7
@Nested
class Level6InterfaceImplementationRequirements {
// No specific tests
}
}

// from: https://updates.clipsal.com/ClipsalSoftwareDownload/DL/downloads/OpenCBus/Serial%20Interface%20User%20Guide.pdf
Expand Down
Loading

0 comments on commit 4e43951

Please sign in to comment.