Skip to content

Commit 9e9c9e7

Browse files
committed
feat: Add DoIP discovery example with VIN selection callback to README
1 parent 762d7f2 commit 9e9c9e7

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

examples/doip_client/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,54 @@ This codebase now includes a small DoIP transport abstraction, a split TCP/UDP i
193193
- Build Integration
194194
- CMake: when `BUILD_UDS_TP_DOIP=ON`, the DoIP target includes the new TCP/UDP transport sources.
195195
- Bazel: `src/BUILD` updated to include the new transport sources and headers.
196+
197+
### Quick Start: Discovery + Selection
198+
199+
Minimal example of discovering DoIP responders and selecting one by VIN prefix:
200+
201+
```c
202+
#include <stdio.h>
203+
#include <string.h>
204+
#include <stdbool.h>
205+
#include <stdint.h>
206+
#include "tp/doip/doip_client.h"
207+
208+
static bool select_by_vin(const DoIPDiscoveryInfo *info, void *user) {
209+
const char *needle = (const char *)user; // VIN prefix or full VIN
210+
if (!needle || !*needle) return false;
211+
if (info->vin[0] == '\0') return false;
212+
return strncmp(info->vin, needle, strlen(needle)) == 0;
213+
}
214+
215+
int main(int argc, char **argv) {
216+
const char *vin_prefix = argc > 1 ? argv[1] : NULL;
217+
bool loopback = argc > 2 ? (strcmp(argv[2], "loopback") == 0) : false;
218+
219+
DoIPClient_t tp;
220+
memset(&tp, 0, sizeof(tp));
221+
222+
UDSDoIPSetSelectionCallback(&tp, select_by_vin, (void*)vin_prefix);
223+
224+
int count = UDSDoIPDiscoverVehicles(&tp, 2000, loopback);
225+
printf("Discovered %d responders\n", count);
226+
printf("Selected server: %s\n", tp.server_ip);
227+
return 0;
228+
}
229+
```
230+
231+
Build and run (ad hoc):
232+
233+
```bash
234+
gcc -DUDS_TP_DOIP -Isrc -I. -o build/doip_discovery_example \
235+
src/tp/doip/doip_client.c src/tp/doip/doip_tp_udp.c src/tp/doip/doip_tp_tcp.c \
236+
examples/doip_discovery_example/main.c
237+
238+
# Default multicast discovery (~2s), chooses first responder
239+
./build/doip_discovery_example
240+
241+
# Filter by VIN prefix
242+
./build/doip_discovery_example WBA
243+
244+
# Loopback discovery for local testing
245+
./build/doip_discovery_example "" loopback
246+
```

src/tp/doip/pr.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## Add DoIP (ISO 13400) Transport Layer Support
2+
3+
This PR implements DoIP (Diagnostic over IP - ISO 13400) as a new transport layer for UDS, enabling diagnostic communication over TCP/IP networks.
4+
5+
### Features
6+
7+
- **DoIP Client Implementation** (`src/tp/doip/`)
8+
- TCP-based diagnostic message transport (ISO 13400-2)
9+
- Routing activation and alive check handling
10+
- Proper DoIP message framing and state management
11+
- Support for diagnostic message ACK/NACK
12+
- Non-blocking I/O with configurable timeouts
13+
14+
### Implementation Details
15+
16+
- **Protocol Version**: DoIP v3 (ISO 13400:2019)
17+
- **Standard Port**: TCP 13400
18+
- **Addressing**: External test equipment range (0x0E00-0x0FFF)
19+
- **Message Types**: Routing activation, diagnostic messages, alive check
20+
21+
### Testing
22+
23+
- Compiles cleanly with `-Wall -Wpedantic -Wextra`
24+
- Integration test passes (`examples/doip_client/test.sh`)
25+
- Successfully exchanges RDBI/WDBI messages over DoIP
26+
27+
### Code Quality
28+
29+
- Consistent with iso14229 coding style
30+
- Comprehensive error handling and logging
31+
- Well-documented with inline comments and function documentation
32+
- No compiler warnings
33+
34+
### Missing Features
35+
36+
- UDP vehicle discovery
37+
- DoIP server implementation in `src/tp/doip/` (currently only in examples)
38+
- TLS support (port 3496)
39+
- Unit tests for DoIP module
40+
- Multi-client server support
41+
42+
### Related Standards
43+
44+
- ISO 13400-2:2019 - Road vehicles — Diagnostic communication over Internet Protocol (DoIP)
45+
- ISO 14229 - Unified Diagnostic Services (UDS)
46+
47+
---
48+
49+
**Testing Instructions:**
50+
51+
```bash
52+
cd examples/doip_client
53+
make
54+
[test.sh](http://_vscodecontentref_/3) # Automated integration test

0 commit comments

Comments
 (0)