X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Frigol-ds1xx2%2Fapi.c;h=ba59c2156af26c66e7026565617d408c76b6277f;hb=21d464a7e53efc9ac9810d9301a12b6a56fdb061;hp=bffc6ab951d0958b05f8edd9936e2ba8ef49379c;hpb=cc9fd2d29c5ff4ab2509b6bb5b33a16304fafa55;p=libsigrok.git diff --git a/hardware/rigol-ds1xx2/api.c b/hardware/rigol-ds1xx2/api.c index bffc6ab9..ba59c215 100644 --- a/hardware/rigol-ds1xx2/api.c +++ b/hardware/rigol-ds1xx2/api.c @@ -133,44 +133,30 @@ static const char *coupling[] = { static const char *supported_models[] = { "DS1052E", "DS1102E", + "DS1152E", "DS1052D", "DS1102D", + "DS1152D", }; SR_PRIV struct sr_dev_driver rigol_ds1xx2_driver_info; static struct sr_dev_driver *di = &rigol_ds1xx2_driver_info; -/* Properly close and free all devices. */ -static int clear_instances(void) +static void clear_helper(void *priv) { - struct sr_dev_inst *sdi; - struct drv_context *drvc; struct dev_context *devc; - GSList *l; - - if (!(drvc = di->priv)) - return SR_OK; - - for (l = drvc->instances; l; l = l->next) { - if (!(sdi = l->data)) - continue; - if (sdi->conn) - sr_serial_dev_inst_free(sdi->conn); + devc = priv; - if ((devc = sdi->priv)) { - g_free(devc->coupling[0]); - g_free(devc->coupling[1]); - g_free(devc->trigger_source); - g_free(devc->trigger_slope); - } - sr_dev_inst_free(sdi); - } - - g_slist_free(drvc->instances); - drvc->instances = NULL; + g_free(devc->coupling[0]); + g_free(devc->coupling[1]); + g_free(devc->trigger_source); + g_free(devc->trigger_slope); +} - return SR_OK; +static int dev_clear(void) +{ + return std_dev_clear(di, clear_helper); } static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...) @@ -192,9 +178,9 @@ static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...) return SR_OK; } -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 int probe_port(const char *port, GSList **devices) @@ -210,7 +196,7 @@ static int probe_port(const char *port, GSList **devices) char buf[256]; gchar **tokens, *channel_name; - *devices = NULL; + *devices = NULL; if (!(serial = sr_serial_dev_inst_new(port, NULL))) return SR_ERR_MALLOC; @@ -246,7 +232,7 @@ static int probe_port(const char *port, GSList **devices) return SR_ERR_NA; } - matched = has_digital = FALSE; + matched = has_digital = FALSE; for (i = 0; i < ARRAY_SIZE(supported_models); i++) { if (!strcmp(model, supported_models[i])) { matched = TRUE; @@ -266,6 +252,7 @@ static int probe_port(const char *port, GSList **devices) if (!(sdi->conn = sr_serial_dev_inst_new(port, NULL))) return SR_ERR_MALLOC; sdi->driver = di; + sdi->inst_type = SR_INST_SERIAL; if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) return SR_ERR_MALLOC; @@ -297,7 +284,7 @@ static int probe_port(const char *port, GSList **devices) return SR_OK; } -static GSList *hw_scan(GSList *options) +static GSList *scan(GSList *options) { struct drv_context *drvc; struct sr_config *src; @@ -317,13 +304,14 @@ static GSList *hw_scan(GSList *options) } } - devices = NULL; + devices = NULL; if (port) { if (probe_port(port, &devices) == SR_ERR_MALLOC) return NULL; } else { - if (!(dir = g_dir_open("/sys/class/usb/", 0, NULL))) - return NULL; + if (!(dir = g_dir_open("/sys/class/usbmisc/", 0, NULL))) + if (!(dir = g_dir_open("/sys/class/usb/", 0, NULL))) + return NULL; while ((dev_name = g_dir_read_name(dir))) { if (strncmp(dev_name, "usbtmc", 6)) continue; @@ -338,19 +326,19 @@ static GSList *hw_scan(GSList *options) g_dir_close(dir); } - /* Tack a copy of the newly found devices onto the driver list. */ - l = g_slist_copy(devices); - drvc->instances = g_slist_concat(drvc->instances, l); + /* Tack a copy of the newly found devices onto the driver list. */ + l = g_slist_copy(devices); + drvc->instances = g_slist_concat(drvc->instances, l); 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) { if (serial_open(sdi->conn, SERIAL_RDWR) != SR_OK) @@ -359,12 +347,12 @@ static int hw_dev_open(struct sr_dev_inst *sdi) if (rigol_ds1xx2_get_dev_cfg(sdi) != SR_OK) return SR_ERR; - sdi->status = SR_ST_ACTIVE; + sdi->status = SR_ST_ACTIVE; return SR_OK; } -static int hw_dev_close(struct sr_dev_inst *sdi) +static int dev_close(struct sr_dev_inst *sdi) { struct sr_serial_dev_inst *serial; @@ -377,11 +365,9 @@ static int hw_dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int hw_cleanup(void) +static int cleanup(void) { - clear_instances(); - - return SR_OK; + return dev_clear(); } static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi) @@ -414,10 +400,8 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) devc = sdi->priv; - if (sdi->status != SR_ST_ACTIVE) { - sr_err("Device inactive, can't set config options."); - return SR_ERR; - } + if (sdi->status != SR_ST_ACTIVE) + return SR_ERR_DEV_CLOSED; ret = SR_OK; switch (id) { @@ -575,7 +559,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) GSList *l; char cmd[256]; - (void)cb_data; + if (sdi->status != SR_ST_ACTIVE) + return SR_ERR_DEV_CLOSED; serial = sdi->conn; devc = sdi->priv; @@ -613,7 +598,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) sr_source_add(serial->fd, G_IO_IN, 50, rigol_ds1xx2_receive, (void *)sdi); /* 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); /* Fetch the first frame. */ if (devc->enabled_analog_probes) { @@ -660,16 +645,16 @@ SR_PRIV struct sr_dev_driver rigol_ds1xx2_driver_info = { .name = "rigol-ds1xx2", .longname = "Rigol DS1xx2", .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 = config_get, .config_set = config_set, .config_list = config_list, - .dev_open = hw_dev_open, - .dev_close = hw_dev_close, + .dev_open = dev_open, + .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, .priv = NULL,