From e3ed413e06ed6ce4ed273f7a8bafbe63df87b459 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 13 Jul 2021 04:32:41 -0700 Subject: [PATCH] send voltage and heater enable to WBO controller (#2956) * add info send function * fatal if CAN not configured correctly * build * s * 20hz * update wideband firmware Co-authored-by: Matthew Kennedy --- .gitmodules | 1 + firmware/controllers/bench_test.cpp | 2 +- firmware/controllers/can/can.h | 7 ------- firmware/controllers/can/can_rx.cpp | 1 + firmware/controllers/can/can_tx.cpp | 5 +++++ ...{wideband_bootloader.cpp => rusefi_wideband.cpp} | 13 +++++++++++++ firmware/controllers/can/rusefi_wideband.h | 10 ++++++++++ firmware/controllers/can/wideband_firmware | 2 +- firmware/controllers/controllers.mk | 2 +- firmware/init/sensor/init_lambda.cpp | 5 +++++ 10 files changed, 38 insertions(+), 10 deletions(-) rename firmware/controllers/can/{wideband_bootloader.cpp => rusefi_wideband.cpp} (92%) create mode 100644 firmware/controllers/can/rusefi_wideband.h diff --git a/.gitmodules b/.gitmodules index 598e339101..9f8c03774d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -21,6 +21,7 @@ [submodule "firmware/controllers/can/wideband_firmware"] path = firmware/controllers/can/wideband_firmware url = https://github.com/mck1117/wideband + branch = master [submodule "firmware/ext/uzlib"] path = firmware/ext/uzlib url = https://github.com/pfalcon/uzlib diff --git a/firmware/controllers/bench_test.cpp b/firmware/controllers/bench_test.cpp index 7e819fb56c..23fc908f65 100644 --- a/firmware/controllers/bench_test.cpp +++ b/firmware/controllers/bench_test.cpp @@ -46,7 +46,7 @@ #include "microsecond_timer.h" #if EFI_WIDEBAND_FIRMWARE_UPDATE -#include "can.h" +#include "rusefi_wideband.h" #endif // EFI_WIDEBAND_FIRMWARE_UPDATE #if EFI_PROD_CODE diff --git a/firmware/controllers/can/can.h b/firmware/controllers/can/can.h index 4c57661d95..76243e9a5d 100644 --- a/firmware/controllers/can/can.h +++ b/firmware/controllers/can/can.h @@ -45,13 +45,6 @@ void processCanRxMessage(const CANRxFrame& msg, efitick_t nowNt); void registerCanListener(CanListener& listener); void registerCanSensor(CanSensorBase& sensor); -// Indicate that an ack response was received from the wideband bootloader -void handleWidebandBootloaderAck(); -// Update the firmware on any connected wideband controller -void updateWidebandFirmware(); -// Set the CAN index offset of any attached wideband controller -void setWidebandOffset(uint8_t index); - class CanWrite final : public PeriodicController<512> { public: CanWrite(); diff --git a/firmware/controllers/can/can_rx.cpp b/firmware/controllers/can/can_rx.cpp index 5eb49c1d5f..ba3514be10 100644 --- a/firmware/controllers/can/can_rx.cpp +++ b/firmware/controllers/can/can_rx.cpp @@ -59,6 +59,7 @@ bool acceptCanRx(int sid DECLARE_ENGINE_PARAMETER_SUFFIX) { #include "engine.h" #include "can_sensor.h" #include "can_vss.h" +#include "rusefi_wideband.h" /** * this build-in CAN sniffer is very basic but that's our CAN sniffer diff --git a/firmware/controllers/can/can_tx.cpp b/firmware/controllers/can/can_tx.cpp index dacd148c73..341e1a4c34 100644 --- a/firmware/controllers/can/can_tx.cpp +++ b/firmware/controllers/can/can_tx.cpp @@ -17,6 +17,7 @@ #include "obd2.h" #include "can_sensor.h" #include "thread_priority.h" +#include "rusefi_wideband.h" EXTERN_ENGINE; @@ -57,6 +58,10 @@ void CanWrite::PeriodicTask(efitime_t nowNt) { updateDash(cycle); + if (CONFIG(enableAemXSeries) && cycle.isInterval(CI::_50ms)) { + sendWidebandInfo(); + } + cycleCount++; } diff --git a/firmware/controllers/can/wideband_bootloader.cpp b/firmware/controllers/can/rusefi_wideband.cpp similarity index 92% rename from firmware/controllers/can/wideband_bootloader.cpp rename to firmware/controllers/can/rusefi_wideband.cpp index c71ea58ce3..87492c25d2 100644 --- a/firmware/controllers/can/wideband_bootloader.cpp +++ b/firmware/controllers/can/rusefi_wideband.cpp @@ -4,6 +4,8 @@ #include "ch.h" #include "can_msg_tx.h" +#include "rusefi_wideband.h" +#include "sensor.h" // This file contains an array called build_wideband_noboot_bin // This array contains the firmware image for the wideband contoller @@ -119,4 +121,15 @@ void setWidebandOffset(uint8_t index) { waitingBootloaderThread = nullptr; } +void sendWidebandInfo() { + CanTxMessage m(0xEF5'0000, 2, true); + + float vbatt = Sensor::get(SensorType::BatteryVoltage).value_or(0) * 10; + + m[0] = vbatt; + + // TODO: send real enable bit! + m[1] = 0x1; +} + #endif // EFI_WIDEBAND_FIRMWARE_UPDATE && HAL_USE_CAN diff --git a/firmware/controllers/can/rusefi_wideband.h b/firmware/controllers/can/rusefi_wideband.h new file mode 100644 index 0000000000..5480646d10 --- /dev/null +++ b/firmware/controllers/can/rusefi_wideband.h @@ -0,0 +1,10 @@ +#pragma once + +// Indicate that an ack response was received from the wideband bootloader +void handleWidebandBootloaderAck(); +// Update the firmware on any connected wideband controller +void updateWidebandFirmware(); +// Set the CAN index offset of any attached wideband controller +void setWidebandOffset(uint8_t index); +// Send info to the wideband controller like battery voltage, heater enable bit, etc. +void sendWidebandInfo(); diff --git a/firmware/controllers/can/wideband_firmware b/firmware/controllers/can/wideband_firmware index 158be23b57..902be081e7 160000 --- a/firmware/controllers/can/wideband_firmware +++ b/firmware/controllers/can/wideband_firmware @@ -1 +1 @@ -Subproject commit 158be23b578423328eb3ab5907eb09698f2359f0 +Subproject commit 902be081e7c8f89516edc133aada5564abcb9bff diff --git a/firmware/controllers/controllers.mk b/firmware/controllers/controllers.mk index 83e6285e2d..be15d60d6e 100644 --- a/firmware/controllers/controllers.mk +++ b/firmware/controllers/controllers.mk @@ -45,7 +45,7 @@ CONTROLLERS_SRC_CPP = \ $(CONTROLLERS_DIR)/can/obd2.cpp \ $(CONTROLLERS_DIR)/can/can_verbose.cpp \ $(CONTROLLERS_DIR)/can/can_rx.cpp \ - $(CONTORLLERS_DIR)/can/wideband_bootloader.cpp \ + $(CONTORLLERS_DIR)/can/rusefi_wideband.cpp \ $(CONTROLLERS_DIR)/can/can_tx.cpp \ $(CONTROLLERS_DIR)/can/can_dash.cpp \ $(CONTROLLERS_DIR)/can/can_vss.cpp \ diff --git a/firmware/init/sensor/init_lambda.cpp b/firmware/init/sensor/init_lambda.cpp index f1f22aa5fe..723a4cee54 100644 --- a/firmware/init/sensor/init_lambda.cpp +++ b/firmware/init/sensor/init_lambda.cpp @@ -34,6 +34,11 @@ void initLambda(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #if EFI_CAN_SUPPORT if (CONFIG(enableAemXSeries)) { + if (!CONFIG(canWriteEnabled) || !CONFIG(canReadEnabled)) { + firmwareError(OBD_PCM_Processor_Fault, "CAN read and write are required to use CAN wideband."); + return; + } + registerCanSensor(aem1); registerCanSensor(aem2);