Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 38 additions & 36 deletions src/ESPEasy-Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -1198,22 +1198,36 @@ struct ExtraTaskSettingsStruct
struct EventStruct
{
EventStruct() :
Data(NULL), idx(0), Par1(0), Par2(0), Par3(0), Par4(0), Par5(0),
Source(0), TaskIndex(TASKS_MAX), ControllerIndex(0), ProtocolIndex(0), NotificationIndex(0),
BaseVarIndex(0), idx(0), sensorType(0), Par1(0), Par2(0), Par3(0), Par4(0), Par5(0),
OriginTaskIndex(0), Data(NULL) {}
BaseVarIndex(0), sensorType(0), OriginTaskIndex(0) {}
EventStruct(const struct EventStruct& event):
Source(event.Source), TaskIndex(event.TaskIndex), ControllerIndex(event.ControllerIndex)
, ProtocolIndex(event.ProtocolIndex), NotificationIndex(event.NotificationIndex)
, BaseVarIndex(event.BaseVarIndex), idx(event.idx), sensorType(event.sensorType)
, Par1(event.Par1), Par2(event.Par2), Par3(event.Par3), Par4(event.Par4), Par5(event.Par5)
, OriginTaskIndex(event.OriginTaskIndex)
, String1(event.String1)
String1(event.String1)
, String2(event.String2)
, String3(event.String3)
, String4(event.String4)
, String5(event.String5)
, Data(event.Data) {}
, Data(event.Data)
, idx(event.idx)
, Par1(event.Par1), Par2(event.Par2), Par3(event.Par3), Par4(event.Par4), Par5(event.Par5)
, Source(event.Source), TaskIndex(event.TaskIndex), ControllerIndex(event.ControllerIndex)
, ProtocolIndex(event.ProtocolIndex), NotificationIndex(event.NotificationIndex)
, BaseVarIndex(event.BaseVarIndex), sensorType(event.sensorType)
, OriginTaskIndex(event.OriginTaskIndex)
{}

String String1;
String String2;
String String3;
String String4;
String String5;
byte *Data;
int idx;
int Par1;
int Par2;
int Par3;
int Par4;
int Par5;
byte Source;
byte TaskIndex; // index position in TaskSettings array, 0-11
byte ControllerIndex; // index position in Settings.Controller, 0-3
Expand All @@ -1222,20 +1236,8 @@ struct EventStruct
//Edwin: Not needed, and wasnt used. We can determine the protocol index with getNotificationProtocolIndex(NotificationIndex)
// byte NotificationProtocolIndex; // index position in notification array, depending on which controller plugins are loaded.
byte BaseVarIndex;
int idx;
byte sensorType;
int Par1;
int Par2;
int Par3;
int Par4;
int Par5;
byte OriginTaskIndex;
String String1;
String String2;
String String3;
String String4;
String String5;
byte *Data;
};


Expand Down Expand Up @@ -1394,16 +1396,16 @@ struct DeviceStruct
byte Type; // How the device is connected. e.g. DEVICE_TYPE_SINGLE => connected through 1 datapin
byte VType; // Type of value the plugin will return, used only for Domoticz
byte Ports; // Port to use when device has multiple I/O pins (N.B. not used much)
byte ValueCount; // The number of output values of a plugin. The value should match the number of keys PLUGIN_VALUENAME1_xxx
boolean PullUpOption; // Allow to set internal pull-up resistors.
boolean InverseLogicOption; // Allow to invert the boolean state (e.g. a switch)
boolean FormulaOption; // Allow to enter a formula to convert values during read. (not possible with Custom enabled)
boolean Custom;
boolean SendDataOption; // Allow to send data to a controller.
boolean GlobalSyncOption; // No longer used. Was used for ESPeasy values sync between nodes
boolean TimerOption; // Allow to set the "Interval" timer for the plugin.
boolean TimerOptional; // When taskdevice timer is not set and not optional, use default "Interval" delay (Settings.Delay)
boolean DecimalsOnly; // Allow to set the number of decimals (otherwise treated a 0 decimals)
byte ValueCount; // The number of output values of a plugin. The value should match the number of keys PLUGIN_VALUENAME1_xxx
bool PullUpOption : 1; // Allow to set internal pull-up resistors.
bool InverseLogicOption : 1; // Allow to invert the boolean state (e.g. a switch)
bool FormulaOption : 1; // Allow to enter a formula to convert values during read. (not possible with Custom enabled)
bool Custom : 1;
bool SendDataOption : 1; // Allow to send data to a controller.
bool GlobalSyncOption : 1; // No longer used. Was used for ESPeasy values sync between nodes
bool TimerOption : 1; // Allow to set the "Interval" timer for the plugin.
bool TimerOptional : 1; // When taskdevice timer is not set and not optional, use default "Interval" delay (Settings.Delay)
bool DecimalsOnly; // Allow to set the number of decimals (otherwise treated a 0 decimals)
};
typedef std::vector<DeviceStruct> DeviceVector;
DeviceVector Device;
Expand Down Expand Up @@ -1468,16 +1470,16 @@ NodesMap Nodes;
struct systemTimerStruct
{
systemTimerStruct() :
timer(0), plugin(0), TaskIndex(-1), Par1(0), Par2(0), Par3(0), Par4(0), Par5(0) {}
timer(0), Par1(0), Par2(0), Par3(0), Par4(0), Par5(0), TaskIndex(-1), plugin(0) {}

unsigned long timer;
byte plugin;
int16_t TaskIndex;
int Par1;
int Par2;
int Par3;
int Par4;
int Par5;
int16_t TaskIndex;
byte plugin;
};
std::map<unsigned long, systemTimerStruct> systemTimers;

