Skip to content

Commit

Permalink
Update vsomeip README
Browse files Browse the repository at this point in the history
  • Loading branch information
Ax9DTW committed Aug 1, 2024
1 parent 038d9e2 commit 2a388cb
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions crates/vsomeip-rs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

Rust bindings to [vsomeip](https://github.com/COVESA/vsomeip)


### vsomeip-sys
This is the low-level binding to the vsomeip library. It is a direct mapping of the C++ API to Rust. This crate is not intended to be used directly by the user. It is used by the `vsomeip-rs` crate to provide a safe and idiomatic Rust API to the user.

Expand All @@ -17,13 +16,59 @@ To use the vsomeip library, you need to install it first.
```bash
git clone [email protected]:COVESA/vsomeip.git
cd vsomeip
# Check out to a compatible version of vsomeip
git checkout cf497232adf84f55947f7a24e1b64e04b49f1f38
mkdir build
cd build
cmake ..
# See these two issues for why this flag needs to be set
# https://github.com/COVESA/vsomeip/issues/688
# https://github.com/COVESA/vsomeip/issues/527
cmake -E env CXXFLAGS="-Wno-error=stringop-overflow" cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE=Debug
make
sudo make install
```

## Example usage
```rust
use vsomeip_rs::*;

const SERVICE_ID: ServiceId = 0x1111;
const INSTANCE_ID: InstanceId = 0x2222;
const METHOD_ID: MethodId = 0x3333;

fn server() {
let runtime = Runtime::get();
let app = runtime.create_application_with_name("hello_world_service").expect("Failed to create server");

let app_clone = app.clone();
let app_clone1 = app.clone();
app.register_state_handler(move |state| {
if state == State::Registered {
app_clone.offer_service(SERVICE_ID, INSTANCE_ID, 0, 0);
}
});

let mut state = 0;
app.register_message_handler(SERVICE_ID, INSTANCE_ID, METHOD_ID, move |request| {
let payload = request.get_payload();
let bytes = payload.get_data();
let response_text = std::str::from_utf8(bytes).unwrap();
println!("{}", response_text);

let mut response = Message::response(request);
response.set_payload(&Payload::with_data(format!("Hello {}", state).as_bytes()));

app_clone1.send(&response);

state += 1;
});

app.start();

cleanup(app);
}
```

## Build and Run

The vsomeip library is loaded dynamically at runtime, so it must be present in the dynamic library path when running any vsomeip application.
Expand Down

0 comments on commit 2a388cb

Please sign in to comment.