From: Matthias Heidbrink Date: Fri, 13 Jun 2014 19:22:11 +0000 (+0200) Subject: norma-dmm: Added request timeout mechanism; docs. X-Git-Tag: libsigrok-0.4.0~1288 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a4e435eb49c1fa30c31d5851b404001324cafe33;p=libsigrok.git norma-dmm: Added request timeout mechanism; docs. --- diff --git a/hardware/norma-dmm/api.c b/hardware/norma-dmm/api.c index e0397c01..5dacde2e 100644 --- a/hardware/norma-dmm/api.c +++ b/hardware/norma-dmm/api.c @@ -17,6 +17,11 @@ * along with this program. If not, see . */ +/** @file + * Norma DM9x0/Siemens B102x DMMs driver. + * @internal + */ + #include "protocol.h" static const int32_t hwopts[] = { @@ -122,6 +127,7 @@ static GSList *do_scan(struct sr_dev_driver* drv, GSList *options) snprintf(req, sizeof(req), "%s\r\n", nmadmm_requests[NMADMM_REQ_IDN].req_str); + g_usleep(150 * 1000); /* Wait a little to allow serial port to settle. */ for (cnt = 0; cnt < 7; cnt++) { if (serial_write(serial, req, strlen(req)) == -1) { sr_err("Unable to send identification request: %d %s.", @@ -129,7 +135,7 @@ static GSList *do_scan(struct sr_dev_driver* drv, GSList *options) return NULL; } len = BUF_MAX; - serial_readline(serial, &buf, &len, 1500); + serial_readline(serial, &buf, &len, NMADMM_TIMEOUT_MS); if (!len) continue; buf[BUF_MAX - 1] = '\0'; diff --git a/hardware/norma-dmm/protocol.c b/hardware/norma-dmm/protocol.c index 8e1466a4..717ef152 100644 --- a/hardware/norma-dmm/protocol.c +++ b/hardware/norma-dmm/protocol.c @@ -17,6 +17,11 @@ * along with this program. If not, see . */ +/** @file + * Norma DM9x0/Siemens B102x DMMs driver. + * @internal + */ + #include "protocol.h" SR_PRIV const struct nmadmm_req nmadmm_requests[] = { @@ -50,6 +55,8 @@ static int nma_send_req(const struct sr_dev_inst *sdi, int req, char *params) return SR_ERR; } + devc->req_sent_at = g_get_monotonic_time(); + return SR_OK; } @@ -417,9 +424,18 @@ SR_PRIV int norma_dmm_receive_data(int fd, int revents, void *cb_data) } /* Request next package. */ - if (!terminating && !devc->last_req_pending) { - if (nma_send_req(sdi, NMADMM_REQ_STATUS, NULL) != SR_OK) - return FALSE; + if (!terminating) { + if (devc->last_req_pending) { + gint64 elapsed_us = g_get_monotonic_time() - devc->req_sent_at; + if (elapsed_us > NMADMM_TIMEOUT_MS * 1000) {/* Timeout! */ + sr_spew("Request timeout!"); + devc->last_req_pending = FALSE; + } + } + if (!devc->last_req_pending) { + if (nma_send_req(sdi, NMADMM_REQ_STATUS, NULL) != SR_OK) + return FALSE; + } } return TRUE; diff --git a/hardware/norma-dmm/protocol.h b/hardware/norma-dmm/protocol.h index 2ed0e250..951734e8 100644 --- a/hardware/norma-dmm/protocol.h +++ b/hardware/norma-dmm/protocol.h @@ -29,10 +29,17 @@ #include "libsigrok.h" #include "libsigrok-internal.h" +/** @file + * Norma DM9x0/Siemens B102x DMMs driver. + * @internal + */ + #define LOG_PREFIX "norma-dmm" #define NMADMM_BUFSIZE 256 +#define NMADMM_TIMEOUT_MS 2000 /**< Request timeout. */ + /** Norma DMM request types (used ones only, the DMMs support about 50). */ enum { NMADMM_REQ_IDN = 0, /**< Request identity */ @@ -63,6 +70,7 @@ struct dev_context { /* Operational state */ int last_req; /**< Last request. */ + int64_t req_sent_at; /**< Request sent. */ gboolean last_req_pending; /**< Last request not answered yet. */ int lowbatt; /**< Low battery. 1=low, 2=critical. */