X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fserial-dmm%2Fapi.c;h=f59702cc3648ba4b108c01651775dada164a9e70;hb=90f680ff006e5ae2fd4935bd885a14bd9927fd99;hp=cb741f936f10bc63a238a6de49127ca0815c526c;hpb=ede25f4e6f9dbf84629c0058f91014a8bab59a56;p=libsigrok.git diff --git a/hardware/serial-dmm/api.c b/hardware/serial-dmm/api.c index cb741f93..f59702cc 100644 --- a/hardware/serial-dmm/api.c +++ b/hardware/serial-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 * Copyright (C) 2012 Alexandru Gagniuc @@ -173,6 +173,7 @@ static int clear_instances(int dmm) struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; + struct sr_serial_dev_inst *serial; GSList *l; struct sr_dev_driver *di; @@ -187,7 +188,8 @@ static int clear_instances(int dmm) 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); @@ -271,7 +273,8 @@ static GSList *scan(const char *conn, const char *serialcomm, int dmm) goto scan_cleanup; } - devc->serial = serial; + sdi->inst_type = SR_INST_SERIAL; + sdi->conn = serial; sdi->priv = devc; sdi->driver = dmms[dmm].di; @@ -326,14 +329,10 @@ static GSList *hw_dev_list(int dmm) 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; @@ -343,12 +342,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; } @@ -367,7 +365,7 @@ 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."); @@ -386,9 +384,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) devc->limit_msec); break; default: - sr_err("Unknown capability: %d.", id); - return SR_ERR; - break; + return SR_ERR_NA; } return SR_OK; @@ -409,7 +405,7 @@ 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; @@ -419,6 +415,10 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data, int dmm) { 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."); @@ -439,7 +439,8 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); /* Poll every 50ms, or whenever some data comes in. */ - sr_source_add(devc->serial->fd, G_IO_IN, 50, + serial = sdi->conn; + sr_source_add(serial->fd, G_IO_IN, 50, dmms[dmm].receive_data, (void *)sdi); return SR_OK; @@ -448,7 +449,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, static int hw_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); + sdi->conn, DRIVER_LOG_DOMAIN); } /* Driver-specific API function wrappers */