From ac7b2d51065a95548844c41d4b35a314ad80a878 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Mon, 17 Jan 2022 00:16:47 -0500 Subject: [PATCH] FlexRay: Automatically reconfigure for runtime-added message buffers --- device/extensions/flexray/controller.cpp | 19 ++++++++++++++++++- .../device/extensions/flexray/controller.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/device/extensions/flexray/controller.cpp b/device/extensions/flexray/controller.cpp index 0c5336a..da13f37 100644 --- a/device/extensions/flexray/controller.cpp +++ b/device/extensions/flexray/controller.cpp @@ -436,6 +436,10 @@ bool FlexRay::Controller::transmit(const std::shared_ptr& frmsg) if(frmsg->channel != bufChannel) continue; + // If we have added changed our configuration, such as adding a message buffer, we will need to reconfigure + if(configDirty && lastSeenRunning) + start(); + // This is a message buffer we want to fill if(!device.com->sendCommand(Command::FlexRayControl, FlexRayControlMessage::BuildWriteMessageBufferArgs(index, buf->_id, frmsg->data, buf->frameLengthBytes))) continue; @@ -474,7 +478,20 @@ bool FlexRay::Controller::setCurrentPOCCommand(FlexRay::POCCommand cmd, bool che const auto writeDuration = std::chrono::steady_clock::now() - beforeWrite; timeout = std::chrono::duration_cast(timeout - writeDuration); - return wasCommandSuccessful(timeout); + const bool success = wasCommandSuccessful(timeout); + if(success) { + switch(cmd) { + case FlexRay::POCCommand::Run: + lastSeenRunning = true; + break; + case FlexRay::POCCommand::Halt: + case FlexRay::POCCommand::Freeze: + lastSeenRunning = false; + break; + default: break; + } + } + return success; } bool FlexRay::Controller::wasCommandSuccessful(std::chrono::milliseconds timeout) const { diff --git a/include/icsneo/device/extensions/flexray/controller.h b/include/icsneo/device/extensions/flexray/controller.h index a72a812..43e6216 100644 --- a/include/icsneo/device/extensions/flexray/controller.h +++ b/include/icsneo/device/extensions/flexray/controller.h @@ -108,6 +108,7 @@ private: bool startWhenGoingOnline = false; bool allowColdstart = false; bool wakeupBeforeStart = false; + bool lastSeenRunning = false; public: #define neoflexray_controller_config_t icsneo::FlexRay::Controller::Configuration