Skip to content

Commit 3bc5235

Browse files
committed
2 parents ccaae27 + 5ebfc1f commit 3bc5235

14 files changed

+102
-128
lines changed

src/board_controller/board.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,16 @@ int Board::prepare_for_acquisition (int buffer_size, char *streamer_params)
8989
db = NULL;
9090
}
9191

92-
try
92+
std::vector<std::string> required_fields {"num_rows", "timestamp_channel", "name"};
93+
for (std::string field : required_fields)
9394
{
94-
board_descr = brainflow_boards_json["boards"][int_to_string (board_id)];
95-
std::vector<std::string> required_fields {"num_rows", "timestamp_channel", "name"};
96-
for (std::string field : required_fields)
95+
if (board_descr.find (field) == board_descr.end ())
9796
{
98-
if (board_descr.find (field) == board_descr.end ())
99-
{
100-
safe_logger (spdlog::level::err,
101-
"Field {} is not found in brainflow_boards.h for id {}", field, board_id);
102-
return (int)BrainFlowExitCodes::GENERAL_ERROR;
103-
}
97+
safe_logger (spdlog::level::err,
98+
"Field {} is not found in brainflow_boards.h for id {}", field, board_id);
99+
return (int)BrainFlowExitCodes::GENERAL_ERROR;
104100
}
105101
}
106-
catch (json::exception &e)
107-
{
108-
safe_logger (spdlog::level::err, e.what ());
109-
return (int)BrainFlowExitCodes::GENERAL_ERROR;
110-
}
111102

112103
int res = prepare_streamer (streamer_params);
113104
if (res != (int)BrainFlowExitCodes::STATUS_OK)

src/board_controller/board_info_getter.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include <fstream>
22
#include <set>
3-
#include <sstream>
43
#include <string.h>
54
#include <string>
65
#include <vector>
@@ -10,20 +9,20 @@
109
#include "brainflow_boards.h"
1110
#include "brainflow_constants.h"
1211

