feat(decoder): warn when the decoder's clock is off (1.42.4)
The decoder's time is never changed. Passings (also during warm-up) measure it against the computer's clock, and Race Day's preflight and the decoder diagnostics warn when it is over a minute off, e.g. after the switch to winter time.
This commit is contained in:
1 parent
ca88fd9ecc
commit
35eb3eb059
14 files changed
+180
-5
No files matched your search
@@ -452,6 +452,8 @@ const processDecoderMessage = (msg, decoderRole = "main") => processDecoderMessa
|
||||
triggerRaceAudio,
|
||||
getTrackRecordMs,
|
||||
onTransponderSeen,
|
||||
// Race Day's preflight shows the decoder clock warning from warm-up passings, before a start.
|
||||
onDecoderClockChange: () => { if (currentView === "race_day") renderView(); },
|
||||
}, decoderRole);
|
||||
const renderDashboard = () => renderDashboardView({ addTrackLayout, startPracticeNow, state, dom, t, backend, getActiveSession, getStatusLabel, getSessionTypeLabel, getEventName, getModeLabel, getBackendUrl, formatLap, renderSessionsTable, setCurrentView: (view) => { currentView = view; }, updateViewUrl, renderNav, renderView, connectDecoder, disconnectDecoder, openOverlayWindow, ensureAudioContext, playPassingBeep, playFinishSiren, escapeHtml });
|
||||
const renderClasses = () => renderClassesView({ state, dom, t, selectedClassEditId: () => selectedClassEditId, setSelectedClassEditId: (value) => { selectedClassEditId = value; }, uid, saveState, renderView, renderTable, escapeHtml, setFormError, bindModalShell });
|
||||
@@ -809,6 +811,9 @@ const TRANSLATIONS = {
|
||||
"race_day.check_error": "Måste åtgärdas",
|
||||
"race_day.check_session": "Session vald",
|
||||
"race_day.check_backend": "Backend och automatisk backup",
|
||||
"race_day.check_decoder_clock": "Decoderns klocka",
|
||||
"race_day.decoder_clock_ahead": "{amount} före datorn – ställ in rätt tid i decodern (sommar-/vintertid?). Första varvet i ett heat och passen i mobilprofilen blir fel.",
|
||||
"race_day.decoder_clock_behind": "{amount} efter datorn – ställ in rätt tid i decodern (sommar-/vintertid?). Första varvet i ett heat och passen i mobilprofilen blir fel.",
|
||||
"race_day.check_decoder": "Main decoder",
|
||||
"race_day.check_split_decoder": "Mellantidsdecoder",
|
||||
"race_day.check_pit_decoders": "Depådecoders",
|
||||
@@ -2648,6 +2653,9 @@ const TRANSLATIONS = {
|
||||
"race_day.check_error": "Must be fixed",
|
||||
"race_day.check_session": "Session selected",
|
||||
"race_day.check_backend": "Backend and automatic backup",
|
||||
"race_day.check_decoder_clock": "Decoder clock",
|
||||
"race_day.decoder_clock_ahead": "{amount} ahead of the computer – set the decoder's clock (summer/winter time?). A heat's first lap and passes in the mobile profile go wrong.",
|
||||
"race_day.decoder_clock_behind": "{amount} behind the computer – set the decoder's clock (summer/winter time?). A heat's first lap and passes in the mobile profile go wrong.",
|
||||
"race_day.check_decoder": "Main decoder",
|
||||
"race_day.check_split_decoder": "Split decoder",
|
||||
"race_day.check_pit_decoders": "Pit decoders",
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// The decoder's clock is the source of truth for timing and is never changed by RaceCore. It
|
||||
// is set by hand (it doesn't follow summer/winter time), and when it is off, everything that
|
||||
// compares a passing with "now" goes wrong: a heat's first lap from the start signal, a
|
||||
// practice pass on the phone, Even laps. Lap times themselves (two decoder times) stay right,
|
||||
// which is why it goes unnoticed. This only measures how far off it is, to warn about it.
|
||||
export const DECODER_CLOCK_WARNING_MS = 60 * 1000;
|
||||
const SAMPLES = 5;
|
||||
|
||||
export function createDecoderClockCheck() {
|
||||
const samples = new Map();
|
||||
return {
|
||||
// rawTs: the decoder's own time for a passing, receivedAt: the computer's clock on arrival.
|
||||
record(role, rawTs, receivedAt = Date.now()) {
|
||||
if (!Number.isFinite(rawTs)) return;
|
||||
const list = samples.get(role) || [];
|
||||
list.push(receivedAt - rawTs);
|
||||
if (list.length > SAMPLES) list.shift();
|
||||
samples.set(role, list);
|
||||
},
|
||||
// How far the decoder is behind the computer (ms; negative = ahead), or null before any
|
||||
// passing. The smallest recent sample: a passing delivered late (resent after a reconnect)
|
||||
// only makes the decoder look further behind than it is.
|
||||
skewMs(role) {
|
||||
const list = samples.get(role);
|
||||
return list?.length ? Math.min(...list) : null;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// null when the clocks agree; otherwise how far and which way the decoder is off.
|
||||
export function describeDecoderClockSkew(skewMs) {
|
||||
if (!Number.isFinite(skewMs) || Math.abs(skewMs) < DECODER_CLOCK_WARNING_MS) return null;
|
||||
const totalMinutes = Math.round(Math.abs(skewMs) / 60000);
|
||||
return { ahead: skewMs < 0, hours: Math.floor(totalMinutes / 60), minutes: totalMinutes % 60 };
|
||||
}
|
||||
|
||||
export const decoderClockCheck = createDecoderClockCheck();
|
||||
@@ -1,4 +1,5 @@
|
||||
import { decoderDiagnostics, DIAGNOSTIC_ROLES } from "./decoder_diagnostics.js";
|
||||
import { decoderClockCheck, describeDecoderClockSkew } from "./decoder_clock_check.js";
|
||||
|
||||
let stopPrevious = () => {};
|
||||
export function decoderDiagnosticsMarkup(language) {
|
||||
@@ -63,9 +64,18 @@ export function mountDecoderDiagnostics(root, getSettings) {
|
||||
if (!force && (paused || !root.open)) return;
|
||||
const settings = getSettings();
|
||||
const entries = decoderDiagnostics.snapshot();
|
||||
// The decoder's clock against the computer's, measured on passings (decoder_clock_check.js).
|
||||
const clockLine = (role) => {
|
||||
const skew = decoderClockCheck.skewMs(role);
|
||||
if (skew == null) return `${tr("Decoderklocka", "Decoder clock")}: -`;
|
||||
const off = describeDecoderClockSkew(skew);
|
||||
if (!off) return `${tr("Decoderklocka", "Decoder clock")}: ${tr("stämmer med datorn", "matches the computer")}`;
|
||||
const amount = `${off.hours ? `${off.hours} h ` : ""}${off.minutes ? `${off.minutes} min` : ""}`.trim();
|
||||
return `${tr("Decoderklocka", "Decoder clock")}: ${amount} ${off.ahead ? tr("före", "ahead of") : tr("efter", "behind")} ${tr("datorn – ställ in rätt tid i decodern", "the computer – set the right time in the decoder")}`;
|
||||
};
|
||||
entries.forEach((entry, i) => {
|
||||
const enabled = i === 0 || (i === 1 ? settings.splitDecoderEnabled : settings.pitDecoderEnabled);
|
||||
nodes[i].textContent = `${names[i]}: ${enabled ? statuses[entry.status] || entry.status : tr("Avstängd", "Disabled")}\n${tr("Konfigurerad", "Configured")}: ${settings[urlKeys[i]] || "-"}\n${tr("Socket-adress", "Socket address")}: ${entry.url || "-"}\n${tr("Senast ansluten", "Last connected")}: ${date(entry.connectedAt)}\n${tr("Senast mottaget", "Last received")}: ${date(entry.lastReceivedAt)} (${entry.lastReceivedAt == null ? "-" : Math.max(0, Math.floor((Date.now() - entry.lastReceivedAt) / 1000))} s)\nFrames: ${entry.frames} | PASSING: ${entry.passings}\n${tr("Hanterade", "Handled")}: ${entry.handled} | ${tr("Ignorerade", "Ignored")}: ${entry.ignored}\n${tr("Ogiltiga varv", "Invalid laps")}: ${entry.invalid} | JSON ${tr("fel", "errors")}: ${entry.parseErrors}`;
|
||||
nodes[i].textContent = `${names[i]}: ${enabled ? statuses[entry.status] || entry.status : tr("Avstängd", "Disabled")}\n${tr("Konfigurerad", "Configured")}: ${settings[urlKeys[i]] || "-"}\n${tr("Socket-adress", "Socket address")}: ${entry.url || "-"}\n${tr("Senast ansluten", "Last connected")}: ${date(entry.connectedAt)}\n${tr("Senast mottaget", "Last received")}: ${date(entry.lastReceivedAt)} (${entry.lastReceivedAt == null ? "-" : Math.max(0, Math.floor((Date.now() - entry.lastReceivedAt) / 1000))} s)\nFrames: ${entry.frames} | PASSING: ${entry.passings}\n${tr("Hanterade", "Handled")}: ${entry.handled} | ${tr("Ignorerade", "Ignored")}: ${entry.ignored}\n${tr("Ogiltiga varv", "Invalid laps")}: ${entry.invalid} | JSON ${tr("fel", "errors")}: ${entry.parseErrors}\n${clockLine(entry.role)}`;
|
||||
});
|
||||
const entry = entries.find(item => item.role === select.value);
|
||||
log.textContent = `${tr("Senaste råmeddelande (max 512 tecken)", "Latest raw frame (max 512 characters)")}:\n${entry.lastFrame || "-"}\n\n${tr("Senaste 50 händelser; orsakskoder", "Latest 50 events; reason codes")}:\n${entry.log.map(item => `${date(item.at)} ${item.reason} ${item.sample}`).join("\n")}`;
|
||||
|
||||
+13
-1
@@ -4,6 +4,7 @@ import { usesPersonalClock, getLatestClockStartTs } from "./prologue_logic.js";
|
||||
import { isSuspectLap, getSuspectReferenceLaps } from "./suspect_laps_logic.js";
|
||||
import { shouldCallPracticePersonalBest } from "./practice_callouts_logic.js";
|
||||
import { normalizeRaceAudioSettings } from "./race_audio.js";
|
||||
import { decoderClockCheck, describeDecoderClockSkew } from "./decoder_clock_check.js";
|
||||
|
||||
const PRACTICE_SESSION_TYPES = new Set(["open_practice", "free_practice", "practice"]);
|
||||
// Last personal best *called* per driver, per practice day and layout (practice_callouts_logic.js).
|
||||
@@ -287,6 +288,7 @@ export function processDecoderMessageHelper(msg, deps, decoderRole = "main") {
|
||||
formatLap, announcePassing, saveState, lastOverlayLeaderKeyBySession,
|
||||
lastOverlayTop3BySession, lastOverlayBestLapByKey, triggerRaceAudio = () => {}, getTrackRecordMs = () => null,
|
||||
onTransponderSeen = () => {},
|
||||
onDecoderClockChange = () => {},
|
||||
} = deps;
|
||||
|
||||
const report = (reason, outcome) => decoderDiagnostics.message(decoderRole, msg, reason, outcome);
|
||||
@@ -309,13 +311,23 @@ export function processDecoderMessageHelper(msg, deps, decoderRole = "main") {
|
||||
if (seenTransponder) onTransponderSeen(seenTransponder);
|
||||
}
|
||||
|
||||
// The decoder's clock against the computer's - only measured, never changed: the decoder is
|
||||
// the source of truth. Before the running-session check so Race Day can warn before a start.
|
||||
const rtcTs = parseRtcTime(msg.rtc_time);
|
||||
decoderClockCheck.record(decoderRole, rtcTs);
|
||||
if (decoderRole === "main" && state.decoder) {
|
||||
const before = JSON.stringify(describeDecoderClockSkew(state.decoder.clockSkewMs));
|
||||
state.decoder.clockSkewMs = decoderClockCheck.skewMs("main");
|
||||
if (JSON.stringify(describeDecoderClockSkew(state.decoder.clockSkewMs)) !== before) onDecoderClockChange();
|
||||
}
|
||||
|
||||
const session = getActiveSession();
|
||||
if (!session || session.status !== "running") {
|
||||
report("no_running_session");
|
||||
return;
|
||||
}
|
||||
|
||||
const timestamp = parseRtcTime(msg.rtc_time) || Date.now();
|
||||
const timestamp = rtcTs || Date.now();
|
||||
const transponder = String(msg.transponder ?? msg.tran_code ?? "").replace("ID:", "").trim();
|
||||
if (!transponder) {
|
||||
report("missing_transponder");
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { describeDecoderClockSkew } from "./decoder_clock_check.js";
|
||||
import { getLayoutLapWindowOverride } from "./track_layouts_logic.js";
|
||||
function unique(values) {
|
||||
return [...new Set(values.map((value) => String(value || "").trim()).filter(Boolean))];
|
||||
@@ -60,6 +61,10 @@ export function buildRaceDayPreflight(state, session, { backendAvailable = false
|
||||
check("backend", backendAvailable ? "ok" : "warning"),
|
||||
check("decoder", state?.decoder?.connected ? "ok" : "error"),
|
||||
];
|
||||
// The decoder's clock against the computer's (decoder_clock_check.js): when it is off, a
|
||||
// heat's first lap from the start signal and passes on the phone go wrong.
|
||||
const clockOff = describeDecoderClockSkew(state?.decoder?.clockSkewMs);
|
||||
if (clockOff) checks.push(check("decoder_clock", "warning", clockOff));
|
||||
|
||||
if (state?.settings?.splitDecoderEnabled) {
|
||||
checks.push(check("split_decoder", state?.decoder?.splitConnected ? "ok" : "warning"));
|
||||
|
||||
@@ -37,6 +37,10 @@ function renderPreflightDetail(item, { t, formatLap, escapeHtml }) {
|
||||
if (item.id === "duplicate_transponders" && item.duplicates?.length) return escapeHtml(item.duplicates.join(", "));
|
||||
if (item.id === "duplicate_team_members" && item.duplicateTeamMemberNames?.length) return escapeHtml(item.duplicateTeamMemberNames.join(", "));
|
||||
if (item.id === "transponder_check") return `${item.seen}/${item.total}`;
|
||||
if (item.id === "decoder_clock") {
|
||||
const amount = `${item.hours ? `${item.hours} h ` : ""}${item.minutes ? `${item.minutes} min` : ""}`.trim();
|
||||
return t(item.ahead ? "race_day.decoder_clock_ahead" : "race_day.decoder_clock_behind", { amount });
|
||||
}
|
||||
if (item.id === "grid") return item.notRequired ? t("race_day.not_required") : `${item.count || 0}/${item.expectedCount || 0}`;
|
||||
return t(`race_day.check_${item.level}`);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user