|
19 | 19 | #include "SystemFunctions.h" |
20 | 20 | #include "ConfigController.h" |
21 | 21 |
|
22 | | -#if defined(NEXTION_DISPLAY_DEVICE) |
23 | | -#include <NextionControl.h> |
24 | | -#include "BasePage.h" |
25 | | -#endif |
26 | | - |
27 | 22 | const char AckCommand[] = "ACK"; |
28 | 23 |
|
29 | 24 | AckCommandHandler::AckCommandHandler(BroadcastManager* broadcastManager, |
30 | | -#if defined(NEXTION_DISPLAY_DEVICE) |
31 | | - NextionControl* nextionControl, |
32 | | -#endif |
| 25 | + MessageBus* messageBus, |
33 | 26 | WarningManager* warningManager) |
34 | | - : BaseNextionCommandHandler(broadcastManager, |
35 | | -#if defined(NEXTION_DISPLAY_DEVICE) |
36 | | - nextionControl, |
37 | | -#endif |
38 | | - warningManager) |
| 27 | + : BaseNextionCommandHandler(broadcastManager, messageBus, warningManager) |
39 | 28 | { |
40 | 29 |
|
41 | 30 | } |
@@ -100,80 +89,88 @@ bool AckCommandHandler::handleCommand(SerialCommandManager* sender, const char* |
100 | 89 | // only process known ACK keys if you need to take action |
101 | 90 |
|
102 | 91 | #if defined(NEXTION_DISPLAY_DEVICE) |
103 | | - if (strcmp(params[0].key, RelayRetrieveStates) == 0 && strcmp(params[0].value, AckSuccess) == 0) |
104 | | - { |
105 | | - // Relay state acknowledgement - handle both formats: |
106 | | - // 1. ACK:R2=ok (just acknowledgement, no relay state - paramCount == 1) |
107 | | - // 2. ACK:R2=ok:0=0 (acknowledgement with relay state - paramCount == 2) |
108 | | - |
109 | | - if (paramCount >= 2) |
110 | | - { |
111 | | - // Format: ACK:R2=ok:0=0 (with relay index and state) |
112 | | - if (!SystemFunctions::isAllDigits(params[1].key) || !SystemFunctions::isAllDigits(params[1].value)) |
113 | | - { |
114 | | - sendDebugMessage(F("Invalid R2 Ack response"), F("AckCommandHandler")); |
115 | | - return true; |
116 | | - } |
| 92 | + if (strcmp(params[0].key, RelayRetrieveStates) == 0 && strcmp(params[0].value, AckSuccess) == 0) |
| 93 | + { |
| 94 | + if (paramCount >= 2) |
| 95 | + { |
| 96 | + if (!SystemFunctions::isAllDigits(params[1].key) || !SystemFunctions::isAllDigits(params[1].value)) |
| 97 | + { |
| 98 | + sendDebugMessage(F("Invalid R2 Ack response"), F("AckCommandHandler")); |
| 99 | + return true; |
| 100 | + } |
117 | 101 |
|
118 | 102 | uint8_t relayIndex = static_cast<uint8_t>(strtoul(params[1].key, nullptr, 0)); |
119 | | - bool isOn = SystemFunctions::parseBooleanValue(params[1].value); |
120 | | - |
121 | | - RelayStateUpdate update = { relayIndex, isOn }; |
122 | | - notifyCurrentPage(static_cast<uint8_t>(PageUpdateType::RelayState), &update); |
123 | | - } |
124 | | - } |
125 | | - else if (strcmp(params[0].key, RelayStatusGet) == 0 && strcmp(params[0].value, AckSuccess) == 0) |
126 | | - { |
127 | | - if (paramCount >= 2) |
128 | | - { |
| 103 | + if (relayIndex < ConfigRelayCount) |
| 104 | + { |
| 105 | + uint8_t changedMask = 1 << relayIndex; |
| 106 | + |
| 107 | + if (_messageBus) |
| 108 | + _messageBus->publish<RelayStatusChanged>(changedMask); |
| 109 | + } |
| 110 | + else |
| 111 | + { |
| 112 | + _broadcaster->sendDebug("ACK relay index out of range", AckCommand); |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + else if (strcmp(params[0].key, RelayStatusGet) == 0 && strcmp(params[0].value, AckSuccess) == 0) |
| 117 | + { |
| 118 | + if (paramCount >= 2) |
| 119 | + { |
129 | 120 | uint8_t relayIndex = static_cast<uint8_t>(strtoul(params[1].key, nullptr, 0)); |
130 | | - bool isOn = SystemFunctions::parseBooleanValue(params[1].value); |
131 | | - |
132 | | - RelayStateUpdate update = { relayIndex, isOn }; |
133 | | - notifyCurrentPage(static_cast<uint8_t>(PageUpdateType::RelayState), &update); |
134 | | - } |
135 | | - else |
136 | | - { |
| 121 | + if (relayIndex < ConfigRelayCount) |
| 122 | + { |
| 123 | + uint8_t changedMask = 1 << relayIndex; |
| 124 | + |
| 125 | + if (_messageBus) |
| 126 | + _messageBus->publish<RelayStatusChanged>(changedMask); |
| 127 | + } |
| 128 | + else |
| 129 | + { |
| 130 | + _broadcaster->sendDebug("ACK relay index out of range", AckCommand); |
| 131 | + } |
| 132 | + } |
| 133 | + else |
| 134 | + { |
137 | 135 | sendDebugMessage(F("Invalid R4 ACK format RelayStatusGet"), AckCommand); |
138 | | - } |
139 | | - } |
140 | | - else if (strcmp(params[0].key, SoundSignalActive) == 0 && strcmp(params[0].value, AckSuccess) == 0) |
141 | | - { |
142 | | - if (paramCount >= 2) |
143 | | - { |
144 | | - bool isOn = SystemFunctions::parseBooleanValue(params[1].value); |
145 | | - |
146 | | - BoolStateUpdate update = { isOn }; |
147 | | - notifyCurrentPage(static_cast<uint8_t>(PageUpdateType::SoundSignal), &update); |
148 | | - } |
149 | | - else |
150 | | - { |
| 136 | + } |
| 137 | + } |
| 138 | + else if (strcmp(params[0].key, SoundSignalActive) == 0 && strcmp(params[0].value, AckSuccess) == 0) |
| 139 | + { |
| 140 | + if (paramCount >= 2) |
| 141 | + { |
| 142 | + bool isOn = SystemFunctions::parseBooleanValue(params[1].value); |
| 143 | + if (_messageBus) |
| 144 | + _messageBus->publish<SoundSignalUpdated>(isOn); |
| 145 | + } |
| 146 | + else |
| 147 | + { |
151 | 148 | sendDebugMessage(F("Invalid R4 ACK format Sound Signal Active"), AckCommand); |
152 | 149 | } |
153 | 150 | } |
154 | 151 | else if (strcmp(params[0].key, SystemCpuUsage) == 0 && strcmp(params[0].value, AckSuccess) == 0) |
155 | | - { |
156 | | - if (paramCount >= 2) |
157 | | - { |
158 | | - uint8_t cpuUsage = static_cast<uint8_t>(strtoul(params[1].value, nullptr, 0)); |
159 | | - UInt8Update update = { cpuUsage }; |
160 | | - notifyCurrentPage(static_cast<uint8_t>(PageUpdateType::CpuUsage), &update); |
161 | | - } |
162 | | - else |
163 | | - { |
164 | | - sendDebugMessage(F("Invalid F3 ACK format: cpu"), AckCommand); |
165 | | - } |
166 | | - } |
167 | | - else if (strcmp(params[0].key, SystemFreeMemory) == 0 && strcmp(params[0].value, AckSuccess) == 0) |
168 | | - { |
169 | | - if (paramCount >= 2) |
170 | | - { |
171 | | - uint16_t freeMemory = static_cast<uint16_t>(strtoul(params[1].value, nullptr, 0)); |
172 | | - UInt16Update update = { freeMemory }; |
173 | | - notifyCurrentPage(static_cast<uint8_t>(PageUpdateType::MemoryUsage), &update); |
174 | | - } |
175 | | - else |
176 | | - { |
| 152 | + { |
| 153 | + if (paramCount >= 2) |
| 154 | + { |
| 155 | + uint8_t cpuUsage = static_cast<uint8_t>(strtoul(params[1].value, nullptr, 0)); |
| 156 | + if (_messageBus) |
| 157 | + _messageBus->publish<CpuUsageUpdated>(cpuUsage); |
| 158 | + } |
| 159 | + else |
| 160 | + { |
| 161 | + sendDebugMessage(F("Invalid F3 ACK format: cpu"), AckCommand); |
| 162 | + } |
| 163 | + } |
| 164 | + else if (strcmp(params[0].key, SystemFreeMemory) == 0 && strcmp(params[0].value, AckSuccess) == 0) |
| 165 | + { |
| 166 | + if (paramCount >= 2) |
| 167 | + { |
| 168 | + uint16_t freeMemory = static_cast<uint16_t>(strtoul(params[1].value, nullptr, 0)); |
| 169 | + if (_messageBus) |
| 170 | + _messageBus->publish<MemoryUsageUpdated>(freeMemory); |
| 171 | + } |
| 172 | + else |
| 173 | + { |
177 | 174 | sendDebugMessage(F("Invalid F2 ACK format free memory"), AckCommand); |
178 | 175 | } |
179 | 176 | } |
|
0 commit comments