18 namespace conversation {
79 std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, ::uds_transport::UdsMessagePtr>
IndicateMessage(
110 rx_buffer_size_{conversion_identifier.rx_buffer_size},
111 p2_client_max_{conversion_identifier.p2_client_max},
112 p2_star_client_max_{conversion_identifier.p2_star_client_max},
113 source_address_{conversion_identifier.source_address},
115 conversation_name_{conversion_name},
116 dm_conversion_handler_{std::make_unique<
DmConversationHandler>(conversion_identifier.handler_id, *this)} {
131 [&](std::stringstream &msg) {
134 <<
"Startup completed";
144 [&](std::stringstream &msg) {
147 <<
"Shutdown completed";
158 connection_ptr_->ConnectToHost(std::make_unique<diag::client::uds_message::DmUdsMessage>(
159 source_address_, target_address, host_ip_addr, payload)))};
160 remote_address_ = host_ip_addr;
161 target_address_ = target_address;
164 __FILE__, __LINE__, __func__, [
this](std::stringstream &msg) {
165 msg <<
"'" << conversation_name_ <<
"'"
167 <<
"Successfully connected to Server with IP <" << remote_address_ <<
">"
168 <<
" and LA= 0x" << std::hex << target_address_;
172 __FILE__, __LINE__, __func__, [
this](std::stringstream &msg) {
173 msg <<
"'" << conversation_name_ <<
"'"
175 <<
"Failed connecting to Server with IP <" << remote_address_ <<
">"
176 <<
" and LA= 0x" << std::hex << target_address_;
179 return connection_result;
190 __FILE__, __LINE__, __func__, [
this](std::stringstream &msg) {
193 <<
"Successfully disconnected from Server with IP <" <<
remote_address_ <<
">"
198 __FILE__, __LINE__, __func__, [&](std::stringstream &msg) {
201 <<
"Failed to disconnect from Server with IP <" <<
remote_address_ <<
">";
220 connection_ptr_->Transmit(std::make_unique<diag::client::uds_message::DmUdsMessage>(
221 source_address_, target_address_, message->GetHostIpAddress(), payload))};
225 __FILE__, __LINE__, __func__, [&](std::stringstream &msg) {
226 msg <<
"'" << conversation_name_ <<
"'"
228 <<
"Diagnostic Request Sent & Positive Ack received";
230 conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kDiagWaitForRes);
232 sync_timer_.WaitForTimeout(
235 conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kIdle);
237 __FILE__, __LINE__,
"", [&](std::stringstream &msg) {
238 msg <<
"'" << conversation_name_ <<
"'"
240 <<
"Diagnostic Response P2 Timeout happened after " << p2_client_max_ <<
" milliseconds";
245 if (conversation_state_.GetConversationStateContext().GetActiveState().GetState() ==
246 ConversationState::kDiagRecvdFinalRes) {
248 }
else if (conversation_state_.GetConversationStateContext().GetActiveState().GetState() ==
249 ConversationState::kDiagRecvdPendingRes) {
251 conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kDiagStartP2StarTimer);
254 std::chrono::milliseconds{p2_client_max_});
257 while (conversation_state_.GetConversationStateContext().GetActiveState().GetState() !=
258 ConversationState::kIdle) {
260 switch (conversation_state_.GetConversationStateContext().GetActiveState().GetState()) {
261 case ConversationState::kDiagRecvdPendingRes:
262 conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kDiagStartP2StarTimer);
264 case ConversationState::kDiagRecvdFinalRes:
267 case ConversationState::kDiagStartP2StarTimer:
269 sync_timer_.WaitForTimeout(
272 __FILE__, __LINE__,
"", [&](std::stringstream &msg) {
273 msg <<
"'" << conversation_name_ <<
"'"
275 <<
"Diagnostic Response P2 Star Timeout happened after " << p2_star_client_max_
280 conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kIdle);
284 if (conversation_state_.GetConversationStateContext().GetActiveState().GetState() ==
285 ConversationState::kDiagRecvdFinalRes) {
287 }
else if (conversation_state_.GetConversationStateContext().GetActiveState().GetState() ==
288 ConversationState::kDiagRecvdPendingRes) {
290 conversation_state_.GetConversationStateContext().TransitionTo(
291 ConversationState::kDiagStartP2StarTimer);
294 std::chrono::milliseconds{p2_star_client_max_});
296 case ConversationState::kDiagSuccess:
298 result.EmplaceValue(std::make_unique<diag::client::uds_message::DmUdsResponse>(payload_rx_buffer_));
299 conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kIdle);
308 result.EmplaceError(ConvertResponseType(transmission_result));
313 [&](std::stringstream &msg) {
314 msg <<
"'" << conversation_name_ <<
"'"
316 <<
"Diagnostic Request message is empty";
323 connection_ptr_ = std::move(connection);
330 std::pair<uds_transport::UdsTransportProtocolMgr::IndicationResult, uds_transport::UdsMessagePtr>
335 std::pair<uds_transport::UdsTransportProtocolMgr::IndicationResult, uds_transport::UdsMessagePtr> ret_val{
338 if (!payload_info.empty()) {
340 if (size <= rx_buffer_size_) {
343 if (payload_info[0U] == 0x7F && payload_info[2U] == 0x78) {
345 __FILE__, __LINE__,
"", [&](std::stringstream &msg) {
346 msg <<
"'" << conversation_name_ <<
"'"
348 <<
"Diagnostic pending response received in Conversation";
351 conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kDiagRecvdPendingRes);
354 __FILE__, __LINE__,
"", [
this](std::stringstream &msg) {
355 msg <<
"'" << conversation_name_ <<
"'"
357 <<
"Diagnostic final response received in Conversation";
361 payload_rx_buffer_.resize(size);
363 ret_val.second = std::make_unique<diag::client::uds_message::DmUdsMessage>(source_address_, target_address_,
"",
365 conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kDiagRecvdFinalRes);
367 sync_timer_.CancelWait();
370 __FILE__, __LINE__,
"", [&](std::stringstream &msg) {
371 msg <<
"'" << conversation_name_ <<
"'"
373 <<
"Diagnostic Conversation Error Indication Overflow";
379 __FILE__, __LINE__,
"", [&](std::stringstream &msg) {
380 msg <<
"'" << conversation_name_ <<
"'"
382 <<
"Diagnostic Conversation Rx Payload size 0 received";
389 if (message !=
nullptr) {
390 conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kDiagSuccess);
397 switch (result_type) {
Class type to contains a value (of type ValueType), or an error (of type ErrorType)
static Result FromError(const E &e) noexcept
Build a new Result from the specified error (given as lvalue)
Interface for diag client conversation.
DiagClientConversation::IpAddress IpAddress
Type alias for Ip address.
DiagError
Definitions of Diagnostics Request Response results.
DisconnectResult
Definitions of Disconnection results.
ConnectResult
Definitions of Connection results.
Class to manage reception from transport protocol handler to dm connection handler.
~DmConversationHandler() override=default
Destructs an instance of DmConversationHandler.
DmConversationHandler(::uds_transport::conversion_manager::ConversionHandlerID handler_id, DmConversation &dm_conversion)
Constructs an instance of DmConversationHandler.
DmConversationHandler & operator=(const DmConversationHandler &other) noexcept=delete
DmConversation & dm_conversation_
Store the reference of dm conversation.
DmConversationHandler & operator=(DmConversationHandler &&other) noexcept=delete
void HandleMessage(::uds_transport::UdsMessagePtr message) const noexcept override
Function to Hands over a valid received Uds message.
DmConversationHandler(DmConversationHandler &&other) noexcept=delete
Deleted move assignment and move constructor.
std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, ::uds_transport::UdsMessagePtr > IndicateMessage(::uds_transport::UdsMessage::Address source_addr, ::uds_transport::UdsMessage::Address target_addr, ::uds_transport::UdsMessage::TargetAddressType type, ::uds_transport::ChannelID channel_id, std::size_t size, ::uds_transport::Priority priority, ::uds_transport::ProtocolKind protocol_kind, core_type::Span< std::uint8_t > payload_info) const noexcept override
Function to indicate a start of reception of message.
DmConversationHandler(const DmConversationHandler &other) noexcept=delete
Deleted copy assignment and copy constructor.
Class to establish connection with Diagnostic Server.
std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, ::uds_transport::UdsMessagePtr > IndicateMessage(::uds_transport::UdsMessage::Address source_addr, ::uds_transport::UdsMessage::Address target_addr, ::uds_transport::UdsMessage::TargetAddressType type, ::uds_transport::ChannelID channel_id, std::size_t size, ::uds_transport::Priority priority, ::uds_transport::ProtocolKind protocol_kind, core_type::Span< std::uint8_t > payload_info) noexcept override
Function to indicate a start of reception of message.
void Startup() noexcept override
Function to start the DmConversation.
~DmConversation() override
Destructs an instance of DmConversation.
DisconnectResult DisconnectFromDiagServer() noexcept override
Function to disconnect from Diagnostic Server.
std::unique_ptr<::uds_transport::ConversionHandler > dm_conversion_handler_
Store the dm conversation handler.
DmConversation(std::string_view conversion_name, DMConversationType &conversion_identifier)
Constructs an instance of DmConversation.
void HandleMessage(::uds_transport::UdsMessagePtr message) noexcept override
Function to Hands over a valid received Uds message.
void RegisterConnection(std::unique_ptr<::uds_transport::Connection > connection) noexcept override
Function to register the conversation to underlying transport protocol handler.
ConnectResult ConnectToDiagServer(std::uint16_t target_address, IpAddress host_ip_addr) noexcept override
Function to connect to Diagnostic Server.
SecurityLevelType
Definitions of active security level.
::uds_transport::ConversionHandler & GetConversationHandler() noexcept override
Function to get the conversation handler from conversation object.
Result< uds_message::UdsResponseMessagePtr, DiagError > SendDiagnosticRequest(uds_message::UdsRequestMessageConstPtr message) noexcept override
Function to send Diagnostic Request and get Diagnostic Response.
ActivityStatusType activity_status_
Store the conversation activity status.
SessionControlType active_session_
Store the active diagnostic session.
std::uint16_t target_address_
Store the logical target address of remote server.
ActivityStatusType
Definitions of current activity status.
std::string remote_address_
Store the remote IP address of remote server.
SecurityLevelType active_security_level_
Store the active diagnostic security level.
void Shutdown() noexcept override
Function to shutdown the DmConversation.
std::unique_ptr<::uds_transport::Connection > connection_ptr_
Store the underlying transport protocol connection object.
std::string conversation_name_
Store the conversation name.
SessionControlType
Definitions of active diagnostic session.
static DiagClientConversation::DiagError ConvertResponseType(::uds_transport::UdsTransportProtocolMgr::TransmissionResult result_type)
Helper function to convert response type.
static auto GetDiagClientLogger() noexcept -> DiagClientLogger &
Get the diag client logger instance.
Class to manage reception from transport protocol handler to connection handler.
ConversionHandler(conversion_manager::ConversionHandlerID handler_id)
Constructs an instance of ConversionHandler.
@ kNegTransmitAckReceived
std::unique_ptr< const UdsMessage > UdsRequestMessageConstPtr
Type alias of unique_ptr for constant UdsRequestMessage.
std::uint8_t ConversionHandlerID
std::string_view ProtocolKind
std::unique_ptr< UdsMessage > UdsMessagePtr
std::vector< std::uint8_t > ByteVector
Structure containing DM conversation type.