From 4b64e0e08790dd3ccda781ce15bd739cc1083f6e Mon Sep 17 00:00:00 2001 From: Stefan de Kraker <61704774+krakert@users.noreply.github.com> Date: Mon, 30 Oct 2023 21:42:52 -0400 Subject: [PATCH] Fixed CAN data bus selection * Fixed CAN data bus selection * Made canChannel non-optional --- firmware/controllers/can/can_dash.cpp | 18 ++++++++++-------- firmware/controllers/can/can_dash_ms.cpp | 11 ++++++----- firmware/controllers/can/can_verbose.cpp | 21 +++++++++++---------- firmware/hw_layer/drivers/can/can_msg_tx.h | 6 +++--- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/firmware/controllers/can/can_dash.cpp b/firmware/controllers/can/can_dash.cpp index 75d6e981b3..e77655590e 100644 --- a/firmware/controllers/can/can_dash.cpp +++ b/firmware/controllers/can/can_dash.cpp @@ -1246,14 +1246,16 @@ void canDashboardAim(CanCycle cycle) { return; } - transmitStruct(CanCategory::NBC, 0x5f0, false); - transmitStruct(CanCategory::NBC, 0x5f1, false); - transmitStruct(CanCategory::NBC, 0x5f2, false); - transmitStruct(CanCategory::NBC, 0x5f3, false); - transmitStruct(CanCategory::NBC, 0x5f4, false); - transmitStruct(CanCategory::NBC, 0x5f5, false); - transmitStruct(CanCategory::NBC, 0x5f6, false); - transmitStruct(CanCategory::NBC, 0x5f7, false); + auto canChannel = engineConfiguration->canBroadcastUseChannelTwo; + + transmitStruct(CanCategory::NBC, 0x5f0, false, canChannel); + transmitStruct(CanCategory::NBC, 0x5f1, false, canChannel); + transmitStruct(CanCategory::NBC, 0x5f2, false, canChannel); + transmitStruct(CanCategory::NBC, 0x5f3, false, canChannel); + transmitStruct(CanCategory::NBC, 0x5f4, false, canChannel); + transmitStruct(CanCategory::NBC, 0x5f5, false, canChannel); + transmitStruct(CanCategory::NBC, 0x5f6, false, canChannel); + transmitStruct(CanCategory::NBC, 0x5f7, false, canChannel); // there are more, but less important for us // transmitStruct(0x5f8, false); diff --git a/firmware/controllers/can/can_dash_ms.cpp b/firmware/controllers/can/can_dash_ms.cpp index adaf3d77ee..98b64426f2 100644 --- a/firmware/controllers/can/can_dash_ms.cpp +++ b/firmware/controllers/can/can_dash_ms.cpp @@ -120,11 +120,12 @@ void canDashboardTS(CanCycle cycle) { return; } - transmitStruct(CanCategory::NBC, baseId + 0, false); - transmitStruct(CanCategory::NBC, baseId + 1, false); - transmitStruct(CanCategory::NBC, baseId + 2, false); - transmitStruct(CanCategory::NBC, baseId + 3, false); - transmitStruct(CanCategory::NBC, baseId + 4, false); + bool busIndex = 0; + transmitStruct(CanCategory::NBC, baseId + 0, false, busIndex); + transmitStruct(CanCategory::NBC, baseId + 1, false, busIndex); + transmitStruct(CanCategory::NBC, baseId + 2, false, busIndex); + transmitStruct(CanCategory::NBC, baseId + 3, false, busIndex); + transmitStruct(CanCategory::NBC, baseId + 4, false, busIndex); } #endif /* EFI_CAN_SUPPORT */ diff --git a/firmware/controllers/can/can_verbose.cpp b/firmware/controllers/can/can_verbose.cpp index 5997fb76d6..ffc967c0ca 100644 --- a/firmware/controllers/can/can_verbose.cpp +++ b/firmware/controllers/can/can_verbose.cpp @@ -216,17 +216,18 @@ static void populateFrame(Odometry& msg) { void sendCanVerbose() { auto base = engineConfiguration->verboseCanBaseAddress; auto isExt = engineConfiguration->rusefiVerbose29b; + auto canChannel = engineConfiguration->canBroadcastUseChannelTwo; - transmitStruct (CanCategory::VERBOSE, base + 0, isExt); - transmitStruct (CanCategory::VERBOSE, base + 1, isExt); - transmitStruct (CanCategory::VERBOSE, base + CAN_PEDAL_TPS_OFFSET, isExt); - transmitStruct (CanCategory::VERBOSE, base + CAN_SENSOR_1_OFFSET, isExt); - transmitStruct (CanCategory::VERBOSE, base + 4, isExt); - transmitStruct (CanCategory::VERBOSE, base + 5, isExt); - transmitStruct (CanCategory::VERBOSE, base + 6, isExt); - transmitStruct (CanCategory::VERBOSE, base + 7, isExt); - transmitStruct (CanCategory::VERBOSE, base + 8, isExt); - transmitStruct (CanCategory::VERBOSE, base + 9, isExt); + transmitStruct (CanCategory::VERBOSE, base + 0, isExt, canChannel); + transmitStruct (CanCategory::VERBOSE, base + 1, isExt, canChannel); + transmitStruct (CanCategory::VERBOSE, base + CAN_PEDAL_TPS_OFFSET, isExt, canChannel); + transmitStruct (CanCategory::VERBOSE, base + CAN_SENSOR_1_OFFSET, isExt, canChannel); + transmitStruct (CanCategory::VERBOSE, base + 4, isExt, canChannel); + transmitStruct (CanCategory::VERBOSE, base + 5, isExt, canChannel); + transmitStruct (CanCategory::VERBOSE, base + 6, isExt, canChannel); + transmitStruct (CanCategory::VERBOSE, base + 7, isExt, canChannel); + transmitStruct (CanCategory::VERBOSE, base + 8, isExt, canChannel); + transmitStruct (CanCategory::VERBOSE, base + 9, isExt, canChannel); } #endif // EFI_CAN_SUPPORT diff --git a/firmware/hw_layer/drivers/can/can_msg_tx.h b/firmware/hw_layer/drivers/can/can_msg_tx.h index d6f399915e..31beee85ce 100644 --- a/firmware/hw_layer/drivers/can/can_msg_tx.h +++ b/firmware/hw_layer/drivers/can/can_msg_tx.h @@ -94,7 +94,7 @@ class CanTxTyped final : public CanTxMessage #endif // EFI_CAN_SUPPORT public: - explicit CanTxTyped(CanCategory category, uint32_t id, bool isExtended) : CanTxMessage(category, id, sizeof(TData), isExtended) { } + explicit CanTxTyped(CanCategory category, uint32_t id, bool isExtended, bool canChannel) : CanTxMessage(category, id, sizeof(TData), isExtended) { } #if EFI_CAN_SUPPORT /** @@ -115,9 +115,9 @@ public: }; template -void transmitStruct(CanCategory category, uint32_t id, bool isExtended) +void transmitStruct(CanCategory category, uint32_t id, bool isExtended, bool canChannel) { - CanTxTyped frame(category, id, isExtended); + CanTxTyped frame(category, id, isExtended, canChannel); // Destruction of an instance of CanTxMessage will transmit the message over the wire. // see CanTxMessage::~CanTxMessage() populateFrame(frame.get());