X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fagilent-dmm%2Fapi.c;h=514a2d276881b8444f8099b2edbbe76285cf7e05;hb=dd5c48a6d567a3cac62c4b0058588273bbeea171;hp=96b10d41dcccfb5e530ffa079d1039797a129b88;hpb=eead2782427ee5da9b793527f9484ac827a7bec5;p=libsigrok.git diff --git a/src/hardware/agilent-dmm/api.c b/src/hardware/agilent-dmm/api.c index 96b10d41..514a2d27 100644 --- a/src/hardware/agilent-dmm/api.c +++ b/src/hardware/agilent-dmm/api.c @@ -17,13 +17,13 @@ * along with this program. If not, see . */ +#include #include #include #include #include #include -#include -#include "libsigrok.h" +#include #include "libsigrok-internal.h" #include "agilent-dmm.h" @@ -32,8 +32,11 @@ static const uint32_t scanopts[] = { SR_CONF_SERIALCOMM, }; -static const uint32_t devopts[] = { +static const uint32_t drvopts[] = { SR_CONF_MULTIMETER, +}; + +static const uint32_t devopts[] = { SR_CONF_CONTINUOUS, SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, SR_CONF_LIMIT_MSEC | SR_CONF_SET, @@ -67,28 +70,19 @@ static const struct agdmm_profile supported_agdmm[] = { ALL_ZERO }; -SR_PRIV struct sr_dev_driver agdmm_driver_info; -static struct sr_dev_driver *di = &agdmm_driver_info; - -static int init(struct sr_context *sr_ctx) -{ - return std_init(sr_ctx, di, LOG_PREFIX); -} - -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; struct sr_config *src; - struct sr_channel *ch; struct sr_serial_dev_inst *serial; GSList *l, *devices; int len, i; const char *conn, *serialcomm; char *buf, **tokens; - drvc = di->priv; + drvc = di->context; drvc->instances = NULL; devices = NULL; @@ -109,23 +103,19 @@ static GSList *scan(GSList *options) if (!serialcomm) serialcomm = SERIALCOMM; - if (!(serial = sr_serial_dev_inst_new(conn, serialcomm))) - return NULL; + serial = sr_serial_dev_inst_new(conn, serialcomm); if (serial_open(serial, SERIAL_RDWR) != SR_OK) return NULL; serial_flush(serial); - if (serial_write_blocking(serial, "*IDN?\r\n", 7, 0) < 7) { + if (serial_write_blocking(serial, "*IDN?\r\n", 7, SERIAL_WRITE_TIMEOUT_MS) < 7) { sr_err("Unable to send identification string."); return NULL; } len = 128; - if (!(buf = g_try_malloc(len))) { - sr_err("Serial buffer malloc failed."); - return NULL; - } + buf = g_malloc(len); serial_readline(serial, &buf, &len, 250); if (!len) return NULL; @@ -136,22 +126,19 @@ static GSList *scan(GSList *options) for (i = 0; supported_agdmm[i].model; i++) { if (strcmp(supported_agdmm[i].modelname, tokens[1])) continue; - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Agilent", - tokens[1], tokens[3]))) - return NULL; - if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { - sr_err("Device context malloc failed."); - return NULL; - } + sdi = g_malloc0(sizeof(struct sr_dev_inst)); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("Agilent"); + sdi->model = g_strdup(tokens[1]); + sdi->version = g_strdup(tokens[3]); + devc = g_malloc0(sizeof(struct dev_context)); devc->profile = &supported_agdmm[i]; devc->cur_mq = -1; sdi->inst_type = SR_INST_SERIAL; sdi->conn = serial; sdi->priv = devc; sdi->driver = di; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"))) - return NULL; - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); break; @@ -167,16 +154,6 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) -{ - return ((struct drv_context *)(di->priv))->instances; -} - -static int cleanup(void) -{ - return std_dev_clear(di, NULL); -} - static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -187,26 +164,15 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - if (!(devc = sdi->priv)) { - sr_err("sdi->priv was NULL."); - return SR_ERR_BUG; - } + devc = sdi->priv; switch (key) { case SR_CONF_LIMIT_MSEC: /* TODO: not yet implemented */ - if (g_variant_get_uint64(data) == 0) { - sr_err("LIMIT_MSEC can't be 0."); - return SR_ERR; - } 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 = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; default: return SR_ERR_NA; @@ -218,7 +184,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - (void)sdi; (void)cg; switch (key) { @@ -227,8 +192,12 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); break; case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); + if (!sdi) + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); + else + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); break; default: return SR_ERR_NA; @@ -237,23 +206,14 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * return SR_OK; } -static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) +static int dev_acquisition_start(const struct sr_dev_inst *sdi) { - 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."); - return SR_ERR_BUG; - } - - devc->cb_data = cb_data; - - /* Send header packet to the session bus. */ - std_session_send_df_header(cb_data, LOG_PREFIX); + std_session_send_df_header(sdi, LOG_PREFIX); /* Poll every 100ms, or whenever some data comes in. */ serial = sdi->conn; @@ -263,20 +223,20 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) return SR_OK; } -static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) +static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - return std_serial_dev_acquisition_stop(sdi, cb_data, std_serial_dev_close, + return std_serial_dev_acquisition_stop(sdi, std_serial_dev_close, sdi->conn, LOG_PREFIX); } -SR_PRIV struct sr_dev_driver agdmm_driver_info = { +static struct sr_dev_driver agdmm_driver_info = { .name = "agilent-dmm", .longname = "Agilent U12xx series DMMs", .api_version = 1, - .init = init, - .cleanup = cleanup, + .init = std_init, + .cleanup = std_cleanup, .scan = scan, - .dev_list = dev_list, + .dev_list = std_dev_list, .dev_clear = NULL, .config_get = NULL, .config_set = config_set, @@ -285,5 +245,6 @@ SR_PRIV struct sr_dev_driver agdmm_driver_info = { .dev_close = std_serial_dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, - .priv = NULL, + .context = NULL, }; +SR_REGISTER_DEV_DRIVER(agdmm_driver_info);