13-
inline std::string int_to_string (int val);
14-
inline int get_single_value (
12+
13+
static int get_single_value (
1514
int board_id, const char *param_name, int *value, bool use_logger = true);
16-
inline int get_string_value (
15+
static int get_string_value (
1716
int board_id, const char *param_name, char *string, int *len, bool use_logger = true);
18-
inline int get_array_value (
17+
static int get_array_value (
1918
int board_id, const char *param_name, int *output_array, int *len, bool use_logger = true);
2019

2120

2221
int get_board_descr (int board_id, char *board_descr, int *len)
2322
{
2423
try
2524
{
26-
std::string res = brainflow_boards_json["boards"][int_to_string (board_id)].dump ();
25+
std::string res = brainflow_boards_json["boards"][std::to_string (board_id)].dump ();
2726
strcpy (board_descr, res.c_str ());
2827
*len = (int)strlen (res.c_str ());
2928
return (int)BrainFlowExitCodes::STATUS_OK;
@@ -166,18 +165,11 @@ int get_exg_channels (int board_id, int *exg_channels, int *len)
166165
return (int)BrainFlowExitCodes::STATUS_OK;
167166
}
168167

169-
inline std::string int_to_string (int val)
170-
{
171-
std::ostringstream ss;
172-
ss << val;
173-
return ss.str ();
174-
}
175-
176-
inline int get_single_value (int board_id, const char *param_name, int *value, bool use_logger)
168+
static int get_single_value (int board_id, const char *param_name, int *value, bool use_logger)
177169
{
178170
try
179171
{
180-
int val = (int)brainflow_boards_json["boards"][int_to_string (board_id)][param_name];
172+
int val = (int)brainflow_boards_json["boards"][std::to_string (board_id)][param_name];
181173
*value = val;
182174
return (int)BrainFlowExitCodes::STATUS_OK;
183175
}
@@ -191,13 +183,13 @@ inline int get_single_value (int board_id, const char *param_name, int *value, b
191183
}
192184
}
193185

194-
inline int get_array_value (
186+
static int get_array_value (
195187
int board_id, const char *param_name, int *output_array, int *len, bool use_logger)
196188
{
197189
try
198190
{
199191
std::vector<int> values =
200-
brainflow_boards_json["boards"][int_to_string (board_id)][param_name];
192+
brainflow_boards_json["boards"][std::to_string (board_id)][param_name];
201193
if (!values.empty ())
202194
{
203195
memcpy (output_array, &values[0], sizeof (int) * values.size ());
@@ -215,12 +207,12 @@ inline int get_array_value (
215207
}
216208
}
217209

218-
inline int get_string_value (
210+
static int get_string_value (
219211
int board_id, const char *param_name, char *string, int *len, bool use_logger)
220212
{
221213
try
222214
{
223-
std::string val = brainflow_boards_json["boards"][int_to_string (board_id)][param_name];
215+
std::string val = brainflow_boards_json["boards"][std::to_string (board_id)][param_name];
224216
strcpy (string, val.c_str ());
225217
*len = (int)strlen (val.c_str ());
226218
return (int)BrainFlowExitCodes::STATUS_OK;

src/board_controller/brainflow_boards.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,24 +312,26 @@ json brainflow_boards_json = {
312312
{"21",
313313
{{"name", "MuseSBLED"},
314314
{"sampling_rate", 256},
315-
{"timestamp_channel", 8},
316-
{"marker_channel", 9},
315+
{"timestamp_channel", 11},
316+
{"marker_channel", 12},
317317
{"package_num_channel", 0},
318-
{"num_rows", 10},
318+
{"num_rows", 13},
319319
{"eeg_channels", {1, 2, 3, 4}},
320320
{"eeg_names", "TP9,Fp1,Fp2,TP10"},
321-
{"accel_channels", {5, 6, 7}}
321+
{"accel_channels", {5, 6, 7}},
322+
{"gyro_channels", {8, 9, 10}}
322323
}},
323324
{"22",
324325
{{"name", "Muse2BLED"},
325326
{"sampling_rate", 256},
326-
{"timestamp_channel", 8},
327-
{"marker_channel", 9},
327+
{"timestamp_channel", 11},
328+
{"marker_channel", 12},
328329
{"package_num_channel", 0},
329-
{"num_rows", 10},
330+
{"num_rows", 13},
330331
{"eeg_channels", {1, 2, 3, 4}},
331332
{"eeg_names", "TP9,Fp1,Fp2,TP10"},
332-
{"accel_channels", {5, 6, 7}}
333+
{"accel_channels", {5, 6, 7}},
334+
{"gyro_channels", {8, 9, 10}}
333335
}},
334336
{"23",
335337
{{"name", "CrownOSC"},

src/board_controller/inc/board.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ class Board
4040
streamer = NULL;
4141
this->board_id = board_id;
4242
this->params = params;
43+
try
44+
{
45+
board_descr = brainflow_boards_json["boards"][std::to_string (board_id)];
46+
}
47+
catch (json::exception &e)
48+
{
49+
safe_logger (spdlog::level::err, e.what ());
50+
}
4351
}
4452
virtual int prepare_session () = 0;
4553
virtual int start_stream (int buffer_size, char *streamer_params) = 0;

src/board_controller/muse/muse_2_bled.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "get_dll_dir.h"
55
#include "muse_2_bled.h"
6-
#include "muse_types.h"
76

87
#include "brainflow_constants.h"
98

src/board_controller/muse/muse_bglib/inc/muse_2_bglib_helper.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@
88
class Muse2BGLibHelper : public MuseBGLibHelper
99
{
1010
public:
11-
Muse2BGLibHelper () : MuseBGLibHelper ()
11+
Muse2BGLibHelper (json board_descr) : MuseBGLibHelper (board_descr)
1212
{
1313
}
1414

1515
std::string get_preset ()
1616
{
1717
return "p21";
1818
}
19-
20-
int get_buffer_size ()
21-
{
22-
return 10;
23-
}
2419
};

src/board_controller/muse/muse_bglib/inc/muse_bglib_helper.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#include "brainflow_constants.h"
1515
#include "brainflow_input_params.h"
1616
#include "data_buffer.h"
17+
#include "json.hpp"
1718

19+
using json = nlohmann::json;
1820

1921
enum class DeviceState : int
2022
{
@@ -49,13 +51,14 @@ class MuseBGLibHelper
4951
std::vector<std::vector<double>> current_buf;
5052
std::vector<bool> new_eeg_data;
5153
double last_timestamp;
54+
json board_descr;
5255

5356
void thread_worker ();
5457

5558
public:
5659
volatile int exit_code;
5760

58-
MuseBGLibHelper ()
61+
MuseBGLibHelper (json descr)
5962
{
6063
exit_code = (int)BrainFlowExitCodes::SYNC_TIMEOUT_ERROR;
6164
connection = -1;
@@ -67,6 +70,7 @@ class MuseBGLibHelper
6770
control_char_handle = 0;
6871
db = NULL;
6972
last_timestamp = -1.0;
73+
board_descr = descr;
7074
}
7175

7276
virtual ~MuseBGLibHelper ()
@@ -88,7 +92,6 @@ class MuseBGLibHelper
8892
virtual int config_device (const char *config);
8993

9094
virtual std::string get_preset () = 0;
91-
virtual int get_buffer_size () = 0;
9295

9396
// callbacks from bglib which we need
9497
virtual void ble_evt_connection_status (const struct ble_msg_connection_status_evt_t *msg);

src/board_controller/muse/muse_bglib/inc/muse_s_bglib_helper.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,12 @@
99
class MuseSBGLibHelper : public MuseBGLibHelper
1010
{
1111
public:
12-
MuseSBGLibHelper () : MuseBGLibHelper ()
12+
MuseSBGLibHelper (json board_descr) : MuseBGLibHelper (board_descr)
1313
{
1414
}
1515

1616
std::string get_preset ()
1717
{
1818
return "p21";
1919
}
20-
21-
int get_buffer_size ()
22-
{
23-
return 10;
24-
}
2520
};

src/board_controller/muse/muse_bglib/inc/muse_types.h

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/board_controller/muse/muse_bglib/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ int initialize (void *param)
3838
switch (static_cast<BoardIds> (std::get<0> (*info)))
3939
{
4040
case BoardIds::MUSE_S_BLED_BOARD:
41-
helper = new MuseSBGLibHelper ();
41+
helper = new MuseSBGLibHelper (std::get<2> (*info));
4242
break;
4343
case BoardIds::MUSE_2_BLED_BOARD:
44-
helper = new Muse2BGLibHelper ();
44+
helper = new Muse2BGLibHelper (std::get<2> (*info));
4545
break;
4646
default:
4747
return (int)BrainFlowExitCodes::UNSUPPORTED_BOARD_ERROR;

0 commit comments

Comments
 (0)