Diag-Client-Lib
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
diag::client::conversation::VdConversation Class Referencefinal

Class to search for available diagnostic server over a network. More...

#include <vd_conversation.h>

Inheritance diagram for diag::client::conversation::VdConversation:
Inheritance graph
[legend]
Collaboration diagram for diag::client::conversation::VdConversation:
Collaboration graph
[legend]

Public Member Functions

 VdConversation (std::string_view conversion_name, VDConversationType &conversion_identifier)
 Constructs an instance of VdConversation. More...
 
 VdConversation (const VdConversation &other) noexcept=delete
 Deleted copy assignment and copy constructor. More...
 
VdConversationoperator= (const VdConversation &other) noexcept=delete
 
 VdConversation (VdConversation &&other) noexcept=delete
 Deleted move assignment and move constructor. More...
 
VdConversationoperator= (VdConversation &&other) noexcept=delete
 
 ~VdConversation () override
 Destructs an instance of DmConversation. More...
 
void Startup () noexcept override
 Function to start the DmConversation. More...
 
void Shutdown () noexcept override
 Function to shutdown the DmConversation. More...
 
void RegisterConnection (std::unique_ptr<::uds_transport::Connection > connection) noexcept override
 Function to register the conversation to underlying transport protocol handler. More...
 
::uds_transport::ConversionHandlerGetConversationHandler () noexcept override
 Function to get the conversation handler from conversation object. More...
 
std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, ::uds_transport::UdsMessagePtrIndicateMessage (::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 > payloadInfo) noexcept override
 Function to indicate a start of reception of message. More...
 
void HandleMessage (::uds_transport::UdsMessagePtr message) noexcept override
 Function to Hands over a valid received Uds message. More...
 
core_type::Result< diag::client::vehicle_info::VehicleInfoMessageResponseUniquePtr, DiagClient::VehicleInfoResponseErrorSendVehicleIdentificationRequest (vehicle_info::VehicleInfoListRequestType vehicle_info_request) noexcept override
 Function to send vehicle identification request and get the Diagnostic Server list. More...
 
vehicle_info::VehicleInfoMessageResponseUniquePtr GetDiagnosticServerList ()
 Function to get the list of available diagnostic server. More...
 
- Public Member Functions inherited from diag::client::conversation::Conversation
 Conversation () noexcept=default
 Constructs an instance of Conversation. More...
 
 Conversation (const Conversation &other) noexcept=delete
 Deleted copy assignment and copy constructor. More...
 
Conversationoperator= (const Conversation &other) noexcept=delete
 
 Conversation (Conversation &&other) noexcept=delete
 Deleted move assignment and move constructor. More...
 
Conversationoperator= (Conversation &&other) noexcept=delete
 
virtual ~Conversation () noexcept=default
 Destructs an instance of Conversation. More...
 
virtual ConnectResult ConnectToDiagServer (std::uint16_t, IpAddress) noexcept
 Function to connect to Diagnostic Server. More...
 
virtual DisconnectResult DisconnectFromDiagServer () noexcept
 Function to disconnect from Diagnostic Server. More...
 
virtual Result< uds_message::UdsResponseMessagePtr, DiagErrorSendDiagnosticRequest (uds_message::UdsRequestMessageConstPtr) noexcept
 Function to send Diagnostic Request and get Diagnostic Response. More...
 

Private Types

using PreselectionMode = std::uint8_t
 Type alias of pre-selection mode. More...
 
using PreselectionValue = std::vector< std::uint8_t >
 Type alias of pre-selection value in terms of vector. More...
 
using VehicleAddrInfoResponseStruct = diag::client::vehicle_info::VehicleAddrInfoResponse
 Type alias of vehicle address info response. More...
 
using LogicalAddress = std::uint16_t
 Type alias of logical address. More...
 

Private Member Functions

bool VerifyVehicleInfoRequest (PreselectionMode preselection_mode, std::uint8_t preselection_value_length)
 Function to verify the received vehicle info request. More...
 

Static Private Member Functions

