mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-09-12 01:24:04 +00:00
[Controller Queue] Reduce bin size by using inheritance
This commit is contained in:
+3
-1
@@ -112,7 +112,9 @@ bool CPlugin_001(CPlugin::Function function, struct EventStruct *event, String&
|
||||
url += mapVccToDomoticz();
|
||||
# endif // if FEATURE_ADC_VCC
|
||||
|
||||
success = C001_DelayHandler->addToQueue(C001_queue_element(event->ControllerIndex, event->TaskIndex, std::move(url)));
|
||||
std::unique_ptr<C001_queue_element> element(new C001_queue_element(event->ControllerIndex, event->TaskIndex, std::move(url)));
|
||||
|
||||
success = C001_DelayHandler->addToQueue(std::move(element));
|
||||
Scheduler.scheduleNextDelayQueue(ESPEasy_Scheduler::IntervalTimer_e::TIMER_C001_DELAY_QUEUE,
|
||||
C001_DelayHandler->getNextScheduleTime());
|
||||
}
|
||||
|
||||
+4
-1
@@ -56,7 +56,10 @@ bool CPlugin_003(CPlugin::Function function, struct EventStruct *event, String&
|
||||
url += ',';
|
||||
url += formatUserVarNoCheck(event, 0);
|
||||
url += '\n';
|
||||
success = C003_DelayHandler->addToQueue(C003_queue_element(event->ControllerIndex, event->TaskIndex, std::move(url)));
|
||||
|
||||
std::unique_ptr<C003_queue_element> element(new C003_queue_element(event->ControllerIndex, event->TaskIndex, std::move(url)));
|
||||
|
||||
success = C003_DelayHandler->addToQueue(std::move(element));
|
||||
Scheduler.scheduleNextDelayQueue(ESPEasy_Scheduler::IntervalTimer_e::TIMER_C003_DELAY_QUEUE, C003_DelayHandler->getNextScheduleTime());
|
||||
|
||||
break;
|
||||
|
||||
+3
-1
@@ -67,7 +67,9 @@ bool CPlugin_004(CPlugin::Function function, struct EventStruct *event, String&
|
||||
if (C004_DelayHandler == nullptr) {
|
||||
break;
|
||||
}
|
||||
success = C004_DelayHandler->addToQueue(C004_queue_element(event));
|
||||
std::unique_ptr<C004_queue_element> element(new C004_queue_element(event));
|
||||
|
||||
success = C004_DelayHandler->addToQueue(std::move(element));
|
||||
Scheduler.scheduleNextDelayQueue(ESPEasy_Scheduler::IntervalTimer_e::TIMER_C004_DELAY_QUEUE, C004_DelayHandler->getNextScheduleTime());
|
||||
|
||||
break;
|
||||
|
||||
+4
-1
@@ -63,7 +63,10 @@ bool CPlugin_007(CPlugin::Function function, struct EventStruct *event, String&
|
||||
addLog(LOG_LEVEL_ERROR, F("emoncms : Unknown sensortype or too many sensor values"));
|
||||
break;
|
||||
}
|
||||
success = C007_DelayHandler->addToQueue(C007_queue_element(event));
|
||||
|
||||
std::unique_ptr<C007_queue_element> element(new C007_queue_element(event));
|
||||
success = C007_DelayHandler->addToQueue(std::move(element));
|
||||
|
||||
Scheduler.scheduleNextDelayQueue(ESPEasy_Scheduler::IntervalTimer_e::TIMER_C007_DELAY_QUEUE, C007_DelayHandler->getNextScheduleTime());
|
||||
break;
|
||||
}
|
||||
|
||||
+6
-2
@@ -75,13 +75,17 @@ bool CPlugin_008(CPlugin::Function function, struct EventStruct *event, String&
|
||||
|
||||
|
||||
uint8_t valueCount = getValueCountForTask(event->TaskIndex);
|
||||
success = C008_DelayHandler->addToQueue(C008_queue_element(event, valueCount));
|
||||
|
||||
|
||||
|
||||
std::unique_ptr<C008_queue_element> element(new C008_queue_element(event, valueCount));
|
||||
success = C008_DelayHandler->addToQueue(std::move(element));
|
||||
|
||||
if (success) {
|
||||
// Element was added.
|
||||
// Now we try to append to the existing element
|
||||
// and thus preventing the need to create a long string only to copy it to a queue element.
|
||||
C008_queue_element& element = C008_DelayHandler->sendQueue.back();
|
||||
C008_queue_element& element = static_cast<C008_queue_element&>(*(C008_DelayHandler->sendQueue.back()));
|
||||
|
||||
// Collect the values at the same run, to make sure all are from the same sample
|
||||
//LoadTaskSettings(event->TaskIndex); // FIXME TD-er: This can probably be removed
|
||||
|
||||
+3
-6
@@ -74,14 +74,11 @@ bool CPlugin_009(CPlugin::Function function, struct EventStruct *event, String&
|
||||
|
||||
case CPlugin::Function::CPLUGIN_PROTOCOL_SEND:
|
||||
{
|
||||
if (C009_DelayHandler == nullptr) {
|
||||
break;
|
||||
}
|
||||
{
|
||||
C009_queue_element element(event);
|
||||
if (C009_DelayHandler != nullptr) {
|
||||
std::unique_ptr<C009_queue_element> element(new C009_queue_element(event));
|
||||
success = C009_DelayHandler->addToQueue(std::move(element));
|
||||
Scheduler.scheduleNextDelayQueue(ESPEasy_Scheduler::IntervalTimer_e::TIMER_C009_DELAY_QUEUE, C009_DelayHandler->getNextScheduleTime());
|
||||
}
|
||||
Scheduler.scheduleNextDelayQueue(ESPEasy_Scheduler::IntervalTimer_e::TIMER_C009_DELAY_QUEUE, C009_DelayHandler->getNextScheduleTime());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
+7
-5
@@ -64,7 +64,9 @@ bool CPlugin_010(CPlugin::Function function, struct EventStruct *event, String&
|
||||
}
|
||||
|
||||
//LoadTaskSettings(event->TaskIndex); // FIXME TD-er: This can probably be removed
|
||||
C010_queue_element element(event, valueCount);
|
||||
|
||||
std::unique_ptr<C010_queue_element> element(new C010_queue_element(event, valueCount));
|
||||
|
||||
|
||||
{
|
||||
String pubname;
|
||||
@@ -86,12 +88,12 @@ bool CPlugin_010(CPlugin::Function function, struct EventStruct *event, String&
|
||||
const String formattedValue = formatUserVar(event, x, isvalid);
|
||||
|
||||
if (isvalid) {
|
||||
element.txt[x] = pubname;
|
||||
parseSingleControllerVariable(element.txt[x], event, x, false);
|
||||
element.txt[x].replace(F("%value%"), formattedValue);
|
||||
element->txt[x] = pubname;
|
||||
parseSingleControllerVariable(element->txt[x], event, x, false);
|
||||
element->txt[x].replace(F("%value%"), formattedValue);
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
if (loglevelActiveFor(LOG_LEVEL_DEBUG_MORE))
|
||||
addLog(LOG_LEVEL_DEBUG_MORE, element.txt[x]);
|
||||
addLog(LOG_LEVEL_DEBUG_MORE, element->txt[x]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -258,13 +258,15 @@ boolean Create_schedule_HTTP_C011(struct EventStruct *event)
|
||||
//LoadTaskSettings(event->TaskIndex); // FIXME TD-er: This can probably be removed
|
||||
|
||||
// Add a new element to the queue with the minimal payload
|
||||
bool success = C011_DelayHandler->addToQueue(C011_queue_element(event));
|
||||
std::unique_ptr<C011_queue_element> element(new C011_queue_element(event));
|
||||
bool success = C011_DelayHandler->addToQueue(std::move(element));
|
||||
|
||||
if (success) {
|
||||
// Element was added.
|
||||
// Now we try to append to the existing element
|
||||
// and thus preventing the need to create a long string only to copy it to a queue element.
|
||||
C011_queue_element& element = C011_DelayHandler->sendQueue.back();
|
||||
C011_queue_element& element = static_cast<C011_queue_element&>(*(C011_DelayHandler->sendQueue.back()));
|
||||
|
||||
|
||||
if (!load_C011_ConfigStruct(event->ControllerIndex, element.HttpMethod, element.uri, element.header, element.postStr))
|
||||
{
|
||||
|
||||
+6
-6
@@ -56,7 +56,7 @@ bool CPlugin_012(CPlugin::Function function, struct EventStruct *event, String&
|
||||
|
||||
// Collect the values at the same run, to make sure all are from the same sample
|
||||
uint8_t valueCount = getValueCountForTask(event->TaskIndex);
|
||||
C012_queue_element element(event, valueCount);
|
||||
std::unique_ptr<C012_queue_element> element(new C012_queue_element(event, valueCount));
|
||||
|
||||
for (uint8_t x = 0; x < valueCount; x++)
|
||||
{
|
||||
@@ -64,13 +64,13 @@ bool CPlugin_012(CPlugin::Function function, struct EventStruct *event, String&
|
||||
const String formattedValue = formatUserVar(event, x, isvalid);
|
||||
|
||||
if (isvalid) {
|
||||
element.txt[x] = F("update/V");
|
||||
element.txt[x] += event->idx + x;
|
||||
element.txt[x] += F("?value=");
|
||||
element.txt[x] += formattedValue;
|
||||
element->txt[x] = F("update/V");
|
||||
element->txt[x] += event->idx + x;
|
||||
element->txt[x] += F("?value=");
|
||||
element->txt[x] += formattedValue;
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
if (loglevelActiveFor(LOG_LEVEL_DEBUG_MORE)) {
|
||||
addLog(LOG_LEVEL_DEBUG_MORE, element.txt[x]);
|
||||
addLog(LOG_LEVEL_DEBUG_MORE, element->txt[x]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
+3
-3
@@ -180,14 +180,14 @@ bool CPlugin_015(CPlugin::Function function, struct EventStruct *event, String&
|
||||
// Collect the values at the same run, to make sure all are from the same sample
|
||||
uint8_t valueCount = getValueCountForTask(event->TaskIndex);
|
||||
|
||||
|
||||
success = C015_DelayHandler->addToQueue(C015_queue_element(event, valueCount));
|
||||
std::unique_ptr<C015_queue_element> element(new C015_queue_element(event, valueCount));
|
||||
success = C015_DelayHandler->addToQueue(std::move(element));
|
||||
|
||||
if (success) {
|
||||
// Element was added.
|
||||
// Now we try to append to the existing element
|
||||
// and thus preventing the need to create a long string only to copy it to a queue element.
|
||||
C015_queue_element& element = C015_DelayHandler->sendQueue.back();
|
||||
C015_queue_element& element = static_cast<C015_queue_element&>(*(C015_DelayHandler->sendQueue.back()));
|
||||
|
||||
for (uint8_t x = 0; x < valueCount; x++)
|
||||
{
|
||||
|
||||
+6
-3
@@ -113,15 +113,18 @@ bool CPlugin_016(CPlugin::Function function, struct EventStruct *event, String&
|
||||
{
|
||||
// Collect the values at the same run, to make sure all are from the same sample
|
||||
uint8_t valueCount = getValueCountForTask(event->TaskIndex);
|
||||
C016_queue_element element(
|
||||
const C016_queue_element element(
|
||||
event,
|
||||
valueCount,
|
||||
C016_allowLocalSystemTime ? node_time.now() : node_time.getUnixTime());
|
||||
|
||||
|
||||
C016_binary_element binary_element = element.getBinary();
|
||||
// It makes no sense to keep the controller index when storing it.
|
||||
// re-purpose it to store the pluginID
|
||||
element.setPluginID_insteadOf_controller_idx();
|
||||
success = ControllerCache.write(reinterpret_cast<const uint8_t *>(&element), sizeof(element));
|
||||
binary_element.setPluginID_insteadOf_controller_idx();
|
||||
|
||||
success = ControllerCache.write(reinterpret_cast<const uint8_t *>(&binary_element), sizeof(C016_binary_element));
|
||||
|
||||
/*
|
||||
if (C016_DelayHandler == nullptr) {
|
||||
|
||||
+2
-1
@@ -64,7 +64,8 @@ bool CPlugin_017(CPlugin::Function function, struct EventStruct *event, String&
|
||||
break;
|
||||
}
|
||||
|
||||
success = C017_DelayHandler->addToQueue(C017_queue_element(event));
|
||||
std::unique_ptr<C017_queue_element> element(new C017_queue_element(event));
|
||||
success = C017_DelayHandler->addToQueue(std::move(element));
|
||||
Scheduler.scheduleNextDelayQueue(ESPEasy_Scheduler::IntervalTimer_e::TIMER_C017_DELAY_QUEUE, C017_DelayHandler->getNextScheduleTime());
|
||||
break;
|
||||
}
|
||||
|
||||
+2
-2
@@ -840,8 +840,8 @@ bool CPlugin_018(CPlugin::Function function, struct EventStruct *event, String&
|
||||
}
|
||||
|
||||
if (C018_data != nullptr) {
|
||||
success = C018_DelayHandler->addToQueue(
|
||||
std::move(C018_queue_element(event, C018_data->getSampleSetCount(event->TaskIndex))));
|
||||
std::unique_ptr<C018_queue_element> element(new C018_queue_element(event, C018_data->getSampleSetCount(event->TaskIndex)));
|
||||
success = C018_DelayHandler->addToQueue(std::move(element));
|
||||
Scheduler.scheduleNextDelayQueue(ESPEasy_Scheduler::IntervalTimer_e::TIMER_C018_DELAY_QUEUE,
|
||||
C018_DelayHandler->getNextScheduleTime());
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ boolean Plugin_146(uint8_t function, struct EventStruct *event, String& string)
|
||||
addFormNumericBox(F("Max Message Size"),
|
||||
F("maxmsgsize"),
|
||||
P146_MQTT_MESSAGE_LENGTH,
|
||||
sizeof(C016_queue_element) + 16,
|
||||
sizeof(C016_binary_element) + 16,
|
||||
MQTT_MAX_PACKET_SIZE - 200);
|
||||
|
||||
addFormSubHeader(F("Non MQTT Output Options"));
|
||||
|
||||
@@ -8,8 +8,10 @@
|
||||
C011_queue_element::C011_queue_element(const struct EventStruct *event) :
|
||||
idx(event->idx),
|
||||
TaskIndex(event->TaskIndex),
|
||||
controller_idx(event->ControllerIndex),
|
||||
sensorType(event->sensorType) {}
|
||||
sensorType(event->sensorType)
|
||||
{
|
||||
controller_idx = event->ControllerIndex;
|
||||
}
|
||||
|
||||
size_t C011_queue_element::getSize() const {
|
||||
size_t total = sizeof(*this);
|
||||
@@ -21,17 +23,19 @@ size_t C011_queue_element::getSize() const {
|
||||
return total;
|
||||
}
|
||||
|
||||
bool C011_queue_element::isDuplicate(const C011_queue_element& other) const {
|
||||
if ((other.controller_idx != controller_idx) ||
|
||||
(other.TaskIndex != TaskIndex) ||
|
||||
(other.sensorType != sensorType) ||
|
||||
(other.idx != idx)) {
|
||||
bool C011_queue_element::isDuplicate(const Queue_element_base& other) const {
|
||||
const C011_queue_element& oth = static_cast<const C011_queue_element&>(other);
|
||||
|
||||
if ((oth.controller_idx != controller_idx) ||
|
||||
(oth.TaskIndex != TaskIndex) ||
|
||||
(oth.sensorType != sensorType) ||
|
||||
(oth.idx != idx)) {
|
||||
return false;
|
||||
}
|
||||
return other.uri.equals(uri) &&
|
||||
other.HttpMethod.equals(HttpMethod) &&
|
||||
other.header.equals(header) &&
|
||||
other.postStr.equals(postStr);
|
||||
return oth.uri.equals(uri) &&
|
||||
oth.HttpMethod.equals(HttpMethod) &&
|
||||
oth.header.equals(header) &&
|
||||
oth.postStr.equals(postStr);
|
||||
}
|
||||
|
||||
#endif // ifdef USES_C011
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define CONTROLLERQUEUE_C011_QUEUE_ELEMENT_H
|
||||
|
||||
#include "../../ESPEasy_common.h"
|
||||
#include "../ControllerQueue/Queue_element_base.h"
|
||||
#include "../CustomBuild/ESPEasyLimits.h"
|
||||
#include "../DataStructs/DeviceStruct.h"
|
||||
#include "../DataStructs/UnitMessageCount.h"
|
||||
@@ -16,24 +17,30 @@ struct EventStruct;
|
||||
/*********************************************************************************************\
|
||||
* C011_queue_element for queueing requests for C011: Generic HTTP Advanced.
|
||||
\*********************************************************************************************/
|
||||
class C011_queue_element {
|
||||
class C011_queue_element : public Queue_element_base {
|
||||
public:
|
||||
|
||||
C011_queue_element() = default;
|
||||
|
||||
C011_queue_element(C011_queue_element&& other) = default;
|
||||
|
||||
#ifdef USE_SECOND_HEAP
|
||||
# ifdef USE_SECOND_HEAP
|
||||
C011_queue_element(const C011_queue_element& other) = default;
|
||||
#else
|
||||
# else // ifdef USE_SECOND_HEAP
|
||||
C011_queue_element(const C011_queue_element& other) = delete;
|
||||
#endif
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
|
||||
C011_queue_element(const struct EventStruct *event);
|
||||
|
||||
bool isDuplicate(const C011_queue_element& other) const;
|
||||
bool isDuplicate(const Queue_element_base& other) const;
|
||||
|
||||
const UnitMessageCount_t* getUnitMessageCount() const { return nullptr; }
|
||||
const UnitMessageCount_t* getUnitMessageCount() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UnitMessageCount_t* getUnitMessageCount() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t getSize() const;
|
||||
|
||||
@@ -41,14 +48,12 @@ public:
|
||||
String HttpMethod;
|
||||
String header;
|
||||
String postStr;
|
||||
int idx = 0;
|
||||
unsigned long _timestamp = millis();
|
||||
taskIndex_t TaskIndex = INVALID_TASK_INDEX;
|
||||
controllerIndex_t controller_idx = INVALID_CONTROLLER_INDEX;
|
||||
Sensor_VType sensorType = Sensor_VType::SENSOR_TYPE_NONE;
|
||||
int idx = 0;
|
||||
taskIndex_t TaskIndex = INVALID_TASK_INDEX;
|
||||
Sensor_VType sensorType = Sensor_VType::SENSOR_TYPE_NONE;
|
||||
};
|
||||
|
||||
#endif //USES_C011
|
||||
#endif // USES_C011
|
||||
|
||||
|
||||
#endif // CONTROLLERQUEUE_C011_QUEUE_ELEMENT_H
|
||||
|
||||
@@ -5,13 +5,15 @@
|
||||
#ifdef USES_C015
|
||||
|
||||
C015_queue_element::C015_queue_element(C015_queue_element&& other)
|
||||
: idx(other.idx), _timestamp(other._timestamp), TaskIndex(other.TaskIndex)
|
||||
, controller_idx(other.controller_idx), valuesSent(other.valuesSent)
|
||||
: idx(other.idx), TaskIndex(other.TaskIndex)
|
||||
, valuesSent(other.valuesSent)
|
||||
, valueCount(other.valueCount)
|
||||
{
|
||||
#ifdef USE_SECOND_HEAP
|
||||
_timestamp = other._timestamp;
|
||||
controller_idx = other.controller_idx;
|
||||
# ifdef USE_SECOND_HEAP
|
||||
HeapSelectIram ephemeral;
|
||||
#endif
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
|
||||
for (uint8_t i = 0; i < VARS_PER_TASK; ++i) {
|
||||
txt[i] = std::move(other.txt[i]);
|
||||
@@ -22,17 +24,19 @@ C015_queue_element::C015_queue_element(C015_queue_element&& other)
|
||||
C015_queue_element::C015_queue_element(const struct EventStruct *event, uint8_t value_count) :
|
||||
idx(event->idx),
|
||||
TaskIndex(event->TaskIndex),
|
||||
controller_idx(event->ControllerIndex),
|
||||
valuesSent(0),
|
||||
valueCount(value_count) {}
|
||||
valueCount(value_count) {
|
||||
controller_idx = event->ControllerIndex;
|
||||
}
|
||||
|
||||
C015_queue_element& C015_queue_element::operator=(C015_queue_element&& other) {
|
||||
idx = other.idx;
|
||||
_timestamp = other._timestamp;
|
||||
TaskIndex = other.TaskIndex;
|
||||
idx = other.idx;
|
||||
_timestamp = other._timestamp;
|
||||
TaskIndex = other.TaskIndex;
|
||||
controller_idx = other.controller_idx;
|
||||
valuesSent = other.valuesSent;
|
||||
valueCount = other.valueCount;
|
||||
valuesSent = other.valuesSent;
|
||||
valueCount = other.valueCount;
|
||||
|
||||
for (uint8_t i = 0; i < VARS_PER_TASK; ++i) {
|
||||
txt[i] = std::move(other.txt[i]);
|
||||
vPin[i] = other.vPin[i];
|
||||
@@ -54,20 +58,22 @@ size_t C015_queue_element::getSize() const {
|
||||
return total;
|
||||
}
|
||||
|
||||
bool C015_queue_element::isDuplicate(const C015_queue_element& other) const {
|
||||
if ((other.controller_idx != controller_idx) ||
|
||||
(other.TaskIndex != TaskIndex) ||
|
||||
(other.valueCount != valueCount) ||
|
||||
(other.idx != idx)) {
|
||||
bool C015_queue_element::isDuplicate(const Queue_element_base& other) const {
|
||||
const C015_queue_element& oth = static_cast<const C015_queue_element&>(other);
|
||||
|
||||
if ((oth.controller_idx != controller_idx) ||
|
||||
(oth.TaskIndex != TaskIndex) ||
|
||||
(oth.valueCount != valueCount) ||
|
||||
(oth.idx != idx)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < VARS_PER_TASK; ++i) {
|
||||
if (other.txt[i] != txt[i]) {
|
||||
if (oth.txt[i] != txt[i]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (other.vPin[i] != vPin[i]) {
|
||||
if (oth.vPin[i] != vPin[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define CONTROLLERQUEUE_C015_QUEUE_ELEMENT_H
|
||||
|
||||
#include "../../ESPEasy_common.h"
|
||||
#include "../ControllerQueue/Queue_element_base.h"
|
||||
#include "../CustomBuild/ESPEasyLimits.h"
|
||||
#include "../DataStructs/UnitMessageCount.h"
|
||||
#include "../Globals/CPlugins.h"
|
||||
@@ -16,42 +17,47 @@ struct EventStruct;
|
||||
* Using SimpleQueueElement_formatted_Strings
|
||||
\*********************************************************************************************/
|
||||
|
||||
class C015_queue_element {
|
||||
class C015_queue_element : public Queue_element_base {
|
||||
public:
|
||||
|
||||
C015_queue_element() = default;
|
||||
|
||||
#ifdef USE_SECOND_HEAP
|
||||
# ifdef USE_SECOND_HEAP
|
||||
C015_queue_element(const C015_queue_element& other) = default;
|
||||
#else
|
||||
# else // ifdef USE_SECOND_HEAP
|
||||
C015_queue_element(const C015_queue_element& other) = delete;
|
||||
#endif
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
|
||||
C015_queue_element(C015_queue_element&& other);
|
||||
|
||||
C015_queue_element(const struct EventStruct *event, uint8_t value_count);
|
||||
C015_queue_element(const struct EventStruct *event,
|
||||
uint8_t value_count);
|
||||
|
||||
C015_queue_element& operator=(C015_queue_element&& other);
|
||||
C015_queue_element & operator=(C015_queue_element&& other);
|
||||
|
||||
bool checkDone(bool succesfull) const;
|
||||
bool checkDone(bool succesfull) const;
|
||||
|
||||
size_t getSize() const;
|
||||
size_t getSize() const;
|
||||
|
||||
bool isDuplicate(const C015_queue_element& other) const;
|
||||
bool isDuplicate(const Queue_element_base& other) const;
|
||||
|
||||
const UnitMessageCount_t* getUnitMessageCount() const { return nullptr; }
|
||||
const UnitMessageCount_t* getUnitMessageCount() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UnitMessageCount_t* getUnitMessageCount() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
String txt[VARS_PER_TASK];
|
||||
int vPin[VARS_PER_TASK] = { 0 };
|
||||
int idx = 0;
|
||||
unsigned long _timestamp = millis();
|
||||
taskIndex_t TaskIndex = INVALID_TASK_INDEX;
|
||||
controllerIndex_t controller_idx = INVALID_CONTROLLER_INDEX;
|
||||
mutable uint8_t valuesSent = 0; // Value must be set by const function checkDone()
|
||||
uint8_t valueCount = 0;
|
||||
int vPin[VARS_PER_TASK] = { 0 };
|
||||
int idx = 0;
|
||||
taskIndex_t TaskIndex = INVALID_TASK_INDEX;
|
||||
mutable uint8_t valuesSent = 0; // Value must be set by const function checkDone()
|
||||
uint8_t valueCount = 0;
|
||||
};
|
||||
|
||||
#endif //USES_C015
|
||||
#endif // USES_C015
|
||||
|
||||
|
||||
#endif // CONTROLLERQUEUE_C015_QUEUE_ELEMENT_H
|
||||
|
||||
@@ -7,30 +7,35 @@
|
||||
|
||||
#ifdef USES_C016
|
||||
|
||||
C016_queue_element::C016_queue_element() : _timestamp(0), TaskIndex(INVALID_TASK_INDEX), controller_idx(0), sensorType(
|
||||
Sensor_VType::SENSOR_TYPE_NONE) {}
|
||||
C016_queue_element::C016_queue_element() : TaskIndex(INVALID_TASK_INDEX), sensorType(
|
||||
Sensor_VType::SENSOR_TYPE_NONE) {
|
||||
_timestamp = 0;
|
||||
controller_idx = 0;
|
||||
}
|
||||
|
||||
C016_queue_element::C016_queue_element(C016_queue_element&& other)
|
||||
: _timestamp(other._timestamp)
|
||||
, TaskIndex(other.TaskIndex)
|
||||
, controller_idx(other.controller_idx)
|
||||
: TaskIndex(other.TaskIndex)
|
||||
, sensorType(other.sensorType)
|
||||
, valueCount(other.valueCount)
|
||||
{
|
||||
_timestamp = other._timestamp;
|
||||
controller_idx = other.controller_idx;
|
||||
|
||||
for (uint8_t i = 0; i < VARS_PER_TASK; ++i) {
|
||||
values[i] = other.values[i];
|
||||
}
|
||||
}
|
||||
|
||||
C016_queue_element::C016_queue_element(const struct EventStruct *event, uint8_t value_count, unsigned long unixTime) :
|
||||
_timestamp(unixTime),
|
||||
TaskIndex(event->TaskIndex),
|
||||
controller_idx(event->ControllerIndex),
|
||||
sensorType(event->sensorType),
|
||||
valueCount(value_count)
|
||||
{
|
||||
_timestamp = unixTime;
|
||||
controller_idx = event->ControllerIndex;
|
||||
|
||||
for (uint8_t i = 0; i < VARS_PER_TASK; ++i) {
|
||||
if (i < value_count && validTaskIndex(event->TaskIndex)) {
|
||||
if ((i < value_count) && validTaskIndex(event->TaskIndex)) {
|
||||
values[i] = UserVar[event->BaseVarIndex + i];
|
||||
} else {
|
||||
values[i] = 0.0f;
|
||||
@@ -39,11 +44,12 @@ C016_queue_element::C016_queue_element(const struct EventStruct *event, uint8_t
|
||||
}
|
||||
|
||||
C016_queue_element& C016_queue_element::operator=(C016_queue_element&& other) {
|
||||
_timestamp = other._timestamp;
|
||||
TaskIndex = other.TaskIndex;
|
||||
_timestamp = other._timestamp;
|
||||
TaskIndex = other.TaskIndex;
|
||||
controller_idx = other.controller_idx;
|
||||
sensorType = other.sensorType;
|
||||
valueCount = other.valueCount;
|
||||
sensorType = other.sensorType;
|
||||
valueCount = other.valueCount;
|
||||
|
||||
for (uint8_t i = 0; i < VARS_PER_TASK; ++i) {
|
||||
values[i] = other.values[i];
|
||||
}
|
||||
@@ -54,23 +60,40 @@ size_t C016_queue_element::getSize() const {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
bool C016_queue_element::isDuplicate(const C016_queue_element& other) const {
|
||||
if ((other.controller_idx != controller_idx) ||
|
||||
(other.TaskIndex != TaskIndex) ||
|
||||
(other.sensorType != sensorType) ||
|
||||
(other.valueCount != valueCount)) {
|
||||
bool C016_queue_element::isDuplicate(const Queue_element_base& other) const {
|
||||
const C016_queue_element& oth = static_cast<const C016_queue_element&>(other);
|
||||
|
||||
if ((oth.controller_idx != controller_idx) ||
|
||||
(oth.TaskIndex != TaskIndex) ||
|
||||
(oth.sensorType != sensorType) ||
|
||||
(oth.valueCount != valueCount)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < VARS_PER_TASK; ++i) {
|
||||
if (!essentiallyEqual(other.values[i] , values[i])) {
|
||||
if (!essentiallyEqual(oth.values[i], values[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void C016_queue_element::setPluginID_insteadOf_controller_idx() {
|
||||
C016_binary_element C016_queue_element::getBinary() const {
|
||||
C016_binary_element element;
|
||||
|
||||
for (uint8_t i = 0; i < VARS_PER_TASK; ++i) {
|
||||
element.values[i] = values[i];
|
||||
}
|
||||
element._timestamp = _timestamp;
|
||||
element.TaskIndex = TaskIndex;
|
||||
element.controller_idx = controller_idx;
|
||||
element.sensorType = sensorType;
|
||||
element.valueCount = valueCount;
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
void C016_binary_element::setPluginID_insteadOf_controller_idx() {
|
||||
controller_idx = getPluginID_from_TaskIndex(TaskIndex);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define CONTROLLERQUEUE_C016_QUEUE_ELEMENT_H
|
||||
|
||||
#include "../../ESPEasy_common.h"
|
||||
#include "../ControllerQueue/Queue_element_base.h"
|
||||
#include "../CustomBuild/ESPEasyLimits.h"
|
||||
#include "../DataStructs/DeviceStruct.h"
|
||||
#include "../DataTypes/ControllerIndex.h"
|
||||
@@ -13,13 +14,30 @@ struct EventStruct;
|
||||
|
||||
#ifdef USES_C016
|
||||
|
||||
|
||||
// The binary format to store the samples using the Cache Controller
|
||||
// Do NOT change order of members!
|
||||
struct C016_binary_element {
|
||||
// It makes no sense to keep the controller index when storing it.
|
||||
// re-purpose it to store the pluginID
|
||||
void setPluginID_insteadOf_controller_idx();
|
||||
|
||||
float values[VARS_PER_TASK] = { 0 };
|
||||
unsigned long _timestamp = 0; // Unix timestamp
|
||||
taskIndex_t TaskIndex = INVALID_TASK_INDEX;
|
||||
controllerIndex_t controller_idx = INVALID_CONTROLLER_INDEX;
|
||||
Sensor_VType sensorType = Sensor_VType::SENSOR_TYPE_NONE;
|
||||
uint8_t valueCount = 0;
|
||||
};
|
||||
|
||||
|
||||
/*********************************************************************************************\
|
||||
* C016_queue_element for queueing requests for C016: Cached HTTP.
|
||||
\*********************************************************************************************/
|
||||
|
||||
// TD-er: This one has a fixed uint8_t order and is stored.
|
||||
// This also means the order of members should not be changed!
|
||||
class C016_queue_element {
|
||||
class C016_queue_element : public Queue_element_base {
|
||||
public:
|
||||
|
||||
C016_queue_element();
|
||||
@@ -32,28 +50,30 @@ public:
|
||||
uint8_t value_count,
|
||||
unsigned long unixTime);
|
||||
|
||||
C016_queue_element& operator=(C016_queue_element&& other);
|
||||
C016_queue_element & operator=(C016_queue_element&& other);
|
||||
|
||||
|
||||
size_t getSize() const;
|
||||
size_t getSize() const;
|
||||
|
||||
bool isDuplicate(const C016_queue_element& other) const;
|
||||
bool isDuplicate(const Queue_element_base& other) const;
|
||||
|
||||
const UnitMessageCount_t* getUnitMessageCount() const { return nullptr; }
|
||||
const UnitMessageCount_t* getUnitMessageCount() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// It makes no sense to keep the controller index when storing it.
|
||||
// re-purpose it to store the pluginID
|
||||
void setPluginID_insteadOf_controller_idx();
|
||||
UnitMessageCount_t* getUnitMessageCount() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
C016_binary_element getBinary() const;
|
||||
|
||||
float values[VARS_PER_TASK] = { 0 };
|
||||
unsigned long _timestamp = 0; // Unix timestamp
|
||||
taskIndex_t TaskIndex = INVALID_TASK_INDEX;
|
||||
controllerIndex_t controller_idx = INVALID_CONTROLLER_INDEX;
|
||||
Sensor_VType sensorType = Sensor_VType::SENSOR_TYPE_NONE;
|
||||
uint8_t valueCount = 0;
|
||||
uint8_t valueCount = 0;
|
||||
};
|
||||
|
||||
#endif //USES_C016
|
||||
#endif // USES_C016
|
||||
|
||||
|
||||
#endif // CONTROLLERQUEUE_C016_QUEUE_ELEMENT_H
|
||||
|
||||
@@ -2,28 +2,29 @@
|
||||
|
||||
#ifdef USES_C018
|
||||
|
||||
#include "../DataStructs/ESPEasy_EventStruct.h"
|
||||
# include "../DataStructs/ESPEasy_EventStruct.h"
|
||||
|
||||
#include "../ESPEasyCore/ESPEasy_Log.h"
|
||||
# include "../ESPEasyCore/ESPEasy_Log.h"
|
||||
|
||||
#include "../Helpers/_CPlugin_LoRa_TTN_helper.h"
|
||||
# include "../Helpers/_CPlugin_LoRa_TTN_helper.h"
|
||||
|
||||
C018_queue_element::C018_queue_element(struct EventStruct *event, uint8_t sampleSetCount) :
|
||||
TaskIndex(event->TaskIndex),
|
||||
controller_idx(event->ControllerIndex)
|
||||
TaskIndex(event->TaskIndex)
|
||||
{
|
||||
controller_idx = event->ControllerIndex;
|
||||
# if FEATURE_PACKED_RAW_DATA
|
||||
#ifdef USE_SECOND_HEAP
|
||||
// HeapSelectIram ephemeral;
|
||||
#endif
|
||||
# ifdef USE_SECOND_HEAP
|
||||
|
||||
packed = getPackedFromPlugin(event, sampleSetCount);
|
||||
// HeapSelectIram ephemeral;
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
String log = F("C018 queue element: ");
|
||||
log += packed;
|
||||
addLogMove(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
packed = getPackedFromPlugin(event, sampleSetCount);
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
String log = F("C018 queue element: ");
|
||||
log += packed;
|
||||
addLogMove(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
# endif // if FEATURE_PACKED_RAW_DATA
|
||||
}
|
||||
|
||||
@@ -31,10 +32,12 @@ size_t C018_queue_element::getSize() const {
|
||||
return sizeof(*this) + packed.length();
|
||||
}
|
||||
|
||||
bool C018_queue_element::isDuplicate(const C018_queue_element& other) const {
|
||||
if ((other.controller_idx != controller_idx) ||
|
||||
(other.TaskIndex != TaskIndex) ||
|
||||
(other.packed != packed)) {
|
||||
bool C018_queue_element::isDuplicate(const Queue_element_base& other) const {
|
||||
const C018_queue_element& oth = static_cast<const C018_queue_element&>(other);
|
||||
|
||||
if ((oth.controller_idx != controller_idx) ||
|
||||
(oth.TaskIndex != TaskIndex) ||
|
||||
(oth.packed != packed)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
|
||||
#ifdef USES_C018
|
||||
|
||||
#include "../CustomBuild/ESPEasyLimits.h"
|
||||
#include "../DataStructs/UnitMessageCount.h"
|
||||
#include "../Globals/CPlugins.h"
|
||||
# include "../ControllerQueue/Queue_element_base.h"
|
||||
# include "../CustomBuild/ESPEasyLimits.h"
|
||||
# include "../DataStructs/UnitMessageCount.h"
|
||||
# include "../Globals/CPlugins.h"
|
||||
|
||||
|
||||
struct EventStruct;
|
||||
@@ -17,35 +18,39 @@ struct EventStruct;
|
||||
\*********************************************************************************************/
|
||||
|
||||
|
||||
class C018_queue_element {
|
||||
class C018_queue_element : public Queue_element_base {
|
||||
public:
|
||||
|
||||
C018_queue_element() = default;
|
||||
|
||||
#ifdef USE_SECOND_HEAP
|
||||
# ifdef USE_SECOND_HEAP
|
||||
C018_queue_element(const C018_queue_element& other) = default;
|
||||
#else
|
||||
# else // ifdef USE_SECOND_HEAP
|
||||
C018_queue_element(const C018_queue_element& other) = delete;
|
||||
#endif
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
|
||||
C018_queue_element(C018_queue_element&& other) = default;
|
||||
|
||||
C018_queue_element(struct EventStruct *event,
|
||||
uint8_t sampleSetCount);
|
||||
|
||||
size_t getSize() const;
|
||||
size_t getSize() const;
|
||||
|
||||
bool isDuplicate(const C018_queue_element& other) const;
|
||||
bool isDuplicate(const Queue_element_base& other) const;
|
||||
|
||||
const UnitMessageCount_t* getUnitMessageCount() const { return nullptr; }
|
||||
const UnitMessageCount_t* getUnitMessageCount() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UnitMessageCount_t* getUnitMessageCount() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
String packed;
|
||||
unsigned long _timestamp = millis();
|
||||
taskIndex_t TaskIndex = INVALID_TASK_INDEX;
|
||||
controllerIndex_t controller_idx = INVALID_CONTROLLER_INDEX;
|
||||
taskIndex_t TaskIndex = INVALID_TASK_INDEX;
|
||||
};
|
||||
|
||||
#endif //USES_C018
|
||||
#endif // USES_C018
|
||||
|
||||
|
||||
#endif // CONTROLLERQUEUE_C018_QUEUE_ELEMENT_H
|
||||
|
||||
@@ -134,10 +134,10 @@ struct ControllerDelayHandlerStruct {
|
||||
// Use reverse iterator here, as it is more likely a duplicate is added shortly after another.
|
||||
auto it = sendQueue.rbegin(); // Same as back()
|
||||
for (; it != sendQueue.rend(); ++it) {
|
||||
if (element.isDuplicate(*it)) {
|
||||
if (element.isDuplicate(*(it->get()))) {
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
|
||||
const cpluginID_t cpluginID = getCPluginID_from_ControllerIndex(it->controller_idx);
|
||||
const cpluginID_t cpluginID = getCPluginID_from_ControllerIndex(it->get()->controller_idx);
|
||||
String log = get_formatted_Controller_number(cpluginID);
|
||||
log += F(" : Remove duplicate");
|
||||
addLogMove(LOG_LEVEL_DEBUG, log);
|
||||
@@ -152,34 +152,29 @@ struct ControllerDelayHandlerStruct {
|
||||
|
||||
// Try to add to the queue, if permitted by "delete_oldest"
|
||||
// Return true when item was added, or skipped as it was considered a duplicate
|
||||
bool addToQueue(T&& element) {
|
||||
if (isDuplicate(element)) {
|
||||
bool addToQueue(std::unique_ptr<T> element) {
|
||||
if (isDuplicate(*element)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (delete_oldest) {
|
||||
// Force add to the queue.
|
||||
// If max buffer is reached, the oldest in the queue (first to be served) will be removed.
|
||||
while (queueFull(element)) {
|
||||
while (queueFull(*element)) {
|
||||
sendQueue.pop_front();
|
||||
attempt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!queueFull(element)) {
|
||||
#ifdef USE_SECOND_HEAP
|
||||
HeapSelectIram ephemeral;
|
||||
sendQueue.push_back(element);
|
||||
#else
|
||||
if (!queueFull(*element)) {
|
||||
sendQueue.push_back(std::move(element));
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
|
||||
const cpluginID_t cpluginID = getCPluginID_from_ControllerIndex(element.controller_idx);
|
||||
const cpluginID_t cpluginID = getCPluginID_from_ControllerIndex((*element).controller_idx);
|
||||
String log = get_formatted_Controller_number(cpluginID);
|
||||
log += F(" : queue full");
|
||||
addLogMove(LOG_LEVEL_DEBUG, log);
|
||||
@@ -201,7 +196,7 @@ struct ControllerDelayHandlerStruct {
|
||||
if (expire_timeout != 0) {
|
||||
bool done = false;
|
||||
while (!done && !sendQueue.empty()) {
|
||||
if (timePassedSince(sendQueue.front()._timestamp) < static_cast<long>(expire_timeout)) {
|
||||
if (sendQueue.front().get() != nullptr && timePassedSince(sendQueue.front()->_timestamp) < static_cast<long>(expire_timeout)) {
|
||||
done = true;
|
||||
} else {
|
||||
sendQueue.pop_front();
|
||||
@@ -211,7 +206,7 @@ struct ControllerDelayHandlerStruct {
|
||||
}
|
||||
|
||||
if (sendQueue.empty()) { return nullptr; }
|
||||
return &sendQueue.front();
|
||||
return sendQueue.front().get();
|
||||
}
|
||||
|
||||
// Mark as processed and return time to schedule for next process.
|
||||
@@ -254,19 +249,20 @@ struct ControllerDelayHandlerStruct {
|
||||
size_t totalSize = 0;
|
||||
|
||||
for (auto it = sendQueue.begin(); it != sendQueue.end(); ++it) {
|
||||
totalSize += it->getSize();
|
||||
if (it->get() != nullptr)
|
||||
totalSize += it->get()->getSize();
|
||||
}
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
std::list<T> sendQueue;
|
||||
std::list<std::unique_ptr<T>> sendQueue;
|
||||
mutable UnitLastMessageCount_map unitLastMessageCount;
|
||||
unsigned long lastSend;
|
||||
unsigned int minTimeBetweenMessages;
|
||||
unsigned long expire_timeout = 0;
|
||||
uint8_t max_queue_depth;
|
||||
uint8_t attempt;
|
||||
uint8_t max_retries;
|
||||
uint8_t max_queue_depth;
|
||||
uint8_t attempt;
|
||||
uint8_t max_retries;
|
||||
bool delete_oldest;
|
||||
bool must_check_reply;
|
||||
bool deduplicate;
|
||||
@@ -301,7 +297,7 @@ struct ControllerDelayHandlerStruct {
|
||||
bool do_process_c##NNN####M##_delay_queue(int controller_number, \
|
||||
const C##NNN####M##_queue_element & element, \
|
||||
ControllerSettingsStruct & ControllerSettings); \
|
||||
typedef ControllerDelayHandlerStruct<C##NNN####M##_queue_element> C##NNN####M##_DelayHandler_t; \
|
||||
typedef ControllerDelayHandlerStruct<Queue_element_base> C##NNN####M##_DelayHandler_t; \
|
||||
extern C##NNN####M##_DelayHandler_t *C##NNN####M##_DelayHandler; \
|
||||
void process_c##NNN####M##_delay_queue(); \
|
||||
bool init_c##NNN####M##_delay_queue(controllerIndex_t ControllerIndex); \
|
||||
@@ -311,7 +307,7 @@ struct ControllerDelayHandlerStruct {
|
||||
C##NNN####M##_DelayHandler_t *C##NNN####M##_DelayHandler = nullptr; \
|
||||
void process_c##NNN####M##_delay_queue() { \
|
||||
if (C##NNN####M##_DelayHandler == nullptr) return; \
|
||||
C##NNN####M##_queue_element *element(C##NNN####M##_DelayHandler->getNext()); \
|
||||
C##NNN####M##_queue_element *element(static_cast<C##NNN####M##_queue_element *>(C##NNN####M##_DelayHandler->getNext())); \
|
||||
if (element == nullptr) return; \
|
||||
if (C##NNN####M##_DelayHandler->readyToProcess(*element)) { \
|
||||
MakeControllerSettings(ControllerSettings); \
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "../Helpers/PeriodicalActions.h"
|
||||
|
||||
#if FEATURE_MQTT
|
||||
ControllerDelayHandlerStruct<MQTT_queue_element> *MQTTDelayHandler = nullptr;
|
||||
ControllerDelayHandlerStruct<Queue_element_base> *MQTTDelayHandler = nullptr;
|
||||
|
||||
bool init_mqtt_delay_queue(controllerIndex_t ControllerIndex, String& pubname, bool& retainFlag) {
|
||||
MakeControllerSettings(ControllerSettings); //-V522
|
||||
@@ -19,7 +19,7 @@ bool init_mqtt_delay_queue(controllerIndex_t ControllerIndex, String& pubname, b
|
||||
HeapSelectIram ephemeral;
|
||||
#endif
|
||||
|
||||
MQTTDelayHandler = new (std::nothrow) ControllerDelayHandlerStruct<MQTT_queue_element>;
|
||||
MQTTDelayHandler = new (std::nothrow) ControllerDelayHandlerStruct<Queue_element_base>;
|
||||
}
|
||||
if (MQTTDelayHandler == nullptr) {
|
||||
return false;
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
|
||||
#include "../ControllerQueue/ControllerDelayHandlerStruct.h"
|
||||
#include "../ControllerQueue/Queue_element_base.h"
|
||||
|
||||
|
||||
#include "../DataStructs/ControllerSettingsStruct.h"
|
||||
|
||||
@@ -28,7 +30,7 @@
|
||||
|
||||
#if FEATURE_MQTT
|
||||
# include "../ControllerQueue/MQTT_queue_element.h"
|
||||
extern ControllerDelayHandlerStruct<MQTT_queue_element> *MQTTDelayHandler;
|
||||
extern ControllerDelayHandlerStruct<Queue_element_base> *MQTTDelayHandler;
|
||||
|
||||
bool init_mqtt_delay_queue(controllerIndex_t ControllerIndex, String& pubname, bool& retainFlag);
|
||||
void exit_mqtt_delay_queue();
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
MQTT_queue_element::MQTT_queue_element(int ctrl_idx,
|
||||
taskIndex_t TaskIndex,
|
||||
const String& topic, const String& payload, bool retained) :
|
||||
TaskIndex(TaskIndex), controller_idx(ctrl_idx), _retained(retained)
|
||||
TaskIndex(TaskIndex), _retained(retained)
|
||||
{
|
||||
controller_idx = ctrl_idx;
|
||||
#ifdef USE_SECOND_HEAP
|
||||
HeapSelectIram ephemeral;
|
||||
#endif
|
||||
@@ -22,8 +23,9 @@ MQTT_queue_element::MQTT_queue_element(int ctrl_idx,
|
||||
String && topic,
|
||||
String && payload,
|
||||
bool retained)
|
||||
: TaskIndex(TaskIndex), controller_idx(ctrl_idx), _retained(retained)
|
||||
: TaskIndex(TaskIndex), _retained(retained)
|
||||
{
|
||||
controller_idx = ctrl_idx;
|
||||
// Copy in the scope of the constructor, so we might store it in the 2nd heap
|
||||
#ifdef USE_SECOND_HEAP
|
||||
HeapSelectIram ephemeral;
|
||||
@@ -49,11 +51,12 @@ size_t MQTT_queue_element::getSize() const {
|
||||
return sizeof(*this) + _topic.length() + _payload.length();
|
||||
}
|
||||
|
||||
bool MQTT_queue_element::isDuplicate(const MQTT_queue_element& other) const {
|
||||
if ((other.controller_idx != controller_idx) ||
|
||||
(other._retained != _retained) ||
|
||||
other._topic != _topic ||
|
||||
other._payload != _payload) {
|
||||
bool MQTT_queue_element::isDuplicate(const Queue_element_base& other) const {
|
||||
const MQTT_queue_element& oth = static_cast<const MQTT_queue_element&>(other);
|
||||
if ((oth.controller_idx != controller_idx) ||
|
||||
(oth._retained != _retained) ||
|
||||
oth._topic != _topic ||
|
||||
oth._payload != _payload) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
|
||||
#if FEATURE_MQTT
|
||||
|
||||
#include "../ControllerQueue/Queue_element_base.h"
|
||||
#include "../DataStructs/UnitMessageCount.h"
|
||||
#include "../Globals/CPlugins.h"
|
||||
|
||||
/*********************************************************************************************\
|
||||
* MQTT_queue_element for all MQTT base controllers
|
||||
\*********************************************************************************************/
|
||||
class MQTT_queue_element {
|
||||
class MQTT_queue_element: public Queue_element_base {
|
||||
public:
|
||||
|
||||
MQTT_queue_element() = default;
|
||||
@@ -38,7 +39,7 @@ public:
|
||||
|
||||
size_t getSize() const;
|
||||
|
||||
bool isDuplicate(const MQTT_queue_element& other) const;
|
||||
bool isDuplicate(const Queue_element_base& other) const;
|
||||
|
||||
const UnitMessageCount_t* getUnitMessageCount() const { return &UnitMessageCount; }
|
||||
UnitMessageCount_t* getUnitMessageCount() { return &UnitMessageCount; }
|
||||
@@ -47,9 +48,7 @@ public:
|
||||
|
||||
String _topic;
|
||||
String _payload;
|
||||
unsigned long _timestamp = millis();
|
||||
taskIndex_t TaskIndex = INVALID_TASK_INDEX;
|
||||
controllerIndex_t controller_idx = INVALID_CONTROLLER_INDEX;
|
||||
bool _retained = false;
|
||||
UnitMessageCount_t UnitMessageCount;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#include "../ControllerQueue/Queue_element_base.h"
|
||||
|
||||
Queue_element_base::~Queue_element_base() {}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef CONTROLLERQUEUE_QUEUE_ELEMENT_BASE_H
|
||||
#define CONTROLLERQUEUE_QUEUE_ELEMENT_BASE_H
|
||||
|
||||
|
||||
#include "../../ESPEasy_common.h"
|
||||
|
||||
#include "../DataStructs/UnitMessageCount.h"
|
||||
#include "../Globals/CPlugins.h"
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Base class for all controller queue elements
|
||||
\*********************************************************************************************/
|
||||
class Queue_element_base {
|
||||
public:
|
||||
|
||||
virtual ~Queue_element_base();
|
||||
|
||||
virtual size_t getSize() const = 0;
|
||||
|
||||
virtual bool isDuplicate(const Queue_element_base& other) const = 0;
|
||||
|
||||
virtual const UnitMessageCount_t* getUnitMessageCount() const = 0;
|
||||
virtual UnitMessageCount_t * getUnitMessageCount() = 0;
|
||||
|
||||
unsigned long _timestamp = millis();
|
||||
controllerIndex_t controller_idx = INVALID_CONTROLLER_INDEX;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -9,10 +9,10 @@
|
||||
SimpleQueueElement_formatted_Strings::SimpleQueueElement_formatted_Strings(struct EventStruct *event) :
|
||||
idx(event->idx),
|
||||
TaskIndex(event->TaskIndex),
|
||||
controller_idx(event->ControllerIndex),
|
||||
sensorType(event->sensorType),
|
||||
valuesSent(0)
|
||||
{
|
||||
controller_idx = event->ControllerIndex;
|
||||
#ifdef USE_SECOND_HEAP
|
||||
HeapSelectIram ephemeral;
|
||||
#endif
|
||||
@@ -27,16 +27,19 @@ SimpleQueueElement_formatted_Strings::SimpleQueueElement_formatted_Strings(struc
|
||||
SimpleQueueElement_formatted_Strings::SimpleQueueElement_formatted_Strings(const struct EventStruct *event, uint8_t value_count) :
|
||||
idx(event->idx),
|
||||
TaskIndex(event->TaskIndex),
|
||||
controller_idx(event->ControllerIndex),
|
||||
sensorType(event->sensorType),
|
||||
valuesSent(0),
|
||||
valueCount(value_count) {}
|
||||
valueCount(value_count) {
|
||||
controller_idx = event->ControllerIndex;
|
||||
}
|
||||
|
||||
SimpleQueueElement_formatted_Strings::SimpleQueueElement_formatted_Strings(SimpleQueueElement_formatted_Strings&& rval)
|
||||
: idx(rval.idx), _timestamp(rval._timestamp), TaskIndex(rval.TaskIndex),
|
||||
controller_idx(rval.controller_idx), sensorType(rval.sensorType),
|
||||
: idx(rval.idx), TaskIndex(rval.TaskIndex),
|
||||
sensorType(rval.sensorType),
|
||||
valuesSent(rval.valuesSent), valueCount(rval.valueCount)
|
||||
{
|
||||
_timestamp = rval._timestamp;
|
||||
controller_idx = rval.controller_idx;
|
||||
#ifdef USE_SECOND_HEAP
|
||||
HeapSelectIram ephemeral;
|
||||
#endif
|
||||
@@ -84,17 +87,19 @@ size_t SimpleQueueElement_formatted_Strings::getSize() const {
|
||||
return total;
|
||||
}
|
||||
|
||||
bool SimpleQueueElement_formatted_Strings::isDuplicate(const SimpleQueueElement_formatted_Strings& rval) const {
|
||||
if ((rval.controller_idx != controller_idx) ||
|
||||
(rval.TaskIndex != TaskIndex) ||
|
||||
(rval.sensorType != sensorType) ||
|
||||
(rval.valueCount != valueCount) ||
|
||||
(rval.idx != idx)) {
|
||||
bool SimpleQueueElement_formatted_Strings::isDuplicate(const Queue_element_base& rval) const {
|
||||
const SimpleQueueElement_formatted_Strings& oth = static_cast<const SimpleQueueElement_formatted_Strings&>(rval);
|
||||
|
||||
if ((oth.controller_idx != controller_idx) ||
|
||||
(oth.TaskIndex != TaskIndex) ||
|
||||
(oth.sensorType != sensorType) ||
|
||||
(oth.valueCount != valueCount) ||
|
||||
(oth.idx != idx)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < VARS_PER_TASK; ++i) {
|
||||
if (rval.txt[i] != txt[i]) {
|
||||
if (oth.txt[i] != txt[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
#include "../../ESPEasy_common.h"
|
||||
#include "../ControllerQueue/Queue_element_base.h"
|
||||
#include "../CustomBuild/ESPEasyLimits.h"
|
||||
#include "../DataStructs/DeviceStruct.h"
|
||||
#include "../DataStructs/UnitMessageCount.h"
|
||||
@@ -15,7 +16,7 @@ struct EventStruct;
|
||||
* Base element class for keeping task value strings in a controller queue
|
||||
* Can also be used for controllers only sending a single value at a time.
|
||||
\*********************************************************************************************/
|
||||
class SimpleQueueElement_formatted_Strings {
|
||||
class SimpleQueueElement_formatted_Strings: public Queue_element_base {
|
||||
public:
|
||||
|
||||
SimpleQueueElement_formatted_Strings() = default;
|
||||
@@ -44,20 +45,22 @@ public:
|
||||
|
||||
size_t getSize() const;
|
||||
|
||||
bool isDuplicate(const SimpleQueueElement_formatted_Strings& other) const;
|
||||
bool isDuplicate(const Queue_element_base& other) const;
|
||||
|
||||
const UnitMessageCount_t * getUnitMessageCount() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UnitMessageCount_t * getUnitMessageCount() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
String txt[VARS_PER_TASK];
|
||||
int idx = 0;
|
||||
unsigned long _timestamp = millis();
|
||||
taskIndex_t TaskIndex = INVALID_TASK_INDEX;
|
||||
controllerIndex_t controller_idx = INVALID_CONTROLLER_INDEX;
|
||||
Sensor_VType sensorType = Sensor_VType::SENSOR_TYPE_NONE;
|
||||
mutable uint8_t valuesSent = 0; // Value must be set by const function checkDone()
|
||||
uint8_t valueCount = 0;
|
||||
mutable uint8_t valuesSent = 0; // Value must be set by const function checkDone()
|
||||
uint8_t valueCount = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
|
||||
simple_queue_element_string_only::simple_queue_element_string_only(int ctrl_idx, taskIndex_t TaskIndex, String&& req) :
|
||||
TaskIndex(TaskIndex), controller_idx(ctrl_idx)
|
||||
TaskIndex(TaskIndex)
|
||||
{
|
||||
controller_idx = ctrl_idx;
|
||||
#ifdef USE_SECOND_HEAP
|
||||
HeapSelectIram ephemeral;
|
||||
if (req.length() > 0 && !mmu_is_iram(&(req[0]))) {
|
||||
@@ -21,10 +22,11 @@ size_t simple_queue_element_string_only::getSize() const {
|
||||
return sizeof(*this) + txt.length();
|
||||
}
|
||||
|
||||
bool simple_queue_element_string_only::isDuplicate(const simple_queue_element_string_only& other) const {
|
||||
if ((other.controller_idx != controller_idx) ||
|
||||
(other.TaskIndex != TaskIndex) ||
|
||||
(other.txt != txt)) {
|
||||
bool simple_queue_element_string_only::isDuplicate(const Queue_element_base& other) const {
|
||||
const simple_queue_element_string_only& oth = static_cast<const simple_queue_element_string_only&>(other);
|
||||
if ((oth.controller_idx != controller_idx) ||
|
||||
(oth.TaskIndex != TaskIndex) ||
|
||||
(oth.txt != txt)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define CONTROLLERQUEUE_SIMPLE_QUEUE_ELEMENT_STRING_ONLY_H
|
||||
|
||||
#include "../../ESPEasy_common.h"
|
||||
#include "../ControllerQueue/Queue_element_base.h"
|
||||
#include "../DataStructs/UnitMessageCount.h"
|
||||
#include "../Globals/CPlugins.h"
|
||||
|
||||
@@ -9,7 +10,7 @@
|
||||
/*********************************************************************************************\
|
||||
* Simple queue element, only storing controller index and some String
|
||||
\*********************************************************************************************/
|
||||
class simple_queue_element_string_only {
|
||||
class simple_queue_element_string_only: public Queue_element_base {
|
||||
public:
|
||||
|
||||
simple_queue_element_string_only() = default;
|
||||
@@ -28,14 +29,13 @@ public:
|
||||
|
||||
size_t getSize() const;
|
||||
|
||||
bool isDuplicate(const simple_queue_element_string_only& other) const;
|
||||
bool isDuplicate(const Queue_element_base& other) const;
|
||||
|
||||
const UnitMessageCount_t* getUnitMessageCount() const { return nullptr; }
|
||||
UnitMessageCount_t* getUnitMessageCount() { return nullptr; }
|
||||
|
||||
String txt;
|
||||
unsigned long _timestamp = millis();
|
||||
taskIndex_t TaskIndex = INVALID_TASK_INDEX;
|
||||
controllerIndex_t controller_idx = INVALID_CONTROLLER_INDEX;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -542,7 +542,7 @@ bool MQTTpublish(controllerIndex_t controller_idx, taskIndex_t taskIndex, const
|
||||
if (MQTT_queueFull(controller_idx)) {
|
||||
return false;
|
||||
}
|
||||
const bool success = MQTTDelayHandler->addToQueue(MQTT_queue_element(controller_idx, taskIndex, topic, payload, retained));
|
||||
const bool success = MQTTDelayHandler->addToQueue(std::unique_ptr<MQTT_queue_element>(new MQTT_queue_element(controller_idx, taskIndex, topic, payload, retained)));
|
||||
|
||||
scheduleNextMQTTdelayQueue();
|
||||
return success;
|
||||
@@ -556,7 +556,7 @@ bool MQTTpublish(controllerIndex_t controller_idx, taskIndex_t taskIndex, Strin
|
||||
if (MQTT_queueFull(controller_idx)) {
|
||||
return false;
|
||||
}
|
||||
const bool success = MQTTDelayHandler->addToQueue(MQTT_queue_element(controller_idx, taskIndex, std::move(topic), std::move(payload), retained));
|
||||
const bool success = MQTTDelayHandler->addToQueue(std::unique_ptr<MQTT_queue_element>(new MQTT_queue_element(controller_idx, taskIndex, std::move(topic), std::move(payload), retained)));
|
||||
|
||||
scheduleNextMQTTdelayQueue();
|
||||
return success;
|
||||
|
||||
@@ -35,7 +35,7 @@ bool C016_getCSVline(
|
||||
float & val3,
|
||||
float & val4)
|
||||
{
|
||||
C016_queue_element element;
|
||||
C016_binary_element element;
|
||||
bool result = ControllerCache.peek((uint8_t *)&element, sizeof(element));
|
||||
|
||||
timestamp = element._timestamp;
|
||||
@@ -58,7 +58,7 @@ struct EventStruct C016_getTaskSample(
|
||||
float & val3,
|
||||
float & val4)
|
||||
{
|
||||
C016_queue_element element;
|
||||
C016_binary_element element;
|
||||
|
||||
if (!ControllerCache.peek((uint8_t *)&element, sizeof(element))) {
|
||||
return EventStruct();
|
||||
|
||||
@@ -125,7 +125,7 @@ void run_compiletime_checks() {
|
||||
check_size<C013_SensorDataStruct, 24u>();
|
||||
#endif
|
||||
#ifdef USES_C016
|
||||
check_size<C016_queue_element, 24u>();
|
||||
check_size<C016_binary_element, 24u>();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ void processMQTTdelayQueue() {
|
||||
}
|
||||
|
||||
START_TIMER;
|
||||
MQTT_queue_element *element(MQTTDelayHandler->getNext());
|
||||
MQTT_queue_element *element(static_cast<MQTT_queue_element *>(MQTTDelayHandler->getNext()));
|
||||
|
||||
if (element == nullptr) { return; }
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ uint32_t P146_data_struct::sendBinaryInBulk(taskIndex_t P146_TaskIndex, uint32_t
|
||||
|
||||
size_t messageLength = message.length();
|
||||
|
||||
const size_t chunkSize = sizeof(C016_queue_element);
|
||||
const size_t chunkSize = sizeof(C016_binary_element);
|
||||
const size_t nrChunks = (maxMessageSize - messageLength) / ((2 * chunkSize) + 1);
|
||||
const size_t expectedMessageSize = messageLength + (nrChunks * ((2 * chunkSize) + 1));
|
||||
|
||||
@@ -107,7 +107,7 @@ uint32_t P146_data_struct::sendBinaryInBulk(taskIndex_t P146_TaskIndex, uint32_t
|
||||
bool done = false;
|
||||
|
||||
for (int chunk = 0; chunk < nrChunks && !done; ++chunk) {
|
||||
C016_queue_element element;
|
||||
C016_binary_element element;
|
||||
|
||||
if (ControllerCache.peek(reinterpret_cast<uint8_t *>(&element), chunkSize))
|
||||
{
|
||||
@@ -218,7 +218,7 @@ bool P146_data_struct::sendViaOriginalTask(
|
||||
bool P146_data_struct::setPeekFilePos(int peekFileNr, int peekReadPos)
|
||||
{
|
||||
{
|
||||
const int modulo_24 = peekReadPos % sizeof(C016_queue_element);
|
||||
const int modulo_24 = peekReadPos % sizeof(C016_binary_element);
|
||||
|
||||
if (modulo_24 != 0) { peekReadPos -= modulo_24; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user