]> git.sur5r.net Git - tio/commitdiff
New upstream version 2.6
authorJakob Haufe <sur5r@debian.org>
Fri, 16 Jun 2023 09:40:59 +0000 (11:40 +0200)
committerJakob Haufe <sur5r@debian.org>
Fri, 16 Jun 2023 09:40:59 +0000 (11:40 +0200)
18 files changed:
AUTHORS
NEWS
README.md
TODO
example/config
images/tio-icon.png [new file with mode: 0644]
man/tio.1.in
man/tio.1.txt
meson.build
src/configfile.c
src/log.c
src/options.c
src/options.h
src/setspeed.c
src/socket.c
src/timestamp.c
src/tty.c
src/tty.h

diff --git a/AUTHORS b/AUTHORS
index 2941ec96ab3a79d6b23ed6b1947a18b3fd24f8ac..481dbe89ae2bdba62c5a330929085252a33d6875 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -42,5 +42,8 @@ Ralph Siemsen <ralphs@netwinder.org>
 Victor Oliveira <rhapsodyv@gmail.com>
 Attila Veghelyi <aveghelyi@dension.com>
 Vyacheslav Patkov <slava@patkov.ru>
+Bill Hass <billhass@umich.edu>
+Peter van Dijk <peter@7bits.nl>
+Braden Young <braden@somewearlabs.com>
 
 Thanks to everyone who has contributed to this project.
diff --git a/NEWS b/NEWS
index cb608e073784664ce15f6846bfa2db86e58add26..7d67de2829b4e9164e05db7be795467ed74db692 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,60 @@
 
-=== tio v2.5 ===
+=== tio v2.6 ===
+
+
+
+Changes since tio v2.5:
+
+ * Remove warning when using pattern option
+
+ * 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.
+
+ * Update man page
+
+ * Update README
+
+ * Fix line termination for response wait feature
+
+   The response wait feature waited for a line response, a string
+   terminated with either CR or NL. However, some devices may send a CR and
+   then their line content and then NL. This means tio will quit before
+   receiving and printing the line response. To solve this we simply ignore
+   the CR character and only consider lines terminated with a NL character.
+
+   This should work for all devices as lines are AFAIK always terminated
+   with either CRNL or a NL.
+
+ * Update tty device listing configuration
+
+   Cleanup and add FreeBSD tty device listing support.
+
+Braden Young:
+
+ * Move map variables to tty to keep them all in one spot
+
+ * Configure socket mapping flags from tty parsing logic. Remove duplicate parsing logic in socket
+
+ * Support input mapping modes for sockets
+
+Josh Soref:
+
+ * Various spelling fixes
+
+Peter van Dijk:
+
+ * avoid "warning: unused parameter" on setspeed stub
+
+ * use right /dev/ path on Haiku
+
+Bill Hass:
+
+ * Update README with details on snap confinement
 
 
 
@@ -524,7 +579,7 @@ Changes since tio v1.39:
    pipe data to tio which then forwards the data to the connected serial
    device.
 
-   Non ineractive means that tio does not react to interactive key commands
+   Non interactive means that tio does not react to interactive key commands
    in the incoming stream. This allows users to pipe binary data directly
    to the connected serial device.
 
@@ -653,7 +708,7 @@ Changes since tio v1.38:
    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.
+   optional options with additional options with required arguments.
 
  * Replace '1' with 'enable' in config files
 
@@ -1018,10 +1073,10 @@ Alban Bedel:
  * Fix out of tree builds
 
    Out of tree builds are currently broken because $(top_srcdir)src/include
-   is not in the search path. In tree builds are working because autconf add
+   is not in the search path. In tree builds are working because autoconf adds
    $(top_builddir)/src/include to the search path for the generated config.h.
    As $(top_builddir) and $(top_srcdir) are identical during in tree builds
-   the search path still end up beeing somehow correct.
+   the search path still end up being somehow correct.
 
    To fix this add -I$(srcdir)/include to the CPPFLAGS in Makefile.am.
 
index 7625e85c693371a00ca92f286448fa01f9238574..c935cf9b9db7966de36ac1f34dcfb254a5563fc7 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,6 +1,9 @@
+
+[![tio](images/tio-icon.png)]()
+
 # tio - a simple serial device I/O tool
 
