Skip to content

Commit b7d483a

Browse files
committed
add example
1 parent d6fb1cb commit b7d483a

5 files changed

Lines changed: 42 additions & 0 deletions

File tree

.github/workflows/linux-windows.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ jobs:
1919
sudo apt-get -y install clang gcc-mingw-w64-x86-64 libclang-dev
2020
- name: Build
2121
run: cargo build --verbose --target=x86_64-pc-windows-gnu --features=all
22+
- name: Build Examples
23+
run: cargo build --verbose --target=x86_64-pc-windows-gnu --features=all --examples

.github/workflows/linux.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ jobs:
1919
scripts/set_up_vcan.sh
2020
- name: Build
2121
run: cargo build --verbose --features=serde
22+
- name: Build Examples
23+
run: cargo build --verbose --features=serde --examples
2224
- name: Run tests
2325
run: cargo test --features=test-vcan,serde --verbose

.github/workflows/macos.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ jobs:
1313
- uses: actions/checkout@v3
1414
- name: Build
1515
run: cargo build --verbose --features=serde
16+
- name: Build Examples
17+
run: cargo build --verbose --features=serde --examples
1618
- name: Run tests
1719
run: cargo test --features=serde --verbose

.github/workflows/windows.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ jobs:
1313
- uses: actions/checkout@v3
1414
- name: Build
1515
run: cargo build --verbose --features=all
16+
- name: Build Examples
17+
run: cargo build --verbose --features=all --examples
1618
- name: Run tests
1719
run: cargo test --features=all --verbose

examples/configure_bitrate.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#[cfg(all(target_os = "windows", feature = "vector-xl"))]
2+
pub async fn run() -> Result<()> {
3+
use automotive::can::bitrate::BitrateBuilder;
4+
use automotive::vector::VectorCan;
5+
tracing_subscriber::fmt::init();
6+
7+
let bitrate_cfg = BitrateBuilder::new::<VectorCan>()
8+
.bitrate(500_000)
9+
.sample_point(0.8)
10+
.data_bitrate(2_000_000)
11+
.data_sample_point(0.8)
12+
.build()
13+
.unwrap();
14+
15+
let adapter = VectorCan::new_async(0, &Some(bitrate_cfg.into()))?;
16+
let mut stream = adapter.recv();
17+
18+
while let Some(frame) = stream.next().await {
19+
println!("{:?}", frame);
20+
}
21+
22+
Ok(())
23+
}
24+
25+
#[cfg(all(target_os = "windows", feature = "vector-xl"))]
26+
#[tokio::main]
27+
async fn main() -> automotive::Result<()> {
28+
run().await
29+
}
30+
31+
#[cfg(not(all(target_os = "windows", feature = "vector-xl")))]
32+
fn main() {
33+
eprintln!("This example requires Windows and the `vector-xl` feature.");
34+
}

0 commit comments

Comments
 (0)