*/
#include <glib.h>
-#include "libsigrok.h"
-#include "libsigrok-internal.h"
-#include "agilent-dmm.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
+#include "libsigrok.h"
+#include "libsigrok-internal.h"
+#include "agilent-dmm.h"
static const int hwopts[] = {
SR_HWOPT_CONN,
return SR_OK;
}
-static int serial_readline(int fd, char **buf, int *buflen, uint64_t timeout_ms)
+/* TODO: Merge into serial_readline() from serial.c. */
+static int serial_readline2(int fd, char **buf, int *buflen, uint64_t timeout_ms)
{
uint64_t start;
int maxlen, len;
len = 128;
buf = g_try_malloc(len);
- serial_readline(fd, &buf, &len, 150);
+ serial_readline2(fd, &buf, &len, 150);
if (!len)
return NULL;
return SR_ERR_ARG;
}
+SR_PRIV int serial_readline(int fd, char **buf, int *buflen,
+ uint64_t timeout_ms)
+{
+ uint64_t start;
+ int maxlen, len;
+
+ timeout_ms *= 1000;
+ start = g_get_monotonic_time();
+
+ maxlen = *buflen;
+ *buflen = len = 0;
+ while(1) {
+ len = maxlen - *buflen - 1;
+ if (len < 1)
+ break;
+ len = serial_read(fd, *buf + *buflen, 1);
+ if (len > 0) {
+ *buflen += len;
+ *(*buf + *buflen) = '\0';
+ if (*buflen > 0 && *(*buf + *buflen - 1) == '\r') {
+ /* Strip LF and terminate. */
+ *(*buf + --*buflen) = '\0';
+ break;
+ }
+ }
+ if (g_get_monotonic_time() - start > timeout_ms)
+ /* Timeout */
+ break;
+ g_usleep(2000);
+ }
+ sr_dbg("Received %d: '%s'.", *buflen, *buf);
+
+ return SR_OK;
+}
*/
#include <glib.h>
-#include "libsigrok.h"
-#include "libsigrok-internal.h"
-#include "fluke-dmm.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
+#include "libsigrok.h"
+#include "libsigrok-internal.h"
+#include "fluke-dmm.h"
static const int hwopts[] = {
SR_HWOPT_CONN,
return SR_OK;
}
-static int serial_readline(int fd, char **buf, int *buflen, uint64_t timeout_ms)
-{
- uint64_t start;
- int maxlen, len;
-
- timeout_ms *= 1000;
- start = g_get_monotonic_time();
-
- maxlen = *buflen;
- *buflen = len = 0;
- while(1) {
- len = maxlen - *buflen - 1;
- if (len < 1)
- break;
- len = serial_read(fd, *buf + *buflen, 1);
- if (len > 0) {
- *buflen += len;
- *(*buf + *buflen) = '\0';
- if (*buflen > 0 && *(*buf + *buflen - 1) == '\r') {
- /* Strip LF and terminate. */
- *(*buf + --*buflen) = '\0';
- break;
- }
- }
- if (g_get_monotonic_time() - start > timeout_ms)
- /* Timeout */
- break;
- g_usleep(2000);
- }
- sr_dbg("Received %d: '%s'.", *buflen, *buf);
-
- return SR_OK;
-}
-
static GSList *fluke_scan(const char *conn, const char *serialcomm)
{
struct sr_dev_inst *sdi;
*/
#include <glib.h>
-#include "libsigrok.h"
-#include "libsigrok-internal.h"
-#include "radioshack-dmm.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
+#include "libsigrok.h"
+#include "libsigrok-internal.h"
+#include "radioshack-dmm.h"
static const int hwopts[] = {
SR_HWOPT_CONN,
return SR_OK;
}
-static int serial_readline(int fd, char **buf, size_t *buflen,
- uint64_t timeout_ms)
-{
- uint64_t start;
- int maxlen, len;
-
- timeout_ms *= 1000;
- start = g_get_monotonic_time();
-
- maxlen = *buflen;
- *buflen = len = 0;
- while(1) {
- len = maxlen - *buflen - 1;
- if (len < 1)
- break;
- len = serial_read(fd, *buf + *buflen, 1);
- if (len > 0) {
- *buflen += len;
- *(*buf + *buflen) = '\0';
- if (*buflen > 0 && *(*buf + *buflen - 1) == '\r') {
- /* Strip LF and terminate. */
- *(*buf + --*buflen) = '\0';
- break;
- }
- }
- if (g_get_monotonic_time() - start > timeout_ms)
- /* Timeout */
- break;
- g_usleep(2000);
- }
-
- return SR_OK;
-}
-
static GSList *rs_22_812_scan(const char *conn, const char *serialcomm)
{
struct sr_dev_inst *sdi;
return SR_OK;
}
-static int serial_readline(int fd, char **buf, int *buflen,
- uint64_t timeout_ms)
-{
- uint64_t start;
- int maxlen, len;
-
- timeout_ms *= 1000;
- start = g_get_monotonic_time();
-
- maxlen = *buflen;
- *buflen = len = 0;
- while (1) {
- len = maxlen - *buflen - 1;
- if (len < 1)
- break;
- len = serial_read(fd, *buf + *buflen, 1);
- if (len > 0) {
- *buflen += len;
- *(*buf + *buflen) = '\0';
- if (*buflen > 0 && *(*buf + *buflen - 1) == '\r') {
- /* Strip LF and terminate. */
- *(*buf + --*buflen) = '\0';
- break;
- }
- }
- if (g_get_monotonic_time() - start > timeout_ms)
- /* Timeout */
- break;
- g_usleep(2000);
- }
-
- return SR_OK;
-}
-
static GSList *lcd14_scan(const char *conn, const char *serialcomm)
{
struct sr_dev_inst *sdi;
SR_PRIV int serial_set_params(int fd, int baudrate, int bits, int parity,
int stopbits, int flowcontrol);
SR_PRIV int serial_set_paramstr(int fd, const char *paramstr);
+SR_PRIV int serial_readline(int fd, char **buf, int *buflen,
+ uint64_t timeout_ms);
/*--- hardware/common/ezusb.c -----------------------------------------------*/