X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Ffluke-dmm%2Fapi.c;h=604d65f4f44aeb7ab5722dcf03bbcc0ae88d60e6;hb=8f996b89481670219c7576e2c68b128a0a2ce026;hp=cdb527d1f1916091aa3299be51f834170fb645d9;hpb=70424328c10640f0c1db0ab6334723658c043470;p=libsigrok.git diff --git a/hardware/fluke-dmm/api.c b/hardware/fluke-dmm/api.c index cdb527d1..604d65f4 100644 --- a/hardware/fluke-dmm/api.c +++ b/hardware/fluke-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 * @@ -58,36 +58,14 @@ static const struct flukedmm_profile supported_flukedmm[] = { { FLUKE_190, "199B", 1000, 3500 }, }; - -/* Properly close and free all devices. */ -static int clear_instances(void) +static int dev_clear(void) { - struct sr_dev_inst *sdi; - struct drv_context *drvc; - struct dev_context *devc; - GSList *l; - - if (!(drvc = di->priv)) - return SR_OK; - - drvc = di->priv; - for (l = drvc->instances; l; l = l->next) { - if (!(sdi = l->data)) - continue; - if (!(devc = sdi->priv)) - continue; - sr_serial_dev_inst_free(devc->serial); - sr_dev_inst_free(sdi); - } - g_slist_free(drvc->instances); - drvc->instances = NULL; - - return SR_OK; + return std_dev_clear(di, NULL); } -static int hw_init(struct sr_context *sr_ctx) +static int init(struct sr_context *sr_ctx) { - return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN); + return std_init(sr_ctx, di, LOG_PREFIX); } static GSList *fluke_scan(const char *conn, const char *serialcomm) @@ -157,7 +135,8 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) return NULL; } devc->profile = &supported_flukedmm[i]; - devc->serial = serial; + 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"))) @@ -180,7 +159,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) return devices; } -static GSList *hw_scan(GSList *options) +static GSList *scan(GSList *options) { struct sr_config *src; GSList *l, *devices; @@ -218,21 +197,17 @@ static GSList *hw_scan(GSList *options) return devices; } -static GSList *hw_dev_list(void) +static GSList *dev_list(void) { return ((struct drv_context *)(di->priv))->instances; } -static int hw_dev_open(struct sr_dev_inst *sdi) +static int 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; @@ -240,34 +215,33 @@ static int hw_dev_open(struct sr_dev_inst *sdi) return SR_OK; } -static int hw_dev_close(struct sr_dev_inst *sdi) +static int 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; } return SR_OK; } -static int hw_cleanup(void) +static int cleanup(void) { - - clear_instances(); - - return SR_OK; + return dev_clear(); } -static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) +static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, + const struct sr_probe_group *probe_group) { struct dev_context *devc; + (void)probe_group; + if (sdi->status != SR_ST_ACTIVE) - return SR_ERR; + return SR_ERR_DEV_CLOSED; if (!(devc = sdi->priv)) { sr_err("sdi->priv was NULL."); @@ -291,18 +265,17 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) 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, GVariant **data, const struct sr_dev_inst *sdi) +static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, + const struct sr_probe_group *probe_group) { - (void)sdi; + (void)probe_group; switch (key) { case SR_CONF_SCAN_OPTIONS: @@ -314,16 +287,19 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) 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 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."); @@ -333,12 +309,13 @@ 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, 50, fluke_receive_data, (void *)sdi); + serial = sdi->conn; + sr_source_add(serial->fd, G_IO_IN, 50, fluke_receive_data, (void *)sdi); - if (serial_write(devc->serial, "QM\r", 3) == -1) { + if (serial_write(serial, "QM\r", 3) == -1) { sr_err("Unable to send QM: %s.", strerror(errno)); return SR_ERR; } @@ -348,27 +325,27 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) +static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { - return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close, - ((struct dev_context *)(sdi->priv))->serial, DRIVER_LOG_DOMAIN); + return std_dev_acquisition_stop_serial(sdi, cb_data, dev_close, + sdi->conn, LOG_PREFIX); } SR_PRIV struct sr_dev_driver flukedmm_driver_info = { .name = "fluke-dmm", .longname = "Fluke 18x/28x series DMMs", .api_version = 1, - .init = hw_init, - .cleanup = hw_cleanup, - .scan = hw_scan, - .dev_list = hw_dev_list, - .dev_clear = clear_instances, + .init = init, + .cleanup = cleanup, + .scan = scan, + .dev_list = dev_list, + .dev_clear = dev_clear, .config_get = NULL, .config_set = config_set, .config_list = config_list, - .dev_open = hw_dev_open, - .dev_close = hw_dev_close, - .dev_acquisition_start = hw_dev_acquisition_start, - .dev_acquisition_stop = hw_dev_acquisition_stop, + .dev_open = dev_open, + .dev_close = dev_close, + .dev_acquisition_start = dev_acquisition_start, + .dev_acquisition_stop = dev_acquisition_stop, .priv = NULL, };