Skip to content

Commit 0f63fbe

Browse files
committed
korad-kaxxxxp: add quirk for long processing times of commands
Some Korad compatibles are said to take rather long a time between reception of adjacent commands. It's not just that the response is delayed, or that execution takes a long time. It's worse in that the next request isn't received, and later responses don't correspond to the requests which host software associates them with. A driver implementation detail then "reads" 0.000 current values when the PSU failed to respond to the "IOUT?" request. Add a quirk flag. Allow for extra processing time after SET commands and the GET command for STATUS. Add the Velleman PS3005D V1.3 model with this quirk. Behaviour does not change for other devices. This implementation is based on a submission that was provided by Pilatomic <[email protected]>.
1 parent 81609a7 commit 0f63fbe

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

src/hardware/korad-kaxxxxp/api.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ static const struct korad_kaxxxxp_model models[] = {
7474
{"Tenma", "72-2710", "", 1, volts_30, amps_5, 0},
7575
{"Velleman", "LABPS3005D", "", 1, volts_30, amps_5,
7676
KORAD_QUIRK_LABPS_OVP_EN},
77+
{"Velleman", "PS3005D V1.3", "VELLEMANPS3005DV1.3" , 1, volts_30, amps_5,
78+
KORAD_QUIRK_ID_TRAILING | KORAD_QUIRK_SLOW_PROCESSING},
7779
{"Velleman", "PS3005D", "", 1, volts_30, amps_5, 0},
7880
ALL_ZERO
7981
};
@@ -327,7 +329,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
327329
sr_sw_limits_init(&devc->limits);
328330
g_mutex_init(&devc->rw_mutex);
329331
devc->model = model;
330-
devc->req_sent_at = 0;
332+
devc->next_req_time = 0;
331333
devc->cc_mode_1_changed = FALSE;
332334
devc->cc_mode_2_changed = FALSE;
333335
devc->output_enabled_changed = FALSE;
@@ -516,7 +518,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
516518
sr_sw_limits_acquisition_start(&devc->limits);
517519
std_session_send_df_header(sdi);
518520

519-
devc->req_sent_at = 0;
521+
devc->next_req_time = 0;
520522
serial = sdi->conn;
521523
serial_source_add(sdi->session, serial, G_IO_IN,
522524
KAXXXXP_POLL_INTERVAL_MS,

src/hardware/korad-kaxxxxp/protocol.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "protocol.h"
2323

2424
#define DEVICE_PROCESSING_TIME_MS 80
25+
#define EXTRA_PROCESSING_TIME_MS 450
2526

2627
SR_PRIV int korad_kaxxxxp_send_cmd(struct sr_serial_dev_inst *serial,
2728
const char *cmd)
@@ -155,18 +156,34 @@ static void give_device_time_to_process(struct dev_context *devc)
155156
{
156157
int64_t sleeping_time;
157158

158-
if (!devc->req_sent_at)
159+
if (!devc->next_req_time)
159160
return;
160161

161-
sleeping_time = devc->req_sent_at + (DEVICE_PROCESSING_TIME_MS * 1000);
162-
sleeping_time -= g_get_monotonic_time();
163-
162+
sleeping_time = devc->next_req_time - g_get_monotonic_time();
164163
if (sleeping_time > 0) {
165164
g_usleep(sleeping_time);
166165
sr_spew("Sleeping for processing %" PRIi64 " usec", sleeping_time);
167166
}
168167
}
169168

169+
static int64_t next_req_time(struct dev_context *devc,
170+
gboolean is_set, int target)
171+
{
172+
gboolean is_slow_device, is_long_command;
173+
int64_t processing_time_us;
174+
175+
is_slow_device = devc->model->quirks & KORAD_QUIRK_SLOW_PROCESSING;
176+
is_long_command = is_set;
177+
is_long_command |= target == KAXXXXP_STATUS;
178+
179+
processing_time_us = DEVICE_PROCESSING_TIME_MS;
180+
if (is_slow_device && is_long_command)
181+
processing_time_us += EXTRA_PROCESSING_TIME_MS;
182+
processing_time_us *= 1000;
183+
184+
return g_get_monotonic_time() + processing_time_us;
185+
}
186+
170187
SR_PRIV int korad_kaxxxxp_set_value(struct sr_serial_dev_inst *serial,
171188
int target, struct dev_context *devc)
172189
{
@@ -243,7 +260,7 @@ SR_PRIV int korad_kaxxxxp_set_value(struct sr_serial_dev_inst *serial,
243260

244261
if (ret == SR_OK && msg[0]) {
245262
ret = korad_kaxxxxp_send_cmd(serial, msg);
246-
devc->req_sent_at = g_get_monotonic_time();
263+
devc->next_req_time = next_req_time(devc, TRUE, target);
247264
}
248265

249266
g_mutex_unlock(&devc->rw_mutex);
@@ -305,7 +322,7 @@ SR_PRIV int korad_kaxxxxp_get_value(struct sr_serial_dev_inst *serial,
305322
return ret;
306323
}
307324

308-
devc->req_sent_at = g_get_monotonic_time();
325+
devc->next_req_time = next_req_time(devc, FALSE, target);
309326

310327
if ((ret = korad_kaxxxxp_read_chars(serial, count, reply)) < 0) {
311328
g_mutex_unlock(&devc->rw_mutex);

src/hardware/korad-kaxxxxp/protocol.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ enum korad_quirks_flag {
3737
KORAD_QUIRK_ID_NO_VENDOR = 1UL << 1,
3838
KORAD_QUIRK_ID_TRAILING = 1UL << 2,
3939
KORAD_QUIRK_ID_OPT_VERSION = 1UL << 3,
40-
KORAD_QUIRK_ALL = (1UL << 4) - 1,
40+
KORAD_QUIRK_SLOW_PROCESSING = 1UL << 4,
41+
KORAD_QUIRK_ALL = (1UL << 5) - 1,
4142
};
4243

4344
/* Information on single model */
@@ -70,7 +71,7 @@ struct dev_context {
7071
const struct korad_kaxxxxp_model *model; /**< Model information. */
7172

7273
struct sr_sw_limits limits;
73-
int64_t req_sent_at;
74+
int64_t next_req_time;
7475
GMutex rw_mutex;
7576

7677
float current; /**< Last current value [A] read from device. */

0 commit comments

Comments
 (0)