From: Uwe Hermann Date: Thu, 14 Apr 2011 07:46:53 +0000 (+0200) Subject: libsigrok: Introduce sr_dbg/sr_info/sr_warn/sr_err. X-Git-Tag: libsigrok-0.1.0~289 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=b08024a8363c7a019bebc05a25e2689e774326e8 libsigrok: Introduce sr_dbg/sr_info/sr_warn/sr_err. We should use these (internal) functions in libsigrok exclusively from now on, i.e. no more use of glib's g_debug() etc. These functions are only for libsigrok, the frontends use whatever logging mechanism is suitable there. --- diff --git a/Makefile.am b/Makefile.am index 8095ff2c..c01801e4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,7 +32,8 @@ libsigrok_la_SOURCES = \ session_driver.c \ hwplugin.c \ filter.c \ - strutil.c + strutil.c \ + log.c libsigrok_la_LIBADD = \ $(LIBOBJS) \ diff --git a/device.c b/device.c index aa1ec782..6e9a3008 100644 --- a/device.c +++ b/device.c @@ -20,6 +20,7 @@ #include #include #include +#include extern struct sr_global *global; @@ -48,7 +49,7 @@ int sr_device_plugin_init(struct sr_device_plugin *plugin) { 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); diff --git a/hardware/alsa/alsa.c b/hardware/alsa/alsa.c index 4ec98a9e..3bf41605 100644 --- a/hardware/alsa/alsa.c +++ b/hardware/alsa/alsa.c @@ -85,21 +85,21 @@ static int hw_opendev(int device_index) 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; } @@ -219,7 +219,7 @@ static int receive_data(int fd, int revents, void *user_data) 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; } @@ -273,7 +273,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) 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; } @@ -281,40 +281,40 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) 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; } @@ -324,7 +324,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) 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; diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 3cd83d35..2722d0db 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "asix-sigma.h" #define USB_VENDOR 0xa600 @@ -105,8 +106,8 @@ static int sigma_read(void *buf, size_t size, struct sigma *sigma) 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; @@ -118,10 +119,10 @@ static int sigma_write(void *buf, size_t size, struct sigma *sigma) 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; @@ -169,7 +170,7 @@ static uint8_t sigma_get_register(uint8_t reg, struct sigma *sigma) 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; } @@ -316,12 +317,12 @@ static int bin2bitbang(const char *filename, 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; } @@ -334,7 +335,7 @@ static int bin2bitbang(const char *filename, firmware = g_malloc(buffer_size); if (!compressed_buf || !firmware) { - g_warning("Error allocating buffers"); + sr_warn("Error allocating buffers"); return -1; } @@ -350,7 +351,7 @@ static int bin2bitbang(const char *filename, 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; } @@ -361,7 +362,7 @@ static int bin2bitbang(const char *filename, *buf = p = (unsigned char *)g_malloc(*buf_size); if (!p) { - g_warning("Error allocating buffers"); + sr_warn("Error allocating buffers"); return -1; } @@ -377,9 +378,9 @@ static int bin2bitbang(const char *filename, 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; } @@ -443,21 +444,21 @@ static int upload_firmware(int firmware_idx, struct sigma *sigma) /* 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; } @@ -484,8 +485,8 @@ static int upload_firmware(int firmware_idx, struct sigma *sigma) 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; } @@ -495,8 +496,8 @@ static int upload_firmware(int firmware_idx, struct sigma *sigma) 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; } @@ -513,7 +514,7 @@ static int upload_firmware(int firmware_idx, struct sigma *sigma) 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; } @@ -537,7 +538,7 @@ static int hw_opendev(int device_index) 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; @@ -578,7 +579,7 @@ static int set_samplerate(struct sr_device_instance *sdi, sigma->samples_per_event = 16 / sigma->num_probes; sigma->state.state = SIGMA_IDLE; - g_message("Firmware uploaded"); + sr_info("Firmware uploaded"); return ret; } @@ -611,9 +612,8 @@ static int configure_probes(struct sr_device_instance *sdi, GSList *probes) 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') @@ -621,9 +621,9 @@ static int configure_probes(struct sr_device_instance *sdi, GSList *probes) 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; } @@ -653,8 +653,8 @@ static int configure_probes(struct sr_device_instance *sdi, GSList *probes) * 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; } } @@ -1000,8 +1000,8 @@ static int receive_data(int fd, int revents, void *user_data) 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); diff --git a/hardware/chronovu-la8/chronovu-la8.c b/hardware/chronovu-la8/chronovu-la8.c index 0f204b85..46a249ee 100644 --- a/hardware/chronovu-la8/chronovu-la8.c +++ b/hardware/chronovu-la8/chronovu-la8.c @@ -20,6 +20,7 @@ #include #include +#include #define USB_VENDOR_ID 0x0403 #define USB_PRODUCT_ID 0x6001 @@ -151,8 +152,8 @@ static int is_valid_samplerate(uint64_t samplerate) return 1; } - g_warning("la8: %s: invalid samplerate (%" PRIu64 "Hz)", - __func__, samplerate); + sr_warn("la8: %s: invalid samplerate (%" PRIu64 "Hz)", + __func__, samplerate); return 0; } @@ -170,13 +171,13 @@ static int is_valid_samplerate(uint64_t samplerate) 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; } @@ -196,34 +197,34 @@ static int la8_write(struct la8 *la8, uint8_t *buf, int size) 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. */ } @@ -243,33 +244,33 @@ static int la8_read(struct la8 *la8, uint8_t *buf, int size) 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; @@ -280,18 +281,18 @@ static int la8_close(struct la8 *la8) 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; @@ -309,39 +310,39 @@ static int la8_close_usb_reset_sequencer(struct la8 *la8) 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. */ @@ -365,16 +366,16 @@ static int la8_reset(struct la8 *la8) 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 @@ -390,7 +391,7 @@ static int la8_reset(struct la8 *la8) /* 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; } @@ -401,14 +402,14 @@ static int hw_init(const char *deviceinfo) 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; } @@ -431,21 +432,21 @@ static int hw_init(const char *deviceinfo) /* 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; } @@ -453,19 +454,19 @@ static int hw_init(const char *deviceinfo) /* 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; } @@ -474,7 +475,7 @@ static int hw_init(const char *deviceinfo) 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. */ @@ -504,44 +505,44 @@ static int hw_opendev(int device_index) 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); @@ -560,16 +561,16 @@ static int set_samplerate(struct sr_device_instance *sdi, uint64_t samplerate) 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(); @@ -580,7 +581,7 @@ static int set_samplerate(struct sr_device_instance *sdi, uint64_t samplerate) /* 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; } @@ -591,23 +592,23 @@ static void hw_closedev(int device_index) 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; @@ -618,18 +619,18 @@ static void hw_cleanup(void) 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. */ @@ -642,15 +643,15 @@ static void *hw_get_device_info(int device_index, int device_info_id) 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; } @@ -673,7 +674,7 @@ static void *hw_get_device_info(int device_index, int device_info_id) 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; } @@ -686,18 +687,18 @@ static int hw_get_status(int device_index) 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; } @@ -707,15 +708,15 @@ static int hw_set_configuration(int device_index, int capability, void *value) 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? */ } @@ -723,33 +724,33 @@ static int hw_set_configuration(int device_index, int capability, void *value) 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; } @@ -769,23 +770,23 @@ static int la8_read_block(struct la8 *la8) 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); @@ -794,13 +795,13 @@ static int la8_read_block(struct la8 *la8) /* 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); @@ -826,18 +827,18 @@ static int receive_data(int fd, int revents, void *user_data) 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; } @@ -847,12 +848,12 @@ static int receive_data(int fd, int revents, void *user_data) 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; @@ -875,26 +876,26 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) 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; } @@ -908,19 +909,19 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) 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; @@ -950,15 +951,15 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id) 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; } @@ -966,7 +967,7 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id) (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; diff --git a/hardware/common/ezusb.c b/hardware/common/ezusb.c index 82174af4..3cd4f03a 100644 --- a/hardware/common/ezusb.c +++ b/hardware/common/ezusb.c @@ -21,6 +21,8 @@ * Helper functions for the Cypress EZ-USB / FX2 series chips. */ +#include +#include #include #include #include @@ -34,12 +36,12 @@ int ezusb_reset(struct libusb_device_handle *hdl, int set_clear) 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; } @@ -50,10 +52,10 @@ int ezusb_install_firmware(libusb_device_handle *hdl, const char *filename) 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; } @@ -66,15 +68,15 @@ int ezusb_install_firmware(libusb_device_handle *hdl, const char *filename) 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; } @@ -85,18 +87,18 @@ int ezusb_upload_firmware(libusb_device *dev, int configuration, 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; } diff --git a/hardware/common/misc.c b/hardware/common/misc.c index 43b158ae..c01e0b6f 100644 --- a/hardware/common/misc.c +++ b/hardware/common/misc.c @@ -24,6 +24,7 @@ #include #endif #include +#include #ifdef HAVE_LIBUSB_1_0 @@ -34,7 +35,7 @@ int opendev2(int device_index, struct sr_device_instance **sdi, 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; } @@ -54,11 +55,11 @@ int opendev2(int device_index, struct sr_device_instance **sdi, 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; } @@ -72,7 +73,7 @@ int opendev3(struct sr_device_instance **sdi, libusb_device *dev, 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; } @@ -84,11 +85,11 @@ int opendev3(struct sr_device_instance **sdi, libusb_device *dev, /* 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; } } diff --git a/hardware/link-mso19/link-mso19.c b/hardware/link-mso19/link-mso19.c index 18e28cff..9c6f015e 100644 --- a/hardware/link-mso19/link-mso19.c +++ b/hardware/link-mso19/link-mso19.c @@ -386,7 +386,7 @@ static int hw_init(const char *deviceinfo) */ udev = udev_new(); if (!udev) { - g_warning("Failed to initialize udev."); + sr_warn("Failed to initialize udev."); goto ret; } enumerate = udev_enumerate_new(udev); @@ -406,8 +406,8 @@ static int hw_init(const char *deviceinfo) 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; } @@ -425,7 +425,7 @@ static int hw_init(const char *deviceinfo) 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); @@ -439,7 +439,7 @@ static int hw_init(const char *deviceinfo) 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 */ @@ -448,8 +448,8 @@ static int hw_init(const char *deviceinfo) 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; } @@ -518,14 +518,14 @@ static int hw_opendev(int device_index) /* 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) diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index 2faadf65..ccdd8a03 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -72,7 +72,7 @@ static int send_shortcommand(int fd, uint8_t command) { 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; @@ -84,7 +84,7 @@ static int send_longcommand(int fd, uint8_t command, uint32_t data) { 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; @@ -210,7 +210,8 @@ static struct sr_device_instance *get_metadata(int fd) 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 */ @@ -231,7 +232,8 @@ static struct sr_device_instance *get_metadata(int fd) 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); @@ -241,7 +243,8 @@ static struct sr_device_instance *get_metadata(int fd) 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 */ @@ -264,7 +267,8 @@ static struct sr_device_instance *get_metadata(int fd) 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; @@ -272,7 +276,8 @@ static struct sr_device_instance *get_metadata(int fd) /* 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 */ @@ -283,7 +288,8 @@ static struct sr_device_instance *get_metadata(int fd) 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; @@ -333,7 +339,7 @@ static int hw_init(const char *deviceinfo) * 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); @@ -563,7 +569,7 @@ static int hw_set_configuration(int device_index, int capability, void *value) 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: @@ -630,10 +636,11 @@ static int receive_data(int fd, int revents, void *user_data) 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 @@ -689,7 +696,7 @@ static int receive_data(int fd, int revents, void *user_data) } } 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. @@ -833,9 +840,9 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) 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; diff --git a/hardware/saleae-logic/saleae-logic.c b/hardware/saleae-logic/saleae-logic.c index e4356d9e..72dbe1a4 100644 --- a/hardware/saleae-logic/saleae-logic.c +++ b/hardware/saleae-logic/saleae-logic.c @@ -233,8 +233,8 @@ static void close_device(struct sr_device_instance *sdi) 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; @@ -302,7 +302,7 @@ static int hw_init(const char *deviceinfo) deviceinfo = deviceinfo; if (libusb_init(&usb_context) != 0) { - g_warning("Failed to initialize USB."); + sr_warn("Failed to initialize USB."); return 0; } @@ -312,7 +312,7 @@ static int hw_init(const char *deviceinfo) 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; } @@ -332,8 +332,8 @@ static int hw_init(const char *deviceinfo) * 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); @@ -366,21 +366,21 @@ static int hw_opendev(int device_index) 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; } @@ -482,14 +482,14 @@ static int set_configuration_samplerate(struct sr_device_instance *sdi, 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; @@ -560,8 +560,8 @@ void receive_transfer(struct libusb_transfer *transfer) 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; @@ -574,7 +574,7 @@ void receive_transfer(struct libusb_transfer *transfer) transfer->length = 4096; if (libusb_submit_transfer(transfer) != 0) { /* TODO: Stop session? */ - g_warning("eek"); + sr_warn("eek"); } if (cur_buflen == 0) { diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index e18d4db6..7ce5c61b 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -150,7 +150,7 @@ static int opendev4(struct sr_device_instance **sdi, libusb_device *dev, 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; } @@ -164,27 +164,26 @@ static int opendev4(struct sr_device_instance **sdi, libusb_device *dev, 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; } } @@ -227,8 +226,8 @@ static void close_device(struct sr_device_instance *sdi) 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; @@ -287,7 +286,7 @@ static int hw_init(const char *deviceinfo) deviceinfo = deviceinfo; if (libusb_init(&usb_context) != 0) { - g_warning("Failed to initialize USB."); + sr_warn("Failed to initialize USB."); return 0; } @@ -298,7 +297,7 @@ static int hw_init(const char *deviceinfo) 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; } @@ -332,13 +331,13 @@ static int hw_opendev(int device_index) 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); @@ -446,7 +445,7 @@ static int *hw_get_capabilities(void) /* 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)) @@ -498,15 +497,15 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) 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); @@ -528,8 +527,8 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) 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; diff --git a/hwplugin.c b/hwplugin.c index 76d2b80c..412cf2d6 100644 --- a/hwplugin.c +++ b/hwplugin.c @@ -25,6 +25,7 @@ #include #include #include +#include /* The list of loaded plugins lives here. */ GSList *plugins; @@ -137,7 +138,7 @@ struct sr_device_instance *sr_get_device_instance(GSList *device_instances, 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; } diff --git a/input/input_chronovu_la8.c b/input/input_chronovu_la8.c index a8095f01..dc6a0117 100644 --- a/input/input_chronovu_la8.c +++ b/input/input_chronovu_la8.c @@ -22,6 +22,7 @@ #include #include #include +#include #define NUM_PACKETS 2048 #define PACKET_SIZE 4096 @@ -48,21 +49,21 @@ static uint64_t divcount_to_samplerate(uint8_t divcount) 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; } @@ -81,7 +82,7 @@ static int init(struct sr_input *in) 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 { @@ -104,7 +105,7 @@ static int loadfile(struct sr_input *in, const char *filename) /* 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; } @@ -119,10 +120,10 @@ static int loadfile(struct sr_input *in, const char *filename) 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; @@ -138,7 +139,7 @@ static int loadfile(struct sr_input *in, const char *filename) /* 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; @@ -153,7 +154,7 @@ static int loadfile(struct sr_input *in, const char *filename) 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; diff --git a/log.c b/log.c new file mode 100644 index 00000000..22dcc107 --- /dev/null +++ b/log.c @@ -0,0 +1,97 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2011 Uwe Hermann + * + * 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 +#include +#include +#include + +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; +} diff --git a/output/output_analog.c b/output/output_analog.c index 5118b5ae..663b8df3 100644 --- a/output/output_analog.c +++ b/output/output_analog.c @@ -274,7 +274,7 @@ static int data_bits(struct sr_output *o, const char *data_in, } } } else { - g_message("short buffer (length_in=%" PRIu64 ")", length_in); + sr_info("short buffer (length_in=%" PRIu64 ")", length_in); } *data_out = outbuf; @@ -428,7 +428,7 @@ static int data_ascii(struct sr_output *o, const char *data_in, 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; diff --git a/output/output_binary.c b/output/output_binary.c index f5429585..e5c1e4ad 100644 --- a/output/output_binary.c +++ b/output/output_binary.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "config.h" static int data(struct sr_output *o, const char *data_in, uint64_t length_in, @@ -33,22 +34,22 @@ 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; } diff --git a/output/output_chronovu_la8.c b/output/output_chronovu_la8.c index adec2dfa..b97c6204 100644 --- a/output/output_chronovu_la8.c +++ b/output/output_chronovu_la8.c @@ -22,6 +22,7 @@ #include #include #include +#include struct context { unsigned int num_enabled_probes; @@ -46,8 +47,8 @@ static int is_valid_samplerate(uint64_t samplerate) 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; } @@ -65,13 +66,13 @@ static int is_valid_samplerate(uint64_t samplerate) 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; } @@ -87,22 +88,22 @@ static int init(struct sr_output *o) 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; } @@ -140,38 +141,37 @@ static int event(struct sr_output *o, int event_type, char **data_out, 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; // } @@ -187,8 +187,8 @@ static int event(struct sr_output *o, int event_type, char **data_out, 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; @@ -204,22 +204,22 @@ static int data(struct sr_output *o, const char *data_in, uint64_t length_in, 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; } diff --git a/output/output_gnuplot.c b/output/output_gnuplot.c index ec50b9d2..c3417c45 100644 --- a/output/output_gnuplot.c +++ b/output/output_gnuplot.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "config.h" struct context { @@ -61,29 +62,29 @@ static int init(struct sr_output *o) 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; } @@ -105,8 +106,8 @@ static int init(struct sr_output *o) 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; @@ -124,7 +125,7 @@ static int init(struct sr_output *o) } 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; @@ -137,7 +138,7 @@ static int init(struct sr_output *o) 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; @@ -152,17 +153,17 @@ static int event(struct sr_output *o, int event_type, char **data_out, 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; } @@ -177,8 +178,8 @@ static int event(struct sr_output *o, int event_type, char **data_out, 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; } @@ -198,27 +199,27 @@ static int data(struct sr_output *o, const char *data_in, uint64_t length_in, 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; } @@ -229,7 +230,7 @@ static int data(struct sr_output *o, const char *data_in, uint64_t length_in, 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; } diff --git a/output/output_vcd.c b/output/output_vcd.c index 94efd2eb..509aad07 100644 --- a/output/output_vcd.c +++ b/output/output_vcd.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "config.h" struct context { @@ -61,7 +62,7 @@ static int init(struct sr_output *o) 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; } diff --git a/output/text/ascii.c b/output/text/ascii.c index fd6c924e..2d0c1c36 100644 --- a/output/text/ascii.c +++ b/output/text/ascii.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "text.h" int init_ascii(struct sr_output *o) @@ -104,7 +105,7 @@ int data_ascii(struct sr_output *o, const char *data_in, uint64_t length_in, 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; diff --git a/output/text/bits.c b/output/text/bits.c index de526e18..00e4d6b9 100644 --- a/output/text/bits.c +++ b/output/text/bits.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "text.h" int init_bits(struct sr_output *o) @@ -91,7 +92,7 @@ int data_bits(struct sr_output *o, const char *data_in, uint64_t length_in, } } } else { - g_message("short buffer (length_in=%" PRIu64 ")", length_in); + sr_info("short buffer (length_in=%" PRIu64 ")", length_in); } *data_out = outbuf; diff --git a/session.c b/session.c index 811bf139..6e597ab3 100644 --- a/session.c +++ b/session.c @@ -24,6 +24,7 @@ #include #include #include +#include /* demo.c */ extern GIOChannel channels[2]; @@ -158,7 +159,7 @@ int sr_session_start(void) 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( @@ -172,7 +173,7 @@ int sr_session_start(void) void sr_session_run(void) { - g_message("session: running"); + sr_info("session: running"); session->running = TRUE; /* do we have real sources? */ @@ -189,7 +190,7 @@ void sr_session_run(void) void sr_session_halt(void) { - g_message("session: halting"); + sr_info("session: halting"); session->running = FALSE; } @@ -199,7 +200,7 @@ void sr_session_stop(void) 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; diff --git a/session_driver.c b/session_driver.c index fa1b9065..b69cf243 100644 --- a/session_driver.c +++ b/session_driver.c @@ -24,6 +24,7 @@ #include #include #include +#include /* size of payloads sent across the session bus */ #define CHUNKSIZE 4096 @@ -72,7 +73,7 @@ static int feed_chunk(int fd, int revents, void *user_data) 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) { @@ -225,24 +226,24 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) 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; } diff --git a/session_file.c b/session_file.c index c8939e5f..764cb68f 100644 --- a/session_file.c +++ b/session_file.c @@ -45,25 +45,25 @@ int sr_session_load(const char *filename) 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); @@ -73,7 +73,7 @@ int sr_session_load(const char *filename) 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; } @@ -159,8 +159,8 @@ int sr_session_save(const char *filename) 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; } @@ -234,7 +234,7 @@ int sr_session_save(const char *filename) 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; } diff --git a/sigrok-internal.h b/sigrok-internal.h index 4aeae18e..d3853403 100644 --- a/sigrok-internal.h +++ b/sigrok-internal.h @@ -20,6 +20,8 @@ #ifndef SIGROK_SIGROK_INTERNAL_H #define SIGROK_SIGROK_INTERNAL_H +#include + /*--- Macros ----------------------------------------------------------------*/ #ifndef ARRAY_SIZE @@ -37,6 +39,21 @@ 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);