]> sigrok.org Git - libsigrok.git/commitdiff
scpi/gpib: Rename backend to scpi_libgpib.
authorBert Vermeulen <redacted>
Fri, 5 Sep 2014 16:33:48 +0000 (18:33 +0200)
committerBert Vermeulen <redacted>
Fri, 5 Sep 2014 16:33:48 +0000 (18:33 +0200)
libgpib is the userspace component to linux-gpib's kernel modules that
implement low-level interface drivers.

When libsigrok gets userspace GPIB interface drivers, that backend will
be the "official" scpi_gpib.

Makefile.am
src/scpi/scpi.c
src/scpi/scpi_gpib.c [deleted file]
src/scpi/scpi_libgpib.c [new file with mode: 0644]

index f5ccd0e32e0371b5e3f8f883317ea5633b1e7d32..2628fbccd1a3ce7264ef0c831088206de8aa6e70 100644 (file)
@@ -93,7 +93,7 @@ libsigrok_la_SOURCES += \
 endif
 if NEED_GPIB
 libsigrok_la_SOURCES += \
-       src/scpi/scpi_gpib.c
+       src/scpi/scpi_libgpib.c
 endif
 
 # Hardware (DMM chip parsers)
index 84db9daca358ea793fdb4b438504da0a4932083c..38e322f5ffb7190e9998d81fa69c7e0ef80f441c 100644 (file)
@@ -71,7 +71,7 @@ SR_PRIV extern const struct sr_scpi_dev_inst scpi_tcp_rigol_dev;
 SR_PRIV extern const struct sr_scpi_dev_inst scpi_usbtmc_libusb_dev;
 SR_PRIV extern const struct sr_scpi_dev_inst scpi_vxi_dev;
 SR_PRIV extern const struct sr_scpi_dev_inst scpi_visa_dev;
