]>
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> | |
23 | #include "libsigrok.h" | |
24 | #include "libsigrok-internal.h" | |
25 | #include "protocol.h" | |
26 | ||
388f9d3e UH |
27 | #define UNI_T_UT_D04_NEW "1a86.e008" |
28 | ||
7d93a62e | 29 | static const int32_t hwopts[] = { |
431ec7ca | 30 | SR_CONF_CONN, |
73365eae UH |
31 | }; |
32 | ||
7d93a62e | 33 | static const int32_t hwcaps[] = { |
1953564a BV |
34 | SR_CONF_MULTIMETER, |
35 | SR_CONF_LIMIT_SAMPLES, | |
36 | SR_CONF_LIMIT_MSEC, | |
37 | SR_CONF_CONTINUOUS, | |
79081ec8 UH |
38 | }; |
39 | ||
b6bad47c | 40 | SR_PRIV struct sr_dev_driver tecpel_dmm_8061_driver_info; |
a7a163a7 FK |
41 | SR_PRIV struct sr_dev_driver uni_t_ut60a_driver_info; |
42 | SR_PRIV struct sr_dev_driver uni_t_ut60e_driver_info; | |
5f985df2 | 43 | SR_PRIV struct sr_dev_driver uni_t_ut61c_driver_info; |
fdbcb86d | 44 | SR_PRIV struct sr_dev_driver uni_t_ut61d_driver_info; |
bbef5e32 | 45 | SR_PRIV struct sr_dev_driver uni_t_ut61e_driver_info; |
fdbcb86d | 46 | SR_PRIV struct sr_dev_driver voltcraft_vc820_driver_info; |
c1345749 | 47 | SR_PRIV struct sr_dev_driver voltcraft_vc830_driver_info; |
695d0e1e | 48 | SR_PRIV struct sr_dev_driver voltcraft_vc840_driver_info; |
5e1f7c89 | 49 | SR_PRIV struct sr_dev_driver tenma_72_7745_driver_info; |
6ac5f892 | 50 | |
c8852687 | 51 | SR_PRIV struct dmm_info udmms[] = { |
b6bad47c UH |
52 | { |
53 | "Tecpel", "DMM-8061", 2400, | |
26e0361c | 54 | FS9721_PACKET_SIZE, |
b6bad47c UH |
55 | sr_fs9721_packet_valid, sr_fs9721_parse, |
56 | sr_fs9721_00_temp_c, | |
57 | &tecpel_dmm_8061_driver_info, receive_data_TECPEL_DMM_8061, | |
58 | }, | |
a7a163a7 FK |
59 | { |
60 | "UNI-T", "UT60A", 2400, | |
26e0361c | 61 | FS9721_PACKET_SIZE, |
a7a163a7 FK |
62 | sr_fs9721_packet_valid, sr_fs9721_parse, |
63 | NULL, | |
64 | &uni_t_ut60a_driver_info, receive_data_UNI_T_UT60A, | |
65 | }, | |
66 | { | |
67 | "UNI-T", "UT60E", 2400, | |
26e0361c | 68 | FS9721_PACKET_SIZE, |
a7a163a7 FK |
69 | sr_fs9721_packet_valid, sr_fs9721_parse, |
70 | sr_fs9721_00_temp_c, | |
71 | &uni_t_ut60e_driver_info, receive_data_UNI_T_UT60E, | |
72 | }, | |
5f985df2 UH |
73 | { |
74 | "UNI-T", "UT61C", 2400, | |
75 | FS9922_PACKET_SIZE, | |
76 | sr_fs9922_packet_valid, sr_fs9922_parse, | |
77 | NULL, | |
78 | &uni_t_ut61c_driver_info, receive_data_UNI_T_UT61C, | |
79 | }, | |
c8852687 | 80 | { |
767aae30 | 81 | "UNI-T", "UT61D", 2400, |
26e0361c | 82 | FS9922_PACKET_SIZE, |
c8852687 UH |
83 | sr_fs9922_packet_valid, sr_fs9922_parse, |
84 | NULL, | |
85 | &uni_t_ut61d_driver_info, receive_data_UNI_T_UT61D, | |
86 | }, | |
bbef5e32 | 87 | { |
4d7ddff7 UH |
88 | /* |
89 | * Important: The actual baudrate of the Cyrustek ES51922 chip | |
90 | * used in this DMM is 19230. However, the WCH CH9325 chip | |
91 | * (UART to USB/HID) used in (some versions of) the UNI-T | |
92 | * UT-D04 cable doesn't support 19230 baud. It only supports | |
93 | * 19200, and setting an unsupported baudrate will result in | |
94 | * the default of 2400 being used (which will not work with | |
95 | * this DMM, of course). | |
96 | */ | |
97 | "UNI-T", "UT61E", 19200, | |
26e0361c | 98 | ES51922_PACKET_SIZE, |
bbef5e32 UH |
99 | sr_es51922_packet_valid, sr_es51922_parse, |
100 | NULL, | |
101 | &uni_t_ut61e_driver_info, receive_data_UNI_T_UT61E, | |
102 | }, | |
c8852687 | 103 | { |
bc653a56 | 104 | "Voltcraft", "VC-820", 2400, |
26e0361c | 105 | FS9721_PACKET_SIZE, |
c8852687 UH |
106 | sr_fs9721_packet_valid, sr_fs9721_parse, |
107 | NULL, | |
108 | &voltcraft_vc820_driver_info, receive_data_VOLTCRAFT_VC820, | |
109 | }, | |
c1345749 | 110 | { |
e52bb9be UH |
111 | /* |
112 | * Note: The VC830 doesn't set the 'volt' and 'diode' bits of | |
113 | * the FS9922 protocol. Instead, it only sets the user-defined | |
114 | * bit "z1" to indicate "diode mode" and "voltage". | |
115 | */ | |
c1345749 | 116 | "Voltcraft", "VC-830", 2400, |
26e0361c | 117 | FS9922_PACKET_SIZE, |
c1345749 | 118 | sr_fs9922_packet_valid, sr_fs9922_parse, |
e52bb9be | 119 | &sr_fs9922_z1_diode, |
c1345749 UH |
120 | &voltcraft_vc830_driver_info, receive_data_VOLTCRAFT_VC830, |
121 | }, | |
695d0e1e UH |
122 | { |
123 | "Voltcraft", "VC-840", 2400, | |
26e0361c | 124 | FS9721_PACKET_SIZE, |
695d0e1e | 125 | sr_fs9721_packet_valid, sr_fs9721_parse, |
2451a20f | 126 | sr_fs9721_00_temp_c, |
695d0e1e UH |
127 | &voltcraft_vc840_driver_info, receive_data_VOLTCRAFT_VC840, |
128 | }, | |
5e1f7c89 BV |
129 | { |
130 | "Tenma", "72-7745", 2400, | |
131 | FS9721_PACKET_SIZE, | |
132 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
133 | sr_fs9721_00_temp_c, | |
134 | &tenma_72_7745_driver_info, | |
135 | /* This is a basic rebadge of the UT60E. */ | |
136 | receive_data_UNI_T_UT60E, | |
137 | }, | |
c8852687 | 138 | }; |
6ac5f892 | 139 | |
3b412e3a | 140 | static int dev_clear(int dmm) |
79081ec8 | 141 | { |
8dca646e | 142 | return std_dev_clear(udmms[dmm].di, NULL); |
79081ec8 UH |
143 | } |
144 | ||
6078d2c9 | 145 | static int init(struct sr_context *sr_ctx, int dmm) |
79081ec8 | 146 | { |
c8852687 | 147 | sr_dbg("Selected '%s' subdriver.", udmms[dmm].di->name); |
6ac5f892 | 148 | |
f6beaac5 | 149 | return std_init(sr_ctx, udmms[dmm].di, LOG_PREFIX); |
fdbcb86d UH |
150 | } |
151 | ||
6078d2c9 | 152 | static GSList *scan(GSList *options, int dmm) |
79081ec8 | 153 | { |
388f9d3e | 154 | GSList *usb_devices, *devices, *l; |
79081ec8 | 155 | struct sr_dev_inst *sdi; |
41d9427f | 156 | struct dev_context *devc; |
79081ec8 | 157 | struct drv_context *drvc; |
388f9d3e | 158 | struct sr_usb_dev_inst *usb; |
431ec7ca | 159 | struct sr_config *src; |
41d9427f | 160 | struct sr_probe *probe; |
388f9d3e | 161 | const char *conn; |
79081ec8 | 162 | |
c8852687 | 163 | drvc = udmms[dmm].di->priv; |
79081ec8 | 164 | |
388f9d3e UH |
165 | conn = NULL; |
166 | for (l = options; l; l = l->next) { | |
431ec7ca BV |
167 | src = l->data; |
168 | switch (src->key) { | |
169 | case SR_CONF_CONN: | |
7d93a62e | 170 | conn = g_variant_get_string(src->data, NULL); |
388f9d3e UH |
171 | break; |
172 | } | |
173 | } | |
174 | if (!conn) | |
56e76981 | 175 | return NULL; |
41d9427f | 176 | |
388f9d3e UH |
177 | devices = NULL; |
178 | if (!(usb_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn))) { | |
179 | g_slist_free_full(usb_devices, g_free); | |
79081ec8 | 180 | return NULL; |
388f9d3e | 181 | } |
79081ec8 | 182 | |
388f9d3e UH |
183 | for (l = usb_devices; l; l = l->next) { |
184 | usb = l->data; | |
41d9427f UH |
185 | |
186 | if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { | |
187 | sr_err("Device context malloc failed."); | |
188 | return NULL; | |
189 | } | |
190 | ||
bc653a56 UH |
191 | devc->first_run = TRUE; |
192 | ||
388f9d3e | 193 | if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, |
c8852687 | 194 | udmms[dmm].vendor, udmms[dmm].device, NULL))) { |
41d9427f UH |
195 | sr_err("sr_dev_inst_new returned NULL."); |
196 | return NULL; | |
197 | } | |
198 | sdi->priv = devc; | |
c8852687 | 199 | sdi->driver = udmms[dmm].di; |
41d9427f UH |
200 | if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1"))) |
201 | return NULL; | |
202 | sdi->probes = g_slist_append(sdi->probes, probe); | |
388f9d3e | 203 | |
3ece1dff UH |
204 | sdi->inst_type = SR_INST_USB; |
205 | sdi->conn = usb; | |
388f9d3e UH |
206 | |
207 | drvc->instances = g_slist_append(drvc->instances, sdi); | |
41d9427f | 208 | devices = g_slist_append(devices, sdi); |
79081ec8 UH |
209 | } |
210 | ||
211 | return devices; | |
212 | } | |
213 | ||
6078d2c9 | 214 | static GSList *dev_list(int dmm) |
79081ec8 | 215 | { |
bc653a56 | 216 | return ((struct drv_context *)(udmms[dmm].di->priv))->instances; |
79081ec8 UH |
217 | } |
218 | ||
6078d2c9 | 219 | static int dev_open(struct sr_dev_inst *sdi, int dmm) |
79081ec8 | 220 | { |
388f9d3e | 221 | struct drv_context *drvc; |
3ece1dff | 222 | struct sr_usb_dev_inst *usb; |
bc653a56 | 223 | int ret; |
41d9427f | 224 | |
c8852687 | 225 | drvc = udmms[dmm].di->priv; |
3ece1dff | 226 | usb = sdi->conn; |
41d9427f | 227 | |
3ece1dff | 228 | if ((ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb)) == SR_OK) |
bc653a56 | 229 | sdi->status = SR_ST_ACTIVE; |
e73ffd42 | 230 | |
bc653a56 | 231 | return ret; |
79081ec8 UH |
232 | } |
233 | ||
6078d2c9 | 234 | static int dev_close(struct sr_dev_inst *sdi) |
79081ec8 UH |
235 | { |
236 | (void)sdi; | |
237 | ||
238 | /* TODO */ | |
239 | ||
bc653a56 | 240 | sdi->status = SR_ST_INACTIVE; |
e73ffd42 | 241 | |
79081ec8 UH |
242 | return SR_OK; |
243 | } | |
244 | ||
6078d2c9 | 245 | static int cleanup(int dmm) |
79081ec8 | 246 | { |
3b412e3a | 247 | return dev_clear(dmm); |
79081ec8 UH |
248 | } |
249 | ||
8f996b89 ML |
250 | static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, |
251 | const struct sr_probe_group *probe_group) | |
79081ec8 UH |
252 | { |
253 | struct dev_context *devc; | |
254 | ||
8f996b89 ML |
255 | (void)probe_group; |
256 | ||
79081ec8 UH |
257 | devc = sdi->priv; |
258 | ||
035a1078 | 259 | switch (id) { |
1953564a | 260 | case SR_CONF_LIMIT_MSEC: |
7d93a62e | 261 | if (g_variant_get_uint64(data) == 0) { |
79081ec8 UH |
262 | sr_err("Time limit cannot be 0."); |
263 | return SR_ERR; | |
264 | } | |
7d93a62e | 265 | devc->limit_msec = g_variant_get_uint64(data); |
79081ec8 UH |
266 | sr_dbg("Setting time limit to %" PRIu64 "ms.", |
267 | devc->limit_msec); | |
268 | break; | |
1953564a | 269 | case SR_CONF_LIMIT_SAMPLES: |
7d93a62e | 270 | if (g_variant_get_uint64(data) == 0) { |
79081ec8 UH |
271 | sr_err("Sample limit cannot be 0."); |
272 | return SR_ERR; | |
273 | } | |
7d93a62e | 274 | devc->limit_samples = g_variant_get_uint64(data); |
79081ec8 UH |
275 | sr_dbg("Setting sample limit to %" PRIu64 ".", |
276 | devc->limit_samples); | |
277 | break; | |
278 | default: | |
bd6fbf62 | 279 | return SR_ERR_NA; |
79081ec8 UH |
280 | } |
281 | ||
282 | return SR_OK; | |
283 | } | |
284 | ||
8f996b89 ML |
285 | static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, |
286 | const struct sr_probe_group *probe_group) | |
a1c743fc | 287 | { |
a1c743fc | 288 | (void)sdi; |
8f996b89 | 289 | (void)probe_group; |
a1c743fc BV |
290 | |
291 | switch (key) { | |
0d485e30 | 292 | case SR_CONF_SCAN_OPTIONS: |
7d93a62e BV |
293 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, |
294 | hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t)); | |
0d485e30 | 295 | break; |
9a6517d1 | 296 | case SR_CONF_DEVICE_OPTIONS: |
7d93a62e BV |
297 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, |
298 | hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); | |
9a6517d1 | 299 | break; |
a1c743fc | 300 | default: |
bd6fbf62 | 301 | return SR_ERR_NA; |
a1c743fc BV |
302 | } |
303 | ||
304 | return SR_OK; | |
305 | } | |
306 | ||
6078d2c9 | 307 | static int dev_acquisition_start(const struct sr_dev_inst *sdi, |
c8852687 | 308 | void *cb_data, int dmm) |
79081ec8 | 309 | { |
79081ec8 UH |
310 | struct dev_context *devc; |
311 | ||
312 | devc = sdi->priv; | |
313 | ||
79081ec8 UH |
314 | devc->cb_data = cb_data; |
315 | ||
c5ffac41 UH |
316 | devc->starttime = g_get_monotonic_time(); |
317 | ||
79081ec8 | 318 | /* Send header packet to the session bus. */ |
29a27196 | 319 | std_session_send_df_header(cb_data, LOG_PREFIX); |
79081ec8 | 320 | |
c8852687 UH |
321 | sr_source_add(0, 0, 10 /* poll_timeout */, |
322 | udmms[dmm].receive_data, (void *)sdi); | |
79081ec8 UH |
323 | |
324 | return SR_OK; | |
325 | } | |
326 | ||
6078d2c9 | 327 | static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) |
79081ec8 UH |
328 | { |
329 | struct sr_datafeed_packet packet; | |
330 | ||
331 | (void)sdi; | |
332 | ||
333 | sr_dbg("Stopping acquisition."); | |
334 | ||
335 | /* Send end packet to the session bus. */ | |
336 | sr_dbg("Sending SR_DF_END."); | |
337 | packet.type = SR_DF_END; | |
338 | sr_session_send(cb_data, &packet); | |
339 | ||
340 | /* TODO? */ | |
341 | sr_source_remove(0); | |
342 | ||
343 | return SR_OK; | |
344 | } | |
345 | ||
c8852687 UH |
346 | /* Driver-specific API function wrappers */ |
347 | #define HW_INIT(X) \ | |
6078d2c9 | 348 | static int init_##X(struct sr_context *sr_ctx) { return init(sr_ctx, X); } |
c8852687 | 349 | #define HW_CLEANUP(X) \ |
6078d2c9 | 350 | static int cleanup_##X(void) { return cleanup(X); } |
c8852687 | 351 | #define HW_SCAN(X) \ |
6078d2c9 | 352 | static GSList *scan_##X(GSList *options) { return scan(options, X); } |
c8852687 | 353 | #define HW_DEV_LIST(X) \ |
6078d2c9 | 354 | static GSList *dev_list_##X(void) { return dev_list(X); } |
3b412e3a UH |
355 | #define HW_DEV_CLEAR(X) \ |
356 | static int dev_clear_##X(void) { return dev_clear(X); } | |
c8852687 | 357 | #define HW_DEV_ACQUISITION_START(X) \ |
6078d2c9 UH |
358 | static int dev_acquisition_start_##X(const struct sr_dev_inst *sdi, \ |
359 | void *cb_data) { return dev_acquisition_start(sdi, cb_data, X); } | |
c8852687 | 360 | #define HW_DEV_OPEN(X) \ |
6078d2c9 | 361 | static int dev_open_##X(struct sr_dev_inst *sdi) { return dev_open(sdi, X); } |
c8852687 UH |
362 | |
363 | /* Driver structs and API function wrappers */ | |
364 | #define DRV(ID, ID_UPPER, NAME, LONGNAME) \ | |
365 | HW_INIT(ID_UPPER) \ | |
366 | HW_CLEANUP(ID_UPPER) \ | |
367 | HW_SCAN(ID_UPPER) \ | |
368 | HW_DEV_LIST(ID_UPPER) \ | |
3b412e3a | 369 | HW_DEV_CLEAR(ID_UPPER) \ |
c8852687 UH |
370 | HW_DEV_ACQUISITION_START(ID_UPPER) \ |
371 | HW_DEV_OPEN(ID_UPPER) \ | |
372 | SR_PRIV struct sr_dev_driver ID##_driver_info = { \ | |
373 | .name = NAME, \ | |
374 | .longname = LONGNAME, \ | |
375 | .api_version = 1, \ | |
6078d2c9 UH |
376 | .init = init_##ID_UPPER, \ |
377 | .cleanup = cleanup_##ID_UPPER, \ | |
378 | .scan = scan_##ID_UPPER, \ | |
379 | .dev_list = dev_list_##ID_UPPER, \ | |
3b412e3a | 380 | .dev_clear = dev_clear_##ID_UPPER, \ |
c8852687 UH |
381 | .config_get = NULL, \ |
382 | .config_set = config_set, \ | |
383 | .config_list = config_list, \ | |
6078d2c9 UH |
384 | .dev_open = dev_open_##ID_UPPER, \ |
385 | .dev_close = dev_close, \ | |
386 | .dev_acquisition_start = dev_acquisition_start_##ID_UPPER, \ | |
387 | .dev_acquisition_stop = dev_acquisition_stop, \ | |
c8852687 | 388 | .priv = NULL, \ |
fdbcb86d UH |
389 | }; |
390 | ||
b6bad47c | 391 | DRV(tecpel_dmm_8061, TECPEL_DMM_8061, "tecpel-dmm-8061", "Tecpel DMM-8061") |
a7a163a7 FK |
392 | DRV(uni_t_ut60a, UNI_T_UT60A, "uni-t-ut60a", "UNI-T UT60A") |
393 | DRV(uni_t_ut60e, UNI_T_UT60E, "uni-t-ut60e", "UNI-T UT60E") | |
5f985df2 | 394 | DRV(uni_t_ut61c, UNI_T_UT61C, "uni-t-ut61c", "UNI-T UT61C") |
c8852687 | 395 | DRV(uni_t_ut61d, UNI_T_UT61D, "uni-t-ut61d", "UNI-T UT61D") |
bbef5e32 | 396 | DRV(uni_t_ut61e, UNI_T_UT61E, "uni-t-ut61e", "UNI-T UT61E") |
c8852687 | 397 | DRV(voltcraft_vc820, VOLTCRAFT_VC820, "voltcraft-vc820", "Voltcraft VC-820") |
c1345749 | 398 | DRV(voltcraft_vc830, VOLTCRAFT_VC830, "voltcraft-vc830", "Voltcraft VC-830") |
695d0e1e | 399 | DRV(voltcraft_vc840, VOLTCRAFT_VC840, "voltcraft-vc840", "Voltcraft VC-840") |
5e1f7c89 | 400 | DRV(tenma_72_7745, TENMA_72_7745, "tenma-72-7745", "Tenma 72-7745") |