From: Gerhard Sittig Date: Wed, 15 Mar 2023 22:59:02 +0000 (+0100) Subject: binary helper: drop analog channel support (submit samples to feed) X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e7fe5bb4974e9c4f8f28ab219fdf4c425c510ec2;p=libsigrok.git binary helper: drop analog channel support (submit samples to feed) Remove the bv_send_analog_channel() routine and its data types. All callers have migrated to the common feed queue API. Extracting numbers from raw binary images remains the only use case for binary helpers. Prefer read_u8() et al endianess aware readers over R8() preprocessor macros. Reduce indentation in the switch() cases according to style. Accept scale factor 0 to mean no scaling in addition to factor 1. Update comments to avoid the redundant "binary blob" phrase. --- diff --git a/src/binary_helpers.c b/src/binary_helpers.c index a15f5cfb..e1c00ddd 100644 --- a/src/binary_helpers.c +++ b/src/binary_helpers.c @@ -38,17 +38,17 @@ SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec, break switch (spec->type) { - VALUE_TYPE(BVT_UINT8, R8, sizeof(uint8_t)); + VALUE_TYPE(BVT_UINT8, read_u8, sizeof(uint8_t)); - 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_BE_UINT16, read_u16be, sizeof(uint16_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, 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)); + VALUE_TYPE(BVT_LE_UINT16, read_u16le, sizeof(uint16_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; @@ -56,52 +56,9 @@ SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec, #undef VALUE_TYPE - *out = value * spec->scale; + if (spec->scale) + value *= spec->scale; + if (out) + *out = value; return SR_OK; } - -SR_PRIV int bv_send_analog_channel(const struct sr_dev_inst *sdi, - struct sr_channel *ch, const struct binary_analog_channel *bac, - const void *data, size_t length) -{ - int err; - struct sr_analog_encoding encoding; - struct sr_analog_meaning meaning; - struct sr_analog_spec spec; - struct sr_datafeed_analog analog; - struct sr_datafeed_packet packet = { - .type = SR_DF_ANALOG, - .payload = &analog, - }; - float value; - - err = bv_get_value(&value, &bac->spec, data, length); - if (err != SR_OK) - goto err_out; - - err = sr_analog_init(&analog, &encoding, &meaning, &spec, bac->digits); - if (err != SR_OK) - goto err_out; - - meaning.mq = bac->mq; - meaning.unit = bac->unit; - meaning.mqflags = 0; - meaning.channels = g_slist_append(NULL, ch); - - spec.spec_digits = bac->digits; - - analog.data = &value; - analog.num_samples = 1; - - err = sr_session_send(sdi, &packet); - if (err != SR_OK) - goto err_free; - - return SR_OK; - -err_free: - g_slist_free(meaning.channels); - -err_out: - return err; -} diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 22ef892b..8bd78eba 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -2163,22 +2163,13 @@ enum binary_value_type { /** Binary value specification */ struct binary_value_spec { - size_t offset; /**!< Offset into binary blob */ + size_t offset; /**!< Offset into binary image */ enum binary_value_type type; /**!< Data type to decode */ float scale; /**!< Scale factor to native units */ }; -/** Binary channel definition */ -struct binary_analog_channel { - const char *name; /**!< Channel name */ - struct binary_value_spec spec; /**!< Binary value in data stream */ - int digits; /**!< Significant digits */ - enum sr_mq mq; /**!< Measured quantity */ - enum sr_unit unit; /**!< Measured unit */ -}; - /** - * Read extract a value from a binary blob. + * Read extract a value from a binary data image. * * @param[out] out Pointer to output buffer (conversion result) * @param[in] spec Binary value specification @@ -2190,22 +2181,6 @@ struct binary_analog_channel { SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec, const void *data, size_t length); -/** - * Send an analog channel packet based on a binary analog channel - * specification. - * - * @param[in] sdi Device instance - * @param[in] ch Sigrok channel - * @param[in] spec Channel specification - * @param[in] data Pointer to binary blob - * @param[in] length Size of binary blob - * - * @return SR_OK on success, SR_ERR_* error code on failure. - */ -SR_PRIV int bv_send_analog_channel(const struct sr_dev_inst *sdi, - struct sr_channel *ch, const struct binary_analog_channel *spec, - const void *data, size_t length); - /*--- crc.c -----------------------------------------------------------------*/ #define SR_CRC16_DEFAULT_INIT 0xffffU