From cbc227941e8f65bf9e1a2cc8a178792a8462be18 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lo=C3=AFc=20Collignon?= Date: Fri, 17 Mar 2017 11:49:27 +0100 Subject: [PATCH] added support for diagnostic messages. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Loïc Collignon --- src/main.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 9497b3a5..4b3feb27 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -167,6 +167,22 @@ std::ostream& operator<<(std::ostream& o, const generator& v) return o; } +template <> +std::ostream& operator<<(std::ostream& o, const generator& v) +{ + o << v.line_prefix_ << "{\n" + << v.line_prefix_ << "\t" << v.v_.pid() << ",\n" + << v.line_prefix_ << "\t" << gen(v.v_.name()) << ",\n" + << v.line_prefix_ << "\t" << 0 << ",\n" + << v.line_prefix_ << "\t" << 0 << ",\n" + << v.line_prefix_ << "\t" << "UNIT::INVALID" << ",\n" + << v.line_prefix_ << "\t" << gen(v.v_.frequency()) << ",\n" + << v.line_prefix_ << "\t" << (v.v_.decoder().size() ? v.v_.decoder() : "nullptr") << ",\n" + << v.line_prefix_ << "\t" << (v.v_.callback().size() ? v.v_.callback() : "nullptr") << ",\n" + << v.line_prefix_ << "\t" << "true" << "\n" + << v.line_prefix_ << "}"; + return o; +} /// @brief Generate the configuration code. /// @param[in] header Content to be inserted as a header. @@ -207,8 +223,24 @@ void generate(const std::string& header, const std::string& footer, const openxc out << '\n'; } out << " }\n" - << " //, obd2_signals_{" << "/*...*/" << "}\n" + << " , diagnostic_messages_\n" + << " {\n" + << gen(message_set.diagnostic_messages(), " ") << "\n" + << " }\n" << "{\n" + << "}\n\n" + << "const std::string configuration_t::get_diagnostic_bus() const\n" + << "{\n"; + + std::string active_bus = ""; + for (const auto& d : message_set.diagnostic_messages()) + { + if (d.bus().size() == 0) std::cerr << "ERROR: The bus name should be set for each diagnostic message." << std::endl; + if (active_bus.size() == 0) active_bus = d.bus(); + if (active_bus != d.bus()) std::cerr << "ERROR: The bus name should be the same for each diagnostic message." << std::endl; + } + + out << " return " << gen(active_bus) << ";\n" << "}\n\n"; out << footer << std::endl; } -- 2.16.6