2 * This file is part of the libsigrok project.
4 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 SR_PRIV int kecheng_kc_330b_handle_events(int fd, int revents, void *cb_data)
24 const struct sr_dev_inst *sdi;
25 struct dev_context *devc;
38 SR_PRIV int kecheng_kc_330b_configure(const struct sr_dev_inst *sdi)
40 struct dev_context *devc;
41 struct sr_usb_dev_inst *usb;
45 sr_dbg("Configuring device.");
50 buf[0] = CMD_CONFIGURE;
51 buf[1] = devc->sample_interval;
52 buf[2] = devc->alarm_low;
53 buf[3] = devc->alarm_high;
54 buf[4] = devc->mqflags & SR_MQFLAG_SPL_TIME_WEIGHT_F ? 0 : 1;
55 buf[5] = devc->mqflags & SR_MQFLAG_SPL_FREQ_WEIGHT_A ? 0 : 1;
56 buf[6] = devc->data_source;
57 ret = libusb_bulk_transfer(usb->devhdl, EP_OUT, buf, 7, &len, 5);
58 if (ret != 0 || len != 7) {
59 sr_dbg("Failed to configure device: %s", libusb_error_name(ret));
63 /* The configure command ack takes about 32ms to come in. */
64 ret = libusb_bulk_transfer(usb->devhdl, EP_IN, buf, 1, &len, 40);
65 if (ret != 0 || len != 1) {
66 sr_dbg("Failed to configure device (no ack): %s", libusb_error_name(ret));
69 if (buf[0] != (CMD_CONFIGURE | 0x80)) {
70 sr_dbg("Failed to configure device: invalid response 0x%2.x", buf[0]);
77 SR_PRIV int kecheng_kc_330b_set_date_time(struct sr_dev_inst *sdi)
79 struct sr_usb_dev_inst *usb;
84 sr_dbg("Setting device date/time.");
88 dt = g_date_time_new_now_local();
89 buf[0] = CMD_SET_DATE_TIME;
90 buf[1] = g_date_time_get_year(dt) - 2000;
91 buf[2] = g_date_time_get_month(dt);
92 buf[3] = g_date_time_get_day_of_month(dt);
93 buf[4] = g_date_time_get_hour(dt);
94 buf[5] = g_date_time_get_minute(dt);
95 buf[6] = g_date_time_get_second(dt);
96 g_date_time_unref(dt);
97 ret = libusb_bulk_transfer(usb->devhdl, EP_OUT, buf, 7, &len, 5);
98 if (ret != 0 || len != 7) {
99 sr_dbg("Failed to set date/time: %s", libusb_error_name(ret));
103 ret = libusb_bulk_transfer(usb->devhdl, EP_IN, buf, 1, &len, 10);
104 if (ret != 0 || len != 1) {
105 sr_dbg("Failed to set date/time (no ack): %s", libusb_error_name(ret));
108 if (buf[0] != (CMD_SET_DATE_TIME | 0x80)) {
109 sr_dbg("Failed to set date/time: invalid response 0x%2.x", buf[0]);
118 SR_PRIV int kecheng_kc_330b_recording_get(const struct sr_dev_inst *sdi,