fix(devices): Dahua snapshot channel is 1-based; add Dahua clock sync; wiki page for the bench IPC-HFW2549T
Build & push images / images (push) Successful in 3m25s
Build & push images / images (push) Successful in 3m25s
The dahua driver decremented the wizard's channel on the belief the CGI is 0-based. On real hardware (IPC-HFW2549T-AS-IL, fw V2.880, 2026-09-17) snapshot.cgi?channel=0 answers HTTP 400 and channel=1 returns the 2880x1620 JPEG — so every Dahua assignment sat at degraded "HTTP 400". The channel is now sent as entered (clamped >= 1) and the URL is pinned in camera.test.ts. DahuaCamera.syncClock reads global.cgi getCurrentTime and, past the drift limit, writes setCurrentTime with the host's naive local wall time (no offset): the OSD burned into snapshots must match the booth clock; the camera's tz/DST config is left alone. Verified live: a 2h-off set, set back, 1s drift -> no write. The device monitor picks it up via isClockSyncable unchanged. Wiki: new entities/dahua-ipc-hfw2549t.md (endpoint table, verbatim eventManager attach parts — VideoMotion Start/Stop, VideoMotionInfo, TimeChange — RealUTC is the camera's belief of UTC, 5-strike login lockout, unit not factory-fresh); lpr-camera Dahua bullet corrected; runbook §3 Dahua paragraph; index + log. The server-side attach-stream subscriber is not built.
This commit is contained in:
@@ -200,12 +200,97 @@ describe("hikvision syncClock — the 1970 power-cut recovery (ISAPI /System/tim
|
||||
await expect(cam().syncClock(HOST_NOW, 60)).rejects.toThrow("clock set failed: HTTP 403");
|
||||
});
|
||||
|
||||
it("the dahua driver does NOT claim the capability (no ISAPI time endpoint)", async () => {
|
||||
it("both camera drivers claim the capability (Dahua via global.cgi since 2026-09-17)", async () => {
|
||||
const { dahuaDriver, hikvisionDriver } = await import("./camera.js");
|
||||
const { isClockSyncable } = await import("../interfaces.js");
|
||||
const mk = (d: typeof dahuaDriver) =>
|
||||
d.create({ host: "10.0.10.12", port: 80, username: "admin", password: "x", channel: 1 });
|
||||
expect(isClockSyncable(mk(dahuaDriver))).toBe(false);
|
||||
expect(isClockSyncable(mk(dahuaDriver))).toBe(true);
|
||||
expect(isClockSyncable(mk(hikvisionDriver))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// Dahua — verified against an IPC-HFW2549T-AS-IL (fw 2.880) on 2026-09-17. The CGI
|
||||
// numbers snapshot channels from 1 (channel=0 → HTTP 400), ignores any stream
|
||||
// selector, and speaks NAIVE local wall time on global.cgi. See camera.ts and
|
||||
// wiki/entities/dahua-ipc-hfw2549t.md.
|
||||
describe("dahua snapshot URL — channel is 1-BASED, no stream selector", () => {
|
||||
async function pathFor(config: Record<string, unknown>): Promise<string> {
|
||||
const { dahuaDriver } = await import("./camera.js");
|
||||
digestGet.mockReset();
|
||||
digestGet.mockResolvedValue(reply(200));
|
||||
dahuaDriver.create(config as never).captureSnapshot({ direction: "entry" });
|
||||
return String((digestGet.mock.calls[0]![0] as { path: string }).path);
|
||||
}
|
||||
|
||||
it("channel 1 as entered → channel=1 (the old `ch - 1` sent 0 → HTTP 400 on hardware)", async () => {
|
||||
expect(await pathFor({ host: "1.2.3.4", channel: 1 })).toBe("/cgi-bin/snapshot.cgi?channel=1");
|
||||
});
|
||||
|
||||
it("defaults to channel 1 when none is configured", async () => {
|
||||
expect(await pathFor({ host: "1.2.3.4" })).toBe("/cgi-bin/snapshot.cgi?channel=1");
|
||||
});
|
||||
|
||||
it("channel 2 passes through; a stream setting is ignored", async () => {
|
||||
expect(await pathFor({ host: "1.2.3.4", channel: 2, stream: 2 })).toBe("/cgi-bin/snapshot.cgi?channel=2");
|
||||
});
|
||||
|
||||
it("a zero/negative channel is clamped to 1 rather than sent as-is", async () => {
|
||||
expect(await pathFor({ host: "1.2.3.4", channel: 0 })).toBe("/cgi-bin/snapshot.cgi?channel=1");
|
||||
});
|
||||
});
|
||||
|
||||
describe("dahua syncClock — global.cgi getCurrentTime/setCurrentTime, naive wall time", () => {
|
||||
const HOST_NOW = "2026-09-17T10:35:49+02:00";
|
||||
const timeReply = (naive: string) => reply(200, `result=${naive}\r\n`);
|
||||
|
||||
async function cam() {
|
||||
const { dahuaDriver } = await import("./camera.js");
|
||||
return dahuaDriver.create({ host: "10.0.10.11", port: 80, username: "admin", password: "x", channel: 1 }) as unknown as {
|
||||
syncClock(localIso: string, maxDriftSec: number): Promise<{ driftSeconds: number | null; synced: boolean }>;
|
||||
};
|
||||
}
|
||||
|
||||
it("in-sync camera: reads, does NOT set", async () => {
|
||||
digestRequest.mockResolvedValueOnce(timeReply("2026-09-17 10:35:40"));
|
||||
const r = await (await cam()).syncClock(HOST_NOW, 60);
|
||||
expect(r).toEqual({ driftSeconds: 9, synced: false });
|
||||
expect(digestRequest).toHaveBeenCalledTimes(1);
|
||||
const get = digestRequest.mock.calls[0]![0] as { method: string; path: string };
|
||||
expect(get.method).toBe("GET");
|
||||
expect(get.path).toBe("/cgi-bin/global.cgi?action=getCurrentTime");
|
||||
});
|
||||
|
||||
it("an hour behind (the bench unit: DST off, NTP off) → sets the HOST wall time, no offset", async () => {
|
||||
digestRequest
|
||||
.mockResolvedValueOnce(timeReply("2026-09-17 09:35:51"))
|
||||
.mockResolvedValueOnce(reply(200, "OK\r\n"));
|
||||
const r = await (await cam()).syncClock(HOST_NOW, 60);
|
||||
expect(r).toEqual({ driftSeconds: 3598, synced: true });
|
||||
const set = digestRequest.mock.calls[1]![0] as { method: string; path: string };
|
||||
expect(set.method).toBe("GET");
|
||||
expect(set.path).toBe("/cgi-bin/global.cgi?action=setCurrentTime&time=2026-09-17%2010%3A35%3A49");
|
||||
});
|
||||
|
||||
it("unparseable camera reply = infinite drift → syncs", async () => {
|
||||
digestRequest
|
||||
.mockResolvedValueOnce(reply(200, "Error\r\nBad Request!"))
|
||||
.mockResolvedValueOnce(reply(200, "OK"));
|
||||
const r = await (await cam()).syncClock(HOST_NOW, 60);
|
||||
expect(r).toEqual({ driftSeconds: null, synced: true });
|
||||
});
|
||||
|
||||
it("a 200 whose body is not OK is still a failed set (Dahua's 'Error' convention)", async () => {
|
||||
digestRequest
|
||||
.mockResolvedValueOnce(timeReply("1970-01-01 01:00:00"))
|
||||
.mockResolvedValueOnce(reply(200, "Error\r\nInvalid Argument!"));
|
||||
await expect((await cam()).syncClock(HOST_NOW, 60)).rejects.toThrow("clock set failed: HTTP 200 Error");
|
||||
});
|
||||
|
||||
it("a non-200 set surfaces as an error", async () => {
|
||||
digestRequest
|
||||
.mockResolvedValueOnce(timeReply("1970-01-01 01:00:00"))
|
||||
.mockResolvedValueOnce(reply(401, "denied"));
|
||||
await expect((await cam()).syncClock(HOST_NOW, 60)).rejects.toThrow("clock set failed: HTTP 401");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user