Пример #1
0
SR_PRIV int usb_source_remove(struct sr_context *ctx)
{
	if (!ctx->usb_source_present)
		return SR_OK;

#ifdef _WIN32
	ctx->usb_thread_running = FALSE;
	g_mutex_unlock(&ctx->usb_mutex);
	libusb_unlock_events(ctx->libusb_ctx);
	g_thread_join(ctx->usb_thread);
	g_mutex_clear(&ctx->usb_mutex);
	sr_session_source_remove_pollfd(&ctx->usb_pollfd);
	CloseHandle(ctx->usb_event);
#else
	const struct libusb_pollfd **lupfd;
	unsigned int i;

	lupfd = libusb_get_pollfds(ctx->libusb_ctx);
	for (i = 0; lupfd[i]; i++)
		sr_source_remove(lupfd[i]->fd);
	free(lupfd);
#endif
	ctx->usb_source_present = FALSE;

	return SR_OK;
}
Пример #2
0
SR_PRIV int scpi_usbtmc_source_remove(void *priv)
{
	struct usbtmc_scpi *uscpi = priv;
	struct sr_usbtmc_dev_inst *usbtmc = uscpi->usbtmc;

	return sr_source_remove(usbtmc->fd);
}
Пример #3
0
static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
{
	struct sr_datafeed_packet packet;

	(void)sdi;

	sr_dbg("Stopping acquisition.");
	sr_source_remove(-1);

	/* Send end packet to the session bus. */
	sr_dbg("Sending SR_DF_END.");
	packet.type = SR_DF_END;
	sr_session_send(cb_data, &packet);

	return SR_OK;
}
Пример #4
0
static void finish_acquisition(struct dev_context *devc)
{
	struct sr_datafeed_packet packet;
	int i;

	/* Terminate session. */
	packet.type = SR_DF_END;
	sr_session_send(devc->cb_data, &packet);

	/* Remove fds from polling. */
	for (i = 0; devc->usbfd[i] != -1; i++)
		sr_source_remove(devc->usbfd[i]);
	g_free(devc->usbfd);

	devc->num_transfers = 0;
	g_free(devc->transfers);
}
Пример #5
0
/*
 * Standard sr_session_stop() API helper.
 *
 * This function can be used to simplify most (serial port based) driver's
 * dev_acquisition_stop() API callback.
 *
 * @param sdi The device instance for which acquisition should stop.
 *            Must not be NULL.
 * @param cb_data Opaque 'cb_data' pointer. Must not be NULL.
 * @param dev_close_fn Function pointer to the driver's dev_close().
 *               	  Must not be NULL.
 * @param serial The serial device instance (struct serial_dev_inst *).
 *               Must not be NULL.
 * @param prefix A driver-specific prefix string used for log messages.
 *               Must not be NULL. An empty string is allowed.
 *
 * @retval SR_OK Success.
 * @retval SR_ERR_ARG Invalid arguments.
 * @retval SR_ERR_DEV_CLOSED Device is closed.
 * @retval SR_ERR Other errors.
 */
SR_PRIV int std_dev_acquisition_stop_serial(struct sr_dev_inst *sdi,
			void *cb_data, dev_close_t dev_close_fn,
			struct sr_serial_dev_inst *serial, const char *prefix)
{
	int ret;
	struct sr_datafeed_packet packet;

	if (!prefix) {
		sr_err("Invalid prefix.");
		return SR_ERR_ARG;
	}

	if (sdi->status != SR_ST_ACTIVE) {
		sr_err("%sDevice inactive, can't stop acquisition.", prefix);
		return SR_ERR_DEV_CLOSED;
	}

	sr_dbg("%sStopping acquisition.", prefix);

	if ((ret = sr_source_remove(serial->fd)) < 0) {
		sr_err("%sFailed to remove source: %d.", prefix, ret);
		return ret;
	}

	if ((ret = dev_close_fn(sdi)) < 0) {
		sr_err("%sFailed to close device: %d.", prefix, ret);
		return ret;
	}

	/* Send SR_DF_END packet to the session bus. */
	sr_dbg("%sSending SR_DF_END packet.", prefix);
	packet.type = SR_DF_END;
	packet.payload = NULL;
	if ((ret = sr_session_send(cb_data, &packet)) < 0) {
		sr_err("%sFailed to send SR_DF_END packet: %d.", prefix, ret);
		return ret;
	}

