mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
Major Update
- migrate toRepresentation methods out of header file - optimize toRepresentation methods - add helper for string formatting - put proper include guards in helper and MDNSManager - begin adding queryMDNS code
This commit is contained in:
parent
88f5cf29b7
commit
746a0a9f9b
@ -10,185 +10,184 @@ ProjectConfig::~ProjectConfig() {}
|
||||
*/
|
||||
void ProjectConfig::initConfig()
|
||||
{
|
||||
if (_name.empty())
|
||||
{
|
||||
log_e("Config name is null\n");
|
||||
_name = "openiris";
|
||||
}
|
||||
if (_name.empty())
|
||||
{
|
||||
log_e("Config name is null\n");
|
||||
_name = "openiris";
|
||||
}
|
||||
|
||||
bool success = begin(_name.c_str());
|
||||
bool success = begin(_name.c_str());
|
||||
|
||||
log_i("Config name: %s", _name.c_str());
|
||||
log_i("Config loaded: %s", success ? "true" : "false");
|
||||
log_i("Config name: %s", _name.c_str());
|
||||
log_i("Config loaded: %s", success ? "true" : "false");
|
||||
|
||||
/*
|
||||
* If the config is not loaded,
|
||||
* we need to initialize the config with default data
|
||||
! Do not initialize the WiFiConfig_t struct here,
|
||||
! as it will create a blank network which breaks the WiFiManager
|
||||
*/
|
||||
this->config.device = {
|
||||
_name,
|
||||
"12345678",
|
||||
3232,
|
||||
};
|
||||
/*
|
||||
* If the config is not loaded,
|
||||
* we need to initialize the config with default data
|
||||
! Do not initialize the WiFiConfig_t struct here,
|
||||
! as it will create a blank network which breaks the WiFiManager
|
||||
*/
|
||||
this->config.device = {
|
||||
_name,
|
||||
"12345678",
|
||||
3232,
|
||||
};
|
||||
|
||||
this->config.ap_network = {
|
||||
"",
|
||||
"",
|
||||
1,
|
||||
false,
|
||||
};
|
||||
this->config.ap_network = {
|
||||
"",
|
||||
"",
|
||||
1,
|
||||
false,
|
||||
};
|
||||
|
||||
this->config.camera = {
|
||||
.vflip = 0,
|
||||
.href = 0,
|
||||
.framesize = 4,
|
||||
.quality = 7,
|
||||
.brightness = 2,
|
||||
};
|
||||
this->config.camera = {
|
||||
.vflip = 0,
|
||||
.href = 0,
|
||||
.framesize = 4,
|
||||
.quality = 7,
|
||||
.brightness = 2,
|
||||
};
|
||||
}
|
||||
|
||||
void ProjectConfig::save()
|
||||
{
|
||||
log_d("Saving project config");
|
||||
deviceConfigSave();
|
||||
cameraConfigSave();
|
||||
wifiConfigSave();
|
||||
end(); // we call end() here to close the connection to the NVS partition, we only do this because we call ESP.restart() next.
|
||||
ESP.restart();
|
||||
log_d("Saving project config");
|
||||
deviceConfigSave();
|
||||
cameraConfigSave();
|
||||
wifiConfigSave();
|
||||
end(); // we call end() here to close the connection to the NVS partition, we only do this because we call ESP.restart() next.
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
void ProjectConfig::wifiConfigSave()
|
||||
{
|
||||
log_d("Saving wifi config");
|
||||
log_d("Saving wifi config");
|
||||
|
||||
/* WiFi Config */
|
||||
putInt("networkCount", this->config.networks.size());
|
||||
/* WiFi Config */
|
||||
putInt("networkCount", this->config.networks.size());
|
||||
|
||||
std::string name = "name";
|
||||
std::string ssid = "ssid";
|
||||
std::string password = "pass";
|
||||
std::string channel = "channel";
|
||||
for (int i = 0; i < this->config.networks.size(); i++)
|
||||
{
|
||||
char buffer[2];
|
||||
std::string iter_str = Helpers::itoa(i, buffer, 10);
|
||||
std::string name = "name";
|
||||
std::string ssid = "ssid";
|
||||
std::string password = "pass";
|
||||
std::string channel = "channel";
|
||||
for (int i = 0; i < this->config.networks.size(); i++)
|
||||
{
|
||||
char buffer[2];
|
||||
std::string iter_str = Helpers::itoa(i, buffer, 10);
|
||||
|
||||
name.append(iter_str);
|
||||
ssid.append(iter_str);
|
||||
password.append(iter_str);
|
||||
channel.append(iter_str);
|
||||
name.append(iter_str);
|
||||
ssid.append(iter_str);
|
||||
password.append(iter_str);
|
||||
channel.append(iter_str);
|
||||
|
||||
putString(name.c_str(), this->config.networks[i].name.c_str());
|
||||
putString(ssid.c_str(), this->config.networks[i].ssid.c_str());
|
||||
putString(password.c_str(), this->config.networks[i].password.c_str());
|
||||
putInt(channel.c_str(), this->config.networks[i].channel);
|
||||
putString(name.c_str(), this->config.networks[i].name.c_str());
|
||||
putString(ssid.c_str(), this->config.networks[i].ssid.c_str());
|
||||
putString(password.c_str(), this->config.networks[i].password.c_str());
|
||||
putInt(channel.c_str(), this->config.networks[i].channel);
|
||||
|
||||
name = "name";
|
||||
ssid = "ssid";
|
||||
password = "pass";
|
||||
channel = "channel";
|
||||
}
|
||||
name = "name";
|
||||
ssid = "ssid";
|
||||
password = "pass";
|
||||
channel = "channel";
|
||||
}
|
||||
|
||||
/* AP Config */
|
||||
putString("apSSID", this->config.ap_network.ssid.c_str());
|
||||
putString("apPass", this->config.ap_network.password.c_str());
|
||||
putUInt("apChannel", this->config.ap_network.channel);
|
||||
/* AP Config */
|
||||
putString("apSSID", this->config.ap_network.ssid.c_str());
|
||||
putString("apPass", this->config.ap_network.password.c_str());
|
||||
putUInt("apChannel", this->config.ap_network.channel);
|
||||
|
||||
log_i("Project config saved and system is rebooting");
|
||||
log_i("Project config saved and system is rebooting");
|
||||
}
|
||||
|
||||
void ProjectConfig::deviceConfigSave()
|
||||
{
|
||||
/* Device Config */
|
||||
putString("deviceName", this->config.device.name.c_str());
|
||||
putString("OTAPassword", this->config.device.OTAPassword.c_str());
|
||||
putInt("OTAPort", this->config.device.OTAPort);
|
||||
//! No need to save the JSON strings or bools, they are generated and used on the fly
|
||||
/* Device Config */
|
||||
putString("deviceName", this->config.device.name.c_str());
|
||||
putString("OTAPassword", this->config.device.OTAPassword.c_str());
|
||||
putInt("OTAPort", this->config.device.OTAPort);
|
||||
//! No need to save the JSON strings or bools, they are generated and used on the fly
|
||||
}
|
||||
|
||||
void ProjectConfig::cameraConfigSave()
|
||||
{
|
||||
/* Camera Config */
|
||||
putInt("vflip", this->config.camera.vflip);
|
||||
putInt("href", this->config.camera.href);
|
||||
putInt("framesize", this->config.camera.framesize);
|
||||
putInt("quality", this->config.camera.quality);
|
||||
putInt("brightness", this->config.camera.brightness);
|
||||
/* Camera Config */
|
||||
putInt("vflip", this->config.camera.vflip);
|
||||
putInt("href", this->config.camera.href);
|
||||
putInt("framesize", this->config.camera.framesize);
|
||||
putInt("quality", this->config.camera.quality);
|
||||
putInt("brightness", this->config.camera.brightness);
|
||||
}
|
||||
|
||||
bool ProjectConfig::reset()
|
||||
{
|
||||
log_w("Resetting project config");
|
||||
return clear();
|
||||
log_w("Resetting project config");
|
||||
return clear();
|
||||
}
|
||||
|
||||
void ProjectConfig::load()
|
||||
{
|
||||
log_d("Loading project config");
|
||||
if (this->_already_loaded)
|
||||
{
|
||||
log_w("Project config already loaded");
|
||||
return;
|
||||
}
|
||||
log_d("Loading project config");
|
||||
if (this->_already_loaded)
|
||||
{
|
||||
log_w("Project config already loaded");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Device Config */
|
||||
this->config.device.name = getString("deviceName", "openiristracker").c_str();
|
||||
this->config.device.OTAPassword = getString("OTAPassword", "12345678").c_str();
|
||||
this->config.device.OTAPort = getInt("OTAPort", 3232);
|
||||
//! No need to load the JSON strings or bools, they are generated and used on the fly
|
||||
/* Device Config */
|
||||
this->config.device.name = getString("deviceName", "openiristracker").c_str();
|
||||
this->config.device.OTAPassword = getString("OTAPassword", "12345678").c_str();
|
||||
this->config.device.OTAPort = getInt("OTAPort", 3232);
|
||||
//! No need to load the JSON strings or bools, they are generated and used on the fly
|
||||
|
||||
/* WiFi Config */
|
||||
int networkCount = getInt("networkCount", 0);
|
||||
std::string name = "name";
|
||||
std::string ssid = "ssid";
|
||||
std::string password = "pass";
|
||||
std::string channel = "channel";
|
||||
for (int i = 0; i < networkCount; i++)
|
||||
{
|
||||
char buffer[2];
|
||||
std::string iter_str = Helpers::itoa(i, buffer, 10);
|
||||
/* WiFi Config */
|
||||
int networkCount = getInt("networkCount", 0);
|
||||
std::string name = "name";
|
||||
std::string ssid = "ssid";
|
||||
std::string password = "pass";
|
||||
std::string channel = "channel";
|
||||
for (int i = 0; i < networkCount; i++)
|
||||
{
|
||||
char buffer[2];
|
||||
std::string iter_str = Helpers::itoa(i, buffer, 10);
|
||||
|
||||
name.append(iter_str);
|
||||
ssid.append(iter_str);
|
||||
password.append(iter_str);
|
||||
channel.append(iter_str);
|
||||
name.append(iter_str);
|
||||
ssid.append(iter_str);
|
||||
password.append(iter_str);
|
||||
channel.append(iter_str);
|
||||
|
||||
const std::string &temp_1 = getString(name.c_str()).c_str();
|
||||
const std::string &temp_2 = getString(ssid.c_str()).c_str();
|
||||
const std::string &temp_3 = getString(password.c_str()).c_str();
|
||||
uint8_t temp_4 = getUInt(channel.c_str());
|
||||
const std::string &temp_1 = getString(name.c_str()).c_str();
|
||||
const std::string &temp_2 = getString(ssid.c_str()).c_str();
|
||||
const std::string &temp_3 = getString(password.c_str()).c_str();
|
||||
uint8_t temp_4 = getUInt(channel.c_str());
|
||||
|
||||
name = "name";
|
||||
ssid = "ssid";
|
||||
password = "pass";
|
||||
channel = "channel";
|
||||
name = "name";
|
||||
ssid = "ssid";
|
||||
password = "pass";
|
||||
channel = "channel";
|
||||
|
||||
//! push_back creates a copy of the object, so we need to use emplace_back
|
||||
this->config.networks.emplace_back(
|
||||
temp_1,
|
||||
temp_2,
|
||||
temp_3,
|
||||
temp_4,
|
||||
false); // false because the networks we store in the config are the ones we want the esp to connect to, rather than host as AP
|
||||
}
|
||||
//! push_back creates a copy of the object, so we need to use emplace_back
|
||||
this->config.networks.emplace_back(
|
||||
temp_1,
|
||||
temp_2,
|
||||
temp_3,
|
||||
temp_4,
|
||||
false); // false because the networks we store in the config are the ones we want the esp to connect to, rather than host as AP
|
||||
}
|
||||
|
||||
/* AP Config */
|
||||
this->config.ap_network.ssid = getString("apSSID", "openiris").c_str();
|
||||
this->config.ap_network.password = getString("apPass", "12345678").c_str();
|
||||
this->config.ap_network.channel = getUInt("apChannel", 1);
|
||||
/* AP Config */
|
||||
this->config.ap_network.ssid = getString("apSSID", "openiris").c_str();
|
||||
this->config.ap_network.password = getString("apPass", "12345678").c_str();
|
||||
this->config.ap_network.channel = getUInt("apChannel", 1);
|
||||
|
||||
/* Camera Config */
|
||||
this->config.camera.vflip = getInt("vflip", 0);
|
||||
this->config.camera.href = getInt("href", 0);
|
||||
this->config.camera.framesize = getInt("framesize", 4);
|
||||
this->config.camera.quality = getInt("quality", 7);
|
||||
this->config.camera.brightness = getInt("brightness", 2);
|
||||
|
||||
/* Camera Config */
|
||||
this->config.camera.vflip = getInt("vflip", 0);
|
||||
this->config.camera.href = getInt("href", 0);
|
||||
this->config.camera.framesize = getInt("framesize", 4);
|
||||
this->config.camera.quality = getInt("quality", 7);
|
||||
this->config.camera.brightness = getInt("brightness", 2);
|
||||
|
||||
this->_already_loaded = true;
|
||||
this->notify(ObserverEvent::configLoaded);
|
||||
this->_already_loaded = true;
|
||||
this->notify(ObserverEvent::configLoaded);
|
||||
}
|
||||
|
||||
//**********************************************************************************************************************
|
||||
@ -198,79 +197,101 @@ void ProjectConfig::load()
|
||||
//**********************************************************************************************************************
|
||||
void ProjectConfig::setDeviceConfig(const std::string &name, const std::string &OTAPassword, int *OTAPort, bool shouldNotify)
|
||||
{
|
||||
log_d("Updating device config");
|
||||
this->config.device.name.assign(name);
|
||||
this->config.device.OTAPassword.assign(OTAPassword);
|
||||
this->config.device.OTAPort = *OTAPort;
|
||||
log_d("Updating device config");
|
||||
this->config.device.name.assign(name);
|
||||
this->config.device.OTAPassword.assign(OTAPassword);
|
||||
this->config.device.OTAPort = *OTAPort;
|
||||
|
||||
if (shouldNotify)
|
||||
this->notify(ObserverEvent::deviceConfigUpdated);
|
||||
if (shouldNotify)
|
||||
this->notify(ObserverEvent::deviceConfigUpdated);
|
||||
}
|
||||
|
||||
void ProjectConfig::setCameraConfig(uint8_t *vflip, uint8_t *framesize, uint8_t *href, uint8_t *quality, uint8_t *brightness, bool shouldNotify)
|
||||
{
|
||||
log_d("Updating camera config");
|
||||
this->config.camera.vflip = *vflip;
|
||||
this->config.camera.href = *href;
|
||||
this->config.camera.framesize = *framesize;
|
||||
this->config.camera.quality = *quality;
|
||||
this->config.camera.brightness = *brightness;
|
||||
log_d("Updating camera config");
|
||||
this->config.camera.vflip = *vflip;
|
||||
this->config.camera.href = *href;
|
||||
this->config.camera.framesize = *framesize;
|
||||
this->config.camera.quality = *quality;
|
||||
this->config.camera.brightness = *brightness;
|
||||
|
||||
log_d("Updating Camera config");
|
||||
if (shouldNotify)
|
||||
this->notify(ObserverEvent::cameraConfigUpdated);
|
||||
log_d("Updating Camera config");
|
||||
if (shouldNotify)
|
||||
this->notify(ObserverEvent::cameraConfigUpdated);
|
||||
}
|
||||
|
||||
void ProjectConfig::setWifiConfig(const std::string &networkName, const std::string &ssid, const std::string &password, uint8_t *channel, bool adhoc, bool shouldNotify)
|
||||
{
|
||||
WiFiConfig_t *networkToUpdate = nullptr;
|
||||
WiFiConfig_t *networkToUpdate = nullptr;
|
||||
|
||||
// we store the ADHOC flag as false because the networks we store in the config are the ones we want the esp to connect to, rather than host as AP, and here we're just updating them
|
||||
size_t size = this->config.networks.size();
|
||||
if (size > 0)
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
if (strcmp(this->config.networks[i].name.c_str(), networkName.c_str()) == 0)
|
||||
networkToUpdate = &this->config.networks[i];
|
||||
// we store the ADHOC flag as false because the networks we store in the config are the ones we want the esp to connect to, rather than host as AP, and here we're just updating them
|
||||
size_t size = this->config.networks.size();
|
||||
if (size > 0)
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
if (strcmp(this->config.networks[i].name.c_str(), networkName.c_str()) == 0)
|
||||
networkToUpdate = &this->config.networks[i];
|
||||
|
||||
//! push_back creates a copy of the object, so we need to use emplace_back
|
||||
if (networkToUpdate != nullptr)
|
||||
{
|
||||
this->config.networks.emplace_back(
|
||||
networkName,
|
||||
ssid,
|
||||
password,
|
||||
*channel,
|
||||
false);
|
||||
}
|
||||
log_d("Updating wifi config");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//! push_back creates a copy of the object, so we need to use emplace_back
|
||||
this->config.networks.emplace_back(
|
||||
networkName,
|
||||
ssid,
|
||||
password,
|
||||
*channel,
|
||||
false);
|
||||
networkToUpdate = &this->config.networks[0];
|
||||
}
|
||||
//! push_back creates a copy of the object, so we need to use emplace_back
|
||||
if (networkToUpdate != nullptr)
|
||||
{
|
||||
this->config.networks.emplace_back(
|
||||
networkName,
|
||||
ssid,
|
||||
password,
|
||||
*channel,
|
||||
false);
|
||||
}
|
||||
log_d("Updating wifi config");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//! push_back creates a copy of the object, so we need to use emplace_back
|
||||
this->config.networks.emplace_back(
|
||||
networkName,
|
||||
ssid,
|
||||
password,
|
||||
*channel,
|
||||
false);
|
||||
networkToUpdate = &this->config.networks[0];
|
||||
}
|
||||
|
||||
if (shouldNotify)
|
||||
this->notify(ObserverEvent::networksConfigUpdated);
|
||||
if (shouldNotify)
|
||||
this->notify(ObserverEvent::networksConfigUpdated);
|
||||
}
|
||||
|
||||
void ProjectConfig::setAPWifiConfig(const std::string &ssid, const std::string &password, uint8_t *channel, bool adhoc, bool shouldNotify)
|
||||
{
|
||||
this->config.ap_network.ssid.assign(ssid);
|
||||
this->config.ap_network.password.assign(password);
|
||||
this->config.ap_network.channel = *channel;
|
||||
this->config.ap_network.adhoc = adhoc;
|
||||
this->config.ap_network.ssid.assign(ssid);
|
||||
this->config.ap_network.password.assign(password);
|
||||
this->config.ap_network.channel = *channel;
|
||||
this->config.ap_network.adhoc = adhoc;
|
||||
|
||||
log_d("Updating access point config");
|
||||
if (shouldNotify)
|
||||
this->notify(ObserverEvent::networksConfigUpdated);
|
||||
log_d("Updating access point config");
|
||||
if (shouldNotify)
|
||||
this->notify(ObserverEvent::networksConfigUpdated);
|
||||
}
|
||||
|
||||
std::string ProjectConfig::DeviceConfig_t::toRepresentation()
|
||||
{
|
||||
std::string json = Helpers::format_string(
|
||||
"device_config: {\"name\": \"%s\", \"OTAPassword\": \"%s\", \"OTAPort\": %u}",
|
||||
this->name.c_str(),
|
||||
this->OTAPassword.c_str(),
|
||||
this->OTAPort);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
std::string ProjectConfig::CameraConfig_t::toRepresentation()
|
||||
{
|
||||
std::string json = Helpers::format_string("camera_config: {\"vflip\": %d,\"framesize\": %d,\"href\": %d,\"quality\": %d,\"brightness\": %d}",
|
||||
this->vflip,
|
||||
this->framesize,
|
||||
this->href,
|
||||
this->quality,
|
||||
this->brightness);
|
||||
return json;
|
||||
}
|
||||
@ -28,15 +28,7 @@ public:
|
||||
std::string OTAPassword;
|
||||
int OTAPort;
|
||||
|
||||
const char* toRepresentation() {
|
||||
char *p = (char*)"device_config: {";
|
||||
p += sprintf(p, "\"name\":%s,", this->name);
|
||||
p += sprintf(p, "\"OTAPassword\":%s,", this->OTAPassword);
|
||||
p += sprintf(p, "\"OTAPort\":%u,", this->OTAPort);
|
||||
p += sprintf(p, "},");
|
||||
*p++ = 0;
|
||||
return p;
|
||||
}
|
||||
std::string toRepresentation();
|
||||
};
|
||||
|
||||
struct CameraConfig_t
|
||||
@ -47,39 +39,30 @@ public:
|
||||
uint8_t quality;
|
||||
uint8_t brightness;
|
||||
|
||||
const char* toRepresentation() {
|
||||
char *p = (char*)"camera_config: {";
|
||||
p += sprintf(p, "\"vflip\":%u,", this->vflip);
|
||||
p += sprintf(p, "\"href\":%u,", this->href);
|
||||
p += sprintf(p, "\"framesize\":%d,", this->framesize);
|
||||
p += sprintf(p, "\"quality\":%d,", this->quality);
|
||||
p += sprintf(p, "\"brightness\":%d", this->brightness);
|
||||
p += sprintf(p, "},");
|
||||
*p++ = 0;
|
||||
return p;
|
||||
}
|
||||
std::string toRepresentation();
|
||||
};
|
||||
|
||||
struct WiFiConfig_t
|
||||
{
|
||||
//! Constructor for WiFiConfig_t - allows us to use emplace_back
|
||||
WiFiConfig_t(const std::string &name,
|
||||
const std::string &ssid,
|
||||
const std::string &password,
|
||||
uint8_t channel,
|
||||
bool adhoc) : name(std::move(name)),
|
||||
ssid(std::move(ssid)),
|
||||
password(std::move(password)),
|
||||
channel(channel),
|
||||
adhoc(adhoc) {}
|
||||
const std::string &ssid,
|
||||
const std::string &password,
|
||||
uint8_t channel,
|
||||
bool adhoc) : name(std::move(name)),
|
||||
ssid(std::move(ssid)),
|
||||
password(std::move(password)),
|
||||
channel(channel),
|
||||
adhoc(adhoc) {}
|
||||
std::string name;
|
||||
std::string ssid;
|
||||
std::string password;
|
||||
uint8_t channel;
|
||||
bool adhoc;
|
||||
|
||||
const char* toRepresentation() {
|
||||
char *p = (char*)"wifi_entry: {";
|
||||
const char *toRepresentation()
|
||||
{
|
||||
char *p = (char *)"wifi_entry: {";
|
||||
p += sprintf(p, "\"name\":%s,", this->name);
|
||||
p += sprintf(p, "\"ssid\":%s,", this->ssid);
|
||||
p += sprintf(p, "\"password\":%s,", this->password);
|
||||
@ -97,8 +80,9 @@ public:
|
||||
std::string password;
|
||||
uint8_t channel;
|
||||
bool adhoc;
|
||||
const char* toRepresentation() {
|
||||
char *p = (char*)"adhoc_network: {";
|
||||
const char *toRepresentation()
|
||||
{
|
||||
char *p = (char *)"adhoc_network: {";
|
||||
p += sprintf(p, "\"ssid\":%s,", this->ssid);
|
||||
p += sprintf(p, "\"password\":%s,", this->password);
|
||||
p += sprintf(p, "\"channel\":%u,", this->channel);
|
||||
|
||||
@ -96,4 +96,4 @@ void Helpers::update_progress_bar(int progress, int total)
|
||||
}
|
||||
std::cout << "] " << int(progress * 100.0 / total) << " %\r";
|
||||
std::cout.flush();
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,10 @@
|
||||
#ifndef HELPERS_HPP
|
||||
#define HELPERS_HPP
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
namespace Helpers
|
||||
{
|
||||
@ -9,4 +12,26 @@ namespace Helpers
|
||||
void split(std::string str, std::string splitBy, std::vector<std::string> &tokens);
|
||||
std::vector<std::string> split(const std::string &s, char delimiter);
|
||||
void update_progress_bar(int progress, int total);
|
||||
}
|
||||
|
||||
/// @brief
|
||||
/// @tparam ...Args
|
||||
/// @param format
|
||||
/// @param ...args
|
||||
/// @return
|
||||
template <typename... Args>
|
||||
std::string format_string(const std::string &format, Args... args)
|
||||
{
|
||||
int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0'
|
||||
if (size_s <= 0)
|
||||
{
|
||||
std::cout << "Error during formatting.";
|
||||
return "";
|
||||
}
|
||||
auto size = static_cast<size_t>(size_s);
|
||||
std::unique_ptr<char[]> buf(new char[size]);
|
||||
std::snprintf(buf.get(), size, format.c_str(), args...);
|
||||
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HELPERS_HPP
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
#ifndef MDNSHANDLER_HPP
|
||||
#define MDNSHANDLER_HPP
|
||||
#include <ESPmDNS.h>
|
||||
#include "data/StateManager/StateManager.hpp"
|
||||
#include "data/utilities/Observer.hpp"
|
||||
@ -16,4 +18,6 @@ public:
|
||||
ProjectConfig *configManager);
|
||||
void startMDNS();
|
||||
void update(ObserverEvent::Event event);
|
||||
};
|
||||
};
|
||||
|
||||
#endif // MDNSHANDLER_HPP
|
||||
0
ESP/lib/src/network/mDNS/queryMDNS.cpp
Normal file
0
ESP/lib/src/network/mDNS/queryMDNS.cpp
Normal file
23
ESP/lib/src/network/mDNS/queryMDNS.hpp
Normal file
23
ESP/lib/src/network/mDNS/queryMDNS.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#ifndef QUERYMDNSSERVICE_HPP
|
||||
#define QUERYMDNSSERVICE_HPP
|
||||
#include <ESPmDNS.h>
|
||||
#include "data/StateManager/StateManager.hpp"
|
||||
#include "data/utilities/Observer.hpp"
|
||||
#include "data/utilities/helpers.hpp"
|
||||
#include "data/config/project_config.hpp"
|
||||
|
||||
class QueryMDNSService : public IObserver
|
||||
{
|
||||
private:
|
||||
StateManager<MDNSState_e> *stateManager;
|
||||
ProjectConfig *configManager;
|
||||
|
||||
public:
|
||||
QueryMDNSService(StateManager<MDNSState_e> *stateManager,
|
||||
ProjectConfig *configManager);
|
||||
void queryMDNS();
|
||||
void update(ObserverEvent::Event event);
|
||||
};
|
||||
|
||||
#endif // QUERYMDNSSERVICE_HPP
|
||||
@ -1 +1 @@
|
||||
276
|
||||
288
|
||||
Loading…
Reference in New Issue
Block a user