mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Merge 13f86bd18a into 6fb3a64ba2
This commit is contained in:
commit
4b621a1cd8
12 changed files with 830 additions and 499 deletions
|
|
@ -3,3 +3,7 @@ IndentWidth: 4
|
||||||
AllowShortFunctionsOnASingleLine: None
|
AllowShortFunctionsOnASingleLine: None
|
||||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
BreakBeforeBraces: Allman
|
BreakBeforeBraces: Allman
|
||||||
|
IndentCaseLabels: true
|
||||||
|
ColumnLimit: 144
|
||||||
|
SortIncludes: false
|
||||||
|
SkipMacroDefinitionBody: true
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ when used in combination with [tmux](https://tmux.github.io).
|
||||||
* Useful for reconnecting when serial device has no serial device by ID
|
* Useful for reconnecting when serial device has no serial device by ID
|
||||||
* Support for non-standard baud rates
|
* Support for non-standard baud rates
|
||||||
* Support for mark and space parity
|
* Support for mark and space parity
|
||||||
* X-modem (1K/CRC) and Y-modem file upload
|
* X-modem (1K/CRC/Checksum) and Y-modem file upload
|
||||||
* Support for RS-485 mode
|
* Support for RS-485 mode
|
||||||
* List available serial devices
|
* List available serial devices
|
||||||
* By device
|
* By device
|
||||||
|
|
@ -431,7 +431,7 @@ Returns the `tio` table.
|
||||||
|
|
||||||
Send file using x/y-modem protocol.
|
Send file using x/y-modem protocol.
|
||||||
|
|
||||||
Protocol can be any of `XMODEM_1K`, `XMODEM_CRC`, `YMODEM`.
|
Protocol can be any of `XMODEM_1K`, `XMODEM_CRC`, `XMODEM_SUM`, `YMODEM`.
|
||||||
|
|
||||||
#### `tio.ttysearch()`
|
#### `tio.ttysearch()`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -205,8 +205,8 @@ Strip control characters and escape sequences from log.
|
||||||
.TP
|
.TP
|
||||||
.BR \-m ", " "\-\-map " \fI<flags>
|
.BR \-m ", " "\-\-map " \fI<flags>
|
||||||
|
|
||||||
Map (replace, translate) characters on input to the serial device or output
|
Map (replace, translate) characters on input from the serial device or output
|
||||||
from the serial device. The following mapping flags are supported:
|
to the serial device. The following mapping flags are supported:
|
||||||
|
|
||||||
.RS
|
.RS
|
||||||
.TP 12n
|
.TP 12n
|
||||||
|
|
@ -426,7 +426,7 @@ Toggle line timestamp mode
|
||||||
.IP "\fBctrl-t v"
|
.IP "\fBctrl-t v"
|
||||||
Show version
|
Show version
|
||||||
.IP "\fBctrl-t x"
|
.IP "\fBctrl-t x"
|
||||||
Send file using the XMODEM-1K or XMODEM-CRC protocol (prompts for file name and protocol)
|
Send file using the XMODEM-1K or XMODEM-CRC or XMODEM-SUM protocol (prompts for file name and protocol)
|
||||||
.IP "\fBctrl-t y"
|
.IP "\fBctrl-t y"
|
||||||
Send file using the YMODEM protocol (prompts for file name)
|
Send file using the YMODEM protocol (prompts for file name)
|
||||||
.IP "\fBctrl-t ctrl-t"
|
.IP "\fBctrl-t ctrl-t"
|
||||||
|
|
@ -468,7 +468,7 @@ Returns the tio table.
|
||||||
.IP "\fBtio.send(file, protocol)"
|
.IP "\fBtio.send(file, protocol)"
|
||||||
Send file using x/y-modem protocol.
|
Send file using x/y-modem protocol.
|
||||||
|
|
||||||
Protocol can be any of XMODEM_1K, XMODEM_CRC, YMODEM.
|
Protocol can be any of XMODEM_1K, XMODEM_CRC, XMODEM_SUM, YMODEM.
|
||||||
|
|
||||||
.IP "\fBtio.ttysearch()"
|
.IP "\fBtio.ttysearch()"
|
||||||
Search for serial devices.
|
Search for serial devices.
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ OPTIONS
|
||||||
|
|
||||||
-m, --map <flags>
|
-m, --map <flags>
|
||||||
|
|
||||||
Map (replace, translate) characters on input to the serial device or output from the serial device. The following mapping flags are supported:
|
Map (replace, translate) characters on input from the serial device or output to the serial device. The following mapping flags are supported:
|
||||||
|
|
||||||
ICRNL Map CR to NL on input (unless IGNCR is set)
|
ICRNL Map CR to NL on input (unless IGNCR is set)
|
||||||
|
|
||||||
|
|
@ -342,7 +342,7 @@ KEY COMMANDS
|
||||||
|
|
||||||
ctrl-t v Show version
|
ctrl-t v Show version
|
||||||
|
|
||||||
ctrl-t x Send file using the XMODEM-1K or XMODEM-CRC protocol (prompts for file name and protocol)
|
ctrl-t x Send file using the XMODEM-1K or XMODEM-CRC or XMODEM-SUM protocol (prompts for file name and protocol)
|
||||||
|
|
||||||
ctrl-t y Send file using the YMODEM protocol (prompts for file name)
|
ctrl-t y Send file using the YMODEM protocol (prompts for file name)
|
||||||
|
|
||||||
|
|
@ -382,7 +382,7 @@ SCRIPT API
|
||||||
send(file, protocol)
|
send(file, protocol)
|
||||||
Send file using x/y-modem protocol.
|
Send file using x/y-modem protocol.
|
||||||
|
|
||||||
Protocol can be any of XMODEM_1K, XMODEM_CRC, YMODEM.
|
Protocol can be any of XMODEM_1K, XMODEM_CRC, XMODEM_SUM, YMODEM.
|
||||||
|
|
||||||
tty_search()
|
tty_search()
|
||||||
Search for serial devices.
|
Search for serial devices.
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,8 @@ int main(int argc, char *argv[])
|
||||||
if (interactive_mode)
|
if (interactive_mode)
|
||||||
{
|
{
|
||||||
tio_printf("Press ctrl-%c q to quit", option.prefix_key);
|
tio_printf("Press ctrl-%c q to quit", option.prefix_key);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
tio_printf("Non-interactive mode enabled");
|
tio_printf("Non-interactive mode enabled");
|
||||||
tio_printf("Press ctrl-c to quit");
|
tio_printf("Press ctrl-c to quit");
|
||||||
|
|
|
||||||
|
|
@ -98,12 +98,17 @@ int read_poll(int fd, void *data, size_t len, int timeout)
|
||||||
if (fds.revents & POLLIN)
|
if (fds.revents & POLLIN)
|
||||||
{
|
{
|
||||||
// Read ready data
|
// Read ready data
|
||||||
|
// return value should not be 0
|
||||||
return read(fd, data, len);
|
return read(fd, data, len);
|
||||||
}
|
}
|
||||||
|
else /* if (fds.revents & (POLLERR | POLLHUP | POLLNVAL)) */
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Timeout */
|
/* Timeout */
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to calculate djb2 hash of string
|
// Function to calculate djb2 hash of string
|
||||||
|
|
@ -170,6 +175,7 @@ bool match_patterns(const char *string, const char *patterns)
|
||||||
pattern = strtok(patterns_copy, ",");
|
pattern = strtok(patterns_copy, ",");
|
||||||
while (pattern != NULL)
|
while (pattern != NULL)
|
||||||
{
|
{
|
||||||
|
// clang-format off
|
||||||
// Check if the string matches the current pattern
|
// Check if the string matches the current pattern
|
||||||
#ifdef FNM_EXTMATCH
|
#ifdef FNM_EXTMATCH
|
||||||
if (fnmatch(pattern, string, FNM_EXTMATCH) == 0)
|
if (fnmatch(pattern, string, FNM_EXTMATCH) == 0)
|
||||||
|
|
@ -180,6 +186,7 @@ bool match_patterns(const char *string, const char *patterns)
|
||||||
free(patterns_copy);
|
free(patterns_copy);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
// Move to the next pattern
|
// Move to the next pattern
|
||||||
pattern = strtok(NULL, ",");
|
pattern = strtok(NULL, ",");
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ enum opt_t
|
||||||
OPT_EXEC,
|
OPT_EXEC,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
/* Default options */
|
/* Default options */
|
||||||
struct option_t option =
|
struct option_t option =
|
||||||
{
|
{
|
||||||
|
|
@ -125,6 +126,7 @@ struct option_t option =
|
||||||
.map_i_msb2lsb = false,
|
.map_i_msb2lsb = false,
|
||||||
.map_o_ign_cr = false,
|
.map_o_ign_cr = false,
|
||||||
};
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void option_print_help(char *argv[])
|
void option_print_help(char *argv[])
|
||||||
{
|
{
|
||||||
|
|
@ -833,12 +835,14 @@ void options_print()
|
||||||
tio_printf(" Output line delay: %d", option.output_line_delay);
|
tio_printf(" Output line delay: %d", option.output_line_delay);
|
||||||
tio_printf(" Automatic connect strategy: %s", option_auto_connect_state_to_string(option.auto_connect));
|
tio_printf(" Automatic connect strategy: %s", option_auto_connect_state_to_string(option.auto_connect));
|
||||||
tio_printf(" Automatic reconnect: %s", option.no_reconnect ? "true" : "false");
|
tio_printf(" Automatic reconnect: %s", option.no_reconnect ? "true" : "false");
|
||||||
|
// clang-format off
|
||||||
tio_printf(" Pulse duration: DTR=%d RTS=%d CTS=%d DSR=%d DCD=%d RI=%d", option.dtr_pulse_duration,
|
tio_printf(" Pulse duration: DTR=%d RTS=%d CTS=%d DSR=%d DCD=%d RI=%d", option.dtr_pulse_duration,
|
||||||
option.rts_pulse_duration,
|
option.rts_pulse_duration,
|
||||||
option.cts_pulse_duration,
|
option.cts_pulse_duration,
|
||||||
option.dsr_pulse_duration,
|
option.dsr_pulse_duration,
|
||||||
option.dcd_pulse_duration,
|
option.dcd_pulse_duration,
|
||||||
option.ri_pulse_duration);
|
option.ri_pulse_duration);
|
||||||
|
// clang-format on
|
||||||
tio_printf(" Input mode: %s", option_input_mode_to_string(option.input_mode));
|
tio_printf(" Input mode: %s", option_input_mode_to_string(option.input_mode));
|
||||||
tio_printf(" Output mode: %s", option_output_mode_to_string(option.output_mode));
|
tio_printf(" Output mode: %s", option_output_mode_to_string(option.output_mode));
|
||||||
tio_printf(" Alert: %s", option_alert_state_to_string(option.alert));
|
tio_printf(" Alert: %s", option_alert_state_to_string(option.alert));
|
||||||
|
|
@ -887,8 +891,9 @@ void options_parse(int argc, char *argv[])
|
||||||
option.vt100 = true;
|
option.vt100 = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1)
|
while (true)
|
||||||
{
|
{
|
||||||
|
// clang-format off
|
||||||
static struct option long_options[] =
|
static struct option long_options[] =
|
||||||
{
|
{
|
||||||
{"baudrate", required_argument, 0, 'b' },
|
{"baudrate", required_argument, 0, 'b' },
|
||||||
|
|
@ -932,6 +937,7 @@ void options_parse(int argc, char *argv[])
|
||||||
{"complete-profiles", no_argument, 0, OPT_COMPLETE_PROFILES },
|
{"complete-profiles", no_argument, 0, OPT_COMPLETE_PROFILES },
|
||||||
{0, 0, 0, 0 }
|
{0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
/* getopt_long stores the option index here */
|
/* getopt_long stores the option index here */
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
|
|
@ -1176,6 +1182,7 @@ void options_parse_final(int argc, char *argv[])
|
||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
unsigned char portnum;
|
unsigned char portnum;
|
||||||
char *tty_win;
|
char *tty_win;
|
||||||
|
// clang-format off
|
||||||
if ( ((strncmp("COM", option.target, 3) == 0)
|
if ( ((strncmp("COM", option.target, 3) == 0)
|
||||||
|| (strncmp("com", option.target, 3) == 0) )
|
|| (strncmp("com", option.target, 3) == 0) )
|
||||||
&& (sscanf(option.target + 3, "%hhu", &portnum) == 1)
|
&& (sscanf(option.target + 3, "%hhu", &portnum) == 1)
|
||||||
|
|
@ -1184,5 +1191,6 @@ void options_parse_final(int argc, char *argv[])
|
||||||
asprintf(&tty_win, "/dev/ttyS%hhu", portnum - 1);
|
asprintf(&tty_win, "/dev/ttyS%hhu", portnum - 1);
|
||||||
option.target = tty_win;
|
option.target = tty_win;
|
||||||
}
|
}
|
||||||
|
// clang-format on
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,7 @@ static void readline_input_left_bracket(void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
readline_input_char('[');
|
||||||
rl_escape = 0;
|
rl_escape = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
24
src/script.c
24
src/script.c
|
|
@ -45,6 +45,7 @@
|
||||||
|
|
||||||
static int device_fd;
|
static int device_fd;
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
static char script_init[] =
|
static char script_init[] =
|
||||||
"tio.set = function(arg)\n"
|
"tio.set = function(arg)\n"
|
||||||
" local dtr = arg.DTR or -1\n"
|
" local dtr = arg.DTR or -1\n"
|
||||||
|
|
@ -71,6 +72,7 @@ static char script_init[] =
|
||||||
"end\n"
|
"end\n"
|
||||||
"tio.alwaysecho = true\n"
|
"tio.alwaysecho = true\n"
|
||||||
"setmetatable(tio, tio)\n";
|
"setmetatable(tio, tio)\n";
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
static bool alwaysecho(lua_State *L)
|
static bool alwaysecho(lua_State *L)
|
||||||
{
|
{
|
||||||
|
|
@ -100,7 +102,9 @@ static int api_echo(lua_State *L)
|
||||||
log_printf("\n[%s] %s", pTimeStampNow, str);
|
log_printf("\n[%s] %s", pTimeStampNow, str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
for (size_t i=0; i<len; i++)
|
for (size_t i=0; i<len; i++)
|
||||||
{
|
{
|
||||||
putchar(str[i]);
|
putchar(str[i]);
|
||||||
|
|
@ -237,6 +241,12 @@ static int api_send(lua_State *L)
|
||||||
tio_printf("%s", ret < 0 ? "Aborted" : "Done");
|
tio_printf("%s", ret < 0 ? "Aborted" : "Done");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case XMODEM_SUM:
|
||||||
|
tio_printf("Sending file '%s' using XMODEM-SUM", file);
|
||||||
|
ret = xymodem_send(device_fd, file, XMODEM_SUM);
|
||||||
|
tio_printf("%s", ret < 0 ? "Aborted" : "Done");
|
||||||
|
break;
|
||||||
|
|
||||||
case YMODEM:
|
case YMODEM:
|
||||||
tio_printf("Sending file '%s' using YMODEM", file);
|
tio_printf("Sending file '%s' using YMODEM", file);
|
||||||
ret = xymodem_send(device_fd, file, YMODEM);
|
ret = xymodem_send(device_fd, file, YMODEM);
|
||||||
|
|
@ -255,7 +265,8 @@ static int api_write(lua_State *L)
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
int attempts = 100;
|
int attempts = 100;
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
ret = write(device_fd, string, len);
|
ret = write(device_fd, string, len);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return luaL_error(L, "%s", strerror(errno));
|
return luaL_error(L, "%s", strerror(errno));
|
||||||
|
|
@ -319,7 +330,8 @@ static int api_read(lua_State *L)
|
||||||
}
|
}
|
||||||
|
|
||||||
// lua: string = tio.readline(timeout)
|
// lua: string = tio.readline(timeout)
|
||||||
static int api_readline(lua_State *L) {
|
static int api_readline(lua_State *L)
|
||||||
|
{
|
||||||
int timeout = lua_tointeger(L, 1); //ms
|
int timeout = lua_tointeger(L, 1); //ms
|
||||||
luaL_Buffer b;
|
luaL_Buffer b;
|
||||||
char ch;
|
char ch;
|
||||||
|
|
@ -331,7 +343,8 @@ static int api_readline(lua_State *L) {
|
||||||
|
|
||||||
luaL_buffinit(L, &b);
|
luaL_buffinit(L, &b);
|
||||||
luaL_prepbuffer(&b);
|
luaL_prepbuffer(&b);
|
||||||
while (true) {
|
while (true)
|
||||||
|
{
|
||||||
int ret = read_poll(device_fd, &ch, 1, timeout);
|
int ret = read_poll(device_fd, &ch, 1, timeout);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
|
@ -440,6 +453,7 @@ static void script_file_run(lua_State *L, const char *filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
static const struct luaL_Reg tio_lib[] =
|
static const struct luaL_Reg tio_lib[] =
|
||||||
{
|
{
|
||||||
{ "echo", api_echo},
|
{ "echo", api_echo},
|
||||||
|
|
@ -453,6 +467,7 @@ static const struct luaL_Reg tio_lib[] =
|
||||||
{ "ttysearch", api_ttysearch},
|
{ "ttysearch", api_ttysearch},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
static void script_load(lua_State *L)
|
static void script_load(lua_State *L)
|
||||||
{
|
{
|
||||||
|
|
@ -477,6 +492,7 @@ static void script_set_globals(lua_State *L)
|
||||||
script_set_global(L, "toggle", 2);
|
script_set_global(L, "toggle", 2);
|
||||||
script_set_global(L, "high", 1);
|
script_set_global(L, "high", 1);
|
||||||
script_set_global(L, "low", 0);
|
script_set_global(L, "low", 0);
|
||||||
|
script_set_global(L, "XMODEM_SUM", XMODEM_SUM);
|
||||||
script_set_global(L, "XMODEM_CRC", XMODEM_CRC);
|
script_set_global(L, "XMODEM_CRC", XMODEM_CRC);
|
||||||
script_set_global(L, "XMODEM_1K", XMODEM_1K);
|
script_set_global(L, "XMODEM_1K", XMODEM_1K);
|
||||||
script_set_global(L, "YMODEM", YMODEM);
|
script_set_global(L, "YMODEM", YMODEM);
|
||||||
|
|
|
||||||
74
src/tty.c
74
src/tty.c
|
|
@ -147,6 +147,7 @@ typedef enum
|
||||||
SUBCOMMAND_MAP,
|
SUBCOMMAND_MAP,
|
||||||
} sub_command_t;
|
} sub_command_t;
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
const char random_array[] =
|
const char random_array[] =
|
||||||
{
|
{
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x28, 0x20, 0x28, 0x0A, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x28, 0x20, 0x28, 0x0A, 0x20,
|
||||||
|
|
@ -160,6 +161,7 @@ const char random_array[] =
|
||||||
0x66, 0x65, 0x65, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x21, 0x0A, 0x20, 0x0A,
|
0x66, 0x65, 0x65, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x21, 0x0A, 0x20, 0x0A,
|
||||||
0x00
|
0x00
|
||||||
};
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
bool interactive_mode = true;
|
bool interactive_mode = true;
|
||||||
|
|
||||||
|
|
@ -257,13 +259,14 @@ ssize_t tty_write(int fd, const void *buffer, size_t count)
|
||||||
{
|
{
|
||||||
ssize_t retval = 0, bytes_written = 0;
|
ssize_t retval = 0, bytes_written = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
unsigned char *cbuf = (unsigned char *)buffer;
|
||||||
|
|
||||||
if (option.map_o_ltu)
|
if (option.map_o_ltu)
|
||||||
{
|
{
|
||||||
// Convert lower case to upper case
|
// Convert lower case to upper case
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
*((unsigned char*)buffer+i) = toupper(*((unsigned char*)buffer+i));
|
cbuf[i] = toupper(cbuf[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -272,7 +275,7 @@ ssize_t tty_write(int fd, const void *buffer, size_t count)
|
||||||
// Write byte by byte with output delay
|
// Write byte by byte with output delay
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
retval = write(fd, buffer, 1);
|
retval = write(fd, &cbuf[i], 1);
|
||||||
if (retval < 0)
|
if (retval < 0)
|
||||||
{
|
{
|
||||||
// Error
|
// Error
|
||||||
|
|
@ -281,15 +284,14 @@ ssize_t tty_write(int fd, const void *buffer, size_t count)
|
||||||
}
|
}
|
||||||
bytes_written += retval;
|
bytes_written += retval;
|
||||||
|
|
||||||
if (option.output_line_delay && *(unsigned char*)buffer == '\n')
|
|
||||||
{
|
|
||||||
delay(option.output_line_delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
fsync(fd);
|
fsync(fd);
|
||||||
tcdrain(fd);
|
tcdrain(fd);
|
||||||
|
|
||||||
if (option.output_delay)
|
if (option.output_line_delay && cbuf[i] == '\n')
|
||||||
|
{
|
||||||
|
delay(option.output_line_delay);
|
||||||
|
}
|
||||||
|
else if (option.output_delay)
|
||||||
{
|
{
|
||||||
delay(option.output_delay);
|
delay(option.output_delay);
|
||||||
}
|
}
|
||||||
|
|
@ -331,7 +333,7 @@ void *tty_stdin_input_thread(void *arg)
|
||||||
pthread_mutex_unlock(&mutex_input_ready);
|
pthread_mutex_unlock(&mutex_input_ready);
|
||||||
|
|
||||||
// Input loop for stdin
|
// Input loop for stdin
|
||||||
while (1)
|
while (true)
|
||||||
{
|
{
|
||||||
/* Input from stdin ready */
|
/* Input from stdin ready */
|
||||||
byte_count = read(STDIN_FILENO, input_buffer, BUFSIZ);
|
byte_count = read(STDIN_FILENO, input_buffer, BUFSIZ);
|
||||||
|
|
@ -360,7 +362,8 @@ void *tty_stdin_input_thread(void *arg)
|
||||||
for (int i = 0; i<byte_count; i++)
|
for (int i = 0; i<byte_count; i++)
|
||||||
{
|
{
|
||||||
// first do key hit check for xmodem abort
|
// first do key hit check for xmodem abort
|
||||||
if (!key_hit) {
|
if (!key_hit)
|
||||||
|
{
|
||||||
key_hit = input_buffer[i];
|
key_hit = input_buffer[i];
|
||||||
byte_count--;
|
byte_count--;
|
||||||
memcpy(input_buffer+i, input_buffer+i+1, byte_count-i);
|
memcpy(input_buffer+i, input_buffer+i+1, byte_count-i);
|
||||||
|
|
@ -383,7 +386,7 @@ void *tty_stdin_input_thread(void *arg)
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
break;
|
break;
|
||||||
case KEY_SHIFT_F:
|
case KEY_SHIFT_F:
|
||||||
tio_printf("Flushed data I/O buffers")
|
tio_printf("Flushed data I/O buffers");
|
||||||
tcflush(device_fd, TCIOFLUSH);
|
tcflush(device_fd, TCIOFLUSH);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -414,7 +417,8 @@ void tty_input_thread_create(void)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&mutex_input_ready);
|
pthread_mutex_lock(&mutex_input_ready);
|
||||||
|
|
||||||
if (pthread_create(&thread, NULL, tty_stdin_input_thread, NULL) != 0) {
|
if (pthread_create(&thread, NULL, tty_stdin_input_thread, NULL) != 0)
|
||||||
|
{
|
||||||
tio_error_printf("pthread_create() error");
|
tio_error_printf("pthread_create() error");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
@ -631,6 +635,7 @@ void tty_output_mode_set(output_mode_t mode)
|
||||||
|
|
||||||
static void mappings_print(void)
|
static void mappings_print(void)
|
||||||
{
|
{
|
||||||
|
// clang-format off
|
||||||
if (option.map_i_cr_nl || option.map_ign_cr || option.map_i_ff_escc ||
|
if (option.map_i_cr_nl || option.map_ign_cr || option.map_i_ff_escc ||
|
||||||
option.map_i_nl_cr || option.map_i_nl_crnl || option.map_i_cr_crnl ||
|
option.map_i_nl_cr || option.map_i_nl_crnl || option.map_i_cr_crnl ||
|
||||||
option.map_o_cr_nl || option.map_o_del_bs || option.map_o_nl_crnl ||
|
option.map_o_cr_nl || option.map_o_del_bs || option.map_o_nl_crnl ||
|
||||||
|
|
@ -656,6 +661,7 @@ static void mappings_print(void)
|
||||||
{
|
{
|
||||||
tio_printf(" Mappings: none");
|
tio_printf(" Mappings: none");
|
||||||
}
|
}
|
||||||
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_command_sequence(char input_char, char *output_char, bool *forward)
|
void handle_command_sequence(char input_char, char *output_char, bool *forward)
|
||||||
|
|
@ -756,7 +762,35 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward)
|
||||||
|
|
||||||
tio_printf("Ready to receiving file '%s' ", line);
|
tio_printf("Ready to receiving file '%s' ", line);
|
||||||
tio_printf("Press any key to abort transfer");
|
tio_printf("Press any key to abort transfer");
|
||||||
ret = xymodem_send(device_fd, line, XMODEM_CRC);
|
ret = xymodem_receive(device_fd, line, XMODEM_CRC);
|
||||||
|
tio_printf("%s", ret < 0 ? "Aborted" : "Done");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_3:
|
||||||
|
tio_printf("Send file with XMODEM-SUM");
|
||||||
|
tio_printf_raw("Enter file name: ");
|
||||||
|
if (tio_readln())
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
tio_printf("Sending file '%s' ", line);
|
||||||
|
tio_printf("Press any key to abort transfer");
|
||||||
|
ret = xymodem_send(device_fd, line, XMODEM_SUM);
|
||||||
|
tio_printf("%s", ret < 0 ? "Aborted" : "Done");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_4:
|
||||||
|
tio_printf("Receive file with XMODEM-SUM");
|
||||||
|
tio_printf_raw("Enter file name: ");
|
||||||
|
if (tio_readln())
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
tio_printf("Ready to receiving file '%s' ", line);
|
||||||
|
tio_printf("Press any key to abort transfer");
|
||||||
|
ret = xymodem_receive(device_fd, line, XMODEM_SUM);
|
||||||
tio_printf("%s", ret < 0 ? "Aborted" : "Done");
|
tio_printf("%s", ret < 0 ? "Aborted" : "Done");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -1011,6 +1045,7 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_M:
|
case KEY_M:
|
||||||
|
// clang-format off
|
||||||
/* Change mapping of characters on input or output */
|
/* Change mapping of characters on input or output */
|
||||||
tio_printf("Please enter which mapping to set or unset:");
|
tio_printf("Please enter which mapping to set or unset:");
|
||||||
tio_printf(" (0) ICRNL: %s mapping CR to NL on input (unless IGNCR is set)",
|
tio_printf(" (0) ICRNL: %s mapping CR to NL on input (unless IGNCR is set)",
|
||||||
|
|
@ -1039,6 +1074,7 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward)
|
||||||
option.map_o_nulbrk ? "Unset" : "Set");
|
option.map_o_nulbrk ? "Unset" : "Set");
|
||||||
tio_printf(" (c) OIGNCR: %s ignoring CR on output",
|
tio_printf(" (c) OIGNCR: %s ignoring CR on output",
|
||||||
option.map_o_ign_cr ? "Unset" : "Set");
|
option.map_o_ign_cr ? "Unset" : "Set");
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
// Process next input character as sub command
|
// Process next input character as sub command
|
||||||
sub_command = SUBCOMMAND_MAP;
|
sub_command = SUBCOMMAND_MAP;
|
||||||
|
|
@ -1050,7 +1086,7 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward)
|
||||||
|
|
||||||
case KEY_R:
|
case KEY_R:
|
||||||
/* Run script */
|
/* Run script */
|
||||||
tio_printf("Run Lua script")
|
tio_printf("Run Lua script");
|
||||||
tio_printf_raw("Enter file name: ");
|
tio_printf_raw("Enter file name: ");
|
||||||
if (tio_readln())
|
if (tio_readln())
|
||||||
{
|
{
|
||||||
|
|
@ -1119,6 +1155,8 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward)
|
||||||
tio_printf(" (0) XMODEM-1K send");
|
tio_printf(" (0) XMODEM-1K send");
|
||||||
tio_printf(" (1) XMODEM-CRC send");
|
tio_printf(" (1) XMODEM-CRC send");
|
||||||
tio_printf(" (2) XMODEM-CRC receive");
|
tio_printf(" (2) XMODEM-CRC receive");
|
||||||
|
tio_printf(" (3) XMODEM-SUM send");
|
||||||
|
tio_printf(" (4) XMODEM-SUM receive");
|
||||||
// Process next input character as sub command
|
// Process next input character as sub command
|
||||||
sub_command = SUBCOMMAND_XMODEM;
|
sub_command = SUBCOMMAND_XMODEM;
|
||||||
break;
|
break;
|
||||||
|
|
@ -1126,7 +1164,8 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward)
|
||||||
case KEY_Y:
|
case KEY_Y:
|
||||||
tio_printf("Send file with YMODEM");
|
tio_printf("Send file with YMODEM");
|
||||||
tio_printf_raw("Enter file name: ");
|
tio_printf_raw("Enter file name: ");
|
||||||
if (tio_readln()) {
|
if (tio_readln())
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
tio_printf("Sending file '%s' ", line);
|
tio_printf("Sending file '%s' ", line);
|
||||||
|
|
@ -2044,7 +2083,8 @@ GList *tty_search_for_serial_devices(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Populate device info */
|
/* Populate device info */
|
||||||
*device_info = (device_t) {
|
*device_info = (device_t)
|
||||||
|
{
|
||||||
.path = devicePath,
|
.path = devicePath,
|
||||||
.tid = g_strdup(tid),
|
.tid = g_strdup(tid),
|
||||||
.uptime = uptime,
|
.uptime = uptime,
|
||||||
|
|
@ -2361,7 +2401,7 @@ void tty_wait_for_device(void)
|
||||||
// Happens when port unpluged
|
// Happens when port unpluged
|
||||||
if (errno == EACCES)
|
if (errno == EACCES)
|
||||||
{
|
{
|
||||||
goto error;
|
break;
|
||||||
}
|
}
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
if (errno == EBADF)
|
if (errno == EBADF)
|
||||||
|
|
|
||||||
1055
src/xymodem.c
1055
src/xymodem.c
File diff suppressed because it is too large
Load diff
|
|
@ -21,14 +21,15 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
XMODEM_1K,
|
XMODEM_1K,
|
||||||
XMODEM_CRC,
|
XMODEM_CRC,
|
||||||
|
XMODEM_SUM,
|
||||||
YMODEM,
|
YMODEM,
|
||||||
} modem_mode_t;
|
} modem_mode_t;
|
||||||
|
|
||||||
extern char key_hit;
|
extern char key_hit;
|
||||||
|
|
||||||
int xymodem_send(int sio, const char *filename, modem_mode_t mode);
|
int xymodem_send(int sio, const char *filename, modem_mode_t mode);
|
||||||
|
|
||||||
int xymodem_receive(int sio, const char *filename, modem_mode_t mode);
|
int xymodem_receive(int sio, const char *filename, modem_mode_t mode);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue