| 58 | } |
| 59 | |
| 60 | int NotionOSC::start_stream (int buffer_size, const char *streamer_params) |
| 61 | { |
| 62 | if (!initialized) |
| 63 | { |
| 64 | safe_logger (spdlog::level::err, "You need to call prepare_session before config_board"); |
| 65 | return (int)BrainFlowExitCodes::BOARD_NOT_CREATED_ERROR; |
| 66 | } |
| 67 | if (keep_alive) |
| 68 | { |
| 69 | safe_logger (spdlog::level::err, "Streaming thread already running"); |
| 70 | return (int)BrainFlowExitCodes::STREAM_ALREADY_RUN_ERROR; |
| 71 | } |
| 72 | int res = prepare_for_acquisition (buffer_size, streamer_params); |
| 73 | if (res != (int)BrainFlowExitCodes::STATUS_OK) |
| 74 | { |
| 75 | return res; |
| 76 | } |
| 77 | |
| 78 | keep_alive = true; |
| 79 | streaming_thread = std::thread ([this] { this->read_thread (); }); |
| 80 | // wait for data to ensure that everything is okay |
| 81 | std::unique_lock<std::mutex> lk (this->m); |
| 82 | auto sec = std::chrono::seconds (1); |
| 83 | if (cv.wait_for (lk, 5 * sec, |
| 84 | [this] { return this->state != (int)BrainFlowExitCodes::SYNC_TIMEOUT_ERROR; })) |
| 85 | { |
| 86 | return state; |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | safe_logger (spdlog::level::err, "no data received in 5sec, stopping thread"); |
| 91 | this->stop_stream (); |
| 92 | return (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | int NotionOSC::stop_stream () |
| 97 | { |
nothing calls this directly
no test coverage detected