]>
Commit | Line | Data |
---|---|---|
79081ec8 | 1 | /* |
50985c20 | 2 | * This file is part of the libsigrok project. |
79081ec8 | 3 | * |
bc653a56 | 4 | * Copyright (C) 2012-2013 Uwe Hermann <uwe@hermann-uwe.de> |
79081ec8 UH |
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 2 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, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
21 | #include <stdlib.h> | |
22 | #include <string.h> | |
c1aae900 | 23 | #include <libsigrok/libsigrok.h> |
79081ec8 UH |
24 | #include "libsigrok-internal.h" |
25 | #include "protocol.h" | |
26 | ||
388f9d3e UH |
27 | #define UNI_T_UT_D04_NEW "1a86.e008" |
28 | ||
a0e0bb41 | 29 | static const uint32_t scanopts[] = { |
431ec7ca | 30 | SR_CONF_CONN, |
73365eae UH |
31 | }; |
32 | ||
f254bc4b | 33 | static const uint32_t devopts[] = { |
1953564a | 34 | SR_CONF_MULTIMETER, |
1953564a | 35 | SR_CONF_CONTINUOUS, |
5827f61b BV |
36 | SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, |
37 | SR_CONF_LIMIT_MSEC | SR_CONF_SET, | |
79081ec8 UH |
38 | }; |
39 | ||
d9e79c51 UH |
40 | /* |
41 | * Note 1: The actual baudrate of the Cyrustek ES519xx chip used in this DMM | |
42 | * is 19230. However, the WCH CH9325 chip (UART to USB/HID) used in (some | |
43 | * versions of) the UNI-T UT-D04 cable doesn't support 19230 baud. It only | |
44 | * supports 19200, and setting an unsupported baudrate will result in the | |
45 | * default of 2400 being used (which will not work with this DMM, of course). | |
46 | */ | |
47 | ||
f0540611 | 48 | static int dev_clear(const struct sr_dev_driver *di) |
79081ec8 | 49 | { |
f0540611 | 50 | return std_dev_clear(di, NULL); |
79081ec8 UH |
51 | } |
52 | ||
f0540611 | 53 | static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) |
79081ec8 | 54 | { |
f0540611 | 55 | return std_init(sr_ctx, di, LOG_PREFIX); |
fdbcb86d UH |
56 | } |
57 | ||
f0540611 | 58 | static GSList *scan(struct sr_dev_driver *di, GSList *options) |
79081ec8 | 59 | { |
388f9d3e | 60 | GSList *usb_devices, *devices, *l; |
79081ec8 | 61 | struct sr_dev_inst *sdi; |
41d9427f | 62 | struct dev_context *devc; |
79081ec8 | 63 | struct drv_context *drvc; |
f0540611 | 64 | struct dmm_info *dmm; |
388f9d3e | 65 | struct sr_usb_dev_inst *usb; |
431ec7ca | 66 | struct sr_config *src; |
388f9d3e | 67 | const char *conn; |
79081ec8 | 68 | |
41812aca | 69 | drvc = di->context; |
f0540611 | 70 | dmm = (struct dmm_info *)di; |
79081ec8 | 71 | |
388f9d3e UH |
72 | conn = NULL; |
73 | for (l = options; l; l = l->next) { | |
431ec7ca BV |
74 | src = l->data; |
75 | switch (src->key) { | |
76 | case SR_CONF_CONN: | |
7d93a62e | 77 | conn = g_variant_get_string(src->data, NULL); |
388f9d3e UH |
78 | break; |
79 | } | |
80 | } | |
81 | if (!conn) | |
56e76981 | 82 | return NULL; |
41d9427f | 83 | |
388f9d3e UH |
84 | devices = NULL; |
85 | if (!(usb_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn))) { | |
86 | g_slist_free_full(usb_devices, g_free); | |
79081ec8 | 87 | return NULL; |
388f9d3e | 88 | } |
79081ec8 | 89 | |
388f9d3e UH |
90 | for (l = usb_devices; l; l = l->next) { |
91 | usb = l->data; | |
f57d8ffe | 92 | devc = g_malloc0(sizeof(struct dev_context)); |
bc653a56 | 93 | devc->first_run = TRUE; |
aac29cc1 | 94 | sdi = g_malloc0(sizeof(struct sr_dev_inst)); |
0af636be | 95 | sdi->status = SR_ST_INACTIVE; |
f0540611 ML |
96 | sdi->vendor = g_strdup(dmm->vendor); |
97 | sdi->model = g_strdup(dmm->device); | |
41d9427f | 98 | sdi->priv = devc; |
f0540611 | 99 | sdi->driver = di; |
5e23fcab | 100 | sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); |
3ece1dff UH |
101 | sdi->inst_type = SR_INST_USB; |
102 | sdi->conn = usb; | |
388f9d3e | 103 | drvc->instances = g_slist_append(drvc->instances, sdi); |
41d9427f | 104 | devices = g_slist_append(devices, sdi); |
79081ec8 UH |
105 | } |
106 | ||
107 | return devices; | |
108 | } | |
109 | ||
f0540611 | 110 | static GSList *dev_list(const struct sr_dev_driver *di) |
79081ec8 | 111 | { |
41812aca | 112 | return ((struct drv_context *)(di->context))->instances; |
79081ec8 UH |
113 | } |
114 | ||
f0540611 | 115 | static int dev_open(struct sr_dev_inst *sdi) |
79081ec8 | 116 | { |
f0540611 | 117 | struct sr_dev_driver *di; |
388f9d3e | 118 | struct drv_context *drvc; |
3ece1dff | 119 | struct sr_usb_dev_inst *usb; |
bc653a56 | 120 | int ret; |
41d9427f | 121 | |
f0540611 | 122 | di = sdi->driver; |
41812aca | 123 | drvc = di->context; |
3ece1dff | 124 | usb = sdi->conn; |
41d9427f | 125 | |
3ece1dff | 126 | if ((ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb)) == SR_OK) |
bc653a56 | 127 | sdi->status = SR_ST_ACTIVE; |
e73ffd42 | 128 | |
bc653a56 | 129 | return ret; |
79081ec8 UH |
130 | } |
131 | ||
6078d2c9 | 132 | static int dev_close(struct sr_dev_inst *sdi) |
79081ec8 | 133 | { |
79081ec8 UH |
134 | /* TODO */ |
135 | ||
bc653a56 | 136 | sdi->status = SR_ST_INACTIVE; |
e73ffd42 | 137 | |
79081ec8 UH |
138 | return SR_OK; |
139 | } | |
140 | ||
f0540611 | 141 | static int cleanup(const struct sr_dev_driver *di) |
79081ec8 | 142 | { |
f0540611 | 143 | return dev_clear(di); |
79081ec8 UH |
144 | } |
145 | ||
584560f1 | 146 | static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, |
53b4680f | 147 | const struct sr_channel_group *cg) |
79081ec8 UH |
148 | { |
149 | struct dev_context *devc; | |
150 | ||
53b4680f | 151 | (void)cg; |
8f996b89 | 152 | |
79081ec8 UH |
153 | devc = sdi->priv; |
154 | ||
584560f1 | 155 | switch (key) { |
1953564a | 156 | case SR_CONF_LIMIT_MSEC: |
7d93a62e | 157 | devc->limit_msec = g_variant_get_uint64(data); |
79081ec8 | 158 | break; |
1953564a | 159 | case SR_CONF_LIMIT_SAMPLES: |
7d93a62e | 160 | devc->limit_samples = g_variant_get_uint64(data); |
79081ec8 UH |
161 | break; |
162 | default: | |
bd6fbf62 | 163 | return SR_ERR_NA; |
79081ec8 UH |
164 | } |
165 | ||
166 | return SR_OK; | |
167 | } | |
168 | ||
584560f1 | 169 | static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
53b4680f | 170 | const struct sr_channel_group *cg) |
a1c743fc | 171 | { |
a1c743fc | 172 | (void)sdi; |
53b4680f | 173 | (void)cg; |
a1c743fc BV |
174 | |
175 | switch (key) { | |
0d485e30 | 176 | case SR_CONF_SCAN_OPTIONS: |
584560f1 | 177 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
a0e0bb41 | 178 | scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); |
0d485e30 | 179 | break; |
9a6517d1 | 180 | case SR_CONF_DEVICE_OPTIONS: |
584560f1 | 181 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
f254bc4b | 182 | devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); |
9a6517d1 | 183 | break; |
a1c743fc | 184 | default: |
bd6fbf62 | 185 | return SR_ERR_NA; |
a1c743fc BV |
186 | } |
187 | ||
188 | return SR_OK; | |
189 | } | |
190 | ||
f0540611 | 191 | static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) |
79081ec8 | 192 | { |
79081ec8 UH |
193 | struct dev_context *devc; |
194 | ||
195 | devc = sdi->priv; | |
196 | ||
79081ec8 UH |
197 | devc->cb_data = cb_data; |
198 | ||
c5ffac41 UH |
199 | devc->starttime = g_get_monotonic_time(); |
200 | ||
79081ec8 | 201 | /* Send header packet to the session bus. */ |
102f1239 | 202 | std_session_send_df_header(sdi, LOG_PREFIX); |
79081ec8 | 203 | |
102f1239 | 204 | sr_session_source_add(sdi->session, 0, 0, 10 /* poll_timeout */, |
f0540611 | 205 | uni_t_dmm_receive_data, (void *)sdi); |
79081ec8 UH |
206 | |
207 | return SR_OK; | |
208 | } | |
209 | ||
6078d2c9 | 210 | static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) |
79081ec8 UH |
211 | { |
212 | struct sr_datafeed_packet packet; | |
213 | ||
102f1239 | 214 | (void)cb_data; |
79081ec8 UH |
215 | |
216 | sr_dbg("Stopping acquisition."); | |
217 | ||
218 | /* Send end packet to the session bus. */ | |
219 | sr_dbg("Sending SR_DF_END."); | |
220 | packet.type = SR_DF_END; | |
102f1239 | 221 | sr_session_send(sdi, &packet); |
79081ec8 | 222 | |
102f1239 | 223 | sr_session_source_remove(sdi->session, 0); |
79081ec8 UH |
224 | |
225 | return SR_OK; | |
226 | } | |
227 | ||
f0540611 ML |
228 | #define DMM(ID, CHIPSET, VENDOR, MODEL, BAUDRATE, PACKETSIZE, \ |
229 | VALID, PARSE, DETAILS) \ | |
230 | &(struct dmm_info) { \ | |
231 | { \ | |
232 | .name = ID, \ | |
233 | .longname = VENDOR " " MODEL, \ | |
234 | .api_version = 1, \ | |
235 | .init = init, \ | |
236 | .cleanup = cleanup, \ | |
237 | .scan = scan, \ | |
238 | .dev_list = dev_list, \ | |
239 | .dev_clear = dev_clear, \ | |
240 | .config_get = NULL, \ | |
241 | .config_set = config_set, \ | |
242 | .config_list = config_list, \ | |
243 | .dev_open = dev_open, \ | |
244 | .dev_close = dev_close, \ | |
245 | .dev_acquisition_start = dev_acquisition_start, \ | |
246 | .dev_acquisition_stop = dev_acquisition_stop, \ | |
41812aca | 247 | .context = NULL, \ |
f0540611 ML |
248 | }, \ |
249 | VENDOR, MODEL, BAUDRATE, PACKETSIZE, \ | |
250 | VALID, PARSE, DETAILS, sizeof(struct CHIPSET##_info) \ | |
251 | } | |
fdbcb86d | 252 | |
f0540611 ML |
253 | SR_PRIV const struct dmm_info *uni_t_dmm_drivers[] = { |
254 | DMM( | |
255 | "tecpel-dmm-8061", fs9721, | |
256 | "Tecpel", "DMM-8061", 2400, | |
257 | FS9721_PACKET_SIZE, | |
258 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
259 | sr_fs9721_00_temp_c | |
260 | ), | |
261 | DMM( | |
262 | "uni-t-ut372", ut372, | |
263 | "UNI-T", "UT372", 2400, | |
264 | UT372_PACKET_SIZE, | |
265 | sr_ut372_packet_valid, sr_ut372_parse, | |
266 | NULL | |
267 | ), | |
268 | DMM( | |
269 | "uni-t-ut60a", fs9721, | |
270 | "UNI-T", "UT60A", 2400, | |
271 | FS9721_PACKET_SIZE, | |
272 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
273 | NULL | |
274 | ), | |
275 | DMM( | |
276 | "uni-t-ut60e", fs9721, | |
277 | "UNI-T", "UT60E", 2400, | |
278 | FS9721_PACKET_SIZE, | |
279 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
280 | sr_fs9721_00_temp_c | |
281 | ), | |
282 | DMM( | |
283 | "uni-t-ut60g", es519xx, | |
284 | /* The baudrate is actually 19230, see "Note 1" below. */ | |
285 | "UNI-T", "UT60G", 19200, | |
286 | ES519XX_11B_PACKET_SIZE, | |
287 | sr_es519xx_19200_11b_packet_valid, sr_es519xx_19200_11b_parse, | |
288 | NULL | |
289 | ), | |
290 | DMM( | |
291 | "uni-t-ut61b", fs9922, | |
292 | "UNI-T", "UT61B", 2400, | |
293 | FS9922_PACKET_SIZE, | |
294 | sr_fs9922_packet_valid, sr_fs9922_parse, | |
295 | NULL | |
296 | ), | |
297 | DMM( | |
298 | "uni-t-ut61c", fs9922, | |
299 | "UNI-T", "UT61C", 2400, | |
300 | FS9922_PACKET_SIZE, | |
301 | sr_fs9922_packet_valid, sr_fs9922_parse, | |
302 | NULL | |
303 | ), | |
304 | DMM( | |
305 | "uni-t-ut61d", fs9922, | |
306 | "UNI-T", "UT61D", 2400, | |
307 | FS9922_PACKET_SIZE, | |
308 | sr_fs9922_packet_valid, sr_fs9922_parse, | |
309 | NULL | |
310 | ), | |
311 | DMM( | |
312 | "uni-t-ut61e", es519xx, | |
313 | /* The baudrate is actually 19230, see "Note 1" below. */ | |
314 | "UNI-T", "UT61E", 19200, | |
315 | ES519XX_14B_PACKET_SIZE, | |
316 | sr_es519xx_19200_14b_packet_valid, sr_es519xx_19200_14b_parse, | |
317 | NULL | |
318 | ), | |
319 | DMM( | |
320 | "uni-t-ut71a", ut71x, | |
321 | "UNI-T", "UT71A", 2400, UT71X_PACKET_SIZE, | |
322 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL | |
323 | ), | |
324 | DMM( | |
325 | "uni-t-ut71b", ut71x, | |
326 | "UNI-T", "UT71B", 2400, UT71X_PACKET_SIZE, | |
327 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL | |
328 | ), | |
329 | DMM( | |
330 | "uni-t-ut71c", ut71x, | |
331 | "UNI-T", "UT71C", 2400, UT71X_PACKET_SIZE, | |
332 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL | |
333 | ), | |
334 | DMM( | |
335 | "uni-t-ut71d", ut71x, | |
336 | "UNI-T", "UT71D", 2400, UT71X_PACKET_SIZE, | |
337 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL | |
338 | ), | |
339 | DMM( | |
340 | "uni-t-ut71e", ut71x, | |
341 | "UNI-T", "UT71E", 2400, UT71X_PACKET_SIZE, | |
342 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL | |
343 | ), | |
344 | DMM( | |
345 | "voltcraft-vc820", fs9721, | |
346 | "Voltcraft", "VC-820", 2400, | |
347 | FS9721_PACKET_SIZE, | |
348 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
349 | NULL | |
350 | ), | |
351 | DMM( | |
352 | "voltcraft-vc830", fs9922, | |
353 | /* | |
354 | * Note: The VC830 doesn't set the 'volt' and 'diode' bits of | |
355 | * the FS9922 protocol. Instead, it only sets the user-defined | |
356 | * bit "z1" to indicate "diode mode" and "voltage". | |
357 | */ | |
358 | "Voltcraft", "VC-830", 2400, | |
359 | FS9922_PACKET_SIZE, | |
360 | sr_fs9922_packet_valid, sr_fs9922_parse, | |
361 | &sr_fs9922_z1_diode | |
362 | ), | |
363 | DMM( | |
364 | "voltcraft-vc840", fs9721, | |
365 | "Voltcraft", "VC-840", 2400, | |
366 | FS9721_PACKET_SIZE, | |
367 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
368 | sr_fs9721_00_temp_c | |
369 | ), | |
370 | DMM( | |
371 | "voltcraft-vc870", vc870, | |
372 | "Voltcraft", "VC-870", 9600, VC870_PACKET_SIZE, | |
373 | sr_vc870_packet_valid, sr_vc870_parse, NULL | |
374 | ), | |
375 | DMM( | |
376 | "voltcraft-vc920", ut71x, | |
377 | "Voltcraft", "VC-920", 2400, UT71X_PACKET_SIZE, | |
378 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL | |
379 | ), | |
380 | DMM( | |
381 | "voltcraft-vc940", ut71x, | |
382 | "Voltcraft", "VC-940", 2400, UT71X_PACKET_SIZE, | |
383 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL | |
384 | ), | |
385 | DMM( | |
386 | "voltcraft-vc960", ut71x, | |
387 | "Voltcraft", "VC-960", 2400, UT71X_PACKET_SIZE, | |
388 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL | |
389 | ), | |
390 | DMM( | |
391 | "tenma-72-7745", es519xx, | |
392 | "Tenma", "72-7745", 2400, | |
393 | FS9721_PACKET_SIZE, | |
394 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
395 | sr_fs9721_00_temp_c | |
396 | ), | |
397 | DMM( | |
398 | "tenma-72-7750", es519xx, | |
399 | /* The baudrate is actually 19230, see "Note 1" below. */ | |
400 | "Tenma", "72-7750", 19200, | |
401 | ES519XX_11B_PACKET_SIZE, | |
402 | sr_es519xx_19200_11b_packet_valid, sr_es519xx_19200_11b_parse, | |
403 | NULL | |
404 | ), | |
b65630f7 | 405 | NULL |
f0540611 | 406 | }; |