]> sigrok.org Git - libsigrok.git/blob - src/hardware/mooshimeter-dmm/protocol.h
uni-t-ut181a: silence compiler warning, use of uninitialized variable
[libsigrok.git] / src / hardware / mooshimeter-dmm / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2019 Derek Hageman <hageman@inthat.cloud>
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_MOOSHIMETER_DMM_PROTOCOL_H
21 #define LIBSIGROK_HARDWARE_MOOSHIMETER_DMM_PROTOCOL_H
22
23 #include <stdint.h>
24 #include <glib.h>
25 #include <libsigrok/libsigrok.h>
26 #include "libsigrok-internal.h"
27
28 #define LOG_PREFIX "mooshimeter-dmm"
29
30 struct packet_rx {
31         int sequence_number;
32         GSList *reorder_buffer;
33         GByteArray *contents;
34 };
35
36 struct packet_tx {
37         int sequence_number;
38 };
39
40 enum tree_node_datatype {
41         TREE_NODE_DATATYPE_PLAIN = 0,
42         TREE_NODE_DATATYPE_LINK,
43         TREE_NODE_DATATYPE_CHOOSER,
44         TREE_NODE_DATATYPE_U8,
45         TREE_NODE_DATATYPE_U16,
46         TREE_NODE_DATATYPE_U32,
47         TREE_NODE_DATATYPE_S8,
48         TREE_NODE_DATATYPE_S16,
49         TREE_NODE_DATATYPE_S32,
50         TREE_NODE_DATATYPE_STRING,
51         TREE_NODE_DATATYPE_BINARY,
52         TREE_NODE_DATATYPE_FLOAT,
53 };
54
55 union tree_value {
56         int32_t i;
57         float f;
58         GByteArray *b;
59 };
60
61 struct config_tree_node {
62         char *name;
63         int id;
64         size_t index_in_parent;
65
66         enum tree_node_datatype type;
67         union tree_value value;
68
69         size_t count_children;
70         struct config_tree_node *children;
71
72         uint32_t update_number;
73         void (*on_update)(struct config_tree_node *node, void *param);
74         void *on_update_param;
75 };
76
77 struct dev_context {
78         struct packet_rx rx;
79         struct packet_tx tx;
80         struct config_tree_node tree_root;
81         struct config_tree_node *tree_id_lookup[0x7F];
82         uint32_t buffer_bps[2];
83         float buffer_lsb2native[2];
84
85         void (*channel_autorange[3])(const struct sr_dev_inst *sdi, float value);
86
87         struct sr_sw_limits limits;
88         struct sr_analog_meaning channel_meaning[3];
89
90         gboolean enable_value_stream;
91 };
92
93 SR_PRIV int mooshimeter_dmm_open(const struct sr_dev_inst *sdi);
94 SR_PRIV int mooshimeter_dmm_close(const struct sr_dev_inst *sdi);
95 SR_PRIV int mooshimeter_dmm_set_chooser(const struct sr_dev_inst *sdi, const char *path, const char *choice);
96 SR_PRIV int mooshimeter_dmm_set_integer(const struct sr_dev_inst *sdi, const char *path, int value);
97 SR_PRIV int mooshimeter_dmm_set_larger_number(const struct sr_dev_inst *sdi, const char *path, const char *parent, float number);
98 SR_PRIV gboolean mooshimeter_dmm_set_autorange(const struct sr_dev_inst *sdi, const char *path, const char *parent, float latest);
99 SR_PRIV int mooshimeter_dmm_get_chosen_number(const struct sr_dev_inst *sdi, const char *path, const char *parent, float *number);
100 SR_PRIV int mooshimeter_dmm_get_available_number_choices(const struct sr_dev_inst *sdi, const char *path, float **numbers, size_t *count);
101 SR_PRIV int mooshimeter_dmm_poll(int fd, int revents, void *cb_data);
102 SR_PRIV int mooshimeter_dmm_heartbeat(int fd, int revents, void *cb_data);
103
104 #endif