X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fhameg-hmo%2Fapi.c;h=8638a790bc56806954dfe017d8b44d7571e44d71;hb=0f523f2b45e84114add85cec5a97aed3f85f95e6;hp=6d4411943640551f723c2bccf00031b6418a5df5;hpb=fcd6a8bdf179d7ac0558eef2e205bfb941e5ba5c;p=libsigrok.git diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 6d441194..8638a790 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -176,28 +176,24 @@ static int config_get(uint32_t key, GVariant **data, (*model->timebases)[state->timebase][1]); break; case SR_CONF_NUM_VDIV: - if (cg_type == CG_NONE) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else if (cg_type == CG_ANALOG) { - if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) < 0) - return SR_ERR_ARG; - *data = g_variant_new_int32(model->num_ydivs); - } else { + if (cg_type != CG_ANALOG) return SR_ERR_NA; - } + if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) < 0) + return SR_ERR_ARG; + *data = g_variant_new_int32(model->num_ydivs); break; case SR_CONF_VDIV: - if (cg_type == CG_NONE) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else if (cg_type == CG_ANALOG) { - if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) - return SR_ERR_ARG; - *data = g_variant_new("(tt)", - (*model->vdivs)[state->analog_channels[idx].vdiv][0], - (*model->vdivs)[state->analog_channels[idx].vdiv][1]); - } else { + if (cg_type != CG_ANALOG) return SR_ERR_NA; - } + if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) + return SR_ERR_ARG; + *data = g_variant_new("(tt)", + (*model->vdivs)[state->analog_channels[idx].vdiv][0], + (*model->vdivs)[state->analog_channels[idx].vdiv][1]); break; case SR_CONF_TRIGGER_SOURCE: *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]); @@ -209,15 +205,13 @@ static int config_get(uint32_t key, GVariant **data, *data = g_variant_new_double(state->horiz_triggerpos); break; case SR_CONF_COUPLING: - if (cg_type == CG_NONE) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else if (cg_type == CG_ANALOG) { - if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) - return SR_ERR_ARG; - *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[idx].coupling]); - } else { + if (cg_type != CG_ANALOG) return SR_ERR_NA; - } + if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) + return SR_ERR_ARG; + *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[idx].coupling]); break; case SR_CONF_SAMPLERATE: *data = g_variant_new_uint64(state->sample_rate); @@ -252,8 +246,6 @@ static int config_set(uint32_t key, GVariant *data, state = devc->model_state; update_sample_rate = FALSE; - ret = SR_ERR_NA; - switch (key) { case SR_CONF_LIMIT_FRAMES: devc->frame_limit = g_variant_get_uint64(data); @@ -269,7 +261,7 @@ static int config_set(uint32_t key, GVariant *data, ret = sr_scpi_send(sdi->conn, command); break; case SR_CONF_VDIV: - if (cg_type == CG_NONE) + if (!cg) return SR_ERR_CHANNEL_GROUP; if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0) return SR_ERR_ARG; @@ -323,7 +315,7 @@ static int config_set(uint32_t key, GVariant *data, ret = sr_scpi_send(sdi->conn, command); break; case SR_CONF_COUPLING: - if (cg_type == CG_NONE) + if (!cg) return SR_ERR_CHANNEL_GROUP; if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0) return SR_ERR_ARG; @@ -372,7 +364,7 @@ static int config_list(uint32_t key, GVariant **data, *data = std_gvar_array_u32(ARRAY_AND_SIZE(scanopts)); break; case SR_CONF_DEVICE_OPTIONS: - if (cg_type == CG_NONE) { + if (!cg) { if (model) *data = std_gvar_array_u32((const uint32_t *)model->devopts, model->num_devopts); else @@ -384,8 +376,10 @@ static int config_list(uint32_t key, GVariant **data, } break; case SR_CONF_COUPLING: - if (cg_type == CG_NONE) + if (!cg) return SR_ERR_CHANNEL_GROUP; + if (!model) + return SR_ERR_ARG; *data = g_variant_new_strv(*model->coupling_options, model->num_coupling_options); break; case SR_CONF_TRIGGER_SOURCE: @@ -404,8 +398,10 @@ static int config_list(uint32_t key, GVariant **data, *data = std_gvar_tuple_array(*model->timebases, model->num_timebases); break; case SR_CONF_VDIV: - if (cg_type == CG_NONE) + if (!cg) return SR_ERR_CHANNEL_GROUP; + if (!model) + return SR_ERR_ARG; *data = std_gvar_tuple_array(*model->vdivs, model->num_vdivs); break; default: @@ -513,6 +509,7 @@ static int hmo_setup_channels(const struct sr_dev_inst *sdi) struct sr_channel *ch; struct dev_context *devc; struct sr_scpi_dev_inst *scpi; + int ret; devc = sdi->priv; scpi = sdi->conn; @@ -532,8 +529,10 @@ static int hmo_setup_channels(const struct sr_dev_inst *sdi) (*model->scpi_dialect)[SCPI_CMD_SET_ANALOG_CHAN_STATE], ch->index + 1, ch->enabled); - if (sr_scpi_send(scpi, command) != SR_OK) + if (sr_scpi_send(scpi, command) != SR_OK) { + g_free(pod_enabled); return SR_ERR; + } state->analog_channels[ch->index].state = ch->enabled; setup_changed = TRUE; break; @@ -551,30 +550,37 @@ static int hmo_setup_channels(const struct sr_dev_inst *sdi) (*model->scpi_dialect)[SCPI_CMD_SET_DIG_CHAN_STATE], ch->index, ch->enabled); - if (sr_scpi_send(scpi, command) != SR_OK) + if (sr_scpi_send(scpi, command) != SR_OK) { + g_free(pod_enabled); return SR_ERR; + } state->digital_channels[ch->index] = ch->enabled; setup_changed = TRUE; break; default: + g_free(pod_enabled); return SR_ERR; } } + ret = SR_OK; for (i = 0; i < model->digital_pods; i++) { if (state->digital_pods[i] == pod_enabled[i]) continue; g_snprintf(command, sizeof(command), (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE], i + 1, pod_enabled[i]); - if (sr_scpi_send(scpi, command) != SR_OK) - return SR_ERR; + if (sr_scpi_send(scpi, command) != SR_OK) { + ret = SR_ERR; + break; + } state->digital_pods[i] = pod_enabled[i]; setup_changed = TRUE; } - g_free(pod_enabled); + if (ret != SR_OK) + return ret; if (setup_changed && hmo_update_sample_rate(sdi) != SR_OK) return SR_ERR;