From 3278d274108d48791a87d2f1b4b3182bf96ed300 Mon Sep 17 00:00:00 2001 From: cam Date: Tue, 1 Oct 2024 18:07:26 +1300 Subject: [PATCH 1/2] Add bit error rate reporting --- cmd/modemd/main.go | 6 ++++-- cmd/modemd/modemController.go | 20 +++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/cmd/modemd/main.go b/cmd/modemd/main.go index bc52ff2..c1e07e6 100644 --- a/cmd/modemd/main.go +++ b/cmd/modemd/main.go @@ -200,10 +200,11 @@ func runMain() error { // TODO make configurable to how long it will try to find a connection gotSignal := false for i := 0; i < 5; i++ { - strengthStr, _ := mc.signalStrength() + strengthStr, bitErrorRate, _ := mc.signalStrength() strength, err := strconv.Atoi(strengthStr) if err == nil && strength != 99 { log.Printf("Signal strength: %s", strengthStr) + log.Printf("Bit error rate: %s", bitErrorRate) gotSignal = true break } @@ -258,7 +259,7 @@ func runMain() error { func makeModemEvent(eventType string, mc *ModemController) { log.Printf("Making modem event '%s'.", eventType) - signalStrength, err := mc.signalStrength() + signalStrength, bitErrorRate, err := mc.signalStrength() if err != nil { log.Printf("Failed to get signal strength: %s", err) } @@ -291,6 +292,7 @@ func makeModemEvent(eventType string, mc *ModemController) { Timestamp: time.Now(), Type: eventType, Details: map[string]interface{}{ + "signalStrengthDB": bitErrorRate, "signalStrength": signalStrength, "band": band, "simStatus": simStatus, diff --git a/cmd/modemd/modemController.go b/cmd/modemd/modemController.go index 2b67c45..4b84d9b 100644 --- a/cmd/modemd/modemController.go +++ b/cmd/modemd/modemController.go @@ -280,8 +280,14 @@ func (mc *ModemController) GetStatus() (map[string]interface{}, error) { // Set details for signal if mc.Modem.ATReady { signal := make(map[string]interface{}) - signal["strength"] = valueOrErrorStr(mc.signalStrength()) - signal["band"] = valueOrErrorStr(mc.readBand()) + signalStrength, bitErrorRate, err := mc.signalStrength() + if err != nil { + signal["strength"] = err.Error() + signal["bitErrorRate"] = err.Error() + } else { + signal["strength"] = signalStrength + signal["bitErrorRate"] = bitErrorRate + } provider, accessTechnology, err := mc.readProvider() if err != nil { signal["provider"] = err.Error() @@ -538,19 +544,19 @@ func (mc *ModemController) FindModem() bool { } } -func (mc *ModemController) signalStrength() (string, error) { +func (mc *ModemController) signalStrength() (string, string, error) { out, err := mc.RunATCommand("AT+CSQ") if err != nil { - return "", err + return "", "", err } out = strings.TrimPrefix(out, "+CSQ:") out = strings.TrimSpace(out) parts := strings.Split(out, ",") - if len(parts) > 1 { - return parts[0], nil + if len(parts) == 2 { + return strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]), nil } else { - return "", fmt.Errorf("unable to read reception, '%s'", out) + return "", "", fmt.Errorf("unable to read reception, '%s'", out) } } From 96b0284bd6992aa646d348f0fce16cf89da81ad7 Mon Sep 17 00:00:00 2001 From: cam Date: Tue, 1 Oct 2024 20:55:08 +1300 Subject: [PATCH 2/2] Add yaml lint check --- .github/workflows/goreleaser.yml | 3 +- .goreleaser.yml | 105 +++++++++++++++---------------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 4c25ec2..b321563 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -1,3 +1,4 @@ +--- name: Go CI and Release on: @@ -12,4 +13,4 @@ on: jobs: build: - uses: TheCacophonyProject/github-actions-templates/.github/workflows/go-ci-release.yml@v0.1.1 + uses: TheCacophonyProject/github-actions-templates/.github/workflows/go-ci-release.yml@v0.1.2 diff --git a/.goreleaser.yml b/.goreleaser.yml index 2d7a3d2..e94dc8a 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,3 +1,4 @@ +--- project_name: modemd version: 2 @@ -9,64 +10,62 @@ release: name_template: '{{.Tag}}' builds: -- id: modemd - goos: - - linux - goarch: - - arm - - arm64 - goarm: - - "7" - main: ./cmd/modemd - ldflags: -s -w -X main.version={{.Version}} - binary: modemd + - id: modemd + goos: + - linux + goarch: + - arm + - arm64 + goarm: + - "7" + main: ./cmd/modemd + ldflags: -s -w -X main.version={{.Version}} + binary: modemd -- id: reception-logger - goos: - - linux - goarch: - - arm - - arm64 - goarm: - - "7" - main: ./cmd/reception-logger - ldflags: -s -w -X main.version={{.Version}} - binary: reception-logger + - id: reception-logger + goos: + - linux + goarch: + - arm + - arm64 + goarm: + - "7" + main: ./cmd/reception-logger + ldflags: -s -w -X main.version={{.Version}} + binary: reception-logger -- id: modem-cli - goos: - - linux - goarch: - - arm - - arm64 - goarm: - - "7" - main: ./cmd/modem-cli - ldflags: -s -w -X main.version={{.Version}} - binary: modem-cli + - id: modem-cli + goos: + - linux + goarch: + - arm + - arm64 + goarm: + - "7" + main: ./cmd/modem-cli + ldflags: -s -w -X main.version={{.Version}} + binary: modem-cli nfpms: -- vendor: The Cacophony Project - homepage: http://cacophony.org.nz/ - maintainer: Cacophony Developers - description: Controls the USB modems - license: GPL v3.0 - file_name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Arch }}" - formats: - - deb - bindir: /usr/bin - contents: - - src: _release/modemd.service - dst: /etc/systemd/system/modemd.service - - src: _release/org.cacophony.modemd.conf - dst: /etc/dbus-1/system.d/org.cacophony.modemd.conf - - src: _release/99-modem-udev.rules - dst: /etc/udev/rules.d/99-modem-udev.rules - #- src: _release/uhubctl - # dst: /usr/sbin/uhubctl - scripts: - postinstall: "_release/postinstall.sh" + - vendor: The Cacophony Project + homepage: http://cacophony.org.nz/ + maintainer: Cacophony Developers + description: Controls the USB modems + license: GPL v3.0 + file_name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Arch }}" + formats: + - deb + bindir: /usr/bin + contents: + - src: _release/modemd.service + dst: /etc/systemd/system/modemd.service + - src: _release/org.cacophony.modemd.conf + dst: /etc/dbus-1/system.d/org.cacophony.modemd.conf + - src: _release/99-modem-udev.rules + dst: /etc/udev/rules.d/99-modem-udev.rules + scripts: + postinstall: "_release/postinstall.sh" checksum: name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt'