2 * This file is part of the libsigrok project.
4 * Copyright (C) 2016 Vlad Ivanov <vlad.ivanov@lab-systems.ru>
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/>.
21 #include <libserialport.h>
27 SR_PRIV struct sr_dev_driver rohde_schwarz_sme_0x_driver_info;
29 static const char *manufacturer = "Rohde&Schwarz";
31 static const struct rs_device_model device_models[] = {
34 .freq_max = SR_GHZ(1.5),
35 .freq_min = SR_KHZ(5),
40 .model_str = "SME03E",
41 .freq_max = SR_GHZ(2.2),
42 .freq_min = SR_KHZ(5),
47 .model_str = "SME03A",
48 .freq_max = SR_GHZ(3),
49 .freq_min = SR_KHZ(5),
55 .freq_max = SR_GHZ(3),
56 .freq_min = SR_KHZ(5),
62 .freq_max = SR_GHZ(1.5),
63 .freq_min = SR_KHZ(5),
69 static const uint32_t scanopts[] = {
74 static const uint32_t drvopts[] = {
75 SR_CONF_SIGNAL_GENERATOR,
78 static const uint32_t devopts[] = {
79 SR_CONF_OUTPUT_FREQUENCY | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
80 SR_CONF_AMPLITUDE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
83 static int rs_init_device(struct sr_dev_inst *sdi)
85 struct dev_context *devc;
91 for (size_t i = 0; i < ARRAY_SIZE(device_models); i++) {
92 if (!strcmp(device_models[i].model_str, sdi->model)) {
94 devc->model_config = &device_models[i];
100 sr_dbg("Device %s %s is not supported by this driver.",
101 manufacturer, sdi->model);
108 static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
110 struct sr_dev_inst *sdi;
111 struct dev_context *devc;
112 struct sr_scpi_hw_info *hw_info;
118 rs_sme0x_mode_remote(scpi);
120 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK)
123 if (strcmp(hw_info->manufacturer, manufacturer) != 0)
126 sdi = g_malloc0(sizeof(struct sr_dev_inst));
127 sdi->vendor = g_strdup(hw_info->manufacturer);
128 sdi->model = g_strdup(hw_info->model);
129 sdi->version = g_strdup(hw_info->firmware_version);
130 sdi->serial_num = g_strdup(hw_info->serial_number);
131 sdi->driver = &rohde_schwarz_sme_0x_driver_info;
132 sdi->inst_type = SR_INST_SCPI;
135 sr_scpi_hw_info_free(hw_info);
138 devc = g_malloc0(sizeof(struct dev_context));
141 if (rs_init_device(sdi) != SR_OK)
147 sr_scpi_hw_info_free(hw_info);
148 sr_dev_inst_free(sdi);
153 static GSList *scan(struct sr_dev_driver *di, GSList *options)
155 return sr_scpi_scan(di->context, options, probe_device);
158 static int dev_open(struct sr_dev_inst *sdi)
160 return sr_scpi_open(sdi->conn);
163 static int dev_close(struct sr_dev_inst *sdi)
165 return sr_scpi_close(sdi->conn);
168 static int config_get(uint32_t key, GVariant **data,
169 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
176 case SR_CONF_OUTPUT_FREQUENCY:
177 rs_sme0x_get_freq(sdi, &value_f);
178 *data = g_variant_new_double(value_f);
180 case SR_CONF_AMPLITUDE:
181 rs_sme0x_get_power(sdi, &value_f);
182 *data = g_variant_new_double(value_f);
191 static int config_set(uint32_t key, GVariant *data,
192 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
202 case SR_CONF_OUTPUT_FREQUENCY:
203 value_f = g_variant_get_double(data);
204 rs_sme0x_set_freq(sdi, value_f);
206 case SR_CONF_AMPLITUDE:
207 value_f = g_variant_get_double(data);
208 rs_sme0x_set_power(sdi, value_f);
217 static int config_list(uint32_t key, GVariant **data,
218 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
220 return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
223 SR_PRIV struct sr_dev_driver rohde_schwarz_sme_0x_driver_info = {
224 .name = "rohde-schwarz-sme-0x",
225 .longname = "Rohde&Schwarz SME-0x",
228 .cleanup = std_cleanup,
230 .dev_list = std_dev_list,
231 .dev_clear = std_dev_clear,
232 .config_get = config_get,
233 .config_set = config_set,
234 .config_list = config_list,
235 .dev_open = dev_open,
236 .dev_close = dev_close,
237 .dev_acquisition_start = std_dummy_dev_acquisition_start,
238 .dev_acquisition_stop = std_serial_dev_acquisition_stop,
242 SR_REGISTER_DEV_DRIVER(rohde_schwarz_sme_0x_driver_info);