aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp152
1 files changed, 68 insertions, 84 deletions
diff --git a/src/main.cpp b/src/main.cpp
index c001df3..660c347 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -35,18 +35,40 @@
#define EXIT_PROGRAM_ERROR 3
-/**
+/*
* FLAGS
+ *
+ * Taken from include/low-can/can-message.hpp in agl-service-can-low-level.
+ * The flags values in the generated message_definition_t definitions needs to
+ * match usage of these flags in the binding, e.g. in the various member
+ * functions in low-can-binding/can/message-definition.cpp.
+ *
+ * ATM the only flags known to be used are:
+ *
+ * CAN_PROTOCOL_WITH_FD_FRAME
+ * J1939_PROTOCOL
+ * ISOTP_PROTOCOL
+ * BYTE_FRAME_IS_BIG_ENDIAN
+ *
+ * Note that for BYTE_FRAME_IS_BIG_ENDIAN, even though it is referenced in
+ * message-definition.cpp, the member function that does so seems currently
+ * unused, so it is not clear what the intended usage actually is.
+ * The JSON parser for CAN messages would likely need an additional field
+ * added to allow setting it, for now that is being left for a future update.
*/
-#define INVALID_FLAG 0x0001
-#define STANDARD_ID 0x0002
-#define EXTENDED_ID 0x0004
-#define BCM_PROTOCOL 0x0008
-#define J1939_PROTOCOL 0x0010
-#define J1939_ADDR_CLAIM_PROTOCOL 0x0020
-#define ISOTP_PROTOCOL 0x0040
-#define FD_FRAME 0x0800
+#define CAN_PROTOCOL 0x0001
+#define CAN_PROTOCOL_WITH_FD_FRAME 0x0002
+#define J1939_ADDR_CLAIM_PROTOCOL 0x0004
+#define J1939_PROTOCOL 0x0008
+#define ISOTP_PROTOCOL 0x0010
+#define ISOTP_SEND 0x0020
+#define ISOTP_RECEIVE 0x0040
+#define BYTE_FRAME_IS_BIG_ENDIAN 0x0080
+#define BIT_POSITION_REVERSED 0x0100
+#define CONTINENTAL_BIT_POSITION 0x0200
+#define INVALID_FLAG 0x8000
+
#define VERSION_LOW_CAN "2.0"
@@ -128,17 +150,17 @@ std::ostream& operator<<(std::ostream& o, const generator<std::vector<T>>& v)
template <>
std::ostream& operator<<(std::ostream& o, const generator<openxc::message_set>& v)
{
- o << v.line_prefix_
- << "{std::make_shared<message_set_t>(message_set_t{"
+ o << "std::shared_ptr<message_set_t> cms = "
+ << "std::make_shared<message_set_t>(message_set_t{"
<< "0,"
<< gen(v.v_.name()) << ",\n"
- << "\t\t\t{ // beginning message_definition_ vector\n"
- << gen(v.v_.messages(), "\t\t\t")
- << "\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 message_set entry\n";
+ << "\t{ // beginning message_definition_ vector\n"
+ << gen(v.v_.messages(), "\t")
+ << "\t}, // end message_definition vector\n"
+ << "\t{ // beginning diagnostic_messages_ vector\n"
+ << gen(v.v_.diagnostic_messages(),"\t") << "\n"
+ << "\t} // end diagnostic_messages_ vector\n"
+ << "}); // end message_set entry\n";
return o;
}
@@ -192,8 +214,8 @@ std::ostream& operator<<(std::ostream& o, const generator<openxc::signal>& v)
}
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' << gen(v.v_.is_big_endian()) << ",// is_big_endian\n"
- << v.line_prefix_ << '\t' << gen(v.v_.is_signed()) << ",// is_signed\n"
+ << v.line_prefix_ << "\tstatic_cast<sign_t>(" << gen(v.v_.sign()) << "),// signed\n"
+ << v.line_prefix_ << '\t' << gen(v.v_.bit_sign_position()) << ",// bit_sign_position\n"
<< v.line_prefix_ << "\t" << gen(v.v_.unit()) << "// unit\n"
<< v.line_prefix_ << "})}";
return o;
@@ -207,11 +229,11 @@ std::ostream& operator<<(std::ostream& o, const generator<openxc::can_message>&
<< gen(v.v_.bus()) << ","
<< v.v_.id() << ","
<< "\"" << v.v_.name() << "\","
- << v.v_.length() << ",";
+ << (v.v_.length() != 0 ? v.v_.length() : 8) << ",";
uint32_t flags = 0;
if(v.v_.is_fd())
{
- flags = flags|FD_FRAME;
+ flags = flags|CAN_PROTOCOL_WITH_FD_FRAME;
}
if(v.v_.is_j1939())
@@ -224,37 +246,22 @@ std::ostream& operator<<(std::ostream& o, const generator<openxc::can_message>&
flags = flags|ISOTP_PROTOCOL;
}
- if(v.v_.is_extended())
- {
- flags = flags|EXTENDED_ID;
- }
- else
- {
- flags = flags|STANDARD_ID;
- }
-
-
- if(v.v_.is_fd())
- {
- flags = flags|FD_FRAME;
- }
-
o << gen(flags) << ",";
o << "frequency_clock_t(" << gen(v.v_.max_frequency()) << "),"
<< gen(v.v_.force_send_changed()) << ",";
std::uint32_t index = 0;
- o << "\n\t\t\t\t\t{ // beginning signals vector\n";
+ o << "\n\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())
{
- o << gen(s, index,"\t\t\t\t\t\t");
+ o << gen(s, index,"\t\t\t\t");
if (signal_count > 1) o << ',';
--signal_count;
o << '\n';
}
- o << "\t\t\t\t\t} // end signals vector\n"
- << "\t\t\t\t})} // end message_definition entry\n";
+ o << "\t\t\t} // end signals vector\n"
+ << "\t\t})} // end message_definition entry\n";
return o;
}
@@ -283,56 +290,33 @@ std::ostream& operator<<(std::ostream& o, const generator<openxc::diagnostic_mes
/// @param[in] out Stream to write on.
void generate(const std::string& header, const std::string& footer, const openxc::message_set& message_set, std::ostream& out)
{
- out << "#include \"application.hpp\"\n"
- << "#include \"../can/can-decoder.hpp\"\n"
- << "#include \"../can/can-encoder.hpp\"\n\n";
+ // Derive CAPI name from message set name
+ // (the name is lowercased and spaces are converted to dashes ('-')
+ std::string capi_name(message_set.name());
+ std::transform(capi_name.begin(), capi_name.end(), capi_name.begin(),
+ [](unsigned char c){ return (c == ' ' ? '-' : std::tolower(c)); });
+
+ out << "#include <binding/application.hpp>\n"
+ << "#include <can/can-decoder.hpp>\n"
+ << "#include <can/can-encoder.hpp>\n\n";
if (header.size()) out << header << "\n";
- out << "application_t::application_t()\n"
- << " : can_bus_manager_{utils::config_parser_t{\"/etc/dev-mapping.conf\"}}\n"
- << " , message_set_{\n"
+ out << "extern \"C\" {\n"
+ << "CTLP_CAPI_REGISTER(\"" << capi_name << "\");\n"
+ << "\n"
<< gen(message_set, "\t\t")
- << "\t} // end message_set vector\n"
- << "{\n"
- << " for(std::shared_ptr<message_set_t> cms: message_set_)\n"
- << " {\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);\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);\n"
- << " }\n"
- << " }\n\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);\n"
- << " }\n"
- << " }\n"
- << " }\n\n"
- << "const std::string application_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 << "\treturn " << gen(active_bus) << ";\n"
- << "}\n\n";
-
+ << "\n"
+ << "CTLP_ONLOAD(plugin, handle) {\n"
+ << "\tafb_api_t api = (afb_api_t) plugin->api;\n"
+ << "\tCtlConfigT* CtlConfig = (CtlConfigT*) afb_api_get_userdata(api);\n"
+ << "\tapplication_t* app = (application_t*) getExternalData(CtlConfig);\n"
+ << "\n"
+ << "\treturn app->add_message_set(cms);\n"
+ << "}\n\n\n}\n";
out << decoder_t::apply_patch();
-
-
out << footer << std::endl;
}