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

Method read_thread

src/board_controller/dyn_lib_board.cpp:147–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145}
146
147void DynLibBoard::read_thread ()
148{
149 int num_attempts = 0;
150 int sleep_time = 10;
151 int max_attempts = params.timeout * 1000 / sleep_time;
152
153 int (*func) (void *) = (int (*) (void *))dll_loader->get_address ("get_data");
154 if (func == NULL)
155 {
156 safe_logger (spdlog::level::err, "failed to get function address for get_data");
157 state = (int)BrainFlowExitCodes::GENERAL_ERROR;
158 return;
159 }
160
161 int num_rows = board_descr["default"]["num_rows"];
162 double *data = new double[num_rows];
163 if (data == NULL)
164 {
165 safe_logger (spdlog::level::err, "failed to allocate data");
166 state = (int)BrainFlowExitCodes::GENERAL_ERROR;
167 return;
168 }
169 for (int i = 0; i < num_rows; i++)
170 {
171 data[i] = 0.0;
172 }
173 while (keep_alive)
174 {
175 int res = func ((void *)data);
176 if (res == (int)BrainFlowExitCodes::STATUS_OK)
177 {
178 if (state != (int)BrainFlowExitCodes::STATUS_OK)
179 {
180 {
181 std::lock_guard<std::mutex> lk (m);
182 state = (int)BrainFlowExitCodes::STATUS_OK;
183 }
184 cv.notify_one ();
185 }
186 push_package (data);
187 }
188 else
189 {
190 if (state == (int)BrainFlowExitCodes::SYNC_TIMEOUT_ERROR)
191 {
192 num_attempts++;
193 }
194 if (num_attempts == max_attempts)
195 {
196 safe_logger (spdlog::level::err, "no data received");
197 {
198 std::lock_guard<std::mutex> lk (m);
199 state = (int)BrainFlowExitCodes::GENERAL_ERROR;
200 }
201 cv.notify_one ();
202 break;
203 }
204#ifdef _WIN32

Callers

nothing calls this directly

Calls 1

get_addressMethod · 0.45

Tested by

no test coverage detected