| 425 | } |
| 426 | |
| 427 | MicrohardLink::MicrohardLink(OHDProfile profile) : m_profile(profile) { |
| 428 | wait_for_microhard_module(m_profile.is_air); |
| 429 | |
| 430 | if (m_profile.is_air) { |
| 431 | m_video_tx = std::make_unique<openhd::UDPForwarder>( |
| 432 | DEVICE_IP_GND, MICROHARD_UDP_PORT_VIDEO_AIR_TX); |
| 433 | auto cb_telemetry_rx = [this](const uint8_t* data, std::size_t data_len) { |
| 434 | auto shared = |
| 435 | std::make_shared<std::vector<uint8_t>>(data, data + data_len); |
| 436 | on_receive_telemetry_data(shared); |
| 437 | }; |
| 438 | m_telemetry_tx_rx = std::make_unique<openhd::UDPReceiver>( |
| 439 | DEVICE_IP_AIR, MICROHARD_UDP_PORT_TELEMETRY_AIR_TX, cb_telemetry_rx); |
| 440 | } else { |
| 441 | auto cb_video_rx = [this](const uint8_t* payload, std::size_t payloadSize) { |
| 442 | on_receive_video_data(0, payload, payloadSize); |
| 443 | }; |
| 444 | m_video_rx = std::make_unique<openhd::UDPReceiver>( |
| 445 | DEVICE_IP_GND, MICROHARD_UDP_PORT_VIDEO_AIR_TX, cb_video_rx); |
| 446 | |
| 447 | auto cb_telemetry_rx = [this](const uint8_t* data, std::size_t data_len) { |
| 448 | auto shared = |
| 449 | std::make_shared<std::vector<uint8_t>>(data, data + data_len); |
| 450 | on_receive_telemetry_data(shared); |
| 451 | }; |
| 452 | m_telemetry_tx_rx = std::make_unique<openhd::UDPReceiver>( |
| 453 | DEVICE_IP_GND, MICROHARD_UDP_PORT_TELEMETRY_AIR_TX, cb_telemetry_rx); |
| 454 | } |
| 455 | |
| 456 | if (m_telemetry_tx_rx) { |
| 457 | m_telemetry_tx_rx->runInBackground(); |
| 458 | } |
| 459 | |
| 460 | if (m_video_rx) { |
| 461 | m_video_rx->runInBackground(); |
| 462 | } |
| 463 | |
| 464 | // Start monitoring gateway signal strength |
| 465 | std::thread monitor_thread(monitor_gateway_signal_strength, get_gateway_ip()); |
| 466 | monitor_thread.detach(); // Run in the background |
| 467 | |
| 468 | // Start the second communication thread |
| 469 | std::thread second_thread(communicate_with_device_slow, get_gateway_ip(), |
| 470 | command2); |
| 471 | second_thread.detach(); // Run in the background |
| 472 | } |
| 473 | |
| 474 | void MicrohardLink::transmit_telemetry_data(OHDLink::TelemetryTxPacket packet) { |
| 475 | const auto destination_ip = m_profile.is_air ? DEVICE_IP_GND : DEVICE_IP_AIR; |
nothing calls this directly
no test coverage detected