X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=hardware%2Fhameg-hmo%2Fprotocol.c;h=eedaf7975b139d8c41e59c403c3f855a4c78c376;hp=2188b40cb7250a557db463fe12b3e7f8b2b8809b;hb=ba7dd8bbb8168cba432a844259a3e239aa5f36d7;hpb=14a2f74d9a5d696baab59cda426604f1750d17ba diff --git a/hardware/hameg-hmo/protocol.c b/hardware/hameg-hmo/protocol.c index 2188b40c..eedaf797 100644 --- a/hardware/hameg-hmo/protocol.c +++ b/hardware/hameg-hmo/protocol.c @@ -40,7 +40,7 @@ static const char *hameg_scpi_dialect[] = { [SCPI_CMD_SET_DIG_CHAN_STATE] = ":LOG%d:STAT %d", [SCPI_CMD_GET_VERTICAL_OFFSET] = ":CHAN%d:POS?", [SCPI_CMD_GET_HORIZ_TRIGGERPOS] = ":TIM:POS?", - [SCPI_CMD_SET_HORIZ_TRIGGERPOS] = ":TIM:POS %E", + [SCPI_CMD_SET_HORIZ_TRIGGERPOS] = ":TIM:POS %s", [SCPI_CMD_GET_ANALOG_CHAN_STATE] = ":CHAN%d:STAT?", [SCPI_CMD_SET_ANALOG_CHAN_STATE] = ":CHAN%d:STAT %d", }; @@ -53,6 +53,7 @@ static const int32_t hmo_hwcaps[] = { SR_CONF_TRIGGER_SLOPE, SR_CONF_HORIZ_TRIGGERPOS, SR_CONF_SAMPLERATE, + SR_CONF_LIMIT_FRAMES, }; static const int32_t hmo_analog_caps[] = { @@ -167,14 +168,14 @@ static const uint64_t hmo_vdivs[][2] = { { 10, 1 }, }; -static const char *scope_analog_probe_names[] = { +static const char *scope_analog_channel_names[] = { "CH1", "CH2", "CH3", "CH4", }; -static const char *scope_digital_probe_names[] = { +static const char *scope_digital_channel_names[] = { "D0", "D1", "D2", @@ -200,8 +201,8 @@ static struct scope_config scope_models[] = { .digital_channels = 8, .digital_pods = 1, - .analog_names = &scope_analog_probe_names, - .digital_names = &scope_digital_probe_names, + .analog_names = &scope_analog_channel_names, + .digital_names = &scope_digital_channel_names, .hw_caps = &hmo_hwcaps, .num_hwcaps = ARRAY_SIZE(hmo_hwcaps), @@ -230,8 +231,8 @@ static struct scope_config scope_models[] = { .digital_channels = 8, .digital_pods = 1, - .analog_names = &scope_analog_probe_names, - .digital_names = &scope_digital_probe_names, + .analog_names = &scope_analog_channel_names, + .digital_names = &scope_digital_channel_names, .hw_caps = &hmo_hwcaps, .num_hwcaps = ARRAY_SIZE(hmo_hwcaps), @@ -290,7 +291,7 @@ static void scope_state_dump(struct scope_config *config, sr_info("Current samplerate: %s", tmp); g_free(tmp); - sr_info("Current trigger: %s (source), %s (slope) %2.2e (offset)", + sr_info("Current trigger: %s (source), %s (slope) %.2f (offset)", (*config->trigger_sources)[state->trigger_source], (*config->trigger_slopes)[state->trigger_slope], state->horiz_triggerpos); @@ -452,11 +453,11 @@ SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi) /* No channel is active, ask the instrument for the sample rate * in single shot mode */ if (!channel_found) { - g_snprintf(tmp_str, sizeof(tmp_str), - (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE]); - - if (sr_scpi_get_float(sdi->conn, tmp_str, &tmp_float) != SR_OK) + if (sr_scpi_get_float(sdi->conn, + (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE], + &tmp_float) != SR_OK) return SR_ERR; + state->sample_rate = tmp_float; } else { if (sr_scpi_get_int(sdi->conn, tmp_str, &tmp) != SR_OK) @@ -506,8 +507,13 @@ SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi) if (sr_scpi_get_float(sdi->conn, (*config->scpi_dialect)[SCPI_CMD_GET_HORIZ_TRIGGERPOS], - &state->horiz_triggerpos) != SR_OK) + &tmp_float) != SR_OK) return SR_ERR; + state->horiz_triggerpos = tmp_float / + (((double) (*config->timebases)[state->timebase][0] / + (*config->timebases)[state->timebase][1]) * config->num_xdivs); + state->horiz_triggerpos -= 0.5; + state->horiz_triggerpos *= -1; if (scope_state_get_array_option(sdi->conn, (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SOURCE], @@ -575,7 +581,7 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) char tmp[25]; int model_index; unsigned int i, j; - struct sr_probe *probe; + struct sr_channel *ch; struct dev_context *devc; devc = sdi->priv; @@ -598,46 +604,46 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) return SR_ERR_NA; } - if (!(devc->analog_groups = g_try_malloc0(sizeof(struct sr_probe_group) * + if (!(devc->analog_groups = g_try_malloc0(sizeof(struct sr_channel_group) * scope_models[model_index].analog_channels))) return SR_ERR_MALLOC; - if (!(devc->digital_groups = g_try_malloc0(sizeof(struct sr_probe_group) * + if (!(devc->digital_groups = g_try_malloc0(sizeof(struct sr_channel_group) * scope_models[model_index].digital_pods))) return SR_ERR_MALLOC; /* Add analog channels. */ for (i = 0; i < scope_models[model_index].analog_channels; i++) { - if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE, + if (!(ch = sr_probe_new(i, SR_PROBE_ANALOG, TRUE, (*scope_models[model_index].analog_names)[i]))) return SR_ERR_MALLOC; - sdi->probes = g_slist_append(sdi->probes, probe); + sdi->channels = g_slist_append(sdi->channels, ch); devc->analog_groups[i].name = (char *)(*scope_models[model_index].analog_names)[i]; - devc->analog_groups[i].probes = g_slist_append(NULL, probe); + devc->analog_groups[i].channels = g_slist_append(NULL, ch); - sdi->probe_groups = g_slist_append(sdi->probe_groups, + sdi->channel_groups = g_slist_append(sdi->channel_groups, &devc->analog_groups[i]); } - /* Add digital probe groups. */ + /* Add digital channel groups. */ for (i = 0; i < scope_models[model_index].digital_pods; ++i) { g_snprintf(tmp, 25, "POD%d", i); devc->digital_groups[i].name = g_strdup(tmp); - sdi->probe_groups = g_slist_append(sdi->probe_groups, + sdi->channel_groups = g_slist_append(sdi->channel_groups, &devc->digital_groups[i < 8 ? 0 : 1]); } /* Add digital channels. */ for (i = 0; i < scope_models[model_index].digital_channels; i++) { - if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, + if (!(ch = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, (*scope_models[model_index].digital_names)[i]))) return SR_ERR_MALLOC; - sdi->probes = g_slist_append(sdi->probes, probe); + sdi->channels = g_slist_append(sdi->channels, ch); - devc->digital_groups[i < 8 ? 0 : 1].probes = g_slist_append( - devc->digital_groups[i < 8 ? 0 : 1].probes, probe); + devc->digital_groups[i < 8 ? 0 : 1].channels = g_slist_append( + devc->digital_groups[i < 8 ? 0 : 1].channels, ch); } devc->model_config = &scope_models[model_index]; @@ -651,7 +657,7 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data) { - struct sr_probe *probe; + struct sr_channel *ch; struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_datafeed_packet packet; @@ -668,9 +674,9 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data) return TRUE; if (revents == G_IO_IN) { - probe = devc->current_probe->data; + ch = devc->current_channel->data; - switch (probe->type) { + switch (ch->type) { case SR_PROBE_ANALOG: if (sr_scpi_get_floatv(sdi->conn, NULL, &data) != SR_OK) { if (data) @@ -682,7 +688,7 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data) packet.type = SR_DF_FRAME_BEGIN; sr_session_send(sdi, &packet); - analog.probes = g_slist_append(NULL, probe); + analog.channels = g_slist_append(NULL, ch); analog.num_samples = data->len; analog.data = (float *) data->data; analog.mq = SR_MQ_VOLTAGE; @@ -691,7 +697,7 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data) packet.type = SR_DF_ANALOG; packet.payload = &analog; sr_session_send(cb_data, &packet); - g_slist_free(analog.probes); + g_slist_free(analog.channels); g_array_free(data, TRUE); break; case SR_PROBE_LOGIC: @@ -713,20 +719,20 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data) g_array_free(data, TRUE); break; default: - sr_err("Invalid probe type."); + sr_err("Invalid channel type."); break; } packet.type = SR_DF_FRAME_END; sr_session_send(sdi, &packet); - if (devc->current_probe->next) { - devc->current_probe = devc->current_probe->next; + if (devc->current_channel->next) { + devc->current_channel = devc->current_channel->next; hmo_request_data(sdi); } else if (++devc->num_frames == devc->frame_limit) { sdi->driver->dev_acquisition_stop(sdi, cb_data); } else { - devc->current_probe = devc->enabled_probes; + devc->current_channel = devc->enabled_channels; hmo_request_data(sdi); } }