-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
69 lines (64 loc) · 1.82 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { parse } = require('./lib/utils');
// function hex2bin(hex) {
// return (parseInt(hex, 16).toString(2)).padStart(8, '0');
// }
const testData = [
{
raw: [0x02, 0x0B, 0x20, 0x01, 0x10, 0x20, 0x00, 0x01, 0x0A, 0x03, 0x11],
decoded: {
info: "IDLING"
}
},
{
raw: [0x02, 0x0B, 0x20, 0x02, 0x10, 0x00, 0x00, 0x01, 0x0A, 0x03, 0x32],
decoded: {
info: "ACCEPTING(drawing in)"
}
},
{
raw: [0x02, 0x0B, 0x21, 0x04, 0x10, 0x18, 0x00, 0x01, 0x0A, 0x03, 0x2D],
decoded: {
info: "ESCROWED $5"
}
},
// {
// raw: [0x02, 0x0B, 0x20, 0x04, 0x10, 0x18, 0x00, 0x01, 0x0A, 0x03, 0x2C],
// decoded: {
// info: "Host requests STACK"
// }
// },
{
raw: [0x02, 0x0B, 0x21, 0x08, 0x10, 0x18, 0x00, 0x01, 0x0A, 0x03, 0x21],
decoded: {
info: "STACKING"
}
},
{
raw: [0x02, 0x0B, 0x21, 0x11, 0x10, 0x18, 0x00, 0x01, 0x0A, 0x03, 0x38],
decoded: {
info: "STACKED"
}
},
{
raw: [0x02, 0x0B, 0x21, 0x01, 0x00, 0x18, 0x00, 0x01, 0x0A, 0x03, 0x38],
decoded: {
info: "IDLING-LRC"
}
},
{
raw: [0x02, 0x1e, 0x70, 0x02, 0x11, 0x10, 0x00, 0x10, 0x55, 0x35, 0x00, 0x55, 0x53, 0x44, 0x30, 0x30, 0x31, 0x2b, 0x30, 0x30, 0x02, 0x43, 0x41, 0x44, 0x42, 0x00, 0x00, 0x00, 0x03, 0x43],
decoded: {
info: "IDLING-LRC"
}
}]
testData.forEach(({ raw, decoded }) => {
console.log('----------------')
const res = parse(raw, 'POLL')
// res.DATA_BITS = res.DATA.map(v => v.toString(2))
// res.DATA_BITS_2 = res.DATA.map(v => hex2bin(v))
// res.decoded = decoded
// res.some = ProcessData0(res.DATA[0])
// console.log(res.DATA_BITS_2[0], res.DATA_BITS[0], decoded.info)
console.log(JSON.stringify(res, null, 2))
console.log('----------------')
})