summaryrefslogtreecommitdiffstats
path: root/examples/basic/generate_example.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-07-11 17:03:20 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-07-21 12:02:10 +0200
commitbe9884ab7d3c138e0adae6abd5a3a0dc4350a9fd (patch)
treef761bf80def631fcb778ff5119ac7eb23e1749a2 /examples/basic/generate_example.cpp
parente66a0cadb84e8892ad82ae056d2d8d4351315170 (diff)
Example regeneration
Change-Id: Iab06c4aebcc4172ae831c8fda2d3986315fb94c2 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'examples/basic/generate_example.cpp')
-rw-r--r--examples/basic/generate_example.cpp344
1 files changed, 175 insertions, 169 deletions
diff --git a/examples/basic/generate_example.cpp b/examples/basic/generate_example.cpp
index 24b01df1..88ee94b9 100644
--- a/examples/basic/generate_example.cpp
+++ b/examples/basic/generate_example.cpp
@@ -1,29 +1,8 @@
-/* DO NOT MODIFY: This source is generated by the scripts in the
- * vi-firmware repository.
- *
- * Generated for v7.x of the OpenXC VI firmware.
- */
+#include "application.hpp"
+#include "../can/can-decoder.hpp"
-#include "diagnostics.h"
-#include "can/canread.h"
-#include "can/canwrite.h"
-#include "signals.h"
-#include "obd2.h"
-#include "util/log.h"
-#include "config.h"
-#include "shared_handlers.h"
-
-namespace can = openxc::can;
-
-using openxc::util::log::debug;
-using openxc::pipeline::Pipeline;
-using openxc::config::getConfiguration;
-using openxc::can::read::booleanDecoder;
-using openxc::can::read::stateDecoder;
-using openxc::can::read::ignoreDecoder;
-using openxc::diagnostics::obd2::handleObd2Pid;
-using namespace openxc::signals::handlers;
+// >>>>> handlers.cpp >>>>>
#include "can/canread.h"
using openxc::can::read::publishNumericalMessage;
@@ -47,151 +26,178 @@ void myLooper() {
// all CAN message processing has been completed
}
-const int MESSAGE_SET_COUNT = 1;
-CanMessageSet MESSAGE_SETS[MESSAGE_SET_COUNT] = {
- { 0, "example", 2, 1, 5, 1 },
-};
-
-const int MAX_CAN_BUS_COUNT = 2;
-CanBus CAN_BUSES[][MAX_CAN_BUS_COUNT] = {
- { // message set: example
- { speed: 500000,
- address: 1,
- maxMessageFrequency: 0,
- rawWritable: false,
- passthroughCanMessages: false,
- bypassFilters: false,
- loopback: false
- },
-
- { speed: 125000,
- address: 2,
- maxMessageFrequency: 0,
- rawWritable: false,
- passthroughCanMessages: false,
- bypassFilters: false,
- loopback: false
- },
-
- },
-};
-
-const int MAX_MESSAGE_COUNT = 1;
-CanMessageDefinition CAN_MESSAGES[][MAX_MESSAGE_COUNT] = {
- { // message set: example
- { bus: &CAN_BUSES[0][0], id: 0x128, format: STANDARD, frequencyClock: {0.000000}, forceSendChanged: true}, // ECM_z_5D2
- },
-};
-
-const int MAX_SIGNAL_STATES = 12;
-const int MAX_SIGNALS_WITH_STATES_COUNT = 1;
-const CanSignalState SIGNAL_STATES[][MAX_SIGNALS_WITH_STATES_COUNT][MAX_SIGNAL_STATES] = {
- { // message set: example
- { {value: 1, name: "FIRST"}, {value: 2, name: "SECOND"}, {value: 3, name: "THIRD"}, {value: 4, name: "FOURTH"}, {value: 5, name: "REVERSE"}, {value: 6, name: "NEUTRAL"}, { 0, NULL }, { 0, NULL }, { 0, NULL }, { 0, NULL }, { 0, NULL }, { 0, NULL }, },
- },
-};
-
-const int MAX_SIGNAL_COUNT = 5;
-CanSignal SIGNALS[][MAX_SIGNAL_COUNT] = {
- { // message set: example
- {message: &CAN_MESSAGES[0][0], genericName: "GearshiftPosition", bitPosition: 41, bitSize: 3, factor: 1.000000, offset: 0.000000, minValue: 0.000000, maxValue: 0.000000, frequencyClock: {0.000000}, sendSame: true, forceSendChanged: false, states: SIGNAL_STATES[0][0], stateCount: 6, writable: false, decoder: stateDecoder, encoder: NULL}, // GrshftPos
- {message: &CAN_MESSAGES[0][0], genericName: "SteeringWheelAngle", bitPosition: 52, bitSize: 12, factor: 0.153920, offset: 0.000000, minValue: 0.000000, maxValue: 0.000000, frequencyClock: {0.000000}, sendSame: true, forceSendChanged: false, states: NULL, stateCount: 0, writable: false, decoder: handleUnsignedSteeringWheelAngle, encoder: NULL}, // StrAnglAct
- {message: &CAN_MESSAGES[0][0], genericName: "engine_speed", bitPosition: 12, bitSize: 8, factor: 1.000000, offset: 0.000000, minValue: 0.000000, maxValue: 0.000000, frequencyClock: {15.000000}, sendSame: true, forceSendChanged: false, states: NULL, stateCount: 0, writable: false, decoder: NULL, encoder: NULL}, // EngSpd
- {message: &CAN_MESSAGES[0][0], genericName: "steering_angle_sign", bitPosition: 52, bitSize: 12, factor: 1.000000, offset: 0.000000, minValue: 0.000000, maxValue: 0.000000, frequencyClock: {0.000000}, sendSame: true, forceSendChanged: false, states: NULL, stateCount: 0, writable: false, decoder: ignoreDecoder, encoder: NULL}, // StrAnglSign
- {message: &CAN_MESSAGES[0][0], genericName: "steering_wheel_angle_error", bitPosition: 44, bitSize: 12, factor: 1.000000, offset: 0.000000, minValue: 0.000000, maxValue: 0.000000, frequencyClock: {0.000000}, sendSame: true, forceSendChanged: false, states: NULL, stateCount: 0, writable: false, decoder: ignoreDecoder, encoder: NULL}, // StrAnglErr
- },
-};
-
-void openxc::signals::initialize(openxc::diagnostics::DiagnosticsManager* diagnosticsManager) {
- switch(getConfiguration()->messageSetIndex) {
- case 0: // message set: example
- initializeMyStuff();
- break;
- }
-}
-
-void openxc::signals::loop() {
- switch(getConfiguration()->messageSetIndex) {
- case 0: // message set: example
- myLooper();
- break;
- }
-}
-
-const int MAX_COMMAND_COUNT = 1;
-CanCommand COMMANDS[][MAX_COMMAND_COUNT] = {
- { // message set: example
- { genericName: "turn_signal_status", handler: handleTurnSignalCommand },
- },
-};
-
-void openxc::signals::decodeCanMessage(Pipeline* pipeline, CanBus* bus, CanMessage* message) {
- switch(getConfiguration()->messageSetIndex) {
- case 0: // message set: example
- switch(bus->address) {
- case 1:
- switch (message->id) {
- case 0x128: // ECM_z_5D2
- handleSteeringWheelMessage(message, SIGNALS[0], getSignalCount(), pipeline);
- can::read::translateSignal(&SIGNALS[0][0], message, SIGNALS[0], getSignalCount(), pipeline); // GrshftPos
- can::read::translateSignal(&SIGNALS[0][1], message, SIGNALS[0], getSignalCount(), pipeline); // StrAnglAct
- can::read::translateSignal(&SIGNALS[0][2], message, SIGNALS[0], getSignalCount(), pipeline); // EngSpd
- can::read::translateSignal(&SIGNALS[0][3], message, SIGNALS[0], getSignalCount(), pipeline); // StrAnglSign
- can::read::translateSignal(&SIGNALS[0][4], message, SIGNALS[0], getSignalCount(), pipeline); // StrAnglErr
- break;
- }
- break;
- case 2:
- switch (message->id) {
- }
- break;
- }
- break;
- }
-}
-
-
-CanCommand* openxc::signals::getCommands() {
- return COMMANDS[getActiveMessageSet()->index];
-}
-
-int openxc::signals::getCommandCount() {
- return getActiveMessageSet()->commandCount;
-}
-
-CanMessageDefinition* openxc::signals::getMessages() {
- return CAN_MESSAGES[getActiveMessageSet()->index];
-}
-
-int openxc::signals::getMessageCount() {
- return getActiveMessageSet()->messageCount;
+// <<<<< handlers.cpp <<<<<
+
+application_t::application_t()
+ : can_bus_manager_{utils::config_parser_t{"/etc/dev-mapping.conf"}}
+ , can_message_set_{
+ {std::make_shared<can_message_set_t>(can_message_set_t{0,"example",
+ { // beginning can_message_definition_ vector
+ {std::make_shared<can_message_definition_t>(can_message_definition_t{"hs",0x128,can_message_format_t::STANDARD,frequency_clock_t(5.00000f),true,
+ { // beginning can_signals vector
+ {std::make_shared<can_signal_t> (can_signal_t{
+ "engine_speed",
+ 12,
+ 8,
+ 1.00000f,
+ 0.00000,
+ 0,
+ 0,
+ frequency_clock_t(15.0000f),
+ true,
+ false,
+ {
+ },
+ false,
+ nullptr,
+ nullptr,
+ false
+ })},
+ {std::make_shared<can_signal_t> (can_signal_t{
+ "GearshiftPosition",
+ 41,
+ 3,
+ 1.00000f,
+ 0.00000,
+ 0,
+ 0,
+ frequency_clock_t(0.00000f),
+ true,
+ false,
+ {
+ {1,"FIRST"},
+ {4,"FOURTH"},
+ {6,"NEUTRAL"},
+ {5,"REVERSE"},
+ {2,"SECOND"},
+ {3,"THIRD"}
+ },
+ false,
+ nullptr,
+ nullptr,
+ false
+ })},
+ {std::make_shared<can_signal_t> (can_signal_t{
+ "SteeringWheelAngle",
+ 52,
+ 12,
+ 0.153920f,
+ 0.00000,
+ 0,
+ 0,
+ frequency_clock_t(0.00000f),
+ true,
+ false,
+ {
+ },
+ false,
+ handleUnsignedSteeringWheelAngle,
+ nullptr,
+ false
+ })},
+ {std::make_shared<can_signal_t> (can_signal_t{
+ "steering_wheel_angle_error",
+ 44,
+ 12,
+ 1.00000f,
+ 0.00000,
+ 0,
+ 0,
+ frequency_clock_t(0.00000f),
+ true,
+ false,
+ {
+ },
+ false,
+ ignoreDecoder,
+ nullptr,
+ false
+ })},
+ {std::make_shared<can_signal_t> (can_signal_t{
+ "steering_angle_sign",
+ 52,
+ 12,
+ 1.00000f,
+ 0.00000,
+ 0,
+ 0,
+ frequency_clock_t(0.00000f),
+ true,
+ false,
+ {
+ },
+ false,
+ ignoreDecoder,
+ nullptr,
+ false
+ })}
+ } // end can_signals vector
+ })} // end can_message_definition entry
+
+ }, // end can_message_definition vector
+ { // beginning diagnostic_messages_ vector
+ {std::make_shared<diagnostic_message_t>(diagnostic_message_t{
+ 12,
+ "",
+ 0,
+ 0,
+ UNIT::INVALID,
+ 1.00000f,
+ handleObd2Pid,
+ nullptr,
+ true
+ })}
+, {std::make_shared<diagnostic_message_t>(diagnostic_message_t{
+ 12,
+ "",
+ 0,
+ 0,
+ UNIT::INVALID,
+ 1.00000f,
+ nullptr,
+ nullptr,
+ true
+ })}
+, {std::make_shared<diagnostic_message_t>(diagnostic_message_t{
+ 6,
+ "",
+ 0,
+ 0,
+ UNIT::INVALID,
+ 1.00000f,
+ handleMyDiagRequest,
+ nullptr,
+ true
+ })}
+
+ } // end diagnostic_messages_ vector
+ })} // end can_message_set entry
+ } // end can_message_set vector
+{
+ for(auto& cms: can_message_set_)
+ {
+ std::vector<std::shared_ptr<can_message_definition_t> >& can_messages_definition = cms->get_can_message_definition();
+ for(auto& cmd : can_messages_definition)
+ {
+ cmd->set_parent(cms.get());
+ std::vector<std::shared_ptr<can_signal_t> >& can_signals = cmd->get_can_signals();
+ for(auto& sig: can_signals)
+ {
+ sig->set_parent(cmd.get());
+ }
+ }
+
+ std::vector<std::shared_ptr<diagnostic_message_t> >& diagnostic_messages = cms->get_diagnostic_messages();
+ for(auto& dm : diagnostic_messages)
+ {
+ dm->set_parent(cms.get());
+ }
+ }
+ }
+
+const std::string application_t::get_diagnostic_bus() const
+{
+ return "hs";
}
-CanSignal* openxc::signals::get_can_signals() {
- return SIGNALS[getActiveMessageSet()->index];
-}
-
-int openxc::signals::getSignalCount() {
- return getActiveMessageSet()->signalCount;
-}
-
-CanBus* openxc::signals::getCanBuses() {
- return CAN_BUSES[getActiveMessageSet()->index];
-}
-
-int openxc::signals::getCanBusCount() {
- return getActiveMessageSet()->busCount;
-}
-
-CanMessageSet* openxc::signals::getActiveMessageSet() {
- return &MESSAGE_SETS[getConfiguration()->messageSetIndex];
-}
-
-CanMessageSet* openxc::signals::getMessageSets() {
- return MESSAGE_SETS;
-}
-
-int openxc::signals::getMessageSetCount() {
- return MESSAGE_SET_COUNT;
-}