186 lines
7.0 KiB
Python
186 lines
7.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Demonstration script showing how the R1000 monitoring system handles
|
|
different external change scenarios.
|
|
|
|
This script simulates various external HMI actions and shows the system response.
|
|
"""
|
|
|
|
import time
|
|
import json
|
|
from datetime import datetime
|
|
|
|
def print_scenario(title, description):
|
|
"""Print a formatted scenario header"""
|
|
print("\n" + "="*70)
|
|
print(f"SCENARIO: {title}")
|
|
print("-" * 70)
|
|
print(description)
|
|
print("="*70)
|
|
|
|
def simulate_r1000_change(old_value, new_value, scenario_name):
|
|
"""Simulate what happens when R1000 changes externally"""
|
|
|
|
# Import the monitoring components (would be running in background)
|
|
from watermaker_plc_api.services.background_tasks import R1000Monitor
|
|
from watermaker_plc_api.services.data_cache import get_data_cache
|
|
|
|
# Create a mock monitor for demonstration
|
|
monitor = R1000Monitor()
|
|
cache = get_data_cache()
|
|
|
|
# Simulate the change detection
|
|
change_info = {
|
|
"previous_value": old_value,
|
|
"new_value": new_value,
|
|
"change_time": datetime.now().isoformat(),
|
|
"change_type": monitor._classify_change(old_value, new_value),
|
|
"external_change": True
|
|
}
|
|
|
|
print(f"\n🔍 DETECTED CHANGE:")
|
|
print(f" R1000: {old_value} → {new_value}")
|
|
print(f" Type: {change_info['change_type']}")
|
|
print(f" Time: {change_info['change_time']}")
|
|
|
|
# Show what would be logged
|
|
log_message = f"R1000 External Change: {old_value} → {new_value} ({change_info['change_type']})"
|
|
print(f"\n📝 LOGGED TO CACHE:")
|
|
print(f" {log_message}")
|
|
|
|
# Show impact assessment
|
|
print(f"\n⚠️ IMPACT ASSESSMENT:")
|
|
if "Process_Start" in change_info['change_type']:
|
|
print(" - External system started DTS process")
|
|
print(" - API should be aware process is now running")
|
|
print(" - Any pending API start operations may conflict")
|
|
elif "Process_Stop" in change_info['change_type']:
|
|
print(" - External system stopped DTS process")
|
|
print(" - Running API tasks should be marked as externally stopped")
|
|
print(" - Process ended without API control")
|
|
elif "Step_Skip" in change_info['change_type']:
|
|
print(" - External system skipped a DTS step")
|
|
print(" - Running API tasks should update current step")
|
|
print(" - Timer-based progress may be affected")
|
|
elif "Step_Advance" in change_info['change_type']:
|
|
print(" - External system advanced DTS step")
|
|
print(" - Running API tasks should track the advancement")
|
|
print(" - Normal process flow continued externally")
|
|
elif "DTS_Start" in change_info['change_type']:
|
|
print(" - DTS process started from requested state")
|
|
print(" - Normal transition, may be API or external")
|
|
print(" - Monitor will track subsequent steps")
|
|
else:
|
|
print(" - General mode change detected")
|
|
print(" - May indicate system state change")
|
|
print(" - Monitor will continue tracking")
|
|
|
|
return change_info
|
|
|
|
def main():
|
|
"""Run demonstration scenarios"""
|
|
|
|
print("R1000 MONITORING SYSTEM - EXTERNAL CHANGE SCENARIOS")
|
|
print("This demonstration shows how the system detects and handles external changes")
|
|
|
|
# Scenario 1: External HMI starts DTS process
|
|
print_scenario(
|
|
"External HMI Starts DTS Process",
|
|
"User presses DTS start button on external HMI while system is in standby mode"
|
|
)
|
|
simulate_r1000_change(2, 5, "external_start")
|
|
|
|
# Scenario 2: External HMI stops running DTS process
|
|
print_scenario(
|
|
"External HMI Stops Running DTS Process",
|
|
"User presses stop button on external HMI while DTS is in production mode"
|
|
)
|
|
simulate_r1000_change(7, 2, "external_stop")
|
|
|
|
# Scenario 3: External HMI skips priming step
|
|
print_scenario(
|
|
"External HMI Skips Priming Step",
|
|
"User skips priming step on external HMI, jumping directly to production"
|
|
)
|
|
simulate_r1000_change(5, 7, "external_skip")
|
|
|
|
# Scenario 4: External HMI advances from init to flush
|
|
print_scenario(
|
|
"External HMI Advances to Flush",
|
|
"User advances from init step directly to flush step on external HMI"
|
|
)
|
|
simulate_r1000_change(6, 8, "external_advance")
|
|
|
|
# Scenario 5: External system requests DTS
|
|
print_scenario(
|
|
"External System Requests DTS",
|
|
"External system sets DTS requested mode, preparing for DTS start"
|
|
)
|
|
simulate_r1000_change(2, 34, "external_request")
|
|
|
|
# Scenario 6: Normal DTS progression (for comparison)
|
|
print_scenario(
|
|
"Normal DTS Progression (For Comparison)",
|
|
"Normal progression from DTS requested to DTS priming (may be API or external)"
|
|
)
|
|
simulate_r1000_change(34, 5, "normal_progression")
|
|
|
|
# Summary
|
|
print("\n" + "="*70)
|
|
print("SUMMARY - R1000 MONITORING CAPABILITIES")
|
|
print("="*70)
|
|
|
|
capabilities = [
|
|
"✅ Detects all R1000 changes in real-time",
|
|
"✅ Classifies change types automatically",
|
|
"✅ Logs changes to data cache for API access",
|
|
"✅ Assesses impact on running DTS tasks",
|
|
"✅ Provides detailed change history",
|
|
"✅ Integrates with existing background task system",
|
|
"✅ Offers API endpoints for monitoring status",
|
|
"✅ Supports callback system for custom handling"
|
|
]
|
|
|
|
for capability in capabilities:
|
|
print(f" {capability}")
|
|
|
|
print("\n" + "="*70)
|
|
print("INTEGRATION WITH EXISTING SYSTEM")
|
|
print("="*70)
|
|
|
|
integration_points = [
|
|
"🔗 Background Tasks: Integrated into existing data update loop",
|
|
"🔗 DTS Controller: Enhanced to detect external changes during operations",
|
|
"🔗 Data Cache: Uses existing error logging system for change history",
|
|
"🔗 API Endpoints: New endpoint provides monitoring status and history",
|
|
"🔗 Logging System: Uses existing logger with appropriate warning levels",
|
|
"🔗 PLC Connection: Uses existing PLC connection service"
|
|
]
|
|
|
|
for point in integration_points:
|
|
print(f" {point}")
|
|
|
|
print("\n" + "="*70)
|
|
print("USAGE IN PRODUCTION")
|
|
print("="*70)
|
|
|
|
usage_scenarios = [
|
|
"🏭 Operators can use external HMI while API monitoring continues",
|
|
"🏭 System detects conflicts between API and external operations",
|
|
"🏭 Maintenance staff can see history of external changes",
|
|
"🏭 Debugging is easier with detailed change classification",
|
|
"🏭 Process integrity is maintained with change awareness",
|
|
"🏭 Real-time alerts possible for critical external changes"
|
|
]
|
|
|
|
for scenario in usage_scenarios:
|
|
print(f" {scenario}")
|
|
|
|
print(f"\n{'='*70}")
|
|
print("DEMONSTRATION COMPLETE")
|
|
print(f"{'='*70}")
|
|
print("The R1000 monitoring system is ready to detect and handle external changes.")
|
|
print("Run 'python test_r1000_monitoring.py' for live testing with actual PLC.")
|
|
|
|
if __name__ == "__main__":
|
|
main() |