static std::pair< LogicalAddress, VehicleAddrInfoResponseStructDeserializeVehicleInfoResponse (::uds_transport::UdsMessagePtr message)
 Function to deserialize the received Vehicle Identification Response/ Announcement. More...
 
static std::pair< PreselectionMode, PreselectionValueDeserializeVehicleInfoRequest (vehicle_info::VehicleInfoListRequestType &vehicle_info_request)
 Function to deserialize the Vehicle Information request from user. More...
 

Private Attributes

std::unique_ptr<::uds_transport::ConversionHandlervd_conversion_handler_
 Store the vd conversation handler. More...
 
std::string conversation_name_
 Store the conversation name. More...
 
std::string broadcast_address_
 Store the broadcast Ip address of the conversation. More...
 
std::unique_ptr<::uds_transport::Connectionconnection_ptr_
 Store the underlying transport protocol connection object. More...
 
std::map< std::uint16_t, VehicleAddrInfoResponseStructvehicle_info_collection_
 Store the vehicle info collection received till now. More...
 
std::mutex vehicle_info_container_mutex_
 Mutex to lock the vehicle info collection container. More...
 

Additional Inherited Members

- Public Types inherited from diag::client::conversation::Conversation
using IpAddress = DiagClientConversation::IpAddress
 Type alias for Ip address. More...
 
using ConnectResult = DiagClientConversation::ConnectResult
 Type alias for Connection results. More...
 
using DisconnectResult = DiagClientConversation::DisconnectResult
 Type alias for Disconnection results. More...
 
using DiagError = DiagClientConversation::DiagError
 Type alias for Diagnostic results. More...
 

Detailed Description

Class to search for available diagnostic server over a network.

Definition at line 33 of file vd_conversation.h.

Member Typedef Documentation

◆ LogicalAddress

Type alias of logical address.

Definition at line 53 of file vd_conversation.h.

◆ PreselectionMode

Type alias of pre-selection mode.

Definition at line 38 of file vd_conversation.h.

◆ PreselectionValue

using diag::client::conversation::VdConversation::PreselectionValue = std::vector<std::uint8_t>
private

Type alias of pre-selection value in terms of vector.

Definition at line 43 of file vd_conversation.h.

◆ VehicleAddrInfoResponseStruct

Type alias of vehicle address info response.

Definition at line 48 of file vd_conversation.h.

Constructor & Destructor Documentation

◆ VdConversation() [1/3]

diag::client::conversation::VdConversation::VdConversation ( std::string_view  conversion_name,
VDConversationType conversion_identifier 
)

Constructs an instance of VdConversation.

Parameters
[in]conversion_nameThe name of conversation
[in]conversion_identifierThe identifier consisting of conversation settings

Definition at line 188 of file vd_conversation.cpp.

189  : vd_conversion_handler_{std::make_unique<VdConversationHandler>(conversion_identifier.handler_id, *this)},
190  conversation_name_{conversion_name},
191  broadcast_address_{conversion_identifier.udp_broadcast_address},
192  connection_ptr_{},
std::map< std::uint16_t, VehicleAddrInfoResponseStruct > vehicle_info_collection_
Store the vehicle info collection received till now.
std::unique_ptr<::uds_transport::Connection > connection_ptr_
Store the underlying transport protocol connection object.
std::unique_ptr<::uds_transport::ConversionHandler > vd_conversion_handler_
Store the vd conversation handler.
std::string conversation_name_
Store the conversation name.
std::mutex vehicle_info_container_mutex_
Mutex to lock the vehicle info collection container.
std::string broadcast_address_
Store the broadcast Ip address of the conversation.

◆ VdConversation() [2/3]

diag::client::conversation::VdConversation::VdConversation ( const VdConversation other)
deletenoexcept

Deleted copy assignment and copy constructor.

◆ VdConversation() [3/3]

diag::client::conversation::VdConversation::VdConversation ( VdConversation &&  other)
deletenoexcept

Deleted move assignment and move constructor.

◆ ~VdConversation()

diag::client::conversation::VdConversation::~VdConversation ( )
overridedefault

Destructs an instance of DmConversation.

