You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2022/07/21 09:22:22 UTC
[plc4x] 01/05: fix(cbus): only use request context once on cal data
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit d3179612d683b24106ea07660cd56fa13bbbb903
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Jul 20 11:00:05 2022 +0200
fix(cbus): only use request context once on cal data
---
plc4go/protocols/cbus/readwrite/model/CALData.go | 2 +-
.../apache/plc4x/java/cbus/RandomPackagesTest.java | 584 +++++++++++----------
.../src/main/resources/protocols/cbus/c-bus.mspec | 3 +-
3 files changed, 299 insertions(+), 290 deletions(-)
diff --git a/plc4go/protocols/cbus/readwrite/model/CALData.go b/plc4go/protocols/cbus/readwrite/model/CALData.go
index 6bdc9a273..a03043e25 100644
--- a/plc4go/protocols/cbus/readwrite/model/CALData.go
+++ b/plc4go/protocols/cbus/readwrite/model/CALData.go
@@ -242,7 +242,7 @@ func CALDataParse(readBuffer utils.ReadBuffer, requestContext RequestContext) (C
if pullErr := readBuffer.PullContext("additionalData"); pullErr != nil {
return nil, errors.Wrap(pullErr, "Error pulling for additionalData")
}
- _val, _err := CALDataParse(readBuffer, requestContext)
+ _val, _err := CALDataParse(readBuffer, nil)
switch {
case errors.Is(_err, utils.ParseAssertError{}) || errors.Is(_err, io.EOF):
log.Debug().Err(_err).Msg("Resetting position because optional threw an error")
diff --git a/plc4j/drivers/c-bus/src/test/java/org/apache/plc4x/java/cbus/RandomPackagesTest.java b/plc4j/drivers/c-bus/src/test/java/org/apache/plc4x/java/cbus/RandomPackagesTest.java
index 259a692ee..6d40c2bbd 100644
--- a/plc4j/drivers/c-bus/src/test/java/org/apache/plc4x/java/cbus/RandomPackagesTest.java
+++ b/plc4j/drivers/c-bus/src/test/java/org/apache/plc4x/java/cbus/RandomPackagesTest.java
@@ -23,7 +23,6 @@ import org.apache.plc4x.java.spi.generation.ReadBufferByteBased;
import org.apache.plc4x.java.spi.generation.WriteBufferByteBased;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
@@ -42,297 +41,306 @@ public class RandomPackagesTest {
cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, false);
}
- @Nested
- class OwnCaptures {
-
- @Disabled
- @Test
- void whatEverThisIs() throws Exception {
- byte[] bytes = "\\3436303230303231303167\r".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- assertMessageMatches(bytes, msg);
- }
-
- @Test
- void deviceManagementInstruction() throws Exception {
- byte[] bytes = "@1A2001\r".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- assertMessageMatches(bytes, msg);
- }
-
- @Test
- void setLight() throws Exception {
- byte[] bytes = "\\0538000100g\r".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- CBusMessageToServer msgToServer = (CBusMessageToServer) msg;
- RequestCommand requestCommand = (RequestCommand) msgToServer.getRequest();
- CBusCommand cbusCommand = requestCommand.getCbusCommand();
- System.out.println(cbusCommand);
- assertMessageMatches(bytes, msg);
- }
-
- @Test
- void identifyResponse() throws Exception {
- byte[] bytes = "g.890150435F434E49454421\r\n".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- // We know we send an identify command so we set the cal flag
- requestContext = new RequestContext(true, false, false);
- cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- CBusMessageToClient messageToClient = (CBusMessageToClient) msg;
- ReplyOrConfirmationConfirmation confirmationReply = (ReplyOrConfirmationConfirmation) messageToClient.getReply();
- ReplyOrConfirmationReply normalReply = (ReplyOrConfirmationReply) confirmationReply.getEmbeddedReply();
- EncodedReplyCALReply encodedReplyCALReply = (EncodedReplyCALReply) ((ReplyEncodedReply) normalReply.getReply()).getEncodedReply();
- System.out.println(encodedReplyCALReply.getCalReply());
- assertMessageMatches(bytes, msg);
- }
-
- @Test
- void someResponse() throws Exception {
- byte[] bytes = "nl.8220025C\r\n".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- requestContext = new RequestContext(true, false, false);
- cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- CBusMessageToClient messageToClient = (CBusMessageToClient) msg;
- ReplyOrConfirmationConfirmation confirmationReply = (ReplyOrConfirmationConfirmation) messageToClient.getReply();
- ReplyOrConfirmationReply normalReply = (ReplyOrConfirmationReply) confirmationReply.getEmbeddedReply();
- EncodedReplyCALReply encodedReplyCALReply = (EncodedReplyCALReply) ((ReplyEncodedReply) normalReply.getReply()).getEncodedReply();
- System.out.println(encodedReplyCALReply.getCalReply());
- assertMessageMatches(bytes, msg);
- }
-
- @Test
- void someOtherResponse() throws Exception {
- byte[] bytes = "\\0538000100g\r".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- CBusMessageToServer messageToServer = (CBusMessageToServer) msg;
- RequestCommand requestCommand = (RequestCommand) messageToServer.getRequest();
- System.out.println(requestCommand.getCbusCommand());
- assertMessageMatches(bytes, msg);
- }
-
-
- @Test
- void identifyRequest2() throws Exception {
- byte[] bytes = "21021A2102i\r".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- CBusMessageToServer messageToServer = (CBusMessageToServer) msg;
- CALData calData = ((RequestObsolete) ((CBusMessageToServer) msg).getRequest()).getCalData();
- System.out.println(calData);
- assertMessageMatches(bytes, msg);
- }
-
- @Test
- void identifyResponse2() throws Exception {
- byte[] bytes = "i.8902352E342E3030202010\r\n".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- // We know we send an identify command so we set the cal flag
- requestContext = new RequestContext(true, false, true);
- cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- CBusMessageToClient messageToClient = (CBusMessageToClient) msg;
- ReplyOrConfirmationConfirmation confirmationReply = (ReplyOrConfirmationConfirmation) messageToClient.getReply();
- ReplyOrConfirmationReply normalReply = (ReplyOrConfirmationReply) confirmationReply.getEmbeddedReply();
- EncodedReplyCALReply encodedReplyCALReply = (EncodedReplyCALReply) ((ReplyEncodedReply) normalReply.getReply()).getEncodedReply();
- System.out.println(encodedReplyCALReply.getCalReply());
- assertMessageMatches(bytes, msg);
- }
-
- @Test
- void recall() throws Exception {
- byte[] bytes = "@1A2001\r".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- CBusMessageToServer messageToServer = (CBusMessageToServer) msg;
- RequestDirectCommandAccess requestDirectCommandAccess = (RequestDirectCommandAccess) messageToServer.getRequest();
- CALData calData = ((RequestDirectCommandAccess) ((CBusMessageToServer) msg).getRequest()).getCalData();
- System.out.println(calData);
-
- WriteBufferByteBased writeBuffer = new WriteBufferByteBased(bytes.length);
- msg.serialize(writeBuffer);
- assertThat(writeBuffer.getBytes()).isEqualTo(bytes);
- assertMessageMatches(bytes, msg);
- }
-
- @Test
- void identifyTypeReply() throws Exception {
- byte[] bytes = "h.890150435F434E49454421\r\n".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- requestContext = new RequestContext(true, false, true);
- cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- CBusMessageToClient messageToClient = (CBusMessageToClient) msg;
- ReplyOrConfirmationConfirmation confirmationReply = (ReplyOrConfirmationConfirmation) messageToClient.getReply();
- ReplyOrConfirmationReply normalReply = (ReplyOrConfirmationReply) confirmationReply.getEmbeddedReply();
- EncodedReplyCALReply encodedReplyCALReply = (EncodedReplyCALReply) ((ReplyEncodedReply) normalReply.getReply()).getEncodedReply();
- System.out.println(encodedReplyCALReply.getCalReply());
-
- assertMessageMatches(bytes, msg);
- }
-
- @Test
- void write30to9755() throws Exception {
- byte[] bytes = "A3309755s\r".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- System.out.println(((RequestObsolete) ((CBusMessageToServer) msg).getRequest()).getCalData());
-
- assertMessageMatches(bytes, msg);
- }
-
- @Test
- void strangeNotYetParsableCommandResponse() throws Exception {
- byte[] bytes = "s.860202003230977D\r\n".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- requestContext = new RequestContext(true, false, false);
- cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- CBusMessageToClient messageToClient = (CBusMessageToClient) msg;
- ReplyOrConfirmationConfirmation confirmationReply = (ReplyOrConfirmationConfirmation) messageToClient.getReply();
- ReplyOrConfirmationReply normalReply = (ReplyOrConfirmationReply) confirmationReply.getEmbeddedReply();
- EncodedReplyCALReply encodedReplyCALReply = (EncodedReplyCALReply) ((ReplyEncodedReply) normalReply.getReply()).getEncodedReply();
- System.out.println(encodedReplyCALReply.getCalReply());
-
- assertMessageMatches(bytes, msg);
- }
-
- @Test
- void statusRequestBinaryState() throws Exception {
- byte[] bytes = "\\05FF00FAFF00v\r".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- CBusMessageToServer messageToServer = (CBusMessageToServer) msg;
- RequestCommand requestCommand = (RequestCommand) messageToServer.getRequest();
- CBusCommand cbusCommand = requestCommand.getCbusCommand();
- System.out.println(cbusCommand);
- assertMessageMatches(bytes, msg);
- }
-
- @Disabled
- @Test
- void wat() throws Exception {
- byte[] bytes = "D8FF0024000002000000000000000008000000000000000000\r\n".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
- requestContext = new RequestContext(true, false, false);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- CBusMessageToClient messageToClient = (CBusMessageToClient) msg;
- ReplyOrConfirmationReply reply = (ReplyOrConfirmationReply) messageToClient.getReply();
+ @Disabled
+ @Test
+ void whatEverThisIs() throws Exception {
+ byte[] bytes = "\\3436303230303231303167\r".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void deviceManagementInstruction() throws Exception {
+ byte[] bytes = "@1A2001\r".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void setLight() throws Exception {
+ byte[] bytes = "\\0538000100g\r".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ CBusMessageToServer msgToServer = (CBusMessageToServer) msg;
+ RequestCommand requestCommand = (RequestCommand) msgToServer.getRequest();
+ CBusCommand cbusCommand = requestCommand.getCbusCommand();
+ System.out.println(cbusCommand);
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void identifyResponse() throws Exception {
+ byte[] bytes = "g.890150435F434E49454421\r\n".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ // We know we send an identify command so we set the cal flag
+ requestContext = new RequestContext(true, false, false);
+ cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ CBusMessageToClient messageToClient = (CBusMessageToClient) msg;
+ ReplyOrConfirmationConfirmation confirmationReply = (ReplyOrConfirmationConfirmation) messageToClient.getReply();
+ ReplyOrConfirmationReply normalReply = (ReplyOrConfirmationReply) confirmationReply.getEmbeddedReply();
+ EncodedReplyCALReply encodedReplyCALReply = (EncodedReplyCALReply) ((ReplyEncodedReply) normalReply.getReply()).getEncodedReply();
+ System.out.println(encodedReplyCALReply.getCalReply());
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void someResponse() throws Exception {
+ byte[] bytes = "nl.8220025C\r\n".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ requestContext = new RequestContext(true, false, false);
+ cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ CBusMessageToClient messageToClient = (CBusMessageToClient) msg;
+ ReplyOrConfirmationConfirmation confirmationReply = (ReplyOrConfirmationConfirmation) messageToClient.getReply();
+ ReplyOrConfirmationReply normalReply = (ReplyOrConfirmationReply) confirmationReply.getEmbeddedReply();
+ EncodedReplyCALReply encodedReplyCALReply = (EncodedReplyCALReply) ((ReplyEncodedReply) normalReply.getReply()).getEncodedReply();
+ System.out.println(encodedReplyCALReply.getCalReply());
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void someOtherResponse() throws Exception {
+ byte[] bytes = "\\0538000100g\r".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ CBusMessageToServer messageToServer = (CBusMessageToServer) msg;
+ RequestCommand requestCommand = (RequestCommand) messageToServer.getRequest();
+ System.out.println(requestCommand.getCbusCommand());
+ assertMessageMatches(bytes, msg);
+ }
+
+
+ @Test
+ void identifyRequest2() throws Exception {
+ byte[] bytes = "21021A2102i\r".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ CBusMessageToServer messageToServer = (CBusMessageToServer) msg;
+ CALData calData = ((RequestObsolete) ((CBusMessageToServer) msg).getRequest()).getCalData();
+ System.out.println(calData);
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void identifyResponse2() throws Exception {
+ byte[] bytes = "i.8902352E342E3030202010\r\n".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ // We know we send an identify command so we set the cal flag
+ requestContext = new RequestContext(true, false, true);
+ cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ CBusMessageToClient messageToClient = (CBusMessageToClient) msg;
+ ReplyOrConfirmationConfirmation confirmationReply = (ReplyOrConfirmationConfirmation) messageToClient.getReply();
+ ReplyOrConfirmationReply normalReply = (ReplyOrConfirmationReply) confirmationReply.getEmbeddedReply();
+ EncodedReplyCALReply encodedReplyCALReply = (EncodedReplyCALReply) ((ReplyEncodedReply) normalReply.getReply()).getEncodedReply();
+ System.out.println(encodedReplyCALReply.getCalReply());
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void recall() throws Exception {
+ byte[] bytes = "@1A2001\r".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ CBusMessageToServer messageToServer = (CBusMessageToServer) msg;
+ RequestDirectCommandAccess requestDirectCommandAccess = (RequestDirectCommandAccess) messageToServer.getRequest();
+ CALData calData = ((RequestDirectCommandAccess) ((CBusMessageToServer) msg).getRequest()).getCalData();
+ System.out.println(calData);
+
+ WriteBufferByteBased writeBuffer = new WriteBufferByteBased(bytes.length);
+ msg.serialize(writeBuffer);
+ assertThat(writeBuffer.getBytes()).isEqualTo(bytes);
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void identifyTypeReply() throws Exception {
+ byte[] bytes = "h.890150435F434E49454421\r\n".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ requestContext = new RequestContext(true, false, true);
+ cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ CBusMessageToClient messageToClient = (CBusMessageToClient) msg;
+ ReplyOrConfirmationConfirmation confirmationReply = (ReplyOrConfirmationConfirmation) messageToClient.getReply();
+ ReplyOrConfirmationReply normalReply = (ReplyOrConfirmationReply) confirmationReply.getEmbeddedReply();
+ EncodedReplyCALReply encodedReplyCALReply = (EncodedReplyCALReply) ((ReplyEncodedReply) normalReply.getReply()).getEncodedReply();
+ System.out.println(encodedReplyCALReply.getCalReply());
+
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void write30to9755() throws Exception {
+ byte[] bytes = "A3309755s\r".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ System.out.println(((RequestObsolete) ((CBusMessageToServer) msg).getRequest()).getCalData());
+
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void strangeNotYetParsableCommandResponse() throws Exception {
+ byte[] bytes = "s.860202003230977D\r\n".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ requestContext = new RequestContext(true, false, false);
+ cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ CBusMessageToClient messageToClient = (CBusMessageToClient) msg;
+ ReplyOrConfirmationConfirmation confirmationReply = (ReplyOrConfirmationConfirmation) messageToClient.getReply();
+ ReplyOrConfirmationReply normalReply = (ReplyOrConfirmationReply) confirmationReply.getEmbeddedReply();
+ EncodedReplyCALReply encodedReplyCALReply = (EncodedReplyCALReply) ((ReplyEncodedReply) normalReply.getReply()).getEncodedReply();
+ System.out.println(encodedReplyCALReply.getCalReply());
+
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void statusRequestBinaryState() throws Exception {
+ byte[] bytes = "\\05FF00FAFF00v\r".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ CBusMessageToServer messageToServer = (CBusMessageToServer) msg;
+ RequestCommand requestCommand = (RequestCommand) messageToServer.getRequest();
+ CBusCommand cbusCommand = requestCommand.getCbusCommand();
+ System.out.println(cbusCommand);
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Disabled
+ @Test
+ void wat() throws Exception {
+ byte[] bytes = "D8FF0024000002000000000000000008000000000000000000\r\n".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
+ requestContext = new RequestContext(true, false, false);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ CBusMessageToClient messageToClient = (CBusMessageToClient) msg;
+ ReplyOrConfirmationReply reply = (ReplyOrConfirmationReply) messageToClient.getReply();
/*
MonitoredSALReply monitoredSALReply = (MonitoredSALReply) reply.getReply();
System.out.println(monitoredSALReply.getMonitoredSAL());
*/
- EncodedReplyCALReply encodedReplyCALReply = (EncodedReplyCALReply) ((ReplyEncodedReply) reply.getReply()).getEncodedReply();
- System.out.println(encodedReplyCALReply.getCalReply());
- assertMessageMatches(bytes, msg);
- }
-
- @Test
- void WriteCommand() throws Exception {
- byte[] bytes = "\\46310900A400410600r\r".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- System.out.println(((RequestCommand) ((CBusMessageToServer) msg).getRequest()).getCbusCommand());
- assertMessageMatches(bytes, msg);
- }
-
- @Test
- void statusReply() throws Exception {
- byte[] bytes = "D8FF5800000000000000000000000000000000000000000000D1\r\n".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
- requestContext = new RequestContext(false, true, false);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- Reply normalReply = ((ReplyOrConfirmationReply) ((CBusMessageToClient) msg).getReply()).getReply();
- EncodedReplyStandardFormatStatusReply encodedReplyStandardFormatStatusReply = (EncodedReplyStandardFormatStatusReply) ((ReplyEncodedReply) normalReply).getEncodedReply();
- System.out.println(encodedReplyStandardFormatStatusReply.getReply());
-
- assertMessageMatches(bytes, msg);
- }
-
- @Test
- void identifyUnitSummary() throws Exception {
- byte[] bytes = "2110\r".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- System.out.println(((RequestObsolete) ((CBusMessageToServer) msg).getRequest()).getCalData());
-
- assertMessageMatches(bytes, msg);
- }
-
- @Test
- void identifyUnitSummaryResponse() throws Exception {
- byte[] bytes = "o.8510020000FF6A\r\n".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
- requestContext = new RequestContext(true, false, true);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- System.out.println(((ReplyEncodedReply) ((ReplyOrConfirmationReply) ((ReplyOrConfirmationConfirmation) ((CBusMessageToClient) msg).getReply()).getEmbeddedReply()).getReply()).getEncodedReply());
-
- assertMessageMatches(bytes, msg);
- }
-
- @Disabled
- @Test
- void strangeMonitoredCal() throws Exception {
- byte[] bytes = "0531AC0079042F0401430316000011\r\n".getBytes(StandardCharsets.UTF_8);
- ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
- requestContext = new RequestContext(false, false, false);
- CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
- assertThat(msg).isNotNull();
- System.out.println(msg);
- System.out.println(((ReplyEncodedReply) ((ReplyOrConfirmationReply) ((CBusMessageToClient) msg).getReply()).getReply()).getEncodedReply());
-
- assertMessageMatches(bytes, msg);
- }
+ EncodedReplyCALReply encodedReplyCALReply = (EncodedReplyCALReply) ((ReplyEncodedReply) reply.getReply()).getEncodedReply();
+ System.out.println(encodedReplyCALReply.getCalReply());
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void WriteCommand() throws Exception {
+ byte[] bytes = "\\46310900A400410600r\r".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ System.out.println(((RequestCommand) ((CBusMessageToServer) msg).getRequest()).getCbusCommand());
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void statusReply() throws Exception {
+ byte[] bytes = "D8FF5800000000000000000000000000000000000000000000D1\r\n".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
+ requestContext = new RequestContext(false, true, false);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ Reply normalReply = ((ReplyOrConfirmationReply) ((CBusMessageToClient) msg).getReply()).getReply();
+ EncodedReplyStandardFormatStatusReply encodedReplyStandardFormatStatusReply = (EncodedReplyStandardFormatStatusReply) ((ReplyEncodedReply) normalReply).getEncodedReply();
+ System.out.println(encodedReplyStandardFormatStatusReply.getReply());
+
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void identifyUnitSummary() throws Exception {
+ byte[] bytes = "2110\r".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ System.out.println(((RequestObsolete) ((CBusMessageToServer) msg).getRequest()).getCalData());
+
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void identifyUnitSummaryResponse() throws Exception {
+ byte[] bytes = "o.8510020000FF6A\r\n".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
+ requestContext = new RequestContext(true, false, true);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ System.out.println(((ReplyEncodedReply) ((ReplyOrConfirmationReply) ((ReplyOrConfirmationConfirmation) ((CBusMessageToClient) msg).getReply()).getEmbeddedReply()).getReply()).getEncodedReply());
+
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void hvacAndCoolingSAL() throws Exception {
+ byte[] bytes = "0531AC0079042F0401430316000011\r\n".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
+ requestContext = new RequestContext(false, false, false);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ System.out.println(((ReplyEncodedReply) ((ReplyOrConfirmationReply) ((CBusMessageToClient) msg).getReply()).getReply()).getEncodedReply());
+
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void calIdentifyReplyAndAnotherCal() throws Exception {
+ byte[] bytes = "h.860102008902312E362E30302020832138FFAE\r\n".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true);
+ requestContext = new RequestContext(false, false, true);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions, bytes.length);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+ System.out.println(((ReplyEncodedReply) ((ReplyOrConfirmationReply) ((ReplyOrConfirmationConfirmation) ((CBusMessageToClient) msg).getReply()).getEmbeddedReply()).getReply()).getEncodedReply());
+
+ assertMessageMatches(bytes, msg);
}
}
diff --git a/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec b/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec
index e042c31f5..5adfca5f3 100644
--- a/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec
+++ b/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec
@@ -614,7 +614,8 @@
]
]
// TODO: we need to check that we don't read the crc by accident
- [optional CALData('requestContext') additionalData]
+ // Note: we omit the request context as it is only useful for the first element
+ [optional CALData('null') additionalData]
]
[enum uint 8 Parameter(vstring group, vstring parameterDescription, vstring form, bit isVolatile, ProtectionLevel protectionLevel)