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

Method find_device

src/board_controller/neuromd/neuromd_board.cpp:443–514  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

441}
442
443int NeuromdBoard::find_device ()
444{
445 if ((params.timeout < 0) || (params.timeout > 600))
446 {
447 safe_logger (spdlog::level::err, "bad value for timeout");
448 return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR;
449 }
450
451 DeviceEnumerator *enumerator = NULL;
452 if (board_id == (int)BoardIds::BRAINBIT_BOARD)
453 {
454 enumerator = create_device_enumerator (DeviceTypeBrainbit);
455 }
456 else
457 {
458 enumerator = create_device_enumerator (DeviceTypeCallibri);
459 }
460 if (enumerator == NULL)
461 {
462 char error_msg[1024];
463 sdk_last_error_msg (error_msg, 1024);
464 safe_logger (spdlog::level::err, "create enumerator error {}", error_msg);
465 return (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR;
466 }
467
468 int timeout = 15;
469 if (params.timeout != 0)
470 {
471 timeout = params.timeout;
472 }
473 safe_logger (spdlog::level::info, "set timeout for device discovery to {}", timeout);
474
475 int sleep_delay = 300;
476 int attempts = (int)(timeout * 1000.0 / sleep_delay);
477 int res = (int)BrainFlowExitCodes::STATUS_OK;
478 DeviceInfo device_info;
479 do
480 {
481 res = find_device_info (enumerator, &device_info);
482 if (res == (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR)
483 {
484 break;
485 }
486 if (res != (int)BrainFlowExitCodes::STATUS_OK)
487 {
488#ifdef _WIN32
489 Sleep (sleep_delay);
490#else
491 usleep (sleep_delay * 1000);
492#endif
493 continue;
494 }
495
496 break;
497 } while (attempts-- > 0);
498
499 if (res == (int)BrainFlowExitCodes::STATUS_OK)
500 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected