kecheng-kc-330b: Check device status before acquisition

Can't really count on it either way though, the device is just
too flaky to conclude whether it's going to work or not, regardless
of the status returned.
This commit is contained in:
Bert Vermeulen 2013-06-25 22:00:29 +02:00
parent df03552894
commit f336618c3d
3 changed files with 55 additions and 0 deletions

View File

@ -431,6 +431,19 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
devc->cb_data = cb_data; devc->cb_data = cb_data;
devc->num_samples = 0; devc->num_samples = 0;
if (devc->data_source == DATA_SOURCE_LIVE) {
if (kecheng_kc_330b_status_get(sdi, &ret) != SR_OK)
return SR_ERR;
sr_dbg("st %s", ret == DEVICE_ACTIVE ? "act" : "deact");
if (ret != DEVICE_ACTIVE) {
sr_err("Device is inactive");
/* Still continue though, since the device will
* just return 30.0 until the user hits the button
* on the device -- and then start feeding good
* samples back. */
}
}
if (!(devc->xfer = libusb_alloc_transfer(0))) if (!(devc->xfer = libusb_alloc_transfer(0)))
return SR_ERR; return SR_ERR;

View File

@ -225,7 +225,41 @@ SR_PRIV int kecheng_kc_330b_set_date_time(struct sr_dev_inst *sdi)
return SR_ERR; return SR_ERR;
} }
return SR_OK;
}
SR_PRIV int kecheng_kc_330b_status_get(const struct sr_dev_inst *sdi,
int *status)
{
struct sr_usb_dev_inst *usb;
int len, ret;
unsigned char buf;
sr_dbg("Getting device status.");
usb = sdi->conn;
buf = CMD_GET_STATUS;
ret = libusb_bulk_transfer(usb->devhdl, EP_OUT, &buf, 1, &len, 5);
if (ret != 0 || len != 1) {
sr_dbg("Failed to get status: %s", libusb_error_name(ret));
return SR_ERR;
}
ret = libusb_bulk_transfer(usb->devhdl, EP_IN, &buf, 1, &len, 10);
if (ret != 0 || len != 1) {
sr_dbg("Failed to get status (no ack): %s", libusb_error_name(ret));
return SR_ERR;
}
/* Need either 0x84 or 0xa4. */
if (buf != (CMD_GET_STATUS | 0x80) && buf != (CMD_GET_STATUS | 0xa0)) {
sr_dbg("Failed to get status: invalid response 0x%2.x", buf);
return SR_ERR;
}
if (buf & 0x20)
*status = DEVICE_INACTIVE;
else
*status = DEVICE_ACTIVE;
return SR_OK; return SR_OK;
} }

View File

@ -55,6 +55,7 @@ enum {
CMD_CONFIGURE = 0x01, CMD_CONFIGURE = 0x01,
CMD_IDENTIFY = 0x02, CMD_IDENTIFY = 0x02,
CMD_SET_DATE_TIME = 0x03, CMD_SET_DATE_TIME = 0x03,
CMD_GET_STATUS = 0x04,
CMD_GET_LIVE_SPL = 0x08, CMD_GET_LIVE_SPL = 0x08,
}; };
@ -63,6 +64,11 @@ enum {
DATA_SOURCE_MEMORY, DATA_SOURCE_MEMORY,
}; };
enum {
DEVICE_ACTIVE,
DEVICE_INACTIVE,
};
/** Private, per-device-instance driver context. */ /** Private, per-device-instance driver context. */
struct dev_context { struct dev_context {
/* Acquisition settings */ /* Acquisition settings */
@ -92,5 +98,7 @@ SR_PRIV int kecheng_kc_330b_configure(const struct sr_dev_inst *sdi);
SR_PRIV int kecheng_kc_330b_set_date_time(struct sr_dev_inst *sdi); SR_PRIV int kecheng_kc_330b_set_date_time(struct sr_dev_inst *sdi);
SR_PRIV int kecheng_kc_330b_recording_get(const struct sr_dev_inst *sdi, SR_PRIV int kecheng_kc_330b_recording_get(const struct sr_dev_inst *sdi,
gboolean *tmp); gboolean *tmp);
SR_PRIV int kecheng_kc_330b_status_get(const struct sr_dev_inst *sdi,
int *status);
#endif #endif