Browse Source

fixes

git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@7702 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 15 years ago
parent
commit
882392fe0a
2 changed files with 11 additions and 3 deletions
  1. +7
    -3
      pc/read.c
  2. +4
    -0
      pc/serial-util.h

+ 7
- 3
pc/read.c View File

@@ -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;


+ 4
- 0
pc/serial-util.h View File

@@ -16,6 +16,10 @@ int serial_open(const char *device, int rate);
are received or a timeout occurs. */
int saferead_timeout(int fd, void *buf, size_t count, int timeout_ms);

static inline int saferead(int fd, void *buf, size_t count) {
return saferead_timeout(fd, buf, count, -1);
}

/* Like write(), but restarts after EINTR */
ssize_t safewrite(int fd, const void *buf, size_t count);



Loading…
Cancel
Save