Diag-Client-Lib
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
doip_client::channel::udp_channel::VehicleIdentificationHandler Class Referencefinal

Class used as a handler to process vehicle identification req/ res messages. More...

#include <doip_vehicle_identification_handler.h>

Classes

class  VehicleIdentificationHandlerImpl
 Class implements vehicle identification handler. More...
 

Public Types

using UdpMessagePtr = sockets::UdpSocketHandler::UdpMessagePtr
 Type alias for Tcp message pointer. More...
 
using UdpMessage = sockets::UdpSocketHandler::UdpMessage
 Type alias for Udp message. More...
 

Public Member Functions

 VehicleIdentificationHandler (sockets::UdpSocketHandler &udp_socket_handler, DoipUdpChannel &channel)
 Constructs an instance of VehicleIdentificationHandler. More...
 
 ~VehicleIdentificationHandler ()
 Destruct an instance of VehicleIdentificationHandler. More...
 
auto HandleVehicleIdentificationRequest (uds_transport::UdsMessageConstPtr vehicle_identification_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
 Function to handle sending of vehicle identification request. More...
 
void ProcessVehicleIdentificationResponse (DoipMessage &doip_payload) noexcept
 Function to process received vehicle identification response. More...
 

Private Member Functions

auto SendVehicleIdentificationRequest (uds_transport::UdsMessageConstPtr vehicle_identification_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
 Function to send vehicle identification request. More...
 

Private Attributes

std::unique_ptr< VehicleIdentificationHandlerImplhandler_impl_
 Stores the Handler implementation. More...
 

Detailed Description

Class used as a handler to process vehicle identification req/ res messages.

Definition at line 26 of file doip_vehicle_identification_handler.h.

Member Typedef Documentation

◆ UdpMessage

Type alias for Udp message.

Definition at line 36 of file doip_vehicle_identification_handler.h.

◆ UdpMessagePtr

Type alias for Tcp message pointer.

Definition at line 31 of file doip_vehicle_identification_handler.h.

Constructor & Destructor Documentation

◆ VehicleIdentificationHandler()

doip_client::channel::udp_channel::VehicleIdentificationHandler::VehicleIdentificationHandler ( sockets::UdpSocketHandler udp_socket_handler,
DoipUdpChannel channel 
)

Constructs an instance of VehicleIdentificationHandler.

Parameters
[in]udp_socket_handlerThe reference to socket handler
[in]channelThe reference to doip udp channel

Definition at line 264 of file doip_vehicle_identification_handler.cpp.

266  : handler_impl_{std::make_unique<VehicleIdentificationHandlerImpl>(udp_socket_handler, channel)} {}
std::unique_ptr< VehicleIdentificationHandlerImpl > handler_impl_
Stores the Handler implementation.

◆ ~VehicleIdentificationHandler()

doip_client::channel::udp_channel::VehicleIdentificationHandler::~VehicleIdentificationHandler ( )
default

Destruct an instance of VehicleIdentificationHandler.

Member Function Documentation

◆ HandleVehicleIdentificationRequest()

auto doip_client::channel::udp_channel::VehicleIdentificationHandler::HandleVehicleIdentificationRequest ( uds_transport::UdsMessageConstPtr  vehicle_identification_request) -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
noexcept

Function to handle sending of vehicle identification request.

Parameters
[in]vehicle_identification_requestThe vehicle identification request
Returns
Transmission result

Definition at line 270 of file doip_vehicle_identification_handler.cpp.

272  {
275  if (handler_impl_->GetStateContext().GetActiveState().GetState() == VehicleIdentificationState::kIdle) {
276  // change state before sending if SendVehicleIdentificationRequest call takes more time to return and in the
277  // same time async reception starts
278  handler_impl_->GetStateContext().TransitionTo(VehicleIdentificationState::kWaitForVehicleIdentificationRes);
279  if (SendVehicleIdentificationRequest(std::move(vehicle_identification_request)) ==
282  // Wait for 2 sec to collect all the vehicle identification response
283  handler_impl_->GetSyncTimer().WaitForTimeout(
284  [&]() {
285  handler_impl_->GetStateContext().TransitionTo(VehicleIdentificationState::kDoIPCtrlTimeout);
286  // Todo: Send data to upper layer here
287  },
288  [&]() {
289  // no cancellation
290  },
291  std::chrono::milliseconds{kDoIPCtrl});
292  handler_impl_->GetStateContext().TransitionTo(VehicleIdentificationState::kIdle);
293  } else {
294  // failed, do nothing
295  handler_impl_->GetStateContext().TransitionTo(VehicleIdentificationState::kIdle);
296  logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogError(
297  __FILE__, __LINE__, "",
298  [](std::stringstream &msg) { msg << "Vehicle Identification request transmission Failed"; });
299  }
300  } else {
301  // not free, state already in idle state
302  }
303  return ret_val;
304 }
auto SendVehicleIdentificationRequest(uds_transport::UdsMessageConstPtr vehicle_identification_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
Function to send vehicle identification request.
static auto GetDiagClientLogger() noexcept -> DoipClientLogger &
Definition: logger.h:20
constexpr std::uint32_t kDoIPCtrl

References doip_client::logger::DoipClientLogger::GetDiagClientLogger(), doip_client::kDoIPCtrl, uds_transport::UdsTransportProtocolMgr::kTransmitFailed, and uds_transport::UdsTransportProtocolMgr::kTransmitOk.

Here is the call graph for this function:

◆ ProcessVehicleIdentificationResponse()

void doip_client::channel::udp_channel::VehicleIdentificationHandler::ProcessVehicleIdentificationResponse ( DoipMessage doip_payload)
noexcept

Function to process received vehicle identification response.

Parameters
[in]doip_payloadThe doip message received

Definition at line 306 of file doip_vehicle_identification_handler.cpp.

306  {
307  if (handler_impl_->GetStateContext().GetActiveState().GetState() ==
308  VehicleIdentificationState::kWaitForVehicleIdentificationRes) {
309  // Deserialize data to indicate to upper layer
310  std::pair<uds_transport::UdsTransportProtocolMgr::IndicationResult, uds_transport::UdsMessagePtr> ret_val{
311  handler_impl_->GetDoipChannel().IndicateMessage(
313  uds_transport::UdsMessage::TargetAddressType::kPhysical, 0U, doip_payload.GetPayload().size(), 0U,
314  "DoIPUdp", doip_payload.GetPayload())};
316  (ret_val.second != nullptr)) {
317  // Add meta info about ip address
319  {"kRemoteIpAddress", std::string{doip_payload.GetHostIpAddress()}}};
320  ret_val.second->AddMetaInfo(std::make_shared<uds_transport::UdsMessage::MetaInfoMap>(meta_info_map));
321  // copy to application buffer
322  (void) std::copy(doip_payload.GetPayload().begin(), doip_payload.GetPayload().end(),
323  ret_val.second->GetPayload().begin());
324  handler_impl_->GetDoipChannel().HandleMessage(std::move(ret_val.second));
325  }
326  } else {
327  // ignore
328  }
329 }
std::map< std::string, std::string > MetaInfoMap
Definition: uds_message.h:28

References uds_transport::UdsTransportProtocolMgr::kIndicationOk, and uds_transport::UdsMessage::kPhysical.

Referenced by doip_client::channel::udp_channel::DoipUdpChannelHandler::ProcessDoIPPayload().

Here is the caller graph for this function:

◆ SendVehicleIdentificationRequest()

auto doip_client::channel::udp_channel::VehicleIdentificationHandler::SendVehicleIdentificationRequest ( uds_transport::UdsMessageConstPtr  vehicle_identification_request) -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
privatenoexcept

Function to send vehicle identification request.

Parameters
[in]vehicle_identification_requestThe vehicle identification request
Returns
Transmission result

Definition at line 331 of file doip_vehicle_identification_handler.cpp.

333  {
336  UdpMessagePtr doip_vehicle_identification_req{std::make_unique<UdpMessage>(
337  vehicle_identification_request->GetHostIpAddress(), vehicle_identification_request->GetHostPortNumber())};
338 
339  // Get preselection mode
340  std::uint8_t preselection_mode{vehicle_identification_request->GetPayload()[BYTE_POS_ONE]};
341  // Get the payload type & length from preselection mode
342  VehiclePayloadType const doip_vehicle_payload_type{GetVehicleIdentificationPayloadType(preselection_mode)};
343 
344  // create header
345  CreateDoipGenericHeader(doip_vehicle_identification_req->GetTxBuffer(), doip_vehicle_payload_type.first,
346  doip_vehicle_payload_type.second);
347  // Copy only if containing VIN / EID
348  if (doip_vehicle_payload_type.first != kDoip_VehicleIdentification_ReqType) {
349  doip_vehicle_identification_req->GetTxBuffer().insert(
350  doip_vehicle_identification_req->GetTxBuffer().begin() + kDoipheadrSize,
351  vehicle_identification_request->GetPayload().begin() + 2U, vehicle_identification_request->GetPayload().end());
352  }
353  if (handler_impl_->GetSocketHandler().Transmit(std::move(doip_vehicle_identification_req))) {
355  }
356  return ret_val;
357 }
sockets::UdpSocketHandler::UdpMessagePtr UdpMessagePtr
Type alias for Tcp message pointer.
constexpr uint8_t BYTE_POS_ONE
Definition: common_header.h:32
std::pair< std::uint16_t, std::uint8_t > VehiclePayloadType
Type alias of vehicle payload type.
void CreateDoipGenericHeader(std::vector< std::uint8_t > &doip_header_buffer, std::uint16_t payload_type, std::uint32_t payload_len)
Create the doip generic header.
auto GetVehicleIdentificationPayloadType(std::uint8_t preselection_mode) noexcept -> VehiclePayloadType
Get the vehicle identification payload type based on preselection mode.
constexpr std::uint8_t kDoipheadrSize
constexpr std::uint16_t kDoip_VehicleIdentification_ReqType

References BYTE_POS_ONE, doip_client::channel::udp_channel::anonymous_namespace{doip_vehicle_identification_handler.cpp}::CreateDoipGenericHeader(), doip_client::channel::udp_channel::anonymous_namespace{doip_vehicle_identification_handler.cpp}::GetVehicleIdentificationPayloadType(), doip_client::kDoip_VehicleIdentification_ReqType, doip_client::kDoipheadrSize, uds_transport::UdsTransportProtocolMgr::kTransmitFailed, and uds_transport::UdsTransportProtocolMgr::kTransmitOk.

Here is the call graph for this function:

Member Data Documentation

◆ handler_impl_

std::unique_ptr<VehicleIdentificationHandlerImpl> doip_client::channel::udp_channel::VehicleIdentificationHandler::handler_impl_
private

Stores the Handler implementation.

Definition at line 88 of file doip_vehicle_identification_handler.h.


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