]> sigrok.org Git - libsigrok.git/commitdiff
sr: add genericdmm driver
authorBert Vermeulen <redacted>
Sun, 1 Jul 2012 20:37:15 +0000 (22:37 +0200)
committerBert Vermeulen <redacted>
Sun, 1 Jul 2012 20:37:15 +0000 (22:37 +0200)
configure.ac
hardware/Makefile.am
hardware/genericdmm/Makefile.am [new file with mode: 0644]
hardware/genericdmm/api.c [new file with mode: 0644]
hardware/genericdmm/fs9922.c [new file with mode: 0644]
hardware/genericdmm/genericdmm.h [new file with mode: 0644]
hwdriver.c
sigrok.h.in

index 8a17f901c2decc170da9fb4f4b51fbdbfc614842..d34a701982df5bd402e663ac935b891b6a8f8148 100644 (file)
@@ -113,6 +113,16 @@ if test "x$LA_FX2LAFW" = "xyes"; then
        AC_DEFINE(HAVE_LA_FX2LAFW, 1, [fx2lafw support])
 fi
 
+# Disabled by default for now
+AC_ARG_ENABLE(genericdmm, AC_HELP_STRING([--enable-genericdmm],
+             [enable genericdmm support (for most DMMs). [default=no]]),
+             [HW_GENERICDMM="$enableval"],
+             [HW_GENERICDMM=no])
+AM_CONDITIONAL(HW_GENERICDMM, test x$HW_GENERICDMM = xyes)
+if test "x$HW_GENERICDMM" = "xyes"; then
+       AC_DEFINE(HAVE_HW_GENERICDMM, 1, [Generic DMM support])
+fi
+
 AC_ARG_ENABLE(demo, AC_HELP_STRING([--enable-demo],
              [enable demo driver support [default=yes]]),
              [LA_DEMO="$enableval"],
@@ -281,6 +291,7 @@ AC_CONFIG_FILES([Makefile
                 hardware/common/Makefile
                 hardware/demo/Makefile
                 hardware/fx2lafw/Makefile
+                hardware/genericdmm/Makefile
                 hardware/link-mso19/Makefile
                 hardware/openbench-logic-sniffer/Makefile
                 hardware/zeroplus-logic-cube/Makefile
@@ -323,6 +334,7 @@ echo "  - ASIX SIGMA/SIGMA2............... $LA_ASIX_SIGMA"
 echo "  - ChronoVu LA8.................... $LA_CHRONOVU_LA8"
 echo "  - Demo driver..................... $LA_DEMO"
 echo "  - fx2lafw (for FX2 LAs)........... $LA_FX2LAFW"
+echo "  - Generic DMM..................... $HW_GENERICDMM"
 echo "  - Link MSO-19..................... $LA_LINK_MSO19"
 echo "  - Openbench Logic Sniffer......... $LA_OLS"
 echo "  - ZEROPLUS Logic Cube............. $LA_ZEROPLUS_LOGIC_CUBE"
index 69e98281f01a8a2003080688914e4326f42011c6..0e207d6b0ed5969456430d7c7437c85c21b1511a 100644 (file)
@@ -24,6 +24,7 @@ SUBDIRS = \
        common \
        demo \
        fx2lafw \
+       genericdmm \
        link-mso19 \
        openbench-logic-sniffer \
        zeroplus-logic-cube \
@@ -49,12 +50,16 @@ if LA_CHRONOVU_LA8
 libsigrokhardware_la_LIBADD += chronovu-la8/libsigrokhwchronovula8.la
 endif
 
+if LA_DEMO
+libsigrokhardware_la_LIBADD += demo/libsigrokhwdemo.la
+endif
+
 if LA_FX2LAFW
 libsigrokhardware_la_LIBADD += fx2lafw/libsigrokhwfx2lafw.la
 endif
 
-if LA_DEMO
-libsigrokhardware_la_LIBADD += demo/libsigrokhwdemo.la
+if HW_GENERICDMM
+libsigrokhardware_la_LIBADD += genericdmm/libsigrokhwgenericdmm.la
 endif
 
 if LA_LINK_MSO19
diff --git a/hardware/genericdmm/Makefile.am b/hardware/genericdmm/Makefile.am
new file mode 100644 (file)
index 0000000..2a31a30
--- /dev/null
@@ -0,0 +1,33 @@
+##
+## This file is part of the sigrok project.
+##
+## Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
+##
+## 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/>.
+##
+
+if HW_GENERICDMM
+
+# Local lib, this is NOT meant to be installed!
+noinst_LTLIBRARIES = libsigrokhwgenericdmm.la
+
+libsigrokhwgenericdmm_la_SOURCES = \
+       api.c \
+       fs9922.c \
+       genericdmm.h
+
+libsigrokhwgenericdmm_la_CFLAGS = \
+       -I$(top_srcdir)
+
+endif
diff --git a/hardware/genericdmm/api.c b/hardware/genericdmm/api.c
new file mode 100644 (file)
index 0000000..be05fb2
--- /dev/null
@@ -0,0 +1,624 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de>
+ * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include "sigrok.h"
+#include "sigrok-internal.h"
+#include "genericdmm.h"
+
+
+extern SR_PRIV struct dmmchip dmmchip_fs9922;
+
+static struct dev_profile dev_profiles[] = {
+       { "victor-70c", "Victor", "70C", &dmmchip_fs9922,
+               0x1244, 0xd237, DMM_TRANSPORT_USBHID },
+       { "mastech-va18b", "Mastech", "VA18B", NULL, 0, 0, DMM_TRANSPORT_SERIAL},
+};
+
+static const int hwcaps[] = {
+       SR_HWCAP_MULTIMETER,
+       SR_HWCAP_LIMIT_SAMPLES,
+       SR_HWCAP_LIMIT_MSEC,
+       SR_HWCAP_CONTINUOUS,
+       SR_HWCAP_MODEL,
+       SR_HWCAP_CONN,
+       SR_HWCAP_SERIALCOMM,
+       0,
+};
+
+static const char *probe_names[] = {
+       "Probe",
+       NULL,
+};
+
+/* TODO need a way to keep these local to the static library */
+SR_PRIV GSList *genericdmm_dev_insts = NULL;
+SR_PRIV libusb_context *genericdmm_usb_context = NULL;
+
+
+static int hw_init(const char *devinfo)
+{
+       struct sr_dev_inst *sdi;
+       struct context *ctx;
+       int devcnt = 0;
+
+       /* Avoid compiler warnings. */
+       (void)devinfo;
+
+       if (libusb_init(&genericdmm_usb_context) != 0) {
+               sr_err("genericdmm: Failed to initialize USB.");
+               return 0;
+       }
+
+       if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
+               sr_err("genericdmm: ctx malloc failed.");
+               return 0;
+       }
+
+       devcnt = g_slist_length(genericdmm_dev_insts);
+       if (!(sdi = sr_dev_inst_new(devcnt, SR_ST_ACTIVE, "Generic DMM",
+                       NULL, NULL))) {
+               sr_err("genericdmm: sr_dev_inst_new returned NULL.");
+               return 0;
+       }
+       sdi->priv = ctx;
+       genericdmm_dev_insts = g_slist_append(genericdmm_dev_insts, sdi);
+
+       /* Always initialized just one device instance. */
+       return 0;
+}
+
+static int hw_dev_open(int dev_index)
+{
+       struct sr_dev_inst *sdi;
+       struct context *ctx;
+
+       if (!(sdi = sr_dev_inst_get(genericdmm_dev_insts, dev_index))) {
+               sr_err("genericdmm: sdi was NULL.");
+               return SR_ERR_BUG;
+       }
+
+       if (!(ctx = sdi->priv)) {
+               sr_err("genericdmm: sdi->priv was NULL.");
+               return SR_ERR_BUG;
+       }
+
+       sr_dbg("genericdmm: Opening serial port '%s'.", ctx->serial->port);
+
+       switch (ctx->profile->transport) {
+       case DMM_TRANSPORT_USBHID:
+               /* TODO */
+               break;
+       case DMM_TRANSPORT_SERIAL:
+               /* TODO: O_NONBLOCK? */
+               ctx->serial->fd = serial_open(ctx->serial->port, O_RDWR | O_NONBLOCK);
+               if (ctx->serial->fd == -1) {
+                       sr_err("genericdmm: Couldn't open serial port '%s'.",
+                              ctx->serial->port);
+                       return SR_ERR;
+               }
+               //      serial_set_params(ctx->serial->fd, 2400, 8, 0, 1, 2);
+               break;
+       default:
+               sr_err("No transport set.");
+       }
+
+       return SR_OK;
+}
+
+static int hw_dev_close(int dev_index)
+{
+       struct sr_dev_inst *sdi;
+       struct context *ctx;
+
+       if (!(sdi = sr_dev_inst_get(genericdmm_dev_insts, dev_index))) {
+               sr_err("genericdmm: %s: sdi was NULL.", __func__);
+               return SR_ERR_BUG;
+       }
+
+       if (!(ctx = sdi->priv)) {
+               sr_err("genericdmm: %s: sdi->priv was NULL.", __func__);
+               return SR_ERR_BUG;
+       }
+
+       /* TODO: Check for != NULL. */
+
+       switch (ctx->profile->transport) {
+       case DMM_TRANSPORT_USBHID:
+               /* TODO */
+               break;
+       case DMM_TRANSPORT_SERIAL:
+               if (ctx->serial && ctx->serial->fd != -1) {
+                       serial_close(ctx->serial->fd);
+                       ctx->serial->fd = -1;
+                       sdi->status = SR_ST_INACTIVE;
+               }
+               break;
+       }
+
+       return SR_OK;
+}
+
+static int hw_cleanup(void)
+{
+       GSList *l;
+       struct sr_dev_inst *sdi;
+       struct context *ctx;
+
+       /* Properly close and free all devices. */
+       for (l = genericdmm_dev_insts; l; l = l->next) {
+               if (!(sdi = l->data)) {
+                       /* Log error, but continue cleaning up the rest. */
+                       sr_err("genericdmm: sdi was NULL, continuing.");
+                       continue;
+               }
+               if (!(ctx = sdi->priv)) {
+                       /* Log error, but continue cleaning up the rest. */
+                       sr_err("genericdmm: sdi->priv was NULL, continuing.");
+                       continue;
+               }
+
+               if (ctx->profile) {
+                       switch (ctx->profile->transport) {
+                       case DMM_TRANSPORT_USBHID:
+                               /* TODO */
+                               break;
+                       case DMM_TRANSPORT_SERIAL:
+                               if (ctx->serial && ctx->serial->fd != -1)
+                                       serial_close(ctx->serial->fd);
+                               sr_serial_dev_inst_free(ctx->serial);
+                               break;
+                       }
+               }
+
+               sr_dev_inst_free(sdi);
+       }
+
+       g_slist_free(genericdmm_dev_insts);
+       genericdmm_dev_insts = NULL;
+
+       if (genericdmm_usb_context)
+               libusb_exit(genericdmm_usb_context);
+
+       return SR_OK;
+}
+
+static const void *hw_dev_info_get(int dev_index, int dev_info_id)
+{
+       struct sr_dev_inst *sdi;
+       struct context *ctx;
+       const void *info;
+
+       if (!(sdi = sr_dev_inst_get(genericdmm_dev_insts, dev_index))) {
+               sr_err("genericdmm: sdi was NULL.");
+               return NULL;
+       }
+
+       if (!(ctx = sdi->priv)) {
+               sr_err("genericdmm: sdi->priv was NULL.");
+               return NULL;
+       }
+
+               sr_spew("genericdmm: dev_index %d, dev_info_id %d.",
+                               dev_index, dev_info_id);
+
+       switch (dev_info_id) {
+       case SR_DI_INST:
+               info = sdi;
+               sr_spew("genericdmm: Returning sdi.");
+               break;
+       case SR_DI_NUM_PROBES:
+               info = GINT_TO_POINTER(1);
+               sr_spew("genericdmm: Returning number of probes: 1.");
+               break;
+       case SR_DI_PROBE_NAMES:
+               info = probe_names;
+               sr_spew("genericdmm: Returning probenames.");
+               break;
+       case SR_DI_CUR_SAMPLERATE:
+               /* TODO get rid of this */
+               info = NULL;
+               sr_spew("genericdmm: Returning samplerate: 0.");
+               break;
+       default:
+               /* Unknown device info ID. */
+               sr_err("genericdmm: Unknown device info ID: %d.", dev_info_id);
+               info = NULL;
+               break;
+       }
+
+       return info;
+}
+
+static int hw_dev_status_get(int dev_index)
+{
+       struct sr_dev_inst *sdi;
+
+       if (!(sdi = sr_dev_inst_get(genericdmm_dev_insts, dev_index))) {
+               sr_err("genericdmm: sdi was NULL, device not found.");
+               return SR_ST_NOT_FOUND;
+       }
+
+       sr_dbg("genericdmm: Returning status: %d.", sdi->status);
+
+       return sdi->status;
+}
+
+static const int *hw_hwcap_get_all(void)
+{
+       sr_spew("genericdmm: Returning list of device capabilities.");
+
+       return hwcaps;
+}
+
+static int parse_conn_vidpid(struct sr_dev_inst *sdi, const char *conn)
+{
+       struct context *ctx;
+       libusb_device **devlist;
+       struct libusb_device_descriptor des;
+       GRegex *reg;
+       GMatchInfo *match;
+       int vid, pid, found, err, i;
+       char *vidstr, *pidstr;
+
+       found = FALSE;
+
+       reg = g_regex_new(DMM_CONN_USB_VIDPID, 0, 0, NULL);
+       if (g_regex_match(reg, conn, 0, &match)) {
+               /* Extract VID. */
+               if (!(vidstr = g_match_info_fetch(match, 0))) {
+                       sr_err("failed to fetch VID from regex");
+                       goto err;
+               }
+               vid = strtoul(vidstr, NULL, 16);
+               g_free(vidstr);
+               if (vid > 0xffff) {
+                       sr_err("invalid VID");
+                       goto err;
+               }
+
+               /* Extract PID. */
+               if (!(pidstr = g_match_info_fetch(match, 0))) {
+                       sr_err("failed to fetch PID from regex");
+                       goto err;
+               }
+               pid = strtoul(pidstr, NULL, 16);
+               g_free(pidstr);
+               if (pid > 0xffff) {
+                       sr_err("invalid PID");
+                       goto err;
+               }
+
+               /* Looks like a valid VID:PID, but is it connected? */
+               libusb_get_device_list(genericdmm_usb_context, &devlist);
+               for (i = 0; devlist[i]; i++) {
+                       if ((err = libusb_get_device_descriptor(devlist[i], &des))) {
+                               sr_err("genericdmm: failed to get device descriptor: %d", err);
+                               goto err;
+                       }
+
+                       if (des.idVendor == vid && des.idProduct == pid) {
+                               ctx = sdi->priv;
+                               ctx->usb = sr_usb_dev_inst_new(
+                                               libusb_get_bus_number(devlist[i]),
+                                               libusb_get_device_address(devlist[i]), NULL);
+                               found = TRUE;
+                               break;
+                       }
+               }
+               libusb_free_device_list(devlist, 1);
+       }
+
+err:
+       if (match)
+               g_match_info_unref(match);
+       g_regex_unref(reg);
+
+       return found;
+}
+
+static int parse_conn_busaddr(struct sr_dev_inst *sdi, const char *conn)
+{
+       struct context *ctx;
+       libusb_device **devlist;
+       struct libusb_device_descriptor des;
+       GRegex *reg;
+       GMatchInfo *match;
+       int bus, addr, found, err, i;
+       char *busstr, *addrstr;
+
+       found = FALSE;
+
+       reg = g_regex_new(DMM_CONN_USB_BUSADDR, 0, 0, NULL);
+       if (g_regex_match(reg, conn, 0, &match)) {
+               /* Extract bus. */
+               if (!(busstr = g_match_info_fetch(match, 0))) {
+                       sr_err("failed to fetch bus from regex");
+                       goto err;
+               }
+               bus = strtoul(busstr, NULL, 16);
+               g_free(busstr);
+               if (bus > 64) {
+                       sr_err("invalid bus");
+                       goto err;
+               }
+
+               /* Extract address. */
+               if (!(addrstr = g_match_info_fetch(match, 0))) {
+                       sr_err("failed to fetch address from regex");
+                       goto err;
+               }
+               addr = strtoul(addrstr, NULL, 16);
+               g_free(addrstr);
+               if (addr > 127) {
+                       sr_err("invalid address");
+                       goto err;
+               }
+
+               /* Looks like a valid bus/address, but is it connected? */
+               libusb_get_device_list(genericdmm_usb_context, &devlist);
+               for (i = 0; devlist[i]; i++) {
+                       if ((err = libusb_get_device_descriptor(devlist[i], &des))) {
+                               sr_err("genericdmm: failed to get device descriptor: %d", err);
+                               goto err;
+                       }
+
+                       if (libusb_get_bus_number(devlist[i]) == bus
+                                       && libusb_get_device_address(devlist[i]) == addr) {
+                               ctx = sdi->priv;
+                               ctx->usb = sr_usb_dev_inst_new(bus, addr, NULL);
+                               found = TRUE;
+                               break;
+                       }
+               }
+               libusb_free_device_list(devlist, 1);
+       }
+
+err:
+       if (match)
+               g_match_info_unref(match);
+       g_regex_unref(reg);
+
+       return found;
+}
+
+static int parse_conn_serial(struct sr_dev_inst *sdi, const char *conn)
+{
+       int found;
+
+       found = FALSE;
+
+       /* TODO */
+
+       return found;
+}
+
+static int parse_conn(struct sr_dev_inst *sdi, const char *conn)
+{
+
+       if (parse_conn_vidpid(sdi, conn))
+               return SR_OK;
+
+       if (parse_conn_busaddr(sdi, conn))
+               return SR_OK;
+
+       if (parse_conn_serial(sdi, conn))
+               return SR_OK;
+
+       sr_err("Invalid connection specification");
+
+       return SR_ERR;
+}
+
+static int parse_serialcomm(struct sr_dev_inst *sdi, const char *conn)
+{
+
+       /* TODO */
+       /* set ctx->serial_* */
+
+       return SR_OK;
+}
+
+static int hw_dev_config_set(int dev_index, int hwcap, const void *value)
+{
+       struct sr_dev_inst *sdi;
+       struct context *ctx;
+       int i;
+
+       if (!(sdi = sr_dev_inst_get(genericdmm_dev_insts, dev_index))) {
+               sr_err("genericdmm: sdi was NULL.");
+               return SR_ERR_BUG;
+       }
+
+       if (!(ctx = sdi->priv)) {
+               sr_err("genericdmm: sdi->priv was NULL.");
+               return SR_ERR_BUG;
+       }
+
+       sr_spew("genericdmm: dev_index %d, hwcap %d.", dev_index, hwcap);
+
+       switch (hwcap) {
+       case SR_HWCAP_LIMIT_MSEC:
+               if (*(const uint64_t *)value == 0) {
+                       sr_err("genericdmm: LIMIT_MSEC can't be 0.");
+                       return SR_ERR;
+               }
+               ctx->limit_msec = *(const uint64_t *)value;
+               sr_dbg("genericdmm: Setting LIMIT_MSEC to %" PRIu64 ".",
+                      ctx->limit_msec);
+               break;
+       case SR_HWCAP_LIMIT_SAMPLES:
+               ctx->limit_samples = *(const uint64_t *)value;
+               sr_dbg("genericdmm: Setting LIMIT_SAMPLES to %" PRIu64 ".",
+                      ctx->limit_samples);
+               break;
+       case SR_HWCAP_MODEL:
+               for (i = 0; dev_profiles[i].model; i++) {
+                       if (!strcasecmp(dev_profiles[i].model, value)) {
+                               ctx->profile = &dev_profiles[i];
+                               /* Frontends access these fields directly, so we
+                                * need to copy them over. */
+                               sdi->vendor = g_strdup(dev_profiles[i].vendor);
+                               sdi->model = g_strdup(dev_profiles[i].model);
+                               /* This is the first time we actually know which
+                                * DMM chip we're talking to, so let's init
+                                * anything specific to it now */
+                               if (ctx->profile->chip->init)
+                                       if (ctx->profile->chip->init(ctx) != SR_OK)
+                                               return SR_ERR;
+                               break;
+                       }
+               }
+               if (!ctx->profile) {
+                       sr_err("unknown model %s", value);
+                       return SR_ERR;
+               }
+               break;
+       case SR_HWCAP_CONN:
+               if (parse_conn(sdi, value) != SR_OK)
+                       return SR_ERR_ARG;
+               break;
+       case SR_HWCAP_SERIALCOMM:
+               if (parse_serialcomm(sdi, value) != SR_OK)
+                       return SR_ERR_ARG;
+               break;
+       default:
+               sr_err("genericdmm: Unknown capability: %d.", hwcap);
+               return SR_ERR;
+               break;
+       }
+
+       return SR_OK;
+}
+
+static int receive_data(int fd, int revents, void *cb_data)
+{
+       struct sr_dev_inst *sdi;
+       struct context *ctx;
+
+       if (!(sdi = cb_data))
+               return FALSE;
+
+       if (!(ctx = sdi->priv))
+               return FALSE;
+
+       if (revents != G_IO_IN) {
+               sr_err("genericdmm: No data?");
+               return FALSE;
+       }
+
+       switch (ctx->profile->transport) {
+       case DMM_TRANSPORT_USBHID:
+               /* TODO */
+               break;
+       case DMM_TRANSPORT_SERIAL:
+               /* TODO */
+               break;
+       }
+
+       return TRUE;
+}
+
+static int hw_dev_acquisition_start(int dev_index, void *cb_data)
+{
+       struct sr_datafeed_packet packet;
+       struct sr_datafeed_header header;
+       struct sr_datafeed_meta_analog meta;
+       struct sr_dev_inst *sdi;
+       struct context *ctx;
+
+       if (!(sdi = sr_dev_inst_get(genericdmm_dev_insts, dev_index))) {
+               sr_err("genericdmm: sdi was NULL.");
+               return SR_ERR_BUG;
+       }
+
+       if (!(ctx = sdi->priv)) {
+               sr_err("genericdmm: sdi->priv was NULL.");
+               return SR_ERR_BUG;
+       }
+
+       sr_dbg("genericdmm: Starting acquisition.");
+
+       ctx->cb_data = cb_data;
+
+       /* Send header packet to the session bus. */
+       sr_dbg("genericdmm: Sending SR_DF_HEADER.");
+       packet.type = SR_DF_HEADER;
+       packet.payload = (uint8_t *)&header;
+       header.feed_version = 1;
+       gettimeofday(&header.starttime, NULL);
+       sr_session_send(ctx->cb_data, &packet);
+
+       /* Send metadata about the SR_DF_ANALOG packets to come. */
+       sr_dbg("genericdmm: Sending SR_DF_META_ANALOG.");
+       packet.type = SR_DF_META_ANALOG;
+       packet.payload = &meta;
+       meta.num_probes = 1;
+       sr_session_send(ctx->cb_data, &packet);
+
+       /* Hook up a proxy handler to receive data from the device. */
+       switch (ctx->profile->transport) {
+       case DMM_TRANSPORT_USBHID:
+               /* TODO libusb FD setup */
+               break;
+       case DMM_TRANSPORT_SERIAL:
+               /* TODO serial FD setup */
+               // sr_source_add(ctx->serial->fd, G_IO_IN, -1, receive_data, sdi);
+               break;
+       }
+
+       return SR_OK;
+}
+
+static int hw_dev_acquisition_stop(int dev_index, void *cb_data)
+{
+       struct sr_datafeed_packet packet;
+
+       /* Avoid compiler warnings. */
+       (void)dev_index;
+
+       sr_dbg("genericdmm: Stopping acquisition.");
+
+       /* Send end packet to the session bus. */
+       sr_dbg("genericdmm: Sending SR_DF_END.");
+       packet.type = SR_DF_END;
+       sr_session_send(cb_data, &packet);
+
+       return SR_OK;
+}
+
+SR_PRIV struct sr_dev_driver genericdmm_driver_info = {
+       .name = "genericdmm",
+       .longname = "Generic DMM",
+       .api_version = 1,
+       .init = hw_init,
+       .cleanup = hw_cleanup,
+       .dev_open = hw_dev_open,
+       .dev_close = hw_dev_close,
+       .dev_info_get = hw_dev_info_get,
+       .dev_status_get = hw_dev_status_get,
+       .hwcap_get_all = hw_hwcap_get_all,
+       .dev_config_set = hw_dev_config_set,
+       .dev_acquisition_start = hw_dev_acquisition_start,
+       .dev_acquisition_stop = hw_dev_acquisition_stop,
+};
diff --git a/hardware/genericdmm/fs9922.c b/hardware/genericdmm/fs9922.c
new file mode 100644 (file)
index 0000000..24acbae
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
+ *
+ * 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 "sigrok.h"
+#include "sigrok-internal.h"
+#include "genericdmm.h"
+
+
+static int fs9922_init(struct context *ctx)
+{
+
+
+       return SR_OK;
+}
+
+static int fs9922_data(struct context *ctx, unsigned char *data)
+{
+       struct sr_datafeed_packet packet;
+       struct sr_datafeed_analog analog;
+
+       packet.type = SR_DF_ANALOG;
+       packet.payload = &analog;
+
+       return SR_OK;
+}
+
+
+SR_PRIV struct dmmchip dmmchip_fs9922 = {
+       .init = fs9922_init,
+       .data = fs9922_data,
+};
+
diff --git a/hardware/genericdmm/genericdmm.h b/hardware/genericdmm/genericdmm.h
new file mode 100644 (file)
index 0000000..5fa8916
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
+ *
+ * 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/>.
+ */
+
+
+#ifndef GENERICDMM_H_
+#define GENERICDMM_H_
+
+/* SR_HWCAP_CONN takes one of these: */
+#define DMM_CONN_USB_VIDPID    "^([0--9a-z]{1,4}):([0--9a-z]{1,4})$"
+#define DMM_CONN_USB_BUSADDR   "^(\\d+)\\.(\\d+)$"
+#define DMM_CONN_SERIALPORT    "^([a-z0-9/\\-_]+)$"
+
+/* SR_HWCAP_SERIALCOMM like 2400/8n1 */
+#define DMM_CONN_SERIALCOMM    "^(\\d+)/(\\d)([neo])(\\d)$"
+
+enum {
+       DMM_TRANSPORT_SERIAL,
+       DMM_TRANSPORT_USBHID,
+};
+
+
+struct dev_profile {
+       char *modelid;
+       char *vendor;
+       char *model;
+       struct dmmchip *chip;
+       /* Only use when the VID:PID is really specific to a DMM. */
+       uint16_t vid;
+       uint16_t pid;
+       int transport;
+};
+
+struct context {
+       struct dev_profile *profile;
+       uint64_t limit_samples;
+       uint64_t limit_msec;
+
+       /* Opaque pointer passed in by the frontend. */
+       void *cb_data;
+
+       /* Only used for USB-connected devices. */
+       struct sr_usb_dev_inst *usb;
+
+       /* Only used for serial-connected devices. */
+       struct sr_serial_dev_inst *serial;
+       int serial_speed;
+       int serial_databits;
+       int serial_parity;
+       int serial_stopbits;
+
+       /* Runtime. */
+       uint64_t num_samples;
+
+       /* DMM chip-specific data, if needed. */
+       void *priv;
+};
+
+struct dmmchip {
+       /* Optional, called once before measurement starts. */
+       int (*init) (struct context *ctx);
+       /* Called whenever a chunk of data arrives. */
+       int (*data) (struct context *ctx, unsigned char *data);
+};
+
+
+#endif /* GENERICDMM_H_ */
index ccd8420d58ccbd90a99e920010c95d2cd498e0df..185fa8c01d1e005ef35adaca3ac482b4b8f9fa53 100644 (file)
@@ -45,6 +45,9 @@ SR_API struct sr_hwcap_option sr_hwcap_options[] = {
        {SR_HWCAP_FILTER, SR_T_CHAR, "Filter targets", "filter"},
        {SR_HWCAP_VDIV, SR_T_RATIONAL_VOLT, "Volts/div", "vdiv"},
        {SR_HWCAP_COUPLING, SR_T_CHAR, "Coupling", "coupling"},
+       {SR_HWCAP_MODEL, SR_T_KEYVALUE, "Model", "model"},
+       {SR_HWCAP_CONN, SR_T_CHAR, "Connection", "connect"},
+       {SR_HWCAP_SERIALCOMM, SR_T_CHAR, "Serial communication", "serialcomm"},
        {0, 0, NULL, NULL},
 };
 
@@ -78,6 +81,9 @@ extern SR_PRIV struct sr_dev_driver hantek_dso_driver_info;
 #ifdef HAVE_HW_MASTECH_VA18B
 extern SR_PRIV struct sr_dev_driver mastech_va18b_driver_info;
 #endif
+#ifdef HAVE_HW_GENERICDMM
+extern SR_PRIV struct sr_dev_driver genericdmm_driver_info;
+#endif
 
 static struct sr_dev_driver *drivers_list[] = {
 #ifdef HAVE_LA_DEMO
@@ -109,6 +115,9 @@ static struct sr_dev_driver *drivers_list[] = {
 #endif
 #ifdef HAVE_HW_MASTECH_VA18B
        &mastech_va18b_driver_info,
+#endif
+#ifdef HAVE_HW_GENERICDMM
+       &genericdmm_driver_info,
 #endif
        NULL,
 };
@@ -234,7 +243,7 @@ SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus,
 
        udi->bus = bus;
        udi->address = address;
-       udi->devhdl = hdl; /* TODO: Check if this is NULL? */
+       udi->devhdl = hdl;
 
        return udi;
 }
index 4dff80808429a8284a5f0a9b46f59da6c320e4f7..091eb3cfebed35fc37efd1f852e960e0767da354 100644 (file)
@@ -304,12 +304,25 @@ enum {
        /** The device can act as an oscilloscope. */
        SR_HWCAP_OSCILLOSCOPE,
 
-       /*--- Device types --------------------------------------------------*/
+       /** The device can act as a multimeter. */
+       SR_HWCAP_MULTIMETER,
 
-       /** The device is demo device. */
+       /** The device is demo device. */
        SR_HWCAP_DEMO_DEV,
 
-       /*--- Device options ------------------------------------------------*/
+
+       /*--- Device communication ------------------------------------------*/
+       /** Some drivers cannot detect the exact model they're talking to. */
+       SR_HWCAP_MODEL,
+
+       /** Specification on how to connect to a device */
+       SR_HWCAP_CONN,
+
+       /** Serial communication spec: <data bits><parity><stop bit> e.g. 8n1 */
+       SR_HWCAP_SERIALCOMM,
+
+
+       /*--- Device configuration ------------------------------------------*/
 
        /** The device supports setting/changing its samplerate. */
        SR_HWCAP_SAMPLERATE,
@@ -352,6 +365,7 @@ enum {
        /** Coupling. */
        SR_HWCAP_COUPLING,
 
+
        /*--- Special stuff -------------------------------------------------*/
 
        /* TODO: Better description. */
@@ -366,6 +380,7 @@ enum {
        /** The device supports setting the number of probes. */
        SR_HWCAP_CAPTURE_NUM_PROBES,
 
+
        /*--- Acquisition modes ---------------------------------------------*/
 
        /**