Commit graph

54 commits

Author SHA1 Message Date
Martin Lund
d34fa1c1ad Rename mapping flag MSB2LSB to IMSB2LSB
This is the correct naming since we are changing the input bit order on
input from the serial device.
2024-06-29 12:14:34 +02:00
Martin Lund
4723cc3f4e Add OIGNCR mapping flag
Ignores CR on output to serial device.
2024-06-27 20:09:25 +02:00
Martin Lund
8014ef68c0 Cleanup parsing of mapping flags 2024-06-02 14:26:39 +02:00
Martin Lund
ae9c8edbca Clean up includes 2024-05-11 10:50:01 +02:00
Martin Lund
e75e19eb00 Add option '--exec <command>' for running shell command
Runs shell command with I/O redirected to device.
2024-05-07 14:38:31 +02:00
Martin Lund
65c5a068d8 Replace inih with glib key file parser
After including the use of glib we might as well replace inih
with the glib key file parser.

All configuraiton file parsing has been reworked and also the options
parsing has been cleaned up, resulting in better and stricter
configuration file and option value checks.

Compared to old, configuration files now requires any default
configurations to be put in a group/section named [default].

Configuration file keywords such as "enable", "disable", "on",
"off", "yes", "no", "0", "1" have been retired. Now only "true" and
"false" apply to boolean configuration options. This is done to simplify
things and avoid any confusion.

The pattern option feature has been reworked so now the user can now
access the full match string and any matching subexpression using the
%mN syntax.

For example:

[usb devices]
pattern = usb([0-9]*)
device = /dev/ttyUSB%m1

Then when using tio:
$ tio usb12

   %m0 = 'usb12'  // Full match string
   %m1 = 12       // First match subexpression

Which results in device = /dev/ttyUSB12
2024-05-02 18:35:37 +02:00
Martin Lund
f5f62ee02d Disable DEC Special Graphics at exit if vt100
If a vt100 terminal receives the Shift In character '\016' it will
enable the 7 bit DEC Special Graphics character set used for line drawing.

For most users this can happen due to line noise from the tty device and
will likely mess up your terminal even after tio exits.

To better handle this we want to make sure that tio disables this mode
by sending the Shift Out character '\017' at exit.

This mechanism will only activate if environment variable TERM assumes
value "vt100".
2024-04-27 17:32:48 +02:00
Martin Lund
42ff234204 Add hexN output mode
Adds support for hexN mode where N is a number in the range 1 to 4096
which defines how many hex values will be printed before a line break.

In short, it defines the width of the hex output.

In this mode, if timestamps are enabled they will be added to each hex
line.
2024-04-27 15:25:34 +02:00
Martin Lund
232cbee697 Rename sub-config to profile
Because better naming.
2024-04-27 09:13:33 +02:00
Martin Lund
d19ba1c492 Add new ways to manage serial devices
* Rename --list-devices to --list

 * Rename --no-autoconnect to --no-reconnect

 * Switch -l and -L options

   * -l now lists available serial devices

   * -L enables log to file

 * Add option --auto-connect <strategy>

   * Supported strategies:

     * "new" - Waits to connect first new appearing serial device

     * "latest" - Connects to latest registered serial device

     * "direct" - Connect directly to specified serial device (default)

 * Add options to exclude serial devices from auto connect strategy by
   pattern

   * Supported exclude options:

     * --exclude-devices <pattern>

       Example: '--exclude-devices "/dev/ttyUSB2,/dev/ttyS?"'

     * --exclude-drivers <pattern>

       Example: '--exclude-drivers "cdc_acm"'

     * --exclude-tids <pattern>

       Example: '--exclude-tids "yW07,bCC2"'

     * Patterns support '*' and '?'

 * Connect to same port/device combination via unique topology ID (TID)

   * Topology ID is a 4 digit base62 encoded hash of a device topology
     string coming from the Linux kernel. This means that whenever you
     plug in the same e.g. USB serial port device to the same USB hub
     port connected via the exact same hub topology all the way to your
     computer, you will get the same unique TID.

   * Useful for stable reconnections when serial device has no serial
     device by ID

   * For now, only tested on Linux.

 * Reworked and improved listing of serial devices to show serial devices:

   * By device

     * Including TID, uptime, driver, and description.

     * Sorted by uptime (newest device listed last)

   * By unique topology ID

   * By ID

   * By path

 * Add script interface 'list = tty_search()' for searching for serial
   devices.
