optolink-bridge 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +7 -1
- package/package.json +1 -1
- package/parse_vs2.js +13 -8
package/index.js
CHANGED
|
@@ -150,8 +150,14 @@ const packetQueue = async.queue(async task => {
|
|
|
150
150
|
trace && console.log(dateTimeString(), directionName(task.direction), (task.data ?? encodePacket(task.packet, task.direction & fromOpto)).toString('hex'));
|
|
151
151
|
|
|
152
152
|
const packet = task.packet ?? parsePacket(task.data, task.direction & fromOpto);
|
|
153
|
+
if (packet.rest?.length) {
|
|
154
|
+
// if there is any rest, two packets have been sent in the same direction, so unshift the rest as the next packet to the queue
|
|
155
|
+
packetQueue.unshift({ data: packet.rest, direction: task.direction });
|
|
156
|
+
}
|
|
153
157
|
|
|
154
|
-
if (
|
|
158
|
+
if (task.direction === fromVitoToOpto && packet.start === 0x04) {
|
|
159
|
+
busState = 0; // reset synchronization
|
|
160
|
+
} else if (busState === 0 && task.direction & toOpto && packet.start === 0x16 && 'zero' in packet) {
|
|
155
161
|
busState = 1;
|
|
156
162
|
} else if (busState === 1 && task.direction & fromOpto && packet.res === 0x06 && !packet.peek?.length) {
|
|
157
163
|
busState = 2;
|
package/package.json
CHANGED
package/parse_vs2.js
CHANGED
|
@@ -21,6 +21,14 @@ function when({ tag, type }) {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
function assertFunction(text, fn) {
|
|
25
|
+
const textFunction = function() {
|
|
26
|
+
return fn.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
textFunction.toString = () => text;
|
|
29
|
+
return textFunction;
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
/**
|
|
25
33
|
* @returns a function that can be used for readUntil, to only peek a single byte (if any)
|
|
26
34
|
*/
|
|
@@ -45,9 +53,9 @@ const parser = new Parser()
|
|
|
45
53
|
0x04: new Parser(), // EOT (end of transmission / sync. start)
|
|
46
54
|
0x16: new Parser() // SYN (synchronous idle / start of transmission)
|
|
47
55
|
.uint16('zero', {
|
|
48
|
-
assert: function(zero) {
|
|
56
|
+
assert: assertFunction('not matching the expected 16 00 00 start sequence', function(zero) {
|
|
49
57
|
return !zero; // has to start with 16 00 00 (zero!)
|
|
50
|
-
}
|
|
58
|
+
})
|
|
51
59
|
}),
|
|
52
60
|
0x41: new Parser() // VS2_DAP_STANDARD (packet start)
|
|
53
61
|
.uint8('len')
|
|
@@ -92,16 +100,13 @@ const parser = new Parser()
|
|
|
92
100
|
}))
|
|
93
101
|
.uint8('crc', {
|
|
94
102
|
type: 'uint8',
|
|
95
|
-
assert: function(crc) {
|
|
103
|
+
assert: assertFunction('a mismatch to the calculated CRC', function(crc) {
|
|
96
104
|
// if raw is not set / empty, we are in the encoding case, CRC will be calculated in the encode function
|
|
97
105
|
return !this.raw?.length || crc256(this.raw, this.len) === crc;
|
|
98
|
-
}
|
|
106
|
+
})
|
|
99
107
|
})
|
|
100
108
|
.buffer('rest', {
|
|
101
|
-
readUntil: 'eof'
|
|
102
|
-
assert: function(rest) {
|
|
103
|
-
return !rest.length;
|
|
104
|
-
}
|
|
109
|
+
readUntil: 'eof'
|
|
105
110
|
})
|
|
106
111
|
}
|
|
107
112
|
});
|