| 30 | } |
| 31 | |
| 32 | int Enophone::start_stream (int buffer_size, const char *streamer_params) |
| 33 | { |
| 34 | if (!initialized) |
| 35 | { |
| 36 | safe_logger (spdlog::level::err, "You need to call prepare_session before start_stream"); |
| 37 | return (int)BrainFlowExitCodes::BOARD_NOT_CREATED_ERROR; |
| 38 | } |
| 39 | if (keep_alive) |
| 40 | { |
| 41 | safe_logger (spdlog::level::err, "Streaming thread already running"); |
| 42 | return (int)BrainFlowExitCodes::STREAM_ALREADY_RUN_ERROR; |
| 43 | } |
| 44 | |
| 45 | int res = prepare_for_acquisition (buffer_size, streamer_params); |
| 46 | if (res != (int)BrainFlowExitCodes::STATUS_OK) |
| 47 | { |
| 48 | return res; |
| 49 | } |
| 50 | |
| 51 | res = bluetooth_open_device (); |
| 52 | if (res != (int)BrainFlowExitCodes::STATUS_OK) |
| 53 | { |
| 54 | return res; |
| 55 | } |
| 56 | |
| 57 | keep_alive = true; |
| 58 | streaming_thread = std::thread ([this] { this->read_thread (); }); |
| 59 | // wait for the 1st package received |
| 60 | std::unique_lock<std::mutex> lk (this->m); |
| 61 | auto sec = std::chrono::seconds (1); |
| 62 | int num_secs = 5; |
| 63 | if (cv.wait_for (lk, num_secs * sec, |
| 64 | [this] { return this->state != (int)BrainFlowExitCodes::SYNC_TIMEOUT_ERROR; })) |
| 65 | { |
| 66 | return state; |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | safe_logger (spdlog::level::err, "no data received in {} sec, stopping thread", num_secs); |
| 71 | stop_stream (); |
| 72 | return (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | int Enophone::stop_stream () |
| 77 | { |
nothing calls this directly
no test coverage detected