]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/rdtech-um/api.c
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / src / hardware / rdtech-um / api.c
index 863ba972cd99ea16807a709a05645db1ff45bf6a..67ff37d87b6b675cc20ea826f73f4271c099080f 100644 (file)
@@ -42,8 +42,8 @@ static const uint32_t drvopts[] = {
 
 static const uint32_t devopts[] = {
        SR_CONF_CONTINUOUS,
-       SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
-       SR_CONF_LIMIT_MSEC | SR_CONF_SET,
+       SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET,
+       SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
 };
 
 static GSList *rdtech_um_scan(struct sr_dev_driver *di,
@@ -55,7 +55,9 @@ static GSList *rdtech_um_scan(struct sr_dev_driver *di,
        struct dev_context *devc;
        struct sr_dev_inst *sdi;
        size_t ch_idx;
-       const char *name;
+       const struct rdtech_um_channel_desc *pch;
+       struct sr_channel *ch;
+       struct feed_queue_analog *feed;
 
        serial = sr_serial_dev_inst_new(conn, serialcomm);
        if (serial_open(serial, SERIAL_RDWR) != SR_OK)
@@ -67,22 +69,29 @@ static GSList *rdtech_um_scan(struct sr_dev_driver *di,
                goto err_out_serial;
        }
 
-       devc = g_malloc0(sizeof(struct dev_context));
-       sdi = g_malloc0(sizeof(struct sr_dev_inst));
-
+       devc = g_malloc0(sizeof(*devc));
        sr_sw_limits_init(&devc->limits);
        devc->profile = p;
 
+       sdi = g_malloc0(sizeof(*sdi));
+       sdi->priv = devc;
        sdi->status = SR_ST_INACTIVE;
        sdi->vendor = g_strdup("RDTech");
        sdi->model = g_strdup(p->model_name);
        sdi->version = NULL;
        sdi->inst_type = SR_INST_SERIAL;
        sdi->conn = serial;
-       sdi->priv = devc;
 
-       for (ch_idx = 0; (name = p->channels[ch_idx].name); ch_idx++)
-               sr_channel_new(sdi, ch_idx, SR_CHANNEL_ANALOG, TRUE, name);
+       devc->feeds = g_malloc0(p->channel_count * sizeof(devc->feeds[0]));
+       for (ch_idx = 0; ch_idx < p->channel_count; ch_idx++) {
+               pch = &p->channels[ch_idx];
+               ch = sr_channel_new(sdi, ch_idx,
+                       SR_CHANNEL_ANALOG, TRUE, pch->name);
+               feed = feed_queue_analog_alloc(sdi, 1, pch->digits, ch);
+               feed_queue_analog_mq_unit(feed, pch->mq, 0, pch->unit);
+               feed_queue_analog_scale_offset(feed, &pch->scale, NULL);
+               devc->feeds[ch_idx] = feed;
+       }
 
        devices = g_slist_append(NULL, sdi);
        serial_close(serial);
@@ -99,32 +108,53 @@ err_out:
        return NULL;
 }
 
+static void clear_helper(struct dev_context *devc)
+{
+       const struct rdtech_um_profile *p;
+       size_t ch_idx;
+
+       if (!devc)
+               return;
+
+       p = devc->profile;
+       if (p && devc->feeds) {
+               for (ch_idx = 0; ch_idx < p->channel_count; ch_idx++)
+                       feed_queue_analog_free(devc->feeds[ch_idx]);
+               g_free(devc->feeds);
+       }
+}
+
+static int dev_clear(const struct sr_dev_driver *di)
+{
+       return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper);
+}
+
 static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
        const char *conn;
        const char *serialcomm;
-       GSList *l;
-       struct sr_config *src;
 
        conn = NULL;
        serialcomm = RDTECH_UM_SERIALCOMM;
-       for (l = options; l; l = l->next) {
-               src = l->data;
-               switch (src->key) {
-               case SR_CONF_CONN:
-                       conn = g_variant_get_string(src->data, NULL);
-                       break;
-               case SR_CONF_SERIALCOMM:
-                       serialcomm = g_variant_get_string(src->data, NULL);
-                       break;
-               }
-       }
+       (void)sr_serial_extract_options(options, &conn, &serialcomm);
        if (!conn)
                return NULL;
 
        return rdtech_um_scan(di, conn, serialcomm);
 }
 
+static int config_get(uint32_t key, GVariant **data,
+       const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
+{
+       struct dev_context *devc;
+
+       (void)cg;
+
+       devc = sdi->priv;
+
+       return sr_sw_limits_config_get(&devc->limits, key, data);
+}
+
 static int config_set(uint32_t key, GVariant *data,
        const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
@@ -167,8 +197,8 @@ static struct sr_dev_driver rdtech_um_driver_info = {
        .cleanup = std_cleanup,
        .scan = scan,
        .dev_list = std_dev_list,
-       .dev_clear = std_dev_clear,
-       .config_get = NULL,
+       .dev_clear = dev_clear,
+       .config_get = config_get,
        .config_set = config_set,
        .config_list = config_list,
        .dev_open = std_serial_dev_open,