Member Function Documentation

◆ DeserializeVehicleInfoRequest()

std::pair< VdConversation::PreselectionMode, VdConversation::PreselectionValue > diag::client::conversation::VdConversation::DeserializeVehicleInfoRequest ( vehicle_info::VehicleInfoListRequestType vehicle_info_request)
staticprivate

Function to deserialize the Vehicle Information request from user.

Parameters
[in]vehicle_info_requestThe vehicle info request
Returns
The pair with preselection mode along with its preselection value

Definition at line 338 of file vd_conversation.cpp.

338  {
339 
340  std::pair<VdConversation::PreselectionMode, VdConversation::PreselectionValue> ret_val{};
341  ret_val.first = vehicle_info_request.preselection_mode;
342 
343  if (ret_val.first == 1U) {
344  // 1U : DoIP Entities with given VIN
345  SerializeVINFromString(vehicle_info_request.preselection_value, ret_val.second,
346  static_cast<uint8_t>(vehicle_info_request.preselection_value.length()), 1U);
347  } else if (ret_val.first == 2U) {
348  // 2U : DoIP Entities with given EID
349  vehicle_info_request.preselection_value.erase(
350  remove(vehicle_info_request.preselection_value.begin(), vehicle_info_request.preselection_value.end(), ':'),
351  vehicle_info_request.preselection_value.end());
352  SerializeEIDGIDFromString(vehicle_info_request.preselection_value, ret_val.second,
353  static_cast<uint8_t>(vehicle_info_request.preselection_value.length()), 2U);
354  } else {
355  // log failure
356  }
357  return ret_val;
358 }
void SerializeVINFromString(std::string &input_string, std::vector< uint8_t > &output_buffer, std::uint8_t total_size, std::uint8_t substring_range)
void SerializeEIDGIDFromString(std::string &input_string, std::vector< uint8_t > &output_buffer, std::uint8_t total_size, std::uint8_t substring_range)

References diag::client::vehicle_info::VehicleAddrInfoRequest::preselection_mode, diag::client::vehicle_info::VehicleAddrInfoRequest::preselection_value, diag::client::conversation::SerializeEIDGIDFromString(), and diag::client::conversation::SerializeVINFromString().

Here is the call graph for this function:

◆ DeserializeVehicleInfoResponse()

std::pair< VdConversation::LogicalAddress, VdConversation::VehicleAddrInfoResponseStruct > diag::client::conversation::VdConversation::DeserializeVehicleInfoResponse ( ::uds_transport::UdsMessagePtr  message)
staticprivate

Function to deserialize the received Vehicle Identification Response/ Announcement.

Parameters
[in]messageThe message to deserialize
Returns
The pair with logical address of server and Vehicle address information

Definition at line 306 of file vd_conversation.cpp.

306  {
307  constexpr std::uint8_t start_index_vin{0U};
308  constexpr std::uint8_t total_vin_length{17U};
309  constexpr std::uint8_t start_index_eid{19U};
310  constexpr std::uint8_t start_index_gid{25U};
311  constexpr std::uint8_t total_eid_gid_length{6U};
312 
313  std::string const vehicle_info_data_vin{
314  ConvertToAsciiString(start_index_vin, total_vin_length, message->GetPayload())};
315  std::string const vehicle_info_data_eid{
316  ConvertToHexString(start_index_eid, total_eid_gid_length, message->GetPayload())};
317  std::string const vehicle_info_data_gid{
318  ConvertToHexString(start_index_gid, total_eid_gid_length, message->GetPayload())};
319 
320  LogicalAddress const logical_address{
321  (static_cast<std::uint16_t>(((message->GetPayload()[17U] & 0xFF) << 8) | (message->GetPayload()[18U] & 0xFF)))};
322 
323  // Create the structure out of the extracted string
324  VehicleAddrInfoResponseStruct const vehicle_addr_info{std::string{message->GetHostIpAddress()}, // remote ip address
325  logical_address, // logical address
326  vehicle_info_data_vin, // vin
327  vehicle_info_data_eid, // eid
328  vehicle_info_data_gid}; // gid
329 
330  return std::pair<std::uint16_t, VdConversation::VehicleAddrInfoResponseStruct>{logical_address, vehicle_addr_info};
331 }
std::uint16_t LogicalAddress
Type alias of logical address.
diag::client::vehicle_info::VehicleAddrInfoResponse VehicleAddrInfoResponseStruct
Type alias of vehicle address info response.
std::string ConvertToAsciiString(std::uint8_t char_start, std::uint8_t char_count, std::vector< std::uint8_t > &input_buffer)
std::string ConvertToHexString(std::uint8_t char_start, std::uint8_t char_count, std::vector< std::uint8_t > &input_buffer)

