fix(devices): Hikvision clock sync owns the time zone (fixed offset, re-set at DST edges)

park-2's cameras burned Beijing time into every frame: factory zone CST-8,
and the sync compared instants only, so zero drift meant the zone was never
touched. The G3H firmware also accepts a POSIX zone with a DST rule, echoes
it back, and ignores the rule.

syncClock now derives the site's current UTC offset as a fixed Hikvision
zone (hikvisionFixedZone) and rewrites it when it differs, sending the clock
with it. The device monitor adds a third trigger beside offline->ready and
the 24h backstop: the moment the site's UTC offset changes, so a DST switch
is handled within one poll. ClockSyncResult reports zoneChanged/timeZone.

Both park-2 cameras were set to CST-2:00:00 by hand on 2026-10-09; this
must be deployed there before 2026-10-25 or the OSD reads 1h ahead from
that day until it is.
This commit is contained in:
2026-10-11 18:17:25 +02:00
parent 9332802e5d
commit 7b29331f52
5 changed files with 163 additions and 31 deletions
+21 -7
View File
@@ -231,14 +231,28 @@ Built: the HOST is the site's time authority (offline-first — no NTP infra dep
device monitor re-syncs each Hikvision camera over the same Digest-auth ISAPI used for snapshots:
- **Trigger:** the camera's **offline → ready transition** (exactly the power-restored moment) +
a **24h backstop**; the attempt timestamp is stamped BEFORE the async call, so a failing camera
retries at backstop cadence, never every 8s poll.
- **Mechanics** (`HikvisionCamera.syncClock`): `GET /ISAPI/System/time`, parse `localTime`; drift ≤
60s → leave alone. Beyond that → `PUT /ISAPI/System/time` with `timeMode=manual`, the site's
a **24h backstop** + **the site's UTC-offset edge** (a DST switch, checked every poll from
`localIsoWithOffset(siteTz)`); the attempt timestamp is stamped BEFORE the async call, so a
failing camera retries at backstop cadence, never every 8s poll.
- **Mechanics** (`HikvisionCamera.syncClock`): `GET /ISAPI/System/time`, parse `localTime` and
`timeZone`. The wanted zone is the site's **current offset as a fixed zone**
(`hikvisionFixedZone`: `+02:00` → `CST-2:00:00`, `+01:00` → `CST-1:00:00`; Hikvision's inverted
POSIX sign; the abbreviation is cosmetic — the camera renames whatever is sent to `CST`). Zone
differs → `PUT /ISAPI/System/time` with `timeMode=manual`, the wanted zone, and the site's
wall-clock now WITH explicit utc offset (`localIsoWithOffset(siteTz)`, e.g.
`2026-07-07T15:30:22+02:00` — the offset makes the instant unambiguous), and the camera's own
`timeZone` string **echoed back verbatim** (we correct the clock, never fight its tz/DST config).
An unparseable camera reply counts as infinite drift → sync.
`2026-07-07T15:30:22+02:00` — the offset makes the instant unambiguous whatever zone the
camera applies). Zone right and drift ≤ 60s → leave alone; drift beyond → the same PUT. An
unparseable camera reply counts as infinite drift → sync. The result carries `zoneChanged` +
`timeZone`; the monitor logs a zone rewrite at **warn**.
- **Why the host owns the zone (2026-10-09, park-2):** both cameras ran the **factory `CST-8:00:00`
(Beijing)** — the instant was right, so the drift check never fired, while the OSD burned into
every snapshot read **six hours ahead** of the booth (the operator's "barrier opened by itself"
claim was argued against camera footage stamped 21:45 for a 15:45 event). The earlier design
"echo the camera's zone verbatim" could never fix that. And this firmware (DS-2CD1047G3H)
**ignores the DST rule in a POSIX zone string**: `CET-1:00:00DST01:00:00,M3.5.0/02:00:00,M10.5.0/03:00:00`
was accepted and echoed back, but `localTime` and the OSD stayed on +01:00 in October. Hence a
fixed offset rewritten by the host at each DST edge, not a camera-side rule. Applied by hand to
both park-2 cameras the same day (`PUT` with `CST-2:00:00`); the deploy keeps it so.
- **Visibility:** a sync after a big jump (>1h — the power-cut signature) logs at **warn**
(persisted to app_logs); small corrections log info. Failures log warn.
- **Scope:** Hikvision only (`isClockSyncable` capability guard); the Dahua driver's CGI has no