feat: Implement configurable pump control preprocessing logic #5
|
|
@ -15,7 +15,7 @@ from .configuration_manager import (
|
||||||
configuration_manager, OPCUAConfig, ModbusTCPConfig, PumpStationConfig,
|
configuration_manager, OPCUAConfig, ModbusTCPConfig, PumpStationConfig,
|
||||||
PumpConfig, SafetyLimitsConfig, DataPointMapping, ProtocolType, ProtocolMapping
|
PumpConfig, SafetyLimitsConfig, DataPointMapping, ProtocolType, ProtocolMapping
|
||||||
)
|
)
|
||||||
from src.discovery.protocol_discovery_persistent import persistent_persistent_discovery_service, DiscoveryStatus, DiscoveredEndpoint
|
from src.discovery.protocol_discovery_persistent import persistent_discovery_service, DiscoveryStatus, DiscoveredEndpoint
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
@ -1025,26 +1025,26 @@ async def get_discovery_results(scan_id: str):
|
||||||
|
|
||||||
# Convert discovered endpoints to dict format
|
# Convert discovered endpoints to dict format
|
||||||
endpoints_data = []
|
endpoints_data = []
|
||||||
for endpoint in result.discovered_endpoints:
|
for endpoint in result["discovered_endpoints"]:
|
||||||
endpoint_data = {
|
endpoint_data = {
|
||||||
"protocol_type": endpoint.protocol_type.value,
|
"protocol_type": endpoint.get("protocol_type"),
|
||||||
"address": endpoint.address,
|
"address": endpoint.get("address"),
|
||||||
"port": endpoint.port,
|
"port": endpoint.get("port"),
|
||||||
"device_id": endpoint.device_id,
|
"device_id": endpoint.get("device_id"),
|
||||||
"device_name": endpoint.device_name,
|
"device_name": endpoint.get("device_name"),
|
||||||
"capabilities": endpoint.capabilities,
|
"capabilities": endpoint.get("capabilities", []),
|
||||||
"response_time": endpoint.response_time,
|
"response_time": endpoint.get("response_time"),
|
||||||
"discovered_at": endpoint.discovered_at.isoformat() if endpoint.discovered_at else None
|
"discovered_at": endpoint.get("discovered_at")
|
||||||
}
|
}
|
||||||
endpoints_data.append(endpoint_data)
|
endpoints_data.append(endpoint_data)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"scan_id": scan_id,
|
"scan_id": scan_id,
|
||||||
"status": result.status.value,
|
"status": result.get("status"),
|
||||||
"scan_duration": result.scan_duration,
|
"scan_duration": None, # Not available in current implementation
|
||||||
"errors": result.errors,
|
"errors": result.get("error_message"),
|
||||||
"timestamp": result.timestamp.isoformat() if result.timestamp else None,
|
"timestamp": result.get("scan_started_at"),
|
||||||
"discovered_endpoints": endpoints_data
|
"discovered_endpoints": endpoints_data
|
||||||
}
|
}
|
||||||
except HTTPException:
|
except HTTPException:
|
||||||
|
|
@ -1076,14 +1076,14 @@ async def get_recent_discoveries():
|
||||||
endpoints_data = []
|
endpoints_data = []
|
||||||
for endpoint in recent_endpoints:
|
for endpoint in recent_endpoints:
|
||||||
endpoint_data = {
|
endpoint_data = {
|
||||||
"protocol_type": endpoint.protocol_type.value,
|
"protocol_type": endpoint.get("protocol_type"),
|
||||||
"address": endpoint.address,
|
"address": endpoint.get("address"),
|
||||||
"port": endpoint.port,
|
"port": endpoint.get("port"),
|
||||||
"device_id": endpoint.device_id,
|
"device_id": endpoint.get("device_id"),
|
||||||
"device_name": endpoint.device_name,
|
"device_name": endpoint.get("device_name"),
|
||||||
"capabilities": endpoint.capabilities,
|
"capabilities": endpoint.get("capabilities", []),
|
||||||
"response_time": endpoint.response_time,
|
"response_time": endpoint.get("response_time"),
|
||||||
"discovered_at": endpoint.discovered_at.isoformat() if endpoint.discovered_at else None
|
"discovered_at": endpoint.get("discovered_at")
|
||||||
}
|
}
|
||||||
endpoints_data.append(endpoint_data)
|
endpoints_data.append(endpoint_data)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,7 @@ class PersistentProtocolDiscoveryService:
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"current_scan_id": self._current_scan_id,
|
"current_scan_id": self._current_scan_id,
|
||||||
|
"is_scanning": self._current_scan_id is not None,
|
||||||
"recent_scans": recent_scans,
|
"recent_scans": recent_scans,
|
||||||
"total_discovered_endpoints": total_endpoints
|
"total_discovered_endpoints": total_endpoints
|
||||||
}
|
}
|
||||||
|
|
@ -118,6 +119,7 @@ class PersistentProtocolDiscoveryService:
|
||||||
logger.error(f"Error getting discovery status: {e}")
|
logger.error(f"Error getting discovery status: {e}")
|
||||||
return {
|
return {
|
||||||
"current_scan_id": None,
|
"current_scan_id": None,
|
||||||
|
"is_scanning": False,
|
||||||
"recent_scans": [],
|
"recent_scans": [],
|
||||||
"total_discovered_endpoints": 0
|
"total_discovered_endpoints": 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ Start Dashboard Server for Protocol Mapping Testing
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import asyncio
|
||||||
import uvicorn
|
import uvicorn
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
@ -13,6 +14,7 @@ from fastapi import Request
|
||||||
|
|
||||||
from src.dashboard.api import dashboard_router
|
from src.dashboard.api import dashboard_router
|
||||||
from src.dashboard.templates import DASHBOARD_HTML
|
from src.dashboard.templates import DASHBOARD_HTML
|
||||||
|
from src.discovery.protocol_discovery_persistent import persistent_discovery_service
|
||||||
|
|
||||||
# Create FastAPI app
|
# Create FastAPI app
|
||||||
app = FastAPI(title="Calejo Control Adapter Dashboard", version="1.0.0")
|
app = FastAPI(title="Calejo Control Adapter Dashboard", version="1.0.0")
|
||||||
|
|
@ -38,6 +40,22 @@ async def health_check():
|
||||||
"""Health check endpoint"""
|
"""Health check endpoint"""
|
||||||
return {"status": "healthy", "service": "dashboard"}
|
return {"status": "healthy", "service": "dashboard"}
|
||||||
|
|
||||||
|
async def initialize_services():
|
||||||
|
"""Initialize services before starting the server"""
|
||||||
|
try:
|
||||||
|
print("🔄 Starting persistent discovery service initialization...")
|
||||||
|
await persistent_discovery_service.initialize()
|
||||||
|
print("✅ Persistent discovery service initialized")
|
||||||
|
|
||||||
|
# Test that it's working
|
||||||
|
status = persistent_discovery_service.get_discovery_status()
|
||||||
|
print(f"📊 Discovery status: {status}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Failed to initialize persistent discovery service: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Get port from environment variable or default to 8080
|
# Get port from environment variable or default to 8080
|
||||||
port = int(os.getenv("REST_API_PORT", "8080"))
|
port = int(os.getenv("REST_API_PORT", "8080"))
|
||||||
|
|
@ -46,6 +64,9 @@ if __name__ == "__main__":
|
||||||
print(f"📊 Dashboard available at: http://localhost:{port}")
|
print(f"📊 Dashboard available at: http://localhost:{port}")
|
||||||
print("📊 Protocol Mapping tab should be visible in the navigation")
|
print("📊 Protocol Mapping tab should be visible in the navigation")
|
||||||
|
|
||||||
|
# Initialize services
|
||||||
|
asyncio.run(initialize_services())
|
||||||
|
|
||||||
uvicorn.run(
|
uvicorn.run(
|
||||||
app,
|
app,
|
||||||
host="0.0.0.0",
|
host="0.0.0.0",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue