CAN Filtering(setsockopt) and Send implementation
robcat030 opened this issue · 0 comments
The library works great for what you've designed it for! I'm trying to implement an application-level filtering using setsockopt, but it doesn't seem to be working correctly. Here's the code I tried:
In bindings.dart:
@override
int setsockopt(int __fd, int __level, int optname,
ffi.Pointer<ffi.Void> __optval, int __optlen) {
return _native.setsockopt(__fd, __level, optname, __optval, __optlen);
}
In linux_can.dart setup()
// Set Filter Mask
final rfilterPtr = calloc.allocate<can_filter>(sizeOf<can_filter>());
final rfilter = rfilterPtr.ref;
final filterpointer = rfilterPtr.cast<Void>();
rfilter.can_id = 0X7E0;
rfilter.can_mask = 0xFFF;
final length = 2;
final filter = _libC.setsockopt(
_socket, SOL_CAN_RAW, CAN_RAW_FILTER, filterpointer, length);
if (filter < 0)
throw SocketException("Failed to set filter/mask for : $_socket");
calloc.free(rfilterPtr);
I'm not sure if it's an issue with my code or not, any help would be greatly appreciated. I'd also like to implement recv() and send() in the future. Right now I'm using python-can but I'd like to switch to this so that I can use a flutter GUI. Thanks!