select in 'get_byte_to' don't work

This commit is contained in:
2018-12-29 12:09:34 +01:00
parent 4eed817ecb
commit 560edb14e8
2 changed files with 22 additions and 43 deletions

View File

@@ -1,4 +1,7 @@
/*
* Experiments with the serial input
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
#include <stdio.h>
#include <stdlib.h>
@@ -14,63 +17,35 @@
int verbosity;
/* ----------------------------------------------------- */
int openserial(char *dev)
{
int uart;
fprintf(stderr, "%s ( %s )\n", __func__, dev);
uart = open(dev, O_RDONLY | O_NOCTTY);
if (uart < 0)
{
perror("unable to open uart");
exit(1);
}
return uart;
}
/* ----------------------------------------------------- */
int configserial(int fd)
{
struct termios tios;
bzero(&tios, sizeof(tios));
tios.c_cflag = B9600 | CRTSCTS | CS8 | CLOCAL | CREAD;
tios.c_lflag = ICANON;
tios.c_cc[VMIN] = 1; /* read bloquant ??? */
tcsetattr(fd,TCSANOW,&tios);
return 0;
}
/* ----------------------------------------------------- */
/* ---------------------------------------------------------------- */
int main (int argc, char *argv[])
{
int serial_in, foo;
unsigned char byte;
if (2 != argc) {
fprintf(stderr, "give me a device name, please.\n");
return 2;
}
serial_in = openserial(argv[1]);
fprintf(stderr, "openserial -> %d\n", serial_in);
(void)configserial(serial_in);
serial_in = prepare_UART(argv[1], 9600);
fprintf(stderr, "going to listen on %d\n", serial_in);
for (;;) {
foo = read(serial_in, &byte, 1);
if (1 != foo) {
foo = getbyte_to(serial_in, 50000);
if (foo < 0) {
fprintf(stderr, "get byte : got %d, err is %d\n",
foo, errno);
}
else {
printf("%9ld $%02x ", time(NULL), byte);
if (isprint(byte)) putchar(byte);
printf("%9ld $%02x ", time(NULL), foo);
if (isprint(foo)) putchar(foo);
puts("");
if ('\n'==byte) puts("");
if ('\n'==foo) puts("");
}
}
return 0;
}
/* ----------------------------------------------------- */
/* ---------------------------------------------------------------- */