SR_PRIV int norma_dmm_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_serial_dev_inst *serial; int len; (void)fd; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; serial = sdi->conn; if (revents == G_IO_IN) { /* Serial data arrived. */ while (NMADMM_BUFSIZE - devc->buflen - 1 > 0) { len = serial_read_nonblocking(serial, devc->buf + devc->buflen, 1); if (len < 1) break; devc->buflen += len; *(devc->buf + devc->buflen) = '\0'; if (*(devc->buf + devc->buflen - 1) == '\n') { /* * TODO: According to specs, should be \r, but * then we'd have to get rid of the \n. */ devc->last_req_pending = FALSE; nma_process_line(sdi); break; } } } if (sr_sw_limits_check(&devc->limits)) { sr_dev_acquisition_stop(sdi); } else { /* Request next package. */ if (devc->last_req_pending) { gint64 elapsed_us = g_get_monotonic_time() - devc->req_sent_at; if (elapsed_us > NMADMM_TIMEOUT_MS * 1000) {/* Timeout! */ sr_spew("Request timeout!"); devc->last_req_pending = FALSE; } } if (!devc->last_req_pending) { if (nma_send_req(sdi, NMADMM_REQ_STATUS, NULL) != SR_OK) return FALSE; } } return TRUE; }
static gboolean session_stop_sync(void *user_data) { struct sr_session *session; struct sr_dev_inst *sdi; GSList *node; session = user_data; if (!session->running) return G_SOURCE_REMOVE; sr_info("Stopping."); for (node = session->devs; node; node = node->next) { sdi = node->data; sr_dev_acquisition_stop(sdi); } return G_SOURCE_REMOVE; }
SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_serial_dev_inst *serial; gboolean stop = FALSE; int len; (void)fd; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; serial = sdi->conn; if (revents == G_IO_IN) { /* Serial data arrived. */ while (AGDMM_BUFSIZE - devc->buflen - 1 > 0) { len = serial_read_nonblocking(serial, devc->buf + devc->buflen, 1); if (len < 1) break; devc->buflen += len; *(devc->buf + devc->buflen) = '\0'; if (*(devc->buf + devc->buflen - 1) == '\n') { /* End of line */ stop = receive_line(sdi); break; } } } if (sr_sw_limits_check(&devc->limits) || stop) sr_dev_acquisition_stop(sdi); else dispatch(sdi); return TRUE; }
/** * Start a session. * * When this function returns with a status code indicating success, the * session is running. Use sr_session_stopped_callback_set() to receive * notification upon completion, or call sr_session_run() to block until * the session stops. * * Session events will be processed in the context of the current thread. * If a thread-default GLib main context has been set, and is not owned by * any other thread, it will be used. Otherwise, libsigrok will create its * own main context for the current thread. * * @param session The session to use. Must not be NULL. * * @retval SR_OK Success. * @retval SR_ERR_ARG Invalid session passed. * @retval SR_ERR Other error. * * @since 0.4.0 */ SR_API int sr_session_start(struct sr_session *session) { struct sr_dev_inst *sdi; struct sr_channel *ch; GSList *l, *c, *lend; int ret; if (!session) { sr_err("%s: session was NULL", __func__); return SR_ERR_ARG; } if (!session->devs) { sr_err("%s: session->devs was NULL; a session " "cannot be started without devices.", __func__); return SR_ERR_ARG; } if (session->running) { sr_err("Cannot (re-)start session while it is still running."); return SR_ERR; } if (session->trigger) { ret = verify_trigger(session->trigger); if (ret != SR_OK) return ret; } /* Check enabled channels and commit settings of all devices. */ for (l = session->devs; l; l = l->next) { sdi = l->data; for (c = sdi->channels; c; c = c->next) { ch = c->data; if (ch->enabled) break; } if (!c) { sr_err("%s device %s has no enabled channels.", sdi->driver->name, sdi->connection_id); return SR_ERR; } ret = sr_config_commit(sdi); if (ret != SR_OK) { sr_err("Failed to commit %s device %s settings " "before starting acquisition.", sdi->driver->name, sdi->connection_id); return ret; } } ret = set_main_context(session); if (ret != SR_OK) return ret; sr_info("Starting."); session->running = TRUE; /* Have all devices start acquisition. */ for (l = session->devs; l; l = l->next) { if (!(sdi = l->data)) { sr_err("Device sdi was NULL, can't start session."); ret = SR_ERR; break; } ret = sr_dev_acquisition_start(sdi); if (ret != SR_OK) { sr_err("Could not start %s device %s acquisition.", sdi->driver->name, sdi->connection_id); break; } } if (ret != SR_OK) { /* If there are multiple devices, some of them may already have * started successfully. Stop them now before returning. */ lend = l->next; for (l = session->devs; l != lend; l = l->next) { sdi = l->data; sr_dev_acquisition_stop(sdi); } /* TODO: Handle delayed stops. Need to iterate the event * sources... */ session->running = FALSE; unset_main_context(session); return ret; } if (g_hash_table_size(session->event_sources) == 0) stop_check_later(session); return SR_OK; }