libdoip  0.1.0
DoIP (Diagnostics over Internet Protocol) ISO 13400 C++17 Library
DoIPClient.h
Go to the documentation of this file.
1 
2 #ifndef DOIPCLIENT_H
3 #define DOIPCLIENT_H
4 
5 #include <arpa/inet.h>
6 #include <cstddef>
7 #include <cstdlib>
8 #include <cstring>
9 #include <iostream>
10 #include <stdlib.h>
11 #include <unistd.h>
12 
13 #include "DoIPConfig.h"
14 #include "DoIPMessage.h"
15 
16 namespace doip {
17 
18 const int _maxDataSize = 64;
19 
20 using DoIPRequest = std::pair<size_t, const uint8_t *>;
21 
22 class DoIPClient {
23 
24  public:
25  DoIPClient() {m_receiveBuf.reserve(DOIP_MAXIMUM_MTU);}
26 
27  void startTcpConnection();
28  void startUdpConnection();
31  ssize_t sendVehicleIdentificationRequest(const char *inet_address);
33  void receiveUdpMessage();
34  [[nodiscard]]
36  /*
37  * Send the builded request over the tcp-connection to server
38  */
39  void receiveMessage();
40 
41  /**
42  * Sends a diagnostic message to the server
43  * @param payload data that will be given to the ecu
44  */
45  ssize_t sendDiagnosticMessage(const ByteArray &payload);
46 
47  /**
48  * Sends a alive check response containing the clients source address to the server
49  */
50  ssize_t sendAliveCheckResponse();
51  void setSourceAddress(const DoIPAddress &address);
53  void closeTcpConnection();
54  void closeUdpConnection();
55  void reconnectServer();
56 
57  int getSockFd();
58  int getConnected();
59 
60  private:
61  ByteArray m_receiveBuf;
62  int m_tcpSocket{-1}, m_udpSocket{-1}, m_udpAnnouncementSocket{-1}, m_connected{-1};
63  int m_broadcast = 1;
64  struct sockaddr_in m_serverAddress, m_clientAddress, m_announcementAddress;
65  DoIPAddress m_sourceAddress = DoIPAddress(0xE000);
66 
67  DoIpVin m_vin{0};
68  DoIPAddress m_logicalAddress = ZERO_ADDRESS;
69  DoIpEid m_eid{0};
70  DoIpGid m_gid{0};
71  DoIPFurtherAction m_furtherActionReqResult = DoIPFurtherAction::NoFurtherAction;
72 
73  void parseVehicleIdentificationResponse(const DoIPMessage& msg);
74 
75  int emptyMessageCounter = 0;
76 };
77 
78 } // namespace doip
79 
80 #endif /* DOIPCLIENT_H */
bool receiveVehicleAnnouncement()
Definition: DoIPClient.cpp:195
void printVehicleInformationResponse()
Definition: DoIPClient.cpp:302
void startTcpConnection()
Definition: DoIPClient.cpp:13
void closeUdpConnection()
Definition: DoIPClient.cpp:96
void receiveUdpMessage()
Definition: DoIPClient.cpp:160
void startUdpConnection()
Definition: DoIPClient.cpp:36
ssize_t sendVehicleIdentificationRequest(const char *inet_address)
Definition: DoIPClient.cpp:234
ssize_t sendAliveCheckResponse()
Sends a alive check response containing the clients source address to the server.
Definition: DoIPClient.cpp:121
void startAnnouncementListener()
Definition: DoIPClient.cpp:56
void setSourceAddress(const DoIPAddress &address)
Sets the source address for this client.
Definition: DoIPClient.cpp:266
ssize_t sendDiagnosticMessage(const ByteArray &payload)
Sends a diagnostic message to the server.
Definition: DoIPClient.cpp:114
void reconnectServer()
Definition: DoIPClient.cpp:103
void closeTcpConnection()
Definition: DoIPClient.cpp:92
ssize_t sendRoutingActivationRequest()
Definition: DoIPClient.cpp:108
void receiveRoutingActivationResponse()
Definition: AnsiColors.h:3
uint16_t DoIPAddress
Represents a 16-bit DoIP address consisting of high and low significant bytes.
Definition: DoIPAddress.h:26
GenericFixedId< 17, true, '0'> DoIpVin
Vehicle Identification Number (VIN) - 17 bytes according to ISO 3779 Padded with ASCII '0' characters...
constexpr DoIPAddress ZERO_ADDRESS
Definition: DoIPAddress.h:28
const int _maxDataSize
Definition: DoIPClient.h:18
std::pair< size_t, const uint8_t * > DoIPRequest
Definition: DoIPClient.h:20
GenericFixedId< 6, false > DoIpEid
Entity Identifier (EID) - 6 bytes for unique entity identification.
GenericFixedId< 6, false > DoIpGid
Group Identifier (GID) - 6 bytes for group identification.
A dynamic array of bytes with utility methods for network protocol handling.
Definition: ByteArray.h:60