| 47 | } |
| 48 | |
| 49 | int BTLibBoard::prepare_session () |
| 50 | { |
| 51 | if (initialized) |
| 52 | { |
| 53 | safe_logger (spdlog::level::info, "Session is already prepared"); |
| 54 | return (int)BrainFlowExitCodes::STATUS_OK; |
| 55 | } |
| 56 | |
| 57 | int return_res = (int)BrainFlowExitCodes::STATUS_OK; |
| 58 | if (!dll_loader->load_library ()) |
| 59 | { |
| 60 | safe_logger (spdlog::level::err, "Failed to load library"); |
| 61 | return_res = (int)BrainFlowExitCodes::GENERAL_ERROR; |
| 62 | } |
| 63 | else |
| 64 | { |
| 65 | safe_logger (spdlog::level::debug, "Library is loaded"); |
| 66 | } |
| 67 | |
| 68 | if (params.ip_port <= 0) |
| 69 | { |
| 70 | params.ip_port = 1; |
| 71 | } |
| 72 | safe_logger (spdlog::level::info, "Use bluetooth port: {}", params.ip_port); |
| 73 | if ((params.mac_address.empty ()) && (return_res == (int)BrainFlowExitCodes::STATUS_OK)) |
| 74 | { |
| 75 | safe_logger ( |
| 76 | spdlog::level::warn, "mac address is not provided, trying to autodiscover device"); |
| 77 | int res = find_bt_addr (get_name_selector ().c_str ()); |
| 78 | if (res == (int)SocketBluetoothReturnCodes::UNIMPLEMENTED_ERROR) |
| 79 | { |
| 80 | safe_logger (spdlog::level::err, "autodiscovery for this OS is not supported"); |
| 81 | return_res = (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR; |
| 82 | } |
| 83 | else if (res == (int)SocketBluetoothReturnCodes::DEVICE_IS_NOT_DISCOVERABLE) |
| 84 | { |
| 85 | safe_logger (spdlog::level::err, "check that device paired and connected"); |
| 86 | return_res = (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR; |
| 87 | } |
| 88 | else if (res != (int)SocketBluetoothReturnCodes::STATUS_OK) |
| 89 | { |
| 90 | safe_logger (spdlog::level::err, "failed to autodiscover device: {}", res); |
| 91 | return_res = (int)BrainFlowExitCodes::GENERAL_ERROR; |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | safe_logger (spdlog::level::info, "found device {}", params.mac_address.c_str ()); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | if (return_res == (int)BrainFlowExitCodes::STATUS_OK) |
| 100 | { |
| 101 | initialized = true; |
| 102 | } |
| 103 | else |
| 104 | { |
| 105 | dll_loader->free_library (); |
| 106 | delete dll_loader; |
nothing calls this directly
no test coverage detected