-
-
Notifications
You must be signed in to change notification settings - Fork 188
Description
Restoring pgnInstances: Active Instance Tracking via FullSignalK
Context
The source-priority-ux branch originally built on top of the TypeBox PR (#2325), which migrated FullSignalK from @signalk/signalk-schema (npm package) into @signalk/server-api as TypeScript source. This allowed us to extend handleNmea2000Source with continuous pgnInstances tracking.
When we rebased source-priority-ux onto master without TypeBox, we lost this capability because FullSignalK is back in @signalk/signalk-schema and cannot be modified.
What was lost
In the TypeBox version, packages/server-api/src/fullsignalk.ts had this addition inside handleNmea2000Source:
// Accumulate data instances per PGN for conflict detection.
if (source.instance !== undefined) {
const pi = (existing.n2k.pgnInstances ??= {} as Record<string, number[]>)
const pgn = String(source.pgn)
const arr = (pi[pgn] ??= [])
const inst = Number(source.instance)
if (!isNaN(inst) && !arr.includes(inst)) {
arr.push(inst)
}
}This ran on every N2K delta, continuously building up which data instances each device uses per PGN. The result was available via /signalk/v1/api/sources in the pgnInstances field of each device's n2k object.
Current fallback
sourceLabels.ts already has a fallback path:
const aInst = a.pgnInstances?.[pgn] ?? pgnDataInstances?.[a.src ?? '']?.[pgn]The pgnDataInstances comes from n2k-discovery.ts, which listens to the N2K bus for a fixed duration when the user clicks "Discover" in the Source Discovery UI. This is a point-in-time snapshot, not continuous.
What to restore when TypeBox merges
When the TypeBox PR merges and FullSignalK is back in server-api as TypeScript:
-
Re-add the
pgnInstancestracking block tohandleNmea2000Sourceinpackages/server-api/src/fullsignalk.ts(code above) -
The
N2kDeviceInfointerface inpackages/server-admin-ui/src/utils/sourceLabels.tsalready has thepgnInstancesfield — no change needed -
The
sourceLabels.tsconflict detection already preferspgnInstancesoverpgnDataInstances— no change needed -
The Sources REST API (
/signalk/v1/api/sources) will automatically includepgnInstancesbecause it returnsFullSignalK.retrieve().sources
In short: just restore the one code block in handleNmea2000Source and everything else reconnects automatically.