X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fagilent-dmm%2Fapi.c;h=76349d8b157e460210bb498b55a7d705f45ec361;hb=8111446ae005bb4feb8859dd2cd12f46ec4d6050;hp=6818bc8f902e269123c12172462b831319c24c42;hpb=6fab7b8f5365c7be69be4a755910945b6113dd8f;p=libsigrok.git diff --git a/hardware/agilent-dmm/api.c b/hardware/agilent-dmm/api.c index 6818bc8f..76349d8b 100644 --- a/hardware/agilent-dmm/api.c +++ b/hardware/agilent-dmm/api.c @@ -1,5 +1,5 @@ /* - * This file is part of the sigrok project. + * This file is part of the libsigrok project. * * Copyright (C) 2012 Bert Vermeulen * @@ -27,18 +27,16 @@ #include "libsigrok-internal.h" #include "agilent-dmm.h" -static const int hwopts[] = { +static const int32_t hwopts[] = { SR_CONF_CONN, SR_CONF_SERIALCOMM, - 0, }; -static const int hwcaps[] = { +static const int32_t hwcaps[] = { SR_CONF_MULTIMETER, SR_CONF_LIMIT_SAMPLES, SR_CONF_LIMIT_MSEC, SR_CONF_CONTINUOUS, - 0, }; extern const struct agdmm_job agdmm_jobs_u123x[]; @@ -69,6 +67,7 @@ static int clear_instances(void) struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; + struct sr_serial_dev_inst *serial; GSList *l; if (!(drvc = di->priv)) @@ -80,7 +79,8 @@ static int clear_instances(void) continue; if (!(devc = sdi->priv)) continue; - sr_serial_dev_inst_free(devc->serial); + serial = sdi->conn; + sr_serial_dev_inst_free(serial); sr_dev_inst_free(sdi); } g_slist_free(drvc->instances); @@ -91,7 +91,7 @@ static int clear_instances(void) static int hw_init(struct sr_context *sr_ctx) { - return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN); + return std_hw_init(sr_ctx, di, LOG_PREFIX); } static GSList *hw_scan(GSList *options) @@ -116,10 +116,10 @@ static GSList *hw_scan(GSList *options) src = l->data; switch (src->key) { case SR_CONF_CONN: - conn = src->value; + conn = g_variant_get_string(src->data, NULL); break; case SR_CONF_SERIALCOMM: - serialcomm = src->value; + serialcomm = g_variant_get_string(src->data, NULL); break; } } @@ -164,8 +164,9 @@ static GSList *hw_scan(GSList *options) return NULL; } devc->profile = &supported_agdmm[i]; - devc->serial = serial; devc->cur_mq = -1; + sdi->inst_type = SR_INST_SERIAL; + sdi->conn = serial; sdi->priv = devc; sdi->driver = di; if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1"))) @@ -193,14 +194,10 @@ static GSList *hw_dev_list(void) static int hw_dev_open(struct sr_dev_inst *sdi) { - struct dev_context *devc; - - if (!(devc = sdi->priv)) { - sr_err("sdi->priv was NULL."); - return SR_ERR_BUG; - } + struct sr_serial_dev_inst *serial; - if (serial_open(devc->serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) + serial = sdi->conn; + if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) return SR_ERR; sdi->status = SR_ST_ACTIVE; @@ -210,12 +207,11 @@ static int hw_dev_open(struct sr_dev_inst *sdi) static int hw_dev_close(struct sr_dev_inst *sdi) { - struct dev_context *devc; - - devc = sdi->priv; + struct sr_serial_dev_inst *serial; - if (devc->serial && devc->serial->fd != -1) { - serial_close(devc->serial); + serial = sdi->conn; + if (serial && serial->fd != -1) { + serial_close(serial); sdi->status = SR_ST_INACTIVE; } @@ -230,12 +226,12 @@ static int hw_cleanup(void) return SR_OK; } -static int config_set(int id, const void *value, const struct sr_dev_inst *sdi) +static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) { struct dev_context *devc; if (sdi->status != SR_ST_ACTIVE) - return SR_ERR; + return SR_ERR_DEV_CLOSED; if (!(devc = sdi->priv)) { sr_err("sdi->priv was NULL."); @@ -245,51 +241,54 @@ static int config_set(int id, const void *value, const struct sr_dev_inst *sdi) switch (id) { case SR_CONF_LIMIT_MSEC: /* TODO: not yet implemented */ - if (*(const uint64_t *)value == 0) { + if (g_variant_get_uint64(data) == 0) { sr_err("LIMIT_MSEC can't be 0."); return SR_ERR; } - devc->limit_msec = *(const uint64_t *)value; + devc->limit_msec = g_variant_get_uint64(data); sr_dbg("Setting time limit to %" PRIu64 "ms.", devc->limit_msec); break; case SR_CONF_LIMIT_SAMPLES: - devc->limit_samples = *(const uint64_t *)value; + devc->limit_samples = g_variant_get_uint64(data); sr_dbg("Setting sample limit to %" PRIu64 ".", devc->limit_samples); break; default: - sr_err("Unknown capability: %d.", id); - return SR_ERR; - break; + return SR_ERR_NA; } return SR_OK; } -static int config_list(int key, const void **data, const struct sr_dev_inst *sdi) +static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) { (void)sdi; switch (key) { case SR_CONF_SCAN_OPTIONS: - *data = hwopts; + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, + hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t)); break; case SR_CONF_DEVICE_OPTIONS: - *data = hwcaps; + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, + hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); break; default: - return SR_ERR_ARG; + return SR_ERR_NA; } return SR_OK; } -static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; + struct sr_serial_dev_inst *serial; + + if (sdi->status != SR_ST_ACTIVE) + return SR_ERR_DEV_CLOSED; if (!(devc = sdi->priv)) { sr_err("sdi->priv was NULL."); @@ -299,39 +298,19 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, devc->cb_data = cb_data; /* Send header packet to the session bus. */ - std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); + std_session_send_df_header(cb_data, LOG_PREFIX); /* Poll every 100ms, or whenever some data comes in. */ - sr_source_add(devc->serial->fd, G_IO_IN, 100, agdmm_receive_data, (void *)sdi); + serial = sdi->conn; + sr_source_add(serial->fd, G_IO_IN, 100, agdmm_receive_data, (void *)sdi); return SR_OK; } static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { - struct sr_datafeed_packet packet; - struct dev_context *devc; - - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR; - - if (!(devc = sdi->priv)) { - sr_err("sdi->priv was NULL."); - return SR_ERR_BUG; - } - - sr_dbg("Stopping acquisition."); - - sr_source_remove(devc->serial->fd); - hw_dev_close((struct sr_dev_inst *)sdi); - - /* Send end packet to the session bus. */ - sr_dbg("Sending SR_DF_END."); - packet.type = SR_DF_END; - sr_session_send(cb_data, &packet); - - - return SR_OK; + return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close, + sdi->conn, LOG_PREFIX); } SR_PRIV struct sr_dev_driver agdmm_driver_info = {