@sailingrotevista/rotevista-dash 7.0.30 → 7.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.js +12 -8
- package/index.js +7 -2
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -348,15 +348,17 @@ function processIncomingData(path, val, source, timeMs) {
|
|
|
348
348
|
} else {
|
|
349
349
|
const currentLock = sourceLocks[path];
|
|
350
350
|
const isSameSource = (currentLock.label === source);
|
|
351
|
-
const isLockExpired = (now - currentLock.lastSeen > 12000); // Scadenza a 12 secondi
|
|
351
|
+
const isLockExpired = (now - currentLock.lastSeen > 12000); // Scadenza a 12 secondi
|
|
352
352
|
const hasHigherPriority = (score > currentLock.score);
|
|
353
|
+
// Consente lo switch tra dispositivi di pari priorità (es. AP e YD) se la sorgente precedente è inattiva da > 1.5s
|
|
354
|
+
const isSamePriorityStale = (score === currentLock.score && (now - currentLock.lastSeen > 1500));
|
|
353
355
|
|
|
354
356
|
if (isSameSource) {
|
|
355
357
|
// Stessa sorgente: aggiorna il timestamp e mantiene il blocco
|
|
356
358
|
currentLock.lastSeen = now;
|
|
357
359
|
currentLock.score = score;
|
|
358
|
-
} else if (isLockExpired || hasHigherPriority) {
|
|
359
|
-
// Ruba il blocco se la sorgente precedente è scaduta o
|
|
360
|
+
} else if (isLockExpired || hasHigherPriority || isSamePriorityStale) {
|
|
361
|
+
// Ruba il blocco se la sorgente precedente è scaduta, ha priorità superiore o è inattiva da 1.5s a pari priorità
|
|
360
362
|
sourceLocks[path] = { label: source, score: score, lastSeen: now };
|
|
361
363
|
console.log(`🔌 [Smart Lock] Path "${path}" switched to: ${source} (Score: ${score})`);
|
|
362
364
|
} else {
|
|
@@ -410,19 +412,21 @@ function processIncomingData(path, val, source, timeMs) {
|
|
|
410
412
|
|
|
411
413
|
// --- GESTIONE PRUA VERA / MAGNETICA CON AUTODIVIAZIONE ---
|
|
412
414
|
if (path === "navigation.headingTrue") {
|
|
415
|
+
store.timestamps["navigation.headingTrueNative"] = now; // Marca la presenza di un sensore nativo di prua vera
|
|
416
|
+
store.timestamps["navigation.headingTrue"] = now;
|
|
413
417
|
safePush(store.smoothBuf.hdg, val, now);
|
|
414
418
|
safePush(store.longBuf.hdg, val, now);
|
|
415
419
|
}
|
|
416
420
|
else if (path === "navigation.headingMagnetic") {
|
|
417
|
-
// Se non
|
|
418
|
-
const
|
|
419
|
-
if (!
|
|
421
|
+
// Se non c'è una prua vera NATIVA negli ultimi 5 secondi, converte e registra ad ogni secondo la prua magnetica
|
|
422
|
+
const hasNativeTrueHdg = store.timestamps["navigation.headingTrueNative"] && (now - store.timestamps["navigation.headingTrueNative"] < 5000);
|
|
423
|
+
if (!hasNativeTrueHdg) {
|
|
420
424
|
const variation = store.raw["navigation.magneticVariation"] || 0; // Legge la declinazione magnetica del GPS
|
|
421
425
|
const calculatedTrueHdg = (val + variation + 2 * Math.PI) % (2 * Math.PI);
|
|
422
426
|
|
|
423
|
-
//
|
|
427
|
+
// Registra il valore calcolato mantenendo attivo il watchdog senza bloccare i successivi pacchetti magnetici
|
|
424
428
|
store.raw["navigation.headingTrue"] = calculatedTrueHdg;
|
|
425
|
-
store.timestamps["navigation.headingTrue"] = now;
|
|
429
|
+
store.timestamps["navigation.headingTrue"] = now;
|
|
426
430
|
safePush(store.smoothBuf.hdg, calculatedTrueHdg, now);
|
|
427
431
|
safePush(store.longBuf.hdg, calculatedTrueHdg, now);
|
|
428
432
|
}
|
package/index.js
CHANGED
|
@@ -38,6 +38,7 @@ module.exports = function (app) {
|
|
|
38
38
|
// Memoria temporale per rilevare la presenza di sensori nativi sul Cerbo
|
|
39
39
|
let lastNativeTwsTime = 0;
|
|
40
40
|
let lastNativeTwdTime = 0;
|
|
41
|
+
let lastNativeHeadingTrueTime = 0; // Traccia la presenza di bussola vera nativa
|
|
41
42
|
|
|
42
43
|
// Monitoraggio dello scorrere dei blocchi da 30 minuti
|
|
43
44
|
let lastFrozen30mSlot = 0;
|
|
@@ -248,10 +249,14 @@ module.exports = function (app) {
|
|
|
248
249
|
lastNativeTwsTime = now; // Rilevato TWS nativo della centralina!
|
|
249
250
|
manageHistory('tws', smoothedVal * 1.94384);
|
|
250
251
|
}
|
|
252
|
+
else if (path === 'navigation.headingTrue') {
|
|
253
|
+
lastNativeHeadingTrueTime = now; // Rilevata prua vera nativa dalla rete NMEA
|
|
254
|
+
}
|
|
251
255
|
// --- DECODIFICA PRUA MAGNETICA SERVER-SIDE ---
|
|
252
256
|
else if (path === 'navigation.headingMagnetic') {
|
|
253
|
-
|
|
254
|
-
|
|
257
|
+
// Converte in prua vera solo se non c'è una bussola vera nativa attiva negli ultimi 5s
|
|
258
|
+
const hasNativeTrueHdg = (now - lastNativeHeadingTrueTime < 5000);
|
|
259
|
+
if (!hasNativeTrueHdg) {
|
|
255
260
|
const variation = raw['navigation.magneticVariation'] || 0;
|
|
256
261
|
raw['navigation.headingTrue'] = (smoothedVal + variation + 2 * Math.PI) % (2 * Math.PI);
|
|
257
262
|
}
|