use new datafeed packet format

This commit is contained in:
Bert Vermeulen 2011-06-19 14:28:50 +02:00
parent 38ab3ee79d
commit 9c939c5132
13 changed files with 206 additions and 151 deletions

View File

@ -98,7 +98,7 @@ static const char *firmware_files[] = {
"asix-sigma-phasor.fw", /* Frequency counter */ "asix-sigma-phasor.fw", /* Frequency counter */
}; };
static void hw_stop_acquisition(int device_index, gpointer session_device_id); static void hw_stop_acquisition(int device_index, gpointer session_data);
static int sigma_read(void *buf, size_t size, struct sigma *sigma) static int sigma_read(void *buf, size_t size, struct sigma *sigma)
{ {
@ -415,6 +415,7 @@ static int hw_init(const char *deviceinfo)
goto free; goto free;
sigma->cur_samplerate = 0; sigma->cur_samplerate = 0;
sigma->period_ps = 0;
sigma->limit_msec = 0; sigma->limit_msec = 0;
sigma->cur_firmware = -1; sigma->cur_firmware = -1;
sigma->num_probes = 0; sigma->num_probes = 0;
@ -585,6 +586,7 @@ static int set_samplerate(struct sr_device_instance *sdi,
} }
sigma->cur_samplerate = samplerate; sigma->cur_samplerate = samplerate;
sigma->period_ps = 1000000000000 / samplerate;
sigma->samples_per_event = 16 / sigma->num_probes; sigma->samples_per_event = 16 / sigma->num_probes;
sigma->state.state = SIGMA_IDLE; sigma->state.state = SIGMA_IDLE;
@ -841,13 +843,14 @@ static int get_trigger_offset(uint16_t *samples, uint16_t last_sample,
*/ */
static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
uint16_t *lastsample, int triggerpos, uint16_t *lastsample, int triggerpos,
uint16_t limit_chunk, void *user_data) uint16_t limit_chunk, void *session_data)
{ {
struct sr_device_instance *sdi = user_data; struct sr_device_instance *sdi = session_data;
struct sigma *sigma = sdi->priv; struct sigma *sigma = sdi->priv;
uint16_t tsdiff, ts; uint16_t tsdiff, ts;
uint16_t samples[65536 * sigma->samples_per_event]; uint16_t samples[65536 * sigma->samples_per_event];
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
int i, j, k, l, numpad, tosend; int i, j, k, l, numpad, tosend;
size_t n = 0, sent = 0; size_t n = 0, sent = 0;
int clustersize = EVENTS_PER_CLUSTER * sigma->samples_per_event; int clustersize = EVENTS_PER_CLUSTER * sigma->samples_per_event;
@ -892,9 +895,13 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
tosend = MIN(2048, n - sent); tosend = MIN(2048, n - sent);
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
packet.length = tosend * sizeof(uint16_t); /* TODO: fill in timeoffset and duration */
packet.unitsize = 2; packet.timeoffset = 0;
packet.payload = samples + sent; packet.duration = 0;
packet.payload = &logic;
logic.length = tosend * sizeof(uint16_t);
logic.unitsize = 2;
logic.data = samples + sent;
sr_session_bus(sigma->session_id, &packet); sr_session_bus(sigma->session_id, &packet);
sent += tosend; sent += tosend;
@ -936,9 +943,13 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
if (tosend > 0) { if (tosend > 0) {
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
packet.length = tosend * sizeof(uint16_t); /* TODO: fill in timeoffset and duration */
packet.unitsize = 2; packet.timeoffset = 0;
packet.payload = samples; packet.duration = 0;
packet.payload = &logic;
logic.length = tosend * sizeof(uint16_t);
logic.unitsize = 2;
logic.data = samples;
sr_session_bus(sigma->session_id, &packet); sr_session_bus(sigma->session_id, &packet);
sent += tosend; sent += tosend;
@ -947,8 +958,9 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
/* Only send trigger if explicitly enabled. */ /* Only send trigger if explicitly enabled. */
if (sigma->use_triggers) { if (sigma->use_triggers) {
packet.type = SR_DF_TRIGGER; packet.type = SR_DF_TRIGGER;
packet.length = 0; /* TODO: fill in timeoffset only */
packet.payload = 0; packet.timeoffset = 0;
packet.duration = 0;
sr_session_bus(sigma->session_id, &packet); sr_session_bus(sigma->session_id, &packet);
} }
} }
@ -958,9 +970,13 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
if (tosend > 0) { if (tosend > 0) {
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
packet.length = tosend * sizeof(uint16_t); /* TODO: fill in timeoffset and duration */
packet.unitsize = 2; packet.timeoffset = 0;
packet.payload = samples + sent; packet.duration = 0;
packet.payload = &logic;
logic.length = tosend * sizeof(uint16_t);
logic.unitsize = 2;
logic.data = samples + sent;
sr_session_bus(sigma->session_id, &packet); sr_session_bus(sigma->session_id, &packet);
} }
@ -970,9 +986,9 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
return SR_OK; return SR_OK;
} }
static int receive_data(int fd, int revents, void *user_data) static int receive_data(int fd, int revents, void *session_data)
{ {
struct sr_device_instance *sdi = user_data; struct sr_device_instance *sdi = session_data;
struct sigma *sigma = sdi->priv; struct sigma *sigma = sdi->priv;
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
const int chunks_per_read = 32; const int chunks_per_read = 32;
@ -999,7 +1015,7 @@ static int receive_data(int fd, int revents, void *user_data)
if (running_msec < sigma->limit_msec && numchunks < 32767) if (running_msec < sigma->limit_msec && numchunks < 32767)
return FALSE; return FALSE;
hw_stop_acquisition(sdi->index, user_data); hw_stop_acquisition(sdi->index, session_data);
return FALSE; return FALSE;
@ -1007,7 +1023,6 @@ static int receive_data(int fd, int revents, void *user_data)
if (sigma->state.chunks_downloaded >= numchunks) { if (sigma->state.chunks_downloaded >= numchunks) {
/* End of samples. */ /* End of samples. */
packet.type = SR_DF_END; packet.type = SR_DF_END;
packet.length = 0;
sr_session_bus(sigma->session_id, &packet); sr_session_bus(sigma->session_id, &packet);
sigma->state.state = SIGMA_IDLE; sigma->state.state = SIGMA_IDLE;
@ -1046,12 +1061,12 @@ static int receive_data(int fd, int revents, void *user_data)
&sigma->state.lastts, &sigma->state.lastts,
&sigma->state.lastsample, &sigma->state.lastsample,
sigma->state.triggerpos & 0x1ff, sigma->state.triggerpos & 0x1ff,
limit_chunk, user_data); limit_chunk, session_data);
else else
decode_chunk_ts(buf + (i * CHUNK_SIZE), decode_chunk_ts(buf + (i * CHUNK_SIZE),
&sigma->state.lastts, &sigma->state.lastts,
&sigma->state.lastsample, &sigma->state.lastsample,
-1, limit_chunk, user_data); -1, limit_chunk, session_data);
++sigma->state.chunks_downloaded; ++sigma->state.chunks_downloaded;
} }
@ -1216,7 +1231,7 @@ static int build_basic_trigger(struct triggerlut *lut, struct sigma *sigma)
return SR_OK; return SR_OK;
} }
static int hw_start_acquisition(int device_index, gpointer session_device_id) static int hw_start_acquisition(int device_index, gpointer session_data)
{ {
struct sr_device_instance *sdi; struct sr_device_instance *sdi;
struct sigma *sigma; struct sigma *sigma;
@ -1228,7 +1243,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
struct triggerinout triggerinout_conf; struct triggerinout triggerinout_conf;
struct triggerlut lut; struct triggerlut lut;
session_device_id = session_device_id; session_data = session_data;
if (!(sdi = sr_get_device_instance(device_instances, device_index))) if (!(sdi = sr_get_device_instance(device_instances, device_index)))
return SR_ERR; return SR_ERR;
@ -1313,19 +1328,17 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
gettimeofday(&sigma->start_tv, 0); gettimeofday(&sigma->start_tv, 0);
sigma_set_register(WRITE_MODE, 0x0d, sigma); sigma_set_register(WRITE_MODE, 0x0d, sigma);
sigma->session_id = session_device_id; sigma->session_id = session_data;
/* Send header packet to the session bus. */ /* Send header packet to the session bus. */
packet.type = SR_DF_HEADER; packet.type = SR_DF_HEADER;
packet.length = sizeof(struct sr_datafeed_header);
packet.payload = &header; packet.payload = &header;
header.feed_version = 1; header.feed_version = 1;
gettimeofday(&header.starttime, NULL); gettimeofday(&header.starttime, NULL);
header.samplerate = sigma->cur_samplerate; header.samplerate = sigma->cur_samplerate;
header.protocol_id = SR_PROTO_RAW;
header.num_logic_probes = sigma->num_probes; header.num_logic_probes = sigma->num_probes;
header.num_analog_probes = 0; header.num_analog_probes = 0;
sr_session_bus(session_device_id, &packet); sr_session_bus(session_data, &packet);
/* Add capture source. */ /* Add capture source. */
sr_source_add(0, G_IO_IN, 10, receive_data, sdi); sr_source_add(0, G_IO_IN, 10, receive_data, sdi);
@ -1335,7 +1348,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
return SR_OK; return SR_OK;
} }
static void hw_stop_acquisition(int device_index, gpointer session_device_id) static void hw_stop_acquisition(int device_index, gpointer session_data)
{ {
struct sr_device_instance *sdi; struct sr_device_instance *sdi;
struct sigma *sigma; struct sigma *sigma;
@ -1346,7 +1359,7 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id)
sigma = sdi->priv; sigma = sdi->priv;
session_device_id = session_device_id; session_data = session_data;
/* Stop acquisition. */ /* Stop acquisition. */
sigma_set_register(WRITE_MODE, 0x11, sigma); sigma_set_register(WRITE_MODE, 0x11, sigma);

View File

@ -176,6 +176,7 @@ struct sigma_state {
struct sigma { struct sigma {
struct ftdi_context ftdic; struct ftdi_context ftdic;
uint64_t cur_samplerate; uint64_t cur_samplerate;
uint64_t period_ps;
uint64_t limit_msec; uint64_t limit_msec;
struct timeval start_tv; struct timeval start_tv;
int cur_firmware; int cur_firmware;

View File

@ -48,6 +48,9 @@ struct la8 {
/** The currently configured samplerate of the device. */ /** The currently configured samplerate of the device. */
uint64_t cur_samplerate; uint64_t cur_samplerate;
/** period in picoseconds corresponding to the samplerate */
uint64_t period_ps;
/** The current sampling limit (in ms). */ /** The current sampling limit (in ms). */
uint64_t limit_msec; uint64_t limit_msec;
@ -123,7 +126,7 @@ static int capabilities[] = {
/* Function prototypes. */ /* Function prototypes. */
static int la8_close_usb_reset_sequencer(struct la8 *la8); static int la8_close_usb_reset_sequencer(struct la8 *la8);
static void hw_stop_acquisition(int device_index, gpointer session_device_id); static void hw_stop_acquisition(int device_index, gpointer session_data);
static int la8_reset(struct la8 *la8); static int la8_reset(struct la8 *la8);
static void fill_supported_samplerates_if_needed(void) static void fill_supported_samplerates_if_needed(void)
@ -479,6 +482,7 @@ static int hw_init(const char *deviceinfo)
/* Set some sane defaults. */ /* Set some sane defaults. */
la8->ftdic = NULL; la8->ftdic = NULL;
la8->cur_samplerate = SR_MHZ(100); /* 100MHz == max. samplerate */ la8->cur_samplerate = SR_MHZ(100); /* 100MHz == max. samplerate */
la8->period_ps = 10000;
la8->limit_msec = 0; la8->limit_msec = 0;
la8->limit_samples = 0; la8->limit_samples = 0;
la8->session_id = NULL; la8->session_id = NULL;
@ -633,6 +637,7 @@ static int set_samplerate(struct sr_device_instance *sdi, uint64_t samplerate)
/* Set the new samplerate. */ /* Set the new samplerate. */
la8->cur_samplerate = samplerate; la8->cur_samplerate = samplerate;
la8->period_ps = 1000000000000 / samplerate;
sr_dbg("la8: samplerate set to %" PRIu64 "Hz", la8->cur_samplerate); sr_dbg("la8: samplerate set to %" PRIu64 "Hz", la8->cur_samplerate);
@ -879,6 +884,7 @@ static void send_block_to_session_bus(struct la8 *la8, int block)
int i; int i;
uint8_t sample, expected_sample; uint8_t sample, expected_sample;
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
int trigger_point; /* Relative trigger point (in this block). */ int trigger_point; /* Relative trigger point (in this block). */
/* Note: No sanity checks on la8/block, caller is responsible. */ /* Note: No sanity checks on la8/block, caller is responsible. */
@ -914,9 +920,12 @@ static void send_block_to_session_bus(struct la8 *la8, int block)
sr_spew("la8: sending SR_DF_LOGIC packet (%d bytes) for " sr_spew("la8: sending SR_DF_LOGIC packet (%d bytes) for "
"block %d", BS, block); "block %d", BS, block);
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
packet.length = BS; packet.timeoffset = block * BS * la8->period_ps;
packet.unitsize = 1; packet.duration = BS * la8->period_ps;
packet.payload = la8->final_buf + (block * BS); packet.payload = &logic;
logic.length = BS;
logic.unitsize = 1;
logic.data = la8->final_buf + (block * BS);
sr_session_bus(la8->session_id, &packet); sr_session_bus(la8->session_id, &packet);
return; return;
} }
@ -936,9 +945,12 @@ static void send_block_to_session_bus(struct la8 *la8, int block)
sr_spew("la8: sending pre-trigger SR_DF_LOGIC packet, " sr_spew("la8: sending pre-trigger SR_DF_LOGIC packet, "
"start = %d, length = %d", block * BS, trigger_point); "start = %d, length = %d", block * BS, trigger_point);
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
packet.length = trigger_point; packet.timeoffset = block * BS * la8->period_ps;
packet.unitsize = 1; packet.duration = trigger_point * la8->period_ps;
packet.payload = la8->final_buf + (block * BS); packet.payload = &logic;
logic.length = trigger_point;
logic.unitsize = 1;
logic.data = la8->final_buf + (block * BS);
sr_session_bus(la8->session_id, &packet); sr_session_bus(la8->session_id, &packet);
} }
@ -946,8 +958,8 @@ static void send_block_to_session_bus(struct la8 *la8, int block)
sr_spew("la8: sending SR_DF_TRIGGER packet, sample = %d", sr_spew("la8: sending SR_DF_TRIGGER packet, sample = %d",
(block * BS) + trigger_point); (block * BS) + trigger_point);
packet.type = SR_DF_TRIGGER; packet.type = SR_DF_TRIGGER;
packet.length = 0; packet.timeoffset = (block * BS + trigger_point) * la8->period_ps;
packet.unitsize = 0; packet.duration = 0;
packet.payload = NULL; packet.payload = NULL;
sr_session_bus(la8->session_id, &packet); sr_session_bus(la8->session_id, &packet);
@ -958,14 +970,17 @@ static void send_block_to_session_bus(struct la8 *la8, int block)
"start = %d, length = %d", "start = %d, length = %d",
(block * BS) + trigger_point, BS - trigger_point); (block * BS) + trigger_point, BS - trigger_point);
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
packet.length = BS - trigger_point; packet.timeoffset = (block * BS + trigger_point) * la8->period_ps;
packet.unitsize = 1; packet.duration = (BS - trigger_point) * la8->period_ps;
packet.payload = la8->final_buf + (block * BS) + trigger_point; packet.payload = &logic;
logic.length = BS - trigger_point;
logic.unitsize = 1;
logic.data = la8->final_buf + (block * BS) + trigger_point;
sr_session_bus(la8->session_id, &packet); sr_session_bus(la8->session_id, &packet);
} }
} }
static int receive_data(int fd, int revents, void *user_data) static int receive_data(int fd, int revents, void *session_data)
{ {
int i, ret; int i, ret;
struct sr_device_instance *sdi; struct sr_device_instance *sdi;
@ -975,7 +990,7 @@ static int receive_data(int fd, int revents, void *user_data)
fd = fd; fd = fd;
revents = revents; revents = revents;
if (!(sdi = user_data)) { if (!(sdi = session_data)) {
sr_err("la8: %s: user_data was NULL", __func__); sr_err("la8: %s: user_data was NULL", __func__);
return FALSE; return FALSE;
} }
@ -988,7 +1003,7 @@ static int receive_data(int fd, int revents, void *user_data)
/* Get one block of data. */ /* Get one block of data. */
if ((ret = la8_read_block(la8)) < 0) { if ((ret = la8_read_block(la8)) < 0) {
sr_err("la8: %s: la8_read_block error: %d", __func__, ret); sr_err("la8: %s: la8_read_block error: %d", __func__, ret);
hw_stop_acquisition(sdi->index, user_data); hw_stop_acquisition(sdi->index, session_data);
return FALSE; return FALSE;
} }
@ -1004,13 +1019,13 @@ static int receive_data(int fd, int revents, void *user_data)
for (i = 0; i < NUM_BLOCKS; i++) for (i = 0; i < NUM_BLOCKS; i++)
send_block_to_session_bus(la8, i); send_block_to_session_bus(la8, i);
hw_stop_acquisition(sdi->index, user_data); hw_stop_acquisition(sdi->index, session_data);
// return FALSE; /* FIXME? */ // return FALSE; /* FIXME? */
return TRUE; return TRUE;
} }
static int hw_start_acquisition(int device_index, gpointer session_device_id) static int hw_start_acquisition(int device_index, gpointer session_data)
{ {
struct sr_device_instance *sdi; struct sr_device_instance *sdi;
struct la8 *la8; struct la8 *la8;
@ -1061,21 +1076,18 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
sr_dbg("la8: acquisition started successfully"); sr_dbg("la8: acquisition started successfully");
la8->session_id = session_device_id; la8->session_id = session_data;
/* Send header packet to the session bus. */ /* Send header packet to the session bus. */
sr_dbg("la8: %s: sending SR_DF_HEADER", __func__); sr_dbg("la8: %s: sending SR_DF_HEADER", __func__);
packet.type = SR_DF_HEADER; packet.type = SR_DF_HEADER;
packet.length = sizeof(struct sr_datafeed_header);
packet.unitsize = 0;
packet.payload = &header; packet.payload = &header;
header.feed_version = 1; header.feed_version = 1;
gettimeofday(&header.starttime, NULL); gettimeofday(&header.starttime, NULL);
header.samplerate = la8->cur_samplerate; header.samplerate = la8->cur_samplerate;
header.protocol_id = SR_PROTO_RAW;
header.num_logic_probes = NUM_PROBES; header.num_logic_probes = NUM_PROBES;
header.num_analog_probes = 0; header.num_analog_probes = 0;
sr_session_bus(session_device_id, &packet); sr_session_bus(session_data, &packet);
/* Time when we should be done (for detecting trigger timeouts). */ /* Time when we should be done (for detecting trigger timeouts). */
la8->done = (la8->divcount + 1) * 0.08388608 + time(NULL) la8->done = (la8->divcount + 1) * 0.08388608 + time(NULL)
@ -1089,7 +1101,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
return SR_OK; return SR_OK;
} }
static void hw_stop_acquisition(int device_index, gpointer session_device_id) static void hw_stop_acquisition(int device_index, gpointer session_data)
{ {
struct sr_device_instance *sdi; struct sr_device_instance *sdi;
struct la8 *la8; struct la8 *la8;
@ -1110,10 +1122,7 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id)
/* Send end packet to the session bus. */ /* Send end packet to the session bus. */
sr_dbg("la8: %s: sending SR_DF_END", __func__); sr_dbg("la8: %s: sending SR_DF_END", __func__);
packet.type = SR_DF_END; packet.type = SR_DF_END;
packet.length = 0; sr_session_bus(session_data, &packet);
packet.unitsize = 0;
packet.payload = NULL;
sr_session_bus(session_device_id, &packet);
} }
struct sr_device_plugin chronovu_la8_plugin_info = { struct sr_device_plugin chronovu_la8_plugin_info = {

View File

@ -73,7 +73,7 @@ struct databag {
uint8_t thread_running; uint8_t thread_running;
uint64_t samples_counter; uint64_t samples_counter;
int device_index; int device_index;
gpointer session_device_id; gpointer session_data;
GTimer *timer; GTimer *timer;
}; };
@ -116,13 +116,14 @@ static uint8_t pattern_sigrok[] = {
/* List of struct sr_device_instance, maintained by opendev()/closedev(). */ /* List of struct sr_device_instance, maintained by opendev()/closedev(). */
static GSList *device_instances = NULL; static GSList *device_instances = NULL;
static uint64_t cur_samplerate = SR_KHZ(200); static uint64_t cur_samplerate = SR_KHZ(200);
static uint64_t period_ps = 5000000;
static uint64_t limit_samples = 0; static uint64_t limit_samples = 0;
static uint64_t limit_msec = 0; static uint64_t limit_msec = 0;
static int default_pattern = PATTERN_SIGROK; static int default_pattern = PATTERN_SIGROK;
static GThread *my_thread; static GThread *my_thread;
static int thread_running; static int thread_running;
static void hw_stop_acquisition(int device_index, gpointer session_device_id); static void hw_stop_acquisition(int device_index, gpointer session_data);
static int hw_init(const char *deviceinfo) static int hw_init(const char *deviceinfo)
{ {
@ -224,6 +225,7 @@ static int hw_set_configuration(int device_index, int capability, void *value)
ret = SR_OK; ret = SR_OK;
} else if (capability == SR_HWCAP_SAMPLERATE) { } else if (capability == SR_HWCAP_SAMPLERATE) {
cur_samplerate = *(uint64_t *)value; cur_samplerate = *(uint64_t *)value;
period_ps = 1000000000000 / cur_samplerate;
sr_dbg("demo: %s: setting samplerate to %" PRIu64, __func__, sr_dbg("demo: %s: setting samplerate to %" PRIu64, __func__,
cur_samplerate); cur_samplerate);
ret = SR_OK; ret = SR_OK;
@ -348,10 +350,12 @@ static void thread_func(void *data)
} }
/* Callback handling data */ /* Callback handling data */
static int receive_data(int fd, int revents, void *user_data) static int receive_data(int fd, int revents, void *session_data)
{ {
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
char c[BUFSIZE]; struct sr_datafeed_logic logic;
static uint64_t samples_received = 0;
unsigned char c[BUFSIZE];
gsize z; gsize z;
/* Avoid compiler warnings. */ /* Avoid compiler warnings. */
@ -364,10 +368,14 @@ static int receive_data(int fd, int revents, void *user_data)
if (z > 0) { if (z > 0) {
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
packet.length = z; packet.payload = &logic;
packet.unitsize = 1; packet.timeoffset = samples_received * period_ps;
packet.payload = c; packet.duration = z * period_ps;
sr_session_bus(user_data, &packet); logic.length = z;
logic.unitsize = 1;
logic.data = c;
sr_session_bus(session_data, &packet);
samples_received += z;
} }
} while (z > 0); } while (z > 0);
@ -377,7 +385,7 @@ static int receive_data(int fd, int revents, void *user_data)
/* Send last packet. */ /* Send last packet. */
packet.type = SR_DF_END; packet.type = SR_DF_END;
sr_session_bus(user_data, &packet); sr_session_bus(session_data, &packet);
return FALSE; return FALSE;
} }
@ -385,7 +393,7 @@ static int receive_data(int fd, int revents, void *user_data)
return TRUE; return TRUE;
} }
static int hw_start_acquisition(int device_index, gpointer session_device_id) static int hw_start_acquisition(int device_index, gpointer session_data)
{ {
struct sr_datafeed_packet *packet; struct sr_datafeed_packet *packet;
struct sr_datafeed_header *header; struct sr_datafeed_header *header;
@ -398,7 +406,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
} }
mydata->sample_generator = default_pattern; mydata->sample_generator = default_pattern;
mydata->session_device_id = session_device_id; mydata->session_data = session_data;
mydata->device_index = device_index; mydata->device_index = device_index;
mydata->samples_counter = 0; mydata->samples_counter = 0;
@ -420,7 +428,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
g_io_channel_set_buffered(channels[1], FALSE); g_io_channel_set_buffered(channels[1], FALSE);
sr_source_add(mydata->pipe_fds[0], G_IO_IN | G_IO_ERR, 40, sr_source_add(mydata->pipe_fds[0], G_IO_IN | G_IO_ERR, 40,
receive_data, session_device_id); receive_data, session_data);
/* Run the demo thread. */ /* Run the demo thread. */
g_thread_init(NULL); g_thread_init(NULL);
@ -445,26 +453,26 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
} }
packet->type = SR_DF_HEADER; packet->type = SR_DF_HEADER;
packet->length = sizeof(struct sr_datafeed_header); packet->payload = header;
packet->payload = (unsigned char *)header; packet->timeoffset = 0;
packet->duration = 0;
header->feed_version = 1; header->feed_version = 1;
gettimeofday(&header->starttime, NULL); gettimeofday(&header->starttime, NULL);
header->samplerate = cur_samplerate; header->samplerate = cur_samplerate;
header->protocol_id = SR_PROTO_RAW;
header->num_logic_probes = NUM_PROBES; header->num_logic_probes = NUM_PROBES;
header->num_analog_probes = 0; header->num_analog_probes = 0;
sr_session_bus(session_device_id, packet); sr_session_bus(session_data, packet);
g_free(header); g_free(header);
g_free(packet); g_free(packet);
return SR_OK; return SR_OK;
} }
static void hw_stop_acquisition(int device_index, gpointer session_device_id) static void hw_stop_acquisition(int device_index, gpointer session_data)
{ {
/* Avoid compiler warnings. */ /* Avoid compiler warnings. */
device_index = device_index; device_index = device_index;
session_device_id = session_device_id; session_data = session_data;
/* Stop generate thread. */ /* Stop generate thread. */
thread_running = 0; thread_running = 0;

View File

@ -180,6 +180,7 @@ static struct ols_device *ols_device_new(void)
ols->trigger_at = -1; ols->trigger_at = -1;
ols->probe_mask = 0xffffffff; ols->probe_mask = 0xffffffff;
ols->cur_samplerate = SR_KHZ(200); ols->cur_samplerate = SR_KHZ(200);
ols->period_ps = 5000000;
return ols; return ols;
} }
@ -553,6 +554,7 @@ static int set_configuration_samplerate(struct sr_device_instance *sdi,
return SR_ERR_SAMPLERATE; return SR_ERR_SAMPLERATE;
ols->cur_samplerate = samplerate; ols->cur_samplerate = samplerate;
ols->period_ps = 1000000000000 / samplerate;
if (samplerate > CLOCK_RATE) { if (samplerate > CLOCK_RATE) {
ols->flag_reg |= FLAG_DEMUX; ols->flag_reg |= FLAG_DEMUX;
ols->cur_samplerate_divider = (CLOCK_RATE * 2 / samplerate) - 1; ols->cur_samplerate_divider = (CLOCK_RATE * 2 / samplerate) - 1;
@ -610,9 +612,10 @@ static int hw_set_configuration(int device_index, int capability, void *value)
return ret; return ret;
} }
static int receive_data(int fd, int revents, void *user_data) static int receive_data(int fd, int revents, void *session_data)
{ {
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
struct sr_device_instance *sdi; struct sr_device_instance *sdi;
struct ols_device *ols; struct ols_device *ols;
GSList *l; GSList *l;
@ -640,7 +643,7 @@ static int receive_data(int fd, int revents, void *user_data)
* finished. We'll double that to 30ms to be sure... * finished. We'll double that to 30ms to be sure...
*/ */
sr_source_remove(fd); sr_source_remove(fd);
sr_source_add(fd, G_IO_IN, 30, receive_data, user_data); sr_source_add(fd, G_IO_IN, 30, receive_data, session_data);
ols->raw_sample_buf = g_try_malloc(ols->limit_samples * 4); ols->raw_sample_buf = g_try_malloc(ols->limit_samples * 4);
if (!ols->raw_sample_buf) { if (!ols->raw_sample_buf) {
sr_err("ols: %s: ols->raw_sample_buf malloc failed", sr_err("ols: %s: ols->raw_sample_buf malloc failed",
@ -759,41 +762,55 @@ static int receive_data(int fd, int revents, void *user_data)
if (ols->trigger_at > 0) { if (ols->trigger_at > 0) {
/* there are pre-trigger samples, send those first */ /* there are pre-trigger samples, send those first */
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
packet.length = ols->trigger_at * 4; packet.timeoffset = 0;
packet.unitsize = 4; packet.duration = ols->trigger_at * ols->period_ps;
packet.payload = ols->raw_sample_buf; packet.payload = &logic;
sr_session_bus(user_data, &packet); logic.length = ols->trigger_at * 4;
logic.unitsize = 4;
logic.data = ols->raw_sample_buf;
sr_session_bus(session_data, &packet);
} }
/* send the trigger */
packet.type = SR_DF_TRIGGER; packet.type = SR_DF_TRIGGER;
packet.length = 0; packet.timeoffset = ols->trigger_at * ols->period_ps;
sr_session_bus(user_data, &packet); packet.duration = 0;
sr_session_bus(session_data, &packet);
/* send post-trigger samples */
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
packet.length = (ols->limit_samples * 4) - (ols->trigger_at * 4); packet.timeoffset = ols->trigger_at * ols->period_ps;
packet.unitsize = 4; packet.duration = (ols->limit_samples - ols->trigger_at) * ols->period_ps;
packet.payload = ols->raw_sample_buf + ols->trigger_at * 4; packet.payload = &logic;
sr_session_bus(user_data, &packet); logic.length = (ols->limit_samples * 4) - (ols->trigger_at * 4);
logic.unitsize = 4;
logic.data = ols->raw_sample_buf + ols->trigger_at * 4;
sr_session_bus(session_data, &packet);
} else { } else {
/* no trigger was used */
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
packet.length = ols->limit_samples * 4; packet.timeoffset = 0;
packet.unitsize = 4; packet.duration = ols->limit_samples * ols->period_ps;
packet.payload = ols->raw_sample_buf; packet.payload = &logic;
sr_session_bus(user_data, &packet); logic.length = ols->limit_samples * 4;
logic.unitsize = 4;
logic.data = ols->raw_sample_buf;
sr_session_bus(session_data, &packet);
} }
g_free(ols->raw_sample_buf); g_free(ols->raw_sample_buf);
serial_flush(fd); serial_flush(fd);
serial_close(fd); serial_close(fd);
packet.type = SR_DF_END; packet.type = SR_DF_END;
packet.length = 0; packet.timeoffset = ols->limit_samples * ols->period_ps;
sr_session_bus(user_data, &packet); packet.duration = 0;
sr_session_bus(session_data, &packet);
} }
return TRUE; return TRUE;
} }
static int hw_start_acquisition(int device_index, gpointer session_device_id) static int hw_start_acquisition(int device_index, gpointer session_data)
{ {
struct sr_datafeed_packet *packet; struct sr_datafeed_packet *packet;
struct sr_datafeed_header *header; struct sr_datafeed_header *header;
@ -908,7 +925,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
return SR_ERR; return SR_ERR;
sr_source_add(sdi->serial->fd, G_IO_IN, -1, receive_data, sr_source_add(sdi->serial->fd, G_IO_IN, -1, receive_data,
session_device_id); session_data);
if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) { if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
sr_err("ols: %s: packet malloc failed", __func__); sr_err("ols: %s: packet malloc failed", __func__);
@ -923,15 +940,13 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
/* Send header packet to the session bus. */ /* Send header packet to the session bus. */
packet->type = SR_DF_HEADER; packet->type = SR_DF_HEADER;
packet->length = sizeof(struct sr_datafeed_header);
packet->payload = (unsigned char *)header; packet->payload = (unsigned char *)header;
header->feed_version = 1; header->feed_version = 1;
gettimeofday(&header->starttime, NULL); gettimeofday(&header->starttime, NULL);
header->samplerate = ols->cur_samplerate; header->samplerate = ols->cur_samplerate;
header->protocol_id = SR_PROTO_RAW;
header->num_logic_probes = NUM_PROBES; header->num_logic_probes = NUM_PROBES;
header->num_analog_probes = 0; header->num_analog_probes = 0;
sr_session_bus(session_device_id, packet); sr_session_bus(session_data, packet);
g_free(header); g_free(header);
g_free(packet); g_free(packet);
@ -947,7 +962,6 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id)
device_index = device_index; device_index = device_index;
packet.type = SR_DF_END; packet.type = SR_DF_END;
packet.length = 0;
sr_session_bus(session_device_id, &packet); sr_session_bus(session_device_id, &packet);
} }

