lascar-el-usb: support for SR_CONF_DATALOG
This commit is contained in:
parent
e6551ea640
commit
361d15110c
|
@ -36,10 +36,15 @@ static const int hwopts[] = {
|
|||
static const int hwcaps[] = {
|
||||
SR_CONF_THERMOMETER,
|
||||
SR_CONF_HYGROMETER,
|
||||
SR_CONF_DATALOG,
|
||||
SR_CONF_LIMIT_SAMPLES,
|
||||
0
|
||||
};
|
||||
|
||||
/* Terrible hack */
|
||||
static int BOOL_TRUE = TRUE;
|
||||
static int BOOL_FALSE = FALSE;
|
||||
|
||||
/* Properly close and free all devices. */
|
||||
static int clear_instances(void)
|
||||
{
|
||||
|
@ -171,7 +176,6 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
|||
libusb_release_interface(devc->usb->devhdl, LASCAR_INTERFACE);
|
||||
libusb_close(devc->usb->devhdl);
|
||||
devc->usb->devhdl = NULL;
|
||||
g_free(devc->config);
|
||||
sdi->status = SR_ST_INACTIVE;
|
||||
|
||||
|
||||
|
@ -193,6 +197,30 @@ static int hw_cleanup(void)
|
|||
return SR_OK;
|
||||
}
|
||||
|
||||
static int config_get(int id, const void **data, const struct sr_dev_inst *sdi)
|
||||
{
|
||||
struct dev_context *devc;
|
||||
int ret;
|
||||
|
||||
devc = sdi->priv;
|
||||
switch (id) {
|
||||
case SR_CONF_DATALOG:
|
||||
if (!sdi)
|
||||
return SR_ERR_ARG;
|
||||
if ((ret = lascar_is_logging(sdi)) == -1)
|
||||
return SR_ERR;
|
||||
*data = ret ? &BOOL_TRUE : &BOOL_FALSE;
|
||||
break;
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
*data = &devc->limit_samples;
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
|
||||
{
|
||||
struct dev_context *devc;
|
||||
|
@ -210,6 +238,15 @@ static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
|
|||
devc = sdi->priv;
|
||||
ret = SR_OK;
|
||||
switch (id) {
|
||||
case SR_CONF_DATALOG:
|
||||
if (*(int *)value) {
|
||||
/* Start logging. */
|
||||
ret = lascar_start_logging(sdi);
|
||||
} else {
|
||||
/* Stop logging. */
|
||||
ret = lascar_stop_logging(sdi);
|
||||
}
|
||||
break;
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = *(const uint64_t *)value;
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||
|
@ -274,10 +311,10 @@ static float binary32_le_to_float(unsigned char *buf)
|
|||
static int lascar_proc_config(const struct sr_dev_inst *sdi)
|
||||
{
|
||||
struct dev_context *devc;
|
||||
int ret;
|
||||
int dummy, ret;
|
||||
|
||||
devc = sdi->priv;
|
||||
if (!(devc->config = lascar_get_config(devc->usb->devhdl)))
|
||||
if (lascar_get_config(devc->usb->devhdl, devc->config, &dummy) != SR_OK)
|
||||
return SR_ERR;
|
||||
|
||||
ret = SR_OK;
|
||||
|
@ -454,7 +491,7 @@ SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info = {
|
|||
.scan = hw_scan,
|
||||
.dev_list = hw_dev_list,
|
||||
.dev_clear = clear_instances,
|
||||
.config_get = NULL,
|
||||
.config_get = config_get,
|
||||
.config_set = config_set,
|
||||
.config_list = config_list,
|
||||
.dev_open = hw_dev_open,
|
||||
|
|
|
@ -85,21 +85,24 @@ static void mark_xfer(struct libusb_transfer *xfer)
|
|||
|
||||
}
|
||||
|
||||
SR_PRIV unsigned char *lascar_get_config(libusb_device_handle *dev_hdl)
|
||||
SR_PRIV int lascar_get_config(libusb_device_handle *dev_hdl,
|
||||
unsigned char *configblock, int *configlen)
|
||||
{
|
||||
struct drv_context *drvc;
|
||||
struct libusb_transfer *xfer_in, *xfer_out;
|
||||
struct timeval tv;
|
||||
int64_t start;
|
||||
int buflen;
|
||||
unsigned char cmd[3], buf[256], *config;
|
||||
unsigned char cmd[3], buf[MAX_CONFIGBLOCK_SIZE];
|
||||
|
||||
sr_spew("Reading config block.");
|
||||
|
||||
drvc = di->priv;
|
||||
config = NULL;
|
||||
*configlen = 0;
|
||||
|
||||
if (!(xfer_in = libusb_alloc_transfer(0)) ||
|
||||
!(xfer_out = libusb_alloc_transfer(0)))
|
||||
return NULL;
|
||||
return SR_ERR;
|
||||
|
||||
/* Flush anything the F321 still has queued. */
|
||||
while (libusb_bulk_transfer(dev_hdl, LASCAR_EP_IN, buf, 256, &buflen,
|
||||
|
@ -143,10 +146,10 @@ SR_PRIV unsigned char *lascar_get_config(libusb_device_handle *dev_hdl)
|
|||
}
|
||||
|
||||
/* Got configuration structure header. */
|
||||
sr_dbg("response to config request: 0x%.2x 0x%.2x 0x%.2x ",
|
||||
sr_spew("Response to config request: 0x%.2x 0x%.2x 0x%.2x ",
|
||||
buf[0], buf[1], buf[2]);
|
||||
buflen = buf[1] | (buf[2] << 8);
|
||||
if (buf[0] != 0x02 || buflen > 256) {
|
||||
if (buf[0] != 0x02 || buflen > MAX_CONFIGBLOCK_SIZE) {
|
||||
sr_dbg("Invalid response to config request: "
|
||||
"0x%.2x 0x%.2x 0x%.2x ", buf[0], buf[1], buf[2]);
|
||||
libusb_close(dev_hdl);
|
||||
|
@ -176,9 +179,8 @@ SR_PRIV unsigned char *lascar_get_config(libusb_device_handle *dev_hdl)
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(config = g_try_malloc(256)))
|
||||
return NULL;
|
||||
memcpy(config, buf, buflen);
|
||||
memcpy(configblock, buf, buflen);
|
||||
*configlen = buflen;
|
||||
|
||||
cleanup:
|
||||
if (!xfer_in->user_data || !xfer_in->user_data) {
|
||||
|
@ -197,10 +199,9 @@ cleanup:
|
|||
libusb_free_transfer(xfer_in);
|
||||
libusb_free_transfer(xfer_out);
|
||||
|
||||
return config;
|
||||
return *configlen ? SR_OK : SR_ERR;
|
||||
}
|
||||
|
||||
/* Currently unused. */
|
||||
SR_PRIV int lascar_save_config(libusb_device_handle *dev_hdl,
|
||||
unsigned char *config, int configlen)
|
||||
{
|
||||
|
@ -211,6 +212,8 @@ SR_PRIV int lascar_save_config(libusb_device_handle *dev_hdl,
|
|||
int buflen, ret;
|
||||
unsigned char cmd[3], buf[256];
|
||||
|
||||
sr_spew("Writing config block.");
|
||||
|
||||
drvc = di->priv;
|
||||
|
||||
if (!(xfer_in = libusb_alloc_transfer(0)) ||
|
||||
|
@ -345,8 +348,8 @@ SR_PRIV struct sr_dev_inst *lascar_scan(int bus, int address)
|
|||
struct libusb_device **devlist;
|
||||
struct libusb_device_descriptor des;
|
||||
libusb_device_handle *dev_hdl;
|
||||
int ret, i;
|
||||
unsigned char *config;
|
||||
int dummy, ret, i;
|
||||
unsigned char config[MAX_CONFIGBLOCK_SIZE];
|
||||
|
||||
drvc = di->priv;
|
||||
sdi = NULL;
|
||||
|
@ -365,12 +368,11 @@ SR_PRIV struct sr_dev_inst *lascar_scan(int bus, int address)
|
|||
if (!(dev_hdl = lascar_open(devlist[i])))
|
||||
continue;
|
||||
|
||||
if (!(config = lascar_get_config(dev_hdl)))
|
||||
if (lascar_get_config(dev_hdl, config, &dummy) != SR_OK)
|
||||
continue;
|
||||
|
||||
libusb_close(dev_hdl);
|
||||
sdi = lascar_identify(config);
|
||||
g_free(config);
|
||||
}
|
||||
|
||||
return sdi;
|
||||
|
@ -545,3 +547,84 @@ SR_PRIV void lascar_el_usb_receive_transfer(struct libusb_transfer *transfer)
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
static int get_flags(unsigned char *configblock)
|
||||
{
|
||||
int flags;
|
||||
|
||||
flags = (configblock[32] | (configblock[33] << 8)) & 0x1fff;
|
||||
sr_spew("Read flags (0x%.4x).", flags);
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
static int set_flags(unsigned char *configblock, int flags)
|
||||
{
|
||||
|
||||
sr_spew("Setting flags to 0x%.4x.", flags);
|
||||
configblock[32] = flags & 0xff;
|
||||
configblock[33] = (flags >> 8) & 0x1f;
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
SR_PRIV int lascar_is_logging(const struct sr_dev_inst *sdi)
|
||||
{
|
||||
struct dev_context *devc;
|
||||
int dummy, flags, ret;
|
||||
|
||||
devc = sdi->priv;
|
||||
if (lascar_get_config(devc->usb->devhdl, devc->config, &dummy) != SR_OK)
|
||||
return -1;
|
||||
|
||||
flags = get_flags(devc->config);
|
||||
if (flags & 0x0100)
|
||||
ret = 1;
|
||||
else
|
||||
ret = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SR_PRIV int lascar_start_logging(const struct sr_dev_inst *sdi)
|
||||
{
|
||||
struct dev_context *devc;
|
||||
int len, flags, ret;
|
||||
|
||||
devc = sdi->priv;
|
||||
if (lascar_get_config(devc->usb->devhdl, devc->config, &len) != SR_OK)
|
||||
return SR_ERR;
|
||||
|
||||
/* Turn on logging. */
|
||||
flags = get_flags(devc->config);
|
||||
flags |= 0x0100;
|
||||
set_flags(devc->config, flags);
|
||||
|
||||
/* Start logging in 0 seconds. */
|
||||
memset(devc->config + 24, 0, 4);
|
||||
|
||||
ret = lascar_save_config(devc->usb->devhdl, devc->config, len);
|
||||
sr_info("Started internal logging.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SR_PRIV int lascar_stop_logging(const struct sr_dev_inst *sdi)
|
||||
{
|
||||
struct dev_context *devc;
|
||||
int len, flags, ret;
|
||||
|
||||
devc = sdi->priv;
|
||||
if (lascar_get_config(devc->usb->devhdl, devc->config, &len) != SR_OK)
|
||||
return SR_ERR;
|
||||
|
||||
flags = get_flags(devc->config);
|
||||
flags &= ~0x0100;
|
||||
set_flags(devc->config, flags);
|
||||
|
||||
ret = lascar_save_config(devc->usb->devhdl, devc->config, len);
|
||||
sr_info("Stopped internal logging.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#define LASCAR_EP_OUT 2
|
||||
/* Max 100ms for a device to positively identify. */
|
||||
#define SCAN_TIMEOUT 100000
|
||||
#define MAX_CONFIGBLOCK_SIZE 256
|
||||
|
||||
/** Private, per-device-instance driver context. */
|
||||
struct dev_context {
|
||||
|
@ -47,7 +48,7 @@ struct dev_context {
|
|||
const struct elusb_profile *profile;
|
||||
int usbfd[10];
|
||||
/* Generic EL-USB */
|
||||
unsigned char *config;
|
||||
unsigned char config[MAX_CONFIGBLOCK_SIZE];
|
||||
unsigned int log_size;
|
||||
unsigned int rcvd_bytes;
|
||||
unsigned int sample_size;
|
||||
|
@ -75,9 +76,13 @@ struct elusb_profile {
|
|||
int logformat;
|
||||
};
|
||||
|
||||
SR_PRIV unsigned char *lascar_get_config(libusb_device_handle *dev_hdl);
|
||||
SR_PRIV int lascar_get_config(libusb_device_handle *dev_hdl,
|
||||
unsigned char *configblock, int *configlen);
|
||||
SR_PRIV int lascar_el_usb_handle_events(int fd, int revents, void *cb_data);
|
||||
SR_PRIV void lascar_el_usb_receive_transfer(struct libusb_transfer *transfer);
|
||||
SR_PRIV int lascar_start_logging(const struct sr_dev_inst *sdi);
|
||||
SR_PRIV int lascar_stop_logging(const struct sr_dev_inst *sdi);
|
||||
SR_PRIV int lascar_is_logging(const struct sr_dev_inst *sdi);
|
||||
SR_PRIV int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue