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

Method config_board

src/board_controller/openbci/galea.cpp:100–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100int Galea::config_board (std::string conf, std::string &response)
101{
102 if (socket == NULL)
103 {
104 safe_logger (spdlog::level::err, "You need to call prepare_session before config_board");
105 return (int)BrainFlowExitCodes::BOARD_NOT_CREATED_ERROR;
106 }
107 // special handling for some commands
108 if (conf == "calc_time")
109 {
110 if (is_streaming)
111 {
112 safe_logger (spdlog::level::err, "can not calc delay during the streaming.");
113 return (int)BrainFlowExitCodes::BOARD_NOT_CREATED_ERROR;
114 }
115 int res = calc_time (response);
116 return res;
117 }
118
119 if (conf == "get_gains")
120 {
121 response = gain_tracker.get_gains_string ();
122 safe_logger (spdlog::level::info, "gains for all channels: {}", response);
123 return (int)BrainFlowExitCodes::STATUS_OK;
124 }
125
126 if (gain_tracker.apply_config (conf) == (int)OpenBCICommandTypes::INVALID_COMMAND)
127 {
128 safe_logger (spdlog::level::warn, "invalid command: {}", conf.c_str ());
129 return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR;
130 }
131
132 const char *config = conf.c_str ();
133 safe_logger (spdlog::level::debug, "Trying to config Galea with {}", config);
134 int len = (int)strlen (config);
135 int res = socket->send (config, len);
136 if (len != res)
137 {
138 gain_tracker.revert_config ();
139 if (res == -1)
140 {
141#ifdef _WIN32
142 safe_logger (spdlog::level::err, "WSAGetLastError is {}", WSAGetLastError ());
143#else
144 safe_logger (spdlog::level::err, "errno {} message {}", errno, strerror (errno));
145#endif
146 }
147 safe_logger (spdlog::level::err, "Failed to config a board");
148 return (int)BrainFlowExitCodes::BOARD_WRITE_ERROR;
149 }
150
151 if (!is_streaming)
152 {
153 char b[Galea::max_transaction_size];
154 res = Galea::max_transaction_size;
155 int max_attempt = 25; // to dont get to infinite loop
156 int current_attempt = 0;
157 while ((res >= 0) && (res % Galea::package_size == 0))

Callers

nothing calls this directly

Calls 6

get_gains_stringMethod · 0.80
revert_configMethod · 0.80
apply_configMethod · 0.45
sendMethod · 0.45
recvMethod · 0.45

Tested by

no test coverage detected