]> sigrok.org Git - libsigrok.git/blame - src/hardware/korad-kaxxxxp/protocol.h
Remove unnecessary std_serial_dev_acquisition_stop() wrappers
[libsigrok.git] / src / hardware / korad-kaxxxxp / protocol.h
CommitLineData
e75ee7de
HV
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2015 Hannu Vuolasaho <vuokkosetae@gmail.com>
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
d7083042
HV
20/**
21 * @file
16fc7ee2 22 * Korad KAxxxxP power supply driver
d7083042
HV
23 * @internal
24 */
25
16fc7ee2
UH
26#ifndef LIBSIGROK_HARDWARE_KORAD_KAXXXXP_PROTOCOL_H
27#define LIBSIGROK_HARDWARE_KORAD_KAXXXXP_PROTOCOL_H
e75ee7de
HV
28
29#include <stdint.h>
d7083042 30#include <string.h>
e75ee7de
HV
31#include <glib.h>
32#include <libsigrok/libsigrok.h>
33#include "libsigrok-internal.h"
34
16fc7ee2 35#define LOG_PREFIX "korad-kaxxxxp"
e75ee7de 36
16fc7ee2 37#define KAXXXXP_POLL_INTERVAL_MS 80
d7083042
HV
38
39enum {
ae9ca5b1
UH
40 VELLEMAN_PS3005D,
41 VELLEMAN_LABPS3005D,
bcf9384d 42 KORAD_KA3005P,
a078d3ec 43 KORAD_KA3005P_0X01,
d7083042
HV
44 /* Support for future devices with this protocol. */
45};
46
47/* Information on single model */
16fc7ee2 48struct korad_kaxxxxp_model {
d7083042 49 int model_id; /**< Model info */
2c240774
UH
50 const char *vendor; /**< Vendor name */
51 const char *name; /**< Model name */
52 const char *id; /**< Model ID, as delivered by interface */
d7083042
HV
53 int channels; /**< Number of channels */
54 double voltage[3]; /**< Min, max, step */
55 double current[3]; /**< Min, max, step */
56};
57
58/* Reply targets */
59enum {
16fc7ee2
UH
60 KAXXXXP_CURRENT,
61 KAXXXXP_CURRENT_MAX,
62 KAXXXXP_VOLTAGE,
63 KAXXXXP_VOLTAGE_MAX,
64 KAXXXXP_STATUS,
65 KAXXXXP_OUTPUT,
66 KAXXXXP_BEEP,
67 KAXXXXP_OCP,
68 KAXXXXP_OVP,
69 KAXXXXP_SAVE,
70 KAXXXXP_RECALL,
d7083042
HV
71};
72
e75ee7de
HV
73/** Private, per-device-instance driver context. */
74struct dev_context {
75 /* Model-specific information */
16fc7ee2 76 const struct korad_kaxxxxp_model *model; /**< Model information. */
e75ee7de
HV
77
78 /* Acquisition settings */
597deef9 79 struct sr_sw_limits limits;
d7083042
HV
80 int64_t req_sent_at;
81 gboolean reply_pending;
82
e75ee7de 83 /* Operational state */
d7083042
HV
84 float current; /**< Last current value [A] read from device. */
85 float current_max; /**< Output current set. */
86 float voltage; /**< Last voltage value [V] read from device. */
87 float voltage_max; /**< Output voltage set. */
88 gboolean cc_mode[2]; /**< Device is in CC mode (otherwise CV). */
e75ee7de 89
d7083042
HV
90 gboolean output_enabled; /**< Is the output enabled? */
91 gboolean beep_enabled; /**< Enable beeper. */
9e5366df
UH
92 gboolean ocp_enabled; /**< Output current protection enabled. */
93 gboolean ovp_enabled; /**< Output voltage protection enabled. */
e75ee7de 94
d7083042 95 /* Temporary state across callbacks */
9e5366df 96 int target; /**< What reply to expect. */
d7083042
HV
97 int program; /**< Program to store or recall. */
98 char reply[6];
e75ee7de
HV
99};
100
16fc7ee2 101SR_PRIV int korad_kaxxxxp_send_cmd(struct sr_serial_dev_inst *serial,
d7083042 102 const char *cmd);
16fc7ee2 103SR_PRIV int korad_kaxxxxp_read_chars(struct sr_serial_dev_inst *serial,
d7083042 104 int count, char *buf);
16fc7ee2 105SR_PRIV int korad_kaxxxxp_set_value(struct sr_serial_dev_inst *serial,
d7083042 106 struct dev_context *devc);
16fc7ee2 107SR_PRIV int korad_kaxxxxp_query_value(struct sr_serial_dev_inst *serial,
d7083042 108 struct dev_context *devc);
16fc7ee2 109SR_PRIV int korad_kaxxxxp_get_reply(struct sr_serial_dev_inst *serial,
d7083042 110 struct dev_context *devc);
16fc7ee2 111SR_PRIV int korad_kaxxxxp_get_all_values(struct sr_serial_dev_inst *serial,
d7083042 112 struct dev_context *devc);
16fc7ee2 113SR_PRIV int korad_kaxxxxp_receive_data(int fd, int revents, void *cb_data);
e75ee7de
HV
114
115#endif