X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Flascar-el-usb%2Fapi.c;h=84daf93e3e792d20089b0efe35f75868858a6b6e;hb=a76842947faadad98572f011cb20f3220998f71b;hp=8ebb4ca0d4a3a6ba75aa420e2f31902ce0142e62;hpb=0d485e30c607b22b5f328512327e4e0fafc6cbb7;p=libsigrok.git diff --git a/hardware/lascar-el-usb/api.c b/hardware/lascar-el-usb/api.c index 8ebb4ca0..84daf93e 100644 --- a/hardware/lascar-el-usb/api.c +++ b/hardware/lascar-el-usb/api.c @@ -28,16 +28,15 @@ SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info; static struct sr_dev_driver *di = &lascar_el_usb_driver_info; static int hw_dev_close(struct sr_dev_inst *sdi); -static const int hwopts[] = { +static const int32_t hwopts[] = { SR_CONF_CONN, - 0, }; -static const int hwcaps[] = { +static const int32_t hwcaps[] = { SR_CONF_THERMOMETER, SR_CONF_HYGROMETER, + SR_CONF_DATALOG, SR_CONF_LIMIT_SAMPLES, - 0 }; /* Properly close and free all devices. */ @@ -70,17 +69,7 @@ static int clear_instances(void) static int hw_init(struct sr_context *sr_ctx) { - struct drv_context *drvc; - - if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { - sr_err("Driver context malloc failed."); - return SR_ERR_MALLOC; - } - - drvc->sr_ctx = sr_ctx; - di->priv = drvc; - - return SR_OK; + return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN); } static GSList *hw_scan(GSList *options) @@ -95,10 +84,7 @@ static GSList *hw_scan(GSList *options) (void)options; - if (!(drvc = di->priv)) { - sr_err("Driver was not initialized."); - return NULL; - } + drvc = di->priv; /* USB scan is always authoritative. */ clear_instances(); @@ -108,7 +94,7 @@ static GSList *hw_scan(GSList *options) src = l->data; switch (src->key) { case SR_CONF_CONN: - conn = src->value; + conn = g_variant_get_string(src->data, NULL); break; } } @@ -140,14 +126,7 @@ static GSList *hw_scan(GSList *options) static GSList *hw_dev_list(void) { - struct drv_context *drvc; - - if (!(drvc = di->priv)) { - sr_err("Driver was not initialized."); - return NULL; - } - - return drvc->instances; + return ((struct drv_context *)(di->priv))->instances; } static int hw_dev_open(struct sr_dev_inst *sdi) @@ -191,7 +170,6 @@ static int hw_dev_close(struct sr_dev_inst *sdi) libusb_release_interface(devc->usb->devhdl, LASCAR_INTERFACE); libusb_close(devc->usb->devhdl); devc->usb->devhdl = NULL; - g_free(devc->config); sdi->status = SR_ST_INACTIVE; @@ -213,11 +191,23 @@ static int hw_cleanup(void) return SR_OK; } -static int config_get(int id, const void **data, const struct sr_dev_inst *sdi) +static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi) { - (void)sdi; + struct dev_context *devc; + int ret; + devc = sdi->priv; switch (id) { + case SR_CONF_DATALOG: + if (!sdi) + return SR_ERR_ARG; + if ((ret = lascar_is_logging(sdi)) == -1) + return SR_ERR; + *data = g_variant_new_boolean(ret ? TRUE : FALSE); + break; + case SR_CONF_LIMIT_SAMPLES: + *data = g_variant_new_uint64(devc->limit_samples); + break; default: return SR_ERR_ARG; } @@ -225,7 +215,7 @@ static int config_get(int id, const void **data, const struct sr_dev_inst *sdi) 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; int ret; @@ -242,8 +232,17 @@ static int config_set(int id, const void *value, const struct sr_dev_inst *sdi) devc = sdi->priv; ret = SR_OK; switch (id) { + case SR_CONF_DATALOG: + if (g_variant_get_boolean(data)) { + /* Start logging. */ + ret = lascar_start_logging(sdi); + } else { + /* Stop logging. */ + ret = lascar_stop_logging(sdi); + } + break; 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; @@ -255,17 +254,19 @@ static int config_set(int id, const void *value, const struct sr_dev_inst *sdi) return ret; } -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; @@ -306,10 +307,10 @@ static float binary32_le_to_float(unsigned char *buf) static int lascar_proc_config(const struct sr_dev_inst *sdi) { struct dev_context *devc; - int ret; + int dummy, ret; devc = sdi->priv; - if (!(devc->config = lascar_get_config(devc->usb->devhdl))) + if (lascar_get_config(devc->usb->devhdl, devc->config, &dummy) != SR_OK) return SR_ERR; ret = SR_OK; @@ -345,12 +346,14 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct sr_datafeed_packet packet; - struct sr_datafeed_header header; + struct sr_datafeed_meta meta; + struct sr_config *src; struct dev_context *devc; - struct drv_context *drvc = di->priv; + struct drv_context *drvc; struct libusb_transfer *xfer_in, *xfer_out; const struct libusb_pollfd **pfd; struct timeval tv; + uint64_t interval; int ret, i; unsigned char cmd[3], resp[4], *buf; @@ -359,6 +362,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_ERR; } + drvc = di->priv; devc = sdi->priv; devc->cb_data = cb_data; @@ -368,11 +372,15 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, sr_dbg("Starting log retrieval."); /* Send header packet to the session bus. */ - sr_dbg("Sending SR_DF_HEADER."); - packet.type = SR_DF_HEADER; - packet.payload = (uint8_t *)&header; - header.feed_version = 1; + std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); + + interval = (devc->config[0x1c] | (devc->config[0x1d] << 8)) * 1000; + packet.type = SR_DF_META; + packet.payload = &meta; + src = sr_config_new(SR_CONF_SAMPLE_INTERVAL, g_variant_new_uint64(interval)); + meta.config = g_slist_append(NULL, src); sr_session_send(devc->cb_data, &packet); + g_free(src); if (devc->logged_samples == 0) { /* This ensures the frontend knows the session is done. */