]> sigrok.org Git - libsigrok.git/blob - src/hardware/scpi-dmm/protocol.h
0864196c44a365c7a40a35d474d54c02e6a1506c
[libsigrok.git] / src / hardware / scpi-dmm / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2018 Gerhard Sittig <gerhard.sittig@gmx.net>
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_DMM_PROTOCOL_H
21 #define LIBSIGROK_HARDWARE_SCPI_DMM_PROTOCOL_H
22
23 #include <config.h>
24 #include <glib.h>
25 #include <stdint.h>
26 #include <stdlib.h>
27 #include <libsigrok/libsigrok.h>
28 #include "libsigrok-internal.h"
29 #include "scpi.h"
30
31 #define LOG_PREFIX "scpi-dmm"
32
33 #define SCPI_DMM_MAX_CHANNELS   1
34
35 enum scpi_dmm_cmdcode {
36         DMM_CMD_SETUP_REMOTE,
37         DMM_CMD_SETUP_FUNC,
38         DMM_CMD_QUERY_FUNC,
39         DMM_CMD_START_ACQ,
40         DMM_CMD_STOP_ACQ,
41         DMM_CMD_QUERY_VALUE,
42         DMM_CMD_QUERY_PREC,
43         DMM_CMD_SETUP_LOCAL,
44         DMM_CMD_QUERY_RANGE_AUTO,
45         DMM_CMD_QUERY_RANGE,
46         DMM_CMD_SETUP_RANGE_AUTO,
47         DMM_CMD_SETUP_RANGE,
48 };
49
50 struct mqopt_item {
51         enum sr_mq mq;
52         enum sr_mqflag mqflag;
53         const char *scpi_func_setup;
54         const char *scpi_func_query;
55         int default_precision;
56         uint32_t drv_flags;
57 };
58 #define NO_DFLT_PREC    -99
59 #define FLAGS_NONE      0
60 #define FLAG_NO_RANGE   (1 << 0)
61 #define FLAG_CONF_DELAY (1 << 1)
62
63 struct scpi_dmm_model {
64         const char *vendor;
65         const char *model;
66         size_t num_channels;
67         ssize_t digits;
68         const struct scpi_command *cmdset;
69         const struct mqopt_item *mqopts;
70         size_t mqopt_size;
71         int (*get_measurement)(const struct sr_dev_inst *sdi, size_t ch);
72         const uint32_t *devopts;
73         size_t devopts_size;
74         unsigned int read_timeout_us; /* If zero, use default from src/scpi/scpi.c. */
75         unsigned int conf_delay_us;
76         float infinity_limit; /* If zero, use default from protocol.c */
77         gboolean check_opc;
78         const char *(*get_range_text)(const struct sr_dev_inst *sdi);
79         int (*set_range_from_text)(const struct sr_dev_inst *sdi,
80                 const char *range);
81         GVariant *(*get_range_text_list)(const struct sr_dev_inst *sdi);
82 };
83
84 struct dev_context {
85         size_t num_channels;
86         const struct scpi_command *cmdset;
87         const struct scpi_dmm_model *model;
88         struct sr_sw_limits limits;
89         struct {
90                 enum sr_mq curr_mq;
91                 enum sr_mqflag curr_mqflag;
92         } start_acq_mq;
93         struct scpi_dmm_acq_info {
94                 float f_value;
95                 double d_value;
96                 struct sr_datafeed_packet packet;
97                 struct sr_datafeed_analog analog[SCPI_DMM_MAX_CHANNELS];
98                 struct sr_analog_encoding encoding[SCPI_DMM_MAX_CHANNELS];
99                 struct sr_analog_meaning meaning[SCPI_DMM_MAX_CHANNELS];
100                 struct sr_analog_spec spec[SCPI_DMM_MAX_CHANNELS];
101         } run_acq_info;
102         gchar *precision;
103         char range_text[32];
104 };
105
106 SR_PRIV void scpi_dmm_cmd_delay(struct sr_scpi_dev_inst *scpi);
107 SR_PRIV const struct mqopt_item *scpi_dmm_lookup_mq_number(
108         const struct sr_dev_inst *sdi, enum sr_mq mq, enum sr_mqflag flag);
109 SR_PRIV const struct mqopt_item *scpi_dmm_lookup_mq_text(
110         const struct sr_dev_inst *sdi, const char *text);
111 SR_PRIV int scpi_dmm_get_mq(const struct sr_dev_inst *sdi,
112         enum sr_mq *mq, enum sr_mqflag *flag, char **rsp,
113         const struct mqopt_item **mqitem);
114 SR_PRIV int scpi_dmm_set_mq(const struct sr_dev_inst *sdi,
115         enum sr_mq mq, enum sr_mqflag flag);
116 SR_PRIV const char *scpi_dmm_get_range_text(const struct sr_dev_inst *sdi);
117 SR_PRIV int scpi_dmm_set_range_from_text(const struct sr_dev_inst *sdi,
118         const char *range);
119 SR_PRIV GVariant *scpi_dmm_get_range_text_list(const struct sr_dev_inst *sdi);
120 SR_PRIV int scpi_dmm_get_meas_agilent(const struct sr_dev_inst *sdi, size_t ch);
121 SR_PRIV int scpi_dmm_get_meas_gwinstek(const struct sr_dev_inst *sdi, size_t ch);
122 SR_PRIV int scpi_dmm_receive_data(int fd, int revents, void *cb_data);
123
124 #endif