@@ -21,11 +21,12 @@ static void brainalive_adapter_1_on_scan_found (
21
21
static void brainalive_read_notifications (simpleble_uuid_t service,
22
22
simpleble_uuid_t characteristic, uint8_t *data, size_t size, void *board)
23
23
{
24
- if (size == BrainAlive::brainalive_handshaking_packet_size)
24
+ if ((size == BrainAlive::brainalive_handshaking_packet_size) && (data[0 ] == START_BYTE) &&
25
+ (data[size - 1 ] == STOP_BYTE) && (data[2 ] == BrainAlive::brainalive_handshaking_command))
25
26
{
26
- ((BrainAlive *)(board))->setSoftwareGain (data[1 ]);
27
- ((BrainAlive *)(board))->setHardwareGain (data[2 ]);
28
- ((BrainAlive *)(board))->setReferenceVoltage (((data[3 ] << 8 ) | data[4 ]));
27
+ ((BrainAlive *)(board))->set_internal_gain (data[3 ]);
28
+ ((BrainAlive *)(board))->set_external_gain (data[4 ]);
29
+ ((BrainAlive *)(board))->set_ref_Voltage (((data[5 ] << 8 ) | data[6 ]));
29
30
}
30
31
else
31
32
{
@@ -113,6 +114,7 @@ int BrainAlive::prepare_session ()
113
114
{
114
115
safe_logger (spdlog::level::info, " Connected to BrainAlive Device" );
115
116
res = (int )BrainFlowExitCodes::STATUS_OK;
117
+
116
118
break ;
117
119
}
118
120
else
@@ -190,6 +192,11 @@ int BrainAlive::prepare_session ()
190
192
if ((res == (int )BrainFlowExitCodes::STATUS_OK) && (control_characteristics_found))
191
193
{
192
194
initialized = true ;
195
+ res = config_board (" 0a036007000d" );
196
+ if (res == (int )BrainFlowExitCodes::STATUS_OK)
197
+ safe_logger (spdlog::level::debug, " Get config command send" );
198
+ else
199
+ safe_logger (spdlog::level::debug, " Failed to send get config command" );
193
200
}
194
201
else
195
202
{
@@ -208,7 +215,7 @@ int BrainAlive::start_stream (int buffer_size, const char *streamer_params)
208
215
209
216
if (res == (int )BrainFlowExitCodes::STATUS_OK)
210
217
{
211
- res = config_board (" 0a8100000d " );
218
+ res = config_board (" 0a038100000d " );
212
219
}
213
220
if (res == (int )BrainFlowExitCodes::STATUS_OK)
214
221
{
@@ -228,7 +235,7 @@ int BrainAlive::stop_stream ()
228
235
int res = (int )BrainFlowExitCodes::STATUS_OK;
229
236
if (is_streaming)
230
237
{
231
- res = config_board (" 0a4000000d " );
238
+ res = config_board (" 0a034000000d " );
232
239
}
233
240
else
234
241
{
@@ -302,15 +309,20 @@ int BrainAlive::config_board (std::string config)
302
309
{
303
310
return (int )BrainFlowExitCodes::BOARD_NOT_CREATED_ERROR;
304
311
}
305
- uint8_t command[5 ];
306
- command[0 ] = 0x0a ;
307
- command[1 ] = 0x81 ; // it is hardcoded for now only
308
- command[2 ] = 0x00 ;
309
- command[3 ] = 0x00 ;
310
- command[4 ] = 0x0d ;
311
- safe_logger (spdlog::level::trace, config[2 ]);
312
+ // Calculate the number of bytes
313
+ size_t num_bytes = config.length () / 2 ; // Each byte is represented by 2 hex characters
314
+ std::vector<uint8_t > byte_array (num_bytes);
315
+ // Convert hex string to byte array
316
+ for (size_t i = 0 ; i < num_bytes; ++i)
317
+ {
318
+ std::string byte_string = config.substr (i * 2 , 2 ); // Get 2 characters for each byte
319
+ byte_array[i] =
320
+ static_cast <unsigned char > (std::stoul (byte_string, nullptr , 16 )); // Convert to byte
321
+ }
322
+
312
323
if (simpleble_peripheral_write_command (brainalive_peripheral, write_characteristics.first ,
313
- write_characteristics.second , command, sizeof (command)) != SIMPLEBLE_SUCCESS)
324
+ write_characteristics.second , byte_array.data (),
325
+ sizeof (byte_array)) != SIMPLEBLE_SUCCESS)
314
326
{
315
327
safe_logger (spdlog::level::err, " failed to send command {} to device" , config.c_str ());
316
328
return (int )BrainFlowExitCodes::BOARD_WRITE_ERROR;
@@ -394,8 +406,8 @@ void BrainAlive::read_data (simpleble_uuid_t service, simpleble_uuid_t character
394
406
{
395
407
package[eeg_channels[k]] =
396
408
(float )(((data[j] << 16 | data[j + 1 ] << 8 | data[j + 2 ]) << 8 ) >> 8 ) *
397
- ((((float )getReferenceVoltage () * 1000 ) /
398
- (float )(getSoftwareGain () * getHardwareGain () * FSR_Value)));
409
+ ((((float )get_ref_voltage () * 1000 ) /
410
+ (float )(get_internal_gain () * get_external_gain () * FSR_Value)));
399
411
}
400
412
401
413
for (int j = i + brainalive_axl_start_index, k = 0 ; j < i + brainalive_axl_end_index;
0 commit comments