mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
first
This commit is contained in:
107
include/Class/TCircularBuffer.h
Normal file
107
include/Class/TCircularBuffer.h
Normal file
@@ -0,0 +1,107 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
template <typename T, size_t BUFFER_SIZE>
|
||||
|
||||
class TCircularBuffer {
|
||||
public:
|
||||
TCircularBuffer() : _head{0}, _tail{0}, _full{false} {}
|
||||
|
||||
~TCircularBuffer() {}
|
||||
|
||||
void reset() {
|
||||
_head = _tail = _full = 0;
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
return _head == _tail && !_full;
|
||||
}
|
||||
|
||||
bool full() const {
|
||||
return _full;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of elements currently stored in the circular_buffer.
|
||||
*/
|
||||
size_t size() const {
|
||||
size_t res = 0;
|
||||
if (!_full) {
|
||||
if (_head < _tail)
|
||||
res = BUFFER_SIZE + _head - _tail;
|
||||
else
|
||||
res = _head - _tail;
|
||||
} else {
|
||||
res = BUFFER_SIZE;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/** Push the transaction to the buffer. This overwrites the buffer if it's full.
|
||||
* Загрузить данные в буфер
|
||||
* @param data item to be pushed to the buffer.
|
||||
*/
|
||||
void push(const T &item) {
|
||||
if (_full) {
|
||||
_tail++;
|
||||
if (_tail == BUFFER_SIZE)
|
||||
_tail = 0;
|
||||
}
|
||||
_pool[_head++] = item;
|
||||
if (_head == BUFFER_SIZE)
|
||||
_head = 0;
|
||||
if (_head == _tail)
|
||||
_full = true;
|
||||
}
|
||||
|
||||
/** Pop from the buffer.
|
||||
* Забрать данные из буфера
|
||||
* @param data item to store the data to be popped from the buffer.
|
||||
* @return True if data popped.
|
||||
*/
|
||||
bool pop(T &item) {
|
||||
bool res = false;
|
||||
if (!empty()) {
|
||||
item = _pool[_tail++];
|
||||
if (_tail == BUFFER_SIZE) _tail = 0;
|
||||
_full = false;
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool pop_back(T &item) {
|
||||
bool res = false;
|
||||
if (!empty()) {
|
||||
item = _pool[--_head];
|
||||
_full = false;
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/** Peek into circular buffer without popping.
|
||||
*
|
||||
* @param data item to be peeked from the buffer.
|
||||
* @return True if the buffer is not empty and data contains a transaction, false otherwise.
|
||||
*/
|
||||
bool peek(T &item) const {
|
||||
bool res = false;
|
||||
if (!empty()) {
|
||||
item = _pool[_tail];
|
||||
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private:
|
||||
T _pool[BUFFER_SIZE];
|
||||
size_t _head;
|
||||
size_t _tail;
|
||||
bool _full;
|
||||
};
|
||||
|
||||
extern TCircularBuffer<char *, 1024> *myTCircularBuffer;
|
||||
extern TCircularBuffer<char *, 20480> *myWsBuffer;
|
||||
@@ -119,6 +119,7 @@ enum NotAsyncActions {
|
||||
do_addPreset,
|
||||
do_sendScenUDP,
|
||||
do_sendScenMQTT,
|
||||
do_webSocketSendSetup,
|
||||
do_LAST,
|
||||
};
|
||||
|
||||
@@ -134,27 +135,27 @@ enum ConfigType_t {
|
||||
CT_SCENARIO
|
||||
};
|
||||
|
||||
//history
|
||||
//07.11.2020 (SSDP OFF, UDP OFF)
|
||||
//RAM: [===== ] 46.8% (used 38376 bytes from 81920 bytes)
|
||||
//Flash: [===== ] 54.2% (used 566004 bytes from 1044464 bytes)
|
||||
// history
|
||||
// 07.11.2020 (SSDP OFF, UDP OFF)
|
||||
// RAM: [===== ] 46.8% (used 38376 bytes from 81920 bytes)
|
||||
// Flash: [===== ] 54.2% (used 566004 bytes from 1044464 bytes)
|
||||
|
||||
//13.11.2020 (SSDP OFF, UDP OFF)
|
||||
//RAM: [===== ] 46.6% (used 38208 bytes from 81920 bytes)
|
||||
//Flash: [===== ] 54.2% (used 566388 bytes from 1044464 bytes)
|
||||
// 13.11.2020 (SSDP OFF, UDP OFF)
|
||||
// RAM: [===== ] 46.6% (used 38208 bytes from 81920 bytes)
|
||||
// Flash: [===== ] 54.2% (used 566388 bytes from 1044464 bytes)
|
||||
|
||||
//15.11.2020 (SSDP OFF, UDP OFF)
|
||||
//RAM: [===== ] 46.1% (used 37780 bytes from 81920 bytes)
|
||||
//Flash: [===== ] 54.3% (used 566656 bytes from 1044464 bytes)
|
||||
// 15.11.2020 (SSDP OFF, UDP OFF)
|
||||
// RAM: [===== ] 46.1% (used 37780 bytes from 81920 bytes)
|
||||
// Flash: [===== ] 54.3% (used 566656 bytes from 1044464 bytes)
|
||||
|
||||
//17.11.2020 (SSDP OFF, UDP OFF)
|
||||
//RAM: [===== ] 45.7% (used 37476 bytes from 81920 bytes)
|
||||
//Flash: [===== ] 54.5% (used 569296 bytes from 1044464 bytes)
|
||||
// 17.11.2020 (SSDP OFF, UDP OFF)
|
||||
// RAM: [===== ] 45.7% (used 37476 bytes from 81920 bytes)
|
||||
// Flash: [===== ] 54.5% (used 569296 bytes from 1044464 bytes)
|
||||
|
||||
//RAM: [===== ] 45.6% (used 37336 bytes from 81920 bytes)
|
||||
//Flash: [====== ] 55.3% (used 577396 bytes from 1044464 bytes)
|
||||
// RAM: [===== ] 45.6% (used 37336 bytes from 81920 bytes)
|
||||
// Flash: [====== ] 55.3% (used 577396 bytes from 1044464 bytes)
|
||||
|
||||
//eventBuf - буфер событий которые проверяются в сценариях,
|
||||
// eventBuf - буфер событий которые проверяются в сценариях,
|
||||
//и если событие удовлетворяет какому нибудь условию то выполняются указанные команды
|
||||
|
||||
//orderBuf - буфер команд которые выполняются сейчас же
|
||||
// orderBuf - буфер команд которые выполняются сейчас же
|
||||
|
||||
@@ -39,6 +39,7 @@ extern AsyncWebServer server;
|
||||
extern boolean just_load;
|
||||
extern boolean telegramInitBeen;
|
||||
extern boolean savedFromWeb;
|
||||
extern boolean wsSetupFlag;
|
||||
|
||||
// Json
|
||||
extern String configSetupJson; //все настройки
|
||||
@@ -65,8 +66,13 @@ extern int mqttConnectAttempts;
|
||||
extern bool changeBroker;
|
||||
extern int currentBroker;
|
||||
|
||||
// web sockets
|
||||
extern int wsAttempts;
|
||||
//extern char* wsBufChar;
|
||||
|
||||
// orders and events
|
||||
extern String orderBuf;
|
||||
extern String wsBuf;
|
||||
extern String eventBuf;
|
||||
extern String mysensorBuf;
|
||||
extern String itemsFile;
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
|
||||
void mqttInit();
|
||||
void selectBroker();
|
||||
void getMqttData1();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
extern void testsPerform();
|
||||
extern void testsPerform();
|
||||
extern void testLoop();
|
||||
11
include/WebSocket.h
Normal file
11
include/WebSocket.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include "Class/TCircularBuffer.h"
|
||||
#include "Global.h"
|
||||
void wsInit();
|
||||
void wsPublishData(String topic, String data);
|
||||
|
||||
// void wsSendSetup();
|
||||
// void wsSendSetupBuffer();
|
||||
//
|
||||
// void sendDataWs();
|
||||
// void loopWsExecute();
|
||||
Reference in New Issue
Block a user