scpi-dmm: minor style adjustment (gdm906x, analog init, comments, diag)
Address minor style issues: Need not assign NULL after g_malloc0(), need not check for NULL before g_free(). Rephrase diagnostics messages which are user visible by default, remove internal development details. Reword a few comments, and adjust their grammar for consistency across the code base. The sr_analog_init() routine executed immediately before getting measurements, need not (re-)assign endianess or floating point details, except those which do change after initialization (double vs float). Rephrase model dependent checks for easier adjustment during maintenance. Unobfuscate string comparisons.
This commit is contained in:
parent
72cd558d4a
commit
33aa8117e3
|
@ -279,7 +279,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
|
|||
devc->num_channels = model->num_channels;
|
||||
devc->cmdset = model->cmdset;
|
||||
devc->model = model;
|
||||
devc->precision = NULL;
|
||||
|
||||
for (i = 0; i < devc->num_channels; i++) {
|
||||
channel_name = g_strdup_printf("P%zu", i + 1);
|
||||
|
@ -449,14 +448,13 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
|||
ret = sr_scpi_get_string(scpi, command, &response);
|
||||
if (ret == SR_OK) {
|
||||
g_strstrip(response);
|
||||
if (devc->precision)
|
||||
g_free(devc->precision);
|
||||
devc->precision=g_strdup(response);
|
||||
g_free(devc->precision);
|
||||
devc->precision = g_strdup(response);
|
||||
g_free(response);
|
||||
sr_dbg("%s: Precision: '%s'", __func__, devc->precision);
|
||||
} else {
|
||||
sr_info("%s: Precision query ('%s') failed: %d",
|
||||
__func__, command, ret);
|
||||
sr_info("Precision query ('%s') failed: %d",
|
||||
command, ret);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -499,10 +497,8 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
|
|||
|
||||
std_session_send_df_end(sdi);
|
||||
|
||||
if (devc->precision) {
|
||||
g_free(devc->precision);
|
||||
devc->precision = NULL;
|
||||
}
|
||||
g_free(devc->precision);
|
||||
devc->precision = NULL;
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
|
|
@ -357,12 +357,6 @@ SR_PRIV int scpi_dmm_get_meas_agilent(const struct sr_dev_inst *sdi, size_t ch)
|
|||
analog->data = &info->f_value;
|
||||
analog->encoding->unitsize = sizeof(info->f_value);
|
||||
}
|
||||
analog->encoding->is_float = TRUE;
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
analog->encoding->is_bigendian = TRUE;
|
||||
#else
|
||||
analog->encoding->is_bigendian = FALSE;
|
||||
#endif
|
||||
analog->encoding->digits = digits;
|
||||
analog->meaning->mq = mq;
|
||||
analog->meaning->mqflags = mqflag;
|
||||
|
@ -413,6 +407,7 @@ SR_PRIV int scpi_dmm_get_meas_gwinstek(const struct sr_dev_inst *sdi, size_t ch)
|
|||
const char *command;
|
||||
char *response;
|
||||
gboolean use_double;
|
||||
double limit;
|
||||
int sig_digits, val_exp;
|
||||
int digits;
|
||||
enum sr_unit unit;
|
||||
|
@ -493,57 +488,53 @@ SR_PRIV int scpi_dmm_get_meas_gwinstek(const struct sr_dev_inst *sdi, size_t ch)
|
|||
return ret;
|
||||
|
||||
/*
|
||||
* Make sure we report "INFINITY" when meter displays "0L"
|
||||
* Make sure we report "INFINITY" when meter displays "0L".
|
||||
*/
|
||||
switch (mmode) {
|
||||
case 7:
|
||||
case 16:
|
||||
/* in resitance modes 0L reads as 1.20000E8 or 1.99999E8 */
|
||||
if (!strncmp(devc->model->model,"GDM8255A",8)) {
|
||||
if (info->d_value >= 1.99999e8)
|
||||
info->d_value = +INFINITY;
|
||||
} else {
|
||||
if (info->d_value >= 1.2e8)
|
||||
info->d_value = +INFINITY;
|
||||
}
|
||||
/* In resitance modes 0L reads as 1.20000E8 or 1.99999E8. */
|
||||
if (strcmp(devc->model->model, "GDM8255A") == 0)
|
||||
limit = 1.99999e8;
|
||||
else
|
||||
limit = 1.2e8;
|
||||
if (info->d_value >= limit)
|
||||
info->d_value = +INFINITY;
|
||||
break;
|
||||
case 13:
|
||||
/* In continuity mode 0L reads as 1.20000E3 */
|
||||
/* In continuity mode 0L reads as 1.20000E3. */
|
||||
if (info->d_value >= 1.2e3)
|
||||
info->d_value = +INFINITY;
|
||||
break;
|
||||
case 17:
|
||||
/* in diode mode 0L reads as 1.00000E0 */
|
||||
/* In diode mode 0L reads as 1.00000E0. */
|
||||
if (info->d_value == 1.0e0)
|
||||
info->d_value = +INFINITY;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate 'digits' based on the precision reading result
|
||||
* done during start of acquisition.
|
||||
*
|
||||
* GW-Instek manual gives following info regarding resolution:
|
||||
*
|
||||
* Type Digit
|
||||
* -------------------- ------------
|
||||
* Slow 5 1/2
|
||||
* Medium 4 1/2
|
||||
* Fast 3 1/2
|
||||
* Calculate 'digits' based on the result of the optional
|
||||
* precision reading which was done at acquisition start.
|
||||
* The GW-Instek manual gives the following information
|
||||
* regarding the resolution:
|
||||
*
|
||||
* Type Digit
|
||||
* -------- ------
|
||||
* Slow 5 1/2
|
||||
* Medium 4 1/2
|
||||
* Fast 3 1/2
|
||||
*/
|
||||
|
||||
digits = devc->model->digits;
|
||||
if (devc->precision && *devc->precision) {
|
||||
if (!strncmp(devc->precision, "Slow", 4))
|
||||
if (g_str_has_prefix(devc->precision, "Slow"))
|
||||
digits = 6;
|
||||
else if (!strncmp(devc->precision, "Mid", 3))
|
||||
else if (g_str_has_prefix(devc->precision, "Mid"))
|
||||
digits = 5;
|
||||
else if (!strncmp(devc->precision, "Fast", 4))
|
||||
else if (g_str_has_prefix(devc->precision, "Fast"))
|
||||
digits = 4;
|
||||
else
|
||||
sr_info("%s: Unknown precision: '%s'",
|
||||
__func__, devc->precision);
|
||||
sr_info("Unknown precision: '%s'", devc->precision);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -559,12 +550,6 @@ SR_PRIV int scpi_dmm_get_meas_gwinstek(const struct sr_dev_inst *sdi, size_t ch)
|
|||
analog->data = &info->f_value;
|
||||
analog->encoding->unitsize = sizeof(info->f_value);
|
||||
}
|
||||
analog->encoding->is_float = TRUE;
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
analog->encoding->is_bigendian = TRUE;
|
||||
#else
|
||||
analog->encoding->is_bigendian = FALSE;
|
||||
#endif
|
||||
analog->encoding->digits = digits;
|
||||
analog->meaning->mq = mq;
|
||||
analog->meaning->mqflags = mqflag;
|
||||
|
|
Loading…
Reference in New Issue