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

Method read_thread

src/board_controller/synchroni/synchroni_board.cpp:70–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68
69
70void SynchroniBoard::read_thread ()
71{
72 int num_attempts = 0;
73 int sleep_time = 10;
74 int max_attempts = params.timeout * 1000 / sleep_time;
75
76 int (*func) (void *) = (int (*) (void *))dll_loader->get_address ("synchroni_get_data_default");
77 if (func == NULL)
78 {
79 safe_logger (spdlog::level::err, "failed to get function address for get_data");
80 state = (int)BrainFlowExitCodes::GENERAL_ERROR;
81 return;
82 }
83
84 int num_rows = board_descr["default"]["num_rows"];
85 double *data = new double[num_rows];
86 if (data == NULL)
87 {
88 safe_logger (spdlog::level::err, "failed to allocate data");
89 state = (int)BrainFlowExitCodes::GENERAL_ERROR;
90 return;
91 }
92 for (int i = 0; i < num_rows; i++)
93 {
94 data[i] = 0.0;
95 }
96
97 std::tuple<std::string, double *, int> info =
98 std::make_tuple (params.mac_address, data, num_rows);
99
100 while (keep_alive)
101 {
102 int res = func ((void *)&info);
103
104 if (res == (int)BrainFlowExitCodes::STATUS_OK)
105 {
106 if (state != (int)BrainFlowExitCodes::STATUS_OK)
107 {
108 {
109 std::lock_guard<std::mutex> lk (m);
110 state = (int)BrainFlowExitCodes::STATUS_OK;
111 }
112 cv.notify_one ();
113 }
114 push_package (data);
115 }
116 else
117 {
118 if (state == (int)BrainFlowExitCodes::SYNC_TIMEOUT_ERROR)
119 {
120 num_attempts++;
121 }
122 if (num_attempts == max_attempts)
123 {
124 safe_logger (spdlog::level::err, "no data received");
125 {
126 std::lock_guard<std::mutex> lk (m);
127 state = (int)BrainFlowExitCodes::GENERAL_ERROR;

Callers

nothing calls this directly

Calls 1

get_addressMethod · 0.45

Tested by

no test coverage detected