| 314 | } |
| 315 | |
| 316 | int SynchroniBoard::start_stream (int buffer_size, const char *streamer_params) |
| 317 | { |
| 318 | if (is_streaming) |
| 319 | { |
| 320 | safe_logger (spdlog::level::err, "Streaming thread already running"); |
| 321 | return (int)BrainFlowExitCodes::STREAM_ALREADY_RUN_ERROR; |
| 322 | } |
| 323 | if (buffer_size <= 0 || buffer_size > MAX_CAPTURE_SAMPLES) |
| 324 | { |
| 325 | safe_logger (spdlog::level::err, "invalid array size"); |
| 326 | return (int)BrainFlowExitCodes::INVALID_BUFFER_SIZE_ERROR; |
| 327 | } |
| 328 | |
| 329 | int res = prepare_for_acquisition (buffer_size, streamer_params); |
| 330 | if (res != (int)BrainFlowExitCodes::STATUS_OK) |
| 331 | { |
| 332 | return res; |
| 333 | } |
| 334 | |
| 335 | res = call_start (); |
| 336 | if (res != (int)BrainFlowExitCodes::STATUS_OK) |
| 337 | { |
| 338 | return res; |
| 339 | } |
| 340 | |
| 341 | keep_alive = true; |
| 342 | streaming_thread = std::thread ([this] { read_thread (); }); |
| 343 | |
| 344 | // wait for data to ensure that everything is okay |
| 345 | std::unique_lock<std::mutex> lk (m); |
| 346 | auto sec = std::chrono::seconds (1); |
| 347 | if (cv.wait_for (lk, params.timeout * sec, |
| 348 | [this] { return state != (int)BrainFlowExitCodes::SYNC_TIMEOUT_ERROR; })) |
| 349 | { |
| 350 | is_streaming = true; |
| 351 | return state; |
| 352 | } |
| 353 | else |
| 354 | { |
| 355 | safe_logger ( |
| 356 | spdlog::level::err, "no data received in {} sec, stopping thread", params.timeout); |
| 357 | is_streaming = true; |
| 358 | stop_stream (); |
| 359 | return (int)BrainFlowExitCodes::SYNC_TIMEOUT_ERROR; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | int SynchroniBoard::stop_stream () |
| 364 | { |
nothing calls this directly
no test coverage detected