mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Add list serial devices feature
For convenience, add a --list-devices option which lists the available serial devices.
This commit is contained in:
parent
6310f28d2c
commit
7a2a18232d
8 changed files with 55 additions and 2 deletions
21
src/tty.c
21
src/tty.c
|
|
@ -36,6 +36,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include <dirent.h>
|
||||
#include "config.h"
|
||||
#include "tio/tty.h"
|
||||
#include "tio/print.h"
|
||||
|
|
@ -48,6 +49,8 @@
|
|||
extern int setspeed2(int fd, int baudrate);
|
||||
#endif
|
||||
|
||||
#define PATH_SERIAL_DEVICES "/dev/serial/by-id/"
|
||||
|
||||
static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old;
|
||||
static unsigned long rx_total = 0, tx_total = 0;
|
||||
static bool connected = false;
|
||||
|
|
@ -841,3 +844,21 @@ error_read:
|
|||
error_open:
|
||||
return TIO_ERROR;
|
||||
}
|
||||
|
||||
void list_serial_devices(void)
|
||||
{
|
||||
DIR *d;
|
||||
struct dirent *dir;
|
||||
d = opendir(PATH_SERIAL_DEVICES);
|
||||
|
||||
if (d)
|
||||
{
|
||||
while ((dir = readdir(d)) != NULL)
|
||||
{
|
||||
if ((strcmp(dir->d_name, ".")) && (strcmp(dir->d_name, "..")))
|
||||
printf("%s%s\n", PATH_SERIAL_DEVICES, dir->d_name);
|
||||
}
|
||||
|
||||
closedir(d);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue