session_driver.c \
hwplugin.c \
filter.c \
- strutil.c
+ strutil.c \
+ log.c
libsigrok_la_LIBADD = \
$(LIBOBJS) \
#include <stdio.h>
#include <glib.h>
#include <sigrok.h>
+#include <sigrok-internal.h>
extern struct sr_global *global;
{
int num_devices, num_probes, i;
- g_message("initializing %s plugin", plugin->name);
+ sr_info("initializing %s plugin", plugin->name);
num_devices = plugin->init(NULL);
for (i = 0; i < num_devices; i++) {
num_probes = (int)plugin->get_device_info(i, SR_DI_NUM_PROBES);
err = snd_pcm_open(&alsa->capture_handle, AUDIO_DEV,
SND_PCM_STREAM_CAPTURE, 0);
if (err < 0) {
- g_warning("cannot open audio device %s (%s)", AUDIO_DEV,
+ sr_warn("cannot open audio device %s (%s)", AUDIO_DEV,
snd_strerror(err));
return SR_ERR;
}
err = snd_pcm_hw_params_malloc(&alsa->hw_params);
if (err < 0) {
- g_warning("cannot allocate hardware parameter structure (%s)",
+ sr_warn("cannot allocate hardware parameter structure (%s)",
snd_strerror(err));
return SR_ERR;
}
err = snd_pcm_hw_params_any(alsa->capture_handle, alsa->hw_params);
if (err < 0) {
- g_warning("cannot initialize hardware parameter structure (%s)",
+ sr_warn("cannot initialize hardware parameter structure (%s)",
snd_strerror(err));
return SR_ERR;
}
count = snd_pcm_readi(alsa->capture_handle, inb,
MIN(4096/4, alsa->limit_samples));
if (count < 1) {
- g_warning("Failed to read samples");
+ sr_warn("Failed to read samples");
return FALSE;
}
err = snd_pcm_hw_params_set_access(alsa->capture_handle,
alsa->hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
if (err < 0) {
- g_warning("cannot set access type (%s)", snd_strerror(err));
+ sr_warn("cannot set access type (%s)", snd_strerror(err));
return SR_ERR;
}
err = snd_pcm_hw_params_set_format(alsa->capture_handle,
alsa->hw_params, SND_PCM_FORMAT_S16_LE);
if (err < 0) {
- g_warning("cannot set sample format (%s)", snd_strerror(err));
+ sr_warn("cannot set sample format (%s)", snd_strerror(err));
return SR_ERR;
}
err = snd_pcm_hw_params_set_rate_near(alsa->capture_handle,
alsa->hw_params, (unsigned int *) &alsa->cur_rate, 0);
if (err < 0) {
- g_warning("cannot set sample rate (%s)", snd_strerror(err));
+ sr_warn("cannot set sample rate (%s)", snd_strerror(err));
return SR_ERR;
}
err = snd_pcm_hw_params_set_channels(alsa->capture_handle,
alsa->hw_params, NUM_PROBES);
if (err < 0) {
- g_warning("cannot set channel count (%s)", snd_strerror(err));
+ sr_warn("cannot set channel count (%s)", snd_strerror(err));
return SR_ERR;
}
err = snd_pcm_hw_params(alsa->capture_handle, alsa->hw_params);
if (err < 0) {
- g_warning("cannot set parameters (%s)", snd_strerror(err));
+ sr_warn("cannot set parameters (%s)", snd_strerror(err));
return SR_ERR;
}
err = snd_pcm_prepare(alsa->capture_handle);
if (err < 0) {
- g_warning("cannot prepare audio interface for use (%s)",
+ sr_warn("cannot prepare audio interface for use (%s)",
snd_strerror(err));
return SR_ERR;
}
count = snd_pcm_poll_descriptors_count(alsa->capture_handle);
if (count < 1) {
- g_warning("Unable to obtain poll descriptors count");
+ sr_warn("Unable to obtain poll descriptors count");
return SR_ERR;
}
err = snd_pcm_poll_descriptors(alsa->capture_handle, ufds, count);
if (err < 0) {
- g_warning("Unable to obtain poll descriptors (%s)",
+ sr_warn("Unable to obtain poll descriptors (%s)",
snd_strerror(err));
free(ufds);
return SR_ERR;
#include <string.h>
#include <zlib.h>
#include <sigrok.h>
+#include <sigrok-internal.h>
#include "asix-sigma.h"
#define USB_VENDOR 0xa600
ret = ftdi_read_data(&sigma->ftdic, (unsigned char *)buf, size);
if (ret < 0) {
- g_warning("ftdi_read_data failed: %s",
- ftdi_get_error_string(&sigma->ftdic));
+ sr_warn("ftdi_read_data failed: %s",
+ ftdi_get_error_string(&sigma->ftdic));
}
return ret;
ret = ftdi_write_data(&sigma->ftdic, (unsigned char *)buf, size);
if (ret < 0) {
- g_warning("ftdi_write_data failed: %s",
- ftdi_get_error_string(&sigma->ftdic));
+ sr_warn("ftdi_write_data failed: %s",
+ ftdi_get_error_string(&sigma->ftdic));
} else if ((size_t) ret != size) {
- g_warning("ftdi_write_data did not complete write\n");
+ sr_warn("ftdi_write_data did not complete write\n");
}
return ret;
uint8_t value;
if (1 != sigma_read_register(reg, &value, 1, sigma)) {
- g_warning("Sigma_get_register: 1 byte expected");
+ sr_warn("sigma_get_register: 1 byte expected");
return 0;
}
f = g_fopen(filename, "rb");
if (!f) {
- g_warning("g_fopen(\"%s\", \"rb\")", filename);
+ sr_warn("g_fopen(\"%s\", \"rb\")", filename);
return -1;
}
if (-1 == fseek(f, 0, SEEK_END)) {
- g_warning("fseek on %s failed", filename);
+ sr_warn("fseek on %s failed", filename);
fclose(f);
return -1;
}
firmware = g_malloc(buffer_size);
if (!compressed_buf || !firmware) {
- g_warning("Error allocating buffers");
+ sr_warn("Error allocating buffers");
return -1;
}
if (ret < 0) {
g_free(compressed_buf);
g_free(firmware);
- g_warning("Could not unpack Sigma firmware. (Error %d)\n", ret);
+ sr_warn("Could not unpack Sigma firmware. (Error %d)\n", ret);
return -1;
}
*buf = p = (unsigned char *)g_malloc(*buf_size);
if (!p) {
- g_warning("Error allocating buffers");
+ sr_warn("Error allocating buffers");
return -1;
}
if (offset != *buf_size) {
g_free(*buf);
- g_warning("Error reading firmware %s "
- "offset=%ld, file_size=%ld, buf_size=%zd\n",
- filename, offset, file_size, *buf_size);
+ sr_warn("Error reading firmware %s "
+ "offset=%ld, file_size=%ld, buf_size=%zd\n",
+ filename, offset, file_size, *buf_size);
return -1;
}
/* Make sure it's an ASIX SIGMA. */
if ((ret = ftdi_usb_open_desc(&sigma->ftdic,
USB_VENDOR, USB_PRODUCT, USB_DESCRIPTION, NULL)) < 0) {
- g_warning("ftdi_usb_open failed: %s",
- ftdi_get_error_string(&sigma->ftdic));
+ sr_warn("ftdi_usb_open failed: %s",
+ ftdi_get_error_string(&sigma->ftdic));
return 0;
}
if ((ret = ftdi_set_bitmode(&sigma->ftdic, 0xdf, BITMODE_BITBANG)) < 0) {
- g_warning("ftdi_set_bitmode failed: %s",
- ftdi_get_error_string(&sigma->ftdic));
+ sr_warn("ftdi_set_bitmode failed: %s",
+ ftdi_get_error_string(&sigma->ftdic));
return 0;
}
/* Four times the speed of sigmalogan - Works well. */
if ((ret = ftdi_set_baudrate(&sigma->ftdic, 750000)) < 0) {
- g_warning("ftdi_set_baudrate failed: %s",
- ftdi_get_error_string(&sigma->ftdic));
+ sr_warn("ftdi_set_baudrate failed: %s",
+ ftdi_get_error_string(&sigma->ftdic));
return 0;
}
firmware_files[firmware_idx]);
if (-1 == bin2bitbang(firmware_path, &buf, &buf_size)) {
- g_warning("An error occured while reading the firmware: %s",
- firmware_path);
+ sr_warn("An error occured while reading the firmware: %s",
+ firmware_path);
return SR_ERR;
}
g_free(buf);
if ((ret = ftdi_set_bitmode(&sigma->ftdic, 0x00, BITMODE_RESET)) < 0) {
- g_warning("ftdi_set_bitmode failed: %s",
- ftdi_get_error_string(&sigma->ftdic));
+ sr_warn("ftdi_set_bitmode failed: %s",
+ ftdi_get_error_string(&sigma->ftdic));
return SR_ERR;
}
ret = sigma_read(result, 3, sigma);
if (ret != 3 ||
result[0] != 0xa6 || result[1] != 0x55 || result[2] != 0xaa) {
- g_warning("Configuration failed. Invalid reply received.");
+ sr_warn("Configuration failed. Invalid reply received.");
return SR_ERR;
}
if ((ret = ftdi_usb_open_desc(&sigma->ftdic,
USB_VENDOR, USB_PRODUCT, USB_DESCRIPTION, NULL)) < 0) {
- g_warning("ftdi_usb_open failed: %s",
+ sr_warn("ftdi_usb_open failed: %s",
ftdi_get_error_string(&sigma->ftdic));
return 0;
sigma->samples_per_event = 16 / sigma->num_probes;
sigma->state.state = SIGMA_IDLE;
- g_message("Firmware uploaded");
+ sr_info("Firmware uploaded");
return ret;
}
if (sigma->cur_samplerate >= SR_MHZ(100)) {
/* Fast trigger support. */
if (trigger_set) {
- g_warning("Asix Sigma only supports a single "
- "pin trigger in 100 and 200 "
- "MHz mode.");
+ sr_warn("Asix Sigma only supports a single "
+ "pin trigger in 100 and 200MHz mode.");
return SR_ERR;
}
if (probe->trigger[0] == 'f')
else if (probe->trigger[0] == 'r')
sigma->trigger.risingmask |= probebit;
else {
- g_warning("Asix Sigma only supports "
- "rising/falling trigger in 100 "
- "and 200 MHz mode.");
+ sr_warn("Asix Sigma only supports "
+ "rising/falling trigger in 100 "
+ "and 200MHz mode.");
return SR_ERR;
}
* does not permit ORed triggers.
*/
if (trigger_set > 1) {
- g_warning("Asix Sigma only supports 1 rising/"
- "falling triggers.");
+ sr_warn("Asix Sigma only supports 1 rising/"
+ "falling triggers.");
return SR_ERR;
}
}
newchunks = MIN(chunks_per_read,
numchunks - sigma->state.chunks_downloaded);
- g_message("Downloading sample data: %.0f %%",
- 100.0 * sigma->state.chunks_downloaded / numchunks);
+ sr_info("Downloading sample data: %.0f %%",
+ 100.0 * sigma->state.chunks_downloaded / numchunks);
bufsz = sigma_read_dram(sigma->state.chunks_downloaded,
newchunks, buf, sigma);
#include <ftdi.h>
#include <sigrok.h>
+#include <sigrok-internal.h>
#define USB_VENDOR_ID 0x0403
#define USB_PRODUCT_ID 0x6001
return 1;
}
- g_warning("la8: %s: invalid samplerate (%" PRIu64 "Hz)",
- __func__, samplerate);
+ sr_warn("la8: %s: invalid samplerate (%" PRIu64 "Hz)",
+ __func__, samplerate);
return 0;
}
static uint8_t samplerate_to_divcount(uint64_t samplerate)
{
if (samplerate == 0) {
- g_warning("la8: %s: samplerate was 0", __func__);
+ sr_warn("la8: %s: samplerate was 0", __func__);
return 0xff;
}
if (!is_valid_samplerate(samplerate)) {
- g_warning("la8: %s: can't get divcount, samplerate invalid",
- __func__);
+ sr_warn("la8: %s: can't get divcount, samplerate invalid",
+ __func__);
return 0xff;
}
int bytes_written;
if (!la8) {
- g_warning("la8: %s: la8 was NULL", __func__);
+ sr_warn("la8: %s: la8 was NULL", __func__);
return SR_ERR_ARG;
}
if (!la8->ftdic) {
- g_warning("la8: %s: la8->ftdic was NULL", __func__);
+ sr_warn("la8: %s: la8->ftdic was NULL", __func__);
return SR_ERR_ARG;
}
if (!buf) {
- g_warning("la8: %s: buf was NULL", __func__);
+ sr_warn("la8: %s: buf was NULL", __func__);
return SR_ERR_ARG;
}
if (size < 0) {
- g_warning("la8: %s: size was < 0", __func__);
+ sr_warn("la8: %s: size was < 0", __func__);
return SR_ERR_ARG;
}
bytes_written = ftdi_write_data(la8->ftdic, buf, size);
if (bytes_written < 0) {
- g_warning("la8: %s: ftdi_write_data: (%d) %s", __func__,
- bytes_written, ftdi_get_error_string(la8->ftdic));
+ sr_warn("la8: %s: ftdi_write_data: (%d) %s", __func__,
+ bytes_written, ftdi_get_error_string(la8->ftdic));
(void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
} else if (bytes_written != size) {
- g_warning("la8: %s: bytes to write: %d, bytes written: %d",
- __func__, size, bytes_written);
+ sr_warn("la8: %s: bytes to write: %d, bytes written: %d",
+ __func__, size, bytes_written);
(void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
}
int bytes_read;
if (!la8) {
- g_warning("la8: %s: la8 was NULL", __func__);
+ sr_warn("la8: %s: la8 was NULL", __func__);
return SR_ERR_ARG;
}
if (!la8->ftdic) {
- g_warning("la8: %s: la8->ftdic was NULL", __func__);
+ sr_warn("la8: %s: la8->ftdic was NULL", __func__);
return SR_ERR_ARG;
}
if (!buf) {
- g_warning("la8: %s: buf was NULL", __func__);
+ sr_warn("la8: %s: buf was NULL", __func__);
return SR_ERR_ARG;
}
if (size <= 0) {
- g_warning("la8: %s: size was <= 0", __func__);
+ sr_warn("la8: %s: size was <= 0", __func__);
return SR_ERR_ARG;
}
bytes_read = ftdi_read_data(la8->ftdic, buf, size);
if (bytes_read < 0) {
- g_warning("la8: %s: ftdi_read_data: (%d) %s", __func__,
- bytes_read, ftdi_get_error_string(la8->ftdic));
+ sr_warn("la8: %s: ftdi_read_data: (%d) %s", __func__,
+ bytes_read, ftdi_get_error_string(la8->ftdic));
} else if (bytes_read != size) {
- // g_warning("la8: %s: bytes to read: %d, bytes read: %d",
- // __func__, size, bytes_read);
+ // sr_warn("la8: %s: bytes to read: %d, bytes read: %d",
+ // __func__, size, bytes_read);
}
return bytes_read;
int ret;
if (!la8) {
- g_warning("la8: %s: la8 was NULL", __func__);
+ sr_warn("la8: %s: la8 was NULL", __func__);
return SR_ERR_ARG;
}
if (!la8->ftdic) {
- g_warning("la8: %s: la8->ftdic was NULL", __func__);
+ sr_warn("la8: %s: la8->ftdic was NULL", __func__);
return SR_ERR_ARG;
}
if ((ret = ftdi_usb_close(la8->ftdic)) < 0) {
- g_warning("la8: %s: ftdi_usb_close: (%d) %s",
- __func__, ret, ftdi_get_error_string(la8->ftdic));
+ sr_warn("la8: %s: ftdi_usb_close: (%d) %s",
+ __func__, ret, ftdi_get_error_string(la8->ftdic));
}
return ret;
uint8_t buf[8] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
int ret;
- g_debug("la8: entering %s", __func__);
+ sr_dbg("la8: entering %s", __func__);
if (!la8) {
- g_warning("la8: %s: la8 was NULL", __func__);
+ sr_warn("la8: %s: la8 was NULL", __func__);
return SR_ERR_ARG;
}
if (!la8->ftdic) {
- g_warning("la8: %s: la8->ftdic was NULL", __func__);
+ sr_warn("la8: %s: la8->ftdic was NULL", __func__);
return SR_ERR_ARG;
}
if (la8->ftdic->usb_dev) {
/* Reset the LA8 sequencer logic, then wait 100ms. */
- g_debug("la8: resetting sequencer logic");
+ sr_dbg("la8: resetting sequencer logic");
(void) la8_write(la8, buf, 8); /* Ignore errors. */
g_usleep(100 * 1000);
/* Purge FTDI buffers, then reset and close the FTDI device. */
- g_debug("la8: purging buffers, resetting+closing FTDI device");
+ sr_dbg("la8: purging buffers, resetting+closing FTDI device");
/* Log errors, but ignore them (i.e., don't abort). */
if ((ret = ftdi_usb_purge_buffers(la8->ftdic)) < 0)
- g_warning("la8: %s: ftdi_usb_purge_buffers: (%d) %s",
+ sr_warn("la8: %s: ftdi_usb_purge_buffers: (%d) %s",
__func__, ret, ftdi_get_error_string(la8->ftdic));
if ((ret = ftdi_usb_reset(la8->ftdic)) < 0)
- g_warning("la8: %s: ftdi_usb_reset: (%d) %s", __func__,
- ret, ftdi_get_error_string(la8->ftdic));
+ sr_warn("la8: %s: ftdi_usb_reset: (%d) %s", __func__,
+ ret, ftdi_get_error_string(la8->ftdic));
if ((ret = ftdi_usb_close(la8->ftdic)) < 0)
- g_warning("la8: %s: ftdi_usb_close: (%d) %s", __func__,
- ret, ftdi_get_error_string(la8->ftdic));
+ sr_warn("la8: %s: ftdi_usb_close: (%d) %s", __func__,
+ ret, ftdi_get_error_string(la8->ftdic));
} else {
- g_debug("la8: %s: usb_dev was NULL, nothing to do", __func__);
+ sr_dbg("la8: %s: usb_dev was NULL, nothing to do", __func__);
}
ftdi_free(la8->ftdic); /* Returns void. */
int bytes_read;
if (!la8) {
- g_warning("la8: %s: la8 was NULL", __func__);
+ sr_warn("la8: %s: la8 was NULL", __func__);
return SR_ERR_ARG;
}
if (!la8->ftdic) {
- g_warning("la8: %s: la8->ftdic was NULL", __func__);
+ sr_warn("la8: %s: la8->ftdic was NULL", __func__);
return SR_ERR_ARG;
}
- g_debug("la8: resetting the device");
+ sr_dbg("la8: resetting the device");
/*
* Purge pending read data from the FTDI hardware FIFO until
/* Reset the LA8 sequencer logic and close the USB port. */
(void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
- g_debug("la8: device reset finished");
+ sr_dbg("la8: device reset finished");
return SR_OK;
}
struct sr_device_instance *sdi;
struct la8 *la8;
- g_debug("la8: entering %s", __func__);
+ sr_dbg("la8: entering %s", __func__);
/* Avoid compiler errors. */
deviceinfo = deviceinfo;
/* Allocate memory for our private driver context. */
if (!(la8 = malloc(sizeof(struct la8)))) {
- g_warning("la8: %s: struct la8 malloc failed", __func__);
+ sr_warn("la8: %s: struct la8 malloc failed", __func__);
ret = SR_ERR_MALLOC;
goto err_free_nothing;
}
/* Allocate memory for the raw (mangled) data from the LA8. */
if (!(la8->mangled_buf = malloc(SDRAM_SIZE))) {
- g_warning("la8: %s: mangled_buf malloc failed", __func__);
+ sr_warn("la8: %s: mangled_buf malloc failed", __func__);
ret = SR_ERR_MALLOC;
goto err_free_la8;
}
/* Allocate memory where we'll store the de-mangled data. */
if (!(la8->final_buf = malloc(SDRAM_SIZE))) {
- g_warning("la8: %s: final_buf malloc failed", __func__);
+ sr_warn("la8: %s: final_buf malloc failed", __func__);
ret = SR_ERR_MALLOC;
goto err_free_mangled_buf;
}
/* Allocate memory for the FTDI context (ftdic) and initialize it. */
if (!(la8->ftdic = ftdi_new())) {
- g_warning("la8: %s: ftdi_new failed", __func__);
+ sr_warn("la8: %s: ftdi_new failed", __func__);
ret = SR_ERR; /* TODO: More specific error? */
goto err_free_final_buf;
}
/* Check for the device and temporarily open it. */
if ((ret = ftdi_usb_open_desc(la8->ftdic, USB_VENDOR_ID,
USB_PRODUCT_ID, USB_DESCRIPTION, NULL)) < 0) {
- g_warning("la8: %s: ftdi_usb_open_desc: (%d) %s",
- __func__, ret, ftdi_get_error_string(la8->ftdic));
+ sr_warn("la8: %s: ftdi_usb_open_desc: (%d) %s",
+ __func__, ret, ftdi_get_error_string(la8->ftdic));
(void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
ret = SR_ERR; /* TODO: More specific error? */
goto err_free_ftdic;
}
- g_debug("la8: found device");
+ sr_dbg("la8: found device");
/* Register the device with libsigrok. */
sdi = sr_device_instance_new(0, SR_ST_INITIALIZING,
USB_VENDOR_NAME, USB_MODEL_NAME, USB_MODEL_VERSION);
if (!sdi) {
- g_warning("la8: %s: sr_device_instance_new failed", __func__);
+ sr_warn("la8: %s: sr_device_instance_new failed", __func__);
ret = SR_ERR; /* TODO: More specific error? */
goto err_close_ftdic;
}
device_instances = g_slist_append(device_instances, sdi);
- g_debug("la8: %s finished successfully", __func__);
+ sr_dbg("la8: %s finished successfully", __func__);
/* Close device. We'll reopen it again when we need it. */
(void) la8_close(la8); /* Log, but ignore errors. */
struct la8 *la8;
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
- g_warning("la8: %s: sdi was NULL", __func__);
+ sr_warn("la8: %s: sdi was NULL", __func__);
return SR_ERR; /* TODO: SR_ERR_ARG? */
}
if (!(la8 = sdi->priv)) {
- g_warning("la8: %s: sdi->priv was NULL", __func__);
+ sr_warn("la8: %s: sdi->priv was NULL", __func__);
return SR_ERR; /* TODO: SR_ERR_ARG? */
}
- g_debug("la8: opening device");
+ sr_dbg("la8: opening device");
/* Open the device. */
if ((ret = ftdi_usb_open_desc(la8->ftdic, USB_VENDOR_ID,
USB_PRODUCT_ID, USB_DESCRIPTION, NULL)) < 0) {
- g_warning("la8: %s: ftdi_usb_open_desc: (%d) %s",
- __func__, ret, ftdi_get_error_string(la8->ftdic));
+ sr_warn("la8: %s: ftdi_usb_open_desc: (%d) %s",
+ __func__, ret, ftdi_get_error_string(la8->ftdic));
(void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
return SR_ERR;
}
- g_debug("la8: device opened successfully");
+ sr_dbg("la8: device opened successfully");
/* Purge RX/TX buffers in the FTDI chip. */
if ((ret = ftdi_usb_purge_buffers(la8->ftdic)) < 0) {
- g_warning("la8: %s: ftdi_usb_purge_buffers: (%d) %s",
- __func__, ret, ftdi_get_error_string(la8->ftdic));
+ sr_warn("la8: %s: ftdi_usb_purge_buffers: (%d) %s",
+ __func__, ret, ftdi_get_error_string(la8->ftdic));
(void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
goto err_opendev_close_ftdic;
}
- g_debug("la8: FTDI buffers purged successfully");
+ sr_dbg("la8: FTDI buffers purged successfully");
/* Enable flow control in the FTDI chip. */
if ((ret = ftdi_setflowctrl(la8->ftdic, SIO_RTS_CTS_HS)) < 0) {
- g_warning("la8: %s: ftdi_setflowcontrol: (%d) %s",
- __func__, ret, ftdi_get_error_string(la8->ftdic));
+ sr_warn("la8: %s: ftdi_setflowcontrol: (%d) %s",
+ __func__, ret, ftdi_get_error_string(la8->ftdic));
(void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
goto err_opendev_close_ftdic;
}
- g_debug("la8: FTDI flow control enabled successfully");
+ sr_dbg("la8: FTDI flow control enabled successfully");
/* Wait 100ms. */
g_usleep(100 * 1000);
struct la8 *la8;
if (!sdi) {
- g_warning("la8: %s: sdi was NULL", __func__);
+ sr_warn("la8: %s: sdi was NULL", __func__);
return SR_ERR_ARG;
}
if (!(la8 = sdi->priv)) {
- g_warning("la8: %s: sdi->priv was NULL", __func__);
+ sr_warn("la8: %s: sdi->priv was NULL", __func__);
return SR_ERR_ARG;
}
- g_debug("la8: setting samplerate");
+ sr_dbg("la8: setting samplerate");
fill_supported_samplerates_if_needed();
/* Set the new samplerate. */
la8->cur_samplerate = samplerate;
- g_debug("la8: samplerate set to %" PRIu64 "Hz", la8->cur_samplerate);
+ sr_dbg("la8: samplerate set to %" PRIu64 "Hz", la8->cur_samplerate);
return SR_OK;
}
struct la8 *la8;
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
- g_warning("la8: %s: sdi was NULL", __func__);
+ sr_warn("la8: %s: sdi was NULL", __func__);
return;
}
if (!(la8 = sdi->priv)) {
- g_warning("la8: %s: sdi->priv was NULL", __func__);
+ sr_warn("la8: %s: sdi->priv was NULL", __func__);
return;
}
- g_debug("la8: closing device");
+ sr_dbg("la8: closing device");
if (sdi->status == SR_ST_ACTIVE) {
- g_debug("la8: %s: status ACTIVE, closing device", __func__);
+ sr_dbg("la8: %s: status ACTIVE, closing device", __func__);
/* TODO: Handle or ignore errors here? */
(void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
} else {
- g_debug("la8: %s: status not ACTIVE, nothing to do", __func__);
+ sr_dbg("la8: %s: status not ACTIVE, nothing to do", __func__);
}
sdi->status = SR_ST_INACTIVE;
GSList *l;
struct sr_device_instance *sdi;
- g_debug("la8: entering %s", __func__);
+ sr_dbg("la8: entering %s", __func__);
/* Properly close all devices. */
for (l = device_instances; l; l = l->next) {
if ((sdi = l->data) == NULL) {
- g_warning("la8: %s: sdi was NULL", __func__);
+ sr_warn("la8: %s: sdi was NULL", __func__);
continue;
}
if (sdi->priv != NULL)
free(sdi->priv);
else
- g_warning("la8: %s: sdi->priv was NULL", __func__);
+ sr_warn("la8: %s: sdi->priv was NULL", __func__);
sr_device_instance_free(sdi); /* Returns void. */
}
g_slist_free(device_instances); /* Returns void. */
struct la8 *la8;
void *info;
- g_debug("la8: entering %s", __func__);
+ sr_dbg("la8: entering %s", __func__);
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
- g_warning("la8: %s: sdi was NULL", __func__);
+ sr_warn("la8: %s: sdi was NULL", __func__);
return NULL;
}
if (!(la8 = sdi->priv)) {
- g_warning("la8: %s: sdi->priv was NULL", __func__);
+ sr_warn("la8: %s: sdi->priv was NULL", __func__);
return NULL;
}
break;
default:
/* Unknown device info ID, return NULL. */
- g_warning("la8: %s: Unknown device info ID", __func__);
+ sr_warn("la8: %s: Unknown device info ID", __func__);
info = NULL;
break;
}
struct sr_device_instance *sdi;
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
- g_warning("la8: %s: sdi was NULL, device not found", __func__);
+ sr_warn("la8: %s: sdi was NULL, device not found", __func__);
return SR_ST_NOT_FOUND;
}
- g_debug("la8: %s: returning status %d", __func__, sdi->status);
+ sr_dbg("la8: %s: returning status %d", __func__, sdi->status);
return sdi->status;
}
static int *hw_get_capabilities(void)
{
- g_debug("la8: entering %s", __func__);
+ sr_dbg("la8: entering %s", __func__);
return capabilities;
}
struct sr_device_instance *sdi;
struct la8 *la8;
- g_debug("la8: entering %s", __func__);
+ sr_dbg("la8: entering %s", __func__);
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
- g_warning("la8: %s: sdi was NULL", __func__);
+ sr_warn("la8: %s: sdi was NULL", __func__);
return SR_ERR; /* TODO: SR_ERR_ARG? */
}
if (!(la8 = sdi->priv)) {
- g_warning("la8: %s: sdi->priv was NULL", __func__);
+ sr_warn("la8: %s: sdi->priv was NULL", __func__);
return SR_ERR; /* TODO: SR_ERR_ARG? */
}
case SR_HWCAP_SAMPLERATE:
if (set_samplerate(sdi, *(uint64_t *)value) == SR_ERR)
return SR_ERR;
- g_debug("la8: SAMPLERATE = %" PRIu64, la8->cur_samplerate);
+ sr_dbg("la8: SAMPLERATE = %" PRIu64, la8->cur_samplerate);
break;
case SR_HWCAP_PROBECONFIG:
/* Nothing to do, but this entry must exist. Fix this. */
/* TODO? */
- g_debug("la8: %s: SR_HWCAP_PROBECONFIG called", __func__);
+ sr_dbg("la8: %s: SR_HWCAP_PROBECONFIG called", __func__);
return SR_OK;
break;
case SR_HWCAP_LIMIT_MSEC:
if (*(uint64_t *)value == 0) {
- g_warning("la8: %s: LIMIT_MSEC can't be 0", __func__);
+ sr_warn("la8: %s: LIMIT_MSEC can't be 0", __func__);
return SR_ERR;
}
la8->limit_msec = *(uint64_t *)value;
- g_debug("la8: LIMIT_MSEC = %" PRIu64, la8->limit_msec);
+ sr_dbg("la8: LIMIT_MSEC = %" PRIu64, la8->limit_msec);
break;
case SR_HWCAP_LIMIT_SAMPLES:
if (*(uint64_t *)value < MIN_NUM_SAMPLES) {
- g_warning("la8: %s: LIMIT_SAMPLES too small", __func__);
+ sr_warn("la8: %s: LIMIT_SAMPLES too small", __func__);
return SR_ERR;
}
la8->limit_samples = *(uint64_t *)value;
- g_debug("la8: LIMIT_SAMPLES = %" PRIu64, la8->limit_samples);
+ sr_dbg("la8: LIMIT_SAMPLES = %" PRIu64, la8->limit_samples);
break;
default:
/* Unknown capability, return SR_ERR. */
- g_warning("la8: %s: Unknown capability", __func__);
+ sr_warn("la8: %s: Unknown capability", __func__);
return SR_ERR;
break;
}
time_t now;
if (!la8) {
- g_warning("la8: %s: la8 was NULL", __func__);
+ sr_warn("la8: %s: la8 was NULL", __func__);
return SR_ERR_ARG;
}
if (!la8->ftdic) {
- g_warning("la8: %s: la8->ftdic was NULL", __func__);
+ sr_warn("la8: %s: la8->ftdic was NULL", __func__);
return SR_ERR_ARG;
}
- // g_debug("la8: %s: reading block %d", __func__, la8->block_counter);
+ // sr_dbg("la8: %s: reading block %d", __func__, la8->block_counter);
bytes_read = la8_read(la8, la8->mangled_buf, 4096);
/* If first block read got 0 bytes, retry until success or timeout. */
if ((bytes_read == 0) && (la8->block_counter == 0)) {
do {
- // g_debug("la8: %s: reading block 0 again", __func__);
+ // sr_dbg("la8: %s: reading block 0 again", __func__);
bytes_read = la8_read(la8, la8->mangled_buf, 4096);
/* TODO: How to handle read errors here? */
now = time(NULL);
/* Check if block read was successful or a timeout occured. */
if (bytes_read != 4096) {
- g_warning("la8: %s: trigger timed out", __func__);
+ sr_warn("la8: %s: trigger timed out", __func__);
(void) la8_reset(la8); /* Ignore errors. */
return SR_ERR;
}
/* De-mangle the data. */
- // g_debug("la8: de-mangling samples of block %d", la8->block_counter);
+ // sr_dbg("la8: de-mangling samples of block %d", la8->block_counter);
byte_offset = la8->block_counter * 4096;
m = byte_offset / (1024 * 1024);
mi = m * (1024 * 1024);
revents = revents;
if (!(sdi = user_data)) {
- g_warning("la8: %s: user_data was NULL", __func__);
+ sr_warn("la8: %s: user_data was NULL", __func__);
return FALSE;
}
if (!(la8 = sdi->priv)) {
- g_warning("la8: %s: sdi->priv was NULL", __func__);
+ sr_warn("la8: %s: sdi->priv was NULL", __func__);
return FALSE;
}
/* Get one block of data (4096 bytes). */
if ((ret = la8_read_block(la8)) < 0) {
- g_warning("la8: %s: la8_read_block error: %d", __func__, ret);
+ sr_warn("la8: %s: la8_read_block error: %d", __func__, ret);
return FALSE;
}
return TRUE;
}
- g_debug("la8: sampling finished, sending data to session bus now");
+ sr_dbg("la8: sampling finished, sending data to session bus now");
/* All data was received and demangled, send it to the session bus. */
for (i = 0; i < 2048; i++) {
/* Send a 4096 byte SR_DF_LOGIC packet to the session bus. */
- // g_debug("la8: %s: sending SR_DF_LOGIC packet", __func__);
+ // sr_dbg("la8: %s: sending SR_DF_LOGIC packet", __func__);
packet.type = SR_DF_LOGIC;
packet.length = 4096;
packet.unitsize = 1;
uint8_t buf[4];
int bytes_written;
- g_debug("la8: entering %s", __func__);
+ sr_dbg("la8: entering %s", __func__);
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
- g_warning("la8: %s: sdi was NULL", __func__);
+ sr_warn("la8: %s: sdi was NULL", __func__);
return SR_ERR; /* TODO: SR_ERR_ARG? */
}
if (!(la8 = sdi->priv)) {
- g_warning("la8: %s: sdi->priv was NULL", __func__);
+ sr_warn("la8: %s: sdi->priv was NULL", __func__);
return SR_ERR; /* TODO: SR_ERR_ARG? */
}
if (!la8->ftdic) {
- g_warning("la8: %s: la8->ftdic was NULL", __func__);
+ sr_warn("la8: %s: la8->ftdic was NULL", __func__);
return SR_ERR_ARG;
}
la8->divcount = samplerate_to_divcount(la8->cur_samplerate);
if (la8->divcount == 0xff) {
- g_warning("la8: %s: invalid divcount/samplerate", __func__);
+ sr_warn("la8: %s: invalid divcount/samplerate", __func__);
return SR_ERR;
}
bytes_written = la8_write(la8, buf, 4);
if (bytes_written < 0) {
- g_warning("la8: acquisition failed to start");
+ sr_warn("la8: acquisition failed to start");
return SR_ERR;
} else if (bytes_written != 4) {
- g_warning("la8: acquisition failed to start");
+ sr_warn("la8: acquisition failed to start");
return SR_ERR; /* TODO: Other error and return code? */
}
- g_debug("la8: acquisition started successfully");
+ sr_dbg("la8: acquisition started successfully");
la8->session_id = session_device_id;
/* Send header packet to the session bus. */
- g_debug("la8: %s: sending SR_DF_HEADER", __func__);
+ sr_dbg("la8: %s: sending SR_DF_HEADER", __func__);
packet.type = SR_DF_HEADER;
packet.length = sizeof(struct sr_datafeed_header);
packet.unitsize = 0;
struct la8 *la8;
struct sr_datafeed_packet packet;
- g_debug("la8: stopping acquisition");
+ sr_dbg("la8: stopping acquisition");
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
- g_warning("la8: %s: sdi was NULL", __func__);
+ sr_warn("la8: %s: sdi was NULL", __func__);
return;
}
if (!(la8 = sdi->priv)) {
- g_warning("la8: %s: sdi->priv was NULL", __func__);
+ sr_warn("la8: %s: sdi->priv was NULL", __func__);
return;
}
(void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
/* Send end packet to the session bus. */
- g_debug("la8: %s: sending SR_DF_END", __func__);
+ sr_dbg("la8: %s: sending SR_DF_END", __func__);
packet.type = SR_DF_END;
packet.length = 0;
packet.unitsize = 0;
* Helper functions for the Cypress EZ-USB / FX2 series chips.
*/
+#include <sigrok.h>
+#include <sigrok-internal.h>
#include <libusb.h>
#include <glib.h>
#include <glib/gstdio.h>
int err;
unsigned char buf[1];
- g_message("setting CPU reset mode %s...", set_clear ? "on" : "off");
+ sr_info("setting CPU reset mode %s...", set_clear ? "on" : "off");
buf[0] = set_clear ? 1 : 0;
err = libusb_control_transfer(hdl, LIBUSB_REQUEST_TYPE_VENDOR, 0xa0,
0xe600, 0x0000, buf, 1, 100);
if (err < 0)
- g_warning("Unable to send control request: %d", err);
+ sr_warn("Unable to send control request: %d", err);
return err;
}
int offset, chunksize, err, result;
unsigned char buf[4096];
- g_message("Uploading firmware at %s", filename);
+ sr_info("Uploading firmware at %s", filename);
if ((fw = g_fopen(filename, "rb")) == NULL) {
- g_warning("Unable to open firmware file %s for reading: %s",
- filename, strerror(errno));
+ sr_warn("Unable to open firmware file %s for reading: %s",
+ filename, strerror(errno));
return 1;
}
LIBUSB_ENDPOINT_OUT, 0xa0, offset,
0x0000, buf, chunksize, 100);
if (err < 0) {
- g_warning("Unable to send firmware to device: %d", err);
+ sr_warn("Unable to send firmware to device: %d", err);
result = 1;
break;
}
- g_message("Uploaded %d bytes", chunksize);
+ sr_info("Uploaded %d bytes", chunksize);
offset += chunksize;
}
fclose(fw);
- g_message("Firmware upload done");
+ sr_info("Firmware upload done");
return result;
}
struct libusb_device_handle *hdl;
int err;
- g_message("uploading firmware to device on %d.%d",
+ sr_info("uploading firmware to device on %d.%d",
libusb_get_bus_number(dev), libusb_get_device_address(dev));
err = libusb_open(dev, &hdl);
if (err != 0) {
- g_warning("failed to open device: %d", err);
+ sr_warn("failed to open device: %d", err);
return 1;
}
err = libusb_set_configuration(hdl, configuration);
if (err != 0) {
- g_warning("Unable to set configuration: %d", err);
+ sr_warn("Unable to set configuration: %d", err);
return 1;
}
#include <libusb.h>
#endif
#include <sigrok.h>
+#include <sigrok-internal.h>
#ifdef HAVE_LIBUSB_1_0
int err;
if ((err = libusb_get_device_descriptor(dev, des))) {
- g_warning("failed to get device descriptor: %d", err);
+ sr_warn("failed to get device descriptor: %d", err);
return -1;
}
if (!(err = libusb_open(dev, &((*sdi)->usb->devhdl)))) {
(*sdi)->usb->address = libusb_get_device_address(dev);
(*sdi)->status = SR_ST_ACTIVE;
- g_message("opened device %d on %d.%d interface %d",
- (*sdi)->index, (*sdi)->usb->bus,
- (*sdi)->usb->address, interface);
+ sr_info("opened device %d on %d.%d interface %d",
+ (*sdi)->index, (*sdi)->usb->bus,
+ (*sdi)->usb->address, interface);
} else {
- g_warning("failed to open device: %d", err);
+ sr_warn("failed to open device: %d", err);
*sdi = NULL;
}
int err;
if ((err = libusb_get_device_descriptor(dev, des))) {
- g_warning("failed to get device descriptor: %d", err);
+ sr_warn("failed to get device descriptor: %d", err);
return -1;
}
/* Found it. */
if (!(err = libusb_open(dev, &((*sdi)->usb->devhdl)))) {
(*sdi)->status = SR_ST_ACTIVE;
- g_message("opened device %d on %d.%d interface %d",
- (*sdi)->index, (*sdi)->usb->bus,
- (*sdi)->usb->address, interface);
+ sr_info("opened device %d on %d.%d interface %d",
+ (*sdi)->index, (*sdi)->usb->bus,
+ (*sdi)->usb->address, interface);
} else {
- g_warning("failed to open device: %d", err);
+ sr_warn("failed to open device: %d", err);
*sdi = NULL;
}
}
*/
udev = udev_new();
if (!udev) {
- g_warning("Failed to initialize udev.");
+ sr_warn("Failed to initialize udev.");
goto ret;
}
enumerate = udev_enumerate_new(udev);
parent = udev_device_get_parent_with_subsystem_devtype(
dev, "usb", "usb_device");
if (!parent) {
- g_warning("Unable to find parent usb device for %s",
- sysname);
+ sr_warn("Unable to find parent usb device for %s",
+ sysname);
continue;
}
s = strcspn(iProduct, " ");
if (s > sizeof(product) ||
strlen(iProduct) - s > sizeof(manufacturer)) {
- g_warning("Could not parse iProduct: %s", iProduct);
+ sr_warn("Could not parse iProduct: %s", iProduct);
continue;
}
strncpy(product, iProduct, s);
memset(mso, 0, sizeof(struct mso));
if (mso_parse_serial(iSerial, iProduct, mso) != SR_OK) {
- g_warning("Invalid iSerial: %s", iSerial);
+ sr_warn("Invalid iSerial: %s", iSerial);
goto err_free_mso;
}
/* hardware initial state */
sdi = sr_device_instance_new(devcnt, SR_ST_INITIALIZING,
manufacturer, product, hwrev);
if (!sdi) {
- g_warning("Unable to create device instance for %s",
- sysname);
+ sr_warn("Unable to create device instance for %s",
+ sysname);
goto err_free_mso;
}
/* FIXME: discard serial buffer */
mso_check_trigger(sdi, &mso->trigger_state);
-// g_warning("trigger state: %c", mso->trigger_state);
+// sr_warn("trigger state: %c", mso->trigger_state);
ret = mso_reset_adc(sdi);
if (ret != SR_OK)
return ret;
mso_check_trigger(sdi, &mso->trigger_state);
-// g_warning("trigger state: %c", mso->trigger_state);
+// sr_warn("trigger state: %c", mso->trigger_state);
// ret = mso_reset_fsm(sdi);
// if (ret != SR_OK)
{
char buf[1];
- g_debug("ols: sending cmd 0x%.2x", command);
+ sr_dbg("ols: sending cmd 0x%.2x", command);
buf[0] = command;
if (serial_write(fd, buf, 1) != 1)
return SR_ERR;
{
char buf[5];
- g_debug("ols: sending cmd 0x%.2x data 0x%.8x", command, data);
+ sr_dbg("ols: sending cmd 0x%.2x data 0x%.8x", command, data);
buf[0] = command;
buf[1] = (data & 0xff000000) >> 24;
buf[2] = (data & 0xff0000) >> 16;
tmp_str = g_string_new("");
while (serial_read(fd, &tmp_c, 1) == 1 && tmp_c != '\0')
g_string_append_c(tmp_str, tmp_c);
- g_debug("ols: got metadata key 0x%.2x value '%s'", key, tmp_str->str);
+ sr_dbg("ols: got metadata key 0x%.2x value '%s'",
+ key, tmp_str->str);
switch (token) {
case 0x01:
/* Device name */
g_string_append(version, tmp_str->str);
break;
default:
- g_message("ols: unknown token 0x%.2x: '%s'", token, tmp_str->str);
+ sr_info("ols: unknown token 0x%.2x: '%s'",
+ token, tmp_str->str);
break;
}
g_string_free(tmp_str, TRUE);
if (serial_read(fd, &tmp_int, 4) != 4)
break;
tmp_int = reverse32(tmp_int);
- g_debug("ols: got metadata key 0x%.2x value 0x%.8x", key, tmp_int);
+ sr_dbg("ols: got metadata key 0x%.2x value 0x%.8x",
+ key, tmp_int);
switch (token) {
case 0x00:
/* Number of usable probes */
ols->protocol_version = tmp_int;
break;
default:
- g_message("ols: unknown token 0x%.2x: 0x%.8x", token, tmp_int);
+ sr_info("ols: unknown token 0x%.2x: 0x%.8x",
+ token, tmp_int);
break;
}
break;
/* 8-bit unsigned integer */
if (serial_read(fd, &tmp_c, 1) != 1)
break;
- g_debug("ols: got metadata key 0x%.2x value 0x%.2x", key, tmp_c);
+ sr_dbg("ols: got metadata key 0x%.2x value 0x%.2x",
+ key, tmp_c);
switch (token) {
case 0x00:
/* Number of usable probes */
ols->protocol_version = tmp_c;
break;
default:
- g_message("ols: unknown token 0x%.2x: 0x%.2x", token, tmp_c);
+ sr_info("ols: unknown token 0x%.2x: 0x%.2x",
+ token, tmp_c);
break;
}
break;
* we do all the sending first, then wait for all of them to
* respond with g_poll().
*/
- g_message("ols: probing %s...", (char *)l->data);
+ sr_info("ols: probing %s...", (char *)l->data);
fd = serial_open(l->data, O_RDWR | O_NONBLOCK);
if (fd != -1) {
serial_params[devcnt] = serial_backup_params(fd);
if (*tmp_u64 < MIN_NUM_SAMPLES)
return SR_ERR;
ols->limit_samples = *tmp_u64;
- g_message("ols: sample limit %" PRIu64, ols->limit_samples);
+ sr_info("ols: sample limit %" PRIu64, ols->limit_samples);
ret = SR_OK;
break;
case SR_HWCAP_CAPTURE_RATIO:
return FALSE;
ols->sample[ols->num_bytes++] = byte;
- g_debug("ols: received byte 0x%.2x", byte);
+ sr_dbg("ols: received byte 0x%.2x", byte);
if (ols->num_bytes == num_channels) {
/* Got a full sample. */
- g_debug("ols: received sample 0x%.*x", ols->num_bytes * 2, (int) *ols->sample);
+ sr_dbg("ols: received sample 0x%.*x",
+ ols->num_bytes * 2, (int) *ols->sample);
if (ols->flag_reg & FLAG_RLE) {
/*
* In RLE mode -1 should never come in as a
}
}
memcpy(ols->sample, ols->tmp_sample, 4);
- g_debug("ols: full sample 0x%.8x", (int) *ols->sample);
+ sr_dbg("ols: full sample 0x%.8x", (int) *ols->sample);
}
/* the OLS sends its sample buffer backwards.
delaycount = readcount;
}
- g_message("ols: setting samplerate to %" PRIu64 " Hz (divider %u, demux %s)",
- ols->cur_samplerate, ols->cur_samplerate_divider,
- ols->flag_reg & FLAG_DEMUX ? "on" : "off");
+ sr_info("ols: setting samplerate to %" PRIu64 " Hz (divider %u, "
+ "demux %s)", ols->cur_samplerate, ols->cur_samplerate_divider,
+ ols->flag_reg & FLAG_DEMUX ? "on" : "off");
if (send_longcommand(sdi->serial->fd, CMD_SET_DIVIDER,
reverse32(ols->cur_samplerate_divider)) != SR_OK)
return SR_ERR;
if (sdi->usb->devhdl == NULL)
return;
- g_message("saleae: closing device %d on %d.%d interface %d", sdi->index,
- sdi->usb->bus, sdi->usb->address, USB_INTERFACE);
+ sr_info("saleae: closing device %d on %d.%d interface %d", sdi->index,
+ sdi->usb->bus, sdi->usb->address, USB_INTERFACE);
libusb_release_interface(sdi->usb->devhdl, USB_INTERFACE);
libusb_close(sdi->usb->devhdl);
sdi->usb->devhdl = NULL;
deviceinfo = deviceinfo;
if (libusb_init(&usb_context) != 0) {
- g_warning("Failed to initialize USB.");
+ sr_warn("Failed to initialize USB.");
return 0;
}
for (i = 0; devlist[i]; i++) {
err = libusb_get_device_descriptor(devlist[i], &des);
if (err != 0) {
- g_warning("failed to get device descriptor: %d", err);
+ sr_warn("failed to get device descriptor: %d", err);
continue;
}
* or uploading the firmware again.
*/
if (upload_firmware(devlist[i]) > 0)
- g_warning("firmware upload failed for "
- "device %d", devcnt);
+ sr_warn("firmware upload failed for device %d",
+ devcnt);
sdi->usb = sr_usb_device_instance_new
(libusb_get_bus_number(devlist[i]), 0, NULL);
timediff = cur - upd;
if (timediff < FIRMWARE_RENUM_DELAY) {
timediff = FIRMWARE_RENUM_DELAY - timediff;
- g_message("saleae: waiting %d ms for device to reset",
- timediff);
+ sr_info("saleae: waiting %d ms for device to reset",
+ timediff);
g_usleep(timediff * 1000);
firmware_updated.tv_sec = 0;
}
}
if (!(sdi = sl_open_device(device_index))) {
- g_warning("unable to open device");
+ sr_warn("unable to open device");
return SR_ERR;
}
err = libusb_claim_interface(sdi->usb->devhdl, USB_INTERFACE);
if (err != 0) {
- g_warning("Unable to claim interface: %d", err);
+ sr_warn("Unable to claim interface: %d", err);
return SR_ERR;
}
divider = (uint8_t) (48 / (samplerate / 1000000.0)) - 1;
- g_message("saleae: setting samplerate to %" PRIu64 " Hz (divider %d)",
- samplerate, divider);
+ sr_info("saleae: setting samplerate to %" PRIu64 " Hz (divider %d)",
+ samplerate, divider);
buf[0] = 0x01;
buf[1] = divider;
ret = libusb_bulk_transfer(sdi->usb->devhdl, 1 | LIBUSB_ENDPOINT_OUT,
buf, 2, &result, 500);
if (ret != 0) {
- g_warning("failed to set samplerate: %d", ret);
+ sr_warn("failed to set samplerate: %d", ret);
return SR_ERR;
}
cur_samplerate = samplerate;
return;
}
- g_message("saleae: receive_transfer(): status %d received %d bytes",
- transfer->status, transfer->actual_length);
+ sr_info("saleae: receive_transfer(): status %d received %d bytes",
+ transfer->status, transfer->actual_length);
/* Save incoming transfer before reusing the transfer struct. */
cur_buf = transfer->buffer;
transfer->length = 4096;
if (libusb_submit_transfer(transfer) != 0) {
/* TODO: Stop session? */
- g_warning("eek");
+ sr_warn("eek");
}
if (cur_buflen == 0) {
int err;
if ((err = libusb_get_device_descriptor(dev, des))) {
- g_warning("failed to get device descriptor: %d", err);
+ sr_warn("failed to get device descriptor: %d", err);
return -1;
}
if (!(des->idProduct == zeroplus_models[i].pid))
continue;
- g_message("Found PID=%04X (%s)", des->idProduct,
- zeroplus_models[i].model_name);
+ sr_info("Found PID=%04X (%s)", des->idProduct,
+ zeroplus_models[i].model_name);
num_channels = zeroplus_models[i].channels;
memory_size = zeroplus_models[i].sample_depth * 1024;
break;
}
if (num_channels == 0) {
- g_warning("Unknown ZeroPlus device %04X",
- des->idProduct);
+ sr_warn("Unknown ZeroPlus device %04X", des->idProduct);
return -2;
}
/* Found it. */
if (!(err = libusb_open(dev, &((*sdi)->usb->devhdl)))) {
(*sdi)->status = SR_ST_ACTIVE;
- g_message("opened device %d on %d.%d interface %d",
- (*sdi)->index, (*sdi)->usb->bus,
- (*sdi)->usb->address, USB_INTERFACE);
+ sr_info("opened device %d on %d.%d interface %d",
+ (*sdi)->index, (*sdi)->usb->bus,
+ (*sdi)->usb->address, USB_INTERFACE);
} else {
- g_warning("failed to open device: %d", err);
+ sr_warn("failed to open device: %d", err);
*sdi = NULL;
}
}
if (!sdi->usb->devhdl)
return;
- g_message("closing device %d on %d.%d interface %d", sdi->index,
- sdi->usb->bus, sdi->usb->address, USB_INTERFACE);
+ sr_info("closing device %d on %d.%d interface %d", sdi->index,
+ sdi->usb->bus, sdi->usb->address, USB_INTERFACE);
libusb_release_interface(sdi->usb->devhdl, USB_INTERFACE);
libusb_close(sdi->usb->devhdl);
sdi->usb->devhdl = NULL;
deviceinfo = deviceinfo;
if (libusb_init(&usb_context) != 0) {
- g_warning("Failed to initialize USB.");
+ sr_warn("Failed to initialize USB.");
return 0;
}
for (i = 0; devlist[i]; i++) {
err = libusb_get_device_descriptor(devlist[i], &des);
if (err != 0) {
- g_warning("failed to get device descriptor: %d", err);
+ sr_warn("failed to get device descriptor: %d", err);
continue;
}
int err;
if (!(sdi = zp_open_device(device_index))) {
- g_warning("unable to open device");
+ sr_warn("unable to open device");
return SR_ERR;
}
err = libusb_claim_interface(sdi->usb->devhdl, USB_INTERFACE);
if (err != 0) {
- g_warning("Unable to claim interface: %d", err);
+ sr_warn("Unable to claim interface: %d", err);
return SR_ERR;
}
analyzer_reset(sdi->usb->devhdl);
/* TODO: This will set the same samplerate for all devices. */
static int set_configuration_samplerate(uint64_t samplerate)
{
- g_message("%s(%" PRIu64 ")", __FUNCTION__, samplerate);
+ sr_info("%s(%" PRIu64 ")", __FUNCTION__, samplerate);
if (samplerate > SR_MHZ(1))
analyzer_set_freq(samplerate / SR_MHZ(1), FREQ_SCALE_MHZ);
else if (samplerate > SR_KHZ(1))
analyzer_configure(sdi->usb->devhdl);
analyzer_start(sdi->usb->devhdl);
- g_message("Waiting for data");
+ sr_info("Waiting for data");
analyzer_wait_data(sdi->usb->devhdl);
- g_message("Stop address = 0x%x",
- analyzer_get_stop_address(sdi->usb->devhdl));
- g_message("Now address = 0x%x",
- analyzer_get_now_address(sdi->usb->devhdl));
- g_message("Trigger address = 0x%x",
- analyzer_get_trigger_address(sdi->usb->devhdl));
+ sr_info("Stop address = 0x%x",
+ analyzer_get_stop_address(sdi->usb->devhdl));
+ sr_info("Now address = 0x%x",
+ analyzer_get_now_address(sdi->usb->devhdl));
+ sr_info("Trigger address = 0x%x",
+ analyzer_get_trigger_address(sdi->usb->devhdl));
packet.type = SR_DF_HEADER;
packet.length = sizeof(struct sr_datafeed_header);
packet_num++) {
res = analyzer_read_data(sdi->usb->devhdl, buf, PACKET_SIZE);
#if 0
- g_message("Tried to read %llx bytes, actually read %x bytes",
- PACKET_SIZE, res);
+ sr_info("Tried to read %llx bytes, actually read %x bytes",
+ PACKET_SIZE, res);
#endif
packet.type = SR_DF_LOGIC;
#include <string.h>
#include <glib.h>
#include <sigrok.h>
+#include <sigrok-internal.h>
/* The list of loaded plugins lives here. */
GSList *plugins;
if (sdi->index == device_index)
return sdi;
}
- g_warning("could not find device index %d instance", device_index);
+ sr_warn("could not find device index %d instance", device_index);
return NULL;
}
#include <fcntl.h>
#include <unistd.h>
#include <sigrok.h>
+#include <sigrok-internal.h>
#define NUM_PACKETS 2048
#define PACKET_SIZE 4096
static int format_match(const char *filename)
{
if (!filename) {
- g_warning("la8input: %s: filename was NULL", __func__);
+ sr_warn("la8input: %s: filename was NULL", __func__);
// return SR_ERR; /* FIXME */
return FALSE;
}
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
- g_warning("la8input: %s: input file '%s' does not exist",
- __func__, filename);
+ sr_warn("la8input: %s: input file '%s' does not exist",
+ __func__, filename);
// return SR_ERR; /* FIXME */
return FALSE;
}
if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
- g_warning("la8input: %s: input file '%s' not a regular file",
- __func__, filename);
+ sr_warn("la8input: %s: input file '%s' not a regular file",
+ __func__, filename);
// return SR_ERR; /* FIXME */
return FALSE;
}
if (in->param && in->param[0]) {
num_probes = strtoul(in->param, NULL, 10);
if (num_probes < 1) {
- g_warning("la8input: %s: strtoul failed", __func__);
+ sr_warn("la8input: %s: strtoul failed", __func__);
return SR_ERR;
}
} else {
/* TODO: Use glib functions! GIOChannel, g_fopen, etc. */
if ((fd = open(filename, O_RDONLY)) == -1) {
- g_warning("la8input: %s: file open failed", __func__);
+ sr_warn("la8input: %s: file open failed", __func__);
return SR_ERR;
}
close(fd); /* FIXME */
return SR_ERR;
}
- g_debug("la8input: %s: samplerate is %" PRIu64, __func__, samplerate);
+ sr_dbg("la8input: %s: samplerate is %" PRIu64, __func__, samplerate);
/* Send header packet to the session bus. */
- g_debug("la8input: %s: sending SR_DF_HEADER packet", __func__);
+ sr_dbg("la8input: %s: sending SR_DF_HEADER packet", __func__);
packet.type = SR_DF_HEADER;
packet.length = sizeof(struct sr_datafeed_header);
packet.unitsize = 0;
/* TODO: Handle trigger point. */
/* Send data packets to the session bus. */
- g_debug("la8input: %s: sending SR_DF_LOGIC data packets", __func__);
+ sr_dbg("la8input: %s: sending SR_DF_LOGIC data packets", __func__);
packet.type = SR_DF_LOGIC;
packet.unitsize = (num_probes + 7) / 8;
packet.payload = buf;
close(fd); /* FIXME */
/* Send end packet to the session bus. */
- g_debug("la8input: %s: sending SR_DF_END", __func__);
+ sr_dbg("la8input: %s: sending SR_DF_END", __func__);
packet.type = SR_DF_END;
packet.length = 0;
packet.unitsize = 0;
--- /dev/null
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2011 Uwe Hermann <uwe@hermann-uwe.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <sigrok.h>
+#include <sigrok-internal.h>
+
+static int sr_logv(int loglevel, const char *format, va_list args)
+{
+ int ret;
+
+ /* Avoid compiler warnings. */
+ loglevel = loglevel;
+
+ ret = vfprintf(stderr, format, args);
+ fprintf(stderr, "\n");
+
+ return ret;
+}
+
+int sr_log(int loglevel, const char *format, ...)
+{
+ int ret;
+ va_list args;
+
+ va_start(args, format);
+ ret = sr_logv(loglevel, format, args);
+ va_end(args);
+
+ return ret;
+}
+
+int sr_dbg(const char *format, ...)
+{
+ int ret;
+ va_list args;
+
+ va_start(args, format);
+ ret = sr_logv(SR_LOG_DBG, format, args);
+ va_end(args);
+
+ return ret;
+}
+
+int sr_info(const char *format, ...)
+{
+ int ret;
+ va_list args;
+
+ va_start(args, format);
+ ret = sr_logv(SR_LOG_INFO, format, args);
+ va_end(args);
+
+ return ret;
+}
+
+int sr_warn(const char *format, ...)
+{
+ int ret;
+ va_list args;
+
+ va_start(args, format);
+ ret = sr_logv(SR_LOG_WARN, format, args);
+ va_end(args);
+
+ return ret;
+}
+
+int sr_err(const char *format, ...)
+{
+ int ret;
+ va_list args;
+
+ va_start(args, format);
+ ret = sr_logv(SR_LOG_ERR, format, args);
+ va_end(args);
+
+ return ret;
+}
}
}
} else {
- g_message("short buffer (length_in=%" PRIu64 ")", length_in);
+ sr_info("short buffer (length_in=%" PRIu64 ")", length_in);
}
*data_out = outbuf;
ctx->prevsample = sample;
}
} else {
- g_message("short buffer (length_in=%" PRIu64 ")", length_in);
+ sr_info("short buffer (length_in=%" PRIu64 ")", length_in);
}
*data_out = outbuf;
#include <string.h>
#include <glib.h>
#include <sigrok.h>
+#include <sigrok-internal.h>
#include "config.h"
static int data(struct sr_output *o, const char *data_in, uint64_t length_in,
o = o;
if (!data_in) {
- g_warning("binary output: %s: data_in was NULL", __func__);
+ sr_warn("binary output: %s: data_in was NULL", __func__);
return SR_ERR;
}
if (!length_out) {
- g_warning("binary output: %s: length_out was NULL", __func__);
+ sr_warn("binary output: %s: length_out was NULL", __func__);
return SR_ERR;
}
if (length_in == 0) {
- g_warning("binary output: %s: length_in was 0", __func__);
+ sr_warn("binary output: %s: length_in was 0", __func__);
return SR_ERR;
}
if (!(outbuf = calloc(1, length_in))) {
- g_warning("binary output: %s: outbuf calloc failed", __func__);
+ sr_warn("binary output: %s: outbuf calloc failed", __func__);
return SR_ERR_MALLOC;
}
#include <string.h>
#include <glib.h>
#include <sigrok.h>
+#include <sigrok-internal.h>
struct context {
unsigned int num_enabled_probes;
return 1;
}
- g_warning("la8 out: %s: invalid samplerate (%" PRIu64 "Hz)",
- __func__, samplerate);
+ sr_warn("la8 out: %s: invalid samplerate (%" PRIu64 "Hz)",
+ __func__, samplerate);
return 0;
}
static uint8_t samplerate_to_divcount(uint64_t samplerate)
{
if (samplerate == 0) {
- g_warning("la8 out: %s: samplerate was 0", __func__);
+ sr_warn("la8 out: %s: samplerate was 0", __func__);
return 0xff;
}
if (!is_valid_samplerate(samplerate)) {
- g_warning("la8 out: %s: can't get divcount, samplerate invalid",
- __func__);
+ sr_warn("la8 out: %s: can't get divcount, samplerate invalid",
+ __func__);
return 0xff;
}
uint64_t samplerate;
if (!o) {
- g_warning("la8 out: %s: o was NULL", __func__);
+ sr_warn("la8 out: %s: o was NULL", __func__);
return SR_ERR_ARG;
}
if (!o->device) {
- g_warning("la8 out: %s: o->device was NULL", __func__);
+ sr_warn("la8 out: %s: o->device was NULL", __func__);
return SR_ERR_ARG;
}
if (!o->device->plugin) {
- g_warning("la8 out: %s: o->device->plugin was NULL", __func__);
+ sr_warn("la8 out: %s: o->device->plugin was NULL", __func__);
return SR_ERR_ARG;
}
if (!(ctx = calloc(1, sizeof(struct context)))) {
- g_warning("la8 out: %s: ctx calloc failed", __func__);
+ sr_warn("la8 out: %s: ctx calloc failed", __func__);
return SR_ERR_MALLOC;
}
char *outbuf;
if (!o) {
- g_warning("la8 out: %s: o was NULL", __func__);
+ sr_warn("la8 out: %s: o was NULL", __func__);
return SR_ERR_ARG;
}
if (!(ctx = o->internal)) {
- g_warning("la8 out: %s: o->internal was NULL", __func__);
+ sr_warn("la8 out: %s: o->internal was NULL", __func__);
return SR_ERR_ARG;
}
if (!data_out) {
- g_warning("la8 out: %s: data_out was NULL", __func__);
+ sr_warn("la8 out: %s: data_out was NULL", __func__);
return SR_ERR_ARG;
}
switch (event_type) {
case SR_DF_TRIGGER:
- g_debug("la8 out: %s: SR_DF_TRIGGER event", __func__);
+ sr_dbg("la8 out: %s: SR_DF_TRIGGER event", __func__);
/* Save the trigger point for later (SR_DF_END). */
ctx->trigger_point = 0; /* TODO: Store _actual_ value. */
break;
case SR_DF_END:
- g_debug("la8 out: %s: SR_DF_END event", __func__);
+ sr_dbg("la8 out: %s: SR_DF_END event", __func__);
if (!(outbuf = malloc(4 + 1))) {
- g_warning("la8 out: %s: outbuf malloc failed",
- __func__);
+ sr_warn("la8 out: %s: outbuf malloc failed", __func__);
return SR_ERR_MALLOC;
}
/* One byte for the 'divcount' value. */
outbuf[0] = samplerate_to_divcount(ctx->samplerate);
// if (outbuf[0] == 0xff) {
- // g_warning("la8 out: %s: invalid divcount", __func__);
+ // sr_warn("la8 out: %s: invalid divcount", __func__);
// return SR_ERR;
// }
o->internal = NULL;
break;
default:
- g_warning("la8 out: %s: unsupported event type: %d", __func__,
- event_type);
+ sr_warn("la8 out: %s: unsupported event type: %d", __func__,
+ event_type);
*data_out = NULL;
*length_out = 0;
break;
char *outbuf;
if (!o) {
- g_warning("la8 out: %s: o was NULL", __func__);
+ sr_warn("la8 out: %s: o was NULL", __func__);
return SR_ERR_ARG;
}
if (!(ctx = o->internal)) {
- g_warning("la8 out: %s: o->internal was NULL", __func__);
+ sr_warn("la8 out: %s: o->internal was NULL", __func__);
return SR_ERR_ARG;
}
if (!data_in) {
- g_warning("la8 out: %s: data_in was NULL", __func__);
+ sr_warn("la8 out: %s: data_in was NULL", __func__);
return SR_ERR_ARG;
}
if (!(outbuf = calloc(1, length_in))) {
- g_warning("la8 out: %s: outbuf calloc failed", __func__);
+ sr_warn("la8 out: %s: outbuf calloc failed", __func__);
return SR_ERR_MALLOC;
}
#include <string.h>
#include <glib.h>
#include <sigrok.h>
+#include <sigrok-internal.h>
#include "config.h"
struct context {
time_t t;
if (!o) {
- g_warning("gnuplot out: %s: o was NULL", __func__);
+ sr_warn("gnuplot out: %s: o was NULL", __func__);
return SR_ERR_ARG;
}
if (!o->device) {
- g_warning("gnuplot out: %s: o->device was NULL", __func__);
+ sr_warn("gnuplot out: %s: o->device was NULL", __func__);
return SR_ERR_ARG;
}
if (!o->device->plugin) {
- g_warning("gnuplot out: %s: o->device->plugin was NULL",
- __func__);
+ sr_warn("gnuplot out: %s: o->device->plugin was NULL",
+ __func__);
return SR_ERR_ARG;
}
if (!(ctx = calloc(1, sizeof(struct context)))) {
- g_warning("gnuplot out: %s: ctx calloc failed", __func__);
+ sr_warn("gnuplot out: %s: ctx calloc failed", __func__);
return SR_ERR_MALLOC;
}
if (!(ctx->header = calloc(1, MAX_HEADER_LEN + 1))) {
- g_warning("gnuplot out: %s: ctx->header calloc failed",
- __func__);
+ sr_warn("gnuplot out: %s: ctx->header calloc failed",
+ __func__);
free(ctx);
return SR_ERR_MALLOC;
}
samplerate = *((uint64_t *) o->device->plugin->get_device_info(
o->device->plugin_index, SR_DI_CUR_SAMPLERATE));
if (!(frequency_s = sr_samplerate_string(samplerate))) {
- g_warning("gnuplot out: %s: sr_samplerate_string "
- "failed", __func__);
+ sr_warn("gnuplot out: %s: sr_samplerate_string failed",
+ __func__);
free(ctx->header);
free(ctx);
return SR_ERR;
}
if (!(frequency_s = sr_period_string(samplerate))) {
- g_warning("gnuplot out: %s: sr_period_string failed", __func__);
+ sr_warn("gnuplot out: %s: sr_period_string failed", __func__);
free(ctx->header);
free(ctx);
return SR_ERR;
free(frequency_s);
if (b < 0) {
- g_warning("gnuplot out: %s: sprintf failed", __func__);
+ sr_warn("gnuplot out: %s: sprintf failed", __func__);
free(ctx->header);
free(ctx);
return SR_ERR;
struct context *ctx;
if (!o) {
- g_warning("gnuplot out: %s: o was NULL", __func__);
+ sr_warn("gnuplot out: %s: o was NULL", __func__);
return SR_ERR_ARG;
}
if (!data_out) {
- g_warning("gnuplot out: %s: data_out was NULL", __func__);
+ sr_warn("gnuplot out: %s: data_out was NULL", __func__);
return SR_ERR_ARG;
}
if (!length_out) {
- g_warning("gnuplot out: %s: length_out was NULL", __func__);
+ sr_warn("gnuplot out: %s: length_out was NULL", __func__);
return SR_ERR_ARG;
}
o->internal = NULL;
break;
default:
- g_warning("gnuplot out: %s: unsupported event type: %d",
- __func__, event_type);
+ sr_warn("gnuplot out: %s: unsupported event type: %d",
+ __func__, event_type);
break;
}
char *outbuf, *c;
if (!o) {
- g_warning("gnuplot out: %s: o was NULL", __func__);
+ sr_warn("gnuplot out: %s: o was NULL", __func__);
return SR_ERR_ARG;
}
if (!o->internal) {
- g_warning("gnuplot out: %s: o->internal was NULL", __func__);
+ sr_warn("gnuplot out: %s: o->internal was NULL", __func__);
return SR_ERR_ARG;
}
if (!data_in) {
- g_warning("gnuplot out: %s: data_in was NULL", __func__);
+ sr_warn("gnuplot out: %s: data_in was NULL", __func__);
return SR_ERR_ARG;
}
if (!data_out) {
- g_warning("gnuplot out: %s: data_out was NULL", __func__);
+ sr_warn("gnuplot out: %s: data_out was NULL", __func__);
return SR_ERR_ARG;
}
if (!length_out) {
- g_warning("gnuplot out: %s: length_out was NULL", __func__);
+ sr_warn("gnuplot out: %s: length_out was NULL", __func__);
return SR_ERR_ARG;
}
outsize += strlen(ctx->header);
if (!(outbuf = calloc(1, outsize))) {
- g_warning("gnuplot out: %s: outbuf calloc failed", __func__);
+ sr_warn("gnuplot out: %s: outbuf calloc failed", __func__);
return SR_ERR_MALLOC;
}
#include <string.h>
#include <glib.h>
#include <sigrok.h>
+#include <sigrok-internal.h>
#include "config.h"
struct context {
ctx->probelist[ctx->num_enabled_probes++] = probe->name;
}
if (ctx->num_enabled_probes > 94) {
- g_warning("VCD only supports 94 probes.");
+ sr_warn("VCD only supports 94 probes.");
return SR_ERR;
}
#include <string.h>
#include <glib.h>
#include <sigrok.h>
+#include <sigrok-internal.h>
#include "text.h"
int init_ascii(struct sr_output *o)
ctx->prevsample = sample;
}
} else {
- g_message("short buffer (length_in=%" PRIu64 ")", length_in);
+ sr_info("short buffer (length_in=%" PRIu64 ")", length_in);
}
*data_out = outbuf;
#include <string.h>
#include <glib.h>
#include <sigrok.h>
+#include <sigrok-internal.h>
#include "text.h"
int init_bits(struct sr_output *o)
}
}
} else {
- g_message("short buffer (length_in=%" PRIu64 ")", length_in);
+ sr_info("short buffer (length_in=%" PRIu64 ")", length_in);
}
*data_out = outbuf;
#include <string.h>
#include <glib.h>
#include <sigrok.h>
+#include <sigrok-internal.h>
/* demo.c */
extern GIOChannel channels[2];
GSList *l;
int ret;
- g_message("session: starting");
+ sr_info("session: starting");
for (l = session->devices; l; l = l->next) {
device = l->data;
if ((ret = device->plugin->start_acquisition(
void sr_session_run(void)
{
- g_message("session: running");
+ sr_info("session: running");
session->running = TRUE;
/* do we have real sources? */
void sr_session_halt(void)
{
- g_message("session: halting");
+ sr_info("session: halting");
session->running = FALSE;
}
struct sr_device *device;
GSList *l;
- g_message("session: stopping");
+ sr_info("session: stopping");
session->running = FALSE;
for (l = session->devices; l; l = l->next) {
device = l->data;
#include <sys/time.h>
#include <zip.h>
#include <sigrok.h>
+#include <sigrok-internal.h>
/* size of payloads sent across the session bus */
#define CHUNKSIZE 4096
fd = fd;
revents = revents;
- g_debug("session_driver: feed chunk");
+ sr_dbg("session_driver: feed chunk");
got_data = FALSE;
for (l = device_instances; l; l = l->next) {
if (!(vdevice = get_vdevice_by_index(device_index)))
return SR_ERR;
- g_message("session_driver: opening archive %s file %s",
- sessionfile, vdevice->capturefile);
+ sr_info("session_driver: opening archive %s file %s", sessionfile,
+ vdevice->capturefile);
if (!(vdevice->archive = zip_open(sessionfile, 0, &err))) {
- g_warning("Failed to open session file '%s': zip error %d\n",
- sessionfile, err);
+ sr_warn("Failed to open session file '%s': zip error %d\n",
+ sessionfile, err);
return SR_ERR;
}
if (zip_stat(vdevice->archive, vdevice->capturefile, 0, &zs) == -1) {
- g_warning("Failed to check capture file '%s' in session file '%s'.",
- vdevice->capturefile, sessionfile);
+ sr_warn("Failed to check capture file '%s' in session file '%s'.",
+ vdevice->capturefile, sessionfile);
return SR_ERR;
}
if (!(vdevice->capfile = zip_fopen(vdevice->archive, vdevice->capturefile, 0))) {
- g_warning("Failed to open capture file '%s' in session file '%s'.",
- vdevice->capturefile, sessionfile);
+ sr_warn("Failed to open capture file '%s' in session file '%s'.",
+ vdevice->capturefile, sessionfile);
return SR_ERR;
}
char **sections, **keys, *metafile, *val, c;
if (!(archive = zip_open(filename, 0, &err))) {
- g_debug("Failed to open session file: zip error %d", err);
+ sr_dbg("Failed to open session file: zip error %d", err);
return SR_ERR;
}
/* check "version" */
if (!(zf = zip_fopen(archive, "version", 0))) {
- g_debug("Not a sigrok session file.");
+ sr_dbg("Not a sigrok session file.");
return SR_ERR;
}
ret = zip_fread(zf, &c, 1);
if (ret != 1 || c != '1') {
- g_debug("Not a valid sigrok session file.");
+ sr_dbg("Not a valid sigrok session file.");
return SR_ERR;
}
zip_fclose(zf);
/* read "metadata" */
if (zip_stat(archive, "metadata", 0, &zs) == -1) {
- g_debug("Not a valid sigrok session file.");
+ sr_dbg("Not a valid sigrok session file.");
return SR_ERR;
}
metafile = g_malloc(zs.size);
kf = g_key_file_new();
if (!g_key_file_load_from_data(kf, metafile, zs.size, 0, NULL)) {
- g_debug("Failed to parse metadata.");
+ sr_dbg("Failed to parse metadata.");
return SR_ERR;
}
if (!(versrc = zip_source_buffer(zipfile, version, 1, 0)))
return SR_ERR;
if (zip_add(zipfile, "version", versrc) == -1) {
- g_message("error saving version into zipfile: %s",
- zip_strerror(zipfile));
+ sr_info("error saving version into zipfile: %s",
+ zip_strerror(zipfile));
return SR_ERR;
}
return SR_ERR;
if ((ret = zip_close(zipfile)) == -1) {
- g_message("error saving zipfile: %s", zip_strerror(zipfile));
+ sr_info("error saving zipfile: %s", zip_strerror(zipfile));
return SR_ERR;
}
#ifndef SIGROK_SIGROK_INTERNAL_H
#define SIGROK_SIGROK_INTERNAL_H
+#include <stdarg.h>
+
/*--- Macros ----------------------------------------------------------------*/
#ifndef ARRAY_SIZE
int load_hwplugins(void);
+/*--- log.c -----------------------------------------------------------------*/
+
+/* Log levels for sr_log() and friends. */
+#define SR_LOG_NONE 0
+#define SR_LOG_DBG 1
+#define SR_LOG_INFO 2
+#define SR_LOG_WARN 3
+#define SR_LOG_ERR 4
+
+int sr_log(int loglevel, const char *format, ...);
+int sr_dbg(const char *format, ...);
+int sr_info(const char *format, ...);
+int sr_warn(const char *format, ...);
+int sr_err(const char *format, ...);
+
/*--- hardware/common/serial.c ----------------------------------------------*/
GSList *list_serial_ports(void);