Commit graph

1277 commits

Author SHA1 Message Date
yabu76
c25a379fbb Add some socket examples of bidirectional command helpers and pexpect
bidir_cmd_herlper.sh: Bidirectional command helper by socat.
bidir_cmd_helper.py: Bidirectional command helper by python and netcat.

pexpect-ping.py, pexpect-pong.py: Scripts for throwing Ping-Pong between
cross-connected tios.
2025-12-07 11:21:55 +09:00
yabu76
a9f05a66f7 Change Ctrl-t r lua funtcion to start with the previous call state
When calling the Lua interpreter with Ctrl-t r, change to start with the
previous call state.

This allows you to use it like REPL:
(example)
  Ctrl-t r : my_library.lua
  Ctrl-t r : !result1 = my_func("test1"); result2 = my_func("test2")
  Ctrl-t r : !if (result1 == result2) then print("OK") else print("NG")
  Ctrl-t r : @new

When you enter strings using Ctrl-t r, the string is interpreted as
follows:
- If the string does not begin with either "!" or "@", the string is
assumed to be the file name of a script and is executed.
- If the string begins with "!", the string excluding the "!" is
interpreted as Lua commands.
- If the string begins with "@", Strings beginning with "@" are
considered instructions to the interpreter. Currently valid instructions
are:
@new: Clear the Lua state. (== reset the Lua interpreter.)
@doopt: Execute the Lua script action specified by the option that start
with clearing the Lua state.
@nuldo=opt: do @doopt action when an empty string is entered (default).
@nuldo=none: Do nothing when an empty string is entered.

And now, lua interpreter start with GC.
If you need to stop GC, do lua function collectgarbage("stop").
2025-11-29 18:03:30 +09:00
yabu76
0983ce6eeb Add history/line-edit function to Ctrl-t command string input
Ctrl-t r/R/x/y commands require string input. To reduce the hassle of
repeatedly entering this information, I apply readline functions
(line-editing and history) to the string input.

Now tio have two histories: one for the line input-mode and one for the
ctrl-t command's string input.

And the following changes are made to the line input:
- Add prompts.
  "> ": line input-mode, ">> " Ctrl-t string input.
- Omits duplicate lines from the history.

To implement the above functionality, we will modify the readline
functions to use the multi-instance style.
2025-11-29 16:41:04 +09:00
yabu76
8a1b739ae6 Add cleanup read to Lua API tio.expect[s]
tio.expect[s]() performs pattern matching for each character received,
but there are cases where the character reception speed exceeds the
pattern matching speed, resulting in characters being missed.

Add non-blocking reads to read all characters that have been received at
that time.
2025-11-15 23:26:43 +09:00
yabu76
8e02cded17 Change the Lua API timeout specification to allow for non-blocking reads.
Change timeout argument of tio.read / readline / expect[s] to be similar
to the timeout specification for poll(2) and LuaSocket.

If timeout is negative value or not provided or nil, it will wait
indefinitely until data is ready to read.
If timeout is 0, it will read data that has arrived with non-blocking.

Prior to this fix, non-blocking reads could not be specified.
2025-11-15 22:46:54 +09:00
yabu76
56c378f5f9 Add multipul patterns function tio.expects() to Lua API
Add tio.expects() which has a table of patterns in the arguments to
support "OR" pattern waiting.

The return values of tio.expects() are:
1st: index of the matched pattern in the table. nil if unmatched.
2nd: a table of captures if one of the patterns are matched.
     nil if any of the patterns are unmatched and timeout.
3rd: all received strings in tio.expects() to treat the strings after
     match.

Add all received string to tio.expect()'s return values too.

For example,
  idx, captures, all_received = tio.expects( {"\nOK", "\nERROR"}, 1000 )
  captures, all_received = tio.expect( "\nPROMPT>", 1000 )
2025-11-02 10:15:16 +09:00
yabu76
b5944275d3 Revert "Add multipul patterns function to Lua API tio.expect()"
This reverts commit d1ff5f7142.
2025-11-02 09:50:44 +09:00
yabu76
67bd6b1a8c Fix map option's input/output description of tio man page. 2025-10-26 22:28:49 +09:00
yabu76
d1ff5f7142 Add multipul patterns function to Lua API tio.expect()
Lua regular expressions do not have an OR specification, so the current
tio.expect() cannot wait until any of multiple patterns match.

This will cause OR waiting behavior when a table of multiple regular
expressions is passed as a pattern.
If you pass a string as a pattern, it will treats a table has single
regular expression.

and this will change return values.
1st: table of captures if one of the patterns matched
     nil if any pattern unmatched and timeout.
2nd: whole input strings
3rd: index of the matched pattern. 0 if unmatched.

