victor-dmm: Cosmetics.

This commit is contained in:
Uwe Hermann 2012-11-11 09:28:30 +01:00
parent 5df7b20156
commit fa7730623a
2 changed files with 48 additions and 48 deletions

View File

@ -18,12 +18,12 @@
*/ */
#include <glib.h> #include <glib.h>
#include "libsigrok.h"
#include "libsigrok-internal.h"
#include "protocol.h"
#include <libusb.h> #include <libusb.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "libsigrok.h"
#include "libsigrok-internal.h"
#include "protocol.h"
#define VICTOR_VID 0x1244 #define VICTOR_VID 0x1244
#define VICTOR_PID 0xd237 #define VICTOR_PID 0xd237
@ -48,7 +48,6 @@ static const char *probe_names[] = {
"P1", "P1",
}; };
/* Properly close and free all devices. */ /* Properly close and free all devices. */
static int clear_instances(void) static int clear_instances(void)
{ {
@ -124,8 +123,8 @@ static GSList *hw_scan(GSList *options)
continue; continue;
devcnt = g_slist_length(drvc->instances); devcnt = g_slist_length(drvc->instances);
if (!(sdi = sr_dev_inst_new(devcnt, SR_ST_INACTIVE, VICTOR_VENDOR, if (!(sdi = sr_dev_inst_new(devcnt, SR_ST_INACTIVE,
NULL, NULL))) VICTOR_VENDOR, NULL, NULL)))
return NULL; return NULL;
sdi->driver = di; sdi->driver = di;
@ -179,7 +178,7 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
|| libusb_get_device_address(devlist[i]) != devc->usb->address) || libusb_get_device_address(devlist[i]) != devc->usb->address)
continue; continue;
if ((ret = libusb_open(devlist[i], &devc->usb->devhdl))) { if ((ret = libusb_open(devlist[i], &devc->usb->devhdl))) {
sr_err("Failed to open device: %s", libusb_error_name(ret)); sr_err("Failed to open device: %s.", libusb_error_name(ret));
return SR_ERR; return SR_ERR;
} }
break; break;
@ -201,7 +200,7 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
if ((ret = libusb_claim_interface(devc->usb->devhdl, if ((ret = libusb_claim_interface(devc->usb->devhdl,
VICTOR_INTERFACE))) { VICTOR_INTERFACE))) {
sr_err("Failed to claim interface: %s", libusb_error_name(ret)); sr_err("Failed to claim interface: %s.", libusb_error_name(ret));
return SR_ERR; return SR_ERR;
} }
sdi->status = SR_ST_ACTIVE; sdi->status = SR_ST_ACTIVE;
@ -249,21 +248,21 @@ static int hw_cleanup(void)
static int hw_info_get(int info_id, const void **data, static int hw_info_get(int info_id, const void **data,
const struct sr_dev_inst *sdi) const struct sr_dev_inst *sdi)
{ {
(void)sdi; (void)sdi;
switch (info_id) { switch (info_id) {
case SR_DI_HWCAPS: case SR_DI_HWCAPS:
*data = hwcaps; *data = hwcaps;
break; break;
case SR_DI_NUM_PROBES: case SR_DI_NUM_PROBES:
*data = GINT_TO_POINTER(1); *data = GINT_TO_POINTER(1);
break; break;
case SR_DI_PROBE_NAMES: case SR_DI_PROBE_NAMES:
*data = probe_names; *data = probe_names;
break; break;
default: default:
return SR_ERR_ARG; sr_err("Unknown info_id: %d.", info_id);
return SR_ERR_ARG;
} }
return SR_OK; return SR_OK;
@ -289,18 +288,18 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
devc = sdi->priv; devc = sdi->priv;
ret = SR_OK; ret = SR_OK;
switch (hwcap) { switch (hwcap) {
case SR_HWCAP_LIMIT_MSEC: case SR_HWCAP_LIMIT_MSEC:
devc->limit_msec = *(const int64_t *)value; devc->limit_msec = *(const int64_t *)value;
now = g_get_monotonic_time() / 1000; now = g_get_monotonic_time() / 1000;
devc->end_time = now + devc->limit_msec; devc->end_time = now + devc->limit_msec;
sr_dbg("setting time limit to %" PRIu64 "ms.", sr_dbg("Setting time limit to %" PRIu64 "ms.",
devc->limit_msec); devc->limit_msec);
break; break;
case SR_HWCAP_LIMIT_SAMPLES: case SR_HWCAP_LIMIT_SAMPLES:
devc->limit_samples = *(const uint64_t *)value; devc->limit_samples = *(const uint64_t *)value;
sr_dbg("setting sample limit to %" PRIu64 ".", sr_dbg("Setting sample limit to %" PRIu64 ".",
devc->limit_samples); devc->limit_samples);
break; break;
default: default:
sr_err("Unknown hardware capability: %d.", hwcap); sr_err("Unknown hardware capability: %d.", hwcap);
ret = SR_ERR_ARG; ret = SR_ERR_ARG;
@ -321,7 +320,7 @@ static void receive_transfer(struct libusb_transfer *transfer)
/* USB device was unplugged. */ /* USB device was unplugged. */
hw_dev_acquisition_stop(sdi, sdi); hw_dev_acquisition_stop(sdi, sdi);
} else if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { } else if (transfer->status == LIBUSB_TRANSFER_COMPLETED) {
sr_dbg("got %d-byte packet", transfer->actual_length); sr_dbg("Got %d-byte packet.", transfer->actual_length);
if (transfer->actual_length == DMM_DATA_SIZE) { if (transfer->actual_length == DMM_DATA_SIZE) {
victor_dmm_receive_data(sdi, transfer->buffer); victor_dmm_receive_data(sdi, transfer->buffer);
if (devc->limit_samples) { if (devc->limit_samples) {
@ -336,7 +335,8 @@ static void receive_transfer(struct libusb_transfer *transfer)
if (sdi->status == SR_ST_ACTIVE) { if (sdi->status == SR_ST_ACTIVE) {
/* Send the same request again. */ /* Send the same request again. */
if ((ret = libusb_submit_transfer(transfer) != 0)) { if ((ret = libusb_submit_transfer(transfer) != 0)) {
sr_err("unable to resubmit transfer: %s", libusb_error_name(ret)); sr_err("Unable to resubmit transfer: %s.",
libusb_error_name(ret));
libusb_free_transfer(transfer); libusb_free_transfer(transfer);
g_free(transfer->buffer); g_free(transfer->buffer);
hw_dev_acquisition_stop(sdi, sdi); hw_dev_acquisition_stop(sdi, sdi);
@ -347,7 +347,6 @@ static void receive_transfer(struct libusb_transfer *transfer)
libusb_free_transfer(transfer); libusb_free_transfer(transfer);
g_free(transfer->buffer); g_free(transfer->buffer);
} }
} }
static int handle_events(int fd, int revents, void *cb_data) static int handle_events(int fd, int revents, void *cb_data)
@ -439,9 +438,10 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
* times you ask, but we want to keep step with the USB events * times you ask, but we want to keep step with the USB events
* handling above. */ * handling above. */
libusb_fill_interrupt_transfer(transfer, devc->usb->devhdl, libusb_fill_interrupt_transfer(transfer, devc->usb->devhdl,
VICTOR_ENDPOINT, buf, DMM_DATA_SIZE, receive_transfer, cb_data, 100); VICTOR_ENDPOINT, buf, DMM_DATA_SIZE, receive_transfer,
cb_data, 100);
if ((ret = libusb_submit_transfer(transfer) != 0)) { if ((ret = libusb_submit_transfer(transfer) != 0)) {
sr_err("unable to submit transfer: %s", libusb_error_name(ret)); sr_err("Unable to submit transfer: %s.", libusb_error_name(ret));
libusb_free_transfer(transfer); libusb_free_transfer(transfer);
g_free(buf); g_free(buf);
return SR_ERR; return SR_ERR;
@ -452,7 +452,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
{ {
(void)cb_data; (void)cb_data;
if (!di->priv) { if (!di->priv) {

View File

@ -18,12 +18,11 @@
*/ */
#include <glib.h> #include <glib.h>
#include <string.h>
#include <math.h>
#include "libsigrok.h" #include "libsigrok.h"
#include "libsigrok-internal.h" #include "libsigrok-internal.h"
#include "protocol.h" #include "protocol.h"
#include <string.h>
#include <math.h>
/* Reverse the high nibble into the low nibble */ /* Reverse the high nibble into the low nibble */
static uint8_t decode_digit(uint8_t in) static uint8_t decode_digit(uint8_t in)
@ -85,7 +84,8 @@ static void decode_buf(struct dev_context *devc, unsigned char *data)
factor = 3; factor = 3;
break; break;
default: default:
sr_err("Unknown decimal point value %.2x.", data[7]); sr_err("Unknown decimal point byte: 0x%.2x.", data[7]);
break;
} }
/* Minus flag */ /* Minus flag */
@ -126,10 +126,11 @@ static void decode_buf(struct dev_context *devc, unsigned char *data)
break; break;
case 0x80: case 0x80:
/* Never seen */ /* Never seen */
sr_dbg("Unknown mode right detail %.2x.", data[4]); sr_dbg("Unknown mode right detail: 0x%.2x.", data[4]);
break; break;
default: default:
sr_dbg("Unknown/invalid mode right detail %.2x.", data[4]); sr_dbg("Unknown/invalid mode right detail: 0x%.2x.", data[4]);
break;
} }
/* Scale flags on the right, continued */ /* Scale flags on the right, continued */
@ -169,7 +170,7 @@ static void decode_buf(struct dev_context *devc, unsigned char *data)
analog.mq = SR_MQ_DUTY_CYCLE; analog.mq = SR_MQ_DUTY_CYCLE;
analog.unit = SR_UNIT_PERCENTAGE; analog.unit = SR_UNIT_PERCENTAGE;
} else } else
sr_dbg("Unknown measurement mode %.2x.", data[3]); sr_dbg("Unknown measurement mode: %.2x.", data[3]);
break; break;
case 0x01: case 0x01:
if (is_diode) { if (is_diode) {
@ -211,7 +212,7 @@ static void decode_buf(struct dev_context *devc, unsigned char *data)
break; break;
case 0x08: case 0x08:
/* Never seen */ /* Never seen */
sr_dbg("Unknown measurement mode %.2x.", data[3]); sr_dbg("Unknown measurement mode: 0x%.2x.", data[3]);
break; break;
case 0x10: case 0x10:
analog.mq = SR_MQ_FREQUENCY; analog.mq = SR_MQ_FREQUENCY;
@ -230,7 +231,8 @@ static void decode_buf(struct dev_context *devc, unsigned char *data)
analog.unit = SR_UNIT_FAHRENHEIT; analog.unit = SR_UNIT_FAHRENHEIT;
break; break;
default: default:
sr_dbg("Unknown/invalid measurement mode %.2x.", data[3]); sr_dbg("Unknown/invalid measurement mode: 0x%.2x.", data[3]);
break;
} }
if (analog.mq == -1) if (analog.mq == -1)
return; return;
@ -292,4 +294,3 @@ SR_PRIV int victor_dmm_receive_data(struct sr_dev_inst *sdi, unsigned char *buf)
return SR_OK; return SR_OK;
} }