From 014ba2dd29eaadb4d61948ca417c25112f76ee0e Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Tue, 13 Jun 2017 17:20:05 +0200 Subject: Import CAN generator from low-level-can-service Also use the app-templates CMake helpers. Change-Id: I034e5efa9baa0f686a081f60df5c3588e4b3bd51 Signed-off-by: Romain Forlot --- src/openxc/diagnostic_message.cpp | 80 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 src/openxc/diagnostic_message.cpp (limited to 'src/openxc/diagnostic_message.cpp') diff --git a/src/openxc/diagnostic_message.cpp b/src/openxc/diagnostic_message.cpp new file mode 100755 index 0000000..3881abe --- /dev/null +++ b/src/openxc/diagnostic_message.cpp @@ -0,0 +1,80 @@ +#include "diagnostic_message.hpp" + +namespace openxc +{ + std::string diagnostic_message::bus() const + { + return bus_; + } + + std::uint32_t diagnostic_message::id() const + { + return id_; + } + + std::uint32_t diagnostic_message::mode() const + { + return mode_; + } + + float diagnostic_message::frequency() const + { + return frequency_; + } + + std::uint32_t diagnostic_message::pid() const + { + return pid_; + } + + std::string diagnostic_message::name() const + { + return name_; + } + + std::string diagnostic_message::decoder() const + { + return decoder_; + } + + std::string diagnostic_message::callback() const + { + return callback_; + } + + void diagnostic_message::from_json(const nlohmann::json& j) + { + bus_ = j.count("bus") ? j["bus"].get() : ""; + id_ = j.count("id") ? j["id"].get() : 0; + mode_ = j.count("mode") ? j["mode"].get() : 1; + frequency_ = j.count("frequency") ? j["frequency"].get() : 0; + pid_ = j.count("pid") ? j["pid"].get() : 0; + name_ = j.count("name") ? j["name"].get() : ""; + decoder_ = j.count("decoder") ? j["decoder"].get() : ""; + callback_ = j.count("callback") ? j["callback"].get() : ""; + } + + nlohmann::json diagnostic_message::to_json() const + { + nlohmann::json j; + j["bus"] = bus_; + j["id"] = id_; + j["mode"] = mode_; + j["frequency"] = frequency_; + j["pid"] = pid_; + j["name"] = name_; + j["decoder"] = decoder_; + j["callback"] = callback_; + return j; + } + + void to_json(nlohmann::json& j, const diagnostic_message& p) + { + j = p.to_json(); + } + + void from_json(const nlohmann::json& j, diagnostic_message& p) + { + p.from_json(j); + } +} -- cgit 1.2.3-korg