X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fnorma-dmm%2Fprotocol.c;h=7e0f2a10834f7fe0fbacc1e0a3026537ede21311;hb=c2fdcc25a47c4c8f25e3ea96ea36a674a151e839;hp=522d88a1749451c62fc1f0d9f527e656e1f7eaa5;hpb=32950cc071715efae178aac92e7975c8ed185fd1;p=libsigrok.git diff --git a/src/hardware/norma-dmm/protocol.c b/src/hardware/norma-dmm/protocol.c index 522d88a1..7e0f2a10 100644 --- a/src/hardware/norma-dmm/protocol.c +++ b/src/hardware/norma-dmm/protocol.c @@ -22,12 +22,15 @@ * @internal */ +#include #include "protocol.h" +#define LINE_LENGTH 20 + SR_PRIV const struct nmadmm_req nmadmm_requests[] = { { NMADMM_REQ_IDN, "IDN?" }, { NMADMM_REQ_IDN, "STATUS?" }, - { 0, NULL }, + ALL_ZERO }; static int nma_send_req(const struct sr_dev_inst *sdi, int req, char *params) @@ -48,9 +51,9 @@ static int nma_send_req(const struct sr_dev_inst *sdi, int req, char *params) devc->last_req = req; devc->last_req_pending = TRUE; - if (serial_write(serial, buf, len) == -1) { - sr_err("Unable to send request: %d %s.", - errno, strerror(errno)); + if (serial_write_blocking(serial, buf, len, + serial_timeout(serial, len)) < 0) { + sr_err("Unable to send request."); devc->last_req_pending = FALSE; return SR_ERR; } @@ -88,24 +91,24 @@ static void nma_process_line(const struct sr_dev_inst *sdi) int mmode, devstat; /* Measuring mode, device status */ float value; /* Measured value */ float scale; /* Scaling factor depending on range and function */ - struct sr_datafeed_analog analog; + struct sr_datafeed_analog_old analog; struct sr_datafeed_packet packet; devc = sdi->priv; - devc->buf[20] = '\0'; + devc->buf[LINE_LENGTH] = '\0'; sr_spew("Received line '%s'.", devc->buf); /* Check line. */ - if (strlen((const char *)devc->buf) != 20) { + if (strlen((const char *)devc->buf) != LINE_LENGTH) { sr_err("line: Invalid status '%s', must be 20 hex digits.", devc->buf); devc->buflen = 0; return; } - for (pos = 0; pos < 20; pos++) { + for (pos = 0; pos < LINE_LENGTH; pos++) { if (!isxdigit(devc->buf[pos])) { sr_err("line: Expected hex digit in '%s' at pos %d!", devc->buf, pos); @@ -117,7 +120,7 @@ static void nma_process_line(const struct sr_dev_inst *sdi) /* Start decoding. */ value = 0.0; scale = 1.0; - memset(&analog, 0, sizeof(analog)); + memset(&analog, 0, sizeof(struct sr_datafeed_analog_old)); /* * The numbers are hex digits, starting from 0. @@ -318,7 +321,7 @@ static void nma_process_line(const struct sr_dev_inst *sdi) sr_warn("Low battery, measurement quality degraded!"); } /* 0x08: SCALED */ - /* 0x04: RATE (=lower resolution, allows higher rata rate up to 10/s. */ + /* 0x04: RATE (=lower resolution, allows higher data rate up to 10/s. */ /* 0x02: Current clamp */ if (flags & 0x01) { /* dB */ /* @@ -360,13 +363,13 @@ static void nma_process_line(const struct sr_dev_inst *sdi) analog.num_samples = 1; analog.data = &value; - memset(&packet, 0, sizeof(packet)); - packet.type = SR_DF_ANALOG; + memset(&packet, 0, sizeof(struct sr_datafeed_packet)); + packet.type = SR_DF_ANALOG_OLD; packet.payload = &analog; - sr_session_send(devc->cb_data, &packet); + sr_session_send(sdi, &packet); /* Finish processing. */ - devc->num_samples++; + sr_sw_limits_update_samples_read(&devc->limits, 1); devc->buflen = 0; } @@ -376,8 +379,6 @@ SR_PRIV int norma_dmm_receive_data(int fd, int revents, void *cb_data) struct dev_context *devc; struct sr_serial_dev_inst *serial; int len; - gboolean terminating; - gdouble elapsed_s; (void)fd; @@ -408,23 +409,10 @@ SR_PRIV int norma_dmm_receive_data(int fd, int revents, void *cb_data) } } - /* If number of samples or time limit reached, stop acquisition. */ - terminating = FALSE; - if (devc->limit_samples && (devc->num_samples >= devc->limit_samples)) { - sdi->driver->dev_acquisition_stop(sdi, cb_data); - terminating = TRUE; - } - - if (devc->limit_msec) { - elapsed_s = g_timer_elapsed(devc->elapsed_msec, NULL); - if ((elapsed_s * 1000) >= devc->limit_msec) { - sdi->driver->dev_acquisition_stop(sdi, cb_data); - terminating = TRUE; - } - } - - /* Request next package. */ - if (!terminating) { + if (sr_sw_limits_check(&devc->limits)) { + sdi->driver->dev_acquisition_stop(sdi); + } else { + /* Request next package. */ if (devc->last_req_pending) { gint64 elapsed_us = g_get_monotonic_time() - devc->req_sent_at; if (elapsed_us > NMADMM_TIMEOUT_MS * 1000) {/* Timeout! */