1 /* DO NOT MODIFY: This source is generated by the scripts in the
2 * vi-firmware repository.
4 * Generated for v7.x of the OpenXC VI firmware.
7 #include "diagnostics.h"
8 #include "can/canread.h"
9 #include "can/canwrite.h"
14 #include "shared_handlers.h"
16 namespace can = openxc::can;
18 using openxc::util::log::debug;
19 using openxc::pipeline::Pipeline;
20 using openxc::config::getConfiguration;
21 using openxc::can::read::booleanDecoder;
22 using openxc::can::read::stateDecoder;
23 using openxc::can::read::ignoreDecoder;
24 using openxc::diagnostics::obd2::handleObd2Pid;
25 using namespace openxc::signals::handlers;
27 #include "can/canread.h"
29 using openxc::can::read::publishNumericalMessage;
31 void handleSteeringWheelMessage(CanMessage* message,
32 CanSignal* signals, int signalCount, Pipeline* pipeline) {
33 publishNumericalMessage("latitude", 42.0, pipeline);
36 openxc_DynamicField handleInverted(CanSignal* signal, CanSignal* signals,
37 int signalCount, float value, bool* send) {
38 return openxc::payload::wrapNumber(value * -1);
41 void initializeMyStuff() { }
43 void initializeOtherStuff() { }
46 // this function will be called once each time through the main loop, after
47 // all CAN message processing has been completed
50 const int MESSAGE_SET_COUNT = 1;
51 CanMessageSet MESSAGE_SETS[MESSAGE_SET_COUNT] = {
52 { 0, "example", 2, 1, 5, 1 },
55 const int MAX_CAN_BUS_COUNT = 2;
56 CanBus CAN_BUSES[][MAX_CAN_BUS_COUNT] = {
57 { // message set: example
60 maxMessageFrequency: 0,
62 passthroughCanMessages: false,
69 maxMessageFrequency: 0,
71 passthroughCanMessages: false,
79 const int MAX_MESSAGE_COUNT = 1;
80 CanMessageDefinition CAN_MESSAGES[][MAX_MESSAGE_COUNT] = {
81 { // message set: example
82 { bus: &CAN_BUSES[0][0], id: 0x128, format: STANDARD, frequencyClock: {0.000000}, forceSendChanged: true}, // ECM_z_5D2
86 const int MAX_SIGNAL_STATES = 12;
87 const int MAX_SIGNALS_WITH_STATES_COUNT = 1;
88 const CanSignalState SIGNAL_STATES[][MAX_SIGNALS_WITH_STATES_COUNT][MAX_SIGNAL_STATES] = {
89 { // message set: example
90 { {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 }, },
94 const int MAX_SIGNAL_COUNT = 5;
95 CanSignal SIGNALS[][MAX_SIGNAL_COUNT] = {
96 { // message set: example
97 {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
98 {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
99 {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
100 {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
101 {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
105 void openxc::signals::initialize(openxc::diagnostics::DiagnosticsManager* diagnosticsManager) {
106 switch(getConfiguration()->messageSetIndex) {
107 case 0: // message set: example
113 void openxc::signals::loop() {
114 switch(getConfiguration()->messageSetIndex) {
115 case 0: // message set: example
121 const int MAX_COMMAND_COUNT = 1;
122 CanCommand COMMANDS[][MAX_COMMAND_COUNT] = {
123 { // message set: example
124 { genericName: "turn_signal_status", handler: handleTurnSignalCommand },
128 void openxc::signals::decodeCanMessage(Pipeline* pipeline, CanBus* bus, CanMessage* message) {
129 switch(getConfiguration()->messageSetIndex) {
130 case 0: // message set: example
131 switch(bus->address) {
133 switch (message->id) {
134 case 0x128: // ECM_z_5D2
135 handleSteeringWheelMessage(message, SIGNALS[0], getSignalCount(), pipeline);
136 can::read::translateSignal(&SIGNALS[0][0], message, SIGNALS[0], getSignalCount(), pipeline); // GrshftPos
137 can::read::translateSignal(&SIGNALS[0][1], message, SIGNALS[0], getSignalCount(), pipeline); // StrAnglAct
138 can::read::translateSignal(&SIGNALS[0][2], message, SIGNALS[0], getSignalCount(), pipeline); // EngSpd
139 can::read::translateSignal(&SIGNALS[0][3], message, SIGNALS[0], getSignalCount(), pipeline); // StrAnglSign
140 can::read::translateSignal(&SIGNALS[0][4], message, SIGNALS[0], getSignalCount(), pipeline); // StrAnglErr
145 switch (message->id) {
154 CanCommand* openxc::signals::getCommands() {
155 return COMMANDS[getActiveMessageSet()->index];
158 int openxc::signals::getCommandCount() {
159 return getActiveMessageSet()->commandCount;
162 CanMessageDefinition* openxc::signals::getMessages() {
163 return CAN_MESSAGES[getActiveMessageSet()->index];
166 int openxc::signals::getMessageCount() {
167 return getActiveMessageSet()->messageCount;
170 CanSignal* openxc::signals::getSignals() {
171 return SIGNALS[getActiveMessageSet()->index];
174 int openxc::signals::getSignalCount() {
175 return getActiveMessageSet()->signalCount;
178 CanBus* openxc::signals::getCanBuses() {
179 return CAN_BUSES[getActiveMessageSet()->index];
182 int openxc::signals::getCanBusCount() {
183 return getActiveMessageSet()->busCount;
186 CanMessageSet* openxc::signals::getActiveMessageSet() {
187 return &MESSAGE_SETS[getConfiguration()->messageSetIndex];
190 CanMessageSet* openxc::signals::getMessageSets() {
194 int openxc::signals::getMessageSetCount() {
195 return MESSAGE_SET_COUNT;