Files
geutebruck/find_mapping_rules.py
Administrator 14893e62a5 feat: Geutebruck GeViScope/GeViSoft Action Mapping System - MVP
This MVP release provides a complete full-stack solution for managing action mappings
in Geutebruck's GeViScope and GeViSoft video surveillance systems.

## Features

### Flutter Web Application (Port 8081)
- Modern, responsive UI for managing action mappings
- Action picker dialog with full parameter configuration
- Support for both GSC (GeViScope) and G-Core server actions
- Consistent UI for input and output actions with edit/delete capabilities
- Real-time action mapping creation, editing, and deletion
- Server categorization (GSC: prefix for GeViScope, G-Core: prefix for G-Core servers)

### FastAPI REST Backend (Port 8000)
- RESTful API for action mapping CRUD operations
- Action template service with comprehensive action catalog (247 actions)
- Server management (G-Core and GeViScope servers)
- Configuration tree reading and writing
- JWT authentication with role-based access control
- PostgreSQL database integration

### C# SDK Bridge (gRPC, Port 50051)
- Native integration with GeViSoft SDK (GeViProcAPINET_4_0.dll)
- Action mapping creation with correct binary format
- Support for GSC and G-Core action types
- Proper Camera parameter inclusion in action strings (fixes CrossSwitch bug)
- Action ID lookup table with server-specific action IDs
- Configuration reading/writing via SetupClient

## Bug Fixes
- **CrossSwitch Bug**: GSC and G-Core actions now correctly display camera/PTZ head parameters in GeViSet
- Action strings now include Camera parameter: `@ PanLeft (Comment: "", Camera: 101028)`
- Proper filter flags and VideoInput=0 for action mappings
- Correct action ID assignment (4198 for GSC, 9294 for G-Core PanLeft)

## Technical Stack
- **Frontend**: Flutter Web, Dart, Dio HTTP client
- **Backend**: Python FastAPI, PostgreSQL, Redis
- **SDK Bridge**: C# .NET 8.0, gRPC, GeViSoft SDK
- **Authentication**: JWT tokens
- **Configuration**: GeViSoft .set files (binary format)

## Credentials
- GeViSoft/GeViScope: username=sysadmin, password=masterkey
- Default admin: username=admin, password=admin123

## Deployment
All services run on localhost:
- Flutter Web: http://localhost:8081
- FastAPI: http://localhost:8000
- SDK Bridge gRPC: localhost:50051
- GeViServer: localhost (default port)

Generated with Claude Code (https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-31 18:10:54 +01:00

156 lines
5.1 KiB
Python

"""
Search for MappingRules in the JSON configuration
"""
import grpc
import sys
import io
import json
sys.path.append(r'C:\DEV\COPILOT\geutebruck-api\src\api')
if sys.platform == 'win32':
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
from protos import configuration_pb2
from protos import configuration_pb2_grpc
def find_mapping_rules(node, path=""):
"""Recursively search for MappingRules folder"""
if isinstance(node, dict):
# Check if this node is MappingRules
if node.get("name") == "MappingRules" and node.get("nodeType") == "folder":
return node, path
# Check children if this is a folder
if "children" in node and isinstance(node["children"], list):
for i, child in enumerate(node["children"]):
result, result_path = find_mapping_rules(child, f"{path}/{node.get('name', 'unknown')}")
if result:
return result, result_path
return None, ""
def find_working_mapping(mapping_rules_node):
"""Find a working mapping (with CrossSwitch)"""
if "children" not in mapping_rules_node:
return None
for rule in mapping_rules_node["children"]:
if rule.get("nodeType") == "folder":
# Find the caption (@ field)
caption = None
if "children" in rule:
for field in rule["children"]:
if field.get("name") == "@" and field.get("nodeType") == "string":
caption = field.get("value")
break
# Look for CrossSwitch or similar working mappings
if caption and ("CrossSwitch" in caption or "C_" in caption):
return rule
return None
print("="*70)
print("SEARCHING FOR MAPPING RULES")
print("="*70)
channel = grpc.insecure_channel('localhost:50051')
stub = configuration_pb2_grpc.ConfigurationServiceStub(channel)
print("\n1. Exporting configuration as JSON...")
export_request = configuration_pb2.ExportJsonRequest()
export_response = stub.ExportConfigurationJson(export_request)
if not export_response.success:
print(f" [ERROR] {export_response.error_message}")
sys.exit(1)
print(f" JSON size: {export_response.json_size} bytes")
config = json.loads(export_response.json_data)
print("\n2. Searching for MappingRules folder...")
# Search in rootNodes
mapping_rules = None
if "rootNodes" in config:
for node in config["rootNodes"]:
result, path = find_mapping_rules(node)
if result:
mapping_rules = result
print(f" Found MappingRules at: {path}/MappingRules")
break
if not mapping_rules:
print(" [ERROR] MappingRules not found!")
print("\n Top-level nodes:")
if "rootNodes" in config:
for i, node in enumerate(config["rootNodes"][:10]):
print(f" {i}: {node.get('name', 'unnamed')} ({node.get('nodeType', 'unknown')})")
sys.exit(1)
print(f"\n3. Found {len(mapping_rules.get('children', []))} rules")
# Find a working mapping
print("\n4. Looking for working mapping...")
working = find_working_mapping(mapping_rules)
if not working:
print(" [ERROR] No working mapping found!")
print("\n Listing all mappings:")
for rule in mapping_rules.get("children", []):
if rule.get("nodeType") == "folder":
caption = None
if "children" in rule:
for field in rule["children"]:
if field.get("name") == "@":
caption = field.get("value")
break
print(f" - Rule {rule.get('name')}: {caption}")
sys.exit(1)
# Get caption
caption = None
for field in working.get("children", []):
if field.get("name") == "@":
caption = field.get("value")
break
print(f"\n5. Found working mapping: '{caption}'")
print(f" Rule ID: {working.get('name')}")
print(f"\n6. Complete structure of working mapping:")
print(json.dumps(working, indent=2))
print(f"\n7. Field summary:")
for field in working.get("children", []):
field_type = field.get("nodeType")
field_name = field.get("name")
if field_type == "folder":
num_children = len(field.get("children", []))
print(f" - {field_name}/ (folder with {num_children} children)")
# Show children of this folder
for child in field.get("children", [])[:5]: # First 5 children
child_name = child.get("name")
child_type = child.get("nodeType")
if child_type == "string":
print(f" - {child_name} = \"{child.get('value', '')}\"")
elif child_type == "int32":
print(f" - {child_name} = {child.get('value', 0)}")
elif child_type == "folder":
print(f" - {child_name}/ (folder)")
elif field_type == "string":
print(f" - {field_name} = \"{field.get('value', '')}\"")
elif field_type == "int32":
print(f" - {field_name} = {field.get('value', 0)}")
else:
print(f" - {field_name} ({field_type})")
print("\n" + "="*70)
print("DONE")
print("="*70)