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