X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=input%2Fchronovu_la8.c;h=c4b3b403be3f3ceb94c5c5a0fcb05a6e56f0e1b4;hb=41d9427f27f8d175fb0a0259c4e4507ca818b616;hp=79f83cc916345ac7be7d9e1bb16d171902f355bb;hpb=f366e86c68071fa7888259aa3963b213caa81b51;p=libsigrok.git diff --git a/input/chronovu_la8.c b/input/chronovu_la8.c index 79f83cc9..c4b3b403 100644 --- a/input/chronovu_la8.c +++ b/input/chronovu_la8.c @@ -22,8 +22,8 @@ #include #include #include -#include "sigrok.h" -#include "sigrok-internal.h" +#include "libsigrok.h" +#include "libsigrok-internal.h" #define NUM_PACKETS 2048 #define PACKET_SIZE 4096 @@ -94,26 +94,33 @@ static int format_match(const char *filename) static int init(struct sr_input *in) { + struct sr_probe *probe; int num_probes, i; char name[SR_MAX_PROBENAME_LEN + 1]; - - if (in->param && in->param[0]) { - num_probes = strtoul(in->param, NULL, 10); - if (num_probes < 1) { - sr_err("la8 in: %s: strtoul failed", __func__); - return SR_ERR; + char *param; + + num_probes = DEFAULT_NUM_PROBES; + + if (in->param) { + param = g_hash_table_lookup(in->param, "numprobes"); + if (param) { + num_probes = strtoul(param, NULL, 10); + if (num_probes < 1) { + sr_err("la8 in: %s: strtoul failed", __func__); + return SR_ERR; + } } - } else { - num_probes = DEFAULT_NUM_PROBES; } /* Create a virtual device. */ - in->vdev = sr_dev_new(NULL, 0); + in->sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, NULL, NULL, NULL); for (i = 0; i < num_probes; i++) { snprintf(name, SR_MAX_PROBENAME_LEN, "%d", i); /* TODO: Check return value. */ - sr_dev_probe_add(in->vdev, name); + if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, name))) + return SR_ERR; + in->sdi->probes = g_slist_append(in->sdi->probes, probe); } return SR_OK; @@ -135,7 +142,7 @@ static int loadfile(struct sr_input *in, const char *filename) return SR_ERR; } - num_probes = g_slist_length(in->vdev->probes); + num_probes = g_slist_length(in->sdi->probes); /* Seek to the end of the file, and read the divcount byte. */ divcount = 0x00; /* TODO: Don't hardcode! */ @@ -154,14 +161,14 @@ static int loadfile(struct sr_input *in, const char *filename) packet.payload = &header; header.feed_version = 1; gettimeofday(&header.starttime, NULL); - sr_session_send(in->vdev, &packet); + sr_session_send(in->sdi, &packet); /* Send metadata about the SR_DF_LOGIC packets to come. */ packet.type = SR_DF_META_LOGIC; packet.payload = &meta; meta.samplerate = samplerate; meta.num_probes = num_probes; - sr_session_send(in->vdev, &packet); + sr_session_send(in->sdi, &packet); /* TODO: Handle trigger point. */ @@ -177,7 +184,7 @@ static int loadfile(struct sr_input *in, const char *filename) /* TODO: Handle errors, handle incomplete reads. */ size = read(fd, buf, PACKET_SIZE); logic.length = size; - sr_session_send(in->vdev, &packet); + sr_session_send(in->sdi, &packet); } close(fd); /* FIXME */ @@ -185,7 +192,7 @@ static int loadfile(struct sr_input *in, const char *filename) sr_dbg("la8 in: %s: sending SR_DF_END", __func__); packet.type = SR_DF_END; packet.payload = NULL; - sr_session_send(in->vdev, &packet); + sr_session_send(in->sdi, &packet); return SR_OK; }