Skip to content

Commit 6ed9b9c

Browse files
LinController: fix tx/rx trivial behaviour (#301)
When not operational, the lin controller should not be able to send frames without waking up/going into operational state first. This fixes this issue for the trivial behaviour case (No Netsim attached) Issues: SILKIT-1468 Signed-off-by: Jan Kraemer <jan.kraemer@vector.com> Co-authored-by: Marius Börschig <Marius.Boerschig@vector.com>
1 parent 0130846 commit 6ed9b9c

6 files changed

Lines changed: 52 additions & 48 deletions

File tree

Demos/communication/Lin/LinMasterDemo.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,6 @@ class LinMaster : public ApplicationBase
104104
{
105105
const auto linId{static_cast<unsigned>(linFrame.id)};
106106

107-
if (_linController->Status() != LinControllerStatus::Operational)
108-
{
109-
std::stringstream ss;
110-
ss << "LIN Frame with ID=" << linId << " not sent, since the controller is not operational";
111-
GetLogger()->Warn(ss.str());
112-
return;
113-
}
114-
115107
_linController->SendFrame(linFrame, responseType);
116108

117109
std::stringstream ss;

SilKit/IntegrationTests/ITest_NetSimLin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,8 @@ TEST_F(ITest_NetSimLin, networksimulation_lin_dynamic)
557557
{
558558
SendLinFrames(now, linController, callCounts.silKitSentMsgLin.SentFramesTrivial);
559559
SendLinFrameHeaders(now, linController, callCounts.silKitSentMsgLin.SentFrameHeadersTrivial);
560-
WakeupOnce(now, linController);
561560
GoToSleepOnce(now, linController);
561+
WakeupOnce(now, linController);
562562
}
563563
}, _stepSize);
564564

SilKit/source/services/lin/LinController.cpp

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -180,88 +180,77 @@ void LinController::ThrowIfNotConfiguredTxUnconditional(LinId linId)
180180

181181
void LinController::WarnOnWrongDataLength(const LinFrame& receivedFrame, const LinFrame& configuredFrame) const
182182
{
183-
std::string errorMsg =
184-
fmt::format("Mismatch between configured ({}) and received ({}) LinDataLength in LinFrame with ID {}",
185-
configuredFrame.dataLength, receivedFrame.dataLength, static_cast<uint16_t>(receivedFrame.id));
186-
_logger->Warn(errorMsg);
183+
Logging::Warn(_logger, "Mismatch between configured ({}) and received ({}) LinDataLength in LinFrame with ID {}",
184+
configuredFrame.dataLength, receivedFrame.dataLength, static_cast<uint16_t>(receivedFrame.id));
187185
}
188186

189187
void LinController::WarnOnWrongChecksum(const LinFrame& receivedFrame, const LinFrame& configuredFrame) const
190188
{
191-
std::string errorMsg = fmt::format(
192-
"Mismatch between configured ({}) and received ({}) LinChecksumModel in LinFrame with ID {}",
193-
configuredFrame.checksumModel, receivedFrame.checksumModel, static_cast<uint16_t>(receivedFrame.id));
194-
_logger->Warn(errorMsg);
189+
Logging::Warn(_logger, "Mismatch between configured ({}) and received ({}) LinChecksumModel in LinFrame with ID {}",
190+
configuredFrame.checksumModel, receivedFrame.checksumModel, static_cast<uint16_t>(receivedFrame.id));
195191
}
196192

197193
void LinController::WarnOnReceptionWithInvalidDataLength(LinDataLength invalidDataLength,
198194
const std::string& fromParticipantName,
199195
const std::string& fromServiceName) const
200196
{
201-
std::string errorMsg =
202-
fmt::format("LinController received transmission with invalid payload length {} from {{{}, {}}}. This "
203-
"tranmission is ignored.",
204-
static_cast<uint16_t>(invalidDataLength), fromParticipantName, fromServiceName);
205-
_logger->Warn(errorMsg);
197+
Logging::Warn(_logger,
198+
"LinController received transmission with invalid payload length {} from {{{}, {}}}. This "
199+
"tranmission is ignored.",
200+
static_cast<uint16_t>(invalidDataLength), fromParticipantName, fromServiceName);
206201
}
207202

