Skip to content

Commit efe2613

Browse files
Make sendResponsePending a free function
1 parent 81a3f07 commit efe2613

File tree

2 files changed

+93
-40
lines changed

2 files changed

+93
-40
lines changed

libs/bsw/uds/include/uds/connection/IncomingDiagConnection.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ class IncomingDiagConnection
8181
&IncomingDiagConnection::triggerNextNestedRequest>(*this))
8282
{
8383
_context = diagContext;
84-
_pendingMessage.init(&_pendingMessageBuffer[0], PENDING_MESSAGE_BUFFER_LENGTH);
8584
for (uint8_t cnt = 0U; cnt < _identifiers.capacity(); cnt++)
8685
{
8786
_identifiers[cnt] = 0U;
@@ -237,8 +236,6 @@ class IncomingDiagConnection
237236

238237
void restartPendingTimeout();
239238

240-
void sendResponsePending();
241-
242239
void asyncTransportMessageProcessed(
243240
transport::TransportMessage* pTransportMessage, ProcessingResult status);
244241

libs/bsw/uds/src/uds/connection/IncomingDiagConnection.cpp

Lines changed: 93 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,51 @@ using ::util::logger::UDS;
2828
namespace uds
2929
{
3030

31+
void buildResponsePendingTransportMessage(
32+
::transport::TransportMessage& pendingMessage,
33+
uint8_t* const pendingMessageBuffer,
34+
uint16_t const sourceAddress,
35+
uint16_t const responseSourceAddress,
36+
uint8_t const serviceId)
37+
{
38+
pendingMessage.init(
39+
pendingMessageBuffer, IncomingDiagConnection::PENDING_MESSAGE_BUFFER_LENGTH);
40+
pendingMessage.setTargetAddress(sourceAddress);
41+
pendingMessage.setSourceAddress(responseSourceAddress);
42+
pendingMessage.resetValidBytes();
43+
(void)pendingMessage.append(DiagReturnCode::NEGATIVE_RESPONSE_IDENTIFIER);
44+
(void)pendingMessage.append(serviceId);
45+
(void)pendingMessage.append(static_cast<uint8_t>(DiagReturnCode::ISO_RESPONSE_PENDING));
46+
pendingMessage.setPayloadLength(IncomingDiagConnection::PENDING_MESSAGE_PAYLOAD_LENGTH);
47+
}
48+
49+
void sendResponsePending(
50+
transport::AbstractTransportLayer& messageSender,
51+
transport::TransportMessage& pendingMessage,
52+
uint8_t& numPendingMessageProcessedCallbacks,
53+
bool& responsePendingSent,
54+
bool& responsePendingIsBeingSent,
55+
transport::ITransportMessageProcessedListener& processedListener)
56+
{
57+
++numPendingMessageProcessedCallbacks;
58+
bool const responsePendingSentBefore = responsePendingSent;
59+
bool const responsePendingIsBeingSentBefore = responsePendingIsBeingSent;
60+
responsePendingSent = true;
61+
responsePendingIsBeingSent = true;
62+
AbstractTransportLayer::ErrorCode const result
63+
= messageSender.send(pendingMessage, &processedListener);
64+
if (result != AbstractTransportLayer::ErrorCode::TP_OK)
65+
{
66+
--numPendingMessageProcessedCallbacks;
67+
responsePendingSent = responsePendingSentBefore;
68+
responsePendingIsBeingSent = responsePendingIsBeingSentBefore;
69+
Logger::error(
70+
UDS,
71+
"IncomingDiagConnection: Unable to send ResponsePending: sendResult = %d!",
72+
result);
73+
}
74+
}
75+
3176
void IncomingDiagConnection::addIdentifier()
3277
{
3378
ETL_ASSERT(!_isResponseActive, ETL_ERROR_GENERIC("response must not be active"));
@@ -291,7 +336,22 @@ void IncomingDiagConnection::asyncSendNegativeResponse(
291336

292337
if (!_responsePendingIsPending)
293338
{ // Only send ResponsePending while response is not being sent
294-
sendResponsePending();
339+
if (isOpen && (messageSender != nullptr))
340+
{
341+
buildResponsePendingTransportMessage(
342+
_pendingMessage,
343+
_pendingMessageBuffer,
344+
sourceAddress,
345+
responseSourceAddress,
346+
serviceId);
347+
sendResponsePending( // send using persistent member instance
348+
*messageSender,
349+
_pendingMessage,
350+
_numPendingMessageProcessedCallbacks,
351+
_responsePendingSent,
352+
_responsePendingIsBeingSent,
353+
*this);
354+
}
295355
}
296356
restartPendingTimeout();
297357
}
@@ -455,7 +515,22 @@ void IncomingDiagConnection::asyncTransportMessageProcessed(
455515
else if (_responsePendingIsPending)
456516
{
457517
_responsePendingIsPending = false;
458-
sendResponsePending();
518+
if (isOpen && (messageSender != nullptr))
519+
{
520+
buildResponsePendingTransportMessage(
521+
_pendingMessage,
522+
_pendingMessageBuffer,
523+
sourceAddress,
524+
responseSourceAddress,
525+
serviceId);
526+
sendResponsePending(
527+
*messageSender,
528+
_pendingMessage,
529+
_numPendingMessageProcessedCallbacks,
530+
_responsePendingSent,
531+
_responsePendingIsBeingSent,
532+
*this);
533+
}
459534
}
460535
}
461536
if (status != ITransportMessageProcessedListener::ProcessingResult::PROCESSED_NO_ERROR)
@@ -513,7 +588,22 @@ void IncomingDiagConnection::expired(::async::RunnableType const& timeout)
513588
if (!_responsePendingIsPending)
514589
{
515590
// Only send ResponsePending while response is not being sent
516-
sendResponsePending();
591+
if (isOpen && (messageSender != nullptr))
592+
{
593+
buildResponsePendingTransportMessage(
594+
_pendingMessage,
595+
_pendingMessageBuffer,
596+
sourceAddress,
597+
responseSourceAddress,
598+
serviceId);
599+
sendResponsePending(
600+
*messageSender,
601+
_pendingMessage,
602+
_numPendingMessageProcessedCallbacks,
603+
_responsePendingSent,
604+
_responsePendingIsBeingSent,
605+
*this);
606+
}
517607
}
518608
restartPendingTimeout();
519609
}
@@ -538,40 +628,6 @@ void IncomingDiagConnection::restartPendingTimeout()
538628
}
539629
}
540630

541-
void IncomingDiagConnection::sendResponsePending()
542-
{
543-
if ((!isOpen) || (nullptr == messageSender))
544-
{
545-
return;
546-
}
547-
_pendingMessage.setTargetAddress(sourceAddress);
548-
_pendingMessage.setSourceAddress(responseSourceAddress);
549-
_pendingMessage.resetValidBytes();
550-
(void)_pendingMessage.append(DiagReturnCode::NEGATIVE_RESPONSE_IDENTIFIER);
551-
(void)_pendingMessage.append(serviceId);
552-
(void)_pendingMessage.append(static_cast<uint8_t>(DiagReturnCode::ISO_RESPONSE_PENDING));
553-
_pendingMessage.setPayloadLength(PENDING_MESSAGE_PAYLOAD_LENGTH);
554-
++_numPendingMessageProcessedCallbacks;
555-
// this flag indicates that pending has been sent --> a positive response must follow!
556-
bool const responsePendingSent = _responsePendingSent;
557-
bool const responsePendingIsBeingSent = _responsePendingIsBeingSent;
558-
_responsePendingSent = true;
559-
_responsePendingIsBeingSent = true;
560-
AbstractTransportLayer::ErrorCode const sendResult = messageSender->send(_pendingMessage, this);
561-
if (sendResult != AbstractTransportLayer::ErrorCode::TP_OK)
562-
{
563-
--_numPendingMessageProcessedCallbacks;
564-
// this flag indicates that pending has been sent --> a positive response must follow!
565-
_responsePendingSent = responsePendingSent;
566-
_responsePendingIsBeingSent = responsePendingIsBeingSent;
567-
Logger::error(
568-
UDS,
569-
"IncomingDiagConnection: Unable to send ResponsePending: "
570-
"sendResult = %d!",
571-
sendResult);
572-
}
573-
}
574-
575631
void IncomingDiagConnection::open(bool const activatePending)
576632
{
577633
if (isOpen)

0 commit comments

Comments
 (0)