system/cu: Support the custom escape char
note: -f could be achieved with -E '' like https://linux.die.net/man/1/cu Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
b60cdf4927
commit
5f9d9bb1c2
@ -73,6 +73,7 @@ struct cu_globals_s
|
|||||||
{
|
{
|
||||||
int devfd; /* I/O data to serial port */
|
int devfd; /* I/O data to serial port */
|
||||||
int stdfd; /* I/O data to standard console */
|
int stdfd; /* I/O data to standard console */
|
||||||
|
int escape; /* Escape char */
|
||||||
struct termios devtio; /* Original serial port setting */
|
struct termios devtio; /* Original serial port setting */
|
||||||
struct termios stdtio; /* Original standard console setting */
|
struct termios stdtio; /* Original standard console setting */
|
||||||
pthread_t listener; /* Terminal listener thread */
|
pthread_t listener; /* Terminal listener thread */
|
||||||
|
@ -227,10 +227,11 @@ static void print_help(void)
|
|||||||
" -e: Set even parity\n"
|
" -e: Set even parity\n"
|
||||||
" -o: Set odd parity\n"
|
" -o: Set odd parity\n"
|
||||||
" -s: Use given speed (default %d)\n"
|
" -s: Use given speed (default %d)\n"
|
||||||
" -r: Disable RTS/CTS flow control (default: on)\n"
|
" -f: Disable RTS/CTS flow control (default: on)\n"
|
||||||
#endif
|
#endif
|
||||||
" -c: Disable lf -> crlf conversion (default: off)\n"
|
" -c: Disable lf -> crlf conversion (default: off)\n"
|
||||||
" -f: Enable endless mode without escape sequence (default: off)\n"
|
" -E: Set the escape character (default: ~).\n"
|
||||||
|
" To eliminate the escape character, use -E ''\n"
|
||||||
" -?: This help\n",
|
" -?: This help\n",
|
||||||
CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE
|
CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE
|
||||||
#ifdef CONFIG_SERIAL_TERMIOS
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
@ -239,19 +240,17 @@ static void print_help(void)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_escape_help(void)
|
static void print_escape_help(FAR struct cu_globals_s *cu)
|
||||||
{
|
{
|
||||||
printf("[Escape sequences]\n"
|
printf("[Escape sequences]\n[%c. hangup]\n", cu->escape);
|
||||||
"[~. hangup]\n"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cu_cmd(char bcmd)
|
static int cu_cmd(FAR struct cu_globals_s *cu, char bcmd)
|
||||||
{
|
{
|
||||||
switch (bcmd)
|
switch (bcmd)
|
||||||
{
|
{
|
||||||
case '?':
|
case '?':
|
||||||
print_escape_help();
|
print_escape_help(cu);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '.':
|
case '.':
|
||||||
@ -287,7 +286,6 @@ int main(int argc, FAR char *argv[])
|
|||||||
int rtscts = 1;
|
int rtscts = 1;
|
||||||
#endif
|
#endif
|
||||||
int nocrlf = 0;
|
int nocrlf = 0;
|
||||||
int nobreak = 0;
|
|
||||||
int option;
|
int option;
|
||||||
int ret;
|
int ret;
|
||||||
int bcmd;
|
int bcmd;
|
||||||
@ -298,6 +296,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
/* Initialize global data */
|
/* Initialize global data */
|
||||||
|
|
||||||
memset(cu, 0, sizeof(*cu));
|
memset(cu, 0, sizeof(*cu));
|
||||||
|
cu->escape = '~';
|
||||||
|
|
||||||
/* Install signal handlers */
|
/* Install signal handlers */
|
||||||
|
|
||||||
@ -306,7 +305,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
sigaction(SIGINT, &sa, NULL);
|
sigaction(SIGINT, &sa, NULL);
|
||||||
|
|
||||||
optind = 0; /* Global that needs to be reset in FLAT mode */
|
optind = 0; /* Global that needs to be reset in FLAT mode */
|
||||||
while ((option = getopt(argc, argv, "l:s:cefhor?")) != ERROR)
|
while ((option = getopt(argc, argv, "l:s:ceE:fho?")) != ERROR)
|
||||||
{
|
{
|
||||||
switch (option)
|
switch (option)
|
||||||
{
|
{
|
||||||
@ -327,7 +326,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
parity = PARITY_ODD;
|
parity = PARITY_ODD;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'f':
|
||||||
rtscts = 0;
|
rtscts = 0;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
@ -336,8 +335,8 @@ int main(int argc, FAR char *argv[])
|
|||||||
nocrlf = 1;
|
nocrlf = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'E':
|
||||||
nobreak = 1;
|
cu->escape = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
@ -450,13 +449,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
|
|
||||||
ch = c;
|
ch = c;
|
||||||
|
|
||||||
if (nobreak == 1)
|
if (start_of_line == 1 && ch == cu->escape)
|
||||||
{
|
|
||||||
write(cu->devfd, &ch, 1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (start_of_line == 1 && ch == '~')
|
|
||||||
{
|
{
|
||||||
/* We've seen and escape (~) character, echo it to local
|
/* We've seen and escape (~) character, echo it to local
|
||||||
* terminal and read the next char from serial
|
* terminal and read the next char from serial
|
||||||
@ -473,7 +466,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (cu_cmd(bcmd) == 1)
|
if (cu_cmd(cu, ch) == 1)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user