X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fscpi-pps%2Fapi.c;h=2a7c80cc67b91f201d366d574182dac73f981c48;hb=9d9cf1c4b902c4556ba32d6f6c5566b48f3d1515;hp=0c19c0177aca5edf8e1c035b74b0fa04e666de2a;hpb=d4eabea847e675bc333be1e51ead4e0be6fc976b;p=libsigrok.git diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index 0c19c017..2a7c80cc 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -25,11 +25,21 @@ static struct sr_dev_driver *di = &scpi_pps_driver_info; extern unsigned int num_pps_profiles; extern const struct scpi_pps pps_profiles[]; -static const int32_t scanopts[] = { +static const uint32_t scanopts[] = { SR_CONF_CONN, SR_CONF_SERIALCOMM, }; +static const uint32_t drvopts[] = { + SR_CONF_POWER_SUPPLY, +}; + +static struct pps_channel_instance pci[] = { + { SR_MQ_VOLTAGE, SCPI_CMD_GET_MEAS_VOLTAGE, "V" }, + { SR_MQ_CURRENT, SCPI_CMD_GET_MEAS_CURRENT, "I" }, + { SR_MQ_POWER, SCPI_CMD_GET_MEAS_POWER, "P" }, +}; + static int init(struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); @@ -43,10 +53,18 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) struct sr_channel_group *cg; struct sr_channel *ch; const struct scpi_pps *device; - const struct channel_group_spec *cgs; + struct pps_channel *pch; + struct channel_spec *channels; + struct channel_group_spec *channel_groups, *cgs; struct pps_channel_group *pcg; + GRegex *model_re; + GMatchInfo *model_mi; + GSList *l; uint64_t mask; - unsigned int i, j; + unsigned int num_channels, num_channel_groups, ch_num, ch_idx, i, j; + int ret; + const char *vendor; + char ch_name[16]; if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) { sr_info("Couldn't get IDN response."); @@ -55,40 +73,88 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) device = NULL; for (i = 0; i < num_pps_profiles; i++) { - if (!strcasecmp(hw_info->manufacturer, pps_profiles[i].idn_vendor) && - !strcmp(hw_info->model, pps_profiles[i].idn_model)) { + vendor = get_vendor(hw_info->manufacturer); + if (strcasecmp(vendor, pps_profiles[i].vendor)) + continue; + model_re = g_regex_new(pps_profiles[i].model, 0, 0, NULL); + if (g_regex_match(model_re, hw_info->model, 0, &model_mi)) device = &pps_profiles[i]; + g_match_info_unref(model_mi); + g_regex_unref(model_re); + if (device) break; - } } if (!device) { sr_scpi_hw_info_free(hw_info); return NULL; } - sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, device->vendor, device->idn_model, - hw_info->firmware_version); + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_ACTIVE; + sdi->vendor = g_strdup(vendor); + sdi->model = g_strdup(hw_info->model); + sdi->version = g_strdup(hw_info->firmware_version); sdi->conn = scpi; sdi->driver = di; sdi->inst_type = SR_INST_SCPI; + sdi->serial_num = g_strdup(hw_info->serial_number); + devc = g_malloc0(sizeof(struct dev_context)); devc->device = device; sdi->priv = devc; - for (i = 0; i < device->num_channels; i++) { - ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, - device->channels[i].name); - sdi->channels = g_slist_append(sdi->channels, ch); + if (device->num_channels) { + /* Static channels and groups. */ + channels = device->channels; + num_channels = device->num_channels; + channel_groups = device->channel_groups; + num_channel_groups = device->num_channel_groups; + } else { + /* Channels and groups need to be probed. */ + ret = device->probe_channels(sdi, hw_info, &channels, &num_channels, + &channel_groups, &num_channel_groups); + if (ret != SR_OK) { + sr_err("Failed to probe for channels."); + return NULL; + } + /* + * Since these were dynamically allocated, we'll need to free them + * later. + */ + devc->channels = channels; + devc->channel_groups = channel_groups; + } + + ch_idx = 0; + for (ch_num = 0; ch_num < num_channels; ch_num++) { + /* Create one channel per measurable output unit. */ + for (i = 0; i < ARRAY_SIZE(pci); i++) { + if (!scpi_cmd_get(sdi, pci[i].command)) + continue; + g_snprintf(ch_name, 16, "%s%s", pci[i].prefix, + channels[ch_num].name); + ch = sr_channel_new(ch_idx++, SR_CHANNEL_ANALOG, TRUE, ch_name); + pch = g_malloc0(sizeof(struct pps_channel)); + pch->hw_output_idx = ch_num; + pch->hwname = channels[ch_num].name; + pch->mq = pci[i].mq; + ch->priv = pch; + sdi->channels = g_slist_append(sdi->channels, ch); + } } - for (i = 0; i < device->num_channel_groups; i++) { - cgs = &device->channel_groups[i]; + for (i = 0; i < num_channel_groups; i++) { + cgs = &channel_groups[i]; cg = g_malloc0(sizeof(struct sr_channel_group)); cg->name = g_strdup(cgs->name); for (j = 0, mask = 1; j < 64; j++, mask <<= 1) { if (cgs->channel_index_mask & mask) { - ch = g_slist_nth_data(sdi->channels, j); - cg->channels = g_slist_append(cg->channels, ch); + for (l = sdi->channels; l; l = l->next) { + ch = l->data; + pch = ch->priv; + if (pch->hw_output_idx == j) + cg->channels = g_slist_append(cg->channels, ch); + } } } pcg = g_malloc0(sizeof(struct pps_channel_group)); @@ -97,8 +163,10 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); } - /* SCPI devices commonly lock the panel keys when accessed remotely. */ - scpi_cmd(sdi, SCPI_CMD_KEY_UNLOCK); + sr_scpi_hw_info_free(hw_info); + hw_info = NULL; + + scpi_cmd(sdi, SCPI_CMD_LOCAL); sr_scpi_close(scpi); return sdi; @@ -121,7 +189,9 @@ static int dev_clear(void) static int dev_open(struct sr_dev_inst *sdi) { + struct dev_context *devc; struct sr_scpi_dev_inst *scpi; + GVariant *beeper; if (sdi->status != SR_ST_ACTIVE) return SR_ERR; @@ -132,19 +202,34 @@ static int dev_open(struct sr_dev_inst *sdi) sdi->status = SR_ST_ACTIVE; + scpi_cmd(sdi, SCPI_CMD_REMOTE); + devc = sdi->priv; + devc->beeper_was_set = FALSE; + if (scpi_cmd_resp(sdi, &beeper, G_VARIANT_TYPE_BOOLEAN, SCPI_CMD_BEEPER) == SR_OK) { + if (g_variant_get_boolean(beeper)) { + devc->beeper_was_set = TRUE; + scpi_cmd(sdi, SCPI_CMD_BEEPER_DISABLE); + } + g_variant_unref(beeper); + } + return SR_OK; } static int dev_close(struct sr_dev_inst *sdi) { struct sr_scpi_dev_inst *scpi; + struct dev_context *devc; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; + devc = sdi->priv; scpi = sdi->conn; if (scpi) { - scpi_cmd(sdi, SCPI_CMD_KEY_UNLOCK); + if (devc->beeper_was_set) + scpi_cmd(sdi, SCPI_CMD_BEEPER_ENABLE); + scpi_cmd(sdi, SCPI_CMD_LOCAL); sr_scpi_close(scpi); sdi->status = SR_ST_INACTIVE; } @@ -152,277 +237,185 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } +static void clear_helper(void *priv) +{ + struct dev_context *devc; + + devc = priv; + g_free(devc->channels); + g_free(devc->channel_groups); + g_free(devc); +} + static int cleanup(void) { - return SR_OK; + return std_dev_clear(di, clear_helper); } -static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi, +static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; - struct sr_scpi_dev_inst *scpi; - struct sr_channel *ch; - double d; - int ret; - char *s; + const GVariantType *gvtype; + unsigned int i; + int cmd, ret; if (!sdi) return SR_ERR_ARG; devc = sdi->priv; - scpi = sdi->conn; - ret = SR_OK; - if (!cg) { - /* No channel group: global options. */ - switch (key) { - case SR_CONF_OVER_TEMPERATURE_PROTECTION: - ret = SR_ERR; - if (scpi_cmd(sdi, SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION) == SR_OK) { - if (sr_scpi_get_string(scpi, NULL, &s) == SR_OK) { - *data = g_variant_new_boolean(!strcmp(s, "ON")); - ret = SR_OK; - } - } - break; - return SR_ERR_NA; - break; - case SR_CONF_OUTPUT_CHANNEL_CONFIG: - ret = SR_ERR; - if (scpi_cmd(sdi, SCPI_CMD_GET_OUTPUT_CHANNEL_CONFIG) == SR_OK) { - if (sr_scpi_get_string(scpi, NULL, &s) == SR_OK) { - *data = g_variant_new_string(s); - g_free(s); - ret = SR_OK; - } - } - break; - default: - return SR_ERR_NA; - } - } else { + if (cg) { /* * These options only apply to channel groups with a single * channel -- they're per-channel settings for the device. */ - if (g_slist_length(cg->channels) > 1) - return SR_ERR_NA; - ch = cg->channels->data; - switch (key) { - case SR_CONF_OUTPUT_REGULATION: - ret = SR_ERR; - if (scpi_cmd(sdi, SCPI_CMD_GET_OUTPUT_REGULATION, ch->name) == SR_OK) { - if (sr_scpi_get_string(scpi, NULL, &s) == SR_OK) { - if (strcmp(s, "CC") && strcmp(s, "CV") && strcmp(s, "UR")) { - sr_dbg("Unknown response to SCPI_CMD_GET_OUTPUT_REGULATION: %s", s); - } else { - *data = g_variant_new_string(s); - g_free(s); - ret = SR_OK; - } - } - } - break; - case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: - ret = SR_ERR; - if (scpi_cmd(sdi, SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED, - ch->name) == SR_OK) { - if (sr_scpi_get_string(scpi, NULL, &s) == SR_OK) { - *data = g_variant_new_boolean(!strcmp(s, "ON")); - ret = SR_OK; - } - } - break; - case SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE: - ret = SR_ERR; - if (scpi_cmd(sdi, SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, - ch->name) == SR_OK) { - if (sr_scpi_get_string(scpi, NULL, &s) == SR_OK) { - *data = g_variant_new_boolean(!strcmp(s, "YES")); - ret = SR_OK; - } - } - break; - case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD: - ret = SR_ERR; - if (scpi_cmd(sdi, SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, - ch->name) == SR_OK) { - if (sr_scpi_get_double(scpi, NULL, &d) == SR_OK) { - *data = g_variant_new_double(d); - ret = SR_OK; - } - } - break; - case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: - ret = SR_ERR; - if (scpi_cmd(sdi, SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, - ch->name) == SR_OK) { - if (sr_scpi_get_string(scpi, NULL, &s) == SR_OK) { - *data = g_variant_new_boolean(!strcmp(s, "ON")); - ret = SR_OK; - } - } - break; - case SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE: - ret = SR_ERR; - if (scpi_cmd(sdi, SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE, - ch->name) == SR_OK) { - if (sr_scpi_get_string(scpi, NULL, &s) == SR_OK) { - *data = g_variant_new_boolean(!strcmp(s, "YES")); - ret = SR_OK; - } - } - break; - case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD: - ret = SR_ERR; - if (scpi_cmd(sdi, SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, - ch->name) == SR_OK) { - if (sr_scpi_get_double(scpi, NULL, &d) == SR_OK) { - *data = g_variant_new_double(d); - ret = SR_OK; - } - } - break; - case SR_CONF_OUTPUT_VOLTAGE: - ret = SR_ERR; - if (scpi_cmd(sdi, SCPI_CMD_GET_MEAS_VOLTAGE, ch->name) == SR_OK) { - if (sr_scpi_get_double(scpi, NULL, &d) == SR_OK) { - *data = g_variant_new_double(d); - ret = SR_OK; - } - } - break; - case SR_CONF_OUTPUT_VOLTAGE_MAX: - ret = SR_ERR; - if (scpi_cmd(sdi, SCPI_CMD_GET_VOLTAGE_MAX, ch->name) == SR_OK) { - if (sr_scpi_get_double(scpi, NULL, &d) == SR_OK) { - *data = g_variant_new_double(d); - ret = SR_OK; - } - } - break; - case SR_CONF_OUTPUT_CURRENT: - ret = SR_ERR; - if (scpi_cmd(sdi, SCPI_CMD_GET_MEAS_CURRENT, ch->name) == SR_OK) { - if (sr_scpi_get_double(scpi, NULL, &d) == SR_OK) { - *data = g_variant_new_double(d); - ret = SR_OK; - } - } - break; - case SR_CONF_OUTPUT_CURRENT_MAX: - ret = SR_ERR; - if (scpi_cmd(sdi, SCPI_CMD_GET_CURRENT_MAX, ch->name) == SR_OK) { - if (sr_scpi_get_double(scpi, NULL, &d) == SR_OK) { - *data = g_variant_new_double(d); - ret = SR_OK; - } - } - break; - case SR_CONF_OUTPUT_ENABLED: - ret = SR_ERR; - if (scpi_cmd(sdi, SCPI_CMD_GET_OUTPUT_ENABLED, ch->name) == SR_OK) { - if (sr_scpi_get_string(scpi, NULL, &s) == SR_OK) { - *data = g_variant_new_boolean(!strcmp(s, "ON")); - ret = SR_OK; - } + /* + * Config keys are handled below depending on whether a channel + * group was provided by the frontend. However some of these + * take a CG on one PPS but not on others. Check the device's + * profile for that here, and NULL out the channel group as needed. + */ + for (i = 0; i < devc->device->num_devopts; i++) { + if (devc->device->devopts[i] == key) { + cg = NULL; + break; } - break; - default: - return SR_ERR_NA; } } + gvtype = NULL; + cmd = -1; + switch (key) { + case SR_CONF_OUTPUT_ENABLED: + gvtype = G_VARIANT_TYPE_BOOLEAN; + cmd = SCPI_CMD_GET_OUTPUT_ENABLED; + break; + case SR_CONF_OUTPUT_VOLTAGE: + gvtype = G_VARIANT_TYPE_DOUBLE; + cmd = SCPI_CMD_GET_MEAS_VOLTAGE; + break; + case SR_CONF_OUTPUT_VOLTAGE_TARGET: + gvtype = G_VARIANT_TYPE_DOUBLE; + cmd = SCPI_CMD_GET_VOLTAGE_TARGET; + break; + case SR_CONF_OUTPUT_CURRENT: + gvtype = G_VARIANT_TYPE_DOUBLE; + cmd = SCPI_CMD_GET_MEAS_CURRENT; + break; + case SR_CONF_OUTPUT_CURRENT_LIMIT: + gvtype = G_VARIANT_TYPE_DOUBLE; + cmd = SCPI_CMD_GET_CURRENT_LIMIT; + break; + case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: + gvtype = G_VARIANT_TYPE_BOOLEAN; + cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED; + break; + case SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE: + gvtype = G_VARIANT_TYPE_BOOLEAN; + cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE; + break; + case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD: + gvtype = G_VARIANT_TYPE_DOUBLE; + cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD; + break; + case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: + gvtype = G_VARIANT_TYPE_BOOLEAN; + cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED; + break; + case SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE: + gvtype = G_VARIANT_TYPE_BOOLEAN; + cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE; + break; + case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD: + gvtype = G_VARIANT_TYPE_DOUBLE; + cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD; + break; + case SR_CONF_OVER_TEMPERATURE_PROTECTION: + gvtype = G_VARIANT_TYPE_BOOLEAN; + cmd = SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION; + break; + case SR_CONF_OUTPUT_REGULATION: + gvtype = G_VARIANT_TYPE_STRING; + cmd = SCPI_CMD_GET_OUTPUT_REGULATION; + } + if (gvtype) { + if (cg) + select_channel(sdi, cg->channels->data); + ret = scpi_cmd_resp(sdi, data, gvtype, cmd); + } else + ret = SR_ERR_NA; + return ret; } -static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi, +static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - struct sr_channel *ch; double d; int ret; - const char *s; + + if (!sdi) + return SR_ERR_ARG; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; + if (cg) + /* Channel group specified. */ + select_channel(sdi, cg->channels->data); ret = SR_OK; - if (!cg) { - switch (key) { - /* No channel group: global options. */ - case SR_CONF_OVER_TEMPERATURE_PROTECTION: - s = g_variant_get_boolean(data) ? "ON" : "OFF"; - if (scpi_cmd(sdi, SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION, s) < 0) - ret = SR_ERR; - break; - case SR_CONF_OUTPUT_CHANNEL_CONFIG: - s = g_variant_get_string(data, NULL); - if (scpi_cmd(sdi, SCPI_CMD_SET_OUTPUT_CHANNEL_CONFIG, s) < 0) - ret = SR_ERR; - break; - default: - ret = SR_ERR_NA; - } - } else { - /* Channel group specified. */ - if (!sdi) - return SR_ERR_ARG; - if (g_slist_length(cg->channels) > 1) - return SR_ERR_NA; - ch = cg->channels->data; - switch (key) { - case SR_CONF_OUTPUT_VOLTAGE_MAX: - d = g_variant_get_double(data); - if (scpi_cmd(sdi, SCPI_CMD_SET_VOLTAGE_MAX, ch->name, d) < 0) - ret = SR_ERR; - break; - case SR_CONF_OUTPUT_CURRENT_MAX: - d = g_variant_get_double(data); - if (scpi_cmd(sdi, SCPI_CMD_SET_CURRENT_MAX, ch->name, d) < 0) - ret = SR_ERR; - break; - case SR_CONF_OUTPUT_ENABLED: - s = g_variant_get_boolean(data) ? "ON" : "OFF"; - if (scpi_cmd(sdi, SCPI_CMD_SET_OUTPUT_ENABLED, ch->name, s) < 0) - ret = SR_ERR; - break; - case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: - s = g_variant_get_boolean(data) ? "ON" : "OFF"; - if (scpi_cmd(sdi, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLED, - ch->name, s) < 0) - ret = SR_ERR; - break; - case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD: - d = g_variant_get_double(data); - if (scpi_cmd(sdi, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, - ch->name, d) < 0) - ret = SR_ERR; - break; - case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: - s = g_variant_get_boolean(data) ? "ON" : "OFF"; - if (scpi_cmd(sdi, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLED, - ch->name, s) < 0) - ret = SR_ERR; - break; - case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD: - d = g_variant_get_double(data); - if (scpi_cmd(sdi, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, - ch->name, d) < 0) - ret = SR_ERR; - break; - default: - ret = SR_ERR_NA; - } + switch (key) { + case SR_CONF_OUTPUT_ENABLED: + if (g_variant_get_boolean(data)) + ret = scpi_cmd(sdi, SCPI_CMD_SET_OUTPUT_ENABLE); + else + ret = scpi_cmd(sdi, SCPI_CMD_SET_OUTPUT_DISABLE); + break; + case SR_CONF_OUTPUT_VOLTAGE_TARGET: + d = g_variant_get_double(data); + ret = scpi_cmd(sdi, SCPI_CMD_SET_VOLTAGE_TARGET, d); + break; + case SR_CONF_OUTPUT_CURRENT_LIMIT: + d = g_variant_get_double(data); + ret = scpi_cmd(sdi, SCPI_CMD_SET_CURRENT_LIMIT, d); + break; + case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: + if (g_variant_get_boolean(data)) + ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE); + else + ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE); + break; + case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD: + d = g_variant_get_double(data); + ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, d); + break; + case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: + if (g_variant_get_boolean(data)) + ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE); + else + ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE); + break; + case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD: + d = g_variant_get_double(data); + ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, d); + break; + case SR_CONF_OVER_TEMPERATURE_PROTECTION: + if (g_variant_get_boolean(data)) + ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE); + else + ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE); + break; + default: + ret = SR_ERR_NA; } return ret; } -static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, +static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; @@ -435,8 +428,12 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, /* Always available, even without sdi. */ if (key == SR_CONF_SCAN_OPTIONS) { - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - scanopts, ARRAY_SIZE(scanopts), sizeof(int32_t)); + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); + return SR_OK; + } else if (key == SR_CONF_DEVICE_OPTIONS && !sdi) { + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); return SR_OK; } @@ -449,11 +446,12 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, /* No channel group: global options. */ switch (key) { case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, devc->device->devopts, devc->device->num_devopts, - sizeof(int32_t)); + sizeof(uint32_t)); break; case SR_CONF_OUTPUT_CHANNEL_CONFIG: + /* Not used. */ i = 0; if (devc->device->features & PPS_INDEPENDENT) s[i++] = "Independent"; @@ -475,26 +473,21 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, } } else { /* Channel group specified. */ - if (!sdi) - return SR_ERR_ARG; /* * Per-channel-group options depending on a channel are actually * done with the first channel. Channel groups in PPS can have * more than one channel, but they will typically be of equal - * specification for use in series or parallel mode. Drop requests - * for groups with more than one channel just to make sure. + * specification for use in series or parallel mode. */ - if (g_slist_length(cg->channels) > 1) - return SR_ERR_NA; ch = cg->channels->data; switch (key) { case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, devc->device->devopts_cg, devc->device->num_devopts_cg, - sizeof(int32_t)); + sizeof(uint32_t)); break; - case SR_CONF_OUTPUT_VOLTAGE_MAX: + case SR_CONF_OUTPUT_VOLTAGE_TARGET: ch_spec = &(devc->device->channels[ch->index]); g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); /* Min, max, write resolution. */ @@ -504,7 +497,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, } *data = g_variant_builder_end(&gvb); break; - case SR_CONF_OUTPUT_CURRENT_MAX: + case SR_CONF_OUTPUT_CURRENT_LIMIT: g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); /* Min, max, step. */ for (i = 0; i < 3; i++) { @@ -528,7 +521,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, struct dev_context *devc; struct sr_scpi_dev_inst *scpi; struct sr_channel *ch; - int ret; + struct pps_channel *pch; + int cmd, ret; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; @@ -537,23 +531,32 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, scpi = sdi->conn; devc->cb_data = cb_data; - if ((ret = sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 100, + if ((ret = sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 10, scpi_pps_receive_data, (void *)sdi)) != SR_OK) return ret; std_session_send_df_header(sdi, LOG_PREFIX); - /* Prime the pipe. */ - devc->state = STATE_VOLTAGE; - ch = sdi->channels->data; - devc->cur_channel = ch; - scpi_cmd(sdi, SCPI_CMD_GET_MEAS_VOLTAGE, ch->name); + /* Prime the pipe with the first channel's fetch. */ + ch = next_enabled_channel(sdi, NULL); + pch = ch->priv; + if ((ret = select_channel(sdi, ch)) != SR_OK) + return ret; + if (pch->mq == SR_MQ_VOLTAGE) + cmd = SCPI_CMD_GET_MEAS_VOLTAGE; + else if (pch->mq == SR_MQ_CURRENT) + cmd = SCPI_CMD_GET_MEAS_CURRENT; + else if (pch->mq == SR_MQ_POWER) + cmd = SCPI_CMD_GET_MEAS_POWER; + else + return SR_ERR; + scpi_cmd(sdi, cmd, pch->hwname); return SR_OK; } static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { - struct dev_context *devc; + struct sr_datafeed_packet packet; struct sr_scpi_dev_inst *scpi; float f; @@ -562,7 +565,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - devc = sdi->priv; scpi = sdi->conn; /* @@ -573,8 +575,8 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) sr_scpi_get_float(scpi, NULL, &f); sr_scpi_source_remove(sdi->session, scpi); - /* Just in case something is queued up. */ - devc->state = STATE_STOP; + packet.type = SR_DF_END; + sr_session_send(sdi, &packet); return SR_OK; }