summaryrefslogtreecommitdiffstats
path: root/src/openxc
diff options
context:
space:
mode:
Diffstat (limited to 'src/openxc')
-rwxr-xr-xsrc/openxc/can_bus.cpp4
-rwxr-xr-xsrc/openxc/can_bus.hpp15
-rwxr-xr-xsrc/openxc/can_message.cpp41
-rwxr-xr-xsrc/openxc/can_message.hpp17
-rwxr-xr-xsrc/openxc/diagnostic_message.cpp4
-rwxr-xr-xsrc/openxc/diagnostic_message.hpp4
-rwxr-xr-xsrc/openxc/message_set.cpp38
-rwxr-xr-xsrc/openxc/message_set.hpp11
-rwxr-xr-xsrc/openxc/signal.cpp14
-rwxr-xr-xsrc/openxc/signal.hpp7
10 files changed, 95 insertions, 60 deletions
diff --git a/src/openxc/can_bus.cpp b/src/openxc/can_bus.cpp
index 545a6c5c..0a968a9e 100755
--- a/src/openxc/can_bus.cpp
+++ b/src/openxc/can_bus.cpp
@@ -22,7 +22,7 @@ namespace openxc
return raw_writable_;
}
- std::uint32_t can_bus::max_message_frequency() const
+ float can_bus::max_message_frequency() const
{
return max_message_frequency_;
}
@@ -38,7 +38,7 @@ namespace openxc
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<std::uint32_t>() : 0;
+ 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;
}
diff --git a/src/openxc/can_bus.hpp b/src/openxc/can_bus.hpp
index db8e0250..74e1273f 100755
--- a/src/openxc/can_bus.hpp
+++ b/src/openxc/can_bus.hpp
@@ -15,20 +15,19 @@ namespace openxc
class can_bus
{
private:
- std::uint32_t controller_;
- std::uint32_t speed_;
- can_bus_mode raw_can_mode_;
- bool raw_writable_;
- std::uint32_t max_message_frequency_;
- bool force_send_changed_;
+ std::uint32_t controller_;
+ std::uint32_t speed_;
+ can_bus_mode raw_can_mode_;
+ bool raw_writable_;
+ float max_message_frequency_;
+ bool force_send_changed_;
public:
-
std::uint32_t controller() const;
std::uint32_t speed() const;
can_bus_mode raw_can_mode() const;
bool raw_writable() const;
- std::uint32_t max_message_frequency() const;
+ float max_message_frequency() const;
bool force_send_changed() const;
void from_json(const nlohmann::json& j);
diff --git a/src/openxc/can_message.cpp b/src/openxc/can_message.cpp
index d42d1efa..fab5a85f 100755
--- a/src/openxc/can_message.cpp
+++ b/src/openxc/can_message.cpp
@@ -2,6 +2,16 @@
namespace openxc
{
+ std::string can_message::id() const
+ {
+ return id_;
+ }
+
+ void can_message::id(const std::string& id)
+ {
+ id_ = id;
+ }
+
std::string can_message::bus() const
{
return bus_;
@@ -12,7 +22,7 @@ namespace openxc
return bit_numbering_inverted_;
}
- const std::map<std::string, signal>& can_message::signals() const
+ const std::vector<signal>& can_message::signals() const
{
return signals_;
}
@@ -32,12 +42,12 @@ namespace openxc
return enabled_;
}
- std::uint32_t can_message::max_frequency() const
+ float can_message::max_frequency() const
{
return max_frequency_;
}
- std::uint32_t can_message::max_signal_frequency() const
+ float can_message::max_signal_frequency() const
{
return max_signal_frequency_;
}
@@ -56,14 +66,25 @@ namespace openxc
{
bus_ = j.count("bus") ? j["bus"].get<std::string>() : "";
bit_numbering_inverted_ = j.count("bit_numbering_inverted") ? j["bit_numbering_inverted"].get<bool>() : false;
- signals_= j.count("signals") ? j["signals"].get<std::map<std::string, signal>>() : std::map<std::string, signal>();
name_ = j.count("name") ? j["name"].get<std::string>() : "";
handlers_ = j.count("handlers") ? j["handlers"].get<std::vector<std::string>>() : std::vector<std::string>();
enabled_ = j.count("enabled") ? j["enabled"].get<bool>() : true;
- max_frequency_ = j.count("max_frequency") ? j["max_frequency"].get<std::uint32_t>() : 0;
- max_signal_frequency_ = j.count("max_signal_frequency") ? j["max_signal_frequency"].get<std::uint32_t>() : 0;
+ max_frequency_ = j.count("max_frequency") ? j["max_frequency"].get<float>() : 0;
+ max_signal_frequency_ = j.count("max_signal_frequency") ? j["max_signal_frequency"].get<float>() : 0;
force_send_changed_ = j.count("force_send_changed") ? j["force_send_changed"].get<bool>() : true;
force_send_changed_signals_ = j.count("force_send_changed_signals") ? j["force_send_changed_signals"].get<bool>() : false;
+
+ if(j.count("signals"))
+ {
+ std::map<std::string, nlohmann::json> signals = j["signals"];
+ for(const auto& s : signals)
+ {
+ signal sig = s.second.get<signal>();
+ sig.id(s.first);
+ signals_.push_back(sig);
+ }
+ }
+
}
std::uint32_t can_message::get_signals_count() const
@@ -91,9 +112,15 @@ namespace openxc
{
j = p.to_json();
}
-
+
void from_json(const nlohmann::json& j, can_message& p)
{
p.from_json(j);
}
+
+ void from_json(const nlohmann::json& j, can_message& p, const std::string& id)
+ {
+ p.from_json(j);
+ p.id(id);
+ }
}
diff --git a/src/openxc/can_message.hpp b/src/openxc/can_message.hpp
index 57bd23fd..3f7b0181 100755
--- a/src/openxc/can_message.hpp
+++ b/src/openxc/can_message.hpp
@@ -2,7 +2,6 @@
#include <string>
#include <vector>
-#include <map>
#include <json.hpp>
#include "signal.hpp"
@@ -12,26 +11,29 @@ namespace openxc
class can_message
{
private:
+ std::string id_;
std::string bus_;
bool bit_numbering_inverted_;
- std::map<std::string, signal> signals_;
+ std::vector<signal> signals_;
std::string name_;
std::vector<std::string> handlers_;
bool enabled_;
- std::uint32_t max_frequency_;
- std::uint32_t max_signal_frequency_;
+ float max_frequency_;
+ float max_signal_frequency_;
bool force_send_changed_;
bool force_send_changed_signals_;
public:
+ std::string id() const;
+ void id(const std::string& id);
std::string bus() const;
bool bit_numbering_inverted() const;
- const std::map<std::string, signal>& signals() const;
+ const std::vector<signal>& signals() const;
std::string name() const;
std::vector<std::string> handlers() const;
bool enabled() const;
- std::uint32_t max_frequency() const;
- std::uint32_t max_signal_frequency() const;
+ float max_frequency() const;
+ float max_signal_frequency() const;
bool force_send_changed() const;
bool force_send_changed_signals() const;
@@ -43,4 +45,5 @@ namespace openxc
void to_json(nlohmann::json& j, const can_message& p);
void from_json(const nlohmann::json& j, can_message& p);
+ void from_json(const nlohmann::json& j, can_message& p, const std::string& id);
}
diff --git a/src/openxc/diagnostic_message.cpp b/src/openxc/diagnostic_message.cpp
index 44b21c64..3881abef 100755
--- a/src/openxc/diagnostic_message.cpp
+++ b/src/openxc/diagnostic_message.cpp
@@ -17,7 +17,7 @@ namespace openxc
return mode_;
}
- std::uint32_t diagnostic_message::frequency() const
+ float diagnostic_message::frequency() const
{
return frequency_;
}
@@ -47,7 +47,7 @@ namespace openxc
bus_ = j.count("bus") ? j["bus"].get<std::string>() : "";
id_ = j.count("id") ? j["id"].get<std::uint32_t>() : 0;
mode_ = j.count("mode") ? j["mode"].get<std::uint32_t>() : 1;
- frequency_ = j.count("frequency") ? j["frequency"].get<std::uint32_t>() : 0;
+ frequency_ = j.count("frequency") ? j["frequency"].get<float>() : 0;
pid_ = j.count("pid") ? j["pid"].get<std::uint32_t>() : 0;
name_ = j.count("name") ? j["name"].get<std::string>() : "";
decoder_ = j.count("decoder") ? j["decoder"].get<std::string>() : "";
diff --git a/src/openxc/diagnostic_message.hpp b/src/openxc/diagnostic_message.hpp
index 33b41e61..1ceba1bd 100755
--- a/src/openxc/diagnostic_message.hpp
+++ b/src/openxc/diagnostic_message.hpp
@@ -11,7 +11,7 @@ namespace openxc
std::string bus_;
std::uint32_t id_;
std::uint32_t mode_;
- std::uint32_t frequency_;
+ float frequency_;
std::uint32_t pid_;
std::string name_;
std::string decoder_;
@@ -20,7 +20,7 @@ namespace openxc
std::string bus() const;
std::uint32_t id() const;
std::uint32_t mode() const;
- std::uint32_t frequency() const;
+ float frequency() const;
std::uint32_t pid() const;
std::string name() const;
std::string decoder() const;
diff --git a/src/openxc/message_set.cpp b/src/openxc/message_set.cpp
index 7f3d2fbb..c47c45f8 100755
--- a/src/openxc/message_set.cpp
+++ b/src/openxc/message_set.cpp
@@ -30,7 +30,7 @@ namespace openxc
return bit_numbering_inverted_;
}
- std::uint32_t message_set::max_message_frequency() const
+ float message_set::max_message_frequency() const
{
return max_message_frequency_;
}
@@ -60,7 +60,7 @@ namespace openxc
return buses_;
}
- const std::map<std::string, can_message>& message_set::messages() const
+ const std::vector<can_message>& message_set::messages() const
{
return messages_;
}
@@ -84,25 +84,6 @@ namespace openxc
{
return commands_;
}
-
- std::string message_set::to_initializer() const
- {
- std::uint32_t signal_count = 0;
- for(const auto& m : messages_)
- {
- signal_count += m.second.get_signals_count();
- }
-
- std::stringstream ss;
- ss << "{0, "
- << "\"" << name_ << "\", "
- << buses_.size() << ", "
- << messages_.size() << ", "
- << signal_count << ", "
- << commands_.size() << ", "
- << diagnostic_messages_.size() << "}";
- return ss.str();
- }
void message_set::from_json(const nlohmann::json& j)
{
@@ -114,14 +95,25 @@ namespace openxc
initializers_ = j.count("initializers") ? j["initializers"].get<std::vector<std::string>>() : std::vector<std::string>();
loopers_ = j.count("loopers") ? j["loopers"].get<std::vector<std::string>>() : std::vector<std::string>();
buses_ = j.count("buses") ? j["buses"].get<std::map<std::string, can_bus>>() : std::map<std::string, can_bus>();
- messages_ = j.count("messages") ? j["messages"].get<std::map<std::string, can_message>>() : std::map<std::string, can_message>();
+ //messages_ = j.count("messages") ? j["messages"].get<std::map<std::string, can_message>>() : std::map<std::string, can_message>();
diagnostic_messages_ = j.count("diagnostic_messages") ? j["diagnostic_messages"].get<std::vector<diagnostic_message>>() : std::vector<diagnostic_message>();
mappings_ = j.count("mappings") ? j["mappings"].get<std::vector<mapping>>() : std::vector<mapping>();
extra_sources_ = j.count("extra_sources") ? j["extra_sources"].get<std::vector<std::string>>() : std::vector<std::string>();
commands_ = j.count("commands") ? j["commands"].get<std::vector<command>>() : std::vector<command>();
+
+
+ if (j.count("messages"))
+ {
+ std::map<std::string, nlohmann::json> messages = j["messages"];
+ for(const std::map<std::string, nlohmann::json>::value_type& m : messages)
+ {
+ can_message cm = m.second.get<can_message>();
+ cm.id(m.first);
+ messages_.push_back(cm);
+ }
+ }
}
-
nlohmann::json message_set::to_json() const
{
nlohmann::json j;
diff --git a/src/openxc/message_set.hpp b/src/openxc/message_set.hpp
index 37b40fc4..935817ee 100755
--- a/src/openxc/message_set.hpp
+++ b/src/openxc/message_set.hpp
@@ -18,13 +18,14 @@ namespace openxc
private:
std::string name_;
bool bit_numbering_inverted_;
- std::uint32_t max_message_frequency_;
+ float max_message_frequency_;
can_bus_mode raw_can_mode_;
std::vector<std::string> parents_;
std::vector<std::string> initializers_;
std::vector<std::string> loopers_;
std::map<std::string, can_bus> buses_;
- std::map<std::string, can_message> messages_;
+ //std::map<std::string, can_message> messages_;
+ std::vector<can_message> messages_;
std::vector<diagnostic_message> diagnostic_messages_;
std::vector<mapping> mappings_;
std::vector<std::string> extra_sources_;
@@ -37,20 +38,18 @@ namespace openxc
std::string name() const;
bool bit_numbering_inverted() const;
- std::uint32_t max_message_frequency() const;
+ float max_message_frequency() const;
can_bus_mode raw_can_mode() const;
const std::vector<std::string>& parents() const;
const std::vector<std::string>& initializers() const;
const std::vector<std::string>& loopers() const;
const std::map<std::string, can_bus>& buses() const;
- const std::map<std::string, can_message>& messages() const;
+ const std::vector<can_message>& messages() const;
const std::vector<diagnostic_message>& diagnostic_messages() const;
const std::vector<mapping>& mappings() const;
const std::vector<std::string>& extra_sources() const;
const std::vector<command>& commands() const;
- std::string to_initializer() const;
-
void from_json(const nlohmann::json& j);
nlohmann::json to_json() const;
};
diff --git a/src/openxc/signal.cpp b/src/openxc/signal.cpp
index 9406112c..6c3ff82a 100755
--- a/src/openxc/signal.cpp
+++ b/src/openxc/signal.cpp
@@ -2,6 +2,18 @@
namespace openxc
{
+ std::string signal::id() const
+ {
+ return id_;
+ }
+
+ void signal::id(const std::string& id)
+ {
+ id_ = id;
+ }
+
+ void id(const std::string& id);
+
std::string signal::generic_name() const
{
return generic_name_;
@@ -47,7 +59,7 @@ namespace openxc
return states_;
}
- std::uint32_t signal::max_frequency() const
+ float signal::max_frequency() const
{
return max_frequency_;
}
diff --git a/src/openxc/signal.hpp b/src/openxc/signal.hpp
index f4b6683b..64dba75e 100755
--- a/src/openxc/signal.hpp
+++ b/src/openxc/signal.hpp
@@ -11,6 +11,7 @@ namespace openxc
class signal
{
private:
+ std::string id_;
std::string generic_name_;
std::uint32_t bit_position_;
std::uint32_t bit_size_;
@@ -20,12 +21,14 @@ namespace openxc
bool ignore_;
bool enabled_;
std::map<std::string, std::vector<std::uint32_t>> states_;
- std::uint32_t max_frequency_;
+ float max_frequency_;
bool send_same_;
bool force_send_changed_;
bool writable_;
std::string encoder_;
public:
+ std::string id() const;
+ void id(const std::string& id);
std::string generic_name() const;
std::uint32_t bit_position() const;
std::uint32_t bit_size() const;
@@ -35,7 +38,7 @@ namespace openxc
bool ignore() const;
bool enabled() const;
const std::map<std::string, std::vector<std::uint32_t>>& states() const;
- std::uint32_t max_frequency() const;
+ float max_frequency() const;
bool send_same() const;
bool force_send_changed() const;
bool writable() const;