init method
override
Initializes the connection to the device.
Implementation
@override
Future<bool> init() async {
_can = nativeLib.BurtCan_create(canInterface.toNativeUtf8(), canTimeout, canType);
await Process.run("sudo", ["ip", "link", "set", "can0", "down"]);
final result = await Process.run("sudo", ["ip", "link", "set", "can0", "up", "type", "can", "bitrate", "500000"]);
if (result.exitCode != 0) {
logger.critical("Could not start can0", body: "sudo ip link set can0 up type can bitrate 500000 failed:\n${result.stderr}");
hasError = true;
return false;
}
final error = nativeLib.BurtCan_open(_can!).stringError;
if (error != null) {
hasError = true;
logger.critical("Could not start the CAN bus", body: error);
return false;
}
_startListening();
logger.info("Listening on CAN interface $canInterface");
return true;
}