mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-12-17 21:59:57 +01:00
serialqueue: Simplify command_event()
There's no reason to attempt to handle multiple buffer transmissions in a single command_event() call. Handle the transmit case outside of the command building loop. If data is transmitted, then get a new timestamp from the pollreactor and retry before sleeping. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
// Serial port command queuing
|
// Serial port command queuing
|
||||||
//
|
//
|
||||||
// Copyright (C) 2016-2021 Kevin O'Connor <kevin@koconnor.net>
|
// Copyright (C) 2016-2025 Kevin O'Connor <kevin@koconnor.net>
|
||||||
//
|
//
|
||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
@@ -626,20 +626,19 @@ command_event(struct serialqueue *sq, double eventtime)
|
|||||||
double waketime;
|
double waketime;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
waketime = check_send_command(sq, buflen, eventtime);
|
waketime = check_send_command(sq, buflen, eventtime);
|
||||||
if (waketime != PR_NOW || buflen + MESSAGE_MAX > sizeof(buf)) {
|
if (waketime != PR_NOW)
|
||||||
|
break;
|
||||||
|
buflen += build_and_send_command(sq, &buf[buflen], buflen, eventtime);
|
||||||
|
if (buflen + MESSAGE_MAX > sizeof(buf))
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (buflen) {
|
if (buflen) {
|
||||||
// Write message blocks
|
// Write message blocks
|
||||||
do_write(sq, buf, buflen);
|
do_write(sq, buf, buflen);
|
||||||
sq->bytes_write += buflen;
|
sq->bytes_write += buflen;
|
||||||
double idletime = (eventtime > sq->idle_time
|
double idletime = eventtime > sq->idle_time ? eventtime : sq->idle_time;
|
||||||
? eventtime : sq->idle_time);
|
|
||||||
sq->idle_time = idletime + calculate_bittime(sq, buflen);
|
sq->idle_time = idletime + calculate_bittime(sq, buflen);
|
||||||
buflen = 0;
|
waketime = PR_NOW;
|
||||||
}
|
|
||||||
if (waketime != PR_NOW)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
buflen += build_and_send_command(sq, &buf[buflen], buflen, eventtime);
|
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&sq->lock);
|
pthread_mutex_unlock(&sq->lock);
|
||||||
return waketime;
|
return waketime;
|
||||||
|
|||||||
Reference in New Issue
Block a user