make socketcan only build on linux
This commit is contained in:
parent
5d6e792a85
commit
cf21deed1b
|
@ -19,4 +19,4 @@ func (cdb *CanDB) Recv() (*Frame, error) {
|
||||||
panic("not implemented") // TODO: Implement
|
panic("not implemented") // TODO: Implement
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCanDB()
|
func NewCanDB() {}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
//go:build linux
|
||||||
|
|
||||||
package socketcan
|
package socketcan
|
||||||
|
|
||||||
// TODO: implement netlink support to set baud rate and other parameters.
|
// TODO: implement netlink support to set baud rate and other parameters.
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
//go:build linux
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Package socketcan provides a wrapper around the Linux socketCAN interface.
|
Package socketcan provides a wrapper around the Linux socketCAN interface.
|
||||||
*/
|
*/
|
||||||
|
@ -21,6 +23,12 @@ type CanSocket struct {
|
||||||
fd int
|
fd int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CanFilter interface {
|
||||||
|
Inverted() bool
|
||||||
|
Mask() uint32
|
||||||
|
Id() uint32
|
||||||
|
}
|
||||||
|
|
||||||
// standardFrameSize is the full size in bytes of the default CAN frame.
|
// standardFrameSize is the full size in bytes of the default CAN frame.
|
||||||
const standardFrameSize = unix.CAN_MTU
|
const standardFrameSize = unix.CAN_MTU
|
||||||
|
|
||||||
|
@ -96,15 +104,15 @@ func (sck *CanSocket) SetFDMode(enable bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFilters will set the socketCAN filters based on a standard CAN filter list.
|
// SetFilters will set the socketCAN filters based on a standard CAN filter list.
|
||||||
func (sck *CanSocket) SetFilters(filters []gotelem.CanFilter) error {
|
func (sck *CanSocket) SetFilters(filters []CanFilter) error {
|
||||||
|
|
||||||
// helper function to make a filter.
|
// helper function to make a filter.
|
||||||
// id and mask are straightforward, if inverted is true, the filter
|
// id and mask are straightforward, if inverted is true, the filter
|
||||||
// will reject anything that matches.
|
// will reject anything that matches.
|
||||||
makeFilter := func(filter gotelem.CanFilter) unix.CanFilter {
|
makeFilter := func(filter CanFilter) unix.CanFilter {
|
||||||
f := unix.CanFilter{Id: filter.Id, Mask: filter.Mask}
|
f := unix.CanFilter{Id: filter.Id(), Mask: filter.Mask()}
|
||||||
|
|
||||||
if filter.Inverted {
|
if filter.Inverted() {
|
||||||
f.Id = f.Id | unix.CAN_INV_FILTER
|
f.Id = f.Id | unix.CAN_INV_FILTER
|
||||||
}
|
}
|
||||||
return f
|
return f
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
//go:build linux
|
||||||
|
|
||||||
package socketcan
|
package socketcan
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
Loading…
Reference in a new issue