mirror of https://github.com/arendst/Tasmota.git
Refactor command file
This commit is contained in:
parent
30a75edff5
commit
ead77e536c
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)) {
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -353,12 +353,12 @@ 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); // Check file ready to disable concurrency
|
return (UfsData.run_file_pos < 0); // Check file ready to disable concurrency
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileRunLoop(void) {
|
void UfsExecuteCommandFileLoop(void) {
|
||||||
if (FileRunReady() || !ffs_type) { return; }
|
if (UfsExecuteCommandFileReady() || !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");
|
||||||
|
@ -410,7 +410,7 @@ void FileRunLoop(void) {
|
||||||
|
|
||||||
bool UfsExecuteCommandFile(const char *fname) {
|
bool UfsExecuteCommandFile(const char *fname) {
|
||||||
// Check for non-concurrency and file existance
|
// Check for non-concurrency and file existance
|
||||||
if (FileRunReady() && TfsFileExists(fname)) {
|
if (UfsExecuteCommandFileReady() && TfsFileExists(fname)) {
|
||||||
snprintf(UfsData.run_file, sizeof(UfsData.run_file), fname);
|
snprintf(UfsData.run_file, sizeof(UfsData.run_file), fname);
|
||||||
UfsData.run_file_pos = 0; // Signal start of file
|
UfsData.run_file_pos = 0; // Signal start of file
|
||||||
return true;
|
return true;
|
||||||
|
@ -471,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();
|
||||||
}
|
}
|
||||||
|
@ -493,7 +493,7 @@ void UFSRename(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!result) {
|
if (!result) {
|
||||||
ResponseCmndChar(PSTR(D_JSON_FAILED));
|
ResponseCmndFailed();
|
||||||
} else {
|
} else {
|
||||||
ResponseCmndDone();
|
ResponseCmndDone();
|
||||||
}
|
}
|
||||||
|
@ -505,7 +505,7 @@ void UFSRun(void) {
|
||||||
if (UfsExecuteCommandFile(XdrvMailbox.data)) {
|
if (UfsExecuteCommandFile(XdrvMailbox.data)) {
|
||||||
ResponseClear();
|
ResponseClear();
|
||||||
} else {
|
} else {
|
||||||
ResponseCmndChar(PSTR(D_JSON_FAILED));
|
ResponseCmndFailed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -864,6 +864,9 @@ 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();
|
||||||
|
|
Loading…
Reference in New Issue