| 52 | } |
| 53 | |
| 54 | int AAVAAv3::prepare_session () |
| 55 | { |
| 56 | if (initialized) |
| 57 | { |
| 58 | safe_logger (spdlog::level::info, "Session is already prepared"); |
| 59 | return (int)BrainFlowExitCodes::STATUS_OK; |
| 60 | } |
| 61 | if (params.timeout < 1) |
| 62 | { |
| 63 | params.timeout = 5; |
| 64 | } |
| 65 | safe_logger (spdlog::level::info, "Use timeout for discovery: {}", params.timeout); |
| 66 | if (!init_dll_loader ()) |
| 67 | { |
| 68 | safe_logger (spdlog::level::err, "Failed to init dll_loader"); |
| 69 | return (int)BrainFlowExitCodes::GENERAL_ERROR; |
| 70 | } |
| 71 | size_t adapter_count = simpleble_adapter_get_count (); |
| 72 | if (adapter_count == 0) |
| 73 | { |
| 74 | safe_logger (spdlog::level::err, "No BLE adapters found"); |
| 75 | return (int)BrainFlowExitCodes::UNABLE_TO_OPEN_PORT_ERROR; |
| 76 | } |
| 77 | |
| 78 | aavaa_adapter = simpleble_adapter_get_handle (0); |
| 79 | if (aavaa_adapter == NULL) |
| 80 | { |
| 81 | safe_logger (spdlog::level::err, "Adapter is NULL"); |
| 82 | return (int)BrainFlowExitCodes::UNABLE_TO_OPEN_PORT_ERROR; |
| 83 | } |
| 84 | |
| 85 | simpleble_adapter_set_callback_on_scan_start ( |
| 86 | aavaa_adapter, ::aavaa_adapter_1_on_scan_start, (void *)this); |
| 87 | simpleble_adapter_set_callback_on_scan_stop ( |
| 88 | aavaa_adapter, ::aavaa_adapter_1_on_scan_stop, (void *)this); |
| 89 | simpleble_adapter_set_callback_on_scan_found ( |
| 90 | aavaa_adapter, ::aavaa_adapter_1_on_scan_found, (void *)this); |
| 91 | |
| 92 | #ifdef _WIN32 |
| 93 | Sleep (1000); |
| 94 | #else |
| 95 | sleep (1); |
| 96 | #endif |
| 97 | |
| 98 | if (!simpleble_adapter_is_bluetooth_enabled ()) |
| 99 | { |
| 100 | safe_logger (spdlog::level::warn, "Probably bluetooth is disabled."); |
| 101 | // dont throw an exception because of this |
| 102 | // https://github.com/OpenBluetoothToolbox/SimpleBLE/issues/115 |
| 103 | } |
| 104 | |
| 105 | simpleble_adapter_scan_start (aavaa_adapter); |
| 106 | int res = (int)BrainFlowExitCodes::STATUS_OK; |
| 107 | std::unique_lock<std::mutex> lk (m); |
| 108 | auto sec = std::chrono::seconds (1); |
| 109 | if (cv.wait_for (lk, params.timeout * sec, [this] { return this->aavaa_peripheral != NULL; })) |
| 110 | { |
| 111 | safe_logger (spdlog::level::info, "Found AAVAAv3 device"); |
nothing calls this directly
no test coverage detected