-
-
Notifications
You must be signed in to change notification settings - Fork 342
/
Copy pathboard_shim.h
270 lines (260 loc) · 12.1 KB
/
board_shim.h
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#pragma once
#include <cstdarg>
#include <string>
#include <vector>
// include it here to allow user include only this single file
#include "board_controller.h"
#include "board_info_getter.h"
#include "brainflow_array.h"
#include "brainflow_constants.h"
#include "brainflow_exception.h"
#include "brainflow_input_params.h"
#include "json.hpp"
using json = nlohmann::json;
/// BoardShim class to communicate with a board
class BoardShim
{
std::string serialized_params;
struct BrainFlowInputParams params;
public:
/// disable BrainFlow loggers
static void disable_board_logger ();
/// enable BrainFlow logger with LEVEL_INFO
static void enable_board_logger ();
/// enable BrainFlow logger with LEVEL_TRACE
static void enable_dev_board_logger ();
/// redirect BrainFlow logger from stderr to file
static void set_log_file (std::string log_file);
/// use set_log_level only if you want to write your own log messages to BrainFlow logger
static void set_log_level (int log_level);
/// write user defined string to BrainFlow logger
static void log_message (int log_level, const char *format, ...);
/**
* get board description as json
* @param board_id board id of your device
* @throw BrainFlowException If board id is not valid exit code is UNSUPPORTED_BOARD_ERROR
*/
static json get_board_descr (int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get sampling rate for this board
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static int get_sampling_rate (int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row index which holds package nums
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static int get_package_num_channel (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row index which holds timestamps
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static int get_timestamp_channel (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row index which holds markers
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static int get_marker_channel (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row index which holds battery level info
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static int get_battery_channel (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get number of rows in returned from @ref get_board_data() 2d array
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static int get_num_rows (int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get device name
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::string get_device_name (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get eeg channel names in 10-20 system for devices with fixed electrode locations
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<std::string> get_eeg_names (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row indices which hold EEG data, for some board we can not split EEG\EMG\...
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<int> get_eeg_channels (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row indices which hold EMG data, for some board we can not split EEG\EMG\...
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<int> get_emg_channels (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row indices which hold ECG data, for some board we can not split EEG\EMG\...
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<int> get_ecg_channels (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row indices which hold EOG data, for some board we can not split EEG\EMG\...
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<int> get_eog_channels (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row indices which hold EXG data
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<int> get_exg_channels (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row indices which hold PPG data
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<int> get_ppg_channels (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row indices which hold EDA data
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<int> get_eda_channels (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row indices which hold accel data
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<int> get_accel_channels (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row indices which hold rotation data
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<int> get_rotation_channels (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row indices which hold rotation calib data
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<int> get_analog_channels (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row indices which hold gyro data
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<int> get_gyro_channels (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row indices which hold other information
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<int> get_other_channels (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row indices which hold temperature data
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<int> get_temperature_channels (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row indices which hold resistance data
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<int> get_resistance_channels (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* get row indices which hold magnetometer data
* @param board_id board id of your device
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
*/
static std::vector<int> get_magnetometer_channels (
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/// release all currently prepared session
static void release_all_sessions ();
/// get brainflow version
static std::string get_version ();
/**
* get available presets for this board
* @param board_id board id of your device
* @throw BrainFlowException
*/
static std::vector<int> get_board_presets (int board_id);
int board_id;
BoardShim (int board_id, struct BrainFlowInputParams params);
~BoardShim ()
{
}
/// prepare BrainFlow's streaming session, should be called first
void prepare_session ();
/**
* start streaming thread and store data in ringbuffer
* @param buffer_size size of internal ring buffer
*/
void start_stream (int buffer_size = 450000, std::string streamer_params = "");
/**
* add streamer
* @param streamer_params use it to pass data packages further or store them directly during
streaming, supported values: "file://%file_name%:w", "file://%file_name%:a",
"streaming_board://%multicast_group_ip%:%port%"". Range for multicast addresses is from
"224.0.0.0" to "239.255.255.255"
*/
void add_streamer (
std::string streamer_params, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/**
* delete streamer
* @param streamer_params use it to pass data packages further or store them directly during
streaming, supported values: "file://%file_name%:w", "file://%file_name%:a",
"streaming_board://%multicast_group_ip%:%port%"". Range for multicast addresses is from
"224.0.0.0" to "239.255.255.255"
*/
void delete_streamer (
std::string streamer_params, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/// check if session is ready or not
bool is_prepared ();
/// stop streaming thread, doesnt release other resources
void stop_stream ();
/// release streaming session
void release_session ();
/// get latest collected data, doesnt remove it from ringbuffer
BrainFlowArray<double, 2> get_current_board_data (
int num_samples, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/// Get board id, for some boards can be different than provided (playback, streaming)
int get_board_id ();
/// get number of packages in ringbuffer
int get_board_data_count (int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/// get all collected data and flush it from internal buffer
BrainFlowArray<double, 2> get_board_data (int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/// get required amount of datapoints or less and flush it from internal buffer
BrainFlowArray<double, 2> get_board_data (int num_datapoints, int preset);
/// send string to a board, use it carefully and only if you understand what you are doing
std::string config_board (std::string config);
/// send raw bytes to a board, not implemented for majority of devices, not recommended to use
void config_board_with_bytes (const char *bytes, int len);
/// insert marker in data stream
void insert_marker (double value, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
};