-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonitorPacketLoss.m
52 lines (49 loc) · 1.84 KB
/
monitorPacketLoss.m
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
function monitorPacketLoss()
%MONITORPACKETLOSS Monitors the data streaming from the Blackrock Neural
%Signal Processor for any drops in packets/signal
%
% CODE PURPOSE
% Monitors the data streaming from the Blackrock Neural Signal Processor
% for packet loss. In the event of a packet loss, the process attempts to
% approximate the amount of data lost in seconds with a warning in the
% command window.
%
% NOTES
% (1) The process uses a modal message box window. Closing this window
% halts the monitoring process.
% (2) The function has been designed to be very simple in order to allow
% other users to add other functions that can be called when a packet loss
% is detected. Inclusion of a background parallel pool to call functions
% and allow this process to continue monitoring for packet losses is
% recommended.
%
% SYNTAX
% monitorPacketLoss()
%
% Author: Joshua Adkinson
packetLossBoxHandle = msgbox({'Monitoring for packet losses on central.','Close this dialog box to halt monitoring.'},'Packet Loss Monitoring','modal');
address = getIPAddressesFromPortNames({'NSP1','NSP2'});
delay = 0.01;
cbmex('open',0,'central-addr',address{1});
cbmex('trialconfig',1,'double','instance',0,'noevent','continuous',102400);
for i = 2:272
cbmex('mask',i,0)
end
pause(delay)
while ishandle(packetLossBoxHandle)
pause(delay)
[~, checkForData] = cbmex('trialdata',1);
if isempty(checkForData)
% INSERT PACKET LOSS FUNCTION CALLBACKS HERE
missingDataCounter = 0;
while isempty(checkForData)
missingDataCounter = missingDataCounter + 1;
[~, checkForData] = cbmex('trialdata',1);
a = tic;
while toc(a) < delay; end
end
warning(['PACKET LOSS!! Approximately ',num2str(delay*missingDataCounter),' seconds of contiguous data was not detected.'])
end
end
cbmex('trialconfig',0)
end