]> sigrok.org Git - libsigrok.git/blame_incremental - hardware/korad-kaxxxxp/protocol.h
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / hardware / korad-kaxxxxp / protocol.h
... / ...
CommitLineData
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
34enum {
35 VELLEMAN_PS3005D,
36 VELLEMAN_LABPS3005D,
37 KORAD_KA3005P,
38 KORAD_KA3005P_0X01,
39 KORAD_KA3005P_0XBC,
40 KORAD_KA3005P_V42,
41 KORAD_KA3005P_V55,
42 KORAD_KD3005P_V20,
43 KORAD_KD3005P_V20_NOSP,
44 KORAD_KD3005P_V21_NOSP,
45 KORAD_KD3005P_V41,
46 RND_320_KD3005P,
47 RND_320_KA3005P,
48 RND_320K30PV,
49 TENMA_72_2550_V2,
50 TENMA_72_2540_V20,
51 TENMA_72_2540_V21,
52 TENMA_72_2540_V52,
53 TENMA_72_2535_V21,
54 TENMA_72_2710_V66,
55 STAMOS_SLS31_V20,
56 KORAD_KD6005P,
57 /* Support for future devices with this protocol. */
58};
59
60/* Information on single model */
61struct korad_kaxxxxp_model {
62 int model_id; /**< Model info */
63 const char *vendor; /**< Vendor name */
64 const char *name; /**< Model name */
65 const char *id; /**< Model ID, as delivered by interface */
66 int channels; /**< Number of channels */
67 double voltage[3]; /**< Min, max, step */
68 double current[3]; /**< Min, max, step */
69};
70
71/* Reply targets */
72enum {
73 KAXXXXP_CURRENT,
74 KAXXXXP_CURRENT_LIMIT,
75 KAXXXXP_VOLTAGE,
76 KAXXXXP_VOLTAGE_TARGET,
77 KAXXXXP_STATUS,
78 KAXXXXP_OUTPUT,
79 KAXXXXP_BEEP,
80 KAXXXXP_OCP,
81 KAXXXXP_OVP,
82 KAXXXXP_SAVE,
83 KAXXXXP_RECALL,
84};
85
86struct dev_context {
87 const struct korad_kaxxxxp_model *model; /**< Model information. */
88
89 struct sr_sw_limits limits;
90 int64_t req_sent_at;
91 GMutex rw_mutex;
92
93 float current; /**< Last current value [A] read from device. */
94 float current_limit; /**< Output current set. */
95 float voltage; /**< Last voltage value [V] read from device. */
96 float voltage_target; /**< Output voltage set. */
97 gboolean cc_mode[2]; /**< Device is in CC mode (otherwise CV). */
98
99 gboolean output_enabled; /**< Is the output enabled? */
100 gboolean beep_enabled; /**< Enable beeper. */
101 gboolean ocp_enabled; /**< Output current protection enabled. */
102 gboolean ovp_enabled; /**< Output voltage protection enabled. */
103
104 gboolean cc_mode_1_changed; /**< CC mode of channel 1 has changed. */
105 gboolean cc_mode_2_changed; /**< CC mode of channel 2 has changed. */
106 gboolean output_enabled_changed; /**< Output enabled state has changed. */
107 gboolean ocp_enabled_changed; /**< OCP enabled state has changed. */
108 gboolean ovp_enabled_changed; /**< OVP enabled state has changed. */
109
110 int acquisition_target; /**< What reply to expect. */
111 int program; /**< Program to store or recall. */
112
113 float set_current_limit; /**< New output current to set. */
114 float set_voltage_target; /**< New output voltage to set. */
115 gboolean set_output_enabled; /**< New output enabled to set. */
116 gboolean set_beep_enabled; /**< New enable beeper to set. */
117 gboolean set_ocp_enabled; /**< New OCP enabled to set. */
118 gboolean set_ovp_enabled; /**< New OVP enabled to set. */
119};
120
121SR_PRIV int korad_kaxxxxp_send_cmd(struct sr_serial_dev_inst *serial,
122 const char *cmd);
123SR_PRIV int korad_kaxxxxp_read_chars(struct sr_serial_dev_inst *serial,
124 size_t count, char *buf);
125SR_PRIV int korad_kaxxxxp_set_value(struct sr_serial_dev_inst *serial,
126 int target, struct dev_context *devc);
127SR_PRIV int korad_kaxxxxp_get_value(struct sr_serial_dev_inst *serial,
128 int target, struct dev_context *devc);
129SR_PRIV int korad_kaxxxxp_get_all_values(struct sr_serial_dev_inst *serial,
130 struct dev_context *devc);
131SR_PRIV int korad_kaxxxxp_receive_data(int fd, int revents, void *cb_data);
132
133#endif