]> sigrok.org Git - libsigrok.git/blobdiff - hardware/demo/demo.c
sr: Made hwcap const
[libsigrok.git] / hardware / demo / demo.c
index 79a7a0acffe6b6fa67cf18cbc58977fd9771e09c..ca572af8a009e6892e2a6b62446997722d86b02e 100644 (file)
@@ -66,7 +66,7 @@ enum {
 /* FIXME: Should not be global. */
 SR_PRIV GIOChannel *channels[2];
 
-struct databag {
+struct context {
        int pipe_fds[2];
        uint8_t sample_generator;
        uint8_t thread_running;
@@ -76,7 +76,7 @@ struct databag {
        GTimer *timer;
 };
 
-static int hwcaps[] = {
+static const int hwcaps[] = {
        SR_HWCAP_LOGIC_ANALYZER,
        SR_HWCAP_DEMO_DEV,
        SR_HWCAP_SAMPLERATE,
@@ -210,7 +210,7 @@ static void *hw_dev_info_get(int dev_index, int dev_info_id)
        case SR_DI_CUR_SAMPLERATE:
                info = &cur_samplerate;
                break;
-       case SR_DI_PATTERNMODES:
+       case SR_DI_PATTERNS:
                info = &pattern_strings;
                break;
        }
@@ -226,7 +226,7 @@ static int hw_dev_status_get(int dev_index)
        return SR_ST_ACTIVE;
 }
 
-static int *hw_hwcap_get_all(void)
+static const int *hw_hwcap_get_all(void)
 {
        return hwcaps;
 }
@@ -285,7 +285,7 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value)
 static void samples_generator(uint8_t *buf, uint64_t size, void *data)
 {
        static uint64_t p = 0;
-       struct databag *ctx = data;
+       struct context *ctx = data;
        uint64_t i;
 
        /* TODO: Needed? */
@@ -323,7 +323,7 @@ static void samples_generator(uint8_t *buf, uint64_t size, void *data)
 /* Thread function */
 static void thread_func(void *data)
 {
-       struct databag *ctx = data;
+       struct context *ctx = data;
        uint8_t buf[BUFSIZE];
        uint64_t nb_to_send = 0;
        int bytes_written;
@@ -398,7 +398,7 @@ static int receive_data(int fd, int revents, void *cb_data)
 
        if (!thread_running && z <= 0) {
                /* Make sure we don't receive more packets. */
-               g_io_channel_close(channels[0]);
+               g_io_channel_shutdown(channels[0], FALSE, NULL);
 
                /* Send last packet. */
                packet.type = SR_DF_END;
@@ -414,10 +414,11 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data)
 {
        struct sr_datafeed_packet *packet;
        struct sr_datafeed_header *header;
-       struct databag *ctx;
+       struct sr_datafeed_meta_logic meta;
+       struct context *ctx;
 
        /* TODO: 'ctx' is never g_free()'d? */
-       if (!(ctx = g_try_malloc(sizeof(struct databag)))) {
+       if (!(ctx = g_try_malloc(sizeof(struct context)))) {
                sr_err("demo: %s: ctx malloc failed", __func__);
                return SR_ERR_MALLOC;
        }
@@ -473,9 +474,15 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data)
        packet->payload = header;
        header->feed_version = 1;
        gettimeofday(&header->starttime, NULL);
-       header->samplerate = cur_samplerate;
-       header->num_logic_probes = NUM_PROBES;
        sr_session_send(ctx->session_dev_id, packet);
+
+       /* Send metadata about the SR_DF_LOGIC packets to come. */
+       packet->type = SR_DF_META_LOGIC;
+       packet->payload = &meta;
+       meta.samplerate = cur_samplerate;
+       meta.num_probes = NUM_PROBES;
+       sr_session_send(ctx->session_dev_id, packet);
+
        g_free(header);
        g_free(packet);