From 49fe0eec8f17698fc5f86d0abe01777af1fb2b23 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Fri, 14 Apr 2017 13:24:07 +0200 Subject: Change directory architecture to use 2 separated projects. Each projects, binder and generator, has to be compiled separatly. CAN-binder will host high and low level binding CAN-config-generator only the generator used for low level binding. build.sh script just launch both build in their respective dir. Change-Id: Ic77932660fcca507b23a631d4e4e790f608880ae Signed-off-by: Romain Forlot --- CAN-config-generator/src/openxc/message_set.cpp | 145 ++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100755 CAN-config-generator/src/openxc/message_set.cpp (limited to 'CAN-config-generator/src/openxc/message_set.cpp') diff --git a/CAN-config-generator/src/openxc/message_set.cpp b/CAN-config-generator/src/openxc/message_set.cpp new file mode 100755 index 00000000..c47c45f8 --- /dev/null +++ b/CAN-config-generator/src/openxc/message_set.cpp @@ -0,0 +1,145 @@ +#include +#include "message_set.hpp" + +namespace openxc +{ + message_set::message_set() + : name_{""} + , bit_numbering_inverted_{false} + , max_message_frequency_{0} + , raw_can_mode_{can_bus_mode::off} + , parents_{} + , initializers_{} + , loopers_{} + , buses_{} + , messages_{} + , diagnostic_messages_{} + , mappings_{} + , extra_sources_{} + , commands_{} + { + } + + std::string message_set::name() const + { + return name_; + } + + bool message_set::bit_numbering_inverted() const + { + return bit_numbering_inverted_; + } + + float message_set::max_message_frequency() const + { + return max_message_frequency_; + } + + can_bus_mode message_set::raw_can_mode() const + { + return raw_can_mode_; + } + + const std::vector& message_set::parents() const + { + return parents_; + } + + const std::vector& message_set::initializers() const + { + return initializers_; + } + + const std::vector& message_set::loopers() const + { + return loopers_; + } + + const std::map& message_set::buses() const + { + return buses_; + } + + const std::vector& message_set::messages() const + { + return messages_; + } + + const std::vector& message_set::diagnostic_messages() const + { + return diagnostic_messages_; + } + + const std::vector& message_set::mappings() const + { + return mappings_; + } + + const std::vector& message_set::extra_sources() const + { + return extra_sources_; + } + + const std::vector& message_set::commands() const + { + return commands_; + } + + void message_set::from_json(const nlohmann::json& j) + { + name_ = j["name"].get(); + bit_numbering_inverted_ = j.count("bit_numbering_inverted") ? j["bit_numbering_inverted"].get() : false; // TODO: should be true by default if database-backed. + max_message_frequency_ = j.count("max_message_frequency") ? j["max_message_frequency"].get() : 0; + raw_can_mode_ = j.count("raw_can_mode") ? j["raw_can_mode"].get() : can_bus_mode::off; + parents_ = j.count("parents") ? j["parents"].get>() : std::vector(); + initializers_ = j.count("initializers") ? j["initializers"].get>() : std::vector(); + loopers_ = j.count("loopers") ? j["loopers"].get>() : std::vector(); + buses_ = j.count("buses") ? j["buses"].get>() : std::map(); + //messages_ = j.count("messages") ? j["messages"].get>() : std::map(); + diagnostic_messages_ = j.count("diagnostic_messages") ? j["diagnostic_messages"].get>() : std::vector(); + mappings_ = j.count("mappings") ? j["mappings"].get>() : std::vector(); + extra_sources_ = j.count("extra_sources") ? j["extra_sources"].get>() : std::vector(); + commands_ = j.count("commands") ? j["commands"].get>() : std::vector(); + + + if (j.count("messages")) + { + std::map messages = j["messages"]; + for(const std::map::value_type& m : messages) + { + can_message cm = m.second.get(); + cm.id(m.first); + messages_.push_back(cm); + } + } + } + + nlohmann::json message_set::to_json() const + { + nlohmann::json j; + j["name_"] = name_; + j["bit_numbering_inverted"] = bit_numbering_inverted_; + j["max_message_frequency"] = max_message_frequency_; + j["raw_can_mode"] = raw_can_mode_; + j["parents"] = parents_; + j["initializers"] = initializers_; + j["loopers"] = loopers_; + j["buses"] = buses_; + j["messages"] = messages_; + j["diagnostic_messages"] = diagnostic_messages_; + j["mappings"] = mappings_; + j["extra_sources"] = extra_sources_; + j["commands"] = commands_; + return j; + } + + void to_json(nlohmann::json& j, const message_set& p) + { + j = p.to_json(); + } + + void from_json(const nlohmann::json& j, message_set& p) + { + p.from_json(j); + } +} -- cgit 1.2.3-korg