* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <config.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
-#include <errno.h>
#include <glib.h>
-#include "libsigrok.h"
+#include <libsigrok/libsigrok.h>
#include "libsigrok-internal.h"
#include "protocol.h"
float floatval;
struct sr_datafeed_packet packet;
struct sr_datafeed_analog analog;
+ struct sr_analog_encoding encoding;
+ struct sr_analog_meaning meaning;
+ struct sr_analog_spec spec;
struct dev_context *devc;
+ gboolean sent_sample;
+ size_t ch_idx;
dmm = (struct dmm_info *)sdi->driver;
log_dmm_packet(buf);
devc = sdi->priv;
- memset(&analog, 0, sizeof(struct sr_datafeed_analog));
-
- analog.channels = sdi->channels;
- analog.num_samples = 1;
- analog.mq = -1;
-
- dmm->packet_parse(buf, &floatval, &analog, info);
- analog.data = &floatval;
-
- /* If this DMM needs additional handling, call the resp. function. */
- if (dmm->dmm_details)
- dmm->dmm_details(&analog, info);
+ sent_sample = FALSE;
+ memset(info, 0, dmm->info_size);
+ for (ch_idx = 0; ch_idx < dmm->channel_count; ch_idx++) {
+ /* Note: digits/spec_digits will be overridden by the DMM parsers. */
+ sr_analog_init(&analog, &encoding, &meaning, &spec, 0);
+
+ analog.meaning->channels =
+ g_slist_append(NULL, g_slist_nth_data(sdi->channels, ch_idx));
+ analog.num_samples = 1;
+ analog.meaning->mq = 0;
+
+ dmm->packet_parse(buf, &floatval, &analog, info);
+ analog.data = &floatval;
+
+ /* If this DMM needs additional handling, call the resp. function. */
+ if (dmm->dmm_details)
+ dmm->dmm_details(&analog, info);
+
+ if (analog.meaning->mq != 0) {
+ /* Got a measurement. */
+ packet.type = SR_DF_ANALOG;
+ packet.payload = &analog;
+ sr_session_send(sdi, &packet);
+ sent_sample = TRUE;
+ }
+ }
- if (analog.mq != -1) {
- /* Got a measurement. */
- packet.type = SR_DF_ANALOG;
- packet.payload = &analog;
- sr_session_send(devc->cb_data, &packet);
- devc->num_samples++;
+ if (sent_sample) {
+ sr_sw_limits_update_samples_read(&devc->limits, 1);
}
}
{
struct dmm_info *dmm;
struct dev_context *devc;
- int len, i, offset = 0;
+ int len, offset;
struct sr_serial_dev_inst *serial;
dmm = (struct dmm_info *)sdi->driver;
devc->buflen += len;
/* Now look for packets in that data. */
+ offset = 0;
while ((devc->buflen - offset) >= dmm->packet_size) {
if (dmm->packet_valid(devc->buf + offset)) {
handle_packet(devc->buf + offset, sdi, info);
}
/* If we have any data left, move it to the beginning of our buffer. */
- for (i = 0; i < devc->buflen - offset; i++)
- devc->buf[i] = devc->buf[offset + i];
+ if (devc->buflen > offset)
+ memmove(devc->buf, devc->buf + offset, devc->buflen - offset);
devc->buflen -= offset;
}
struct sr_dev_inst *sdi;
struct dev_context *devc;
struct dmm_info *dmm;
- int64_t time;
void *info;
(void)fd;
if (revents == G_IO_IN) {
/* Serial data arrived. */
- info = malloc(dmm->info_size);
+ info = g_malloc(dmm->info_size);
handle_new_data(sdi, info);
- free(info);
+ g_free(info);
} else {
/* Timeout; send another packet request if DMM needs it. */
if (dmm->packet_request && (req_packet(sdi) < 0))
return FALSE;
}
- 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;
- }
- }
+ if (sr_sw_limits_check(&devc->limits))
+ sr_dev_acquisition_stop(sdi);
return TRUE;
}