#include "misc.h"
#include "print.h"
#include "tty.h"
+#include "rs485.h"
+#include "timestamp.h"
+#include "alert.h"
enum opt_t
{
OPT_LOG_FILE,
OPT_LOG_STRIP,
OPT_LINE_PULSE_DURATION,
+ OPT_RESPONSE_TIMEOUT,
+ OPT_RS485,
+ OPT_RS485_CONFIG,
+ OPT_ALERT,
};
/* Default options */
.hex_mode = false,
.prefix_code = 20, // ctrl-t
.prefix_key = 't',
+ .response_wait = false,
+ .response_timeout = 100,
+ .mute = false,
+ .rs485 = false,
+ .rs485_config_flags = 0,
+ .rs485_delay_rts_before_send = -1,
+ .rs485_delay_rts_after_send = -1,
+ .alert = ALERT_NONE,
};
void print_help(char *argv[])
printf(" -e, --local-echo Enable local echo\n");
printf(" -t, --timestamp Enable line timestamp\n");
printf(" --timestamp-format <format> Set timestamp format (default: 24hour)\n");
- printf(" -L, --list-devices List available serial devices\n");
+ 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-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");
- printf(" -S, --socket <socket> Redirect I/O to file or network socket\n");
+ printf(" -S, --socket <socket> Redirect I/O to socket\n");
printf(" -x, --hexadecimal Enable hexadecimal mode\n");
+ printf(" -r, --response-wait Wait for line response then quit\n");
+ printf(" --response-timeout <ms> Response timeout (default: 100)\n");
+ printf(" --rs-485 Enable RS-485 mode\n");
+ printf(" --rs-485-config <config> Set RS-485 configuration\n");
+ printf(" --alert bell|blink|none Alert on connect/disconnect (default: none)\n");
printf(" -v, --version Display version\n");
printf(" -h, --help Display help\n");
printf("\n");
printf("See the man page for more details.\n");
}
-const char* timestamp_state_to_string(enum timestamp_t timestamp)
-{
- switch (timestamp)
- {
- case TIMESTAMP_NONE:
- return "disabled";
- break;
-
- case TIMESTAMP_24HOUR:
- return "24hour";
- break;
-
- case TIMESTAMP_24HOUR_START:
- return "24hour-start";
- break;
-
- case TIMESTAMP_24HOUR_DELTA:
- return "24hour-delta";
- break;
-
- case TIMESTAMP_ISO8601:
- return "iso8601";
- break;
-
- default:
- return "unknown";
- break;
- }
-}
-
-enum timestamp_t timestamp_option_parse(const char *arg)
-{
- enum timestamp_t timestamp = TIMESTAMP_24HOUR; // Default
-
- if (arg != NULL)
- {
- if (strcmp(arg, "24hour") == 0)
- {
- return TIMESTAMP_24HOUR;
- }
- else if (strcmp(arg, "24hour-start") == 0)
- {
- return TIMESTAMP_24HOUR_START;
- }
- else if (strcmp(arg, "24hour-delta") == 0)
- {
- return TIMESTAMP_24HOUR_DELTA;
- }
- else if (strcmp(arg, "iso8601") == 0)
- {
- return TIMESTAMP_ISO8601;
- }
- }
-
- return timestamp;
-}
-
void line_pulse_duration_option_parse(const char *arg)
{
bool token_found = true;
if (token != NULL)
{
- char keyname[10];
+ char keyname[11];
unsigned int value;
sscanf(token, "%10[^=]=%d", keyname, &value);
}
}
free(buffer);
-
}
void options_print()
tio_printf(" Timestamp: %s", timestamp_state_to_string(option.timestamp));
tio_printf(" Output delay: %d", option.output_delay);
tio_printf(" Output line delay: %d", option.output_line_delay);
- tio_printf(" DTR pulse duration: %d", option.dtr_pulse_duration);
tio_printf(" Auto connect: %s", option.no_autoconnect ? "disabled" : "enabled");
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.dsr_pulse_duration,
option.dcd_pulse_duration,
option.ri_pulse_duration);
+ tio_printf(" Hexadecimal mode: %s", option.hex_mode ? "enabled" : "disabled");
if (option.map[0] != 0)
tio_printf(" Map flags: %s", option.map);
if (option.log)
{"map", required_argument, 0, 'm' },
{"color", required_argument, 0, 'c' },
{"hexadecimal", no_argument, 0, 'x' },
+ {"response-wait", no_argument, 0, 'r' },
+ {"response-timeout", required_argument, 0, OPT_RESPONSE_TIMEOUT },
+ {"rs-485", no_argument, 0, OPT_RS485 },
+ {"rs-485-config", required_argument, 0, OPT_RS485_CONFIG },
+ {"alert", required_argument, 0, OPT_ALERT },
{"version", no_argument, 0, 'v' },
{"help", no_argument, 0, 'h' },
{0, 0, 0, 0 }
int option_index = 0;
/* Parse argument using getopt_long */
- c = getopt_long(argc, argv, "b:d:f:s:p:o:O:netLlS:m:c:xvh", long_options, &option_index);
+ c = getopt_long(argc, argv, "b:d:f:s:p:o:O:netLlS:m:c:xrvh", long_options, &option_index);
/* Detect the end of the options */
if (c == -1)
break;
case OPT_LOG_FILE:
- option.log = true;
option.log_filename = optarg;
break;
option.hex_mode = true;
break;
+ case 'r':
+ option.response_wait = true;
+ break;
+
+ case OPT_RESPONSE_TIMEOUT:
+ option.response_timeout = string_to_long(optarg);
+ break;
+
+ case OPT_RS485:
+ option.rs485 = true;
+ break;
+
+ case OPT_RS485_CONFIG:
+ rs485_parse_config(optarg);
+ break;
+
+ case OPT_ALERT:
+ option.alert = alert_option_parse(optarg);
+ break;
+
case 'v':
printf("tio v%s\n", VERSION);
- printf("Copyright (c) 2014-2022 Martin Lund\n");
- printf("\n");
- printf("License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>.\n");
- printf("This is free software: you are free to change and redistribute it.\n");
- printf("There is NO WARRANTY, to the extent permitted by law.\n");
exit(EXIT_SUCCESS);
break;