MCPcopy Create free account
hub / github.com/brainflow-dev/brainflow / stop_stream

Method stop_stream

src/board_controller/openbci/galea.cpp:282–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280}
281
282int Galea::stop_stream ()
283{
284 if (is_streaming)
285 {
286 keep_alive = false;
287 is_streaming = false;
288 streaming_thread.join ();
289 this->state = (int)BrainFlowExitCodes::SYNC_TIMEOUT_ERROR;
290 int res = socket->send ("s", 1);
291 if (res != 1)
292 {
293 if (res == -1)
294 {
295#ifdef _WIN32
296 safe_logger (spdlog::level::err, "WSAGetLastError is {}", WSAGetLastError ());
297#else
298 safe_logger (spdlog::level::err, "errno {} message {}", errno, strerror (errno));
299#endif
300 }
301 safe_logger (spdlog::level::err, "Failed to send a command to board");
302 return (int)BrainFlowExitCodes::BOARD_WRITE_ERROR;
303 }
304
305 // free kernel buffer
306 unsigned char b[Galea::max_transaction_size];
307 res = 0;
308 int max_attempt = 25; // to dont get to infinite loop
309 int current_attempt = 0;
310 while (res != -1)
311 {
312 res = socket->recv (b, Galea::max_transaction_size);
313 current_attempt++;
314 if (current_attempt == max_attempt)
315 {
316 safe_logger (
317 spdlog::level::err, "Command 's' was sent but streaming is still running.");
318 return (int)BrainFlowExitCodes::BOARD_WRITE_ERROR;
319 }
320 }
321
322 std::string resp;
323 for (int i = 0; i < 3; i++)
324 {
325 res = calc_time (resp); // call it in the end once to print time in the end
326 if (res != (int)BrainFlowExitCodes::STATUS_OK)
327 {
328 break; // dont send exit code
329 }
330 }
331 return (int)BrainFlowExitCodes::STATUS_OK;
332 }
333 else
334 {
335 return (int)BrainFlowExitCodes::STREAM_THREAD_IS_NOT_RUNNING;
336 }
337}
338
339int Galea::release_session ()

Callers 1

start_streamMethod · 0.95

Calls 2

sendMethod · 0.45
recvMethod · 0.45

Tested by

no test coverage detected