-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
||
|
@@ -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. | ||
|