]> sigrok.org Git - libsigrok.git/blobdiff - hardware/tondaj-sl-814/api.c
Enforce open device before config_set()/dev_acquisition_start()
[libsigrok.git] / hardware / tondaj-sl-814 / api.c
index 3a3ea9662e9772c259c8e95f4b6f2c8c2b6cab50..bfe4c401ceac42f4fabc0f5679afa2328c39916a 100644 (file)
@@ -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 <uwe@hermann-uwe.de>
  *
 
 #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;
@@ -96,10 +94,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);
@@ -182,45 +180,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;
@@ -231,6 +228,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 {
        struct dev_context *devc;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        devc = sdi->priv;
        devc->cb_data = cb_data;