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/08 10:45:39 UTC

[plc4x] 02/02: feat(plc4xbrowser): added browse 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

commit a3d68a2d135d7f2d5ea4f190e316c1614507c438
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon Aug 8 12:45:31 2022 +0200

    feat(plc4xbrowser): added browse support
---
 plc4go/tools/plc4xbrowser/commands.go | 67 ++++++++++++++++++++++++++++++++++-
 1 file changed, 66 insertions(+), 1 deletion(-)

diff --git a/plc4go/tools/plc4xbrowser/commands.go b/plc4go/tools/plc4xbrowser/commands.go
index 15661245a..fef5f58a8 100644
--- a/plc4go/tools/plc4xbrowser/commands.go
+++ b/plc4go/tools/plc4xbrowser/commands.go
@@ -211,7 +211,7 @@ var rootCommand = Command{
 					}
 					plc4xBrowserLog.Debug().Msgf("write took %f seconds", time.Now().Sub(start).Seconds())
 					if err := writeRequestResult.GetErr(); err != nil {
-						return errors.Wrapf(err, "%s error reading", connectionsString)
+						return errors.Wrapf(err, "%s error writing", connectionsString)
 					}
 					numberOfMessagesReceived++
 					messageReceived(numberOfMessagesReceived, time.Now(), writeRequestResult.GetResponse())
@@ -233,6 +233,71 @@ var rootCommand = Command{
 				return
 			},
 		},
+		{
+			Name:        "browse",
+			Description: "Starts a browse request (switched mode to browse 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:        "browse-direct",
+			Description: "Builds a browse 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 three arguments [connection url] [fieldQuery]", c)
+				}
+				connectionsString := split[0]
+				if connection, ok := connections[connectionsString]; !ok {
+					return errors.Errorf("%s not connected", connectionsString)
+				} else {
+					start := time.Now()
+					writeRequest, err := connection.BrowseRequestBuilder().
+						AddItem("writeField", split[1]).
+						Build()
+					if err != nil {
+						return errors.Wrapf(err, "%s can't browse", connectionsString)
+					}
+					writeRequestResult := <-writeRequest.Execute()
+					if err := writeRequestResult.GetErr(); err != nil {
+						return errors.Wrapf(err, "%s can't browse", connectionsString)
+					}
+					plc4xBrowserLog.Debug().Msgf("write took %f seconds", time.Now().Sub(start).Seconds())
+					if err := writeRequestResult.GetErr(); err != nil {
+						return errors.Wrapf(err, "%s error browse", connectionsString)
+					}
+					numberOfMessagesReceived++
+					messageReceived(numberOfMessagesReceived, time.Now(), writeRequestResult.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.
+						case "c-bus":
+							entries = append(entries, connectionsString+" info/*/*")
+						}
+					} else {
+						entries = append(entries, connectionsString)
+					}
+				}
+				return
+			},
+		},
 		{
 			Name:        "register",
 			Description: "register a driver in the subsystem",