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 13:15:53 UTC

[plc4x] branch develop updated: feat(plc4xbrowser): implemented write-direct

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 8d2e7134d feat(plc4xbrowser): implemented write-direct
8d2e7134d is described below

commit 8d2e7134db61c303bdf7cdf4e48c28ba0b15bfb2
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Aug 5 15:15:47 2022 +0200

    feat(plc4xbrowser): implemented write-direct
---
 plc4go/tools/plc4xbrowser/commands.go | 47 +++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/plc4go/tools/plc4xbrowser/commands.go b/plc4go/tools/plc4xbrowser/commands.go
index b0a2132bc..5e4d928bd 100644
--- a/plc4go/tools/plc4xbrowser/commands.go
+++ b/plc4go/tools/plc4xbrowser/commands.go
@@ -186,6 +186,53 @@ var rootCommand = Command{
 				return
 			},
 		},
+		{
+			Name:        "write-direct",
+			Description: "Builds a write request with the supplied field",
+			action: func(c Command, connectionsStringAndFieldQuery string) error {
+				split := strings.Split(connectionsStringAndFieldQuery, " ")
+				if len(split) != 3 {
+					return errors.Errorf("%s expects exactly three arguments [connection url] [fieldQuery] [value]", c)
+				}
+				connectionsString := split[0]
+				if connection, ok := connections[connectionsString]; !ok {
+					return errors.Errorf("%s not connected", connectionsString)
+				} else {
+					start := time.Now()
+					writeRequest, err := connection.WriteRequestBuilder().
+						AddQuery("writeField", split[1], split[2]).
+						Build()
+					if err != nil {
+						return errors.Wrapf(err, "%s can't write", connectionsString)
+					}
+					writeRequestResult := <-writeRequest.Execute()
+					if err := writeRequestResult.GetErr(); err != nil {
+						return errors.Wrapf(err, "%s can't write", 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 reading", 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.
+
+						}
+					} else {
+						entries = append(entries, connectionsString)
+					}
+				}
+				return
+			},
+		},
 		{
 			Name:        "register",
 			Description: "register a driver in the subsystem",