mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
Добавил три типа очередей: очередь сущностей, очередь структур, и очередь char
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "classes/NotAsync.h"
|
||||
#include "ESPConfiguration.h"
|
||||
#include "MqttClient.h"
|
||||
#include "classes/CommandBuf.h"
|
||||
#include "classes/QueueBuf.h"
|
||||
#include "classes/QueueFromChar.h"
|
||||
#include "classes/QueueFromInstance.h"
|
||||
#include "classes/QueueFromStruct.h"
|
||||
#include "classes/QueueInst.h"
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
#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;
|
||||
39
include/classes/QueueFromChar.h
Normal file
39
include/classes/QueueFromChar.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
|
||||
#define MAX_COMMAND_LENGTH 16
|
||||
#define BUFFER 128
|
||||
|
||||
class QueueFromChar;
|
||||
|
||||
class QueueFromChar {
|
||||
public:
|
||||
QueueFromChar();
|
||||
~QueueFromChar();
|
||||
|
||||
void addCommand(const char* command);
|
||||
|
||||
void printCommands();
|
||||
|
||||
String getLastCommand();
|
||||
|
||||
private:
|
||||
struct CharBufferStruct {
|
||||
char command[MAX_COMMAND_LENGTH + 1];
|
||||
};
|
||||
CharBufferStruct* commandList;
|
||||
int commandCount = 0;
|
||||
};
|
||||
|
||||
extern QueueFromChar* myBuf;
|
||||
|
||||
//========проверка очереди=====================
|
||||
// myBuf = new QueueFromChar;
|
||||
// myBuf->addCommand("zero");
|
||||
// myBuf->addCommand("one");
|
||||
// myBuf->addCommand("two");
|
||||
// myBuf->printCommands();
|
||||
// myBuf->getLastCommand();
|
||||
// myBuf->getLastCommand();
|
||||
// myBuf->getLastCommand();
|
||||
// myBuf->printCommands();
|
||||
@@ -6,12 +6,12 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class QueueBuf;
|
||||
class QueueFromInstance;
|
||||
|
||||
class QueueBuf {
|
||||
class QueueFromInstance {
|
||||
public:
|
||||
QueueBuf();
|
||||
~QueueBuf();
|
||||
QueueFromInstance();
|
||||
~QueueFromInstance();
|
||||
|
||||
void push(QueueInstance instance);
|
||||
void pop();
|
||||
@@ -21,4 +21,4 @@ class QueueBuf {
|
||||
queue<QueueInstance> queue1;
|
||||
};
|
||||
|
||||
extern QueueBuf* myQueue;
|
||||
extern QueueFromInstance* myQueue;
|
||||
41
include/classes/QueueFromStruct.h
Normal file
41
include/classes/QueueFromStruct.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#include <queue>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct QueueItems {
|
||||
String myword;
|
||||
};
|
||||
|
||||
class QueueFromStruct;
|
||||
|
||||
class QueueFromStruct {
|
||||
public:
|
||||
QueueFromStruct();
|
||||
~QueueFromStruct();
|
||||
|
||||
void push(QueueItems word);
|
||||
void pop();
|
||||
QueueItems front();
|
||||
|
||||
private:
|
||||
queue<QueueItems> queue1;
|
||||
QueueItems tmpItem;
|
||||
};
|
||||
|
||||
extern QueueFromStruct* myQueueStruct;
|
||||
|
||||
//=======проверка очереди из структур=================
|
||||
// myQueueStruct = new QueueFromStruct;
|
||||
// QueueItems myItem;
|
||||
// myItem.myword = "word1";
|
||||
// myQueueStruct->push(myItem);
|
||||
// myItem.myword = "word2";
|
||||
// myQueueStruct->push(myItem);
|
||||
// myItem.myword = "word3";
|
||||
// myQueueStruct->push(myItem);
|
||||
// Serial.println(myQueueStruct->front().myword);
|
||||
// Serial.println(myQueueStruct->front().myword);
|
||||
// Serial.println(myQueueStruct->front().myword);
|
||||
29
src/Main.cpp
29
src/Main.cpp
@@ -41,35 +41,6 @@ void setup() {
|
||||
sendConfigJson = 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();
|
||||
|
||||
myQueue = new QueueBuf;
|
||||
|
||||
myQueue->push(*new QueueInstance("text1"));
|
||||
myQueue->push(*new QueueInstance("text2"));
|
||||
myQueue->push(*new QueueInstance("text3"));
|
||||
|
||||
Serial.println(myQueue->front().get());
|
||||
Serial.println(myQueue->front().get());
|
||||
Serial.println(myQueue->front().get());
|
||||
|
||||
// myQueue->push(20);
|
||||
// myQueue->push(30);
|
||||
//
|
||||
// Serial.println(myQueue->front());
|
||||
// Serial.println(myQueue->front());
|
||||
// Serial.println(myQueue->front());
|
||||
|
||||
configure("/config.json");
|
||||
|
||||
//выводим остаток оперативной памяти после старта
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "classes/CommandBuf.h"
|
||||
#include "classes/QueueFromChar.h"
|
||||
|
||||
CommandBuf::CommandBuf() {
|
||||
QueueFromChar::QueueFromChar() {
|
||||
commandList = NULL;
|
||||
commandCount = 0;
|
||||
}
|
||||
CommandBuf::~CommandBuf() {}
|
||||
QueueFromChar::~QueueFromChar() {}
|
||||
|
||||
//добавление команды в буфер
|
||||
void CommandBuf::addCommand(const char* command) {
|
||||
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));
|
||||
@@ -15,7 +15,7 @@ void CommandBuf::addCommand(const char* command) {
|
||||
}
|
||||
|
||||
//распечатаем все добавленные команды
|
||||
void CommandBuf::printCommands() {
|
||||
void QueueFromChar::printCommands() {
|
||||
if (commandCount > 0 && commandList != NULL) {
|
||||
for (int i = 0; i < commandCount; i++) {
|
||||
Serial.println(commandList[i].command);
|
||||
@@ -24,7 +24,7 @@ void CommandBuf::printCommands() {
|
||||
}
|
||||
|
||||
//заберем последнюю из положенных в буфер команд
|
||||
String CommandBuf::getLastCommand() {
|
||||
String QueueFromChar::getLastCommand() {
|
||||
String ret = "empty";
|
||||
if (commandList != NULL) {
|
||||
int cnt = commandCount - 1;
|
||||
@@ -40,4 +40,4 @@ String CommandBuf::getLastCommand() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
CommandBuf* myBuf;
|
||||
QueueFromChar* myBuf;
|
||||
@@ -1,22 +1,22 @@
|
||||
#include "classes/QueueBuf.h"
|
||||
#include "classes/QueueFromInstance.h"
|
||||
|
||||
QueueBuf::QueueBuf() {}
|
||||
QueueBuf::~QueueBuf() {}
|
||||
QueueFromInstance::QueueFromInstance() {}
|
||||
QueueFromInstance::~QueueFromInstance() {}
|
||||
|
||||
//добавим элемент в конец очереди
|
||||
void QueueBuf::push(QueueInstance instance) {
|
||||
void QueueFromInstance::push(QueueInstance instance) {
|
||||
queue1.push(instance);
|
||||
}
|
||||
|
||||
//удалим элемент из начала очереди
|
||||
void QueueBuf::pop() {
|
||||
void QueueFromInstance::pop() {
|
||||
if (!queue1.empty()) {
|
||||
queue1.pop();
|
||||
}
|
||||
}
|
||||
|
||||
//вернуть элемент из начала очереди и удалить его
|
||||
QueueInstance QueueBuf::front() {
|
||||
QueueInstance QueueFromInstance::front() {
|
||||
QueueInstance instance("");
|
||||
if (!queue1.empty()) {
|
||||
instance = queue1.front();
|
||||
@@ -25,4 +25,4 @@ QueueInstance QueueBuf::front() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
QueueBuf* myQueue;
|
||||
QueueFromInstance* myQueue;
|
||||
27
src/classes/QueueFromStruct.cpp
Normal file
27
src/classes/QueueFromStruct.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "classes/QueueFromStruct.h"
|
||||
|
||||
QueueFromStruct::QueueFromStruct() {}
|
||||
QueueFromStruct::~QueueFromStruct() {}
|
||||
|
||||
//добавим элемент в конец очереди
|
||||
void QueueFromStruct::push(QueueItems word) {
|
||||
queue1.push(word);
|
||||
}
|
||||
|
||||
//удалим элемент из начала очереди
|
||||
void QueueFromStruct::pop() {
|
||||
if (!queue1.empty()) {
|
||||
queue1.pop();
|
||||
}
|
||||
}
|
||||
|
||||
//вернуть элемент из начала очереди и удалить его
|
||||
QueueItems QueueFromStruct::front() {
|
||||
if (!queue1.empty()) {
|
||||
tmpItem = queue1.front();
|
||||
queue1.pop();
|
||||
}
|
||||
return tmpItem;
|
||||
}
|
||||
|
||||
QueueFromStruct* myQueueStruct;
|
||||
@@ -8,3 +8,15 @@ QueueInstance::~QueueInstance() {}
|
||||
String QueueInstance::get() {
|
||||
return _text;
|
||||
}
|
||||
|
||||
//========проверка очереди из экземпляров======
|
||||
|
||||
// myQueue = new QueueFromInstance;
|
||||
|
||||
// myQueue->push(QueueInstance("text1"));
|
||||
// myQueue->push(QueueInstance("text2"));
|
||||
// myQueue->push(QueueInstance("text3"));
|
||||
|
||||
// Serial.println(myQueue->front().get());
|
||||
// Serial.println(myQueue->front().get());
|
||||
// Serial.println(myQueue->front().get());
|
||||
Reference in New Issue
Block a user