Skip to content

Message Routes

Projects Involved: OBC, GCS

Concepts: Post requests, Protobuf in OBC

Abstract:

The final step of this onboarding project is for you to write a route /message that handles POST requests from the GCS. Unlike a GET request (like /capture), which only attempts to fetch some information from the OBC, a POST request attempts to send some information to the OBC. In this case, that information is the matched target from the dropdown menu from the previous step. This information is serialized to json in the GCS, and then deserialized back to a proto message in the OBC. You will be using this information to make sure that the object matched is what is shown in the displayed image.

Goals:

  • Learn to write and route post requests
  • Learn to serialize and deserialize proto messages

Files Involved:

OBC

  • include/network/gcs_routes.hpp
  • src/network/gcs_routes.cpp
  • src/network/gcs.cpp

GCS

  • backend-go/internal/obc/client.go
  • backend-go/internal/server/server.go

Base Steps:

1. Uncomment the imports at the top of client.go and server.go, and uncomment the methods used for the message handler in both of the files.

2. Fix the appropriate handlers for POST /message in client.go and server.go on the GCS side.

  • For client.go, you should just read the TODO comments to see what needs to be implemented.
  • For server.go, try to figure out what the vague TODO message does.

3. Add the route handler on the OBC side.

  • To check if an "object" is correctly matched, you should just check if the detected object name from the route is the same as the image filename (this information should already be stored within the mission state image variable). No need to check for capitalization or different spellings or anything of that matter.

Tips:

1: Tip to perform the POST request in PostMessage (client.go) Refer to other GET requests in the same file. They have something similar that defines the response and error. You might just be able to change a single word from there...
2: Tip for reading the response body from the OBC PostMessage (client.go) Refer to other GET requests in the same file. You can just copy and paste the exact block of code.
3: Stuck on server.go? You need to call the client.go method here and define the response status and error. The solution is one line and can be found directly somewhere in other methods. Perhaps refer to your code for GET /capture?
4: Tips for deserializing json into proto You might find these to be useful.
auto parse_status = google::protobuf::util::JsonStringToMessage(received_message, &detected_proto);
const std::string detected_name = ODLCObjects_Name(detected_proto.object());