Files
meshcore-open/third_party/flserial/macos/Classes/flserial.h
T
just-stuff-tm 2474389099 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.
2026-10-16 20:11:05 -04:00

80 lines
1.8 KiB
C

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#if _WIN32
#include <windows.h>
#else
#include <pthread.h>
#include <unistd.h>
#endif
#if _WIN32
#define FFI_PLUGIN_EXPORT __declspec(dllexport)
#else
#define FFI_PLUGIN_EXPORT
#endif
#define MAX_PORT_FIFO_LEN 128*1024
#define MAX_PORT_NAME_LEN 512
#define MAX_PORT_COUNT 16
typedef enum FlCtrl {
FL_CTRL_LAST_ERROR,
FL_CTRL_IS_PORT_OPEN,
FL_CTRL_BREAK,
FL_CTRL_SET_RTS,
FL_CTRL_GET_CTS,
FL_CTRL_SET_DTR,
FL_CTRL_GET_DSR,
FL_CTRL_SET_BYTESIZE_5,
FL_CTRL_SET_BYTESIZE_6,
FL_CTRL_SET_BYTESIZE_7,
FL_CTRL_SET_BYTESIZE_8,
FL_CTRL_SET_PARITY_NONE,
FL_CTRL_SET_PARITY_ODD,
FL_CTRL_SET_PARITY_EVEN,
FL_CTRL_SET_PARITY_MARK,
FL_CTRL_SET_PARITY_SPACE,
FL_CTRL_SET_STOPBITS_ONE,
FL_CTRL_SET_STOPBITS_TWO,
FL_CTRL_SET_STOPBITS_ONE_POINT_FIVE,
FL_CTRL_SET_FLOWCONTROL_NONE,
FL_CTRL_SET_FLOWCONTROL_HARDWARE,
FL_CTRL_SET_FLOWCONTROL_SOFTWARE,
FL_CTRL_GET_STATUS_CHANGE,
FL_CTRL_LAST,
} FlCtrl;
typedef enum FlError {
FL_ERROR_OK,
FL_ERROR_UNKNOW,
FL_ERROR_PORT_ALLREADY_OPEN,
FL_ERROR_PORT_NOT_EXIST,
FL_ERROR_IO,
FL_ERROR_HANDLER,
FL_ERROR_LAST,
} FlError;
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*flcallback)(unsigned int, unsigned int);
FFI_PLUGIN_EXPORT int fl_init (int portCount);
FFI_PLUGIN_EXPORT int fl_set_callback(int flh, flcallback cb);
FFI_PLUGIN_EXPORT int fl_ports (int index, int buffsize, char *buff);
FFI_PLUGIN_EXPORT int fl_open (int flh, char *portname, int baudrate);
FFI_PLUGIN_EXPORT int fl_read (int flh, int len, char *buff);
FFI_PLUGIN_EXPORT int fl_write (int flh, int len, char *data);
FFI_PLUGIN_EXPORT int fl_close (int flh);
FFI_PLUGIN_EXPORT int fl_ctrl (int flh, FlCtrl param, int value);
FFI_PLUGIN_EXPORT int fl_free (void);
#ifdef __cplusplus
}
#endif