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