X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Ftondaj-sl-814%2Fapi.c;h=444b372b156c6fe1a60b10c3ac50201dffb14fa3;hb=a5e44c3247ae64ab1a65e7c6ebe6d66c6ab0a0a1;hp=3a3ea9662e9772c259c8e95f4b6f2c8c2b6cab50;hpb=cd2f0fe22c35dcf3b010411ff6f123701be2a2d6;p=libsigrok.git diff --git a/hardware/tondaj-sl-814/api.c b/hardware/tondaj-sl-814/api.c index 3a3ea966..444b372b 100644 --- a/hardware/tondaj-sl-814/api.c +++ b/hardware/tondaj-sl-814/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 Uwe Hermann * @@ -26,17 +26,15 @@ #define SERIALCOMM "9600/8e1" -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_SOUNDLEVELMETER, SR_CONF_LIMIT_SAMPLES, SR_CONF_CONTINUOUS, - 0, }; SR_PRIV struct sr_dev_driver tondaj_sl_814_driver_info; @@ -48,6 +46,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)) @@ -58,7 +57,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); } @@ -82,6 +82,7 @@ static GSList *hw_scan(GSList *options) struct sr_probe *probe; GSList *devices, *l; const char *conn, *serialcomm; + struct sr_serial_dev_inst *serial; drvc = di->priv; drvc->instances = NULL; @@ -96,10 +97,10 @@ static GSList *hw_scan(GSList *options) } 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; default: sr_err("Unknown option %d, skipping.", src->key); @@ -122,12 +123,15 @@ static GSList *hw_scan(GSList *options) return NULL; } - if (!(devc->serial = sr_serial_dev_inst_new(conn, serialcomm))) + if (!(serial = sr_serial_dev_inst_new(conn, serialcomm))) return NULL; - if (serial_open(devc->serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) + if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) return NULL; + sdi->inst_type = SR_INST_SERIAL; + sdi->conn = serial; + sdi->priv = devc; sdi->driver = di; probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1"); @@ -149,11 +153,10 @@ static GSList *hw_dev_list(void) static int hw_dev_open(struct sr_dev_inst *sdi) { - struct dev_context *devc; + struct sr_serial_dev_inst *serial; - devc = sdi->priv; - - 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; @@ -163,12 +166,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; + struct sr_serial_dev_inst *serial; - devc = sdi->priv; - - 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; } @@ -182,45 +184,44 @@ 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) { - sr_err("Device inactive, can't set config options."); - return SR_ERR; - } + if (sdi->status != SR_ST_ACTIVE) + return SR_ERR_DEV_CLOSED; devc = sdi->priv; switch (id) { 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 hardware capability: %d.", id); - return SR_ERR_ARG; + 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; @@ -230,6 +231,10 @@ 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; devc = sdi->priv; devc->cb_data = cb_data; @@ -238,7 +243,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 500ms, or whenever some data comes in. */ - sr_source_add(devc->serial->fd, G_IO_IN, 500, + serial = sdi->conn; + sr_source_add(serial->fd, G_IO_IN, 500, tondaj_sl_814_receive_data, (void *)sdi); return SR_OK; @@ -247,7 +253,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); } SR_PRIV struct sr_dev_driver tondaj_sl_814_driver_info = {