Skip to content

Commit

Permalink
Merge remote-tracking branch 'openbci/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey1994 committed Nov 13, 2019
2 parents 4425b1d + 3a3c911 commit b5c2c1b
Show file tree
Hide file tree
Showing 26 changed files with 762 additions and 32 deletions.
49 changes: 37 additions & 12 deletions cpp-package/src/board_shim.h
Expand Up @@ -9,48 +9,66 @@
#include "brainflow_exception.h"


/// LogLevels enum to store all possible log levels
enum class LogLevels : int
{
LEVEL_TRACE = 0,
LEVEL_DEBUG = 1,
LEVEL_INFO = 2,
LEVEL_WARN = 3,
LEVEL_ERROR = 4,
LEVEL_CRITICAL = 5,
LEVEL_OFF = 6
LEVEL_TRACE = 0, /// TRACE
LEVEL_DEBUG = 1, /// DEBUG
LEVEL_INFO = 2, /// INFO
LEVEL_WARN = 3, /// WARN
LEVEL_ERROR = 4, /// ERROR
LEVEL_CRITICAL = 5, /// CRITICAL
LEVEL_OFF = 6 // OFF
};

/// BoardShim class to communicate with a board
class BoardShim
{

void reshape_data (int data_points, double *linear_buffer, double **output_buf);
std::string input_params;

public:
// logging methods
/// disable BrainFlow logger
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 (char *log_file);
// use set_log_level and log_message only if you want to write your own log messages to
// brainflow logger
/// 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, ...);

// data desc and board desc methods, these methods return column indexes in data table
/// get sampling rate for this board, info about sampling rate is hardcoded in json file
static int get_sampling_rate (int board_id);
/// get row index which holds package nums
static int get_package_num_channel (int board_id);
/// get row index which holds timestamps
static int get_timestamp_channel (int board_id);
/// get number of rows in returned from @ref get_board_data() 2d array
static int get_num_rows (int board_id);
/// get row indices which hold EEG data, for some board we can not split EEG\EMG\...
static int *get_eeg_channels (int board_id, int *len);
/// get row indices which hold EMG data, for some board we can not split EEG\EMG\...
static int *get_emg_channels (int board_id, int *len);
/// get row indices which hold ECG data, for some board we can not split EEG\EMG\...
static int *get_ecg_channels (int board_id, int *len);
/// get row indices which hold EOG data, for some board we can not split EEG\EMG\...
static int *get_eog_channels (int board_id, int *len);
/// get row indices which hold PPG data
static int *get_ppg_channels (int board_id, int *len);
/// get row indices which hold EDA data
static int *get_eda_channels (int board_id, int *len);
/// get row indices which hold accel data
static int *get_accel_channels (int board_id, int *len);
/// get row indices which hold ANALOG data
static int *get_analog_channels (int board_id, int *len);
/// get row indices which hold gyro data
static int *get_gyro_channels (int board_id, int *len);
/// get row indices which hold other information for this board
static int *get_other_channels (int board_id, int *len);

int board_id;
Expand All @@ -60,13 +78,20 @@ class BoardShim
{
}

// data acquisition methods
/// prepare BrainFlow's streaming session, should be called first
void prepare_session ();
/// start streaming thread and store data in ringbuffer
void start_stream (int buffer_size = 450000);
/// 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
double **get_current_board_data (int num_samples, int *num_data_points);
/// get number of packages in ringbuffer
int get_board_data_count ();
/// get all collected data and flush it from internal buffer
double **get_board_data (int *num_data_points);
/// send string to a board, use it carefully and only if you understand what you are doing
void config_board (char *config);
};
2 changes: 2 additions & 0 deletions cpp-package/src/brainflow_exception.h
Expand Up @@ -4,10 +4,12 @@
#include <exception>
#include <string>

/// BrainFlowException class to notify about errors
class BrainFlowException : public std::exception
{

public:
/// exit code returned from low level API
int exit_code;

explicit BrainFlowException (const char *msg, int exit_code) : std::exception ()
Expand Down
9 changes: 9 additions & 0 deletions cpp-package/src/data_filter.cpp
Expand Up @@ -46,6 +46,15 @@ void DataFilter::perform_bandstop (double *data, int data_len, int sampling_rate
}
}

void DataFilter::perform_rolling_filter (double *data, int data_len, int period, int agg_operation)
{
int res = ::perform_rolling_filter (data, data_len, period, agg_operation);
if (res != STATUS_OK)
{
throw BrainFlowException ("failed to filter signal", res);
}
}

double **DataFilter::read_file (int *num_rows, int *num_cols, char *file_name)
{
int max_elements = 0;
Expand Down
10 changes: 10 additions & 0 deletions cpp-package/src/data_filter.h
Expand Up @@ -5,20 +5,30 @@
#include "brainflow_exception.h"
#include "data_handler.h"


/// DataFilter class to perform signal processing
class DataFilter
{
public:
/// perform low pass filter in-place
static void perform_lowpass (double *data, int data_len, int sampling_rate, double cutoff,
int order, int filter_type, double ripple);
/// perform high pass filter in-place
static void perform_highpass (double *data, int data_len, int sampling_rate, double cutoff,
int order, int filter_type, double ripple);
/// perform bandpass filter in-place
static void perform_bandpass (double *data, int data_len, int sampling_rate, double center_freq,
double band_width, int order, int filter_type, double ripple);
/// perform bandstop filter in-place
static void perform_bandstop (double *data, int data_len, int sampling_rate, double center_freq,
double band_width, int order, int filter_type, double ripple);
/// perform moving average or moving median filter in-place
static void perform_rolling_filter (double *data, int data_len, int period, int agg_operation);

/// write file, in file data will be transposed
static void write_file (
double **data, int num_rows, int num_cols, char *file_name, char *file_mode);
/// read data from file, data will be transposed to original format
static double **read_file (int *num_rows, int *num_cols, char *file_name);

private:
Expand Down

0 comments on commit b5c2c1b

Please sign in to comment.