|
|
@@ -10,6 +10,7 @@ |
|
|
|
#include <linux/serial.h> |
|
|
|
#include "serial-util.h" |
|
|
|
#include <string.h> |
|
|
|
#include <ctype.h> |
|
|
|
|
|
|
|
int hex = 0; |
|
|
|
int dec = 0; |
|
|
@@ -20,7 +21,7 @@ int process(const uint8_t *buf, int len); |
|
|
|
|
|
|
|
int main(int argc, char *argv[]) |
|
|
|
{ |
|
|
|
char *device=strdup("/dev/ttyUSB0"); |
|
|
|
char *device=strdup("/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A6007wag-if00-port0"); |
|
|
|
int rate=500000; |
|
|
|
int fd; |
|
|
|
int getopt_index; |
|
|
@@ -33,7 +34,6 @@ int main(int argc, char *argv[]) |
|
|
|
{ "rate", required_argument, NULL, 'r' }, |
|
|
|
{ "hex", no_argument, NULL, 'x' }, |
|
|
|
{ "dec", no_argument, NULL, 'D' }, |
|
|
|
{ "raw", no_argument, NULL, 'R' }, |
|
|
|
{ "unprocessed", no_argument, NULL, 'u' }, |
|
|
|
{ "no-calibrate", no_argument, NULL, 'n' }, |
|
|
|
{ "screen", no_argument, NULL, 's' }, |
|
|
@@ -85,6 +85,7 @@ int main(int argc, char *argv[]) |
|
|
|
fprintf(stderr, " -d, --device %-14s serial port\n", device); |
|
|
|
fprintf(stderr, " -r, --rate %-16d baud rate\n", rate); |
|
|
|
fprintf(stderr, " -x, --hex hex out\n"); |
|
|
|
fprintf(stderr, " -D, --dec dec out\n"); |
|
|
|
fprintf(stderr, " -u, --unprocessed dump raw unprocessed data\n"); |
|
|
|
fprintf(stderr, " -n, --no-calibrate skip calibration routine\n"); |
|
|
|
fprintf(stderr, " -s, --screen send \\r instead of \\n\n"); |
|
|
@@ -96,8 +97,10 @@ int main(int argc, char *argv[]) |
|
|
|
err(1, "serial_open failed for %s", device); |
|
|
|
|
|
|
|
if (calibrate) { |
|
|
|
fprintf(stderr, "performing calibration\n"); |
|
|
|
char c = 'c'; |
|
|
|
write(fd, &c, 1); |
|
|
|
drain(fd); |
|
|
|
} |
|
|
|
|
|
|
|
len = 0; |
|
|
@@ -165,7 +168,7 @@ int process_calibration(const uint8_t *buf) |
|
|
|
{ |
|
|
|
float f = *(float *)buf; |
|
|
|
|
|
|
|
printf("got calibration value: %f\n", f); |
|
|
|
fprintf(stderr, "got calibration value: %f\n", f); |
|
|
|
|
|
|
|
return 1; |
|
|
|
} |
|
|
@@ -197,6 +200,7 @@ int process(const uint8_t *buf, int len) |
|
|
|
} |
|
|
|
if (!ok) { |
|
|
|
/* badly formed data; eat one byte and retry */ |
|
|
|
fprintf(stderr,"throwing away 0x%02x '%c'\n", buf[0], isprint(buf[0]) ? buf[0] : '.'); |
|
|
|
buf++; |
|
|
|
n++; |
|
|
|
goto retry; |
|
|
|