References diag::client::conversation::ConvertToAsciiString(), and diag::client::conversation::ConvertToHexString().

Here is the call graph for this function:

◆ GetConversationHandler()

uds_transport::ConversionHandler & diag::client::conversation::VdConversation::GetConversationHandler ( )
overridevirtualnoexcept

Function to get the conversation handler from conversation object.

Returns
ConversionHandler & The reference to conversation handler

Implements diag::client::conversation::Conversation.

Definition at line 333 of file vd_conversation.cpp.

333  {
334  return *vd_conversion_handler_;
335 }

References vd_conversion_handler_.

◆ GetDiagnosticServerList()

vehicle_info::VehicleInfoMessageResponseUniquePtr diag::client::conversation::VdConversation::GetDiagnosticServerList ( )

Function to get the list of available diagnostic server.

Returns
The Vehicle info message containing available diagnostic server information

Definition at line 255 of file vd_conversation.cpp.

255 { return nullptr; }

◆ HandleMessage()

void diag::client::conversation::VdConversation::HandleMessage ( ::uds_transport::UdsMessagePtr  message)
overridevirtualnoexcept

Function to Hands over a valid received Uds message.

Parameters
[in]messageThe The Uds message ptr (unique_ptr semantics) with the request. Ownership of the UdsMessage is given back to the conversation here

Implements diag::client::conversation::Conversation.

Definition at line 274 of file vd_conversation.cpp.

274  {
275  if (message != nullptr) {
276  std::lock_guard<std::mutex> const lock{vehicle_info_container_mutex_};
277  std::pair<std::uint16_t, VehicleAddrInfoResponseStruct> vehicle_info_request{
278  DeserializeVehicleInfoResponse(std::move(message))};
279 
280  vehicle_info_collection_.emplace(vehicle_info_request.first, vehicle_info_request.second);
281  }
282 }
static std::pair< LogicalAddress, VehicleAddrInfoResponseStruct > DeserializeVehicleInfoResponse(::uds_transport::UdsMessagePtr message)
Function to deserialize the received Vehicle Identification Response/ Announcement.

Referenced by diag::client::conversation::VdConversationHandler::HandleMessage().

Here is the caller graph for this function:

◆ IndicateMessage()

std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult,::uds_transport::UdsMessagePtr > diag::client::conversation::VdConversation::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 >  payloadInfo 
)
overridevirtualnoexcept

Function to indicate a start of reception of message.

This is called to indicate the reception of new message by underlying transport protocol handler

Parameters
[in]source_addrThe UDS source address of message
[in]target_addrThe UDS target address of message
[in]typeThe indication whether its is phys/func request
[in]channel_idThe transport protocol channel on which message start happened
[in]sizeThe size in bytes of the UdsMessage starting from SID
[in]priorityThe priority of the given message, used for prioritization of conversations
[in]protocol_kindThe identifier of protocol kind associated to message
[in]payload_infoThe View onto the first received payload bytes, if any. This view shall be used only within this function call. It is recommended that the TP provides at least the first two bytes of the request message, so the DM can identify a functional TesterPresent
Returns
std::pair< IndicationResult, UdsMessagePtr > The pair of IndicationResult and a pointer to UdsMessage owned/created by DM core and returned to the handler to get filled

Implements diag::client::conversation::Conversation.

Definition at line 258 of file vd_conversation.cpp.

262  {
263  using IndicationResult =
264  std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, ::uds_transport::UdsMessagePtr>;
266  if (!payload_info.empty()) {
268  ret_val.second = std::make_unique<diag::client::vd_message::VdMessage>();
269  ret_val.second->GetPayload().resize(size);
270  }
271  return ret_val;
272 }

References uds_transport::UdsTransportProtocolMgr::kIndicationNOk, and uds_transport::UdsTransportProtocolMgr::kIndicationOk.

Referenced by diag::client::conversation::VdConversationHandler::IndicateMessage().

Here is the caller graph for this function:

◆ operator=() [1/2]

VdConversation& diag::client::conversation::VdConversation::operator= ( const VdConversation other)
deletenoexcept

◆ operator=() [2/2]

VdConversation& diag::client::conversation::VdConversation::operator= ( VdConversation &&  other)
deletenoexcept

◆ RegisterConnection()

void diag::client::conversation::VdConversation::RegisterConnection ( std::unique_ptr<::uds_transport::Connection connection)
overridevirtualnoexcept

Function to register the conversation to underlying transport protocol handler.

Parameters
[in]connectionThe conversation connection object

Implements diag::client::conversation::Conversation.

Definition at line 210 of file vd_conversation.cpp.

210  {
211  connection_ptr_ = std::move(connection);
212 }

◆ SendVehicleIdentificationRequest()

core_type::Result< diag::client::vehicle_info::VehicleInfoMessageResponseUniquePtr, DiagClient::VehicleInfoResponseError > diag::client::conversation::VdConversation::SendVehicleIdentificationRequest ( vehicle_info::VehicleInfoListRequestType  vehicle_info_request)
overridevirtualnoexcept

Function to send vehicle identification request and get the Diagnostic Server list.

Parameters
[in]vehicle_info_requestVehicle information sent along with request
Returns
Result containing available vehicle information response on success, VehicleResponseErrorCode on error

Reimplemented from diag::client::conversation::Conversation.

Definition at line 215 of file vd_conversation.cpp.

