]>
Commit | Line | Data |
---|---|---|
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> | |
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, | |
ed1fae0b | 31 | RS_CMD_GET_POWER, |
a28b3df1 VI |
32 | }; |
33 | ||
9e506594 | 34 | static char *commands[] = { |
a28b3df1 VI |
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?", | |
ed1fae0b | 39 | [RS_CMD_GET_POWER] = "POW?", |
a28b3df1 VI |
40 | }; |
41 | ||
ed1fae0b UH |
42 | SR_PRIV int rs_sme0x_mode_remote(struct sr_scpi_dev_inst *scpi) |
43 | { | |
a28b3df1 VI |
44 | return sr_scpi_send(scpi, commands[RS_CMD_CONTROL_REMOTE]); |
45 | } | |
46 | ||
ed1fae0b UH |
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) | |
a28b3df1 | 50 | return SR_ERR; |
a28b3df1 VI |
51 | |
52 | return SR_OK; | |
53 | } | |
54 | ||
ed1fae0b UH |
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) | |
a28b3df1 | 58 | return SR_ERR; |
a28b3df1 VI |
59 | |
60 | return SR_OK; | |
61 | } | |
62 | ||
ed1fae0b UH |
63 | SR_PRIV int rs_sme0x_set_freq(const struct sr_dev_inst *sdi, double freq) |
64 | { | |
a28b3df1 VI |
65 | struct dev_context *devc; |
66 | const struct rs_device_model *config; | |
67 | ||
68 | devc = sdi->priv; | |
69 | config = devc->model_config; | |
70 | ||
ed1fae0b | 71 | if ((freq > config->freq_max) || (freq < config->freq_min)) |
a28b3df1 | 72 | return SR_ERR_ARG; |
a28b3df1 VI |
73 | |
74 | return sr_scpi_send(sdi->conn, commands[RS_CMD_SET_FREQ], freq); | |
75 | } | |
76 | ||
ed1fae0b UH |
77 | SR_PRIV int rs_sme0x_set_power(const struct sr_dev_inst *sdi, double power) |
78 | { | |
a28b3df1 VI |
79 | struct dev_context *devc; |
80 | const struct rs_device_model *config; | |
81 | ||
82 | devc = sdi->priv; | |
83 | config = devc->model_config; | |
84 | ||
ed1fae0b | 85 | if ((power > config->power_max) || (power < config->power_min)) |
a28b3df1 | 86 | return SR_ERR_ARG; |
a28b3df1 VI |
87 | |
88 | return sr_scpi_send(sdi->conn, commands[RS_CMD_SET_POWER], power); | |
89 | } |