mirror of
https://github.com/onyx-and-iris/vbantxt.git
synced 2026-04-20 07:53:34 +00:00
Compare commits
8 Commits
d72c6a2d17
...
v0.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 4bb79c8500 | |||
| db497a017b | |||
| 3afc5ee66c | |||
| 99b630dd47 | |||
| 8bd62b72d0 | |||
| e36af2c059 | |||
| 5a5a6fa893 | |||
| be11239d39 |
31
.github/workflows/release.yml
vendored
Normal file
31
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name: goreleaser
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
goreleaser:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
-
|
||||||
|
name: Set up Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
-
|
||||||
|
name: Run GoReleaser
|
||||||
|
uses: goreleaser/goreleaser-action@v6
|
||||||
|
with:
|
||||||
|
distribution: goreleaser
|
||||||
|
version: '~> v2'
|
||||||
|
args: release --clean
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
30
.github/workflows/update-go-modules.yml
vendored
Normal file
30
.github/workflows/update-go-modules.yml
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
name: Auto-Update Go Modules
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: "0 0 * * 1" # Runs every Monday at midnight
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
update-go-modules:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: stable
|
||||||
|
|
||||||
|
- name: Update Dependencies
|
||||||
|
run: |
|
||||||
|
go get -u ./...
|
||||||
|
go mod tidy
|
||||||
|
git config user.name "github-actions[bot]"
|
||||||
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
git add go.mod go.sum
|
||||||
|
git commit -m "chore: auto-update Go modules"
|
||||||
|
git push
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -14,3 +14,6 @@ bin/
|
|||||||
|
|
||||||
# Dependency directories (remove the comment below to include it)
|
# Dependency directories (remove the comment below to include it)
|
||||||
# vendor/
|
# vendor/
|
||||||
|
|
||||||
|
# Added by goreleaser init:
|
||||||
|
dist/
|
||||||
|
|||||||
55
.goreleaser.yaml
Normal file
55
.goreleaser.yaml
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
# This is an example .goreleaser.yml file with some sensible defaults.
|
||||||
|
# Make sure to check the documentation at https://goreleaser.com
|
||||||
|
|
||||||
|
# The lines below are called `modelines`. See `:help modeline`
|
||||||
|
# Feel free to remove those if you don't want/need to use them.
|
||||||
|
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
|
||||||
|
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
|
||||||
|
before:
|
||||||
|
hooks:
|
||||||
|
# You may remove this if you don't use go modules.
|
||||||
|
- go mod tidy
|
||||||
|
# you may remove this if you don't need go generate
|
||||||
|
- go generate ./...
|
||||||
|
|
||||||
|
builds:
|
||||||
|
- main: ./cmd/vbantxt/
|
||||||
|
env:
|
||||||
|
- CGO_ENABLED=0
|
||||||
|
goos:
|
||||||
|
- linux
|
||||||
|
- windows
|
||||||
|
goarch:
|
||||||
|
- amd64
|
||||||
|
|
||||||
|
archives:
|
||||||
|
- formats: ['tar.gz']
|
||||||
|
# this name template makes the OS and Arch compatible with the results of `uname`.
|
||||||
|
name_template: >-
|
||||||
|
{{ .ProjectName }}_
|
||||||
|
{{- title .Os }}_
|
||||||
|
{{- if eq .Arch "amd64" }}x86_64
|
||||||
|
{{- else if eq .Arch "386" }}i386
|
||||||
|
{{- else }}{{ .Arch }}{{ end }}
|
||||||
|
{{- if .Arm }}v{{ .Arm }}{{ end }}
|
||||||
|
# use zip for windows archives
|
||||||
|
format_overrides:
|
||||||
|
- goos: windows
|
||||||
|
formats: ['zip']
|
||||||
|
|
||||||
|
changelog:
|
||||||
|
sort: asc
|
||||||
|
filters:
|
||||||
|
exclude:
|
||||||
|
- '^docs:'
|
||||||
|
- '^test:'
|
||||||
|
|
||||||
|
release:
|
||||||
|
footer: >-
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Released by [GoReleaser](https://github.com/goreleaser/goreleaser).
|
||||||
@@ -11,6 +11,12 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
|
|||||||
|
|
||||||
- [x]
|
- [x]
|
||||||
|
|
||||||
|
# [0.2.1] - 2024-11-07
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- {packet}.header() now uses a reusable buffer.
|
||||||
|
|
||||||
# [0.2.0] - 2024-10-27
|
# [0.2.0] - 2024-10-27
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ For example, in Windows with Powershell you could:
|
|||||||
|
|
||||||
Or with Bash:
|
Or with Bash:
|
||||||
|
|
||||||
`cat script.txt | xargs vbantxt-cli`
|
`xargs vbantxt < script.txt`
|
||||||
|
|
||||||
to load commands from a file:
|
to load commands from a file:
|
||||||
|
|
||||||
|
|||||||
55
Taskfile.yml
Normal file
55
Taskfile.yml
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
vars:
|
||||||
|
PROGRAM: vbantxt
|
||||||
|
SHELL: '{{if eq .OS "Windows_NT"}}powershell{{end}}'
|
||||||
|
BIN_DIR: bin
|
||||||
|
|
||||||
|
WINDOWS: '{{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe'
|
||||||
|
LINUX: '{{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64'
|
||||||
|
GIT_COMMIT:
|
||||||
|
sh: git log -n 1 --format=%h
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
default:
|
||||||
|
desc: Build the vbantxt project
|
||||||
|
cmds:
|
||||||
|
- task: build
|
||||||
|
|
||||||
|
build:
|
||||||
|
desc: 'Build the vbantxt project'
|
||||||
|
deps: [vet]
|
||||||
|
cmds:
|
||||||
|
- task: build-windows
|
||||||
|
- task: build-linux
|
||||||
|
|
||||||
|
vet:
|
||||||
|
desc: Vet the code
|
||||||
|
deps: [fmt]
|
||||||
|
cmds:
|
||||||
|
- go vet ./...
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
desc: Fmt the code
|
||||||
|
cmds:
|
||||||
|
- go fmt ./...
|
||||||
|
|
||||||
|
build-windows:
|
||||||
|
desc: Build the vbantxt project for Windows
|
||||||
|
cmds:
|
||||||
|
- GOOS=windows GOARCH=amd64 go build -o {{.WINDOWS}} -ldflags="-X main.Version={{.GIT_COMMIT}}" ./cmd/{{.PROGRAM}}/
|
||||||
|
|
||||||
|
build-linux:
|
||||||
|
desc: Build the vbantxt project for Linux
|
||||||
|
cmds:
|
||||||
|
- GOOS=linux GOARCH=amd64 go build -o {{.LINUX}} -ldflags="-X main.Version={{.GIT_COMMIT}}" ./cmd/{{.PROGRAM}}/
|
||||||
|
|
||||||
|
test:
|
||||||
|
desc: Run tests
|
||||||
|
cmds:
|
||||||
|
- go test ./...
|
||||||
|
|
||||||
|
clean:
|
||||||
|
desc: Clean the build artifacts
|
||||||
|
cmds:
|
||||||
|
- '{{.SHELL}} rm -r {{.BIN_DIR}}'
|
||||||
12
makefile
12
makefile
@@ -1,11 +1,11 @@
|
|||||||
program = vbantxt
|
PROGRAM = vbantxt
|
||||||
|
|
||||||
GO = go
|
GO = go
|
||||||
BIN_DIR := bin
|
BIN_DIR := bin
|
||||||
|
|
||||||
WINDOWS=$(BIN_DIR)/$(program)_windows_amd64.exe
|
WINDOWS=$(BIN_DIR)/$(PROGRAM)_windows_amd64.exe
|
||||||
LINUX=$(BIN_DIR)/$(program)_linux_amd64
|
LINUX=$(BIN_DIR)/$(PROGRAM)_linux_amd64
|
||||||
VERSION=$(shell git describe --tags --always --long --dirty)
|
VERSION=$(shell git log -n 1 --format=%h)
|
||||||
|
|
||||||
.DEFAULT_GOAL := build
|
.DEFAULT_GOAL := build
|
||||||
|
|
||||||
@@ -25,10 +25,10 @@ linux: $(LINUX)
|
|||||||
|
|
||||||
|
|
||||||
$(WINDOWS):
|
$(WINDOWS):
|
||||||
env GOOS=windows GOARCH=amd64 go build -v -o $(WINDOWS) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/vbantxt/
|
env GOOS=windows GOARCH=amd64 go build -v -o $(WINDOWS) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/$(PROGRAM)/
|
||||||
|
|
||||||
$(LINUX):
|
$(LINUX):
|
||||||
env GOOS=linux GOARCH=amd64 go build -v -o $(LINUX) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/vbantxt/
|
env GOOS=linux GOARCH=amd64 go build -v -o $(LINUX) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/$(PROGRAM)/
|
||||||
|
|
||||||
test:
|
test:
|
||||||
$(GO) test ./...
|
$(GO) test ./...
|
||||||
|
|||||||
35
packet.go
35
packet.go
@@ -1,6 +1,7 @@
|
|||||||
package vbantxt
|
package vbantxt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@@ -17,19 +18,24 @@ var BpsOpts = []int{0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200,
|
|||||||
1000000, 1500000, 2000000, 3000000}
|
1000000, 1500000, 2000000, 3000000}
|
||||||
|
|
||||||
type packet struct {
|
type packet struct {
|
||||||
name string
|
streamname []byte
|
||||||
bpsIndex int
|
bpsIndex int
|
||||||
channel int
|
channel int
|
||||||
framecounter []byte
|
framecounter []byte
|
||||||
|
hbuf *bytes.Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
// newPacket returns a packet struct with default values, framecounter at 0.
|
// newPacket returns a packet struct with default values, framecounter at 0.
|
||||||
func newPacket(streamname string) packet {
|
func newPacket(streamname string) packet {
|
||||||
|
streamnameBuf := make([]byte, streamNameSz)
|
||||||
|
copy(streamnameBuf, streamname)
|
||||||
|
|
||||||
return packet{
|
return packet{
|
||||||
name: streamname,
|
streamname: streamnameBuf,
|
||||||
bpsIndex: 0,
|
bpsIndex: 0,
|
||||||
channel: 0,
|
channel: 0,
|
||||||
framecounter: make([]byte, 4),
|
framecounter: make([]byte, 4),
|
||||||
|
hbuf: bytes.NewBuffer(make([]byte, headerSz)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,24 +49,17 @@ func (p *packet) nbc() byte {
|
|||||||
return byte(p.channel)
|
return byte(p.channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
// streamname defines the stream name of the text request
|
|
||||||
func (p *packet) streamname() []byte {
|
|
||||||
b := make([]byte, streamNameSz)
|
|
||||||
copy(b, p.name)
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// header returns a fully formed packet header
|
// header returns a fully formed packet header
|
||||||
func (p *packet) header() []byte {
|
func (p *packet) header() []byte {
|
||||||
h := make([]byte, 0, headerSz)
|
p.hbuf.Reset()
|
||||||
h = append(h, []byte("VBAN")...)
|
p.hbuf.WriteString("VBAN")
|
||||||
h = append(h, p.sr())
|
p.hbuf.WriteByte(p.sr())
|
||||||
h = append(h, byte(0))
|
p.hbuf.WriteByte(byte(0))
|
||||||
h = append(h, p.nbc())
|
p.hbuf.WriteByte(p.nbc())
|
||||||
h = append(h, byte(0x10))
|
p.hbuf.WriteByte(byte(0x10))
|
||||||
h = append(h, p.streamname()...)
|
p.hbuf.Write(p.streamname)
|
||||||
h = append(h, p.framecounter...)
|
p.hbuf.Write(p.framecounter)
|
||||||
return h
|
return p.hbuf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
// bumpFrameCounter increments the frame counter by 1
|
// bumpFrameCounter increments the frame counter by 1
|
||||||
|
|||||||
Reference in New Issue
Block a user