diff options
-rw-r--r-- | src/main.cpp | 97 | ||||
-rwxr-xr-x | src/openxc/can_message.cpp | 21 | ||||
-rwxr-xr-x | src/openxc/can_message.hpp | 9 | ||||
-rwxr-xr-x | src/openxc/signal.cpp | 96 | ||||
-rwxr-xr-x | src/openxc/signal.hpp | 13 |
5 files changed, 175 insertions, 61 deletions
diff --git a/src/main.cpp b/src/main.cpp index 0608f16..f178667 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -109,16 +109,16 @@ template <> std::ostream& operator<<(std::ostream& o, const generator<openxc::message_set>& v)
{
o << v.line_prefix_
- << "{std::make_shared<can_message_set_t>(can_message_set_t{"
+ << "{std::make_shared<message_set_t>(message_set_t{"
<< "0,"
<< gen(v.v_.name()) << ",\n"
- << "\t\t\t{ // beginning can_message_definition_ vector\n"
+ << "\t\t\t{ // beginning message_definition_ vector\n"
<< gen(v.v_.messages(), "\t\t\t")
- << "\n\t\t}, // end can_message_definition vector\n"
+ << "\n\t\t}, // end message_definition vector\n"
<< "\t\t\t{ // beginning diagnostic_messages_ vector\n"
<< gen(v.v_.diagnostic_messages(),"\t\t\t") << "\n"
<< "\t\t\t} // end diagnostic_messages_ vector\n"
- << "\t\t})} // end can_message_set entry\n";
+ << "\t\t})} // end message_set entry\n";
return o;
}
@@ -146,22 +146,33 @@ std::ostream& operator<<(std::ostream& o, const generator<std::map<std::string, template <>
std::ostream& operator<<(std::ostream& o, const generator<openxc::signal>& v)
{
- o << v.line_prefix_ << "{std::make_shared<can_signal_t> (can_signal_t{\n"
- << v.line_prefix_ << "\t" << gen(v.v_.generic_name()) << ",\n"
- << v.line_prefix_ << "\t" << v.v_.bit_position() << ",\n"
- << v.line_prefix_ << "\t" << v.v_.bit_size() << ",\n"
- << v.line_prefix_ << "\t" << gen(v.v_.factor()) << ",\n"
- << v.line_prefix_ << "\t" << v.v_.offset() << ",\n"
- << v.line_prefix_ << "\t" << "0,\n"
- << v.line_prefix_ << "\t" << "0,\n"
- << v.line_prefix_ << "\tfrequency_clock_t(" << gen(v.v_.max_frequency()) << "),\n"
- << v.line_prefix_ << "\t" << gen(v.v_.send_same()) << ",\n"
- << v.line_prefix_ << "\t" << gen(v.v_.force_send_changed()) << ",\n"
- << gen(v.v_.states(), v.line_prefix_ + '\t') << ",\n"
- << v.line_prefix_ << '\t' << gen(v.v_.writable()) << ",\n"
- << v.line_prefix_ << '\t' << (v.v_.decoder().size() ? v.v_.decoder() : "nullptr") << ",\n"
- << v.line_prefix_ << '\t' << (v.v_.encoder().size() ? v.v_.encoder() : "nullptr") << ",\n"
- << v.line_prefix_ << '\t' << "false\n"
+ o << v.line_prefix_ << "{std::make_shared<signal_t> (signal_t{\n"
+ << v.line_prefix_ << "\t" << gen(v.v_.generic_name()) << ",// generic_name\n"
+ << v.line_prefix_ << "\t" << v.v_.bit_position() << ",// bit_position\n"
+ << v.line_prefix_ << "\t" << v.v_.bit_size() << ",// bit_size\n"
+ << v.line_prefix_ << "\t" << gen(v.v_.factor()) << ",// factor\n"
+ << v.line_prefix_ << "\t" << v.v_.offset() << ",// offset\n"
+ << v.line_prefix_ << "\t" << "0,// min_value\n"
+ << v.line_prefix_ << "\t" << "0,// max_value\n"
+ << v.line_prefix_ << "\tfrequency_clock_t(" << gen(v.v_.max_frequency()) << "),// frequency\n"
+ << v.line_prefix_ << "\t" << gen(v.v_.send_same()) << ",// send_same\n"
+ << v.line_prefix_ << "\t" << gen(v.v_.force_send_changed()) << ",// force_send_changed\n"
+ << gen(v.v_.states(), v.line_prefix_ + '\t') << ",// states\n"
+ << v.line_prefix_ << '\t' << gen(v.v_.writable()) << ",// writable\n"
+ << v.line_prefix_ << '\t' << (v.v_.decoder().size() ? v.v_.decoder() : "nullptr") << ",// decoder\n"
+ << v.line_prefix_ << '\t' << (v.v_.encoder().size() ? v.v_.encoder() : "nullptr") << ",// encoder\n"
+ << v.line_prefix_ << '\t' << "false,// received\n";
+ std::string multi_first = "";
+ if(v.v_.multiplex().first){
+ multi_first = "true";
+ }else{
+ multi_first = "false";
+ }
+ std::string multi = "std::make_pair<bool, int>(" + multi_first + "," + std::to_string(v.v_.multiplex().second) + ")";
+ o << v.line_prefix_ << '\t' << multi << ",// multiplex\n"
+ << v.line_prefix_ << '\t' << v.v_.is_big_endian() << ",// is_big_endian\n"
+ << v.line_prefix_ << '\t' << v.v_.is_signed() << ",// is_signed\n"
+ << v.line_prefix_ << "\t" << gen(v.v_.unit()) << ",// unit\n"
<< v.line_prefix_ << "})}";
return o;
}
@@ -170,15 +181,21 @@ template <> std::ostream& operator<<(std::ostream& o, const generator<openxc::can_message>& v)
{
o << v.line_prefix_
- << "{std::make_shared<can_message_definition_t>(can_message_definition_t{"
+ << "{std::make_shared<message_definition_t>(message_definition_t{"
<< gen(v.v_.bus()) << ","
<< v.v_.id() << ","
- << v.v_.is_fd() << ","
- << "can_message_format_t::STANDARD,"
- << "frequency_clock_t(" << gen(v.v_.max_frequency()) << "),"
- << gen(v.v_.force_send_changed()) << ",\n";
+ << "\"" << v.v_.name() << "\","
+ << v.v_.length() << ","
+ << v.v_.is_fd() << ",";
+ if(v.v_.is_j1939()){
+ o << "message_format_t::J1939,";
+ }else{
+ o << "message_format_t::STANDARD,";
+ }
+ o << "frequency_clock_t(" << gen(v.v_.max_frequency()) << "),"
+ << gen(v.v_.force_send_changed()) << ",";
std::uint32_t index = 0;
- o << "\t\t\t\t\t{ // beginning can_signals vector\n";
+ o << "\t\t\t\t\t{ // beginning signals vector\n";
std::uint32_t signal_count = (uint32_t)v.v_.signals().size();
for(const openxc::signal& s : v.v_.signals())
{
@@ -187,8 +204,8 @@ std::ostream& operator<<(std::ostream& o, const generator<openxc::can_message>& --signal_count;
o << '\n';
}
- o << "\t\t\t\t\t} // end can_signals vector\n"
- << "\t\t\t\t})} // end can_message_definition entry\n";
+ o << "\t\t\t\t\t} // end signals vector\n"
+ << "\t\t\t\t})} // end message_definition entry\n";
return o;
}
@@ -225,26 +242,26 @@ void generate(const std::string& header, const std::string& footer, const openxc out << "application_t::application_t()\n"
<< " : can_bus_manager_{utils::config_parser_t{\"/etc/dev-mapping.conf\"}}\n"
- << " , can_message_set_{\n"
+ << " , message_set_{\n"
<< gen(message_set, "\t\t")
- << "\t} // end can_message_set vector\n"
+ << "\t} // end message_set vector\n"
<< "{\n"
- << " for(auto& cms: can_message_set_)\n"
+ << " for(std::shared_ptr<message_set_t> cms: message_set_)\n"
<< " {\n"
- << " std::vector<std::shared_ptr<can_message_definition_t> >& can_messages_definition = cms->get_can_message_definition();\n"
- << " for(auto& cmd : can_messages_definition)\n"
+ << " std::vector<std::shared_ptr<message_definition_t>> messages_definition = cms->get_messages_definition();\n"
+ << " for(std::shared_ptr<message_definition_t> cmd : messages_definition)\n"
<< " {\n"
- << " cmd->set_parent(cms.get());\n"
- << " std::vector<std::shared_ptr<can_signal_t> >& can_signals = cmd->get_can_signals();\n"
- << " for(auto& sig: can_signals)\n"
+ << " cmd->set_parent(cms);\n"
+ << " std::vector<std::shared_ptr<signal_t>> signals = cmd->get_signals();\n"
+ << " for(std::shared_ptr<signal_t> sig: signals)\n"
<< " {\n"
- << " sig->set_parent(cmd.get());\n"
+ << " sig->set_parent(cmd);\n"
<< " }\n"
<< " }\n\n"
- << " std::vector<std::shared_ptr<diagnostic_message_t> >& diagnostic_messages = cms->get_diagnostic_messages();\n"
- << " for(auto& dm : diagnostic_messages)\n"
+ << " std::vector<std::shared_ptr<diagnostic_message_t>> diagnostic_messages = cms->get_diagnostic_messages();\n"
+ << " for(std::shared_ptr<diagnostic_message_t> dm : diagnostic_messages)\n"
<< " {\n"
- << " dm->set_parent(cms.get());\n"
+ << " dm->set_parent(cms);\n"
<< " }\n"
<< " }\n"
<< " }\n\n"
diff --git a/src/openxc/can_message.cpp b/src/openxc/can_message.cpp index 77418d8..858540c 100755 --- a/src/openxc/can_message.cpp +++ b/src/openxc/can_message.cpp @@ -27,6 +27,16 @@ namespace openxc return is_fd_;
}
+ void can_message::is_j1939(const bool is_j1939)
+ {
+ is_j1939_ = is_j1939;
+ }
+
+ bool can_message::is_j1939() const
+ {
+ return is_j1939_;
+ }
+
bool can_message::bit_numbering_inverted() const
{
return bit_numbering_inverted_;
@@ -72,10 +82,16 @@ namespace openxc return force_send_changed_;
}
+ uint32_t can_message::length() const
+ {
+ return length_;
+ }
+
void can_message::from_json(const nlohmann::json& j)
{
bus_ = j.count("bus") ? j["bus"].get<std::string>() : "";
is_fd_ = j.count("is_fd") ? j["is_fd"].get<bool>() : false;
+ is_j1939_ = j.count("is_j1939") ? j["is_j1939"].get<bool>() : false;
bit_numbering_inverted_ = j.count("bit_numbering_inverted") ? j["bit_numbering_inverted"].get<bool>() : false;
name_ = j.count("name") ? j["name"].get<std::string>() : "";
handlers_ = j.count("handlers") ? j["handlers"].get<std::vector<std::string>>() : std::vector<std::string>();
@@ -84,7 +100,8 @@ namespace openxc max_signal_frequency_ = j.count("max_signal_frequency") ? j["max_signal_frequency"].get<float>() : 5;
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;
-
+ length_ = j.count("length") ? j["length"].get<uint32_t>() : 0;
+
if(j.count("signals"))
{
std::map<std::string, nlohmann::json> signals = j["signals"];
@@ -108,6 +125,7 @@ namespace openxc nlohmann::json j;
j["bus"] = bus_;
j["is_fd"] = is_fd_;
+ j["is_j1939"] = is_j1939_;
j["bit_numbering_inverted"] = bit_numbering_inverted_;
j["signals"] = signals_;
j["name"] = name_;
@@ -117,6 +135,7 @@ namespace openxc j["max_signal_frequency"] = max_signal_frequency_;
j["force_send_changed"] = force_send_changed_;
j["force_send_changed_signals"] = force_send_changed_signals_;
+ j["length"] = length_;
return j;
}
diff --git a/src/openxc/can_message.hpp b/src/openxc/can_message.hpp index f2d1b6e..3d92b18 100755 --- a/src/openxc/can_message.hpp +++ b/src/openxc/can_message.hpp @@ -22,13 +22,19 @@ namespace openxc float max_signal_frequency_;
bool force_send_changed_;
bool force_send_changed_signals_;
- bool is_fd_;
+ bool is_fd_;
+ bool is_j1939_;
+ uint32_t length_;
+ float min_value;
+ float max_value;
public:
std::string id() const;
void id(const std::string& id);
void is_fd(const bool is_fd);
bool is_fd() const;
+ void is_j1939(const bool is_j1939);
+ bool is_j1939() const;
std::string bus() const;
bool bit_numbering_inverted() const;
const std::vector<signal>& signals() const;
@@ -39,6 +45,7 @@ namespace openxc float max_signal_frequency() const;
bool force_send_changed() const;
bool force_send_changed_signals() const;
+ uint32_t length() 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 e9c1088..1bcd869 100755 --- a/src/openxc/signal.cpp +++ b/src/openxc/signal.cpp @@ -6,84 +6,100 @@ namespace openxc {
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_;
}
-
+
std::uint32_t signal::bit_position() const
{
return bit_position_;
}
-
+
std::uint32_t signal::bit_size() const
{
return bit_size_;
}
-
+
float signal::factor() const
{
return factor_;
}
-
+
float signal::offset() const
{
return offset_;
}
-
+
std::string signal::decoder() const
{
return decoder_;
}
-
+
bool signal::ignore() const
{
return ignore_;
}
-
+
bool signal::enabled() const
{
return enabled_;
}
-
+
const std::map<std::string, std::vector<std::uint32_t>>& signal::states() const
{
return states_;
}
-
+
float signal::max_frequency() const
{
return max_frequency_;
}
-
+
bool signal::send_same() const
{
return send_same_;
}
-
+
bool signal::force_send_changed() const
{
return force_send_changed_;
}
-
+
bool signal::writable() const
{
return writable_;
}
-
+
std::string signal::encoder() const
{
return encoder_;
}
-
+
+ std::pair<bool,int> signal::multiplex() const{
+ return multiplex_;
+ }
+
+ bool signal::is_big_endian() const{
+ return is_big_endian_;
+ }
+
+ bool signal::is_signed() const{
+ return is_signed_;
+ }
+
+ std::string signal::unit() const{
+ return unit_;
+ }
+
void signal::from_json(const nlohmann::json& j)
{
generic_name_ = j.count("generic_name") ? j["generic_name"].get<std::string>() : "";
@@ -99,6 +115,29 @@ namespace openxc force_send_changed_ = j.count("force_send_changed") ? j["force_send_changed"].get<bool>() : false;
writable_ = j.count("writable") ? j["writable"].get<bool>() : false;
encoder_ = j.count("encoder") ? j["encoder"].get<std::string>() : "";
+ if(j.count("multiplex"))
+ {
+ std::string mult = j["multiplex"].get<std::string>();
+ bool first = false;
+ int second = 0 ;
+ if(mult.compare("Multiplexor") == 0){
+ first = true;
+ }
+ else if (mult.compare("") != 0)
+ {
+ second = std::stoi(mult);
+ }
+ multiplex_ = std::make_pair(first,second);
+ }
+ else
+ {
+ multiplex_ = std::make_pair(false,0);
+ }
+ is_big_endian_ = j.count("is_big_endian") ? j["is_big_endian"].get<bool>() : false;
+ is_signed_ = j.count("is_signed") ? j["is_signed"].get<bool>() : false;
+ unit_ = j.count("unit") ? j["unit"].get<std::string>() : "";
+
+
if (j.count("states"))
{
@@ -127,6 +166,29 @@ namespace openxc j["force_send_changed"] = force_send_changed_;
j["writable"] = writable_;
j["encoder"] = encoder_;
+
+ std::string multi = "";
+
+ if(multiplex_.first)
+ {
+ multi = "Multiplexor";
+ }
+ else if(multiplex_.second != 0)
+ {
+ multi = std::to_string(multiplex_.second);
+ }
+ else
+ {
+ multi = "";
+ }
+
+ j["multiplex"] = multi;
+
+
+
+ j["is_big_endian"] = is_big_endian_;
+ j["is_signed"] = is_signed_;
+ j["unit"] = unit_;
return j;
}
diff --git a/src/openxc/signal.hpp b/src/openxc/signal.hpp index e0124c3..750926b 100755 --- a/src/openxc/signal.hpp +++ b/src/openxc/signal.hpp @@ -21,11 +21,16 @@ namespace openxc bool ignore_;
bool enabled_;
std::map<std::string, std::vector<std::uint32_t>> states_;
- float max_frequency_;
+ float max_frequency_;
bool send_same_;
bool force_send_changed_;
bool writable_;
std::string encoder_;
+ std::pair<bool,int> multiplex_;
+ bool is_big_endian_;
+ bool is_signed_;
+ std::string unit_;
+
public:
std::string id() const;
void id(const std::string& id);
@@ -43,7 +48,11 @@ namespace openxc bool force_send_changed() const;
bool writable() const;
std::string encoder() const;
-
+ std::pair<bool,int> multiplex() const;
+ bool is_big_endian() const;
+ bool is_signed() const;
+ std::string unit() const;
+
void from_json(const nlohmann::json& j);
nlohmann::json to_json() const;
};
|