]>
Commit | Line | Data |
---|---|---|
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 | { | |
44 | return sr_scpi_send(scpi, commands[RS_CMD_CONTROL_REMOTE]); | |
45 | } | |
46 | ||
47 | SR_PRIV int rs_sme0x_get_freq(const struct sr_dev_inst *sdi, double *freq) | |
48 | { | |
49 | if (sr_scpi_get_double(sdi->conn, commands[RS_CMD_GET_FREQ], freq) != SR_OK) | |
50 | return SR_ERR; | |
51 | ||
52 | return SR_OK; | |
53 | } | |
54 | ||
55 | SR_PRIV int rs_sme0x_get_power(const struct sr_dev_inst *sdi, double *power) | |
56 | { | |
57 | if (sr_scpi_get_double(sdi->conn, commands[RS_CMD_GET_POWER], power) != SR_OK) | |
58 | return SR_ERR; | |
59 | ||
60 | return SR_OK; | |
61 | } | |
62 | ||
63 | SR_PRIV int rs_sme0x_set_freq(const struct sr_dev_inst *sdi, double freq) | |
64 | { | |
65 | struct dev_context *devc; | |
66 | const struct rs_device_model *config; | |
67 | ||
68 | devc = sdi->priv; | |
69 | config = devc->model_config; | |
70 | ||
71 | if ((freq > config->freq_max) || (freq < config->freq_min)) | |
72 | return SR_ERR_ARG; | |
73 | ||
74 | return sr_scpi_send(sdi->conn, commands[RS_CMD_SET_FREQ], freq); | |
75 | } | |
76 | ||
77 | SR_PRIV int rs_sme0x_set_power(const struct sr_dev_inst *sdi, double power) | |
78 | { | |
79 | struct dev_context *devc; | |
80 | const struct rs_device_model *config; | |
81 | ||
82 | devc = sdi->priv; | |
83 | config = devc->model_config; | |
84 | ||
85 | if ((power > config->power_max) || (power < config->power_min)) | |
86 | return SR_ERR_ARG; | |
87 | ||
88 | return sr_scpi_send(sdi->conn, commands[RS_CMD_SET_POWER], power); | |
89 | } |