Skip to content

Commit

Permalink
connection fix from 4/15/24 testing w/ Cody
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler-Lentz committed Apr 16, 2024
1 parent 07d0910 commit 14a9932
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
7 changes: 6 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion include/airdrop/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/network/airdrop_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
6 changes: 6 additions & 0 deletions src/ticks/mission_prep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 14a9932

Please sign in to comment.