X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Ffluke-dmm%2Ffluke.c;h=3629b5f373e1cbbf8e6cd2908efbaaa5569b7708;hb=45884333ff8641c86d9808b46dde9f571083c10d;hp=242843dfc58f57316494fb2a663ed3bf21524d56;hpb=707fa85ad5fa7e3f74dbb6863891e80a26126b25;p=libsigrok.git diff --git a/src/hardware/fluke-dmm/fluke.c b/src/hardware/fluke-dmm/fluke.c index 242843df..3629b5f3 100644 --- a/src/hardware/fluke-dmm/fluke.c +++ b/src/hardware/fluke-dmm/fluke.c @@ -17,19 +17,19 @@ * along with this program. If not, see . */ +#include #include #include #include -#include #include -#include "libsigrok.h" +#include #include "libsigrok-internal.h" #include "fluke-dmm.h" -static struct sr_datafeed_analog *handle_qm_18x(const struct sr_dev_inst *sdi, +static struct sr_datafeed_analog_old *handle_qm_18x(const struct sr_dev_inst *sdi, char **tokens) { - struct sr_datafeed_analog *analog; + struct sr_datafeed_analog_old *analog; float fvalue; char *e, *u; gboolean is_oor; @@ -40,14 +40,14 @@ static struct sr_datafeed_analog *handle_qm_18x(const struct sr_dev_inst *sdi, if ((e = strstr(tokens[1], "Out of range"))) { is_oor = TRUE; fvalue = -1; - while(*e && *e != '.') + while (*e && *e != '.') e++; } else { is_oor = FALSE; /* Delimit the float, since sr_atof_ascii() wants only * a valid float here. */ e = tokens[1]; - while(*e && *e != ' ') + while (*e && *e != ' ') e++; *e++ = '\0'; if (sr_atof_ascii(tokens[1], &fvalue) != SR_OK || fvalue == 0.0) { @@ -56,13 +56,11 @@ static struct sr_datafeed_analog *handle_qm_18x(const struct sr_dev_inst *sdi, return NULL; } } - while(*e && *e == ' ') + while (*e && *e == ' ') e++; - if (!(analog = g_try_malloc0(sizeof(struct sr_datafeed_analog)))) - return NULL; - if (!(analog->data = g_try_malloc(sizeof(float)))) - return NULL; + analog = g_malloc0(sizeof(struct sr_datafeed_analog_old)); + analog->data = g_malloc(sizeof(float)); analog->channels = sdi->channels; analog->num_samples = 1; if (is_oor) @@ -156,10 +154,10 @@ static struct sr_datafeed_analog *handle_qm_18x(const struct sr_dev_inst *sdi, return analog; } -static struct sr_datafeed_analog *handle_qm_28x(const struct sr_dev_inst *sdi, +static struct sr_datafeed_analog_old *handle_qm_28x(const struct sr_dev_inst *sdi, char **tokens) { - struct sr_datafeed_analog *analog; + struct sr_datafeed_analog_old *analog; float fvalue; if (!tokens[1]) @@ -170,10 +168,8 @@ static struct sr_datafeed_analog *handle_qm_28x(const struct sr_dev_inst *sdi, return NULL; } - if (!(analog = g_try_malloc0(sizeof(struct sr_datafeed_analog)))) - return NULL; - if (!(analog->data = g_try_malloc(sizeof(float)))) - return NULL; + analog = g_malloc0(sizeof(struct sr_datafeed_analog_old)); + analog->data = g_malloc(sizeof(float)); analog->channels = sdi->channels; analog->num_samples = 1; *analog->data = fvalue; @@ -366,7 +362,7 @@ static void handle_qm_19x_data(const struct sr_dev_inst *sdi, char **tokens) { struct dev_context *devc; struct sr_datafeed_packet packet; - struct sr_datafeed_analog analog; + struct sr_datafeed_analog_old analog; float fvalue; if (!strcmp(tokens[0], "9.9E+37")) { @@ -386,7 +382,6 @@ static void handle_qm_19x_data(const struct sr_dev_inst *sdi, char **tokens) /* Don't have valid metadata yet. */ return; - if (devc->mq == SR_MQ_RESISTANCE && isnan(fvalue)) fvalue = INFINITY; else if (devc->mq == SR_MQ_CONTINUITY) { @@ -402,9 +397,9 @@ static void handle_qm_19x_data(const struct sr_dev_inst *sdi, char **tokens) analog.mq = devc->mq; analog.unit = devc->unit; analog.mqflags = 0; - packet.type = SR_DF_ANALOG; + packet.type = SR_DF_ANALOG_OLD; packet.payload = &analog; - sr_session_send(devc->cb_data, &packet); + sr_session_send(sdi, &packet); devc->num_samples++; } @@ -414,7 +409,7 @@ static void handle_line(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_serial_dev_inst *serial; struct sr_datafeed_packet packet; - struct sr_datafeed_analog *analog; + struct sr_datafeed_analog_old *analog; int num_tokens, n, i; char cmd[16], **tokens; @@ -438,7 +433,7 @@ static void handle_line(const struct sr_dev_inst *sdi) if (devc->profile->model == FLUKE_187 || devc->profile->model == FLUKE_189) { devc->expect_response = FALSE; analog = handle_qm_18x(sdi, tokens); - } else if (devc->profile->model == FLUKE_287) { + } else if (devc->profile->model == FLUKE_287 || devc->profile->model == FLUKE_289) { devc->expect_response = FALSE; analog = handle_qm_28x(sdi, tokens); } else if (devc->profile->model == FLUKE_190) { @@ -456,9 +451,8 @@ static void handle_line(const struct sr_dev_inst *sdi) /* Slip the request in now, before the main * timer loop asks for metadata again. */ n = sprintf(cmd, "QM %d\r", devc->meas_type); - if (serial_write(serial, cmd, n) == -1) - sr_err("Unable to send QM (measurement): %s.", - strerror(errno)); + if (serial_write_blocking(serial, cmd, n, SERIAL_WRITE_TIMEOUT_MS) < 0) + sr_err("Unable to send QM (measurement)."); } } else { /* Response to QM measurement request. */ @@ -471,9 +465,9 @@ static void handle_line(const struct sr_dev_inst *sdi) if (analog) { /* Got a measurement. */ - packet.type = SR_DF_ANALOG; + packet.type = SR_DF_ANALOG_OLD; packet.payload = analog; - sr_session_send(devc->cb_data, &packet); + sr_session_send(sdi, &packet); devc->num_samples++; g_free(analog->data); g_free(analog); @@ -500,7 +494,7 @@ SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data) serial = sdi->conn; if (revents == G_IO_IN) { /* Serial data arrived. */ - while(FLUKEDMM_BUFSIZE - devc->buflen - 1 > 0) { + while (FLUKEDMM_BUFSIZE - devc->buflen - 1 > 0) { len = serial_read_nonblocking(serial, devc->buf + devc->buflen, 1); if (len < 1) break; @@ -515,7 +509,7 @@ SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data) } if (devc->limit_samples && devc->num_samples >= devc->limit_samples) { - sdi->driver->dev_acquisition_stop(sdi, cb_data); + sdi->driver->dev_acquisition_stop(sdi); return TRUE; } @@ -526,8 +520,8 @@ SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data) * out-of-sync or temporary disconnect issues. */ if ((devc->expect_response == FALSE && elapsed > devc->profile->poll_period) || elapsed > devc->profile->timeout) { - if (serial_write(serial, "QM\r", 3) == -1) - sr_err("Unable to send QM: %s.", strerror(errno)); + if (serial_write_blocking(serial, "QM\r", 3, SERIAL_WRITE_TIMEOUT_MS) < 0) + sr_err("Unable to send QM."); devc->cmd_sent_at = now; devc->expect_response = TRUE; }