# Protocol Mapping - Phase 1 Implementation Plan
## Overview
This document outlines the detailed implementation plan for Phase 1 of the Protocol Mapping UI feature, supporting Modbus, OPC UA, and other industrial protocols.
## ๐ฏ Phase 1 Goals
- Enable basic configuration of database-to-protocol mappings through unified dashboard interface
- Replace hardcoded protocol mappings with configurable system
- Support multiple protocols (Modbus, OPC UA) through single Protocol Mapping tab
- Provide protocol-specific validation within unified interface
- Implement protocol switching within single dashboard tab
## ๐ Detailed Task Breakdown
### Task 1: Extend Configuration Manager with Protocol Mapping Support
**Priority**: High
**Estimated Effort**: 3 days
#### Implementation Details:
```python
# File: src/dashboard/configuration_manager.py
class ProtocolMapping(BaseModel):
"""Protocol mapping configuration for all protocols"""
id: str
protocol_type: str # modbus_tcp, opcua, custom
station_id: str
pump_id: str
data_type: str # setpoint, status, power, etc.
protocol_address: str # register address or OPC UA node
db_source: str
transformation_rules: List[Dict] = []
# Protocol-specific configurations
modbus_config: Optional[Dict] = None
opcua_config: Optional[Dict] = None
class ConfigurationManager:
def __init__(self):
self.protocol_mappings: List[ProtocolMapping] = []
def add_protocol_mapping(self, mapping: ProtocolMapping) -> bool:
"""Add a new protocol mapping with validation"""
def get_protocol_mappings(self,
protocol_type: str = None,
station_id: str = None,
pump_id: str = None) -> List[ProtocolMapping]:
"""Get mappings filtered by protocol/station/pump"""
def validate_protocol_mapping(self, mapping: ProtocolMapping) -> Dict[str, Any]:
"""Validate mapping for conflicts and protocol-specific rules"""
```
### Task 2: Create Protocol Mapping API Endpoints
**Priority**: High
**Estimated Effort**: 2 days
#### Implementation Details:
```python
# File: src/dashboard/api.py
@dashboard_router.get("/protocol-mappings")
async def get_protocol_mappings(
protocol_type: Optional[str] = None,
station_id: Optional[str] = None,
pump_id: Optional[str] = None
):
"""Get all protocol mappings"""
@dashboard_router.post("/protocol-mappings")
async def create_protocol_mapping(mapping: ProtocolMapping):
"""Create a new protocol mapping"""
@dashboard_router.put("/protocol-mappings/{mapping_id}")
async def update_protocol_mapping(mapping_id: str, mapping: ProtocolMapping):
"""Update an existing protocol mapping"""
@dashboard_router.delete("/protocol-mappings/{mapping_id}")
async def delete_protocol_mapping(mapping_id: str):
"""Delete a protocol mapping"""
@dashboard_router.post("/protocol-mappings/validate")
async def validate_protocol_mapping(mapping: ProtocolMapping):
"""Validate a protocol mapping without saving"""
# Protocol-specific endpoints
@dashboard_router.get("/protocol-mappings/modbus")
async def get_modbus_mappings():
"""Get all Modbus mappings"""
@dashboard_router.get("/protocol-mappings/opcua")
async def get_opcua_mappings():
"""Get all OPC UA mappings"""
```
### Task 3: Build Multi-Protocol Configuration Form UI
**Priority**: High
**Estimated Effort**: 3 days
#### Implementation Details:
```html
// Add Protocol Mapping section to dashboard
function createProtocolMappingSection() {
return `
Protocol Mapping Configuration
`;
}
// Protocol switching within the single tab
function selectProtocol(protocol) {
// Update active protocol button
document.querySelectorAll('.protocol-btn').forEach(btn => btn.classList.remove('active'));
event.target.classList.add('active');
// Load protocol-specific content
loadProtocolMappings(protocol);
}
```
### Task 10: Implement Protocol Discovery Features
**Priority**: Medium
**Estimated Effort**: 2 days
#### Implementation Details:
```python
# File: src/dashboard/api.py
@dashboard_router.post("/protocol-mappings/modbus/discover")
async def discover_modbus_registers():
"""Auto-discover available Modbus registers"""
try:
# Scan for available registers
discovered_registers = await modbus_client.scan_registers()
return {"success": True, "registers": discovered_registers}
except Exception as e:
logger.error(f"Failed to discover Modbus registers: {str(e)}")
raise HTTPException(status_code=500, detail=f"Discovery failed: {str(e)}")
@dashboard_router.post("/protocol-mappings/opcua/browse")
async def browse_opcua_nodes():
"""Browse OPC UA server for available nodes"""
try:
# Browse OPC UA server
nodes = await opcua_client.browse_nodes()
return {"success": True, "nodes": nodes}
except Exception as e:
logger.error(f"Failed to browse OPC UA nodes: {str(e)}")
raise HTTPException(status_code=500, detail=f"Browse failed: {str(e)}")
```
## ๐ Integration Points
### Existing System Integration
1. **Configuration Manager**: Extend existing class with unified protocol mapping support
2. **Protocol Servers**: Inject configuration manager and use configured mappings (Modbus, OPC UA)
3. **Dashboard API**: Add unified protocol mapping endpoints alongside existing configuration endpoints
4. **Dashboard UI**: Add single Protocol Mapping tab with protocol switching
5. **Database**: Add unified table for persistent storage of all protocol mappings
### Data Flow Changes
```
Current: Database โ Setpoint Manager โ Hardcoded Mapping โ Protocol Servers
New: Database โ Setpoint Manager โ Unified Configurable Mapping โ Protocol Servers
โ
Unified Configuration Manager
```
### Dashboard Integration
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DASHBOARD NAVIGATION โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ [Status] [Config] [SCADA] [Signals] [Protocol Mapping] [Logs] โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Within Protocol Mapping Tab:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PROTOCOL MAPPING โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ [Modbus] [OPC UA] [All Protocols] โ Protocol Selector โ
โ โ
โ Unified Mapping Grid & Configuration Forms โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
## ๐งช Testing Strategy
### Test Scenarios
1. **Protocol Configuration Validation**: Test address conflicts, data type compatibility across protocols
2. **Integration Testing**: Test that configured mappings are applied correctly to all protocol servers
3. **Protocol-Specific Testing**: Test Modbus register mapping and OPC UA node mapping separately
4. **Performance Testing**: Test impact on protocol server performance
### Test Data
- Create test mappings for different protocols and scenarios
- Test edge cases (address boundaries, data type conversions, protocol-specific rules)
- Test cross-protocol conflict scenarios
## ๐ Success Metrics
### Functional Requirements
- โ
Users can configure database-to-protocol mappings through dashboard
- โ
System uses configured mappings for all supported protocols
- โ
Protocol-specific validation prevents configuration conflicts
- โ
Mappings are persisted across application restarts
- โ
Support for multiple protocols (Modbus, OPC UA) with unified interface
### Performance Requirements
- โฑ๏ธ Mapping configuration response time < 500ms
- โฑ๏ธ Protocol server update performance maintained
- ๐พ Memory usage increase < 15MB for typical multi-protocol configurations
## ๐จ Risk Mitigation
### Technical Risks
1. **Performance Impact**: Monitor protocol server update times, optimize if needed
2. **Configuration Errors**: Implement comprehensive protocol-specific validation
3. **Protocol Compatibility**: Ensure consistent behavior across different protocols
### Implementation Risks
1. **Scope Creep**: Stick to Phase 1 requirements only
2. **Integration Issues**: Test thoroughly with existing protocol servers
3. **Data Loss**: Implement backup/restore for mapping configurations
## ๐
Estimated Timeline
**Total Phase 1 Effort**: 18.5 days
| Week | Tasks | Deliverables |
|------|-------|--------------|
| 1 | Tasks 1-3 | Configuration manager, API endpoints, multi-protocol UI |
| 2 | Tasks 4-6 | Grid view, protocol-specific validation, server integration |
| 3 | Tasks 7-10 | Database schema, tests, navigation, discovery features |
## ๐ฏ Next Steps After Phase 1
1. **User Testing**: Gather feedback from operators on multi-protocol interface
2. **Bug Fixing**: Address any issues discovered in production
3. **Phase 2 Planning**: Begin design for enhanced features (drag & drop, templates, bulk operations)
---
*This implementation plan provides a detailed roadmap for delivering Phase 1 of the Protocol Mapping feature, supporting multiple industrial protocols with a unified interface. Each task includes specific implementation details and integration points with the existing system.*