проверка

This commit is contained in:
Dmitry Borisenko
2022-01-20 13:36:00 +01:00
parent c4a3dec67c
commit f893a3623d
13 changed files with 311 additions and 20 deletions

View File

@@ -0,0 +1,46 @@
#ifdef QUEUE_FROM_CHAR
#include "classes/QueueFromChar.h"
QueueFromChar::QueueFromChar() {
commandList = NULL;
commandCount = 0;
}
QueueFromChar::~QueueFromChar() {}
//добавление команды в буфер
void QueueFromChar::addCommand(const char* command) {
commandList = (CharBufferStruct*)realloc(commandList, (commandCount + 1) * sizeof(CharBufferStruct));
strncpy(commandList[commandCount].command, command, MAX_COMMAND_LENGTH);
Serial.println("command added: " + String(command) + " " + String(commandCount));
commandCount++;
}
//распечатаем все добавленные команды
void QueueFromChar::printCommands() {
if (commandCount > 0 && commandList != NULL) {
for (int i = 0; i < commandCount; i++) {
Serial.println(commandList[i].command);
}
}
}
//заберем последнюю из положенных в буфер команд
String QueueFromChar::getLastCommand() {
String ret = "empty";
if (commandList != NULL) {
int cnt = commandCount - 1;
ret = commandList[cnt].command;
if (cnt > 0) {
delete commandList[cnt].command;
} else if (cnt == 0) {
commandList = NULL;
}
Serial.println("command deleted: " + ret + " " + String(cnt));
commandCount--;
}
return ret;
}
// QueueFromChar* myBuf;
#endif