+ Add system timestamps to lua read() and new lua read_line() per global options

+ Add missing timestamp-format epoch
+ Update send_ to use fsync and tcdrain like normal tty_sync does
+ Rework read_line to save partial line at timeout
+ Simplified read_line to reduce cyclomatic complexity

+ renamed example files read.lua and read_line.lua
+ moved #define READ_LINE_SIZE to top of file
+ renamed g_linebuf to linebuf, and moved it into read_line as a static variable
This commit is contained in:
Keith Hill 2024-10-25 11:22:56 -05:00 committed by Martin Lund
parent db3f109c7d
commit afd82f7ac4
12 changed files with 171 additions and 24 deletions

View file

@ -467,7 +467,18 @@ until data is ready to read.
Returns number of bytes read on success, 0 on timeout, or -1 on error.
On success, returns read string as second return value.
On success, returns read string as second return value. Also emits a single
timestamp to stdout and log file per options.timestamp and options.log.
.IP "\fBread_line(timeout)"
Read line from serial device. If timeout is 0 or not provided it will wait
forever until data is ready to read.
Returns number of bytes read on success, 0 on timeout, or -1 on error.
On success, returns the string that was read as second return value. Also
emits a single timestamp to stdout and log file per options.timestamp
and options.log.
.IP "\fBset{line=state, ...}"
Set state of one or multiple tty modem lines.

View file

@ -373,7 +373,14 @@ SCRIPT API
Returns number of bytes read on success, 0 on timeout, or -1 on error.
On success, returns read string as second return value.
On success, returns read string as second return value. Also emits a single timestamp to stdout and log file per options.timestamp and options.log.
read_line(timeout)
Read line from serial device. If timeout is 0 or not provided it will wait forever until data is ready to read.
Returns number of bytes read on success, 0 on timeout, or -1 on error.
On success, returns the string that was read as second return value. Also emits a single timestamp to stdout and log file per options.timestamp and options.log.
set{line=state, ...}
Set state of one or multiple tty modem lines.