X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fagilent-dmm%2Fapi.c;h=82e4378326bc426cdeff102acd6f0f00d69b0db7;hb=1f706c21a2977c768692f72d09b35633628d2b0d;hp=084f9b4d89171699c3f87cbd8d3785fb43e8a796;hpb=95779b43b882bff8ce36828f812482d69c0cfa0a;p=libsigrok.git
diff --git a/src/hardware/agilent-dmm/api.c b/src/hardware/agilent-dmm/api.c
index 084f9b4d..82e43783 100644
--- a/src/hardware/agilent-dmm/api.c
+++ b/src/hardware/agilent-dmm/api.c
@@ -17,13 +17,13 @@
* 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"
@@ -32,9 +32,12 @@ static const uint32_t scanopts[] = {
SR_CONF_SERIALCOMM,
};
-static const uint32_t devopts[] = {
+static const uint32_t drvopts[] = {
SR_CONF_MULTIMETER,
- SR_CONF_CONTINUOUS,
+};
+
+static const uint32_t devopts[] = {
+ SR_CONF_CONTINUOUS | SR_CONF_SET,
SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
SR_CONF_LIMIT_MSEC | SR_CONF_SET,
};
@@ -68,27 +71,25 @@ static const struct agdmm_profile supported_agdmm[] = {
};
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)
+static int init(struct sr_dev_driver *di, 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 = di->context;
drvc->instances = NULL;
devices = NULL;
@@ -109,8 +110,7 @@ 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) != SR_OK)
return NULL;
@@ -122,10 +122,7 @@ static GSList *scan(GSList *options)
}
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;
@@ -136,22 +133,19 @@ 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(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);
+ sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
break;
@@ -167,12 +161,12 @@ static GSList *scan(GSList *options)
return devices;
}
-static GSList *dev_list(void)
+static GSList *dev_list(const struct sr_dev_driver *di)
{
- return ((struct drv_context *)(di->priv))->instances;
+ return ((struct drv_context *)(di->context))->instances;
}
-static int cleanup(void)
+static int cleanup(const struct sr_dev_driver *di)
{
return std_dev_clear(di, NULL);
}
@@ -195,18 +189,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
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;
@@ -227,8 +213,12 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- devopts, ARRAY_SIZE(devopts), sizeof(uint32_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;
@@ -285,5 +275,5 @@ 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,
};