]>
Commit | Line | Data |
---|---|---|
12e7abe2 FS |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2021 Frank Stettner <frank-stettner@gmx.net> | |
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 <config.h> | |
584269fd | 21 | #include "scpi.h" |
12e7abe2 FS |
22 | #include "protocol.h" |
23 | ||
584269fd FS |
24 | static const uint32_t scanopts[] = { |
25 | SR_CONF_CONN, | |
26 | }; | |
12e7abe2 | 27 | |
584269fd FS |
28 | static const uint32_t drvopts[] = { |
29 | SR_CONF_MULTIPLEXER, | |
30 | }; | |
12e7abe2 | 31 | |
584269fd | 32 | static const uint32_t devopts[] = { |
0c678b26 | 33 | SR_CONF_CONN | SR_CONF_GET, |
97c3c869 | 34 | SR_CONF_ENABLED | SR_CONF_SET, |
584269fd | 35 | }; |
12e7abe2 | 36 | |
584269fd FS |
37 | static const uint32_t devopts_cg[] = { |
38 | SR_CONF_ENABLED | SR_CONF_SET, | |
39 | }; | |
12e7abe2 | 40 | |
584269fd | 41 | static struct sr_dev_driver hp_59306a_driver_info; |
12e7abe2 | 42 | |
584269fd | 43 | static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) |
12e7abe2 | 44 | { |
584269fd FS |
45 | struct sr_dev_inst *sdi; |
46 | struct dev_context *devc; | |
47 | struct channel_group_context *cgc; | |
48 | size_t idx, nr; | |
49 | struct sr_channel_group *cg; | |
d810901a | 50 | char cg_name[24]; |
584269fd | 51 | |
d008c027 GS |
52 | /* |
53 | * The device cannot get identified by means of SCPI queries. | |
54 | * Neither shall non-SCPI requests get emitted before reliable | |
55 | * identification of the device. Assume that we only get here | |
56 | * when user specs led us to believe it's safe to communicate | |
57 | * to the expected kind of device. | |
58 | */ | |
59 | ||
584269fd FS |
60 | sdi = g_malloc0(sizeof(*sdi)); |
61 | sdi->vendor = g_strdup("Hewlett-Packard"); | |
62 | sdi->model = g_strdup("59306A"); | |
63 | sdi->conn = scpi; | |
64 | sdi->driver = &hp_59306a_driver_info; | |
65 | sdi->inst_type = SR_INST_SCPI; | |
0c678b26 FS |
66 | if (sr_scpi_connection_id(scpi, &sdi->connection_id) != SR_OK) { |
67 | g_free(sdi->connection_id); | |
68 | sdi->connection_id = NULL; | |
69 | } | |
584269fd FS |
70 | |
71 | devc = g_malloc0(sizeof(*devc)); | |
72 | sdi->priv = devc; | |
73 | ||
74 | devc->channel_count = 6; | |
75 | for (idx = 0; idx < devc->channel_count; idx++) { | |
76 | nr = idx + 1; | |
d810901a | 77 | snprintf(cg_name, sizeof(cg_name), "R%zu", nr); |
584269fd FS |
78 | cgc = g_malloc0(sizeof(*cgc)); |
79 | cgc->number = nr; | |
d810901a GS |
80 | cg = sr_channel_group_new(sdi, cg_name, cgc); |
81 | (void)cg; | |
584269fd | 82 | } |
12e7abe2 | 83 | |
584269fd | 84 | return sdi; |
12e7abe2 FS |
85 | } |
86 | ||
584269fd | 87 | static GSList *scan(struct sr_dev_driver *di, GSList *options) |
12e7abe2 | 88 | { |
d008c027 GS |
89 | const char *conn; |
90 | ||
91 | /* Only scan for a device when conn= was specified. */ | |
92 | conn = NULL; | |
93 | (void)sr_serial_extract_options(options, &conn, NULL); | |
94 | if (!conn) | |
95 | return NULL; | |
96 | ||
584269fd | 97 | return sr_scpi_scan(di->context, options, probe_device); |
12e7abe2 FS |
98 | } |
99 | ||
584269fd | 100 | static int dev_open(struct sr_dev_inst *sdi) |
12e7abe2 | 101 | { |
584269fd FS |
102 | return sr_scpi_open(sdi->conn); |
103 | } | |
12e7abe2 | 104 | |
584269fd FS |
105 | static int dev_close(struct sr_dev_inst *sdi) |
106 | { | |
107 | return sr_scpi_close(sdi->conn); | |
12e7abe2 FS |
108 | } |
109 | ||
0c678b26 FS |
110 | static int config_get(uint32_t key, GVariant **data, |
111 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
112 | { | |
113 | (void)cg; | |
114 | ||
115 | if (!sdi || !data) | |
116 | return SR_ERR_ARG; | |
117 | ||
118 | switch (key) { | |
119 | case SR_CONF_CONN: | |
120 | *data = g_variant_new_string(sdi->connection_id); | |
121 | break; | |
122 | default: | |
123 | return SR_ERR_NA; | |
124 | } | |
125 | ||
126 | return SR_OK; | |
127 | } | |
128 | ||
12e7abe2 FS |
129 | static int config_set(uint32_t key, GVariant *data, |
130 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
131 | { | |
584269fd FS |
132 | gboolean on; |
133 | ||
134 | if (!cg) { | |
135 | switch (key) { | |
584269fd | 136 | case SR_CONF_ENABLED: |
97c3c869 FS |
137 | /* Enable/disable all channels at the same time. */ |
138 | on = g_variant_get_boolean(data); | |
139 | return hp_59306a_switch_cg(sdi, cg, on); | |
584269fd FS |
140 | default: |
141 | return SR_ERR_NA; | |
142 | } | |
143 | } else { | |
144 | switch (key) { | |
145 | case SR_CONF_ENABLED: | |
146 | on = g_variant_get_boolean(data); | |
147 | return hp_59306a_switch_cg(sdi, cg, on); | |
148 | default: | |
149 | return SR_ERR_NA; | |
150 | } | |
12e7abe2 FS |
151 | } |
152 | ||
584269fd | 153 | return SR_OK; |
12e7abe2 FS |
154 | } |
155 | ||
156 | static int config_list(uint32_t key, GVariant **data, | |
157 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
158 | { | |
584269fd FS |
159 | if (!cg) { |
160 | switch (key) { | |
161 | case SR_CONF_SCAN_OPTIONS: | |
162 | case SR_CONF_DEVICE_OPTIONS: | |
163 | return STD_CONFIG_LIST(key, data, sdi, cg, | |
164 | scanopts, drvopts, devopts); | |
165 | default: | |
166 | return SR_ERR_NA; | |
167 | } | |
168 | } else { | |
169 | switch (key) { | |
170 | case SR_CONF_DEVICE_OPTIONS: | |
171 | *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg)); | |
172 | break; | |
173 | default: | |
174 | return SR_ERR_NA; | |
175 | } | |
12e7abe2 FS |
176 | } |
177 | ||
12e7abe2 FS |
178 | return SR_OK; |
179 | } | |
180 | ||
181 | static struct sr_dev_driver hp_59306a_driver_info = { | |
182 | .name = "hp-59306a", | |
3029e904 | 183 | .longname = "HP 59306A", |
12e7abe2 FS |
184 | .api_version = 1, |
185 | .init = std_init, | |
186 | .cleanup = std_cleanup, | |
187 | .scan = scan, | |
188 | .dev_list = std_dev_list, | |
189 | .dev_clear = std_dev_clear, | |
0c678b26 | 190 | .config_get = config_get, |
12e7abe2 FS |
191 | .config_set = config_set, |
192 | .config_list = config_list, | |
193 | .dev_open = dev_open, | |
194 | .dev_close = dev_close, | |
584269fd FS |
195 | .dev_acquisition_start = std_dummy_dev_acquisition_start, |
196 | .dev_acquisition_stop = std_dummy_dev_acquisition_stop, | |
12e7abe2 FS |
197 | .context = NULL, |
198 | }; | |
199 | SR_REGISTER_DEV_DRIVER(hp_59306a_driver_info); |