]> sigrok.org Git - libsigrok.git/blame - src/hardware/scpi-pps/protocol.h
Add private storage pointer to struct sr_channel.
[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,
40 SCPI_CMD_SET_OUTPUT_ENABLED,
41 SCPI_CMD_GET_OUTPUT_REGULATION,
42 SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION,
43 SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION,
44 SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED,
45 SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLED,
46 SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE,
47 SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD,
48 SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD,
49 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED,
50 SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLED,
51 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE,
52 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD,
53 SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD,
9e45cd41
BV
54};
55
56/*
57 * These are bit values denoting features a device can have either globally,
58 * in scpi_pps.features, or on a per-channel-group basis in
59 * channel_group_spec.features.
60 */
61enum pps_features {
62 PPS_OTP = (1 << 0),
63 PPS_OVP = (1 << 1),
64 PPS_OCP = (1 << 2),
65 PPS_INDEPENDENT = (1 << 3),
66 PPS_SERIES = (1 << 4),
67 PPS_PARALLEL = (1 << 5),
68};
69
70struct scpi_pps {
58b77c41
BV
71 char *vendor;
72 char *model;
9e45cd41
BV
73 uint64_t features;
74 const int32_t *devopts;
75 unsigned int num_devopts;
76 const int32_t *devopts_cg;
77 unsigned int num_devopts_cg;
78 struct channel_spec *channels;
79 unsigned int num_channels;
80 struct channel_group_spec *channel_groups;
81 unsigned int num_channel_groups;
82 struct scpi_command *commands;
83 unsigned int num_commands;
84};
85
86struct channel_spec {
87 char *name;
88 /* Min, max, programming resolution. */
89 float voltage[3];
90 float current[3];
91};
92
93struct scpi_command {
94 int command;
95 char *string;
96};
97
98struct channel_group_spec {
99 char *name;
100 uint64_t channel_index_mask;
101 uint64_t features;
102};
103
104struct pps_channel_group {
105 uint64_t features;
106};
107
108enum acq_states {
109 STATE_VOLTAGE,
110 STATE_CURRENT,
111 STATE_STOP,
112};
113
ca1a7cb5
BV
114/** Private, per-device-instance driver context. */
115struct dev_context {
116 /* Model-specific information */
9e45cd41 117 const struct scpi_pps *device;
ca1a7cb5
BV
118
119 /* Acquisition settings */
9e45cd41 120 void *cb_data;
ca1a7cb5
BV
121
122 /* Operational state */
123
124 /* Temporary state across callbacks */
9e45cd41
BV
125 int state;
126 struct sr_channel *cur_channel;
ca1a7cb5
BV
127};
128
22c18b03 129const char *get_vendor(const char *raw_vendor);
478c8d92 130SR_PRIV char *scpi_cmd_get(const struct sr_dev_inst *sdi, int command);
9e45cd41 131SR_PRIV int scpi_cmd(const struct sr_dev_inst *sdi, int command, ...);
478c8d92
BV
132SR_PRIV int scpi_cmd_resp(const struct sr_dev_inst *sdi, GVariant **gvar,
133 const GVariantType *gvtype, int command, ...);
ca1a7cb5
BV
134SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data);
135
136#endif