Skip to content

Commit

Permalink
Merge branch 'sigrokproject:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
filipkosecek committed Oct 23, 2022
2 parents f5ab583 + 2b7d35b commit 1f81da0
Show file tree
Hide file tree
Showing 40 changed files with 1,331 additions and 478 deletions.
20 changes: 20 additions & 0 deletions include/libsigrok/libsigrok.h
Expand Up @@ -784,6 +784,26 @@ enum sr_configkey {
*/
SR_CONF_FORCE_DETECT,

/**
* Override builtin probe names from user specs.
*
* Users may want to override the names which are assigned to
* probes during scan (these usually match the vendor's labels
* on the device). This avoids the interactive tedium of
* changing channel names after device creation and before
* protocol decoder attachment. Think of IEEE488 recorders or
* parallel computer bus loggers. The scan option eliminates
* the issue of looking up previously assigned names before
* renaming a channel (see sigrok-cli -C), which depends on
* the device as well as the application, and is undesirable.
* The scan option is limited to those drivers which implement
* support for it, but works identically across those drivers.
*
* The value is a string, either a comma separated list of
* probe names, or an alias for a typical set of names.
*/
SR_CONF_PROBE_NAMES,

/* Update sr_key_info_config[] (hwdriver.c) upon changes! */

/*--- Device (or channel group) configuration -----------------------*/
Expand Down
4 changes: 4 additions & 0 deletions include/libsigrok/proto.h
Expand Up @@ -253,6 +253,10 @@ SR_API uint64_t sr_parse_timestring(const char *timestring);
SR_API gboolean sr_parse_boolstring(const char *boolstring);
SR_API int sr_parse_period(const char *periodstr, uint64_t *p, uint64_t *q);
SR_API int sr_parse_voltage(const char *voltstr, uint64_t *p, uint64_t *q);
SR_API char **sr_parse_probe_names(const char *spec,
const char **dflt_names, size_t dflt_count,
size_t max_count, size_t *ret_count);
SR_API void sr_free_probe_names(char **names);
SR_API int sr_sprintf_ascii(char *buf, const char *format, ...);
SR_API int sr_vsprintf_ascii(char *buf, const char *format, va_list args);
SR_API int sr_snprintf_ascii(char *buf, size_t buf_size,
Expand Down
7 changes: 5 additions & 2 deletions src/device.c
Expand Up @@ -67,7 +67,7 @@ SR_PRIV struct sr_channel *sr_channel_new(struct sr_dev_inst *sdi,
ch->index = index;
ch->type = type;
ch->enabled = enabled;
if (name)
if (name && *name)
ch->name = g_strdup(name);

sdi->channels = g_slist_append(sdi->channels, ch);
Expand Down Expand Up @@ -120,6 +120,8 @@ SR_API int sr_dev_channel_name_set(struct sr_channel *channel,
{
if (!channel)
return SR_ERR_ARG;
if (!name || !*name)
return SR_ERR_ARG;

g_free(channel->name);
channel->name = g_strdup(name);
Expand Down Expand Up @@ -489,7 +491,8 @@ SR_API int sr_dev_inst_channel_add(struct sr_dev_inst *sdi, int index, int type,
if (!sdi || sdi->inst_type != SR_INST_USER || index < 0)
return SR_ERR_ARG;

sr_channel_new(sdi, index, type, TRUE, name);
if (!sr_channel_new(sdi, index, type, TRUE, name))
return SR_ERR_DATA;

return SR_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dmm/bm52x.c
Expand Up @@ -1362,7 +1362,7 @@ SR_PRIV int brymen_bm52x_config_get(void *st, uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct brymen_bm52x_state *state;
char text[20];
char text[32];

state = st;

Expand Down
18 changes: 18 additions & 0 deletions src/dmm/bm86x.c
Expand Up @@ -59,6 +59,22 @@ SR_PRIV gboolean sr_brymen_bm86x_packet_valid(const uint8_t *buf)
if (buf[19] != 0x86)
return FALSE;

/*
* 2021-05 update: The devices that we have seen in the field do
* provide four bytes which we can synchronize to. Which happens
* to match the bm52x and bm82x devices' protocol. This condition
* is not documented by the vendor, but improves reliability of
* the re-synchronization for slight offsets, which were seen
* in the field, and which would have kept failing in an earlier
* implementation.
*/
if (buf[16] != 0x86)
return FALSE;
if (buf[17] != 0x86)
return FALSE;
if (buf[18] != 0x86)
return FALSE;

return TRUE;
}

Expand Down Expand Up @@ -286,6 +302,8 @@ static void brymen_bm86x_parse(const uint8_t *buf, float *floatval,
NULL, &temp_unit, NULL, 0x80);
ret = brymen_bm86x_parse_digits(&buf[9], 4, txtbuf,
floatval, NULL, &digits, 0x10);
if (ret != SR_OK)
return;

/* SI unit. */
if (buf[14] & 0x08) {
Expand Down
2 changes: 2 additions & 0 deletions src/dmm/eev121gw.c
Expand Up @@ -762,6 +762,8 @@ static int sr_eev121gw_parse(const uint8_t *buf, float *floatval,
ser_mon = FIELD_NL(raw_serial, SERIAL_MONTH);
ser_nr = FIELD_NL(raw_serial, SERIAL_NUMBER);
sr_spew("Packet: Y-M %x-%x, nr %x.", ser_year, ser_mon, ser_nr);
} else {
(void)raw_serial; /* Silence compiler warning. */
}

switch (display) {
Expand Down
11 changes: 6 additions & 5 deletions src/drivers.c
Expand Up @@ -25,11 +25,12 @@
#include "libsigrok-internal.h"

/*
* sr_driver_list is a special section contains pointers to all the hardware
* drivers built into the library. The __start and __stop symbols are
* created from driver_list_start.c and driver_list_stop.c, and point to the
* start and end of the section. They are used to iterate over the list of
* all drivers.
* The special __sr_driver_list section contains pointers to all hardware
* drivers which were built into the library according to its configuration
* (will depend on the availability of dependencies, as well as user provided
* specs). The __start and __stop symbols point to the start and end of the
* section. They are used to iterate over the list of all drivers which were
* included in the library.
*/
SR_PRIV extern const struct sr_dev_driver *sr_driver_list__start[];
SR_PRIV extern const struct sr_dev_driver *sr_driver_list__stop[];
Expand Down
27 changes: 20 additions & 7 deletions src/hardware/asix-omega-rtm-cli/api.c
Expand Up @@ -126,9 +126,10 @@ static const uint32_t devopts[] = {

static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
const char *conn, *serno, *exe;
GSList *devices;
size_t argc, chidx;
const char *conn, *probe_names, *serno, *exe;
GSList *devices, *l;
struct sr_config *src;
size_t argc, chmax, chidx;
gchar **argv, *output, *vers_text, *eol;
GSpawnFlags flags;
GError *error;
Expand All @@ -139,9 +140,18 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)

/* Extract optional serial number from conn= spec. */
conn = NULL;
probe_names = NULL;
(void)sr_serial_extract_options(options, &conn, NULL);
if (!conn || !*conn)
conn = NULL;
for (l = options; l; l = l->next) {
src = l->data;
switch (src->key) {
case SR_CONF_PROBE_NAMES:
probe_names = g_variant_get_string(src->data, NULL);
break;
}
}
serno = NULL;
if (conn) {
if (!g_str_has_prefix(conn, "sn=")) {
Expand Down Expand Up @@ -242,13 +252,16 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->serial_num = g_strdup(serno);
if (conn)
sdi->connection_id = g_strdup(conn);
for (chidx = 0; chidx < ARRAY_SIZE(channel_names); chidx++) {
devc = g_malloc0(sizeof(*devc));
sdi->priv = devc;
devc->channel_names = sr_parse_probe_names(probe_names,
channel_names, ARRAY_SIZE(channel_names),
ARRAY_SIZE(channel_names), &chmax);
for (chidx = 0; chidx < chmax; chidx++) {
sr_channel_new(sdi, chidx, SR_CHANNEL_LOGIC,
TRUE, channel_names[chidx]);
TRUE, devc->channel_names[chidx]);
}

devc = g_malloc0(sizeof(*devc));
sdi->priv = devc;
sr_sw_limits_init(&devc->limits);
argc = 1;
g_free(argv[argc]);
Expand Down
1 change: 1 addition & 0 deletions src/hardware/asix-omega-rtm-cli/protocol.h
Expand Up @@ -32,6 +32,7 @@
#define FEED_QUEUE_DEPTH (256 * 1024)

struct dev_context {
char **channel_names;
struct sr_sw_limits limits;
struct {
gchar **argv;
Expand Down
36 changes: 29 additions & 7 deletions src/hardware/asix-sigma/api.c
Expand Up @@ -35,6 +35,7 @@ static const char *channel_names[] = {

static const uint32_t scanopts[] = {
SR_CONF_CONN,
SR_CONF_PROBE_NAMES,
};

static const uint32_t drvopts[] = {
Expand Down Expand Up @@ -109,6 +110,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
struct drv_context *drvc;
libusb_context *usbctx;
const char *conn;
const char *probe_names;
GSList *l, *conn_devices;
struct sr_config *src;
GSList *devices;
Expand All @@ -126,18 +128,23 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
struct sr_dev_inst *sdi;
struct dev_context *devc;
size_t devidx, chidx;
size_t count;

drvc = di->context;
usbctx = drvc->sr_ctx->libusb_ctx;

/* Find all devices which match an (optional) conn= spec. */
conn = NULL;
probe_names = NULL;
for (l = options; l; l = l->next) {
src = l->data;
switch (src->key) {
case SR_CONF_CONN:
conn = g_variant_get_string(src->data, NULL);
break;
case SR_CONF_PROBE_NAMES:
probe_names = g_variant_get_string(src->data, NULL);
break;
}
}
conn_devices = NULL;
Expand Down Expand Up @@ -234,12 +241,14 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->model = g_strdup(dev_text);
sdi->serial_num = g_strdup(serno_txt);
sdi->connection_id = g_strdup(conn_id);
for (chidx = 0; chidx < ARRAY_SIZE(channel_names); chidx++)
sr_channel_new(sdi, chidx, SR_CHANNEL_LOGIC,
TRUE, channel_names[chidx]);

devc = g_malloc0(sizeof(*devc));
sdi->priv = devc;
devc->channel_names = sr_parse_probe_names(probe_names,
channel_names, ARRAY_SIZE(channel_names),
ARRAY_SIZE(channel_names), &count);
for (chidx = 0; chidx < count; chidx++)
sr_channel_new(sdi, chidx, SR_CHANNEL_LOGIC,
TRUE, devc->channel_names[chidx]);
devc->id.vid = des.idVendor;
devc->id.pid = des.idProduct;
devc->id.serno = serno_num;
Expand Down Expand Up @@ -304,7 +313,7 @@ static int config_get(uint32_t key, GVariant **data,
*data = g_variant_new_boolean(devc->clock.use_ext_clock);
break;
case SR_CONF_EXTERNAL_CLOCK_SOURCE:
clock_text = channel_names[devc->clock.clock_pin];
clock_text = devc->channel_names[devc->clock.clock_pin];
*data = g_variant_new_string(clock_text);
break;
case SR_CONF_CLOCK_EDGE:
Expand All @@ -330,6 +339,8 @@ static int config_set(uint32_t key, GVariant *data,
struct dev_context *devc;
int ret;
uint64_t want_rate, have_rate;
const char **names;
size_t count;
int idx;

(void)cg;
Expand Down Expand Up @@ -357,7 +368,9 @@ static int config_set(uint32_t key, GVariant *data,
devc->clock.use_ext_clock = g_variant_get_boolean(data);
break;
case SR_CONF_EXTERNAL_CLOCK_SOURCE:
idx = std_str_idx(data, ARRAY_AND_SIZE(channel_names));
names = (const char **)devc->channel_names;
count = g_strv_length(devc->channel_names);
idx = std_str_idx(data, names, count);
if (idx < 0)
return SR_ERR_ARG;
devc->clock.clock_pin = idx;
Expand All @@ -384,6 +397,11 @@ static int config_set(uint32_t key, GVariant *data,
static int config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc;
const char **names;
size_t count;

devc = sdi ? sdi->priv : NULL;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
Expand All @@ -395,7 +413,11 @@ static int config_list(uint32_t key, GVariant **data,
*data = sigma_get_samplerates_list();
break;
case SR_CONF_EXTERNAL_CLOCK_SOURCE:
*data = g_variant_new_strv(ARRAY_AND_SIZE(channel_names));
if (!devc)
return SR_ERR_ARG;
names = (const char **)devc->channel_names;
count = g_strv_length(devc->channel_names);
*data = g_variant_new_strv(names, count);
break;
case SR_CONF_CLOCK_EDGE:
*data = g_variant_new_strv(ARRAY_AND_SIZE(ext_clock_edges));
Expand Down
1 change: 1 addition & 0 deletions src/hardware/asix-sigma/protocol.h
Expand Up @@ -330,6 +330,7 @@ struct dev_context {
uint16_t prefix;
enum asix_device_type type;
} id;
char **channel_names;
struct {
struct ftdi_context ctx;
gboolean is_open, must_close;
Expand Down

0 comments on commit 1f81da0

Please sign in to comment.