native library
dart:io + dart:ffi-only additions for mcp_io_can.
Importing the main mcp_io_can library keeps the package web-safe
(the abstract CanTransport + InMemoryCanTransport). Importing
this native library opts in to platform-native transports that
rely on dart:ffi.
Today only Linux SocketCAN ships; PEAK PCAN-Basic (Windows) and Vector XL (Windows / pro) are tracked as follow-up packages so they can land per-vendor SDK without dragging the rest of the package into the per-vendor licensing surface.
import 'package:mcp_io_can/mcp_io_can.dart';
import 'package:mcp_io_can/native.dart';
final transport = SocketCanTransport(interfaceName: 'vcan0');
final adapter = CanAdapter(deviceId: 'bus', transport: transport);
await adapter.connect();
Classes
- PcanBaud
- PcanBindings
- PcanCanTransport
- PcanHandle
- PcanMsgType
- PcanStatus
- SocketCanBindings
- SocketCanTransport
- TpcanMsg
-
TPCANMsg— classic CAN frame. 14 bytes packed. - TpcanMsgFd
-
TPCANMsgFD— CAN-FD frame. 70 bytes packed. - TpcanTimestamp
-
TPCANTimestamp— receive timestamp. 8 bytes packed. - VectorXlBindings
- VectorXlBusType
- VectorXlCanMsg
-
XLcanMsg— classic CAN message body inside an VectorXlEvent. 32 bytes packed (vxlapi.h v4). - VectorXlCanMsgFlag
- VectorXlCanTransport
- VectorXlEvent
-
XLeventlegacy struct — 48 bytes. - VectorXlEventTag
- VectorXlInterfaceVersion
- VectorXlStatus
Constants
- kAfCan → const int
-
Address family for CAN —
AF_CAN. - kCanFdFrameSize → const int
-
Size of
struct canfd_frame(CAN-FD frame layout). - kCanFrameSize → const int
-
Size of
struct can_frame. - kCanRaw → const int
-
CAN_RAW— the raw CAN protocol. - kCanRawFdFrames → const int
-
CAN_RAW_FD_FRAMES— option name. When set to non-zero, the kernel allows reading and writing 72-bytestruct canfd_framevia the same socket. When zero (default), only 16-bytestruct can_frameis exchanged. - kIfNameSize → const int
-
IFNAMSIZ— maximum length of an interface name (incl. NUL). - kIfReqSize → const int
-
Effective ABI size of
struct ifreq(most Linux archs). - kPfCan → const int
-
Protocol family for CAN —
PF_CAN. Same value as kAfCan. - kSiocgIfIndex → const int
-
SIOCGIFINDEX— translate interface name → index. (Linux x86/x86_64) - kSockAddrCanSize → const int
-
Size of
struct sockaddr_canon Linux x86_64. - kSockRaw → const int
-
SOCK_RAW. - kSolCanRaw → const int
-
SOL_CAN_RAW— option level forsetsockopt(fd, SOL_CAN_RAW, ...). - kVectorXlCanExtMsgId → const int
-
XL_CAN_EXT_MSG_ID— top bit ofXLcanMsg.idset ⇒ extended.
Functions
-
allocIfReq(
String name) → Pointer< Uint8> -
Allocate a properly-sized
struct ifreqand copynameinto theifr_namefield. Caller frees withcalloc.free. -
allocSockaddrCan(
int ifIndex) → Pointer< Uint8> -
Allocate and populate a
struct sockaddr_canfor AF_CAN with the supplied interface index. -
readIfReqIfIndex(
Pointer< Uint8> ifreq) → int -
Read the
ifr_ifindexfield from anifreqpopulated byioctl(SIOCGIFINDEX). The field sits at byte offset 16 (immediately afterifr_name[16]), little-endian on Linux/x86 + arm64.
Typedefs
-
BindDart
= int Function(int fd, Pointer<
Void> addr, int addrLen) -
BindNative
= Int32 Function(Int32 fd, Pointer<
Void> addr, Uint32 addrLen) - CloseDart = int Function(int fd)
- CloseNative = Int32 Function(Int32 fd)
-
IoctlDart
= int Function(int fd, int request, Pointer<
Void> arg) -
IoctlNative
= Int32 Function(Int32 fd, UnsignedLong request, Pointer<
Void> arg) -
ReadWriteDart
= int Function(int fd, Pointer<
Uint8> buf, int count) -
ReadWriteNative
= IntPtr Function(Int32 fd, Pointer<
Uint8> buf, IntPtr count) -
SetsockoptDart
= int Function(int fd, int level, int optname, Pointer<
Void> optval, int optlen) -
SetsockoptNative
= Int32 Function(Int32 fd, Int32 level, Int32 optname, Pointer<
Void> optval, Uint32 optlen) - SocketDart = int Function(int domain, int type, int protocol)
- SocketNative = Int32 Function(Int32 domain, Int32 type, Int32 protocol)