Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bit error rate #29

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Go CI and Release

on:
Expand All @@ -12,4 +13,4 @@ on:

jobs:
build:
uses: TheCacophonyProject/github-actions-templates/.github/workflows/[email protected].1
uses: TheCacophonyProject/github-actions-templates/.github/workflows/[email protected].2
105 changes: 52 additions & 53 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
project_name: modemd

version: 2
Expand All @@ -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 <[email protected]>
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 <[email protected]>
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'
Expand Down
6 changes: 4 additions & 2 deletions cmd/modemd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 13 additions & 7 deletions cmd/modemd/modemController.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
}

Expand Down