mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 20:09:14 +03:00
добавил буффер char
This commit is contained in:
@@ -9,3 +9,4 @@
|
|||||||
#include "classes/NotAsync.h"
|
#include "classes/NotAsync.h"
|
||||||
#include "ESPConfiguration.h"
|
#include "ESPConfiguration.h"
|
||||||
#include "MqttClient.h"
|
#include "MqttClient.h"
|
||||||
|
#include "classes/CommandBuf.h"
|
||||||
|
|||||||
28
include/classes/CommandBuf.h
Normal file
28
include/classes/CommandBuf.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
|
#define MAX_COMMAND_LENGTH 16
|
||||||
|
#define BUFFER 128
|
||||||
|
|
||||||
|
class CommandBuf;
|
||||||
|
|
||||||
|
class CommandBuf {
|
||||||
|
public:
|
||||||
|
CommandBuf();
|
||||||
|
~CommandBuf();
|
||||||
|
|
||||||
|
void addCommand(const char* command);
|
||||||
|
|
||||||
|
void printCommands();
|
||||||
|
|
||||||
|
String getLastCommand();
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct CharBufferStruct {
|
||||||
|
char command[MAX_COMMAND_LENGTH + 1];
|
||||||
|
};
|
||||||
|
CharBufferStruct* commandList;
|
||||||
|
int commandCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern CommandBuf* myBuf;
|
||||||
12
src/Main.cpp
12
src/Main.cpp
@@ -41,6 +41,18 @@ void setup() {
|
|||||||
sendConfigJson = new SendJson;
|
sendConfigJson = new SendJson;
|
||||||
sendWigdetsJson = new SendJson;
|
sendWigdetsJson = new SendJson;
|
||||||
|
|
||||||
|
myBuf = new CommandBuf;
|
||||||
|
|
||||||
|
myBuf->addCommand("zero");
|
||||||
|
myBuf->addCommand("one");
|
||||||
|
myBuf->addCommand("two");
|
||||||
|
myBuf->printCommands();
|
||||||
|
|
||||||
|
myBuf->getLastCommand();
|
||||||
|
myBuf->getLastCommand();
|
||||||
|
myBuf->getLastCommand();
|
||||||
|
//myBuf->printCommands();
|
||||||
|
|
||||||
configure("/config.json");
|
configure("/config.json");
|
||||||
|
|
||||||
//выводим остаток оперативной памяти после старта
|
//выводим остаток оперативной памяти после старта
|
||||||
|
|||||||
43
src/classes/CommandBuf.cpp
Normal file
43
src/classes/CommandBuf.cpp
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#include "classes/CommandBuf.h"
|
||||||
|
|
||||||
|
CommandBuf::CommandBuf() {
|
||||||
|
commandList = NULL;
|
||||||
|
commandCount = 0;
|
||||||
|
}
|
||||||
|
CommandBuf::~CommandBuf() {}
|
||||||
|
|
||||||
|
//добавление команды в буфер
|
||||||
|
void CommandBuf::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 CommandBuf::printCommands() {
|
||||||
|
if (commandCount > 0 && commandList != NULL) {
|
||||||
|
for (int i = 0; i < commandCount; i++) {
|
||||||
|
Serial.println(commandList[i].command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//заберем последнюю из положенных в буфер команд
|
||||||
|
String CommandBuf::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;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandBuf* myBuf;
|
||||||
Reference in New Issue
Block a user