Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9b89c6f

Browse files
committed
Merge branch 'develop'
2 parents6b65ade +b757c9e commit9b89c6f

File tree

7 files changed

+51
-22
lines changed

7 files changed

+51
-22
lines changed

‎examples/blocking.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ use embedded_can::{blocking::Can, Frame as EmbeddedFrame, StandardId};
1616
use socketcan::{CanFrame,CanSocket,Frame,Socket};
1717
use std::env;
1818

19+
fnframe_to_string<F:Frame>(frame:&F) ->String{
20+
let id = frame.raw_id();
21+
let data_string = frame
22+
.data()
23+
.iter()
24+
.fold(String::from(""), |a, b|format!("{} {:02x}", a, b));
25+
26+
format!("{:X} [{}] {}", id, frame.dlc(), data_string)
27+
}
28+
29+
// --------------------------------------------------------------------------
30+
1931
fnmain() -> anyhow::Result<()>{
2032
let iface = env::args().nth(1).unwrap_or_else(||"vcan0".into());
2133

@@ -33,13 +45,3 @@ fn main() -> anyhow::Result<()> {
3345

3446
Ok(())
3547
}
36-
37-
fnframe_to_string<F:Frame>(frame:&F) ->String{
38-
let id = frame.raw_id();
39-
let data_string = frame
40-
.data()
41-
.iter()
42-
.fold(String::from(""), |a, b|format!("{} {:02x}", a, b));
43-
44-
format!("{:X} [{}] {}", id, frame.dlc(), data_string)
45-
}

‎examples/echo.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010
// @author Natesh Narain <nnaraindev@gmail.com>
1111
// @date Jul 05 2022
1212
//
13+
//! Listen on a CAN interface and echo any CAN 2.0 data frames back to
14+
//! the bus.
15+
//!
16+
//! The frames are sent back on CAN ID +1.
17+
//!
18+
//! You can test send frames to the application like this:
19+
//!
20+
//!```text
21+
//! $ cansend can0 110#00112233
22+
//! $ cansend can0 110#0011223344556677
23+
//!```
24+
//!
1325
1426
use anyhow::Context;
1527
use embedded_can::{blocking::Can,FrameasEmbeddedFrame};
@@ -26,11 +38,13 @@ fn frame_to_string<F: Frame>(frame: &F) -> String {
2638
let data_string = frame
2739
.data()
2840
.iter()
29-
.fold(String::from(""), |a, b|format!("{} {:02x}", a, b));
41+
.fold(String::new(), |a, b|format!("{} {:02X}", a, b));
3042

3143
format!("{:08X} [{}] {}", id, frame.dlc(), data_string)
3244
}
3345

46+
// --------------------------------------------------------------------------
47+
3448
fnmain() -> anyhow::Result<()>{
3549
let iface = env::args().nth(1).unwrap_or_else(||"vcan0".into());
3650

‎examples/echo_fd.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
// @author Natesh Narain <nnaraindev@gmail.com>
1212
// @date Jul 05 2022
1313
//
14+
//! Listen on a CAN FD interface and echo any FD frames back to the bus.
15+
//!
16+
//! The frames are sent back on CAN ID +1.
17+
//!
18+
//! You can test send frames to the application like this:
19+
//!
20+
//!```text
21+
//! $ cansend can0 110##100112233445566778899AABBCCDDEEFF
22+
//! $ cansend can0 110##100112233445566778899AABBCCDDEEFFAA
23+
//!```
24+
//!
1425
1526
use anyhow::Context;
1627
use embedded_can::FrameasEmbeddedFrame;
@@ -26,9 +37,9 @@ fn frame_to_string<F: Frame>(frame: &F) -> String {
2637
let data_string = frame
2738
.data()
2839
.iter()
29-
.fold(String::from(""), |a, b|format!("{} {:02x}", a, b));
40+
.fold(String::new(), |a, b|format!("{} {:02X}", a, b));
3041

31-
format!("{:08X} [{}] {}", id, frame.dlc(), data_string)
42+
format!("{:08X} [{}] {}", id, frame.len(), data_string)
3243
}
3344

3445
// --------------------------------------------------------------------------
@@ -37,17 +48,17 @@ fn main() -> anyhow::Result<()> {
3748
let iface = env::args().nth(1).unwrap_or_else(||"vcan0".into());
3849

3950
let sock =CanFdSocket::open(&iface)
40-
.with_context(||format!("Failed to open socket on interface {}", iface))?;
51+
.with_context(||format!("Failed to openFDsocket on interface {}", iface))?;
4152

4253
sock.set_nonblocking(true)
43-
.with_context(||"Failed to make socket non-blocking")?;
54+
.with_context(||"Failed to makeFDsocket non-blocking")?;
4455

4556
staticQUIT:AtomicBool =AtomicBool::new(false);
4657

4758
ctrlc::set_handler(||{
4859
QUIT.store(true,Ordering::Relaxed);
4960
})
50-
.expect("Failed to set signal handler");
61+
.expect("Failed to set^Csignal handler");
5162

5263
while !QUIT.load(Ordering::Relaxed){
5364
ifletOk(CanAnyFrame::Fd(frame)) = sock.read_frame(){

‎examples/enumerate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() {
2323
};
2424

2525
for ifacein interfaces{
26-
println!("{}", iface);
26+
println!("{}", iface);
2727
}
2828
}
2929
Err(e) =>{

‎scripts/buildtst.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ for VER in stable ${MSRV} ; do
4646
cargo +"${VER}" clippy --features="$FEATURES"
4747
["$?"-ne 0 ]&&exit 1
4848

49-
forFEATUREin"tokio""async-std""smol";do
49+
forFEATUREin"tokio""async-std""smol""utils""enumerate""utils";do
5050
printf"\n\nBuilding with feature [%s]...\n""${FEATURE}""${VER}"
5151
FEATURES="${FEATURE} vcan_tests"
5252
cargo clean&& \

‎scripts/vcan.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ if (( $EUID != 0 )); then
1212
exit 1
1313
fi
1414

15+
# Default to use "vcan0" if none is specified on the cmd line
16+
1517
IFACE=vcan0
1618
[-n"$1" ]&& IFACE=$1
1719

@@ -26,7 +28,9 @@ if [ -z "${VCAN_LOADED}" ]; then
2628
fi
2729

2830
# Add and set up the CAN interface
31+
# Request an MTU size of 72 to allow for FD frames
2932

3033
ip link addtype vcan&& \
34+
ip linkset"${IFACE}" mtu 72
3135
ip linkset up"${IFACE}"
3236

‎src/dump.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ impl<R: io::BufRead> Reader<R> {
200200
};
201201

202202
let frame:CanAnyFrame =if is_fd_frame{
203-
CanFdFrame::init(can_id,&data, fd_flags)
204-
.map(CanAnyFrame::Fd)
203+
CanFdFrame::init(can_id,&data, fd_flags).map(CanAnyFrame::Fd)
205204
}else{
206205
CanDataFrame::init(can_id,&data)
207206
.map(CanFrame::Data)
@@ -318,8 +317,7 @@ mod test {
318317
// Issue #74
319318
#[test]
320319
fntest_extended_id_fd(){
321-
let input:&[u8] =
322-
b"(1234.567890) can0 12345678##500112233445566778899AABBCCDDEEFF";
320+
let input:&[u8] =b"(1234.567890) can0 12345678##500112233445566778899AABBCCDDEEFF";
323321

324322
letmut reader =Reader::from_reader(input);
325323
let rec = reader.next_record().unwrap().unwrap();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp