SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+ SR_CONF_DATA_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
};
static const uint64_t samplerates[] = {
SR_HZ(1),
};
-extern const struct agdmm_job agdmm_jobs_u12xx[];
+static const char *data_sources[] = {
+ "Live",
+ "Log-Hand",
+ "Log-Trig",
+ "Log-Auto",
+ "Log-Export",
+};
+
+extern const struct agdmm_job agdmm_jobs_live[];
+extern const struct agdmm_job agdmm_jobs_log[];
extern const struct agdmm_recv agdmm_recvs_u123x[];
extern const struct agdmm_recv agdmm_recvs_u124x[];
extern const struct agdmm_recv agdmm_recvs_u125x[];
#define SERIALCOMM "9600/8n1"
static const struct agdmm_profile supported_agdmm[] = {
- { AGILENT_U1231, "U1231A", 1, agdmm_jobs_u12xx, agdmm_recvs_u123x },
- { AGILENT_U1232, "U1232A", 1, agdmm_jobs_u12xx, agdmm_recvs_u123x },
- { AGILENT_U1233, "U1233A", 1, agdmm_jobs_u12xx, agdmm_recvs_u123x },
-
- { AGILENT_U1241, "U1241A", 2, agdmm_jobs_u12xx, agdmm_recvs_u124x },
- { AGILENT_U1242, "U1242A", 2, agdmm_jobs_u12xx, agdmm_recvs_u124x },
- { AGILENT_U1241, "U1241B", 2, agdmm_jobs_u12xx, agdmm_recvs_u124x },
- { AGILENT_U1242, "U1242B", 2, agdmm_jobs_u12xx, agdmm_recvs_u124x },
-
- { AGILENT_U1251, "U1251A", 3, agdmm_jobs_u12xx, agdmm_recvs_u125x },
- { AGILENT_U1252, "U1252A", 3, agdmm_jobs_u12xx, agdmm_recvs_u125x },
- { AGILENT_U1253, "U1253A", 3, agdmm_jobs_u12xx, agdmm_recvs_u125x },
- { AGILENT_U1251, "U1251B", 3, agdmm_jobs_u12xx, agdmm_recvs_u125x },
- { AGILENT_U1252, "U1252B", 3, agdmm_jobs_u12xx, agdmm_recvs_u125x },
- { AGILENT_U1253, "U1253B", 3, agdmm_jobs_u12xx, agdmm_recvs_u125x },
-
- { KEYSIGHT_U1281, "U1281A", 3, agdmm_jobs_u12xx, agdmm_recvs_u128x },
- { KEYSIGHT_U1282, "U1282A", 3, agdmm_jobs_u12xx, agdmm_recvs_u128x },
+ { AGILENT_U1231, "U1231A", 1, agdmm_jobs_live, NULL, agdmm_recvs_u123x },
+ { AGILENT_U1232, "U1232A", 1, agdmm_jobs_live, NULL, agdmm_recvs_u123x },
+ { AGILENT_U1233, "U1233A", 1, agdmm_jobs_live, NULL, agdmm_recvs_u123x },
+
+ { AGILENT_U1241, "U1241A", 2, agdmm_jobs_live, NULL, agdmm_recvs_u124x },
+ { AGILENT_U1242, "U1242A", 2, agdmm_jobs_live, NULL, agdmm_recvs_u124x },
+ { AGILENT_U1241, "U1241B", 2, agdmm_jobs_live, NULL, agdmm_recvs_u124x },
+ { AGILENT_U1242, "U1242B", 2, agdmm_jobs_live, NULL, agdmm_recvs_u124x },
+
+ { AGILENT_U1251, "U1251A", 3, agdmm_jobs_live, NULL, agdmm_recvs_u125x },
+ { AGILENT_U1252, "U1252A", 3, agdmm_jobs_live, NULL, agdmm_recvs_u125x },
+ { AGILENT_U1253, "U1253A", 3, agdmm_jobs_live, NULL, agdmm_recvs_u125x },
+ { AGILENT_U1251, "U1251B", 3, agdmm_jobs_live, NULL, agdmm_recvs_u125x },
+ { AGILENT_U1252, "U1252B", 3, agdmm_jobs_live, NULL, agdmm_recvs_u125x },
+ { AGILENT_U1253, "U1253B", 3, agdmm_jobs_live, NULL, agdmm_recvs_u125x },
+
+ { KEYSIGHT_U1281, "U1281A", 3, agdmm_jobs_live, agdmm_jobs_log, agdmm_recvs_u128x },
+ { KEYSIGHT_U1282, "U1282A", 3, agdmm_jobs_live, agdmm_jobs_log, agdmm_recvs_u128x },
ALL_ZERO
};
devc = g_malloc0(sizeof(struct dev_context));
sr_sw_limits_init(&devc->limits);
devc->profile = &supported_agdmm[i];
+ devc->data_source = DEFAULT_DATA_SOURCE;
devc->cur_samplerate = 5;
if (supported_agdmm[i].nb_channels > 1) {
int temp_chan = supported_agdmm[i].nb_channels - 1;
case SR_CONF_LIMIT_MSEC:
ret = sr_sw_limits_config_get(&devc->limits, key, data);
break;
+ case SR_CONF_DATA_SOURCE:
+ *data = g_variant_new_string(data_sources[devc->data_source]);
+ break;
default:
return SR_ERR_NA;
}
{
struct dev_context *devc;
uint64_t samplerate;
+ const char *tmp_str;
+ unsigned int i;
int ret;
(void)cg;
case SR_CONF_LIMIT_MSEC:
ret = sr_sw_limits_config_set(&devc->limits, key, data);
break;
+ case SR_CONF_DATA_SOURCE: {
+ tmp_str = g_variant_get_string(data, NULL);
+ for (i = 0; i < ARRAY_SIZE(data_sources); i++)
+ if (!strcmp(tmp_str, data_sources[i])) {
+ devc->data_source = i;
+ break;
+ }
+ if (i == ARRAY_SIZE(data_sources))
+ return SR_ERR;
+ break;
+ }
default:
ret = SR_ERR_NA;
}
g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar);
*data = g_variant_builder_end(&gvb);
break;
+ case SR_CONF_DATA_SOURCE:
+ *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
+ break;
default:
return SR_ERR_NA;
}
devc->cur_channel = sr_next_enabled_channel(sdi, NULL);
devc->cur_conf = sr_next_enabled_channel(sdi, NULL);
+ devc->cur_sample = 1;
devc->cur_mq[0] = -1;
if (devc->profile->nb_channels > 2)
devc->cur_mq[1] = -1;
+ if (devc->data_source == DATA_SOURCE_LIVE) {
+ devc->jobs = devc->profile->jobs_live;
+ } else {
+ devc->jobs = devc->profile->jobs_log;
+ if (!devc->jobs) {
+ sr_err("Log data source is not implemented for this model.");
+ return SR_ERR_NA;
+ }
+ if (!((struct sr_channel *)sdi->channels->data)->enabled) {
+ sr_err("Log data is only available for channel P1.");
+ return SR_ERR_NA;
+ }
+ }
+
sr_sw_limits_acquisition_start(&devc->limits);
std_session_send_df_header(sdi);
static const struct agdmm_job *job_current(const struct dev_context *devc)
{
- return &devc->profile->jobs[devc->current_job];
+ return &devc->jobs[devc->current_job];
}
static void job_done(struct dev_context *devc)
job_run(sdi);
}
-static void receive_line(const struct sr_dev_inst *sdi)
+static gboolean receive_line(const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
const struct agdmm_recv *recvs, *recv;
GRegex *reg;
GMatchInfo *match;
+ gboolean stop = FALSE;
int i;
devc = sdi->priv;
job_done(devc);
else if (type == JOB_AGAIN)
job_again(devc);
+ else if (type == JOB_STOP)
+ stop = TRUE;
g_match_info_unref(match);
g_regex_unref(reg);
} else
/* Done with this. */
devc->buflen = 0;
+ return stop;
}
SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data)
struct sr_dev_inst *sdi;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
+ gboolean stop = FALSE;
int len;
(void)fd;
*(devc->buf + devc->buflen) = '\0';
if (*(devc->buf + devc->buflen - 1) == '\n') {
/* End of line */
- receive_line(sdi);
+ stop = receive_line(sdi);
break;
}
}
}
- dispatch(sdi);
-
- if (sr_sw_limits_check(&devc->limits))
+ if (sr_sw_limits_check(&devc->limits) || stop)
sdi->driver->dev_acquisition_stop(sdi);
+ else
+ dispatch(sdi);
return TRUE;
}
return JOB_CONF;
}
+static int send_log(const struct sr_dev_inst *sdi)
+{
+ const char *source[] = { "LOG:HAND", "LOG:TRIG", "LOG:AUTO", "LOG:EXPO" };
+ struct dev_context *devc = sdi->priv;
+ return agdmm_send(sdi, "%s %d",
+ source[devc->data_source - 1], devc->cur_sample);
+}
+
+static int recv_log_u128x(const struct sr_dev_inst *sdi, GMatchInfo *match)
+{
+ static const int mqs[] = { SR_MQ_VOLTAGE, SR_MQ_VOLTAGE, SR_MQ_CURRENT, SR_MQ_CURRENT, SR_MQ_RESISTANCE, SR_MQ_VOLTAGE, SR_MQ_TEMPERATURE, SR_MQ_CAPACITANCE, SR_MQ_FREQUENCY, SR_MQ_DUTY_CYCLE, SR_MQ_PULSE_WIDTH, SR_MQ_VOLTAGE, SR_MQ_CURRENT, SR_MQ_CONDUCTANCE };
+ static const int units[] = { SR_UNIT_VOLT, SR_UNIT_VOLT, SR_UNIT_AMPERE, SR_UNIT_AMPERE, SR_UNIT_OHM, SR_UNIT_VOLT, SR_UNIT_CELSIUS, SR_UNIT_FARAD, SR_UNIT_HERTZ, SR_UNIT_PERCENTAGE, SR_UNIT_SECOND, SR_UNIT_DECIBEL_MW, SR_UNIT_PERCENTAGE, SR_UNIT_SIEMENS };
+ static const int exponents[] = { -6, -4, -9, -4, -3, -4, -1, -12, -3, -3, -6, -3, -2, -11 };
+ struct dev_context *devc;
+ struct sr_datafeed_packet packet;
+ struct sr_datafeed_analog analog;
+ struct sr_analog_encoding encoding;
+ struct sr_analog_meaning meaning;
+ struct sr_analog_spec spec;
+ char *mstr;
+ unsigned function;
+ int value, negative, overload, exponent, alternate_unit, mq, unit;
+ int mqflags = 0;
+ float fvalue;
+
+ sr_spew("LOG response '%s'.", g_match_info_get_string(match));
+
+ devc = sdi->priv;
+
+ mstr = g_match_info_fetch(match, 2);
+ if (sr_atoi(mstr, (int*)&function) != SR_OK || function >= ARRAY_SIZE(mqs)) {
+ g_free(mstr);
+ sr_dbg("Invalid function.");
+ return SR_ERR;
+ }
+ g_free(mstr);
+
+ mstr = g_match_info_fetch(match, 3);
+ if (sr_atoi(mstr, &value) != SR_OK) {
+ g_free(mstr);
+ sr_dbg("Invalid value.");
+ return SR_ERR;
+ }
+ g_free(mstr);
+
+ mstr = g_match_info_fetch(match, 1);
+ negative = mstr[7] & 2 ? -1 : 1;
+ overload = mstr[8] & 4;
+ exponent = (mstr[9] & 0xF) + exponents[function];
+ alternate_unit = mstr[10] & 1;
+
+ if (mstr[ 8] & 1) mqflags |= SR_MQFLAG_DC;
+ if (mstr[ 8] & 2) mqflags |= SR_MQFLAG_AC;
+ if (mstr[11] & 4) mqflags |= SR_MQFLAG_RELATIVE;
+ if (mstr[12] & 1) mqflags |= SR_MQFLAG_AVG;
+ if (mstr[12] & 2) mqflags |= SR_MQFLAG_MIN;
+ if (mstr[12] & 4) mqflags |= SR_MQFLAG_MAX;
+ if (function == 5) mqflags |= SR_MQFLAG_DIODE;
+ g_free(mstr);
+
+ mq = mqs[function];
+ unit = units[function];
+ if (alternate_unit) {
+ if (mq == SR_MQ_RESISTANCE)
+ mq = SR_MQ_CONTINUITY;
+ if (unit == SR_UNIT_DECIBEL_MW)
+ unit = SR_UNIT_DECIBEL_VOLT;
+ if (unit == SR_UNIT_CELSIUS) {
+ unit = SR_UNIT_FAHRENHEIT;
+ exponent--;
+ }
+ }
+
+ if (overload)
+ fvalue = NAN;
+ else
+ fvalue = negative * value * powf(10, exponent);
+
+ sr_analog_init(&analog, &encoding, &meaning, &spec, -exponent);
+ analog.meaning->mq = mq;
+ analog.meaning->unit = unit;
+ analog.meaning->mqflags = mqflags;
+ analog.meaning->channels = g_slist_append(NULL, devc->cur_channel);
+ analog.num_samples = 1;
+ analog.data = &fvalue;
+ packet.type = SR_DF_ANALOG;
+ packet.payload = &analog;
+ sr_session_send(sdi, &packet);
+ g_slist_free(analog.meaning->channels);
+
+ sr_sw_limits_update_samples_read(&devc->limits, 1);
+ devc->cur_sample++;
+
+ return JOB_LOG;
+}
+
/* This comes in whenever the rotary switch is changed to a new position.
* We could use it to determine the major measurement mode, but we already
* have the output of CONF? for that, which is more detailed. However
return SR_OK;
}
+static int recv_err(const struct sr_dev_inst *sdi, GMatchInfo *match)
+{
+ struct dev_context *devc = sdi->priv;
+
+ (void) match;
+
+ if (devc->data_source != DATA_SOURCE_LIVE)
+ return JOB_STOP; /* In log mode, stop acquisition after receiving *E. */
+ else
+ return JOB_AGAIN;
+}
+
/* Poll CONF/STAT at 1Hz and values at samplerate. */
-SR_PRIV const struct agdmm_job agdmm_jobs_u12xx[] = {
+SR_PRIV const struct agdmm_job agdmm_jobs_live[] = {
{ JOB_FETC, SAMPLERATE_INTERVAL, send_fetc },
{ JOB_CONF, 1000, send_conf },
{ JOB_STAT, 1000, send_stat },
ALL_ZERO
};
+/* Poll LOG as fast as possible. */
+SR_PRIV const struct agdmm_job agdmm_jobs_log[] = {
+ { JOB_LOG, 0, send_log },
+ ALL_ZERO
+};
+
SR_PRIV const struct agdmm_recv agdmm_recvs_u123x[] = {
{ "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u123x },
{ "^\\*([0-9])$", recv_switch },
{ "^\"(PULS:PWID|PULS:PWID:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
{ "^\"(TEMP:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x },
{ "^\"(DIOD|SQU|PULS:PDUT|TEMP)\"$", recv_conf_u124x_5x },
+ { "^\"((\\d{2})(\\d{5})\\d{7})\"$", recv_log_u128x },
+ { "^\\*E$", recv_err },
ALL_ZERO
};