X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=input%2Finput_chronovu_la8.c;h=241b7a0cf6e7b2e6cd14581c8771e1efdcf91c87;hb=464d12c72aa8d83acccccbbc0bc755fbb9d542c0;hp=a8095f01ab5da5ee200290e4197a7e82701cbc76;hpb=83e9d586385097b957774d150a718ebaa7fcc3c9;p=libsigrok.git diff --git a/input/input_chronovu_la8.c b/input/input_chronovu_la8.c index a8095f01..241b7a0c 100644 --- a/input/input_chronovu_la8.c +++ b/input/input_chronovu_la8.c @@ -22,6 +22,7 @@ #include #include #include +#include #define NUM_PACKETS 2048 #define PACKET_SIZE 4096 @@ -48,21 +49,21 @@ static uint64_t divcount_to_samplerate(uint8_t divcount) static int format_match(const char *filename) { if (!filename) { - g_warning("la8input: %s: filename was NULL", __func__); + sr_warn("la8input: %s: filename was NULL", __func__); // return SR_ERR; /* FIXME */ return FALSE; } if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { - g_warning("la8input: %s: input file '%s' does not exist", - __func__, filename); + sr_warn("la8input: %s: input file '%s' does not exist", + __func__, filename); // return SR_ERR; /* FIXME */ return FALSE; } if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { - g_warning("la8input: %s: input file '%s' not a regular file", - __func__, filename); + sr_warn("la8input: %s: input file '%s' not a regular file", + __func__, filename); // return SR_ERR; /* FIXME */ return FALSE; } @@ -76,12 +77,13 @@ static int format_match(const char *filename) static int init(struct sr_input *in) { - int num_probes; + int num_probes, i; + char name[SR_MAX_PROBENAME_LEN]; if (in->param && in->param[0]) { num_probes = strtoul(in->param, NULL, 10); if (num_probes < 1) { - g_warning("la8input: %s: strtoul failed", __func__); + sr_warn("la8input: %s: strtoul failed", __func__); return SR_ERR; } } else { @@ -89,7 +91,12 @@ static int init(struct sr_input *in) } /* Create a virtual device. */ - in->vdevice = sr_device_new(NULL, 0, num_probes); + in->vdevice = sr_device_new(NULL, 0); + + for (i = 0; i < num_probes; i++) { + snprintf(name, SR_MAX_PROBENAME_LEN, "%d", i); + sr_device_probe_add(in->vdevice, name); /* TODO: Check return value. */ + } return SR_OK; } @@ -98,13 +105,14 @@ static int loadfile(struct sr_input *in, const char *filename) { struct sr_datafeed_header header; struct sr_datafeed_packet packet; + struct sr_datafeed_logic logic; uint8_t buf[PACKET_SIZE], divcount; int i, fd, size, num_probes; uint64_t samplerate; /* TODO: Use glib functions! GIOChannel, g_fopen, etc. */ if ((fd = open(filename, O_RDONLY)) == -1) { - g_warning("la8input: %s: file open failed", __func__); + sr_warn("la8input: %s: file open failed", __func__); return SR_ERR; } @@ -119,44 +127,40 @@ static int loadfile(struct sr_input *in, const char *filename) close(fd); /* FIXME */ return SR_ERR; } - g_debug("la8input: %s: samplerate is %" PRIu64, __func__, samplerate); + sr_dbg("la8input: %s: samplerate is %" PRIu64, __func__, samplerate); /* Send header packet to the session bus. */ - g_debug("la8input: %s: sending SR_DF_HEADER packet", __func__); + sr_dbg("la8input: %s: sending SR_DF_HEADER packet", __func__); packet.type = SR_DF_HEADER; - packet.length = sizeof(struct sr_datafeed_header); - packet.unitsize = 0; packet.payload = &header; header.feed_version = 1; gettimeofday(&header.starttime, NULL); header.num_logic_probes = num_probes; header.num_analog_probes = 0; - header.protocol_id = SR_PROTO_RAW; header.samplerate = samplerate; sr_session_bus(in->vdevice, &packet); /* TODO: Handle trigger point. */ /* Send data packets to the session bus. */ - g_debug("la8input: %s: sending SR_DF_LOGIC data packets", __func__); + sr_dbg("la8input: %s: sending SR_DF_LOGIC data packets", __func__); packet.type = SR_DF_LOGIC; - packet.unitsize = (num_probes + 7) / 8; - packet.payload = buf; + packet.payload = &logic; + logic.unitsize = (num_probes + 7) / 8; + logic.data = buf; /* Send 8MB of total data to the session bus in small chunks. */ for (i = 0; i < NUM_PACKETS; i++) { /* TODO: Handle errors, handle incomplete reads. */ size = read(fd, buf, PACKET_SIZE); - packet.length = PACKET_SIZE; + logic.length = PACKET_SIZE; sr_session_bus(in->vdevice, &packet); } close(fd); /* FIXME */ /* Send end packet to the session bus. */ - g_debug("la8input: %s: sending SR_DF_END", __func__); + sr_dbg("la8input: %s: sending SR_DF_END", __func__); packet.type = SR_DF_END; - packet.length = 0; - packet.unitsize = 0; packet.payload = NULL; sr_session_bus(in->vdevice, &packet);