This repository was archived by the owner on Dec 17, 2025. It is now read-only.
forked from AVL-DiTEST-DiagDev/libdoip
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexampleDoIPClient.cpp
More file actions
86 lines (69 loc) · 2.86 KB
/
exampleDoIPClient.cpp
File metadata and controls
86 lines (69 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "DoIPClient.h"
#include "DoIPMessage.h"
#include "Logger.h"
#include <iomanip>
#include <iostream>
#include <thread>
using namespace doip;
using namespace std;
DoIPClient client;
static void printUsage(const char *progName) {
cout << "Usage: " << progName << " [OPTIONS]\n";
cout << "Options:\n";
cout << " --loopback Use loopback (127.0.0.1) instead of multicast\n";
cout << " --server <ip> Connect to specific server IP\n";
cout << " --help Show this help message\n";
}
int main(int argc, char *argv[]) {
string serverAddress = "224.0.0.2"; // Default multicast address
// Parse command line arguments
for (int i = 1; i < argc; i++) {
string arg = argv[i];
if (arg == "--loopback") {
serverAddress = "127.0.0.1";
DOIP_LOG_INFO("Loopback mode enabled - using 127.0.0.1");
} else if (arg == "--server" && i + 1 < argc) {
serverAddress = argv[++i];
DOIP_LOG_INFO("Using custom server address: {}", serverAddress);
} else if (arg == "--help") {
printUsage(argv[0]);
return 0;
} else {
cout << "Unknown argument: " << arg << endl;
printUsage(argv[0]);
return 1;
}
}
DOIP_LOG_INFO("Starting DoIP Client");
// Start UDP connections (don't start TCP yet)
client.startUdpConnection();
client.startAnnouncementListener(); // Listen for Vehicle Announcements on port 13401
// Listen for Vehicle Announcements first
DOIP_LOG_INFO("Listening for Vehicle Announcements...");
client.receiveVehicleAnnouncement();
// Send Vehicle Identification Request to configured address
if (client.sendVehicleIdentificationRequest(serverAddress.c_str()) > 0) {
DOIP_LOG_INFO("Vehicle Identification Request sent successfully");
client.receiveUdpMessage();
}
// Now start TCP connection for diagnostic communication
DOIP_LOG_INFO("Starting TCP connection for diagnostic messages");
client.startTcpConnection();
if (client.sendRoutingActivationRequest() < 0) {
std::cerr << "sendRoutingActivationRequest Failed";
exit(EXIT_FAILURE);
}
// NEEDS REWORK! State handling required!
client.receiveMessage();
client.sendDiagnosticMessage({0x22, 0xF1, 0x90}); // Example: Read Data by Identifier (0xF190 = VIN)
client.receiveMessage(); // ack
std::this_thread::sleep_for(2s);
client.sendDiagnosticMessage({0x22, 0xF2, 0x90}); // Example: Read Data by Identifier (0xF190 = VIN)
client.receiveMessage();
std::this_thread::sleep_for(2s);
client.sendDiagnosticMessage({0x22, 0xF1, 0x90}); // Example: Read Data by Identifier (0xF190 = VIN)
client.receiveMessage(); // ack
std::this_thread::sleep_for(2s);
client.closeTcpConnection();
client.closeUdpConnection();
}