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