-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassthrough-escaping.cpp
56 lines (47 loc) · 1.3 KB
/
passthrough-escaping.cpp
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
#include "passthrough-escaping.h"
#include "client-connection.h"
#include "system-operation-mode.h"
#include <SoftwareSerial.h>
int passthroughEscapeSequence = 0;
bool potentialEscapeSequenceForming = false;
void abortEscapeSquence() {
if (!potentialEscapeSequenceForming)
return;
for (int i = 0; i < passthroughEscapeSequence; i++)
client.write('+');
passthroughEscapeSequence = 0;
potentialEscapeSequenceForming = false;
}
void processPotentialEscape(const int timeSinceLastByte) {
switch (passthroughEscapeSequence) {
case 0:
if (timeSinceLastByte > 1000) {
potentialEscapeSequenceForming = true;
passthroughEscapeSequence++;
return;
}
client.write('+');
return;
case 1:
case 2:
if (timeSinceLastByte < 200) {
passthroughEscapeSequence++;
return;
}
break;
}
passthroughEscapeSequence++;
abortEscapeSquence();
}
void testForEscapeSequence(const int timeSinceLastByte) {
if (!potentialEscapeSequenceForming)
return;
if ((passthroughEscapeSequence == 1 || passthroughEscapeSequence == 2) && timeSinceLastByte > 210) {
abortEscapeSquence();
}
if (passthroughEscapeSequence == 3 && timeSinceLastByte > 1000) {
Serial.print(PSTR("\r\nREADY\r\n"));
operationMode = CommandMode;
passthroughEscapeSequence = 0;
}
}