Fix Linux USB open crash and the glibc 2.39 release bundle.
BETA-99.0.0 segfaults when a USB companion transmits as soon as the port opens, and the Linux release fails to load on Ubuntu 24.04 and Linux Mint 22 (glibc 2.39). Fixes #600. fl_open starts SerialThread before Dart installs fl_set_callback. A Seeed Wio Tracker L1 sends bytes immediately, and the reader called that null pointer (segfault at ip 0, FlSerial+0x44b8). Vendor MeshEnvy/flserial e1864de under third_party/flserial. That is the 0.3.5 FFI API this app already calls (openPort, setCallback, setByteSize8, setDTR), not official grzesl/flserial 0.7.3. The reader waits until the callback is set, and the port mutexes are initialized before the thread starts. Merging this makes zjs81/meshcore-open the owner of that vendored copy. The release libflserial.so needed GLIBC_2.42 for cfsetispeed and cfsetospeed, so USB discovery failed on glibc 2.39 before the port opened. Bind those symbols at GLIBC_2.2.5 and pass the legacy baud values those symbols expect. 115200 is octal 0010002. glibc 2.42 turned the B* macros into plain numbers, so passing 115200 to the old symbol would select the wrong rate. flutter_onnxruntime 1.9.0 needs libonnxruntime.so.1 from ONNX Runtime 1.28.3. The zip did not ship that file, and the plugin RUNPATH was the build machine's download directory. The loader uses the plugin path for this library. The install copies libonnxruntime.so, .so.1, .so.1.28.3, and libonnxruntime_providers_shared.so into bundle/lib. The plugin build RPATH is $ORIGIN followed by the download directory: $ORIGIN is bundle/lib at runtime, and the download directory is what ld needs while linking. Dropping it makes the release link fail. The executable keeps DT_RPATH $ORIGIN/lib for its own plugins. Checked on Ubuntu 26.04.1 (glibc 2.43) with Flutter 3.47.7. Opening /dev/ttyACM0 at 115200 set both termios2 speeds to 115200 and delivered data after fl_set_callback (last length 402). The built libflserial.so has no GLIBC_2.42 requirement. flutter build linux --release succeeded. With the plugin's absolute build path removed and LD_LIBRARY_PATH unset, ldd resolved libonnxruntime.so.1 from bundle/lib.
This commit is contained in:
1 parent
3bee159c4f
commit
2474389099
74 files changed
+16313
-4
No files matched your search
+452
@@ -0,0 +1,452 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:flserial/flserial_exception.dart';
|
||||
|
||||
import 'flserial_bindings_generated.dart';
|
||||
|
||||
const String _libName = 'flserial';
|
||||
const int _serialIOBuffLen = 1024 * 8;
|
||||
|
||||
/// The dynamic library in which the symbols for [FlserialBindings] can be found.
|
||||
final DynamicLibrary dylib = () {
|
||||
if (Platform.isMacOS || Platform.isIOS) {
|
||||
return DynamicLibrary.open('$_libName.framework/$_libName');
|
||||
}
|
||||
if (Platform.isAndroid || Platform.isLinux) {
|
||||
return DynamicLibrary.open('lib$_libName.so');
|
||||
}
|
||||
if (Platform.isWindows) {
|
||||
return DynamicLibrary.open('$_libName.dll');
|
||||
}
|
||||
throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
|
||||
}();
|
||||
|
||||
/// The bindings to the native functions in [_dylib].
|
||||
final FlserialBindings bindings = FlserialBindings(dylib);
|
||||
|
||||
/// Native pointer to string conversion
|
||||
String nativeInt8ToString(Pointer<Int8> pointer, {bool allowMalformed = true}) {
|
||||
var ptrName = pointer.cast<Utf8>();
|
||||
final ptrNameCodeUnits = pointer.cast<Uint8>();
|
||||
var list = ptrNameCodeUnits.asTypedList(ptrName.length);
|
||||
return utf8.decode(list, allowMalformed: allowMalformed);
|
||||
}
|
||||
|
||||
/// String conversion to native pointer, memory should be free outside function
|
||||
Pointer<Char> stringToNativeInt8(String str, {Allocator allocator = calloc}) {
|
||||
final units = utf8.encode(str);
|
||||
final result = allocator<Uint8>(units.length + 1);
|
||||
final nativeString = result.asTypedList(units.length + 1);
|
||||
nativeString.setAll(0, units);
|
||||
nativeString[units.length] = 0;
|
||||
|
||||
return result.cast<Char>();
|
||||
}
|
||||
|
||||
/// List conversion to native pointer, memory should be free outside function
|
||||
Pointer<Char> int8ListToPointerInt8(
|
||||
Uint8List units,
|
||||
Pointer<Uint8> pointer, {
|
||||
Allocator allocator = calloc,
|
||||
}) {
|
||||
final nativeString = pointer.asTypedList(units.length + 1); //blobBytes
|
||||
nativeString.setAll(0, units);
|
||||
nativeString[units.length] = 0;
|
||||
return pointer.cast<Char>();
|
||||
}
|
||||
|
||||
Pointer<Double> listToPointerDouble(List<double> sample) {
|
||||
final Pointer<Double> pointer = calloc.allocate<Double>(
|
||||
sample.length,
|
||||
alignment: 8,
|
||||
);
|
||||
final nativeSamples = pointer.asTypedList(sample.length);
|
||||
nativeSamples.setAll(0, sample);
|
||||
return pointer.cast<Double>();
|
||||
}
|
||||
|
||||
/// Native pointer conversion to list
|
||||
Int8List nativeInt8ToInt8List(Pointer<Int8> pointer) {
|
||||
var ptrName = pointer.cast<Utf8>();
|
||||
final ptrNameCodeUnits = pointer.cast<Int8>();
|
||||
var list = ptrNameCodeUnits.asTypedList(ptrName.length);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// Open serial port status
|
||||
enum FlOpenStatus { open, closed, error }
|
||||
|
||||
/// Class for incoming data handling
|
||||
class FlSerialEventArgs {
|
||||
FlSerialEventArgs(this.serial, this.len, this.cts, this.dsr);
|
||||
final FlSerial serial;
|
||||
final int len;
|
||||
final bool cts, dsr;
|
||||
}
|
||||
|
||||
/// Main serial wrapper class over ffi
|
||||
class FlSerial {
|
||||
int flh = -1;
|
||||
bool prevCTS = false;
|
||||
bool prevDSR = false;
|
||||
var onSerialData = StreamController<FlSerialEventArgs>();
|
||||
Pointer<Char> serialReadBuff = Pointer.fromAddress(0);
|
||||
Pointer<Uint8> serialWriteBuff = Pointer.fromAddress(0);
|
||||
|
||||
/// Init should be called at program start, after FlSerial creation
|
||||
/// Function is used to make array of internal port structs for 16 parallel processing ports
|
||||
int init() {
|
||||
return bindings.fl_init(16);
|
||||
}
|
||||
|
||||
/// Setting callback to native code. Used for incoming data signal
|
||||
void setCallback(int flh, {required DartflcallbackFunction callback}) {
|
||||
final nativeCallable = NativeCallable<flcallbackFunction>.listener(
|
||||
callback,
|
||||
);
|
||||
bindings.fl_set_callback(flh, nativeCallable.nativeFunction);
|
||||
}
|
||||
|
||||
/// Listing serial ports. Platform depend
|
||||
static List<String> listPorts() {
|
||||
List<String> list = List<String>.empty(growable: true);
|
||||
|
||||
Allocator allocator = calloc;
|
||||
var result = allocator<Char>(1024);
|
||||
|
||||
for (int i = 0; i < 255; i++) {
|
||||
int len = bindings.fl_ports(i, 1024, result);
|
||||
if (len > 0) {
|
||||
String resultStr = result.cast<Utf8>().toDartString(length: len);
|
||||
list.add(resultStr);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
allocator.free(result);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// Internal function for serial port handler checking
|
||||
int _checkFLH(int handler) {
|
||||
if (handler >= 0 && handler < MAX_PORT_COUNT) {
|
||||
return FlError.FL_ERROR_OK;
|
||||
}
|
||||
throw FlSerialException(FlError.FL_ERROR_HANDLER, msg: "$handler");
|
||||
}
|
||||
|
||||
/// Function for openning serial port
|
||||
FlOpenStatus openPort(String portname, int baudrate) {
|
||||
prevCTS = false;
|
||||
prevDSR = false;
|
||||
Pointer<Char> ptr = stringToNativeInt8(portname);
|
||||
flh = bindings.fl_open(flh, ptr, baudrate);
|
||||
calloc.free(ptr);
|
||||
int error = bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_LAST_ERROR, -1);
|
||||
int flerror = FlError.FL_ERROR_UNKNOW;
|
||||
if (error > 0) {
|
||||
/// error mapping
|
||||
String msg = "Port open error: $portname";
|
||||
switch (error) {
|
||||
case 1:
|
||||
case 3:
|
||||
flerror = FlError.FL_ERROR_PORT_NOT_EXIST;
|
||||
msg += " port not exist";
|
||||
break;
|
||||
case 2:
|
||||
flerror = FlError.FL_ERROR_PORT_ALLREADY_OPEN;
|
||||
msg += " port allready open";
|
||||
break;
|
||||
}
|
||||
|
||||
bindings.fl_close(flh);
|
||||
flh = -1;
|
||||
throw FlSerialException(flerror, msg: msg);
|
||||
}
|
||||
|
||||
onSerialData = StreamController<FlSerialEventArgs>();
|
||||
|
||||
Allocator allocator = calloc;
|
||||
serialReadBuff = allocator<Char>(_serialIOBuffLen);
|
||||
serialWriteBuff = allocator<Uint8>(_serialIOBuffLen);
|
||||
|
||||
setCallback(
|
||||
flh,
|
||||
callback: (cflh, len) async {
|
||||
if (len > 0) {
|
||||
onSerialData.add(FlSerialEventArgs(this, len, prevCTS, prevDSR));
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return isOpen();
|
||||
}
|
||||
|
||||
/// Function check is serial port opened
|
||||
FlOpenStatus isOpen() {
|
||||
if (flh < 0) {
|
||||
return FlOpenStatus.closed;
|
||||
}
|
||||
|
||||
int error = bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_LAST_ERROR, -1);
|
||||
if (error > 0) {
|
||||
return FlOpenStatus.error;
|
||||
}
|
||||
int nres = bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_IS_PORT_OPEN, -1);
|
||||
if (nres == 0) {
|
||||
return FlOpenStatus.closed;
|
||||
}
|
||||
return FlOpenStatus.open;
|
||||
}
|
||||
|
||||
/// Get last error message. Return empty string if no error
|
||||
String getLastError() {
|
||||
_checkFLH(flh);
|
||||
|
||||
int res = bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_LAST_ERROR, -1);
|
||||
String strres = "";
|
||||
|
||||
switch (res) {
|
||||
case FlError.FL_ERROR_OK:
|
||||
strres = "0: None";
|
||||
break;
|
||||
case FlError.FL_ERROR_PORT_ALLREADY_OPEN:
|
||||
strres = "$res: Port allready open";
|
||||
break;
|
||||
case FlError.FL_ERROR_PORT_NOT_EXIST:
|
||||
strres = "$res: Port not exist";
|
||||
break;
|
||||
default:
|
||||
strres = "-1: Unknow error";
|
||||
break;
|
||||
}
|
||||
return strres;
|
||||
}
|
||||
|
||||
/*
|
||||
Future<int> _readLineStatus() async {
|
||||
|
||||
_checkFLH(flh);
|
||||
|
||||
bool currCTS = getCTS();
|
||||
bool currDSR = getDSR();
|
||||
if(currCTS != prevCTS || prevDSR != currDSR)
|
||||
{
|
||||
prevCTS = currCTS;
|
||||
prevDSR = currDSR;
|
||||
|
||||
onSerialData.broadcast(FlSerialEventArgs(
|
||||
readBuff.length, Uint8List(0), currCTS, currDSR));
|
||||
}
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
/// Internal function to read serial data from lower layer with desired len. If no data is present, empty list is returned
|
||||
Uint8List _readList(int len) {
|
||||
_checkFLH(flh);
|
||||
|
||||
if (len > _serialIOBuffLen) {
|
||||
len = _serialIOBuffLen;
|
||||
}
|
||||
|
||||
int intres = bindings.fl_read(flh, len, serialReadBuff);
|
||||
|
||||
if (intres <= 0) {
|
||||
return Uint8List(0);
|
||||
}
|
||||
|
||||
final ptrNameCodeUnits = serialReadBuff.cast<Uint8>();
|
||||
var list = ptrNameCodeUnits.asTypedList(intres);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// Read full read bufer from serial port
|
||||
Uint8List readList() {
|
||||
_checkFLH(flh);
|
||||
|
||||
return readListLen(1024 * 8);
|
||||
}
|
||||
|
||||
/// Read desired len from serial port buffer
|
||||
Uint8List readListLen(int len) {
|
||||
_checkFLH(flh);
|
||||
|
||||
return _readList(len);
|
||||
}
|
||||
|
||||
/// Read single byte
|
||||
int read() {
|
||||
_checkFLH(flh);
|
||||
|
||||
Uint8List data = _readList(1);
|
||||
|
||||
if (data.isNotEmpty) {
|
||||
return data.first;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// Write list data to serial port
|
||||
int write(Uint8List data) {
|
||||
_checkFLH(flh);
|
||||
|
||||
Pointer<Char> ptr = int8ListToPointerInt8(data, serialWriteBuff);
|
||||
int res = bindings.fl_write(flh, data.length, ptr);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Close serial port and free resources
|
||||
int closePort() {
|
||||
_checkFLH(flh);
|
||||
bindings.fl_close(flh);
|
||||
onSerialData.close();
|
||||
Allocator allocator = calloc;
|
||||
if (serialReadBuff.value != 0) {
|
||||
allocator.free(serialReadBuff);
|
||||
}
|
||||
if (serialWriteBuff.value != 0) {
|
||||
allocator.free(serialWriteBuff);
|
||||
}
|
||||
flh = -1;
|
||||
return flh;
|
||||
}
|
||||
|
||||
/// Uniwersal function to control serial port
|
||||
int ctrl(int cmd, int value) {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, cmd, value);
|
||||
}
|
||||
|
||||
/// Function set RTS line in serial port
|
||||
int setRTS(bool value) {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_RTS, value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// Function set CTS line in serial port
|
||||
bool getCTS() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_GET_CTS, 0) > 0 ? true : false;
|
||||
}
|
||||
|
||||
/// Get status of DTR line
|
||||
int setDTR(bool value) {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_DTR, value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// Get status of DSR line
|
||||
bool getDSR() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_GET_DSR, 0) > 0 ? true : false;
|
||||
}
|
||||
|
||||
/// Set byte size to 5 bits
|
||||
int setByteSize5() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_BYTESIZE_5, 0);
|
||||
}
|
||||
|
||||
/// Set byte size to 6 bits
|
||||
int setByteSize6() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_BYTESIZE_6, 0);
|
||||
}
|
||||
|
||||
/// Set byte size to 7 bits
|
||||
int setByteSize7() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_BYTESIZE_7, 0);
|
||||
}
|
||||
|
||||
/// Set byte size to 8 bits
|
||||
int setByteSize8() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_BYTESIZE_8, 0);
|
||||
}
|
||||
|
||||
/// Set bit parity to none
|
||||
int setBitParityNone() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_PARITY_NONE, 0);
|
||||
}
|
||||
|
||||
/// Set bit parity to odd
|
||||
int setBitParityOdd() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_PARITY_ODD, 0);
|
||||
}
|
||||
|
||||
// Set bit parity to even
|
||||
int setBitParityEven() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_PARITY_EVEN, 0);
|
||||
}
|
||||
|
||||
// Set bit parity to mark
|
||||
int setBitParityMark() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_PARITY_MARK, 0);
|
||||
}
|
||||
|
||||
// Set bit parity to space
|
||||
int setBitParitySpace() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_PARITY_SPACE, 0);
|
||||
}
|
||||
|
||||
/// Set stop bits to one
|
||||
int setStopBits1() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_STOPBITS_ONE, 0);
|
||||
}
|
||||
|
||||
/// Set stop bits to one and half
|
||||
int setStopBits1_5() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_STOPBITS_ONE_POINT_FIVE, 0);
|
||||
}
|
||||
|
||||
/// Set stop bits to two
|
||||
int setStopBits2() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_STOPBITS_TWO, 0);
|
||||
}
|
||||
|
||||
/// Disable flow control
|
||||
int setFlowControlNone() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_FLOWCONTROL_NONE, 0);
|
||||
}
|
||||
|
||||
/// Set hardware flow control
|
||||
int setFlowControlHardware() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_FLOWCONTROL_HARDWARE, 0);
|
||||
}
|
||||
|
||||
/// Set xon/xoff flow control (software)
|
||||
int setFlowControlSoftware() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_SET_FLOWCONTROL_SOFTWARE, 0);
|
||||
}
|
||||
|
||||
/// Waiting for status line change
|
||||
int setWaitStatusChange() {
|
||||
_checkFLH(flh);
|
||||
return bindings.fl_ctrl(flh, FlCtrl.FL_CTRL_GET_STATUS_CHANGE, 0);
|
||||
}
|
||||
|
||||
/// Free resources. Serial port should not be used after calling this function
|
||||
int free() {
|
||||
return bindings.fl_free();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
// ignore_for_file: always_specify_types
|
||||
// ignore_for_file: camel_case_types
|
||||
// ignore_for_file: non_constant_identifier_names
|
||||
|
||||
// AUTO GENERATED FILE, DO NOT EDIT.
|
||||
//
|
||||
// Generated by `package:ffigen`.
|
||||
// ignore_for_file: type=lint
|
||||
import 'dart:ffi' as ffi;
|
||||
|
||||
/// Bindings for `src/flserial.h`.
|
||||
///
|
||||
/// Regenerate bindings with `dart run ffigen --config ffigen.yaml`.
|
||||
///
|
||||
class FlserialBindings {
|
||||
/// Holds the symbol lookup function.
|
||||
final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
|
||||
_lookup;
|
||||
|
||||
/// The symbols are looked up in [dynamicLibrary].
|
||||
FlserialBindings(ffi.DynamicLibrary dynamicLibrary)
|
||||
: _lookup = dynamicLibrary.lookup;
|
||||
|
||||
/// The symbols are looked up with [lookup].
|
||||
FlserialBindings.fromLookup(
|
||||
ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
|
||||
lookup)
|
||||
: _lookup = lookup;
|
||||
|
||||
int fl_init(
|
||||
int portCount,
|
||||
) {
|
||||
return _fl_init(
|
||||
portCount,
|
||||
);
|
||||
}
|
||||
|
||||
late final _fl_initPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Int Function(ffi.Int)>>('fl_init');
|
||||
late final _fl_init = _fl_initPtr.asFunction<int Function(int)>();
|
||||
|
||||
int fl_set_callback(
|
||||
int flh,
|
||||
flcallback cb,
|
||||
) {
|
||||
return _fl_set_callback(
|
||||
flh,
|
||||
cb,
|
||||
);
|
||||
}
|
||||
|
||||
late final _fl_set_callbackPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Int Function(ffi.Int, flcallback)>>(
|
||||
'fl_set_callback');
|
||||
late final _fl_set_callback =
|
||||
_fl_set_callbackPtr.asFunction<int Function(int, flcallback)>();
|
||||
|
||||
int fl_ports(
|
||||
int index,
|
||||
int buffsize,
|
||||
ffi.Pointer<ffi.Char> buff,
|
||||
) {
|
||||
return _fl_ports(
|
||||
index,
|
||||
buffsize,
|
||||
buff,
|
||||
);
|
||||
}
|
||||
|
||||
late final _fl_portsPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Int Function(
|
||||
ffi.Int, ffi.Int, ffi.Pointer<ffi.Char>)>>('fl_ports');
|
||||
late final _fl_ports =
|
||||
_fl_portsPtr.asFunction<int Function(int, int, ffi.Pointer<ffi.Char>)>();
|
||||
|
||||
int fl_open(
|
||||
int flh,
|
||||
ffi.Pointer<ffi.Char> portname,
|
||||
int baudrate,
|
||||
) {
|
||||
return _fl_open(
|
||||
flh,
|
||||
portname,
|
||||
baudrate,
|
||||
);
|
||||
}
|
||||
|
||||
late final _fl_openPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Int Function(
|
||||
ffi.Int, ffi.Pointer<ffi.Char>, ffi.Int)>>('fl_open');
|
||||
late final _fl_open =
|
||||
_fl_openPtr.asFunction<int Function(int, ffi.Pointer<ffi.Char>, int)>();
|
||||
|
||||
int fl_read(
|
||||
int flh,
|
||||
int len,
|
||||
ffi.Pointer<ffi.Char> buff,
|
||||
) {
|
||||
return _fl_read(
|
||||
flh,
|
||||
len,
|
||||
buff,
|
||||
);
|
||||
}
|
||||
|
||||
late final _fl_readPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Int Function(
|
||||
ffi.Int, ffi.Int, ffi.Pointer<ffi.Char>)>>('fl_read');
|
||||
late final _fl_read =
|
||||
_fl_readPtr.asFunction<int Function(int, int, ffi.Pointer<ffi.Char>)>();
|
||||
|
||||
int fl_write(
|
||||
int flh,
|
||||
int len,
|
||||
ffi.Pointer<ffi.Char> data,
|
||||
) {
|
||||
return _fl_write(
|
||||
flh,
|
||||
len,
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
late final _fl_writePtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Int Function(
|
||||
ffi.Int, ffi.Int, ffi.Pointer<ffi.Char>)>>('fl_write');
|
||||
late final _fl_write =
|
||||
_fl_writePtr.asFunction<int Function(int, int, ffi.Pointer<ffi.Char>)>();
|
||||
|
||||
int fl_close(
|
||||
int flh,
|
||||
) {
|
||||
return _fl_close(
|
||||
flh,
|
||||
);
|
||||
}
|
||||
|
||||
late final _fl_closePtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Int Function(ffi.Int)>>('fl_close');
|
||||
late final _fl_close = _fl_closePtr.asFunction<int Function(int)>();
|
||||
|
||||
int fl_ctrl(
|
||||
int flh,
|
||||
int param,
|
||||
int value,
|
||||
) {
|
||||
return _fl_ctrl(
|
||||
flh,
|
||||
param,
|
||||
value,
|
||||
);
|
||||
}
|
||||
|
||||
late final _fl_ctrlPtr = _lookup<
|
||||
ffi.NativeFunction<ffi.Int Function(ffi.Int, ffi.Int32, ffi.Int)>>(
|
||||
'fl_ctrl');
|
||||
late final _fl_ctrl = _fl_ctrlPtr.asFunction<int Function(int, int, int)>();
|
||||
|
||||
int fl_free() {
|
||||
return _fl_free();
|
||||
}
|
||||
|
||||
late final _fl_freePtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Int Function()>>('fl_free');
|
||||
late final _fl_free = _fl_freePtr.asFunction<int Function()>();
|
||||
}
|
||||
|
||||
abstract class FlCtrl {
|
||||
static const int FL_CTRL_LAST_ERROR = 0;
|
||||
static const int FL_CTRL_IS_PORT_OPEN = 1;
|
||||
static const int FL_CTRL_BREAK = 2;
|
||||
static const int FL_CTRL_SET_RTS = 3;
|
||||
static const int FL_CTRL_GET_CTS = 4;
|
||||
static const int FL_CTRL_SET_DTR = 5;
|
||||
static const int FL_CTRL_GET_DSR = 6;
|
||||
static const int FL_CTRL_SET_BYTESIZE_5 = 7;
|
||||
static const int FL_CTRL_SET_BYTESIZE_6 = 8;
|
||||
static const int FL_CTRL_SET_BYTESIZE_7 = 9;
|
||||
static const int FL_CTRL_SET_BYTESIZE_8 = 10;
|
||||
static const int FL_CTRL_SET_PARITY_NONE = 11;
|
||||
static const int FL_CTRL_SET_PARITY_ODD = 12;
|
||||
static const int FL_CTRL_SET_PARITY_EVEN = 13;
|
||||
static const int FL_CTRL_SET_PARITY_MARK = 14;
|
||||
static const int FL_CTRL_SET_PARITY_SPACE = 15;
|
||||
static const int FL_CTRL_SET_STOPBITS_ONE = 16;
|
||||
static const int FL_CTRL_SET_STOPBITS_TWO = 17;
|
||||
static const int FL_CTRL_SET_STOPBITS_ONE_POINT_FIVE = 18;
|
||||
static const int FL_CTRL_SET_FLOWCONTROL_NONE = 19;
|
||||
static const int FL_CTRL_SET_FLOWCONTROL_HARDWARE = 20;
|
||||
static const int FL_CTRL_SET_FLOWCONTROL_SOFTWARE = 21;
|
||||
static const int FL_CTRL_GET_STATUS_CHANGE = 22;
|
||||
static const int FL_CTRL_LAST = 23;
|
||||
}
|
||||
|
||||
abstract class FlError {
|
||||
static const int FL_ERROR_OK = 0;
|
||||
static const int FL_ERROR_UNKNOW = 1;
|
||||
static const int FL_ERROR_PORT_ALLREADY_OPEN = 2;
|
||||
static const int FL_ERROR_PORT_NOT_EXIST = 3;
|
||||
static const int FL_ERROR_IO = 4;
|
||||
static const int FL_ERROR_HANDLER = 5;
|
||||
static const int FL_ERROR_LAST = 6;
|
||||
}
|
||||
|
||||
typedef flcallback = ffi.Pointer<ffi.NativeFunction<flcallbackFunction>>;
|
||||
typedef flcallbackFunction = ffi.Void Function(
|
||||
ffi.UnsignedInt, ffi.UnsignedInt);
|
||||
typedef DartflcallbackFunction = void Function(int, int);
|
||||
|
||||
const int MAX_PORT_NAME_LEN = 512;
|
||||
|
||||
const int MAX_PORT_COUNT = 128;
|
||||
@@ -0,0 +1,6 @@
|
||||
/// Exception class for serial port
|
||||
class FlSerialException implements Exception {
|
||||
FlSerialException(this.error, {required this.msg});
|
||||
final int error;
|
||||
final String msg;
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export 'flserial_exception.dart';
|
||||
export 'flserial.dart';
|
||||
Reference in new issue
Block a user