diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2f83d5b7..6a0cf67d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,12 +1,17 @@ // See this page for reference of options: https://containers.dev/implementors/json_reference { "name": "Existing Dockerfile", - "image": "ghcr.io/tritonuas/obcpp:x86", + "image": "ghcr.io/tritonuas/obcpp:main", // enable when need to connect over USB to pixhawk // also: need to run obcpp with sudo or add tuas user to dialout group with // `sudo usermod -aG dialout tuas && newgrp && bash` // "runArgs": ["--device=/dev/ttyACM0"], + "appPort": [ "45906:45906/udp", "45907:45907/udp" ], // port forward airdrop ports for local testing + "runArgs": [ + "--network=host" + ], + "customizations": { "vscode": { "settings": { diff --git a/include/airdrop/packet.h b/include/airdrop/packet.h index ae7ac18f..0a795b36 100644 --- a/include/airdrop/packet.h +++ b/include/airdrop/packet.h @@ -52,6 +52,7 @@ enum ad_packet_hdr { // Handshake to establish connection SET_MODE = 1, ACK_MODE = 2, + RESET_MODE = 3, // TODO: // Direct Drop DROP_NOW = 100, @@ -91,7 +92,6 @@ inline int validate_packet_as(enum ad_packet_hdr hdr, ad_packet_t packet) { } switch (packet.hdr) { - case HEARTBEAT: case ACK_MODE: return 1; case SET_MODE: @@ -102,6 +102,7 @@ inline int validate_packet_as(enum ad_packet_hdr hdr, ad_packet_t packet) { case REVOKE: case ACK_REVOKE: case ABOUT_TO_RELEASE: + case HEARTBEAT: return (packet.data >= BOTTLE_A && packet.data <= BOTTLE_E); default: return 0; diff --git a/src/network/airdrop_client.cpp b/src/network/airdrop_client.cpp index fcb4d385..23127e21 100644 --- a/src/network/airdrop_client.cpp +++ b/src/network/airdrop_client.cpp @@ -55,6 +55,8 @@ void AirdropClient::_establishConnection() { LOG_F(INFO, "Payload connection established in %s mode", (this->mode == DIRECT_DROP) ? "Direct" : "Indirect"); + send_ad_packet(this->socket, make_ad_packet(ad_packet_hdr::ACK_MODE, *this->mode)); + this->worker_future = std::async(std::launch::async, &AirdropClient::_receiveWorker, this); } @@ -173,6 +175,12 @@ void AirdropClient::_receiveWorker() { continue; // heartbeat, so we should not put it in the queue } + if (packet.hdr == SET_MODE) { + send_ad_packet(this->socket, make_ad_packet(ad_packet_hdr::ACK_MODE, *this->mode)); + LOG_F(INFO, "Received extra SET_MODE, reacking"); + continue; + } + Lock lock(this->recv_mut); this->recv_queue.emplace(packet); } @@ -188,5 +196,7 @@ bool AirdropClient::_parseHeartbeats(ad_packet_t packet) { // subtract 1 to get the index into the lastHeartbeat array. this->last_heartbeat[packet.data - 1] = getUnixTime_ms(); + LOG_F(INFO, "Packet heartbeat from %d", packet.data); + return true; } diff --git a/src/ticks/mission_prep.cpp b/src/ticks/mission_prep.cpp index 08e2ed73..ebaf7629 100644 --- a/src/ticks/mission_prep.cpp +++ b/src/ticks/mission_prep.cpp @@ -15,7 +15,13 @@ std::chrono::milliseconds MissionPrepTick::getWait() const { return MISSION_PREP_TICK_WAIT; } +using namespace std::chrono_literals; + Tick* MissionPrepTick::tick() { + if (this->state->getAirdrop() != nullptr) { + LOG_F(INFO, "%ld", this->state->getAirdrop()->getLostConnections(1s).size()); + } + if (this->state->config.getCachedMission().has_value()) { LOG_F(INFO, "Valid mission configuration detected"); return new PathGenTick(this->state);