]> sigrok.org Git - libsigrok.git/blob - src/hardware/rdtech-dps/protocol.h
26c196ff43755d1585206c0e60df30f6bcf54e03
[libsigrok.git] / src / hardware / rdtech-dps / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2018 James Churchill <pelrun@gmail.com>
5  * Copyright (C) 2019 Frank Stettner <frank-stettner@gmx.net>
6  * Copyright (C) 2021 Gerhard Sittig <gerhard.sittig@gmx.net>
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 #ifndef LIBSIGROK_HARDWARE_RDTECH_DPS_PROTOCOL_H
23 #define LIBSIGROK_HARDWARE_RDTECH_DPS_PROTOCOL_H
24
25 #include <config.h>
26
27 #include <glib.h>
28 #include <libsigrok/libsigrok.h>
29 #include <stdint.h>
30
31 #include "libsigrok-internal.h"
32
33 #define LOG_PREFIX "rdtech-dps"
34
35 enum rdtech_dps_model_type {
36         MODEL_NONE,
37         MODEL_DPS,
38         MODEL_RD,
39 };
40
41 struct rdtech_dps_model {
42         enum rdtech_dps_model_type model_type;
43         unsigned int id;
44         const char *name;
45         unsigned int max_current;
46         unsigned int max_voltage;
47         unsigned int max_power;
48         unsigned int current_digits;
49         unsigned int voltage_digits;
50 };
51
52 struct dev_context {
53         const struct rdtech_dps_model *model;
54         double current_multiplier;
55         double voltage_multiplier;
56         struct sr_sw_limits limits;
57         GMutex rw_mutex;
58         gboolean curr_ovp_state;
59         gboolean curr_ocp_state;
60         gboolean curr_cc_state;
61         gboolean curr_out_state;
62 };
63
64 /* Container to get and set parameter values. */
65 struct rdtech_dps_state {
66         enum rdtech_dps_state_mask {
67                 STATE_LOCK = 1 << 0,
68                 STATE_OUTPUT_ENABLED = 1 << 1,
69                 STATE_REGULATION_CC = 1 << 2,
70                 STATE_PROTECT_OVP = 1 << 3,
71                 STATE_PROTECT_OCP = 1 << 4,
72                 STATE_PROTECT_ENABLED = 1 << 5,
73                 STATE_VOLTAGE_TARGET = 1 << 6,
74                 STATE_CURRENT_LIMIT = 1 << 7,
75                 STATE_OVP_THRESHOLD = 1 << 8,
76                 STATE_OCP_THRESHOLD = 1 << 9,
77                 STATE_VOLTAGE = 1 << 10,
78                 STATE_CURRENT = 1 << 11,
79                 STATE_POWER = 1 << 12,
80         } mask;
81         gboolean lock;
82         gboolean output_enabled, regulation_cc;
83         gboolean protect_ovp, protect_ocp, protect_enabled;
84         float voltage_target, current_limit;
85         float ovp_threshold, ocp_threshold;
86         float voltage, current, power;
87 };
88
89 SR_PRIV int rdtech_dps_get_state(const struct sr_dev_inst *sdi,
90         struct rdtech_dps_state *state);
91 SR_PRIV int rdtech_dps_set_state(const struct sr_dev_inst *sdi,
92         struct rdtech_dps_state *state);
93
94 SR_PRIV int rdtech_dps_get_model_version(struct sr_modbus_dev_inst *modbus,
95         enum rdtech_dps_model_type model_type,
96         uint16_t *model, uint16_t *version, uint32_t *serno);
97 SR_PRIV int rdtech_dps_seed_receive(const struct sr_dev_inst *sdi);
98 SR_PRIV int rdtech_dps_receive_data(int fd, int revents, void *cb_data);
99
100 #endif