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

Commit95db362

Browse files
committed
Some reorganization
1 parent7c73d5a commit95db362

File tree

3 files changed

+70
-70
lines changed

3 files changed

+70
-70
lines changed

‎src/frame.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
//!
3232
3333
usecrate::{
34-
id::{id_from_raw, id_to_canid_t,CanId,FdFlags,IdFlags},
34+
id::{CanId,FdFlags,IdFlags},
3535
CanError,ConstructionError,
3636
};
3737
use embedded_can::{ExtendedId,FrameasEmbeddedFrame,Id,StandardId};
@@ -42,10 +42,12 @@ use std::{
4242
mem::size_of,
4343
{convert::TryFrom, fmt, matches, mem},
4444
};
45-
// TODO: Remove these on the next major ver update.
45+
46+
// TODO: Remove these (or make private) on the next major ver update.
4647
pubusecrate::id::{
47-
CANFD_BRS,CANFD_ESI,CANFD_MAX_DLEN,CAN_EFF_FLAG,CAN_EFF_MASK,CAN_ERR_FLAG,CAN_ERR_MASK,
48-
CAN_MAX_DLEN,CAN_RTR_FLAG,CAN_SFF_MASK,
48+
id_from_raw, id_is_extended, id_to_canid_t,CANFD_BRS,CANFD_ESI,CANFD_MAX_DLEN,CAN_EFF_FLAG,
49+
CAN_EFF_MASK,CAN_ERR_FLAG,CAN_ERR_MASK,CAN_MAX_DLEN,CAN_RTR_FLAG,CAN_SFF_MASK,
50+
ERR_MASK_ALL,ERR_MASK_NONE,
4951
};
5052

5153
// ===== can_frame =====

‎src/lib.rs

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
unsafe_op_in_unsafe_fn
104104
)]
105105

106-
use std::{io::ErrorKind,mem::size_of};
106+
use std::mem::size_of;
107107

108108
// Re-export the embedded_can crate so that applications can rely on
109109
// finding the same version we use.
@@ -184,66 +184,3 @@ pub(crate) fn as_bytes_mut<T: Sized>(val: &mut T) -> &mut [u8] {
184184
unsafe{ std::slice::from_raw_parts_mut(valas*mut_as*mutu8, sz)}
185185
}
186186

187-
// ===== embedded_can I/O traits =====
188-
189-
impl embedded_can::blocking::CanforCanSocket{
190-
typeFrame =CanFrame;
191-
typeError =Error;
192-
193-
/// Blocking call to receive the next frame from the bus.
194-
///
195-
/// This block and wait for the next frame to be received from the bus.
196-
/// If an error frame is received, it will be converted to a `CanError`
197-
/// and returned as an error.
198-
fnreceive(&mutself) ->Result<Self::Frame>{
199-
useCanFrame::*;
200-
matchself.read_frame(){
201-
Ok(Error(frame)) =>Err(frame.into_error().into()),
202-
Ok(frame) =>Ok(frame),
203-
Err(e) =>Err(e.into()),
204-
}
205-
}
206-
207-
/// Blocking transmit of a frame to the bus.
208-
fntransmit(&mutself,frame:&Self::Frame) ->Result<()>{
209-
self.write_frame_insist(frame).map_err(|err| err.into())
210-
}
211-
}
212-
213-
impl embedded_can::nb::CanforCanSocket{
214-
typeFrame =CanFrame;
215-
typeError =Error;
216-
217-
/// Non-blocking call to receive the next frame from the bus.
218-
///
219-
/// If an error frame is received, it will be converted to a `CanError`
220-
/// and returned as an error.
221-
/// If no frame is available, it returns a `WouldBlck` error.
222-
fnreceive(&mutself) -> nb::Result<Self::Frame,Self::Error>{
223-
useCanFrame::*;
224-
matchself.read_frame(){
225-
Ok(Data(frame)) =>Ok(Data(frame)),
226-
Ok(Remote(frame)) =>Ok(Remote(frame)),
227-
Ok(Error(frame)) =>Err(crate::Error::from(frame.into_error()).into()),
228-
Err(err) =>Err(match err.kind(){
229-
ErrorKind::WouldBlock => nb::Error::WouldBlock,
230-
_ =>crate::Error::from(err).into(),
231-
}),
232-
}
233-
}
234-
235-
/// Non-blocking transmit of a frame to the bus.
236-
fntransmit(&mutself,frame:&Self::Frame) -> nb::Result<Option<Self::Frame>,Self::Error>{
237-
matchself.write_frame(frame){
238-
Ok(_) =>Ok(None),
239-
Err(err) =>{
240-
match err.kind(){
241-
ErrorKind::WouldBlock =>Err(nb::Error::WouldBlock),
242-
// TODO: How to indicate buffer is full?
243-
// ErrorKind::StorageFull => Ok(frame),
244-
_ =>Err(Error::from(err).into()),
245-
}
246-
}
247-
}
248-
}
249-
}

