Merge branch 'development' of github.com:arendst/Tasmota into pr2_tm1637

This commit is contained in:
Ajith Vasudevan 2021-02-16 22:50:49 +05:30
commit 10dbd0767b
5 changed files with 45 additions and 34 deletions

View File

@ -108,6 +108,10 @@ void ResponseCmndError(void) {
ResponseCmndChar_P(PSTR(D_JSON_ERROR)); ResponseCmndChar_P(PSTR(D_JSON_ERROR));
} }
void ResponseCmndFailed(void) {
ResponseCmndChar_P(PSTR(D_JSON_FAILED));
}
void ResponseCmndIdxChar(const char* value) { void ResponseCmndIdxChar(const char* value) {
Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, EscapeJSONString(value).c_str()); Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, EscapeJSONString(value).c_str());
} }

View File

@ -964,7 +964,7 @@ void Every100mSeconds(void)
bool CommandsReady(void) { bool CommandsReady(void) {
bool ready = BACKLOG_EMPTY ; bool ready = BACKLOG_EMPTY ;
#ifdef USE_UFILESYS #ifdef USE_UFILESYS
ready |= FileRunReady(); ready |= UfsExecuteCommandFileReady();
#endif // USE_UFILESYS #endif // USE_UFILESYS
return ready; return ready;
} }

View File

