1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-23 16:25:22 +03:00

Improve timeout optimization

This commit is contained in:
Mark Haslinghuis 2025-06-11 00:41:38 +02:00
parent 5b1a70077e
commit 8500754b99

View file

@ -404,14 +404,16 @@ const MSP = {
// Send message if it has data or is a new request
if (data || !isDuplicateRequest) {
// Optimize timeout for frequent requests
if (this.timeout > this.MIN_TIMEOUT) {
this.timeout--;
}
// Simple adaptive timeout - decrease on success, increase on timeout
serial.send(bufferOut, (sendInfo) => {
if (sendInfo.bytesSent === bufferOut.byteLength && callback_sent) {
callback_sent();
if (sendInfo.bytesSent === bufferOut.byteLength) {
// Success: gradually decrease timeout for faster response
if (this.timeout > this.MIN_TIMEOUT) {
this.timeout = Math.max(this.MIN_TIMEOUT, this.timeout - 5);
}
if (callback_sent) {
callback_sent();
}
}
});
}
@ -426,6 +428,9 @@ const MSP = {
},
_handleTimeout(requestObj, bufferOut) {
// Increase timeout on failure for better reliability
this.timeout = Math.min(this.MAX_TIMEOUT, this.timeout + 50);
// Increment retry attempts
requestObj.attempts++;