26 #include "libsigrok-internal.h"
29 #define LOG_PREFIX "analog"
46 struct unit_mq_string {
52 static struct unit_mq_string unit_strings[] = {
94 static struct unit_mq_string mq_strings[] = {
126 memset(analog, 0,
sizeof(*analog));
127 memset(encoding, 0,
sizeof(*encoding));
128 memset(meaning, 0,
sizeof(*meaning));
129 memset(spec, 0,
sizeof(*spec));
137 #ifdef WORDS_BIGENDIAN
142 encoding->
digits = digits;
175 unsigned int b, i, count;
178 if (!analog || !(analog->
data) || !(analog->
meaning)
184 #ifdef WORDS_BIGENDIAN
194 int8_t *data8 = (int8_t *)(analog->
data);
195 int16_t *data16 = (int16_t *)(analog->
data);
196 int32_t *data32 = (int32_t *)(analog->
data);
201 for (
unsigned int i = 0; i < count; i++) {
202 outbuf[i] = scale * data8[i];
206 for (
unsigned int i = 0; i < count; i++) {
207 outbuf[i] = scale * R8(data8 + i);
213 if (is_signed && is_bigendian) {
214 for (
unsigned int i = 0; i < count; i++) {
215 outbuf[i] = scale * RB16S(&data16[i]);
218 }
else if (is_bigendian) {
219 for (
unsigned int i = 0; i < count; i++) {
220 outbuf[i] = scale * RB16(&data16[i]);
223 }
else if (is_signed) {
224 for (
unsigned int i = 0; i < count; i++) {
225 outbuf[i] = scale * RL16S(&data16[i]);
229 for (
unsigned int i = 0; i < count; i++) {
230 outbuf[i] = scale * RL16(&data16[i]);
236 if (is_signed && is_bigendian) {
237 for (
unsigned int i = 0; i < count; i++) {
238 outbuf[i] = scale * RB32S(&data32[i]);
241 }
else if (is_bigendian) {
242 for (
unsigned int i = 0; i < count; i++) {
243 outbuf[i] = scale * RB32(&data32[i]);
246 }
else if (is_signed) {
247 for (
unsigned int i = 0; i < count; i++) {
248 outbuf[i] = scale * RL32S(&data32[i]);
252 for (
unsigned int i = 0; i < count; i++) {
253 outbuf[i] = scale * RL32(&data32[i]);
259 sr_err(
"Unsupported unit size '%d' for analog-to-float conversion.",
272 memcpy(outbuf, analog->
data, count *
sizeof(
float));
277 ((uint8_t *)outbuf)[i + b] =
315 if (!analog || !(analog->
meaning) || !result)
318 buf = g_string_new(NULL);
320 for (i = 0; unit_strings[i].value; i++) {
321 if (analog->
meaning->
unit == unit_strings[i].value) {
322 g_string_assign(buf, unit_strings[i].str);
328 for (i = 0; mq_strings[i].value; i++)
330 g_string_append(buf, mq_strings[i].str);
333 g_string_free(buf, FALSE);
Sound pressure level is Z-weighted (i.e.
An absolute measurement of power, in decibels, referenced to 1 milliwatt (dBu).
Device is in autoranging mode.
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, int digits)
struct sr_analog_encoding * encoding
Pieces (number of items).
Value is voltage drop across a diode, or NAN.
The public libsigrok header file to be used by frontends.
Mass in tael (variants: Hong Kong, Singapore/Malaysia, Taiwan)
Mass in pennyweight [dwt].
Wind speed in meters per second.
Voltage measurement is alternating current (AC).
Unstable value (hasn't settled yet).
void sr_rational_set(struct sr_rational *r, int64_t p, uint64_t q)
Set sr_rational r to the given value.
Generic/unspecified error.
Device is in "hold" mode (repeating the last measurement).
Time is duration (as opposed to epoch, ...).
Sound pressure level is A-weighted in the frequency domain, according to IEC 61672:2003.
Degrees Fahrenheit (temperature).
This is a true RMS measurement.
Unit of conductance, the inverse of resistance.
Sound pressure level measurement is F-weighted (125ms) in the time domain.
Hertz (frequency, 1/s, [Hz]).
Degrees Celsius (temperature).
struct sr_rational offset
gboolean is_digits_decimal
Analog datafeed payload for type SR_DF_ANALOG.
Sound pressure level is time-averaged (LAT), also known as Equivalent Continuous A-weighted Sound Lev...
int sr_analog_to_float(const struct sr_datafeed_analog *analog, float *outbuf)
Convert an analog datafeed payload to an array of floats.
Sound pressure level is C-weighted in the frequency domain, according to IEC 61672:2003.
Voltage measurement is direct current (DC).
struct sr_analog_meaning * meaning
Device is in "min" mode, only updating upon a new min value.
Sound pressure level represented as a percentage of measurements that were over a preset alarm level...
uint64_t q
Denominator of the rational number.
int64_t p
Numerator of the rational number.
Voltage in decibel, referenced to 1 volt (dBV).
struct sr_analog_spec * spec
Relative humidity assuming air temperature of 293 Kelvin (rF).
Sound pressure level, in decibels, relative to 20 micropascals.
Device is in "max" mode, only updating upon a new max value.
Device is in relative mode.
Measurements that intrinsically do not have units attached, such as ratios, gains, etc.
Sound pressure level is not weighted in the frequency domain, albeit without standards-defined low an...
Device is in "avg" mode, averaging upon each new value.
Mass in troy ounce [oz t].
Normalized (0 to 1) concentration of a substance or compound with 0 representing a concentration of 0...
Plane angle in 1/360th of a full circle.
Sound pressure level measurement is S-weighted (1s) in the time domain.
int sr_analog_unit_to_string(const struct sr_datafeed_analog *analog, char **result)
Convert the unit/MQ/MQ flags in the analog struct to a string.