]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2019 Gerhard Sittig <gerhard.sittig@gmx.net> | |
5 | * | |
6 | * This program is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | /* | |
21 | * This implements serial communication primitives for the Brymen BU-86X | |
22 | * infrared adapter for handheld multimeters. The vendor's protocol spec | |
23 | * http://brymen.com/product-html/images/DownloadList/ProtocolList/BM860-BM860s_List/BM860-BM860s-500000-count-dual-display-DMMs-protocol.pdf | |
24 | * suggests that HID reports get communicated, but only report number 0 | |
25 | * is involved, which carries a mere byte stream in 8 byte chunks each. | |
26 | * The frame format and bitrate are fixed, and need not get configured. | |
27 | * | |
28 | * The meter's packet consists of 24 bytes which get received in three | |
29 | * HID reports. Packet reception gets initiated by sending a short HID | |
30 | * report to the meter. It's uncertain which parts of this exchange are | |
31 | * specific to the adapter and to the meter. Using the IR adapter with | |
32 | * other devices, or using the meter with other cables/adapters may need | |
33 | * a little more adjustment with respect to layering. | |
34 | */ | |
35 | ||
36 | #include <config.h> | |
37 | #include <glib.h> | |
38 | #include <libsigrok/libsigrok.h> | |
39 | #include "libsigrok-internal.h" | |
40 | #include "serial_hid.h" | |
41 | #include <string.h> | |
42 | ||
43 | /** @cond PRIVATE */ | |
44 | #define LOG_PREFIX "serial-bu86x" | |
45 | /** @endcond */ | |
46 | ||
47 | #ifdef HAVE_SERIAL_COMM | |
48 | #ifdef HAVE_LIBHIDAPI | |
49 | ||
50 | /** | |
51 | * @file | |
52 | * | |
53 | * Support serial-over-HID, specifically the Brymen BU-86X infrared adapter. | |
54 | */ | |
55 | ||
56 | #define BU86X_MAX_BYTES_PER_REQUEST 8 | |
57 | ||
58 | static const struct vid_pid_item vid_pid_items_bu86x[] = { | |
59 | { 0x0820, 0x0001, }, | |
60 | ALL_ZERO | |
61 | }; | |
62 | ||
63 | static int bu86x_read_bytes(struct sr_serial_dev_inst *serial, | |
64 | uint8_t *data, int space, unsigned int timeout) | |
65 | { | |
66 | int rc; | |
67 | ||
68 | if (space > BU86X_MAX_BYTES_PER_REQUEST) | |
69 | space = BU86X_MAX_BYTES_PER_REQUEST; | |
70 | rc = ser_hid_hidapi_get_data(serial, 0, data, space, timeout); | |
71 | if (rc == SR_ERR_TIMEOUT) | |
72 | return 0; | |
73 | if (rc < 0) | |
74 | return rc; | |
75 | if (rc == 0) | |
76 | return 0; | |
77 | return rc; | |
78 | } | |
79 | ||
80 | static int bu86x_write_bytes(struct sr_serial_dev_inst *serial, | |
81 | const uint8_t *data, int size) | |
82 | { | |
83 | return ser_hid_hidapi_set_data(serial, 0, data, size, 0); | |
84 | } | |
85 | ||
86 | static struct ser_hid_chip_functions chip_bu86x = { | |
87 | .chipname = "bu86x", | |
88 | .chipdesc = "Brymen BU-86X", | |
89 | .vid_pid_items = vid_pid_items_bu86x, | |
90 | .max_bytes_per_request = BU86X_MAX_BYTES_PER_REQUEST, | |
91 | /* | |
92 | * The IR adapter's communication parameters are fixed and need | |
93 | * not get configured. Just silently ignore the caller's spec. | |
94 | */ | |
95 | .set_params = std_dummy_set_params, | |
96 | .read_bytes = bu86x_read_bytes, | |
97 | .write_bytes = bu86x_write_bytes, | |
98 | }; | |
99 | SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_bu86x = &chip_bu86x; | |
100 | ||
101 | #else | |
102 | ||
103 | SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_bu86x = NULL; | |
104 | ||
105 | #endif | |
106 | #endif |