summaryrefslogtreecommitdiffstats
path: root/can-config-generator/src/openxc/can_bus.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-04-11 15:49:47 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-04-11 15:49:47 +0200
commita58d40b5ae336a54408201963b065ee049b43acd (patch)
tree9769e3d5b624e0238fe550df601e5382f259c52e /can-config-generator/src/openxc/can_bus.cpp
parent9e444ade872bc436cf12bc12d03c3a5d51ac0b9e (diff)
parentb7591d16c2686214d5d8dcc0739a233f15aee5db (diff)
Add 'can-config-generator/' from commit 'b7591d16c2686214d5d8dcc0739a233f15aee5db'
git-subtree-dir: can-config-generator git-subtree-mainline: 9e444ade872bc436cf12bc12d03c3a5d51ac0b9e git-subtree-split: b7591d16c2686214d5d8dcc0739a233f15aee5db
Diffstat (limited to 'can-config-generator/src/openxc/can_bus.cpp')
-rwxr-xr-xcan-config-generator/src/openxc/can_bus.cpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/can-config-generator/src/openxc/can_bus.cpp b/can-config-generator/src/openxc/can_bus.cpp
new file mode 100755
index 00000000..0a968a9e
--- /dev/null
+++ b/can-config-generator/src/openxc/can_bus.cpp
@@ -0,0 +1,89 @@
+#include "can_bus.hpp"
+
+namespace openxc
+{
+ std::uint32_t can_bus::controller() const
+ {
+ return controller_;
+ }
+
+ std::uint32_t can_bus::speed() const
+ {
+ return speed_;
+ }
+
+ can_bus_mode can_bus::raw_can_mode() const
+ {
+ return raw_can_mode_;
+ }
+
+ bool can_bus::raw_writable() const
+ {
+ return raw_writable_;
+ }
+
+ float can_bus::max_message_frequency() const
+ {
+ return max_message_frequency_;
+ }
+
+ bool can_bus::force_send_changed() const
+ {
+ return force_send_changed_;
+ }
+
+ void can_bus::from_json(const nlohmann::json& j)
+ {
+ controller_ = j.count("controller") ? j["controller"].get<std::uint32_t>() : 1;
+ speed_ = j.count("speed") ? j["speed"].get<std::uint32_t>() : 0;
+ raw_can_mode_ = j.count("raw_can_mode") ? j["raw_can_mode"].get<can_bus_mode>() : can_bus_mode::off;
+ raw_writable_ = j.count("raw_writable") ? j["raw_writable"].get<bool>() : false;
+ max_message_frequency_ = j.count("max_message_frequency") ? j["max_message_frequency"].get<float>() : 0;
+ force_send_changed_ = j.count("force_send_changed") ? j["force_send_changed"].get<bool>() : false;
+ }
+
+ nlohmann::json can_bus::to_json() const
+ {
+ nlohmann::json j;
+ j["controller"] = controller_;
+ j["speed"] = speed_;
+ j["raw_can_mode"] = raw_can_mode_;
+ j["raw_writable"] = raw_writable_;
+ j["max_message_frequency"] = max_message_frequency_;
+ j["force_send_changed"] = force_send_changed_;
+ return j;
+ }
+
+ void to_json(nlohmann::json& j, const can_bus& p)
+ {
+ j = p.to_json();
+ }
+
+ void from_json(const nlohmann::json& j, can_bus& p)
+ {
+ p.from_json(j);
+ }
+
+ void to_json(nlohmann::json& j, const can_bus_mode& p)
+ {
+ switch (p)
+ {
+ case can_bus_mode::off:
+ j = std::string("off");
+ break;
+ case can_bus_mode::filtered:
+ j = std::string("filtered");
+ break;
+ case can_bus_mode::unfiltered:
+ j = std::string("unfiltered");
+ break;
+ }
+ }
+
+ void from_json(const nlohmann::json& j, can_bus_mode& p)
+ {
+ if (j.get<std::string>() == "off") p = can_bus_mode::off;
+ else if (j.get<std::string>() == "filtered") p = can_bus_mode::filtered;
+ else p = can_bus_mode::unfiltered;
+ }
+}