1 | import Protocol from "../src/protocol";
|
2 |
|
3 | test("protocol parse", () => {
|
4 | const protocol = new Protocol();
|
5 | const buf = Buffer.from([
|
6 | "0x23",
|
7 | "0x23",
|
8 | "0x01",
|
9 | "0x09",
|
10 | "0x12",
|
11 | "0x08",
|
12 | "0x08",
|
13 | "0x20",
|
14 | "0x23",
|
15 | "0x23",
|
16 | ]);
|
17 |
|
18 | const json = protocol.parse(buf);
|
19 | expect(json.header).toEqual({ command: 0x01 });
|
20 | expect(json.body).toEqual({
|
21 | month: 0x09,
|
22 | date: 0x12,
|
23 | hour: 0x08,
|
24 | minute: 0x08,
|
25 | second: 0x20,
|
26 | });
|
27 | });
|
28 |
|
29 | test("protocol build", () => {
|
30 | const protocol = new Protocol();
|
31 | const str = protocol.build({
|
32 | month: 0x09,
|
33 | date: 0x12,
|
34 | hour: 0x08,
|
35 | minute: 0x08,
|
36 | second: 0x20,
|
37 | });
|
38 |
|
39 | expect(str).toBe("time: 9-18-8-8-32");
|
40 | });
|