feat(devices): DT-008 reader discovery + auto-configuration over the vendor UDP protocol
Build & push images / images (push) Successful in 3m7s
Build & push images / images (push) Successful in 3m7s
The Dingtian DT-008's Windows-only config tool speaks a small binary UDP protocol (reader :24680 unicast get/set, :24582 broadcast search/set-network), reversed in wiki/raw/dingtian_qr_linux (PROTOCOL.md + dingtian_qr.py, copied to scripts/). Reading park-2's readers with it from the booth found both in WG26 output mode — the "beeps but captures nothing" enrolment failure: they never pushed HTTP at all. The app now speaks the protocol itself (packages/devices dingtian-qr-config.ts, Node dgram, host-network container) and the dingtian-qr-reader driver uses it: - discover(): first driver to implement the wizard's Scan capability; rows show serial, IP, output mode, current server target, card format, firmware. - preconditions: output type must be HTTP (fixable — save switches it); typed serial must equal the reported one and the reader must answer on UDP (both block the save). - configureInputPush(): set-network the reader's server to this booth's IP + listen port, confirmed by polling (the reader applies it without an ack and is silent for seconds). - usesPushAuth=false: the scan GET carries no credentials, so no push secret is stored. - a reader saved without an IP warns instead of failing (legacy vendor-tool setup). Verified on the bench unit: WG26→HTTP, target 8080→8081→8080, struct byte-identical after. 15 protocol tests against a fake reader + 17 adapter tests. Wiki: device-discovery, first-run-setup, dingtian-dt008-reader, site-device-installation §2 (SSH procedure; the "needs a Windows laptop" claim withdrawn), new source page dingtian-qr-linux-tool.
This commit is contained in:
@@ -41,3 +41,219 @@ describe("QR reader healthCheck (ICMP liveness)", () => {
|
||||
expect(hostField!.required).toBe(false); // operation is push-by-serial; IP is monitor-only
|
||||
});
|
||||
});
|
||||
|
||||
// --- DT-008 configuration over the vendor UDP protocol -----------------------------
|
||||
// The protocol layer is mocked (it has its own fake-reader tests in
|
||||
// dingtian-qr-config.test.ts); here we check what the ADAPTER decides: which
|
||||
// preconditions it reports, what it writes to fix them, and how it points the reader at
|
||||
// the booth. Scenario values are park-2's real readers (WG26, server 10.0.10.101:3000).
|
||||
|
||||
const qr = vi.hoisted(() => ({
|
||||
readFirmware: vi.fn(),
|
||||
readParams: vi.fn(),
|
||||
writeSetting: vi.fn(),
|
||||
setNetwork: vi.fn(),
|
||||
subnetBroadcastFor: vi.fn(),
|
||||
discoverReaders: vi.fn(),
|
||||
}));
|
||||
vi.mock("./dingtian-qr-config.js", async (importOriginal) => {
|
||||
const real = await importOriginal<typeof import("./dingtian-qr-config.js")>();
|
||||
return { ...real, ...qr };
|
||||
});
|
||||
|
||||
const fw = { model: "doorqrcode", firmware: "ver_client1_1.1", chip: "v3s", hardware: "h42", serial: "HC009E84" };
|
||||
const park2Params = {
|
||||
dhcp: 0,
|
||||
ip: "10.0.10.7",
|
||||
netmask: "255.255.255.0",
|
||||
gateway: "0.0.0.0",
|
||||
dns1: "0.0.0.0",
|
||||
dns2: "0.0.0.0",
|
||||
server: "10.0.10.101",
|
||||
serverPort: 3000,
|
||||
httpLanguage: 1,
|
||||
outputType: 6, // WG26 — the park-2 fault
|
||||
cardInputFormat: 1,
|
||||
lastAddEnter: 1,
|
||||
lastAddNewline: 0,
|
||||
qrPrefix: "",
|
||||
qrSuffix: "",
|
||||
restartInterval: 1,
|
||||
workMode: 0,
|
||||
buzzer: 0,
|
||||
highPulseUs: 2000,
|
||||
lowPulseUs: 400,
|
||||
baudrate: 9600,
|
||||
dataBits: 8,
|
||||
stopBits: 1,
|
||||
parity: 2,
|
||||
qrOutputFormat: 4,
|
||||
fillLight: 1,
|
||||
cardOutputFormat: 1,
|
||||
cardPrefix: "",
|
||||
cardSuffix: "",
|
||||
};
|
||||
|
||||
type Configurable = {
|
||||
checkPreconditions(): Promise<{ ok: boolean; issues: { key: string; fixable: boolean; message: string }[] }>;
|
||||
fixPreconditions(): Promise<{ ok: boolean; issues: { key: string }[] }>;
|
||||
configureInputPush(o: { host: string; port: number; pathBase: string; auth: { user: string; password: string } }): Promise<void>;
|
||||
usesPushAuth?: boolean;
|
||||
};
|
||||
const reader = (cfg: Record<string, string>) => dingtianQrReaderDriver.create(cfg) as unknown as Configurable;
|
||||
const push = { pathBase: "/x", auth: { user: "u", password: "p" } };
|
||||
|
||||
afterEach(() => {
|
||||
for (const m of Object.values(qr)) m.mockReset();
|
||||
});
|
||||
|
||||
describe("DT-008 preconditions (reader must be in HTTP mode, serial must match)", () => {
|
||||
it("WG26 → one FIXABLE issue naming the mode and the current target", async () => {
|
||||
qr.readFirmware.mockResolvedValue(fw);
|
||||
qr.readParams.mockResolvedValue(park2Params);
|
||||
const r = await reader({ serial: "HC009E84", host: "10.0.10.7" }).checkPreconditions();
|
||||
expect(r.ok).toBe(false);
|
||||
expect(r.issues).toHaveLength(1);
|
||||
expect(r.issues[0]).toMatchObject({ key: "output-type", fixable: true });
|
||||
expect(r.issues[0]!.message).toMatch(/WG26.*HTTP.*10\.0\.10\.101:3000/);
|
||||
});
|
||||
|
||||
it("typed serial ≠ reported serial → UNFIXABLE (scans would land on the wrong device)", async () => {
|
||||
qr.readFirmware.mockResolvedValue(fw);
|
||||
qr.readParams.mockResolvedValue({ ...park2Params, outputType: 3 });
|
||||
const r = await reader({ serial: "HC00D3B0", host: "10.0.10.7" }).checkPreconditions();
|
||||
expect(r.ok).toBe(false);
|
||||
expect(r.issues).toEqual([expect.objectContaining({ key: "serial-mismatch", fixable: false })]);
|
||||
expect(r.issues[0]!.message).toContain("HC009E84");
|
||||
});
|
||||
|
||||
it("serial comparison ignores case/whitespace; HTTP mode → ok", async () => {
|
||||
qr.readFirmware.mockResolvedValue(fw);
|
||||
qr.readParams.mockResolvedValue({ ...park2Params, outputType: 3 });
|
||||
expect(await reader({ serial: " hc009e84 ", host: "10.0.10.7" }).checkPreconditions()).toEqual({ ok: true, issues: [] });
|
||||
});
|
||||
|
||||
it("no IP → ok with no issues (nothing to talk to; legacy vendor-tool setup)", async () => {
|
||||
expect(await reader({ serial: "HC009E84" }).checkPreconditions()).toEqual({ ok: true, issues: [] });
|
||||
expect(qr.readParams).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("IP set but no UDP answer → UNFIXABLE 'unreachable' (save fails with a clear message)", async () => {
|
||||
qr.readFirmware.mockResolvedValue(null);
|
||||
qr.readParams.mockResolvedValue(null);
|
||||
const r = await reader({ serial: "HC009E84", host: "10.0.10.9" }).checkPreconditions();
|
||||
expect(r.ok).toBe(false);
|
||||
expect(r.issues[0]).toMatchObject({ key: "unreachable", fixable: false });
|
||||
expect(r.issues[0]!.message).toMatch(/10\.0\.10\.9.*UDP 24680/);
|
||||
});
|
||||
|
||||
it("fixPreconditions writes cmd 6 = 3 (HTTP) once and re-checks", async () => {
|
||||
qr.readFirmware.mockResolvedValue(fw);
|
||||
qr.readParams.mockResolvedValueOnce(park2Params).mockResolvedValue({ ...park2Params, outputType: 3 });
|
||||
qr.writeSetting.mockResolvedValue(0);
|
||||
const r = await reader({ serial: "HC009E84", host: "10.0.10.7" }).fixPreconditions();
|
||||
expect(qr.writeSetting).toHaveBeenCalledTimes(1);
|
||||
expect(qr.writeSetting).toHaveBeenCalledWith("10.0.10.7", 6, 3);
|
||||
expect(r.ok).toBe(true);
|
||||
});
|
||||
|
||||
it("fixPreconditions: a rejected / unacknowledged write throws (no silent 'fixed')", async () => {
|
||||
qr.readFirmware.mockResolvedValue(fw);
|
||||
qr.readParams.mockResolvedValue(park2Params);
|
||||
qr.writeSetting.mockResolvedValue(1);
|
||||
await expect(reader({ serial: "HC009E84", host: "10.0.10.7" }).fixPreconditions()).rejects.toThrow(/status 1/);
|
||||
qr.writeSetting.mockResolvedValue(null);
|
||||
await expect(reader({ serial: "HC009E84", host: "10.0.10.7" }).fixPreconditions()).rejects.toThrow(/no acknowledgement/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("DT-008 configureInputPush (point the reader at this booth)", () => {
|
||||
it("already pointing at us → no write at all", async () => {
|
||||
qr.readFirmware.mockResolvedValue(fw);
|
||||
qr.readParams.mockResolvedValue({ ...park2Params, outputType: 3 });
|
||||
await reader({ serial: "HC009E84", host: "10.0.10.7" }).configureInputPush({ host: "10.0.10.101", port: 3000, ...push });
|
||||
expect(qr.setNetwork).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("different target → set-network with the READER's serial + its own network block, then verified by polling (reader is silent right after)", async () => {
|
||||
qr.readFirmware.mockResolvedValue(fw);
|
||||
qr.readParams
|
||||
.mockResolvedValueOnce({ ...park2Params, outputType: 3, server: "10.0.10.203", serverPort: 8080 })
|
||||
.mockResolvedValueOnce(null) // re-initialising its network: no answer to the first poll
|
||||
.mockResolvedValue({ ...park2Params, outputType: 3, server: "10.0.10.101", serverPort: 3000 });
|
||||
qr.subnetBroadcastFor.mockReturnValue("10.0.10.255");
|
||||
qr.setNetwork.mockResolvedValue(undefined);
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const p = reader({ serial: "hc009e84", host: "10.0.10.7" }).configureInputPush({ host: "10.0.10.101", port: 3000, ...push });
|
||||
await vi.advanceTimersByTimeAsync(3000); // poll 1: silent, poll 2: new target
|
||||
await p;
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
expect(qr.setNetwork).toHaveBeenCalledWith(
|
||||
{
|
||||
serial: "HC009E84", // as REPORTED, not as typed
|
||||
ip: "10.0.10.7",
|
||||
netmask: "255.255.255.0",
|
||||
gateway: "0.0.0.0",
|
||||
dns1: "0.0.0.0",
|
||||
dns2: "0.0.0.0",
|
||||
server: "10.0.10.101",
|
||||
serverPort: 3000,
|
||||
httpLanguage: 1,
|
||||
},
|
||||
"10.0.10.255",
|
||||
);
|
||||
});
|
||||
|
||||
it("reader did not apply the new target → throws (set-network has no ack; the re-read is the proof)", async () => {
|
||||
qr.readFirmware.mockResolvedValue(fw);
|
||||
qr.readParams.mockResolvedValue({ ...park2Params, outputType: 3, server: "10.0.10.203", serverPort: 8080 });
|
||||
qr.subnetBroadcastFor.mockReturnValue("10.0.10.255");
|
||||
qr.setNetwork.mockResolvedValue(undefined);
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const p = reader({ serial: "HC009E84", host: "10.0.10.7" }).configureInputPush({ host: "10.0.10.101", port: 3000, ...push });
|
||||
const expectation = expect(p).rejects.toThrow(/did not apply server 10\.0\.10\.101:3000 \(still 10\.0\.10\.203:8080\)/);
|
||||
await vi.advanceTimersByTimeAsync(15_000); // polls once a second until the 12 s deadline
|
||||
await expectation;
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("reader not on a directly attached subnet → throws before broadcasting", async () => {
|
||||
qr.readFirmware.mockResolvedValue(fw);
|
||||
qr.readParams.mockResolvedValue({ ...park2Params, outputType: 3 });
|
||||
qr.subnetBroadcastFor.mockReturnValue(null);
|
||||
await expect(
|
||||
reader({ serial: "HC009E84", host: "10.0.10.7" }).configureInputPush({ host: "10.0.10.101", port: 80, ...push }),
|
||||
).rejects.toThrow(/directly attached subnet/);
|
||||
expect(qr.setNetwork).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("declares usesPushAuth=false and pushesToBackend (the scan GET is identified by serial)", () => {
|
||||
expect(reader({ serial: "x" }).usesPushAuth).toBe(false);
|
||||
expect(dingtianQrReaderDriver.pushesToBackend).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("DT-008 discover (LAN search → wizard rows)", () => {
|
||||
it("maps each reader to serial/host config + mode/target info", async () => {
|
||||
qr.discoverReaders.mockResolvedValue([
|
||||
{ serial: "HC009E84", ip: "10.0.10.7", netmask: "255.255.255.0", gateway: "0.0.0.0", dns1: "0.0.0.0", dns2: "0.0.0.0", server: "10.0.10.101", serverPort: 3000, httpLanguage: 1, replyFrom: "10.0.10.7" },
|
||||
]);
|
||||
qr.readFirmware.mockResolvedValue(fw);
|
||||
qr.readParams.mockResolvedValue(park2Params);
|
||||
const found = await (dingtianQrReaderDriver as unknown as { discover(): Promise<unknown[]> }).discover();
|
||||
expect(found).toEqual([
|
||||
{
|
||||
id: "HC009E84",
|
||||
label: "HC009E84 @ 10.0.10.7",
|
||||
config: { serial: "HC009E84", host: "10.0.10.7" },
|
||||
info: { output: "WG26", server: "10.0.10.101:3000", url: "/qa/mcardsea.jsp", cardFormat: "6H", firmware: "ver_client1_1.1" },
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user