X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fhp-59306a%2Fapi.c;h=d2b840041d36dc227979f5b6dfde0a8f353372a4;hb=b9890a3292ac709a330208aabcc9472a019edcaf;hp=402c34fd91590adfb10ba18f41496b95e7999f10;hpb=12e7abe2197e303c484de0fa61bf2c2a96e3f596;p=libsigrok.git diff --git a/src/hardware/hp-59306a/api.c b/src/hardware/hp-59306a/api.c index 402c34fd..d2b84004 100644 --- a/src/hardware/hp-59306a/api.c +++ b/src/hardware/hp-59306a/api.c @@ -18,124 +18,169 @@ */ #include +#include "scpi.h" #include "protocol.h" +static const uint32_t scanopts[] = { + SR_CONF_CONN, +}; + +static const uint32_t drvopts[] = { + SR_CONF_MULTIPLEXER, +}; + +static const uint32_t devopts[] = { + SR_CONF_CONN | SR_CONF_GET, + SR_CONF_ENABLED | SR_CONF_SET, +}; + +static const uint32_t devopts_cg[] = { + SR_CONF_ENABLED | SR_CONF_SET, +}; + static struct sr_dev_driver hp_59306a_driver_info; -static GSList *scan(struct sr_dev_driver *di, GSList *options) +static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) { - struct drv_context *drvc; - GSList *devices; + struct sr_dev_inst *sdi; + struct dev_context *devc; + struct channel_group_context *cgc; + size_t idx, nr; + struct sr_channel_group *cg; + char cg_name[24]; + + /* + * The device cannot get identified by means of SCPI queries. + * Neither shall non-SCPI requests get emitted before reliable + * identification of the device. Assume that we only get here + * when user specs led us to believe it's safe to communicate + * to the expected kind of device. + */ + + sdi = g_malloc0(sizeof(*sdi)); + sdi->vendor = g_strdup("Hewlett-Packard"); + sdi->model = g_strdup("59306A"); + sdi->conn = scpi; + sdi->driver = &hp_59306a_driver_info; + sdi->inst_type = SR_INST_SCPI; + if (sr_scpi_connection_id(scpi, &sdi->connection_id) != SR_OK) { + g_free(sdi->connection_id); + sdi->connection_id = NULL; + } + + devc = g_malloc0(sizeof(*devc)); + sdi->priv = devc; + + devc->channel_count = 6; + for (idx = 0; idx < devc->channel_count; idx++) { + nr = idx + 1; + snprintf(cg_name, sizeof(cg_name), "R%zu", nr); + cgc = g_malloc0(sizeof(*cgc)); + cgc->number = nr; + cg = sr_channel_group_new(sdi, cg_name, cgc); + (void)cg; + } - (void)options; + return sdi; +} - devices = NULL; - drvc = di->context; - drvc->instances = NULL; +static GSList *scan(struct sr_dev_driver *di, GSList *options) +{ + const char *conn; - /* TODO: scan for devices, either based on a SR_CONF_CONN option - * or on a USB scan. */ + /* Only scan for a device when conn= was specified. */ + conn = NULL; + (void)sr_serial_extract_options(options, &conn, NULL); + if (!conn) + return NULL; - return devices; + return sr_scpi_scan(di->context, options, probe_device); } static int dev_open(struct sr_dev_inst *sdi) { - (void)sdi; - - /* TODO: get handle from sdi->conn and open it. */ - - return SR_OK; + return sr_scpi_open(sdi->conn); } static int dev_close(struct sr_dev_inst *sdi) { - (void)sdi; - - /* TODO: get handle from sdi->conn and close it. */ - - return SR_OK; + return sr_scpi_close(sdi->conn); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - int ret; - - (void)sdi; - (void)data; (void)cg; - ret = SR_OK; + if (!sdi || !data) + return SR_ERR_ARG; + switch (key) { - /* TODO */ + case SR_CONF_CONN: + *data = g_variant_new_string(sdi->connection_id); + break; default: return SR_ERR_NA; } - return ret; + return SR_OK; } static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - int ret; - - (void)sdi; - (void)data; - (void)cg; - - ret = SR_OK; - switch (key) { - /* TODO */ - default: - ret = SR_ERR_NA; + gboolean on; + + if (!cg) { + switch (key) { + case SR_CONF_ENABLED: + /* Enable/disable all channels at the same time. */ + on = g_variant_get_boolean(data); + return hp_59306a_switch_cg(sdi, cg, on); + default: + return SR_ERR_NA; + } + } else { + switch (key) { + case SR_CONF_ENABLED: + on = g_variant_get_boolean(data); + return hp_59306a_switch_cg(sdi, cg, on); + default: + return SR_ERR_NA; + } } - return ret; + return SR_OK; } static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - int ret; - - (void)sdi; - (void)data; - (void)cg; - - ret = SR_OK; - switch (key) { - /* TODO */ - default: - return SR_ERR_NA; + if (!cg) { + switch (key) { + case SR_CONF_SCAN_OPTIONS: + case SR_CONF_DEVICE_OPTIONS: + return STD_CONFIG_LIST(key, data, sdi, cg, + scanopts, drvopts, devopts); + default: + return SR_ERR_NA; + } + } else { + switch (key) { + case SR_CONF_DEVICE_OPTIONS: + *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg)); + break; + default: + return SR_ERR_NA; + } } - return ret; -} - -static int dev_acquisition_start(const struct sr_dev_inst *sdi) -{ - /* TODO: configure hardware, reset acquisition state, set up - * callbacks and send header packet. */ - - (void)sdi; - - return SR_OK; -} - -static int dev_acquisition_stop(struct sr_dev_inst *sdi) -{ - /* TODO: stop acquisition. */ - - (void)sdi; - return SR_OK; } static struct sr_dev_driver hp_59306a_driver_info = { .name = "hp-59306a", - .longname = "hp-59306a", + .longname = "HP 59306A", .api_version = 1, .init = std_init, .cleanup = std_cleanup, @@ -147,8 +192,8 @@ static struct sr_dev_driver hp_59306a_driver_info = { .config_list = config_list, .dev_open = dev_open, .dev_close = dev_close, - .dev_acquisition_start = dev_acquisition_start, - .dev_acquisition_stop = dev_acquisition_stop, + .dev_acquisition_start = std_dummy_dev_acquisition_start, + .dev_acquisition_stop = std_dummy_dev_acquisition_stop, .context = NULL, }; SR_REGISTER_DEV_DRIVER(hp_59306a_driver_info);