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;
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;
}
CMD_CONFIGURE = 0x01,
CMD_IDENTIFY = 0x02,
CMD_SET_DATE_TIME = 0x03,
+ CMD_GET_STATUS = 0x04,
CMD_GET_LIVE_SPL = 0x08,
};
DATA_SOURCE_MEMORY,
};
+enum {
+ DEVICE_ACTIVE,
+ DEVICE_INACTIVE,
+};
+
/** Private, per-device-instance driver context. */
struct dev_context {
/* Acquisition settings */
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