merge with upstream
This commit is contained in:
parent
10c552e086
commit
42298ca801
@ -4,6 +4,8 @@
|
|||||||
/// \cond
|
/// \cond
|
||||||
// C headers
|
// C headers
|
||||||
// C++ headers
|
// C++ headers
|
||||||
|
#include <boost/property_tree/ptree.hpp>
|
||||||
|
#include <boost/property_tree/xml_parser.hpp>
|
||||||
// 3rd party headers
|
// 3rd party headers
|
||||||
#include <boost/property_tree/ptree.hpp>
|
#include <boost/property_tree/ptree.hpp>
|
||||||
#include <boost/property_tree/xml_parser.hpp>
|
#include <boost/property_tree/xml_parser.hpp>
|
||||||
|
@ -74,4 +74,4 @@ private:
|
|||||||
|
|
||||||
} // namespace utils
|
} // namespace utils
|
||||||
|
|
||||||
#endif // UTILS_MOTORMODELDATABASE_H
|
#endif // UTILS_MOTORMODELDATABASE_H
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
// C++ headers
|
// C++ headers
|
||||||
// 3rd party headers
|
// 3rd party headers
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
|
#include <optional>
|
||||||
/// \endcond
|
/// \endcond
|
||||||
|
|
||||||
// qtrocket headers
|
// qtrocket headers
|
||||||
@ -25,6 +26,58 @@ ThrustCurveAPI::~ThrustCurveAPI()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<ThrustCurve> ThrustCurveAPI::getThrustCurve(const std::string& id)
|
||||||
|
{
|
||||||
|
std::stringstream endpoint;
|
||||||
|
endpoint << hostname << "api/v1/download.json?motorId=" << id << "&data=samples";
|
||||||
|
std::vector<std::string> extraHeaders = {};
|
||||||
|
|
||||||
|
std::string res = curlConnection.get(endpoint.str(), extraHeaders);
|
||||||
|
model::MotorModel mm;
|
||||||
|
|
||||||
|
if(!res.empty())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Json::Reader reader;
|
||||||
|
Json::Value jsonResult;
|
||||||
|
reader.parse(res, jsonResult);
|
||||||
|
|
||||||
|
std::vector<std::pair<double, double>> samples;
|
||||||
|
for(Json::ValueConstIterator iter = jsonResult["results"].begin();
|
||||||
|
iter != jsonResult["results"].end();
|
||||||
|
++iter)
|
||||||
|
{
|
||||||
|
// if there are more than 1 items in the results list, we only want the RASP data
|
||||||
|
// Otherwise just take whatever is there
|
||||||
|
if(std::next(iter) != jsonResult["results"].end())
|
||||||
|
{
|
||||||
|
if( (*iter)["format"].asString() != "RASP")
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for(Json::ValueConstIterator samplesIter = (*iter)["samples"].begin();
|
||||||
|
samplesIter != (*iter)["samples"].end();
|
||||||
|
++samplesIter)
|
||||||
|
{
|
||||||
|
samples.push_back(std::make_pair((*samplesIter)["time"].asDouble(),
|
||||||
|
(*samplesIter)["thrust"].asDouble()));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ThrustCurve(samples);
|
||||||
|
}
|
||||||
|
catch(const std::exception& e)
|
||||||
|
{
|
||||||
|
std::string err("Unable to parse JSON from Thrustcurve motor data request. Error: ");
|
||||||
|
err += e.what();
|
||||||
|
|
||||||
|
Logger::getInstance()->error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
model::MotorModel ThrustCurveAPI::getMotorData(const std::string& motorId)
|
model::MotorModel ThrustCurveAPI::getMotorData(const std::string& motorId)
|
||||||
{
|
{
|
||||||
@ -227,6 +280,11 @@ std::vector<model::MotorModel> ThrustCurveAPI::searchMotors(const SearchCriteria
|
|||||||
mm.type = model::MotorModel::MotorType(model::MotorModel::MOTORTYPE::HYBRID);
|
mm.type = model::MotorModel::MotorType(model::MotorModel::MOTORTYPE::HYBRID);
|
||||||
|
|
||||||
motorModel.moveMetaData(std::move(mm));
|
motorModel.moveMetaData(std::move(mm));
|
||||||
|
auto tc = getThrustCurve(mm.motorIdTC);
|
||||||
|
if(tc)
|
||||||
|
{
|
||||||
|
motorModel.addThrustCurve(*tc);
|
||||||
|
}
|
||||||
retVal.push_back(motorModel);
|
retVal.push_back(motorModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
// C++ headers
|
// C++ headers
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
// 3rd party headers
|
// 3rd party headers
|
||||||
/// \endcond
|
/// \endcond
|
||||||
@ -91,6 +92,8 @@ private:
|
|||||||
const std::string hostname;
|
const std::string hostname;
|
||||||
CurlConnection curlConnection;
|
CurlConnection curlConnection;
|
||||||
|
|
||||||
|
std::optional<ThrustCurve> getThrustCurve(const std::string& id);
|
||||||
|
|
||||||
// no extra headers, but CurlConnection library wants them
|
// no extra headers, but CurlConnection library wants them
|
||||||
const std::vector<std::string> extraHeaders{};
|
const std::vector<std::string> extraHeaders{};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user