]>
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 | ||
d7083042 HV |
20 | /** |
21 | * @file | |
22 | * Korad KDxxxxP power supply driver | |
23 | * @internal | |
24 | */ | |
25 | ||
e75ee7de HV |
26 | #ifndef LIBSIGROK_HARDWARE_KORAD_KDXXXXP_PROTOCOL_H |
27 | #define LIBSIGROK_HARDWARE_KORAD_KDXXXXP_PROTOCOL_H | |
28 | ||
29 | #include <stdint.h> | |
d7083042 | 30 | #include <string.h> |
e75ee7de HV |
31 | #include <glib.h> |
32 | #include <libsigrok/libsigrok.h> | |
33 | #include "libsigrok-internal.h" | |
34 | ||
35 | #define LOG_PREFIX "korad-kdxxxxp" | |
36 | ||
d7083042 HV |
37 | #define KDXXXXP_POLL_INTERVAL_MS 80 |
38 | ||
39 | enum { | |
40 | VELLEMAN_LABPS_3005D, | |
41 | /* Support for future devices with this protocol. */ | |
42 | }; | |
43 | ||
44 | /* Information on single model */ | |
45 | struct korad_kdxxxxp_model { | |
46 | int model_id; /**< Model info */ | |
47 | char *vendor; /**< Vendor name */ | |
48 | char *name; /**< Model name */ | |
49 | char *id; /**< Model ID, as delivered by interface */ | |
50 | int channels; /**< Number of channels */ | |
51 | double voltage[3]; /**< Min, max, step */ | |
52 | double current[3]; /**< Min, max, step */ | |
53 | }; | |
54 | ||
55 | /* Reply targets */ | |
56 | enum { | |
57 | KDXXXXP_CURRENT, | |
58 | KDXXXXP_CURRENT_MAX, | |
59 | KDXXXXP_VOLTAGE, | |
60 | KDXXXXP_VOLTAGE_MAX, | |
61 | KDXXXXP_STATUS, | |
62 | KDXXXXP_OUTPUT, | |
63 | KDXXXXP_BEEP, | |
64 | KDXXXXP_SAVE, | |
65 | KDXXXXP_RECALL, | |
66 | }; | |
67 | ||
e75ee7de HV |
68 | /** Private, per-device-instance driver context. */ |
69 | struct dev_context { | |
70 | /* Model-specific information */ | |
d7083042 | 71 | const struct korad_kdxxxxp_model *model; /**< Model information. */ |
e75ee7de HV |
72 | |
73 | /* Acquisition settings */ | |
d7083042 HV |
74 | uint64_t limit_samples; |
75 | uint64_t limit_msec; | |
76 | uint64_t num_samples; | |
77 | int64_t starttime; | |
78 | int64_t req_sent_at; | |
79 | gboolean reply_pending; | |
80 | ||
81 | void *cb_data; | |
e75ee7de HV |
82 | |
83 | /* Operational state */ | |
d7083042 HV |
84 | float current; /**< Last current value [A] read from device. */ |
85 | float current_max; /**< Output current set. */ | |
86 | float voltage; /**< Last voltage value [V] read from device. */ | |
87 | float voltage_max; /**< Output voltage set. */ | |
88 | gboolean cc_mode[2]; /**< Device is in CC mode (otherwise CV). */ | |
e75ee7de | 89 | |
d7083042 HV |
90 | gboolean output_enabled; /**< Is the output enabled? */ |
91 | gboolean beep_enabled; /**< Enable beeper. */ | |
e75ee7de | 92 | |
d7083042 HV |
93 | /* Temporary state across callbacks */ |
94 | int target; /**< What reply to expect */ | |
95 | int program; /**< Program to store or recall. */ | |
96 | char reply[6]; | |
e75ee7de HV |
97 | }; |
98 | ||
d7083042 HV |
99 | SR_PRIV int korad_kdxxxxp_send_cmd(struct sr_serial_dev_inst *serial, |
100 | const char *cmd); | |
101 | SR_PRIV int korad_kdxxxxp_read_chars(struct sr_serial_dev_inst *serial, | |
102 | int count, char *buf); | |
103 | SR_PRIV int korad_kdxxxxp_set_value(struct sr_serial_dev_inst *serial, | |
104 | struct dev_context *devc); | |
105 | SR_PRIV int korad_kdxxxxp_query_value(struct sr_serial_dev_inst *serial, | |
106 | struct dev_context *devc); | |
107 | SR_PRIV int korad_kdxxxxp_get_reply(struct sr_serial_dev_inst *serial, | |
108 | struct dev_context *devc); | |
109 | SR_PRIV int korad_kdxxxxp_get_all_values(struct sr_serial_dev_inst *serial, | |
110 | struct dev_context *devc); | |
e75ee7de HV |
111 | SR_PRIV int korad_kdxxxxp_receive_data(int fd, int revents, void *cb_data); |
112 | ||
113 | #endif |