2 * This file is part of the libsigrok project.
4 * Copyright (C) 2020 Andreas Sandberg <andreas@sandberg.pp.se>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <libsigrok/libsigrok.h>
23 #include "libsigrok-internal.h"
25 SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec,
26 const void *data, size_t length)
30 if (!out || !spec || !data)
33 #define VALUE_TYPE(T, R, L) \
35 if (spec->offset + (L) > length) \
37 value = R(data + spec->offset); \
41 VALUE_TYPE(BVT_UINT8, read_u8, sizeof(uint8_t));
43 VALUE_TYPE(BVT_BE_UINT16, read_u16be, sizeof(uint16_t));
44 VALUE_TYPE(BVT_BE_UINT32, read_u32be, sizeof(uint32_t));
45 VALUE_TYPE(BVT_BE_UINT64, read_u64be, sizeof(uint64_t));
46 VALUE_TYPE(BVT_BE_FLOAT, read_fltbe, sizeof(float));
48 VALUE_TYPE(BVT_LE_UINT16, read_u16le, sizeof(uint16_t));
49 VALUE_TYPE(BVT_LE_UINT32, read_u32le, sizeof(uint32_t));
50 VALUE_TYPE(BVT_LE_UINT64, read_u64le, sizeof(uint64_t));
51 VALUE_TYPE(BVT_LE_FLOAT, read_fltle, sizeof(float));