]> sigrok.org Git - libsigrok.git/commitdiff
serial: use timeout API in stream detect, obsoletes bitrate param
authorGerhard Sittig <redacted>
Wed, 1 May 2019 17:50:01 +0000 (19:50 +0200)
committerGerhard Sittig <redacted>
Sun, 9 Jun 2019 12:51:02 +0000 (14:51 +0200)
The serial_stream_detect() routine needs to estimate the time which is
needed to communicate a given amount of data. Since the serial port got
opened and configured before, the serial communication parameters are
known, and callers need not redundantly specify the bit rate.

src/hardware/appa-55ii/api.c
src/hardware/kern-scale/api.c
src/hardware/serial-dmm/api.c
src/hardware/teleinfo/api.c
src/lcr/es51919.c
src/libsigrok-internal.h
src/serial.c

index ddf3fe4a11885468a041838e1ab8d01a0300c2ea..81eafdce3ff1c809c1e23a1f9d671710ed30a117 100644 (file)
@@ -83,7 +83,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
        /* Let's get a bit of data and see if we can find a packet. */
        if (serial_stream_detect(serial, buf, &len, 25,
-                       appa_55ii_packet_valid, 500, 9600) != SR_OK)
+                       appa_55ii_packet_valid, 500) != SR_OK)
                goto scan_cleanup;
 
        sr_info("Found device on port %s.", conn);
index e369a44cf5e585722dbec8acf544b8a90b8119e8..fba3e4a50d155e7e5156d7f50de606938147eeaa 100644 (file)
@@ -89,7 +89,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        /* Let's get a bit of data and see if we can find a packet. */
        len = sizeof(buf);
        ret = serial_stream_detect(serial, buf, &len, scale->packet_size,
-                                  scale->packet_valid, 3000, scale->baudrate);
+                                  scale->packet_valid, 3000);
        if (ret != SR_OK)
                goto scan_cleanup;
 
index 009f37c5e63f5caadabb054b8a891bbd9530b503..f237bb2ad6e328ca5321d29e27a3d1b33d0a07f6 100644 (file)
@@ -106,8 +106,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        /* Let's get a bit of data and see if we can find a packet. */
        len = sizeof(buf);
        ret = serial_stream_detect(serial, buf, &len, dmm->packet_size,
-                                  dmm->packet_valid, 3000,
-                                  dmm->baudrate);
+                                  dmm->packet_valid, 3000);
        if (ret != SR_OK)
                goto scan_cleanup;
 
index 71a14106fcf4f1b17c718a06ab041bc88c7aa5bf..3de4456ba6687b16def01f928078b6650408f219 100644 (file)
@@ -79,7 +79,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
        /* Let's get a bit of data and see if we can find a packet. */
        if (serial_stream_detect(serial, buf, &len, len,
-                                teleinfo_packet_valid, 3000, 1200) != SR_OK)
+                                teleinfo_packet_valid, 3000) != SR_OK)
                goto scan_cleanup;
 
        sr_info("Found device on port %s.", conn);
index 38750098407129a5ba5e7fcf92d1f4d17332b851..fad0a3e98f08eb4d2f99fb61b4e5c77ee62d67cb 100644 (file)
@@ -209,7 +209,7 @@ static int serial_stream_check_buf(struct sr_serial_dev_inst *serial,
                                   uint8_t *buf, size_t buflen,
                                   size_t packet_size,
                                   packet_valid_callback is_valid,
-                                  uint64_t timeout_ms, int baudrate)
+                                  uint64_t timeout_ms)
 {
        size_t len, dropped;
        int ret;
@@ -221,7 +221,7 @@ static int serial_stream_check_buf(struct sr_serial_dev_inst *serial,
 
        len = buflen;
        ret = serial_stream_detect(serial, buf, &len, packet_size,
-                                  is_valid, timeout_ms, baudrate);
+                                  is_valid, timeout_ms);
 
        serial_close(serial);
 
@@ -245,12 +245,12 @@ static int serial_stream_check_buf(struct sr_serial_dev_inst *serial,
 static int serial_stream_check(struct sr_serial_dev_inst *serial,
                               size_t packet_size,
                               packet_valid_callback is_valid,
-                              uint64_t timeout_ms, int baudrate)
+                              uint64_t timeout_ms)
 {
        uint8_t buf[128];
 
        return serial_stream_check_buf(serial, buf, sizeof(buf), packet_size,
-                                      is_valid, timeout_ms, baudrate);
+                                      is_valid, timeout_ms);
 }
 
 /*
@@ -713,8 +713,7 @@ SR_PRIV struct sr_dev_inst *es51919_serial_scan(GSList *options,
        if (!(serial = serial_dev_new(options, "9600/8n1/rts=1/dtr=1")))
                goto scan_cleanup;
 
-       ret = serial_stream_check(serial, PACKET_SIZE, packet_valid,
-                                 3000, 9600);
+       ret = serial_stream_check(serial, PACKET_SIZE, packet_valid, 3000);
        if (ret != SR_OK)
                goto scan_cleanup;
 
index 9a34ba169a84863e0dffb382d2c0688c27ec724a..5a9d3951473de7c413fb2db37a1c969428b84337 100644 (file)
@@ -1175,7 +1175,7 @@ SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial,
                                 uint8_t *buf, size_t *buflen,
                                 size_t packet_size,
                                 packet_valid_callback is_valid,
-                                uint64_t timeout_ms, int baudrate);
+                                uint64_t timeout_ms);
 SR_PRIV int sr_serial_extract_options(GSList *options, const char **serial_device,
                                      const char **serial_options);
 SR_PRIV int serial_source_add(struct sr_session *session,
index 12026a8965d6b9228efc245cecf9d87b4d3231f3..a2d0189fbb734c9908079e3d8bee768acc48b82a 100644 (file)
@@ -749,9 +749,6 @@ SR_PRIV int serial_readline(struct sr_serial_dev_inst *serial,
  * @param is_valid Callback that assesses whether the packet is valid or not.
  * @param[in] timeout_ms The timeout after which, if no packet is detected, to
  *                       abort scanning.
- * @param[in] baudrate The baudrate of the serial port. This parameter is not
- *                     critical, but it helps fine tune the serial port polling
- *                     delay.
  *
  * @retval SR_OK Valid packet was found within the given timeout.
  * @retval SR_ERR Failure.
@@ -762,7 +759,7 @@ SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial,
        uint8_t *buf, size_t *buflen,
        size_t packet_size,
        packet_valid_callback is_valid,
-       uint64_t timeout_ms, int baudrate)
+       uint64_t timeout_ms)
 {
        uint64_t start, time, byte_delay_us;
        size_t ibuf, i, maxlen;
@@ -770,16 +767,16 @@ SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial,
 
        maxlen = *buflen;
 
-       sr_dbg("Detecting packets on %s (timeout = %" PRIu64
-              "ms, baudrate = %d).", serial->port, timeout_ms, baudrate);
+       sr_dbg("Detecting packets on %s (timeout = %" PRIu64 "ms).",
+               serial->port, timeout_ms);
 
-       if (maxlen < (packet_size / 2) ) {
+       if (maxlen < (packet_size * 2) ) {
                sr_err("Buffer size must be at least twice the packet size.");
                return SR_ERR;
        }
 
        /* Assume 8n1 transmission. That is 10 bits for every byte. */
-       byte_delay_us = 10 * ((1000 * 1000) / baudrate);
+       byte_delay_us = serial_timeout(serial, 1) * 1000;
        start = g_get_monotonic_time();
 
        i = ibuf = len = 0;