From a8e54a6a33d26cd4a4cf5a2c731f1b1e0367b960 Mon Sep 17 00:00:00 2001 From: Morgan Larsson Date: Thu, 16 Jun 2022 11:07:09 +0200 Subject: [PATCH] chore: update to sage --- .github/dependabot.yml | 5 ++ .github/workflows/ci.yaml | 20 +++--- .github/workflows/release.yml | 25 ++++++++ .golangci.yml | 30 --------- .sage/go.mod | 5 ++ .sage/go.sum | 2 + .sage/sagefile.go | 82 ++++++++++++++++++++++++ Makefile | 116 +++++++++++++++++----------------- README.md | 21 ++++-- cmd/settings/main.go | 2 +- cmd/streaming/main.go | 4 +- commands.go | 54 ++++++++-------- go.mod | 2 +- packet.go | 10 +-- parameters.go | 4 +- pkg/discover/discover.go | 4 +- pkg/packets/timecode.go | 6 +- protocol.go | 20 +++--- tools/golangci-lint/rules.mk | 27 -------- tools/goreview/rules.mk | 27 -------- tools/stringer/go.mod | 10 --- tools/stringer/go.sum | 24 ------- tools/stringer/rules.mk | 8 --- tools/stringer/tool.go | 5 -- 24 files changed, 253 insertions(+), 260 deletions(-) create mode 100644 .github/workflows/release.yml delete mode 100644 .golangci.yml create mode 100644 .sage/go.mod create mode 100644 .sage/go.sum create mode 100644 .sage/sagefile.go delete mode 100644 tools/golangci-lint/rules.mk delete mode 100644 tools/goreview/rules.mk delete mode 100644 tools/stringer/go.mod delete mode 100644 tools/stringer/go.sum delete mode 100644 tools/stringer/rules.mk delete mode 100644 tools/stringer/tool.go diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 288303f..2125d89 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,3 +6,8 @@ updates: schedule: interval: "weekly" day: "monday" + + - package-ecosystem: gomod + directory: .sage + schedule: + interval: weekly diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d4d8a3c..c7cd509 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,24 +1,24 @@ -name: CI +name: ci on: push: branches: - master pull_request: - branches: - - "*" + types: [opened, reopened, synchronize] + +env: + GOPRIVATE: github.com/einride/* jobs: - make: + build: runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2.3.5 - - name: Setup Go - uses: actions/setup-go@v2.1.4 + steps: + - name: Setup Sage + uses: einride/sage/actions/setup@master with: - go-version: ^1.17 + go-version: 1.18 - name: Make run: make diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b22d14b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,25 @@ +name: Release + +on: + push: + branches: [master] + +permissions: write-all + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Setup Sage + uses: einride/sage/actions/setup@master + with: + go-version: 1.18 + + - name: Make + run: make + + - name: Release + uses: go-semantic-release/action@v1.18 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + allow-initial-development-versions: true diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index 7b3a7f3..0000000 --- a/.golangci.yml +++ /dev/null @@ -1,30 +0,0 @@ -run: - timeout: 5m - -linters: - enable-all: true - disable: - - dupl # allow duplication - - funlen # allow long functions - - testpackage # unwanted convention - - gomnd # allow some magic numbers - - wsl # unwanted amount of whitespace - - godox # allow TODOs - - interfacer # deprecated by the author for having too many false positives - - gocognit # allow higher cognitive complexity - - nestif # allow deep nesting - - paralleltest # code is not thread safe so skip parallel testing demands. - - unparam # allow constant parameters - - goerr113 # allow "dynamic" errors - - nlreturn # don't enforce whitespace before return - - wrapcheck # don't enforce error wrapping - - exhaustivestruct # don't require exhaustive structs - - durationcheck # has false positives - - maligned # deprecated - - scopelint # deprecated - - golint # deprecated - - exhaustive # unwanted - -linters-settings: - cyclop: - max-complexity: 20 diff --git a/.sage/go.mod b/.sage/go.mod new file mode 100644 index 0000000..a0159f0 --- /dev/null +++ b/.sage/go.mod @@ -0,0 +1,5 @@ +module sage + +go 1.18 + +require go.einride.tech/sage v0.116.0 diff --git a/.sage/go.sum b/.sage/go.sum new file mode 100644 index 0000000..8315bdd --- /dev/null +++ b/.sage/go.sum @@ -0,0 +1,2 @@ +go.einride.tech/sage v0.116.0 h1:Z1ru00FnZ5ew4Wyni9tfbbcerzgZJ2nQa9n4Y01Uj88= +go.einride.tech/sage v0.116.0/go.mod h1:EzV5uciFX7/2ho8EKB5K9JghOfXIxlzs694b+Tkl5GQ= diff --git a/.sage/sagefile.go b/.sage/sagefile.go new file mode 100644 index 0000000..ed6e658 --- /dev/null +++ b/.sage/sagefile.go @@ -0,0 +1,82 @@ +package main + +import ( + "context" + + "go.einride.tech/sage/sg" + "go.einride.tech/sage/sgtool" + "go.einride.tech/sage/tools/sgconvco" + "go.einride.tech/sage/tools/sggit" + "go.einride.tech/sage/tools/sggo" + "go.einride.tech/sage/tools/sggolangcilint" + "go.einride.tech/sage/tools/sggoreview" + "go.einride.tech/sage/tools/sgmarkdownfmt" + "go.einride.tech/sage/tools/sgyamlfmt" +) + +func main() { + sg.GenerateMakefiles( + sg.Makefile{ + Path: sg.FromGitRoot("Makefile"), + DefaultTarget: All, + }, + ) +} + +func All(ctx context.Context) error { + sg.Deps(ctx, ConvcoCheck, GoGenerate, GoLint, GoReview, GoTest, FormatMarkdown, FormatYAML) + sg.SerialDeps(ctx, GoModTidy, GitVerifyNoDiff) + return nil +} + +func FormatYAML(ctx context.Context) error { + sg.Logger(ctx).Println("formatting YAML files...") + return sgyamlfmt.Command(ctx, "-d", sg.FromGitRoot(), "-r").Run() +} + +func GoModTidy(ctx context.Context) error { + sg.Logger(ctx).Println("tidying Go module files...") + return sg.Command(ctx, "go", "mod", "tidy", "-v").Run() +} + +func GoTest(ctx context.Context) error { + sg.Logger(ctx).Println("running Go tests...") + return sggo.TestCommand(ctx).Run() +} + +func GoReview(ctx context.Context) error { + sg.Logger(ctx).Println("reviewing Go files...") + return sggoreview.Command(ctx, "-c", "1", "./...").Run() +} + +func GoLint(ctx context.Context) error { + sg.Logger(ctx).Println("linting Go files...") + return sggolangcilint.Run(ctx) +} + +func FormatMarkdown(ctx context.Context) error { + sg.Logger(ctx).Println("formatting Markdown files...") + return sgmarkdownfmt.Command(ctx, "-w", ".").Run() +} + +func ConvcoCheck(ctx context.Context) error { + sg.Logger(ctx).Println("checking git commits...") + return sgconvco.Command(ctx, "check", "origin/master..HEAD").Run() +} + +func GitVerifyNoDiff(ctx context.Context) error { + sg.Logger(ctx).Println("verifying that git has no diff...") + return sggit.VerifyNoDiff(ctx) +} + +func Stringer(ctx context.Context) error { + sg.Logger(ctx).Println("building...") + _, err := sgtool.GoInstall(ctx, "golang.org/x/tools/cmd/stringer", "v0.1.10") + return err +} + +func GoGenerate(ctx context.Context) error { + sg.Deps(ctx, Stringer) + sg.Logger(ctx).Println("generating Go code...") + return sg.Command(ctx, "go", "generate", "./...").Run() +} diff --git a/Makefile b/Makefile index 4ca242e..2ae6c9f 100644 --- a/Makefile +++ b/Makefile @@ -1,68 +1,66 @@ -export GO111MODULE := on -export GOPRIVATE := github.com/mlveggo/* +# Code generated by go.einride.tech/sage. DO NOT EDIT. +# To learn more, see .sage/sagefile.go and https://github.com/einride/sage. + +.DEFAULT_GOAL := all + +sagefile := .sage/bin/sagefile + +$(sagefile): .sage/go.mod .sage/*.go + @cd .sage && go mod tidy && go run . + +.PHONY: sage +sage: + @git clean -fxq $(sagefile) + @$(MAKE) $(sagefile) + +.PHONY: update-sage +update-sage: + @cd .sage && go get -d go.einride.tech/sage@latest && go mod tidy && go run . + +.PHONY: clean-sage +clean-sage: + @git clean -fdx .sage/tools .sage/bin .sage/build .PHONY: all -all: \ - go-generate \ - go-fmt \ - go-mod-tidy \ - go-vet \ - go-review \ - go-lint \ - go-test \ - -include tools/golangci-lint/rules.mk -include tools/goreview/rules.mk -include tools/stringer/rules.mk - -.PHONY: clean -clean: - rm -rf build +all: $(sagefile) + @$(sagefile) All -.PHONY: go-mod-tidy -go-mod-tidy: - go mod tidy -v +.PHONY: convco-check +convco-check: $(sagefile) + @$(sagefile) ConvcoCheck -.PHONY: go-fmt -go-fmt: - go fmt ./... +.PHONY: format-markdown +format-markdown: $(sagefile) + @$(sagefile) FormatMarkdown -.PHONY: go-vet -go-vet: - go vet ./... +.PHONY: format-yaml +format-yaml: $(sagefile) + @$(sagefile) FormatYAML -.PHONY: go-test -go-test: - go test -race -cover ./... +.PHONY: git-verify-no-diff +git-verify-no-diff: $(sagefile) + @$(sagefile) GitVerifyNoDiff .PHONY: go-generate -go-generate: \ - protocol_string.go \ - commands_string.go \ - parameters_string.go \ - packet_string.go \ - file_string.go \ - pkg/packets/timecode_string.go \ - pkg/packets/image_string.go - -%_string.go: %.go $(stringer) - $(info generating $@...) - @go generate ./$< - -.PHONY: go-build -go-build: - mkdir build - go build -o build ./... - -.PHONY: run -run: - go run cmd/streaming/main.go - -.PHONY: run-discover -run-discover: - go run cmd/discover/main.go - -.PHONY: run-settings -run-settings: - go run cmd/settings/main.go +go-generate: $(sagefile) + @$(sagefile) GoGenerate + +.PHONY: go-lint +go-lint: $(sagefile) + @$(sagefile) GoLint + +.PHONY: go-mod-tidy +go-mod-tidy: $(sagefile) + @$(sagefile) GoModTidy + +.PHONY: go-review +go-review: $(sagefile) + @$(sagefile) GoReview + +.PHONY: go-test +go-test: $(sagefile) + @$(sagefile) GoTest +.PHONY: stringer +stringer: $(sagefile) + @$(sagefile) Stringer diff --git a/README.md b/README.md index aed4c2b..39fec7d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,11 @@ -# qualisys-go -Go sdk for Qualisys Track Manager streaming of motion capture data. +qualisys-go +=========== + +Go sdk for Qualisys Track Manager streaming of motion capture data. + +Discovery example +----------------- -## Discovery example ```Go package main @@ -25,7 +29,10 @@ func main() { } ``` -## Issues -- It should always fail to connect to older QTM version (Support 1.22 and upwards) -- StreamFrames - Missing support for [:channels] handling. -- Makefile doesn't work on Windows (golangci-lint/goreview handling) \ No newline at end of file +Issues +------ + +- It should always fail to connect to older QTM version (Support 1.22 and upwards) +- StreamFrames - Missing support for \[:channels] handling. +- Makefile doesn't work on Windows (golangci-lint/goreview handling) +- Support passing in an context.Context in NewProtocol() diff --git a/cmd/settings/main.go b/cmd/settings/main.go index 57ae98f..8880f95 100644 --- a/cmd/settings/main.go +++ b/cmd/settings/main.go @@ -23,7 +23,7 @@ func main() { break } } - rt := qualisys.NewRtProtocol(ip, basePort) + rt := qualisys.NewProtocol(ip, basePort) log.Println("Connecting to:", ip) if err := rt.Connect(); err != nil { log.Println(err) diff --git a/cmd/streaming/main.go b/cmd/streaming/main.go index f4e6552..e361da2 100644 --- a/cmd/streaming/main.go +++ b/cmd/streaming/main.go @@ -10,7 +10,7 @@ import ( "github.com/mlveggo/qualisys-go/pkg/discover" ) -func HandlePackets(p *qualisys.RtPacket) { +func HandlePackets(p *qualisys.Packet) { switch p.Type { case qualisys.PacketTypeEvent: log.Println("Event:", p.Event) @@ -42,7 +42,7 @@ func main() { ip = os.Args[1] } log.Println("Connecting to: ", ip) - rt := qualisys.NewRtProtocol(ip, basePort) + rt := qualisys.NewProtocol(ip, basePort) parametersFetched := false streaming := false for { diff --git a/commands.go b/commands.go index 9fc80f8..1691ea8 100644 --- a/commands.go +++ b/commands.go @@ -9,7 +9,7 @@ import ( type senderType func(string) error -func (rt *RtProtocol) sendCommand(cmd string) error { +func (rt *Protocol) sendCommand(cmd string) error { if !rt.IsConnected() { return fmt.Errorf("sendcommand: not connected") } @@ -25,7 +25,7 @@ func (rt *RtProtocol) sendCommand(cmd string) error { return nil } -func (rt *RtProtocol) sendXML(cmd string) error { +func (rt *Protocol) sendXML(cmd string) error { if !rt.IsConnected() { return fmt.Errorf("sendxml: not connected") } @@ -41,7 +41,7 @@ func (rt *RtProtocol) sendXML(cmd string) error { return nil } -func (rt *RtProtocol) SetVersion(major int, minor int) error { +func (rt *Protocol) SetVersion(major, minor int) error { ver := strconv.Itoa(major) + "." + strconv.Itoa(minor) cmd := "Version " + ver qtmResponses := []string{"Version set to " + ver} @@ -52,7 +52,7 @@ func (rt *RtProtocol) SetVersion(major int, minor int) error { } // GetState makes QTM send the current state as an event. -func (rt *RtProtocol) GetState() error { +func (rt *Protocol) GetState() error { cmd := "GetState" if err := rt.sendCommand(cmd); err != nil { return fmt.Errorf("getstate: %w", err) @@ -69,7 +69,7 @@ const ( StreamRateTypeFrequencyDivisor ) -func (rt RtProtocol) getComponentString(c ComponentType) string { +func (rt Protocol) getComponentString(c ComponentType) string { componentsToString := map[ComponentType]string{ ComponentType3D: "3D", ComponentType3DNoLabels: "3DNoLabels", @@ -94,7 +94,7 @@ func (rt RtProtocol) getComponentString(c ComponentType) string { return componentsToString[c] } -func (rt *RtProtocol) GetCurrentFrame(rate StreamRateType, value int, components ...ComponentType) error { +func (rt *Protocol) GetCurrentFrame(rate StreamRateType, value int, components ...ComponentType) error { cmd := "GetCurrentFrame" for _, c := range components { cmd += " " + rt.getComponentString(c) @@ -105,14 +105,14 @@ func (rt *RtProtocol) GetCurrentFrame(rate StreamRateType, value int, components return nil } -func (rt *RtProtocol) StreamFramesAll(components ...ComponentType) error { +func (rt *Protocol) StreamFramesAll(components ...ComponentType) error { if err := rt.StreamFrames(StreamRateTypeAllFrames, 0, components...); err != nil { return fmt.Errorf("streamframesall: %w", err) } return nil } -func (rt *RtProtocol) StreamFrames(rate StreamRateType, value int, components ...ComponentType) error { +func (rt *Protocol) StreamFrames(rate StreamRateType, value int, components ...ComponentType) error { cmd := "StreamFrames" switch rate { case StreamRateTypeAllFrames: @@ -131,7 +131,7 @@ func (rt *RtProtocol) StreamFrames(rate StreamRateType, value int, components .. return nil } -func (rt *RtProtocol) StreamFramesStop() error { +func (rt *Protocol) StreamFramesStop() error { cmd := "StreamFrames stop" if err := rt.sendCommand(cmd); err != nil { return fmt.Errorf("streamframesstop: %w", err) @@ -139,7 +139,7 @@ func (rt *RtProtocol) StreamFramesStop() error { return nil } -func (rt *RtProtocol) TakeControl(password string) error { +func (rt *Protocol) TakeControl(password string) error { cmd := "TakeControl " + password qtmResponses := []string{"You are now master", "You are already master"} if err := rt.sendAndWaitForResponse(rt.sendCommand, cmd, qtmResponses); err != nil { @@ -148,7 +148,7 @@ func (rt *RtProtocol) TakeControl(password string) error { return nil } -func (rt *RtProtocol) ReleaseControl(password string) error { +func (rt *Protocol) ReleaseControl(password string) error { cmd := "ReleaseControl" qtmResponses := []string{"You are now a regular client", "You are already a regular client"} if err := rt.sendAndWaitForResponse(rt.sendCommand, cmd, qtmResponses); err != nil { @@ -157,7 +157,7 @@ func (rt *RtProtocol) ReleaseControl(password string) error { return nil } -func (rt *RtProtocol) New(password string) error { +func (rt *Protocol) New(password string) error { cmd := "New" qtmResponses := []string{"Creating new connection"} if err := rt.sendAndWaitForResponse(rt.sendCommand, cmd, qtmResponses); err != nil { @@ -166,7 +166,7 @@ func (rt *RtProtocol) New(password string) error { return nil } -func (rt *RtProtocol) Close(password string) error { +func (rt *Protocol) Close(password string) error { cmd := "Close" qtmResponses := []string{"Closing connection", "Closing file"} if err := rt.sendAndWaitForResponse(rt.sendCommand, cmd, qtmResponses); err != nil { @@ -175,7 +175,7 @@ func (rt *RtProtocol) Close(password string) error { return nil } -func (rt *RtProtocol) Start(rtFromFile bool) error { +func (rt *Protocol) Start(rtFromFile bool) error { cmd := "Start" if rtFromFile { cmd += " RTFromFile" @@ -187,7 +187,7 @@ func (rt *RtProtocol) Start(rtFromFile bool) error { return nil } -func (rt *RtProtocol) Stop() error { +func (rt *Protocol) Stop() error { cmd := "Stop" qtmResponses := []string{"Stopping measurement"} if err := rt.sendAndWaitForResponse(rt.sendCommand, cmd, qtmResponses); err != nil { @@ -196,7 +196,7 @@ func (rt *RtProtocol) Stop() error { return nil } -func (rt *RtProtocol) Load(filename string) error { +func (rt *Protocol) Load(filename string) error { cmd := "Load " + filename qtmResponses := []string{"Measurement loaded"} if err := rt.sendAndWaitForResponse(rt.sendCommand, cmd, qtmResponses); err != nil { @@ -205,7 +205,7 @@ func (rt *RtProtocol) Load(filename string) error { return nil } -func (rt *RtProtocol) Save(filename string, overwrite bool) error { +func (rt *Protocol) Save(filename string, overwrite bool) error { cmd := "Save " + filename if overwrite { cmd += " Overwrite" @@ -217,7 +217,7 @@ func (rt *RtProtocol) Save(filename string, overwrite bool) error { return nil } -func (rt *RtProtocol) LoadProject(path string) error { +func (rt *Protocol) LoadProject(path string) error { cmd := "LoadProject " + path qtmResponses := []string{"Project loaded"} if err := rt.sendAndWaitForResponse(rt.sendCommand, cmd, qtmResponses); err != nil { @@ -226,7 +226,7 @@ func (rt *RtProtocol) LoadProject(path string) error { return nil } -func (rt *RtProtocol) GetCaptureC3D(path string) error { +func (rt *Protocol) GetCaptureC3D(path string) error { cmd := "GetCaptureC3D" qtmResponses := []string{"Sending capture"} if err := rt.sendAndWaitForResponse(rt.sendCommand, cmd, qtmResponses); err != nil { @@ -235,7 +235,7 @@ func (rt *RtProtocol) GetCaptureC3D(path string) error { return nil } -func (rt *RtProtocol) GetCaptureQTM(path string) error { +func (rt *Protocol) GetCaptureQTM(path string) error { cmd := "GetCaptureQTM" qtmResponses := []string{"Sending capture"} if err := rt.sendAndWaitForResponse(rt.sendCommand, cmd, qtmResponses); err != nil { @@ -244,7 +244,7 @@ func (rt *RtProtocol) GetCaptureQTM(path string) error { return nil } -func (rt *RtProtocol) Trig(path string) error { +func (rt *Protocol) Trig(path string) error { cmd := "Trig" qtmResponses := []string{"Trig ok"} if err := rt.sendAndWaitForResponse(rt.sendCommand, cmd, qtmResponses); err != nil { @@ -253,7 +253,7 @@ func (rt *RtProtocol) Trig(path string) error { return nil } -func (rt *RtProtocol) SetQTMEvent(label string) error { +func (rt *Protocol) SetQTMEvent(label string) error { cmd := "SetQTMEvent " + label qtmResponses := []string{"Event set"} if err := rt.sendAndWaitForResponse(rt.sendCommand, cmd, qtmResponses); err != nil { @@ -262,7 +262,7 @@ func (rt *RtProtocol) SetQTMEvent(label string) error { return nil } -func (rt *RtProtocol) Reprocess(label string) error { +func (rt *Protocol) Reprocess(label string) error { cmd := "Reprocess" qtmResponses := []string{"Reprocessing file"} if err := rt.sendAndWaitForResponse(rt.sendCommand, cmd, qtmResponses); err != nil { @@ -271,7 +271,7 @@ func (rt *RtProtocol) Reprocess(label string) error { return nil } -func (rt *RtProtocol) Calibrate(refine bool) error { +func (rt *Protocol) Calibrate(refine bool) error { cmd := "Calibrate" if refine { cmd += " Refine" @@ -301,7 +301,7 @@ const ( LedColorAll ) -func (rt *RtProtocol) Led(cameraNumber int, mode LedMode, color LedColor) error { +func (rt *Protocol) Led(cameraNumber int, mode LedMode, color LedColor) error { cmd := "Led " + strconv.Itoa(cameraNumber) + " " + mode.String() + " " + color.String() if err := rt.sendCommand(cmd); err != nil { return fmt.Errorf("stop: %w", err) @@ -309,7 +309,7 @@ func (rt *RtProtocol) Led(cameraNumber int, mode LedMode, color LedColor) error return nil } -func (rt *RtProtocol) Quit() error { +func (rt *Protocol) Quit() error { cmd := "Quit" qtmResponses := []string{"Bye bye"} if err := rt.sendAndWaitForResponse(rt.sendCommand, cmd, qtmResponses); err != nil { @@ -318,7 +318,7 @@ func (rt *RtProtocol) Quit() error { return nil } -func (rt *RtProtocol) sendAndWaitForResponse(sender senderType, s string, expectedResponses []string) error { +func (rt *Protocol) sendAndWaitForResponse(sender senderType, s string, expectedResponses []string) error { if err := sender(s); err != nil { return fmt.Errorf("sendcommandandwaitforresponse: sender: %w", err) } diff --git a/go.mod b/go.mod index 5f5bf0c..777e30b 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/mlveggo/qualisys-go -go 1.17 +go 1.18 require gotest.tools v2.2.0+incompatible diff --git a/packet.go b/packet.go index 60378ad..2a11803 100644 --- a/packet.go +++ b/packet.go @@ -53,7 +53,7 @@ type DataPacket struct { Components []IDataObject } -type RtPacket struct { +type Packet struct { Type PacketType ErrorResponse string CommandResponse string @@ -64,15 +64,15 @@ type RtPacket struct { File FilePacket } -func (p *RtPacket) Error() bool { +func (p *Packet) Error() bool { return p.Type == PacketTypeError } -func (p *RtPacket) IsPacketData() bool { +func (p *Packet) IsPacketData() bool { return p.Type == PacketTypeData } -func (p *RtPacket) EndOfData() bool { +func (p *Packet) EndOfData() bool { return p.Type == PacketTypeNoMoreData } @@ -149,7 +149,7 @@ func trimStringResponse(data []byte) string { return string(bytes.Trim(data, "\x00")) } -func (p *RtPacket) UnmarshalBinary(data []byte) error { +func (p *Packet) UnmarshalBinary(data []byte) error { p.Size = int(binary.LittleEndian.Uint32(data[0:4])) p.Type = PacketType(binary.LittleEndian.Uint32(data[4:8])) switch p.Type { diff --git a/parameters.go b/parameters.go index bc8ffb2..d8f3568 100644 --- a/parameters.go +++ b/parameters.go @@ -22,7 +22,7 @@ const ( ) // GetParameters fetches xml settings from QTM for specified. -func (rt *RtProtocol) GetParameters(parameters ...ParameterType) (string, error) { +func (rt *Protocol) GetParameters(parameters ...ParameterType) (string, error) { parametersToString := map[ParameterType]string{ ParameterTypeAll: "All", ParameterTypeGeneral: "General", @@ -53,7 +53,7 @@ func (rt *RtProtocol) GetParameters(parameters ...ParameterType) (string, error) return p.XMLResponse, nil } -func (rt *RtProtocol) SetParameters(xml string) error { +func (rt *Protocol) SetParameters(xml string) error { s := "" + xml + "" qtmResponses := []string{"Setting parameters succeeded"} if err := rt.sendAndWaitForResponse(rt.sendXML, s, qtmResponses); err != nil { diff --git a/pkg/discover/discover.go b/pkg/discover/discover.go index 1bba598..c9401e2 100644 --- a/pkg/discover/discover.go +++ b/pkg/discover/discover.go @@ -145,7 +145,7 @@ func (d *Discovery) Discover() ([]Response, error) { if err := conn.SetReadDeadline(time.Now().Add(d.timeout)); err != nil { return nil, fmt.Errorf("discover: setreaddeadline: %w", err) } - var responses []Response + responses := make([]Response, 0, 1) for { size, addr, err := conn.ReadFrom(b) if err != nil { @@ -187,7 +187,7 @@ func (dr *Response) UnmarshalBinary(data []byte) error { return nil } -func splitAndTrimStrings(s string, sep string) []string { +func splitAndTrimStrings(s, sep string) []string { parts := strings.Split(s, sep) for i := range parts { parts[i] = strings.TrimSpace(parts[i]) diff --git a/pkg/packets/timecode.go b/pkg/packets/timecode.go index 767a622..65c2e2e 100644 --- a/pkg/packets/timecode.go +++ b/pkg/packets/timecode.go @@ -18,7 +18,7 @@ type IrigTime struct { Year, Day, Hour, Minute, Second, Tenth uint32 } -func (i *IrigTime) Convert(high uint32, low uint32) { +func (i *IrigTime) Convert(high, low uint32) { i.Year = 0x7f & high i.Day = 0x1FF & (high >> 7) i.Hour = 0x1f & low @@ -31,7 +31,7 @@ type SmpteTime struct { Hour, Minute, Second, Frame uint32 } -func (i *SmpteTime) Convert(high uint32, low uint32) { +func (i *SmpteTime) Convert(high, low uint32) { i.Hour = 0x1f & low i.Minute = 0x3F & (low >> 5) i.Second = 0x3F & (low >> 11) @@ -40,7 +40,7 @@ func (i *SmpteTime) Convert(high uint32, low uint32) { type CameraTime uint64 -func (i *CameraTime) Convert(high uint32, low uint32) { +func (i *CameraTime) Convert(high, low uint32) { *i = CameraTime((uint64(high) << uint64(32)) | uint64(low)) } diff --git a/protocol.go b/protocol.go index d866ed4..3afe52a 100644 --- a/protocol.go +++ b/protocol.go @@ -35,7 +35,7 @@ const ( ComponentTypeEyeTracker ) -type RtProtocol struct { +type Protocol struct { conn net.Conn buffer []byte ip string @@ -44,16 +44,16 @@ type RtProtocol struct { const DefaultLittleEndianPort = 22223 -func NewRtProtocol(ip string, basePort int) *RtProtocol { +func NewProtocol(ip string, basePort int) *Protocol { const startBufferSize int = 4096 - rt := new(RtProtocol) + rt := new(Protocol) rt.buffer = make([]byte, startBufferSize) rt.ip = ip rt.basePort = basePort return rt } -func (rt *RtProtocol) Connect() error { +func (rt *Protocol) Connect() error { if rt.IsConnected() { rt.Disconnect() } @@ -84,11 +84,11 @@ func (rt *RtProtocol) Connect() error { return err } -func (rt *RtProtocol) IsConnected() bool { +func (rt *Protocol) IsConnected() bool { return rt.conn != nil } -func (rt *RtProtocol) Disconnect() { +func (rt *Protocol) Disconnect() { if !rt.IsConnected() { return } @@ -96,7 +96,7 @@ func (rt *RtProtocol) Disconnect() { rt.conn = nil } -func (rt *RtProtocol) Receive() (*RtPacket, error) { +func (rt *Protocol) Receive() (*Packet, error) { for i := range rt.buffer { rt.buffer[i] = 0 } @@ -108,14 +108,14 @@ func (rt *RtProtocol) Receive() (*RtPacket, error) { if err != nil { var netError net.Error if errors.As(err, &netError) && netError.Timeout() { - return &RtPacket{Type: PacketTypeNoMoreData}, nil + return &Packet{Type: PacketTypeNoMoreData}, nil } return nil, fmt.Errorf("receive: read %w", err) } if packetSize < packetHeaderSize { return nil, fmt.Errorf("receive: packet to small for header") } - var p RtPacket + var p Packet p.Size = int(binary.LittleEndian.Uint32(rt.buffer[0:4])) p.Type = PacketType(binary.LittleEndian.Uint32(rt.buffer[4:8])) if len(rt.buffer) < p.Size { @@ -133,7 +133,7 @@ func (rt *RtProtocol) Receive() (*RtPacket, error) { if err != nil { var netError net.Error if errors.As(err, &netError) && netError.Timeout() { - return &RtPacket{Type: PacketTypeNoMoreData}, nil + return &Packet{Type: PacketTypeNoMoreData}, nil } if !errors.Is(err, io.EOF) { return nil, fmt.Errorf("receive: read %w", err) diff --git a/tools/golangci-lint/rules.mk b/tools/golangci-lint/rules.mk deleted file mode 100644 index 20fb79b..0000000 --- a/tools/golangci-lint/rules.mk +++ /dev/null @@ -1,27 +0,0 @@ -golangci_lint_cwd := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) -golangci_lint_version := 1.42.1 -golangci_lint := $(golangci_lint_cwd)/$(golangci_lint_version)/golangci-lint - -system_os := $(shell uname -s | tr A-Z a-z) -system_arch := $(shell uname -m | sed 's/x86_/amd/') - -ifneq ($(shell uname),Linux) -ifneq ($(shell uname),Darwin) -$(error unsupported OS: $(shell uname)) -endif -endif - -golangci_lint_archive_url := https://github.com/golangci/golangci-lint/releases/download/v${golangci_lint_version}/golangci-lint-${golangci_lint_version}-$(system_os)-$(system_arch).tar.gz - -$(golangci_lint): - $(info [golangci-lint] fetching $(golangci_lint_version) binary...) - @mkdir -p $(dir $@) - @curl -sSL $(golangci_lint_archive_url) -o - | \ - tar -xz --directory $(dir $@) --strip-components 1 - @chmod +x $@ - @touch $@ - -.PHONY: go-lint -go-lint: $(golangci_lint) - $(info [$@] linting Go code...) - @$(golangci_lint) run diff --git a/tools/goreview/rules.mk b/tools/goreview/rules.mk deleted file mode 100644 index 2d47d05..0000000 --- a/tools/goreview/rules.mk +++ /dev/null @@ -1,27 +0,0 @@ -goreview_cwd := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) -goreview_version := 0.18.0 -goreview := $(goreview_cwd)/$(goreview_version)/goreview - -system_os := $(shell uname -s) -system_arch := $(shell uname -m) - -ifneq ($(shell uname),Linux) -ifneq ($(shell uname),Darwin) -$(error unsupported OS: $(shell uname)) -endif -endif - -goreview_archive_url := https://github.com/einride/goreview/releases/download/v$(goreview_version)/goreview_$(goreview_version)_$(system_os)_$(system_arch).tar.gz - -$(goreview): $(goreview_cwd)/rules.mk - $(info [goreview] fetching $(goreview_version) binary...) - @mkdir -p $(dir $@) - @curl -sSL $(goreview_archive_url) -o - | tar -xz --directory $(dir $@) - @chmod +x $@ - @touch $@ - -# go-review: review Go code for Einride-specific conventions -.PHONY: go-review -go-review: $(goreview) - $(info [$@] reviewing Go code for Einride-specific conventions...) - @$(goreview) -c 1 ./... diff --git a/tools/stringer/go.mod b/tools/stringer/go.mod deleted file mode 100644 index 1285de2..0000000 --- a/tools/stringer/go.mod +++ /dev/null @@ -1,10 +0,0 @@ -module tools/stringer - -go 1.17 - -require golang.org/x/tools v0.0.0-20201208062317-e652b2f42cc7 - -require ( - golang.org/x/mod v0.3.0 // indirect - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect -) diff --git a/tools/stringer/go.sum b/tools/stringer/go.sum deleted file mode 100644 index 376e72f..0000000 --- a/tools/stringer/go.sum +++ /dev/null @@ -1,24 +0,0 @@ -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20201208062317-e652b2f42cc7 h1:2OSu5vYyX4LVqZAtqZXnFEcN26SDKIJYlEVIRl1tj8U= -golang.org/x/tools v0.0.0-20201208062317-e652b2f42cc7/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/tools/stringer/rules.mk b/tools/stringer/rules.mk deleted file mode 100644 index 668d403..0000000 --- a/tools/stringer/rules.mk +++ /dev/null @@ -1,8 +0,0 @@ -stringer_cwd := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) -stringer := $(stringer_cwd)/bin/stringer -export PATH := $(PATH):$(dir $(stringer)) - -$(stringer): $(stringer_cwd)/go.mod - $(info [stringer] building binary...) - @cd $(stringer_cwd) && go build -o $@ golang.org/x/tools/cmd/stringer - @cd $(stringer_cwd) && go mod tidy diff --git a/tools/stringer/tool.go b/tools/stringer/tool.go deleted file mode 100644 index f836ab8..0000000 --- a/tools/stringer/tool.go +++ /dev/null @@ -1,5 +0,0 @@ -//+build tool - -package tool - -import _ "golang.org/x/tools/cmd/stringer"