| 241 | } |
| 242 | |
| 243 | void Explore::read_thread () |
| 244 | { |
| 245 | // exg data |
| 246 | int num_exg_rows = board_descr["default"]["num_rows"]; |
| 247 | double *package_exg = new double[num_exg_rows]; |
| 248 | memset (package_exg, 0, sizeof (double) * num_exg_rows); |
| 249 | // orientation data |
| 250 | int num_aux_rows = board_descr["auxiliary"]["num_rows"]; |
| 251 | double *package_aux = new double[num_aux_rows]; |
| 252 | memset (package_aux, 0, sizeof (double) * num_aux_rows); |
| 253 | // env data |
| 254 | int num_anc_rows = board_descr["ancillary"]["num_rows"]; |
| 255 | double *package_anc = new double[num_anc_rows]; |
| 256 | memset (package_anc, 0, sizeof (double) * num_anc_rows); |
| 257 | |
| 258 | unsigned char payload_buffer[UINT16_MAX]; |
| 259 | |
| 260 | while (keep_alive) |
| 261 | { |
| 262 | struct ExploreHeader header; |
| 263 | int res = bluetooth_get_data ((char *)&header, sizeof (header)); |
| 264 | if (res < 0) |
| 265 | { |
| 266 | safe_logger (spdlog::level::err, "error reading data from bluetooth"); |
| 267 | } |
| 268 | if (res != 8) |
| 269 | { |
| 270 | continue; |
| 271 | } |
| 272 | // notify main thread that 1st byte received |
| 273 | if (state != (int)BrainFlowExitCodes::STATUS_OK) |
| 274 | { |
| 275 | { |
| 276 | std::lock_guard<std::mutex> lk (m); |
| 277 | state = (int)BrainFlowExitCodes::STATUS_OK; |
| 278 | } |
| 279 | cv.notify_one (); |
| 280 | safe_logger (spdlog::level::debug, "received first package"); |
| 281 | } |
| 282 | res = 0; |
| 283 | // safe_logger (spdlog::level::trace, "header pid counter size timestamp: {} {} {} {}", |
| 284 | // header.pid, header.counter, header.payload_size, header.timestamp); |
| 285 | |
| 286 | header.payload_size -= 4; // its because of timestamp which moved to header from the package |
| 287 | if (header.payload_size < 1) |
| 288 | { |
| 289 | safe_logger (spdlog::level::err, "negative size for payload"); |
| 290 | continue; |
| 291 | } |
| 292 | |
| 293 | while ((res != header.payload_size) && (keep_alive)) |
| 294 | { |
| 295 | res = bluetooth_get_data ((char *)payload_buffer, header.payload_size); |
| 296 | } |
| 297 | if (!keep_alive) |
| 298 | { |
| 299 | break; |
| 300 | } |
no test coverage detected