]> sigrok.org Git - libsigrok.git/blob - src/hardware/scpi-dmm/protocol.h
scpi-dmm: move OPC availability check to after IDN device identification
[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 };
45
46 struct mqopt_item {
47         enum sr_mq mq;
48         enum sr_mqflag mqflag;
49         const char *scpi_func_setup;
50         const char *scpi_func_query;
51         int default_precision;
52 };
53 #define NO_DFLT_PREC    -99
54
55 struct scpi_dmm_model {
56         const char *vendor;
57         const char *model;
58         size_t num_channels;
59         ssize_t digits;
60         const struct scpi_command *cmdset;
61         const struct mqopt_item *mqopts;
62         size_t mqopt_size;
63         int (*get_measurement)(const struct sr_dev_inst *sdi, size_t ch);
64         const uint32_t *devopts;
65         size_t devopts_size;
66         unsigned int read_timeout_us; /* If zero, use default from src/scpi/scpi.c. */
67         float infinity_limit; /* If zero, use default from protocol.c */
68         gboolean check_opc;
69 };
70
71 struct dev_context {
72         size_t num_channels;
73         const struct scpi_command *cmdset;
74         const struct scpi_dmm_model *model;
75         struct sr_sw_limits limits;
76         struct {
77                 enum sr_mq curr_mq;
78                 enum sr_mqflag curr_mqflag;
79         } start_acq_mq;
80         struct scpi_dmm_acq_info {
81                 float f_value;
82                 double d_value;
83                 struct sr_datafeed_packet packet;
84                 struct sr_datafeed_analog analog[SCPI_DMM_MAX_CHANNELS];
85                 struct sr_analog_encoding encoding[SCPI_DMM_MAX_CHANNELS];
86                 struct sr_analog_meaning meaning[SCPI_DMM_MAX_CHANNELS];
87                 struct sr_analog_spec spec[SCPI_DMM_MAX_CHANNELS];
88         } run_acq_info;
89         gchar *precision;
90 };
91
92 SR_PRIV void scpi_dmm_cmd_delay(struct sr_scpi_dev_inst *scpi);
93 SR_PRIV const struct mqopt_item *scpi_dmm_lookup_mq_number(
94         const struct sr_dev_inst *sdi, enum sr_mq mq, enum sr_mqflag flag);
95 SR_PRIV const struct mqopt_item *scpi_dmm_lookup_mq_text(
96         const struct sr_dev_inst *sdi, const char *text);
97 SR_PRIV int scpi_dmm_get_mq(const struct sr_dev_inst *sdi,
98         enum sr_mq *mq, enum sr_mqflag *flag, char **rsp,
99         const struct mqopt_item **mqitem);
100 SR_PRIV int scpi_dmm_set_mq(const struct sr_dev_inst *sdi,
101         enum sr_mq mq, enum sr_mqflag flag);
102 SR_PRIV int scpi_dmm_get_meas_agilent(const struct sr_dev_inst *sdi, size_t ch);
103 SR_PRIV int scpi_dmm_get_meas_gwinstek(const struct sr_dev_inst *sdi, size_t ch);
104 SR_PRIV int scpi_dmm_receive_data(int fd, int revents, void *cb_data);
105
106 #endif