Move getChipId to separate class

This commit is contained in:
Thomas Basler 2022-10-20 19:35:17 +02:00
parent 9f4d8bdddb
commit ca51aab236
4 changed files with 23 additions and 12 deletions

View File

@ -62,7 +62,6 @@ private:
void setStaticIp();
void setupMode();
void NetworkEvent(WiFiEvent_t event);
static uint32_t getChipId();
bool adminEnabled = true;
bool forceDisconnection = false;
int adminTimeoutCounter = 0;

9
include/Utils.h Normal file
View File

@ -0,0 +1,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <cstdint>
class Utils {
public:
static uint32_t getChipId();
};

View File

@ -4,6 +4,7 @@
*/
#include "NetworkSettings.h"
#include "Configuration.h"
#include "Utils.h"
#include "defaults.h"
#include <WiFi.h>
#ifdef OPENDTU_ETHERNET
@ -142,7 +143,7 @@ void NetworkSettingsClass::enableAdminMode()
String NetworkSettingsClass::getApName()
{
return String(ACCESS_POINT_NAME + String(getChipId()));
return String(ACCESS_POINT_NAME + String(Utils::getChipId()));
}
void NetworkSettingsClass::loop()
@ -385,7 +386,7 @@ String NetworkSettingsClass::getHostname()
char resultHostname[WIFI_MAX_HOSTNAME_STRLEN + 1];
uint8_t pos = 0;
uint32_t chipId = getChipId();
uint32_t chipId = Utils::getChipId();
snprintf(preparedHostname, WIFI_MAX_HOSTNAME_STRLEN + 1, config.WiFi_Hostname, chipId);
const char* pC = preparedHostname;
@ -431,13 +432,4 @@ network_mode NetworkSettingsClass::NetworkMode()
return _networkMode;
}
uint32_t NetworkSettingsClass::getChipId()
{
uint32_t chipId = 0;
for (int i = 0; i < 17; i += 8) {
chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
}
return chipId;
}
NetworkSettingsClass NetworkSettings;

11
src/Utils.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "utils.h"
#include <Esp.h>
uint32_t Utils::getChipId()
{
uint32_t chipId = 0;
for (int i = 0; i < 17; i += 8) {
chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
}
return chipId;
}