From a82e7006ab3ecb3cce7e7edf02bbd9595d576067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20R=C3=BChl?= Date: Fri, 29 Jul 2022 11:18:32 +0200 Subject: [PATCH] fix(cbus): fixed detection of monitored sal --- .../protocols/cbus/readwrite/model/EncodedReply.go | 4 ++-- .../apache/plc4x/java/cbus/RandomPackagesTest.java | 12 ++++++++++++ .../src/main/resources/protocols/cbus/c-bus.mspec | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/plc4go/protocols/cbus/readwrite/model/EncodedReply.go b/plc4go/protocols/cbus/readwrite/model/EncodedReply.go index df941153539..b7e124731f3 100644 --- a/plc4go/protocols/cbus/readwrite/model/EncodedReply.go +++ b/plc4go/protocols/cbus/readwrite/model/EncodedReply.go @@ -98,7 +98,7 @@ func (m *_EncodedReply) GetPeekedByte() byte { /////////////////////// func (m *_EncodedReply) GetIsMonitoredSAL() bool { - return bool(bool((m.GetPeekedByte() & 0x3F) == (0x05))) + return bool(bool(bool(bool((m.GetPeekedByte()&0x3F) == (0x05))) || bool(bool((m.GetPeekedByte()) == (0x00)))) || bool(bool((m.GetPeekedByte()&0xF8) == (0x00)))) } func (m *_EncodedReply) GetIsCalCommand() bool { @@ -175,7 +175,7 @@ func EncodedReplyParse(readBuffer utils.ReadBuffer, cBusOptions CBusOptions, req readBuffer.Reset(currentPos) // Virtual field - _isMonitoredSAL := bool((peekedByte & 0x3F) == (0x05)) + _isMonitoredSAL := bool(bool(bool((peekedByte&0x3F) == (0x05))) || bool(bool((peekedByte) == (0x00)))) || bool(bool((peekedByte&0xF8) == (0x00))) isMonitoredSAL := bool(_isMonitoredSAL) _ = isMonitoredSAL 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 72f002d1712..a16d0d962d7 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 @@ -405,4 +405,16 @@ void closestFitIsAStatusRequestButWeDonTHaveAnyBytesBeforeThat() throws Exceptio assertMessageMatches(bytes, msg); } + @Test + void ownSal() throws Exception { + byte[] bytes = "003809AF10\r\n".getBytes(StandardCharsets.UTF_8); + ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes); + cBusOptions = C_BUS_OPTIONS_WITH_SRCHK; + CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions); + assertThat(msg).isNotNull(); + System.out.println(msg); + System.out.println(((ReplyEncodedReply) ((ReplyOrConfirmationReply) ((CBusMessageToClient) msg).getReply()).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 74b4ba7410d..fb54f2f3c22 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 @@ -1393,7 +1393,7 @@ [type EncodedReply(CBusOptions cBusOptions, RequestContext requestContext) [peek byte peekedByte ] // TODO: if we reliable can detect this with the mask we don't need the request context anymore - [virtual bit isMonitoredSAL '(peekedByte & 0x3F) == 0x05' ] + [virtual bit isMonitoredSAL '(peekedByte & 0x3F) == 0x05 || peekedByte == 0x00 || (peekedByte & 0xF8) == 0x00'] // First check if it is in long mode, second for short mode, third for bridged short mode [virtual bit isCalCommand '(peekedByte & 0x3F) == 0x06 || requestContext.sendCalCommandBefore' ] // The 0x3F and 0x06 doesn't seem to work always [virtual bit isStandardFormatStatus '(peekedByte & 0xC0) == 0xC0 && !cBusOptions.exstat' ] [virtual bit isExtendedFormatStatus '(peekedByte & 0xE0) == 0xE0 && (cBusOptions.exstat || requestContext.sendStatusRequestLevelBefore)']