From d98f4cda3b20c2e0b58e82d32150cf330e4fbe11 Mon Sep 17 00:00:00 2001 From: Arkadiusz Drabczyk Date: Thu, 28 Sep 2023 10:19:22 +0200 Subject: [PATCH] feat: add interface It'll be easier to mock candevice functionality in other packages. --- pkg/candevice/device_linux.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/candevice/device_linux.go b/pkg/candevice/device_linux.go index bfc713f..89c55a8 100644 --- a/pkg/candevice/device_linux.go +++ b/pkg/candevice/device_linux.go @@ -41,8 +41,18 @@ type Device struct { ifi ifInfoMsg } +type CanDevice interface { + Bitrate() (uint32, error) + Info() (Info, error) + IsUp() (bool, error) + SetBitrate(uint32) error + SetDown() error + SetListenOnlyMode(bool) error + SetUp() error +} + // Creates a handle to a CAN device specified by name, e.g. can0. -func New(deviceName string) (*Device, error) { +func New(deviceName string) (CanDevice, error) { iface, err := net.InterfaceByName(deviceName) if err != nil { return nil, err