/* Execute a stop on BeagleLogic */
devc->beaglelogic->stop(devc);
- /* lseek to offset 0, flushes the cache */
+ /* Flush the cache */
if (devc->beaglelogic == &beaglelogic_native_ops)
lseek(devc->fd, 0, SEEK_SET);
+ else
+ beaglelogic_tcp_drain(devc);
/* Remove session source and send EOT packet */
sr_session_source_remove_pollfd(sdi->session, &devc->pollfd);
SR_PRIV extern const struct beaglelogic_ops beaglelogic_tcp_ops;
SR_PRIV int beaglelogic_tcp_detect(struct dev_context *devc);
+SR_PRIV int beaglelogic_tcp_drain(struct dev_context *devc);
#endif
return len;
}
+SR_PRIV int beaglelogic_tcp_drain(struct dev_context *devc) {
+ char *buf = g_malloc(1024);
+ fd_set rset;
+ int ret, len = 0;
+ struct timeval tv;
+
+ FD_ZERO(&rset);
+ FD_SET(devc->socket, &rset);
+
+ /* 25ms timeout */
+ tv.tv_sec = 0;
+ tv.tv_usec = 25 * 1000;
+
+ do {
+ ret = select(devc->socket + 1, &rset, NULL, NULL, &tv);
+ if (ret > 0) {
+ len += beaglelogic_tcp_read_data(devc, buf, 1024);
+ }
+ } while (ret > 0);
+
+ sr_spew("Drained %d bytes of data.", len);
+
+ g_free(buf);
+ return SR_OK;
+}
+
static int beaglelogic_tcp_get_string(struct dev_context *devc, const char *cmd,
char **tcp_resp) {
GString *response = g_string_sized_new(1024);
}
static int beaglelogic_start(struct dev_context *devc) {
+ beaglelogic_tcp_drain(devc);
return beaglelogic_tcp_send_cmd(devc, "get");
}
/* Send EOA Packet, stop polling */
std_session_send_df_end(sdi);
devc->beaglelogic->stop(devc);
+
+ /* Drain the receive buffer */
+ beaglelogic_tcp_drain(devc);
+
sr_session_source_remove_pollfd(sdi->session, &devc->pollfd);
}