* Copyright (C) 2011 Olivier Fauchon <olivier@aixmarseille.com>
* Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
* Copyright (C) 2015 Bartosz Golaszewski <bgolaszewski@baylibre.com>
+ * Copyright (C) 2019 Frank Stettner <frank-stettner@gmx.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
};
static const uint32_t devopts_cg_analog_channel[] = {
+ SR_CONF_MEASURED_QUANTITY | SR_CONF_GET | SR_CONF_SET,
SR_CONF_PATTERN_MODE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
SR_CONF_AMPLITUDE | SR_CONF_GET | SR_CONF_SET,
};
/* Every channel gets a generator struct. */
ag = g_malloc(sizeof(struct analog_gen));
ag->ch = ch;
+ ag->mq = SR_MQ_VOLTAGE;
+ ag->mq_flags = SR_MQFLAG_DC;
+ ag->unit = SR_UNIT_VOLT;
ag->amplitude = DEFAULT_ANALOG_AMPLITUDE;
sr_analog_init(&ag->packet, &ag->encoding, &ag->meaning, &ag->spec, 2);
ag->packet.meaning->channels = cg->channels;
- ag->packet.meaning->mq = SR_MQ_VOLTAGE;
- ag->packet.meaning->mqflags = SR_MQFLAG_DC;
- ag->packet.meaning->unit = SR_UNIT_VOLT;
+ ag->packet.meaning->mq = ag->mq;
+ ag->packet.meaning->mqflags = ag->mq_flags;
+ ag->packet.meaning->unit = ag->unit;
ag->packet.encoding->digits = DEFAULT_ANALOG_ENCODING_DIGITS;
ag->packet.spec->spec_digits = DEFAULT_ANALOG_SPEC_DIGITS;
ag->packet.data = ag->pattern_data;
struct dev_context *devc;
struct sr_channel *ch;
struct analog_gen *ag;
+ GVariant *mq_arr[2];
int pattern;
if (!sdi)
case SR_CONF_AVG_SAMPLES:
*data = g_variant_new_uint64(devc->avg_samples);
break;
+ case SR_CONF_MEASURED_QUANTITY:
+ if (!cg)
+ return SR_ERR_CHANNEL_GROUP;
+ /* Any channel in the group will do. */
+ ch = cg->channels->data;
+ if (ch->type != SR_CHANNEL_ANALOG)
+ return SR_ERR_ARG;
+ ag = g_hash_table_lookup(devc->ch_ag, ch);
+ mq_arr[0] = g_variant_new_uint32(ag->mq);
+ mq_arr[1] = g_variant_new_uint64(ag->mq_flags);
+ *data = g_variant_new_tuple(mq_arr, 2);
+ break;
case SR_CONF_PATTERN_MODE:
if (!cg)
return SR_ERR_CHANNEL_GROUP;
struct dev_context *devc;
struct analog_gen *ag;
struct sr_channel *ch;
+ GVariant *mq_tuple_child;
GSList *l;
int logic_pattern, analog_pattern;
devc->avg_samples = g_variant_get_uint64(data);
sr_dbg("Setting averaging rate to %" PRIu64, devc->avg_samples);
break;
+ case SR_CONF_MEASURED_QUANTITY:
+ if (!cg)
+ return SR_ERR_CHANNEL_GROUP;
+ for (l = cg->channels; l; l = l->next) {
+ ch = l->data;
+ if (ch->type != SR_CHANNEL_ANALOG)
+ return SR_ERR_ARG;
+ ag = g_hash_table_lookup(devc->ch_ag, ch);
+ mq_tuple_child = g_variant_get_child_value(data, 0);
+ ag->mq = g_variant_get_uint32(mq_tuple_child);
+ mq_tuple_child = g_variant_get_child_value(data, 1);
+ ag->mq_flags = g_variant_get_uint64(mq_tuple_child);
+ g_variant_unref(mq_tuple_child);
+ }
+ break;
case SR_CONF_PATTERN_MODE:
if (!cg)
return SR_ERR_CHANNEL_GROUP;
* Copyright (C) 2011 Olivier Fauchon <olivier@aixmarseille.com>
* Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
* Copyright (C) 2015 Bartosz Golaszewski <bgolaszewski@baylibre.com>
+ * Copyright (C) 2019 Frank Stettner <frank-stettner@gmx.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
packet.type = SR_DF_ANALOG;
packet.payload = &ag->packet;
+ ag->packet.meaning->channels = g_slist_append(NULL, ag->ch);
+ ag->packet.meaning->mq = ag->mq;
+ ag->packet.meaning->mqflags = ag->mq_flags;
+
+ /* Set a unit for the given quantity */
+ if (ag->mq == SR_MQ_VOLTAGE)
+ ag->packet.meaning->unit = SR_UNIT_VOLT;
+ else if (ag->mq == SR_MQ_CURRENT)
+ ag->packet.meaning->unit = SR_UNIT_AMPERE;
+ else if (ag->mq == SR_MQ_RESISTANCE)
+ ag->packet.meaning->unit = SR_UNIT_OHM;
+ else if (ag->mq == SR_MQ_CAPACITANCE)
+ ag->packet.meaning->unit = SR_UNIT_FARAD;
+ else if (ag->mq == SR_MQ_TEMPERATURE)
+ ag->packet.meaning->unit = SR_UNIT_CELSIUS;
+ else if (ag->mq == SR_MQ_FREQUENCY)
+ ag->packet.meaning->unit = SR_UNIT_HERTZ;
+ else if (ag->mq == SR_MQ_DUTY_CYCLE)
+ ag->packet.meaning->unit = SR_UNIT_PERCENTAGE;
+ else if (ag->mq == SR_MQ_CONTINUITY)
+ ag->packet.meaning->unit = SR_UNIT_OHM;
+ else if (ag->mq == SR_MQ_PULSE_WIDTH)
+ ag->packet.meaning->unit = SR_UNIT_PERCENTAGE;
+ else if (ag->mq == SR_MQ_CONDUCTANCE)
+ ag->packet.meaning->unit = SR_UNIT_SIEMENS;
+ else if (ag->mq == SR_MQ_POWER)
+ ag->packet.meaning->unit = SR_UNIT_WATT;
+ else if (ag->mq == SR_MQ_GAIN)
+ ag->packet.meaning->unit = SR_UNIT_UNITLESS;
+ else if (ag->mq == SR_MQ_SOUND_PRESSURE_LEVEL)
+ ag->packet.meaning->unit = SR_UNIT_DECIBEL_SPL;
+ else if (ag->mq == SR_MQ_CARBON_MONOXIDE)
+ ag->packet.meaning->unit = SR_UNIT_CONCENTRATION;
+ else if (ag->mq == SR_MQ_RELATIVE_HUMIDITY)
+ ag->packet.meaning->unit = SR_UNIT_HUMIDITY_293K;
+ else if (ag->mq == SR_MQ_TIME)
+ ag->packet.meaning->unit = SR_UNIT_SECOND;
+ else if (ag->mq == SR_MQ_WIND_SPEED)
+ ag->packet.meaning->unit = SR_UNIT_METER_SECOND;
+ else if (ag->mq == SR_MQ_PRESSURE)
+ ag->packet.meaning->unit = SR_UNIT_HECTOPASCAL;
+ else if (ag->mq == SR_MQ_PARALLEL_INDUCTANCE)
+ ag->packet.meaning->unit = SR_UNIT_HENRY;
+ else if (ag->mq == SR_MQ_PARALLEL_CAPACITANCE)
+ ag->packet.meaning->unit = SR_UNIT_FARAD;
+ else if (ag->mq == SR_MQ_PARALLEL_RESISTANCE)
+ ag->packet.meaning->unit = SR_UNIT_OHM;
+ else if (ag->mq == SR_MQ_SERIES_INDUCTANCE)
+ ag->packet.meaning->unit = SR_UNIT_HENRY;
+ else if (ag->mq == SR_MQ_SERIES_CAPACITANCE)
+ ag->packet.meaning->unit = SR_UNIT_FARAD;
+ else if (ag->mq == SR_MQ_SERIES_RESISTANCE)
+ ag->packet.meaning->unit = SR_UNIT_OHM;
+ else if (ag->mq == SR_MQ_DISSIPATION_FACTOR)
+ ag->packet.meaning->unit = SR_UNIT_UNITLESS;
+ else if (ag->mq == SR_MQ_QUALITY_FACTOR)
+ ag->packet.meaning->unit = SR_UNIT_UNITLESS;
+ else if (ag->mq == SR_MQ_PHASE_ANGLE)
+ ag->packet.meaning->unit = SR_UNIT_DEGREE;
+ else if (ag->mq == SR_MQ_DIFFERENCE)
+ ag->packet.meaning->unit = SR_UNIT_UNITLESS;
+ else if (ag->mq == SR_MQ_COUNT)
+ ag->packet.meaning->unit = SR_UNIT_PIECE;
+ else if (ag->mq == SR_MQ_POWER_FACTOR)
+ ag->packet.meaning->unit = SR_UNIT_UNITLESS;
+ else if (ag->mq == SR_MQ_APPARENT_POWER)
+ ag->packet.meaning->unit = SR_UNIT_VOLT_AMPERE;
+ else if (ag->mq == SR_MQ_MASS)
+ ag->packet.meaning->unit = SR_UNIT_GRAM;
+ else if (ag->mq == SR_MQ_HARMONIC_RATIO)
+ ag->packet.meaning->unit = SR_UNIT_UNITLESS;
+ else
+ ag->packet.meaning->unit = SR_UNIT_UNITLESS;
+
if (!devc->avg) {
ag_pattern_pos = analog_pos % ag->num_samples;
sending_now = MIN(analog_todo, ag->num_samples - ag_pattern_pos);