Skip to content

Commit

Permalink
feat: Moving to a callback-based system (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: Russ Daniels <[email protected]>
  • Loading branch information
deregtd and inquestruss authored Oct 7, 2023
1 parent 667d20b commit c4ed510
Show file tree
Hide file tree
Showing 27 changed files with 714 additions and 656 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
with:
Expand All @@ -22,7 +22,7 @@ jobs:
name: go test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

### ASDF Logic
- name: Setup asdf
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
bin

# Binaries for programs and plugins
*.exe
*.exe~
Expand All @@ -13,3 +15,6 @@

# Dependency directories (remove the comment below to include it)
# vendor/

canboatjson.cache

2 changes: 0 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
golang 1.21.1
nodejs 18.18.0
balena-cli 17.1.2
golangci-lint 1.54.2
mage 1.15.0
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ testfast: machine-deps
codegen: machine-deps
@mage -v codegen


.PHONY: clean
clean: machine-deps
@mage clean
2 changes: 1 addition & 1 deletion cmd/pgngen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (conv *canboatConverter) write() {
}).Parse(pgninfoTemplate))

templateData := struct {
PGNDoc interface{}
PGNDoc any
}{
PGNDoc: conv,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/pgngen/templates/pgninfo.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ type {{ .Id }}Repeating2 struct {
}
{{- end }}
{{- $funcName := concat "Decode" .Id }}
func {{ $funcName }}(Info MessageInfo, stream *PGNDataStream) (interface{}, error) {
func {{ $funcName }}(Info MessageInfo, stream *PGNDataStream) (any, error) {
var val {{ .Id }}
val.Info = Info

Expand Down
58 changes: 21 additions & 37 deletions cmd/replay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,24 @@ package main

import (
// "context"
"context"
"flag"
"os"
"strings"
"sync"

// "time"

"github.com/boatkit-io/n2k/pkg/adapter"
"github.com/boatkit-io/n2k/pkg/adapter/canadapter"
"github.com/boatkit-io/n2k/pkg/endpoint"
"github.com/boatkit-io/n2k/pkg/endpoint/n2kendpoint"
"github.com/boatkit-io/n2k/pkg/endpoint/n2kfileendpoint"
"github.com/boatkit-io/n2k/pkg/pgn"
"github.com/boatkit-io/n2k/pkg/pkt"
"github.com/boatkit-io/n2k/pkg/subscribe"

// "github.com/boatkit-io/tugboat/pkg/service"
"github.com/sirupsen/logrus"
)

func main() {
var exitCode int
var activities = new(sync.WaitGroup)
var n endpoint.Endpoint
var p adapter.Adapter
defer func() {
os.Exit(exitCode)
}()
Expand All @@ -39,43 +33,33 @@ func main() {

log := logrus.StandardLogger()
log.Infof("in replayfile, dump:%t, file:%s\n", dumpPgns, replayFile)

subs := subscribe.New()
s := pkt.NewPacketStruct()
h := pgn.NewStructHandler(s.OutChannel(), subs)
go func() {
if dumpPgns {
_, _ = subs.SubscribeToAllStructs(func(p any) {
log.Infof("Handling PGN: %s", pgn.DebugDumpPGN(p))
})
}
}()

ps := pkt.NewPacketStruct()
ps.SetOutput(subs)

// ctx, cancel := context.WithCancel(context.Background())
// defer cancel()
if len(replayFile) > 0 && strings.HasSuffix(replayFile, ".n2k") {
n = n2kendpoint.NewN2kEndpoint(replayFile, log)
p = canadapter.NewCanAdapter(log)
p.SetInChannel(n.OutChannel())
p.SetOutChannel(s.InChannel())
activities.Add(5)
h.Run(activities)
s.Run(activities)
err := p.Run(activities)
if err != nil {
exitCode = 1
return
}
err = n.Run(activities)
ca := canadapter.NewCANAdapter(log)
ca.SetOutput(ps)

ep := n2kfileendpoint.NewN2kFileEndpoint(replayFile, log)
ep.SetOutput(ca)

ctx := context.Background()
err := ep.Run(ctx)
if err != nil {
exitCode = 1
return
}
}

go func() {

defer activities.Done()

if dumpPgns {
_, _ = subs.SubscribeToAllStructs(func(p interface{}) {
log.Infof("Handling PGN: %s", pgn.DebugDumpPGN(p))
})
}
}()

activities.Wait()

}
48 changes: 28 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
module github.com/boatkit-io/n2k

go 1.19
go 1.21

toolchain go1.21.1

require (
github.com/Masterminds/sprig/v3 v3.2.2
github.com/Masterminds/sprig/v3 v3.2.3
github.com/boatkit-io/tugboat v0.5.1
github.com/brutella/can v0.0.2
github.com/magefile/mage v1.14.0
github.com/magefile/mage v1.15.0
github.com/pkg/errors v0.9.1
github.com/schollz/progressbar/v3 v3.12.1
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.1
golang.org/x/text v0.4.0
github.com/schollz/progressbar/v3 v3.13.1
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.4
golang.org/x/text v0.13.0
)

require (
github.com/vishvananda/netlink v1.2.1-beta.2.0.20221214185949-378a404a26f0 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
)

require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/huandu/xstrings v1.3.1 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.2 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/term v0.1.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.1 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit c4ed510

Please sign in to comment.