| 35 | } |
| 36 | |
| 37 | int Emotibit::prepare_session () |
| 38 | { |
| 39 | if (initialized) |
| 40 | { |
| 41 | safe_logger (spdlog::level::info, "Session is already prepared"); |
| 42 | return (int)BrainFlowExitCodes::STATUS_OK; |
| 43 | } |
| 44 | |
| 45 | if (params.timeout < 2) |
| 46 | { |
| 47 | params.timeout = 4; |
| 48 | } |
| 49 | |
| 50 | int res = create_adv_connection (); |
| 51 | if (res == (int)BrainFlowExitCodes::STATUS_OK) |
| 52 | { |
| 53 | res = create_data_connection (); |
| 54 | } |
| 55 | if (res == (int)BrainFlowExitCodes::STATUS_OK) |
| 56 | { |
| 57 | res = create_control_connection (); |
| 58 | } |
| 59 | if (res == (int)BrainFlowExitCodes::STATUS_OK) |
| 60 | { |
| 61 | res = send_connect_msg (); |
| 62 | } |
| 63 | if (res == (int)BrainFlowExitCodes::STATUS_OK) |
| 64 | { |
| 65 | res = wait_for_connection (); |
| 66 | } |
| 67 | if (res == (int)BrainFlowExitCodes::STATUS_OK) |
| 68 | { |
| 69 | res = send_control_msg (MODE_LOW_POWER); |
| 70 | } |
| 71 | |
| 72 | if (res != (int)BrainFlowExitCodes::STATUS_OK) |
| 73 | { |
| 74 | if (adv_socket != NULL) |
| 75 | { |
| 76 | delete adv_socket; |
| 77 | adv_socket = NULL; |
| 78 | } |
| 79 | if (data_socket != NULL) |
| 80 | { |
| 81 | delete data_socket; |
| 82 | data_socket = NULL; |
| 83 | } |
| 84 | if (control_socket != NULL) |
| 85 | { |
| 86 | delete control_socket; |
| 87 | control_socket = NULL; |
| 88 | } |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | initialized = true; |
| 93 | connection_thread = std::thread ([this] { this->ping_thread (); }); |
| 94 | } |
nothing calls this directly
no test coverage detected