From: Gerhard Sittig Date: Mon, 17 Jun 2019 20:51:36 +0000 (+0200) Subject: serial-lcr: add support for chip specific channel names X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3f5473dde2044130f8cb405e2a3ebb43c226a474;p=libsigrok.git serial-lcr: add support for chip specific channel names Allow LCR chip drivers to specify custom printf() formats for their channel names. Default to "P1" etc in the absence of format specs. This implementation is similar to serial-dmm. --- diff --git a/src/hardware/serial-lcr/api.c b/src/hardware/serial-lcr/api.c index 002fb5bf..5bf5f184 100644 --- a/src/hardware/serial-lcr/api.c +++ b/src/hardware/serial-lcr/api.c @@ -98,6 +98,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) struct sr_dev_inst *sdi; struct dev_context *devc; size_t ch_idx; + const char **ch_fmts; + const char *fmt; char ch_name[8]; lcr = (struct lcr_info *)di; @@ -163,8 +165,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi->priv = devc; devc->lcr_info = lcr; sr_sw_limits_init(&devc->limits); + ch_fmts = lcr->channel_formats; for (ch_idx = 0; ch_idx < lcr->channel_count; ch_idx++) { - snprintf(ch_name, sizeof(ch_name), "P%zu", ch_idx + 1); + fmt = (ch_fmts && ch_fmts[ch_idx]) ? ch_fmts[ch_idx] : "P%zu"; + snprintf(ch_name, sizeof(ch_name), fmt, ch_idx + 1); sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, ch_name); } devices = g_slist_append(devices, sdi); @@ -323,7 +327,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) .dev_acquisition_stop = std_serial_dev_acquisition_stop, \ .context = NULL, \ }, \ - vendor, model, ES51919_CHANNEL_COUNT, \ + vendor, model, ES51919_CHANNEL_COUNT, NULL, \ ES51919_COMM_PARAM, ES51919_PACKET_SIZE, \ es51919_packet_valid, es51919_packet_parse, \ NULL, NULL, es51919_config_list, \ diff --git a/src/hardware/serial-lcr/protocol.h b/src/hardware/serial-lcr/protocol.h index 8e11733c..292a10ea 100644 --- a/src/hardware/serial-lcr/protocol.h +++ b/src/hardware/serial-lcr/protocol.h @@ -33,6 +33,7 @@ struct lcr_info { const char *vendor; const char *model; size_t channel_count; + const char **channel_formats; const char *comm; size_t packet_size; gboolean (*packet_valid)(const uint8_t *pkt);