@sailingrotevista/rotevista-dash 6.2.2 → 6.2.3
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/index.js +61 -24
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -338,31 +338,45 @@ module.exports = function (app) {
|
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
340
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
341
|
+
// Validazione e clamping di sicurezza (non si applica all'oggetto TWD)
|
|
342
|
+
if (!isTwdType) {
|
|
343
|
+
if (!isFinite(finalValue)) return;
|
|
344
|
+
finalValue = Math.max(0, finalValue);
|
|
345
|
+
histories[type].push({ val: finalValue, time: now });
|
|
346
|
+
|
|
347
|
+
// EMISSIONE DEL DELTA: Se abbiamo calcolato il TWS di fallback, lo trasmettiamo a Signal K
|
|
348
|
+
if (type === 'tws' && (now - lastNativeTwsTime > 5000)) {
|
|
349
|
+
emitDelta('environment.wind.speedTrue', finalValue / 1.94384); // Converte nodi in m/s
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
// Salvataggio specifico del TWD contenente l'oggetto { val, min, max, time }
|
|
353
|
+
histories['twd'].push({
|
|
354
|
+
val: finalValue.val,
|
|
355
|
+
min: finalValue.min,
|
|
356
|
+
max: finalValue.max,
|
|
357
|
+
time: now
|
|
358
|
+
});
|
|
354
359
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
360
|
+
// EMISSIONE DEL DELTA: Se abbiamo calcolato il TWD di fallback, lo trasmettiamo a Signal K
|
|
361
|
+
if (now - lastNativeTwdTime > 5000) {
|
|
362
|
+
emitDelta('environment.wind.directionTrue', {
|
|
363
|
+
val: finalValue.val,
|
|
364
|
+
min: finalValue.min,
|
|
365
|
+
max: finalValue.max
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// --- TRIGGER DI CONGELAMENTO ARCO (Ogni :00 e :30 dell'orologio) ---
|
|
370
|
+
const current30mSlot = Math.floor(now / 1800000) * 1800000;
|
|
371
|
+
if (lastFrozen30mSlot === 0) {
|
|
372
|
+
lastFrozen30mSlot = current30mSlot; // Inizializzazione al primo avvio
|
|
373
|
+
} else if (current30mSlot > lastFrozen30mSlot) {
|
|
374
|
+
// Lo slot da 30 minuti precedente (lastFrozen30mSlot) si è appena concluso!
|
|
375
|
+
// Avviamo la procedura di compressione e congelamento dei dati di quel periodo
|
|
376
|
+
freeze30mSlot(lastFrozen30mSlot);
|
|
377
|
+
lastFrozen30mSlot = current30mSlot;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
366
380
|
|
|
367
381
|
// Pruning automatico basato sulle impostazioni di timeline
|
|
368
382
|
// (Forziamo il server a conservare sempre almeno 60 minuti per il TWD!)
|
|
@@ -730,6 +744,29 @@ module.exports = function (app) {
|
|
|
730
744
|
app.error('[Open-Meteo] Forecast matching slots not found for target time');
|
|
731
745
|
}
|
|
732
746
|
}
|
|
747
|
+
/**
|
|
748
|
+
* emitDelta: Scrive ed emette un aggiornamento di rotta direttamente nel
|
|
749
|
+
* server principale di Signal K per renderlo disponibile a tutti i client WebSocket.
|
|
750
|
+
*/
|
|
751
|
+
function emitDelta(path, value) {
|
|
752
|
+
if (typeof app.handleMessage === 'function') {
|
|
753
|
+
app.handleMessage(plugin.id, {
|
|
754
|
+
updates: [
|
|
755
|
+
{
|
|
756
|
+
source: { label: 'rotevista-dash-plugin' },
|
|
757
|
+
timestamp: new Date().toISOString(),
|
|
758
|
+
values: [
|
|
759
|
+
{
|
|
760
|
+
path: path,
|
|
761
|
+
value: value
|
|
762
|
+
}
|
|
763
|
+
]
|
|
764
|
+
}
|
|
765
|
+
]
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
733
770
|
|
|
734
771
|
return plugin;
|
|
735
772
|
};
|