]> sigrok.org Git - libsigrok.git/blobdiff - hardware/kecheng-kc-330b/protocol.c
kecheng-kc-330b: Implement all SR_CONF options
[libsigrok.git] / hardware / kecheng-kc-330b / protocol.c
index d519e6b3fdece0fe63c85b0b565d86e4b38b0e5b..040652959dcf19489aa19ce68e555f51587086d6 100644 (file)
 
 #include "protocol.h"
 
-SR_PRIV int kecheng_kc_330b_receive_data(int fd, int revents, void *cb_data)
+SR_PRIV int kecheng_kc_330b_handle_events(int fd, int revents, void *cb_data)
 {
+       const struct sr_dev_inst *sdi;
+       struct dev_context *devc;
+       struct timeval tv;
+
        (void)fd;
+       (void)revents;
 
-       const struct sr_dev_inst *sdi;
+       sdi = cb_data;
+       devc = sdi->priv;
+
+
+       return TRUE;
+}
+
+SR_PRIV int kecheng_kc_330b_configure(const struct sr_dev_inst *sdi)
+{
        struct dev_context *devc;
+       struct sr_usb_dev_inst *usb;
+       int len, ret;
+       unsigned char buf[7];
 
-       if (!(sdi = cb_data))
-               return TRUE;
+       sr_dbg("Configuring device.");
 
-       if (!(devc = sdi->priv))
-               return TRUE;
+       usb = sdi->conn;
+       devc = sdi->priv;
 
-       if (revents == G_IO_IN) {
-               /* TODO */
+       buf[0] = CMD_CONFIGURE;
+       buf[1] = devc->sample_interval;
+       buf[2] = devc->alarm_low;
+       buf[3] = devc->alarm_high;
+       buf[4] = devc->mqflags & SR_MQFLAG_SPL_TIME_WEIGHT_F ? 0 : 1;
+       buf[5] = devc->mqflags & SR_MQFLAG_SPL_FREQ_WEIGHT_A ? 0 : 1;
+       buf[6] = devc->data_source;
+       ret = libusb_bulk_transfer(usb->devhdl, EP_OUT, buf, 7, &len, 5);
+       if (ret != 0 || len != 7) {
+               sr_dbg("Failed to configure device: %s", libusb_error_name(ret));
+               return SR_ERR;
        }
 
-       return TRUE;
+       /* The configure command ack takes about 32ms to come in. */
+       ret = libusb_bulk_transfer(usb->devhdl, EP_IN, buf, 1, &len, 40);
+       if (ret != 0 || len != 1) {
+               sr_dbg("Failed to configure device (no ack): %s", libusb_error_name(ret));
+               return SR_ERR;
+       }
+       if (buf[0] != (CMD_CONFIGURE | 0x80)) {
+               sr_dbg("Failed to configure device: invalid response 0x%2.x", buf[0]);
+               return SR_ERR;
+       }
+
+       return SR_OK;
+}
+
+SR_PRIV int kecheng_kc_330b_set_date_time(struct sr_dev_inst *sdi)
+{
+       struct sr_usb_dev_inst *usb;
+       GDateTime *dt;
+       int len, ret;
+       unsigned char buf[7];
+
+       sr_dbg("Setting device date/time.");
+
+       usb = sdi->conn;
+
+       dt = g_date_time_new_now_local();
+       buf[0] = CMD_SET_DATE_TIME;
+       buf[1] = g_date_time_get_year(dt) - 2000;
+       buf[2] = g_date_time_get_month(dt);
+       buf[3] = g_date_time_get_day_of_month(dt);
+       buf[4] = g_date_time_get_hour(dt);
+       buf[5] = g_date_time_get_minute(dt);
+       buf[6] = g_date_time_get_second(dt);
+       g_date_time_unref(dt);
+       ret = libusb_bulk_transfer(usb->devhdl, EP_OUT, buf, 7, &len, 5);
+       if (ret != 0 || len != 7) {
+               sr_dbg("Failed to set date/time: %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 set date/time (no ack): %s", libusb_error_name(ret));
+               return SR_ERR;
+       }
+       if (buf[0] != (CMD_SET_DATE_TIME | 0x80)) {
+               sr_dbg("Failed to set date/time: invalid response 0x%2.x", buf[0]);
+               return SR_ERR;
+       }
+
+
+
+       return SR_OK;
+}
+
+SR_PRIV int kecheng_kc_330b_recording_get(const struct sr_dev_inst *sdi,
+               gboolean *tmp)
+{
+
+       return SR_OK;
 }