#include "protocol.h"
-static const char *manufacturers[] = {
- "HAMEG",
-};
-
static const char *hameg_scpi_dialect[] = {
[SCPI_CMD_GET_DIG_DATA] = ":POD%d:DATA?",
[SCPI_CMD_GET_TIMEBASE] = ":TIM:SCAL?",
- [SCPI_CMD_SET_TIMEBASE] = ":TIM:SCAL %E",
+ [SCPI_CMD_SET_TIMEBASE] = ":TIM:SCAL %s",
[SCPI_CMD_GET_COUPLING] = ":CHAN%d:COUP?",
[SCPI_CMD_SET_COUPLING] = ":CHAN%d:COUP %s",
+ [SCPI_CMD_GET_SAMPLE_RATE] = ":ACQ:SRAT?",
+ [SCPI_CMD_GET_SAMPLE_RATE_LIVE] = ":%s:DATA:POINTS?",
[SCPI_CMD_GET_ANALOG_DATA] = ":CHAN%d:DATA?",
[SCPI_CMD_GET_VERTICAL_DIV] = ":CHAN%d:SCAL?",
- [SCPI_CMD_SET_VERTICAL_DIV] = ":CHAN%d:SCAL %E",
+ [SCPI_CMD_SET_VERTICAL_DIV] = ":CHAN%d:SCAL %s",
[SCPI_CMD_GET_DIG_POD_STATE] = ":POD%d:STAT?",
[SCPI_CMD_SET_DIG_POD_STATE] = ":POD%d:STAT %d",
[SCPI_CMD_GET_TRIGGER_SLOPE] = ":TRIG:A:EDGE:SLOP?",
SR_CONF_NUM_TIMEBASE,
SR_CONF_TRIGGER_SLOPE,
SR_CONF_HORIZ_TRIGGERPOS,
+ SR_CONF_SAMPLERATE,
+ SR_CONF_LIMIT_FRAMES,
};
static const int32_t hmo_analog_caps[] = {
"AC",
"ACL",
"DC",
+ "DCL",
"GND",
NULL,
};
},
};
-static int check_manufacturer(const char *manufacturer)
-{
- unsigned int i;
-
- for (i = 0; i < ARRAY_SIZE(manufacturers); ++i)
- if (!strcmp(manufacturer, manufacturers[i]))
- return SR_OK;
-
- return SR_ERR;
-}
-
static void scope_state_dump(struct scope_config *config,
struct scope_state *state)
{
unsigned int i;
+ char *tmp;
for (i = 0; i < config->analog_channels; ++i) {
- sr_info("State of analog channel %d -> %s : %s %.3eV %.3e offset", i + 1,
- state->analog_channels[i].state ? "On" : "Off",
+ tmp = sr_voltage_string((*config->vdivs)[state->analog_channels[i].vdiv][0],
+ (*config->vdivs)[state->analog_channels[i].vdiv][1]);
+ sr_info("State of analog channel %d -> %s : %s (coupling) %s (vdiv) %2.2e (offset)",
+ i + 1, state->analog_channels[i].state ? "On" : "Off",
(*config->coupling_options)[state->analog_channels[i].coupling],
- state->analog_channels[i].vdiv, state->analog_channels[i].vertical_offset);
+ tmp, state->analog_channels[i].vertical_offset);
}
for (i = 0; i < config->digital_channels; ++i) {
state->digital_pods[i] ? "On" : "Off");
}
- sr_info("Current timebase: %.2es", state->timebase);
- sr_info("Current trigger: %s (source), %s (slope) %.2e (offset)",
+ tmp = sr_period_string((*config->timebases)[state->timebase][0] *
+ (*config->timebases)[state->timebase][1]);
+ sr_info("Current timebase: %s", tmp);
+ g_free(tmp);
+
+ tmp = sr_samplerate_string(state->sample_rate);
+ sr_info("Current samplerate: %s", tmp);
+ g_free(tmp);
+
+ sr_info("Current trigger: %s (source), %s (slope) %2.2e (offset)",
(*config->trigger_sources)[state->trigger_source],
(*config->trigger_slopes)[state->trigger_slope],
state->horiz_triggerpos);
struct scope_config *config,
struct scope_state *state)
{
- unsigned int i;
+ unsigned int i, j;
+ float tmp_float;
char command[MAX_COMMAND_SIZE];
for (i = 0; i < config->analog_channels; ++i) {
(*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_DIV],
i + 1);
- if (sr_scpi_get_float(scpi, command,
- &state->analog_channels[i].vdiv) != SR_OK)
+ if (sr_scpi_get_float(scpi, command, &tmp_float) != SR_OK)
+ return SR_ERR;
+ for (j = 0; j < config->num_vdivs; j++) {
+ if (tmp_float == ((float) (*config->vdivs)[j][0] /
+ (*config->vdivs)[j][1])) {
+ state->analog_channels[i].vdiv = j;
+ break;
+ }
+ }
+ if (i == config->num_vdivs)
return SR_ERR;
g_snprintf(command, sizeof(command),
return SR_OK;
}
+SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi)
+{
+ struct dev_context *devc;
+ struct scope_state *state;
+ struct scope_config *config;
+
+ int tmp;
+ unsigned int i;
+ float tmp_float;
+ gboolean channel_found;
+ char tmp_str[MAX_COMMAND_SIZE];
+ char chan_name[20];
+
+ devc = sdi->priv;
+ config = devc->model_config;
+ state = devc->model_state;
+ channel_found = FALSE;
+
+ for (i = 0; i < config->analog_channels; ++i) {
+ if (state->analog_channels[i].state) {
+ g_snprintf(chan_name, sizeof(chan_name), "CHAN%d", i + 1);
+ g_snprintf(tmp_str, sizeof(tmp_str),
+ (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE],
+ chan_name);
+ channel_found = TRUE;
+ break;
+ }
+ }
+
+ if (!channel_found) {
+ for (i = 0; i < config->digital_pods; i++) {
+ if (state->digital_pods[i]) {
+ g_snprintf(chan_name, sizeof(chan_name), "POD%d", i);
+ g_snprintf(tmp_str, sizeof(tmp_str),
+ (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE],
+ chan_name);
+ channel_found = TRUE;
+ break;
+ }
+ }
+ }
+
+ /* No channel is active, ask the instrument for the sample rate
+ * in single shot mode */
+ if (!channel_found) {
+ 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)
+ return SR_ERR;
+ state->sample_rate = tmp / (((float) (*config->timebases)[state->timebase][0] /
+ (*config->timebases)[state->timebase][1]) *
+ config->num_xdivs);
+ }
+
+ return SR_OK;
+}
+
SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi)
{
struct dev_context *devc;
struct scope_state *state;
struct scope_config *config;
+ float tmp_float;
+ unsigned int i;
devc = sdi->priv;
config = devc->model_config;
state = devc->model_state;
+ sr_info("Fetching scope state");
+
if (analog_channel_state_get(sdi->conn, config, state) != SR_OK)
return SR_ERR;
if (digital_channel_state_get(sdi->conn, config, state) != SR_OK)
return SR_ERR;
- /* TODO: Check if value is sensible. */
if (sr_scpi_get_float(sdi->conn,
(*config->scpi_dialect)[SCPI_CMD_GET_TIMEBASE],
- &state->timebase) != SR_OK)
+ &tmp_float) != SR_OK)
+ return SR_ERR;
+
+ for (i = 0; i < config->num_timebases; i++) {
+ if (tmp_float == ((float) (*config->timebases)[i][0] /
+ (*config->timebases)[i][1])) {
+ state->timebase = i;
+ break;
+ }
+ }
+ if (i == config->num_timebases)
return SR_ERR;
if (sr_scpi_get_float(sdi->conn,
config->trigger_slopes, &state->trigger_slope) != SR_OK)
return SR_ERR;
+ if (hmo_update_sample_rate(sdi) != SR_OK)
+ return SR_ERR;
+
+ sr_info("Fetching finished.");
+
scope_state_dump(config, state);
return SR_OK;
}
-SR_PRIV struct scope_state *scope_state_new(struct scope_config *config)
+static struct scope_state *scope_state_new(struct scope_config *config)
{
struct scope_state *state;
return SR_OK;
}
-SR_PRIV struct sr_dev_inst *hmo_probe_serial_device(const char *serial_device,
- const char *serial_options)
-{
- struct sr_dev_inst *sdi;
- struct dev_context *devc;
- struct sr_scpi_hw_info *hw_info;
- struct sr_scpi_dev_inst *scpi;
-
- sdi = NULL;
- devc = NULL;
- scpi = NULL;
- hw_info = NULL;
-
- if (!(scpi = scpi_serial_dev_inst_new(serial_device, serial_options)))
- goto fail;
-
- sr_info("Probing %s.", serial_device);
- if (sr_scpi_open(scpi) != SR_OK)
- goto fail;
-
- if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
- sr_info("Couldn't get IDN response.");
- goto fail;
- }
-
- if (check_manufacturer(hw_info->manufacturer) != SR_OK)
- goto fail;
-
- if (!(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE,
- hw_info->manufacturer, hw_info->model,
- hw_info->firmware_version))) {
- goto fail;
- }
- sr_scpi_hw_info_free(hw_info);
- hw_info = NULL;
-
- if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
- goto fail;
-
- sdi->driver = di;
- sdi->priv = devc;
- sdi->inst_type = SR_INST_SCPI;
- sdi->conn = scpi;
-
- if (hmo_init_device(sdi) != SR_OK)
- goto fail;
-
- return sdi;
-
-fail:
- if (hw_info)
- sr_scpi_hw_info_free(hw_info);
- if (scpi)
- sr_scpi_free(scpi);
- if (sdi)
- sr_dev_inst_free(sdi);
- if (devc)
- g_free(devc);
-
- return NULL;
-}
-
SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data)
{
struct sr_probe *probe;
devc->current_probe = devc->current_probe->next;
hmo_request_data(sdi);
} else if (++devc->num_frames == devc->frame_limit) {
- packet.type = SR_DF_END;
- sr_session_send(sdi, &packet);
sdi->driver->dev_acquisition_stop(sdi, cb_data);
} else {
devc->current_probe = devc->enabled_probes;