	return SR_OK;
}
Пример #6
0
static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
{
	struct dev_context *devc;
	struct sr_serial_dev_inst *serial;

	(void)cb_data;

	devc = sdi->priv;

	if (sdi->status != SR_ST_ACTIVE) {
		sr_err("Device inactive, can't stop acquisition.");
		return SR_ERR;
	}

	g_slist_free(devc->enabled_analog_probes);
	g_slist_free(devc->enabled_digital_probes);
	devc->enabled_analog_probes = NULL;
	devc->enabled_digital_probes = NULL;
	serial = sdi->conn;
	sr_source_remove(serial->fd);

	return SR_OK;
}
Пример #7
0
static int handle_event(int fd, int revents, void *cb_data)
{
	const struct sr_dev_inst *sdi;
	struct sr_datafeed_packet packet;
	struct timeval tv;
	struct dev_context *devc;
	struct drv_context *drvc = di->priv;
	const struct libusb_pollfd **lupfd;
	int num_probes, i;
	uint32_t trigger_offset;
	uint8_t capturestate;

	(void)fd;
	(void)revents;

	sdi = cb_data;
	devc = sdi->priv;
	if (devc->dev_state == STOPPING) {
		/* We've been told to wind up the acquisition. */
		sr_dbg("Stopping acquisition.");
		/*
		 * TODO: Doesn't really cancel pending transfers so they might
		 * come in after SR_DF_END is sent.
		 */
		lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
		for (i = 0; lupfd[i]; i++)
			sr_source_remove(lupfd[i]->fd);
		free(lupfd);

		packet.type = SR_DF_END;
		sr_session_send(sdi, &packet);

		devc->dev_state = IDLE;

		return TRUE;
	}

	/* Always handle pending libusb events. */
	tv.tv_sec = tv.tv_usec = 0;
	libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv);

	/* TODO: ugh */
	if (devc->dev_state == NEW_CAPTURE) {
		if (dso_capture_start(devc) != SR_OK)
			return TRUE;
		if (dso_enable_trigger(devc) != SR_OK)
			return TRUE;
//		if (dso_force_trigger(devc) != SR_OK)
//			return TRUE;
		sr_dbg("Successfully requested next chunk.");
		devc->dev_state = CAPTURE;
		return TRUE;
	}
	if (devc->dev_state != CAPTURE)
		return TRUE;

	if ((dso_get_capturestate(devc, &capturestate, &trigger_offset)) != SR_OK)
		return TRUE;

	sr_dbg("Capturestate %d.", capturestate);
	sr_dbg("Trigger offset 0x%.6x.", trigger_offset);
	switch (capturestate) {
	case CAPTURE_EMPTY:
		if (++devc->capture_empty_count >= MAX_CAPTURE_EMPTY) {
			devc->capture_empty_count = 0;
			if (dso_capture_start(devc) != SR_OK)
				break;
			if (dso_enable_trigger(devc) != SR_OK)
				break;
//			if (dso_force_trigger(devc) != SR_OK)
//				break;
			sr_dbg("Successfully requested next chunk.");
		}
		break;
	case CAPTURE_FILLING:
		/* No data yet. */
		break;
	case CAPTURE_READY_8BIT:
		/* Remember where in the captured frame the trigger is. */
		devc->trigger_offset = trigger_offset;

		num_probes = (devc->ch1_enabled && devc->ch2_enabled) ? 2 : 1;
		/* TODO: Check malloc return value. */
		devc->framebuf = g_try_malloc(devc->framesize * num_probes * 2);
		devc->samp_buffered = devc->samp_received = 0;

		/* Tell the scope to send us the first frame. */
		if (dso_get_channeldata(sdi, receive_transfer) != SR_OK)
			break;

		/*
		 * Don't hit the state machine again until we're done fetching
		 * the data we just told the scope to send.
		 */
		devc->dev_state = FETCH_DATA;

		/* Tell the frontend a new frame is on the way. */
		packet.type = SR_DF_FRAME_BEGIN;
		sr_session_send(sdi, &packet);
		break;
	case CAPTURE_READY_9BIT:
		/* TODO */
		sr_err("Not yet supported.");
		break;
	case CAPTURE_TIMEOUT:
		/* Doesn't matter, we'll try again next time. */
		break;
	default:
		sr_dbg("Unknown capture state: %d.", capturestate);
		break;
	}

	return TRUE;
}
Пример #8
0
static int scpi_vxi_source_remove(void *priv)
{
	(void)priv;

	return sr_source_remove(-1);
}