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/29 11:40:37 UTC

[plc4x] 02/04: fix(cbus): fixed detection of monitored sal

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 a82e7006ab3ecb3cce7e7edf02bbd9595d576067
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Jul 29 11:18:32 2022 +0200

    fix(cbus): fixed detection of monitored sal
---
 plc4go/protocols/cbus/readwrite/model/EncodedReply.go        |  4 ++--
 .../java/org/apache/plc4x/java/cbus/RandomPackagesTest.java  | 12 ++++++++++++
 .../c-bus/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 df9411535..b7e124731 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 72f002d17..a16d0d962 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 @@ public class RandomPackagesTest {
         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 74b4ba741..fb54f2f3c 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)']