mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
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> "
This commit is contained in:
parent
03e41b61a3
commit
fb453160ef
11 changed files with 335 additions and 57 deletions
31
src/socket.h
Normal file
31
src/socket.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
* Copyright (c) 2022 Google LLC
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
void socket_configure(void);
|
||||
void socket_write(char input_char);
|
||||
int socket_add_fds(fd_set *fds, bool connected);
|
||||
bool socket_handle_input(fd_set *fds, char *output_char);
|
||||
Loading…
Add table
Add a link
Reference in a new issue