File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -404,14 +404,16 @@ const MSP = {
404404
405405 // Send message if it has data or is a new request
406406 if ( data || ! isDuplicateRequest ) {
407- // Optimize timeout for frequent requests
408- if ( this . timeout > this . MIN_TIMEOUT ) {
409- this . timeout -- ;
410- }
411-
407+ // Simple adaptive timeout - decrease on success, increase on timeout
412408 serial . send ( bufferOut , ( sendInfo ) => {
413- if ( sendInfo . bytesSent === bufferOut . byteLength && callback_sent ) {
414- callback_sent ( ) ;
409+ if ( sendInfo . bytesSent === bufferOut . byteLength ) {
410+ // Success: gradually decrease timeout for faster response
411+ if ( this . timeout > this . MIN_TIMEOUT ) {
412+ this . timeout = Math . max ( this . MIN_TIMEOUT , this . timeout - 5 ) ;
413+ }
414+ if ( callback_sent ) {
415+ callback_sent ( ) ;
416+ }
415417 }
416418 } ) ;
417419 }
@@ -426,6 +428,9 @@ const MSP = {
426428 } ,
427429
428430 _handleTimeout ( requestObj , bufferOut ) {
431+ // Increase timeout on failure for better reliability
432+ this . timeout = Math . min ( this . MAX_TIMEOUT , this . timeout + 50 ) ;
433+
429434 // Increment retry attempts
430435 requestObj . attempts ++ ;
431436
You can’t perform that action at this time.
0 commit comments