]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2015 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 | /** @file | |
21 | * @internal | |
22 | */ | |
23 | ||
24 | #ifndef LIBSIGROK_SCPI_H | |
25 | #define LIBSIGROK_SCPI_H | |
26 | ||
27 | #include <stdint.h> | |
28 | #include <glib.h> | |
29 | #include <libsigrok/libsigrok.h> | |
30 | #include "libsigrok-internal.h" | |
31 | ||
32 | #define SCPI_CMD_IDN "*IDN?" | |
33 | #define SCPI_CMD_OPC "*OPC?" | |
34 | ||
35 | enum { | |
36 | SCPI_CMD_SET_TRIGGER_SOURCE = 1, | |
37 | SCPI_CMD_SET_TIMEBASE, | |
38 | SCPI_CMD_SET_VERTICAL_DIV, | |
39 | SCPI_CMD_SET_TRIGGER_SLOPE, | |
40 | SCPI_CMD_SET_COUPLING, | |
41 | SCPI_CMD_SET_HORIZ_TRIGGERPOS, | |
42 | SCPI_CMD_GET_ANALOG_CHAN_STATE, | |
43 | SCPI_CMD_GET_DIG_CHAN_STATE, | |
44 | SCPI_CMD_GET_TIMEBASE, | |
45 | SCPI_CMD_GET_VERTICAL_DIV, | |
46 | SCPI_CMD_GET_VERTICAL_OFFSET, | |
47 | SCPI_CMD_GET_TRIGGER_SOURCE, | |
48 | SCPI_CMD_GET_HORIZ_TRIGGERPOS, | |
49 | SCPI_CMD_GET_TRIGGER_SLOPE, | |
50 | SCPI_CMD_GET_COUPLING, | |
51 | SCPI_CMD_SET_ANALOG_CHAN_STATE, | |
52 | SCPI_CMD_SET_DIG_CHAN_STATE, | |
53 | SCPI_CMD_GET_DIG_POD_STATE, | |
54 | SCPI_CMD_SET_DIG_POD_STATE, | |
55 | SCPI_CMD_GET_ANALOG_DATA, | |
56 | SCPI_CMD_GET_DIG_DATA, | |
57 | SCPI_CMD_GET_SAMPLE_RATE, | |
58 | SCPI_CMD_GET_SAMPLE_RATE_LIVE, | |
59 | SCPI_CMD_GET_DATA_FORMAT, | |
60 | SCPI_CMD_GET_PROBE_FACTOR, | |
61 | SCPI_CMD_SET_PROBE_FACTOR, | |
62 | SCPI_CMD_GET_PROBE_UNIT, | |
63 | SCPI_CMD_SET_PROBE_UNIT, | |
64 | SCPI_CMD_GET_ANALOG_CHAN_NAME, | |
65 | SCPI_CMD_GET_DIG_CHAN_NAME, | |
66 | }; | |
67 | ||
68 | struct scpi_command { | |
69 | int command; | |
70 | const char *string; | |
71 | }; | |
72 | ||
73 | struct sr_scpi_hw_info { | |
74 | char *manufacturer; | |
75 | char *model; | |
76 | char *serial_number; | |
77 | char *firmware_version; | |
78 | }; | |
79 | ||
80 | struct sr_scpi_dev_inst { | |
81 | const char *name; | |
82 | const char *prefix; | |
83 | int priv_size; | |
84 | GSList *(*scan)(struct drv_context *drvc); | |
85 | int (*dev_inst_new)(void *priv, struct drv_context *drvc, | |
86 | const char *resource, char **params, const char *serialcomm); | |
87 | int (*open)(struct sr_scpi_dev_inst *scpi); | |
88 | int (*source_add)(struct sr_session *session, void *priv, int events, | |
89 | int timeout, sr_receive_data_callback cb, void *cb_data); | |
90 | int (*source_remove)(struct sr_session *session, void *priv); | |
91 | int (*send)(void *priv, const char *command); | |
92 | int (*read_begin)(void *priv); | |
93 | int (*read_data)(void *priv, char *buf, int maxlen); | |
94 | int (*write_data)(void *priv, char *buf, int len); | |
95 | int (*read_complete)(void *priv); | |
96 | int (*close)(struct sr_scpi_dev_inst *scpi); | |
97 | void (*free)(void *priv); | |
98 | unsigned int read_timeout_us; | |
99 | void *priv; | |
100 | /* Only used for quirk workarounds, notably the Rigol DS1000 series. */ | |
101 | uint64_t firmware_version; | |
102 | GMutex scpi_mutex; | |
103 | char *actual_channel_name; | |
104 | }; | |
105 | ||
106 | SR_PRIV GSList *sr_scpi_scan(struct drv_context *drvc, GSList *options, | |
107 | struct sr_dev_inst *(*probe_device)(struct sr_scpi_dev_inst *scpi)); | |
108 | SR_PRIV struct sr_scpi_dev_inst *scpi_dev_inst_new(struct drv_context *drvc, | |
109 | const char *resource, const char *serialcomm); | |
110 | SR_PRIV int sr_scpi_open(struct sr_scpi_dev_inst *scpi); | |
111 | SR_PRIV int sr_scpi_source_add(struct sr_session *session, | |
112 | struct sr_scpi_dev_inst *scpi, int events, int timeout, | |
113 | sr_receive_data_callback cb, void *cb_data); | |
114 | SR_PRIV int sr_scpi_source_remove(struct sr_session *session, | |
115 | struct sr_scpi_dev_inst *scpi); | |
116 | SR_PRIV int sr_scpi_send(struct sr_scpi_dev_inst *scpi, | |
117 | const char *format, ...); | |
118 | SR_PRIV int sr_scpi_send_variadic(struct sr_scpi_dev_inst *scpi, | |
119 | const char *format, va_list args); | |
120 | SR_PRIV int sr_scpi_read_begin(struct sr_scpi_dev_inst *scpi); | |
121 | SR_PRIV int sr_scpi_read_data(struct sr_scpi_dev_inst *scpi, char *buf, int maxlen); | |
122 | SR_PRIV int sr_scpi_write_data(struct sr_scpi_dev_inst *scpi, char *buf, int len); | |
123 | SR_PRIV int sr_scpi_read_complete(struct sr_scpi_dev_inst *scpi); | |
124 | SR_PRIV int sr_scpi_close(struct sr_scpi_dev_inst *scpi); | |
125 | SR_PRIV void sr_scpi_free(struct sr_scpi_dev_inst *scpi); | |
126 | ||
127 | SR_PRIV int sr_scpi_read_response(struct sr_scpi_dev_inst *scpi, | |
128 | GString *response, gint64 abs_timeout_us); | |
129 | SR_PRIV int sr_scpi_get_string(struct sr_scpi_dev_inst *scpi, | |
130 | const char *command, char **scpi_response); | |
131 | SR_PRIV int sr_scpi_get_bool(struct sr_scpi_dev_inst *scpi, | |
132 | const char *command, gboolean *scpi_response); | |
133 | SR_PRIV int sr_scpi_get_int(struct sr_scpi_dev_inst *scpi, | |
134 | const char *command, int *scpi_response); | |
135 | SR_PRIV int sr_scpi_get_float(struct sr_scpi_dev_inst *scpi, | |
136 | const char *command, float *scpi_response); | |
137 | SR_PRIV int sr_scpi_get_double(struct sr_scpi_dev_inst *scpi, | |
138 | const char *command, double *scpi_response); | |
139 | SR_PRIV int sr_scpi_get_opc(struct sr_scpi_dev_inst *scpi); | |
140 | SR_PRIV int sr_scpi_get_floatv(struct sr_scpi_dev_inst *scpi, | |
141 | const char *command, GArray **scpi_response); | |
142 | SR_PRIV int sr_scpi_get_uint8v(struct sr_scpi_dev_inst *scpi, | |
143 | const char *command, GArray **scpi_response); | |
144 | SR_PRIV int sr_scpi_get_data(struct sr_scpi_dev_inst *scpi, | |
145 | const char *command, GString **scpi_response); | |
146 | SR_PRIV int sr_scpi_get_block(struct sr_scpi_dev_inst *scpi, | |
147 | const char *command, GByteArray **scpi_response); | |
148 | SR_PRIV int sr_scpi_get_hw_id(struct sr_scpi_dev_inst *scpi, | |
149 | struct sr_scpi_hw_info **scpi_response); | |
150 | SR_PRIV void sr_scpi_hw_info_free(struct sr_scpi_hw_info *hw_info); | |
151 | ||
152 | SR_PRIV const char *sr_vendor_alias(const char *raw_vendor); | |
153 | SR_PRIV const char *sr_scpi_cmd_get(const struct scpi_command *cmdtable, | |
154 | int command); | |
155 | SR_PRIV int sr_scpi_cmd(const struct sr_dev_inst *sdi, | |
156 | const struct scpi_command *cmdtable, | |
157 | int channel_command, const char *channel_name, | |
158 | int command, ...); | |
159 | SR_PRIV int sr_scpi_cmd_resp(const struct sr_dev_inst *sdi, | |
160 | const struct scpi_command *cmdtable, | |
161 | int channel_command, const char *channel_name, | |
162 | GVariant **gvar, const GVariantType *gvtype, int command, ...); | |
163 | ||
164 | #endif |