]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2012 Bert Vermeulen <bert@biot.com> | |
5 | * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com> | |
6 | * Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de> | |
7 | * | |
8 | * This program is free software: you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation, either version 3 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 | */ | |
21 | ||
22 | #include <sys/types.h> | |
23 | #include <sys/stat.h> | |
24 | #include <fcntl.h> | |
25 | #include <string.h> | |
26 | #include <errno.h> | |
27 | #include <glib.h> | |
28 | #include "libsigrok.h" | |
29 | #include "libsigrok-internal.h" | |
30 | #include "protocol.h" | |
31 | ||
32 | static const uint32_t scanopts[] = { | |
33 | SR_CONF_CONN, | |
34 | SR_CONF_SERIALCOMM, | |
35 | }; | |
36 | ||
37 | static const uint32_t devopts[] = { | |
38 | SR_CONF_MULTIMETER, | |
39 | SR_CONF_CONTINUOUS, | |
40 | SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, | |
41 | SR_CONF_LIMIT_MSEC | SR_CONF_SET, | |
42 | }; | |
43 | ||
44 | SR_PRIV struct sr_dev_driver bbcgm_m2110_driver_info; | |
45 | SR_PRIV struct sr_dev_driver digitek_dt4000zc_driver_info; | |
46 | SR_PRIV struct sr_dev_driver tekpower_tp4000zc_driver_info; | |
47 | SR_PRIV struct sr_dev_driver metex_me31_driver_info; | |
48 | SR_PRIV struct sr_dev_driver peaktech_3410_driver_info; | |
49 | SR_PRIV struct sr_dev_driver mastech_mas345_driver_info; | |
50 | SR_PRIV struct sr_dev_driver mastech_ms8250b_driver_info; | |
51 | SR_PRIV struct sr_dev_driver va_va18b_driver_info; | |
52 | SR_PRIV struct sr_dev_driver va_va40b_driver_info; | |
53 | SR_PRIV struct sr_dev_driver metex_m3640d_driver_info; | |
54 | SR_PRIV struct sr_dev_driver metex_m4650cr_driver_info; | |
55 | SR_PRIV struct sr_dev_driver peaktech_4370_driver_info; | |
56 | SR_PRIV struct sr_dev_driver pce_pce_dm32_driver_info; | |
57 | SR_PRIV struct sr_dev_driver radioshack_22_168_driver_info; | |
58 | SR_PRIV struct sr_dev_driver radioshack_22_805_driver_info; | |
59 | SR_PRIV struct sr_dev_driver radioshack_22_812_driver_info; | |
60 | SR_PRIV struct sr_dev_driver tecpel_dmm_8061_ser_driver_info; | |
61 | SR_PRIV struct sr_dev_driver voltcraft_m3650cr_driver_info; | |
62 | SR_PRIV struct sr_dev_driver voltcraft_m3650d_driver_info; | |
63 | SR_PRIV struct sr_dev_driver voltcraft_m4650cr_driver_info; | |
64 | SR_PRIV struct sr_dev_driver voltcraft_me42_driver_info; | |
65 | SR_PRIV struct sr_dev_driver voltcraft_vc820_ser_driver_info; | |
66 | SR_PRIV struct sr_dev_driver voltcraft_vc830_ser_driver_info; | |
67 | SR_PRIV struct sr_dev_driver voltcraft_vc840_ser_driver_info; | |
68 | SR_PRIV struct sr_dev_driver voltcraft_vc870_ser_driver_info; | |
69 | SR_PRIV struct sr_dev_driver voltcraft_vc920_ser_driver_info; | |
70 | SR_PRIV struct sr_dev_driver voltcraft_vc940_ser_driver_info; | |
71 | SR_PRIV struct sr_dev_driver voltcraft_vc960_ser_driver_info; | |
72 | SR_PRIV struct sr_dev_driver uni_t_ut60a_ser_driver_info; | |
73 | SR_PRIV struct sr_dev_driver uni_t_ut60e_ser_driver_info; | |
74 | SR_PRIV struct sr_dev_driver uni_t_ut60g_ser_driver_info; | |
75 | SR_PRIV struct sr_dev_driver uni_t_ut61b_ser_driver_info; | |
76 | SR_PRIV struct sr_dev_driver uni_t_ut61c_ser_driver_info; | |
77 | SR_PRIV struct sr_dev_driver uni_t_ut61d_ser_driver_info; | |
78 | SR_PRIV struct sr_dev_driver uni_t_ut61e_ser_driver_info; | |
79 | SR_PRIV struct sr_dev_driver uni_t_ut71a_ser_driver_info; | |
80 | SR_PRIV struct sr_dev_driver uni_t_ut71b_ser_driver_info; | |
81 | SR_PRIV struct sr_dev_driver uni_t_ut71c_ser_driver_info; | |
82 | SR_PRIV struct sr_dev_driver uni_t_ut71d_ser_driver_info; | |
83 | SR_PRIV struct sr_dev_driver uni_t_ut71e_ser_driver_info; | |
84 | SR_PRIV struct sr_dev_driver iso_tech_idm103n_driver_info; | |
85 | SR_PRIV struct sr_dev_driver tenma_72_7745_ser_driver_info; | |
86 | SR_PRIV struct sr_dev_driver tenma_72_7750_ser_driver_info; | |
87 | SR_PRIV struct sr_dev_driver brymen_bm25x_driver_info; | |
88 | ||
89 | SR_PRIV struct dmm_info dmms[] = { | |
90 | { | |
91 | "BBC Goertz Metrawatt", "M2110", "1200/7n2", 1200, | |
92 | BBCGM_M2110_PACKET_SIZE, 0, 0, NULL, | |
93 | sr_m2110_packet_valid, sr_m2110_parse, | |
94 | NULL, | |
95 | &bbcgm_m2110_driver_info, receive_data_BBCGM_M2110, | |
96 | }, | |
97 | { | |
98 | "Digitek", "DT4000ZC", "2400/8n1/dtr=1", 2400, | |
99 | FS9721_PACKET_SIZE, 0, 0, NULL, | |
100 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
101 | sr_fs9721_10_temp_c, | |
102 | &digitek_dt4000zc_driver_info, receive_data_DIGITEK_DT4000ZC, | |
103 | }, | |
104 | { | |
105 | "TekPower", "TP4000ZC", "2400/8n1/dtr=1", 2400, | |
106 | FS9721_PACKET_SIZE, 0, 0, NULL, | |
107 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
108 | sr_fs9721_10_temp_c, | |
109 | &tekpower_tp4000zc_driver_info, receive_data_TEKPOWER_TP4000ZC, | |
110 | }, | |
111 | { | |
112 | "Metex", "ME-31", "600/7n2/rts=0/dtr=1", 600, | |
113 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
114 | sr_metex14_packet_valid, sr_metex14_parse, | |
115 | NULL, | |
116 | &metex_me31_driver_info, receive_data_METEX_ME31, | |
117 | }, | |
118 | { | |
119 | "Peaktech", "3410", "600/7n2/rts=0/dtr=1", 600, | |
120 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
121 | sr_metex14_packet_valid, sr_metex14_parse, | |
122 | NULL, | |
123 | &peaktech_3410_driver_info, receive_data_PEAKTECH_3410, | |
124 | }, | |
125 | { | |
126 | "MASTECH", "MAS345", "600/7n2/rts=0/dtr=1", 600, | |
127 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
128 | sr_metex14_packet_valid, sr_metex14_parse, | |
129 | NULL, | |
130 | &mastech_mas345_driver_info, receive_data_MASTECH_MAS345, | |
131 | }, | |
132 | { | |
133 | "MASTECH", "MS8250B", "2400/8n1/rts=0/dtr=1", | |
134 | 2400, FS9721_PACKET_SIZE, 0, 0, NULL, | |
135 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
136 | NULL, | |
137 | &mastech_ms8250b_driver_info, receive_data_MASTECH_MS8250B, | |
138 | }, | |
139 | { | |
140 | "V&A", "VA18B", "2400/8n1", 2400, | |
141 | FS9721_PACKET_SIZE, 0, 0, NULL, | |
142 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
143 | sr_fs9721_01_temp_c, | |
144 | &va_va18b_driver_info, receive_data_VA_VA18B, | |
145 | }, | |
146 | { | |
147 | "V&A", "VA40B", "2400/8n1", 2400, | |
148 | FS9721_PACKET_SIZE, 0, 0, NULL, | |
149 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
150 | sr_fs9721_max_c_min, | |
151 | &va_va40b_driver_info, receive_data_VA_VA40B, | |
152 | }, | |
153 | { | |
154 | "Metex", "M-3640D", "1200/7n2/rts=0/dtr=1", 1200, | |
155 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
156 | sr_metex14_packet_valid, sr_metex14_parse, | |
157 | NULL, | |
158 | &metex_m3640d_driver_info, receive_data_METEX_M3640D, | |
159 | }, | |
160 | { | |
161 | "Metex", "M-4650CR", "1200/7n2/rts=0/dtr=1", 1200, | |
162 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
163 | sr_metex14_packet_valid, sr_metex14_parse, | |
164 | NULL, | |
165 | &metex_m4650cr_driver_info, receive_data_METEX_M4650CR, | |
166 | }, | |
167 | { | |
168 | "PeakTech", "4370", "1200/7n2/rts=0/dtr=1", 1200, | |
169 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
170 | sr_metex14_packet_valid, sr_metex14_parse, | |
171 | NULL, | |
172 | &peaktech_4370_driver_info, receive_data_PEAKTECH_4370, | |
173 | }, | |
174 | { | |
175 | "PCE", "PCE-DM32", "2400/8n1", 2400, | |
176 | FS9721_PACKET_SIZE, 0, 0, NULL, | |
177 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
178 | sr_fs9721_01_10_temp_f_c, | |
179 | &pce_pce_dm32_driver_info, receive_data_PCE_PCE_DM32, | |
180 | }, | |
181 | { | |
182 | "RadioShack", "22-168", "1200/7n2/rts=0/dtr=1", 1200, | |
183 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
184 | sr_metex14_packet_valid, sr_metex14_parse, | |
185 | NULL, | |
186 | &radioshack_22_168_driver_info, receive_data_RADIOSHACK_22_168, | |
187 | }, | |
188 | { | |
189 | "RadioShack", "22-805", "600/7n2/rts=0/dtr=1", 600, | |
190 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
191 | sr_metex14_packet_valid, sr_metex14_parse, | |
192 | NULL, | |
193 | &radioshack_22_805_driver_info, receive_data_RADIOSHACK_22_805, | |
194 | }, | |
195 | { | |
196 | "RadioShack", "22-812", "4800/8n1/rts=0/dtr=1", 4800, | |
197 | RS9LCD_PACKET_SIZE, 0, 0, NULL, | |
198 | sr_rs9lcd_packet_valid, sr_rs9lcd_parse, | |
199 | NULL, | |
200 | &radioshack_22_812_driver_info, receive_data_RADIOSHACK_22_812, | |
201 | }, | |
202 | { | |
203 | "Tecpel", "DMM-8061 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
204 | 2400, FS9721_PACKET_SIZE, 0, 0, NULL, | |
205 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
206 | sr_fs9721_00_temp_c, | |
207 | &tecpel_dmm_8061_ser_driver_info, | |
208 | receive_data_TECPEL_DMM_8061_SER, | |
209 | }, | |
210 | { | |
211 | "Voltcraft", "M-3650CR", "1200/7n2/rts=0/dtr=1", 1200, | |
212 | METEX14_PACKET_SIZE, 150, 20, sr_metex14_packet_request, | |
213 | sr_metex14_packet_valid, sr_metex14_parse, | |
214 | NULL, | |
215 | &voltcraft_m3650cr_driver_info, receive_data_VOLTCRAFT_M3650CR, | |
216 | }, | |
217 | { | |
218 | "Voltcraft", "M-3650D", "1200/7n2/rts=0/dtr=1", 1200, | |
219 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
220 | sr_metex14_packet_valid, sr_metex14_parse, | |
221 | NULL, | |
222 | &voltcraft_m3650d_driver_info, receive_data_VOLTCRAFT_M3650D, | |
223 | }, | |
224 | { | |
225 | "Voltcraft", "M-4650CR", "1200/7n2/rts=0/dtr=1", 1200, | |
226 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
227 | sr_metex14_packet_valid, sr_metex14_parse, | |
228 | NULL, | |
229 | &voltcraft_m4650cr_driver_info, receive_data_VOLTCRAFT_M4650CR, | |
230 | }, | |
231 | { | |
232 | "Voltcraft", "ME-42", "600/7n2/rts=0/dtr=1", 600, | |
233 | METEX14_PACKET_SIZE, 250, 60, sr_metex14_packet_request, | |
234 | sr_metex14_packet_valid, sr_metex14_parse, | |
235 | NULL, | |
236 | &voltcraft_me42_driver_info, receive_data_VOLTCRAFT_ME42, | |
237 | }, | |
238 | { | |
239 | "Voltcraft", "VC-820 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
240 | 2400, FS9721_PACKET_SIZE, 0, 0, NULL, | |
241 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
242 | NULL, | |
243 | &voltcraft_vc820_ser_driver_info, | |
244 | receive_data_VOLTCRAFT_VC820_SER, | |
245 | }, | |
246 | { | |
247 | /* | |
248 | * Note: The VC830 doesn't set the 'volt' and 'diode' bits of | |
249 | * the FS9922 protocol. Instead, it only sets the user-defined | |
250 | * bit "z1" to indicate "diode mode" and "voltage". | |
251 | */ | |
252 | "Voltcraft", "VC-830 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
253 | 2400, FS9922_PACKET_SIZE, 0, 0, NULL, | |
254 | sr_fs9922_packet_valid, sr_fs9922_parse, | |
255 | &sr_fs9922_z1_diode, | |
256 | &voltcraft_vc830_ser_driver_info, | |
257 | receive_data_VOLTCRAFT_VC830_SER, | |
258 | }, | |
259 | { | |
260 | "Voltcraft", "VC-840 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
261 | 2400, FS9721_PACKET_SIZE, 0, 0, NULL, | |
262 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
263 | sr_fs9721_00_temp_c, | |
264 | &voltcraft_vc840_ser_driver_info, | |
265 | receive_data_VOLTCRAFT_VC840_SER, | |
266 | }, | |
267 | { | |
268 | "Voltcraft", "VC-870 (UT-D02 cable)", "9600/8n1/rts=0/dtr=1", | |
269 | 9600, VC870_PACKET_SIZE, 0, 0, NULL, | |
270 | sr_vc870_packet_valid, sr_vc870_parse, | |
271 | NULL, | |
272 | &voltcraft_vc870_ser_driver_info, receive_data_VOLTCRAFT_VC870_SER, | |
273 | }, | |
274 | { | |
275 | "Voltcraft", "VC-920 (UT-D02 cable)", "2400/7o1/rts=0/dtr=1", | |
276 | 2400, UT71X_PACKET_SIZE, 0, 0, NULL, | |
277 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL, | |
278 | &voltcraft_vc920_ser_driver_info, | |
279 | receive_data_VOLTCRAFT_VC920_SER, | |
280 | }, | |
281 | { | |
282 | "Voltcraft", "VC-940 (UT-D02 cable)", "2400/7o1/rts=0/dtr=1", | |
283 | 2400, UT71X_PACKET_SIZE, 0, 0, NULL, | |
284 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL, | |
285 | &voltcraft_vc940_ser_driver_info, | |
286 | receive_data_VOLTCRAFT_VC940_SER, | |
287 | }, | |
288 | { | |
289 | "Voltcraft", "VC-960 (UT-D02 cable)", "2400/7o1/rts=0/dtr=1", | |
290 | 2400, UT71X_PACKET_SIZE, 0, 0, NULL, | |
291 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL, | |
292 | &voltcraft_vc960_ser_driver_info, | |
293 | receive_data_VOLTCRAFT_VC960_SER, | |
294 | }, | |
295 | { | |
296 | "UNI-T", "UT60A (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
297 | 2400, FS9721_PACKET_SIZE, 0, 0, NULL, | |
298 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
299 | NULL, | |
300 | &uni_t_ut60a_ser_driver_info, | |
301 | receive_data_UNI_T_UT60A_SER, | |
302 | }, | |
303 | { | |
304 | "UNI-T", "UT60E (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
305 | 2400, FS9721_PACKET_SIZE, 0, 0, NULL, | |
306 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
307 | sr_fs9721_00_temp_c, | |
308 | &uni_t_ut60e_ser_driver_info, | |
309 | receive_data_UNI_T_UT60E_SER, | |
310 | }, | |
311 | { | |
312 | /* Note: ES51986 baudrate is actually 19230! */ | |
313 | "UNI-T", "UT60G (UT-D02 cable)", "19200/7o1/rts=0/dtr=1", | |
314 | 19200, ES519XX_11B_PACKET_SIZE, 0, 0, NULL, | |
315 | sr_es519xx_19200_11b_packet_valid, sr_es519xx_19200_11b_parse, | |
316 | NULL, | |
317 | &uni_t_ut60g_ser_driver_info, receive_data_UNI_T_UT60G_SER, | |
318 | }, | |
319 | { | |
320 | "UNI-T", "UT61B (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
321 | 2400, FS9922_PACKET_SIZE, 0, 0, NULL, | |
322 | sr_fs9922_packet_valid, sr_fs9922_parse, NULL, | |
323 | &uni_t_ut61b_ser_driver_info, receive_data_UNI_T_UT61B_SER, | |
324 | }, | |
325 | { | |
326 | "UNI-T", "UT61C (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
327 | 2400, FS9922_PACKET_SIZE, 0, 0, NULL, | |
328 | sr_fs9922_packet_valid, sr_fs9922_parse, NULL, | |
329 | &uni_t_ut61c_ser_driver_info, receive_data_UNI_T_UT61C_SER, | |
330 | }, | |
331 | { | |
332 | "UNI-T", "UT61D (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
333 | 2400, FS9922_PACKET_SIZE, 0, 0, NULL, | |
334 | sr_fs9922_packet_valid, sr_fs9922_parse, NULL, | |
335 | &uni_t_ut61d_ser_driver_info, receive_data_UNI_T_UT61D_SER, | |
336 | }, | |
337 | { | |
338 | /* Note: ES51922 baudrate is actually 19230! */ | |
339 | "UNI-T", "UT61E (UT-D02 cable)", "19200/7o1/rts=0/dtr=1", | |
340 | 19200, ES519XX_14B_PACKET_SIZE, 0, 0, NULL, | |
341 | sr_es519xx_19200_14b_packet_valid, sr_es519xx_19200_14b_parse, | |
342 | NULL, | |
343 | &uni_t_ut61e_ser_driver_info, receive_data_UNI_T_UT61E_SER, | |
344 | }, | |
345 | { | |
346 | "UNI-T", "UT71A (UT-D02 cable)", "2400/7o1/rts=0/dtr=1", | |
347 | 2400, UT71X_PACKET_SIZE, 0, 0, NULL, | |
348 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL, | |
349 | &uni_t_ut71a_ser_driver_info, receive_data_UNI_T_UT71A_SER, | |
350 | }, | |
351 | { | |
352 | "UNI-T", "UT71B (UT-D02 cable)", "2400/7o1/rts=0/dtr=1", | |
353 | 2400, UT71X_PACKET_SIZE, 0, 0, NULL, | |
354 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL, | |
355 | &uni_t_ut71b_ser_driver_info, receive_data_UNI_T_UT71B_SER, | |
356 | }, | |
357 | { | |
358 | "UNI-T", "UT71C (UT-D02 cable)", "2400/7o1/rts=0/dtr=1", | |
359 | 2400, UT71X_PACKET_SIZE, 0, 0, NULL, | |
360 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL, | |
361 | &uni_t_ut71c_ser_driver_info, receive_data_UNI_T_UT71C_SER, | |
362 | }, | |
363 | { | |
364 | "UNI-T", "UT71D (UT-D02 cable)", "2400/7o1/rts=0/dtr=1", | |
365 | 2400, UT71X_PACKET_SIZE, 0, 0, NULL, | |
366 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL, | |
367 | &uni_t_ut71d_ser_driver_info, receive_data_UNI_T_UT71D_SER, | |
368 | }, | |
369 | { | |
370 | "UNI-T", "UT71E (UT-D02 cable)", "2400/7o1/rts=0/dtr=1", | |
371 | 2400, UT71X_PACKET_SIZE, 0, 0, NULL, | |
372 | sr_ut71x_packet_valid, sr_ut71x_parse, NULL, | |
373 | &uni_t_ut71e_ser_driver_info, receive_data_UNI_T_UT71E_SER, | |
374 | }, | |
375 | { | |
376 | "ISO-TECH", "IDM103N", "2400/7o1/rts=0/dtr=1", | |
377 | 2400, ES519XX_11B_PACKET_SIZE, 0, 0, NULL, | |
378 | sr_es519xx_2400_11b_packet_valid, sr_es519xx_2400_11b_parse, | |
379 | NULL, | |
380 | &iso_tech_idm103n_driver_info, receive_data_ISO_TECH_IDM103N, | |
381 | }, | |
382 | { | |
383 | "Tenma", "72-7745 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
384 | 2400, FS9721_PACKET_SIZE, 0, 0, NULL, | |
385 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
386 | sr_fs9721_00_temp_c, | |
387 | &tenma_72_7745_ser_driver_info, receive_data_TENMA_72_7745_SER, | |
388 | }, | |
389 | { | |
390 | /* Note: ES51986 baudrate is actually 19230! */ | |
391 | "Tenma", "72-7750 (UT-D02 cable)", "19200/7o1/rts=0/dtr=1", | |
392 | 19200, ES519XX_11B_PACKET_SIZE, 0, 0, NULL, | |
393 | sr_es519xx_19200_11b_packet_valid, sr_es519xx_19200_11b_parse, | |
394 | NULL, | |
395 | &tenma_72_7750_ser_driver_info, receive_data_TENMA_72_7750_SER, | |
396 | }, | |
397 | { | |
398 | "Brymen", "BM25x", "9600/8n1/rts=1/dtr=1", | |
399 | 9600, BRYMEN_BM25X_PACKET_SIZE, 0, 0, NULL, | |
400 | sr_brymen_bm25x_packet_valid, sr_brymen_bm25x_parse, | |
401 | NULL, | |
402 | &brymen_bm25x_driver_info, receive_data_BRYMEN_BM25X, | |
403 | }, | |
404 | }; | |
405 | ||
406 | static int dev_clear(int dmm) | |
407 | { | |
408 | return std_dev_clear(dmms[dmm].di, NULL); | |
409 | } | |
410 | ||
411 | static int init(struct sr_context *sr_ctx, int dmm) | |
412 | { | |
413 | return std_init(sr_ctx, dmms[dmm].di, LOG_PREFIX); | |
414 | } | |
415 | ||
416 | static GSList *sdmm_scan(const char *conn, const char *serialcomm, int dmm) | |
417 | { | |
418 | struct sr_dev_inst *sdi; | |
419 | struct drv_context *drvc; | |
420 | struct dev_context *devc; | |
421 | struct sr_serial_dev_inst *serial; | |
422 | GSList *devices; | |
423 | int dropped, ret; | |
424 | size_t len; | |
425 | uint8_t buf[128]; | |
426 | ||
427 | serial = sr_serial_dev_inst_new(conn, serialcomm); | |
428 | ||
429 | if (serial_open(serial, SERIAL_RDWR) != SR_OK) | |
430 | return NULL; | |
431 | ||
432 | sr_info("Probing serial port %s.", conn); | |
433 | ||
434 | drvc = dmms[dmm].di->priv; | |
435 | devices = NULL; | |
436 | serial_flush(serial); | |
437 | ||
438 | /* Request a packet if the DMM requires this. */ | |
439 | if (dmms[dmm].packet_request) { | |
440 | if ((ret = dmms[dmm].packet_request(serial)) < 0) { | |
441 | sr_err("Failed to request packet: %d.", ret); | |
442 | return FALSE; | |
443 | } | |
444 | } | |
445 | ||
446 | /* | |
447 | * There's no way to get an ID from the multimeter. It just sends data | |
448 | * periodically (or upon request), so the best we can do is check if | |
449 | * the packets match the expected format. | |
450 | */ | |
451 | ||
452 | /* Let's get a bit of data and see if we can find a packet. */ | |
453 | len = sizeof(buf); | |
454 | ret = serial_stream_detect(serial, buf, &len, dmms[dmm].packet_size, | |
455 | dmms[dmm].packet_valid, 3000, | |
456 | dmms[dmm].baudrate); | |
457 | if (ret != SR_OK) | |
458 | goto scan_cleanup; | |
459 | ||
460 | /* | |
461 | * If we dropped more than two packets worth of data, something is | |
462 | * wrong. We shouldn't quit however, since the dropped bytes might be | |
463 | * just zeroes at the beginning of the stream. Those can occur as a | |
464 | * combination of the nonstandard cable that ships with some devices | |
465 | * and the serial port or USB to serial adapter. | |
466 | */ | |
467 | dropped = len - dmms[dmm].packet_size; | |
468 | if (dropped > 2 * dmms[dmm].packet_size) | |
469 | sr_warn("Had to drop too much data."); | |
470 | ||
471 | sr_info("Found device on port %s.", conn); | |
472 | ||
473 | sdi = g_malloc0(sizeof(struct sr_dev_inst)); | |
474 | sdi->status = SR_ST_INACTIVE; | |
475 | sdi->vendor = g_strdup(dmms[dmm].vendor); | |
476 | sdi->model = g_strdup(dmms[dmm].device); | |
477 | devc = g_malloc0(sizeof(struct dev_context)); | |
478 | sdi->inst_type = SR_INST_SERIAL; | |
479 | sdi->conn = serial; | |
480 | sdi->priv = devc; | |
481 | sdi->driver = dmms[dmm].di; | |
482 | sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); | |
483 | drvc->instances = g_slist_append(drvc->instances, sdi); | |
484 | devices = g_slist_append(devices, sdi); | |
485 | ||
486 | scan_cleanup: | |
487 | serial_close(serial); | |
488 | ||
489 | return devices; | |
490 | } | |
491 | ||
492 | static GSList *scan(GSList *options, int dmm) | |
493 | { | |
494 | struct sr_config *src; | |
495 | GSList *l, *devices; | |
496 | const char *conn, *serialcomm; | |
497 | ||
498 | conn = serialcomm = NULL; | |
499 | for (l = options; l; l = l->next) { | |
500 | src = l->data; | |
501 | switch (src->key) { | |
502 | case SR_CONF_CONN: | |
503 | conn = g_variant_get_string(src->data, NULL); | |
504 | break; | |
505 | case SR_CONF_SERIALCOMM: | |
506 | serialcomm = g_variant_get_string(src->data, NULL); | |
507 | break; | |
508 | } | |
509 | } | |
510 | if (!conn) | |
511 | return NULL; | |
512 | ||
513 | if (serialcomm) { | |
514 | /* Use the provided comm specs. */ | |
515 | devices = sdmm_scan(conn, serialcomm, dmm); | |
516 | } else { | |
517 | /* Try the default. */ | |
518 | devices = sdmm_scan(conn, dmms[dmm].conn, dmm); | |
519 | } | |
520 | ||
521 | return devices; | |
522 | } | |
523 | ||
524 | static GSList *dev_list(int dmm) | |
525 | { | |
526 | return ((struct drv_context *)(dmms[dmm].di->priv))->instances; | |
527 | } | |
528 | ||
529 | static int cleanup(int dmm) | |
530 | { | |
531 | return dev_clear(dmm); | |
532 | } | |
533 | ||
534 | static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, | |
535 | const struct sr_channel_group *cg) | |
536 | { | |
537 | struct dev_context *devc; | |
538 | ||
539 | (void)cg; | |
540 | ||
541 | if (sdi->status != SR_ST_ACTIVE) | |
542 | return SR_ERR_DEV_CLOSED; | |
543 | ||
544 | if (!(devc = sdi->priv)) { | |
545 | sr_err("sdi->priv was NULL."); | |
546 | return SR_ERR_BUG; | |
547 | } | |
548 | ||
549 | switch (key) { | |
550 | case SR_CONF_LIMIT_SAMPLES: | |
551 | devc->limit_samples = g_variant_get_uint64(data); | |
552 | sr_dbg("Setting sample limit to %" PRIu64 ".", | |
553 | devc->limit_samples); | |
554 | break; | |
555 | case SR_CONF_LIMIT_MSEC: | |
556 | devc->limit_msec = g_variant_get_uint64(data); | |
557 | sr_dbg("Setting time limit to %" PRIu64 "ms.", | |
558 | devc->limit_msec); | |
559 | break; | |
560 | default: | |
561 | return SR_ERR_NA; | |
562 | } | |
563 | ||
564 | return SR_OK; | |
565 | } | |
566 | ||
567 | static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, | |
568 | const struct sr_channel_group *cg) | |
569 | { | |
570 | (void)sdi; | |
571 | (void)cg; | |
572 | ||
573 | switch (key) { | |
574 | case SR_CONF_SCAN_OPTIONS: | |
575 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, | |
576 | scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); | |
577 | break; | |
578 | case SR_CONF_DEVICE_OPTIONS: | |
579 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, | |
580 | devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); | |
581 | break; | |
582 | default: | |
583 | return SR_ERR_NA; | |
584 | } | |
585 | ||
586 | return SR_OK; | |
587 | } | |
588 | ||
589 | static int dev_acquisition_start(const struct sr_dev_inst *sdi, | |
590 | void *cb_data, int dmm) | |
591 | { | |
592 | struct dev_context *devc; | |
593 | struct sr_serial_dev_inst *serial; | |
594 | ||
595 | if (sdi->status != SR_ST_ACTIVE) | |
596 | return SR_ERR_DEV_CLOSED; | |
597 | ||
598 | if (!(devc = sdi->priv)) { | |
599 | sr_err("sdi->priv was NULL."); | |
600 | return SR_ERR_BUG; | |
601 | } | |
602 | ||
603 | devc->cb_data = cb_data; | |
604 | ||
605 | /* | |
606 | * Reset the number of samples to take. If we've already collected our | |
607 | * quota, but we start a new session, and don't reset this, we'll just | |
608 | * quit without acquiring any new samples. | |
609 | */ | |
610 | devc->num_samples = 0; | |
611 | devc->starttime = g_get_monotonic_time(); | |
612 | ||
613 | /* Send header packet to the session bus. */ | |
614 | std_session_send_df_header(cb_data, LOG_PREFIX); | |
615 | ||
616 | /* Poll every 50ms, or whenever some data comes in. */ | |
617 | serial = sdi->conn; | |
618 | serial_source_add(sdi->session, serial, G_IO_IN, 50, | |
619 | dmms[dmm].receive_data, (void *)sdi); | |
620 | ||
621 | return SR_OK; | |
622 | } | |
623 | ||
624 | static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) | |
625 | { | |
626 | return std_serial_dev_acquisition_stop(sdi, cb_data, std_serial_dev_close, | |
627 | sdi->conn, LOG_PREFIX); | |
628 | } | |
629 | ||
630 | /* Driver-specific API function wrappers */ | |
631 | #define HW_INIT(X) \ | |
632 | static int init_##X(struct sr_context *sr_ctx) { return init(sr_ctx, X); } | |
633 | #define HW_CLEANUP(X) \ | |
634 | static int cleanup_##X(void) { return cleanup(X); } | |
635 | #define HW_SCAN(X) \ | |
636 | static GSList *scan_##X(GSList *options) { return scan(options, X); } | |
637 | #define HW_DEV_LIST(X) \ | |
638 | static GSList *dev_list_##X(void) { return dev_list(X); } | |
639 | #define HW_DEV_CLEAR(X) \ | |
640 | static int dev_clear_##X(void) { return dev_clear(X); } | |
641 | #define HW_DEV_ACQUISITION_START(X) \ | |
642 | static int dev_acquisition_start_##X(const struct sr_dev_inst *sdi, \ | |
643 | void *cb_data) { return dev_acquisition_start(sdi, cb_data, X); } | |
644 | ||
645 | /* Driver structs and API function wrappers */ | |
646 | #define DRV(ID, ID_UPPER, NAME, LONGNAME) \ | |
647 | HW_INIT(ID_UPPER) \ | |
648 | HW_CLEANUP(ID_UPPER) \ | |
649 | HW_SCAN(ID_UPPER) \ | |
650 | HW_DEV_LIST(ID_UPPER) \ | |
651 | HW_DEV_CLEAR(ID_UPPER) \ | |
652 | HW_DEV_ACQUISITION_START(ID_UPPER) \ | |
653 | SR_PRIV struct sr_dev_driver ID##_driver_info = { \ | |
654 | .name = NAME, \ | |
655 | .longname = LONGNAME, \ | |
656 | .api_version = 1, \ | |
657 | .init = init_##ID_UPPER, \ | |
658 | .cleanup = cleanup_##ID_UPPER, \ | |
659 | .scan = scan_##ID_UPPER, \ | |
660 | .dev_list = dev_list_##ID_UPPER, \ | |
661 | .dev_clear = dev_clear_##ID_UPPER, \ | |
662 | .config_get = NULL, \ | |
663 | .config_set = config_set, \ | |
664 | .config_list = config_list, \ | |
665 | .dev_open = std_serial_dev_open, \ | |
666 | .dev_close = std_serial_dev_close, \ | |
667 | .dev_acquisition_start = dev_acquisition_start_##ID_UPPER, \ | |
668 | .dev_acquisition_stop = dev_acquisition_stop, \ | |
669 | .priv = NULL, \ | |
670 | }; | |
671 | ||
672 | DRV(bbcgm_m2110, BBCGM_M2110, "bbcgm-m2110", "BBC Goertz Metrawatt M2110") | |
673 | DRV(digitek_dt4000zc, DIGITEK_DT4000ZC, "digitek-dt4000zc", "Digitek DT4000ZC") | |
674 | DRV(tekpower_tp4000zc, TEKPOWER_TP4000ZC, "tekpower-tp4000zc", "TekPower TP4000ZC") | |
675 | DRV(metex_me31, METEX_ME31, "metex-me31", "Metex ME-31") | |
676 | DRV(peaktech_3410, PEAKTECH_3410, "peaktech-3410", "PeakTech 3410") | |
677 | DRV(mastech_mas345, MASTECH_MAS345, "mastech-mas345", "MASTECH MAS345") | |
678 | DRV(mastech_ms8250b, MASTECH_MS8250B, "mastech-ms8250b", "MASTECH MS8250B") | |
679 | DRV(va_va18b, VA_VA18B, "va-va18b", "V&A VA18B") | |
680 | DRV(va_va40b, VA_VA40B, "va-va40b", "V&A VA40B") | |
681 | DRV(metex_m3640d, METEX_M3640D, "metex-m3640d", "Metex M-3640D") | |
682 | DRV(metex_m4650cr, METEX_M4650CR, "metex-m4650cr", "Metex M-4650CR") | |
683 | DRV(peaktech_4370, PEAKTECH_4370, "peaktech-4370", "PeakTech 4370") | |
684 | DRV(pce_pce_dm32, PCE_PCE_DM32, "pce-pce-dm32", "PCE PCE-DM32") | |
685 | DRV(radioshack_22_168, RADIOSHACK_22_168, "radioshack-22-168", "RadioShack 22-168") | |
686 | DRV(radioshack_22_805, RADIOSHACK_22_805, "radioshack-22-805", "RadioShack 22-805") | |
687 | DRV(radioshack_22_812, RADIOSHACK_22_812, "radioshack-22-812", "RadioShack 22-812") | |
688 | DRV(tecpel_dmm_8061_ser, TECPEL_DMM_8061_SER, "tecpel-dmm-8061-ser", "Tecpel DMM-8061 (UT-D02 cable)") | |
689 | DRV(voltcraft_m3650cr, VOLTCRAFT_M3650CR, "voltcraft-m3650cr", "Voltcraft M-3650CR") | |
690 | DRV(voltcraft_m3650d, VOLTCRAFT_M3650D, "voltcraft-m3650d", "Voltcraft M-3650D") | |
691 | DRV(voltcraft_m4650cr, VOLTCRAFT_M4650CR, "voltcraft-m4650cr", "Voltcraft M-4650CR") | |
692 | DRV(voltcraft_me42, VOLTCRAFT_ME42, "voltcraft-me42", "Voltcraft ME-42") | |
693 | DRV(voltcraft_vc820_ser, VOLTCRAFT_VC820_SER, "voltcraft-vc820-ser", "Voltcraft VC-820 (UT-D02 cable)") | |
694 | DRV(voltcraft_vc830_ser, VOLTCRAFT_VC830_SER, "voltcraft-vc830-ser", "Voltcraft VC-830 (UT-D02 cable)") | |
695 | DRV(voltcraft_vc840_ser, VOLTCRAFT_VC840_SER, "voltcraft-vc840-ser", "Voltcraft VC-840 (UT-D02 cable)") | |
696 | DRV(voltcraft_vc870_ser, VOLTCRAFT_VC870_SER, "voltcraft-vc870-ser", "Voltcraft VC-870 (UT-D02 cable)") | |
697 | DRV(voltcraft_vc920_ser, VOLTCRAFT_VC920_SER, "voltcraft-vc920-ser", "Voltcraft VC-920 (UT-D02 cable)") | |
698 | DRV(voltcraft_vc940_ser, VOLTCRAFT_VC940_SER, "voltcraft-vc940-ser", "Voltcraft VC-940 (UT-D02 cable)") | |
699 | DRV(voltcraft_vc960_ser, VOLTCRAFT_VC960_SER, "voltcraft-vc960-ser", "Voltcraft VC-960 (UT-D02 cable)") | |
700 | DRV(uni_t_ut60a_ser, UNI_T_UT60A_SER, "uni-t-ut60a-ser", "UNI-T UT60A (UT-D02 cable)") | |
701 | DRV(uni_t_ut60e_ser, UNI_T_UT60E_SER, "uni-t-ut60e-ser", "UNI-T UT60E (UT-D02 cable)") | |
702 | DRV(uni_t_ut60g_ser, UNI_T_UT60G_SER, "uni-t-ut60g-ser", "UNI-T UT60G (UT-D02 cable)") | |
703 | DRV(uni_t_ut61b_ser, UNI_T_UT61B_SER, "uni-t-ut61b-ser", "UNI-T UT61B (UT-D02 cable)") | |
704 | DRV(uni_t_ut61c_ser, UNI_T_UT61C_SER, "uni-t-ut61c-ser", "UNI-T UT61C (UT-D02 cable)") | |
705 | DRV(uni_t_ut61d_ser, UNI_T_UT61D_SER, "uni-t-ut61d-ser", "UNI-T UT61D (UT-D02 cable)") | |
706 | DRV(uni_t_ut61e_ser, UNI_T_UT61E_SER, "uni-t-ut61e-ser", "UNI-T UT61E (UT-D02 cable)") | |
707 | DRV(uni_t_ut71a_ser, UNI_T_UT71A_SER, "uni-t-ut71a-ser", "UNI-T UT71A (UT-D02 cable)") | |
708 | DRV(uni_t_ut71b_ser, UNI_T_UT71B_SER, "uni-t-ut71b-ser", "UNI-T UT71B (UT-D02 cable)") | |
709 | DRV(uni_t_ut71c_ser, UNI_T_UT71C_SER, "uni-t-ut71c-ser", "UNI-T UT71C (UT-D02 cable)") | |
710 | DRV(uni_t_ut71d_ser, UNI_T_UT71D_SER, "uni-t-ut71d-ser", "UNI-T UT71D (UT-D02 cable)") | |
711 | DRV(uni_t_ut71e_ser, UNI_T_UT71E_SER, "uni-t-ut71e-ser", "UNI-T UT71E (UT-D02 cable)") | |
712 | DRV(iso_tech_idm103n, ISO_TECH_IDM103N, "iso-tech-idm103n", "ISO-TECH IDM103N") | |
713 | DRV(tenma_72_7745_ser, TENMA_72_7745_SER, "tenma-72-7745-ser", "Tenma 72-7745 (UT-D02 cable)") | |
714 | DRV(tenma_72_7750_ser, TENMA_72_7750_SER, "tenma-72-7750-ser", "Tenma 72-7750 (UT-D02 cable)") | |
715 | DRV(brymen_bm25x, BRYMEN_BM25X, "brymen-bm25x", "Brymen BM25x") |