added support for diagnostic messages.
authorLoïc Collignon <loic.collignon@iot.bzh>
Fri, 17 Mar 2017 10:49:27 +0000 (11:49 +0100)
committerLoïc Collignon <loic.collignon@iot.bzh>
Fri, 17 Mar 2017 10:49:27 +0000 (11:49 +0100)
Signed-off-by: Loïc Collignon <loic.collignon@iot.bzh>
src/main.cpp

index 9497b3a..4b3feb2 100644 (file)
@@ -167,6 +167,22 @@ std::ostream& operator<<(std::ostream& o, const generator<openxc::signal>& v)
        return o;\r
 }\r
 \r
+template <>\r
+std::ostream& operator<<(std::ostream& o, const generator<openxc::diagnostic_message>& v)\r
+{\r
+       o       << v.line_prefix_ << "{\n"\r
+               << v.line_prefix_ << "\t" << v.v_.pid() << ",\n"\r
+               << v.line_prefix_ << "\t" << gen(v.v_.name()) << ",\n"\r
+               << v.line_prefix_ << "\t" << 0 << ",\n"\r
+               << v.line_prefix_ << "\t" << 0 << ",\n"\r
+               << v.line_prefix_ << "\t" << "UNIT::INVALID" << ",\n"\r
+               << v.line_prefix_ << "\t" << gen(v.v_.frequency()) << ",\n"\r
+               << v.line_prefix_ << "\t" << (v.v_.decoder().size() ? v.v_.decoder() : "nullptr") << ",\n"\r
+               << v.line_prefix_ << "\t" << (v.v_.callback().size() ? v.v_.callback() : "nullptr") << ",\n"\r
+               << v.line_prefix_ << "\t" << "true" << "\n"\r
+               << v.line_prefix_ << "}";\r
+       return o;\r
+}\r
 \r
 /// @brief Generate the configuration code.\r
 /// @param[in] header Content to be inserted as a header.\r
@@ -207,8 +223,24 @@ void generate(const std::string& header, const std::string& footer, const openxc
                        out << '\n';\r
                }\r
                out << "        }\n"\r
-                       << "    //, obd2_signals_{" << "/*...*/" << "}\n"\r
+                       << "    , diagnostic_messages_\n"\r
+                       << "    {\n"\r
+                       << gen(message_set.diagnostic_messages(), "             ") << "\n"\r
+                       << "    }\n"\r
                        << "{\n"\r
+                       << "}\n\n"\r
+                       << "const std::string configuration_t::get_diagnostic_bus() const\n"\r
+                       << "{\n";\r
+\r
+               std::string active_bus = "";\r
+               for (const auto& d : message_set.diagnostic_messages())\r
+               {\r
+                       if (d.bus().size() == 0) std::cerr << "ERROR: The bus name should be set for each diagnostic message." << std::endl;\r
+                       if (active_bus.size() == 0) active_bus = d.bus();\r
+                       if (active_bus != d.bus()) std::cerr << "ERROR: The bus name should be the same for each diagnostic message." << std::endl;\r
+               }\r
+\r
+               out     << "    return " << gen(active_bus) << ";\n"\r
                        << "}\n\n";\r
        out << footer << std::endl;\r
 }\r