From 424653545697e178eb7835b5f542d921a2227abd Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 11 Apr 2011 10:40:44 -0300 Subject: [PATCH] tools/lib/: atnet now works (tried atrf-txrx send and receive, atrf-rssi) - atrf-proxy/atrf-proxy.c (cmd_two): "SET" wrote the wrong value - lib/atnet.c (atnet_buf_read): cleaned up the logic and fixed some small bugs --- tools/atrf-proxy/atrf-proxy.c | 2 +- tools/lib/atnet.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/atrf-proxy/atrf-proxy.c b/tools/atrf-proxy/atrf-proxy.c index be06382..0d36369 100644 --- a/tools/atrf-proxy/atrf-proxy.c +++ b/tools/atrf-proxy/atrf-proxy.c @@ -73,7 +73,7 @@ static int cmd_two(struct atrf_dsc *dsc, struct netio *netio, const char *cmd) return ret; if (val > 255) return netio_printf(netio, "-bad argument\n"); - atrf_reg_write(dsc, n, ret); + atrf_reg_write(dsc, n, val); if (atrf_error(dsc)) return netio_printf(netio, "-I/O error\n"); return netio_printf(netio, "+\n"); diff --git a/tools/lib/atnet.c b/tools/lib/atnet.c index b857598..8b91006 100644 --- a/tools/lib/atnet.c +++ b/tools/lib/atnet.c @@ -321,15 +321,22 @@ static int atnet_buf_read(void *dsc, void *buf, int size) goto fail; n = netio_read_until(netio, " ", tmp, sizeof(tmp)-1, NULL); + if (n < 0) + goto fail; + tmp[n] = 0; if (*tmp == '-') { - tmp[n] = 0; - fprintf(stderr, "%s\n", tmp+1); + fprintf(stderr, "%s ", tmp+1); + n = netio_read_until(netio, "\n", tmp, sizeof(tmp)-1, NULL); + if (n >= 0) { + tmp[n] = 0; + fprintf(stderr, "%s\n", tmp); + } goto fail; } - if (*tmp != '+' || n < 3) /* +0 */ + if (*tmp != '+' || n < 2) /* +0 */ goto invalid; len = strtoul(tmp+1, &end, 0); - if (*end != ' ') + if (*end) goto invalid; if (len > size) { fprintf(stderr, "buffer overflow\n");