diff --git a/serial/t.c b/serial/t.c index 4fed028..cd95b9e 100644 --- a/serial/t.c +++ b/serial/t.c @@ -3,17 +3,41 @@ #include #include #include +#include //Used for UART +#include //Used for UART +#include #include "serial.h" 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"); + return -1; + } +return uart; +} +/* ----------------------------------------------------- */ + int main (int argc, char *argv[]) { -int serial_in; -int byte; +int serial_in, foo; +unsigned char byte; -serial_in = prepare_UART("/dev/ttyACM0", 9600); +if (2 != argc) { + fprintf(stderr, "device name ?\n"); + return 2; + } + +serial_in = openserial(argv[1]); fprintf(stderr, "prepare uart -> %d\n", serial_in); if (serial_in < 0) { @@ -21,17 +45,16 @@ if (serial_in < 0) { } for (;;) { - - byte = getbyte(serial_in); - - if (byte < 0) { - fprintf(stderr, "get byte : err is %d\n", byte); + foo = read(serial_in, &byte, 1); + if (1 != foo) { + fprintf(stderr, "get byte : err is %d\n", errno); } else { - printf("%9ld %02x/%d\n", - time(NULL), byte, byte); + printf("%9ld %02x/%d\n", time(NULL), byte, byte); } } return 0; } + +/* ----------------------------------------------------- */ diff --git a/simulator/send-random/send-random.ino b/simulator/send-random/send-random.ino index 16cd63f..70f8bb0 100644 --- a/simulator/send-random/send-random.ino +++ b/simulator/send-random/send-random.ino @@ -48,7 +48,7 @@ void sendvalues(void) void loop() { updatevalues(); sendvalues(); - delay(5000); + delay(1000); } /* -------------------------------------------------- */