move trace data config to json
parent
fd2ead1373
commit
86a25bcaeb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
namespace nsUtils
|
||||
{
|
||||
template <typename T>
|
||||
bool IsWithinTol(T Offset, T Tol)
|
||||
{
|
||||
if (Offset > Tol || Offset < -Tol)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void getValue(const nlohmann::json& j, const std::string& fieldname, T& value)
|
||||
{
|
||||
if (j.contains(fieldname))
|
||||
{
|
||||
j.at(fieldname).get_to(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
// thirdparty
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
// project
|
||||
#include "GeneralUtils.h"
|
||||
|
||||
namespace nsKeyValue
|
||||
{
|
||||
using stKeyValue = struct _stKeyValue
|
||||
{
|
||||
std::string Name;
|
||||
double Value{ 0.0 };
|
||||
};
|
||||
|
||||
using stKeyValueBool = struct _stKeyValueBool
|
||||
{
|
||||
std::string Name;
|
||||
bool Value{};
|
||||
};
|
||||
};
|
||||
|
||||
namespace nsKeyValue
|
||||
{
|
||||
using namespace nlohmann;
|
||||
using namespace nsUtils;
|
||||
|
||||
void from_json(const json& j, stKeyValue& x);
|
||||
void to_json(json& j, const stKeyValue& x);
|
||||
|
||||
void from_json(const json& j, stKeyValueBool& x);
|
||||
void to_json(json& j, const stKeyValueBool& x);
|
||||
|
||||
inline void from_json(const json& j, stKeyValue& x)
|
||||
{
|
||||
getValue(j, "Name", x.Name);
|
||||
getValue(j, "Value", x.Value);
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const stKeyValue& x)
|
||||
{
|
||||
j = nlohmann::json{
|
||||
{ "Name", x.Name },
|
||||
{ "Value", x.Value }
|
||||
};
|
||||
}
|
||||
|
||||
inline void from_json(const json& j, stKeyValueBool& x)
|
||||
{
|
||||
getValue(j, "Name", x.Name);
|
||||
getValue(j, "Value", x.Value);
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const stKeyValueBool& x)
|
||||
{
|
||||
j = nlohmann::json{
|
||||
{ "Name", x.Name },
|
||||
{ "Value", x.Value }
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,95 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "KeyValueStruct.h"
|
||||
|
||||
#include "DllDefines.h"
|
||||
|
||||
namespace nsTrace
|
||||
{
|
||||
using stTrace = struct
|
||||
{
|
||||
std::vector<nsKeyValue::stKeyValueBool> Trace;
|
||||
std::vector<nsKeyValue::stKeyValueBool> TraceTiming;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace nsTrace
|
||||
{
|
||||
using namespace nlohmann;
|
||||
using namespace nsUtils;
|
||||
|
||||
void from_json(const json& j, stTrace& x);
|
||||
void to_json(json& j, const stTrace& x);
|
||||
|
||||
inline void from_json(const json& j, stTrace& x)
|
||||
{
|
||||
getValue(j, "Trace", x.Trace);
|
||||
getValue(j, "TraceTiming", x.TraceTiming);
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const stTrace& x)
|
||||
{
|
||||
j = nlohmann::json{
|
||||
{ "Trace", x.Trace },
|
||||
{ "TraceTiming", x.TraceTiming }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace nsTraceConfig
|
||||
{
|
||||
const std::string HARDWARE_TRACE_CONFIG = "d:/machine/config/trace/hardwareTrace.json";
|
||||
const std::string CLASS_TRACE_CONFIG = "d:/machine/config/trace/classTrace.json";
|
||||
const std::string MODULE_TRACE_CONFIG = "d:/machine/config/trace/hardwareTrace.json";
|
||||
}
|
||||
|
||||
class UTILITYDLL CTraceConfig
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @summary
|
||||
* @param strFilePath Name of Trace file. eg: d:/machine/config/trace/HardwareTrace.json, d:/machine/config/trace/ModuleTrace.json, d:/machine/config/trace/classTrace.json
|
||||
*/
|
||||
CTraceConfig(const std::string& strFilePath);
|
||||
virtual ~CTraceConfig();
|
||||
|
||||
/**
|
||||
* @brief Init Memory Parameters
|
||||
*/
|
||||
void InitParameters();
|
||||
|
||||
/**
|
||||
* @brief Get config object
|
||||
* @return nsTrace::stTrace object (read Only)
|
||||
*/
|
||||
const nsTrace::stTrace& Get();
|
||||
|
||||
/**
|
||||
* @brief Check Trace Enable
|
||||
* @param strName Name of Trace
|
||||
* @return true=enable trace
|
||||
*/
|
||||
bool IsTrace(const std::string& strName);
|
||||
|
||||
/**
|
||||
* @brief Check Trace Timing Enable
|
||||
* @param strName Name of Trace Data
|
||||
* @return true=enable trace data
|
||||
*/
|
||||
bool IsTraceTiming(const std::string& strName);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Load config from file
|
||||
* @param strFilePath File Path to load from
|
||||
*/
|
||||
void Load(const std::string& strFilePath);
|
||||
|
||||
std::string m_strFilePath;
|
||||
nsTrace::stTrace m_config;
|
||||
};
|
||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue