From c4a3dec67ced80bbe4e61ce6056b9d57970598b4 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <67171972+IoTManagerProject@users.noreply.github.com> Date: Thu, 20 Jan 2022 13:07:37 +0100 Subject: [PATCH] =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B0=D1=82=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=B8=D0=B7-?= =?UTF-8?q?=D0=B7=D0=B0=20=D0=BF=D0=BE=D1=82=D0=B5=D1=80=D0=B8=20=D0=BE?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B0=D1=82=D0=B8=D0=B2=D0=BD=D0=BE=D0=B9=20?= =?UTF-8?q?=D0=BF=D0=B0=D0=BC=D1=8F=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Const.h | 2 -- include/Main.h | 4 --- include/classes/QueueFromStruct.h | 46 ------------------------------- include/classes/SendJson.h | 10 +++---- include/queue/QueueFromChar.h | 42 ---------------------------- include/queue/QueueFromInstance.h | 26 ----------------- include/queue/QueueInst.h | 19 ------------- src/Main.cpp | 9 +++--- src/StandWebServer.cpp | 4 +-- src/classes/QueueFromStruct.cpp | 32 --------------------- src/classes/SendJson.cpp | 27 +++++------------- src/queue/QueueFromChar.cpp | 46 ------------------------------- src/queue/QueueFromInstance.cpp | 30 -------------------- src/queue/QueueInst.cpp | 22 --------------- 14 files changed, 18 insertions(+), 301 deletions(-) delete mode 100644 include/classes/QueueFromStruct.h delete mode 100644 include/queue/QueueFromChar.h delete mode 100644 include/queue/QueueFromInstance.h delete mode 100644 include/queue/QueueInst.h delete mode 100644 src/classes/QueueFromStruct.cpp delete mode 100644 src/queue/QueueFromChar.cpp delete mode 100644 src/queue/QueueFromInstance.cpp delete mode 100644 src/queue/QueueInst.cpp diff --git a/include/Const.h b/include/Const.h index aa92e40e..c6f18da2 100644 --- a/include/Const.h +++ b/include/Const.h @@ -25,8 +25,6 @@ #define USE_LITTLEFS false #endif -#define QUEUE_FROM_STR - //задачи таскера enum TimerTask_t { WIFI_SCAN, WIFI_MQTT_CONNECTION_CHECK, diff --git a/include/Main.h b/include/Main.h index 37a77c8a..222a55be 100644 --- a/include/Main.h +++ b/include/Main.h @@ -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" diff --git a/include/classes/QueueFromStruct.h b/include/classes/QueueFromStruct.h deleted file mode 100644 index 020c919b..00000000 --- a/include/classes/QueueFromStruct.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once -#include "Global.h" -#ifdef QUEUE_FROM_STR -#include -#include - -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 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 diff --git a/include/classes/SendJson.h b/include/classes/SendJson.h index 915ec16d..69a3c956 100644 --- a/include/classes/SendJson.h +++ b/include/classes/SendJson.h @@ -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; diff --git a/include/queue/QueueFromChar.h b/include/queue/QueueFromChar.h deleted file mode 100644 index c16b799e..00000000 --- a/include/queue/QueueFromChar.h +++ /dev/null @@ -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 diff --git a/include/queue/QueueFromInstance.h b/include/queue/QueueFromInstance.h deleted file mode 100644 index 0a509bf8..00000000 --- a/include/queue/QueueFromInstance.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "Global.h" -#ifdef QUEUE_FROM_INST -#include "classes/QueueInst.h" -#include -#include - -using namespace std; - -class QueueFromInstance; - -class QueueFromInstance { - public: - QueueFromInstance(); - ~QueueFromInstance(); - - void push(QueueInstance instance); - void pop(); - QueueInstance front(); - - private: - queue queue1; -}; - -// extern QueueFromInstance* myQueue; -#endif \ No newline at end of file diff --git a/include/queue/QueueInst.h b/include/queue/QueueInst.h deleted file mode 100644 index de6e0843..00000000 --- a/include/queue/QueueInst.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once -#include "Global.h" -#include -#include - -using namespace std; - -class QueueInstance; - -class QueueInstance { - public: - QueueInstance(String text); - ~QueueInstance(); - - String get(); - - private: - String _text; -}; diff --git a/src/Main.cpp b/src/Main.cpp index f16e6a9c..3394cf54 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -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 сервера diff --git a/src/StandWebServer.cpp b/src/StandWebServer.cpp index 710fda57..84cab220 100644 --- a/src/StandWebServer.cpp +++ b/src/StandWebServer.cpp @@ -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 наоборот) то перепишем файл, пока переписываем целеком diff --git a/src/classes/QueueFromStruct.cpp b/src/classes/QueueFromStruct.cpp deleted file mode 100644 index 52c5fb4c..00000000 --- a/src/classes/QueueFromStruct.cpp +++ /dev/null @@ -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 diff --git a/src/classes/SendJson.cpp b/src/classes/SendJson.cpp index 10b5ffb0..4b1bc970 100644 --- a/src/classes/SendJson.cpp +++ b/src/classes/SendJson.cpp @@ -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; diff --git a/src/queue/QueueFromChar.cpp b/src/queue/QueueFromChar.cpp deleted file mode 100644 index 3d7a4bc3..00000000 --- a/src/queue/QueueFromChar.cpp +++ /dev/null @@ -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 diff --git a/src/queue/QueueFromInstance.cpp b/src/queue/QueueFromInstance.cpp deleted file mode 100644 index 69321913..00000000 --- a/src/queue/QueueFromInstance.cpp +++ /dev/null @@ -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 diff --git a/src/queue/QueueInst.cpp b/src/queue/QueueInst.cpp deleted file mode 100644 index 3d296462..00000000 --- a/src/queue/QueueInst.cpp +++ /dev/null @@ -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()); \ No newline at end of file