]> sigrok.org Git - libsigrok.git/blame - hardware/kecheng-kc-330b/protocol.c
kecheng-kc-330b: Implement all SR_CONF options
[libsigrok.git] / hardware / kecheng-kc-330b / protocol.c
CommitLineData
ed759a08
BV
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20#include "protocol.h"
21
bc7be4a9 22SR_PRIV int kecheng_kc_330b_handle_events(int fd, int revents, void *cb_data)
ed759a08 23{
bc7be4a9
BV
24 const struct sr_dev_inst *sdi;
25 struct dev_context *devc;
26 struct timeval tv;
27
ed759a08 28 (void)fd;
bc7be4a9 29 (void)revents;
ed759a08 30
bc7be4a9
BV
31 sdi = cb_data;
32 devc = sdi->priv;
33
34
35 return TRUE;
36}
37
38SR_PRIV int kecheng_kc_330b_configure(const struct sr_dev_inst *sdi)
39{
ed759a08 40 struct dev_context *devc;
bc7be4a9
BV
41 struct sr_usb_dev_inst *usb;
42 int len, ret;
43 unsigned char buf[7];
ed759a08 44
bc7be4a9 45 sr_dbg("Configuring device.");
ed759a08 46
bc7be4a9
BV
47 usb = sdi->conn;
48 devc = sdi->priv;
ed759a08 49
bc7be4a9
BV
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));
60 return SR_ERR;
ed759a08
BV
61 }
62
bc7be4a9
BV
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));
67 return SR_ERR;
68 }
69 if (buf[0] != (CMD_CONFIGURE | 0x80)) {
70 sr_dbg("Failed to configure device: invalid response 0x%2.x", buf[0]);
71 return SR_ERR;
72 }
73
74 return SR_OK;
75}
76
77SR_PRIV int kecheng_kc_330b_set_date_time(struct sr_dev_inst *sdi)
78{
79 struct sr_usb_dev_inst *usb;
80 GDateTime *dt;
81 int len, ret;
82 unsigned char buf[7];
83
84 sr_dbg("Setting device date/time.");
85
86 usb = sdi->conn;
87
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));
100 return SR_ERR;
101 }
102
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));
106 return SR_ERR;
107 }
108 if (buf[0] != (CMD_SET_DATE_TIME | 0x80)) {
109 sr_dbg("Failed to set date/time: invalid response 0x%2.x", buf[0]);
110 return SR_ERR;
111 }
112
113
114
115 return SR_OK;
116}
117
118SR_PRIV int kecheng_kc_330b_recording_get(const struct sr_dev_inst *sdi,
119 gboolean *tmp)
120{
121
122 return SR_OK;
ed759a08 123}