A few more random 'probe' to 'channel' changes.

This fixes parts of bug #259.
This commit is contained in:
Uwe Hermann 2014-03-24 16:11:45 +01:00
parent f3ca73edd2
commit fca75cbb74
13 changed files with 73 additions and 73 deletions

View File

@ -29,39 +29,39 @@
/** /**
* @file * @file
* *
* Helper functions to filter out unused probes from samples. * Helper functions to filter out unused channels from samples.
*/ */
/** /**
* @defgroup grp_filter Probe filter * @defgroup grp_filter Channel filter
* *
* Helper functions to filter out unused probes from samples. * Helper functions to filter out unused channels from samples.
* *
* @{ * @{
*/ */
/** /**
* Remove unused probes from samples. * Remove unused channels from samples.
* *
* Convert sample from maximum probes -- the way the hardware driver sent * Convert sample from maximum channels -- the way the hardware driver sent
* it -- to a sample taking up only as much space as required, with * it -- to a sample taking up only as much space as required, with
* unused probes removed. * unused channels removed.
* *
* The "unit size" is the number of bytes used to store probe values. * The "unit size" is the number of bytes used to store channel values.
* For example, a unit size of 1 means one byte is used (which can store * For example, a unit size of 1 means one byte is used (which can store
* 8 probe values, each of them is 1 bit). A unit size of 2 means we can * 8 channel values, each of them is 1 bit). A unit size of 2 means we can
* store 16 probe values, 3 means we can store 24 probe values, and so on. * store 16 channel values, 3 means we can store 24 channel values, and so on.
* *
* If the data coming from the logic analyzer has a unit size of 4 for * If the data coming from the logic analyzer has a unit size of 4 for
* example (as the device has 32 probes), but only 2 of them are actually * example (as the device has 32 channels), but only 2 of them are actually
* used in an acquisition, this function can convert the samples to only * used in an acquisition, this function can convert the samples to only
* use up 1 byte per sample (unit size = 1) instead of 4 bytes per sample. * use up 1 byte per sample (unit size = 1) instead of 4 bytes per sample.
* *
* The output will contain the probe values in the order specified via the * The output will contain the channel values in the order specified via the
* probelist. For example, if in_unitsize = 4, probelist = [5, 16, 30], and * channellist. For example, if in_unitsize = 4, channellist = [5, 16, 30], and
* out_unitsize = 1, then the output samples (each of them one byte in size) * out_unitsize = 1, then the output samples (each of them one byte in size)
* will have the following format: bit 0 = value of probe 5, bit 1 = value * will have the following format: bit 0 = value of channel 5, bit 1 = value
* of probe 16, bit 2 = value of probe 30. Unused bit(s) in the output byte(s) * of channel 16, bit 2 = value of channel 30. Unused bit(s) in the output byte(s)
* are zero. * are zero.
* *
* The caller must make sure that length_in is not bigger than the memory * The caller must make sure that length_in is not bigger than the memory
@ -72,8 +72,8 @@
* @param out_unitsize The unit size (>= 1) the output shall have (data_out). * @param out_unitsize The unit size (>= 1) the output shall have (data_out).
* The requested unit size must be big enough to hold as * The requested unit size must be big enough to hold as
* much data as is specified by the number of enabled * much data as is specified by the number of enabled
* probes in 'probelist'. * channels in 'channellist'.
* @param probe_array Pointer to a list of probe numbers, numbered starting * @param channel_array Pointer to a list of channel numbers, numbered starting
* from 0. The list is terminated with -1. * from 0. The list is terminated with -1.
* @param data_in Pointer to the input data buffer. Must not be NULL. * @param data_in Pointer to the input data buffer. Must not be NULL.
* @param length_in The input data length (>= 1), in number of bytes. * @param length_in The input data length (>= 1), in number of bytes.
@ -92,20 +92,20 @@
* @since 0.2.0 * @since 0.2.0
*/ */
SR_API int sr_filter_channels(unsigned int in_unitsize, unsigned int out_unitsize, SR_API int sr_filter_channels(unsigned int in_unitsize, unsigned int out_unitsize,
const GArray *probe_array, const uint8_t *data_in, const GArray *channel_array, const uint8_t *data_in,
uint64_t length_in, uint8_t **data_out, uint64_t length_in, uint8_t **data_out,
uint64_t *length_out) uint64_t *length_out)
{ {
unsigned int in_offset, out_offset; unsigned int in_offset, out_offset;
int *probelist, out_bit; int *channellist, out_bit;
unsigned int i; unsigned int i;
uint8_t *sample_in, *sample_out; uint8_t *sample_in, *sample_out;
if (!probe_array) { if (!channel_array) {
sr_err("%s: probe_array was NULL", __func__); sr_err("%s: channel_array was NULL", __func__);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
probelist = (int *)probe_array->data; channellist = (int *)channel_array->data;
if (!data_in) { if (!data_in) {
sr_err("%s: data_in was NULL", __func__); sr_err("%s: data_in was NULL", __func__);
@ -122,10 +122,10 @@ SR_API int sr_filter_channels(unsigned int in_unitsize, unsigned int out_unitsiz
return SR_ERR_ARG; return SR_ERR_ARG;
} }
/* Are there more probes than the target unit size supports? */ /* Are there more channels than the target unit size supports? */
if (probe_array->len > out_unitsize * 8) { if (channel_array->len > out_unitsize * 8) {
sr_err("%s: too many probes (%d) for the target unit " sr_err("%s: too many channels (%d) for the target unit "
"size (%d)", __func__, probe_array->len, out_unitsize); "size (%d)", __func__, channel_array->len, out_unitsize);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
@ -134,22 +134,22 @@ SR_API int sr_filter_channels(unsigned int in_unitsize, unsigned int out_unitsiz
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
} }
if (probe_array->len == in_unitsize * 8) { if (channel_array->len == in_unitsize * 8) {
/* All probes are used -- no need to compress anything. */ /* All channels are used -- no need to compress anything. */
memcpy(*data_out, data_in, length_in); memcpy(*data_out, data_in, length_in);
*length_out = length_in; *length_out = length_in;
return SR_OK; return SR_OK;
} }
/* If we reached this point, not all probes are used, so "compress". */ /* If we reached this point, not all channels are used, so "compress". */
in_offset = out_offset = 0; in_offset = out_offset = 0;
while (in_offset <= length_in - in_unitsize) { while (in_offset <= length_in - in_unitsize) {
sample_in = (uint8_t *)data_in + in_offset; sample_in = (uint8_t *)data_in + in_offset;
sample_out = (*data_out) + out_offset; sample_out = (*data_out) + out_offset;
memset(sample_out, 0, out_unitsize); memset(sample_out, 0, out_unitsize);
out_bit = 0; out_bit = 0;
for (i = 0; i < probe_array->len; i++) { for (i = 0; i < channel_array->len; i++) {
if (sample_in[probelist[i]>>3] & (1 << (probelist[i]&7))) if (sample_in[channellist[i]>>3] & (1 << (channellist[i]&7)))
sample_out[out_bit>>3] |= (1 << (out_bit&7)); sample_out[out_bit>>3] |= (1 << (out_bit&7));
out_bit++; out_bit++;
} }

View File

@ -24,7 +24,7 @@
#include "libsigrok-internal.h" #include "libsigrok-internal.h"
#include "protocol.h" #include "protocol.h"
/* Probes are numbered 0-7. */ /* Channels are numbered 0-7. */
SR_PRIV const char *chronovu_la8_channel_names[NUM_CHANNELS + 1] = { SR_PRIV const char *chronovu_la8_channel_names[NUM_CHANNELS + 1] = {
"0", "1", "2", "3", "4", "5", "6", "7", "0", "1", "2", "3", "4", "5", "6", "7",
NULL, NULL,

View File

@ -101,7 +101,7 @@ static GSList *scan(GSList *options)
GSList *l; GSList *l;
struct sr_config *src; struct sr_config *src;
struct udev *udev; struct udev *udev;
int ptype; int chtype;
for (l = options; l; l = l->next) { for (l = options; l; l = l->next) {
src = l->data; src = l->data;
@ -218,8 +218,8 @@ static GSList *scan(GSList *options)
for (i = 0; i < NUM_CHANNELS; i++) { for (i = 0; i < NUM_CHANNELS; i++) {
struct sr_channel *ch; struct sr_channel *ch;
ptype = (i == 0) ? SR_CHANNEL_ANALOG : SR_CHANNEL_LOGIC; chtype = (i == 0) ? SR_CHANNEL_ANALOG : SR_CHANNEL_LOGIC;
if (!(ch = sr_channel_new(i, ptype, TRUE, if (!(ch = sr_channel_new(i, chtype, TRUE,
mso19_channel_names[i]))) mso19_channel_names[i])))
return 0; return 0;
sdi->channels = g_slist_append(sdi->channels, ch); sdi->channels = g_slist_append(sdi->channels, ch);

View File

@ -96,10 +96,10 @@ static struct sr_config_info sr_config_info_data[] = {
"Power off", NULL}, "Power off", NULL},
{SR_CONF_DATA_SOURCE, SR_T_CHAR, "data_source", {SR_CONF_DATA_SOURCE, SR_T_CHAR, "data_source",
"Data source", NULL}, "Data source", NULL},
{SR_CONF_NUM_LOGIC_CHANNELS, SR_T_INT32, "logic_probes", {SR_CONF_NUM_LOGIC_CHANNELS, SR_T_INT32, "logic_channels",
"Number of logic probes", NULL}, "Number of logic channels", NULL},
{SR_CONF_NUM_ANALOG_CHANNELS, SR_T_INT32, "analog_probes", {SR_CONF_NUM_ANALOG_CHANNELS, SR_T_INT32, "analog_channels",
"Number of analog probes", NULL}, "Number of analog channels", NULL},
{SR_CONF_OUTPUT_VOLTAGE, SR_T_FLOAT, "output_voltage", {SR_CONF_OUTPUT_VOLTAGE, SR_T_FLOAT, "output_voltage",
"Current output voltage", NULL}, "Current output voltage", NULL},
{SR_CONF_OUTPUT_VOLTAGE_MAX, SR_T_FLOAT, "output_voltage_max", {SR_CONF_OUTPUT_VOLTAGE_MAX, SR_T_FLOAT, "output_voltage_max",

View File

@ -226,9 +226,9 @@ SR_PRIV int sr_err(const char *format, ...);
/** Values for the changes argument of sr_dev_driver.config_channel_set. */ /** Values for the changes argument of sr_dev_driver.config_channel_set. */
enum { enum {
/** The enabled state of the probe has been changed. */ /** The enabled state of the channel has been changed. */
SR_CHANNEL_SET_ENABLED = 1 << 0, SR_CHANNEL_SET_ENABLED = 1 << 0,
/** The trigger setup of the probe has been changed. */ /** The trigger setup of the channel has been changed. */
SR_CHANNEL_SET_TRIGGER = 1 << 1, SR_CHANNEL_SET_TRIGGER = 1 << 1,
}; };

View File

@ -597,12 +597,12 @@ struct sr_output_format {
int (*cleanup) (struct sr_output *o); int (*cleanup) (struct sr_output *o);
}; };
/** Constants for probe type. */ /** Constants for channel type. */
enum { enum {
/** Probe type is logic probe. */ /** Channel type is logic channel. */
SR_CHANNEL_LOGIC = 10000, SR_CHANNEL_LOGIC = 10000,
/** Probe type is analog probe. */ /** Channel type is analog channel. */
SR_CHANNEL_ANALOG, SR_CHANNEL_ANALOG,
}; };
/** Information on single channel. */ /** Information on single channel. */
@ -803,10 +803,10 @@ enum {
*/ */
SR_CONF_CENTER_FREQUENCY, SR_CONF_CENTER_FREQUENCY,
/** The device supports setting the number of logic probes. */ /** The device supports setting the number of logic channels. */
SR_CONF_NUM_LOGIC_CHANNELS, SR_CONF_NUM_LOGIC_CHANNELS,
/** The device supports setting the number of analog probes. */ /** The device supports setting the number of analog channels. */
SR_CONF_NUM_ANALOG_CHANNELS, SR_CONF_NUM_ANALOG_CHANNELS,
/** Output voltage. */ /** Output voltage. */
@ -992,7 +992,7 @@ struct sr_dev_driver {
int (*config_set) (int id, GVariant *data, int (*config_set) (int id, GVariant *data,
const struct sr_dev_inst *sdi, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg); const struct sr_channel_group *cg);
/** Probe status change. /** Channel status change.
* @see sr_dev_channel_enable(), sr_dev_trigger_set(). */ * @see sr_dev_channel_enable(), sr_dev_trigger_set(). */
int (*config_channel_set) (const struct sr_dev_inst *sdi, int (*config_channel_set) (const struct sr_dev_inst *sdi,
struct sr_channel *ch, unsigned int changes); struct sr_channel *ch, unsigned int changes);

View File

@ -46,7 +46,7 @@ SR_PRIV int data_ascii(struct sr_output *o, const uint8_t *data_in,
max_linelen = SR_MAX_CHANNELNAME_LEN + 3 + ctx->samples_per_line max_linelen = SR_MAX_CHANNELNAME_LEN + 3 + ctx->samples_per_line
+ ctx->samples_per_line / 8; + ctx->samples_per_line / 8;
/* /*
* Calculate space needed for probes. Set aside 512 bytes for * Calculate space needed for channels. Set aside 512 bytes for
* extra output, e.g. trigger. * extra output, e.g. trigger.
*/ */
outsize = 512 + (1 + (length_in / ctx->unitsize) / ctx->samples_per_line) outsize = 512 + (1 + (length_in / ctx->unitsize) / ctx->samples_per_line)

View File

@ -46,7 +46,7 @@ SR_PRIV int data_bits(struct sr_output *o, const uint8_t *data_in,
max_linelen = SR_MAX_CHANNELNAME_LEN + 3 + ctx->samples_per_line max_linelen = SR_MAX_CHANNELNAME_LEN + 3 + ctx->samples_per_line
+ ctx->samples_per_line / 8; + ctx->samples_per_line / 8;
/* /*
* Calculate space needed for probes. Set aside 512 bytes for * Calculate space needed for channels. Set aside 512 bytes for
* extra output, e.g. trigger. * extra output, e.g. trigger.
*/ */
outsize = 512 + (1 + (length_in / ctx->unitsize) / ctx->samples_per_line) outsize = 512 + (1 + (length_in / ctx->unitsize) / ctx->samples_per_line)

10
proto.h
View File

@ -46,10 +46,10 @@ SR_API char *sr_log_logdomain_get(void);
/*--- device.c --------------------------------------------------------------*/ /*--- device.c --------------------------------------------------------------*/
SR_API int sr_dev_channel_name_set(const struct sr_dev_inst *sdi, SR_API int sr_dev_channel_name_set(const struct sr_dev_inst *sdi,
int probenum, const char *name); int channelnum, const char *name);
SR_API int sr_dev_channel_enable(const struct sr_dev_inst *sdi, int probenum, SR_API int sr_dev_channel_enable(const struct sr_dev_inst *sdi, int channelnum,
gboolean state); gboolean state);
SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int probenum, SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int channelnum,
const char *trigger); const char *trigger);
SR_API gboolean sr_dev_has_option(const struct sr_dev_inst *sdi, int key); SR_API gboolean sr_dev_has_option(const struct sr_dev_inst *sdi, int key);
SR_API GSList *sr_dev_list(const struct sr_dev_driver *driver); SR_API GSList *sr_dev_list(const struct sr_dev_driver *driver);
@ -60,7 +60,7 @@ SR_API int sr_dev_close(struct sr_dev_inst *sdi);
/*--- filter.c --------------------------------------------------------------*/ /*--- filter.c --------------------------------------------------------------*/
SR_API int sr_filter_channels(unsigned int in_unitsize, unsigned int out_unitsize, SR_API int sr_filter_channels(unsigned int in_unitsize, unsigned int out_unitsize,
const GArray *probe_array, const uint8_t *data_in, const GArray *channel_array, const uint8_t *data_in,
uint64_t length_in, uint8_t **data_out, uint64_t length_in, uint8_t **data_out,
uint64_t *length_out); uint64_t *length_out);
@ -110,7 +110,7 @@ SR_API int sr_session_stop(void);
SR_API int sr_session_save(const char *filename, const struct sr_dev_inst *sdi, SR_API int sr_session_save(const char *filename, const struct sr_dev_inst *sdi,
unsigned char *buf, int unitsize, int units); unsigned char *buf, int unitsize, int units);
SR_API int sr_session_save_init(const char *filename, uint64_t samplerate, SR_API int sr_session_save_init(const char *filename, uint64_t samplerate,
char **probes); char **channels);
SR_API int sr_session_append(const char *filename, unsigned char *buf, SR_API int sr_session_append(const char *filename, unsigned char *buf,
int unitsize, int units); int unitsize, int units);
SR_API int sr_session_source_add(int fd, int events, int timeout, SR_API int sr_session_source_add(int fd, int events, int timeout,

View File

@ -41,7 +41,7 @@ struct session_vdev {
int bytes_read; int bytes_read;
uint64_t samplerate; uint64_t samplerate;
int unitsize; int unitsize;
int num_probes; int num_channels;
int cur_chunk; int cur_chunk;
gboolean finished; gboolean finished;
}; };
@ -260,7 +260,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
vdev->unitsize = g_variant_get_uint64(data); vdev->unitsize = g_variant_get_uint64(data);
break; break;
case SR_CONF_NUM_LOGIC_CHANNELS: case SR_CONF_NUM_LOGIC_CHANNELS:
vdev->num_probes = g_variant_get_uint64(data); vdev->num_channels = g_variant_get_uint64(data);
break; break;
default: default:
return SR_ERR_NA; return SR_ERR_NA;

View File

@ -34,7 +34,7 @@ static struct sr_context *sr_ctx;
static uint64_t df_packet_counter = 0, sample_counter = 0; static uint64_t df_packet_counter = 0, sample_counter = 0;
static gboolean have_seen_df_end = FALSE; static gboolean have_seen_df_end = FALSE;
static GArray *logic_probelist = NULL; static GArray *logic_channellist = NULL;
static int check_to_perform; static int check_to_perform;
static uint64_t expected_samples; static uint64_t expected_samples;
static uint64_t *expected_samplerate; static uint64_t *expected_samplerate;
@ -123,10 +123,10 @@ static void datafeed_in(const struct sr_dev_inst *sdi,
// g_debug("Received SR_DF_HEADER."); // g_debug("Received SR_DF_HEADER.");
// fail_unless(p != NULL, "SR_DF_HEADER payload was NULL."); // fail_unless(p != NULL, "SR_DF_HEADER payload was NULL.");
logic_probelist = srtest_get_enabled_logic_probes(sdi); logic_channellist = srtest_get_enabled_logic_channels(sdi);
fail_unless(logic_probelist != NULL); fail_unless(logic_channellist != NULL);
fail_unless(logic_probelist->len != 0); fail_unless(logic_channellist->len != 0);
// g_debug("Enabled probes: %d.", logic_probelist->len); // g_debug("Enabled channels: %d.", logic_channellist->len);
break; break;
case SR_DF_META: case SR_DF_META:
// g_debug("Received SR_DF_META."); // g_debug("Received SR_DF_META.");
@ -208,7 +208,7 @@ static void check_buf(const char *filename, GHashTable *param,
/* Initialize global variables for this run. */ /* Initialize global variables for this run. */
df_packet_counter = sample_counter = 0; df_packet_counter = sample_counter = 0;
have_seen_df_end = FALSE; have_seen_df_end = FALSE;
logic_probelist = NULL; logic_channellist = NULL;
check_to_perform = check; check_to_perform = check;
expected_samples = samples; expected_samples = samples;
expected_samplerate = samplerate; expected_samplerate = samplerate;

View File

@ -211,21 +211,21 @@ void srtest_buf_to_file(const char *filename, const uint8_t *buf, uint64_t len)
fclose(f); fclose(f);
} }
GArray *srtest_get_enabled_logic_probes(const struct sr_dev_inst *sdi) GArray *srtest_get_enabled_logic_channels(const struct sr_dev_inst *sdi)
{ {
struct sr_channel *ch; struct sr_channel *ch;
GArray *probes; GArray *channels;
GSList *l; GSList *l;
probes = g_array_new(FALSE, FALSE, sizeof(int)); channels = g_array_new(FALSE, FALSE, sizeof(int));
for (l = sdi->probes; l; l = l->next) { for (l = sdi->channels; l; l = l->next) {
probe = l->data; ch = l->data;
if (probe->type != SR_CHANNEL_LOGIC) if (ch->type != SR_CHANNEL_LOGIC)
continue; continue;
if (probe->enabled != TRUE) if (ch->enabled != TRUE)
continue; continue;
g_array_append_val(probes, probe->index); g_array_append_val(channels, ch->index);
} }
return probes; return channels;
} }

View File

@ -39,7 +39,7 @@ void srtest_check_samplerate(struct sr_context *sr_ctx, const char *drivername,
uint64_t samplerate); uint64_t samplerate);
void srtest_buf_to_file(const char *filename, const uint8_t *buf, uint64_t len); void srtest_buf_to_file(const char *filename, const uint8_t *buf, uint64_t len);
GArray *srtest_get_enabled_logic_probes(const struct sr_dev_inst *sdi); GArray *srtest_get_enabled_logic_channels(const struct sr_dev_inst *sdi);
Suite *suite_core(void); Suite *suite_core(void);
Suite *suite_driver_all(void); Suite *suite_driver_all(void);