216  {
217  using VehicleIdentificationResponseResult =
220 
221  VehicleIdentificationResponseResult result{
222  VehicleIdentificationResponseResult::FromError(DiagClient::VehicleInfoResponseError::kTransmitFailed)};
223 
224  // Deserialize first , Todo: Add optional when deserialize fails
225  std::pair<PreselectionMode, PreselectionValue> vehicle_info_request_deserialized_value{
226  DeserializeVehicleInfoRequest(vehicle_info_request)};
227 
228  if (VerifyVehicleInfoRequest(vehicle_info_request_deserialized_value.first,
229  static_cast<uint8_t>(vehicle_info_request_deserialized_value.second.size()))) {
230  if (connection_ptr_->Transmit(std::make_unique<diag::client::vd_message::VdMessage>(
231  vehicle_info_request_deserialized_value.first, vehicle_info_request_deserialized_value.second,
233  // Check if any response received
234  if (vehicle_info_collection_.empty()) {
235  // no response received
237  logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogWarn(
238  __FILE__, __LINE__, __func__, [&](std::stringstream &msg) {
239  msg << "'" << conversation_name_ << "'"
240  << "-> "
241  << "No vehicle identification response received, timed out without response";
242  });
243  } else {
244  result.EmplaceValue(std::make_unique<VehicleInfoMessageImpl>(vehicle_info_collection_));
245  // all the responses are copied, now clear the map
246  vehicle_info_collection_.clear();
247  }
248  }
249  } else {
251  }
252  return result;
253 }
Class type to contains a value (of type ValueType), or an error (of type ErrorType)
Definition: result.h:29
VehicleInfoResponseError
Definitions of Vehicle Identification response error code.
static std::pair< PreselectionMode, PreselectionValue > DeserializeVehicleInfoRequest(vehicle_info::VehicleInfoListRequestType &vehicle_info_request)
Function to deserialize the Vehicle Information request from user.
bool VerifyVehicleInfoRequest(PreselectionMode preselection_mode, std::uint8_t preselection_value_length)
Function to verify the received vehicle info request.
static auto GetDiagClientLogger() noexcept -> DiagClientLogger &
Get the diag client logger instance.
Definition: logger.h:32
std::unique_ptr< VehicleInfoMessage > VehicleInfoMessageResponseUniquePtr
The unique_ptr for Vehicle Identification Response Message.

References diag::client::logger::DiagClientLogger::GetDiagClientLogger(), diag::client::DiagClient::kInvalidParameters, diag::client::DiagClient::kNoResponseReceived, diag::client::DiagClient::kTransmitFailed, and uds_transport::UdsTransportProtocolMgr::kTransmitFailed.

Here is the call graph for this function:

◆ Shutdown()

void diag::client::conversation::VdConversation::Shutdown ( )
overridevirtualnoexcept

Function to shutdown the DmConversation.

Implements diag::client::conversation::Conversation.

Definition at line 205 of file vd_conversation.cpp.

205  {
206  // shutdown connection
207  connection_ptr_->Stop();
208 }

References connection_ptr_.

◆ Startup()

void diag::client::conversation::VdConversation::Startup ( )
overridevirtualnoexcept

Function to start the DmConversation.

Implements diag::client::conversation::Conversation.

Definition at line 198 of file vd_conversation.cpp.

198  {
199  // initialize the connection
200  static_cast<void>(connection_ptr_->Initialize());
201  // start the connection
202  connection_ptr_->Start();
203 }

References connection_ptr_.

◆ VerifyVehicleInfoRequest()

bool diag::client::conversation::VdConversation::VerifyVehicleInfoRequest ( PreselectionMode  preselection_mode,
std::uint8_t  preselection_value_length 
)
private

Function to verify the received vehicle info request.

Parameters
[in]preselection_modeThe preselection mode
[in]preselection_value_lengthThe length of preselection value
Returns
True on success, else false

Definition at line 284 of file vd_conversation.cpp.

285  {
286  bool is_veh_info_valid{false};
287  // 0U : No preselection
288  if (preselection_mode == 0U && (preselection_value_length == 0U)) {
289  is_veh_info_valid = true;
290  }
291  // 1U : DoIP Entities with given VIN
292  else if (preselection_mode == 1U && (preselection_value_length == 17U)) {
293  is_veh_info_valid = true;
294  }
295  // 2U : DoIP Entities with given EID
296  else if (preselection_mode == 2U && (preselection_value_length == 6U)) {
297  is_veh_info_valid = true;
298  } else {
299  // do nothing
300  }
301 
302  return is_veh_info_valid;
303 }

Member Data Documentation

◆ broadcast_address_

std::string diag::client::conversation::VdConversation::broadcast_address_
private

Store the broadcast Ip address of the conversation.

Definition at line 203 of file vd_conversation.h.

◆ connection_ptr_

std::unique_ptr<::uds_transport::Connection> diag::client::conversation::VdConversation::connection_ptr_
private

Store the underlying transport protocol connection object.

Definition at line 208 of file vd_conversation.h.

Referenced by Shutdown(), and Startup().

◆ conversation_name_

std::string diag::client::conversation::VdConversation::conversation_name_
private

Store the conversation name.

Definition at line 198 of file vd_conversation.h.

◆ vd_conversion_handler_

std::unique_ptr<::uds_transport::ConversionHandler> diag::client::conversation::VdConversation::vd_conversion_handler_
private

Store the vd conversation handler.

Definition at line 193 of file vd_conversation.h.

Referenced by GetConversationHandler().

◆ vehicle_info_collection_

std::map<std::uint16_t, VehicleAddrInfoResponseStruct> diag::client::conversation::VdConversation::vehicle_info_collection_
private

Store the vehicle info collection received till now.

Definition at line 213 of file vd_conversation.h.

◆ vehicle_info_container_mutex_

std::mutex diag::client::conversation::VdConversation::vehicle_info_container_mutex_
private

Mutex to lock the vehicle info collection container.

Definition at line 218 of file vd_conversation.h.


The documentation for this class was generated from the following files: