From d65f51bf5c549e5dbacb5c6fb6636e482ff02da8 Mon Sep 17 00:00:00 2001 From: Gerhard Sittig Date: Wed, 22 Dec 2021 13:45:22 +0100 Subject: [PATCH] binary helpers: add "invalid" enum item, improve readability The "binary value" helpers would not follow the sigrok project's style of only using non-zero values for valid enum items (a zero value is assumed to always represent something "inactive" or "invalid"). Introduce the "invalid" item in the enum declaration to fixup the style issue. Rephrase the bv_get_value() routine's length specs to improve readability, match numbers in length specs to the numbers in conversion routine references. --- src/binary_helpers.c | 18 +++++++++--------- src/libsigrok-internal.h | 4 +++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/binary_helpers.c b/src/binary_helpers.c index 9108f5bb..86c4c583 100644 --- a/src/binary_helpers.c +++ b/src/binary_helpers.c @@ -37,17 +37,17 @@ SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec, const break switch (spec->type) { - VALUE_TYPE(BVT_UINT8, R8, 1); + VALUE_TYPE(BVT_UINT8, R8, sizeof(uint8_t)); - VALUE_TYPE(BVT_BE_UINT16, RB16, 2); - VALUE_TYPE(BVT_BE_UINT32, RB32, 4); - VALUE_TYPE(BVT_BE_UINT64, RB64, 8); - VALUE_TYPE(BVT_BE_FLOAT, RBFL, 4); + VALUE_TYPE(BVT_BE_UINT16, RB16, sizeof(uint16_t)); + VALUE_TYPE(BVT_BE_UINT32, RB32, sizeof(uint32_t)); + VALUE_TYPE(BVT_BE_UINT64, RB64, sizeof(uint64_t)); + VALUE_TYPE(BVT_BE_FLOAT, RBFL, sizeof(float)); - VALUE_TYPE(BVT_LE_UINT16, RL16, 2); - VALUE_TYPE(BVT_LE_UINT32, RL32, 4); - VALUE_TYPE(BVT_LE_UINT64, RL64, 8); - VALUE_TYPE(BVT_LE_FLOAT, RLFL, 4); + VALUE_TYPE(BVT_LE_UINT16, RL16, sizeof(uint16_t)); + VALUE_TYPE(BVT_LE_UINT32, RL32, sizeof(uint32_t)); + VALUE_TYPE(BVT_LE_UINT64, RL64, sizeof(uint64_t)); + VALUE_TYPE(BVT_LE_FLOAT, RLFL, sizeof(float)); default: return SR_ERR_ARG; diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 4e414300..25297f4c 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -2064,7 +2064,9 @@ SR_PRIV gboolean usb_match_manuf_prod(libusb_device *dev, /** Binary value type */ enum binary_value_type { - BVT_UINT8 = 0, + BVT_INVALID, + + BVT_UINT8, BVT_BE_UINT8 = BVT_UINT8, BVT_LE_UINT8 = BVT_UINT8, -- 2.30.2