]> sigrok.org Git - libsigrok.git/blame - src/hardware/scpi-pps/protocol.h
scpi-pps: Split boolean set options into enable/disable.
[libsigrok.git] / src / hardware / scpi-pps / protocol.h
CommitLineData
ca1a7cb5
BV
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
9e45cd41
BV
30enum pps_scpi_cmds {
31 SCPI_CMD_KEY_UNLOCK,
32 SCPI_CMD_GET_MEAS_VOLTAGE,
33 SCPI_CMD_GET_MEAS_CURRENT,
34 SCPI_CMD_GET_MEAS_POWER,
35 SCPI_CMD_GET_VOLTAGE_MAX,
36 SCPI_CMD_SET_VOLTAGE_MAX,
37 SCPI_CMD_GET_CURRENT_MAX,
38 SCPI_CMD_SET_CURRENT_MAX,
39 SCPI_CMD_GET_OUTPUT_ENABLED,
53a81803
BV
40 SCPI_CMD_SET_OUTPUT_ENABLE,
41 SCPI_CMD_SET_OUTPUT_DISABLE,
9e45cd41
BV
42 SCPI_CMD_GET_OUTPUT_REGULATION,
43 SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION,
53a81803
BV
44 SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE,
45 SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE,
9e45cd41 46 SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED,
53a81803
BV
47 SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE,
48 SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE,
9e45cd41
BV
49 SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE,
50 SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD,
51 SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD,
52 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED,
53a81803
BV
53 SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE,
54 SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE,
9e45cd41
BV
55 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE,
56 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD,
57 SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD,
9e45cd41
BV
58};
59
60/*
61 * These are bit values denoting features a device can have either globally,
62 * in scpi_pps.features, or on a per-channel-group basis in
63 * channel_group_spec.features.
64 */
65enum pps_features {
66 PPS_OTP = (1 << 0),
67 PPS_OVP = (1 << 1),
68 PPS_OCP = (1 << 2),
69 PPS_INDEPENDENT = (1 << 3),
70 PPS_SERIES = (1 << 4),
71 PPS_PARALLEL = (1 << 5),
72};
73
74struct scpi_pps {
58b77c41
BV
75 char *vendor;
76 char *model;
9e45cd41 77 uint64_t features;
584560f1 78 const uint32_t *devopts;
9e45cd41 79 unsigned int num_devopts;
584560f1 80 const uint32_t *devopts_cg;
9e45cd41
BV
81 unsigned int num_devopts_cg;
82 struct channel_spec *channels;
83 unsigned int num_channels;
84 struct channel_group_spec *channel_groups;
85 unsigned int num_channel_groups;
86 struct scpi_command *commands;
87 unsigned int num_commands;
88};
89
90struct channel_spec {
91 char *name;
92 /* Min, max, programming resolution. */
93 float voltage[3];
94 float current[3];
95};
96
97struct scpi_command {
98 int command;
99 char *string;
100};
101
102struct channel_group_spec {
103 char *name;
104 uint64_t channel_index_mask;
105 uint64_t features;
106};
107
01b0257a
BV
108struct pps_channel {
109 int mq;
110 unsigned int hw_output_idx;
111 char *hwname;
112};
113
114struct pps_channel_instance {
115 int mq;
116 int command;
117 char *prefix;
118};
119
9e45cd41
BV
120struct pps_channel_group {
121 uint64_t features;
122};
123
124enum acq_states {
125 STATE_VOLTAGE,
126 STATE_CURRENT,
127 STATE_STOP,
128};
129
ca1a7cb5
BV
130/** Private, per-device-instance driver context. */
131struct dev_context {
132 /* Model-specific information */
9e45cd41 133 const struct scpi_pps *device;
ca1a7cb5
BV
134
135 /* Acquisition settings */
9e45cd41 136 void *cb_data;
ca1a7cb5
BV
137
138 /* Operational state */
139
140 /* Temporary state across callbacks */
9e45cd41 141 struct sr_channel *cur_channel;
ca1a7cb5
BV
142};
143
22c18b03 144const char *get_vendor(const char *raw_vendor);
478c8d92 145SR_PRIV char *scpi_cmd_get(const struct sr_dev_inst *sdi, int command);
9e45cd41 146SR_PRIV int scpi_cmd(const struct sr_dev_inst *sdi, int command, ...);
478c8d92
BV
147SR_PRIV int scpi_cmd_resp(const struct sr_dev_inst *sdi, GVariant **gvar,
148 const GVariantType *gvtype, int command, ...);
ca1a7cb5
BV
149SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data);
150
151#endif