]> sigrok.org Git - libsigrok.git/commitdiff
binary helpers: add "invalid" enum item, improve readability
authorGerhard Sittig <redacted>
Wed, 22 Dec 2021 12:45:22 +0000 (13:45 +0100)
committerGerhard Sittig <redacted>
Wed, 22 Dec 2021 19:04:28 +0000 (20:04 +0100)
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
src/libsigrok-internal.h

index 9108f5bb7678983e04aad9c753696db4fbbbee0d..86c4c5838fce2bf470524bd3c2a0b8859a741514 100644 (file)
@@ -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;
index 4e4143009a9c506f2ab34ab58583a3c784bce296..25297f4c9386561d8583494cf9e2c2c75e7cd3f6 100644 (file)
@@ -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,