Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Zephyr BioHarness 3 Example of continuous client
- Loading branch information
Showing
27 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
MuLES_source/client_examples/matlab/simple_client_continuous_example.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
% MuLES Simple Client example | ||
% This script shows how to connect to MuLES and | ||
% request data continuously | ||
% | ||
% The script is divided as follows: | ||
% 1 Configuration for the TCP/IP Client | ||
% 2 Request of Headers | ||
% 3 Request Channel Names | ||
% 4 Flush old data from the Server | ||
% 5 Creating of buffer | ||
% 6 Request EEG data every 500ms during 40 seconds, and a marker is | ||
% send the first 10 seconds | ||
% 7 Plot EEG data | ||
% 8 Close connection with Server | ||
% | ||
% Instructions: | ||
% (MuLES and the Client are expected to be in the same computer, if that is not | ||
% the case, modify the variable mules_ip, in Section 1 of this script) | ||
% | ||
% 1 Run the Server | ||
% 2 Select your device | ||
% (Alternatively you can select FILE and the example recording: | ||
% log20141210_195303.csv) | ||
% 3 Select Streamming, Logging is optional | ||
% (In casse of reading from a File, You cannot change these options) | ||
% 4 Click on PLAY | ||
% 5 Run this script | ||
% | ||
% Note that you can run this script serveral times without restart the | ||
% Server. | ||
|
||
clear all; | ||
close all; | ||
clc; | ||
|
||
figure() | ||
pause(1); | ||
|
||
% 1 Configuration for the TCP/IP Client | ||
mules_ip = '127.0.0.1'; | ||
client_cnx = tcpip(mules_ip, 30000, 'NetworkRole', 'client'); | ||
client_cnx.InputBufferSize = 500000; | ||
client_cnx.Timeout = 5; %in seconds | ||
% Open a connection. | ||
waiting_server = true; | ||
|
||
while waiting_server | ||
waiting_server = false; | ||
%disp('1'); | ||
try | ||
fopen(client_cnx); | ||
%disp('2'); | ||
catch | ||
waiting_server = true; | ||
%disp('3'); | ||
end | ||
end | ||
|
||
disp(['Connection with MuLES (' mules_ip ') was successful'] ); | ||
|
||
% 2 Request of Header | ||
disp('Header request ...'); | ||
command = 'H'; | ||
fwrite(client_cnx, command); | ||
|
||
nBytes_4B = fread(client_cnx, 4); %How large is the package (# bytes) | ||
nBytes = double(swapbytes(typecast(uint8(nBytes_4B),'int32'))); | ||
package = fread(client_cnx,nBytes); | ||
header_str = char(package)'; | ||
[dev_name, dev_hardware, fs, data_format, nCh] = mules_parse_header(header_str); | ||
|
||
disp('Header successfully received'); | ||
|
||
% 3 Request of Channel Names | ||
disp('Channel names request ...'); | ||
command = 'N'; | ||
fwrite(client_cnx, command); | ||
|
||
nBytes_4B = fread(client_cnx, 4); %How large is the package (# bytes) | ||
nBytes = double(swapbytes(typecast(uint8(nBytes_4B),'int32'))); | ||
package = fread(client_cnx,nBytes); | ||
ch_names_str = char(package)'; | ||
tmp = textscan(ch_names_str,'%s','delimiter',','); | ||
ch_labels = tmp{1}; | ||
|
||
disp('Channel names successfully received'); | ||
|
||
% 4 Flush old data from the Server data | ||
disp('Flushing Server data ...'); | ||
command = 'F'; | ||
fwrite(client_cnx, command); | ||
disp('Flush done'); | ||
|
||
% 5 Creates Buffer | ||
buffer_sec = 15; | ||
buffer = zeros(buffer_sec*fs,numel(data_format)); | ||
|
||
xlabel('Time [s]'); | ||
ylabel('Amplitude'); | ||
|
||
tic | ||
marker = true; | ||
|
||
while true | ||
% 6 Request EEG data every 500ms | ||
pause(0.5); | ||
command = 'R'; | ||
fwrite(client_cnx, command); | ||
|
||
nBytes_4B = fread(client_cnx, 4); %How large is the package (# bytes) | ||
nBytes = double(swapbytes(typecast(uint8(nBytes_4B),'int32'))); | ||
eeg_package = fread(client_cnx,nBytes); | ||
eeg_data = mules_parse_data(eeg_package,data_format); | ||
|
||
buffer = [eeg_data; buffer]; | ||
buffer = buffer(1:buffer_sec*fs,:); | ||
|
||
% 7 Plot EEG data | ||
n_samples = size(buffer,1); | ||
time_vec = (0:n_samples-1)/fs; | ||
|
||
plot(time_vec,buffer); | ||
|
||
if toc >40 | ||
break | ||
end | ||
|
||
if toc >10 && marker | ||
%Send Marker | ||
command = 30; | ||
fwrite(client_cnx, command, 'uint8'); | ||
marker = false; | ||
end | ||
|
||
end | ||
|
||
% 8 Close connection with Server | ||
fclose(client_cnx); | ||
disp('Connection closed'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+23.7 KB
MuLES_source/source_vi/acquisition/Zephyr_BH3/command_vi/bh3_get_battery_status.vi
Binary file not shown.
Binary file added
BIN
+21.5 KB
MuLES_source/source_vi/acquisition/Zephyr_BH3/command_vi/bh3_get_unit_mac_address.vi
Binary file not shown.
Binary file added
BIN
+19.3 KB
MuLES_source/source_vi/acquisition/Zephyr_BH3/command_vi/bh3_lifesign.vi
Binary file not shown.
Binary file added
BIN
+23.5 KB
...source_vi/acquisition/Zephyr_BH3/command_vi/bh3_set_ECG_waveform_packet_transmit_state.vi
Binary file not shown.
Binary file added
BIN
+23.6 KB
...vi/acquisition/Zephyr_BH3/command_vi/bh3_set_accelerometer_100mg_packet_transmit_state.vi
Binary file not shown.
Binary file added
BIN
+23.5 KB
...ource_vi/acquisition/Zephyr_BH3/command_vi/bh3_set_accelerometer_packet_transmit_state.vi
Binary file not shown.
Binary file added
BIN
+23.6 KB
..._vi/acquisition/Zephyr_BH3/command_vi/bh3_set_breathing_waveform_packet_transmit_state.vi
Binary file not shown.
Binary file added
BIN
+23.7 KB
...ource_vi/acquisition/Zephyr_BH3/command_vi/bh3_set_extended_data_packet_transmit_state.vi
Binary file not shown.
Binary file added
BIN
+20.3 KB
...source_vi/acquisition/Zephyr_BH3/command_vi/bh3_set_general_data_packet_transmit_state.vi
Binary file not shown.
Binary file added
BIN
+23.5 KB
...rce/source_vi/acquisition/Zephyr_BH3/command_vi/bh3_set_r_r_data_packet_transmit_state.vi
Binary file not shown.
Binary file added
BIN
+23.7 KB
MuLES_source/source_vi/acquisition/Zephyr_BH3/command_vi/bh3_stop_all_transmit_state.vi
Binary file not shown.
Binary file added
BIN
+23.4 KB
MuLES_source/source_vi/acquisition/Zephyr_BH3/support_vi/bh3_ECG_waveform_format.vi
Binary file not shown.
Binary file added
BIN
+26.6 KB
MuLES_source/source_vi/acquisition/Zephyr_BH3/support_vi/bh3_acc100mg_waveform_format.vi
Binary file not shown.
Binary file added
BIN
+23.1 KB
MuLES_source/source_vi/acquisition/Zephyr_BH3/support_vi/bh3_bluetooth_read.vi
Binary file not shown.
Binary file added
BIN
+23.5 KB
MuLES_source/source_vi/acquisition/Zephyr_BH3/support_vi/bh3_breathing_waveform_format.vi
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+19 KB
MuLES_source/source_vi/acquisition/Zephyr_BH3/support_vi/bh3_create_package.vi
Binary file not shown.
Binary file added
BIN
+19.5 KB
MuLES_source/source_vi/acquisition/Zephyr_BH3/support_vi/bh3_data_array_to_data_string.vi
Binary file not shown.
Binary file added
BIN
+25.9 KB
MuLES_source/source_vi/acquisition/Zephyr_BH3/support_vi/bh3_open_bt_cnx.vi
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.