]>
Commit | Line | Data |
---|---|---|
a1bb33af UH |
1 | /* |
2 | * This file is part of the sigrok project. | |
3 | * | |
c73d2ea4 | 4 | * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com> |
b19f4622 | 5 | * Copyright (C) 2010-2012 Uwe Hermann <uwe@hermann-uwe.de> |
a1bb33af UH |
6 | * |
7 | * This program is free software: you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation, either version 3 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | */ | |
20 | ||
54b38f64 | 21 | #include <string.h> |
d02a535e BV |
22 | #include <sys/types.h> |
23 | #include <sys/stat.h> | |
24 | #include <fcntl.h> | |
25 | #include <unistd.h> | |
926b866c | 26 | #ifdef _WIN32 |
a9f54bcd | 27 | #include <windows.h> |
926b866c UH |
28 | #else |
29 | #include <glob.h> | |
d02a535e | 30 | #include <termios.h> |
926b866c | 31 | #endif |
d02a535e | 32 | #include <stdlib.h> |
b19f4622 | 33 | #include <errno.h> |
a1bb33af | 34 | #include <glib.h> |
45c59c8b BV |
35 | #include "libsigrok.h" |
36 | #include "libsigrok-internal.h" | |
a1bb33af | 37 | |
b19f4622 UH |
38 | /* Message logging helpers with driver-specific prefix string. */ |
39 | #define DRIVER_LOG_DOMAIN "serial: " | |
40 | #define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args) | |
41 | #define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args) | |
42 | #define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args) | |
43 | #define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args) | |
44 | #define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args) | |
45 | #define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args) | |
46 | ||
926b866c UH |
47 | // FIXME: Must be moved, or rather passed as function argument. |
48 | #ifdef _WIN32 | |
a0ecd83b | 49 | static HANDLE hdl; |
926b866c UH |
50 | #endif |
51 | ||
b19f4622 UH |
52 | /** |
53 | * Open the specified serial port. | |
54 | * | |
55 | * @param pathname OS-specific serial port specification. Examples: | |
56 | * "/dev/ttyUSB0", "/dev/ttyACM1", "/dev/tty.Modem-0", "COM1". | |
57 | * @param flags Flags to use when opening the serial port. | |
58 | * | |
59 | * @return 0 upon success, -1 upon failure. | |
60 | */ | |
1a081ca6 | 61 | SR_PRIV int serial_open(const char *pathname, int flags) |
d02a535e | 62 | { |
b19f4622 UH |
63 | /* TODO: Abstract 'flags', currently they're OS-specific! */ |
64 | ||
65 | sr_dbg("Opening serial port '%s' (flags = %d).", pathname, flags); | |
66 | ||
926b866c | 67 | #ifdef _WIN32 |
b19f4622 UH |
68 | pathname = "COM1"; /* FIXME: Don't hardcode COM1. */ |
69 | ||
70 | hdl = CreateFile(pathname, GENERIC_READ | GENERIC_WRITE, 0, 0, | |
926b866c UH |
71 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
72 | if (hdl == INVALID_HANDLE_VALUE) { | |
b19f4622 UH |
73 | sr_err("Error opening serial port '%s'.", pathname); |
74 | return -1; | |
926b866c UH |
75 | } |
76 | return 0; | |
77 | #else | |
b19f4622 UH |
78 | int fd; |
79 | ||
80 | if ((fd = open(pathname, flags)) < 0) { | |
81 | /* | |
82 | * Should be sr_err(), but since some drivers try to open all | |
83 | * ports on a system and see if they succeed, this would | |
84 | * yield ugly output for e.g. "sigrok-cli -D". | |
85 | */ | |
86 | sr_dbg("Error opening serial port '%s': %s.", pathname, | |
87 | strerror(errno)); | |
83e3c368 UH |
88 | } else { |
89 | sr_dbg("Opened serial port '%s' as FD %d.", pathname, fd); | |
b19f4622 UH |
90 | } |
91 | ||
92 | return fd; | |
926b866c | 93 | #endif |
d02a535e BV |
94 | } |
95 | ||
b19f4622 UH |
96 | /** |
97 | * Close the specified serial port. | |
98 | * | |
99 | * @param fd File descriptor of the serial port. | |
100 | * | |
101 | * @return 0 upon success, -1 upon failure. | |
2119ab03 | 102 | */ |
1a081ca6 | 103 | SR_PRIV int serial_close(int fd) |
d02a535e | 104 | { |
b19f4622 UH |
105 | sr_dbg("FD %d: Closing serial port.", fd); |
106 | ||
926b866c | 107 | #ifdef _WIN32 |
2119ab03 UH |
108 | /* Returns non-zero upon success, 0 upon failure. */ |
109 | return (CloseHandle(hdl) == 0) ? -1 : 0; | |
926b866c | 110 | #else |
b19f4622 UH |
111 | int ret; |
112 | ||
2119ab03 | 113 | /* Returns 0 upon success, -1 upon failure. */ |
b19f4622 UH |
114 | if ((ret = close(fd)) < 0) { |
115 | sr_dbg("FD %d: Error closing serial port: %s.", | |
116 | fd, strerror(errno)); | |
117 | } | |
118 | ||
119 | return ret; | |
926b866c | 120 | #endif |
d02a535e BV |
121 | } |
122 | ||
b19f4622 | 123 | /** |
1fdb75e1 | 124 | * Flush serial port buffers (if any). |
b19f4622 UH |
125 | * |
126 | * @param fd File descriptor of the serial port. | |
127 | * | |
128 | * @return 0 upon success, -1 upon failure. | |
1fdb75e1 | 129 | */ |
1a081ca6 | 130 | SR_PRIV int serial_flush(int fd) |
06d64eb8 | 131 | { |
b19f4622 UH |
132 | sr_dbg("FD %d: Flushing serial port.", fd); |
133 | ||
1fdb75e1 UH |
134 | #ifdef _WIN32 |
135 | /* Returns non-zero upon success, 0 upon failure. */ | |
2119ab03 | 136 | return (PurgeComm(hdl, PURGE_RXCLEAR | PURGE_TXCLEAR) == 0) ? -1 : 0; |
1fdb75e1 | 137 | #else |
b19f4622 UH |
138 | int ret; |
139 | ||
1fdb75e1 | 140 | /* Returns 0 upon success, -1 upon failure. */ |
b19f4622 UH |
141 | if ((ret = tcflush(fd, TCIOFLUSH)) < 0) |
142 | sr_err("Error flushing serial port: %s.", strerror(errno)); | |
143 | ||
144 | return ret; | |
1fdb75e1 | 145 | #endif |
06d64eb8 BV |
146 | } |
147 | ||
b19f4622 | 148 | /** |
2119ab03 | 149 | * Write a number of bytes to the specified serial port. |
b19f4622 UH |
150 | * |
151 | * @param fd File descriptor of the serial port. | |
152 | * @param buf Buffer containing the bytes to write. | |
153 | * @param count Number of bytes to write. | |
154 | * | |
155 | * @return The number of bytes written, or -1 upon failure. | |
2119ab03 | 156 | */ |
1a081ca6 | 157 | SR_PRIV int serial_write(int fd, const void *buf, size_t count) |
2119ab03 UH |
158 | { |
159 | #ifdef _WIN32 | |
160 | DWORD tmp = 0; | |
161 | ||
162 | /* FIXME */ | |
163 | /* Returns non-zero upon success, 0 upon failure. */ | |
164 | WriteFile(hdl, buf, count, &tmp, NULL); | |
165 | #else | |
b19f4622 UH |
166 | ssize_t ret; |
167 | ||
2119ab03 | 168 | /* Returns the number of bytes written, or -1 upon failure. */ |
b19f4622 UH |
169 | ret = write(fd, buf, count); |
170 | if (ret < 0) | |
171 | sr_err("FD %d: Write error: %s.", fd, strerror(errno)); | |
302c4b5a UH |
172 | else |
173 | sr_spew("FD %d: Wrote %d/%d bytes.", fd, ret, count); | |
b19f4622 UH |
174 | |
175 | return ret; | |
2119ab03 UH |
176 | #endif |
177 | } | |
178 | ||
b19f4622 | 179 | /** |
2119ab03 | 180 | * Read a number of bytes from the specified serial port. |
b19f4622 UH |
181 | * |
182 | * @param fd File descriptor of the serial port. | |
183 | * @param buf Buffer where to store the bytes that are read. | |
184 | * @param count The number of bytes to read. | |
185 | * | |
186 | * @return The number of bytes read, or -1 upon failure. | |
2119ab03 | 187 | */ |
1a081ca6 | 188 | SR_PRIV int serial_read(int fd, void *buf, size_t count) |
2119ab03 UH |
189 | { |
190 | #ifdef _WIN32 | |
191 | DWORD tmp = 0; | |
192 | ||
193 | /* FIXME */ | |
194 | /* Returns non-zero upon success, 0 upon failure. */ | |
195 | return ReadFile(hdl, buf, count, &tmp, NULL); | |
196 | #else | |
b19f4622 UH |
197 | ssize_t ret; |
198 | ||
2119ab03 | 199 | /* Returns the number of bytes read, or -1 upon failure. */ |
b19f4622 UH |
200 | ret = read(fd, buf, count); |
201 | if (ret < 0) { | |
202 | /* | |
203 | * Should be sr_err(), but that would yield lots of | |
204 | * "Resource temporarily unavailable" messages. | |
205 | */ | |
206 | sr_spew("FD %d: Read error: %s.", fd, strerror(errno)); | |
302c4b5a UH |
207 | } else { |
208 | sr_spew("FD %d: Read %d/%d bytes.", fd, ret, count); | |
b19f4622 UH |
209 | } |
210 | ||
211 | return ret; | |
2119ab03 UH |
212 | #endif |
213 | } | |
214 | ||
b19f4622 UH |
215 | /** |
216 | * Set serial parameters for the specified serial port. | |
217 | * | |
218 | * @param baudrate The baudrate to set. | |
219 | * @param bits The number of data bits to use. | |
220 | * @param parity The parity setting to use (0 = none, 1 = even, 2 = odd). | |
221 | * @param stopbits The number of stop bits to use (1 or 2). | |
222 | * @param flowcontrol The flow control settings to use (0 = none, 1 = RTS/CTS, | |
223 | * 2 = XON/XOFF). | |
2119ab03 | 224 | * |
b19f4622 | 225 | * @return SR_OK upon success, SR_ERR upon failure. |
1ff7712c | 226 | */ |
0abee507 | 227 | SR_PRIV int serial_set_params(int fd, int baudrate, int bits, int parity, |
1a081ca6 | 228 | int stopbits, int flowcontrol) |
d02a535e | 229 | { |
b19f4622 UH |
230 | sr_dbg("FD %d: Setting serial parameters.", fd); |
231 | ||
926b866c UH |
232 | #ifdef _WIN32 |
233 | DCB dcb; | |
234 | ||
235 | if (!GetCommState(hdl, &dcb)) { | |
236 | /* TODO: Error handling. */ | |
e46b8fb1 | 237 | return SR_ERR; |
926b866c UH |
238 | } |
239 | ||
0abee507 | 240 | switch (baudrate) { |
1fdb75e1 | 241 | /* TODO: Support for higher baud rates. */ |
926b866c UH |
242 | case 115200: |
243 | dcb.BaudRate = CBR_115200; | |
244 | break; | |
245 | case 57600: | |
246 | dcb.BaudRate = CBR_57600; | |
247 | break; | |
248 | case 38400: | |
249 | dcb.BaudRate = CBR_38400; | |
250 | break; | |
251 | case 19200: | |
252 | dcb.BaudRate = CBR_19200; | |
253 | break; | |
254 | case 9600: | |
255 | dcb.BaudRate = CBR_9600; | |
256 | break; | |
e8e9dcdd AG |
257 | case 4800: |
258 | dcb.BaudRate = CBR_4800; | |
259 | break; | |
0f708301 AG |
260 | case 2400: |
261 | dcb.BaudRate = CBR_2400; | |
262 | break; | |
926b866c | 263 | default: |
b19f4622 UH |
264 | sr_err("Unsupported baudrate: %d.", baudrate); |
265 | return SR_ERR; | |
926b866c UH |
266 | } |
267 | dcb.ByteSize = bits; | |
268 | dcb.Parity = NOPARITY; /* TODO: Don't hardcode. */ | |
269 | dcb.StopBits = ONESTOPBIT; /* TODO: Don't hardcode. */ | |
270 | ||
271 | if (!SetCommState(hdl, &dcb)) { | |
272 | /* TODO: Error handling. */ | |
e46b8fb1 | 273 | return SR_ERR; |
926b866c UH |
274 | } |
275 | #else | |
d02a535e | 276 | struct termios term; |
1ff7712c | 277 | speed_t baud; |
d02a535e | 278 | |
b19f4622 UH |
279 | sr_dbg("FD %d: Getting terminal settings.", fd); |
280 | if (tcgetattr(fd, &term) < 0) { | |
20af6106 | 281 | sr_err("tcgetattr() error: %s.", strerror(errno)); |
6a6e23ab | 282 | return SR_ERR; |
b19f4622 | 283 | } |
6a6e23ab | 284 | |
0abee507 | 285 | switch (baudrate) { |
b19f4622 UH |
286 | case 50: |
287 | baud = B50; | |
288 | break; | |
289 | case 75: | |
290 | baud = B75; | |
291 | break; | |
292 | case 110: | |
293 | baud = B110; | |
294 | break; | |
295 | case 134: | |
296 | baud = B134; | |
297 | break; | |
298 | case 150: | |
299 | baud = B150; | |
300 | break; | |
301 | case 200: | |
302 | baud = B200; | |
303 | break; | |
304 | case 300: | |
305 | baud = B300; | |
306 | break; | |
307 | case 600: | |
308 | baud = B600; | |
309 | break; | |
310 | case 1200: | |
311 | baud = B1200; | |
312 | break; | |
313 | case 1800: | |
314 | baud = B1800; | |
315 | break; | |
0f708301 AG |
316 | case 2400: |
317 | baud = B2400; | |
318 | break; | |
e8e9dcdd AG |
319 | case 4800: |
320 | baud = B4800; | |
321 | break; | |
1ff7712c DR |
322 | case 9600: |
323 | baud = B9600; | |
324 | break; | |
b19f4622 UH |
325 | case 19200: |
326 | baud = B19200; | |
327 | break; | |
1ff7712c DR |
328 | case 38400: |
329 | baud = B38400; | |
330 | break; | |
331 | case 57600: | |
332 | baud = B57600; | |
333 | break; | |
334 | case 115200: | |
335 | baud = B115200; | |
336 | break; | |
b19f4622 UH |
337 | case 230400: |
338 | baud = B230400; | |
339 | break; | |
9a751023 | 340 | #ifndef __APPLE__ |
1ff7712c DR |
341 | case 460800: |
342 | baud = B460800; | |
343 | break; | |
9a751023 | 344 | #endif |
1ff7712c | 345 | default: |
b19f4622 | 346 | sr_err("Unsupported baudrate: %d.", baudrate); |
e46b8fb1 | 347 | return SR_ERR; |
1ff7712c | 348 | } |
b19f4622 UH |
349 | |
350 | sr_dbg("FD %d: Configuring output baudrate to %d (%d).", | |
351 | fd, baudrate, baud); | |
352 | if (cfsetospeed(&term, baud) < 0) { | |
5df7b201 | 353 | sr_err("cfsetospeed() error: %s.", strerror(errno)); |
e46b8fb1 | 354 | return SR_ERR; |
b19f4622 UH |
355 | } |
356 | ||
357 | sr_dbg("FD %d: Configuring input baudrate to %d (%d).", | |
358 | fd, baudrate, baud); | |
359 | if (cfsetispeed(&term, baud) < 0) { | |
5df7b201 | 360 | sr_err("cfsetispeed() error: %s.", strerror(errno)); |
e46b8fb1 | 361 | return SR_ERR; |
b19f4622 | 362 | } |
1ff7712c | 363 | |
b19f4622 | 364 | sr_dbg("FD %d: Configuring %d data bits.", fd, bits); |
d02a535e | 365 | term.c_cflag &= ~CSIZE; |
1ff7712c DR |
366 | switch (bits) { |
367 | case 8: | |
368 | term.c_cflag |= CS8; | |
369 | break; | |
370 | case 7: | |
371 | term.c_cflag |= CS7; | |
372 | break; | |
373 | default: | |
b19f4622 | 374 | sr_err("Unsupported data bits number: %d.", bits); |
e46b8fb1 | 375 | return SR_ERR; |
1ff7712c DR |
376 | } |
377 | ||
b19f4622 | 378 | sr_dbg("FD %d: Configuring %d stop bits.", fd, stopbits); |
d02a535e | 379 | term.c_cflag &= ~CSTOPB; |
1ff7712c DR |
380 | switch (stopbits) { |
381 | case 1: | |
b19f4622 | 382 | /* Do nothing, a cleared CSTOPB entry means "1 stop bit". */ |
1ff7712c DR |
383 | break; |
384 | case 2: | |
385 | term.c_cflag |= CSTOPB; | |
d7c776b9 | 386 | break; |
1ff7712c | 387 | default: |
b19f4622 | 388 | sr_err("Unsupported stopbits number: %d.", stopbits); |
e46b8fb1 | 389 | return SR_ERR; |
1ff7712c DR |
390 | } |
391 | ||
f38b9763 BV |
392 | term.c_iflag &= ~(IXON | IXOFF); |
393 | term.c_cflag &= ~CRTSCTS; | |
1ff7712c | 394 | switch (flowcontrol) { |
f38b9763 BV |
395 | case 0: |
396 | /* No flow control. */ | |
b19f4622 | 397 | sr_dbg("FD %d: Configuring no flow control.", fd); |
1ff7712c DR |
398 | break; |
399 | case 1: | |
b19f4622 | 400 | sr_dbg("FD %d: Configuring RTS/CTS flow control.", fd); |
1ff7712c | 401 | term.c_cflag |= CRTSCTS; |
d7c776b9 | 402 | break; |
f38b9763 | 403 | case 2: |
b19f4622 | 404 | sr_dbg("FD %d: Configuring XON/XOFF flow control.", fd); |
f38b9763 BV |
405 | term.c_iflag |= IXON | IXOFF; |
406 | break; | |
1ff7712c | 407 | default: |
b19f4622 | 408 | sr_err("Unsupported flow control setting: %d.", flowcontrol); |
e46b8fb1 | 409 | return SR_ERR; |
1ff7712c DR |
410 | } |
411 | ||
ac4a2ea4 DR |
412 | term.c_iflag &= ~IGNPAR; |
413 | term.c_cflag &= ~(PARODD | PARENB); | |
1ff7712c | 414 | switch (parity) { |
f8c1fcda | 415 | case SERIAL_PARITY_NONE: |
b19f4622 | 416 | sr_dbg("FD %d: Configuring no parity.", fd); |
1ff7712c DR |
417 | term.c_iflag |= IGNPAR; |
418 | break; | |
f8c1fcda | 419 | case SERIAL_PARITY_EVEN: |
b19f4622 | 420 | sr_dbg("FD %d: Configuring even parity.", fd); |
ac4a2ea4 | 421 | term.c_cflag |= PARENB; |
1ff7712c | 422 | break; |
f8c1fcda | 423 | case SERIAL_PARITY_ODD: |
b19f4622 | 424 | sr_dbg("FD %d: Configuring odd parity.", fd); |
ac4a2ea4 | 425 | term.c_cflag |= PARENB | PARODD; |
1ff7712c DR |
426 | break; |
427 | default: | |
b19f4622 | 428 | sr_err("Unsupported parity setting: %d.", parity); |
e46b8fb1 | 429 | return SR_ERR; |
1ff7712c DR |
430 | } |
431 | ||
b19f4622 | 432 | /* Do NOT translate carriage return to newline on input. */ |
fb9d3bf9 | 433 | term.c_iflag &= ~(ICRNL); |
b19f4622 UH |
434 | |
435 | /* Disable canonical mode, and don't echo input characters. */ | |
5c51e098 BV |
436 | term.c_lflag &= ~(ICANON | ECHO); |
437 | ||
b19f4622 UH |
438 | /* Write the configured settings. */ |
439 | if (tcsetattr(fd, TCSADRAIN, &term) < 0) { | |
440 | sr_err("tcsetattr() error: %ѕ.", strerror(errno)); | |
e46b8fb1 | 441 | return SR_ERR; |
b19f4622 | 442 | } |
926b866c | 443 | #endif |
d02a535e | 444 | |
e46b8fb1 | 445 | return SR_OK; |
d02a535e | 446 | } |
792fc686 BV |
447 | |
448 | #define SERIAL_COMM_SPEC "^(\\d+)/([78])([neo])([12])$" | |
449 | SR_PRIV int serial_set_paramstr(int fd, const char *paramstr) | |
450 | { | |
451 | GRegex *reg; | |
452 | GMatchInfo *match; | |
453 | int speed, databits, parity, stopbits; | |
454 | char *mstr; | |
455 | ||
456 | speed = databits = parity = stopbits = 0; | |
457 | reg = g_regex_new(SERIAL_COMM_SPEC, 0, 0, NULL); | |
458 | if (g_regex_match(reg, paramstr, 0, &match)) { | |
459 | if ((mstr = g_match_info_fetch(match, 1))) | |
460 | speed = strtoul(mstr, NULL, 10); | |
461 | g_free(mstr); | |
462 | if ((mstr = g_match_info_fetch(match, 2))) | |
463 | databits = strtoul(mstr, NULL, 10); | |
464 | g_free(mstr); | |
465 | if ((mstr = g_match_info_fetch(match, 3))) { | |
466 | switch (mstr[0]) { | |
467 | case 'n': | |
468 | parity = SERIAL_PARITY_NONE; | |
469 | break; | |
470 | case 'e': | |
471 | parity = SERIAL_PARITY_EVEN; | |
472 | break; | |
473 | case 'o': | |
474 | parity = SERIAL_PARITY_ODD; | |
475 | break; | |
476 | } | |
477 | } | |
478 | g_free(mstr); | |
479 | if ((mstr = g_match_info_fetch(match, 4))) | |
480 | stopbits = strtoul(mstr, NULL, 10); | |
481 | g_free(mstr); | |
482 | } | |
483 | g_match_info_unref(match); | |
484 | g_regex_unref(reg); | |
485 | ||
486 | if (speed) | |
487 | return serial_set_params(fd, speed, databits, parity, stopbits, 0); | |
488 | else | |
489 | return SR_ERR_ARG; | |
490 | } | |
491 | ||
6f22a8ef | 492 | SR_PRIV int serial_readline(int fd, char **buf, int *buflen, |
b87f8504 | 493 | gint64 timeout_ms) |
6f22a8ef | 494 | { |
b87f8504 | 495 | gint64 start; |
6f22a8ef UH |
496 | int maxlen, len; |
497 | ||
498 | timeout_ms *= 1000; | |
499 | start = g_get_monotonic_time(); | |
500 | ||
501 | maxlen = *buflen; | |
502 | *buflen = len = 0; | |
503 | while(1) { | |
504 | len = maxlen - *buflen - 1; | |
505 | if (len < 1) | |
506 | break; | |
507 | len = serial_read(fd, *buf + *buflen, 1); | |
508 | if (len > 0) { | |
509 | *buflen += len; | |
510 | *(*buf + *buflen) = '\0'; | |
318dd53c BV |
511 | if (*buflen > 0 && (*(*buf + *buflen - 1) == '\r' |
512 | || *(*buf + *buflen - 1) == '\n')) { | |
513 | /* Strip CR/LF and terminate. */ | |
6f22a8ef UH |
514 | *(*buf + --*buflen) = '\0'; |
515 | break; | |
516 | } | |
517 | } | |
518 | if (g_get_monotonic_time() - start > timeout_ms) | |
519 | /* Timeout */ | |
520 | break; | |
521 | g_usleep(2000); | |
522 | } | |
318dd53c BV |
523 | if (*buflen) |
524 | sr_dbg("Received %d: '%s'.", *buflen, *buf); | |
6f22a8ef UH |
525 | |
526 | return SR_OK; | |
527 | } |