You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2022/03/01 13:51:56 UTC
[plc4x] branch develop updated: feat(protocol/c-bus): Got the CAL Data tests working
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new dcac0ea feat(protocol/c-bus): Got the CAL Data tests working
dcac0ea is described below
commit dcac0ea8d6648ce08a380e0d95ba703ca2778a12
Author: cdutz <ch...@c-ware.de>
AuthorDate: Tue Mar 1 14:51:13 2022 +0100
feat(protocol/c-bus): Got the CAL Data tests working
---
.../templates/java/model-template.java.ftlh | 2 +-
.../apache/plc4x/java/cbus/RandomPackagesTest.java | 39 +++++++++++++++------
.../src/main/resources/protocols/cbus/c-bus.mspec | 40 +++++++++++++---------
3 files changed, 53 insertions(+), 28 deletions(-)
diff --git a/code-generation/language-java/src/main/resources/templates/java/model-template.java.ftlh b/code-generation/language-java/src/main/resources/templates/java/model-template.java.ftlh
index edebdc3..5441388 100644
--- a/code-generation/language-java/src/main/resources/templates/java/model-template.java.ftlh
+++ b/code-generation/language-java/src/main/resources/templates/java/model-template.java.ftlh
@@ -717,7 +717,7 @@ public<#if type.isDiscriminatedParentTypeDefinition()> abstract</#if> class ${ty
<#if discriminatorType.isEnumTypeReference()>
${helper.getLanguageTypeNameForTypeReference(discriminatorType)}.${helper.toParseExpression(switchField, discriminatorType, discriminatorValueTerm, parserArguments)}
<#else>
- ${helper.toParseExpression(switchField, discriminatorType, discriminatorValueTerm, parserArguments)}
+ (${helper.getLanguageTypeNameForTypeReference(discriminatorType, true)}) ${helper.toParseExpression(switchField, discriminatorType, discriminatorValueTerm, parserArguments)}
</#if>
)
</#if>
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 eb46395..8d52543 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
@@ -19,7 +19,7 @@
package org.apache.plc4x.java.cbus;
import org.apache.commons.codec.binary.Hex;
-import org.apache.plc4x.java.cbus.readwrite.CBusCommand;
+import org.apache.plc4x.java.cbus.readwrite.*;
import org.apache.plc4x.java.spi.generation.ReadBufferByteBased;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
@@ -27,17 +27,18 @@ import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
-//@Disabled("non of those work yet")
public class RandomPackagesTest {
static final String BACKSLASH = "5C";
static final String CR = "0D";
+ static final String LF = "0A";
// from: https://updates.clipsal.com/ClipsalSoftwareDownload/DL/downloads/OpenCBus/Serial%20Interface%20User%20Guide.pdf
@Nested
class ReferenceDocumentationTest {
// 4.2.9.1
@Test
+ @Disabled("Not yet implemented")
void pointToPointCommand1() throws Exception {
byte[] bytes = Hex.decodeHex(BACKSLASH + "0603002102D4");
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
@@ -48,6 +49,7 @@ public class RandomPackagesTest {
// 4.2.9.1
@Test
+ @Disabled("Not yet implemented")
void pointToPointCommand2() throws Exception {
byte[] bytes = Hex.decodeHex(BACKSLASH + "06420903210289");
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
@@ -58,6 +60,7 @@ public class RandomPackagesTest {
// 4.2.9.2
@Test
+ @Disabled("Not yet implemented")
void pointToMultiPointCommand1() throws Exception {
byte[] bytes = Hex.decodeHex(BACKSLASH + "0538000108BA");
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
@@ -68,6 +71,7 @@ public class RandomPackagesTest {
// 4.2.9.2
@Test
+ @Disabled("Not yet implemented")
void pointToMultiPointCommand2() throws Exception {
byte[] bytes = Hex.decodeHex(BACKSLASH + "05FF007A38004A");
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
@@ -78,6 +82,7 @@ public class RandomPackagesTest {
// 4.2.9.3
@Test
+ @Disabled("Not yet implemented")
void pointToPointToMultiPointCommand2() throws Exception {
byte[] bytes = Hex.decodeHex(BACKSLASH + "03420938010871");
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
@@ -88,7 +93,8 @@ public class RandomPackagesTest {
// 4.3.3.1
@Test
- void calReply1() throws Exception {
+ @Disabled("Not yet implemented")
+ void calRequest() throws Exception {
byte[] bytes = Hex.decodeHex(BACKSLASH + "0605002102" + CR);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
CBusCommand cBusCommand = CBusCommand.staticParse(readBufferByteBased, false);
@@ -99,22 +105,35 @@ public class RandomPackagesTest {
// 4.3.3.1
@Test
- void calReply2() throws Exception {
- byte[] bytes = Hex.decodeHex(BACKSLASH + "860593008902312E322E363620207F" + CR);
+ void calReplyNormal() throws Exception {
+ byte[] bytes = Hex.decodeHex("8902312E322E363620200A" + CR + LF);
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- CBusCommand cBusCommand = CBusCommand.staticParse(readBufferByteBased, false);
- assertThat(cBusCommand)
+ CALReply msg = CALReplyShort.staticParse(readBufferByteBased, false);
+ assertThat(msg)
.isNotNull();
+ System.out.println(msg);
+ }
+
+ @Test
+ void calReplySmart() throws Exception {
+ byte[] bytes = Hex.decodeHex("860593008902312E322E363620207F" + CR + LF);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ CALReply msg = CALReplyLong.staticParse(readBufferByteBased, false);
+ assertThat(msg)
+ .isNotNull();
+ System.out.println(msg);
}
// 4.3.3.2
@Test
+ @Disabled("Not yet implemented")
void monitoredSal() throws Exception {
- byte[] bytes = Hex.decodeHex(BACKSLASH + "0503380079083F");
+ byte[] bytes = Hex.decodeHex("0503380079083F");
ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
- CBusCommand cBusCommand = CBusCommand.staticParse(readBufferByteBased, false);
- assertThat(cBusCommand)
+ Reply msg = MonitoredSALReply.staticParse(readBufferByteBased, false);
+ assertThat(msg)
.isNotNull();
+ System.out.println(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 51bd3c5..96ad949 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
@@ -183,18 +183,24 @@
[simple uint 8 paramNo]
[simple uint 8 count]
]
- ['REPLY' CALDataReplyReply
- // TODO: how to parse this?
+ ['REPLY' CALDataReplyReply(CALCommandTypeContainer commandTypeContainer)
+ [simple uint 8 paramNumber ]
+ [array byte data count 'commandTypeContainer.numBytes']
]
['ACKNOWLEDGE' CALDataReplyAcknowledge
[simple uint 8 paramNo]
[simple uint 8 code]
]
- ['STATUS' CALDataReplyStatus
- // TODO: how to parse this?
+ ['STATUS' CALDataReplyStatus(CALCommandTypeContainer commandTypeContainer)
+ [simple Application application]
+ [simple uint 8 blockStart ]
+ [array byte data count 'commandTypeContainer.numBytes']
]
- ['STATUS_EXTENDED' CALDataReplyStatusExtended
- // TODO: how to parse this?
+ ['STATUS_EXTENDED' CALDataReplyStatusExtended(CALCommandTypeContainer commandTypeContainer)
+ [simple uint 8 encoding ]
+ [simple Application application]
+ [simple uint 8 blockStart ]
+ [array byte data count 'commandTypeContainer.numBytes']
]
]
]
@@ -412,27 +418,27 @@
]
[type CALReply
- [peek byte calType ]
+ [peek byte calType ]
[typeSwitch calType
['0x86' CALReplyLong
- [reserved byte '0x86' ]
- [peek uint 24 terminatingByte ]
+ [reserved byte '0x86' ]
+ [peek uint 24 terminatingByte ]
// TODO: this should be subSub type but mspec doesn't support that yet directly
[virtual bit isUnitAddress '(terminatingByte & 0xff) == 0x00']
- [optional UnitAddress unitAddress 'isUnitAddress' ]
- [optional BridgeAddress bridgeAddress '!isUnitAddress' ]
- [simple SerialInterfaceAddress serialInterfaceAddress ]
- [optional byte reservedByte 'isUnitAddress' ]
+ [optional UnitAddress unitAddress 'isUnitAddress' ]
+ [optional BridgeAddress bridgeAddress '!isUnitAddress' ]
+ [simple SerialInterfaceAddress serialInterfaceAddress ]
+ [optional byte reservedByte 'isUnitAddress' ]
[validation 'isUnitAddress && reservedByte == 0x00 || !isUnitAddress' "wrong reservedByte"]
- [optional ReplyNetwork replyNetwork '!isUnitAddress' ]
+ [optional ReplyNetwork replyNetwork '!isUnitAddress' ]
]
[ CALReplyShort
]
]
- [simple CALData calData ]
+ [simple CALData calData ]
//[checksum byte crc '0x00' ] // TODO: Fix this
- [const byte cr 0x0D ] // 0xD == "<cr>"
- [const byte lf 0x0A ] // 0xA == "<lf>"
+ [const byte cr 0x0D ] // 0xD == "<cr>"
+ [const byte lf 0x0A ] // 0xA == "<lf>"
]
[type BridgeCount