Skip to content
Snippets Groups Projects
Commit ded6ee7b authored by fortissBot's avatar fortissBot
Browse files

Verzögerung des LRF durch Löschen des Buffers vermeiden, Automatische...

Verzögerung des LRF durch Löschen des Buffers vermeiden, Automatische Erkennung des Ports (Issue #7910)
refs 7909
parent b517780a
No related branches found
No related tags found
No related merge requests found
......@@ -30,4 +30,6 @@ int uart_receive(char*, int, int);
void uart_close();
void uart_flush();
#endif
#include "inc/LaserRangeFinder.h"
// constants
const char* LRF_DEVICE_NAME = "/dev/ttyACM0";
// init, terminate
void lrf_init() {
uart_setup(LRF_DEVICE_NAME);
char port[] = "/dev/????????";
FILE* fp = popen("dmesg | grep -A 3 \"Arduino Uno\" | grep -o \"ttyACM.\" | tail -n 1","r");
fgets(port+5, sizeof(port)-6, fp);
printf("Port: %s\n", port);
pclose(fp);
uart_setup(port);
}
void lrf_term() {
......@@ -27,6 +31,11 @@ GEN_TYPE_int lrf_read() {
int i;
int d;
// free buffer
uart_flush();
// looks like a blocking call and actually is but is always very fast
// since it only has to read the queue
while (1) {
......@@ -36,10 +45,11 @@ GEN_TYPE_int lrf_read() {
if (bytes[i] != 0xd && bytes[i] != 0xa) {
value[n++] = bytes[i];
} else if (atoi(value) != 0) {
d = atoi(value);
for (i = n; i < 3; i++) {
value[i] = 0;
}
return atoi(value);
return d;
}
}
}
......
......@@ -36,7 +36,9 @@ int uart_setup(const char *porta) {
tty.c_cflag |= CREAD | CLOCAL;
cfmakeraw(&tty);
tcflush(uart_filestream, TCIFLUSH);
uart_flush();
if (tcsetattr(uart_filestream, TCSANOW, &tty) != 0) {
fprintf(stderr, "[%s] Error from tcsetattr: %s\n", port, strerror(errno));
}
......@@ -123,3 +125,7 @@ int uart_receive(char *c, int bufLen, int printt) {
void uart_close() {
close(uart_filestream);
}
void uart_flush() {
tcflush(uart_filestream, TCIFLUSH);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment