template <typename T>\r
std::ostream& operator<<(std::ostream& o, const generator<std::vector<T>>& v)\r
{\r
- o << v.line_prefix_ << "{\n";\r
+// o << v.line_prefix_;\r
auto sz = v.v_.size();\r
for(const T& i : v.v_)\r
{\r
o << gen(i, v.line_prefix_ + '\t');\r
if (sz > 1) o << ",";\r
--sz;\r
- o << '\n';\r
+// o << '\n';\r
}\r
- o << v.line_prefix_ << '}';\r
+// o << v.line_prefix_;\r
return o;\r
}\r
\r
std::ostream& operator<<(std::ostream& o, const generator<openxc::message_set>& v)\r
{\r
o << v.line_prefix_\r
- << '{'\r
- << "0, "\r
- << gen(v.v_.name()) << ", "\r
- << v.v_.buses().size() << ", "\r
- << v.v_.messages().size() << ", "\r
- << std::accumulate(\r
- std::begin(v.v_.messages()),\r
- std::end(v.v_.messages()),\r
- 0,\r
- [](int sum, const openxc::can_message& p) { return sum + p.signals().size(); }\r
- ) << ", "\r
- << v.v_.commands().size() << ", "\r
- << v.v_.diagnostic_messages().size() << "}";\r
- return o;\r
-}\r
-\r
-template <>\r
-std::ostream& operator<<(std::ostream& o, const generator<openxc::can_message>& v)\r
-{\r
- o << v.line_prefix_\r
- << "can_message_definition_t("\r
- << "0, "\r
- << gen(v.v_.bus()) << ", "\r
- << v.v_.id() << ", "\r
- << "can_message_format_t::STANDARD, "\r
- << "frequency_clock_t(" << gen(v.v_.max_frequency()) << "), "\r
- << gen(v.v_.force_send_changed())\r
- << ')';\r
+ << "{std::make_shared<can_message_set_t>(can_message_set_t{"\r
+ << "0,"\r
+ << gen(v.v_.name()) << ",\n"\r
+ << "\t\t\t{ // beginning can_message_definition_ vector\n"\r
+ << gen(v.v_.messages(), "\t\t\t")\r
+ << "\n\t\t}, // end can_message_definition vector\n"\r
+ << "\t\t\t{ // beginning diagnostic_messages_ vector\n"\r
+ << gen(v.v_.diagnostic_messages(),"\t\t\t") << "\n"\r
+ << "\t\t\t} // end diagnostic_messages_ vector\n"\r
+ << "\t\t})} // end can_message_set entry\n";\r
return o;\r
}\r
\r
std::ostream& operator<<(std::ostream& o, const generator<std::map<std::string, std::vector<std::uint32_t>>>& v)\r
{\r
o << v.line_prefix_ << "{\n";\r
- std::uint32_t c1 = v.v_.size();\r
+ std::uint32_t c1 = (uint32_t)v.v_.size();\r
for(const auto& state : v.v_)\r
{\r
- std::uint32_t c2 = state.second.size();\r
+ std::uint32_t c2 = (uint32_t)state.second.size();\r
for(const auto& i : state.second)\r
{\r
- o << v.line_prefix_ << "\t" << "{" << i << ", " << gen(state.first) << "}";\r
+ o << v.line_prefix_ << "\t" << "{" << i << "," << gen(state.first) << "}";\r
if (c1 > 1 || c2 > 1) o << ',';\r
o << '\n';\r
--c2;\r
template <>\r
std::ostream& operator<<(std::ostream& o, const generator<openxc::signal>& v)\r
{\r
- o << v.line_prefix_ << "{\n"\r
- << v.line_prefix_ << "\t0,\n"\r
- << v.line_prefix_ << "\t" << v.index_ << ",\n"\r
+ o << v.line_prefix_ << "{std::make_shared<can_signal_t> (can_signal_t{\n"\r
<< v.line_prefix_ << "\t" << gen(v.v_.generic_name()) << ",\n"\r
<< v.line_prefix_ << "\t" << v.v_.bit_position() << ",\n"\r
<< v.line_prefix_ << "\t" << v.v_.bit_size() << ",\n"\r
- << v.line_prefix_ << "\t" << gen(v.v_.factor()) << ", \n"\r
- << v.line_prefix_ << "\t" << v.v_.offset() << ", \n"\r
+ << v.line_prefix_ << "\t" << gen(v.v_.factor()) << ",\n"\r
+ << v.line_prefix_ << "\t" << v.v_.offset() << ",\n"\r
<< v.line_prefix_ << "\t" << "0,\n"\r
<< v.line_prefix_ << "\t" << "0,\n"\r
<< v.line_prefix_ << "\tfrequency_clock_t(" << gen(v.v_.max_frequency()) << "),\n"\r
<< v.line_prefix_ << '\t' << (v.v_.decoder().size() ? v.v_.decoder() : "nullptr") << ",\n"\r
<< v.line_prefix_ << '\t' << (v.v_.encoder().size() ? v.v_.encoder() : "nullptr") << ",\n"\r
<< v.line_prefix_ << '\t' << "false\n"\r
- << v.line_prefix_ << "}";\r
+ << v.line_prefix_ << "})}";\r
+ return o;\r
+}\r
+\r
+template <>\r
+std::ostream& operator<<(std::ostream& o, const generator<openxc::can_message>& v)\r
+{\r
+ o << v.line_prefix_\r
+ << "{std::make_shared<can_message_definition_t>(can_message_definition_t{"\r
+ << gen(v.v_.bus()) << ","\r
+ << v.v_.id() << ","\r
+ << "can_message_format_t::STANDARD,"\r
+ << "frequency_clock_t(" << gen(v.v_.max_frequency()) << "),"\r
+ << gen(v.v_.force_send_changed()) << ",\n";\r
+ std::uint32_t index = 0;\r
+ o << "\t\t\t\t\t{ // beginning can_signals vector\n";\r
+ std::uint32_t signal_count = (uint32_t)v.v_.signals().size();\r
+ for(const openxc::signal& s : v.v_.signals())\r
+ {\r
+ o << gen(s, index,"\t\t\t\t\t\t");\r
+ if (signal_count > 1) o << ',';\r
+ --signal_count;\r
+ o << '\n';\r
+ }\r
+ o << "\t\t\t\t\t} // end can_signals vector\n"\r
+ << "\t\t\t\t})} // end can_message_definition entry\n";\r
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
+ o << v.line_prefix_ << "{std::make_shared<diagnostic_message_t>(diagnostic_message_t{\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" << (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
+ << v.line_prefix_ << "})}\n";\r
return o;\r
}\r
\r
-/// @brief Generate the configuration code.\r
+/// @brief Generate the application code.\r
/// @param[in] header Content to be inserted as a header.\r
/// @param[in] footer Content to be inserted as a footer.\r
-/// @param[in] message_set Configuration read from the json file.\r
+/// @param[in] message_set application read from the json file.\r
/// @param[in] out Stream to write on.\r
void generate(const std::string& header, const std::string& footer, const openxc::message_set& message_set, std::ostream& out)\r
{\r
- out << "#include \"configuration.hpp\"\n"\r
- << "#include \"can/can-decoder.hpp\"\n\n";\r
+ out << "#include \"application.hpp\"\n"\r
+ << "#include \"../can/can-decoder.hpp\"\n\n";\r
\r
if (header.size()) out << header << "\n";\r
\r
- out << "configuration_t::configuration_t()\n"\r
- << " : can_message_set_{" << gen(message_set) << "}\n"\r
- << " , can_message_definition_\n"\r
+ out << "application_t::application_t()\n"\r
+ << " : can_bus_manager_{utils::config_parser_t{\"/etc/dev-mapping.conf\"}}\n"\r
+ << " , can_message_set_{\n"\r
+ << gen(message_set, "\t\t")\r
+ << "\t} // end can_message_set vector\n"\r
+ << "{\n"\r
+ << " for(auto& cms: can_message_set_)\n"\r
<< " {\n"\r
- << gen(message_set.messages(), "\t\t") << '\n'\r
+ << " std::vector<std::shared_ptr<can_message_definition_t> >& can_messages_definition = cms->get_can_message_definition();\n"\r
+ << " for(auto& cmd : can_messages_definition)\n"\r
+ << " {\n"\r
+ << " cmd->set_parent(cms.get());\n"\r
+ << " std::vector<std::shared_ptr<can_signal_t> >& can_signals = cmd->get_can_signals();\n"\r
+ << " for(auto& sig: can_signals)\n"\r
+ << " {\n"\r
+ << " sig->set_parent(cmd.get());\n"\r
+ << " }\n"\r
+ << " }\n\n"\r
+ << " std::vector<std::shared_ptr<diagnostic_message_t> >& diagnostic_messages = cms->get_diagnostic_messages();\n"\r
+ << " for(auto& dm : diagnostic_messages)\n"\r
+ << " {\n"\r
+ << " dm->set_parent(cms.get());\n"\r
+ << " }\n"\r
<< " }\n"\r
- << " , can_signals_\n"\r
- << " {\n";\r
- std::uint32_t message_count = message_set.messages().size();\r
- std::uint32_t index = 0;\r
- out << " {\n";\r
- for(const openxc::can_message& m : message_set.messages())\r
- {\r
- std::uint32_t signal_count = m.signals().size();\r
- for(const openxc::signal& s : m.signals())\r
- {\r
- out << gen(s, index, " ");\r
- if (signal_count > 1) out << ',';\r
- --signal_count;\r
- out << '\n';\r
- }\r
- if (index + 1 < message_count) out << ',';\r
- ++index;\r
- }\r
- out << " }\n";\r
- out << " }\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
+ << " }\n\n"\r
+ << "const std::string application_t::get_diagnostic_bus() const\n"\r
+ << "{\n";\r
\r
std::string active_bus = "";\r
for (const auto& d : message_set.diagnostic_messages())\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
+ out << "\treturn " << gen(active_bus) << ";\n"\r
+ << "}\n\n";\r
+ out << footer << std::endl;\r
}\r
\r
/// @brief Read whole file content to a string.\r
// function that show the help information\r
void showhelpinfo(char *s)\r
{\r
-std::cout<<"Usage: "<<s<<" <-m inpout.json> [-o configuration-generated.cpp]"<< std::endl;\r
+std::cout<<"Usage: "<<s<<" <-m inpout.json> [-o application-generated.cpp]"<< std::endl;\r
std::cout<<"option: "<<"-m input.json : JSON file describing CAN messages and signals"<< std::endl;\r
std::cout<<" "<<"-h header.cpp : header source file insert at the beginning of generated file"<< std::endl;\r
std::cout<<" "<<"-f footer.cpp : footer source file append to generated file."<< std::endl;\r
-std::cout<<" "<<"-o configuration-generated.cpp : output source file. Name has to be configuration-generated.cpp"<< std::endl;\r
+std::cout<<" "<<"-o application-generated.cpp : output source file. Name has to be application-generated.cpp"<< std::endl;\r
}\r
\r
/// @brief Entry point.\r
/*use function getopt to get the arguments with option."hu:p:s:v" indicate \r
that option h,v are the options without arguments while u,p,s are the\r
options with arguments*/\r
- while((tmp=getopt(argc,argv,"m:h:f:o:"))!=-1)\r
+ while((tmp=(char)getopt(argc,argv,"m:h:f:o:"))!=-1)\r
{\r
switch(tmp)\r
{\r