]> sigrok.org Git - libsigrok.git/commitdiff
norma-dmm: Added request timeout mechanism; docs.
authorMatthias Heidbrink <redacted>
Fri, 13 Jun 2014 19:22:11 +0000 (21:22 +0200)
committerMatthias Heidbrink <redacted>
Fri, 13 Jun 2014 19:22:11 +0000 (21:22 +0200)
hardware/norma-dmm/api.c
hardware/norma-dmm/protocol.c
hardware/norma-dmm/protocol.h

index e0397c01d2c4eb416bd46f76763917edceb73685..5dacde2ea4a4d24119dde53813eeeefa98d62319 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+/** @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';
index 8e1466a42df76e0a5504890cf492bd21fb233380..717ef15213142ed93080578aa4599ae7e4a1ef1b 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+/** @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;
index 2ed0e250346d4193fdd98ee12b8e7df8b140f195..951734e8f99667b7502375e4e0eab500309e9d5d 100644 (file)
 #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. */