-[![](https://img.shields.io/circleci/build/gh/tio/tio?token=da7e7fd0d0ee99b9f986f8877dcdbe28f73d9e06)](https://circleci.com/gh/tio/tio/tree/master)
+[![](https://img.shields.io/circleci/build/github/tio/tio)](https://circleci.com/github/tio/tio/tree/master)
 [![](https://img.shields.io/github/v/release/tio/tio?sort=semver)](https://github.com/tio/tio/releases)
 [![](https://img.shields.io/repology/repositories/tio)](https://repology.org/project/tio/versions)
 [![](https://img.shields.io/tokei/lines/github/tio/tio)](https://github.com/tio/tio)
@@ -29,7 +32,7 @@ when used in combination with [tmux](https://tmux.github.io).
 
  * Easily connect to serial TTY devices
  * Automatic connect and reconnect
- * Sensible defaults
+ * Sensible defaults (115200 8n1)
  * Support for non-standard baud rates
  * Support for RS-485 mode
  * Support for mark and space parity
@@ -55,6 +58,7 @@ when used in combination with [tmux](https://tmux.github.io).
  * Visual or audible alert on connect/disconnect
  * Remapping of prefix key
  * Man page documentation
+ * Binary size less than 80kB
  * Plays nicely with [tmux](https://tmux.github.io)
 
 ## 3. Usage
@@ -256,9 +260,12 @@ reach out to its package maintainers team.
 
 Install latest stable version:
 ```
-$ snap install tio
+$ snap install tio --classic
 ```
 
+Note: Classic confinement is currently required due to limitations of the snapcraft framework.
+See [Issue #187](https://github.com/tio/tio/issues/187) for discussion.
+
 ### 4.3 Installation using brew (MacOS, Linux)
 
 If you have [brew](http://brew.sh) installed:
@@ -279,7 +286,7 @@ The latest source releases can be found [here](https://github.com/tio/tio/releas
 
 Install steps:
 ```
-$ meson build
+$ meson setup build
 $ meson compile -C build
 $ meson install -C build
 ```
@@ -288,6 +295,15 @@ See meson\_options.txt for tio specific build options.
 
 Note: The meson install steps may differ depending on your specific system.
 
+### 4.6 Known issues
+
+Getting permission access errors trying to open your serial device?
+
+Add your user to the group which allows serial device access. For example, to add your user to the 'dialout' group do:
+```
+$ sudo usermod -a -G dialout <username>
+```
+
 
 ## 5. Contributing
 
diff --git a/TODO b/TODO
index ce251732ca8c00583b814b5a556c6f6da661dc0c..5a0bbf12167ff996ad120773e589e6ba5f803ae0 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,3 +1,34 @@
+ * Support for interaction using simple autoresponse strings
+
+   Add support for simple autoresponse strings in the configuration file. For
+   example:
+
+   autoresponse = expect:'localhost login: ', send:'root\n',
+                  expect:'Password: ', send:'abcd1234\n'
+
+   When expect line is matched tio will respond by writing the send string.
+
+   When parsing the autoresponse variable make sure matching expect/send pairs
+   else provide warning.
+
+   Maybe support regex matching in expect string to make feature more powerful.
+
+   This is mostly a convenience feature. For more powerful scripted interaction
+   users can continue use the socket feature in combination with the expect tool
+   as described in the man page.
+
+   Maybe provide a mechanism to disable autoresponse feature. Maybe by defining
+   maximum match count and/or in session key command to toggle feature.
+
+ * Support for running external command
+
+   Add key command e.g. 'ctrl-t r' which prompts user to run external command.
+   The command will be run in a process which stdin/stdout is redirected to the
+   serial port.
+
+   This is the first step towards maybe also adding automatic support for
+   x/y/zmodem data transfer protocols by calling external programs such as
+   rb/sb, rx/sx, rz/sz, etc.
 
  * Allow tio to connect to socket
 
index 05f96c976246978fda90959722983d55f7699337..c208fbaf1cf0c06cb9879d97b90ea2181367aa82 100644 (file)
@@ -22,6 +22,7 @@ no-autoconnect = disable
 hexadecimal = disable
 timestamp = disable
 log = disable
+log-append = disable
 log-strip = disable
 local-echo = disable
 color = bold
@@ -29,7 +30,7 @@ rs-485 = disable
 response-wait = disable
 alert = none
 
-# Sub-configuraions
+# Sub-configurations
 
 [rpi3]
 baudrate = 115200
diff --git a/images/tio-icon.png b/images/tio-icon.png
new file mode 100644 (file)
index 0000000..d95d449
Binary files /dev/null and b/images/tio-icon.png differ
index 52523ee6074ccc94f0d3a267ca5550a7fbf5bb96..ba2a9ad87cbb7b0591335c8649d8d7f0da4ee325 100644 (file)
@@ -131,13 +131,21 @@ List available serial devices by ID.
 
 Enable log to file.
 
-If no filename is provided the filename will be automatically generated.
+The filename will be automatically generated using the following format
+tio_DEVICE_YYYY-MM-DDTHH:MM:SS.log.
+
+The filename can be manually set using the \-\-log-file option.
 
 .TP
 .BR "    \-\-log-file \fI<filename>
 
 Set log filename.
 
+.TP
+.BR "    \-\-log-append
+
+Append to log file.
+
 .TP
 .BR "    \-\-log-strip
 
@@ -220,8 +228,8 @@ At present there is a hardcoded limit of 16 clients connected at one time.
 .TP
 .BR \-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
+Wait for line response then quit. A line is considered any string terminated
+with a 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
@@ -280,7 +288,7 @@ Display help.
 .SH "KEYS"
 .PP
 .TP 16n
-In session, the following key sequences, a prefix key (default: ctrl-t) followed by a command key, are intercepted as tio commands:
+In session, all key strokes are forwarded to the serial device except the following key sequence: a prefix key (default: ctrl-t) followed by a command key. These sequences are intercepted as tio commands:
 .IP "\fBctrl-t ?"
 List available key commands
 .IP "\fBctrl-t b"
@@ -502,12 +510,12 @@ correct serial device if it is disconnected and then reconnected.
 .TP
 Redirect serial device I/O to Unix file socket for scripting:
 
-$ tio -S unix:/tmp/tmux-socket0 /dev/ttyUSB0
+$ tio -S unix:/tmp/tio-socket0 /dev/ttyUSB0
 
 .TP
 Then, to issue a command via the file socket simply do:
 
-$ echo "ls -la" | nc -UN /tmp/tmux-socket0 > /dev/null
+$ echo "ls -la" | nc -UN /tmp/tio-socket0 > /dev/null
 
 .TP
 Or use the expect command to script an interaction:
index c66269fd929108535b12bcda071498dafef97db3..252ca60a9ab12226700999d870e71962bd6f3a57 100644 (file)
@@ -1,4 +1,4 @@
-tio(1)                                                                                                                User Commands                                                                                                               tio(1)
+tio(1)                                                                                                                                         User Commands                                                                                                                                         tio(1)
 
 NAME
        tio - a simple serial device I/O tool
@@ -66,8 +66,7 @@ OPTIONS
 
               Disable automatic connect.
 
-              By  default tio automatically connects to the provided device if present. If the device is not present, it will wait for it to appear and then connect. If the connection is lost (eg. device disconnects), it will wait for the device to
-              reappear and then reconnect.
+              By default tio automatically connects to the provided device if present. If the device is not present, it will wait for it to appear and then connect. If the connection is lost (eg. device disconnects), it will wait for the device to reappear and then reconnect.
 
               However, if the --no-autoconnect option is provided, tio will exit if the device is not present or an established connection is lost.
 
@@ -101,12 +100,18 @@ OPTIONS
 
               Enable log to file.
 
-              If no filename is provided the filename will be automatically generated.
+              The filename will be automatically generated using the following format tio_DEVICE_YYYY-MM-DDTHH:MM:SS.log.
+
+              The filename can be manually set using the --log-file option.
 
            --log-file <filename>
 
               Set log filename.
 
+           --log-append
+
+              Append to log file.
+
            --log-strip
 
               Strip control characters and escape sequences from log.
@@ -151,8 +156,7 @@ OPTIONS
 
               Redirect I/O to socket.
 
-              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.
+              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.
 
@@ -170,7 +174,7 @@ 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.
+              Wait for line response then quit. A line is considered any string terminated with a 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.
 
@@ -215,7 +219,7 @@ OPTIONS
               Display help.
 
 KEYS
-       In session, the following key sequences, a prefix key (default: ctrl-t) followed by a command key, are intercepted as tio commands:
+       In session, all key strokes are forwarded to the serial device except the following key sequence: a prefix key (default: ctrl-t) followed by a command key. These sequences are intercepted as tio commands:
 
        ctrl-t ?        List available key commands
 
@@ -391,11 +395,11 @@ EXAMPLES
 
        Redirect serial device I/O to Unix file socket for scripting:
 
-              $ tio -S unix:/tmp/tmux-socket0 /dev/ttyUSB0
+              $ tio -S unix:/tmp/tio-socket0 /dev/ttyUSB0
 
        Then, to issue a command via the file socket simply do:
 
-              $ echo "ls -la" | nc -UN /tmp/tmux-socket0 > /dev/null
+              $ echo "ls -la" | nc -UN /tmp/tio-socket0 > /dev/null
 
        Or use the expect command to script an interaction:
 
@@ -444,4 +448,4 @@ WEBSITE
 AUTHOR
        Created by Martin Lund <martin.lund@keep-it-simple.com>.
 
-tio 2.5                                                                                                                2022-11-02                                                                                                                 tio(1)
+tio 2.6                                                                                                                                          2022-12-17                                                                                                                                          tio(1)
index 3fb3a22c6b92f8cc7e1015f3c32ddbbac3dfb828..1ed012e7507413edf5d51ae5f8e68c4255e8b0b4 100644 (file)
@@ -1,5 +1,5 @@
 project('tio', 'c',
-    version : '2.5',
+    version : '2.6',
     license : [ 'GPL-2'],
     meson_version : '>= 0.53.2',
     default_options : [ 'warning_level=2', 'buildtype=release', 'c_std=gnu99' ]
index d3dbd16aa159234cfe2112b9bce05647190cbd8a..387063bd830e13628fb1bab1d254044cafd66701 100644 (file)
@@ -198,6 +198,10 @@ static int data_handler(void *user, const char *section, const char *name,
             asprintf(&c.log_filename, "%s", value);
             option.log_filename = c.log_filename;
         }
+        else if (!strcmp(name, "log-append"))
+        {
+            option.log_append = read_boolean(value, name);
+        }
         else if (!strcmp(name, "log-strip"))
         {
             option.log_strip = read_boolean(value, name);
@@ -285,6 +289,10 @@ static int data_handler(void *user, const char *section, const char *name,
         {
             option.mute = read_boolean(value, name);
         }
+        else if (!strcmp(name, "pattern"))
+        {
+            // Do nothing
+        }
         else
         {
             tio_warning_printf("Unknown option '%s' in configuration file, ignored", name);
index d0cf54396033fd38f75fa4406e4c5a2f58a50957..de3be861d191ac39b5b45bb310d90d0cf9f55951 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -69,8 +69,17 @@ int log_open(const char *filename)
 
     log_filename = filename;
 
-    // Open log file in append write mode
-    fp = fopen(filename, "a+");
+    // Open log file
+    if (option.log_append)
+    {
+        // Appends to existing log file
+        fp = fopen(filename, "a+");
+    }
+    else
+    {
+        // Truncates existing log file
+        fp = fopen(filename, "w+");
+    }
     if (fp == NULL)
     {
         tio_warning_printf("Could not open log file %s (%s)", filename, strerror(errno));
index eb75144edf7ae99445fa1b67dd7697659b311edb..6217cc48ef932c631b63651d9cfe34cb9aabeaab 100644 (file)
@@ -74,6 +74,7 @@ struct option_t option =
     .ri_pulse_duration = 100,
     .no_autoconnect = false,
     .log = false,
+    .log_append = false,
     .log_filename = NULL,
     .log_strip = false,
     .local_echo = false,
@@ -119,6 +120,7 @@ void print_help(char *argv[])
     printf("  -L, --list-devices                     List available serial devices by ID\n");
     printf("  -l, --log                              Enable log to file\n");
     printf("      --log-file <filename>              Set log filename\n");
+    printf("      --log-append                       Append to log file\n");
     printf("      --log-strip                        Strip control characters and escape sequences\n");
     printf("  -m, --map <flags>                      Map characters\n");
     printf("  -c, --color 0..255|bold|none|list      Colorize tio text (default: bold)\n");
index 8ae556d5271ae748af8f8ac3e7104d166e94baf6..b18d8ffbbc552666bbf56a6beb28eb5a167b1a4b 100644 (file)
@@ -48,6 +48,7 @@ struct option_t
     unsigned int ri_pulse_duration;
     bool no_autoconnect;
     bool log;
+    bool log_append;
     bool log_strip;
     bool local_echo;
     enum timestamp_t timestamp;
index 745bd4b519b053c85d3c9d5d426d0e4266f0e8c6..012d97ba1726ad45398dd52bed5a237e8a2c9468 100644 (file)
@@ -33,6 +33,7 @@
 #include <IOKit/serial/ioss.h>
 #endif
 
+#include "misc.h"
 
 #ifdef HAVE_TERMIOS2
 int setspeed(int fd, int baudrate)
@@ -62,6 +63,9 @@ int setspeed(int fd, int baudrate)
 #else
 int setspeed(int fd, int baudrate)
 {
+    UNUSED(fd);
+    UNUSED(baudrate);
+
     errno = EINVAL;
     return -1;
 }
index 16d962189540a7ce44c343bace3fa4104ecf83dc..23b12498d5e0acbebfd6c7af0db6c793bc81f393 100644 (file)
@@ -33,6 +33,7 @@
 #include "socket.h"
 #include "options.h"
 #include "print.h"
+#include "tty.h"
 
 #define MAX_SOCKET_CLIENTS 16
 #define SOCKET_PORT_DEFAULT 3333
@@ -340,11 +341,26 @@ bool socket_handle_input(fd_set *rdfs, char *output_char)
                 clientfds[i] = -1;
                 continue;
             }
-            /* match the behavior of a terminal in raw mode */
-            if (*output_char == '\n')
+
+            /* If INLCR is set, a received NL character shall be translated into a CR character */
+            if (*output_char == '\n' && map_i_nl_cr)
             {
                 *output_char = '\r';
             }
+            else if (*output_char == '\r')
+            {
+                /* If IGNCR is set, a received CR character shall be ignored (not read). */
+                if (map_ign_cr)
+                {
+                    return false;
+                }
+
+                /* If IGNCR is not set and ICRNL is set, a received CR character shall be translated into an NL character. */
+                if (map_i_cr_nl)
+                {
+                    *output_char = '\n';
+                }
+            }
             return true;
         }
     }
index b8a219828f07219b7ff9f646038ee92e1c3eb613..91374dd3a99d3c0a6d0ea583c6cd5cbfe7639e11 100644 (file)
@@ -50,7 +50,7 @@ char *timestamp_current_time(void)
         first = false;
     }
 
-    // Add formatted timestap
+    // Add formatted timestamp
     switch (option.timestamp)
     {
         case TIMESTAMP_NONE:
index f5ffc355fd330a42b88a06d64da6ce4b05d88aa9..186fa77c9745100a6f0442bd9de5f4b612abcc23 100644 (file)
--- a/src/tty.c
+++ b/src/tty.c
 #include "timestamp.h"
 #include "misc.h"
 
-#if defined(__APPLE__)
+/* tty device listing configuration */
+
+#if defined(__linux__)
+#define PATH_SERIAL_DEVICES "/dev/serial/by-id/"
+#define PREFIX_TTY_DEVICES ""
+#elif defined(__FreeBSD__)
+#define PATH_SERIAL_DEVICES "/dev/"
+#define PREFIX_TTY_DEVICES "cua"
+#elif defined(__APPLE__)
 #define PATH_SERIAL_DEVICES "/dev/"
 #define PREFIX_TTY_DEVICES "tty."
 #elif defined(__CYGWIN__)
 #define PATH_SERIAL_DEVICES "/dev/"
 #define PREFIX_TTY_DEVICES "ttyS"
-#else
-#define PATH_SERIAL_DEVICES "/dev/serial/by-id/"
+#elif defined(__HAIKU__)
+#define PATH_SERIAL_DEVICES "/dev/ports/"
 #define PREFIX_TTY_DEVICES ""
+#else
+#define PATH_SERIAL_DEVICES "/dev/"
+#define PREFIX_TTY_DEVICES "tty"
 #endif
 
 #ifndef CMSPAR
@@ -118,6 +129,9 @@ const char random_array[] =
 };
 
 bool interactive_mode = true;
+bool map_i_nl_cr = false;
+bool map_i_cr_nl = false;
+bool map_ign_cr = false;
 
 static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old;
 static unsigned long rx_total = 0, tx_total = 0;
@@ -976,14 +990,17 @@ void tty_configure(void)
             if (strcmp(token,"INLCR") == 0)
             {
                 tio.c_iflag |= INLCR;
+                map_i_nl_cr = true;
             }
             else if (strcmp(token,"IGNCR") == 0)
             {
                 tio.c_iflag |= IGNCR;
+                map_ign_cr = true;
             }
             else if (strcmp(token,"ICRNL") == 0)
             {
                 tio.c_iflag |= ICRNL;
+                map_i_cr_nl = true;
             }
             else if (strcmp(token,"OCRNL") == 0)
             {
@@ -1409,7 +1426,7 @@ int tty_connect(void)
 
                     if (option.response_wait)
                     {
-                        if ((input_char == '\r') || (input_char == '\n'))
+                        if (input_char == '\n')
                         {
                              tty_sync(fd);
                              exit(EXIT_SUCCESS);
index c4b67974971cb7e3e8f028c898fce214d8b1aa07..add8bf1dff89f2a04d38e9a00eca3bf9cf1ab136 100644 (file)
--- a/src/tty.h
+++ b/src/tty.h
@@ -24,6 +24,9 @@
 #include <stdbool.h>
 
 extern bool interactive_mode;
+extern bool map_i_nl_cr;
+extern bool map_i_cr_nl;
+extern bool map_ign_cr;
 
 void stdout_configure(void);
 void stdin_configure(void);