From: Bert Vermeulen Date: Tue, 25 Jun 2013 20:00:29 +0000 (+0200) Subject: kecheng-kc-330b: Check device status before acquisition X-Git-Tag: libsigrok-0.2.1~30 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f336618c3d1dc766da1c9f8ba46b322de9c746fa;p=libsigrok.git 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. --- diff --git a/hardware/kecheng-kc-330b/api.c b/hardware/kecheng-kc-330b/api.c index 1555ac48..66984e9a 100644 --- a/hardware/kecheng-kc-330b/api.c +++ b/hardware/kecheng-kc-330b/api.c @@ -431,6 +431,19 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, devc->cb_data = cb_data; 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))) return SR_ERR; diff --git a/hardware/kecheng-kc-330b/protocol.c b/hardware/kecheng-kc-330b/protocol.c index 5133783e..9eca15c0 100644 --- a/hardware/kecheng-kc-330b/protocol.c +++ b/hardware/kecheng-kc-330b/protocol.c @@ -225,7 +225,41 @@ SR_PRIV int kecheng_kc_330b_set_date_time(struct sr_dev_inst *sdi) 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; } diff --git a/hardware/kecheng-kc-330b/protocol.h b/hardware/kecheng-kc-330b/protocol.h index 1ec64e3e..f872676e 100644 --- a/hardware/kecheng-kc-330b/protocol.h +++ b/hardware/kecheng-kc-330b/protocol.h @@ -55,6 +55,7 @@ enum { CMD_CONFIGURE = 0x01, CMD_IDENTIFY = 0x02, CMD_SET_DATE_TIME = 0x03, + CMD_GET_STATUS = 0x04, CMD_GET_LIVE_SPL = 0x08, }; @@ -63,6 +64,11 @@ enum { DATA_SOURCE_MEMORY, }; +enum { + DEVICE_ACTIVE, + DEVICE_INACTIVE, +}; + /** Private, per-device-instance driver context. */ struct dev_context { /* 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_recording_get(const struct sr_dev_inst *sdi, gboolean *tmp); +SR_PRIV int kecheng_kc_330b_status_get(const struct sr_dev_inst *sdi, + int *status); #endif