Skip to content

Commit aee5ec1

Browse files
authored
Package loss notify (#1053)
* add notifications about lost packages Signed-off-by: Andrey Parfenov <a1994ndrey@gmail.com>
1 parent b0a43aa commit aee5ec1

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

OpenBCI_GUI/PacketLossTracker.pde

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ class PacketLossTracker {
4646

4747
protected ArrayList<Integer> sampleIndexArray = new ArrayList<Integer>();
4848

49+
// use these vars for notification at the bottom
50+
private boolean notificationShown = false;
51+
protected String lostPackagesMsg = "Lost packets detected, open packet loss widget for more info";
52+
protected String noLostPackagesMsg = "Data streaming is running as usual";
53+
protected int windowSizeNotificationMs = 5000;
54+
protected double thresholdNotification = 1.0;
55+
4956
PacketLossTracker(int _sampleIndexChannel, int _timestampChannel, int _minSampleIndex, int _maxSampleIndex) {
5057
this(_sampleIndexChannel, _timestampChannel, _minSampleIndex, _maxSampleIndex, new RealTimeProvider());
5158
}
@@ -153,6 +160,7 @@ class PacketLossTracker {
153160
}
154161

155162
packetRecords.push(currentRecord);
163+
checkCurrentStreamStatus();
156164
}
157165

158166
private void incrementLastSampleIndexLocation() {
@@ -165,6 +173,22 @@ class PacketLossTracker {
165173
protected void reset() {
166174
lastSample = null;
167175
}
176+
177+
protected void checkCurrentStreamStatus() {
178+
PacketRecord lastMillisPacketRecord = getCumulativePacketRecordForLast(windowSizeNotificationMs);
179+
if (lastMillisPacketRecord.getLostPercent() > thresholdNotification) {
180+
if (!notificationShown) {
181+
notificationShown = true;
182+
outputWarn(lostPackagesMsg);
183+
}
184+
}
185+
else {
186+
if (notificationShown) {
187+
notificationShown = false;
188+
outputInfo(noLostPackagesMsg);
189+
}
190+
}
191+
}
168192
}
169193

170194
// sample index range 1-255, odd numbers only (skips evens)

OpenBCI_GUI_unittests/OpenBCI_GUI_UnitTests.pde

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,12 @@ private void notifySuccess(boolean success) {
5151
PrintWriter output = createWriter(failFileName);
5252
output.close();
5353
}
54-
}
54+
}
55+
56+
private void outputWarn(String str) {
57+
println("warn stub for tests");
58+
}
59+
60+
private void outputInfo(String str) {
61+
println("info stub for tests");
62+
}

OpenBCI_GUI_unittests/run-unittests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# Once we get rid of globals we could copy all PDEs
1212
files_to_unittest = [
1313
"PacketLossTracker.pde",
14-
"TimeTrackingQueue.pde",
14+
"TimeTrackingQueue.pde"
1515
]
1616

1717
def main ():

0 commit comments

Comments
 (0)