mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[sysid] Update JSON library usage (#5765)
This commit is contained in:
@@ -12,9 +12,9 @@
|
||||
#include <fmt/format.h>
|
||||
#include <units/angle.h>
|
||||
#include <units/math.h>
|
||||
#include <wpi/MemoryBuffer.h>
|
||||
#include <wpi/StringExtras.h>
|
||||
#include <wpi/StringMap.h>
|
||||
#include <wpi/raw_istream.h>
|
||||
|
||||
#include "sysid/Util.h"
|
||||
#include "sysid/analysis/FilteringUtils.h"
|
||||
@@ -451,13 +451,13 @@ AnalysisManager::AnalysisManager(std::string_view path, Settings& settings,
|
||||
{
|
||||
// Read JSON from the specified path
|
||||
std::error_code ec;
|
||||
wpi::raw_fd_istream is{path, ec};
|
||||
|
||||
if (ec) {
|
||||
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
|
||||
wpi::MemoryBuffer::GetFile(path, ec);
|
||||
if (fileBuffer == nullptr || ec) {
|
||||
throw FileReadingError(path);
|
||||
}
|
||||
|
||||
is >> m_json;
|
||||
m_json = wpi::json::parse(fileBuffer->begin(), fileBuffer->end());
|
||||
|
||||
WPI_INFO(m_logger, "Read {}", path);
|
||||
}
|
||||
@@ -469,13 +469,13 @@ AnalysisManager::AnalysisManager(std::string_view path, Settings& settings,
|
||||
|
||||
// Read JSON from the specified path
|
||||
std::error_code ec;
|
||||
wpi::raw_fd_istream is{newPath, ec};
|
||||
|
||||
if (ec) {
|
||||
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
|
||||
wpi::MemoryBuffer::GetFile(path, ec);
|
||||
if (fileBuffer == nullptr || ec) {
|
||||
throw FileReadingError(newPath);
|
||||
}
|
||||
|
||||
is >> m_json;
|
||||
m_json = wpi::json::parse(fileBuffer->begin(), fileBuffer->end());
|
||||
|
||||
WPI_INFO(m_logger, "Read {}", newPath);
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/Logger.h>
|
||||
#include <wpi/MemoryBuffer.h>
|
||||
#include <wpi/fmt/raw_ostream.h>
|
||||
#include <wpi/json.h>
|
||||
#include <wpi/raw_istream.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "sysid/Util.h"
|
||||
@@ -34,14 +34,13 @@ static constexpr size_t kRVelCol = 8;
|
||||
|
||||
static wpi::json GetJSON(std::string_view path, wpi::Logger& logger) {
|
||||
std::error_code ec;
|
||||
wpi::raw_fd_istream input{path, ec};
|
||||
|
||||
if (ec) {
|
||||
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
|
||||
wpi::MemoryBuffer::GetFile(path, ec);
|
||||
if (fileBuffer == nullptr || ec) {
|
||||
throw std::runtime_error(fmt::format("Unable to read: {}", path));
|
||||
}
|
||||
|
||||
wpi::json json;
|
||||
input >> json;
|
||||
wpi::json json = wpi::json::parse(fileBuffer->begin(), fileBuffer->end());
|
||||
WPI_INFO(logger, "Read frc-characterization JSON from {}", path);
|
||||
return json;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user