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