| 214 | } |
| 215 | |
| 216 | int Galea::start_stream (int buffer_size, const char *streamer_params) |
| 217 | { |
| 218 | if (!initialized) |
| 219 | { |
| 220 | safe_logger (spdlog::level::err, "You need to call prepare_session before config_board"); |
| 221 | return (int)BrainFlowExitCodes::BOARD_NOT_CREATED_ERROR; |
| 222 | } |
| 223 | if (is_streaming) |
| 224 | { |
| 225 | safe_logger (spdlog::level::err, "Streaming thread already running"); |
| 226 | return (int)BrainFlowExitCodes::STREAM_ALREADY_RUN_ERROR; |
| 227 | } |
| 228 | |
| 229 | // calc time before start stream |
| 230 | std::string resp; |
| 231 | for (int i = 0; i < 3; i++) |
| 232 | { |
| 233 | int res = calc_time (resp); |
| 234 | if (res != (int)BrainFlowExitCodes::STATUS_OK) |
| 235 | { |
| 236 | return res; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | int res = prepare_for_acquisition (buffer_size, streamer_params); |
| 241 | if (res != (int)BrainFlowExitCodes::STATUS_OK) |
| 242 | { |
| 243 | return res; |
| 244 | } |
| 245 | |
| 246 | // start streaming |
| 247 | res = socket->send ("b", 1); |
| 248 | if (res != 1) |
| 249 | { |
| 250 | if (res == -1) |
| 251 | { |
| 252 | #ifdef _WIN32 |
| 253 | safe_logger (spdlog::level::err, "WSAGetLastError is {}", WSAGetLastError ()); |
| 254 | #else |
| 255 | safe_logger (spdlog::level::err, "errno {} message {}", errno, strerror (errno)); |
| 256 | #endif |
| 257 | } |
| 258 | safe_logger (spdlog::level::err, "Failed to send a command to board"); |
| 259 | return (int)BrainFlowExitCodes::BOARD_WRITE_ERROR; |
| 260 | } |
| 261 | |
| 262 | keep_alive = true; |
| 263 | streaming_thread = std::thread ([this] { this->read_thread (); }); |
| 264 | // wait for data to ensure that everything is okay |
| 265 | std::unique_lock<std::mutex> lk (this->m); |
| 266 | auto sec = std::chrono::seconds (1); |
| 267 | if (cv.wait_for (lk, 3 * sec, |
| 268 | [this] { return this->state != (int)BrainFlowExitCodes::SYNC_TIMEOUT_ERROR; })) |
| 269 | { |
| 270 | this->is_streaming = true; |
| 271 | return this->state; |
| 272 | } |
| 273 | else |
nothing calls this directly
no test coverage detected