]> sigrok.org Git - libsigrok.git/blobdiff - src/binary_helpers.c
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / src / binary_helpers.c
index e15787e9feb0f655b40b69f12a850499ddc4bdb0..14196110475e00c34d66bdb32d194587437af307 100644 (file)
@@ -22,8 +22,8 @@
 #include <libsigrok/libsigrok.h>
 #include "libsigrok-internal.h"
 
-SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec,
-       const void *data, size_t length)
+SR_PRIV int bv_get_value_len(float *out, const struct binary_value_spec *spec,
+       const uint8_t *data, size_t length)
 {
        float value;
 
@@ -43,14 +43,10 @@ SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec,
        VALUE_TYPE(BVT_BE_UINT16, read_u16be, sizeof(uint16_t));
        VALUE_TYPE(BVT_BE_UINT24, read_u24be, 3 * sizeof(uint8_t));
        VALUE_TYPE(BVT_BE_UINT32, read_u32be, sizeof(uint32_t));
-       VALUE_TYPE(BVT_BE_UINT64, read_u64be, sizeof(uint64_t));
-       VALUE_TYPE(BVT_BE_FLOAT,  read_fltbe, sizeof(float));
 
        VALUE_TYPE(BVT_LE_UINT16, read_u16le, sizeof(uint16_t));
        VALUE_TYPE(BVT_LE_UINT24, read_u24le, 3 * sizeof(uint8_t));
        VALUE_TYPE(BVT_LE_UINT32, read_u32le, sizeof(uint32_t));
-       VALUE_TYPE(BVT_LE_UINT64, read_u64le, sizeof(uint64_t));
-       VALUE_TYPE(BVT_LE_FLOAT,  read_fltle, sizeof(float));
 
        default:
                return SR_ERR_ARG;
@@ -62,3 +58,42 @@ SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec,
                *out = value;
        return SR_OK;
 }
+
+SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec,
+       const uint8_t *data)
+{
+       float value;
+       const uint8_t *ptr;
+
+       ptr = &data[spec->offset];
+
+       switch (spec->type) {
+       case BVT_UINT8:
+               value = read_u8(ptr);
+               break;
+       case BVT_BE_UINT16:
+               value = read_u16be(ptr);
+               break;
+       case BVT_BE_UINT24:
+               value = read_u24be(ptr);
+               break;
+       case BVT_BE_UINT32:
+               value = read_u32be(ptr);
+               break;
+       case BVT_LE_UINT16:
+               value = read_u16le(ptr);
+               break;
+       case BVT_LE_UINT24:
+               value = read_u24le(ptr);
+               break;
+       case BVT_LE_UINT32:
+               value = read_u32le(ptr);
+               break;
+       default:
+               return SR_ERR_ARG;
+       }
+
+       if (out)
+               *out = value;
+       return SR_OK;
+}