This commit is contained in:
Dmitry Borisenko
2021-01-04 00:39:35 +01:00
parent bf9855aa60
commit 5eb3c6d3a3
339 changed files with 21164 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
#pragma once
#include <Arduino.h>
#include "FileSystem.h"
class FileHelper {
public:
FileHelper(const String filename);
/*
* Проверить существование
*/
void exists();
/*
* Удалить файл
*/
void remove();
/*
* Открыть файл установить позицию @position
*/
File seek(size_t position = 0);
/*
* Чтение строки с содержащей @substr
*/
String readFileString(const String substr);
/*
* Добовление строки @str в файл
*/
String appendStr(const String str);
/*
* Запись строки
*/
String writeStr(const String);
/*
* Чтение в строку
*/
String readStr(size_t);
/*
* Размер в байтах
*/
size_t getSize();
};

62
include/Utils/FileUtils.h Normal file
View File

@@ -0,0 +1,62 @@
#pragma once
#include <Arduino.h>
#include "Consts.h"
#include "FileSystem.h"
/*
* Инициализация ФС
*/
bool fileSystemInit();
/*
* Удалить файл
*/
void removeFile(const String& filename);
/*
* Открыть файл на позиции
*/
File seekFile(const String& filename, size_t position = 0);
/*
* Чтение строки из файла
* возвращает стоку из файла в которой есть искомое слово found
*/
const String readFileString(const String& filename, const String& to_find);
/*
* Добовление строки в файл
*/
const String addFileLn(const String& filename, const String& str);
/*
* Добовление строки в файл
*/
const String addFile(const String& filename, const String& str);
/*
* Запись строки в файл
*/
const String writeFile(const String& filename, const String& str);
/*
* Чтение файла в строку
*/
const String readFile(const String& filename, size_t max_size);
/*
* Посчитать
*/
size_t countLines(const String filename);
/*
* Размер файла
*/
size_t getFileSize(const String filename);
bool copyFile(const String& src, const String& dst, bool overwrite = true);
const String getFSSizeInfo();
const String getConfigFile(uint8_t preset, ConfigType_t type);

21
include/Utils/JsonUtils.h Normal file
View File

@@ -0,0 +1,21 @@
#pragma once
#include <Arduino.h>
String jsonReadStr(String& json, String name);
int jsonReadInt(String& json, String name);
boolean jsonReadBool(String& json, String name);
String jsonWriteStr(String& json, String name, String value);
String jsonWriteInt(String& json, String name, int value);
String jsonWriteFloat(String& json, String name, float value);
String jsonWriteBool(String& json, String name, boolean value);
void saveConfig();
void saveStore();

View File

@@ -0,0 +1,3 @@
#pragma once
#include <Arduino.h>
void SerialPrint(String errorLevel, String module, String msg);

View File

@@ -0,0 +1,34 @@
#pragma once
#include <Arduino.h>
uint8_t hexStringToUint8(String hex);
uint16_t hexStringToUint16(String hex);
String selectToMarkerLast(String str, String found);
String selectToMarker(String str, String found);
String extractInner(String str);
String deleteAfterDelimiter(String str, String found);
String deleteBeforeDelimiter(String str, String found);
String deleteBeforeDelimiterTo(String str, String found);
String deleteToMarkerLast(String str, String found);
String selectFromMarkerToMarker(String str, String found, int number);
size_t itemsCount2(String str, const String& separator);
size_t itemsCount(String& str, const char* delim);
boolean isDigitStr(const String& str);
boolean isDigitDotCommaStr(const String& str);
String prettyBytes(size_t size);

19
include/Utils/SysUtils.h Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include <Arduino.h>
#include "Global.h"
uint32_t ESP_getChipId();
const String getChipId();
void setLedStatus(LedStatus_t status);
const String getUniqueId(const String& name);
const String printMemoryStatus();
const String getHeapStats();
const String getMacAddress();
void setChipId();

69
include/Utils/TimeUtils.h Normal file
View File

