]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/fluke-dmm/api.c
Constify a few arrays and variables.
[libsigrok.git] / src / hardware / fluke-dmm / api.c
index 7ece648774f1a20a94c08e7e7e6201f3b710de1a..216c6359c83c721e0eab3805cd2985b0885cca08 100644 (file)
@@ -40,9 +40,8 @@ static const uint32_t devopts[] = {
 };
 
 SR_PRIV struct sr_dev_driver flukedmm_driver_info;
-static struct sr_dev_driver *di = &flukedmm_driver_info;
 
-static char *scan_conn[] = {
+static const char *scan_conn[] = {
        /* 287/289 */
        "115200/8n1",
        /* 187/189 */
@@ -59,24 +58,23 @@ static const struct flukedmm_profile supported_flukedmm[] = {
        { FLUKE_190, "199B", 1000, 3500 },
 };
 
-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 *fluke_scan(const char *conn, const char *serialcomm)
+static GSList *fluke_scan(struct sr_dev_driver *di, const char *conn,
+               const char *serialcomm)
 {
        struct sr_dev_inst *sdi;
        struct drv_context *drvc;
        struct dev_context *devc;
-       struct sr_channel *ch;
        struct sr_serial_dev_inst *serial;
        GSList *devices;
        int retry, len, i, s;
        char buf[128], *b, **tokens;
 
-       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,21 +120,18 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm)
                                        continue;
                                /* Skip leading spaces in version number. */
                                for (s = 0; tokens[1][s] == ' '; s++);
-                               if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Fluke",
-                                               tokens[0] + 6, tokens[1] + s)))
-                                       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("Fluke");
+                               sdi->model = g_strdup(tokens[0] + 6);
+                               sdi->version = g_strdup(tokens[1] + s);
+                               devc = g_malloc0(sizeof(struct dev_context));
                                devc->profile = &supported_flukedmm[i];
                                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;
@@ -154,7 +149,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm)
        return devices;
 }
 
-static GSList *scan(GSList *options)
+static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
        struct sr_config *src;
        GSList *l, *devices;
@@ -179,10 +174,10 @@ static GSList *scan(GSList *options)
        devices = NULL;
        if (serialcomm) {
                /* Use the provided comm specs. */
-               devices = fluke_scan(conn, serialcomm);
+               devices = fluke_scan(di, conn, serialcomm);
        } else {
                for (i = 0; scan_conn[i]; i++) {
-                       if ((devices = fluke_scan(conn, scan_conn[i])))
+                       if ((devices = fluke_scan(di, conn, scan_conn[i])))
                                break;
                        /* The Scopemeter 199B, at least, requires this
                         * after all the 115k/9.6k confusion. */
@@ -193,12 +188,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;
 }
 
-static int cleanup(void)
+static int cleanup(const struct sr_dev_driver *di)
 {
        return std_dev_clear(di, NULL);
 }