]> sigrok.org Git - libsigrok.git/commitdiff
serial-hid: introduce support for Brymen BU-86X IR adapters
authorGerhard Sittig <redacted>
Sun, 9 Jun 2019 06:25:54 +0000 (08:25 +0200)
committerGerhard Sittig <redacted>
Thu, 13 Jun 2019 16:33:23 +0000 (18:33 +0200)
The Brymen BU-86X infrared adapters are sold with BM869s meters. Raw
streams of data bytes get communicated by means of HID reports with
report number 0 and up to 8 data bytes each. Communication parameters
are fixed and need no configuration.

Makefile.am
src/libsigrok-internal.h
src/serial_hid.c
src/serial_hid_bu86x.c [new file with mode: 0644]

index 96542f62cdec5fce88a8e9ed9cc7723b6f6af171..cf0136f9e29ccad5072d3bb71e08a3cead6674ae 100644 (file)
@@ -125,6 +125,7 @@ libsigrok_la_SOURCES += \
        src/serial.c \
        src/serial_bt.c \
        src/serial_hid.c \
+       src/serial_hid_bu86x.c \
        src/serial_hid_ch9325.c \
        src/serial_hid_cp2110.c \
        src/serial_libsp.c \
index 0dfacbce1f09188fde9b0e0dca99893a277b7ff1..a6c113a5609b948014ecbc698ccf746840275b45 100644 (file)
@@ -756,6 +756,7 @@ struct sr_serial_dev_inst {
 #ifdef HAVE_LIBHIDAPI
        enum ser_hid_chip_t {
                SER_HID_CHIP_UNKNOWN,           /**!< place holder */
+               SER_HID_CHIP_BTC_BU86X,         /**!< Brymen BU86x */
                SER_HID_CHIP_SIL_CP2110,        /**!< SiLabs CP2110 */
                SER_HID_CHIP_WCH_CH9325,        /**!< WCH CH9325 */
                SER_HID_CHIP_LAST,              /**!< sentinel */
@@ -1247,6 +1248,7 @@ struct ser_hid_chip_functions {
        int (*flush)(struct sr_serial_dev_inst *serial);
        int (*drain)(struct sr_serial_dev_inst *serial);
 };
+extern SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_bu86x;
 extern SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_ch9325;
 extern SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_cp2110;
 SR_PRIV const char *ser_hid_chip_find_name_vid_pid(uint16_t vid, uint16_t pid);
index b4b82f1694bcf986c3f47d4022d845724bbfb957..1aca73e62254d1ab1d928dab0223c60f3da5c4de 100644 (file)
@@ -550,6 +550,7 @@ SR_PRIV int ser_hid_hidapi_set_data(struct sr_serial_dev_inst *serial,
 
 static struct ser_hid_chip_functions **chips[SER_HID_CHIP_LAST] = {
        [SER_HID_CHIP_UNKNOWN] = NULL,
+       [SER_HID_CHIP_BTC_BU86X] = &ser_hid_chip_funcs_bu86x,
        [SER_HID_CHIP_SIL_CP2110] = &ser_hid_chip_funcs_cp2110,
        [SER_HID_CHIP_WCH_CH9325] = &ser_hid_chip_funcs_ch9325,
 };
diff --git a/src/serial_hid_bu86x.c b/src/serial_hid_bu86x.c
new file mode 100644 (file)
index 0000000..3697e5b
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * This file is part of the libsigrok project.
+ *
+ * Copyright (C) 2019 Gerhard Sittig <gerhard.sittig@gmx.net>
+ *
+ * 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/>.
+ */
+
+/*
+ * This implements serial communication primitives for the Brymen BU-86X
+ * infrared adapter for handheld multimeters. The vendor's protocol spec
+ * http://brymen.com/product-html/images/DownloadList/ProtocolList/BM860-BM860s_List/BM860-BM860s-500000-count-dual-display-DMMs-protocol.pdf
+ * suggests that HID reports get communicated, but only report number 0
+ * is involved, which carries a mere byte stream in 8 byte chunks each.
+ * The frame format and bitrate are fixed, and need not get configured.
+ *
+ * The meter's packet consists of 24 bytes which get received in three
+ * HID reports. Packet reception gets initiated by sending a short HID
+ * report to the meter. It's uncertain which parts of this exchange are
+ * specific to the adapter and to the meter. Using the IR adapter with
+ * other devices, or using the meter with other cables/adapters may need
+ * a little more adjustment with respect to layering.
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <libsigrok/libsigrok.h>
+#include "libsigrok-internal.h"
+#include "serial_hid.h"
+#include <string.h>
+
+/** @cond PRIVATE */
+#define LOG_PREFIX "serial-bu86x"
+/** @endcond */
+
+#ifdef HAVE_SERIAL_COMM
+#ifdef HAVE_LIBHIDAPI
+
+/**
+ * @file
+ *
+ * Support serial-over-HID, specifically the Brymen BU-86X infrared adapter.
+ */
+
+#define BU86X_MAX_BYTES_PER_REQUEST    8
+
+static const struct vid_pid_item vid_pid_items_bu86x[] = {
+       { 0x0820, 0x0001, },
+       VID_PID_TERM,
+};
+
+static int bu86x_set_params(struct sr_serial_dev_inst *serial,
+       int baudrate, int bits, int parity, int stopbits,
+       int flowcontrol, int rts, int dtr)
+{
+       /*
+        * The IR adapter's communication parameters are fixed and need
+        * not get configured. Just silently ignore the caller's spec.
+        */
+       (void)serial;
+       (void)baudrate;
+       (void)bits;
+       (void)parity;
+       (void)stopbits;
+       (void)flowcontrol;
+       (void)rts;
+       (void)dtr;
+
+       return SR_OK;
+}
+
+static int bu86x_read_bytes(struct sr_serial_dev_inst *serial,
+       uint8_t *data, int space, unsigned int timeout)
+{
+       int rc;
+
+       if (space > BU86X_MAX_BYTES_PER_REQUEST)
+               space = BU86X_MAX_BYTES_PER_REQUEST;
+       rc = ser_hid_hidapi_get_data(serial, 0, data, space, timeout);
+       if (rc == SR_ERR_TIMEOUT)
+               return 0;
+       if (rc < 0)
+               return rc;
+       if (rc == 0)
+               return 0;
+       return rc;
+}
+
+static int bu86x_write_bytes(struct sr_serial_dev_inst *serial,
+       const uint8_t *data, int size)
+{
+       return ser_hid_hidapi_set_data(serial, 0, data, size, 0);
+}
+
+static struct ser_hid_chip_functions chip_bu86x = {
+       .chipname = "bu86x",
+       .chipdesc = "Brymen BU-86X",
+       .vid_pid_items = vid_pid_items_bu86x,
+       .max_bytes_per_request = BU86X_MAX_BYTES_PER_REQUEST,
+       .set_params = bu86x_set_params,
+       .read_bytes = bu86x_read_bytes,
+       .write_bytes = bu86x_write_bytes,
+};
+SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_bu86x = &chip_bu86x;
+
+#else
+
+SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_bu86x = NULL;
+
+#endif
+#endif