View File

@ -67,6 +67,7 @@ struct ols_device {
uint64_t cur_samplerate; uint64_t cur_samplerate;
uint32_t cur_samplerate_divider; uint32_t cur_samplerate_divider;
uint64_t period_ps;
uint64_t limit_samples; uint64_t limit_samples;
/* Current state of the flag register */ /* Current state of the flag register */
uint32_t flag_reg; uint32_t flag_reg;

View File

@ -517,6 +517,7 @@ static int set_configuration_samplerate(struct sr_device_instance *sdi,
return SR_ERR; return SR_ERR;
} }
fx2->cur_samplerate = samplerate; fx2->cur_samplerate = samplerate;
fx2->period_ps = 1000000000000 / samplerate;
return SR_OK; return SR_OK;
} }
@ -565,9 +566,11 @@ static int receive_data(int fd, int revents, void *user_data)
void receive_transfer(struct libusb_transfer *transfer) void receive_transfer(struct libusb_transfer *transfer)
{ {
/* TODO: these statics have to move to fx2_device struct */
static int num_samples = 0; static int num_samples = 0;
static int empty_transfer_count = 0; static int empty_transfer_count = 0;
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
struct fx2_device *fx2; struct fx2_device *fx2;
int cur_buflen, trigger_offset, i; int cur_buflen, trigger_offset, i;
unsigned char *cur_buf, *new_buf; unsigned char *cur_buf, *new_buf;
@ -639,7 +642,9 @@ void receive_transfer(struct libusb_transfer *transfer)
* Tell the frontend we hit the trigger here. * Tell the frontend we hit the trigger here.
*/ */
packet.type = SR_DF_TRIGGER; packet.type = SR_DF_TRIGGER;
packet.length = 0; packet.timeoffset = (num_samples - fx2->trigger_stage) * fx2->period_ps;
packet.duration = 0;
packet.payload = NULL;
sr_session_bus(fx2->session_data, &packet); sr_session_bus(fx2->session_data, &packet);
/* /*
@ -647,9 +652,12 @@ void receive_transfer(struct libusb_transfer *transfer)
* skipping past them. * skipping past them.
*/ */
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
packet.length = fx2->trigger_stage; packet.timeoffset = (num_samples - fx2->trigger_stage) * fx2->period_ps;
packet.unitsize = 1; packet.duration = fx2->trigger_stage * fx2->period_ps;
packet.payload = fx2->trigger_buffer; packet.payload = &logic;
logic.length = fx2->trigger_stage;
logic.unitsize = 1;
logic.data = fx2->trigger_buffer;
sr_session_bus(fx2->session_data, &packet); sr_session_bus(fx2->session_data, &packet);
fx2->trigger_stage = TRIGGER_FIRED; fx2->trigger_stage = TRIGGER_FIRED;
@ -678,9 +686,12 @@ void receive_transfer(struct libusb_transfer *transfer)
if (fx2->trigger_stage == TRIGGER_FIRED) { if (fx2->trigger_stage == TRIGGER_FIRED) {
/* Send the incoming transfer to the session bus. */ /* Send the incoming transfer to the session bus. */
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
packet.length = cur_buflen - trigger_offset; packet.timeoffset = num_samples * fx2->period_ps;
packet.unitsize = 1; packet.duration = cur_buflen * fx2->period_ps;
packet.payload = cur_buf + trigger_offset; packet.payload = &logic;
logic.length = cur_buflen - trigger_offset;
logic.unitsize = 1;
logic.data = cur_buf + trigger_offset;
sr_session_bus(fx2->session_data, &packet); sr_session_bus(fx2->session_data, &packet);
g_free(cur_buf); g_free(cur_buf);
@ -749,12 +760,10 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
free(lupfd); free(lupfd);
packet->type = SR_DF_HEADER; packet->type = SR_DF_HEADER;
packet->length = sizeof(struct sr_datafeed_header); packet->payload = header;
packet->payload = (unsigned char *)header;
header->feed_version = 1; header->feed_version = 1;
gettimeofday(&header->starttime, NULL); gettimeofday(&header->starttime, NULL);
header->samplerate = fx2->cur_samplerate; header->samplerate = fx2->cur_samplerate;
header->protocol_id = SR_PROTO_RAW;
header->num_logic_probes = fx2->profile->num_probes; header->num_logic_probes = fx2->profile->num_probes;
header->num_analog_probes = 0; header->num_analog_probes = 0;
sr_session_bus(session_data, packet); sr_session_bus(session_data, packet);

View File

@ -60,6 +60,7 @@ struct fx2_device {
GTimeVal fw_updated; GTimeVal fw_updated;
/* device/capture settings */ /* device/capture settings */
uint64_t cur_samplerate; uint64_t cur_samplerate;
uint64_t period_ps;
uint64_t limit_samples; uint64_t limit_samples;
uint8_t probe_mask; uint8_t probe_mask;
uint8_t trigger_mask[NUM_TRIGGER_STAGES]; uint8_t trigger_mask[NUM_TRIGGER_STAGES];

View File

@ -118,6 +118,7 @@ static struct sr_samplerates samplerates = {
/* TODO: All of these should go in a device-specific struct. */ /* TODO: All of these should go in a device-specific struct. */
static uint64_t cur_samplerate = 0; static uint64_t cur_samplerate = 0;
static uint64_t period_ps = 0;
static uint64_t limit_samples = 0; static uint64_t limit_samples = 0;
static int num_channels = 32; /* TODO: This isn't initialized before it's needed :( */ static int num_channels = 32; /* TODO: This isn't initialized before it's needed :( */
static uint64_t memory_size = 0; static uint64_t memory_size = 0;
@ -461,6 +462,7 @@ static int set_configuration_samplerate(uint64_t samplerate)
analyzer_set_freq(samplerate, FREQ_SCALE_HZ); analyzer_set_freq(samplerate, FREQ_SCALE_HZ);
cur_samplerate = samplerate; cur_samplerate = samplerate;
period_ps = 1000000000000 / samplerate;
return SR_OK; return SR_OK;
} }
@ -488,11 +490,13 @@ static int hw_set_configuration(int device_index, int capability, void *value)
} }
} }
static int hw_start_acquisition(int device_index, gpointer session_device_id) static int hw_start_acquisition(int device_index, gpointer session_data)
{ {
struct sr_device_instance *sdi; struct sr_device_instance *sdi;
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
struct sr_datafeed_header header; struct sr_datafeed_header header;
uint64_t samples_read;
int res; int res;
unsigned int packet_num; unsigned int packet_num;
unsigned char *buf; unsigned char *buf;
@ -507,50 +511,48 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
sr_info("Waiting for data"); sr_info("Waiting for data");
analyzer_wait_data(sdi->usb->devhdl); analyzer_wait_data(sdi->usb->devhdl);
sr_info("Stop address = 0x%x", sr_info("Stop address = 0x%x", analyzer_get_stop_address(sdi->usb->devhdl));
analyzer_get_stop_address(sdi->usb->devhdl)); sr_info("Now address = 0x%x", analyzer_get_now_address(sdi->usb->devhdl));
sr_info("Now address = 0x%x", sr_info("Trigger address = 0x%x", analyzer_get_trigger_address(sdi->usb->devhdl));
analyzer_get_now_address(sdi->usb->devhdl));
sr_info("Trigger address = 0x%x",
analyzer_get_trigger_address(sdi->usb->devhdl));
packet.type = SR_DF_HEADER; packet.type = SR_DF_HEADER;
packet.length = sizeof(struct sr_datafeed_header); packet.payload = &header;
packet.payload = (unsigned char *)&header;
header.feed_version = 1; header.feed_version = 1;
gettimeofday(&header.starttime, NULL); gettimeofday(&header.starttime, NULL);
header.samplerate = cur_samplerate; header.samplerate = cur_samplerate;
header.protocol_id = SR_PROTO_RAW;
header.num_logic_probes = num_channels; header.num_logic_probes = num_channels;
header.num_analog_probes = 0; header.num_analog_probes = 0;
sr_session_bus(session_device_id, &packet); sr_session_bus(session_data, &packet);
if (!(buf = g_try_malloc(PACKET_SIZE))) { if (!(buf = g_try_malloc(PACKET_SIZE))) {
sr_err("lap-c: %s: buf malloc failed", __func__); sr_err("lap-c: %s: buf malloc failed", __func__);
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
} }
samples_read = 0;
analyzer_read_start(sdi->usb->devhdl); analyzer_read_start(sdi->usb->devhdl);
/* Send the incoming transfer to the session bus. */ /* Send the incoming transfer to the session bus. */
for (packet_num = 0; packet_num < (memory_size * 4 / PACKET_SIZE); for (packet_num = 0; packet_num < (memory_size * 4 / PACKET_SIZE);
packet_num++) { packet_num++) {
res = analyzer_read_data(sdi->usb->devhdl, buf, PACKET_SIZE); res = analyzer_read_data(sdi->usb->devhdl, buf, PACKET_SIZE);
#if 0
sr_info("Tried to read %llx bytes, actually read %x bytes", sr_info("Tried to read %llx bytes, actually read %x bytes",
PACKET_SIZE, res); PACKET_SIZE, res);
#endif
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
packet.length = PACKET_SIZE; packet.timeoffset = samples_read * period_ps;
packet.unitsize = 4; packet.duration = res / 4 * period_ps;
packet.payload = buf; packet.payload = &logic;
sr_session_bus(session_device_id, &packet); logic.length = PACKET_SIZE;
logic.unitsize = 4;
logic.data = buf;
sr_session_bus(session_data, &packet);
samples_read += res / 4;
} }
analyzer_read_stop(sdi->usb->devhdl); analyzer_read_stop(sdi->usb->devhdl);
g_free(buf); g_free(buf);
packet.type = SR_DF_END; packet.type = SR_DF_END;
sr_session_bus(session_device_id, &packet); sr_session_bus(session_data, &packet);
return SR_OK; return SR_OK;
} }

