mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-03-28 17:43:05 +01:00
Add multipath tracking
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { Contact, RadioConfig } from '../types';
|
||||
import type { Contact, RadioConfig, MessagePath } from '../types';
|
||||
import { CONTACT_TYPE_REPEATER } from '../types';
|
||||
|
||||
export interface PathHop {
|
||||
@@ -155,6 +155,33 @@ export function getHopCount(path: string | null | undefined): number {
|
||||
return Math.floor(path.length / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format hop counts from multiple paths for display.
|
||||
* Returns something like "d/1/3/3" for direct, 1-hop, 3-hop, 3-hop paths.
|
||||
* Returns null if no paths or only direct.
|
||||
*/
|
||||
export function formatHopCounts(paths: MessagePath[] | null | undefined): {
|
||||
display: string;
|
||||
allDirect: boolean;
|
||||
hasMultiple: boolean;
|
||||
} {
|
||||
if (!paths || paths.length === 0) {
|
||||
return { display: '', allDirect: true, hasMultiple: false };
|
||||
}
|
||||
|
||||
// Get hop counts for all paths and sort ascending
|
||||
const hopCounts = paths.map((p) => getHopCount(p.path)).sort((a, b) => a - b);
|
||||
|
||||
const allDirect = hopCounts.every((h) => h === 0);
|
||||
const hasMultiple = paths.length > 1;
|
||||
|
||||
// Format: "d" for 0, numbers for others
|
||||
const parts = hopCounts.map((h) => (h === 0 ? 'd' : h.toString()));
|
||||
const display = parts.join('/');
|
||||
|
||||
return { display, allDirect, hasMultiple };
|
||||
}
|
||||
|
||||
/**
|
||||
* Build complete path resolution with sender, hops, and receiver
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user