Fixed MQTT and WS Routing - w/o SSL
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
#include "../ConfigManager/ConfigManager.hpp" // Configuration and settings
|
||||
#include "../Telemetry/Telemetry.hpp" // System monitoring and analytics
|
||||
#include "../OutputManager/OutputManager.hpp" // Hardware abstraction layer
|
||||
#include "../Communication/Communication.hpp" // Communication system for notifications
|
||||
#include "../Communication/CommunicationRouter/CommunicationRouter.hpp" // Communication system for notifications
|
||||
|
||||
// ═════════════════════════════════════════════════════════════════════════════════
|
||||
// CONSTRUCTOR & DESTRUCTOR IMPLEMENTATION
|
||||
@@ -94,7 +94,7 @@ void BellEngine::begin() {
|
||||
/**
|
||||
* @brief Set Communication manager reference for bell notifications
|
||||
*/
|
||||
void BellEngine::setCommunicationManager(Communication* commManager) {
|
||||
void BellEngine::setCommunicationManager(CommunicationRouter* commManager) {
|
||||
_communicationManager = commManager;
|
||||
LOG_DEBUG("BellEngine: Communication manager %s",
|
||||
commManager ? "connected" : "disconnected");
|
||||
@@ -181,6 +181,9 @@ void BellEngine::engineLoop() {
|
||||
|
||||
playbackLoop();
|
||||
|
||||
// Check telemetry for overloads and send notifications if needed
|
||||
checkAndNotifyOverloads();
|
||||
|
||||
// Pause handling AFTER complete loop - never interrupt mid-melody!
|
||||
while (_player.isPaused && _player.isPlaying && !_player.hardStop) {
|
||||
LOG_DEBUG("⏸️ Pausing between melody loops");
|
||||
@@ -241,15 +244,15 @@ void BellEngine::activateNote(uint16_t note) {
|
||||
|
||||
// Iterate through each bit position (note index)
|
||||
for (uint8_t noteIndex = 0; noteIndex < 16; noteIndex++) {
|
||||
if (note & (1 << noteIndex)) {
|
||||
// Get bell mapping
|
||||
uint8_t bellIndex = _player.noteAssignments[noteIndex];
|
||||
if (note & (1 << noteIndex)) {
|
||||
// Get bell mapping (noteAssignments stored as 1-indexed)
|
||||
uint8_t bellConfig = _player.noteAssignments[noteIndex];
|
||||
|
||||
// Skip if no bell assigned
|
||||
if (bellIndex == 0) continue;
|
||||
// Skip if no bell assigned
|
||||
if (bellConfig == 0) continue;
|
||||
|
||||
// Convert to 0-based indexing
|
||||
bellIndex = bellIndex - 1;
|
||||
// Convert 1-indexed config to 0-indexed bellIndex
|
||||
uint8_t bellIndex = bellConfig - 1;
|
||||
|
||||
// Additional safety check to prevent underflow crashes
|
||||
if (bellIndex >= 255) {
|
||||
@@ -373,12 +376,6 @@ bool BellEngine::isHealthy() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if we're not in emergency stop state
|
||||
if (_emergencyStop.load()) {
|
||||
LOG_DEBUG("BellEngine: Unhealthy - Emergency stop active");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if OutputManager is properly connected and healthy
|
||||
if (!_outputManager.isInitialized()) {
|
||||
LOG_DEBUG("BellEngine: Unhealthy - OutputManager not initialized");
|
||||
@@ -387,3 +384,48 @@ bool BellEngine::isHealthy() const {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BellEngine::checkAndNotifyOverloads() {
|
||||
if (!_communicationManager) {
|
||||
return; // No communication manager available
|
||||
}
|
||||
|
||||
// Collect overloaded bells from telemetry
|
||||
std::vector<uint8_t> criticalBells;
|
||||
std::vector<uint16_t> criticalLoads;
|
||||
std::vector<uint8_t> warningBells;
|
||||
std::vector<uint16_t> warningLoads;
|
||||
|
||||
bool hasOverload = false;
|
||||
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
uint16_t load = _telemetry.getBellLoad(i);
|
||||
if (load == 0) continue; // Skip inactive bells
|
||||
|
||||
if (_telemetry.isOverloaded(i)) {
|
||||
criticalBells.push_back(i);
|
||||
criticalLoads.push_back(load);
|
||||
hasOverload = true;
|
||||
} else {
|
||||
// Check thresholds - get max load for this bell (assume 60 default)
|
||||
uint16_t criticalThreshold = 54; // 90% of 60
|
||||
uint16_t warningThreshold = 36; // 60% of 60
|
||||
|
||||
if (load > criticalThreshold) {
|
||||
criticalBells.push_back(i);
|
||||
criticalLoads.push_back(load);
|
||||
} else if (load > warningThreshold) {
|
||||
warningBells.push_back(i);
|
||||
warningLoads.push_back(load);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send notifications if needed
|
||||
if (!criticalBells.empty()) {
|
||||
String severity = hasOverload ? "critical" : "warning";
|
||||
_communicationManager->sendBellOverloadNotification(criticalBells, criticalLoads, severity);
|
||||
} else if (!warningBells.empty()) {
|
||||
_communicationManager->sendBellOverloadNotification(warningBells, warningLoads, "warning");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user