|
22 | 22 | #include "protocol.h" |
23 | 23 |
|
24 | 24 | #define DEVICE_PROCESSING_TIME_MS 80 |
| 25 | +#define EXTRA_PROCESSING_TIME_MS 450 |
25 | 26 |
|
26 | 27 | SR_PRIV int korad_kaxxxxp_send_cmd(struct sr_serial_dev_inst *serial, |
27 | 28 | const char *cmd) |
@@ -155,18 +156,34 @@ static void give_device_time_to_process(struct dev_context *devc) |
155 | 156 | { |
156 | 157 | int64_t sleeping_time; |
157 | 158 |
|
158 | | - if (!devc->req_sent_at) |
| 159 | + if (!devc->next_req_time) |
159 | 160 | return; |
160 | 161 |
|
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(); |
164 | 163 | if (sleeping_time > 0) { |
165 | 164 | g_usleep(sleeping_time); |
166 | 165 | sr_spew("Sleeping for processing %" PRIi64 " usec", sleeping_time); |
167 | 166 | } |
168 | 167 | } |
169 | 168 |
|
| 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 | + |
170 | 187 | SR_PRIV int korad_kaxxxxp_set_value(struct sr_serial_dev_inst *serial, |
171 | 188 | int target, struct dev_context *devc) |
172 | 189 | { |
@@ -243,7 +260,7 @@ SR_PRIV int korad_kaxxxxp_set_value(struct sr_serial_dev_inst *serial, |
243 | 260 |
|
244 | 261 | if (ret == SR_OK && msg[0]) { |
245 | 262 | 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); |
247 | 264 | } |
248 | 265 |
|
249 | 266 | g_mutex_unlock(&devc->rw_mutex); |
@@ -305,7 +322,7 @@ SR_PRIV int korad_kaxxxxp_get_value(struct sr_serial_dev_inst *serial, |
305 | 322 | return ret; |
306 | 323 | } |
307 | 324 |
|
308 | | - devc->req_sent_at = g_get_monotonic_time(); |
| 325 | + devc->next_req_time = next_req_time(devc, FALSE, target); |
309 | 326 |
|
310 | 327 | if ((ret = korad_kaxxxxp_read_chars(serial, count, reply)) < 0) { |
311 | 328 | g_mutex_unlock(&devc->rw_mutex); |
|
0 commit comments