]>
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> | |
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 | ||
16fc7ee2 UH |
20 | #ifndef LIBSIGROK_HARDWARE_KORAD_KAXXXXP_PROTOCOL_H |
21 | #define LIBSIGROK_HARDWARE_KORAD_KAXXXXP_PROTOCOL_H | |
e75ee7de HV |
22 | |
23 | #include <stdint.h> | |
d7083042 | 24 | #include <string.h> |
e75ee7de HV |
25 | #include <glib.h> |
26 | #include <libsigrok/libsigrok.h> | |
27 | #include "libsigrok-internal.h" | |
28 | ||
16fc7ee2 | 29 | #define LOG_PREFIX "korad-kaxxxxp" |
e75ee7de | 30 | |
16fc7ee2 | 31 | #define KAXXXXP_POLL_INTERVAL_MS 80 |
d7083042 HV |
32 | |
33 | enum { | |
ae9ca5b1 UH |
34 | VELLEMAN_PS3005D, |
35 | VELLEMAN_LABPS3005D, | |
bcf9384d | 36 | KORAD_KA3005P, |
a078d3ec | 37 | KORAD_KA3005P_0X01, |
41802ca4 | 38 | KORAD_KD3005P, |
d7083042 HV |
39 | /* Support for future devices with this protocol. */ |
40 | }; | |
41 | ||
42 | /* Information on single model */ | |
16fc7ee2 | 43 | struct korad_kaxxxxp_model { |
d7083042 | 44 | int model_id; /**< Model info */ |
2c240774 UH |
45 | const char *vendor; /**< Vendor name */ |
46 | const char *name; /**< Model name */ | |
47 | const char *id; /**< Model ID, as delivered by interface */ | |
d7083042 HV |
48 | int channels; /**< Number of channels */ |
49 | double voltage[3]; /**< Min, max, step */ | |
50 | double current[3]; /**< Min, max, step */ | |
51 | }; | |
52 | ||
53 | /* Reply targets */ | |
54 | enum { | |
16fc7ee2 UH |
55 | KAXXXXP_CURRENT, |
56 | KAXXXXP_CURRENT_MAX, | |
57 | KAXXXXP_VOLTAGE, | |
58 | KAXXXXP_VOLTAGE_MAX, | |
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 HV |
72 | int64_t req_sent_at; |
73 | gboolean reply_pending; | |
74 | ||
d7083042 HV |
75 | float current; /**< Last current value [A] read from device. */ |
76 | float current_max; /**< Output current set. */ | |
77 | float voltage; /**< Last voltage value [V] read from device. */ | |
78 | float voltage_max; /**< Output voltage set. */ | |
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 | |
9e5366df | 86 | int target; /**< What reply to expect. */ |
d7083042 HV |
87 | int program; /**< Program to store or recall. */ |
88 | char reply[6]; | |
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, |
d7083042 | 96 | struct dev_context *devc); |
16fc7ee2 | 97 | SR_PRIV int korad_kaxxxxp_query_value(struct sr_serial_dev_inst *serial, |
d7083042 | 98 | struct dev_context *devc); |
16fc7ee2 | 99 | SR_PRIV int korad_kaxxxxp_get_reply(struct sr_serial_dev_inst *serial, |
d7083042 | 100 | struct dev_context *devc); |
16fc7ee2 | 101 | SR_PRIV int korad_kaxxxxp_get_all_values(struct sr_serial_dev_inst *serial, |
d7083042 | 102 | struct dev_context *devc); |
16fc7ee2 | 103 | SR_PRIV int korad_kaxxxxp_receive_data(int fd, int revents, void *cb_data); |
e75ee7de HV |
104 | |
105 | #endif |