mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
откат изменений из-за потери оперативной памяти
This commit is contained in:
@@ -25,8 +25,6 @@
|
|||||||
#define USE_LITTLEFS false
|
#define USE_LITTLEFS false
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define QUEUE_FROM_STR
|
|
||||||
|
|
||||||
//задачи таскера
|
//задачи таскера
|
||||||
enum TimerTask_t { WIFI_SCAN,
|
enum TimerTask_t { WIFI_SCAN,
|
||||||
WIFI_MQTT_CONNECTION_CHECK,
|
WIFI_MQTT_CONNECTION_CHECK,
|
||||||
|
|||||||
@@ -9,7 +9,3 @@
|
|||||||
#include "classes/NotAsync.h"
|
#include "classes/NotAsync.h"
|
||||||
#include "ESPConfiguration.h"
|
#include "ESPConfiguration.h"
|
||||||
#include "MqttClient.h"
|
#include "MqttClient.h"
|
||||||
//#include "queue/QueueFromChar.h"
|
|
||||||
//#include "queue/QueueFromInstance.h"
|
|
||||||
//#include "queue/QueueInst.h"
|
|
||||||
#include "classes/QueueFromStruct.h"
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "classes/QueueFromStruct.h"
|
|
||||||
|
|
||||||
class SendJson;
|
class SendJson;
|
||||||
|
|
||||||
@@ -9,7 +8,7 @@ class SendJson {
|
|||||||
SendJson();
|
SendJson();
|
||||||
~SendJson();
|
~SendJson();
|
||||||
|
|
||||||
void addFileToQueue(String path, uint8_t num);
|
void sendFile(String path, uint8_t num);
|
||||||
|
|
||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
@@ -17,13 +16,12 @@ class SendJson {
|
|||||||
|
|
||||||
void sendMqtt(String& jsonArrayElement);
|
void sendMqtt(String& jsonArrayElement);
|
||||||
|
|
||||||
QueueItems myItem;
|
uint8_t _num;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
File file;
|
File file;
|
||||||
String _path;
|
String _path;
|
||||||
uint8_t _num;
|
|
||||||
bool sendingInProgress = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern SendJson* sendJsonFiles;
|
extern SendJson* sendConfigJson;
|
||||||
|
extern SendJson* sendWigdetsJson;
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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;
|
|
||||||
};
|
|
||||||
@@ -35,11 +35,11 @@ void setup() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//инициализация mqtt
|
//инициализация mqtt
|
||||||
// mqttInit();
|
mqttInit();
|
||||||
|
|
||||||
//создаем объект класса выгружающего json массив из файла
|
//создаем объект класса выгружающего json массив из файла
|
||||||
|
sendConfigJson = new SendJson;
|
||||||
sendJsonFiles = new SendJson;
|
sendWigdetsJson = new SendJson;
|
||||||
|
|
||||||
configure("/config.json");
|
configure("/config.json");
|
||||||
|
|
||||||
@@ -62,7 +62,8 @@ void loop() {
|
|||||||
ts.update();
|
ts.update();
|
||||||
|
|
||||||
//отправка json
|
//отправка json
|
||||||
if (sendJsonFiles) sendJsonFiles->loop();
|
if (sendConfigJson) sendConfigJson->loop();
|
||||||
|
if (sendWigdetsJson) sendWigdetsJson->loop();
|
||||||
|
|
||||||
#ifdef STANDARD_WEB_SERVER
|
#ifdef STANDARD_WEB_SERVER
|
||||||
//обработка web сервера
|
//обработка web сервера
|
||||||
|
|||||||
@@ -219,8 +219,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
// очередь задавалась бы так: /widgets.json,/config.json,
|
// очередь задавалась бы так: /widgets.json,/config.json,
|
||||||
// хорошая идея на завтра)
|
// хорошая идея на завтра)
|
||||||
|
|
||||||
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/widgets.json", num);
|
if (sendWigdetsJson) sendWigdetsJson->sendFile("/widgets.json", num);
|
||||||
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/config.json", num);
|
if (sendConfigJson) sendConfigJson->sendFile("/config.json", num);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payloadStr.startsWith("/gifnoc.json")) { //если прилетел измененный пакет с меткой /gifnoc (config наоборот) то перепишем файл, пока переписываем целеком
|
if (payloadStr.startsWith("/gifnoc.json")) { //если прилетел измененный пакет с меткой /gifnoc (config наоборот) то перепишем файл, пока переписываем целеком
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -1,32 +1,18 @@
|
|||||||
#include "classes/SendJson.h"
|
#include "classes/SendJson.h"
|
||||||
|
|
||||||
SendJson::SendJson() {
|
SendJson::SendJson() {}
|
||||||
filesQueue = new QueueFromStruct;
|
|
||||||
}
|
|
||||||
SendJson::~SendJson() {}
|
SendJson::~SendJson() {}
|
||||||
|
|
||||||
void SendJson::addFileToQueue(String path, uint8_t num) {
|
void SendJson::sendFile(String path, uint8_t num) {
|
||||||
myItem.myword = path;
|
_path = path;
|
||||||
myItem.num = num;
|
_num = num;
|
||||||
filesQueue->push(myItem);
|
file = seekFile(path);
|
||||||
SerialPrint(F("i"), F("WS"), "file added to Queue " + path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendJson::loop() {
|
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()) {
|
if (file.available()) {
|
||||||
String jsonArrayElement = _path + file.readStringUntil('}') + "}";
|
String jsonArrayElement = _path + file.readStringUntil('}') + "}";
|
||||||
sendWs(jsonArrayElement);
|
sendWs(jsonArrayElement);
|
||||||
} else {
|
|
||||||
sendingInProgress = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,4 +24,5 @@ void SendJson::sendMqtt(String& jsonArrayElement) {
|
|||||||
// mqtt send to do
|
// mqtt send to do
|
||||||
}
|
}
|
||||||
|
|
||||||
SendJson* sendJsonFiles;
|
SendJson* sendConfigJson;
|
||||||
|
SendJson* sendWigdetsJson;
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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());
|
|
||||||
Reference in New Issue
Block a user