r4228 - in developers/werner/ahrt/host/tmc: . examples
werner at sita.openmoko.org
werner at sita.openmoko.org
Thu Mar 20 00:15:45 CET 2008
Author: werner
Date: 2008-03-20 00:15:37 +0100 (Thu, 20 Mar 2008)
New Revision: 4228
Modified:
developers/werner/ahrt/host/tmc/README
developers/werner/ahrt/host/tmc/examples/tty.py
developers/werner/ahrt/host/tmc/python.c
developers/werner/ahrt/host/tmc/telnet.c
developers/werner/ahrt/host/tmc/tmc.c
developers/werner/ahrt/host/tmc/tmc.h
developers/werner/ahrt/host/tmc/usbtmc.c
Log:
- python.c, README, tmc.h, tmc.c: new module method "debug" to enable/disable
debugging
- telnet.c: moved most of the retry logic from telnet_open into do_connect
- usbtmc.c: all debugging messages are not controlled with "debug"
- examples/tty.py: we don't need to import "time"
- README: added more material on the Fluke 8845A resetting connections
Modified: developers/werner/ahrt/host/tmc/README
===================================================================
--- developers/werner/ahrt/host/tmc/README 2008-03-19 21:05:41 UTC (rev 4227)
+++ developers/werner/ahrt/host/tmc/README 2008-03-19 23:15:37 UTC (rev 4228)
@@ -112,6 +112,16 @@
(DCI) command to the instrument.
+Debugging
+---------
+
+Debug output can be enabled or disabled with
+
+ tmc.debug(level)
+
+Level 0 turns debug output off.
+
+
Transport arguments
===================
@@ -178,7 +188,9 @@
Setting the option "tries=3" should work around all this.
+[ Note: no, it doesn't fix this all the time. See below. ]
+
PicoTest M3500
--------------
@@ -222,8 +234,12 @@
completed, and also to synchronize with that event.
The "telnet" protocol handler retries connections even if "tries" is set
-to one.
+to one. (Fixed now ?)
+The Fluke 8845A resets the connection also on writes. Most likely, the
+first TCP segment after the initial SYN resets it. Should probably send
+an *IDN? to check.
+
The way how we select the protocol is probably very non-Python-ish. Should
there be a per-module method for each protocol that returns a properly
initialized object of type tmc.Instr instead ? Or maybe even a set of
Modified: developers/werner/ahrt/host/tmc/examples/tty.py
===================================================================
--- developers/werner/ahrt/host/tmc/examples/tty.py 2008-03-19 21:05:41 UTC (rev 4227)
+++ developers/werner/ahrt/host/tmc/examples/tty.py 2008-03-19 23:15:37 UTC (rev 4228)
@@ -5,7 +5,7 @@
# /dev/ttyUSB0, to output 1.234V limited to 10mA on its programmable output.
#
-import tmc, time
+import tmc
d = tmc.Instr("tty", "bps=9600", "no_dci", "/dev/ttyUSB0")
d.send('*IDN?')
Modified: developers/werner/ahrt/host/tmc/python.c
===================================================================
--- developers/werner/ahrt/host/tmc/python.c 2008-03-19 21:05:41 UTC (rev 4227)
+++ developers/werner/ahrt/host/tmc/python.c 2008-03-19 23:15:37 UTC (rev 4228)
@@ -203,6 +203,17 @@
}
+static PyObject *tmc_py_debug(PyObject *self, PyObject *arg)
+{
+ int dbg;
+
+ if (!PyArg_ParseTuple(arg, "i", &dbg))
+ return NULL;
+ tmc_debug(dbg);
+ return Py_BuildValue("");
+}
+
+
static PyMethodDef tmc_tp_methods[] = {
{ "send", tmc_py_send, METH_VARARGS, "Send commands" },
{ "read", tmc_py_read, METH_NOARGS, "Read a response" },
@@ -226,6 +237,7 @@
static PyMethodDef tmc_methods[] = {
+ { "debug", tmc_py_debug, METH_VARARGS, "Enable debug output" },
{ NULL, NULL, 0, NULL }
};
Modified: developers/werner/ahrt/host/tmc/telnet.c
===================================================================
--- developers/werner/ahrt/host/tmc/telnet.c 2008-03-19 21:05:41 UTC (rev 4227)
+++ developers/werner/ahrt/host/tmc/telnet.c 2008-03-19 23:15:37 UTC (rev 4228)
@@ -72,26 +72,27 @@
static int do_connect(struct telnet_dsc *d)
{
- while (1) {
- d->sd = socket(PF_INET, SOCK_STREAM, 0);
- if (d->sd < 0) {
- perror("socket");
- return -1;
- }
+ d->sd = socket(PF_INET, SOCK_STREAM, 0);
+ if (d->sd < 0) {
+ perror("socket");
+ return -1;
+ }
+ while (d->tries_left || !d->max_tries) {
+ if (d->tries_left)
+ d->tries_left--;
if (connect(d->sd,
(struct sockaddr *) &d->addr, sizeof(d->addr)) >= 0)
return 0;
- if (errno != ECONNREFUSED || d->tries_left == 1) {
+ if (errno != ECONNREFUSED || !d->tries_left) {
perror("connect");
- if (close(d->sd) < 0)
- perror("close");
- return -1;
+ break;
}
- if (d->tries_left)
- d->tries_left--;
sleep(1);
}
+ if (close(d->sd) < 0)
+ perror("close");
+ return -1;
}
@@ -111,7 +112,7 @@
return NULL;
}
tries = strtoul(argv[0]+6, &end, 0);
- if (*end) {
+ if (*end || !tries) {
usage();
return NULL;
}
@@ -232,11 +233,9 @@
do {
got = read(d->sd, buf, BUF_SIZE);
- if (got < 0 && errno == ECONNRESET &&
- (d->tries_left || !d->max_tries)) {
- (void) close(d->sd);
- if (d->tries_left)
- d->tries_left--;
+ if (got < 0 && errno == ECONNRESET) {
+ if (close(d->sd) < 0)
+ perror("close");
if (do_connect(d) < 0)
return -1;
if (telnet_write(dsc, d->last_buf, d->last_len) < 0)
Modified: developers/werner/ahrt/host/tmc/tmc.c
===================================================================
--- developers/werner/ahrt/host/tmc/tmc.c 2008-03-19 21:05:41 UTC (rev 4227)
+++ developers/werner/ahrt/host/tmc/tmc.c 2008-03-19 23:15:37 UTC (rev 4228)
@@ -153,6 +153,12 @@
}
+void tmc_debug(int level)
+{
+ debug = level;
+}
+
+
const struct proto_ops *tmc_ops(const char *name)
{
static struct {
Modified: developers/werner/ahrt/host/tmc/tmc.h
===================================================================
--- developers/werner/ahrt/host/tmc/tmc.h 2008-03-19 21:05:41 UTC (rev 4227)
+++ developers/werner/ahrt/host/tmc/tmc.h 2008-03-19 23:15:37 UTC (rev 4228)
@@ -29,6 +29,8 @@
int tmc_start(struct tmc_dsc *dsc, const char *file, const char *repeat);
int tmc_stop(struct tmc_dsc *dsc);
+void tmc_debug(int level);
+
/*
* This should probably go somewhere else ...
*/
Modified: developers/werner/ahrt/host/tmc/usbtmc.c
===================================================================
--- developers/werner/ahrt/host/tmc/usbtmc.c 2008-03-19 21:05:41 UTC (rev 4227)
+++ developers/werner/ahrt/host/tmc/usbtmc.c 2008-03-19 23:15:37 UTC (rev 4228)
@@ -291,7 +291,8 @@
(int) got);
return;
}
- fprintf(stderr, "status 0x%02x bTag 0x%02x\n", buf[0], buf[1]);
+ if (debug)
+ fprintf(stderr, "status 0x%02x bTag 0x%02x\n", buf[0], buf[1]);
/* depending on status, do more */
}
@@ -315,7 +316,8 @@
(int) got);
return;
}
- fprintf(stderr, "status 0x%02x bTag 0x%02x\n", buf[0], buf[1]);
+ if (debug)
+ fprintf(stderr, "status 0x%02x bTag 0x%02x\n", buf[0], buf[1]);
/* depending on status, do more */
}
More information about the commitlog
mailing list