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

Commit d63cb0f

Browse files
committed
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
1 parent e67922a commit d63cb0f

4 files changed

Lines changed: 29 additions & 23 deletions

File tree

cmd/eom/execonmcode.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,36 @@ import (
44
"flag"
55
"log"
66

7+
"github.com/Duet3D/DSF-APIs/godsfapi/connection"
78
"github.com/wilriker/execonmcode"
8-
"github.com/wilriker/goduetapiclient/connection"
99
)
1010

1111
type settings struct {
1212
socketPath string
1313
mCodes execonmcode.MCodes
1414
commands execonmcode.Commands
1515
debug bool
16+
trace bool
1617
}
1718

1819
func main() {
20+
1921
s := settings{}
2022

2123
flag.StringVar(&s.socketPath, "socketPath", connection.FullSocketPath, "Path to socket")
2224
flag.Var(&s.mCodes, "mCode", "Code that will initiate execution of the command")
2325
flag.Var(&s.commands, "command", "Command to execute")
2426
flag.BoolVar(&s.debug, "debug", false, "Print debug output")
27+
flag.BoolVar(&s.trace, "trace", false, "Print underlying requests/responses")
2528
flag.Parse()
2629

2730
if s.mCodes.Len() != s.commands.Len() {
2831
log.Fatal("Unequal amount of M-codes and commands given")
2932
}
3033

31-
e := execonmcode.NewExecutor(s.socketPath, s.commands, s.mCodes, s.debug)
32-
e.Run()
34+
e := execonmcode.NewExecutor(s.socketPath, s.commands, s.mCodes, s.debug, s.trace)
35+
err := e.Run()
36+
if err != nil {
37+
log.Fatal(err)
38+
}
3339
}

executor.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
"os/exec"
88
"strings"
99

10-
"github.com/wilriker/goduetapiclient/commands"
11-
"github.com/wilriker/goduetapiclient/connection"
12-
"github.com/wilriker/goduetapiclient/connection/initmessages"
13-
"github.com/wilriker/goduetapiclient/types"
10+
"github.com/Duet3D/DSF-APIs/godsfapi/commands"
11+
"github.com/Duet3D/DSF-APIs/godsfapi/connection"
12+
"github.com/Duet3D/DSF-APIs/godsfapi/connection/initmessages"
13+
"github.com/Duet3D/DSF-APIs/godsfapi/types"
1414
)
1515

1616
const (
@@ -22,9 +22,10 @@ type Executor struct {
2222
mCodes map[int64]int
2323
commands Commands
2424
debug bool
25+
trace bool
2526
}
2627

27-
func NewExecutor(socketPath string, commands Commands, mCodes MCodes, debug bool) *Executor {
28+
func NewExecutor(socketPath string, commands Commands, mCodes MCodes, debug, trace bool) *Executor {
2829
mc := make(map[int64]int)
2930
for i, m := range mCodes {
3031
mc[m] = i
@@ -41,15 +42,17 @@ func NewExecutor(socketPath string, commands Commands, mCodes MCodes, debug bool
4142
mCodes: mc,
4243
commands: commands,
4344
debug: debug,
45+
trace: trace,
4446
}
4547
}
4648

47-
func (e *Executor) Run() {
49+
func (e *Executor) Run() error {
4850

4951
ic := connection.InterceptConnection{}
52+
ic.Debug = e.trace
5053
err := ic.Connect(initmessages.InterceptionModePre, e.socketPath)
5154
if err != nil {
52-
log.Fatal(err)
55+
return err
5356
}
5457
defer ic.Close()
5558

@@ -58,7 +61,12 @@ func (e *Executor) Run() {
5861
if err != nil {
5962
if err == io.EOF {
6063
log.Println("Connection to DCS closed")
61-
break
64+
return err
65+
}
66+
if _, ok := err.(*connection.DecodeError); ok {
67+
// If it is "just" a problem with decoding ignore the received code
68+
// as it otherwise will block DCS
69+
ic.IgnoreCode()
6270
}
6371
log.Printf("Error receiving code: %s", err)
6472
continue

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/wilriker/execonmcode
22

3-
go 1.13
3+
go 1.14
44

5-
require github.com/wilriker/goduetapiclient v1.2.0
5+
require github.com/Duet3D/DSF-APIs/godsfapi v0.0.0-20200406084749-1671ee2a95ae

go.sum

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
1-
github.com/wilriker/goduetapiclient v0.0.0-20191014112126-94a17c5b2e4c h1:kbeSWusNKHJYqPLLUn3UqBsgUw+fqTLGBYqhiVfCvhQ=
2-
github.com/wilriker/goduetapiclient v0.0.0-20191014112126-94a17c5b2e4c/go.mod h1:KSadGbt2Z/wbyhZoh3I+Zp0me9YqrLhAPrAjH9J8OLM=
3-
github.com/wilriker/goduetapiclient v0.0.0-20191213105344-41ea5d36085a h1:jlWEyWAq7VTVxZo6SxywPjmZkEanBFhnfvzwgmh5KxA=
4-
github.com/wilriker/goduetapiclient v0.0.0-20191213105344-41ea5d36085a/go.mod h1:KSadGbt2Z/wbyhZoh3I+Zp0me9YqrLhAPrAjH9J8OLM=
5-
github.com/wilriker/goduetapiclient v1.1.0 h1:s2ufoNPyEZ8QxP7lY0COMfDGRf1A6x/xPxEdsoT9cGA=
6-
github.com/wilriker/goduetapiclient v1.1.0/go.mod h1:KSadGbt2Z/wbyhZoh3I+Zp0me9YqrLhAPrAjH9J8OLM=
7-
github.com/wilriker/goduetapiclient v1.1.1-0.20191226195316-8e83bd8e4124 h1:YApThH1QQk1QShCc82Crj7aSiDXtWJdxS39kOFiU61c=
8-
github.com/wilriker/goduetapiclient v1.1.1-0.20191226195316-8e83bd8e4124/go.mod h1:KSadGbt2Z/wbyhZoh3I+Zp0me9YqrLhAPrAjH9J8OLM=
9-
github.com/wilriker/goduetapiclient v1.2.0 h1:lB5owgJVYpTeMjWcT6slQwKXQgPgrzCdHdeNIv80JCo=
10-
github.com/wilriker/goduetapiclient v1.2.0/go.mod h1:KSadGbt2Z/wbyhZoh3I+Zp0me9YqrLhAPrAjH9J8OLM=
1+
github.com/Duet3D/DSF-APIs/godsfapi v0.0.0-20200406084749-1671ee2a95ae h1:+T8uabIU7Tp8alI/II5MdX9W3iSLYWOsH5bhbw225Yk=
2+
github.com/Duet3D/DSF-APIs/godsfapi v0.0.0-20200406084749-1671ee2a95ae/go.mod h1:Pr9LdwVqZpjqHTUKaWmzCCWzk2jn1QaLTPaDF6UKlWo=

0 commit comments

Comments
 (0)