X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fnorma-dmm%2Fprotocol.c;h=a077cf983b05ef392a642f322ebe9991fab0852e;hb=0a1f7b09b3fa4cc4da29c7acf53717e14b004b63;hp=e8270593428403c1360acb0935d9d1036882cce6;hpb=d0148a506ed1007518704d72c0410d4361668fa4;p=libsigrok.git diff --git a/src/hardware/norma-dmm/protocol.c b/src/hardware/norma-dmm/protocol.c index e8270593..a077cf98 100644 --- a/src/hardware/norma-dmm/protocol.c +++ b/src/hardware/norma-dmm/protocol.c @@ -22,8 +22,11 @@ * @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?" }, @@ -48,7 +51,8 @@ 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_blocking(serial, buf, len, 0) < 0) { + 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; @@ -87,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); @@ -116,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(struct sr_datafeed_analog)); + memset(&analog, 0, sizeof(struct sr_datafeed_analog_old)); /* * The numbers are hex digits, starting from 0. @@ -317,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,7 +364,7 @@ static void nma_process_line(const struct sr_dev_inst *sdi) analog.data = &value; memset(&packet, 0, sizeof(struct sr_datafeed_packet)); - packet.type = SR_DF_ANALOG; + packet.type = SR_DF_ANALOG_OLD; packet.payload = &analog; sr_session_send(devc->cb_data, &packet);