X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoder%2Fruntc.c;h=f24a180ac4eb720d1a1dc299a0697aa97dafd4c6;hb=450d475b2bfc3e73d56580e0061a508fa67972b0;hp=90c37b64b76746ed7391b8ae20c90c0703b3310e;hpb=c83a4758759625c438791d3aa5bc4c4823649157;p=sigrok-test.git diff --git a/decoder/runtc.c b/decoder/runtc.c index 90c37b6..f24a180 100644 --- a/decoder/runtc.c +++ b/decoder/runtc.c @@ -17,6 +17,8 @@ * along with this program. If not, see . */ +#include + #include #include #include @@ -68,7 +70,7 @@ struct output { const char *pd; const char *pd_id; int type; - const char *class; + const char *class_; int class_idx; const char *outfile; int outfd; @@ -324,10 +326,16 @@ static void sr_cb(const struct sr_dev_inst *sdi, const struct sr_datafeed_packet *packet, void *cb_data) { static int samplecnt = 0; + static gboolean start_sent; + const struct sr_datafeed_logic *logic; struct srd_session *sess; + const struct sr_datafeed_meta *meta; + struct sr_config *src; + GSList *l; GVariant *gvar; uint64_t samplerate; + int ret; int num_samples; struct sr_dev_driver *driver; @@ -336,26 +344,49 @@ static void sr_cb(const struct sr_dev_inst *sdi, driver = sr_dev_inst_driver_get(sdi); switch (packet->type) { + case SR_DF_META: + DBG("Received SR_DF_META"); + meta = packet->payload; + for (l = meta->config; l; l = l->next) { + src = l->data; + switch (src->key) { + case SR_CONF_SAMPLERATE: + samplerate = g_variant_get_uint64(src->data); + ret = srd_session_metadata_set(sess, + SRD_CONF_SAMPLERATE, + g_variant_new_uint64(samplerate)); + if (ret != SRD_OK) + ERR("Setting samplerate failed (meta)"); + break; + default: + /* EMPTY */ + break; + } + } + break; case SR_DF_HEADER: DBG("Received SR_DF_HEADER"); if (sr_config_get(driver, sdi, NULL, SR_CONF_SAMPLERATE, &gvar) != SR_OK) { - ERR("Getting samplerate failed"); + DBG("Getting samplerate failed (SR_DF_HEADER)"); break; } samplerate = g_variant_get_uint64(gvar); g_variant_unref(gvar); - if (srd_session_metadata_set(sess, SRD_CONF_SAMPLERATE, - g_variant_new_uint64(samplerate)) != SRD_OK) { - ERR("Setting samplerate failed"); - break; - } - if (srd_session_start(sess) != SRD_OK) { - ERR("Session start failed"); - break; - } + ret = srd_session_metadata_set(sess, SRD_CONF_SAMPLERATE, + g_variant_new_uint64(samplerate)); + if (ret != SRD_OK) + ERR("Setting samplerate failed (header)"); break; case SR_DF_LOGIC: + DBG("Received SR_DF_LOGIC"); + if (!start_sent) { + if (srd_session_start(sess) != SRD_OK) { + ERR("Session start failed"); + break; + } + start_sent = TRUE; + } logic = packet->payload; num_samples = logic->length / logic->unitsize; DBG("Received SR_DF_LOGIC (%"PRIu64" bytes, unitsize = %d).", @@ -366,6 +397,9 @@ static void sr_cb(const struct sr_dev_inst *sdi, break; case SR_DF_END: DBG("Received SR_DF_END"); +#if defined HAVE_SRD_SESSION_SEND_EOF && HAVE_SRD_SESSION_SEND_EOF + (void)srd_session_send_eof(sess); +#endif break; } @@ -544,7 +578,7 @@ static int run_testcase(const char *infile, GSList *pdlist, struct output *op) /* Resolve selected decoder's class index, so we can match. */ dec = srd_decoder_get_by_id(pd->name); - if (op->class) { + if (op->class_) { if (op->type == SRD_OUTPUT_ANN) l = dec->annotations; else if (op->type == SRD_OUTPUT_BINARY) @@ -557,7 +591,7 @@ static int run_testcase(const char *infile, GSList *pdlist, struct output *op) idx = 0; while (l) { decoder_class = l->data; - if (!strcmp(decoder_class[0], op->class)) { + if (!strcmp(decoder_class[0], op->class_)) { op->class_idx = idx; break; } @@ -566,10 +600,10 @@ static int run_testcase(const char *infile, GSList *pdlist, struct output *op) } if (op->class_idx == -1) { ERR("Output class '%s' not found in decoder %s.", - op->class, pd->name); + op->class_, pd->name); return FALSE; } - DBG("Class %s index is %d", op->class, op->class_idx); + DBG("Class %s index is %d", op->class_, op->class_idx); } sr_session_start(sr_sess); @@ -822,7 +856,7 @@ int main(int argc, char **argv) op->pd = NULL; op->pd_id = NULL; op->type = -1; - op->class = NULL; + op->class_ = NULL; op->class_idx = -1; op->outfd = 1; @@ -904,7 +938,7 @@ int main(int argc, char **argv) usage(NULL); } if (opstr[2]) - op->class = g_strdup(opstr[2]); + op->class_ = g_strdup(opstr[2]); g_strfreev(opstr); break; case 'f':