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