analog.mq = devc->cur_mq;
analog.unit = devc->cur_unit;
analog.mqflags = devc->cur_mqflags;
+ analog.probes = sdi->probes;
analog.num_samples = 1;
analog.data = &fvalue;
packet.type = SR_DF_ANALOG;
}
/* Send a sample packet with the analog values. */
+ analog.probes = sdi->probes;
analog.num_samples = count;
analog.mq = SR_MQ_VOLTAGE; /* FIXME */
analog.unit = SR_UNIT_VOLT; /* FIXME */
memset(&analog, 0, sizeof(struct sr_datafeed_analog));
analog.mq = SR_MQ_SOUND_PRESSURE_LEVEL;
analog.unit = SR_UNIT_DECIBEL_SPL;
+ analog.probes = sdi->probes;
analog.num_samples = 1;
analog.data = &fvalue;
while(*e && *e == ' ')
e++;
- /* TODO: Check malloc return value. */
- analog = g_try_malloc0(sizeof(struct sr_datafeed_analog));
+ if (!(analog = g_try_malloc0(sizeof(struct sr_datafeed_analog))))
+ return NULL;
+ if (!(analog->data = g_try_malloc(sizeof(float))))
+ return NULL;
+ analog->probes = sdi->probes;
analog->num_samples = 1;
- /* TODO: Check malloc return value. */
- analog->data = g_try_malloc(sizeof(float));
if (is_oor)
*analog->data = NAN;
else
return NULL;
}
- /* TODO: Check malloc return value. */
- analog = g_try_malloc0(sizeof(struct sr_datafeed_analog));
+ if (!(analog = g_try_malloc0(sizeof(struct sr_datafeed_analog))))
+ return NULL;
+ if (!(analog->data = g_try_malloc(sizeof(float))))
+ return NULL;
+ analog->probes = sdi->probes;
analog->num_samples = 1;
- /* TODO: Check malloc return value. */
- analog->data = g_try_malloc(sizeof(float));
*analog->data = fvalue;
analog->mq = -1;
fvalue = 1.0;
}
+ analog.probes = sdi->probes;
analog.num_samples = 1;
analog.data = &fvalue;
analog.mq = devc->mq;
static int configure_probes(const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
- const struct sr_probe *probe;
+ struct sr_probe *probe;
const GSList *l;
+ int p;
devc = sdi->priv;
+ g_slist_free(devc->enabled_probes);
devc->ch1_enabled = devc->ch2_enabled = FALSE;
- for (l = sdi->probes; l; l = l->next) {
- probe = (struct sr_probe *)l->data;
- if (probe->index == 0)
+ for (l = sdi->probes, p = 0; l; l = l->next, p++) {
+ probe = l->data;
+ if (p == 0)
devc->ch1_enabled = probe->enabled;
- else if (probe->index == 1)
+ else
devc->ch2_enabled = probe->enabled;
+ if (probe->enabled)
+ devc->enabled_probes = g_slist_append(devc->enabled_probes, probe);
}
return SR_OK;
dso_close(sdi);
sr_usb_dev_inst_free(devc->usb);
g_free(devc->triggersource);
+ g_slist_free(devc->enabled_probes);
sr_dev_inst_free(sdi);
}
return ret;
}
-static void send_chunk(struct dev_context *devc, unsigned char *buf,
+static void send_chunk(struct sr_dev_inst *sdi, unsigned char *buf,
int num_samples)
{
struct sr_datafeed_packet packet;
struct sr_datafeed_analog analog;
+ struct dev_context *devc;
float ch1, ch2, range;
int num_probes, data_offset, i;
+ devc = sdi->priv;
num_probes = (devc->ch1_enabled && devc->ch2_enabled) ? 2 : 1;
packet.type = SR_DF_ANALOG;
packet.payload = &analog;
/* TODO: support for 5xxx series 9-bit samples */
+ analog.probes = devc->enabled_probes;
analog.num_samples = num_samples;
analog.mq = SR_MQ_VOLTAGE;
analog.unit = SR_UNIT_VOLT;
static void receive_transfer(struct libusb_transfer *transfer)
{
struct sr_datafeed_packet packet;
+ struct sr_dev_inst *sdi;
struct dev_context *devc;
int num_samples, pre;
- devc = transfer->user_data;
+ sdi = transfer->user_data;
+ devc = sdi->priv;
sr_dbg("receive_transfer(): status %d received %d bytes.",
transfer->status, transfer->actual_length);
/* Avoid the corner case where the chunk ended at
* exactly the trigger point. */
if (num_samples > pre)
- send_chunk(devc, transfer->buffer + pre * 2,
+ send_chunk(sdi, transfer->buffer + pre * 2,
num_samples - pre);
}
} else {
/* Already past the trigger point, just send it all out. */
- send_chunk(devc, transfer->buffer,
+ send_chunk(sdi, transfer->buffer,
num_samples);
}
* pre-trigger samples out now, in one big chunk. */
sr_dbg("End of frame, sending %d pre-trigger buffered samples.",
devc->samp_buffered);
- send_chunk(devc, devc->framebuf, devc->samp_buffered);
+ send_chunk(sdi, devc->framebuf, devc->samp_buffered);
/* Mark the end of this frame. */
packet.type = SR_DF_FRAME_END;
devc->samp_buffered = devc->samp_received = 0;
/* Tell the scope to send us the first frame. */
- if (dso_get_channeldata(devc, receive_transfer) != SR_OK)
+ if (dso_get_channeldata(sdi, receive_transfer) != SR_OK)
break;
/*
return SR_OK;
}
-SR_PRIV int dso_get_channeldata(struct dev_context *devc, libusb_transfer_cb_fn cb)
+SR_PRIV int dso_get_channeldata(const struct sr_dev_inst *sdi,
+ libusb_transfer_cb_fn cb)
{
+ struct dev_context *devc;
struct libusb_transfer *transfer;
int num_transfers, ret, i;
uint8_t cmdstring[2];
unsigned char *buf;
+ devc = sdi->priv;
sr_dbg("Sending CMD_GET_CHANNELDATA.");
cmdstring[0] = CMD_GET_CHANNELDATA;
transfer = libusb_alloc_transfer(0);
libusb_fill_bulk_transfer(transfer, devc->usb->devhdl,
DSO_EP_IN | LIBUSB_ENDPOINT_IN, buf,
- devc->epin_maxpacketsize, cb, devc, 40);
+ devc->epin_maxpacketsize, cb, (void *)sdi, 40);
if ((ret = libusb_submit_transfer(transfer)) != 0) {
sr_err("Failed to submit transfer: %s.",
libusb_error_name(ret));
void *cb_data;
uint64_t limit_frames;
uint64_t num_frames;
+ GSList *enabled_probes;
/* We can't keep track of an FX2-based device after upgrading
* the firmware (it re-enumerates into a different device address
* after the upgrade) this is like a global lock. No device will open
SR_PRIV int dso_get_capturestate(struct dev_context *devc,
uint8_t *capturestate, uint32_t *trigger_offset);
SR_PRIV int dso_capture_start(struct dev_context *devc);
-SR_PRIV int dso_get_channeldata(struct dev_context *devc,
+SR_PRIV int dso_get_channeldata(const struct sr_dev_inst *sdi,
libusb_transfer_cb_fn cb);
#endif
int samples, samples_left, i, j;
devc = sdi->priv;
+ analog.probes = sdi->probes;
+
samples = buflen / devc->sample_size;
samples_left = devc->logged_samples - devc->rcvd_samples;
if (samples_left < samples)
continue;
g_free(devc->device);
+ g_slist_free(devc->enabled_probes);
close(devc->fd);
sr_dev_inst_free(sdi);
gettimeofday(&header.starttime, NULL);
sr_session_send(cb_data, &packet);
+ /* Hardcoded to CH1 only. */
+ devc->enabled_probes = g_slist_append(NULL, sdi->probes->data);
rigol_ds1xx2_send_data(devc->fd, ":CHAN1:SCAL?\n");
len = read(devc->fd, buf, sizeof(buf));
buf[len] = 0;
return TRUE;
for (i = 0; i < len; i++)
data[i] = devc->scale / 25.6 * (128 - buf[i]) - devc->offset;
+ analog.probes = devc->enabled_probes;
analog.num_samples = len;
analog.data = data;
analog.mq = SR_MQ_VOLTAGE;
/** USBTMC character device file descriptor. */
int fd;
+
+ GSList *enabled_probes;
};
SR_PRIV int rigol_ds1xx2_receive_data(int fd, int revents, void *cb_data);
}
}
-static void handle_packet(const uint8_t *buf, struct dev_context *devc,
+static void handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi,
int dmm, void *info)
{
float floatval;
struct sr_datafeed_packet packet;
struct sr_datafeed_analog *analog;
+ struct dev_context *devc;
log_dmm_packet(buf);
+ devc = sdi->priv;
if (!(analog = g_try_malloc0(sizeof(struct sr_datafeed_analog)))) {
sr_err("Analog packet malloc failed.");
return;
}
+ analog->probes = sdi->probes;
analog->num_samples = 1;
analog->mq = -1;
g_free(analog);
}
-static void handle_new_data(struct dev_context *devc, int dmm, void *info)
+static void handle_new_data(struct sr_dev_inst *sdi, int dmm, void *info)
{
+ struct dev_context *devc;
int len, i, offset = 0;
+ devc = sdi->priv;
+
/* Try to get as much data as the buffer can hold. */
len = DMM_BUFSIZE - devc->buflen;
len = serial_read(devc->serial, devc->buf + devc->buflen, len);
/* Now look for packets in that data. */
while ((devc->buflen - offset) >= dmms[dmm].packet_size) {
if (dmms[dmm].packet_valid(devc->buf + offset)) {
- handle_packet(devc->buf + offset, devc, dmm, info);
+ handle_packet(devc->buf + offset, sdi, dmm, info);
offset += dmms[dmm].packet_size;
} else {
offset++;
if (revents == G_IO_IN) {
/* Serial data arrived. */
- handle_new_data(devc, dmm, info);
+ handle_new_data(sdi, dmm, info);
} else {
/* Timeout, send another packet request (if DMM needs it). */
if (dmms[dmm].packet_request) {
(void)level;
}
-static void decode_packet(struct dev_context *devc)
+static void decode_packet(struct sr_dev_inst *sdi)
{
struct sr_datafeed_packet packet;
struct sr_datafeed_analog analog;
+ struct dev_context *devc;
float floatval;
+ devc = sdi->priv;
memset(&analog, 0, sizeof(struct sr_datafeed_analog));
parse_packet(devc->buf, &floatval, &analog);
/* Send a sample packet with one analog value. */
+ analog.probes = sdi->probes;
analog.num_samples = 1;
analog.data = &floatval;
packet.type = SR_DF_ANALOG;
return TRUE;
}
- decode_packet(devc);
+ decode_packet(sdi);
devc->state = SEND_PACKET_REQUEST;
} else {
* - ...
*/
-static void decode_packet(struct dev_context *devc, int dmm, const uint8_t *buf)
+static void decode_packet(struct sr_dev_inst *sdi, int dmm, const uint8_t *buf)
{
struct sr_datafeed_packet packet;
struct sr_datafeed_analog analog;
+ struct dev_context *devc;
struct fs9721_info info;
float floatval;
int ret;
+ devc = sdi->priv;
memset(&analog, 0, sizeof(struct sr_datafeed_analog));
/* Parse the protocol packet. */
}
/* Send a sample packet with one analog value. */
+ analog.probes = sdi->probes;
analog.num_samples = 1;
analog.data = &floatval;
packet.type = SR_DF_ANALOG;
return TRUE;
}
}
- decode_packet(devc, dmm, pbuf);
+ decode_packet(sdi, dmm, pbuf);
memset(pbuf, 0x00, NUM_DATA_BYTES);
}
}
return out;
}
-static void decode_buf(struct dev_context *devc, unsigned char *data)
+static void decode_buf(struct sr_dev_inst *sdi, unsigned char *data)
{
struct sr_datafeed_packet packet;
struct sr_datafeed_analog analog;
+ struct dev_context *devc;
long factor, ivalue;
uint8_t digits[4];
gboolean is_duty, is_continuity, is_diode, is_ac, is_dc, is_auto;
gboolean is_hold, is_max, is_min, is_relative, minus;
float fvalue;
+ devc = sdi->priv;
+
digits[0] = decode_digit(data[12]);
digits[1] = decode_digit(data[11]);
digits[2] = decode_digit(data[10]);
if (is_relative)
analog.mqflags |= SR_MQFLAG_RELATIVE;
+ analog.probes = sdi->probes;
analog.num_samples = 1;
analog.data = &fvalue;
packet.type = SR_DF_ANALOG;
SR_PRIV int victor_dmm_receive_data(struct sr_dev_inst *sdi, unsigned char *buf)
{
- struct dev_context *devc;
GString *dbg;
int i;
unsigned char data[DMM_DATA_SIZE];
6, 13, 5, 11, 2, 7, 9, 8, 3, 10, 12, 0, 4, 1
};
- devc = sdi->priv;
-
for (i = 0; i < DMM_DATA_SIZE && buf[i] == 0; i++);
if (i == DMM_DATA_SIZE) {
/* This DMM outputs all zeroes from time to time, just ignore it. */
g_string_free(dbg, TRUE);
}
- decode_buf(devc, data);
+ decode_buf(sdi, data);
return SR_OK;
}
};
struct sr_datafeed_analog {
+ GSList *probes;
int num_samples;
/** Measured quantity (voltage, current, temperature, and so on). */
int mq;
static GString *receive(struct sr_output *o, const struct sr_dev_inst *sdi,
const struct sr_datafeed_packet *packet)
{
- const struct sr_datafeed_analog *analog;
struct context *ctx;
+ const struct sr_datafeed_analog *analog;
+ struct sr_probe *probe;
+ GSList *l;
const float *fdata;
- int i, j;
+ int i, p;
(void)sdi;
analog = packet->payload;
fdata = (const float *)analog->data;
for (i = 0; i < analog->num_samples; i++) {
- for (j = 0; j < ctx->num_enabled_probes; j++) {
- g_string_append_printf(ctx->out, "%s: ",
- (char *)g_ptr_array_index(ctx->probelist, j));
+ for (l = analog->probes, p = 0; l; l = l->next, p++) {
+ probe = l->data;
+ g_string_append_printf(ctx->out, "%s: ", probe->name);
fancyprint(analog->unit, analog->mqflags,
- fdata[i + j], ctx->out);
+ fdata[i + p], ctx->out);
}
}
break;