]> sigrok.org Git - libsigrok.git/blob - src/hardware/rohde-schwarz-sme-0x/protocol.c
0235ce8a352cb4632e23d9e117f8605186355217
[libsigrok.git] / src / hardware / rohde-schwarz-sme-0x / protocol.c
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>
21 #include <glib.h>
22 #include <scpi.h>
23
24 #include "protocol.h"
25
26 enum {
27         RS_CMD_CONTROL_REMOTE,
28         RS_CMD_SET_FREQ,
29         RS_CMD_SET_POWER,
30         RS_CMD_GET_FREQ,
31         RS_CMD_GET_POWER
32 };
33
34 static char *commands[] = {
35         [RS_CMD_CONTROL_REMOTE] = "\n",
36         [RS_CMD_SET_FREQ] = "FREQ %.1fHz",
37         [RS_CMD_SET_POWER] = "POW %.1fdBm",
38         [RS_CMD_GET_FREQ] = "FREQ?",
39         [RS_CMD_GET_POWER] = "POW?"
40 };
41
42 SR_PRIV int rs_sme0x_mode_remote(struct sr_scpi_dev_inst *scpi) {
43         return sr_scpi_send(scpi, commands[RS_CMD_CONTROL_REMOTE]);
44 }
45
46 SR_PRIV int rs_sme0x_get_freq(const struct sr_dev_inst *sdi, double *freq) {
47         if (sr_scpi_get_double(sdi->conn, commands[RS_CMD_GET_FREQ], freq) != SR_OK) {
48                 return SR_ERR;
49         }
50
51         return SR_OK;
52 }
53
54 SR_PRIV int rs_sme0x_get_power(const struct sr_dev_inst *sdi, double *power) {
55         if (sr_scpi_get_double(sdi->conn, commands[RS_CMD_GET_POWER], power) != SR_OK) {
56                 return SR_ERR;
57         }
58
59         return SR_OK;
60 }
61
62 SR_PRIV int rs_sme0x_set_freq(const struct sr_dev_inst *sdi, double freq) {
63         struct dev_context *devc;
64         const struct rs_device_model *config;
65
66         devc = sdi->priv;
67         config = devc->model_config;
68
69         if ((freq > config->freq_max) || (freq < config->freq_min)) {
70                 return SR_ERR_ARG;
71         }
72
73         return sr_scpi_send(sdi->conn, commands[RS_CMD_SET_FREQ], freq);
74 }
75
76 SR_PRIV int rs_sme0x_set_power(const struct sr_dev_inst *sdi, double power) {
77         struct dev_context *devc;
78         const struct rs_device_model *config;
79
80         devc = sdi->priv;
81         config = devc->model_config;
82
83         if ((power > config->power_max) || (power < config->power_min)) {
84                 return SR_ERR_ARG;
85         }
86
87         return sr_scpi_send(sdi->conn, commands[RS_CMD_SET_POWER], power);
88 }