diff --git a/SilKit/source/services/lin/LinController.cpp b/SilKit/source/services/lin/LinController.cpp index b96ff82c2..d0419c526 100644 --- a/SilKit/source/services/lin/LinController.cpp +++ b/SilKit/source/services/lin/LinController.cpp @@ -161,13 +161,13 @@ void LinController::ThrowIfDynamic(const std::string& callingMethodName) const void LinController::ThrowIfNotDynamic(const std::string& callingMethodName) const { - if (_useDynamicResponse) + if (!_useDynamicResponse) { std::string errorMsg = callingMethodName + " can only be called if the node was initialized using InitDynamic!"; _logger->MakeMessage(Logging::Level::Error, TopicOf(*this)) .SetMessage(errorMsg) .Dispatch(); - throw SilKitError{errorMsg}; + throw SilKit::StateError{errorMsg}; } } @@ -372,10 +372,7 @@ void LinController::InitDynamic(const SilKit::Experimental::Services::Lin::LinCo void LinController::SendDynamicResponse(const LinFrame& frame) { - if (!_useDynamicResponse) - { - ThrowIfNotDynamic(__FUNCTION__); - } + ThrowIfNotDynamic(__FUNCTION__); // prepare the response update LinFrameResponse response{}; diff --git a/SilKit/source/services/lin/Test_LinControllerTrivialSim.cpp b/SilKit/source/services/lin/Test_LinControllerTrivialSim.cpp index 2b0abb498..bdfa65a51 100644 --- a/SilKit/source/services/lin/Test_LinControllerTrivialSim.cpp +++ b/SilKit/source/services/lin/Test_LinControllerTrivialSim.cpp @@ -811,6 +811,18 @@ TEST_F(Test_LinControllerTrivialSim, add_remove_handler) master.ReceiveMsg(&slave1, transmission); } +// SendDynamicResponse throws a StateError if the controller was not initialized using InitDynamic, including when it +// was not initialized at all. +TEST_F(Test_LinControllerTrivialSim, send_dynamic_response_throws_if_not_dynamic) +{ + const auto frame = MakeFrame(17, LinChecksumModel::Enhanced, 4); + + EXPECT_THROW(master.SendDynamicResponse(frame), SilKit::StateError); + + master.Init(MakeControllerConfig(LinControllerMode::Master)); + EXPECT_THROW(master.SendDynamicResponse(frame), SilKit::StateError); +} + //////////// // Tracing //////////// diff --git a/docs/changelog/versions/latest.md b/docs/changelog/versions/latest.md index cc47f4d97..e4df93e85 100644 --- a/docs/changelog/versions/latest.md +++ b/docs/changelog/versions/latest.md @@ -1,3 +1,5 @@ # [5.0.9] - UNRELEASED -> This changelog entry is still empty. \ No newline at end of file +## Fixed + +- LIN: `SendDynamicResponse` now throws a `SilKit::StateError`, as documented, if the controller was not initialized using `InitDynamic`. Previously, the call was silently processed.