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 12:23:54 UTC

[plc4x] branch develop updated: feat(plc4xbrowser): added first iteration of read support

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


The following commit(s) were added to refs/heads/develop by this push:
     new 5faa9e14a feat(plc4xbrowser): added first iteration of read support
5faa9e14a is described below

commit 5faa9e14acf366f9a58987329cb299950a0477db
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Aug 5 14:23:47 2022 +0200

    feat(plc4xbrowser): added first iteration of read support
---
 plc4go/tools/plc4xbrowser/commands.go | 75 ++++++++++++++++++++++++++++++++++-
 plc4go/tools/plc4xbrowser/main.go     |  2 +
 2 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/plc4go/tools/plc4xbrowser/commands.go b/plc4go/tools/plc4xbrowser/commands.go
index 1292908c7..bec0d764b 100644
--- a/plc4go/tools/plc4xbrowser/commands.go
+++ b/plc4go/tools/plc4xbrowser/commands.go
@@ -36,6 +36,8 @@ const rootCommandIndicator = "rootCommand"
 
 var commands = map[inputMode]Command{
 	normalMode:        rootCommand,
+	readEditMode:      rootCommand,
+	writeEditMode:     rootCommand,
 	subscribeEditMode: rootCommand,
 }
 
@@ -104,10 +106,79 @@ var rootCommand = Command{
 			},
 		},
 		{
-			Name: "read",
+			Name:        "read",
+			Description: "Starts a read request (switched mode to read edit)",
+			action: func(_ Command, connectionsString string) error {
+				if connection, ok := connections[connectionsString]; !ok {
+					return errors.Errorf("%s not connected", connectionsString)
+				} else {
+					return errors.Errorf("%s mode switch not yet implemented", connection)
+				}
+			},
+			parameterSuggestions: func(currentText string) (entries []string) {
+				for connectionsString, _ := range connections {
+					entries = append(entries, connectionsString)
+				}
+				return
+			},
+		},
+		{
+			Name:        "read-direct",
+			Description: "Builds a read request with the supplied field",
+			action: func(c Command, connectionsStringAndFieldQuery string) error {
+				split := strings.Split(connectionsStringAndFieldQuery, " ")
+				if len(split) != 2 {
+					return errors.Errorf("%s expects exactly two arguments [connection url] [fieldQuery]", c)
+				}
+				connectionsString := split[0]
+				if connection, ok := connections[connectionsString]; !ok {
+					return errors.Errorf("%s not connected", connectionsString)
+				} else {
+					readRequest, err := connection.ReadRequestBuilder().
+						AddQuery("readField", split[1]).
+						Build()
+					if err != nil {
+						return errors.Wrapf(err, "%s can't read", connectionsString)
+					}
+					readRequestResult := <-readRequest.Execute()
+					if err := readRequestResult.GetErr(); err != nil {
+						return errors.Wrapf(err, "%s can't read", connectionsString)
+					}
+					log.Info().Msgf("read result %s", readRequestResult.GetResponse())
+				}
+				return nil
+			},
+			parameterSuggestions: func(currentText string) (entries []string) {
+				for connectionsString, _ := range connections {
+					if strings.HasPrefix(currentText, connectionsString+"") {
+						parse, _ := url.Parse(connectionsString)
+						switch parse.Scheme {
+						// TODO: add to protocol suggestor so it can be reused.
+
+						}
+					} else {
+						entries = append(entries, connectionsString)
+					}
+				}
+				return
+			},
 		},
 		{
-			Name: "write",
+			Name:        "write",
+			Description: "Starts a write request (switched mode to write edit)",
+			action: func(_ Command, connectionsString string) error {
+				if connection, ok := connections[connectionsString]; !ok {
+					return errors.Errorf("%s not connected", connectionsString)
+				} else {
+					return errors.Errorf("%s mode switch not yet implemented", connection)
+				}
+			},
+			parameterSuggestions: func(currentText string) (entries []string) {
+				for connectionsString, _ := range connections {
+					entries = append(entries, connectionsString)
+				}
+				return
+			},
 		},
 		{
 			Name:        "register",
diff --git a/plc4go/tools/plc4xbrowser/main.go b/plc4go/tools/plc4xbrowser/main.go
index 4c0e48a3f..1f5ebcd1c 100644
--- a/plc4go/tools/plc4xbrowser/main.go
+++ b/plc4go/tools/plc4xbrowser/main.go
@@ -49,6 +49,8 @@ type inputMode int
 
 const (
 	normalMode inputMode = iota
+	readEditMode
+	writeEditMode
 	subscribeEditMode
 )