From 06b69da78fa1b8bcc332526d85fcae65e7262644 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Wed, 14 Feb 2024 02:08:09 +0700 Subject: [PATCH] expand mqtt callbacks from 2^8 to 2^16 --- .../lib/ESPMegaPRO/ESPMegaIoT.cpp | 12 +++++----- .../lib/ESPMegaPRO/ESPMegaIoT.hpp | 24 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.cpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.cpp index b6f2a8f..60a14b2 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.cpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.cpp @@ -377,7 +377,7 @@ void ESPMegaIoT::publish(const char *topic, const char *payload) * @param callback The callback function * @return The handler for the callback */ -uint8_t ESPMegaIoT::registerMqttCallback(std::function callback) +uint16_t ESPMegaIoT::registerMqttCallback(std::function callback) { mqtt_callbacks[mqtt_callbacks_handler_index] = callback; return mqtt_callbacks_handler_index++; @@ -388,7 +388,7 @@ uint8_t ESPMegaIoT::registerMqttCallback(std::function cal * * @param handler The handler of the callback */ -void ESPMegaIoT::unregisterMqttCallback(uint8_t handler) +void ESPMegaIoT::unregisterMqttCallback(uint16_t handler) { mqtt_callbacks.erase(handler); } @@ -479,7 +479,7 @@ void ESPMegaIoT::sessionKeepAlive() * @param callback The callback function * @return The handler for the callback */ -uint8_t ESPMegaIoT::registerRelativeMqttCallback(std::function callback) +uint16_t ESPMegaIoT::registerRelativeMqttCallback(std::function callback) { mqtt_relative_callbacks[mqtt_relative_callbacks_handler_index] = callback; return mqtt_relative_callbacks_handler_index++; @@ -490,7 +490,7 @@ uint8_t ESPMegaIoT::registerRelativeMqttCallback(std::function callback) +uint16_t ESPMegaIoT::registerSubscribeCallback(std::function callback) { subscribe_callbacks[subscribe_callbacks_handler_index] = callback; return subscribe_callbacks_handler_index++; @@ -539,7 +539,7 @@ uint8_t ESPMegaIoT::registerSubscribeCallback(std::function callback * * @param handler The handler of the callback */ -void ESPMegaIoT::unregisterSubscribeCallback(uint8_t handler) +void ESPMegaIoT::unregisterSubscribeCallback(uint16_t handler) { subscribe_callbacks.erase(handler); } diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.hpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.hpp index 74f5dd2..c5467b2 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.hpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.hpp @@ -105,12 +105,12 @@ public: bool mqttConnected(); void disconnectFromMqtt(); void publish(const char *topic, const char *payload); - uint8_t registerMqttCallback(std::function callback); - void unregisterMqttCallback(uint8_t handler); - uint8_t registerRelativeMqttCallback(std::function callback); - void unregisterRelativeMqttCallback(uint8_t handler); - uint8_t registerSubscribeCallback(std::function callback); - void unregisterSubscribeCallback(uint8_t handler); + uint16_t registerMqttCallback(std::function callback); + void unregisterMqttCallback(uint16_t handler); + uint16_t registerRelativeMqttCallback(std::function callback); + void unregisterRelativeMqttCallback(uint16_t handler); + uint16_t registerSubscribeCallback(std::function callback); + void unregisterSubscribeCallback(uint16_t handler); void setBaseTopic(char *base_topic); void bindEthernetInterface(ETHClass *ethernetIface); bool networkConnected(); @@ -137,12 +137,12 @@ private: void wifiReconnect(); void mqttSubscribe(); void mqttCallback(char *topic, byte *payload, unsigned int length); - uint8_t mqtt_callbacks_handler_index; - uint8_t mqtt_relative_callbacks_handler_index; - uint8_t subscribe_callbacks_handler_index; - std::map> mqtt_callbacks; - std::map> mqtt_relative_callbacks; - std::map> subscribe_callbacks; + uint16_t mqtt_callbacks_handler_index; + uint16_t mqtt_relative_callbacks_handler_index; + uint16_t subscribe_callbacks_handler_index; + std::map> mqtt_callbacks; + std::map> mqtt_relative_callbacks; + std::map> subscribe_callbacks; void publishRelative(uint8_t card_id, char *topic, char *payload); bool active; PubSubClient mqtt;