mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-10-15 04:40:05 +00:00
Rebase of #1881 by @SaarMesh-Bot onto current master. Their three commits are preserved, two of them cherry-picked with authorship intact; the sweep itself had to be regenerated. Opened as a new PR rather than force-pushing their branch. Closes #1881 once merged. Addresses parts 1 and 3 of #1859; part 2 landed as #1937. ## Why regenerated rather than merged The sweep in #1881 was cut on 2026-09-02 07:13 and roughly forty PRs landed after it, so it went `CONFLICTING/DIRTY`. Re-running `gofmt` on current master is cheaper and less error-prone than resolving 72 conflicts that are all whitespace. The drift it fixes also grew in the meantime: 66 files now, against 72 then, but spread differently. ## The three commits 1. **`style(#1859)`** — `gofmt -w` across the 14 modules. 66 files. 2. **`test(#1859)`** — @SaarMesh-Bot's fix for the one `go vet` copylocks finding, `cmd/ingestor/coverage_boost_test.go`: the range variable copied a `Config` embedding `sync.Once`. Cherry-picked unchanged. 3. **`ci(#1859)`** — @SaarMesh-Bot's CI step that fails on gofmt drift or vet findings, plus `.git-blame-ignore-revs`. Cherry-picked with one change, noted in the commit message: the ignore file pointed at `04bc80ee`, the sweep commit on their branch, which does not exist on this base and would make `git blame --ignore-revs-file` error. Repointed at `d3a02599`, the sweep here. ## Verification The claim "formatting only" is checked twice rather than asserted: - Every changed file is byte-identical to `gofmt(previous content)`. 0 of 66 deviate. - With line comments and all whitespace stripped, 0 of 66 files differ, so no code outside comments changed. 14 of the 66 also show doc-comment reflow. Since Go 1.19 `gofmt` re-indents indented comment blocks to tabs and inserts a blank comment line before them; the behavior matrix above `resolveHopWithContext` in `cmd/ingestor/path_resolver.go` is a clear example. That is gofmt's own output, not an edit, but it is worth naming because it makes the diff look larger than "whitespace" suggests. The gate was run locally exactly as the workflow runs it: `gofmt` clean, and `go vet` clean in all 14 modules, including `cmd/ingestor` which is what commit 2 fixes. Suites: `cmd/server` ok (80.7s), `internal/packetpath` ok (2.3s), `cmd/ingestor` passes except `TestWriteStatsAtomic_SymlinkAtDestIsReplaced`, which fails identically on bare master with "A required privilege is not held by the client" (Windows symlink privilege on my host, not code). ## Sequencing This should go last in the queue. The sweep touches 66 files, so merging it before the remaining open Go PRs gives each of them a conflict about nothing but formatting. After it lands the gate is active, and any PR with drift fails CI until it runs `gofmt -w`. Excluded from the sweep: the misnamed `Dockerfile.go`, which is a Dockerfile that gofmt cannot parse (the workflow excludes it too), and `docs/DEPLOYMENT.md`, which a case-insensitive filesystem surfaces as a spurious modification against `docs/deployment.md` and is unrelated. --------- Co-authored-by: SaarMesh-Bot <300107934+SaarMesh-Bot@users.noreply.github.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
97 lines
2.6 KiB
Go
97 lines
2.6 KiB
Go
package lora
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Reference values cross-checked against the closed-form computation
|
|
// shown in issue #1768 and against RadioLib calculateTimeOnAir():
|
|
//
|
|
// freq=869.6 MHz, BW=62.5 kHz, SF=8, CR=4/5, preamble=32 (SF<=8)
|
|
// T_sym = 256/62500 = 4.096 ms
|
|
// preamble_symbols = 32 + 4.25 = 36.25
|
|
//
|
|
// PL=8: num = 64 - 32 + 28 + 16 = 76; den = 4*(8 - 0) = 32 (DE=0 since T_sym<16ms)
|
|
// ceil(76/32) = 3 → symbols_payload = 8 + 3*5 = 23
|
|
// total = (36.25 + 23) * 4.096 = 242.688 ms
|
|
// PL=16: total = 283.648 ms
|
|
// PL=32: total = 365.568 ms
|
|
// PL=64: total = 529.408 ms
|
|
//
|
|
// These match the table in the issue #1768 body to the microsecond.
|
|
func TestTimeOnAir_DefaultEUPreset(t *testing.T) {
|
|
preset := Preset{
|
|
FreqHz: 869.6e6,
|
|
BWkHz: 62.5,
|
|
SF: 8,
|
|
CR: 5,
|
|
Preamble: PreambleForSF(8), // 32
|
|
}
|
|
|
|
cases := []struct {
|
|
pl int
|
|
wantMs float64
|
|
}{
|
|
{8, 242.688},
|
|
{16, 283.648},
|
|
{32, 365.568},
|
|
{64, 529.408},
|
|
}
|
|
for _, c := range cases {
|
|
got := TimeOnAir(c.pl, preset)
|
|
gotMs := float64(got) / float64(time.Millisecond)
|
|
if math.Abs(gotMs-c.wantMs) > 0.01 {
|
|
t.Errorf("TimeOnAir(%d B) = %.3f ms, want %.3f ms", c.pl, gotMs, c.wantMs)
|
|
}
|
|
}
|
|
}
|
|
|
|
// SF11/BW125 → T_sym = 2048/125000 = 16.384 ms ≥ 16ms → DE = 1; preamble = 16.
|
|
// PL=8:
|
|
//
|
|
// num = 8*8 - 4*11 + 28 + 16 = 64 - 44 + 44 = 64
|
|
// den = 4*(11 - 2*1) = 36; ceil(64/36) = 2
|
|
// symbols_payload = 8 + 2*5 = 18
|
|
// preamble_symbols = 16 + 4.25 = 20.25
|
|
// total = (20.25 + 18) * 16.384 = 38.25 * 16.384 ≈ 626.688 ms
|
|
func TestTimeOnAir_DERangeSF11(t *testing.T) {
|
|
preset := Preset{
|
|
BWkHz: 125,
|
|
SF: 11,
|
|
CR: 5,
|
|
Preamble: PreambleForSF(11),
|
|
}
|
|
got := TimeOnAir(8, preset)
|
|
wantMs := 626.688
|
|
gotMs := float64(got) / float64(time.Millisecond)
|
|
if math.Abs(gotMs-wantMs) > 0.05 {
|
|
t.Errorf("TimeOnAir(SF11/BW125, PL=8) = %.3f ms, want ~%.3f ms", gotMs, wantMs)
|
|
}
|
|
}
|
|
|
|
func TestTimeOnAir_InvalidPresetReturnsZero(t *testing.T) {
|
|
cases := []Preset{
|
|
{BWkHz: 125, SF: 5, CR: 5}, // SF too low
|
|
{BWkHz: 125, SF: 13, CR: 5}, // SF too high
|
|
{BWkHz: 0, SF: 8, CR: 5}, // BW zero
|
|
{BWkHz: 125, SF: 8, CR: 4}, // CR too low
|
|
{BWkHz: 125, SF: 8, CR: 9}, // CR too high
|
|
}
|
|
for _, p := range cases {
|
|
if got := TimeOnAir(16, p); got != 0 {
|
|
t.Errorf("TimeOnAir(invalid preset %+v) = %v, want 0", p, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPreambleForSF(t *testing.T) {
|
|
if PreambleForSF(7) != 32 || PreambleForSF(8) != 32 {
|
|
t.Errorf("PreambleForSF(<=8) must be 32 (firmware preambleLengthForSF)")
|
|
}
|
|
if PreambleForSF(9) != 16 || PreambleForSF(12) != 16 {
|
|
t.Errorf("PreambleForSF(>8) must be 16")
|
|
}
|
|
}
|