Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit aaeb12f

Browse files
committed
Update README
1 parent 49a3019 commit aaeb12f

File tree

1 file changed

+95
-14
lines changed

1 file changed

+95
-14
lines changed

README.md

Lines changed: 95 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,60 @@
11
# smip
2-
An experimental framework for working with someip in rust.
2+
smip aims to make SOME/IP development in Rust feel as natural as building regular web services.
33

4-
A service can be defined using attributes on function and structs.
4+
Why is it better than something like vsomeip-rs?
55

6-
For example:
6+
vsomeip-rs is a Rust binding for the vsomeip C++ library. It exposes the C++ API directly to Rust developers, potentially leading to less Rust-idiomatic code.
7+
Also vsomeip is a very low level someip implementation and is heavily callback oriented.
8+
For example a service definition in vsomeip may look like this:
79

810
```rust
9-
use smip::Runtime;
11+
use vsomeip_rs::*;
12+
13+
const SERVICE_ID: ServiceId = 0x1111;
14+
const INSTANCE_ID: InstanceId = 0x2222;
15+
const METHOD_ID: MethodId = 0x3333;
16+
17+
fn server() {
18+
let runtime = Runtime::get();
19+
let app = runtime.create_application_with_name("hello_world_service").expect("Failed to create server");
20+
21+
let app_clone = app.clone();
22+
let app_clone1 = app.clone();
23+
app.register_state_handler(move |state| {
24+
if state == State::Registered {
25+
app_clone.offer_service(SERVICE_ID, INSTANCE_ID, 0, 0);
26+
}
27+
});
28+
29+
let mut state = 0;
30+
app.register_message_handler(SERVICE_ID, INSTANCE_ID, METHOD_ID, move |request| {
31+
let payload = request.get_payload();
32+
let bytes = payload.get_data();
33+
let response_text = std::str::from_utf8(bytes).unwrap();
34+
println!("{}", response_text);
35+
36+
let mut response = Message::response(request);
37+
response.set_payload(&Payload::with_data(format!("Hello {}", state).as_bytes()));
38+
39+
app_clone1.send(&response);
40+
41+
state += 1;
42+
});
43+
44+
app.start();
45+
46+
cleanup(app);
47+
}
48+
```
49+
Methods on services are defined using callbacks. While this is fine for simple services, this can get very complicated for services with complex logic, or with many methods. This is where smip can be of use.
50+
51+
It offers a higher-level abstraction over the underlying protocol, making it easier to use and understand by providing a cleaner more structured way to define services by leveraging Rust's powerful macro system, something similar to [rocket.rs](https://rocket.rs/) but for SOME/IP.
52+
53+
# Example
54+
Here's a simple example of defining a service and method using smip:
55+
56+
```rust
57+
use smip::{Runtime, RuntimeConfig, Service};
1058

1159
#[smip::service(id = 0x1234, major_version = 1, minor_version = 0)]
1260
struct MyService {
@@ -18,22 +66,55 @@ impl MyService {
1866
#[smip_method(id = 1)]
1967
fn add(&mut self, value: u32) -> u32 {
2068
self.x += value;
21-
2269
self.x
2370
}
71+
2472
#[smip_method(id = 2)]
2573
fn hello(&self) -> String {
26-
"Hello World".into()
74+
"Hello World!".to_string()
2775
}
2876
}
29-
fn main() {
30-
let config = smip::RuntimeConfig::new("Simple", 0xABCD, 0x1);
3177

32-
let application = Runtime::new(config).service(
33-
MyService {
34-
x: 0
35-
}, 30509);
78+
fn main() {
79+
let config: RuntimeConfig = smip::RuntimeConfig::new(
80+
"Simple",
81+
0xABCD,
82+
instance_id: 0x1,
83+
service: Some(MyService { x: 0 })
84+
);
3685

37-
let _ = application.run();
86+
let application: Runtime = smip::Runtime::new(config);
87+
application.run();
3888
}
39-
```
89+
```
90+
A service is represented by a struct with a `service` attribute for providing its `id` and other metadata. This struct will also hold all of the service's state.
91+
92+
SOME/IP methods are just rust methods with a special `smip_method` attribute attribute to indicate its id. Whatever you pass as an argument to your method is parsed automatically from the payload, and whatever you return from it serialized into a response and sent back.
93+
All of these need to be in a special impl block marked with a `methods_impl` attribute for the framework to recognize them.
94+
95+
# Aim
96+
97+
Smip aims to be a SOME/IP framework and not an implementation of SOME/IP, so its not competing with vsomeip or sommar. Currently vsomeip is used as the underlying implementation but this can be swapped with any compliant implementation in the future.
98+
99+
Key Benefits:
100+
* Macro-Based Definition: The smip macro simplifies the definition of services and methods, reducing the amount of code needed.
101+
* Automatic Serialization/Deserialization: smip handles the serialization and deserialization of your service's data types, so you don't have to write it yourself.
102+
* Rust-Idiomatic API: The framework's API is designed to be Rust-friendly, with a focus on clarity and simplicity.
103+
* Improved Developer Experience: smip streamlines the development process, making it easier to create and manage SOME/IP services in Rust.
104+
105+
106+
⚠️ **This is a highly experimental framework and doesn't support all features in SOME/IP.**
107+
108+
# Run
109+
For a working demo see `examples/simple.rs` and `examples/simple_client.rs`:
110+
111+
To run locally,
112+
```bash
113+
cargo run --example simple
114+
```
115+
In another terminal,
116+
```bash
117+
cargo run --example simple_demo
118+
```
119+
120+
- You may need to set the `LD_LIBRARY_PATH` environment to a path that contains the vsomeip library as this is dynamically loaded `LD_LIBRARY_PATH=/usr/local/lib`

0 commit comments

Comments
 (0)