Skip to content

Commit

Permalink
2.4: add thread
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Dec 2, 2022
1 parent 77a5f1d commit 8a212d1
Show file tree
Hide file tree
Showing 15 changed files with 331 additions and 97 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
TARGET=tio
VERSION=2.1
VERSION=2.4
BAUDRATES=0 50 75 110 134 150 200 300 600 1200 1800 2400 4800 9600 19200 38400 57600 115200 230400 460800 500000 576000 921600 1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 # not found: 7200 14400 28800 76800

CC=cc
CFLAGS=-Wall -std=gnu99 -Isrc
CFLAGS=-Wall -std=gnu99 -pthread -Isrc
LDFLAGS= -linih -s
RM = rm -f
SRCS = \
Expand Down
45 changes: 44 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@

=== tio v2.2 ===
=== tio v2.4 ===



Changes since tio v2.3:

* Add threaded input handling

To make tio more responsive to quit and I/O flush key command when main I/O
thread is blocked on output.

* Fix so that is it possible to quit tio in tio etc.

Fix regression so that it is possible to send the prefix key code to the
remote tio session without local tio session reacting to same key code
(quitting etc.).

* Add key command to toggle log on/off

Add key command 'ctrl-t f' which will toggle log on/off.

If no log filename has been specified via the 'log-filename' option then
tio will automatically generate a new log filename every time the log
feature is toggled on. Meaning, when toggled multiple times, multiple
log files will be generated.

However, if a log filename has been specified, tio will only write and
append to that same file.



Changes since tio v2.2:

* Add mute feature

This will make tio go fully silent and not print anything.

* Rename config variable 'tty' to 'device'

* Deprecate tty config keyword but keep it around for now

* Update show config

* Update example tiorc



Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ The command-line interface is straightforward as reflected in the output from
```
Usage: tio [<options>] <tty-device|sub-config>
Connect to tty device directly or via sub-configuration.
Connect to TTY device directly or via sub-configuration.
Options:
-b, --baudrate <bps> Baud rate (default: 115200)
Expand Down Expand Up @@ -140,7 +140,7 @@ Which corresponds to the commonly used default options:
$ tio -b 115200 -d 8 -f none -s 1 -p none /dev/ttyUSB0
```

It is recommended to connect serial tty devices by ID:
It is recommended to connect serial TTY devices by ID:
```
$ tio /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
```
Expand All @@ -152,7 +152,7 @@ List available serial devices by ID:
$ tio --list-devices
```
Note: One can also use tio shell completion on /dev which will automatically
list all available serial tty devices.
list all available serial TTY devices.

Log to file with autogenerated filename:
```
Expand Down Expand Up @@ -191,6 +191,7 @@ ctrl-t ? to list the available key commands.
[20:19:12.040] ctrl-t b Send break
[20:19:12.040] ctrl-t c Show configuration
[20:19:12.040] ctrl-t e Toggle local echo mode
[20:19:12.040] ctrl-t f Toggle log to file
[20:19:12.040] ctrl-t g Toggle serial port line
[20:19:12.040] ctrl-t h Toggle hexadecimal mode
[20:19:12.040] ctrl-t l Clear screen
Expand All @@ -216,7 +217,7 @@ following locations in the order listed:

The configuration file supports sub-configurations using named sections which can
be activated via the command-line by name or pattern. A sub-configuration
specifies which tty to connect to and other options.
specifies which TTY device to connect to and other options.

Example configuration file:

