X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fhardware%2Fagilent-dmm%2Fapi.c;h=1165dc5ae3056702f0050bd1a9d53fa1b2fb9ed7;hb=15a5bfe4815f9991a9bb532c05d6244a1818a0e4;hp=55f87416721df2bc198fac3f8ab85f7df33d3508;hpb=ee2bcdfc44f285c5a7b93fcba625409fdd25dcc3;p=libsigrok.git
diff --git a/src/hardware/agilent-dmm/api.c b/src/hardware/agilent-dmm/api.c
index 55f87416..1165dc5a 100644
--- a/src/hardware/agilent-dmm/api.c
+++ b/src/hardware/agilent-dmm/api.c
@@ -17,26 +17,29 @@
* along with this program. If not, see .
*/
+#include
#include
#include
#include
#include
#include
-#include
-#include "libsigrok.h"
+#include
#include "libsigrok-internal.h"
#include "agilent-dmm.h"
-static const int32_t hwopts[] = {
+static const uint32_t scanopts[] = {
SR_CONF_CONN,
SR_CONF_SERIALCOMM,
};
-static const int32_t hwcaps[] = {
+static const uint32_t drvopts[] = {
SR_CONF_MULTIMETER,
- SR_CONF_LIMIT_SAMPLES,
- SR_CONF_LIMIT_MSEC,
+};
+
+static const uint32_t devopts[] = {
SR_CONF_CONTINUOUS,
+ SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
+ SR_CONF_LIMIT_MSEC | SR_CONF_SET,
};
extern const struct agdmm_job agdmm_jobs_u12xx[];
@@ -67,30 +70,17 @@ static const struct agdmm_profile supported_agdmm[] = {
ALL_ZERO
};
-SR_PRIV struct sr_dev_driver agdmm_driver_info;
-static struct sr_dev_driver *di = &agdmm_driver_info;
-
-static int init(struct sr_context *sr_ctx)
-{
- return std_init(sr_ctx, di, LOG_PREFIX);
-}
-
-static GSList *scan(GSList *options)
+static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_config *src;
- struct sr_channel *ch;
struct sr_serial_dev_inst *serial;
GSList *l, *devices;
int len, i;
const char *conn, *serialcomm;
char *buf, **tokens;
- drvc = di->priv;
- drvc->instances = NULL;
-
devices = NULL;
conn = serialcomm = NULL;
for (l = options; l; l = l->next) {
@@ -109,24 +99,19 @@ static GSList *scan(GSList *options)
if (!serialcomm)
serialcomm = SERIALCOMM;
- if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
- return NULL;
+ serial = sr_serial_dev_inst_new(conn, serialcomm);
- if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
+ if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;
serial_flush(serial);
- if (serial_write(serial, "*IDN?\r\n", 7) == -1) {
- sr_err("Unable to send identification string: %s.",
- strerror(errno));
+ if (serial_write_blocking(serial, "*IDN?\r\n", 7, SERIAL_WRITE_TIMEOUT_MS) < 7) {
+ sr_err("Unable to send identification string.");
return NULL;
}
len = 128;
- if (!(buf = g_try_malloc(len))) {
- sr_err("Serial buffer malloc failed.");
- return NULL;
- }
+ buf = g_malloc(len);
serial_readline(serial, &buf, &len, 250);
if (!len)
return NULL;
@@ -137,23 +122,18 @@ static GSList *scan(GSList *options)
for (i = 0; supported_agdmm[i].model; i++) {
if (strcmp(supported_agdmm[i].modelname, tokens[1]))
continue;
- if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, "Agilent",
- tokens[1], tokens[3])))
- return NULL;
- if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
- sr_err("Device context malloc failed.");
- return NULL;
- }
+ sdi = g_malloc0(sizeof(struct sr_dev_inst));
+ sdi->status = SR_ST_INACTIVE;
+ sdi->vendor = g_strdup("Agilent");
+ sdi->model = g_strdup(tokens[1]);
+ sdi->version = g_strdup(tokens[3]);
+ devc = g_malloc0(sizeof(struct dev_context));
devc->profile = &supported_agdmm[i];
devc->cur_mq = -1;
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1")))
- return NULL;
- sdi->channels = g_slist_append(sdi->channels, ch);
- drvc->instances = g_slist_append(drvc->instances, sdi);
+ sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
devices = g_slist_append(devices, sdi);
break;
}
@@ -165,20 +145,10 @@ static GSList *scan(GSList *options)
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
-static GSList *dev_list(void)
-{
- return ((struct drv_context *)(di->priv))->instances;
-}
-
-static int cleanup(void)
-{
- return std_dev_clear(di, NULL);
-}
-
-static int config_set(int id, 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 dev_context *devc;
@@ -188,26 +158,15 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
- if (!(devc = sdi->priv)) {
- sr_err("sdi->priv was NULL.");
- return SR_ERR_BUG;
- }
+ devc = sdi->priv;
- switch (id) {
+ switch (key) {
case SR_CONF_LIMIT_MSEC:
/* TODO: not yet implemented */
- if (g_variant_get_uint64(data) == 0) {
- sr_err("LIMIT_MSEC can't be 0.");
- return SR_ERR;
- }
devc->limit_msec = g_variant_get_uint64(data);
- sr_dbg("Setting time limit to %" PRIu64 "ms.",
- devc->limit_msec);
break;
case SR_CONF_LIMIT_SAMPLES:
devc->limit_samples = g_variant_get_uint64(data);
- sr_dbg("Setting sample limit to %" PRIu64 ".",
- devc->limit_samples);
break;
default:
return SR_ERR_NA;
@@ -216,20 +175,23 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
return SR_OK;
}
-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)
{
- (void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
- hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t));
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+ scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
- hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
+ if (!sdi)
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+ drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
+ else
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+ devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
@@ -238,23 +200,14 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
return SR_OK;
}
-static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
+static int dev_acquisition_start(const struct sr_dev_inst *sdi)
{
- struct dev_context *devc;
struct sr_serial_dev_inst *serial;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
- if (!(devc = sdi->priv)) {
- sr_err("sdi->priv was NULL.");
- return SR_ERR_BUG;
- }
-
- devc->cb_data = cb_data;
-
- /* Send header packet to the session bus. */
- std_session_send_df_header(cb_data, LOG_PREFIX);
+ std_session_send_df_header(sdi, LOG_PREFIX);
/* Poll every 100ms, or whenever some data comes in. */
serial = sdi->conn;
@@ -264,20 +217,20 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
return SR_OK;
}
-static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
+static int dev_acquisition_stop(struct sr_dev_inst *sdi)
{
- return std_serial_dev_acquisition_stop(sdi, cb_data, std_serial_dev_close,
+ return std_serial_dev_acquisition_stop(sdi, std_serial_dev_close,
sdi->conn, LOG_PREFIX);
}
-SR_PRIV struct sr_dev_driver agdmm_driver_info = {
+static struct sr_dev_driver agdmm_driver_info = {
.name = "agilent-dmm",
.longname = "Agilent U12xx series DMMs",
.api_version = 1,
- .init = init,
- .cleanup = cleanup,
+ .init = std_init,
+ .cleanup = std_cleanup,
.scan = scan,
- .dev_list = dev_list,
+ .dev_list = std_dev_list,
.dev_clear = NULL,
.config_get = NULL,
.config_set = config_set,
@@ -286,5 +239,6 @@ SR_PRIV struct sr_dev_driver agdmm_driver_info = {
.dev_close = std_serial_dev_close,
.dev_acquisition_start = dev_acquisition_start,
.dev_acquisition_stop = dev_acquisition_stop,
- .priv = NULL,
+ .context = NULL,
};
+SR_REGISTER_DEV_DRIVER(agdmm_driver_info);