DD2-monitor/serial/t.c

59 lines
1.1 KiB
C
Raw Normal View History

2018-12-12 16:06:18 +01:00
#include <stdio.h>
2018-12-20 11:57:23 +01:00
#include <stdlib.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-12 16:06:18 +01:00
#include "serial.h"
2018-12-20 11:57:23 +01:00
int verbosity;
2018-12-21 17:53:17 +01:00
/* ----------------------------------------------------- */
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");
2018-12-29 02:43:12 +01:00
exit(1);
2018-12-21 17:53:17 +01:00
}
return uart;
}
/* ----------------------------------------------------- */
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;
unsigned char byte;
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;
}
serial_in = openserial(argv[1]);
2018-12-29 02:43:12 +01:00
fprintf(stderr, "openserial -> %d\n", serial_in);
2018-12-20 11:57:23 +01:00
for (;;) {
2018-12-21 17:53:17 +01:00
foo = read(serial_in, &byte, 1);
if (1 != foo) {
2018-12-29 02:43:12 +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 02:43:12 +01:00
printf("%9ld $%02x ", time(NULL), byte);
if (isprint(byte)) putchar(byte);
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
/* ----------------------------------------------------- */