#define LOG_PREFIX "analog"
+SR_PRIV int sr_analog_init(struct sr_datafeed_analog2 *analog,
+ struct sr_analog_encoding *encoding,
+ struct sr_analog_meaning *meaning,
+ struct sr_analog_spec *spec,
+ int digits)
+{
+ memset(analog, 0, sizeof(*analog));
+ memset(encoding, 0, sizeof(*encoding));
+ memset(meaning, 0, sizeof(*meaning));
+ memset(spec, 0, sizeof(*spec));
+
+ analog->encoding = encoding;
+ analog->meaning = meaning;
+ analog->spec = spec;
+
+ encoding->unitsize = sizeof(float);
+ encoding->is_float = TRUE;
+#ifdef WORDS_BIGENDIAN
+ encoding->is_bigendian = TRUE;
+#else
+ encoding->is_bigendian = FALSE;
+#endif
+ encoding->digits = digits;
+ encoding->is_digits_decimal = TRUE;
+ encoding->scale.p = 1;
+ encoding->scale.q = 1;
+ encoding->offset.p = 0;
+ encoding->offset.q = 1;
+
+ spec->spec_digits = digits;
+
+ return SR_OK;
+}
+
SR_API int sr_analog_to_float(const struct sr_datafeed_analog2 *analog,
float *buf)
{
return SR_ERR;
}
- memset(&analog, 0, sizeof(struct sr_datafeed_analog));
- memset(&encoding, 0, sizeof(struct sr_analog_encoding));
- memset(&meaning, 0, sizeof(struct sr_analog_meaning));
- memset(&spec, 0, sizeof(struct sr_analog_spec));
+ sr_analog_init(&analog, &encoding, &meaning, &spec, 3);
/* Common values for both channels. */
packet.type = SR_DF_ANALOG2;
packet.payload = &analog;
- analog.encoding = &encoding;
- analog.meaning = &meaning;
- analog.spec = &spec;
analog.num_samples = 1;
- encoding.unitsize = sizeof(float);
- encoding.is_float = TRUE;
-#ifdef WORDS_BIGENDIAN
- encoding.is_bigendian = TRUE;
-#else
- encoding.is_bigendian = FALSE;
-#endif
- encoding.digits = 3; /* Values are always 3-digit numbers. */
- encoding.is_digits_decimal = TRUE;
- encoding.scale.p = 1;
- encoding.scale.q = 1;
- encoding.offset.p = 0;
- encoding.offset.q = 1;
- spec.spec_digits = encoding.digits;
/* Temperature. */
l = g_slist_copy(sdi->channels);
if (minus)
fvalue = -fvalue;
- memset(&analog, 0, sizeof(struct sr_datafeed_analog2));
- memset(&encoding, 0, sizeof(struct sr_analog_encoding));
- memset(&meaning, 0, sizeof(struct sr_analog_meaning));
- memset(&spec, 0, sizeof(struct sr_analog_spec));
+ sr_analog_init(&analog, &encoding, &meaning, &spec, 4);
/* Measurement mode */
meaning.channels = sdi->channels;
if (is_relative)
meaning.mqflags |= SR_MQFLAG_RELATIVE;
- encoding.unitsize = sizeof(float);
- encoding.is_float = TRUE;
-#ifdef WORDS_BIGENDIAN
- encoding.is_bigendian = TRUE;
-#else
- encoding.is_bigendian = FALSE;
-#endif
- encoding.digits = 4; /* Values are always 4-digit numbers. */
- encoding.is_digits_decimal = TRUE;
- encoding.scale.p = 1;
- encoding.scale.q = 1;
- encoding.offset.p = 0;
- encoding.offset.q = 1;
-
- spec.spec_digits = encoding.digits;
-
analog.data = &fvalue;
analog.num_samples = 1;
- analog.encoding = &encoding;
- analog.meaning = &meaning;
- analog.spec = &spec;
packet.type = SR_DF_ANALOG2;
packet.payload = &analog;
struct sr_datafeed_packet **copy);
SR_PRIV void sr_packet_free(struct sr_datafeed_packet *packet);
+/*--- analog.c --------------------------------------------------------------*/
+
+SR_PRIV int sr_analog_init(struct sr_datafeed_analog2 *analog,
+ struct sr_analog_encoding *encoding,
+ struct sr_analog_meaning *meaning,
+ struct sr_analog_spec *spec,
+ int digits);
+
/*--- std.c -----------------------------------------------------------------*/
typedef int (*dev_close_callback)(struct sr_dev_inst *sdi);