2024-04-26 22:19:22 +02:00
Martin Lund
ae76f8f58d Clean up timestamp enum definition 2024-04-20 15:02:43 +02:00
Martin Lund
b05f38abd0 Add missing options to show configuration 2024-04-20 14:51:45 +02:00
Martin Lund
6fff4939e4 Add timeout based timestamps in hex output mode
This change reintroduces timestamping in hex output mode but based on
timeout instead of new lines which made no sense. This means that
timestamps will only be printed when timeout time has elapsed with no
output activity from serial device.

Adds option --timestamp-timeout <ms> for setting the timeout value in
milliseconds.

Defaults to 200 ms.
2024-04-18 15:52:45 +02:00
Martin Lund
4801816357 Introduce basic line input mode 2024-04-16 17:42:34 +02:00
Martin Lund
97537853a8 Remove options --response-wait, --response-timeout
Remove options and rework input handling so it is possible to do the
same thing but via script which is much more flexible.

These options were always a bit of a hardcoded solution. With the new
script expect feature we can wait for any type of response.

For example, pipe command to serial device and wait for line response within 1 second:

$ echo "*IDN?" | tio /dev/ttyACM0 --script "expect('\r\n', 1000)" --mute
2024-04-13 23:18:25 +02:00
Martin Lund
0afae5d3ee Update text 2024-04-12 13:03:51 +02:00
Martin Lund
2fff4d36d0 Add independent input and output mode
Replaces -x, --hexadecimal option with --intput-mode and --output-mode
so it is possible to select hex or normal mode for both input and output
independently.

To obtain same behaviour as -x, --hexadecimal use the following
configuration:

input-mode = hex
output-mode = hex
2024-04-10 14:40:18 +02:00
Martin Lund
70913fe120 Add --log-directory option
For specifying directory path in which to save automatically named log
files.
2024-04-04 12:31:55 +02:00
Martin Lund
0becfa3274 Add Lua scripting feature
Add support for running Lua scripts that can manipulate the tty control
lines. Script is activated automatically on connect or manually via in
session key command.

The Lua scripting feature opens up for many posibilities in the future
such as adding expect like functionality to easily and programatically
interact with the connected device.
2024-04-01 15:37:40 +02:00
Martin Lund
593f9495f4 Add support for disabling prefix key handling
To disable prefix key input handing simply set prefix-ctrl-key to
'none'.

Based on original patch from Sebastian Krahmer.
2024-02-19 16:51:02 +01:00
Martin Lund
148a3c1da1 Add --log-append option
Add --log-append option which makes tio append to any existing log file.

This also changes the default behaviour of tio from appending to
overwriting any existing log file. Now you have to use this new option
to make tio append.
2023-04-28 20:50:34 +02:00
Martin Lund
a97b2c00cd Add shell completion of sub-configuration names
Does not work with sub configuration names that contains one or more
white spaces.
2022-10-16 23:02:04 +02:00
Martin Lund
1dc3a3891d Cleanup 2022-09-10 23:31:02 +02:00
Martin Lund
ba2d49d2f7 Consolidate timestamp implementation in one file 2022-09-10 23:29:23 +02:00
Martin Lund
dbc9a8e82d Add visual or audible alert support on connect/disconnect
The feature is detailed via the following option:

 --alert none|bell|blink

     Set alert action on connect/disconnect.

     It will sound the bell once or blink once on successful connect.
     Likewise it will sound the bell twice or blink twice on disconnect.

     Default value is "none" for no alert.
2022-09-10 22:33:42 +02:00
Martin Lund
ee46686fb6 Add experimental RS-485 support
Many modern RS-485 serial devices such as the ones from FTDI already
operate in RS-485 mode by default and will work with tio out of the box.
However, there are some RS-232/485 devices which need to be switched
from e.g. RS-232 to RS-485 mode to operate accordingly on the physical
level.

This commit implements the switching mechanism and interface required to
enable RS-485 mode. It only works on Linux and with serial devices which
use device drivers that support the Linux RS-485 control interface.

The RS-485 feature is detailed via the following options:

 --rs-485                           Enable RS-485 mode
 --rs-485-config <config>           Set RS-485 configuration

