]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/demo/demo.c
demo: Convert to SR_DF_ANALOG.
[libsigrok.git] / src / hardware / demo / demo.c
index cf520ca4b6a59cef15144590bc7e682469cc179c..d6b18ae7a5efe271d973465524f2a457bb7b8940 100644 (file)
@@ -98,7 +98,10 @@ struct analog_gen {
        float amplitude;
        float pattern_data[ANALOG_BUFSIZE];
        unsigned int num_samples;
-       struct sr_datafeed_analog_old packet;
+       struct sr_datafeed_analog packet;
+       struct sr_analog_encoding encoding;
+       struct sr_analog_meaning meaning;
+       struct sr_analog_spec spec;
        float avg_val; /* Average value */
        unsigned num_avgs; /* Number of samples averaged */
 };
@@ -252,19 +255,16 @@ static void generate_analog_pattern(struct analog_gen *ag, uint64_t sample_rate)
 
 static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
-       struct drv_context *drvc;
        struct dev_context *devc;
        struct sr_dev_inst *sdi;
        struct sr_channel *ch;
        struct sr_channel_group *cg, *acg;
        struct sr_config *src;
        struct analog_gen *ag;
-       GSList *devices, *l;
+       GSList *l;
        int num_logic_channels, num_analog_channels, pattern, i;
        char channel_name[16];
 
-       drvc = di->context;
-
        num_logic_channels = DEFAULT_NUM_LOGIC_CHANNELS;
        num_analog_channels = DEFAULT_NUM_ANALOG_CHANNELS;
        for (l = options; l; l = l->next) {
@@ -279,12 +279,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                }
        }
 
-       devices = NULL;
-
        sdi = g_malloc0(sizeof(struct sr_dev_inst));
        sdi->status = SR_ST_INACTIVE;
        sdi->model = g_strdup("Demo device");
-       sdi->driver = di;
 
        devc = g_malloc0(sizeof(struct dev_context));
        devc->cur_samplerate = SR_KHZ(200);
@@ -329,10 +326,11 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                        /* Every channel gets a generator struct. */
                        ag = g_malloc(sizeof(struct analog_gen));
                        ag->amplitude = DEFAULT_ANALOG_AMPLITUDE;
-                       ag->packet.channels = cg->channels;
-                       ag->packet.mq = 0;
-                       ag->packet.mqflags = 0;
-                       ag->packet.unit = SR_UNIT_VOLT;
+                       sr_analog_init(&ag->packet, &ag->encoding, &ag->meaning, &ag->spec, 0);
+                       ag->packet.meaning->channels = cg->channels;
+                       ag->packet.meaning->mq = 0;
+                       ag->packet.meaning->mqflags = 0;
+                       ag->packet.meaning->unit = SR_UNIT_VOLT;
                        ag->packet.data = ag->pattern_data;
                        ag->pattern = pattern;
                        ag->avg_val = 0.0f;
@@ -345,10 +343,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        }
 
        sdi->priv = devc;
-       devices = g_slist_append(devices, sdi);
-       drvc->instances = g_slist_append(drvc->instances, sdi);
 
-       return devices;
+       return std_scan_complete(di, g_slist_append(NULL, sdi));
 }
 
 static int dev_open(struct sr_dev_inst *sdi)
@@ -679,7 +675,7 @@ static void send_analog_packet(struct analog_gen *ag,
        unsigned int i;
 
        devc = sdi->priv;
-       packet.type = SR_DF_ANALOG_OLD;
+       packet.type = SR_DF_ANALOG;
        packet.payload = &ag->packet;
 
        if (!devc->avg) {
@@ -825,7 +821,7 @@ static int prepare_data(int fd, int revents, void *cb_data)
                        g_hash_table_iter_init(&iter, devc->ch_ag);
                        while (g_hash_table_iter_next(&iter, NULL, &value)) {
                                ag = value;
-                               packet.type = SR_DF_ANALOG_OLD;
+                               packet.type = SR_DF_ANALOG;
                                packet.payload = &ag->packet;
                                ag->packet.data = &ag->avg_val;
                                ag->packet.num_samples = 1;
@@ -858,7 +854,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        sr_session_source_add(sdi->session, -1, 0, 100,
                        prepare_data, (struct sr_dev_inst *)sdi);
 
-       std_session_send_df_header(sdi, LOG_PREFIX);
+       std_session_send_df_header(sdi);
 
        /* We use this timestamp to decide how many more samples to send. */
        devc->start_us = g_get_monotonic_time();
@@ -871,12 +867,12 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
 {
        sr_dbg("Stopping acquisition.");
        sr_session_source_remove(sdi->session, -1);
-       std_session_send_df_end(sdi, LOG_PREFIX);
+       std_session_send_df_end(sdi);
 
        return SR_OK;
 }
 
-SR_PRIV struct sr_dev_driver demo_driver_info = {
+static struct sr_dev_driver demo_driver_info = {
        .name = "demo",
        .longname = "Demo driver and pattern generator",
        .api_version = 1,
@@ -894,3 +890,4 @@ SR_PRIV struct sr_dev_driver demo_driver_info = {
        .dev_acquisition_stop = dev_acquisition_stop,
        .context = NULL,
 };
+SR_REGISTER_DEV_DRIVER(demo_driver_info);