Skip to content
This repository has been archived by the owner on Sep 5, 2022. It is now read-only.

Commit

Permalink
Switch to github.com/Duet3D/DSF-APIs/godsfapi
Browse files Browse the repository at this point in the history
Add new trace parameter to enable debugging output in godsfapi
Ignore codes that have been received but had decoding errors
  • Loading branch information
wilriker committed Apr 6, 2020
1 parent e67922a commit d63cb0f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
12 changes: 9 additions & 3 deletions cmd/eom/execonmcode.go
Expand Up @@ -4,30 +4,36 @@ import (
"flag"
"log"

"github.com/Duet3D/DSF-APIs/godsfapi/connection"
"github.com/wilriker/execonmcode"
"github.com/wilriker/goduetapiclient/connection"
)

type settings struct {
socketPath string
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)
}
}
24 changes: 16 additions & 8 deletions executor.go
Expand Up @@ -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 (
Expand All @@ -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
Expand All @@ -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()

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions 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
12 changes: 2 additions & 10 deletions 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=

0 comments on commit d63cb0f

Please sign in to comment.