mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
проверка
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
#define STANDARD_WEB_SERVER
|
||||
#define STANDARD_WEB_SOCKETS
|
||||
|
||||
//#define QUEUE_FROM_STR
|
||||
|
||||
//#define REST_FILE_OPERATIONS
|
||||
|
||||
#define MQTT_RECONNECT_INTERVAL 20000
|
||||
|
||||
46
include/classes/QueueFromStruct.h
Normal file
46
include/classes/QueueFromStruct.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#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,5 +1,7 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#ifdef QUEUE_FROM_STR
|
||||
#include "classes/QueueFromStruct.h"
|
||||
|
||||
class SendJson;
|
||||
|
||||
@@ -8,7 +10,7 @@ class SendJson {
|
||||
SendJson();
|
||||
~SendJson();
|
||||
|
||||
void sendFile(String path, uint8_t num);
|
||||
void addFileToQueue(String path, uint8_t num);
|
||||
|
||||
void loop();
|
||||
|
||||
@@ -16,12 +18,14 @@ class SendJson {
|
||||
|
||||
void sendMqtt(String& jsonArrayElement);
|
||||
|
||||
uint8_t _num;
|
||||
QueueItems myItem;
|
||||
|
||||
private:
|
||||
File file;
|
||||
String _path;
|
||||
uint8_t _num;
|
||||
bool sendingInProgress = false;
|
||||
};
|
||||
|
||||
extern SendJson* sendConfigJson;
|
||||
extern SendJson* sendWigdetsJson;
|
||||
extern SendJson* sendJsonFiles;
|
||||
#endif
|
||||
|
||||
14
src/Main.cpp
14
src/Main.cpp
@@ -37,9 +37,10 @@ void setup() {
|
||||
//инициализация mqtt
|
||||
mqttInit();
|
||||
|
||||
//создаем объект класса выгружающего json массив из файла
|
||||
sendConfigJson = new SendJson;
|
||||
sendWigdetsJson = new SendJson;
|
||||
//создаем объект класса выгружающего json массив из файла
|
||||
#ifdef QUEUE_FROM_STR
|
||||
sendJsonFiles = new SendJson;
|
||||
#endif
|
||||
|
||||
configure("/config.json");
|
||||
|
||||
@@ -61,9 +62,10 @@ void loop() {
|
||||
//обновление задач таскера
|
||||
ts.update();
|
||||
|
||||
//отправка json
|
||||
if (sendConfigJson) sendConfigJson->loop();
|
||||
if (sendWigdetsJson) sendWigdetsJson->loop();
|
||||
//отправка json
|
||||
#ifdef QUEUE_FROM_STR
|
||||
if (sendJsonFiles) sendJsonFiles->loop();
|
||||
#endif
|
||||
|
||||
#ifdef STANDARD_WEB_SERVER
|
||||
//обработка web сервера
|
||||
|
||||
@@ -218,9 +218,10 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
||||
// не нравится мне это, нужно что бы класс строил очередь и отправлял вначале первый файл потом второй
|
||||
// очередь задавалась бы так: /widgets.json,/config.json,
|
||||
// хорошая идея на завтра)
|
||||
|
||||
if (sendWigdetsJson) sendWigdetsJson->sendFile("/widgets.json", num);
|
||||
if (sendConfigJson) sendConfigJson->sendFile("/config.json", num);
|
||||
#ifdef QUEUE_FROM_STR
|
||||
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/widgets.json", num);
|
||||
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/config.json", num);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (payloadStr.startsWith("/gifnoc.json")) { //если прилетел измененный пакет с меткой /gifnoc (config наоборот) то перепишем файл, пока переписываем целеком
|
||||
|
||||
32
src/classes/QueueFromStruct.cpp
Normal file
32
src/classes/QueueFromStruct.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#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,18 +1,33 @@
|
||||
#include "classes/SendJson.h"
|
||||
#ifdef QUEUE_FROM_STR
|
||||
|
||||
SendJson::SendJson() {}
|
||||
SendJson::SendJson() {
|
||||
filesQueue = new QueueFromStruct;
|
||||
}
|
||||
SendJson::~SendJson() {}
|
||||
|
||||
void SendJson::sendFile(String path, uint8_t num) {
|
||||
_path = path;
|
||||
_num = num;
|
||||
file = seekFile(path);
|
||||
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::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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,5 +39,5 @@ void SendJson::sendMqtt(String& jsonArrayElement) {
|
||||
// mqtt send to do
|
||||
}
|
||||
|
||||
SendJson* sendConfigJson;
|
||||
SendJson* sendWigdetsJson;
|
||||
SendJson* sendJsonFiles;
|
||||
#endif
|
||||
46
training/QueueFromChar.cpp
Normal file
46
training/QueueFromChar.cpp
Normal 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
|
||||
42
training/QueueFromChar.h
Normal file
42
training/QueueFromChar.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#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
|
||||
30
training/QueueFromInstance.cpp
Normal file
30
training/QueueFromInstance.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#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
|
||||
26
training/QueueFromInstance.h
Normal file
26
training/QueueFromInstance.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#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
|
||||
24
training/QueueInst.cpp
Normal file
24
training/QueueInst.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifdef QUEUE_FROM_INST
|
||||
#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());
|
||||
#endif
|
||||
21
training/QueueInst.h
Normal file
21
training/QueueInst.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#ifdef QUEUE_FROM_INST
|
||||
#include <queue>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class QueueInstance;
|
||||
|
||||
class QueueInstance {
|
||||
public:
|
||||
QueueInstance(String text);
|
||||
~QueueInstance();
|
||||
|
||||
String get();
|
||||
|
||||
private:
|
||||
String _text;
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user