Set the RS-485 configuration using the following key or key value pair
format in the configuration field:

 RTS_ON_SEND=value             Set logical level (0 or 1) for RTS pin when sending
 RTS_AFTER_SEND=value          Set logical level (0 or 1) for RTS pin after sending
 RTS_DELAY_BEFORE_SEND=value   Set RTS delay (ms) before sending
 RTS_DELAY_AFTER_SEND=value    Set RTS delay (ms) after sending
 RX_DURING_TX                  Receive data even while sending data

If defining more than one key or key value pair, they must be comma
separated.

Example use:

 $ tio /dev/ttyUSB0 --rs-485 --rs-r485-config=RTS_DELAY_AFTER_SEND=50,RX_DURING_TX
2022-09-10 17:52:54 +02:00
Martin Lund
e837fd0303 Add line response feature
Add a simple line response feature to make it possible to send e.g. a
command string to your serial device and easily receive and parse a line
response.

This is a convenience feature for simple request/response interaction
based on lines. For more advanced interaction the socket feature should
be used instead.

The line response feature is detailed via the following options:

 -r, --response-wait

Wait for line response then quit. A line is considered any string ending
with either CR or NL character. If no line is received tio will quit
after response timeout.

Any tio text is automatically muted when piping a string to tio while in
response mode to make it easy to parse the response.

 --response-timeout <ms>

Set timeout [ms] of line response (default: 100).

Example:

Sending a string (SCPI command) to a test instrument (Korad PSU) and
print line response:

 $ echo "*IDN?" | tio /dev/ttyACM0 --response-wait
 KORAD KD3305P V4.2 SN:32477045
2022-08-15 19:58:28 +02:00
Martin Lund
3903880106 Rework toggle and pulse feature to support all lines
Replace existing toggle and pulse key commands with the following
generalized key commands which allows to toggle or pulse all serial port
lines:

 ctrl-t g   Toggle serial port line
 ctrl-t p   Pulse serial port line

When used, user will be asked which serial line to toggle or pulse.

Also introduce --line-pulse-duration option for setting specific pulse
duration in milliseconds for each serial line using a key value pair
format. Each key represents a serial line. The following keys are
available: DTR, RTS, CTS, DSR, DCD, RI.

Example:

 $ tio /dev/ttyUSB0 --line-pulse-duration DTR=200,RTS=300,RI=50

Likewise, the pulse duration can also be set via configuration file
using the line-pulse-duration variable:

 line-pulse-duration = DTR=200,RTS=300,RI=50
2022-07-19 12:54:40 +02:00
Martin Lund
02729c10b1 Add support for remapping prefix key
Make it possible to remap the prefix key (default: ctrl-t) by setting
the prefix-ctrl-key variable in the configuration file.

Allowed values are in the range a..z.

Example, to set the prefix key to ctrl-a simply do:

prefix-ctrl-key = a
2022-07-15 12:18:40 +02:00
Martin Lund
39af74f263 Rename EOL delay to Output line delay 2022-07-11 14:08:12 +02:00
Martin Lund
11762b2300 Replace -U,--upcase with mapping flag OLTU 2022-07-11 10:15:12 +02:00
Robert Snell
944ee9173b Additional commands: EOL delay, lower to upper translation, added mark parity
Added command line options:
-O, --eol-delay to have a separate delay for end of line
-U, --upper to enable translation of lower case alpha to upper case

Added ability to set mark parity.
Added ctrl-t U key sequence to allow enable/disable lower case alpha to
upper case during a session.
Updated Man page with command line options, ctrl-t sequences and
configuration file options.
Updated README.md, with above information.
2022-07-09 21:22:43 -04:00
George Joseph
f24cee61e7 Add Pulse DTR command
MCUs like the ESP32 can be reset if the serial port DTR line is
pulsed for a short time.  You could just type CTRL-t d CTRL-t d
but that's a little awkward since you have to lift your finger
off the CTRL key to type the Ds.  Now you can just type CTRL-T D.

* Added new command "D" to pulse the DTR line.  I.E.  Toggle its
  state twice with a configurable duration between toggles.

* Added new config/command line option "--dtr-pulse-duration"
  to set the duration between the DTR state toggles.  The default
  is 100ms.
2022-07-07 12:45:29 -06:00
Martin Lund
72fd2f2980 Fix timestamp configuration state 2022-07-06 13:22:19 +02:00
Martin Lund
732c0c3f89 Add '24hour-delta' timestamp option
When enabled this option will timestamp new lines with the time elapsed
since the line before.

