]>
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 | ||
21 | #include <config.h> | |
349803b6 GS |
22 | |
23 | #include <ctype.h> | |
24 | ||
e75ee7de HV |
25 | #include "protocol.h" |
26 | ||
d7083042 HV |
27 | static const uint32_t scanopts[] = { |
28 | SR_CONF_CONN, | |
29 | SR_CONF_SERIALCOMM, | |
e37e301e | 30 | SR_CONF_FORCE_DETECT, |
d7083042 HV |
31 | }; |
32 | ||
55fb76b3 | 33 | static const uint32_t drvopts[] = { |
55fb76b3 UH |
34 | SR_CONF_POWER_SUPPLY, |
35 | }; | |
36 | ||
d7083042 | 37 | static const uint32_t devopts[] = { |
048250d0 | 38 | SR_CONF_CONN | SR_CONF_GET, |
d7083042 HV |
39 | SR_CONF_CONTINUOUS, |
40 | SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, | |
41 | SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET, | |
d7083042 HV |
42 | SR_CONF_VOLTAGE | SR_CONF_GET, |
43 | SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
44 | SR_CONF_CURRENT | SR_CONF_GET, | |
45 | SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
46 | SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET, | |
b16d975a | 47 | SR_CONF_REGULATION | SR_CONF_GET, |
c40ed60f HV |
48 | SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET, |
49 | SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET, | |
d7083042 HV |
50 | }; |
51 | ||
ecd4600b GS |
52 | /* Voltage and current ranges. Values are: Min, max, step. */ |
53 | static const double volts_30[] = { 0, 31, 0.01, }; | |
54 | static const double volts_60[] = { 0, 61, 0.01, }; | |
55 | static const double amps_3[] = { 0, 3.1, 0.001, }; | |
56 | static const double amps_5[] = { 0, 5.1, 0.001, }; | |
57 | ||
16fc7ee2 | 58 | static const struct korad_kaxxxxp_model models[] = { |
c55adfa1 | 59 | /* Vendor, model name, ID reply, channels, voltage, current, quirks. */ |
d241cc20 GS |
60 | {"Korad", "KA3005P", "", 1, volts_30, amps_5, |
61 | KORAD_QUIRK_ID_TRAILING}, | |
62 | {"Korad", "KD3005P", "", 1, volts_30, amps_5, 0}, | |
63 | {"Korad", "KD6005P", "", 1, volts_60, amps_5, 0}, | |
64 | {"RND", "320-KA3005P", "", 1, volts_30, amps_5, 0}, | |
65 | {"RND", "320-KD3005P", "", 1, volts_30, amps_5, 0}, | |
66 | {"Stamos Soldering", "S-LS-31", "", 1, volts_30, amps_5, | |
67 | KORAD_QUIRK_ID_NO_VENDOR}, | |
68 | {"Tenma", "72-2535", "", 1, volts_30, amps_3, 0}, | |
69 | {"Tenma", "72-2540", "", 1, volts_30, amps_5, 0}, | |
70 | {"Tenma", "72-2550", "", 1, volts_60, amps_3, 0}, | |
71 | {"Tenma", "72-2710", "", 1, volts_30, amps_5, 0}, | |
72 | {"Velleman", "LABPS3005D", "", 1, volts_30, amps_5, | |
73 | KORAD_QUIRK_LABPS_OVP_EN}, | |
74 | {"Velleman", "PS3005D", "", 1, volts_30, amps_5, 0}, | |
9e9dba7b | 75 | ALL_ZERO |
d7083042 HV |
76 | }; |
77 | ||
551024f2 GS |
78 | /* |
79 | * Bump this when adding new models[] above. Make sure the text buffer | |
80 | * for the ID response can hold the longest sequence that we expect in | |
81 | * the field which consists of: vendor + model [ + version ][ + serno ]. | |
82 | * Don't be too generous here, the maximum receive buffer size affects | |
83 | * the timeout within which the first response character is expected. | |
84 | */ | |
85 | static const size_t id_text_buffer_size = 48; | |
86 | ||
87 | /* | |
88 | * Check whether the device's "*IDN?" response matches a supported model. | |
89 | * The caller already stripped off the optional serial number. | |
90 | */ | |
91 | static gboolean model_matches(const struct korad_kaxxxxp_model *model, | |
92 | const char *id_text) | |
93 | { | |
349803b6 | 94 | gboolean matches; |
0f96d9bc | 95 | gboolean opt_version, skip_vendor, accept_trail; |
349803b6 GS |
96 | const char *want; |
97 | ||
98 | if (!model) | |
99 | return FALSE; | |
100 | ||
101 | /* | |
102 | * When the models[] entry contains a specific response text, | |
103 | * then expect to see this very text in literal form. This | |
104 | * lets the driver map weird and untypical responses to a | |
105 | * specific set of display texts for vendor and model names. | |
0f96d9bc | 106 | * Accept an optionally trailing version if models[] says so. |
349803b6 GS |
107 | */ |
108 | if (model->id && model->id[0]) { | |
0f96d9bc GS |
109 | opt_version = model->quirks & KORAD_QUIRK_ID_OPT_VERSION; |
110 | if (!opt_version) { | |
111 | matches = g_strcmp0(id_text, model->id) == 0; | |
112 | if (!matches) | |
113 | return FALSE; | |
349803b6 | 114 | sr_dbg("Matches expected ID text: '%s'.", model->id); |
0f96d9bc GS |
115 | return TRUE; |
116 | } | |
117 | matches = g_str_has_prefix(id_text, model->id); | |
118 | if (!matches) | |
119 | return FALSE; | |
120 | id_text += strlen(model->id); | |
121 | while (isspace((int)*id_text)) | |
122 | id_text++; | |
123 | if (*id_text == 'V') { | |
124 | id_text++; | |
125 | while (*id_text == '.' || isdigit((int)*id_text)) | |
126 | id_text++; | |
127 | while (isspace((int)*id_text)) | |
128 | id_text++; | |
129 | } | |
130 | if (*id_text) | |
131 | return FALSE; | |
132 | sr_dbg("Matches expected ID text [vers]: '%s'.", model->id); | |
133 | return TRUE; | |
349803b6 GS |
134 | } |
135 | ||
136 | /* | |
137 | * A more generic approach which covers most devices: Check | |
138 | * for the very vendor and model names which also are shown | |
139 | * to users (the display texts). Weakened to match responses | |
140 | * more widely: Case insensitive checks, optional whitespace | |
141 | * in responses, optional version details. Optional trailing | |
142 | * garbage. Optional omission of the vendor name. Shall match | |
143 | * all the devices which were individually listed in earlier | |
144 | * implementations of the driver, and shall also match firmware | |
145 | * versions that were not listed before. | |
146 | */ | |
147 | skip_vendor = model->quirks & KORAD_QUIRK_ID_NO_VENDOR; | |
148 | accept_trail = model->quirks & KORAD_QUIRK_ID_TRAILING; | |
149 | if (!skip_vendor) { | |
150 | want = model->vendor; | |
151 | matches = g_ascii_strncasecmp(id_text, want, strlen(want)) == 0; | |
152 | if (!matches) | |
153 | return FALSE; | |
154 | id_text += strlen(want); | |
155 | while (isspace((int)*id_text)) | |
156 | id_text++; | |
157 | } | |
158 | want = model->name; | |
159 | matches = g_ascii_strncasecmp(id_text, want, strlen(want)) == 0; | |
160 | if (!matches) | |
161 | return FALSE; | |
162 | id_text += strlen(want); | |
163 | while (isspace((int)*id_text)) | |
164 | id_text++; | |
165 | if (*id_text == 'V') { | |
166 | /* TODO Isolate and (also) return version details? */ | |
167 | id_text++; | |
168 | while (*id_text == '.' || isdigit((int)*id_text)) | |
169 | id_text++; | |
170 | while (isspace((int)*id_text)) | |
171 | id_text++; | |
172 | } | |
173 | if (accept_trail) { | |
174 | /* | |
175 | * TODO Determine how many non-printables to accept here | |
176 | * and how strict to check for "known" garbage variants. | |
177 | */ | |
178 | switch (*id_text) { | |
179 | case '\x01': | |
180 | case '\xbc': | |
181 | id_text++; | |
182 | break; | |
183 | case '\x00': | |
184 | /* EMPTY */ | |
185 | break; | |
186 | default: | |
187 | return FALSE; | |
188 | } | |
189 | } | |
190 | if (*id_text) | |
191 | return FALSE; | |
192 | sr_dbg("Matches generic '[vendor] model [vers] [trail]' pattern."); | |
193 | return TRUE; | |
551024f2 GS |
194 | } |
195 | ||
e75ee7de HV |
196 | static GSList *scan(struct sr_dev_driver *di, GSList *options) |
197 | { | |
fcacf532 GS |
198 | static const char *serno_prefix = " SN:"; |
199 | ||
d7083042 | 200 | struct dev_context *devc; |
43376f33 | 201 | GSList *l; |
d7083042 HV |
202 | struct sr_dev_inst *sdi; |
203 | struct sr_config *src; | |
204 | const char *conn, *serialcomm; | |
e37e301e | 205 | const char *force_detect; |
d7083042 | 206 | struct sr_serial_dev_inst *serial; |
5255f856 | 207 | size_t i; |
d7083042 | 208 | char reply[50]; |
5255f856 GS |
209 | int ret; |
210 | const struct korad_kaxxxxp_model *model; | |
fcacf532 GS |
211 | size_t len; |
212 | char *serno; | |
e75ee7de | 213 | |
d7083042 HV |
214 | conn = NULL; |
215 | serialcomm = NULL; | |
e37e301e | 216 | force_detect = NULL; |
e75ee7de | 217 | |
d7083042 HV |
218 | for (l = options; l; l = l->next) { |
219 | src = l->data; | |
220 | switch (src->key) { | |
221 | case SR_CONF_CONN: | |
222 | conn = g_variant_get_string(src->data, NULL); | |
223 | break; | |
224 | case SR_CONF_SERIALCOMM: | |
225 | serialcomm = g_variant_get_string(src->data, NULL); | |
226 | break; | |
e37e301e GS |
227 | case SR_CONF_FORCE_DETECT: |
228 | force_detect = g_variant_get_string(src->data, NULL); | |
229 | break; | |
d7083042 HV |
230 | default: |
231 | sr_err("Unknown option %d, skipping.", src->key); | |
232 | break; | |
233 | } | |
234 | } | |
235 | ||
236 | if (!conn) | |
237 | return NULL; | |
238 | if (!serialcomm) | |
239 | serialcomm = "9600/8n1"; | |
e37e301e GS |
240 | if (force_detect && !*force_detect) |
241 | force_detect = NULL; | |
d7083042 HV |
242 | |
243 | serial = sr_serial_dev_inst_new(conn, serialcomm); | |
244 | if (serial_open(serial, SERIAL_RDWR) != SR_OK) | |
245 | return NULL; | |
246 | ||
551024f2 GS |
247 | /* Communicate the identification request. */ |
248 | len = id_text_buffer_size; | |
fcacf532 GS |
249 | if (len > sizeof(reply) - 1) |
250 | len = sizeof(reply) - 1; | |
251 | sr_dbg("Want max %zu bytes.", len); | |
cf6beeb2 | 252 | |
fcacf532 GS |
253 | ret = korad_kaxxxxp_send_cmd(serial, "*IDN?"); |
254 | if (ret < 0) | |
d7083042 HV |
255 | return NULL; |
256 | ||
fcacf532 GS |
257 | ret = korad_kaxxxxp_read_chars(serial, len, reply); |
258 | if (ret < 0) | |
d7083042 | 259 | return NULL; |
fcacf532 | 260 | sr_dbg("Received: %d, %s", ret, reply); |
cf6beeb2 | 261 | |
fcacf532 GS |
262 | /* |
263 | * Isolate the optional serial number at the response's end. | |
264 | * Lookup the response's model ID in the list of known models. | |
265 | */ | |
266 | serno = g_strrstr(reply, serno_prefix); | |
267 | if (serno) { | |
268 | *serno = '\0'; | |
269 | serno += strlen(serno_prefix); | |
270 | } | |
cf6beeb2 | 271 | |
5255f856 | 272 | model = NULL; |
349803b6 | 273 | for (i = 0; models[i].name; i++) { |
551024f2 | 274 | if (!model_matches(&models[i], reply)) |
fcacf532 | 275 | continue; |
5255f856 | 276 | model = &models[i]; |
fcacf532 | 277 | break; |
d7083042 | 278 | } |
5255f856 | 279 | if (!model && force_detect) { |
349803b6 | 280 | sr_warn("Found unknown model ID '%s', trying '%s' spec.", |
e37e301e | 281 | reply, force_detect); |
349803b6 | 282 | for (i = 0; models[i].name; i++) { |
551024f2 | 283 | if (!model_matches(&models[i], force_detect)) |
e37e301e GS |
284 | continue; |
285 | sr_info("Found replacement, using it instead."); | |
5255f856 | 286 | model = &models[i]; |
e37e301e GS |
287 | break; |
288 | } | |
289 | } | |
5255f856 | 290 | if (!model) { |
349803b6 | 291 | sr_err("Found unknown model ID '%s', aborting.", reply); |
d7083042 HV |
292 | return NULL; |
293 | } | |
349803b6 GS |
294 | sr_dbg("Found: %s %s (idx %zu).", model->vendor, model->name, |
295 | model - &models[0]); | |
d7083042 | 296 | |
d7083042 HV |
297 | sdi = g_malloc0(sizeof(struct sr_dev_inst)); |
298 | sdi->status = SR_ST_INACTIVE; | |
5255f856 GS |
299 | sdi->vendor = g_strdup(model->vendor); |
300 | sdi->model = g_strdup(model->name); | |
fcacf532 GS |
301 | if (serno) |
302 | sdi->serial_num = g_strdup(serno); | |
d7083042 HV |
303 | sdi->inst_type = SR_INST_SERIAL; |
304 | sdi->conn = serial; | |
048250d0 | 305 | sdi->connection_id = g_strdup(conn); |
d7083042 | 306 | |
23165d7b FS |
307 | sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "V"); |
308 | sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "I"); | |
d7083042 HV |
309 | |
310 | devc = g_malloc0(sizeof(struct dev_context)); | |
597deef9 | 311 | sr_sw_limits_init(&devc->limits); |
3f9b48ae | 312 | g_mutex_init(&devc->rw_mutex); |
5255f856 | 313 | devc->model = model; |
d7083042 | 314 | devc->req_sent_at = 0; |
2e129b8b FS |
315 | devc->cc_mode_1_changed = FALSE; |
316 | devc->cc_mode_2_changed = FALSE; | |
317 | devc->output_enabled_changed = FALSE; | |
318 | devc->ocp_enabled_changed = FALSE; | |
319 | devc->ovp_enabled_changed = FALSE; | |
d7083042 HV |
320 | sdi->priv = devc; |
321 | ||
322 | /* Get current status of device. */ | |
16fc7ee2 | 323 | if (korad_kaxxxxp_get_all_values(serial, devc) < 0) |
d7083042 | 324 | goto exit_err; |
d7083042 HV |
325 | |
326 | serial_close(serial); | |
e75ee7de | 327 | |
43376f33 | 328 | return std_scan_complete(di, g_slist_append(NULL, sdi)); |
d7083042 HV |
329 | |
330 | exit_err: | |
331 | sr_dev_inst_free(sdi); | |
332 | g_free(devc); | |
333 | sr_dbg("Scan failed."); | |
334 | ||
335 | return NULL; | |
e75ee7de HV |
336 | } |
337 | ||
e75ee7de HV |
338 | static int config_get(uint32_t key, GVariant **data, |
339 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
340 | { | |
d7083042 | 341 | struct dev_context *devc; |
e75ee7de | 342 | |
e75ee7de HV |
343 | (void)cg; |
344 | ||
d7083042 HV |
345 | if (!sdi || !data) |
346 | return SR_ERR_ARG; | |
347 | ||
348 | devc = sdi->priv; | |
349 | ||
e75ee7de | 350 | switch (key) { |
cd04f641 UH |
351 | case SR_CONF_LIMIT_SAMPLES: |
352 | case SR_CONF_LIMIT_MSEC: | |
597deef9 | 353 | return sr_sw_limits_config_get(&devc->limits, key, data); |
048250d0 GS |
354 | case SR_CONF_CONN: |
355 | *data = g_variant_new_string(sdi->connection_id); | |
356 | break; | |
d7083042 | 357 | case SR_CONF_VOLTAGE: |
3f9b48ae | 358 | korad_kaxxxxp_get_value(sdi->conn, KAXXXXP_VOLTAGE, devc); |
d7083042 HV |
359 | *data = g_variant_new_double(devc->voltage); |
360 | break; | |
361 | case SR_CONF_VOLTAGE_TARGET: | |
8da30037 FS |
362 | korad_kaxxxxp_get_value(sdi->conn, KAXXXXP_VOLTAGE_TARGET, devc); |
363 | *data = g_variant_new_double(devc->voltage_target); | |
d7083042 HV |
364 | break; |
365 | case SR_CONF_CURRENT: | |
3f9b48ae | 366 | korad_kaxxxxp_get_value(sdi->conn, KAXXXXP_CURRENT, devc); |
d7083042 HV |
367 | *data = g_variant_new_double(devc->current); |
368 | break; | |
369 | case SR_CONF_CURRENT_LIMIT: | |
8da30037 FS |
370 | korad_kaxxxxp_get_value(sdi->conn, KAXXXXP_CURRENT_LIMIT, devc); |
371 | *data = g_variant_new_double(devc->current_limit); | |
d7083042 HV |
372 | break; |
373 | case SR_CONF_ENABLED: | |
3f9b48ae | 374 | korad_kaxxxxp_get_value(sdi->conn, KAXXXXP_OUTPUT, devc); |
d7083042 HV |
375 | *data = g_variant_new_boolean(devc->output_enabled); |
376 | break; | |
b16d975a HV |
377 | case SR_CONF_REGULATION: |
378 | /* Dual channel not supported. */ | |
3f9b48ae | 379 | korad_kaxxxxp_get_value(sdi->conn, KAXXXXP_STATUS, devc); |
9e5366df | 380 | *data = g_variant_new_string((devc->cc_mode[0]) ? "CC" : "CV"); |
b16d975a | 381 | break; |
c40ed60f | 382 | case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: |
3f9b48ae | 383 | korad_kaxxxxp_get_value(sdi->conn, KAXXXXP_OCP, devc); |
9e5366df | 384 | *data = g_variant_new_boolean(devc->ocp_enabled); |
c40ed60f HV |
385 | break; |
386 | case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: | |
3f9b48ae | 387 | korad_kaxxxxp_get_value(sdi->conn, KAXXXXP_OVP, devc); |
9e5366df | 388 | *data = g_variant_new_boolean(devc->ovp_enabled); |
c40ed60f | 389 | break; |
e75ee7de HV |
390 | default: |
391 | return SR_ERR_NA; | |
392 | } | |
393 | ||
d7083042 | 394 | return SR_OK; |
e75ee7de HV |
395 | } |
396 | ||
397 | static int config_set(uint32_t key, GVariant *data, | |
398 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
399 | { | |
d7083042 HV |
400 | struct dev_context *devc; |
401 | double dval; | |
402 | gboolean bval; | |
e75ee7de | 403 | |
e75ee7de HV |
404 | (void)cg; |
405 | ||
d7083042 HV |
406 | devc = sdi->priv; |
407 | ||
e75ee7de | 408 | switch (key) { |
d7083042 | 409 | case SR_CONF_LIMIT_MSEC: |
d7083042 | 410 | case SR_CONF_LIMIT_SAMPLES: |
597deef9 | 411 | return sr_sw_limits_config_set(&devc->limits, key, data); |
d7083042 HV |
412 | case SR_CONF_VOLTAGE_TARGET: |
413 | dval = g_variant_get_double(data); | |
414 | if (dval < devc->model->voltage[0] || dval > devc->model->voltage[1]) | |
415 | return SR_ERR_ARG; | |
8da30037 FS |
416 | devc->set_voltage_target = dval; |
417 | if (korad_kaxxxxp_set_value(sdi->conn, KAXXXXP_VOLTAGE_TARGET, devc) < 0) | |
d7083042 HV |
418 | return SR_ERR; |
419 | break; | |
420 | case SR_CONF_CURRENT_LIMIT: | |
421 | dval = g_variant_get_double(data); | |
422 | if (dval < devc->model->current[0] || dval > devc->model->current[1]) | |
423 | return SR_ERR_ARG; | |
8da30037 FS |
424 | devc->set_current_limit = dval; |
425 | if (korad_kaxxxxp_set_value(sdi->conn, KAXXXXP_CURRENT_LIMIT, devc) < 0) | |
d7083042 HV |
426 | return SR_ERR; |
427 | break; | |
428 | case SR_CONF_ENABLED: | |
429 | bval = g_variant_get_boolean(data); | |
430 | /* Set always so it is possible turn off with sigrok-cli. */ | |
8da30037 | 431 | devc->set_output_enabled = bval; |
3f9b48ae | 432 | if (korad_kaxxxxp_set_value(sdi->conn, KAXXXXP_OUTPUT, devc) < 0) |
d7083042 | 433 | return SR_ERR; |
c40ed60f HV |
434 | break; |
435 | case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: | |
436 | bval = g_variant_get_boolean(data); | |
8da30037 | 437 | devc->set_ocp_enabled = bval; |
3f9b48ae | 438 | if (korad_kaxxxxp_set_value(sdi->conn, KAXXXXP_OCP, devc) < 0) |
c40ed60f HV |
439 | return SR_ERR; |
440 | break; | |
441 | case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: | |
442 | bval = g_variant_get_boolean(data); | |
8da30037 | 443 | devc->set_ovp_enabled = bval; |
3f9b48ae | 444 | if (korad_kaxxxxp_set_value(sdi->conn, KAXXXXP_OVP, devc) < 0) |
c40ed60f | 445 | return SR_ERR; |
d7083042 | 446 | break; |
e75ee7de | 447 | default: |
d7083042 | 448 | return SR_ERR_NA; |
e75ee7de HV |
449 | } |
450 | ||
d7083042 | 451 | return SR_OK; |
e75ee7de HV |
452 | } |
453 | ||
454 | static int config_list(uint32_t key, GVariant **data, | |
455 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
456 | { | |
d7083042 | 457 | struct dev_context *devc; |
d7083042 | 458 | |
e66d1892 | 459 | devc = (sdi) ? sdi->priv : NULL; |
d7083042 | 460 | |
e75ee7de | 461 | switch (key) { |
e66d1892 | 462 | case SR_CONF_SCAN_OPTIONS: |
d7083042 | 463 | case SR_CONF_DEVICE_OPTIONS: |
e66d1892 | 464 | return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts); |
d7083042 | 465 | case SR_CONF_VOLTAGE_TARGET: |
fc69eecc GS |
466 | if (!devc || !devc->model) |
467 | return SR_ERR_ARG; | |
54d471f4 | 468 | *data = std_gvar_min_max_step_array(devc->model->voltage); |
d7083042 HV |
469 | break; |
470 | case SR_CONF_CURRENT_LIMIT: | |
fc69eecc GS |
471 | if (!devc || !devc->model) |
472 | return SR_ERR_ARG; | |
54d471f4 | 473 | *data = std_gvar_min_max_step_array(devc->model->current); |
d7083042 | 474 | break; |
e75ee7de HV |
475 | default: |
476 | return SR_ERR_NA; | |
477 | } | |
478 | ||
d7083042 | 479 | return SR_OK; |
e75ee7de HV |
480 | } |
481 | ||
3f9b48ae FS |
482 | static int dev_close(struct sr_dev_inst *sdi) |
483 | { | |
484 | struct dev_context *devc; | |
485 | ||
486 | devc = (sdi) ? sdi->priv : NULL; | |
487 | if (devc) | |
488 | g_mutex_clear(&devc->rw_mutex); | |
489 | ||
490 | return std_serial_dev_close(sdi); | |
491 | } | |
492 | ||
695dc859 | 493 | static int dev_acquisition_start(const struct sr_dev_inst *sdi) |
e75ee7de | 494 | { |
d7083042 HV |
495 | struct dev_context *devc; |
496 | struct sr_serial_dev_inst *serial; | |
e75ee7de | 497 | |
d7083042 | 498 | devc = sdi->priv; |
d7083042 | 499 | |
597deef9 | 500 | sr_sw_limits_acquisition_start(&devc->limits); |
bee2b016 | 501 | std_session_send_df_header(sdi); |
d7083042 | 502 | |
d7083042 HV |
503 | devc->req_sent_at = 0; |
504 | serial = sdi->conn; | |
505 | serial_source_add(sdi->session, serial, G_IO_IN, | |
16fc7ee2 UH |
506 | KAXXXXP_POLL_INTERVAL_MS, |
507 | korad_kaxxxxp_receive_data, (void *)sdi); | |
e75ee7de HV |
508 | |
509 | return SR_OK; | |
510 | } | |
511 | ||
dd5c48a6 | 512 | static struct sr_dev_driver korad_kaxxxxp_driver_info = { |
16fc7ee2 UH |
513 | .name = "korad-kaxxxxp", |
514 | .longname = "Korad KAxxxxP", | |
e75ee7de | 515 | .api_version = 1, |
c2fdcc25 | 516 | .init = std_init, |
700d6b64 | 517 | .cleanup = std_cleanup, |
e75ee7de | 518 | .scan = scan, |
c01bf34c | 519 | .dev_list = std_dev_list, |
f778bf02 | 520 | .dev_clear = std_dev_clear, |
e75ee7de HV |
521 | .config_get = config_get, |
522 | .config_set = config_set, | |
523 | .config_list = config_list, | |
d7083042 | 524 | .dev_open = std_serial_dev_open, |
3f9b48ae | 525 | .dev_close = dev_close, |
e75ee7de | 526 | .dev_acquisition_start = dev_acquisition_start, |
4b1a9d5d | 527 | .dev_acquisition_stop = std_serial_dev_acquisition_stop, |
e75ee7de HV |
528 | .context = NULL, |
529 | }; | |
dd5c48a6 | 530 | SR_REGISTER_DEV_DRIVER(korad_kaxxxxp_driver_info); |