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/27 09:58:15 UTC

[plc4x] branch develop updated (8bfb8ecf4 -> 04ff7740f)

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 8bfb8ecf4 build(deps): bump actions/github-script from 6.2.0 to 6.3.0 (#521)
     new 01a2ecef4 fix(plc-simulator/cbus): fix missing reset echo on smart or connect
     new 04ff7740f refactor(plc4go/cbus): added cleanups and logging

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:
 plc4go/internal/cbus/Connection.go                             |  5 ++---
 plc4go/internal/cbus/MessageCodec.go                           | 10 +++++++---
 .../simulator/server/cbus/protocol/CBusServerAdapter.java      |  5 +++++
 3 files changed, 14 insertions(+), 6 deletions(-)


[plc4x] 02/02: refactor(plc4go/cbus): added cleanups and logging

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 04ff7740f6101f468d6d362e76a5832a394791eb
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Sep 27 11:58:02 2022 +0200

    refactor(plc4go/cbus): added cleanups and logging
---
 plc4go/internal/cbus/Connection.go   |  5 ++---
 plc4go/internal/cbus/MessageCodec.go | 10 +++++++---
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/plc4go/internal/cbus/Connection.go b/plc4go/internal/cbus/Connection.go
index 43732e417..ab1d96f54 100644
--- a/plc4go/internal/cbus/Connection.go
+++ b/plc4go/internal/cbus/Connection.go
@@ -112,8 +112,7 @@ func (c *Connection) Connect() <-chan plc4go.PlcConnectionConnectResult {
 	log.Trace().Msg("Connecting")
 	ch := make(chan plc4go.PlcConnectionConnectResult)
 	go func() {
-		err := c.messageCodec.Connect()
-		if err != nil {
+		if err := c.messageCodec.Connect(); err != nil {
 			c.fireConnectionError(errors.Wrap(err, "Error connecting codec"), ch)
 			return
 		}
@@ -312,7 +311,7 @@ func (c *Connection) sendReset(ctx context.Context, ch chan plc4go.PlcConnection
 		if sendOutErrorNotification {
 			c.fireConnectionError(errors.Errorf("Timeout after %v", timeout.Sub(startTime)), ch)
 		} else {
-			log.Trace().Msg("timeout")
+			log.Trace().Msgf("Timeout after %v", timeout.Sub(startTime))
 		}
 		return false
 	}
diff --git a/plc4go/internal/cbus/MessageCodec.go b/plc4go/internal/cbus/MessageCodec.go
index 5d68716e9..7b07c3e4e 100644
--- a/plc4go/internal/cbus/MessageCodec.go
+++ b/plc4go/internal/cbus/MessageCodec.go
@@ -85,11 +85,13 @@ func (m *MessageCodec) Send(message spi.Message) error {
 }
 
 func (m *MessageCodec) Receive() (spi.Message, error) {
+	log.Trace().Msg("Receive")
 	ti := m.GetTransportInstance()
 	confirmation := false
 	// Fill the buffer
 	{
 		if err := ti.FillBuffer(func(_ uint, currentByte byte, reader *bufio.Reader) bool {
+			log.Trace().Uint8("byte", currentByte).Msg("current byte")
 			switch currentByte {
 			case
 				readWriteModel.ResponseTermination_CR,
@@ -111,6 +113,7 @@ func (m *MessageCodec) Receive() (spi.Message, error) {
 			return nil, errors.Wrap(err, "error filling buffer")
 		}
 	}
+	log.Trace().Msg("Buffer filled")
 
 	// Check how many readable bytes we have
 	var readableBytes uint32
@@ -165,11 +168,13 @@ lookingForTheEnd:
 			break lookingForTheEnd
 		}
 	}
+	log.Trace().Msgf("indexOfCR %d,indexOfLF %d,indexOfConfirmation %d", indexOfCR, indexOfLF, indexOfConfirmation)
 	if indexOfCR < 0 && indexOfLF >= 0 {
 		// This means that the package is garbage as a lf is always prefixed with a cr
 		log.Debug().Err(err).Msg("Error reading")
-		// TODO: Possibly clean up ...
-		return nil, nil
+		garbage, err := ti.Read(readableBytes)
+		log.Warn().Bytes("garbage", garbage).Msg("Garbage bytes")
+		return nil, err
 	}
 	if indexOfCR+1 == indexOfLF {
 		// This means a <cr> is directly followed by a <lf> which means that we know for sure this is a response
@@ -287,7 +292,6 @@ lookingForTheEnd:
 		}
 
 		log.Warn().Err(err).Msg("error parsing")
-		// TODO: Possibly clean up ...
 		return nil, nil
 	}
 	return cBusMessage, nil


[plc4x] 01/02: fix(plc-simulator/cbus): fix missing reset echo on smart or connect

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 01a2ecef479021ae40f90733e77313961a1fb119
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Sep 27 11:57:10 2022 +0200

    fix(plc-simulator/cbus): fix missing reset echo on smart or connect
---
 .../plc4x/simulator/server/cbus/protocol/CBusServerAdapter.java      | 5 +++++
 1 file changed, 5 insertions(+)

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 493decf9b..677e633cc 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
@@ -128,6 +128,11 @@ public class CBusServerAdapter extends ChannelInboundHandlerAdapter {
             LOGGER.info("Handling RequestObsolete\n{}", requestObsolete);
             // TODO: handle this
         } else if (request instanceof RequestReset) {
+            if (smart || connect) {
+                // On reset, we need to send the echo if we had not sent it above
+                LOGGER.info("Sending echo");
+                ctx.write(msg);
+            }
             handleReset((RequestReset) request);
         } else if (request instanceof RequestSmartConnectShortcut) {
             handleSmartConnect((RequestSmartConnectShortcut) request);