This is a very useful feature to identify which events takes the most
time.
2022-07-05 16:05:38 +02:00
Martin Lund
256d6b4fc2 Merge branch 'allow_strip_esc_key' of https://github.com/nh26223/tio into nh26223-allow_strip_esc_key 2022-06-15 22:49:22 +02:00
Martin Lund
63d3232b32 Improve key command response for local echo and timestamp 2022-06-12 04:07:17 +02:00
Martin Lund
bf749aead4 Cleanup list devices code 2022-06-11 23:14:18 +02:00
Martin Lund
a0d4be068b Fix command-line tty-device|config parsing
Allow user to add options on both sides of the provided config argument.

For example:

 $ tio -b 9600 am64-evm -e

Before, tio only allowed adding arguments after the config argument.

Implemented as simple as possible by introducing two stage option parsing.
2022-06-11 22:56:03 +02:00
Martin Lund
6d007d39d7 Remove newline option in hex mode 2022-06-06 19:38:31 +02:00
g0mb4
0b55981e52 Extended hexadecimal mode.
While in hex mode (ctrl-t h) you can output hexadecimal values.
E.g.: to send 0x0A you have to type 0A (always 2 characters).

Added option -x, --hex to start in hexadecimal mode.

Added option --newline-in-hex to interpret newline characters in hex mode.
This is disabled by default, because, in my opinion, hex stream is
fundamentally different from text, so a "new line" is meaningless in this
context.
2022-06-06 19:10:00 +02:00
Martin Lund
9476422922 Remove command-line option inconsistencies
Optional arguments, as parsed by the getopt_long mechanism, are
inherently inconsistent with how you define required arguments.

To avoid confusion we decide to avoid this inconsistency by replacing
optional options with additional options with required argmuments.
2022-06-04 19:08:05 +02:00
Peter Collingbourne
fb453160ef Add support for external control via a Unix domain socket.
This feature allows an external program to inject output into and
listen to input from a serial port via a Unix domain socket (path
specified via the -S/--socket command line flag, or the socket
config file option) while tio is running. This is useful for ad-hoc
scripting of serial port interactions while still permitting manual
control. Since many serial devices (at least on Linux) get confused
when opened by multiple processes, and most commands do not know
how to correctly open a serial device, this allows a more convenient
usage model than directly writing to the device node from an external
program.

Any input from clients connected to the socket is sent on the serial
port as if entered at the terminal where tio is running (except that
ctrl-t sequences are not recognized), and any input from the serial
port is multiplexed to the terminal and all connected clients.

Sockets remain open while the serial port is disconnected, and writes
will block.

Example usage 1 (issue a command):

  echo command | nc -UN /path/to/socket > /dev/null

Example usage 2 (use the expect command to script an interaction):

  #!/usr/bin/expect -f

  set timeout -1
  log_user 0

  spawn nc -UN /path/to/socket
  set uart $spawn_id

  send -i $uart "command1\n"
  expect -i $uart "prompt> "
  send -i $uart "command2\n"
  expect -i $uart "prompt> "
2022-04-18 14:06:33 -07:00
Martin Lund
28c880cdab Remove verbose option
Remove the command-line verbose option but let the ctrl-t c feature
print some of the verbose information (active config path/section).
2022-04-13 16:28:30 +02:00
Sylvain LAFRASSE
a543fbd7ef Factorize timestamp parsing to be coherent with command line format in configuration file. 2022-03-30 17:11:50 +02:00
Martin Lund
8965b7b42c Update headers 2022-03-11 15:15:39 +01:00
Martin Lund
a2b164519f Mostly cosmetic updates 2022-03-11 15:11:43 +01:00
Martin Lund
e9d5a23129 Move string_to_long() to misc.c 2022-03-11 13:33:35 +01:00
Liam Beguin
04da651f09 options: expose string_to_long()
Expose string_to_long() so that other source files can use it.

Signed-off-by: Liam Beguin <liambeguin@gmail.com>
2022-03-09 20:15:30 -05:00
Martin Lund
d8a822a3fb Add support for configurable timestamp format
Also changes default timestamp format from ISO8601 to classic 24-hour
format as this is assumed to be the format that most users would prefer.

And reintroduces strict but optional ISO8601 format.

This feature allows to easily add more timestamp formats in the future.
2022-02-19 02:26:10 +01:00