]> sigrok.org Git - libsigrok.git/blame - src/hardware/rohde-schwarz-sme-0x/api.c
rohde-schwarz-sme-0x: remove obsolete libserialport reference
[libsigrok.git] / src / hardware / rohde-schwarz-sme-0x / api.c
CommitLineData
a28b3df1
VI
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2016 Vlad Ivanov <vlad.ivanov@lab-systems.ru>
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>
a28b3df1
VI
21#include <scpi.h>
22#include <string.h>
23
24#include "protocol.h"
25
3f34a402 26static struct sr_dev_driver rohde_schwarz_sme_0x_driver_info;
a28b3df1 27
9e506594
SA
28static const char *manufacturer = "Rohde&Schwarz";
29
30static const struct rs_device_model device_models[] = {
31 {
32 .model_str = "SME02",
33 .freq_max = SR_GHZ(1.5),
34 .freq_min = SR_KHZ(5),
35 .power_max = 16,
ed1fae0b 36 .power_min = -144,
9e506594
SA
37 },
38 {
39 .model_str = "SME03E",
40 .freq_max = SR_GHZ(2.2),
41 .freq_min = SR_KHZ(5),
42 .power_max = 16,
ed1fae0b 43 .power_min = -144,
9e506594
SA
44 },
45 {
46 .model_str = "SME03A",
47 .freq_max = SR_GHZ(3),
48 .freq_min = SR_KHZ(5),
49 .power_max = 16,
ed1fae0b 50 .power_min = -144,
9e506594
SA
51 },
52 {
53 .model_str = "SME03",
54 .freq_max = SR_GHZ(3),
55 .freq_min = SR_KHZ(5),
56 .power_max = 16,
ed1fae0b 57 .power_min = -144,
9e506594
SA
58 },
59 {
60 .model_str = "SME06",
61 .freq_max = SR_GHZ(1.5),
62 .freq_min = SR_KHZ(5),
63 .power_max = 16,
ed1fae0b 64 .power_min = -144,
9e506594
SA
65 }
66};
a28b3df1
VI
67
68static const uint32_t scanopts[] = {
69 SR_CONF_CONN,
70 SR_CONF_SERIALCOMM,
71};
72
0d9841dd
UH
73static const uint32_t drvopts[] = {
74 SR_CONF_SIGNAL_GENERATOR,
75};
76
a28b3df1
VI
77static const uint32_t devopts[] = {
78 SR_CONF_OUTPUT_FREQUENCY | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
79 SR_CONF_AMPLITUDE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
80};
81
a28b3df1
VI
82static int rs_init_device(struct sr_dev_inst *sdi)
83{
84 struct dev_context *devc;
85 uint8_t model_found;
86
87 devc = sdi->priv;
88 model_found = 0;
89
90 for (size_t i = 0; i < ARRAY_SIZE(device_models); i++) {
91 if (!strcmp(device_models[i].model_str, sdi->model)) {
92 model_found = 1;
93 devc->model_config = &device_models[i];
94 break;
95 }
96 }
97
98 if (!model_found) {
ed1fae0b
UH
99 sr_dbg("Device %s %s is not supported by this driver.",
100 manufacturer, sdi->model);
a28b3df1
VI
101 return SR_ERR_NA;
102 }
103
104 return SR_OK;
105}
106
373e92a4 107static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
a28b3df1
VI
108{
109 struct sr_dev_inst *sdi;
110 struct dev_context *devc;
111 struct sr_scpi_hw_info *hw_info;
112
113 sdi = NULL;
114 devc = NULL;
115 hw_info = NULL;
116
117 rs_sme0x_mode_remote(scpi);
118
ed1fae0b 119 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK)
a28b3df1 120 goto fail;
a28b3df1 121
ed1fae0b 122 if (strcmp(hw_info->manufacturer, manufacturer) != 0)
a28b3df1 123 goto fail;
a28b3df1
VI
124
125 sdi = g_malloc0(sizeof(struct sr_dev_inst));
126 sdi->vendor = g_strdup(hw_info->manufacturer);
127 sdi->model = g_strdup(hw_info->model);
128 sdi->version = g_strdup(hw_info->firmware_version);
129 sdi->serial_num = g_strdup(hw_info->serial_number);
130 sdi->driver = &rohde_schwarz_sme_0x_driver_info;
131 sdi->inst_type = SR_INST_SCPI;
132 sdi->conn = scpi;
133
134 sr_scpi_hw_info_free(hw_info);
135 hw_info = NULL;
136
137 devc = g_malloc0(sizeof(struct dev_context));
138 sdi->priv = devc;
139
ed1fae0b 140 if (rs_init_device(sdi) != SR_OK)
a28b3df1 141 goto fail;
a28b3df1
VI
142
143 return sdi;
144
145fail:
7b365c47 146 sr_scpi_hw_info_free(hw_info);
4bf93988 147 sr_dev_inst_free(sdi);
a28b3df1
VI
148 g_free(devc);
149 return NULL;
150}
151
152static GSList *scan(struct sr_dev_driver *di, GSList *options)
153{
373e92a4 154 return sr_scpi_scan(di->context, options, probe_device);
a28b3df1
VI
155}
156
a28b3df1
VI
157static int dev_open(struct sr_dev_inst *sdi)
158{
7e463623 159 return sr_scpi_open(sdi->conn);
a28b3df1
VI
160}
161
162static int dev_close(struct sr_dev_inst *sdi)
163{
f1ba6b4b 164 return sr_scpi_close(sdi->conn);
a28b3df1
VI
165}
166
167static int config_get(uint32_t key, GVariant **data,
168 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
169{
170 double value_f;
171
172 (void) cg;
173
174 switch (key) {
175 case SR_CONF_OUTPUT_FREQUENCY:
176 rs_sme0x_get_freq(sdi, &value_f);
177 *data = g_variant_new_double(value_f);
178 break;
179 case SR_CONF_AMPLITUDE:
180 rs_sme0x_get_power(sdi, &value_f);
181 *data = g_variant_new_double(value_f);
182 break;
183 default:
184 return SR_ERR_NA;
185 }
186
187 return SR_OK;
188}
189
190static int config_set(uint32_t key, GVariant *data,
191 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
192{
193 double value_f;
194
195 (void)cg;
196
ed1fae0b 197 if (!sdi)
a28b3df1 198 return SR_ERR_ARG;
a28b3df1 199
a28b3df1
VI
200 switch (key) {
201 case SR_CONF_OUTPUT_FREQUENCY:
202 value_f = g_variant_get_double(data);
203 rs_sme0x_set_freq(sdi, value_f);
204 break;
205 case SR_CONF_AMPLITUDE:
206 value_f = g_variant_get_double(data);
207 rs_sme0x_set_power(sdi, value_f);
208 break;
209 default:
210 return SR_ERR_NA;
211 }
212
213 return SR_OK;
214}
215
216static int config_list(uint32_t key, GVariant **data,
217 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
218{
e66d1892 219 return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
a28b3df1
VI
220}
221
3f34a402 222static struct sr_dev_driver rohde_schwarz_sme_0x_driver_info = {
a28b3df1
VI
223 .name = "rohde-schwarz-sme-0x",
224 .longname = "Rohde&Schwarz SME-0x",
225 .api_version = 1,
226 .init = std_init,
227 .cleanup = std_cleanup,
228 .scan = scan,
229 .dev_list = std_dev_list,
f778bf02 230 .dev_clear = std_dev_clear,
a28b3df1
VI
231 .config_get = config_get,
232 .config_set = config_set,
233 .config_list = config_list,
234 .dev_open = dev_open,
235 .dev_close = dev_close,
4d67b9d9 236 .dev_acquisition_start = std_dummy_dev_acquisition_start,
a28b3df1
VI
237 .dev_acquisition_stop = std_serial_dev_acquisition_stop,
238 .context = NULL,
239};
a28b3df1 240SR_REGISTER_DEV_DRIVER(rohde_schwarz_sme_0x_driver_info);