DD2-monitor/serial/t.c

52 lines
1.0 KiB
C
Raw Normal View History

2018-12-29 12:09:34 +01:00
/*
* Experiments with the serial input
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
2018-12-12 16:06:18 +01:00
#include <stdio.h>
2018-12-20 11:57:23 +01:00
#include <stdlib.h>
2018-12-29 09:45:22 +01:00
#include <strings.h>
#include <ctype.h>
2018-12-12 22:26:54 +01:00
#include <time.h>
2018-12-21 17:53:17 +01:00
#include <unistd.h> //Used for UART
#include <fcntl.h> //Used for UART
#include <errno.h>
2018-12-29 09:45:22 +01:00
#include <termios.h> //Used for UART
2018-12-12 16:06:18 +01:00
#include "serial.h"
2018-12-20 11:57:23 +01:00
int verbosity;
2018-12-29 12:09:34 +01:00
/* ---------------------------------------------------------------- */
2018-12-12 16:06:18 +01:00
int main (int argc, char *argv[])
{
2018-12-21 17:53:17 +01:00
int serial_in, foo;
2018-12-12 16:06:18 +01:00
2018-12-21 17:53:17 +01:00
if (2 != argc) {
2018-12-29 02:43:12 +01:00
fprintf(stderr, "give me a device name, please.\n");
2018-12-21 17:53:17 +01:00
return 2;
}
2018-12-29 12:09:34 +01:00
serial_in = prepare_UART(argv[1], 9600);
2018-12-29 09:45:22 +01:00
2018-12-29 12:09:34 +01:00
fprintf(stderr, "going to listen on %d\n", serial_in);
2018-12-29 09:45:22 +01:00
2018-12-20 11:57:23 +01:00
for (;;) {
2018-12-29 12:09:34 +01:00
foo = getbyte_to(serial_in, 50000);
if (foo < 0) {
2018-12-29 09:45:22 +01:00
fprintf(stderr, "get byte : got %d, err is %d\n",
foo, errno);
2018-12-12 20:07:49 +01:00
}
2018-12-20 11:57:23 +01:00
else {
2018-12-29 12:09:34 +01:00
printf("%9ld $%02x ", time(NULL), foo);
if (isprint(foo)) putchar(foo);
2018-12-29 02:43:12 +01:00
puts("");
2018-12-29 12:09:34 +01:00
if ('\n'==foo) puts("");
2018-12-20 11:57:23 +01:00
}
2018-12-12 16:06:18 +01:00
}
return 0;
}
2018-12-21 17:53:17 +01:00
2018-12-29 12:09:34 +01:00
/* ---------------------------------------------------------------- */