]> sigrok.org Git - libsigrok.git/blame - src/hardware/scpi-dmm/protocol.h
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / src / hardware / scpi-dmm / protocol.h
CommitLineData
7a396ff5
GS
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
3cdad416 23#include <config.h>
7a396ff5 24#include <glib.h>
3cdad416
GS
25#include <stdint.h>
26#include <stdlib.h>
7a396ff5
GS
27#include <libsigrok/libsigrok.h>
28#include "libsigrok-internal.h"
3cdad416 29#include "scpi.h"
7a396ff5
GS
30
31#define LOG_PREFIX "scpi-dmm"
32
3cdad416
GS
33#define SCPI_DMM_MAX_CHANNELS 1
34
35enum 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,
4c80a272 43 DMM_CMD_SETUP_LOCAL,
a0418c20
GS
44 DMM_CMD_QUERY_RANGE_AUTO,
45 DMM_CMD_QUERY_RANGE,
46 DMM_CMD_SETUP_RANGE_AUTO,
47 DMM_CMD_SETUP_RANGE,
3cdad416
GS
48};
49
50struct 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;
1de14d67 56 uint32_t drv_flags;
3cdad416
GS
57};
58#define NO_DFLT_PREC -99
1de14d67 59#define FLAGS_NONE 0
5bf642db 60#define FLAG_NO_RANGE (1 << 0)
08f023fe 61#define FLAG_CONF_DELAY (1 << 1)
e90551c3 62#define FLAG_MEAS_DELAY (1 << 2)
3cdad416
GS
63
64struct scpi_dmm_model {
65 const char *vendor;
66 const char *model;
67 size_t num_channels;
68 ssize_t digits;
69 const struct scpi_command *cmdset;
70 const struct mqopt_item *mqopts;
71 size_t mqopt_size;
72 int (*get_measurement)(const struct sr_dev_inst *sdi, size_t ch);
1d2f9963
GS
73 const uint32_t *devopts;
74 size_t devopts_size;
a1619831 75 unsigned int read_timeout_us; /* If zero, use default from src/scpi/scpi.c. */
08f023fe 76 unsigned int conf_delay_us;
e90551c3 77 unsigned int meas_delay_us;
33306b13 78 float infinity_limit; /* If zero, use default from protocol.c */
cae328b5 79 gboolean check_opc;
a0418c20
GS
80 const char *(*get_range_text)(const struct sr_dev_inst *sdi);
81 int (*set_range_from_text)(const struct sr_dev_inst *sdi,
82 const char *range);
83 GVariant *(*get_range_text_list)(const struct sr_dev_inst *sdi);
3cdad416
GS
84};
85
7a396ff5 86struct dev_context {
3cdad416
GS
87 size_t num_channels;
88 const struct scpi_command *cmdset;
89 const struct scpi_dmm_model *model;
90 struct sr_sw_limits limits;
91 struct {
92 enum sr_mq curr_mq;
93 enum sr_mqflag curr_mqflag;
94 } start_acq_mq;
95 struct scpi_dmm_acq_info {
96 float f_value;
97 double d_value;
98 struct sr_datafeed_packet packet;
99 struct sr_datafeed_analog analog[SCPI_DMM_MAX_CHANNELS];
100 struct sr_analog_encoding encoding[SCPI_DMM_MAX_CHANNELS];
101 struct sr_analog_meaning meaning[SCPI_DMM_MAX_CHANNELS];
102 struct sr_analog_spec spec[SCPI_DMM_MAX_CHANNELS];
103 } run_acq_info;
d0b602f0 104 gchar *precision;
a0418c20 105 char range_text[32];
7a396ff5
GS
106};
107
3cdad416
GS
108SR_PRIV void scpi_dmm_cmd_delay(struct sr_scpi_dev_inst *scpi);
109SR_PRIV const struct mqopt_item *scpi_dmm_lookup_mq_number(
110 const struct sr_dev_inst *sdi, enum sr_mq mq, enum sr_mqflag flag);
111SR_PRIV const struct mqopt_item *scpi_dmm_lookup_mq_text(
112 const struct sr_dev_inst *sdi, const char *text);
113SR_PRIV int scpi_dmm_get_mq(const struct sr_dev_inst *sdi,
08f3b427
GS
114 enum sr_mq *mq, enum sr_mqflag *flag, char **rsp,
115 const struct mqopt_item **mqitem);
3cdad416
GS
116SR_PRIV int scpi_dmm_set_mq(const struct sr_dev_inst *sdi,
117 enum sr_mq mq, enum sr_mqflag flag);
a0418c20
GS
118SR_PRIV const char *scpi_dmm_get_range_text(const struct sr_dev_inst *sdi);
119SR_PRIV int scpi_dmm_set_range_from_text(const struct sr_dev_inst *sdi,
120 const char *range);
121SR_PRIV GVariant *scpi_dmm_get_range_text_list(const struct sr_dev_inst *sdi);
3cdad416 122SR_PRIV int scpi_dmm_get_meas_agilent(const struct sr_dev_inst *sdi, size_t ch);
d0b602f0 123SR_PRIV int scpi_dmm_get_meas_gwinstek(const struct sr_dev_inst *sdi, size_t ch);
7a396ff5
GS
124SR_PRIV int scpi_dmm_receive_data(int fd, int revents, void *cb_data);
125
126#endif