]> sigrok.org Git - libsigrok.git/blob - src/hardware/scpi-pps/protocol.h
scpi-pps: Use only standard SCPI for Rigol DP800 series.
[libsigrok.git] / src / hardware / scpi-pps / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2014 Bert Vermeulen <bert@biot.com>
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 #ifndef LIBSIGROK_HARDWARE_SCPI_PPS_PROTOCOL_H
21 #define LIBSIGROK_HARDWARE_SCPI_PPS_PROTOCOL_H
22
23 #include <stdint.h>
24 #include <glib.h>
25 #include "libsigrok.h"
26 #include "libsigrok-internal.h"
27
28 #define LOG_PREFIX "scpi-pps"
29
30 enum pps_scpi_cmds {
31         SCPI_CMD_REMOTE,
32         SCPI_CMD_LOCAL,
33         SCPI_CMD_SELECT_CHANNEL,
34         SCPI_CMD_GET_MEAS_VOLTAGE,
35         SCPI_CMD_GET_MEAS_CURRENT,
36         SCPI_CMD_GET_MEAS_POWER,
37         SCPI_CMD_GET_VOLTAGE_TARGET,
38         SCPI_CMD_SET_VOLTAGE_TARGET,
39         SCPI_CMD_GET_CURRENT_LIMIT,
40         SCPI_CMD_SET_CURRENT_LIMIT,
41         SCPI_CMD_GET_OUTPUT_ENABLED,
42         SCPI_CMD_SET_OUTPUT_ENABLE,
43         SCPI_CMD_SET_OUTPUT_DISABLE,
44         SCPI_CMD_GET_OUTPUT_REGULATION,
45         SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION,
46         SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE,
47         SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE,
48         SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED,
49         SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE,
50         SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE,
51         SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE,
52         SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD,
53         SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD,
54         SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED,
55         SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE,
56         SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE,
57         SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE,
58         SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD,
59         SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD,
60 };
61
62 /*
63  * These are bit values denoting features a device can have either globally,
64  * in scpi_pps.features, or on a per-channel-group basis in
65  * channel_group_spec.features.
66  */
67 enum pps_features {
68         PPS_OTP           = (1 << 0),
69         PPS_OVP           = (1 << 1),
70         PPS_OCP           = (1 << 2),
71         PPS_INDEPENDENT   = (1 << 3),
72         PPS_SERIES        = (1 << 4),
73         PPS_PARALLEL      = (1 << 5),
74 };
75
76 struct scpi_pps {
77         char *vendor;
78         char *model;
79         uint64_t features;
80         const uint32_t *devopts;
81         unsigned int num_devopts;
82         const uint32_t *devopts_cg;
83         unsigned int num_devopts_cg;
84         struct channel_spec *channels;
85         unsigned int num_channels;
86         struct channel_group_spec *channel_groups;
87         unsigned int num_channel_groups;
88         struct scpi_command *commands;
89         unsigned int num_commands;
90 };
91
92 struct channel_spec {
93         char *name;
94         /* Min, max, programming resolution. */
95         float voltage[3];
96         float current[3];
97 };
98
99 struct scpi_command {
100         int command;
101         char *string;
102 };
103
104 struct channel_group_spec {
105         char *name;
106         uint64_t channel_index_mask;
107         uint64_t features;
108 };
109
110 struct pps_channel {
111         int mq;
112         unsigned int hw_output_idx;
113         char *hwname;
114 };
115
116 struct pps_channel_instance {
117         int mq;
118         int command;
119         char *prefix;
120 };
121
122 struct pps_channel_group {
123         uint64_t features;
124 };
125
126 enum acq_states {
127         STATE_VOLTAGE,
128         STATE_CURRENT,
129         STATE_STOP,
130 };
131
132 /** Private, per-device-instance driver context. */
133 struct dev_context {
134         /* Model-specific information */
135         const struct scpi_pps *device;
136
137         /* Acquisition settings */
138         void *cb_data;
139
140         /* Operational state */
141
142         /* Temporary state across callbacks */
143         struct sr_channel *cur_channel;
144 };
145
146 const char *get_vendor(const char *raw_vendor);
147 SR_PRIV char *scpi_cmd_get(const struct sr_dev_inst *sdi, int command);
148 SR_PRIV int scpi_cmd(const struct sr_dev_inst *sdi, int command, ...);
149 SR_PRIV int scpi_cmd_resp(const struct sr_dev_inst *sdi, GVariant **gvar,
150                 const GVariantType *gvtype, int command, ...);
151 SR_PRIV int select_channel(const struct sr_dev_inst *sdi, struct sr_channel *ch);
152 SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data);
153
154 #endif