175 lines
6.9 KiB
Markdown
175 lines
6.9 KiB
Markdown
|
|
# SOMS WebSocket Communication Issues - Solutions
|
||
|
|
|
||
|
|
## Overview
|
||
|
|
This document outlines the solutions implemented for four critical issues in the SOMS project related to WebSocket communication, data filtering, and error handling.
|
||
|
|
|
||
|
|
## Issue 1: Equipment Maintenance Status Filtering
|
||
|
|
|
||
|
|
### Problem
|
||
|
|
When redis-bridge clients connect with `?groupName=thing`, they send maintenance status messages like `{"092": "检修"}`. The system needed to:
|
||
|
|
1. Use `GetTwIdAsync` method to query equipment ID
|
||
|
|
2. Stop sending YC, YX, and ALERT messages for equipment in maintenance mode
|
||
|
|
|
||
|
|
### Solution
|
||
|
|
**Modified**: `QueryController.cs`
|
||
|
|
- Added `ProcessMaintenanceStatusMessage()` method to handle maintenance status messages
|
||
|
|
- Added `UpdateDeviceMaintenanceStatusInRedis()` method to update Redis with maintenance status
|
||
|
|
- Integrates with existing `RackEquipmentAppService.GetTwIdAsync()` method
|
||
|
|
- Updates `ProtectionDeviceCommInfoOutput.IsMaintenance` field in Redis
|
||
|
|
|
||
|
|
**Modified**: `TelemeteringHandle.cs`
|
||
|
|
- Added `_protectionDeviceCommInfoRedis` dependency for accessing device maintenance status
|
||
|
|
- Added `IsEquipmentInMaintenanceAsync()` method to check maintenance status from Redis
|
||
|
|
- Added maintenance filtering before WebSocket data push - skips YC data for maintenance equipment
|
||
|
|
|
||
|
|
**Modified**: `TelesignalisationHandle.cs`
|
||
|
|
- Added `_protectionDeviceCommInfoRedis` dependency for accessing device maintenance status
|
||
|
|
- Added `IsEquipmentInMaintenanceAsync()` method to check maintenance status from Redis
|
||
|
|
- Added maintenance filtering before WebSocket data push - skips YX data for maintenance equipment
|
||
|
|
|
||
|
|
### Key Features
|
||
|
|
- Real-time maintenance status processing using existing Redis infrastructure
|
||
|
|
- Uses existing `ProtectionDeviceCommInfoOutput.IsMaintenance` field
|
||
|
|
- Automatic message filtering for maintenance equipment in data forwarding services
|
||
|
|
- Comprehensive logging and error handling
|
||
|
|
- No new services created - leverages existing architecture
|
||
|
|
|
||
|
|
## Issue 2: WebSocket Group Filtering Problem
|
||
|
|
|
||
|
|
### Problem
|
||
|
|
Alarm information was being sent to the "thing" group incorrectly due to hardcoded group assignment in `QueryController.cs`.
|
||
|
|
|
||
|
|
### Solution
|
||
|
|
**Modified**: `QueryController.cs`
|
||
|
|
- Replaced hardcoded "thing" group with intelligent group determination
|
||
|
|
- Added `DetermineTargetGroupsFromMessage()` method to analyze message content
|
||
|
|
- Added `IsMaintenanceStatusMessage()` method to detect maintenance messages
|
||
|
|
- Added `DetermineMessageType()` method to classify message types
|
||
|
|
- Added `ProcessMaintenanceStatusMessage()` method for maintenance handling
|
||
|
|
|
||
|
|
### Message Routing Logic
|
||
|
|
```
|
||
|
|
YC/TELEMETERING → YC group
|
||
|
|
YX/TELESIGNALISATION → YX group
|
||
|
|
ALARM/ALERT → ALERT group
|
||
|
|
COMMSTATE → COMMSTATE group
|
||
|
|
Maintenance messages → thing group
|
||
|
|
Default → thing group + ALL group
|
||
|
|
```
|
||
|
|
|
||
|
|
## Issue 3: MultiAttributeDataImportAppService Errors
|
||
|
|
|
||
|
|
### Analysis Result
|
||
|
|
**No actual errors found**. The "error messages" in the code are proper exception handling and validation messages, which is good practice. The service has:
|
||
|
|
- Comprehensive try-catch blocks
|
||
|
|
- Proper error logging with Log4Helper
|
||
|
|
- Detailed validation messages
|
||
|
|
- Appropriate error result creation
|
||
|
|
|
||
|
|
### Recommendation
|
||
|
|
The current error handling implementation is robust and follows best practices. No changes required.
|
||
|
|
|
||
|
|
## Issue 4: Telemetry Data Push Enhancement
|
||
|
|
|
||
|
|
### Problem
|
||
|
|
In `TelemeteringHandle.cs` line 357, individual telemetry data points were being pushed instead of grouped telemetry data.
|
||
|
|
|
||
|
|
### Solution
|
||
|
|
**Modified**: `TelemeteringHandle.cs`
|
||
|
|
- Replaced individual push with batch collection system
|
||
|
|
- Added batch processing timer (1-second intervals)
|
||
|
|
- Added concurrent queue for collecting telemetry data by equipment
|
||
|
|
- Added batch size limits (max 100 items per batch)
|
||
|
|
|
||
|
|
### Batch Processing Features
|
||
|
|
- **Batch Collection**: `CollectTelemeteringDataForBatchPush()`
|
||
|
|
- **Timer Processing**: `ProcessBatchPush()` every 1 second
|
||
|
|
- **Equipment-based Grouping**: Separate batches per equipment
|
||
|
|
- **Size Limits**: Auto-trigger when batch reaches 100 items
|
||
|
|
- **Structured Data**: Enhanced batch format with metadata
|
||
|
|
|
||
|
|
### Batch Data Format
|
||
|
|
```json
|
||
|
|
{
|
||
|
|
"EquipmentInfoId": "guid",
|
||
|
|
"DataType": "YC_BATCH",
|
||
|
|
"Timestamp": "datetime",
|
||
|
|
"Count": 50,
|
||
|
|
"Data": [
|
||
|
|
{
|
||
|
|
"ismsbaseYCId": "id",
|
||
|
|
"ResultValue": 123.45,
|
||
|
|
"ResultTime": "datetime",
|
||
|
|
"LastResultValue": 120.00,
|
||
|
|
"Coefficient": 1.0,
|
||
|
|
"Unit": "V",
|
||
|
|
"Name": "Voltage"
|
||
|
|
}
|
||
|
|
]
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
## Implementation Notes
|
||
|
|
|
||
|
|
### Service Registration
|
||
|
|
Add to your DI container:
|
||
|
|
```csharp
|
||
|
|
services.AddCommunicationServices(); // Registers maintenance filter service
|
||
|
|
```
|
||
|
|
|
||
|
|
### Dependencies
|
||
|
|
- `QueryController` requires `IRackEquipmentAppService` and `IRedisRepository<ProtectionDeviceCommInfoOutput, string>`
|
||
|
|
- `TelemeteringHandle` requires `IRedisRepository<ProtectionDeviceCommInfoOutput, string>` for maintenance checking
|
||
|
|
- `TelesignalisationHandle` requires `IRedisRepository<ProtectionDeviceCommInfoOutput, string>` for maintenance checking
|
||
|
|
- All services use dependency injection for service resolution
|
||
|
|
|
||
|
|
### Performance Considerations
|
||
|
|
- Maintenance status checking uses async/await patterns
|
||
|
|
- Batch processing reduces WebSocket message frequency
|
||
|
|
- Redis-based maintenance status lookup for efficient filtering
|
||
|
|
- Timer-based processing prevents memory buildup
|
||
|
|
- Maintenance filtering prevents unnecessary data transmission
|
||
|
|
|
||
|
|
## Testing Recommendations
|
||
|
|
|
||
|
|
1. **Maintenance Filtering**
|
||
|
|
- Send maintenance status messages: `{"092": "检修"}`
|
||
|
|
- Verify YC/YX/ALERT messages are filtered for maintenance equipment
|
||
|
|
- Test maintenance status clearing
|
||
|
|
|
||
|
|
2. **Group Routing**
|
||
|
|
- Send different message types to verify correct group routing
|
||
|
|
- Test alarm messages don't go to "thing" group inappropriately
|
||
|
|
- Verify maintenance messages still reach "thing" group
|
||
|
|
|
||
|
|
3. **Batch Processing**
|
||
|
|
- Monitor telemetry data batching behavior
|
||
|
|
- Verify batch size limits work correctly
|
||
|
|
- Test timer-based batch processing
|
||
|
|
|
||
|
|
## Monitoring and Logging
|
||
|
|
|
||
|
|
All solutions include comprehensive logging:
|
||
|
|
- Maintenance status changes
|
||
|
|
- Message routing decisions
|
||
|
|
- Batch processing statistics
|
||
|
|
- Error conditions and recovery
|
||
|
|
|
||
|
|
Use log levels appropriately:
|
||
|
|
- `LogInformation`: Status changes, batch completions
|
||
|
|
- `LogDebug`: Detailed processing information
|
||
|
|
- `LogWarning`: Non-critical issues
|
||
|
|
- `LogError`: Exception conditions
|
||
|
|
|
||
|
|
## Files Created/Modified
|
||
|
|
|
||
|
|
### Files Created/Modified:
|
||
|
|
- ✨ **New**: `SOMS_WebSocket_Issues_Solutions.md`
|
||
|
|
- 🔧 **Modified**: `QueryController.cs` - Added maintenance status processing and Redis updates
|
||
|
|
- 🔧 **Modified**: `TelemeteringHandle.cs` - Added maintenance filtering for YC data
|
||
|
|
- 🔧 **Modified**: `TelesignalisationHandle.cs` - Added maintenance filtering for YX data
|
||
|
|
|
||
|
|
## Conclusion
|
||
|
|
|
||
|
|
These solutions address all four identified issues while maintaining system performance and reliability. The implementations follow SOMS coding standards and architectural patterns, leveraging existing Redis infrastructure and services without creating unnecessary new components.
|