From d63cb0fd830239b8ed46eb77833771fa20f234ca Mon Sep 17 00:00:00 2001 From: Manuel Coenen Date: Mon, 6 Apr 2020 11:14:18 +0200 Subject: [PATCH] Switch to github.com/Duet3D/DSF-APIs/godsfapi Add new trace parameter to enable debugging output in godsfapi Ignore codes that have been received but had decoding errors --- cmd/eom/execonmcode.go | 12 +++++++++--- executor.go | 24 ++++++++++++++++-------- go.mod | 4 ++-- go.sum | 12 ++---------- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/cmd/eom/execonmcode.go b/cmd/eom/execonmcode.go index 04fcef3..583b8a3 100644 --- a/cmd/eom/execonmcode.go +++ b/cmd/eom/execonmcode.go @@ -4,8 +4,8 @@ import ( "flag" "log" + "github.com/Duet3D/DSF-APIs/godsfapi/connection" "github.com/wilriker/execonmcode" - "github.com/wilriker/goduetapiclient/connection" ) type settings struct { @@ -13,21 +13,27 @@ type settings struct { mCodes execonmcode.MCodes commands execonmcode.Commands debug bool + trace bool } func main() { + s := settings{} flag.StringVar(&s.socketPath, "socketPath", connection.FullSocketPath, "Path to socket") flag.Var(&s.mCodes, "mCode", "Code that will initiate execution of the command") flag.Var(&s.commands, "command", "Command to execute") flag.BoolVar(&s.debug, "debug", false, "Print debug output") + flag.BoolVar(&s.trace, "trace", false, "Print underlying requests/responses") flag.Parse() if s.mCodes.Len() != s.commands.Len() { log.Fatal("Unequal amount of M-codes and commands given") } - e := execonmcode.NewExecutor(s.socketPath, s.commands, s.mCodes, s.debug) - e.Run() + e := execonmcode.NewExecutor(s.socketPath, s.commands, s.mCodes, s.debug, s.trace) + err := e.Run() + if err != nil { + log.Fatal(err) + } } diff --git a/executor.go b/executor.go index fa21160..429670b 100644 --- a/executor.go +++ b/executor.go @@ -7,10 +7,10 @@ import ( "os/exec" "strings" - "github.com/wilriker/goduetapiclient/commands" - "github.com/wilriker/goduetapiclient/connection" - "github.com/wilriker/goduetapiclient/connection/initmessages" - "github.com/wilriker/goduetapiclient/types" + "github.com/Duet3D/DSF-APIs/godsfapi/commands" + "github.com/Duet3D/DSF-APIs/godsfapi/connection" + "github.com/Duet3D/DSF-APIs/godsfapi/connection/initmessages" + "github.com/Duet3D/DSF-APIs/godsfapi/types" ) const ( @@ -22,9 +22,10 @@ type Executor struct { mCodes map[int64]int commands Commands debug bool + trace bool } -func NewExecutor(socketPath string, commands Commands, mCodes MCodes, debug bool) *Executor { +func NewExecutor(socketPath string, commands Commands, mCodes MCodes, debug, trace bool) *Executor { mc := make(map[int64]int) for i, m := range mCodes { mc[m] = i @@ -41,15 +42,17 @@ func NewExecutor(socketPath string, commands Commands, mCodes MCodes, debug bool mCodes: mc, commands: commands, debug: debug, + trace: trace, } } -func (e *Executor) Run() { +func (e *Executor) Run() error { ic := connection.InterceptConnection{} + ic.Debug = e.trace err := ic.Connect(initmessages.InterceptionModePre, e.socketPath) if err != nil { - log.Fatal(err) + return err } defer ic.Close() @@ -58,7 +61,12 @@ func (e *Executor) Run() { if err != nil { if err == io.EOF { log.Println("Connection to DCS closed") - break + return err + } + if _, ok := err.(*connection.DecodeError); ok { + // If it is "just" a problem with decoding ignore the received code + // as it otherwise will block DCS + ic.IgnoreCode() } log.Printf("Error receiving code: %s", err) continue diff --git a/go.mod b/go.mod index 20b8245..2a01c22 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module github.com/wilriker/execonmcode -go 1.13 +go 1.14 -require github.com/wilriker/goduetapiclient v1.2.0 +require github.com/Duet3D/DSF-APIs/godsfapi v0.0.0-20200406084749-1671ee2a95ae diff --git a/go.sum b/go.sum index 3fa1965..1920e7a 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,2 @@ -github.com/wilriker/goduetapiclient v0.0.0-20191014112126-94a17c5b2e4c h1:kbeSWusNKHJYqPLLUn3UqBsgUw+fqTLGBYqhiVfCvhQ= -github.com/wilriker/goduetapiclient v0.0.0-20191014112126-94a17c5b2e4c/go.mod h1:KSadGbt2Z/wbyhZoh3I+Zp0me9YqrLhAPrAjH9J8OLM= -github.com/wilriker/goduetapiclient v0.0.0-20191213105344-41ea5d36085a h1:jlWEyWAq7VTVxZo6SxywPjmZkEanBFhnfvzwgmh5KxA= -github.com/wilriker/goduetapiclient v0.0.0-20191213105344-41ea5d36085a/go.mod h1:KSadGbt2Z/wbyhZoh3I+Zp0me9YqrLhAPrAjH9J8OLM= -github.com/wilriker/goduetapiclient v1.1.0 h1:s2ufoNPyEZ8QxP7lY0COMfDGRf1A6x/xPxEdsoT9cGA= -github.com/wilriker/goduetapiclient v1.1.0/go.mod h1:KSadGbt2Z/wbyhZoh3I+Zp0me9YqrLhAPrAjH9J8OLM= -github.com/wilriker/goduetapiclient v1.1.1-0.20191226195316-8e83bd8e4124 h1:YApThH1QQk1QShCc82Crj7aSiDXtWJdxS39kOFiU61c= -github.com/wilriker/goduetapiclient v1.1.1-0.20191226195316-8e83bd8e4124/go.mod h1:KSadGbt2Z/wbyhZoh3I+Zp0me9YqrLhAPrAjH9J8OLM= -github.com/wilriker/goduetapiclient v1.2.0 h1:lB5owgJVYpTeMjWcT6slQwKXQgPgrzCdHdeNIv80JCo= -github.com/wilriker/goduetapiclient v1.2.0/go.mod h1:KSadGbt2Z/wbyhZoh3I+Zp0me9YqrLhAPrAjH9J8OLM= +github.com/Duet3D/DSF-APIs/godsfapi v0.0.0-20200406084749-1671ee2a95ae h1:+T8uabIU7Tp8alI/II5MdX9W3iSLYWOsH5bhbw225Yk= +github.com/Duet3D/DSF-APIs/godsfapi v0.0.0-20200406084749-1671ee2a95ae/go.mod h1:Pr9LdwVqZpjqHTUKaWmzCCWzk2jn1QaLTPaDF6UKlWo=