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 2023/08/01 19:35:21 UTC

[plc4x] branch develop updated (a5a5e94834 -> aff77887f2)

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 a5a5e94834 refactor(plc4go/opcua): use keyed logging
     new 265fdd1e14 feat(plc4go/opcua): fix issues with test
     new 52ed7ed50e test(plc4go): add a global timeout to DriverTestsuite for get connection
     new aff77887f2 fix(plc4go): fix issue with generator

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/Subscriber_plc4xgen.go  |  2 +-
 plc4go/internal/opcua/Driver.go              |  8 ++++++++
 plc4go/internal/opcua/MessageCodec.go        |  3 +++
 plc4go/internal/opcua/Subscriber_plc4xgen.go |  2 +-
 plc4go/spi/testutils/DriverTestRunner.go     | 12 +++++++++++-
 plc4go/tools/plc4xgenerator/gen.go           | 11 +++++++----
 6 files changed, 31 insertions(+), 7 deletions(-)


[plc4x] 01/03: feat(plc4go/opcua): fix issues with test

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 265fdd1e146695fb3b943dfba0bc2e8af0363354
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Aug 1 20:00:05 2023 +0200

    feat(plc4go/opcua): fix issues with test
---
 plc4go/internal/opcua/Driver.go       | 8 ++++++++
 plc4go/internal/opcua/MessageCodec.go | 3 +++
 2 files changed, 11 insertions(+)

diff --git a/plc4go/internal/opcua/Driver.go b/plc4go/internal/opcua/Driver.go
index f5a35cdfe3..265e00a3b4 100644
--- a/plc4go/internal/opcua/Driver.go
+++ b/plc4go/internal/opcua/Driver.go
@@ -153,6 +153,14 @@ func (m *Driver) GetConnectionWithContext(ctx context.Context, transportUrl url.
 	return connection.ConnectWithContext(ctx)
 }
 