-SR_PRIV extern const struct sr_scpi_dev_inst scpi_gpib_dev;
+SR_PRIV extern const struct sr_scpi_dev_inst scpi_libgpib_dev;
 
 static const struct sr_scpi_dev_inst *scpi_devs[] = {
        &scpi_tcp_raw_dev,
@@ -86,7 +86,7 @@ static const struct sr_scpi_dev_inst *scpi_devs[] = {
        &scpi_visa_dev,
 #endif
 #ifdef HAVE_LIBGPIB
-       &scpi_gpib_dev,
+       &scpi_libgpib_dev,
 #endif
 #ifdef HAVE_LIBSERIALPORT
        &scpi_serial_dev,  /* must be last as it matches any resource */
diff --git a/src/scpi/scpi_gpib.c b/src/scpi/scpi_gpib.c
deleted file mode 100644 (file)
index 06ae1dd..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * This file is part of the libsigrok project.
- *
- * Copyright (C) 2014 Martin Ling <martin-sigrok@earth.li>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "libsigrok.h"
-#include "libsigrok-internal.h"
-
-#include <gpib/ib.h>
-#include <string.h>
-
-#define LOG_PREFIX "scpi_gpib"
-
-struct scpi_gpib {
-       char *name;
-       int descriptor;
-       int read_started;
-};
-
-static int scpi_gpib_dev_inst_new(void *priv, struct drv_context *drvc,
-               const char *resource, char **params, const char *serialcomm)
-{
-       struct scpi_gpib *gscpi = priv;
-
-       (void)drvc;
-       (void)resource;
-       (void)serialcomm;
-
-       if (!params || !params[1])
-                       return SR_ERR;
-
-       gscpi->name = g_strdup(params[1]);
-
-       return SR_OK;
-}
-
-static int scpi_gpib_open(void *priv)
-{
-       struct scpi_gpib *gscpi = priv;
-
-       if ((gscpi->descriptor = ibfind(gscpi->name)) < 0)
-               return SR_ERR;
-
-       return SR_OK;
-}
-
-static int scpi_gpib_source_add(struct sr_session *session, void *priv,
-               int events, int timeout, sr_receive_data_callback cb, void *cb_data)
-{
-       (void) priv;
-
-       /* Hook up a dummy handler to receive data from the device. */
-       return sr_session_source_add(session, -1, events, timeout, cb, cb_data);
-}
-
-static int scpi_gpib_source_remove(struct sr_session *session, void *priv)
-{
-       (void) priv;
-
-       return sr_session_source_remove(session, -1);
-}
-
-static int scpi_gpib_send(void *priv, const char *command)
-{
-       struct scpi_gpib *gscpi = priv;
-       int len = strlen(command);
-
-       ibwrt(gscpi->descriptor, command, len);
-
-       if (ibsta & ERR)
-       {
-               sr_err("Error while sending SCPI command: '%s': iberr = %d.",
-                               command, iberr);
-               return SR_ERR;
-       }
-
-       if (ibcnt < len)
-       {
-               sr_err("Failed to send all of SCPI command: '%s': "
-                               "len = %d, ibcnt = .", command, len, ibcnt);
-               return SR_ERR;
-       }
-
-       sr_spew("Successfully sent SCPI command: '%s'.", command);
-
-       return SR_OK;
-}
-
-static int scpi_gpib_read_begin(void *priv)
-{
-       struct scpi_gpib *gscpi = priv;
-
-       gscpi->read_started = 0;
-
-       return SR_OK;
-}
-
-static int scpi_gpib_read_data(void *priv, char *buf, int maxlen)
-{
-       struct scpi_gpib *gscpi = priv;
-
-       ibrd(gscpi->descriptor, buf, maxlen);
-
-       if (ibsta & ERR)
-       {
-               sr_err("Error while reading SCPI response: iberr = %d.", iberr);
-               return SR_ERR;
-       }
-
-       gscpi->read_started = 1;
-
-       return ibcnt;
-}
-
-static int scpi_gpib_read_complete(void *priv)
-{
-       struct scpi_gpib *gscpi = priv;
-
-       return gscpi->read_started && (ibsta & END);
-}
-
-static int scpi_gpib_close(void *priv)
-{
-       struct scpi_gpib *gscpi = priv;
-
-       ibonl(gscpi->descriptor, 0);
-
-       return SR_OK;
-}
-
-static void scpi_gpib_free(void *priv)
-{
-       struct scpi_gpib *gscpi = priv;
-
-       g_free(gscpi->name);
-}
-
-SR_PRIV const struct sr_scpi_dev_inst scpi_gpib_dev = {
-       .name = "GPIB",
-       .prefix = "gpib",
-       .priv_size = sizeof(struct scpi_gpib),
-       .dev_inst_new = scpi_gpib_dev_inst_new,
-       .open = scpi_gpib_open,
-       .source_add = scpi_gpib_source_add,
-       .source_remove = scpi_gpib_source_remove,
-       .send = scpi_gpib_send,
-       .read_begin = scpi_gpib_read_begin,
-       .read_data = scpi_gpib_read_data,
-       .read_complete = scpi_gpib_read_complete,
-       .close = scpi_gpib_close,
-       .free = scpi_gpib_free,
-};
diff --git a/src/scpi/scpi_libgpib.c b/src/scpi/scpi_libgpib.c
new file mode 100644 (file)
index 0000000..5df9041
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+ * This file is part of the libsigrok project.
+ *
+ * Copyright (C) 2014 Martin Ling <martin-sigrok@earth.li>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "libsigrok.h"
+#include "libsigrok-internal.h"
+
+#include <gpib/ib.h>
+#include <string.h>
+
+#define LOG_PREFIX "scpi_gpib"
+
+struct scpi_gpib {
+       char *name;
+       int descriptor;
+       int read_started;
+};
+
+static int scpi_gpib_dev_inst_new(void *priv, struct drv_context *drvc,
+               const char *resource, char **params, const char *serialcomm)
+{
+       struct scpi_gpib *gscpi = priv;
+
+       (void)drvc;
+       (void)resource;
+       (void)serialcomm;
+
+       if (!params || !params[1])
+                       return SR_ERR;
+
+       gscpi->name = g_strdup(params[1]);
+
+       return SR_OK;
+}
+
+static int scpi_gpib_open(void *priv)
+{
+       struct scpi_gpib *gscpi = priv;
+
+       if ((gscpi->descriptor = ibfind(gscpi->name)) < 0)
+               return SR_ERR;
+
+       return SR_OK;
+}
+
+static int scpi_gpib_source_add(struct sr_session *session, void *priv,
+               int events, int timeout, sr_receive_data_callback cb, void *cb_data)
+{
+       (void) priv;
+
+       /* Hook up a dummy handler to receive data from the device. */
+       return sr_session_source_add(session, -1, events, timeout, cb, cb_data);
+}
+
+static int scpi_gpib_source_remove(struct sr_session *session, void *priv)
+{
+       (void) priv;
+
+       return sr_session_source_remove(session, -1);
+}
+
+static int scpi_gpib_send(void *priv, const char *command)
+{
+       struct scpi_gpib *gscpi = priv;
+       int len = strlen(command);
+
+       ibwrt(gscpi->descriptor, command, len);
+
+       if (ibsta & ERR)
+       {
+               sr_err("Error while sending SCPI command: '%s': iberr = %d.",
+                               command, iberr);
+               return SR_ERR;
+       }
+
+       if (ibcnt < len)
+       {
+               sr_err("Failed to send all of SCPI command: '%s': "
+                               "len = %d, ibcnt = .", command, len, ibcnt);
+               return SR_ERR;
+       }
+
+       sr_spew("Successfully sent SCPI command: '%s'.", command);
+
+       return SR_OK;
+}
+
+static int scpi_gpib_read_begin(void *priv)
+{
+       struct scpi_gpib *gscpi = priv;
+
+       gscpi->read_started = 0;
+
+       return SR_OK;
+}
+
+static int scpi_gpib_read_data(void *priv, char *buf, int maxlen)
+{
+       struct scpi_gpib *gscpi = priv;
+
+       ibrd(gscpi->descriptor, buf, maxlen);
+
+       if (ibsta & ERR)
+       {
+               sr_err("Error while reading SCPI response: iberr = %d.", iberr);
+               return SR_ERR;
+       }
+
+       gscpi->read_started = 1;
+
+       return ibcnt;
+}
+
+static int scpi_gpib_read_complete(void *priv)
+{
+       struct scpi_gpib *gscpi = priv;
+
+       return gscpi->read_started && (ibsta & END);
+}
+
+static int scpi_gpib_close(void *priv)
+{
+       struct scpi_gpib *gscpi = priv;
+
+       ibonl(gscpi->descriptor, 0);
+
+       return SR_OK;
+}
+
+static void scpi_gpib_free(void *priv)
+{
+       struct scpi_gpib *gscpi = priv;
+
+       g_free(gscpi->name);
+}
+
+SR_PRIV const struct sr_scpi_dev_inst scpi_libgpib_dev = {
+       .name = "GPIB",
+       .prefix = "libgpib",
+       .priv_size = sizeof(struct scpi_gpib),
+       .dev_inst_new = scpi_gpib_dev_inst_new,
+       .open = scpi_gpib_open,
+       .source_add = scpi_gpib_source_add,
+       .source_remove = scpi_gpib_source_remove,
+       .send = scpi_gpib_send,
+       .read_begin = scpi_gpib_read_begin,
+       .read_data = scpi_gpib_read_data,
+       .read_complete = scpi_gpib_read_complete,
+       .close = scpi_gpib_close,
+       .free = scpi_gpib_free,
+};