X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fbinary_helpers.c;h=7482371cf577e7aa48fda36bfd2d59a7e0dd5a80;hb=9697b4a5a4be6639909fe0f10bd10f8a486e036b;hp=72c05ef101a0cbc33e161971d0a32ae95a16441c;hpb=48b7c90166221e69aee1b618fe8ecced8be90f9b;p=libsigrok.git diff --git a/src/binary_helpers.c b/src/binary_helpers.c index 72c05ef1..7482371c 100644 --- a/src/binary_helpers.c +++ b/src/binary_helpers.c @@ -62,3 +62,54 @@ SR_PRIV int bv_get_value_len(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_BE_UINT64: + value = read_u64be(ptr); + break; + case BVT_BE_FLOAT: + value = read_fltbe(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; + case BVT_LE_UINT64: + value = read_u64le(ptr); + break; + case BVT_LE_FLOAT: + value = read_fltle(ptr); + break; + default: + return SR_ERR_ARG; + } + + if (out) + *out = value; + return SR_OK; +}