]> sigrok.org Git - libsigrok.git/commitdiff
atten-pps3xxx: Use serial_timeout().
authorBert Vermeulen <redacted>
Mon, 6 Oct 2014 10:12:13 +0000 (12:12 +0200)
committerBert Vermeulen <redacted>
Mon, 6 Oct 2014 10:12:13 +0000 (12:12 +0200)
src/hardware/atten-pps3xxx/api.c
src/hardware/atten-pps3xxx/protocol.c
src/hardware/atten-pps3xxx/protocol.h

index 68dec6b08d3e15cad1d84f340eaf83b6659ef357..5bbafca8c3a6b88ca102804b50a5e5c15c3dc0ba 100644 (file)
@@ -92,10 +92,9 @@ static GSList *scan(GSList *options, int modelid)
        struct sr_serial_dev_inst *serial;
        GSList *l, *devices;
        struct pps_model *model;
-       float byte_delay_ms;
        uint8_t packet[PACKET_SIZE];
        unsigned int i;
-       int ret;
+       int delay_ms, ret;
        const char *conn, *serialcomm;
        char channel[10];
 
@@ -127,20 +126,12 @@ static GSList *scan(GSList *options, int modelid)
                return NULL;
        serial_flush(serial);
 
-       /* How long it takes for a byte to transfer over the serial port. */
-       if (sp_get_port_transport(serial->data) == SP_TRANSPORT_NATIVE)
-               /* 11 bits at 9600 bps. */
-               byte_delay_ms = 1.15;
-       else
-               /* Emulated serial over USB or bluetooth is just enqueueing. */
-               byte_delay_ms = 0;
-
        /* This is how the vendor software scans for hardware. */
        memset(packet, 0, PACKET_SIZE);
        packet[0] = 0xaa;
        packet[1] = 0xaa;
-       if (serial_write_blocking(serial, packet, PACKET_SIZE,
-                       byte_delay_ms * PACKET_SIZE + 1) < PACKET_SIZE) {
+       delay_ms = serial_timeout(serial, PACKET_SIZE);
+       if (serial_write_blocking(serial, packet, PACKET_SIZE, delay_ms) < PACKET_SIZE) {
                sr_err("Unable to write while probing for hardware.");
                return NULL;
        }
@@ -188,7 +179,7 @@ static GSList *scan(GSList *options, int modelid)
        devc = g_malloc0(sizeof(struct dev_context));
        devc->model = model;
        devc->config = g_malloc0(sizeof(struct per_channel_config) * model->num_channels);
-       devc->byte_delay_ms = byte_delay_ms;
+       devc->delay_ms = delay_ms;
        sdi->priv = devc;
        drvc->instances = g_slist_append(drvc->instances, sdi);
        devices = g_slist_append(devices, sdi);
index 98838b65bbe05a2ba00b4018f06ded7a8f5a3019..e7d9d810c1c6dbfc2e5bf410192ce898f01d135c 100644 (file)
@@ -88,8 +88,7 @@ SR_PRIV void send_packet(const struct sr_dev_inst *sdi, uint8_t *packet)
 
        devc = sdi->priv;
        serial = sdi->conn;
-       if (serial_write_blocking(serial, packet, PACKET_SIZE,
-                       devc->byte_delay_ms * PACKET_SIZE + 1) < PACKET_SIZE)
+       if (serial_write_blocking(serial, packet, PACKET_SIZE, devc->delay_ms) < PACKET_SIZE)
                sr_dbg("Failed to send packet.");
        dump_packet("sent", packet);
 }
index 2ad9e857b3f3d377df2b81e926fabda060026e5d..36ee281a8e2e63bfa32d1af73f20117ca9e3dcd6 100644 (file)
@@ -82,7 +82,8 @@ struct dev_context {
        /* Operational state */
        gboolean config_dirty;
        struct per_channel_config *config;
-       float byte_delay_ms;
+       /* Blocking write timeout for packet. */
+       int delay_ms;
        /* Received from device. */
        int channel_mode;
        gboolean over_current_protection;