|
| 1 | +# Examples |
| 2 | + |
| 3 | +This directory contains aliases to example applications demonstrating the S-CORE Communication middleware API. |
| 4 | + |
| 5 | +## Available Examples |
| 6 | + |
| 7 | +- **[COM-API-Example](#com-api-example)**: Rust-based producer-consumer pattern demonstrating the Communication API with tire pressure data |
| 8 | +- **[IPC Bridge](#ipc-bridge)**: C++/Rust application demonstrating IPC communication with skeleton/proxy pattern |
| 9 | + |
| 10 | +## COM-API-Example |
| 11 | + |
| 12 | +### Standard Build (Host Platform) |
| 13 | + |
| 14 | +```bash |
| 15 | +bazel build //examples/com-api-example:com-api-example |
| 16 | +``` |
| 17 | + |
| 18 | +### QNX Cross-Compilation |
| 19 | + |
| 20 | +```bash |
| 21 | +bazel build --config=x86_64-qnx //examples/com-api-example:com-api-example |
| 22 | +``` |
| 23 | + |
| 24 | +### Running |
| 25 | + |
| 26 | +After building, the binary will be in `bazel-bin/score/mw/com/example/com-api-example/com-api-example`. |
| 27 | + |
| 28 | +### Quick Start |
| 29 | + |
| 30 | +To see the COM API in action, run the example from the repo root: |
| 31 | + |
| 32 | +```bash |
| 33 | +./bazel-bin/score/mw/com/example/com-api-example/com-api-example |
| 34 | +``` |
| 35 | + |
| 36 | +The application demonstrates a producer-consumer pattern where: |
| 37 | + |
| 38 | +- A `VehicleOfferedProducer` publishes tire pressure data |
| 39 | +- A `VehicleConsumer` subscribes to and receives tire pressure updates |
| 40 | +- Five samples are sent with incrementing tire pressure values (5.0, 6.0, 7.0, 8.0, 9.0) |
| 41 | +- Each sample is read back and validated |
| 42 | + |
| 43 | +You should see output showing tire data being sent and received, demonstrating the complete publish-subscribe workflow. |
| 44 | + |
| 45 | +### Code Structure |
| 46 | + |
| 47 | +The example demonstrates several key patterns: |
| 48 | + |
| 49 | +### VehicleMonitor Struct |
| 50 | + |
| 51 | +A composite structure that combines: |
| 52 | + |
| 53 | +- `VehicleConsumer`: Subscribes to vehicle data |
| 54 | +- `VehicleOfferedProducer`: Publishes vehicle data |
| 55 | +- `Subscription`: Active subscription to tire data |
| 56 | + |
| 57 | +### Producer-Consumer Pattern |
| 58 | + |
| 59 | +```rust |
| 60 | +// Create producer |
| 61 | +let producer = create_producer(runtime, service_id.clone()); |
| 62 | + |
| 63 | +// Create consumer |
| 64 | +let consumer = create_consumer(runtime, service_id); |
| 65 | + |
| 66 | +// Create monitor combining both |
| 67 | +let monitor = VehicleMonitor::new(consumer, producer).unwrap(); |
| 68 | + |
| 69 | +// Write data |
| 70 | +monitor.write_tire_data(Tire { pressure: 5.0 }).unwrap(); |
| 71 | + |
| 72 | +// Read data |
| 73 | +let tire_data = monitor.read_tire_data().unwrap(); |
| 74 | +``` |
| 75 | + |
| 76 | +## IPC Bridge |
| 77 | + |
| 78 | +### Standard Build (Host Platform) |
| 79 | + |
| 80 | +```bash |
| 81 | +bazel build //examples:ipc_bridge_cpp |
| 82 | +``` |
| 83 | + |
| 84 | +### QNX Cross-Compilation |
| 85 | + |
| 86 | +```bash |
| 87 | +bazel build --config=x86_64-qnx //examples:ipc_bridge_cpp |
| 88 | +``` |
| 89 | + |
| 90 | +### Running |
| 91 | + |
| 92 | +After building the binary will be in `bazel-bin/score/mw/com/example/ipc_bridge/ipc_bridge_cpp`. |
| 93 | + |
| 94 | +#### Quick Start (Two Terminals) |
| 95 | + |
| 96 | +To see the IPC communication in action, open two terminals in the repo root: |
| 97 | + |
| 98 | +**Terminal 1 - Start Skeleton (Publisher):** |
| 99 | + |
| 100 | +```bash |
| 101 | +./bazel-bin/score/mw/com/example/ipc_bridge/ipc_bridge_cpp \ |
| 102 | + --mode skeleton \ |
| 103 | + --cycle-time 1000 \ |
| 104 | + --num-cycles 10 \ |
| 105 | + --service_instance_manifest score/mw/com/example/ipc_bridge/etc/mw_com_config.json |
| 106 | +``` |
| 107 | + |
| 108 | +**Terminal 2 - Start Proxy (Subscriber):** |
| 109 | + |
| 110 | +```bash |
| 111 | +./bazel-bin/score/mw/com/example/ipc_bridge/ipc_bridge_cpp \ |
| 112 | + --mode proxy \ |
| 113 | + --cycle-time 500 \ |
| 114 | + --num-cycles 20 \ |
| 115 | + --service_instance_manifest score/mw/com/example/ipc_bridge/etc/mw_com_config.json |
| 116 | +``` |
| 117 | + |
| 118 | +You should see the proxy discover the skeleton service, subscribe, and receive `MapApiLanesStamped` samples. The proxy validates data integrity and ordering for each received sample. |
| 119 | + |
| 120 | +#### Command-Line Options |
| 121 | + |
| 122 | +| Option | Description | Required | |
| 123 | +| ------ | ----------- | -------- | |
| 124 | +| `--mode, -m` | Operation mode: `skeleton`/`send` or `proxy`/`recv` | Yes | |
| 125 | +| `--cycle-time, -t` | Cycle time in milliseconds for sending/polling | Yes | |
| 126 | +| `--num-cycles, -n` | Number of cycles to execute (0 = infinite) | Yes | |
| 127 | +| `--service_instance_manifest, -s` | Path to communication config JSON | Optional | |
| 128 | +| `--disable-hash-check, -d` | Skip sample hash validation in proxy mode | Optional | |
| 129 | + |
| 130 | +## Configuration |
| 131 | + |
| 132 | +The communication behavior is configured via `score/mw/com/example/ipc_bridge/etc/mw_com_config.json`: |
| 133 | + |
| 134 | +- Service type definitions and bindings |
| 135 | +- Event definitions with IDs |
| 136 | +- Instance-specific configuration (shared memory settings, subscriber limits) |
| 137 | +- ASIL level and process ID restrictions |
0 commit comments