]>
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> | |
22 | #include "protocol.h" | |
23 | ||
d7083042 HV |
24 | #define REQ_TIMEOUT_MS 500 |
25 | #define DEVICE_PROCESSING_TIME_MS 80 | |
26 | ||
16fc7ee2 | 27 | SR_PRIV int korad_kaxxxxp_send_cmd(struct sr_serial_dev_inst *serial, |
d7083042 HV |
28 | const char *cmd) |
29 | { | |
30 | int ret; | |
31 | ||
32 | sr_dbg("Sending '%s'.", cmd); | |
33 | if ((ret = serial_write_blocking(serial, cmd, strlen(cmd), 0)) < 0) { | |
34 | sr_err("Error sending command: %d.", ret); | |
35 | return ret; | |
36 | } | |
37 | ||
38 | return ret; | |
39 | } | |
40 | ||
d2cc60bd GS |
41 | /** |
42 | * Read a variable length non-terminated string (caller specified maximum size). | |
43 | * | |
44 | * @param[in] serial The serial port to read from. | |
45 | * @param[in] count The maximum amount of data to read. | |
46 | * @param[out] buf The buffer to read data into. Must be larger than @a count. | |
47 | * | |
48 | * @return The amount of received data, or negative in case of error. | |
49 | * See @ref SR_ERR and other error codes. | |
50 | * | |
51 | * @internal | |
52 | * | |
53 | * The protocol has no concept of request/response termination. The only | |
54 | * terminating conditions are either the caller's expected maxmimum byte | |
55 | * count, or a period of time without receive data. It's essential to | |
56 | * accept a longer initial period of time before the first receive data | |
57 | * is seen. The supported devices can be very slow to respond. | |
58 | * | |
59 | * The protocol is text based. That's why the 'count' parameter specifies | |
60 | * the expected number of text characters, and does not include the NUL | |
61 | * termination which is not part of the wire protocol but gets added by | |
62 | * the receive routine. The caller provided buffer is expected to have | |
63 | * enough space for the text data and the NUL termination. | |
64 | * | |
65 | * Implementation detail: It's assumed that once receive data was seen, | |
66 | * remaining response data will follow at wire speed. No further delays | |
67 | * are expected beyond bitrate expectations. All normal commands in the | |
68 | * acquisition phase are of fixed length which is known to the caller. | |
69 | * Identification during device scan needs to deal with variable length | |
70 | * data. Quick termination after reception is important there, as is the | |
71 | * larger initial timeout period before receive data is seen. | |
72 | */ | |
16fc7ee2 | 73 | SR_PRIV int korad_kaxxxxp_read_chars(struct sr_serial_dev_inst *serial, |
d2cc60bd | 74 | size_t count, char *buf) |
d7083042 | 75 | { |
d2cc60bd GS |
76 | int timeout_first, timeout_later, timeout; |
77 | size_t retries_first, retries_later, retries; | |
78 | size_t received; | |
79 | int ret; | |
d7083042 | 80 | |
d2cc60bd GS |
81 | /* Clear the buffer early, to simplify the receive code path. */ |
82 | memset(buf, 0, count + 1); | |
d7083042 | 83 | |
d2cc60bd GS |
84 | /* |
85 | * This calculation is aiming for backwards compatibility with | |
86 | * an earlier implementation. An initial timeout is used which | |
87 | * depends on the expected response byte count, and a maximum | |
88 | * iteration count is used for read attempts. | |
89 | * | |
90 | * TODO Consider an absolute initial timeout instead, to reduce | |
91 | * accumulated rounding errors for serial timeout results. The | |
92 | * iteration with a short period is still required for variable | |
93 | * length responses, because otherwise the serial communication | |
94 | * layer would spend the total amount of time waiting for the | |
95 | * remaining bytes, while the device probe code path by design | |
96 | * passes a larger acceptable count than the typical and legal | |
97 | * response would occupy. | |
98 | * | |
99 | * After initial receive data was seen, a shorter timeout is | |
100 | * used which corresponds to a few bytes at wire speed. Idle | |
101 | * periods without receive data longer than this threshold are | |
102 | * taken as the end of the response. This is not compatible to | |
103 | * the previous implementation, but was found to work as well. | |
104 | * And severely reduces the time spent scanning for devices. | |
105 | */ | |
106 | timeout_first = serial_timeout(serial, count); | |
107 | retries_first = 100; | |
108 | timeout_later = serial_timeout(serial, 3); | |
109 | retries_later = 1; | |
110 | ||
111 | sr_spew("want %zu bytes, timeout/retry: init %d/%zu, later %d/%zu.", | |
112 | count, timeout_first, retries_first, | |
113 | timeout_later, retries_later); | |
114 | ||
115 | /* | |
116 | * Run a sequence of read attempts. Try with the larger timeout | |
117 | * and a high retry count until the first receive data became | |
118 | * available. Then continue with a short timeout and small retry | |
119 | * count. | |
120 | * | |
121 | * Failed read is fatal, immediately terminates the read sequence. | |
122 | * A timeout in the initial phase just keeps repeating. A timeout | |
123 | * after receive data was seen regularly terminates the sequence. | |
124 | * Successful reads of non-empty responses keep extending the | |
125 | * read sequence until no more receive data is available. | |
126 | */ | |
127 | received = 0; | |
128 | timeout = timeout_first; | |
129 | retries = retries_first; | |
130 | while (received < count && retries--) { | |
131 | ret = serial_read_blocking(serial, | |
132 | &buf[received], count - received, timeout); | |
133 | if (ret < 0) { | |
134 | sr_err("Error %d reading %zu bytes from device.", | |
d7083042 HV |
135 | ret, count); |
136 | return ret; | |
137 | } | |
d2cc60bd GS |
138 | if (ret == 0 && !received) |
139 | continue; | |
140 | if (ret == 0 && received) { | |
141 | sr_spew("receive timed out, want %zu, received %zu.", | |
142 | count, received); | |
143 | break; | |
144 | } | |
d7083042 | 145 | received += ret; |
d2cc60bd GS |
146 | timeout = timeout_later; |
147 | retries = retries_later; | |
148 | } | |
149 | /* TODO Escape non-printables? Seen those with status queries. */ | |
150 | sr_dbg("got %zu bytes, received: '%s'.", received, buf); | |
d7083042 | 151 | |
d2cc60bd | 152 | return received; |
d7083042 HV |
153 | } |
154 | ||
155 | static void give_device_time_to_process(struct dev_context *devc) | |
156 | { | |
157 | int64_t sleeping_time; | |
158 | ||
159 | sleeping_time = devc->req_sent_at + (DEVICE_PROCESSING_TIME_MS * 1000); | |
160 | sleeping_time -= g_get_monotonic_time(); | |
161 | ||
162 | if (sleeping_time > 0) { | |
163 | g_usleep(sleeping_time); | |
ef2bcf11 | 164 | sr_spew("Sleeping for processing %" PRIi64 " usec", sleeping_time); |
d7083042 HV |
165 | } |
166 | } | |
167 | ||
16fc7ee2 | 168 | SR_PRIV int korad_kaxxxxp_set_value(struct sr_serial_dev_inst *serial, |
3f9b48ae | 169 | int target, struct dev_context *devc) |
d7083042 | 170 | { |
8f39d569 | 171 | char *msg; |
2c240774 | 172 | const char *cmd; |
d7083042 HV |
173 | float value; |
174 | int ret; | |
175 | ||
3f9b48ae | 176 | g_mutex_lock(&devc->rw_mutex); |
d7083042 HV |
177 | give_device_time_to_process(devc); |
178 | ||
3f9b48ae | 179 | switch (target) { |
16fc7ee2 UH |
180 | case KAXXXXP_CURRENT: |
181 | case KAXXXXP_VOLTAGE: | |
182 | case KAXXXXP_STATUS: | |
3f9b48ae FS |
183 | sr_err("Can't set measurable parameter %d.", target); |
184 | g_mutex_unlock(&devc->rw_mutex); | |
d7083042 | 185 | return SR_ERR; |
8da30037 | 186 | case KAXXXXP_CURRENT_LIMIT: |
d7083042 | 187 | cmd = "ISET1:%05.3f"; |
8da30037 | 188 | value = devc->set_current_limit; |
d7083042 | 189 | break; |
8da30037 | 190 | case KAXXXXP_VOLTAGE_TARGET: |
d7083042 | 191 | cmd = "VSET1:%05.2f"; |
8da30037 | 192 | value = devc->set_voltage_target; |
d7083042 | 193 | break; |
16fc7ee2 | 194 | case KAXXXXP_OUTPUT: |
d7083042 | 195 | cmd = "OUT%01.0f"; |
8da30037 FS |
196 | value = (devc->set_output_enabled) ? 1 : 0; |
197 | /* Set value back to recognize changes */ | |
198 | devc->output_enabled = devc->set_output_enabled; | |
d7083042 | 199 | break; |
16fc7ee2 | 200 | case KAXXXXP_BEEP: |
d7083042 | 201 | cmd = "BEEP%01.0f"; |
8da30037 | 202 | value = (devc->set_beep_enabled) ? 1 : 0; |
d7083042 | 203 | break; |
16fc7ee2 | 204 | case KAXXXXP_OCP: |
c40ed60f | 205 | cmd = "OCP%01.0f"; |
8da30037 FS |
206 | value = (devc->set_ocp_enabled) ? 1 : 0; |
207 | /* Set value back to recognize changes */ | |
208 | devc->ocp_enabled = devc->set_ocp_enabled; | |
c40ed60f | 209 | break; |
16fc7ee2 | 210 | case KAXXXXP_OVP: |
c40ed60f | 211 | cmd = "OVP%01.0f"; |
8da30037 FS |
212 | value = (devc->set_ovp_enabled) ? 1 : 0; |
213 | /* Set value back to recognize changes */ | |
214 | devc->ovp_enabled = devc->set_ovp_enabled; | |
c40ed60f | 215 | break; |
16fc7ee2 | 216 | case KAXXXXP_SAVE: |
d7083042 HV |
217 | cmd = "SAV%01.0f"; |
218 | if (devc->program < 1 || devc->program > 5) { | |
219 | sr_err("Only programs 1-5 supported and %d isn't " | |
220 | "between them.", devc->program); | |
3f9b48ae | 221 | g_mutex_unlock(&devc->rw_mutex); |
d7083042 HV |
222 | return SR_ERR; |
223 | } | |
224 | value = devc->program; | |
225 | break; | |
16fc7ee2 | 226 | case KAXXXXP_RECALL: |
d7083042 HV |
227 | cmd = "RCL%01.0f"; |
228 | if (devc->program < 1 || devc->program > 5) { | |
229 | sr_err("Only programs 1-5 supported and %d isn't " | |
230 | "between them.", devc->program); | |
3f9b48ae | 231 | g_mutex_unlock(&devc->rw_mutex); |
d7083042 HV |
232 | return SR_ERR; |
233 | } | |
234 | value = devc->program; | |
235 | break; | |
236 | default: | |
3f9b48ae FS |
237 | sr_err("Don't know how to set %d.", target); |
238 | g_mutex_unlock(&devc->rw_mutex); | |
d7083042 HV |
239 | return SR_ERR; |
240 | } | |
241 | ||
8f39d569 | 242 | msg = g_malloc0(20 + 1); |
d7083042 | 243 | if (cmd) |
8f39d569 | 244 | sr_snprintf_ascii(msg, 20, cmd, value); |
d7083042 | 245 | |
16fc7ee2 | 246 | ret = korad_kaxxxxp_send_cmd(serial, msg); |
d7083042 | 247 | devc->req_sent_at = g_get_monotonic_time(); |
8f39d569 | 248 | g_free(msg); |
3f9b48ae FS |
249 | |
250 | g_mutex_unlock(&devc->rw_mutex); | |
d7083042 HV |
251 | |
252 | return ret; | |
253 | } | |
254 | ||
3f9b48ae FS |
255 | SR_PRIV int korad_kaxxxxp_get_value(struct sr_serial_dev_inst *serial, |
256 | int target, struct dev_context *devc) | |
d7083042 | 257 | { |
3f9b48ae FS |
258 | int ret, count; |
259 | char reply[6]; | |
260 | float *value; | |
261 | char status_byte; | |
2e129b8b | 262 | gboolean prev_status; |
d7083042 | 263 | |
3f9b48ae | 264 | g_mutex_lock(&devc->rw_mutex); |
d7083042 HV |
265 | give_device_time_to_process(devc); |
266 | ||
3f9b48ae FS |
267 | value = NULL; |
268 | count = 5; | |
269 | ||
270 | switch (target) { | |
16fc7ee2 | 271 | case KAXXXXP_CURRENT: |
d7083042 | 272 | /* Read current from device. */ |
16fc7ee2 | 273 | ret = korad_kaxxxxp_send_cmd(serial, "IOUT1?"); |
3f9b48ae | 274 | value = &(devc->current); |
d7083042 | 275 | break; |
8da30037 | 276 | case KAXXXXP_CURRENT_LIMIT: |
d7083042 | 277 | /* Read set current from device. */ |
16fc7ee2 | 278 | ret = korad_kaxxxxp_send_cmd(serial, "ISET1?"); |
8da30037 | 279 | value = &(devc->current_limit); |
d7083042 | 280 | break; |
16fc7ee2 | 281 | case KAXXXXP_VOLTAGE: |
d7083042 | 282 | /* Read voltage from device. */ |
16fc7ee2 | 283 | ret = korad_kaxxxxp_send_cmd(serial, "VOUT1?"); |
3f9b48ae | 284 | value = &(devc->voltage); |
d7083042 | 285 | break; |
8da30037 | 286 | case KAXXXXP_VOLTAGE_TARGET: |
d7083042 | 287 | /* Read set voltage from device. */ |
16fc7ee2 | 288 | ret = korad_kaxxxxp_send_cmd(serial, "VSET1?"); |
8da30037 | 289 | value = &(devc->voltage_target); |
d7083042 | 290 | break; |
16fc7ee2 UH |
291 | case KAXXXXP_STATUS: |
292 | case KAXXXXP_OUTPUT: | |
3f9b48ae FS |
293 | case KAXXXXP_OCP: |
294 | case KAXXXXP_OVP: | |
d7083042 | 295 | /* Read status from device. */ |
16fc7ee2 | 296 | ret = korad_kaxxxxp_send_cmd(serial, "STATUS?"); |
3f9b48ae | 297 | count = 1; |
d7083042 HV |
298 | break; |
299 | default: | |
3f9b48ae FS |
300 | sr_err("Don't know how to query %d.", target); |
301 | g_mutex_unlock(&devc->rw_mutex); | |
d7083042 HV |
302 | return SR_ERR; |
303 | } | |
304 | ||
305 | devc->req_sent_at = g_get_monotonic_time(); | |
d7083042 | 306 | |
3f9b48ae FS |
307 | if ((ret = korad_kaxxxxp_read_chars(serial, count, reply)) < 0) { |
308 | g_mutex_unlock(&devc->rw_mutex); | |
d7083042 | 309 | return ret; |
3f9b48ae | 310 | } |
d7083042 | 311 | |
3f9b48ae | 312 | reply[count] = 0; |
d7083042 | 313 | |
3f9b48ae FS |
314 | if (value) { |
315 | sr_atof_ascii((const char *)&reply, value); | |
316 | sr_dbg("value: %f", *value); | |
d7083042 HV |
317 | } else { |
318 | /* We have status reply. */ | |
3f9b48ae | 319 | status_byte = reply[0]; |
2e129b8b FS |
320 | |
321 | /* Constant current channel one. */ | |
322 | prev_status = devc->cc_mode[0]; | |
323 | devc->cc_mode[0] = !(status_byte & (1 << 0)); | |
324 | devc->cc_mode_1_changed = devc->cc_mode[0] != prev_status; | |
325 | /* Constant current channel two. */ | |
326 | prev_status = devc->cc_mode[1]; | |
327 | devc->cc_mode[1] = !(status_byte & (1 << 1)); | |
328 | devc->cc_mode_2_changed = devc->cc_mode[1] != prev_status; | |
329 | ||
d7083042 | 330 | /* |
2e129b8b | 331 | * Tracking: |
d7083042 HV |
332 | * status_byte & ((1 << 2) | (1 << 3)) |
333 | * 00 independent 01 series 11 parallel | |
334 | */ | |
2e129b8b FS |
335 | devc->beep_enabled = status_byte & (1 << 4); |
336 | ||
337 | /* OCP enabled. */ | |
338 | prev_status = devc->ocp_enabled; | |
339 | devc->ocp_enabled = status_byte & (1 << 5); | |
340 | devc->ocp_enabled_changed = devc->ocp_enabled != prev_status; | |
341 | ||
342 | /* Output status. */ | |
343 | prev_status = devc->output_enabled; | |
344 | devc->output_enabled = status_byte & (1 << 6); | |
345 | devc->output_enabled_changed = devc->output_enabled != prev_status; | |
346 | ||
347 | /* OVP enabled, special handling for Velleman LABPS3005 quirk. */ | |
348 | if ((devc->model->model_id == VELLEMAN_LABPS3005D && devc->output_enabled) || | |
349 | devc->model->model_id != VELLEMAN_LABPS3005D) { | |
350 | ||
351 | prev_status = devc->ovp_enabled; | |
352 | devc->ovp_enabled = status_byte & (1 << 7); | |
353 | devc->ovp_enabled_changed = devc->ovp_enabled != prev_status; | |
354 | } | |
355 | ||
d7083042 | 356 | sr_dbg("Status: 0x%02x", status_byte); |
c40ed60f | 357 | sr_spew("Status: CH1: constant %s CH2: constant %s. " |
253d653d FS |
358 | "Tracking would be %s and %s. Output is %s. " |
359 | "OCP is %s, OVP is %s. Device is %s.", | |
d7083042 HV |
360 | (status_byte & (1 << 0)) ? "voltage" : "current", |
361 | (status_byte & (1 << 1)) ? "voltage" : "current", | |
c40ed60f | 362 | (status_byte & (1 << 2)) ? "parallel" : "series", |
d7083042 | 363 | (status_byte & (1 << 3)) ? "tracking" : "independent", |
c40ed60f | 364 | (status_byte & (1 << 6)) ? "enabled" : "disabled", |
253d653d FS |
365 | (status_byte & (1 << 5)) ? "enabled" : "disabled", |
366 | (status_byte & (1 << 7)) ? "enabled" : "disabled", | |
367 | (status_byte & (1 << 4)) ? "beeping" : "silent"); | |
d7083042 | 368 | } |
3f9b48ae | 369 | |
8abdf006 | 370 | /* Read the sixth byte from ISET? BUG workaround. */ |
8da30037 | 371 | if (target == KAXXXXP_CURRENT_LIMIT) |
8abdf006 | 372 | serial_read_blocking(serial, &status_byte, 1, 10); |
3f9b48ae FS |
373 | |
374 | g_mutex_unlock(&devc->rw_mutex); | |
375 | ||
376 | return ret; | |
377 | } | |
378 | ||
379 | SR_PRIV int korad_kaxxxxp_get_all_values(struct sr_serial_dev_inst *serial, | |
380 | struct dev_context *devc) | |
381 | { | |
382 | int ret, target; | |
383 | ||
384 | for (target = KAXXXXP_CURRENT; | |
385 | target <= KAXXXXP_STATUS; target++) { | |
386 | if ((ret = korad_kaxxxxp_get_value(serial, target, devc)) < 0) | |
387 | return ret; | |
388 | } | |
d7083042 HV |
389 | |
390 | return ret; | |
391 | } | |
392 | ||
393 | static void next_measurement(struct dev_context *devc) | |
394 | { | |
3f9b48ae | 395 | switch (devc->acquisition_target) { |
16fc7ee2 | 396 | case KAXXXXP_CURRENT: |
3f9b48ae | 397 | devc->acquisition_target = KAXXXXP_VOLTAGE; |
d7083042 | 398 | break; |
16fc7ee2 | 399 | case KAXXXXP_VOLTAGE: |
3f9b48ae | 400 | devc->acquisition_target = KAXXXXP_STATUS; |
d7083042 | 401 | break; |
16fc7ee2 | 402 | case KAXXXXP_STATUS: |
3f9b48ae | 403 | devc->acquisition_target = KAXXXXP_CURRENT; |
d7083042 HV |
404 | break; |
405 | default: | |
3f9b48ae FS |
406 | devc->acquisition_target = KAXXXXP_CURRENT; |
407 | sr_err("Invalid target for next acquisition."); | |
d7083042 HV |
408 | } |
409 | } | |
410 | ||
16fc7ee2 | 411 | SR_PRIV int korad_kaxxxxp_receive_data(int fd, int revents, void *cb_data) |
e75ee7de | 412 | { |
d7083042 | 413 | struct sr_dev_inst *sdi; |
e75ee7de | 414 | struct dev_context *devc; |
d7083042 HV |
415 | struct sr_serial_dev_inst *serial; |
416 | struct sr_datafeed_packet packet; | |
2e715341 UH |
417 | struct sr_datafeed_analog analog; |
418 | struct sr_analog_encoding encoding; | |
419 | struct sr_analog_meaning meaning; | |
420 | struct sr_analog_spec spec; | |
23165d7b | 421 | GSList *l; |
e75ee7de HV |
422 | |
423 | (void)fd; | |
a7e48f3c | 424 | (void)revents; |
e75ee7de HV |
425 | |
426 | if (!(sdi = cb_data)) | |
427 | return TRUE; | |
428 | ||
429 | if (!(devc = sdi->priv)) | |
430 | return TRUE; | |
431 | ||
d7083042 HV |
432 | serial = sdi->conn; |
433 | ||
a7e48f3c FS |
434 | /* Get the value. */ |
435 | korad_kaxxxxp_get_value(serial, devc->acquisition_target, devc); | |
436 | ||
437 | /* Note: digits/spec_digits will be overridden later. */ | |
438 | sr_analog_init(&analog, &encoding, &meaning, &spec, 0); | |
439 | ||
440 | /* Send the value forward. */ | |
441 | packet.type = SR_DF_ANALOG; | |
442 | packet.payload = &analog; | |
443 | analog.num_samples = 1; | |
444 | l = g_slist_copy(sdi->channels); | |
445 | if (devc->acquisition_target == KAXXXXP_CURRENT) { | |
446 | l = g_slist_remove_link(l, g_slist_nth(l, 0)); | |
447 | analog.meaning->channels = l; | |
448 | analog.meaning->mq = SR_MQ_CURRENT; | |
449 | analog.meaning->unit = SR_UNIT_AMPERE; | |
d1a3f3be | 450 | analog.meaning->mqflags = SR_MQFLAG_DC; |
a7e48f3c FS |
451 | analog.encoding->digits = 3; |
452 | analog.spec->spec_digits = 3; | |
453 | analog.data = &devc->current; | |
454 | sr_session_send(sdi, &packet); | |
455 | } else if (devc->acquisition_target == KAXXXXP_VOLTAGE) { | |
456 | l = g_slist_remove_link(l, g_slist_nth(l, 1)); | |
457 | analog.meaning->channels = l; | |
458 | analog.meaning->mq = SR_MQ_VOLTAGE; | |
459 | analog.meaning->unit = SR_UNIT_VOLT; | |
460 | analog.meaning->mqflags = SR_MQFLAG_DC; | |
461 | analog.encoding->digits = 2; | |
462 | analog.spec->spec_digits = 2; | |
463 | analog.data = &devc->voltage; | |
464 | sr_session_send(sdi, &packet); | |
465 | sr_sw_limits_update_samples_read(&devc->limits, 1); | |
2e129b8b FS |
466 | } else if (devc->acquisition_target == KAXXXXP_STATUS) { |
467 | if (devc->cc_mode_1_changed) { | |
468 | sr_session_send_meta(sdi, SR_CONF_REGULATION, | |
469 | g_variant_new_string((devc->cc_mode[0]) ? "CC" : "CV")); | |
470 | devc->cc_mode_1_changed = FALSE; | |
471 | } | |
472 | if (devc->cc_mode_2_changed) { | |
473 | sr_session_send_meta(sdi, SR_CONF_REGULATION, | |
474 | g_variant_new_string((devc->cc_mode[1]) ? "CC" : "CV")); | |
475 | devc->cc_mode_2_changed = FALSE; | |
476 | } | |
477 | if (devc->output_enabled_changed) { | |
478 | sr_session_send_meta(sdi, SR_CONF_ENABLED, | |
479 | g_variant_new_boolean(devc->output_enabled)); | |
480 | devc->output_enabled_changed = FALSE; | |
481 | } | |
482 | if (devc->ocp_enabled_changed) { | |
483 | sr_session_send_meta(sdi, SR_CONF_OVER_CURRENT_PROTECTION_ENABLED, | |
484 | g_variant_new_boolean(devc->ocp_enabled)); | |
485 | devc->ocp_enabled_changed = FALSE; | |
486 | } | |
487 | if (devc->ovp_enabled_changed) { | |
488 | sr_session_send_meta(sdi, SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED, | |
489 | g_variant_new_boolean(devc->ovp_enabled)); | |
490 | devc->ovp_enabled_changed = FALSE; | |
491 | } | |
d7083042 | 492 | } |
a7e48f3c | 493 | next_measurement(devc); |
d7083042 | 494 | |
3f9b48ae | 495 | if (sr_sw_limits_check(&devc->limits)) |
d2f7c417 | 496 | sr_dev_acquisition_stop(sdi); |
e75ee7de HV |
497 | |
498 | return TRUE; | |
499 | } |