Add list serial devices feature

For convenience, add a --list-devices option which lists the available
serial devices.
This commit is contained in:
Martin Lund 2022-02-08 22:44:48 +01:00
parent 6310f28d2c
commit 7a2a18232d
8 changed files with 55 additions and 2 deletions

View file

@ -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);
}
}