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