Skip to content

Commit f10b94b

Browse files
committed
codex: bug fixes and cleanup
Signed-off-by: Andrey Parfenov <a1994ndrey@gmail.com>
1 parent ee7d056 commit f10b94b

18 files changed

Lines changed: 225 additions & 91 deletions

File tree

cpp_package/src/board_shim.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ std::string BoardShim::config_board (std::string config)
235235
int response_len = 0;
236236
char response[8192];
237237
int res = ::config_board (
238-
config.c_str (), response, &response_len, board_id, serialized_params.c_str ());
238+
config.c_str (), response, &response_len, sizeof (response), board_id,
239+
serialized_params.c_str ());
239240
if (res != (int)BrainFlowExitCodes::STATUS_OK)
240241
{
241242
throw BrainFlowException ("failed to config board", res);
@@ -289,7 +290,8 @@ json BoardShim::get_board_descr (int board_id, int preset)
289290
{
290291
char board_descr_str[16000];
291292
int string_len = 0;
292-
int res = ::get_board_descr (board_id, preset, board_descr_str, &string_len);
293+
int res =
294+
::get_board_descr (board_id, preset, board_descr_str, &string_len, sizeof (board_descr_str));
293295
if (res != (int)BrainFlowExitCodes::STATUS_OK)
294296
{
295297
throw BrainFlowException ("failed to get board info", res);
@@ -368,7 +370,7 @@ std::vector<std::string> BoardShim::get_eeg_names (int board_id, int preset)
368370
{
369371
char eeg_names[4096];
370372
int string_len = 0;
371-
int res = ::get_eeg_names (board_id, preset, eeg_names, &string_len);
373+
int res = ::get_eeg_names (board_id, preset, eeg_names, &string_len, sizeof (eeg_names));
372374
if (res != (int)BrainFlowExitCodes::STATUS_OK)
373375
{
374376
throw BrainFlowException ("failed to get board info", res);
@@ -401,7 +403,7 @@ std::string BoardShim::get_device_name (int board_id, int preset)
401403
{
402404
char name[4096];
403405
int string_len = 0;
404-
int res = ::get_device_name (board_id, preset, name, &string_len);
406+
int res = ::get_device_name (board_id, preset, name, &string_len, sizeof (name));
405407
if (res != (int)BrainFlowExitCodes::STATUS_OK)
406408
{
407409
throw BrainFlowException ("failed to get board info", res);
@@ -602,4 +604,4 @@ std::string BoardShim::get_version ()
602604
std::string verion_str (version, string_len);
603605

604606
return verion_str;
605-
}
607+
}

csharp_package/brainflow/brainflow/board_controller_library.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public static class BoardControllerLibrary64
151151
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
152152
public static extern int log_message_board_controller (int log_level, string message);
153153
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
154-
public static extern int config_board (string config, byte[] response, int[] len, int board_id, string input_json);
154+
public static extern int config_board (string config, byte[] response, int[] len, int max_len, int board_id, string input_json);
155155
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
156156
public static extern int config_board_with_bytes (byte[] bytes, int len, int board_id, string input_json);
157157
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
@@ -195,19 +195,19 @@ public static class BoardControllerLibrary64
195195
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
196196
public static extern int is_prepared (int[] prepared, int board_id, string input_json);
197197
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
198-
public static extern int get_eeg_names (int board_id, int preset, byte[] eeg_names, int[] len);
198+
public static extern int get_eeg_names (int board_id, int preset, byte[] eeg_names, int[] len, int max_len);
199199
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
200200
public static extern int get_resistance_channels (int board_id, int preset, int[] channels, int[] len);
201201
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
202202
public static extern int get_magnetometer_channels (int board_id, int preset, int[] channels, int[] len);
203203
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
204204
public static extern int get_exg_channels (int board_id, int preset, int[] channels, int[] len);
205205
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
206-
public static extern int get_device_name (int board_id, int preset, byte[] name, int[] len);
206+
public static extern int get_device_name (int board_id, int preset, byte[] name, int[] len, int max_len);
207207
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
208208
public static extern int insert_marker (double value, int preset, int board_id, string input_json);
209209
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
210-
public static extern int get_board_descr (int board_id, int preset, byte[] board_descr, int[] len);
210+
public static extern int get_board_descr (int board_id, int preset, byte[] board_descr, int[] len, int max_len);
211211
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
212212
public static extern int release_all_sessions ();
213213
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
@@ -241,7 +241,7 @@ public static class BoardControllerLibrary32
241241
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
242242
public static extern int log_message_board_controller (int log_level, string message);
243243
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
244-
public static extern int config_board (string config, byte[] response, int[] len, int board_id, string input_json);
244+
public static extern int config_board (string config, byte[] response, int[] len, int max_len, int board_id, string input_json);
245245
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
246246
public static extern int config_board_with_bytes (byte[] bytes, int len, int board_id, string input_json);
247247
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
@@ -285,17 +285,17 @@ public static class BoardControllerLibrary32
285285
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
286286
public static extern int is_prepared (int[] prepared, int board_id, string input_json);
287287
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
288-
public static extern int get_eeg_names (int board_id, int preset, byte[] eeg_names, int[] len);
288+
public static extern int get_eeg_names (int board_id, int preset, byte[] eeg_names, int[] len, int max_len);
289289
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
290290
public static extern int get_resistance_channels (int board_id, int preset, int[] channels, int[] len);
291291
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
292292
public static extern int get_exg_channels (int board_id, int preset, int[] channels, int[] len);
293293
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
294-
public static extern int get_device_name (int board_id, int preset, byte[] name, int[] len);
294+
public static extern int get_device_name (int board_id, int preset, byte[] name, int[] len, int max_len);
295295
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
296296
public static extern int insert_marker (double value, int preset, int board_id, string input_json);
297297
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
298-
public static extern int get_board_descr (int board_id, int preset, byte[] board_descr, int[] len);
298+
public static extern int get_board_descr (int board_id, int preset, byte[] board_descr, int[] len, int max_len);
299299
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
300300
public static extern int release_all_sessions ();
301301
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
@@ -457,14 +457,14 @@ public static int insert_marker (double value, int preset, int board_id, string
457457
}
458458

459459

460-
public static int config_board (string config, byte[] str, int[] len, int board_id, string input_json)
460+
public static int config_board (string config, byte[] str, int[] len, int max_len, int board_id, string input_json)
461461
{
462462
switch (PlatformHelper.get_library_environment ())
463463
{
464464
case LibraryEnvironment.x64:
465-
return BoardControllerLibrary64.config_board (config, str, len, board_id, input_json);
465+
return BoardControllerLibrary64.config_board (config, str, len, max_len, board_id, input_json);
466466
case LibraryEnvironment.x86:
467-
return BoardControllerLibrary32.config_board (config, str, len, board_id, input_json);
467+
return BoardControllerLibrary32.config_board (config, str, len, max_len, board_id, input_json);
468468
}
469469

470470
return (int)BrainFlowExitCodes.GENERAL_ERROR;
@@ -600,14 +600,14 @@ public static int get_marker_channel (int board_id, int preset, int[] marker_cha
600600
return (int)BrainFlowExitCodes.GENERAL_ERROR;
601601
}
602602

603-
public static int get_eeg_names (int board_id, int preset, byte[] names, int[] len)
603+
public static int get_eeg_names (int board_id, int preset, byte[] names, int[] len, int max_len)
604604
{
605605
switch (PlatformHelper.get_library_environment ())
606606
{
607607
case LibraryEnvironment.x64:
608-
return BoardControllerLibrary64.get_eeg_names (board_id, preset, names, len);
608+
return BoardControllerLibrary64.get_eeg_names (board_id, preset, names, len, max_len);
609609
case LibraryEnvironment.x86:
610-
return BoardControllerLibrary32.get_eeg_names (board_id, preset, names, len);
610+
return BoardControllerLibrary32.get_eeg_names (board_id, preset, names, len, max_len);
611611
}
612612

613613
return (int)BrainFlowExitCodes.GENERAL_ERROR;
@@ -626,27 +626,27 @@ public static int get_board_presets (int board_id, int[] names, int[] len)
626626
return (int)BrainFlowExitCodes.GENERAL_ERROR;
627627
}
628628

629-
public static int get_board_descr (int board_id, int preset, byte[] descr, int[] len)
629+
public static int get_board_descr (int board_id, int preset, byte[] descr, int[] len, int max_len)
630630
{
631631
switch (PlatformHelper.get_library_environment ())
632632
{
633633
case LibraryEnvironment.x64:
634-
return BoardControllerLibrary64.get_board_descr (board_id, preset, descr, len);
634+
return BoardControllerLibrary64.get_board_descr (board_id, preset, descr, len, max_len);
635635
case LibraryEnvironment.x86:
636-
return BoardControllerLibrary32.get_board_descr (board_id, preset, descr, len);
636+
return BoardControllerLibrary32.get_board_descr (board_id, preset, descr, len, max_len);
637637
}
638638

639639
return (int)BrainFlowExitCodes.GENERAL_ERROR;
640640
}
641641

642-
public static int get_device_name (int board_id, int preset, byte[] name, int[] len)
642+
public static int get_device_name (int board_id, int preset, byte[] name, int[] len, int max_len)
643643
{
644644
switch (PlatformHelper.get_library_environment ())
645645
{
646646
case LibraryEnvironment.x64:
647-
return BoardControllerLibrary64.get_device_name (board_id, preset, name, len);
647+
return BoardControllerLibrary64.get_device_name (board_id, preset, name, len, max_len);
648648
case LibraryEnvironment.x86:
649-
return BoardControllerLibrary32.get_device_name (board_id, preset, name, len);
649+
return BoardControllerLibrary32.get_device_name (board_id, preset, name, len, max_len);
650650
}
651651

652652
return (int)BrainFlowExitCodes.GENERAL_ERROR;

csharp_package/brainflow/brainflow/board_shim.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public static string[] get_eeg_names (int board_id, int preset = (int)BrainFlowP
179179
{
180180
int[] len = new int[1];
181181
byte[] str = new byte[4096];
182-
int res = BoardControllerLibrary.get_eeg_names (board_id, preset, str, len);
182+
int res = BoardControllerLibrary.get_eeg_names (board_id, preset, str, len, str.Length);
183183
if (res != (int)BrainFlowExitCodes.STATUS_OK)
184184
{
185185
throw new BrainFlowError (res);
@@ -222,7 +222,7 @@ public static T get_board_descr<T> (int board_id, int preset = (int)BrainFlowPre
222222
{
223223
int[] len = new int[1];
224224
byte[] str = new byte[16000];
225-
int res = BoardControllerLibrary.get_board_descr (board_id, preset, str, len);
225+
int res = BoardControllerLibrary.get_board_descr (board_id, preset, str, len, str.Length);
226226
if (res != (int)BrainFlowExitCodes.STATUS_OK)
227227
{
228228
throw new BrainFlowError (res);
@@ -246,7 +246,7 @@ public static string get_device_name (int board_id, int preset = (int)BrainFlowP
246246
{
247247
int[] len = new int[1];
248248
byte[] str = new byte[4096];
249-
int res = BoardControllerLibrary.get_device_name (board_id, preset, str, len);
249+
int res = BoardControllerLibrary.get_device_name (board_id, preset, str, len, str.Length);
250250
if (res != (int)BrainFlowExitCodes.STATUS_OK)
251251
{
252252
throw new BrainFlowError (res);
@@ -717,7 +717,7 @@ public string config_board (string config)
717717
{
718718
int[] len = new int[1];
719719
byte[] str = new byte[4096];
720-
int res = BoardControllerLibrary.config_board (config, str, len, board_id, input_json);
720+
int res = BoardControllerLibrary.config_board (config, str, len, str.Length, board_id, input_json);
721721
if (res != (int)BrainFlowExitCodes.STATUS_OK)
722722
{
723723
throw new BrainFlowError (res);

java_package/brainflow/src/main/java/brainflow/BoardShim.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ private interface DllInterface extends Library
2323
{
2424
int prepare_session (int board_id, String params);
2525

26-
int config_board (String config, byte[] names, int[] len, int board_id, String params);
26+
int config_board (
27+
String config, byte[] names, int[] len, int max_len, int board_id, String params);
2728

2829
int config_board_with_bytes (byte[] bytes, int len, int board_id, String params);
2930

@@ -100,11 +101,11 @@ int get_current_board_data (int num_samples, int preset, double[] data_buf, int[
100101

101102
int is_prepared (int[] prepared, int board_id, String params);
102103

103-
int get_eeg_names (int board_id, int preset, byte[] names, int[] len);
104+
int get_eeg_names (int board_id, int preset, byte[] names, int[] len, int max_len);
104105

105-
int get_board_descr (int board_id, int preset, byte[] names, int[] len);
106+
int get_board_descr (int board_id, int preset, byte[] names, int[] len, int max_len);
106107

107-
int get_device_name (int board_id, int preset, byte[] name, int[] len);
108+
int get_device_name (int board_id, int preset, byte[] name, int[] len, int max_len);
108109

109110
int get_board_presets (int board_id, int[] presets, int[] len);
110111

@@ -509,7 +510,7 @@ public static String[] get_eeg_names (int board_id, BrainFlowPresets preset) thr
509510
{
510511
int[] len = new int[1];
511512
byte[] str = new byte[4096];
512-
int ec = instance.get_eeg_names (board_id, preset.get_code (), str, len);
513+
int ec = instance.get_eeg_names (board_id, preset.get_code (), str, len, str.length);
513514
if (ec != BrainFlowExitCode.STATUS_OK.get_code ())
514515
{
515516
throw new BrainFlowError ("Error in board info getter", ec);
@@ -574,7 +575,7 @@ public static <T> T get_board_descr (Class<T> type, int board_id, BrainFlowPrese
574575
{
575576
int[] len = new int[1];
576577
byte[] str = new byte[16000];
577-
int ec = instance.get_board_descr (board_id, preset.get_code (), str, len);
578+
int ec = instance.get_board_descr (board_id, preset.get_code (), str, len, str.length);
578579
if (ec != BrainFlowExitCode.STATUS_OK.get_code ())
579580
{
580581
throw new BrainFlowError ("Error in board info getter", ec);
@@ -617,7 +618,7 @@ public static String get_device_name (int board_id, BrainFlowPresets preset) thr
617618
{
618619
int[] len = new int[1];
619620
byte[] str = new byte[4096];
620-
int ec = instance.get_device_name (board_id, preset.get_code (), str, len);
621+
int ec = instance.get_device_name (board_id, preset.get_code (), str, len, str.length);
621622
if (ec != BrainFlowExitCode.STATUS_OK.get_code ())
622623
{
623624
throw new BrainFlowError ("Error in board info getter", ec);
@@ -1217,7 +1218,7 @@ public static int[] get_gyro_channels (int board_id, BrainFlowPresets preset) th
12171218
*/
12181219
public static int[] get_gyro_channels (int board_id) throws BrainFlowError
12191220
{
1220-
return get_gyro_channels (board_id);
1221+
return get_gyro_channels (board_id, BrainFlowPresets.DEFAULT_PRESET);
12211222
}
12221223

12231224
/**
@@ -1410,7 +1411,7 @@ public String config_board (String config) throws BrainFlowError
14101411
{
14111412
int[] len = new int[1];
14121413
byte[] str = new byte[4096];
1413-
int ec = instance.config_board (config, str, len, board_id, input_json);
1414+
int ec = instance.config_board (config, str, len, str.length, board_id, input_json);
14141415
if (ec != BrainFlowExitCode.STATUS_OK.get_code ())
14151416
{
14161417
throw new BrainFlowError ("Error in config_board", ec);

0 commit comments

Comments
 (0)