@ -426,9 +426,6 @@ void Scheduler(void) {
DeviceGroupsLoop(); DeviceGroupsLoop();
#endif // USE_DEVICE_GROUPS #endif // USE_DEVICE_GROUPS
BacklogLoop(); BacklogLoop();
#ifdef USE_UFILESYS
FileRunLoop();
#endif // USE_UFILESYS
static uint32_t state_50msecond = 0; // State 50msecond timer static uint32_t state_50msecond = 0; // State 50msecond timer
if (TimeReached(state_50msecond)) { if (TimeReached(state_50msecond)) {

View File

@ -434,14 +434,14 @@ void CmndTmChatId(void) {
void CmndTmSend(void) { void CmndTmSend(void) {
if (!Telegram.send_enable || !strlen(SettingsText(SET_TELEGRAM_CHATID))) { if (!Telegram.send_enable || !strlen(SettingsText(SET_TELEGRAM_CHATID))) {
ResponseCmndChar(PSTR(D_JSON_FAILED)); ResponseCmndFailed();
return; return;
} }
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
String message = XdrvMailbox.data; String message = XdrvMailbox.data;
String chat_id = SettingsText(SET_TELEGRAM_CHATID); String chat_id = SettingsText(SET_TELEGRAM_CHATID);
if (!TelegramSendMessage(chat_id.toInt(), message)) { if (!TelegramSendMessage(chat_id.toInt(), message)) {
ResponseCmndChar(PSTR(D_JSON_FAILED)); ResponseCmndFailed();
return; return;
} }
} }

View File

@ -353,44 +353,48 @@ bool TfsRenameFile(const char *fname1, const char *fname2) {
* File command execute support * File command execute support
\*********************************************************************************************/ \*********************************************************************************************/
bool FileRunReady(void) { bool UfsExecuteCommandFileReady(void) {
return (UfsData.run_file_pos < 0); return (UfsData.run_file_pos < 0); // Check file ready to disable concurrency
} }
void FileRunLoop(void) { void UfsExecuteCommandFileLoop(void) {
if (FileRunReady()) { return; } if (UfsExecuteCommandFileReady() || !ffs_type) { return; }
if (!ffs_type) { return; }
if (strlen(UfsData.run_file) && !UfsData.run_file_mutex) { if (strlen(UfsData.run_file) && !UfsData.run_file_mutex) {
File file = ffsp->open(UfsData.run_file, "r"); File file = ffsp->open(UfsData.run_file, "r");
if (!file) { return; } if (!file || !file.seek(UfsData.run_file_pos)) {
if (!file.seek(UfsData.run_file_pos)) { return; } UfsData.run_file_pos = -1; // Signal file ready
return;
}
UfsData.run_file_mutex = true; UfsData.run_file_mutex = true;
char cmd_line[512]; char cmd_line[512];
cmd_line[0] = '\0'; // Clear in case of re-entry cmd_line[0] = '\0'; // Clear in case of re-entry
while (file.available()) { while (file.available()) {
uint16_t index = 0; uint16_t index = 0;
bool comment = false;
while (file.available()) { while (file.available()) {
uint8_t buf[1]; uint8_t buf[1];
file.read(buf, 1); file.read(buf, 1);
if ((buf[0] == '\n') || (buf[0] == '\r')) { if ((buf[0] == '\n') || (buf[0] == '\r')) {
break; // Line terminated with linefeed or carriage return break; // End of command with linefeed or carriage return
} }
else if (index && (buf[0] == ';')) { else if (index && !comment && (buf[0] == ';')) {
break; // End of multi command line break; // End of command on multi command line
} }
else if ((0 == index) && isspace(buf[0])) { else if ((0 == index) && isspace(buf[0])) {
// Skip leading spaces (' ','\t','\n','\v','\f','\r') // Skip leading spaces (' ','\t','\n','\v','\f','\r')
} }
else if (index < sizeof(cmd_line) - 2) { else if ((0 == index) && (buf[0] == ';')) {
cmd_line[index++] = buf[0]; comment = true; // Ignore comment lines until linefeed or carriage return
}
else if (!comment && (index < sizeof(cmd_line) - 2)) {
cmd_line[index++] = buf[0]; // Build command
} }
} }
if ((index > 0) && (index < sizeof(cmd_line) - 1) && (cmd_line[0] != ';')) { if ((index > 0) && (index < sizeof(cmd_line) - 1)) {
// No comment so try to execute command cmd_line[index] = '\0'; // Valid command received
cmd_line[index] = '\0';
break; break;
} }
} }
@ -404,11 +408,14 @@ void FileRunLoop(void) {
} }
} }
void UfsAutoexec(void) { bool UfsExecuteCommandFile(const char *fname) {
if (TfsFileExists(TASM_FILE_AUTOEXEC)) { // Check for non-concurrency and file existance
snprintf(UfsData.run_file, sizeof(UfsData.run_file), TASM_FILE_AUTOEXEC); if (UfsExecuteCommandFileReady() && TfsFileExists(fname)) {
UfsData.run_file_pos = 0; snprintf(UfsData.run_file, sizeof(UfsData.run_file), fname);
UfsData.run_file_pos = 0; // Signal start of file
return true;
} }
return false;
} }
/*********************************************************************************************\ /*********************************************************************************************\
@ -464,7 +471,7 @@ void UFSDelete(void) {
result = (ufs_type && ufsp->remove(XdrvMailbox.data)); result = (ufs_type && ufsp->remove(XdrvMailbox.data));
} }
if (!result) { if (!result) {
ResponseCmndChar(PSTR(D_JSON_FAILED)); ResponseCmndFailed();
} else { } else {
ResponseCmndDone(); ResponseCmndDone();
} }
@ -486,7 +493,7 @@ void UFSRename(void) {
} }
} }
if (!result) { if (!result) {
ResponseCmndChar(PSTR(D_JSON_FAILED)); ResponseCmndFailed();
} else { } else {
ResponseCmndDone(); ResponseCmndDone();
} }
@ -495,12 +502,10 @@ void UFSRename(void) {
void UFSRun(void) { void UFSRun(void) {
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
if (FileRunReady() && TfsFileExists(XdrvMailbox.data)) { if (UfsExecuteCommandFile(XdrvMailbox.data)) {
snprintf(UfsData.run_file, sizeof(UfsData.run_file), XdrvMailbox.data);
UfsData.run_file_pos = 0;
ResponseClear(); ResponseClear();
} else { } else {
ResponseCmndChar(PSTR(D_JSON_FAILED)); ResponseCmndFailed();
} }
} }
} }
@ -859,13 +864,18 @@ bool Xdrv50(uint8_t function) {
bool result = false; bool result = false;
switch (function) { switch (function) {
case FUNC_LOOP:
UfsExecuteCommandFileLoop();
break;
#ifdef USE_SDCARD #ifdef USE_SDCARD
case FUNC_PRE_INIT: case FUNC_PRE_INIT:
UfsCheckSDCardInit(); UfsCheckSDCardInit();
break; break;
#endif // USE_SDCARD #endif // USE_SDCARD
case FUNC_MQTT_INIT: case FUNC_MQTT_INIT:
if (!TasmotaGlobal.no_autoexec) { UfsAutoexec(); } if (!TasmotaGlobal.no_autoexec) {
UfsExecuteCommandFile(TASM_FILE_AUTOEXEC);
}
break; break;
case FUNC_COMMAND: case FUNC_COMMAND:
result = DecodeCommand(kUFSCommands, kUFSCommand); result = DecodeCommand(kUFSCommands, kUFSCommand);