fix timeout for flipper connection

This commit is contained in:
2026-01-30 00:10:58 +03:00
parent 9a3fe4457c
commit aab373cc0f
2 changed files with 6 additions and 19 deletions

View File

@@ -46,7 +46,6 @@ class FlipperServer:
# Timing constants # Timing constants
PAGE_UPDATE_INTERVAL = 0.5 # Send PAGE every 500ms PAGE_UPDATE_INTERVAL = 0.5 # Send PAGE every 500ms
CONNECTION_TIMEOUT = 10.0 # Consider disconnected after 10s of silence
def __init__( def __init__(
self, self,
@@ -73,7 +72,6 @@ class FlipperServer:
self._page_manager = PageManager() self._page_manager = PageManager()
self._last_page_sent = 0.0 self._last_page_sent = 0.0
self._last_command_received = 0.0
self._logger = get_logger("obd2_client.flipper") self._logger = get_logger("obd2_client.flipper")
self._ip_address = "0.0.0.0" self._ip_address = "0.0.0.0"
@@ -151,7 +149,6 @@ class FlipperServer:
# Send periodic PAGE updates if connected # Send periodic PAGE updates if connected
if self._state == ServerState.CONNECTED: if self._state == ServerState.CONNECTED:
self._send_page_updates() self._send_page_updates()
self._check_connection_timeout()
except Exception as e: except Exception as e:
self._logger.error(f"Server error: {e}") self._logger.error(f"Server error: {e}")
@@ -207,7 +204,6 @@ class FlipperServer:
self._logger.debug(f"Unknown command: {line.strip()}") self._logger.debug(f"Unknown command: {line.strip()}")
return return
self._last_command_received = time.time()
self._logger.debug(f"Received: {cmd.cmd_type.name}") self._logger.debug(f"Received: {cmd.cmd_type.name}")
# INIT can be received at any time (reconnection support) # INIT can be received at any time (reconnection support)
@@ -252,7 +248,6 @@ class FlipperServer:
# Reset state for fresh connection # Reset state for fresh connection
self._state = ServerState.CONNECTED self._state = ServerState.CONNECTED
self._last_command_received = time.time()
self._last_page_sent = 0.0 # Force immediate PAGE send self._last_page_sent = 0.0 # Force immediate PAGE send
# Reset page manager to first page # Reset page manager to first page
@@ -333,17 +328,6 @@ class FlipperServer:
if (current_time - self._last_page_sent) >= self.PAGE_UPDATE_INTERVAL: if (current_time - self._last_page_sent) >= self.PAGE_UPDATE_INTERVAL:
self._send_current_page() self._send_current_page()
def _check_connection_timeout(self) -> None:
"""Check if connection has timed out (no commands from Flipper)."""
if self._last_command_received == 0:
return
elapsed = time.time() - self._last_command_received
if elapsed > self.CONNECTION_TIMEOUT:
self._logger.warning(f"Connection timeout ({elapsed:.1f}s since last command)")
self._state = ServerState.IDLE
self._last_command_received = 0
def _send_current_page(self) -> None: def _send_current_page(self) -> None:
"""Send current page content.""" """Send current page content."""
page = self._page_manager.get_current_page() page = self._page_manager.get_current_page()

View File

@@ -66,9 +66,12 @@ class OBD2Scanner:
""" """
import time import time
if use_cache and self._load_cache(): if use_cache:
self._logger.info(f"Loaded {len(self._supported_pids)} PIDs from cache") if self._load_cache() and len(self._supported_pids) > 0:
return self.supported_pids self._logger.info(f"Loaded {len(self._supported_pids)} PIDs from cache")
return self.supported_pids
else:
self._logger.debug("Cache empty or invalid, will scan")
# Initial delay to let CAN interface and ECU stabilize # Initial delay to let CAN interface and ECU stabilize
if initial_delay > 0: if initial_delay > 0: