Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions SilKit/source/services/lin/LinController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
}

Expand Down Expand Up @@ -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{};
Expand Down
12 changes: 12 additions & 0 deletions SilKit/source/services/lin/Test_LinControllerTrivialSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
////////////
Expand Down
4 changes: 3 additions & 1 deletion docs/changelog/versions/latest.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# [5.0.9] - UNRELEASED

> This changelog entry is still empty.
## Fixed

- LIN: `SendDynamicResponse` now throws a `SilKit::StateError`, as documented, if the controller was not initialized using `InitDynamic`. Previously, the call was silently processed.
Loading