2018-12-13 02:06:18 +11:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2018-12-20 21:57:23 +11:00
|
|
|
#include <stdlib.h>
|
2018-12-29 19:45:22 +11:00
|
|
|
#include <strings.h>
|
|
|
|
#include <ctype.h>
|
2018-12-13 08:26:54 +11:00
|
|
|
#include <time.h>
|
2018-12-22 03:53:17 +11:00
|
|
|
#include <unistd.h> //Used for UART
|
|
|
|
#include <fcntl.h> //Used for UART
|
|
|
|
#include <errno.h>
|
2018-12-29 19:45:22 +11:00
|
|
|
#include <termios.h> //Used for UART
|
2018-12-13 02:06:18 +11:00
|
|
|
|
|
|
|
#include "serial.h"
|
|
|
|
|
2018-12-20 21:57:23 +11:00
|
|
|
int verbosity;
|
|
|
|
|
2018-12-22 03:53:17 +11: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 12:43:12 +11:00
|
|
|
exit(1);
|
2018-12-22 03:53:17 +11:00
|
|
|
}
|
|
|
|
return uart;
|
|
|
|
}
|
|
|
|
/* ----------------------------------------------------- */
|
2018-12-29 19:45:22 +11:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
/* ----------------------------------------------------- */
|
2018-12-13 02:06:18 +11:00
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
2018-12-22 03:53:17 +11:00
|
|
|
int serial_in, foo;
|
|
|
|
unsigned char byte;
|
2018-12-13 02:06:18 +11:00
|
|
|
|
2018-12-22 03:53:17 +11:00
|
|
|
if (2 != argc) {
|
2018-12-29 12:43:12 +11:00
|
|
|
fprintf(stderr, "give me a device name, please.\n");
|
2018-12-22 03:53:17 +11:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
serial_in = openserial(argv[1]);
|
2018-12-29 12:43:12 +11:00
|
|
|
fprintf(stderr, "openserial -> %d\n", serial_in);
|
2018-12-20 21:57:23 +11:00
|
|
|
|
2018-12-29 19:45:22 +11:00
|
|
|
(void)configserial(serial_in);
|
|
|
|
|
|
|
|
|
2018-12-20 21:57:23 +11:00
|
|
|
for (;;) {
|
2018-12-22 03:53:17 +11:00
|
|
|
foo = read(serial_in, &byte, 1);
|
|
|
|
if (1 != foo) {
|
2018-12-29 19:45:22 +11:00
|
|
|
fprintf(stderr, "get byte : got %d, err is %d\n",
|
|
|
|
foo, errno);
|
2018-12-13 06:07:49 +11:00
|
|
|
}
|
2018-12-20 21:57:23 +11:00
|
|
|
else {
|
2018-12-29 12:43:12 +11:00
|
|
|
printf("%9ld $%02x ", time(NULL), byte);
|
2018-12-29 19:45:22 +11:00
|
|
|
if (isprint(byte)) putchar(byte);
|
2018-12-29 12:43:12 +11:00
|
|
|
puts("");
|
2018-12-29 19:45:22 +11:00
|
|
|
if ('\n'==byte) puts("");
|
2018-12-20 21:57:23 +11:00
|
|
|
}
|
2018-12-13 02:06:18 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-12-22 03:53:17 +11:00
|
|
|
|
|
|
|
/* ----------------------------------------------------- */
|