2 * This file is part of the libsigrok project.
4 * Copyright (C) 2015 Hannu Vuolasaho <vuokkosetae@gmail.com>
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.
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.
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/>.
22 * Korad KDxxxxP power supply driver
26 #ifndef LIBSIGROK_HARDWARE_KORAD_KDXXXXP_PROTOCOL_H
27 #define LIBSIGROK_HARDWARE_KORAD_KDXXXXP_PROTOCOL_H
32 #include <libsigrok/libsigrok.h>
33 #include "libsigrok-internal.h"
35 #define LOG_PREFIX "korad-kdxxxxp"
37 #define KDXXXXP_POLL_INTERVAL_MS 80
41 /* Support for future devices with this protocol. */
44 /* Information on single model */
45 struct korad_kdxxxxp_model {
46 int model_id; /**< Model info */
47 const char *vendor; /**< Vendor name */
48 const char *name; /**< Model name */
49 const char *id; /**< Model ID, as delivered by interface */
50 int channels; /**< Number of channels */
51 double voltage[3]; /**< Min, max, step */
52 double current[3]; /**< Min, max, step */
70 /** Private, per-device-instance driver context. */
72 /* Model-specific information */
73 const struct korad_kdxxxxp_model *model; /**< Model information. */
75 /* Acquisition settings */
76 uint64_t limit_samples;
81 gboolean reply_pending;
85 /* Operational state */
86 float current; /**< Last current value [A] read from device. */
87 float current_max; /**< Output current set. */
88 float voltage; /**< Last voltage value [V] read from device. */
89 float voltage_max; /**< Output voltage set. */
90 gboolean cc_mode[2]; /**< Device is in CC mode (otherwise CV). */
92 gboolean output_enabled; /**< Is the output enabled? */
93 gboolean beep_enabled; /**< Enable beeper. */
94 gboolean ocp_enabled; /**< Output current protection enabled. */
95 gboolean ovp_enabled; /**< Output voltage protection enabled. */
97 /* Temporary state across callbacks */
98 int target; /**< What reply to expect. */
99 int program; /**< Program to store or recall. */
103 SR_PRIV int korad_kdxxxxp_send_cmd(struct sr_serial_dev_inst *serial,
105 SR_PRIV int korad_kdxxxxp_read_chars(struct sr_serial_dev_inst *serial,
106 int count, char *buf);
107 SR_PRIV int korad_kdxxxxp_set_value(struct sr_serial_dev_inst *serial,
108 struct dev_context *devc);
109 SR_PRIV int korad_kdxxxxp_query_value(struct sr_serial_dev_inst *serial,
110 struct dev_context *devc);
111 SR_PRIV int korad_kdxxxxp_get_reply(struct sr_serial_dev_inst *serial,
112 struct dev_context *devc);
113 SR_PRIV int korad_kdxxxxp_get_all_values(struct sr_serial_dev_inst *serial,
114 struct dev_context *devc);
115 SR_PRIV int korad_kdxxxxp_receive_data(int fd, int revents, void *cb_data);