forked from soligen2010/RC_RX_CABELL_V3_FHSS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestHarness.cpp
188 lines (146 loc) · 6.24 KB
/
TestHarness.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
Copyright 2017 by Dennis Cabell
KE8FZX
To use this software, you must adhere to the license terms described below, and assume all responsibility for the use
of the software. The user is responsible for all consequences or damage that may result from using this software.
The user is responsible for ensuring that the hardware used to run this software complies with local regulations and that
any radio signal generated from use of this software is legal for that user to generate. The author(s) of this software
assume no liability whatsoever. The author(s) of this software is not responsible for legal or civil consequences of
using this software, including, but not limited to, any damages cause by lost control of a vehicle using this software.
If this software is copied or modified, this disclaimer must accompany all copies.
This project is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RC_RX_CABELL_V3_FHSS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RC_RX_CABELL_V3_FHSS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TestHarness.h"
#include "Pins.h"
#ifdef TEST_HARNESS
#include "Arduino.h"
#ifdef USE_I2C_LCD
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(LCD_I2C_ADDR, // Set the LCD I2C address
I2C_EN_PIN,
I2C_RW_PIN,
I2C_RS_PIN,
I2C_D4_PIN,
I2C_D5_PIN,
I2C_D6_PIN,
I2C_D7_PIN,
I2C_BL_PIN,
I2C_BACKLIGHT_POLARITY);
#else
#include <LiquidCrystal.h>
LiquidCrystal lcd( RS_PIN,
EN_PIN,
D4_PIN,
D5_PIN,
D6_PIN,
D7_PIN);
#endif
//--------------------------------------------------------------------------------------------------------------------------
TestHarness::TestHarness ()
{
}
//--------------------------------------------------------------------------------------------------------------------------
void TestHarness::init() {
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);lcd.print(F("FHSS PKT Rate %"));
lcd.setCursor(0, 1);lcd.print(F("Searching ..."));
}
//--------------------------------------------------------------------------------------------------------------------------
void TestHarness::hit() {
if (!firstPacketHit) resetCounters();
firstPacketHit = true;
hitCount++;
sequentialMissCount = 0;
packetProcess();
}
//--------------------------------------------------------------------------------------------------------------------------
void TestHarness::miss() {
missCount++;
sequentialMissCount++;
if (sequentialMissCount > holdSequentialMissCount) holdSequentialMissCount = sequentialMissCount;
packetProcess();
}
//--------------------------------------------------------------------------------------------------------------------------
void TestHarness::secondaryHit() {
secondaryHitCount++;
}
//--------------------------------------------------------------------------------------------------------------------------
void TestHarness::badPacket() {
badPacketCount++;
hit();
}
//--------------------------------------------------------------------------------------------------------------------------
void TestHarness::failSafe() {
if (firstDisplay) {
lcd.clear();
lcd.setCursor(0, 0);lcd.print(F("Fail-safe"));
}
resetCounters();
displayPacketCount = 0;
}
//--------------------------------------------------------------------------------------------------------------------------
void TestHarness::reSync() {
if (firstDisplay) {
lcd.clear();
lcd.setCursor(0, 0);lcd.print(F("Re-sync"));
firstDisplay = false;
}
resetCounters();
displayPacketCount = 0;
}
//--------------------------------------------------------------------------------------------------------------------------
void TestHarness::packetProcess() {
if (!firstPacketHit) {
resetCounters();
} else {
packetCount++;
if (packetCount >= PACKET_DISPLAY_INTERVAL) {
displayHitCount = hitCount;
displayMissCount = missCount;
displaySequentialMissCount = holdSequentialMissCount;
displayHoldSequentialMissCount = holdSequentialMissCount;
displaySecondaryHitCount = secondaryHitCount;
displayBadPacketCount = badPacketCount;
displayPacketCount = packetCount;
displayPacketRate = (float)(displayHitCount - displayBadPacketCount)*100.0/(float)(displayHitCount+displayMissCount);
resetCounters();
}
if (firstPacketHit && displayPacketCount > 0) {
display(packetCount);
}
}
}
//--------------------------------------------------------------------------------------------------------------------------
void TestHarness::resetCounters() {
hitCount = 0;
missCount = 0;
sequentialMissCount = 0;
holdSequentialMissCount = 0;
secondaryHitCount = 0;
badPacketCount = 0;
packetCount = 0;
firstPacketHit = false;
}
//--------------------------------------------------------------------------------------------------------------------------
void TestHarness::display(int LCD_Command) {
// updateing the lcd is slow, so change display gradually, one character at a time
static char line[18];
if ( LCD_Command == 1) sprintf(line,"%-7i%-4i%5i",(int)displayPacketRate,displaySequentialMissCount,displaySecondaryHitCount);
if ( LCD_Command == 3) lcd.setCursor(0, 0);
if ( LCD_Command >= 5 && LCD_Command < 5+16) lcd.write(line[LCD_Command-5]);
if ( LCD_Command == 22) sprintf(line,"%-7i%-9i",displayHitCount,displayMissCount);
if ( LCD_Command == 24) lcd.setCursor(0, 1);
if ( LCD_Command >= 26 && LCD_Command < 26+16) lcd.write(line[LCD_Command-26]);
firstDisplay = true;
}
#endif