Skip to content

Commit

Permalink
Support Ganglion v3 detection on MacOS native BLE (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippitts authored Sep 20, 2023
1 parent 5b3a118 commit bee49d3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
23 changes: 23 additions & 0 deletions src/board_controller/ble_lib_board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,29 @@ simpleble_err_t BLELibBoard::simpleble_peripheral_manufacturer_data_get (
return func (handle, index, manufacturer_data);
}

simpleble_err_t BLELibBoard::simpleble_peripheral_read (simpleble_peripheral_t handle,
simpleble_uuid_t service, simpleble_uuid_t characteristic, uint8_t **data, size_t *data_length)
{
std::lock_guard<std::mutex> lock (BLELibBoard::mutex);
if (BLELibBoard::dll_loader == NULL)
{
safe_logger (spdlog::level::err, "BLELibBoard::dll_loader is not initialized");
return SIMPLEBLE_FAILURE;
}
simpleble_err_t (*func) (simpleble_peripheral_t, simpleble_uuid_t, simpleble_uuid_t, uint8_t **,
size_t *) = (simpleble_err_t (*) (simpleble_peripheral_t, simpleble_uuid_t,
simpleble_uuid_t, uint8_t **,
size_t *))BLELibBoard::dll_loader->get_address ("simpleble_peripheral_read");
if (func == NULL)
{
safe_logger (
spdlog::level::err, "failed to get function address for simpleble_peripheral_read");
return SIMPLEBLE_FAILURE;
}

return func (handle, service, characteristic, data, data_length);
}

simpleble_err_t BLELibBoard::simpleble_peripheral_is_connected (
simpleble_peripheral_t handle, bool *connected)
{
Expand Down
3 changes: 3 additions & 0 deletions src/board_controller/inc/ble_lib_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class BLELibBoard : public Board
size_t simpleble_peripheral_manufacturer_data_count (simpleble_peripheral_t handle);
simpleble_err_t simpleble_peripheral_manufacturer_data_get (simpleble_peripheral_t handle,
size_t index, simpleble_manufacturer_data_t *manufacturer_data);
simpleble_err_t simpleble_peripheral_read (simpleble_peripheral_t handle,
simpleble_uuid_t service, simpleble_uuid_t characteristic, uint8_t **data,
size_t *data_length);
simpleble_err_t simpleble_peripheral_is_connected (
simpleble_peripheral_t handle, bool *connected);

Expand Down
19 changes: 14 additions & 5 deletions src/board_controller/openbci/ganglion_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#define GANGLION_WRITE_CHAR "2d30c083-f39f-4ce6-923f-3484ea480596"
#define GANGLION_NOTIFY_CHAR "2d30c082-f39f-4ce6-923f-3484ea480596"
#define GANGLION_SOFTWARE_REVISION "00002a28-0000-1000-8000-00805f9b34fb"


static void ganglion_adapter_1_on_scan_start (simpleble_adapter_t adapter, void *board)
Expand Down Expand Up @@ -108,7 +109,6 @@ int GanglionNative::prepare_session ()
lk, params.timeout * sec, [this] { return this->ganglion_peripheral != NULL; }))
{
safe_logger (spdlog::level::info, "Found GanglionNative device");
safe_logger (spdlog::level::info, "Detected firmware version {}", firmware);
}
else
{
Expand Down Expand Up @@ -162,11 +162,21 @@ int GanglionNative::prepare_session ()
res = (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR;
}

safe_logger (spdlog::level::trace, "found servce {}", service.uuid.value);
safe_logger (spdlog::level::trace, "found service {}", service.uuid.value);
for (size_t j = 0; j < service.characteristic_count; j++)
{
safe_logger (spdlog::level::trace, "found characteristic {}",
service.characteristics[j].uuid.value);
// Read the software revision characteristic to get the firmware version
if (strcmp (service.characteristics[j].uuid.value, GANGLION_SOFTWARE_REVISION) == 0)
{
uint8_t *data;
size_t data_length;
simpleble_peripheral_read (ganglion_peripheral, service.uuid,
service.characteristics[j].uuid, &data, &data_length);

// Data should be in the form x.x.x stored as ASCII values in the data buffer
firmware = (data[0] == '3') ? 3 : 2;
safe_logger (spdlog::level::info, "Detected firmware version {}", firmware);
}

if (strcmp (service.characteristics[j].uuid.value,
GANGLION_WRITE_CHAR) == 0) // Write Characteristics
Expand Down Expand Up @@ -444,7 +454,6 @@ void GanglionNative::adapter_1_on_scan_found (

if (found)
{
firmware = strncmp (peripheral_identified, "Ganglion 1.3", 12) == 0 ? 3 : 2;
{
std::lock_guard<std::mutex> lk (m);
ganglion_peripheral = peripheral;
Expand Down

0 comments on commit bee49d3

Please sign in to comment.