feat: include snr in trace route hops

closes: #43
This commit is contained in:
Enot (ded) Skelly
2026-06-06 13:30:59 -07:00
parent 5247e4c3a8
commit 610b941afb
2 changed files with 10 additions and 6 deletions
+8 -5
View File
@@ -26,8 +26,6 @@ func New(pool *pgxpool.Pool) *Store {
return &Store{q: sqlc.New(pool)}
}
// ResolvePathHashes returns a map of hex-encoded path hash → matching node entries for
// the given IATA. Hash size is inferred from the length of the first element in hashes.
func (s *Store) ResolvePathHashes(ctx context.Context, iata string, hashes [][]byte) (map[string][]api.ResolvedPathEntry, error) {
if len(hashes) == 0 {
return nil, nil
@@ -99,8 +97,9 @@ func toChannelMessage(id int64, packetHashHex string, channelHash []byte, sender
// Returns nil if the payload cannot be parsed or contains no path hashes.
func (s *Store) resolveTraceRoute(ctx context.Context, parsedPayload []byte, iatas []string) []api.ResolvedHop {
var tracePayload struct {
PathHashes []string `json:"pathHashes"`
Flags byte `json:"flags"`
PathHashes []string `json:"pathHashes"`
Flags byte `json:"flags"`
SNRValues []float32 `json:"snrValues"`
}
if err := json.Unmarshal(parsedPayload, &tracePayload); err != nil || len(tracePayload.PathHashes) == 0 {
return nil
@@ -145,11 +144,15 @@ func (s *Store) resolveTraceRoute(ctx context.Context, parsedPayload []byte, iat
}
}
route := make([]api.ResolvedHop, 0, len(hashes))
for _, hr := range merged {
for i, hr := range merged {
hop := api.ResolvedHop{
Confidence: hr.confidence,
Nodes: make([]api.ResolvedNode, 0, len(hr.entries)),
}
if i < len(tracePayload.SNRValues) {
snr := tracePayload.SNRValues[i]
hop.SNR = &snr
}
for _, e := range hr.entries {
hop.Nodes = append(hop.Nodes, api.ResolvedNode{
ID: e.NodeID,
+2 -1
View File
@@ -68,7 +68,8 @@ type PacketRadio struct {
// Confidence is "high" (exactly one match), "ambiguous" (multiple matches), or "none" (no match).
type ResolvedHop struct {
Confidence string `json:"confidence"` // "high", "ambiguous", or "none"
Nodes []ResolvedNode `json:"nodes"` // empty for "none", one for "high", multiple for "ambiguous"
SNR *float32 `json:"snr,omitempty"`
Nodes []ResolvedNode `json:"nodes"` // empty for "none", one for "high", multiple for "ambiguous"
}
// ResolvedNode is a node reference within a resolved path hop.