]>
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> | |
2e129b8b | 5 | * Copyright (C) 2018-2019 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, |
1c0e1baa | 39 | KORAD_KA3005P_0XBC, |
7415217e | 40 | KORAD_KA3005P_V42, |
8b58a519 | 41 | KORAD_KA3005P_V55, |
41802ca4 | 42 | KORAD_KD3005P, |
76f712a7 | 43 | KORAD_KD3005P_V20_NOSP, |
cf6beeb2 | 44 | RND_320_KD3005P, |
c8dcd3ab | 45 | RND_320_KA3005P, |
e843992d | 46 | RND_320K30PV, |
0540954d UH |
47 | TENMA_72_2540_V20, |
48 | TENMA_72_2540_V21, | |
082ca8d8 | 49 | TENMA_72_2540_V52, |
ddbe6880 | 50 | TENMA_72_2535_V21, |
27a9b663 | 51 | STAMOS_SLS31_V20, |
b1b8a7d0 | 52 | KORAD_KD6005P, |
d7083042 HV |
53 | /* Support for future devices with this protocol. */ |
54 | }; | |
55 | ||
56 | /* Information on single model */ | |
16fc7ee2 | 57 | struct korad_kaxxxxp_model { |
d7083042 | 58 | int model_id; /**< Model info */ |
2c240774 UH |
59 | const char *vendor; /**< Vendor name */ |
60 | const char *name; /**< Model name */ | |
61 | const char *id; /**< Model ID, as delivered by interface */ | |
d7083042 HV |
62 | int channels; /**< Number of channels */ |
63 | double voltage[3]; /**< Min, max, step */ | |
64 | double current[3]; /**< Min, max, step */ | |
65 | }; | |
66 | ||
67 | /* Reply targets */ | |
68 | enum { | |
16fc7ee2 | 69 | KAXXXXP_CURRENT, |
8da30037 | 70 | KAXXXXP_CURRENT_LIMIT, |
16fc7ee2 | 71 | KAXXXXP_VOLTAGE, |
8da30037 | 72 | KAXXXXP_VOLTAGE_TARGET, |
16fc7ee2 UH |
73 | KAXXXXP_STATUS, |
74 | KAXXXXP_OUTPUT, | |
75 | KAXXXXP_BEEP, | |
76 | KAXXXXP_OCP, | |
77 | KAXXXXP_OVP, | |
78 | KAXXXXP_SAVE, | |
79 | KAXXXXP_RECALL, | |
d7083042 HV |
80 | }; |
81 | ||
e75ee7de | 82 | struct dev_context { |
16fc7ee2 | 83 | const struct korad_kaxxxxp_model *model; /**< Model information. */ |
e75ee7de | 84 | |
597deef9 | 85 | struct sr_sw_limits limits; |
d7083042 | 86 | int64_t req_sent_at; |
3f9b48ae | 87 | GMutex rw_mutex; |
d7083042 | 88 | |
d7083042 | 89 | float current; /**< Last current value [A] read from device. */ |
8da30037 | 90 | float current_limit; /**< Output current set. */ |
d7083042 | 91 | float voltage; /**< Last voltage value [V] read from device. */ |
8da30037 | 92 | float voltage_target; /**< Output voltage set. */ |
d7083042 | 93 | gboolean cc_mode[2]; /**< Device is in CC mode (otherwise CV). */ |
e75ee7de | 94 | |
d7083042 HV |
95 | gboolean output_enabled; /**< Is the output enabled? */ |
96 | gboolean beep_enabled; /**< Enable beeper. */ | |
9e5366df UH |
97 | gboolean ocp_enabled; /**< Output current protection enabled. */ |
98 | gboolean ovp_enabled; /**< Output voltage protection enabled. */ | |
e75ee7de | 99 | |
2e129b8b FS |
100 | gboolean cc_mode_1_changed; /**< CC mode of channel 1 has changed. */ |
101 | gboolean cc_mode_2_changed; /**< CC mode of channel 2 has changed. */ | |
102 | gboolean output_enabled_changed; /**< Output enabled state has changed. */ | |
103 | gboolean ocp_enabled_changed; /**< OCP enabled state has changed. */ | |
104 | gboolean ovp_enabled_changed; /**< OVP enabled state has changed. */ | |
105 | ||
3f9b48ae | 106 | int acquisition_target; /**< What reply to expect. */ |
d7083042 | 107 | int program; /**< Program to store or recall. */ |
8da30037 FS |
108 | |
109 | float set_current_limit; /**< New output current to set. */ | |
110 | float set_voltage_target; /**< New output voltage to set. */ | |
111 | gboolean set_output_enabled; /**< New output enabled to set. */ | |
112 | gboolean set_beep_enabled; /**< New enable beeper to set. */ | |
113 | gboolean set_ocp_enabled; /**< New OCP enabled to set. */ | |
114 | gboolean set_ovp_enabled; /**< New OVP enabled to set. */ | |
e75ee7de HV |
115 | }; |
116 | ||
16fc7ee2 | 117 | SR_PRIV int korad_kaxxxxp_send_cmd(struct sr_serial_dev_inst *serial, |
d7083042 | 118 | const char *cmd); |
16fc7ee2 | 119 | SR_PRIV int korad_kaxxxxp_read_chars(struct sr_serial_dev_inst *serial, |
d7083042 | 120 | int count, char *buf); |
16fc7ee2 | 121 | SR_PRIV int korad_kaxxxxp_set_value(struct sr_serial_dev_inst *serial, |
3f9b48ae FS |
122 | int target, struct dev_context *devc); |
123 | SR_PRIV int korad_kaxxxxp_get_value(struct sr_serial_dev_inst *serial, | |
124 | int target, struct dev_context *devc); | |
16fc7ee2 | 125 | SR_PRIV int korad_kaxxxxp_get_all_values(struct sr_serial_dev_inst *serial, |
d7083042 | 126 | struct dev_context *devc); |
16fc7ee2 | 127 | SR_PRIV int korad_kaxxxxp_receive_data(int fd, int revents, void *cb_data); |
e75ee7de HV |
128 | |
129 | #endif |