View File

@ -60,7 +60,8 @@ static int loadfile(struct sr_input *in, const char *filename)
{ {
struct sr_datafeed_header header; struct sr_datafeed_header header;
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
char buffer[CHUNKSIZE]; struct sr_datafeed_logic logic;
unsigned char buffer[CHUNKSIZE];
int fd, size, num_probes; int fd, size, num_probes;
if ((fd = open(filename, O_RDONLY)) == -1) if ((fd = open(filename, O_RDONLY)) == -1)
@ -72,27 +73,25 @@ static int loadfile(struct sr_input *in, const char *filename)
header.feed_version = 1; header.feed_version = 1;
header.num_logic_probes = num_probes; header.num_logic_probes = num_probes;
header.num_analog_probes = 0; header.num_analog_probes = 0;
header.protocol_id = SR_PROTO_RAW;
header.samplerate = 0; header.samplerate = 0;
gettimeofday(&header.starttime, NULL); gettimeofday(&header.starttime, NULL);
packet.type = SR_DF_HEADER; packet.type = SR_DF_HEADER;
packet.length = sizeof(struct sr_datafeed_header);
packet.payload = &header; packet.payload = &header;
sr_session_bus(in->vdevice, &packet); sr_session_bus(in->vdevice, &packet);
/* chop up the input file into chunks and feed it into the session bus */ /* chop up the input file into chunks and feed it into the session bus */
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
packet.unitsize = (num_probes + 7) / 8; packet.payload = &logic;
packet.payload = buffer; logic.unitsize = (num_probes + 7) / 8;
logic.data = buffer;
while ((size = read(fd, buffer, CHUNKSIZE)) > 0) { while ((size = read(fd, buffer, CHUNKSIZE)) > 0) {
packet.length = size; logic.length = size;
sr_session_bus(in->vdevice, &packet); sr_session_bus(in->vdevice, &packet);
} }
close(fd); close(fd);
/* end of stream */ /* end of stream */
packet.type = SR_DF_END; packet.type = SR_DF_END;
packet.length = 0;
sr_session_bus(in->vdevice, &packet); sr_session_bus(in->vdevice, &packet);
return SR_OK; return SR_OK;

View File

@ -99,6 +99,7 @@ static int loadfile(struct sr_input *in, const char *filename)
{ {
struct sr_datafeed_header header; struct sr_datafeed_header header;
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
uint8_t buf[PACKET_SIZE], divcount; uint8_t buf[PACKET_SIZE], divcount;
int i, fd, size, num_probes; int i, fd, size, num_probes;
uint64_t samplerate; uint64_t samplerate;
@ -125,14 +126,11 @@ static int loadfile(struct sr_input *in, const char *filename)
/* Send header packet to the session bus. */ /* Send header packet to the session bus. */
sr_dbg("la8input: %s: sending SR_DF_HEADER packet", __func__); sr_dbg("la8input: %s: sending SR_DF_HEADER packet", __func__);
packet.type = SR_DF_HEADER; packet.type = SR_DF_HEADER;
packet.length = sizeof(struct sr_datafeed_header);
packet.unitsize = 0;
packet.payload = &header; packet.payload = &header;
header.feed_version = 1; header.feed_version = 1;
gettimeofday(&header.starttime, NULL); gettimeofday(&header.starttime, NULL);
header.num_logic_probes = num_probes; header.num_logic_probes = num_probes;
header.num_analog_probes = 0; header.num_analog_probes = 0;
header.protocol_id = SR_PROTO_RAW;
header.samplerate = samplerate; header.samplerate = samplerate;
sr_session_bus(in->vdevice, &packet); sr_session_bus(in->vdevice, &packet);
@ -141,14 +139,15 @@ static int loadfile(struct sr_input *in, const char *filename)
/* Send data packets to the session bus. */ /* Send data packets to the session bus. */
sr_dbg("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.type = SR_DF_LOGIC;
packet.unitsize = (num_probes + 7) / 8; packet.payload = &logic;
packet.payload = buf; logic.unitsize = (num_probes + 7) / 8;
logic.data = buf;
/* Send 8MB of total data to the session bus in small chunks. */ /* Send 8MB of total data to the session bus in small chunks. */
for (i = 0; i < NUM_PACKETS; i++) { for (i = 0; i < NUM_PACKETS; i++) {
/* TODO: Handle errors, handle incomplete reads. */ /* TODO: Handle errors, handle incomplete reads. */
size = read(fd, buf, PACKET_SIZE); size = read(fd, buf, PACKET_SIZE);
packet.length = PACKET_SIZE; logic.length = PACKET_SIZE;
sr_session_bus(in->vdevice, &packet); sr_session_bus(in->vdevice, &packet);
} }
close(fd); /* FIXME */ close(fd); /* FIXME */
@ -156,8 +155,6 @@ static int loadfile(struct sr_input *in, const char *filename)
/* Send end packet to the session bus. */ /* Send end packet to the session bus. */
sr_dbg("la8input: %s: sending SR_DF_END", __func__); sr_dbg("la8input: %s: sending SR_DF_END", __func__);
packet.type = SR_DF_END; packet.type = SR_DF_END;
packet.length = 0;
packet.unitsize = 0;
packet.payload = NULL; packet.payload = NULL;
sr_session_bus(in->vdevice, &packet); sr_session_bus(in->vdevice, &packet);

View File

@ -60,11 +60,12 @@ static struct session_vdevice *get_vdevice_by_index(int device_index)
return vdevice; return vdevice;
} }
static int feed_chunk(int fd, int revents, void *user_data) static int feed_chunk(int fd, int revents, void *session_data)
{ {
struct sr_device_instance *sdi; struct sr_device_instance *sdi;
struct session_vdevice *vdevice; struct session_vdevice *vdevice;
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
GSList *l; GSList *l;
void *buf; void *buf;
int ret, got_data; int ret, got_data;
@ -93,10 +94,13 @@ static int feed_chunk(int fd, int revents, void *user_data)
if (ret > 0) { if (ret > 0) {
got_data = TRUE; got_data = TRUE;
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
packet.length = ret; packet.timeoffset = 0;
packet.unitsize = vdevice->unitsize; packet.duration = 0;
packet.payload = buf; packet.payload = &logic;
sr_session_bus(user_data, &packet); logic.length = ret;
logic.unitsize = vdevice->unitsize;
logic.data = buf;
sr_session_bus(session_data, &packet);
} else { } else {
/* done with this capture file */ /* done with this capture file */
zip_fclose(vdevice->capfile); zip_fclose(vdevice->capfile);
@ -108,8 +112,7 @@ static int feed_chunk(int fd, int revents, void *user_data)
if (!got_data) { if (!got_data) {
packet.type = SR_DF_END; packet.type = SR_DF_END;
packet.length = 0; sr_session_bus(session_data, &packet);
sr_session_bus(user_data, &packet);
} }
return TRUE; return TRUE;
@ -270,12 +273,10 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
/* Send header packet to the session bus. */ /* Send header packet to the session bus. */
packet->type = SR_DF_HEADER; packet->type = SR_DF_HEADER;
packet->length = sizeof(struct sr_datafeed_header);
packet->payload = (unsigned char *)header; packet->payload = (unsigned char *)header;
header->feed_version = 1; header->feed_version = 1;
gettimeofday(&header->starttime, NULL); gettimeofday(&header->starttime, NULL);
header->samplerate = 0; header->samplerate = 0;
header->protocol_id = SR_PROTO_RAW;
header->num_logic_probes = vdevice->num_probes; header->num_logic_probes = vdevice->num_probes;
header->num_analog_probes = 0; header->num_analog_probes = 0;
sr_session_bus(session_device_id, packet); sr_session_bus(session_device_id, packet);

View File

@ -123,7 +123,7 @@ struct sr_datafeed_header {
struct sr_datafeed_logic { struct sr_datafeed_logic {
uint64_t length; uint64_t length;
uint16_t unitsize; uint16_t unitsize;
unsigned char *data; void *data;
}; };
struct sr_datafeed_pd { struct sr_datafeed_pd {