]>
Commit | Line | Data |
---|---|---|
20cbc785 AG |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com> | |
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 | ||
6ec6c43b | 20 | #include <config.h> |
20cbc785 AG |
21 | #include "protocol.h" |
22 | ||
a0e0bb41 | 23 | static const uint32_t scanopts[] = { |
601fb67c AG |
24 | SR_CONF_CONN, |
25 | SR_CONF_SERIALCOMM, | |
601fb67c AG |
26 | }; |
27 | ||
05199c0a | 28 | static const uint32_t drvopts[] = { |
601fb67c | 29 | SR_CONF_MULTIMETER, |
05199c0a UH |
30 | }; |
31 | ||
32 | static const uint32_t devopts[] = { | |
601fb67c | 33 | SR_CONF_CONTINUOUS, |
5827f61b BV |
34 | SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, |
35 | SR_CONF_LIMIT_MSEC | SR_CONF_SET, | |
601fb67c AG |
36 | }; |
37 | ||
e32862eb LPC |
38 | static GSList *brymen_scan(struct sr_dev_driver *di, const char *conn, |
39 | const char *serialcomm) | |
20cbc785 | 40 | { |
601fb67c AG |
41 | struct sr_dev_inst *sdi; |
42 | struct dev_context *devc; | |
601fb67c AG |
43 | struct sr_serial_dev_inst *serial; |
44 | GSList *devices; | |
45 | int ret; | |
c5d6f5cc UH |
46 | uint8_t buf[128]; |
47 | size_t len; | |
20cbc785 | 48 | |
91219afc | 49 | serial = sr_serial_dev_inst_new(conn, serialcomm); |
601fb67c | 50 | |
ca4266a0 | 51 | if (serial_open(serial, SERIAL_RDWR) != SR_OK) |
601fb67c AG |
52 | return NULL; |
53 | ||
54 | sr_info("Probing port %s.", conn); | |
55 | ||
56 | devices = NULL; | |
57 | ||
58 | /* Request reading */ | |
c5d6f5cc UH |
59 | if ((ret = brymen_packet_request(serial)) < 0) { |
60 | sr_err("Unable to send command: %d.", ret); | |
601fb67c | 61 | goto scan_cleanup; |
20cbc785 AG |
62 | } |
63 | ||
00ed77f2 | 64 | len = sizeof(buf); |
601fb67c AG |
65 | ret = brymen_stream_detect(serial, buf, &len, brymen_packet_length, |
66 | brymen_packet_is_valid, 1000, 9600); | |
67 | if (ret != SR_OK) | |
68 | goto scan_cleanup; | |
20cbc785 | 69 | |
601fb67c AG |
70 | sr_info("Found device on port %s.", conn); |
71 | ||
aac29cc1 | 72 | sdi = g_malloc0(sizeof(struct sr_dev_inst)); |
0af636be UH |
73 | sdi->status = SR_ST_INACTIVE; |
74 | sdi->vendor = g_strdup("Brymen"); | |
75 | sdi->model = g_strdup("BM85x"); | |
f57d8ffe | 76 | devc = g_malloc0(sizeof(struct dev_context)); |
dcba0c41 | 77 | sr_sw_limits_init(&devc->sw_limits); |
d9a7c349 UH |
78 | sdi->inst_type = SR_INST_SERIAL; |
79 | sdi->conn = serial; | |
601fb67c | 80 | sdi->priv = devc; |
5e23fcab | 81 | sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); |
601fb67c AG |
82 | devices = g_slist_append(devices, sdi); |
83 | ||
601fb67c AG |
84 | scan_cleanup: |
85 | serial_close(serial); | |
86 | ||
15a5bfe4 | 87 | return std_scan_complete(di, devices); |
20cbc785 AG |
88 | } |
89 | ||
4f840ce9 | 90 | static GSList *scan(struct sr_dev_driver *di, GSList *options) |
20cbc785 | 91 | { |
601fb67c AG |
92 | struct sr_config *src; |
93 | GSList *devices, *l; | |
94 | const char *conn, *serialcomm; | |
20cbc785 | 95 | |
20cbc785 | 96 | devices = NULL; |
20cbc785 | 97 | |
601fb67c AG |
98 | conn = serialcomm = NULL; |
99 | for (l = options; l; l = l->next) { | |
100 | src = l->data; | |
101 | switch (src->key) { | |
c5d6f5cc | 102 | case SR_CONF_CONN: |
510b3e69 | 103 | conn = g_variant_get_string(src->data, NULL); |
c5d6f5cc UH |
104 | break; |
105 | case SR_CONF_SERIALCOMM: | |
510b3e69 | 106 | serialcomm = g_variant_get_string(src->data, NULL); |
c5d6f5cc | 107 | break; |
601fb67c AG |
108 | } |
109 | } | |
d9a7c349 | 110 | if (!conn) |
601fb67c | 111 | return NULL; |
601fb67c | 112 | |
ca314e06 | 113 | if (serialcomm) |
e32862eb | 114 | devices = brymen_scan(di, conn, serialcomm); |
ca314e06 | 115 | else |
e32862eb | 116 | devices = brymen_scan(di, conn, "9600/8n1/dtr=1/rts=1"); |
20cbc785 AG |
117 | |
118 | return devices; | |
119 | } | |
120 | ||
dd7a72ea UH |
121 | static int config_set(uint32_t key, GVariant *data, |
122 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
20cbc785 | 123 | { |
601fb67c | 124 | struct dev_context *devc; |
20cbc785 | 125 | |
53b4680f | 126 | (void)cg; |
8f996b89 | 127 | |
b0baddef | 128 | devc = sdi->priv; |
601fb67c | 129 | |
dcba0c41 | 130 | return sr_sw_limits_config_set(&devc->sw_limits, key, data); |
20cbc785 AG |
131 | } |
132 | ||
dd7a72ea UH |
133 | static int config_list(uint32_t key, GVariant **data, |
134 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
510b3e69 | 135 | { |
05199c0a | 136 | return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts); |
510b3e69 BV |
137 | } |
138 | ||
695dc859 | 139 | static int dev_acquisition_start(const struct sr_dev_inst *sdi) |
20cbc785 | 140 | { |
601fb67c | 141 | struct dev_context *devc; |
d9a7c349 | 142 | struct sr_serial_dev_inst *serial; |
601fb67c | 143 | |
208c1d35 | 144 | devc = sdi->priv; |
601fb67c | 145 | |
dcba0c41 | 146 | sr_sw_limits_acquisition_start(&devc->sw_limits); |
bee2b016 | 147 | std_session_send_df_header(sdi); |
601fb67c | 148 | |
d9a7c349 | 149 | serial = sdi->conn; |
102f1239 BV |
150 | serial_source_add(sdi->session, serial, G_IO_IN, 50, |
151 | brymen_dmm_receive_data, (void *)sdi); | |
20cbc785 AG |
152 | |
153 | return SR_OK; | |
154 | } | |
155 | ||
dd5c48a6 | 156 | static struct sr_dev_driver brymen_bm857_driver_info = { |
c5d6f5cc UH |
157 | .name = "brymen-bm857", |
158 | .longname = "Brymen BM857", | |
20cbc785 | 159 | .api_version = 1, |
c2fdcc25 | 160 | .init = std_init, |
700d6b64 | 161 | .cleanup = std_cleanup, |
6078d2c9 | 162 | .scan = scan, |
c01bf34c | 163 | .dev_list = std_dev_list, |
f778bf02 | 164 | .dev_clear = std_dev_clear, |
6fab7b8f UH |
165 | .config_get = NULL, |
166 | .config_set = config_set, | |
167 | .config_list = config_list, | |
854434de | 168 | .dev_open = std_serial_dev_open, |
bf2c987f | 169 | .dev_close = std_serial_dev_close, |
6078d2c9 | 170 | .dev_acquisition_start = dev_acquisition_start, |
4b1a9d5d | 171 | .dev_acquisition_stop = std_serial_dev_acquisition_stop, |
41812aca | 172 | .context = NULL, |
20cbc785 | 173 | }; |
dd5c48a6 | 174 | SR_REGISTER_DEV_DRIVER(brymen_bm857_driver_info); |