For example,
    captures, whole, idx = tio.expect( {"\nOK", "\nERROR"} )
    captures, whole, idx = tio.expect( "\nOK" )
2025-10-05 20:43:06 +09:00
yabu76
58aae5511f Add --script function to key command ctrl-t r "Run script"
If filename starts with '!', do filename's remain parts as lua commands.
2025-10-05 18:52:49 +09:00
yabu76
e62a23f320 Add option '--output-line-delay-char cr|lf' 2025-10-05 15:25:47 +09:00
yabu76
9e51d2e4ee Add Lua API twrite
The twrite Lua API is a variation of the write API, with the output
character mapping and output-delay / output-line-delay features enabled.
Since it processes each character internally, writing speed is slower
than the write API.

~~~~~~~~~~~~~~~~~~~~~~~
twrite(string)
    Translate string with output character mapping and write the
    translated string to serial device with output-delay /
    output-line-delay.
2025-09-23 19:15:30 +09:00
yabu76
6a590bd598 Fix output-delay and input-mode line combination bug 2025-09-20 22:09:16 +09:00
yabu76
3922ce3447 Fix output-line-delay behavior
If output-line-delay is non-zero and output-delay is any, line delay
time set output-line-delay.
If output-line-delay is zero and output-delay is non-zero, line delay
time set output-delay.

It was previously (output-line-delay + output-delay) in any case.
Also, since the buffer was flushed after the line delay, there was a
possibility that the delay would be reduced or not applied at all.
2025-09-20 22:08:25 +09:00
yabu76
9784d3c277 Fix compile error in MSYS2/Cygwin 2025-08-16 18:05:56 +09:00
yabu76
e458b02771 Add Xmodem-SUM support. 2025-08-16 10:52:31 +09:00
yabu76
6cc0a58ed8 Refactoring XYMODEM codes and Fix error code handling
Refactoring.
- separete routines from xmodem_send_xxx,
  - xmsend_inirial_handshake
  - xmsend_wait_response,
  - xmsend_repeat_eot_and_wait_response
- separete routines from xmodem_receive,
  - xmrecv_drain_pending_chars
- separete routines from xymodem_send,
  - ymodem_send_1k
- rename routines.
  - crc16 --> calculate_crc16
  - update_CRC --> update_crc16
  - xmodem_1k --> xmodem_send_1k
  - xmodem_send --> xmodem_send_128b
  - receive_packet --> xmrecv_receive_packet
- rename struct types.
  - xpacket --> xpacket_128b
- separete xpacket's header / footer
  - xpacket_hdr, xpacket_ftr_crc

Fix error code handling.
- use 'rc' for system call's return code,
  and add 'err' for xymodem function's return code (OK, ERR, ...)
- add ERR_TMO to return codes
- change USER_CAN to ERR_USER_CAN, because it is negative value

Fix xmrecv_receive_packet()'s argument packet to pointer type.
2025-08-15 23:10:20 +09:00
yabu76
b2a8c02d1d Fix incorrect handling of the return value of the poll system call 2025-08-15 21:38:00 +09:00
yabu76
4aa36e6e91 Adjust code style to comply with clang-format rules 2025-08-14 13:50:58 +09:00
yabu76
102657af58 Fix XMODEM reception start failure. 2025-08-14 09:03:58 +09:00
aiotter
3af4c5591e Fix redundant output on macOS 2025-08-07 17:18:29 +02:00
John Barbero Unenge
cce94b9d92 Add --complete-profiles to help printout and man pages 2025-06-17 16:30:31 +02:00
ii8
86f48a2fb6 Overhaul Lua API
Lua API moved into a tio library table and names adjusted to Lua stdlib style.
Regex in expect() replaced with Lua patterns so binary data can be handled.
New tio.alwaysecho variable allows enabling and disabling echo to console.
Read and write functions now manage complex retry and timeout logic internally,
giving the user a simple "nil if fail" API like the rest of Lua.
exit() was removed, os.exit() already exists in the Lua standard library.
2025-06-14 15:09:21 +02:00
Martin Lund
381c0b7823 Update codeql to v3 2025-06-14 07:03:17 +02:00
Martin Lund
8f33cff6ea Disable compiler warning on unused result 2025-05-31 19:43:11 +02:00
Keith Barratt
9d00cd3492 Fix device description-Linux
This commit only effects Linux.

The description field of the `device_list`, populated by
`tty_search_for_serial_devices()`, was either incorrect or less than ideal
for CDC ACM virtual com ports. For instance:
    (i) Some devices incorrectly have the description field populated by
    the 'product' property of USB hub they are connected via.
    (ii) Other devices have description fields populated with the interface,
    e.g. CDC, when there is a 'product' property available that would give a
    clearer description.

