откат изменений из-за потери оперативной памяти

This commit is contained in:
Dmitry Borisenko
2022-01-20 13:07:37 +01:00
parent 8229e0b116
commit c4a3dec67c
14 changed files with 18 additions and 301 deletions

View File

@@ -25,8 +25,6 @@
#define USE_LITTLEFS false
#endif
#define QUEUE_FROM_STR
//задачи таскера
enum TimerTask_t { WIFI_SCAN,
WIFI_MQTT_CONNECTION_CHECK,

View File

@@ -9,7 +9,3 @@
#include "classes/NotAsync.h"
#include "ESPConfiguration.h"
#include "MqttClient.h"
//#include "queue/QueueFromChar.h"
//#include "queue/QueueFromInstance.h"
//#include "queue/QueueInst.h"
#include "classes/QueueFromStruct.h"

View File

@@ -1,46 +0,0 @@
#pragma once
#include "Global.h"
#ifdef QUEUE_FROM_STR
#include <queue>
#include <iostream>
using namespace std;
struct QueueItems {
String myword;
uint8_t num;
};
class QueueFromStruct;
class QueueFromStruct {
public:
QueueFromStruct();
~QueueFromStruct();
void push(QueueItems word);
void pop();
QueueItems front();
bool empty();
private:
queue<QueueItems> queue1;
QueueItems tmpItem;
};
extern QueueFromStruct* filesQueue;
//=======проверка очереди из структур=================
// 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);
#endif

View File

@@ -1,6 +1,5 @@
#pragma once
#include "Global.h"
#include "classes/QueueFromStruct.h"
class SendJson;
@@ -9,7 +8,7 @@ class SendJson {
SendJson();
~SendJson();
void addFileToQueue(String path, uint8_t num);
void sendFile(String path, uint8_t num);
void loop();
@@ -17,13 +16,12 @@ class SendJson {
void sendMqtt(String& jsonArrayElement);
QueueItems myItem;
uint8_t _num;
private:
File file;
String _path;
uint8_t _num;
bool sendingInProgress = false;
};
extern SendJson* sendJsonFiles;
extern SendJson* sendConfigJson;
extern SendJson* sendWigdetsJson;

View File

@@ -1,42 +0,0 @@
#pragma once
#include "Global.h"
#ifdef QUEUE_FROM_CHAR
#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();
#endif

View File

@@ -1,26 +0,0 @@
#pragma once
#include "Global.h"
#ifdef QUEUE_FROM_INST
#include "classes/QueueInst.h"
#include <queue>
#include <iostream>
using namespace std;
class QueueFromInstance;
class QueueFromInstance {
public:
QueueFromInstance();
~QueueFromInstance();
void push(QueueInstance instance);
void pop();
QueueInstance front();
private:
queue<QueueInstance> queue1;
};
// extern QueueFromInstance* myQueue;
#endif

View File

@@ -1,19 +0,0 @@
#pragma once
#include "Global.h"
#include <queue>
#include <iostream>
using namespace std;
class QueueInstance;
class QueueInstance {
public:
QueueInstance(String text);
~QueueInstance();
String get();
private:
String _text;
};

View File

@@ -35,11 +35,11 @@ void setup() {
#endif
//инициализация mqtt
// mqttInit();
mqttInit();
//создаем объект класса выгружающего json массив из файла
sendJsonFiles = new SendJson;
sendConfigJson = new SendJson;
sendWigdetsJson = new SendJson;
configure("/config.json");
@@ -62,7 +62,8 @@ void loop() {
ts.update();
//отправка json
if (sendJsonFiles) sendJsonFiles->loop();
if (sendConfigJson) sendConfigJson->loop();
if (sendWigdetsJson) sendWigdetsJson->loop();
#ifdef STANDARD_WEB_SERVER
//обработка web сервера

View File

@@ -219,8 +219,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
// очередь задавалась бы так: /widgets.json,/config.json,
// хорошая идея на завтра)
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/widgets.json", num);
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/config.json", num);
if (sendWigdetsJson) sendWigdetsJson->sendFile("/widgets.json", num);
if (sendConfigJson) sendConfigJson->sendFile("/config.json", num);
}
if (payloadStr.startsWith("/gifnoc.json")) { //если прилетел измененный пакет с меткой /gifnoc (config наоборот) то перепишем файл, пока переписываем целеком

View File

@@ -1,32 +0,0 @@
#include "classes/QueueFromStruct.h"
#ifdef QUEUE_FROM_STR
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;
}
bool QueueFromStruct::empty() {
return queue1.empty();
}
QueueFromStruct* filesQueue;
#endif

View File

@@ -1,32 +1,18 @@
#include "classes/SendJson.h"
SendJson::SendJson() {
filesQueue = new QueueFromStruct;
}
SendJson::SendJson() {}
SendJson::~SendJson() {}
void SendJson::addFileToQueue(String path, uint8_t num) {
myItem.myword = path;
myItem.num = num;
filesQueue->push(myItem);
SerialPrint(F("i"), F("WS"), "file added to Queue " + path);
void SendJson::sendFile(String path, uint8_t num) {
_path = path;
_num = num;
file = seekFile(path);
}
void SendJson::loop() {
if (!filesQueue->empty() && !sendingInProgress) {
Serial.println("Queue not empty");
myItem = filesQueue->front();
_path = myItem.myword;
_num = myItem.num;
file = seekFile(_path);
SerialPrint(F("i"), F("WS"), "seek File to WS " + _path);
sendingInProgress = true;
}
if (file.available()) {
String jsonArrayElement = _path + file.readStringUntil('}') + "}";
sendWs(jsonArrayElement);
} else {
sendingInProgress = false;
}
}
@@ -38,4 +24,5 @@ void SendJson::sendMqtt(String& jsonArrayElement) {
// mqtt send to do
}
SendJson* sendJsonFiles;
SendJson* sendConfigJson;
SendJson* sendWigdetsJson;

View File

@@ -1,46 +0,0 @@
#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

View File

@@ -1,30 +0,0 @@
#ifdef QUEUE_FROM_INST
#include "classes/QueueFromInstance.h"
QueueFromInstance::QueueFromInstance() {}
QueueFromInstance::~QueueFromInstance() {}
//добавим элемент в конец очереди
void QueueFromInstance::push(QueueInstance instance) {
queue1.push(instance);
}
//удалим элемент из начала очереди
void QueueFromInstance::pop() {
if (!queue1.empty()) {
queue1.pop();
}
}
//вернуть элемент из начала очереди и удалить его
QueueInstance QueueFromInstance::front() {
QueueInstance instance("");
if (!queue1.empty()) {
instance = queue1.front();
queue1.pop();
}
return instance;
}
// QueueFromInstance* myQueue;
#endif

View File

@@ -1,22 +0,0 @@
#include "queue/QueueInst.h"
QueueInstance::QueueInstance(String text) {
_text = text;
}
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());