static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data)
{
- struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
struct dev_context *devc;
if (!(devc = sdi->priv)) {
return SR_ERR_BUG;
}
- sr_dbg("Starting acquisition.");
-
devc->cb_data = cb_data;
/* Send header packet to the session bus. */
- sr_dbg("Sending SR_DF_HEADER.");
- packet.type = SR_DF_HEADER;
- packet.payload = (uint8_t *)&header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(devc->cb_data, &packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
/* Poll every 100ms, or whenever some data comes in. */
sr_source_add(devc->serial->fd, G_IO_IN, 100, agdmm_receive_data, (void *)sdi);
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data)
{
- struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
struct dev_context *devc;
int count, ret;
char *endianness;
}
/* Send header packet to the session bus. */
- sr_dbg("Sending SR_DF_HEADER packet.");
- packet.type = SR_DF_HEADER;
- packet.payload = (uint8_t *)&header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(devc->cb_data, &packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
/* Poll every 10ms, or whenever some data comes in. */
sr_source_add(devc->ufds[0].fd, devc->ufds[0].events, 10,
void *cb_data)
{
struct dev_context *devc;
- struct sr_datafeed_packet *packet;
- struct sr_datafeed_header *header;
struct clockselect_50 clockselect;
int frac, triggerpin, ret;
uint8_t triggerselect = 0;
devc->session_dev_id = cb_data;
- if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
- sr_err("%s: packet malloc failed.", __func__);
- return SR_ERR_MALLOC;
- }
-
- if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) {
- sr_err("%s: header malloc failed.", __func__);
- return SR_ERR_MALLOC;
- }
-
/* Send header packet to the session bus. */
- packet->type = SR_DF_HEADER;
- packet->payload = header;
- header->feed_version = 1;
- gettimeofday(&header->starttime, NULL);
- sr_session_send(devc->session_dev_id, packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
/* Add capture source. */
sr_source_add(0, G_IO_IN, 10, receive_data, (void *)sdi);
- g_free(header);
- g_free(packet);
-
devc->state.state = SIGMA_CAPTURE;
return SR_OK;
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data)
{
- struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
struct dev_context *devc;
if (!(devc = sdi->priv)) {
return SR_ERR_BUG;
}
- sr_dbg("Starting acquisition.");
-
devc->cb_data = cb_data;
/*
devc->starttime = g_get_monotonic_time();
/* Send header packet to the session bus. */
- sr_dbg("Sending SR_DF_HEADER.");
- packet.type = SR_DF_HEADER;
- packet.payload = &header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(devc->cb_data, &packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
/* Poll every 50ms, or whenever some data comes in. */
sr_source_add(devc->serial->fd, G_IO_IN, 50,
void *cb_data)
{
struct dev_context *devc;
- struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
uint8_t buf[4];
int bytes_written;
return SR_ERR;
}
- sr_dbg("Starting acquisition.");
-
/* Fill acquisition parameters into buf[]. */
buf[0] = devc->divcount;
buf[1] = 0xff; /* This byte must always be 0xff. */
return SR_ERR;
}
- sr_dbg("Acquisition started successfully.");
+ sr_dbg("Hardware acquisition started successfully.");
devc->session_dev_id = cb_data;
/* Send header packet to the session bus. */
- sr_dbg("Sending SR_DF_HEADER.");
- packet.type = SR_DF_HEADER;
- packet.payload = &header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(devc->session_dev_id, &packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
/* Time when we should be done (for detecting trigger timeouts). */
devc->done = (devc->divcount + 1) * 0.08388608 + time(NULL)
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data)
{
- struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
struct dev_context *devc;
if (!(devc = sdi->priv)) {
return SR_ERR_BUG;
}
- sr_dbg("Starting acquisition.");
-
devc->cb_data = cb_data;
/* Send header packet to the session bus. */
- sr_dbg("Sending SR_DF_HEADER.");
- packet.type = SR_DF_HEADER;
- packet.payload = (uint8_t *)&header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(devc->cb_data, &packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
/* Poll every 150ms, or whenever some data comes in. */
sr_source_add(devc->serial->fd, G_IO_IN, 150, colead_slm_receive_data,
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data)
{
- struct sr_datafeed_packet *packet;
- struct sr_datafeed_header *header;
struct dev_context *devc;
(void)sdi;
- sr_dbg("Starting acquisition.");
-
/* TODO: 'devc' is never g_free()'d? */
if (!(devc = g_try_malloc(sizeof(struct dev_context)))) {
sr_err("%s: devc malloc failed", __func__);
sr_session_source_add_channel(devc->channels[0], G_IO_IN | G_IO_ERR,
40, receive_data, devc);
- if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
- sr_err("%s: packet malloc failed", __func__);
- return SR_ERR_MALLOC;
- }
-
- if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) {
- sr_err("%s: header malloc failed", __func__);
- return SR_ERR_MALLOC;
- }
-
- packet->type = SR_DF_HEADER;
- packet->payload = header;
- header->feed_version = 1;
- gettimeofday(&header->starttime, NULL);
- sr_session_send(devc->session_dev_id, packet);
+ /* Send header packet to the session bus. */
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
/* We use this timestamp to decide how many more samples to send. */
devc->starttime = g_get_monotonic_time();
- g_free(header);
- g_free(packet);
-
return SR_OK;
}
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data)
{
- struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
struct dev_context *devc;
if (!(devc = sdi->priv)) {
return SR_ERR_BUG;
}
- sr_dbg("Starting acquisition.");
-
devc->cb_data = cb_data;
/* Send header packet to the session bus. */
- sr_dbg("Sending SR_DF_HEADER.");
- packet.type = SR_DF_HEADER;
- packet.payload = (uint8_t *)&header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(devc->cb_data, &packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
/* Poll every 100ms, or whenever some data comes in. */
sr_source_add(devc->serial->fd, G_IO_IN, 50, fluke_receive_data, (void *)sdi);
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data)
{
- struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
struct dev_context *devc;
struct drv_context *drvc;
struct libusb_transfer *transfer;
timeout, receive_data, NULL);
free(lupfd); /* NOT g_free()! */
- packet.type = SR_DF_HEADER;
- packet.payload = &header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(cb_data, &packet);
+ /* Send header packet to the session bus. */
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
if ((ret = command_start_acquisition(devc->usb->devhdl,
devc->cur_samplerate, devc->sample_wide)) != SR_OK) {
void *cb_data)
{
const struct libusb_pollfd **lupfd;
- struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
struct dev_context *devc;
struct drv_context *drvc = di->priv;
int i;
free(lupfd);
/* Send header packet to the session bus. */
- packet.type = SR_DF_HEADER;
- packet.payload = (unsigned char *)&header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(cb_data, &packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
return SR_OK;
}
void *cb_data)
{
struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
struct dev_context *devc;
struct drv_context *drvc = di->priv;
struct libusb_transfer *xfer_in, *xfer_out;
sr_dbg("Starting log retrieval.");
/* Send header packet to the session bus. */
- sr_dbg("Sending SR_DF_HEADER.");
- packet.type = SR_DF_HEADER;
- packet.payload = (uint8_t *)&header;
- header.feed_version = 1;
- sr_session_send(devc->cb_data, &packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
if (devc->logged_samples == 0) {
/* This ensures the frontend knows the session is done. */
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data)
{
- struct sr_datafeed_packet *packet;
- struct sr_datafeed_header *header;
struct dev_context *devc;
int ret = SR_ERR;
if (ret != SR_OK)
return ret;
- sr_source_add(devc->serial->fd, G_IO_IN, -1, mso_receive_data, cb_data);
-
- if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
- sr_err("Datafeed packet malloc failed.");
- return SR_ERR_MALLOC;
- }
+ /* Send header packet to the session bus. */
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
- if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) {
- sr_err("Datafeed header malloc failed.");
- g_free(packet);
- return SR_ERR_MALLOC;
- }
-
- packet->type = SR_DF_HEADER;
- packet->payload = (unsigned char *)header;
- header->feed_version = 1;
- gettimeofday(&header->starttime, NULL);
- sr_session_send(cb_data, packet);
-
- g_free(header);
- g_free(packet);
+ sr_source_add(devc->serial->fd, G_IO_IN, -1, mso_receive_data, cb_data);
return SR_OK;
}
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data, int idx)
{
- struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
struct dev_context *devc;
devc = sdi->priv;
devc->cb_data = cb_data;
- sr_dbg("Starting acquisition.");
-
devc->num_samples = 0;
devc->starttime = g_get_monotonic_time();
/* Send header packet to the session bus. */
- sr_dbg("Sending SR_DF_HEADER.");
- packet.type = SR_DF_HEADER;
- packet.payload = (uint8_t *)&header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(devc->cb_data, &packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
/* Poll every 100ms, or whenever some data comes in. */
sr_source_add(devc->serial->fd, G_IO_IN, 100,
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data)
{
- struct sr_datafeed_packet *packet;
- struct sr_datafeed_header *header;
struct dev_context *devc;
uint32_t trigger_config[4];
uint32_t data;
if (send_shortcommand(devc->serial, CMD_RUN) != SR_OK)
return SR_ERR;
+ /* Send header packet to the session bus. */
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
+
sr_source_add(devc->serial->fd, G_IO_IN, -1, ols_receive_data,
cb_data);
- if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
- sr_err("Datafeed packet malloc failed.");
- return SR_ERR_MALLOC;
- }
-
- if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) {
- sr_err("Datafeed header malloc failed.");
- g_free(packet);
- return SR_ERR_MALLOC;
- }
-
- /* Send header packet to the session bus. */
- packet->type = SR_DF_HEADER;
- packet->payload = (unsigned char *)header;
- header->feed_version = 1;
- gettimeofday(&header->starttime, NULL);
- sr_session_send(cb_data, packet);
-
- g_free(header);
- g_free(packet);
-
return SR_OK;
}
void *cb_data)
{
struct dev_context *devc;
- struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
char buf[256];
int len;
sr_source_add(devc->fd, G_IO_IN, 50, rigol_ds1xx2_receive_data, (void *)sdi);
/* Send header packet to the session bus. */
- packet.type = SR_DF_HEADER;
- packet.payload = (unsigned char *)&header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(cb_data, &packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
/* Hardcoded to CH1 only. */
devc->enabled_probes = g_slist_append(NULL, sdi->probes->data);
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data, int dmm)
{
- struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
struct dev_context *devc;
if (!(devc = sdi->priv)) {
return SR_ERR_BUG;
}
- sr_dbg("Starting acquisition.");
-
devc->cb_data = cb_data;
/*
devc->starttime = g_get_monotonic_time();
/* Send header packet to the session bus. */
- sr_dbg("Sending SR_DF_HEADER.");
- packet.type = SR_DF_HEADER;
- packet.payload = (uint8_t *)&header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(devc->cb_data, &packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
/* Poll every 50ms, or whenever some data comes in. */
sr_source_add(devc->serial->fd, G_IO_IN, 50,
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data)
{
- struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
struct dev_context *devc;
devc = sdi->priv;
devc->cb_data = cb_data;
/* Send header packet to the session bus. */
- sr_dbg("Sending SR_DF_HEADER.");
- packet.type = SR_DF_HEADER;
- packet.payload = (uint8_t *)&header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(devc->cb_data, &packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
/* Poll every 500ms, or whenever some data comes in. */
sr_source_add(devc->serial->fd, G_IO_IN, 500,
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data)
{
- struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
struct dev_context *devc;
devc = sdi->priv;
- sr_dbg("Starting acquisition.");
-
devc->cb_data = cb_data;
/* Send header packet to the session bus. */
- sr_dbg("Sending SR_DF_HEADER.");
- packet.type = SR_DF_HEADER;
- packet.payload = (uint8_t *)&header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(devc->cb_data, &packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
if (!strcmp(di->name, "uni-t-ut61d")) {
sr_source_add(0, 0, 10 /* poll_timeout */,
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data)
{
- struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
struct dev_context *devc;
struct drv_context *drvc = di->priv;
const struct libusb_pollfd **pfd;
return SR_ERR;
}
- sr_dbg("Starting acquisition.");
-
devc = sdi->priv;
devc->cb_data = cb_data;
/* Send header packet to the session bus. */
- sr_dbg("Sending SR_DF_HEADER.");
- packet.type = SR_DF_HEADER;
- packet.payload = (uint8_t *)&header;
- header.feed_version = 1;
- sr_session_send(devc->cb_data, &packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
for (i = 0; pfd[i]; i++) {
{
struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
- struct sr_datafeed_header header;
//uint64_t samples_read;
int res;
unsigned int packet_num;
sr_info("Trigger address = 0x%x.",
analyzer_get_trigger_address(devc->usb->devhdl));
- packet.type = SR_DF_HEADER;
- packet.payload = &header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(cb_data, &packet);
+ /* Send header packet to the session bus. */
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
if (!(buf = g_try_malloc(PACKET_SIZE))) {
sr_err("Packet buffer malloc failed.");
static int loadfile(struct sr_input *in, const char *filename)
{
- struct sr_datafeed_header header;
struct sr_datafeed_packet packet;
struct sr_datafeed_meta meta;
struct sr_datafeed_logic logic;
num_probes = g_slist_length(in->sdi->probes);
/* Send header packet to the session bus. */
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- packet.type = SR_DF_HEADER;
- packet.payload = &header;
- sr_session_send(in->sdi, &packet);
+ std_session_send_df_header(in->sdi, DRIVER_LOG_DOMAIN);
if (ctx->samplerate) {
packet.type = SR_DF_META;
static int loadfile(struct sr_input *in, const char *filename)
{
- struct sr_datafeed_header header;
struct sr_datafeed_packet packet;
struct sr_datafeed_meta meta;
struct sr_datafeed_logic logic;
sr_dbg("%s: samplerate is %" PRIu64, __func__, samplerate);
/* Send header packet to the session bus. */
- sr_dbg("%s: sending SR_DF_HEADER packet", __func__);
- packet.type = SR_DF_HEADER;
- packet.payload = &header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(in->sdi, &packet);
+ std_session_send_df_header(in->sdi, DRIVER_LOG_DOMAIN);
/* Send metadata about the SR_DF_LOGIC packets to come. */
packet.type = SR_DF_META;
static int loadfile(struct sr_input *in, const char *filename)
{
- struct sr_datafeed_header header;
struct sr_datafeed_packet packet;
struct sr_datafeed_meta meta;
struct sr_config *src;
}
/* Send header packet to the session bus. */
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- packet.type = SR_DF_HEADER;
- packet.payload = &header;
- sr_session_send(in->sdi, &packet);
+ std_session_send_df_header(in->sdi, DRIVER_LOG_DOMAIN);
/* Send metadata about the SR_DF_LOGIC packets to come. */
packet.type = SR_DF_META;
SR_PRIV int std_hw_init(struct sr_context *sr_ctx, struct sr_dev_driver *di,
const char *prefix);
+SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi,
+ const char *prefix);
+
/*--- hardware/common/serial.c ----------------------------------------------*/
enum {
{
struct zip_stat zs;
struct session_vdev *vdev;
- struct sr_datafeed_header *header;
- struct sr_datafeed_packet *packet;
int ret;
vdev = sdi->priv;
return SR_ERR;
}
+ /* Send header packet to the session bus. */
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
+
/* freewheeling source */
sr_session_source_add(-1, 0, 0, receive_data, cb_data);
- if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
- sr_err("%s: packet malloc failed", __func__);
- return SR_ERR_MALLOC;
- }
-
- if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) {
- sr_err("%s: header malloc failed", __func__);
- return SR_ERR_MALLOC;
- }
-
- /* Send header packet to the session bus. */
- packet->type = SR_DF_HEADER;
- packet->payload = (unsigned char *)header;
- header->feed_version = 1;
- gettimeofday(&header->starttime, NULL);
- sr_session_send(cb_data, packet);
-
- g_free(header);
- g_free(packet);
-
return SR_OK;
}
return SR_OK;
}
+
+/**
+ * Standard API helper for sending an SR_DF_HEADER packet.
+ *
+ * This function can be used to simplify most driver's
+ * hw_dev_acquisition_start() API callback.
+ *
+ * @param sdi The device instance to use.
+ * @param prefix A driver-specific prefix string used for log messages.
+ * Must not be NULL. An empty string is allowed.
+ *
+ * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or
+ * SR_ERR upon other errors.
+ */
+SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi,
+ const char *prefix)
+{
+ int ret;
+ struct sr_datafeed_packet packet;
+ struct sr_datafeed_header header;
+
+ if (!prefix) {
+ sr_err("Invalid prefix.");
+ return SR_ERR_ARG;
+ }
+
+ sr_dbg("%sStarting acquisition.", prefix);
+
+ /* Send header packet to the session bus. */
+ sr_dbg("%sSending SR_DF_HEADER packet.", prefix);
+ packet.type = SR_DF_HEADER;
+ packet.payload = (uint8_t *)&header;
+ header.feed_version = 1;
+ gettimeofday(&header.starttime, NULL);
+
+ if ((ret = sr_session_send(sdi, &packet)) < 0) {
+ sr_err("%sFailed to send header packet: %d.", prefix, ret);
+ return ret;
+ }
+
+ return SR_OK;
+}