Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions cpp_package/src/board_shim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ std::string BoardShim::config_board (std::string config)
int response_len = 0;
char response[8192];
int res = ::config_board (
config.c_str (), response, &response_len, board_id, serialized_params.c_str ());
config.c_str (), response, &response_len, sizeof (response), board_id,
serialized_params.c_str ());
if (res != (int)BrainFlowExitCodes::STATUS_OK)
{
throw BrainFlowException ("failed to config board", res);
Expand Down Expand Up @@ -281,6 +282,18 @@ int BoardShim::get_board_id ()
return master_board_id;
}

int BoardShim::get_board_sampling_rate (int preset)
{
int sampling_rate = -1;
int res =
::get_board_sampling_rate (preset, &sampling_rate, board_id, serialized_params.c_str ());
if (res != (int)BrainFlowExitCodes::STATUS_OK)
{
throw BrainFlowException ("failed to get board sampling rate", res);
}
return sampling_rate;
}

//////////////////////////////////////////
///////////// data desc methods //////////
//////////////////////////////////////////
Expand All @@ -289,7 +302,8 @@ json BoardShim::get_board_descr (int board_id, int preset)
{
char board_descr_str[16000];
int string_len = 0;
int res = ::get_board_descr (board_id, preset, board_descr_str, &string_len);
int res =
::get_board_descr (board_id, preset, board_descr_str, &string_len, sizeof (board_descr_str));
if (res != (int)BrainFlowExitCodes::STATUS_OK)
{
throw BrainFlowException ("failed to get board info", res);
Expand Down Expand Up @@ -368,7 +382,7 @@ std::vector<std::string> BoardShim::get_eeg_names (int board_id, int preset)
{
char eeg_names[4096];
int string_len = 0;
int res = ::get_eeg_names (board_id, preset, eeg_names, &string_len);
int res = ::get_eeg_names (board_id, preset, eeg_names, &string_len, sizeof (eeg_names));
if (res != (int)BrainFlowExitCodes::STATUS_OK)
{
throw BrainFlowException ("failed to get board info", res);
Expand Down Expand Up @@ -401,7 +415,7 @@ std::string BoardShim::get_device_name (int board_id, int preset)
{
char name[4096];
int string_len = 0;
int res = ::get_device_name (board_id, preset, name, &string_len);
int res = ::get_device_name (board_id, preset, name, &string_len, sizeof (name));
if (res != (int)BrainFlowExitCodes::STATUS_OK)
{
throw BrainFlowException ("failed to get board info", res);
Expand Down Expand Up @@ -602,4 +616,4 @@ std::string BoardShim::get_version ()
std::string verion_str (version, string_len);

return verion_str;
}
}
2 changes: 2 additions & 0 deletions cpp_package/src/inc/board_shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ class BoardShim
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 actual sampling rate for prepared board session
int get_board_sampling_rate (int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
/// 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
Expand Down
57 changes: 37 additions & 20 deletions csharp_package/brainflow/brainflow/board_controller_library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,16 @@ public static class BoardControllerLibrary64
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int log_message_board_controller (int log_level, string message);
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int config_board (string config, byte[] response, int[] len, int board_id, string input_json);
public static extern int config_board (string config, byte[] response, int[] len, int max_len, int board_id, string input_json);
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int config_board_with_bytes (byte[] bytes, int len, int board_id, string input_json);
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int set_log_file_board_controller (string log_file);
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_sampling_rate (int board_id, int preset, int[] sampling_rate);
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_board_sampling_rate (int preset, int[] sampling_rate, int board_id, string input_json);
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_timestamp_channel (int board_id, int preset, int[] timestamp_channel);
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_marker_channel (int board_id, int preset, int[] marker_channel);
Expand Down Expand Up @@ -195,19 +197,19 @@ public static class BoardControllerLibrary64
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int is_prepared (int[] prepared, int board_id, string input_json);
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_eeg_names (int board_id, int preset, byte[] eeg_names, int[] len);
public static extern int get_eeg_names (int board_id, int preset, byte[] eeg_names, int[] len, int max_len);
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_resistance_channels (int board_id, int preset, int[] channels, int[] len);
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_magnetometer_channels (int board_id, int preset, int[] channels, int[] len);
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_exg_channels (int board_id, int preset, int[] channels, int[] len);
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_device_name (int board_id, int preset, byte[] name, int[] len);
public static extern int get_device_name (int board_id, int preset, byte[] name, int[] len, int max_len);
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int insert_marker (double value, int preset, int board_id, string input_json);
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_board_descr (int board_id, int preset, byte[] board_descr, int[] len);
public static extern int get_board_descr (int board_id, int preset, byte[] board_descr, int[] len, int max_len);
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int release_all_sessions ();
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
Expand Down Expand Up @@ -241,14 +243,16 @@ public static class BoardControllerLibrary32
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int log_message_board_controller (int log_level, string message);
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int config_board (string config, byte[] response, int[] len, int board_id, string input_json);
public static extern int config_board (string config, byte[] response, int[] len, int max_len, int board_id, string input_json);
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int config_board_with_bytes (byte[] bytes, int len, int board_id, string input_json);
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int set_log_file_board_controller (string log_file);
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_sampling_rate (int board_id, int preset, int[] sampling_rate);
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_board_sampling_rate (int preset, int[] sampling_rate, int board_id, string input_json);
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_timestamp_channel (int board_id, int preset, int[] timestamp_channel);
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_marker_channel (int board_id, int preset, int[] marker_channel);
Expand Down Expand Up @@ -285,17 +289,17 @@ public static class BoardControllerLibrary32
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int is_prepared (int[] prepared, int board_id, string input_json);
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_eeg_names (int board_id, int preset, byte[] eeg_names, int[] len);
public static extern int get_eeg_names (int board_id, int preset, byte[] eeg_names, int[] len, int max_len);
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_resistance_channels (int board_id, int preset, int[] channels, int[] len);
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_exg_channels (int board_id, int preset, int[] channels, int[] len);
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_device_name (int board_id, int preset, byte[] name, int[] len);
public static extern int get_device_name (int board_id, int preset, byte[] name, int[] len, int max_len);
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int insert_marker (double value, int preset, int board_id, string input_json);
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_board_descr (int board_id, int preset, byte[] board_descr, int[] len);
public static extern int get_board_descr (int board_id, int preset, byte[] board_descr, int[] len, int max_len);
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int release_all_sessions ();
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
Expand Down Expand Up @@ -457,14 +461,14 @@ public static int insert_marker (double value, int preset, int board_id, string
}


public static int config_board (string config, byte[] str, int[] len, int board_id, string input_json)
public static int config_board (string config, byte[] str, int[] len, int max_len, int board_id, string input_json)
{
switch (PlatformHelper.get_library_environment ())
{
case LibraryEnvironment.x64:
return BoardControllerLibrary64.config_board (config, str, len, board_id, input_json);
return BoardControllerLibrary64.config_board (config, str, len, max_len, board_id, input_json);
case LibraryEnvironment.x86:
return BoardControllerLibrary32.config_board (config, str, len, board_id, input_json);
return BoardControllerLibrary32.config_board (config, str, len, max_len, board_id, input_json);
}

return (int)BrainFlowExitCodes.GENERAL_ERROR;
Expand Down Expand Up @@ -535,6 +539,19 @@ public static int get_sampling_rate (int board_id, int preset, int[] sampling_ra
return (int)BrainFlowExitCodes.GENERAL_ERROR;
}

public static int get_board_sampling_rate (int preset, int[] sampling_rate, int board_id, string input_json)
{
switch (PlatformHelper.get_library_environment ())
{
case LibraryEnvironment.x64:
return BoardControllerLibrary64.get_board_sampling_rate (preset, sampling_rate, board_id, input_json);
case LibraryEnvironment.x86:
return BoardControllerLibrary32.get_board_sampling_rate (preset, sampling_rate, board_id, input_json);
}

return (int)BrainFlowExitCodes.GENERAL_ERROR;
}

public static int get_package_num_channel (int board_id, int preset, int[] package_num)
{
switch (PlatformHelper.get_library_environment ())
Expand Down Expand Up @@ -600,14 +617,14 @@ public static int get_marker_channel (int board_id, int preset, int[] marker_cha
return (int)BrainFlowExitCodes.GENERAL_ERROR;
}

public static int get_eeg_names (int board_id, int preset, byte[] names, int[] len)
public static int get_eeg_names (int board_id, int preset, byte[] names, int[] len, int max_len)
{
switch (PlatformHelper.get_library_environment ())
{
case LibraryEnvironment.x64:
return BoardControllerLibrary64.get_eeg_names (board_id, preset, names, len);
return BoardControllerLibrary64.get_eeg_names (board_id, preset, names, len, max_len);
case LibraryEnvironment.x86:
return BoardControllerLibrary32.get_eeg_names (board_id, preset, names, len);
return BoardControllerLibrary32.get_eeg_names (board_id, preset, names, len, max_len);
}

return (int)BrainFlowExitCodes.GENERAL_ERROR;
Expand All @@ -626,27 +643,27 @@ public static int get_board_presets (int board_id, int[] names, int[] len)
return (int)BrainFlowExitCodes.GENERAL_ERROR;
}

public static int get_board_descr (int board_id, int preset, byte[] descr, int[] len)
public static int get_board_descr (int board_id, int preset, byte[] descr, int[] len, int max_len)
{
switch (PlatformHelper.get_library_environment ())
{
case LibraryEnvironment.x64:
return BoardControllerLibrary64.get_board_descr (board_id, preset, descr, len);
return BoardControllerLibrary64.get_board_descr (board_id, preset, descr, len, max_len);
case LibraryEnvironment.x86:
return BoardControllerLibrary32.get_board_descr (board_id, preset, descr, len);
return BoardControllerLibrary32.get_board_descr (board_id, preset, descr, len, max_len);
}

return (int)BrainFlowExitCodes.GENERAL_ERROR;
}

public static int get_device_name (int board_id, int preset, byte[] name, int[] len)
public static int get_device_name (int board_id, int preset, byte[] name, int[] len, int max_len)
{
switch (PlatformHelper.get_library_environment ())
{
case LibraryEnvironment.x64:
return BoardControllerLibrary64.get_device_name (board_id, preset, name, len);
return BoardControllerLibrary64.get_device_name (board_id, preset, name, len, max_len);
case LibraryEnvironment.x86:
return BoardControllerLibrary32.get_device_name (board_id, preset, name, len);
return BoardControllerLibrary32.get_device_name (board_id, preset, name, len, max_len);
}

return (int)BrainFlowExitCodes.GENERAL_ERROR;
Expand Down
24 changes: 20 additions & 4 deletions csharp_package/brainflow/brainflow/board_shim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static string[] get_eeg_names (int board_id, int preset = (int)BrainFlowP
{
int[] len = new int[1];
byte[] str = new byte[4096];
int res = BoardControllerLibrary.get_eeg_names (board_id, preset, str, len);
int res = BoardControllerLibrary.get_eeg_names (board_id, preset, str, len, str.Length);
if (res != (int)BrainFlowExitCodes.STATUS_OK)
{
throw new BrainFlowError (res);
Expand Down Expand Up @@ -222,7 +222,7 @@ public static T get_board_descr<T> (int board_id, int preset = (int)BrainFlowPre
{
int[] len = new int[1];
byte[] str = new byte[16000];
int res = BoardControllerLibrary.get_board_descr (board_id, preset, str, len);
int res = BoardControllerLibrary.get_board_descr (board_id, preset, str, len, str.Length);
if (res != (int)BrainFlowExitCodes.STATUS_OK)
{
throw new BrainFlowError (res);
Expand All @@ -246,7 +246,7 @@ public static string get_device_name (int board_id, int preset = (int)BrainFlowP
{
int[] len = new int[1];
byte[] str = new byte[4096];
int res = BoardControllerLibrary.get_device_name (board_id, preset, str, len);
int res = BoardControllerLibrary.get_device_name (board_id, preset, str, len, str.Length);
if (res != (int)BrainFlowExitCodes.STATUS_OK)
{
throw new BrainFlowError (res);
Expand Down Expand Up @@ -717,7 +717,7 @@ public string config_board (string config)
{
int[] len = new int[1];
byte[] str = new byte[4096];
int res = BoardControllerLibrary.config_board (config, str, len, board_id, input_json);
int res = BoardControllerLibrary.config_board (config, str, len, str.Length, board_id, input_json);
if (res != (int)BrainFlowExitCodes.STATUS_OK)
{
throw new BrainFlowError (res);
Expand Down Expand Up @@ -839,6 +839,22 @@ public int get_board_id ()
return master_board;
}

/// <summary>
/// get actual sampling rate for this prepared board session
/// </summary>
/// <param name="preset">preset for device</param>
/// <returns>sampling rate</returns>
public int get_board_sampling_rate (int preset = (int)BrainFlowPresets.DEFAULT_PRESET)
{
int[] val = new int[1];
int res = BoardControllerLibrary.get_board_sampling_rate (preset, val, board_id, input_json);
if (res != (int)BrainFlowExitCodes.STATUS_OK)
{
throw new BrainFlowError (res);
}
return val[0];
}

///<summary>
/// Get input params
///</summary>
Expand Down
Loading
Loading