diff --git a/src/board_controller/ble_lib_board.cpp b/src/board_controller/ble_lib_board.cpp index 145e82352..be231b073 100644 --- a/src/board_controller/ble_lib_board.cpp +++ b/src/board_controller/ble_lib_board.cpp @@ -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 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) { diff --git a/src/board_controller/inc/ble_lib_board.h b/src/board_controller/inc/ble_lib_board.h index 32cf196ad..b252d47a6 100644 --- a/src/board_controller/inc/ble_lib_board.h +++ b/src/board_controller/inc/ble_lib_board.h @@ -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); diff --git a/src/board_controller/openbci/ganglion_native.cpp b/src/board_controller/openbci/ganglion_native.cpp index a96d90cf1..986b8b1ee 100644 --- a/src/board_controller/openbci/ganglion_native.cpp +++ b/src/board_controller/openbci/ganglion_native.cpp @@ -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) @@ -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 { @@ -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 @@ -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 lk (m); ganglion_peripheral = peripheral;