208203
void LinController::WarnOnReceptionWithInvalidLinId(LinId invalidLinId, const std::string& fromParticipantName,
209204
const std::string& fromServiceName) const
210205
{
211-
std::string errorMsg = fmt::format(
206+
Logging::Warn(
207+
_logger,
212208
"LinController received transmission with invalid LIN ID {} from {{{}, {}}}. This transmission is ignored.",
213209
static_cast<uint16_t>(invalidLinId), fromParticipantName, fromServiceName);
214-
_logger->Warn(errorMsg);
215210
}
216211

217-
void LinController::WarnOnReceptionWhileInactive() const
212+
void LinController::WarnOnReceptionWhileInactive(const LinTransmission& msg) const
218213
{
219-
std::string errorMsg = fmt::format("Inactive LinController received a transmission. This transmission is ignored.");
220-
_logger->Warn(errorMsg);
214+
Logging::Warn(_logger, "Inactive LinController received a transmission ({}). This transmission is ignored.", msg);
215+
}
216+
217+
void LinController::WarnOnReceptionWhileSleeping() const
218+
{
219+
Logging::Warn(_logger, "Sleeping LinController received a transmission. This transmission is ignored!");
221220
}
222221

223222
void LinController::WarnOnUnneededStatusChange(LinControllerStatus status) const
224223
{
225-
std::string errorMsg =
226-
fmt::format("Invalid LinController status change: controller is already in {} mode.", status);
227-
_logger->Warn(errorMsg);
224+
Logging::Warn(_logger, "Invalid LinController status change: controller is already in {} mode.", status);
228225
}
229226

230227
void LinController::WarnOnInvalidLinId(LinId invalidLinId, const std::string& callingMethodName) const
231228
{
232-
std::string errorMsg =
233-
fmt::format("Invalid ID={} in call to '{}'", static_cast<uint16_t>(invalidLinId), callingMethodName);
234-
_logger->Warn(errorMsg);
229+
Logging::Warn(_logger, "Invalid ID={} in call to '{}'", static_cast<uint16_t>(invalidLinId), callingMethodName);
235230
}
236231

237232
void LinController::WarnOnUnusedResponseMode(const std::string& callingMethodName) const
238233
{
239-
std::string errorMsg =
240-
fmt::format("LinFrameResponseMode::Unused is not allowed in call to '{}'.", callingMethodName);
241-
_logger->Warn(errorMsg);
234+
Logging::Warn(_logger, "LinFrameResponseMode::Unused is not allowed in call to '{}'.", callingMethodName);
242235
}
243236

244237
void LinController::WarnOnResponseModeReconfiguration(LinId id, LinFrameResponseMode currentResponseMode) const
245238
{
246-
std::string errorMsg =
247-
fmt::format("Can't set response mode for ID={}. Mode is already configured to {}.", id, currentResponseMode);
248-
_logger->Warn(errorMsg);
239+
Logging::Warn(_logger, "Can't set response mode for ID={}. Mode is already configured to {}.", id, currentResponseMode);
249240
}
250241

251242

252243
void LinController::WarnOnUnconfiguredSlaveResponse(LinId id) const
253244
{
254-
std::string errorMsg = fmt::format("No slave has configured a response for ID={}. Use Init() or SetFrameResponse() "
255-
"on the slave node to configure responses.",
256-
id);
257-
_logger->Warn(errorMsg);
245+
Logging::Warn(_logger,
246+
"No slave has configured a response for ID={}. Use Init() or SetFrameResponse() on the slave node to "
247+
"configure responses.",
248+
id);
258249
}
259250

260251
void LinController::WarnOnSendFrameSlaveResponseWithMasterTx(LinId id) const
261252
{
262-
std::string errorMsg =
263-
fmt::format("Master has already configured a response on ID={}. Ignoring this call to SendFrame()", id);
264-
_logger->Warn(errorMsg);
253+
Logging::Warn(_logger, "Master has already configured a response on ID={}. Ignoring this call to SendFrame()", id);
265254
}
266255

267256
void LinController::ThrowOnSendAttemptWithUndefinedChecksum(const LinFrame& frame) const
@@ -752,7 +741,13 @@ void LinController::ReceiveMsg(const IServiceEndpoint* from, const LinTransmissi
752741

753742
if (_controllerMode == LinControllerMode::Inactive)
754743
{
755-
WarnOnReceptionWhileInactive();
744+
WarnOnReceptionWhileInactive(msg);
745+
return;
746+
}
747+
748+
if(_controllerStatus == LinControllerStatus::Sleep || _controllerStatus == LinControllerStatus::Unknown)
749+
{
750+
WarnOnReceptionWhileSleeping();
756751
return;
757752
}
758753

SilKit/source/services/lin/LinController.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ class LinController
186186
const std::string& fromServiceName) const;
187187
void WarnOnReceptionWithInvalidLinId(LinId invalidLinId, const std::string& fromParticipantName,
188188
const std::string& fromServiceName) const;
189-
void WarnOnReceptionWhileInactive() const;
189+
void WarnOnReceptionWhileInactive(const LinTransmission& msg) const;
190+
void WarnOnReceptionWhileSleeping() const;
190191
void WarnOnUnneededStatusChange(LinControllerStatus status) const;
191192
void WarnOnInvalidLinId(LinId invalidLinId, const std::string& callingMethodName) const;
192193
void WarnOnUnusedResponseMode(const std::string& callingMethodName) const;

SilKit/source/services/lin/SimBehaviorTrivial.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "LinController.hpp"
66
#include "SimBehaviorTrivial.hpp"
77
#include "Assert.hpp"
8+
#include "LoggerMessage.hpp"
89

910
namespace SilKit {
1011
namespace Services {
@@ -88,11 +89,25 @@ void SimBehaviorTrivial::SendMsgImpl(MsgT&& msg)
8889

8990
void SimBehaviorTrivial::SendMsg(LinSendFrameRequest&& msg)
9091
{
92+
auto controllerStatus = _parentController->Status();
93+
if(controllerStatus == LinControllerStatus::Sleep || controllerStatus == LinControllerStatus::Unknown)
94+
{
95+
Logging::Warn(_participant->GetLogger(),
96+
"LinController not operational. SendFrameRequest will not be sent!");
97+
return;
98+
}
9199
_parentController->SendFrameHeader(msg.frame.id);
92100
}
93101

94102
void SimBehaviorTrivial::SendMsg(LinTransmission&& msg)
95103
{
104+
auto controllerStatus = _parentController->Status();
105+
if(controllerStatus == LinControllerStatus::Sleep || controllerStatus == LinControllerStatus::Unknown)
106+
{
107+
Logging::Warn(_participant->GetLogger(),
108+
"LinController not operational. LinTransmission will not be sent!");
109+
return;
110+
}
96111
SendMsgImpl(msg);
97112
}
98113

docs/changelog/versions/latest.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44

55
- `demos`: improved code quality
66
- `pubsub` / `rpc`: fix some edge cases when matching labels
7+
- `Lin controller`: fixed TX/RX behaviour when controller is not operational

0 commit comments

Comments
 (0)