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/08/05 15:13:11 UTC

[plc4x] branch develop updated (b67679f0b -> 3c7065cb4)

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 b67679f0b fix(plc4go): fix go install by changing to fork
     new e4f60a3f1 fix(cbus): fixed identify output unit sumary
     new 3c7065cb4 feat(plc-simulator/cbus): implemented identify responses

The 2 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:
 .../model/IdentifyReplyCommandOutputUnitSummary.go |  78 +++++++-----
 .../src/main/resources/protocols/cbus/c-bus.mspec  |   5 +-
 .../server/cbus/protocol/CBusServerAdapter.java    | 134 ++++++++++++++++++++-
 3 files changed, 181 insertions(+), 36 deletions(-)


[plc4x] 02/02: feat(plc-simulator/cbus): implemented identify responses

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 3c7065cb47349ff041b749ddc6dfac73419f0fee
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Aug 5 17:13:01 2022 +0200

    feat(plc-simulator/cbus): implemented identify responses
---
 .../server/cbus/protocol/CBusServerAdapter.java    | 134 ++++++++++++++++++++-
 1 file changed, 132 insertions(+), 2 deletions(-)

diff --git a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/protocol/CBusServerAdapter.java b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/protocol/CBusServerAdapter.java
index e58490f06..9a890561d 100644
--- a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/protocol/CBusServerAdapter.java
+++ b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/protocol/CBusServerAdapter.java
@@ -210,8 +210,129 @@ public class CBusServerAdapter extends ChannelInboundHandlerAdapter {
                 LOGGER.info("Handling CBusCommand\n{}", cbusCommand);
                 if (cbusCommand instanceof CBusCommandPointToPoint) {
                     CBusCommandPointToPoint cBusCommandPointToPoint = (CBusCommandPointToPoint) cbusCommand;
-                    LOGGER.info("Handling CBusCommandPointToPoint\n{}", cBusCommandPointToPoint);
-                    // TODO: handle this
+                    CBusPointToPointCommand command = cBusCommandPointToPoint.getCommand();
+                    UnitAddress unitAddress;
+                    if (command instanceof CBusPointToPointCommandIndirect) {
+                        CBusPointToPointCommandIndirect cBusPointToPointCommandIndirect = (CBusPointToPointCommandIndirect) command;
+                        // TODO: handle bridgeAddress
+                        // TODO: handle networkRoute
+                        unitAddress = cBusPointToPointCommandIndirect.getUnitAddress();
+                    }
+                    if (command instanceof CBusPointToPointCommandDirect) {
+                        CBusPointToPointCommandDirect cBusPointToPointCommandDirect = (CBusPointToPointCommandDirect) command;
+                        unitAddress = cBusPointToPointCommandDirect.getUnitAddress();
+                    }
+                    CALData calData = command.getCalData();
+                    // TODO: handle other Datatypes
+                    if (calData instanceof CALDataIdentify) {
+                        short numBytes = 0;
+                        IdentifyReplyCommand identifyReplyCommand;
+                        CALDataIdentify calDataIdentify = (CALDataIdentify) calData;
+                        switch (calDataIdentify.getAttribute()) {
+                            case Manufacturer:
+                                numBytes = 0x08;
+                                identifyReplyCommand = new IdentifyReplyCommandManufacturer("Apache", numBytes);
+                                break;
+                            case Type:
+                                numBytes = 0x08;
+                                identifyReplyCommand = new IdentifyReplyCommandType("plc4x-si", numBytes);
+                                break;
+                            case FirmwareVersion:
+                                numBytes = 0x08;
+                                identifyReplyCommand = new IdentifyReplyCommandFirmwareVersion("0.9", numBytes);
+                                break;
+                            case Summary:
+                                numBytes = 0x09;
+                                identifyReplyCommand = new IdentifyReplyCommandFirmwareSummary("0.9", (byte) 0xAF, "0.0", numBytes);
+                                break;
+                            case ExtendedDiagnosticSummary:
+                                numBytes = 0x0C;
+                                identifyReplyCommand = new IdentifyReplyCommandExtendedDiagnosticSummary(ApplicationIdContainer.FREE_USAGE_01, ApplicationIdContainer.FREE_USAGE_0F, (byte) 0x0, 0x0, 4711l, (byte) 0x13, false, false, false, true, false, false, false, false, false, false, false, false, false, numBytes);
+                                break;
+                            case NetworkTerminalLevels:
+                                numBytes = 0x0D;
+                                identifyReplyCommand = new IdentifyReplyCommandNetworkTerminalLevels(new byte[]{0x13}, numBytes);
+                                break;
+                            case TerminalLevel:
+                                numBytes = 0x0D;
+                                identifyReplyCommand = new IdentifyReplyCommandTerminalLevels(new byte[]{0x13}, numBytes);
+                                break;
+                            case NetworkVoltage:
+                                numBytes = 0x05;
+                                identifyReplyCommand = new IdentifyReplyCommandNetworkVoltage("48", "7", numBytes);
+                                break;
+                            case GAVValuesCurrent:
+                                numBytes = 0x10;
+                                identifyReplyCommand = new IdentifyReplyCommandGAVValuesCurrent(new byte[]{
+                                    0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
+                                    0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
+                                }, numBytes);
+                                break;
+                            case GAVValuesStored:
+                                numBytes = 0x10;
+                                identifyReplyCommand = new IdentifyReplyCommandGAVValuesStored(new byte[]{
+                                    0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
+                                    0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
+                                }, numBytes);
+                                break;
+                            case GAVPhysicalAddresses:
+                                numBytes = 0x10;
+                                identifyReplyCommand = new IdentifyReplyCommandGAVPhysicalAddresses(new byte[]{
+                                    0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
+                                    0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
+                                }, numBytes);
+                                break;
+                            case LogicalAssignment:
+                                numBytes = 0x0E;
+                                identifyReplyCommand = new IdentifyReplyCommandLogicalAssignment(List.of(new LogicAssignment(false, true, true, true, true, true)), numBytes);
+                                break;
+                            case Delays:
+                                numBytes = 0x0F;
+                                identifyReplyCommand = new IdentifyReplyCommandDelays(new byte[]{0x3}, (byte) 0x13, numBytes);
+                                break;
+                            case MinimumLevels:
+                                numBytes = 0x0E;
+                                identifyReplyCommand = new IdentifyReplyCommandMinimumLevels(new byte[]{0x3}, numBytes);
+                                break;
+                            case MaximumLevels:
+                                numBytes = 0x0F;
+                                identifyReplyCommand = new IdentifyReplyCommandMaximumLevels(new byte[]{0xF}, numBytes);
+                                break;
+                            case CurrentSenseLevels:
+                                numBytes = 0x10;
+                                identifyReplyCommand = new IdentifyReplyCommandCurrentSenseLevels(new byte[]{0xF}, numBytes);
+                                break;
+                            case OutputUnitSummary:
+                                numBytes = 0x12;
+                                identifyReplyCommand = new IdentifyReplyCommandOutputUnitSummary(new IdentifyReplyCommandUnitSummary(false, false, false, false, false, false, false, false), (byte) 0x4, (byte) 0x4, (short) 45, numBytes);
+                                break;
+                            case DSIStatus:
+                                numBytes = 0x12;
+                                identifyReplyCommand = new IdentifyReplyCommandDSIStatus(ChannelStatus.OK, ChannelStatus.OK, ChannelStatus.OK, ChannelStatus.OK, ChannelStatus.OK, ChannelStatus.OK, ChannelStatus.OK, ChannelStatus.OK, UnitStatus.OK, (byte) 0x34, numBytes);
+                                break;
+                            default:
+                                throw new IllegalStateException("unmapped type " + calDataIdentify.getAttribute());
+                        }
+
+                        calData = new CALDataIdentifyReply(getReplyCommandType(numBytes + 1), null, ((CALDataIdentify) calData).getAttribute(), identifyReplyCommand, requestContext);
+                        CALReply calReply;
+                        if (exstat) {
+                            calReply = new CALReplyLong((byte) 0x0, calData, (byte) 0x0, new UnitAddress((byte) 0x0), null, new SerialInterfaceAddress((byte) 0x02), (byte) 0x0, null, cBusOptions, requestContext);
+                        } else {
+                            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);
+                        LOGGER.info("Send identify response\n{}", response);
+                        ctx.writeAndFlush(response);
+                    }
                     return;
                 }
                 if (cbusCommand instanceof CBusCommandPointToMultiPoint) {
@@ -451,4 +572,13 @@ public class CBusServerAdapter extends ChannelInboundHandlerAdapter {
         mmiMonitorFuture = null;
     }
 
+    private CALCommandTypeContainer getReplyCommandType(int numBytes) {
+        for (CALCommandTypeContainer value : CALCommandTypeContainer.values()) {
+            if (value.getCommandType() == CALCommandType.REPLY && value.getNumBytes() == numBytes) {
+                return value;
+            }
+        }
+        throw new IllegalArgumentException("No reply type for " + numBytes);
+    }
+
 }


[plc4x] 01/02: fix(cbus): fixed identify output unit sumary

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 e4f60a3f1f81cab3fb52e2e69a87d8cfac3c6afa
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Aug 5 17:07:30 2022 +0200

    fix(cbus): fixed identify output unit sumary
---
 .../model/IdentifyReplyCommandOutputUnitSummary.go | 78 +++++++++++++---------
 .../src/main/resources/protocols/cbus/c-bus.mspec  |  5 +-
 2 files changed, 49 insertions(+), 34 deletions(-)

diff --git a/plc4go/protocols/cbus/readwrite/model/IdentifyReplyCommandOutputUnitSummary.go b/plc4go/protocols/cbus/readwrite/model/IdentifyReplyCommandOutputUnitSummary.go
index df181dea6..61986d80e 100644
--- a/plc4go/protocols/cbus/readwrite/model/IdentifyReplyCommandOutputUnitSummary.go
+++ b/plc4go/protocols/cbus/readwrite/model/IdentifyReplyCommandOutputUnitSummary.go
@@ -34,9 +34,9 @@ type IdentifyReplyCommandOutputUnitSummary interface {
 	// GetUnitFlags returns UnitFlags (property field)
 	GetUnitFlags() IdentifyReplyCommandUnitSummary
 	// GetGavStoreEnabledByte1 returns GavStoreEnabledByte1 (property field)
-	GetGavStoreEnabledByte1() byte
+	GetGavStoreEnabledByte1() *byte
 	// GetGavStoreEnabledByte2 returns GavStoreEnabledByte2 (property field)
-	GetGavStoreEnabledByte2() byte
+	GetGavStoreEnabledByte2() *byte
 	// GetTimeFromLastRecoverOfMainsInSeconds returns TimeFromLastRecoverOfMainsInSeconds (property field)
 	GetTimeFromLastRecoverOfMainsInSeconds() uint8
 }
@@ -52,8 +52,8 @@ type IdentifyReplyCommandOutputUnitSummaryExactly interface {
 type _IdentifyReplyCommandOutputUnitSummary struct {
 	*_IdentifyReplyCommand
 	UnitFlags                           IdentifyReplyCommandUnitSummary
-	GavStoreEnabledByte1                byte
-	GavStoreEnabledByte2                byte
+	GavStoreEnabledByte1                *byte
+	GavStoreEnabledByte2                *byte
 	TimeFromLastRecoverOfMainsInSeconds uint8
 }
 
@@ -86,11 +86,11 @@ func (m *_IdentifyReplyCommandOutputUnitSummary) GetUnitFlags() IdentifyReplyCom
 	return m.UnitFlags
 }
 
-func (m *_IdentifyReplyCommandOutputUnitSummary) GetGavStoreEnabledByte1() byte {
+func (m *_IdentifyReplyCommandOutputUnitSummary) GetGavStoreEnabledByte1() *byte {
 	return m.GavStoreEnabledByte1
 }
 
-func (m *_IdentifyReplyCommandOutputUnitSummary) GetGavStoreEnabledByte2() byte {
+func (m *_IdentifyReplyCommandOutputUnitSummary) GetGavStoreEnabledByte2() *byte {
 	return m.GavStoreEnabledByte2
 }
 
@@ -104,7 +104,7 @@ func (m *_IdentifyReplyCommandOutputUnitSummary) GetTimeFromLastRecoverOfMainsIn
 ///////////////////////////////////////////////////////////
 
 // NewIdentifyReplyCommandOutputUnitSummary factory function for _IdentifyReplyCommandOutputUnitSummary
-func NewIdentifyReplyCommandOutputUnitSummary(unitFlags IdentifyReplyCommandUnitSummary, gavStoreEnabledByte1 byte, gavStoreEnabledByte2 byte, timeFromLastRecoverOfMainsInSeconds uint8, numBytes uint8) *_IdentifyReplyCommandOutputUnitSummary {
+func NewIdentifyReplyCommandOutputUnitSummary(unitFlags IdentifyReplyCommandUnitSummary, gavStoreEnabledByte1 *byte, gavStoreEnabledByte2 *byte, timeFromLastRecoverOfMainsInSeconds uint8, numBytes uint8) *_IdentifyReplyCommandOutputUnitSummary {
 	_result := &_IdentifyReplyCommandOutputUnitSummary{
 		UnitFlags:                           unitFlags,
 		GavStoreEnabledByte1:                gavStoreEnabledByte1,
@@ -141,11 +141,15 @@ func (m *_IdentifyReplyCommandOutputUnitSummary) GetLengthInBitsConditional(last
 	// Simple field (unitFlags)
 	lengthInBits += m.UnitFlags.GetLengthInBits()
 
-	// Simple field (gavStoreEnabledByte1)
-	lengthInBits += 8
+	// Optional Field (gavStoreEnabledByte1)
+	if m.GavStoreEnabledByte1 != nil {
+		lengthInBits += 8
+	}
 
-	// Simple field (gavStoreEnabledByte2)
-	lengthInBits += 8
+	// Optional Field (gavStoreEnabledByte2)
+	if m.GavStoreEnabledByte2 != nil {
+		lengthInBits += 8
+	}
 
 	// Simple field (timeFromLastRecoverOfMainsInSeconds)
 	lengthInBits += 8
@@ -179,19 +183,25 @@ func IdentifyReplyCommandOutputUnitSummaryParse(readBuffer utils.ReadBuffer, att
 		return nil, errors.Wrap(closeErr, "Error closing for unitFlags")
 	}
 
-	// Simple Field (gavStoreEnabledByte1)
-	_gavStoreEnabledByte1, _gavStoreEnabledByte1Err := readBuffer.ReadByte("gavStoreEnabledByte1")
-	if _gavStoreEnabledByte1Err != nil {
-		return nil, errors.Wrap(_gavStoreEnabledByte1Err, "Error parsing 'gavStoreEnabledByte1' field of IdentifyReplyCommandOutputUnitSummary")
+	// Optional Field (gavStoreEnabledByte1) (Can be skipped, if a given expression evaluates to false)
+	var gavStoreEnabledByte1 *byte = nil
+	if bool((numBytes) > (1)) {
+		_val, _err := readBuffer.ReadByte("gavStoreEnabledByte1")
+		if _err != nil {
+			return nil, errors.Wrap(_err, "Error parsing 'gavStoreEnabledByte1' field of IdentifyReplyCommandOutputUnitSummary")
+		}
+		gavStoreEnabledByte1 = &_val
 	}
-	gavStoreEnabledByte1 := _gavStoreEnabledByte1
 
-	// Simple Field (gavStoreEnabledByte2)
-	_gavStoreEnabledByte2, _gavStoreEnabledByte2Err := readBuffer.ReadByte("gavStoreEnabledByte2")
-	if _gavStoreEnabledByte2Err != nil {
-		return nil, errors.Wrap(_gavStoreEnabledByte2Err, "Error parsing 'gavStoreEnabledByte2' field of IdentifyReplyCommandOutputUnitSummary")
+	// Optional Field (gavStoreEnabledByte2) (Can be skipped, if a given expression evaluates to false)
+	var gavStoreEnabledByte2 *byte = nil
+	if bool((numBytes) > (2)) {
+		_val, _err := readBuffer.ReadByte("gavStoreEnabledByte2")
+		if _err != nil {
+			return nil, errors.Wrap(_err, "Error parsing 'gavStoreEnabledByte2' field of IdentifyReplyCommandOutputUnitSummary")
+		}
+		gavStoreEnabledByte2 = &_val
 	}
-	gavStoreEnabledByte2 := _gavStoreEnabledByte2
 
 	// Simple Field (timeFromLastRecoverOfMainsInSeconds)
 	_timeFromLastRecoverOfMainsInSeconds, _timeFromLastRecoverOfMainsInSecondsErr := readBuffer.ReadUint8("timeFromLastRecoverOfMainsInSeconds", 8)
@@ -238,18 +248,24 @@ func (m *_IdentifyReplyCommandOutputUnitSummary) Serialize(writeBuffer utils.Wri
 			return errors.Wrap(_unitFlagsErr, "Error serializing 'unitFlags' field")
 		}
 
-		// Simple Field (gavStoreEnabledByte1)
-		gavStoreEnabledByte1 := byte(m.GetGavStoreEnabledByte1())
-		_gavStoreEnabledByte1Err := writeBuffer.WriteByte("gavStoreEnabledByte1", (gavStoreEnabledByte1))
-		if _gavStoreEnabledByte1Err != nil {
-			return errors.Wrap(_gavStoreEnabledByte1Err, "Error serializing 'gavStoreEnabledByte1' field")
+		// Optional Field (gavStoreEnabledByte1) (Can be skipped, if the value is null)
+		var gavStoreEnabledByte1 *byte = nil
+		if m.GetGavStoreEnabledByte1() != nil {
+			gavStoreEnabledByte1 = m.GetGavStoreEnabledByte1()
+			_gavStoreEnabledByte1Err := writeBuffer.WriteByte("gavStoreEnabledByte1", *(gavStoreEnabledByte1))
+			if _gavStoreEnabledByte1Err != nil {
+				return errors.Wrap(_gavStoreEnabledByte1Err, "Error serializing 'gavStoreEnabledByte1' field")
+			}
 		}
 
-		// Simple Field (gavStoreEnabledByte2)
-		gavStoreEnabledByte2 := byte(m.GetGavStoreEnabledByte2())
-		_gavStoreEnabledByte2Err := writeBuffer.WriteByte("gavStoreEnabledByte2", (gavStoreEnabledByte2))
-		if _gavStoreEnabledByte2Err != nil {
-			return errors.Wrap(_gavStoreEnabledByte2Err, "Error serializing 'gavStoreEnabledByte2' field")
+		// Optional Field (gavStoreEnabledByte2) (Can be skipped, if the value is null)
+		var gavStoreEnabledByte2 *byte = nil
+		if m.GetGavStoreEnabledByte2() != nil {
+			gavStoreEnabledByte2 = m.GetGavStoreEnabledByte2()
+			_gavStoreEnabledByte2Err := writeBuffer.WriteByte("gavStoreEnabledByte2", *(gavStoreEnabledByte2))
+			if _gavStoreEnabledByte2Err != nil {
+				return errors.Wrap(_gavStoreEnabledByte2Err, "Error serializing 'gavStoreEnabledByte2' field")
+			}
 		}
 
 		// Simple Field (timeFromLastRecoverOfMainsInSeconds)
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 3c18bd8e1..d5454dd16 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
@@ -1123,11 +1123,10 @@
             [array  byte        currentSenseLevels  count 'numBytes'       ]
         ]
         ['OutputUnitSummary'            IdentifyReplyCommandOutputUnitSummary
-            // TODO: we can use the bytes from above, but how is that dynamic? repeat the complete block here?
             [simple   IdentifyReplyCommandUnitSummary
                              unitFlags                              ]
-            [simple   byte   gavStoreEnabledByte1                   ]
-            [simple   byte   gavStoreEnabledByte2                   ]
+            [optional byte   gavStoreEnabledByte1  'numBytes>1'     ]
+            [optional byte   gavStoreEnabledByte2  'numBytes>2'     ]
             [simple   uint 8 timeFromLastRecoverOfMainsInSeconds    ]
         ]
         ['DSIStatus'                    IdentifyReplyCommandDSIStatus