| 575 | } |
| 576 | |
| 577 | int Emotibit::create_adv_connection () |
| 578 | { |
| 579 | int res = (int)BrainFlowExitCodes::STATUS_OK; |
| 580 | std::vector<std::string> broadcast_addresses; |
| 581 | if (!params.ip_address.empty ()) |
| 582 | { |
| 583 | broadcast_addresses.push_back (params.ip_address); |
| 584 | } |
| 585 | else |
| 586 | { |
| 587 | safe_logger (spdlog::level::warn, |
| 588 | "no ip_address provided, trying to discover network, it may take longer"); |
| 589 | broadcast_addresses = get_broadcast_addresses (); |
| 590 | } |
| 591 | |
| 592 | if (broadcast_addresses.empty ()) |
| 593 | { |
| 594 | safe_logger (spdlog::level::err, "no broadcast addresses found"); |
| 595 | res = (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR; |
| 596 | } |
| 597 | |
| 598 | for (std::string broadcast_address : broadcast_addresses) |
| 599 | { |
| 600 | BroadCastServer *advertise_socket = |
| 601 | new BroadCastServer (broadcast_address.c_str (), WIFI_ADVERTISING_PORT); |
| 602 | res = (int)BrainFlowExitCodes::STATUS_OK; |
| 603 | safe_logger ( |
| 604 | spdlog::level::info, "trying broadcast address: {}", broadcast_address.c_str ()); |
| 605 | if (res == (int)BrainFlowExitCodes::STATUS_OK) |
| 606 | { |
| 607 | int init_res = advertise_socket->init (); |
| 608 | if (init_res != (int)BroadCastServerReturnCodes::STATUS_OK) |
| 609 | { |
| 610 | safe_logger (spdlog::level::err, "failed to init broadcast server socket: {}", res); |
| 611 | res = (int)BrainFlowExitCodes::GENERAL_ERROR; |
| 612 | } |
| 613 | } |
| 614 | if (res == (int)BrainFlowExitCodes::STATUS_OK) |
| 615 | { |
| 616 | std::string package = create_package (HELLO_EMOTIBIT, 0, "", 0); |
| 617 | safe_logger (spdlog::level::info, "sending package: {}", package.c_str ()); |
| 618 | int bytes_send = advertise_socket->send (package.c_str (), (int)package.size ()); |
| 619 | if (bytes_send != (int)package.size ()) |
| 620 | { |
| 621 | safe_logger ( |
| 622 | spdlog::level::err, "failed to send adv package, res is {}", bytes_send); |
| 623 | res = (int)BrainFlowExitCodes::GENERAL_ERROR; |
| 624 | } |
| 625 | } |
| 626 | if (res == (int)BrainFlowExitCodes::STATUS_OK) |
| 627 | { |
| 628 | constexpr int max_size = 32768; |
| 629 | constexpr int max_ip_addr_size = 100; |
| 630 | char recv_data[max_size]; |
| 631 | char emotibit_ip[max_ip_addr_size]; |
| 632 | bool found = false; |
| 633 | double start_time = get_timestamp (); |
| 634 | for (int i = 0; (i < 100) && (!found); i++) |
nothing calls this directly
no test coverage detected