-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHammingSerial_Tests.h
More file actions
98 lines (82 loc) · 2.04 KB
/
HammingSerial_Tests.h
File metadata and controls
98 lines (82 loc) · 2.04 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "Test_Framework.h"
HammingSerial master(&Serial1);
HammingSerial slave(&Serial2);
long throughput;
bool sendByteTest() {
byte b,x;
b = 3;
if (master.tx_buffer.push(b)) {
if (master.send()) {
Serial1.flush();
if (slave.receive()) {
if (slave.rx_buffer.pop(&x)) {
if (x == b) {
return true;
}
}
}
}
}
return false;
}
bool send16ByteTest() {
byte i,b;
for (i=0;i<16;i++) {
if (!master.tx_buffer.push(i*7)) return false;
}
if (master.send()) {
Serial1.flush();
if (slave.receive()) {
for (i=0;i<16;i++) {
if (slave.rx_buffer.pop(&b)) {
if (i*7 != b)
return false;
} else return false;
}
} else return false;
} else return false;
return true;
}
bool randomPacketTest0() {
byte i,x;
byte b[16];
for (i=0;i<16;i++) {
b[i] = random(256);
if (!master.tx_buffer.push(b[i]))
return false;
}
if (master.send()) {
Serial1.flush();
if (slave.receive()) {
for (i=0;i<16;i++) {
if (slave.rx_buffer.pop(&x)) {
if (b[i] != x)
return false;
} else return false;
}
} else return false;
} else return false;
return true;
}
bool randomPacketTest() {
byte i;
unsigned long start, stop;
start = millis();
for (i=0;i<255;i++) {
if (!randomPacketTest0())
return false;
}
stop = millis();
throughput = (256.0 * 16.0 * 8.0) / ((stop - start) / 1000.0);
return true;
}
void runHammingSerialTests() {
Serial1.begin(115200,SERIAL_7N1);
Serial2.begin(115200,SERIAL_7N1);
printTestTitle("Hamming Serial Adapter");
printTestResult("Send Byte Test",sendByteTest());
printTestResult("Send 16 Byte Test",send16ByteTest());
printTestResult("Random Packet Test",randomPacketTest());
Serial.print("Throughput="); Serial.print(throughput); Serial.println(" bps");
Serial.print("Errors Corrected="); Serial.print(slave.errorsCorrected);
}