mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-29 07:32:18 +03:00
добавил очередь отправки файлов в сокеты
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
#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;
|
||||
@@ -1,28 +0,0 @@
|
||||
#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;
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "classes/QueueFromStruct.h"
|
||||
|
||||
#ifdef QUEUE_FROM_STR
|
||||
QueueFromStruct::QueueFromStruct() {}
|
||||
QueueFromStruct::~QueueFromStruct() {}
|
||||
|
||||
@@ -24,4 +24,9 @@ QueueItems QueueFromStruct::front() {
|
||||
return tmpItem;
|
||||
}
|
||||
|
||||
QueueFromStruct* myQueueStruct;
|
||||
bool QueueFromStruct::empty() {
|
||||
return queue1.empty();
|
||||
}
|
||||
|
||||
QueueFromStruct* filesQueue;
|
||||
#endif
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#include "classes/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());
|
||||
@@ -1,18 +1,32 @@
|
||||
#include "classes/SendJson.h"
|
||||
|
||||
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 +38,4 @@ void SendJson::sendMqtt(String& jsonArrayElement) {
|
||||
// mqtt send to do
|
||||
}
|
||||
|
||||
SendJson* sendConfigJson;
|
||||
SendJson* sendWigdetsJson;
|
||||
SendJson* sendJsonFiles;
|
||||
|
||||
Reference in New Issue
Block a user