diff --git a/Demos/communication/Lin/LinMasterDemo.cpp b/Demos/communication/Lin/LinMasterDemo.cpp index eef858e12..46784a019 100644 --- a/Demos/communication/Lin/LinMasterDemo.cpp +++ b/Demos/communication/Lin/LinMasterDemo.cpp @@ -104,14 +104,6 @@ class LinMaster : public ApplicationBase { const auto linId{static_cast(linFrame.id)}; - if (_linController->Status() != LinControllerStatus::Operational) - { - std::stringstream ss; - ss << "LIN Frame with ID=" << linId << " not sent, since the controller is not operational"; - GetLogger()->Warn(ss.str()); - return; - } - _linController->SendFrame(linFrame, responseType); std::stringstream ss; diff --git a/SilKit/IntegrationTests/ITest_NetSimLin.cpp b/SilKit/IntegrationTests/ITest_NetSimLin.cpp index d0fa28d65..3a5f4f3dc 100644 --- a/SilKit/IntegrationTests/ITest_NetSimLin.cpp +++ b/SilKit/IntegrationTests/ITest_NetSimLin.cpp @@ -557,8 +557,8 @@ TEST_F(ITest_NetSimLin, networksimulation_lin_dynamic) { SendLinFrames(now, linController, callCounts.silKitSentMsgLin.SentFramesTrivial); SendLinFrameHeaders(now, linController, callCounts.silKitSentMsgLin.SentFrameHeadersTrivial); - WakeupOnce(now, linController); GoToSleepOnce(now, linController); + WakeupOnce(now, linController); } }, _stepSize); diff --git a/SilKit/source/services/lin/LinController.cpp b/SilKit/source/services/lin/LinController.cpp index 67c980962..3952f7eab 100644 --- a/SilKit/source/services/lin/LinController.cpp +++ b/SilKit/source/services/lin/LinController.cpp @@ -180,88 +180,77 @@ void LinController::ThrowIfNotConfiguredTxUnconditional(LinId linId) void LinController::WarnOnWrongDataLength(const LinFrame& receivedFrame, const LinFrame& configuredFrame) const { - std::string errorMsg = - fmt::format("Mismatch between configured ({}) and received ({}) LinDataLength in LinFrame with ID {}", - configuredFrame.dataLength, receivedFrame.dataLength, static_cast(receivedFrame.id)); - _logger->Warn(errorMsg); + Logging::Warn(_logger, "Mismatch between configured ({}) and received ({}) LinDataLength in LinFrame with ID {}", + configuredFrame.dataLength, receivedFrame.dataLength, static_cast(receivedFrame.id)); } void LinController::WarnOnWrongChecksum(const LinFrame& receivedFrame, const LinFrame& configuredFrame) const { - std::string errorMsg = fmt::format( - "Mismatch between configured ({}) and received ({}) LinChecksumModel in LinFrame with ID {}", - configuredFrame.checksumModel, receivedFrame.checksumModel, static_cast(receivedFrame.id)); - _logger->Warn(errorMsg); + Logging::Warn(_logger, "Mismatch between configured ({}) and received ({}) LinChecksumModel in LinFrame with ID {}", + configuredFrame.checksumModel, receivedFrame.checksumModel, static_cast(receivedFrame.id)); } void LinController::WarnOnReceptionWithInvalidDataLength(LinDataLength invalidDataLength, const std::string& fromParticipantName, const std::string& fromServiceName) const { - std::string errorMsg = - fmt::format("LinController received transmission with invalid payload length {} from {{{}, {}}}. This " - "tranmission is ignored.", - static_cast(invalidDataLength), fromParticipantName, fromServiceName); - _logger->Warn(errorMsg); + Logging::Warn(_logger, + "LinController received transmission with invalid payload length {} from {{{}, {}}}. This " + "tranmission is ignored.", + static_cast(invalidDataLength), fromParticipantName, fromServiceName); } void LinController::WarnOnReceptionWithInvalidLinId(LinId invalidLinId, const std::string& fromParticipantName, const std::string& fromServiceName) const { - std::string errorMsg = fmt::format( + Logging::Warn( + _logger, "LinController received transmission with invalid LIN ID {} from {{{}, {}}}. This transmission is ignored.", static_cast(invalidLinId), fromParticipantName, fromServiceName); - _logger->Warn(errorMsg); } -void LinController::WarnOnReceptionWhileInactive() const +void LinController::WarnOnReceptionWhileInactive(const LinTransmission& msg) const { - std::string errorMsg = fmt::format("Inactive LinController received a transmission. This transmission is ignored."); - _logger->Warn(errorMsg); + Logging::Warn(_logger, "Inactive LinController received a transmission ({}). This transmission is ignored.", msg); +} + +void LinController::WarnOnReceptionWhileSleeping() const +{ + Logging::Warn(_logger, "Sleeping LinController received a transmission. This transmission is ignored!"); } void LinController::WarnOnUnneededStatusChange(LinControllerStatus status) const { - std::string errorMsg = - fmt::format("Invalid LinController status change: controller is already in {} mode.", status); - _logger->Warn(errorMsg); + Logging::Warn(_logger, "Invalid LinController status change: controller is already in {} mode.", status); } void LinController::WarnOnInvalidLinId(LinId invalidLinId, const std::string& callingMethodName) const { - std::string errorMsg = - fmt::format("Invalid ID={} in call to '{}'", static_cast(invalidLinId), callingMethodName); - _logger->Warn(errorMsg); + Logging::Warn(_logger, "Invalid ID={} in call to '{}'", static_cast(invalidLinId), callingMethodName); } void LinController::WarnOnUnusedResponseMode(const std::string& callingMethodName) const { - std::string errorMsg = - fmt::format("LinFrameResponseMode::Unused is not allowed in call to '{}'.", callingMethodName); - _logger->Warn(errorMsg); + Logging::Warn(_logger, "LinFrameResponseMode::Unused is not allowed in call to '{}'.", callingMethodName); } void LinController::WarnOnResponseModeReconfiguration(LinId id, LinFrameResponseMode currentResponseMode) const { - std::string errorMsg = - fmt::format("Can't set response mode for ID={}. Mode is already configured to {}.", id, currentResponseMode); - _logger->Warn(errorMsg); + Logging::Warn(_logger, "Can't set response mode for ID={}. Mode is already configured to {}.", id, currentResponseMode); } void LinController::WarnOnUnconfiguredSlaveResponse(LinId id) const { - std::string errorMsg = fmt::format("No slave has configured a response for ID={}. Use Init() or SetFrameResponse() " - "on the slave node to configure responses.", - id); - _logger->Warn(errorMsg); + Logging::Warn(_logger, + "No slave has configured a response for ID={}. Use Init() or SetFrameResponse() on the slave node to " + "configure responses.", + id); } void LinController::WarnOnSendFrameSlaveResponseWithMasterTx(LinId id) const { - std::string errorMsg = - fmt::format("Master has already configured a response on ID={}. Ignoring this call to SendFrame()", id); - _logger->Warn(errorMsg); + Logging::Warn(_logger, "Master has already configured a response on ID={}. Ignoring this call to SendFrame()", id); } void LinController::ThrowOnSendAttemptWithUndefinedChecksum(const LinFrame& frame) const @@ -752,7 +741,13 @@ void LinController::ReceiveMsg(const IServiceEndpoint* from, const LinTransmissi if (_controllerMode == LinControllerMode::Inactive) { - WarnOnReceptionWhileInactive(); + WarnOnReceptionWhileInactive(msg); + return; + } + + if(_controllerStatus == LinControllerStatus::Sleep || _controllerStatus == LinControllerStatus::Unknown) + { + WarnOnReceptionWhileSleeping(); return; } diff --git a/SilKit/source/services/lin/LinController.hpp b/SilKit/source/services/lin/LinController.hpp index 5313c2534..ee4a72095 100644 --- a/SilKit/source/services/lin/LinController.hpp +++ b/SilKit/source/services/lin/LinController.hpp @@ -186,7 +186,8 @@ class LinController const std::string& fromServiceName) const; void WarnOnReceptionWithInvalidLinId(LinId invalidLinId, const std::string& fromParticipantName, const std::string& fromServiceName) const; - void WarnOnReceptionWhileInactive() const; + void WarnOnReceptionWhileInactive(const LinTransmission& msg) const; + void WarnOnReceptionWhileSleeping() const; void WarnOnUnneededStatusChange(LinControllerStatus status) const; void WarnOnInvalidLinId(LinId invalidLinId, const std::string& callingMethodName) const; void WarnOnUnusedResponseMode(const std::string& callingMethodName) const; diff --git a/SilKit/source/services/lin/SimBehaviorTrivial.cpp b/SilKit/source/services/lin/SimBehaviorTrivial.cpp index ac31fc09e..89c14e49f 100644 --- a/SilKit/source/services/lin/SimBehaviorTrivial.cpp +++ b/SilKit/source/services/lin/SimBehaviorTrivial.cpp @@ -5,6 +5,7 @@ #include "LinController.hpp" #include "SimBehaviorTrivial.hpp" #include "Assert.hpp" +#include "LoggerMessage.hpp" namespace SilKit { namespace Services { @@ -88,11 +89,25 @@ void SimBehaviorTrivial::SendMsgImpl(MsgT&& msg) void SimBehaviorTrivial::SendMsg(LinSendFrameRequest&& msg) { + auto controllerStatus = _parentController->Status(); + if(controllerStatus == LinControllerStatus::Sleep || controllerStatus == LinControllerStatus::Unknown) + { + Logging::Warn(_participant->GetLogger(), + "LinController not operational. SendFrameRequest will not be sent!"); + return; + } _parentController->SendFrameHeader(msg.frame.id); } void SimBehaviorTrivial::SendMsg(LinTransmission&& msg) { + auto controllerStatus = _parentController->Status(); + if(controllerStatus == LinControllerStatus::Sleep || controllerStatus == LinControllerStatus::Unknown) + { + Logging::Warn(_participant->GetLogger(), + "LinController not operational. LinTransmission will not be sent!"); + return; + } SendMsgImpl(msg); } diff --git a/docs/changelog/versions/latest.md b/docs/changelog/versions/latest.md index 3fa895aaf..00304ab50 100644 --- a/docs/changelog/versions/latest.md +++ b/docs/changelog/versions/latest.md @@ -4,3 +4,4 @@ - `demos`: improved code quality - `pubsub` / `rpc`: fix some edge cases when matching labels +- `Lin controller`: fixed TX/RX behaviour when controller is not operational