From 0c5d7b6ddbd728d684ffd86960ecee46a4147333 Mon Sep 17 00:00:00 2001 From: yoursmengle Date: Tue, 5 Jul 2022 10:28:59 +0800 Subject: [PATCH 01/10] add extended flag into ID --- frame.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frame.go b/frame.go index 19e8200..f1df3b6 100644 --- a/frame.go +++ b/frame.go @@ -19,6 +19,9 @@ func (f CanFrame) putID(buf []byte) { if f.RTR { f.ID |= CAN_RTR_FLAG } + if f.Extended { + f.ID |= CAN_EFF_FLAG + } binary.LittleEndian.PutUint32(buf[0:4], f.ID) } From 9c456e9e96dc03c209476340365e0927df85942a Mon Sep 17 00:00:00 2001 From: yoursmengle Date: Wed, 13 Jul 2022 13:48:02 +0800 Subject: [PATCH 02/10] add filter --- raw_interface_linux.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/raw_interface_linux.go b/raw_interface_linux.go index bd7ffc4..50e52b7 100644 --- a/raw_interface_linux.go +++ b/raw_interface_linux.go @@ -69,3 +69,21 @@ func IsClosedInterfaceError(err error) bool { } return errno == syscall.EBADF || errno == syscall.ENETDOWN || errno == syscall.ENODEV } + +type CanFilter struct { + canID uint32 + mask uint32 +} + +func (itf *rawInterface) Addfilter(rfilter []CanFilter) error { + if rfilter == nil { + return nil + } + + unix.setsockopt(ift.fd, unix.SOL_CAN_RAW, unix.CAN_RAW_FILTER, &rfilter, len(rfilter)) + join_filter := 1 + unix.setsockopt(ift.fd, unix.SOL_CAN_RAW, unix.CAN_RAW_JOIN_FILTERS, &join_filter, 4) + + return nil +} + From 307df302a04f7dc3ce3f9af77e155a9f3aabbc42 Mon Sep 17 00:00:00 2001 From: yoursmengle Date: Fri, 15 Jul 2022 11:36:41 +0800 Subject: [PATCH 03/10] add filter --- raw_interface_linux.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/raw_interface_linux.go b/raw_interface_linux.go index 50e52b7..a3de134 100644 --- a/raw_interface_linux.go +++ b/raw_interface_linux.go @@ -2,7 +2,6 @@ package socketcan import ( "syscall" - "golang.org/x/sys/unix" ) @@ -80,10 +79,12 @@ func (itf *rawInterface) Addfilter(rfilter []CanFilter) error { return nil } - unix.setsockopt(ift.fd, unix.SOL_CAN_RAW, unix.CAN_RAW_FILTER, &rfilter, len(rfilter)) + err := syscall.Setsockopt(itf.fd, syscall.SOL_CAN_RAW, syscall.CAN_RAW_FILTER, &rfilter, len(rfilter)) + if err != nil { + return err + } + join_filter := 1 - unix.setsockopt(ift.fd, unix.SOL_CAN_RAW, unix.CAN_RAW_JOIN_FILTERS, &join_filter, 4) - return nil + return syscall.Setsockopt(itf.fd, syscall.SOL_CAN_RAW, syscall.CAN_RAW_JOIN_FILTERS, &join_filter, 4) } - From c55fad4f6d5d84656d0a986a5b65cc15e39cab52 Mon Sep 17 00:00:00 2001 From: yoursmengle Date: Fri, 15 Jul 2022 14:26:06 +0800 Subject: [PATCH 04/10] add filter --- .vscode/settings.json | 5 +++ go.mod | 5 +++ go.sum | 2 ++ raw_interface_linux.go | 20 ++--------- sys_setopt.go | 79 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 18 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 go.mod create mode 100644 go.sum create mode 100644 sys_setopt.go diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..30097c1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "socket.h": "c" + } +} \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..dc346a1 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module socketcan + +go 1.18 + +require golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..975cf95 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e h1:NHvCuwuS43lGnYhten69ZWqi2QOj/CiDNcKbVqwVoew= +golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/raw_interface_linux.go b/raw_interface_linux.go index a3de134..4037987 100644 --- a/raw_interface_linux.go +++ b/raw_interface_linux.go @@ -69,22 +69,6 @@ func IsClosedInterfaceError(err error) bool { return errno == syscall.EBADF || errno == syscall.ENETDOWN || errno == syscall.ENODEV } -type CanFilter struct { - canID uint32 - mask uint32 -} - -func (itf *rawInterface) Addfilter(rfilter []CanFilter) error { - if rfilter == nil { - return nil - } - - err := syscall.Setsockopt(itf.fd, syscall.SOL_CAN_RAW, syscall.CAN_RAW_FILTER, &rfilter, len(rfilter)) - if err != nil { - return err - } - - join_filter := 1 - - return syscall.Setsockopt(itf.fd, syscall.SOL_CAN_RAW, syscall.CAN_RAW_JOIN_FILTERS, &join_filter, 4) +func (itf *rawInterface) AddfilterPass(canid_pass uint) error { + return can_filter_pass(itf.fd, canid_pass) } diff --git a/sys_setopt.go b/sys_setopt.go new file mode 100644 index 0000000..4be8c97 --- /dev/null +++ b/sys_setopt.go @@ -0,0 +1,79 @@ +package socketcan + +/* +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CAN_FILTER_PASS 0x01 //过滤方式-通过 +#define CAN_FILTER_REJECT 0x02 //过滤方式-拒绝 + +int rcvFiltersSet(int canfd, const uint canId, const uint filterType) +{ + if(canfd <= 0) //canfd就不用解释了… + return -1; + + if(0 == canId){ + setsockopt(canfd, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0); //不需要接收任何报文 + return 0; + } + + struct can_filter rfilter; + + if(filterType & CAN_FILTER_PASS){ + rfilter.can_id = canId; + } else { + rfilter.can_id = canId | CAN_INV_FILTER; + } + if(canId &0x80000000) { + rfilter.can_mask = 0x1fffffff; + } else { + rfilter.can_mask = 0x7ff; + } + + if(filterType & CAN_FILTER_REJECT){ + int join_filter = 1; + setsockopt(canfd, SOL_CAN_RAW, CAN_RAW_JOIN_FILTERS, &join_filter, sizeof(join_filter)); + } + setsockopt(canfd, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter)); + return 0; +} +*/ +import "C" + +import ( + "errors" +) +/* +*const uint can_id_reject[] = {0x123, 0x11111678, 0x282}; //除这三种canid之外的报文,都接收 +canRcvFiltersSet(canfd, can_id_reject, sizeof(can_id_reject)/sizeof(uint), CAN_FILTER_REJECT); + +*const uint can_id_pass[] = {0x123, 0x11111678, 0x282}; //只接收这三种canid报文,其它不接收 +canRcvFiltersSet(canfd, can_id_pass, sizeof(can_id_pass)/sizeof(uint), CAN_FILTER_PASS); +*/ + +func can_filter_pass(fd int, canid_pass uint ) error { + succ := C.rcvFiltersSet(C.int(fd), C.uint(canid_pass), C.CAN_FILTER_PASS) + if succ == 0 { + return nil + } + + return errors.New("can filter failed") +} From 31a733e825473d657f09daeb7225d076fc7a54be Mon Sep 17 00:00:00 2001 From: yoursmengle Date: Fri, 15 Jul 2022 14:43:25 +0800 Subject: [PATCH 05/10] update filter --- sys_setopt.go => filter.go | 6 ++++-- raw_interface_linux.go | 4 ---- 2 files changed, 4 insertions(+), 6 deletions(-) rename sys_setopt.go => filter.go (92%) diff --git a/sys_setopt.go b/filter.go similarity index 92% rename from sys_setopt.go rename to filter.go index 4be8c97..d110a8e 100644 --- a/sys_setopt.go +++ b/filter.go @@ -61,6 +61,8 @@ import "C" import ( "errors" ) + + /* *const uint can_id_reject[] = {0x123, 0x11111678, 0x282}; //除这三种canid之外的报文,都接收 canRcvFiltersSet(canfd, can_id_reject, sizeof(can_id_reject)/sizeof(uint), CAN_FILTER_REJECT); @@ -69,8 +71,8 @@ canRcvFiltersSet(canfd, can_id_reject, sizeof(can_id_reject)/sizeof(uint), CAN_F canRcvFiltersSet(canfd, can_id_pass, sizeof(can_id_pass)/sizeof(uint), CAN_FILTER_PASS); */ -func can_filter_pass(fd int, canid_pass uint ) error { - succ := C.rcvFiltersSet(C.int(fd), C.uint(canid_pass), C.CAN_FILTER_PASS) +func (itf *rawInterface) AddfilterPass(canid_pass uint) error { + succ := C.rcvFiltersSet(C.int(itf.fd), C.uint(canid_pass), C.CAN_FILTER_PASS) if succ == 0 { return nil } diff --git a/raw_interface_linux.go b/raw_interface_linux.go index 4037987..e6b4e23 100644 --- a/raw_interface_linux.go +++ b/raw_interface_linux.go @@ -68,7 +68,3 @@ func IsClosedInterfaceError(err error) bool { } return errno == syscall.EBADF || errno == syscall.ENETDOWN || errno == syscall.ENODEV } - -func (itf *rawInterface) AddfilterPass(canid_pass uint) error { - return can_filter_pass(itf.fd, canid_pass) -} From 38d7e75ea65664dff00dc3b509e4d9f995e8b284 Mon Sep 17 00:00:00 2001 From: yoursmengle Date: Fri, 15 Jul 2022 14:49:10 +0800 Subject: [PATCH 06/10] update readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index fe18922..9bbc791 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ # golang-socketcan + +fork from https://github.com/atuleu/golang-socketcan \ No newline at end of file From 8b161158824df332a160493618d162b84ae07e2f Mon Sep 17 00:00:00 2001 From: yoursmengle Date: Fri, 15 Jul 2022 15:02:20 +0800 Subject: [PATCH 07/10] add func into interface --- raw_interface.go | 1 + 1 file changed, 1 insertion(+) diff --git a/raw_interface.go b/raw_interface.go index 7b48bf7..0e348b8 100644 --- a/raw_interface.go +++ b/raw_interface.go @@ -4,4 +4,5 @@ type RawInterface interface { Send(CanFrame) error Receive() (CanFrame, error) Close() error + AddfilterPass(uint) error } From 37ce8c2dd7aebcc29b2069ac57b0391396e9ea0e Mon Sep 17 00:00:00 2001 From: yoursmengle Date: Fri, 15 Jul 2022 15:17:36 +0800 Subject: [PATCH 08/10] remove useless files --- filter.go | 81 ------------------------------------------ frame.go | 9 +++-- raw_interface_linux.go | 68 +++++++++++++++++++++++++++++++++++ raw_interface_stub.go | 33 ----------------- 4 files changed, 72 insertions(+), 119 deletions(-) delete mode 100644 filter.go delete mode 100644 raw_interface_stub.go diff --git a/filter.go b/filter.go deleted file mode 100644 index d110a8e..0000000 --- a/filter.go +++ /dev/null @@ -1,81 +0,0 @@ -package socketcan - -/* -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define CAN_FILTER_PASS 0x01 //过滤方式-通过 -#define CAN_FILTER_REJECT 0x02 //过滤方式-拒绝 - -int rcvFiltersSet(int canfd, const uint canId, const uint filterType) -{ - if(canfd <= 0) //canfd就不用解释了… - return -1; - - if(0 == canId){ - setsockopt(canfd, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0); //不需要接收任何报文 - return 0; - } - - struct can_filter rfilter; - - if(filterType & CAN_FILTER_PASS){ - rfilter.can_id = canId; - } else { - rfilter.can_id = canId | CAN_INV_FILTER; - } - if(canId &0x80000000) { - rfilter.can_mask = 0x1fffffff; - } else { - rfilter.can_mask = 0x7ff; - } - - if(filterType & CAN_FILTER_REJECT){ - int join_filter = 1; - setsockopt(canfd, SOL_CAN_RAW, CAN_RAW_JOIN_FILTERS, &join_filter, sizeof(join_filter)); - } - setsockopt(canfd, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter)); - return 0; -} -*/ -import "C" - -import ( - "errors" -) - - -/* -*const uint can_id_reject[] = {0x123, 0x11111678, 0x282}; //除这三种canid之外的报文,都接收 -canRcvFiltersSet(canfd, can_id_reject, sizeof(can_id_reject)/sizeof(uint), CAN_FILTER_REJECT); - -*const uint can_id_pass[] = {0x123, 0x11111678, 0x282}; //只接收这三种canid报文,其它不接收 -canRcvFiltersSet(canfd, can_id_pass, sizeof(can_id_pass)/sizeof(uint), CAN_FILTER_PASS); -*/ - -func (itf *rawInterface) AddfilterPass(canid_pass uint) error { - succ := C.rcvFiltersSet(C.int(itf.fd), C.uint(canid_pass), C.CAN_FILTER_PASS) - if succ == 0 { - return nil - } - - return errors.New("can filter failed") -} diff --git a/frame.go b/frame.go index f1df3b6..7502571 100644 --- a/frame.go +++ b/frame.go @@ -12,16 +12,15 @@ type CanFrame struct { func (f CanFrame) putID(buf []byte) { if f.Extended == true { - f.ID = f.ID & CAN_EFF_MASK + f.ID &= CAN_EFF_MASK + f.ID |= CAN_EFF_FLAG } else { - f.ID = f.ID & CAN_SFF_MASK + f.ID &= CAN_SFF_MASK } + if f.RTR { f.ID |= CAN_RTR_FLAG } - if f.Extended { - f.ID |= CAN_EFF_FLAG - } binary.LittleEndian.PutUint32(buf[0:4], f.ID) } diff --git a/raw_interface_linux.go b/raw_interface_linux.go index e6b4e23..8da8250 100644 --- a/raw_interface_linux.go +++ b/raw_interface_linux.go @@ -1,7 +1,66 @@ package socketcan +/* +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CAN_FILTER_PASS 0x01 //过滤方式-通过 +#define CAN_FILTER_REJECT 0x02 //过滤方式-拒绝 + +int rcvFiltersSet(int canfd, const uint canId, const uint filterType) +{ + if(canfd <= 0) //canfd就不用解释了… + return -1; + + if(0 == canId){ + setsockopt(canfd, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0); //不需要接收任何报文 + return 0; + } + + struct can_filter rfilter; + + if(filterType & CAN_FILTER_PASS){ + rfilter.can_id = canId; + } else { + rfilter.can_id = canId | CAN_INV_FILTER; + } + if(canId &0x80000000) { + rfilter.can_mask = 0x1fffffff; + } else { + rfilter.can_mask = 0x7ff; + } + + if(filterType & CAN_FILTER_REJECT){ + int join_filter = 1; + setsockopt(canfd, SOL_CAN_RAW, CAN_RAW_JOIN_FILTERS, &join_filter, sizeof(join_filter)); + } + setsockopt(canfd, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter)); + return 0; +} +*/ +import "C" + import ( "syscall" + "errors" "golang.org/x/sys/unix" ) @@ -68,3 +127,12 @@ func IsClosedInterfaceError(err error) bool { } return errno == syscall.EBADF || errno == syscall.ENETDOWN || errno == syscall.ENODEV } + +func (itf *rawInterface) AddfilterPass(canid_pass uint) error { + succ := C.rcvFiltersSet(C.int(itf.fd), C.uint(canid_pass), C.CAN_FILTER_PASS) + if succ == 0 { + return nil + } + + return errors.New("can filter failed") +} diff --git a/raw_interface_stub.go b/raw_interface_stub.go deleted file mode 100644 index 04a6cd1..0000000 --- a/raw_interface_stub.go +++ /dev/null @@ -1,33 +0,0 @@ -// +build !linux - -package socketcan - -type rawInterfaceStub struct { -} - -func (itf *rawInterfaceStub) SocketFD() int { - return 0 -} - -func NewRawInterface(ifName string) (RawInterface, error) { - res := &rawInterfaceStub{} - return res, nil -} - -func (itf *rawInterfaceStub) Close() error { - return nil -} - -func (itf *rawInterfaceStub) Send(f CanFrame) error { - return nil -} - -func (itf *rawInterfaceStub) Receive() (CanFrame, error) { - f := CanFrame{Dlc: 0, Data: make([]byte, 8)} - select {} - return f, nil -} - -func IsClosedInterfaceError(err error) bool { - return false -} From ff4578c62df02b8263e0286d0820d7abb31512b7 Mon Sep 17 00:00:00 2001 From: yoursmengle Date: Fri, 15 Jul 2022 16:52:31 +0800 Subject: [PATCH 09/10] update interface --- constant.go | 10 ------- interface.go | 21 --------------- interface_linux.go | 35 ------------------------- raw_interface.go | 8 ------ raw_interface_linux.go | 59 ++++++++++++++++++++++++++---------------- 5 files changed, 36 insertions(+), 97 deletions(-) delete mode 100644 constant.go delete mode 100644 interface.go delete mode 100644 interface_linux.go delete mode 100644 raw_interface.go diff --git a/constant.go b/constant.go deleted file mode 100644 index a18115a..0000000 --- a/constant.go +++ /dev/null @@ -1,10 +0,0 @@ -// +build !linux - -package socketcan - -const ( - CAN_EFF_MASK uint32 = 0x01ffffff - CAN_SFF_MASK uint32 = 0x000007ff - CAN_RTR_FLAG uint32 = 1 << 30 - CAN_EFF_FLAG uint32 = 1 << 31 -) diff --git a/interface.go b/interface.go deleted file mode 100644 index d3425c7..0000000 --- a/interface.go +++ /dev/null @@ -1,21 +0,0 @@ -package socketcan - -import ( - "time" - - "golang.org/x/sys/unix" -) - -type Interface interface { - SocketFD() int -} - -func SetRecvTimeout(i Interface, timeout time.Duration) error { - tv := unix.NsecToTimeval(timeout.Nanoseconds()) - return unix.SetsockoptTimeval(i.SocketFD(), unix.SOL_SOCKET, unix.SO_RCVTIMEO, &tv) -} - -func SetSendTimeout(i Interface, timeout time.Duration) error { - tv := unix.NsecToTimeval(timeout.Nanoseconds()) - return unix.SetsockoptTimeval(i.SocketFD(), unix.SOL_SOCKET, unix.SO_SNDTIMEO, &tv) -} diff --git a/interface_linux.go b/interface_linux.go deleted file mode 100644 index 209606b..0000000 --- a/interface_linux.go +++ /dev/null @@ -1,35 +0,0 @@ -package socketcan - -import ( - "fmt" - "unsafe" - - "golang.org/x/sys/unix" -) - -func getIfIndex(itf Interface, ifName string) (int, error) { - ifNameRaw, err := unix.ByteSliceFromString(ifName) - if err != nil { - return 0, err - } - if len(ifNameRaw) > unix.IFNAMSIZ { - return 0, fmt.Errorf("Maximum ifname length is %d characters", unix.IFNAMSIZ) - } - - type ifreq struct { - Name [unix.IFNAMSIZ]byte - Index int - } - var ifReq ifreq - fd := itf.SocketFD() - copy(ifReq.Name[:], ifNameRaw) - _, _, errno := unix.Syscall(unix.SYS_IOCTL, - uintptr(fd), - unix.SIOCGIFINDEX, - uintptr(unsafe.Pointer(&ifReq))) - if errno != 0 { - return 0, fmt.Errorf("ioctl: %v", errno) - } - - return ifReq.Index, nil -} diff --git a/raw_interface.go b/raw_interface.go deleted file mode 100644 index 0e348b8..0000000 --- a/raw_interface.go +++ /dev/null @@ -1,8 +0,0 @@ -package socketcan - -type RawInterface interface { - Send(CanFrame) error - Receive() (CanFrame, error) - Close() error - AddfilterPass(uint) error -} diff --git a/raw_interface_linux.go b/raw_interface_linux.go index 8da8250..0911cc9 100644 --- a/raw_interface_linux.go +++ b/raw_interface_linux.go @@ -59,44 +59,65 @@ int rcvFiltersSet(int canfd, const uint canId, const uint filterType) import "C" import ( - "syscall" "errors" "golang.org/x/sys/unix" ) -type rawInterface struct { +type RawInterface struct { fd int name string } -func (itf *rawInterface) SocketFD() int { - return itf.fd +func (itf *RawInterface) getIfIndex(ifName string) (int, error) { + ifNameRaw, err := unix.ByteSliceFromString(ifName) + if err != nil { + return 0, err + } + if len(ifNameRaw) > unix.IFNAMSIZ { + return 0, fmt.Errorf("Maximum ifname length is %d characters", unix.IFNAMSIZ) + } + + type ifreq struct { + Name [unix.IFNAMSIZ]byte + Index int + } + var ifReq ifreq + copy(ifReq.Name[:], ifNameRaw) + _, _, errno := unix.Syscall(unix.SYS_IOCTL, + uintptr(itf.fd), + unix.SIOCGIFINDEX, + uintptr(unsafe.Pointer(&ifReq))) + if errno != 0 { + return 0, fmt.Errorf("ioctl: %v", errno) + } + + return ifReq.Index, nil } -func NewRawInterface(ifName string) (RawInterface, error) { - res := &rawInterface{name: ifName} +func NewCanItf(ifName string) (RawInterface, error) { + itf := RawInterface{name: ifName} var err error - res.fd, err = unix.Socket(unix.AF_CAN, unix.SOCK_RAW, unix.CAN_RAW) + itf.fd, err = unix.Socket(unix.AF_CAN, unix.SOCK_RAW, unix.CAN_RAW) if err != nil { return nil, err } - ifIndex, err := getIfIndex(res, ifName) + ifIndex, err := getIfIndex(itf, ifName) if err != nil { - return res, err + return itf, err } addr := &unix.SockaddrCAN{Ifindex: ifIndex} - err = unix.Bind(res.fd, addr) + err = unix.Bind(itf.fd, addr) - return res, err + return itf, err } -func (itf *rawInterface) Close() error { +func (itf *RawInterface) Close() error { return unix.Close(itf.fd) } -func (itf *rawInterface) Send(f CanFrame) error { +func (itf *RawInterface) Send(f CanFrame) error { frameBytes := make([]byte, 16) f.putID(frameBytes) frameBytes[4] = f.Dlc @@ -105,7 +126,7 @@ func (itf *rawInterface) Send(f CanFrame) error { return err } -func (itf *rawInterface) Receive() (CanFrame, error) { +func (itf *RawInterface) Receive() (CanFrame, error) { f := CanFrame{Data: make([]byte, 8)} frameBytes := make([]byte, 16) _, err := unix.Read(itf.fd, frameBytes) @@ -120,15 +141,7 @@ func (itf *rawInterface) Receive() (CanFrame, error) { return f, nil } -func IsClosedInterfaceError(err error) bool { - errno, ok := err.(syscall.Errno) - if ok == false { - return false - } - return errno == syscall.EBADF || errno == syscall.ENETDOWN || errno == syscall.ENODEV -} - -func (itf *rawInterface) AddfilterPass(canid_pass uint) error { +func (itf *RawInterface) AddfilterPass(canid_pass uint) error { succ := C.rcvFiltersSet(C.int(itf.fd), C.uint(canid_pass), C.CAN_FILTER_PASS) if succ == 0 { return nil From c864eb96de99fd19c93d1259555205519f9b8a4c Mon Sep 17 00:00:00 2001 From: Alexandre Tuleu Date: Fri, 15 Jul 2022 11:27:54 +0200 Subject: [PATCH 10/10] Delete settings.json It seems something specific to your IDE I think it should be also in the .gitignore rule --- .vscode/settings.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 30097c1..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "files.associations": { - "socket.h": "c" - } -} \ No newline at end of file