#include "libsigrok-internal.h"
#include "dso.h"
-
/* Max time in ms before we want to check on USB events */
/* TODO tune this properly */
-#define TICK 1
+#define TICK 1
static const int hwcaps[] = {
SR_HWCAP_OSCILLOSCOPE,
SR_PRIV struct sr_dev_driver hantek_dso_driver_info;
static struct sr_dev_driver *hdi = &hantek_dso_driver_info;
+
static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data);
static struct sr_dev_inst *dso_dev_new(int index, const struct dso_profile *prof)
return NULL;
sdi->driver = hdi;
- /* Add only the real probes -- EXT isn't a source of data, only
+ /*
+ * Add only the real probes -- EXT isn't a source of data, only
* a trigger source internal to the device.
*/
for (i = 0; probe_names[i]; i++) {
}
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
- sr_err("hantek-dso: devc malloc failed");
+ sr_err("Device context malloc failed.");
return NULL;
}
+
devc->profile = prof;
devc->dev_state = IDLE;
devc->timebase = DEFAULT_TIMEBASE;
for (l = drvc->instances; l; l = l->next) {
if (!(sdi = l->data)) {
/* Log error, but continue cleaning up the rest. */
- sr_err("hantek-dso: %s: sdi was NULL, continuing", __func__);
+ sr_err("%s: sdi was NULL, continuing", __func__);
continue;
}
if (!(devc = sdi->priv)) {
/* Log error, but continue cleaning up the rest. */
- sr_err("hantek-dso: %s: sdi->priv was NULL, continuing", __func__);
+ sr_err("%s: sdi->priv was NULL, continuing", __func__);
continue;
}
dso_close(sdi);
struct drv_context *drvc;
if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
- sr_err("hantek-dso: driver context malloc failed.");
+ sr_err("Driver context malloc failed.");
return SR_ERR_MALLOC;
}
if (libusb_init(NULL) != 0) {
g_free(drvc);
- sr_err("hantek-dso: Failed to initialize USB.");
+ sr_err("Failed to initialize USB.");
return SR_ERR;
}
int devcnt, ret, i, j;
(void)options;
+
devcnt = 0;
devices = 0;
drvc = hdi->priv;
libusb_get_device_list(NULL, &devlist);
for (i = 0; devlist[i]; i++) {
if ((ret = libusb_get_device_descriptor(devlist[i], &des))) {
- sr_err("hantek-dso: failed to get device descriptor: %d", ret);
+ sr_err("Failed to get device descriptor: %d.", ret);
continue;
}
&& des.idProduct == dev_profiles[j].orig_pid) {
/* Device matches the pre-firmware profile. */
prof = &dev_profiles[j];
- sr_dbg("hantek-dso: Found a %s %s.", prof->vendor, prof->model);
+ sr_dbg("Found a %s %s.", prof->vendor, prof->model);
sdi = dso_dev_new(devcnt, prof);
devices = g_slist_append(devices, sdi);
devc = sdi->priv;
/* Remember when the firmware on this device was updated */
devc->fw_updated = g_get_monotonic_time();
else
- sr_err("hantek-dso: firmware upload failed for "
- "device %d", devcnt);
+ sr_err("Firmware upload failed for "
+ "device %d.", devcnt);
/* Dummy USB address of 0xff will get overwritten later. */
devc->usb = sr_usb_dev_inst_new(
libusb_get_bus_number(devlist[i]), 0xff, NULL);
&& des.idProduct == dev_profiles[j].fw_pid) {
/* Device matches the post-firmware profile. */
prof = &dev_profiles[j];
- sr_dbg("hantek-dso: Found a %s %s.", prof->vendor, prof->model);
+ sr_dbg("Found a %s %s.", prof->vendor, prof->model);
sdi = dso_dev_new(devcnt, prof);
sdi->status = SR_ST_INACTIVE;
devices = g_slist_append(devices, sdi);
devc = sdi->priv;
/*
- * if the firmware was recently uploaded, wait up to MAX_RENUM_DELAY_MS
- * for the FX2 to renumerate
+ * If the firmware was recently uploaded, wait up to MAX_RENUM_DELAY_MS
+ * for the FX2 to renumerate.
*/
err = SR_ERR;
if (devc->fw_updated > 0) {
- sr_info("hantek-dso: waiting for device to reset");
- /* takes at least 300ms for the FX2 to be gone from the USB bus */
+ sr_info("Waiting for device to reset.");
+ /* Takes >= 300ms for the FX2 to be gone from the USB bus. */
g_usleep(300 * 1000);
timediff_ms = 0;
while (timediff_ms < MAX_RENUM_DELAY_MS) {
g_usleep(100 * 1000);
timediff_us = g_get_monotonic_time() - devc->fw_updated;
timediff_ms = timediff_us / 1000;
- sr_spew("hantek-dso: waited %" PRIi64 " ms", timediff_ms);
+ sr_spew("Waited %" PRIi64 " ms.", timediff_ms);
}
- sr_info("hantek-dso: device came back after %d ms", timediff_ms);
+ sr_info("Device came back after %d ms.", timediff_ms);
} else {
err = dso_open(sdi);
}
if (err != SR_OK) {
- sr_err("hantek-dso: unable to open device");
+ sr_err("Unable to open device.");
return SR_ERR;
}
err = libusb_claim_interface(devc->usb->devhdl, USB_INTERFACE);
if (err != 0) {
- sr_err("hantek-dso: Unable to claim interface: %d", err);
+ sr_err("Unable to claim interface: %d.", err);
return SR_ERR;
}
static int hw_dev_close(struct sr_dev_inst *sdi)
{
-
dso_close(sdi);
return SR_OK;
}
static int hw_info_get(int info_id, const void **data,
- const struct sr_dev_inst *sdi)
+ const struct sr_dev_inst *sdi)
{
uint64_t tmp;
}
static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
- const void *value)
+ const void *value)
{
struct dev_context *devc;
struct sr_rational tmp_rat;
case SR_HWCAP_HORIZ_TRIGGERPOS:
tmp_float = *(const float *)value;
if (tmp_float < 0.0 || tmp_float > 1.0) {
- sr_err("hantek-dso: trigger position should be between 0.0 and 1.0");
+ sr_err("Trigger position should be between 0.0 and 1.0.");
ret = SR_ERR_ARG;
} else
devc->triggerposition = tmp_float;
else if (!strcmp(targets[i], "TRIGGER"))
devc->filter_trigger = TRUE;
else {
- sr_err("invalid filter target %s", targets[i]);
+ sr_err("Invalid filter target %s.", targets[i]);
ret = SR_ERR_ARG;
}
}
g_strfreev(targets);
break;
case SR_HWCAP_VDIV:
- /* TODO not supporting vdiv per channel yet */
+ /* TODO: Not supporting vdiv per channel yet. */
tmp_rat = *(const struct sr_rational *)value;
for (i = 0; vdivs[i].p && vdivs[i].q; i++) {
if (vdivs[i].p == tmp_rat.p
ret = SR_ERR_ARG;
break;
case SR_HWCAP_COUPLING:
- /* TODO not supporting coupling per channel yet */
+ /* TODO: Not supporting coupling per channel yet. */
for (i = 0; coupling[i]; i++) {
if (!strcmp(value, coupling[i])) {
devc->coupling_ch1 = i;
break;
default:
ret = SR_ERR_ARG;
+ break;
}
return ret;
analog.data = g_try_malloc(analog.num_samples * sizeof(float) * num_probes);
data_offset = 0;
for (i = 0; i < analog.num_samples; i++) {
- /* The device always sends data for both channels. If a channel
+ /*
+ * The device always sends data for both channels. If a channel
* is disabled, it contains a copy of the enabled channel's
- * data. However, we only send the requested channels to the bus.
+ * data. However, we only send the requested channels to
+ * the bus.
*
- * Voltage values are encoded as a value 0-255 (0-512 on the 5200*),
- * where the value is a point in the range represented by the vdiv
- * setting. There are 8 vertical divs, so e.g. 500mV/div represents
- * 4V peak-to-peak where 0 = -2V and 255 = +2V.
+ * Voltage values are encoded as a value 0-255 (0-512 on the
+ * DSO-5200*), where the value is a point in the range
+ * represented by the vdiv setting. There are 8 vertical divs,
+ * so e.g. 500mV/div represents 4V peak-to-peak where 0 = -2V
+ * and 255 = +2V.
*/
- /* TODO: support for 5xxx series 9-bit samples */
+ /* TODO: Support for DSO-5xxx series 9-bit samples. */
if (devc->ch1_enabled) {
range = ((float)vdivs[devc->voltage_ch1].p / vdivs[devc->voltage_ch1].q) * 8;
ch1 = range / 255 * *(buf + i * 2 + 1);
}
}
sr_session_send(devc->cb_data, &packet);
-
}
-/* Called by libusb (as triggered by handle_event()) when a transfer comes in.
+/*
+ * Called by libusb (as triggered by handle_event()) when a transfer comes in.
* Only channel data comes in asynchronously, and all transfers for this are
- * queued up beforehand, so this just needs so chuck the incoming data onto
+ * queued up beforehand, so this just needs to chuck the incoming data onto
* the libsigrok session bus.
*/
static void receive_transfer(struct libusb_transfer *transfer)
int num_samples, pre;
devc = transfer->user_data;
- sr_dbg("hantek-dso: receive_transfer(): status %d received %d bytes",
- transfer->status, transfer->actual_length);
+ sr_dbg("receive_transfer(): status %d received %d bytes.",
+ transfer->status, transfer->actual_length);
if (transfer->actual_length == 0)
/* Nothing to send to the bus. */
num_samples = transfer->actual_length / 2;
- sr_dbg("hantek-dso: got %d-%d/%d samples in frame", devc->samp_received + 1,
- devc->samp_received + num_samples, devc->framesize);
+ sr_dbg("Got %d-%d/%d samples in frame.", devc->samp_received + 1,
+ devc->samp_received + num_samples, devc->framesize);
- /* The device always sends a full frame, but the beginning of the frame
+ /*
+ * The device always sends a full frame, but the beginning of the frame
* doesn't represent the trigger point. The offset at which the trigger
* happened came in with the capture state, so we need to start sending
- * from there up the session bus. The samples in the frame buffer before
- * that trigger point came after the end of the device's frame buffer was
- * reached, and it wrapped around to overwrite up until the trigger point.
+ * from there up the session bus. The samples in the frame buffer
+ * before that trigger point came after the end of the device's frame
+ * buffer was reached, and it wrapped around to overwrite up until the
+ * trigger point.
*/
if (devc->samp_received < devc->trigger_offset) {
/* Trigger point not yet reached. */
transfer->buffer, num_samples * 2);
devc->samp_buffered += num_samples;
} else {
- /* This chunk hits or overruns the trigger point.
+ /*
+ * This chunk hits or overruns the trigger point.
* Store the part before the trigger fired, and
- * send the rest up to the session bus. */
+ * send the rest up to the session bus.
+ */
pre = devc->trigger_offset - devc->samp_received;
memcpy(devc->framebuf + devc->samp_buffered * 2,
transfer->buffer, pre * 2);
devc->samp_buffered += pre;
/* The rest of this chunk starts with the trigger point. */
- sr_dbg("hantek-dso: reached trigger point, %d samples buffered",
- devc->samp_buffered);
+ sr_dbg("Reached trigger point, %d samples buffered.",
+ devc->samp_buffered);
/* Avoid the corner case where the chunk ended at
* exactly the trigger point. */
if (devc->samp_received >= devc->framesize) {
/* That was the last chunk in this frame. Send the buffered
* pre-trigger samples out now, in one big chunk. */
- sr_dbg("hantek-dso: end of frame, sending %d pre-trigger buffered samples",
- devc->samp_buffered);
+ sr_dbg("End of frame, sending %d pre-trigger buffered samples.",
+ devc->samp_buffered);
send_chunk(devc, devc->framebuf, devc->samp_buffered);
/* Mark the end of this frame. */
devc->dev_state = NEW_CAPTURE;
}
}
-
}
static int handle_event(int fd, int revents, void *cb_data)
uint32_t trigger_offset;
uint8_t capturestate;
- /* Avoid compiler warnings. */
(void)fd;
(void)revents;
devc = sdi->priv;
if (devc->dev_state == STOPPING) {
/* We've been told to wind up the acquisition. */
- sr_dbg("hantek-dso: stopping acquisition");
- /* TODO: doesn't really cancel pending transfers so they might
- * come in after SR_DF_END is sent. */
+ sr_dbg("Stopping acquisition.");
+ /*
+ * TODO: Doesn't really cancel pending transfers so they might
+ * come in after SR_DF_END is sent.
+ */
lupfd = libusb_get_pollfds(NULL);
for (i = 0; lupfd[i]; i++)
sr_source_remove(lupfd[i]->fd);
return TRUE;
// if (dso_force_trigger(devc) != SR_OK)
// return TRUE;
- sr_dbg("hantek-dso: successfully requested next chunk");
+ sr_dbg("Successfully requested next chunk.");
devc->dev_state = CAPTURE;
return TRUE;
}
if ((dso_get_capturestate(devc, &capturestate, &trigger_offset)) != SR_OK)
return TRUE;
- sr_dbg("hantek-dso: capturestate %d", capturestate);
- sr_dbg("hantek-dso: trigger offset 0x%.6x", trigger_offset);
+ sr_dbg("Capturestate %d.", capturestate);
+ sr_dbg("Trigger offset 0x%.6x.", trigger_offset);
switch (capturestate) {
case CAPTURE_EMPTY:
if (++devc->capture_empty_count >= MAX_CAPTURE_EMPTY) {
break;
// if (dso_force_trigger(devc) != SR_OK)
// break;
- sr_dbg("hantek-dso: successfully requested next chunk");
+ sr_dbg("Successfully requested next chunk.");
}
break;
case CAPTURE_FILLING:
- /* no data yet */
+ /* No data yet. */
break;
case CAPTURE_READY_8BIT:
/* Remember where in the captured frame the trigger is. */
if (dso_get_channeldata(devc, receive_transfer) != SR_OK)
break;
- /* Don't hit the state machine again until we're done fetching
+ /*
+ * Don't hit the state machine again until we're done fetching
* the data we just told the scope to send.
*/
devc->dev_state = FETCH_DATA;
break;
case CAPTURE_READY_9BIT:
/* TODO */
- sr_err("not yet supported");
+ sr_err("Not yet supported.");
break;
case CAPTURE_TIMEOUT:
/* Doesn't matter, we'll try again next time. */
break;
default:
- sr_dbg("unknown capture state");
+ sr_dbg("Unknown capture state: %d.", capturestate);
+ break;
}
return TRUE;
}
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
- void *cb_data)
+ void *cb_data)
{
const struct libusb_pollfd **lupfd;
struct sr_datafeed_packet packet;
devc->cb_data = cb_data;
if (configure_probes(sdi) != SR_OK) {
- sr_err("hantek-dso: failed to configured probes");
+ sr_err("Failed to configure probes.");
return SR_ERR;
}
devc->dev_state = CAPTURE;
lupfd = libusb_get_pollfds(NULL);
for (i = 0; lupfd[i]; i++)
- sr_source_add(lupfd[i]->fd, lupfd[i]->events, TICK, handle_event,
- (void *)sdi);
+ sr_source_add(lupfd[i]->fd, lupfd[i]->events, TICK,
+ handle_event, (void *)sdi);
free(lupfd);
/* Send header packet to the session bus. */
extern struct sr_dev_driver hantek_dso_driver_info;
-
static int send_begin(struct dev_context *devc)
{
int ret;
unsigned char buffer[] = {0x0f, 0x03, 0x03, 0x03, 0x68, 0xac, 0xfe,
0x00, 0x01, 0x00};
- sr_dbg("hantek-dso: sending CTRL_BEGINCOMMAND");
+ sr_dbg("Sending CTRL_BEGINCOMMAND.");
if ((ret = libusb_control_transfer(devc->usb->devhdl,
LIBUSB_REQUEST_TYPE_VENDOR, CTRL_BEGINCOMMAND,
0, 0, buffer, sizeof(buffer), 200)) != sizeof(buffer)) {
- sr_err("failed to send begincommand: %d", ret);
+ sr_err("Failed to send begincommand: %d.", ret);
return SR_ERR;
}
libusb_get_device_list(NULL, &devlist);
for (i = 0; devlist[i]; i++) {
if ((err = libusb_get_device_descriptor(devlist[i], &des))) {
- sr_err("hantek-dso: failed to get device descriptor: %d", err);
+ sr_err("Failed to get device descriptor: %d.", err);
continue;
}
*/
devc->usb->address = libusb_get_device_address(devlist[i]);
- if(!(devc->epin_maxpacketsize = dso_getmps(devlist[i])))
- sr_err("hantek-dso: wrong endpoint profile");
+ if (!(devc->epin_maxpacketsize = dso_getmps(devlist[i])))
+ sr_err("Wrong endpoint profile.");
else {
sdi->status = SR_ST_ACTIVE;
- sr_info("hantek-dso: opened device %d on %d.%d interface %d",
+ sr_info("Opened device %d on %d.%d interface %d.",
sdi->index, devc->usb->bus,
devc->usb->address, USB_INTERFACE);
}
} else {
- sr_err("hantek-dso: failed to open device: %d", err);
+ sr_err("Failed to open device: %d.", err);
}
- /* if we made it here, we handled the device one way or another */
+ /* If we made it here, we handled the device (somehow). */
break;
}
libusb_free_device_list(devlist, 1);
if (devc->usb->devhdl == NULL)
return;
- sr_info("hantek-dso: closing device %d on %d.%d interface %d", sdi->index,
+ sr_info("Closing device %d on %d.%d interface %d.", sdi->index,
devc->usb->bus, devc->usb->address, USB_INTERFACE);
libusb_release_interface(devc->usb->devhdl, USB_INTERFACE);
libusb_close(devc->usb->devhdl);
GString *gs;
int chan, v, ret;
- sr_dbg("hantek-dso: getting channel offsets");
+ sr_dbg("Getting channel offsets.");
ret = libusb_control_transfer(devc->usb->devhdl,
LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR,
(unsigned char *)&devc->channel_levels,
sizeof(devc->channel_levels), 200);
if (ret != sizeof(devc->channel_levels)) {
- sr_err("failed to get channel offsets: %d", ret);
+ sr_err("Failed to get channel offsets: %d.", ret);
return SR_ERR;
}
*/
for (chan = 0; chan < 2; chan++) {
for (v = 0; v < 9; v++) {
- devc->channel_levels[chan][v][0] = g_ntohs(devc->channel_levels[chan][v][0]);
- devc->channel_levels[chan][v][1] = g_ntohs(devc->channel_levels[chan][v][1]);
+ devc->channel_levels[chan][v][0] =
+ g_ntohs(devc->channel_levels[chan][v][0]);
+ devc->channel_levels[chan][v][1] =
+ g_ntohs(devc->channel_levels[chan][v][1]);
}
}
if (sr_log_loglevel_get() >= SR_LOG_DBG) {
gs = g_string_sized_new(128);
for (chan = 0; chan < 2; chan++) {
- g_string_printf(gs, "hantek-dso: CH%d:", chan + 1);
+ g_string_printf(gs, "CH%d:", chan + 1);
for (v = 0; v < 9; v++) {
g_string_append_printf(gs, " %.4x-%.4x",
- devc->channel_levels[chan][v][0],
- devc->channel_levels[chan][v][1]);
+ devc->channel_levels[chan][v][0],
+ devc->channel_levels[chan][v][1]);
}
sr_dbg(gs->str);
}
int ret, tmp;
uint8_t cmdstring[12];
uint16_t timebase_small[] = { 0xffff, 0xfffc, 0xfff7, 0xffe8, 0xffce,
- 0xff9c, 0xff07, 0xfe0d, 0xfc19, 0xf63d, 0xec79, 0xd8f1 };
+ 0xff9c, 0xff07, 0xfe0d, 0xfc19, 0xf63d, 0xec79, 0xd8f1 };
uint16_t timebase_large[] = { 0xffff, 0x0000, 0xfffc, 0xfff7, 0xffe8,
- 0xffce, 0xff9d, 0xff07, 0xfe0d, 0xfc19, 0xf63d, 0xec79 };
+ 0xffce, 0xff9d, 0xff07, 0xfe0d, 0xfc19, 0xf63d, 0xec79 };
- sr_dbg("hantek-dso: preparing CMD_SET_TRIGGER_SAMPLERATE");
+ sr_dbg("Preparing CMD_SET_TRIGGER_SAMPLERATE.");
memset(cmdstring, 0, sizeof(cmdstring));
/* Command */
cmdstring[0] = CMD_SET_TRIGGER_SAMPLERATE;
/* Trigger source */
- sr_dbg("hantek-dso: trigger source %s", devc->triggersource);
+ sr_dbg("Trigger source %s.", devc->triggersource);
if (!strcmp("CH2", devc->triggersource))
tmp = 0;
else if (!strcmp("CH1", devc->triggersource))
else if (!strcmp("EXT", devc->triggersource))
tmp = 2;
else {
- sr_err("hantek-dso: invalid trigger source %s", devc->triggersource);
+ sr_err("Invalid trigger source: '%s'.", devc->triggersource);
return SR_ERR_ARG;
}
cmdstring[2] = tmp;
/* Frame size */
- sr_dbg("hantek-dso: frame size %d", devc->framesize);
+ sr_dbg("Frame size: %d.", devc->framesize);
cmdstring[2] |= (devc->framesize == FRAMESIZE_SMALL ? 0x01 : 0x02) << 2;
/* Timebase fast */
- sr_dbg("hantek-dso: time base index %d", devc->timebase);
+ sr_dbg("Time base index: %d.", devc->timebase);
switch (devc->framesize) {
case FRAMESIZE_SMALL:
if (devc->timebase < TIME_20us)
break;
case FRAMESIZE_LARGE:
if (devc->timebase < TIME_40us) {
- sr_err("hantek-dso: timebase < 40us only supported with 10K buffer");
+ sr_err("Timebase < 40us only supported with 10K buffer.");
return SR_ERR_ARG;
}
else if (devc->timebase == TIME_40us)
cmdstring[2] |= (tmp & 0x07) << 5;
/* Enabled channels: 00=CH1 01=CH2 10=both */
- sr_dbg("hantek-dso: channels CH1=%d CH2=%d", devc->ch1_enabled, devc->ch2_enabled);
+ sr_dbg("Channels CH1=%d CH2=%d", devc->ch1_enabled, devc->ch2_enabled);
tmp = (((devc->ch2_enabled ? 1 : 0) << 1) + (devc->ch1_enabled ? 1 : 0)) - 1;
cmdstring[3] = tmp;
/* Fast rates channel */
- /* TODO: is this right? */
+ /* TODO: Is this right? */
tmp = devc->timebase < TIME_10us ? 1 : 0;
cmdstring[3] |= tmp << 2;
/* Trigger slope: 0=positive 1=negative */
- /* TODO: does this work? */
- sr_dbg("hantek-dso: trigger slope %d", devc->triggerslope);
+ /* TODO: Does this work? */
+ sr_dbg("Trigger slope: %d.", devc->triggerslope);
cmdstring[3] |= (devc->triggerslope == SLOPE_NEGATIVE ? 1 : 0) << 3;
/* Timebase slow */
cmdstring[5] = (tmp >> 8) & 0xff;
/* Horizontal trigger position */
- sr_dbg("hantek-dso: trigger position %3.2f", devc->triggerposition);
+ sr_dbg("Trigger position: %3.2f.", devc->triggerposition);
tmp = 0x77fff + 0x8000 * devc->triggerposition;
cmdstring[6] = tmp & 0xff;
cmdstring[7] = (tmp >> 8) & 0xff;
DSO_EP_OUT | LIBUSB_ENDPOINT_OUT,
cmdstring, sizeof(cmdstring),
&tmp, 100)) != 0) {
- sr_err("Failed to set trigger/samplerate: %d", ret);
+ sr_err("Failed to set trigger/samplerate: %d.", ret);
return SR_ERR;
}
- sr_dbg("hantek-dso: sent CMD_SET_TRIGGER_SAMPLERATE");
+ sr_dbg("Sent CMD_SET_TRIGGER_SAMPLERATE.");
return SR_OK;
}
int ret, tmp;
uint8_t cmdstring[8];
- sr_dbg("hantek-dso: preparing CMD_SET_FILTERS");
+ sr_dbg("Preparing CMD_SET_FILTERS.");
memset(cmdstring, 0, sizeof(cmdstring));
cmdstring[0] = CMD_SET_FILTERS;
cmdstring[1] = 0x0f;
if (devc->filter_ch1) {
- sr_dbg("hantek-dso: turning on CH1 filter");
+ sr_dbg("Turning on CH1 filter.");
cmdstring[2] |= 0x80;
}
if (devc->filter_ch2) {
- sr_dbg("hantek-dso: turning on CH2 filter");
+ sr_dbg("Turning on CH2 filter.");
cmdstring[2] |= 0x40;
}
if (devc->filter_trigger) {
/* TODO: supported on the DSO-2090? */
- sr_dbg("hantek-dso: turning on trigger filter");
+ sr_dbg("Turning on trigger filter.");
cmdstring[2] |= 0x20;
}
sr_err("Failed to set filters: %d", ret);
return SR_ERR;
}
- sr_dbg("hantek-dso: sent CMD_SET_FILTERS");
+ sr_dbg("Sent CMD_SET_FILTERS.");
return SR_OK;
}
int ret, tmp;
uint8_t cmdstring[8];
- sr_dbg("hantek-dso: preparing CMD_SET_VOLTAGE");
+ sr_dbg("Preparing CMD_SET_VOLTAGE.");
memset(cmdstring, 0, sizeof(cmdstring));
cmdstring[0] = CMD_SET_VOLTAGE;
cmdstring[2] = 0x30;
/* CH1 volts/div is encoded in bits 0-1 */
- sr_dbg("hantek-dso: CH1 vdiv index %d", devc->voltage_ch1);
+ sr_dbg("CH1 vdiv index: %d.", devc->voltage_ch1);
switch (devc->voltage_ch1) {
case VDIV_1V:
case VDIV_100MV:
}
/* CH2 volts/div is encoded in bits 2-3 */
- sr_dbg("hantek-dso: CH2 vdiv index %d", devc->voltage_ch2);
+ sr_dbg("CH2 vdiv index: %d.", devc->voltage_ch2);
switch (devc->voltage_ch2) {
case VDIV_1V:
case VDIV_100MV:
DSO_EP_OUT | LIBUSB_ENDPOINT_OUT,
cmdstring, sizeof(cmdstring),
&tmp, 100)) != 0) {
- sr_err("Failed to set voltage: %d", ret);
+ sr_err("Failed to set voltage: %d.", ret);
return SR_ERR;
}
- sr_dbg("hantek-dso: sent CMD_SET_VOLTAGE");
+ sr_dbg("Sent CMD_SET_VOLTAGE.");
return SR_OK;
}
uint8_t relays[17] = { 0x00, 0x04, 0x08, 0x02, 0x20, 0x40, 0x10, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- sr_dbg("hantek-dso: preparing CTRL_SETRELAYS");
+ sr_dbg("Preparing CTRL_SETRELAYS.");
if (devc->voltage_ch1 < VDIV_1V)
relays[1] = ~relays[1];
if (devc->voltage_ch1 < VDIV_100MV)
relays[2] = ~relays[2];
- sr_dbg("hantek-dso: CH1 coupling %d", devc->coupling_ch1);
+ sr_dbg("CH1 coupling: %d.", devc->coupling_ch1);
if (devc->coupling_ch1 != COUPLING_AC)
relays[3] = ~relays[3];
if (devc->voltage_ch2 < VDIV_100MV)
relays[5] = ~relays[5];
- sr_dbg("hantek-dso: CH2 coupling %d", devc->coupling_ch1);
+ sr_dbg("CH2 coupling: %d.", devc->coupling_ch1);
if (devc->coupling_ch2 != COUPLING_AC)
relays[6] = ~relays[6];
if (sr_log_loglevel_get() >= SR_LOG_DBG) {
gs = g_string_sized_new(128);
- g_string_printf(gs, "hantek-dso: relays:");
+ g_string_printf(gs, "Relays:");
for (i = 0; i < 17; i++)
g_string_append_printf(gs, " %.2x", relays[i]);
sr_dbg(gs->str);
if ((ret = libusb_control_transfer(devc->usb->devhdl,
LIBUSB_REQUEST_TYPE_VENDOR, CTRL_SETRELAYS,
0, 0, relays, 17, 100)) != sizeof(relays)) {
- sr_err("failed to set relays: %d", ret);
+ sr_err("Failed to set relays: %d.", ret);
return SR_ERR;
}
- sr_dbg("hantek-dso: sent CTRL_SETRELAYS");
+ sr_dbg("Sent CTRL_SETRELAYS.");
return SR_OK;
}
uint16_t *ch_levels;
uint8_t offsets[17];
- sr_dbg("hantek-dso: preparing CTRL_SETOFFSET");
+ sr_dbg("Preparing CTRL_SETOFFSET.");
memset(offsets, 0, sizeof(offsets));
/* Channel 1 */
offset = (ch_levels[1] - ch_levels[0]) * devc->voffset_ch1 + ch_levels[0];
offsets[0] = (offset >> 8) | 0x20;
offsets[1] = offset & 0xff;
- sr_dbg("hantek-dso: CH1 offset %3.2f (%.2x%.2x)", devc->voffset_ch1,
- offsets[0], offsets[1]);
+ sr_dbg("CH1 offset: %3.2f (%.2x%.2x).", devc->voffset_ch1,
+ offsets[0], offsets[1]);
/* Channel 2 */
ch_levels = devc->channel_levels[1][devc->voltage_ch2];
offset = (ch_levels[1] - ch_levels[0]) * devc->voffset_ch2 + ch_levels[0];
offsets[2] = (offset >> 8) | 0x20;
offsets[3] = offset & 0xff;
- sr_dbg("hantek-dso: CH2 offset %3.2f (%.2x%.2x)", devc->voffset_ch2,
- offsets[2], offsets[3]);
+ sr_dbg("CH2 offset: %3.2f (%.2x%.2x).", devc->voffset_ch2,
+ offsets[2], offsets[3]);
/* Trigger */
offset = MAX_VERT_TRIGGER * devc->voffset_trigger;
offsets[4] = (offset >> 8) | 0x20;
offsets[5] = offset & 0xff;
- sr_dbg("hantek-dso: trigger offset %3.2f (%.2x%.2x)", devc->voffset_trigger,
+ sr_dbg("Trigger offset: %3.2f (%.2x%.2x).", devc->voffset_trigger,
offsets[4], offsets[5]);
if ((ret = libusb_control_transfer(devc->usb->devhdl,
LIBUSB_REQUEST_TYPE_VENDOR, CTRL_SETOFFSET,
0, 0, offsets, sizeof(offsets), 100)) != sizeof(offsets)) {
- sr_err("failed to set offsets: %d", ret);
+ sr_err("Failed to set offsets: %d.", ret);
return SR_ERR;
}
- sr_dbg("hantek-dso: sent CTRL_SETOFFSET");
+ sr_dbg("Sent CTRL_SETOFFSET.");
return SR_OK;
}
int ret, tmp;
uint8_t cmdstring[2];
- sr_dbg("hantek-dso: sending CMD_ENABLE_TRIGGER");
+ sr_dbg("Sending CMD_ENABLE_TRIGGER.");
memset(cmdstring, 0, sizeof(cmdstring));
cmdstring[0] = CMD_ENABLE_TRIGGER;
DSO_EP_OUT | LIBUSB_ENDPOINT_OUT,
cmdstring, sizeof(cmdstring),
&tmp, 100)) != 0) {
- sr_err("Failed to enable trigger: %d", ret);
+ sr_err("Failed to enable trigger: %d.", ret);
return SR_ERR;
}
int ret, tmp;
uint8_t cmdstring[2];
- sr_dbg("hantek-dso: sending CMD_FORCE_TRIGGER");
+ sr_dbg("Sending CMD_FORCE_TRIGGER.");
memset(cmdstring, 0, sizeof(cmdstring));
cmdstring[0] = CMD_FORCE_TRIGGER;
DSO_EP_OUT | LIBUSB_ENDPOINT_OUT,
cmdstring, sizeof(cmdstring),
&tmp, 100)) != 0) {
- sr_err("Failed to force trigger: %d", ret);
+ sr_err("Failed to force trigger: %d.", ret);
return SR_ERR;
}
SR_PRIV int dso_init(struct dev_context *devc)
{
- sr_dbg("hantek-dso: initializing dso");
+ sr_dbg("Initializing DSO.");
if (get_channel_offsets(devc) != SR_OK)
return SR_ERR;
return SR_OK;
}
-SR_PRIV int dso_get_capturestate(struct dev_context *devc, uint8_t *capturestate,
- uint32_t *trigger_offset)
+SR_PRIV int dso_get_capturestate(struct dev_context *devc,
+ uint8_t *capturestate,
+ uint32_t *trigger_offset)
{
int ret, tmp, i;
unsigned int bitvalue, toff;
uint8_t cmdstring[2], inbuf[512];
- sr_dbg("hantek-dso: sending CMD_GET_CAPTURESTATE");
+ sr_dbg("Sending CMD_GET_CAPTURESTATE.");
cmdstring[0] = CMD_GET_CAPTURESTATE;
cmdstring[1] = 0;
if ((ret = send_bulkcmd(devc, cmdstring, sizeof(cmdstring))) != SR_OK) {
- sr_dbg("Failed to send get_capturestate command: %d", ret);
+ sr_dbg("Failed to send get_capturestate command: %d.", ret);
return SR_ERR;
}
if ((ret = libusb_bulk_transfer(devc->usb->devhdl,
DSO_EP_IN | LIBUSB_ENDPOINT_IN,
inbuf, 512, &tmp, 100)) != 0) {
- sr_dbg("Failed to get capturestate: %d", ret);
+ sr_dbg("Failed to get capturestate: %d.", ret);
return SR_ERR;
}
*capturestate = inbuf[0];
toff = (inbuf[1] << 16) | (inbuf[3] << 8) | inbuf[2];
- /* This conversion comes from the openhantek project.
+ /*
+ * This conversion comes from the openhantek project.
* Each set bit in the 24-bit value inverts all bits with a lower
* value. No idea why the device reports the trigger point this way.
*/
int ret;
uint8_t cmdstring[2];
- sr_dbg("hantek-dso: sending CMD_CAPTURE_START");
+ sr_dbg("Sending CMD_CAPTURE_START.");
cmdstring[0] = CMD_CAPTURE_START;
cmdstring[1] = 0;
if ((ret = send_bulkcmd(devc, cmdstring, sizeof(cmdstring))) != SR_OK) {
- sr_err("Failed to send capture_start command: %d", ret);
+ sr_err("Failed to send capture_start command: %d.", ret);
return SR_ERR;
}
uint8_t cmdstring[2];
unsigned char *buf;
- sr_dbg("hantek-dso: sending CMD_GET_CHANNELDATA");
+ sr_dbg("Sending CMD_GET_CHANNELDATA.");
cmdstring[0] = CMD_GET_CHANNELDATA;
cmdstring[1] = 0;
if ((ret = send_bulkcmd(devc, cmdstring, sizeof(cmdstring))) != SR_OK) {
- sr_err("Failed to get channel data: %d", ret);
+ sr_err("Failed to get channel data: %d.", ret);
return SR_ERR;
}
- /* TODO: dso-2xxx only */
- num_transfers = devc->framesize * sizeof(unsigned short) / devc->epin_maxpacketsize;
- sr_dbg("hantek-dso: queueing up %d transfers", num_transfers);
+ /* TODO: DSO-2xxx only. */
+ num_transfers = devc->framesize *
+ sizeof(unsigned short) / devc->epin_maxpacketsize;
+ sr_dbg("Queueing up %d transfers.", num_transfers);
for (i = 0; i < num_transfers; i++) {
if (!(buf = g_try_malloc(devc->epin_maxpacketsize))) {
- sr_err("hantek-dso: %s: buf malloc failed", __func__);
+ sr_err("Failed to malloc USB endpoint buffer.");
return SR_ERR_MALLOC;
}
transfer = libusb_alloc_transfer(0);
DSO_EP_IN | LIBUSB_ENDPOINT_IN, buf,
devc->epin_maxpacketsize, cb, devc, 40);
if ((ret = libusb_submit_transfer(transfer)) != 0) {
- sr_err("failed to submit transfer: %d", ret);
+ sr_err("Failed to submit transfer: %d.", ret);
/* TODO: Free them all. */
libusb_free_transfer(transfer);
g_free(buf);
return SR_OK;
}
-