From 7d880ddee4065b4b7538692e43862173b4ade36d Mon Sep 17 00:00:00 2001 From: Manuel Coenen Date: Wed, 22 Apr 2020 15:36:39 +0200 Subject: [PATCH] Update to godsfapi 2.1.0 --- cmd/eom/execonmcode.go | 13 ++++++++++++- executor.go | 22 ++++++++++++++-------- go.mod | 2 +- go.sum | 9 +++++++-- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/cmd/eom/execonmcode.go b/cmd/eom/execonmcode.go index 583b8a3..9df9622 100644 --- a/cmd/eom/execonmcode.go +++ b/cmd/eom/execonmcode.go @@ -3,11 +3,16 @@ package main import ( "flag" "log" + "os" - "github.com/Duet3D/DSF-APIs/godsfapi/connection" + "github.com/Duet3D/DSF-APIs/godsfapi/v2/connection" "github.com/wilriker/execonmcode" ) +const ( + version = "5.0" +) + type settings struct { socketPath string mCodes execonmcode.MCodes @@ -25,8 +30,14 @@ func main() { 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") + version := flag.Bool("version", false, "Show version and exit") flag.Parse() + if *version { + log.Println(version) + os.Exit(0) + } + if s.mCodes.Len() != s.commands.Len() { log.Fatal("Unequal amount of M-codes and commands given") } diff --git a/executor.go b/executor.go index 429670b..cfba1a0 100644 --- a/executor.go +++ b/executor.go @@ -7,10 +7,10 @@ import ( "os/exec" "strings" - "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" + "github.com/Duet3D/DSF-APIs/godsfapi/v2/commands" + "github.com/Duet3D/DSF-APIs/godsfapi/v2/connection" + "github.com/Duet3D/DSF-APIs/godsfapi/v2/connection/initmessages" + "github.com/Duet3D/DSF-APIs/godsfapi/v2/machine/messages" ) const ( @@ -71,15 +71,21 @@ func (e *Executor) Run() error { log.Printf("Error receiving code: %s", err) continue } - if c.Type == types.MCode && c.MajorNumber != nil { + if c.Type == commands.MCode && c.MajorNumber != nil { i, ok := e.mCodes[*c.MajorNumber] if !ok { ic.IgnoreCode() continue } + success, err := ic.Flush(c.Channel) + if !success || err != nil { + log.Println("Could not Flush. Cancelling code") + ic.CancelCode() + continue + } comd, a, err := e.commands.Get(i) if err != nil { - ic.ResolveCode(types.Error, err.Error()) + ic.ResolveCode(messages.Error, err.Error()) } else { cmd := exec.Command(comd, e.getArgs(c, a)...) if e.debug { @@ -87,9 +93,9 @@ func (e *Executor) Run() error { } output, err := cmd.CombinedOutput() if err != nil { - err = ic.ResolveCode(types.Error, fmt.Sprintf("%s: %s", err.Error(), string(output))) + err = ic.ResolveCode(messages.Error, fmt.Sprintf("%s: %s", err.Error(), string(output))) } else { - err = ic.ResolveCode(types.Success, "") + err = ic.ResolveCode(messages.Success, "") } if err != nil { log.Println("Error executing command:", err) diff --git a/go.mod b/go.mod index 2a01c22..a96c3fb 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/wilriker/execonmcode go 1.14 -require github.com/Duet3D/DSF-APIs/godsfapi v0.0.0-20200406084749-1671ee2a95ae +require github.com/Duet3D/DSF-APIs/godsfapi/v2 v2.0.0-20200422123133-670706fea346 diff --git a/go.sum b/go.sum index 1920e7a..52812b2 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,7 @@ -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= +github.com/Duet3D/DSF-APIs v1.2.4 h1:J5ez7gAEzQdxqLMgBy2+EY5xCQIlDJM+Xt0HR80+L/0= +github.com/Duet3D/DSF-APIs v2.1.0+incompatible h1:UW9VZATPRJRXvbP1vBpiNL9S/iUzTucB0C6n95jXamA= +github.com/Duet3D/DSF-APIs/godsfapi v0.0.0-20200422123133-670706fea346 h1:Qjo7CFDbeW2cVjn/iBbbx3gcjecHPKiWDcpkVDdADTg= +github.com/Duet3D/DSF-APIs/godsfapi/v2 v2.0.0-20200422123133-670706fea346 h1:wC9h+UN3xETa7xlkEAJyvBwpfVD2zB7H1d4kvni49bw= +github.com/Duet3D/DSF-APIs/godsfapi/v2 v2.0.0-20200422123133-670706fea346/go.mod h1:4MbBdIOM6SlzCSvtSjpeAj2S62ANmW0fFHeOk8SpjXw= +github.com/mitchellh/mapstructure v1.2.2 h1:dxe5oCinTXiTIcfgmZecdCzPmAJKd46KsCWc35r0TV4= +github.com/mitchellh/mapstructure v1.2.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=