| 171 | } |
| 172 | |
| 173 | int Explore::start_stream (int buffer_size, const char *streamer_params) |
| 174 | { |
| 175 | if (!initialized) |
| 176 | { |
| 177 | safe_logger (spdlog::level::err, "You need to call prepare_session before start_stream"); |
| 178 | return (int)BrainFlowExitCodes::BOARD_NOT_CREATED_ERROR; |
| 179 | } |
| 180 | if (keep_alive) |
| 181 | { |
| 182 | safe_logger (spdlog::level::err, "Streaming thread already running"); |
| 183 | return (int)BrainFlowExitCodes::STREAM_ALREADY_RUN_ERROR; |
| 184 | } |
| 185 | |
| 186 | int res = prepare_for_acquisition (buffer_size, streamer_params); |
| 187 | if (res != (int)BrainFlowExitCodes::STATUS_OK) |
| 188 | { |
| 189 | return res; |
| 190 | } |
| 191 | |
| 192 | res = bluetooth_open_device (); |
| 193 | if (res != (int)BrainFlowExitCodes::STATUS_OK) |
| 194 | { |
| 195 | return res; |
| 196 | } |
| 197 | |
| 198 | keep_alive = true; |
| 199 | streaming_thread = std::thread ([this] { this->read_thread (); }); |
| 200 | // wait for the 1st package received |
| 201 | std::unique_lock<std::mutex> lk (this->m); |
| 202 | auto sec = std::chrono::seconds (1); |
| 203 | int num_secs = 7; |
| 204 | if (cv.wait_for (lk, num_secs * sec, |
| 205 | [this] { return this->state != (int)BrainFlowExitCodes::SYNC_TIMEOUT_ERROR; })) |
| 206 | { |
| 207 | return state; |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | safe_logger (spdlog::level::err, "no data received in {} sec, stopping thread", num_secs); |
| 212 | stop_stream (); |
| 213 | return (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | int Explore::stop_stream () |
| 218 | { |
nothing calls this directly
no test coverage detected