]> sigrok.org Git - libsigrok.git/blob - src/hardware/korad-kaxxxxp/protocol.h
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / src / hardware / korad-kaxxxxp / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2015 Hannu Vuolasaho <vuokkosetae@gmail.com>
5  * Copyright (C) 2018-2019 Frank Stettner <frank-stettner@gmx.net>
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #ifndef LIBSIGROK_HARDWARE_KORAD_KAXXXXP_PROTOCOL_H
22 #define LIBSIGROK_HARDWARE_KORAD_KAXXXXP_PROTOCOL_H
23
24 #include <stdint.h>
25 #include <string.h>
26 #include <glib.h>
27 #include <libsigrok/libsigrok.h>
28 #include "libsigrok-internal.h"
29
30 #define LOG_PREFIX "korad-kaxxxxp"
31
32 #define KAXXXXP_POLL_INTERVAL_MS 80
33
34 enum korad_quirks_flag {
35         KORAD_QUIRK_NONE = 0,
36         KORAD_QUIRK_LABPS_OVP_EN = 1UL << 0,
37         KORAD_QUIRK_ID_NO_VENDOR = 1UL << 1,
38         KORAD_QUIRK_ID_TRAILING = 1UL << 2,
39         KORAD_QUIRK_ID_OPT_VERSION = 1UL << 3,
40         KORAD_QUIRK_SLOW_PROCESSING = 1UL << 4,
41         KORAD_QUIRK_ALL = (1UL << 5) - 1,
42 };
43
44 /* Information on single model */
45 struct korad_kaxxxxp_model {
46         const char *vendor; /**< Vendor name */
47         const char *name; /**< Model name */
48         const char *id; /**< Model ID, as delivered by interface */
49         int channels; /**< Number of channels */
50         const double *voltage; /**< References: Min, max, step */
51         const double *current; /**< References: Min, max, step */
52         enum korad_quirks_flag quirks;
53 };
54
55 /* Reply targets */
56 enum {
57         KAXXXXP_CURRENT,
58         KAXXXXP_CURRENT_LIMIT,
59         KAXXXXP_VOLTAGE,
60         KAXXXXP_VOLTAGE_TARGET,
61         KAXXXXP_STATUS,
62         KAXXXXP_OUTPUT,
63         KAXXXXP_BEEP,
64         KAXXXXP_OCP,
65         KAXXXXP_OVP,
66         KAXXXXP_SAVE,
67         KAXXXXP_RECALL,
68 };
69
70 struct dev_context {
71         const struct korad_kaxxxxp_model *model; /**< Model information. */
72
73         struct sr_sw_limits limits;
74         int64_t next_req_time;
75         GMutex rw_mutex;
76
77         float current;          /**< Last current value [A] read from device. */
78         float current_limit;    /**< Output current set. */
79         float voltage;          /**< Last voltage value [V] read from device. */
80         float voltage_target;   /**< Output voltage set. */
81         gboolean cc_mode[2];    /**< Device is in CC mode (otherwise CV). */
82
83         gboolean output_enabled; /**< Is the output enabled? */
84         gboolean beep_enabled;   /**< Enable beeper. */
85         gboolean ocp_enabled;    /**< Output current protection enabled. */
86         gboolean ovp_enabled;    /**< Output voltage protection enabled. */
87
88         gboolean cc_mode_1_changed;      /**< CC mode of channel 1 has changed. */
89         gboolean cc_mode_2_changed;      /**< CC mode of channel 2 has changed. */
90         gboolean output_enabled_changed; /**< Output enabled state has changed. */
91         gboolean ocp_enabled_changed;    /**< OCP enabled state has changed. */
92         gboolean ovp_enabled_changed;    /**< OVP enabled state has changed. */
93
94         int acquisition_target;  /**< What reply to expect. */
95         int program;             /**< Program to store or recall. */
96
97         float set_current_limit;     /**< New output current to set. */
98         float set_voltage_target;    /**< New output voltage to set. */
99         gboolean set_output_enabled; /**< New output enabled to set. */
100         gboolean set_beep_enabled;   /**< New enable beeper to set. */
101         gboolean set_ocp_enabled;    /**< New OCP enabled to set. */
102         gboolean set_ovp_enabled;    /**< New OVP enabled to set. */
103 };
104
105 SR_PRIV int korad_kaxxxxp_send_cmd(struct sr_serial_dev_inst *serial,
106                 const char *cmd);
107 SR_PRIV int korad_kaxxxxp_read_chars(struct sr_serial_dev_inst *serial,
108                 size_t count, char *buf);
109 SR_PRIV int korad_kaxxxxp_set_value(struct sr_serial_dev_inst *serial,
110                 int target, struct dev_context *devc);
111 SR_PRIV int korad_kaxxxxp_get_value(struct sr_serial_dev_inst *serial,
112                 int target, struct dev_context *devc);
113 SR_PRIV int korad_kaxxxxp_get_all_values(struct sr_serial_dev_inst *serial,
114                 struct dev_context *devc);
115 SR_PRIV int korad_kaxxxxp_receive_data(int fd, int revents, void *cb_data);
116
117 #endif