| 41 | } |
| 42 | |
| 43 | int Galea::prepare_session () |
| 44 | { |
| 45 | if (initialized) |
| 46 | { |
| 47 | safe_logger (spdlog::level::info, "Session is already prepared"); |
| 48 | return (int)BrainFlowExitCodes::STATUS_OK; |
| 49 | } |
| 50 | if ((params.timeout > 600) || (params.timeout < 1)) |
| 51 | { |
| 52 | params.timeout = 5; |
| 53 | } |
| 54 | |
| 55 | if (params.ip_address.empty ()) |
| 56 | { |
| 57 | params.ip_address = find_device (); |
| 58 | if (params.ip_address.empty ()) |
| 59 | { |
| 60 | return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR; |
| 61 | } |
| 62 | } |
| 63 | socket = new SocketClientUDP (params.ip_address.c_str (), 2390); |
| 64 | int res = socket->connect (); |
| 65 | if (res != (int)SocketClientUDPReturnCodes::STATUS_OK) |
| 66 | { |
| 67 | safe_logger (spdlog::level::err, "failed to init socket: {}", res); |
| 68 | delete socket; |
| 69 | socket = NULL; |
| 70 | return (int)BrainFlowExitCodes::GENERAL_ERROR; |
| 71 | } |
| 72 | |
| 73 | safe_logger (spdlog::level::trace, "timeout for socket is {}", socket_timeout); |
| 74 | socket->set_timeout (socket_timeout); |
| 75 | // force default settings for device |
| 76 | std::string tmp; |
| 77 | std::string default_settings = "d"; // use default mode |
| 78 | res = config_board (default_settings, tmp); |
| 79 | if (res != (int)BrainFlowExitCodes::STATUS_OK) |
| 80 | { |
| 81 | safe_logger (spdlog::level::err, "failed to apply default settings"); |
| 82 | delete socket; |
| 83 | socket = NULL; |
| 84 | return (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR; |
| 85 | } |
| 86 | // force default sampling rate - 250 |
| 87 | std::string sampl_rate = "~6"; |
| 88 | res = config_board (sampl_rate, tmp); |
| 89 | if (res != (int)BrainFlowExitCodes::STATUS_OK) |
| 90 | { |
| 91 | safe_logger (spdlog::level::err, "failed to apply default sampling rate"); |
| 92 | delete socket; |
| 93 | socket = NULL; |
| 94 | return (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR; |
| 95 | } |
| 96 | initialized = true; |
| 97 | return (int)BrainFlowExitCodes::STATUS_OK; |
| 98 | } |
| 99 | |
| 100 | int Galea::config_board (std::string conf, std::string &response) |
nothing calls this directly
no test coverage detected