Skip to content

Commit

Permalink
Manual DROP_NOW GCS Route (#164)
Browse files Browse the repository at this point in the history
* add route to send manual DROP_NOW airdrop signal

* fix lint
  • Loading branch information
Tyler-Lentz authored Apr 25, 2024
1 parent 1e1f9f3 commit 146fabc
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"name": "CMake",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"includePath": [
"${workspaceFolder}/include"
"${workspaceFolder}/include",
"${workspaceFolder}/build/gen_protos/"
],
"cppStandard": "c++20"
}
Expand Down
9 changes: 9 additions & 0 deletions include/network/gcs_routes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ticks/tick.hpp"
#include "ticks/path_gen.hpp"


/*
* GET /connection
* ---
Expand Down Expand Up @@ -185,4 +186,12 @@ DEF_GCS_HANDLE(Get, camera, config);
*/
DEF_GCS_HANDLE(Post, camera, config);

/**
* POST /dodropnow
* ---
* Tells the OBC to do a drop now, for the given bottle
* Expects the body to be a BottleSwap proto message in json format
*/
DEF_GCS_HANDLE(Post, dodropnow);

#endif // INCLUDE_NETWORK_GCS_ROUTES_HPP_
2 changes: 2 additions & 0 deletions src/network/gcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,6 @@ void GCSServer::_bindHandlers() {
BIND_HANDLER(Get, camera, capture);
BIND_HANDLER(Get, camera, config);
BIND_HANDLER(Post, camera, config);

BIND_HANDLER(Post, dodropnow);
}
37 changes: 36 additions & 1 deletion src/network/gcs_routes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "core/mission_state.hpp"
#include "protos/obc.pb.h"
#include "utilities/serialize.hpp"
#include "utilities/http.hpp"
#include "utilities/logging.hpp"
#include "utilities/http.hpp"
#include "network/gcs_macros.hpp"
#include "ticks/tick.hpp"
#include "ticks/path_gen.hpp"
Expand All @@ -36,6 +36,7 @@ using namespace std::chrono_literals; // NOLINT
* the LOG_RESPONSE macro will handle it for you.
*/


DEF_GCS_HANDLE(Get, connections) {
LOG_REQUEST_TRACE("GET", "/connections");

Expand Down Expand Up @@ -212,3 +213,37 @@ DEF_GCS_HANDLE(Post, camera, config) {

LOG_RESPONSE(WARNING, "Not Implemented", NOT_IMPLEMENTED);
}

DEF_GCS_HANDLE(Post, dodropnow) {
LOG_REQUEST("POST", "/dodropnow");

BottleSwap bottle_proto;
google::protobuf::util::JsonStringToMessage(request.body, &bottle_proto);

ad_bottle bottle;
if (bottle_proto.index() == BottleDropIndex::A) {
bottle = ad_bottle::BOTTLE_A;
} else if (bottle_proto.index() == BottleDropIndex::B) {
bottle = ad_bottle::BOTTLE_B;
} else if (bottle_proto.index() == BottleDropIndex::C) {
bottle = ad_bottle::BOTTLE_C;
} else if (bottle_proto.index() == BottleDropIndex::D) {
bottle = ad_bottle::BOTTLE_D;
} else if (bottle_proto.index() == BottleDropIndex::E) {
bottle = ad_bottle::BOTTLE_E;
} else {
LOG_RESPONSE(ERROR, "Invalid bottle index", BAD_REQUEST);
return;
}

LOG_F(INFO, "Received signal to drop bottle %d", bottle);

if (state->getAirdrop() == nullptr) {
LOG_RESPONSE(ERROR, "Airdrop not connected", BAD_REQUEST);
return;
}

state->getAirdrop()->send(ad_packet_t { .hdr = DROP_NOW, .data = bottle });

LOG_RESPONSE(INFO, "Dropped bottle", OK);
}

0 comments on commit 146fabc

Please sign in to comment.