aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Guyader <arthur.guyader@iot.bzh>2019-07-30 11:06:55 +0200
committerArthur Guyader <arthur.guyader@iot.bzh>2019-07-30 11:28:48 +0200
commitf61a6cb23ab86da2b3d477276886f1e73ec5c88c (patch)
tree0216631d7aa242d86e48b02afdaaf9747d2c2632
parent0bb5744297d7d25577b5ed48899c021e23e9a8ec (diff)
Add some options for J1939 support
This commit add some options for the support of the J1939. Signed-off-by: Arthur Guyader <arthur.guyader@iot.bzh> Change-Id: I9baee6a7319c8e8effa988d940a67e45ab64496d
-rw-r--r--src/main.cpp102
-rwxr-xr-xsrc/openxc/can_message.cpp64
-rwxr-xr-xsrc/openxc/can_message.hpp16
-rwxr-xr-xsrc/openxc/signal.cpp63
-rwxr-xr-xsrc/openxc/signal.hpp13
5 files changed, 197 insertions, 61 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 7880da2..ac7ce4b 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() : v.v_.states().size() ? "decoder_t::decode_state" : "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() : v.v_.states().size() ? "decoder_t::decode_state" : "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,26 @@ 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() << ","
+ << gen(v.v_.is_fd()) << ",";
+ if(v.v_.is_j1939()){
+ o << "message_format_t::J1939,";
+ }
+ else if(v.v_.is_extended())
+ {
+ o << "message_format_t::EXTENDED,";
+ }
+ 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 +209,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 +247,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..70b98a7 100755
--- a/src/openxc/can_message.cpp
+++ b/src/openxc/can_message.cpp
@@ -6,17 +6,17 @@ namespace openxc
{
return id_;
}
-
+
void can_message::id(const std::string& id)
{
id_ = id;
}
-
+
std::string can_message::bus() const
{
return bus_;
}
-
+
void can_message::is_fd(const bool is_fd)
{
is_fd_ = is_fd;
@@ -26,56 +26,82 @@ namespace openxc
{
return is_fd_;
}
+ void can_message::is_extended(const bool is_extended)
+ {
+ is_extended_ = is_extended;
+ }
+
+ bool can_message::is_extended() const
+ {
+ return is_extended_;
+ }
+
+ 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_;
}
-
+
const std::vector<signal>& can_message::signals() const
{
return signals_;
}
-
+
std::string can_message::name() const
{
return name_;
}
-
+
std::vector<std::string> can_message::handlers() const
{
return handlers_;
}
-
+
bool can_message::enabled() const
{
return enabled_;
}
-
+
float can_message::max_frequency() const
{
return max_frequency_;
}
-
+
float can_message::max_signal_frequency() const
{
return max_signal_frequency_;
}
-
+
bool can_message::force_send_changed() const
{
return force_send_changed_;
}
-
+
bool can_message::force_send_changed_signals() const
{
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_extended_ = j.count("is_extended") ? j["is_extended"].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 +110,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"];
@@ -95,9 +122,9 @@ namespace openxc
signals_.push_back(sig);
}
}
-
+
}
-
+
std::uint32_t can_message::get_signals_count() const
{
return (uint32_t)signals_.size();
@@ -108,6 +135,10 @@ namespace openxc
nlohmann::json j;
j["bus"] = bus_;
j["is_fd"] = is_fd_;
+
+ j["is_extended"] = is_extended_;
+
+ j["is_j1939"] = is_j1939_;
j["bit_numbering_inverted"] = bit_numbering_inverted_;
j["signals"] = signals_;
j["name"] = name_;
@@ -117,6 +148,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;
}
@@ -124,7 +156,7 @@ namespace openxc
{
j = p.to_json();
}
-
+
void from_json(const nlohmann::json& j, can_message& p)
{
p.from_json(j);
diff --git a/src/openxc/can_message.hpp b/src/openxc/can_message.hpp
index f2d1b6e..98b38a5 100755
--- a/src/openxc/can_message.hpp
+++ b/src/openxc/can_message.hpp
@@ -22,13 +22,22 @@ namespace openxc
float max_signal_frequency_;
bool force_send_changed_;
bool force_send_changed_signals_;
- bool is_fd_;
+ bool is_fd_;
+ bool is_extended_;
+ 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_extended(const bool is_extended);
+ bool is_extended() 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,10 +48,11 @@ 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;
-
+
std::uint32_t get_signals_count() const;
};
diff --git a/src/openxc/signal.cpp b/src/openxc/signal.cpp
index e9c1088..e60c3ee 100755
--- a/src/openxc/signal.cpp
+++ b/src/openxc/signal.cpp
@@ -83,6 +83,23 @@ namespace openxc
{
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)
{
@@ -99,6 +116,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 +167,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;
};