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);
Normalized (0 to 1) concentration of a substance or compound with 0 representing a concentration of 0...
Sound pressure level measurement is S-weighted (1s) in the time domain.
Voltage measurement is alternating current (AC).
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.
struct sr_analog_encoding * encoding
Unstable value (hasn't settled yet).
Sound pressure level is Z-weighted (i.e.
Generic/unspecified error.
Time is duration (as opposed to epoch, ...).
uint64_t q
Denominator of the rational number.
An absolute measurement of power, in decibels, referenced to 1 milliwatt (dBu).
Sound pressure level is A-weighted in the frequency domain, according to IEC 61672:2003.
int sr_analog_to_float(const struct sr_datafeed_analog *analog, float *outbuf)
Convert an analog datafeed payload to an array of floats.
Pieces (number of items).
Value is voltage drop across a diode, or NAN.
Mass in tael (variants: Hong Kong, Singapore/Malaysia, Taiwan)
This is a true RMS measurement.
Unit of conductance, the inverse of resistance.
Wind speed in meters per second.
Sound pressure level measurement is F-weighted (125ms) in the time domain.
Degrees Celsius (temperature).
void sr_rational_set(struct sr_rational *r, int64_t p, uint64_t q)
Set sr_rational r to the given value.
Device is in "hold" mode (repeating the last measurement).
Sound pressure level is C-weighted in the frequency domain, according to IEC 61672:2003.
Voltage measurement is direct current (DC).
Degrees Fahrenheit (temperature).
Device is in "min" mode, only updating upon a new min value.
Hertz (frequency, 1/s, [Hz]).
gboolean is_digits_decimal
int64_t p
Numerator of the rational number.
The public libsigrok header file to be used by frontends.
Sound pressure level is time-averaged (LAT), also known as Equivalent Continuous A-weighted Sound Lev...
Relative humidity assuming air temperature of 293 Kelvin (rF).
struct sr_analog_spec * spec
struct sr_analog_meaning * meaning
Sound pressure level represented as a percentage of measurements that were over a preset alarm level...
Sound pressure level, in decibels, relative to 20 micropascals.
Device is in "max" mode, only updating upon a new max value.
Voltage in decibel, referenced to 1 volt (dBV).
Analog datafeed payload for type SR_DF_ANALOG.
Measurements that intrinsically do not have units attached, such as ratios, gains, etc.
Device is in "avg" mode, averaging upon each new value.
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)
Device is in relative mode.
Plane angle in 1/360th of a full circle.
struct sr_rational offset
Sound pressure level is not weighted in the frequency domain, albeit without standards-defined low an...
Device is in autoranging mode.
Mass in troy ounce [oz t].
Mass in pennyweight [dwt].