#include "protocol.h"
#define DEVICE_PROCESSING_TIME_MS 80
+#define EXTRA_PROCESSING_TIME_MS 450
SR_PRIV int korad_kaxxxxp_send_cmd(struct sr_serial_dev_inst *serial,
- const char *cmd)
+ const char *cmd)
{
int ret;
{
int64_t sleeping_time;
- sleeping_time = devc->req_sent_at + (DEVICE_PROCESSING_TIME_MS * 1000);
- sleeping_time -= g_get_monotonic_time();
+ if (!devc->next_req_time)
+ return;
+ sleeping_time = devc->next_req_time - g_get_monotonic_time();
if (sleeping_time > 0) {
g_usleep(sleeping_time);
sr_spew("Sleeping for processing %" PRIi64 " usec", sleeping_time);
}
}
+static int64_t next_req_time(struct dev_context *devc,
+ gboolean is_set, int target)
+{
+ gboolean is_slow_device, is_long_command;
+ int64_t processing_time_us;
+
+ is_slow_device = devc->model->quirks & KORAD_QUIRK_SLOW_PROCESSING;
+ is_long_command = is_set;
+ is_long_command |= target == KAXXXXP_STATUS;
+
+ processing_time_us = DEVICE_PROCESSING_TIME_MS;
+ if (is_slow_device && is_long_command)
+ processing_time_us += EXTRA_PROCESSING_TIME_MS;
+ processing_time_us *= 1000;
+
+ return g_get_monotonic_time() + processing_time_us;
+}
+
SR_PRIV int korad_kaxxxxp_set_value(struct sr_serial_dev_inst *serial,
- int target, struct dev_context *devc)
+ int target, struct dev_context *devc)
{
char msg[20];
int ret;
if (ret == SR_OK && msg[0]) {
ret = korad_kaxxxxp_send_cmd(serial, msg);
- devc->req_sent_at = g_get_monotonic_time();
+ devc->next_req_time = next_req_time(devc, TRUE, target);
}
g_mutex_unlock(&devc->rw_mutex);
}
SR_PRIV int korad_kaxxxxp_get_value(struct sr_serial_dev_inst *serial,
- int target, struct dev_context *devc)
+ int target, struct dev_context *devc)
{
int ret, count;
char reply[6];
return ret;
}
- devc->req_sent_at = g_get_monotonic_time();
+ devc->next_req_time = next_req_time(devc, FALSE, target);
if ((ret = korad_kaxxxxp_read_chars(serial, count, reply)) < 0) {
g_mutex_unlock(&devc->rw_mutex);
}
SR_PRIV int korad_kaxxxxp_get_all_values(struct sr_serial_dev_inst *serial,
- struct dev_context *devc)
+ struct dev_context *devc)
{
int ret, target;