]>
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 | 33 | |
c7275098 GS |
34 | enum korad_quirks_flag { |
35 | KORAD_QUIRK_NONE = 0, | |
36 | KORAD_QUIRK_LABPS_OVP_EN = 1UL << 0, | |
551024f2 GS |
37 | KORAD_QUIRK_ID_NO_VENDOR = 1UL << 1, |
38 | KORAD_QUIRK_ID_TRAILING = 1UL << 2, | |
39 | KORAD_QUIRK_ALL = (1UL << 3) - 1, | |
c7275098 GS |
40 | }; |
41 | ||
d7083042 | 42 | /* Information on single model */ |
16fc7ee2 | 43 | struct korad_kaxxxxp_model { |
2c240774 UH |
44 | const char *vendor; /**< Vendor name */ |
45 | const char *name; /**< Model name */ | |
46 | const char *id; /**< Model ID, as delivered by interface */ | |
d7083042 | 47 | int channels; /**< Number of channels */ |
ecd4600b GS |
48 | const double *voltage; /**< References: Min, max, step */ |
49 | const double *current; /**< References: Min, max, step */ | |
c7275098 | 50 | enum korad_quirks_flag quirks; |
d7083042 HV |
51 | }; |
52 | ||
53 | /* Reply targets */ | |
54 | enum { | |
16fc7ee2 | 55 | KAXXXXP_CURRENT, |
8da30037 | 56 | KAXXXXP_CURRENT_LIMIT, |
16fc7ee2 | 57 | KAXXXXP_VOLTAGE, |
8da30037 | 58 | KAXXXXP_VOLTAGE_TARGET, |
16fc7ee2 UH |
59 | KAXXXXP_STATUS, |
60 | KAXXXXP_OUTPUT, | |
61 | KAXXXXP_BEEP, | |
62 | KAXXXXP_OCP, | |
63 | KAXXXXP_OVP, | |
64 | KAXXXXP_SAVE, | |
65 | KAXXXXP_RECALL, | |
d7083042 HV |
66 | }; |
67 | ||
e75ee7de | 68 | struct dev_context { |
16fc7ee2 | 69 | const struct korad_kaxxxxp_model *model; /**< Model information. */ |
e75ee7de | 70 | |
597deef9 | 71 | struct sr_sw_limits limits; |
d7083042 | 72 | int64_t req_sent_at; |
3f9b48ae | 73 | GMutex rw_mutex; |
d7083042 | 74 | |
d7083042 | 75 | float current; /**< Last current value [A] read from device. */ |
8da30037 | 76 | float current_limit; /**< Output current set. */ |
d7083042 | 77 | float voltage; /**< Last voltage value [V] read from device. */ |
8da30037 | 78 | float voltage_target; /**< Output voltage set. */ |
d7083042 | 79 | gboolean cc_mode[2]; /**< Device is in CC mode (otherwise CV). */ |
e75ee7de | 80 | |
d7083042 HV |
81 | gboolean output_enabled; /**< Is the output enabled? */ |
82 | gboolean beep_enabled; /**< Enable beeper. */ | |
9e5366df UH |
83 | gboolean ocp_enabled; /**< Output current protection enabled. */ |
84 | gboolean ovp_enabled; /**< Output voltage protection enabled. */ | |
e75ee7de | 85 | |
2e129b8b FS |
86 | gboolean cc_mode_1_changed; /**< CC mode of channel 1 has changed. */ |
87 | gboolean cc_mode_2_changed; /**< CC mode of channel 2 has changed. */ | |
88 | gboolean output_enabled_changed; /**< Output enabled state has changed. */ | |
89 | gboolean ocp_enabled_changed; /**< OCP enabled state has changed. */ | |
90 | gboolean ovp_enabled_changed; /**< OVP enabled state has changed. */ | |
91 | ||
3f9b48ae | 92 | int acquisition_target; /**< What reply to expect. */ |
d7083042 | 93 | int program; /**< Program to store or recall. */ |
8da30037 FS |
94 | |
95 | float set_current_limit; /**< New output current to set. */ | |
96 | float set_voltage_target; /**< New output voltage to set. */ | |
97 | gboolean set_output_enabled; /**< New output enabled to set. */ | |
98 | gboolean set_beep_enabled; /**< New enable beeper to set. */ | |
99 | gboolean set_ocp_enabled; /**< New OCP enabled to set. */ | |
100 | gboolean set_ovp_enabled; /**< New OVP enabled to set. */ | |
e75ee7de HV |
101 | }; |
102 | ||
16fc7ee2 | 103 | SR_PRIV int korad_kaxxxxp_send_cmd(struct sr_serial_dev_inst *serial, |
d7083042 | 104 | const char *cmd); |
16fc7ee2 | 105 | SR_PRIV int korad_kaxxxxp_read_chars(struct sr_serial_dev_inst *serial, |
d2cc60bd | 106 | size_t count, char *buf); |
16fc7ee2 | 107 | SR_PRIV int korad_kaxxxxp_set_value(struct sr_serial_dev_inst *serial, |
3f9b48ae FS |
108 | int target, struct dev_context *devc); |
109 | SR_PRIV int korad_kaxxxxp_get_value(struct sr_serial_dev_inst *serial, | |
110 | int target, struct dev_context *devc); | |
16fc7ee2 | 111 | SR_PRIV int korad_kaxxxxp_get_all_values(struct sr_serial_dev_inst *serial, |
d7083042 | 112 | struct dev_context *devc); |
16fc7ee2 | 113 | SR_PRIV int korad_kaxxxxp_receive_data(int fd, int revents, void *cb_data); |
e75ee7de HV |
114 | |
115 | #endif |