X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fhameg-hmo%2Fapi.c;h=4868410a00655d179260062a016815bb17a1e588;hb=8d558c7a9fd96f60077fc2b176576846f5089110;hp=37e458afd42dc2a7503d3ee2a1983367ebabacd8;hpb=89280b1a4c0675b1383ccc6a5a63e8a2a6add05e;p=libsigrok.git diff --git a/hardware/hameg-hmo/api.c b/hardware/hameg-hmo/api.c index 37e458af..4868410a 100644 --- a/hardware/hameg-hmo/api.c +++ b/hardware/hameg-hmo/api.c @@ -38,6 +38,13 @@ static struct usb_id_info ho_models[] = { { 0x0403, 0xed73 }, /* HO730 */ }; +enum { + PG_INVALID = -1, + PG_NONE, + PG_ANALOG, + PG_DIGITAL, +}; + static int init(struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); @@ -197,7 +204,7 @@ static GSList *scan(GSList *options) if (sr_serial_extract_options(options, &serial_device, &serial_options) == SR_OK) { - sdi = hameg_probe_serial_device(serial_device, serial_options); + sdi = hmo_probe_serial_device(serial_device, serial_options); if (sdi != NULL) { devices = g_slist_append(devices, sdi); drvc->instances = g_slist_append(drvc->instances, sdi); @@ -213,7 +220,7 @@ static GSList *scan(GSList *options) } for (l = tty_devs; l; l = l->next) { - sdi = hameg_probe_serial_device(l->data, serial_options); + sdi = hmo_probe_serial_device(l->data, serial_options); if (sdi != NULL) { devices = g_slist_append(devices, sdi); drvc->instances = g_slist_append(drvc->instances, sdi); @@ -240,7 +247,7 @@ static void clear_helper(void *priv) devc = priv; model = devc->model_config; - scope_state_free(devc->model_state); + hmo_scope_state_free(devc->model_state); for (i = 0; i < model->analog_channels; ++i) g_slist_free(devc->analog_groups[i].probes); @@ -267,7 +274,7 @@ static int dev_open(struct sr_dev_inst *sdi) serial_open(sdi->conn, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) return SR_ERR; - if (scope_state_get(sdi) != SR_OK) + if (hmo_scope_state_get(sdi) != SR_OK) return SR_ERR; sdi->status = SR_ST_ACTIVE; @@ -346,11 +353,11 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi, return SR_ERR_PROBE_GROUP; } else if (pg_type == PG_ANALOG) { for (i = 0; i < model->analog_channels; ++i) { - if (probe_group == &devc->analog_groups[i]) { - *data = g_variant_new_int32(model->num_ydivs); - ret = SR_OK; - break; - } + if (probe_group != &devc->analog_groups[i]) + continue; + *data = g_variant_new_int32(model->num_ydivs); + ret = SR_OK; + break; } } else { @@ -415,15 +422,15 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi, case SR_CONF_TRIGGER_SOURCE: tmp = g_variant_get_string(data, NULL); for (i = 0; (*model->trigger_sources)[i]; i++) { - if (!g_strcmp0(tmp, (*model->trigger_sources)[i])) { - state->trigger_source = i; - g_snprintf(command, sizeof(command), - (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SOURCE], - (*model->trigger_sources)[i]); + if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0) + continue; + state->trigger_source = i; + g_snprintf(command, sizeof(command), + (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SOURCE], + (*model->trigger_sources)[i]); - ret = sr_scpi_send(sdi->conn, command); - break; - } + ret = sr_scpi_send(sdi->conn, command); + break; } break; case SR_CONF_VDIV: @@ -435,42 +442,42 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi, g_variant_get(data, "(tt)", &p, &q); for (i = 0; i < model->num_vdivs; i++) { - if (p == (*model->vdivs)[i][0] && - q == (*model->vdivs)[i][1]) { - for (j = 1; j <= model->analog_channels; ++j) { - if (probe_group == &devc->analog_groups[j - 1]) { - state->analog_channels[j - 1].vdiv = (float) p / q; - g_snprintf(command, sizeof(command), - (*model->scpi_dialect)[SCPI_CMD_SET_VERTICAL_DIV], - j, state->analog_channels[j-1].vdiv); - - if (sr_scpi_send(sdi->conn, command) != SR_OK || - sr_scpi_get_opc(sdi->conn) != SR_OK) - return SR_ERR; - - break; - } - } + if (p != (*model->vdivs)[i][0] || + q != (*model->vdivs)[i][1]) + continue; + for (j = 1; j <= model->analog_channels; ++j) { + if (probe_group != &devc->analog_groups[j - 1]) + continue; + state->analog_channels[j - 1].vdiv = (float) p / q; + g_snprintf(command, sizeof(command), + (*model->scpi_dialect)[SCPI_CMD_SET_VERTICAL_DIV], + j, state->analog_channels[j-1].vdiv); + + if (sr_scpi_send(sdi->conn, command) != SR_OK || + sr_scpi_get_opc(sdi->conn) != SR_OK) + return SR_ERR; - ret = SR_OK; break; } + + ret = SR_OK; + break; } break; case SR_CONF_TIMEBASE: g_variant_get(data, "(tt)", &p, &q); for (i = 0; i < model->num_timebases; i++) { - if (p == (*model->timebases)[i][0] && - q == (*model->timebases)[i][1]) { - state->timebase = (float) p / q; - g_snprintf(command, sizeof(command), - (*model->scpi_dialect)[SCPI_CMD_SET_TIMEBASE], - state->timebase); + if (p != (*model->timebases)[i][0] || + q != (*model->timebases)[i][1]) + continue; + state->timebase = (float) p / q; + g_snprintf(command, sizeof(command), + (*model->scpi_dialect)[SCPI_CMD_SET_TIMEBASE], + state->timebase); - ret = sr_scpi_send(sdi->conn, command); - break; - } + ret = sr_scpi_send(sdi->conn, command); + break; } break; case SR_CONF_HORIZ_TRIGGERPOS: @@ -509,25 +516,25 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi, tmp = g_variant_get_string(data, NULL); for (i = 0; (*model->coupling_options)[i]; i++) { - if (!strcmp(tmp, (*model->coupling_options)[i])) { - for (j = 1; j <= model->analog_channels; ++j) { - if (probe_group == &devc->analog_groups[j - 1]) { - state->analog_channels[j-1].coupling = i; - - g_snprintf(command, sizeof(command), - (*model->scpi_dialect)[SCPI_CMD_SET_COUPLING], - j, tmp); - - if (sr_scpi_send(sdi->conn, command) != SR_OK || - sr_scpi_get_opc(sdi->conn) != SR_OK) - return SR_ERR; - break; - } - } + if (strcmp(tmp, (*model->coupling_options)[i]) != 0) + continue; + for (j = 1; j <= model->analog_channels; ++j) { + if (probe_group != &devc->analog_groups[j - 1]) + continue; + state->analog_channels[j-1].coupling = i; - ret = SR_OK; + g_snprintf(command, sizeof(command), + (*model->scpi_dialect)[SCPI_CMD_SET_COUPLING], + j, tmp); + + if (sr_scpi_send(sdi->conn, command) != SR_OK || + sr_scpi_get_opc(sdi->conn) != SR_OK) + return SR_ERR; break; } + + ret = SR_OK; + break; } break; default: @@ -685,15 +692,15 @@ static int hmo_setup_probes(const struct sr_dev_inst *sdi) probe = l->data; switch (probe->type) { case SR_PROBE_ANALOG: - if (probe->enabled != state->analog_channels[probe->index].state) { - g_snprintf(command, sizeof(command), - (*model->scpi_dialect)[SCPI_CMD_SET_ANALOG_CHAN_STATE], - probe->index + 1, probe->enabled); + if (probe->enabled == state->analog_channels[probe->index].state) + break; + g_snprintf(command, sizeof(command), + (*model->scpi_dialect)[SCPI_CMD_SET_ANALOG_CHAN_STATE], + probe->index + 1, probe->enabled); - if (sr_scpi_send(serial, command) != SR_OK) - return SR_ERR; - state->analog_channels[probe->index].state = probe->enabled; - } + if (sr_scpi_send(serial, command) != SR_OK) + return SR_ERR; + state->analog_channels[probe->index].state = probe->enabled; break; case SR_PROBE_LOGIC: /* @@ -703,16 +710,16 @@ static int hmo_setup_probes(const struct sr_dev_inst *sdi) if (probe->enabled) pod_enabled[probe->index < 8 ? 0 : 1] = TRUE; - if (probe->enabled != state->digital_channels[probe->index]) { - g_snprintf(command, sizeof(command), - (*model->scpi_dialect)[SCPI_CMD_SET_DIG_CHAN_STATE], - probe->index, probe->enabled); + if (probe->enabled == state->digital_channels[probe->index]) + break; + g_snprintf(command, sizeof(command), + (*model->scpi_dialect)[SCPI_CMD_SET_DIG_CHAN_STATE], + probe->index, probe->enabled); - if (sr_scpi_send(serial, command) != SR_OK) - return SR_ERR; + if (sr_scpi_send(serial, command) != SR_OK) + return SR_ERR; - state->digital_channels[probe->index] = probe->enabled; - } + state->digital_channels[probe->index] = probe->enabled; break; default: return SR_ERR; @@ -720,16 +727,14 @@ static int hmo_setup_probes(const struct sr_dev_inst *sdi) } for (i = 1; i <= model->digital_pods; ++i) { - if (state->digital_pods[i - 1] != pod_enabled[i - 1]) { - g_snprintf(command, sizeof(command), - (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE], - i, pod_enabled[i - 1]); - - if (sr_scpi_send(serial, command) != SR_OK) - return SR_ERR; - - state->digital_pods[i - 1] = pod_enabled[i - 1]; - } + if (state->digital_pods[i - 1] == pod_enabled[i - 1]) + continue; + g_snprintf(command, sizeof(command), + (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE], + i, pod_enabled[i - 1]); + if (sr_scpi_send(serial, command) != SR_OK) + return SR_ERR; + state->digital_pods[i - 1] = pod_enabled[i - 1]; } g_free(pod_enabled); @@ -754,14 +759,14 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) for (l = sdi->probes; l; l = l->next) { probe = l->data; - if (probe->enabled) { - /* Only add a single digital probe. */ - if (probe->type != SR_PROBE_LOGIC || !digital_added) { - devc->enabled_probes = g_slist_append( - devc->enabled_probes, probe); - if (probe->type == SR_PROBE_LOGIC) - digital_added = TRUE; - } + if (!probe->enabled) + continue; + /* Only add a single digital probe. */ + if (probe->type != SR_PROBE_LOGIC || !digital_added) { + devc->enabled_probes = g_slist_append( + devc->enabled_probes, probe); + if (probe->type == SR_PROBE_LOGIC) + digital_added = TRUE; } } @@ -778,7 +783,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) return SR_ERR; } - sr_source_add(serial->fd, G_IO_IN, 50, hameg_hmo_receive_data, (void *)sdi); + sr_source_add(serial->fd, G_IO_IN, 50, hmo_receive_data, (void *)sdi); /* Send header packet to the session bus. */ std_session_send_df_header(cb_data, LOG_PREFIX);