This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Restructure * Need to resolve gtest lib linking * Building and linking work * Old tests working * Add CLI arg parsing * CLI works * Add script to run db_util * Documentation * Fix linting * Make build flow easier to follow * Fix CMake include directories
- Loading branch information
Showing
16 changed files
with
936 additions
and
601 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
add_subdirectory(cmn_hdrs) | ||
add_subdirectory(protofiles) | ||
add_subdirectory(sailbot_db) | ||
|
||
# add directories as needed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
set(module sailbot_db) | ||
|
||
set(link_libs | ||
${PROTOBUF_LINK_LIBS} | ||
mongo::mongocxx_shared | ||
mongo::bsoncxx_shared | ||
) | ||
|
||
set(inc_dirs | ||
${PROTOBUF_INCLUDE_PATH} | ||
${LIBMONGOCXX_INCLUDE_DIRS} | ||
${LIBBSONCXX_INCLUDE_DIRS} | ||
) | ||
|
||
set(srcs | ||
${CMAKE_CURRENT_LIST_DIR}/src/sailbot_db.cpp | ||
${CMAKE_CURRENT_LIST_DIR}/src/util_db.cpp | ||
) | ||
|
||
# make sailbot_db library | ||
make_lib(${module} "${srcs}" "${link_libs}" "${inc_dirs}" "${compile_defs}") | ||
|
||
set(bin_srcs | ||
${srcs} | ||
${CMAKE_CURRENT_LIST_DIR}/src/main.cpp | ||
) | ||
|
||
# Make executable | ||
make_exe(${module} "${bin_srcs}" "${link_libs}" "${inc_dirs}" "${compile_defs}") | ||
|
||
# Create unit test | ||
set(test_srcs | ||
${srcs} | ||
${CMAKE_CURRENT_LIST_DIR}/test/test_sailbot_db.cpp | ||
) | ||
make_unit_test(${module} "${test_srcs}" "${link_libs}" "${inc_dirs}" "${compile_defs}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#pragma once | ||
|
||
#include <random> | ||
#include <span> | ||
|
||
#include "sailbot_db.h" | ||
#include "sensors.pb.h" | ||
#include "utils/utils.h" | ||
|
||
class UtilDB : public SailbotDB | ||
{ | ||
public: | ||
static constexpr int NUM_AIS_SHIPS = 15; // arbitrary number | ||
static constexpr int NUM_GENERIC_SENSORS = 5; // arbitrary number | ||
static constexpr int NUM_PATH_WAYPOINTS = 5; // arbitrary number | ||
|
||
/** | ||
* @brief Construct a UtilDB, which has debug utilities for SailbotDB | ||
* | ||
* @param db_name | ||
* @param mongodb_conn_str | ||
* @param rng | ||
*/ | ||
UtilDB(const std::string & db_name, const std::string & mongodb_conn_str, std::shared_ptr<std::mt19937> rng); | ||
|
||
/** | ||
* @brief Delete all documents in all collections | ||
*/ | ||
void cleanDB(); | ||
|
||
/** | ||
* @brief Generate random data for all sensors | ||
* | ||
* @return Sensors object | ||
*/ | ||
Polaris::Sensors genRandSensors(); | ||
|
||
/** | ||
* @return timestamp for the current time | ||
*/ | ||
static std::tm getTimestamp(); | ||
|
||
/** | ||
* @brief Generate random sensors and Iridium msg info | ||
* | ||
* @param tm Timestamp returned by getTimestamp() (with any modifications made to it) | ||
* @return std::pair<Sensors, SailbotDB::RcvdMsgInfo> | ||
*/ | ||
std::pair<Polaris::Sensors, SailbotDB::RcvdMsgInfo> genRandData(const std::tm & tm); | ||
|
||
/** | ||
* @brief Query the database and check that the sensor and message are correct | ||
* | ||
* @param expected_sensors | ||
* @param expected_msg_info | ||
*/ | ||
bool verifyDBWrite( | ||
std::span<Polaris::Sensors> expected_sensors, std::span<SailbotDB::RcvdMsgInfo> expected_msg_info); | ||
|
||
/** | ||
* @brief Dump and check all sensors and timestamps from the database | ||
* | ||
* @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::pair{Vector of dumped Sensors, Vector of dumped timestamps} | ||
*/ | ||
std::pair<std::vector<Polaris::Sensors>, std::vector<std::string>> dumpSensors( | ||
utils::FailTracker & tracker, size_t expected_num_docs = 1); | ||
|
||
private: | ||
std::shared_ptr<std::mt19937> rng_; // random number generator | ||
|
||
/** | ||
* @brief generate random GPS data | ||
* | ||
* @param gps_data GPS data to modify | ||
*/ | ||
void genRandGpsData(Polaris::Sensors::Gps & gps_data); | ||
|
||
/** | ||
* @brief generate random ais ships data | ||
* | ||
* @param ais_ship AIS ship data to modify | ||
*/ | ||
void genRandAisData(Polaris::Sensors::Ais & ais_ship); | ||
|
||
/** | ||
* @brief generate random generic sensor data | ||
* | ||
* @param generic_sensor Generic sensor data to modify | ||
*/ | ||
void genRandGenericSensorData(Polaris::Sensors::Generic & generic_sensor); | ||
|
||
/** | ||
* @brief generate random battery data | ||
* | ||
* @param battery battery data to modify | ||
*/ | ||
void genRandBatteryData(Polaris::Sensors::Battery & battery); | ||
|
||
/** | ||
* @brief generate random wind sensors data | ||
* | ||
* @param wind_data Wind sensor data to modify | ||
*/ | ||
void genRandWindData(Polaris::Sensors::Wind & wind_data); | ||
|
||
/** | ||
* @brief generate random path data | ||
* | ||
* @param path_data Path data to modify | ||
*/ | ||
void genRandPathData(Polaris::Sensors::Path & path_data); | ||
}; |
Oops, something went wrong.