DD2-monitor/serial/t.c

52 lines
1.0 KiB
C

/*
* Experiments with the serial input
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h> //Used for UART
#include <fcntl.h> //Used for UART
#include <errno.h>
#include <termios.h> //Used for UART
#include "serial.h"
int verbosity;
/* ---------------------------------------------------------------- */
int main (int argc, char *argv[])
{
int serial_in, foo;
if (2 != argc) {
fprintf(stderr, "give me a device name, please.\n");
return 2;
}
serial_in = prepare_UART(argv[1], 9600);
fprintf(stderr, "going to listen on %d\n", serial_in);
for (;;) {
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), foo);
if (isprint(foo)) putchar(foo);
puts("");
if ('\n'==foo) puts("");
}
}
return 0;
}
/* ---------------------------------------------------------------- */