mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-25 11:46:31 +00:00
Refactor backlog by removing some str copies
This commit is contained in:
parent
8223777e4f
commit
9608b7513a
@ -789,12 +789,13 @@ void BacklogLoop(void) {
|
|||||||
TasmotaGlobal.backlog_mutex = true;
|
TasmotaGlobal.backlog_mutex = true;
|
||||||
bool nodelay = false;
|
bool nodelay = false;
|
||||||
do {
|
do {
|
||||||
char cmd[strlen(backlog.get(0))+1]; // Need to accomodate large commands like Template
|
char* cmd = backlog.shift();
|
||||||
BacklogHead(cmd);
|
|
||||||
if (!strncasecmp_P(cmd, PSTR(D_CMND_NODELAY), strlen(D_CMND_NODELAY))) {
|
if (!strncasecmp_P(cmd, PSTR(D_CMND_NODELAY), strlen(D_CMND_NODELAY))) {
|
||||||
|
free(cmd);
|
||||||
nodelay = true;
|
nodelay = true;
|
||||||
} else {
|
} else {
|
||||||
ExecuteCommand(cmd, SRC_BACKLOG);
|
ExecuteCommand(cmd, SRC_BACKLOG);
|
||||||
|
free(cmd);
|
||||||
if (nodelay || TasmotaGlobal.backlog_nodelay) {
|
if (nodelay || TasmotaGlobal.backlog_nodelay) {
|
||||||
TasmotaGlobal.backlog_timer = millis(); // Reset backlog_timer which has been set by ExecuteCommand (CommandHandler)
|
TasmotaGlobal.backlog_timer = millis(); // Reset backlog_timer which has been set by ExecuteCommand (CommandHandler)
|
||||||
}
|
}
|
||||||
|
@ -491,43 +491,6 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len) {
|
|||||||
TasmotaGlobal.fallback_topic_flag = false;
|
TasmotaGlobal.fallback_topic_flag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
|
||||||
|
|
||||||
void BacklogAdd(const char* blcommand) {
|
|
||||||
// Add object at end of list
|
|
||||||
char* temp = (char*)malloc(strlen(blcommand)+1);
|
|
||||||
if (temp != nullptr) {
|
|
||||||
strcpy(temp, blcommand);
|
|
||||||
backlog.add(temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BacklogInsert(uint32_t position, const char* blcommand) {
|
|
||||||
// Add object at position in list
|
|
||||||
char* temp = (char*)malloc(strlen(blcommand)+1);
|
|
||||||
if (temp != nullptr) {
|
|
||||||
strcpy(temp, (char*)blcommand);
|
|
||||||
backlog.add(position, temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BacklogClear(void) {
|
|
||||||
// Clear list
|
|
||||||
while (backlog.size()) {
|
|
||||||
free(backlog.pop());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char* BacklogHead(char* blcommand) {
|
|
||||||
// Remove first object from list
|
|
||||||
char* temp = backlog.shift();
|
|
||||||
strcpy(blcommand, temp);
|
|
||||||
free(temp);
|
|
||||||
return blcommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
void CmndBacklog(void) {
|
void CmndBacklog(void) {
|
||||||
// Backlog command1;command2;.. Execute commands in sequence with a delay in between set with SetOption34
|
// Backlog command1;command2;.. Execute commands in sequence with a delay in between set with SetOption34
|
||||||
// Backlog0 command1;command2;.. Execute commands in sequence with no delay
|
// Backlog0 command1;command2;.. Execute commands in sequence with no delay
|
||||||
@ -557,7 +520,11 @@ void CmndBacklog(void) {
|
|||||||
}
|
}
|
||||||
// Do not allow command Reset in backlog
|
// Do not allow command Reset in backlog
|
||||||
if ((*blcommand != '\0') && (strncasecmp_P(blcommand, PSTR(D_CMND_RESET), strlen(D_CMND_RESET)) != 0)) {
|
if ((*blcommand != '\0') && (strncasecmp_P(blcommand, PSTR(D_CMND_RESET), strlen(D_CMND_RESET)) != 0)) {
|
||||||
BacklogAdd(blcommand);
|
char* temp = (char*)malloc(strlen(blcommand)+1);
|
||||||
|
if (temp != nullptr) {
|
||||||
|
strcpy(temp, blcommand);
|
||||||
|
backlog.add(temp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
blcommand = strtok(nullptr, ";");
|
blcommand = strtok(nullptr, ";");
|
||||||
}
|
}
|
||||||
@ -566,13 +533,13 @@ void CmndBacklog(void) {
|
|||||||
TasmotaGlobal.backlog_timer = millis();
|
TasmotaGlobal.backlog_timer = millis();
|
||||||
} else {
|
} else {
|
||||||
bool blflag = BACKLOG_EMPTY;
|
bool blflag = BACKLOG_EMPTY;
|
||||||
BacklogClear();
|
while (backlog.size()) {
|
||||||
|
free(backlog.pop());
|
||||||
|
}
|
||||||
ResponseCmndChar(blflag ? PSTR(D_JSON_EMPTY) : PSTR(D_JSON_ABORTED));
|
ResponseCmndChar(blflag ? PSTR(D_JSON_EMPTY) : PSTR(D_JSON_ABORTED));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
|
||||||
|
|
||||||
void CmndJson(void) {
|
void CmndJson(void) {
|
||||||
// Json {"template":{"NAME":"Dummy","GPIO":[320,0,321],"FLAG":0,"BASE":18},"power":2,"HSBColor":"51,97,100","Channel":[100,85,3]}
|
// Json {"template":{"NAME":"Dummy","GPIO":[320,0,321],"FLAG":0,"BASE":18},"power":2,"HSBColor":"51,97,100","Channel":[100,85,3]}
|
||||||
//
|
//
|
||||||
|
@ -2062,24 +2062,18 @@ void ExecuteCommandBlock(const char * commands, int len)
|
|||||||
}
|
}
|
||||||
//Start to process current command we found
|
//Start to process current command we found
|
||||||
//Going to insert the command into backlog
|
//Going to insert the command into backlog
|
||||||
String sCurrentCommand = oneCommand;
|
char* blcommand = oneCommand;
|
||||||
sCurrentCommand.trim();
|
Trim(blcommand);
|
||||||
/*
|
if (strlen(blcommand)) {
|
||||||
if (sCurrentCommand.length() > 0
|
|
||||||
&& !TasmotaGlobal.backlog_mutex)
|
|
||||||
{
|
|
||||||
//Insert into backlog
|
//Insert into backlog
|
||||||
TasmotaGlobal.backlog_mutex = true;
|
char* temp = (char*)malloc(strlen(blcommand)+1);
|
||||||
BacklogInsert(insertPosition, sCurrentCommand.c_str());
|
if (temp != nullptr) {
|
||||||
TasmotaGlobal.backlog_mutex = false;
|
strcpy(temp, blcommand);
|
||||||
insertPosition++;
|
backlog.add(insertPosition, temp);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
if (sCurrentCommand.length() > 0) {
|
|
||||||
//Insert into backlog
|
|
||||||
BacklogInsert(insertPosition, sCurrentCommand.c_str());
|
|
||||||
insertPosition++;
|
insertPosition++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user