From: Gerhard Sittig Date: Wed, 15 Mar 2023 18:01:57 +0000 (+0100) Subject: rdtech-um: rephrase channel count in profile description X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=7cfa93b013341e1980461c4a56c8d8c0bca800c8;p=libsigrok.git rdtech-um: rephrase channel count in profile description Use ARRAY_AND_SIZE() instead of the ALL_ZERO terminator for the list of channels in a model's profile. This improves iteration readability, avoids off-by-one issues, eliminates "empty slot?" checks in numerical iteration over indices. Rename channel list identifiers to reduce the text line length in the source code. --- diff --git a/src/hardware/rdtech-um/api.c b/src/hardware/rdtech-um/api.c index 768596a6..ce0356e0 100644 --- a/src/hardware/rdtech-um/api.c +++ b/src/hardware/rdtech-um/api.c @@ -80,8 +80,10 @@ static GSList *rdtech_um_scan(struct sr_dev_driver *di, sdi->inst_type = SR_INST_SERIAL; sdi->conn = serial; - for (ch_idx = 0; (name = p->channels[ch_idx].name); ch_idx++) + for (ch_idx = 0; ch_idx < p->channel_count; ch_idx++) { + name = p->channels[ch_idx].name; sr_channel_new(sdi, ch_idx, SR_CHANNEL_ANALOG, TRUE, name); + } devices = g_slist_append(NULL, sdi); serial_close(serial); diff --git a/src/hardware/rdtech-um/protocol.c b/src/hardware/rdtech-um/protocol.c index 763ad95b..5d3ab6ea 100644 --- a/src/hardware/rdtech-um/protocol.c +++ b/src/hardware/rdtech-um/protocol.c @@ -39,7 +39,7 @@ /* Command code to request another poll response. */ #define UM_CMD_POLL 0xf0 -static const struct binary_analog_channel rdtech_default_channels[] = { +static const struct binary_analog_channel default_channels[] = { { "V", { 2, BVT_BE_UINT16, 0.01, }, 2, SR_MQ_VOLTAGE, SR_UNIT_VOLT }, { "I", { 4, BVT_BE_UINT16, 0.001, }, 3, SR_MQ_CURRENT, SR_UNIT_AMPERE }, { "D+", { 96, BVT_BE_UINT16, 0.01, }, 2, SR_MQ_VOLTAGE, SR_UNIT_VOLT }, @@ -47,10 +47,9 @@ static const struct binary_analog_channel rdtech_default_channels[] = { { "T", { 10, BVT_BE_UINT16, 1.0, }, 0, SR_MQ_TEMPERATURE, SR_UNIT_CELSIUS }, /* Threshold-based recording (mWh) */ { "E", { 106, BVT_BE_UINT32, 0.001, }, 3, SR_MQ_ENERGY, SR_UNIT_WATT_HOUR }, - ALL_ZERO, }; -static const struct binary_analog_channel rdtech_um25c_channels[] = { +static const struct binary_analog_channel um25c_channels[] = { { "V", { 2, BVT_BE_UINT16, 0.001, }, 3, SR_MQ_VOLTAGE, SR_UNIT_VOLT }, { "I", { 4, BVT_BE_UINT16, 0.0001, }, 4, SR_MQ_CURRENT, SR_UNIT_AMPERE }, { "D+", { 96, BVT_BE_UINT16, 0.01, }, 2, SR_MQ_VOLTAGE, SR_UNIT_VOLT }, @@ -58,7 +57,6 @@ static const struct binary_analog_channel rdtech_um25c_channels[] = { { "T", { 10, BVT_BE_UINT16, 1.0, }, 0, SR_MQ_TEMPERATURE, SR_UNIT_CELSIUS }, /* Threshold-based recording (mWh) */ { "E", { 106, BVT_BE_UINT32, 0.001, }, 3, SR_MQ_ENERGY, SR_UNIT_WATT_HOUR }, - ALL_ZERO, }; static gboolean csum_ok_fff1(const uint8_t *buf, size_t len) @@ -100,9 +98,9 @@ static gboolean csum_ok_um34c(const uint8_t *buf, size_t len) } static const struct rdtech_um_profile um_profiles[] = { - { "UM24C", RDTECH_UM24C, rdtech_default_channels, csum_ok_fff1, }, - { "UM25C", RDTECH_UM25C, rdtech_um25c_channels, csum_ok_fff1, }, - { "UM34C", RDTECH_UM34C, rdtech_default_channels, csum_ok_um34c, }, + { "UM24C", RDTECH_UM24C, ARRAY_AND_SIZE(default_channels), csum_ok_fff1, }, + { "UM25C", RDTECH_UM25C, ARRAY_AND_SIZE(um25c_channels), csum_ok_fff1, }, + { "UM34C", RDTECH_UM34C, ARRAY_AND_SIZE(default_channels), csum_ok_um34c, }, }; static const struct rdtech_um_profile *find_profile(uint16_t id) diff --git a/src/hardware/rdtech-um/protocol.h b/src/hardware/rdtech-um/protocol.h index dfe1cd75..e501e920 100644 --- a/src/hardware/rdtech-um/protocol.h +++ b/src/hardware/rdtech-um/protocol.h @@ -38,6 +38,7 @@ struct rdtech_um_profile { const char *model_name; enum rdtech_um_model_id model_id; const struct binary_analog_channel *channels; + size_t channel_count; gboolean (*csum_ok)(const uint8_t *buf, size_t len); };