serial_source_add(sdi->session, serial, G_IO_IN, 50,
rdtech_um_receive_data, (void *)sdi);
- return rdtech_um_poll(sdi);
+ return rdtech_um_poll(sdi, TRUE);
}
static struct sr_dev_driver rdtech_um_driver_info = {
return p;
}
-SR_PRIV int rdtech_um_poll(const struct sr_dev_inst *sdi)
+SR_PRIV int rdtech_um_poll(const struct sr_dev_inst *sdi, gboolean force)
{
struct dev_context *devc;
+ int64_t now, elapsed;
struct sr_serial_dev_inst *serial;
uint8_t request;
+ /* Check for expired intervals or forced requests. */
+ devc = sdi->priv;
+ now = g_get_monotonic_time() / 1000;
+ elapsed = now - devc->cmd_sent_at;
+ if (!force && elapsed < UM_POLL_PERIOD_MS)
+ return SR_OK;
+
+ /* Send another poll request. Update interval only on success. */
serial = sdi->conn;
request = UM_CMD_POLL;
if (serial_write_blocking(serial, &request, sizeof(request),
sr_err("Unable to send poll request.");
return SR_ERR;
}
-
- devc = sdi->priv;
- devc->cmd_sent_at = g_get_monotonic_time() / 1000;
+ devc->cmd_sent_at = now;
return SR_OK;
}
struct sr_dev_inst *sdi;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
- int64_t now, elapsed;
(void)fd;
return TRUE;
}
- now = g_get_monotonic_time() / 1000;
- elapsed = now - devc->cmd_sent_at;
-
- if (elapsed > UM_POLL_PERIOD_MS)
- rdtech_um_poll(sdi);
+ (void)rdtech_um_poll(sdi, FALSE);
return TRUE;
}
SR_PRIV const struct rdtech_um_profile *rdtech_um_probe(struct sr_serial_dev_inst *serial);
SR_PRIV int rdtech_um_receive_data(int fd, int revents, void *cb_data);
-SR_PRIV int rdtech_um_poll(const struct sr_dev_inst *sdi);
+SR_PRIV int rdtech_um_poll(const struct sr_dev_inst *sdi, gboolean force);
#endif