Core library#
Initialization, configuration, scanning and versioning, plus the codes these functions return.
bacore.h#
Core library info and lifecycle API.
- Author
Neurotechnology (brainaccess@neurotechnology.com)
- Copyright
Copyright (c) 2022 Neurotechnology
Defines
-
BA_INIT_ERROR_UNKNOWN#
Unknown error.
-
BA_INIT_ERROR_OK#
Initialized successfully.
-
BA_INIT_ERROR_CONFIG_TYPE#
Invalid config value type.
-
BA_INIT_ERROR_WRONG_ADAPTER_VALUE#
Invalid Bluetooth adapter value.
-
BA_INIT_ERROR_INCOMPATIBLE_VERSION#
Incompatible library version.
-
BA_INIT_ERROR_NOT_ENABLED#
Bluetooth isn’t enabled.
-
BA_INIT_ERROR_NOT_FOUND#
Bluetooth adapter not found.
-
BA_INIT_ERROR_CONFIG_PARSE#
Invalid or missing config file.
-
BA_INIT_ERROR_INVALID_PATH#
Invalid file path
-
BA_INIT_ERROR_NOT_ALL_MANAGERS_CLOSED#
ba_core_close() refused: EEG managers not freed yet (same value as BA_ERROR_NOT_ALL_MANAGERS_CLOSED)
-
BA_INIT_WARNING_ALREADY_INITIALIZED#
Already initialized.
-
BA_INIT_WARNING_NOT_INITIALIZED#
Not initialized, so there was nothing to shut down.
Typedefs
-
typedef uint8_t ba_init_error#
Type of the codes ba_core_init() and ba_core_close() return: BA_INIT_ERROR_* and BA_INIT_WARNING_*.
Functions
-
ba_init_error ba_core_init()#
Initializes the core system of the application.
This function sets up the core system, ensuring that all necessary parts and resources are properly initialized. It must be called before performing any operations that depend on the core system.
- Returns:
A
ba_init_errorindicating the success or failure of the initialization:BA_INIT_ERROR_OK: The core system was successfully initialized.
BA_INIT_WARNING_ALREADY_INITIALIZED: The core system was already initialized. Nothing was changed and no matching ba_core_close() is owed for this call.
BA_INIT_ERROR_UNKNOWN: Allocation failed. Nothing is left allocated, the core stays uninitialized, and the call may be retried.
-
ba_error ba_core_get_config(sBACORE_Config_t *config)#
Retrieves the current core configuration.
Copies the library’s current configuration into the caller-provided sBACORE_Config_t structure. The core must be initialized with ba_core_init() before calling this function.
- Parameters:
config – [out] Pointer to a pre-allocated sBACORE_Config_t structure that receives the current configuration. Must not be NULL.
- Returns:
A ba_error indicating the result:
BA_ERROR_OK: Configuration successfully copied.
BA_ERROR_CORE_NOT_INITIALIZED: ba_core_init() has not been called, or ba_core_close() has already been called.
-
ba_error ba_core_set_config(sBACORE_Config_t *config)#
Sets the core configuration.
Applies the provided configuration to the library. The core must be initialized with ba_core_init() before calling this function. On success, the logging subsystem is reinitialized, according to the new settings (log_buffer_size, log_path, append_logs, log_level, timestamps_enabled, thread_ids_enabled, enable_logs, autoflush). The log file is created (or, with append_logs false, truncated) when the first line is written, not when logging is enabled, so setting enable_logs to false right after ba_core_init() leaves no file at the default path. Other fields (e.g., adapter_index, chunk_size) affect later operations where relevant.
- Parameters:
config – [in] Pointer to the configuration to apply. Must not be NULL.
- Returns:
A ba_error indicating the result:
BA_ERROR_OK: Configuration successfully applied.
BA_ERROR_CORE_NOT_INITIALIZED: ba_core_init() has not been called, or ba_core_close() has already been called.
BA_ERROR_WRONG_VALUE:
configis NULL, orchunk_sizeis outside 1..100. Nothing is applied.
-
const ba_version *ba_core_get_version()#
Retrieves a pointer to the library’s version information.
Provides the library’s version information, including major, minor, and patch numbers using semantic versioning. This information can be used to ensure compatibility.
- Returns:
Pointer to a
ba_versionstructure containing the library’s version information.
-
ba_error ba_core_scan(ba_ble_device **device_list, size_t *device_list_size)#
Scans for available Bluetooth devices.
This function triggers a scan to discover nearby Bluetooth devices and populates the provided device list with the scan results.
The scan blocks for about five seconds.
device_listis set to an internal buffer owned by the library: do not free it, and treat it as valid only until the next ba_core_scan() or ba_core_close().- Parameters:
device_list – Pointer to an array of ba_ble_device pointers that will store the discovered devices
device_list_size – Pointer to size_t that will store the number of discovered devices
- Returns:
A
ba_errorindicating the success or failure of the scanning process:BA_ERROR_OK: The scan completed. Only BrainAccess names (“BA <model>
<number>”) are listed, so a count of zero means no headset was advertising, not that anything failed.
BA_ERROR_CORE_NOT_INITIALIZED: ba_core_init() has not been called, or ba_core_close() has already been called.
BA_ERROR_WRONG_VALUE: device_list or device_list_size is NULL.
BA_ERROR_ADAPTER_OUT_OF_INDEX: The host has Bluetooth controllers, but not the one sBACORE_Config_t::adapter_index named. No scan ran.
BA_ERROR_BLUETOOTH_ADAPTER_NOT_FOUND: The Bluetooth service answered and reported no controller at all. No scan ran.
BA_ERROR_BLUETOOTH_SERVICE_UNAVAILABLE: The Bluetooth service could not be reached, or did not answer in time, so whether a controller exists is unknown. No scan ran.
-
ba_init_error ba_core_close()#
Shuts down the core system of the application.
This function performs cleanup operations, releasing all resources and components initialized by the core system. It should be called when the core system is no longer needed or before application termination.
- Returns:
A
ba_init_errorindicating the success or failure of the shutdown process:BA_INIT_ERROR_OK: The core system was successfully shut down.
BA_INIT_WARNING_NOT_INITIALIZED: The core system was not initialized, so there was nothing to shut down. This is the mirror of BA_INIT_WARNING_ALREADY_INITIALIZED: a call made in the wrong order, not a failure of this call.
BA_INIT_ERROR_NOT_ALL_MANAGERS_CLOSED: At least one EEG manager from ba_eeg_manager_new() has not been passed to ba_eeg_manager_free(). Nothing was shut down; free every manager and call ba_core_close() again.
-
struct sBACORE_Config_t#
- #include <bacore.h>
Library configuration, read with ba_core_get_config() and applied with ba_core_set_config().
ba_core_init() fills it with the defaults listed per field. Read it, change the fields you need and write it back, so the others keep their current values.
Public Members
-
size_t log_buffer_size#
Size of the log buffer in bytes (default 512).
-
char log_path[200]#
NUL-terminated path of the log file (default “bacore.log”).
-
ba_log_level log_level#
Lowest level written to the log (default BA_LOG_LEVEL_INFO); see log_level.h.
-
bool append_logs#
Append to an existing log file; false overwrites it (default false).
-
bool timestamps_enabled#
Prefix each log line with a timestamp (default true).
-
bool autoflush#
Flush the log after every line (default false).
-
bool thread_ids_enabled#
Include the thread ID in each log line (default true).
-
size_t chunk_size#
Samples per chunk callback, 1 to 100 (default 25); see ba_eeg_manager_set_callback_chunk.
-
bool enable_logs#
Write the log file at all (default true).
-
char update_path[200]#
NUL-terminated path of the firmware image ba_eeg_manager_start_update() sends.
-
uint8_t adapter_index#
Linux only: index of the Bluetooth controller to use (default 0).
-
size_t log_buffer_size#
version.h#
Version numbers.
- Author
Neurotechnology (brainaccess@neurotechnology.com)
- Copyright
Copyright (c) 2022 Neurotechnology
Functions
-
bool ba_is_version_compatible(const ba_version *expected, const ba_version *actual)#
Check if versions are compatible.
Versions are compatible when their major and minor numbers are equal; the patch number is ignored.
- Parameters:
expected – Version the application was built against
actual – Version to check, e.g. from ba_core_get_version()
- Returns:
trueif compatible,falseif not or if either is NULL
-
struct ba_version#
- #include <version.h>
Struct describing version numbers.
Uses semantic versioning
log_level.h#
Defines constants for different log levels used in the library.
- Author
Neurotechnology (brainaccess@neurotechnology.com)
- Copyright
Copyright (c) 2022 Neurotechnology
Defines
-
BA_LOG_LEVEL_VERBOSE#
Log level for verbose messages.
-
BA_LOG_LEVEL_DEBUG#
Log level for debug messages.
-
BA_LOG_LEVEL_INFO#
Log level for informational messages.
-
BA_LOG_LEVEL_WARNING#
Log level for warning messages.
-
BA_LOG_LEVEL_ERROR#
Log level for error messages.
Typedefs
-
typedef uint8_t ba_log_level#
Type definition for log level.
error.h#
This file defines error codes used in the library.
- Author
Neurotechnology (brainaccess@neurotechnology.com)
- Copyright
Copyright (c) 2022 Neurotechnology
Defines
-
BA_ERROR_OK#
No error.
-
BA_ERROR_CONNECTION#
Connection error.
-
BA_ERROR_UNSUPPORTED_DEVICE#
Unsupported device error.
-
BA_ERROR_WRONG_VALUE#
Wrong value error.
-
BA_ERROR_BLUETOOTH_DISABLED#
Bluetooth disabled error.
-
BA_ERROR_BLUETOOTH_ADAPTER_NOT_FOUND#
Bluetooth adapter didn’t find error.
-
BA_ERROR_ADAPTER_OUT_OF_INDEX#
Adapter out of index error.
-
BA_ERROR_UPDATE_FILE_NOT_FOUND#
OTA update file not found.
-
BA_ERROR_UPDATE_INITIATED_UNSUCCESSFULLY#
OTA update initiated unsuccessfully.
-
BA_ERROR_UPDATE_FAILED_DEVICE_DISCONNECTED#
OTA update failed, device disconnect.
-
BA_ERROR_ANNOTATION_UNAVAILABLE_CALIBRATING#
Unavailable to set annotation. Calibrating, try in a few seconds.
-
BA_ERROR_NO_DEVICES_FOUND#
0 devices were found
-
BA_ERROR_NOT_ALL_MANAGERS_CLOSED#
Not all managers were closed properly.
-
BA_ERROR_CORE_NOT_INITIALIZED#
Core not initialized error.
-
BA_ERROR_PATH_NOT_FOUND#
Path not found.
-
BA_ERROR_BLUETOOTH_SERVICE_UNAVAILABLE#
The Bluetooth service could not be reached to be asked.
Distinct from BA_ERROR_BLUETOOTH_ADAPTER_NOT_FOUND, which means the service answered and reported no controller. This one means no answer: the system bus is unreachable, or the request timed out. The host may well have a working adapter; nothing here has established otherwise.
-
BA_ERROR_UPDATE_REJECTED#
The device received the whole update image and refused it.
The device validated the image after the last packet and rejected it (corrupt, truncated, or not signed for it). It keeps running the firmware it had; the boot partition is unchanged.
-
BA_ERROR_STREAM_START_FAILED#
The device accepted the start command but could not start streaming.
It could not configure its EEG converter over its internal bus. It has powered the converter back down and will send no data; the connection stays usable, so the start can be retried.
-
BA_ERROR_NOT_STREAMING#
The request needs a running stream.
The device powers its EEG converter only while it streams, so between streams there is nothing to answer it.
-
BA_ERROR_UNKNOWN#
Unknown error.
Typedefs
-
typedef uint8_t ba_error#
Type definition for error code.