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>
190 lines
6.1 KiB
C#
190 lines
6.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using GeViSetEditor.Core.Models;
|
|
|
|
namespace GeViSetEditor.Core.Parsers
|
|
{
|
|
/// <summary>
|
|
/// Safe parser that preserves original binary data for round-trip conversion
|
|
/// Only parses action mappings, keeps everything else as-is
|
|
/// </summary>
|
|
public class SafeSetFileParser
|
|
{
|
|
private byte[] _originalData;
|
|
private int _position;
|
|
|
|
public SafeSetFile Parse(byte[] data)
|
|
{
|
|
_originalData = data;
|
|
_position = 0;
|
|
|
|
var setFile = new SafeSetFile
|
|
{
|
|
OriginalData = data,
|
|
FileSize = data.Length
|
|
};
|
|
|
|
// Read header
|
|
if (_position < data.Length && data[_position] == 0x00)
|
|
_position++;
|
|
|
|
string header = ReadPascalString();
|
|
setFile.Header = header ?? "GeViSoft Parameters";
|
|
|
|
Console.WriteLine($"Parsing .set file: {data.Length} bytes, header: '{setFile.Header}'");
|
|
|
|
// Find and extract all action mappings without disturbing the rest
|
|
ExtractActionMappings(setFile);
|
|
|
|
return setFile;
|
|
}
|
|
|
|
private void ExtractActionMappings(SafeSetFile setFile)
|
|
{
|
|
// Search for all "Rules" patterns (05 52 75 6C 65 73)
|
|
byte[] rulesPattern = new byte[] { 0x05, 0x52, 0x75, 0x6C, 0x65, 0x73 };
|
|
|
|
for (int i = 0; i < _originalData.Length - rulesPattern.Length - 100; i++)
|
|
{
|
|
if (MatchesPattern(_originalData, i, rulesPattern))
|
|
{
|
|
var mapping = TryExtractActionMapping(i);
|
|
if (mapping != null)
|
|
{
|
|
setFile.ActionMappings.Add(mapping);
|
|
}
|
|
}
|
|
}
|
|
|
|
Console.WriteLine($"Extracted {setFile.ActionMappings.Count} action mappings");
|
|
}
|
|
|
|
private ActionMappingEntry TryExtractActionMapping(int rulesOffset)
|
|
{
|
|
try
|
|
{
|
|
var entry = new ActionMappingEntry
|
|
{
|
|
FileOffset = rulesOffset,
|
|
RulesMarkerOffset = rulesOffset
|
|
};
|
|
|
|
// Position after "Rules" marker
|
|
int pos = rulesOffset + 6; // Skip "05 Rules"
|
|
|
|
// Read what appears to be count/metadata
|
|
if (pos + 10 > _originalData.Length) return null;
|
|
|
|
// Skip metadata bytes
|
|
while (pos < _originalData.Length && _originalData[pos] <= 0x04)
|
|
{
|
|
pos++;
|
|
}
|
|
|
|
// Store start of action data
|
|
int actionDataStart = pos;
|
|
|
|
// Extract action strings using pattern 07 01 40 <len_2bytes> <data>
|
|
var actions = new List<string>();
|
|
int consecutiveFailures = 0;
|
|
int maxAttempts = 200;
|
|
|
|
while (maxAttempts-- > 0 && pos < _originalData.Length - 10)
|
|
{
|
|
var action = TryReadActionStringAt(pos);
|
|
if (action != null)
|
|
{
|
|
actions.Add(action);
|
|
pos += 5 + Encoding.UTF8.GetByteCount(action); // 07 01 40 + 2-byte len + data
|
|
consecutiveFailures = 0;
|
|
}
|
|
else
|
|
{
|
|
pos++;
|
|
consecutiveFailures++;
|
|
if (consecutiveFailures > 100) break;
|
|
}
|
|
}
|
|
|
|
if (actions.Count > 0)
|
|
{
|
|
entry.Actions = actions;
|
|
entry.ActionDataStartOffset = actionDataStart;
|
|
entry.ActionDataEndOffset = pos;
|
|
|
|
// Store original bytes for this mapping
|
|
int length = pos - rulesOffset;
|
|
entry.OriginalBytes = new byte[length];
|
|
Array.Copy(_originalData, rulesOffset, entry.OriginalBytes, 0, length);
|
|
|
|
return entry;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Error extracting mapping at offset {rulesOffset}: {ex.Message}");
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private string TryReadActionStringAt(int pos)
|
|
{
|
|
// Pattern: 07 01 40 <len_2bytes> <data>
|
|
if (pos + 5 > _originalData.Length) return null;
|
|
|
|
if (_originalData[pos] != 0x07 ||
|
|
_originalData[pos + 1] != 0x01 ||
|
|
_originalData[pos + 2] != 0x40)
|
|
return null;
|
|
|
|
int length = BitConverter.ToUInt16(_originalData, pos + 3);
|
|
if (length == 0 || length > 500 || pos + 5 + length > _originalData.Length)
|
|
return null;
|
|
|
|
try
|
|
{
|
|
string result = Encoding.UTF8.GetString(_originalData, pos + 5, length);
|
|
|
|
// Validate it looks like an action string
|
|
if (string.IsNullOrWhiteSpace(result) || result.Length < 3)
|
|
return null;
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private bool MatchesPattern(byte[] data, int offset, byte[] pattern)
|
|
{
|
|
if (offset + pattern.Length > data.Length)
|
|
return false;
|
|
|
|
for (int i = 0; i < pattern.Length; i++)
|
|
{
|
|
if (data[offset + i] != pattern[i])
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private string ReadPascalString()
|
|
{
|
|
if (_position + 2 > _originalData.Length || _originalData[_position] != 0x07)
|
|
return null;
|
|
|
|
byte length = _originalData[_position + 1];
|
|
if (_position + 2 + length > _originalData.Length || length == 0)
|
|
return null;
|
|
|
|
string result = Encoding.UTF8.GetString(_originalData, _position + 2, length);
|
|
_position += 2 + length;
|
|
return result;
|
|
}
|
|
}
|
|
}
|