]>
Commit | Line | Data |
---|---|---|
7b4edcb6 MH |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
c90beca7 | 4 | * Copyright (C) 2013, 2014 Matthias Heidbrink <m-sigrok@heidbrink.biz> |
7b4edcb6 MH |
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 3 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, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
6392d599 MH |
20 | /** @file |
21 | * Gossen Metrawatt Metrahit 1x/2x drivers | |
c90beca7 | 22 | * @internal |
6392d599 MH |
23 | */ |
24 | ||
f5792417 | 25 | #include <string.h> |
7b4edcb6 MH |
26 | #include "protocol.h" |
27 | ||
f5792417 MH |
28 | /* Serial communication parameters for Metrahit 1x/2x with 'RS232' adaptor */ |
29 | #define SERIALCOMM_1X_RS232 "8228/6n1/dtr=1/rts=1/flow=0" /* =8192, closer with divider */ | |
30 | #define SERIALCOMM_2X_RS232 "9600/6n1/dtr=1/rts=1/flow=0" | |
6392d599 | 31 | #define SERIALCOMM_2X "9600/8n1/dtr=1/rts=1/flow=0" |
f5792417 MH |
32 | #define VENDOR_GMC "Gossen Metrawatt" |
33 | ||
7b4edcb6 | 34 | SR_PRIV struct sr_dev_driver gmc_mh_1x_2x_rs232_driver_info; |
c90beca7 | 35 | SR_PRIV struct sr_dev_driver gmc_mh_2x_bd232_driver_info; |
7b4edcb6 | 36 | |
a0e0bb41 | 37 | static const uint32_t scanopts[] = { |
f5792417 MH |
38 | SR_CONF_CONN, |
39 | SR_CONF_SERIALCOMM, | |
40 | }; | |
41 | ||
c90beca7 | 42 | /** Hardware capabilities for Metrahit 1x/2x devices in send mode. */ |
f254bc4b | 43 | static const uint32_t devopts_sm[] = { |
f5792417 | 44 | SR_CONF_MULTIMETER, |
6392d599 | 45 | SR_CONF_THERMOMETER, /**< All GMC 1x/2x multimeters seem to support this */ |
f5792417 | 46 | SR_CONF_CONTINUOUS, |
5827f61b BV |
47 | SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, |
48 | SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET, | |
f5792417 MH |
49 | }; |
50 | ||
c90beca7 | 51 | /** Hardware capabilities for Metrahit 2x devices in bidirectional Mode. */ |
f254bc4b | 52 | static const uint32_t devopts_bd[] = { |
c90beca7 MH |
53 | SR_CONF_MULTIMETER, |
54 | SR_CONF_THERMOMETER, /**< All GMC 1x/2x multimeters seem to support this */ | |
c90beca7 | 55 | SR_CONF_CONTINUOUS, |
5827f61b BV |
56 | SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, |
57 | SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET, | |
58 | SR_CONF_POWER_OFF | SR_CONF_GET | SR_CONF_SET, | |
c90beca7 MH |
59 | }; |
60 | ||
61 | ||
6392d599 MH |
62 | /* TODO: |
63 | * - For the 29S SR_CONF_ENERGYMETER, too. | |
64 | * - SR_CONF_PATTERN_MODE for some 2x devices | |
65 | * - SR_CONF_DATALOG for 22M, 26M, 29S and storage adaptors. | |
66 | * Need to implement device-specific lists. | |
67 | */ | |
68 | ||
69 | /** Init driver gmc_mh_1x_2x_rs232. */ | |
c90beca7 MH |
70 | static int init_1x_2x_rs232(struct sr_context *sr_ctx) |
71 | { | |
72 | return std_init(sr_ctx, &gmc_mh_1x_2x_rs232_driver_info, LOG_PREFIX); | |
73 | } | |
74 | ||
75 | /** Init driver gmc_mh_2x_bd232. */ | |
76 | static int init_2x_bd232(struct sr_context *sr_ctx) | |
7b4edcb6 | 77 | { |
c90beca7 | 78 | return std_init(sr_ctx, &gmc_mh_2x_bd232_driver_info, LOG_PREFIX); |
7b4edcb6 MH |
79 | } |
80 | ||
fc348b77 UH |
81 | /** |
82 | * Read single byte from serial port. | |
83 | * | |
84 | * @retval -1 Timeout or error. | |
85 | * @retval other Byte. | |
f5792417 MH |
86 | */ |
87 | static int read_byte(struct sr_serial_dev_inst *serial, gint64 timeout) | |
7b4edcb6 | 88 | { |
fc348b77 | 89 | uint8_t result = 0; |
f5792417 MH |
90 | int rc = 0; |
91 | ||
92 | for (;;) { | |
0714a010 | 93 | rc = serial_read_nonblocking(serial, &result, 1); |
f5792417 MH |
94 | if (rc == 1) { |
95 | sr_spew("read: 0x%02x/%d", result, result); | |
96 | return result; | |
97 | } | |
98 | if (g_get_monotonic_time() > timeout) | |
99 | return -1; | |
100 | g_usleep(2000); | |
101 | } | |
102 | } | |
103 | ||
fc348b77 UH |
104 | /** |
105 | * Try to detect GMC 1x/2x multimeter model in send mode for max. 1 second. | |
f5792417 | 106 | * |
fc348b77 UH |
107 | * @param serial Configured, open serial port. |
108 | * | |
109 | * @retval NULL Detection failed. | |
110 | * @retval other Model code. | |
f5792417 MH |
111 | */ |
112 | static enum model scan_model_sm(struct sr_serial_dev_inst *serial) | |
113 | { | |
114 | int byte, bytecnt, cnt; | |
115 | enum model model; | |
116 | gint64 timeout_us; | |
117 | ||
873e0c12 | 118 | model = METRAHIT_NONE; |
fc348b77 | 119 | timeout_us = g_get_monotonic_time() + 1 * 1000 * 1000; |
f5792417 | 120 | |
fc348b77 UH |
121 | /* |
122 | * Try to find message consisting of device code and several | |
123 | * (at least 4) data bytes. | |
124 | */ | |
f5792417 MH |
125 | for (bytecnt = 0; bytecnt < 100; bytecnt++) { |
126 | byte = read_byte(serial, timeout_us); | |
127 | if ((byte == -1) || (timeout_us < g_get_monotonic_time())) | |
128 | break; | |
129 | if ((byte & MSGID_MASK) == MSGID_INF) { | |
873e0c12 | 130 | if (!(model = gmc_decode_model_sm(byte & MSGC_MASK))) |
f5792417 | 131 | break; |
fc348b77 | 132 | /* Now expect (at least) 4 data bytes. */ |
f5792417 MH |
133 | for (cnt = 0; cnt < 4; cnt++) { |
134 | byte = read_byte(serial, timeout_us); | |
135 | if ((byte == -1) || | |
c90beca7 | 136 | ((byte & MSGID_MASK) != MSGID_DATA)) |
f5792417 | 137 | { |
873e0c12 | 138 | model = METRAHIT_NONE; |
f5792417 MH |
139 | bytecnt = 100; |
140 | break; | |
141 | } | |
142 | } | |
143 | break; | |
144 | } | |
145 | } | |
7b4edcb6 | 146 | |
f5792417 MH |
147 | return model; |
148 | } | |
149 | ||
fc348b77 UH |
150 | /** |
151 | * Scan for Metrahit 1x and Metrahit 2x in send mode using Gossen Metrawatt | |
152 | * 'RS232' interface. | |
153 | * | |
154 | * The older 1x models use 8192 baud and the newer 2x 9600 baud. | |
155 | * The DMM usually sends up to about 20 messages per second. However, depending | |
156 | * on configuration and measurement mode the intervals can be much larger and | |
157 | * then the detection might not work. | |
f5792417 | 158 | */ |
c90beca7 | 159 | static GSList *scan_1x_2x_rs232(GSList *options) |
f5792417 MH |
160 | { |
161 | struct sr_dev_inst *sdi; | |
162 | struct drv_context *drvc; | |
163 | struct dev_context *devc; | |
164 | struct sr_config *src; | |
ba7dd8bb | 165 | struct sr_channel *ch; |
f5792417 MH |
166 | struct sr_serial_dev_inst *serial; |
167 | GSList *l, *devices; | |
168 | const char *conn, *serialcomm; | |
169 | enum model model; | |
170 | gboolean serialcomm_given; | |
7b4edcb6 MH |
171 | |
172 | devices = NULL; | |
6392d599 | 173 | drvc = (&gmc_mh_1x_2x_rs232_driver_info)->priv; |
7b4edcb6 | 174 | drvc->instances = NULL; |
f5792417 | 175 | conn = serialcomm = NULL; |
873e0c12 | 176 | model = METRAHIT_NONE; |
f5792417 MH |
177 | serialcomm_given = FALSE; |
178 | ||
c90beca7 | 179 | sr_spew("scan_1x_2x_rs232() called!"); |
f5792417 MH |
180 | |
181 | for (l = options; l; l = l->next) { | |
182 | src = l->data; | |
183 | switch (src->key) { | |
184 | case SR_CONF_CONN: | |
185 | conn = g_variant_get_string(src->data, NULL); | |
186 | break; | |
187 | case SR_CONF_SERIALCOMM: | |
188 | serialcomm = g_variant_get_string(src->data, NULL); | |
189 | serialcomm_given = TRUE; | |
190 | break; | |
191 | } | |
192 | } | |
193 | if (!conn) | |
194 | return NULL; | |
195 | if (!serialcomm) | |
196 | serialcomm = SERIALCOMM_2X_RS232; | |
197 | ||
91219afc | 198 | serial = sr_serial_dev_inst_new(conn, serialcomm); |
f5792417 | 199 | |
e13e354f | 200 | if (serial_open(serial, SERIAL_RDWR) != SR_OK) { |
f5792417 MH |
201 | sr_serial_dev_inst_free(serial); |
202 | return NULL; | |
203 | } | |
7b4edcb6 | 204 | |
f5792417 MH |
205 | serial_flush(serial); |
206 | ||
207 | model = scan_model_sm(serial); | |
208 | ||
fc348b77 UH |
209 | /* |
210 | * If detection failed and no user-supplied parameters, | |
211 | * try second baud rate. | |
212 | */ | |
873e0c12 | 213 | if ((model == METRAHIT_NONE) && !serialcomm_given) { |
f5792417 MH |
214 | serialcomm = SERIALCOMM_1X_RS232; |
215 | g_free(serial->serialcomm); | |
216 | serial->serialcomm = g_strdup(serialcomm); | |
217 | if (serial_set_paramstr(serial, serialcomm) == SR_OK) { | |
218 | serial_flush(serial); | |
219 | model = scan_model_sm(serial); | |
220 | } | |
221 | } | |
222 | ||
873e0c12 UH |
223 | if (model != METRAHIT_NONE) { |
224 | sr_spew("%s %s detected!", VENDOR_GMC, gmc_model_str(model)); | |
aac29cc1 | 225 | sdi = g_malloc0(sizeof(struct sr_dev_inst)); |
0af636be UH |
226 | sdi->status = SR_ST_INACTIVE; |
227 | sdi->vendor = g_strdup(VENDOR_GMC); | |
228 | sdi->model = g_strdup(gmc_model_str(model)); | |
f57d8ffe | 229 | devc = g_malloc0(sizeof(struct dev_context)); |
f5792417 MH |
230 | devc->model = model; |
231 | devc->limit_samples = 0; | |
232 | devc->limit_msec = 0; | |
233 | devc->num_samples = 0; | |
234 | devc->elapsed_msec = g_timer_new(); | |
235 | devc->settings_ok = FALSE; | |
f5792417 MH |
236 | sdi->conn = serial; |
237 | sdi->priv = devc; | |
6392d599 | 238 | sdi->driver = &gmc_mh_1x_2x_rs232_driver_info; |
c368e6f3 | 239 | ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); |
ba7dd8bb | 240 | sdi->channels = g_slist_append(sdi->channels, ch); |
f5792417 MH |
241 | drvc->instances = g_slist_append(drvc->instances, sdi); |
242 | devices = g_slist_append(devices, sdi); | |
243 | } | |
7b4edcb6 MH |
244 | |
245 | return devices; | |
246 | } | |
247 | ||
c90beca7 MH |
248 | /** Scan for Metrahit 2x in a bidirectional mode using Gossen Metrawatt 'BD 232' interface. |
249 | * | |
250 | */ | |
251 | static GSList *scan_2x_bd232(GSList *options) | |
252 | { | |
253 | struct sr_dev_inst *sdi; | |
254 | struct drv_context *drvc; | |
255 | struct dev_context *devc; | |
256 | struct sr_config *src; | |
ba7dd8bb | 257 | struct sr_channel *ch; |
c90beca7 MH |
258 | struct sr_serial_dev_inst *serial; |
259 | GSList *l, *devices; | |
260 | const char *conn, *serialcomm; | |
261 | int cnt, byte; | |
262 | gint64 timeout_us; | |
263 | ||
264 | sdi = NULL; | |
265 | devc = NULL; | |
266 | conn = serialcomm = NULL; | |
267 | devices = NULL; | |
268 | ||
269 | drvc = (&gmc_mh_2x_bd232_driver_info)->priv; | |
270 | drvc->instances = NULL; | |
271 | ||
272 | sr_spew("scan_2x_bd232() called!"); | |
273 | ||
274 | for (l = options; l; l = l->next) { | |
275 | src = l->data; | |
276 | switch (src->key) { | |
277 | case SR_CONF_CONN: | |
278 | conn = g_variant_get_string(src->data, NULL); | |
279 | break; | |
280 | case SR_CONF_SERIALCOMM: | |
281 | serialcomm = g_variant_get_string(src->data, NULL); | |
282 | break; | |
283 | } | |
284 | } | |
285 | if (!conn) | |
286 | return NULL; | |
287 | if (!serialcomm) | |
288 | serialcomm = SERIALCOMM_2X; | |
289 | ||
91219afc | 290 | serial = sr_serial_dev_inst_new(conn, serialcomm); |
c90beca7 | 291 | |
e13e354f | 292 | if (serial_open(serial, SERIAL_RDWR) != SR_OK) |
c90beca7 MH |
293 | goto exit_err; |
294 | ||
f57d8ffe | 295 | devc = g_malloc0(sizeof(struct dev_context)); |
c90beca7 | 296 | |
aac29cc1 | 297 | sdi = g_malloc0(sizeof(struct sr_dev_inst)); |
0af636be UH |
298 | sdi->status = SR_ST_INACTIVE; |
299 | sdi->vendor = g_strdup(VENDOR_GMC); | |
c90beca7 MH |
300 | sdi->priv = devc; |
301 | ||
302 | /* Send message 03 "Query multimeter version and status" */ | |
303 | sdi->conn = serial; | |
304 | sdi->priv = devc; | |
305 | if (req_stat14(sdi, TRUE) != SR_OK) | |
306 | goto exit_err; | |
307 | ||
308 | /* Wait for reply from device(s) for up to 2s. */ | |
309 | timeout_us = g_get_monotonic_time() + 2*1000*1000; | |
310 | ||
311 | while (timeout_us > g_get_monotonic_time()) { | |
312 | /* Receive reply (14 bytes) */ | |
313 | devc->buflen = 0; | |
314 | for (cnt = 0; cnt < 14; cnt++) { | |
315 | byte = read_byte(serial, timeout_us); | |
316 | if (byte != -1) | |
317 | devc->buf[devc->buflen++] = (byte & MASK_6BITS); | |
318 | } | |
319 | ||
320 | if (devc->buflen != 14) | |
321 | continue; | |
322 | ||
323 | devc->addr = devc->buf[0]; | |
324 | process_msg14(sdi); | |
325 | devc->buflen = 0; | |
326 | ||
327 | if (devc->model != METRAHIT_NONE) { | |
328 | sr_spew("%s %s detected!", VENDOR_GMC, gmc_model_str(devc->model)); | |
c90beca7 | 329 | devc->elapsed_msec = g_timer_new(); |
c90beca7 MH |
330 | sdi->model = g_strdup(gmc_model_str(devc->model)); |
331 | sdi->version = g_strdup_printf("Firmware %d.%d", devc->fw_ver_maj, devc->fw_ver_min); | |
332 | sdi->conn = serial; | |
333 | sdi->priv = devc; | |
334 | sdi->driver = &gmc_mh_2x_bd232_driver_info; | |
c368e6f3 | 335 | ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); |
ba7dd8bb | 336 | sdi->channels = g_slist_append(sdi->channels, ch); |
c90beca7 MH |
337 | drvc->instances = g_slist_append(drvc->instances, sdi); |
338 | devices = g_slist_append(devices, sdi); | |
f57d8ffe | 339 | devc = g_malloc0(sizeof(struct dev_context)); |
aac29cc1 | 340 | sdi = g_malloc0(sizeof(struct sr_dev_inst)); |
0af636be UH |
341 | sdi->status = SR_ST_INACTIVE; |
342 | sdi->vendor = g_strdup(VENDOR_GMC); | |
c90beca7 MH |
343 | } |
344 | }; | |
345 | ||
346 | /* Free last alloc if no device found */ | |
347 | if (devc->model == METRAHIT_NONE) { | |
348 | g_free(devc); | |
349 | sr_dev_inst_free(sdi); | |
350 | } | |
351 | ||
352 | return devices; | |
353 | ||
354 | exit_err: | |
355 | sr_info("scan_2x_bd232(): Error!"); | |
356 | ||
357 | if (serial) | |
358 | sr_serial_dev_inst_free(serial); | |
359 | if (devc) | |
360 | g_free(devc); | |
361 | if (sdi) | |
362 | sr_dev_inst_free(sdi); | |
363 | ||
364 | return NULL; | |
365 | } | |
366 | ||
367 | /** Driver device list function */ | |
368 | static GSList *dev_list_1x_2x_rs232(void) | |
369 | { | |
370 | return ((struct drv_context *)(gmc_mh_1x_2x_rs232_driver_info.priv))->instances; | |
371 | } | |
372 | ||
373 | /** Driver device list function */ | |
374 | static GSList *dev_list_2x_bd232(void) | |
7b4edcb6 | 375 | { |
c90beca7 MH |
376 | return ((struct drv_context *)(gmc_mh_2x_bd232_driver_info.priv)) |
377 | ->instances; | |
7b4edcb6 MH |
378 | } |
379 | ||
7b4edcb6 MH |
380 | static int dev_close(struct sr_dev_inst *sdi) |
381 | { | |
f5792417 | 382 | struct dev_context *devc; |
7b4edcb6 | 383 | |
bf2c987f | 384 | std_serial_dev_close(sdi); |
7b4edcb6 MH |
385 | |
386 | sdi->status = SR_ST_INACTIVE; | |
387 | ||
f5792417 MH |
388 | /* Free dynamically allocated resources. */ |
389 | if ((devc = sdi->priv) && devc->elapsed_msec) { | |
390 | g_timer_destroy(devc->elapsed_msec); | |
391 | devc->elapsed_msec = NULL; | |
873e0c12 | 392 | devc->model = METRAHIT_NONE; |
f5792417 MH |
393 | } |
394 | ||
7b4edcb6 MH |
395 | return SR_OK; |
396 | } | |
397 | ||
c90beca7 MH |
398 | static int cleanup_sm_rs232(void) |
399 | { | |
a6630742 | 400 | return std_dev_clear(&gmc_mh_1x_2x_rs232_driver_info, NULL); |
c90beca7 MH |
401 | } |
402 | ||
403 | static int cleanup_2x_bd232(void) | |
7b4edcb6 | 404 | { |
a6630742 | 405 | return std_dev_clear(&gmc_mh_2x_bd232_driver_info, NULL); |
7b4edcb6 MH |
406 | } |
407 | ||
6392d599 | 408 | /** Get value of configuration item */ |
584560f1 BV |
409 | static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
410 | const struct sr_channel_group *cg) | |
7b4edcb6 MH |
411 | { |
412 | int ret; | |
fadd0707 | 413 | struct dev_context *devc; |
c90beca7 | 414 | |
53b4680f | 415 | (void)cg; |
c90beca7 | 416 | |
6392d599 | 417 | ret = SR_OK; |
7b4edcb6 | 418 | |
6392d599 MH |
419 | if (!sdi || !(devc = sdi->priv)) |
420 | return SR_ERR_ARG; | |
421 | ||
7b4edcb6 MH |
422 | ret = SR_OK; |
423 | switch (key) { | |
6392d599 MH |
424 | case SR_CONF_LIMIT_SAMPLES: |
425 | *data = g_variant_new_uint64(devc->limit_samples); | |
426 | break; | |
427 | case SR_CONF_LIMIT_MSEC: | |
428 | *data = g_variant_new_uint64(devc->limit_msec); | |
429 | break; | |
c90beca7 MH |
430 | case SR_CONF_POWER_OFF: |
431 | *data = g_variant_new_boolean(FALSE); | |
432 | break; | |
7b4edcb6 MH |
433 | default: |
434 | return SR_ERR_NA; | |
435 | } | |
436 | ||
437 | return ret; | |
438 | } | |
439 | ||
c90beca7 | 440 | /** Implementation of config_list, auxiliary function for common parts, */ |
584560f1 BV |
441 | static int config_list_common(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
442 | const struct sr_channel_group *cg) | |
7b4edcb6 | 443 | { |
c90beca7 | 444 | (void)sdi; |
53b4680f | 445 | (void)cg; |
7b4edcb6 | 446 | |
7b4edcb6 | 447 | switch (key) { |
c90beca7 | 448 | case SR_CONF_SCAN_OPTIONS: |
584560f1 | 449 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
5827f61b | 450 | scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); |
f5792417 | 451 | break; |
7b4edcb6 | 452 | default: |
f5792417 | 453 | return SR_ERR_NA; |
7b4edcb6 MH |
454 | } |
455 | ||
f5792417 | 456 | return SR_OK; |
7b4edcb6 MH |
457 | } |
458 | ||
c90beca7 | 459 | /** Implementation of config_list for Metrahit 1x/2x send mode */ |
584560f1 | 460 | static int config_list_sm(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
53b4680f | 461 | const struct sr_channel_group *cg) |
7b4edcb6 | 462 | { |
7b4edcb6 | 463 | switch (key) { |
c90beca7 | 464 | case SR_CONF_DEVICE_OPTIONS: |
584560f1 | 465 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
5827f61b | 466 | devopts_sm, ARRAY_SIZE(devopts_sm), sizeof(uint32_t)); |
f5792417 | 467 | break; |
c90beca7 | 468 | default: |
53b4680f | 469 | return config_list_common(key, data, sdi, cg); |
c90beca7 MH |
470 | } |
471 | ||
472 | return SR_OK; | |
473 | } | |
474 | ||
475 | /** Implementation of config_list for Metrahit 2x bidirectional mode */ | |
584560f1 | 476 | static int config_list_bd(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
53b4680f | 477 | const struct sr_channel_group *cg) |
c90beca7 | 478 | { |
c90beca7 | 479 | switch (key) { |
f5792417 | 480 | case SR_CONF_DEVICE_OPTIONS: |
584560f1 | 481 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
5827f61b | 482 | devopts_bd, ARRAY_SIZE(devopts_bd), sizeof(uint32_t)); |
f5792417 | 483 | break; |
7b4edcb6 | 484 | default: |
53b4680f | 485 | return config_list_common(key, data, sdi, cg); |
7b4edcb6 MH |
486 | } |
487 | ||
f5792417 | 488 | return SR_OK; |
7b4edcb6 MH |
489 | } |
490 | ||
c90beca7 MH |
491 | static int dev_acquisition_start_1x_2x_rs232(const struct sr_dev_inst *sdi, |
492 | void *cb_data) | |
7b4edcb6 | 493 | { |
f5792417 MH |
494 | struct dev_context *devc; |
495 | struct sr_serial_dev_inst *serial; | |
496 | ||
497 | if (!sdi || !cb_data || !(devc = sdi->priv)) | |
498 | return SR_ERR_BUG; | |
7b4edcb6 MH |
499 | |
500 | if (sdi->status != SR_ST_ACTIVE) | |
501 | return SR_ERR_DEV_CLOSED; | |
502 | ||
f5792417 MH |
503 | devc->cb_data = cb_data; |
504 | devc->settings_ok = FALSE; | |
505 | devc->buflen = 0; | |
506 | ||
507 | /* Send header packet to the session bus. */ | |
508 | std_session_send_df_header(cb_data, LOG_PREFIX); | |
509 | ||
510 | /* Start timer, if required. */ | |
511 | if (devc->limit_msec) | |
512 | g_timer_start(devc->elapsed_msec); | |
513 | ||
514 | /* Poll every 40ms, or whenever some data comes in. */ | |
515 | serial = sdi->conn; | |
102f1239 BV |
516 | serial_source_add(sdi->session, serial, G_IO_IN, 40, |
517 | gmc_mh_1x_2x_receive_data, (void *)sdi); | |
7b4edcb6 MH |
518 | |
519 | return SR_OK; | |
520 | } | |
521 | ||
c90beca7 MH |
522 | static int dev_acquisition_start_2x_bd232(const struct sr_dev_inst *sdi, |
523 | void *cb_data) | |
524 | { | |
525 | struct dev_context *devc; | |
526 | struct sr_serial_dev_inst *serial; | |
527 | ||
528 | if (!sdi || !cb_data || !(devc = sdi->priv)) | |
529 | return SR_ERR_BUG; | |
530 | ||
531 | if (sdi->status != SR_ST_ACTIVE) | |
532 | return SR_ERR_DEV_CLOSED; | |
533 | ||
534 | devc->cb_data = cb_data; | |
535 | devc->settings_ok = FALSE; | |
536 | devc->buflen = 0; | |
537 | ||
538 | /* Send header packet to the session bus. */ | |
539 | std_session_send_df_header(cb_data, LOG_PREFIX); | |
540 | ||
541 | /* Start timer, if required. */ | |
542 | if (devc->limit_msec) | |
543 | g_timer_start(devc->elapsed_msec); | |
544 | ||
545 | /* Poll every 40ms, or whenever some data comes in. */ | |
546 | serial = sdi->conn; | |
102f1239 BV |
547 | serial_source_add(sdi->session, serial, G_IO_IN, 40, |
548 | gmc_mh_2x_receive_data, (void *)sdi); | |
c90beca7 MH |
549 | |
550 | /* Send start message */ | |
551 | return req_meas14(sdi); | |
552 | } | |
553 | ||
27fd2eaa | 554 | static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) |
7b4edcb6 | 555 | { |
f5792417 | 556 | struct dev_context *devc; |
7b4edcb6 | 557 | |
f5792417 MH |
558 | /* Stop timer, if required. */ |
559 | if (sdi && (devc = sdi->priv) && devc->limit_msec) | |
560 | g_timer_stop(devc->elapsed_msec); | |
7b4edcb6 | 561 | |
d43b0908 | 562 | return std_serial_dev_acquisition_stop(sdi, cb_data, dev_close, |
f5792417 | 563 | sdi->conn, LOG_PREFIX); |
7b4edcb6 MH |
564 | } |
565 | ||
566 | SR_PRIV struct sr_dev_driver gmc_mh_1x_2x_rs232_driver_info = { | |
567 | .name = "gmc-mh-1x-2x-rs232", | |
a90061e5 | 568 | .longname = "Gossen Metrawatt Metrahit 1x/2x, RS232 interface", |
7b4edcb6 | 569 | .api_version = 1, |
c90beca7 MH |
570 | .init = init_1x_2x_rs232, |
571 | .cleanup = cleanup_sm_rs232, | |
572 | .scan = scan_1x_2x_rs232, | |
573 | .dev_list = dev_list_1x_2x_rs232, | |
a6630742 | 574 | .dev_clear = NULL, |
c90beca7 MH |
575 | .config_get = config_get, |
576 | .config_set = config_set, | |
577 | .config_list = config_list_sm, | |
578 | .dev_open = std_serial_dev_open, | |
579 | .dev_close = dev_close, | |
580 | .dev_acquisition_start = dev_acquisition_start_1x_2x_rs232, | |
581 | .dev_acquisition_stop = dev_acquisition_stop, | |
582 | .priv = NULL, | |
583 | }; | |
584 | ||
585 | SR_PRIV struct sr_dev_driver gmc_mh_2x_bd232_driver_info = { | |
586 | .name = "gmc-mh-2x-bd232", | |
a90061e5 | 587 | .longname = "Gossen Metrawatt Metrahit 2x, BD232/SI232-II interface", |
c90beca7 MH |
588 | .api_version = 1, |
589 | .init = init_2x_bd232, | |
590 | .cleanup = cleanup_2x_bd232, | |
591 | .scan = scan_2x_bd232, | |
592 | .dev_list = dev_list_2x_bd232, | |
a6630742 | 593 | .dev_clear = NULL, |
7b4edcb6 MH |
594 | .config_get = config_get, |
595 | .config_set = config_set, | |
c90beca7 | 596 | .config_list = config_list_bd, |
854434de | 597 | .dev_open = std_serial_dev_open, |
7b4edcb6 | 598 | .dev_close = dev_close, |
c90beca7 | 599 | .dev_acquisition_start = dev_acquisition_start_2x_bd232, |
27fd2eaa | 600 | .dev_acquisition_stop = dev_acquisition_stop, |
7b4edcb6 MH |
601 | .priv = NULL, |
602 | }; |