Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

microcom: allow for specifying the escape character #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions microcom.1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ microcom \- A minimalistic terminal program
.IR host : port ]
.RB [\| \-s
.IR speed \|]
.RB [\| \-e
.IR escape-char \|]
.br
.B microcom -c
.IB interface : rx_id : tx_id
Expand Down Expand Up @@ -65,6 +67,9 @@ work in telnet (rfc2217) mode.
.BI \-c\ interface\fB:\fIrx_id\fB:\fItx_id\fR,\ \fI \-\-can= interface\fB:\fIrx_id\fB:\fItx_id
work in CAN mode (default: \fBcan0:200:200\fR)
.TP
.BI \-e\ escape-character \fR,\ \fB\-\-escape-char= char
use specified escape charater with Ctrl (default \fB\\\fR).
.TP
.BR -h ", " \-\-help
Show help.

Expand Down
18 changes: 14 additions & 4 deletions microcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ void main_usage(int exitcode, char *str, char *dev)
" -l, --logfile=<logfile> log output to <logfile>\n"
" -o, --listenonly Do not modify local terminal, do not send input\n"
" from stdin\n"
" -a, --answerback=<str> specify the answerback string sent as response to\n"
" -a, --answerback=<str> specify the answerback string sent as response to\n"
" an ENQ (ASCII 0x05) Character\n"
" -e, --escape-char=<chr> escape charater to use with Ctrl (%c)\n"
" -v, --version print version string\n"
" -h, --help This help\n",
DEFAULT_DEVICE, DEFAULT_BAUDRATE,
DEFAULT_CAN_INTERFACE, DEFAULT_CAN_ID, DEFAULT_CAN_ID);
DEFAULT_CAN_INTERFACE, DEFAULT_CAN_ID, DEFAULT_CAN_ID,
DEFAULT_ESCAPE_CHAR);
fprintf(stderr, "Exitcode %d - %s %s\n\n", exitcode, str, dev);
exit(exitcode);
}
Expand All @@ -113,6 +115,7 @@ int opt_force = 0;
unsigned long current_speed = DEFAULT_BAUDRATE;
int current_flow = FLOW_NONE;
int listenonly = 0;
char escape_char = DEFAULT_ESCAPE_CHAR;

int main(int argc, char *argv[])
{
Expand All @@ -139,7 +142,7 @@ int main(int argc, char *argv[])
{ },
};

while ((opt = getopt_long(argc, argv, "hp:s:t:c:dfl:oi:a:v", long_options, NULL)) != -1) {
while ((opt = getopt_long(argc, argv, "hp:s:t:c:dfl:oi:a:e:v", long_options, NULL)) != -1) {
switch (opt) {
case '?':
main_usage(1, "", "");
Expand Down Expand Up @@ -180,6 +183,13 @@ int main(int argc, char *argv[])
case 'a':
answerback = optarg;
break;
case 'e':
if (strlen(optarg) != 1) {
fprintf(stderr, "Option -e requires a single character argument.\n");
exit(EXIT_FAILURE);
}
escape_char = *optarg;
break;
}
}

Expand Down Expand Up @@ -224,7 +234,7 @@ int main(int argc, char *argv[])
ios->set_flow(ios, current_flow);

if (!listenonly) {
printf("Escape character: Ctrl-\\\n");
printf("Escape character: Ctrl-%c\n", escape_char);
printf("Type the escape character to get to the prompt.\n");

/* Now deal with the local terminal side */
Expand Down
2 changes: 2 additions & 0 deletions microcom.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#define DEFAULT_DEVICE "/dev/ttyS0"
#define DEFAULT_CAN_INTERFACE "can0"
#define DEFAULT_CAN_ID (0x200)
#define DEFAULT_ESCAPE_CHAR ('\\')

struct ios_ops {
ssize_t (*write)(struct ios_ops *, const void *buf, size_t count);
Expand Down Expand Up @@ -73,6 +74,7 @@ extern int debug;
extern int opt_force;
extern int listenonly;
extern char *answerback;
extern char escape_char;

struct cmd {
char *name;
Expand Down
2 changes: 1 addition & 1 deletion mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static void cook_buf(struct ios_ops *ios, unsigned char *buf, int num)
while (current < num) { /* big while loop, to process all the charactes in buffer */

/* look for the next escape character (Ctrl-\) */
while ((current < num) && (buf[current] != 28))
while ((current < num) && (buf[current] != CTRL(escape_char)))
current++;
/* and write the sequence before esc char to the comm port */
if (current)
Expand Down