SR_DF_FRAME_BEGIN,
/** End of frame. No payload. */
SR_DF_FRAME_END,
- /** Payload is struct sr_datafeed_analog2. */
- SR_DF_ANALOG2,
+ /** Payload is struct sr_datafeed_analog. */
+ SR_DF_ANALOG,
/* Update datafeed_dump() (session.c) upon changes! */
};
-/** Measured quantity, sr_datafeed_analog.mq. */
+/** Measured quantity, sr_analog_meaning.mq. */
enum sr_mq {
SR_MQ_VOLTAGE = 10000,
SR_MQ_CURRENT,
/* Update sr_key_info_mq[] (hwdriver.c) upon changes! */
};
-/** Unit of measured quantity, sr_datafeed_analog.unit. */
+/** Unit of measured quantity, sr_analog_meaning.unit. */
enum sr_unit {
/** Volt */
SR_UNIT_VOLT = 10000,
*/
};
-/** Values for sr_datafeed_analog.flags. */
+/** Values for sr_analog_meaning.mqflags. */
enum sr_mqflag {
/** Voltage measurement is alternating current (AC). */
SR_MQFLAG_AC = 0x01,
float *data;
};
-/** Analog datafeed payload for type SR_DF_ANALOG2. */
-struct sr_datafeed_analog2 {
+/** Analog datafeed payload for type SR_DF_ANALOG. */
+struct sr_datafeed_analog {
void *data;
uint32_t num_samples;
struct sr_analog_encoding *encoding;
/*--- analog.c --------------------------------------------------------------*/
-SR_API int sr_analog_to_float(const struct sr_datafeed_analog2 *analog,
+SR_API int sr_analog_to_float(const struct sr_datafeed_analog *analog,
float *buf);
SR_API int sr_analog_float_to_string(float value, int digits, char **result);
-SR_API int sr_analog_unit_to_string(const struct sr_datafeed_analog2 *analog,
+SR_API int sr_analog_unit_to_string(const struct sr_datafeed_analog *analog,
char **result);
SR_API void sr_rational_set(struct sr_rational *r, int64_t p, uint64_t q);
ALL_ZERO
};
-SR_PRIV int sr_analog_init(struct sr_datafeed_analog2 *analog,
+SR_PRIV int sr_analog_init(struct sr_datafeed_analog *analog,
struct sr_analog_encoding *encoding,
struct sr_analog_meaning *meaning,
struct sr_analog_spec *spec,
return SR_OK;
}
-SR_API int sr_analog_to_float(const struct sr_datafeed_analog2 *analog,
+SR_API int sr_analog_to_float(const struct sr_datafeed_analog *analog,
float *outbuf)
{
float offset;
*
* @since 0.4.0
*/
-SR_API int sr_analog_unit_to_string(const struct sr_datafeed_analog2 *analog,
+SR_API int sr_analog_unit_to_string(const struct sr_datafeed_analog *analog,
char **result)
{
int i;
{
float temperature, humidity;
struct sr_datafeed_packet packet;
- struct sr_datafeed_analog2 analog;
+ struct sr_datafeed_analog analog;
struct sr_analog_encoding encoding;
struct sr_analog_meaning meaning;
struct sr_analog_spec spec;
sr_analog_init(&analog, &encoding, &meaning, &spec, 3);
/* Common values for both channels. */
- packet.type = SR_DF_ANALOG2;
+ packet.type = SR_DF_ANALOG;
packet.payload = &analog;
analog.num_samples = 1;
static void decode_buf(struct sr_dev_inst *sdi, unsigned char *data)
{
struct sr_datafeed_packet packet;
- struct sr_datafeed_analog2 analog;
+ struct sr_datafeed_analog analog;
struct sr_analog_encoding encoding;
struct sr_analog_meaning meaning;
struct sr_analog_spec spec;
analog.data = &fvalue;
analog.num_samples = 1;
- packet.type = SR_DF_ANALOG2;
+ packet.type = SR_DF_ANALOG;
packet.payload = &analog;
sr_session_send(devc->cb_data, &packet);
/*--- analog.c --------------------------------------------------------------*/
-SR_PRIV int sr_analog_init(struct sr_datafeed_analog2 *analog,
+SR_PRIV int sr_analog_init(struct sr_datafeed_analog *analog,
struct sr_analog_encoding *encoding,
struct sr_analog_meaning *meaning,
struct sr_analog_spec *spec,
{
struct context *ctx;
const struct sr_datafeed_analog_old *analog_old;
- const struct sr_datafeed_analog2 *analog2;
+ const struct sr_datafeed_analog *analog;
struct sr_channel *ch;
GSList *l;
float *fdata;
}
}
break;
- case SR_DF_ANALOG2:
- analog2 = packet->payload;
- num_channels = g_slist_length(analog2->meaning->channels);
+ case SR_DF_ANALOG:
+ analog = packet->payload;
+ num_channels = g_slist_length(analog->meaning->channels);
if (!(fdata = g_try_malloc(
- analog2->num_samples * num_channels * sizeof(float))))
+ analog->num_samples * num_channels * sizeof(float))))
return SR_ERR_MALLOC;
- if ((ret = sr_analog_to_float(analog2, fdata)) != SR_OK)
+ if ((ret = sr_analog_to_float(analog, fdata)) != SR_OK)
return ret;
*out = g_string_sized_new(512);
- if (analog2->encoding->is_digits_decimal) {
+ if (analog->encoding->is_digits_decimal) {
if (ctx->digits == DIGITS_ALL)
- digits = analog2->encoding->digits;
+ digits = analog->encoding->digits;
else
- digits = analog2->spec->spec_digits;
+ digits = analog->spec->spec_digits;
} else {
/* TODO we don't know how to print by number of bits yet. */
digits = 6;
}
- sr_analog_unit_to_string(analog2, &suffix);
- for (i = 0; i < analog2->num_samples; i++) {
- for (l = analog2->meaning->channels, c = 0; l; l = l->next, c++) {
+ sr_analog_unit_to_string(analog, &suffix);
+ for (i = 0; i < analog->num_samples; i++) {
+ for (l = analog->meaning->channels, c = 0; l; l = l->next, c++) {
ch = l->data;
g_string_append_printf(*out, "%s: ", ch->name);
sr_analog_float_to_string(fdata[i * num_channels + c],
const struct sr_datafeed_meta *meta;
const struct sr_datafeed_logic *logic;
const struct sr_datafeed_analog_old *analog_old;
- const struct sr_datafeed_analog2 *analog2;
+ const struct sr_datafeed_analog *analog;
const struct sr_config *src;
unsigned int num_samples;
float *data;
}
break;
case SR_DF_ANALOG_OLD:
- case SR_DF_ANALOG2:
+ case SR_DF_ANALOG:
analog_old = packet->payload;
- analog2 = packet->payload;
+ analog = packet->payload;
if (packet->type == SR_DF_ANALOG_OLD) {
channels = analog_old->channels;
num_samples = analog_old->num_samples;
data = analog_old->data;
} else {
- channels = analog2->meaning->channels;
+ channels = analog->meaning->channels;
numch = g_slist_length(channels);
- num_samples = analog2->num_samples;
+ num_samples = analog->num_samples;
data = g_malloc(sizeof(float) * num_samples * numch);
- ret = sr_analog_to_float(analog2, data);
+ ret = sr_analog_to_float(analog, data);
if (ret != SR_OK)
return ret;
}
struct out_context *outc;
const struct sr_datafeed_meta *meta;
const struct sr_datafeed_analog_old *analog_old;
- const struct sr_datafeed_analog2 *analog2;
+ const struct sr_datafeed_analog *analog;
const struct sr_config *src;
struct sr_channel *ch;
GSList *l;
}
break;
case SR_DF_ANALOG_OLD:
- case SR_DF_ANALOG2:
+ case SR_DF_ANALOG:
if (!outc->header_done) {
*out = gen_header(o);
outc->header_done = TRUE;
*out = g_string_sized_new(512);
analog_old = packet->payload;
- analog2 = packet->payload;
+ analog = packet->payload;
if (packet->type == SR_DF_ANALOG_OLD) {
num_samples = analog_old->num_samples;
num_channels = g_slist_length(analog_old->channels);
data = analog_old->data;
} else {
- num_samples = analog2->num_samples;
- channels = analog2->meaning->channels;
- num_channels = g_slist_length(analog2->meaning->channels);
+ num_samples = analog->num_samples;
+ channels = analog->meaning->channels;
+ num_channels = g_slist_length(analog->meaning->channels);
data = g_malloc(sizeof(float) * num_samples * num_channels);
- ret = sr_analog_to_float(analog2, data);
+ ret = sr_analog_to_float(analog, data);
if (ret != SR_OK)
return ret;
}
{
const struct sr_datafeed_logic *logic;
const struct sr_datafeed_analog_old *analog_old;
- const struct sr_datafeed_analog2 *analog2;
+ const struct sr_datafeed_analog *analog;
/* Please use the same order as in libsigrok.h. */
switch (packet->type) {
case SR_DF_FRAME_END:
sr_dbg("bus: Received SR_DF_FRAME_END packet.");
break;
- case SR_DF_ANALOG2:
- analog2 = packet->payload;
- sr_dbg("bus: Received SR_DF_ANALOG2 packet (%d samples).",
- analog2->num_samples);
+ case SR_DF_ANALOG:
+ analog = packet->payload;
+ sr_dbg("bus: Received SR_DF_ANALOG packet (%d samples).",
+ analog->num_samples);
break;
default:
sr_dbg("bus: Received unknown packet type: %d.", packet->type);
}
if (packet->type == SR_DF_ANALOG_OLD) {
- /* Convert to SR_DF_ANALOG2. */
+ /* Convert to SR_DF_ANALOG. */
const struct sr_datafeed_analog_old *analog_old = packet->payload;
struct sr_analog_encoding encoding;
struct sr_analog_meaning meaning;
struct sr_analog_spec spec;
- struct sr_datafeed_analog2 analog2;
- struct sr_datafeed_packet a2_packet;
- a2_packet.type = SR_DF_ANALOG2;
- a2_packet.payload = &analog2;
- analog2.data = analog_old->data;
- analog2.num_samples = analog_old->num_samples;
- analog2.encoding = &encoding;
- analog2.meaning = &meaning;
- analog2.spec = &spec;
+ struct sr_datafeed_analog analog;
+ struct sr_datafeed_packet new_packet;
+ new_packet.type = SR_DF_ANALOG;
+ new_packet.payload = &analog;
+ analog.data = analog_old->data;
+ analog.num_samples = analog_old->num_samples;
+ analog.encoding = &encoding;
+ analog.meaning = &meaning;
+ analog.spec = &spec;
encoding.unitsize = sizeof(float);
encoding.is_signed = TRUE;
encoding.is_float = TRUE;
meaning.mqflags = analog_old->mqflags;
meaning.channels = analog_old->channels;
spec.spec_digits = 0;
- return sr_session_send(sdi, &a2_packet);
+ return sr_session_send(sdi, &new_packet);
}
/*
struct sr_datafeed_logic *logic_copy;
const struct sr_datafeed_analog_old *analog_old;
struct sr_datafeed_analog_old *analog_old_copy;
- const struct sr_datafeed_analog2 *analog2;
- struct sr_datafeed_analog2 *analog2_copy;
+ const struct sr_datafeed_analog *analog;
+ struct sr_datafeed_analog *analog_copy;
uint8_t *payload;
*copy = g_malloc0(sizeof(struct sr_datafeed_packet));
analog_old->num_samples * sizeof(float));
(*copy)->payload = analog_old_copy;
break;
- case SR_DF_ANALOG2:
- analog2 = packet->payload;
- analog2_copy = g_malloc(sizeof(analog2));
- analog2_copy->data = g_malloc(
- analog2->encoding->unitsize * analog2->num_samples);
- memcpy(analog2_copy->data, analog2->data,
- analog2->encoding->unitsize * analog2->num_samples);
- analog2_copy->num_samples = analog2->num_samples;
- analog2_copy->encoding = g_memdup(analog2->encoding,
+ case SR_DF_ANALOG:
+ analog = packet->payload;
+ analog_copy = g_malloc(sizeof(analog));
+ analog_copy->data = g_malloc(
+ analog->encoding->unitsize * analog->num_samples);
+ memcpy(analog_copy->data, analog->data,
+ analog->encoding->unitsize * analog->num_samples);
+ analog_copy->num_samples = analog->num_samples;
+ analog_copy->encoding = g_memdup(analog->encoding,
sizeof(struct sr_analog_encoding));
- analog2_copy->meaning = g_memdup(analog2->meaning,
+ analog_copy->meaning = g_memdup(analog->meaning,
sizeof(struct sr_analog_meaning));
- analog2_copy->meaning->channels = g_slist_copy(
- analog2->meaning->channels);
- analog2_copy->spec = g_memdup(analog2->spec,
+ analog_copy->meaning->channels = g_slist_copy(
+ analog->meaning->channels);
+ analog_copy->spec = g_memdup(analog->spec,
sizeof(struct sr_analog_spec));
- (*copy)->payload = analog2_copy;
+ (*copy)->payload = analog_copy;
break;
default:
sr_err("Unknown packet type %d", packet->type);
const struct sr_datafeed_meta *meta;
const struct sr_datafeed_logic *logic;
const struct sr_datafeed_analog_old *analog_old;
- const struct sr_datafeed_analog2 *analog2;
+ const struct sr_datafeed_analog *analog;
struct sr_config *src;
GSList *l;
g_free(analog_old->data);
g_free((void *)packet->payload);
break;
- case SR_DF_ANALOG2:
- analog2 = packet->payload;
- g_free(analog2->data);
- g_free(analog2->encoding);
- g_slist_free(analog2->meaning->channels);
- g_free(analog2->meaning);
- g_free(analog2->spec);
+ case SR_DF_ANALOG:
+ analog = packet->payload;
+ g_free(analog->data);
+ g_free(analog->encoding);
+ g_slist_free(analog->meaning->channels);
+ g_free(analog->meaning);
+ g_free(analog->spec);
g_free((void *)packet->payload);
break;
default:
{
const struct sr_datafeed_logic *logic;
const struct sr_datafeed_analog_old *analog_old;
- const struct sr_datafeed_analog2 *analog2;
+ const struct sr_datafeed_analog *analog;
struct sr_channel *ch;
GSList *l;
float *fdata, *f;
}
}
break;
- case SR_DF_ANALOG2:
- analog2 = packet_in->payload;
- p = analog2->encoding->scale.p;
- q = analog2->encoding->scale.q;
+ case SR_DF_ANALOG:
+ analog = packet_in->payload;
+ p = analog->encoding->scale.p;
+ q = analog->encoding->scale.q;
if (q > INT64_MAX)
return SR_ERR;
- analog2->encoding->scale.p = (p < 0) ? -q : q;
- analog2->encoding->scale.q = (p < 0) ? -p : p;
+ analog->encoding->scale.p = (p < 0) ? -q : q;
+ analog->encoding->scale.q = (p < 0) ? -p : p;
break;
default:
sr_spew("Unsupported packet type %d, ignoring.", packet_in->type);
{
struct context *ctx;
const struct sr_datafeed_analog_old *analog_old;
- const struct sr_datafeed_analog2 *analog2;
+ const struct sr_datafeed_analog *analog;
struct sr_channel *ch;
GSList *l;
float *fdata;
}
}
break;
- case SR_DF_ANALOG2:
- analog2 = packet_in->payload;
- analog2->encoding->scale.p *= ctx->factor.p;
- analog2->encoding->scale.q *= ctx->factor.q;
+ case SR_DF_ANALOG:
+ analog = packet_in->payload;
+ analog->encoding->scale.p *= ctx->factor.p;
+ analog->encoding->scale.q *= ctx->factor.q;
break;
default:
sr_spew("Unsupported packet type %d, ignoring.", packet_in->type);