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