X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fserial-dmm%2Fprotocol.c;h=52efecb3526ad566cf2046016657f50138cdddcd;hb=50985c2019b2b5a6ce394589d89ee925b4f5e3a9;hp=d10eec267ee4e2f2aaaecf6ac235acf775214a02;hpb=54d112218713b34491cd65454abad340ff19a393;p=libsigrok.git diff --git a/hardware/serial-dmm/protocol.c b/hardware/serial-dmm/protocol.c index d10eec26..52efecb3 100644 --- a/hardware/serial-dmm/protocol.c +++ b/hardware/serial-dmm/protocol.c @@ -1,5 +1,5 @@ /* - * This file is part of the sigrok project. + * This file is part of the libsigrok project. * * Copyright (C) 2012 Alexandru Gagniuc * Copyright (C) 2012 Uwe Hermann @@ -85,48 +85,51 @@ SR_PRIV void dmm_details_pce_dm32(struct sr_datafeed_analog *analog, void *info) } } -static void handle_packet(const uint8_t *buf, struct dev_context *devc, +static void handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int dmm, void *info) { float floatval; struct sr_datafeed_packet packet; - struct sr_datafeed_analog *analog; + struct sr_datafeed_analog analog; + struct dev_context *devc; log_dmm_packet(buf); + devc = sdi->priv; - if (!(analog = g_try_malloc0(sizeof(struct sr_datafeed_analog)))) { - sr_err("Analog packet malloc failed."); - return; - } + memset(&analog, 0, sizeof(struct sr_datafeed_analog)); - analog->num_samples = 1; - analog->mq = -1; + analog.probes = sdi->probes; + analog.num_samples = 1; + analog.mq = -1; - dmms[dmm].packet_parse(buf, &floatval, analog, info); - analog->data = &floatval; + dmms[dmm].packet_parse(buf, &floatval, &analog, info); + analog.data = &floatval; /* If this DMM needs additional handling, call the resp. function. */ if (dmms[dmm].dmm_details) - dmms[dmm].dmm_details(analog, info); + dmms[dmm].dmm_details(&analog, info); - if (analog->mq != -1) { + if (analog.mq != -1) { /* Got a measurement. */ packet.type = SR_DF_ANALOG; - packet.payload = analog; + packet.payload = &analog; sr_session_send(devc->cb_data, &packet); devc->num_samples++; } - - g_free(analog); } -static void handle_new_data(struct dev_context *devc, int dmm, void *info) +static void handle_new_data(struct sr_dev_inst *sdi, int dmm, void *info) { + struct dev_context *devc; int len, i, offset = 0; + struct sr_serial_dev_inst *serial; + + devc = sdi->priv; + serial = sdi->conn; /* Try to get as much data as the buffer can hold. */ len = DMM_BUFSIZE - devc->buflen; - len = serial_read(devc->serial, devc->buf + devc->buflen, len); + len = serial_read(serial, devc->buf + devc->buflen, len); if (len < 1) { sr_err("Serial port read error: %d.", len); return; @@ -136,7 +139,7 @@ static void handle_new_data(struct dev_context *devc, int dmm, void *info) /* Now look for packets in that data. */ while ((devc->buflen - offset) >= dmms[dmm].packet_size) { if (dmms[dmm].packet_valid(devc->buf + offset)) { - handle_packet(devc->buf + offset, devc, dmm, info); + handle_packet(devc->buf + offset, sdi, dmm, info); offset += dmms[dmm].packet_size; } else { offset++; @@ -153,6 +156,8 @@ static int receive_data(int fd, int revents, int dmm, void *info, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; + struct sr_serial_dev_inst *serial; + int64_t time; int ret; (void)fd; @@ -163,13 +168,15 @@ static int receive_data(int fd, int revents, int dmm, void *info, void *cb_data) if (!(devc = sdi->priv)) return TRUE; + serial = sdi->conn; + if (revents == G_IO_IN) { /* Serial data arrived. */ - handle_new_data(devc, dmm, info); + handle_new_data(sdi, dmm, info); } else { /* Timeout, send another packet request (if DMM needs it). */ if (dmms[dmm].packet_request) { - ret = dmms[dmm].packet_request(devc->serial); + ret = dmms[dmm].packet_request(serial); if (ret < 0) { sr_err("Failed to request packet: %d.", ret); return FALSE; @@ -177,12 +184,21 @@ static int receive_data(int fd, int revents, int dmm, void *info, void *cb_data) } } - if (devc->num_samples >= devc->limit_samples) { - sr_info("Requested number of samples reached, stopping."); + if (devc->limit_samples && devc->num_samples >= devc->limit_samples) { + sr_info("Requested number of samples reached."); sdi->driver->dev_acquisition_stop(sdi, cb_data); return TRUE; } + if (devc->limit_msec) { + time = (g_get_monotonic_time() - devc->starttime) / 1000; + if (time > (int64_t)devc->limit_msec) { + sr_info("Requested time limit reached."); + sdi->driver->dev_acquisition_stop(sdi, cb_data); + return TRUE; + } + } + return TRUE; } @@ -202,6 +218,8 @@ RECEIVE_DATA(METEX_M3640D, metex14) RECEIVE_DATA(PEAKTECH_4370, metex14) RECEIVE_DATA(PCE_PCE_DM32, fs9721) RECEIVE_DATA(RADIOSHACK_22_168, metex14) +RECEIVE_DATA(RADIOSHACK_22_805, metex14) RECEIVE_DATA(RADIOSHACK_22_812, rs9lcd) -RECEIVE_DATA(VOLTCRAFT_VC820, fs9721) -RECEIVE_DATA(VOLTCRAFT_VC840, fs9721) +RECEIVE_DATA(VOLTCRAFT_VC820_SER, fs9721) +RECEIVE_DATA(VOLTCRAFT_VC840_SER, fs9721) +RECEIVE_DATA(UNI_T_UT61E_SER, es51922)