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