Expand All @@ -229,7 +230,7 @@ stopbits = 1
color = 10
[rpi3]
tty = /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
device = /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
baudrate = 115200
no-autoconnect = enable
log = enable
Expand All @@ -239,7 +240,7 @@ color = 12
[usb devices]
pattern = usb([0-9]*)
tty = /dev/ttyUSB%s
device = /dev/ttyUSB%s
color = 13
```

Expand Down
29 changes: 29 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@

* Allow tio to connect to socket

After some more consideration I think it makes sense to support connecting to a
socket as that will make tio be able to both serve a serial port via a socket
and connect to it - it will be an end to end solution. In short we will be able
to do the following:

Host serial port on socket (existing feature):
$ tio --socket unix:/tmp/tio-socket-0 /dev/ttyUSB0

Connect to same socket (new feature):
$ tio unix:/tmp/tio-socket-0

Besides a bit of refactoring the following required changes spring to mind:

* Socket mode and type of socket should be activated via device name prefix. For example:
* UNIX socket: tio unix:<filename>
* TCPv4 socket: tio inet:<ip>:<port>
* TCPv6 socket: tio inet6:<ip>:<port>
* If no port number defined default to 3333
* Mapping flags INLCR, IGNCR, ICRNL needs implementation for socket mode
* Error messages should just say "device" instead of "tty device" etc.
* Remove other tty'isms (tty_write() should be device_write() etc.)
* In session key commands that do not work in socket mode should either not be listed or print an error messages if used.
* All non-tty features should continue work (auto-connect etc.)
* Shell completion script update
* Man page update


* Split I/O feature

Allow to split input and output so that it is possible to manage these
Expand Down
5 changes: 5 additions & 0 deletions bash-completion/tio
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ _tio()
--rs-485 \
--rs-485-config \
--alert \
--mute \
-v --version \
-h --help"

Expand Down Expand Up @@ -141,6 +142,10 @@ _tio()
COMPREPLY=( $(compgen -W "none bell blink" -- ${cur}) )
return 0
;;
--mute)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
-v | --version)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
Expand Down
12 changes: 6 additions & 6 deletions example/tiorc
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,32 @@ alert = none

[rpi3]
baudrate = 115200
tty = /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A6009HU3-if00-port0
device = /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A6009HU3-if00-port0
socket = unix:/tmp/tio-socket-0
color = 9

[am64-evm]
baudrate = 115200
tty = /dev/serial/by-id/usb-Silicon_Labs_CP2105_Dual_USB_to_UART_Bridge_Controller_01093176-if01-port0
device = /dev/serial/by-id/usb-Silicon_Labs_CP2105_Dual_USB_to_UART_Bridge_Controller_01093176-if01-port0
line-pulse-duration = DTR=200,RTS=300,RI=50
alert = bell
color = 10

[tincan]
baudrate = 9600
tty = /dev/serial/by-id/usb-TinCanTools_Flyswatter2_FS20000-if00-port0
device = /dev/serial/by-id/usb-TinCanTools_Flyswatter2_FS20000-if00-port0
log = enable
log-file = tincan.log
log-strip = enable
color = 11

[usb devices]
[usb]
pattern = usb([0-9]*)
tty = /dev/ttyUSB%s
device = /dev/ttyUSB%s
color = 12

[rs-485-device]
tty = /dev/ttyUSB0
device = /dev/ttyUSB0
rs-485 = enable
rs-485-config = RTS_ON_SEND=1,RTS_AFTER_SEND=1,RTS_DELAY_BEFORE_SEND=60,RTS_DELAY_AFTER_SEND=80,RX_DURING_TX
color = 13
22 changes: 13 additions & 9 deletions man/man1/tio.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "tio" "1" "2022-10-18" "tio 2.2" "User Commands"
.TH "tio" "1" "2022-11-02" "tio 2.4" "User Commands"

.SH "NAME"
tio \- a simple serial device I/O tool
Expand Down Expand Up @@ -289,6 +289,10 @@ Send serial break (triggers SysRq on Linux, etc.)
Show configuration (baudrate, databits, etc.)
.IP "\fBctrl-t e"
Toggle local echo mode
.IP "\fBctrl-t f"
Toggle log to file
.IP "\fBctrl-t F"
Flush data I/O buffers (discard data written but not transmitted and data received but not read)
.IP "\fBctrl-t g"
Toggle serial port line
.IP "\fBctrl-t h"
Expand Down Expand Up @@ -340,7 +344,7 @@ activated from the command-line when starting tio.

.PP
\fBtio\fR will try to match the user input to a sub-configuration by name or by
pattern to get the tty and other options.
pattern to get the TTY device and other options.

.PP
Options without any label change the default options.
Expand All @@ -354,8 +358,8 @@ The following configuration file options are available:
.TP 25n
.IP "\fBpattern"
Pattern matching user input. This pattern can be an extended regular expression with a single group.
.IP "\fBtty"
tty device to open. If it contains a "%s" it is substituted with the first group match.
.IP "\fBdevice"
TTY device to open. If it contains a "%s" it is substituted with the first group match.
.IP "\fBbaudrate"
Set baud rate
.IP "\fBdatabits"
Expand Down Expand Up @@ -433,7 +437,7 @@ Named sub-configurations can be added via labels:
.nf
.eo
[rpi3]
tty = /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
device = /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
baudrate = 115200
color = 11
.ec
Expand All @@ -458,7 +462,7 @@ A sub-configuration can also be activated by its pattern which supports regular
.eo
[usb device]
pattern = usb([0-9]*)
tty = /dev/ttyUSB%s
device = /dev/ttyUSB%s
baudrate = 115200
.ec
.fi
Expand Down Expand Up @@ -489,7 +493,7 @@ Which corresponds to the commonly used default options:

$ tio \-b 115200 \-d 8 \-f none \-s 1 \-p none /dev/ttyUSB0
.TP
It is recommended to connect serial tty devices by ID:
It is recommended to connect serial TTY devices by ID:

$ tio /dev/serial/by\-id/usb\-FTDI_TTL232R-3V3_FTGQVXBL\-if00\-port0
.PP
Expand Down Expand Up @@ -528,13 +532,13 @@ expect -i $uart "prompt> "
.RE

.TP
Redirect device I/O to network file socket for remote tty sharing:
Redirect device I/O to network file socket for remote TTY sharing:

$ tio --socket inet:4444 /dev/ttyUSB0

.TP

Then, use netcat to connect to the shared tty session over network (assuming tio is hosted on IP 10.0.0.42):
Then, use netcat to connect to the shared TTY session over network (assuming tio is hosted on IP 10.0.0.42):

$ nc -N 10.0.0.42 4444

Expand Down
20 changes: 12 additions & 8 deletions man/man1/tio.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ KEYS

ctrl-t e Toggle local echo mode

ctrl-t f Toggle log to file

ctrl-t F Flush data I/O buffers (discard data written but not transmitted and data received but not read)

ctrl-t g Toggle serial port line

ctrl-t h Toggle hexadecimal mode
Expand Down Expand Up @@ -262,7 +266,7 @@ CONFIGURATION FILE

Labels can be used to group settings into named sub-configurations which can be activated from the command-line when starting tio.

tio will try to match the user input to a sub-configuration by name or by pattern to get the tty and other options.
tio will try to match the user input to a sub-configuration by name or by pattern to get the TTY device and other options.

Options without any label change the default options.

Expand All @@ -272,7 +276,7 @@ CONFIGURATION FILE

pattern Pattern matching user input. This pattern can be an extended regular expression with a single group.

tty tty device to open. If it contains a "%s" it is substituted with the first group match.
device TTY device to open. If it contains a "%s" it is substituted with the first group match.

baudrate Set baud rate

Expand Down Expand Up @@ -338,7 +342,7 @@ CONFIGURATION FILE EXAMPLES
Named sub-configurations can be added via labels:

[rpi3]
tty = /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
device = /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
baudrate = 115200
color = 11

Expand All @@ -354,7 +358,7 @@ CONFIGURATION FILE EXAMPLES

[usb device]
pattern = usb([0-9]*)
tty = /dev/ttyUSB%s
device = /dev/ttyUSB%s
baudrate = 115200

Activate the sub-configuration by pattern match:
Expand All @@ -378,7 +382,7 @@ EXAMPLES

$ tio -b 115200 -d 8 -f none -s 1 -p none /dev/ttyUSB0

It is recommended to connect serial tty devices by ID:
It is recommended to connect serial TTY devices by ID:

$ tio /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0

Expand Down Expand Up @@ -407,11 +411,11 @@ EXAMPLES
send -i $uart "ls -la\n"
expect -i $uart "prompt> "

Redirect device I/O to network file socket for remote tty sharing:
Redirect device I/O to network file socket for remote TTY sharing:

$ tio --socket inet:4444 /dev/ttyUSB0

Then, use netcat to connect to the shared tty session over network (assuming tio is hosted on IP 10.0.0.42):
Then, use netcat to connect to the shared TTY session over network (assuming tio is hosted on IP 10.0.0.42):

$ nc -N 10.0.0.42 4444

Expand Down Expand Up @@ -439,4 +443,4 @@ WEBSITE
AUTHOR
Created by Martin Lund <[email protected]>.

tio 2.2 2022-10-18 tio(1)
tio 2.4 2022-11-02 tio(1)
Loading

0 comments on commit 8a212d1

Please sign in to comment.