SR_DF_ANALOG2 and sr_datafeed_analog2 renames.
Rename SR_DF_ANALOG2 to SR_DF_ANALOG, and 'struct sr_datafeed_analog2' to 'struct sr_datafeed_analog'.
This commit is contained in:
parent
5faebab290
commit
edb691fced
|
@ -168,13 +168,13 @@ enum sr_packettype {
|
|||
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,
|
||||
|
@ -237,7 +237,7 @@ enum sr_mq {
|
|||
/* 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,
|
||||
|
@ -331,7 +331,7 @@ enum sr_unit {
|
|||
*/
|
||||
};
|
||||
|
||||
/** 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,
|
||||
|
@ -512,8 +512,8 @@ struct sr_datafeed_analog_old {
|
|||
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;
|
||||
|
|
|
@ -28,10 +28,10 @@
|
|||
|
||||
/*--- 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);
|
||||
|
||||
|
|
|
@ -117,7 +117,7 @@ static struct unit_mq_string mq_strings[] = {
|
|||
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,
|
||||
|
@ -151,7 +151,7 @@ SR_PRIV int sr_analog_init(struct sr_datafeed_analog2 *analog,
|
|||
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;
|
||||
|
@ -245,7 +245,7 @@ SR_API int sr_analog_float_to_string(float value, int digits, char **result)
|
|||
*
|
||||
* @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;
|
||||
|
|
|
@ -95,7 +95,7 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx)
|
|||
{
|
||||
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;
|
||||
|
@ -116,7 +116,7 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx)
|
|||
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;
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ static uint8_t decode_digit(uint8_t in)
|
|||
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;
|
||||
|
@ -260,7 +260,7 @@ static void decode_buf(struct sr_dev_inst *sdi, unsigned char *data)
|
|||
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);
|
||||
|
||||
|
|
|
@ -759,7 +759,7 @@ SR_PRIV GKeyFile *sr_sessionfile_read_metadata(struct zip *archive,
|
|||
|
||||
/*--- 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,
|
||||
|
|
|
@ -279,7 +279,7 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
|
|||
{
|
||||
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;
|
||||
|
@ -313,27 +313,27 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
|
|||
}
|
||||
}
|
||||
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],
|
||||
|
|
|
@ -193,7 +193,7 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
|
|||
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;
|
||||
|
@ -269,9 +269,9 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
|
|||
}
|
||||
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;
|
||||
|
@ -279,11 +279,11 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
|
|||
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;
|
||||
|
@ -262,7 +262,7 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
|
|||
}
|
||||
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;
|
||||
|
@ -270,7 +270,7 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
|
|||
*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;
|
||||
|
@ -278,11 +278,11 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -1001,7 +1001,7 @@ static void datafeed_dump(const struct sr_datafeed_packet *packet)
|
|||
{
|
||||
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) {
|
||||
|
@ -1033,10 +1033,10 @@ static void datafeed_dump(const struct sr_datafeed_packet *packet)
|
|||
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);
|
||||
|
@ -1082,20 +1082,20 @@ SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
|
|||
}
|
||||
|
||||
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;
|
||||
|
@ -1115,7 +1115,7 @@ SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
|
|||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1468,8 +1468,8 @@ SR_PRIV int sr_packet_copy(const struct sr_datafeed_packet *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));
|
||||
|
@ -1512,23 +1512,23 @@ SR_PRIV int sr_packet_copy(const struct sr_datafeed_packet *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);
|
||||
|
@ -1543,7 +1543,7 @@ void sr_packet_free(struct sr_datafeed_packet *packet)
|
|||
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;
|
||||
|
||||
|
@ -1577,13 +1577,13 @@ void sr_packet_free(struct sr_datafeed_packet *packet)
|
|||
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:
|
||||
|
|
|
@ -31,7 +31,7 @@ static int receive(const struct sr_transform *t,
|
|||
{
|
||||
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;
|
||||
|
@ -68,14 +68,14 @@ static int receive(const struct sr_transform *t,
|
|||
}
|
||||
}
|
||||
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);
|
||||
|
|
|
@ -50,7 +50,7 @@ static int receive(const struct sr_transform *t,
|
|||
{
|
||||
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;
|
||||
|
@ -76,10 +76,10 @@ static int receive(const struct sr_transform *t,
|
|||
}
|
||||
}
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue