serial over USB is evil, really evil

This commit is contained in:
tth 2018-12-21 17:53:17 +01:00
parent 0c6f849310
commit 73348c2339
2 changed files with 34 additions and 11 deletions

View File

@ -3,17 +3,41 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h> //Used for UART
#include <fcntl.h> //Used for UART
#include <errno.h>
#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;
}
/* ----------------------------------------------------- */

View File

@ -48,7 +48,7 @@ void sendvalues(void)
void loop() {
updatevalues();
sendvalues();
delay(5000);
delay(1000);
}
/* -------------------------------------------------- */