diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 57467682..7f23f2be 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -6,9 +6,6 @@ // 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"], - // "runArgs": [ - // "--network=host" - // ], // Enable network mode host if on Linux and testing airdrop connectivity // "appPort": [ "45906:45906/udp", "45907:45907/udp" ], // port forward airdrop ports for local testing @@ -16,6 +13,8 @@ // "--network=host" // ], + "extensions.verifySignature": false, + "customizations": { "vscode": { "settings": { diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 578a5bb4..c94dffab 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -2,8 +2,12 @@ "configurations": [ { "name": "CMake", - "compileCommands": "${workspaceFolder}/build/compile_commands.json" + "compileCommands": "${workspaceFolder}/build/compile_commands.json", + "includePath": [ + "${workspaceFolder}/include" + ], + "cppStandard": "c++20" } ], "version": 4 -} +} \ No newline at end of file diff --git a/README.md b/README.md index 6d333692..bca9b76d 100644 --- a/README.md +++ b/README.md @@ -242,3 +242,13 @@ int x = 0; // NOLINT ### Formatting No formatter has been added yet. Formatting will be enforced once one is set up. + +## Jetson Setup + +### Network is Unreachable + +If you are having problems sending UDP broadcast packets from the jetson, ensure that the default gateway ip is set correctly. You can use the following command to do this: + +``` +route add default gw 192.168.1.1 +``` \ No newline at end of file diff --git a/configs/dev-config.json b/configs/dev-config.json index b33ec15b..88555931 100644 --- a/configs/dev-config.json +++ b/configs/dev-config.json @@ -4,7 +4,7 @@ }, "network": { "mavlink": { - "connect": "tcp://172.17.0.1:5760" + "connect": "tcp://127.0.0.1:14552" }, "gcs": { "port": 5010 diff --git a/docker/Dockerfile.sitl b/docker/Dockerfile.sitl new file mode 100644 index 00000000..d572cccb --- /dev/null +++ b/docker/Dockerfile.sitl @@ -0,0 +1,26 @@ +FROM amd64/ubuntu:22.04 + +# set up user +ARG USERNAME=tuas USER_UID=1000 USER_GID=1000 DEBIAN_FRONTEND=noninteractive +RUN groupadd -f --gid $USER_GID $USERNAME \ + && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME +RUN usermod -a -G dialout $USERNAME + +USER $USERNAME + +# Steps from https://ardupilot.org/dev/docs/building-setup-linux.html#building-setup-linux + +WORKDIR /home/$USERNAME + +RUN sudo apt-get update && sudo apt-get install git && sudo apt-get install git +RUN git clone --recurse-submodules https://github.com/ArduPilot/ardupilot.git + +WORKDIR ./ardupilot + +RUN Tools/environment_install/install-prereqs-ubuntu.sh -y +RUN source ~/.profile + +# wipe parameters +RUN timeout 3 ./sim_vehicle.py -w + +ENTRYPOINT ./sim_vehicle.py -v ArduPlane -f quadplane --console --map diff --git a/include/airdrop/packet.h b/include/airdrop/packet.h index 71f3ad10..f33c793a 100644 --- a/include/airdrop/packet.h +++ b/include/airdrop/packet.h @@ -4,7 +4,7 @@ #include /********************************************************************************************** - * LAST UPDATED: 2024/04/15 by Tyler Lentz + * LAST UPDATED: 2024/04/24 by Tyler Lentz * * This file defines the packet definitions for Airdrop communications. It is used in two * separate repositories: @@ -103,6 +103,8 @@ inline int validate_packet_as(enum ad_packet_hdr hdr, ad_packet_t packet) { case ACK_REVOKE: case ABOUT_TO_RELEASE: case HEARTBEAT: + case SEND_LATLNG: + case ACK_LATLNG: return (packet.data >= BOTTLE_A && packet.data <= BOTTLE_E); default: return 0; diff --git a/protos b/protos index b7d3e9b7..c5841043 160000 --- a/protos +++ b/protos @@ -1 +1 @@ -Subproject commit b7d3e9b74b38046602d4631072e6777b0b59b273 +Subproject commit c5841043ba805c065997232b5a6ae281873d9969 diff --git a/src/network/airdrop_client.cpp b/src/network/airdrop_client.cpp index 23127e21..26157160 100644 --- a/src/network/airdrop_client.cpp +++ b/src/network/airdrop_client.cpp @@ -181,6 +181,8 @@ void AirdropClient::_receiveWorker() { continue; } + VLOG_F(TRACE, "RECEIVED AIRDROP PACKET %d %d", (int)packet.hdr, (int)packet.data); + Lock lock(this->recv_mut); this->recv_queue.emplace(packet); } diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index 936e4c9a..64d914e4 100644 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -208,6 +208,22 @@ target_add_loguru(airdrop_pathing_2) target_include_directories(airdrop_pathing_2 PRIVATE ${ImageMagick_INCLUDE_DIRS}) target_link_libraries(airdrop_pathing_2 PRIVATE -Wl,--copy-dt-needed-entries ${ImageMagick_LIBRARIES}) +add_executable(airdrop_packets "airdrop_packets.cpp") +target_link_libraries(airdrop_packets PRIVATE obcpp_lib) +target_include_directories(airdrop_packets PRIVATE ${INCLUDE_DIRECTORY}) +target_add_protobuf(airdrop_packets) +target_add_torch(airdrop_packets) +target_add_torchvision(airdrop_packets) +target_add_json(airdrop_packets) +target_add_opencv(airdrop_packets) +target_add_httplib(airdrop_packets) +target_add_mavsdk(airdrop_packets) +target_add_matplot(airdrop_packets) +target_add_loguru(airdrop_packets) + +target_include_directories(airdrop_packets PRIVATE ${ImageMagick_INCLUDE_DIRS}) +target_link_libraries(airdrop_packets PRIVATE -Wl,--copy-dt-needed-entries ${ImageMagick_LIBRARIES}) + # airdrop_sockets # add_executable(airdrop_sockets src/network/airdrop_sockets.c tests/integration/airdrop_sockets.c) # target_include_directories(airdrop_sockets PRIVATE ${INCLUDE_DIRECTORY}) diff --git a/tests/integration/airdrop_packets.cpp b/tests/integration/airdrop_packets.cpp new file mode 100644 index 00000000..a114af20 --- /dev/null +++ b/tests/integration/airdrop_packets.cpp @@ -0,0 +1,59 @@ +#include +#include + +extern "C" { + #include "airdrop/packet.h" + #include "network/airdrop_sockets.h" +} + +#include "network/airdrop_client.hpp" +#include "utilities/logging.hpp" + +using namespace std::chrono_literals; + +int main(int argc, char** argv) { + initLogging("/workspaces/obcpp/logs", true, argc, argv); + + ad_socket_result_t result = make_ad_socket(AD_OBC_PORT, AD_PAYLOAD_PORT); + + if (result.is_err) { + std::cerr << "SOCKET ERROR: " << result.data.err << std::endl; + std::exit(1); + } + + AirdropClient airdrop(result.data.res); + airdrop.send(ad_latlng_packet_t {.hdr=SEND_LATLNG, .bottle=BOTTLE_A, .lat=32.12345, .lng=76.98765}); + std::this_thread::sleep_for(5s); + LOG_F(INFO, "Checking for ack latlng..."); + while (true) { + auto packet = airdrop.receive(); + if (!packet) { + break; + } + LOG_F(INFO, "test %d %d", static_cast(packet->data), static_cast(packet->hdr)); + } + LOG_F(INFO, "Done with checking for ack latlng"); + airdrop.send(ad_packet_t {.hdr=SIGNAL, .data=BOTTLE_A}); + std::this_thread::sleep_for(1s); + while (true) { + auto packet = airdrop.receive(); + if (!packet) { + break; + } + LOG_F(INFO, "test2 %d %d", static_cast(packet->data), static_cast(packet->hdr)); + } + airdrop.send(ad_packet_t {.hdr=REVOKE, .data=BOTTLE_A}); + std::this_thread::sleep_for(1s); + while (true) { + auto packet = airdrop.receive(); + if (!packet) { + break; + } + LOG_F(INFO, "test2 %d %d", static_cast(packet->data), static_cast(packet->hdr)); + } + + while (true) { + std::cout << "stop\n"; + std::this_thread::sleep_for(1s); + } +} \ No newline at end of file