]>
Commit | Line | Data |
---|---|---|
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 | ||
20 | /** | |
21 | * @file | |
22 | * Korad KAxxxxP power supply driver | |
23 | * @internal | |
24 | */ | |
25 | ||
26 | #ifndef LIBSIGROK_HARDWARE_KORAD_KAXXXXP_PROTOCOL_H | |
27 | #define LIBSIGROK_HARDWARE_KORAD_KAXXXXP_PROTOCOL_H | |
28 | ||
29 | #include <stdint.h> | |
30 | #include <string.h> | |
31 | #include <glib.h> | |
32 | #include <libsigrok/libsigrok.h> | |
33 | #include "libsigrok-internal.h" | |
34 | ||
35 | #define LOG_PREFIX "korad-kaxxxxp" | |
36 | ||
37 | #define KAXXXXP_POLL_INTERVAL_MS 80 | |
38 | ||
39 | enum { | |
40 | VELLEMAN_PS3005D, | |
41 | VELLEMAN_LABPS3005D, | |
42 | KORAD_KA3005P, | |
43 | KORAD_KA3005P_0X01, | |
44 | /* Support for future devices with this protocol. */ | |
45 | }; | |
46 | ||
47 | /* Information on single model */ | |
48 | struct korad_kaxxxxp_model { | |
49 | int model_id; /**< Model info */ | |
50 | const char *vendor; /**< Vendor name */ | |
51 | const char *name; /**< Model name */ | |
52 | const char *id; /**< Model ID, as delivered by interface */ | |
53 | int channels; /**< Number of channels */ | |
54 | double voltage[3]; /**< Min, max, step */ | |
55 | double current[3]; /**< Min, max, step */ | |
56 | }; | |
57 | ||
58 | /* Reply targets */ | |
59 | enum { | |
60 | KAXXXXP_CURRENT, | |
61 | KAXXXXP_CURRENT_MAX, | |
62 | KAXXXXP_VOLTAGE, | |
63 | KAXXXXP_VOLTAGE_MAX, | |
64 | KAXXXXP_STATUS, | |
65 | KAXXXXP_OUTPUT, | |
66 | KAXXXXP_BEEP, | |
67 | KAXXXXP_OCP, | |
68 | KAXXXXP_OVP, | |
69 | KAXXXXP_SAVE, | |
70 | KAXXXXP_RECALL, | |
71 | }; | |
72 | ||
73 | /** Private, per-device-instance driver context. */ | |
74 | struct dev_context { | |
75 | /* Model-specific information */ | |
76 | const struct korad_kaxxxxp_model *model; /**< Model information. */ | |
77 | ||
78 | /* Acquisition settings */ | |
79 | uint64_t limit_samples; | |
80 | uint64_t limit_msec; | |
81 | uint64_t num_samples; | |
82 | int64_t starttime; | |
83 | int64_t req_sent_at; | |
84 | gboolean reply_pending; | |
85 | ||
86 | void *cb_data; | |
87 | ||
88 | /* Operational state */ | |
89 | float current; /**< Last current value [A] read from device. */ | |
90 | float current_max; /**< Output current set. */ | |
91 | float voltage; /**< Last voltage value [V] read from device. */ | |
92 | float voltage_max; /**< Output voltage set. */ | |
93 | gboolean cc_mode[2]; /**< Device is in CC mode (otherwise CV). */ | |
94 | ||
95 | gboolean output_enabled; /**< Is the output enabled? */ | |
96 | gboolean beep_enabled; /**< Enable beeper. */ | |
97 | gboolean ocp_enabled; /**< Output current protection enabled. */ | |
98 | gboolean ovp_enabled; /**< Output voltage protection enabled. */ | |
99 | ||
100 | /* Temporary state across callbacks */ | |
101 | int target; /**< What reply to expect. */ | |
102 | int program; /**< Program to store or recall. */ | |
103 | char reply[6]; | |
104 | }; | |
105 | ||
106 | SR_PRIV int korad_kaxxxxp_send_cmd(struct sr_serial_dev_inst *serial, | |
107 | const char *cmd); | |
108 | SR_PRIV int korad_kaxxxxp_read_chars(struct sr_serial_dev_inst *serial, | |
109 | int count, char *buf); | |
110 | SR_PRIV int korad_kaxxxxp_set_value(struct sr_serial_dev_inst *serial, | |
111 | struct dev_context *devc); | |
112 | SR_PRIV int korad_kaxxxxp_query_value(struct sr_serial_dev_inst *serial, | |
113 | struct dev_context *devc); | |
114 | SR_PRIV int korad_kaxxxxp_get_reply(struct sr_serial_dev_inst *serial, | |
115 | struct dev_context *devc); | |
116 | SR_PRIV int korad_kaxxxxp_get_all_values(struct sr_serial_dev_inst *serial, | |
117 | struct dev_context *devc); | |
118 | SR_PRIV int korad_kaxxxxp_receive_data(int fd, int revents, void *cb_data); | |
119 | ||
120 | #endif |