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/09/01 10:50:51 UTC
[plc4x] branch develop updated (4621b6296 -> 8334e20f4)
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
from 4621b6296 build(deps): bump milo.version from 0.6.6 to 0.6.7 (#481)
new 5e61dc80d feat(cbus): introduced INFO_MESSAGES and NETWORK_CONTROL application ids
new 720c603a8 feat(plc-simulator/cbus): added support for installation mmi requests
new 8334e20f4 fix(plc4go/cbus): fix filtering
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
plc4go/internal/cbus/Field.go | 16 ++--
plc4go/internal/cbus/FieldHandler.go | 16 ++--
plc4go/internal/cbus/Subscriber.go | 13 ++--
.../cbus/readwrite/model/ApplicationId.go | 16 ++++
.../cbus/readwrite/model/ApplicationIdContainer.go | 32 ++++----
.../apache/plc4x/java/cbus/RandomPackagesTest.java | 70 ++++++++++++-----
.../server/cbus/protocol/CBusServerAdapter.java | 88 ++++++++++++++++++++++
.../src/main/resources/protocols/cbus/c-bus.mspec | 6 +-
8 files changed, 198 insertions(+), 59 deletions(-)
[plc4x] 01/03: feat(cbus): introduced INFO_MESSAGES and NETWORK_CONTROL application ids
Posted by sr...@apache.org.
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 5e61dc80dc997b69b0ab31b897cb67117a727224
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Sep 1 12:49:22 2022 +0200
feat(cbus): introduced INFO_MESSAGES and NETWORK_CONTROL application ids
---
.../cbus/readwrite/model/ApplicationId.go | 16 +++++++++++
.../cbus/readwrite/model/ApplicationIdContainer.go | 32 +++++++++++-----------
.../src/main/resources/protocols/cbus/c-bus.mspec | 6 ++--
3 files changed, 36 insertions(+), 18 deletions(-)
diff --git a/plc4go/protocols/cbus/readwrite/model/ApplicationId.go b/plc4go/protocols/cbus/readwrite/model/ApplicationId.go
index 6d1f69fce..ed313e7be 100644
--- a/plc4go/protocols/cbus/readwrite/model/ApplicationId.go
+++ b/plc4go/protocols/cbus/readwrite/model/ApplicationId.go
@@ -57,6 +57,8 @@ const (
ApplicationId_MEDIA_TRANSPORT_CONTROL ApplicationId = 0x14
ApplicationId_ERROR_REPORTING ApplicationId = 0x15
ApplicationId_HVAC_ACTUATOR ApplicationId = 0x16
+ ApplicationId_INFO_MESSAGES ApplicationId = 0x17
+ ApplicationId_NETWORK_CONTROL ApplicationId = 0x18
)
var ApplicationIdValues []ApplicationId
@@ -87,6 +89,8 @@ func init() {
ApplicationId_MEDIA_TRANSPORT_CONTROL,
ApplicationId_ERROR_REPORTING,
ApplicationId_HVAC_ACTUATOR,
+ ApplicationId_INFO_MESSAGES,
+ ApplicationId_NETWORK_CONTROL,
}
}
@@ -138,6 +142,10 @@ func ApplicationIdByValue(value uint8) (enum ApplicationId, ok bool) {
return ApplicationId_ERROR_REPORTING, true
case 0x16:
return ApplicationId_HVAC_ACTUATOR, true
+ case 0x17:
+ return ApplicationId_INFO_MESSAGES, true
+ case 0x18:
+ return ApplicationId_NETWORK_CONTROL, true
}
return 0, false
}
@@ -190,6 +198,10 @@ func ApplicationIdByName(value string) (enum ApplicationId, ok bool) {
return ApplicationId_ERROR_REPORTING, true
case "HVAC_ACTUATOR":
return ApplicationId_HVAC_ACTUATOR, true
+ case "INFO_MESSAGES":
+ return ApplicationId_INFO_MESSAGES, true
+ case "NETWORK_CONTROL":
+ return ApplicationId_NETWORK_CONTROL, true
}
return 0, false
}
@@ -287,6 +299,10 @@ func (e ApplicationId) PLC4XEnumName() string {
return "ERROR_REPORTING"
case ApplicationId_HVAC_ACTUATOR:
return "HVAC_ACTUATOR"
+ case ApplicationId_INFO_MESSAGES:
+ return "INFO_MESSAGES"
+ case ApplicationId_NETWORK_CONTROL:
+ return "NETWORK_CONTROL"
}
return ""
}
diff --git a/plc4go/protocols/cbus/readwrite/model/ApplicationIdContainer.go b/plc4go/protocols/cbus/readwrite/model/ApplicationIdContainer.go
index 871909503..6eace5439 100644
--- a/plc4go/protocols/cbus/readwrite/model/ApplicationIdContainer.go
+++ b/plc4go/protocols/cbus/readwrite/model/ApplicationIdContainer.go
@@ -209,7 +209,7 @@ const (
ApplicationIdContainer_RESERVED_AA ApplicationIdContainer = 0xAA
ApplicationIdContainer_RESERVED_AB ApplicationIdContainer = 0xAB
ApplicationIdContainer_AIR_CONDITIONING_AC ApplicationIdContainer = 0xAC
- ApplicationIdContainer_RESERVED_AD ApplicationIdContainer = 0xAD
+ ApplicationIdContainer_INFO_MESSAGES ApplicationIdContainer = 0xAD
ApplicationIdContainer_RESERVED_AE ApplicationIdContainer = 0xAE
ApplicationIdContainer_RESERVED_AF ApplicationIdContainer = 0xAF
ApplicationIdContainer_RESERVED_B0 ApplicationIdContainer = 0xB0
@@ -291,7 +291,7 @@ const (
ApplicationIdContainer_RESERVED_FC ApplicationIdContainer = 0xFC
ApplicationIdContainer_RESERVED_FD ApplicationIdContainer = 0xFD
ApplicationIdContainer_RESERVED_FE ApplicationIdContainer = 0xFE
- ApplicationIdContainer_RESERVED_FF ApplicationIdContainer = 0xFF
+ ApplicationIdContainer_NETWORK_CONTROL ApplicationIdContainer = 0xFF
)
var ApplicationIdContainerValues []ApplicationIdContainer
@@ -472,7 +472,7 @@ func init() {
ApplicationIdContainer_RESERVED_AA,
ApplicationIdContainer_RESERVED_AB,
ApplicationIdContainer_AIR_CONDITIONING_AC,
- ApplicationIdContainer_RESERVED_AD,
+ ApplicationIdContainer_INFO_MESSAGES,
ApplicationIdContainer_RESERVED_AE,
ApplicationIdContainer_RESERVED_AF,
ApplicationIdContainer_RESERVED_B0,
@@ -554,7 +554,7 @@ func init() {
ApplicationIdContainer_RESERVED_FC,
ApplicationIdContainer_RESERVED_FD,
ApplicationIdContainer_RESERVED_FE,
- ApplicationIdContainer_RESERVED_FF,
+ ApplicationIdContainer_NETWORK_CONTROL,
}
}
@@ -2296,7 +2296,7 @@ func (e ApplicationIdContainer) ApplicationId() ApplicationId {
}
case 0xAD:
{ /* '0xAD' */
- return ApplicationId_RESERVED
+ return ApplicationId_INFO_MESSAGES
}
case 0xAE:
{ /* '0xAE' */
@@ -2624,7 +2624,7 @@ func (e ApplicationIdContainer) ApplicationId() ApplicationId {
}
case 0xFF:
{ /* '0xFF' */
- return ApplicationId_RESERVED
+ return ApplicationId_NETWORK_CONTROL
}
default:
{
@@ -2990,7 +2990,7 @@ func ApplicationIdContainerByValue(value uint8) (enum ApplicationIdContainer, ok
case 0xAC:
return ApplicationIdContainer_AIR_CONDITIONING_AC, true
case 0xAD:
- return ApplicationIdContainer_RESERVED_AD, true
+ return ApplicationIdContainer_INFO_MESSAGES, true
case 0xAE:
return ApplicationIdContainer_RESERVED_AE, true
case 0xAF:
@@ -3154,7 +3154,7 @@ func ApplicationIdContainerByValue(value uint8) (enum ApplicationIdContainer, ok
case 0xFE:
return ApplicationIdContainer_RESERVED_FE, true
case 0xFF:
- return ApplicationIdContainer_RESERVED_FF, true
+ return ApplicationIdContainer_NETWORK_CONTROL, true
}
return 0, false
}
@@ -3507,8 +3507,8 @@ func ApplicationIdContainerByName(value string) (enum ApplicationIdContainer, ok
return ApplicationIdContainer_RESERVED_AB, true
case "AIR_CONDITIONING_AC":
return ApplicationIdContainer_AIR_CONDITIONING_AC, true
- case "RESERVED_AD":
- return ApplicationIdContainer_RESERVED_AD, true
+ case "INFO_MESSAGES":
+ return ApplicationIdContainer_INFO_MESSAGES, true
case "RESERVED_AE":
return ApplicationIdContainer_RESERVED_AE, true
case "RESERVED_AF":
@@ -3671,8 +3671,8 @@ func ApplicationIdContainerByName(value string) (enum ApplicationIdContainer, ok
return ApplicationIdContainer_RESERVED_FD, true
case "RESERVED_FE":
return ApplicationIdContainer_RESERVED_FE, true
- case "RESERVED_FF":
- return ApplicationIdContainer_RESERVED_FF, true
+ case "NETWORK_CONTROL":
+ return ApplicationIdContainer_NETWORK_CONTROL, true
}
return 0, false
}
@@ -4070,8 +4070,8 @@ func (e ApplicationIdContainer) PLC4XEnumName() string {
return "RESERVED_AB"
case ApplicationIdContainer_AIR_CONDITIONING_AC:
return "AIR_CONDITIONING_AC"
- case ApplicationIdContainer_RESERVED_AD:
- return "RESERVED_AD"
+ case ApplicationIdContainer_INFO_MESSAGES:
+ return "INFO_MESSAGES"
case ApplicationIdContainer_RESERVED_AE:
return "RESERVED_AE"
case ApplicationIdContainer_RESERVED_AF:
@@ -4234,8 +4234,8 @@ func (e ApplicationIdContainer) PLC4XEnumName() string {
return "RESERVED_FD"
case ApplicationIdContainer_RESERVED_FE:
return "RESERVED_FE"
- case ApplicationIdContainer_RESERVED_FF:
- return "RESERVED_FF"
+ case ApplicationIdContainer_NETWORK_CONTROL:
+ return "NETWORK_CONTROL"
}
return ""
}
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 02f6dc9f9..703b200bf 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
@@ -280,6 +280,8 @@
['0x14' MEDIA_TRANSPORT_CONTROL ]
['0x15' ERROR_REPORTING ]
['0x16' HVAC_ACTUATOR ]
+ ['0x17' INFO_MESSAGES ]
+ ['0x18' NETWORK_CONTROL ]
]
[enum uint 4 LightingCompatible
@@ -463,7 +465,7 @@
['0xAA' RESERVED_AA ['RESERVED' , 'NA' ]]
['0xAB' RESERVED_AB ['RESERVED' , 'NA' ]]
['0xAC' AIR_CONDITIONING_AC ['AIR_CONDITIONING' , 'NO' ]]
- ['0xAD' RESERVED_AD ['RESERVED' , 'NA' ]] // INFO_MESSAGES
+ ['0xAD' INFO_MESSAGES ['INFO_MESSAGES' , 'NA' ]]
['0xAE' RESERVED_AE ['RESERVED' , 'NA' ]]
['0xAF' RESERVED_AF ['RESERVED' , 'NA' ]]
['0xB0' RESERVED_B0 ['RESERVED' , 'NA' ]]
@@ -545,7 +547,7 @@
['0xFC' RESERVED_FC ['RESERVED' , 'NO' ]]
['0xFD' RESERVED_FD ['RESERVED' , 'NO' ]]
['0xFE' RESERVED_FE ['RESERVED' , 'NO' ]]
- ['0xFF' RESERVED_FF ['RESERVED' , 'NO' ]] // NETWORK_CONTROL
+ ['0xFF' NETWORK_CONTROL ['NETWORK_CONTROL' , 'NO' ]]
]
[type CALData(RequestContext requestContext)
[plc4x] 02/03: feat(plc-simulator/cbus): added support for installation mmi requests
Posted by sr...@apache.org.
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 720c603a8ac5b97bfec8bf200d1f52a5185f81a9
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Sep 1 12:49:50 2022 +0200
feat(plc-simulator/cbus): added support for installation mmi requests
---
.../apache/plc4x/java/cbus/RandomPackagesTest.java | 70 ++++++++++++-----
.../server/cbus/protocol/CBusServerAdapter.java | 88 ++++++++++++++++++++++
2 files changed, 138 insertions(+), 20 deletions(-)
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 03e2328fb..55533ab1a 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
@@ -22,6 +22,7 @@ import org.apache.plc4x.java.cbus.readwrite.*;
import org.apache.plc4x.java.spi.generation.ReadBufferByteBased;
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;
@@ -401,27 +402,56 @@ public class RandomPackagesTest {
assertMessageMatches(bytes, msg);
}
- @Test
- void initiateMMI() throws Exception {
- byte[] bytes = ( "\\05FF007AFF0083g\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);
+ @Nested
+ class InstallationMMI {
+ @Test
+ void initiateMMI() throws Exception {
+ byte[] bytes = ("\\05FF007AFF0083g\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);
+ }
+
+ @Test
+ void initiateMMIReponse1() throws Exception {
+ byte[] bytes = ("g.86020200F900FF0094120006000000000000000008000000000000000000CA\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);
+
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void initiateMMIReponse2() throws Exception {
+ byte[] bytes = ("86020200F900FF580000000000000000000000000000000000000000000026\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);
+
+ assertMessageMatches(bytes, msg);
+ }
+
+ @Test
+ void initiateMMIReponse3() throws Exception {
+ byte[] bytes = ("86020200F700FFB00000000000000000000000000000000000000000D0\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);
+
+ assertMessageMatches(bytes, msg);
+ }
}
- @Test
- void initiateMMIReponse() throws Exception {
- byte[] bytes = ( "g.86020200F900FF0094120006000000000000000008000000000000000000CA\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);
- assertMessageMatches(bytes, msg);
- }
}
diff --git a/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/protocol/CBusServerAdapter.java b/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/protocol/CBusServerAdapter.java
index bf790c6d6..7960ca965 100644
--- a/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/protocol/CBusServerAdapter.java
+++ b/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/protocol/CBusServerAdapter.java
@@ -286,6 +286,11 @@ public class CBusServerAdapter extends ChannelInboundHandlerAdapter {
if (statusRequest instanceof StatusRequestBinaryState) {
StatusRequestBinaryState statusRequestBinaryState = (StatusRequestBinaryState) statusRequest;
LOGGER.info("Handling StatusRequestBinaryState\n{}", statusRequestBinaryState);
+ if (statusRequestBinaryState.getApplication() == ApplicationIdContainer.NETWORK_CONTROL) {
+ LOGGER.info("Handling installation MMI Request");
+ sendInstallationMMIResponse(ctx, requestCommand, statusRequestBinaryState.getApplication());
+ return;
+ }
CALReply calReply;
if (exstat) {
// TODO: map actuall values from simulator
@@ -316,6 +321,11 @@ public class CBusServerAdapter extends ChannelInboundHandlerAdapter {
if (statusRequest instanceof StatusRequestBinaryStateDeprecated) {
StatusRequestBinaryStateDeprecated statusRequestBinaryStateDeprecated = (StatusRequestBinaryStateDeprecated) statusRequest;
LOGGER.info("Handling StatusRequestBinaryStateDeprecated\n{}", statusRequestBinaryStateDeprecated);
+ if (statusRequestBinaryStateDeprecated.getApplication() == ApplicationIdContainer.NETWORK_CONTROL) {
+ LOGGER.info("Handling installation MMI Request");
+ sendInstallationMMIResponse(ctx, requestCommand, statusRequestBinaryStateDeprecated.getApplication());
+ return;
+ }
CALReply calReply;
if (exstat) {
// TODO: map actuall values from simulator
@@ -397,6 +407,84 @@ public class CBusServerAdapter extends ChannelInboundHandlerAdapter {
}
}
+ private static void sendInstallationMMIResponse(ChannelHandlerContext ctx, RequestCommand requestCommand, ApplicationIdContainer application) {
+ LOGGER.info("Send installation mmis");
+ {
+ byte blockStart = 0x0;
+ List<StatusByte> unitStatusBytes = new LinkedList<>();
+ for (int i = blockStart; i <= 88 - 4; i = i + 4) {
+ LOGGER.debug("Handling units 0-88 {},{},{},{}", i, (i + 1), (i + 2), (i + 3));
+ unitStatusBytes.add(
+ new StatusByte(
+ AVAILABLE_UNITS.contains((byte) (i + 0)) ? GAVState.ON : GAVState.DOES_NOT_EXIST,
+ AVAILABLE_UNITS.contains((byte) (i + 1)) ? GAVState.ON : GAVState.DOES_NOT_EXIST,
+ AVAILABLE_UNITS.contains((byte) (i + 2)) ? GAVState.ON : GAVState.DOES_NOT_EXIST,
+ AVAILABLE_UNITS.contains((byte) (i + 3)) ? GAVState.ON : GAVState.DOES_NOT_EXIST
+ )
+ );
+ }
+ LOGGER.debug("Produced {}, status bytes which equates to {} status", unitStatusBytes.size(), unitStatusBytes.size() * 4);
+ CALData calData = new CALDataStatusExtended(CALCommandTypeContainer.CALCommandReply_22Bytes, null, StatusCoding.BINARY_BY_THIS_SERIAL_INTERFACE, application, blockStart, unitStatusBytes, null, requestContext);
+ CALReply calReply = new CALReplyShort((byte) 0x0, calData, cBusOptions, requestContext);
+ EncodedReply encodedReply = new EncodedReplyCALReply((byte) 0x0, calReply, cBusOptions, requestContext);
+ ReplyEncodedReply replyEncodedReply = new ReplyEncodedReply((byte) 0xC0, encodedReply, null, cBusOptions, requestContext);
+ ReplyOrConfirmation replyOrConfirmation = new ReplyOrConfirmationReply((byte) 0xFF, replyEncodedReply, new ResponseTermination(), cBusOptions, requestContext);
+ Alpha alpha = requestCommand.getAlpha();
+ if (alpha != null) {
+ Confirmation confirmation = new Confirmation(alpha, null, ConfirmationType.CONFIRMATION_SUCCESSFUL);
+ replyOrConfirmation = new ReplyOrConfirmationConfirmation(alpha.getCharacter(), confirmation, replyOrConfirmation, cBusOptions, requestContext);
+ }
+ CBusMessage response = new CBusMessageToClient(replyOrConfirmation, requestContext, cBusOptions);
+ ctx.writeAndFlush(response);
+ }
+ {
+ byte blockStart = 88;
+ List<StatusByte> unitStatusBytes = new LinkedList<>();
+ for (int i = 88; i <= 88 + 88 - 4; i = i + 4) {
+ LOGGER.debug("Handling units 88-176 {},{},{},{}", i, (i + 1), (i + 2), (i + 3));
+ unitStatusBytes.add(
+ new StatusByte(
+ AVAILABLE_UNITS.contains((byte) (i + 0)) ? GAVState.ON : GAVState.DOES_NOT_EXIST,
+ AVAILABLE_UNITS.contains((byte) (i + 1)) ? GAVState.ON : GAVState.DOES_NOT_EXIST,
+ AVAILABLE_UNITS.contains((byte) (i + 2)) ? GAVState.ON : GAVState.DOES_NOT_EXIST,
+ AVAILABLE_UNITS.contains((byte) (i + 3)) ? GAVState.ON : GAVState.DOES_NOT_EXIST
+ )
+ );
+ }
+ LOGGER.debug("Produced {}, status bytes which equates to {} status", unitStatusBytes.size(), unitStatusBytes.size() * 4);
+ CALData calData = new CALDataStatusExtended(CALCommandTypeContainer.CALCommandReply_22Bytes, null, StatusCoding.BINARY_BY_THIS_SERIAL_INTERFACE, application, blockStart, unitStatusBytes, null, requestContext);
+ CALReply calReply = new CALReplyShort((byte) 0x0, calData, cBusOptions, requestContext);
+ EncodedReply encodedReply = new EncodedReplyCALReply((byte) 0x0, calReply, cBusOptions, requestContext);
+ ReplyEncodedReply replyEncodedReply = new ReplyEncodedReply((byte) 0xC0, encodedReply, null, cBusOptions, requestContext);
+ ReplyOrConfirmation replyOrConfirmation = new ReplyOrConfirmationReply((byte) 0xFF, replyEncodedReply, new ResponseTermination(), cBusOptions, requestContext);
+ CBusMessage response = new CBusMessageToClient(replyOrConfirmation, requestContext, cBusOptions);
+ ctx.writeAndFlush(response);
+ }
+ {
+ byte blockStart = (byte) 176;
+ List<StatusByte> unitStatusBytes = new LinkedList<>();
+ for (int i = 176; i <= 176 + 80 - 4; i = i + 4) {
+ LOGGER.debug("Handling units 176-256 {},{},{},{}", i, (i + 1), (i + 2), (i + 3));
+ unitStatusBytes.add(
+ new StatusByte(
+ AVAILABLE_UNITS.contains((byte) (i + 0)) ? GAVState.ON : GAVState.DOES_NOT_EXIST,
+ AVAILABLE_UNITS.contains((byte) (i + 1)) ? GAVState.ON : GAVState.DOES_NOT_EXIST,
+ AVAILABLE_UNITS.contains((byte) (i + 2)) ? GAVState.ON : GAVState.DOES_NOT_EXIST,
+ AVAILABLE_UNITS.contains((byte) (i + 3)) ? GAVState.ON : GAVState.DOES_NOT_EXIST
+ )
+ );
+ }
+ LOGGER.debug("Produced {}, status bytes which equates to {} status", unitStatusBytes.size(), unitStatusBytes.size() * 4);
+ CALData calData = new CALDataStatusExtended(CALCommandTypeContainer.CALCommandReply_21Bytes, null, StatusCoding.BINARY_BY_THIS_SERIAL_INTERFACE, application, blockStart, unitStatusBytes, null, requestContext);
+ CALReply calReply = new CALReplyShort((byte) 0x0, calData, cBusOptions, requestContext);
+ EncodedReply encodedReply = new EncodedReplyCALReply((byte) 0x0, calReply, cBusOptions, requestContext);
+ ReplyEncodedReply replyEncodedReply = new ReplyEncodedReply((byte) 0xC0, encodedReply, null, cBusOptions, requestContext);
+ ReplyOrConfirmation replyOrConfirmation = new ReplyOrConfirmationReply((byte) 0xFF, replyEncodedReply, new ResponseTermination(), cBusOptions, requestContext);
+ CBusMessage response = new CBusMessageToClient(replyOrConfirmation, requestContext, cBusOptions);
+ ctx.writeAndFlush(response);
+ }
+ }
+
private void handleCalDataIdentify(ChannelHandlerContext ctx, CALDataIdentify calDataIdentify, Alpha alpha) {
short numBytes;
IdentifyReplyCommand identifyReplyCommand;
[plc4x] 03/03: fix(plc4go/cbus): fix filtering
Posted by sr...@apache.org.
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 8334e20f47c1508abf5d177898aa881bf6a0f416
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Sep 1 12:50:38 2022 +0200
fix(plc4go/cbus): fix filtering
---
plc4go/internal/cbus/Field.go | 16 ++++++++--------
plc4go/internal/cbus/FieldHandler.go | 16 ++++++++--------
plc4go/internal/cbus/Subscriber.go | 13 ++++++++-----
3 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/plc4go/internal/cbus/Field.go b/plc4go/internal/cbus/Field.go
index aec98236f..84f32cb55 100644
--- a/plc4go/internal/cbus/Field.go
+++ b/plc4go/internal/cbus/Field.go
@@ -137,10 +137,10 @@ func NewSALField(application readWriteModel.ApplicationIdContainer, salCommand s
type SALMonitorField interface {
model.PlcField
GetUnitAddress() readWriteModel.UnitAddress
- GetApplication() readWriteModel.ApplicationIdContainer
+ GetApplication() *readWriteModel.ApplicationIdContainer
}
-func NewSALMonitorField(unitAddress readWriteModel.UnitAddress, application readWriteModel.ApplicationIdContainer, numElements uint16) SALMonitorField {
+func NewSALMonitorField(unitAddress readWriteModel.UnitAddress, application *readWriteModel.ApplicationIdContainer, numElements uint16) SALMonitorField {
return &salMonitorField{
fieldType: SAL_MONITOR,
unitAddress: unitAddress,
@@ -154,10 +154,10 @@ type MMIMonitorField interface {
model.PlcField
CalField
GetUnitAddress() readWriteModel.UnitAddress
- GetApplication() readWriteModel.ApplicationIdContainer
+ GetApplication() *readWriteModel.ApplicationIdContainer
}
-func NewMMIMonitorField(unitAddress readWriteModel.UnitAddress, application readWriteModel.ApplicationIdContainer, numElements uint16) SALMonitorField {
+func NewMMIMonitorField(unitAddress readWriteModel.UnitAddress, application *readWriteModel.ApplicationIdContainer, numElements uint16) SALMonitorField {
return &mmiMonitorField{
fieldType: MMI_STATUS_MONITOR,
unitAddress: unitAddress,
@@ -232,14 +232,14 @@ type salField struct {
type salMonitorField struct {
fieldType FieldType
unitAddress readWriteModel.UnitAddress
- application readWriteModel.ApplicationIdContainer
+ application *readWriteModel.ApplicationIdContainer
numElements uint16
}
type mmiMonitorField struct {
fieldType FieldType
unitAddress readWriteModel.UnitAddress
- application readWriteModel.ApplicationIdContainer
+ application *readWriteModel.ApplicationIdContainer
numElements uint16
}
@@ -531,7 +531,7 @@ func (s salMonitorField) GetUnitAddress() readWriteModel.UnitAddress {
return s.unitAddress
}
-func (s salMonitorField) GetApplication() readWriteModel.ApplicationIdContainer {
+func (s salMonitorField) GetApplication() *readWriteModel.ApplicationIdContainer {
return s.application
}
@@ -581,7 +581,7 @@ func (m mmiMonitorField) GetUnitAddress() readWriteModel.UnitAddress {
return m.unitAddress
}
-func (m mmiMonitorField) GetApplication() readWriteModel.ApplicationIdContainer {
+func (m mmiMonitorField) GetApplication() *readWriteModel.ApplicationIdContainer {
return m.application
}
diff --git a/plc4go/internal/cbus/FieldHandler.go b/plc4go/internal/cbus/FieldHandler.go
index f6fceb055..07c65d5d2 100644
--- a/plc4go/internal/cbus/FieldHandler.go
+++ b/plc4go/internal/cbus/FieldHandler.go
@@ -327,17 +327,17 @@ func (m FieldHandler) handleSALMonitorPattern(match map[string]string) (model.Pl
}
}
- var application readWriteModel.ApplicationIdContainer
+ var application *readWriteModel.ApplicationIdContainer
{
applicationIdArgument := match["application"]
if applicationIdArgument == "*" {
- application = readWriteModel.ApplicationIdContainer_RESERVED_FF
+ application = nil
} else {
- var err error
- application, err = applicationIdFromArgument(applicationIdArgument)
+ applicationId, err := applicationIdFromArgument(applicationIdArgument)
if err != nil {
return nil, errors.Wrap(err, "Error getting application id from argument")
}
+ application = &applicationId
}
}
@@ -368,17 +368,17 @@ func (m FieldHandler) handleMMIMonitorPattern(match map[string]string) (model.Pl
}
}
- var application readWriteModel.ApplicationIdContainer
+ var application *readWriteModel.ApplicationIdContainer
{
applicationIdArgument := match["application"]
if applicationIdArgument == "*" {
- application = readWriteModel.ApplicationIdContainer_RESERVED_FF
+ application = nil
} else {
- var err error
- application, err = applicationIdFromArgument(applicationIdArgument)
+ applicationId, err := applicationIdFromArgument(applicationIdArgument)
if err != nil {
return nil, errors.Wrap(err, "Error getting application id from argument")
}
+ application = &applicationId
}
}
diff --git a/plc4go/internal/cbus/Subscriber.go b/plc4go/internal/cbus/Subscriber.go
index c995aa08e..16774ba95 100644
--- a/plc4go/internal/cbus/Subscriber.go
+++ b/plc4go/internal/cbus/Subscriber.go
@@ -118,9 +118,6 @@ func (m *Subscriber) handleMonitoredMMI(calReply readWriteModel.CALReply) bool {
continue
}
}
- application := field.GetApplication()
- // TODO: filter in unit address
- _ = application
subscriptionType := subscriptionRequest.GetType(fieldName)
// TODO: handle subscriptionType
@@ -191,6 +188,12 @@ func (m *Subscriber) handleMonitoredMMI(calReply readWriteModel.CALReply) bool {
default:
return false
}
+ if application := field.GetApplication(); application != nil {
+ if actualApplicationIdString := application.ApplicationId().String(); applicationString != actualApplicationIdString {
+ log.Debug().Msgf("Current application id %s doesn't match actual id %s", unitAddressString, actualApplicationIdString)
+ continue
+ }
+ }
statusType := "binary"
if isLevel {
statusType = fmt.Sprintf("level=0x%X", blockStart)
@@ -262,9 +265,9 @@ func (m *Subscriber) handleMonitoredSal(sal readWriteModel.MonitoredSAL) bool {
}
}
- if application := field.GetApplication(); application != readWriteModel.ApplicationIdContainer_RESERVED_FF {
+ if application := field.GetApplication(); application != nil {
if actualApplicationIdString := application.ApplicationId().String(); applicationString != actualApplicationIdString {
- log.Debug().Msgf("Current application id %s doesn't matchactual id %s", unitAddressString, actualApplicationIdString)
+ log.Debug().Msgf("Current application id %s doesn't match actual id %s", unitAddressString, actualApplicationIdString)
continue
}
}