]> sigrok.org Git - libsigrok.git/blame_incremental - src/hardware/korad-kaxxxxp/protocol.h
Makefile.am: Add/update udev rules files.
[libsigrok.git] / src / 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 *
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
20#ifndef LIBSIGROK_HARDWARE_KORAD_KAXXXXP_PROTOCOL_H
21#define LIBSIGROK_HARDWARE_KORAD_KAXXXXP_PROTOCOL_H
22
23#include <stdint.h>
24#include <string.h>
25#include <glib.h>
26#include <libsigrok/libsigrok.h>
27#include "libsigrok-internal.h"
28
29#define LOG_PREFIX "korad-kaxxxxp"
30
31#define KAXXXXP_POLL_INTERVAL_MS 80
32
33enum {
34 VELLEMAN_PS3005D,
35 VELLEMAN_LABPS3005D,
36 KORAD_KA3005P,
37 KORAD_KA3005P_0X01,
38 /* Support for future devices with this protocol. */
39};
40
41/* Information on single model */
42struct korad_kaxxxxp_model {
43 int model_id; /**< Model info */
44 const char *vendor; /**< Vendor name */
45 const char *name; /**< Model name */
46 const char *id; /**< Model ID, as delivered by interface */
47 int channels; /**< Number of channels */
48 double voltage[3]; /**< Min, max, step */
49 double current[3]; /**< Min, max, step */
50};
51
52/* Reply targets */
53enum {
54 KAXXXXP_CURRENT,
55 KAXXXXP_CURRENT_MAX,
56 KAXXXXP_VOLTAGE,
57 KAXXXXP_VOLTAGE_MAX,
58 KAXXXXP_STATUS,
59 KAXXXXP_OUTPUT,
60 KAXXXXP_BEEP,
61 KAXXXXP_OCP,
62 KAXXXXP_OVP,
63 KAXXXXP_SAVE,
64 KAXXXXP_RECALL,
65};
66
67struct dev_context {
68 const struct korad_kaxxxxp_model *model; /**< Model information. */
69
70 struct sr_sw_limits limits;
71 int64_t req_sent_at;
72 gboolean reply_pending;
73
74 float current; /**< Last current value [A] read from device. */
75 float current_max; /**< Output current set. */
76 float voltage; /**< Last voltage value [V] read from device. */
77 float voltage_max; /**< Output voltage set. */
78 gboolean cc_mode[2]; /**< Device is in CC mode (otherwise CV). */
79
80 gboolean output_enabled; /**< Is the output enabled? */
81 gboolean beep_enabled; /**< Enable beeper. */
82 gboolean ocp_enabled; /**< Output current protection enabled. */
83 gboolean ovp_enabled; /**< Output voltage protection enabled. */
84
85 int target; /**< What reply to expect. */
86 int program; /**< Program to store or recall. */
87 char reply[6];
88};
89
90SR_PRIV int korad_kaxxxxp_send_cmd(struct sr_serial_dev_inst *serial,
91 const char *cmd);
92SR_PRIV int korad_kaxxxxp_read_chars(struct sr_serial_dev_inst *serial,
93 int count, char *buf);
94SR_PRIV int korad_kaxxxxp_set_value(struct sr_serial_dev_inst *serial,
95 struct dev_context *devc);
96SR_PRIV int korad_kaxxxxp_query_value(struct sr_serial_dev_inst *serial,
97 struct dev_context *devc);
98SR_PRIV int korad_kaxxxxp_get_reply(struct sr_serial_dev_inst *serial,
99 struct dev_context *devc);
100SR_PRIV int korad_kaxxxxp_get_all_values(struct sr_serial_dev_inst *serial,
101 struct dev_context *devc);
102SR_PRIV int korad_kaxxxxp_receive_data(int fd, int revents, void *cb_data);
103
104#endif