@@ -0,0 +1,69 @@
#pragma once
#include <Arduino.h>
#include "Consts.h"
#define ONE_MINUTE_s 60
#define ONE_HOUR_m 60
#define ONE_HOUR_s 60 * ONE_MINUTE_s
#define LEAP_YEAR(Y) (((1970 + Y) > 0) && !((1970 + Y) % 4) && (((1970 + Y) % 100) || !((1970 + Y) % 400)))
#define MIN_DATETIME 1575158400
#define ONE_SECOND_ms 1000
/*
* Время (мс) прошедщее с @since
*/
unsigned long millis_since(unsigned long sinse);
/*
* Интерввал времени (мс) между @start и @finish
*/
unsigned long millis_passed(unsigned long start, unsigned long finish);
/*
* Форматиронное время интервала (мс)
* "чч:мм:cc",
* "дд чч:мм", если > 24 часов
*/
const String prettyMillis(unsigned long time_ms = millis());
/*
* Форматиронное время интервала (c)
* "чч:мм:cc",
* "дд чч:мм", если > 24 часов
*/
const String prettySeconds(unsigned long time_s);
/*
* Тайм зона в секундах
*/
int getOffsetInSeconds(int timezone);
/*
* Тайм зона в минутах
*/
int getOffsetInMinutes(int timezone);
/*
* Разбивает время на составляющие
*/
struct Time_t {
uint8_t second;
uint8_t minute;
uint8_t hour;
uint8_t day_of_week;
uint8_t day_of_month;
uint8_t month;
uint16_t day_of_year;
uint16_t year;
unsigned long days;
unsigned long valid;
};
void breakEpochToTime(unsigned long epoch, Time_t& tm);
void timeInit();

71
include/Utils/Timings.h Normal file
View File

@@ -0,0 +1,71 @@
#include <Arduino.h>
enum Timings_t { MT_ONE,
MT_TWO,
NUM_TIMINGS };
struct Timing {
unsigned long _total_mu;
unsigned long _min_mu;
unsigned long _max_mu;
Timing() : _total_mu{0}, _min_mu{999999}, _max_mu{0} {};
void reset() {
_total_mu = 0;
_min_mu = 999999;
_max_mu = 0;
}
void add(unsigned long time_mu) {
if (time_mu == 0) return;
_total_mu += time_mu;
if (_min_mu > time_mu) {
_min_mu = time_mu;
}
if (_max_mu < time_mu) {
_max_mu = time_mu;
}
}
};
static const char* module_name[NUM_TIMINGS] = {"strings", "boolean"};
struct Timings {
Timing mu[NUM_TIMINGS];
unsigned long _counter;
unsigned long _start;
unsigned long long _total;
Timings() : _counter{0}, _start{0} {};
void add(size_t module, unsigned long now = micros()) {
unsigned long time = now - _start;
_total += time;
mu[module].add(time);
_start = now;
}
void count() {
_counter++;
_start = micros();
}
void print() {
if (!_counter) {
return;
};
Serial.printf("lp/ms: %llu ", _counter / _total);
for (size_t i = 0; i < NUM_TIMINGS; i++) {
Serial.printf("%s: %.2f%% ", module_name[i], ((float)mu[i]._total_mu / _total) * 100);
mu[i].reset();
}
Serial.println();
_counter = 0;
_total = 0;
};
};

7
include/Utils/WebUtils.h Normal file
View File

@@ -0,0 +1,7 @@
#pragma once
#include "HttpServer.h"
#include <Arduino.h>
extern String getURL(const String& urls);
extern const String getMethodName(AsyncWebServerRequest* request);
extern const String getRequestInfo(AsyncWebServerRequest* request);

16
include/Utils/WiFiUtils.h Normal file
View File

@@ -0,0 +1,16 @@
#pragma once
#include "Global.h"
boolean isNetworkActive();
void routerConnect();
bool startAPMode();
boolean RouterFind(String ssid);
uint8_t RSSIquality();
extern void wifiSignalInit();

22
include/Utils/statUtils.h Normal file
View File

@@ -0,0 +1,22 @@
#pragma once
#include <Arduino.h>
#include "Global.h"
extern void initSt();
extern String updateDevicePsn(String lat, String lon, String accur, String geo);
extern String updateDeviceStatus();
extern String addNewDevice();
extern void decide();
extern void getPsn();
extern String getUptimeTotal();
extern uint8_t getNextNumber(String file);
extern uint8_t getCurrentNumber(String file);
//extern int plusOneHour();
//extern void eeWriteInt(int pos, int val);
//extern int eeGetInt(int pos);
//extern void updateDeviceList();
//extern void saveId(String file, int id);
//extern int getId(String file);