+func (m *Driver) SetAwaitSetupComplete(awaitComplete bool) {
+	m.awaitSetupComplete = awaitComplete
+}
+
+func (m *Driver) SetAwaitDisconnectComplete(awaitComplete bool) {
+	m.awaitDisconnectComplete = awaitComplete
+}
+
 func (m *Driver) reportError(err error) <-chan plc4go.PlcConnectionConnectResult {
 	ch := make(chan plc4go.PlcConnectionConnectResult, 1)
 	ch <- _default.NewDefaultPlcConnectionConnectResult(nil, err)
diff --git a/plc4go/internal/opcua/MessageCodec.go b/plc4go/internal/opcua/MessageCodec.go
index b82b653c8f..6b0a845381 100644
--- a/plc4go/internal/opcua/MessageCodec.go
+++ b/plc4go/internal/opcua/MessageCodec.go
@@ -147,10 +147,13 @@ func (m *MessageCodec) Receive() (spi.Message, error) {
 
 	if err := ti.FillBuffer(
 		func(pos uint, currentByte byte, reader transports.ExtendedReader) bool {
+			m.log.Trace().Uint("pos", pos).Uint8("currentByte", currentByte).Msg("filling")
 			numBytesAvailable, err := ti.GetNumBytesAvailableInBuffer()
 			if err != nil {
+				m.log.Debug().Err(err).Msg("error getting available bytes")
 				return false
 			}
+			m.log.Trace().Uint32("numBytesAvailable", numBytesAvailable).Msg("check available bytes < 8")
 			return numBytesAvailable < 8
 		}); err != nil {
 		m.log.Warn().Err(err).Msg("error filling buffer")


[plc4x] 03/03: fix(plc4go): fix issue with generator

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 aff77887f2b76979a7c47115dff53836bf99f2dd
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Aug 1 21:35:13 2023 +0200

    fix(plc4go): fix issue with generator
---
 plc4go/internal/cbus/Subscriber_plc4xgen.go  |  2 +-
 plc4go/internal/opcua/Subscriber_plc4xgen.go |  2 +-
 plc4go/tools/plc4xgenerator/gen.go           | 11 +++++++----
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/plc4go/internal/cbus/Subscriber_plc4xgen.go b/plc4go/internal/cbus/Subscriber_plc4xgen.go
index d76c87cf19..4db417c08c 100644
--- a/plc4go/internal/cbus/Subscriber_plc4xgen.go
+++ b/plc4go/internal/cbus/Subscriber_plc4xgen.go
@@ -46,7 +46,7 @@ func (d *Subscriber) SerializeWithWriteBuffer(ctx context.Context, writeBuffer u
 		return err
 	}
 	for _name, elem := range d.consumers {
-		name := fmt.Sprintf("%v", _name)
+		name := fmt.Sprintf("%v", &_name)
 
 		var elem any = elem
 		if serializable, ok := elem.(utils.Serializable); ok {
diff --git a/plc4go/internal/opcua/Subscriber_plc4xgen.go b/plc4go/internal/opcua/Subscriber_plc4xgen.go
index 48ffad27dd..c96d7ddfa4 100644
--- a/plc4go/internal/opcua/Subscriber_plc4xgen.go
+++ b/plc4go/internal/opcua/Subscriber_plc4xgen.go
@@ -46,7 +46,7 @@ func (d *Subscriber) SerializeWithWriteBuffer(ctx context.Context, writeBuffer u
 		return err
 	}
 	for _name, elem := range d.consumers {
-		name := fmt.Sprintf("%v", _name)
+		name := fmt.Sprintf("%v", &_name)
 
 		var elem any = elem
 		if serializable, ok := elem.(utils.Serializable); ok {
diff --git a/plc4go/tools/plc4xgenerator/gen.go b/plc4go/tools/plc4xgenerator/gen.go
index de4f403d89..156215a9ed 100644
--- a/plc4go/tools/plc4xgenerator/gen.go
+++ b/plc4go/tools/plc4xgenerator/gen.go
@@ -350,15 +350,18 @@ func (g *Generator) generate(typeName string) {
 			g.Printf("if err := writeBuffer.PushContext(%s, utils.WithRenderAsList(true)); err != nil {\n\t\treturn err\n\t}\n", fieldNameUntitled)
 			// TODO: we use serializable or strings as we don't want to over-complex this
 			g.Printf("for _name, elem := range d.%s {\n", fieldName)
-			if ident, ok := fieldType.Key.(*ast.Ident); !ok || ident.Name != "string" {
-				switch ident.Name {
+			switch keyType := fieldType.Key.(type) {
+			case *ast.Ident:
+				switch keyType.Name {
 				case "uint", "uint8", "uint16", "uint32", "uint64", "int", "int8", "int16", "int32", "int64": // TODO: add other types
 					g.Printf("\t\tname := fmt.Sprintf(\"%s\", _name)\n", "%v")
+				case "string":
+					g.Printf("\t\tname := _name\n")
 				default:
 					g.Printf("\t\tname := fmt.Sprintf(\"%s\", &_name)\n", "%v")
 				}
-			} else {
-				g.Printf("\t\tname := _name\n")
+			default:
+				g.Printf("\t\tname := fmt.Sprintf(\"%s\", &_name)\n", "%v")
 			}
 			switch eltType := fieldType.Value.(type) {
 			case *ast.StarExpr, *ast.SelectorExpr:


[plc4x] 02/03: test(plc4go): add a global timeout to DriverTestsuite for get connection

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 52ed7ed50e78acd60a164cf7783d79717215ad42
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Aug 1 21:03:44 2023 +0200

    test(plc4go): add a global timeout to DriverTestsuite for get connection
---
 plc4go/spi/testutils/DriverTestRunner.go | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/plc4go/spi/testutils/DriverTestRunner.go b/plc4go/spi/testutils/DriverTestRunner.go
index b5a639ca2b..909bfac2d0 100644
--- a/plc4go/spi/testutils/DriverTestRunner.go
+++ b/plc4go/spi/testutils/DriverTestRunner.go
@@ -46,6 +46,8 @@ import (
 	"github.com/subchen/go-xmldom"
 )
 
+var DriverTestsuiteConnectTimeout = 30 * time.Second
+
 type DriverTestsuite struct {
 	name             string
 	protocolName     string
@@ -101,8 +103,16 @@ func (m DriverTestsuite) Run(t *testing.T, driverManager plc4go.PlcDriverManager
 		optionsString = "?" + strings.Join(driverParameters, "&")
 	}
 	// Get a connection
+	t.Log("getting a connection")
 	connectionChan := driverManager.GetConnection(m.driverName + ":test://hurz" + optionsString)
-	connectionResult := <-connectionChan
+	timer := time.NewTimer(DriverTestsuiteConnectTimeout)
+	t.Cleanup(func() { utils.CleanupTimer(timer) })
+	var connectionResult plc4go.PlcConnectionConnectResult
+	select {
+	case connectionResult = <-connectionChan:
+	case <-timer.C:
+		t.Fatalf("timeout")
+	}
 
 	if connectionResult.GetErr() != nil {
 		return errors.Wrap(connectionResult.GetErr(), "error getting a connection")