13 #include "common/logger.h"
19 namespace udp_channel {
134 std::uint32_t payload_len) {
137 doip_header_buffer.emplace_back(
static_cast<std::uint8_t
>((payload_type & 0xFF00) >> 8));
138 doip_header_buffer.emplace_back(
static_cast<std::uint8_t
>(payload_type & 0x00FF));
139 doip_header_buffer.emplace_back(
static_cast<std::uint8_t
>((payload_len & 0xFF000000) >> 24));
140 doip_header_buffer.emplace_back(
static_cast<std::uint8_t
>((payload_len & 0x00FF0000) >> 16));
141 doip_header_buffer.emplace_back(
static_cast<std::uint8_t
>((payload_len & 0x0000FF00) >> 8));
142 doip_header_buffer.emplace_back(
static_cast<std::uint8_t
>(payload_len & 0x000000FF));
152 std::uint16_t vehicle_identification_type{0u};
153 std::uint8_t vehicle_identification_length{0u};
154 switch (preselection_mode) {
170 return VehiclePayloadType{vehicle_identification_type, vehicle_identification_length};
202 std::make_unique<kIdle>(VehicleIdentificationState::kIdle));
205 VehicleIdentificationState::kSendVehicleIdentificationReq,
206 std::make_unique<kSendVehicleIdentificationReq>(VehicleIdentificationState::kSendVehicleIdentificationReq));
209 std::make_unique<kWaitForVehicleIdentificationRes>(
210 VehicleIdentificationState::kWaitForVehicleIdentificationRes));
213 std::make_unique<kDoIPCtrlTimeout>(VehicleIdentificationState::kDoIPCtrlTimeout));
275 if (handler_impl_->GetStateContext().GetActiveState().GetState() == VehicleIdentificationState::kIdle) {
278 handler_impl_->GetStateContext().TransitionTo(VehicleIdentificationState::kWaitForVehicleIdentificationRes);
279 if (SendVehicleIdentificationRequest(std::move(vehicle_identification_request)) ==
283 handler_impl_->GetSyncTimer().WaitForTimeout(
285 handler_impl_->GetStateContext().TransitionTo(VehicleIdentificationState::kDoIPCtrlTimeout);
292 handler_impl_->GetStateContext().TransitionTo(VehicleIdentificationState::kIdle);
295 handler_impl_->GetStateContext().TransitionTo(VehicleIdentificationState::kIdle);
297 __FILE__, __LINE__,
"",
298 [](std::stringstream &msg) { msg <<
"Vehicle Identification request transmission Failed"; });
307 if (handler_impl_->GetStateContext().GetActiveState().GetState() ==
308 VehicleIdentificationState::kWaitForVehicleIdentificationRes) {
310 std::pair<uds_transport::UdsTransportProtocolMgr::IndicationResult, uds_transport::UdsMessagePtr> ret_val{
311 handler_impl_->GetDoipChannel().IndicateMessage(
314 "DoIPUdp", doip_payload.GetPayload())};
316 (ret_val.second !=
nullptr)) {
319 {
"kRemoteIpAddress", std::string{doip_payload.GetHostIpAddress()}}};
320 ret_val.second->AddMetaInfo(std::make_shared<uds_transport::UdsMessage::MetaInfoMap>(meta_info_map));
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));
336 UdpMessagePtr doip_vehicle_identification_req{std::make_unique<UdpMessage>(
337 vehicle_identification_request->GetHostIpAddress(), vehicle_identification_request->GetHostPortNumber())};
340 std::uint8_t preselection_mode{vehicle_identification_request->GetPayload()[
BYTE_POS_ONE]};
346 doip_vehicle_payload_type.second);
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());
353 if (handler_impl_->GetSocketHandler().Transmit(std::move(doip_vehicle_identification_req))) {
Immutable class to store received doip message.
Class to manage a udp channel as per DoIP protocol.
Class implements vehicle identification handler.
VehicleIdentificationStateContext state_context_
Stores the vehicle identification states.
VehicleIdentificationHandlerImpl(sockets::UdpSocketHandler &udp_socket_handler, DoipUdpChannel &channel)
Constructs an instance of VehicleDiscoveryHandlerImpl.
DoipUdpChannel & channel_
The reference to doip channel.
sockets::UdpSocketHandler & udp_socket_handler_
The reference to socket handler.
auto GetStateContext() noexcept -> VehicleIdentificationStateContext &
Function to get the Vehicle Identification State context.
SyncTimer sync_timer_
Store the synchronous timer.
auto GetSyncTimer() noexcept -> SyncTimer &
Function to get the sync timer.
auto GetSocketHandler() noexcept -> sockets::UdpSocketHandler &
Function to get the socket handler.
auto GetDoipChannel() noexcept -> DoipUdpChannel &
Function to get the doip channel.
auto SendVehicleIdentificationRequest(uds_transport::UdsMessageConstPtr vehicle_identification_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
Function to send vehicle identification request.
~VehicleIdentificationHandler()
Destruct an instance of VehicleIdentificationHandler.
auto HandleVehicleIdentificationRequest(uds_transport::UdsMessageConstPtr vehicle_identification_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
Function to handle sending of vehicle identification request.
void ProcessVehicleIdentificationResponse(DoipMessage &doip_payload) noexcept
Function to process received vehicle identification response.
VehicleIdentificationHandler(sockets::UdpSocketHandler &udp_socket_handler, DoipUdpChannel &channel)
Constructs an instance of VehicleIdentificationHandler.
sockets::UdpSocketHandler::UdpMessagePtr UdpMessagePtr
Type alias for Tcp message pointer.
Class implements sending of vehicle identification request state.
void Stop() override
Function to stop the current state.
void Start() override
Function to start the current state.
kSendVehicleIdentificationReq(VehicleIdentificationState state)
Constructs an instance of kSendVehicleIdentificationReq.
Class implements wait for vehicle identification response state.
void Start() override
Function to start the current state.
kWaitForVehicleIdentificationRes(VehicleIdentificationState state)
Constructs an instance of kWaitForVehicleIdentificationRes.
void Stop() override
Function to stop the current state.
Class implements Ctrl timeout state.
void Start() override
Function to start the current state.
kDoIPCtrlTimeout(VehicleIdentificationState state)
Constructs an instance of kDoIPCtrlTimeout.
void Stop() override
Function to stop the current state.
Class implements idle state.
void Stop() override
Function to stop the current state.
void Start() override
Function to start the current state.
kIdle(VehicleIdentificationState state)
Constructs an instance of kIdle.
static auto GetDiagClientLogger() noexcept -> DoipClientLogger &
Class used to create a udp socket for handling transmission and reception of udp message from driver.
std::map< std::string, std::string > MetaInfoMap
void TransitionTo(EnumState state)
void AddState(EnumState state, std::unique_ptr< State< EnumState >> state_ptr)
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.
VehicleIdentificationState
Different vehicle identification state.
constexpr std::uint8_t kDoipheadrSize
constexpr std::uint16_t kDoip_VehicleIdentification_ReqType
constexpr std::uint32_t kDoIPCtrl
constexpr std::uint32_t kDoip_VehicleIdentification_ReqLen
constexpr std::uint8_t kDoip_ProtocolVersion
constexpr std::uint32_t kDoip_VehicleIdentificationVIN_ReqLen
constexpr std::uint16_t kDoip_VehicleIdentificationVIN_ReqType
constexpr std::uint32_t kDoip_VehicleIdentificationEID_ReqLen
constexpr std::uint16_t kDoip_VehicleIdentificationEID_ReqType
std::unique_ptr< const UdsMessage > UdsMessageConstPtr