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
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool

{
std::lock_guard<std::mutex> lk (m);
ganglion_peripheral = peripheral;
Expand Down