mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-11-22 05:57:12 +00:00
Both features are OPT-IN ("los" and "planner" config blocks, default
off); with them off nothing is fetched and payloads are unchanged.
Route view
- Multi-path picker discoverability: on-map "N hops shown · tap to see
all" badge, picker pulse (reduced-motion safe), one-time tip, row hover
arrow; "no GPS" hops counted apart from "unresolved".
- Line of sight for every leg of a packet route: clear / marginal /
blocked chips (first-Fresnel clearance, k=4/3), obstruction markers on
the map, docked terrain-profile panel with antenna/frequency inputs and
a &los= deep link. Backed by GET /api/elevation/profile, an Open-Meteo
proxy that only accepts known node positions, with weighted budgets,
back-off and a per-IP limit.
Repeater planner (#/tools/planner)
- Chain: LOS on every leg between any number of points or nodes.
- Relay: best single relay for A→B among known repeaters and open
terrain.
- Area: suggested new repeater sites that best join the existing
repeater backbone in a box up to 100×100 km, picked greedily to merge
clusters, then remove single points of failure, then reach unlinked
repeaters.
- Terrain: SRTM 1° tiles from AWS Open Data, in memory only (~90 m,
bounded LRU); the server stays read-only. Exact-length gunzip, fetch
budget with back-off, missing terrain reported rather than read as sea
level, fuzzed pixel maths.
- GET /api/planner/{profile,relay,coverage}: quantised cache keys, 202 +
progress then cached 200, separate compute slots, per-IP and global
limits, failed jobs remembered, unpolled jobs cancelled. Nodes pass the
same blacklist / hidden-name / geo_filter rules as /api/nodes. The Go
LOS maths matches public/los.js on shared test vectors.
Also: the per-IP client limiter is extracted from elevation.go into
client_limit.go (behaviour-preserving) so both features share it.
Perf (real SRTM): coverage cold 1.5-5.6 s (tile download), warm 10 ms;
worst real compute 545 ms; peak RSS 91 MiB; live /api/nodes and
/api/packets p95 at most 1.6x while a job computes (GOMAXPROCS=2).
Tests: Go suites for elevation, terrain (fuzz), LOS vectors, graph
(brute-force property test), search and planner API; frontend unit
suites in test-all.sh; Playwright e2e for route LOS and the planner.
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: efiten <erwin.fiten@gmail.com>
125 lines
4.0 KiB
Go
125 lines
4.0 KiB
Go
package main
|
|
|
|
// Radio line-of-sight (LOS) for packet routes on the map. OPT-IN, like
|
|
// rfParams (#1268): without los.enabled the server fetches nothing,
|
|
// /api/elevation/profile answers 404 and /api/config/client omits "los", so
|
|
// the frontend shows no LOS UI at all.
|
|
//
|
|
// The server only supplies terrain elevation along each leg (elevation.go),
|
|
// read from the SRTM tiles the planner uses (terrain_config.go: one shared
|
|
// source, in memory, never written to disk or the DB). Earth curvature, the
|
|
// Fresnel zone and the verdict are computed in the browser (public/los.js) so
|
|
// the antenna-height and frequency inputs re-render instantly.
|
|
|
|
import (
|
|
"log"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
defaultLOSFrequencyMHz = 910.525
|
|
defaultLOSAntennaM = 5.0
|
|
defaultLOSKFactor = 4.0 / 3.0
|
|
|
|
// losMaxPoints caps the route points in one profile request (so at most
|
|
// losMaxPoints-1 legs).
|
|
losMaxPoints = 16
|
|
// losMaxLegKm: longer legs are not real LoRa links worth a profile; they
|
|
// come back with error "too_long" and load no terrain.
|
|
losMaxLegKm = 300.0
|
|
// losMaxTiles caps the distinct 1° SRTM tiles one profile request may
|
|
// load; a leg that would take the request past it is "too_many_tiles".
|
|
// A 300 km leg's samples fall in about 10 tiles within the SRTM band. The
|
|
// shared source keeps at least this many resident (terrainViewTiles).
|
|
losMaxTiles = 16
|
|
// losTileWait is how long a request waits for its tiles before it
|
|
// answers 202; the downloads carry on without it.
|
|
losTileWait = 1500 * time.Millisecond
|
|
// losPollAfterS is the 202's retry_after_s.
|
|
losPollAfterS = 2
|
|
)
|
|
|
|
// LOSConfig is the "los" block in config.json. Terrain tiles come from the
|
|
// "terrain" block (TerrainConfig).
|
|
type LOSConfig struct {
|
|
Enabled bool `json:"enabled"`
|
|
FrequencyMHz float64 `json:"frequencyMhz"`
|
|
AntennaHeightM float64 `json:"antennaHeightM"`
|
|
KFactor float64 `json:"kFactor"`
|
|
}
|
|
|
|
func (c *LOSConfig) enabled() bool { return c != nil && c.Enabled }
|
|
|
|
// resolved returns the config with defaults applied and out-of-range values
|
|
// replaced by their default (logged once at startup by the caller).
|
|
func (c *LOSConfig) resolved() (LOSConfig, []string) {
|
|
out := LOSConfig{
|
|
FrequencyMHz: defaultLOSFrequencyMHz,
|
|
AntennaHeightM: defaultLOSAntennaM,
|
|
KFactor: defaultLOSKFactor,
|
|
}
|
|
var warns []string
|
|
if c == nil {
|
|
return out, nil
|
|
}
|
|
out.Enabled = c.Enabled
|
|
if c.FrequencyMHz != 0 {
|
|
if c.FrequencyMHz >= 100 && c.FrequencyMHz <= 6000 {
|
|
out.FrequencyMHz = c.FrequencyMHz
|
|
} else {
|
|
warns = append(warns, "los.frequencyMhz must be within 100-6000; using the default")
|
|
}
|
|
}
|
|
if c.AntennaHeightM != 0 {
|
|
if c.AntennaHeightM > 0 && c.AntennaHeightM <= 300 {
|
|
out.AntennaHeightM = c.AntennaHeightM
|
|
} else {
|
|
warns = append(warns, "los.antennaHeightM must be within 0-300; using the default")
|
|
}
|
|
}
|
|
if c.KFactor != 0 {
|
|
if c.KFactor >= 0.5 && c.KFactor <= 10 {
|
|
out.KFactor = c.KFactor
|
|
} else {
|
|
warns = append(warns, "los.kFactor must be within 0.5-10; using the default")
|
|
}
|
|
}
|
|
return out, warns
|
|
}
|
|
|
|
// LOSClientConfig is /api/config/client "los"; present only when enabled.
|
|
type LOSClientConfig struct {
|
|
FrequencyMHz float64 `json:"frequencyMhz"`
|
|
AntennaHeightM float64 `json:"antennaHeightM"`
|
|
KFactor float64 `json:"kFactor"`
|
|
MaxPoints int `json:"maxPoints"`
|
|
MaxLegKm float64 `json:"maxLegKm"`
|
|
}
|
|
|
|
func (c *LOSConfig) clientConfig() *LOSClientConfig {
|
|
if !c.enabled() {
|
|
return nil
|
|
}
|
|
r, _ := c.resolved()
|
|
return &LOSClientConfig{
|
|
FrequencyMHz: r.FrequencyMHz,
|
|
AntennaHeightM: r.AntennaHeightM,
|
|
KFactor: r.KFactor,
|
|
MaxPoints: losMaxPoints,
|
|
MaxLegKm: losMaxLegKm,
|
|
}
|
|
}
|
|
|
|
// logLOSConfig reports the effective config once at startup.
|
|
func logLOSConfig(c *LOSConfig) {
|
|
if !c.enabled() {
|
|
return
|
|
}
|
|
r, warns := c.resolved()
|
|
for _, w := range warns {
|
|
log.Printf("[los] %s", w)
|
|
}
|
|
log.Printf("[los] enabled (%.3f MHz, antenna=%.1f m, k=%.3f, up to %d terrain tiles a request)",
|
|
r.FrequencyMHz, r.AntennaHeightM, r.KFactor, losMaxTiles)
|
|
}
|