yokogawa-dlm: Replace g_try_malloc() calls and fix coding style

This commit is contained in:
Soeren Apel 2014-08-31 00:40:11 +02:00
parent 0028d5a1ee
commit ac10a927b5
3 changed files with 77 additions and 79 deletions

View File

@ -63,14 +63,13 @@ static struct sr_dev_inst *probe_usbtmc_device(struct sr_scpi_dev_inst *scpi)
goto fail; goto fail;
if (!(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, MANUFACTURER_NAME, if (!(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, MANUFACTURER_NAME,
model_name, NULL))) model_name, NULL)))
goto fail; goto fail;
sr_scpi_hw_info_free(hw_info); sr_scpi_hw_info_free(hw_info);
hw_info = NULL; hw_info = NULL;
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) devc = g_malloc0(sizeof(struct dev_context));
goto fail;
sdi->driver = di; sdi->driver = di;
sdi->priv = devc; sdi->priv = devc;
@ -168,7 +167,7 @@ static int cleanup(void)
* @retval CG_INVALID cg is something else * @retval CG_INVALID cg is something else
*/ */
static int check_channel_group(struct dev_context *devc, static int check_channel_group(struct dev_context *devc,
const struct sr_channel_group *cg) const struct sr_channel_group *cg)
{ {
unsigned int i; unsigned int i;
struct scope_config *model; struct scope_config *model;
@ -191,7 +190,7 @@ static int check_channel_group(struct dev_context *devc,
} }
static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi, static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg) const struct sr_channel_group *cg)
{ {
int ret, cg_type; int ret, cg_type;
unsigned int i; unsigned int i;
@ -216,8 +215,8 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
break; break;
case SR_CONF_TIMEBASE: case SR_CONF_TIMEBASE:
*data = g_variant_new("(tt)", *data = g_variant_new("(tt)",
(*model->timebases)[state->timebase][0], (*model->timebases)[state->timebase][0],
(*model->timebases)[state->timebase][1]); (*model->timebases)[state->timebase][1]);
ret = SR_OK; ret = SR_OK;
break; break;
case SR_CONF_NUM_VDIV: case SR_CONF_NUM_VDIV:
@ -244,8 +243,8 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
if (cg != devc->analog_groups[i]) if (cg != devc->analog_groups[i])
continue; continue;
*data = g_variant_new("(tt)", *data = g_variant_new("(tt)",
(*model->vdivs)[state->analog_states[i].vdiv][0], (*model->vdivs)[state->analog_states[i].vdiv][0],
(*model->vdivs)[state->analog_states[i].vdiv][1]); (*model->vdivs)[state->analog_states[i].vdiv][1]);
ret = SR_OK; ret = SR_OK;
break; break;
} }
@ -309,7 +308,7 @@ static GVariant *build_tuples(const uint64_t (*array)[][2], unsigned int n)
} }
static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi, static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg) const struct sr_channel_group *cg)
{ {
int ret, cg_type; int ret, cg_type;
unsigned int i, j; unsigned int i, j;
@ -360,7 +359,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
for (i = 0; i < model->num_vdivs; i++) { for (i = 0; i < model->num_vdivs; i++) {
if (p != (*model->vdivs)[i][0] || if (p != (*model->vdivs)[i][0] ||
q != (*model->vdivs)[i][1]) q != (*model->vdivs)[i][1])
continue; continue;
for (j = 1; j <= model->analog_channels; ++j) { for (j = 1; j <= model->analog_channels; ++j) {
if (cg != devc->analog_groups[j - 1]) if (cg != devc->analog_groups[j - 1])
@ -369,7 +368,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
g_ascii_formatd(float_str, sizeof(float_str), g_ascii_formatd(float_str, sizeof(float_str),
"%E", (float) p / q); "%E", (float) p / q);
if (dlm_analog_chan_vdiv_set(sdi->conn, j, float_str) != SR_OK || if (dlm_analog_chan_vdiv_set(sdi->conn, j, float_str) != SR_OK ||
sr_scpi_get_opc(sdi->conn) != SR_OK) sr_scpi_get_opc(sdi->conn) != SR_OK)
return SR_ERR; return SR_ERR;
break; break;
@ -384,7 +383,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
for (i = 0; i < model->num_timebases; i++) { for (i = 0; i < model->num_timebases; i++) {
if (p != (*model->timebases)[i][0] || if (p != (*model->timebases)[i][0] ||
q != (*model->timebases)[i][1]) q != (*model->timebases)[i][1])
continue; continue;
state->timebase = i; state->timebase = i;
g_ascii_formatd(float_str, sizeof(float_str), g_ascii_formatd(float_str, sizeof(float_str),
@ -403,9 +402,9 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
state->horiz_triggerpos = tmp_d; state->horiz_triggerpos = tmp_d;
tmp_d = -(tmp_d - 0.5) * tmp_d = -(tmp_d - 0.5) *
((double) (*model->timebases)[state->timebase][0] / ((double) (*model->timebases)[state->timebase][0] /
(*model->timebases)[state->timebase][1]) (*model->timebases)[state->timebase][1])
* model->num_xdivs; * model->num_xdivs;
g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d); g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d);
ret = dlm_horiz_trigger_pos_set(sdi->conn, float_str); ret = dlm_horiz_trigger_pos_set(sdi->conn, float_str);
@ -439,7 +438,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
state->analog_states[j-1].coupling = i; state->analog_states[j-1].coupling = i;
if (dlm_analog_chan_coupl_set(sdi->conn, j, tmp) != SR_OK || if (dlm_analog_chan_coupl_set(sdi->conn, j, tmp) != SR_OK ||
sr_scpi_get_opc(sdi->conn) != SR_OK) sr_scpi_get_opc(sdi->conn) != SR_OK)
return SR_ERR; return SR_ERR;
break; break;
} }
@ -463,7 +462,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
} }
static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg) const struct sr_channel_group *cg)
{ {
int cg_type; int cg_type;
struct dev_context *devc; struct dev_context *devc;
@ -497,15 +496,15 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
if (cg_type == CG_NONE) if (cg_type == CG_NONE)
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
*data = g_variant_new_strv(*model->coupling_options, *data = g_variant_new_strv(*model->coupling_options,
g_strv_length((char **)*model->coupling_options)); g_strv_length((char **)*model->coupling_options));
break; break;
case SR_CONF_TRIGGER_SOURCE: case SR_CONF_TRIGGER_SOURCE:
*data = g_variant_new_strv(*model->trigger_sources, *data = g_variant_new_strv(*model->trigger_sources,
g_strv_length((char **)*model->trigger_sources)); g_strv_length((char **)*model->trigger_sources));
break; break;
case SR_CONF_TRIGGER_SLOPE: case SR_CONF_TRIGGER_SLOPE:
*data = g_variant_new_strv(*model->trigger_slopes, *data = g_variant_new_strv(*model->trigger_slopes,
g_strv_length((char **)*model->trigger_slopes)); g_strv_length((char **)*model->trigger_slopes));
break; break;
case SR_CONF_TIMEBASE: case SR_CONF_TIMEBASE:
*data = build_tuples(model->timebases, model->num_timebases); *data = build_tuples(model->timebases, model->num_timebases);
@ -570,7 +569,7 @@ static int dlm_setup_channels(const struct sr_dev_inst *sdi)
model = devc->model_config; model = devc->model_config;
setup_changed = FALSE; setup_changed = FALSE;
pod_enabled = g_try_malloc0(sizeof(gboolean) * model->pods); pod_enabled = g_malloc0(sizeof(gboolean) * model->pods);
for (l = sdi->channels; l; l = l->next) { for (l = sdi->channels; l; l = l->next) {
ch = l->data; ch = l->data;
@ -580,7 +579,7 @@ static int dlm_setup_channels(const struct sr_dev_inst *sdi)
break; break;
if (dlm_analog_chan_state_set(scpi, ch->index + 1, if (dlm_analog_chan_state_set(scpi, ch->index + 1,
ch->enabled) != SR_OK) ch->enabled) != SR_OK)
return SR_ERR; return SR_ERR;
state->analog_states[ch->index].state = ch->enabled; state->analog_states[ch->index].state = ch->enabled;
@ -594,7 +593,7 @@ static int dlm_setup_channels(const struct sr_dev_inst *sdi)
break; break;
if (dlm_digital_chan_state_set(scpi, ch->index + 1, if (dlm_digital_chan_state_set(scpi, ch->index + 1,
ch->enabled) != SR_OK) ch->enabled) != SR_OK)
return SR_ERR; return SR_ERR;
state->digital_states[ch->index] = ch->enabled; state->digital_states[ch->index] = ch->enabled;
@ -610,7 +609,7 @@ static int dlm_setup_channels(const struct sr_dev_inst *sdi)
continue; continue;
if (dlm_digital_pod_state_set(scpi, i, if (dlm_digital_pod_state_set(scpi, i,
pod_enabled[i - 1]) != SR_OK) pod_enabled[i - 1]) != SR_OK)
return SR_ERR; return SR_ERR;
state->pod_states[i - 1] = pod_enabled[i - 1]; state->pod_states[i - 1] = pod_enabled[i - 1];
@ -635,7 +634,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
(void)cb_data; (void)cb_data;
if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
scpi = sdi->conn; scpi = sdi->conn;
devc = sdi->priv; devc = sdi->priv;
@ -651,9 +651,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
/* Only add a single digital channel. */ /* Only add a single digital channel. */
if (ch->type != SR_CHANNEL_LOGIC || !digital_added) { if (ch->type != SR_CHANNEL_LOGIC || !digital_added) {
devc->enabled_channels = g_slist_append( devc->enabled_channels = g_slist_append(
devc->enabled_channels, ch); devc->enabled_channels, ch);
if (ch->type == SR_CHANNEL_LOGIC) if (ch->type == SR_CHANNEL_LOGIC)
digital_added = TRUE; digital_added = TRUE;
} }
} }
@ -708,7 +708,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
SR_PRIV struct sr_dev_driver yokogawa_dlm_driver_info = { SR_PRIV struct sr_dev_driver yokogawa_dlm_driver_info = {
.name = "yokogawa-dlm", .name = "yokogawa-dlm",
.longname = "Yokogawa DL/DLM driver", .longname = "Yokogawa DL/DLM",
.api_version = 1, .api_version = 1,
.init = init, .init = init,
.cleanup = cleanup, .cleanup = cleanup,

View File

@ -241,25 +241,25 @@ static void scope_state_dump(struct scope_config *config,
for (i = 0; i < config->analog_channels; ++i) { for (i = 0; i < config->analog_channels; ++i) {
tmp = sr_voltage_string((*config->vdivs)[state->analog_states[i].vdiv][0], tmp = sr_voltage_string((*config->vdivs)[state->analog_states[i].vdiv][0],
(*config->vdivs)[state->analog_states[i].vdiv][1]); (*config->vdivs)[state->analog_states[i].vdiv][1]);
sr_info("State of analog channel %d -> %s : %s (coupling) %s (vdiv) %2.2e (offset)", sr_info("State of analog channel %d -> %s : %s (coupling) %s (vdiv) %2.2e (offset)",
i + 1, state->analog_states[i].state ? "On" : "Off", i + 1, state->analog_states[i].state ? "On" : "Off",
(*config->coupling_options)[state->analog_states[i].coupling], (*config->coupling_options)[state->analog_states[i].coupling],
tmp, state->analog_states[i].vertical_offset); tmp, state->analog_states[i].vertical_offset);
} }
for (i = 0; i < config->digital_channels; ++i) { for (i = 0; i < config->digital_channels; ++i) {
sr_info("State of digital channel %d -> %s", i, sr_info("State of digital channel %d -> %s", i,
state->digital_states[i] ? "On" : "Off"); state->digital_states[i] ? "On" : "Off");
} }
for (i = 0; i < config->pods; ++i) { for (i = 0; i < config->pods; ++i) {
sr_info("State of digital POD %d -> %s", i, sr_info("State of digital POD %d -> %s", i,
state->pod_states[i] ? "On" : "Off"); state->pod_states[i] ? "On" : "Off");
} }
tmp = sr_period_string((*config->timebases)[state->timebase][0] * tmp = sr_period_string((*config->timebases)[state->timebase][0] *
(*config->timebases)[state->timebase][1]); (*config->timebases)[state->timebase][1]);
sr_info("Current timebase: %s", tmp); sr_info("Current timebase: %s", tmp);
g_free(tmp); g_free(tmp);
@ -268,12 +268,12 @@ static void scope_state_dump(struct scope_config *config,
g_free(tmp); g_free(tmp);
sr_info("Current samples per acquisition (i.e. frame): %d", sr_info("Current samples per acquisition (i.e. frame): %d",
state->samples_per_frame); state->samples_per_frame);
sr_info("Current trigger: %s (source), %s (slope) %.2f (offset)", sr_info("Current trigger: %s (source), %s (slope) %.2f (offset)",
(*config->trigger_sources)[state->trigger_source], (*config->trigger_sources)[state->trigger_source],
(*config->trigger_slopes)[state->trigger_slope], (*config->trigger_slopes)[state->trigger_slope],
state->horiz_triggerpos); state->horiz_triggerpos);
} }
/** /**
@ -328,6 +328,7 @@ static int array_float_get(gchar *value, const uint64_t array[][2],
int i; int i;
uint64_t f; uint64_t f;
float s; float s;
unsigned int s_int;
gchar ss[10], es[10]; gchar ss[10], es[10];
memset(ss, 0, sizeof(ss)); memset(ss, 0, sizeof(ss));
@ -350,10 +351,10 @@ static int array_float_get(gchar *value, const uint64_t array[][2],
while ((int)fmod(log10(f), 3) > 0) { s *= 10; f *= 10; } while ((int)fmod(log10(f), 3) > 0) { s *= 10; f *= 10; }
/* Truncate s to circumvent rounding errors. */ /* Truncate s to circumvent rounding errors. */
s = (int)s; s_int = (unsigned int)s;
for (i = 0; i < array_len; i++) { for (i = 0; i < array_len; i++) {
if ( (s == array[i][0]) && (f == array[i][1]) ) { if ( (s_int == array[i][0]) && (f == array[i][1]) ) {
*result = i; *result = i;
return SR_OK; return SR_OK;
} }
@ -373,8 +374,8 @@ static int array_float_get(gchar *value, const uint64_t array[][2],
* @return SR_ERR on error, SR_OK otherwise. * @return SR_ERR on error, SR_OK otherwise.
*/ */
static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi, static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi,
struct scope_config *config, struct scope_config *config,
struct scope_state *state) struct scope_state *state)
{ {
int i, j; int i, j;
gchar *response; gchar *response;
@ -382,14 +383,14 @@ static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi,
for (i = 0; i < config->analog_channels; ++i) { for (i = 0; i < config->analog_channels; ++i) {
if (dlm_analog_chan_state_get(scpi, i + 1, if (dlm_analog_chan_state_get(scpi, i + 1,
&state->analog_states[i].state) != SR_OK) &state->analog_states[i].state) != SR_OK)
return SR_ERR; return SR_ERR;
if (dlm_analog_chan_vdiv_get(scpi, i + 1, &response) != SR_OK) if (dlm_analog_chan_vdiv_get(scpi, i + 1, &response) != SR_OK)
return SR_ERR; return SR_ERR;
if (array_float_get(response, *config->vdivs, config->num_vdivs, if (array_float_get(response, *config->vdivs, config->num_vdivs,
&j) != SR_OK) { &j) != SR_OK) {
g_free(response); g_free(response);
return SR_ERR; return SR_ERR;
} }
@ -398,15 +399,15 @@ static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi,
state->analog_states[i].vdiv = j; state->analog_states[i].vdiv = j;
if (dlm_analog_chan_voffs_get(scpi, i + 1, if (dlm_analog_chan_voffs_get(scpi, i + 1,
&state->analog_states[i].vertical_offset) != SR_OK) &state->analog_states[i].vertical_offset) != SR_OK)
return SR_ERR; return SR_ERR;
if (dlm_analog_chan_wrange_get(scpi, i + 1, if (dlm_analog_chan_wrange_get(scpi, i + 1,
&state->analog_states[i].waveform_range) != SR_OK) &state->analog_states[i].waveform_range) != SR_OK)
return SR_ERR; return SR_ERR;
if (dlm_analog_chan_woffs_get(scpi, i + 1, if (dlm_analog_chan_woffs_get(scpi, i + 1,
&state->analog_states[i].waveform_offset) != SR_OK) &state->analog_states[i].waveform_offset) != SR_OK)
return SR_ERR; return SR_ERR;
if (dlm_analog_chan_coupl_get(scpi, i + 1, &response) != SR_OK) { if (dlm_analog_chan_coupl_get(scpi, i + 1, &response) != SR_OK) {
@ -415,7 +416,7 @@ static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi,
} }
if (array_option_get(response, config->coupling_options, if (array_option_get(response, config->coupling_options,
&state->analog_states[i].coupling) != SR_OK) { &state->analog_states[i].coupling) != SR_OK) {
g_free(response); g_free(response);
return SR_ERR; return SR_ERR;
} }
@ -436,15 +437,15 @@ static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi,
* @return SR_ERR on error, SR_OK otherwise. * @return SR_ERR on error, SR_OK otherwise.
*/ */
static int digital_channel_state_get(struct sr_scpi_dev_inst *scpi, static int digital_channel_state_get(struct sr_scpi_dev_inst *scpi,
struct scope_config *config, struct scope_config *config,
struct scope_state *state) struct scope_state *state)
{ {
unsigned int i; unsigned int i;
if (!config->digital_channels) if (!config->digital_channels)
{ {
sr_warn("Tried obtaining digital channel states on a " \ sr_warn("Tried obtaining digital channel states on a " \
"model without digital inputs."); "model without digital inputs.");
return SR_OK; return SR_OK;
} }
@ -530,7 +531,7 @@ SR_PRIV int dlm_scope_state_query(struct sr_dev_inst *sdi)
return SR_ERR; return SR_ERR;
if (array_float_get(response, *config->timebases, if (array_float_get(response, *config->timebases,
config->num_timebases, &i) != SR_OK) { config->num_timebases, &i) != SR_OK) {
g_free(response); g_free(response);
return SR_ERR; return SR_ERR;
} }
@ -543,8 +544,8 @@ SR_PRIV int dlm_scope_state_query(struct sr_dev_inst *sdi)
/* TODO: Check if the calculation makes sense for the DLM. */ /* TODO: Check if the calculation makes sense for the DLM. */
state->horiz_triggerpos = tmp_float / state->horiz_triggerpos = tmp_float /
(((double)(*config->timebases)[state->timebase][0] / (((double)(*config->timebases)[state->timebase][0] /
(*config->timebases)[state->timebase][1]) * config->num_xdivs); (*config->timebases)[state->timebase][1]) * config->num_xdivs);
state->horiz_triggerpos -= 0.5; state->horiz_triggerpos -= 0.5;
state->horiz_triggerpos *= -1; state->horiz_triggerpos *= -1;
@ -554,7 +555,7 @@ SR_PRIV int dlm_scope_state_query(struct sr_dev_inst *sdi)
} }
if (array_option_get(response, config->trigger_sources, if (array_option_get(response, config->trigger_sources,
&state->trigger_source) != SR_OK) { &state->trigger_source) != SR_OK) {
g_free(response); g_free(response);
return SR_ERR; return SR_ERR;
} }
@ -583,20 +584,19 @@ SR_PRIV int dlm_scope_state_query(struct sr_dev_inst *sdi)
* *
* @param config The device configuration to use. * @param config The device configuration to use.
* *
* @return The newly allocated scope_state struct or NULL on error. * @return The newly allocated scope_state struct.
*/ */
static struct scope_state *dlm_scope_state_new(struct scope_config *config) static struct scope_state *dlm_scope_state_new(struct scope_config *config)
{ {
struct scope_state *state; struct scope_state *state;
if (!(state = g_try_malloc0(sizeof(struct scope_state)))) state = g_malloc0(sizeof(struct scope_state));
return NULL;
state->analog_states = g_malloc0(config->analog_channels * state->analog_states = g_malloc0(config->analog_channels *
sizeof(struct analog_channel_state)); sizeof(struct analog_channel_state));
state->digital_states = g_malloc0(config->digital_channels * state->digital_states = g_malloc0(config->digital_channels *
sizeof(gboolean)); sizeof(gboolean));
state->pod_states = g_malloc0(config->pods * sizeof(gboolean)); state->pod_states = g_malloc0(config->pods * sizeof(gboolean));
@ -637,7 +637,7 @@ SR_PRIV int dlm_model_get(char *model_id, char **model_name, int *model_index)
if (*model_index == -1) { if (*model_index == -1) {
sr_err("Found unsupported DLM device with model identifier %s.", sr_err("Found unsupported DLM device with model identifier %s.",
model_id); model_id);
return SR_ERR_NA; return SR_ERR_NA;
} }
@ -660,10 +660,10 @@ SR_PRIV int dlm_device_init(struct sr_dev_inst *sdi, int model_index)
devc = sdi->priv; devc = sdi->priv;
devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group*) * devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group*) *
scope_models[model_index].analog_channels); scope_models[model_index].analog_channels);
devc->digital_groups = g_malloc0(sizeof(struct sr_channel_group*) * devc->digital_groups = g_malloc0(sizeof(struct sr_channel_group*) *
scope_models[model_index].digital_channels); scope_models[model_index].digital_channels);
/* Add analog channels. */ /* Add analog channels. */
for (i = 0; i < scope_models[model_index].analog_channels; i++) { for (i = 0; i < scope_models[model_index].analog_channels; i++) {
@ -675,11 +675,11 @@ SR_PRIV int dlm_device_init(struct sr_dev_inst *sdi, int model_index)
devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
devc->analog_groups[i]->name = g_strdup( devc->analog_groups[i]->name = g_strdup(
(char *)(*scope_models[model_index].analog_names)[i]); (char *)(*scope_models[model_index].analog_names)[i]);
devc->analog_groups[i]->channels = g_slist_append(NULL, ch); devc->analog_groups[i]->channels = g_slist_append(NULL, ch);
sdi->channel_groups = g_slist_append(sdi->channel_groups, sdi->channel_groups = g_slist_append(sdi->channel_groups,
devc->analog_groups[i]); devc->analog_groups[i]);
} }
/* Add digital channel groups. */ /* Add digital channel groups. */
@ -703,7 +703,7 @@ SR_PRIV int dlm_device_init(struct sr_dev_inst *sdi, int model_index)
sdi->channels = g_slist_append(sdi->channels, ch); sdi->channels = g_slist_append(sdi->channels, ch);
devc->digital_groups[i / 8]->channels = g_slist_append( devc->digital_groups[i / 8]->channels = g_slist_append(
devc->digital_groups[i / 8]->channels, ch); devc->digital_groups[i / 8]->channels, ch);
} }
devc->model_config = &scope_models[model_index]; devc->model_config = &scope_models[model_index];
devc->frame_limit = 0; devc->frame_limit = 0;
@ -789,8 +789,8 @@ static int dlm_block_data_header_process(GArray *data, int *len)
* @return SR_ERR when data is trucated, SR_OK otherwise. * @return SR_ERR when data is trucated, SR_OK otherwise.
*/ */
static int dlm_analog_samples_send(GArray *data, static int dlm_analog_samples_send(GArray *data,
struct analog_channel_state *ch_state, struct analog_channel_state *ch_state,
struct sr_dev_inst *sdi) struct sr_dev_inst *sdi)
{ {
uint32_t i, samples; uint32_t i, samples;
float voltage, range, offset; float voltage, range, offset;
@ -821,7 +821,7 @@ static int dlm_analog_samples_send(GArray *data,
for (i = 0; i < samples; i++) { for (i = 0; i < samples; i++) {
voltage = (float)g_array_index(data, int8_t, i); voltage = (float)g_array_index(data, int8_t, i);
voltage = (range * voltage / voltage = (range * voltage /
DLM_DIVISION_FOR_BYTE_FORMAT) + offset; DLM_DIVISION_FOR_BYTE_FORMAT) + offset;
g_array_append_val(float_data, voltage); g_array_append_val(float_data, voltage);
} }
@ -852,7 +852,7 @@ static int dlm_analog_samples_send(GArray *data,
* @return SR_ERR when data is trucated, SR_OK otherwise. * @return SR_ERR when data is trucated, SR_OK otherwise.
*/ */
static int dlm_digital_samples_send(GArray *data, static int dlm_digital_samples_send(GArray *data,
struct sr_dev_inst *sdi) struct sr_dev_inst *sdi)
{ {
struct dev_context *devc; struct dev_context *devc;
struct scope_state *model_state; struct scope_state *model_state;
@ -923,14 +923,14 @@ SR_PRIV int dlm_data_receive(int fd, int revents, void *cb_data)
if (sr_scpi_read_begin(sdi->conn) == SR_OK) if (sr_scpi_read_begin(sdi->conn) == SR_OK)
/* The 16 here accounts for the header and EOL. */ /* The 16 here accounts for the header and EOL. */
data = g_array_sized_new(FALSE, FALSE, sizeof(uint8_t), data = g_array_sized_new(FALSE, FALSE, sizeof(uint8_t),
16 + model_state->samples_per_frame); 16 + model_state->samples_per_frame);
else else
return TRUE; return TRUE;
} }
/* Store incoming data. */ /* Store incoming data. */
chunk_len = sr_scpi_read_data(sdi->conn, devc->receive_buffer, chunk_len = sr_scpi_read_data(sdi->conn, devc->receive_buffer,
RECEIVE_BUFFER_SIZE); RECEIVE_BUFFER_SIZE);
if (chunk_len < 0) { if (chunk_len < 0) {
sr_err("Error while reading data: %d", chunk_len); sr_err("Error while reading data: %d", chunk_len);
goto fail; goto fail;
@ -957,8 +957,8 @@ SR_PRIV int dlm_data_receive(int fd, int revents, void *cb_data)
if (num_bytes == 0) { if (num_bytes == 0) {
sr_warn("Zero-length waveform data packet received. " \ sr_warn("Zero-length waveform data packet received. " \
"Live mode not supported yet, stopping " \ "Live mode not supported yet, stopping " \
"acquisition and retrying."); "acquisition and retrying.");
/* Don't care about return value here. */ /* Don't care about return value here. */
dlm_acquisition_stop(sdi->conn); dlm_acquisition_stop(sdi->conn);
g_array_free(data, TRUE); g_array_free(data, TRUE);

View File

@ -79,8 +79,6 @@ struct scope_config {
const uint8_t num_xdivs; const uint8_t num_xdivs;
const uint8_t num_ydivs; const uint8_t num_ydivs;
const char *(*scpi_dialect)[];
}; };
struct analog_channel_state { struct analog_channel_state {