To solve these issues, we first prioritise searching for the 'product' property
of the device over the 'interface' property. We also look for the
'product' property in an additional directory.
2025-05-30 17:20:06 +02:00
Martin Lund
3e0b2d861d Fix Ubuntu workflow 2025-05-30 17:18:21 +02:00
ii8
a1217af4c6 Fix string truncation bug in scripting api 2025-05-25 21:13:43 +02:00
Martin Lund
58bf5c5008 Update tio man page 2025-05-25 19:46:18 +02:00
Maximilian Seesslen
7e61a34df3 Added timestamp format "epoch-usec"
This timestamp format will print the seconds since epoch along with
subdivision in microseconds.

Example:
 [1748009585.087083] tio v3.9-8-g2fb788f-dirty
 [1748009585.087156] Press ctrl-t q to quit
 [1748009585.087683] Connected to /dev/ttyUSB0
2025-05-23 16:36:39 +02:00
Hideaki Tai
2fb788f817 fix: lua script stops output if it includes null terminate 2025-05-06 17:28:53 +02:00
Martin Lund
f887756a71 meson: Enable compiler warnings on unused result and global shadows 2025-04-29 17:44:08 +02:00
Robert Lipe
5d915134a3 Fix --auto new and --auto latest on MacOS. (redo)
Git is being dumb about
67c071633d This PR is identical to that one and will supercede it.

Fix --auto new and --auto latest on MacOS.

'device_list' was both a global (eww!) and a local inside
tty_search_for_serial_devices(). The local got set and
returned, so it looked sane, but the caller used the global
instead of the return value of the function it had just
called, meaning (global) device_list was NULL while
(ignored, local) device_list held a perfectly lovely
linked list.

Tested:
tio --auto new waits for a new device to appare and connects
tio --latest will connect to the most recently attached device
  which, in most worlds, is the most recently enumerated USB
  device, conveniently skipping all the bluetooth nonsense.
  If the lone USB device is disconnected, it then connects to
  one of those, meaning you really do have to restart tio.
2025-04-29 17:05:24 +02:00
Robert Lipe
7516dff802 Add missing build piece. 2025-04-24 17:55:26 +02:00
Robert Lipe
03ef931fb2 - Implemented getPropertyString(), getDeviceLocation(), tty_search_for_serial_devices()
for MacOS
- Added error handling and memory management
- Improved code readability and consistency
- Updated coding style to match project conventions

- Added robust error checking for CoreFoundation property retrieval
- Implemented more defensive memory allocation and type checking
- Switched to using callout device key for more reliable device discovery
- Added single-line block bracing consistent with project style
- Improved comments and code formatting

- Used `kIOCalloutDeviceKey` instead of `kIODialinDeviceKey` for device path retrieval
- Enhanced type checking for CoreFoundation objects
- Simplified memory management and error handling
- Added additional logging and error reporting

- Verified functionality on MacOS 10.11 and 10.15. Tested with ESP32-P4 and ESP32-BOX

Resolves potential device discovery and memory management issues in the MacOS serial device detection code.
2025-04-24 17:55:26 +02:00
Martin Lund
437881f0ed Update AUTHORS 2025-04-23 08:17:11 +02:00
David Ordnung
c736b1e353 Input ICRCRNL mapping to avoid using INLCRNL with ICRNL 2025-04-23 08:09:22 +02:00
Martin Lund
d682e98a66 codeql: Build using ubuntu-22.04 2025-04-16 10:47:39 +02:00
Martin Lund
bdfe87e1cb Update date 2025-04-13 13:31:06 +02:00
Martin Lund
5c2ced1093 Update NEWS 2025-04-13 13:27:50 +02:00
Martin Lund
f87f470415 Fix pattern matching memory corruption 2025-04-13 13:25:25 +02:00
Martin Lund
2e86718973 Add typos.toml 2025-04-13 08:28:01 +02:00
Martin Lund
013aebcc05 Update NEWS 2025-04-12 09:02:22 +02:00
Martin Lund
b33045189f Update plain text man page 2025-04-12 08:57:25 +02:00
Martin Lund
600c3d7563 Update version date 2025-04-12 08:55:40 +02:00
Martin Lund
ebce2d4ee9 Bump version 2025-04-12 08:55:11 +02:00
Martin Lund
16b7aee42f Update NEWS 2025-04-12 08:54:50 +02:00
Martin Lund
d33e275ca3 Update AUTHORS 2025-03-23 07:04:47 +01:00
Samuel Holland
da4074c9a5 Don't add null characters to the expect buffer
They prevent regexec() from seeing the remainder of the buffer.
2025-03-23 07:02:56 +01:00
Martin Lund
f716d2ccdd Update TODO 2025-03-13 15:44:12 +01:00