diff --git a/src/network_systems/lib/sailbot_db/inc/sailbot_db.h b/src/network_systems/lib/sailbot_db/inc/sailbot_db.h index 70c62004a..78ba4bc4d 100644 --- a/src/network_systems/lib/sailbot_db/inc/sailbot_db.h +++ b/src/network_systems/lib/sailbot_db/inc/sailbot_db.h @@ -93,6 +93,15 @@ class SailbotDB */ bool storeNewSensors(const Polaris::Sensors & sensors_pb, RcvdMsgInfo new_info); + /** + * @brief Write new sensor data to the database + * + * @param global_pb Protobuf GlobalPath object + * @param timestamp Timestamp for data + * + * @return true if successful + * @return false on failure + */ bool storeNewGlobalPath(const Polaris::GlobalPath & global_pb, const std::string & timestamp); /** @@ -108,6 +117,17 @@ class SailbotDB bool storeNewGlobalPath( const Polaris::GlobalPath & global_path_pb, const std::string & timestamp, mongocxx::client & client); + /** + * @brief Write iridium response data to the database + * + * @param response OK or FAILED + * @param error MO message error code + * @param message message given by rockblock server + * @param timestamp transmission time -- :: + + * @return true if successful + * @return false on failure + */ bool storeIridiumResponse( const std::string & response, const std::string & error, const std::string & message, const std::string & timestamp); @@ -117,6 +137,7 @@ class SailbotDB * * @param response OK or FAILED * @param error MO message error code + * @param message message given by rockblock server * @param timestamp transmission time -- :: * @param client mongocxx::client instance for the current thread * @@ -209,14 +230,4 @@ class SailbotDB */ bool storeWindSensors( const ProtoList & wind_pb, const std::string & timestamp, mongocxx::client & client); - - // /** - // * @brief Builds global path document by extracting waypoint information and adding it to document - // * - // * @param global_path_doc_arr bstream document builder array for global path - // * @param waypoints global path waypoints: , - // * - // */ - // auto buildGlobalPathDoc( - // auto global_path_doc_arr, const ProtoList& waypoints); }; diff --git a/src/network_systems/lib/sailbot_db/inc/util_db.h b/src/network_systems/lib/sailbot_db/inc/util_db.h index fe4ea4ed6..7234867b8 100644 --- a/src/network_systems/lib/sailbot_db/inc/util_db.h +++ b/src/network_systems/lib/sailbot_db/inc/util_db.h @@ -50,6 +50,12 @@ class UtilDB : public SailbotDB */ std::pair genRandData(const std::tm & tm); + /** + * @brief Generate random global path data + * + * @param tm Timestamp returned by getTimestamp() (with any modifications made to it) + * @return std::pair + */ std::pair genGlobalData(const std::tm & tm); /** @@ -71,10 +77,11 @@ class UtilDB : public SailbotDB std::span expected_globalpath, std::span expected_timestamp); /** - * @brief Query the database and check that the Iridium response, error code, and timestamp are correct + * @brief Query the database and check that the Iridium response, error code, message, and timestamp are correct * * @param expected_response * @param expected_error + * @param expected_message * @param expected_timestamp */ bool verifyDBWrite_IridiumResponse( @@ -106,7 +113,7 @@ class UtilDB : public SailbotDB * * @param tracker FailureTracker that gets if any unexpected results are dumped * @param expected_num_docs Expected number of documents. tracker is updated if there's a mismatch - * @return std::tuple{Vector of dumped responses, Vector of dumped error codes, Vector of dumped timestamps} + * @return std::tuple{Vector of dumped responses, Vector of dumped error codes, Vector of dumped messages, Vector of dumped timestamps} */ std::tuple, std::vector, std::vector, std::vector> dumpIridiumResponse(utils::FailTracker & tracker, size_t expected_num_docs = 1); @@ -156,5 +163,10 @@ class UtilDB : public SailbotDB */ void genRandPathData(Polaris::Sensors::Path & path_data); + /** + * @brief generate random global path data + * + * @param global_path_data Global path data to modify + */ void genGlobalPathData(Polaris::GlobalPath & global_path_data); }; diff --git a/src/network_systems/lib/sailbot_db/src/sailbot_db.cpp b/src/network_systems/lib/sailbot_db/src/sailbot_db.cpp index fb4a570a0..31f4a8244 100644 --- a/src/network_systems/lib/sailbot_db/src/sailbot_db.cpp +++ b/src/network_systems/lib/sailbot_db/src/sailbot_db.cpp @@ -202,7 +202,6 @@ bool SailbotDB::storeNewGlobalPath( global_path_doc_arr = global_path_doc_arr << bstream::open_document << "latitude" << waypoint.latitude() << "longitude" << waypoint.longitude() << bstream::close_document; } - // global_path_doc_arr = buildGlobalPathDoc(global_path_doc_arr, waypoints); DocVal global_path_doc = global_path_doc_arr << bstream::close_array << "timestamp" << timestamp << bstream::finalize; return static_cast(global_path_coll.insert_one(global_path_doc.view())); @@ -215,21 +214,9 @@ bool SailbotDB::storeIridiumResponse( mongocxx::database db = client[db_name_]; mongocxx::collection iridium_response_coll = db[COLLECTION_IRIDIUM_RESPONSE]; - // Print the contents of the collection before insertion - // std::cout << "Collection contents before insertion:\n"; - // for (auto doc : iridium_response_coll.find({})) { - // std::cout << bsoncxx::to_json(doc) << "\n"; - // } DocVal iridium_response_doc = bstream::document{} << "response" << response << "error" << error << "timestamp" << timestamp << "message" << message << bstream::finalize; - // Print the contents of the collection after insertion - // std::cout << "\nCollection contents after insertion:\n"; - // for (auto doc : iridium_response_coll.find({})) { - // std::cout << bsoncxx::to_json(doc) << "\n"; - // } - - // return static_cast(iridium_response_coll.insert_one(iridium_response_doc.view())); return static_cast(iridium_response_coll.insert_one(iridium_response_doc.view())); } diff --git a/src/network_systems/lib/sailbot_db/test/test_sailbot_db.cpp b/src/network_systems/lib/sailbot_db/test/test_sailbot_db.cpp index a68ac1639..e35733058 100644 --- a/src/network_systems/lib/sailbot_db/test/test_sailbot_db.cpp +++ b/src/network_systems/lib/sailbot_db/test/test_sailbot_db.cpp @@ -52,5 +52,3 @@ TEST_F(TestSailbotDB, TestStoreGlobalPath) EXPECT_TRUE(g_test_db.verifyDBWrite_GlobalPath(expected_global_path_data, expected_global_path_timestamp)); } - -//testing diff --git a/src/network_systems/projects/remote_transceiver/src/remote_transceiver.cpp b/src/network_systems/projects/remote_transceiver/src/remote_transceiver.cpp index 4ef0696bb..d1d2b8a9e 100644 --- a/src/network_systems/projects/remote_transceiver/src/remote_transceiver.cpp +++ b/src/network_systems/projects/remote_transceiver/src/remote_transceiver.cpp @@ -198,15 +198,12 @@ void HTTPServer::doPost() beast::ostream(res_.body()) << "Server does not support sensors POST requests of type: " << content_type; } } else if (req_.target() == remote_transceiver::targets::GLOBAL_PATH) { - // TODO(): Allow POST global path - std::shared_ptr self = shared_from_this(); std::string json_str = beast::buffers_to_string(req_.body().data()); //JSON Parsing std::stringstream ss(json_str); boost::property_tree::ptree json_tree; boost::property_tree::read_json(ss, json_tree); - std::string timestamp = json_tree.get("timestamp"); - std::cout << "timestamp: " << timestamp << std::endl; + std::string timestamp = json_tree.get("timestamp"); Polaris::GlobalPath global_path; int num_waypoints = 0; for (const auto & waypoint : json_tree.get_child("waypoints")) { @@ -216,7 +213,6 @@ void HTTPServer::doPost() global_waypoint->set_longitude(lon); global_waypoint->set_latitude(lat); num_waypoints++; - std::cout << "actual waypoint latlon: " << lat << " " << lon << std::endl; } global_path.set_num_waypoints(num_waypoints); std::string data; @@ -239,7 +235,6 @@ void HTTPServer::doPost() std::string readBuffer; curl = curl_easy_init(); - // Sample URL we are using: http://localhost:8100/?data=thisistestdata&ec=B&imei=300434065264590&username=myuser std::string EC = "B"; std::string IMEI = "300434065264590"; @@ -267,7 +262,6 @@ void HTTPServer::doPost() if (res != CURLE_OK) { std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl; } else { - std::cout << "Read Buffer: " << readBuffer << std::endl; std::stringstream ss(readBuffer); std::string response; @@ -278,10 +272,6 @@ void HTTPServer::doPost() std::getline(ss, error, ','); std::getline(ss, message, ','); - std::cout << "response: " << response << std::endl; - std::cout << "error: " << error << std::endl; - std::cout << "message: " << message << std::endl; - if (!self->db_.storeIridiumResponse(response, error, message, timestamp)) { //important std::cerr << "Error, failed to store data received at:\n" << timestamp << std::endl; } else { @@ -294,8 +284,6 @@ void HTTPServer::doPost() } curl_global_cleanup(); - // Create a post request to rockblock http pot request URL (how to send a post request to a url/endpoint) - } else { doNotFound(); } @@ -421,5 +409,3 @@ http::response http_client::post_response_body( return res; } - -//OK, 10, message diff --git a/src/network_systems/projects/remote_transceiver/test/test_remote_transceiver.cpp b/src/network_systems/projects/remote_transceiver/test/test_remote_transceiver.cpp index faf7a1e12..08a89a0fc 100644 --- a/src/network_systems/projects/remote_transceiver/test/test_remote_transceiver.cpp +++ b/src/network_systems/projects/remote_transceiver/test/test_remote_transceiver.cpp @@ -5,7 +5,7 @@ #include #include #include -#include //JSON parser +#include #include #include #include @@ -240,7 +240,6 @@ TEST_F(TestRemoteTransceiver, rockblockWebServerExample) std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl; // EXPECT_TRUE(false); } else { - std::cout << "Response data: " << readBuffer << std::endl; EXPECT_EQ("FAILED,11,No RockBLOCK with this IMEI found on your account", readBuffer); } @@ -261,24 +260,17 @@ TEST_F(TestRemoteTransceiver, TestPostGlobalPath) std::string rand_global_path_str; ASSERT_TRUE(rand_global_path.SerializeToString(&rand_global_path_str)); - std::cout << "rand_global_path: " << rand_global_path_str << std::endl; Polaris::GlobalPath test; test.ParseFromString(rand_global_path_str); - std::cout << "global path str: " << rand_global_path_str << std::endl; - // This query is comprised entirely of arbitrary values exccept for .data_ - //Configure for global path boost::property_tree::ptree global_path_json; boost::property_tree::ptree waypoints_arr; for (const auto & waypoint : rand_global_path.waypoints()) { - std::cout << "test waypoint lat: " << waypoint.latitude() << std::endl; - std::cout << "test waypoint long: " << waypoint.longitude() << std::endl; boost::property_tree::ptree waypoint_node; waypoint_node.put("latitude", waypoint.latitude()); waypoint_node.put("longitude", waypoint.longitude()); waypoints_arr.push_back(std::make_pair("", waypoint_node)); - std::cout << "waypoint arr size: " << waypoints_arr.size() << std::endl; } global_path_json.add_child("waypoints", waypoints_arr); @@ -309,7 +301,7 @@ TEST_F(TestRemoteTransceiver, TestPostGlobalPathMult) { SCOPED_TRACE("Seed: " + std::to_string(g_rand_seed)); // Print seed on any failure - constexpr int NUM_REQS = 3; // Keep this + constexpr int NUM_REQS = 3; // Keep this number under 60 to simplify timestamp logic std::array queries; std::array req_threads; std::array res_statuses; @@ -340,13 +332,10 @@ TEST_F(TestRemoteTransceiver, TestPostGlobalPathMult) boost::property_tree::ptree waypoints_arr; for (const auto & waypoint : rand_globalpaths.waypoints()) { - std::cout << "test waypoint lat: " << waypoint.latitude() << std::endl; - std::cout << "test waypoint long: " << waypoint.longitude() << std::endl; boost::property_tree::ptree waypoint_node; waypoint_node.put("latitude", waypoint.latitude()); waypoint_node.put("longitude", waypoint.longitude()); waypoints_arr.push_back(std::make_pair("", waypoint_node)); - std::cout << "waypoint arr size: " << waypoints_arr.size() << std::endl; } global_path_json.add_child("waypoints", waypoints_arr);