Remove deprecated files and scripts to streamline the codebase
- Deleted unused API test files, RTSP diagnostic scripts, and development utility scripts to reduce clutter. - Removed outdated database schema and modularization proposal documents to maintain focus on current architecture. - Cleaned up configuration files and logging scripts that are no longer in use, enhancing project maintainability.
This commit is contained in:
@@ -45,8 +45,21 @@ class StandaloneAutoRecorder:
|
||||
|
||||
# Setup logging (only if not already configured)
|
||||
if not logging.getLogger().handlers:
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", handlers=[logging.FileHandler("standalone_auto_recorder.log"), logging.StreamHandler()])
|
||||
# Use WARNING level by default to reduce INFO log noise
|
||||
log_level = getattr(self.config.system, 'log_level', 'WARNING')
|
||||
log_level_num = getattr(logging, log_level.upper(), logging.WARNING)
|
||||
logging.basicConfig(
|
||||
level=log_level_num,
|
||||
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
||||
handlers=[
|
||||
logging.FileHandler("standalone_auto_recorder.log"),
|
||||
logging.StreamHandler()
|
||||
]
|
||||
)
|
||||
self.logger = logging.getLogger(__name__)
|
||||
# Ensure this logger respects the configured log level
|
||||
if hasattr(self.config, 'system') and hasattr(self.config.system, 'log_level'):
|
||||
self.logger.setLevel(getattr(logging, self.config.system.log_level.upper(), logging.WARNING))
|
||||
|
||||
# Initialize components
|
||||
self.state_manager = StateManager()
|
||||
@@ -59,6 +72,9 @@ class StandaloneAutoRecorder:
|
||||
self.camera_recorders: Dict[str, CameraRecorder] = {}
|
||||
self.active_recordings: Dict[str, str] = {} # camera_name -> filename
|
||||
|
||||
# Camera device cache
|
||||
self._device_list: Optional[list] = None
|
||||
|
||||
# Machine to camera mapping
|
||||
self.machine_camera_map = self._build_machine_camera_map()
|
||||
|
||||
@@ -257,7 +273,7 @@ class StandaloneAutoRecorder:
|
||||
return None
|
||||
|
||||
def _find_camera_device(self, camera_name: str):
|
||||
"""Simplified camera device discovery"""
|
||||
"""Find camera device by matching serial number or using index mapping"""
|
||||
try:
|
||||
# Import camera SDK
|
||||
import sys
|
||||
@@ -266,23 +282,73 @@ class StandaloneAutoRecorder:
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "camera_sdk"))
|
||||
import mvsdk
|
||||
|
||||
# Initialize SDK
|
||||
mvsdk.CameraSdkInit(1)
|
||||
# Initialize SDK (only if not already initialized)
|
||||
try:
|
||||
mvsdk.CameraSdkInit(1)
|
||||
except:
|
||||
pass # SDK may already be initialized
|
||||
|
||||
# Enumerate cameras
|
||||
device_list = mvsdk.CameraEnumerateDevice()
|
||||
|
||||
# For now, map by index (camera1 = index 0, camera2 = index 1)
|
||||
camera_index = int(camera_name.replace("camera", "")) - 1
|
||||
|
||||
if 0 <= camera_index < len(device_list):
|
||||
return device_list[camera_index]
|
||||
# Cache device list to avoid re-enumerating
|
||||
if self._device_list is None:
|
||||
device_list = mvsdk.CameraEnumerateDevice()
|
||||
self._device_list = device_list
|
||||
self.logger.info(f"Enumerated {len(device_list)} camera device(s)")
|
||||
else:
|
||||
self.logger.error(f"Camera index {camera_index} not found (total: {len(device_list)})")
|
||||
device_list = self._device_list
|
||||
|
||||
if len(device_list) == 0:
|
||||
self.logger.error("No cameras detected")
|
||||
return None
|
||||
|
||||
# Find camera config to get serial number or device_index if available
|
||||
camera_config = None
|
||||
for config in self.config.cameras:
|
||||
if config.name == camera_name:
|
||||
camera_config = config
|
||||
break
|
||||
|
||||
# Try to match by serial number if available in device info
|
||||
if camera_config:
|
||||
# Check if config has device_index specified
|
||||
device_index = getattr(camera_config, 'device_index', None)
|
||||
if device_index is not None and 0 <= device_index < len(device_list):
|
||||
self.logger.info(f"Using device_index {device_index} for {camera_name}")
|
||||
return device_list[device_index]
|
||||
|
||||
# Try matching by serial number from camera config if available
|
||||
config_serial = getattr(camera_config, 'serial_number', None)
|
||||
if config_serial:
|
||||
for i, dev_info in enumerate(device_list):
|
||||
try:
|
||||
dev_serial = getattr(dev_info, 'acSn', None) or getattr(dev_info, 'GetSn', lambda: None)()
|
||||
if dev_serial and str(dev_serial) == str(config_serial):
|
||||
self.logger.info(f"Matched {camera_name} to device {i} by serial number: {dev_serial}")
|
||||
return dev_info
|
||||
except:
|
||||
continue
|
||||
|
||||
# Fallback to index mapping (camera1 = index 0, camera2 = index 1, etc.)
|
||||
try:
|
||||
camera_index = int(camera_name.replace("camera", "")) - 1
|
||||
if 0 <= camera_index < len(device_list):
|
||||
self.logger.info(f"Using index mapping for {camera_name} -> device {camera_index}")
|
||||
return device_list[camera_index]
|
||||
else:
|
||||
self.logger.error(f"Camera index {camera_index} not found (total: {len(device_list)}). Available indices: 0-{len(device_list)-1}")
|
||||
# If only one camera is available, use it for any camera name
|
||||
if len(device_list) == 1:
|
||||
self.logger.warning(f"Only 1 camera detected, using it for {camera_name}")
|
||||
return device_list[0]
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
self.logger.error(f"No device found for camera {camera_name}")
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error finding camera device: {e}")
|
||||
import traceback
|
||||
self.logger.debug(traceback.format_exc())
|
||||
return None
|
||||
|
||||
def start(self) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user