Expand All @@ -1486,11 +1488,11 @@ std::map<unsigned long, systemTimerStruct> systemTimers;
\*********************************************************************************************/
struct pinStatesStruct
{
pinStatesStruct() : plugin(0), index(0), mode(0), value(0) {}
pinStatesStruct() : value(0), plugin(0), index(0), mode(0) {}
uint16_t value;
byte plugin;
byte index;
byte mode;
uint16_t value;
} pinStates[PINSTATE_TABLE_MAX];


Expand Down
12 changes: 9 additions & 3 deletions src/Misc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,7 @@ void delayBackground(unsigned long delay)
void parseCommandString(struct EventStruct *event, const String& string)
{
checkRAM(F("parseCommandString"));
char TmpStr1[INPUT_COMMAND_SIZE];
TmpStr1[0] = 0;
char *TmpStr1 = new char[INPUT_COMMAND_SIZE]();
event->Par1 = 0;
event->Par2 = 0;
event->Par3 = 0;
Expand All @@ -458,6 +457,7 @@ void parseCommandString(struct EventStruct *event, const String& string)
if (GetArgv(string.c_str(), TmpStr1, 4)) { event->Par3 = CalculateParam(TmpStr1); }
if (GetArgv(string.c_str(), TmpStr1, 5)) { event->Par4 = CalculateParam(TmpStr1); }
if (GetArgv(string.c_str(), TmpStr1, 6)) { event->Par5 = CalculateParam(TmpStr1); }
delete[] TmpStr1;
}

/********************************************************************************************\
Expand Down Expand Up @@ -568,6 +568,7 @@ boolean GetArgv(const char *string, char *argv, unsigned int argc) {

boolean GetArgv(const char *string, char *argv, unsigned int argv_size, unsigned int argc)
{
memset(argv, 0, argv_size);
size_t string_len = strlen(string);
unsigned int string_pos = 0, argv_pos = 0, argc_pos = 0;
char c, d;
Expand Down Expand Up @@ -2251,6 +2252,7 @@ for (byte x=0; x < RULESETS_MAX; x++){
\*********************************************************************************************/
void rulesProcessing(String& event)
{
if (!Settings.UseRules) return;
checkRAM(F("rulesProcessing"));
unsigned long timer = millis();
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
Expand Down Expand Up @@ -2290,6 +2292,7 @@ void rulesProcessing(String& event)
\*********************************************************************************************/
String rulesProcessingFile(const String& fileName, String& event)
{
if (!Settings.UseRules) return "";
checkRAM(F("rulesProcessingFile"));
if (Settings.SerialLogLevel == LOG_LEVEL_DEBUG_DEV){
Serial.print(F("RuleDebug Processing:"));
Expand Down Expand Up @@ -2585,7 +2588,7 @@ void processMatchedRule(
{
String tmpString = event.substring(equalsPos + 1);

char tmpParam[INPUT_COMMAND_SIZE];
char* tmpParam = new char[INPUT_COMMAND_SIZE];
tmpParam[0] = 0;

if (GetArgv(tmpString.c_str(),tmpParam,1)) {
Expand All @@ -2595,6 +2598,7 @@ void processMatchedRule(
if (GetArgv(tmpString.c_str(),tmpParam,2)) action.replace(F("%eventvalue2%"), tmpParam); // substitute %eventvalue2% in actions with the actual value from the event
if (GetArgv(tmpString.c_str(),tmpParam,3)) action.replace(F("%eventvalue3%"), tmpParam); // substitute %eventvalue3% in actions with the actual value from the event
if (GetArgv(tmpString.c_str(),tmpParam,4)) action.replace(F("%eventvalue4%"), tmpParam); // substitute %eventvalue4% in actions with the actual value from the event
delete[] tmpParam;
}
}

Expand Down Expand Up @@ -2896,6 +2900,7 @@ boolean conditionMatch(const String& check)
\*********************************************************************************************/
void rulesTimers()
{
if (!Settings.UseRules) return;
for (byte x = 0; x < RULES_TIMER_MAX; x++)
{
if (!RulesTimer[x].paused && RulesTimer[x].timestamp != 0L) // timer active?
Expand All @@ -2918,6 +2923,7 @@ void rulesTimers()

void createRuleEvents(byte TaskIndex)
{
if (!Settings.UseRules) return;
LoadTaskSettings(TaskIndex);
byte BaseVarIndex = TaskIndex * VARS_PER_TASK;
byte DeviceIndex = getDeviceIndex(Settings.TaskDeviceNumber[TaskIndex]);
Expand Down
Loading