From 8a3e47d9e6708ecb57359996091a50b455cd72c4 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 29 Mar 2020 21:15:06 -0400 Subject: [PATCH] refactoring + MAP broadcast consumption --- firmware/controllers/algo/engine_configuration.cpp | 2 +- firmware/controllers/can/can.h | 3 +++ firmware/controllers/can/can_rx.cpp | 8 ++++++-- firmware/controllers/can/can_verbose.cpp | 5 +++-- firmware/integration/rusefi_config.txt | 2 ++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index fc8d054f52..ab1dd6c7da 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -681,7 +681,7 @@ static void setDefaultEngineConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) { engineConfiguration->canNbcType = CAN_BUS_MAZDA_RX8; // Don't enable, but set default address - engineConfiguration->verboseCanBaseAddress = 0x200; + engineConfiguration->verboseCanBaseAddress = CAN_DEFAULT_BASE; engineConfiguration->sdCardPeriodMs = 50; diff --git a/firmware/controllers/can/can.h b/firmware/controllers/can/can.h index 261176de79..2477b49cae 100644 --- a/firmware/controllers/can/can.h +++ b/firmware/controllers/can/can.h @@ -11,6 +11,9 @@ #include "periodic_thread_controller.h" +#define CAN_PEDAL_TPS_OFFSET 2 +#define CAN_SENSOR_1_OFFSET 3 + class Logging; void processCanRxMessage(const CANRxFrame& msg, Logging* logger); diff --git a/firmware/controllers/can/can_rx.cpp b/firmware/controllers/can/can_rx.cpp index f0e7cb057b..57023a252f 100644 --- a/firmware/controllers/can/can_rx.cpp +++ b/firmware/controllers/can/can_rx.cpp @@ -27,6 +27,7 @@ static void printPacket(const CANRxFrame& rx, Logging* logger) { volatile float aemXSeriesLambda = 0; volatile float canPedal = 0; +volatile float canMap = 0; void processCanRxMessage(const CANRxFrame& frame, Logging* logger) { // TODO: if/when we support multiple lambda sensors, sensor N @@ -35,9 +36,12 @@ void processCanRxMessage(const CANRxFrame& frame, Logging* logger) { // AEM x-series lambda sensor reports in 0.0001 lambda per bit uint16_t lambdaInt = SWAP_UINT16(frame.data16[0]); aemXSeriesLambda = 0.0001f * lambdaInt; - } else if (frame.EID == 0x202) { + } else if (frame.EID == CONFIG(verboseCanBaseAddress) + CAN_PEDAL_TPS_OFFSET) { int16_t pedalScaled = *reinterpret_cast(&frame.data8[0]); - canPedal = pedalScaled * 0.01f; + canPedal = pedalScaled / (1.0 * PACK_MULT_PERCENT); + } else if (frame.EID == CONFIG(verboseCanBaseAddress) + CAN_SENSOR_1_OFFSET) { + int16_t mapScaled = *reinterpret_cast(&frame.data8[0]); + canMap = mapScaled / (1.0 * PACK_MULT_PRESSURE); } else { printPacket(frame, logger); obdOnCanPacketRx(frame); diff --git a/firmware/controllers/can/can_verbose.cpp b/firmware/controllers/can/can_verbose.cpp index 9d3aa852ec..fc8e9e7417 100644 --- a/firmware/controllers/can/can_verbose.cpp +++ b/firmware/controllers/can/can_verbose.cpp @@ -7,6 +7,7 @@ #include "scaled_channel.h" #include "can_msg_tx.h" #include "sensor.h" +#include "can.h" #include "allsensors.h" #include "fuel_math.h" #include "spark_logic.h" @@ -137,8 +138,8 @@ void sendCanVerbose() { transmitStruct (base + 0); transmitStruct (base + 1); - transmitStruct (base + 2); - transmitStruct (base + 3); + transmitStruct (base + CAN_PEDAL_TPS_OFFSET); + transmitStruct (base + CAN_SENSOR_1_OFFSET); transmitStruct (base + 4); transmitStruct (base + 5); } diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index c29a809233..6948176437 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -124,6 +124,8 @@ struct_no_prefix engine_configuration_s #define BOOST_LOAD_COUNT 8 #define PEDAL_TO_TPS_SIZE 8 +#define CAN_DEFAULT_BASE 0x200 + ! ! all the xxx_PACKING_xxx constants are about persisting tables in compact for, for example packing RPM with 50 increment in a byte