‎src/socket.rs

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ use crate::{
1515
as_bytes, as_bytes_mut,
1616
frame::{can_frame_default, canfd_frame_default,AsPtr},
1717
id::CAN_ERR_MASK,
18-
CanAddr,CanAnyFrame,CanFdFrame,CanFrame,CanRawFrame,IoError,IoErrorKind,IoResult,
18+
CanAddr,CanAnyFrame,CanFdFrame,CanFrame,CanRawFrame,Error,IoError,IoErrorKind,IoResult,Result,
1919
};
2020
use libc::{canid_t, socklen_t,AF_CAN,EINPROGRESS};
2121
use socket2::SockAddr;
2222
use std::{
2323
fmt,
24-
io::{Read,Write},
24+
io::{Read,Write,ErrorKind},
2525
mem::{size_of, size_of_val},
2626
os::{
2727
raw::{c_int, c_void},
@@ -571,6 +571,67 @@ impl Write for CanSocket {
571571
}
572572
}
573573

574+
impl embedded_can::blocking::CanforCanSocket{
575+
typeFrame =CanFrame;
576+
typeError =Error;
577+
578+
/// Blocking call to receive the next frame from the bus.
579+
///
580+
/// This block and wait for the next frame to be received from the bus.
581+
/// If an error frame is received, it will be converted to a `CanError`
582+
/// and returned as an error.
583+
fnreceive(&mutself) ->Result<Self::Frame>{
584+
matchself.read_frame(){
585+
Ok(CanFrame::Error(frame)) =>Err(frame.into_error().into()),
586+
Ok(frame) =>Ok(frame),
587+
Err(e) =>Err(e.into()),
588+
}
589+
}
590+
591+
/// Blocking transmit of a frame to the bus.
592+
fntransmit(&mutself,frame:&Self::Frame) ->Result<()>{
593+
self.write_frame_insist(frame).map_err(|err| err.into())
594+
}
595+
}
596+
597+
impl embedded_can::nb::CanforCanSocket{
598+
typeFrame =CanFrame;
599+
typeError =Error;
600+
601+
/// Non-blocking call to receive the next frame from the bus.
602+
///
603+
/// If an error frame is received, it will be converted to a `CanError`
604+
/// and returned as an error.
605+
/// If no frame is available, it returns a `WouldBlck` error.
606+
fnreceive(&mutself) -> nb::Result<Self::Frame,Self::Error>{
607+
useCanFrame::*;
608+
matchself.read_frame(){
609+
Ok(Data(frame)) =>Ok(Data(frame)),
610+
Ok(Remote(frame)) =>Ok(Remote(frame)),
611+
Ok(Error(frame)) =>Err(crate::Error::from(frame.into_error()).into()),
612+
Err(err) =>Err(match err.kind(){
613+
ErrorKind::WouldBlock => nb::Error::WouldBlock,
614+
_ =>crate::Error::from(err).into(),
615+
}),
616+
}
617+
}
618+
619+
/// Non-blocking transmit of a frame to the bus.
620+
fntransmit(&mutself,frame:&Self::Frame) -> nb::Result<Option<Self::Frame>,Self::Error>{
621+
matchself.write_frame(frame){
622+
Ok(_) =>Ok(None),
623+
Err(err) =>{
624+
match err.kind(){
625+
ErrorKind::WouldBlock =>Err(nb::Error::WouldBlock),
626+
// TODO: How to indicate buffer is full?
627+
// ErrorKind::StorageFull => Ok(frame),
628+
_ =>Err(Error::from(err).into()),
629+
}
630+
}
631+
}
632+
}
633+
}
634+
574635
// ===== CanFdSocket =====
575636

576637
/// A socket for CAN FD devices.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp