| 228 | } |
| 229 | |
| 230 | int UnicornBoard::call_open () |
| 231 | { |
| 232 | // find devices |
| 233 | int (*func_get_available) (UNICORN_DEVICE_SERIAL *, uint32_t *, BOOL) = |
| 234 | (int (*) (UNICORN_DEVICE_SERIAL *, uint32_t *, BOOL))dll_loader->get_address ( |
| 235 | "UNICORN_GetAvailableDevices"); |
| 236 | if (func_get_available == NULL) |
| 237 | { |
| 238 | safe_logger ( |
| 239 | spdlog::level::err, "failed to get function address for UNICORN_GetAvailableDevices"); |
| 240 | return (int)BrainFlowExitCodes::GENERAL_ERROR; |
| 241 | } |
| 242 | unsigned int available_device_count = 0; |
| 243 | int ec = func_get_available (NULL, &available_device_count, TRUE); |
| 244 | if (ec != UNICORN_ERROR_SUCCESS) |
| 245 | { |
| 246 | safe_logger (spdlog::level::err, "Error in UNICORN_GetAvailableDevices {}", ec); |
| 247 | return (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR; |
| 248 | } |
| 249 | if (available_device_count < 1) |
| 250 | { |
| 251 | safe_logger (spdlog::level::err, "Unicorn not found"); |
| 252 | return (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR; |
| 253 | } |
| 254 | UNICORN_DEVICE_SERIAL *available_devices = new UNICORN_DEVICE_SERIAL[available_device_count]; |
| 255 | ec = func_get_available (available_devices, &available_device_count, TRUE); |
| 256 | if (ec != UNICORN_ERROR_SUCCESS) |
| 257 | { |
| 258 | safe_logger (spdlog::level::err, "Error in UNICORN_GetAvailableDevices {}", ec); |
| 259 | delete[] available_devices; |
| 260 | return (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR; |
| 261 | } |
| 262 | |
| 263 | // search for device |
| 264 | unsigned int device_num = 0; |
| 265 | if (params.serial_number.empty ()) |
| 266 | { |
| 267 | safe_logger (spdlog::level::warn, |
| 268 | "Use device with id {}. To select another one provide id to serial_number field.", |
| 269 | available_devices[device_num]); |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | for (device_num = 0; device_num < available_device_count; device_num++) |
| 274 | { |
| 275 | if (strcmp (available_devices[device_num], params.serial_number.c_str ()) == 0) |
| 276 | { |
| 277 | break; |
| 278 | } |
| 279 | } |
| 280 | if (device_num == available_device_count) |
| 281 | { |
| 282 | safe_logger ( |
| 283 | spdlog::level::err, "device with id {} not found", params.serial_number.c_str ()); |
| 284 | delete[] available_devices; |
| 285 | return (int)BrainFlowExitCodes::GENERAL_ERROR; |
| 286 | } |
| 287 | } |
nothing calls this directly
no test coverage detected